Lines Matching refs:Db
2479 sqlite3 *db, /* An open database */
2547 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2575 ** sqlite3_exec(db, zSQL, 0, 0, 0);
3146 ** <tr><td> file:data.db <td>
3147 ** Open the file "data.db" in the current directory.
3148 ** <tr><td> file:/home/fred/data.db<br>
3149 ** file:///home/fred/data.db <br>
3150 ** file://localhost/home/fred/data.db <br> <td>
3151 ** Open the database file "/home/fred/data.db".
3152 ** <tr><td> file://darkstar/home/fred/data.db <td>
3155 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3156 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3160 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3161 ** Open file "data.db" in the current directory for read-only access.
3164 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3165 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3167 ** <tr><td> file:data.db?mode=readonly <td>
3194 sqlite3 **ppDb /* OUT: SQLite db handle */
3198 sqlite3 **ppDb /* OUT: SQLite db handle */
3202 sqlite3 **ppDb, /* OUT: SQLite db handle */
3292 SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
3293 SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
3444 ** The first argument, "db", is a [database connection] obtained from a
3517 sqlite3 *db, /* Database handle */
3524 sqlite3 *db, /* Database handle */
3531 sqlite3 *db, /* Database handle */
3538 sqlite3 *db, /* Database handle */
4443 sqlite3 *db,
4453 sqlite3 *db,
4463 sqlite3 *db,
5056 sqlite3 *db, /* Database to be rekeyed */
5060 sqlite3 *db, /* Database to be rekeyed */
5074 sqlite3 *db, /* Database to be rekeyed */
5078 sqlite3 *db, /* Database to be rekeyed */
5268 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5278 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5599 sqlite3 *db, /* Connection handle */
5646 sqlite3 *db, /* Load the extension into this database connection */
5666 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5683 ** sqlite3 *db,
5954 sqlite3 *db, /* SQLite connection to register module with */
5960 sqlite3 *db, /* SQLite connection to register module with */
7679 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7701 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7772 ** [database connection] db. In this case the
7796 sqlite3 *db, /* Database handle */
7843 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
8061 sqlite3 *db,
8087 sqlite3 *db,
9944 typedef struct Db Db;
10038 sqlite3 *db, /* Associated database connection */
10051 #define BTREE_MEMORY 2 /* This is an in-memory DB */
11528 struct Db {
11568 ** Db.pSchema->flags field.
11576 ** Allowed values for the DB.pSchema->flags field.
11687 Db *aDb; /* All backends */
11713 u8 iDb; /* Which db file is being initialized */
11767 Db aDbStatic[2]; /* Static space for the 2 default backends */
11800 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
11801 #define ENC(db) ((db)->enc)
11863 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
11864 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
11866 #define OptimizationDisabled(db, mask) 0
11867 #define OptimizationEnabled(db, mask) 1
12167 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
12171 sqlite3 *db; /* Database connection associated with this table */
12352 sqlite3 *db; /* The database connection */
12431 int tnum; /* DB Page containing root of this index */
12754 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
13206 sqlite3 *db; /* The main database structure */
13298 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
13331 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
13333 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
13454 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
13470 sqlite3 *db; /* The database being initialized */
14225 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
14238 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
14293 # define sqlite3VtabInSync(db) 0
14300 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
14301 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
14302 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*);
14303 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
14304 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
14311 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
14441 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
14442 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
15320 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
15398 int nDbChange; /* Value of db->nChange */
15431 sqlite3 *db; /* The associated database connection */
15576 sqlite3 *db; /* The database connection that owns this statement */
15588 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
15612 int nChange; /* Number of db changes made since last reset */
15613 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
15912 sqlite3 *db, /* The database connection whose status is desired */
15920 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
15924 sqlite3_mutex_enter(db->mutex);
15927 *pCurrent = db->lookaside.nOut;
15928 *pHighwater = db->lookaside.mxOut;
15930 db->lookaside.mxOut = db->lookaside.nOut;
15944 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
15946 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
15959 sqlite3BtreeEnterAll(db);
15960 for(i=0; i<db->nDb; i++){
15961 Btree *pBt = db->aDb[i].pBt;
15967 sqlite3BtreeLeaveAll(db);
15982 sqlite3BtreeEnterAll(db);
15983 db->pnBytesFreed = &nByte;
15984 for(i=0; i<db->nDb; i++){
15985 Schema *pSchema = db->aDb[i].pSchema;
16001 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
16004 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
16008 db->pnBytesFreed = 0;
16009 sqlite3BtreeLeaveAll(db);
16025 db->pnBytesFreed = &nByte;
16026 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
16027 sqlite3VdbeClearObject(db, pVdbe);
16028 sqlite3DbFree(db, pVdbe);
16030 db->pnBytesFreed = 0;
16051 for(i=0; i<db->nDb; i++){
16052 if( db->aDb[i].pBt ){
16053 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
16070 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
16078 sqlite3_mutex_leave(db->mutex);
16980 sqlite3 *db;
16986 db = sqlite3_context_db_handle(context);
17022 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
17023 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
17026 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
17030 z = sqlite3DbMallocRaw(db, (int)n);
17166 sqlite3 *db;
21738 ** TRUE if p is a lookaside memory allocation from db
21741 static int isLookaside(sqlite3 *db, void *p){
21742 return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
21756 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
21757 if( db==0 || !isLookaside(db,p) ){
21759 if( db==0 ){
21769 assert( sqlite3_mutex_held(db->mutex) );
21770 return db->lookaside.sz;
21799 ** *db->pnBytesFreed.
21801 static SQLITE_NOINLINE void measureAllocationSize(sqlite3 *db, void *p){
21802 *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
21809 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
21810 assert( db==0 || sqlite3_mutex_held(db->mutex) );
21812 if( db ){
21813 if( db->pnBytesFreed ){
21814 measureAllocationSize(db, p);
21817 if( isLookaside(db, p) ){
21821 memset(p, 0xaa, db->lookaside.sz);
21823 pBuf->pNext = db->lookaside.pFree;
21824 db->lookaside.pFree = pBuf;
21825 db->lookaside.nOut--;
21831 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
21921 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, u64 n){
21922 void *p = sqlite3DbMallocRaw(db, n);
21933 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
21940 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
21941 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
21947 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){
21949 assert( db==0 || sqlite3_mutex_held(db->mutex) );
21950 assert( db==0 || db->pnBytesFreed==0 );
21952 if( db ){
21954 if( db->mallocFailed ){
21957 if( db->lookaside.bEnabled ){
21958 if( n>db->lookaside.sz ){
21959 db->lookaside.anStat[1]++;
21960 }else if( (pBuf = db->lookaside.pFree)==0 ){
21961 db->lookaside.anStat[2]++;
21963 db->lookaside.pFree = pBuf->pNext;
21964 db->lookaside.nOut++;
21965 db->lookaside.anStat[0]++;
21966 if( db->lookaside.nOut>db->lookaside.mxOut ){
21967 db->lookaside.mxOut = db->lookaside.nOut;
21974 if( db && db->mallocFailed ){
21979 if( !p && db ){
21980 db->mallocFailed = 1;
21983 (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
21991 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
21993 assert( db!=0 );
21994 assert( sqlite3_mutex_held(db->mutex) );
21995 if( db->mallocFailed==0 ){
21997 return sqlite3DbMallocRaw(db, n);
21999 if( isLookaside(db, p) ){
22000 if( n<=db->lookaside.sz ){
22003 pNew = sqlite3DbMallocRaw(db, n);
22005 memcpy(pNew, p, db->lookaside.sz);
22006 sqlite3DbFree(db, p);
22014 db->mallocFailed = 1;
22017 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
22027 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){
22029 pNew = sqlite3DbRealloc(db, p, n);
22031 sqlite3DbFree(db, p);
22043 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
22051 zNew = sqlite3DbMallocRaw(db, (int)n);
22057 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
22063 zNew = sqlite3DbMallocRaw(db, n+1);
22074 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
22075 sqlite3DbFree(db, *pz);
22076 *pz = sqlite3DbStrDup(db, zNew);
22082 static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
22083 db->mallocFailed = 0;
22084 sqlite3Error(db, SQLITE_NOMEM);
22100 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
22101 /* If the db handle must hold the connection handle mutex here.
22102 ** Otherwise the read (and possible write) of db->mallocFailed
22105 assert( db!=0 );
22106 assert( sqlite3_mutex_held(db->mutex) );
22107 if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
22108 return apiOomError(db);
22110 return rc & db->errMask;
22884 if( p->db ){
22885 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22893 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
22965 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22981 sqlite3DbFree(p->db, p->zText);
22990 ** db: Pointer to a database connection. May be NULL. Lookaside
22991 ** memory is used if not NULL. db->mallocFailed is set appropriately
23000 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
23002 p->db = db;
23013 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
23017 assert( db!=0 );
23018 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
23019 db->aLimit[SQLITE_LIMIT_LENGTH]);
23023 db->mallocFailed = 1;
23032 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
23036 z = sqlite3VMPrintf(db, zFormat, ap);
24255 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
24319 zOut = sqlite3DbMallocRaw(pMem->db, len);
24368 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
24482 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
24485 m.db = db;
24488 if( db->mallocFailed ){
24492 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
24493 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
24494 assert( m.z || db->mallocFailed );
24693 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code){
24694 assert( db!=0 );
24695 db->errCode = err_code;
24696 if( db->pErr ) sqlite3ValueSetNull(db->pErr);
24701 ** handle "db". The error code is set to "err_code".
24716 ** To clear the most recent error for sqlite handle "db", sqlite3Error
24720 SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3 *db, int err_code, const char *zFormat, ...){
24721 assert( db!=0 );
24722 db->errCode = err_code;
24724 sqlite3Error(db, err_code);
24725 }else if( db->pErr || (db->pErr = sqlite3ValueNew(db))!=0 ){
24729 z = sqlite3VMPrintf(db, zFormat, ap);
24731 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
24755 sqlite3 *db = pParse->db;
24757 zMsg = sqlite3VMPrintf(db, zFormat, ap);
24759 if( db->suppressErr ){
24760 sqlite3DbFree(db, zMsg);
24763 sqlite3DbFree(db, pParse->zErrMsg);
25717 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
25721 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
25746 ** Check to make sure we have a valid db pointer. This test is not
25748 ** misuse of the interface such as passing in db pointers that are
25750 ** 1 it means that the db pointer is valid and 0 if it should not be
25754 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
25755 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
25759 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
25761 if( db==0 ){
25765 magic = db->magic;
25767 if( sqlite3SafetyCheckSickOrOk(db) ){
25776 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
25778 magic = db->magic;
25879 ** test.db-journal => test.nal
25880 ** test.db-wal => test.wal
25881 ** test.db-shm => test.shm
25882 ** test.db-mj7f3319fa => test.9fa
28002 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
30875 ** is "/home/user1/config.db" then the file that is created and mmapped
30876 ** for shared memory will be called "/home/user1/config.db-shm".
31401 int h = pFd->h; /* File descriptor open on db file */
31947 ** proxyLock activation is possible (remote proxy is based on db name)
32254 ** "<path to db>-journal"
32255 ** "<path to db>-wal"
32256 ** "<path to db>-journalNN"
32257 ** "<path to db>-walNN"
32366 /* The main DB, main journal, WAL file and master journal are never
32959 ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE,
32961 ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE,
32977 ** For database path "/Users/me/foo.db"
32978 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
33112 /* transform the db path to a unique cache name */
33770 /* afp style keeps a reference to the db path in the filePath field
33783 /* all other styles use the locking context to store the db file path */
39067 /* The main DB, main journal, WAL file and master journal are never
42483 sqlite3 *db; /* The database connection */
42501 ** are available at pSpace. The db pointer is used as a memory context
42511 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
42516 p->db = db;
42536 sqlite3DbFree(p->db, pChunk);
42551 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
42558 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
43013 int sync_flags, /* Flags to sync db file with (or 0) */
43040 ** stored in each frame (i.e. the db page-size when the WAL was created).
43311 ** db size etc.) are consistent with the contents of the file-system.
43749 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
43750 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
44949 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
45433 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
46201 i64 n = 0; /* Size of db file in bytes */
46238 ** function. Because an EXCLUSIVE lock on the db file is required to delete
47637 ROUND8(pVfs->szOsFile) + /* The main db file */
48181 ** possibility by unmapping the db here. */
48295 ** flag was specified by the caller. And so long as the db is not a
49146 int noSync /* True to omit the xSync on the db file */
49167 /* If this is an in-memory db, or no pages have been written to, or this
49226 /* Update the db file change counter via the direct-write method. The
49275 ** last page in the db image moved to the free-list. In this case the
50683 u32 nBackfill; /* Number of WAL frames backfilled into DB */
50991 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
51018 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
52092 ** about the eventual size of the db file to the VFS layer.
52103 /* Iterate through the contents of the WAL, copying data to the db file */
53305 int sync_flags, /* Flags to sync db file with (or 0) */
53873 sqlite3 *db; /* The database connection holding this btree */
53876 u8 sharable; /* True if we can share pBt with another db */
53877 u8 locked; /* True if db currently has pBt locked */
53882 Btree *pNext; /* List of other sharable Btrees from the same db */
53937 sqlite3 *db; /* Database connection currently using this Btree */
53944 u8 bDoTruncate; /* True to truncate db on commit */
54018 ** particular database connection identified BtCursor.pBtree.db.
54198 u8 *aPgRef; /* 1 bit per page in the db (see above) */
54241 ** set BtShared.db to the database handle associated with p and the
54247 assert( sqlite3_mutex_held(p->db->mutex) );
54250 p->pBt->db = p->db;
54262 assert( sqlite3_mutex_held(p->db->mutex) );
54263 assert( p->db==pBt->db );
54295 assert( p->pNext==0 || p->pNext->db==p->db );
54296 assert( p->pPrev==0 || p->pPrev->db==p->db );
54304 assert( sqlite3_mutex_held(p->db->mutex) );
54306 /* Unless the database is sharable and unlocked, then BtShared.db
54308 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
54330 p->pBt->db = p->db;
54361 assert( sqlite3_mutex_held(p->db->mutex) );
54380 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
54382 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
54418 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
54421 assert( sqlite3_mutex_held(db->mutex) );
54422 for(i=0; i<db->nDb; i++){
54423 p = db->aDb[i].pBt;
54427 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
54430 assert( sqlite3_mutex_held(db->mutex) );
54431 for(i=0; i<db->nDb; i++){
54432 p = db->aDb[i].pBt;
54452 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
54454 if( !sqlite3_mutex_held(db->mutex) ){
54457 for(i=0; i<db->nDb; i++){
54459 p = db->aDb[i].pBt;
54472 ** db->aDb[iDb].pSchema structure. The mutexes required for schema
54475 ** (1) The mutex on db
54476 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
54479 ** db using sqlite3SchemaToIndex().
54481 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
54483 assert( db!=0 );
54484 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
54485 assert( iDb>=0 && iDb<db->nDb );
54486 if( !sqlite3_mutex_held(db->mutex) ) return 0;
54488 p = db->aDb[iDb].pBt;
54506 p->pBt->db = p->db;
54508 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
54510 for(i=0; i<db->nDb; i++){
54511 Btree *p = db->aDb[i].pBt;
54513 p->pBt->db = p->db;
54676 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
54753 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
54774 assert( p->db!=0 );
54775 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
54793 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
54810 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
54847 assert( p->db!=0 );
54853 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
55287 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
55295 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
56238 assert( pPage->pBt->db!=0 );
56298 if( pBt->db->flags & SQLITE_CellSizeCk ){
56610 assert( pBt->db );
56611 assert( sqlite3_mutex_held(pBt->db->mutex) );
56612 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
56639 sqlite3 *db, /* Associated database handle */
56661 || (isTempDb && sqlite3TempInMemory(db))
56665 assert( db!=0 );
56667 assert( sqlite3_mutex_held(db->mutex) );
56687 p->db = db;
56732 for(iDb=db->nDb-1; iDb>=0; iDb--){
56733 Btree *pExisting = db->aDb[iDb].pBt;
56782 sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
56789 pBt->db = db;
56846 db->mallocFailed = 0;
56866 for(i=0; i<db->nDb; i++){
56867 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
57005 assert( sqlite3_mutex_held(p->db->mutex) );
57072 assert( sqlite3_mutex_held(p->db->mutex) );
57086 assert( sqlite3_mutex_held(p->db->mutex) );
57108 assert( sqlite3_mutex_held(p->db->mutex) );
57123 assert( sqlite3_mutex_held(p->db->mutex) );
57429 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
57648 pBlock = pBt->pWriter->db;
57653 pBlock = pIter->pBtree->db;
57659 sqlite3ConnectionBlocked(p->db, pBlock);
57687 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
57725 /* If the db-size header field is incorrect (as it may be if an old
57747 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
58239 sqlite3 *db = p->db;
58245 if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){
58487 assert( iStatement>p->db->nSavepoint );
59039 assert( pCur->pBtree->db==pBt->db );
59191 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59450 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59473 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59549 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59602 ** would have already detected db corruption. Similarly, pPage must
59710 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
63033 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
63800 int savedDbFlags = pBt->db->flags;
63846 testcase( pBt->db->flags & SQLITE_CellSizeCk );
63847 pBt->db->flags &= ~SQLITE_CellSizeCk;
63858 pBt->db->flags = savedDbFlags;
63929 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
63963 assert( sqlite3_mutex_held(p->db->mutex) );
63969 assert( sqlite3_mutex_held(p->db->mutex) );
64011 assert( sqlite3_mutex_held(p->db->mutex) );
64059 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
64270 pParse->db = pDb;
64306 ** message in database handle db.
64308 static int checkReadTransaction(sqlite3 *db, Btree *p){
64310 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
64552 int nSrcPage = -1; /* Size of source db in pages */
64553 int bCloseTrans = 0; /* True if src db requires unlocking */
64944 b.pSrcDb = pFrom->db;
65023 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
65069 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65104 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
65108 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
65111 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
65112 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
65120 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
65170 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65200 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65237 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65265 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65311 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65315 t.db = pMem->db;
65321 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
65338 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
65372 sqlite3DbFree(p->db, p->zMalloc);
65438 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65462 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65487 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65512 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65526 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65545 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65572 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
65596 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
65608 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){
65611 pMem->db = db;
65696 sqlite3 *db = pMem->db;
65697 assert( db!=0 );
65700 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
65701 if( db->mallocFailed ){
65706 pMem->szMalloc = sqlite3DbMallocSize(db, pMem->zMalloc);
65707 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, pMem->szMalloc);
65718 assert( p->db!=0 );
65724 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
65765 assert( pTo->db==pFrom->db );
65785 assert( pTo->db==pFrom->db || pFrom->db==0 );
65807 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
65808 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
65809 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
65843 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65852 if( pMem->db ){
65853 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
65891 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
66000 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
66023 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
66024 || pVal->db->mallocFailed );
66044 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
66059 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
66060 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
66063 p->db = db;
66090 static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
66102 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
66107 assert( pRec->pKeyInfo->enc==ENC(db) );
66111 pRec->aMem[i].db = db;
66114 sqlite3DbFree(db, pRec);
66128 return sqlite3ValueNew(db);
66153 sqlite3 *db, /* The database connection */
66175 pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
66184 apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
66190 rc = sqlite3ValueFromExpr(db, pList->a[i].pExpr, enc, aff, &apVal[i]);
66195 pVal = valueNew(db, pCtx);
66228 sqlite3DbFree(db, apVal);
66249 sqlite3 *db, /* The database connection */
66278 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
66299 pVal = valueNew(db, pCtx);
66304 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
66319 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal)
66334 pVal = valueNew(db, pCtx);
66342 pVal = valueNew(db, pCtx);
66347 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
66354 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
66362 db->mallocFailed = 1;
66363 sqlite3DbFree(db, zVal);
66384 sqlite3 *db, /* The database connection */
66390 return valueFromExpr(db, pExpr, enc, affinity, ppVal, 0);
66412 sqlite3 *db;
66419 db = sqlite3_context_db_handle(context);
66422 aRet = sqlite3DbMallocRaw(db, nRet);
66430 sqlite3DbFree(db, aRet);
66476 sqlite3 *db = pParse->db;
66482 pVal = valueNew(db, pAlloc);
66493 pVal = valueNew(db, pAlloc);
66497 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
66499 pVal->db = pParse->db;
66503 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, pAlloc);
66506 assert( pVal==0 || pVal->db==db );
66560 assert( pVal==0 || pVal->db==pParse->db );
66593 sqlite3 *db, /* Database handle */
66624 pMem = *ppVal = sqlite3ValueNew(db);
66628 pMem->enc = ENC(db);
66642 sqlite3 *db = aMem[0].db;
66647 sqlite3DbFree(db, pRec);
66671 sqlite3DbFree(((Mem*)v)->db, v);
66722 sqlite3 *db = pParse->db;
66724 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
66726 p->db = db;
66727 if( db->pVdbe ){
66728 db->pVdbe->pPrev = p;
66730 p->pNext = db->pVdbe;
66732 db->pVdbe = p;
66746 sqlite3DbFree(p->db, p->zErrMsg);
66748 p->zErrMsg = sqlite3VMPrintf(p->db, zFormat, ap);
66762 p->zSql = sqlite3DbStrNDup(p->db, z, n);
66825 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
66827 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
66885 if( p->db->flags & SQLITE_VdbeAddopTrace ){
67004 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
67042 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
67090 ** sqlite3DbFree(v->db, sIter.apSub);
67132 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
67193 sqlite3DbFree(v->db, sIter.apSub);
67200 return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
67289 sqlite3DbFree(p->db, pParse->aLabel);
67317 assert( aOp && !p->db->mallocFailed );
67365 if( p->db->flags & SQLITE_VdbeAddopTrace ){
67388 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
67395 pNew->zName = sqlite3DbStrDup(p->db, zName);
67436 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
67438 sqlite3DbFree(db, pDef);
67447 static void freeP4(sqlite3 *db, int p4type, void *p4){
67449 assert( db );
67452 freeEphemeralFunction(db, ((sqlite3_context*)p4)->pFunc);
67459 sqlite3DbFree(db, p4);
67463 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
67467 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
67471 freeEphemeralFunction(db, (FuncDef*)p4);
67475 if( db->pnBytesFreed==0 ){
67479 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
67480 sqlite3DbFree(db, p);
67485 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
67497 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
67501 freeP4(db, pOp->p4type, pOp->p4.p);
67503 sqlite3DbFree(db, pOp->zComment);
67507 sqlite3DbFree(db, aOp);
67526 sqlite3 *db = p->db;
67527 freeP4(db, pOp->p4type, pOp->p4.p);
67566 sqlite3 *db;
67568 db = p->db;
67570 if( p->aOp==0 || db->mallocFailed ){
67572 freeP4(db, n, (void*)*(char**)&zP4);
67585 freeP4(db, pOp->p4type, pOp->p4.p);
67602 assert( ((VTable *)zP4)->db==p->db );
67608 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
67634 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
67637 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
67638 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
67690 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
67691 if( p->db->mallocFailed ){
67908 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
67916 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
67919 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
67929 ** sets the BtShared.db member of each of the BtShared structures, ensuring
67933 ** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
67948 sqlite3 *db;
67949 Db *aDb;
67952 db = p->db;
67953 aDb = db->aDb;
67954 nDb = db->nDb;
67969 sqlite3 *db;
67970 Db *aDb;
67972 db = p->db;
67973 aDb = db->aDb;
67974 nDb = db->nDb;
68020 sqlite3 *db = p->db;
68021 u8 malloc_failed = db->mallocFailed;
68022 if( db->pnBytesFreed ){
68024 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
68029 assert( (&p[1])==pEnd || p[0].db==p[1].db );
68051 sqlite3DbFree(db, p->zMalloc);
68057 db->mallocFailed = malloc_failed;
68073 sqlite3DbFree(p->v->db, p);
68099 sqlite3 *db = p->db; /* The database connection */
68118 db->mallocFailed = 1;
68154 }else if( db->u1.isInterrupted ){
68220 assert( p->db->mallocFailed );
68236 assert( p->db->mallocFailed );
68247 assert( p->db->mallocFailed );
68376 assert( p->aMem[i].db==p->db );
68418 sqlite3 *db; /* The database connection */
68434 db = p->db;
68435 assert( db->mallocFailed==0 );
68493 p->pFree = sqlite3DbMallocZero(db, nByte);
68497 }while( nByte && !db->mallocFailed );
68505 p->aVar[n].db = db;
68518 p->aMem[n].db = db;
68533 sqlite3VdbeSorterClose(p->db, pCx);
68587 v->db->lastRowid = pFrame->lastRowid;
68589 v->db->nChange = pFrame->nDbChange;
68629 sqlite3 *db = p->db;
68641 sqlite3DbFree(db, p->zErrMsg);
68655 sqlite3 *db = p->db;
68658 sqlite3DbFree(db, p->aColName);
68661 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
68665 pColName->db = p->db;
68691 if( p->db->mallocFailed ){
68704 ** db. If a transaction is active, commit it. If there is a
68708 static int vdbeCommit(sqlite3 *db, Vdbe *p){
68727 rc = sqlite3VtabSync(db, p);
68735 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68736 Btree *pBt = db->aDb[i].pBt;
68750 if( needXcommit && db->xCommitCallback ){
68751 rc = db->xCommitCallback(db->pCommitArg);
68766 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
68769 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68770 Btree *pBt = db->aDb[i].pBt;
68781 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68782 Btree *pBt = db->aDb[i].pBt;
68788 sqlite3VtabCommit(db);
68798 sqlite3_vfs *pVfs = db->pVfs;
68801 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
68810 zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
68841 sqlite3DbFree(db, zMaster);
68851 for(i=0; i<db->nDb; i++){
68852 Btree *pBt = db->aDb[i].pBt;
68867 sqlite3DbFree(db, zMaster);
68882 sqlite3DbFree(db, zMaster);
68886 /* Sync all the db files involved in the transaction. The same call
68896 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68897 Btree *pBt = db->aDb[i].pBt;
68905 sqlite3DbFree(db, zMaster);
68914 sqlite3DbFree(db, zMaster);
68929 for(i=0; i<db->nDb; i++){
68930 Btree *pBt = db->aDb[i].pBt;
68938 sqlite3VtabCommit(db);
68955 static void checkActiveVdbeCnt(sqlite3 *db){
68960 p = db->pVdbe;
68969 assert( cnt==db->nVdbeActive );
68970 db->nVdbeWrite );
68971 assert( nRead==db->nVdbeRead );
68988 sqlite3 *const db = p->db;
68994 ** In this case (db->nStatement==0), and there is nothing to do.
68996 if( db->nStatement && p->iStatement ){
69001 assert( db->nStatement>0 );
69002 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
69004 for(i=0; i<db->nDb; i++){
69006 Btree *pBt = db->aDb[i].pBt;
69019 db->nStatement--;
69024 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
69027 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
69035 db->nDeferredCons = p->nStmtDefCons;
69036 db->nDeferredImmCons = p->nStmtDefImmCons;
69054 sqlite3 *db = p->db;
69055 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
69082 sqlite3 *db = p->db;
69100 if( p->db->mallocFailed ){
69108 checkActiveVdbeCnt(db);
69144 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69145 sqlite3CloseSavepoints(db);
69146 db->autoCommit = 1;
69163 if( !sqlite3VtabInSync(db)
69164 && db->autoCommit
69165 && db->nVdbeWrite==(p->readOnly==0)
69180 rc = vdbeCommit(db, p);
69187 sqlite3RollbackAll(db, SQLITE_OK);
69190 db->nDeferredCons = 0;
69191 db->nDeferredImmCons = 0;
69192 db->flags &= ~SQLITE_DeferFKs;
69193 sqlite3CommitInternalChanges(db);
69196 sqlite3RollbackAll(db, SQLITE_OK);
69199 db->nStatement = 0;
69206 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69207 sqlite3CloseSavepoints(db);
69208 db->autoCommit = 1;
69224 sqlite3DbFree(db, p->zErrMsg);
69227 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69228 sqlite3CloseSavepoints(db);
69229 db->autoCommit = 1;
69239 sqlite3VdbeSetChanges(db, p->nChange);
69241 sqlite3VdbeSetChanges(db, 0);
69252 db->nVdbeActive--;
69253 if( !p->readOnly ) db->nVdbeWrite--;
69254 if( p->bIsReader ) db->nVdbeRead--;
69255 assert( db->nVdbeActive>=db->nVdbeRead );
69256 assert( db->nVdbeRead>=db->nVdbeWrite );
69257 assert( db->nVdbeWrite>=0 );
69260 checkActiveVdbeCnt(db);
69261 if( p->db->mallocFailed ){
69266 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
69269 if( db->autoCommit ){
69270 sqlite3ConnectionUnlocked(db);
69273 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
69295 sqlite3 *db = p->db;
69298 u8 mallocFailed = db->mallocFailed;
69300 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
69301 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
69303 db->mallocFailed = mallocFailed;
69304 db->errCode = rc;
69306 sqlite3Error(db, rc);
69319 assert( v->db->init.busy==0 );
69322 sqlite3GlobalConfig.pSqllogArg, v->db, zExpanded, 1
69324 sqlite3DbFree(v->db, zExpanded);
69344 sqlite3 *db;
69345 db = p->db;
69361 sqlite3DbFree(db, p->zErrMsg);
69369 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
69370 sqlite3DbFree(db, p->zErrMsg);
69416 return p->rc & db->errMask;
69427 assert( (rc & p->db->errMask)==rc );
69461 sqlite3DbFree(pVdbe->db, pAux);
69476 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
69479 assert( p->db==0 || p->db==db );
69484 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
69485 sqlite3DbFree(db, pSub);
69487 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
69488 vdbeFreeOpArray(db, p->aOp, p->nOp);
69489 sqlite3DbFree(db, p->aColName);
69490 sqlite3DbFree(db, p->zSql);
69491 sqlite3DbFree(db, p->pFree);
69494 sqlite3DbFree(db, p->aScan[i].zName);
69496 sqlite3DbFree(db, p->aScan);
69504 sqlite3 *db;
69507 db = p->db;
69508 assert( sqlite3_mutex_held(db->mutex) );
69509 sqlite3VdbeClearObject(db, p);
69513 assert( db->pVdbe==p );
69514 db->pVdbe = p->pNext;
69520 p->db = 0;
69521 sqlite3DbFree(db, p);
69672 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
69967 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
70010 pMem->db = pKeyInfo->db;
70048 if( pKeyInfo->db==0 ) return 1;
70050 mem1.db = pKeyInfo->db;
70121 if( pKeyInfo->db->mallocFailed ) return 1;
70184 sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null);
70185 sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null);
70360 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
70478 mem1.db = pKeyInfo->db;
70544 || pKeyInfo->db->mallocFailed
70706 || pPKey2->pKeyInfo->db->mallocFailed
70762 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
70781 sqlite3VdbeMemInit(&m, db, 0);
70841 sqlite3 *db, /* Database connection */
70860 sqlite3VdbeMemInit(&m, db, 0);
70872 ** sqlite3_changes() on the database handle 'db'.
70874 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
70875 assert( sqlite3_mutex_held(db->mutex) );
70876 db->nChange = nChange;
70877 db->nTotalChange += nChange;
70898 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
70900 for(p = db->pVdbe; p; p=p->pNext){
70909 return v->db;
70925 sqlite3_value *pRet = sqlite3ValueNew(v->db);
70957 sqlite3 *db = p->db;
70958 sqlite3DbFree(db, p->zErrMsg);
70959 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
71006 if( p->db==0 ){
71027 static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
71030 assert( db->xProfile!=0 );
71031 assert( db->init.busy==0 );
71033 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
71034 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
71038 ** The checkProfileCallback(DB,P) macro checks to see if a profile callback
71041 # define checkProfileCallback(DB,P) \
71042 if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
71044 # define checkProfileCallback(DB,P) /*no-op*/
71064 sqlite3 *db = v->db;
71066 sqlite3_mutex_enter(db->mutex);
71067 checkProfileCallback(db, v);
71069 rc = sqlite3ApiExit(db, rc);
71070 sqlite3LeaveMutexAndCloseZombie(db);
71089 sqlite3 *db = v->db;
71090 sqlite3_mutex_enter(db->mutex);
71091 checkProfileCallback(db, v);
71094 assert( (rc & (db->errMask))==rc );
71095 rc = sqlite3ApiExit(db, rc);
71096 sqlite3_mutex_leave(db->mutex);
71109 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
71225 pNew->db = 0;
71290 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71299 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71308 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71312 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71319 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71326 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71330 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71334 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71338 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71347 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71357 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71373 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71382 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71391 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71396 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71400 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71405 assert( sqlite3_mutex_held(pOut->db->mutex) );
71406 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
71426 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71435 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71439 pCtx->pOut->db->mallocFailed = 1;
71446 static int doWalCallbacks(sqlite3 *db){
71450 for(i=0; i<db->nDb; i++){
71451 Btree *pBt = db->aDb[i].pBt;
71457 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
71458 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
71477 sqlite3 *db;
71510 db = p->db;
71511 if( db->mallocFailed ){
71526 if( db->nVdbeActive==0 ){
71527 db->u1.isInterrupted = 0;
71530 assert( db->nVdbeWrite>0 || db->autoCommit==0
71531 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
71535 if( db->xProfile && !db->init.busy && p->zSql ){
71536 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
71542 db->nVdbeActive++;
71543 if( p->readOnly==0 ) db->nVdbeWrite++;
71544 if( p->bIsReader ) db->nVdbeRead++;
71556 db->nVdbeExec++;
71558 db->nVdbeExec--;
71563 if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
71568 p->rc = doWalCallbacks(db);
71574 db->errCode = rc;
71575 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
71597 return (rc&db->errMask);
71610 sqlite3 *db; /* The database connection */
71615 db = v->db;
71616 sqlite3_mutex_enter(db->mutex);
71636 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
71637 sqlite3DbFree(db, v->zErrMsg);
71638 if( !db->mallocFailed ){
71639 v->zErrMsg = sqlite3DbStrDup(db, zErr);
71646 rc = sqlite3ApiExit(db, rc);
71647 sqlite3_mutex_leave(db->mutex);
71673 return p->pOut->db;
71693 rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime);
71749 assert( sqlite3_mutex_held(p->pOut->db->mutex) );
71765 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71792 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71804 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
71889 /* .db = */ (sqlite3*)0,
71911 sqlite3_mutex_enter(pVm->db->mutex);
71914 if( pVm && ALWAYS(pVm->db) ){
71915 sqlite3_mutex_enter(pVm->db->mutex);
71916 sqlite3Error(pVm->db, SQLITE_RANGE);
71950 p->rc = sqlite3ApiExit(p->db, p->rc);
71951 sqlite3_mutex_leave(p->db->mutex);
72046 sqlite3 *db;
72055 db = p->db;
72056 assert( db!=0 );
72060 sqlite3_mutex_enter(db->mutex);
72061 assert( db->mallocFailed==0 );
72066 if( db->mallocFailed ){
72067 db->mallocFailed = 0;
72070 sqlite3_mutex_leave(db->mutex);
72179 ** The error code stored in database p->db is overwritten with the return
72187 sqlite3_mutex_enter(p->db->mutex);
72189 sqlite3Error(p->db, SQLITE_MISUSE);
72190 sqlite3_mutex_leave(p->db->mutex);
72196 sqlite3Error(p->db, SQLITE_RANGE);
72197 sqlite3_mutex_leave(p->db->mutex);
72204 sqlite3Error(p->db, SQLITE_OK);
72244 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
72246 sqlite3Error(p->db, rc);
72247 rc = sqlite3ApiExit(p->db, rc);
72249 sqlite3_mutex_leave(p->db->mutex);
72289 sqlite3_mutex_leave(p->db->mutex);
72302 sqlite3_mutex_leave(p->db->mutex);
72311 sqlite3_mutex_leave(p->db->mutex);
72388 sqlite3_mutex_leave(p->db->mutex);
72395 sqlite3_mutex_enter(p->db->mutex);
72396 if( n>(u64)p->db->aLimit[SQLITE_LIMIT_LENGTH] ){
72402 rc = sqlite3ApiExit(p->db, rc);
72403 sqlite3_mutex_leave(p->db->mutex);
72461 assert( pTo->db==pFrom->db );
72463 sqlite3_mutex_enter(pTo->db->mutex);
72467 sqlite3_mutex_leave(pTo->db->mutex);
72507 return pStmt ? ((Vdbe*)pStmt)->db : 0;
72713 sqlite3 *db; /* The database connection */
72723 db = p->db;
72724 sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
72725 db->aLimit[SQLITE_LIMIT_LENGTH]);
72726 if( db->nVdbeExec>1 ){
72774 u8 enc = ENC(db);
72778 utf8.db = db;
73310 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
73424 ** assert( checkSavepointCount(db) );
73426 static int checkSavepointCount(sqlite3 *db){
73429 for(p=db->pSavepoint; p; p=p->pNext) n++;
73430 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
73464 sqlite3 *db = p->db; /* The database */
73466 u8 encoding = ENC(db); /* The database encoding */
73478 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
73497 db
73498 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
73501 if( db->xProgress ){
73503 assert( 0 < db->nProgressOps );
73504 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
73510 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
73515 if( p->db->flags & SQLITE_VdbeListing ){
73521 if( p->db->flags & SQLITE_VdbeEQP ){
73530 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
73536 if( db->mallocFailed ) goto no_mem;
73548 if( db->flags & SQLITE_VdbeTrace ){
73561 sqlite3_interrupt(db);
73669 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
73677 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
73678 assert( db->nProgressOps!=0 );
73679 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
73680 if( db->xProgress(db->pProgressArg) ){
73849 sqlite3VdbeSetChanges(db, p->nChange);
73851 lastRowid = db->lastRowid;
73898 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
73968 sqlite3DbFree(db, pOp->p4.z);
73975 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
74204 if( db->xProgress!=0
74206 && db->xProgress(db->pProgressArg)!=0
74217 assert( db->flags&SQLITE_CountRows );
74237 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
74259 if( db->mallocFailed ) goto no_mem;
74296 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
74516 pCtx = sqlite3DbMallocRaw(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
74554 db->lastRowid = lastRowid;
74556 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
74919 if( db->mallocFailed ) goto no_mem;
75326 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
75650 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
75737 assert( db->pSavepoint==0 || db->autoCommit==0 );
75739 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
75740 assert( checkSavepointCount(db) );
75744 if( db->nVdbeWrite>0 ){
75757 ** that the db->aVTrans[] array is empty. */
75758 assert( db->autoCommit==0 || db->nVTrans==0 );
75759 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
75760 db->nStatement+db->nSavepoint);
75765 pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
75772 if( db->autoCommit ){
75773 db->autoCommit = 0;
75774 db->isTransactionSavepoint = 1;
75776 db->nSavepoint++;
75780 pNew->pNext = db->pSavepoint;
75781 db->pSavepoint = pNew;
75782 pNew->nDeferredCons = db->nDeferredCons;
75783 pNew->nDeferredImmCons = db->nDeferredImmCons;
75792 pSavepoint = db->pSavepoint;
75801 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
75814 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
75819 db->autoCommit = 1;
75822 db->autoCommit = 0;
75826 db->isTransactionSavepoint = 0;
75830 iSavepoint = db->nSavepoint - iSavepoint - 1;
75832 isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
75833 for(ii=0; ii<db->nDb; ii++){
75834 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
75842 for(ii=0; ii<db->nDb; ii++){
75843 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
75849 sqlite3ExpirePreparedStatements(db);
75850 sqlite3ResetAllSchemasOfConnection(db);
75851 db->flags = (db->flags | SQLITE_InternChanges);
75857 while( db->pSavepoint!=pSavepoint ){
75858 pTmp = db->pSavepoint;
75859 db->pSavepoint = pTmp->pNext;
75860 sqlite3DbFree(db, pTmp);
75861 db->nSavepoint--;
75869 assert( pSavepoint==db->pSavepoint );
75870 db->pSavepoint = pSavepoint->pNext;
75871 sqlite3DbFree(db, pSavepoint);
75873 db->nSavepoint--;
75876 db->nDeferredCons = pSavepoint->nDeferredCons;
75877 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
75881 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
75906 turnOnAC = desiredAutoCommit && !db->autoCommit;
75909 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
75912 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
75919 }else if( desiredAutoCommit!=db->autoCommit ){
75922 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
75923 db->autoCommit = 1;
75927 db->autoCommit = (u8)desiredAutoCommit;
75931 db->autoCommit = (u8)(1-desiredAutoCommit);
75935 assert( db->nStatement==0 );
75936 sqlite3CloseSavepoints(db);
75995 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75997 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
76001 pBt = db->aDb[pOp->p1].pBt;
76017 && (db->autoCommit==0 || db->nVdbeRead>1)
76021 assert( db->nStatement>=0 && db->nSavepoint>=0 );
76022 db->nStatement++;
76023 p->iStatement = db->nSavepoint + db->nStatement;
76026 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
76034 p->nStmtDefCons = db->nDeferredCons;
76035 p->nStmtDefImmCons = db->nDeferredImmCons;
76045 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
76051 sqlite3DbFree(db, p->zErrMsg);
76052 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
76066 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
76067 sqlite3ResetOneSchema(db, pOp->p1);
76096 assert( iDb>=0 && iDb<db->nDb );
76097 assert( db->aDb[iDb].pBt!=0 );
76100 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
76117 Db *pDb;
76119 assert( pOp->p1>=0 && pOp->p1<db->nDb );
76122 pDb = &db->aDb[pOp->p1];
76124 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
76132 db->flags |= SQLITE_InternChanges;
76140 sqlite3ExpirePreparedStatements(db);
76219 Db *pDb;
76248 assert( iDb>=0 && iDb<db->nDb );
76250 pDb = &db->aDb[iDb];
76255 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76281 assert( pKeyInfo->enc==ENC(db) );
76282 assert( pKeyInfo->db==db );
76354 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
76371 assert( pKeyInfo->db==db );
76372 assert( pKeyInfo->enc==ENC(db) );
76404 assert( pCx->pKeyInfo->db==db );
76405 assert( pCx->pKeyInfo->enc==ENC(db) );
76406 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx);
76864 sqlite3DbFree(db, pFree);
77171 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
77192 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
77193 zDb = db->aDb[pC->iDb].zName;
77197 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
77234 hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable;
77255 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
77256 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
77270 sqlite3VdbeSetChanges(db, p->nChange);
77394 if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
77401 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
77662 rc = sqlite3VdbeSorterNext(db, pC, &res);
77833 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
77917 rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
77958 if( db->nVdbeRead > db->nVDestroy+1 ){
77965 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
77970 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
78005 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
78033 sqlite3VdbeSorterReset(db, pC->pSorter);
78069 Db *pDb;
78073 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78076 pDb = &db->aDb[pOp->p1];
78108 for(iDb=0; iDb<db->nDb; iDb++){
78109 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
78114 assert( iDb>=0 && iDb<db->nDb );
78115 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
78118 initData.db = db;
78121 zSql = sqlite3MPrintf(db,
78123 db->aDb[iDb].zName, zMaster, pOp->p4.z);
78127 assert( db->init.busy==0 );
78128 db->init.busy = 1;
78130 assert( !db->mallocFailed );
78131 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
78133 sqlite3DbFree(db, zSql);
78134 db->init.busy = 0;
78137 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
78152 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78153 rc = sqlite3AnalysisLoad(db, pOp->p1);
78167 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
78180 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
78193 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
78230 aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
78241 assert( pOp->p5<db->nDb );
78243 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
78245 sqlite3DbFree(db, aRoot);
78410 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
78431 pFrame = sqlite3DbMallocZero(db, nByte);
78459 pMem->db = db;
78472 pFrame->nDbChange = p->db->nChange;
78526 if( db->flags & SQLITE_DeferFKs ){
78527 db->nDeferredImmCons += pOp->p2;
78529 db->nDeferredCons += pOp->p2;
78550 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
78551 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
78553 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
78554 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
78716 pCtx = sqlite3DbMallocRaw(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
78755 sqlite3VdbeMemInit(&t, db, MEM_Null);
78832 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
78875 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78878 pBt = db->aDb[pOp->p1].pBt;
78900 if( !db->autoCommit || db->nVdbeRead>1 ){
78959 rc = sqlite3RunVacuum(&p->zErrMsg, db);
78974 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78977 pBt = db->aDb[pOp->p1].pBt;
79000 sqlite3ExpirePreparedStatements(db);
79025 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
79027 assert( p1>=0 && p1<db->nDb );
79030 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
79053 rc = sqlite3VtabBegin(db, pVTab);
79070 sMem.db = db;
79078 assert( zTab || db->mallocFailed );
79080 rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg);
79094 db->nVDestroy++;
79095 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
79096 db->nVDestroy--;
79135 assert( db->mallocFailed );
79379 u8 vtabOnConflict = db->vtabOnConflict;
79388 db->vtabOnConflict = pOp->p5;
79390 db->vtabOnConflict = vtabOnConflict;
79394 db->lastRowid = lastRowid = rowid;
79417 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
79437 db->aDb[pOp->p1].pBt;
79466 if( db->xTrace
79471 db->xTrace(db->pTraceArg, z);
79472 sqlite3DbFree(db, z);
79478 for(i=0; i<db->nDb; i++){
79480 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
79485 if( (db->flags & SQLITE_SqlTrace)!=0
79538 if( db->flags & SQLITE_VdbeTrace ){
79561 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
79564 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
79571 db->lastRowid = lastRowid;
79588 db->mallocFailed = 1;
79598 if( db->mallocFailed ) rc = SQLITE_NOMEM;
79608 assert( db->u1.isInterrupted );
79649 sqlite3 *db; /* The associated database */
79687 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
79707 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
79710 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
79725 sqlite3* db, /* The database connection */
79737 ** db/table/row entry. The reason for using a vdbe program instead
79780 if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
79786 sqlite3_mutex_enter(db->mutex);
79788 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
79790 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
79795 pParse->db = db;
79796 sqlite3DbFree(db, zErr);
79799 sqlite3BtreeEnterAll(db);
79817 sqlite3DbFree(db, zErr);
79822 sqlite3BtreeLeaveAll(db);
79833 sqlite3DbFree(db, zErr);
79834 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
79836 sqlite3BtreeLeaveAll(db);
79848 if( db->flags&SQLITE_ForeignKeys ){
79874 sqlite3DbFree(db, zErr);
79875 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
79877 sqlite3BtreeLeaveAll(db);
79883 assert( pBlob->pStmt || db->mallocFailed );
79886 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79923 if( !db->mallocFailed ){
79933 pBlob->db = db;
79934 sqlite3BtreeLeaveAll(db);
79935 if( db->mallocFailed ){
79943 if( rc==SQLITE_OK && db->mallocFailed==0 ){
79947 sqlite3DbFree(db, pBlob);
79949 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
79950 sqlite3DbFree(db, zErr);
79952 sqlite3StackFree(db, pParse);
79953 rc = sqlite3ApiExit(db, rc);
79954 sqlite3_mutex_leave(db->mutex);
79965 sqlite3 *db;
79968 db = p->db;
79969 sqlite3_mutex_enter(db->mutex);
79971 sqlite3DbFree(db, p);
79972 sqlite3_mutex_leave(db->mutex);
79992 sqlite3 *db;
79995 db = p->db;
79996 sqlite3_mutex_enter(db->mutex);
80011 assert( db == v->db );
80022 sqlite3Error(db, rc);
80023 rc = sqlite3ApiExit(db, rc);
80024 sqlite3_mutex_leave(db->mutex);
80066 sqlite3 *db;
80069 db = p->db;
80070 sqlite3_mutex_enter(db->mutex);
80081 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
80082 sqlite3DbFree(db, zErr);
80087 rc = sqlite3ApiExit(db, rc);
80089 sqlite3_mutex_leave(db->mutex);
80420 sqlite3 *db; /* Database connection */
80711 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
81024 sqlite3 *db, /* Database connection (for malloc()) */
81032 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
81044 if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
81047 nWorker = db->aLimit[SQLITE_LIMIT_WORKER_THREADS];
81063 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
81070 pKeyInfo->db = 0;
81075 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
81079 pSorter->db = db;
81085 if( !sqlite3TempInMemory(db) ){
81088 mxCache = db->aDb[0].pSchema->cache_size;
81105 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
81118 static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord){
81123 sqlite3DbFree(db, p);
81131 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
81132 sqlite3DbFree(db, pTask->pUnpacked);
81157 sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t);
81171 sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t);
81181 sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t);
81314 SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *db, VdbeSorter *pSorter){
81321 sqlite3DbFree(db, pSorter->pReader);
81329 vdbeSortSubtaskCleanup(db, pTask);
81340 sqlite3DbFree(db, pSorter->pUnpacked);
81347 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){
81350 sqlite3VdbeSorterReset(db, pSorter);
81352 sqlite3DbFree(db, pSorter);
81367 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
81368 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
81387 sqlite3 *db, /* Database handle doing sort */
81393 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
81402 vdbeSorterExtendFile(db, *ppFd, nExtend);
81632 sqlite3 *db = pTask->pSorter->db;
81648 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
81656 vdbeSorterExtendFile(db, pTask->file.pFd, pTask->file.iEof+pList->szPMA+9);
82262 sqlite3 *db = pTask->pSorter->db;
82276 db, mxSz, &pIncr->aFile[0].pFd);
82278 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
82285 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
82573 sqlite3 *db = pTask0->pSorter->db;
82591 pReadr = (PmaReader*)sqlite3DbMallocZero(db, sizeof(PmaReader));
82696 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *db, const VdbeCursor *pCsr, int *pbEof){
82720 if( pSorter->list.aMemory==0 ) vdbeSorterRecordFree(db, pFree);
83576 sqlite3 *db; /* The database connection */
83581 db = pParse->db;
83582 pDup = sqlite3ExprDup(db, pOrig, 0);
83594 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
83598 sqlite3ExprDelete(db, pExpr);
83602 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
83605 sqlite3DbFree(db, pDup);
83661 ** pExpr->iDb Set the index in db->aDb[] of the database X
83694 sqlite3 *db = pParse->db; /* The database connection */
83726 for(i=0; i<db->nDb; i++){
83727 assert( db->aDb[i].zName );
83728 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
83729 pSchema = db->aDb[i].pSchema;
83977 sqlite3ExprDelete(db, pExpr->pLeft);
83979 sqlite3ExprDelete(db, pExpr->pRight);
84006 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
84007 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
84157 u8 enc = ENC(pParse->db); /* The database encoding */
84163 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
84165 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
84225 }else if( no_such_func && pParse->db->init.busy==0 ){
84279 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
84341 sqlite3 *db; /* Database connection */
84343 u8 savedSuppErr; /* Saved value of db->suppressErr */
84356 db = pParse->db;
84357 savedSuppErr = db->suppressErr;
84358 db->suppressErr = 1;
84360 db->suppressErr = savedSuppErr;
84413 sqlite3 *db;
84418 db = pParse->db;
84420 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
84451 pDup = sqlite3ExprDup(db, pE, 0);
84452 if( !db->mallocFailed ){
84456 sqlite3ExprDelete(db, pDup);
84462 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
84475 sqlite3ExprDelete(db, pE);
84511 sqlite3 *db = pParse->db;
84515 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
84517 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
84622 sqlite3 *db; /* Database connection */
84631 db = pParse->db;
84643 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
84697 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
84788 if( db->mallocFailed ){
84798 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
85066 ** If a memory allocation error occurs, that fact is recorded in pParse->db
85076 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
85122 sqlite3 *db = pParse->db;
85133 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
85145 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
85321 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
85448 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
85464 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
85497 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
85504 return sqlite3ExprAlloc(db, op, &x, 0);
85514 sqlite3 *db,
85520 assert( db->mallocFailed );
85521 sqlite3ExprDelete(db, pLeft);
85522 sqlite3ExprDelete(db, pRight);
85540 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
85553 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
85555 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
85556 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
85599 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
85605 sqlite3ExprDelete(db, pLeft);
85606 sqlite3ExprDelete(db, pRight);
85607 return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
85609 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
85610 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
85621 sqlite3 *db = pParse->db;
85623 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
85625 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
85651 sqlite3 *db = pParse->db;
85674 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
85675 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
85676 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
85678 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
85701 a = sqlite3DbRealloc(db
85702 if( a==0 ) return; /* Error reported through db->mallocFailed */
85708 sqlite3DbFree(db, pParse->azVar[x-1]);
85709 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
85713 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
85721 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
85728 sqlite3ExprDelete(db, p->pLeft);
85729 sqlite3ExprDelete(db, p->pRight);
85730 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
85732 sqlite3SelectDelete(db, p->x.pSelect);
85734 sqlite3ExprListDelete(db, p->x.pList);
85738 sqlite3DbFree(db, p);
85854 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
85868 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
85909 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
85911 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
85919 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
85920 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
85927 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
85928 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
85940 ** and the db->mallocFailed flag set.
85943 static With *withDup(sqlite3 *db, With *p){
85947 pRet = sqlite3DbMallocZero(db, nByte);
85952 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
85953 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
85954 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
85981 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
85982 return exprDup(db, p, flags, 0);
85984 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
85989 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
85993 pNew->a = pItem = sqlite3DbMallocRaw(db, i*sizeof(p->a[0]) );
85995 sqlite3DbFree(db, pNew);
86001 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
86002 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
86003 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
86020 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
86026 pNew = sqlite3DbMallocRaw(db, nByte );
86034 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
86035 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
86036 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
86042 pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
86047 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
86053 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
86054 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
86055 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
86060 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
86064 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
86067 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
86069 sqlite3DbFree(db, pNew);
86078 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
86083 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
86086 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
86088 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
86089 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
86090 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
86091 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
86092 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
86093 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
86095 pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
86098 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
86099 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
86106 pNew->pWith = withDup(db, p->pWith);
86111 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
86131 sqlite3 *db = pParse->db;
86133 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
86137 pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
86142 a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
86158 sqlite3ExprDelete(db, pExpr);
86159 sqlite3ExprListDelete(db
86182 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
86191 assert( pList!=0 || pParse->db->mallocFailed!=0 );
86197 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
86207 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
86215 sqlite3 *db = pParse->db;
86216 assert( pList!=0 || db->mallocFailed!=0 );
86220 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
86221 sqlite3DbFree(db, pItem->zSpan);
86222 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
86236 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
86247 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
86253 sqlite3ExprDelete(db, pItem->pExpr);
86254 sqlite3DbFree(db, pItem->zName);
86255 sqlite3DbFree(db, pItem->zSpan);
86257 sqlite3DbFree(db, pList->a);
86258 sqlite3DbFree(db, pList);
86712 sqlite3 *db = pParse->db; /* Database connection */
86727 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
86760 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
86877 pParse->db, "EXECUTE %s%s SUBQUERY %d", jmpIfDynamic>=0?"":"CORRELATED ",
86908 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
87032 db, pSel->pLimit);
87311 assert( iReg>0 || pParse->nErr || pParse->db->mallocFailed );
87318 if( OptimizationDisabled(pParse->db, SQLITE_ColumnCache) ) return;
87390 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
87407 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
87528 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
87605 sqlite3 *db = pParse->db; /* The database connection */
87610 assert( pParse->db->mallocFailed );
87849 u8 enc = ENC(db); /* The text encoding used by this database */
87862 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
87954 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
87956 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
87960 if( !pColl ) pColl = db->pDfltColl;
88169 assert( db->mallocFailed || pParse->nErr>0
88220 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
88289 assert( pParse->pVdbe || pParse->db->mallocFailed );
88734 sqlite3 *db = pParse->db;
88735 Expr *pCopy = sqlite3ExprDup(db, pExpr, 0);
88736 if( db->mallocFailed==0 ){
88739 sqlite3ExprDelete(db, pCopy);
88938 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
88941 db,
88954 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
88957 db,
89006 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
89064 u8 enc = ENC(pParse->db);
89065 i = addAggInfoFunc(pParse->db, pAggInfo);
89072 pItem->pFunc = sqlite3FindFunction(pParse->db,
89254 sqlite3 *db = sqlite3_context_db_handle(context);
89283 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
89310 sqlite3 *db = sqlite3_context_db_handle(context);
89333 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
89337 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
89340 sqlite3DbFree(db, zOutput);
89344 sqlite3DbFree(db, zParent);
89348 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
89350 sqlite3DbFree(db, zOutput);
89376 sqlite3 *db = sqlite3_context_db_handle(context);
89424 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
89469 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
89472 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
89474 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
89475 sqlite3DbFree(db, zWhere);
89491 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
89506 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
89508 /* If the table is not located in the temp-db (in which case NULL is
89510 ** that is not part of the temp-db schema, add a clause to the WHERE
89514 sqlite3 *db = pParse->db;
89517 zWhere = whereOrName(db, zWhere, pTrig->zName);
89522 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
89523 sqlite3DbFree(pParse->db, zWhere);
89547 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
89548 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
89554 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
89564 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
89607 sqlite3 *db = pParse->db; /* Database connection */
89615 int savedDbFlags; /* Saved value of db->flags */
89617 savedDbFlags = db->flags;
89618 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
89620 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
89624 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
89625 zDb = db->aDb[iDb].zName;
89626 db->flags |= SQLITE_PreferBuiltin;
89629 zName = sqlite3NameFromToken(db, pName);
89635 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
89670 pVTab = sqlite3GetVTable(db, pTab);
89708 if( db->flags&SQLITE_ForeignKeys ){
89717 sqlite3DbFree(db, zWhere);
89751 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
89769 sqlite3DbFree(db, zWhere);
89774 if( db->flags&SQLITE_ForeignKeys ){
89789 sqlite3SrcListDelete(db, pSrc);
89790 sqlite3DbFree(db, zName);
89791 db->flags = savedDbFlags;
89838 sqlite3 *db; /* The database connection; */
89840 db = pParse->db;
89841 if( pParse->nErr || db->mallocFailed ) return;
89845 assert( sqlite3BtreeHoldsAllMutexes(db) );
89846 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
89847 zDb = db->aDb[iDb].zName;
89851 pTab = sqlite3FindTable(db, zTab, zDb);
89881 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
89898 rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal);
89901 db->mallocFailed = 1;
89912 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
89915 int savedDbFlags = db->flags;
89919 db->flags |= SQLITE_PreferBuiltin;
89927 sqlite3DbFree(db, zCol);
89928 db->flags = savedDbFlags;
89963 sqlite3 *db = pParse->db;
89967 assert( sqlite3BtreeHoldsAllMutexes(db) );
89968 if( db->mallocFailed ) goto exit_begin_add_column;
89989 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
89998 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
90006 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
90007 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
90009 db->mallocFailed = 1;
90015 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
90021 pNew->pSchema = db->aDb[iDb].pSchema;
90032 sqlite3SrcListDelete(db, pSrc);
90234 sqlite3 *db = pParse->db;
90235 Db *pDb;
90241 assert( sqlite3BtreeHoldsAllMutexes(db) );
90242 assert( sqlite3VdbeDb(v)==db );
90243 pDb = &db->aDb[iDb];
90251 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
90333 sqlite3 *db; /* Database connection, for malloc() */
90339 static void sampleClear(sqlite3 *db, Stat4Sample *p){
90340 assert( db!=0 );
90342 sqlite3DbFree(db, p->u.aRowid);
90351 static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
90352 assert( db!=0 );
90353 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
90354 p->u.aRowid = sqlite3DbMallocRaw(db, n);
90367 static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
90368 assert( db!=0 );
90369 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
90388 sampleSetRowid(p->db, pTo, pFrom->nRowid, pFrom->u.aRowid);
90390 sampleSetRowidInt64(p->db, pTo, pFrom->u.iRowid);
90402 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
90403 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
90404 sampleClear(p->db, &p->current);
90406 sqlite3DbFree(p->db, p);
90442 sqlite3 *db; /* Database connection */
90466 db = sqlite3_context_db_handle(context);
90467 p = sqlite3DbMallocZero(db, n);
90473 p->db = db;
90631 sampleClear(p->db, pMin);
90785 sampleSetRowidInt64(p->db
90787 sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
91001 sqlite3 *db = pParse->db; /* Database handle */
91035 assert( sqlite3BtreeHoldsAllMutexes(db) );
91036 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91038 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
91041 db->aDb[iDb].zName ) ){
91119 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
91159 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*nColTest);
91207 sqlite3DbFree(db, aGotoChng);
91330 sqlite3 *db = pParse->db;
91331 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
91343 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
91361 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
91362 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
91388 sqlite3 *db = pParse->db;
91399 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
91407 for(i=0; i<db->nDb; i++){
91413 iDb = sqlite3FindDb(db, pName1);
91417 z = sqlite3NameFromToken(db, pName1);
91419 if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
91424 sqlite3DbFree(db, z);
91431 zDb = db->aDb[iDb].zName;
91432 z = sqlite3NameFromToken(db, pTableName);
91434 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
91439 sqlite3DbFree(db, z);
91453 sqlite3 *db;
91545 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
91554 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
91567 if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
91591 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
91597 sqlite3DbFree(db, p->p);
91599 sqlite3DbFree(db, pIdx->aSample);
91601 if( db && db->pnBytesFreed==0 ){
91606 UNUSED_PARAMETER(db);
91676 sqlite3 *db,
91680 Index *pIdx = sqlite3FindIndex(db, zName, zDb);
91682 Table *pTab = sqlite3FindTable(db, zName, zDb);
91702 sqlite3 *db, /* Database handle */
91714 assert( db->lookaside.bEnabled==0 );
91715 zSql = sqlite3MPrintf(db, zSql1, zDb);
91719 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
91720 sqlite3DbFree(db, zSql);
91736 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
91754 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
91771 zSql = sqlite3MPrintf(db, zSql2, zDb);
91775 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
91776 sqlite3DbFree(db, zSql);
91786 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
91808 pSample->p = sqlite3DbMallocZero(db, pSample->n + 2);
91825 static int loadStat4(sqlite3 *db, const char *zDb){
91828 assert( db->lookaside.bEnabled==0 );
91829 if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){
91830 rc = loadStatTbl(db, 0,
91837 if( rc==SQLITE_OK && sqlite3FindTable(db, "sqlite_stat3", zDb) ){
91838 rc = loadStatTbl(db, 1,
91865 ** If an OOM error occurs, this function always sets db->mallocFailed.
91869 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
91875 assert( iDb>=0 && iDb<db->nDb );
91876 assert( db->aDb[iDb].pBt!=0 );
91879 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
91880 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
91884 sqlite3DeleteIndexSamples(db, pIdx);
91890 sInfo.db = db;
91891 sInfo.zDatabase = db->aDb[iDb].zName;
91892 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
91897 zSql = sqlite3MPrintf(db,
91902 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
91903 sqlite3DbFree(db, zSql);
91909 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
91910 int lookasideEnabled = db->lookaside.bEnabled;
91911 db->lookaside.bEnabled = 0;
91912 rc = loadStat4(db, sInfo.zDatabase);
91913 db->lookaside.bEnabled = lookasideEnabled;
91915 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
91923 db->mallocFailed = 1;
91998 sqlite3 *db = sqlite3_context_db_handle(context);
92004 Db *aNew;
92021 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
92022 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
92023 db->aLimit[SQLITE_LIMIT_ATTACHED]
92027 if( !db->autoCommit ){
92028 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
92031 for(i=0; i<db->nDb; i++){
92032 char *z = db->aDb[i].zName;
92035 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
92040 /* Allocate the new entry in the db->aDb[] array and initialize the schema
92043 if( db->aDb==db->aDbStatic ){
92044 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
92046 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
92048 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
92051 db->aDb = aNew;
92052 aNew = &db->aDb[db->nDb];
92059 flags = db->openFlags;
92060 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
92062 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
92069 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
92071 db->nDb++;
92074 zErrDyn = sqlite3MPrintf(db, "database is already attached");
92077 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
92080 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
92081 zErrDyn = sqlite3MPrintf(db,
92087 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
92089 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
92091 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
92096 aNew->zName = sqlite3DbStrDup(db, zName);
92112 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
92120 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
92125 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
92126 if( nKey>0 || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
92127 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
92136 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
92140 sqlite3BtreeEnterAll(db);
92141 rc = sqlite3Init(db, &zErrDyn);
92142 sqlite3BtreeLeaveAll(db);
92147 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
92148 if( newAuth<db->auth.authLevel ){
92154 int iDb = db->nDb - 1;
92156 if( db->aDb[iDb].pBt ){
92157 sqlite3BtreeClose(db->aDb[iDb].pBt);
92158 db->aDb[iDb].pBt = 0;
92159 db->aDb[iDb].pSchema = 0;
92161 sqlite3ResetAllSchemasOfConnection(db);
92162 db->nDb = iDb;
92164 db->mallocFailed = 1;
92165 sqlite3DbFree(db, zErrDyn);
92166 zErrDyn = sqlite3MPrintf(db, "out of memory");
92168 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
92179 sqlite3DbFree(db, zErrDyn);
92198 sqlite3 *db = sqlite3_context_db_handle(context);
92200 Db *pDb = 0;
92206 for(i=0; i<db->nDb; i++){
92207 pDb = &db->aDb[i];
92212 if( i>=db->nDb ){
92220 if( !db->autoCommit ){
92233 sqlite3CollapseDatabaseArray(db);
92256 sqlite3* db = pParse->db;
92292 assert( v || db->mallocFailed );
92307 sqlite3ExprDelete(db, pFilename);
92308 sqlite3ExprDelete(db, pDbname);
92309 sqlite3ExprDelete(db, pKey);
92366 sqlite3 *db;
92368 db = pParse->db;
92369 assert( db->nDb>iDb );
92371 pFix->zDb = db->aDb[iDb].zName;
92372 pFix->pSchema = db->aDb[iDb].pSchema;
92410 sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
92461 if( pFix->pParse->db->init.busy ){
92590 sqlite3 *db,
92595 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
92597 sqlite3_mutex_enter(db->mutex);
92598 db->xAuth = (sqlite3_xauth)xAuth;
92599 db->pAuthArg = pArg;
92600 sqlite3ExpirePreparedStatements(db);
92601 sqlite3_mutex_leave(db->mutex);
92629 sqlite3 *db = pParse->db; /* Database handle */
92630 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
92633 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
92635 ,db->auth.zAuthUser
92639 if( db->nDb>2 || iDb!=0 ){
92666 sqlite3 *db = pParse->db;
92673 if( db->xAuth==0 ) return;
92674 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
92705 assert( iDb>=0 && iDb<db->nDb );
92724 sqlite3 *db = pParse->db;
92730 if( db->init.busy || IN_DECLARE_VTAB ){
92734 if( db->xAuth==0 ){
92737 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
92739 ,db->auth.zAuthUser
92863 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
92872 pToplevel->db->mallocFailed = 1;
92922 sqlite3 *db;
92926 db = pParse->db;
92928 if( db->mallocFailed || pParse->nErr ){
92944 if( pParse->nTableLock>0 && db->init.busy==0 ){
92945 sqlite3UserAuthInit(db);
92946 if( db->auth.authLevel<UAUTH_User ){
92960 if( db->mallocFailed==0
92966 for(iDb=0; iDb<db->nDb; iDb++){
92974 db->aDb[iDb].pSchema->iGeneration /* P4 */
92976 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
92982 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
93015 if( v && pParse->nErr==0 && !db->mallocFailed ){
93049 sqlite3 *db = pParse->db;
93056 zSql = sqlite3VMPrintf(db, zFormat, ap);
93065 sqlite3DbFree(db, zErrMsg);
93066 sqlite3DbFree(db, zSql);
93093 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
93098 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
93102 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
93106 for(i=OMIT_TEMPDB; i<db->nDb; i++){
93108 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
93109 assert( sqlite3SchemaMutexHeld(db, j, 0) );
93110 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
93140 p = sqlite3FindTable(pParse->db, zName, zDbase);
93144 if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
93148 Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
93162 else if( pParse->db->auth.authLevel<UAUTH_User ){
93187 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
93188 zDb = pParse->db->aDb[iDb].zName;
93207 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
93211 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
93212 for(i=OMIT_TEMPDB; i<db->nDb; i++){
93214 Schema *pSchema = db->aDb[j].pSchema;
93216 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
93217 assert( sqlite3SchemaMutexHeld(db, j, 0) );
93227 static void freeIndex(sqlite3 *db, Index *p){
93229 sqlite3DeleteIndexSamples(db, p);
93231 sqlite3ExprDelete(db, p->pPartIdxWhere);
93232 sqlite3ExprListDelete(db, p->aColExpr);
93233 sqlite3DbFree(db, p->zColAff);
93234 if( p->isResized ) sqlite3DbFree(db, p->azColl);
93238 sqlite3DbFree(db, p);
93247 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
93251 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93252 pHash = &db->aDb[iDb].pSchema->idxHash;
93267 freeIndex(db, pIndex);
93269 db->flags |= SQLITE_InternChanges;
93273 ** Look through the list of open database files in db->aDb[] and if
93275 ** db->aDb[] structure to a smaller size, if possible.
93280 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
93282 for(i=j=2; i<db->nDb; i++){
93283 struct Db *pDb = &db->aDb[i];
93285 sqlite3DbFree(db, pDb->zName);
93290 db->aDb[j] = db->aDb[i];
93294 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
93295 db->nDb = j;
93296 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
93297 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
93298 sqlite3DbFree(db, db->aDb);
93299 db->aDb = db->aDbStatic;
93307 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){
93308 Db *pDb;
93309 assert( iDb<db->nDb );
93312 pDb = &db->aDb[iDb];
93313 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93322 pDb = &db->aDb[1];
93333 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){
93335 sqlite3BtreeEnterAll(db);
93336 for(i=0; i<db->nDb; i++){
93337 Db *pDb = &db->aDb[i];
93342 db->flags &= ~SQLITE_InternChanges;
93343 sqlite3VtabUnlockList(db);
93344 sqlite3BtreeLeaveAll(db);
93345 sqlite3CollapseDatabaseArray(db);
93351 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
93352 db->flags &= ~SQLITE_InternChanges;
93359 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
93365 sqlite3DbFree(db, pCol->zName);
93366 sqlite3ExprDelete(db, pCol->pDflt);
93367 sqlite3DbFree(db, pCol->zDflt);
93368 sqlite3DbFree(db, pCol->zType);
93369 sqlite3DbFree(db, pCol->zColl);
93371 sqlite3DbFree(db, pTable->aCol);
93384 ** The db parameter is optional. It is needed if the Table object
93387 ** db parameter can be used with db->pnBytesFreed to measure the memory
93390 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
93398 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
93403 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
93404 db->lookaside.nOut : 0 );
93410 if( !db || db->pnBytesFreed==0 ){
93415 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
93418 freeIndex(db, pIndex);
93422 sqlite3FkDelete(db, pTable);
93426 sqlite3DeleteColumnNames(db, pTable);
93427 sqlite3DbFree(db, pTable->zName);
93428 sqlite3DbFree(db, pTable->zColAff);
93429 sqlite3SelectDelete(db, pTable->pSelect);
93430 sqlite3ExprListDelete(db, pTable->pCheck);
93432 sqlite3VtabClear(db, pTable);
93434 sqlite3DbFree(db, pTable);
93437 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
93444 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
93446 Db *pDb;
93448 assert( db!=0 );
93449 assert( iDb>=0 && iDb<db->nDb );
93451 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93453 pDb = &db->aDb[iDb];
93455 sqlite3DeleteTable(db, p);
93456 db->flags |= SQLITE_InternChanges;
93472 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
93475 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
93498 ** of a database ("main", "temp" or the name of an attached db). This
93499 ** function returns the index of the named database in db->aDb[], or
93500 ** -1 if the named db cannot be found.
93502 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
93505 Db *pDb;
93507 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
93519 ** "temp" or the name of an attached db). This routine returns the
93520 ** index of the named database in db->aDb[], or -1 if the named db
93523 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
93526 zName = sqlite3NameFromToken(db, pName);
93527 i = sqlite3FindDbName(db, zName);
93528 sqlite3DbFree(db, zName);
93555 sqlite3 *db = pParse->db;
93558 if( db->init.busy ) {
93563 iDb = sqlite3FindDb(db, pName1);
93569 assert( db->init.iDb==0 || db->init.busy );
93570 iDb = db->init.iDb;
93584 if( !pParse->db->init.busy && pParse->nested==0
93585 && (pParse->db->flags & SQLITE_WriteSchema)==0
93641 sqlite3 *db = pParse->db;
93674 zName = sqlite3NameFromToken(db, pName);
93679 if( db->init.iDb==1 ) isTemp = 1;
93684 char *zDb = db->aDb[iDb].zName;
93715 char *zDb = db->aDb[iDb].zName;
93719 pTable = sqlite3FindTable(db, zName, zDb);
93724 assert( !db->init.busy || CORRUPT_DB );
93729 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
93735 pTable = sqlite3DbMallocZero(db, sizeof(Table));
93737 db->mallocFailed = 1;
93744 pTable->pSchema = db->aDb[iDb].pSchema;
93756 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93769 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
93792 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
93796 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
93830 sqlite3DbFree(db, zName);
93860 sqlite3 *db = pParse->db;
93863 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
93868 z = sqlite3NameFromToken(db, pName);
93873 sqlite3DbFree(db, z);
93879 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
93881 sqlite3DbFree(db, z);
94016 sqlite3DbFree(pParse->db, pCol->zType);
94017 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
94034 sqlite3 *db = pParse->db;
94038 if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
94046 sqlite3ExprDelete(db, pCol->pDflt);
94047 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
94048 sqlite3DbFree(db, pCol->zDflt);
94049 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
94053 sqlite3ExprDelete(db, pSpan->pExpr);
94164 sqlite3ExprListDelete(pParse->db, pList);
94177 sqlite3 *db = pParse->db;
94179 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
94188 sqlite3ExprDelete(pParse->db, pCheckExpr);
94200 sqlite3 *db;
94204 db = pParse->db;
94205 zColl = sqlite3NameFromToken(db, pToken);
94210 sqlite3DbFree(db, p->aCol[i].zColl);
94224 sqlite3DbFree(db, zColl);
94249 sqlite3 *db = pParse->db;
94250 u8 enc = ENC(db);
94251 u8 initbusy = db->init.busy;
94254 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
94281 sqlite3 *db = pParse->db;
94283 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94284 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
94346 static char *createTableStmt(sqlite3 *db, Table *p){
94368 db->mallocFailed = 1;
94414 static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
94420 zExtra = sqlite3DbMallocZero(db, nByte);
94499 sqlite3 *db = pParse->db;
94520 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
94536 assert( db->init.busy==0 );
94560 if( !db->init.imposterTable ){
94584 if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
94599 if( resizeIndexObject(db, pPk, pTab->nCol) ) return;
94624 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
94643 sqlite3 *db = pParse->db; /* The database connection */
94650 assert( !db->mallocFailed );
94654 assert( !db->init.busy || !pSelect );
94656 /* If the db->init.busy is 1 it means we are reading the SQL off the
94659 ** for the table from the db->init.newTnum field. (The page number
94662 if( db->init.busy ){
94663 p->tnum = db->init.newTnum;
94681 iDb = sqlite3SchemaToIndex(db, p->pSchema);
94703 if( !db->init.busy ){
94774 sqlite3DeleteTable(db, pSelTab);
94788 zStmt = createTableStmt(db, p);
94793 zStmt = sqlite3MPrintf(db,
94806 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
94814 sqlite3DbFree(db, zStmt);
94822 Db *pDb = &db->aDb[iDb];
94823 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94835 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
94841 if( db->init.busy ){
94844 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94848 db->mallocFailed = 1;
94852 db->flags |= SQLITE_InternChanges;
94890 sqlite3 *db = pParse->db;
94900 iDb = sqlite3SchemaToIndex(db, p->pSchema);
94909 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
94910 p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
94911 if( db->mallocFailed ) goto create_view_fail;
94933 sqlite3SelectDelete(db, pSelect);
94934 sqlite3ExprListDelete(db, pCNames);
94950 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
94952 u8 bEnabledLA; /* Saved db->lookaside.bEnabled state */
94998 bEnabledLA = db->lookaside.bEnabled;
95000 db->lookaside.bEnabled = 0;
95004 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
95009 db->lookaside.bEnabled = 0;
95011 xAuth = db->xAuth;
95012 db->xAuth = 0;
95014 db->xAuth = xAuth;
95025 sqlite3DeleteTable(db, pSelTab);
95026 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
95031 sqlite3SelectDelete(db, pSel);
95036 db->lookaside.bEnabled = bEnabledLA;
95047 static void sqliteViewResetAll(sqlite3 *db, int idx){
95049 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
95050 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
95051 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
95054 sqlite3DeleteColumnNames(db, pTab);
95059 DbClearProperty(db, idx, DB_UnresetViews);
95083 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
95086 Db *pDb;
95088 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95089 pDb = &db->aDb[iDb];
95130 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
95144 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
95186 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
95187 assert( iDb>=0 && iDb<pParse->db->nDb );
95206 const char *zDbName = pParse->db->aDb[iDb].zName;
95210 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
95224 sqlite3 *db = pParse->db;
95226 Db *pDb = &db->aDb[iDb];
95245 pTrigger->pSchema==db->aDb[1].pSchema );
95286 sqliteViewResetAll(db, iDb);
95296 sqlite3 *db = pParse->db;
95299 if( db->mallocFailed ){
95305 if( noErr ) db->suppressErr++;
95307 if( noErr ) db->suppressErr--;
95313 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95314 assert( iDb>=0 && iDb<db->nDb );
95326 const char *zDb = db->aDb[iDb].zName;
95340 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
95389 sqlite3SrcListDelete(db, pName);
95415 sqlite3 *db = pParse->db;
95451 pFKey = sqlite3DbMallocZero(db, nByte );
95496 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
95501 db->mallocFailed = 1;
95516 sqlite3DbFree(db, pFKey);
95518 sqlite3ExprListDelete(db, pFromCol);
95519 sqlite3ExprListDelete(db, pToCol);
95562 sqlite3 *db = pParse->db; /* The database connection */
95563 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
95567 db->aDb[iDb].zName ) ){
95606 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
95638 sqlite3 *db, /* Database connection */
95651 p = sqlite3DbMallocZero(db, nByte + nExtra);
95701 sqlite3 *db = pParse->db;
95702 Db *pDb; /* The specific table containing the indexed database */
95711 if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
95724 ** to search for the table. 'Fix' the table name to this db
95737 if( !db->init.busy ){
95739 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
95752 assert( db->mallocFailed==0 || pTab==0 );
95754 if( iDb==1 && db->aDb[iDb].pSchema!=pTab->pSchema ){
95766 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95768 pDb = &db->aDb[iDb];
95773 && db->init.busy==0
95808 zName = sqlite3NameFromToken(db, pName);
95814 if( !db->init.busy ){
95815 if( sqlite3FindTable(db, zName, 0)!=0 ){
95820 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
95824 assert( !db->init.busy );
95833 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
95864 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
95888 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
95890 if( db->mallocFailed ){
95902 pIndex->pSchema = db->aDb[iDb].pSchema;
95909 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95944 ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
95946 if( !db->mallocFailed ){
95978 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
96077 if( db->init.busy ){
96079 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
96084 db->mallocFailed = 1;
96087 db->flags |= SQLITE_InternChanges;
96089 pIndex->tnum = db->init.newTnum;
96132 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
96144 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
96150 sqlite3DbFree(db, zStmt);
96159 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
96172 if( db->init.busy || pTblName==0 ){
96191 if( pIndex ) freeIndex(db, pIndex);
96192 sqlite3ExprDelete(db, pPIWhere);
96193 sqlite3ExprListDelete(db, pList);
96194 sqlite3SrcListDelete(db, pTblName);
96195 sqlite3DbFree(db, zName);
96248 sqlite3 *db = pParse->db;
96252 if( db->mallocFailed ){
96259 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
96274 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
96279 const char *zDb = db->aDb[iDb].zName;
96297 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
96306 sqlite3SrcListDelete(db, pName);
96327 sqlite3 *db, /* Connection to notify of malloc failures */
96337 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
96357 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
96360 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
96364 db,
96371 sqlite3IdListDelete(db, pList);
96374 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
96381 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
96385 sqlite3DbFree(db, pList->a[i].zName);
96387 sqlite3DbFree(db, pList->a);
96388 sqlite3DbFree(db, pList);
96412 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
96421 ** db->mallocFailed flag will be set to true.
96424 sqlite3 *db, /* Database connection to notify of OOM errors */
96442 pNew = sqlite3DbRealloc(db, pSrc,
96445 assert( db->mallocFailed );
96449 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
96506 sqlite3 *db, /* Connection to notify of malloc failures */
96514 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
96518 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
96519 if( db->mallocFailed ){
96520 sqlite3SrcListDelete(db, pList);
96532 pItem->zName = sqlite3NameFromToken(db, pTable);
96533 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
96543 assert(pList || pParse->db->mallocFailed );
96558 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
96563 sqlite3DbFree(db, pItem->zDatabase);
96564 sqlite3DbFree(db, pItem->zName);
96565 sqlite3DbFree(db, pItem->zAlias);
96566 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
96567 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
96568 sqlite3DeleteTable(db, pItem->pTab);
96569 sqlite3SelectDelete(db, pItem->pSelect);
96570 sqlite3ExprDelete(db, pItem->pOn);
96571 sqlite3IdListDelete(db, pItem->pUsing);
96573 sqlite3DbFree(db, pList);
96603 sqlite3 *db = pParse->db;
96610 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
96617 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
96626 sqlite3ExprDelete(db, pOn);
96627 sqlite3IdListDelete(db, pUsing);
96628 sqlite3SelectDelete(db, pSubquery);
96648 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
96667 sqlite3ExprListDelete(pParse->db, pList);
96700 sqlite3 *db;
96705 db = pParse->db;
96706 assert( db!=0 );
96707 /* if( db->aDb[0].pBt==0 ) return; */
96714 for(i=0; i<db->nDb; i++){
96729 assert( pParse->db!=0 );
96746 assert( pParse->db!=0 );
96761 char *zName = sqlite3NameFromToken(pParse->db, pName);
96769 sqlite3DbFree(pParse->db, zName);
96781 sqlite3 *db = pParse->db;
96782 if( db->aDb[1].pBt==0 && !pParse->explain ){
96792 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
96799 db->aDb[1].pBt = pBt;
96800 assert( db->aDb[1].pSchema );
96801 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
96802 db->mallocFailed = 1;
96817 sqlite3 *db = pToplevel->db;
96819 assert( iDb>=0 && iDb<db->nDb );
96820 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
96822 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
96825 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
96837 sqlite3 *db = pParse->db;
96839 for(i=0; i<db->nDb; i++){
96840 Db *pDb = &db->aDb[i];
96935 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
96966 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
96970 zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
97006 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
97021 Db *pDb; /* A single database */
97023 sqlite3 *db = pParse->db; /* The database connection */
97027 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
97028 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
97059 sqlite3 *db = pParse->db; /* The database connection */
97074 zColl = sqlite3NameFromToken(pParse->db, pName1);
97076 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
97079 sqlite3DbFree(db, zColl);
97082 sqlite3DbFree(db, zColl);
97086 z = sqlite3NameFromToken(db, pObjName);
97088 zDb = db->aDb[iDb].zName;
97089 pTab = sqlite3FindTable(db, z, zDb);
97092 sqlite3DbFree(db, z);
97095 pIndex = sqlite3FindIndex(db, z, zDb);
97096 sqlite3DbFree(db, z);
97123 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
97125 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
97156 sqlite3 *db = pParse->db;
97162 zName = sqlite3NameFromToken(pParse->db, pName);
97174 pNew = sqlite3DbRealloc(db, pWith, nByte);
97176 pNew = sqlite3DbMallocZero(db
97179 assert( db->mallocFailed==0 || pNew==0 );
97182 sqlite3ExprListDelete(db, pArglist);
97183 sqlite3SelectDelete(db, pQuery);
97184 sqlite3DbFree(db, zName);
97200 SQLITE_PRIVATE void sqlite3WithDelete(sqlite3 *db, With *pWith){
97205 sqlite3ExprListDelete(db, pCte->pCols);
97206 sqlite3SelectDelete(db, pCte->pSelect);
97207 sqlite3DbFree(db, pCte->zName);
97209 sqlite3DbFree(db, pWith);
97238 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
97239 assert( !db->xCollNeeded || !db->xCollNeeded16 );
97240 if( db->xCollNeeded ){
97241 char *zExternal = sqlite3DbStrDup(db, zName);
97243 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
97244 sqlite3DbFree(db, zExternal);
97247 if( db->xCollNeeded16 ){
97249 sqlite3_value *pTmp = sqlite3ValueNew(db);
97253 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
97267 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
97273 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
97292 ** db for collation type name zName, length nName, or NULL, if no collation
97304 sqlite3 *db = pParse->db;
97308 p = sqlite3FindCollSeq(db, enc, zName, 0);
97314 callCollNeeded(db, enc, zName);
97315 p = sqlite3FindCollSeq(db, enc, zName, 0);
97317 if( p && !p->xCmp && synthCollSeq(db, p) ){
97341 sqlite3 *db = pParse->db;
97342 CollSeq *p = sqlite3GetCollSeq(pParse, ENC(db), pColl, zName);
97354 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
97367 sqlite3 *db, /* Database connection */
97372 pColl = sqlite3HashFind(&db->aCollSeq, zName);
97376 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1);
97387 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
97395 db->mallocFailed = 1;
97396 sqlite3DbFree(db, pDel);
97407 ** for the encoding 'enc' from the database 'db'.
97420 sqlite3 *db,
97427 pColl = findCollSeqEntry(db, zName, create);
97429 pColl = db->pDfltColl;
97548 ** structure is created and liked into the "db" structure if a
97561 sqlite3 *db, /* An open database */
97575 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
97579 p = functionSearch(&db->aFunc, h, zName, nName);
97601 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
97620 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
97626 sqlite3FuncDefInsert(&db->aFunc, pBest);
97637 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
97675 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
97683 db->mallocFailed = 1;
97731 sqlite3DeleteTable(pParse->db, pItem->pTab);
97759 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
97761 && (pParse->db->flags & SQLITE_WriteSchema)==0
97793 sqlite3 *db = pParse->db;
97794 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
97795 pWhere = sqlite3ExprDup(db, pWhere, 0);
97796 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
97799 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
97800 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
97807 sqlite3SelectDelete(db, pSel);
97868 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
97870 sqlite3ExprListDelete(pParse->db, pEList);
97892 sqlite3SelectDelete(pParse->db, pSelect);
97896 sqlite3ExprDelete(pParse->db, pWhere);
97897 sqlite3ExprListDelete(pParse->db, pOrderBy);
97898 sqlite3ExprDelete(pParse->db, pLimit);
97899 sqlite3ExprDelete(pParse->db, pOffset);
97927 sqlite3 *db; /* Main database structure */
97954 db = pParse->db;
97955 if( pParse->nErr || db->mallocFailed ){
97994 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
97995 assert( iDb<db->nDb );
97996 zDb = db->aDb[iDb].zName;
98049 if( db->flags & SQLITE_CountRows ){
98113 if( db->flags & SQLITE_CountRows ){
98136 aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
98152 sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
98210 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
98264 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
98272 sqlite3SrcListDelete(db, pTabList);
98273 sqlite3ExprDelete(db, pWhere);
98274 sqlite3DbFree(db, aToOpen);
98825 sqlite3 *db = sqlite3_context_db_handle(context);
98831 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
98989 sqlite3 *db = sqlite3_context_db_handle(context);
98991 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
98992 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
98993 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
99115 sqlite3 *db = sqlite3_context_db_handle(context);
99120 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
99135 sqlite3 *db = sqlite3_context_db_handle(context);
99137 sqlite3_result_int(context, sqlite3_changes(db));
99149 sqlite3 *db = sqlite3_context_db_handle(context);
99153 sqlite3_result_int(context, sqlite3_total_changes(db));
99386 sqlite3 *db = sqlite3_context_db_handle(context);
99395 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
99396 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
99397 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
99783 sqlite3 *db = sqlite3_context_db_handle(context);
99785 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
99786 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
99787 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
99964 sqlite3 *db = sqlite3_context_db_handle(context);
99972 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
100110 ** returns (void *)db, where db is the sqlite3* database pointer.
100122 pBest->db = sqlite3_context_db_handle(context);
100154 sqlite3 *db = sqlite3_context_db_handle(context);
100156 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
100192 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
100193 int rc = sqlite3_overload_function(db, "MATCH", 2);
100196 db->mallocFailed = 1;
100203 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
100205 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
100217 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
100224 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
100225 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
100226 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
100228 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
100229 setLikeOptFlag(db, "like",
100245 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
100254 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
100570 ** pParse->db->mallocFailed flag is set.
100611 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
100675 sqlite3DbFree(pParse->db, aiCol);
100811 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
100819 if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
100859 sqlite3 *db = pParse->db;
100861 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
100868 if( zColl==0 ) zColl = db->pDfltColl->zName;
100883 sqlite3 *db, /* The database connection */
100888 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
100905 ** the number of FK violations in the db) or +1 when deleting one (as this
100939 sqlite3 *db = pParse->db; /* Database handle */
100977 pRight = sqlite3Expr(db, TK_ID, zCol);
100979 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
100999 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
101009 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
101011 pAll = sqlite3ExprAnd(db, pAll, pEq);
101015 pWhere = sqlite3ExprAnd(db, pWhere, pNe);
101034 sqlite3ExprDelete(db, pWhere);
101095 sqlite3 *db = pParse->db;
101096 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
101109 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
101117 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
101129 if( (db->flags & SQLITE_DeferFKs)==0 ){
101252 sqlite3 *db = pParse->db; /* Database handle */
101262 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
101264 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
101265 zDb = db->aDb[iDb].zName;
101290 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
101296 if( !isIgnoreErrors || db->mallocFailed ) return;
101332 if( db->xAuth ){
101365 sqlite3DbFree(db, aiFree);
101379 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
101389 if( !isIgnoreErrors || db->mallocFailed ) return;
101396 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
101432 sqlite3SrcListDelete(db, pSrc);
101434 sqlite3DbFree(db, aiCol);
101449 if( pParse->db->flags&SQLITE_ForeignKeys ){
101490 if( pParse->db->flags&SQLITE_ForeignKeys ){
101550 sqlite3 *db = pParse->db; /* Database handle */
101559 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
101598 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
101599 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
101601 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
101603 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
101613 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
101614 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
101617 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
101618 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
101621 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
101628 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
101629 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
101634 pNew = sqlite3ExprDup(db, pDflt, 0);
101645 sqlite3DbFree(db, aiCol);
101656 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
101662 sqlite3SrcListAppend(db, 0, &tFrom, 0),
101670 enableLookaside = db->lookaside.bEnabled;
101671 db->lookaside.bEnabled = 0;
101673 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
101683 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
101684 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
101685 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
101688 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
101693 db->lookaside.bEnabled = enableLookaside;
101695 sqlite3ExprDelete(db, pWhere);
101696 sqlite3ExprDelete(db, pWhen);
101697 sqlite3ExprListDelete(db, pList);
101698 sqlite3SelectDelete(db, pSelect);
101699 if( db->mallocFailed==1 ){
101700 fkTriggerDelete(db, pTrigger);
101743 if( pParse->db->flags&SQLITE_ForeignKeys ){
101763 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
101767 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
101771 if( !db || db->pnBytesFreed==0 ){
101791 fkTriggerDelete(db, pFKey->apTrigger[0]);
101792 fkTriggerDelete(db, pFKey->apTrigger[1]);
101796 sqlite3DbFree(db, pFKey);
101874 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
101888 db->mallocFailed = 1;
101936 sqlite3 *db = sqlite3VdbeDb(v);
101939 db->mallocFailed = 1;
101972 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
102035 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
102056 sqlite3 *db = pParse->db; /* The database connection */
102057 Db *pDb; /* Database only autoinc table */
102069 pDb = &db->aDb[p->iDb];
102071 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
102113 sqlite3 *db = pParse->db;
102117 Db *pDb = &db->aDb[p->iDb];
102123 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
102258 sqlite3 *db; /* The main database structure */
102276 Db *pDb; /* The database containing table being inserted into */
102298 db = pParse->db;
102300 if( pParse->nErr || db->mallocFailed ){
102311 sqlite3SelectDelete(db, pSelect);
102324 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102325 assert( iDb<db->nDb );
102326 pDb = &db->aDb[iDb];
102464 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
102559 if( db->flags & SQLITE_CountRows ){
102569 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
102768 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
102788 if( (db->flags & SQLITE_CountRows)!=0 ){
102833 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
102840 sqlite3SrcListDelete(db, pTabList);
102841 sqlite3ExprListDelete(db, pList);
102842 sqlite3SelectDelete(db, pSelect);
102843 sqlite3IdListDelete(db, pColumn);
102844 sqlite3DbFree(db, aRegIdx);
102959 sqlite3 *db; /* Database connection */
102974 db = pParse->db;
103020 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
103047 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
103147 if( db->flags&SQLITE_RecTriggers ){
103335 if( db->flags&SQLITE_RecTriggers ){
103473 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
103607 sqlite3 *db = pParse->db;
103755 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
103759 if( (db->flags & SQLITE_CountRows)!=0 ){
103770 iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
103780 if( (db->flags & SQLITE_Vacuum)==0 && (
103848 if( db->flags & SQLITE_Vacuum ){
103929 sqlite3 *db, /* The database on which the SQL executes */
103941 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
103944 sqlite3_mutex_enter(db->mutex);
103945 sqlite3Error(db, SQLITE_OK);
103951 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
103972 && db->flags&SQLITE_NullCallback)) ){
103974 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
103991 db->mallocFailed = 1;
104003 sqlite3Error(db, SQLITE_ABORT);
104017 sqlite3DbFree(db, azCols);
104023 sqlite3DbFree(db, azCols);
104025 rc = sqlite3ApiExit(db, rc);
104027 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
104030 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
104033 sqlite3Error(db, SQLITE_NOMEM);
104039 assert( (rc&db->errMask)==rc );
104040 sqlite3_mutex_leave(db->mutex);
104162 int (*errcode)(sqlite3*db);
105009 ** by calling sqlite3DbFree(db, ).
105012 sqlite3 *db, /* Load the extension into this database connection */
105017 sqlite3_vfs *pVfs = db->pVfs;
105047 if( (db->flags & SQLITE_LoadExtension)==0 ){
105127 if( xInit(db, &zErrmsg, &sqlite3Apis) ){
105136 /* Append the new shared library handle to the db->aExtension array. */
105137 db, sizeof(handle)*(db->nExtension+1));
105141 if( db->nExtension>0 ){
105142 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
105144 sqlite3DbFree(db, db->aExtension);
105145 db->aExtension = aHandle;
105147 db->aExtension[db->nExtension++] = handle;
105151 sqlite3 *db, /* Load the extension into this database connection */
105157 sqlite3_mutex_enter(db->mutex);
105158 rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
105159 rc = sqlite3ApiExit(db, rc);
105160 sqlite3_mutex_leave(db->mutex);
105168 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
105170 assert( sqlite3_mutex_held(db->mutex) );
105171 for(i=0; i<db->nExtension; i++){
105172 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
105174 sqlite3DbFree(db, db->aExtension);
105181 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
105182 sqlite3_mutex_enter(db->mutex);
105184 db->flags |= SQLITE_LoadExtension;
105186 db->flags &= ~SQLITE_LoadExtension;
105188 sqlite3_mutex_leave(db->mutex);
105328 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
105354 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
105355 sqlite3ErrorWithMsg(db, rc,
105937 ** Interpret the given string as a temp db location. Return 1 for file
105960 sqlite3 *db = pParse->db;
105961 if( db->aDb[1].pBt!=0 ){
105962 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
105967 sqlite3BtreeClose(db->aDb[1].pBt);
105968 db->aDb[1].pBt = 0;
105969 sqlite3ResetAllSchemasOfConnection(db);
105983 sqlite3 *db = pParse->db;
105984 if( db->temp_store==ts ) return SQLITE_OK;
105988 db->temp_store = (u8)ts;
106041 static void setAllPagerFlags(sqlite3 *db){
106042 if( db->autoCommit ){
106043 Db *pDb = db->aDb;
106044 int n = db->nDb;
106054 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) );
106138 sqlite3 *db = pParse->db; /* The database connection */
106139 Db *pDb; /* The specific database being pragmaed */
106148 ** index of the database this pragma is being applied to in db.aDb[]. */
106151 pDb = &db->aDb[iDb];
106160 zLeft = sqlite3NameFromToken(db, pId);
106163 zRight = sqlite3MPrintf(db, "-%T", pValue);
106165 zRight = sqlite3NameFromToken(db, pValue);
106193 db->busyHandler.nBusy = 0;
106194 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
106278 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
106306 db->nextPagesize = sqlite3Atoi(zRight);
106307 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
106308 db->mallocFailed = 1;
106331 for(ii=0; ii<db->nDb; ii++){
106332 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
106386 eMode = db->dfltLockMode;
106392 ** set on all attached databases, as well as the main db file.
106399 assert(pDb==&db->aDb[0]);
106400 for(ii=2; ii<db->nDb; ii++){
106401 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
106404 db->dfltLockMode = (u8)eMode;
106450 for(ii=db->nDb-1; ii>=0; ii--){
106451 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
106496 db->nextAutovac = (u8)eAuto;
106500 ** as an auto-vacuum capable db.
106567 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
106597 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
106602 if( pId2->n==0 ) db->szMmap = sz;
106603 for(ii=db->nDb-1; ii>=0; ii--){
106604 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
106605 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
106610 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
106637 returnSingleInt(v, "temp_store", db->temp_store);
106661 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
106668 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
106669 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
106705 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
106773 if( !db->autoCommit ){
106780 setAllPagerFlags(db);
106790 returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
106793 if( db->autoCommit==0 ){
106799 if( db->auth.authLevel==UAUTH_User ){
106806 db->flags |= mask;
106808 db->flags &= ~mask;
106809 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
106817 setAllPagerFlags(db);
106838 pTab = sqlite3FindTable(db, zRight, zDb);
106906 pIdx = sqlite3FindIndex(db, zRight, zDb);
106946 pTab = sqlite3FindTable(db, zRight, zDb);
106974 for(i=0; i<db->nDb; i++){
106975 if( db->aDb[i].pBt==0 ) continue;
106976 assert( db->aDb[i].zName!=0 );
106979 db->aDb[i].zName,
106980 sqlite3BtreeGetFilename(db->aDb[i].pBt));
106992 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
107005 pTab = sqlite3FindTable(db, zRight, zDb);
107067 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
107082 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
107104 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
107135 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
107144 sqlite3DbFree(db, aiCols);
107172 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
107203 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
107204 ** then iDb is set to the index of the database identified by <db>.
107231 for(i=0; i<db->nDb; i++){
107250 assert( sqlite3SchemaMutexHeld(db, i, 0) );
107251 pTbls = &db->aDb[i].pSchema->tblHash;
107275 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
107318 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
107449 returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
107457 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
107458 DbHasProperty(db, 0, DB_Empty)
107462 SCHEMA_ENC(db) = ENC(db) =
107596 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
107599 db->xWalCallback==sqlite3WalDefaultHook ?
107600 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
107613 sqlite3_db_release_memory(db);
107621 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
107629 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
107631 returnSingleInt(v, "timeout", db->busyTimeout);
107668 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
107671 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
107687 for(i=0; i<db->nDb; i++){
107691 if( db->aDb[i].zName==0 ) continue;
107692 pBt = db->aDb[i].pBt;
107695 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
107699 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
107708 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
107712 if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
107725 sqlite3_key_v2(db, zDb, zKey, i/2);
107727 sqlite3_rekey_v2(db, zDb, zKey, i/2);
107752 sqlite3DbFree(db, zLeft);
107753 sqlite3DbFree(db, zRight);
107786 sqlite3 *db = pData->db;
107787 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
107792 sqlite3DbFree(db, *pData->pzErrMsg);
107794 if( z==0 ) db->mallocFailed = 1;
107796 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT;
107813 sqlite3 *db = pData->db;
107818 assert( sqlite3_mutex_held(db->mutex) );
107819 DbClearProperty(db, iDb, DB_Empty);
107820 if( db->mallocFailed ){
107825 assert( iDb>=0 && iDb<db->nDb );
107831 ** But because db->init.busy is set to 1, no VDBE code is generated
107839 assert( db->init.busy );
107840 db->init.iDb = iDb;
107841 db->init.newTnum = sqlite3Atoi(argv[1]);
107842 db->init.orphanTrigger = 0;
107843 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
107844 rc = db->errCode;
107846 db->init.iDb = 0;
107848 if( db->init.orphanTrigger ){
107853 db->mallocFailed = 1;
107855 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
107870 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
107893 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
107900 Db *pDb;
107934 assert( iDb>=0 && iDb<db->nDb );
107935 assert( db->aDb[iDb].pSchema );
107936 assert( sqlite3_mutex_held(db->mutex) );
107937 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
107955 initData.db = db;
107964 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
107971 pDb = &db->aDb[iDb];
107974 DbSetProperty(db, 1, DB_SchemaLoaded);
107986 sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc));
107999 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
108016 ** For an attached db, it is an error if the encoding is not the same
108023 /* If opening the main database, set ENC(db). */
108026 ENC(db) = encoding;
108028 db) = SQLITE_UTF8;
108031 /* If opening an attached database, the encoding much match ENC(db) */
108032 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
108033 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
108040 DbSetProperty(db, iDb, DB_Empty);
108042 pDb->pSchema->enc = ENC(db);
108066 sqlite3SetString(pzErrMsg, db, "unsupported file format");
108077 db->flags &= ~SQLITE_LegacyFileFmt;
108082 assert( db->init.busy );
108085 zSql = sqlite3MPrintf(db,
108087 db->aDb[iDb].zName, zMasterName);
108091 xAuth = db->xAuth;
108092 db->xAuth = 0;
108094 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
108096 db->xAuth = xAuth;
108100 sqlite3DbFree(db, zSql);
108103 sqlite3AnalysisLoad(db, iDb);
108107 if( db->mallocFailed ){
108109 sqlite3ResetAllSchemasOfConnection(db);
108111 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
108120 DbSetProperty(db, iDb, DB_SchemaLoaded);
108136 db->mallocFailed = 1;
108148 ** bit is set in the flags field of the Db structure. If the database
108151 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
108153 int commit_internal = !(db->flags&SQLITE_InternChanges);
108155 assert( sqlite3_mutex_held(db->mutex) );
108156 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
108157 assert( db->init.busy==0 );
108159 db->init.busy = 1;
108160 ENC(db) = SCHEMA_ENC(db);
108161 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
108162 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
108163 rc = sqlite3InitOne(db, i, pzErrMsg);
108165 sqlite3ResetOneSchema(db, i);
108174 assert( db->nDb>1 );
108175 if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
108176 rc = sqlite3InitOne(db, 1, pzErrMsg);
108178 sqlite3ResetOneSchema(db, 1);
108183 db->init.busy = 0;
108185 sqlite3CommitInternalChanges(db);
108197 sqlite3 *db = pParse->db;
108198 assert( sqlite3_mutex_held(db->mutex) );
108199 if( !db->init.busy ){
108200 rc = sqlite3Init(db, &pParse->zErrMsg);
108216 sqlite3 *db = pParse->db;
108222 assert( sqlite3_mutex_held(db->mutex) );
108223 for(iDb=0; iDb<db->nDb; iDb++){
108225 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
108234 db->mallocFailed = 1;
108244 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
108245 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
108246 sqlite3ResetOneSchema(db, iDb);
108259 ** which database file in db->aDb[] the schema refers to.
108264 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
108273 ** -1000000 as the incorrect index into db->aDb[] is much
108277 assert( sqlite3_mutex_held(db->mutex) );
108279 for(i=0; ALWAYS(i<db->nDb); i++){
108280 if( db->aDb[i].pSchema==pSchema ){
108284 assert( i>=0 && i<db->nDb );
108294 sqlite3 *db = pParse->db;
108295 sqlite3DbFree(db, pParse->aLabel);
108296 sqlite3ExprListDelete(db, pParse->pConstExpr);
108304 sqlite3 *db, /* Database handle. */
108318 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
108325 assert( !db->mallocFailed );
108326 assert( sqlite3_mutex_held(db->mutex) );
108351 for(i=0; i<db->nDb; i++) {
108352 Btree *pBt = db->aDb[i].pBt;
108357 const char *zDb = db->aDb[i].zName;
108358 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
108359 testcase( db->flags & SQLITE_ReadUncommitted );
108365 sqlite3VtabUnlockList(db);
108367 pParse->db = db;
108371 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
108375 sqlite3ErrorWithMsg(db, SQLITE_TOOBIG, "statement too long");
108376 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
108379 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
108382 sqlite3DbFree(db, zSqlCopy);
108392 if( db->mallocFailed ){
108399 if( db->mallocFailed ){
108430 if( db->init.busy==0 ){
108434 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
108442 sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg);
108443 sqlite3DbFree(db, zErrMsg);
108445 sqlite3Error(db, rc);
108452 sqlite3DbFree(db, pT);
108458 sqlite3StackFree(db, pParse);
108459 rc = sqlite3ApiExit(db, rc);
108460 assert( (rc&db->errMask)==rc );
108464 sqlite3 *db, /* Database handle. */
108478 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
108481 sqlite3_mutex_enter(db->mutex);
108482 sqlite3BtreeEnterAll(db);
108483 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
108486 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
108488 sqlite3BtreeLeaveAll(db);
108489 sqlite3_mutex_leave(db->mutex);
108506 sqlite3 *db;
108511 db = sqlite3VdbeDb(p);
108512 assert( sqlite3_mutex_held(db->mutex) );
108513 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
108516 db->mallocFailed = 1;
108540 sqlite3 *db, /* Database handle. */
108547 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
108552 sqlite3 *db, /* Database handle. */
108559 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
108570 sqlite3 *db, /* Database handle. */
108589 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
108598 sqlite3_mutex_enter(db->mutex);
108599 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
108601 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
108613 sqlite3DbFree(db, zSql8);
108614 rc = sqlite3ApiExit(db, rc);
108615 sqlite3_mutex_leave(db->mutex);
108628 sqlite3 *db, /* Database handle. */
108635 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
108640 sqlite3 *db, /* Database handle. */
108647 rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
108720 static void clearSelect(sqlite3 *db, Select *p, int bFree){
108723 sqlite3ExprListDelete(db, p->pEList);
108724 sqlite3SrcListDelete(db, p->pSrc);
108725 sqlite3ExprDelete(db, p->pWhere);
108726 sqlite3ExprListDelete(db, p->pGroupBy);
108727 sqlite3ExprDelete(db, p->pHaving);
108728 sqlite3ExprListDelete(db, p->pOrderBy);
108729 sqlite3ExprDelete(db, p->pLimit);
108730 sqlite3ExprDelete(db, p->pOffset);
108731 sqlite3WithDelete(db, p->pWith);
108732 if( bFree ) sqlite3DbFree(db, p);
108768 sqlite3 *db = pParse->db;
108769 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
108771 assert( db->mallocFailed );
108776 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
108779 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
108789 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
108792 if( db->mallocFailed ) {
108793 clearSelect(db, pNew, pNew!=&standin);
108817 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
108818 clearSelect(db, p, 1);
108969 sqlite3 *db = pParse->db;
108979 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
108980 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
108989 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
109101 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
109205 if( pParse->db->mallocFailed ) return;
109427 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
109652 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
109659 p->enc = ENC(db);
109660 p->db = db;
109663 db->mallocFailed = 1;
109723 sqlite3 *db = pParse->db;
109727 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
109733 if( !pColl ) pColl = db->pDfltColl;
109769 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
109815 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
110080 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
110081 zOrigDb = pNC->pParse->db->aDb[iDb].zName;
110176 sqlite3 *db = pParse->db;
110186 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
110188 fullNames = (db->flags & SQLITE_FullColNames)!=0;
110189 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
110216 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
110219 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
110226 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
110252 sqlite3 *db = pParse->db; /* Database connection */
110263 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
110278 zName = sqlite3DbStrDup(db, zName);
110291 zName = sqlite3MPrintf(db, "%s",
110295 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
110298 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
110301 if( db->mallocFailed ){
110302 sqlite3DbFree(db, zName);
110317 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
110318 sqlite3DbFree(db, zName);
110326 if( db->mallocFailed ){
110328 sqlite3DbFree(db, aCol[j].zName);
110330 sqlite3DbFree(db, aCol);
110354 sqlite3 *db = pParse->db;
110365 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
110366 if( db->mallocFailed ) return;
110373 pCol->zType = sqlite3DbStrDup(db,
110381 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
110393 sqlite3 *db = pParse->db;
110396 savedFlags = db->flags;
110397 db->flags &= ~SQLITE_FullColNames;
110398 db->flags |= SQLITE_ShortColNames;
110402 db->flags = savedFlags;
110403 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
110409 assert( db->lookaside.bEnabled==0 );
110416 if( db->mallocFailed ){
110417 sqlite3DeleteTable(db, pTab);
110433 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
110551 sqlite3 *db = pParse->db;
110552 KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
110564 if( pColl==0 ) pColl = db->pDfltColl;
110737 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
110836 sqlite3 *db; /* Database connection */
110847 db = pParse->db;
111008 sqlite3ExprListDelete(db, p->pOrderBy);
111013 sqlite3ExprDelete(db, p->pLimit);
111093 sqlite3ExprDelete(db, p->pLimit);
111145 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
111153 *apColl = db->pDfltColl;
111178 sqlite3SelectDelete(db, pDelete);
111245 if( pParse->db->mallocFailed ) return 0;
111462 sqlite3 *db; /* Database connection */
111473 db = pParse->db;
111494 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
111501 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
111518 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
111534 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
111544 assert( nOrderBy>=nExpr || db->mallocFailed );
111548 pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
111578 sqlite3ExprDelete(db, p->pLimit);
111580 sqlite3ExprDelete(db, p->pOffset);
111725 sqlite3SelectDelete(db, p->pPrior);
111756 sqlite3 *db, /* Report malloc errors to this connection */
111769 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
111770 sqlite3ExprDelete(db, pExpr);
111774 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
111775 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
111777 substSelect(db, pExpr->x.pSelect, iTable, pEList, 1);
111779 substExprList(db, pExpr->x.pList, iTable, pEList);
111785 sqlite3 *db, /* Report malloc errors here */
111793 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
111797 sqlite3 *db, /* Report malloc errors here */
111808 substExprList(db, p->pEList, iTable, pEList);
111809 substExprList(db, p->pGroupBy, iTable, pEList);
111810 substExprList(db, p->pOrderBy, iTable, pEList);
111811 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
111812 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
111816 substSelect(db, pItem->pSelect, iTable, pEList, 1);
111818 substExprList(db, pItem->u1.pFuncArg, iTable, pEList);
111983 sqlite3 *db = pParse->db;
111989 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
112169 pNew = sqlite3SelectDup(db, p, 0);
112187 if( db->mallocFailed ) return 1;
112198 sqlite3DbFree(db, pSubitem->zDatabase);
112199 sqlite3DbFree(db, pSubitem->zName);
112200 sqlite3DbFree(db, pSubitem->zAlias);
112250 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112252 assert( db->mallocFailed );
112273 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
112274 if( db->mallocFailed ){
112283 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
112304 char *zName = sqlite3DbStrDup(db, pList->a[i].zSpan);
112329 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
112334 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
112335 sqlite3ExprDup(db, pSub->pHaving, 0));
112337 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
112339 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
112341 substSelect(db, pParent, iParent, pSub->pEList, 0);
112363 sqlite3SelectDelete(db, pSub1);
112415 sqlite3 *db, /* The database connection (for malloc()) */
112430 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
112437 pNew = sqlite3ExprDup(db, pWhere, 0);
112438 pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
112439 pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew);
112572 sqlite3 *db;
112591 db = pParse->db;
112592 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
112599 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0));
112689 sqlite3 *db = pParse->db;
112714 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
112717 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
112721 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
112722 if( db->mallocFailed ) return SQLITE_NOMEM;
112840 sqlite3 *db = pParse->db;
112845 if( db->mallocFailed ){
112882 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
112885 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
112913 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
112931 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
112960 int flags = pParse->db->flags;
112998 if( db->mallocFailed ) break;
113004 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
113005 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
113044 pRight = sqlite3Expr(db, TK_ID, zName);
113049 pLeft = sqlite3Expr(db, TK_ID, zTabName);
113052 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
113056 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
113069 pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
113072 db, "%s.%s.%s",
113078 sqlite3DbFree(db, zToFree);
113090 sqlite3ExprListDelete(db, pEList);
113094 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
113126 ** and/or pParse->db->mallocFailed.
113222 sqlite3 *db;
113224 db = pParse->db;
113225 if( db->mallocFailed ) return;
113228 if( pParse->nErr || db->mallocFailed ) return;
113230 if( pParse->nErr || db->mallocFailed ) return;
113337 pColl = pParse->db->pDfltColl;
113389 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
113435 sqlite3 *db; /* The database connection */
113442 db = pParse->db;
113443 if( p==0 || db->mallocFailed || pParse->nErr ){
113467 sqlite3ExprListDelete(db, p->pOrderBy);
113475 if( pParse->nErr || db->mallocFailed ){
113525 if( db->mallocFailed ) goto select_end;
113587 && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
113601 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
113652 if( db->mallocFailed ) goto select_end;
113691 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
113859 if( db->mallocFailed ) goto select_end;
113986 if( orderByGrp && OptimizationEnabled(db, SQLITE_GroupByOrder)
114111 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
114192 pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
114194 if( pMinMax && !db->mallocFailed ){
114207 sqlite3ExprListDelete(db, pDel);
114225 sqlite3ExprListDelete(db, pDel);
114264 sqlite3DbFree(db, sAggInfo.aCol);
114265 sqlite3DbFree(db, sAggInfo.aFunc);
114393 sqlite3 *db, /* The database on which the SQL executes */
114404 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
114418 db->errCode = SQLITE_NOMEM;
114422 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
114434 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
114447 db->errCode = SQLITE_NOMEM;
114496 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
114501 sqlite3ExprDelete(db, pTmp->pWhere);
114502 sqlite3ExprListDelete(db, pTmp->pExprList);
114503 sqlite3SelectDelete(db, pTmp->pSelect);
114504 sqlite3IdListDelete(db, pTmp->pIdList);
114506 sqlite3DbFree(db, pTmp);
114525 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
114534 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
114572 sqlite3 *db = pParse->db; /* The database connection */
114574 Token *pName; /* The unqualified db name */
114575 DbFixer sFix; /* State vector for the DB fixer */
114591 /* Figure out the db that the trigger will be created in */
114597 if( !pTableName || db->mallocFailed ){
114609 if( db->init.busy && iDb!=1 ){
114610 sqlite3DbFree(db, pTableName->a[0].zDatabase);
114620 if( db->init.busy==0 && pName2->n==0 && pTab
114621 && pTab->pSchema==db->aDb[1].pSchema ){
114626 if( db->mallocFailed ) goto trigger_cleanup;
114635 if( db->init.iDb==1 ){
114644 db->init.orphanTrigger = 1;
114655 zName = sqlite3NameFromToken(db, pName);
114659 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114660 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
114664 assert( !db->init.busy );
114689 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
114694 const char *zDb = db->aDb[iTabDb].zName;
114695 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
114716 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
114720 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
114721 pTrigger->pSchema = db->aDb[iDb].pSchema;
114725 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
114726 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
114731 sqlite3DbFree(db, zName);
114732 sqlite3SrcListDelete(db, pTableName);
114733 sqlite3IdListDelete(db, pColumns);
114734 sqlite3ExprDelete(db, pWhen);
114736 sqlite3DeleteTrigger(db, pTrigger);
114753 sqlite3 *db = pParse->db; /* The database */
114761 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
114779 if( !db->init.busy ){
114787 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
114790 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
114792 sqlite3DbFree(db, z);
114795 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
114798 if( db->init.busy ){
114800 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
114801 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114804 db->mallocFailed = 1;
114815 sqlite3DeleteTrigger(db, pTrig);
114817 sqlite3DeleteTriggerStep(db, pStepList);
114827 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
114828 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
114830 sqlite3SelectDelete(db, pSelect);
114843 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
114846 sqlite3 *db, /* Database connection */
114852 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
114871 sqlite3 *db, /* The database connection */
114879 assert(pSelect != 0 || db->mallocFailed);
114881 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
114883 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
114887 sqlite3IdListDelete(db, pColumn);
114889 sqlite3SelectDelete(db, pSelect);
114900 sqlite3 *db, /* The database connection */
114908 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
114910 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
114911 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
114914 sqlite3ExprListDelete(db, pEList);
114915 sqlite3ExprDelete(db, pWhere);
114925 sqlite3 *db, /* Database connection */
114931 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
114933 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
114936 sqlite3ExprDelete(db, pWhere);
114943 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
114945 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
114946 sqlite3DbFree(db, pTrigger->zName);
114947 sqlite3DbFree(db, pTrigger->table);
114948 sqlite3ExprDelete(db, pTrigger->pWhen);
114949 sqlite3IdListDelete(db, pTrigger->pColumns);
114950 sqlite3DbFree(db, pTrigger);
114966 sqlite3 *db = pParse->db;
114968 if( db->mallocFailed ) goto drop_trigger_cleanup;
114976 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
114977 for(i=OMIT_TEMPDB; i<db->nDb; i++){
114979 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
114980 assert( sqlite3SchemaMutexHeld(db, j, 0) );
114981 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
114996 sqlite3SrcListDelete(db, pName);
115014 sqlite3 *db = pParse->db;
115017 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
115018 assert( iDb>=0 && iDb<db->nDb );
115025 const char *zDb = db->aDb[iDb].zName;
115070 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
115074 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
115075 pHash = &(db->aDb[iDb].pSchema->trigHash);
115084 sqlite3DeleteTrigger(db, pTrigger);
115085 db->flags |= SQLITE_InternChanges;
115124 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
115153 sqlite3 *db = pParse->db;
115157 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
115160 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
115161 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
115163 assert( iDb<db->nDb );
115164 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
115181 sqlite3 *db = pParse->db;
115207 sqlite3ExprListDup(db, pStep->pExprList, 0),
115208 sqlite3ExprDup(db, pStep->pWhere, 0),
115216 sqlite3SelectDup(db, pStep->pSelect, 0),
115217 sqlite3IdListDup(db, pStep->pIdList),
115225 sqlite3ExprDup(db, pStep->pWhere, 0)
115231 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
115234 sqlite3SelectDelete(db, pSelect);
115277 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
115292 sqlite3 *db = pParse->db; /* Database handle */
115307 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
115311 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
115321 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
115325 pSubParse->db = db;
115344 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
115352 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
115354 && db->mallocFailed==0
115359 sqlite3ExprDelete(db, pWhen);
115373 if( db->mallocFailed==0 ){
115388 sqlite3StackFree(db, pSubParse);
115444 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
115449 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
115530 || p->pSchema==pParse->db->aDb[1].pSchema );
115706 sqlite3 *db; /* The database structure */
115744 db = pParse->db;
115745 if( pParse->nErr || db->mallocFailed ){
115754 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
115799 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
115851 db->aDb[iDb].zName);
115996 sqlite3IndexAffinityStr(db, pPk), nPk);
116004 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
116216 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
116258 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
116266 sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
116267 sqlite3SrcListDelete(db, pTabList);
116268 sqlite3ExprListDelete(db, pChanges);
116269 sqlite3ExprDelete(db, pWhere);
116317 sqlite3 *db = pParse->db; /* Database connection */
116318 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
116434 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
116438 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
116444 ** Execute zSql on database db. Return an error code.
116446 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
116452 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
116453 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
116454 return sqlite3_errcode(db);
116457 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
116458 return vacuumFinalize(db, pStmt, pzErrMsg);
116462 ** Execute zSql on database db. The statement returns exactly
116465 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
116469 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
116473 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
116475 vacuumFinalize(db, pStmt, pzErrMsg);
116480 return vacuumFinalize(db, pStmt, pzErrMsg);
116525 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
116530 int saved_flags; /* Saved value of the db->flags */
116531 int saved_nChange; /* Saved value of db->nChange */
116532 int saved_nTotalChange; /* Saved value of db->nTotalChange */
116533 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */
116534 Db *pDb = 0; /* Database to detach at end of vacuum */
116539 if( !db->autoCommit ){
116540 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
116543 if( db->nVdbeActive>1 ){
116544 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
116551 saved_flags = db->flags;
116552 saved_nChange = db->nChange;
116553 saved_nTotalChange = db->nTotalChange;
116554 saved_xTrace = db->xTrace;
116555 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
116556 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
116557 db->xTrace = 0;
116559 pMain = db->aDb[0].pBt;
116576 nDb = db->nDb;
116577 if( sqlite3TempInMemory(db) ){
116582 rc = execSql(db, pzErrMsg, zSql);
116583 if( db->nDb>nDb ){
116584 pDb = &db->aDb[db->nDb-1];
116588 pTemp = db->aDb[db->nDb-1].pBt;
116600 if( db->nextPagesize ){
116604 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
116605 if( nKey ) db->nextPagesize = 0;
116609 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
116616 rc = execSql(db, pzErrMsg, "BEGIN;");
116624 db->nextPagesize = 0;
116628 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
116629 || NEVER(db->mallocFailed)
116636 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
116643 rc = execExecSql(db, pzErrMsg,
116649 rc = execExecSql(db, pzErrMsg,
116653 rc = execExecSql(db, pzErrMsg,
116662 assert( (db->flags & SQLITE_Vacuum)==0 );
116663 db->flags |= SQLITE_Vacuum;
116664 rc = execExecSql(db, pzErrMsg,
116671 assert( (db->flags & SQLITE_Vacuum)!=0 );
116672 db->flags &= ~SQLITE_Vacuum;
116677 rc = execExecSql(db, pzErrMsg,
116682 rc = execExecSql(db, pzErrMsg,
116695 rc = execSql(db, pzErrMsg,
116753 /* Restore the original value of db->flags */
116754 db->flags = saved_flags;
116755 db->nChange = saved_nChange;
116756 db->nTotalChange = saved_nTotalChange;
116757 db->xTrace = saved_xTrace;
116767 db->autoCommit = 1;
116775 /* This both clears the schemas and reduces the size of the db->aDb[]
116777 sqlite3ResetAllSchemasOfConnection(db);
116822 sqlite3 *db, /* Database in which module is registered */
116831 sqlite3_mutex_enter(db->mutex);
116833 if( sqlite3HashFind(&db->aModule, zName) ){
116837 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
116847 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
116850 db->mallocFailed = 1;
116851 sqlite3DbFree(db, pDel);
116855 rc = sqlite3ApiExit(db, rc);
116858 sqlite3_mutex_leave(db->mutex);
116867 sqlite3 *db, /* Database in which module is registered */
116873 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
116875 return createModule(db, zName, pModule, pAux, 0);
116882 sqlite3 *db, /* Database in which module is registered */
116889 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
116891 return createModule(db, zName, pModule, pAux, xDestroy);
116909 ** Return a pointer to the VTable object used by connection db to access
116912 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
116915 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
116924 sqlite3 *db = pVTab->db;
116926 assert( db );
116928 assert( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ZOMBIE );
116936 sqlite3DbFree(db, pVTab);
116944 ** Except, if argument db is not NULL, then the entry associated with
116945 ** connection db is left in the p->pVTable list.
116947 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
116958 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
116961 sqlite3 *db2 = pVTable->db;
116964 if( db2==db ){
116975 assert( !db || pRet );
116981 ** for table *p associated with database connection db from the linked
116983 ** used when closing database connection db to free all of its VTable
116987 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){
116991 assert( sqlite3BtreeHoldsAllMutexes(db) );
116992 assert( sqlite3_mutex_held(db->mutex) );
116995 if( (*ppVTab)->db==db ){
117009 ** shared b-tree databases opened using connection db are held by the
117025 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
117026 VTable *p = db->pDisconnect;
117027 db->pDisconnect = 0;
117029 assert( sqlite3BtreeHoldsAllMutexes(db) );
117030 assert( sqlite3_mutex_held(db->mutex) );
117033 sqlite3ExpirePreparedStatements(db);
117051 ** connection db is decremented immediately (which may lead to the
117056 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
117057 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
117061 if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
117063 sqlite3DbFree(db, p->azModuleArg);
117073 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
117076 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
117078 sqlite3DbFree(db, zArg);
117101 sqlite3 *db; /* Database connection */
117108 db = pParse->db;
117109 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
117114 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
117115 addModuleArgument(db, pTable, 0);
117116 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
117132 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
117146 sqlite3 *db = pParse->db;
117147 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
117157 sqlite3 *db = pParse->db; /* The database connection */
117170 if( !db->init.busy ){
117181 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
117191 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117196 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
117202 sqlite3DbFree(db, zStmt);
117207 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
117224 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
117227 db->mallocFailed = 1;
117266 sqlite3 *db,
117283 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
117285 *pzErr = sqlite3MPrintf(db,
117292 zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
117297 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
117299 sqlite3DbFree(db, zModuleName);
117302 pVTable->db = db;
117305 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117306 pTab->azModuleArg[1] = db->aDb[iDb].zName;
117309 assert( &db->pVtabCtx );
117313 sCtx.pPrior = db->pVtabCtx;
117315 db->pVtabCtx = &sCtx;
117316 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
117317 db->pVtabCtx = sCtx.pPrior;
117318 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
117323 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
117325 *pzErr = sqlite3MPrintf(db, "%s", zErr);
117328 sqlite3DbFree(db, pVTable);
117337 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
117389 sqlite3DbFree(db, zModuleName);
117401 sqlite3 *db = pParse->db;
117407 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
117413 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
117421 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
117425 sqlite3DbFree(db, zErr);
117431 ** Grow the db->aVTrans[] array so that there is room for at least one
117434 static int growVTrans(sqlite3 *db){
117438 if( (db->nVTrans%ARRAY_INCR)==0 ){
117440 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
117441 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
117445 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
117446 db->aVTrans = aVTrans;
117456 static void addToVTrans(sqlite3 *db, VTable *pVTab){
117458 db->aVTrans[db->nVTrans++] = pVTab;
117468 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
117470 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
117476 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
117481 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
117488 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
117491 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
117496 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
117497 rc = growVTrans(db);
117499 addToVTrans(db, sqlite3GetVTable(db, pTab));
117511 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
117519 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
117523 sqlite3_mutex_enter(db->mutex);
117524 pCtx = db->pVtabCtx;
117526 sqlite3Error(db, SQLITE_MISUSE);
117527 sqlite3_mutex_leave(db->mutex);
117533 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
117538 pParse->db = db;
117543 && !db->mallocFailed
117555 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
117556 sqlite3DbFree(db, zErr);
117564 sqlite3DeleteTable(db, pParse->pNewTable);
117566 sqlite3StackFree(db, pParse);
117570 rc = sqlite3ApiExit(db, rc);
117571 sqlite3_mutex_leave(db->mutex);
117582 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
117586 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
117596 p = vtabDisconnectAll(db, pTab);
117620 db, int offset){
117622 if( db->aVTrans ){
117623 VTable **aVTrans = db->aVTrans;
117624 db->aVTrans = 0;
117625 for(i=0; i<db->nVTrans; i++){
117636 sqlite3DbFree(db, aVTrans);
117637 db->nVTrans = 0;
117648 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *p){
117651 VTable **aVTrans = db->aVTrans;
117653 db->aVTrans = 0;
117654 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
117662 db->aVTrans = aVTrans;
117670 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
117671 callFinaliser(db, offsetof(sqlite3_module,xRollback));
117679 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
117680 callFinaliser(db, offsetof(sqlite3_module,xCommit));
117692 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
117696 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
117701 if( sqlite3VtabInSync(db) ){
117713 for(i=0; i<db->nVTrans; i++){
117714 if( db->aVTrans[i]==pVTab ){
117721 rc = growVTrans(db);
117725 int iSvpt = db->nStatement + db->nSavepoint;
117726 addToVTrans(db, pVTab);
117727 if( iSvpt ) rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, iSvpt-1);
117749 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
117754 if( db->aVTrans ){
117756 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
117757 VTable *pVTab = db->aVTrans[i];
117796 sqlite3 *db, /* Database connection for reporting malloc problems */
117818 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
117827 zLowerName = sqlite3DbStrDup(db, pDef->zName);
117833 sqlite3DbFree(db, zLowerName);
117841 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
117876 pToplevel->db->mallocFailed = 1;
117900 sqlite3 *db = pParse->db;
117904 pTab = sqlite3DbMallocZero(db, sizeof(Table) + nName);
117910 pTab->pSchema = db->aDb[0].pSchema;
117914 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117915 addModuleArgument(db, pTab, 0);
117916 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117917 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
117920 sqlite3DbFree(db, zErr);
117921 sqlite3VtabEponymousTableClear(db, pMod);
117931 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *db, Module *pMod){
117934 sqlite3DeleteColumnNames(db, pTab);
117935 sqlite3VtabClear(db, pTab);
117936 sqlite3DbFree(db, pTab);
117948 SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *db){
117953 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
117957 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
117958 return (int)aMap[db->vtabOnConflict-1];
117966 SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3 *db, int op, ...){
117971 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
117973 sqlite3_mutex_enter(db->mutex);
117977 VtabCtx *p = db->pVtabCtx;
117992 if( rc!=SQLITE_OK ) sqlite3Error(db, rc);
117993 sqlite3_mutex_leave(db->mutex);
118286 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
118654 sqlite3 *db = pParse->db; /* Database handle */
118671 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118847 assert( pParse->db->mallocFailed );
118935 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
119034 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
119036 pParse->db->mallocFailed = 1;
119123 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
119149 sqlite3 *db; /* Database connection */
119160 db = pParse->db;
119584 sqlite3DbFree(db, zStartAff);
119721 pOrTab = sqlite3StackAllocRaw(db,
119784 pExpr = sqlite3ExprDup(db, pExpr, 0);
119785 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
119814 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
119925 sqlite3ExprDelete(db, pAndExpr);
119931 if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
120018 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
120023 sqlite3StackFree(db, pEAlt);
120081 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
120083 sqlite3DbFree(db, p);
120089 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
120091 sqlite3DbFree(db, p);
120100 ** the db->mallocFailed flag so that higher-level functions can detect it.
120119 sqlite3 *db = pWC->pWInfo->pParse->db;
120120 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
120123 sqlite3ExprDelete(db, p);
120130 sqlite3DbFree(db, pOld);
120132 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
120255 sqlite3 *db = pParse->db; /* Database connection */
120259 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
120299 pPrefix = sqlite3Expr(db, TK_STRING, z);
120421 sqlite3 *db; /* Database connection (for malloc) */
120443 db = pWC->pWInfo->pParse->db;
120444 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
120547 sqlite3 *db = pParse->db; /* Database connection */
120564 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
120571 if( db->mallocFailed ) return;
120584 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
120598 testcase( db->mallocFailed );
120599 if( !db->mallocFailed ){
120759 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
120764 pDup = sqlite3ExprDup(db, pLeft, 0);
120777 sqlite3ExprListDelete(db, pList);
120804 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
120931 sqlite3 *db = pParse->db; /* Database connection */
120933 if( db->mallocFailed ){
120984 pDup = sqlite3ExprDup(db, pExpr, 0);
120985 if( db->mallocFailed ){
120986 sqlite3ExprDelete(db, pDup);
121041 sqlite3ExprDup(db, pExpr->pLeft, 0),
121042 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
121091 pStr2 = sqlite3ExprDup(db, pStr1, 0);
121097 if( noCase && !pParse->db->mallocFailed ){
121107 if( !db->mallocFailed ){
121124 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
121132 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
121168 0, sqlite3ExprDup(db, pRight, 0), 0);
121195 && OptimizationEnabled(db, SQLITE_Stat34)
121203 sqlite3ExprDup(db, pLeft, 0),
121283 sqlite3 *db = pWC->pWInfo->pParse->db;
121286 sqlite3ExprDelete(db, a->pExpr);
121289 whereOrInfoDelete(db, a->u.pOrInfo);
121291 whereAndInfoDelete(db, a->u.pAndInfo);
121295 sqlite3DbFree(db, pWC->a);
121386 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
121622 if( pColl==0 ) pColl = pParse->db->pDfltColl;
122047 pPartial = sqlite3ExprAnd(pParse->db, pPartial,
122048 sqlite3ExprDup(pParse->db, pExpr, 0));
122062 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
122095 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
122189 sqlite3ExprDelete(pParse->db, pPartial);
122249 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
122325 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
122335 pParse->db->mallocFailed = 1;
122478 if( pParse->db->mallocFailed==0 ){
122485 || pParse->db->mallocFailed
122495 || pParse->db->mallocFailed );
122504 || pParse->db->mallocFailed );
122509 || pParse->db->mallocFailed );
122579 static char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
122582 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
122634 sqlite3 *db = pParse->db;
122638 u8 aff = sqlite3IndexColumnAffinity(db, p, nEq);
122659 rc = sqlite3Stat4Column(db, p->aSample[i].p, p->aSample[i].n, nEq, &pVal);
122786 aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq);
122945 aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1);
123097 static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){
123104 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
123105 sqlite3DbFree(db, p->u.btree.pIndex);
123114 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
123115 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
123116 whereLoopClearUnion(db, p);
123123 static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
123127 paNew = sqlite3DbMallocRaw(db, sizeof(p->aLTerm[0])*n);
123130 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
123139 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
123140 whereLoopClearUnion(db, pTo);
123141 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
123158 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
123159 whereLoopClear(db, p);
123160 sqlite3DbFree(db, p);
123166 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
123172 sqlite3DbFree(db, pLevel->u.in.aInLoop);
123179 whereLoopDelete(db, p);
123181 sqlite3DbFree(db, pWInfo);
123366 sqlite3 *db = pWInfo->pParse->db;
123424 *ppPrev = p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
123446 whereLoopDelete(db, pToDel);
123449 whereLoopXfer(db, p, pTemplate);
123564 sqlite3 *db = pParse->db; /* Database connection malloc context */
123581 if( db->mallocFailed ) return SQLITE_NOMEM;
123629 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
123680 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
123808 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
124007 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
124103 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan)
124174 sqlite3 *db;
124191 db = pParse->db;
124206 if( whereLoopResize(db, pNew, nConstraint) ){
124207 sqlite3DbFree(db, pIdxInfo);
124335 sqlite3DbFree(db, pIdxInfo);
124477 sqlite3 *db = pWInfo->pParse->db;
124510 if( rc || db->mallocFailed ) break;
124513 whereLoopClear(db, pNew);
124561 sqlite3 *db = pWInfo->pParse->db; /* Database connection */
124590 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
124624 if( !pColl ) pColl = db->pDfltColl;
124627 if( !pColl ) pColl = db->pDfltColl;
124716 if( !pColl ) pColl = db->pDfltColl;
124878 sqlite3 *db; /* The database connection */
124897 db = pParse->db;
124920 pSpace = sqlite3DbMallocRaw(db, nSpace);
125145 sqlite3DbFree(db, pSpace);
125203 sqlite3DbFree(db, pSpace);
125403 sqlite3 *db; /* Database connection */
125412 db = pParse->db;
125422 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
125450 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
125451 if( db->mallocFailed ){
125452 sqlite3DbFree(db, pWInfo);
125530 if( db->mallocFailed ) goto whereBeginError;
125573 if( db->mallocFailed ) goto whereBeginError;
125576 if( db->mallocFailed ) goto whereBeginError;
125579 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
125582 if( pParse->nErr || NEVER(db->mallocFailed) ){
125614 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
125676 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
125683 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
125778 if( db->mallocFailed ) goto whereBeginError;
125794 if( db->mallocFailed ) goto whereBeginError;
125816 whereInfoFree(db, pWInfo);
125832 sqlite3 *db = pParse->db;
125921 if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
125966 && !db->mallocFailed
125998 whereInfoFree(db, pWInfo);
126079 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
126138 sqlite3 *db = pParse->db;
126141 sqlite3ExprDelete(db, pA->pRight);
126174 && pParse->db->init.busy==0
127437 sqlite3SelectDelete(pParse->db, (yypminor->yy3));
127443 sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
127458 sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
127466 sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
127472 sqlite3WithDelete(pParse->db, (yypminor->yy59));
127483 sqlite3ExprDelete(pParse->db, (yypminor->yy132));
127490 sqlite3IdListDelete(pParse->db, (yypminor->yy408));
127496 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy473));
127501 sqlite3IdListDelete(pParse->db, (yypminor->yy378).b);
128196 pParse->db->lookaside.bEnabled = 0;
128231 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
128441 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
128451 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
128479 sqlite3SelectDelete(pParse->db, pLhs);
128565 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
128581 {yygotominor.yy65 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy65));}
128630 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy65);
128644 {yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
128767 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
128770 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
128840 if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
128939 sqlite3ExprListDelete(pParse->db, pList);
128958 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy346.pExpr);
128978 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
128992 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
129008 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
129022 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
129031 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
129038 sqlite3SrcListDelete(pParse->db, pSrc);
129053 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
129066 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
129067 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
129094 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
129214 { yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
129217 {yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
129220 {yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
129223 {yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
129290 pParse->db->lookaside.bEnabled = 0;
130301 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
130302 sqlite3 *db = pParse->db; /* The database connection */
130306 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
130307 if( db->nVdbeActive==0 ){
130308 db->u1.isInterrupted = 0;
130317 db->mallocFailed = 1;
130325 enableLookaside = db->lookaside.bEnabled;
130326 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
130327 while( !db->mallocFailed && zSql[i]!=0 ){
130338 if( db->u1.isInterrupted ){
130366 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
130372 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
130384 db->lookaside.bEnabled = enableLookaside;
130385 if( db->mallocFailed ){
130389 pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
130404 sqlite3DbFree(db, pParse->aTableLock);
130418 sqlite3DeleteTable(db, pParse->pNewTable);
130421 if( pParse->bFreeWith ) sqlite3WithDelete(db, pParse->pWith);
130422 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
130423 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
130424 sqlite3DbFree(db, pParse->azVar);
130428 sqlite3DbFree(db, p);
130433 sqlite3DeleteTable(db, p);
130776 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
130809 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
130842 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
131474 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
131477 if( db->lookaside.nOut ){
131484 if( db->lookaside.bMalloced ){
131485 sqlite3_free(db->lookaside.pStart);
131504 db->lookaside.pStart = pStart;
131505 db->lookaside.pFree = 0;
131506 db->lookaside.sz = (u16)sz;
131513 p->pNext = db->lookaside.pFree;
131514 db->lookaside.pFree = p;
131517 db->lookaside.pEnd = p;
131518 db->lookaside.bEnabled = 1;
131519 db->lookaside.bMalloced = pBuf==0 ?1:0;
131521 db->lookaside.pStart = db;
131522 db->lookaside.pEnd = db;
131523 db->lookaside.bEnabled = 0;
131524 db->lookaside.bMalloced = 0;
131533 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3 *db){
131535 if( !sqlite3SafetyCheckOk(db) ){
131540 return db->mutex;
131547 SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3 *db){
131551 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
131553 sqlite3_mutex_enter(db->mutex);
131554 sqlite3BtreeEnterAll(db);
131555 for(i=0; i<db->nDb; i++){
131556 Btree *pBt = db->aDb[i].pBt;
131562 sqlite3BtreeLeaveAll(db);
131563 sqlite3_mutex_leave(db->mutex);
131570 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
131579 rc = setupLookaside(db, pBuf, sz, cnt);
131596 int oldFlags = db->flags;
131598 db->flags |= aFlagOp[i].mask;
131600 db->flags &= ~aFlagOp[i].mask;
131602 if( oldFlags!=db->flags ){
131603 sqlite3ExpirePreparedStatements(db);
131606 *pRes = (db->flags & aFlagOp[i].mask)!=0;
131689 SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3 *db){
131691 if( !sqlite3SafetyCheckOk(db) ){
131696 return db->lastRowid;
131702 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3 *db){
131704 if( !sqlite3SafetyCheckOk(db) ){
131709 return db->nChange;
131715 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3 *db){
131717 if( !sqlite3SafetyCheckOk(db) ){
131722 return db->nTotalChange;
131730 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
131731 while( db->pSavepoint ){
131732 Savepoint *pTmp = db->pSavepoint;
131733 db->pSavepoint = pTmp->pNext;
131734 sqlite3DbFree(db, pTmp);
131736 db->nSavepoint = 0;
131737 db->nStatement = 0;
131738 db->isTransactionSavepoint = 0;
131747 static void functionDestroy(sqlite3 *db, FuncDef *p){
131753 sqlite3DbFree(db, pDestructor);
131760 ** db. This is called when db is being closed.
131762 static void disconnectAllVtab(sqlite3 *db){
131766 sqlite3BtreeEnterAll(db);
131767 for(i=0; i<db->nDb; i++){
131768 Schema *pSchema = db->aDb[i].pSchema;
131769 if( db->aDb[i].pSchema ){
131772 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
131776 for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
131779 sqlite3VtabDisconnect(db, pMod->pEpoTab);
131782 sqlite3VtabUnlockList(db);
131783 sqlite3BtreeLeaveAll(db);
131785 UNUSED_PARAMETER(db);
131790 ** Return TRUE if database connection db has unfinalized prepared
131793 static int connectionIsBusy(sqlite3 *db){
131795 assert( sqlite3_mutex_held(db->mutex) );
131796 if( db->pVdbe ) return 1;
131797 for(j=0; j<db->nDb; j++){
131798 Btree *pBt = db->aDb[j].pBt;
131807 static int sqlite3Close(sqlite3 *db, int forceZombie){
131808 if( !db ){
131813 if( !sqlite3SafetyCheckSickOrOk(db) ){
131816 sqlite3_mutex_enter(db->mutex);
131819 disconnectAllVtab(db);
131823 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
131828 sqlite3VtabRollback(db);
131833 if( !forceZombie && connectionIsBusy(db) ){
131834 sqlite3ErrorWithMsg(db, SQLITE_BUSY, "unable to close due to unfinalized "
131836 sqlite3_mutex_leave(db->mutex);
131843 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
131849 db->magic = SQLITE_MAGIC_ZOMBIE;
131850 sqlite3LeaveMutexAndCloseZombie(db);
131863 SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
131864 SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
131868 ** Close the mutex on database connection db.
131870 ** Furthermore, if database connection db is a zombie (meaning that there
131871 ** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
131875 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
131883 if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
131884 sqlite3_mutex_leave(db->mutex);
131898 sqlite3RollbackAll(db, SQLITE_OK);
131901 sqlite3CloseSavepoints(db);
131904 for(j=0; j<db->nDb; j++){
131905 struct Db *pDb = &db->aDb[j];
131915 if( db->aDb[1].pSchema ){
131916 sqlite3SchemaClear(db->aDb[1].pSchema);
131918 sqlite3VtabUnlockList(db);
131921 sqlite3CollapseDatabaseArray(db);
131922 assert( db->nDb<=2 );
131923 assert( db->aDb==db->aDbStatic );
131928 sqlite3ConnectionClosed(db);
131930 for(j=0; j<ArraySize(db->aFunc.a); j++){
131932 for(p=db->aFunc.a[j]; p; p=pHash){
131935 functionDestroy(db, p);
131937 sqlite3DbFree(db, p);
131942 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
131950 sqlite3DbFree(db, pColl);
131952 sqlite3HashClear(&db->aCollSeq);
131954 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
131959 sqlite3VtabEponymousTableClear(db, pMod);
131960 sqlite3DbFree(db, pMod);
131962 sqlite3HashClear(&db->aModule);
131965 sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
131966 sqlite3ValueFree(db->pErr);
131967 sqlite3CloseExtensions(db);
131969 sqlite3_free(db->auth.zAuthUser);
131970 sqlite3_free(db->auth.zAuthPW);
131973 db->magic = SQLITE_MAGIC_ERROR;
131981 sqlite3DbFree(db, db->aDb[1].pSchema);
131982 sqlite3_mutex_leave(db->mutex);
131983 db->magic = SQLITE_MAGIC_CLOSED;
131984 sqlite3_mutex_free(db->mutex);
131985 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
131986 if( db->lookaside.bMalloced ){
131987 sqlite3_free(db->lookaside.pStart);
131989 sqlite3_free(db);
131999 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
132003 assert( sqlite3_mutex_held(db->mutex) );
132012 sqlite3BtreeEnterAll(db);
132013 schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
132015 for(i=0; i<db->nDb; i++){
132016 Btree *p = db->aDb[i].pBt;
132024 sqlite3VtabRollback(db);
132027 if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
132028 sqlite3ExpirePreparedStatements(db);
132029 sqlite3ResetAllSchemasOfConnection(db);
132031 sqlite3BtreeLeaveAll(db);
132034 db->nDeferredCons = 0;
132035 db->nDeferredImmCons = 0;
132036 db->flags &= ~SQLITE_DeferFKs;
132039 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
132040 db->xRollbackCallback(db->pRollbackArg);
132220 sqlite3 *db = (sqlite3 *)ptr;
132221 int timeout = db->busyTimeout;
132236 sqlite3OsSleep(db->pVfs, delay*1000);
132239 sqlite3 *db = (sqlite3 *)ptr;
132244 sqlite3OsSleep(db->pVfs, 1000000);
132273 sqlite3 *db,
132278 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132280 sqlite3_mutex_enter(db->mutex);
132281 db->busyHandler.xFunc = xBusy;
132282 db->busyHandler.pArg = pArg;
132283 db->busyHandler.nBusy = 0;
132284 db->busyTimeout = 0;
132285 sqlite3_mutex_leave(db->mutex);
132296 sqlite3 *db,
132302 if( !sqlite3SafetyCheckOk(db) ){
132307 sqlite3_mutex_enter(db->mutex);
132309 db->xProgress = xProgress;
132310 db->nProgressOps = (unsigned)nOps;
132311 db->pProgressArg = pArg;
132313 db->xProgress = 0;
132314 db->nProgressOps = 0;
132315 db->pProgressArg = 0;
132317 sqlite3_mutex_leave(db->mutex);
132326 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3 *db, int ms){
132328 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132331 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
132332 db->busyTimeout = ms;
132334 sqlite3_busy_handler(db, 0, 0);
132342 SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3 *db){
132344 if( !sqlite3SafetyCheckOk(db) ){
132349 db->u1.isInterrupted = 1;
132360 sqlite3 *db,
132374 assert( sqlite3_mutex_held(db->mutex) );
132400 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
132403 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
132420 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
132422 if( db->nVdbeActive ){
132423 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
132425 assert( !db->mallocFailed );
132428 sqlite3ExpirePreparedStatements(db);
132432 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
132433 assert(p || db->mallocFailed);
132440 functionDestroy(db, p);
132460 sqlite3 *db,
132469 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
132474 sqlite3 *db,
132488 if( !sqlite3SafetyCheckOk(db) ){
132492 sqlite3_mutex_enter(db->mutex);
132494 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
132502 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
132506 sqlite3DbFree(db, pArg);
132510 rc = sqlite3ApiExit(db, rc);
132511 sqlite3_mutex_leave(db->mutex);
132517 sqlite3 *db,
132530 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
132532 sqlite3_mutex_enter(db->mutex);
132533 assert( !db->mallocFailed );
132534 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
132535 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
132536 sqlite3DbFree(db, zFunc8);
132537 rc = sqlite3ApiExit(db, rc);
132538 sqlite3_mutex_leave(db->mutex);
132557 sqlite3 *db,
132565 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
132569 sqlite3_mutex_enter(db->mutex);
132570 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
132571 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
132574 rc = sqlite3ApiExit(db, rc);
132575 sqlite3_mutex_leave(db->mutex);
132588 SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
132592 if( !sqlite3SafetyCheckOk(db) ){
132597 db->mutex);
132598 pOld = db->pTraceArg;
132599 db->xTrace = xTrace;
132600 db->pTraceArg = pArg;
132601 sqlite3_mutex_leave(db->mutex);
132613 sqlite3 *db,
132620 if( !sqlite3SafetyCheckOk(db) ){
132625 sqlite3_mutex_enter(db->mutex);
132626 pOld = db->pProfileArg;
132627 db->xProfile = xProfile;
132628 db->pProfileArg = pArg;
132629 sqlite3_mutex_leave(db->mutex);
132640 sqlite3 *db, /* Attach the hook to this database */
132647 if( !sqlite3SafetyCheckOk(db) ){
132652 sqlite3_mutex_enter(db->mutex);
132653 pOld = db->pCommitArg;
132654 db->xCommitCallback = xCallback;
132655 db->pCommitArg = pArg;
132656 sqlite3_mutex_leave(db->mutex);
132665 sqlite3 *db, /* Attach the hook to this database */
132672 if( !sqlite3SafetyCheckOk(db) ){
132677 sqlite3_mutex_enter(db->mutex);
132678 pRet = db->pUpdateArg;
132679 db->xUpdateCallback = xCallback;
132680 db->pUpdateArg = pArg;
132681 sqlite3_mutex_leave(db->mutex);
132690 sqlite3 *db, /* Attach the hook to this database */
132697 if( !sqlite3SafetyCheckOk(db) ){
132702 sqlite3_mutex_enter(db->mutex);
132703 pRet = db->pRollbackArg;
132704 db->xRollbackCallback = xCallback;
132705 db->pRollbackArg = pArg;
132706 sqlite3_mutex_leave(db->mutex);
132719 sqlite3 *db, /* Connection */
132725 sqlite3_wal_checkpoint(db, zDb);
132743 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
132745 UNUSED_PARAMETER(db);
132749 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132752 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
132754 sqlite3_wal_hook(db, 0, 0);
132765 sqlite3 *db, /* Attach the hook to this db handle */
132772 if( !sqlite3SafetyCheckOk(db) ){
132777 sqlite3_mutex_enter(db->mutex);
132778 pRet = db->pWalArg;
132779 db->xWalCallback = xCallback;
132780 db->pWalArg = pArg;
132781 sqlite3_mutex_leave(db->mutex);
132792 sqlite3 *db, /* Database handle */
132802 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
132805 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132822 sqlite3_mutex_enter(db->mutex);
132824 iDb = sqlite3FindDbName(db, zDb);
132828 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb);
132830 db->busyHandler.nBusy = 0;
132831 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
132832 sqlite3Error(db, rc);
132834 rc = sqlite3ApiExit(db, rc);
132835 sqlite3_mutex_leave(db->mutex);
132846 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
132849 return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
132862 ** The mutex on database handle db should be held by the caller. The mutex
132872 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
132877 assert( sqlite3_mutex_held(db->mutex) );
132881 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
132883 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
132900 ** The value returned depends on the value of db->temp_store (runtime
132905 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
132916 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
132918 return ( db->temp_store==2 );
132921 return ( db->temp_store!=1 );
132924 UNUSED_PARAMETER(db);
132928 UNUSED_PARAMETER(db);
132937 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3 *db){
132939 if( !db ){
132942 if( !sqlite3SafetyCheckSickOrOk(db) ){
132945 sqlite3_mutex_enter(db->mutex);
132946 if( db->mallocFailed ){
132949 testcase( db->pErr==0 );
132950 z = (char*)sqlite3_value_text(db->pErr);
132951 assert( !db->mallocFailed );
132953 z = sqlite3ErrStr(db->errCode);
132956 sqlite3_mutex_leave(db->mutex);
132965 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3 *db){
132979 if( !db ){
132982 if( !sqlite3SafetyCheckSickOrOk(db) ){
132985 sqlite3_mutex_enter(db->mutex);
132986 if( db->mallocFailed ){
132989 z = sqlite3_value_text16(db->pErr);
132991 sqlite3ErrorWithMsg(db, db->errCode, sqlite3ErrStr(db->errCode));
132992 z = sqlite3_value_text16(db->pErr);
132995 ** above. If this is the case, then the db->mallocFailed flag needs to
132999 db->mallocFailed = 0;
133001 sqlite3_mutex_leave(db->mutex);
133010 SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db){
133011 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
133014 if( !db || db->mallocFailed ){
133017 return db->errCode & db->errMask;
133019 SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db){
133020 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
133023 if( !db || db->mallocFailed ){
133026 return db->errCode;
133039 ** Create a new collating function for database "db". The name is zName
133043 sqlite3* db,
133053 assert( sqlite3_mutex_held(db->mutex) );
133073 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
133075 if( db->nVdbeActive ){
133076 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
133080 sqlite3ExpirePreparedStatements(db);
133089 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
133103 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
133109 sqlite3Error(db, SQLITE_OK);
133182 SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
133186 if( !sqlite3SafetyCheckOk(db) ){
133216 oldLimit = db->aLimit[limitId];
133221 db->aLimit[limitId] = newLimit;
133483 sqlite3 *db; /* Store allocated handle here */
133557 db = sqlite3MallocZero( sizeof(sqlite3) );
133558 if( db==0 ) goto opendb_out;
133560 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
133561 if( db->mutex==0 ){
133562 sqlite3_free(db);
133563 db = 0;
133567 sqlite3_mutex_enter(db->mutex);
133568 db->errMask = 0xff;
133569 db->nDb = 2;
133570 db->magic = SQLITE_MAGIC_BUSY;
133571 db->aDb = db->aDbStatic;
133573 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
133574 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
133575 db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = SQLITE_DEFAULT_WORKER_THREADS;
133576 db->autoCommit = 1;
133577 db->nextAutovac = -1;
133578 db->szMmap = sqlite3GlobalConfig.szMmap;
133579 db->nextPagesize = 0;
133580 db->nMaxSorterMmap = 0x7FFFFFFF;
133581 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
133607 sqlite3HashInit(&db->aCollSeq);
133609 sqlite3HashInit(&db->aModule);
133619 createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
133620 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
133621 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
133622 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
133623 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
133624 if( db->mallocFailed ){
133630 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
133631 assert( db->pDfltColl!=0 );
133634 db->openFlags = flags;
133635 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
133637 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
133638 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
133644 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
133650 sqlite3Error(db, rc);
133653 sqlite3BtreeEnter(db->aDb[0].pBt);
133654 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
133655 if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
133656 sqlite3BtreeLeave(db->aDb[0].pBt);
133657 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
133662 db->aDb[0].zName = "main";
133663 db->aDb[0].safety_level = 3;
133664 db->aDb[1].zName = "temp";
133665 db->aDb[1].safety_level = 1;
133667 db->magic = SQLITE_MAGIC_OPEN;
133668 if( db->mallocFailed ){
133676 sqlite3Error(db, SQLITE_OK);
133677 sqlite3RegisterBuiltinFunctions(db);
133682 rc = sqlite3_errcode(db);
133684 sqlite3AutoLoadExtensions(db);
133685 rc = sqlite3_errcode(db);
133692 if( !db->mallocFailed ){
133694 rc = sqlite3Fts1Init(db);
133699 if( !db->mallocFailed && rc==SQLITE_OK ){
133701 rc = sqlite3Fts2Init(db);
133706 if( !db->mallocFailed && rc==SQLITE_OK ){
133707 rc = sqlite3Fts3Init(db);
133712 if( !db->mallocFailed && rc==SQLITE_OK ){
133713 rc = sqlite3Fts5Init(db);
133718 if( !db->mallocFailed && rc==SQLITE_OK ){
133719 rc = sqlite3IcuInit(db);
133724 if( !db->mallocFailed && rc==SQLITE_OK){
133725 rc = sqlite3RtreeInit(db);
133730 if( !db->mallocFailed && rc==SQLITE_OK){
133731 rc = sqlite3DbstatRegister(db);
133736 if( !db->mallocFailed && rc==SQLITE_OK){
133737 rc = sqlite3Json1Init(db);
133746 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
133747 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
133751 if( rc ) sqlite3Error(db, rc);
133754 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
133757 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
133761 if( db ){
133762 assert( db->mutex!=0 || isThreadsafe==0
133764 sqlite3_mutex_leave(db->mutex);
133766 rc = sqlite3_errcode(db);
133767 assert( db!=0 || rc==SQLITE_NOMEM );
133769 sqlite3_close(db);
133770 db = 0;
133772 db->magic = SQLITE_MAGIC_SICK;
133774 *ppDb = db;
133777 /* Opening a db handle. Fourth parameter is passed 0. */
133779 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
133797 sqlite3 **ppDb, /* OUT: SQLite db handle */
133845 ** Register a new collation sequence with the database handle db.
133848 sqlite3* db,
133854 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
133858 ** Register a new collation sequence with the database handle db.
133861 sqlite3* db,
133871 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
133873 sqlite3_mutex_enter(db->mutex);
133874 assert( !db->mallocFailed );
133875 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
133876 rc = sqlite3ApiExit(db, rc);
133877 sqlite3_mutex_leave(db->mutex);
133883 ** Register a new collation sequence with the database handle db.
133886 sqlite3* db,
133896 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
133898 sqlite3_mutex_enter(db->mutex);
133899 assert( !db->mallocFailed );
133900 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
133902 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
133903 sqlite3DbFree(db, zName8);
133905 rc = sqlite3ApiExit(db, rc);
133906 sqlite3_mutex_leave(db->mutex);
133913 ** db. Replace any previously installed collation sequence factory.
133916 sqlite3 *db,
133921 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
133923 sqlite3_mutex_enter(db->mutex);
133924 db->xCollNeeded = xCollNeeded;
133925 db->xCollNeeded16 = 0;
133926 db->pCollNeededArg = pCollNeededArg;
133927 sqlite3_mutex_leave(db->mutex);
133934 ** db. Replace any previously installed collation sequence factory.
133937 sqlite3 *db,
133942 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
133944 sqlite3_mutex_enter(db->mutex);
133945 db->xCollNeeded = 0;
133946 db->xCollNeeded16 = xCollNeeded16;
133947 db->pCollNeededArg = pCollNeededArg;
133948 sqlite3_mutex_leave(db->mutex);
133969 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3 *db){
133971 if( !sqlite3SafetyCheckOk(db) ){
133976 return db->autoCommit;
134030 sqlite3 *db, /* Connection handle */
134053 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
134059 sqlite3_mutex_enter(db->mutex);
134060 sqlite3BtreeEnterAll(db);
134061 rc = sqlite3Init(db, &zErrMsg);
134067 pTab = sqlite3FindTable(db, zTableName, zDbName);
134119 sqlite3BtreeLeaveAll(db);
134132 sqlite3DbFree(db, zErrMsg);
134133 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
134137 sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
134138 sqlite3DbFree(db, zErrMsg);
134139 rc = sqlite3ApiExit(db, rc);
134140 sqlite3_mutex_leave(db->mutex);
134163 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3 *db, int onoff){
134165 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
134167 sqlite3_mutex_enter(db->mutex);
134168 db->errMask = onoff ? 0xffffffff : 0xff;
134169 sqlite3_mutex_leave(db->mutex);
134176 SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
134181 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
134183 sqlite3_mutex_enter(db->mutex);
134184 pBtree = sqlite3DbNameToBtree(db, zDbName);
134203 sqlite3_mutex_leave(db->mutex);
134391 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
134394 ** connection db.
134397 sqlite3 *db = va_arg(ap, sqlite3*);
134399 sqlite3_mutex_enter(db->mutex);
134400 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
134401 sqlite3_mutex_leave(db->mutex);
134405 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
134415 sqlite3 *db = va_arg(ap, sqlite3*);
134416 db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
134493 /* sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */
134495 sqlite3 *db = va_arg(ap, sqlite3*);
134496 db->nMaxSorterMmap = va_arg(ap, int);
134510 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
134512 ** This test control is used to create imposter tables. "db" is a pointer
134527 sqlite3 *db = va_arg(ap, sqlite3*);
134528 sqlite3_mutex_enter(db->mutex);
134529 db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
134530 db->init.busy = db->init.imposterTable = va_arg(ap,int);
134531 db->init.newTnum = va_arg(ap,int);
134532 if( db->init.busy==0 && db->init.newTnum>0 ){
134533 sqlite3ResetAllSchemasOfConnection(db);
134535 sqlite3_mutex_leave(db->mutex);
134595 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
134597 for(i=0; i<db->nDb; i++){
134598 if( db->aDb[i].pBt
134599 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
134601 return db->aDb[i].pBt;
134611 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName){
134614 if( !sqlite3SafetyCheckOk(db) ){
134619 pBt = sqlite3DbNameToBtree(db, zDbName);
134627 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
134630 if( !sqlite3SafetyCheckOk(db) ){
134635 pBt = sqlite3DbNameToBtree(db, zDbName);
134693 ** 3) If the argument db is not NULL, then none of the entries in the
134695 ** set to db. This is used when closing connection db.
134697 static void checkListProperties(sqlite3 *db){
134710 assert( db==0 || p->pUnlockConnection!=db );
134711 assert( db==0 || p->pBlockingConnection!=db );
134720 ** Remove connection db from the blocked connections list. If connection
134721 ** db is not currently a part of the list, this function is a no-op.
134723 static void removeFromBlockedList(sqlite3 *db){
134727 if( *pp==db ){
134735 ** Add connection db to the blocked connections list. It is assumed
134738 static void addToBlockedList(sqlite3 *db){
134743 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
134746 db->pNextBlocked = *pp;
134747 *pp = db;
134770 ** This is called after connection "db" has attempted some operation
134773 ** cache. pOther is found by looking at db->pBlockingConnection.
134778 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
134785 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
134789 sqlite3 *db,
134795 sqlite3_mutex_enter(db->mutex);
134799 removeFromBlockedList(db);
134800 db->pBlockingConnection = 0;
134801 db->pUnlockConnection = 0;
134802 db->xUnlockNotify = 0;
134803 db->pUnlockArg = 0;
134804 }else if( 0==db->pBlockingConnection ){
134813 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
134817 db->pUnlockConnection = db->pBlockingConnection;
134818 db->xUnlockNotify = xNotify;
134819 db->pUnlockArg = pArg;
134820 removeFromBlockedList(db);
134821 addToBlockedList(db);
134826 assert( !db->mallocFailed );
134827 sqlite3ErrorWithMsg(db, rc, (rc?"database is deadlocked":0));
134828 sqlite3_mutex_leave(db->mutex);
134834 ** associated with connection db. The operation will return SQLITE_LOCKED
134838 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
134840 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
134841 addToBlockedList(db);
134843 db->pBlockingConnection = pBlocker;
134849 ** the transaction opened by database db has just finished. Locks held
134850 ** by database connection db have been released.
134856 ** set to db, then set pBlockingConnection=0.
134859 ** set to db, then invoke the configured unlock-notify callback and
134866 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
134882 if( p->pBlockingConnection==db ){
134887 if( p->pUnlockConnection==db ){
134914 ** is returned the transaction on connection db will still be
134965 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
134966 sqlite3ConnectionUnlocked(db);
134968 removeFromBlockedList(db);
134969 checkListProperties(db);
135759 sqlite3 *db; /* The database connection */
136127 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
136128 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
136136 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
136402 sqlite3 *db, /* Database in which to run SQL */
136415 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
136427 sqlite3 *db = p->db; /* Database handle */
136431 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
136433 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
136434 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
136435 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
136436 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
136464 sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
136480 rc = sqlite3_declare_vtab(p->db, zSql);
136493 fts3DbExec(pRc, p->db,
136513 sqlite3 *db = p->db; /* The database connection */
136531 fts3DbExec(&rc, db,
136539 fts3DbExec(&rc, db,
136543 fts3DbExec(&rc, db,
136556 fts3DbExec(&rc, db,
136585 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
136906 sqlite3 *db, /* Database handle */
136907 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
136922 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
136924 sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
136982 sqlite3 *db, /* The SQLite database connection */
137177 rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
137230 p->db = db;
137358 sqlite3 *db, /* Database connection */
137365 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
137368 sqlite3 *db, /* Database connection */
137375 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
137589 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
139126 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
139266 int mxLevel = 0; /* Maximum relative level value in db */
139292 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
139586 sqlite3 *db = p->db; /* Database connection */
139605 fts3DbExec(&rc, db,
139612 fts3DbExec(&rc, db,
139618 fts3DbExec(&rc, db,
139623 fts3DbExec(&rc, db,
139627 fts3DbExec(&rc, db,
139743 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
139762 rc = sqlite3Fts3InitTerm(db);
139766 rc = sqlite3Fts3InitAux(db);
139798 rc = sqlite3Fts3ExprInitTestInterface(db);
139808 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
139810 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
139811 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
139812 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
139813 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
139814 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
139818 db, "fts1", &fts3Module, (void *)pHash, 0
139822 db, "fts2", &fts3Module, (void *)pHash, 0
139827 db, "fts3", &fts3Module, (void *)pHash, hashDestroy
139831 db, "fts4", &fts3Module, (void *)pHash, 0
139835 rc = sqlite3Fts3InitTok(db, (void *)pHash);
140963 ** the db. In this case the position-list is not populated at all.
141798 sqlite3 *db,
141803 return sqlite3Fts3Init(db);
141868 sqlite3 *db, /* Database connection */
141888 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
141907 rc = sqlite3_declare_vtab(db, FTS3_AUX_SCHEMA);
141918 p->pFts3Tab->db = db;
142325 ** Register the fts3aux module with database connection db. Return SQLITE_OK
142328 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db){
142356 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
143478 sqlite3 *db,
143487 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
143584 sqlite3 *db = sqlite3_context_db_handle(context);
143593 rc = queryTestTokenizer(db,
143657 ** with database connection db.
143659 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
143661 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
143664 rc = sqlite3_create_function(db, "fts3_exprtest_rebalance",
145059 sqlite3 *db,
145067 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
145081 sqlite3 *db,
145090 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
145133 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
145140 rc = queryTokenizer(db, "simple", &p2);
145143 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
145146 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
145149 rc = registerTokenizer(db, "nosuchtokenizer", p1);
145151 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
145161 ** Set up SQL objects in database db used to access the contents of
145178 sqlite3 *db,
145189 void *pdb = (void *)db;
145198 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
145201 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
145205 rc = sqlite3_create_function(db, zTest, -1, any, p, testFunc, 0, 0);
145208 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
145619 sqlite3 *db, /* Database connection */
145633 rc = sqlite3_declare_vtab(db, FTS3_TOK_SCHEMA);
145879 ** Register the fts3tok module with database connection db. Return SQLITE_OK
145882 SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){
145910 rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
146250 ** of the oldest level in the db that contains at least ? segments. Or,
146326 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
146931 *piDocid = sqlite3_last_insert_rowid(p->db);
147129 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
148044 ** blocks were written to the db). Otherwise, an SQLite error code is
148260 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
148267 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
149425 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
150562 ** Each input segment is either removed from the db completely (if all of
151100 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
151520 if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
151578 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
151582 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
151585 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
151586 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
154185 sqlite3 *db; /* Host database connection */
154736 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
154829 sqlite3 *db,
154835 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
154842 sqlite3 *db,
154848 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
154903 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
156755 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
156951 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
157019 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
157030 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
157041 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
157090 sqlite3 *db,
157117 pRtree->db = db;
157131 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
157148 rc = rtreeQueryStat1(db, pRtree);
157152 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
157165 ** using database connection db. If successful, the integer value returned
157169 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
157173 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
157200 sqlite3 *db, /* Database handle */
157210 rc = getIntFromStmt(db, zSql, &iPageSize);
157217 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157224 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
157226 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157244 sqlite3 *db, /* Database connection */
157270 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
157291 rc = getNodeSize(db, pRtree, isCreate, pzErr);
157298 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
157299 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157316 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
157317 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157417 ** Register the r-tree module with database handle db. This creates the
157421 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
157425 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
157427 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
157435 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
157439 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
157523 sqlite3 *db, /* Register SQL function on this connection */
157537 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
157547 sqlite3 *db, /* Register SQL function on this connection */
157562 return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
157572 sqlite3 *db,
157577 return sqlite3RtreeInit(db);
158000 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
158023 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
158033 ** Register the ICU extension functions with database db.
158035 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
158058 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
158067 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
158079 sqlite3 *db,
158084 return sqlite3IcuInit(db);
158564 ** example, if the target db contains either of the following:
158781 ** the rbu update db handle to any required virtual table
158795 ** Do some work towards applying the RBU update to the target db.
158963 ** target db file.
159059 const char *zTbl; /* Name of target db table */
159060 const char *zDataTbl; /* Name of rbu db table (or null) */
159061 const char *zIdx; /* Name of target db index (or null) */
159122 char *zTarget; /* Path to target db */
159123 char *zRbu; /* Path to rbu db */
159124 char *zState; /* Path to state db (or NULL if zRbu) */
159125 char zStateDb[5]; /* Db name for state ("stat" or "main") */
159132 rbu_file *pTargetFd; /* File handle open on target db */
159155 rbu_file *pMain; /* Linked list of main db files */
159169 u32 iCookie; /* Cookie value for main db files */
159170 u8 iWriteVer; /* "write-version" value for main db files */
159176 const char *zWal; /* Wal filename for this main db file */
159177 rbu_file *pWalFd; /* Wal file descriptor for this main db */
159429 ** Prepare the SQL statement in buffer zSql against database handle db.
159439 sqlite3 *db,
159444 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
159446 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
159471 ** statement against database db and frees the buffer. If statement
159484 sqlite3 *db,
159495 rc = prepareAndCollectError(db, ppStmt, pzErrmsg, zSql);
159725 static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){
159734 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
159822 sqlite3 *db = sqlite3_db_handle(pStmt);
159826 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
160933 sqlite3 *db = 0;
160936 p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
160938 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
160939 sqlite3_close(db);
160940 db = 0;
160943 return db;
160959 ** the RBU db handle now. */
161018 ** test.db-journal => test.nal
161019 ** test.db-wal => test.wal
161020 ** test.db-shm => test.shm
161021 ** test.db-mj7f3319fa => test.9fa
161062 ** (wal frame -> db page) copy operations required to checkpoint the
161249 /* Move the *-oal file to *-wal. At this point connection p->db is
161251 ** in WAL mode). So no other connection may be writing the db.
161627 /* Sync the db file */
161919 sqlite3 *db = p->dbMain;
161923 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
161928 /* Check if the main database is a zipvfs db. If it is, set the upper
161932 int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
161934 p->rc = sqlite3_exec(db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
161975 sqlite3 *db = 0;
161977 db = (bRbu ? pRbu->dbRbu : pRbu->dbMain);
161979 return db;
162090 ** db fds opened using a particular RBU VFS is maintained at
162093 ** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
162112 ** 3b. The *-shm pages returned by xShmMap() for a target db file in
162573 ** the name of the *-wal file this db connection will use. SQLite
163009 sqlite3 *db;
163021 sqlite3 *db,
163032 iDb = sqlite3FindDbName(db, argv[3]);
163040 rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
163049 pTab->db = db;
163291 Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
163320 Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt;
163465 pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
163483 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
163487 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
163535 sqlite3 *db = sqlite3_context_db_handle(ctx);
163537 sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
163553 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){
163576 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
163579 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
165120 sqlite3 *db,
165145 rc = sqlite3_declare_vtab(db,
165569 SQLITE_PRIVATE int sqlite3Json1Init(sqlite3 *db){
165608 rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
165615 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
165627 sqlite3 *db,
165633 return sqlite3Json1Init(db);
166312 sqlite3 *db; /* Database handle */
169388 sqlite3 *db,
169402 pRet->db = db;
169547 rc = sqlite3_declare_vtab(pConfig->db, zSql);
169761 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p, 0);
171839 sqlite3 *db = sqlite3_context_db_handle(pCtx);
171881 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
171973 static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
171989 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
173168 rc = sqlite3_blob_open(pConfig->db,
173226 p->rc = sqlite3_prepare_v2(p->pConfig->db, zSql, -1, ppStmt, 0);
173275 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p->pDeleter, 0);
177362 rc = sqlite3_blob_open(pConfig->db, pConfig->zDb, p->zDataTbl,
178221 ** connection db. It registers several user-defined scalar functions useful
178227 static int sqlite3Fts5IndexInit(sqlite3 *db){
178229 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
178233 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
178316 sqlite3 *db; /* Associated database connection */
178595 sqlite3 *db, /* The SQLite database connection */
178611 rc = sqlite3Fts5ConfigParse(pGlobal, db, argc, azConfig, &pConfig, pzErr);
178651 sqlite3 *db, /* Database connection */
178658 return fts5InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
178661 sqlite3 *db, /* Database connection */
178668 return fts5InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
179099 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pSorter->pStmt, 0);
179196 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pStmt, 0);
179689 int eConflict = sqlite3_vtab_on_conflict(pConfig->db);
180446 fts5_api *pApi, /* Global context (one per db handle) */
180453 int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
180485 fts5_api *pApi, /* Global context (one per db handle) */
180541 fts5_api *pApi, /* Global context (one per db handle) */
180638 static int fts5Init(sqlite3 *db){
180674 pGlobal->db = db;
180679 rc = sqlite3_create_module_v2(db, "fts5", &fts5Mod, p, fts5ModuleDestroy);
180680 if( rc==SQLITE_OK ) rc = sqlite3Fts5IndexInit(db);
180681 if( rc==SQLITE_OK ) rc = sqlite3Fts5ExprInit(pGlobal, db);
180684 if( rc==SQLITE_OK ) rc = sqlite3Fts5VocabInit(pGlobal, db);
180687 db, "fts5", 0, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
180692 db, "fts5_source_id", 0, SQLITE_UTF8, p, fts5SourceIdFunc, 0, 0
180713 sqlite3 *db,
180719 return fts5Init(db);
180726 sqlite3 *db,
180732 return fts5Init(db);
180735 SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3 *db){
180736 return fts5Init(db);
180877 rc = sqlite3_prepare_v2(pC->db, zSql, -1, &p->aStmt[eStmt], 0);
180880 *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
180891 sqlite3 *db,
180906 rc = sqlite3_exec(db, zSql, 0, 0, pzErr);
180919 int rc = fts5ExecPrintf(pConfig->db, 0,
180928 rc = fts5ExecPrintf(pConfig->db, 0,
180934 rc = fts5ExecPrintf(pConfig->db, 0,
180949 *pRc = fts5ExecPrintf(pConfig->db, 0,
180986 rc = fts5ExecPrintf(pConfig->db, &zErr, "CREATE TABLE %Q.'%q_%q'(%s)%s",
181334 rc = fts5ExecPrintf(pConfig->db, 0,
181341 rc = fts5ExecPrintf(pConfig->db, 0,
181439 *piRowid = sqlite3_last_insert_rowid(p->pConfig->db);
181484 *piRowid = sqlite3_last_insert_rowid(pConfig->db);
181552 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pCnt, 0);
183831 char *zFts5Db; /* Db containing fts5 table */
183832 sqlite3 *db; /* Database handle */
183932 sqlite3 *db, /* The SQLite database connection */
183965 rc = sqlite3_declare_vtab(db, azSchema[eType]);
183973 pRet->db = db;
183993 sqlite3 *db, /* Database connection */
184000 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
184003 sqlite3 *db, /* Database connection */
184010 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
184044 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
184244 static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){
184272 return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);