| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** 2001 September 15 | 2 ** 2001 September 15 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 ** | 23 ** |
| 24 ** -DSQLITE_TEST When used in conjuction with -DTCLSH=1, add | 24 ** -DSQLITE_TEST When used in conjuction with -DTCLSH=1, add |
| 25 ** hundreds of new commands used for testing | 25 ** hundreds of new commands used for testing |
| 26 ** SQLite. This option implies -DSQLITE_TCLMD5. | 26 ** SQLite. This option implies -DSQLITE_TCLMD5. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 /* | 29 /* |
| 30 ** If requested, include the SQLite compiler options file for MSVC. | 30 ** If requested, include the SQLite compiler options file for MSVC. |
| 31 */ | 31 */ |
| 32 #if defined(INCLUDE_MSVC_H) | 32 #if defined(INCLUDE_MSVC_H) |
| 33 #include "msvc.h" | 33 # include "msvc.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #include "tcl.h" | 36 #if defined(INCLUDE_SQLITE_TCL_H) |
| 37 # include "sqlite_tcl.h" |
| 38 #else |
| 39 # include "tcl.h" |
| 40 # ifndef SQLITE_TCLAPI |
| 41 # define SQLITE_TCLAPI |
| 42 # endif |
| 43 #endif |
| 37 #include <errno.h> | 44 #include <errno.h> |
| 38 | 45 |
| 39 /* | 46 /* |
| 40 ** Some additional include files are needed if this file is not | 47 ** Some additional include files are needed if this file is not |
| 41 ** appended to the amalgamation. | 48 ** appended to the amalgamation. |
| 42 */ | 49 */ |
| 43 #ifndef SQLITE_AMALGAMATION | 50 #ifndef SQLITE_AMALGAMATION |
| 44 # include "sqlite3.h" | 51 # include "sqlite3.h" |
| 45 # include <stdlib.h> | 52 # include <stdlib.h> |
| 46 # include <string.h> | 53 # include <string.h> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ** testfixture executable), then it may be configured to use either | 133 ** testfixture executable), then it may be configured to use either |
| 127 ** sqlite3_prepare_v2() or sqlite3_prepare() to prepare SQL statements. | 134 ** sqlite3_prepare_v2() or sqlite3_prepare() to prepare SQL statements. |
| 128 ** If SqliteDb.bLegacyPrepare is true, sqlite3_prepare() is used. | 135 ** If SqliteDb.bLegacyPrepare is true, sqlite3_prepare() is used. |
| 129 */ | 136 */ |
| 130 struct SqliteDb { | 137 struct SqliteDb { |
| 131 sqlite3 *db; /* The "real" database structure. MUST BE FIRST */ | 138 sqlite3 *db; /* The "real" database structure. MUST BE FIRST */ |
| 132 Tcl_Interp *interp; /* The interpreter used for this database */ | 139 Tcl_Interp *interp; /* The interpreter used for this database */ |
| 133 char *zBusy; /* The busy callback routine */ | 140 char *zBusy; /* The busy callback routine */ |
| 134 char *zCommit; /* The commit hook callback routine */ | 141 char *zCommit; /* The commit hook callback routine */ |
| 135 char *zTrace; /* The trace callback routine */ | 142 char *zTrace; /* The trace callback routine */ |
| 143 char *zTraceV2; /* The trace_v2 callback routine */ |
| 136 char *zProfile; /* The profile callback routine */ | 144 char *zProfile; /* The profile callback routine */ |
| 137 char *zProgress; /* The progress callback routine */ | 145 char *zProgress; /* The progress callback routine */ |
| 138 char *zAuth; /* The authorization callback routine */ | 146 char *zAuth; /* The authorization callback routine */ |
| 139 int disableAuth; /* Disable the authorizer if it exists */ | 147 int disableAuth; /* Disable the authorizer if it exists */ |
| 140 char *zNull; /* Text to substitute for an SQL NULL value */ | 148 char *zNull; /* Text to substitute for an SQL NULL value */ |
| 141 SqlFunc *pFunc; /* List of SQL functions */ | 149 SqlFunc *pFunc; /* List of SQL functions */ |
| 142 Tcl_Obj *pUpdateHook; /* Update hook script (if any) */ | 150 Tcl_Obj *pUpdateHook; /* Update hook script (if any) */ |
| 151 Tcl_Obj *pPreUpdateHook; /* Pre-update hook script (if any) */ |
| 143 Tcl_Obj *pRollbackHook; /* Rollback hook script (if any) */ | 152 Tcl_Obj *pRollbackHook; /* Rollback hook script (if any) */ |
| 144 Tcl_Obj *pWalHook; /* WAL hook script (if any) */ | 153 Tcl_Obj *pWalHook; /* WAL hook script (if any) */ |
| 145 Tcl_Obj *pUnlockNotify; /* Unlock notify script (if any) */ | 154 Tcl_Obj *pUnlockNotify; /* Unlock notify script (if any) */ |
| 146 SqlCollate *pCollate; /* List of SQL collation functions */ | 155 SqlCollate *pCollate; /* List of SQL collation functions */ |
| 147 int rc; /* Return code of most recent sqlite3_exec() */ | 156 int rc; /* Return code of most recent sqlite3_exec() */ |
| 148 Tcl_Obj *pCollateNeeded; /* Collation needed script */ | 157 Tcl_Obj *pCollateNeeded; /* Collation needed script */ |
| 149 SqlPreparedStmt *stmtList; /* List of prepared statements*/ | 158 SqlPreparedStmt *stmtList; /* List of prepared statements*/ |
| 150 SqlPreparedStmt *stmtLast; /* Last statement in the list */ | 159 SqlPreparedStmt *stmtLast; /* Last statement in the list */ |
| 151 int maxStmt; /* The next maximum number of stmtList */ | 160 int maxStmt; /* The next maximum number of stmtList */ |
| 152 int nStmt; /* Number of statements in stmtList */ | 161 int nStmt; /* Number of statements in stmtList */ |
| 153 IncrblobChannel *pIncrblob;/* Linked list of open incrblob channels */ | 162 IncrblobChannel *pIncrblob;/* Linked list of open incrblob channels */ |
| 154 int nStep, nSort, nIndex; /* Statistics for most recent operation */ | 163 int nStep, nSort, nIndex; /* Statistics for most recent operation */ |
| 155 int nTransaction; /* Number of nested [transaction] methods */ | 164 int nTransaction; /* Number of nested [transaction] methods */ |
| 165 int openFlags; /* Flags used to open. (SQLITE_OPEN_URI) */ |
| 156 #ifdef SQLITE_TEST | 166 #ifdef SQLITE_TEST |
| 157 int bLegacyPrepare; /* True to use sqlite3_prepare() */ | 167 int bLegacyPrepare; /* True to use sqlite3_prepare() */ |
| 158 #endif | 168 #endif |
| 159 }; | 169 }; |
| 160 | 170 |
| 161 struct IncrblobChannel { | 171 struct IncrblobChannel { |
| 162 sqlite3_blob *pBlob; /* sqlite3 blob handle */ | 172 sqlite3_blob *pBlob; /* sqlite3 blob handle */ |
| 163 SqliteDb *pDb; /* Associated database connection */ | 173 SqliteDb *pDb; /* Associated database connection */ |
| 164 int iSeek; /* Current seek offset */ | 174 int iSeek; /* Current seek offset */ |
| 165 Tcl_Channel channel; /* Channel identifier */ | 175 Tcl_Channel channel; /* Channel identifier */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 183 ** Close all incrblob channels opened using database connection pDb. | 193 ** Close all incrblob channels opened using database connection pDb. |
| 184 ** This is called when shutting down the database connection. | 194 ** This is called when shutting down the database connection. |
| 185 */ | 195 */ |
| 186 static void closeIncrblobChannels(SqliteDb *pDb){ | 196 static void closeIncrblobChannels(SqliteDb *pDb){ |
| 187 IncrblobChannel *p; | 197 IncrblobChannel *p; |
| 188 IncrblobChannel *pNext; | 198 IncrblobChannel *pNext; |
| 189 | 199 |
| 190 for(p=pDb->pIncrblob; p; p=pNext){ | 200 for(p=pDb->pIncrblob; p; p=pNext){ |
| 191 pNext = p->pNext; | 201 pNext = p->pNext; |
| 192 | 202 |
| 193 /* Note: Calling unregister here call Tcl_Close on the incrblob channel, | 203 /* Note: Calling unregister here call Tcl_Close on the incrblob channel, |
| 194 ** which deletes the IncrblobChannel structure at *p. So do not | 204 ** which deletes the IncrblobChannel structure at *p. So do not |
| 195 ** call Tcl_Free() here. | 205 ** call Tcl_Free() here. |
| 196 */ | 206 */ |
| 197 Tcl_UnregisterChannel(pDb->interp, p->channel); | 207 Tcl_UnregisterChannel(pDb->interp, p->channel); |
| 198 } | 208 } |
| 199 } | 209 } |
| 200 | 210 |
| 201 /* | 211 /* |
| 202 ** Close an incremental blob channel. | 212 ** Close an incremental blob channel. |
| 203 */ | 213 */ |
| 204 static int incrblobClose(ClientData instanceData, Tcl_Interp *interp){ | 214 static int SQLITE_TCLAPI incrblobClose( |
| 215 ClientData instanceData, |
| 216 Tcl_Interp *interp |
| 217 ){ |
| 205 IncrblobChannel *p = (IncrblobChannel *)instanceData; | 218 IncrblobChannel *p = (IncrblobChannel *)instanceData; |
| 206 int rc = sqlite3_blob_close(p->pBlob); | 219 int rc = sqlite3_blob_close(p->pBlob); |
| 207 sqlite3 *db = p->pDb->db; | 220 sqlite3 *db = p->pDb->db; |
| 208 | 221 |
| 209 /* Remove the channel from the SqliteDb.pIncrblob list. */ | 222 /* Remove the channel from the SqliteDb.pIncrblob list. */ |
| 210 if( p->pNext ){ | 223 if( p->pNext ){ |
| 211 p->pNext->pPrev = p->pPrev; | 224 p->pNext->pPrev = p->pPrev; |
| 212 } | 225 } |
| 213 if( p->pPrev ){ | 226 if( p->pPrev ){ |
| 214 p->pPrev->pNext = p->pNext; | 227 p->pPrev->pNext = p->pNext; |
| 215 } | 228 } |
| 216 if( p->pDb->pIncrblob==p ){ | 229 if( p->pDb->pIncrblob==p ){ |
| 217 p->pDb->pIncrblob = p->pNext; | 230 p->pDb->pIncrblob = p->pNext; |
| 218 } | 231 } |
| 219 | 232 |
| 220 /* Free the IncrblobChannel structure */ | 233 /* Free the IncrblobChannel structure */ |
| 221 Tcl_Free((char *)p); | 234 Tcl_Free((char *)p); |
| 222 | 235 |
| 223 if( rc!=SQLITE_OK ){ | 236 if( rc!=SQLITE_OK ){ |
| 224 Tcl_SetResult(interp, (char *)sqlite3_errmsg(db), TCL_VOLATILE); | 237 Tcl_SetResult(interp, (char *)sqlite3_errmsg(db), TCL_VOLATILE); |
| 225 return TCL_ERROR; | 238 return TCL_ERROR; |
| 226 } | 239 } |
| 227 return TCL_OK; | 240 return TCL_OK; |
| 228 } | 241 } |
| 229 | 242 |
| 230 /* | 243 /* |
| 231 ** Read data from an incremental blob channel. | 244 ** Read data from an incremental blob channel. |
| 232 */ | 245 */ |
| 233 static int incrblobInput( | 246 static int SQLITE_TCLAPI incrblobInput( |
| 234 ClientData instanceData, | 247 ClientData instanceData, |
| 235 char *buf, | 248 char *buf, |
| 236 int bufSize, | 249 int bufSize, |
| 237 int *errorCodePtr | 250 int *errorCodePtr |
| 238 ){ | 251 ){ |
| 239 IncrblobChannel *p = (IncrblobChannel *)instanceData; | 252 IncrblobChannel *p = (IncrblobChannel *)instanceData; |
| 240 int nRead = bufSize; /* Number of bytes to read */ | 253 int nRead = bufSize; /* Number of bytes to read */ |
| 241 int nBlob; /* Total size of the blob */ | 254 int nBlob; /* Total size of the blob */ |
| 242 int rc; /* sqlite error code */ | 255 int rc; /* sqlite error code */ |
| 243 | 256 |
| 244 nBlob = sqlite3_blob_bytes(p->pBlob); | 257 nBlob = sqlite3_blob_bytes(p->pBlob); |
| 245 if( (p->iSeek+nRead)>nBlob ){ | 258 if( (p->iSeek+nRead)>nBlob ){ |
| 246 nRead = nBlob-p->iSeek; | 259 nRead = nBlob-p->iSeek; |
| 247 } | 260 } |
| 248 if( nRead<=0 ){ | 261 if( nRead<=0 ){ |
| 249 return 0; | 262 return 0; |
| 250 } | 263 } |
| 251 | 264 |
| 252 rc = sqlite3_blob_read(p->pBlob, (void *)buf, nRead, p->iSeek); | 265 rc = sqlite3_blob_read(p->pBlob, (void *)buf, nRead, p->iSeek); |
| 253 if( rc!=SQLITE_OK ){ | 266 if( rc!=SQLITE_OK ){ |
| 254 *errorCodePtr = rc; | 267 *errorCodePtr = rc; |
| 255 return -1; | 268 return -1; |
| 256 } | 269 } |
| 257 | 270 |
| 258 p->iSeek += nRead; | 271 p->iSeek += nRead; |
| 259 return nRead; | 272 return nRead; |
| 260 } | 273 } |
| 261 | 274 |
| 262 /* | 275 /* |
| 263 ** Write data to an incremental blob channel. | 276 ** Write data to an incremental blob channel. |
| 264 */ | 277 */ |
| 265 static int incrblobOutput( | 278 static int SQLITE_TCLAPI incrblobOutput( |
| 266 ClientData instanceData, | 279 ClientData instanceData, |
| 267 CONST char *buf, | 280 CONST char *buf, |
| 268 int toWrite, | 281 int toWrite, |
| 269 int *errorCodePtr | 282 int *errorCodePtr |
| 270 ){ | 283 ){ |
| 271 IncrblobChannel *p = (IncrblobChannel *)instanceData; | 284 IncrblobChannel *p = (IncrblobChannel *)instanceData; |
| 272 int nWrite = toWrite; /* Number of bytes to write */ | 285 int nWrite = toWrite; /* Number of bytes to write */ |
| 273 int nBlob; /* Total size of the blob */ | 286 int nBlob; /* Total size of the blob */ |
| 274 int rc; /* sqlite error code */ | 287 int rc; /* sqlite error code */ |
| 275 | 288 |
| 276 nBlob = sqlite3_blob_bytes(p->pBlob); | 289 nBlob = sqlite3_blob_bytes(p->pBlob); |
| 277 if( (p->iSeek+nWrite)>nBlob ){ | 290 if( (p->iSeek+nWrite)>nBlob ){ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 288 return -1; | 301 return -1; |
| 289 } | 302 } |
| 290 | 303 |
| 291 p->iSeek += nWrite; | 304 p->iSeek += nWrite; |
| 292 return nWrite; | 305 return nWrite; |
| 293 } | 306 } |
| 294 | 307 |
| 295 /* | 308 /* |
| 296 ** Seek an incremental blob channel. | 309 ** Seek an incremental blob channel. |
| 297 */ | 310 */ |
| 298 static int incrblobSeek( | 311 static int SQLITE_TCLAPI incrblobSeek( |
| 299 ClientData instanceData, | 312 ClientData instanceData, |
| 300 long offset, | 313 long offset, |
| 301 int seekMode, | 314 int seekMode, |
| 302 int *errorCodePtr | 315 int *errorCodePtr |
| 303 ){ | 316 ){ |
| 304 IncrblobChannel *p = (IncrblobChannel *)instanceData; | 317 IncrblobChannel *p = (IncrblobChannel *)instanceData; |
| 305 | 318 |
| 306 switch( seekMode ){ | 319 switch( seekMode ){ |
| 307 case SEEK_SET: | 320 case SEEK_SET: |
| 308 p->iSeek = offset; | 321 p->iSeek = offset; |
| 309 break; | 322 break; |
| 310 case SEEK_CUR: | 323 case SEEK_CUR: |
| 311 p->iSeek += offset; | 324 p->iSeek += offset; |
| 312 break; | 325 break; |
| 313 case SEEK_END: | 326 case SEEK_END: |
| 314 p->iSeek = sqlite3_blob_bytes(p->pBlob) + offset; | 327 p->iSeek = sqlite3_blob_bytes(p->pBlob) + offset; |
| 315 break; | 328 break; |
| 316 | 329 |
| 317 default: assert(!"Bad seekMode"); | 330 default: assert(!"Bad seekMode"); |
| 318 } | 331 } |
| 319 | 332 |
| 320 return p->iSeek; | 333 return p->iSeek; |
| 321 } | 334 } |
| 322 | 335 |
| 323 | 336 |
| 324 static void incrblobWatch(ClientData instanceData, int mode){ | 337 static void SQLITE_TCLAPI incrblobWatch( |
| 325 /* NO-OP */ | 338 ClientData instanceData, |
| 339 int mode |
| 340 ){ |
| 341 /* NO-OP */ |
| 326 } | 342 } |
| 327 static int incrblobHandle(ClientData instanceData, int dir, ClientData *hPtr){ | 343 static int SQLITE_TCLAPI incrblobHandle( |
| 344 ClientData instanceData, |
| 345 int dir, |
| 346 ClientData *hPtr |
| 347 ){ |
| 328 return TCL_ERROR; | 348 return TCL_ERROR; |
| 329 } | 349 } |
| 330 | 350 |
| 331 static Tcl_ChannelType IncrblobChannelType = { | 351 static Tcl_ChannelType IncrblobChannelType = { |
| 332 "incrblob", /* typeName */ | 352 "incrblob", /* typeName */ |
| 333 TCL_CHANNEL_VERSION_2, /* version */ | 353 TCL_CHANNEL_VERSION_2, /* version */ |
| 334 incrblobClose, /* closeProc */ | 354 incrblobClose, /* closeProc */ |
| 335 incrblobInput, /* inputProc */ | 355 incrblobInput, /* inputProc */ |
| 336 incrblobOutput, /* outputProc */ | 356 incrblobOutput, /* outputProc */ |
| 337 incrblobSeek, /* seekProc */ | 357 incrblobSeek, /* seekProc */ |
| 338 0, /* setOptionProc */ | 358 0, /* setOptionProc */ |
| 339 0, /* getOptionProc */ | 359 0, /* getOptionProc */ |
| 340 incrblobWatch, /* watchProc (this is a no-op) */ | 360 incrblobWatch, /* watchProc (this is a no-op) */ |
| 341 incrblobHandle, /* getHandleProc (always returns error) */ | 361 incrblobHandle, /* getHandleProc (always returns error) */ |
| 342 0, /* close2Proc */ | 362 0, /* close2Proc */ |
| 343 0, /* blockModeProc */ | 363 0, /* blockModeProc */ |
| 344 0, /* flushProc */ | 364 0, /* flushProc */ |
| 345 0, /* handlerProc */ | 365 0, /* handlerProc */ |
| 346 0, /* wideSeekProc */ | 366 0, /* wideSeekProc */ |
| 347 }; | 367 }; |
| 348 | 368 |
| 349 /* | 369 /* |
| 350 ** Create a new incrblob channel. | 370 ** Create a new incrblob channel. |
| 351 */ | 371 */ |
| 352 static int createIncrblobChannel( | 372 static int createIncrblobChannel( |
| 353 Tcl_Interp *interp, | 373 Tcl_Interp *interp, |
| 354 SqliteDb *pDb, | 374 SqliteDb *pDb, |
| 355 const char *zDb, | 375 const char *zDb, |
| 356 const char *zTable, | 376 const char *zTable, |
| 357 const char *zColumn, | 377 const char *zColumn, |
| 358 sqlite_int64 iRow, | 378 sqlite_int64 iRow, |
| 359 int isReadonly | 379 int isReadonly |
| 360 ){ | 380 ){ |
| 361 IncrblobChannel *p; | 381 IncrblobChannel *p; |
| 362 sqlite3 *db = pDb->db; | 382 sqlite3 *db = pDb->db; |
| 363 sqlite3_blob *pBlob; | 383 sqlite3_blob *pBlob; |
| 364 int rc; | 384 int rc; |
| 365 int flags = TCL_READABLE|(isReadonly ? 0 : TCL_WRITABLE); | 385 int flags = TCL_READABLE|(isReadonly ? 0 : TCL_WRITABLE); |
| 366 | 386 |
| 367 /* This variable is used to name the channels: "incrblob_[incr count]" */ | 387 /* This variable is used to name the channels: "incrblob_[incr count]" */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 ** Find an SqlFunc structure with the given name. Or create a new | 449 ** Find an SqlFunc structure with the given name. Or create a new |
| 430 ** one if an existing one cannot be found. Return a pointer to the | 450 ** one if an existing one cannot be found. Return a pointer to the |
| 431 ** structure. | 451 ** structure. |
| 432 */ | 452 */ |
| 433 static SqlFunc *findSqlFunc(SqliteDb *pDb, const char *zName){ | 453 static SqlFunc *findSqlFunc(SqliteDb *pDb, const char *zName){ |
| 434 SqlFunc *p, *pNew; | 454 SqlFunc *p, *pNew; |
| 435 int nName = strlen30(zName); | 455 int nName = strlen30(zName); |
| 436 pNew = (SqlFunc*)Tcl_Alloc( sizeof(*pNew) + nName + 1 ); | 456 pNew = (SqlFunc*)Tcl_Alloc( sizeof(*pNew) + nName + 1 ); |
| 437 pNew->zName = (char*)&pNew[1]; | 457 pNew->zName = (char*)&pNew[1]; |
| 438 memcpy(pNew->zName, zName, nName+1); | 458 memcpy(pNew->zName, zName, nName+1); |
| 439 for(p=pDb->pFunc; p; p=p->pNext){ | 459 for(p=pDb->pFunc; p; p=p->pNext){ |
| 440 if( sqlite3_stricmp(p->zName, pNew->zName)==0 ){ | 460 if( sqlite3_stricmp(p->zName, pNew->zName)==0 ){ |
| 441 Tcl_Free((char*)pNew); | 461 Tcl_Free((char*)pNew); |
| 442 return p; | 462 return p; |
| 443 } | 463 } |
| 444 } | 464 } |
| 445 pNew->interp = pDb->interp; | 465 pNew->interp = pDb->interp; |
| 446 pNew->pDb = pDb; | 466 pNew->pDb = pDb; |
| 447 pNew->pScript = 0; | 467 pNew->pScript = 0; |
| 448 pNew->pNext = pDb->pFunc; | 468 pNew->pNext = pDb->pFunc; |
| 449 pDb->pFunc = pNew; | 469 pDb->pFunc = pNew; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 476 } | 496 } |
| 477 pDb->nStmt = 0; | 497 pDb->nStmt = 0; |
| 478 pDb->stmtLast = 0; | 498 pDb->stmtLast = 0; |
| 479 pDb->stmtList = 0; | 499 pDb->stmtList = 0; |
| 480 } | 500 } |
| 481 | 501 |
| 482 /* | 502 /* |
| 483 ** TCL calls this procedure when an sqlite3 database command is | 503 ** TCL calls this procedure when an sqlite3 database command is |
| 484 ** deleted. | 504 ** deleted. |
| 485 */ | 505 */ |
| 486 static void DbDeleteCmd(void *db){ | 506 static void SQLITE_TCLAPI DbDeleteCmd(void *db){ |
| 487 SqliteDb *pDb = (SqliteDb*)db; | 507 SqliteDb *pDb = (SqliteDb*)db; |
| 488 flushStmtCache(pDb); | 508 flushStmtCache(pDb); |
| 489 closeIncrblobChannels(pDb); | 509 closeIncrblobChannels(pDb); |
| 490 sqlite3_close(pDb->db); | 510 sqlite3_close(pDb->db); |
| 491 while( pDb->pFunc ){ | 511 while( pDb->pFunc ){ |
| 492 SqlFunc *pFunc = pDb->pFunc; | 512 SqlFunc *pFunc = pDb->pFunc; |
| 493 pDb->pFunc = pFunc->pNext; | 513 pDb->pFunc = pFunc->pNext; |
| 494 assert( pFunc->pDb==pDb ); | 514 assert( pFunc->pDb==pDb ); |
| 495 Tcl_DecrRefCount(pFunc->pScript); | 515 Tcl_DecrRefCount(pFunc->pScript); |
| 496 Tcl_Free((char*)pFunc); | 516 Tcl_Free((char*)pFunc); |
| 497 } | 517 } |
| 498 while( pDb->pCollate ){ | 518 while( pDb->pCollate ){ |
| 499 SqlCollate *pCollate = pDb->pCollate; | 519 SqlCollate *pCollate = pDb->pCollate; |
| 500 pDb->pCollate = pCollate->pNext; | 520 pDb->pCollate = pCollate->pNext; |
| 501 Tcl_Free((char*)pCollate); | 521 Tcl_Free((char*)pCollate); |
| 502 } | 522 } |
| 503 if( pDb->zBusy ){ | 523 if( pDb->zBusy ){ |
| 504 Tcl_Free(pDb->zBusy); | 524 Tcl_Free(pDb->zBusy); |
| 505 } | 525 } |
| 506 if( pDb->zTrace ){ | 526 if( pDb->zTrace ){ |
| 507 Tcl_Free(pDb->zTrace); | 527 Tcl_Free(pDb->zTrace); |
| 508 } | 528 } |
| 529 if( pDb->zTraceV2 ){ |
| 530 Tcl_Free(pDb->zTraceV2); |
| 531 } |
| 509 if( pDb->zProfile ){ | 532 if( pDb->zProfile ){ |
| 510 Tcl_Free(pDb->zProfile); | 533 Tcl_Free(pDb->zProfile); |
| 511 } | 534 } |
| 512 if( pDb->zAuth ){ | 535 if( pDb->zAuth ){ |
| 513 Tcl_Free(pDb->zAuth); | 536 Tcl_Free(pDb->zAuth); |
| 514 } | 537 } |
| 515 if( pDb->zNull ){ | 538 if( pDb->zNull ){ |
| 516 Tcl_Free(pDb->zNull); | 539 Tcl_Free(pDb->zNull); |
| 517 } | 540 } |
| 518 if( pDb->pUpdateHook ){ | 541 if( pDb->pUpdateHook ){ |
| 519 Tcl_DecrRefCount(pDb->pUpdateHook); | 542 Tcl_DecrRefCount(pDb->pUpdateHook); |
| 520 } | 543 } |
| 544 if( pDb->pPreUpdateHook ){ |
| 545 Tcl_DecrRefCount(pDb->pPreUpdateHook); |
| 546 } |
| 521 if( pDb->pRollbackHook ){ | 547 if( pDb->pRollbackHook ){ |
| 522 Tcl_DecrRefCount(pDb->pRollbackHook); | 548 Tcl_DecrRefCount(pDb->pRollbackHook); |
| 523 } | 549 } |
| 524 if( pDb->pWalHook ){ | 550 if( pDb->pWalHook ){ |
| 525 Tcl_DecrRefCount(pDb->pWalHook); | 551 Tcl_DecrRefCount(pDb->pWalHook); |
| 526 } | 552 } |
| 527 if( pDb->pCollateNeeded ){ | 553 if( pDb->pCollateNeeded ){ |
| 528 Tcl_DecrRefCount(pDb->pCollateNeeded); | 554 Tcl_DecrRefCount(pDb->pCollateNeeded); |
| 529 } | 555 } |
| 530 Tcl_Free((char*)pDb); | 556 Tcl_Free((char*)pDb); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 557 | 583 |
| 558 assert( pDb->zProgress ); | 584 assert( pDb->zProgress ); |
| 559 rc = Tcl_Eval(pDb->interp, pDb->zProgress); | 585 rc = Tcl_Eval(pDb->interp, pDb->zProgress); |
| 560 if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){ | 586 if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){ |
| 561 return 1; | 587 return 1; |
| 562 } | 588 } |
| 563 return 0; | 589 return 0; |
| 564 } | 590 } |
| 565 #endif | 591 #endif |
| 566 | 592 |
| 567 #ifndef SQLITE_OMIT_TRACE | 593 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ |
| 594 !defined(SQLITE_OMIT_DEPRECATED) |
| 568 /* | 595 /* |
| 569 ** This routine is called by the SQLite trace handler whenever a new | 596 ** This routine is called by the SQLite trace handler whenever a new |
| 570 ** block of SQL is executed. The TCL script in pDb->zTrace is executed. | 597 ** block of SQL is executed. The TCL script in pDb->zTrace is executed. |
| 571 */ | 598 */ |
| 572 static void DbTraceHandler(void *cd, const char *zSql){ | 599 static void DbTraceHandler(void *cd, const char *zSql){ |
| 573 SqliteDb *pDb = (SqliteDb*)cd; | 600 SqliteDb *pDb = (SqliteDb*)cd; |
| 574 Tcl_DString str; | 601 Tcl_DString str; |
| 575 | 602 |
| 576 Tcl_DStringInit(&str); | 603 Tcl_DStringInit(&str); |
| 577 Tcl_DStringAppend(&str, pDb->zTrace, -1); | 604 Tcl_DStringAppend(&str, pDb->zTrace, -1); |
| 578 Tcl_DStringAppendElement(&str, zSql); | 605 Tcl_DStringAppendElement(&str, zSql); |
| 579 Tcl_Eval(pDb->interp, Tcl_DStringValue(&str)); | 606 Tcl_Eval(pDb->interp, Tcl_DStringValue(&str)); |
| 580 Tcl_DStringFree(&str); | 607 Tcl_DStringFree(&str); |
| 581 Tcl_ResetResult(pDb->interp); | 608 Tcl_ResetResult(pDb->interp); |
| 582 } | 609 } |
| 583 #endif | 610 #endif |
| 584 | 611 |
| 585 #ifndef SQLITE_OMIT_TRACE | 612 #ifndef SQLITE_OMIT_TRACE |
| 586 /* | 613 /* |
| 614 ** This routine is called by the SQLite trace_v2 handler whenever a new |
| 615 ** supported event is generated. Unsupported event types are ignored. |
| 616 ** The TCL script in pDb->zTraceV2 is executed, with the arguments for |
| 617 ** the event appended to it (as list elements). |
| 618 */ |
| 619 static int DbTraceV2Handler( |
| 620 unsigned type, /* One of the SQLITE_TRACE_* event types. */ |
| 621 void *cd, /* The original context data pointer. */ |
| 622 void *pd, /* Primary event data, depends on event type. */ |
| 623 void *xd /* Extra event data, depends on event type. */ |
| 624 ){ |
| 625 SqliteDb *pDb = (SqliteDb*)cd; |
| 626 Tcl_Obj *pCmd; |
| 627 |
| 628 switch( type ){ |
| 629 case SQLITE_TRACE_STMT: { |
| 630 sqlite3_stmt *pStmt = (sqlite3_stmt *)pd; |
| 631 char *zSql = (char *)xd; |
| 632 |
| 633 pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1); |
| 634 Tcl_IncrRefCount(pCmd); |
| 635 Tcl_ListObjAppendElement(pDb->interp, pCmd, |
| 636 Tcl_NewWideIntObj((Tcl_WideInt)pStmt)); |
| 637 Tcl_ListObjAppendElement(pDb->interp, pCmd, |
| 638 Tcl_NewStringObj(zSql, -1)); |
| 639 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); |
| 640 Tcl_DecrRefCount(pCmd); |
| 641 Tcl_ResetResult(pDb->interp); |
| 642 break; |
| 643 } |
| 644 case SQLITE_TRACE_PROFILE: { |
| 645 sqlite3_stmt *pStmt = (sqlite3_stmt *)pd; |
| 646 sqlite3_int64 ns = (sqlite3_int64)xd; |
| 647 |
| 648 pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1); |
| 649 Tcl_IncrRefCount(pCmd); |
| 650 Tcl_ListObjAppendElement(pDb->interp, pCmd, |
| 651 Tcl_NewWideIntObj((Tcl_WideInt)pStmt)); |
| 652 Tcl_ListObjAppendElement(pDb->interp, pCmd, |
| 653 Tcl_NewWideIntObj((Tcl_WideInt)ns)); |
| 654 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); |
| 655 Tcl_DecrRefCount(pCmd); |
| 656 Tcl_ResetResult(pDb->interp); |
| 657 break; |
| 658 } |
| 659 case SQLITE_TRACE_ROW: { |
| 660 sqlite3_stmt *pStmt = (sqlite3_stmt *)pd; |
| 661 |
| 662 pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1); |
| 663 Tcl_IncrRefCount(pCmd); |
| 664 Tcl_ListObjAppendElement(pDb->interp, pCmd, |
| 665 Tcl_NewWideIntObj((Tcl_WideInt)pStmt)); |
| 666 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); |
| 667 Tcl_DecrRefCount(pCmd); |
| 668 Tcl_ResetResult(pDb->interp); |
| 669 break; |
| 670 } |
| 671 case SQLITE_TRACE_CLOSE: { |
| 672 sqlite3 *db = (sqlite3 *)pd; |
| 673 |
| 674 pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1); |
| 675 Tcl_IncrRefCount(pCmd); |
| 676 Tcl_ListObjAppendElement(pDb->interp, pCmd, |
| 677 Tcl_NewWideIntObj((Tcl_WideInt)db)); |
| 678 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); |
| 679 Tcl_DecrRefCount(pCmd); |
| 680 Tcl_ResetResult(pDb->interp); |
| 681 break; |
| 682 } |
| 683 } |
| 684 return SQLITE_OK; |
| 685 } |
| 686 #endif |
| 687 |
| 688 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ |
| 689 !defined(SQLITE_OMIT_DEPRECATED) |
| 690 /* |
| 587 ** This routine is called by the SQLite profile handler after a statement | 691 ** This routine is called by the SQLite profile handler after a statement |
| 588 ** SQL has executed. The TCL script in pDb->zProfile is evaluated. | 692 ** SQL has executed. The TCL script in pDb->zProfile is evaluated. |
| 589 */ | 693 */ |
| 590 static void DbProfileHandler(void *cd, const char *zSql, sqlite_uint64 tm){ | 694 static void DbProfileHandler(void *cd, const char *zSql, sqlite_uint64 tm){ |
| 591 SqliteDb *pDb = (SqliteDb*)cd; | 695 SqliteDb *pDb = (SqliteDb*)cd; |
| 592 Tcl_DString str; | 696 Tcl_DString str; |
| 593 char zTm[100]; | 697 char zTm[100]; |
| 594 | 698 |
| 595 sqlite3_snprintf(sizeof(zTm)-1, zTm, "%lld", tm); | 699 sqlite3_snprintf(sizeof(zTm)-1, zTm, "%lld", tm); |
| 596 Tcl_DStringInit(&str); | 700 Tcl_DStringInit(&str); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 625 assert(pDb->pRollbackHook); | 729 assert(pDb->pRollbackHook); |
| 626 if( TCL_OK!=Tcl_EvalObjEx(pDb->interp, pDb->pRollbackHook, 0) ){ | 730 if( TCL_OK!=Tcl_EvalObjEx(pDb->interp, pDb->pRollbackHook, 0) ){ |
| 627 Tcl_BackgroundError(pDb->interp); | 731 Tcl_BackgroundError(pDb->interp); |
| 628 } | 732 } |
| 629 } | 733 } |
| 630 | 734 |
| 631 /* | 735 /* |
| 632 ** This procedure handles wal_hook callbacks. | 736 ** This procedure handles wal_hook callbacks. |
| 633 */ | 737 */ |
| 634 static int DbWalHandler( | 738 static int DbWalHandler( |
| 635 void *clientData, | 739 void *clientData, |
| 636 sqlite3 *db, | 740 sqlite3 *db, |
| 637 const char *zDb, | 741 const char *zDb, |
| 638 int nEntry | 742 int nEntry |
| 639 ){ | 743 ){ |
| 640 int ret = SQLITE_OK; | 744 int ret = SQLITE_OK; |
| 641 Tcl_Obj *p; | 745 Tcl_Obj *p; |
| 642 SqliteDb *pDb = (SqliteDb*)clientData; | 746 SqliteDb *pDb = (SqliteDb*)clientData; |
| 643 Tcl_Interp *interp = pDb->interp; | 747 Tcl_Interp *interp = pDb->interp; |
| 644 assert(pDb->pWalHook); | 748 assert(pDb->pWalHook); |
| 645 | 749 |
| 646 assert( db==pDb->db ); | 750 assert( db==pDb->db ); |
| 647 p = Tcl_DuplicateObj(pDb->pWalHook); | 751 p = Tcl_DuplicateObj(pDb->pWalHook); |
| 648 Tcl_IncrRefCount(p); | 752 Tcl_IncrRefCount(p); |
| 649 Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1)); | 753 Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1)); |
| 650 Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry)); | 754 Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry)); |
| 651 if( TCL_OK!=Tcl_EvalObjEx(interp, p, 0) | 755 if( TCL_OK!=Tcl_EvalObjEx(interp, p, 0) |
| 652 || TCL_OK!=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &ret) | 756 || TCL_OK!=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &ret) |
| 653 ){ | 757 ){ |
| 654 Tcl_BackgroundError(interp); | 758 Tcl_BackgroundError(interp); |
| 655 } | 759 } |
| 656 Tcl_DecrRefCount(p); | 760 Tcl_DecrRefCount(p); |
| 657 | 761 |
| 658 return ret; | 762 return ret; |
| 659 } | 763 } |
| 660 | 764 |
| 661 #if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY) | 765 #if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 678 SqliteDb *pDb = (SqliteDb *)apArg[i]; | 782 SqliteDb *pDb = (SqliteDb *)apArg[i]; |
| 679 setTestUnlockNotifyVars(pDb->interp, i, nArg); | 783 setTestUnlockNotifyVars(pDb->interp, i, nArg); |
| 680 assert( pDb->pUnlockNotify); | 784 assert( pDb->pUnlockNotify); |
| 681 Tcl_EvalObjEx(pDb->interp, pDb->pUnlockNotify, flags); | 785 Tcl_EvalObjEx(pDb->interp, pDb->pUnlockNotify, flags); |
| 682 Tcl_DecrRefCount(pDb->pUnlockNotify); | 786 Tcl_DecrRefCount(pDb->pUnlockNotify); |
| 683 pDb->pUnlockNotify = 0; | 787 pDb->pUnlockNotify = 0; |
| 684 } | 788 } |
| 685 } | 789 } |
| 686 #endif | 790 #endif |
| 687 | 791 |
| 792 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 793 /* |
| 794 ** Pre-update hook callback. |
| 795 */ |
| 796 static void DbPreUpdateHandler( |
| 797 void *p, |
| 798 sqlite3 *db, |
| 799 int op, |
| 800 const char *zDb, |
| 801 const char *zTbl, |
| 802 sqlite_int64 iKey1, |
| 803 sqlite_int64 iKey2 |
| 804 ){ |
| 805 SqliteDb *pDb = (SqliteDb *)p; |
| 806 Tcl_Obj *pCmd; |
| 807 static const char *azStr[] = {"DELETE", "INSERT", "UPDATE"}; |
| 808 |
| 809 assert( (SQLITE_DELETE-1)/9 == 0 ); |
| 810 assert( (SQLITE_INSERT-1)/9 == 1 ); |
| 811 assert( (SQLITE_UPDATE-1)/9 == 2 ); |
| 812 assert( pDb->pPreUpdateHook ); |
| 813 assert( db==pDb->db ); |
| 814 assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE ); |
| 815 |
| 816 pCmd = Tcl_DuplicateObj(pDb->pPreUpdateHook); |
| 817 Tcl_IncrRefCount(pCmd); |
| 818 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(azStr[(op-1)/9], -1)); |
| 819 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1)); |
| 820 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1)); |
| 821 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(iKey1)); |
| 822 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(iKey2)); |
| 823 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); |
| 824 Tcl_DecrRefCount(pCmd); |
| 825 } |
| 826 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 827 |
| 688 static void DbUpdateHandler( | 828 static void DbUpdateHandler( |
| 689 void *p, | 829 void *p, |
| 690 int op, | 830 int op, |
| 691 const char *zDb, | 831 const char *zDb, |
| 692 const char *zTbl, | 832 const char *zTbl, |
| 693 sqlite_int64 rowid | 833 sqlite_int64 rowid |
| 694 ){ | 834 ){ |
| 695 SqliteDb *pDb = (SqliteDb *)p; | 835 SqliteDb *pDb = (SqliteDb *)p; |
| 696 Tcl_Obj *pCmd; | 836 Tcl_Obj *pCmd; |
| 837 static const char *azStr[] = {"DELETE", "INSERT", "UPDATE"}; |
| 838 |
| 839 assert( (SQLITE_DELETE-1)/9 == 0 ); |
| 840 assert( (SQLITE_INSERT-1)/9 == 1 ); |
| 841 assert( (SQLITE_UPDATE-1)/9 == 2 ); |
| 697 | 842 |
| 698 assert( pDb->pUpdateHook ); | 843 assert( pDb->pUpdateHook ); |
| 699 assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE ); | 844 assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE ); |
| 700 | 845 |
| 701 pCmd = Tcl_DuplicateObj(pDb->pUpdateHook); | 846 pCmd = Tcl_DuplicateObj(pDb->pUpdateHook); |
| 702 Tcl_IncrRefCount(pCmd); | 847 Tcl_IncrRefCount(pCmd); |
| 703 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj( | 848 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(azStr[(op-1)/9], -1)); |
| 704 ( (op==SQLITE_INSERT)?"INSERT":(op==SQLITE_UPDATE)?"UPDATE":"DELETE"), -1)); | |
| 705 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1)); | 849 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zDb, -1)); |
| 706 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1)); | 850 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewStringObj(zTbl, -1)); |
| 707 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(rowid)); | 851 Tcl_ListObjAppendElement(0, pCmd, Tcl_NewWideIntObj(rowid)); |
| 708 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); | 852 Tcl_EvalObjEx(pDb->interp, pCmd, TCL_EVAL_DIRECT); |
| 709 Tcl_DecrRefCount(pCmd); | 853 Tcl_DecrRefCount(pCmd); |
| 710 } | 854 } |
| 711 | 855 |
| 712 static void tclCollateNeeded( | 856 static void tclCollateNeeded( |
| 713 void *pCtx, | 857 void *pCtx, |
| 714 sqlite3 *db, | 858 sqlite3 *db, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 ** subsequent invocations much faster. */ | 907 ** subsequent invocations much faster. */ |
| 764 pCmd = p->pScript; | 908 pCmd = p->pScript; |
| 765 Tcl_IncrRefCount(pCmd); | 909 Tcl_IncrRefCount(pCmd); |
| 766 rc = Tcl_EvalObjEx(p->interp, pCmd, 0); | 910 rc = Tcl_EvalObjEx(p->interp, pCmd, 0); |
| 767 Tcl_DecrRefCount(pCmd); | 911 Tcl_DecrRefCount(pCmd); |
| 768 }else{ | 912 }else{ |
| 769 /* If there are arguments to the function, make a shallow copy of the | 913 /* If there are arguments to the function, make a shallow copy of the |
| 770 ** script object, lappend the arguments, then evaluate the copy. | 914 ** script object, lappend the arguments, then evaluate the copy. |
| 771 ** | 915 ** |
| 772 ** By "shallow" copy, we mean only the outer list Tcl_Obj is duplicated. | 916 ** By "shallow" copy, we mean only the outer list Tcl_Obj is duplicated. |
| 773 ** The new Tcl_Obj contains pointers to the original list elements. | 917 ** The new Tcl_Obj contains pointers to the original list elements. |
| 774 ** That way, when Tcl_EvalObjv() is run and shimmers the first element | 918 ** That way, when Tcl_EvalObjv() is run and shimmers the first element |
| 775 ** of the list to tclCmdNameType, that alternate representation will | 919 ** of the list to tclCmdNameType, that alternate representation will |
| 776 ** be preserved and reused on the next invocation. | 920 ** be preserved and reused on the next invocation. |
| 777 */ | 921 */ |
| 778 Tcl_Obj **aArg; | 922 Tcl_Obj **aArg; |
| 779 int nArg; | 923 int nArg; |
| 780 if( Tcl_ListObjGetElements(p->interp, p->pScript, &nArg, &aArg) ){ | 924 if( Tcl_ListObjGetElements(p->interp, p->pScript, &nArg, &aArg) ){ |
| 781 sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); | 925 sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); |
| 782 return; | 926 return; |
| 783 } | 927 } |
| 784 pCmd = Tcl_NewListObj(nArg, aArg); | 928 pCmd = Tcl_NewListObj(nArg, aArg); |
| 785 Tcl_IncrRefCount(pCmd); | 929 Tcl_IncrRefCount(pCmd); |
| 786 for(i=0; i<argc; i++){ | 930 for(i=0; i<argc; i++){ |
| 787 sqlite3_value *pIn = argv[i]; | 931 sqlite3_value *pIn = argv[i]; |
| 788 Tcl_Obj *pVal; | 932 Tcl_Obj *pVal; |
| 789 | 933 |
| 790 /* Set pVal to contain the i'th column of this row. */ | 934 /* Set pVal to contain the i'th column of this row. */ |
| 791 switch( sqlite3_value_type(pIn) ){ | 935 switch( sqlite3_value_type(pIn) ){ |
| 792 case SQLITE_BLOB: { | 936 case SQLITE_BLOB: { |
| 793 int bytes = sqlite3_value_bytes(pIn); | 937 int bytes = sqlite3_value_bytes(pIn); |
| 794 pVal = Tcl_NewByteArrayObj(sqlite3_value_blob(pIn), bytes); | 938 pVal = Tcl_NewByteArrayObj(sqlite3_value_blob(pIn), bytes); |
| 795 break; | 939 break; |
| 796 } | 940 } |
| 797 case SQLITE_INTEGER: { | 941 case SQLITE_INTEGER: { |
| 798 sqlite_int64 v = sqlite3_value_int64(pIn); | 942 sqlite_int64 v = sqlite3_value_int64(pIn); |
| 799 if( v>=-2147483647 && v<=2147483647 ){ | 943 if( v>=-2147483647 && v<=2147483647 ){ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 814 } | 958 } |
| 815 default: { | 959 default: { |
| 816 int bytes = sqlite3_value_bytes(pIn); | 960 int bytes = sqlite3_value_bytes(pIn); |
| 817 pVal = Tcl_NewStringObj((char *)sqlite3_value_text(pIn), bytes); | 961 pVal = Tcl_NewStringObj((char *)sqlite3_value_text(pIn), bytes); |
| 818 break; | 962 break; |
| 819 } | 963 } |
| 820 } | 964 } |
| 821 rc = Tcl_ListObjAppendElement(p->interp, pCmd, pVal); | 965 rc = Tcl_ListObjAppendElement(p->interp, pCmd, pVal); |
| 822 if( rc ){ | 966 if( rc ){ |
| 823 Tcl_DecrRefCount(pCmd); | 967 Tcl_DecrRefCount(pCmd); |
| 824 sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); | 968 sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); |
| 825 return; | 969 return; |
| 826 } | 970 } |
| 827 } | 971 } |
| 828 if( !p->useEvalObjv ){ | 972 if( !p->useEvalObjv ){ |
| 829 /* Tcl_EvalObjEx() will automatically call Tcl_EvalObjv() if pCmd | 973 /* Tcl_EvalObjEx() will automatically call Tcl_EvalObjv() if pCmd |
| 830 ** is a list without a string representation. To prevent this from | 974 ** is a list without a string representation. To prevent this from |
| 831 ** happening, make sure pCmd has a valid string representation */ | 975 ** happening, make sure pCmd has a valid string representation */ |
| 832 Tcl_GetString(pCmd); | 976 Tcl_GetString(pCmd); |
| 833 } | 977 } |
| 834 rc = Tcl_EvalObjEx(p->interp, pCmd, TCL_EVAL_DIRECT); | 978 rc = Tcl_EvalObjEx(p->interp, pCmd, TCL_EVAL_DIRECT); |
| 835 Tcl_DecrRefCount(pCmd); | 979 Tcl_DecrRefCount(pCmd); |
| 836 } | 980 } |
| 837 | 981 |
| 838 if( rc && rc!=TCL_RETURN ){ | 982 if( rc && rc!=TCL_RETURN ){ |
| 839 sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); | 983 sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); |
| 840 }else{ | 984 }else{ |
| 841 Tcl_Obj *pVar = Tcl_GetObjResult(p->interp); | 985 Tcl_Obj *pVar = Tcl_GetObjResult(p->interp); |
| 842 int n; | 986 int n; |
| 843 u8 *data; | 987 u8 *data; |
| 844 const char *zType = (pVar->typePtr ? pVar->typePtr->name : ""); | 988 const char *zType = (pVar->typePtr ? pVar->typePtr->name : ""); |
| 845 char c = zType[0]; | 989 char c = zType[0]; |
| 846 if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){ | 990 if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){ |
| 847 /* Only return a BLOB type if the Tcl variable is a bytearray and | 991 /* Only return a BLOB type if the Tcl variable is a bytearray and |
| 848 ** has no string representation. */ | 992 ** has no string representation. */ |
| 849 data = Tcl_GetByteArrayFromObj(pVar, &n); | 993 data = Tcl_GetByteArrayFromObj(pVar, &n); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 } | 1075 } |
| 932 Tcl_DStringInit(&str); | 1076 Tcl_DStringInit(&str); |
| 933 Tcl_DStringAppend(&str, pDb->zAuth, -1); | 1077 Tcl_DStringAppend(&str, pDb->zAuth, -1); |
| 934 Tcl_DStringAppendElement(&str, zCode); | 1078 Tcl_DStringAppendElement(&str, zCode); |
| 935 Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : ""); | 1079 Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : ""); |
| 936 Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : ""); | 1080 Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : ""); |
| 937 Tcl_DStringAppendElement(&str, zArg3 ? zArg3 : ""); | 1081 Tcl_DStringAppendElement(&str, zArg3 ? zArg3 : ""); |
| 938 Tcl_DStringAppendElement(&str, zArg4 ? zArg4 : ""); | 1082 Tcl_DStringAppendElement(&str, zArg4 ? zArg4 : ""); |
| 939 #ifdef SQLITE_USER_AUTHENTICATION | 1083 #ifdef SQLITE_USER_AUTHENTICATION |
| 940 Tcl_DStringAppendElement(&str, zArg5 ? zArg5 : ""); | 1084 Tcl_DStringAppendElement(&str, zArg5 ? zArg5 : ""); |
| 941 #endif | 1085 #endif |
| 942 rc = Tcl_GlobalEval(pDb->interp, Tcl_DStringValue(&str)); | 1086 rc = Tcl_GlobalEval(pDb->interp, Tcl_DStringValue(&str)); |
| 943 Tcl_DStringFree(&str); | 1087 Tcl_DStringFree(&str); |
| 944 zReply = rc==TCL_OK ? Tcl_GetStringResult(pDb->interp) : "SQLITE_DENY"; | 1088 zReply = rc==TCL_OK ? Tcl_GetStringResult(pDb->interp) : "SQLITE_DENY"; |
| 945 if( strcmp(zReply,"SQLITE_OK")==0 ){ | 1089 if( strcmp(zReply,"SQLITE_OK")==0 ){ |
| 946 rc = SQLITE_OK; | 1090 rc = SQLITE_OK; |
| 947 }else if( strcmp(zReply,"SQLITE_DENY")==0 ){ | 1091 }else if( strcmp(zReply,"SQLITE_DENY")==0 ){ |
| 948 rc = SQLITE_DENY; | 1092 rc = SQLITE_DENY; |
| 949 }else if( strcmp(zReply,"SQLITE_IGNORE")==0 ){ | 1093 }else if( strcmp(zReply,"SQLITE_IGNORE")==0 ){ |
| 950 rc = SQLITE_IGNORE; | 1094 rc = SQLITE_IGNORE; |
| 951 }else{ | 1095 }else{ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 | 1146 |
| 1003 | 1147 |
| 1004 /* | 1148 /* |
| 1005 ** This function is part of the implementation of the command: | 1149 ** This function is part of the implementation of the command: |
| 1006 ** | 1150 ** |
| 1007 ** $db transaction [-deferred|-immediate|-exclusive] SCRIPT | 1151 ** $db transaction [-deferred|-immediate|-exclusive] SCRIPT |
| 1008 ** | 1152 ** |
| 1009 ** It is invoked after evaluating the script SCRIPT to commit or rollback | 1153 ** It is invoked after evaluating the script SCRIPT to commit or rollback |
| 1010 ** the transaction or savepoint opened by the [transaction] command. | 1154 ** the transaction or savepoint opened by the [transaction] command. |
| 1011 */ | 1155 */ |
| 1012 static int DbTransPostCmd( | 1156 static int SQLITE_TCLAPI DbTransPostCmd( |
| 1013 ClientData data[], /* data[0] is the Sqlite3Db* for $db */ | 1157 ClientData data[], /* data[0] is the Sqlite3Db* for $db */ |
| 1014 Tcl_Interp *interp, /* Tcl interpreter */ | 1158 Tcl_Interp *interp, /* Tcl interpreter */ |
| 1015 int result /* Result of evaluating SCRIPT */ | 1159 int result /* Result of evaluating SCRIPT */ |
| 1016 ){ | 1160 ){ |
| 1017 static const char *const azEnd[] = { | 1161 static const char *const azEnd[] = { |
| 1018 "RELEASE _tcl_transaction", /* rc==TCL_ERROR, nTransaction!=0 */ | 1162 "RELEASE _tcl_transaction", /* rc==TCL_ERROR, nTransaction!=0 */ |
| 1019 "COMMIT", /* rc!=TCL_ERROR, nTransaction==0 */ | 1163 "COMMIT", /* rc!=TCL_ERROR, nTransaction==0 */ |
| 1020 "ROLLBACK TO _tcl_transaction ; RELEASE _tcl_transaction", | 1164 "ROLLBACK TO _tcl_transaction ; RELEASE _tcl_transaction", |
| 1021 "ROLLBACK" /* rc==TCL_ERROR, nTransaction==0 */ | 1165 "ROLLBACK" /* rc==TCL_ERROR, nTransaction==0 */ |
| 1022 }; | 1166 }; |
| 1023 SqliteDb *pDb = (SqliteDb*)data[0]; | 1167 SqliteDb *pDb = (SqliteDb*)data[0]; |
| 1024 int rc = result; | 1168 int rc = result; |
| 1025 const char *zEnd; | 1169 const char *zEnd; |
| 1026 | 1170 |
| 1027 pDb->nTransaction--; | 1171 pDb->nTransaction--; |
| 1028 zEnd = azEnd[(rc==TCL_ERROR)*2 + (pDb->nTransaction==0)]; | 1172 zEnd = azEnd[(rc==TCL_ERROR)*2 + (pDb->nTransaction==0)]; |
| 1029 | 1173 |
| 1030 pDb->disableAuth++; | 1174 pDb->disableAuth++; |
| 1031 if( sqlite3_exec(pDb->db, zEnd, 0, 0, 0) ){ | 1175 if( sqlite3_exec(pDb->db, zEnd, 0, 0, 0) ){ |
| 1032 /* This is a tricky scenario to handle. The most likely cause of an | 1176 /* This is a tricky scenario to handle. The most likely cause of an |
| 1033 ** error is that the exec() above was an attempt to commit the | 1177 ** error is that the exec() above was an attempt to commit the |
| 1034 ** top-level transaction that returned SQLITE_BUSY. Or, less likely, | 1178 ** top-level transaction that returned SQLITE_BUSY. Or, less likely, |
| 1035 ** that an IO-error has occurred. In either case, throw a Tcl exception | 1179 ** that an IO-error has occurred. In either case, throw a Tcl exception |
| 1036 ** and try to rollback the transaction. | 1180 ** and try to rollback the transaction. |
| 1037 ** | 1181 ** |
| 1038 ** But it could also be that the user executed one or more BEGIN, | 1182 ** But it could also be that the user executed one or more BEGIN, |
| 1039 ** COMMIT, SAVEPOINT, RELEASE or ROLLBACK commands that are confusing | 1183 ** COMMIT, SAVEPOINT, RELEASE or ROLLBACK commands that are confusing |
| 1040 ** this method's logic. Not clear how this would be best handled. | 1184 ** this method's logic. Not clear how this would be best handled. |
| 1041 */ | 1185 */ |
| 1042 if( rc!=TCL_ERROR ){ | 1186 if( rc!=TCL_ERROR ){ |
| 1043 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); | 1187 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); |
| 1044 rc = TCL_ERROR; | 1188 rc = TCL_ERROR; |
| 1045 } | 1189 } |
| 1046 sqlite3_exec(pDb->db, "ROLLBACK", 0, 0, 0); | 1190 sqlite3_exec(pDb->db, "ROLLBACK", 0, 0, 0); |
| 1047 } | 1191 } |
| 1048 pDb->disableAuth--; | 1192 pDb->disableAuth--; |
| 1049 | 1193 |
| 1050 return rc; | 1194 return rc; |
| 1051 } | 1195 } |
| 1052 | 1196 |
| 1053 /* | 1197 /* |
| 1054 ** Unless SQLITE_TEST is defined, this function is a simple wrapper around | 1198 ** Unless SQLITE_TEST is defined, this function is a simple wrapper around |
| 1055 ** sqlite3_prepare_v2(). If SQLITE_TEST is defined, then it uses either | 1199 ** sqlite3_prepare_v2(). If SQLITE_TEST is defined, then it uses either |
| 1056 ** sqlite3_prepare_v2() or legacy interface sqlite3_prepare(), depending | 1200 ** sqlite3_prepare_v2() or legacy interface sqlite3_prepare(), depending |
| 1057 ** on whether or not the [db_use_legacy_prepare] command has been used to | 1201 ** on whether or not the [db_use_legacy_prepare] command has been used to |
| 1058 ** configure the connection. | 1202 ** configure the connection. |
| 1059 */ | 1203 */ |
| 1060 static int dbPrepare( | 1204 static int dbPrepare( |
| 1061 SqliteDb *pDb, /* Database object */ | 1205 SqliteDb *pDb, /* Database object */ |
| 1062 const char *zSql, /* SQL to compile */ | 1206 const char *zSql, /* SQL to compile */ |
| 1063 sqlite3_stmt **ppStmt, /* OUT: Prepared statement */ | 1207 sqlite3_stmt **ppStmt, /* OUT: Prepared statement */ |
| 1064 const char **pzOut /* OUT: Pointer to next SQL statement */ | 1208 const char **pzOut /* OUT: Pointer to next SQL statement */ |
| 1065 ){ | 1209 ){ |
| 1066 #ifdef SQLITE_TEST | 1210 #ifdef SQLITE_TEST |
| 1067 if( pDb->bLegacyPrepare ){ | 1211 if( pDb->bLegacyPrepare ){ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 Tcl_Interp *interp = pDb->interp; | 1247 Tcl_Interp *interp = pDb->interp; |
| 1104 | 1248 |
| 1105 *ppPreStmt = 0; | 1249 *ppPreStmt = 0; |
| 1106 | 1250 |
| 1107 /* Trim spaces from the start of zSql and calculate the remaining length. */ | 1251 /* Trim spaces from the start of zSql and calculate the remaining length. */ |
| 1108 while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; } | 1252 while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; } |
| 1109 nSql = strlen30(zSql); | 1253 nSql = strlen30(zSql); |
| 1110 | 1254 |
| 1111 for(pPreStmt = pDb->stmtList; pPreStmt; pPreStmt=pPreStmt->pNext){ | 1255 for(pPreStmt = pDb->stmtList; pPreStmt; pPreStmt=pPreStmt->pNext){ |
| 1112 int n = pPreStmt->nSql; | 1256 int n = pPreStmt->nSql; |
| 1113 if( nSql>=n | 1257 if( nSql>=n |
| 1114 && memcmp(pPreStmt->zSql, zSql, n)==0 | 1258 && memcmp(pPreStmt->zSql, zSql, n)==0 |
| 1115 && (zSql[n]==0 || zSql[n-1]==';') | 1259 && (zSql[n]==0 || zSql[n-1]==';') |
| 1116 ){ | 1260 ){ |
| 1117 pStmt = pPreStmt->pStmt; | 1261 pStmt = pPreStmt->pStmt; |
| 1118 *pzOut = &zSql[pPreStmt->nSql]; | 1262 *pzOut = &zSql[pPreStmt->nSql]; |
| 1119 | 1263 |
| 1120 /* When a prepared statement is found, unlink it from the | 1264 /* When a prepared statement is found, unlink it from the |
| 1121 ** cache list. It will later be added back to the beginning | 1265 ** cache list. It will later be added back to the beginning |
| 1122 ** of the cache list in order to implement LRU replacement. | 1266 ** of the cache list in order to implement LRU replacement. |
| 1123 */ | 1267 */ |
| 1124 if( pPreStmt->pPrev ){ | 1268 if( pPreStmt->pPrev ){ |
| 1125 pPreStmt->pPrev->pNext = pPreStmt->pNext; | 1269 pPreStmt->pPrev->pNext = pPreStmt->pNext; |
| 1126 }else{ | 1270 }else{ |
| 1127 pDb->stmtList = pPreStmt->pNext; | 1271 pDb->stmtList = pPreStmt->pNext; |
| 1128 } | 1272 } |
| 1129 if( pPreStmt->pNext ){ | 1273 if( pPreStmt->pNext ){ |
| 1130 pPreStmt->pNext->pPrev = pPreStmt->pPrev; | 1274 pPreStmt->pNext->pPrev = pPreStmt->pPrev; |
| 1131 }else{ | 1275 }else{ |
| 1132 pDb->stmtLast = pPreStmt->pPrev; | 1276 pDb->stmtLast = pPreStmt->pPrev; |
| 1133 } | 1277 } |
| 1134 pDb->nStmt--; | 1278 pDb->nStmt--; |
| 1135 nVar = sqlite3_bind_parameter_count(pStmt); | 1279 nVar = sqlite3_bind_parameter_count(pStmt); |
| 1136 break; | 1280 break; |
| 1137 } | 1281 } |
| 1138 } | 1282 } |
| 1139 | 1283 |
| 1140 /* If no prepared statement was found. Compile the SQL text. Also allocate | 1284 /* If no prepared statement was found. Compile the SQL text. Also allocate |
| 1141 ** a new SqlPreparedStmt structure. */ | 1285 ** a new SqlPreparedStmt structure. */ |
| 1142 if( pPreStmt==0 ){ | 1286 if( pPreStmt==0 ){ |
| 1143 int nByte; | 1287 int nByte; |
| 1144 | 1288 |
| 1145 if( SQLITE_OK!=dbPrepare(pDb, zSql, &pStmt, pzOut) ){ | 1289 if( SQLITE_OK!=dbPrepare(pDb, zSql, &pStmt, pzOut) ){ |
| 1146 Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3_errmsg(pDb->db), -1)); | 1290 Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3_errmsg(pDb->db), -1)); |
| 1147 return TCL_ERROR; | 1291 return TCL_ERROR; |
| 1148 } | 1292 } |
| 1149 if( pStmt==0 ){ | 1293 if( pStmt==0 ){ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1175 memcpy(zCopy, zSql, pPreStmt->nSql); | 1319 memcpy(zCopy, zSql, pPreStmt->nSql); |
| 1176 zCopy[pPreStmt->nSql] = '\0'; | 1320 zCopy[pPreStmt->nSql] = '\0'; |
| 1177 pPreStmt->zSql = zCopy; | 1321 pPreStmt->zSql = zCopy; |
| 1178 } | 1322 } |
| 1179 #endif | 1323 #endif |
| 1180 } | 1324 } |
| 1181 assert( pPreStmt ); | 1325 assert( pPreStmt ); |
| 1182 assert( strlen30(pPreStmt->zSql)==pPreStmt->nSql ); | 1326 assert( strlen30(pPreStmt->zSql)==pPreStmt->nSql ); |
| 1183 assert( 0==memcmp(pPreStmt->zSql, zSql, pPreStmt->nSql) ); | 1327 assert( 0==memcmp(pPreStmt->zSql, zSql, pPreStmt->nSql) ); |
| 1184 | 1328 |
| 1185 /* Bind values to parameters that begin with $ or : */ | 1329 /* Bind values to parameters that begin with $ or : */ |
| 1186 for(i=1; i<=nVar; i++){ | 1330 for(i=1; i<=nVar; i++){ |
| 1187 const char *zVar = sqlite3_bind_parameter_name(pStmt, i); | 1331 const char *zVar = sqlite3_bind_parameter_name(pStmt, i); |
| 1188 if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){ | 1332 if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){ |
| 1189 Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0); | 1333 Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0); |
| 1190 if( pVar ){ | 1334 if( pVar ){ |
| 1191 int n; | 1335 int n; |
| 1192 u8 *data; | 1336 u8 *data; |
| 1193 const char *zType = (pVar->typePtr ? pVar->typePtr->name : ""); | 1337 const char *zType = (pVar->typePtr ? pVar->typePtr->name : ""); |
| 1194 c = zType[0]; | 1338 c = zType[0]; |
| 1195 if( zVar[0]=='@' || | 1339 if( zVar[0]=='@' || |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 pDb->stmtList->pPrev = pPreStmt; | 1407 pDb->stmtList->pPrev = pPreStmt; |
| 1264 } | 1408 } |
| 1265 pDb->stmtList = pPreStmt; | 1409 pDb->stmtList = pPreStmt; |
| 1266 if( pDb->stmtLast==0 ){ | 1410 if( pDb->stmtLast==0 ){ |
| 1267 assert( pDb->nStmt==0 ); | 1411 assert( pDb->nStmt==0 ); |
| 1268 pDb->stmtLast = pPreStmt; | 1412 pDb->stmtLast = pPreStmt; |
| 1269 }else{ | 1413 }else{ |
| 1270 assert( pDb->nStmt>0 ); | 1414 assert( pDb->nStmt>0 ); |
| 1271 } | 1415 } |
| 1272 pDb->nStmt++; | 1416 pDb->nStmt++; |
| 1273 | 1417 |
| 1274 /* If we have too many statement in cache, remove the surplus from | 1418 /* If we have too many statement in cache, remove the surplus from |
| 1275 ** the end of the cache list. */ | 1419 ** the end of the cache list. */ |
| 1276 while( pDb->nStmt>pDb->maxStmt ){ | 1420 while( pDb->nStmt>pDb->maxStmt ){ |
| 1277 SqlPreparedStmt *pLast = pDb->stmtLast; | 1421 SqlPreparedStmt *pLast = pDb->stmtLast; |
| 1278 pDb->stmtLast = pLast->pPrev; | 1422 pDb->stmtLast = pLast->pPrev; |
| 1279 pDb->stmtLast->pNext = 0; | 1423 pDb->stmtLast->pNext = 0; |
| 1280 pDb->nStmt--; | 1424 pDb->nStmt--; |
| 1281 dbFreeStmt(pLast); | 1425 dbFreeStmt(pLast); |
| 1282 } | 1426 } |
| 1283 } | 1427 } |
| 1284 } | 1428 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 } | 1462 } |
| 1319 p->nCol = 0; | 1463 p->nCol = 0; |
| 1320 } | 1464 } |
| 1321 | 1465 |
| 1322 /* | 1466 /* |
| 1323 ** Initialize a DbEvalContext structure. | 1467 ** Initialize a DbEvalContext structure. |
| 1324 ** | 1468 ** |
| 1325 ** If pArray is not NULL, then it contains the name of a Tcl array | 1469 ** If pArray is not NULL, then it contains the name of a Tcl array |
| 1326 ** variable. The "*" member of this array is set to a list containing | 1470 ** variable. The "*" member of this array is set to a list containing |
| 1327 ** the names of the columns returned by the statement as part of each | 1471 ** the names of the columns returned by the statement as part of each |
| 1328 ** call to dbEvalStep(), in order from left to right. e.g. if the names | 1472 ** call to dbEvalStep(), in order from left to right. e.g. if the names |
| 1329 ** of the returned columns are a, b and c, it does the equivalent of the | 1473 ** of the returned columns are a, b and c, it does the equivalent of the |
| 1330 ** tcl command: | 1474 ** tcl command: |
| 1331 ** | 1475 ** |
| 1332 ** set ${pArray}(*) {a b c} | 1476 ** set ${pArray}(*) {a b c} |
| 1333 */ | 1477 */ |
| 1334 static void dbEvalInit( | 1478 static void dbEvalInit( |
| 1335 DbEvalContext *p, /* Pointer to structure to initialize */ | 1479 DbEvalContext *p, /* Pointer to structure to initialize */ |
| 1336 SqliteDb *pDb, /* Database handle */ | 1480 SqliteDb *pDb, /* Database handle */ |
| 1337 Tcl_Obj *pSql, /* Object containing SQL script */ | 1481 Tcl_Obj *pSql, /* Object containing SQL script */ |
| 1338 Tcl_Obj *pArray /* Name of Tcl array to set (*) element of */ | 1482 Tcl_Obj *pArray /* Name of Tcl array to set (*) element of */ |
| 1339 ){ | 1483 ){ |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 dbReleaseColumnNames(p); | 1584 dbReleaseColumnNames(p); |
| 1441 p->pPreStmt = 0; | 1585 p->pPreStmt = 0; |
| 1442 | 1586 |
| 1443 if( rcs!=SQLITE_OK ){ | 1587 if( rcs!=SQLITE_OK ){ |
| 1444 /* If a run-time error occurs, report the error and stop reading | 1588 /* If a run-time error occurs, report the error and stop reading |
| 1445 ** the SQL. */ | 1589 ** the SQL. */ |
| 1446 dbReleaseStmt(pDb, pPreStmt, 1); | 1590 dbReleaseStmt(pDb, pPreStmt, 1); |
| 1447 #if SQLITE_TEST | 1591 #if SQLITE_TEST |
| 1448 if( p->pDb->bLegacyPrepare && rcs==SQLITE_SCHEMA && zPrevSql ){ | 1592 if( p->pDb->bLegacyPrepare && rcs==SQLITE_SCHEMA && zPrevSql ){ |
| 1449 /* If the runtime error was an SQLITE_SCHEMA, and the database | 1593 /* If the runtime error was an SQLITE_SCHEMA, and the database |
| 1450 ** handle is configured to use the legacy sqlite3_prepare() | 1594 ** handle is configured to use the legacy sqlite3_prepare() |
| 1451 ** interface, retry prepare()/step() on the same SQL statement. | 1595 ** interface, retry prepare()/step() on the same SQL statement. |
| 1452 ** This only happens once. If there is a second SQLITE_SCHEMA | 1596 ** This only happens once. If there is a second SQLITE_SCHEMA |
| 1453 ** error, the error will be returned to the caller. */ | 1597 ** error, the error will be returned to the caller. */ |
| 1454 p->zSql = zPrevSql; | 1598 p->zSql = zPrevSql; |
| 1455 continue; | 1599 continue; |
| 1456 } | 1600 } |
| 1457 #endif | 1601 #endif |
| 1458 Tcl_SetObjResult(pDb->interp, | 1602 Tcl_SetObjResult(pDb->interp, |
| 1459 Tcl_NewStringObj(sqlite3_errmsg(pDb->db), -1)); | 1603 Tcl_NewStringObj(sqlite3_errmsg(pDb->db), -1)); |
| 1460 return TCL_ERROR; | 1604 return TCL_ERROR; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 ** This allows stubs-enabled builds to be used with older Tcl libraries. | 1672 ** This allows stubs-enabled builds to be used with older Tcl libraries. |
| 1529 */ | 1673 */ |
| 1530 #if TCL_MAJOR_VERSION>8 || (TCL_MAJOR_VERSION==8 && TCL_MINOR_VERSION>=6) | 1674 #if TCL_MAJOR_VERSION>8 || (TCL_MAJOR_VERSION==8 && TCL_MINOR_VERSION>=6) |
| 1531 # define SQLITE_TCL_NRE 1 | 1675 # define SQLITE_TCL_NRE 1 |
| 1532 static int DbUseNre(void){ | 1676 static int DbUseNre(void){ |
| 1533 int major, minor; | 1677 int major, minor; |
| 1534 Tcl_GetVersion(&major, &minor, 0, 0); | 1678 Tcl_GetVersion(&major, &minor, 0, 0); |
| 1535 return( (major==8 && minor>=6) || major>8 ); | 1679 return( (major==8 && minor>=6) || major>8 ); |
| 1536 } | 1680 } |
| 1537 #else | 1681 #else |
| 1538 /* | 1682 /* |
| 1539 ** Compiling using headers earlier than 8.6. In this case NR cannot be | 1683 ** Compiling using headers earlier than 8.6. In this case NR cannot be |
| 1540 ** used, so DbUseNre() to always return zero. Add #defines for the other | 1684 ** used, so DbUseNre() to always return zero. Add #defines for the other |
| 1541 ** Tcl_NRxxx() functions to prevent them from causing compilation errors, | 1685 ** Tcl_NRxxx() functions to prevent them from causing compilation errors, |
| 1542 ** even though the only invocations of them are within conditional blocks | 1686 ** even though the only invocations of them are within conditional blocks |
| 1543 ** of the form: | 1687 ** of the form: |
| 1544 ** | 1688 ** |
| 1545 ** if( DbUseNre() ) { ... } | 1689 ** if( DbUseNre() ) { ... } |
| 1546 */ | 1690 */ |
| 1547 # define SQLITE_TCL_NRE 0 | 1691 # define SQLITE_TCL_NRE 0 |
| 1548 # define DbUseNre() 0 | 1692 # define DbUseNre() 0 |
| 1549 # define Tcl_NRAddCallback(a,b,c,d,e,f) (void)0 | 1693 # define Tcl_NRAddCallback(a,b,c,d,e,f) (void)0 |
| 1550 # define Tcl_NREvalObj(a,b,c) 0 | 1694 # define Tcl_NREvalObj(a,b,c) 0 |
| 1551 # define Tcl_NRCreateCommand(a,b,c,d,e,f) (void)0 | 1695 # define Tcl_NRCreateCommand(a,b,c,d,e,f) (void)0 |
| 1552 #endif | 1696 #endif |
| 1553 | 1697 |
| 1554 /* | 1698 /* |
| 1555 ** This function is part of the implementation of the command: | 1699 ** This function is part of the implementation of the command: |
| 1556 ** | 1700 ** |
| 1557 ** $db eval SQL ?ARRAYNAME? SCRIPT | 1701 ** $db eval SQL ?ARRAYNAME? SCRIPT |
| 1558 */ | 1702 */ |
| 1559 static int DbEvalNextCmd( | 1703 static int SQLITE_TCLAPI DbEvalNextCmd( |
| 1560 ClientData data[], /* data[0] is the (DbEvalContext*) */ | 1704 ClientData data[], /* data[0] is the (DbEvalContext*) */ |
| 1561 Tcl_Interp *interp, /* Tcl interpreter */ | 1705 Tcl_Interp *interp, /* Tcl interpreter */ |
| 1562 int result /* Result so far */ | 1706 int result /* Result so far */ |
| 1563 ){ | 1707 ){ |
| 1564 int rc = result; /* Return code */ | 1708 int rc = result; /* Return code */ |
| 1565 | 1709 |
| 1566 /* The first element of the data[] array is a pointer to a DbEvalContext | 1710 /* The first element of the data[] array is a pointer to a DbEvalContext |
| 1567 ** structure allocated using Tcl_Alloc(). The second element of data[] | 1711 ** structure allocated using Tcl_Alloc(). The second element of data[] |
| 1568 ** is a pointer to a Tcl_Obj containing the script to run for each row | 1712 ** is a pointer to a Tcl_Obj containing the script to run for each row |
| 1569 ** returned by the queries encapsulated in data[0]. */ | 1713 ** returned by the queries encapsulated in data[0]. */ |
| 1570 DbEvalContext *p = (DbEvalContext *)data[0]; | 1714 DbEvalContext *p = (DbEvalContext *)data[0]; |
| 1571 Tcl_Obj *pScript = (Tcl_Obj *)data[1]; | 1715 Tcl_Obj *pScript = (Tcl_Obj *)data[1]; |
| 1572 Tcl_Obj *pArray = p->pArray; | 1716 Tcl_Obj *pArray = p->pArray; |
| 1573 | 1717 |
| 1574 while( (rc==TCL_OK || rc==TCL_CONTINUE) && TCL_OK==(rc = dbEvalStep(p)) ){ | 1718 while( (rc==TCL_OK || rc==TCL_CONTINUE) && TCL_OK==(rc = dbEvalStep(p)) ){ |
| 1575 int i; | 1719 int i; |
| 1576 int nCol; | 1720 int nCol; |
| 1577 Tcl_Obj **apColName; | 1721 Tcl_Obj **apColName; |
| 1578 dbEvalRowInfo(p, &nCol, &apColName); | 1722 dbEvalRowInfo(p, &nCol, &apColName); |
| 1579 for(i=0; i<nCol; i++){ | 1723 for(i=0; i<nCol; i++){ |
| 1580 Tcl_Obj *pVal = dbEvalColumnValue(p, i); | 1724 Tcl_Obj *pVal = dbEvalColumnValue(p, i); |
| 1581 if( pArray==0 ){ | 1725 if( pArray==0 ){ |
| 1582 Tcl_ObjSetVar2(interp, apColName[i], 0, pVal, 0); | 1726 Tcl_ObjSetVar2(interp, apColName[i], 0, pVal, 0); |
| 1583 }else{ | 1727 }else{ |
| 1584 Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0); | 1728 Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0); |
| 1585 } | 1729 } |
| 1586 } | 1730 } |
| 1587 | 1731 |
| 1588 /* The required interpreter variables are now populated with the data | 1732 /* The required interpreter variables are now populated with the data |
| 1589 ** from the current row. If using NRE, schedule callbacks to evaluate | 1733 ** from the current row. If using NRE, schedule callbacks to evaluate |
| 1590 ** script pScript, then to invoke this function again to fetch the next | 1734 ** script pScript, then to invoke this function again to fetch the next |
| 1591 ** row (or clean up if there is no next row or the script throws an | 1735 ** row (or clean up if there is no next row or the script throws an |
| 1592 ** exception). After scheduling the callbacks, return control to the | 1736 ** exception). After scheduling the callbacks, return control to the |
| 1593 ** caller. | 1737 ** caller. |
| 1594 ** | 1738 ** |
| 1595 ** If not using NRE, evaluate pScript directly and continue with the | 1739 ** If not using NRE, evaluate pScript directly and continue with the |
| 1596 ** next iteration of this while(...) loop. */ | 1740 ** next iteration of this while(...) loop. */ |
| 1597 if( DbUseNre() ){ | 1741 if( DbUseNre() ){ |
| 1598 Tcl_NRAddCallback(interp, DbEvalNextCmd, (void*)p, (void*)pScript, 0, 0); | 1742 Tcl_NRAddCallback(interp, DbEvalNextCmd, (void*)p, (void*)pScript, 0, 0); |
| 1599 return Tcl_NREvalObj(interp, pScript, 0); | 1743 return Tcl_NREvalObj(interp, pScript, 0); |
| 1600 }else{ | 1744 }else{ |
| 1601 rc = Tcl_EvalObjEx(interp, pScript, 0); | 1745 rc = Tcl_EvalObjEx(interp, pScript, 0); |
| 1602 } | 1746 } |
| 1603 } | 1747 } |
| 1604 | 1748 |
| 1605 Tcl_DecrRefCount(pScript); | 1749 Tcl_DecrRefCount(pScript); |
| 1606 dbEvalFinalize(p); | 1750 dbEvalFinalize(p); |
| 1607 Tcl_Free((char *)p); | 1751 Tcl_Free((char *)p); |
| 1608 | 1752 |
| 1609 if( rc==TCL_OK || rc==TCL_BREAK ){ | 1753 if( rc==TCL_OK || rc==TCL_BREAK ){ |
| 1610 Tcl_ResetResult(interp); | 1754 Tcl_ResetResult(interp); |
| 1611 rc = TCL_OK; | 1755 rc = TCL_OK; |
| 1612 } | 1756 } |
| 1613 return rc; | 1757 return rc; |
| 1614 } | 1758 } |
| 1615 | 1759 |
| 1616 /* | 1760 /* |
| 1761 ** This function is used by the implementations of the following database |
| 1762 ** handle sub-commands: |
| 1763 ** |
| 1764 ** $db update_hook ?SCRIPT? |
| 1765 ** $db wal_hook ?SCRIPT? |
| 1766 ** $db commit_hook ?SCRIPT? |
| 1767 ** $db preupdate hook ?SCRIPT? |
| 1768 */ |
| 1769 static void DbHookCmd( |
| 1770 Tcl_Interp *interp, /* Tcl interpreter */ |
| 1771 SqliteDb *pDb, /* Database handle */ |
| 1772 Tcl_Obj *pArg, /* SCRIPT argument (or NULL) */ |
| 1773 Tcl_Obj **ppHook /* Pointer to member of SqliteDb */ |
| 1774 ){ |
| 1775 sqlite3 *db = pDb->db; |
| 1776 |
| 1777 if( *ppHook ){ |
| 1778 Tcl_SetObjResult(interp, *ppHook); |
| 1779 if( pArg ){ |
| 1780 Tcl_DecrRefCount(*ppHook); |
| 1781 *ppHook = 0; |
| 1782 } |
| 1783 } |
| 1784 if( pArg ){ |
| 1785 assert( !(*ppHook) ); |
| 1786 if( Tcl_GetCharLength(pArg)>0 ){ |
| 1787 *ppHook = pArg; |
| 1788 Tcl_IncrRefCount(*ppHook); |
| 1789 } |
| 1790 } |
| 1791 |
| 1792 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 1793 sqlite3_preupdate_hook(db, (pDb->pPreUpdateHook?DbPreUpdateHandler:0), pDb); |
| 1794 #endif |
| 1795 sqlite3_update_hook(db, (pDb->pUpdateHook?DbUpdateHandler:0), pDb); |
| 1796 sqlite3_rollback_hook(db, (pDb->pRollbackHook?DbRollbackHandler:0), pDb); |
| 1797 sqlite3_wal_hook(db, (pDb->pWalHook?DbWalHandler:0), pDb); |
| 1798 } |
| 1799 |
| 1800 /* |
| 1617 ** The "sqlite" command below creates a new Tcl command for each | 1801 ** The "sqlite" command below creates a new Tcl command for each |
| 1618 ** connection it opens to an SQLite database. This routine is invoked | 1802 ** connection it opens to an SQLite database. This routine is invoked |
| 1619 ** whenever one of those connection-specific commands is executed | 1803 ** whenever one of those connection-specific commands is executed |
| 1620 ** in Tcl. For example, if you run Tcl code like this: | 1804 ** in Tcl. For example, if you run Tcl code like this: |
| 1621 ** | 1805 ** |
| 1622 ** sqlite3 db1 "my_database" | 1806 ** sqlite3 db1 "my_database" |
| 1623 ** db1 close | 1807 ** db1 close |
| 1624 ** | 1808 ** |
| 1625 ** The first command opens a connection to the "my_database" database | 1809 ** The first command opens a connection to the "my_database" database |
| 1626 ** and calls that connection "db1". The second command causes this | 1810 ** and calls that connection "db1". The second command causes this |
| 1627 ** subroutine to be invoked. | 1811 ** subroutine to be invoked. |
| 1628 */ | 1812 */ |
| 1629 static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ | 1813 static int SQLITE_TCLAPI DbObjCmd( |
| 1814 void *cd, |
| 1815 Tcl_Interp *interp, |
| 1816 int objc, |
| 1817 Tcl_Obj *const*objv |
| 1818 ){ |
| 1630 SqliteDb *pDb = (SqliteDb*)cd; | 1819 SqliteDb *pDb = (SqliteDb*)cd; |
| 1631 int choice; | 1820 int choice; |
| 1632 int rc = TCL_OK; | 1821 int rc = TCL_OK; |
| 1633 static const char *DB_strs[] = { | 1822 static const char *DB_strs[] = { |
| 1634 "authorizer", "backup", "busy", | 1823 "authorizer", "backup", "busy", |
| 1635 "cache", "changes", "close", | 1824 "cache", "changes", "close", |
| 1636 "collate", "collation_needed", "commit_hook", | 1825 "collate", "collation_needed", "commit_hook", |
| 1637 "complete", "copy", "enable_load_extension", | 1826 "complete", "copy", "enable_load_extension", |
| 1638 "errorcode", "eval", "exists", | 1827 "errorcode", "eval", "exists", |
| 1639 "function", "incrblob", "interrupt", | 1828 "function", "incrblob", "interrupt", |
| 1640 "last_insert_rowid", "nullvalue", "onecolumn", | 1829 "last_insert_rowid", "nullvalue", "onecolumn", |
| 1641 "profile", "progress", "rekey", | 1830 "preupdate", "profile", "progress", |
| 1642 "restore", "rollback_hook", "status", | 1831 "rekey", "restore", "rollback_hook", |
| 1643 "timeout", "total_changes", "trace", | 1832 "status", "timeout", "total_changes", |
| 1644 "transaction", "unlock_notify", "update_hook", | 1833 "trace", "trace_v2", "transaction", |
| 1645 "version", "wal_hook", 0 | 1834 "unlock_notify", "update_hook", "version", |
| 1835 "wal_hook", |
| 1836 0 |
| 1646 }; | 1837 }; |
| 1647 enum DB_enum { | 1838 enum DB_enum { |
| 1648 DB_AUTHORIZER, DB_BACKUP, DB_BUSY, | 1839 DB_AUTHORIZER, DB_BACKUP, DB_BUSY, |
| 1649 DB_CACHE, DB_CHANGES, DB_CLOSE, | 1840 DB_CACHE, DB_CHANGES, DB_CLOSE, |
| 1650 DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK, | 1841 DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK, |
| 1651 DB_COMPLETE, DB_COPY, DB_ENABLE_LOAD_EXTENSION, | 1842 DB_COMPLETE, DB_COPY, DB_ENABLE_LOAD_EXTENSION, |
| 1652 DB_ERRORCODE, DB_EVAL, DB_EXISTS, | 1843 DB_ERRORCODE, DB_EVAL, DB_EXISTS, |
| 1653 DB_FUNCTION, DB_INCRBLOB, DB_INTERRUPT, | 1844 DB_FUNCTION, DB_INCRBLOB, DB_INTERRUPT, |
| 1654 DB_LAST_INSERT_ROWID, DB_NULLVALUE, DB_ONECOLUMN, | 1845 DB_LAST_INSERT_ROWID, DB_NULLVALUE, DB_ONECOLUMN, |
| 1655 DB_PROFILE, DB_PROGRESS, DB_REKEY, | 1846 DB_PREUPDATE, DB_PROFILE, DB_PROGRESS, |
| 1656 DB_RESTORE, DB_ROLLBACK_HOOK, DB_STATUS, | 1847 DB_REKEY, DB_RESTORE, DB_ROLLBACK_HOOK, |
| 1657 DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE, | 1848 DB_STATUS, DB_TIMEOUT, DB_TOTAL_CHANGES, |
| 1658 DB_TRANSACTION, DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK, | 1849 DB_TRACE, DB_TRACE_V2, DB_TRANSACTION, |
| 1659 DB_VERSION, DB_WAL_HOOK | 1850 DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK, DB_VERSION, |
| 1851 DB_WAL_HOOK, |
| 1660 }; | 1852 }; |
| 1661 /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ | 1853 /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ |
| 1662 | 1854 |
| 1663 if( objc<2 ){ | 1855 if( objc<2 ){ |
| 1664 Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ..."); | 1856 Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ..."); |
| 1665 return TCL_ERROR; | 1857 return TCL_ERROR; |
| 1666 } | 1858 } |
| 1667 if( Tcl_GetIndexFromObj(interp, objv[1], DB_strs, "option", 0, &choice) ){ | 1859 if( Tcl_GetIndexFromObj(interp, objv[1], DB_strs, "option", 0, &choice) ){ |
| 1668 return TCL_ERROR; | 1860 return TCL_ERROR; |
| 1669 } | 1861 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1743 if( objc==3 ){ | 1935 if( objc==3 ){ |
| 1744 zSrcDb = "main"; | 1936 zSrcDb = "main"; |
| 1745 zDestFile = Tcl_GetString(objv[2]); | 1937 zDestFile = Tcl_GetString(objv[2]); |
| 1746 }else if( objc==4 ){ | 1938 }else if( objc==4 ){ |
| 1747 zSrcDb = Tcl_GetString(objv[2]); | 1939 zSrcDb = Tcl_GetString(objv[2]); |
| 1748 zDestFile = Tcl_GetString(objv[3]); | 1940 zDestFile = Tcl_GetString(objv[3]); |
| 1749 }else{ | 1941 }else{ |
| 1750 Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME"); | 1942 Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME"); |
| 1751 return TCL_ERROR; | 1943 return TCL_ERROR; |
| 1752 } | 1944 } |
| 1753 rc = sqlite3_open(zDestFile, &pDest); | 1945 rc = sqlite3_open_v2(zDestFile, &pDest, |
| 1946 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| pDb->openFlags, 0); |
| 1754 if( rc!=SQLITE_OK ){ | 1947 if( rc!=SQLITE_OK ){ |
| 1755 Tcl_AppendResult(interp, "cannot open target database: ", | 1948 Tcl_AppendResult(interp, "cannot open target database: ", |
| 1756 sqlite3_errmsg(pDest), (char*)0); | 1949 sqlite3_errmsg(pDest), (char*)0); |
| 1757 sqlite3_close(pDest); | 1950 sqlite3_close(pDest); |
| 1758 return TCL_ERROR; | 1951 return TCL_ERROR; |
| 1759 } | 1952 } |
| 1760 pBackup = sqlite3_backup_init(pDest, "main", pDb->db, zSrcDb); | 1953 pBackup = sqlite3_backup_init(pDest, "main", pDb->db, zSrcDb); |
| 1761 if( pBackup==0 ){ | 1954 if( pBackup==0 ){ |
| 1762 Tcl_AppendResult(interp, "backup failed: ", | 1955 Tcl_AppendResult(interp, "backup failed: ", |
| 1763 sqlite3_errmsg(pDest), (char*)0); | 1956 sqlite3_errmsg(pDest), (char*)0); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 return TCL_ERROR; | 2027 return TCL_ERROR; |
| 1835 }else{ | 2028 }else{ |
| 1836 flushStmtCache( pDb ); | 2029 flushStmtCache( pDb ); |
| 1837 } | 2030 } |
| 1838 }else if( *subCmd=='s' && strcmp(subCmd,"size")==0 ){ | 2031 }else if( *subCmd=='s' && strcmp(subCmd,"size")==0 ){ |
| 1839 if( objc!=4 ){ | 2032 if( objc!=4 ){ |
| 1840 Tcl_WrongNumArgs(interp, 2, objv, "size n"); | 2033 Tcl_WrongNumArgs(interp, 2, objv, "size n"); |
| 1841 return TCL_ERROR; | 2034 return TCL_ERROR; |
| 1842 }else{ | 2035 }else{ |
| 1843 if( TCL_ERROR==Tcl_GetIntFromObj(interp, objv[3], &n) ){ | 2036 if( TCL_ERROR==Tcl_GetIntFromObj(interp, objv[3], &n) ){ |
| 1844 Tcl_AppendResult( interp, "cannot convert \"", | 2037 Tcl_AppendResult( interp, "cannot convert \"", |
| 1845 Tcl_GetStringFromObj(objv[3],0), "\" to integer", (char*)0); | 2038 Tcl_GetStringFromObj(objv[3],0), "\" to integer", (char*)0); |
| 1846 return TCL_ERROR; | 2039 return TCL_ERROR; |
| 1847 }else{ | 2040 }else{ |
| 1848 if( n<0 ){ | 2041 if( n<0 ){ |
| 1849 flushStmtCache( pDb ); | 2042 flushStmtCache( pDb ); |
| 1850 n = 0; | 2043 n = 0; |
| 1851 }else if( n>MAX_PREPARED_STMTS ){ | 2044 }else if( n>MAX_PREPARED_STMTS ){ |
| 1852 n = MAX_PREPARED_STMTS; | 2045 n = MAX_PREPARED_STMTS; |
| 1853 } | 2046 } |
| 1854 pDb->maxStmt = n; | 2047 pDb->maxStmt = n; |
| 1855 } | 2048 } |
| 1856 } | 2049 } |
| 1857 }else{ | 2050 }else{ |
| 1858 Tcl_AppendResult( interp, "bad option \"", | 2051 Tcl_AppendResult( interp, "bad option \"", |
| 1859 Tcl_GetStringFromObj(objv[2],0), "\": must be flush or size", | 2052 Tcl_GetStringFromObj(objv[2],0), "\": must be flush or size", |
| 1860 (char*)0); | 2053 (char*)0); |
| 1861 return TCL_ERROR; | 2054 return TCL_ERROR; |
| 1862 } | 2055 } |
| 1863 break; | 2056 break; |
| 1864 } | 2057 } |
| 1865 | 2058 |
| 1866 /* $db changes | 2059 /* $db changes |
| 1867 ** | 2060 ** |
| 1868 ** Return the number of rows that were modified, inserted, or deleted by | 2061 ** Return the number of rows that were modified, inserted, or deleted by |
| 1869 ** the most recent INSERT, UPDATE or DELETE statement, not including | 2062 ** the most recent INSERT, UPDATE or DELETE statement, not including |
| 1870 ** any changes made by trigger programs. | 2063 ** any changes made by trigger programs. |
| 1871 */ | 2064 */ |
| 1872 case DB_CHANGES: { | 2065 case DB_CHANGES: { |
| 1873 Tcl_Obj *pResult; | 2066 Tcl_Obj *pResult; |
| 1874 if( objc!=2 ){ | 2067 if( objc!=2 ){ |
| 1875 Tcl_WrongNumArgs(interp, 2, objv, ""); | 2068 Tcl_WrongNumArgs(interp, 2, objv, ""); |
| 1876 return TCL_ERROR; | 2069 return TCL_ERROR; |
| 1877 } | 2070 } |
| 1878 pResult = Tcl_GetObjResult(interp); | 2071 pResult = Tcl_GetObjResult(interp); |
| 1879 Tcl_SetIntObj(pResult, sqlite3_changes(pDb->db)); | 2072 Tcl_SetIntObj(pResult, sqlite3_changes(pDb->db)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1906 } | 2099 } |
| 1907 zName = Tcl_GetStringFromObj(objv[2], 0); | 2100 zName = Tcl_GetStringFromObj(objv[2], 0); |
| 1908 zScript = Tcl_GetStringFromObj(objv[3], &nScript); | 2101 zScript = Tcl_GetStringFromObj(objv[3], &nScript); |
| 1909 pCollate = (SqlCollate*)Tcl_Alloc( sizeof(*pCollate) + nScript + 1 ); | 2102 pCollate = (SqlCollate*)Tcl_Alloc( sizeof(*pCollate) + nScript + 1 ); |
| 1910 if( pCollate==0 ) return TCL_ERROR; | 2103 if( pCollate==0 ) return TCL_ERROR; |
| 1911 pCollate->interp = interp; | 2104 pCollate->interp = interp; |
| 1912 pCollate->pNext = pDb->pCollate; | 2105 pCollate->pNext = pDb->pCollate; |
| 1913 pCollate->zScript = (char*)&pCollate[1]; | 2106 pCollate->zScript = (char*)&pCollate[1]; |
| 1914 pDb->pCollate = pCollate; | 2107 pDb->pCollate = pCollate; |
| 1915 memcpy(pCollate->zScript, zScript, nScript+1); | 2108 memcpy(pCollate->zScript, zScript, nScript+1); |
| 1916 if( sqlite3_create_collation(pDb->db, zName, SQLITE_UTF8, | 2109 if( sqlite3_create_collation(pDb->db, zName, SQLITE_UTF8, |
| 1917 pCollate, tclSqlCollate) ){ | 2110 pCollate, tclSqlCollate) ){ |
| 1918 Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE); | 2111 Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE); |
| 1919 return TCL_ERROR; | 2112 return TCL_ERROR; |
| 1920 } | 2113 } |
| 1921 break; | 2114 break; |
| 1922 } | 2115 } |
| 1923 | 2116 |
| 1924 /* | 2117 /* |
| 1925 ** $db collation_needed SCRIPT | 2118 ** $db collation_needed SCRIPT |
| 1926 ** | 2119 ** |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2032 char **azCol; /* zLine[] broken up into columns */ | 2225 char **azCol; /* zLine[] broken up into columns */ |
| 2033 const char *zCommit; /* How to commit changes */ | 2226 const char *zCommit; /* How to commit changes */ |
| 2034 FILE *in; /* The input file */ | 2227 FILE *in; /* The input file */ |
| 2035 int lineno = 0; /* Line number of input file */ | 2228 int lineno = 0; /* Line number of input file */ |
| 2036 char zLineNum[80]; /* Line number print buffer */ | 2229 char zLineNum[80]; /* Line number print buffer */ |
| 2037 Tcl_Obj *pResult; /* interp result */ | 2230 Tcl_Obj *pResult; /* interp result */ |
| 2038 | 2231 |
| 2039 const char *zSep; | 2232 const char *zSep; |
| 2040 const char *zNull; | 2233 const char *zNull; |
| 2041 if( objc<5 || objc>7 ){ | 2234 if( objc<5 || objc>7 ){ |
| 2042 Tcl_WrongNumArgs(interp, 2, objv, | 2235 Tcl_WrongNumArgs(interp, 2, objv, |
| 2043 "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"); | 2236 "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"); |
| 2044 return TCL_ERROR; | 2237 return TCL_ERROR; |
| 2045 } | 2238 } |
| 2046 if( objc>=6 ){ | 2239 if( objc>=6 ){ |
| 2047 zSep = Tcl_GetStringFromObj(objv[5], 0); | 2240 zSep = Tcl_GetStringFromObj(objv[5], 0); |
| 2048 }else{ | 2241 }else{ |
| 2049 zSep = "\t"; | 2242 zSep = "\t"; |
| 2050 } | 2243 } |
| 2051 if( objc>=7 ){ | 2244 if( objc>=7 ){ |
| 2052 zNull = Tcl_GetStringFromObj(objv[6], 0); | 2245 zNull = Tcl_GetStringFromObj(objv[6], 0); |
| 2053 }else{ | 2246 }else{ |
| 2054 zNull = ""; | 2247 zNull = ""; |
| 2055 } | 2248 } |
| 2056 zConflict = Tcl_GetStringFromObj(objv[2], 0); | 2249 zConflict = Tcl_GetStringFromObj(objv[2], 0); |
| 2057 zTable = Tcl_GetStringFromObj(objv[3], 0); | 2250 zTable = Tcl_GetStringFromObj(objv[3], 0); |
| 2058 zFile = Tcl_GetStringFromObj(objv[4], 0); | 2251 zFile = Tcl_GetStringFromObj(objv[4], 0); |
| 2059 nSep = strlen30(zSep); | 2252 nSep = strlen30(zSep); |
| 2060 nNull = strlen30(zNull); | 2253 nNull = strlen30(zNull); |
| 2061 if( nSep==0 ){ | 2254 if( nSep==0 ){ |
| 2062 Tcl_AppendResult(interp,"Error: non-null separator required for copy", | 2255 Tcl_AppendResult(interp,"Error: non-null separator required for copy", |
| 2063 (char*)0); | 2256 (char*)0); |
| 2064 return TCL_ERROR; | 2257 return TCL_ERROR; |
| 2065 } | 2258 } |
| 2066 if(strcmp(zConflict, "rollback") != 0 && | 2259 if(strcmp(zConflict, "rollback") != 0 && |
| 2067 strcmp(zConflict, "abort" ) != 0 && | 2260 strcmp(zConflict, "abort" ) != 0 && |
| 2068 strcmp(zConflict, "fail" ) != 0 && | 2261 strcmp(zConflict, "fail" ) != 0 && |
| 2069 strcmp(zConflict, "ignore" ) != 0 && | 2262 strcmp(zConflict, "ignore" ) != 0 && |
| 2070 strcmp(zConflict, "replace" ) != 0 ) { | 2263 strcmp(zConflict, "replace" ) != 0 ) { |
| 2071 Tcl_AppendResult(interp, "Error: \"", zConflict, | 2264 Tcl_AppendResult(interp, "Error: \"", zConflict, |
| 2072 "\", conflict-algorithm must be one of: rollback, " | 2265 "\", conflict-algorithm must be one of: rollback, " |
| 2073 "abort, fail, ignore, or replace", (char*)0); | 2266 "abort, fail, ignore, or replace", (char*)0); |
| 2074 return TCL_ERROR; | 2267 return TCL_ERROR; |
| 2075 } | 2268 } |
| 2076 zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable); | 2269 zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable); |
| 2077 if( zSql==0 ){ | 2270 if( zSql==0 ){ |
| 2078 Tcl_AppendResult(interp, "Error: no such table: ", zTable, (char*)0); | 2271 Tcl_AppendResult(interp, "Error: no such table: ", zTable, (char*)0); |
| 2079 return TCL_ERROR; | 2272 return TCL_ERROR; |
| 2080 } | 2273 } |
| 2081 nByte = strlen30(zSql); | 2274 nByte = strlen30(zSql); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2107 zSql[j] = 0; | 2300 zSql[j] = 0; |
| 2108 rc = sqlite3_prepare(pDb->db, zSql, -1, &pStmt, 0); | 2301 rc = sqlite3_prepare(pDb->db, zSql, -1, &pStmt, 0); |
| 2109 free(zSql); | 2302 free(zSql); |
| 2110 if( rc ){ | 2303 if( rc ){ |
| 2111 Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), (char*)0); | 2304 Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), (char*)0); |
| 2112 sqlite3_finalize(pStmt); | 2305 sqlite3_finalize(pStmt); |
| 2113 return TCL_ERROR; | 2306 return TCL_ERROR; |
| 2114 } | 2307 } |
| 2115 in = fopen(zFile, "rb"); | 2308 in = fopen(zFile, "rb"); |
| 2116 if( in==0 ){ | 2309 if( in==0 ){ |
| 2117 Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, NULL); | 2310 Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, (char*)0); |
| 2118 sqlite3_finalize(pStmt); | 2311 sqlite3_finalize(pStmt); |
| 2119 return TCL_ERROR; | 2312 return TCL_ERROR; |
| 2120 } | 2313 } |
| 2121 azCol = malloc( sizeof(azCol[0])*(nCol+1) ); | 2314 azCol = malloc( sizeof(azCol[0])*(nCol+1) ); |
| 2122 if( azCol==0 ) { | 2315 if( azCol==0 ) { |
| 2123 Tcl_AppendResult(interp, "Error: can't malloc()", (char*)0); | 2316 Tcl_AppendResult(interp, "Error: can't malloc()", (char*)0); |
| 2124 fclose(in); | 2317 fclose(in); |
| 2125 return TCL_ERROR; | 2318 return TCL_ERROR; |
| 2126 } | 2319 } |
| 2127 (void)sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0); | 2320 (void)sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2150 zFile, lineno, nCol, i+1); | 2343 zFile, lineno, nCol, i+1); |
| 2151 Tcl_AppendResult(interp, zErr, (char*)0); | 2344 Tcl_AppendResult(interp, zErr, (char*)0); |
| 2152 free(zErr); | 2345 free(zErr); |
| 2153 } | 2346 } |
| 2154 zCommit = "ROLLBACK"; | 2347 zCommit = "ROLLBACK"; |
| 2155 break; | 2348 break; |
| 2156 } | 2349 } |
| 2157 for(i=0; i<nCol; i++){ | 2350 for(i=0; i<nCol; i++){ |
| 2158 /* check for null data, if so, bind as null */ | 2351 /* check for null data, if so, bind as null */ |
| 2159 if( (nNull>0 && strcmp(azCol[i], zNull)==0) | 2352 if( (nNull>0 && strcmp(azCol[i], zNull)==0) |
| 2160 || strlen30(azCol[i])==0 | 2353 || strlen30(azCol[i])==0 |
| 2161 ){ | 2354 ){ |
| 2162 sqlite3_bind_null(pStmt, i+1); | 2355 sqlite3_bind_null(pStmt, i+1); |
| 2163 }else{ | 2356 }else{ |
| 2164 sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC); | 2357 sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC); |
| 2165 } | 2358 } |
| 2166 } | 2359 } |
| 2167 sqlite3_step(pStmt); | 2360 sqlite3_step(pStmt); |
| 2168 rc = sqlite3_reset(pStmt); | 2361 rc = sqlite3_reset(pStmt); |
| 2169 free(zLine); | 2362 free(zLine); |
| 2170 if( rc!=SQLITE_OK ){ | 2363 if( rc!=SQLITE_OK ){ |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2229 break; | 2422 break; |
| 2230 } | 2423 } |
| 2231 | 2424 |
| 2232 /* | 2425 /* |
| 2233 ** $db exists $sql | 2426 ** $db exists $sql |
| 2234 ** $db onecolumn $sql | 2427 ** $db onecolumn $sql |
| 2235 ** | 2428 ** |
| 2236 ** The onecolumn method is the equivalent of: | 2429 ** The onecolumn method is the equivalent of: |
| 2237 ** lindex [$db eval $sql] 0 | 2430 ** lindex [$db eval $sql] 0 |
| 2238 */ | 2431 */ |
| 2239 case DB_EXISTS: | 2432 case DB_EXISTS: |
| 2240 case DB_ONECOLUMN: { | 2433 case DB_ONECOLUMN: { |
| 2434 Tcl_Obj *pResult = 0; |
| 2241 DbEvalContext sEval; | 2435 DbEvalContext sEval; |
| 2242 if( objc!=3 ){ | 2436 if( objc!=3 ){ |
| 2243 Tcl_WrongNumArgs(interp, 2, objv, "SQL"); | 2437 Tcl_WrongNumArgs(interp, 2, objv, "SQL"); |
| 2244 return TCL_ERROR; | 2438 return TCL_ERROR; |
| 2245 } | 2439 } |
| 2246 | 2440 |
| 2247 dbEvalInit(&sEval, pDb, objv[2], 0); | 2441 dbEvalInit(&sEval, pDb, objv[2], 0); |
| 2248 rc = dbEvalStep(&sEval); | 2442 rc = dbEvalStep(&sEval); |
| 2249 if( choice==DB_ONECOLUMN ){ | 2443 if( choice==DB_ONECOLUMN ){ |
| 2250 if( rc==TCL_OK ){ | 2444 if( rc==TCL_OK ){ |
| 2251 Tcl_SetObjResult(interp, dbEvalColumnValue(&sEval, 0)); | 2445 pResult = dbEvalColumnValue(&sEval, 0); |
| 2252 }else if( rc==TCL_BREAK ){ | 2446 }else if( rc==TCL_BREAK ){ |
| 2253 Tcl_ResetResult(interp); | 2447 Tcl_ResetResult(interp); |
| 2254 } | 2448 } |
| 2255 }else if( rc==TCL_BREAK || rc==TCL_OK ){ | 2449 }else if( rc==TCL_BREAK || rc==TCL_OK ){ |
| 2256 Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc==TCL_OK)); | 2450 pResult = Tcl_NewBooleanObj(rc==TCL_OK); |
| 2257 } | 2451 } |
| 2258 dbEvalFinalize(&sEval); | 2452 dbEvalFinalize(&sEval); |
| 2453 if( pResult ) Tcl_SetObjResult(interp, pResult); |
| 2259 | 2454 |
| 2260 if( rc==TCL_BREAK ){ | 2455 if( rc==TCL_BREAK ){ |
| 2261 rc = TCL_OK; | 2456 rc = TCL_OK; |
| 2262 } | 2457 } |
| 2263 break; | 2458 break; |
| 2264 } | 2459 } |
| 2265 | 2460 |
| 2266 /* | 2461 /* |
| 2267 ** $db eval $sql ?array? ?{ ...code... }? | 2462 ** $db eval $sql ?array? ?{ ...code... }? |
| 2268 ** | 2463 ** |
| 2269 ** The SQL statement in $sql is evaluated. For each row, the values are | 2464 ** The SQL statement in $sql is evaluated. For each row, the values are |
| 2270 ** placed in elements of the array named "array" and ...code... is executed. | 2465 ** placed in elements of the array named "array" and ...code... is executed. |
| 2271 ** If "array" and "code" are omitted, then no callback is every invoked. | 2466 ** If "array" and "code" are omitted, then no callback is every invoked. |
| 2272 ** If "array" is an empty string, then the values are placed in variables | 2467 ** If "array" is an empty string, then the values are placed in variables |
| 2273 ** that have the same name as the fields extracted by the query. | 2468 ** that have the same name as the fields extracted by the query. |
| 2274 */ | 2469 */ |
| 2275 case DB_EVAL: { | 2470 case DB_EVAL: { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2301 ClientData cd2[2]; | 2496 ClientData cd2[2]; |
| 2302 DbEvalContext *p; | 2497 DbEvalContext *p; |
| 2303 Tcl_Obj *pArray = 0; | 2498 Tcl_Obj *pArray = 0; |
| 2304 Tcl_Obj *pScript; | 2499 Tcl_Obj *pScript; |
| 2305 | 2500 |
| 2306 if( objc==5 && *(char *)Tcl_GetString(objv[3]) ){ | 2501 if( objc==5 && *(char *)Tcl_GetString(objv[3]) ){ |
| 2307 pArray = objv[3]; | 2502 pArray = objv[3]; |
| 2308 } | 2503 } |
| 2309 pScript = objv[objc-1]; | 2504 pScript = objv[objc-1]; |
| 2310 Tcl_IncrRefCount(pScript); | 2505 Tcl_IncrRefCount(pScript); |
| 2311 | 2506 |
| 2312 p = (DbEvalContext *)Tcl_Alloc(sizeof(DbEvalContext)); | 2507 p = (DbEvalContext *)Tcl_Alloc(sizeof(DbEvalContext)); |
| 2313 dbEvalInit(p, pDb, objv[2], pArray); | 2508 dbEvalInit(p, pDb, objv[2], pArray); |
| 2314 | 2509 |
| 2315 cd2[0] = (void *)p; | 2510 cd2[0] = (void *)p; |
| 2316 cd2[1] = (void *)pScript; | 2511 cd2[1] = (void *)pScript; |
| 2317 rc = DbEvalNextCmd(cd2, interp, TCL_OK); | 2512 rc = DbEvalNextCmd(cd2, interp, TCL_OK); |
| 2318 } | 2513 } |
| 2319 break; | 2514 break; |
| 2320 } | 2515 } |
| 2321 | 2516 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2334 int i; | 2529 int i; |
| 2335 if( objc<4 ){ | 2530 if( objc<4 ){ |
| 2336 Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT"); | 2531 Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT"); |
| 2337 return TCL_ERROR; | 2532 return TCL_ERROR; |
| 2338 } | 2533 } |
| 2339 for(i=3; i<(objc-1); i++){ | 2534 for(i=3; i<(objc-1); i++){ |
| 2340 const char *z = Tcl_GetString(objv[i]); | 2535 const char *z = Tcl_GetString(objv[i]); |
| 2341 int n = strlen30(z); | 2536 int n = strlen30(z); |
| 2342 if( n>2 && strncmp(z, "-argcount",n)==0 ){ | 2537 if( n>2 && strncmp(z, "-argcount",n)==0 ){ |
| 2343 if( i==(objc-2) ){ | 2538 if( i==(objc-2) ){ |
| 2344 Tcl_AppendResult(interp, "option requires an argument: ", z, 0); | 2539 Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0); |
| 2345 return TCL_ERROR; | 2540 return TCL_ERROR; |
| 2346 } | 2541 } |
| 2347 if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR; | 2542 if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR; |
| 2348 if( nArg<0 ){ | 2543 if( nArg<0 ){ |
| 2349 Tcl_AppendResult(interp, "number of arguments must be non-negative", | 2544 Tcl_AppendResult(interp, "number of arguments must be non-negative", |
| 2350 (char*)0); | 2545 (char*)0); |
| 2351 return TCL_ERROR; | 2546 return TCL_ERROR; |
| 2352 } | 2547 } |
| 2353 i++; | 2548 i++; |
| 2354 }else | 2549 }else |
| 2355 if( n>2 && strncmp(z, "-deterministic",n)==0 ){ | 2550 if( n>2 && strncmp(z, "-deterministic",n)==0 ){ |
| 2356 flags |= SQLITE_DETERMINISTIC; | 2551 flags |= SQLITE_DETERMINISTIC; |
| 2357 }else{ | 2552 }else{ |
| 2358 Tcl_AppendResult(interp, "bad option \"", z, | 2553 Tcl_AppendResult(interp, "bad option \"", z, |
| 2359 "\": must be -argcount or -deterministic", 0 | 2554 "\": must be -argcount or -deterministic", (char*)0 |
| 2360 ); | 2555 ); |
| 2361 return TCL_ERROR; | 2556 return TCL_ERROR; |
| 2362 } | 2557 } |
| 2363 } | 2558 } |
| 2364 | 2559 |
| 2365 pScript = objv[objc-1]; | 2560 pScript = objv[objc-1]; |
| 2366 zName = Tcl_GetStringFromObj(objv[2], 0); | 2561 zName = Tcl_GetStringFromObj(objv[2], 0); |
| 2367 pFunc = findSqlFunc(pDb, zName); | 2562 pFunc = findSqlFunc(pDb, zName); |
| 2368 if( pFunc==0 ) return TCL_ERROR; | 2563 if( pFunc==0 ) return TCL_ERROR; |
| 2369 if( pFunc->pScript ){ | 2564 if( pFunc->pScript ){ |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2457 pDb->zNull[len] = '\0'; | 2652 pDb->zNull[len] = '\0'; |
| 2458 }else{ | 2653 }else{ |
| 2459 pDb->zNull = 0; | 2654 pDb->zNull = 0; |
| 2460 } | 2655 } |
| 2461 } | 2656 } |
| 2462 Tcl_SetObjResult(interp, Tcl_NewStringObj(pDb->zNull, -1)); | 2657 Tcl_SetObjResult(interp, Tcl_NewStringObj(pDb->zNull, -1)); |
| 2463 break; | 2658 break; |
| 2464 } | 2659 } |
| 2465 | 2660 |
| 2466 /* | 2661 /* |
| 2467 ** $db last_insert_rowid | 2662 ** $db last_insert_rowid |
| 2468 ** | 2663 ** |
| 2469 ** Return an integer which is the ROWID for the most recent insert. | 2664 ** Return an integer which is the ROWID for the most recent insert. |
| 2470 */ | 2665 */ |
| 2471 case DB_LAST_INSERT_ROWID: { | 2666 case DB_LAST_INSERT_ROWID: { |
| 2472 Tcl_Obj *pResult; | 2667 Tcl_Obj *pResult; |
| 2473 Tcl_WideInt rowid; | 2668 Tcl_WideInt rowid; |
| 2474 if( objc!=2 ){ | 2669 if( objc!=2 ){ |
| 2475 Tcl_WrongNumArgs(interp, 2, objv, ""); | 2670 Tcl_WrongNumArgs(interp, 2, objv, ""); |
| 2476 return TCL_ERROR; | 2671 return TCL_ERROR; |
| 2477 } | 2672 } |
| 2478 rowid = sqlite3_last_insert_rowid(pDb->db); | 2673 rowid = sqlite3_last_insert_rowid(pDb->db); |
| 2479 pResult = Tcl_GetObjResult(interp); | 2674 pResult = Tcl_GetObjResult(interp); |
| 2480 Tcl_SetWideIntObj(pResult, rowid); | 2675 Tcl_SetWideIntObj(pResult, rowid); |
| 2481 break; | 2676 break; |
| 2482 } | 2677 } |
| 2483 | 2678 |
| 2484 /* | 2679 /* |
| 2485 ** The DB_ONECOLUMN method is implemented together with DB_EXISTS. | 2680 ** The DB_ONECOLUMN method is implemented together with DB_EXISTS. |
| 2486 */ | 2681 */ |
| 2487 | 2682 |
| 2488 /* $db progress ?N CALLBACK? | 2683 /* $db progress ?N CALLBACK? |
| 2489 ** | 2684 ** |
| 2490 ** Invoke the given callback every N virtual machine opcodes while executing | 2685 ** Invoke the given callback every N virtual machine opcodes while executing |
| 2491 ** queries. | 2686 ** queries. |
| 2492 */ | 2687 */ |
| 2493 case DB_PROGRESS: { | 2688 case DB_PROGRESS: { |
| 2494 if( objc==2 ){ | 2689 if( objc==2 ){ |
| 2495 if( pDb->zProgress ){ | 2690 if( pDb->zProgress ){ |
| 2496 Tcl_AppendResult(interp, pDb->zProgress, (char*)0); | 2691 Tcl_AppendResult(interp, pDb->zProgress, (char*)0); |
| 2497 } | 2692 } |
| 2498 }else if( objc==4 ){ | 2693 }else if( objc==4 ){ |
| 2499 char *zProgress; | 2694 char *zProgress; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2547 if( pDb->zProfile ){ | 2742 if( pDb->zProfile ){ |
| 2548 Tcl_Free(pDb->zProfile); | 2743 Tcl_Free(pDb->zProfile); |
| 2549 } | 2744 } |
| 2550 zProfile = Tcl_GetStringFromObj(objv[2], &len); | 2745 zProfile = Tcl_GetStringFromObj(objv[2], &len); |
| 2551 if( zProfile && len>0 ){ | 2746 if( zProfile && len>0 ){ |
| 2552 pDb->zProfile = Tcl_Alloc( len + 1 ); | 2747 pDb->zProfile = Tcl_Alloc( len + 1 ); |
| 2553 memcpy(pDb->zProfile, zProfile, len+1); | 2748 memcpy(pDb->zProfile, zProfile, len+1); |
| 2554 }else{ | 2749 }else{ |
| 2555 pDb->zProfile = 0; | 2750 pDb->zProfile = 0; |
| 2556 } | 2751 } |
| 2557 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) | 2752 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ |
| 2753 !defined(SQLITE_OMIT_DEPRECATED) |
| 2558 if( pDb->zProfile ){ | 2754 if( pDb->zProfile ){ |
| 2559 pDb->interp = interp; | 2755 pDb->interp = interp; |
| 2560 sqlite3_profile(pDb->db, DbProfileHandler, pDb); | 2756 sqlite3_profile(pDb->db, DbProfileHandler, pDb); |
| 2561 }else{ | 2757 }else{ |
| 2562 sqlite3_profile(pDb->db, 0, 0); | 2758 sqlite3_profile(pDb->db, 0, 0); |
| 2563 } | 2759 } |
| 2564 #endif | 2760 #endif |
| 2565 } | 2761 } |
| 2566 break; | 2762 break; |
| 2567 } | 2763 } |
| 2568 | 2764 |
| 2569 /* | 2765 /* |
| 2570 ** $db rekey KEY | 2766 ** $db rekey KEY |
| 2571 ** | 2767 ** |
| 2572 ** Change the encryption key on the currently open database. | 2768 ** Change the encryption key on the currently open database. |
| 2573 */ | 2769 */ |
| 2574 case DB_REKEY: { | 2770 case DB_REKEY: { |
| 2575 #ifdef SQLITE_HAS_CODEC | 2771 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 2576 int nKey; | 2772 int nKey; |
| 2577 void *pKey; | 2773 void *pKey; |
| 2578 #endif | 2774 #endif |
| 2579 if( objc!=3 ){ | 2775 if( objc!=3 ){ |
| 2580 Tcl_WrongNumArgs(interp, 2, objv, "KEY"); | 2776 Tcl_WrongNumArgs(interp, 2, objv, "KEY"); |
| 2581 return TCL_ERROR; | 2777 return TCL_ERROR; |
| 2582 } | 2778 } |
| 2583 #ifdef SQLITE_HAS_CODEC | 2779 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 2584 pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey); | 2780 pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey); |
| 2585 rc = sqlite3_rekey(pDb->db, pKey, nKey); | 2781 rc = sqlite3_rekey(pDb->db, pKey, nKey); |
| 2586 if( rc ){ | 2782 if( rc ){ |
| 2587 Tcl_AppendResult(interp, sqlite3_errstr(rc), (char*)0); | 2783 Tcl_AppendResult(interp, sqlite3_errstr(rc), (char*)0); |
| 2588 rc = TCL_ERROR; | 2784 rc = TCL_ERROR; |
| 2589 } | 2785 } |
| 2590 #endif | 2786 #endif |
| 2591 break; | 2787 break; |
| 2592 } | 2788 } |
| 2593 | 2789 |
| 2594 /* $db restore ?DATABASE? FILENAME | 2790 /* $db restore ?DATABASE? FILENAME |
| 2595 ** | 2791 ** |
| 2596 ** Open a database file named FILENAME. Transfer the content | 2792 ** Open a database file named FILENAME. Transfer the content |
| 2597 ** of FILENAME into the local database DATABASE (default: "main"). | 2793 ** of FILENAME into the local database DATABASE (default: "main"). |
| 2598 */ | 2794 */ |
| 2599 case DB_RESTORE: { | 2795 case DB_RESTORE: { |
| 2600 const char *zSrcFile; | 2796 const char *zSrcFile; |
| 2601 const char *zDestDb; | 2797 const char *zDestDb; |
| 2602 sqlite3 *pSrc; | 2798 sqlite3 *pSrc; |
| 2603 sqlite3_backup *pBackup; | 2799 sqlite3_backup *pBackup; |
| 2604 int nTimeout = 0; | 2800 int nTimeout = 0; |
| 2605 | 2801 |
| 2606 if( objc==3 ){ | 2802 if( objc==3 ){ |
| 2607 zDestDb = "main"; | 2803 zDestDb = "main"; |
| 2608 zSrcFile = Tcl_GetString(objv[2]); | 2804 zSrcFile = Tcl_GetString(objv[2]); |
| 2609 }else if( objc==4 ){ | 2805 }else if( objc==4 ){ |
| 2610 zDestDb = Tcl_GetString(objv[2]); | 2806 zDestDb = Tcl_GetString(objv[2]); |
| 2611 zSrcFile = Tcl_GetString(objv[3]); | 2807 zSrcFile = Tcl_GetString(objv[3]); |
| 2612 }else{ | 2808 }else{ |
| 2613 Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME"); | 2809 Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? FILENAME"); |
| 2614 return TCL_ERROR; | 2810 return TCL_ERROR; |
| 2615 } | 2811 } |
| 2616 rc = sqlite3_open_v2(zSrcFile, &pSrc, SQLITE_OPEN_READONLY, 0); | 2812 rc = sqlite3_open_v2(zSrcFile, &pSrc, |
| 2813 SQLITE_OPEN_READONLY | pDb->openFlags, 0); |
| 2617 if( rc!=SQLITE_OK ){ | 2814 if( rc!=SQLITE_OK ){ |
| 2618 Tcl_AppendResult(interp, "cannot open source database: ", | 2815 Tcl_AppendResult(interp, "cannot open source database: ", |
| 2619 sqlite3_errmsg(pSrc), (char*)0); | 2816 sqlite3_errmsg(pSrc), (char*)0); |
| 2620 sqlite3_close(pSrc); | 2817 sqlite3_close(pSrc); |
| 2621 return TCL_ERROR; | 2818 return TCL_ERROR; |
| 2622 } | 2819 } |
| 2623 pBackup = sqlite3_backup_init(pDb->db, zDestDb, pSrc, "main"); | 2820 pBackup = sqlite3_backup_init(pDb->db, zDestDb, pSrc, "main"); |
| 2624 if( pBackup==0 ){ | 2821 if( pBackup==0 ){ |
| 2625 Tcl_AppendResult(interp, "restore failed: ", | 2822 Tcl_AppendResult(interp, "restore failed: ", |
| 2626 sqlite3_errmsg(pDb->db), (char*)0); | 2823 sqlite3_errmsg(pDb->db), (char*)0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2646 sqlite3_errmsg(pDb->db), (char*)0); | 2843 sqlite3_errmsg(pDb->db), (char*)0); |
| 2647 rc = TCL_ERROR; | 2844 rc = TCL_ERROR; |
| 2648 } | 2845 } |
| 2649 sqlite3_close(pSrc); | 2846 sqlite3_close(pSrc); |
| 2650 break; | 2847 break; |
| 2651 } | 2848 } |
| 2652 | 2849 |
| 2653 /* | 2850 /* |
| 2654 ** $db status (step|sort|autoindex) | 2851 ** $db status (step|sort|autoindex) |
| 2655 ** | 2852 ** |
| 2656 ** Display SQLITE_STMTSTATUS_FULLSCAN_STEP or | 2853 ** Display SQLITE_STMTSTATUS_FULLSCAN_STEP or |
| 2657 ** SQLITE_STMTSTATUS_SORT for the most recent eval. | 2854 ** SQLITE_STMTSTATUS_SORT for the most recent eval. |
| 2658 */ | 2855 */ |
| 2659 case DB_STATUS: { | 2856 case DB_STATUS: { |
| 2660 int v; | 2857 int v; |
| 2661 const char *zOp; | 2858 const char *zOp; |
| 2662 if( objc!=3 ){ | 2859 if( objc!=3 ){ |
| 2663 Tcl_WrongNumArgs(interp, 2, objv, "(step|sort|autoindex)"); | 2860 Tcl_WrongNumArgs(interp, 2, objv, "(step|sort|autoindex)"); |
| 2664 return TCL_ERROR; | 2861 return TCL_ERROR; |
| 2665 } | 2862 } |
| 2666 zOp = Tcl_GetString(objv[2]); | 2863 zOp = Tcl_GetString(objv[2]); |
| 2667 if( strcmp(zOp, "step")==0 ){ | 2864 if( strcmp(zOp, "step")==0 ){ |
| 2668 v = pDb->nStep; | 2865 v = pDb->nStep; |
| 2669 }else if( strcmp(zOp, "sort")==0 ){ | 2866 }else if( strcmp(zOp, "sort")==0 ){ |
| 2670 v = pDb->nSort; | 2867 v = pDb->nSort; |
| 2671 }else if( strcmp(zOp, "autoindex")==0 ){ | 2868 }else if( strcmp(zOp, "autoindex")==0 ){ |
| 2672 v = pDb->nIndex; | 2869 v = pDb->nIndex; |
| 2673 }else{ | 2870 }else{ |
| 2674 Tcl_AppendResult(interp, | 2871 Tcl_AppendResult(interp, |
| 2675 "bad argument: should be autoindex, step, or sort", | 2872 "bad argument: should be autoindex, step, or sort", |
| 2676 (char*)0); | 2873 (char*)0); |
| 2677 return TCL_ERROR; | 2874 return TCL_ERROR; |
| 2678 } | 2875 } |
| 2679 Tcl_SetObjResult(interp, Tcl_NewIntObj(v)); | 2876 Tcl_SetObjResult(interp, Tcl_NewIntObj(v)); |
| 2680 break; | 2877 break; |
| 2681 } | 2878 } |
| 2682 | 2879 |
| 2683 /* | 2880 /* |
| 2684 ** $db timeout MILLESECONDS | 2881 ** $db timeout MILLESECONDS |
| 2685 ** | 2882 ** |
| 2686 ** Delay for the number of milliseconds specified when a file is locked. | 2883 ** Delay for the number of milliseconds specified when a file is locked. |
| 2687 */ | 2884 */ |
| 2688 case DB_TIMEOUT: { | 2885 case DB_TIMEOUT: { |
| 2689 int ms; | 2886 int ms; |
| 2690 if( objc!=3 ){ | 2887 if( objc!=3 ){ |
| 2691 Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS"); | 2888 Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS"); |
| 2692 return TCL_ERROR; | 2889 return TCL_ERROR; |
| 2693 } | 2890 } |
| 2694 if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR; | 2891 if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR; |
| 2695 sqlite3_busy_timeout(pDb->db, ms); | 2892 sqlite3_busy_timeout(pDb->db, ms); |
| 2696 break; | 2893 break; |
| 2697 } | 2894 } |
| 2698 | 2895 |
| 2699 /* | 2896 /* |
| 2700 ** $db total_changes | 2897 ** $db total_changes |
| 2701 ** | 2898 ** |
| 2702 ** Return the number of rows that were modified, inserted, or deleted | 2899 ** Return the number of rows that were modified, inserted, or deleted |
| 2703 ** since the database handle was created. | 2900 ** since the database handle was created. |
| 2704 */ | 2901 */ |
| 2705 case DB_TOTAL_CHANGES: { | 2902 case DB_TOTAL_CHANGES: { |
| 2706 Tcl_Obj *pResult; | 2903 Tcl_Obj *pResult; |
| 2707 if( objc!=2 ){ | 2904 if( objc!=2 ){ |
| 2708 Tcl_WrongNumArgs(interp, 2, objv, ""); | 2905 Tcl_WrongNumArgs(interp, 2, objv, ""); |
| 2709 return TCL_ERROR; | 2906 return TCL_ERROR; |
| 2710 } | 2907 } |
| 2711 pResult = Tcl_GetObjResult(interp); | 2908 pResult = Tcl_GetObjResult(interp); |
| 2712 Tcl_SetIntObj(pResult, sqlite3_total_changes(pDb->db)); | 2909 Tcl_SetIntObj(pResult, sqlite3_total_changes(pDb->db)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2733 if( pDb->zTrace ){ | 2930 if( pDb->zTrace ){ |
| 2734 Tcl_Free(pDb->zTrace); | 2931 Tcl_Free(pDb->zTrace); |
| 2735 } | 2932 } |
| 2736 zTrace = Tcl_GetStringFromObj(objv[2], &len); | 2933 zTrace = Tcl_GetStringFromObj(objv[2], &len); |
| 2737 if( zTrace && len>0 ){ | 2934 if( zTrace && len>0 ){ |
| 2738 pDb->zTrace = Tcl_Alloc( len + 1 ); | 2935 pDb->zTrace = Tcl_Alloc( len + 1 ); |
| 2739 memcpy(pDb->zTrace, zTrace, len+1); | 2936 memcpy(pDb->zTrace, zTrace, len+1); |
| 2740 }else{ | 2937 }else{ |
| 2741 pDb->zTrace = 0; | 2938 pDb->zTrace = 0; |
| 2742 } | 2939 } |
| 2743 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) | 2940 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) && \ |
| 2941 !defined(SQLITE_OMIT_DEPRECATED) |
| 2744 if( pDb->zTrace ){ | 2942 if( pDb->zTrace ){ |
| 2745 pDb->interp = interp; | 2943 pDb->interp = interp; |
| 2746 sqlite3_trace(pDb->db, DbTraceHandler, pDb); | 2944 sqlite3_trace(pDb->db, DbTraceHandler, pDb); |
| 2747 }else{ | 2945 }else{ |
| 2748 sqlite3_trace(pDb->db, 0, 0); | 2946 sqlite3_trace(pDb->db, 0, 0); |
| 2749 } | 2947 } |
| 2750 #endif | 2948 #endif |
| 2751 } | 2949 } |
| 2752 break; | 2950 break; |
| 2753 } | 2951 } |
| 2754 | 2952 |
| 2953 /* $db trace_v2 ?CALLBACK? ?MASK? |
| 2954 ** |
| 2955 ** Make arrangements to invoke the CALLBACK routine for each trace event |
| 2956 ** matching the mask that is generated. The parameters are appended to |
| 2957 ** CALLBACK before it is executed. |
| 2958 */ |
| 2959 case DB_TRACE_V2: { |
| 2960 if( objc>4 ){ |
| 2961 Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK? ?MASK?"); |
| 2962 return TCL_ERROR; |
| 2963 }else if( objc==2 ){ |
| 2964 if( pDb->zTraceV2 ){ |
| 2965 Tcl_AppendResult(interp, pDb->zTraceV2, (char*)0); |
| 2966 } |
| 2967 }else{ |
| 2968 char *zTraceV2; |
| 2969 int len; |
| 2970 Tcl_WideInt wMask = 0; |
| 2971 if( objc==4 ){ |
| 2972 static const char *TTYPE_strs[] = { |
| 2973 "statement", "profile", "row", "close", 0 |
| 2974 }; |
| 2975 enum TTYPE_enum { |
| 2976 TTYPE_STMT, TTYPE_PROFILE, TTYPE_ROW, TTYPE_CLOSE |
| 2977 }; |
| 2978 int i; |
| 2979 if( TCL_OK!=Tcl_ListObjLength(interp, objv[3], &len) ){ |
| 2980 return TCL_ERROR; |
| 2981 } |
| 2982 for(i=0; i<len; i++){ |
| 2983 Tcl_Obj *pObj; |
| 2984 int ttype; |
| 2985 if( TCL_OK!=Tcl_ListObjIndex(interp, objv[3], i, &pObj) ){ |
| 2986 return TCL_ERROR; |
| 2987 } |
| 2988 if( Tcl_GetIndexFromObj(interp, pObj, TTYPE_strs, "trace type", |
| 2989 0, &ttype)!=TCL_OK ){ |
| 2990 Tcl_WideInt wType; |
| 2991 Tcl_Obj *pError = Tcl_DuplicateObj(Tcl_GetObjResult(interp)); |
| 2992 Tcl_IncrRefCount(pError); |
| 2993 if( TCL_OK==Tcl_GetWideIntFromObj(interp, pObj, &wType) ){ |
| 2994 Tcl_DecrRefCount(pError); |
| 2995 wMask |= wType; |
| 2996 }else{ |
| 2997 Tcl_SetObjResult(interp, pError); |
| 2998 Tcl_DecrRefCount(pError); |
| 2999 return TCL_ERROR; |
| 3000 } |
| 3001 }else{ |
| 3002 switch( (enum TTYPE_enum)ttype ){ |
| 3003 case TTYPE_STMT: wMask |= SQLITE_TRACE_STMT; break; |
| 3004 case TTYPE_PROFILE: wMask |= SQLITE_TRACE_PROFILE; break; |
| 3005 case TTYPE_ROW: wMask |= SQLITE_TRACE_ROW; break; |
| 3006 case TTYPE_CLOSE: wMask |= SQLITE_TRACE_CLOSE; break; |
| 3007 } |
| 3008 } |
| 3009 } |
| 3010 }else{ |
| 3011 wMask = SQLITE_TRACE_STMT; /* use the "legacy" default */ |
| 3012 } |
| 3013 if( pDb->zTraceV2 ){ |
| 3014 Tcl_Free(pDb->zTraceV2); |
| 3015 } |
| 3016 zTraceV2 = Tcl_GetStringFromObj(objv[2], &len); |
| 3017 if( zTraceV2 && len>0 ){ |
| 3018 pDb->zTraceV2 = Tcl_Alloc( len + 1 ); |
| 3019 memcpy(pDb->zTraceV2, zTraceV2, len+1); |
| 3020 }else{ |
| 3021 pDb->zTraceV2 = 0; |
| 3022 } |
| 3023 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT) |
| 3024 if( pDb->zTraceV2 ){ |
| 3025 pDb->interp = interp; |
| 3026 sqlite3_trace_v2(pDb->db, (unsigned)wMask, DbTraceV2Handler, pDb); |
| 3027 }else{ |
| 3028 sqlite3_trace_v2(pDb->db, 0, 0, 0); |
| 3029 } |
| 3030 #endif |
| 3031 } |
| 3032 break; |
| 3033 } |
| 3034 |
| 2755 /* $db transaction [-deferred|-immediate|-exclusive] SCRIPT | 3035 /* $db transaction [-deferred|-immediate|-exclusive] SCRIPT |
| 2756 ** | 3036 ** |
| 2757 ** Start a new transaction (if we are not already in the midst of a | 3037 ** Start a new transaction (if we are not already in the midst of a |
| 2758 ** transaction) and execute the TCL script SCRIPT. After SCRIPT | 3038 ** transaction) and execute the TCL script SCRIPT. After SCRIPT |
| 2759 ** completes, either commit the transaction or roll it back if SCRIPT | 3039 ** completes, either commit the transaction or roll it back if SCRIPT |
| 2760 ** throws an exception. Or if no new transation was started, do nothing. | 3040 ** throws an exception. Or if no new transation was started, do nothing. |
| 2761 ** pass the exception on up the stack. | 3041 ** pass the exception on up the stack. |
| 2762 ** | 3042 ** |
| 2763 ** This command was inspired by Dave Thomas's talk on Ruby at the | 3043 ** This command was inspired by Dave Thomas's talk on Ruby at the |
| 2764 ** 2005 O'Reilly Open Source Convention (OSCON). | 3044 ** 2005 O'Reilly Open Source Convention (OSCON). |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2797 pDb->disableAuth--; | 3077 pDb->disableAuth--; |
| 2798 if( rc!=SQLITE_OK ){ | 3078 if( rc!=SQLITE_OK ){ |
| 2799 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); | 3079 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); |
| 2800 return TCL_ERROR; | 3080 return TCL_ERROR; |
| 2801 } | 3081 } |
| 2802 pDb->nTransaction++; | 3082 pDb->nTransaction++; |
| 2803 | 3083 |
| 2804 /* If using NRE, schedule a callback to invoke the script pScript, then | 3084 /* If using NRE, schedule a callback to invoke the script pScript, then |
| 2805 ** a second callback to commit (or rollback) the transaction or savepoint | 3085 ** a second callback to commit (or rollback) the transaction or savepoint |
| 2806 ** opened above. If not using NRE, evaluate the script directly, then | 3086 ** opened above. If not using NRE, evaluate the script directly, then |
| 2807 ** call function DbTransPostCmd() to commit (or rollback) the transaction | 3087 ** call function DbTransPostCmd() to commit (or rollback) the transaction |
| 2808 ** or savepoint. */ | 3088 ** or savepoint. */ |
| 2809 if( DbUseNre() ){ | 3089 if( DbUseNre() ){ |
| 2810 Tcl_NRAddCallback(interp, DbTransPostCmd, cd, 0, 0, 0); | 3090 Tcl_NRAddCallback(interp, DbTransPostCmd, cd, 0, 0, 0); |
| 2811 (void)Tcl_NREvalObj(interp, pScript, 0); | 3091 (void)Tcl_NREvalObj(interp, pScript, 0); |
| 2812 }else{ | 3092 }else{ |
| 2813 rc = DbTransPostCmd(&cd, interp, Tcl_EvalObjEx(interp, pScript, 0)); | 3093 rc = DbTransPostCmd(&cd, interp, Tcl_EvalObjEx(interp, pScript, 0)); |
| 2814 } | 3094 } |
| 2815 break; | 3095 break; |
| 2816 } | 3096 } |
| 2817 | 3097 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2828 Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); | 3108 Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); |
| 2829 rc = TCL_ERROR; | 3109 rc = TCL_ERROR; |
| 2830 }else{ | 3110 }else{ |
| 2831 void (*xNotify)(void **, int) = 0; | 3111 void (*xNotify)(void **, int) = 0; |
| 2832 void *pNotifyArg = 0; | 3112 void *pNotifyArg = 0; |
| 2833 | 3113 |
| 2834 if( pDb->pUnlockNotify ){ | 3114 if( pDb->pUnlockNotify ){ |
| 2835 Tcl_DecrRefCount(pDb->pUnlockNotify); | 3115 Tcl_DecrRefCount(pDb->pUnlockNotify); |
| 2836 pDb->pUnlockNotify = 0; | 3116 pDb->pUnlockNotify = 0; |
| 2837 } | 3117 } |
| 2838 | 3118 |
| 2839 if( objc==3 ){ | 3119 if( objc==3 ){ |
| 2840 xNotify = DbUnlockNotify; | 3120 xNotify = DbUnlockNotify; |
| 2841 pNotifyArg = (void *)pDb; | 3121 pNotifyArg = (void *)pDb; |
| 2842 pDb->pUnlockNotify = objv[2]; | 3122 pDb->pUnlockNotify = objv[2]; |
| 2843 Tcl_IncrRefCount(pDb->pUnlockNotify); | 3123 Tcl_IncrRefCount(pDb->pUnlockNotify); |
| 2844 } | 3124 } |
| 2845 | 3125 |
| 2846 if( sqlite3_unlock_notify(pDb->db, xNotify, pNotifyArg) ){ | 3126 if( sqlite3_unlock_notify(pDb->db, xNotify, pNotifyArg) ){ |
| 2847 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); | 3127 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); |
| 2848 rc = TCL_ERROR; | 3128 rc = TCL_ERROR; |
| 2849 } | 3129 } |
| 2850 } | 3130 } |
| 2851 #endif | 3131 #endif |
| 2852 break; | 3132 break; |
| 2853 } | 3133 } |
| 2854 | 3134 |
| 2855 /* | 3135 /* |
| 3136 ** $db preupdate_hook count |
| 3137 ** $db preupdate_hook hook ?SCRIPT? |
| 3138 ** $db preupdate_hook new INDEX |
| 3139 ** $db preupdate_hook old INDEX |
| 3140 */ |
| 3141 case DB_PREUPDATE: { |
| 3142 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK |
| 3143 Tcl_AppendResult(interp, "preupdate_hook was omitted at compile-time", |
| 3144 (char*)0); |
| 3145 rc = TCL_ERROR; |
| 3146 #else |
| 3147 static const char *azSub[] = {"count", "depth", "hook", "new", "old", 0}; |
| 3148 enum DbPreupdateSubCmd { |
| 3149 PRE_COUNT, PRE_DEPTH, PRE_HOOK, PRE_NEW, PRE_OLD |
| 3150 }; |
| 3151 int iSub; |
| 3152 |
| 3153 if( objc<3 ){ |
| 3154 Tcl_WrongNumArgs(interp, 2, objv, "SUB-COMMAND ?ARGS?"); |
| 3155 } |
| 3156 if( Tcl_GetIndexFromObj(interp, objv[2], azSub, "sub-command", 0, &iSub) ){ |
| 3157 return TCL_ERROR; |
| 3158 } |
| 3159 |
| 3160 switch( (enum DbPreupdateSubCmd)iSub ){ |
| 3161 case PRE_COUNT: { |
| 3162 int nCol = sqlite3_preupdate_count(pDb->db); |
| 3163 Tcl_SetObjResult(interp, Tcl_NewIntObj(nCol)); |
| 3164 break; |
| 3165 } |
| 3166 |
| 3167 case PRE_HOOK: { |
| 3168 if( objc>4 ){ |
| 3169 Tcl_WrongNumArgs(interp, 2, objv, "hook ?SCRIPT?"); |
| 3170 return TCL_ERROR; |
| 3171 } |
| 3172 DbHookCmd(interp, pDb, (objc==4 ? objv[3] : 0), &pDb->pPreUpdateHook); |
| 3173 break; |
| 3174 } |
| 3175 |
| 3176 case PRE_DEPTH: { |
| 3177 Tcl_Obj *pRet; |
| 3178 if( objc!=3 ){ |
| 3179 Tcl_WrongNumArgs(interp, 3, objv, ""); |
| 3180 return TCL_ERROR; |
| 3181 } |
| 3182 pRet = Tcl_NewIntObj(sqlite3_preupdate_depth(pDb->db)); |
| 3183 Tcl_SetObjResult(interp, pRet); |
| 3184 break; |
| 3185 } |
| 3186 |
| 3187 case PRE_NEW: |
| 3188 case PRE_OLD: { |
| 3189 int iIdx; |
| 3190 sqlite3_value *pValue; |
| 3191 if( objc!=4 ){ |
| 3192 Tcl_WrongNumArgs(interp, 3, objv, "INDEX"); |
| 3193 return TCL_ERROR; |
| 3194 } |
| 3195 if( Tcl_GetIntFromObj(interp, objv[3], &iIdx) ){ |
| 3196 return TCL_ERROR; |
| 3197 } |
| 3198 |
| 3199 if( iSub==PRE_OLD ){ |
| 3200 rc = sqlite3_preupdate_old(pDb->db, iIdx, &pValue); |
| 3201 }else{ |
| 3202 assert( iSub==PRE_NEW ); |
| 3203 rc = sqlite3_preupdate_new(pDb->db, iIdx, &pValue); |
| 3204 } |
| 3205 |
| 3206 if( rc==SQLITE_OK ){ |
| 3207 Tcl_Obj *pObj; |
| 3208 pObj = Tcl_NewStringObj((char*)sqlite3_value_text(pValue), -1); |
| 3209 Tcl_SetObjResult(interp, pObj); |
| 3210 }else{ |
| 3211 Tcl_AppendResult(interp, sqlite3_errmsg(pDb->db), (char*)0); |
| 3212 return TCL_ERROR; |
| 3213 } |
| 3214 } |
| 3215 } |
| 3216 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 3217 break; |
| 3218 } |
| 3219 |
| 3220 /* |
| 2856 ** $db wal_hook ?script? | 3221 ** $db wal_hook ?script? |
| 2857 ** $db update_hook ?script? | 3222 ** $db update_hook ?script? |
| 2858 ** $db rollback_hook ?script? | 3223 ** $db rollback_hook ?script? |
| 2859 */ | 3224 */ |
| 2860 case DB_WAL_HOOK: | 3225 case DB_WAL_HOOK: |
| 2861 case DB_UPDATE_HOOK: | 3226 case DB_UPDATE_HOOK: |
| 2862 case DB_ROLLBACK_HOOK: { | 3227 case DB_ROLLBACK_HOOK: { |
| 2863 | 3228 /* set ppHook to point at pUpdateHook or pRollbackHook, depending on |
| 2864 /* set ppHook to point at pUpdateHook or pRollbackHook, depending on | |
| 2865 ** whether [$db update_hook] or [$db rollback_hook] was invoked. | 3229 ** whether [$db update_hook] or [$db rollback_hook] was invoked. |
| 2866 */ | 3230 */ |
| 2867 Tcl_Obj **ppHook; | 3231 Tcl_Obj **ppHook = 0; |
| 2868 if( choice==DB_UPDATE_HOOK ){ | 3232 if( choice==DB_WAL_HOOK ) ppHook = &pDb->pWalHook; |
| 2869 ppHook = &pDb->pUpdateHook; | 3233 if( choice==DB_UPDATE_HOOK ) ppHook = &pDb->pUpdateHook; |
| 2870 }else if( choice==DB_WAL_HOOK ){ | 3234 if( choice==DB_ROLLBACK_HOOK ) ppHook = &pDb->pRollbackHook; |
| 2871 ppHook = &pDb->pWalHook; | 3235 if( objc>3 ){ |
| 2872 }else{ | |
| 2873 ppHook = &pDb->pRollbackHook; | |
| 2874 } | |
| 2875 | |
| 2876 if( objc!=2 && objc!=3 ){ | |
| 2877 Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); | 3236 Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); |
| 2878 return TCL_ERROR; | 3237 return TCL_ERROR; |
| 2879 } | 3238 } |
| 2880 if( *ppHook ){ | |
| 2881 Tcl_SetObjResult(interp, *ppHook); | |
| 2882 if( objc==3 ){ | |
| 2883 Tcl_DecrRefCount(*ppHook); | |
| 2884 *ppHook = 0; | |
| 2885 } | |
| 2886 } | |
| 2887 if( objc==3 ){ | |
| 2888 assert( !(*ppHook) ); | |
| 2889 if( Tcl_GetCharLength(objv[2])>0 ){ | |
| 2890 *ppHook = objv[2]; | |
| 2891 Tcl_IncrRefCount(*ppHook); | |
| 2892 } | |
| 2893 } | |
| 2894 | 3239 |
| 2895 sqlite3_update_hook(pDb->db, (pDb->pUpdateHook?DbUpdateHandler:0), pDb); | 3240 DbHookCmd(interp, pDb, (objc==3 ? objv[2] : 0), ppHook); |
| 2896 sqlite3_rollback_hook(pDb->db,(pDb->pRollbackHook?DbRollbackHandler:0),pDb); | |
| 2897 sqlite3_wal_hook(pDb->db,(pDb->pWalHook?DbWalHandler:0),pDb); | |
| 2898 | |
| 2899 break; | 3241 break; |
| 2900 } | 3242 } |
| 2901 | 3243 |
| 2902 /* $db version | 3244 /* $db version |
| 2903 ** | 3245 ** |
| 2904 ** Return the version string for this database. | 3246 ** Return the version string for this database. |
| 2905 */ | 3247 */ |
| 2906 case DB_VERSION: { | 3248 case DB_VERSION: { |
| 2907 Tcl_SetResult(interp, (char *)sqlite3_libversion(), TCL_STATIC); | 3249 Tcl_SetResult(interp, (char *)sqlite3_libversion(), TCL_STATIC); |
| 2908 break; | 3250 break; |
| 2909 } | 3251 } |
| 2910 | 3252 |
| 2911 | 3253 |
| 2912 } /* End of the SWITCH statement */ | 3254 } /* End of the SWITCH statement */ |
| 2913 return rc; | 3255 return rc; |
| 2914 } | 3256 } |
| 2915 | 3257 |
| 2916 #if SQLITE_TCL_NRE | 3258 #if SQLITE_TCL_NRE |
| 2917 /* | 3259 /* |
| 2918 ** Adaptor that provides an objCmd interface to the NRE-enabled | 3260 ** Adaptor that provides an objCmd interface to the NRE-enabled |
| 2919 ** interface implementation. | 3261 ** interface implementation. |
| 2920 */ | 3262 */ |
| 2921 static int DbObjCmdAdaptor( | 3263 static int SQLITE_TCLAPI DbObjCmdAdaptor( |
| 2922 void *cd, | 3264 void *cd, |
| 2923 Tcl_Interp *interp, | 3265 Tcl_Interp *interp, |
| 2924 int objc, | 3266 int objc, |
| 2925 Tcl_Obj *const*objv | 3267 Tcl_Obj *const*objv |
| 2926 ){ | 3268 ){ |
| 2927 return Tcl_NRCallObjProc(interp, DbObjCmd, cd, objc, objv); | 3269 return Tcl_NRCallObjProc(interp, DbObjCmd, cd, objc, objv); |
| 2928 } | 3270 } |
| 2929 #endif /* SQLITE_TCL_NRE */ | 3271 #endif /* SQLITE_TCL_NRE */ |
| 2930 | 3272 |
| 2931 /* | 3273 /* |
| 2932 ** sqlite3 DBNAME FILENAME ?-vfs VFSNAME? ?-key KEY? ?-readonly BOOLEAN? | 3274 ** sqlite3 DBNAME FILENAME ?-vfs VFSNAME? ?-key KEY? ?-readonly BOOLEAN? |
| 2933 ** ?-create BOOLEAN? ?-nomutex BOOLEAN? | 3275 ** ?-create BOOLEAN? ?-nomutex BOOLEAN? |
| 2934 ** | 3276 ** |
| 2935 ** This is the main Tcl command. When the "sqlite" Tcl command is | 3277 ** This is the main Tcl command. When the "sqlite" Tcl command is |
| 2936 ** invoked, this routine runs to process that command. | 3278 ** invoked, this routine runs to process that command. |
| 2937 ** | 3279 ** |
| 2938 ** The first argument, DBNAME, is an arbitrary name for a new | 3280 ** The first argument, DBNAME, is an arbitrary name for a new |
| 2939 ** database connection. This command creates a new command named | 3281 ** database connection. This command creates a new command named |
| 2940 ** DBNAME that is used to control that connection. The database | 3282 ** DBNAME that is used to control that connection. The database |
| 2941 ** connection is deleted when the DBNAME command is deleted. | 3283 ** connection is deleted when the DBNAME command is deleted. |
| 2942 ** | 3284 ** |
| 2943 ** The second argument is the name of the database file. | 3285 ** The second argument is the name of the database file. |
| 2944 ** | 3286 ** |
| 2945 */ | 3287 */ |
| 2946 static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ | 3288 static int SQLITE_TCLAPI DbMain( |
| 3289 void *cd, |
| 3290 Tcl_Interp *interp, |
| 3291 int objc, |
| 3292 Tcl_Obj *const*objv |
| 3293 ){ |
| 2947 SqliteDb *p; | 3294 SqliteDb *p; |
| 2948 const char *zArg; | 3295 const char *zArg; |
| 2949 char *zErrMsg; | 3296 char *zErrMsg; |
| 2950 int i; | 3297 int i; |
| 2951 const char *zFile; | 3298 const char *zFile; |
| 2952 const char *zVfs = 0; | 3299 const char *zVfs = 0; |
| 2953 int flags; | 3300 int flags; |
| 2954 Tcl_DString translatedFilename; | 3301 Tcl_DString translatedFilename; |
| 2955 #ifdef SQLITE_HAS_CODEC | 3302 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 2956 void *pKey = 0; | 3303 void *pKey = 0; |
| 2957 int nKey = 0; | 3304 int nKey = 0; |
| 2958 #endif | 3305 #endif |
| 2959 int rc; | 3306 int rc; |
| 2960 | 3307 |
| 2961 /* In normal use, each TCL interpreter runs in a single thread. So | 3308 /* In normal use, each TCL interpreter runs in a single thread. So |
| 2962 ** by default, we can turn of mutexing on SQLite database connections. | 3309 ** by default, we can turn of mutexing on SQLite database connections. |
| 2963 ** However, for testing purposes it is useful to have mutexes turned | 3310 ** However, for testing purposes it is useful to have mutexes turned |
| 2964 ** on. So, by default, mutexes default off. But if compiled with | 3311 ** on. So, by default, mutexes default off. But if compiled with |
| 2965 ** SQLITE_TCL_DEFAULT_FULLMUTEX then mutexes default on. | 3312 ** SQLITE_TCL_DEFAULT_FULLMUTEX then mutexes default on. |
| 2966 */ | 3313 */ |
| 2967 #ifdef SQLITE_TCL_DEFAULT_FULLMUTEX | 3314 #ifdef SQLITE_TCL_DEFAULT_FULLMUTEX |
| 2968 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX; | 3315 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX; |
| 2969 #else | 3316 #else |
| 2970 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX; | 3317 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX; |
| 2971 #endif | 3318 #endif |
| 2972 | 3319 |
| 2973 if( objc==2 ){ | 3320 if( objc==2 ){ |
| 2974 zArg = Tcl_GetStringFromObj(objv[1], 0); | 3321 zArg = Tcl_GetStringFromObj(objv[1], 0); |
| 2975 if( strcmp(zArg,"-version")==0 ){ | 3322 if( strcmp(zArg,"-version")==0 ){ |
| 2976 Tcl_AppendResult(interp,sqlite3_libversion(), (char*)0); | 3323 Tcl_AppendResult(interp,sqlite3_libversion(), (char*)0); |
| 2977 return TCL_OK; | 3324 return TCL_OK; |
| 2978 } | 3325 } |
| 3326 if( strcmp(zArg,"-sourceid")==0 ){ |
| 3327 Tcl_AppendResult(interp,sqlite3_sourceid(), (char*)0); |
| 3328 return TCL_OK; |
| 3329 } |
| 2979 if( strcmp(zArg,"-has-codec")==0 ){ | 3330 if( strcmp(zArg,"-has-codec")==0 ){ |
| 2980 #ifdef SQLITE_HAS_CODEC | 3331 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 2981 Tcl_AppendResult(interp,"1",(char*)0); | 3332 Tcl_AppendResult(interp,"1",(char*)0); |
| 2982 #else | 3333 #else |
| 2983 Tcl_AppendResult(interp,"0",(char*)0); | 3334 Tcl_AppendResult(interp,"0",(char*)0); |
| 2984 #endif | 3335 #endif |
| 2985 return TCL_OK; | 3336 return TCL_OK; |
| 2986 } | 3337 } |
| 2987 } | 3338 } |
| 2988 for(i=3; i+1<objc; i+=2){ | 3339 for(i=3; i+1<objc; i+=2){ |
| 2989 zArg = Tcl_GetString(objv[i]); | 3340 zArg = Tcl_GetString(objv[i]); |
| 2990 if( strcmp(zArg,"-key")==0 ){ | 3341 if( strcmp(zArg,"-key")==0 ){ |
| 2991 #ifdef SQLITE_HAS_CODEC | 3342 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 2992 pKey = Tcl_GetByteArrayFromObj(objv[i+1], &nKey); | 3343 pKey = Tcl_GetByteArrayFromObj(objv[i+1], &nKey); |
| 2993 #endif | 3344 #endif |
| 2994 }else if( strcmp(zArg, "-vfs")==0 ){ | 3345 }else if( strcmp(zArg, "-vfs")==0 ){ |
| 2995 zVfs = Tcl_GetString(objv[i+1]); | 3346 zVfs = Tcl_GetString(objv[i+1]); |
| 2996 }else if( strcmp(zArg, "-readonly")==0 ){ | 3347 }else if( strcmp(zArg, "-readonly")==0 ){ |
| 2997 int b; | 3348 int b; |
| 2998 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR; | 3349 if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR; |
| 2999 if( b ){ | 3350 if( b ){ |
| 3000 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); | 3351 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); |
| 3001 flags |= SQLITE_OPEN_READONLY; | 3352 flags |= SQLITE_OPEN_READONLY; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 flags |= SQLITE_OPEN_URI; | 3387 flags |= SQLITE_OPEN_URI; |
| 3037 }else{ | 3388 }else{ |
| 3038 flags &= ~SQLITE_OPEN_URI; | 3389 flags &= ~SQLITE_OPEN_URI; |
| 3039 } | 3390 } |
| 3040 }else{ | 3391 }else{ |
| 3041 Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0); | 3392 Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0); |
| 3042 return TCL_ERROR; | 3393 return TCL_ERROR; |
| 3043 } | 3394 } |
| 3044 } | 3395 } |
| 3045 if( objc<3 || (objc&1)!=1 ){ | 3396 if( objc<3 || (objc&1)!=1 ){ |
| 3046 Tcl_WrongNumArgs(interp, 1, objv, | 3397 Tcl_WrongNumArgs(interp, 1, objv, |
| 3047 "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?" | 3398 "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?" |
| 3048 " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" | 3399 " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" |
| 3049 #ifdef SQLITE_HAS_CODEC | 3400 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 3050 " ?-key CODECKEY?" | 3401 " ?-key CODECKEY?" |
| 3051 #endif | 3402 #endif |
| 3052 ); | 3403 ); |
| 3053 return TCL_ERROR; | 3404 return TCL_ERROR; |
| 3054 } | 3405 } |
| 3055 zErrMsg = 0; | 3406 zErrMsg = 0; |
| 3056 p = (SqliteDb*)Tcl_Alloc( sizeof(*p) ); | 3407 p = (SqliteDb*)Tcl_Alloc( sizeof(*p) ); |
| 3057 if( p==0 ){ | 3408 if( p==0 ){ |
| 3058 Tcl_SetResult(interp, (char *)"malloc failed", TCL_STATIC); | 3409 Tcl_SetResult(interp, (char *)"malloc failed", TCL_STATIC); |
| 3059 return TCL_ERROR; | 3410 return TCL_ERROR; |
| 3060 } | 3411 } |
| 3061 memset(p, 0, sizeof(*p)); | 3412 memset(p, 0, sizeof(*p)); |
| 3062 zFile = Tcl_GetStringFromObj(objv[2], 0); | 3413 zFile = Tcl_GetStringFromObj(objv[2], 0); |
| 3063 zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); | 3414 zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); |
| 3064 rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs); | 3415 rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs); |
| 3065 Tcl_DStringFree(&translatedFilename); | 3416 Tcl_DStringFree(&translatedFilename); |
| 3066 if( p->db ){ | 3417 if( p->db ){ |
| 3067 if( SQLITE_OK!=sqlite3_errcode(p->db) ){ | 3418 if( SQLITE_OK!=sqlite3_errcode(p->db) ){ |
| 3068 zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); | 3419 zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); |
| 3069 sqlite3_close(p->db); | 3420 sqlite3_close(p->db); |
| 3070 p->db = 0; | 3421 p->db = 0; |
| 3071 } | 3422 } |
| 3072 }else{ | 3423 }else{ |
| 3073 zErrMsg = sqlite3_mprintf("%s", sqlite3_errstr(rc)); | 3424 zErrMsg = sqlite3_mprintf("%s", sqlite3_errstr(rc)); |
| 3074 } | 3425 } |
| 3075 #ifdef SQLITE_HAS_CODEC | 3426 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
| 3076 if( p->db ){ | 3427 if( p->db ){ |
| 3077 sqlite3_key(p->db, pKey, nKey); | 3428 sqlite3_key(p->db, pKey, nKey); |
| 3078 } | 3429 } |
| 3079 #endif | 3430 #endif |
| 3080 if( p->db==0 ){ | 3431 if( p->db==0 ){ |
| 3081 Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE); | 3432 Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE); |
| 3082 Tcl_Free((char*)p); | 3433 Tcl_Free((char*)p); |
| 3083 sqlite3_free(zErrMsg); | 3434 sqlite3_free(zErrMsg); |
| 3084 return TCL_ERROR; | 3435 return TCL_ERROR; |
| 3085 } | 3436 } |
| 3086 p->maxStmt = NUM_PREPARED_STMTS; | 3437 p->maxStmt = NUM_PREPARED_STMTS; |
| 3438 p->openFlags = flags & SQLITE_OPEN_URI; |
| 3087 p->interp = interp; | 3439 p->interp = interp; |
| 3088 zArg = Tcl_GetStringFromObj(objv[1], 0); | 3440 zArg = Tcl_GetStringFromObj(objv[1], 0); |
| 3089 if( DbUseNre() ){ | 3441 if( DbUseNre() ){ |
| 3090 Tcl_NRCreateCommand(interp, zArg, DbObjCmdAdaptor, DbObjCmd, | 3442 Tcl_NRCreateCommand(interp, zArg, DbObjCmdAdaptor, DbObjCmd, |
| 3091 (char*)p, DbDeleteCmd); | 3443 (char*)p, DbDeleteCmd); |
| 3092 }else{ | 3444 }else{ |
| 3093 Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd); | 3445 Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd); |
| 3094 } | 3446 } |
| 3095 return TCL_OK; | 3447 return TCL_OK; |
| 3096 } | 3448 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3136 #endif | 3488 #endif |
| 3137 rc = Tcl_PkgProvide(interp, "sqlite3", PACKAGE_VERSION); | 3489 rc = Tcl_PkgProvide(interp, "sqlite3", PACKAGE_VERSION); |
| 3138 } | 3490 } |
| 3139 return rc; | 3491 return rc; |
| 3140 } | 3492 } |
| 3141 EXTERN int Tclsqlite3_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); } | 3493 EXTERN int Tclsqlite3_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); } |
| 3142 EXTERN int Sqlite3_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } | 3494 EXTERN int Sqlite3_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } |
| 3143 EXTERN int Tclsqlite3_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } | 3495 EXTERN int Tclsqlite3_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } |
| 3144 | 3496 |
| 3145 /* Because it accesses the file-system and uses persistent state, SQLite | 3497 /* Because it accesses the file-system and uses persistent state, SQLite |
| 3146 ** is not considered appropriate for safe interpreters. Hence, we deliberately | 3498 ** is not considered appropriate for safe interpreters. Hence, we cause |
| 3147 ** omit the _SafeInit() interfaces. | 3499 ** the _SafeInit() interfaces return TCL_ERROR. |
| 3148 */ | 3500 */ |
| 3501 EXTERN int Sqlite3_SafeInit(Tcl_Interp *interp){ return TCL_ERROR; } |
| 3502 EXTERN int Sqlite3_SafeUnload(Tcl_Interp *interp, int flags){return TCL_ERROR;} |
| 3503 |
| 3504 |
| 3149 | 3505 |
| 3150 #ifndef SQLITE_3_SUFFIX_ONLY | 3506 #ifndef SQLITE_3_SUFFIX_ONLY |
| 3151 int Sqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); } | 3507 int Sqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); } |
| 3152 int Tclsqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); } | 3508 int Tclsqlite_Init(Tcl_Interp *interp){ return Sqlite3_Init(interp); } |
| 3153 int Sqlite_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } | 3509 int Sqlite_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } |
| 3154 int Tclsqlite_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } | 3510 int Tclsqlite_Unload(Tcl_Interp *interp, int flags){ return TCL_OK; } |
| 3155 #endif | 3511 #endif |
| 3156 | 3512 |
| 3157 #ifdef TCLSH | 3513 #ifdef TCLSH |
| 3158 /***************************************************************************** | 3514 /***************************************************************************** |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3323 ctx->buf[2] = 0x98badcfe; | 3679 ctx->buf[2] = 0x98badcfe; |
| 3324 ctx->buf[3] = 0x10325476; | 3680 ctx->buf[3] = 0x10325476; |
| 3325 ctx->bits[0] = 0; | 3681 ctx->bits[0] = 0; |
| 3326 ctx->bits[1] = 0; | 3682 ctx->bits[1] = 0; |
| 3327 } | 3683 } |
| 3328 | 3684 |
| 3329 /* | 3685 /* |
| 3330 * Update context to reflect the concatenation of another buffer full | 3686 * Update context to reflect the concatenation of another buffer full |
| 3331 * of bytes. | 3687 * of bytes. |
| 3332 */ | 3688 */ |
| 3333 static | 3689 static |
| 3334 void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len){ | 3690 void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len){ |
| 3335 uint32 t; | 3691 uint32 t; |
| 3336 | 3692 |
| 3337 /* Update bitcount */ | 3693 /* Update bitcount */ |
| 3338 | 3694 |
| 3339 t = ctx->bits[0]; | 3695 t = ctx->bits[0]; |
| 3340 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t) | 3696 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t) |
| 3341 ctx->bits[1]++; /* Carry from low to high */ | 3697 ctx->bits[1]++; /* Carry from low to high */ |
| 3342 ctx->bits[1] += len >> 29; | 3698 ctx->bits[1] += len >> 29; |
| 3343 | 3699 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3369 buf += 64; | 3725 buf += 64; |
| 3370 len -= 64; | 3726 len -= 64; |
| 3371 } | 3727 } |
| 3372 | 3728 |
| 3373 /* Handle any remaining bytes of data. */ | 3729 /* Handle any remaining bytes of data. */ |
| 3374 | 3730 |
| 3375 memcpy(ctx->in, buf, len); | 3731 memcpy(ctx->in, buf, len); |
| 3376 } | 3732 } |
| 3377 | 3733 |
| 3378 /* | 3734 /* |
| 3379 * Final wrapup - pad to 64-byte boundary with the bit pattern | 3735 * Final wrapup - pad to 64-byte boundary with the bit pattern |
| 3380 * 1 0* (64-bit count of bits processed, MSB-first) | 3736 * 1 0* (64-bit count of bits processed, MSB-first) |
| 3381 */ | 3737 */ |
| 3382 static void MD5Final(unsigned char digest[16], MD5Context *ctx){ | 3738 static void MD5Final(unsigned char digest[16], MD5Context *ctx){ |
| 3383 unsigned count; | 3739 unsigned count; |
| 3384 unsigned char *p; | 3740 unsigned char *p; |
| 3385 | 3741 |
| 3386 /* Compute number of bytes mod 64 */ | 3742 /* Compute number of bytes mod 64 */ |
| 3387 count = (ctx->bits[0] >> 3) & 0x3F; | 3743 count = (ctx->bits[0] >> 3) & 0x3F; |
| 3388 | 3744 |
| 3389 /* Set the first char of padding to 0x80. This is safe since there is | 3745 /* Set the first char of padding to 0x80. This is safe since there is |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3445 x = digest[i]*256 + digest[i+1]; | 3801 x = digest[i]*256 + digest[i+1]; |
| 3446 if( i>0 ) zDigest[j++] = '-'; | 3802 if( i>0 ) zDigest[j++] = '-'; |
| 3447 sqlite3_snprintf(50-j, &zDigest[j], "%05u", x); | 3803 sqlite3_snprintf(50-j, &zDigest[j], "%05u", x); |
| 3448 j += 5; | 3804 j += 5; |
| 3449 } | 3805 } |
| 3450 zDigest[j] = 0; | 3806 zDigest[j] = 0; |
| 3451 } | 3807 } |
| 3452 | 3808 |
| 3453 /* | 3809 /* |
| 3454 ** A TCL command for md5. The argument is the text to be hashed. The | 3810 ** A TCL command for md5. The argument is the text to be hashed. The |
| 3455 ** Result is the hash in base64. | 3811 ** Result is the hash in base64. |
| 3456 */ | 3812 */ |
| 3457 static int md5_cmd(void*cd, Tcl_Interp *interp, int argc, const char **argv){ | 3813 static int SQLITE_TCLAPI md5_cmd( |
| 3814 void*cd, |
| 3815 Tcl_Interp *interp, |
| 3816 int argc, |
| 3817 const char **argv |
| 3818 ){ |
| 3458 MD5Context ctx; | 3819 MD5Context ctx; |
| 3459 unsigned char digest[16]; | 3820 unsigned char digest[16]; |
| 3460 char zBuf[50]; | 3821 char zBuf[50]; |
| 3461 void (*converter)(unsigned char*, char*); | 3822 void (*converter)(unsigned char*, char*); |
| 3462 | 3823 |
| 3463 if( argc!=2 ){ | 3824 if( argc!=2 ){ |
| 3464 Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0], | 3825 Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0], |
| 3465 " TEXT\"", (char*)0); | 3826 " TEXT\"", (char*)0); |
| 3466 return TCL_ERROR; | 3827 return TCL_ERROR; |
| 3467 } | 3828 } |
| 3468 MD5Init(&ctx); | 3829 MD5Init(&ctx); |
| 3469 MD5Update(&ctx, (unsigned char*)argv[1], (unsigned)strlen(argv[1])); | 3830 MD5Update(&ctx, (unsigned char*)argv[1], (unsigned)strlen(argv[1])); |
| 3470 MD5Final(digest, &ctx); | 3831 MD5Final(digest, &ctx); |
| 3471 converter = (void(*)(unsigned char*,char*))cd; | 3832 converter = (void(*)(unsigned char*,char*))cd; |
| 3472 converter(digest, zBuf); | 3833 converter(digest, zBuf); |
| 3473 Tcl_AppendResult(interp, zBuf, (char*)0); | 3834 Tcl_AppendResult(interp, zBuf, (char*)0); |
| 3474 return TCL_OK; | 3835 return TCL_OK; |
| 3475 } | 3836 } |
| 3476 | 3837 |
| 3477 /* | 3838 /* |
| 3478 ** A TCL command to take the md5 hash of a file. The argument is the | 3839 ** A TCL command to take the md5 hash of a file. The argument is the |
| 3479 ** name of the file. | 3840 ** name of the file. |
| 3480 */ | 3841 */ |
| 3481 static int md5file_cmd(void*cd, Tcl_Interp*interp, int argc, const char **argv){ | 3842 static int SQLITE_TCLAPI md5file_cmd( |
| 3843 void*cd, |
| 3844 Tcl_Interp *interp, |
| 3845 int argc, |
| 3846 const char **argv |
| 3847 ){ |
| 3482 FILE *in; | 3848 FILE *in; |
| 3483 MD5Context ctx; | 3849 MD5Context ctx; |
| 3484 void (*converter)(unsigned char*, char*); | 3850 void (*converter)(unsigned char*, char*); |
| 3485 unsigned char digest[16]; | 3851 unsigned char digest[16]; |
| 3486 char zBuf[10240]; | 3852 char zBuf[10240]; |
| 3487 | 3853 |
| 3488 if( argc!=2 ){ | 3854 if( argc!=2 ){ |
| 3489 Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0], | 3855 Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0], |
| 3490 " FILENAME\"", (char*)0); | 3856 " FILENAME\"", (char*)0); |
| 3491 return TCL_ERROR; | 3857 return TCL_ERROR; |
| 3492 } | 3858 } |
| 3493 in = fopen(argv[1],"rb"); | 3859 in = fopen(argv[1],"rb"); |
| 3494 if( in==0 ){ | 3860 if( in==0 ){ |
| 3495 Tcl_AppendResult(interp,"unable to open file \"", argv[1], | 3861 Tcl_AppendResult(interp,"unable to open file \"", argv[1], |
| 3496 "\" for reading", (char*)0); | 3862 "\" for reading", (char*)0); |
| 3497 return TCL_ERROR; | 3863 return TCL_ERROR; |
| 3498 } | 3864 } |
| 3499 MD5Init(&ctx); | 3865 MD5Init(&ctx); |
| 3500 for(;;){ | 3866 for(;;){ |
| 3501 int n; | 3867 int n; |
| 3502 n = (int)fread(zBuf, 1, sizeof(zBuf), in); | 3868 n = (int)fread(zBuf, 1, sizeof(zBuf), in); |
| 3503 if( n<=0 ) break; | 3869 if( n<=0 ) break; |
| 3504 MD5Update(&ctx, (unsigned char*)zBuf, (unsigned)n); | 3870 MD5Update(&ctx, (unsigned char*)zBuf, (unsigned)n); |
| 3505 } | 3871 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3551 } | 3917 } |
| 3552 static void md5finalize(sqlite3_context *context){ | 3918 static void md5finalize(sqlite3_context *context){ |
| 3553 MD5Context *p; | 3919 MD5Context *p; |
| 3554 unsigned char digest[16]; | 3920 unsigned char digest[16]; |
| 3555 char zBuf[33]; | 3921 char zBuf[33]; |
| 3556 p = sqlite3_aggregate_context(context, sizeof(*p)); | 3922 p = sqlite3_aggregate_context(context, sizeof(*p)); |
| 3557 MD5Final(digest,p); | 3923 MD5Final(digest,p); |
| 3558 MD5DigestToBase16(digest, zBuf); | 3924 MD5DigestToBase16(digest, zBuf); |
| 3559 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); | 3925 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 3560 } | 3926 } |
| 3561 int Md5_Register(sqlite3 *db){ | 3927 int Md5_Register( |
| 3562 int rc = sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0, | 3928 sqlite3 *db, |
| 3929 char **pzErrMsg, |
| 3930 const sqlite3_api_routines *pThunk |
| 3931 ){ |
| 3932 int rc = sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0, |
| 3563 md5step, md5finalize); | 3933 md5step, md5finalize); |
| 3564 sqlite3_overload_function(db, "md5sum", -1); /* To exercise this API */ | 3934 sqlite3_overload_function(db, "md5sum", -1); /* To exercise this API */ |
| 3565 return rc; | 3935 return rc; |
| 3566 } | 3936 } |
| 3567 #endif /* defined(SQLITE_TEST) */ | 3937 #endif /* defined(SQLITE_TEST) */ |
| 3568 | 3938 |
| 3569 | 3939 |
| 3570 /* | 3940 /* |
| 3571 ** If the macro TCLSH is one, then put in code this for the | 3941 ** If the macro TCLSH is one, then put in code this for the |
| 3572 ** "main" routine that will initialize Tcl and take input from | 3942 ** "main" routine that will initialize Tcl and take input from |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3599 ; | 3969 ; |
| 3600 return zMainloop; | 3970 return zMainloop; |
| 3601 } | 3971 } |
| 3602 #endif | 3972 #endif |
| 3603 #if TCLSH==2 | 3973 #if TCLSH==2 |
| 3604 static const char *tclsh_main_loop(void); | 3974 static const char *tclsh_main_loop(void); |
| 3605 #endif | 3975 #endif |
| 3606 | 3976 |
| 3607 #ifdef SQLITE_TEST | 3977 #ifdef SQLITE_TEST |
| 3608 static void init_all(Tcl_Interp *); | 3978 static void init_all(Tcl_Interp *); |
| 3609 static int init_all_cmd( | 3979 static int SQLITE_TCLAPI init_all_cmd( |
| 3610 ClientData cd, | 3980 ClientData cd, |
| 3611 Tcl_Interp *interp, | 3981 Tcl_Interp *interp, |
| 3612 int objc, | 3982 int objc, |
| 3613 Tcl_Obj *CONST objv[] | 3983 Tcl_Obj *CONST objv[] |
| 3614 ){ | 3984 ){ |
| 3615 | 3985 |
| 3616 Tcl_Interp *slave; | 3986 Tcl_Interp *slave; |
| 3617 if( objc!=2 ){ | 3987 if( objc!=2 ){ |
| 3618 Tcl_WrongNumArgs(interp, 1, objv, "SLAVE"); | 3988 Tcl_WrongNumArgs(interp, 1, objv, "SLAVE"); |
| 3619 return TCL_ERROR; | 3989 return TCL_ERROR; |
| 3620 } | 3990 } |
| 3621 | 3991 |
| 3622 slave = Tcl_GetSlave(interp, Tcl_GetString(objv[1])); | 3992 slave = Tcl_GetSlave(interp, Tcl_GetString(objv[1])); |
| 3623 if( !slave ){ | 3993 if( !slave ){ |
| 3624 return TCL_ERROR; | 3994 return TCL_ERROR; |
| 3625 } | 3995 } |
| 3626 | 3996 |
| 3627 init_all(slave); | 3997 init_all(slave); |
| 3628 return TCL_OK; | 3998 return TCL_OK; |
| 3629 } | 3999 } |
| 3630 | 4000 |
| 3631 /* | 4001 /* |
| 3632 ** Tclcmd: db_use_legacy_prepare DB BOOLEAN | 4002 ** Tclcmd: db_use_legacy_prepare DB BOOLEAN |
| 3633 ** | 4003 ** |
| 3634 ** The first argument to this command must be a database command created by | 4004 ** The first argument to this command must be a database command created by |
| 3635 ** [sqlite3]. If the second argument is true, then the handle is configured | 4005 ** [sqlite3]. If the second argument is true, then the handle is configured |
| 3636 ** to use the sqlite3_prepare_v2() function to prepare statements. If it | 4006 ** to use the sqlite3_prepare_v2() function to prepare statements. If it |
| 3637 ** is false, sqlite3_prepare(). | 4007 ** is false, sqlite3_prepare(). |
| 3638 */ | 4008 */ |
| 3639 static int db_use_legacy_prepare_cmd( | 4009 static int SQLITE_TCLAPI db_use_legacy_prepare_cmd( |
| 3640 ClientData cd, | 4010 ClientData cd, |
| 3641 Tcl_Interp *interp, | 4011 Tcl_Interp *interp, |
| 3642 int objc, | 4012 int objc, |
| 3643 Tcl_Obj *CONST objv[] | 4013 Tcl_Obj *CONST objv[] |
| 3644 ){ | 4014 ){ |
| 3645 Tcl_CmdInfo cmdInfo; | 4015 Tcl_CmdInfo cmdInfo; |
| 3646 SqliteDb *pDb; | 4016 SqliteDb *pDb; |
| 3647 int bPrepare; | 4017 int bPrepare; |
| 3648 | 4018 |
| 3649 if( objc!=3 ){ | 4019 if( objc!=3 ){ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3666 return TCL_OK; | 4036 return TCL_OK; |
| 3667 } | 4037 } |
| 3668 | 4038 |
| 3669 /* | 4039 /* |
| 3670 ** Tclcmd: db_last_stmt_ptr DB | 4040 ** Tclcmd: db_last_stmt_ptr DB |
| 3671 ** | 4041 ** |
| 3672 ** If the statement cache associated with database DB is not empty, | 4042 ** If the statement cache associated with database DB is not empty, |
| 3673 ** return the text representation of the most recently used statement | 4043 ** return the text representation of the most recently used statement |
| 3674 ** handle. | 4044 ** handle. |
| 3675 */ | 4045 */ |
| 3676 static int db_last_stmt_ptr( | 4046 static int SQLITE_TCLAPI db_last_stmt_ptr( |
| 3677 ClientData cd, | 4047 ClientData cd, |
| 3678 Tcl_Interp *interp, | 4048 Tcl_Interp *interp, |
| 3679 int objc, | 4049 int objc, |
| 3680 Tcl_Obj *CONST objv[] | 4050 Tcl_Obj *CONST objv[] |
| 3681 ){ | 4051 ){ |
| 3682 extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*); | 4052 extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*); |
| 3683 Tcl_CmdInfo cmdInfo; | 4053 Tcl_CmdInfo cmdInfo; |
| 3684 SqliteDb *pDb; | 4054 SqliteDb *pDb; |
| 3685 sqlite3_stmt *pStmt = 0; | 4055 sqlite3_stmt *pStmt = 0; |
| 3686 char zBuf[100]; | 4056 char zBuf[100]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3703 Tcl_SetResult(interp, zBuf, TCL_VOLATILE); | 4073 Tcl_SetResult(interp, zBuf, TCL_VOLATILE); |
| 3704 | 4074 |
| 3705 return TCL_OK; | 4075 return TCL_OK; |
| 3706 } | 4076 } |
| 3707 #endif /* SQLITE_TEST */ | 4077 #endif /* SQLITE_TEST */ |
| 3708 | 4078 |
| 3709 /* | 4079 /* |
| 3710 ** Configure the interpreter passed as the first argument to have access | 4080 ** Configure the interpreter passed as the first argument to have access |
| 3711 ** to the commands and linked variables that make up: | 4081 ** to the commands and linked variables that make up: |
| 3712 ** | 4082 ** |
| 3713 ** * the [sqlite3] extension itself, | 4083 ** * the [sqlite3] extension itself, |
| 3714 ** | 4084 ** |
| 3715 ** * If SQLITE_TCLMD5 or SQLITE_TEST is defined, the Md5 commands, and | 4085 ** * If SQLITE_TCLMD5 or SQLITE_TEST is defined, the Md5 commands, and |
| 3716 ** | 4086 ** |
| 3717 ** * If SQLITE_TEST is set, the various test interfaces used by the Tcl | 4087 ** * If SQLITE_TEST is set, the various test interfaces used by the Tcl |
| 3718 ** test suite. | 4088 ** test suite. |
| 3719 */ | 4089 */ |
| 3720 static void init_all(Tcl_Interp *interp){ | 4090 static void init_all(Tcl_Interp *interp){ |
| 3721 Sqlite3_Init(interp); | 4091 Sqlite3_Init(interp); |
| 3722 | 4092 |
| 3723 #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5) | 4093 #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3753 extern int SqlitetestOnefile_Init(); | 4123 extern int SqlitetestOnefile_Init(); |
| 3754 extern int SqlitetestOsinst_Init(Tcl_Interp*); | 4124 extern int SqlitetestOsinst_Init(Tcl_Interp*); |
| 3755 extern int Sqlitetestbackup_Init(Tcl_Interp*); | 4125 extern int Sqlitetestbackup_Init(Tcl_Interp*); |
| 3756 extern int Sqlitetestintarray_Init(Tcl_Interp*); | 4126 extern int Sqlitetestintarray_Init(Tcl_Interp*); |
| 3757 extern int Sqlitetestvfs_Init(Tcl_Interp *); | 4127 extern int Sqlitetestvfs_Init(Tcl_Interp *); |
| 3758 extern int Sqlitetestrtree_Init(Tcl_Interp*); | 4128 extern int Sqlitetestrtree_Init(Tcl_Interp*); |
| 3759 extern int Sqlitequota_Init(Tcl_Interp*); | 4129 extern int Sqlitequota_Init(Tcl_Interp*); |
| 3760 extern int Sqlitemultiplex_Init(Tcl_Interp*); | 4130 extern int Sqlitemultiplex_Init(Tcl_Interp*); |
| 3761 extern int SqliteSuperlock_Init(Tcl_Interp*); | 4131 extern int SqliteSuperlock_Init(Tcl_Interp*); |
| 3762 extern int SqlitetestSyscall_Init(Tcl_Interp*); | 4132 extern int SqlitetestSyscall_Init(Tcl_Interp*); |
| 4133 #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK) |
| 4134 extern int TestSession_Init(Tcl_Interp*); |
| 4135 #endif |
| 3763 extern int Fts5tcl_Init(Tcl_Interp *); | 4136 extern int Fts5tcl_Init(Tcl_Interp *); |
| 3764 extern int SqliteRbu_Init(Tcl_Interp*); | 4137 extern int SqliteRbu_Init(Tcl_Interp*); |
| 4138 extern int Sqlitetesttcl_Init(Tcl_Interp*); |
| 3765 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) | 4139 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) |
| 3766 extern int Sqlitetestfts3_Init(Tcl_Interp *interp); | 4140 extern int Sqlitetestfts3_Init(Tcl_Interp *interp); |
| 3767 #endif | 4141 #endif |
| 3768 | 4142 |
| 3769 #ifdef SQLITE_ENABLE_ZIPVFS | 4143 #ifdef SQLITE_ENABLE_ZIPVFS |
| 3770 extern int Zipvfs_Init(Tcl_Interp*); | 4144 extern int Zipvfs_Init(Tcl_Interp*); |
| 3771 Zipvfs_Init(interp); | 4145 Zipvfs_Init(interp); |
| 3772 #endif | 4146 #endif |
| 3773 | 4147 |
| 3774 Sqliteconfig_Init(interp); | 4148 Sqliteconfig_Init(interp); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3787 Sqlitetest_demovfs_Init(interp); | 4161 Sqlitetest_demovfs_Init(interp); |
| 3788 Sqlitetest_func_Init(interp); | 4162 Sqlitetest_func_Init(interp); |
| 3789 Sqlitetest_hexio_Init(interp); | 4163 Sqlitetest_hexio_Init(interp); |
| 3790 Sqlitetest_init_Init(interp); | 4164 Sqlitetest_init_Init(interp); |
| 3791 Sqlitetest_malloc_Init(interp); | 4165 Sqlitetest_malloc_Init(interp); |
| 3792 Sqlitetest_mutex_Init(interp); | 4166 Sqlitetest_mutex_Init(interp); |
| 3793 Sqlitetestschema_Init(interp); | 4167 Sqlitetestschema_Init(interp); |
| 3794 Sqlitetesttclvar_Init(interp); | 4168 Sqlitetesttclvar_Init(interp); |
| 3795 Sqlitetestfs_Init(interp); | 4169 Sqlitetestfs_Init(interp); |
| 3796 SqlitetestThread_Init(interp); | 4170 SqlitetestThread_Init(interp); |
| 3797 SqlitetestOnefile_Init(interp); | 4171 SqlitetestOnefile_Init(); |
| 3798 SqlitetestOsinst_Init(interp); | 4172 SqlitetestOsinst_Init(interp); |
| 3799 Sqlitetestbackup_Init(interp); | 4173 Sqlitetestbackup_Init(interp); |
| 3800 Sqlitetestintarray_Init(interp); | 4174 Sqlitetestintarray_Init(interp); |
| 3801 Sqlitetestvfs_Init(interp); | 4175 Sqlitetestvfs_Init(interp); |
| 3802 Sqlitetestrtree_Init(interp); | 4176 Sqlitetestrtree_Init(interp); |
| 3803 Sqlitequota_Init(interp); | 4177 Sqlitequota_Init(interp); |
| 3804 Sqlitemultiplex_Init(interp); | 4178 Sqlitemultiplex_Init(interp); |
| 3805 SqliteSuperlock_Init(interp); | 4179 SqliteSuperlock_Init(interp); |
| 3806 SqlitetestSyscall_Init(interp); | 4180 SqlitetestSyscall_Init(interp); |
| 4181 #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK) |
| 4182 TestSession_Init(interp); |
| 4183 #endif |
| 3807 Fts5tcl_Init(interp); | 4184 Fts5tcl_Init(interp); |
| 3808 SqliteRbu_Init(interp); | 4185 SqliteRbu_Init(interp); |
| 4186 Sqlitetesttcl_Init(interp); |
| 3809 | 4187 |
| 3810 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) | 4188 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) |
| 3811 Sqlitetestfts3_Init(interp); | 4189 Sqlitetestfts3_Init(interp); |
| 3812 #endif | 4190 #endif |
| 3813 | 4191 |
| 3814 Tcl_CreateObjCommand( | 4192 Tcl_CreateObjCommand( |
| 3815 interp, "load_testfixture_extensions", init_all_cmd, 0, 0 | 4193 interp, "load_testfixture_extensions", init_all_cmd, 0, 0 |
| 3816 ); | 4194 ); |
| 3817 Tcl_CreateObjCommand( | 4195 Tcl_CreateObjCommand( |
| 3818 interp, "db_use_legacy_prepare", db_use_legacy_prepare_cmd, 0, 0 | 4196 interp, "db_use_legacy_prepare", db_use_legacy_prepare_cmd, 0, 0 |
| 3819 ); | 4197 ); |
| 3820 Tcl_CreateObjCommand( | 4198 Tcl_CreateObjCommand( |
| 3821 interp, "db_last_stmt_ptr", db_last_stmt_ptr, 0, 0 | 4199 interp, "db_last_stmt_ptr", db_last_stmt_ptr, 0, 0 |
| 3822 ); | 4200 ); |
| 3823 | 4201 |
| 3824 #ifdef SQLITE_SSE | 4202 #ifdef SQLITE_SSE |
| 3825 Sqlitetestsse_Init(interp); | 4203 Sqlitetestsse_Init(interp); |
| 3826 #endif | 4204 #endif |
| 3827 } | 4205 } |
| 3828 #endif | 4206 #endif |
| 3829 } | 4207 } |
| 3830 | 4208 |
| 3831 /* Needed for the setrlimit() system call on unix */ | 4209 /* Needed for the setrlimit() system call on unix */ |
| 3832 #if defined(unix) | 4210 #if defined(unix) |
| 3833 #include <sys/resource.h> | 4211 #include <sys/resource.h> |
| 3834 #endif | 4212 #endif |
| 3835 | 4213 |
| 3836 #define TCLSH_MAIN main /* Needed to fake out mktclapp */ | 4214 #define TCLSH_MAIN main /* Needed to fake out mktclapp */ |
| 3837 int TCLSH_MAIN(int argc, char **argv){ | 4215 int SQLITE_CDECL TCLSH_MAIN(int argc, char **argv){ |
| 3838 Tcl_Interp *interp; | 4216 Tcl_Interp *interp; |
| 3839 | 4217 |
| 3840 #if !defined(_WIN32_WCE) | 4218 #if !defined(_WIN32_WCE) |
| 3841 if( getenv("BREAK") ){ | 4219 if( getenv("BREAK") ){ |
| 3842 fprintf(stderr, | 4220 fprintf(stderr, |
| 3843 "attach debugger to process %d and press any key to continue.\n", | 4221 "attach debugger to process %d and press any key to continue.\n", |
| 3844 GETPID()); | 4222 GETPID()); |
| 3845 fgetc(stdin); | 4223 fgetc(stdin); |
| 3846 } | 4224 } |
| 3847 #endif | 4225 #endif |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3888 fprintf(stderr,"%s: %s\n", *argv, zInfo); | 4266 fprintf(stderr,"%s: %s\n", *argv, zInfo); |
| 3889 return 1; | 4267 return 1; |
| 3890 } | 4268 } |
| 3891 } | 4269 } |
| 3892 if( TCLSH==2 || argc<=1 ){ | 4270 if( TCLSH==2 || argc<=1 ){ |
| 3893 Tcl_GlobalEval(interp, tclsh_main_loop()); | 4271 Tcl_GlobalEval(interp, tclsh_main_loop()); |
| 3894 } | 4272 } |
| 3895 return 0; | 4273 return 0; |
| 3896 } | 4274 } |
| 3897 #endif /* TCLSH */ | 4275 #endif /* TCLSH */ |
| OLD | NEW |