]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Get the non-callback API working with the EXPLAIN keyword and for PRAGMAs.
authordrh <drh@noemail.net>
Sat, 1 Mar 2003 19:45:34 +0000 (19:45 +0000)
committerdrh <drh@noemail.net>
Sat, 1 Mar 2003 19:45:34 +0000 (19:45 +0000)
Tickets #258 and #257.  Update the API documentation on the sqlite_changes()
routine to explain how it works with the non-callback API.  Ticket #250. (CVS 875)

FossilOrigin-Name: 620e1065e978545dd7bf6fa6fad1e6b93918dbf8

manifest
manifest.uuid
src/build.c
src/vdbe.c
test/capi2.test
test/tester.tcl
www/c_interface.tcl

index e32ae6d5a2dd4cb8a2a5cbe5ac16ed4711adb5ab..b7bb6c119f7a2bc84e4e087b3c249cfd9e22a8f8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\smemory\sleak\sassociated\swith\sPRIMARY\sKEY\sin\sa\sCREATE\sTABLE\sstatement\nthat\sfails.\s\sTicket\s#249.\s(CVS\s874)
-D 2003-02-26T13:52:52
+C Get\sthe\snon-callback\sAPI\sworking\swith\sthe\sEXPLAIN\skeyword\sand\sfor\sPRAGMAs.\nTickets\s#258\sand\s#257.\s\sUpdate\sthe\sAPI\sdocumentation\son\sthe\ssqlite_changes()\nroutine\sto\sexplain\show\sit\sworks\swith\sthe\snon-callback\sAPI.\s\sTicket\s#250.\s(CVS\s875)
+D 2003-03-01T19:45:34
 F Makefile.in 6606854b1512f185b8e8c779b8d7fc2750463d64
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -21,7 +21,7 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
 F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729
 F src/btree.c 2a0305ccbe617266ac3524805e0c6ef55a9f9cb7
 F src/btree.h 36a7a26a29382c2b1a519b42bb125880d46d00d4
-F src/build.c 02a106e40f0577437284fb78ebdd0a5443dc972c
+F src/build.c 25d5f901c456d6554020a33c4e457b6672181623
 F src/delete.c cbd499f3f9297504c42e328af89bef1a2113d04c
 F src/encode.c faf03741efe921755ec371cf4a6984536de00042
 F src/expr.c bd690b3a6174e97a0f16800e78c8aeae749a4e71
@@ -53,7 +53,7 @@ F src/tokenize.c bc40937d6666f188037aa3e54f0a2661a6fef6d1
 F src/trigger.c da142decd2808bc39e801f3bb1f161dbc2bd4005
 F src/update.c f06afa9bf1f777d17702e0f6e33cf44c44bc4f75
 F src/util.c 73b668d1ed468df650dc00685a5e4ffa6887feb4
-F src/vdbe.c 4906e666ffbe49e6d9aa03b9ef43cad8213d3a85
+F src/vdbe.c f8fdbf03ac82ccd68ddc3ea33d581babcef52c4d
 F src/vdbe.h ed43771f1dc2b994d5c484fdf2eab357c6ef0ee3
 F src/where.c ba96cab1fb076f025b6eae3fb0aead769fd2c96f
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@@ -64,7 +64,7 @@ F test/btree.test 1e3463c7838e7e71bbf37c9c6e45beee9c8975ba
 F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
 F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
 F test/btree4.test fa955a3d7a8bc91d6084b7f494f9e5d1bdfb15b6
-F test/capi2.test 0c82193ae67978c431e2ffc3259b544dc8fdd138
+F test/capi2.test b5c7fd0b34ecd03ce16ea15dd08934f7bcb5821a
 F test/conflict.test 80cf3780c8686b92db4ce0f60bca46a000537327
 F test/copy.test 73df5ed3112e858e006a8b7ddb4c9bab6a25d0fb
 F test/delete.test 5821a95a66061ae09723a88938f23d10d8a881ad
@@ -107,7 +107,7 @@ F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
 F test/tableapi.test 3c80421a889e1d106df16e5800fa787f0d2914a6
 F test/tclsqlite.test f650195b8124aca24bee175393a1ed2e5a544a38
 F test/temptable.test 03b7bdb7d6ce2c658ad20c94b037652c6cad34e0
-F test/tester.tcl d7541e28bb87588fd042498e7abc766f6567ef1b
+F test/tester.tcl d7a5835edaf118539241145d8188f0822b673488
 F test/trans.test 75e7a171b5d2d94ee56766459113e2ad0e5f809d
 F test/trigger1.test ec1da76e1a9f618deb96e505f459dcf8a23f2247
 F test/trigger2.test ab4c743bb96cee96ab5a17c5edfd57a9134329d6
@@ -134,7 +134,7 @@ F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
 F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
 F www/arch.tcl 679a0c48817f71bc91d5911ef386e5ef35d4f178
 F www/audit.tcl 90e09d580f79c7efec0c7d6f447b7ec5c2dce5c0
-F www/c_interface.tcl bca0aea880d043ed1bc0ad3bb39e24043f88b5bf
+F www/c_interface.tcl 5b54a6f65b70b02da2f6df4f8a23a4b10032e89e
 F www/changes.tcl 7eb04deffbe116cdb558443f8f7df74ebd021daa
 F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
 F www/crosscompile.tcl 3622ebbe518927a3854a12de51344673eb2dd060
@@ -155,7 +155,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 66158843dfa073ffb8779a5170e091cebc018855
-R dc727e1053fa9644419f9b675fcc2f6a
+P 8e9dc567996c3301c14a1f055ff2265770cbc3e1
+R 590441fe595414a275b875853b52b052
 U drh
-Z e1a44da712ef303e36bd1f401146575b
+Z c88b48546440c39c922d47e5442b91f3
index 1a37fb03e2c9ffc71e402650420ad0297b49adcc..e23a4ebb30648887b85bdadb6d7f155afa6241f4 100644 (file)
@@ -1 +1 @@
-8e9dc567996c3301c14a1f055ff2265770cbc3e1
\ No newline at end of file
+620e1065e978545dd7bf6fa6fad1e6b93918dbf8
\ No newline at end of file
index f0dd8ef67a08dfadde13ed644d1ef68df6181b26..45b82b0b5e1b4486748b57b315f6df39a86ea513 100644 (file)
@@ -25,7 +25,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.130 2003/02/26 13:52:51 drh Exp $
+** $Id: build.c,v 1.131 2003/03/01 19:45:34 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2194,6 +2194,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
   char *zLeft = 0;
   char *zRight = 0;
   sqlite *db = pParse->db;
+  Vdbe *v = sqliteGetVdbe(pParse);
+  if( v==0 ) return;
 
   zLeft = sqliteStrNDup(pLeft->z, pLeft->n);
   sqliteDequote(zLeft);
@@ -2237,8 +2239,6 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
       { OP_ColumnName,  0, 0,        "cache_size"},
       { OP_Callback,    1, 0,        0},
     };
-    Vdbe *v = sqliteGetVdbe(pParse);
-    if( v==0 ) return;
     if( pRight->z==pLeft->z ){
       sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
     }else{
@@ -2277,8 +2277,6 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
       { OP_ColumnName,  0, 0,        "cache_size"},
       { OP_Callback,    1, 0,        0},
     };
-    Vdbe *v = sqliteGetVdbe(pParse);
-    if( v==0 ) return;
     if( pRight->z==pLeft->z ){
       int size = db->cache_size;;
       if( size<0 ) size = -size;
@@ -2327,8 +2325,6 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
       { OP_AddImm,     -1, 0,        0},  /* 10 */
       { OP_Callback,    1, 0,        0}
     };
-    Vdbe *v = sqliteGetVdbe(pParse);
-    if( v==0 ) return;
     if( pRight->z==pLeft->z ){
       int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
       sqliteVdbeChangeP2(v, addr+3, addr+10);
@@ -2372,8 +2368,6 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
       { OP_ColumnName,  0, 0,        "synchronous"},
       { OP_Callback,    1, 0,        0},
     };
-    Vdbe *v = sqliteGetVdbe(pParse);
-    if( v==0 ) return;
     if( pRight->z==pLeft->z ){
       sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0);
       sqliteVdbeAddOpList(v, ArraySize(getSync), getSync);
@@ -2446,10 +2440,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
 
   if( sqliteStrICmp(zLeft, "table_info")==0 ){
     Table *pTab;
-    Vdbe *v;
     pTab = sqliteFindTable(db, zRight);
-    if( pTab ) v = sqliteGetVdbe(pParse);
-    if( pTab && v ){
+    if( pTab ){
       static VdbeOp tableInfoPreface[] = {
         { OP_ColumnName,  0, 0,       "cid"},
         { OP_ColumnName,  1, 0,       "name"},
@@ -2478,10 +2470,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
   if( sqliteStrICmp(zLeft, "index_info")==0 ){
     Index *pIdx;
     Table *pTab;
-    Vdbe *v;
     pIdx = sqliteFindIndex(db, zRight);
-    if( pIdx ) v = sqliteGetVdbe(pParse);
-    if( pIdx && v ){
+    if( pIdx ){
       static VdbeOp tableInfoPreface[] = {
         { OP_ColumnName,  0, 0,       "seqno"},
         { OP_ColumnName,  1, 0,       "cid"},
@@ -2505,13 +2495,12 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
   if( sqliteStrICmp(zLeft, "index_list")==0 ){
     Index *pIdx;
     Table *pTab;
-    Vdbe *v;
     pTab = sqliteFindTable(db, zRight);
     if( pTab ){
       v = sqliteGetVdbe(pParse);
       pIdx = pTab->pIndex;
     }
-    if( pTab && pIdx && v ){
+    if( pTab && pIdx ){
       int i = 0; 
       static VdbeOp indexListPreface[] = {
         { OP_ColumnName,  0, 0,       "seq"},
@@ -2563,8 +2552,6 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
       { OP_IntegrityCk, 1, 1,        0},    /* 15 */
       { OP_Callback,    1, 0,        0},
     };
-    Vdbe *v = sqliteGetVdbe(pParse);
-    if( v==0 ) return;
     sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb);
   }else
 
index 84beb0c0f31345f8039f91e3b4b4af2f0f6aca8d..beca506110be96138144f52fd21eeae6234b3cb8 100644 (file)
@@ -36,7 +36,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.205 2003/02/20 01:48:13 drh Exp $
+** $Id: vdbe.c,v 1.206 2003/03/01 19:45:34 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1300,7 +1300,7 @@ int sqliteVdbeList(
       p->rc = SQLITE_MISUSE;
     }
   }
-  return p->rc==SQLITE_OK ? SQLITE_OK : SQLITE_ERROR;
+  return p->rc==SQLITE_OK ? SQLITE_DONE : SQLITE_ERROR;
 }
 
 /*
index f171e62cbf0fdae7c86c992c141ac0a992319e8b..c1292089aca3b29bf8676968443687c92ba8f0e8 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script testing the callback-free C/C++ API.
 #
-# $Id: capi2.test,v 1.4 2003/02/16 22:21:33 drh Exp $
+# $Id: capi2.test,v 1.5 2003/03/01 19:45:35 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -389,6 +389,60 @@ do_test capi2-6.28 {
 do_test capi2-6.99 {
   list [catch {sqlite_finalize $VM1} msg] [set msg]
 } {0 {}}
+execsql {ROLLBACK}
+
+do_test capi2-7.1 {
+  stepsql $DB {
+    SELECT * FROM t1
+  }
+} {0 1 2 3}
+do_test capi2-7.2 {
+  stepsql $DB {
+    PRAGMA count_changes=on
+  }
+} {0}
+do_test capi2-7.3 {
+  stepsql $DB {
+    UPDATE t1 SET a=a+10;
+  }
+} {0 1}
+do_test capi2-7.4 {
+  stepsql $DB {
+    INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
+  }
+} {0 1}
+do_test capi2-7.5 {
+  stepsql $DB {
+    UPDATE t1 SET a=a+10;
+  }
+} {0 2}
+do_test capi2-7.6 {
+  stepsql $DB {
+    SELECT * FROM t1;
+  }
+} {0 21 2 3 22 3 4}
+do_test capi2-7.7 {
+  stepsql $DB {
+    INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
+  }
+} {0 2}
+do_test capi2-7.8 {
+  stepsql $DB {
+    SELECT * FROM t1;
+  }
+} {0 21 2 3 22 3 4 23 4 5 24 5 6}
+do_test capi2-7.9 {
+  stepsql $DB {
+    UPDATE t1 SET a=a-20;
+    SELECT * FROM t1;
+  }
+} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
+do_test capi2-7.10 {
+  set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
+  lindex $x 0
+} {0}
+
+
 
 db2 close
 
index 642e6fcf0b342dfad7b5252d4c612fc9e3083ce2..788dda5bd7deffc7c08c99d836810d75fffdc441 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.24 2003/02/16 22:21:33 drh Exp $
+# $Id: tester.tcl,v 1.25 2003/03/01 19:45:35 drh Exp $
 
 # Make sure tclsqlite was compiled correctly.  Abort now with an
 # error message if not.
@@ -214,6 +214,26 @@ proc execsql2 {sql} {
   return $result
 }
 
+# Use the non-callback API to execute multiple SQL statements
+#
+proc stepsql {dbptr sql} {
+  set sql [string trim $sql]
+  set r 0
+  while {[string length $sql]>0} {
+    if {[catch {sqlite_compile $dbptr $sql sqltail} vm]} {
+      return [list 1 $vm]
+    }
+    set sql [string trim $sqltail]
+    while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} {
+      foreach v $VAL {lappend r $v}
+    }
+    if {[catch {sqlite_finalize $vm} errmsg]} {
+      return [list 1 $errmsg]
+    }
+  }
+  return $r
+}
+
 # Delete a file or directory
 #
 proc forcedelete {filename} {
index 4798c188e2a163e605c489c25f6dbc1fe10b27fb..e549a7211421f3f7ed23d57d7dadfa574f1ebb7a 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Run this Tcl script to generate the sqlite.html file.
 #
-set rcsid {$Id: c_interface.tcl,v 1.36 2003/01/29 22:58:27 drh Exp $}
+set rcsid {$Id: c_interface.tcl,v 1.37 2003/03/01 19:45:35 drh Exp $}
 
 puts {<html>
 <head>
@@ -660,7 +660,8 @@ for the most recent INSERT statement using the
 
 <p>The <b>sqlite_changes</b> API function returns the number of rows
 that were inserted, deleted, or modified during the most recent
-<b>sqlite_exec</b> call.  The number reported includes any changes
+<b>sqlite_exec</b> call of by <b>sqlite_step</b> calls since the
+most recent <b>sqlite_compile</b>.  The number reported includes any changes
 that were later undone by a ROLLBACK or ABORT.  But rows that are
 deleted because of a DROP TABLE are <em>not</em> counted.</p>