zoukankan      html  css  js  c++  java
  • eval 捕获dbi错误

    [root@dr-mysql01 ~]# cat t2.pl 
    use DBI;
    my $dbUser='zabbix';
    my $user="root";
    my $passwd="1234567";
    my $TABLE_NAME='history_uint';
    my $date='201605';
    my $dbh  = DBI->connect("dbi:mysql:database=zabbix;host=192.168.32.55;port=3306",$user,$passwd,{RaiseError => 1}) or die "can't connect to database ". DBI-errstr;
    my $hostSql = qq{select TABLE_NAME,PARTITION_NAME from INFORMATION_SCHEMA.PARTITIONS where TABLE_NAME='$TABLE_NAME' and PARTITION_NAME like "p$date%";};
    print "$hostSql is $hostSql
    ";
    my ($a1, $a2);
    #if ($a1){
    my $selStmt = $dbh->prepare($hostSql);
    $selStmt->execute();
    $selStmt->bind_columns(undef, $a1,$a2);
    print "$a1 is $a1
    ";
    print "$a2 is $a2
    ";
    print $selStmt->fetch();
    print "
    ";
     eval {$selStmt->fetch()};
    print "$@ is $@
    ";;
    print "
    ";
    [root@dr-mysql01 ~]# perl t2.pl 
    $hostSql is select TABLE_NAME,PARTITION_NAME from INFORMATION_SCHEMA.PARTITIONS where TABLE_NAME='history_uint' and PARTITION_NAME like "p201605%";
    $a1 is 
    $a2 is 
    ARRAY(0x2324778)
    $@ is 
    
    
    
    [root@dr-mysql01 ~]# cat t2.pl 
    use DBI;
    my $dbUser='zabbix';
    my $user="root";
    my $passwd="1234567";
    my $TABLE_NAME='history_uint';
    my $date='201604';
    my $dbh  = DBI->connect("dbi:mysql:database=zabbix;host=192.168.32.55;port=3306",$user,$passwd,{RaiseError => 1}) or die "can't connect to database ". DBI-errstr;
    my $hostSql = qq{select TABLE_NAME,PARTITION_NAME from INFORMATION_SCHEMA.PARTITIONS where TABLE_NAME='$TABLE_NAME' and PARTITION_NAME like "p$date%";};
    print "$hostSql is $hostSql
    ";
    my ($a1, $a2);
    #if ($a1){
    my $selStmt = $dbh->prepare($hostSql);
    $selStmt->execute();
    $selStmt->bind_columns(undef, $a1,$a2);
    print "$a1 is $a1
    ";
    print "$a2 is $a2
    ";
    print $selStmt->fetch();
    print "
    ";
     eval {$selStmt->fetch()};
    print "$@ is $@
    ";;
    print "
    ";
    [root@dr-mysql01 ~]# perl t2.pl 
    $hostSql is select TABLE_NAME,PARTITION_NAME from INFORMATION_SCHEMA.PARTITIONS where TABLE_NAME='history_uint' and PARTITION_NAME like "p201604%";
    $a1 is 
    $a2 is 
    
    DBD::mysql::st fetch failed: fetch() without execute() at t2.pl line 19.
    $@ is DBD::mysql::st fetch failed: fetch() without execute() at t2.pl line 19.

  • 相关阅读:
    cmake使用的一些补充
    Visual Studio调试Tersseract
    Python实现重命名一个文件夹下的图片
    TensorFlow:使用inception-v3实现各种图像识别
    TensorFlow:谷歌图像识别网络inception-v3下载与查看结构
    TensorFlow 模型的保存与载入
    TensorFlow使用RNN实现手写数字识别
    TensorFlow卷积神经网络实现手写数字识别以及可视化
    tensorboard可视化
    tensorflow之tensorboard
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350739.html
Copyright © 2011-2022 走看看