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