I have a Drupal Site A that shares the users table of Drupal Site B. The Site A settings.php file has the following entry for $db_prefix:
$db_prefix = array(
...
"users" => "pvun.",
"sequences" => 'pvun.'
...
);
There are problems, however, when a new user gets created in Site A. I get a duplicate entry error. After investigating, I saw the following entry in the id column of my sequences table: pvun.users_uid. It's value is set to 1.
I investigated the problem and it stems from the fact that the db_prefix_tables() function, which gets called indirectly by the db_next_id({users}_uid) line in the user.module, does not take into account sites sharing tables.
I think the db_next_id() function needs to be rewritten to hanlde the case of sites sharing tables. A test would need to be run to determine if the prefix ended in a '.' or not.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | shared_tables_2.patch | 1.81 KB | Steve Dondley |
| #3 | shared_tables_1.patch | 1.24 KB | Steve Dondley |
| #2 | shared_tables_0.patch | 2.31 KB | Steve Dondley |
| #1 | shared_tables.patch | 2.29 KB | Steve Dondley |
Comments
Comment #1
Steve Dondley commentedOK, here's a first go at a patch. Most of the changes are made to the db_prefix_tables() function. The overall behavior of that function is determined by a new argument passed to it, $next_id.
If $next_id is set to FALSE
or
it's set to TRUE by the db_next_id() and the last character in the db_prefix is not equal to '.' (signifying that it is not a tabled shared between two databases), the module behaves the same.
However, if it's set to TRUE and the db_prefix does end in '.' (signifying that it is a shared table), the function simply removes the curly braces.
Comment #2
Steve Dondley commentedUse this patch instead. Fixed a bug.
Comment #3
Steve Dondley commentedHere's a much cleaner patch. Thanks to Java_ for bringing some helpful info about this bug and pointing out the obvious to me.
Comment #4
Steve Dondley commentedLet's try this again. Last patch wouldn't work for any site that used table prefixes. I think this patch should do it. Someone should definitely review it, however.
Comment #5
killes@www.drop.org commentedSteve and I resolved this to be a docs issue. Steve, will you provide better docs?
Comment #6
Steve Dondley commentedI already did. Forgot to close this out. See http://drupal.org/node/22268