]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In sqlite3_bind() interfaces, avoid acquiring the mutex until after the
authordrh <drh@noemail.net>
Mon, 6 Oct 2008 12:46:43 +0000 (12:46 +0000)
committerdrh <drh@noemail.net>
Mon, 6 Oct 2008 12:46:43 +0000 (12:46 +0000)
statement handle has been validated.  Ticket #3418. (CVS 5768)

FossilOrigin-Name: 693503e241001271512f4ce3e8cc932ba6a3106c

manifest
manifest.uuid
src/vdbeapi.c

index a464c4071d12266ab527b1f5ff3782e265a0f41d..7ddcfbfbc0a0199f2fdb0523eff84b349e269e30 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sa\stest\sto\sindexedby.test\sto\scheck\sthat\sautomatic\sindexes\s(sqlite_autoindex_xxx)\scan\sbe\sused\swith\sthe\sINDEXED\sBY\ssyntax.\s(CVS\s5767)
-D 2008-10-06T11:29:49
+C In\ssqlite3_bind()\sinterfaces,\savoid\sacquiring\sthe\smutex\suntil\safter\sthe\nstatement\shandle\shas\sbeen\svalidated.\s\sTicket\s#3418.\s(CVS\s5768)
+D 2008-10-06T12:46:44
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in e4ab842f9a64ef61d57093539a8aab76b12810db
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -192,7 +192,7 @@ F src/vacuum.c fd77433d0c26d3ff1eb96eab017a1787ac5aa642
 F src/vdbe.c c9499f1824049cfef00a6146ef832b742f477920
 F src/vdbe.h 41c99aaad9167c1b5431993db446de74b2f71fc3
 F src/vdbeInt.h b48c74d86a9fb62b707a3186ccca76bb32f1c6be
-F src/vdbeapi.c c0f87aabb2bcf8c760ff9cb289119f7f6ba1797a
+F src/vdbeapi.c 5beff875bef3a801484ac78c24b13a039a4d511c
 F src/vdbeaux.c 20a7d109c95e32beee7891fba828c63e419af26c
 F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
 F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
@@ -639,7 +639,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 98ca5580f5acd2e7b3ce512520ec0527f221505e
-R 0f893f469ad12cc6a25579e35395d754
-U danielk1977
-Z ca84df9ff1faefde10026b9c258b030a
+P bb51c34506b3353506b6f3566fbe2a10d02e8ebc
+R 69a4995829880b2d104f98bd582a2981
+U drh
+Z aca7259dd10a822c578f92e2091145fe
index 2e06e150391f75f78f0a20cf89776c0c71f05f6e..0456388007a8d34278dfa50e82ae3661e694ab96 100644 (file)
@@ -1 +1 @@
-bb51c34506b3353506b6f3566fbe2a10d02e8ebc
\ No newline at end of file
+693503e241001271512f4ce3e8cc932ba6a3106c
\ No newline at end of file
index 2ce388c1ca2bf6f11d08e60593af97b88185d315..5fd14802dde97efd42473fb7fc0d8472d0ab6c6d 100644 (file)
@@ -13,7 +13,7 @@
 ** This file contains code use to implement APIs that are part of the
 ** VDBE.
 **
-** $Id: vdbeapi.c,v 1.141 2008/09/04 12:03:43 shane Exp $
+** $Id: vdbeapi.c,v 1.142 2008/10/06 12:46:44 drh Exp $
 */
 #include "sqliteInt.h"
 #include "vdbeInt.h"
@@ -1005,17 +1005,24 @@ const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
 ** the same as binding a NULL value to the column. If the "i" parameter is
 ** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
 **
+** A successful evaluation of this routine acquires the mutex on p.
+** the mutex is released if any kind of error occurs.
+**
 ** The error code stored in database p->db is overwritten with the return
 ** value in any case.
 */
 static int vdbeUnbind(Vdbe *p, int i){
   Mem *pVar;
-  if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
-    if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
+  if( p==0 ) return SQLITE_MISUSE;
+  sqlite3_mutex_enter(p->db->mutex);
+  if( p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
+    sqlite3Error(p->db, SQLITE_MISUSE, 0);
+    sqlite3_mutex_leave(p->db->mutex);
     return SQLITE_MISUSE;
   }
   if( i<1 || i>p->nVar ){
     sqlite3Error(p->db, SQLITE_RANGE, 0);
+    sqlite3_mutex_leave(p->db->mutex);
     return SQLITE_RANGE;
   }
   i--;
@@ -1041,21 +1048,19 @@ static int bindText(
   Mem *pVar;
   int rc;
 
-  if( p==0 ){
-    return SQLITE_MISUSE;
-  }
-  sqlite3_mutex_enter(p->db->mutex);
   rc = vdbeUnbind(p, i);
-  if( rc==SQLITE_OK && zData!=0 ){
-    pVar = &p->aVar[i-1];
-    rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
-    if( rc==SQLITE_OK && encoding!=0 ){
-      rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
+  if( rc==SQLITE_OK ){
+    if( zData!=0 ){
+      pVar = &p->aVar[i-1];
+      rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
+      if( rc==SQLITE_OK && encoding!=0 ){
+        rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
+      }
+      sqlite3Error(p->db, rc, 0);
+      rc = sqlite3ApiExit(p->db, rc);
     }
-    sqlite3Error(p->db, rc, 0);
-    rc = sqlite3ApiExit(p->db, rc);
+    sqlite3_mutex_leave(p->db->mutex);
   }
-  sqlite3_mutex_leave(p->db->mutex);
   return rc;
 }
 
@@ -1075,12 +1080,11 @@ int sqlite3_bind_blob(
 int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
   int rc;
   Vdbe *p = (Vdbe *)pStmt;
-  sqlite3_mutex_enter(p->db->mutex);
   rc = vdbeUnbind(p, i);
   if( rc==SQLITE_OK ){
     sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
+    sqlite3_mutex_leave(p->db->mutex);
   }
-  sqlite3_mutex_leave(p->db->mutex);
   return rc;
 }
 int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
@@ -1089,20 +1093,20 @@ int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
 int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
   int rc;
   Vdbe *p = (Vdbe *)pStmt;
-  sqlite3_mutex_enter(p->db->mutex);
   rc = vdbeUnbind(p, i);
   if( rc==SQLITE_OK ){
     sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
+    sqlite3_mutex_leave(p->db->mutex);
   }
-  sqlite3_mutex_leave(p->db->mutex);
   return rc;
 }
 int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
   int rc;
   Vdbe *p = (Vdbe*)pStmt;
-  sqlite3_mutex_enter(p->db->mutex);
   rc = vdbeUnbind(p, i);
-  sqlite3_mutex_leave(p->db->mutex);
+  if( rc==SQLITE_OK ){
+    sqlite3_mutex_leave(p->db->mutex);
+  }
   return rc;
 }
 int sqlite3_bind_text( 
@@ -1128,27 +1132,25 @@ int sqlite3_bind_text16(
 int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
   int rc;
   Vdbe *p = (Vdbe *)pStmt;
-  sqlite3_mutex_enter(p->db->mutex);
   rc = vdbeUnbind(p, i);
   if( rc==SQLITE_OK ){
     rc = sqlite3VdbeMemCopy(&p->aVar[i-1], pValue);
     if( rc==SQLITE_OK ){
       rc = sqlite3VdbeChangeEncoding(&p->aVar[i-1], ENC(p->db));
     }
+    sqlite3_mutex_leave(p->db->mutex);
   }
-  rc = sqlite3ApiExit(p->db, rc);
-  sqlite3_mutex_leave(p->db->mutex);
+  /* rc = sqlite3ApiExit(p->db, rc); */
   return rc;
 }
 int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
   int rc;
   Vdbe *p = (Vdbe *)pStmt;
-  sqlite3_mutex_enter(p->db->mutex);
   rc = vdbeUnbind(p, i);
   if( rc==SQLITE_OK ){
     sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
+    sqlite3_mutex_leave(p->db->mutex);
   }
-  sqlite3_mutex_leave(p->db->mutex);
   return rc;
 }