2014-01-25 40 views
0

自2011年以來一直處理此問題。通常能夠解決此問題。現在出現了這樣一種情況:我真的需要能夠處理錯誤,而且我在想,人們多年以來就知道這個問題,看起來像是修復列表上的高級事物,但最新的DBI升級問題仍未解決。有沒有人找到解決辦法,或知道如何破解庫,並獲取DBI :: errstr攜帶值時出現錯誤?Win 64草莓Perl DBI沒有錯誤報告錯誤仍然沒有解決?

這裏是我的代碼(是我知道的問題瓦特/空的root密碼):現在

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::errstr\n"; 

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::errstr\n"; 

my $return = $DBI_query_handle->execute() or warn "$DBI::errstr\n"; 

print "sys arry".Dumper [email protected]"\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 "\n\n-------------------------------------------------------------------\n\n"; 

my $hash = DBI->installed_versions; 
print Dumper $hash; 

,該表是無效的,列有在它和中間報價值是一個未加引號的字符串。應該像聖誕樹一樣點亮錯誤處理。

如果我將執行語句更改爲「$ 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. 

的信息的最後一位爲你當我傾倒$ DBI :: lasth,我可以看到錯誤的方法是聯合國民主基金:

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'); 

所以請請的這麼好的人,我該怎麼辦時,編程的最重要的原則之一 - 錯誤處理 - 在我的程序的核心模塊中不起作用?!

+0

模塊的作者在報告錯誤時說了些什麼? – ikegami

回答