免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2556 | 回复: 3
打印 上一主题 下一主题

Duplicate entry 问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-22 15:10 |只看该作者 |倒序浏览
在INSERT插入一个数据的时候,出现这样的问题:
Duplicate entry  'clk5' for key 1;
请问这是什么问题啊?

论坛徽章:
0
2 [报告]
发表于 2008-03-22 15:54 |只看该作者

代码和错误

#!/usr/bin/perl
#write_data.pl
use warnings;
use strict;

use DBI;

our @clk_name                                   = ();  # the name of the variables below are defferent from ISSAC block
our @clk_width                                  = ();
our @clk_reset_value                            = ();
our @clk_description                            = ();
#@clk_name =("clk","clk5");
@clk_name =("clk5","clk7","clk8");
@clk_width=("1","1","1");      
@clk_reset_value=("0","0","0");
@clk_description=("input","input","input");

&write_data;

sub write_data {
my ($dbh,$sth,$sql,$sql2,$sql3,$i);
# create a statement in $sth
$dbh=DBI->connect('dbi:mysql:mydatabase','root','123456',{PrintError=>0,RaiseError=>1});

#prepare the statement
$i=0;
$sql="insert into node_tag_clock_input (signal_name,signal_width,signal_reset_value,signal_description) values('$clk_name[$i]','$clk_width[$i]','$clk_reset_value[$i]','$clk_description[$i]')";
$sql2="select signal_name from node_tag_clock_input";
$sql3="update node_tag_clock_input set signal_width = '$clk_width[$i]',signal_reset_value='$clk_reset_value[$i]',signal_description='$clk_description[$i]' where signal_name='$clk_name[$i]'";

for ($i=0;$i<=(@clk_name-1);$i++) {
$sth=$dbh->prepare($sql2);
#execute the statement
$sth->execute or die $dbh->errstr;
print $clk_name[$i],$clk_width[$i],$clk_reset_value[$i],$clk_description[$i],$i;
print "a\n";
my $clk_name_2;
while (my ($clk_name_1)=$sth->fetchrow_array){
        $clk_name_2=$clk_name_2 . $clk_name_1;
        #print "**" . $clk_name_2 ."**\n";
}

   #print "aa\n";
if ($clk_name_2 =~ m/$clk_name[$i]/) {
          #print "aaa\n";
        $dbh->do($sql3);
} else {
   # print "aaaa\n";
  $dbh->do($sql);
}
}

#while (my ($clk_name_1,$clk_width_1)=$sth->fetchrow_array) {
# printf("\$clk_name=%s,\$clk_width=%d\n",$clk_name_1,$clk_width_1);
#}
#
$sth->finish;
$dbh->disconnect;
}

问题:DBD::mysql::db do failed:duplicate entry 'clk5' for key 1 at e:\perl_dbi_test_code\write_data.pl line 50.

论坛徽章:
0
3 [报告]
发表于 2008-03-22 17:53 |只看该作者
Duplicate entry  'clk5' for key 1;
clk5这一列要求唯一值,不允许重复。这说明已经数据中中已经有这个值了,所以不能插入

论坛徽章:
0
4 [报告]
发表于 2008-03-23 09:42 |只看该作者
如果你硬是要插的话,先屏蔽掉唯一索引。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP