When using multiple databases, db_error and db_affected_rows will fail to return correct values because they are called with arguments. According to php.net, this means that the last opened database is used instead of the active database.
This created a problem for us with caching, as rows had changed on the last active database, but not on the last opened one .. causing db_affected_rows to return 0 and not insert anything into the cache.
I'm attaching a patch that adds $active_db as a parameter to all of the *_last_error and *_affected_rows function calls in database.*.inc so that it will return the correct values.
Comment | File | Size | Author |
---|---|---|---|
#16 | database_pgsql_inc_handles_4-6.patch | 1.08 KB | rkerr |
#15 | database_mysql_inc_handles_4-6.patch | 2.06 KB | rkerr |
#13 | database_pgsql_inc_handles.patch | 1.07 KB | rkerr |
#12 | database_mysql_inc_handles.patch | 2.63 KB | rkerr |
#10 | database-inc-4.7cvs.patch | 3.62 KB | rkerr |
Comments
Comment #1
rkerr CreditAttribution: rkerr commentedAttaching PostgreSQL patch file for database.pgsql.inc
Comment #2
rkerr CreditAttribution: rkerr commentedIssue description should say .. "called withOUT arguments" :)
Comment #3
rkerr CreditAttribution: rkerr commentedThis should probably also include the fixed db_escape_string() for mysql to use
global $active_db;
mysql_real_escape_string($text, $active_db);
instead of the current (as of 4.6.3) addslashes function.
Comment #4
Cvbge CreditAttribution: Cvbge commentedHi.
What about mysqli patch?
Connection part:
+ $connection = pg_connect($conn_string) or die(pg_last_error($connection));
+ $connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE) or die(mysql_error($connection));
If *_connect() function fails it returns FALSE. Do pg_last_error() or mysql_error() work when you give them FALSE? I doubt it (it does not work for postgresql at least; php.net documentation is wrong)
(Current code is wrong too IMO)
Other than that, seems ok.
Comment #5
rkerr CreditAttribution: rkerr commentedYou're right about the connect() failing. It's pointless to check for an error when the connection wasn't even made.
I hadn't considered mysqli because I was only looking at 4.6. . . but it looks like this issue still applies to 4.7 head so I can make more patches.
Comment #6
m3avrck CreditAttribution: m3avrck commentedWill this be backported to 4.6.4? Not sure, but this is a good fix for CVS. How about a MySQLi too and just one patch to fix them all? :-)
Comment #7
rkerr CreditAttribution: rkerr commentedThe patches I originally attached are 4.6.3... But I'll repatch against 4.6.4 as well as 4.7 HEAD (including mysqli version). That seems to make the most sense.
Comment #8
rkerr CreditAttribution: rkerr commentedLooks like the mysqli file in 4.7 HEAD already has $active_db for all the functions.
So only mysql and pgsql need to be patched.
Comment #9
rkerr CreditAttribution: rkerr commentedRan "diff -rupN old new > tree.diff" between the tarball source trees for 4.6.4 against a copy with my updates to database.mysql.inc and database.pgsql.inc.
Attaching patch file for 4.6.4...
Comment #10
rkerr CreditAttribution: rkerr commentedRan "diff -rupN old new > tree.diff" between the tarball source trees for 4.7 HEAD (CVS) against a copy with my updates to database.mysql.inc and database.pgsql.inc.
Attaching patch file for 4.7 HEAD (CVS)...
Comment #11
rkerr CreditAttribution: rkerr commentedComment #12
rkerr CreditAttribution: rkerr commentedNew patches to sync with HEAD
Comment #13
rkerr CreditAttribution: rkerr commentedNew patch to sync with HEAD (postgresql version)
Comment #14
Dries CreditAttribution: Dries commentedCommitted to HEAD. Thanks.
Comment #15
rkerr CreditAttribution: rkerr commentedAttaching patch against DRUPAL-4-6 cvs for Mysql.
Comment #16
rkerr CreditAttribution: rkerr commentedAttaching patch against DRUPAL-4-6 cvs for PostgreSQL.
Comment #17
Dries CreditAttribution: Dries commentedCommitted to DRUPAL-4-6. Thanks.
Comment #18
rkerr CreditAttribution: rkerr commentedLovely! Many thanks.
Comment #19
(not verified) CreditAttribution: commented