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

black silence - July 22, 2009 - 13:18
Title:PHP errors "Duplicate entry '489' for key 'PRIMARY' query..."» PHP errors "Duplicate entry '489' for key 'PRIMARY' query..."
Status:active» needs review

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

AttachmentSize
realname-492066.patch 698 bytes

#2

roball - July 22, 2009 - 17:29

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;
  }

AttachmentSize
Duplicate entry PHP errors.png 21.71 KB

#3

roball - July 22, 2009 - 20:02
Title:PHP errors "Duplicate entry '489' for key 'PRIMARY' query..."» PHP errors "Duplicate entry 'UID' for key 'PRIMARY' query..."

#4

hefox - August 10, 2009 - 03:56

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

roball - August 10, 2009 - 06:44

Nancy, do you think about committing the solution posted above?

#6

tim.plunkett - October 5, 2009 - 15:20
Status:needs review» reviewed & tested by the community

The changes in #4 worked for me.
Here's a patch.

AttachmentSize
realname_492066.patch 1.14 KB

#7

NancyDru - October 8, 2009 - 20:46
Status:reviewed & tested by the community» fixed

Thanks

#8

roball - October 12, 2009 - 23:15
Status:fixed» active

I am still getting the same errors with the latest dev version (2009-Oct-09) of RealName and D6.14.

#9

anarchman - October 14, 2009 - 23:34

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

roball - October 15, 2009 - 14:07

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

anarchman - October 18, 2009 - 06:54

Cool, thanks. Let me know if you receive the error again. Thanks.

#12

anarchman - October 18, 2009 - 06:54
Assigned to:Anonymous» anarchman
Status:active» postponed (maintainer needs more info)

#13

roball - October 18, 2009 - 08:03

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 to realname.module, like this:

Duplicate entry &#039;489&#039; for key &#039;PRIMARY&#039; query: INSERT INTO realname (uid, realname) VALUES(489, &#039;Jane Doe&#039;) in /var/www/drupal-6.14/sites/all/modules/realname/realname.module on line 707.

Line 707 of realname.module is within

  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);
  }

#14

anarchman - November 16, 2009 - 05:29

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

roball - November 19, 2009 - 23:32

Just did it. Now I have to watch the dblog for some time to find out if that helped.

 
 

Drupal is a registered trademark of Dries Buytaert.