From 0f5ea0b34ccc94c8356996248dcf00830b562841 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 9 Apr 2009 14:02:44 +0000 Subject: [PATCH] Remove misuse detection from the deprecated sqlite3_transfer_bindings() interface. The code was hard to test and was simply taking up space. (CVS 6476) FossilOrigin-Name: 4cd829107cc9e94b092490aa821574492292b425 --- manifest | 14 ++++++------ manifest.uuid | 2 +- src/vdbeapi.c | 57 ++++++++++++++++++++++++++-------------------- test/bindxfer.test | 9 +++----- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index a67a789ec8..552c7a28d9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\ssqlite3_shutdown()\sso\sthat\sit\sautomatically\sinvokes\nsqlite3_reset_auto_extension().\s\sThis\sis\sa\sharmless\sno-op\sif\sapplications\nare\salready\scalling\ssqlite3_reset_auto_extension()\sprior\sto\ssqlite3_shutdown().\nAnd\sit\sprevents\spossible\smemory\scorruption\sif\sthey\sdo\snot.\s\sSo\sit\sworks\neither\sway.\s\sMost\sof\sthe\schanges\sare\sto\sthe\stest\scases.\s(CVS\s6475) -D 2009-04-09T01:23:49 +C Remove\smisuse\sdetection\sfrom\sthe\sdeprecated\ssqlite3_transfer_bindings()\ninterface.\s\sThe\scode\swas\shard\sto\stest\sand\swas\ssimply\staking\sup\sspace.\s(CVS\s6476) +D 2009-04-09T14:02:44 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -203,7 +203,7 @@ F src/vacuum.c 07121a727beeee88f27d704a00313ad6a7c9bef0 F src/vdbe.c 3d252f70666a80fea2fb794b6fe154a282d11573 F src/vdbe.h d70a68bee196ab228914a3902c79dbd24342a0f2 F src/vdbeInt.h 53a2f4696871712646c77351904576cca6ad9752 -F src/vdbeapi.c adf0e8f104a831936d966888c427b70565087aed +F src/vdbeapi.c d3c6f28dbf462187f3fd696f2357e0d23940abac F src/vdbeaux.c 570aaa5e15ae141115194d22443c73c8beb5032b F src/vdbeblob.c e67757450ae8581a8b354d9d7e467e41502dfe38 F src/vdbemem.c 9798905787baae83d0b53b62030e32ecf7a0586f @@ -242,7 +242,7 @@ F test/between.test 16b1776c6323faadb097a52d673e8e3d8be7d070 F test/bigfile.test b746a34ce0e2039994b45fea8b7fbfa78f594cdf F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747 F test/bind.test 455f7e8322a215e245414625eede3ab0e1429c14 -F test/bindxfer.test d4f573750e06c34ef2309acb95ad57da1d3c983f +F test/bindxfer.test 7623b509240d8a3d4e26602bebfe4bbfbdc08895 F test/bitvec.test 75894a880520164d73b1305c1c3f96882615e142 F test/blob.test 2a38d867bdf08f9ce081776acec1ac8d4bca66be F test/boundary1.tcl 6421b2d920d8b09539503a8673339d32f7609eb1 @@ -716,7 +716,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 0628f5864f8cc035b41bbe644bd8ec8fb43c70ce -R 0cf963266eec9b2fca0ecf33410b18cd +P 0c41f7cff4f6ffb9321f6f6b6ef3e431b750d41a +R 59e3d78266a19aec5181c6f03b28fa03 U drh -Z c7192b6903fa3facf78f58d5b0aaedc3 +Z f358b0439d22ea82c6fffdf3f3cfcb17 diff --git a/manifest.uuid b/manifest.uuid index dda76da0dd..399d49ef6f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0c41f7cff4f6ffb9321f6f6b6ef3e431b750d41a \ No newline at end of file +4cd829107cc9e94b092490aa821574492292b425 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 87bb6da405..3a20b3efe4 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.158 2009/04/08 23:05:29 drh Exp $ +** $Id: vdbeapi.c,v 1.159 2009/04/09 14:02:44 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -1164,8 +1164,8 @@ int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){ rc = sqlite3VdbeChangeEncoding(&p->aVar[i-1], ENC(p->db)); } sqlite3_mutex_leave(p->db->mutex); + rc = sqlite3ApiExit(p->db, rc); } - rc = sqlite3ApiExit(p->db, rc); return rc; } int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){ @@ -1195,18 +1195,21 @@ int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){ */ static void createVarMap(Vdbe *p){ if( !p->okVar ){ + int j; + Op *pOp; sqlite3_mutex_enter(p->db->mutex); - if( !p->okVar ){ - int j; - Op *pOp; - for(j=0, pOp=p->aOp; jnOp; j++, pOp++){ - if( pOp->opcode==OP_Variable ){ - assert( pOp->p1>0 && pOp->p1<=p->nVar ); - p->azVar[pOp->p1-1] = pOp->p4.z; - } + /* The race condition here is harmless. If two threads call this + ** routine on the same Vdbe at the same time, they both might end + ** up initializing the Vdbe.azVar[] array. That is a little extra + ** work but it results in the same answer. + */ + for(j=0, pOp=p->aOp; jnOp; j++, pOp++){ + if( pOp->opcode==OP_Variable ){ + assert( pOp->p1>0 && pOp->p1<=p->nVar ); + p->azVar[pOp->p1-1] = pOp->p4.z; } - p->okVar = 1; } + p->okVar = 1; sqlite3_mutex_leave(p->db->mutex); } } @@ -1251,36 +1254,40 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ /* ** Transfer all bindings from the first statement over to the second. -** If the two statements contain a different number of bindings, then -** an SQLITE_ERROR is returned. */ int sqlite3TransferBindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ Vdbe *pFrom = (Vdbe*)pFromStmt; Vdbe *pTo = (Vdbe*)pToStmt; - int i, rc = SQLITE_OK; - if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT) - || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) - || pTo->db!=pFrom->db ){ - return SQLITE_MISUSE; - } - if( pFrom->nVar!=pTo->nVar ){ - return SQLITE_ERROR; - } + int i; + assert( pTo->db==pFrom->db ); + assert( pTo->nVar==pFrom->nVar ); sqlite3_mutex_enter(pTo->db->mutex); - for(i=0; rc==SQLITE_OK && inVar; i++){ + for(i=0; inVar; i++){ sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); } sqlite3_mutex_leave(pTo->db->mutex); - assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); - return rc; + return SQLITE_OK; } #ifndef SQLITE_OMIT_DEPRECATED /* ** Deprecated external interface. Internal/core SQLite code ** should call sqlite3TransferBindings. +** +** Is is misuse to call this routine with statements from different +** database connections. But as this is a deprecated interface, we +** will not bother to check for that condition. +** +** If the two statements contain a different number of bindings, then +** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise +** SQLITE_OK is returned. */ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){ + Vdbe *pFrom = (Vdbe*)pFromStmt; + Vdbe *pTo = (Vdbe*)pToStmt; + if( pFrom->nVar!=pTo->nVar ){ + return SQLITE_ERROR; + } return sqlite3TransferBindings(pFromStmt, pToStmt); } #endif diff --git a/test/bindxfer.test b/test/bindxfer.test index 266993542b..b8e71d901b 100644 --- a/test/bindxfer.test +++ b/test/bindxfer.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script testing the sqlite_transfer_bindings() API. # -# $Id: bindxfer.test,v 1.6 2008/10/12 00:27:54 shane Exp $ +# $Id: bindxfer.test,v 1.7 2009/04/09 14:02:44 drh Exp $ # set testdir [file dirname $argv0] @@ -68,11 +68,8 @@ ifcapable deprecated { do_test bindxfer-1.8 { set VALUES } {one two {}} - do_test bindxfer-1.9-misuse { - catch {sqlite3_finalize $VM1} - catch {sqlite3_finalize $VM2} - sqlite3_transfer_bindings $VM1 $VM2 - } 21 ;# SQLITE_MISUSE + catch {sqlite3_finalize $VM1} + catch {sqlite3_finalize $VM2} do_test bindxfer-1.10 { set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL] set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?, ?} -1 TAIL] -- 2.47.2