📄 test1.c
字号:
zNeededCollation[i] = 0; sqlite3_create_collation( db, "test_collate", ENC(db), (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); zNeededCollation[0] = 0; if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; return TCL_OK;bad_args: Tcl_WrongNumArgs(interp, 1, objv, "DB"); return TCL_ERROR;}/*** tclcmd: add_alignment_test_collations DB**** Add two new collating sequences to the database DB**** utf16_aligned** utf16_unaligned**** Both collating sequences use the same sort order as BINARY.** The only difference is that the utf16_aligned collating** sequence is declared with the SQLITE_UTF16_ALIGNED flag.** Both collating functions increment the unaligned utf16 counter** whenever they see a string that begins on an odd byte boundary.*/static int unaligned_string_counter = 0;static int alignmentCollFunc( void *NotUsed, int nKey1, const void *pKey1, int nKey2, const void *pKey2){ int rc, n; n = nKey1<nKey2 ? nKey1 : nKey2; if( nKey1>0 && 1==(1&(int)pKey1) ) unaligned_string_counter++; if( nKey2>0 && 1==(1&(int)pKey2) ) unaligned_string_counter++; rc = memcmp(pKey1, pKey2, n); if( rc==0 ){ rc = nKey1 - nKey2; } return rc;}static int add_alignment_test_collations( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3 *db; if( objc>=2 ){ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; sqlite3_create_collation(db, "utf16_unaligned", SQLITE_UTF16, 0, alignmentCollFunc); sqlite3_create_collation(db, "utf16_aligned", SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, 0, alignmentCollFunc); } return SQLITE_OK;}#endif /* !defined(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((char*)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((char*)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,(char*)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((char*)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;}/*** 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.** N is the index of a wildcard in the prepared statement. This command** binds a 32-bit integer VALUE to that wildcard.*/static int test_bind_int( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3_stmt *pStmt; int idx; int value; int rc; if( objc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; rc = sqlite3_bind_int(pStmt, idx, value); if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; if( rc!=SQLITE_OK ){ return TCL_ERROR; } return TCL_OK;}/*** Usage: sqlite3_bind_int64 STMT N VALUE**** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.** N is the index of a wildcard in the prepared statement. This command** binds a 64-bit integer VALUE to that wildcard.*/static int test_bind_int64( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3_stmt *pStmt; int idx; i64 value; int rc; if( objc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; if( Tcl_GetWideIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; rc = sqlite3_bind_int64(pStmt, idx, value); if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; if( rc!=SQLITE_OK ){ return TCL_ERROR; } return TCL_OK;}/*** Usage: sqlite3_bind_double STMT N VALUE**** Test the sqlite3_bind_double interface. STMT is a prepared statement.** N is the index of a wildcard in the prepared statement. This command** binds a 64-bit integer VALUE to that wildcard.*/static int test_bind_double( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3_stmt *pStmt; int idx; double value; int rc; if( objc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; if( Tcl_GetDoubleFromObj(interp, objv[3], &value) ) return TCL_ERROR; rc = sqlite3_bind_double(pStmt, idx, value); if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; if( rc!=SQLITE_OK ){ return TCL_ERROR; } return TCL_OK;}/*** Usage: sqlite3_bind_null STMT N**** Test the sqlite3_bind_null interface. STMT is a prepared statement.** N is the index of a wildcard in the prepared statement. This command** binds a NULL to the wildcard.*/static int test_bind_null( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3_stmt *pStmt; int idx; int rc; if( objc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " STMT N", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; rc = sqlite3_bind_null(pStmt, idx); if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; if( rc!=SQLITE_OK ){ return TCL_ERROR; } return TCL_OK;}/*** Usage: sqlite3_bind_text STMT N STRING BYTES**** Test the sqlite3_bind_text interface. STMT is a prepared statement.** N is the index of a wildcard in the prepared statement. This command** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes** long.*/static int test_bind_text( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ sqlite3_stmt *pStmt; int idx; int bytes; char *value; int rc; if( objc!=5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; value = Tcl_GetString(objv[3]); if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT); if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; if( rc!=SQLI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -