📄 test1.c
字号:
}/*** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER**** Call mprintf with three integer arguments*/static int sqlite3_mprintf_int( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int a[3], i; char *z; if( argc!=5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT INT INT INT\"", 0); return TCL_ERROR; } for(i=2; i<5; i++){ if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; } z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** If zNum represents an integer that will fit in 64-bits, then set** *pValue to that integer and return true. Otherwise return false.*/static int sqlite3GetInt64(const char *zNum, i64 *pValue){ if( sqlite3FitsIn64Bits(zNum) ){ sqlite3atoi64(zNum, pValue); return 1; } return 0;}/*** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER**** Call mprintf with three 64-bit integer arguments*/static int sqlite3_mprintf_int64( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int i; sqlite_int64 a[3]; char *z; if( argc!=5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT INT INT INT\"", 0); return TCL_ERROR; } for(i=2; i<5; i++){ if( !sqlite3GetInt64(argv[i], &a[i-2]) ){ Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0); return TCL_ERROR; } } z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING**** Call mprintf with two integer arguments and one string argument*/static int sqlite3_mprintf_str( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int a[3], i; char *z; if( argc<4 || argc>5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT INT INT ?STRING?\"", 0); return TCL_ERROR; } for(i=2; i<4; i++){ if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; } z = sqlite3_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING**** Call mprintf with two integer arguments and one string argument*/static int sqlite3_snprintf_str( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int a[3], i; int n; char *z; if( argc<5 || argc>6 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " INT FORMAT INT INT ?STRING?\"", 0); return TCL_ERROR; } if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR; if( n<0 ){ Tcl_AppendResult(interp, "N must be non-negative", 0); return TCL_ERROR; } for(i=3; i<5; i++){ if( Tcl_GetInt(interp, argv[i], &a[i-3]) ) return TCL_ERROR; } z = sqlite3_malloc( n+1 ); sqlite3_snprintf(n, z, argv[2], a[0], a[1], argc>4 ? argv[5] : NULL); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE**** Call mprintf with two integer arguments and one double argument*/static int sqlite3_mprintf_double( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int a[3], i; double r; char *z; if( argc!=5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT INT INT DOUBLE\"", 0); return TCL_ERROR; } for(i=2; i<4; i++){ if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; } if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR; z = sqlite3_mprintf(argv[1], a[0], a[1], r); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE**** Call mprintf with a single double argument which is the product of the** two arguments given above. This is used to generate overflow and underflow** doubles to test that they are converted properly.*/static int sqlite3_mprintf_scaled( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int i; double r[2]; char *z; if( argc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT DOUBLE DOUBLE\"", 0); return TCL_ERROR; } for(i=2; i<4; i++){ if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR; } z = sqlite3_mprintf(argv[1], r[0]*r[1]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite3_mprintf_stronly FORMAT STRING**** Call mprintf with a single double argument which is the product of the** two arguments given above. This is used to generate overflow and underflow** doubles to test that they are converted properly.*/static int sqlite3_mprintf_stronly( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ char *z; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT STRING\"", 0); return TCL_ERROR; } z = sqlite3_mprintf(argv[1], argv[2]); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite3_mprintf_hexdouble FORMAT HEX**** Call mprintf with a single double argument which is derived from the** hexadecimal encoding of an IEEE double.*/static int sqlite3_mprintf_hexdouble( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ char *z; double r; unsigned x1, x2; long long unsigned d; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FORMAT STRING\"", 0); return TCL_ERROR; } if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){ Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0); return TCL_ERROR; } d = x2; d = (d<<32) + x1; memcpy(&r, &d, sizeof(r)); z = sqlite3_mprintf(argv[1], r); Tcl_AppendResult(interp, z, 0); sqlite3_free(z); return TCL_OK;}/*** Usage: sqlite_malloc_fail N ?REPEAT-INTERVAL?**** Rig sqliteMalloc() to fail on the N-th call and every REPEAT-INTERVAL call** after that. If REPEAT-INTERVAL is 0 or is omitted, then only a single** malloc will fail. If REPEAT-INTERVAL is 1 then all mallocs after the** first failure will continue to fail on every call. If REPEAT-INTERVAL is** 2 then every other malloc will fail. And so forth.**** Turn off this mechanism and reset the sqlite3ThreadData()->mallocFailed ** variable if N==0.*/#ifdef SQLITE_MEMDEBUGstatic int sqlite_malloc_fail( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ int n; int rep; if( argc!=2 && argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " N\"", 0); return TCL_ERROR; } if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR; if( argc==3 ){ if( Tcl_GetInt(interp, argv[2], &rep) ) return TCL_ERROR; }else{ rep = 0; } sqlite3_iMallocFail = n; sqlite3_iMallocReset = rep; return TCL_OK;}#endif/*** Usage: sqlite_malloc_stat**** Return the number of prior calls to sqliteMalloc() and sqliteFree().*/#ifdef SQLITE_MEMDEBUGstatic int sqlite_malloc_stat( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */){ char zBuf[200]; sprintf(zBuf, "%d %d %d", sqlite3_nMalloc,sqlite3_nFree,sqlite3_iMallocFail); Tcl_AppendResult(interp, zBuf, 0); return TCL_OK;}/*** This function implements a Tcl command that may be invoked using any of** the four forms enumerated below.**** sqlite_malloc_outstanding** Return a summary of all unfreed blocks of memory allocated by the** current thread. See comments above function sqlite3OutstandingMallocs() ** in util.c for a description of the returned value.**** sqlite_malloc_outstanding -bytes** Return the total amount of unfreed memory (in bytes) allocated by ** this thread.**** sqlite_malloc_outstanding -maxbytes** Return the maximum amount of dynamic memory in use at one time ** by this thread.**** sqlite_malloc_outstanding -clearmaxbytes** Set the value returned by [sqlite_malloc_outstanding -maxbytes]** to the current value of [sqlite_malloc_outstanding -bytes]. */static int sqlite_malloc_outstanding( ClientData clientData, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int objc, /* Number of arguments */ Tcl_Obj *CONST objv[] /* Command arguments */){ extern int sqlite3OutstandingMallocs(Tcl_Interp *interp);#if defined(SQLITE_DEBUG) && defined(SQLITE_MEMDEBUG) && SQLITE_MEMDEBUG>1 if( objc==2 ){ const char *zArg = Tcl_GetString(objv[1]);#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT ThreadData const *pTd = sqlite3ThreadDataReadOnly(); if( 0==strcmp(zArg, "-bytes") ){ Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc)); }else if( 0==strcmp(zArg, "-clearmaxbytes") ){ sqlite3_nMaxAlloc = pTd->nAlloc; }else #endif if( 0==strcmp(zArg, "-maxbytes") ){ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3_nMaxAlloc)); }else{ Tcl_AppendResult(interp, "bad option \"", zArg, "\": must be -bytes, -maxbytes or -clearmaxbytes", 0 ); return TCL_ERROR; } return TCL_OK; } if( objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, "?-bytes?"); return TCL_ERROR; } return sqlite3OutstandingMallocs(interp);#else return TCL_OK;#endif}#endif/*** Usage: sqlite3_enable_shared_cache BOOLEAN***/#if !defined(SQLITE_OMIT_SHARED_CACHE)static int test_enable_shared( ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int objc, /* Number of arguments */ Tcl_Obj *CONST objv[] /* Command arguments */){ int rc; int enable; int ret = 0; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN"); return TCL_ERROR; } if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){ return TCL_ERROR; } ret = sqlite3ThreadDataReadOnly()->useSharedData; rc = sqlite3_enable_shared_cache(enable); if( rc!=SQLITE_OK ){ Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC); return TCL_ERROR; } Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret)); return TCL_OK;}#endif/*** Usage: sqlite3_extended_result_codes DB BOOLEAN***/static int test_extended_result_codes( ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int objc, /* Number of arguments */ Tcl_Obj *CONST objv[] /* Command arguments */){ int enable; sqlite3 *db; if( objc!=3 ){ Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN"); return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR; sqlite3_extended_result_codes(db, enable); return TCL_OK;}/*** Usage: sqlite3_libversion_number***/static int test_libversion_number( ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int objc, /* Number of arguments */ Tcl_Obj *CONST objv[] /* Command arguments */){ Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number())); return TCL_OK;}/*** Usage: sqlite3_table_column_metadata DB dbname tblname colname**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -