Asnwering a friend request positive leads on our site www.daimonin.org to this error message:

user warning: Duplicate entry '0' for key 'PRIMARY' query: INSERT INTO flag_friend_message VALUES(0, 'check check') in .. /modules/flag_friend/flag_friend.module on line 416.

That happens when i put in some text.

In the 2nd try without text it works.

But: The page is after the add not redirected right - it shows the yes/no page over and over.
If you add the friend over and over the other user is also shown in YOUR approval queue.

It don't harms the friend system at all - just senseless listings.

Feel free to register 2 testing account on the site if you like.

We use beta1 - is it recommend to use the dev package?

Comments

sirkitree’s picture

Status: Active » Needs review

I see the problem, fcid was type 'int' instead of 'serial' which allows it to auto-increment. I made this change in cvs, please do a checkout from cvs, or wait for the changes to roll into the -dev package and test it out for me by then re-installing the module or hitting update.php and try this functionality again. Please report back.

michtoen’s picture

ok, i update to the next dev package release and report then back

tracerhand’s picture

i've uploaded to this new dev on when i do a db update i get:

user warning: Incorrect table definition; there can be only one auto column and it must be defined as a key query: ALTER TABLE flag_friend_message ADD `fcid` INT auto_increment DEFAULT NULL in /var/www/vhosts/howdidyoumakethat.com/httpdocs/includes/database.mysql-common.inc on line 298.

...

The following queries were executed
flag_friend module
Update #6000

* ALTER TABLE {flag_friend_message} DROP fcid
* Failed: ALTER TABLE {flag_friend_message} ADD `fcid` INT auto_increment DEFAULT NULL

tracerhand’s picture

And when I add a message to a friend request, using the brand-new dev, I get:

user warning: Column count doesn't match value count at row 1 query: INSERT INTO flag_friend_message VALUES(73, 'I love you bro') in /var/www/vhosts/howdidyoumakethat.com/httpdocs/sites/all/modules/flag_friend/flag_friend.module on line 416.

sirkitree’s picture

Version: 6.x-1.0-beta1 » 6.x-1.x-dev

Ah, I forgot to reassign it as the primary key when adding it back in. I changed it around and made sure to test it this time. Thank you for your testing.

sirkitree’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

dicreat’s picture

Status: Closed (fixed) » Active

I'm using latest 6.x-1.x-dev with fresh install and I have this error when user approve friend's request:

Duplicate entry '0'; for key 'PRIMARY' query: INSERT INTO flag_friend_message VALUES(0, 'message') in /sites/all/modules/flag_friend/flag_friend.module at line 442.

sirkitree’s picture

Status: Active » Postponed (maintainer needs more info)

@dicreat - can you post lines 54 through 66 of the flag_friend.install file that you have on your system? This is a serialized field and should never hold 0 within it. I'm thinking you have an outdated version somehow.

dicreat’s picture

  $schema['flag_friend_message'] = array(
    'fields' => array(
      'fcid' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'message' => array(
        'type' => 'text',.
        'not null' => TRUE
      )
    ),
    'primary key' => array('fcid'),
  );
sirkitree’s picture

I'm not sure why that period is on the line 'type' => 'text',. but the rest of this looks fine and should be incrementing as planned.

Do you have access to your database where you can verify that the field 'fcid' is indeed an auto-increment field?

If you have access to mysql command line, you can run the following:

mysql> desc flag_friend_message;

And should receive output like this:

+---------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------------------+------+-----+---------+----------------+
| fcid | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| message | text | NO | | | |
+---------+----------------------+------+-----+---------+----------------+

The 'Extra' column should say 'auto_increment'.

dicreat’s picture

This is my result:
Field Type Null Key Default Extra
fcid int(11) NO PRI NULL auto_increment
message text NO NULL

I just make clean install the latest dev-version (2009-Jun-10) and I have the same error and the same table structure:
Field Type Null Key Default Extra
fcid int(11) NO PRI NULL auto_increment
message text NO NULL

When user1 send friend request to user2 with text message, there is no error and text message successfully insert into database. Then, if user2 accept friend request from user1 and enter a text message, I see the error "Duplicate entry". If user2 don't enter a text - no error happend.

sirkitree’s picture

What version of Flag module are you using?

Also, make sure that your flag_content table has an fcid as that is where it gets it.

Hrmm... that being said, I'm not so sure that field should be an auto-increment - but i'm not sure it hurts either.

dicreat’s picture

I'm using Flag module version 6.x-1.1.

flag_content table:
Field Type Null Key Default Extra
fcid int(10) unsigned NO PRI NULL auto_increment
fid smallint(5) unsigned NO MUL 0
content_type varchar(32) NO MUL
content_id int(10) unsigned NO 0
uid int(10) unsigned NO 0
timestamp int(10) unsigned NO 0

sirkitree’s picture

Status: Postponed (maintainer needs more info) » Active

Wow, I'm at a loss - the only thing I could think of was that the function flag_friend_get_fcid() was somehow failing on you, but by looking at your table definition for the flag_content table, I can't see how. Like I said, it's working for me - both on a complex platform with many modules and with a fresh install of just flag_friend and dependencies.

The next step would be to print $fcid after each call to flag_friend_get_fcid() and determine exactly where it's getting that 0 for $fcid.

andypost’s picture

Maybe this depends on #488106: Error when approve friend request

Because $user undefined and messages going to be inserted with fcid = 0 or NULL

andypost’s picture

Status: Active » Closed (duplicate)

Marked as duplicate of #488106: Error when approve friend request

Error happens when someone aprove pending request with message because ATM is broken in flag_friend_form_submit()

sirkitree’s picture

Status: Closed (duplicate) » Fixed

This should be fixed now.

andypost’s picture

Still not fixed but should go to #488106: Error when approve friend request

Status: Fixed » Closed (fixed)

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