]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Adding the sqlite3_stmt_readonly() interface.
authordrh <drh@noemail.net>
Tue, 16 Nov 2010 23:10:25 +0000 (23:10 +0000)
committerdrh <drh@noemail.net>
Tue, 16 Nov 2010 23:10:25 +0000 (23:10 +0000)
FossilOrigin-Name: fd5b2f23dd5111d2f0934dd828bae36b755024c1

manifest
manifest.uuid
src/sqlite.h.in
src/test1.c
src/vdbeapi.c
test/capi3d.test

index d06d475d13a5945fa99c86f7dad7269b34c54b3f..0a258e04dd3e378c0702bac2203f7cc9c63e94e9 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Use\sthe\sestimated\snumber\sof\srows\scomputed\sfor\ssubqueries\sin\sthe\scost\ncomputations\sfor\souter\squeries.
-D 2010-11-16T02:49:16
+C Adding\sthe\ssqlite3_stmt_readonly()\sinterface.
+D 2010-11-16T23:10:26
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e7a59672eaeb04408d1fa8501618d7501a3c5e39
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -179,14 +179,14 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
 F src/select.c 550d67688f5e8bc8022faf6d014838afba1415af
 F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056
-F src/sqlite.h.in f47e09412fc9a129f759fa4d96ef21f4b3d529eb
+F src/sqlite.h.in 533fbbd82130f0edc01396f1e53a698cdf1b590e
 F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754
 F src/sqliteInt.h dd28f6138c74cf4833e032a989b6ff7885798cf6
 F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44
 F src/status.c 496913d4e8441195f6f2a75b1c95993a45b9b30b
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
 F src/tclsqlite.c e1c485fa323e3ef02e5b10fe6a016e7638013eb9
-F src/test1.c a1339ecea631f3287b7dafcc8d55d343f7c5d193
+F src/test1.c c2aa29d0fd6db7506fb7f0de7bff1386078296df
 F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
 F src/test3.c 056093cfef69ff4227a6bdb9108564dc7f45e4bc
 F src/test4.c 0528360b5025688002a5feb6be906ddce52eaaee
@@ -233,7 +233,7 @@ F src/vacuum.c 924bd1bcee2dfb05376f79845bd3b4cec7b54b2f
 F src/vdbe.c e1aa917961e69f71c80f46ce231b496d3c841ae1
 F src/vdbe.h 4de0efb4b0fdaaa900cf419b35c458933ef1c6d2
 F src/vdbeInt.h 7f4cf1b2b69bef3a432b1f23dfebef57275436b4
-F src/vdbeapi.c 5368714fa750270cf6430160287c21adff44582d
+F src/vdbeapi.c fb0036185b3c56e15916a5ee96309cd4acf6818f
 F src/vdbeaux.c 762c2b146cf5fe7a7f743af1bbfed4a966aa937a
 F src/vdbeblob.c e0ce3c54cc0c183af2ec67b63a289acf92251df4
 F src/vdbemem.c 23723a12cd3ba7ab3099193094cbb2eb78956aa9
@@ -298,7 +298,7 @@ F test/capi2.test 00032d7504b9c14f1b36331670c5e7b0f73e3c5d
 F test/capi3.test 1945a2ba75e3f4c49d5beb8fc092115b6292d471
 F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4
 F test/capi3c.test bea67403a5e37a4b33230ee4723e315a2ffb31e7
-F test/capi3d.test 57d83b690d7364bde02cddbf8339a4b50d80ce23
+F test/capi3d.test cd36571f014f34bdc4421967f6453cbb597d5d16
 F test/cast.test 166951664a0b0a2e0f8fb5997a152490c6363932
 F test/check.test db2b29d557544347d28e25b8406f5d5ecc3d1bc3
 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91
@@ -889,14 +889,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P d52b593978aa1776af7aeb957c4f8df0c5cb7e43
-R d49dbce342d6074d2c08ca15a1061dc2
+P 56bbc539246a6dc9f1ae1edb898db7a4f6f6d322
+R 72844ae88a5f828dd3936f0015dc03a4
 U drh
-Z 1d0a2a683be8d99ef69f89af3e0fc4c3
+Z 48d737e0936d03f220e9650734c5994d
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFM4fEvoxKgR168RlERAtLBAJ0duCZxNY8VlhlVLo/NezKrqI5noACdE3GU
-LDKZgeEbRVz6H1/mucVVNUQ=
-=B2su
+iD8DBQFM4w9loxKgR168RlERAicMAJ9C8dDp3QsQXrjRY7uCIkkgU8xQjwCePeD8
+5VbOBryk2e4pErKiCR+rel8=
+=5cE5
 -----END PGP SIGNATURE-----
index 5f256ca04e5f27f262746845e88b0b9b55f8cf8a..8883b02e12fff3390bd6a19c15d0625ee7ff0085 100644 (file)
@@ -1 +1 @@
-56bbc539246a6dc9f1ae1edb898db7a4f6f6d322
\ No newline at end of file
+fd5b2f23dd5111d2f0934dd828bae36b755024c1
\ No newline at end of file
index e08d5ce5965603c4a87bab69c4eb3ad50cfebe11..fc96c31caa4bdf6abde369839835144e565c6998 100644 (file)
@@ -2628,6 +2628,21 @@ int sqlite3_prepare16_v2(
 */
 const char *sqlite3_sql(sqlite3_stmt *pStmt);
 
+/*
+** CAPI3REF: Determine If An SQL Statement Writes The Database
+**
+** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
+** the [prepared statement] X is guaranteed to leave the database file
+** unmodified.  ^If the sqlite3_stmt_readonly(X) interface returns false (zero)
+** then evaluating the statement might change the database file, but this
+** is not guaranteed as the write operation might be conditional and the
+** condition might not be met.  ^If X is a NULL pointer then
+** sqlite3_stmt_readonly(X) returns true.  If X is a non-NULL pointer but
+** is not a pointer to a valid, unfinalized prepared statement, then the
+** behavior is undefined and probably harmful.
+*/
+int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
+
 /*
 ** CAPI3REF: Dynamically Typed Value Object
 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
index 57b86f5b2878e8a1d125e2b9e73c11576aa7c129..27834f36e1b083f7a5e9692d73ce3af09d9f9e97 100644 (file)
@@ -2299,6 +2299,33 @@ static int test_next_stmt(
   return TCL_OK;
 }
 
+/*
+** Usage:  sqlite3_stmt_readonly  STMT
+**
+** Return true if STMT is a NULL pointer or a pointer to a statement
+** that is guaranteed to leave the database unmodified.
+*/
+static int test_stmt_readonly(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+  sqlite3_stmt *pStmt;
+  int rc;
+
+  if( objc!=2 ){
+    Tcl_AppendResult(interp, "wrong # args: should be \"",
+        Tcl_GetStringFromObj(objv[0], 0), " STMT", 0);
+    return TCL_ERROR;
+  }
+
+  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
+  rc = sqlite3_stmt_readonly(pStmt);
+  Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc));
+  return TCL_OK;
+}
+
 
 /*
 ** Usage:  sqlite3_reset  STMT 
@@ -5392,6 +5419,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3_step",                  test_step          ,0 },
      { "sqlite3_sql",                   test_sql           ,0 },
      { "sqlite3_next_stmt",             test_next_stmt     ,0 },
+     { "sqlite3_stmt_readonly",         test_stmt_readonly ,0 },
 
      { "sqlite3_release_memory",        test_release_memory,     0},
      { "sqlite3_soft_heap_limit",       test_soft_heap_limit,    0},
index e51555658cc5eea8a71d97aba5363d49827413ee..93689ebceeeff3c013a6244dd69afbf90a49f3a7 100644 (file)
@@ -1266,6 +1266,14 @@ sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
   return pStmt ? ((Vdbe*)pStmt)->db : 0;
 }
 
+/*
+** Return true if the prepared statement is guaranteed to not modify the
+** database.
+*/
+int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
+  return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
+}
+
 /*
 ** Return a pointer to the next prepared statement after pStmt associated
 ** with database connection pDb.  If pStmt is NULL, return the first
index e346029f92f6b8300aae73680cf593641ec149c2..49e64476ebb5f5698d175185d8f566e331b2bbd5 100644 (file)
@@ -10,7 +10,8 @@
 #***********************************************************************
 # This file implements regression tests for SQLite library.  
 #
-# This file is devoted to testing the sqlite3_next_stmt interface.
+# This file is devoted to testing the sqlite3_next_stmt and
+# sqlite3_stmt_readonly interfaces.
 #
 # $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $
 #
@@ -88,6 +89,28 @@ for {set i 1} {$i<=100} {incr i} {
     sqlite3_next_stmt db 0
   } {}
 }
-      
+
+# Tests for the is-read-only interface.
+#
+proc test_is_readonly {testname sql truth} {
+  do_test $testname [format {
+    set DB [sqlite3_connection_pointer db]
+    set STMT [sqlite3_prepare $DB {%s} -1 TAIL]
+    set rc [sqlite3_stmt_readonly $STMT]
+    sqlite3_finalize $STMT
+    set rc
+  } $sql] $truth
+}
+
+test_is_readonly capi3d-2.1 {SELECT * FROM sqlite_master} 1
+test_is_readonly capi3d-2.2 {CREATE TABLE t1(x)} 0
+db eval {CREATE TABLE t1(x)}
+test_is_readonly capi3d-2.3 {INSERT INTO t1 VALUES(5)} 0
+test_is_readonly capi3d-2.4 {UPDATE t1 SET x=x+1 WHERE x<0} 0
+test_is_readonly capi3d-2.5 {SELECT * FROM t1} 1
+do_test capi3-2.99 {
+  sqlite3_stmt_readonly 0
+} 1
+
 
 finish_test