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');
;
}
-# 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->[$_]
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->[$_];
}
}
# 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');
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
{