From a0fe46546ac465666e642b37e9d41bb94f447de1 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 29 Jan 2009 03:27:51 +0000 Subject: [PATCH] DBD::SQLite: applied a patch to make "do" faster [RT #35449] --- SQLite.xs | 15 +++++++++++++++ dbdimp.c | 19 +++++++++++++++++++ lib/DBD/SQLite.pm | 9 +++++++++ 3 files changed, 43 insertions(+) diff --git a/SQLite.xs b/SQLite.xs index ffae61d..2f8dba1 100644 --- a/SQLite.xs +++ b/SQLite.xs @@ -63,6 +63,21 @@ busy_timeout(dbh, timeout=0) OUTPUT: RETVAL +void +_do(dbh, statement) + SV * dbh + char * statement + CODE: + { + D_imp_dbh(dbh); + IV retval; + retval = sqlite_db_do(dbh, imp_dbh, statement); + if (retval == 0) + XST_mPV(0, "0E0"); /* (true but zero) */ + else + XST_mUNDEF(0); /* <= -2 means error */ + } + MODULE = DBD::SQLite PACKAGE = DBD::SQLite::st PROTOTYPES: DISABLE diff --git a/dbdimp.c b/dbdimp.c index 043ec08..0c4c05d 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -230,6 +230,25 @@ sqlite_db_commit(SV *dbh, imp_dbh_t *imp_dbh) return TRUE; } +int +sqlite_db_do(SV *dbh, imp_dbh_t *imp_dbh, char *statement) +{ + dTHR; + int retval; + char *errmsg; + + sqlite_trace(2, "DO"); + if ((retval = sqlite3_exec(imp_dbh->db, statement, + NULL, NULL, &errmsg)) + != SQLITE_OK) + { + sqlite_error(dbh, (imp_xxh_t*)imp_dbh, retval, errmsg); + return -2; + } + + return 0; +} + int sqlite_discon_all(SV *drh, imp_drh_t *imp_drh) { diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index c7fdeb9..5bca094 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -62,6 +62,15 @@ sub connect { package DBD::SQLite::db; +sub do { + my ($dbh, $statement, $attr, @params) = @_; + return DBD::SQLite::db::_do($dbh, $statement) unless defined $attr && @params; + my $sth = $dbh->prepare($statement, $attr) or return undef; + $sth->execute(@params) or return undef; + my $rows = $sth->rows; + ($rows == 0) ? "0E0" : $rows; +} + sub prepare { my ($dbh, $statement, @attribs) = @_;