PDO For WordPress v1.0.0: Already a bug!!
Nanxiao just posted a comment here. Having originally thought this was due to a badly behaved plugin, i’ve just looked at it myself again. most of the routes to comment moderation work (i.e. direct clicking on the email link, going to comments through a manage-posts screen etc).
However, it is correct that the comments do not natively show up in the manage comments list. from wp 2.5.1.
This seems to be because the authors have started to use index hints in the sql – this is annoying and another example of non-standard sql!
The queries that are executed are these:
SELECT comment_approved, COUNT( * ) AS num_comments FROM wp_comments GROUP BY comment_approved SELECT COUNT(*) FROM wp_comments USE INDEX (comment_date_gmt) WHERE ( comment_approved = '0' OR comment_approved = '1' ) ORDER BY comment_date_gmt DESC SELECT SQL_CALC_FOUND_ROWS * FROM wp_comments USE INDEX (comment_date_gmt) WHERE ( comment_approved = '0' OR comment_approved = '1' ) ORDER BY comment_date_gmt DESC LIMIT 0, 25 |
Personally I don’t see why all these queries are needed (but i have not looked at it closely). I don’t see why we need to have an order by clause on a select count(*) query and i don’t see why you need the second query when the third query gives you the same information.
Anyway, the problem comes in the USE INDEX () syntax, which is required by mysql for index hinting but is either not required or not supported by sqlite.
The good news is that this is an easy fix which I will post later todayhave already posted. In the meantime, the other routes to comment moderation will function.
Thanks to Nanxiao for spotting this and pointing it out.
I download version 1.0.1 ,but I can’t find any different form 1.0.0
except version number.
The manage comments list function do not work well still.
thanks again for pointing the bugs out. there seems to be an error in my svn upload routine (i use Aptana Studio). I will look at it shortly.
the repository was corrupted (locally). this has been fixed and a new version (1.0.2) has been uploaded.
The plugin does not appear to handle permalinks correctly. Whenever I click on a post I get a error 404 from wordpress itself. This means that permalinks on the server is working fine but something in the database lookup is not working. I tested on the same server with both mysql and sqlite. Mysql works fine but sqlite does not. The website provided in this comment is a test one I have running for public access that uses sqlite. It has permalinks enabled. All other links other than the post ones work.
Hello Robert,
thanks for your comment. can you tell me what pemalink structure you are using so that i can try to duplicate your environment?
and what version of WP and the PDO plugin too, of course.
thanks
Justin
Hi Justin,
Thanks for responding so quickly.
WordPress 2.5.1
PDO for WordPress 1.0.2 (latest)
I have tested on both Lighttpd and Apache.
When you asked about which permalinks don’t work I went and checked to see which of the standard ones are broken. I found that the Date based ones (“Day and name” and “Month and name”) are broken however the Numeric one works fine. So it looks like it is the date being in there that is fouling it up. I’ll check it some more and see specifically which part(s) is.
Ok. Looked at it further. The year part is ok. It is when it goes to do the day or month number. Don’t ask me why. I’ll go through today checking other structure tags and see if any others are causing an issue.
Last comment for now (I promise). I finished going through the list. They were paired with postname which is already known to be ok. First list are all good and working and the second one causes a 404 error to be generated by wordpress (not the server). With these in mind I just discovered that date based archives do not work since they use either the day or month number in the address.
Good to go!
—————-
year
postname
post_id
category
author
These don’t work.
———————
monthnum
day
hour
minute
second
Ok. I’m going to have to update one more time. I don’t know if permalinks are even the cause here. I just noticed that even if permalinks is off then the dated archives are broken. You can even try them on your own site. The ones for this year produce a not found error (even though we know there should be something there) however the ones for last year work fine. Odd…
permalinks are not the cause, no. there was a bug in my implementation of the necessary time and date rewrites for sqlite.
i _think_ i’ve fixed it now. would you, Robert, be willing to try an unversioned code drop to see whether it solves the problem for you?
Yes. Please do send me a copy to my email address (I think you already have it).
I try to use pdo for wordpress on my gentoobox with no mysql.
I got only white screen.
This is because in wp-include/wp-db.php is include in pdo/db.h and wp-include/wp-db.php need mysql.
You nedd mysql to use sqlite (gasp).
solution in pdo/db.php :
set a value to $wpdb juste after declaring it global
Hi Bertrand,
you don’t need mysql to use pdo sqlite, no. i had not noticed the behaviour that you post about, but i am building a new version of pdo for wordpress that uses far fewer regular expressions and will look into your message.
apart from the redundant echos your code makes sense in that it will stop $wpdb from being instantiated as an object due to the conditionality in this code block of db.php
Hello, just before to take the my car for holydays.
The creation of wordpress (not PDO) call mysql functions, so if you want to run on a pure salite platform you must inhibit it.
in wp-include/wp-db.h tou have
function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
register_shutdown_function(array(&$this, "__destruct"));
if ( defined('WP_DEBUG') and WP_DEBUG == true )
$this->show_errors();
if ( defined('DB_CHARSET') )
$this->charset = DB_CHARSET;
if ( defined('DB_COLLATE') )
$this->collate = DB_COLLATE;
$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
and this call to mysql_connect was THE problem
Hello,
I have a strange problem with pdo sqlite the link http://bertrand.belguise.net/blog/?m=200809 doesn’t give me the posts …
The same sructure of blog with mysql don’t give me the same problem. May be a date problem with pdo sqlite.
(WordPress 2.61)
hello Bertrand.
you have not said what version of my code and what version of the WP code you are using. A bug was introduced into wp 2.6 which causes this problem. mysql ignores the bug and functions as anticipated anyway.
If I’m right this seems to be a repeat of the problems that Robert was having. I have not yet updated the code at wp.org as there are/were some other fixes I was adding.
would you be willing to try an unversioned drop of the code? i suspect that this will fix the problem.
thanks
Justin
I use the last version font on wordpress.org. (1.0.2)
And the problem is cause by strftime …
strftime return with %m return 2 characters string
so
Select count(*) ….. AND strftime
(‘%m’,post_date)= 09
give me 0
and
Select count(*) ….. AND strftime
(‘%m’,post_date)= ’09′
give me two
yes Bertrand – it is to do with inconsistent date handling in wp2.6.
as said – i have a fix for it in the current version of the code base. if you would be willing to try out untested code i can let you have the fix.
Yes of course where can i get it ?
for the moment i have modified pdo_sqlite_driver.php like this
private function _rewrite_datetime_functions($matches){
//may need to expand this to other functions.
switch (strtolower($matches[1])){
case "year":
return " cast( strftime('%Y',{$matches[2]}) as integer ) ";
break;
case "month":
return " cast( strftime('%m',{$matches[2]}) as integer )";
break;
case "day":
case "dayofmonth":
return " cast( strftime('%d',{$matches[2]}) as integer)";
break;
case "unix_timestamp":
return " cast(strftime('%s', {$matches[2]}) as integer)";
break;
}
}
Bertrand,
that will not fix it. the problem is in the write functions and not the read. it is the db update/inserts that are inconsistently implemented.
i would recommend fixing like this
add this to pdo_sqlite_driver
and add this
to the select, update, insert and replace cases within the rewriteQuery method.
oh, and you might want to fix the existing inconsistencies in the database from previous posts. don’t forget to backup your database first!
i wrote this code, which should work but I HAVE NOT TESTED IT other than on a tiny wp installation.
I store this file in the wp root directory (don’t forget to remove it after use…)
the code above was flawed. i’ve fixed it now.
i’m also going to have a look at the stringify option for pdo which would then more closely mimic the mysql behaviour and thus might avoid some other problems i’ve been seeing.
Ok i’ll wait, for the moment my fix (with the cast) solve my problem as you can see my worrd works fine
and i don’t see errors in my database with SqliteManager i have
post_date = ’2008-08-30 18:30:12′
the problem that yoiy patch fix is for the first day of a month and in my database the post_date is right like this
’2008-09-04 21:36:03′ i think that we don’t speak of same problem mine was because ’08′ is not equal to 08 (the string is not equal to the integer.
i can confirm that. BertrandB’s solution is working indeed. the dateupdate-script posted by justin above does not help. with the integer-casts i solved the broken page-archive due to wrong string vs. integer comparison – like bertrandb already said it: ’08′ != 8
thanks bertrand, now i have my page-archive finally working
Works great, thank you