From 9f291b41d351823256b995878e3e96e2d744a6cd Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 4 Nov 2010 16:24:00 +0000 Subject: [PATCH] disabled (Print)Warn hack (by timbunce's guidance) --- lib/DBD/SQLite.pm | 24 ++++++++++++++++++------ t/30_auto_rollback.t | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 6450447..5839ef2 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -79,9 +79,9 @@ sub connect { my ($drh, $dbname, $user, $auth, $attr) = @_; # Default PrintWarn to the value of $^W - unless ( defined $attr->{PrintWarn} ) { - $attr->{PrintWarn} = $^W ? 1 : 0; - } + # unless ( defined $attr->{PrintWarn} ) { + # $attr->{PrintWarn} = $^W ? 1 : 0; + # } my $dbh = DBI::_new_dbh( $drh, { Name => $dbname, @@ -136,9 +136,21 @@ sub connect { # HACK: Since PrintWarn = 0 doesn't seem to actually prevent warnings # in DBD::SQLite we set Warn to false if PrintWarn is false. - unless ( $attr->{PrintWarn} ) { - $attr->{Warn} = 0; - } + + # NOTE: According to the explanation by timbunce, + # "Warn is meant to report on bad practices or problems with + # the DBI itself (hence always on by default), while PrintWarn + # is meant to report warnings coming from the database." + # That is, if you want to disable an ineffective rollback warning + # etc (due to bad practices), you should turn off Warn, + # and to silence other warnings, turn off PrintWarn. + # Warn and PrintWarn are independent, and turning off PrintWarn + # does not silence those warnings that should be controlled by + # Warn. + + # unless ( $attr->{PrintWarn} ) { + # $attr->{Warn} = 0; + # } return $dbh; } diff --git a/t/30_auto_rollback.t b/t/30_auto_rollback.t index 57a5127..7a23760 100644 --- a/t/30_auto_rollback.t +++ b/t/30_auto_rollback.t @@ -13,7 +13,7 @@ use Test::More tests => 6; use Test::NoWarnings; SCOPE: { - my $dbh = connect_ok( RaiseError => 1, PrintWarn => 0 ); + my $dbh = connect_ok( RaiseError => 1, PrintWarn => 0, Warn => 0 ); ok( ! $dbh->{PrintWarn}, '->{PrintWarn} is false' ); ok( $dbh->do("CREATE TABLE f (f1, f2, f3)"), 'CREATE TABLE ok' ); ok( $dbh->begin_work, '->begin_work' );