drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 1 | /* |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 2 | ** 2001 September 15 |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 3 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 6 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** Code for testing the btree.c module in SQLite. This code |
| 13 | ** is not included in the SQLite library. It is used for automated |
| 14 | ** testing of the SQLite library. |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 15 | */ |
| 16 | #include "sqliteInt.h" |
danielk1977 | a1644fd | 2007-08-29 12:31:25 +0000 | [diff] [blame] | 17 | #include "btreeInt.h" |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 18 | #include "tcl.h" |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | |
| 22 | /* |
| 23 | ** Interpret an SQLite error number |
| 24 | */ |
| 25 | static char *errorName(int rc){ |
| 26 | char *zName; |
| 27 | switch( rc ){ |
| 28 | case SQLITE_OK: zName = "SQLITE_OK"; break; |
| 29 | case SQLITE_ERROR: zName = "SQLITE_ERROR"; break; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 30 | case SQLITE_PERM: zName = "SQLITE_PERM"; break; |
| 31 | case SQLITE_ABORT: zName = "SQLITE_ABORT"; break; |
| 32 | case SQLITE_BUSY: zName = "SQLITE_BUSY"; break; |
| 33 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 34 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 35 | case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; |
| 36 | case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; |
| 37 | case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 38 | case SQLITE_FULL: zName = "SQLITE_FULL"; break; |
| 39 | case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break; |
| 40 | case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; |
drh | 24cd67e | 2004-05-10 16:18:47 +0000 | [diff] [blame] | 41 | case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; |
danielk1977 | e6efa74 | 2004-11-10 11:55:10 +0000 | [diff] [blame] | 42 | case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 43 | default: zName = "SQLITE_Unknown"; break; |
| 44 | } |
| 45 | return zName; |
| 46 | } |
| 47 | |
| 48 | /* |
drh | a2451e2 | 2007-08-20 23:50:24 +0000 | [diff] [blame] | 49 | ** A bogus sqlite3 connection structure for use in the btree |
| 50 | ** tests. |
| 51 | */ |
| 52 | static sqlite3 sDb; |
| 53 | static int nRefSqlite3 = 0; |
| 54 | |
| 55 | /* |
drh | 75c014c | 2010-08-30 15:02:28 +0000 | [diff] [blame] | 56 | ** Usage: btree_open FILENAME NCACHE |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 57 | ** |
| 58 | ** Open a new database |
| 59 | */ |
| 60 | static int btree_open( |
| 61 | void *NotUsed, |
| 62 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 63 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 64 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 65 | ){ |
| 66 | Btree *pBt; |
drh | 75c014c | 2010-08-30 15:02:28 +0000 | [diff] [blame] | 67 | int rc, nCache; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 68 | char zBuf[100]; |
drh | c02a43a | 2012-01-10 23:18:38 +0000 | [diff] [blame] | 69 | int n; |
| 70 | char *zFilename; |
drh | 75c014c | 2010-08-30 15:02:28 +0000 | [diff] [blame] | 71 | if( argc!=3 ){ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 72 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | 23e11ca | 2004-05-04 17:27:28 +0000 | [diff] [blame] | 73 | " FILENAME NCACHE FLAGS\"", 0); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 74 | return TCL_ERROR; |
| 75 | } |
drh | 23e11ca | 2004-05-04 17:27:28 +0000 | [diff] [blame] | 76 | if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR; |
drh | a2451e2 | 2007-08-20 23:50:24 +0000 | [diff] [blame] | 77 | nRefSqlite3++; |
| 78 | if( nRefSqlite3==1 ){ |
| 79 | sDb.pVfs = sqlite3_vfs_find(0); |
danielk1977 | 59f8c08 | 2008-06-18 17:09:10 +0000 | [diff] [blame] | 80 | sDb.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 81 | sqlite3_mutex_enter(sDb.mutex); |
drh | a2451e2 | 2007-08-20 23:50:24 +0000 | [diff] [blame] | 82 | } |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 83 | n = (int)strlen(argv[1]); |
drh | c02a43a | 2012-01-10 23:18:38 +0000 | [diff] [blame] | 84 | zFilename = sqlite3_malloc( n+2 ); |
| 85 | if( zFilename==0 ) return TCL_ERROR; |
| 86 | memcpy(zFilename, argv[1], n+1); |
| 87 | zFilename[n+1] = 0; |
| 88 | rc = sqlite3BtreeOpen(sDb.pVfs, zFilename, &sDb, &pBt, 0, |
drh | 33f4e02 | 2007-09-03 15:19:34 +0000 | [diff] [blame] | 89 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB); |
drh | c02a43a | 2012-01-10 23:18:38 +0000 | [diff] [blame] | 90 | sqlite3_free(zFilename); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 91 | if( rc!=SQLITE_OK ){ |
| 92 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 93 | return TCL_ERROR; |
| 94 | } |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 95 | sqlite3BtreeSetCacheSize(pBt, nCache); |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 96 | sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pBt); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 97 | Tcl_AppendResult(interp, zBuf, 0); |
| 98 | return TCL_OK; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | ** Usage: btree_close ID |
| 103 | ** |
| 104 | ** Close the given database. |
| 105 | */ |
| 106 | static int btree_close( |
| 107 | void *NotUsed, |
| 108 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 109 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 110 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 111 | ){ |
| 112 | Btree *pBt; |
| 113 | int rc; |
| 114 | if( argc!=2 ){ |
| 115 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 116 | " ID\"", 0); |
| 117 | return TCL_ERROR; |
| 118 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 119 | pBt = sqlite3TestTextToPtr(argv[1]); |
drh | 23e11ca | 2004-05-04 17:27:28 +0000 | [diff] [blame] | 120 | rc = sqlite3BtreeClose(pBt); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 121 | if( rc!=SQLITE_OK ){ |
| 122 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 123 | return TCL_ERROR; |
| 124 | } |
drh | a2451e2 | 2007-08-20 23:50:24 +0000 | [diff] [blame] | 125 | nRefSqlite3--; |
| 126 | if( nRefSqlite3==0 ){ |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 127 | sqlite3_mutex_leave(sDb.mutex); |
drh | a2451e2 | 2007-08-20 23:50:24 +0000 | [diff] [blame] | 128 | sqlite3_mutex_free(sDb.mutex); |
| 129 | sDb.mutex = 0; |
drh | a2451e2 | 2007-08-20 23:50:24 +0000 | [diff] [blame] | 130 | sDb.pVfs = 0; |
| 131 | } |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 132 | return TCL_OK; |
| 133 | } |
| 134 | |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 135 | |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 136 | /* |
| 137 | ** Usage: btree_begin_transaction ID |
| 138 | ** |
| 139 | ** Start a new transaction |
| 140 | */ |
| 141 | static int btree_begin_transaction( |
| 142 | void *NotUsed, |
| 143 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 144 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 145 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 146 | ){ |
| 147 | Btree *pBt; |
| 148 | int rc; |
| 149 | if( argc!=2 ){ |
| 150 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 151 | " ID\"", 0); |
| 152 | return TCL_ERROR; |
| 153 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 154 | pBt = sqlite3TestTextToPtr(argv[1]); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 155 | sqlite3BtreeEnter(pBt); |
danielk1977 | 40b38dc | 2004-06-26 08:38:24 +0000 | [diff] [blame] | 156 | rc = sqlite3BtreeBeginTrans(pBt, 1); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 157 | sqlite3BtreeLeave(pBt); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 158 | if( rc!=SQLITE_OK ){ |
| 159 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 160 | return TCL_ERROR; |
| 161 | } |
| 162 | return TCL_OK; |
| 163 | } |
| 164 | |
| 165 | /* |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 166 | ** Usage: btree_pager_stats ID |
| 167 | ** |
| 168 | ** Returns pager statistics |
| 169 | */ |
| 170 | static int btree_pager_stats( |
| 171 | void *NotUsed, |
| 172 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 173 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 174 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 175 | ){ |
| 176 | Btree *pBt; |
| 177 | int i; |
| 178 | int *a; |
| 179 | |
| 180 | if( argc!=2 ){ |
| 181 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 182 | " ID\"", 0); |
| 183 | return TCL_ERROR; |
| 184 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 185 | pBt = sqlite3TestTextToPtr(argv[1]); |
danielk1977 | f3c6265 | 2007-08-30 08:27:39 +0000 | [diff] [blame] | 186 | |
| 187 | /* Normally in this file, with a b-tree handle opened using the |
| 188 | ** [btree_open] command it is safe to call sqlite3BtreeEnter() directly. |
| 189 | ** But this function is sometimes called with a btree handle obtained |
| 190 | ** from an open SQLite connection (using [btree_from_db]). In this case |
| 191 | ** we need to obtain the mutex for the controlling SQLite handle before |
| 192 | ** it is safe to call sqlite3BtreeEnter(). |
| 193 | */ |
drh | e5fe690 | 2007-12-07 18:55:28 +0000 | [diff] [blame] | 194 | sqlite3_mutex_enter(pBt->db->mutex); |
danielk1977 | f3c6265 | 2007-08-30 08:27:39 +0000 | [diff] [blame] | 195 | |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 196 | sqlite3BtreeEnter(pBt); |
danielk1977 | 3b8a05f | 2007-03-19 17:44:26 +0000 | [diff] [blame] | 197 | a = sqlite3PagerStats(sqlite3BtreePager(pBt)); |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 198 | for(i=0; i<11; i++){ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 199 | static char *zName[] = { |
| 200 | "ref", "page", "max", "size", "state", "err", |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 201 | "hit", "miss", "ovfl", "read", "write" |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 202 | }; |
| 203 | char zBuf[100]; |
| 204 | Tcl_AppendElement(interp, zName[i]); |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 205 | sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",a[i]); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 206 | Tcl_AppendElement(interp, zBuf); |
| 207 | } |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 208 | sqlite3BtreeLeave(pBt); |
danielk1977 | f3c6265 | 2007-08-30 08:27:39 +0000 | [diff] [blame] | 209 | |
| 210 | /* Release the mutex on the SQLite handle that controls this b-tree */ |
drh | e5fe690 | 2007-12-07 18:55:28 +0000 | [diff] [blame] | 211 | sqlite3_mutex_leave(pBt->db->mutex); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 212 | return TCL_OK; |
| 213 | } |
| 214 | |
| 215 | /* |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 216 | ** Usage: btree_cursor ID TABLENUM WRITEABLE |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 217 | ** |
| 218 | ** Create a new cursor. Return the ID for the cursor. |
| 219 | */ |
| 220 | static int btree_cursor( |
| 221 | void *NotUsed, |
| 222 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 223 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 224 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 225 | ){ |
| 226 | Btree *pBt; |
| 227 | int iTable; |
| 228 | BtCursor *pCur; |
dan | 93a696f | 2010-01-07 11:27:30 +0000 | [diff] [blame] | 229 | int rc = SQLITE_OK; |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 230 | int wrFlag; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 231 | char zBuf[30]; |
| 232 | |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 233 | if( argc!=4 ){ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 234 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 235 | " ID TABLENUM WRITEABLE\"", 0); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 236 | return TCL_ERROR; |
| 237 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 238 | pBt = sqlite3TestTextToPtr(argv[1]); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 239 | if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR; |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 240 | if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR; |
danielk1977 | cd3e8f7 | 2008-03-25 09:47:35 +0000 | [diff] [blame] | 241 | pCur = (BtCursor *)ckalloc(sqlite3BtreeCursorSize()); |
| 242 | memset(pCur, 0, sqlite3BtreeCursorSize()); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 243 | sqlite3BtreeEnter(pBt); |
dan | 93a696f | 2010-01-07 11:27:30 +0000 | [diff] [blame] | 244 | #ifndef SQLITE_OMIT_SHARED_CACHE |
danielk1977 | 96d48e9 | 2009-06-29 06:00:37 +0000 | [diff] [blame] | 245 | rc = sqlite3BtreeLockTable(pBt, iTable, wrFlag); |
dan | 93a696f | 2010-01-07 11:27:30 +0000 | [diff] [blame] | 246 | #endif |
danielk1977 | 96d48e9 | 2009-06-29 06:00:37 +0000 | [diff] [blame] | 247 | if( rc==SQLITE_OK ){ |
| 248 | rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, pCur); |
| 249 | } |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 250 | sqlite3BtreeLeave(pBt); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 251 | if( rc ){ |
danielk1977 | cd3e8f7 | 2008-03-25 09:47:35 +0000 | [diff] [blame] | 252 | ckfree((char *)pCur); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 253 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 254 | return TCL_ERROR; |
| 255 | } |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 256 | sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 257 | Tcl_AppendResult(interp, zBuf, 0); |
| 258 | return SQLITE_OK; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | ** Usage: btree_close_cursor ID |
| 263 | ** |
| 264 | ** Close a cursor opened using btree_cursor. |
| 265 | */ |
| 266 | static int btree_close_cursor( |
| 267 | void *NotUsed, |
| 268 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 269 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 270 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 271 | ){ |
| 272 | BtCursor *pCur; |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 273 | Btree *pBt; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 274 | int rc; |
| 275 | |
| 276 | if( argc!=2 ){ |
| 277 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 278 | " ID\"", 0); |
| 279 | return TCL_ERROR; |
| 280 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 281 | pCur = sqlite3TestTextToPtr(argv[1]); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 282 | pBt = pCur->pBtree; |
| 283 | sqlite3BtreeEnter(pBt); |
drh | 23e11ca | 2004-05-04 17:27:28 +0000 | [diff] [blame] | 284 | rc = sqlite3BtreeCloseCursor(pCur); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 285 | sqlite3BtreeLeave(pBt); |
danielk1977 | cd3e8f7 | 2008-03-25 09:47:35 +0000 | [diff] [blame] | 286 | ckfree((char *)pCur); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 287 | if( rc ){ |
| 288 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 289 | return TCL_ERROR; |
| 290 | } |
| 291 | return SQLITE_OK; |
| 292 | } |
| 293 | |
| 294 | /* |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 295 | ** Usage: btree_next ID |
| 296 | ** |
drh | 2dcc9aa | 2002-12-04 13:40:25 +0000 | [diff] [blame] | 297 | ** Move the cursor to the next entry in the table. Return 0 on success |
| 298 | ** or 1 if the cursor was already on the last entry in the table or if |
| 299 | ** the table is empty. |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 300 | */ |
| 301 | static int btree_next( |
| 302 | void *NotUsed, |
| 303 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 304 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 305 | const char **argv /* Text of each argument */ |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 306 | ){ |
| 307 | BtCursor *pCur; |
| 308 | int rc; |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 309 | int res = 0; |
| 310 | char zBuf[100]; |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 311 | |
| 312 | if( argc!=2 ){ |
| 313 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 314 | " ID\"", 0); |
| 315 | return TCL_ERROR; |
| 316 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 317 | pCur = sqlite3TestTextToPtr(argv[1]); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 318 | sqlite3BtreeEnter(pCur->pBtree); |
drh | 4fc0fb4 | 2004-05-07 02:26:28 +0000 | [diff] [blame] | 319 | rc = sqlite3BtreeNext(pCur, &res); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 320 | sqlite3BtreeLeave(pCur->pBtree); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 321 | if( rc ){ |
| 322 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 323 | return TCL_ERROR; |
| 324 | } |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 325 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res); |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 326 | Tcl_AppendResult(interp, zBuf, 0); |
| 327 | return SQLITE_OK; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | ** Usage: btree_first ID |
| 332 | ** |
drh | 2dcc9aa | 2002-12-04 13:40:25 +0000 | [diff] [blame] | 333 | ** Move the cursor to the first entry in the table. Return 0 if the |
| 334 | ** cursor was left point to something and 1 if the table is empty. |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 335 | */ |
| 336 | static int btree_first( |
| 337 | void *NotUsed, |
| 338 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 339 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 340 | const char **argv /* Text of each argument */ |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 341 | ){ |
| 342 | BtCursor *pCur; |
| 343 | int rc; |
| 344 | int res = 0; |
| 345 | char zBuf[100]; |
| 346 | |
| 347 | if( argc!=2 ){ |
| 348 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 349 | " ID\"", 0); |
| 350 | return TCL_ERROR; |
| 351 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 352 | pCur = sqlite3TestTextToPtr(argv[1]); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 353 | sqlite3BtreeEnter(pCur->pBtree); |
drh | 4fc0fb4 | 2004-05-07 02:26:28 +0000 | [diff] [blame] | 354 | rc = sqlite3BtreeFirst(pCur, &res); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 355 | sqlite3BtreeLeave(pCur->pBtree); |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 356 | if( rc ){ |
| 357 | Tcl_AppendResult(interp, errorName(rc), 0); |
| 358 | return TCL_ERROR; |
| 359 | } |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 360 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",res); |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 361 | Tcl_AppendResult(interp, zBuf, 0); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 362 | return SQLITE_OK; |
| 363 | } |
| 364 | |
| 365 | /* |
drh | c39e000 | 2004-05-07 23:50:57 +0000 | [diff] [blame] | 366 | ** Usage: btree_eof ID |
| 367 | ** |
| 368 | ** Return TRUE if the given cursor is not pointing at a valid entry. |
| 369 | ** Return FALSE if the cursor does point to a valid entry. |
| 370 | */ |
| 371 | static int btree_eof( |
| 372 | void *NotUsed, |
| 373 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 374 | int argc, /* Number of arguments */ |
| 375 | const char **argv /* Text of each argument */ |
| 376 | ){ |
| 377 | BtCursor *pCur; |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 378 | int rc; |
drh | c39e000 | 2004-05-07 23:50:57 +0000 | [diff] [blame] | 379 | char zBuf[50]; |
| 380 | |
| 381 | if( argc!=2 ){ |
| 382 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 383 | " ID\"", 0); |
| 384 | return TCL_ERROR; |
| 385 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 386 | pCur = sqlite3TestTextToPtr(argv[1]); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 387 | sqlite3BtreeEnter(pCur->pBtree); |
| 388 | rc = sqlite3BtreeEof(pCur); |
| 389 | sqlite3BtreeLeave(pCur->pBtree); |
| 390 | sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", rc); |
drh | c39e000 | 2004-05-07 23:50:57 +0000 | [diff] [blame] | 391 | Tcl_AppendResult(interp, zBuf, 0); |
| 392 | return SQLITE_OK; |
| 393 | } |
| 394 | |
| 395 | /* |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 396 | ** Usage: btree_payload_size ID |
| 397 | ** |
| 398 | ** Return the number of bytes of payload |
| 399 | */ |
| 400 | static int btree_payload_size( |
| 401 | void *NotUsed, |
| 402 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 403 | int argc, /* Number of arguments */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 404 | const char **argv /* Text of each argument */ |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 405 | ){ |
| 406 | BtCursor *pCur; |
drh | 4fc0fb4 | 2004-05-07 02:26:28 +0000 | [diff] [blame] | 407 | int n2; |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 408 | u64 n1; |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 409 | char zBuf[50]; |
| 410 | |
| 411 | if( argc!=2 ){ |
| 412 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 413 | " ID\"", 0); |
| 414 | return TCL_ERROR; |
| 415 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 416 | pCur = sqlite3TestTextToPtr(argv[1]); |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 417 | sqlite3BtreeEnter(pCur->pBtree); |
danielk1977 | 3054866 | 2009-07-09 05:07:37 +0000 | [diff] [blame] | 418 | |
| 419 | /* The cursor may be in "require-seek" state. If this is the case, the |
| 420 | ** call to BtreeDataSize() will fix it. */ |
| 421 | sqlite3BtreeDataSize(pCur, (u32*)&n2); |
shane | cbcadd4 | 2009-07-09 03:20:46 +0000 | [diff] [blame] | 422 | if( pCur->apPage[pCur->iPage]->intKey ){ |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 423 | n1 = 0; |
| 424 | }else{ |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 425 | sqlite3BtreeKeySize(pCur, (i64*)&n1); |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 426 | } |
drh | ff0587c | 2007-08-29 17:43:19 +0000 | [diff] [blame] | 427 | sqlite3BtreeLeave(pCur->pBtree); |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 428 | sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", (int)(n1+n2)); |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 429 | Tcl_AppendResult(interp, zBuf, 0); |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 430 | return SQLITE_OK; |
| 431 | } |
| 432 | |
| 433 | /* |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 434 | ** usage: varint_test START MULTIPLIER COUNT INCREMENT |
| 435 | ** |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 436 | ** This command tests the putVarint() and getVarint() |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 437 | ** routines, both for accuracy and for speed. |
| 438 | ** |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 439 | ** An integer is written using putVarint() and read back with |
| 440 | ** getVarint() and varified to be unchanged. This repeats COUNT |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 441 | ** times. The first integer is START*MULTIPLIER. Each iteration |
| 442 | ** increases the integer by INCREMENT. |
| 443 | ** |
| 444 | ** This command returns nothing if it works. It returns an error message |
| 445 | ** if something goes wrong. |
| 446 | */ |
| 447 | static int btree_varint_test( |
| 448 | void *NotUsed, |
| 449 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 450 | int argc, /* Number of arguments */ |
| 451 | const char **argv /* Text of each argument */ |
| 452 | ){ |
| 453 | u32 start, mult, count, incr; |
| 454 | u64 in, out; |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 455 | int n1, n2, i, j; |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 456 | unsigned char zBuf[100]; |
| 457 | if( argc!=5 ){ |
| 458 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 459 | " START MULTIPLIER COUNT INCREMENT\"", 0); |
| 460 | return TCL_ERROR; |
| 461 | } |
| 462 | if( Tcl_GetInt(interp, argv[1], (int*)&start) ) return TCL_ERROR; |
| 463 | if( Tcl_GetInt(interp, argv[2], (int*)&mult) ) return TCL_ERROR; |
| 464 | if( Tcl_GetInt(interp, argv[3], (int*)&count) ) return TCL_ERROR; |
| 465 | if( Tcl_GetInt(interp, argv[4], (int*)&incr) ) return TCL_ERROR; |
| 466 | in = start; |
| 467 | in *= mult; |
drh | 7da5fcb | 2012-03-30 14:59:43 +0000 | [diff] [blame] | 468 | for(i=0; i<(int)count; i++){ |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 469 | char zErr[200]; |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 470 | n1 = putVarint(zBuf, in); |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 471 | if( n1>9 || n1<1 ){ |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 472 | sprintf(zErr, "putVarint returned %d - should be between 1 and 9", n1); |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 473 | Tcl_AppendResult(interp, zErr, 0); |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 474 | return TCL_ERROR; |
| 475 | } |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 476 | n2 = getVarint(zBuf, &out); |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 477 | if( n1!=n2 ){ |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 478 | sprintf(zErr, "putVarint returned %d and getVarint returned %d", n1, n2); |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 479 | Tcl_AppendResult(interp, zErr, 0); |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 480 | return TCL_ERROR; |
| 481 | } |
| 482 | if( in!=out ){ |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 483 | sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx", in, out); |
| 484 | Tcl_AppendResult(interp, zErr, 0); |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 485 | return TCL_ERROR; |
| 486 | } |
drh | 9d213ef | 2004-06-30 04:02:11 +0000 | [diff] [blame] | 487 | if( (in & 0xffffffff)==in ){ |
| 488 | u32 out32; |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 489 | n2 = getVarint32(zBuf, out32); |
drh | 9d213ef | 2004-06-30 04:02:11 +0000 | [diff] [blame] | 490 | out = out32; |
| 491 | if( n1!=n2 ){ |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 492 | sprintf(zErr, "putVarint returned %d and GetVarint32 returned %d", |
drh | 9d213ef | 2004-06-30 04:02:11 +0000 | [diff] [blame] | 493 | n1, n2); |
| 494 | Tcl_AppendResult(interp, zErr, 0); |
| 495 | return TCL_ERROR; |
| 496 | } |
| 497 | if( in!=out ){ |
| 498 | sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx from GetVarint32", |
| 499 | in, out); |
| 500 | Tcl_AppendResult(interp, zErr, 0); |
| 501 | return TCL_ERROR; |
| 502 | } |
| 503 | } |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 504 | |
| 505 | /* In order to get realistic timings, run getVarint 19 more times. |
| 506 | ** This is because getVarint is called about 20 times more often |
| 507 | ** than putVarint. |
| 508 | */ |
| 509 | for(j=0; j<19; j++){ |
shane | 3f8d5cf | 2008-04-24 19:15:09 +0000 | [diff] [blame] | 510 | getVarint(zBuf, &out); |
drh | d8820e8 | 2004-05-18 15:57:42 +0000 | [diff] [blame] | 511 | } |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 512 | in += incr; |
| 513 | } |
| 514 | return TCL_OK; |
| 515 | } |
drh | 9b17127 | 2004-05-08 02:03:22 +0000 | [diff] [blame] | 516 | |
| 517 | /* |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 518 | ** usage: btree_from_db DB-HANDLE |
| 519 | ** |
| 520 | ** This command returns the btree handle for the main database associated |
| 521 | ** with the database-handle passed as the argument. Example usage: |
| 522 | ** |
| 523 | ** sqlite3 db test.db |
| 524 | ** set bt [btree_from_db db] |
| 525 | */ |
| 526 | static int btree_from_db( |
| 527 | void *NotUsed, |
| 528 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 529 | int argc, /* Number of arguments */ |
| 530 | const char **argv /* Text of each argument */ |
| 531 | ){ |
| 532 | char zBuf[100]; |
| 533 | Tcl_CmdInfo info; |
| 534 | sqlite3 *db; |
| 535 | Btree *pBt; |
danielk1977 | 63c64f3 | 2007-05-17 14:45:12 +0000 | [diff] [blame] | 536 | int iDb = 0; |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 537 | |
danielk1977 | 63c64f3 | 2007-05-17 14:45:12 +0000 | [diff] [blame] | 538 | if( argc!=2 && argc!=3 ){ |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 539 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
danielk1977 | 63c64f3 | 2007-05-17 14:45:12 +0000 | [diff] [blame] | 540 | " DB-HANDLE ?N?\"", 0); |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 541 | return TCL_ERROR; |
| 542 | } |
| 543 | |
| 544 | if( 1!=Tcl_GetCommandInfo(interp, argv[1], &info) ){ |
| 545 | Tcl_AppendResult(interp, "No such db-handle: \"", argv[1], "\"", 0); |
| 546 | return TCL_ERROR; |
| 547 | } |
danielk1977 | 63c64f3 | 2007-05-17 14:45:12 +0000 | [diff] [blame] | 548 | if( argc==3 ){ |
| 549 | iDb = atoi(argv[2]); |
| 550 | } |
| 551 | |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 552 | db = *((sqlite3 **)info.objClientData); |
| 553 | assert( db ); |
| 554 | |
danielk1977 | 63c64f3 | 2007-05-17 14:45:12 +0000 | [diff] [blame] | 555 | pBt = db->aDb[iDb].pBt; |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 556 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", pBt); |
| 557 | Tcl_SetResult(interp, zBuf, TCL_VOLATILE); |
| 558 | return TCL_OK; |
| 559 | } |
| 560 | |
danielk1977 | 17b90b5 | 2008-06-06 11:11:25 +0000 | [diff] [blame] | 561 | /* |
| 562 | ** Usage: btree_ismemdb ID |
| 563 | ** |
| 564 | ** Return true if the B-Tree is in-memory. |
| 565 | */ |
| 566 | static int btree_ismemdb( |
| 567 | void *NotUsed, |
| 568 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 569 | int argc, /* Number of arguments */ |
| 570 | const char **argv /* Text of each argument */ |
| 571 | ){ |
| 572 | Btree *pBt; |
| 573 | int res; |
| 574 | |
| 575 | if( argc!=2 ){ |
| 576 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 577 | " ID\"", 0); |
| 578 | return TCL_ERROR; |
| 579 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 580 | pBt = sqlite3TestTextToPtr(argv[1]); |
danielk1977 | 17b90b5 | 2008-06-06 11:11:25 +0000 | [diff] [blame] | 581 | sqlite3_mutex_enter(pBt->db->mutex); |
| 582 | sqlite3BtreeEnter(pBt); |
| 583 | res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt)); |
| 584 | sqlite3BtreeLeave(pBt); |
| 585 | sqlite3_mutex_leave(pBt->db->mutex); |
| 586 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res)); |
| 587 | return SQLITE_OK; |
| 588 | } |
| 589 | |
danielk1977 | 3054866 | 2009-07-09 05:07:37 +0000 | [diff] [blame] | 590 | /* |
| 591 | ** usage: btree_set_cache_size ID NCACHE |
| 592 | ** |
| 593 | ** Set the size of the cache used by btree $ID. |
| 594 | */ |
| 595 | static int btree_set_cache_size( |
| 596 | void *NotUsed, |
| 597 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 598 | int argc, /* Number of arguments */ |
| 599 | const char **argv /* Text of each argument */ |
| 600 | ){ |
| 601 | int nCache; |
| 602 | Btree *pBt; |
| 603 | |
| 604 | if( argc!=3 ){ |
| 605 | Tcl_AppendResult( |
| 606 | interp, "wrong # args: should be \"", argv[0], " BT NCACHE\"", 0); |
| 607 | return TCL_ERROR; |
| 608 | } |
| 609 | pBt = sqlite3TestTextToPtr(argv[1]); |
| 610 | if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR; |
| 611 | |
| 612 | sqlite3_mutex_enter(pBt->db->mutex); |
| 613 | sqlite3BtreeEnter(pBt); |
| 614 | sqlite3BtreeSetCacheSize(pBt, nCache); |
| 615 | sqlite3BtreeLeave(pBt); |
| 616 | sqlite3_mutex_leave(pBt->db->mutex); |
| 617 | return TCL_OK; |
| 618 | } |
| 619 | |
| 620 | |
danielk1977 | 1ad7f64 | 2005-01-20 05:24:32 +0000 | [diff] [blame] | 621 | |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 622 | /* |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 623 | ** Register commands with the TCL interpreter. |
| 624 | */ |
| 625 | int Sqlitetest3_Init(Tcl_Interp *interp){ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 626 | static struct { |
| 627 | char *zName; |
| 628 | Tcl_CmdProc *xProc; |
| 629 | } aCmd[] = { |
| 630 | { "btree_open", (Tcl_CmdProc*)btree_open }, |
| 631 | { "btree_close", (Tcl_CmdProc*)btree_close }, |
| 632 | { "btree_begin_transaction", (Tcl_CmdProc*)btree_begin_transaction }, |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 633 | { "btree_pager_stats", (Tcl_CmdProc*)btree_pager_stats }, |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 634 | { "btree_cursor", (Tcl_CmdProc*)btree_cursor }, |
| 635 | { "btree_close_cursor", (Tcl_CmdProc*)btree_close_cursor }, |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 636 | { "btree_next", (Tcl_CmdProc*)btree_next }, |
drh | c39e000 | 2004-05-07 23:50:57 +0000 | [diff] [blame] | 637 | { "btree_eof", (Tcl_CmdProc*)btree_eof }, |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 638 | { "btree_payload_size", (Tcl_CmdProc*)btree_payload_size }, |
| 639 | { "btree_first", (Tcl_CmdProc*)btree_first }, |
drh | 6d2fb15 | 2004-05-14 16:50:06 +0000 | [diff] [blame] | 640 | { "btree_varint_test", (Tcl_CmdProc*)btree_varint_test }, |
danielk1977 | 42741be | 2005-01-08 12:42:39 +0000 | [diff] [blame] | 641 | { "btree_from_db", (Tcl_CmdProc*)btree_from_db }, |
danielk1977 | 3054866 | 2009-07-09 05:07:37 +0000 | [diff] [blame] | 642 | { "btree_ismemdb", (Tcl_CmdProc*)btree_ismemdb }, |
| 643 | { "btree_set_cache_size", (Tcl_CmdProc*)btree_set_cache_size } |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 644 | }; |
| 645 | int i; |
| 646 | |
| 647 | for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ |
| 648 | Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
| 649 | } |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 650 | |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 651 | return TCL_OK; |
| 652 | } |