1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 22:28:47 -04:00

disabled (Print)Warn hack (by timbunce's guidance)

This commit is contained in:
Kenichi Ishigaki 2010-11-04 16:24:00 +00:00
parent 8b35bb979a
commit 9f291b41d3
2 changed files with 19 additions and 7 deletions

View file

@ -79,9 +79,9 @@ sub connect {
my ($drh, $dbname, $user, $auth, $attr) = @_; my ($drh, $dbname, $user, $auth, $attr) = @_;
# Default PrintWarn to the value of $^W # Default PrintWarn to the value of $^W
unless ( defined $attr->{PrintWarn} ) { # unless ( defined $attr->{PrintWarn} ) {
$attr->{PrintWarn} = $^W ? 1 : 0; # $attr->{PrintWarn} = $^W ? 1 : 0;
} # }
my $dbh = DBI::_new_dbh( $drh, { my $dbh = DBI::_new_dbh( $drh, {
Name => $dbname, Name => $dbname,
@ -136,9 +136,21 @@ sub connect {
# HACK: Since PrintWarn = 0 doesn't seem to actually prevent warnings # HACK: Since PrintWarn = 0 doesn't seem to actually prevent warnings
# in DBD::SQLite we set Warn to false if PrintWarn is false. # 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; return $dbh;
} }

View file

@ -13,7 +13,7 @@ use Test::More tests => 6;
use Test::NoWarnings; use Test::NoWarnings;
SCOPE: { 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->{PrintWarn}, '->{PrintWarn} is false' );
ok( $dbh->do("CREATE TABLE f (f1, f2, f3)"), 'CREATE TABLE ok' ); ok( $dbh->do("CREATE TABLE f (f1, f2, f3)"), 'CREATE TABLE ok' );
ok( $dbh->begin_work, '->begin_work' ); ok( $dbh->begin_work, '->begin_work' );