diff options
author | drh <drh@noemail.net> | 2008-06-19 02:52:25 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2008-06-19 02:52:25 +0000 |
commit | bb5a9c3eea276ff67a2823df1cad92a3af1be354 (patch) | |
tree | 2126114665d735b59bd39cdf5b2306a5c0e6d66c | |
parent | 8c4d6b97e0f76248b26442237c758e3f55c2b904 (diff) | |
download | sqlite-bb5a9c3eea276ff67a2823df1cad92a3af1be354.tar.gz sqlite-bb5a9c3eea276ff67a2823df1cad92a3af1be354.zip |
Add the sqlite3_next_stmt() interface, including test cases. (CVS 5243)
FossilOrigin-Name: 565a530896b40790287eeaad709edd51980fbddf
-rw-r--r-- | manifest | 17 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/sqlite.h.in | 35 | ||||
-rw-r--r-- | src/test1.c | 35 | ||||
-rw-r--r-- | src/vdbeapi.c | 20 | ||||
-rw-r--r-- | test/capi3d.test | 92 |
6 files changed, 189 insertions, 12 deletions
@@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\sthe\snoop-mutex\simplementation.\s(CVS\s5242) -D 2008-06-19T01:50:09 +C Add\sthe\ssqlite3_next_stmt()\sinterface,\sincluding\stest\scases.\s(CVS\s5243) +D 2008-06-19T02:52:25 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in ff6f90048555a0088f6a4b7406bed5e55a7c4eff F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -143,13 +143,13 @@ F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a F src/select.c 669687459e7d0193c89de06c5dbed55b4a41191c F src/shell.c a12ea645271b7876c8f080146f48e20b00d367ec -F src/sqlite.h.in f69427508e76eec76dae7f5fffdfefc05a9d4329 +F src/sqlite.h.in 2590420afe3c9c5a05ee7269f32c3c6f4b06c053 F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3 F src/sqliteInt.h 6dd55232e738a4dac23475cd4b0e444dff75c896 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822 F src/tclsqlite.c 4dd9ee4cb44846ad9bcc4d0da8088c1e7d4b33d9 -F src/test1.c 736be7dea5cc126356bbb61a4b1ac5ff4fac7994 +F src/test1.c e78c07d7f1db40593ab1e4aa321016184af0c7ad F src/test2.c c46d146019ab6e37474e66b3c789e5237d9ea7b7 F src/test3.c 01ff03164cf6a2bededa3b44ecd481603e2644fc F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071 @@ -184,7 +184,7 @@ F src/vacuum.c 14eb21b480924d87e791cd8ab6fb35ac563243ef F src/vdbe.c f6866986de706b98c2738040bc65907728650e8d F src/vdbe.h 1e3722d471739c2b213c6283b60373290e52f7ea F src/vdbeInt.h de321b2c02593e1420106634ed1f5a7d77ad35a7 -F src/vdbeapi.c 9cf3207a58e484c74c60d61ac037c1cad8aa5b65 +F src/vdbeapi.c a7c6b8db324cf7eccff32de871dea36aa305c994 F src/vdbeaux.c 09d7a6923d4d71d7028e0d72b9d146d3ece6054e F src/vdbeblob.c 9345f6dcd675fdcfdb537d2d2f487542d9ea136a F src/vdbefifo.c c46dae1194e4277bf007144d7e5b0c0b1c24f136 @@ -228,6 +228,7 @@ F test/capi2.test cc64df7560a96f848f919ea2926c60acf639684b F test/capi3.test d3848b06fb36d43b73aca6e22c44f734e14e5c3b F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97 F test/capi3c.test 208713e5f3a63442c3574c55b83baa7cf8ac5f28 +F test/capi3d.test 537de3a1f724862e327e02bb21b4a84f185dc1e2 F test/cast.test ce8f14fc80f70b30ed984480cc0d8914a459e8f9 F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184 F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04 @@ -598,7 +599,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 005f8eaef5ae05cef5c76f3afe299eaa2cf8af2f -R bb3c0fc73a660955ea9906ca7b361daf +P eec9a54dc3554a00ea69fc8e26d205f30a3bcabd +R c8ee455d2762ac91cbcc6d328820d18d U drh -Z a303ab4342edea1fe35b42a109e80885 +Z 1aaf0ee87bfe5a8385c7655d6421e7d4 diff --git a/manifest.uuid b/manifest.uuid index ecb935ce4..1e801bd91 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eec9a54dc3554a00ea69fc8e26d205f30a3bcabd
\ No newline at end of file +565a530896b40790287eeaad709edd51980fbddf
\ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index b072c0663..9ea25148d 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.337 2008/06/19 00:16:08 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.338 2008/06/19 02:52:25 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -4739,6 +4739,39 @@ int sqlite3_get_autocommit(sqlite3*); */ sqlite3 *sqlite3_db_handle(sqlite3_stmt*); +/* +** CAPI3REF: Find the next prepared statement {F13140} +** +** Return a pointer to the next [prepared statement] after pStmt +** associated with [database connection] pDb. If pStmt is NULL +** then return a pointer to the first [prepared statement] associated +** with the [database connection] pDb. If no [prepared statement] +** satisfies the conditions of this routine, return NULL. +** +** INVARIANTS: +** +** {F13143} If D is a [database connection] that holds one or more +** unfinalized [prepared statements] and S is a NULL pointer, +** then [sqlite3_next_stmt(D, S)] routine shall return a pointer +** to one of the [prepared statements] associated with D. +** +** {F13146} If D is a [database connection] that holds no +** unfinalized [prepared statements] and S is a NULL pointer, +** then [sqlite3_next_stmt(D, S)] routine shall return a NULL +** pointer. +** +** {F13149} If S is a [prepared statement] in [database connection] D +** and S is not the last [prepared statement] in D, then +** [sqlite3_next_stmt(D, S)] routine shall return a pointer +** to the next [prepared statement] in D after S. +** +** {F13152} If S is the last [prepared statement] in [database connection] D +** then [sqlite3_next_stmt(D, S)] routine shall return a NULL +** pointer. +** +*/ +sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); + /* ** CAPI3REF: Commit And Rollback Notification Callbacks {F12950} diff --git a/src/test1.c b/src/test1.c index 6174f2b13..f31e5d8ee 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.305 2008/05/29 02:57:48 shane Exp $ +** $Id: test1.c,v 1.306 2008/06/19 02:52:25 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -1899,6 +1899,38 @@ static int test_finalize( } /* +** Usage: sqlite3_next_stmt DB STMT +** +** Return the next statment in sequence after STMT. +*/ +static int test_next_stmt( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + sqlite3_stmt *pStmt; + sqlite3 *db = 0; + char zBuf[50]; + + if( objc!=3 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", + Tcl_GetStringFromObj(objv[0], 0), " DB STMT", 0); + return TCL_ERROR; + } + + if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; + if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt) ) return TCL_ERROR; + pStmt = sqlite3_next_stmt(db, pStmt); + if( pStmt ){ + if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; + Tcl_AppendResult(interp, zBuf, 0); + } + return TCL_OK; +} + + +/* ** Usage: sqlite3_reset STMT ** ** Reset a statement handle. @@ -4605,6 +4637,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_transfer_bindings", test_transfer_bind ,0 }, { "sqlite3_changes", test_changes ,0 }, { "sqlite3_step", test_step ,0 }, + { "sqlite3_next_stmt", test_next_stmt ,0 }, { "sqlite3_release_memory", test_release_memory, 0}, { "sqlite3_soft_heap_limit", test_soft_heap_limit, 0}, diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 8fc3987c6..fea540f43 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -13,7 +13,7 @@ ** This file contains code use to implement APIs that are part of the ** VDBE. ** -** $Id: vdbeapi.c,v 1.133 2008/06/18 17:09:10 danielk1977 Exp $ +** $Id: vdbeapi.c,v 1.134 2008/06/19 02:52:25 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -1256,3 +1256,21 @@ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){ return pStmt ? ((Vdbe*)pStmt)->db : 0; } + +/* +** Return a pointer to the next prepared statement after pStmt associated +** with database connection pDb. If pStmt is NULL, return the first +** prepared statement for the database connection. Return NULL if there +** are no more. +*/ +sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){ + sqlite3_stmt *pNext; + sqlite3_mutex_enter(pDb->mutex); + if( pStmt==0 ){ + pNext = (sqlite3_stmt*)pDb->pVdbe; + }else{ + pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext; + } + sqlite3_mutex_leave(pDb->mutex); + return pNext; +} diff --git a/test/capi3d.test b/test/capi3d.test new file mode 100644 index 000000000..a441afa76 --- /dev/null +++ b/test/capi3d.test @@ -0,0 +1,92 @@ +# 2008 June 18 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is devoted to testing the sqlite3_next_stmt interface. +# +# $Id: capi3d.test,v 1.1 2008/06/19 02:52:25 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create N prepared statements against database connection db +# and return a list of all the generated prepared statements. +# +proc make_prepared_statements {N} { + set plist {} + for {set i 0} {$i<$N} {incr i} { + set sql "SELECT $i FROM sqlite_master WHERE name LIKE '%$i%'" + if {rand()<0.33} { + set s [sqlite3_prepare_v2 db $sql -1 notused] + } else { + ifcapable utf16 { + if {rand()<0.5} { + set sql [encoding convertto unicode $sql]\x00\x00 + set s [sqlite3_prepare16 db $sql -1 notused] + } else { + set s [sqlite3_prepare db $sql -1 notused] + } + } + ifcapable !utf16 { + set s [sqlite3_prepare db $sql -1 notused] + } + } + lappend plist $s + } + return $plist +} + + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# Database initially has no prepared statements. +# +do_test capi3d-1.1 { + sqlite3_next_stmt db 0 +} {} + +# Run the following tests for between 1 and 100 prepared statements. +# +for {set i 1} {$i<=100} {incr i} { + set stmtlist [make_prepared_statements $i] + do_test capi3d-1.2.$i.1 { + set p [sqlite3_next_stmt db 0] + set x {} + while {$p!=""} { + lappend x $p + set p [sqlite3_next_stmt db $p] + } + lsort $x + } [lsort $stmtlist] + do_test capi3-1.2.$i.2 { + foreach p [scramble $::stmtlist] { + sqlite3_finalize $p + } + sqlite3_next_stmt db 0 + } {} +} + + +finish_test |