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

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

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 **
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 char zBuf[30]; 207 char zBuf[30];
208 208
209 if( argc!=4 ){ 209 if( argc!=4 ){
210 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 210 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
211 " ID TABLENUM WRITEABLE\"", 0); 211 " ID TABLENUM WRITEABLE\"", 0);
212 return TCL_ERROR; 212 return TCL_ERROR;
213 } 213 }
214 pBt = sqlite3TestTextToPtr(argv[1]); 214 pBt = sqlite3TestTextToPtr(argv[1]);
215 if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR; 215 if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
216 if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR; 216 if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR;
217 if( wrFlag ) wrFlag = BTREE_WRCSR;
217 pCur = (BtCursor *)ckalloc(sqlite3BtreeCursorSize()); 218 pCur = (BtCursor *)ckalloc(sqlite3BtreeCursorSize());
218 memset(pCur, 0, sqlite3BtreeCursorSize()); 219 memset(pCur, 0, sqlite3BtreeCursorSize());
220 sqlite3_mutex_enter(pBt->db->mutex);
219 sqlite3BtreeEnter(pBt); 221 sqlite3BtreeEnter(pBt);
220 #ifndef SQLITE_OMIT_SHARED_CACHE 222 #ifndef SQLITE_OMIT_SHARED_CACHE
221 rc = sqlite3BtreeLockTable(pBt, iTable, wrFlag); 223 rc = sqlite3BtreeLockTable(pBt, iTable, !!wrFlag);
222 #endif 224 #endif
223 if( rc==SQLITE_OK ){ 225 if( rc==SQLITE_OK ){
224 rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, pCur); 226 rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, 0, pCur);
225 } 227 }
226 sqlite3BtreeLeave(pBt); 228 sqlite3BtreeLeave(pBt);
229 sqlite3_mutex_leave(pBt->db->mutex);
227 if( rc ){ 230 if( rc ){
228 ckfree((char *)pCur); 231 ckfree((char *)pCur);
229 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); 232 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
230 return TCL_ERROR; 233 return TCL_ERROR;
231 } 234 }
232 sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur); 235 sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur);
233 Tcl_AppendResult(interp, zBuf, 0); 236 Tcl_AppendResult(interp, zBuf, 0);
234 return SQLITE_OK; 237 return SQLITE_OK;
235 } 238 }
236 239
(...skipping 12 matching lines...) Expand all
249 Btree *pBt; 252 Btree *pBt;
250 int rc; 253 int rc;
251 254
252 if( argc!=2 ){ 255 if( argc!=2 ){
253 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 256 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
254 " ID\"", 0); 257 " ID\"", 0);
255 return TCL_ERROR; 258 return TCL_ERROR;
256 } 259 }
257 pCur = sqlite3TestTextToPtr(argv[1]); 260 pCur = sqlite3TestTextToPtr(argv[1]);
258 pBt = pCur->pBtree; 261 pBt = pCur->pBtree;
262 sqlite3_mutex_enter(pBt->db->mutex);
259 sqlite3BtreeEnter(pBt); 263 sqlite3BtreeEnter(pBt);
260 rc = sqlite3BtreeCloseCursor(pCur); 264 rc = sqlite3BtreeCloseCursor(pCur);
261 sqlite3BtreeLeave(pBt); 265 sqlite3BtreeLeave(pBt);
266 sqlite3_mutex_leave(pBt->db->mutex);
262 ckfree((char *)pCur); 267 ckfree((char *)pCur);
263 if( rc ){ 268 if( rc ){
264 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); 269 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
265 return TCL_ERROR; 270 return TCL_ERROR;
266 } 271 }
267 return SQLITE_OK; 272 return SQLITE_OK;
268 } 273 }
269 274
270 /* 275 /*
271 ** Usage: btree_next ID 276 ** Usage: btree_next ID
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 if( Tcl_GetInt(interp, argv[1], (int*)&start) ) return TCL_ERROR; 443 if( Tcl_GetInt(interp, argv[1], (int*)&start) ) return TCL_ERROR;
439 if( Tcl_GetInt(interp, argv[2], (int*)&mult) ) return TCL_ERROR; 444 if( Tcl_GetInt(interp, argv[2], (int*)&mult) ) return TCL_ERROR;
440 if( Tcl_GetInt(interp, argv[3], (int*)&count) ) return TCL_ERROR; 445 if( Tcl_GetInt(interp, argv[3], (int*)&count) ) return TCL_ERROR;
441 if( Tcl_GetInt(interp, argv[4], (int*)&incr) ) return TCL_ERROR; 446 if( Tcl_GetInt(interp, argv[4], (int*)&incr) ) return TCL_ERROR;
442 in = start; 447 in = start;
443 in *= mult; 448 in *= mult;
444 for(i=0; i<(int)count; i++){ 449 for(i=0; i<(int)count; i++){
445 char zErr[200]; 450 char zErr[200];
446 n1 = putVarint(zBuf, in); 451 n1 = putVarint(zBuf, in);
447 if( n1>9 || n1<1 ){ 452 if( n1>9 || n1<1 ){
448 sprintf(zErr, "putVarint returned %d - should be between 1 and 9", n1); 453 sqlite3_snprintf(sizeof(zErr), zErr,
454 "putVarint returned %d - should be between 1 and 9", n1);
449 Tcl_AppendResult(interp, zErr, 0); 455 Tcl_AppendResult(interp, zErr, 0);
450 return TCL_ERROR; 456 return TCL_ERROR;
451 } 457 }
452 n2 = getVarint(zBuf, &out); 458 n2 = getVarint(zBuf, &out);
453 if( n1!=n2 ){ 459 if( n1!=n2 ){
454 sprintf(zErr, "putVarint returned %d and getVarint returned %d", n1, n2); 460 sqlite3_snprintf(sizeof(zErr), zErr,
461 "putVarint returned %d and getVarint returned %d", n1, n2);
455 Tcl_AppendResult(interp, zErr, 0); 462 Tcl_AppendResult(interp, zErr, 0);
456 return TCL_ERROR; 463 return TCL_ERROR;
457 } 464 }
458 if( in!=out ){ 465 if( in!=out ){
459 sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx", in, out); 466 sqlite3_snprintf(sizeof(zErr), zErr,
467 "Wrote 0x%016llx and got back 0x%016llx", in, out);
460 Tcl_AppendResult(interp, zErr, 0); 468 Tcl_AppendResult(interp, zErr, 0);
461 return TCL_ERROR; 469 return TCL_ERROR;
462 } 470 }
463 if( (in & 0xffffffff)==in ){ 471 if( (in & 0xffffffff)==in ){
464 u32 out32; 472 u32 out32;
465 n2 = getVarint32(zBuf, out32); 473 n2 = getVarint32(zBuf, out32);
466 out = out32; 474 out = out32;
467 if( n1!=n2 ){ 475 if( n1!=n2 ){
468 sprintf(zErr, "putVarint returned %d and GetVarint32 returned %d", 476 sqlite3_snprintf(sizeof(zErr), zErr,
477 "putVarint returned %d and GetVarint32 returned %d",
469 n1, n2); 478 n1, n2);
470 Tcl_AppendResult(interp, zErr, 0); 479 Tcl_AppendResult(interp, zErr, 0);
471 return TCL_ERROR; 480 return TCL_ERROR;
472 } 481 }
473 if( in!=out ){ 482 if( in!=out ){
474 sprintf(zErr, "Wrote 0x%016llx and got back 0x%016llx from GetVarint32", 483 sqlite3_snprintf(sizeof(zErr), zErr,
484 "Wrote 0x%016llx and got back 0x%016llx from GetVarint32",
475 in, out); 485 in, out);
476 Tcl_AppendResult(interp, zErr, 0); 486 Tcl_AppendResult(interp, zErr, 0);
477 return TCL_ERROR; 487 return TCL_ERROR;
478 } 488 }
479 } 489 }
480 490
481 /* In order to get realistic timings, run getVarint 19 more times. 491 /* In order to get realistic timings, run getVarint 19 more times.
482 ** This is because getVarint is called about 20 times more often 492 ** This is because getVarint is called about 20 times more often
483 ** than putVarint. 493 ** than putVarint.
484 */ 494 */
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR; 596 if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
587 597
588 sqlite3_mutex_enter(pBt->db->mutex); 598 sqlite3_mutex_enter(pBt->db->mutex);
589 sqlite3BtreeEnter(pBt); 599 sqlite3BtreeEnter(pBt);
590 sqlite3BtreeSetCacheSize(pBt, nCache); 600 sqlite3BtreeSetCacheSize(pBt, nCache);
591 sqlite3BtreeLeave(pBt); 601 sqlite3BtreeLeave(pBt);
592 sqlite3_mutex_leave(pBt->db->mutex); 602 sqlite3_mutex_leave(pBt->db->mutex);
593 return TCL_OK; 603 return TCL_OK;
594 } 604 }
595 605
606 /*
607 ** usage: btree_insert CSR ?KEY? VALUE
608 **
609 ** Set the size of the cache used by btree $ID.
610 */
611 static int btree_insert(
612 ClientData clientData,
613 Tcl_Interp *interp,
614 int objc,
615 Tcl_Obj *const objv[]
616 ){
617 BtCursor *pCur;
618 int rc;
619 void *pKey = 0;
620 int nKey = 0;
621 void *pData = 0;
622 int nData = 0;
623
624 if( objc!=4 && objc!=3 ){
625 Tcl_WrongNumArgs(interp, 1, objv, "?-intkey? CSR KEY VALUE");
626 return TCL_ERROR;
627 }
628
629 if( objc==4 ){
630 if( Tcl_GetIntFromObj(interp, objv[2], &nKey) ) return TCL_ERROR;
631 pData = (void*)Tcl_GetByteArrayFromObj(objv[3], &nData);
632 }else{
633 pKey = (void*)Tcl_GetByteArrayFromObj(objv[2], &nKey);
634 }
635 pCur = (BtCursor*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
636
637 sqlite3_mutex_enter(pCur->pBtree->db->mutex);
638 sqlite3BtreeEnter(pCur->pBtree);
639 rc = sqlite3BtreeInsert(pCur, pKey, nKey, pData, nData, 0, 0, 0);
640 sqlite3BtreeLeave(pCur->pBtree);
641 sqlite3_mutex_leave(pCur->pBtree->db->mutex);
642
643 Tcl_ResetResult(interp);
644 if( rc ){
645 Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
646 return TCL_ERROR;
647 }
648 return TCL_OK;
649 }
596 650
597 651
598 /* 652 /*
599 ** Register commands with the TCL interpreter. 653 ** Register commands with the TCL interpreter.
600 */ 654 */
601 int Sqlitetest3_Init(Tcl_Interp *interp){ 655 int Sqlitetest3_Init(Tcl_Interp *interp){
602 static struct { 656 static struct {
603 char *zName; 657 char *zName;
604 Tcl_CmdProc *xProc; 658 Tcl_CmdProc *xProc;
605 } aCmd[] = { 659 } aCmd[] = {
(...skipping 11 matching lines...) Expand all
617 { "btree_from_db", (Tcl_CmdProc*)btree_from_db }, 671 { "btree_from_db", (Tcl_CmdProc*)btree_from_db },
618 { "btree_ismemdb", (Tcl_CmdProc*)btree_ismemdb }, 672 { "btree_ismemdb", (Tcl_CmdProc*)btree_ismemdb },
619 { "btree_set_cache_size", (Tcl_CmdProc*)btree_set_cache_size } 673 { "btree_set_cache_size", (Tcl_CmdProc*)btree_set_cache_size }
620 }; 674 };
621 int i; 675 int i;
622 676
623 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ 677 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
624 Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); 678 Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
625 } 679 }
626 680
681 Tcl_CreateObjCommand(interp, "btree_insert", btree_insert, 0, 0);
682
627 return TCL_OK; 683 return TCL_OK;
628 } 684 }
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/test2.c ('k') | third_party/sqlite/sqlite-src-3100200/src/test4.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698