user warning: Duplicate entry '2' for key 1 query: INSERT INTO privatemsg (id, author, recipient, subject, message, timestamp, newmsg, hostname, format) VALUES (2, 1, 2, 'test', 'test', 1172460676, 1, '61.29.36.18', 1) in includes/database.mysql.inc on line 172.

Comments

neubreed’s picture

For some reason the sequences table went back to zero for the privatemsg_id value. Do you think this was a one off?

airblaster’s picture

If I'm not mistaken the install script ignores table prefixes, which causes the sequences table beeing filled with wrong data.

mindless’s picture

Assigned: Unassigned » mindless

Are you using postgresql DB and you have a table prefix? The upgrade code is in fact missing the prefix for this db type, I'll fix that. Please confirm if this is your configuration so we can tell if there is also another problem.

mindless’s picture

No, I take that back.. looking closer I think the prefix handling is ok in the upgrade code. airblaster, where do you see missing prefix?

neubreed, what is your db type and do you use a table prefix?
if mysql, what do you get for SELECT * from sequences where name like '{privatemsg%';
and SELECT max(id) from privatemsg;
(add prefix to table names if needed)

airblaster’s picture

I've done some testing to get the actual error messages.
I get the following error messages after executing the update from 1.3 to 1.4:

 user warning: Table 'fmweb_test.privatemsg' doesn't exist query: SELECT max(id) FROM privatemsg in P:\www\FM\test\htdocs\drupal\includes\database.mysql.inc on line 172.
user warning: Table 'fmweb_test.privatemsg_folder' doesn't exist query: SELECT max(fid) FROM privatemsg_folder in P:\www\FM\test\htdocs\drupal\includes\database.mysql.inc on line 172.
 The following queries were executed
privatemsg module
Update #2
ALTER TABLE {privatemsg} MODIFY id int(10) unsigned NOT NULL
INSERT INTO {sequences} (name, id) VALUES ('privatemsg_id', 0)
ALTER TABLE {privatemsg_folder} MODIFY fid int(10) unsigned NOT NULL
INSERT INTO {sequences} (name, id) VALUES ('privatemsg_folder_fid', 0)
ALTER TABLE {privatemsg_archive} MODIFY id int(10) unsigned NOT NULL

Database: MySQL
Test data: 2 folders and 2 private messages

After the update, the follwing sequences are in drupal_sequences:
privatemsg_folder_fid with value 0
privatemsg_id with value 0

Note that (unlike most other entries in the sequences table) these entries don't have any table prefix.

mindless’s picture

What is your drupal version and php version? All the queries here have { } around the table names, so I don't know why the prefix wouldn't be applied.

mindless’s picture

Also, what is your $db_prefix definition from your settings file?

airblaster’s picture

My Drupal Version is 5.1, $db_prefix is 'drupal_'.
I've used VertrigoServ 2.14 (on Windows XP) for the tests, which comes with PHP 5.2.0.

I've not looked at the code for sequences, but could the problem possibly be caused by the values of the inserts I quoted before?:

INSERT INTO {sequences} (name, id) VALUES ('privatemsg_id', 0)
INSERT INTO {sequences} (name, id) VALUES ('privatemsg_folder_fid', 0)

(e.g. with $db_prefix='drupal_', should it possibly be drupal_privatemsg_id instead of privatemsg_id?)

mindless’s picture

Title: SQL error with latest version » SQL error after upgrade if using db_prefix
Status: Active » Fixed

ack, got it. i didn't realize that { } meant something in PHP strings.. fixed in DRUPAL-5 branch. i'll do a new release asap so others with db_prefix don't hit this. thanks for the debug help!

neubreed’s picture

Sorry for the late reply, had no net for a few days.. db type is MySQL.. better late than never ;)

Anonymous’s picture

Status: Fixed » Closed (fixed)