Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/tclsqlite.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 **
11 ************************************************************************* 11 *************************************************************************
12 ** A TCL Interface to SQLite. Append this file to sqlite3.c and 12 ** A TCL Interface to SQLite. Append this file to sqlite3.c and
13 ** compile the whole thing to build a TCL-enabled version of SQLite. 13 ** compile the whole thing to build a TCL-enabled version of SQLite.
14 ** 14 **
15 ** Compile-time options: 15 ** Compile-time options:
16 ** 16 **
17 ** -DTCLSH=1 Add a "main()" routine that works as a tclsh. 17 ** -DTCLSH=1 Add a "main()" routine that works as a tclsh.
18 ** 18 **
19 ** -DSQLITE_TCLMD5 When used in conjuction with -DTCLSH=1, add 19 ** -DSQLITE_TCLMD5 When used in conjuction with -DTCLSH=1, add
20 ** four new commands to the TCL interpreter for 20 ** four new commands to the TCL interpreter for
21 ** generating MD5 checksums: md5, md5file, 21 ** generating MD5 checksums: md5, md5file,
22 ** md5-10x8, and md5file-10x8. 22 ** md5-10x8, and md5file-10x8.
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
29 /*
30 ** If requested, include the SQLite compiler options file for MSVC.
31 */
32 #if defined(INCLUDE_MSVC_H)
33 #include "msvc.h"
34 #endif
35
28 #include "tcl.h" 36 #include "tcl.h"
29 #include <errno.h> 37 #include <errno.h>
30 38
31 /* 39 /*
32 ** Some additional include files are needed if this file is not 40 ** Some additional include files are needed if this file is not
33 ** appended to the amalgamation. 41 ** appended to the amalgamation.
34 */ 42 */
35 #ifndef SQLITE_AMALGAMATION 43 #ifndef SQLITE_AMALGAMATION
36 # include "sqlite3.h" 44 # include "sqlite3.h"
37 # include <stdlib.h> 45 # include <stdlib.h>
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 sqlite3 *db, 636 sqlite3 *db,
629 const char *zDb, 637 const char *zDb,
630 int nEntry 638 int nEntry
631 ){ 639 ){
632 int ret = SQLITE_OK; 640 int ret = SQLITE_OK;
633 Tcl_Obj *p; 641 Tcl_Obj *p;
634 SqliteDb *pDb = (SqliteDb*)clientData; 642 SqliteDb *pDb = (SqliteDb*)clientData;
635 Tcl_Interp *interp = pDb->interp; 643 Tcl_Interp *interp = pDb->interp;
636 assert(pDb->pWalHook); 644 assert(pDb->pWalHook);
637 645
646 assert( db==pDb->db );
638 p = Tcl_DuplicateObj(pDb->pWalHook); 647 p = Tcl_DuplicateObj(pDb->pWalHook);
639 Tcl_IncrRefCount(p); 648 Tcl_IncrRefCount(p);
640 Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1)); 649 Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1));
641 Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry)); 650 Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry));
642 if( TCL_OK!=Tcl_EvalObjEx(interp, p, 0) 651 if( TCL_OK!=Tcl_EvalObjEx(interp, p, 0)
643 || TCL_OK!=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &ret) 652 || TCL_OK!=Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &ret)
644 ){ 653 ){
645 Tcl_BackgroundError(interp); 654 Tcl_BackgroundError(interp);
646 } 655 }
647 Tcl_DecrRefCount(p); 656 Tcl_DecrRefCount(p);
648 657
649 return ret; 658 return ret;
650 } 659 }
651 660
652 #if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY) 661 #if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_UNLOCK_NOTIFY)
653 static void setTestUnlockNotifyVars(Tcl_Interp *interp, int iArg, int nArg){ 662 static void setTestUnlockNotifyVars(Tcl_Interp *interp, int iArg, int nArg){
654 char zBuf[64]; 663 char zBuf[64];
655 sprintf(zBuf, "%d", iArg); 664 sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", iArg);
656 Tcl_SetVar(interp, "sqlite_unlock_notify_arg", zBuf, TCL_GLOBAL_ONLY); 665 Tcl_SetVar(interp, "sqlite_unlock_notify_arg", zBuf, TCL_GLOBAL_ONLY);
657 sprintf(zBuf, "%d", nArg); 666 sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", nArg);
658 Tcl_SetVar(interp, "sqlite_unlock_notify_argcount", zBuf, TCL_GLOBAL_ONLY); 667 Tcl_SetVar(interp, "sqlite_unlock_notify_argcount", zBuf, TCL_GLOBAL_ONLY);
659 } 668 }
660 #else 669 #else
661 # define setTestUnlockNotifyVars(x,y,z) 670 # define setTestUnlockNotifyVars(x,y,z)
662 #endif 671 #endif
663 672
664 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY 673 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
665 static void DbUnlockNotify(void **apArg, int nArg){ 674 static void DbUnlockNotify(void **apArg, int nArg){
666 int i; 675 int i;
667 for(i=0; i<nArg; i++){ 676 for(i=0; i<nArg; i++){
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 ** If successful, TCL_OK is returned. Otherwise, TCL_ERROR is returned 1086 ** If successful, TCL_OK is returned. Otherwise, TCL_ERROR is returned
1078 ** and an error message loaded into interpreter pDb->interp. 1087 ** and an error message loaded into interpreter pDb->interp.
1079 */ 1088 */
1080 static int dbPrepareAndBind( 1089 static int dbPrepareAndBind(
1081 SqliteDb *pDb, /* Database object */ 1090 SqliteDb *pDb, /* Database object */
1082 char const *zIn, /* SQL to compile */ 1091 char const *zIn, /* SQL to compile */
1083 char const **pzOut, /* OUT: Pointer to next SQL statement */ 1092 char const **pzOut, /* OUT: Pointer to next SQL statement */
1084 SqlPreparedStmt **ppPreStmt /* OUT: Object used to cache statement */ 1093 SqlPreparedStmt **ppPreStmt /* OUT: Object used to cache statement */
1085 ){ 1094 ){
1086 const char *zSql = zIn; /* Pointer to first SQL statement in zIn */ 1095 const char *zSql = zIn; /* Pointer to first SQL statement in zIn */
1087 sqlite3_stmt *pStmt; /* Prepared statement object */ 1096 sqlite3_stmt *pStmt = 0; /* Prepared statement object */
1088 SqlPreparedStmt *pPreStmt; /* Pointer to cached statement */ 1097 SqlPreparedStmt *pPreStmt; /* Pointer to cached statement */
1089 int nSql; /* Length of zSql in bytes */ 1098 int nSql; /* Length of zSql in bytes */
1090 int nVar; /* Number of variables in statement */ 1099 int nVar = 0; /* Number of variables in statement */
1091 int iParm = 0; /* Next free entry in apParm */ 1100 int iParm = 0; /* Next free entry in apParm */
1092 char c; 1101 char c;
1093 int i; 1102 int i;
1094 Tcl_Interp *interp = pDb->interp; 1103 Tcl_Interp *interp = pDb->interp;
1095 1104
1096 *ppPreStmt = 0; 1105 *ppPreStmt = 0;
1097 1106
1098 /* Trim spaces from the start of zSql and calculate the remaining length. */ 1107 /* Trim spaces from the start of zSql and calculate the remaining length. */
1099 while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; } 1108 while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; }
1100 nSql = strlen30(zSql); 1109 nSql = strlen30(zSql);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 1184
1176 /* Bind values to parameters that begin with $ or : */ 1185 /* Bind values to parameters that begin with $ or : */
1177 for(i=1; i<=nVar; i++){ 1186 for(i=1; i<=nVar; i++){
1178 const char *zVar = sqlite3_bind_parameter_name(pStmt, i); 1187 const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
1179 if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){ 1188 if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){
1180 Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0); 1189 Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0);
1181 if( pVar ){ 1190 if( pVar ){
1182 int n; 1191 int n;
1183 u8 *data; 1192 u8 *data;
1184 const char *zType = (pVar->typePtr ? pVar->typePtr->name : ""); 1193 const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
1185 char c = zType[0]; 1194 c = zType[0];
1186 if( zVar[0]=='@' || 1195 if( zVar[0]=='@' ||
1187 (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){ 1196 (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){
1188 /* Load a BLOB type if the Tcl variable is a bytearray and 1197 /* Load a BLOB type if the Tcl variable is a bytearray and
1189 ** it has no string representation or the host 1198 ** it has no string representation or the host
1190 ** parameter name begins with "@". */ 1199 ** parameter name begins with "@". */
1191 data = Tcl_GetByteArrayFromObj(pVar, &n); 1200 data = Tcl_GetByteArrayFromObj(pVar, &n);
1192 sqlite3_bind_blob(pStmt, i, data, n, SQLITE_STATIC); 1201 sqlite3_bind_blob(pStmt, i, data, n, SQLITE_STATIC);
1193 Tcl_IncrRefCount(pVar); 1202 Tcl_IncrRefCount(pVar);
1194 pPreStmt->apParm[iParm++] = pVar; 1203 pPreStmt->apParm[iParm++] = pVar;
1195 }else if( c=='b' && strcmp(zType,"boolean")==0 ){ 1204 }else if( c=='b' && strcmp(zType,"boolean")==0 ){
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 Tcl_ListObjAppendElement(interp, pRet, dbEvalColumnValue(&sEval, i)); 2291 Tcl_ListObjAppendElement(interp, pRet, dbEvalColumnValue(&sEval, i));
2283 } 2292 }
2284 } 2293 }
2285 dbEvalFinalize(&sEval); 2294 dbEvalFinalize(&sEval);
2286 if( rc==TCL_BREAK ){ 2295 if( rc==TCL_BREAK ){
2287 Tcl_SetObjResult(interp, pRet); 2296 Tcl_SetObjResult(interp, pRet);
2288 rc = TCL_OK; 2297 rc = TCL_OK;
2289 } 2298 }
2290 Tcl_DecrRefCount(pRet); 2299 Tcl_DecrRefCount(pRet);
2291 }else{ 2300 }else{
2292 ClientData cd[2]; 2301 ClientData cd2[2];
2293 DbEvalContext *p; 2302 DbEvalContext *p;
2294 Tcl_Obj *pArray = 0; 2303 Tcl_Obj *pArray = 0;
2295 Tcl_Obj *pScript; 2304 Tcl_Obj *pScript;
2296 2305
2297 if( objc==5 && *(char *)Tcl_GetString(objv[3]) ){ 2306 if( objc==5 && *(char *)Tcl_GetString(objv[3]) ){
2298 pArray = objv[3]; 2307 pArray = objv[3];
2299 } 2308 }
2300 pScript = objv[objc-1]; 2309 pScript = objv[objc-1];
2301 Tcl_IncrRefCount(pScript); 2310 Tcl_IncrRefCount(pScript);
2302 2311
2303 p = (DbEvalContext *)Tcl_Alloc(sizeof(DbEvalContext)); 2312 p = (DbEvalContext *)Tcl_Alloc(sizeof(DbEvalContext));
2304 dbEvalInit(p, pDb, objv[2], pArray); 2313 dbEvalInit(p, pDb, objv[2], pArray);
2305 2314
2306 cd[0] = (void *)p; 2315 cd2[0] = (void *)p;
2307 cd[1] = (void *)pScript; 2316 cd2[1] = (void *)pScript;
2308 rc = DbEvalNextCmd(cd, interp, TCL_OK); 2317 rc = DbEvalNextCmd(cd2, interp, TCL_OK);
2309 } 2318 }
2310 break; 2319 break;
2311 } 2320 }
2312 2321
2313 /* 2322 /*
2314 ** $db function NAME [-argcount N] SCRIPT 2323 ** $db function NAME [-argcount N] [-deterministic] SCRIPT
2315 ** 2324 **
2316 ** Create a new SQL function called NAME. Whenever that function is 2325 ** Create a new SQL function called NAME. Whenever that function is
2317 ** called, invoke SCRIPT to evaluate the function. 2326 ** called, invoke SCRIPT to evaluate the function.
2318 */ 2327 */
2319 case DB_FUNCTION: { 2328 case DB_FUNCTION: {
2329 int flags = SQLITE_UTF8;
2320 SqlFunc *pFunc; 2330 SqlFunc *pFunc;
2321 Tcl_Obj *pScript; 2331 Tcl_Obj *pScript;
2322 char *zName; 2332 char *zName;
2323 int nArg = -1; 2333 int nArg = -1;
2324 if( objc==6 ){ 2334 int i;
2325 const char *z = Tcl_GetString(objv[3]); 2335 if( objc<4 ){
2336 Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT");
2337 return TCL_ERROR;
2338 }
2339 for(i=3; i<(objc-1); i++){
2340 const char *z = Tcl_GetString(objv[i]);
2326 int n = strlen30(z); 2341 int n = strlen30(z);
2327 if( n>2 && strncmp(z, "-argcount",n)==0 ){ 2342 if( n>2 && strncmp(z, "-argcount",n)==0 ){
2328 if( Tcl_GetIntFromObj(interp, objv[4], &nArg) ) return TCL_ERROR; 2343 if( i==(objc-2) ){
2344 Tcl_AppendResult(interp, "option requires an argument: ", z, 0);
2345 return TCL_ERROR;
2346 }
2347 if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR;
2329 if( nArg<0 ){ 2348 if( nArg<0 ){
2330 Tcl_AppendResult(interp, "number of arguments must be non-negative", 2349 Tcl_AppendResult(interp, "number of arguments must be non-negative",
2331 (char*)0); 2350 (char*)0);
2332 return TCL_ERROR; 2351 return TCL_ERROR;
2333 } 2352 }
2353 i++;
2354 }else
2355 if( n>2 && strncmp(z, "-deterministic",n)==0 ){
2356 flags |= SQLITE_DETERMINISTIC;
2357 }else{
2358 Tcl_AppendResult(interp, "bad option \"", z,
2359 "\": must be -argcount or -deterministic", 0
2360 );
2361 return TCL_ERROR;
2334 } 2362 }
2335 pScript = objv[5];
2336 }else if( objc!=4 ){
2337 Tcl_WrongNumArgs(interp, 2, objv, "NAME [-argcount N] SCRIPT");
2338 return TCL_ERROR;
2339 }else{
2340 pScript = objv[3];
2341 } 2363 }
2364
2365 pScript = objv[objc-1];
2342 zName = Tcl_GetStringFromObj(objv[2], 0); 2366 zName = Tcl_GetStringFromObj(objv[2], 0);
2343 pFunc = findSqlFunc(pDb, zName); 2367 pFunc = findSqlFunc(pDb, zName);
2344 if( pFunc==0 ) return TCL_ERROR; 2368 if( pFunc==0 ) return TCL_ERROR;
2345 if( pFunc->pScript ){ 2369 if( pFunc->pScript ){
2346 Tcl_DecrRefCount(pFunc->pScript); 2370 Tcl_DecrRefCount(pFunc->pScript);
2347 } 2371 }
2348 pFunc->pScript = pScript; 2372 pFunc->pScript = pScript;
2349 Tcl_IncrRefCount(pScript); 2373 Tcl_IncrRefCount(pScript);
2350 pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript); 2374 pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript);
2351 rc = sqlite3_create_function(pDb->db, zName, nArg, SQLITE_UTF8, 2375 rc = sqlite3_create_function(pDb->db, zName, nArg, flags,
2352 pFunc, tclSqlFunc, 0, 0); 2376 pFunc, tclSqlFunc, 0, 0);
2353 if( rc!=SQLITE_OK ){ 2377 if( rc!=SQLITE_OK ){
2354 rc = TCL_ERROR; 2378 rc = TCL_ERROR;
2355 Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE); 2379 Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE);
2356 } 2380 }
2357 break; 2381 break;
2358 } 2382 }
2359 2383
2360 /* 2384 /*
2361 ** $db incrblob ?-readonly? ?DB? TABLE COLUMN ROWID 2385 ** $db incrblob ?-readonly? ?DB? TABLE COLUMN ROWID
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 ** 3118 **
3095 ** This Tcl module contains only a single new Tcl command named "sqlite". 3119 ** This Tcl module contains only a single new Tcl command named "sqlite".
3096 ** (Hence there is no namespace. There is no point in using a namespace 3120 ** (Hence there is no namespace. There is no point in using a namespace
3097 ** if the extension only supplies one new name!) The "sqlite" command is 3121 ** if the extension only supplies one new name!) The "sqlite" command is
3098 ** used to open a new SQLite database. See the DbMain() routine above 3122 ** used to open a new SQLite database. See the DbMain() routine above
3099 ** for additional information. 3123 ** for additional information.
3100 ** 3124 **
3101 ** The EXTERN macros are required by TCL in order to work on windows. 3125 ** The EXTERN macros are required by TCL in order to work on windows.
3102 */ 3126 */
3103 EXTERN int Sqlite3_Init(Tcl_Interp *interp){ 3127 EXTERN int Sqlite3_Init(Tcl_Interp *interp){
3104 int rc = Tcl_InitStubs(interp, "8.4", 0)==0 ? TCL_ERROR : TCL_OK; 3128 int rc = Tcl_InitStubs(interp, "8.4", 0) ? TCL_OK : TCL_ERROR;
3105 if( rc==TCL_OK ){ 3129 if( rc==TCL_OK ){
3106 Tcl_CreateObjCommand(interp, "sqlite3", (Tcl_ObjCmdProc*)DbMain, 0, 0); 3130 Tcl_CreateObjCommand(interp, "sqlite3", (Tcl_ObjCmdProc*)DbMain, 0, 0);
3107 #ifndef SQLITE_3_SUFFIX_ONLY 3131 #ifndef SQLITE_3_SUFFIX_ONLY
3108 /* The "sqlite" alias is undocumented. It is here only to support 3132 /* The "sqlite" alias is undocumented. It is here only to support
3109 ** legacy scripts. All new scripts should use only the "sqlite3" 3133 ** legacy scripts. All new scripts should use only the "sqlite3"
3110 ** command. */ 3134 ** command. */
3111 Tcl_CreateObjCommand(interp, "sqlite", (Tcl_ObjCmdProc*)DbMain, 0, 0); 3135 Tcl_CreateObjCommand(interp, "sqlite", (Tcl_ObjCmdProc*)DbMain, 0, 0);
3112 #endif 3136 #endif
3113 rc = Tcl_PkgProvide(interp, "sqlite3", PACKAGE_VERSION); 3137 rc = Tcl_PkgProvide(interp, "sqlite3", PACKAGE_VERSION);
3114 } 3138 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
3413 ** Convert a 128-bit MD5 digest into sequency of eight 5-digit integers 3437 ** Convert a 128-bit MD5 digest into sequency of eight 5-digit integers
3414 ** each representing 16 bits of the digest and separated from each 3438 ** each representing 16 bits of the digest and separated from each
3415 ** other by a "-" character. 3439 ** other by a "-" character.
3416 */ 3440 */
3417 static void MD5DigestToBase10x8(unsigned char digest[16], char zDigest[50]){ 3441 static void MD5DigestToBase10x8(unsigned char digest[16], char zDigest[50]){
3418 int i, j; 3442 int i, j;
3419 unsigned int x; 3443 unsigned int x;
3420 for(i=j=0; i<16; i+=2){ 3444 for(i=j=0; i<16; i+=2){
3421 x = digest[i]*256 + digest[i+1]; 3445 x = digest[i]*256 + digest[i+1];
3422 if( i>0 ) zDigest[j++] = '-'; 3446 if( i>0 ) zDigest[j++] = '-';
3423 sprintf(&zDigest[j], "%05u", x); 3447 sqlite3_snprintf(50-j, &zDigest[j], "%05u", x);
3424 j += 5; 3448 j += 5;
3425 } 3449 }
3426 zDigest[j] = 0; 3450 zDigest[j] = 0;
3427 } 3451 }
3428 3452
3429 /* 3453 /*
3430 ** A TCL command for md5. The argument is the text to be hashed. The 3454 ** A TCL command for md5. The argument is the text to be hashed. The
3431 ** Result is the hash in base64. 3455 ** Result is the hash in base64.
3432 */ 3456 */
3433 static int md5_cmd(void*cd, Tcl_Interp *interp, int argc, const char **argv){ 3457 static int md5_cmd(void*cd, Tcl_Interp *interp, int argc, const char **argv){
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 pDb = (SqliteDb*)cmdInfo.objClientData; 3658 pDb = (SqliteDb*)cmdInfo.objClientData;
3635 if( Tcl_GetBooleanFromObj(interp, objv[2], &bPrepare) ){ 3659 if( Tcl_GetBooleanFromObj(interp, objv[2], &bPrepare) ){
3636 return TCL_ERROR; 3660 return TCL_ERROR;
3637 } 3661 }
3638 3662
3639 pDb->bLegacyPrepare = bPrepare; 3663 pDb->bLegacyPrepare = bPrepare;
3640 3664
3641 Tcl_ResetResult(interp); 3665 Tcl_ResetResult(interp);
3642 return TCL_OK; 3666 return TCL_OK;
3643 } 3667 }
3644 #endif 3668
3669 /*
3670 ** Tclcmd: db_last_stmt_ptr DB
3671 **
3672 ** If the statement cache associated with database DB is not empty,
3673 ** return the text representation of the most recently used statement
3674 ** handle.
3675 */
3676 static int db_last_stmt_ptr(
3677 ClientData cd,
3678 Tcl_Interp *interp,
3679 int objc,
3680 Tcl_Obj *CONST objv[]
3681 ){
3682 extern int sqlite3TestMakePointerStr(Tcl_Interp*, char*, void*);
3683 Tcl_CmdInfo cmdInfo;
3684 SqliteDb *pDb;
3685 sqlite3_stmt *pStmt = 0;
3686 char zBuf[100];
3687
3688 if( objc!=2 ){
3689 Tcl_WrongNumArgs(interp, 1, objv, "DB");
3690 return TCL_ERROR;
3691 }
3692
3693 if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){
3694 Tcl_AppendResult(interp, "no such db: ", Tcl_GetString(objv[1]), (char*)0);
3695 return TCL_ERROR;
3696 }
3697 pDb = (SqliteDb*)cmdInfo.objClientData;
3698
3699 if( pDb->stmtList ) pStmt = pDb->stmtList->pStmt;
3700 if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ){
3701 return TCL_ERROR;
3702 }
3703 Tcl_SetResult(interp, zBuf, TCL_VOLATILE);
3704
3705 return TCL_OK;
3706 }
3707 #endif /* SQLITE_TEST */
3645 3708
3646 /* 3709 /*
3647 ** Configure the interpreter passed as the first argument to have access 3710 ** Configure the interpreter passed as the first argument to have access
3648 ** to the commands and linked variables that make up: 3711 ** to the commands and linked variables that make up:
3649 ** 3712 **
3650 ** * the [sqlite3] extension itself, 3713 ** * the [sqlite3] extension itself,
3651 ** 3714 **
3652 ** * If SQLITE_TCLMD5 or SQLITE_TEST is defined, the Md5 commands, and 3715 ** * If SQLITE_TCLMD5 or SQLITE_TEST is defined, the Md5 commands, and
3653 ** 3716 **
3654 ** * If SQLITE_TEST is set, the various test interfaces used by the Tcl 3717 ** * If SQLITE_TEST is set, the various test interfaces used by the Tcl
3655 ** test suite. 3718 ** test suite.
3656 */ 3719 */
3657 static void init_all(Tcl_Interp *interp){ 3720 static void init_all(Tcl_Interp *interp){
3658 Sqlite3_Init(interp); 3721 Sqlite3_Init(interp);
3659 3722
3660 #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5) 3723 #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5)
3661 Md5_Init(interp); 3724 Md5_Init(interp);
3662 #endif 3725 #endif
3663 3726
3664 /* Install the [register_dbstat_vtab] command to access the implementation
3665 ** of virtual table dbstat (source file test_stat.c). This command is
3666 ** required for testfixture and sqlite3_analyzer, but not by the production
3667 ** Tcl extension. */
3668 #if defined(SQLITE_TEST) || TCLSH==2
3669 {
3670 extern int SqlitetestStat_Init(Tcl_Interp*);
3671 SqlitetestStat_Init(interp);
3672 }
3673 #endif
3674
3675 #ifdef SQLITE_TEST 3727 #ifdef SQLITE_TEST
3676 { 3728 {
3677 extern int Sqliteconfig_Init(Tcl_Interp*); 3729 extern int Sqliteconfig_Init(Tcl_Interp*);
3678 extern int Sqlitetest1_Init(Tcl_Interp*); 3730 extern int Sqlitetest1_Init(Tcl_Interp*);
3679 extern int Sqlitetest2_Init(Tcl_Interp*); 3731 extern int Sqlitetest2_Init(Tcl_Interp*);
3680 extern int Sqlitetest3_Init(Tcl_Interp*); 3732 extern int Sqlitetest3_Init(Tcl_Interp*);
3681 extern int Sqlitetest4_Init(Tcl_Interp*); 3733 extern int Sqlitetest4_Init(Tcl_Interp*);
3682 extern int Sqlitetest5_Init(Tcl_Interp*); 3734 extern int Sqlitetest5_Init(Tcl_Interp*);
3683 extern int Sqlitetest6_Init(Tcl_Interp*); 3735 extern int Sqlitetest6_Init(Tcl_Interp*);
3684 extern int Sqlitetest7_Init(Tcl_Interp*); 3736 extern int Sqlitetest7_Init(Tcl_Interp*);
3685 extern int Sqlitetest8_Init(Tcl_Interp*); 3737 extern int Sqlitetest8_Init(Tcl_Interp*);
3686 extern int Sqlitetest9_Init(Tcl_Interp*); 3738 extern int Sqlitetest9_Init(Tcl_Interp*);
3687 extern int Sqlitetestasync_Init(Tcl_Interp*); 3739 extern int Sqlitetestasync_Init(Tcl_Interp*);
3688 extern int Sqlitetest_autoext_Init(Tcl_Interp*); 3740 extern int Sqlitetest_autoext_Init(Tcl_Interp*);
3741 extern int Sqlitetest_blob_Init(Tcl_Interp*);
3689 extern int Sqlitetest_demovfs_Init(Tcl_Interp *); 3742 extern int Sqlitetest_demovfs_Init(Tcl_Interp *);
3690 extern int Sqlitetest_func_Init(Tcl_Interp*); 3743 extern int Sqlitetest_func_Init(Tcl_Interp*);
3691 extern int Sqlitetest_hexio_Init(Tcl_Interp*); 3744 extern int Sqlitetest_hexio_Init(Tcl_Interp*);
3692 extern int Sqlitetest_init_Init(Tcl_Interp*); 3745 extern int Sqlitetest_init_Init(Tcl_Interp*);
3693 extern int Sqlitetest_malloc_Init(Tcl_Interp*); 3746 extern int Sqlitetest_malloc_Init(Tcl_Interp*);
3694 extern int Sqlitetest_mutex_Init(Tcl_Interp*); 3747 extern int Sqlitetest_mutex_Init(Tcl_Interp*);
3695 extern int Sqlitetestschema_Init(Tcl_Interp*); 3748 extern int Sqlitetestschema_Init(Tcl_Interp*);
3696 extern int Sqlitetestsse_Init(Tcl_Interp*); 3749 extern int Sqlitetestsse_Init(Tcl_Interp*);
3697 extern int Sqlitetesttclvar_Init(Tcl_Interp*); 3750 extern int Sqlitetesttclvar_Init(Tcl_Interp*);
3698 extern int Sqlitetestfs_Init(Tcl_Interp*); 3751 extern int Sqlitetestfs_Init(Tcl_Interp*);
3699 extern int SqlitetestThread_Init(Tcl_Interp*); 3752 extern int SqlitetestThread_Init(Tcl_Interp*);
3700 extern int SqlitetestOnefile_Init(); 3753 extern int SqlitetestOnefile_Init();
3701 extern int SqlitetestOsinst_Init(Tcl_Interp*); 3754 extern int SqlitetestOsinst_Init(Tcl_Interp*);
3702 extern int Sqlitetestbackup_Init(Tcl_Interp*); 3755 extern int Sqlitetestbackup_Init(Tcl_Interp*);
3703 extern int Sqlitetestintarray_Init(Tcl_Interp*); 3756 extern int Sqlitetestintarray_Init(Tcl_Interp*);
3704 extern int Sqlitetestvfs_Init(Tcl_Interp *); 3757 extern int Sqlitetestvfs_Init(Tcl_Interp *);
3705 extern int Sqlitetestrtree_Init(Tcl_Interp*); 3758 extern int Sqlitetestrtree_Init(Tcl_Interp*);
3706 extern int Sqlitequota_Init(Tcl_Interp*); 3759 extern int Sqlitequota_Init(Tcl_Interp*);
3707 extern int Sqlitemultiplex_Init(Tcl_Interp*); 3760 extern int Sqlitemultiplex_Init(Tcl_Interp*);
3708 extern int SqliteSuperlock_Init(Tcl_Interp*); 3761 extern int SqliteSuperlock_Init(Tcl_Interp*);
3709 extern int SqlitetestSyscall_Init(Tcl_Interp*); 3762 extern int SqlitetestSyscall_Init(Tcl_Interp*);
3710 3763 extern int Fts5tcl_Init(Tcl_Interp *);
3764 extern int SqliteRbu_Init(Tcl_Interp*);
3711 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 3765 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
3712 extern int Sqlitetestfts3_Init(Tcl_Interp *interp); 3766 extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
3713 #endif 3767 #endif
3714 3768
3715 #ifdef SQLITE_ENABLE_ZIPVFS 3769 #ifdef SQLITE_ENABLE_ZIPVFS
3716 extern int Zipvfs_Init(Tcl_Interp*); 3770 extern int Zipvfs_Init(Tcl_Interp*);
3717 Zipvfs_Init(interp); 3771 Zipvfs_Init(interp);
3718 #endif 3772 #endif
3719 3773
3720 Sqliteconfig_Init(interp); 3774 Sqliteconfig_Init(interp);
3721 Sqlitetest1_Init(interp); 3775 Sqlitetest1_Init(interp);
3722 Sqlitetest2_Init(interp); 3776 Sqlitetest2_Init(interp);
3723 Sqlitetest3_Init(interp); 3777 Sqlitetest3_Init(interp);
3724 Sqlitetest4_Init(interp); 3778 Sqlitetest4_Init(interp);
3725 Sqlitetest5_Init(interp); 3779 Sqlitetest5_Init(interp);
3726 Sqlitetest6_Init(interp); 3780 Sqlitetest6_Init(interp);
3727 Sqlitetest7_Init(interp); 3781 Sqlitetest7_Init(interp);
3728 Sqlitetest8_Init(interp); 3782 Sqlitetest8_Init(interp);
3729 Sqlitetest9_Init(interp); 3783 Sqlitetest9_Init(interp);
3730 Sqlitetestasync_Init(interp); 3784 Sqlitetestasync_Init(interp);
3731 Sqlitetest_autoext_Init(interp); 3785 Sqlitetest_autoext_Init(interp);
3786 Sqlitetest_blob_Init(interp);
3732 Sqlitetest_demovfs_Init(interp); 3787 Sqlitetest_demovfs_Init(interp);
3733 Sqlitetest_func_Init(interp); 3788 Sqlitetest_func_Init(interp);
3734 Sqlitetest_hexio_Init(interp); 3789 Sqlitetest_hexio_Init(interp);
3735 Sqlitetest_init_Init(interp); 3790 Sqlitetest_init_Init(interp);
3736 Sqlitetest_malloc_Init(interp); 3791 Sqlitetest_malloc_Init(interp);
3737 Sqlitetest_mutex_Init(interp); 3792 Sqlitetest_mutex_Init(interp);
3738 Sqlitetestschema_Init(interp); 3793 Sqlitetestschema_Init(interp);
3739 Sqlitetesttclvar_Init(interp); 3794 Sqlitetesttclvar_Init(interp);
3740 Sqlitetestfs_Init(interp); 3795 Sqlitetestfs_Init(interp);
3741 SqlitetestThread_Init(interp); 3796 SqlitetestThread_Init(interp);
3742 SqlitetestOnefile_Init(interp); 3797 SqlitetestOnefile_Init(interp);
3743 SqlitetestOsinst_Init(interp); 3798 SqlitetestOsinst_Init(interp);
3744 Sqlitetestbackup_Init(interp); 3799 Sqlitetestbackup_Init(interp);
3745 Sqlitetestintarray_Init(interp); 3800 Sqlitetestintarray_Init(interp);
3746 Sqlitetestvfs_Init(interp); 3801 Sqlitetestvfs_Init(interp);
3747 Sqlitetestrtree_Init(interp); 3802 Sqlitetestrtree_Init(interp);
3748 Sqlitequota_Init(interp); 3803 Sqlitequota_Init(interp);
3749 Sqlitemultiplex_Init(interp); 3804 Sqlitemultiplex_Init(interp);
3750 SqliteSuperlock_Init(interp); 3805 SqliteSuperlock_Init(interp);
3751 SqlitetestSyscall_Init(interp); 3806 SqlitetestSyscall_Init(interp);
3807 Fts5tcl_Init(interp);
3808 SqliteRbu_Init(interp);
3752 3809
3753 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 3810 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
3754 Sqlitetestfts3_Init(interp); 3811 Sqlitetestfts3_Init(interp);
3755 #endif 3812 #endif
3756 3813
3757 Tcl_CreateObjCommand( 3814 Tcl_CreateObjCommand(
3758 interp, "load_testfixture_extensions", init_all_cmd, 0, 0 3815 interp, "load_testfixture_extensions", init_all_cmd, 0, 0
3759 ); 3816 );
3760 Tcl_CreateObjCommand( 3817 Tcl_CreateObjCommand(
3761 interp, "db_use_legacy_prepare", db_use_legacy_prepare_cmd, 0, 0 3818 interp, "db_use_legacy_prepare", db_use_legacy_prepare_cmd, 0, 0
3762 ); 3819 );
3820 Tcl_CreateObjCommand(
3821 interp, "db_last_stmt_ptr", db_last_stmt_ptr, 0, 0
3822 );
3763 3823
3764 #ifdef SQLITE_SSE 3824 #ifdef SQLITE_SSE
3765 Sqlitetestsse_Init(interp); 3825 Sqlitetestsse_Init(interp);
3766 #endif 3826 #endif
3767 } 3827 }
3768 #endif 3828 #endif
3769 } 3829 }
3770 3830
3831 /* Needed for the setrlimit() system call on unix */
3832 #if defined(unix)
3833 #include <sys/resource.h>
3834 #endif
3835
3771 #define TCLSH_MAIN main /* Needed to fake out mktclapp */ 3836 #define TCLSH_MAIN main /* Needed to fake out mktclapp */
3772 int TCLSH_MAIN(int argc, char **argv){ 3837 int TCLSH_MAIN(int argc, char **argv){
3773 Tcl_Interp *interp; 3838 Tcl_Interp *interp;
3774 3839
3775 #if !defined(_WIN32_WCE) 3840 #if !defined(_WIN32_WCE)
3776 if( getenv("BREAK") ){ 3841 if( getenv("BREAK") ){
3777 fprintf(stderr, 3842 fprintf(stderr,
3778 "attach debugger to process %d and press any key to continue.\n", 3843 "attach debugger to process %d and press any key to continue.\n",
3779 GETPID()); 3844 GETPID());
3780 fgetc(stdin); 3845 fgetc(stdin);
3781 } 3846 }
3782 #endif 3847 #endif
3783 3848
3849 /* Since the primary use case for this binary is testing of SQLite,
3850 ** be sure to generate core files if we crash */
3851 #if defined(SQLITE_TEST) && defined(unix)
3852 { struct rlimit x;
3853 getrlimit(RLIMIT_CORE, &x);
3854 x.rlim_cur = x.rlim_max;
3855 setrlimit(RLIMIT_CORE, &x);
3856 }
3857 #endif /* SQLITE_TEST && unix */
3858
3859
3784 /* Call sqlite3_shutdown() once before doing anything else. This is to 3860 /* Call sqlite3_shutdown() once before doing anything else. This is to
3785 ** test that sqlite3_shutdown() can be safely called by a process before 3861 ** test that sqlite3_shutdown() can be safely called by a process before
3786 ** sqlite3_initialize() is. */ 3862 ** sqlite3_initialize() is. */
3787 sqlite3_shutdown(); 3863 sqlite3_shutdown();
3788 3864
3789 Tcl_FindExecutable(argv[0]); 3865 Tcl_FindExecutable(argv[0]);
3790 Tcl_SetSystemEncoding(NULL, "utf-8"); 3866 Tcl_SetSystemEncoding(NULL, "utf-8");
3791 interp = Tcl_CreateInterp(); 3867 interp = Tcl_CreateInterp();
3792 3868
3793 #if TCLSH==2 3869 #if TCLSH==2
(...skipping 18 matching lines...) Expand all
3812 fprintf(stderr,"%s: %s\n", *argv, zInfo); 3888 fprintf(stderr,"%s: %s\n", *argv, zInfo);
3813 return 1; 3889 return 1;
3814 } 3890 }
3815 } 3891 }
3816 if( TCLSH==2 || argc<=1 ){ 3892 if( TCLSH==2 || argc<=1 ){
3817 Tcl_GlobalEval(interp, tclsh_main_loop()); 3893 Tcl_GlobalEval(interp, tclsh_main_loop());
3818 } 3894 }
3819 return 0; 3895 return 0;
3820 } 3896 }
3821 #endif /* TCLSH */ 3897 #endif /* TCLSH */
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/table.c ('k') | third_party/sqlite/sqlite-src-3100200/src/test1.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698