我想知道在连接到任何数据库时使用DBI_TRACE=1
时出现警告的原因。奖励指向一种编写 clean 代码的方法,该代码不会显示它。
我说的是!! warn: 0 CLEARED by call to connect method
似乎无害的,
因为代码确实按预期工作。请注意,如果没有设置DBI跟踪模式,它就不会出现。
示例Perl代码(使用SQLite):
use warnings;
use DBI;
DBI->connect("dbi:SQLite:dbname=test.sqlite","","") or die $DBI::errstr;
示例输出:
DBI 1.612-ithread default trace level set to 0x0/1 (pid 12814 pi 1ddd010) at DBI.pm line 275 via test.pl line 2
-> DBI->connect(dbi:SQLite:dbname=test.sqlite, , ****)
-> DBI->install_driver(SQLite) for linux perl=5.010001 pid=12814 ruid=1000 euid=1000
install_driver: DBD::SQLite version 1.29 loaded from /usr/lib/perl5/DBD/SQLite.pm
<- install_driver= DBI::dr=HASH(0x204da38)
!! warn: 0 CLEARED by call to connect method
<- connect('dbname=test.sqlite', '', ...)= DBI::db=HASH(0x204e278) at DBI.pm line 662
<- STORE('PrintError', 1)= 1 at DBI.pm line 714
<- STORE('AutoCommit', 1)= 1 at DBI.pm line 714
<- STORE('PrintWarn', 0)= 1 at DBI.pm line 717
<- FETCH('PrintWarn')= '' at DBI.pm line 717
<- STORE('Warn', 0)= 1 at DBI.pm line 717
<- FETCH('Warn')= '' at DBI.pm line 717
<- STORE('Username', '')= 1 at DBI.pm line 717
<> FETCH('Username')= '' ('Username' from cache) at DBI.pm line 717
<- connected('dbi:SQLite:dbname=test.sqlite', '', ...)= undef at DBI.pm line 723
<- connect= DBI::db=HASH(0x204e278)
<- STORE('dbi_connect_closure', CODE(0x204da08))= 1 at DBI.pm line 732
<- DESTROY(DBI::db=HASH(204e1d0))= undef
<- disconnect_all= '' at DBI.pm line 740
! <- DESTROY(DBI::dr=HASH(204da38))= undef during global destruction
答案 0 :(得分:2)
它来自DBI附带的以下XS代码:
if (!keep_error && meth_type != methtype_set_err) {
SV *err_sv;
if (trace_level && SvOK(err_sv=DBIc_ERR(imp_xxh))) {
PerlIO *logfp = DBILOGFP;
PerlIO_printf(logfp, " !! %s: %s CLEARED by call to %s method\n",
SvTRUE(err_sv) ? "ERROR" : strlen(SvPV_nolen(err_sv)) ? "warn" : "info",
neatsvpv(DBIc_ERR(imp_xxh),0), meth_name);
}
DBIh_CLEAR_ERROR(imp_xxh);
}
else { /* we check for change in ErrCount during call */
ErrCount = DBIc_ErrCount(imp_xxh);
}
它只是字符串“warn”的跟踪文件的打印,它不是已发出的警告。我认为这种情况正在你的情况下发生,因为连接方法是SQLite将DBI的错误设置为'0'所以它是假的但不是零长度。
但是,我发现它发生在多个DBD(包括DBD :: ODBC)。