From 0c9660283767ee0e136e0563410a4939a9045a3e Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 26 Mar 2014 23:14:40 +0900 Subject: [PATCH] allow to set busy_timeout to 0 via sqlite_busy_timeout() (#3) --- SQLite.xs | 4 ++-- dbdimp.c | 8 ++++---- dbdimp.h | 2 +- t/02_logon.t | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/SQLite.xs b/SQLite.xs index a50a160..ee307e8 100644 --- a/SQLite.xs +++ b/SQLite.xs @@ -206,9 +206,9 @@ set_authorizer(dbh, authorizer) int -busy_timeout(dbh, timeout=0) +busy_timeout(dbh, timeout=NULL) SV *dbh - int timeout + SV *timeout ALIAS: DBD::SQLite::db::sqlite_busy_timeout = 1 CODE: diff --git a/dbdimp.c b/dbdimp.c index d6b93b9..bb486bd 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -1379,19 +1379,19 @@ sqlite_db_filename(pTHX_ SV *dbh) } int -sqlite_db_busy_timeout(pTHX_ SV *dbh, int timeout ) +sqlite_db_busy_timeout(pTHX_ SV *dbh, SV *timeout ) { D_imp_dbh(dbh); croak_if_db_is_null(); - if (timeout) { - imp_dbh->timeout = timeout; + if (timeout && SvIOK(timeout)) { + imp_dbh->timeout = SvIV(timeout); if (!DBIc_ACTIVE(imp_dbh)) { sqlite_error(dbh, -2, "attempt to set busy timeout on inactive database handle"); return -2; } - sqlite3_busy_timeout(imp_dbh->db, timeout); + sqlite3_busy_timeout(imp_dbh->db, imp_dbh->timeout); } return imp_dbh->timeout; } diff --git a/dbdimp.h b/dbdimp.h index cde9f20..944d5d2 100644 --- a/dbdimp.h +++ b/dbdimp.h @@ -96,7 +96,7 @@ int sqlite_db_create_aggregate(pTHX_ SV *dbh, const char *name, int argc, SV *ag int sqlite_db_create_collation(pTHX_ SV *dbh, const char *name, SV *func); int sqlite_db_progress_handler(pTHX_ SV *dbh, int n_opcodes, SV *handler); int sqlite_bind_col( SV *sth, imp_sth_t *imp_sth, SV *col, SV *ref, IV sql_type, SV *attribs ); -int sqlite_db_busy_timeout (pTHX_ SV *dbh, int timeout ); +int sqlite_db_busy_timeout (pTHX_ SV *dbh, SV *timeout ); int sqlite_db_backup_from_file(pTHX_ SV *dbh, char *filename); int sqlite_db_backup_to_file(pTHX_ SV *dbh, char *filename); void sqlite_db_collation_needed(pTHX_ SV *dbh, SV *callback ); diff --git a/t/02_logon.t b/t/02_logon.t index a8c607d..8b1349c 100644 --- a/t/02_logon.t +++ b/t/02_logon.t @@ -12,7 +12,7 @@ use t::lib::Test qw/connect_ok @CALL_FUNCS/; use Test::More; use Test::NoWarnings; -plan tests => 18 * @CALL_FUNCS + 1; +plan tests => 20 * @CALL_FUNCS + 1; my $show_diag = 0; foreach my $call_func (@CALL_FUNCS) { @@ -26,6 +26,9 @@ foreach my $call_func (@CALL_FUNCS) { ok( $dbh->$call_func('busy_timeout'), 'Found initial busy_timeout' ); ok( $dbh->$call_func(5000, 'busy_timeout') ); is( $dbh->$call_func('busy_timeout'), 5000, 'Set busy_timeout to new value' ); + + ok( defined $dbh->$call_func(0, 'busy_timeout') ); + is( $dbh->$call_func('busy_timeout'), 0, 'Set busy_timeout to 0' ); } # Attributes in the connect string