Roundcube Community Forum

 

Problems saving NEW ENTRYS in the Adressbook-MySQL

Started by chichi, November 30, 2010, 06:32:21 AM

Previous topic - Next topic

chichi

Hello I have a promlem with the database I use in Roundcube. I placed all my contacts in the database by using a MySQL-Query in PHPMyAdmin. I can make changes to the contacts within the Roundcube-adressbook, but i cant add a new contact to it -> red Saving Error message on top of roundcube.

I tried to switch the "contact_id" of the contacts to auto-increment, but this is not allowed. MySQL-Error: #1062 - Duplicate entry '1' for key 1

My table look like this:

-- `contacts`

CREATE TABLE IF NOT EXISTS `contacts` (
  `contact_id` int(10) unsigned NOT NULL,
  `changed` datetime NOT NULL default '1000-01-01 00:00:00',
  `del` tinyint(1) NOT NULL default '0',
  `name` varchar(128) NOT NULL default '',
  `email` varchar(128) NOT NULL,
  `firstname` varchar(128) NOT NULL default '',
  `surname` varchar(128) NOT NULL default '',
  `vcard` text,
  `user_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`contact_id`),
  KEY `user_contacts_index` (`user_id`,`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- Constraints der Tabelle `contacts`
--
ALTER TABLE `contacts`
  ADD CONSTRAINT `user_id_fk_contacts` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;

Is there a way to add to the prefilled database new entrys.  :confused:
Is auto-increment the solution, I could not get it working? How can I give the database the info to keep adding new entrys beginning with contact_id = 122, because the there are already entrys from 1-121 in the database.

Update: Now I found out how to add manually an entry: by adding a entry with MySQL with writing the contact_id = 122 manually. This shows me that the database does not know which id is next (like auto increment). How can I solve this? How is the adressbook managed to add with the next bigger number?

save.inc of the adressbook looks like this

// insert record and send response
  if (!$plugin['abort'] && ($insert_id = $CONTACTS->insert($a_record)))
  {
    // add contact row or jump to the page where it should appear
    $CONTACTS->reset();
    $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);

    rcmail_js_contacts_list($result, 'parent.');
    $OUTPUT->command('parent.contact_list.select', $insert_id);

My MySQL-database does not know the number of entrys --> I cant add new entrys. What can Ido with this parent row?

dshepherd

You could try setting the contact_id field to auto increment and then executing the following statement in phpMyAdmin, which will set the auto increment to start at row 123.

alter contacts auto_increment = 123;

chichi

Thanks for your help. I tried this, but setting the contact_id field to auto increment is not possible. I even tried it with a primary key and then setting to auto increment. Its not working. Error message:

ALTER TABLE `contacts` CHANGE `contact_id` `contact_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT

MySQL meldet: Dokumentation
#1062 - Duplicate entry '1' for key 1


:(

dshepherd

#3
Setting the contact_id to auto increment will only be possible if all the current contact_id values are unique. You'll need to manually scan through all the rows in the table and check that there are no duplicates. This should be pretty quick to do if you order the table by contact_id asc. You'll then need to change the contact_id for any duplicates that exist.

You can then set the contact_id to auto increment and run the query above, changing the auto increment number to reflect any duplicates found.

chichi

Thanks I had one duplicate and now its working (auto-increment). Thanks for your help. :D