Index: third_party/sqlite/src/src/test3.c |
diff --git a/third_party/sqlite/src/src/test3.c b/third_party/sqlite/src/src/test3.c |
index e3ed310c8104fe3621cebb0f51d10145018d4fac..2a41068e5f9bd775a9f58343ffd0496601a2a437 100644 |
--- a/third_party/sqlite/src/src/test3.c |
+++ b/third_party/sqlite/src/src/test3.c |
@@ -214,16 +214,19 @@ static int btree_cursor( |
pBt = sqlite3TestTextToPtr(argv[1]); |
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR; |
if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR; |
+ if( wrFlag ) wrFlag = BTREE_WRCSR; |
pCur = (BtCursor *)ckalloc(sqlite3BtreeCursorSize()); |
memset(pCur, 0, sqlite3BtreeCursorSize()); |
+ sqlite3_mutex_enter(pBt->db->mutex); |
sqlite3BtreeEnter(pBt); |
#ifndef SQLITE_OMIT_SHARED_CACHE |
- rc = sqlite3BtreeLockTable(pBt, iTable, wrFlag); |
+ rc = sqlite3BtreeLockTable(pBt, iTable, !!wrFlag); |
#endif |
if( rc==SQLITE_OK ){ |
rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, pCur); |
} |
sqlite3BtreeLeave(pBt); |
+ sqlite3_mutex_leave(pBt->db->mutex); |
if( rc ){ |
ckfree((char *)pCur); |
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
@@ -256,9 +259,11 @@ static int btree_close_cursor( |
} |
pCur = sqlite3TestTextToPtr(argv[1]); |
pBt = pCur->pBtree; |
+ sqlite3_mutex_enter(pBt->db->mutex); |
sqlite3BtreeEnter(pBt); |
rc = sqlite3BtreeCloseCursor(pCur); |
sqlite3BtreeLeave(pBt); |
+ sqlite3_mutex_leave(pBt->db->mutex); |
ckfree((char *)pCur); |
if( rc ){ |
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
@@ -445,18 +450,21 @@ static int btree_varint_test( |
char zErr[200]; |
n1 = putVarint(zBuf, in); |
if( n1>9 || n1<1 ){ |
- sprintf(zErr, "putVarint returned %d - should be between 1 and 9", n1); |
+ sqlite3_snprintf(sizeof(zErr), zErr, |
+ "putVarint returned %d - should be between 1 and 9", n1); |
Tcl_AppendResult(interp, zErr, 0); |
return TCL_ERROR; |
} |
n2 = getVarint(zBuf, &out); |
if( n1!=n2 ){ |
- sprintf(zErr, "putVarint returned %d and getVarint returned %d", n1, n2); |
+ sqlite3_snprintf(sizeof(zErr), zErr, |
+ "putVarint returned %d and getVarint returned %d", n1, n2); |
Tcl_AppendResult(interp, zErr, 0); |
return TCL_ERROR; |
} |
if( in!=out ){ |
- sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx", in, out); |
+ sqlite3_snprintf(sizeof(zErr), zErr, |
+ "Wrote 0x%016llx and got back 0x%016llx", in, out); |
Tcl_AppendResult(interp, zErr, 0); |
return TCL_ERROR; |
} |
@@ -465,13 +473,15 @@ static int btree_varint_test( |
n2 = getVarint32(zBuf, out32); |
out = out32; |
if( n1!=n2 ){ |
- sprintf(zErr, "putVarint returned %d and GetVarint32 returned %d", |
+ sqlite3_snprintf(sizeof(zErr), zErr, |
+ "putVarint returned %d and GetVarint32 returned %d", |
n1, n2); |
Tcl_AppendResult(interp, zErr, 0); |
return TCL_ERROR; |
} |
if( in!=out ){ |
- sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx from GetVarint32", |
+ sqlite3_snprintf(sizeof(zErr), zErr, |
+ "Wrote 0x%016llx and got back 0x%016llx from GetVarint32", |
in, out); |
Tcl_AppendResult(interp, zErr, 0); |
return TCL_ERROR; |
@@ -593,6 +603,50 @@ static int btree_set_cache_size( |
return TCL_OK; |
} |
+/* |
+** usage: btree_insert CSR ?KEY? VALUE |
+** |
+** Set the size of the cache used by btree $ID. |
+*/ |
+static int btree_insert( |
+ ClientData clientData, |
+ Tcl_Interp *interp, |
+ int objc, |
+ Tcl_Obj *const objv[] |
+){ |
+ BtCursor *pCur; |
+ int rc; |
+ void *pKey = 0; |
+ int nKey = 0; |
+ void *pData = 0; |
+ int nData = 0; |
+ |
+ if( objc!=4 && objc!=3 ){ |
+ Tcl_WrongNumArgs(interp, 1, objv, "?-intkey? CSR KEY VALUE"); |
+ return TCL_ERROR; |
+ } |
+ |
+ if( objc==4 ){ |
+ if( Tcl_GetIntFromObj(interp, objv[2], &nKey) ) return TCL_ERROR; |
+ pData = (void*)Tcl_GetByteArrayFromObj(objv[3], &nData); |
+ }else{ |
+ pKey = (void*)Tcl_GetByteArrayFromObj(objv[2], &nKey); |
+ } |
+ pCur = (BtCursor*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); |
+ |
+ sqlite3_mutex_enter(pCur->pBtree->db->mutex); |
+ sqlite3BtreeEnter(pCur->pBtree); |
+ rc = sqlite3BtreeInsert(pCur, pKey, nKey, pData, nData, 0, 0, 0); |
+ sqlite3BtreeLeave(pCur->pBtree); |
+ sqlite3_mutex_leave(pCur->pBtree->db->mutex); |
+ |
+ Tcl_ResetResult(interp); |
+ if( rc ){ |
+ Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
+ return TCL_ERROR; |
+ } |
+ return TCL_OK; |
+} |
/* |
@@ -624,5 +678,7 @@ int Sqlitetest3_Init(Tcl_Interp *interp){ |
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
} |
+ Tcl_CreateObjCommand(interp, "btree_insert", btree_insert, 0, 0); |
+ |
return TCL_OK; |
} |