mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 22:28:47 -04:00
DBD::SQLite: empty or comment-only statements shouldn't die. issue spotted by tokuhirom++
This commit is contained in:
parent
7cacca18b4
commit
fc6dc7a3d3
3 changed files with 56 additions and 2 deletions
4
Changes
4
Changes
|
@ -1,5 +1,9 @@
|
||||||
Changes for Perl extension DBD-SQLite
|
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
|
1.28_01 Tue 22 Dec 2009
|
||||||
- Updated to SQLite 3.6.21 (ISHIGAKI)
|
- Updated to SQLite 3.6.21 (ISHIGAKI)
|
||||||
- silence warnings on HP-UX (HMBRAND)
|
- silence warnings on HP-UX (HMBRAND)
|
||||||
|
|
5
dbdimp.c
5
dbdimp.c
|
@ -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 */
|
return FALSE; /* -> undef in lib/DBD/SQLite.pm */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (*statement == '\0') {
|
if (*statement == '\0') {
|
||||||
sqlite_error(sth, -2, "attempt to prepare empty statement");
|
sqlite_error(sth, -2, "attempt to prepare empty statement");
|
||||||
return FALSE; /* -> undef in lib/DBD/SQLite.pm */
|
return FALSE; /* -> undef in lib/DBD/SQLite.pm */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
sqlite_trace(sth, imp_sth, 3, form("prepare statement: %s", statement));
|
sqlite_trace(sth, imp_sth, 3, form("prepare statement: %s", statement));
|
||||||
imp_sth->nrow = -1;
|
imp_sth->nrow = -1;
|
||||||
|
@ -467,6 +469,8 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth)
|
||||||
return -2; /* -> undef in SQLite.xsi */
|
return -2; /* -> undef in SQLite.xsi */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!imp_sth->stmt) return 0;
|
||||||
|
|
||||||
croak_if_db_is_null();
|
croak_if_db_is_null();
|
||||||
croak_if_stmt_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));
|
sqlite_error(sth, imp_sth->retval, sqlite3_errmsg(imp_dbh->db));
|
||||||
if (sqlite3_reset(imp_sth->stmt) != SQLITE_OK) {
|
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));
|
sqlite_error(sth, imp_sth->retval, sqlite3_errmsg(imp_dbh->db));
|
||||||
}
|
}
|
||||||
return -5; /* -> undef in SQLite.xsi */
|
return -5; /* -> undef in SQLite.xsi */
|
||||||
|
|
45
t/38_empty_statement.t
Normal file
45
t/38_empty_statement.t
Normal file
|
@ -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 $@;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue