📄 test1.c
字号:
return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; rc = sqlite3_reset(pStmt); if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC); if( rc ){ return TCL_ERROR; } return TCL_OK;}/*** Usage: sqlite3_expired STMT **** Return TRUE if a recompilation of the statement is recommended.*/static int test_expired( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3_stmt *pStmt; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt))); return TCL_OK;}/*** Usage: sqlite3_changes DB**** Return the number of changes made to the database by the last SQL** execution.*/static int test_changes( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3 *db; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetString(objv[0]), " DB", 0); return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_changes(db))); return TCL_OK;}/*** This is the "static_bind_value" that variables are bound to when** the FLAG option of sqlite3_bind is "static"*/static char *sqlite_static_bind_value = 0;/*** Usage: sqlite3_bind VM IDX VALUE FLAGS**** Sets the value of the IDX-th occurance of "?" in the original SQL** string. VALUE is the new value. If FLAGS=="null" then VALUE is** ignored and the value is set to NULL. If FLAGS=="static" then** the value is set to the value of a static variable named** "sqlite_static_bind_value". If FLAGS=="normal" then a copy** of the VALUE is made.*/static int test_bind( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ sqlite3_stmt *pStmt; int rc; int idx; if( argc!=5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " VM IDX VALUE (null|static|normal)\"", 0); return TCL_ERROR; } if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR; if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR; if( strcmp(argv[4],"null")==0 ){ rc = sqlite3_bind_null(pStmt, idx); }else if( strcmp(argv[4],"static")==0 ){ rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0); }else if( strcmp(argv[4],"normal")==0 ){ rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT); }else{ Tcl_AppendResult(interp, "4th argument should be " "\"null\" or \"static\" or \"normal\"", 0); return TCL_ERROR; } if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; if( rc ){ char zBuf[50]; sprintf(zBuf, "(%d) ", rc); Tcl_AppendResult(interp, zBuf, sqlite3ErrStr(rc), 0); return TCL_ERROR; } return TCL_OK;}#ifndef SQLITE_OMIT_UTF16/*** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>**** This function is used to test that SQLite selects the correct collation** sequence callback when multiple versions (for different text encodings)** are available.**** Calling this routine registers the collation sequence "test_collate"** with database handle <db>. The second argument must be a list of three** boolean values. If the first is true, then a version of test_collate is** registered for UTF-8, if the second is true, a version is registered for** UTF-16le, if the third is true, a UTF-16be version is available.** Previous versions of test_collate are deleted.**** The collation sequence test_collate is implemented by calling the** following TCL script:**** "test_collate <enc> <lhs> <rhs>"**** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.** The <enc> parameter is the encoding of the collation function that** SQLite selected to call. The TCL test script implements the** "test_collate" proc.**** Note that this will only work with one intepreter at a time, as the** interp pointer to use when evaluating the TCL script is stored in** pTestCollateInterp.*/static Tcl_Interp* pTestCollateInterp;static int test_collate_func( void *pCtx, int nA, const void *zA, int nB, const void *zB){ Tcl_Interp *i = pTestCollateInterp; int encin = (int)pCtx; int res; sqlite3_value *pVal; Tcl_Obj *pX; pX = Tcl_NewStringObj("test_collate", -1); Tcl_IncrRefCount(pX); switch( encin ){ case SQLITE_UTF8: Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-8",-1)); break; case SQLITE_UTF16LE: Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16LE",-1)); break; case SQLITE_UTF16BE: Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16BE",-1)); break; default: assert(0); } pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC); Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),-1)); sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC); Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),-1)); sqlite3ValueFree(pVal); Tcl_EvalObjEx(i, pX, 0); Tcl_DecrRefCount(pX); Tcl_GetIntFromObj(i, Tcl_GetObjResult(i), &res); return res;}static int test_collate( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3 *db; int val; sqlite3_value *pVal; int rc; if( objc!=5 ) goto bad_args; pTestCollateInterp = interp; if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF8, (void *)SQLITE_UTF8, val?test_collate_func:0); if( rc==SQLITE_OK ){ if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE, (void *)SQLITE_UTF16LE, val?test_collate_func:0); if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); sqlite3_create_collation16(db, sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), SQLITE_UTF16BE, (void *)SQLITE_UTF16BE, val?test_collate_func:0); sqlite3ValueFree(pVal); } if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; return TCL_OK;bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); return TCL_ERROR;}static void test_collate_needed_cb( void *pCtx, sqlite3 *db, int eTextRep, const void *notUsed){ int enc = db->enc; sqlite3_create_collation( db, "test_collate", db->enc, (void *)enc, test_collate_func);}/*** Usage: add_test_collate_needed DB*/static int test_collate_needed( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3 *db; int rc; if( objc!=2 ) goto bad_args; if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb); if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; return TCL_OK;bad_args: Tcl_WrongNumArgs(interp, 1, objv, "DB"); return TCL_ERROR;}#endif /* SQLITE_OMIT_UTF16 *//*** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>**** This function is used to test that SQLite selects the correct user** function callback when multiple versions (for different text encodings)** are available.**** Calling this routine registers up to three versions of the user function** "test_function" with database handle <db>. If the second argument is** true, then a version of test_function is registered for UTF-8, if the** third is true, a version is registered for UTF-16le, if the fourth is** true, a UTF-16be version is available. Previous versions of** test_function are deleted.**** The user function is implemented by calling the following TCL script:**** "test_function <enc> <arg>"**** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the** single argument passed to the SQL function. The value returned by** the TCL script is used as the return value of the SQL function. It** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8** for a UTF-16LE test_function(), and UTF-16LE for an implementation that** prefers UTF-16BE.*/#ifndef SQLITE_OMIT_UTF16static void test_function_utf8( sqlite3_context *pCtx, int nArg, sqlite3_value **argv){ Tcl_Interp *interp; Tcl_Obj *pX; sqlite3_value *pVal; interp = (Tcl_Interp *)sqlite3_user_data(pCtx); pX = Tcl_NewStringObj("test_function", -1); Tcl_IncrRefCount(pX); Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1)); Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1)); Tcl_EvalObjEx(interp, pX, 0); Tcl_DecrRefCount(pX); sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT); pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), SQLITE_UTF8, SQLITE_STATIC); sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal), -1, SQLITE_TRANSIENT); sqlite3ValueFree(pVal);}static void test_function_utf16le( sqlite3_context *pCtx, int nArg, sqlite3_value **argv){ Tcl_Interp *interp; Tcl_Obj *pX; sqlite3_value *pVal; interp = (Tcl_Interp *)sqlite3_user_data(pCtx); pX = Tcl_NewStringObj("test_function", -1); Tcl_IncrRefCount(pX); Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1)); Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1)); Tcl_EvalObjEx(interp, pX, 0); Tcl_DecrRefCount(pX); pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), SQLITE_UTF8, SQLITE_STATIC); sqlite3_result_text(pCtx,sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT); sqlite3ValueFree(pVal);}static void test_function_utf16be( sqlite3_context *pCtx, int nArg, sqlite3_value **argv){ Tcl_Interp *interp; Tcl_Obj *pX; sqlite3_value *pVal; interp = (Tcl_Interp *)sqlite3_user_data(pCtx); pX = Tcl_NewStringObj("test_function", -1); Tcl_IncrRefCount(pX); Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1)); Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1)); Tcl_EvalObjEx(interp, pX, 0); Tcl_DecrRefCount(pX); pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), SQLITE_UTF8, SQLITE_STATIC); sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal), -1, SQLITE_TRANSIENT); sqlite3ValueFree(pVal);}#endif /* SQLITE_OMIT_UTF16 */static int test_function( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){#ifndef SQLITE_OMIT_UTF16 sqlite3 *db; int val; if( objc!=5 ) goto bad_args; if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; if( val ){ sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8, interp, test_function_utf8, 0, 0); } if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; if( val ){ sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE, interp, test_function_utf16le, 0, 0); } if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; if( val ){ sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE, interp, test_function_utf16be, 0, 0); } return TCL_OK;bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);#endif /* SQLITE_OMIT_UTF16 */ return TCL_ERROR;}/*** Usage: test_errstr <err code>**** Test that the english language string equivalents for sqlite error codes** are sane. The parameter is an integer representing an sqlite error code.** The result is a list of two elements, the string representation of the** error code and the english language explanation.*/static int test_errstr( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ char *zCode; int i; if( objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, "<error code>"); } zCode = Tcl_GetString(objv[1]); for(i=0; i<200; i++){ if( 0==strcmp(errorName(i), zCode) ) break; } Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0); return TCL_OK;}static int sqlite3_crashparams( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){#ifdef OS_TEST int delay; if( objc!=3 ) goto bad_args; if( Tcl_GetIntFromObj(interp, objv[1], &delay) ) return TCL_ERROR; sqlite3SetCrashParams(delay, Tcl_GetString(objv[2]));#endif return TCL_OK;#ifdef OS_TESTbad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), "<delay> <filename>", 0); return TCL_ERROR;#endif}/*** Usage: breakpoint**** This routine exists for one purpose - to provide a place to put a** breakpoint with GDB that can be triggered using TCL code. The use** for this is when a particular test fails on (say) the 1485th iteration.** In the TCL test script, we can add code like this:**** if {$i==1485} breakpoint**** Then run testfixture in the debugger and wait for the breakpoint to** fire. Then additional breakpoints can be set to trace down the bug.*/static int test_breakpoint( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ return TCL_OK; /* Do nothing */}/*** Usage: sqlite3_bind_int STMT N VALUE**** Test the sqlite3_bind_int interface. STMT is a prepared statement.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -