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