2

我想知道为什么在连接到任何数据库时会出现警告。DBI_TRACE=1奖励指出了一种编写不展示它的干净代码的方法。

我说的!! 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
4

1 回答 1

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)上。

于 2013-09-24T14:34:06.463 回答