PHP errors "Duplicate entry 'UID' for key 'PRIMARY' query..."
roball - June 15, 2009 - 11:12
| Project: | RealName |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | anarchman |
| Status: | postponed (maintainer needs more info) |
Description
At admin/reports/dblog I have several logs of an php error like this:
Duplicate entry '489' for key 'PRIMARY' query: INSERT INTO realname (uid, realname) VALUES (489, 'Jane Doe') in /var/www/drupal-6.12/includes/common.inc on line 3476.Don't know what these errors are caused by. I am using RealName 6.x-1.x-dev (2009-May-13) with Drupal 6.12.

#1
i think that error may occur when a user account is created, but the fields which realname is set to use for realname creation have no content.
example:
realname uses a "last name" field to create the realname, but when the user account is created that field has no content
I have that issue myself, attached patch should fix it - check if the realname is an empty string, then use UPDATE instead of INSERT
#2
I'm not sure because my log is full of these PHP errors, but the users do have their realname fields set to proper values. See the attached screenshot of admin/reports/dblog.
Now with the (patched) "common.inc" of Drupal 6.13, the line number is 3492, which is the first line of
if (db_query($query, $values)) {if ($serials) {
// Get last insert ids and fill them in.
foreach ($serials as $field) {
$object->$field = db_last_insert_id($table, $field);
}
}
}
else {
$return = FALSE;
}
#3
#4
when saving a user I have a similar problem but it's when the realname field in the database is set to '' for whatever reason, not the actual result of _realname_make_name
<?php$result = _realname_make_name($account);
if (empty($result)) return $account->name;
if (!db_result(db_query("SELECT uid from {realname} WHERE uid=%d", $account->uid))) {
db_query("INSERT INTO {realname} (uid, realname) VALUES(%d, '%s')", $account->uid, $result);
} else {
db_query("UPDATE {realname} SET realname='s' where uid=%d", $result,$account->uid);
}
return $result;
}
?>
that was my solution
#5
Nancy, do you think about committing the solution posted above?
#6
The changes in #4 worked for me.
Here's a patch.
#7
Thanks
#8
I am still getting the same errors with the latest dev version (2009-Oct-09) of RealName and D6.14.
#9
Are you getting errors from a fresh 6.x install on a fresh database, i.e. are you able to reproduce this error or is it just on your database? If you get this on a fresh install I will attempt to reproduce, otherwise I would look at try uninstall/reinstall to see if rebuilding the tables does any good.
#10
I have completely uninstalled RealName, freshly installed v6.x-1.3 and rebuilt the realname table. Let's see if that finally solved the problem.
#11
Cool, thanks. Let me know if you receive the error again. Thanks.
#12
#13
Hm, I am still observing these error messages, but not every time a user logs in. In addition to the messages referring to
common.inc, there are also messages referring torealname.module, like this:Duplicate entry '489' for key 'PRIMARY' query: INSERT INTO realname (uid, realname) VALUES(489, 'Jane Doe') in /var/www/drupal-6.14/sites/all/modules/realname/realname.module on line 707.Line 707 of
realname.moduleis withinif (!db_result(db_query("SELECT uid FROM {realname} WHERE uid=%d", $account->uid))) {db_query("INSERT INTO {realname} (uid, realname) VALUES(%d, '%s')", $account->uid, $result);
}
#14
Can you try making a backup of your realname table, then empty it and then have some users login/logout/login again and see if the problem persists.
#15
Just did it. Now I have to watch the dblog for some time to find out if that helped.