我正在从 Perl 插入 mysql 数据库。第一次插入后出现重复错误。这是我用于插入的代码。我正在从 json 响应中提取一个 id。我在代码下面收到了我收到的输出,
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
这里是我收到的输出。 (返回没有复制到正确的位置。因此下面的内容看起来不正确,但正确的数据在那里)。这就像 133
我的 $query = $db->do($query_insert);
id=2576246314
查询插入 = INSERT INTO 日历 (id) VALUES (2576246314)
查询 = 1
ID = 2576246678
查询插入 = INSERT INTO 日历 (id) VALUES (2576246678)
DBD::mysql::db 失败:./calendar_run.pl 第 133 行的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576246781
查询插入 = INSERT INTO 日历 (id) VALUES (2576246781)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576247610
查询插入 = INSERT INTO 日历 (id) VALUES (2576247610)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576247737
查询插入 = INSERT INTO 日历 (id) VALUES (2576247737)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576247756
查询插入 = INSERT INTO 日历 (id) VALUES (2576247756)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576247766
查询插入 = INSERT INTO 日历 (id) VALUES (2576247766)
DBD::mysql::db 失败:./calendar_run.pl 第 133 行的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576248369
查询插入 = INSERT INTO 日历 (id) VALUES (2576248369)
DBD::mysql::db 失败:./calendar_run.pl 第 133 行的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576248388
查询插入 = INSERT INTO 日历 (id) VALUES (2576248388)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576248660
查询插入 = INSERT INTO 日历 (id) VALUES (2576248660)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576249706
查询插入 = INSERT INTO 日历 (id) VALUES (2576249706)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
id=2576250254
查询插入 = INSERT INTO 日历 (id) VALUES (2576250254)
DBD::mysql::db 执行失败:./calendar_run.pl 第 133 行处的键“PRIMARY”重复条目“2147483647”。
查询=
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 = INSERT 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 =
发布评论
评论(2)
听起来 id 的类型太短了。 “重复条目”消息中的值 (2147483647) 是最大有符号 32 位整数值。尝试使用较大尺寸的 ID。
It sounds like the type for id is too short. That value in your "duplicate entry" message (2147483647) is the maximum signed 32-bit integer value. Try using a larger size for ID.
我使用 DBD::MySQL 遇到了同样的错误。这是我发现的:“Perl 将返回的值存储为字符串,但当您在数字上下文中使用这些值时,它会自动将它们转换为数字。这将导致它们被“截断”为 2147483647,因为 Perl 使用带符号的 LONG 值来存储这样的数字。” (此处:http://www.tol.it/doc/MySQL/chapter7.html< /a>)。
但我还没有发现任何公共错误。
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.