Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: third_party/sqlite/src/src/test3.c

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/src/test2.c ('k') | third_party/sqlite/src/src/test4.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2001 September 15 2 ** 2001 September 15
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
11 ************************************************************************* 11 *************************************************************************
12 ** Code for testing the btree.c module in SQLite. This code 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 13 ** is not included in the SQLite library. It is used for automated
14 ** testing of the SQLite library. 14 ** testing of the SQLite library.
15 */ 15 */
16 #include "sqliteInt.h" 16 #include "sqliteInt.h"
17 #include "btreeInt.h" 17 #include "btreeInt.h"
18 #include "tcl.h" 18 #if defined(INCLUDE_SQLITE_TCL_H)
19 # include "sqlite_tcl.h"
20 #else
21 # include "tcl.h"
22 #endif
19 #include <stdlib.h> 23 #include <stdlib.h>
20 #include <string.h> 24 #include <string.h>
21 25
22 extern const char *sqlite3ErrName(int); 26 extern const char *sqlite3ErrName(int);
23 27
24 /* 28 /*
25 ** A bogus sqlite3 connection structure for use in the btree 29 ** A bogus sqlite3 connection structure for use in the btree
26 ** tests. 30 ** tests.
27 */ 31 */
28 static sqlite3 sDb; 32 static sqlite3 sDb;
29 static int nRefSqlite3 = 0; 33 static int nRefSqlite3 = 0;
30 34
31 /* 35 /*
32 ** Usage: btree_open FILENAME NCACHE 36 ** Usage: btree_open FILENAME NCACHE
33 ** 37 **
34 ** Open a new database 38 ** Open a new database
35 */ 39 */
36 static int btree_open( 40 static int SQLITE_TCLAPI btree_open(
37 void *NotUsed, 41 void *NotUsed,
38 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 42 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
39 int argc, /* Number of arguments */ 43 int argc, /* Number of arguments */
40 const char **argv /* Text of each argument */ 44 const char **argv /* Text of each argument */
41 ){ 45 ){
42 Btree *pBt; 46 Btree *pBt;
43 int rc, nCache; 47 int rc, nCache;
44 char zBuf[100]; 48 char zBuf[100];
45 int n; 49 int n;
46 char *zFilename; 50 char *zFilename;
(...skipping 25 matching lines...) Expand all
72 sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pBt); 76 sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pBt);
73 Tcl_AppendResult(interp, zBuf, 0); 77 Tcl_AppendResult(interp, zBuf, 0);
74 return TCL_OK; 78 return TCL_OK;
75 } 79 }
76 80
77 /* 81 /*
78 ** Usage: btree_close ID 82 ** Usage: btree_close ID
79 ** 83 **
80 ** Close the given database. 84 ** Close the given database.
81 */ 85 */
82 static int btree_close( 86 static int SQLITE_TCLAPI btree_close(
83 void *NotUsed, 87 void *NotUsed,
84 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 88 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
85 int argc, /* Number of arguments */ 89 int argc, /* Number of arguments */
86 const char **argv /* Text of each argument */ 90 const char **argv /* Text of each argument */
87 ){ 91 ){
88 Btree *pBt; 92 Btree *pBt;
89 int rc; 93 int rc;
90 if( argc!=2 ){ 94 if( argc!=2 ){
91 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 95 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
92 " ID\"", 0); 96 " ID\"", 0);
(...skipping 14 matching lines...) Expand all
107 } 111 }
108 return TCL_OK; 112 return TCL_OK;
109 } 113 }
110 114
111 115
112 /* 116 /*
113 ** Usage: btree_begin_transaction ID 117 ** Usage: btree_begin_transaction ID
114 ** 118 **
115 ** Start a new transaction 119 ** Start a new transaction
116 */ 120 */
117 static int btree_begin_transaction( 121 static int SQLITE_TCLAPI btree_begin_transaction(
118 void *NotUsed, 122 void *NotUsed,
119 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 123 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
120 int argc, /* Number of arguments */ 124 int argc, /* Number of arguments */
121 const char **argv /* Text of each argument */ 125 const char **argv /* Text of each argument */
122 ){ 126 ){
123 Btree *pBt; 127 Btree *pBt;
124 int rc; 128 int rc;
125 if( argc!=2 ){ 129 if( argc!=2 ){
126 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 130 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
127 " ID\"", 0); 131 " ID\"", 0);
128 return TCL_ERROR; 132 return TCL_ERROR;
129 } 133 }
130 pBt = sqlite3TestTextToPtr(argv[1]); 134 pBt = sqlite3TestTextToPtr(argv[1]);
131 sqlite3BtreeEnter(pBt); 135 sqlite3BtreeEnter(pBt);
132 rc = sqlite3BtreeBeginTrans(pBt, 1); 136 rc = sqlite3BtreeBeginTrans(pBt, 1);
133 sqlite3BtreeLeave(pBt); 137 sqlite3BtreeLeave(pBt);
134 if( rc!=SQLITE_OK ){ 138 if( rc!=SQLITE_OK ){
135 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); 139 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
136 return TCL_ERROR; 140 return TCL_ERROR;
137 } 141 }
138 return TCL_OK; 142 return TCL_OK;
139 } 143 }
140 144
141 /* 145 /*
142 ** Usage: btree_pager_stats ID 146 ** Usage: btree_pager_stats ID
143 ** 147 **
144 ** Returns pager statistics 148 ** Returns pager statistics
145 */ 149 */
146 static int btree_pager_stats( 150 static int SQLITE_TCLAPI btree_pager_stats(
147 void *NotUsed, 151 void *NotUsed,
148 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 152 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
149 int argc, /* Number of arguments */ 153 int argc, /* Number of arguments */
150 const char **argv /* Text of each argument */ 154 const char **argv /* Text of each argument */
151 ){ 155 ){
152 Btree *pBt; 156 Btree *pBt;
153 int i; 157 int i;
154 int *a; 158 int *a;
155 159
156 if( argc!=2 ){ 160 if( argc!=2 ){
(...skipping 29 matching lines...) Expand all
186 /* Release the mutex on the SQLite handle that controls this b-tree */ 190 /* Release the mutex on the SQLite handle that controls this b-tree */
187 sqlite3_mutex_leave(pBt->db->mutex); 191 sqlite3_mutex_leave(pBt->db->mutex);
188 return TCL_OK; 192 return TCL_OK;
189 } 193 }
190 194
191 /* 195 /*
192 ** Usage: btree_cursor ID TABLENUM WRITEABLE 196 ** Usage: btree_cursor ID TABLENUM WRITEABLE
193 ** 197 **
194 ** Create a new cursor. Return the ID for the cursor. 198 ** Create a new cursor. Return the ID for the cursor.
195 */ 199 */
196 static int btree_cursor( 200 static int SQLITE_TCLAPI btree_cursor(
197 void *NotUsed, 201 void *NotUsed,
198 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 202 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
199 int argc, /* Number of arguments */ 203 int argc, /* Number of arguments */
200 const char **argv /* Text of each argument */ 204 const char **argv /* Text of each argument */
201 ){ 205 ){
202 Btree *pBt; 206 Btree *pBt;
203 int iTable; 207 int iTable;
204 BtCursor *pCur; 208 BtCursor *pCur;
205 int rc = SQLITE_OK; 209 int rc = SQLITE_OK;
206 int wrFlag; 210 int wrFlag;
(...skipping 28 matching lines...) Expand all
235 sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur); 239 sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur);
236 Tcl_AppendResult(interp, zBuf, 0); 240 Tcl_AppendResult(interp, zBuf, 0);
237 return SQLITE_OK; 241 return SQLITE_OK;
238 } 242 }
239 243
240 /* 244 /*
241 ** Usage: btree_close_cursor ID 245 ** Usage: btree_close_cursor ID
242 ** 246 **
243 ** Close a cursor opened using btree_cursor. 247 ** Close a cursor opened using btree_cursor.
244 */ 248 */
245 static int btree_close_cursor( 249 static int SQLITE_TCLAPI btree_close_cursor(
246 void *NotUsed, 250 void *NotUsed,
247 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 251 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
248 int argc, /* Number of arguments */ 252 int argc, /* Number of arguments */
249 const char **argv /* Text of each argument */ 253 const char **argv /* Text of each argument */
250 ){ 254 ){
251 BtCursor *pCur; 255 BtCursor *pCur;
252 Btree *pBt;
253 int rc; 256 int rc;
254 257
255 if( argc!=2 ){ 258 if( argc!=2 ){
256 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 259 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
257 " ID\"", 0); 260 " ID\"", 0);
258 return TCL_ERROR; 261 return TCL_ERROR;
259 } 262 }
260 pCur = sqlite3TestTextToPtr(argv[1]); 263 pCur = sqlite3TestTextToPtr(argv[1]);
261 pBt = pCur->pBtree; 264 #if SQLITE_THREADSAFE>0
262 sqlite3_mutex_enter(pBt->db->mutex); 265 {
263 sqlite3BtreeEnter(pBt); 266 Btree *pBt = pCur->pBtree;
267 sqlite3_mutex_enter(pBt->db->mutex);
268 sqlite3BtreeEnter(pBt);
269 rc = sqlite3BtreeCloseCursor(pCur);
270 sqlite3BtreeLeave(pBt);
271 sqlite3_mutex_leave(pBt->db->mutex);
272 }
273 #else
264 rc = sqlite3BtreeCloseCursor(pCur); 274 rc = sqlite3BtreeCloseCursor(pCur);
265 sqlite3BtreeLeave(pBt); 275 #endif
266 sqlite3_mutex_leave(pBt->db->mutex);
267 ckfree((char *)pCur); 276 ckfree((char *)pCur);
268 if( rc ){ 277 if( rc ){
269 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); 278 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
270 return TCL_ERROR; 279 return TCL_ERROR;
271 } 280 }
272 return SQLITE_OK; 281 return SQLITE_OK;
273 } 282 }
274 283
275 /* 284 /*
276 ** Usage: btree_next ID 285 ** Usage: btree_next ID
277 ** 286 **
278 ** Move the cursor to the next entry in the table. Return 0 on success 287 ** Move the cursor to the next entry in the table. Return 0 on success
279 ** or 1 if the cursor was already on the last entry in the table or if 288 ** or 1 if the cursor was already on the last entry in the table or if
280 ** the table is empty. 289 ** the table is empty.
281 */ 290 */
282 static int btree_next( 291 static int SQLITE_TCLAPI btree_next(
283 void *NotUsed, 292 void *NotUsed,
284 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 293 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
285 int argc, /* Number of arguments */ 294 int argc, /* Number of arguments */
286 const char **argv /* Text of each argument */ 295 const char **argv /* Text of each argument */
287 ){ 296 ){
288 BtCursor *pCur; 297 BtCursor *pCur;
289 int rc; 298 int rc;
290 int res = 0; 299 int res = 0;
291 char zBuf[100]; 300 char zBuf[100];
292 301
(...skipping 14 matching lines...) Expand all
307 Tcl_AppendResult(interp, zBuf, 0); 316 Tcl_AppendResult(interp, zBuf, 0);
308 return SQLITE_OK; 317 return SQLITE_OK;
309 } 318 }
310 319
311 /* 320 /*
312 ** Usage: btree_first ID 321 ** Usage: btree_first ID
313 ** 322 **
314 ** Move the cursor to the first entry in the table. Return 0 if the 323 ** Move the cursor to the first entry in the table. Return 0 if the
315 ** cursor was left point to something and 1 if the table is empty. 324 ** cursor was left point to something and 1 if the table is empty.
316 */ 325 */
317 static int btree_first( 326 static int SQLITE_TCLAPI btree_first(
318 void *NotUsed, 327 void *NotUsed,
319 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 328 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
320 int argc, /* Number of arguments */ 329 int argc, /* Number of arguments */
321 const char **argv /* Text of each argument */ 330 const char **argv /* Text of each argument */
322 ){ 331 ){
323 BtCursor *pCur; 332 BtCursor *pCur;
324 int rc; 333 int rc;
325 int res = 0; 334 int res = 0;
326 char zBuf[100]; 335 char zBuf[100];
327 336
(...skipping 14 matching lines...) Expand all
342 Tcl_AppendResult(interp, zBuf, 0); 351 Tcl_AppendResult(interp, zBuf, 0);
343 return SQLITE_OK; 352 return SQLITE_OK;
344 } 353 }
345 354
346 /* 355 /*
347 ** Usage: btree_eof ID 356 ** Usage: btree_eof ID
348 ** 357 **
349 ** Return TRUE if the given cursor is not pointing at a valid entry. 358 ** Return TRUE if the given cursor is not pointing at a valid entry.
350 ** Return FALSE if the cursor does point to a valid entry. 359 ** Return FALSE if the cursor does point to a valid entry.
351 */ 360 */
352 static int btree_eof( 361 static int SQLITE_TCLAPI btree_eof(
353 void *NotUsed, 362 void *NotUsed,
354 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 363 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
355 int argc, /* Number of arguments */ 364 int argc, /* Number of arguments */
356 const char **argv /* Text of each argument */ 365 const char **argv /* Text of each argument */
357 ){ 366 ){
358 BtCursor *pCur; 367 BtCursor *pCur;
359 int rc; 368 int rc;
360 char zBuf[50]; 369 char zBuf[50];
361 370
362 if( argc!=2 ){ 371 if( argc!=2 ){
363 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 372 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
364 " ID\"", 0); 373 " ID\"", 0);
365 return TCL_ERROR; 374 return TCL_ERROR;
366 } 375 }
367 pCur = sqlite3TestTextToPtr(argv[1]); 376 pCur = sqlite3TestTextToPtr(argv[1]);
368 sqlite3BtreeEnter(pCur->pBtree); 377 sqlite3BtreeEnter(pCur->pBtree);
369 rc = sqlite3BtreeEof(pCur); 378 rc = sqlite3BtreeEof(pCur);
370 sqlite3BtreeLeave(pCur->pBtree); 379 sqlite3BtreeLeave(pCur->pBtree);
371 sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", rc); 380 sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", rc);
372 Tcl_AppendResult(interp, zBuf, 0); 381 Tcl_AppendResult(interp, zBuf, 0);
373 return SQLITE_OK; 382 return SQLITE_OK;
374 } 383 }
375 384
376 /* 385 /*
377 ** Usage: btree_payload_size ID 386 ** Usage: btree_payload_size ID
378 ** 387 **
379 ** Return the number of bytes of payload 388 ** Return the number of bytes of payload
380 */ 389 */
381 static int btree_payload_size( 390 static int SQLITE_TCLAPI btree_payload_size(
382 void *NotUsed, 391 void *NotUsed,
383 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 392 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
384 int argc, /* Number of arguments */ 393 int argc, /* Number of arguments */
385 const char **argv /* Text of each argument */ 394 const char **argv /* Text of each argument */
386 ){ 395 ){
387 BtCursor *pCur; 396 BtCursor *pCur;
388 int n2; 397 u32 n;
389 u64 n1;
390 char zBuf[50]; 398 char zBuf[50];
391 399
392 if( argc!=2 ){ 400 if( argc!=2 ){
393 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 401 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
394 " ID\"", 0); 402 " ID\"", 0);
395 return TCL_ERROR; 403 return TCL_ERROR;
396 } 404 }
397 pCur = sqlite3TestTextToPtr(argv[1]); 405 pCur = sqlite3TestTextToPtr(argv[1]);
398 sqlite3BtreeEnter(pCur->pBtree); 406 sqlite3BtreeEnter(pCur->pBtree);
399 407 n = sqlite3BtreePayloadSize(pCur);
400 /* The cursor may be in "require-seek" state. If this is the case, the
401 ** call to BtreeDataSize() will fix it. */
402 sqlite3BtreeDataSize(pCur, (u32*)&n2);
403 if( pCur->apPage[pCur->iPage]->intKey ){
404 n1 = 0;
405 }else{
406 sqlite3BtreeKeySize(pCur, (i64*)&n1);
407 }
408 sqlite3BtreeLeave(pCur->pBtree); 408 sqlite3BtreeLeave(pCur->pBtree);
409 sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", (int)(n1+n2)); 409 sqlite3_snprintf(sizeof(zBuf),zBuf, "%u", n);
410 Tcl_AppendResult(interp, zBuf, 0); 410 Tcl_AppendResult(interp, zBuf, 0);
411 return SQLITE_OK; 411 return SQLITE_OK;
412 } 412 }
413 413
414 /* 414 /*
415 ** usage: varint_test START MULTIPLIER COUNT INCREMENT 415 ** usage: varint_test START MULTIPLIER COUNT INCREMENT
416 ** 416 **
417 ** This command tests the putVarint() and getVarint() 417 ** This command tests the putVarint() and getVarint()
418 ** routines, both for accuracy and for speed. 418 ** routines, both for accuracy and for speed.
419 ** 419 **
420 ** An integer is written using putVarint() and read back with 420 ** An integer is written using putVarint() and read back with
421 ** getVarint() and varified to be unchanged. This repeats COUNT 421 ** getVarint() and varified to be unchanged. This repeats COUNT
422 ** times. The first integer is START*MULTIPLIER. Each iteration 422 ** times. The first integer is START*MULTIPLIER. Each iteration
423 ** increases the integer by INCREMENT. 423 ** increases the integer by INCREMENT.
424 ** 424 **
425 ** This command returns nothing if it works. It returns an error message 425 ** This command returns nothing if it works. It returns an error message
426 ** if something goes wrong. 426 ** if something goes wrong.
427 */ 427 */
428 static int btree_varint_test( 428 static int SQLITE_TCLAPI btree_varint_test(
429 void *NotUsed, 429 void *NotUsed,
430 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 430 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
431 int argc, /* Number of arguments */ 431 int argc, /* Number of arguments */
432 const char **argv /* Text of each argument */ 432 const char **argv /* Text of each argument */
433 ){ 433 ){
434 u32 start, mult, count, incr; 434 u32 start, mult, count, incr;
435 u64 in, out; 435 u64 in, out;
436 int n1, n2, i, j; 436 int n1, n2, i, j;
437 unsigned char zBuf[100]; 437 unsigned char zBuf[100];
438 if( argc!=5 ){ 438 if( argc!=5 ){
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 502
503 /* 503 /*
504 ** usage: btree_from_db DB-HANDLE 504 ** usage: btree_from_db DB-HANDLE
505 ** 505 **
506 ** This command returns the btree handle for the main database associated 506 ** This command returns the btree handle for the main database associated
507 ** with the database-handle passed as the argument. Example usage: 507 ** with the database-handle passed as the argument. Example usage:
508 ** 508 **
509 ** sqlite3 db test.db 509 ** sqlite3 db test.db
510 ** set bt [btree_from_db db] 510 ** set bt [btree_from_db db]
511 */ 511 */
512 static int btree_from_db( 512 static int SQLITE_TCLAPI btree_from_db(
513 void *NotUsed, 513 void *NotUsed,
514 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 514 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
515 int argc, /* Number of arguments */ 515 int argc, /* Number of arguments */
516 const char **argv /* Text of each argument */ 516 const char **argv /* Text of each argument */
517 ){ 517 ){
518 char zBuf[100]; 518 char zBuf[100];
519 Tcl_CmdInfo info; 519 Tcl_CmdInfo info;
520 sqlite3 *db; 520 sqlite3 *db;
521 Btree *pBt; 521 Btree *pBt;
522 int iDb = 0; 522 int iDb = 0;
(...skipping 17 matching lines...) Expand all
540 540
541 pBt = db->aDb[iDb].pBt; 541 pBt = db->aDb[iDb].pBt;
542 sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", pBt); 542 sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", pBt);
543 Tcl_SetResult(interp, zBuf, TCL_VOLATILE); 543 Tcl_SetResult(interp, zBuf, TCL_VOLATILE);
544 return TCL_OK; 544 return TCL_OK;
545 } 545 }
546 546
547 /* 547 /*
548 ** Usage: btree_ismemdb ID 548 ** Usage: btree_ismemdb ID
549 ** 549 **
550 ** Return true if the B-Tree is in-memory. 550 ** Return true if the B-Tree is currently stored entirely in memory.
551 */ 551 */
552 static int btree_ismemdb( 552 static int SQLITE_TCLAPI btree_ismemdb(
553 void *NotUsed, 553 void *NotUsed,
554 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 554 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
555 int argc, /* Number of arguments */ 555 int argc, /* Number of arguments */
556 const char **argv /* Text of each argument */ 556 const char **argv /* Text of each argument */
557 ){ 557 ){
558 Btree *pBt; 558 Btree *pBt;
559 int res; 559 int res;
560 sqlite3_file *pFile;
560 561
561 if( argc!=2 ){ 562 if( argc!=2 ){
562 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 563 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
563 " ID\"", 0); 564 " ID\"", 0);
564 return TCL_ERROR; 565 return TCL_ERROR;
565 } 566 }
566 pBt = sqlite3TestTextToPtr(argv[1]); 567 pBt = sqlite3TestTextToPtr(argv[1]);
567 sqlite3_mutex_enter(pBt->db->mutex); 568 sqlite3_mutex_enter(pBt->db->mutex);
568 sqlite3BtreeEnter(pBt); 569 sqlite3BtreeEnter(pBt);
569 res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt)); 570 pFile = sqlite3PagerFile(sqlite3BtreePager(pBt));
571 res = (pFile->pMethods==0);
570 sqlite3BtreeLeave(pBt); 572 sqlite3BtreeLeave(pBt);
571 sqlite3_mutex_leave(pBt->db->mutex); 573 sqlite3_mutex_leave(pBt->db->mutex);
572 Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res)); 574 Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res));
573 return SQLITE_OK; 575 return SQLITE_OK;
574 } 576 }
575 577
576 /* 578 /*
577 ** usage: btree_set_cache_size ID NCACHE 579 ** usage: btree_set_cache_size ID NCACHE
578 ** 580 **
579 ** Set the size of the cache used by btree $ID. 581 ** Set the size of the cache used by btree $ID.
580 */ 582 */
581 static int btree_set_cache_size( 583 static int SQLITE_TCLAPI btree_set_cache_size(
582 void *NotUsed, 584 void *NotUsed,
583 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 585 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
584 int argc, /* Number of arguments */ 586 int argc, /* Number of arguments */
585 const char **argv /* Text of each argument */ 587 const char **argv /* Text of each argument */
586 ){ 588 ){
587 int nCache; 589 int nCache;
588 Btree *pBt; 590 Btree *pBt;
589 591
590 if( argc!=3 ){ 592 if( argc!=3 ){
591 Tcl_AppendResult( 593 Tcl_AppendResult(
592 interp, "wrong # args: should be \"", argv[0], " BT NCACHE\"", 0); 594 interp, "wrong # args: should be \"", argv[0], " BT NCACHE\"", 0);
593 return TCL_ERROR; 595 return TCL_ERROR;
594 } 596 }
595 pBt = sqlite3TestTextToPtr(argv[1]); 597 pBt = sqlite3TestTextToPtr(argv[1]);
596 if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR; 598 if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
597 599
598 sqlite3_mutex_enter(pBt->db->mutex); 600 sqlite3_mutex_enter(pBt->db->mutex);
599 sqlite3BtreeEnter(pBt); 601 sqlite3BtreeEnter(pBt);
600 sqlite3BtreeSetCacheSize(pBt, nCache); 602 sqlite3BtreeSetCacheSize(pBt, nCache);
601 sqlite3BtreeLeave(pBt); 603 sqlite3BtreeLeave(pBt);
602 sqlite3_mutex_leave(pBt->db->mutex); 604 sqlite3_mutex_leave(pBt->db->mutex);
603 return TCL_OK; 605 return TCL_OK;
604 } 606 }
605 607
606 /* 608 /*
607 ** usage: btree_insert CSR ?KEY? VALUE 609 ** usage: btree_insert CSR ?KEY? VALUE
608 ** 610 **
609 ** Set the size of the cache used by btree $ID. 611 ** Set the size of the cache used by btree $ID.
610 */ 612 */
611 static int btree_insert( 613 static int SQLITE_TCLAPI btree_insert(
612 ClientData clientData, 614 ClientData clientData,
613 Tcl_Interp *interp, 615 Tcl_Interp *interp,
614 int objc, 616 int objc,
615 Tcl_Obj *const objv[] 617 Tcl_Obj *const objv[]
616 ){ 618 ){
617 BtCursor *pCur; 619 BtCursor *pCur;
618 int rc; 620 int rc;
619 void *pKey = 0; 621 BtreePayload x;
620 int nKey = 0;
621 void *pData = 0;
622 int nData = 0;
623 622
624 if( objc!=4 && objc!=3 ){ 623 if( objc!=4 && objc!=3 ){
625 Tcl_WrongNumArgs(interp, 1, objv, "?-intkey? CSR KEY VALUE"); 624 Tcl_WrongNumArgs(interp, 1, objv, "?-intkey? CSR KEY VALUE");
626 return TCL_ERROR; 625 return TCL_ERROR;
627 } 626 }
628 627
628 memset(&x, 0, sizeof(x));
629 if( objc==4 ){ 629 if( objc==4 ){
630 if( Tcl_GetIntFromObj(interp, objv[2], &nKey) ) return TCL_ERROR; 630 if( Tcl_GetIntFromObj(interp, objv[2], &rc) ) return TCL_ERROR;
631 pData = (void*)Tcl_GetByteArrayFromObj(objv[3], &nData); 631 x.nKey = rc;
632 x.pData = (void*)Tcl_GetByteArrayFromObj(objv[3], &x.nData);
632 }else{ 633 }else{
633 pKey = (void*)Tcl_GetByteArrayFromObj(objv[2], &nKey); 634 x.pKey = (void*)Tcl_GetByteArrayFromObj(objv[2], &rc);
635 x.nKey = rc;
634 } 636 }
635 pCur = (BtCursor*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 637 pCur = (BtCursor*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
636 638
637 sqlite3_mutex_enter(pCur->pBtree->db->mutex); 639 sqlite3_mutex_enter(pCur->pBtree->db->mutex);
638 sqlite3BtreeEnter(pCur->pBtree); 640 sqlite3BtreeEnter(pCur->pBtree);
639 rc = sqlite3BtreeInsert(pCur, pKey, nKey, pData, nData, 0, 0, 0); 641 rc = sqlite3BtreeInsert(pCur, &x, 0, 0);
640 sqlite3BtreeLeave(pCur->pBtree); 642 sqlite3BtreeLeave(pCur->pBtree);
641 sqlite3_mutex_leave(pCur->pBtree->db->mutex); 643 sqlite3_mutex_leave(pCur->pBtree->db->mutex);
642 644
643 Tcl_ResetResult(interp); 645 Tcl_ResetResult(interp);
644 if( rc ){ 646 if( rc ){
645 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); 647 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
646 return TCL_ERROR; 648 return TCL_ERROR;
647 } 649 }
648 return TCL_OK; 650 return TCL_OK;
649 } 651 }
(...skipping 25 matching lines...) Expand all
675 int i; 677 int i;
676 678
677 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ 679 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
678 Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); 680 Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
679 } 681 }
680 682
681 Tcl_CreateObjCommand(interp, "btree_insert", btree_insert, 0, 0); 683 Tcl_CreateObjCommand(interp, "btree_insert", btree_insert, 0, 0);
682 684
683 return TCL_OK; 685 return TCL_OK;
684 } 686 }
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/test2.c ('k') | third_party/sqlite/src/src/test4.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698