Domanda

I'm wondering why a warn appears when using DBI_TRACE=1 upon connecting to any DB. Bonus points to a way to write clean code that doesn't exhibit it.

I'm speaking about the !! warn: 0 CLEARED by call to connect method that seems harmless, since the code does work as intended. Note that it doesn't appear without setting the DBI trace mode.

Sample Perl code (using SQLite):

use warnings;
use DBI;
DBI->connect("dbi:SQLite:dbname=test.sqlite","","") or die $DBI::errstr;

Sample output :

    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
È stato utile?

Soluzione

It comes from the following XS code included with DBI:

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

It is simply a print to the trace file of the string "warn", it is not an issued warning. I think it is happening in your case because the connect method is SQLite is setting DBI's err to '0' so it is false but not zero length.

However, I see it happens with multiple DBDs (including DBD::ODBC).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top