Calling findPublishedDate() throws an exception error and a workaround.

Was getting an unusual error that seems to have been mentioned once before, with no solution.

Anyway I have chased it down to the widget with one line causing the issue in entryService. This line is

posts = entryService.findPublishedEntriesByDate(year=rc.year, month = rc.month, day = dayCounter);

Now it seems to fail on this line of code

results.count = executeQuery(query=“select count(*) #hql#”,params=params,max=1,asQuery=false)[1];

I have done some digging into this, and I found that another user had also raised this problem with no answer.

Anyway here is the quick fix for the solution to this problem.

If(arrayLen(results.entries) {

results.count = executeQuery(query=“select count(*) #hql#”,params=params,max=1,asQuery=false)[1];

} else (

results.count = 0

}

I am not sure why this was not considered, but it seems to work with that fix.

The error produce is as follows

Error Type: Application : [N/A]
Error Messages: Error while executing the Hibernate query.
java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Column “cb_content.publishedDate” is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.

Damn, I just got another error from it.

It looks like the HQL is not getting the or adding the published date to the data being returned for some reason. When did this change so my widget stopped working?

Ohh man! Something really went wrong with your request. The administrator has been adviced, so do not worry! Please try your request again!
Fault Action: archives
Error Information:
Error while executing the Hibernate query. java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Column “cb_content.publishedDate” is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.

What are you calling?

Luis Majano
CEO
Ortus Solutions, Corp
Toll Free/Fax: 1-888-557-8057
Direct: 909-248-3408
www.ortussolutions.com
Twitter: @lmajano, @ortussolutions

the first line of code in my post above…

I tracked it back to this change

https://github.com/Ortus-Solutions/ContentBox/commit/630cdc49a07b49bc5ef573db84e87b80fc069c0c

If I remove that change then it all works again.

What are you calling?

Luis Majano
CEO
Ortus Solutions, Corp
Toll Free/Fax: 1-888-557-8057
Direct: 909-248-3408
www.ortussolutions.com
Twitter: @lmajano, @ortussolutions

Luis, it is in my first post for crying out loud. the first line of code at the very top, is the culprit.

Ok here is the final fix for this BUG… I am sure it might cause problems but from my quick tests it now looks like a solution.

// Entry listing by Date
function findPublishedEntriesByDate(numeric year=0,numeric month=0, numeric day=0,max=0,offset=0,asQuery=false){
var results = {};
var hql = “FROM cbEntry
WHERE isPublished = true
AND passwordProtection = ‘’”;
var params = {};

// year lookup mandatory
if( arguments.year NEQ 0 ){
params[“year”] = arguments.year;
hql &= " AND YEAR(publishedDate) = :year";
}
// month lookup
if( arguments.month NEQ 0 ){
params[“month”] = arguments.month;
hql &= " AND MONTH(publishedDate) = :month";
}
// day lookup
if( arguments.day NEQ 0 ){
params[“day”] = arguments.day;
hql &= " AND DAY(publishedDate) = :day";
}
hql2 = hql & " ORDER BY publishedDate DESC";
// find
results.entries = executeQuery(query=hql2,params=params,max=arguments.max,offset=arguments.offset,asQuery=arguments.asQuery);
results.count = executeQuery(query=“select count(*) #hql#”,params=params,max=1,asQuery=false)[1];
return results;
}