So, a few days ago I blogged about an issue with BlogCFC and MySQL/Access. I was able to reproduce it, but for the life of me, I couldn't figure out why the bug occured. I was able to fix it though, so I've updated the zip. Changes include:
- Fix for MySQL/Access. More on the issue below.
- Updated the TrackBack spam list. I highly encourage you to copy this setting even if you don't need the MySQL/Access fix. If all BlogCFC users have a strong TB spam list, it may encourage TB spammers to ignore the platform.
As always, you can download BlogCFC from the project page.
So - more on the bug. The bug was very odd. Basically org.hastings.utils.cfc would throw an error on this line: (I've added a few spaces in it to make it break nicely.)
return variables.aDateFormat.getDateInstance( variables.aDateFormat[arguments.style], variables.thisLocale).format(utcDate);
The error stated the value of utcDate wasn't a valid date. Now - this is what I don't get. This CFC hasn't been touched in ages, probably over a year. The date values in the database hasn't changed since BlogCFC was released. Yet there it was - throwing errors. Now - I can say that my dev platform has changed. I used to run the "Simple" CF, ie, install, hook up to Apache, that's it. I've recently switched to CF installed in JRun. So maybe that was the key - but the question is - why hasn't anyone else complained?
Oh - and it gets better. The error was only thrown when you got categories. Let me make this a bit simpler and just paste in the email I sent when I originally asked for help. It may clear things up a bit. What follows is straight from an email, so forgive the fact that it may not match this entry well.
Now here is something that is baffling. BlogCFC has one uber-function to get blog entries. Depending on various filters, I modify the query a bit. For some reason, whenever I tell BlogCFC to get data and filter by a category, I get an error when I try to date format the data. (I'm not using CF's built in dateFormat though.)
I dumped the result of a simple, getEntries, versus a getEntries based on category. In both cases, while the entries were a bit different, the data was, essentially, the same.
On a whim I decided to dump the metadata on the query. For a normal getEntries, the posted column was datetime. For the getEntries/category filter, the value of the column was varchar!
Well - there ya go. Thing is - I can't understand why the query would change the posted column. Here is a sample of the query when doing a normal getEntries:
select tblblogentries.id, tblblogentries.title,
tblblogentries.alias,
date_add(posted, interval -1 hour) as posted,
tblblogentries.username, tblblogentries.allowcomments,
tblblogentries.enclosure, tblblogentries.filesize, tblblogentries.mimetype
, tblblogentries.body, tblblogentries.morebody
from tblblogentries
where 1=1
and blog = ?
order by tblblogentries.posted desc
limit 4
Now here is the query with a category filter:
select tblblogentries.id, tblblogentries.title,
tblblogentries.alias,
date_add(posted, interval -1 hour) as posted,
tblblogentries.username, tblblogentries.allowcomments,
tblblogentries.enclosure, tblblogentries.filesize, tblblogentries.mimetype
, tblblogentries.body, tblblogentries.morebody
from tblblogentries
,tblblogentriescategories
where 1=1
and blog = ?
and tblblogentriescategories.entryidfk = tblblogentries.id
and tblblogentriescategories.categoryidfk = ?
order by tblblogentries.posted desc
limit 4
So - anyone have a bright idea?
Archived Comments
I'm just shooting in the dark here, but you aren't qualifying the column in the date_add function.
Should the line be this:
date_add(tblblogentries.posted, interval -1 hour) as posted,
I wouldn't expect that to cause the problem, unless you added a "posted" column to tblblogentriescategories.
Eh? I do see "as posted". And nope, no posted in blogentriescategories.
Did the "eh?" mean you didn't understand? If so, I'll try to expand.
The line:
date_add(posted, interval -1 hour) as posted,
Could be:
date_add(tblblogentries.posted, interval -1 hour) as posted,
The column "posted" inside the date_add function is not qualified with the table name (every other column reference in the query is).
Of course, I would not expect this to cause the bug you're seeing.
I wonder if MySQL has a problem with aliases that are identical to table names?
Re-reading your original post, I'm unsure if you were still asking for help or if the bug was fixed.
The eh meant I thought you were wrong, but I see what you mean now. I'll try that. The bug -is- fixed by my mod to utils.cfc, but I don't consider it a 'good' fix if that makes sense. I'll try this and let you know.
I just tried the update and it didn't fix the date problem for me :o( It's definatly an odd one, if I get a chance I will investigate further...
Doug, what platform? I may have a new fix coming in soon.
Hi Ray, currently it's happening on a windows 2003 server, cf7.0.1, mysql 4.1.3a using IIS and my dev XP box with cf7.0.1 mysql 4.1.3a and IIS.
I was wondering if had something to do with my regional settings being set to UK but haven't had time to look through it yet.
Doug, try changing the parseDatetime in hastings.utils.cfc to lsparsedatetime. Be sure to refresh the cache. Paul is working on a 'more proper' fix.
I'm not positive this is related, but the keywords are all there that's for sure. I just extracted the ZIP for the first time, set it up with my own DSN and to work w/MS ACCESS - believing myself to have followed all the instructions. However, I am getting an error that reads " Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'datepart('d', dateAdd(''h'', 1, tblblogentries.posted))'.
I have no idea what it means (although I am suspcious about a double quote appearing around the H for dateadd). Anyway, if this helps this bug diagnostics, great -- otherwise if anyone can tell me what I'm doing wrong I'd love to demo this thing. FYI, I'm running it as localhost (or 127.0.0.1:8500).
Dave
I have an idea of the line #, but please tell it ot me. Also confirm you have MSACCESS as your db type in the ini file.
Hi, it's 699 in BLOG.CFC. The problem spot seems to be:
<cfelseif instance.blogDBType is "MSACCESS">
<cfset posted = "dateAdd('h', #instance.offset#, tblblogentries.posted)">
I definetely have MSACCESS set as the DBtype, but here is my evolved INI in the meantime (partially listed - sorry if this doesn't format well):
dsn=cfblog
owneremail=dpinero@fmhi.usf.edu
blogURL=http://127.0.0.1:8500/blog/client/index.cfm
unsubscribeURL=http://127.0.0.1:8500/blog/client/unsubscribe.cfm
blogTitle=BlogDev
blogDescription=The Dev Blog
blogItemURLPrefix=mode=entry&entry=
blogDBType=MSACCESS
locale=en_US
users=admin
commentsFrom=
mailserver=
mailusername=
mailpassword=
pingurls=
offset=1
allowtrackbacks=1
No, it can't be line 699, since that just makes a string. Thats where the string is created, but the real error should be on a cfquery block.
Found the bug. Check this blog. There will be an update later today.