Duplicate entry warnings running cron

robertDouglass - October 4, 2008 - 09:48
Project:Memetracker
Version:6.x-1.1-alpha6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

user warning: Duplicate entry '172-445' for key 1 query: INSERT INTO machinelearningapi_distance_cache VALUES ( 172, 445, 5.26295375824) in /var/www/acquia-drupal-1.0.0-ISR-update/sites/all/modules/memetracker/machine_learning_api.inc on line 228.
user warning: Duplicate entry '173-177' for key 1 query: INSERT INTO machinelearningapi_distance_cache VALUES ( 173, 177, 2.92246603966) in /var/www/acquia-drupal-1.0.0-ISR-update/sites/all/modules/memetracker/machine_learning_api.inc on line 228.

#1

vinayras - October 16, 2008 - 19:06

I am also getting this error. Can anyone point this issue?

I am using Mysql 4.x and remove the key solves the problem - but i am sure that its is wrong way todo

Thanks
Vinay

#2

vinayras - October 16, 2008 - 19:32

I replaced

         $prev_value = db_result(db_query("SELECT * from
         {machinelearningapi_distance_cache} WHERE cid1 = %d AND cid2 = %d",
         $cid1, $cid2));
        
         if (!$prev_value) {
           db_query("INSERT INTO {machinelearningapi_distance_cache} VALUES (
           %d, %d, %f)", $cid1, $cid2, $score);
         }

with

db_query("DELETE FROM {machinelearningapi_distance_cache} WHERE cid1 = $cid1 AND cid2 = $cid2");
db_query("INSERT INTO {machinelearningapi_distance_cache} VALUES (%d, %d, %f)", $cid1, $cid2, $score);

and it works for me.

Vinay

 
 

Drupal is a registered trademark of Dries Buytaert.