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 ** |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 sqlite3GlobalConfig.isMutexInit = 1; | 180 sqlite3GlobalConfig.isMutexInit = 1; |
181 if( !sqlite3GlobalConfig.isMallocInit ){ | 181 if( !sqlite3GlobalConfig.isMallocInit ){ |
182 rc = sqlite3MallocInit(); | 182 rc = sqlite3MallocInit(); |
183 } | 183 } |
184 if( rc==SQLITE_OK ){ | 184 if( rc==SQLITE_OK ){ |
185 sqlite3GlobalConfig.isMallocInit = 1; | 185 sqlite3GlobalConfig.isMallocInit = 1; |
186 if( !sqlite3GlobalConfig.pInitMutex ){ | 186 if( !sqlite3GlobalConfig.pInitMutex ){ |
187 sqlite3GlobalConfig.pInitMutex = | 187 sqlite3GlobalConfig.pInitMutex = |
188 sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); | 188 sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); |
189 if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){ | 189 if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){ |
190 rc = SQLITE_NOMEM; | 190 rc = SQLITE_NOMEM_BKPT; |
191 } | 191 } |
192 } | 192 } |
193 } | 193 } |
194 if( rc==SQLITE_OK ){ | 194 if( rc==SQLITE_OK ){ |
195 sqlite3GlobalConfig.nRefInitMutex++; | 195 sqlite3GlobalConfig.nRefInitMutex++; |
196 } | 196 } |
197 sqlite3_mutex_leave(pMaster); | 197 sqlite3_mutex_leave(pMaster); |
198 | 198 |
199 /* If rc is not SQLITE_OK at this point, then either the malloc | 199 /* If rc is not SQLITE_OK at this point, then either the malloc |
200 ** subsystem could not be initialized or the system failed to allocate | 200 ** subsystem could not be initialized or the system failed to allocate |
(...skipping 10 matching lines...) Expand all Loading... |
211 ** | 211 ** |
212 ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls | 212 ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls |
213 ** to the xInit method, so the xInit method need not be threadsafe. | 213 ** to the xInit method, so the xInit method need not be threadsafe. |
214 ** | 214 ** |
215 ** The following mutex is what serializes access to the appdef pcache xInit | 215 ** The following mutex is what serializes access to the appdef pcache xInit |
216 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the | 216 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the |
217 ** call to sqlite3PcacheInitialize(). | 217 ** call to sqlite3PcacheInitialize(). |
218 */ | 218 */ |
219 sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex); | 219 sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex); |
220 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ | 220 if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){ |
221 FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); | |
222 sqlite3GlobalConfig.inProgress = 1; | 221 sqlite3GlobalConfig.inProgress = 1; |
223 #ifdef SQLITE_ENABLE_SQLLOG | 222 #ifdef SQLITE_ENABLE_SQLLOG |
224 { | 223 { |
225 extern void sqlite3_init_sqllog(void); | 224 extern void sqlite3_init_sqllog(void); |
226 sqlite3_init_sqllog(); | 225 sqlite3_init_sqllog(); |
227 } | 226 } |
228 #endif | 227 #endif |
229 memset(pHash, 0, sizeof(sqlite3GlobalFunctions)); | 228 memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions)); |
230 sqlite3RegisterGlobalFunctions(); | 229 sqlite3RegisterBuiltinFunctions(); |
231 if( sqlite3GlobalConfig.isPCacheInit==0 ){ | 230 if( sqlite3GlobalConfig.isPCacheInit==0 ){ |
232 rc = sqlite3PcacheInitialize(); | 231 rc = sqlite3PcacheInitialize(); |
233 } | 232 } |
234 if( rc==SQLITE_OK ){ | 233 if( rc==SQLITE_OK ){ |
235 sqlite3GlobalConfig.isPCacheInit = 1; | 234 sqlite3GlobalConfig.isPCacheInit = 1; |
236 rc = sqlite3OsInit(); | 235 rc = sqlite3OsInit(); |
237 } | 236 } |
238 if( rc==SQLITE_OK ){ | 237 if( rc==SQLITE_OK ){ |
239 sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, | 238 sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, |
240 sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); | 239 sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 sqlite3GlobalConfig.nHeap = va_arg(ap, int); | 626 sqlite3GlobalConfig.nHeap = va_arg(ap, int); |
628 break; | 627 break; |
629 } | 628 } |
630 #endif | 629 #endif |
631 | 630 |
632 case SQLITE_CONFIG_PMASZ: { | 631 case SQLITE_CONFIG_PMASZ: { |
633 sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int); | 632 sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int); |
634 break; | 633 break; |
635 } | 634 } |
636 | 635 |
| 636 case SQLITE_CONFIG_STMTJRNL_SPILL: { |
| 637 sqlite3GlobalConfig.nStmtSpill = va_arg(ap, int); |
| 638 break; |
| 639 } |
| 640 |
637 default: { | 641 default: { |
638 rc = SQLITE_ERROR; | 642 rc = SQLITE_ERROR; |
639 break; | 643 break; |
640 } | 644 } |
641 } | 645 } |
642 va_end(ap); | 646 va_end(ap); |
643 return rc; | 647 return rc; |
644 } | 648 } |
645 | 649 |
646 /* | 650 /* |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 int i; | 695 int i; |
692 LookasideSlot *p; | 696 LookasideSlot *p; |
693 assert( sz > (int)sizeof(LookasideSlot*) ); | 697 assert( sz > (int)sizeof(LookasideSlot*) ); |
694 p = (LookasideSlot*)pStart; | 698 p = (LookasideSlot*)pStart; |
695 for(i=cnt-1; i>=0; i--){ | 699 for(i=cnt-1; i>=0; i--){ |
696 p->pNext = db->lookaside.pFree; | 700 p->pNext = db->lookaside.pFree; |
697 db->lookaside.pFree = p; | 701 db->lookaside.pFree = p; |
698 p = (LookasideSlot*)&((u8*)p)[sz]; | 702 p = (LookasideSlot*)&((u8*)p)[sz]; |
699 } | 703 } |
700 db->lookaside.pEnd = p; | 704 db->lookaside.pEnd = p; |
701 db->lookaside.bEnabled = 1; | 705 db->lookaside.bDisable = 0; |
702 db->lookaside.bMalloced = pBuf==0 ?1:0; | 706 db->lookaside.bMalloced = pBuf==0 ?1:0; |
703 }else{ | 707 }else{ |
704 db->lookaside.pStart = db; | 708 db->lookaside.pStart = db; |
705 db->lookaside.pEnd = db; | 709 db->lookaside.pEnd = db; |
706 db->lookaside.bEnabled = 0; | 710 db->lookaside.bDisable = 1; |
707 db->lookaside.bMalloced = 0; | 711 db->lookaside.bMalloced = 0; |
708 } | 712 } |
709 #endif /* SQLITE_OMIT_LOOKASIDE */ | 713 #endif /* SQLITE_OMIT_LOOKASIDE */ |
710 return SQLITE_OK; | 714 return SQLITE_OK; |
711 } | 715 } |
712 | 716 |
713 /* | 717 /* |
714 ** Return the mutex associated with a database connection. | 718 ** Return the mutex associated with a database connection. |
715 */ | 719 */ |
716 sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ | 720 sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 } | 782 } |
779 | 783 |
780 /* | 784 /* |
781 ** Configuration settings for an individual database connection | 785 ** Configuration settings for an individual database connection |
782 */ | 786 */ |
783 int sqlite3_db_config(sqlite3 *db, int op, ...){ | 787 int sqlite3_db_config(sqlite3 *db, int op, ...){ |
784 va_list ap; | 788 va_list ap; |
785 int rc; | 789 int rc; |
786 va_start(ap, op); | 790 va_start(ap, op); |
787 switch( op ){ | 791 switch( op ){ |
| 792 case SQLITE_DBCONFIG_MAINDBNAME: { |
| 793 db->aDb[0].zDbSName = va_arg(ap,char*); |
| 794 rc = SQLITE_OK; |
| 795 break; |
| 796 } |
788 case SQLITE_DBCONFIG_LOOKASIDE: { | 797 case SQLITE_DBCONFIG_LOOKASIDE: { |
789 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */ | 798 void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */ |
790 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */ | 799 int sz = va_arg(ap, int); /* IMP: R-47871-25994 */ |
791 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */ | 800 int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */ |
792 rc = setupLookaside(db, pBuf, sz, cnt); | 801 rc = setupLookaside(db, pBuf, sz, cnt); |
793 break; | 802 break; |
794 } | 803 } |
795 default: { | 804 default: { |
796 static const struct { | 805 static const struct { |
797 int op; /* The opcode */ | 806 int op; /* The opcode */ |
798 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */ | 807 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */ |
799 } aFlagOp[] = { | 808 } aFlagOp[] = { |
800 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys }, | 809 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys }, |
801 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger }, | 810 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger }, |
| 811 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer }, |
| 812 { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension }, |
| 813 { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose }, |
802 }; | 814 }; |
803 unsigned int i; | 815 unsigned int i; |
804 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ | 816 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
805 for(i=0; i<ArraySize(aFlagOp); i++){ | 817 for(i=0; i<ArraySize(aFlagOp); i++){ |
806 if( aFlagOp[i].op==op ){ | 818 if( aFlagOp[i].op==op ){ |
807 int onoff = va_arg(ap, int); | 819 int onoff = va_arg(ap, int); |
808 int *pRes = va_arg(ap, int*); | 820 int *pRes = va_arg(ap, int*); |
809 int oldFlags = db->flags; | 821 int oldFlags = db->flags; |
810 if( onoff>0 ){ | 822 if( onoff>0 ){ |
811 db->flags |= aFlagOp[i].mask; | 823 db->flags |= aFlagOp[i].mask; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 db->isTransactionSavepoint = 0; | 963 db->isTransactionSavepoint = 0; |
952 } | 964 } |
953 | 965 |
954 /* | 966 /* |
955 ** Invoke the destructor function associated with FuncDef p, if any. Except, | 967 ** Invoke the destructor function associated with FuncDef p, if any. Except, |
956 ** if this is not the last copy of the function, do not invoke it. Multiple | 968 ** if this is not the last copy of the function, do not invoke it. Multiple |
957 ** copies of a single function are created when create_function() is called | 969 ** copies of a single function are created when create_function() is called |
958 ** with SQLITE_ANY as the encoding. | 970 ** with SQLITE_ANY as the encoding. |
959 */ | 971 */ |
960 static void functionDestroy(sqlite3 *db, FuncDef *p){ | 972 static void functionDestroy(sqlite3 *db, FuncDef *p){ |
961 FuncDestructor *pDestructor = p->pDestructor; | 973 FuncDestructor *pDestructor = p->u.pDestructor; |
962 if( pDestructor ){ | 974 if( pDestructor ){ |
963 pDestructor->nRef--; | 975 pDestructor->nRef--; |
964 if( pDestructor->nRef==0 ){ | 976 if( pDestructor->nRef==0 ){ |
965 pDestructor->xDestroy(pDestructor->pUserData); | 977 pDestructor->xDestroy(pDestructor->pUserData); |
966 sqlite3DbFree(db, pDestructor); | 978 sqlite3DbFree(db, pDestructor); |
967 } | 979 } |
968 } | 980 } |
969 } | 981 } |
970 | 982 |
971 /* | 983 /* |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 static int sqlite3Close(sqlite3 *db, int forceZombie){ | 1032 static int sqlite3Close(sqlite3 *db, int forceZombie){ |
1021 if( !db ){ | 1033 if( !db ){ |
1022 /* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or | 1034 /* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or |
1023 ** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */ | 1035 ** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */ |
1024 return SQLITE_OK; | 1036 return SQLITE_OK; |
1025 } | 1037 } |
1026 if( !sqlite3SafetyCheckSickOrOk(db) ){ | 1038 if( !sqlite3SafetyCheckSickOrOk(db) ){ |
1027 return SQLITE_MISUSE_BKPT; | 1039 return SQLITE_MISUSE_BKPT; |
1028 } | 1040 } |
1029 sqlite3_mutex_enter(db->mutex); | 1041 sqlite3_mutex_enter(db->mutex); |
| 1042 if( db->mTrace & SQLITE_TRACE_CLOSE ){ |
| 1043 db->xTrace(SQLITE_TRACE_CLOSE, db->pTraceArg, db, 0); |
| 1044 } |
1030 | 1045 |
1031 /* Force xDisconnect calls on all virtual tables */ | 1046 /* Force xDisconnect calls on all virtual tables */ |
1032 disconnectAllVtab(db); | 1047 disconnectAllVtab(db); |
1033 | 1048 |
1034 /* If a transaction is open, the disconnectAllVtab() call above | 1049 /* If a transaction is open, the disconnectAllVtab() call above |
1035 ** will not have called the xDisconnect() method on any virtual | 1050 ** will not have called the xDisconnect() method on any virtual |
1036 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() | 1051 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() |
1037 ** call will do so. We need to do this before the check for active | 1052 ** call will do so. We need to do this before the check for active |
1038 ** SQL statements below, as the v-table implementation may be storing | 1053 ** SQL statements below, as the v-table implementation may be storing |
1039 ** some prepared statements internally. | 1054 ** some prepared statements internally. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 /* Free up the array of auxiliary databases */ | 1148 /* Free up the array of auxiliary databases */ |
1134 sqlite3CollapseDatabaseArray(db); | 1149 sqlite3CollapseDatabaseArray(db); |
1135 assert( db->nDb<=2 ); | 1150 assert( db->nDb<=2 ); |
1136 assert( db->aDb==db->aDbStatic ); | 1151 assert( db->aDb==db->aDbStatic ); |
1137 | 1152 |
1138 /* Tell the code in notify.c that the connection no longer holds any | 1153 /* Tell the code in notify.c that the connection no longer holds any |
1139 ** locks and does not require any further unlock-notify callbacks. | 1154 ** locks and does not require any further unlock-notify callbacks. |
1140 */ | 1155 */ |
1141 sqlite3ConnectionClosed(db); | 1156 sqlite3ConnectionClosed(db); |
1142 | 1157 |
1143 for(j=0; j<ArraySize(db->aFunc.a); j++){ | 1158 for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){ |
1144 FuncDef *pNext, *pHash, *p; | 1159 FuncDef *pNext, *p; |
1145 for(p=db->aFunc.a[j]; p; p=pHash){ | 1160 p = sqliteHashData(i); |
1146 pHash = p->pHash; | 1161 do{ |
1147 while( p ){ | 1162 functionDestroy(db, p); |
1148 functionDestroy(db, p); | 1163 pNext = p->pNext; |
1149 pNext = p->pNext; | 1164 sqlite3DbFree(db, p); |
1150 sqlite3DbFree(db, p); | 1165 p = pNext; |
1151 p = pNext; | 1166 }while( p ); |
1152 } | |
1153 } | |
1154 } | 1167 } |
| 1168 sqlite3HashClear(&db->aFunc); |
1155 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){ | 1169 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){ |
1156 CollSeq *pColl = (CollSeq *)sqliteHashData(i); | 1170 CollSeq *pColl = (CollSeq *)sqliteHashData(i); |
1157 /* Invoke any destructors registered for collation sequence user data. */ | 1171 /* Invoke any destructors registered for collation sequence user data. */ |
1158 for(j=0; j<3; j++){ | 1172 for(j=0; j<3; j++){ |
1159 if( pColl[j].xDel ){ | 1173 if( pColl[j].xDel ){ |
1160 pColl[j].xDel(pColl[j].pUser); | 1174 pColl[j].xDel(pColl[j].pUser); |
1161 } | 1175 } |
1162 } | 1176 } |
1163 sqlite3DbFree(db, pColl); | 1177 sqlite3DbFree(db, pColl); |
1164 } | 1178 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 sqlite3_busy_handler(db, 0, 0); | 1561 sqlite3_busy_handler(db, 0, 0); |
1548 } | 1562 } |
1549 return SQLITE_OK; | 1563 return SQLITE_OK; |
1550 } | 1564 } |
1551 | 1565 |
1552 /* | 1566 /* |
1553 ** Cause any pending operation to stop at its earliest opportunity. | 1567 ** Cause any pending operation to stop at its earliest opportunity. |
1554 */ | 1568 */ |
1555 void sqlite3_interrupt(sqlite3 *db){ | 1569 void sqlite3_interrupt(sqlite3 *db){ |
1556 #ifdef SQLITE_ENABLE_API_ARMOR | 1570 #ifdef SQLITE_ENABLE_API_ARMOR |
1557 if( !sqlite3SafetyCheckOk(db) ){ | 1571 if( !sqlite3SafetyCheckOk(db) && (db==0 || db->magic!=SQLITE_MAGIC_ZOMBIE) ){ |
1558 (void)SQLITE_MISUSE_BKPT; | 1572 (void)SQLITE_MISUSE_BKPT; |
1559 return; | 1573 return; |
1560 } | 1574 } |
1561 #endif | 1575 #endif |
1562 db->u1.isInterrupted = 1; | 1576 db->u1.isInterrupted = 1; |
1563 } | 1577 } |
1564 | 1578 |
1565 | 1579 |
1566 /* | 1580 /* |
1567 ** This function is exactly the same as sqlite3_create_function(), except | 1581 ** This function is exactly the same as sqlite3_create_function(), except |
1568 ** that it is designed to be called by internal code. The difference is | 1582 ** that it is designed to be called by internal code. The difference is |
1569 ** that if a malloc() fails in sqlite3_create_function(), an error code | 1583 ** that if a malloc() fails in sqlite3_create_function(), an error code |
1570 ** is returned and the mallocFailed flag cleared. | 1584 ** is returned and the mallocFailed flag cleared. |
1571 */ | 1585 */ |
1572 int sqlite3CreateFunc( | 1586 int sqlite3CreateFunc( |
1573 sqlite3 *db, | 1587 sqlite3 *db, |
1574 const char *zFunctionName, | 1588 const char *zFunctionName, |
1575 int nArg, | 1589 int nArg, |
1576 int enc, | 1590 int enc, |
1577 void *pUserData, | 1591 void *pUserData, |
1578 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | 1592 void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), |
1579 void (*xStep)(sqlite3_context*,int,sqlite3_value **), | 1593 void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
1580 void (*xFinal)(sqlite3_context*), | 1594 void (*xFinal)(sqlite3_context*), |
1581 FuncDestructor *pDestructor | 1595 FuncDestructor *pDestructor |
1582 ){ | 1596 ){ |
1583 FuncDef *p; | 1597 FuncDef *p; |
1584 int nName; | 1598 int nName; |
1585 int extraFlags; | 1599 int extraFlags; |
1586 | 1600 |
1587 assert( sqlite3_mutex_held(db->mutex) ); | 1601 assert( sqlite3_mutex_held(db->mutex) ); |
1588 if( zFunctionName==0 || | 1602 if( zFunctionName==0 || |
1589 (xFunc && (xFinal || xStep)) || | 1603 (xSFunc && (xFinal || xStep)) || |
1590 (!xFunc && (xFinal && !xStep)) || | 1604 (!xSFunc && (xFinal && !xStep)) || |
1591 (!xFunc && (!xFinal && xStep)) || | 1605 (!xSFunc && (!xFinal && xStep)) || |
1592 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || | 1606 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
1593 (255<(nName = sqlite3Strlen30( zFunctionName))) ){ | 1607 (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
1594 return SQLITE_MISUSE_BKPT; | 1608 return SQLITE_MISUSE_BKPT; |
1595 } | 1609 } |
1596 | 1610 |
1597 assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); | 1611 assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); |
1598 extraFlags = enc & SQLITE_DETERMINISTIC; | 1612 extraFlags = enc & SQLITE_DETERMINISTIC; |
1599 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); | 1613 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); |
1600 | 1614 |
1601 #ifndef SQLITE_OMIT_UTF16 | 1615 #ifndef SQLITE_OMIT_UTF16 |
1602 /* If SQLITE_UTF16 is specified as the encoding type, transform this | 1616 /* If SQLITE_UTF16 is specified as the encoding type, transform this |
1603 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the | 1617 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
1604 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. | 1618 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
1605 ** | 1619 ** |
1606 ** If SQLITE_ANY is specified, add three versions of the function | 1620 ** If SQLITE_ANY is specified, add three versions of the function |
1607 ** to the hash table. | 1621 ** to the hash table. |
1608 */ | 1622 */ |
1609 if( enc==SQLITE_UTF16 ){ | 1623 if( enc==SQLITE_UTF16 ){ |
1610 enc = SQLITE_UTF16NATIVE; | 1624 enc = SQLITE_UTF16NATIVE; |
1611 }else if( enc==SQLITE_ANY ){ | 1625 }else if( enc==SQLITE_ANY ){ |
1612 int rc; | 1626 int rc; |
1613 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, | 1627 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
1614 pUserData, xFunc, xStep, xFinal, pDestructor); | 1628 pUserData, xSFunc, xStep, xFinal, pDestructor); |
1615 if( rc==SQLITE_OK ){ | 1629 if( rc==SQLITE_OK ){ |
1616 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, | 1630 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
1617 pUserData, xFunc, xStep, xFinal, pDestructor); | 1631 pUserData, xSFunc, xStep, xFinal, pDestructor); |
1618 } | 1632 } |
1619 if( rc!=SQLITE_OK ){ | 1633 if( rc!=SQLITE_OK ){ |
1620 return rc; | 1634 return rc; |
1621 } | 1635 } |
1622 enc = SQLITE_UTF16BE; | 1636 enc = SQLITE_UTF16BE; |
1623 } | 1637 } |
1624 #else | 1638 #else |
1625 enc = SQLITE_UTF8; | 1639 enc = SQLITE_UTF8; |
1626 #endif | 1640 #endif |
1627 | 1641 |
1628 /* Check if an existing function is being overridden or deleted. If so, | 1642 /* Check if an existing function is being overridden or deleted. If so, |
1629 ** and there are active VMs, then return SQLITE_BUSY. If a function | 1643 ** and there are active VMs, then return SQLITE_BUSY. If a function |
1630 ** is being overridden/deleted but there are no active VMs, allow the | 1644 ** is being overridden/deleted but there are no active VMs, allow the |
1631 ** operation to continue but invalidate all precompiled statements. | 1645 ** operation to continue but invalidate all precompiled statements. |
1632 */ | 1646 */ |
1633 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0); | 1647 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 0); |
1634 if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){ | 1648 if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){ |
1635 if( db->nVdbeActive ){ | 1649 if( db->nVdbeActive ){ |
1636 sqlite3ErrorWithMsg(db, SQLITE_BUSY, | 1650 sqlite3ErrorWithMsg(db, SQLITE_BUSY, |
1637 "unable to delete/modify user-function due to active statements"); | 1651 "unable to delete/modify user-function due to active statements"); |
1638 assert( !db->mallocFailed ); | 1652 assert( !db->mallocFailed ); |
1639 return SQLITE_BUSY; | 1653 return SQLITE_BUSY; |
1640 }else{ | 1654 }else{ |
1641 sqlite3ExpirePreparedStatements(db); | 1655 sqlite3ExpirePreparedStatements(db); |
1642 } | 1656 } |
1643 } | 1657 } |
1644 | 1658 |
1645 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1); | 1659 p = sqlite3FindFunction(db, zFunctionName, nArg, (u8)enc, 1); |
1646 assert(p || db->mallocFailed); | 1660 assert(p || db->mallocFailed); |
1647 if( !p ){ | 1661 if( !p ){ |
1648 return SQLITE_NOMEM; | 1662 return SQLITE_NOMEM_BKPT; |
1649 } | 1663 } |
1650 | 1664 |
1651 /* If an older version of the function with a configured destructor is | 1665 /* If an older version of the function with a configured destructor is |
1652 ** being replaced invoke the destructor function here. */ | 1666 ** being replaced invoke the destructor function here. */ |
1653 functionDestroy(db, p); | 1667 functionDestroy(db, p); |
1654 | 1668 |
1655 if( pDestructor ){ | 1669 if( pDestructor ){ |
1656 pDestructor->nRef++; | 1670 pDestructor->nRef++; |
1657 } | 1671 } |
1658 p->pDestructor = pDestructor; | 1672 p->u.pDestructor = pDestructor; |
1659 p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; | 1673 p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; |
1660 testcase( p->funcFlags & SQLITE_DETERMINISTIC ); | 1674 testcase( p->funcFlags & SQLITE_DETERMINISTIC ); |
1661 p->xFunc = xFunc; | 1675 p->xSFunc = xSFunc ? xSFunc : xStep; |
1662 p->xStep = xStep; | |
1663 p->xFinalize = xFinal; | 1676 p->xFinalize = xFinal; |
1664 p->pUserData = pUserData; | 1677 p->pUserData = pUserData; |
1665 p->nArg = (u16)nArg; | 1678 p->nArg = (u16)nArg; |
1666 return SQLITE_OK; | 1679 return SQLITE_OK; |
1667 } | 1680 } |
1668 | 1681 |
1669 /* | 1682 /* |
1670 ** Create new user functions. | 1683 ** Create new user functions. |
1671 */ | 1684 */ |
1672 int sqlite3_create_function( | 1685 int sqlite3_create_function( |
1673 sqlite3 *db, | 1686 sqlite3 *db, |
1674 const char *zFunc, | 1687 const char *zFunc, |
1675 int nArg, | 1688 int nArg, |
1676 int enc, | 1689 int enc, |
1677 void *p, | 1690 void *p, |
1678 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | 1691 void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), |
1679 void (*xStep)(sqlite3_context*,int,sqlite3_value **), | 1692 void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
1680 void (*xFinal)(sqlite3_context*) | 1693 void (*xFinal)(sqlite3_context*) |
1681 ){ | 1694 ){ |
1682 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep, | 1695 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xSFunc, xStep, |
1683 xFinal, 0); | 1696 xFinal, 0); |
1684 } | 1697 } |
1685 | 1698 |
1686 int sqlite3_create_function_v2( | 1699 int sqlite3_create_function_v2( |
1687 sqlite3 *db, | 1700 sqlite3 *db, |
1688 const char *zFunc, | 1701 const char *zFunc, |
1689 int nArg, | 1702 int nArg, |
1690 int enc, | 1703 int enc, |
1691 void *p, | 1704 void *p, |
1692 void (*xFunc)(sqlite3_context*,int,sqlite3_value **), | 1705 void (*xSFunc)(sqlite3_context*,int,sqlite3_value **), |
1693 void (*xStep)(sqlite3_context*,int,sqlite3_value **), | 1706 void (*xStep)(sqlite3_context*,int,sqlite3_value **), |
1694 void (*xFinal)(sqlite3_context*), | 1707 void (*xFinal)(sqlite3_context*), |
1695 void (*xDestroy)(void *) | 1708 void (*xDestroy)(void *) |
1696 ){ | 1709 ){ |
1697 int rc = SQLITE_ERROR; | 1710 int rc = SQLITE_ERROR; |
1698 FuncDestructor *pArg = 0; | 1711 FuncDestructor *pArg = 0; |
1699 | 1712 |
1700 #ifdef SQLITE_ENABLE_API_ARMOR | 1713 #ifdef SQLITE_ENABLE_API_ARMOR |
1701 if( !sqlite3SafetyCheckOk(db) ){ | 1714 if( !sqlite3SafetyCheckOk(db) ){ |
1702 return SQLITE_MISUSE_BKPT; | 1715 return SQLITE_MISUSE_BKPT; |
1703 } | 1716 } |
1704 #endif | 1717 #endif |
1705 sqlite3_mutex_enter(db->mutex); | 1718 sqlite3_mutex_enter(db->mutex); |
1706 if( xDestroy ){ | 1719 if( xDestroy ){ |
1707 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); | 1720 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor)); |
1708 if( !pArg ){ | 1721 if( !pArg ){ |
1709 xDestroy(p); | 1722 xDestroy(p); |
1710 goto out; | 1723 goto out; |
1711 } | 1724 } |
1712 pArg->xDestroy = xDestroy; | 1725 pArg->xDestroy = xDestroy; |
1713 pArg->pUserData = p; | 1726 pArg->pUserData = p; |
1714 } | 1727 } |
1715 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg); | 1728 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, pArg); |
1716 if( pArg && pArg->nRef==0 ){ | 1729 if( pArg && pArg->nRef==0 ){ |
1717 assert( rc!=SQLITE_OK ); | 1730 assert( rc!=SQLITE_OK ); |
1718 xDestroy(p); | 1731 xDestroy(p); |
1719 sqlite3DbFree(db, pArg); | 1732 sqlite3DbFree(db, pArg); |
1720 } | 1733 } |
1721 | 1734 |
1722 out: | 1735 out: |
1723 rc = sqlite3ApiExit(db, rc); | 1736 rc = sqlite3ApiExit(db, rc); |
1724 sqlite3_mutex_leave(db->mutex); | 1737 sqlite3_mutex_leave(db->mutex); |
1725 return rc; | 1738 return rc; |
1726 } | 1739 } |
1727 | 1740 |
1728 #ifndef SQLITE_OMIT_UTF16 | 1741 #ifndef SQLITE_OMIT_UTF16 |
1729 int sqlite3_create_function16( | 1742 int sqlite3_create_function16( |
1730 sqlite3 *db, | 1743 sqlite3 *db, |
1731 const void *zFunctionName, | 1744 const void *zFunctionName, |
1732 int nArg, | 1745 int nArg, |
1733 int eTextRep, | 1746 int eTextRep, |
1734 void *p, | 1747 void *p, |
1735 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), | 1748 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**), |
1736 void (*xStep)(sqlite3_context*,int,sqlite3_value**), | 1749 void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
1737 void (*xFinal)(sqlite3_context*) | 1750 void (*xFinal)(sqlite3_context*) |
1738 ){ | 1751 ){ |
1739 int rc; | 1752 int rc; |
1740 char *zFunc8; | 1753 char *zFunc8; |
1741 | 1754 |
1742 #ifdef SQLITE_ENABLE_API_ARMOR | 1755 #ifdef SQLITE_ENABLE_API_ARMOR |
1743 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; | 1756 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT; |
1744 #endif | 1757 #endif |
1745 sqlite3_mutex_enter(db->mutex); | 1758 sqlite3_mutex_enter(db->mutex); |
1746 assert( !db->mallocFailed ); | 1759 assert( !db->mallocFailed ); |
1747 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); | 1760 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE); |
1748 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0); | 1761 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0); |
1749 sqlite3DbFree(db, zFunc8); | 1762 sqlite3DbFree(db, zFunc8); |
1750 rc = sqlite3ApiExit(db, rc); | 1763 rc = sqlite3ApiExit(db, rc); |
1751 sqlite3_mutex_leave(db->mutex); | 1764 sqlite3_mutex_leave(db->mutex); |
1752 return rc; | 1765 return rc; |
1753 } | 1766 } |
1754 #endif | 1767 #endif |
1755 | 1768 |
1756 | 1769 |
1757 /* | 1770 /* |
1758 ** Declare that a function has been overloaded by a virtual table. | 1771 ** Declare that a function has been overloaded by a virtual table. |
1759 ** | 1772 ** |
1760 ** If the function already exists as a regular global function, then | 1773 ** If the function already exists as a regular global function, then |
1761 ** this routine is a no-op. If the function does not exist, then create | 1774 ** this routine is a no-op. If the function does not exist, then create |
1762 ** a new one that always throws a run-time error. | 1775 ** a new one that always throws a run-time error. |
1763 ** | 1776 ** |
1764 ** When virtual tables intend to provide an overloaded function, they | 1777 ** When virtual tables intend to provide an overloaded function, they |
1765 ** should call this routine to make sure the global function exists. | 1778 ** should call this routine to make sure the global function exists. |
1766 ** A global function must exist in order for name resolution to work | 1779 ** A global function must exist in order for name resolution to work |
1767 ** properly. | 1780 ** properly. |
1768 */ | 1781 */ |
1769 int sqlite3_overload_function( | 1782 int sqlite3_overload_function( |
1770 sqlite3 *db, | 1783 sqlite3 *db, |
1771 const char *zName, | 1784 const char *zName, |
1772 int nArg | 1785 int nArg |
1773 ){ | 1786 ){ |
1774 int nName = sqlite3Strlen30(zName); | |
1775 int rc = SQLITE_OK; | 1787 int rc = SQLITE_OK; |
1776 | 1788 |
1777 #ifdef SQLITE_ENABLE_API_ARMOR | 1789 #ifdef SQLITE_ENABLE_API_ARMOR |
1778 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){ | 1790 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){ |
1779 return SQLITE_MISUSE_BKPT; | 1791 return SQLITE_MISUSE_BKPT; |
1780 } | 1792 } |
1781 #endif | 1793 #endif |
1782 sqlite3_mutex_enter(db->mutex); | 1794 sqlite3_mutex_enter(db->mutex); |
1783 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){ | 1795 if( sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)==0 ){ |
1784 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, | 1796 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8, |
1785 0, sqlite3InvalidFunction, 0, 0, 0); | 1797 0, sqlite3InvalidFunction, 0, 0, 0); |
1786 } | 1798 } |
1787 rc = sqlite3ApiExit(db, rc); | 1799 rc = sqlite3ApiExit(db, rc); |
1788 sqlite3_mutex_leave(db->mutex); | 1800 sqlite3_mutex_leave(db->mutex); |
1789 return rc; | 1801 return rc; |
1790 } | 1802 } |
1791 | 1803 |
1792 #ifndef SQLITE_OMIT_TRACE | 1804 #ifndef SQLITE_OMIT_TRACE |
1793 /* | 1805 /* |
1794 ** Register a trace function. The pArg from the previously registered trace | 1806 ** Register a trace function. The pArg from the previously registered trace |
1795 ** is returned. | 1807 ** is returned. |
1796 ** | 1808 ** |
1797 ** A NULL trace function means that no tracing is executes. A non-NULL | 1809 ** A NULL trace function means that no tracing is executes. A non-NULL |
1798 ** trace is a pointer to a function that is invoked at the start of each | 1810 ** trace is a pointer to a function that is invoked at the start of each |
1799 ** SQL statement. | 1811 ** SQL statement. |
1800 */ | 1812 */ |
1801 void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ | 1813 #ifndef SQLITE_OMIT_DEPRECATED |
| 1814 void *sqlite3_trace(sqlite3 *db, void(*xTrace)(void*,const char*), void *pArg){ |
1802 void *pOld; | 1815 void *pOld; |
1803 | 1816 |
1804 #ifdef SQLITE_ENABLE_API_ARMOR | 1817 #ifdef SQLITE_ENABLE_API_ARMOR |
1805 if( !sqlite3SafetyCheckOk(db) ){ | 1818 if( !sqlite3SafetyCheckOk(db) ){ |
1806 (void)SQLITE_MISUSE_BKPT; | 1819 (void)SQLITE_MISUSE_BKPT; |
1807 return 0; | 1820 return 0; |
1808 } | 1821 } |
1809 #endif | 1822 #endif |
1810 sqlite3_mutex_enter(db->mutex); | 1823 sqlite3_mutex_enter(db->mutex); |
1811 pOld = db->pTraceArg; | 1824 pOld = db->pTraceArg; |
1812 db->xTrace = xTrace; | 1825 db->mTrace = xTrace ? SQLITE_TRACE_LEGACY : 0; |
| 1826 db->xTrace = (int(*)(u32,void*,void*,void*))xTrace; |
1813 db->pTraceArg = pArg; | 1827 db->pTraceArg = pArg; |
1814 sqlite3_mutex_leave(db->mutex); | 1828 sqlite3_mutex_leave(db->mutex); |
1815 return pOld; | 1829 return pOld; |
1816 } | 1830 } |
| 1831 #endif /* SQLITE_OMIT_DEPRECATED */ |
| 1832 |
| 1833 /* Register a trace callback using the version-2 interface. |
| 1834 */ |
| 1835 int sqlite3_trace_v2( |
| 1836 sqlite3 *db, /* Trace this connection */ |
| 1837 unsigned mTrace, /* Mask of events to be traced */ |
| 1838 int(*xTrace)(unsigned,void*,void*,void*), /* Callback to invoke */ |
| 1839 void *pArg /* Context */ |
| 1840 ){ |
| 1841 #ifdef SQLITE_ENABLE_API_ARMOR |
| 1842 if( !sqlite3SafetyCheckOk(db) ){ |
| 1843 return SQLITE_MISUSE_BKPT; |
| 1844 } |
| 1845 #endif |
| 1846 sqlite3_mutex_enter(db->mutex); |
| 1847 if( mTrace==0 ) xTrace = 0; |
| 1848 if( xTrace==0 ) mTrace = 0; |
| 1849 db->mTrace = mTrace; |
| 1850 db->xTrace = xTrace; |
| 1851 db->pTraceArg = pArg; |
| 1852 sqlite3_mutex_leave(db->mutex); |
| 1853 return SQLITE_OK; |
| 1854 } |
| 1855 |
| 1856 #ifndef SQLITE_OMIT_DEPRECATED |
1817 /* | 1857 /* |
1818 ** Register a profile function. The pArg from the previously registered | 1858 ** Register a profile function. The pArg from the previously registered |
1819 ** profile function is returned. | 1859 ** profile function is returned. |
1820 ** | 1860 ** |
1821 ** A NULL profile function means that no profiling is executes. A non-NULL | 1861 ** A NULL profile function means that no profiling is executes. A non-NULL |
1822 ** profile is a pointer to a function that is invoked at the conclusion of | 1862 ** profile is a pointer to a function that is invoked at the conclusion of |
1823 ** each SQL statement that is run. | 1863 ** each SQL statement that is run. |
1824 */ | 1864 */ |
1825 void *sqlite3_profile( | 1865 void *sqlite3_profile( |
1826 sqlite3 *db, | 1866 sqlite3 *db, |
1827 void (*xProfile)(void*,const char*,sqlite_uint64), | 1867 void (*xProfile)(void*,const char*,sqlite_uint64), |
1828 void *pArg | 1868 void *pArg |
1829 ){ | 1869 ){ |
1830 void *pOld; | 1870 void *pOld; |
1831 | 1871 |
1832 #ifdef SQLITE_ENABLE_API_ARMOR | 1872 #ifdef SQLITE_ENABLE_API_ARMOR |
1833 if( !sqlite3SafetyCheckOk(db) ){ | 1873 if( !sqlite3SafetyCheckOk(db) ){ |
1834 (void)SQLITE_MISUSE_BKPT; | 1874 (void)SQLITE_MISUSE_BKPT; |
1835 return 0; | 1875 return 0; |
1836 } | 1876 } |
1837 #endif | 1877 #endif |
1838 sqlite3_mutex_enter(db->mutex); | 1878 sqlite3_mutex_enter(db->mutex); |
1839 pOld = db->pProfileArg; | 1879 pOld = db->pProfileArg; |
1840 db->xProfile = xProfile; | 1880 db->xProfile = xProfile; |
1841 db->pProfileArg = pArg; | 1881 db->pProfileArg = pArg; |
1842 sqlite3_mutex_leave(db->mutex); | 1882 sqlite3_mutex_leave(db->mutex); |
1843 return pOld; | 1883 return pOld; |
1844 } | 1884 } |
| 1885 #endif /* SQLITE_OMIT_DEPRECATED */ |
1845 #endif /* SQLITE_OMIT_TRACE */ | 1886 #endif /* SQLITE_OMIT_TRACE */ |
1846 | 1887 |
1847 /* | 1888 /* |
1848 ** Register a function to be invoked when a transaction commits. | 1889 ** Register a function to be invoked when a transaction commits. |
1849 ** If the invoked function returns non-zero, then the commit becomes a | 1890 ** If the invoked function returns non-zero, then the commit becomes a |
1850 ** rollback. | 1891 ** rollback. |
1851 */ | 1892 */ |
1852 void *sqlite3_commit_hook( | 1893 void *sqlite3_commit_hook( |
1853 sqlite3 *db, /* Attach the hook to this database */ | 1894 sqlite3 *db, /* Attach the hook to this database */ |
1854 int (*xCallback)(void*), /* Function to invoke on each commit */ | 1895 int (*xCallback)(void*), /* Function to invoke on each commit */ |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 } | 1954 } |
1914 #endif | 1955 #endif |
1915 sqlite3_mutex_enter(db->mutex); | 1956 sqlite3_mutex_enter(db->mutex); |
1916 pRet = db->pRollbackArg; | 1957 pRet = db->pRollbackArg; |
1917 db->xRollbackCallback = xCallback; | 1958 db->xRollbackCallback = xCallback; |
1918 db->pRollbackArg = pArg; | 1959 db->pRollbackArg = pArg; |
1919 sqlite3_mutex_leave(db->mutex); | 1960 sqlite3_mutex_leave(db->mutex); |
1920 return pRet; | 1961 return pRet; |
1921 } | 1962 } |
1922 | 1963 |
| 1964 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 1965 /* |
| 1966 ** Register a callback to be invoked each time a row is updated, |
| 1967 ** inserted or deleted using this database connection. |
| 1968 */ |
| 1969 void *sqlite3_preupdate_hook( |
| 1970 sqlite3 *db, /* Attach the hook to this database */ |
| 1971 void(*xCallback)( /* Callback function */ |
| 1972 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64), |
| 1973 void *pArg /* First callback argument */ |
| 1974 ){ |
| 1975 void *pRet; |
| 1976 sqlite3_mutex_enter(db->mutex); |
| 1977 pRet = db->pPreUpdateArg; |
| 1978 db->xPreUpdateCallback = xCallback; |
| 1979 db->pPreUpdateArg = pArg; |
| 1980 sqlite3_mutex_leave(db->mutex); |
| 1981 return pRet; |
| 1982 } |
| 1983 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 1984 |
1923 #ifndef SQLITE_OMIT_WAL | 1985 #ifndef SQLITE_OMIT_WAL |
1924 /* | 1986 /* |
1925 ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint(). | 1987 ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint(). |
1926 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file | 1988 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file |
1927 ** is greater than sqlite3.pWalArg cast to an integer (the value configured by | 1989 ** is greater than sqlite3.pWalArg cast to an integer (the value configured by |
1928 ** wal_autocheckpoint()). | 1990 ** wal_autocheckpoint()). |
1929 */ | 1991 */ |
1930 int sqlite3WalDefaultHook( | 1992 int sqlite3WalDefaultHook( |
1931 void *pClientData, /* Argument */ | 1993 void *pClientData, /* Argument */ |
1932 sqlite3 *db, /* Connection */ | 1994 sqlite3 *db, /* Connection */ |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 } | 2100 } |
2039 if( iDb<0 ){ | 2101 if( iDb<0 ){ |
2040 rc = SQLITE_ERROR; | 2102 rc = SQLITE_ERROR; |
2041 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb); | 2103 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb); |
2042 }else{ | 2104 }else{ |
2043 db->busyHandler.nBusy = 0; | 2105 db->busyHandler.nBusy = 0; |
2044 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt); | 2106 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt); |
2045 sqlite3Error(db, rc); | 2107 sqlite3Error(db, rc); |
2046 } | 2108 } |
2047 rc = sqlite3ApiExit(db, rc); | 2109 rc = sqlite3ApiExit(db, rc); |
| 2110 |
| 2111 /* If there are no active statements, clear the interrupt flag at this |
| 2112 ** point. */ |
| 2113 if( db->nVdbeActive==0 ){ |
| 2114 db->u1.isInterrupted = 0; |
| 2115 } |
| 2116 |
2048 sqlite3_mutex_leave(db->mutex); | 2117 sqlite3_mutex_leave(db->mutex); |
2049 return rc; | 2118 return rc; |
2050 #endif | 2119 #endif |
2051 } | 2120 } |
2052 | 2121 |
2053 | 2122 |
2054 /* | 2123 /* |
2055 ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points | 2124 ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points |
2056 ** to contains a zero-length string, all attached databases are | 2125 ** to contains a zero-length string, all attached databases are |
2057 ** checkpointed. | 2126 ** checkpointed. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2143 #endif | 2212 #endif |
2144 } | 2213 } |
2145 | 2214 |
2146 /* | 2215 /* |
2147 ** Return UTF-8 encoded English language explanation of the most recent | 2216 ** Return UTF-8 encoded English language explanation of the most recent |
2148 ** error. | 2217 ** error. |
2149 */ | 2218 */ |
2150 const char *sqlite3_errmsg(sqlite3 *db){ | 2219 const char *sqlite3_errmsg(sqlite3 *db){ |
2151 const char *z; | 2220 const char *z; |
2152 if( !db ){ | 2221 if( !db ){ |
2153 return sqlite3ErrStr(SQLITE_NOMEM); | 2222 return sqlite3ErrStr(SQLITE_NOMEM_BKPT); |
2154 } | 2223 } |
2155 if( !sqlite3SafetyCheckSickOrOk(db) ){ | 2224 if( !sqlite3SafetyCheckSickOrOk(db) ){ |
2156 return sqlite3ErrStr(SQLITE_MISUSE_BKPT); | 2225 return sqlite3ErrStr(SQLITE_MISUSE_BKPT); |
2157 } | 2226 } |
2158 sqlite3_mutex_enter(db->mutex); | 2227 sqlite3_mutex_enter(db->mutex); |
2159 if( db->mallocFailed ){ | 2228 if( db->mallocFailed ){ |
2160 z = sqlite3ErrStr(SQLITE_NOMEM); | 2229 z = sqlite3ErrStr(SQLITE_NOMEM_BKPT); |
2161 }else{ | 2230 }else{ |
2162 testcase( db->pErr==0 ); | 2231 testcase( db->pErr==0 ); |
2163 z = (char*)sqlite3_value_text(db->pErr); | 2232 z = (char*)sqlite3_value_text(db->pErr); |
2164 assert( !db->mallocFailed ); | 2233 assert( !db->mallocFailed ); |
2165 if( z==0 ){ | 2234 if( z==0 ){ |
2166 z = sqlite3ErrStr(db->errCode); | 2235 z = sqlite3ErrStr(db->errCode); |
2167 } | 2236 } |
2168 } | 2237 } |
2169 sqlite3_mutex_leave(db->mutex); | 2238 sqlite3_mutex_leave(db->mutex); |
2170 return z; | 2239 return z; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2202 z = sqlite3_value_text16(db->pErr); | 2271 z = sqlite3_value_text16(db->pErr); |
2203 if( z==0 ){ | 2272 if( z==0 ){ |
2204 sqlite3ErrorWithMsg(db, db->errCode, sqlite3ErrStr(db->errCode)); | 2273 sqlite3ErrorWithMsg(db, db->errCode, sqlite3ErrStr(db->errCode)); |
2205 z = sqlite3_value_text16(db->pErr); | 2274 z = sqlite3_value_text16(db->pErr); |
2206 } | 2275 } |
2207 /* A malloc() may have failed within the call to sqlite3_value_text16() | 2276 /* A malloc() may have failed within the call to sqlite3_value_text16() |
2208 ** above. If this is the case, then the db->mallocFailed flag needs to | 2277 ** above. If this is the case, then the db->mallocFailed flag needs to |
2209 ** be cleared before returning. Do this directly, instead of via | 2278 ** be cleared before returning. Do this directly, instead of via |
2210 ** sqlite3ApiExit(), to avoid setting the database handle error message. | 2279 ** sqlite3ApiExit(), to avoid setting the database handle error message. |
2211 */ | 2280 */ |
2212 db->mallocFailed = 0; | 2281 sqlite3OomClear(db); |
2213 } | 2282 } |
2214 sqlite3_mutex_leave(db->mutex); | 2283 sqlite3_mutex_leave(db->mutex); |
2215 return z; | 2284 return z; |
2216 } | 2285 } |
2217 #endif /* SQLITE_OMIT_UTF16 */ | 2286 #endif /* SQLITE_OMIT_UTF16 */ |
2218 | 2287 |
2219 /* | 2288 /* |
2220 ** Return the most recent error code generated by an SQLite routine. If NULL is | 2289 ** Return the most recent error code generated by an SQLite routine. If NULL is |
2221 ** passed to this function, we assume a malloc() failed during sqlite3_open(). | 2290 ** passed to this function, we assume a malloc() failed during sqlite3_open(). |
2222 */ | 2291 */ |
2223 int sqlite3_errcode(sqlite3 *db){ | 2292 int sqlite3_errcode(sqlite3 *db){ |
2224 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ | 2293 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ |
2225 return SQLITE_MISUSE_BKPT; | 2294 return SQLITE_MISUSE_BKPT; |
2226 } | 2295 } |
2227 if( !db || db->mallocFailed ){ | 2296 if( !db || db->mallocFailed ){ |
2228 return SQLITE_NOMEM; | 2297 return SQLITE_NOMEM_BKPT; |
2229 } | 2298 } |
2230 return db->errCode & db->errMask; | 2299 return db->errCode & db->errMask; |
2231 } | 2300 } |
2232 int sqlite3_extended_errcode(sqlite3 *db){ | 2301 int sqlite3_extended_errcode(sqlite3 *db){ |
2233 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ | 2302 if( db && !sqlite3SafetyCheckSickOrOk(db) ){ |
2234 return SQLITE_MISUSE_BKPT; | 2303 return SQLITE_MISUSE_BKPT; |
2235 } | 2304 } |
2236 if( !db || db->mallocFailed ){ | 2305 if( !db || db->mallocFailed ){ |
2237 return SQLITE_NOMEM; | 2306 return SQLITE_NOMEM_BKPT; |
2238 } | 2307 } |
2239 return db->errCode; | 2308 return db->errCode; |
2240 } | 2309 } |
| 2310 int sqlite3_system_errno(sqlite3 *db){ |
| 2311 return db ? db->iSysErrno : 0; |
| 2312 } |
2241 | 2313 |
2242 /* | 2314 /* |
2243 ** Return a string that describes the kind of error specified in the | 2315 ** Return a string that describes the kind of error specified in the |
2244 ** argument. For now, this simply calls the internal sqlite3ErrStr() | 2316 ** argument. For now, this simply calls the internal sqlite3ErrStr() |
2245 ** function. | 2317 ** function. |
2246 */ | 2318 */ |
2247 const char *sqlite3_errstr(int rc){ | 2319 const char *sqlite3_errstr(int rc){ |
2248 return sqlite3ErrStr(rc); | 2320 return sqlite3ErrStr(rc); |
2249 } | 2321 } |
2250 | 2322 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 if( p->xDel ){ | 2379 if( p->xDel ){ |
2308 p->xDel(p->pUser); | 2380 p->xDel(p->pUser); |
2309 } | 2381 } |
2310 p->xCmp = 0; | 2382 p->xCmp = 0; |
2311 } | 2383 } |
2312 } | 2384 } |
2313 } | 2385 } |
2314 } | 2386 } |
2315 | 2387 |
2316 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1); | 2388 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1); |
2317 if( pColl==0 ) return SQLITE_NOMEM; | 2389 if( pColl==0 ) return SQLITE_NOMEM_BKPT; |
2318 pColl->xCmp = xCompare; | 2390 pColl->xCmp = xCompare; |
2319 pColl->pUser = pCtx; | 2391 pColl->pUser = pCtx; |
2320 pColl->xDel = xDel; | 2392 pColl->xDel = xDel; |
2321 pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED)); | 2393 pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED)); |
2322 sqlite3Error(db, SQLITE_OK); | 2394 sqlite3Error(db, SQLITE_OK); |
2323 return SQLITE_OK; | 2395 return SQLITE_OK; |
2324 } | 2396 } |
2325 | 2397 |
2326 | 2398 |
2327 /* | 2399 /* |
(...skipping 27 matching lines...) Expand all Loading... |
2355 #endif | 2427 #endif |
2356 #if SQLITE_MAX_SQL_LENGTH>SQLITE_MAX_LENGTH | 2428 #if SQLITE_MAX_SQL_LENGTH>SQLITE_MAX_LENGTH |
2357 # error SQLITE_MAX_SQL_LENGTH must not be greater than SQLITE_MAX_LENGTH | 2429 # error SQLITE_MAX_SQL_LENGTH must not be greater than SQLITE_MAX_LENGTH |
2358 #endif | 2430 #endif |
2359 #if SQLITE_MAX_COMPOUND_SELECT<2 | 2431 #if SQLITE_MAX_COMPOUND_SELECT<2 |
2360 # error SQLITE_MAX_COMPOUND_SELECT must be at least 2 | 2432 # error SQLITE_MAX_COMPOUND_SELECT must be at least 2 |
2361 #endif | 2433 #endif |
2362 #if SQLITE_MAX_VDBE_OP<40 | 2434 #if SQLITE_MAX_VDBE_OP<40 |
2363 # error SQLITE_MAX_VDBE_OP must be at least 40 | 2435 # error SQLITE_MAX_VDBE_OP must be at least 40 |
2364 #endif | 2436 #endif |
2365 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000 | 2437 #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>127 |
2366 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000 | 2438 # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 127 |
2367 #endif | 2439 #endif |
2368 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125 | 2440 #if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125 |
2369 # error SQLITE_MAX_ATTACHED must be between 0 and 125 | 2441 # error SQLITE_MAX_ATTACHED must be between 0 and 125 |
2370 #endif | 2442 #endif |
2371 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 | 2443 #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1 |
2372 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 | 2444 # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1 |
2373 #endif | 2445 #endif |
2374 #if SQLITE_MAX_COLUMN>32767 | 2446 #if SQLITE_MAX_COLUMN>32767 |
2375 # error SQLITE_MAX_COLUMN must not exceed 32767 | 2447 # error SQLITE_MAX_COLUMN must not exceed 32767 |
2376 #endif | 2448 #endif |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 int iIn; /* Input character index */ | 2558 int iIn; /* Input character index */ |
2487 int iOut = 0; /* Output character index */ | 2559 int iOut = 0; /* Output character index */ |
2488 u64 nByte = nUri+2; /* Bytes of space to allocate */ | 2560 u64 nByte = nUri+2; /* Bytes of space to allocate */ |
2489 | 2561 |
2490 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen | 2562 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen |
2491 ** method that there may be extra parameters following the file-name. */ | 2563 ** method that there may be extra parameters following the file-name. */ |
2492 flags |= SQLITE_OPEN_URI; | 2564 flags |= SQLITE_OPEN_URI; |
2493 | 2565 |
2494 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); | 2566 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&'); |
2495 zFile = sqlite3_malloc64(nByte); | 2567 zFile = sqlite3_malloc64(nByte); |
2496 if( !zFile ) return SQLITE_NOMEM; | 2568 if( !zFile ) return SQLITE_NOMEM_BKPT; |
2497 | 2569 |
2498 iIn = 5; | 2570 iIn = 5; |
2499 #ifdef SQLITE_ALLOW_URI_AUTHORITY | 2571 #ifdef SQLITE_ALLOW_URI_AUTHORITY |
2500 if( strncmp(zUri+5, "///", 3)==0 ){ | 2572 if( strncmp(zUri+5, "///", 3)==0 ){ |
2501 iIn = 7; | 2573 iIn = 7; |
2502 /* The following condition causes URIs with five leading / characters | 2574 /* The following condition causes URIs with five leading / characters |
2503 ** like file://///host/path to be converted into UNCs like //host/path. | 2575 ** like file://///host/path to be converted into UNCs like //host/path. |
2504 ** The correct URI for that UNC has only two or four leading / characters | 2576 ** The correct URI for that UNC has only two or four leading / characters |
2505 ** file://host/path or file:////host/path. But 5 leading slashes is a | 2577 ** file://host/path or file:////host/path. But 5 leading slashes is a |
2506 ** common error, we are told, so we handle it as a special case. */ | 2578 ** common error, we are told, so we handle it as a special case. */ |
(...skipping 30 matching lines...) Expand all Loading... |
2537 iIn++; | 2609 iIn++; |
2538 if( c=='%' | 2610 if( c=='%' |
2539 && sqlite3Isxdigit(zUri[iIn]) | 2611 && sqlite3Isxdigit(zUri[iIn]) |
2540 && sqlite3Isxdigit(zUri[iIn+1]) | 2612 && sqlite3Isxdigit(zUri[iIn+1]) |
2541 ){ | 2613 ){ |
2542 int octet = (sqlite3HexToInt(zUri[iIn++]) << 4); | 2614 int octet = (sqlite3HexToInt(zUri[iIn++]) << 4); |
2543 octet += sqlite3HexToInt(zUri[iIn++]); | 2615 octet += sqlite3HexToInt(zUri[iIn++]); |
2544 | 2616 |
2545 assert( octet>=0 && octet<256 ); | 2617 assert( octet>=0 && octet<256 ); |
2546 if( octet==0 ){ | 2618 if( octet==0 ){ |
| 2619 #ifndef SQLITE_ENABLE_URI_00_ERROR |
2547 /* This branch is taken when "%00" appears within the URI. In this | 2620 /* This branch is taken when "%00" appears within the URI. In this |
2548 ** case we ignore all text in the remainder of the path, name or | 2621 ** case we ignore all text in the remainder of the path, name or |
2549 ** value currently being parsed. So ignore the current character | 2622 ** value currently being parsed. So ignore the current character |
2550 ** and skip to the next "?", "=" or "&", as appropriate. */ | 2623 ** and skip to the next "?", "=" or "&", as appropriate. */ |
2551 while( (c = zUri[iIn])!=0 && c!='#' | 2624 while( (c = zUri[iIn])!=0 && c!='#' |
2552 && (eState!=0 || c!='?') | 2625 && (eState!=0 || c!='?') |
2553 && (eState!=1 || (c!='=' && c!='&')) | 2626 && (eState!=1 || (c!='=' && c!='&')) |
2554 && (eState!=2 || c!='&') | 2627 && (eState!=2 || c!='&') |
2555 ){ | 2628 ){ |
2556 iIn++; | 2629 iIn++; |
2557 } | 2630 } |
2558 continue; | 2631 continue; |
| 2632 #else |
| 2633 /* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */ |
| 2634 *pzErrMsg = sqlite3_mprintf("unexpected %%00 in uri"); |
| 2635 rc = SQLITE_ERROR; |
| 2636 goto parse_uri_out; |
| 2637 #endif |
2559 } | 2638 } |
2560 c = octet; | 2639 c = octet; |
2561 }else if( eState==1 && (c=='&' || c=='=') ){ | 2640 }else if( eState==1 && (c=='&' || c=='=') ){ |
2562 if( zFile[iOut-1]==0 ){ | 2641 if( zFile[iOut-1]==0 ){ |
2563 /* An empty option name. Ignore this option altogether. */ | 2642 /* An empty option name. Ignore this option altogether. */ |
2564 while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++; | 2643 while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++; |
2565 continue; | 2644 continue; |
2566 } | 2645 } |
2567 if( c=='&' ){ | 2646 if( c=='&' ){ |
2568 zFile[iOut++] = '\0'; | 2647 zFile[iOut++] = '\0'; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2652 } | 2731 } |
2653 flags = (flags & ~mask) | mode; | 2732 flags = (flags & ~mask) | mode; |
2654 } | 2733 } |
2655 } | 2734 } |
2656 | 2735 |
2657 zOpt = &zVal[nVal+1]; | 2736 zOpt = &zVal[nVal+1]; |
2658 } | 2737 } |
2659 | 2738 |
2660 }else{ | 2739 }else{ |
2661 zFile = sqlite3_malloc64(nUri+2); | 2740 zFile = sqlite3_malloc64(nUri+2); |
2662 if( !zFile ) return SQLITE_NOMEM; | 2741 if( !zFile ) return SQLITE_NOMEM_BKPT; |
2663 memcpy(zFile, zUri, nUri); | 2742 if( nUri ){ |
| 2743 memcpy(zFile, zUri, nUri); |
| 2744 } |
2664 zFile[nUri] = '\0'; | 2745 zFile[nUri] = '\0'; |
2665 zFile[nUri+1] = '\0'; | 2746 zFile[nUri+1] = '\0'; |
2666 flags &= ~SQLITE_OPEN_URI; | 2747 flags &= ~SQLITE_OPEN_URI; |
2667 } | 2748 } |
2668 | 2749 |
2669 *ppVfs = sqlite3_vfs_find(zVfs); | 2750 *ppVfs = sqlite3_vfs_find(zVfs); |
2670 if( *ppVfs==0 ){ | 2751 if( *ppVfs==0 ){ |
2671 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); | 2752 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); |
2672 rc = SQLITE_ERROR; | 2753 rc = SQLITE_ERROR; |
2673 } | 2754 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2809 #endif | 2890 #endif |
2810 #if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS | 2891 #if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS |
2811 | SQLITE_ForeignKeys | 2892 | SQLITE_ForeignKeys |
2812 #endif | 2893 #endif |
2813 #if defined(SQLITE_REVERSE_UNORDERED_SELECTS) | 2894 #if defined(SQLITE_REVERSE_UNORDERED_SELECTS) |
2814 | SQLITE_ReverseOrder | 2895 | SQLITE_ReverseOrder |
2815 #endif | 2896 #endif |
2816 #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK) | 2897 #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK) |
2817 | SQLITE_CellSizeCk | 2898 | SQLITE_CellSizeCk |
2818 #endif | 2899 #endif |
| 2900 #if defined(SQLITE_ENABLE_FTS3_TOKENIZER) |
| 2901 | SQLITE_Fts3Tokenizer |
| 2902 #endif |
2819 ; | 2903 ; |
2820 sqlite3HashInit(&db->aCollSeq); | 2904 sqlite3HashInit(&db->aCollSeq); |
2821 #ifndef SQLITE_OMIT_VIRTUALTABLE | 2905 #ifndef SQLITE_OMIT_VIRTUALTABLE |
2822 sqlite3HashInit(&db->aModule); | 2906 sqlite3HashInit(&db->aModule); |
2823 #endif | 2907 #endif |
2824 | 2908 |
2825 /* Add the default collation sequence BINARY. BINARY works for both UTF-8 | 2909 /* Add the default collation sequence BINARY. BINARY works for both UTF-8 |
2826 ** and UTF-16, so add a version for each to avoid any unnecessary | 2910 ** and UTF-16, so add a version for each to avoid any unnecessary |
2827 ** conversions. The only error that can occur here is a malloc() failure. | 2911 ** conversions. The only error that can occur here is a malloc() failure. |
2828 ** | 2912 ** |
(...skipping 11 matching lines...) Expand all Loading... |
2840 /* EVIDENCE-OF: R-08308-17224 The default collating function for all | 2924 /* EVIDENCE-OF: R-08308-17224 The default collating function for all |
2841 ** strings is BINARY. | 2925 ** strings is BINARY. |
2842 */ | 2926 */ |
2843 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, sqlite3StrBINARY, 0); | 2927 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, sqlite3StrBINARY, 0); |
2844 assert( db->pDfltColl!=0 ); | 2928 assert( db->pDfltColl!=0 ); |
2845 | 2929 |
2846 /* Parse the filename/URI argument. */ | 2930 /* Parse the filename/URI argument. */ |
2847 db->openFlags = flags; | 2931 db->openFlags = flags; |
2848 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); | 2932 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); |
2849 if( rc!=SQLITE_OK ){ | 2933 if( rc!=SQLITE_OK ){ |
2850 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; | 2934 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); |
2851 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg); | 2935 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg); |
2852 sqlite3_free(zErrMsg); | 2936 sqlite3_free(zErrMsg); |
2853 goto opendb_out; | 2937 goto opendb_out; |
2854 } | 2938 } |
2855 | 2939 |
2856 /* Open the backend database driver */ | 2940 /* Open the backend database driver */ |
2857 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0, | 2941 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0, |
2858 flags | SQLITE_OPEN_MAIN_DB); | 2942 flags | SQLITE_OPEN_MAIN_DB); |
2859 if( rc!=SQLITE_OK ){ | 2943 if( rc!=SQLITE_OK ){ |
2860 if( rc==SQLITE_IOERR_NOMEM ){ | 2944 if( rc==SQLITE_IOERR_NOMEM ){ |
2861 rc = SQLITE_NOMEM; | 2945 rc = SQLITE_NOMEM_BKPT; |
2862 } | 2946 } |
2863 sqlite3Error(db, rc); | 2947 sqlite3Error(db, rc); |
2864 goto opendb_out; | 2948 goto opendb_out; |
2865 } | 2949 } |
2866 sqlite3BtreeEnter(db->aDb[0].pBt); | 2950 sqlite3BtreeEnter(db->aDb[0].pBt); |
2867 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); | 2951 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt); |
2868 if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db); | 2952 if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db); |
2869 sqlite3BtreeLeave(db->aDb[0].pBt); | 2953 sqlite3BtreeLeave(db->aDb[0].pBt); |
2870 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); | 2954 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0); |
2871 | 2955 |
2872 /* The default safety_level for the main database is 'full'; for the temp | 2956 /* The default safety_level for the main database is FULL; for the temp |
2873 ** database it is 'NONE'. This matches the pager layer defaults. | 2957 ** database it is OFF. This matches the pager layer defaults. |
2874 */ | 2958 */ |
2875 db->aDb[0].zName = "main"; | 2959 db->aDb[0].zDbSName = "main"; |
2876 db->aDb[0].safety_level = 3; | 2960 db->aDb[0].safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; |
2877 db->aDb[1].zName = "temp"; | 2961 db->aDb[1].zDbSName = "temp"; |
2878 db->aDb[1].safety_level = 1; | 2962 db->aDb[1].safety_level = PAGER_SYNCHRONOUS_OFF; |
2879 | 2963 |
2880 db->magic = SQLITE_MAGIC_OPEN; | 2964 db->magic = SQLITE_MAGIC_OPEN; |
2881 if( db->mallocFailed ){ | 2965 if( db->mallocFailed ){ |
2882 goto opendb_out; | 2966 goto opendb_out; |
2883 } | 2967 } |
2884 | 2968 |
2885 /* Register all built-in functions, but do not attempt to read the | 2969 /* Register all built-in functions, but do not attempt to read the |
2886 ** database schema yet. This is delayed until the first time the database | 2970 ** database schema yet. This is delayed until the first time the database |
2887 ** is accessed. | 2971 ** is accessed. |
2888 */ | 2972 */ |
2889 sqlite3Error(db, SQLITE_OK); | 2973 sqlite3Error(db, SQLITE_OK); |
2890 sqlite3RegisterBuiltinFunctions(db); | 2974 sqlite3RegisterPerConnectionBuiltinFunctions(db); |
| 2975 rc = sqlite3_errcode(db); |
| 2976 |
| 2977 #ifdef SQLITE_ENABLE_FTS5 |
| 2978 /* Register any built-in FTS5 module before loading the automatic |
| 2979 ** extensions. This allows automatic extensions to register FTS5 |
| 2980 ** tokenizers and auxiliary functions. */ |
| 2981 if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 2982 rc = sqlite3Fts5Init(db); |
| 2983 } |
| 2984 #endif |
2891 | 2985 |
2892 /* Load automatic extensions - extensions that have been registered | 2986 /* Load automatic extensions - extensions that have been registered |
2893 ** using the sqlite3_automatic_extension() API. | 2987 ** using the sqlite3_automatic_extension() API. |
2894 */ | 2988 */ |
2895 rc = sqlite3_errcode(db); | |
2896 if( rc==SQLITE_OK ){ | 2989 if( rc==SQLITE_OK ){ |
2897 sqlite3AutoLoadExtensions(db); | 2990 sqlite3AutoLoadExtensions(db); |
2898 rc = sqlite3_errcode(db); | 2991 rc = sqlite3_errcode(db); |
2899 if( rc!=SQLITE_OK ){ | 2992 if( rc!=SQLITE_OK ){ |
2900 goto opendb_out; | 2993 goto opendb_out; |
2901 } | 2994 } |
2902 } | 2995 } |
2903 | 2996 |
2904 #ifdef SQLITE_ENABLE_FTS1 | 2997 #ifdef SQLITE_ENABLE_FTS1 |
2905 if( !db->mallocFailed ){ | 2998 if( !db->mallocFailed ){ |
2906 extern int sqlite3Fts1Init(sqlite3*); | 2999 extern int sqlite3Fts1Init(sqlite3*); |
2907 rc = sqlite3Fts1Init(db); | 3000 rc = sqlite3Fts1Init(db); |
2908 } | 3001 } |
2909 #endif | 3002 #endif |
2910 | 3003 |
2911 #ifdef SQLITE_ENABLE_FTS2 | 3004 #ifdef SQLITE_ENABLE_FTS2 |
2912 if( !db->mallocFailed && rc==SQLITE_OK ){ | 3005 if( !db->mallocFailed && rc==SQLITE_OK ){ |
2913 extern int sqlite3Fts2Init(sqlite3*); | 3006 extern int sqlite3Fts2Init(sqlite3*); |
2914 rc = sqlite3Fts2Init(db); | 3007 rc = sqlite3Fts2Init(db); |
2915 } | 3008 } |
2916 #endif | 3009 #endif |
2917 | 3010 |
2918 #ifdef SQLITE_ENABLE_FTS3 /* automatically defined by SQLITE_ENABLE_FTS4 */ | 3011 #ifdef SQLITE_ENABLE_FTS3 /* automatically defined by SQLITE_ENABLE_FTS4 */ |
2919 if( !db->mallocFailed && rc==SQLITE_OK ){ | 3012 if( !db->mallocFailed && rc==SQLITE_OK ){ |
2920 rc = sqlite3Fts3Init(db); | 3013 rc = sqlite3Fts3Init(db); |
2921 } | 3014 } |
2922 #endif | 3015 #endif |
2923 | 3016 |
2924 #ifdef SQLITE_ENABLE_FTS5 | |
2925 if( !db->mallocFailed && rc==SQLITE_OK ){ | |
2926 rc = sqlite3Fts5Init(db); | |
2927 } | |
2928 #endif | |
2929 | |
2930 #ifdef DEFAULT_ENABLE_RECOVER | 3017 #ifdef DEFAULT_ENABLE_RECOVER |
2931 /* Initialize recover virtual table for testing. */ | 3018 /* Initialize recover virtual table for testing. */ |
2932 extern int recoverVtableInit(sqlite3 *db); | 3019 extern int recoverVtableInit(sqlite3 *db); |
2933 if( !db->mallocFailed && rc==SQLITE_OK ){ | 3020 if( !db->mallocFailed && rc==SQLITE_OK ){ |
2934 rc = recoverVtableInit(db); | 3021 rc = recoverVtableInit(db); |
2935 } | 3022 } |
2936 #endif | 3023 #endif |
2937 | 3024 |
2938 #ifdef SQLITE_ENABLE_ICU | 3025 #ifdef SQLITE_ENABLE_ICU |
2939 if( !db->mallocFailed && rc==SQLITE_OK ){ | 3026 if( !db->mallocFailed && rc==SQLITE_OK ){ |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3062 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); | 3149 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); |
3063 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); | 3150 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); |
3064 if( zFilename8 ){ | 3151 if( zFilename8 ){ |
3065 rc = openDatabase(zFilename8, ppDb, | 3152 rc = openDatabase(zFilename8, ppDb, |
3066 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); | 3153 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); |
3067 assert( *ppDb || rc==SQLITE_NOMEM ); | 3154 assert( *ppDb || rc==SQLITE_NOMEM ); |
3068 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){ | 3155 if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){ |
3069 SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE; | 3156 SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE; |
3070 } | 3157 } |
3071 }else{ | 3158 }else{ |
3072 rc = SQLITE_NOMEM; | 3159 rc = SQLITE_NOMEM_BKPT; |
3073 } | 3160 } |
3074 sqlite3ValueFree(pVal); | 3161 sqlite3ValueFree(pVal); |
3075 | 3162 |
3076 return rc & 0xff; | 3163 return rc & 0xff; |
3077 } | 3164 } |
3078 #endif /* SQLITE_OMIT_UTF16 */ | 3165 #endif /* SQLITE_OMIT_UTF16 */ |
3079 | 3166 |
3080 /* | 3167 /* |
3081 ** Register a new collation sequence with the database handle db. | 3168 ** Register a new collation sequence with the database handle db. |
3082 */ | 3169 */ |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3207 if( !sqlite3SafetyCheckOk(db) ){ | 3294 if( !sqlite3SafetyCheckOk(db) ){ |
3208 (void)SQLITE_MISUSE_BKPT; | 3295 (void)SQLITE_MISUSE_BKPT; |
3209 return 0; | 3296 return 0; |
3210 } | 3297 } |
3211 #endif | 3298 #endif |
3212 return db->autoCommit; | 3299 return db->autoCommit; |
3213 } | 3300 } |
3214 | 3301 |
3215 /* | 3302 /* |
3216 ** The following routines are substitutes for constants SQLITE_CORRUPT, | 3303 ** The following routines are substitutes for constants SQLITE_CORRUPT, |
3217 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error | 3304 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error |
3218 ** constants. They serve two purposes: | 3305 ** constants. They serve two purposes: |
3219 ** | 3306 ** |
3220 ** 1. Serve as a convenient place to set a breakpoint in a debugger | 3307 ** 1. Serve as a convenient place to set a breakpoint in a debugger |
3221 ** to detect when version error conditions occurs. | 3308 ** to detect when version error conditions occurs. |
3222 ** | 3309 ** |
3223 ** 2. Invoke sqlite3_log() to provide the source code location where | 3310 ** 2. Invoke sqlite3_log() to provide the source code location where |
3224 ** a low-level error is first detected. | 3311 ** a low-level error is first detected. |
3225 */ | 3312 */ |
| 3313 static int reportError(int iErr, int lineno, const char *zType){ |
| 3314 sqlite3_log(iErr, "%s at line %d of [%.10s]", |
| 3315 zType, lineno, 20+sqlite3_sourceid()); |
| 3316 return iErr; |
| 3317 } |
3226 int sqlite3CorruptError(int lineno){ | 3318 int sqlite3CorruptError(int lineno){ |
3227 testcase( sqlite3GlobalConfig.xLog!=0 ); | 3319 testcase( sqlite3GlobalConfig.xLog!=0 ); |
3228 sqlite3_log(SQLITE_CORRUPT, | 3320 return reportError(SQLITE_CORRUPT, lineno, "database corruption"); |
3229 "database corruption at line %d of [%.10s]", | |
3230 lineno, 20+sqlite3_sourceid()); | |
3231 return SQLITE_CORRUPT; | |
3232 } | 3321 } |
3233 int sqlite3MisuseError(int lineno){ | 3322 int sqlite3MisuseError(int lineno){ |
3234 testcase( sqlite3GlobalConfig.xLog!=0 ); | 3323 testcase( sqlite3GlobalConfig.xLog!=0 ); |
3235 sqlite3_log(SQLITE_MISUSE, | 3324 return reportError(SQLITE_MISUSE, lineno, "misuse"); |
3236 "misuse at line %d of [%.10s]", | |
3237 lineno, 20+sqlite3_sourceid()); | |
3238 return SQLITE_MISUSE; | |
3239 } | 3325 } |
3240 int sqlite3CantopenError(int lineno){ | 3326 int sqlite3CantopenError(int lineno){ |
3241 testcase( sqlite3GlobalConfig.xLog!=0 ); | 3327 testcase( sqlite3GlobalConfig.xLog!=0 ); |
3242 sqlite3_log(SQLITE_CANTOPEN, | 3328 return reportError(SQLITE_CANTOPEN, lineno, "cannot open file"); |
3243 "cannot open file at line %d of [%.10s]", | |
3244 lineno, 20+sqlite3_sourceid()); | |
3245 return SQLITE_CANTOPEN; | |
3246 } | 3329 } |
3247 | 3330 #ifdef SQLITE_DEBUG |
| 3331 int sqlite3NomemError(int lineno){ |
| 3332 testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 3333 return reportError(SQLITE_NOMEM, lineno, "OOM"); |
| 3334 } |
| 3335 int sqlite3IoerrnomemError(int lineno){ |
| 3336 testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 3337 return reportError(SQLITE_IOERR_NOMEM, lineno, "I/O OOM error"); |
| 3338 } |
| 3339 #endif |
3248 | 3340 |
3249 #ifndef SQLITE_OMIT_DEPRECATED | 3341 #ifndef SQLITE_OMIT_DEPRECATED |
3250 /* | 3342 /* |
3251 ** This is a convenience routine that makes sure that all thread-specific | 3343 ** This is a convenience routine that makes sure that all thread-specific |
3252 ** data for this thread has been deallocated. | 3344 ** data for this thread has been deallocated. |
3253 ** | 3345 ** |
3254 ** SQLite no longer uses thread-specific data so this routine is now a | 3346 ** SQLite no longer uses thread-specific data so this routine is now a |
3255 ** no-op. It is retained for historical compatibility. | 3347 ** no-op. It is retained for historical compatibility. |
3256 */ | 3348 */ |
3257 void sqlite3_thread_cleanup(void){ | 3349 void sqlite3_thread_cleanup(void){ |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3331 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey | 3423 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey |
3332 ** and autoinc. At this point there are two possibilities: | 3424 ** and autoinc. At this point there are two possibilities: |
3333 ** | 3425 ** |
3334 ** 1. The specified column name was rowid", "oid" or "_rowid_" | 3426 ** 1. The specified column name was rowid", "oid" or "_rowid_" |
3335 ** and there is no explicitly declared IPK column. | 3427 ** and there is no explicitly declared IPK column. |
3336 ** | 3428 ** |
3337 ** 2. The table is not a view and the column name identified an | 3429 ** 2. The table is not a view and the column name identified an |
3338 ** explicitly declared column. Copy meta information from *pCol. | 3430 ** explicitly declared column. Copy meta information from *pCol. |
3339 */ | 3431 */ |
3340 if( pCol ){ | 3432 if( pCol ){ |
3341 zDataType = pCol->zType; | 3433 zDataType = sqlite3ColumnType(pCol,0); |
3342 zCollSeq = pCol->zColl; | 3434 zCollSeq = pCol->zColl; |
3343 notnull = pCol->notNull!=0; | 3435 notnull = pCol->notNull!=0; |
3344 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0; | 3436 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0; |
3345 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0; | 3437 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0; |
3346 }else{ | 3438 }else{ |
3347 zDataType = "INTEGER"; | 3439 zDataType = "INTEGER"; |
3348 primarykey = 1; | 3440 primarykey = 1; |
3349 } | 3441 } |
3350 if( !zCollSeq ){ | 3442 if( !zCollSeq ){ |
3351 zCollSeq = sqlite3StrBINARY; | 3443 zCollSeq = sqlite3StrBINARY; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3444 } | 3536 } |
3445 sqlite3_mutex_leave(db->mutex); | 3537 sqlite3_mutex_leave(db->mutex); |
3446 return rc; | 3538 return rc; |
3447 } | 3539 } |
3448 | 3540 |
3449 /* | 3541 /* |
3450 ** Interface to the testing logic. | 3542 ** Interface to the testing logic. |
3451 */ | 3543 */ |
3452 int sqlite3_test_control(int op, ...){ | 3544 int sqlite3_test_control(int op, ...){ |
3453 int rc = 0; | 3545 int rc = 0; |
3454 #ifdef SQLITE_OMIT_BUILTIN_TEST | 3546 #ifdef SQLITE_UNTESTABLE |
3455 UNUSED_PARAMETER(op); | 3547 UNUSED_PARAMETER(op); |
3456 #else | 3548 #else |
3457 va_list ap; | 3549 va_list ap; |
3458 va_start(ap, op); | 3550 va_start(ap, op); |
3459 switch( op ){ | 3551 switch( op ){ |
3460 | 3552 |
3461 /* | 3553 /* |
3462 ** Save the current state of the PRNG. | 3554 ** Save the current state of the PRNG. |
3463 */ | 3555 */ |
3464 case SQLITE_TESTCTRL_PRNG_SAVE: { | 3556 case SQLITE_TESTCTRL_PRNG_SAVE: { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3568 ** This action provides a run-time test to see whether or not | 3660 ** This action provides a run-time test to see whether or not |
3569 ** assert() was enabled at compile-time. If X is true and assert() | 3661 ** assert() was enabled at compile-time. If X is true and assert() |
3570 ** is enabled, then the return value is true. If X is true and | 3662 ** is enabled, then the return value is true. If X is true and |
3571 ** assert() is disabled, then the return value is zero. If X is | 3663 ** assert() is disabled, then the return value is zero. If X is |
3572 ** false and assert() is enabled, then the assertion fires and the | 3664 ** false and assert() is enabled, then the assertion fires and the |
3573 ** process aborts. If X is false and assert() is disabled, then the | 3665 ** process aborts. If X is false and assert() is disabled, then the |
3574 ** return value is zero. | 3666 ** return value is zero. |
3575 */ | 3667 */ |
3576 case SQLITE_TESTCTRL_ASSERT: { | 3668 case SQLITE_TESTCTRL_ASSERT: { |
3577 volatile int x = 0; | 3669 volatile int x = 0; |
3578 assert( (x = va_arg(ap,int))!=0 ); | 3670 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 ); |
3579 rc = x; | 3671 rc = x; |
3580 break; | 3672 break; |
3581 } | 3673 } |
3582 | 3674 |
3583 | 3675 |
3584 /* | 3676 /* |
3585 ** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X) | 3677 ** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X) |
3586 ** | 3678 ** |
3587 ** This action provides a run-time test to see how the ALWAYS and | 3679 ** This action provides a run-time test to see how the ALWAYS and |
3588 ** NEVER macros were defined at compile-time. | 3680 ** NEVER macros were defined at compile-time. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3710 ** formed and never corrupt. This flag is clear by default, indicating that | 3802 ** formed and never corrupt. This flag is clear by default, indicating that |
3711 ** database files might have arbitrary corruption. Setting the flag during | 3803 ** database files might have arbitrary corruption. Setting the flag during |
3712 ** testing causes certain assert() statements in the code to be activated | 3804 ** testing causes certain assert() statements in the code to be activated |
3713 ** that demonstrat invariants on well-formed database files. | 3805 ** that demonstrat invariants on well-formed database files. |
3714 */ | 3806 */ |
3715 case SQLITE_TESTCTRL_NEVER_CORRUPT: { | 3807 case SQLITE_TESTCTRL_NEVER_CORRUPT: { |
3716 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int); | 3808 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int); |
3717 break; | 3809 break; |
3718 } | 3810 } |
3719 | 3811 |
| 3812 /* Set the threshold at which OP_Once counters reset back to zero. |
| 3813 ** By default this is 0x7ffffffe (over 2 billion), but that value is |
| 3814 ** too big to test in a reasonable amount of time, so this control is |
| 3815 ** provided to set a small and easily reachable reset value. |
| 3816 */ |
| 3817 case SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD: { |
| 3818 sqlite3GlobalConfig.iOnceResetThreshold = va_arg(ap, int); |
| 3819 break; |
| 3820 } |
3720 | 3821 |
3721 /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr); | 3822 /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr); |
3722 ** | 3823 ** |
3723 ** Set the VDBE coverage callback function to xCallback with context | 3824 ** Set the VDBE coverage callback function to xCallback with context |
3724 ** pointer ptr. | 3825 ** pointer ptr. |
3725 */ | 3826 */ |
3726 case SQLITE_TESTCTRL_VDBE_COVERAGE: { | 3827 case SQLITE_TESTCTRL_VDBE_COVERAGE: { |
3727 #ifdef SQLITE_VDBE_COVERAGE | 3828 #ifdef SQLITE_VDBE_COVERAGE |
3728 typedef void (*branch_callback)(void*,int,u8,u8); | 3829 typedef void (*branch_callback)(void*,int,u8,u8); |
3729 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback); | 3830 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3772 db->init.busy = db->init.imposterTable = va_arg(ap,int); | 3873 db->init.busy = db->init.imposterTable = va_arg(ap,int); |
3773 db->init.newTnum = va_arg(ap,int); | 3874 db->init.newTnum = va_arg(ap,int); |
3774 if( db->init.busy==0 && db->init.newTnum>0 ){ | 3875 if( db->init.busy==0 && db->init.newTnum>0 ){ |
3775 sqlite3ResetAllSchemasOfConnection(db); | 3876 sqlite3ResetAllSchemasOfConnection(db); |
3776 } | 3877 } |
3777 sqlite3_mutex_leave(db->mutex); | 3878 sqlite3_mutex_leave(db->mutex); |
3778 break; | 3879 break; |
3779 } | 3880 } |
3780 } | 3881 } |
3781 va_end(ap); | 3882 va_end(ap); |
3782 #endif /* SQLITE_OMIT_BUILTIN_TEST */ | 3883 #endif /* SQLITE_UNTESTABLE */ |
3783 return rc; | 3884 return rc; |
3784 } | 3885 } |
3785 | 3886 |
3786 /* | 3887 /* |
3787 ** This is a utility routine, useful to VFS implementations, that checks | 3888 ** This is a utility routine, useful to VFS implementations, that checks |
3788 ** to see if a database file was a URI that contained a specific query | 3889 ** to see if a database file was a URI that contained a specific query |
3789 ** parameter, and if so obtains the value of the query parameter. | 3890 ** parameter, and if so obtains the value of the query parameter. |
3790 ** | 3891 ** |
3791 ** The zFilename argument is the filename pointer passed into the xOpen() | 3892 ** The zFilename argument is the filename pointer passed into the xOpen() |
3792 ** method of a VFS implementation. The zParam argument is the name of the | 3893 ** method of a VFS implementation. The zParam argument is the name of the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3828 if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){ | 3929 if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){ |
3829 bDflt = v; | 3930 bDflt = v; |
3830 } | 3931 } |
3831 return bDflt; | 3932 return bDflt; |
3832 } | 3933 } |
3833 | 3934 |
3834 /* | 3935 /* |
3835 ** Return the Btree pointer identified by zDbName. Return NULL if not found. | 3936 ** Return the Btree pointer identified by zDbName. Return NULL if not found. |
3836 */ | 3937 */ |
3837 Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){ | 3938 Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){ |
3838 int i; | 3939 int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0; |
3839 for(i=0; i<db->nDb; i++){ | 3940 return iDb<0 ? 0 : db->aDb[iDb].pBt; |
3840 if( db->aDb[i].pBt | |
3841 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0) | |
3842 ){ | |
3843 return db->aDb[i].pBt; | |
3844 } | |
3845 } | |
3846 return 0; | |
3847 } | 3941 } |
3848 | 3942 |
3849 /* | 3943 /* |
3850 ** Return the filename of the database associated with a database | 3944 ** Return the filename of the database associated with a database |
3851 ** connection. | 3945 ** connection. |
3852 */ | 3946 */ |
3853 const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ | 3947 const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){ |
3854 Btree *pBt; | 3948 Btree *pBt; |
3855 #ifdef SQLITE_ENABLE_API_ARMOR | 3949 #ifdef SQLITE_ENABLE_API_ARMOR |
3856 if( !sqlite3SafetyCheckOk(db) ){ | 3950 if( !sqlite3SafetyCheckOk(db) ){ |
(...skipping 26 matching lines...) Expand all Loading... |
3883 ** Obtain a snapshot handle for the snapshot of database zDb currently | 3977 ** Obtain a snapshot handle for the snapshot of database zDb currently |
3884 ** being read by handle db. | 3978 ** being read by handle db. |
3885 */ | 3979 */ |
3886 int sqlite3_snapshot_get( | 3980 int sqlite3_snapshot_get( |
3887 sqlite3 *db, | 3981 sqlite3 *db, |
3888 const char *zDb, | 3982 const char *zDb, |
3889 sqlite3_snapshot **ppSnapshot | 3983 sqlite3_snapshot **ppSnapshot |
3890 ){ | 3984 ){ |
3891 int rc = SQLITE_ERROR; | 3985 int rc = SQLITE_ERROR; |
3892 #ifndef SQLITE_OMIT_WAL | 3986 #ifndef SQLITE_OMIT_WAL |
3893 int iDb; | |
3894 | 3987 |
3895 #ifdef SQLITE_ENABLE_API_ARMOR | 3988 #ifdef SQLITE_ENABLE_API_ARMOR |
3896 if( !sqlite3SafetyCheckOk(db) ){ | 3989 if( !sqlite3SafetyCheckOk(db) ){ |
3897 return SQLITE_MISUSE_BKPT; | 3990 return SQLITE_MISUSE_BKPT; |
3898 } | 3991 } |
3899 #endif | 3992 #endif |
3900 sqlite3_mutex_enter(db->mutex); | 3993 sqlite3_mutex_enter(db->mutex); |
3901 | 3994 |
3902 iDb = sqlite3FindDbName(db, zDb); | 3995 if( db->autoCommit==0 ){ |
3903 if( iDb==0 || iDb>1 ){ | 3996 int iDb = sqlite3FindDbName(db, zDb); |
3904 Btree *pBt = db->aDb[iDb].pBt; | 3997 if( iDb==0 || iDb>1 ){ |
3905 if( 0==sqlite3BtreeIsInTrans(pBt) ){ | 3998 Btree *pBt = db->aDb[iDb].pBt; |
3906 rc = sqlite3BtreeBeginTrans(pBt, 0); | 3999 if( 0==sqlite3BtreeIsInTrans(pBt) ){ |
3907 if( rc==SQLITE_OK ){ | 4000 rc = sqlite3BtreeBeginTrans(pBt, 0); |
3908 rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot); | 4001 if( rc==SQLITE_OK ){ |
| 4002 rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot); |
| 4003 } |
3909 } | 4004 } |
3910 } | 4005 } |
3911 } | 4006 } |
3912 | 4007 |
3913 sqlite3_mutex_leave(db->mutex); | 4008 sqlite3_mutex_leave(db->mutex); |
3914 #endif /* SQLITE_OMIT_WAL */ | 4009 #endif /* SQLITE_OMIT_WAL */ |
3915 return rc; | 4010 return rc; |
3916 } | 4011 } |
3917 | 4012 |
3918 /* | 4013 /* |
(...skipping 27 matching lines...) Expand all Loading... |
3946 } | 4041 } |
3947 } | 4042 } |
3948 } | 4043 } |
3949 | 4044 |
3950 sqlite3_mutex_leave(db->mutex); | 4045 sqlite3_mutex_leave(db->mutex); |
3951 #endif /* SQLITE_OMIT_WAL */ | 4046 #endif /* SQLITE_OMIT_WAL */ |
3952 return rc; | 4047 return rc; |
3953 } | 4048 } |
3954 | 4049 |
3955 /* | 4050 /* |
| 4051 ** Recover as many snapshots as possible from the wal file associated with |
| 4052 ** schema zDb of database db. |
| 4053 */ |
| 4054 int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){ |
| 4055 int rc = SQLITE_ERROR; |
| 4056 int iDb; |
| 4057 #ifndef SQLITE_OMIT_WAL |
| 4058 |
| 4059 #ifdef SQLITE_ENABLE_API_ARMOR |
| 4060 if( !sqlite3SafetyCheckOk(db) ){ |
| 4061 return SQLITE_MISUSE_BKPT; |
| 4062 } |
| 4063 #endif |
| 4064 |
| 4065 sqlite3_mutex_enter(db->mutex); |
| 4066 iDb = sqlite3FindDbName(db, zDb); |
| 4067 if( iDb==0 || iDb>1 ){ |
| 4068 Btree *pBt = db->aDb[iDb].pBt; |
| 4069 if( 0==sqlite3BtreeIsInReadTrans(pBt) ){ |
| 4070 rc = sqlite3BtreeBeginTrans(pBt, 0); |
| 4071 if( rc==SQLITE_OK ){ |
| 4072 rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt)); |
| 4073 sqlite3BtreeCommit(pBt); |
| 4074 } |
| 4075 } |
| 4076 } |
| 4077 sqlite3_mutex_leave(db->mutex); |
| 4078 #endif /* SQLITE_OMIT_WAL */ |
| 4079 return rc; |
| 4080 } |
| 4081 |
| 4082 /* |
3956 ** Free a snapshot handle obtained from sqlite3_snapshot_get(). | 4083 ** Free a snapshot handle obtained from sqlite3_snapshot_get(). |
3957 */ | 4084 */ |
3958 void sqlite3_snapshot_free(sqlite3_snapshot *pSnapshot){ | 4085 void sqlite3_snapshot_free(sqlite3_snapshot *pSnapshot){ |
3959 sqlite3_free(pSnapshot); | 4086 sqlite3_free(pSnapshot); |
3960 } | 4087 } |
3961 #endif /* SQLITE_ENABLE_SNAPSHOT */ | 4088 #endif /* SQLITE_ENABLE_SNAPSHOT */ |
OLD | NEW |