?? test1.c
字號:
rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT); }else if( strcmp(argv[4],"blob10")==0 ){ rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC); }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; int n; 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); n = sqlite3_value_bytes(pVal); Tcl_ListObjAppendElement(i,pX, Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC); n = sqlite3_value_bytes(pVal); Tcl_ListObjAppendElement(i,pX, Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); 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;#ifdef SQLITE_MEMDEBUG if( sqlite3_iMallocFail>0 ){ sqlite3_iMallocFail++; }#endif pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); rc = 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; if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); 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;}/*** When the collation needed callback is invoked, record the name of ** the requested collating function here. The recorded name is linked** to a TCL variable and used to make sure that the requested collation** name is correct.*/static char zNeededCollation[200];static char *pzNeededCollation = zNeededCollation;/*** Called when a collating sequence is needed. Registered using** sqlite3_collation_needed16().*/static void test_collate_needed_cb( void *pCtx, sqlite3 *db, int eTextRep, const void *pName){ int enc = ENC(db); int i; char *z; for(z = (char*)pName, i=0; *z || z[1]; z++){ if( *z ) zNeededCollation[i++] = *z; } 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 ){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -