1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

applied another patch by Yuriy Kaminskiy to fix finalize issues

This commit is contained in:
Kenichi Ishigaki 2011-10-20 16:14:56 +00:00
parent 68db35b8b4
commit b4220250ce
2 changed files with 86 additions and 1 deletions

View file

@ -581,6 +581,7 @@ sqlite_st_prepare(SV *sth, imp_sth_t *imp_sth, char *statement, SV *attribs)
sqlite_error(sth, rc, sqlite3_errmsg(imp_dbh->db));
if (imp_sth->stmt) {
rc = sqlite3_finalize(imp_sth->stmt);
imp_sth->stmt = NULL;
if (rc != SQLITE_OK) {
sqlite_error(sth, rc, sqlite3_errmsg(imp_dbh->db));
}
@ -827,7 +828,6 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth)
if (sqlite3_reset(imp_sth->stmt) != SQLITE_OK) {
sqlite_error(sth, imp_sth->retval, sqlite3_errmsg(imp_dbh->db));
}
imp_sth->stmt = NULL;
return -6; /* -> undef in SQLite.xsi */
}
}
@ -991,6 +991,7 @@ sqlite_st_destroy(SV *sth, imp_sth_t *imp_sth)
/* finalize sth when active connection */
rc = sqlite3_finalize(imp_sth->stmt);
imp_sth->stmt = NULL;
if (rc != SQLITE_OK) {
sqlite_error(sth, rc, sqlite3_errmsg(imp_dbh->db));
}

84
t/47_execute.t Normal file
View file

@ -0,0 +1,84 @@
#!/usr/bin/perl
# Trigger locking error and test prepared statement is still valid afterwards
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test qw/connect_ok dbfile @CALL_FUNCS/;
use Test::More;
use Test::NoWarnings;
plan tests => 10 * @CALL_FUNCS + 1;
foreach my $call_func (@CALL_FUNCS) {
my $dbh = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
);
my $dbh2 = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
);
my $dbfile = dbfile('foo');
# NOTE: Let's make it clear what we're doing here.
# $dbh starts locking with the first INSERT statement.
# $dbh2 tries to INSERT, but as the database is locked,
# it starts waiting. However, $dbh won't release the lock.
# Eventually $dbh2 gets timed out, and spits an error, saying
# the database is locked. So, we don't need to let $dbh2 wait
# too much here. It should be timed out anyway.
ok($dbh->$call_func(300, 'busy_timeout'));
ok($dbh2->$call_func(300, 'busy_timeout'));
$dbh->do("CREATE TABLE Blah ( id INTEGER )");
$dbh->do("INSERT INTO Blah VALUES ( 1 )");
$dbh->commit;
my $sth;
ok($sth = $dbh->prepare("SELECT id FROM Blah"));
$sth->execute;
{
my $row;
ok($row = $sth->fetch);
ok($row && $row->[0] == 1);
}
$sth->finish;
$dbh->commit;
$dbh2->do("BEGIN EXCLUSIVE");
eval {
$sth->execute;
};
ok($@);
if ($@) {
print "# expected execute failure : $@";
$sth->finish;
$dbh->rollback;
}
$dbh2->commit;
$sth->execute;
{
my $row;
ok($row = $sth->fetch);
ok($row && $row->[0] == 1);
}
$sth->finish;
$dbh->commit;
$dbh2->disconnect;
undef($dbh2);
$dbh->disconnect;
undef($dbh);
unlink $dbfile;
}