开发者

dup entry when doing insert into mysql from perl

i'm doing an insert into a mysql db from perl. i'm getting a duplicate error after the 1st insert. here is the code i'm using for the insert. i'm pulling an id from a json response. i have output of what i'm receiving below the code

  foreach my $listing(@{$json_text->{listings}})
    {
      my $id = $listing->{id};
   print "\nid = $id \n";


    # DO THE INSERT
    my $query_insert = "INSERT INTO calendar (id) VALUES ($id)";
    print "query insert = $query_insert \n";
    my $query = $db->do($query_insert); 
   print "query = $query \n";

    } #end foreach

here is the output i'm receiving. (returns didn't copy over right. so the below looks off, but the right data is there). this is like 133 my $query = $db->do($query_insert);

id = 2576246314 query insert = INSERT INTO calendar (id) VALUES (2576246314) query = 1

id = 2576246678 query insert = INSERT INTO calendar (id) VALUES (2576246678) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576246781 query insert = INS开发者_C百科ERT INTO calendar (id) VALUES (2576246781) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247610 query insert = INSERT INTO calendar (id) VALUES (2576247610) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247737 query insert = INSERT INTO calendar (id) VALUES (2576247737) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247756 query insert = INSERT INTO calendar (id) VALUES (2576247756) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576247766 query insert = INSERT INTO calendar (id) VALUES (2576247766) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576248369 query insert = INSERT INTO calendar (id) VALUES (2576248369) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576248388 query insert = INSERT INTO calendar (id) VALUES (2576248388) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576248660 query insert = INSERT INTO calendar (id) VALUES (2576248660) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576249706 query insert = INSERT INTO calendar (id) VALUES (2576249706) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =

id = 2576250254 query insert = INSERT INTO calendar (id) VALUES (2576250254) DBD::mysql::db do failed: Duplicate entry '2147483647' for key 'PRIMARY' at ./calendar_run.pl line 133. query =


It sounds like the type for id is too short. That value (2147683647) is the maximum signed 32 bit integer value. Try using a larger size for id.


I got the same error using DBD::MySQL. Here is what I found: "Perl stores returned values as strings, but will automatically convert them to numbers when you use the values in a numeric context. This will cause them to be "truncated" to 2147483647 since Perl uses a signed LONG value to store such numbers." (here: http://www.tol.it/doc/MySQL/chapter7.html). But I haven't found any public bug for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜