diff --git a/Changes b/Changes index aed545f..4cee5d4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Changes for Perl extension DBD-SQLite +1.28_02 to be released + - Now empty (or comment only) statements won't cause segv + or "not an error" errors. Spotted by TOKUHIROM. (ISHIGAKI) + 1.28_01 Tue 22 Dec 2009 - Updated to SQLite 3.6.21 (ISHIGAKI) - silence warnings on HP-UX (HMBRAND) diff --git a/dbdimp.c b/dbdimp.c index 7964b87..43705a8 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -16,8 +16,8 @@ DBISTATE_DECLARE; #define croak_if_db_is_null() if (!imp_dbh->db) croak("imp_dbh->db is NULL at line %d in %s", __LINE__, __FILE__) #define croak_if_stmt_is_null() if (!imp_sth->stmt) croak("imp_sth->stmt is NULL at line %d in %s", __LINE__, __FILE__) #else - #define croak_if_db_is_null() - #define croak_if_stmt_is_null() + #define croak_if_db_is_null() + #define croak_if_stmt_is_null() #endif /*-----------------------------------------------------* @@ -415,10 +415,12 @@ sqlite_st_prepare(SV *sth, imp_sth_t *imp_sth, char *statement, SV *attribs) return FALSE; /* -> undef in lib/DBD/SQLite.pm */ } +#if 0 if (*statement == '\0') { sqlite_error(sth, -2, "attempt to prepare empty statement"); return FALSE; /* -> undef in lib/DBD/SQLite.pm */ } +#endif sqlite_trace(sth, imp_sth, 3, form("prepare statement: %s", statement)); imp_sth->nrow = -1; @@ -467,6 +469,8 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth) return -2; /* -> undef in SQLite.xsi */ } + if (!imp_sth->stmt) return 0; + croak_if_db_is_null(); croak_if_stmt_is_null(); @@ -575,6 +579,7 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth) } sqlite_error(sth, imp_sth->retval, sqlite3_errmsg(imp_dbh->db)); if (sqlite3_reset(imp_sth->stmt) != SQLITE_OK) { +sqlite_trace(sth, imp_sth, 3, "RESET ERROR!"); sqlite_error(sth, imp_sth->retval, sqlite3_errmsg(imp_dbh->db)); } return -5; /* -> undef in SQLite.xsi */ diff --git a/t/38_empty_statement.t b/t/38_empty_statement.t new file mode 100644 index 0000000..fc9e7a9 --- /dev/null +++ b/t/38_empty_statement.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test qw/connect_ok/; +use Test::More; +use Test::NoWarnings; + +plan tests => 8; + +my $dbh = connect_ok( RaiseError => 1 ); + +eval { $dbh->do("\n") }; +ok !$@, "empty statement does not spit a warning"; +diag $@ if $@; + +eval { $dbh->do(" ") }; +ok !$@, "empty statement does not spit a warning"; +diag $@ if $@; + +eval { $dbh->do("") }; +ok !$@, "empty statement does not spit a warning"; +diag $@ if $@; + +eval { $dbh->do("/* everything in a comment */") }; +ok !$@, "empty statement does not spit a warning"; +diag $@ if $@; + +eval { $dbh->do("-- everything in a comment") }; +ok !$@, "empty statement does not spit a warning"; +diag $@ if $@; + +{ + # We know this causes "Use of uninitialized value + # in subroutine entry" warning, but anyway this + # shouldn't die, either. + local $SIG{__WARN__}; + eval { $dbh->do(undef) }; + ok !$@, "undef statement does spit a warning, but does not die anyway"; + diag $@ if $@; +}