Subject: | Patch for busy_timeout support |
Just a quick patch to implement previous posters request for busy_timeout support.
diff -ru DBD-SQLite-0.31/dbdimp.c new/dbdimp.c
--- DBD-SQLite-0.31/dbdimp.c 2004-02-15 04:36:38.000000000 +1100
+++ new/dbdimp.c 2004-02-27 16:06:13.000000000 +1100
@@ -64,7 +64,11 @@
imp_dbh->handle_binary_nulls = FALSE;
- sqlite_busy_timeout(imp_dbh->db, SQL_TIMEOUT);
+ if (imp_dbh->busy_timeout > 0) {
+ } else {
+ imp_dbh->busy_timeout = SQL_TIMEOUT;
+ }
+ sqlite_busy_timeout(imp_dbh->db, imp_dbh->busy_timeout);
if (retval = sqlite_exec(imp_dbh->db, "PRAGMA empty_result_callbacks = ON",
NULL, NULL, &errmsg)
@@ -563,8 +567,7 @@
}
DBIc_set(imp_dbh, DBIcf_AutoCommit, SvTRUE(valuesv));
return TRUE;
- }
- else if (strEQ(key, "sqlite_no_utf8_flag") || strEQ(key, "NoUTF8Flag")) {
+ } else if (strEQ(key, "sqlite_no_utf8_flag") || strEQ(key, "NoUTF8Flag")) {
warn("NoUTF8Flag is deprecated due to perl unicode weirdness\n");
if (SvTRUE(valuesv)) {
imp_dbh->no_utf8_flag = TRUE;
@@ -573,8 +576,7 @@
imp_dbh->no_utf8_flag = FALSE;
}
return TRUE;
- }
- else if (strEQ(key, "sqlite_handle_binary_nulls")) {
+ } else if (strEQ(key, "sqlite_handle_binary_nulls")) {
if (SvTRUE(valuesv)) {
imp_dbh->handle_binary_nulls = TRUE;
}
@@ -582,6 +584,14 @@
imp_dbh->handle_binary_nulls = FALSE;
}
return TRUE;
+ } else if (strEQ(key, "sqlite_busy_timeout")) {
+ if (SvIOK(valuesv)) {
+ imp_dbh->busy_timeout = SvIV(valuesv);
+ sqlite_busy_timeout(imp_dbh->db, imp_dbh->busy_timeout);
+ return TRUE;
+ } else {
+ warn("Failed to set busy timeout. Must supply an integer\n");
+ }
}
return FALSE;
}
@@ -594,12 +604,12 @@
if (strEQ(key, "sqlite_no_utf8_flag") || strEQ(key, "NoUTF8Flag")) {
return newSViv(imp_dbh->no_utf8_flag ? 1 : 0);
- }
- if (strEQ(key, "sqlite_version")) {
+ } else if (strEQ(key, "sqlite_version")) {
return newSVpv(sqlite_version, strlen(sqlite_version));
- }
- if (strEQ(key, "sqlite_encoding")) {
+ } else if (strEQ(key, "sqlite_encoding")) {
return newSVpv(sqlite_encoding, strlen(sqlite_encoding));
+ } else if (strEQ(key, "sqlite_busy_timeout")) {
+ return newSViv(imp_dbh->busy_timeout);
}
return NULL;
}
diff -ru DBD-SQLite-0.31/dbdimp.h new/dbdimp.h
--- DBD-SQLite-0.31/dbdimp.h 2003-08-19 17:43:10.000000000 +1000
+++ new/dbdimp.h 2004-02-27 16:06:42.000000000 +1100
@@ -23,6 +23,7 @@
bool in_tran;
bool no_utf8_flag;
bool handle_binary_nulls;
+ IV busy_timeout;
AV *functions;
AV *aggregates;
};
diff -ru DBD-SQLite-0.31/lib/DBD/SQLite.pm new/lib/DBD/SQLite.pm
--- DBD-SQLite-0.31/lib/DBD/SQLite.pm 2004-02-15 06:13:51.000000000 +1100
+++ new/lib/DBD/SQLite.pm 2004-02-27 15:53:30.000000000 +1100
@@ -348,6 +348,12 @@
application. This does not use the built in sqlite_encode_binary
and sqlite_decode_binary functions, which may be considered a bug.
+=item sqlite_busy_timeout
+
+Set this attribute to be the number of milliseconds that the database will
+wait to establish a lock on the database, such as when a BEGIN TRANSACTION
+statement has been executed by another process.
+
=back
=head1 DRIVER PRIVATE METHODS
Only in new: output
diff -ru DBD-SQLite-0.31/t/01logon.t new/t/01logon.t
--- DBD-SQLite-0.31/t/01logon.t 2003-03-04 18:31:49.000000000 +1100
+++ new/t/01logon.t 2004-02-27 15:58:45.000000000 +1100
@@ -1,10 +1,11 @@
use Test;
-BEGIN { plan tests => 3 }
+BEGIN { plan tests => 4 }
use DBI;
my $dbh = DBI->connect("dbi:SQLite:dbname=foo", "", "");
ok($dbh);
ok($dbh->{sqlite_version});
ok($dbh->{sqlite_encoding});
-print "sqlite_version=$dbh->{sqlite_version}, sqlite_encoding=$dbh->{sqlite_encoding}\n";
+ok($dbh->{sqlite_busy_timeout});
+print "sqlite_version=$dbh->{sqlite_version}, sqlite_encoding=$dbh->{sqlite_encoding}, sqlite_busy_timeout=$dbh->{sqlite_busy_timeout}\n";
$dbh->disconnect;