SQL Error: Unique key violated for forum_read and forum_notify [message #27842] |
Wed, 28 September 2005 10:53 |
awadallah
Messages: 11 Registered: September 2005 Location: Palo Alto, CA
Karma: 0
|
Junior Member |
|
|
Its a very weird error that only happens when a users trys to post to same topic more than once, sometimes I get the following error for thread_notify:
(/egypt_chat/index.php:200
/egypt_chat/theme/default/post.php:1081
/egypt_chat/theme/default/post.php:3861
/egypt_chat/index.php:1171
) 2000: Unknown MySQL error
Query: INSERT INTO fud26_thread_notify (user_id, thread_id) VALUES (2, 12)
_GET: array ( 't' => 'post', )
_POST: array ( 'msg_subject' => 'Re: التليفزيون', 'msg_icon' ...
Server Version: 4.1.12
and some other times I get the following error for thread_read:
(/egypt_chat/index.php:200
/egypt_chat/index.php:1046
/egypt_chat/theme/default/msg.php:1050
/egypt_chat/index.php:1171
) 2000: Unknown MySQL error
Query: INSERT INTO fud26_forum_read (forum_id, user_id, last_view) VALUES (10, 2, 1127896274)
_GET: array ( 't' => 'msg', 'th' => '12', 'rid' => '2', 'S' ..
Server Version: 4.1.12
or:
(/egypt_chat/index.php:200
/egypt_chat/index.php:1046
/egypt_chat/theme/default/post.php:3867
/egypt_chat/index.php:1171
) 2000: Unknown MySQL error
Query: INSERT INTO fud26_forum_read (forum_id, user_id, last_view) VALUES (10, 2, 1127899088)
_GET: array ( 't' => 'post', )
_POST: array ( 'spell_chk_subject_3' ...
Server Version: 4.1.12
its clear the the forum_id, user_id will be violated in both of these cases (since they are repeat visits) which leads mysql server to return an error.
what is the solution ? I had this problem with 2.6, I upgraded to 2.7.2 and still have this problem. Everything else seems to be working fine, user registration, posting a brand new topic, etc.
thanks,
-- amr
|
|
|
|
Re: SQL Error: Unique key violated for forum_read and forum_notify [message #27860 is a reply to message #27846] |
Wed, 28 September 2005 20:39 |
awadallah
Messages: 11 Registered: September 2005 Location: Palo Alto, CA
Karma: 0
|
Junior Member |
|
|
MySQL optimization is enabled in fudforum.
The error is a unique key violation error (despitate fact that MySQL error message just says unknown error).
does your code depend on the error code returned ? In that case I would have to contact my hosting provider to figure out why the heck the mysql server is replying back with Unknown error.
But I did try the sql statement directly, and when I change one of the userid or forumid it works fine, so it is just about a unique key violation. I am referring to this statement:
INSERT INTO fud26_thread_notify (user_id, thread_id) VALUES (2, 12)
OR
INSERT INTO fud26_forum_read (forum_id, user_id, last_view) VALUES (10, 2, 1127899088)
Thanks,
-- amr
|
|
|
Re: SQL Error: Unique key violated for forum_read and forum_notify [message #27865 is a reply to message #27860] |
Wed, 28 September 2005 22:45 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Fudforum relies on an error code being returned, it is not in your case hence the problem. If you have MySQL 4.1 optimization setting turned on this query shouldn't even happen. Instead the query should have a suffix with ON DUPLICATE KEY UPDATE ...
FUDforum Core Developer
|
|
|
|
|
|
|
|
Re: SQL Error: Unique key violated for forum_read and forum_notify [message #27872 is a reply to message #27842] |
Thu, 29 September 2005 00:48 |
awadallah
Messages: 11 Registered: September 2005 Location: Palo Alto, CA
Karma: 0
|
Junior Member |
|
|
ok, for now, I just changed the db_li function to be as listed below, not clean, but gets the job done till hosting provider figures out why mysql keeps returning 2000 for dupe key.
essentially just added "|| mysql_errno(fud_sql_lnk) == 2000" to the 2nd if condition.
function db_li($q, &$ef, $li=0)
{
$r = mysql_query($q, fud_sql_lnk);
if ($r) {
return ($li ? mysql_insert_id(fud_sql_lnk) : $r);
}
/* duplicate key */
if (mysql_errno(fud_sql_lnk) == 1062 || mysql_errno(fud_sql_lnk) == 2000 ) {
$ef = ltrim(strrchr(mysql_error(fud_sql_lnk), ' '));
return null;
} else {
die(fud_sql_error_handler($q, mysql_error(fud_sql_lnk), mysql_errno(fud_sql_lnk), get_version()));
}
}
|
|
|
|