| OLD | NEW |
| 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 ** Main file for the SQLite library. The routines in this file | 12 ** Main file for the SQLite library. The routines in this file |
| 13 ** implement the programmer interface to the library. Routines in | 13 ** implement the programmer interface to the library. Routines in |
| 14 ** other files are for internal use by SQLite and should not be | 14 ** other files are for internal use by SQLite and should not be |
| 15 ** accessed by users of the library. | 15 ** accessed by users of the library. |
| 16 */ | 16 */ |
| 17 #include "sqliteInt.h" | 17 #include "sqliteInt.h" |
| 18 | 18 |
| 19 #ifdef SQLITE_ENABLE_FTS3 | 19 #ifdef SQLITE_ENABLE_FTS3 |
| 20 # include "../../ext/fts3/fts3.h" | 20 # include "fts3.h" |
| 21 #endif | 21 #endif |
| 22 #ifdef SQLITE_ENABLE_RTREE | 22 #ifdef SQLITE_ENABLE_RTREE |
| 23 # include "rtree.h" | 23 # include "rtree.h" |
| 24 #endif | 24 #endif |
| 25 #ifdef SQLITE_ENABLE_ICU | 25 #ifdef SQLITE_ENABLE_ICU |
| 26 # include "sqliteicu.h" | 26 # include "sqliteicu.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 /* | 29 #ifndef SQLITE_AMALGAMATION |
| 30 ** The version of the library | 30 /* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant |
| 31 ** contains the text of SQLITE_VERSION macro. |
| 31 */ | 32 */ |
| 32 #ifndef SQLITE_AMALGAMATION | |
| 33 const char sqlite3_version[] = SQLITE_VERSION; | 33 const char sqlite3_version[] = SQLITE_VERSION; |
| 34 #endif | 34 #endif |
| 35 |
| 36 /* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns |
| 37 ** a pointer to the to the sqlite3_version[] string constant. |
| 38 */ |
| 35 const char *sqlite3_libversion(void){ return sqlite3_version; } | 39 const char *sqlite3_libversion(void){ return sqlite3_version; } |
| 40 |
| 41 /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a |
| 42 ** pointer to a string constant whose value is the same as the |
| 43 ** SQLITE_SOURCE_ID C preprocessor macro. |
| 44 */ |
| 36 const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } | 45 const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 46 |
| 47 /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function |
| 48 ** returns an integer equal to SQLITE_VERSION_NUMBER. |
| 49 */ |
| 37 int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } | 50 int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; } |
| 51 |
| 52 /* IMPLEMENTATION-OF: R-54823-41343 The sqlite3_threadsafe() function returns |
| 53 ** zero if and only if SQLite was compiled mutexing code omitted due to |
| 54 ** the SQLITE_THREADSAFE compile-time option being set to 0. |
| 55 */ |
| 38 int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } | 56 int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; } |
| 39 | 57 |
| 40 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) | 58 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
| 41 /* | 59 /* |
| 42 ** If the following function pointer is not NULL and if | 60 ** If the following function pointer is not NULL and if |
| 43 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing | 61 ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing |
| 44 ** I/O active are written using this function. These messages | 62 ** I/O active are written using this function. These messages |
| 45 ** are intended for debugging activity only. | 63 ** are intended for debugging activity only. |
| 46 */ | 64 */ |
| 47 void (*sqlite3IoTrace)(const char*, ...) = 0; | 65 void (*sqlite3IoTrace)(const char*, ...) = 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 ** the pInitMutex mutex. Return an error in either case. */ | 166 ** the pInitMutex mutex. Return an error in either case. */ |
| 149 if( rc!=SQLITE_OK ){ | 167 if( rc!=SQLITE_OK ){ |
| 150 return rc; | 168 return rc; |
| 151 } | 169 } |
| 152 | 170 |
| 153 /* Do the rest of the initialization under the recursive mutex so | 171 /* Do the rest of the initialization under the recursive mutex so |
| 154 ** that we will be able to handle recursive calls into | 172 ** that we will be able to handle recursive calls into |
| 155 ** sqlite3_initialize(). The recursive calls normally come through | 173 ** sqlite3_initialize(). The recursive calls normally come through |
| 156 ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other | 174 ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other |
| 157 ** recursive calls might also be possible. | 175 ** recursive calls might also be possible. |
| 176 ** |
| 177 ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls |
| 178 ** to the xInit method, so the xInit method need not be threadsafe. |
| 179 ** |
| 180 ** The following mutex is what serializes access to the appdef pcache xInit |
| 181 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the |
| 182 ** call to sqlite3PcacheInitialize(). |
| 158 */ | 183 */ |
| 159 sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex); | 184 sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex); |
| 160 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ | 185 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ |
| 161 FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); | 186 FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); |
| 162 sqlite3GlobalConfig.inProgress = 1; | 187 sqlite3GlobalConfig.inProgress = 1; |
| 163 memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); | 188 memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); |
| 164 sqlite3RegisterGlobalFunctions(); | 189 sqlite3RegisterGlobalFunctions(); |
| 165 if( sqlite3GlobalConfig.isPCacheInit==0 ){ | 190 if( sqlite3GlobalConfig.isPCacheInit==0 ){ |
| 166 rc = sqlite3PcacheInitialize(); | 191 rc = sqlite3PcacheInitialize(); |
| 167 } | 192 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 ** database connections or memory allocations. This routine is not | 275 ** database connections or memory allocations. This routine is not |
| 251 ** threadsafe. Failure to heed these warnings can lead to unpredictable | 276 ** threadsafe. Failure to heed these warnings can lead to unpredictable |
| 252 ** behavior. | 277 ** behavior. |
| 253 */ | 278 */ |
| 254 int sqlite3_config(int op, ...){ | 279 int sqlite3_config(int op, ...){ |
| 255 va_list ap; | 280 va_list ap; |
| 256 int rc = SQLITE_OK; | 281 int rc = SQLITE_OK; |
| 257 | 282 |
| 258 /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while | 283 /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while |
| 259 ** the SQLite library is in use. */ | 284 ** the SQLite library is in use. */ |
| 260 if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE; | 285 if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE_BKPT; |
| 261 | 286 |
| 262 va_start(ap, op); | 287 va_start(ap, op); |
| 263 switch( op ){ | 288 switch( op ){ |
| 264 | 289 |
| 265 /* Mutex configuration options are only available in a threadsafe | 290 /* Mutex configuration options are only available in a threadsafe |
| 266 ** compile. | 291 ** compile. |
| 267 */ | 292 */ |
| 268 #if SQLITE_THREADSAFE | 293 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 |
| 269 case SQLITE_CONFIG_SINGLETHREAD: { | 294 case SQLITE_CONFIG_SINGLETHREAD: { |
| 270 /* Disable all mutexing */ | 295 /* Disable all mutexing */ |
| 271 sqlite3GlobalConfig.bCoreMutex = 0; | 296 sqlite3GlobalConfig.bCoreMutex = 0; |
| 272 sqlite3GlobalConfig.bFullMutex = 0; | 297 sqlite3GlobalConfig.bFullMutex = 0; |
| 273 break; | 298 break; |
| 274 } | 299 } |
| 275 case SQLITE_CONFIG_MULTITHREAD: { | 300 case SQLITE_CONFIG_MULTITHREAD: { |
| 276 /* Disable mutexing of database connections */ | 301 /* Disable mutexing of database connections */ |
| 277 /* Enable mutexing of core data structures */ | 302 /* Enable mutexing of core data structures */ |
| 278 sqlite3GlobalConfig.bCoreMutex = 1; | 303 sqlite3GlobalConfig.bCoreMutex = 1; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 396 } |
| 372 break; | 397 break; |
| 373 } | 398 } |
| 374 #endif | 399 #endif |
| 375 | 400 |
| 376 case SQLITE_CONFIG_LOOKASIDE: { | 401 case SQLITE_CONFIG_LOOKASIDE: { |
| 377 sqlite3GlobalConfig.szLookaside = va_arg(ap, int); | 402 sqlite3GlobalConfig.szLookaside = va_arg(ap, int); |
| 378 sqlite3GlobalConfig.nLookaside = va_arg(ap, int); | 403 sqlite3GlobalConfig.nLookaside = va_arg(ap, int); |
| 379 break; | 404 break; |
| 380 } | 405 } |
| 406 |
| 407 /* Record a pointer to the logger funcction and its first argument. |
| 408 ** The default is NULL. Logging is disabled if the function pointer is |
| 409 ** NULL. |
| 410 */ |
| 411 case SQLITE_CONFIG_LOG: { |
| 412 /* MSVC is picky about pulling func ptrs from va lists. |
| 413 ** http://support.microsoft.com/kb/47961 |
| 414 ** sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*)); |
| 415 */ |
| 416 typedef void(*LOGFUNC_t)(void*,int,const char*); |
| 417 sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t); |
| 418 sqlite3GlobalConfig.pLogArg = va_arg(ap, void*); |
| 419 break; |
| 420 } |
| 381 | 421 |
| 382 default: { | 422 default: { |
| 383 rc = SQLITE_ERROR; | 423 rc = SQLITE_ERROR; |
| 384 break; | 424 break; |
| 385 } | 425 } |
| 386 } | 426 } |
| 387 va_end(ap); | 427 va_end(ap); |
| 388 return rc; | 428 return rc; |
| 389 } | 429 } |
| 390 | 430 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 413 } | 453 } |
| 414 /* The size of a lookaside slot needs to be larger than a pointer | 454 /* The size of a lookaside slot needs to be larger than a pointer |
| 415 ** to be useful. | 455 ** to be useful. |
| 416 */ | 456 */ |
| 417 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0; | 457 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0; |
| 418 if( cnt<0 ) cnt = 0; | 458 if( cnt<0 ) cnt = 0; |
| 419 if( sz==0 || cnt==0 ){ | 459 if( sz==0 || cnt==0 ){ |
| 420 sz = 0; | 460 sz = 0; |
| 421 pStart = 0; | 461 pStart = 0; |
| 422 }else if( pBuf==0 ){ | 462 }else if( pBuf==0 ){ |
| 423 sz = ROUND8(sz); | 463 sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */ |
| 424 sqlite3BeginBenignMalloc(); | 464 sqlite3BeginBenignMalloc(); |
| 425 pStart = sqlite3Malloc( sz*cnt ); | 465 pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */ |
| 426 sqlite3EndBenignMalloc(); | 466 sqlite3EndBenignMalloc(); |
| 427 }else{ | 467 }else{ |
| 428 sz = ROUNDDOWN8(sz); | 468 sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */ |
| 429 pStart = pBuf; | 469 pStart = pBuf; |
| 430 } | 470 } |
| 431 db->lookaside.pStart = pStart; | 471 db->lookaside.pStart = pStart; |
| 432 db->lookaside.pFree = 0; | 472 db->lookaside.pFree = 0; |
| 433 db->lookaside.sz = (u16)sz; | 473 db->lookaside.sz = (u16)sz; |
| 434 if( pStart ){ | 474 if( pStart ){ |
| 435 int i; | 475 int i; |
| 436 LookasideSlot *p; | 476 LookasideSlot *p; |
| 437 assert( sz > (int)sizeof(LookasideSlot*) ); | 477 assert( sz > (int)sizeof(LookasideSlot*) ); |
| 438 p = (LookasideSlot*)pStart; | 478 p = (LookasideSlot*)pStart; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 461 | 501 |
| 462 /* | 502 /* |
| 463 ** Configuration settings for an individual database connection | 503 ** Configuration settings for an individual database connection |
| 464 */ | 504 */ |
| 465 int sqlite3_db_config(sqlite3 *db, int op, ...){ | 505 int sqlite3_db_config(sqlite3 *db, int op, ...){ |
| 466 va_list ap; | 506 va_list ap; |
| 467 int rc; | 507 int rc; |
| 468 va_start(ap, op); | 508 va_start(ap, op); |
| 469 switch( op ){ | 509 switch( op ){ |
| 470 case SQLITE_DBCONFIG_LOOKASIDE: { | 510 case SQLITE_DBCONFIG_LOOKASIDE: { |
| 471 void *pBuf = va_arg(ap, void*); | 511 void *pBuf = va_arg(ap, void*); /* IMP: R-21112-12275 */ |
| 472 int sz = va_arg(ap, int); | 512 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */ |
| 473 int cnt = va_arg(ap, int); | 513 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */ |
| 474 rc = setupLookaside(db, pBuf, sz, cnt); | 514 rc = setupLookaside(db, pBuf, sz, cnt); |
| 475 break; | 515 break; |
| 476 } | 516 } |
| 477 default: { | 517 default: { |
| 478 rc = SQLITE_ERROR; | 518 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
| 479 break; | 519 break; |
| 480 } | 520 } |
| 481 } | 521 } |
| 482 va_end(ap); | 522 va_end(ap); |
| 483 return rc; | 523 return rc; |
| 484 } | 524 } |
| 485 | 525 |
| 486 | 526 |
| 487 /* | 527 /* |
| 488 ** Return true if the buffer z[0..n-1] contains all spaces. | 528 ** Return true if the buffer z[0..n-1] contains all spaces. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 Savepoint *pTmp = db->pSavepoint; | 614 Savepoint *pTmp = db->pSavepoint; |
| 575 db->pSavepoint = pTmp->pNext; | 615 db->pSavepoint = pTmp->pNext; |
| 576 sqlite3DbFree(db, pTmp); | 616 sqlite3DbFree(db, pTmp); |
| 577 } | 617 } |
| 578 db->nSavepoint = 0; | 618 db->nSavepoint = 0; |
| 579 db->nStatement = 0; | 619 db->nStatement = 0; |
| 580 db->isTransactionSavepoint = 0; | 620 db->isTransactionSavepoint = 0; |
| 581 } | 621 } |
| 582 | 622 |
| 583 /* | 623 /* |
| 624 ** Invoke the destructor function associated with FuncDef p, if any. Except, |
| 625 ** if this is not the last copy of the function, do not invoke it. Multiple |
| 626 ** copies of a single function are created when create_function() is called |
| 627 ** with SQLITE_ANY as the encoding. |
| 628 */ |
| 629 static void functionDestroy(sqlite3 *db, FuncDef *p){ |
| 630 FuncDestructor *pDestructor = p->pDestructor; |
| 631 if( pDestructor ){ |
| 632 pDestructor->nRef--; |
| 633 if( pDestructor->nRef==0 ){ |
| 634 pDestructor->xDestroy(pDestructor->pUserData); |
| 635 sqlite3DbFree(db, pDestructor); |
| 636 } |
| 637 } |
| 638 } |
| 639 |
| 640 /* |
| 584 ** Close an existing SQLite database | 641 ** Close an existing SQLite database |
| 585 */ | 642 */ |
| 586 int sqlite3_close(sqlite3 *db){ | 643 int sqlite3_close(sqlite3 *db){ |
| 587 HashElem *i; | 644 HashElem *i; /* Hash table iterator */ |
| 588 int j; | 645 int j; |
| 589 | 646 |
| 590 if( !db ){ | 647 if( !db ){ |
| 591 return SQLITE_OK; | 648 return SQLITE_OK; |
| 592 } | 649 } |
| 593 if( !sqlite3SafetyCheckSickOrOk(db) ){ | 650 if( !sqlite3SafetyCheckSickOrOk(db) ){ |
| 594 return SQLITE_MISUSE; | 651 return SQLITE_MISUSE_BKPT; |
| 595 } | 652 } |
| 596 sqlite3_mutex_enter(db->mutex); | 653 sqlite3_mutex_enter(db->mutex); |
| 597 | 654 |
| 598 sqlite3ResetInternalSchema(db, 0); | 655 sqlite3ResetInternalSchema(db, 0); |
| 599 | 656 |
| 600 /* If a transaction is open, the ResetInternalSchema() call above | 657 /* If a transaction is open, the ResetInternalSchema() call above |
| 601 ** will not have called the xDisconnect() method on any virtual | 658 ** will not have called the xDisconnect() method on any virtual |
| 602 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() | 659 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() |
| 603 ** call will do so. We need to do this before the check for active | 660 ** call will do so. We need to do this before the check for active |
| 604 ** SQL statements below, as the v-table implementation may be storing | 661 ** SQL statements below, as the v-table implementation may be storing |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 */ | 702 */ |
| 646 sqlite3ConnectionClosed(db); | 703 sqlite3ConnectionClosed(db); |
| 647 | 704 |
| 648 assert( db->nDb<=2 ); | 705 assert( db->nDb<=2 ); |
| 649 assert( db->aDb==db->aDbStatic ); | 706 assert( db->aDb==db->aDbStatic ); |
| 650 for(j=0; j<ArraySize(db->aFunc.a); j++){ | 707 for(j=0; j<ArraySize(db->aFunc.a); j++){ |
| 651 FuncDef *pNext, *pHash, *p; | 708 FuncDef *pNext, *pHash, *p; |
| 652 for(p=db->aFunc.a[j]; p; p=pHash){ | 709 for(p=db->aFunc.a[j]; p; p=pHash){ |
| 653 pHash = p->pHash; | 710 pHash = p->pHash; |
| 654 while( p ){ | 711 while( p ){ |
| 712 functionDestroy(db, p); |
| 655 pNext = p->pNext; | 713 pNext = p->pNext; |
| 656 sqlite3DbFree(db, p); | 714 sqlite3DbFree(db, p); |
| 657 p = pNext; | 715 p = pNext; |
| 658 } | 716 } |
| 659 } | 717 } |
| 660 } | 718 } |
| 661 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){ | 719 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){ |
| 662 CollSeq *pColl = (CollSeq *)sqliteHashData(i); | 720 CollSeq *pColl = (CollSeq *)sqliteHashData(i); |
| 663 /* Invoke any destructors registered for collation sequence user data. */ | 721 /* Invoke any destructors registered for collation sequence user data. */ |
| 664 for(j=0; j<3; j++){ | 722 for(j=0; j<3; j++){ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 782 } |
| 725 } | 783 } |
| 726 sqlite3VtabRollback(db); | 784 sqlite3VtabRollback(db); |
| 727 sqlite3EndBenignMalloc(); | 785 sqlite3EndBenignMalloc(); |
| 728 | 786 |
| 729 if( db->flags&SQLITE_InternChanges ){ | 787 if( db->flags&SQLITE_InternChanges ){ |
| 730 sqlite3ExpirePreparedStatements(db); | 788 sqlite3ExpirePreparedStatements(db); |
| 731 sqlite3ResetInternalSchema(db, 0); | 789 sqlite3ResetInternalSchema(db, 0); |
| 732 } | 790 } |
| 733 | 791 |
| 792 /* Any deferred constraint violations have now been resolved. */ |
| 793 db->nDeferredCons = 0; |
| 794 |
| 734 /* If one has been configured, invoke the rollback-hook callback */ | 795 /* If one has been configured, invoke the rollback-hook callback */ |
| 735 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ | 796 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ |
| 736 db->xRollbackCallback(db->pRollbackArg); | 797 db->xRollbackCallback(db->pRollbackArg); |
| 737 } | 798 } |
| 738 } | 799 } |
| 739 | 800 |
| 740 /* | 801 /* |
| 741 ** Return a static string that describes the kind of error specified in the | 802 ** Return a static string that describes the kind of error specified in the |
| 742 ** argument. | 803 ** argument. |
| 743 */ | 804 */ |
| 744 const char *sqlite3ErrStr(int rc){ | 805 const char *sqlite3ErrStr(int rc){ |
| 745 static const char* const aMsg[] = { | 806 static const char* const aMsg[] = { |
| 746 /* SQLITE_OK */ "not an error", | 807 /* SQLITE_OK */ "not an error", |
| 747 /* SQLITE_ERROR */ "SQL logic error or missing database", | 808 /* SQLITE_ERROR */ "SQL logic error or missing database", |
| 748 /* SQLITE_INTERNAL */ 0, | 809 /* SQLITE_INTERNAL */ 0, |
| 749 /* SQLITE_PERM */ "access permission denied", | 810 /* SQLITE_PERM */ "access permission denied", |
| 750 /* SQLITE_ABORT */ "callback requested query abort", | 811 /* SQLITE_ABORT */ "callback requested query abort", |
| 751 /* SQLITE_BUSY */ "database is locked", | 812 /* SQLITE_BUSY */ "database is locked", |
| 752 /* SQLITE_LOCKED */ "database table is locked", | 813 /* SQLITE_LOCKED */ "database table is locked", |
| 753 /* SQLITE_NOMEM */ "out of memory", | 814 /* SQLITE_NOMEM */ "out of memory", |
| 754 /* SQLITE_READONLY */ "attempt to write a readonly database", | 815 /* SQLITE_READONLY */ "attempt to write a readonly database", |
| 755 /* SQLITE_INTERRUPT */ "interrupted", | 816 /* SQLITE_INTERRUPT */ "interrupted", |
| 756 /* SQLITE_IOERR */ "disk I/O error", | 817 /* SQLITE_IOERR */ "disk I/O error", |
| 757 /* SQLITE_CORRUPT */ "database disk image is malformed", | 818 /* SQLITE_CORRUPT */ "database disk image is malformed", |
| 758 /* SQLITE_NOTFOUND */ 0, | 819 /* SQLITE_NOTFOUND */ 0, |
| 759 /* SQLITE_FULL */ "database or disk is full", | 820 /* SQLITE_FULL */ "database or disk is full", |
| 760 /* SQLITE_CANTOPEN */ "unable to open database file", | 821 /* SQLITE_CANTOPEN */ "unable to open database file", |
| 761 /* SQLITE_PROTOCOL */ 0, | 822 /* SQLITE_PROTOCOL */ "locking protocol", |
| 762 /* SQLITE_EMPTY */ "table contains no data", | 823 /* SQLITE_EMPTY */ "table contains no data", |
| 763 /* SQLITE_SCHEMA */ "database schema has changed", | 824 /* SQLITE_SCHEMA */ "database schema has changed", |
| 764 /* SQLITE_TOOBIG */ "string or blob too big", | 825 /* SQLITE_TOOBIG */ "string or blob too big", |
| 765 /* SQLITE_CONSTRAINT */ "constraint failed", | 826 /* SQLITE_CONSTRAINT */ "constraint failed", |
| 766 /* SQLITE_MISMATCH */ "datatype mismatch", | 827 /* SQLITE_MISMATCH */ "datatype mismatch", |
| 767 /* SQLITE_MISUSE */ "library routine called out of sequence", | 828 /* SQLITE_MISUSE */ "library routine called out of sequence", |
| 768 /* SQLITE_NOLFS */ "large file support is disabled", | 829 /* SQLITE_NOLFS */ "large file support is disabled", |
| 769 /* SQLITE_AUTH */ "authorization denied", | 830 /* SQLITE_AUTH */ "authorization denied", |
| 770 /* SQLITE_FORMAT */ "auxiliary database format error", | 831 /* SQLITE_FORMAT */ "auxiliary database format error", |
| 771 /* SQLITE_RANGE */ "bind or column index out of range", | 832 /* SQLITE_RANGE */ "bind or column index out of range", |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 ** is returned and the mallocFailed flag cleared. | 977 ** is returned and the mallocFailed flag cleared. |
| 917 */ | 978 */ |
| 918 int sqlite3CreateFunc( | 979 int sqlite3CreateFunc( |
| 919 sqlite3 *db, | 980 sqlite3 *db, |
| 920 const char *zFunctionName, | 981 const char *zFunctionName, |
| 921 int nArg, | 982 int nArg, |
| 922 int enc, | 983 int enc, |
| 923 void *pUserData, | 984 void *pUserData, |
| 924 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | 985 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), |
| 925 void (*xStep)(sqlite3_context*,int,sqlite3_value **), | 986 void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 926 void (*xFinal)(sqlite3_context*) | 987 void (*xFinal)(sqlite3_context*), |
| 988 FuncDestructor *pDestructor |
| 927 ){ | 989 ){ |
| 928 FuncDef *p; | 990 FuncDef *p; |
| 929 int nName; | 991 int nName; |
| 930 | 992 |
| 931 assert( sqlite3_mutex_held(db->mutex) ); | 993 assert( sqlite3_mutex_held(db->mutex) ); |
| 932 if( zFunctionName==0 || | 994 if( zFunctionName==0 || |
| 933 (xFunc && (xFinal || xStep)) || | 995 (xFunc && (xFinal || xStep)) || |
| 934 (!xFunc && (xFinal && !xStep)) || | 996 (!xFunc && (xFinal && !xStep)) || |
| 935 (!xFunc && (!xFinal && xStep)) || | 997 (!xFunc && (!xFinal && xStep)) || |
| 936 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || | 998 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 937 (255<(nName = sqlite3Strlen30( zFunctionName))) ){ | 999 (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 938 return SQLITE_MISUSE; | 1000 return SQLITE_MISUSE_BKPT; |
| 939 } | 1001 } |
| 940 | 1002 |
| 941 #ifndef SQLITE_OMIT_UTF16 | 1003 #ifndef SQLITE_OMIT_UTF16 |
| 942 /* If SQLITE_UTF16 is specified as the encoding type, transform this | 1004 /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 943 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the | 1005 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 944 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. | 1006 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| 945 ** | 1007 ** |
| 946 ** If SQLITE_ANY is specified, add three versions of the function | 1008 ** If SQLITE_ANY is specified, add three versions of the function |
| 947 ** to the hash table. | 1009 ** to the hash table. |
| 948 */ | 1010 */ |
| 949 if( enc==SQLITE_UTF16 ){ | 1011 if( enc==SQLITE_UTF16 ){ |
| 950 enc = SQLITE_UTF16NATIVE; | 1012 enc = SQLITE_UTF16NATIVE; |
| 951 }else if( enc==SQLITE_ANY ){ | 1013 }else if( enc==SQLITE_ANY ){ |
| 952 int rc; | 1014 int rc; |
| 953 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8, | 1015 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8, |
| 954 pUserData, xFunc, xStep, xFinal); | 1016 pUserData, xFunc, xStep, xFinal, pDestructor); |
| 955 if( rc==SQLITE_OK ){ | 1017 if( rc==SQLITE_OK ){ |
| 956 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE, | 1018 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE, |
| 957 pUserData, xFunc, xStep, xFinal); | 1019 pUserData, xFunc, xStep, xFinal, pDestructor); |
| 958 } | 1020 } |
| 959 if( rc!=SQLITE_OK ){ | 1021 if( rc!=SQLITE_OK ){ |
| 960 return rc; | 1022 return rc; |
| 961 } | 1023 } |
| 962 enc = SQLITE_UTF16BE; | 1024 enc = SQLITE_UTF16BE; |
| 963 } | 1025 } |
| 964 #else | 1026 #else |
| 965 enc = SQLITE_UTF8; | 1027 enc = SQLITE_UTF8; |
| 966 #endif | 1028 #endif |
| 967 | 1029 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 980 }else{ | 1042 }else{ |
| 981 sqlite3ExpirePreparedStatements(db); | 1043 sqlite3ExpirePreparedStatements(db); |
| 982 } | 1044 } |
| 983 } | 1045 } |
| 984 | 1046 |
| 985 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1); | 1047 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1); |
| 986 assert(p || db->mallocFailed); | 1048 assert(p || db->mallocFailed); |
| 987 if( !p ){ | 1049 if( !p ){ |
| 988 return SQLITE_NOMEM; | 1050 return SQLITE_NOMEM; |
| 989 } | 1051 } |
| 1052 |
| 1053 /* If an older version of the function with a configured destructor is |
| 1054 ** being replaced invoke the destructor function here. */ |
| 1055 functionDestroy(db, p); |
| 1056 |
| 1057 if( pDestructor ){ |
| 1058 pDestructor->nRef++; |
| 1059 } |
| 1060 p->pDestructor = pDestructor; |
| 990 p->flags = 0; | 1061 p->flags = 0; |
| 991 p->xFunc = xFunc; | 1062 p->xFunc = xFunc; |
| 992 p->xStep = xStep; | 1063 p->xStep = xStep; |
| 993 p->xFinalize = xFinal; | 1064 p->xFinalize = xFinal; |
| 994 p->pUserData = pUserData; | 1065 p->pUserData = pUserData; |
| 995 p->nArg = (u16)nArg; | 1066 p->nArg = (u16)nArg; |
| 996 return SQLITE_OK; | 1067 return SQLITE_OK; |
| 997 } | 1068 } |
| 998 | 1069 |
| 999 /* | 1070 /* |
| 1000 ** Create new user functions. | 1071 ** Create new user functions. |
| 1001 */ | 1072 */ |
| 1002 int sqlite3_create_function( | 1073 int sqlite3_create_function( |
| 1003 sqlite3 *db, | 1074 sqlite3 *db, |
| 1004 const char *zFunctionName, | 1075 const char *zFunc, |
| 1005 int nArg, | 1076 int nArg, |
| 1006 int enc, | 1077 int enc, |
| 1007 void *p, | 1078 void *p, |
| 1008 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | 1079 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), |
| 1009 void (*xStep)(sqlite3_context*,int,sqlite3_value **), | 1080 void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 1010 void (*xFinal)(sqlite3_context*) | 1081 void (*xFinal)(sqlite3_context*) |
| 1011 ){ | 1082 ){ |
| 1012 int rc; | 1083 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep, |
| 1084 xFinal, 0); |
| 1085 } |
| 1086 |
| 1087 int sqlite3_create_function_v2( |
| 1088 sqlite3 *db, |
| 1089 const char *zFunc, |
| 1090 int nArg, |
| 1091 int enc, |
| 1092 void *p, |
| 1093 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), |
| 1094 void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
| 1095 void (*xFinal)(sqlite3_context*), |
| 1096 void (*xDestroy)(void *) |
| 1097 ){ |
| 1098 int rc = SQLITE_ERROR; |
| 1099 FuncDestructor *pArg = 0; |
| 1013 sqlite3_mutex_enter(db->mutex); | 1100 sqlite3_mutex_enter(db->mutex); |
| 1014 rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal); | 1101 if( xDestroy ){ |
| 1102 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); |
| 1103 if( !pArg ){ |
| 1104 xDestroy(p); |
| 1105 goto out; |
| 1106 } |
| 1107 pArg->xDestroy = xDestroy; |
| 1108 pArg->pUserData = p; |
| 1109 } |
| 1110 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg); |
| 1111 if( pArg && pArg->nRef==0 ){ |
| 1112 assert( rc!=SQLITE_OK ); |
| 1113 xDestroy(p); |
| 1114 sqlite3DbFree(db, pArg); |
| 1115 } |
| 1116 |
| 1117 out: |
| 1015 rc = sqlite3ApiExit(db, rc); | 1118 rc = sqlite3ApiExit(db, rc); |
| 1016 sqlite3_mutex_leave(db->mutex); | 1119 sqlite3_mutex_leave(db->mutex); |
| 1017 return rc; | 1120 return rc; |
| 1018 } | 1121 } |
| 1019 | 1122 |
| 1020 #ifndef SQLITE_OMIT_UTF16 | 1123 #ifndef SQLITE_OMIT_UTF16 |
| 1021 int sqlite3_create_function16( | 1124 int sqlite3_create_function16( |
| 1022 sqlite3 *db, | 1125 sqlite3 *db, |
| 1023 const void *zFunctionName, | 1126 const void *zFunctionName, |
| 1024 int nArg, | 1127 int nArg, |
| 1025 int eTextRep, | 1128 int eTextRep, |
| 1026 void *p, | 1129 void *p, |
| 1027 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), | 1130 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 1028 void (*xStep)(sqlite3_context*,int,sqlite3_value**), | 1131 void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 1029 void (*xFinal)(sqlite3_context*) | 1132 void (*xFinal)(sqlite3_context*) |
| 1030 ){ | 1133 ){ |
| 1031 int rc; | 1134 int rc; |
| 1032 char *zFunc8; | 1135 char *zFunc8; |
| 1033 sqlite3_mutex_enter(db->mutex); | 1136 sqlite3_mutex_enter(db->mutex); |
| 1034 assert( !db->mallocFailed ); | 1137 assert( !db->mallocFailed ); |
| 1035 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1); | 1138 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
| 1036 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal); | 1139 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); |
| 1037 sqlite3DbFree(db, zFunc8); | 1140 sqlite3DbFree(db, zFunc8); |
| 1038 rc = sqlite3ApiExit(db, rc); | 1141 rc = sqlite3ApiExit(db, rc); |
| 1039 sqlite3_mutex_leave(db->mutex); | 1142 sqlite3_mutex_leave(db->mutex); |
| 1040 return rc; | 1143 return rc; |
| 1041 } | 1144 } |
| 1042 #endif | 1145 #endif |
| 1043 | 1146 |
| 1044 | 1147 |
| 1045 /* | 1148 /* |
| 1046 ** Declare that a function has been overloaded by a virtual table. | 1149 ** Declare that a function has been overloaded by a virtual table. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1057 int sqlite3_overload_function( | 1160 int sqlite3_overload_function( |
| 1058 sqlite3 *db, | 1161 sqlite3 *db, |
| 1059 const char *zName, | 1162 const char *zName, |
| 1060 int nArg | 1163 int nArg |
| 1061 ){ | 1164 ){ |
| 1062 int nName = sqlite3Strlen30(zName); | 1165 int nName = sqlite3Strlen30(zName); |
| 1063 int rc; | 1166 int rc; |
| 1064 sqlite3_mutex_enter(db->mutex); | 1167 sqlite3_mutex_enter(db->mutex); |
| 1065 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ | 1168 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ |
| 1066 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, | 1169 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
| 1067 0, sqlite3InvalidFunction, 0, 0); | 1170 0, sqlite3InvalidFunction, 0, 0, 0); |
| 1068 } | 1171 } |
| 1069 rc = sqlite3ApiExit(db, SQLITE_OK); | 1172 rc = sqlite3ApiExit(db, SQLITE_OK); |
| 1070 sqlite3_mutex_leave(db->mutex); | 1173 sqlite3_mutex_leave(db->mutex); |
| 1071 return rc; | 1174 return rc; |
| 1072 } | 1175 } |
| 1073 | 1176 |
| 1074 #ifndef SQLITE_OMIT_TRACE | 1177 #ifndef SQLITE_OMIT_TRACE |
| 1075 /* | 1178 /* |
| 1076 ** Register a trace function. The pArg from the previously registered trace | 1179 ** Register a trace function. The pArg from the previously registered trace |
| 1077 ** is returned. | 1180 ** is returned. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 ){ | 1264 ){ |
| 1162 void *pRet; | 1265 void *pRet; |
| 1163 sqlite3_mutex_enter(db->mutex); | 1266 sqlite3_mutex_enter(db->mutex); |
| 1164 pRet = db->pRollbackArg; | 1267 pRet = db->pRollbackArg; |
| 1165 db->xRollbackCallback = xCallback; | 1268 db->xRollbackCallback = xCallback; |
| 1166 db->pRollbackArg = pArg; | 1269 db->pRollbackArg = pArg; |
| 1167 sqlite3_mutex_leave(db->mutex); | 1270 sqlite3_mutex_leave(db->mutex); |
| 1168 return pRet; | 1271 return pRet; |
| 1169 } | 1272 } |
| 1170 | 1273 |
| 1274 #ifndef SQLITE_OMIT_WAL |
| 1275 /* |
| 1276 ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint(). |
| 1277 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file |
| 1278 ** is greater than sqlite3.pWalArg cast to an integer (the value configured by |
| 1279 ** wal_autocheckpoint()). |
| 1280 */ |
| 1281 int sqlite3WalDefaultHook( |
| 1282 void *pClientData, /* Argument */ |
| 1283 sqlite3 *db, /* Connection */ |
| 1284 const char *zDb, /* Database */ |
| 1285 int nFrame /* Size of WAL */ |
| 1286 ){ |
| 1287 if( nFrame>=SQLITE_PTR_TO_INT(pClientData) ){ |
| 1288 sqlite3BeginBenignMalloc(); |
| 1289 sqlite3_wal_checkpoint(db, zDb); |
| 1290 sqlite3EndBenignMalloc(); |
| 1291 } |
| 1292 return SQLITE_OK; |
| 1293 } |
| 1294 #endif /* SQLITE_OMIT_WAL */ |
| 1295 |
| 1296 /* |
| 1297 ** Configure an sqlite3_wal_hook() callback to automatically checkpoint |
| 1298 ** a database after committing a transaction if there are nFrame or |
| 1299 ** more frames in the log file. Passing zero or a negative value as the |
| 1300 ** nFrame parameter disables automatic checkpoints entirely. |
| 1301 ** |
| 1302 ** The callback registered by this function replaces any existing callback |
| 1303 ** registered using sqlite3_wal_hook(). Likewise, registering a callback |
| 1304 ** using sqlite3_wal_hook() disables the automatic checkpoint mechanism |
| 1305 ** configured by this function. |
| 1306 */ |
| 1307 int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ |
| 1308 #ifdef SQLITE_OMIT_WAL |
| 1309 UNUSED_PARAMETER(db); |
| 1310 UNUSED_PARAMETER(nFrame); |
| 1311 #else |
| 1312 if( nFrame>0 ){ |
| 1313 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame)); |
| 1314 }else{ |
| 1315 sqlite3_wal_hook(db, 0, 0); |
| 1316 } |
| 1317 #endif |
| 1318 return SQLITE_OK; |
| 1319 } |
| 1320 |
| 1321 /* |
| 1322 ** Register a callback to be invoked each time a transaction is written |
| 1323 ** into the write-ahead-log by this database connection. |
| 1324 */ |
| 1325 void *sqlite3_wal_hook( |
| 1326 sqlite3 *db, /* Attach the hook to this db handle */ |
| 1327 int(*xCallback)(void *, sqlite3*, const char*, int), |
| 1328 void *pArg /* First argument passed to xCallback() */ |
| 1329 ){ |
| 1330 #ifndef SQLITE_OMIT_WAL |
| 1331 void *pRet; |
| 1332 sqlite3_mutex_enter(db->mutex); |
| 1333 pRet = db->pWalArg; |
| 1334 db->xWalCallback = xCallback; |
| 1335 db->pWalArg = pArg; |
| 1336 sqlite3_mutex_leave(db->mutex); |
| 1337 return pRet; |
| 1338 #else |
| 1339 return 0; |
| 1340 #endif |
| 1341 } |
| 1342 |
| 1343 |
| 1344 /* |
| 1345 ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points |
| 1346 ** to contains a zero-length string, all attached databases are |
| 1347 ** checkpointed. |
| 1348 */ |
| 1349 int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ |
| 1350 #ifdef SQLITE_OMIT_WAL |
| 1351 return SQLITE_OK; |
| 1352 #else |
| 1353 int rc; /* Return code */ |
| 1354 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */ |
| 1355 |
| 1356 sqlite3_mutex_enter(db->mutex); |
| 1357 if( zDb && zDb[0] ){ |
| 1358 iDb = sqlite3FindDbName(db, zDb); |
| 1359 } |
| 1360 if( iDb<0 ){ |
| 1361 rc = SQLITE_ERROR; |
| 1362 sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb); |
| 1363 }else{ |
| 1364 rc = sqlite3Checkpoint(db, iDb); |
| 1365 sqlite3Error(db, rc, 0); |
| 1366 } |
| 1367 rc = sqlite3ApiExit(db, rc); |
| 1368 sqlite3_mutex_leave(db->mutex); |
| 1369 return rc; |
| 1370 #endif |
| 1371 } |
| 1372 |
| 1373 #ifndef SQLITE_OMIT_WAL |
| 1374 /* |
| 1375 ** Run a checkpoint on database iDb. This is a no-op if database iDb is |
| 1376 ** not currently open in WAL mode. |
| 1377 ** |
| 1378 ** If a transaction is open on the database being checkpointed, this |
| 1379 ** function returns SQLITE_LOCKED and a checkpoint is not attempted. If |
| 1380 ** an error occurs while running the checkpoint, an SQLite error code is |
| 1381 ** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK. |
| 1382 ** |
| 1383 ** The mutex on database handle db should be held by the caller. The mutex |
| 1384 ** associated with the specific b-tree being checkpointed is taken by |
| 1385 ** this function while the checkpoint is running. |
| 1386 ** |
| 1387 ** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are |
| 1388 ** checkpointed. If an error is encountered it is returned immediately - |
| 1389 ** no attempt is made to checkpoint any remaining databases. |
| 1390 */ |
| 1391 int sqlite3Checkpoint(sqlite3 *db, int iDb){ |
| 1392 int rc = SQLITE_OK; /* Return code */ |
| 1393 int i; /* Used to iterate through attached dbs */ |
| 1394 |
| 1395 assert( sqlite3_mutex_held(db->mutex) ); |
| 1396 |
| 1397 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){ |
| 1398 if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){ |
| 1399 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt); |
| 1400 } |
| 1401 } |
| 1402 |
| 1403 return rc; |
| 1404 } |
| 1405 #endif /* SQLITE_OMIT_WAL */ |
| 1406 |
| 1171 /* | 1407 /* |
| 1172 ** This function returns true if main-memory should be used instead of | 1408 ** This function returns true if main-memory should be used instead of |
| 1173 ** a temporary file for transient pager files and statement journals. | 1409 ** a temporary file for transient pager files and statement journals. |
| 1174 ** The value returned depends on the value of db->temp_store (runtime | 1410 ** The value returned depends on the value of db->temp_store (runtime |
| 1175 ** parameter) and the compile time value of SQLITE_TEMP_STORE. The | 1411 ** parameter) and the compile time value of SQLITE_TEMP_STORE. The |
| 1176 ** following table describes the relationship between these two values | 1412 ** following table describes the relationship between these two values |
| 1177 ** and this functions return value. | 1413 ** and this functions return value. |
| 1178 ** | 1414 ** |
| 1179 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database | 1415 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database |
| 1180 ** ----------------- -------------- ------------------------------ | 1416 ** ----------------- -------------- ------------------------------ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1196 #endif | 1432 #endif |
| 1197 #if SQLITE_TEMP_STORE==3 | 1433 #if SQLITE_TEMP_STORE==3 |
| 1198 return 1; | 1434 return 1; |
| 1199 #endif | 1435 #endif |
| 1200 #if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3 | 1436 #if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3 |
| 1201 return 0; | 1437 return 0; |
| 1202 #endif | 1438 #endif |
| 1203 } | 1439 } |
| 1204 | 1440 |
| 1205 /* | 1441 /* |
| 1206 ** This routine is called to create a connection to a database BTree | |
| 1207 ** driver. If zFilename is the name of a file, then that file is | |
| 1208 ** opened and used. If zFilename is the magic name ":memory:" then | |
| 1209 ** the database is stored in memory (and is thus forgotten as soon as | |
| 1210 ** the connection is closed.) If zFilename is NULL then the database | |
| 1211 ** is a "virtual" database for transient use only and is deleted as | |
| 1212 ** soon as the connection is closed. | |
| 1213 ** | |
| 1214 ** A virtual database can be either a disk file (that is automatically | |
| 1215 ** deleted when the file is closed) or it an be held entirely in memory. | |
| 1216 ** The sqlite3TempInMemory() function is used to determine which. | |
| 1217 */ | |
| 1218 int sqlite3BtreeFactory( | |
| 1219 const sqlite3 *db, /* Main database when opening aux otherwise 0 */ | |
| 1220 const char *zFilename, /* Name of the file containing the BTree database */ | |
| 1221 int omitJournal, /* if TRUE then do not journal this file */ | |
| 1222 int nCache, /* How many pages in the page cache */ | |
| 1223 int vfsFlags, /* Flags passed through to vfsOpen */ | |
| 1224 Btree **ppBtree /* Pointer to new Btree object written here */ | |
| 1225 ){ | |
| 1226 int btFlags = 0; | |
| 1227 int rc; | |
| 1228 | |
| 1229 assert( sqlite3_mutex_held(db->mutex) ); | |
| 1230 assert( ppBtree != 0); | |
| 1231 if( omitJournal ){ | |
| 1232 btFlags |= BTREE_OMIT_JOURNAL; | |
| 1233 } | |
| 1234 if( db->flags & SQLITE_NoReadlock ){ | |
| 1235 btFlags |= BTREE_NO_READLOCK; | |
| 1236 } | |
| 1237 #ifndef SQLITE_OMIT_MEMORYDB | |
| 1238 if( zFilename==0 && sqlite3TempInMemory(db) ){ | |
| 1239 zFilename = ":memory:"; | |
| 1240 } | |
| 1241 #endif | |
| 1242 | |
| 1243 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (zFilename==0 || *zFilename==0) ){ | |
| 1244 vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB; | |
| 1245 } | |
| 1246 rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btFlags, vfsFlags); | |
| 1247 | |
| 1248 /* If the B-Tree was successfully opened, set the pager-cache size to the | |
| 1249 ** default value. Except, if the call to BtreeOpen() returned a handle | |
| 1250 ** open on an existing shared pager-cache, do not change the pager-cache | |
| 1251 ** size. | |
| 1252 */ | |
| 1253 if( rc==SQLITE_OK && 0==sqlite3BtreeSchema(*ppBtree, 0, 0) ){ | |
| 1254 sqlite3BtreeSetCacheSize(*ppBtree, nCache); | |
| 1255 } | |
| 1256 return rc; | |
| 1257 } | |
| 1258 | |
| 1259 /* | |
| 1260 ** Return UTF-8 encoded English language explanation of the most recent | 1442 ** Return UTF-8 encoded English language explanation of the most recent |
| 1261 ** error. | 1443 ** error. |
| 1262 */ | 1444 */ |
| 1263 const char *sqlite3_errmsg(sqlite3 *db){ | 1445 const char *sqlite3_errmsg(sqlite3 *db){ |
| 1264 const char *z; | 1446 const char *z; |
| 1265 if( !db ){ | 1447 if( !db ){ |
| 1266 return sqlite3ErrStr(SQLITE_NOMEM); | 1448 return sqlite3ErrStr(SQLITE_NOMEM); |
| 1267 } | 1449 } |
| 1268 if( !sqlite3SafetyCheckSickOrOk(db) ){ | 1450 if( !sqlite3SafetyCheckSickOrOk(db) ){ |
| 1269 return sqlite3ErrStr(SQLITE_MISUSE); | 1451 return sqlite3ErrStr(SQLITE_MISUSE_BKPT); |
| 1270 } | 1452 } |
| 1271 sqlite3_mutex_enter(db->mutex); | 1453 sqlite3_mutex_enter(db->mutex); |
| 1272 if( db->mallocFailed ){ | 1454 if( db->mallocFailed ){ |
| 1273 z = sqlite3ErrStr(SQLITE_NOMEM); | 1455 z = sqlite3ErrStr(SQLITE_NOMEM); |
| 1274 }else{ | 1456 }else{ |
| 1275 z = (char*)sqlite3_value_text(db->pErr); | 1457 z = (char*)sqlite3_value_text(db->pErr); |
| 1276 assert( !db->mallocFailed ); | 1458 assert( !db->mallocFailed ); |
| 1277 if( z==0 ){ | 1459 if( z==0 ){ |
| 1278 z = sqlite3ErrStr(db->errCode); | 1460 z = sqlite3ErrStr(db->errCode); |
| 1279 } | 1461 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 return z; | 1510 return z; |
| 1329 } | 1511 } |
| 1330 #endif /* SQLITE_OMIT_UTF16 */ | 1512 #endif /* SQLITE_OMIT_UTF16 */ |
| 1331 | 1513 |
| 1332 /* | 1514 /* |
| 1333 ** Return the most recent error code generated by an SQLite routine. If NULL is | 1515 ** Return the most recent error code generated by an SQLite routine. If NULL is |
| 1334 ** passed to this function, we assume a malloc() failed during sqlite3_open(). | 1516 ** passed to this function, we assume a malloc() failed during sqlite3_open(). |
| 1335 */ | 1517 */ |
| 1336 int sqlite3_errcode(sqlite3 *db){ | 1518 int sqlite3_errcode(sqlite3 *db){ |
| 1337 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ | 1519 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ |
| 1338 return SQLITE_MISUSE; | 1520 return SQLITE_MISUSE_BKPT; |
| 1339 } | 1521 } |
| 1340 if( !db || db->mallocFailed ){ | 1522 if( !db || db->mallocFailed ){ |
| 1341 return SQLITE_NOMEM; | 1523 return SQLITE_NOMEM; |
| 1342 } | 1524 } |
| 1343 return db->errCode & db->errMask; | 1525 return db->errCode & db->errMask; |
| 1344 } | 1526 } |
| 1345 int sqlite3_extended_errcode(sqlite3 *db){ | 1527 int sqlite3_extended_errcode(sqlite3 *db){ |
| 1346 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ | 1528 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ |
| 1347 return SQLITE_MISUSE; | 1529 return SQLITE_MISUSE_BKPT; |
| 1348 } | 1530 } |
| 1349 if( !db || db->mallocFailed ){ | 1531 if( !db || db->mallocFailed ){ |
| 1350 return SQLITE_NOMEM; | 1532 return SQLITE_NOMEM; |
| 1351 } | 1533 } |
| 1352 return db->errCode; | 1534 return db->errCode; |
| 1353 } | 1535 } |
| 1354 | 1536 |
| 1355 /* | 1537 /* |
| 1356 ** Create a new collating function for database "db". The name is zName | 1538 ** Create a new collating function for database "db". The name is zName |
| 1357 ** and the encoding is enc. | 1539 ** and the encoding is enc. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1375 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the | 1557 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 1376 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. | 1558 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| 1377 */ | 1559 */ |
| 1378 enc2 = enc; | 1560 enc2 = enc; |
| 1379 testcase( enc2==SQLITE_UTF16 ); | 1561 testcase( enc2==SQLITE_UTF16 ); |
| 1380 testcase( enc2==SQLITE_UTF16_ALIGNED ); | 1562 testcase( enc2==SQLITE_UTF16_ALIGNED ); |
| 1381 if( enc2==SQLITE_UTF16 || enc2==SQLITE_UTF16_ALIGNED ){ | 1563 if( enc2==SQLITE_UTF16 || enc2==SQLITE_UTF16_ALIGNED ){ |
| 1382 enc2 = SQLITE_UTF16NATIVE; | 1564 enc2 = SQLITE_UTF16NATIVE; |
| 1383 } | 1565 } |
| 1384 if( enc2<SQLITE_UTF8 || enc2>SQLITE_UTF16BE ){ | 1566 if( enc2<SQLITE_UTF8 || enc2>SQLITE_UTF16BE ){ |
| 1385 return SQLITE_MISUSE; | 1567 return SQLITE_MISUSE_BKPT; |
| 1386 } | 1568 } |
| 1387 | 1569 |
| 1388 /* Check if this call is removing or replacing an existing collation | 1570 /* Check if this call is removing or replacing an existing collation |
| 1389 ** sequence. If so, and there are active VMs, return busy. If there | 1571 ** sequence. If so, and there are active VMs, return busy. If there |
| 1390 ** are no active VMs, invalidate any pre-compiled statements. | 1572 ** are no active VMs, invalidate any pre-compiled statements. |
| 1391 */ | 1573 */ |
| 1392 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0); | 1574 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0); |
| 1393 if( pColl && pColl->xCmp ){ | 1575 if( pColl && pColl->xCmp ){ |
| 1394 if( db->activeVdbeCnt ){ | 1576 if( db->activeVdbeCnt ){ |
| 1395 sqlite3Error(db, SQLITE_BUSY, | 1577 sqlite3Error(db, SQLITE_BUSY, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 #endif | 1653 #endif |
| 1472 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 | 1654 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 |
| 1473 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 | 1655 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 |
| 1474 #endif | 1656 #endif |
| 1475 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30 | 1657 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30 |
| 1476 # error SQLITE_MAX_ATTACHED must be between 0 and 30 | 1658 # error SQLITE_MAX_ATTACHED must be between 0 and 30 |
| 1477 #endif | 1659 #endif |
| 1478 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 | 1660 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 |
| 1479 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 | 1661 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 |
| 1480 #endif | 1662 #endif |
| 1481 #if SQLITE_MAX_VARIABLE_NUMBER<1 | |
| 1482 # error SQLITE_MAX_VARIABLE_NUMBER must be at least 1 | |
| 1483 #endif | |
| 1484 #if SQLITE_MAX_COLUMN>32767 | 1663 #if SQLITE_MAX_COLUMN>32767 |
| 1485 # error SQLITE_MAX_COLUMN must not exceed 32767 | 1664 # error SQLITE_MAX_COLUMN must not exceed 32767 |
| 1486 #endif | 1665 #endif |
| 1487 #if SQLITE_MAX_TRIGGER_DEPTH<1 | 1666 #if SQLITE_MAX_TRIGGER_DEPTH<1 |
| 1488 # error SQLITE_MAX_TRIGGER_DEPTH must be at least 1 | 1667 # error SQLITE_MAX_TRIGGER_DEPTH must be at least 1 |
| 1489 #endif | 1668 #endif |
| 1490 | 1669 |
| 1491 | 1670 |
| 1492 /* | 1671 /* |
| 1493 ** Change the value of a limit. Report the old value. | 1672 ** Change the value of a limit. Report the old value. |
| 1494 ** If an invalid limit index is supplied, report -1. | 1673 ** If an invalid limit index is supplied, report -1. |
| 1495 ** Make no changes but still report the old value if the | 1674 ** Make no changes but still report the old value if the |
| 1496 ** new limit is negative. | 1675 ** new limit is negative. |
| 1497 ** | 1676 ** |
| 1498 ** A new lower limit does not shrink existing constructs. | 1677 ** A new lower limit does not shrink existing constructs. |
| 1499 ** It merely prevents new constructs that exceed the limit | 1678 ** It merely prevents new constructs that exceed the limit |
| 1500 ** from forming. | 1679 ** from forming. |
| 1501 */ | 1680 */ |
| 1502 int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ | 1681 int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ |
| 1503 int oldLimit; | 1682 int oldLimit; |
| 1683 |
| 1684 |
| 1685 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME |
| 1686 ** there is a hard upper bound set at compile-time by a C preprocessor |
| 1687 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to |
| 1688 ** "_MAX_".) |
| 1689 */ |
| 1690 assert( aHardLimit[SQLITE_LIMIT_LENGTH]==SQLITE_MAX_LENGTH ); |
| 1691 assert( aHardLimit[SQLITE_LIMIT_SQL_LENGTH]==SQLITE_MAX_SQL_LENGTH ); |
| 1692 assert( aHardLimit[SQLITE_LIMIT_COLUMN]==SQLITE_MAX_COLUMN ); |
| 1693 assert( aHardLimit[SQLITE_LIMIT_EXPR_DEPTH]==SQLITE_MAX_EXPR_DEPTH ); |
| 1694 assert( aHardLimit[SQLITE_LIMIT_COMPOUND_SELECT]==SQLITE_MAX_COMPOUND_SELECT); |
| 1695 assert( aHardLimit[SQLITE_LIMIT_VDBE_OP]==SQLITE_MAX_VDBE_OP ); |
| 1696 assert( aHardLimit[SQLITE_LIMIT_FUNCTION_ARG]==SQLITE_MAX_FUNCTION_ARG ); |
| 1697 assert( aHardLimit[SQLITE_LIMIT_ATTACHED]==SQLITE_MAX_ATTACHED ); |
| 1698 assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]== |
| 1699 SQLITE_MAX_LIKE_PATTERN_LENGTH ); |
| 1700 assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER); |
| 1701 assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH ); |
| 1702 assert( SQLITE_LIMIT_TRIGGER_DEPTH==(SQLITE_N_LIMIT-1) ); |
| 1703 |
| 1704 |
| 1504 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){ | 1705 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){ |
| 1505 return -1; | 1706 return -1; |
| 1506 } | 1707 } |
| 1507 oldLimit = db->aLimit[limitId]; | 1708 oldLimit = db->aLimit[limitId]; |
| 1508 if( newLimit>=0 ){ | 1709 if( newLimit>=0 ){ /* IMP: R-52476-28732 */ |
| 1509 if( newLimit>aHardLimit[limitId] ){ | 1710 if( newLimit>aHardLimit[limitId] ){ |
| 1510 newLimit = aHardLimit[limitId]; | 1711 newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */ |
| 1511 } | 1712 } |
| 1512 db->aLimit[limitId] = newLimit; | 1713 db->aLimit[limitId] = newLimit; |
| 1513 } | 1714 } |
| 1514 return oldLimit; | 1715 return oldLimit; /* IMP: R-53341-35419 */ |
| 1515 } | 1716 } |
| 1516 | 1717 |
| 1517 /* | 1718 /* |
| 1518 ** This routine does the work of opening a database on behalf of | 1719 ** This routine does the work of opening a database on behalf of |
| 1519 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" | 1720 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| 1520 ** is UTF-8 encoded. | 1721 ** is UTF-8 encoded. |
| 1521 */ | 1722 */ |
| 1522 static int openDatabase( | 1723 static int openDatabase( |
| 1523 const char *zFilename, /* Database filename UTF-8 encoded */ | 1724 const char *zFilename, /* Database filename UTF-8 encoded */ |
| 1524 sqlite3 **ppDb, /* OUT: Returned database handle */ | 1725 sqlite3 **ppDb, /* OUT: Returned database handle */ |
| 1525 unsigned flags, /* Operational flags */ | 1726 unsigned flags, /* Operational flags */ |
| 1526 const char *zVfs /* Name of the VFS to use */ | 1727 const char *zVfs /* Name of the VFS to use */ |
| 1527 ){ | 1728 ){ |
| 1528 sqlite3 *db; | 1729 sqlite3 *db; |
| 1529 int rc; | 1730 int rc; |
| 1530 int isThreadsafe; | 1731 int isThreadsafe; |
| 1531 | 1732 |
| 1532 *ppDb = 0; | 1733 *ppDb = 0; |
| 1533 #ifndef SQLITE_OMIT_AUTOINIT | 1734 #ifndef SQLITE_OMIT_AUTOINIT |
| 1534 rc = sqlite3_initialize(); | 1735 rc = sqlite3_initialize(); |
| 1535 if( rc ) return rc; | 1736 if( rc ) return rc; |
| 1536 #endif | 1737 #endif |
| 1537 | 1738 |
| 1739 /* Only allow sensible combinations of bits in the flags argument. |
| 1740 ** Throw an error if any non-sense combination is used. If we |
| 1741 ** do not block illegal combinations here, it could trigger |
| 1742 ** assert() statements in deeper layers. Sensible combinations |
| 1743 ** are: |
| 1744 ** |
| 1745 ** 1: SQLITE_OPEN_READONLY |
| 1746 ** 2: SQLITE_OPEN_READWRITE |
| 1747 ** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
| 1748 */ |
| 1749 assert( SQLITE_OPEN_READONLY == 0x01 ); |
| 1750 assert( SQLITE_OPEN_READWRITE == 0x02 ); |
| 1751 assert( SQLITE_OPEN_CREATE == 0x04 ); |
| 1752 testcase( (1<<(flags&7))==0x02 ); /* READONLY */ |
| 1753 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */ |
| 1754 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */ |
| 1755 if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE; |
| 1756 |
| 1538 if( sqlite3GlobalConfig.bCoreMutex==0 ){ | 1757 if( sqlite3GlobalConfig.bCoreMutex==0 ){ |
| 1539 isThreadsafe = 0; | 1758 isThreadsafe = 0; |
| 1540 }else if( flags & SQLITE_OPEN_NOMUTEX ){ | 1759 }else if( flags & SQLITE_OPEN_NOMUTEX ){ |
| 1541 isThreadsafe = 0; | 1760 isThreadsafe = 0; |
| 1542 }else if( flags & SQLITE_OPEN_FULLMUTEX ){ | 1761 }else if( flags & SQLITE_OPEN_FULLMUTEX ){ |
| 1543 isThreadsafe = 1; | 1762 isThreadsafe = 1; |
| 1544 }else{ | 1763 }else{ |
| 1545 isThreadsafe = sqlite3GlobalConfig.bFullMutex; | 1764 isThreadsafe = sqlite3GlobalConfig.bFullMutex; |
| 1546 } | 1765 } |
| 1547 if( flags & SQLITE_OPEN_PRIVATECACHE ){ | 1766 if( flags & SQLITE_OPEN_PRIVATECACHE ){ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1561 flags &= ~( SQLITE_OPEN_DELETEONCLOSE | | 1780 flags &= ~( SQLITE_OPEN_DELETEONCLOSE | |
| 1562 SQLITE_OPEN_EXCLUSIVE | | 1781 SQLITE_OPEN_EXCLUSIVE | |
| 1563 SQLITE_OPEN_MAIN_DB | | 1782 SQLITE_OPEN_MAIN_DB | |
| 1564 SQLITE_OPEN_TEMP_DB | | 1783 SQLITE_OPEN_TEMP_DB | |
| 1565 SQLITE_OPEN_TRANSIENT_DB | | 1784 SQLITE_OPEN_TRANSIENT_DB | |
| 1566 SQLITE_OPEN_MAIN_JOURNAL | | 1785 SQLITE_OPEN_MAIN_JOURNAL | |
| 1567 SQLITE_OPEN_TEMP_JOURNAL | | 1786 SQLITE_OPEN_TEMP_JOURNAL | |
| 1568 SQLITE_OPEN_SUBJOURNAL | | 1787 SQLITE_OPEN_SUBJOURNAL | |
| 1569 SQLITE_OPEN_MASTER_JOURNAL | | 1788 SQLITE_OPEN_MASTER_JOURNAL | |
| 1570 SQLITE_OPEN_NOMUTEX | | 1789 SQLITE_OPEN_NOMUTEX | |
| 1571 SQLITE_OPEN_FULLMUTEX | 1790 SQLITE_OPEN_FULLMUTEX | |
| 1791 SQLITE_OPEN_WAL |
| 1572 ); | 1792 ); |
| 1573 | 1793 |
| 1574 /* Allocate the sqlite data structure */ | 1794 /* Allocate the sqlite data structure */ |
| 1575 db = sqlite3MallocZero( sizeof(sqlite3) ); | 1795 db = sqlite3MallocZero( sizeof(sqlite3) ); |
| 1576 if( db==0 ) goto opendb_out; | 1796 if( db==0 ) goto opendb_out; |
| 1577 if( isThreadsafe ){ | 1797 if( isThreadsafe ){ |
| 1578 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); | 1798 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); |
| 1579 if( db->mutex==0 ){ | 1799 if( db->mutex==0 ){ |
| 1580 sqlite3_free(db); | 1800 sqlite3_free(db); |
| 1581 db = 0; | 1801 db = 0; |
| 1582 goto opendb_out; | 1802 goto opendb_out; |
| 1583 } | 1803 } |
| 1584 } | 1804 } |
| 1585 sqlite3_mutex_enter(db->mutex); | 1805 sqlite3_mutex_enter(db->mutex); |
| 1586 db->errMask = 0xff; | 1806 db->errMask = 0xff; |
| 1587 db->nDb = 2; | 1807 db->nDb = 2; |
| 1588 db->magic = SQLITE_MAGIC_BUSY; | 1808 db->magic = SQLITE_MAGIC_BUSY; |
| 1589 db->aDb = db->aDbStatic; | 1809 db->aDb = db->aDbStatic; |
| 1590 | 1810 |
| 1591 assert( sizeof(db->aLimit)==sizeof(aHardLimit) ); | 1811 assert( sizeof(db->aLimit)==sizeof(aHardLimit) ); |
| 1592 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit)); | 1812 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit)); |
| 1593 db->autoCommit = 1; | 1813 db->autoCommit = 1; |
| 1594 db->nextAutovac = -1; | 1814 db->nextAutovac = -1; |
| 1595 db->nextPagesize = 0; | 1815 db->nextPagesize = 0; |
| 1596 db->flags |= SQLITE_ShortColNames | 1816 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex |
| 1597 #if SQLITE_DEFAULT_FILE_FORMAT<4 | 1817 #if SQLITE_DEFAULT_FILE_FORMAT<4 |
| 1598 | SQLITE_LegacyFileFmt | 1818 | SQLITE_LegacyFileFmt |
| 1599 #endif | 1819 #endif |
| 1600 #ifdef SQLITE_ENABLE_LOAD_EXTENSION | 1820 #ifdef SQLITE_ENABLE_LOAD_EXTENSION |
| 1601 | SQLITE_LoadExtension | 1821 | SQLITE_LoadExtension |
| 1602 #endif | 1822 #endif |
| 1603 #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS | 1823 #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS |
| 1604 | SQLITE_RecTriggers | 1824 | SQLITE_RecTriggers |
| 1605 #endif | 1825 #endif |
| 1606 ; | 1826 ; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1633 } | 1853 } |
| 1634 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0); | 1854 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0); |
| 1635 assert( db->pDfltColl!=0 ); | 1855 assert( db->pDfltColl!=0 ); |
| 1636 | 1856 |
| 1637 /* Also add a UTF-8 case-insensitive collation sequence. */ | 1857 /* Also add a UTF-8 case-insensitive collation sequence. */ |
| 1638 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0, | 1858 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0, |
| 1639 nocaseCollatingFunc, 0); | 1859 nocaseCollatingFunc, 0); |
| 1640 | 1860 |
| 1641 /* Open the backend database driver */ | 1861 /* Open the backend database driver */ |
| 1642 db->openFlags = flags; | 1862 db->openFlags = flags; |
| 1643 rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE, | 1863 rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0, |
| 1644 flags | SQLITE_OPEN_MAIN_DB, | 1864 flags | SQLITE_OPEN_MAIN_DB); |
| 1645 &db->aDb[0].pBt); | |
| 1646 if( rc!=SQLITE_OK ){ | 1865 if( rc!=SQLITE_OK ){ |
| 1647 if( rc==SQLITE_IOERR_NOMEM ){ | 1866 if( rc==SQLITE_IOERR_NOMEM ){ |
| 1648 rc = SQLITE_NOMEM; | 1867 rc = SQLITE_NOMEM; |
| 1649 } | 1868 } |
| 1650 sqlite3Error(db, rc, 0); | 1869 sqlite3Error(db, rc, 0); |
| 1651 goto opendb_out; | 1870 goto opendb_out; |
| 1652 } | 1871 } |
| 1653 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); | 1872 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); |
| 1654 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); | 1873 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); |
| 1655 | 1874 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 #ifdef SQLITE_DEFAULT_LOCKING_MODE | 1943 #ifdef SQLITE_DEFAULT_LOCKING_MODE |
| 1725 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE; | 1944 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE; |
| 1726 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt), | 1945 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt), |
| 1727 SQLITE_DEFAULT_LOCKING_MODE); | 1946 SQLITE_DEFAULT_LOCKING_MODE); |
| 1728 #endif | 1947 #endif |
| 1729 | 1948 |
| 1730 /* Enable the lookaside-malloc subsystem */ | 1949 /* Enable the lookaside-malloc subsystem */ |
| 1731 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, | 1950 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, |
| 1732 sqlite3GlobalConfig.nLookaside); | 1951 sqlite3GlobalConfig.nLookaside); |
| 1733 | 1952 |
| 1953 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| 1954 |
| 1734 opendb_out: | 1955 opendb_out: |
| 1735 if( db ){ | 1956 if( db ){ |
| 1736 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0
); | 1957 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0
); |
| 1737 sqlite3_mutex_leave(db->mutex); | 1958 sqlite3_mutex_leave(db->mutex); |
| 1738 } | 1959 } |
| 1739 rc = sqlite3_errcode(db); | 1960 rc = sqlite3_errcode(db); |
| 1740 if( rc==SQLITE_NOMEM ){ | 1961 if( rc==SQLITE_NOMEM ){ |
| 1741 sqlite3_close(db); | 1962 sqlite3_close(db); |
| 1742 db = 0; | 1963 db = 0; |
| 1743 }else if( rc!=SQLITE_OK ){ | 1964 }else if( rc!=SQLITE_OK ){ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 sqlite3* db, | 2072 sqlite3* db, |
| 1852 const void *zName, | 2073 const void *zName, |
| 1853 int enc, | 2074 int enc, |
| 1854 void* pCtx, | 2075 void* pCtx, |
| 1855 int(*xCompare)(void*,int,const void*,int,const void*) | 2076 int(*xCompare)(void*,int,const void*,int,const void*) |
| 1856 ){ | 2077 ){ |
| 1857 int rc = SQLITE_OK; | 2078 int rc = SQLITE_OK; |
| 1858 char *zName8; | 2079 char *zName8; |
| 1859 sqlite3_mutex_enter(db->mutex); | 2080 sqlite3_mutex_enter(db->mutex); |
| 1860 assert( !db->mallocFailed ); | 2081 assert( !db->mallocFailed ); |
| 1861 zName8 = sqlite3Utf16to8(db, zName, -1); | 2082 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE); |
| 1862 if( zName8 ){ | 2083 if( zName8 ){ |
| 1863 rc = createCollation(db, zName8, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare,
0); | 2084 rc = createCollation(db, zName8, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare,
0); |
| 1864 sqlite3DbFree(db, zName8); | 2085 sqlite3DbFree(db, zName8); |
| 1865 } | 2086 } |
| 1866 rc = sqlite3ApiExit(db, rc); | 2087 rc = sqlite3ApiExit(db, rc); |
| 1867 sqlite3_mutex_leave(db->mutex); | 2088 sqlite3_mutex_leave(db->mutex); |
| 1868 return rc; | 2089 return rc; |
| 1869 } | 2090 } |
| 1870 #endif /* SQLITE_OMIT_UTF16 */ | 2091 #endif /* SQLITE_OMIT_UTF16 */ |
| 1871 | 2092 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1898 ){ | 2119 ){ |
| 1899 sqlite3_mutex_enter(db->mutex); | 2120 sqlite3_mutex_enter(db->mutex); |
| 1900 db->xCollNeeded = 0; | 2121 db->xCollNeeded = 0; |
| 1901 db->xCollNeeded16 = xCollNeeded16; | 2122 db->xCollNeeded16 = xCollNeeded16; |
| 1902 db->pCollNeededArg = pCollNeededArg; | 2123 db->pCollNeededArg = pCollNeededArg; |
| 1903 sqlite3_mutex_leave(db->mutex); | 2124 sqlite3_mutex_leave(db->mutex); |
| 1904 return SQLITE_OK; | 2125 return SQLITE_OK; |
| 1905 } | 2126 } |
| 1906 #endif /* SQLITE_OMIT_UTF16 */ | 2127 #endif /* SQLITE_OMIT_UTF16 */ |
| 1907 | 2128 |
| 1908 #ifndef SQLITE_OMIT_GLOBALRECOVER | |
| 1909 #ifndef SQLITE_OMIT_DEPRECATED | 2129 #ifndef SQLITE_OMIT_DEPRECATED |
| 1910 /* | 2130 /* |
| 1911 ** This function is now an anachronism. It used to be used to recover from a | 2131 ** This function is now an anachronism. It used to be used to recover from a |
| 1912 ** malloc() failure, but SQLite now does this automatically. | 2132 ** malloc() failure, but SQLite now does this automatically. |
| 1913 */ | 2133 */ |
| 1914 int sqlite3_global_recover(void){ | 2134 int sqlite3_global_recover(void){ |
| 1915 return SQLITE_OK; | 2135 return SQLITE_OK; |
| 1916 } | 2136 } |
| 1917 #endif | 2137 #endif |
| 1918 #endif | |
| 1919 | 2138 |
| 1920 /* | 2139 /* |
| 1921 ** Test to see whether or not the database connection is in autocommit | 2140 ** Test to see whether or not the database connection is in autocommit |
| 1922 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on | 2141 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on |
| 1923 ** by default. Autocommit is disabled by a BEGIN statement and reenabled | 2142 ** by default. Autocommit is disabled by a BEGIN statement and reenabled |
| 1924 ** by the next COMMIT or ROLLBACK. | 2143 ** by the next COMMIT or ROLLBACK. |
| 1925 ** | 2144 ** |
| 1926 ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** | 2145 ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** |
| 1927 */ | 2146 */ |
| 1928 int sqlite3_get_autocommit(sqlite3 *db){ | 2147 int sqlite3_get_autocommit(sqlite3 *db){ |
| 1929 return db->autoCommit; | 2148 return db->autoCommit; |
| 1930 } | 2149 } |
| 1931 | 2150 |
| 1932 #ifdef SQLITE_DEBUG | |
| 1933 /* | 2151 /* |
| 1934 ** The following routine is subtituted for constant SQLITE_CORRUPT in | 2152 ** The following routines are subtitutes for constants SQLITE_CORRUPT, |
| 1935 ** debugging builds. This provides a way to set a breakpoint for when | 2153 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error |
| 1936 ** corruption is first detected. | 2154 ** constants. They server two purposes: |
| 2155 ** |
| 2156 ** 1. Serve as a convenient place to set a breakpoint in a debugger |
| 2157 ** to detect when version error conditions occurs. |
| 2158 ** |
| 2159 ** 2. Invoke sqlite3_log() to provide the source code location where |
| 2160 ** a low-level error is first detected. |
| 1937 */ | 2161 */ |
| 1938 int sqlite3Corrupt(void){ | 2162 int sqlite3CorruptError(int lineno){ |
| 2163 testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 2164 sqlite3_log(SQLITE_CORRUPT, |
| 2165 "database corruption at line %d of [%.10s]", |
| 2166 lineno, 20+sqlite3_sourceid()); |
| 1939 return SQLITE_CORRUPT; | 2167 return SQLITE_CORRUPT; |
| 1940 } | 2168 } |
| 1941 #endif | 2169 int sqlite3MisuseError(int lineno){ |
| 2170 testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 2171 sqlite3_log(SQLITE_MISUSE, |
| 2172 "misuse at line %d of [%.10s]", |
| 2173 lineno, 20+sqlite3_sourceid()); |
| 2174 return SQLITE_MISUSE; |
| 2175 } |
| 2176 int sqlite3CantopenError(int lineno){ |
| 2177 testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 2178 sqlite3_log(SQLITE_CANTOPEN, |
| 2179 "cannot open file at line %d of [%.10s]", |
| 2180 lineno, 20+sqlite3_sourceid()); |
| 2181 return SQLITE_CANTOPEN; |
| 2182 } |
| 2183 |
| 1942 | 2184 |
| 1943 #ifndef SQLITE_OMIT_DEPRECATED | 2185 #ifndef SQLITE_OMIT_DEPRECATED |
| 1944 /* | 2186 /* |
| 1945 ** This is a convenience routine that makes sure that all thread-specific | 2187 ** This is a convenience routine that makes sure that all thread-specific |
| 1946 ** data for this thread has been deallocated. | 2188 ** data for this thread has been deallocated. |
| 1947 ** | 2189 ** |
| 1948 ** SQLite no longer uses thread-specific data so this routine is now a | 2190 ** SQLite no longer uses thread-specific data so this routine is now a |
| 1949 ** no-op. It is retained for historical compatibility. | 2191 ** no-op. It is retained for historical compatibility. |
| 1950 */ | 2192 */ |
| 1951 void sqlite3_thread_cleanup(void){ | 2193 void sqlite3_thread_cleanup(void){ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1975 int iCol; | 2217 int iCol; |
| 1976 | 2218 |
| 1977 char const *zDataType = 0; | 2219 char const *zDataType = 0; |
| 1978 char const *zCollSeq = 0; | 2220 char const *zCollSeq = 0; |
| 1979 int notnull = 0; | 2221 int notnull = 0; |
| 1980 int primarykey = 0; | 2222 int primarykey = 0; |
| 1981 int autoinc = 0; | 2223 int autoinc = 0; |
| 1982 | 2224 |
| 1983 /* Ensure the database schema has been loaded */ | 2225 /* Ensure the database schema has been loaded */ |
| 1984 sqlite3_mutex_enter(db->mutex); | 2226 sqlite3_mutex_enter(db->mutex); |
| 1985 (void)sqlite3SafetyOn(db); | |
| 1986 sqlite3BtreeEnterAll(db); | 2227 sqlite3BtreeEnterAll(db); |
| 1987 rc = sqlite3Init(db, &zErrMsg); | 2228 rc = sqlite3Init(db, &zErrMsg); |
| 1988 if( SQLITE_OK!=rc ){ | 2229 if( SQLITE_OK!=rc ){ |
| 1989 goto error_out; | 2230 goto error_out; |
| 1990 } | 2231 } |
| 1991 | 2232 |
| 1992 /* Locate the table in question */ | 2233 /* Locate the table in question */ |
| 1993 pTab = sqlite3FindTable(db, zTableName, zDbName); | 2234 pTab = sqlite3FindTable(db, zTableName, zDbName); |
| 1994 if( !pTab || pTab->pSelect ){ | 2235 if( !pTab || pTab->pSelect ){ |
| 1995 pTab = 0; | 2236 pTab = 0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 }else{ | 2275 }else{ |
| 2035 zDataType = "INTEGER"; | 2276 zDataType = "INTEGER"; |
| 2036 primarykey = 1; | 2277 primarykey = 1; |
| 2037 } | 2278 } |
| 2038 if( !zCollSeq ){ | 2279 if( !zCollSeq ){ |
| 2039 zCollSeq = "BINARY"; | 2280 zCollSeq = "BINARY"; |
| 2040 } | 2281 } |
| 2041 | 2282 |
| 2042 error_out: | 2283 error_out: |
| 2043 sqlite3BtreeLeaveAll(db); | 2284 sqlite3BtreeLeaveAll(db); |
| 2044 (void)sqlite3SafetyOff(db); | |
| 2045 | 2285 |
| 2046 /* Whether the function call succeeded or failed, set the output parameters | 2286 /* Whether the function call succeeded or failed, set the output parameters |
| 2047 ** to whatever their local counterparts contain. If an error did occur, | 2287 ** to whatever their local counterparts contain. If an error did occur, |
| 2048 ** this has the effect of zeroing all output parameters. | 2288 ** this has the effect of zeroing all output parameters. |
| 2049 */ | 2289 */ |
| 2050 if( pzDataType ) *pzDataType = zDataType; | 2290 if( pzDataType ) *pzDataType = zDataType; |
| 2051 if( pzCollSeq ) *pzCollSeq = zCollSeq; | 2291 if( pzCollSeq ) *pzCollSeq = zCollSeq; |
| 2052 if( pNotNull ) *pNotNull = notnull; | 2292 if( pNotNull ) *pNotNull = notnull; |
| 2053 if( pPrimaryKey ) *pPrimaryKey = primarykey; | 2293 if( pPrimaryKey ) *pPrimaryKey = primarykey; |
| 2054 if( pAutoinc ) *pAutoinc = autoinc; | 2294 if( pAutoinc ) *pAutoinc = autoinc; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2202 ** Set the PENDING byte to the value in the argument, if X>0. | 2442 ** Set the PENDING byte to the value in the argument, if X>0. |
| 2203 ** Make no changes if X==0. Return the value of the pending byte | 2443 ** Make no changes if X==0. Return the value of the pending byte |
| 2204 ** as it existing before this routine was called. | 2444 ** as it existing before this routine was called. |
| 2205 ** | 2445 ** |
| 2206 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in | 2446 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in |
| 2207 ** an incompatible database file format. Changing the PENDING byte | 2447 ** an incompatible database file format. Changing the PENDING byte |
| 2208 ** while any database connection is open results in undefined and | 2448 ** while any database connection is open results in undefined and |
| 2209 ** dileterious behavior. | 2449 ** dileterious behavior. |
| 2210 */ | 2450 */ |
| 2211 case SQLITE_TESTCTRL_PENDING_BYTE: { | 2451 case SQLITE_TESTCTRL_PENDING_BYTE: { |
| 2212 unsigned int newVal = va_arg(ap, unsigned int); | 2452 rc = PENDING_BYTE; |
| 2213 rc = sqlite3PendingByte; | 2453 #ifndef SQLITE_OMIT_WSD |
| 2214 if( newVal ) sqlite3PendingByte = newVal; | 2454 { |
| 2455 unsigned int newVal = va_arg(ap, unsigned int); |
| 2456 if( newVal ) sqlite3PendingByte = newVal; |
| 2457 } |
| 2458 #endif |
| 2215 break; | 2459 break; |
| 2216 } | 2460 } |
| 2217 | 2461 |
| 2218 /* | 2462 /* |
| 2219 ** sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X) | 2463 ** sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X) |
| 2220 ** | 2464 ** |
| 2221 ** This action provides a run-time test to see whether or not | 2465 ** This action provides a run-time test to see whether or not |
| 2222 ** assert() was enabled at compile-time. If X is true and assert() | 2466 ** assert() was enabled at compile-time. If X is true and assert() |
| 2223 ** is enabled, then the return value is true. If X is true and | 2467 ** is enabled, then the return value is true. If X is true and |
| 2224 ** assert() is disabled, then the return value is zero. If X is | 2468 ** assert() is disabled, then the return value is zero. If X is |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2274 */ | 2518 */ |
| 2275 case SQLITE_TESTCTRL_RESERVE: { | 2519 case SQLITE_TESTCTRL_RESERVE: { |
| 2276 sqlite3 *db = va_arg(ap, sqlite3*); | 2520 sqlite3 *db = va_arg(ap, sqlite3*); |
| 2277 int x = va_arg(ap,int); | 2521 int x = va_arg(ap,int); |
| 2278 sqlite3_mutex_enter(db->mutex); | 2522 sqlite3_mutex_enter(db->mutex); |
| 2279 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0); | 2523 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0); |
| 2280 sqlite3_mutex_leave(db->mutex); | 2524 sqlite3_mutex_leave(db->mutex); |
| 2281 break; | 2525 break; |
| 2282 } | 2526 } |
| 2283 | 2527 |
| 2528 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N) |
| 2529 ** |
| 2530 ** Enable or disable various optimizations for testing purposes. The |
| 2531 ** argument N is a bitmask of optimizations to be disabled. For normal |
| 2532 ** operation N should be 0. The idea is that a test program (like the |
| 2533 ** SQL Logic Test or SLT test module) can run the same SQL multiple times |
| 2534 ** with various optimizations disabled to verify that the same answer |
| 2535 ** is obtained in every case. |
| 2536 */ |
| 2537 case SQLITE_TESTCTRL_OPTIMIZATIONS: { |
| 2538 sqlite3 *db = va_arg(ap, sqlite3*); |
| 2539 int x = va_arg(ap,int); |
| 2540 db->flags = (x & SQLITE_OptMask) | (db->flags & ~SQLITE_OptMask); |
| 2541 break; |
| 2542 } |
| 2543 |
| 2544 #ifdef SQLITE_N_KEYWORD |
| 2545 /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord) |
| 2546 ** |
| 2547 ** If zWord is a keyword recognized by the parser, then return the |
| 2548 ** number of keywords. Or if zWord is not a keyword, return 0. |
| 2549 ** |
| 2550 ** This test feature is only available in the amalgamation since |
| 2551 ** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite |
| 2552 ** is built using separate source files. |
| 2553 */ |
| 2554 case SQLITE_TESTCTRL_ISKEYWORD: { |
| 2555 const char *zWord = va_arg(ap, const char*); |
| 2556 int n = sqlite3Strlen30(zWord); |
| 2557 rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0; |
| 2558 break; |
| 2559 } |
| 2560 #endif |
| 2561 |
| 2562 /* sqlite3_test_control(SQLITE_TESTCTRL_PGHDRSZ) |
| 2563 ** |
| 2564 ** Return the size of a pcache header in bytes. |
| 2565 */ |
| 2566 case SQLITE_TESTCTRL_PGHDRSZ: { |
| 2567 rc = sizeof(PgHdr); |
| 2568 break; |
| 2569 } |
| 2570 |
| 2571 /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree); |
| 2572 ** |
| 2573 ** Pass pFree into sqlite3ScratchFree(). |
| 2574 ** If sz>0 then allocate a scratch buffer into pNew. |
| 2575 */ |
| 2576 case SQLITE_TESTCTRL_SCRATCHMALLOC: { |
| 2577 void *pFree, **ppNew; |
| 2578 int sz; |
| 2579 sz = va_arg(ap, int); |
| 2580 ppNew = va_arg(ap, void**); |
| 2581 pFree = va_arg(ap, void*); |
| 2582 if( sz ) *ppNew = sqlite3ScratchMalloc(sz); |
| 2583 sqlite3ScratchFree(pFree); |
| 2584 break; |
| 2585 } |
| 2586 |
| 2284 } | 2587 } |
| 2285 va_end(ap); | 2588 va_end(ap); |
| 2286 #endif /* SQLITE_OMIT_BUILTIN_TEST */ | 2589 #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 2287 return rc; | 2590 return rc; |
| 2288 } | 2591 } |
| OLD | NEW |