📄 test3.c
字号:
return TCL_OK;}/*** Usage: btree_pager_stats ID**** Returns pager statistics*/static int btree_pager_stats( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; int i; int *a; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]); a = sqlite3pager_stats(sqlite3BtreePager(pBt)); for(i=0; i<11; i++){ static char *zName[] = { "ref", "page", "max", "size", "state", "err", "hit", "miss", "ovfl", "read", "write" }; char zBuf[100]; Tcl_AppendElement(interp, zName[i]); sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",a[i]); Tcl_AppendElement(interp, zBuf); } return TCL_OK;}/*** Usage: btree_pager_ref_dump ID**** Print out all outstanding pages.*/static int btree_pager_ref_dump( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]);#ifdef SQLITE_DEBUG sqlite3pager_refdump(sqlite3BtreePager(pBt));#endif return TCL_OK;}/*** Usage: btree_integrity_check ID ROOT ...**** Look through every page of the given BTree file to verify correct** formatting and linkage. Return a line of text for each problem found.** Return an empty string if everything worked.*/static int btree_integrity_check( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; int nRoot; int *aRoot; int i; char *zResult; if( argc<3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID ROOT ...\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]); nRoot = argc-2; aRoot = malloc( sizeof(int)*(argc-2) ); for(i=0; i<argc-2; i++){ if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR; }#ifndef SQLITE_OMIT_INTEGRITY_CHECK zResult = sqlite3BtreeIntegrityCheck(pBt, aRoot, nRoot);#else zResult = 0;#endif free(aRoot); if( zResult ){ Tcl_AppendResult(interp, zResult, 0); sqliteFree(zResult); } return TCL_OK;}/*** Usage: btree_cursor_list ID**** Print information about all cursors to standard output for debugging.*/#ifdef SQLITE_DEBUGstatic int btree_cursor_list( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]); sqlite3BtreeCursorList(pBt); return SQLITE_OK;}#endif/*** Usage: btree_cursor ID TABLENUM WRITEABLE**** Create a new cursor. Return the ID for the cursor.*/static int btree_cursor( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; int iTable; BtCursor *pCur; int rc; int wrFlag; char zBuf[30]; if( argc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID TABLENUM WRITEABLE\"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]); if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR; if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR; rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, 0, &pCur); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_close_cursor ID**** Close a cursor opened using btree_cursor.*/static int btree_close_cursor( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); rc = sqlite3BtreeCloseCursor(pCur); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return SQLITE_OK;}/*** Usage: btree_move_to ID KEY**** Move the cursor to the entry with the given key.*/static int btree_move_to( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; int res; char zBuf[20]; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID KEY\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){ int iKey; if( Tcl_GetInt(interp, argv[2], &iKey) ) return TCL_ERROR; rc = sqlite3BtreeMoveto(pCur, 0, iKey, &res); }else{ rc = sqlite3BtreeMoveto(pCur, argv[2], strlen(argv[2]), &res); } if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } if( res<0 ) res = -1; if( res>0 ) res = 1; sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",res); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_delete ID**** Delete the entry that the cursor is pointing to*/static int btree_delete( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); rc = sqlite3BtreeDelete(pCur); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return SQLITE_OK;}/*** Usage: btree_insert ID KEY DATA**** Create a new entry with the given key and data. If an entry already** exists with the same key the old entry is overwritten.*/static int btree_insert( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){ BtCursor *pCur; int rc; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "ID KEY DATA"); return TCL_ERROR; } pCur = sqlite3TextToPtr(Tcl_GetString(objv[1])); if( sqlite3BtreeFlags(pCur) & BTREE_INTKEY ){ i64 iKey; int len; unsigned char *pBuf; if( Tcl_GetWideIntFromObj(interp, objv[2], &iKey) ) return TCL_ERROR; pBuf = Tcl_GetByteArrayFromObj(objv[3], &len); rc = sqlite3BtreeInsert(pCur, 0, iKey, pBuf, len); }else{ int keylen; int dlen; unsigned char *pKBuf; unsigned char *pDBuf; pKBuf = Tcl_GetByteArrayFromObj(objv[2], &keylen); pDBuf = Tcl_GetByteArrayFromObj(objv[3], &dlen); rc = sqlite3BtreeInsert(pCur, pKBuf, keylen, pDBuf, dlen); } if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } return SQLITE_OK;}/*** Usage: btree_next ID**** Move the cursor to the next entry in the table. Return 0 on success** or 1 if the cursor was already on the last entry in the table or if** the table is empty.*/static int btree_next( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; int res = 0; char zBuf[100]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); rc = sqlite3BtreeNext(pCur, &res); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_prev ID**** Move the cursor to the previous entry in the table. Return 0 on** success and 1 if the cursor was already on the first entry in** the table or if the table was empty.*/static int btree_prev( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; int res = 0; char zBuf[100]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); rc = sqlite3BtreePrevious(pCur, &res); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_first ID**** Move the cursor to the first entry in the table. Return 0 if the** cursor was left point to something and 1 if the table is empty.*/static int btree_first( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; int res = 0; char zBuf[100]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); rc = sqlite3BtreeFirst(pCur, &res); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_last ID**** Move the cursor to the last entry in the table. Return 0 if the** cursor was left point to something and 1 if the table is empty.*/static int btree_last( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; int rc; int res = 0; char zBuf[100]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); rc = sqlite3BtreeLast(pCur, &res); if( rc ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; } sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_eof ID**** Return TRUE if the given cursor is not pointing at a valid entry.** Return FALSE if the cursor does point to a valid entry.*/static int btree_eof( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; char zBuf[50]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", sqlite3BtreeEof(pCur)); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK;}/*** Usage: btree_keysize ID**** Return the number of bytes of key. For an INTKEY table, this** returns the key itself.*/static int btree_keysize( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ BtCursor *pCur; u64 n; char zBuf[50]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TextToPtr(argv[1]); sqlite3BtreeKeySize(pCur, (i64*)&n);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -