Subject: | binding nulls under strict causes error messages. included test cases and fix |
the sqlite_trace statements assumed that the value in a bind operation would be defined. when an undef was passed in using strict, it threw an appropriate error. test case and fix are attached.
diff -Naur DBD-SQLite-1.07/dbdimp.c new/dbdimp.c
--- DBD-SQLite-1.07/dbdimp.c 2004-10-05 06:02:21.000000000 +1000
+++ new/dbdimp.c 2004-11-01 12:09:08.000000000 +1100
@@ -327,8 +327,12 @@
SV *sql_type_sv = av_shift(imp_sth->params);
int sql_type = SvIV(sql_type_sv);
- sqlite_trace(4, "params left in 0x%p: %d", imp_sth->params, 1+av_len(imp_sth->params));
- sqlite_trace(4, "bind %d type %d as %s", i, sql_type, SvPV_nolen(value));
+ sqlite_trace(4, "params left in 0x%p: %d", imp_sth->params, 1+av_len(imp_sth->params));
+ if (SvOK(value)) {
+ sqlite_trace(4, "bind %d type %d as '%s'", i, sql_type, SvPV_nolen(value));
+ } else {
+ sqlite_trace(4, "bind %d type %d as NULL", i, sql_type);
+ }
if (!SvOK(value)) {
sqlite_trace(5, "binding null");
@@ -430,8 +434,13 @@
croak("InOut bind params not implemented");
}
pos = 2 * (SvIV(param) - 1);
- sqlite_trace(3, "bind into 0x%p: %d => %s (%d) pos %d\n",
- imp_sth->params, SvIV(param), SvPV_nolen(value), sql_type, pos);
+ if (SvOK(value)) {
+ sqlite_trace(3, "bind into 0x%p: %d => '%s' (%d) pos %d\n",
+ imp_sth->params, SvIV(param), SvPV_nolen(value), sql_type, pos);
+ } else {
+ sqlite_trace(3, "bind into 0x%p: %d => NULL (%d) pos %d\n",
+ imp_sth->params, SvIV(param), sql_type, pos);
+ }
av_store(imp_sth->params, pos, SvREFCNT_inc(value));
av_store(imp_sth->params, pos+1, newSViv(sql_type));
diff -Naur DBD-SQLite-1.07/t/03insert.t new/t/03insert.t
--- DBD-SQLite-1.07/t/03insert.t 2004-08-24 00:50:34.000000000 +1000
+++ new/t/03insert.t 2004-11-01 12:09:11.000000000 +1100
@@ -1,5 +1,8 @@
use Test;
use DBI;
+use strict;
+use warnings;
+
BEGIN { plan tests => 10 }
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "");
ok($dbh);
@@ -16,6 +19,6 @@
}
ok($sth->execute("test", "test", "1"));
ok($sth->execute("test", "test", "2"));
-ok($sth->execute("test", "test", "3"));
+ok($sth->execute("test", "test", undef));
ok($dbh->do("delete from f where f1='test'") == 3);
$dbh->disconnect;