INSERT INTO profile_values fails
| Project: | Pubcookie |
| Version: | 6.x-1.1 |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Drupal 6.2
Profile module enabled, two profile fields created to load from LDAP data
pubcookie-6.x-1.1 enabled, configured to use LDAP
# user warning: Duplicate entry '27-5' for key 1 query: INSERT INTO profile_values (fid, uid, value) VALUES (5, 27, 'my department') in /home/web/html/sites/all/modules/pubcookie/pubcookie.module on line 180.
# user warning: Duplicate entry '27-6' for key 1 query: INSERT INTO profile_values (fid, uid, value) VALUES (6, 27, 'my phone number') in /home/web/html/sites/all/modules/pubcookie/pubcookie.module on line 180.
It appears that the empty profile fields are created before pubcookie tries to fill them and the INSERT statement doesn't set the value. I got rid of the warnings and filled the value fields by modifying the INSERT statement from
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $data->fid, $user->uid, $pubcookie_record[$key]);
to
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s') ON DUPLICATE KEY UPDATE value = '%s'", $data->fid, $user->uid, $pubcookie_record[$key], $pubcookie_record[$key]);
but the MySQL manual says "you should try to avoid using an ON DUPLICATE KEY clause on tables with multiple unique indexes" like profile_values
