WIN 64草莓Perl DBI没有错误报告错误仍未解决



自2011年以来一直在处理此问题。通常能够围绕它进行工作。现在已经出现了我真的需要能够处理错误的情况,我在想,人们多年来都知道这个问题,这似乎是修复列表中的那种事情,但是最新的DBI升级而且问题仍然没有解决。是否有人找到了工作人员,或者知道如何入侵库并在发生错误时携带DBI :: ERRSTR来携带值?

这是我的代码(是的,我知道带有空白密码的问题):

use strict;
use DBI;
use DBD::mysql;
use Data::Dumper;
my $platform = "mysql";
my $database = "test";
my $host = "localhost";
my $port = "3306";
my $user = "root";
my $pw = "";
my $dsn;
$dsn = "dbi:mysql:$database:$host:$port";
my $DBI_connect = DBI->connect($dsn, $user, $pw, {RaiseError => 1,PrintError=>1}) or die "$DBI::errstrn"; 
my $sql_str = 'INSERT INTO test_tablexx ('xxx) VALUES (blah)';
my $DBI_query_handle = $DBI_connect->prepare( $sql_str ) or die "Can't prepare SQL statement: $DBI::errstrn";
my $return = $DBI_query_handle->execute() or warn "$DBI::errstrn";
print "sys arry".Dumper $@."n";
print "err: ".$DBI_query_handle->err."n";
print "errstr: ".$DBI_query_handle->errstr."n";
print "state: ".$DBI_query_handle->state."n";
print "err: ".$DBI_connect->err."n";
print "errstr: ".$DBI_connect->errstr."n";
print "state: ".$DBI_connect->state."n";
print Dumper $DBI_query_handle;
print "nn-------------------------------------------------------------------nn";
my  $hash = DBI->installed_versions;
print Dumper $hash;

现在,该表是无效的,该列的中间有一个报价,值是一个未引用的字符串。应该像圣诞树一样点亮错误处理。

如果我将Execute语句更改为" $ dbi :: errstr n";它会死,但根本没有消息。

但这是结果:

sys arry$VAR1 = '
';
err:
errstr:
state:
err:
errstr:
state:
$VAR1 = bless( {}, 'DBI::st' );
-------------------------------------------------------------------
$VAR1 = {
     'DBD::SQLite' => '1.37',
     'DBD::ExampleP' => '12.014311',
     'DBD::Sponge' => '12.010003',
     'DBD::Pg' => bless( {
                           'original' => '2.19.3',
                           'qv' => 1,
                           'version' => [
                                          2,
                                          19,
                                          3
                                        ]
                         }, 'version' ),
     'DBD::Gofer' => '0.015327',
     'DBD::DBM' => '0.08',
     'DBD::mysql' => '4.022',
     'DBD::ADO' => '2.99',
     'DBD::ODBC' => '1.41',
     'DBI' => '1.631',
     'DBD::File' => '0.42'
   };

最后一个位是版本信息的转储,因此您可以看到我对DBI安装的最新信息。

现在,当我将数据库更改为不存在的事物时,我的$ database =" testxxx",它确实确实会发出错误:

DBI connect('testxx:localhost:3306','root',...) failed: Unknown database 'testxx' at ../sql_tester.pl line 17.

为您提供最后的信息。

print Dumper $DBI::lasth;
$VAR1 = bless( {
            'FetchHashKeyName' => 'NAME',
            'TraceLevel' => 0,
            'ImplementorClass' => 'DBD::mysql::db',
            'dbi_imp_data' => undef,
            'State' => undef,
            'Username' => 'root',
            'Errstr' => undef,
            'ChildHandles' => [
                                bless( {}, 'DBI::st' )
                              ],
            'Driver' => bless( {
                                 'Attribution' => 'DBD::mysql by Patrick Galbraith',
                                 'FetchHashKeyName' => 'NAME',
                                 'TraceLevel' => 0,
                                 'ImplementorClass' => 'DBD::mysql::dr',
                                 'State' => undef,
                                 'Version' => '4.022',
                                 'Errstr' => undef,
                                 'ChildHandles' => [
                                                     bless( {}, 'DBI::db' )
                                                   ],
                                 'Name' => 'mysql',
                                 'Err' => undef
                               }, 'DBI::dr' ),
            'Statement' => 'INSERT INTO test_tablexx ('xxx) VALUES (blah)',
            'Name' => 'test:localhost:3306',
            'dbi_connect_closure' => sub { "DUMMY" },
            'Err' => undef
          }, 'DBI::db' );

所以请让好人这样做,当编程的最重要原则之一 - 错误处理 - 无法在我的程序的核心模块中工作时,我该怎么办?!

根据DBD :: mysql ChangElog,这是在v4.024中修复的(2013年9月17日发布)。您的输出表明您仅使用v4.022,因此您需要升级DBD :: mySQL。您可以在此处找到详细信息的错误报告。

最新更新