From: Graham Knop Date: Wed, 18 Jan 2012 15:55:43 +0000 (-0500) Subject: skip workaround for SQLite numifying strings silently on new versions of DBD::SQLite X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=00414f34fa462d3fe41ce9980add7ce4264e63a9;p=dbsrgits%2FDBIx-Class.git skip workaround for SQLite numifying strings silently on new versions of DBD::SQLite --- diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index fe67702..b8eecd8 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -10,6 +10,7 @@ use DBIx::Class::Carp; use Scalar::Util 'looks_like_number'; use Scope::Guard (); use Context::Preserve 'preserve_context'; +use Try::Tiny; use namespace::clean; __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite'); @@ -117,19 +118,19 @@ sub bind_attribute_by_data_type { ; } -# DBD::SQLite (at least up to version 1.31 has a bug where it will +# DBD::SQLite up to version 1.34_01 has a bug where it will # non-fatally nummify a string value bound as an integer, resulting # in insertions of '0' into supposed-to-be-numeric fields # Since this can result in severe data inconsistency, remove the # bind attr if such a sitation is detected -# -# FIXME - when a DBD::SQLite version is released that eventually fixes -# this sutiation (somehow) - no-op this override once a proper DBD -# version is detected sub _dbi_attrs_for_bind { my ($self, $ident, $bind) = @_; my $bindattrs = $self->next::method($ident, $bind); + if (try { DBD::SQLite->VERSION('1.34_02'); 1 } ) { + return $bindattrs; + } + for (0.. $#$bindattrs) { if ( defined $bindattrs->[$_] @@ -140,11 +141,10 @@ sub _dbi_attrs_for_bind { and ! looks_like_number ($bind->[$_][1]) ) { - carp_unique( sprintf ( + $self->throw_exception( sprintf ( "Non-numeric value supplied for column '%s' despite the numeric datatype", - $bind->[$_][0]{dbic_colname} || "# $_" + $bind->[$_][0]{dbic_colname}, ) ); - undef $bindattrs->[$_]; } } diff --git a/t/752sqlite.t b/t/752sqlite.t index fa2fc98..fd538ba 100644 --- a/t/752sqlite.t +++ b/t/752sqlite.t @@ -11,7 +11,7 @@ use DBICTest; # savepoints test { - my $schema = DBICTest->init_schema(auto_savepoint => 1); + my $schema = DBICTest->init_schema(auto_savepoint => 1, PrintError => 0); my $ars = $schema->resultset('Artist'); @@ -45,14 +45,14 @@ use DBICTest; my $schema = DBICTest->init_schema(); -# make sure the side-effects of RT#67581 do not result in data loss my $row; -warnings_exist { $row = $schema->resultset('Artist')->create ({ name => 'alpha rank', rank => 'abc' }) } - [qr/Non-numeric value supplied for column 'rank' despite the numeric datatype/], - 'proper warning on string insertion into an numeric column' +# make sure the side-effects of RT#67581 do not result in data loss on older DBD::SQLite versions +throws_ok { $row = $schema->resultset('Artist')->create ({ name => 'alpha rank', rank => 'abc' }) } + qr/datatype mismatch: bind 1 type 1 as abc|Non-numeric value supplied for column 'rank' despite the numeric datatype/, + 'proper exception on string insertion into an numeric column' ; -$row->discard_changes; -is ($row->rank, 'abc', 'proper rank inserted into database'); +is $schema->resultset('Artist')->search({ name => 'alpha rank' })->count, 0, + 'no rows inserted for string insertion into a numeric column'; # and make sure we do not lose actual bigints {