sl@0: /* sl@0: ** 2001 September 15 sl@0: ** sl@0: ** The author disclaims copyright to this source code. In place of sl@0: ** a legal notice, here is a blessing: sl@0: ** sl@0: ** May you do good and not evil. sl@0: ** May you find forgiveness for yourself and forgive others. sl@0: ** May you share freely, never taking more than you give. sl@0: ** sl@0: ************************************************************************* sl@0: ** Code for testing all sorts of SQLite interfaces. This code sl@0: ** is not included in the SQLite library. It is used for automated sl@0: ** testing of the SQLite library. sl@0: ** sl@0: ** $Id: test1.c,v 1.326 2008/10/02 14:49:02 danielk1977 Exp $ sl@0: */ sl@0: #include "sqliteInt.h" sl@0: #include "tcl.h" sl@0: #include sl@0: #include sl@0: sl@0: /* sl@0: ** This is a copy of the first part of the SqliteDb structure in sl@0: ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine sl@0: ** can extract the sqlite3* pointer from an existing Tcl SQLite sl@0: ** connection. sl@0: */ sl@0: struct SqliteDb { sl@0: sqlite3 *db; sl@0: }; sl@0: sl@0: /* sl@0: ** Convert text generated by the "%p" conversion format back into sl@0: ** a pointer. sl@0: */ sl@0: static int testHexToInt(int h){ sl@0: if( h>='0' && h<='9' ){ sl@0: return h - '0'; sl@0: }else if( h>='a' && h<='f' ){ sl@0: return h - 'a' + 10; sl@0: }else{ sl@0: assert( h>='A' && h<='F' ); sl@0: return h - 'A' + 10; sl@0: } sl@0: } sl@0: void *sqlite3TestTextToPtr(const char *z){ sl@0: void *p; sl@0: u64 v; sl@0: u32 v2; sl@0: if( z[0]=='0' && z[1]=='x' ){ sl@0: z += 2; sl@0: } sl@0: v = 0; sl@0: while( *z ){ sl@0: v = (v<<4) + testHexToInt(*z); sl@0: z++; sl@0: } sl@0: if( sizeof(p)==sizeof(v) ){ sl@0: memcpy(&p, &v, sizeof(p)); sl@0: }else{ sl@0: assert( sizeof(p)==sizeof(v2) ); sl@0: v2 = (u32)v; sl@0: memcpy(&p, &v2, sizeof(p)); sl@0: } sl@0: return p; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** A TCL command that returns the address of the sqlite* pointer sl@0: ** for an sqlite connection instance. Bad things happen if the sl@0: ** input is not an sqlite connection. sl@0: */ sl@0: static int get_sqlite_pointer( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: struct SqliteDb *p; sl@0: Tcl_CmdInfo cmdInfo; sl@0: char zBuf[100]; sl@0: if( objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){ sl@0: Tcl_AppendResult(interp, "command not found: ", sl@0: Tcl_GetString(objv[1]), (char*)0); sl@0: return TCL_ERROR; sl@0: } sl@0: p = (struct SqliteDb*)cmdInfo.objClientData; sl@0: sprintf(zBuf, "%p", p->db); sl@0: if( strncmp(zBuf,"0x",2) ){ sl@0: sprintf(zBuf, "0x%p", p->db); sl@0: } sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Decode a pointer to an sqlite3 object. sl@0: */ sl@0: int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ sl@0: struct SqliteDb *p; sl@0: Tcl_CmdInfo cmdInfo; sl@0: if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){ sl@0: p = (struct SqliteDb*)cmdInfo.objClientData; sl@0: *ppDb = p->db; sl@0: }else{ sl@0: *ppDb = (sqlite3*)sqlite3TestTextToPtr(zA); sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: const char *sqlite3TestErrorName(int rc){ sl@0: const char *zName = 0; sl@0: switch( rc & 0xff ){ sl@0: case SQLITE_OK: zName = "SQLITE_OK"; break; sl@0: case SQLITE_ERROR: zName = "SQLITE_ERROR"; break; sl@0: case SQLITE_PERM: zName = "SQLITE_PERM"; break; sl@0: case SQLITE_ABORT: zName = "SQLITE_ABORT"; break; sl@0: case SQLITE_BUSY: zName = "SQLITE_BUSY"; break; sl@0: case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break; sl@0: case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; sl@0: case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; sl@0: case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; sl@0: case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; sl@0: case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break; sl@0: case SQLITE_FULL: zName = "SQLITE_FULL"; break; sl@0: case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break; sl@0: case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; sl@0: case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; sl@0: case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break; sl@0: case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break; sl@0: case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break; sl@0: case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break; sl@0: case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break; sl@0: case SQLITE_AUTH: zName = "SQLITE_AUTH"; break; sl@0: case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break; sl@0: case SQLITE_RANGE: zName = "SQLITE_RANGE"; break; sl@0: case SQLITE_ROW: zName = "SQLITE_ROW"; break; sl@0: case SQLITE_DONE: zName = "SQLITE_DONE"; break; sl@0: case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break; sl@0: case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break; sl@0: default: zName = "SQLITE_Unknown"; break; sl@0: } sl@0: return zName; sl@0: } sl@0: #define t1ErrorName sqlite3TestErrorName sl@0: sl@0: /* sl@0: ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the sl@0: ** fact that the sqlite3* is the first field in the Vdbe structure. sl@0: */ sl@0: #define StmtToDb(X) sqlite3_db_handle(X) sl@0: sl@0: /* sl@0: ** Check a return value to make sure it agrees with the results sl@0: ** from sqlite3_errcode. sl@0: */ sl@0: int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){ sl@0: if( rc!=SQLITE_MISUSE && rc!=SQLITE_OK && sqlite3_errcode(db)!=rc ){ sl@0: char zBuf[200]; sl@0: int r2 = sqlite3_errcode(db); sl@0: sprintf(zBuf, "error code %s (%d) does not match sqlite3_errcode %s (%d)", sl@0: t1ErrorName(rc), rc, t1ErrorName(r2), r2); sl@0: Tcl_ResetResult(interp); sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: return 1; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: /* sl@0: ** Decode a pointer to an sqlite3_stmt object. sl@0: */ sl@0: static int getStmtPointer( sl@0: Tcl_Interp *interp, sl@0: const char *zArg, sl@0: sqlite3_stmt **ppStmt sl@0: ){ sl@0: *ppStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(zArg); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Generate a text representation of a pointer that can be understood sl@0: ** by the getDbPointer and getVmPointer routines above. sl@0: ** sl@0: ** The problem is, on some machines (Solaris) if you do a printf with sl@0: ** "%p" you cannot turn around and do a scanf with the same "%p" and sl@0: ** get your pointer back. You have to prepend a "0x" before it will sl@0: ** work. Or at least that is what is reported to me (drh). But this sl@0: ** behavior varies from machine to machine. The solution used her is sl@0: ** to test the string right after it is generated to see if it can be sl@0: ** understood by scanf, and if not, try prepending an "0x" to see if sl@0: ** that helps. If nothing works, a fatal error is generated. sl@0: */ sl@0: int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){ sl@0: sqlite3_snprintf(100, zPtr, "%p", p); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** The callback routine for sqlite3_exec_printf(). sl@0: */ sl@0: static int exec_printf_cb(void *pArg, int argc, char **argv, char **name){ sl@0: Tcl_DString *str = (Tcl_DString*)pArg; sl@0: int i; sl@0: sl@0: if( Tcl_DStringLength(str)==0 ){ sl@0: for(i=0; imutex); sl@0: return TCL_OK; sl@0: } sl@0: static int db_leave( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3 *db; sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: sqlite3_mutex_leave(db->mutex); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_exec DB SQL sl@0: ** sl@0: ** Invoke the sqlite3_exec interface using the open database DB sl@0: */ sl@0: static int test_exec( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3 *db; sl@0: Tcl_DString str; sl@0: int rc; sl@0: char *zErr = 0; sl@0: char *zSql; sl@0: int i, j; sl@0: char zBuf[30]; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB SQL", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: Tcl_DStringInit(&str); sl@0: zSql = sqlite3_mprintf("%s", argv[2]); sl@0: for(i=j=0; zSql[i];){ sl@0: if( zSql[i]=='%' ){ sl@0: zSql[j++] = (testHexToInt(zSql[i+1])<<4) + testHexToInt(zSql[i+2]); sl@0: i += 3; sl@0: }else{ sl@0: zSql[j++] = zSql[i++]; sl@0: } sl@0: } sl@0: zSql[j] = 0; sl@0: rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr); sl@0: sqlite3_free(zSql); sl@0: sprintf(zBuf, "%d", rc); sl@0: Tcl_AppendElement(interp, zBuf); sl@0: Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr); sl@0: Tcl_DStringFree(&str); sl@0: if( zErr ) sqlite3_free(zErr); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_exec_nr DB SQL sl@0: ** sl@0: ** Invoke the sqlite3_exec interface using the open database DB. Discard sl@0: ** all results sl@0: */ sl@0: static int test_exec_nr( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3 *db; sl@0: int rc; sl@0: char *zErr = 0; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB SQL", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: rc = sqlite3_exec(db, argv[2], 0, 0, &zErr); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ... sl@0: ** sl@0: ** Test the %z format of sqliteMPrintf(). Use multiple mprintf() calls to sl@0: ** concatenate arg0 through argn using separator as the separator. sl@0: ** Return the result. sl@0: */ sl@0: static int test_mprintf_z( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: char *zResult = 0; sl@0: int i; sl@0: sl@0: for(i=2; isizeof(zStr) ) n = sizeof(zStr); sl@0: sqlite3_snprintf(sizeof(zStr), zStr, "abcdefghijklmnopqrstuvwxyz"); sl@0: sqlite3_snprintf(n, zStr, zFormat, a1); sl@0: Tcl_AppendResult(interp, zStr, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: #ifndef SQLITE_OMIT_GET_TABLE sl@0: sl@0: /* sl@0: ** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts? sl@0: ** sl@0: ** Invoke the sqlite3_get_table_printf() interface using the open database sl@0: ** DB. The SQL is the string FORMAT. The format string should contain sl@0: ** one %s or %q. STRING is the value inserted into %s or %q. sl@0: */ sl@0: static int test_get_table_printf( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3 *db; sl@0: Tcl_DString str; sl@0: int rc; sl@0: char *zErr = 0; sl@0: int nRow, nCol; sl@0: char **aResult; sl@0: int i; sl@0: char zBuf[30]; sl@0: char *zSql; sl@0: int resCount = -1; sl@0: if( argc==5 ){ sl@0: if( Tcl_GetInt(interp, argv[4], &resCount) ) return TCL_ERROR; sl@0: } sl@0: if( argc!=4 && argc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB FORMAT STRING ?COUNT?", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: Tcl_DStringInit(&str); sl@0: zSql = sqlite3_mprintf(argv[2],argv[3]); sl@0: if( argc==5 ){ sl@0: rc = sqlite3_get_table(db, zSql, &aResult, 0, 0, &zErr); sl@0: }else{ sl@0: rc = sqlite3_get_table(db, zSql, &aResult, &nRow, &nCol, &zErr); sl@0: resCount = (nRow+1)*nCol; sl@0: } sl@0: sqlite3_free(zSql); sl@0: sprintf(zBuf, "%d", rc); sl@0: Tcl_AppendElement(interp, zBuf); sl@0: if( rc==SQLITE_OK ){ sl@0: if( argc==4 ){ sl@0: sprintf(zBuf, "%d", nRow); sl@0: Tcl_AppendElement(interp, zBuf); sl@0: sprintf(zBuf, "%d", nCol); sl@0: Tcl_AppendElement(interp, zBuf); sl@0: } sl@0: for(i=0; inUsed + n + 2 > p->nAlloc ){ sl@0: char *zNew; sl@0: p->nAlloc = p->nAlloc*2 + n + 200; sl@0: zNew = sqlite3_realloc(p->z, p->nAlloc); sl@0: if( zNew==0 ){ sl@0: sqlite3_free(p->z); sl@0: memset(p, 0, sizeof(*p)); sl@0: return; sl@0: } sl@0: p->z = zNew; sl@0: } sl@0: if( divider && p->nUsed>0 ){ sl@0: p->z[p->nUsed++] = divider; sl@0: } sl@0: memcpy(&p->z[p->nUsed], z, n+1); sl@0: p->nUsed += n; sl@0: } sl@0: sl@0: /* sl@0: ** Invoked for each callback from sqlite3ExecFunc sl@0: */ sl@0: static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){ sl@0: struct dstr *p = (struct dstr*)pData; sl@0: int i; sl@0: for(i=0; imutex); sl@0: pVal = sqlite3ValueNew(db); sl@0: sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC); sl@0: zUtf16 = sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); sl@0: if( db->mallocFailed ){ sl@0: rc = SQLITE_NOMEM; sl@0: }else{ sl@0: rc = sqlite3_create_function16(db, zUtf16, sl@0: 1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0); sl@0: } sl@0: sqlite3ValueFree(pVal); sl@0: sqlite3_mutex_leave(db->mutex); sl@0: } sl@0: #endif sl@0: sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Routines to implement the x_count() aggregate function. sl@0: ** sl@0: ** x_count() counts the number of non-null arguments. But there are sl@0: ** some twists for testing purposes. sl@0: ** sl@0: ** If the argument to x_count() is 40 then a UTF-8 error is reported sl@0: ** on the step function. If x_count(41) is seen, then a UTF-16 error sl@0: ** is reported on the step function. If the total count is 42, then sl@0: ** a UTF-8 error is reported on the finalize function. sl@0: */ sl@0: typedef struct t1CountCtx t1CountCtx; sl@0: struct t1CountCtx { sl@0: int n; sl@0: }; sl@0: static void t1CountStep( sl@0: sqlite3_context *context, sl@0: int argc, sl@0: sqlite3_value **argv sl@0: ){ sl@0: t1CountCtx *p; sl@0: p = sqlite3_aggregate_context(context, sizeof(*p)); sl@0: if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0]) ) && p ){ sl@0: p->n++; sl@0: } sl@0: if( argc>0 ){ sl@0: int v = sqlite3_value_int(argv[0]); sl@0: if( v==40 ){ sl@0: sqlite3_result_error(context, "value of 40 handed to x_count", -1); sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: }else if( v==41 ){ sl@0: const char zUtf16ErrMsg[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0}; sl@0: sqlite3_result_error16(context, &zUtf16ErrMsg[1-SQLITE_BIGENDIAN], -1); sl@0: #endif sl@0: } sl@0: } sl@0: } sl@0: static void t1CountFinalize(sqlite3_context *context){ sl@0: t1CountCtx *p; sl@0: p = sqlite3_aggregate_context(context, sizeof(*p)); sl@0: if( p ){ sl@0: if( p->n==42 ){ sl@0: sqlite3_result_error(context, "x_count totals to 42", -1); sl@0: }else{ sl@0: sqlite3_result_int(context, p ? p->n : 0); sl@0: } sl@0: } sl@0: } sl@0: sl@0: static void legacyCountStep( sl@0: sqlite3_context *context, sl@0: int argc, sl@0: sqlite3_value **argv sl@0: ){ sl@0: /* no-op */ sl@0: } sl@0: static void legacyCountFinalize(sqlite3_context *context){ sl@0: sqlite3_result_int(context, sqlite3_aggregate_count(context)); sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_create_aggregate DB sl@0: ** sl@0: ** Call the sqlite3_create_function API on the given database in order sl@0: ** to create a function named "x_count". This function is similar sl@0: ** to the built-in count() function, with a few special quirks sl@0: ** for testing the sqlite3_result_error() APIs. sl@0: ** sl@0: ** The original motivation for this routine was to be able to call the sl@0: ** sqlite3_create_aggregate function while a query is in progress in order sl@0: ** to test the SQLITE_MISUSE detection logic. See misuse.test. sl@0: ** sl@0: ** This routine was later extended to test the use of sqlite3_result_error() sl@0: ** within aggregate functions. sl@0: ** sl@0: ** Later: It is now also extended to register the aggregate function sl@0: ** "legacy_count()" with the supplied database handle. This is used sl@0: ** to test the deprecated sqlite3_aggregate_count() API. sl@0: */ sl@0: static int test_create_aggregate( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3 *db; sl@0: int rc; sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FILENAME\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0, sl@0: t1CountStep,t1CountFinalize); sl@0: if( rc==SQLITE_OK ){ sl@0: rc = sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0, sl@0: t1CountStep,t1CountFinalize); sl@0: } sl@0: if( rc==SQLITE_OK ){ sl@0: rc = sqlite3_create_function(db, "legacy_count", 0, SQLITE_ANY, 0, 0, sl@0: legacyCountStep, legacyCountFinalize sl@0: ); sl@0: } sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** Usage: printf TEXT sl@0: ** sl@0: ** Send output to printf. Use this rather than puts to merge the output sl@0: ** in the correct sequence with debugging printfs inserted into C code. sl@0: ** Puts uses a separate buffer and debugging statements will be out of sl@0: ** sequence if it is used. sl@0: */ sl@0: static int test_printf( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " TEXT\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: printf("%s\n", argv[1]); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER sl@0: ** sl@0: ** Call mprintf with three integer arguments sl@0: */ sl@0: static int sqlite3_mprintf_int( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: int a[3], i; sl@0: char *z; sl@0: if( argc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT INT INT INT\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: for(i=2; i<5; i++){ sl@0: if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; sl@0: } sl@0: z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** If zNum represents an integer that will fit in 64-bits, then set sl@0: ** *pValue to that integer and return true. Otherwise return false. sl@0: */ sl@0: static int sqlite3GetInt64(const char *zNum, i64 *pValue){ sl@0: if( sqlite3FitsIn64Bits(zNum, 0) ){ sl@0: sqlite3Atoi64(zNum, pValue); sl@0: return 1; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER sl@0: ** sl@0: ** Call mprintf with three 64-bit integer arguments sl@0: */ sl@0: static int sqlite3_mprintf_int64( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: sqlite_int64 a[3]; sl@0: char *z; sl@0: if( argc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT INT INT INT\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: for(i=2; i<5; i++){ sl@0: if( !sqlite3GetInt64(argv[i], &a[i-2]) ){ sl@0: Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: } sl@0: z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING sl@0: ** sl@0: ** Call mprintf with two integer arguments and one string argument sl@0: */ sl@0: static int sqlite3_mprintf_str( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: int a[3], i; sl@0: char *z; sl@0: if( argc<4 || argc>5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT INT INT ?STRING?\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: for(i=2; i<4; i++){ sl@0: if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; sl@0: } sl@0: z = sqlite3_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING sl@0: ** sl@0: ** Call mprintf with two integer arguments and one string argument sl@0: */ sl@0: static int sqlite3_snprintf_str( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: int a[3], i; sl@0: int n; sl@0: char *z; sl@0: if( argc<5 || argc>6 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " INT FORMAT INT INT ?STRING?\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR; sl@0: if( n<0 ){ sl@0: Tcl_AppendResult(interp, "N must be non-negative", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: for(i=3; i<5; i++){ sl@0: if( Tcl_GetInt(interp, argv[i], &a[i-3]) ) return TCL_ERROR; sl@0: } sl@0: z = sqlite3_malloc( n+1 ); sl@0: sqlite3_snprintf(n, z, argv[2], a[0], a[1], argc>4 ? argv[5] : NULL); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE sl@0: ** sl@0: ** Call mprintf with two integer arguments and one double argument sl@0: */ sl@0: static int sqlite3_mprintf_double( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: int a[3], i; sl@0: double r; sl@0: char *z; sl@0: if( argc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT INT INT DOUBLE\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: for(i=2; i<4; i++){ sl@0: if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; sl@0: } sl@0: if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR; sl@0: z = sqlite3_mprintf(argv[1], a[0], a[1], r); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE sl@0: ** sl@0: ** Call mprintf with a single double argument which is the product of the sl@0: ** two arguments given above. This is used to generate overflow and underflow sl@0: ** doubles to test that they are converted properly. sl@0: */ sl@0: static int sqlite3_mprintf_scaled( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: int i; sl@0: double r[2]; sl@0: char *z; sl@0: if( argc!=4 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT DOUBLE DOUBLE\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: for(i=2; i<4; i++){ sl@0: if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR; sl@0: } sl@0: z = sqlite3_mprintf(argv[1], r[0]*r[1]); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_stronly FORMAT STRING sl@0: ** sl@0: ** Call mprintf with a single double argument which is the product of the sl@0: ** two arguments given above. This is used to generate overflow and underflow sl@0: ** doubles to test that they are converted properly. sl@0: */ sl@0: static int sqlite3_mprintf_stronly( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: char *z; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT STRING\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: z = sqlite3_mprintf(argv[1], argv[2]); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX sl@0: ** sl@0: ** Call mprintf with a single double argument which is derived from the sl@0: ** hexadecimal encoding of an IEEE double. sl@0: */ sl@0: static int sqlite3_mprintf_hexdouble( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: char *z; sl@0: double r; sl@0: unsigned int x1, x2; sl@0: sqlite_uint64 d; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " FORMAT STRING\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){ sl@0: Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: d = x2; sl@0: d = (d<<32) + x1; sl@0: memcpy(&r, &d, sizeof(r)); sl@0: z = sqlite3_mprintf(argv[1], r); sl@0: Tcl_AppendResult(interp, z, 0); sl@0: sqlite3_free(z); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_enable_shared_cache ?BOOLEAN? sl@0: ** sl@0: */ sl@0: #if !defined(SQLITE_OMIT_SHARED_CACHE) sl@0: static int test_enable_shared( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: int rc; sl@0: int enable; sl@0: int ret = 0; sl@0: sl@0: if( objc!=2 && objc!=1 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?"); sl@0: return TCL_ERROR; sl@0: } sl@0: ret = sqlite3GlobalConfig.sharedCacheEnabled; sl@0: sl@0: if( objc==2 ){ sl@0: if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: rc = sqlite3_enable_shared_cache(enable); sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC); sl@0: return TCL_ERROR; sl@0: } sl@0: } sl@0: Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret)); sl@0: return TCL_OK; sl@0: } sl@0: #endif sl@0: sl@0: sl@0: sl@0: /* sl@0: ** Usage: sqlite3_extended_result_codes DB BOOLEAN sl@0: ** sl@0: */ sl@0: static int test_extended_result_codes( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: int enable; sl@0: sqlite3 *db; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR; sl@0: sqlite3_extended_result_codes(db, enable); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_libversion_number sl@0: ** sl@0: */ sl@0: static int test_libversion_number( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number())); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_table_column_metadata DB dbname tblname colname sl@0: ** sl@0: */ sl@0: #ifdef SQLITE_ENABLE_COLUMN_METADATA sl@0: static int test_table_column_metadata( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: sqlite3 *db; sl@0: const char *zDb; sl@0: const char *zTbl; sl@0: const char *zCol; sl@0: int rc; sl@0: Tcl_Obj *pRet; sl@0: sl@0: const char *zDatatype; sl@0: const char *zCollseq; sl@0: int notnull; sl@0: int primarykey; sl@0: int autoincrement; sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "DB dbname tblname colname"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: zDb = Tcl_GetString(objv[2]); sl@0: zTbl = Tcl_GetString(objv[3]); sl@0: zCol = Tcl_GetString(objv[4]); sl@0: sl@0: if( strlen(zDb)==0 ) zDb = 0; sl@0: sl@0: rc = sqlite3_table_column_metadata(db, zDb, zTbl, zCol, sl@0: &zDatatype, &zCollseq, ¬null, &primarykey, &autoincrement); sl@0: sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_AppendResult(interp, sqlite3_errmsg(db), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: pRet = Tcl_NewObj(); sl@0: Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zDatatype, -1)); sl@0: Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zCollseq, -1)); sl@0: Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(notnull)); sl@0: Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(primarykey)); sl@0: Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(autoincrement)); sl@0: Tcl_SetObjResult(interp, pRet); sl@0: sl@0: return TCL_OK; sl@0: } sl@0: #endif sl@0: sl@0: #ifndef SQLITE_OMIT_INCRBLOB sl@0: sl@0: /* sl@0: ** sqlite3_blob_read CHANNEL OFFSET N sl@0: ** sl@0: ** This command is used to test the sqlite3_blob_read() in ways that sl@0: ** the Tcl channel interface does not. The first argument should sl@0: ** be the name of a valid channel created by the [incrblob] method sl@0: ** of a database handle. This function calls sqlite3_blob_read() sl@0: ** to read N bytes from offset OFFSET from the underlying SQLite sl@0: ** blob handle. sl@0: ** sl@0: ** On success, a byte-array object containing the read data is sl@0: ** returned. On failure, the interpreter result is set to the sl@0: ** text representation of the returned error code (i.e. "SQLITE_NOMEM") sl@0: ** and a Tcl exception is thrown. sl@0: */ sl@0: static int test_blob_read( sl@0: ClientData clientData, /* Not used */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: Tcl_Channel channel; sl@0: ClientData instanceData; sl@0: sqlite3_blob *pBlob; sl@0: int notUsed; sl@0: int nByte; sl@0: int iOffset; sl@0: unsigned char *zBuf; sl@0: int rc; sl@0: sl@0: if( objc!=4 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET N"); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), ¬Used); sl@0: if( !channel sl@0: || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset) sl@0: || TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &nByte) sl@0: || nByte<0 || iOffset<0 sl@0: ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: instanceData = Tcl_GetChannelInstanceData(channel); sl@0: pBlob = *((sqlite3_blob **)instanceData); sl@0: sl@0: zBuf = (unsigned char *)Tcl_Alloc(nByte); sl@0: rc = sqlite3_blob_read(pBlob, zBuf, nByte, iOffset); sl@0: if( rc==SQLITE_OK ){ sl@0: Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zBuf, nByte)); sl@0: }else{ sl@0: Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); sl@0: } sl@0: Tcl_Free((char *)zBuf); sl@0: sl@0: return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); sl@0: } sl@0: sl@0: /* sl@0: ** sqlite3_blob_write CHANNEL OFFSET DATA ?NDATA? sl@0: ** sl@0: ** This command is used to test the sqlite3_blob_write() in ways that sl@0: ** the Tcl channel interface does not. The first argument should sl@0: ** be the name of a valid channel created by the [incrblob] method sl@0: ** of a database handle. This function calls sqlite3_blob_write() sl@0: ** to write the DATA byte-array to the underlying SQLite blob handle. sl@0: ** at offset OFFSET. sl@0: ** sl@0: ** On success, an empty string is returned. On failure, the interpreter sl@0: ** result is set to the text representation of the returned error code sl@0: ** (i.e. "SQLITE_NOMEM") and a Tcl exception is thrown. sl@0: */ sl@0: static int test_blob_write( sl@0: ClientData clientData, /* Not used */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: Tcl_Channel channel; sl@0: ClientData instanceData; sl@0: sqlite3_blob *pBlob; sl@0: int notUsed; sl@0: int iOffset; sl@0: int rc; sl@0: sl@0: unsigned char *zBuf; sl@0: int nBuf; sl@0: sl@0: if( objc!=4 && objc!=5 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET DATA ?NDATA?"); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), ¬Used); sl@0: if( !channel || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: instanceData = Tcl_GetChannelInstanceData(channel); sl@0: pBlob = *((sqlite3_blob **)instanceData); sl@0: sl@0: zBuf = Tcl_GetByteArrayFromObj(objv[3], &nBuf); sl@0: if( objc==5 && Tcl_GetIntFromObj(interp, objv[4], &nBuf) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: rc = sqlite3_blob_write(pBlob, zBuf, nBuf, iOffset); sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); sl@0: } sl@0: sl@0: return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); sl@0: } sl@0: #endif sl@0: sl@0: /* sl@0: ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC sl@0: ** sl@0: ** This Tcl proc is used for testing the experimental sl@0: ** sqlite3_create_collation_v2() interface. sl@0: */ sl@0: struct TestCollationX { sl@0: Tcl_Interp *interp; sl@0: Tcl_Obj *pCmp; sl@0: Tcl_Obj *pDel; sl@0: }; sl@0: typedef struct TestCollationX TestCollationX; sl@0: static void testCreateCollationDel(void *pCtx){ sl@0: TestCollationX *p = (TestCollationX *)pCtx; sl@0: sl@0: int rc = Tcl_EvalObjEx(p->interp, p->pDel, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL); sl@0: if( rc!=TCL_OK ){ sl@0: Tcl_BackgroundError(p->interp); sl@0: } sl@0: sl@0: Tcl_DecrRefCount(p->pCmp); sl@0: Tcl_DecrRefCount(p->pDel); sl@0: sqlite3_free((void *)p); sl@0: } sl@0: static int testCreateCollationCmp( sl@0: void *pCtx, sl@0: int nLeft, sl@0: const void *zLeft, sl@0: int nRight, sl@0: const void *zRight sl@0: ){ sl@0: TestCollationX *p = (TestCollationX *)pCtx; sl@0: Tcl_Obj *pScript = Tcl_DuplicateObj(p->pCmp); sl@0: int iRes = 0; sl@0: sl@0: Tcl_IncrRefCount(pScript); sl@0: Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zLeft, nLeft)); sl@0: Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zRight,nRight)); sl@0: sl@0: if( TCL_OK!=Tcl_EvalObjEx(p->interp, pScript, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL) sl@0: || TCL_OK!=Tcl_GetIntFromObj(p->interp, Tcl_GetObjResult(p->interp), &iRes) sl@0: ){ sl@0: Tcl_BackgroundError(p->interp); sl@0: } sl@0: Tcl_DecrRefCount(pScript); sl@0: sl@0: return iRes; sl@0: } sl@0: static int test_create_collation_v2( sl@0: ClientData clientData, /* Not used */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: TestCollationX *p; sl@0: sqlite3 *db; sl@0: int rc; sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE NAME CMP-PROC DEL-PROC"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: sl@0: p = (TestCollationX *)sqlite3_malloc(sizeof(TestCollationX)); sl@0: p->pCmp = objv[3]; sl@0: p->pDel = objv[4]; sl@0: p->interp = interp; sl@0: Tcl_IncrRefCount(p->pCmp); sl@0: Tcl_IncrRefCount(p->pDel); sl@0: sl@0: rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), 16, sl@0: (void *)p, testCreateCollationCmp, testCreateCollationDel sl@0: ); sl@0: if( rc!=SQLITE_MISUSE ){ sl@0: Tcl_AppendResult(interp, "sqlite3_create_collate_v2() failed to detect " sl@0: "an invalid encoding", (char*)0); sl@0: return TCL_ERROR; sl@0: } sl@0: rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8, sl@0: (void *)p, testCreateCollationCmp, testCreateCollationDel sl@0: ); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC? sl@0: */ sl@0: static int test_load_extension( sl@0: ClientData clientData, /* Not used */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: Tcl_CmdInfo cmdInfo; sl@0: sqlite3 *db; sl@0: int rc; sl@0: char *zDb; sl@0: char *zFile; sl@0: char *zProc = 0; sl@0: char *zErr = 0; sl@0: sl@0: if( objc!=4 && objc!=3 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE FILE ?PROC?"); sl@0: return TCL_ERROR; sl@0: } sl@0: zDb = Tcl_GetString(objv[1]); sl@0: zFile = Tcl_GetString(objv[2]); sl@0: if( objc==4 ){ sl@0: zProc = Tcl_GetString(objv[3]); sl@0: } sl@0: sl@0: /* Extract the C database handle from the Tcl command name */ sl@0: if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ sl@0: Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0); sl@0: return TCL_ERROR; sl@0: } sl@0: db = ((struct SqliteDb*)cmdInfo.objClientData)->db; sl@0: assert(db); sl@0: sl@0: /* Call the underlying C function. If an error occurs, set rc to sl@0: ** TCL_ERROR and load any error string into the interpreter. If no sl@0: ** error occurs, set rc to TCL_OK. sl@0: */ sl@0: #ifdef SQLITE_OMIT_LOAD_EXTENSION sl@0: rc = SQLITE_ERROR; sl@0: zErr = sqlite3_mprintf("this build omits sqlite3_load_extension()"); sl@0: #else sl@0: rc = sqlite3_load_extension(db, zFile, zProc, &zErr); sl@0: #endif sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_SetResult(interp, zErr ? zErr : "", TCL_VOLATILE); sl@0: rc = TCL_ERROR; sl@0: }else{ sl@0: rc = TCL_OK; sl@0: } sl@0: sqlite3_free(zErr); sl@0: sl@0: return rc; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF sl@0: */ sl@0: static int test_enable_load( sl@0: ClientData clientData, /* Not used */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: Tcl_CmdInfo cmdInfo; sl@0: sqlite3 *db; sl@0: char *zDb; sl@0: int onoff; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE ONOFF"); sl@0: return TCL_ERROR; sl@0: } sl@0: zDb = Tcl_GetString(objv[1]); sl@0: sl@0: /* Extract the C database handle from the Tcl command name */ sl@0: if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ sl@0: Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0); sl@0: return TCL_ERROR; sl@0: } sl@0: db = ((struct SqliteDb*)cmdInfo.objClientData)->db; sl@0: assert(db); sl@0: sl@0: /* Get the onoff parameter */ sl@0: if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: #ifdef SQLITE_OMIT_LOAD_EXTENSION sl@0: Tcl_AppendResult(interp, "this build omits sqlite3_load_extension()"); sl@0: return TCL_ERROR; sl@0: #else sl@0: sqlite3_enable_load_extension(db, onoff); sl@0: return TCL_OK; sl@0: #endif sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite_abort sl@0: ** sl@0: ** Shutdown the process immediately. This is not a clean shutdown. sl@0: ** This command is used to test the recoverability of a database in sl@0: ** the event of a program crash. sl@0: */ sl@0: static int sqlite_abort( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: assert( interp==0 ); /* This will always fail */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** The following routine is a user-defined SQL function whose purpose sl@0: ** is to test the sqlite_set_result() API. sl@0: */ sl@0: static void testFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ sl@0: while( argc>=2 ){ sl@0: const char *zArg0 = (char*)sqlite3_value_text(argv[0]); sl@0: if( zArg0 ){ sl@0: if( 0==sqlite3StrICmp(zArg0, "int") ){ sl@0: sqlite3_result_int(context, sqlite3_value_int(argv[1])); sl@0: }else if( sqlite3StrICmp(zArg0,"int64")==0 ){ sl@0: sqlite3_result_int64(context, sqlite3_value_int64(argv[1])); sl@0: }else if( sqlite3StrICmp(zArg0,"string")==0 ){ sl@0: sqlite3_result_text(context, (char*)sqlite3_value_text(argv[1]), -1, sl@0: SQLITE_TRANSIENT); sl@0: }else if( sqlite3StrICmp(zArg0,"double")==0 ){ sl@0: sqlite3_result_double(context, sqlite3_value_double(argv[1])); sl@0: }else if( sqlite3StrICmp(zArg0,"null")==0 ){ sl@0: sqlite3_result_null(context); sl@0: }else if( sqlite3StrICmp(zArg0,"value")==0 ){ sl@0: sqlite3_result_value(context, argv[sqlite3_value_int(argv[1])]); sl@0: }else{ sl@0: goto error_out; sl@0: } sl@0: }else{ sl@0: goto error_out; sl@0: } sl@0: argc -= 2; sl@0: argv += 2; sl@0: } sl@0: return; sl@0: sl@0: error_out: sl@0: sqlite3_result_error(context,"first argument should be one of: " sl@0: "int int64 string double null value", -1); sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite_register_test_function DB NAME sl@0: ** sl@0: ** Register the test SQL function on the database DB under the name NAME. sl@0: */ sl@0: static int test_register_func( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3 *db; sl@0: int rc; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB FUNCTION-NAME", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, sl@0: testFunc, 0, 0); sl@0: if( rc!=0 ){ sl@0: Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_finalize STMT sl@0: ** sl@0: ** Finalize a statement handle. sl@0: */ sl@0: static int test_finalize( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int rc; sl@0: sqlite3 *db = 0; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " ", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: sl@0: if( pStmt ){ sl@0: db = StmtToDb(pStmt); sl@0: } sl@0: rc = sqlite3_finalize(pStmt); sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); sl@0: if( db && sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_next_stmt DB STMT sl@0: ** sl@0: ** Return the next statment in sequence after STMT. sl@0: */ sl@0: static int test_next_stmt( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: sqlite3 *db = 0; sl@0: char zBuf[50]; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " DB STMT", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt) ) return TCL_ERROR; sl@0: pStmt = sqlite3_next_stmt(db, pStmt); sl@0: if( pStmt ){ sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** Usage: sqlite3_reset STMT sl@0: ** sl@0: ** Reset a statement handle. sl@0: */ sl@0: static int test_reset( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int rc; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " ", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_reset(pStmt); sl@0: if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); sl@0: /* sl@0: if( rc ){ sl@0: return TCL_ERROR; sl@0: } sl@0: */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_expired STMT sl@0: ** sl@0: ** Return TRUE if a recompilation of the statement is recommended. sl@0: */ sl@0: static int test_expired( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " ", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT sl@0: ** sl@0: ** Transfer all bindings from FROMSTMT over to TOSTMT sl@0: */ sl@0: static int test_transfer_bind( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt1, *pStmt2; sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR; sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, sl@0: Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_changes DB sl@0: ** sl@0: ** Return the number of changes made to the database by the last SQL sl@0: ** execution. sl@0: */ sl@0: static int test_changes( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_changes(db))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** This is the "static_bind_value" that variables are bound to when sl@0: ** the FLAG option of sqlite3_bind is "static" sl@0: */ sl@0: static char *sqlite_static_bind_value = 0; sl@0: static int sqlite_static_bind_nbyte = 0; sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind VM IDX VALUE FLAGS sl@0: ** sl@0: ** Sets the value of the IDX-th occurance of "?" in the original SQL sl@0: ** string. VALUE is the new value. If FLAGS=="null" then VALUE is sl@0: ** ignored and the value is set to NULL. If FLAGS=="static" then sl@0: ** the value is set to the value of a static variable named sl@0: ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy sl@0: ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored sl@0: ** an a 10-byte blob "abc\000xyz\000pq" is inserted. sl@0: */ sl@0: static int test_bind( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int rc; sl@0: int idx; sl@0: if( argc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " VM IDX VALUE (null|static|normal)\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR; sl@0: if( strcmp(argv[4],"null")==0 ){ sl@0: rc = sqlite3_bind_null(pStmt, idx); sl@0: }else if( strcmp(argv[4],"static")==0 ){ sl@0: rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0); sl@0: }else if( strcmp(argv[4],"static-nbytes")==0 ){ sl@0: rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, sl@0: sqlite_static_bind_nbyte, 0); sl@0: }else if( strcmp(argv[4],"normal")==0 ){ sl@0: rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT); sl@0: }else if( strcmp(argv[4],"blob10")==0 ){ sl@0: rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC); sl@0: }else{ sl@0: Tcl_AppendResult(interp, "4th argument should be " sl@0: "\"null\" or \"static\" or \"normal\"", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc ){ sl@0: char zBuf[50]; sl@0: sprintf(zBuf, "(%d) ", rc); sl@0: Tcl_AppendResult(interp, zBuf, sqlite3ErrStr(rc), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: /* sl@0: ** Usage: add_test_collate sl@0: ** sl@0: ** This function is used to test that SQLite selects the correct collation sl@0: ** sequence callback when multiple versions (for different text encodings) sl@0: ** are available. sl@0: ** sl@0: ** Calling this routine registers the collation sequence "test_collate" sl@0: ** with database handle . The second argument must be a list of three sl@0: ** boolean values. If the first is true, then a version of test_collate is sl@0: ** registered for UTF-8, if the second is true, a version is registered for sl@0: ** UTF-16le, if the third is true, a UTF-16be version is available. sl@0: ** Previous versions of test_collate are deleted. sl@0: ** sl@0: ** The collation sequence test_collate is implemented by calling the sl@0: ** following TCL script: sl@0: ** sl@0: ** "test_collate " sl@0: ** sl@0: ** The and are the two values being compared, encoded in UTF-8. sl@0: ** The parameter is the encoding of the collation function that sl@0: ** SQLite selected to call. The TCL test script implements the sl@0: ** "test_collate" proc. sl@0: ** sl@0: ** Note that this will only work with one intepreter at a time, as the sl@0: ** interp pointer to use when evaluating the TCL script is stored in sl@0: ** pTestCollateInterp. sl@0: */ sl@0: static Tcl_Interp* pTestCollateInterp; sl@0: static int test_collate_func( sl@0: void *pCtx, sl@0: int nA, const void *zA, sl@0: int nB, const void *zB sl@0: ){ sl@0: Tcl_Interp *i = pTestCollateInterp; sl@0: int encin = (int)pCtx; sl@0: int res; sl@0: int n; sl@0: sl@0: sqlite3_value *pVal; sl@0: Tcl_Obj *pX; sl@0: sl@0: pX = Tcl_NewStringObj("test_collate", -1); sl@0: Tcl_IncrRefCount(pX); sl@0: sl@0: switch( encin ){ sl@0: case SQLITE_UTF8: sl@0: Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-8",-1)); sl@0: break; sl@0: case SQLITE_UTF16LE: sl@0: Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16LE",-1)); sl@0: break; sl@0: case SQLITE_UTF16BE: sl@0: Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16BE",-1)); sl@0: break; sl@0: default: sl@0: assert(0); sl@0: } sl@0: sl@0: pVal = sqlite3ValueNew(0); sl@0: sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC); sl@0: n = sqlite3_value_bytes(pVal); sl@0: Tcl_ListObjAppendElement(i,pX, sl@0: Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); sl@0: sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC); sl@0: n = sqlite3_value_bytes(pVal); sl@0: Tcl_ListObjAppendElement(i,pX, sl@0: Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); sl@0: sqlite3ValueFree(pVal); sl@0: sl@0: Tcl_EvalObjEx(i, pX, 0); sl@0: Tcl_DecrRefCount(pX); sl@0: Tcl_GetIntFromObj(i, Tcl_GetObjResult(i), &res); sl@0: return res; sl@0: } sl@0: static int test_collate( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: int val; sl@0: sqlite3_value *pVal; sl@0: int rc; sl@0: sl@0: if( objc!=5 ) goto bad_args; sl@0: pTestCollateInterp = interp; sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: sl@0: if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; sl@0: rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF8, sl@0: (void *)SQLITE_UTF8, val?test_collate_func:0); sl@0: if( rc==SQLITE_OK ){ sl@0: const void *zUtf16; sl@0: if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; sl@0: rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE, sl@0: (void *)SQLITE_UTF16LE, val?test_collate_func:0); sl@0: if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; sl@0: sl@0: #if 0 sl@0: if( sqlite3_iMallocFail>0 ){ sl@0: sqlite3_iMallocFail++; sl@0: } sl@0: #endif sl@0: sqlite3_mutex_enter(db->mutex); sl@0: pVal = sqlite3ValueNew(db); sl@0: sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); sl@0: zUtf16 = sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); sl@0: if( db->mallocFailed ){ sl@0: rc = SQLITE_NOMEM; sl@0: }else{ sl@0: rc = sqlite3_create_collation16(db, zUtf16, SQLITE_UTF16BE, sl@0: (void *)SQLITE_UTF16BE, val?test_collate_func:0); sl@0: } sl@0: sqlite3ValueFree(pVal); sl@0: sqlite3_mutex_leave(db->mutex); sl@0: } sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: return TCL_OK; sl@0: sl@0: bad_args: sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " ", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: /* sl@0: ** When the collation needed callback is invoked, record the name of sl@0: ** the requested collating function here. The recorded name is linked sl@0: ** to a TCL variable and used to make sure that the requested collation sl@0: ** name is correct. sl@0: */ sl@0: static char zNeededCollation[200]; sl@0: static char *pzNeededCollation = zNeededCollation; sl@0: sl@0: sl@0: /* sl@0: ** Called when a collating sequence is needed. Registered using sl@0: ** sqlite3_collation_needed16(). sl@0: */ sl@0: static void test_collate_needed_cb( sl@0: void *pCtx, sl@0: sqlite3 *db, sl@0: int eTextRep, sl@0: const void *pName sl@0: ){ sl@0: int enc = ENC(db); sl@0: int i; sl@0: char *z; sl@0: for(z = (char*)pName, i=0; *z || z[1]; z++){ sl@0: if( *z ) zNeededCollation[i++] = *z; sl@0: } sl@0: zNeededCollation[i] = 0; sl@0: sqlite3_create_collation( sl@0: db, "test_collate", ENC(db), (void *)enc, test_collate_func); sl@0: } sl@0: sl@0: /* sl@0: ** Usage: add_test_collate_needed DB sl@0: */ sl@0: static int test_collate_needed( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: int rc; sl@0: sl@0: if( objc!=2 ) goto bad_args; sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb); sl@0: zNeededCollation[0] = 0; sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: return TCL_OK; sl@0: sl@0: bad_args: sl@0: Tcl_WrongNumArgs(interp, 1, objv, "DB"); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: /* sl@0: ** tclcmd: add_alignment_test_collations DB sl@0: ** sl@0: ** Add two new collating sequences to the database DB sl@0: ** sl@0: ** utf16_aligned sl@0: ** utf16_unaligned sl@0: ** sl@0: ** Both collating sequences use the same sort order as BINARY. sl@0: ** The only difference is that the utf16_aligned collating sl@0: ** sequence is declared with the SQLITE_UTF16_ALIGNED flag. sl@0: ** Both collating functions increment the unaligned utf16 counter sl@0: ** whenever they see a string that begins on an odd byte boundary. sl@0: */ sl@0: static int unaligned_string_counter = 0; sl@0: static int alignmentCollFunc( sl@0: void *NotUsed, sl@0: int nKey1, const void *pKey1, sl@0: int nKey2, const void *pKey2 sl@0: ){ sl@0: int rc, n; sl@0: n = nKey10 && 1==(1&(int)pKey1) ) unaligned_string_counter++; sl@0: if( nKey2>0 && 1==(1&(int)pKey2) ) unaligned_string_counter++; sl@0: rc = memcmp(pKey1, pKey2, n); sl@0: if( rc==0 ){ sl@0: rc = nKey1 - nKey2; sl@0: } sl@0: return rc; sl@0: } sl@0: static int add_alignment_test_collations( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: if( objc>=2 ){ sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: sqlite3_create_collation(db, "utf16_unaligned", sl@0: SQLITE_UTF16, sl@0: 0, alignmentCollFunc); sl@0: sqlite3_create_collation(db, "utf16_aligned", sl@0: SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, sl@0: 0, alignmentCollFunc); sl@0: } sl@0: return SQLITE_OK; sl@0: } sl@0: #endif /* !defined(SQLITE_OMIT_UTF16) */ sl@0: sl@0: /* sl@0: ** Usage: add_test_function sl@0: ** sl@0: ** This function is used to test that SQLite selects the correct user sl@0: ** function callback when multiple versions (for different text encodings) sl@0: ** are available. sl@0: ** sl@0: ** Calling this routine registers up to three versions of the user function sl@0: ** "test_function" with database handle . If the second argument is sl@0: ** true, then a version of test_function is registered for UTF-8, if the sl@0: ** third is true, a version is registered for UTF-16le, if the fourth is sl@0: ** true, a UTF-16be version is available. Previous versions of sl@0: ** test_function are deleted. sl@0: ** sl@0: ** The user function is implemented by calling the following TCL script: sl@0: ** sl@0: ** "test_function " sl@0: ** sl@0: ** Where is one of UTF-8, UTF-16LE or UTF16BE, and is the sl@0: ** single argument passed to the SQL function. The value returned by sl@0: ** the TCL script is used as the return value of the SQL function. It sl@0: ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8 sl@0: ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that sl@0: ** prefers UTF-16BE. sl@0: */ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: static void test_function_utf8( sl@0: sqlite3_context *pCtx, sl@0: int nArg, sl@0: sqlite3_value **argv sl@0: ){ sl@0: Tcl_Interp *interp; sl@0: Tcl_Obj *pX; sl@0: sqlite3_value *pVal; sl@0: interp = (Tcl_Interp *)sqlite3_user_data(pCtx); sl@0: pX = Tcl_NewStringObj("test_function", -1); sl@0: Tcl_IncrRefCount(pX); sl@0: Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1)); sl@0: Tcl_ListObjAppendElement(interp, pX, sl@0: Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); sl@0: Tcl_EvalObjEx(interp, pX, 0); sl@0: Tcl_DecrRefCount(pX); sl@0: sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT); sl@0: pVal = sqlite3ValueNew(0); sl@0: sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), sl@0: SQLITE_UTF8, SQLITE_STATIC); sl@0: sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal), sl@0: -1, SQLITE_TRANSIENT); sl@0: sqlite3ValueFree(pVal); sl@0: } sl@0: static void test_function_utf16le( sl@0: sqlite3_context *pCtx, sl@0: int nArg, sl@0: sqlite3_value **argv sl@0: ){ sl@0: Tcl_Interp *interp; sl@0: Tcl_Obj *pX; sl@0: sqlite3_value *pVal; sl@0: interp = (Tcl_Interp *)sqlite3_user_data(pCtx); sl@0: pX = Tcl_NewStringObj("test_function", -1); sl@0: Tcl_IncrRefCount(pX); sl@0: Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1)); sl@0: Tcl_ListObjAppendElement(interp, pX, sl@0: Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); sl@0: Tcl_EvalObjEx(interp, pX, 0); sl@0: Tcl_DecrRefCount(pX); sl@0: pVal = sqlite3ValueNew(0); sl@0: sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), sl@0: SQLITE_UTF8, SQLITE_STATIC); sl@0: sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT); sl@0: sqlite3ValueFree(pVal); sl@0: } sl@0: static void test_function_utf16be( sl@0: sqlite3_context *pCtx, sl@0: int nArg, sl@0: sqlite3_value **argv sl@0: ){ sl@0: Tcl_Interp *interp; sl@0: Tcl_Obj *pX; sl@0: sqlite3_value *pVal; sl@0: interp = (Tcl_Interp *)sqlite3_user_data(pCtx); sl@0: pX = Tcl_NewStringObj("test_function", -1); sl@0: Tcl_IncrRefCount(pX); sl@0: Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1)); sl@0: Tcl_ListObjAppendElement(interp, pX, sl@0: Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); sl@0: Tcl_EvalObjEx(interp, pX, 0); sl@0: Tcl_DecrRefCount(pX); sl@0: pVal = sqlite3ValueNew(0); sl@0: sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), sl@0: SQLITE_UTF8, SQLITE_STATIC); sl@0: sqlite3_result_text16(pCtx, sqlite3_value_text16le(pVal), sl@0: -1, SQLITE_TRANSIENT); sl@0: sqlite3_result_text16be(pCtx, sqlite3_value_text16le(pVal), sl@0: -1, SQLITE_TRANSIENT); sl@0: sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal), sl@0: -1, SQLITE_TRANSIENT); sl@0: sqlite3ValueFree(pVal); sl@0: } sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: static int test_function( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: sqlite3 *db; sl@0: int val; sl@0: sl@0: if( objc!=5 ) goto bad_args; sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: sl@0: if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; sl@0: if( val ){ sl@0: sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8, sl@0: interp, test_function_utf8, 0, 0); sl@0: } sl@0: if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; sl@0: if( val ){ sl@0: sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE, sl@0: interp, test_function_utf16le, 0, 0); sl@0: } sl@0: if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; sl@0: if( val ){ sl@0: sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE, sl@0: interp, test_function_utf16be, 0, 0); sl@0: } sl@0: sl@0: return TCL_OK; sl@0: bad_args: sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " ", 0); sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: test_errstr sl@0: ** sl@0: ** Test that the english language string equivalents for sqlite error codes sl@0: ** are sane. The parameter is an integer representing an sqlite error code. sl@0: ** The result is a list of two elements, the string representation of the sl@0: ** error code and the english language explanation. sl@0: */ sl@0: static int test_errstr( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: char *zCode; sl@0: int i; sl@0: if( objc!=1 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, ""); sl@0: } sl@0: sl@0: zCode = Tcl_GetString(objv[1]); sl@0: for(i=0; i<200; i++){ sl@0: if( 0==strcmp(t1ErrorName(i), zCode) ) break; sl@0: } sl@0: Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: breakpoint sl@0: ** sl@0: ** This routine exists for one purpose - to provide a place to put a sl@0: ** breakpoint with GDB that can be triggered using TCL code. The use sl@0: ** for this is when a particular test fails on (say) the 1485th iteration. sl@0: ** In the TCL test script, we can add code like this: sl@0: ** sl@0: ** if {$i==1485} breakpoint sl@0: ** sl@0: ** Then run testfixture in the debugger and wait for the breakpoint to sl@0: ** fire. Then additional breakpoints can be set to trace down the bug. sl@0: */ sl@0: static int test_breakpoint( sl@0: void *NotUsed, sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int argc, /* Number of arguments */ sl@0: char **argv /* Text of each argument */ sl@0: ){ sl@0: return TCL_OK; /* Do nothing */ sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_zeroblob STMT IDX N sl@0: ** sl@0: ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement. sl@0: ** IDX is the index of a wildcard in the prepared statement. This command sl@0: ** binds a N-byte zero-filled BLOB to the wildcard. sl@0: */ sl@0: static int test_bind_zeroblob( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: int n; sl@0: int rc; sl@0: sl@0: if( objc!=4 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX N"); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &n) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_zeroblob(pStmt, idx, n); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_int STMT N VALUE sl@0: ** sl@0: ** Test the sqlite3_bind_int interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a 32-bit integer VALUE to that wildcard. sl@0: */ sl@0: static int test_bind_int( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: int value; sl@0: int rc; sl@0: sl@0: if( objc!=4 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_int(pStmt, idx, value); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_int64 STMT N VALUE sl@0: ** sl@0: ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a 64-bit integer VALUE to that wildcard. sl@0: */ sl@0: static int test_bind_int64( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: i64 value; sl@0: int rc; sl@0: sl@0: if( objc!=4 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: if( Tcl_GetWideIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_int64(pStmt, idx, value); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_double STMT N VALUE sl@0: ** sl@0: ** Test the sqlite3_bind_double interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a 64-bit integer VALUE to that wildcard. sl@0: */ sl@0: static int test_bind_double( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: double value; sl@0: int rc; sl@0: const char *zVal; sl@0: int i; sl@0: static const struct { sl@0: const char *zName; /* Name of the special floating point value */ sl@0: unsigned int iUpper; /* Upper 32 bits */ sl@0: unsigned int iLower; /* Lower 32 bits */ sl@0: } aSpecialFp[] = { sl@0: { "NaN", 0x7fffffff, 0xffffffff }, sl@0: { "SNaN", 0x7ff7ffff, 0xffffffff }, sl@0: { "-NaN", 0xffffffff, 0xffffffff }, sl@0: { "-SNaN", 0xfff7ffff, 0xffffffff }, sl@0: { "+Inf", 0x7ff00000, 0x00000000 }, sl@0: { "-Inf", 0xfff00000, 0x00000000 }, sl@0: { "Epsilon", 0x00000000, 0x00000001 }, sl@0: { "-Epsilon", 0x80000000, 0x00000001 }, sl@0: { "NaN0", 0x7ff80000, 0x00000000 }, sl@0: { "-NaN0", 0xfff80000, 0x00000000 }, sl@0: }; sl@0: sl@0: if( objc!=4 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: sl@0: /* Intercept the string "NaN" and generate a NaN value for it. sl@0: ** All other strings are passed through to Tcl_GetDoubleFromObj(). sl@0: ** Tcl_GetDoubleFromObj() should understand "NaN" but some versions sl@0: ** contain a bug. sl@0: */ sl@0: zVal = Tcl_GetString(objv[3]); sl@0: for(i=0; i=sizeof(aSpecialFp)/sizeof(aSpecialFp[0]) && sl@0: Tcl_GetDoubleFromObj(interp, objv[3], &value) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: rc = sqlite3_bind_double(pStmt, idx, value); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_null STMT N sl@0: ** sl@0: ** Test the sqlite3_bind_null interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a NULL to the wildcard. sl@0: */ sl@0: static int test_bind_null( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: int rc; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_null(pStmt, idx); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_text STMT N STRING BYTES sl@0: ** sl@0: ** Test the sqlite3_bind_text interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes sl@0: ** long. sl@0: */ sl@0: static int test_bind_text( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: int bytes; sl@0: char *value; sl@0: int rc; sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: value = (char*)Tcl_GetByteArrayFromObj(objv[3], &bytes); sl@0: if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES sl@0: ** sl@0: ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes sl@0: ** long. sl@0: */ sl@0: static int test_bind_text16( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: int bytes; sl@0: char *value; sl@0: int rc; sl@0: sl@0: void (*xDel)() = (objc==6?SQLITE_STATIC:SQLITE_TRANSIENT); sl@0: Tcl_Obj *oStmt = objv[objc-4]; sl@0: Tcl_Obj *oN = objv[objc-3]; sl@0: Tcl_Obj *oString = objv[objc-2]; sl@0: Tcl_Obj *oBytes = objv[objc-1]; sl@0: sl@0: if( objc!=5 && objc!=6){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(oStmt), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR; sl@0: value = (char*)Tcl_GetByteArrayFromObj(oString, 0); sl@0: if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES sl@0: ** sl@0: ** Test the sqlite3_bind_blob interface. STMT is a prepared statement. sl@0: ** N is the index of a wildcard in the prepared statement. This command sl@0: ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size. sl@0: */ sl@0: static int test_bind_blob( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int idx; sl@0: int bytes; sl@0: char *value; sl@0: int rc; sl@0: sqlite3_destructor_type xDestructor = SQLITE_TRANSIENT; sl@0: sl@0: if( objc!=5 && objc!=6 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " STMT N DATA BYTES", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( objc==6 ){ sl@0: xDestructor = SQLITE_STATIC; sl@0: objv++; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; sl@0: value = Tcl_GetString(objv[3]); sl@0: if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_bind_blob(pStmt, idx, value, bytes, xDestructor); sl@0: if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_parameter_count STMT sl@0: ** sl@0: ** Return the number of wildcards in the given statement. sl@0: */ sl@0: static int test_bind_parameter_count( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "STMT"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_parameter_name STMT N sl@0: ** sl@0: ** Return the name of the Nth wildcard. The first wildcard is 1. sl@0: ** An empty string is returned if N is out of range or if the wildcard sl@0: ** is nameless. sl@0: */ sl@0: static int test_bind_parameter_name( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int i; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "STMT N"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &i) ) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, sl@0: Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt,i),-1) sl@0: ); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_bind_parameter_index STMT NAME sl@0: ** sl@0: ** Return the index of the wildcard called NAME. Return 0 if there is sl@0: ** no such wildcard. sl@0: */ sl@0: static int test_bind_parameter_index( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "STMT NAME"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, sl@0: Tcl_NewIntObj( sl@0: sqlite3_bind_parameter_index(pStmt,Tcl_GetString(objv[2])) sl@0: ) sl@0: ); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_clear_bindings STMT sl@0: ** sl@0: */ sl@0: static int test_clear_bindings( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "STMT"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_sleep MILLISECONDS sl@0: */ sl@0: static int test_sleep( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: int ms; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "MILLISECONDS"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( Tcl_GetIntFromObj(interp, objv[1], &ms) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_sleep(ms))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_errcode DB sl@0: ** sl@0: ** Return the string representation of the most recent sqlite3_* API sl@0: ** error code. e.g. "SQLITE_ERROR". sl@0: */ sl@0: static int test_errcode( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: int rc; sl@0: char zBuf[30]; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: rc = sqlite3_errcode(db); sl@0: if( (rc&0xff)==rc ){ sl@0: zBuf[0] = 0; sl@0: }else{ sl@0: sprintf(zBuf,"+%d", rc>>8); sl@0: } sl@0: Tcl_AppendResult(interp, (char *)t1ErrorName(rc), zBuf, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: test_errmsg DB sl@0: ** sl@0: ** Returns the UTF-8 representation of the error message string for the sl@0: ** most recent sqlite3_* API call. sl@0: */ sl@0: static int test_errmsg( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: const char *zErr; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: sl@0: zErr = sqlite3_errmsg(db); sl@0: Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: test_errmsg16 DB sl@0: ** sl@0: ** Returns the UTF-16 representation of the error message string for the sl@0: ** most recent sqlite3_* API call. This is a byte array object at the TCL sl@0: ** level, and it includes the 0x00 0x00 terminator bytes at the end of the sl@0: ** UTF-16 string. sl@0: */ sl@0: static int test_errmsg16( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: sqlite3 *db; sl@0: const void *zErr; sl@0: int bytes = 0; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: sl@0: zErr = sqlite3_errmsg16(db); sl@0: if( zErr ){ sl@0: bytes = sqlite3Utf16ByteLen(zErr, -1); sl@0: } sl@0: Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes)); sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_prepare DB sql bytes tailvar sl@0: ** sl@0: ** Compile up to bytes of the supplied SQL string using sl@0: ** database handle . The parameter is the name of a global sl@0: ** variable that is set to the unused portion of (if any). A sl@0: ** STMT handle is returned. sl@0: */ sl@0: static int test_prepare( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: const char *zSql; sl@0: int bytes; sl@0: const char *zTail = 0; sl@0: sqlite3_stmt *pStmt = 0; sl@0: char zBuf[50]; sl@0: int rc; sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: zSql = Tcl_GetString(objv[2]); sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_prepare(db, zSql, bytes, &pStmt, &zTail); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: if( zTail ){ sl@0: if( bytes>=0 ){ sl@0: bytes = bytes - (zTail-zSql); sl@0: } sl@0: if( strlen(zTail) bytes of the supplied SQL string using sl@0: ** database handle . The parameter is the name of a global sl@0: ** variable that is set to the unused portion of (if any). A sl@0: ** STMT handle is returned. sl@0: */ sl@0: static int test_prepare_v2( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: const char *zSql; sl@0: int bytes; sl@0: const char *zTail = 0; sl@0: sqlite3_stmt *pStmt = 0; sl@0: char zBuf[50]; sl@0: int rc; sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: zSql = Tcl_GetString(objv[2]); sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_prepare_v2(db, zSql, bytes, &pStmt, &zTail); sl@0: assert(rc==SQLITE_OK || pStmt==0); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: if( zTail ){ sl@0: if( bytes>=0 ){ sl@0: bytes = bytes - (zTail-zSql); sl@0: } sl@0: Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); sl@0: } sl@0: if( rc!=SQLITE_OK ){ sl@0: assert( pStmt==0 ); sl@0: sprintf(zBuf, "(%d) ", rc); sl@0: Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( pStmt ){ sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_prepare_tkt3134 DB sl@0: ** sl@0: ** Generate a prepared statement for a zero-byte string as a test sl@0: ** for ticket #3134. The string should be preceeded by a zero byte. sl@0: */ sl@0: static int test_prepare_tkt3134( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: static const char zSql[] = "\000SELECT 1"; sl@0: sqlite3_stmt *pStmt = 0; sl@0: char zBuf[50]; sl@0: int rc; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: rc = sqlite3_prepare_v2(db, &zSql[1], 0, &pStmt, 0); sl@0: assert(rc==SQLITE_OK || pStmt==0); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: if( rc!=SQLITE_OK ){ sl@0: assert( pStmt==0 ); sl@0: sprintf(zBuf, "(%d) ", rc); sl@0: Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( pStmt ){ sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_prepare16 DB sql bytes tailvar sl@0: ** sl@0: ** Compile up to bytes of the supplied SQL string using sl@0: ** database handle . The parameter is the name of a global sl@0: ** variable that is set to the unused portion of (if any). A sl@0: ** STMT handle is returned. sl@0: */ sl@0: static int test_prepare16( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: sqlite3 *db; sl@0: const void *zSql; sl@0: const void *zTail = 0; sl@0: Tcl_Obj *pTail = 0; sl@0: sqlite3_stmt *pStmt = 0; sl@0: char zBuf[50]; sl@0: int rc; sl@0: int bytes; /* The integer specified as arg 3 */ sl@0: int objlen; /* The byte-array length of arg 2 */ sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen); sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_prepare16(db, zSql, bytes, &pStmt, &zTail); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: if( rc ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( zTail ){ sl@0: objlen = objlen - ((u8 *)zTail-(u8 *)zSql); sl@0: }else{ sl@0: objlen = 0; sl@0: } sl@0: pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen); sl@0: Tcl_IncrRefCount(pTail); sl@0: Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0); sl@0: Tcl_DecrRefCount(pTail); sl@0: sl@0: if( pStmt ){ sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; sl@0: } sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_prepare16_v2 DB sql bytes tailvar sl@0: ** sl@0: ** Compile up to bytes of the supplied SQL string using sl@0: ** database handle . The parameter is the name of a global sl@0: ** variable that is set to the unused portion of (if any). A sl@0: ** STMT handle is returned. sl@0: */ sl@0: static int test_prepare16_v2( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: sqlite3 *db; sl@0: const void *zSql; sl@0: const void *zTail = 0; sl@0: Tcl_Obj *pTail = 0; sl@0: sqlite3_stmt *pStmt = 0; sl@0: char zBuf[50]; sl@0: int rc; sl@0: int bytes; /* The integer specified as arg 3 */ sl@0: int objlen; /* The byte-array length of arg 2 */ sl@0: sl@0: if( objc!=5 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen); sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; sl@0: sl@0: rc = sqlite3_prepare16_v2(db, zSql, bytes, &pStmt, &zTail); sl@0: if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; sl@0: if( rc ){ sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( zTail ){ sl@0: objlen = objlen - ((u8 *)zTail-(u8 *)zSql); sl@0: }else{ sl@0: objlen = 0; sl@0: } sl@0: pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen); sl@0: Tcl_IncrRefCount(pTail); sl@0: Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0); sl@0: Tcl_DecrRefCount(pTail); sl@0: sl@0: if( pStmt ){ sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; sl@0: } sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_open filename ?options-list? sl@0: */ sl@0: static int test_open( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: const char *zFilename; sl@0: sqlite3 *db; sl@0: int rc; sl@0: char zBuf[100]; sl@0: sl@0: if( objc!=3 && objc!=2 && objc!=1 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " filename options-list", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: zFilename = objc>1 ? Tcl_GetString(objv[1]) : 0; sl@0: rc = sqlite3_open(zFilename, &db); sl@0: sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_open16 filename options sl@0: */ sl@0: static int test_open16( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: const void *zFilename; sl@0: sqlite3 *db; sl@0: int rc; sl@0: char zBuf[100]; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " filename options-list", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: zFilename = Tcl_GetByteArrayFromObj(objv[1], 0); sl@0: rc = sqlite3_open16(zFilename, &db); sl@0: sl@0: if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_complete16 sl@0: ** sl@0: ** Return 1 if the supplied argument is a complete SQL statement, or zero sl@0: ** otherwise. sl@0: */ sl@0: static int test_complete16( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16) sl@0: char *zBuf; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, ""); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: zBuf = (char*)Tcl_GetByteArrayFromObj(objv[1], 0); sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf))); sl@0: #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */ sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_step STMT sl@0: ** sl@0: ** Advance the statement to the next row. sl@0: */ sl@0: static int test_step( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int rc; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: rc = sqlite3_step(pStmt); sl@0: sl@0: /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */ sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_count STMT sl@0: ** sl@0: ** Return the number of columns returned by the sql statement STMT. sl@0: */ sl@0: static int test_column_count( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_column_count(pStmt))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_type STMT column sl@0: ** sl@0: ** Return the type of the data in column 'column' of the current row. sl@0: */ sl@0: static int test_column_type( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: int tp; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: sl@0: tp = sqlite3_column_type(pStmt, col); sl@0: switch( tp ){ sl@0: case SQLITE_INTEGER: sl@0: Tcl_SetResult(interp, "INTEGER", TCL_STATIC); sl@0: break; sl@0: case SQLITE_NULL: sl@0: Tcl_SetResult(interp, "NULL", TCL_STATIC); sl@0: break; sl@0: case SQLITE_FLOAT: sl@0: Tcl_SetResult(interp, "FLOAT", TCL_STATIC); sl@0: break; sl@0: case SQLITE_TEXT: sl@0: Tcl_SetResult(interp, "TEXT", TCL_STATIC); sl@0: break; sl@0: case SQLITE_BLOB: sl@0: Tcl_SetResult(interp, "BLOB", TCL_STATIC); sl@0: break; sl@0: default: sl@0: assert(0); sl@0: } sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_int64 STMT column sl@0: ** sl@0: ** Return the data in column 'column' of the current row cast as an sl@0: ** wide (64-bit) integer. sl@0: */ sl@0: static int test_column_int64( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: i64 iVal; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: sl@0: iVal = sqlite3_column_int64(pStmt, col); sl@0: Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_blob STMT column sl@0: */ sl@0: static int test_column_blob( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: sl@0: int len; sl@0: const void *pBlob; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: sl@0: len = sqlite3_column_bytes(pStmt, col); sl@0: pBlob = sqlite3_column_blob(pStmt, col); sl@0: Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_double STMT column sl@0: ** sl@0: ** Return the data in column 'column' of the current row cast as a double. sl@0: */ sl@0: static int test_column_double( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: double rVal; sl@0: sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: sl@0: rVal = sqlite3_column_double(pStmt, col); sl@0: Tcl_SetObjResult(interp, Tcl_NewDoubleObj(rVal)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_data_count STMT sl@0: ** sl@0: ** Return the number of columns returned by the sql statement STMT. sl@0: */ sl@0: static int test_data_count( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_data_count(pStmt))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_text STMT column sl@0: ** sl@0: ** Usage: sqlite3_column_decltype STMT column sl@0: ** sl@0: ** Usage: sqlite3_column_name STMT column sl@0: */ sl@0: static int test_stmt_utf8( sl@0: void * clientData, /* Pointer to SQLite API function to be invoke */ sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: const char *(*xFunc)(sqlite3_stmt*, int); sl@0: const char *zRet; sl@0: sl@0: xFunc = (const char *(*)(sqlite3_stmt*, int))clientData; sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: zRet = xFunc(pStmt, col); sl@0: if( zRet ){ sl@0: Tcl_SetResult(interp, (char *)zRet, 0); sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: static int test_global_recover( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_GLOBALRECOVER sl@0: int rc; sl@0: if( objc!=1 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, ""); sl@0: return TCL_ERROR; sl@0: } sl@0: rc = sqlite3_global_recover(); sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); sl@0: #endif sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_text STMT column sl@0: ** sl@0: ** Usage: sqlite3_column_decltype STMT column sl@0: ** sl@0: ** Usage: sqlite3_column_name STMT column sl@0: */ sl@0: static int test_stmt_utf16( sl@0: void * clientData, /* Pointer to SQLite API function to be invoked */ sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: Tcl_Obj *pRet; sl@0: const void *zName16; sl@0: const void *(*xFunc)(sqlite3_stmt*, int); sl@0: sl@0: xFunc = (const void *(*)(sqlite3_stmt*, int))clientData; sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: sl@0: zName16 = xFunc(pStmt, col); sl@0: if( zName16 ){ sl@0: pRet = Tcl_NewByteArrayObj(zName16, sqlite3Utf16ByteLen(zName16, -1)+2); sl@0: Tcl_SetObjResult(interp, pRet); sl@0: } sl@0: #endif /* SQLITE_OMIT_UTF16 */ sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_column_int STMT column sl@0: ** sl@0: ** Usage: sqlite3_column_bytes STMT column sl@0: ** sl@0: ** Usage: sqlite3_column_bytes16 STMT column sl@0: ** sl@0: */ sl@0: static int test_stmt_int( sl@0: void * clientData, /* Pointer to SQLite API function to be invoked */ sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_stmt *pStmt; sl@0: int col; sl@0: int (*xFunc)(sqlite3_stmt*, int); sl@0: sl@0: xFunc = (int (*)(sqlite3_stmt*, int))clientData; sl@0: if( objc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetString(objv[0]), " STMT column", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: sl@0: if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; sl@0: if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; sl@0: sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(xFunc(pStmt, col))); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite_set_magic DB MAGIC-NUMBER sl@0: ** sl@0: ** Set the db->magic value. This is used to test error recovery logic. sl@0: */ sl@0: static int sqlite_set_magic( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int argc, sl@0: char **argv sl@0: ){ sl@0: sqlite3 *db; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB MAGIC", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){ sl@0: db->magic = SQLITE_MAGIC_OPEN; sl@0: }else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){ sl@0: db->magic = SQLITE_MAGIC_CLOSED; sl@0: }else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){ sl@0: db->magic = SQLITE_MAGIC_BUSY; sl@0: }else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){ sl@0: db->magic = SQLITE_MAGIC_ERROR; sl@0: }else if( Tcl_GetInt(interp, argv[2], &db->magic) ){ sl@0: return TCL_ERROR; sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_interrupt DB sl@0: ** sl@0: ** Trigger an interrupt on DB sl@0: */ sl@0: static int test_interrupt( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int argc, sl@0: char **argv sl@0: ){ sl@0: sqlite3 *db; sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: sqlite3_interrupt(db); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: static u8 *sqlite3_stack_baseline = 0; sl@0: sl@0: /* sl@0: ** Fill the stack with a known bitpattern. sl@0: */ sl@0: static void prepStack(void){ sl@0: int i; sl@0: u32 bigBuf[65536]; sl@0: for(i=0; i=0 && ((u32*)sqlite3_stack_baseline)[-i]==0xdeadbeef; i--){} sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(i*4)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite_delete_function DB function-name sl@0: ** sl@0: ** Delete the user function 'function-name' from database handle DB. It sl@0: ** is assumed that the user function was created as UTF8, any number of sl@0: ** arguments (the way the TCL interface does it). sl@0: */ sl@0: static int delete_function( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int argc, sl@0: char **argv sl@0: ){ sl@0: int rc; sl@0: sqlite3 *db; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB function-name", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, 0, 0, 0); sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite_delete_collation DB collation-name sl@0: ** sl@0: ** Delete the collation sequence 'collation-name' from database handle sl@0: ** DB. It is assumed that the collation sequence was created as UTF8 (the sl@0: ** way the TCL interface does it). sl@0: */ sl@0: static int delete_collation( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int argc, sl@0: char **argv sl@0: ){ sl@0: int rc; sl@0: sqlite3 *db; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB function-name", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: rc = sqlite3_create_collation(db, argv[2], SQLITE_UTF8, 0, 0); sl@0: Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_get_autocommit DB sl@0: ** sl@0: ** Return true if the database DB is currently in auto-commit mode. sl@0: ** Return false if not. sl@0: */ sl@0: static int get_autocommit( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int argc, sl@0: char **argv sl@0: ){ sl@0: char zBuf[30]; sl@0: sqlite3 *db; sl@0: if( argc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: sprintf(zBuf, "%d", sqlite3_get_autocommit(db)); sl@0: Tcl_AppendResult(interp, zBuf, 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_busy_timeout DB MS sl@0: ** sl@0: ** Set the busy timeout. This is more easily done using the timeout sl@0: ** method of the TCL interface. But we need a way to test the case sl@0: ** where it returns SQLITE_MISUSE. sl@0: */ sl@0: static int test_busy_timeout( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int argc, sl@0: char **argv sl@0: ){ sl@0: int rc, ms; sl@0: sqlite3 *db; sl@0: if( argc!=3 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], sl@0: " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; sl@0: if( Tcl_GetInt(interp, argv[2], &ms) ) return TCL_ERROR; sl@0: rc = sqlite3_busy_timeout(db, ms); sl@0: Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: tcl_variable_type VARIABLENAME sl@0: ** sl@0: ** Return the name of the internal representation for the sl@0: ** value of the given variable. sl@0: */ sl@0: static int tcl_variable_type( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: Tcl_Obj *pVar; sl@0: if( objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "VARIABLE"); sl@0: return TCL_ERROR; sl@0: } sl@0: pVar = Tcl_GetVar2Ex(interp, Tcl_GetString(objv[1]), 0, TCL_LEAVE_ERR_MSG); sl@0: if( pVar==0 ) return TCL_ERROR; sl@0: if( pVar->typePtr ){ sl@0: Tcl_SetObjResult(interp, Tcl_NewStringObj(pVar->typePtr->name, -1)); sl@0: } sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_release_memory ?N? sl@0: ** sl@0: ** Attempt to release memory currently held but not actually required. sl@0: ** The integer N is the number of bytes we are trying to release. The sl@0: ** return value is the amount of memory actually released. sl@0: */ sl@0: static int test_release_memory( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO) sl@0: int N; sl@0: int amt; sl@0: if( objc!=1 && objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "?N?"); sl@0: return TCL_ERROR; sl@0: } sl@0: if( objc==2 ){ sl@0: if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; sl@0: }else{ sl@0: N = -1; sl@0: } sl@0: amt = sqlite3_release_memory(N); sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(amt)); sl@0: #endif sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_soft_heap_limit ?N? sl@0: ** sl@0: ** Query or set the soft heap limit for the current thread. The sl@0: ** limit is only changed if the N is present. The previous limit sl@0: ** is returned. sl@0: */ sl@0: static int test_soft_heap_limit( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: static int softHeapLimit = 0; sl@0: int amt; sl@0: if( objc!=1 && objc!=2 ){ sl@0: Tcl_WrongNumArgs(interp, 1, objv, "?N?"); sl@0: return TCL_ERROR; sl@0: } sl@0: amt = softHeapLimit; sl@0: if( objc==2 ){ sl@0: int N; sl@0: if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; sl@0: sqlite3_soft_heap_limit(N); sl@0: softHeapLimit = N; sl@0: } sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(amt)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Usage: sqlite3_thread_cleanup sl@0: ** sl@0: ** Call the sqlite3_thread_cleanup API. sl@0: */ sl@0: static int test_thread_cleanup( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3_thread_cleanup(); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** Usage: sqlite3_pager_refcounts DB sl@0: ** sl@0: ** Return a list of numbers which are the PagerRefcount for all sl@0: ** pagers on each database connection. sl@0: */ sl@0: static int test_pager_refcounts( sl@0: void * clientData, sl@0: Tcl_Interp *interp, sl@0: int objc, sl@0: Tcl_Obj *CONST objv[] sl@0: ){ sl@0: sqlite3 *db; sl@0: int i; sl@0: int v, *a; sl@0: Tcl_Obj *pResult; sl@0: sl@0: if( objc!=2 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " DB", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: pResult = Tcl_NewObj(); sl@0: for(i=0; inDb; i++){ sl@0: if( db->aDb[i].pBt==0 ){ sl@0: v = -1; sl@0: }else{ sl@0: sqlite3_mutex_enter(db->mutex); sl@0: a = sqlite3PagerStats(sqlite3BtreePager(db->aDb[i].pBt)); sl@0: v = a[0]; sl@0: sqlite3_mutex_leave(db->mutex); sl@0: } sl@0: Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(v)); sl@0: } sl@0: Tcl_SetObjResult(interp, pResult); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** tclcmd: working_64bit_int sl@0: ** sl@0: ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This sl@0: ** leads to a number of test failures. The present command checks the sl@0: ** TCL build to see whether or not it supports 64-bit integers. It sl@0: ** returns TRUE if it does and FALSE if not. sl@0: ** sl@0: ** This command is used to warn users that their TCL build is defective sl@0: ** and that the errors they are seeing in the test scripts might be sl@0: ** a result of their defective TCL rather than problems in SQLite. sl@0: */ sl@0: static int working_64bit_int( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: Tcl_Obj *pTestObj; sl@0: int working = 0; sl@0: sl@0: pTestObj = Tcl_NewWideIntObj(1000000*(i64)1234567890); sl@0: working = strcmp(Tcl_GetString(pTestObj), "1234567890000000")==0; sl@0: Tcl_DecrRefCount(pTestObj); sl@0: Tcl_SetObjResult(interp, Tcl_NewBooleanObj(working)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** tclcmd: vfs_unlink_test sl@0: ** sl@0: ** This TCL command unregisters the primary VFS and then registers sl@0: ** it back again. This is used to test the ability to register a sl@0: ** VFS when none are previously registered, and the ability to sl@0: ** unregister the only available VFS. Ticket #2738 sl@0: */ sl@0: static int vfs_unlink_test( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: int i; sl@0: sqlite3_vfs *pMain; sl@0: sqlite3_vfs *apVfs[20]; sl@0: sqlite3_vfs one, two; sl@0: sl@0: sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */ sl@0: one.zName = "__one"; sl@0: two.zName = "__two"; sl@0: sl@0: /* Calling sqlite3_vfs_register with 2nd argument of 0 does not sl@0: ** change the default VFS sl@0: */ sl@0: pMain = sqlite3_vfs_find(0); sl@0: sqlite3_vfs_register(&one, 0); sl@0: assert( pMain==0 || pMain==sqlite3_vfs_find(0) ); sl@0: sqlite3_vfs_register(&two, 0); sl@0: assert( pMain==0 || pMain==sqlite3_vfs_find(0) ); sl@0: sl@0: /* We can find a VFS by its name */ sl@0: assert( sqlite3_vfs_find("__one")==&one ); sl@0: assert( sqlite3_vfs_find("__two")==&two ); sl@0: sl@0: /* Calling sqlite_vfs_register with non-zero second parameter changes the sl@0: ** default VFS, even if the 1st parameter is an existig VFS that is sl@0: ** previously registered as the non-default. sl@0: */ sl@0: sqlite3_vfs_register(&one, 1); sl@0: assert( sqlite3_vfs_find("__one")==&one ); sl@0: assert( sqlite3_vfs_find("__two")==&two ); sl@0: assert( sqlite3_vfs_find(0)==&one ); sl@0: sqlite3_vfs_register(&two, 1); sl@0: assert( sqlite3_vfs_find("__one")==&one ); sl@0: assert( sqlite3_vfs_find("__two")==&two ); sl@0: assert( sqlite3_vfs_find(0)==&two ); sl@0: if( pMain ){ sl@0: sqlite3_vfs_register(pMain, 1); sl@0: assert( sqlite3_vfs_find("__one")==&one ); sl@0: assert( sqlite3_vfs_find("__two")==&two ); sl@0: assert( sqlite3_vfs_find(0)==pMain ); sl@0: } sl@0: sl@0: /* Unlink the default VFS. Repeat until there are no more VFSes sl@0: ** registered. sl@0: */ sl@0: for(i=0; izName) ); sl@0: sqlite3_vfs_unregister(apVfs[i]); sl@0: assert( 0==sqlite3_vfs_find(apVfs[i]->zName) ); sl@0: } sl@0: } sl@0: assert( 0==sqlite3_vfs_find(0) ); sl@0: sl@0: /* Register the main VFS as non-default (will be made default, since sl@0: ** it'll be the only one in existence). sl@0: */ sl@0: sqlite3_vfs_register(pMain, 0); sl@0: assert( sqlite3_vfs_find(0)==pMain ); sl@0: sl@0: /* Un-register the main VFS again to restore an empty VFS list */ sl@0: sqlite3_vfs_unregister(pMain); sl@0: assert( 0==sqlite3_vfs_find(0) ); sl@0: sl@0: /* Relink all VFSes in reverse order. */ sl@0: for(i=sizeof(apVfs)/sizeof(apVfs[0])-1; i>=0; i--){ sl@0: if( apVfs[i] ){ sl@0: sqlite3_vfs_register(apVfs[i], 1); sl@0: assert( apVfs[i]==sqlite3_vfs_find(0) ); sl@0: assert( apVfs[i]==sqlite3_vfs_find(apVfs[i]->zName) ); sl@0: } sl@0: } sl@0: sl@0: /* Unregister out sample VFSes. */ sl@0: sqlite3_vfs_unregister(&one); sl@0: sqlite3_vfs_unregister(&two); sl@0: sl@0: /* Unregistering a VFS that is not currently registered is harmless */ sl@0: sqlite3_vfs_unregister(&one); sl@0: sqlite3_vfs_unregister(&two); sl@0: assert( sqlite3_vfs_find("__one")==0 ); sl@0: assert( sqlite3_vfs_find("__two")==0 ); sl@0: sl@0: /* We should be left with the original default VFS back as the sl@0: ** original */ sl@0: assert( sqlite3_vfs_find(0)==pMain ); sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** tclcmd: vfs_initfail_test sl@0: ** sl@0: ** This TCL command attempts to vfs_find and vfs_register when the sl@0: ** sqlite3_initialize() interface is failing. All calls should fail. sl@0: */ sl@0: static int vfs_initfail_test( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: sqlite3_vfs one; sl@0: one.zName = "__one"; sl@0: sl@0: if( sqlite3_vfs_find(0) ) return TCL_ERROR; sl@0: sqlite3_vfs_register(&one, 0); sl@0: if( sqlite3_vfs_find(0) ) return TCL_ERROR; sl@0: sqlite3_vfs_register(&one, 1); sl@0: if( sqlite3_vfs_find(0) ) return TCL_ERROR; sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** Saved VFSes sl@0: */ sl@0: static sqlite3_vfs *apVfs[20]; sl@0: static int nVfs = 0; sl@0: sl@0: /* sl@0: ** tclcmd: vfs_unregister_all sl@0: ** sl@0: ** Unregister all VFSes. sl@0: */ sl@0: static int vfs_unregister_all( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: int i; sl@0: for(i=0; ipNext){ sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(pVfs->zName, -1)); sl@0: } sl@0: Tcl_SetObjResult(interp, pRet); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** tclcmd: sqlite3_limit DB ID VALUE sl@0: ** sl@0: ** This TCL command runs the sqlite3_limit interface and sl@0: ** verifies correct operation of the same. sl@0: */ sl@0: static int test_limit( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: sqlite3 *db; sl@0: int rc; sl@0: static const struct { sl@0: char *zName; sl@0: int id; sl@0: } aId[] = { sl@0: { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH }, sl@0: { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH }, sl@0: { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN }, sl@0: { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH }, sl@0: { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT }, sl@0: { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP }, sl@0: { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG }, sl@0: { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED }, sl@0: { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH }, sl@0: { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER }, sl@0: sl@0: /* Out of range test cases */ sl@0: { "SQLITE_LIMIT_TOOSMALL", -1, }, sl@0: { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_VARIABLE_NUMBER+1 }, sl@0: }; sl@0: int i, id; sl@0: int val; sl@0: const char *zId; sl@0: sl@0: if( objc!=4 ){ sl@0: Tcl_AppendResult(interp, "wrong # args: should be \"", sl@0: Tcl_GetStringFromObj(objv[0], 0), " DB ID VALUE", 0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sl@0: zId = Tcl_GetString(objv[2]); sl@0: for(i=0; i=sizeof(aId)/sizeof(aId[0]) ){ sl@0: Tcl_AppendResult(interp, "unknown limit type: ", zId, (char*)0); sl@0: return TCL_ERROR; sl@0: } sl@0: if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR; sl@0: rc = sqlite3_limit(db, id, val); sl@0: Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** tclcmd: save_prng_state sl@0: ** sl@0: ** Save the state of the pseudo-random number generator. sl@0: ** At the same time, verify that sqlite3_test_control works even when sl@0: ** called with an out-of-range opcode. sl@0: */ sl@0: static int save_prng_state( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: int rc = sqlite3_test_control(9999); sl@0: assert( rc==0 ); sl@0: rc = sqlite3_test_control(-1); sl@0: assert( rc==0 ); sl@0: sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE); sl@0: return TCL_OK; sl@0: } sl@0: /* sl@0: ** tclcmd: restore_prng_state sl@0: */ sl@0: static int restore_prng_state( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE); sl@0: return TCL_OK; sl@0: } sl@0: /* sl@0: ** tclcmd: reset_prng_state sl@0: */ sl@0: static int reset_prng_state( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET); sl@0: return TCL_OK; sl@0: } sl@0: sl@0: /* sl@0: ** tclcmd: pcache_stats sl@0: */ sl@0: static int test_pcache_stats( sl@0: ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ sl@0: Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ sl@0: int objc, /* Number of arguments */ sl@0: Tcl_Obj *CONST objv[] /* Command arguments */ sl@0: ){ sl@0: int nMin; sl@0: int nMax; sl@0: int nCurrent; sl@0: int nRecyclable; sl@0: Tcl_Obj *pRet; sl@0: sl@0: sqlite3PcacheStats(&nCurrent, &nMax, &nMin, &nRecyclable); sl@0: sl@0: pRet = Tcl_NewObj(); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("current", -1)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nCurrent)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("max", -1)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nMax)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("min", -1)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nMin)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("recyclable", -1)); sl@0: Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nRecyclable)); sl@0: sl@0: Tcl_SetObjResult(interp, pRet); sl@0: sl@0: return TCL_OK; sl@0: } sl@0: sl@0: sl@0: /* sl@0: ** Register commands with the TCL interpreter. sl@0: */ sl@0: int Sqlitetest1_Init(Tcl_Interp *interp){ sl@0: extern int sqlite3_search_count; sl@0: extern int sqlite3_interrupt_count; sl@0: extern int sqlite3_open_file_count; sl@0: extern int sqlite3_sort_count; sl@0: extern int sqlite3_current_time; sl@0: extern int sqlite3_max_blobsize; sl@0: extern int sqlite3BtreeSharedCacheReport(void*, sl@0: Tcl_Interp*,int,Tcl_Obj*CONST*); sl@0: static struct { sl@0: char *zName; sl@0: Tcl_CmdProc *xProc; sl@0: } aCmd[] = { sl@0: { "db_enter", (Tcl_CmdProc*)db_enter }, sl@0: { "db_leave", (Tcl_CmdProc*)db_leave }, sl@0: { "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int }, sl@0: { "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 }, sl@0: { "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str }, sl@0: { "sqlite3_snprintf_str", (Tcl_CmdProc*)sqlite3_snprintf_str }, sl@0: { "sqlite3_mprintf_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly}, sl@0: { "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double }, sl@0: { "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled }, sl@0: { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble}, sl@0: { "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z }, sl@0: { "sqlite3_mprintf_n_test", (Tcl_CmdProc*)test_mprintf_n }, sl@0: { "sqlite3_snprintf_int", (Tcl_CmdProc*)test_snprintf_int }, sl@0: { "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid }, sl@0: { "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf }, sl@0: { "sqlite3_exec", (Tcl_CmdProc*)test_exec }, sl@0: { "sqlite3_exec_nr", (Tcl_CmdProc*)test_exec_nr }, sl@0: #ifndef SQLITE_OMIT_GET_TABLE sl@0: { "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf }, sl@0: #endif sl@0: { "sqlite3_close", (Tcl_CmdProc*)sqlite_test_close }, sl@0: { "sqlite3_create_function", (Tcl_CmdProc*)test_create_function }, sl@0: { "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate }, sl@0: { "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func }, sl@0: { "sqlite_abort", (Tcl_CmdProc*)sqlite_abort }, sl@0: { "sqlite_bind", (Tcl_CmdProc*)test_bind }, sl@0: { "breakpoint", (Tcl_CmdProc*)test_breakpoint }, sl@0: { "sqlite3_key", (Tcl_CmdProc*)test_key }, sl@0: { "sqlite3_rekey", (Tcl_CmdProc*)test_rekey }, sl@0: { "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic }, sl@0: { "sqlite3_interrupt", (Tcl_CmdProc*)test_interrupt }, sl@0: { "sqlite_delete_function", (Tcl_CmdProc*)delete_function }, sl@0: { "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation }, sl@0: { "sqlite3_get_autocommit", (Tcl_CmdProc*)get_autocommit }, sl@0: { "sqlite3_stack_used", (Tcl_CmdProc*)test_stack_used }, sl@0: { "sqlite3_busy_timeout", (Tcl_CmdProc*)test_busy_timeout }, sl@0: { "printf", (Tcl_CmdProc*)test_printf }, sl@0: { "sqlite3IoTrace", (Tcl_CmdProc*)test_io_trace }, sl@0: }; sl@0: static struct { sl@0: char *zName; sl@0: Tcl_ObjCmdProc *xProc; sl@0: void *clientData; sl@0: } aObjCmd[] = { sl@0: { "sqlite3_connection_pointer", get_sqlite_pointer, 0 }, sl@0: { "sqlite3_bind_int", test_bind_int, 0 }, sl@0: { "sqlite3_bind_zeroblob", test_bind_zeroblob, 0 }, sl@0: { "sqlite3_bind_int64", test_bind_int64, 0 }, sl@0: { "sqlite3_bind_double", test_bind_double, 0 }, sl@0: { "sqlite3_bind_null", test_bind_null ,0 }, sl@0: { "sqlite3_bind_text", test_bind_text ,0 }, sl@0: { "sqlite3_bind_text16", test_bind_text16 ,0 }, sl@0: { "sqlite3_bind_blob", test_bind_blob ,0 }, sl@0: { "sqlite3_bind_parameter_count", test_bind_parameter_count, 0}, sl@0: { "sqlite3_bind_parameter_name", test_bind_parameter_name, 0}, sl@0: { "sqlite3_bind_parameter_index", test_bind_parameter_index, 0}, sl@0: { "sqlite3_clear_bindings", test_clear_bindings, 0}, sl@0: { "sqlite3_sleep", test_sleep, 0}, sl@0: { "sqlite3_errcode", test_errcode ,0 }, sl@0: { "sqlite3_errmsg", test_errmsg ,0 }, sl@0: { "sqlite3_errmsg16", test_errmsg16 ,0 }, sl@0: { "sqlite3_open", test_open ,0 }, sl@0: { "sqlite3_open16", test_open16 ,0 }, sl@0: { "sqlite3_complete16", test_complete16 ,0 }, sl@0: sl@0: { "sqlite3_prepare", test_prepare ,0 }, sl@0: { "sqlite3_prepare16", test_prepare16 ,0 }, sl@0: { "sqlite3_prepare_v2", test_prepare_v2 ,0 }, sl@0: { "sqlite3_prepare_tkt3134", test_prepare_tkt3134, 0}, sl@0: { "sqlite3_prepare16_v2", test_prepare16_v2 ,0 }, sl@0: { "sqlite3_finalize", test_finalize ,0 }, sl@0: { "sqlite3_reset", test_reset ,0 }, sl@0: { "sqlite3_expired", test_expired ,0 }, sl@0: { "sqlite3_transfer_bindings", test_transfer_bind ,0 }, sl@0: { "sqlite3_changes", test_changes ,0 }, sl@0: { "sqlite3_step", test_step ,0 }, sl@0: { "sqlite3_next_stmt", test_next_stmt ,0 }, sl@0: sl@0: { "sqlite3_release_memory", test_release_memory, 0}, sl@0: { "sqlite3_soft_heap_limit", test_soft_heap_limit, 0}, sl@0: { "sqlite3_thread_cleanup", test_thread_cleanup, 0}, sl@0: { "sqlite3_pager_refcounts", test_pager_refcounts, 0}, sl@0: sl@0: { "sqlite3_load_extension", test_load_extension, 0}, sl@0: { "sqlite3_enable_load_extension", test_enable_load, 0}, sl@0: { "sqlite3_extended_result_codes", test_extended_result_codes, 0}, sl@0: { "sqlite3_limit", test_limit, 0}, sl@0: sl@0: { "save_prng_state", save_prng_state, 0 }, sl@0: { "restore_prng_state", restore_prng_state, 0 }, sl@0: { "reset_prng_state", reset_prng_state, 0 }, sl@0: sl@0: /* sqlite3_column_*() API */ sl@0: { "sqlite3_column_count", test_column_count ,0 }, sl@0: { "sqlite3_data_count", test_data_count ,0 }, sl@0: { "sqlite3_column_type", test_column_type ,0 }, sl@0: { "sqlite3_column_blob", test_column_blob ,0 }, sl@0: { "sqlite3_column_double", test_column_double ,0 }, sl@0: { "sqlite3_column_int64", test_column_int64 ,0 }, sl@0: { "sqlite3_column_text", test_stmt_utf8, (void*)sqlite3_column_text }, sl@0: { "sqlite3_column_name", test_stmt_utf8, (void*)sqlite3_column_name }, sl@0: { "sqlite3_column_int", test_stmt_int, (void*)sqlite3_column_int }, sl@0: { "sqlite3_column_bytes", test_stmt_int, (void*)sqlite3_column_bytes}, sl@0: #ifndef SQLITE_OMIT_DECLTYPE sl@0: { "sqlite3_column_decltype",test_stmt_utf8,(void*)sqlite3_column_decltype}, sl@0: #endif sl@0: #ifdef SQLITE_ENABLE_COLUMN_METADATA sl@0: { "sqlite3_column_database_name",test_stmt_utf8,(void*)sqlite3_column_database_name}, sl@0: { "sqlite3_column_table_name",test_stmt_utf8,(void*)sqlite3_column_table_name}, sl@0: { "sqlite3_column_origin_name",test_stmt_utf8,(void*)sqlite3_column_origin_name}, sl@0: #endif sl@0: sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: { "sqlite3_column_bytes16", test_stmt_int, (void*)sqlite3_column_bytes16 }, sl@0: { "sqlite3_column_text16", test_stmt_utf16, (void*)sqlite3_column_text16}, sl@0: { "sqlite3_column_name16", test_stmt_utf16, (void*)sqlite3_column_name16}, sl@0: { "add_alignment_test_collations", add_alignment_test_collations, 0 }, sl@0: #ifndef SQLITE_OMIT_DECLTYPE sl@0: { "sqlite3_column_decltype16",test_stmt_utf16,(void*)sqlite3_column_decltype16}, sl@0: #endif sl@0: #ifdef SQLITE_ENABLE_COLUMN_METADATA sl@0: {"sqlite3_column_database_name16", sl@0: test_stmt_utf16, sqlite3_column_database_name16}, sl@0: {"sqlite3_column_table_name16", test_stmt_utf16, (void*)sqlite3_column_table_name16}, sl@0: {"sqlite3_column_origin_name16", test_stmt_utf16, (void*)sqlite3_column_origin_name16}, sl@0: #endif sl@0: #endif sl@0: { "sqlite3_create_collation_v2", test_create_collation_v2, 0 }, sl@0: { "sqlite3_global_recover", test_global_recover, 0 }, sl@0: { "working_64bit_int", working_64bit_int, 0 }, sl@0: { "vfs_unlink_test", vfs_unlink_test, 0 }, sl@0: { "vfs_initfail_test", vfs_initfail_test, 0 }, sl@0: { "vfs_unregister_all", vfs_unregister_all, 0 }, sl@0: { "vfs_reregister_all", vfs_reregister_all, 0 }, sl@0: { "file_control_test", file_control_test, 0 }, sl@0: { "sqlite3_vfs_list", vfs_list, 0 }, sl@0: sl@0: /* Functions from os.h */ sl@0: #ifndef SQLITE_OMIT_UTF16 sl@0: { "add_test_collate", test_collate, 0 }, sl@0: { "add_test_collate_needed", test_collate_needed, 0 }, sl@0: { "add_test_function", test_function, 0 }, sl@0: #endif sl@0: { "sqlite3_test_errstr", test_errstr, 0 }, sl@0: { "tcl_variable_type", tcl_variable_type, 0 }, sl@0: #ifndef SQLITE_OMIT_SHARED_CACHE sl@0: { "sqlite3_enable_shared_cache", test_enable_shared, 0 }, sl@0: { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport, 0}, sl@0: #endif sl@0: { "sqlite3_libversion_number", test_libversion_number, 0 }, sl@0: #ifdef SQLITE_ENABLE_COLUMN_METADATA sl@0: { "sqlite3_table_column_metadata", test_table_column_metadata, 0 }, sl@0: #endif sl@0: #ifndef SQLITE_OMIT_INCRBLOB sl@0: { "sqlite3_blob_read", test_blob_read, 0 }, sl@0: { "sqlite3_blob_write", test_blob_write, 0 }, sl@0: #endif sl@0: { "pcache_stats", test_pcache_stats, 0 }, sl@0: }; sl@0: static int bitmask_size = sizeof(Bitmask)*8; sl@0: int i; sl@0: extern int sqlite3_sync_count, sqlite3_fullsync_count; sl@0: extern int sqlite3_opentemp_count; sl@0: extern int sqlite3_like_count; sl@0: extern int sqlite3_xferopt_count; sl@0: extern int sqlite3_pager_readdb_count; sl@0: extern int sqlite3_pager_writedb_count; sl@0: extern int sqlite3_pager_writej_count; sl@0: #if SQLITE_OS_UNIX && defined(SQLITE_TEST) && SQLITE_THREADSAFE sl@0: extern int threadsOverrideEachOthersLocks; sl@0: #endif sl@0: #if SQLITE_OS_WIN sl@0: extern int sqlite3_os_type; sl@0: #endif sl@0: #ifdef SQLITE_DEBUG sl@0: extern int sqlite3WhereTrace; sl@0: extern int sqlite3OSTrace; sl@0: extern int sqlite3VdbeAddopTrace; sl@0: #endif sl@0: #ifdef SQLITE_TEST sl@0: extern int sqlite3_enable_in_opt; sl@0: extern char sqlite3_query_plan[]; sl@0: static char *query_plan = sqlite3_query_plan; sl@0: #endif sl@0: sl@0: for(i=0; i