aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraf123 <jimdevel@hummypkg.org.uk>2012-11-29 10:26:14 +1000
committerSteve Bennett <steveb@workware.net.au>2012-11-29 10:30:15 +1000
commitfe63bcdba4b63372a0aa18e1444cfdbc8621a881 (patch)
tree21080e5eabe25434b2b578ec02300f6833492b85
parent446c4faa6a6cda3c43ab68df168b3eeec67274b6 (diff)
downloadjimtcl-fe63bcdba4b63372a0aa18e1444cfdbc8621a881.zip
jimtcl-fe63bcdba4b63372a0aa18e1444cfdbc8621a881.tar.gz
jimtcl-fe63bcdba4b63372a0aa18e1444cfdbc8621a881.tar.bz2
Use sqlite3_prepare_v2()
When I'm working with SQLite3 databases in Jim, I find that I occasionally get a 'schema has changed' error so I end up using catch to detect the error and try the query again. Here's a quick patch to change the SQLite3 extension to use the sqlite3_prepare_v2() API function instead of sqlite3_prepare() - trivial but the _v2() function has a number of benefits and everyone should have a new enough SQLite3 library to support it. Please can you consider it for inclusion? See - http://www.sqlite.org/c3ref/prepare.html The benefit I'm specifically interested in is: With the _v2() variant, "If the database schema changes, instead of returning SQLITE_SCHEMA as it always used to do, sqlite3_step() will automatically recompile the SQL statement and try to run it again."
-rw-r--r--auto.def2
-rw-r--r--jim-sqlite3.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/auto.def b/auto.def
index fd80d8e..ddb0c1e 100644
--- a/auto.def
+++ b/auto.def
@@ -248,7 +248,7 @@ dict set extdb info {
libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
}
signal { check {[have-feature sigaction] && [have-feature vfork]} }
- sqlite3 { check {[cc-check-function-in-lib sqlite3_open sqlite3]} libdep lib_sqlite3_open }
+ sqlite3 { check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
syslog { check {[have-feature syslog]} }
tree { dep oo }
win32 { check {[have-feature windows]} }
diff --git a/jim-sqlite3.c b/jim-sqlite3.c
index 8016b7f..62d8fa9 100644
--- a/jim-sqlite3.c
+++ b/jim-sqlite3.c
@@ -193,7 +193,7 @@ static int JimSqliteHandlerCommand(Jim_Interp *interp, int argc, Jim_Obj *const
query = Jim_GetString(objPtr, &len);
Jim_IncrRefCount(objPtr);
/* Compile the query into VM code */
- if (sqlite3_prepare(sh->db, query, len, &stmt, &tail) != SQLITE_OK) {
+ if (sqlite3_prepare_v2(sh->db, query, len, &stmt, &tail) != SQLITE_OK) {
Jim_DecrRefCount(interp, objPtr);
Jim_SetResultString(interp, sqlite3_errmsg(sh->db), -1);
Jim_Free(nullstr);