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.

Comments

black silence’s picture

Title: PHP errors "Duplicate entry '489' for key 'PRIMARY' query..." » PHP errors "Duplicate entry '489' for key 'PRIMARY' query..."
Status: Active » Needs review
StatusFileSize
new698 bytes

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

roball’s picture

StatusFileSize
new21.71 KB

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;
  }
roball’s picture

Title: PHP errors "Duplicate entry '489' for key 'PRIMARY' query..." » PHP errors "Duplicate entry 'UID' for key 'PRIMARY' query..."
hefox’s picture

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

  $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

roball’s picture

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

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.14 KB

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

nancydru’s picture

Status: Reviewed & tested by the community » Fixed

Thanks

roball’s picture

Status: Fixed » Active

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

coderintherye’s picture

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.

roball’s picture

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.

coderintherye’s picture

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

coderintherye’s picture

Assigned: Unassigned » coderintherye
Status: Active » Postponed (maintainer needs more info)
roball’s picture

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 '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.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);
  }
coderintherye’s picture

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.

roball’s picture

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

coreyp_1’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.03 KB

Thanks to the previous posters for getting us this far on the bug! The patch in #6 should work, but is incomplete because of a few issues. Specifically:

  1. There is a typo in the SQL. "s" should be "%s".
  2. Static caching is not being used. A static variable is declared and tested earlier in the function, but the static variable is never actually set.
  3. The code always issues a SQL query to either INSERT or UPDATE a record. If, however, the realname was correctly set on a previous page view, then why should the query be repeated on every page call for every user that is loaded?

Since the patch in #6 has already been committed, I am attaching a patch against the latest dev. On my site, implementing the attached patch saves me about 30 database calls per page view, and sometimes more.

-Corey

roball’s picture

@ #14-15: That suggestion did not help, unfortunately.

@ #16: Thanks for the revised patch, coreyp_1. I'll apply it and report back if it solved the problem.

roball’s picture

The patch in #16 seems to work fine, however - after monitoring my dblog for a while - I still see some of those "Duplicate entry..." errors.

coderintherye’s picture

I wanted to test out this patch but darn PHP 5.3 on my fresh xampplite install is running into Drupal bugs. I will hopefully test this weekend when I can run it on another install.

YK85’s picture

subscribing

coderintherye’s picture

StatusFileSize
new1.14 KB

Patch had just one very minor issue of missing a space after a comma, otherwise applied cleanly on Drupal 6.x-1.x-dev. So just re-rolling with the space and going to run it through coder again. If that checks out ok I'm going to set to RTBC and hopefully get a comment from NancyDru before committing.

Sorry that this took so long.

coderintherye’s picture

StatusFileSize
new1.14 KB

Oops missed the naming standard, so uploading again with full name. Checked patch through coder and no problems were found.

coderintherye’s picture

Status: Needs review » Reviewed & tested by the community

So current status is just want buy-in from NancyDru and then she can commit it or if she wants I can commit it.

nancydru’s picture

Status: Reviewed & tested by the community » Fixed

With the fixes I have just committed the code is what you show. After the -dev release rolls out, please see if this issue is fixed. If it is not, reopen it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

roball’s picture

Just updated RealName from 6.x-1.3 to the latest 6.x-1.x-dev (2010-May-27). Will have to watch the dblog for a while to see if the warnings are gone.

cjback’s picture

Using RealName 6.x-1.4 Drupal version 6.20
Received same error. Did the fix not get applied to version 6.x-1.4?

roball’s picture

Use the latest official releases: Drupal core 6.28 and Real Name 6.x-1.5. The bug should have been fixed.