Home | History | Annotate | Download | only in dist

Lines Matching defs:Db

2560   sqlite3 *db,          /* An open database */
2624 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2652 ** sqlite3_exec(db, zSQL, 0, 0, 0);
3159 ** <tr><td> file:data.db <td>
3160 ** Open the file "data.db" in the current directory.
3161 ** <tr><td> file:/home/fred/data.db<br>
3162 ** file:///home/fred/data.db <br>
3163 ** file://localhost/home/fred/data.db <br> <td>
3164 ** Open the database file "/home/fred/data.db".
3165 ** <tr><td> file://darkstar/home/fred/data.db <td>
3168 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3169 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3173 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3174 ** Open file "data.db" in the current directory for read-only access.
3177 ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
3178 ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
3179 ** <tr><td> file:data.db?mode=readonly <td>
3200 sqlite3 **ppDb /* OUT: SQLite db handle */
3204 sqlite3 **ppDb /* OUT: SQLite db handle */
3208 sqlite3 **ppDb, /* OUT: SQLite db handle */
3290 SQLITE_API int sqlite3_errcode(sqlite3 *db);
3291 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3433 ** The first argument, "db", is a [database connection] obtained from a
3508 sqlite3 *db, /* Database handle */
3515 sqlite3 *db, /* Database handle */
3522 sqlite3 *db, /* Database handle */
3529 sqlite3 *db, /* Database handle */
4389 sqlite3 *db,
4399 sqlite3 *db,
4409 sqlite3 *db,
4915 sqlite3 *db, /* Database to be rekeyed */
4928 sqlite3 *db, /* Database to be rekeyed */
5050 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5059 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5362 sqlite3 *db, /* Connection handle */
5399 sqlite3 *db, /* Load the extension into this database connection */
5418 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5435 ** &nbsp; sqlite3 *db,
5653 sqlite3 *db, /* SQLite connection to register module with */
5659 sqlite3 *db, /* SQLite connection to register module with */
7283 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7301 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7307 ** handle db. The specific operation is determined by the value of the
7313 ** readers or writers to finish. Sync the db file if all frames in the log
7374 sqlite3 *db, /* Database handle */
7419 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
7524 sqlite3 *db,
8130 typedef struct Db Db;
8221 sqlite3 *db, /* Associated database connection */
8234 #define BTREE_MEMORY 2 /* This is an in-memory DB */
9597 struct Db {
9638 ** Db.pSchema->flags field.
9646 ** Allowed values for the DB.pSchema->flags field.
9718 Db *aDb; /* All backends */
9740 u8 iDb; /* Which db file is being initialized */
9794 Db aDbStatic[2]; /* Static space for the 2 default backends */
9824 #define ENC(db) ((db)->aDb[0].pSchema->enc)
10131 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
10135 sqlite3 *db; /* Database connection associated with this table */
10309 sqlite3 *db; /* The database connection */
11084 sqlite3 *db; /* The main database structure */
11161 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
11193 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
11194 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
11308 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
11324 sqlite3 *db; /* The database being initialized */
11944 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11951 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
11997 # define sqlite3VtabInSync(db) 0
12004 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12005 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
12006 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12007 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12013 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
12115 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
12116 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
12880 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12975 sqlite3 *db; /* The associated database connection */
13119 sqlite3 *db; /* The database connection that owns this statement */
13134 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
13153 int nChange; /* Number of db changes made since last reset */
13154 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13388 sqlite3 *db, /* The database connection whose status is desired */
13395 sqlite3_mutex_enter(db->mutex);
13398 *pCurrent = db->lookaside.nOut;
13399 *pHighwater = db->lookaside.mxOut;
13401 db->lookaside.mxOut = db->lookaside.nOut;
13415 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
13417 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
13430 sqlite3BtreeEnterAll(db);
13431 for(i=0; i<db->nDb; i++){
13432 Btree *pBt = db->aDb[i].pBt;
13438 sqlite3BtreeLeaveAll(db);
13453 sqlite3BtreeEnterAll(db);
13454 db->pnBytesFreed = &nByte;
13455 for(i=0; i<db->nDb; i++){
13456 Schema *pSchema = db->aDb[i].pSchema;
13472 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
13475 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
13479 db->pnBytesFreed = 0;
13480 sqlite3BtreeLeaveAll(db);
13496 db->pnBytesFreed = &nByte;
13497 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
13498 sqlite3VdbeDeleteObject(db, pVdbe);
13500 db->pnBytesFreed = 0;
13519 for(i=0; i<db->nDb; i++){
13520 if( db->aDb[i].pBt ){
13521 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
13534 sqlite3_mutex_leave(db->mutex);
13835 sqlite3 *db = sqlite3_context_db_handle(context);
13836 if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
14426 sqlite3 *db;
14430 db = sqlite3_context_db_handle(context);
14466 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
14467 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
14470 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
14474 z = sqlite3DbMallocRaw(db, (int)n);
14610 sqlite3 *db;
14619 db = sqlite3_context_db_handle(context);
14620 if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
19017 ** TRUE if p is a lookaside memory allocation from db
19020 static int isLookaside(sqlite3 *db, void *p){
19021 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19036 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19037 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19038 if( db && isLookaside(db, p) ){
19039 return db->lookaside.sz;
19043 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
19070 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
19071 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19072 if( db ){
19073 if( db->pnBytesFreed ){
19074 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
19077 if( isLookaside(db, p) ){
19079 pBuf->pNext = db->lookaside.pFree;
19080 db->lookaside.pFree = pBuf;
19081 db->lookaside.nOut--;
19087 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
19170 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
19171 void *p = sqlite3DbMallocRaw(db, n);
19182 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
19189 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
19190 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
19196 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
19198 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19199 assert( db==0 || db->pnBytesFreed==0 );
19201 if( db ){
19203 if( db->mallocFailed ){
19206 if( db->lookaside.bEnabled ){
19207 if( n>db->lookaside.sz ){
19208 db->lookaside.anStat[1]++;
19209 }else if( (pBuf = db->lookaside.pFree)==0 ){
19210 db->lookaside.anStat[2]++;
19212 db->lookaside.pFree = pBuf->pNext;
19213 db->lookaside.nOut++;
19214 db->lookaside.anStat[0]++;
19215 if( db->lookaside.nOut>db->lookaside.mxOut ){
19216 db->lookaside.mxOut = db->lookaside.nOut;
19223 if( db && db->mallocFailed ){
19228 if( !p && db ){
19229 db->mallocFailed = 1;
19232 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
19240 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
19242 assert( db!=0 );
19243 assert( sqlite3_mutex_held(db->mutex) );
19244 if( db->mallocFailed==0 ){
19246 return sqlite3DbMallocRaw(db, n);
19248 if( isLookaside(db, p) ){
19249 if( n<=db->lookaside.sz ){
19252 pNew = sqlite3DbMallocRaw(db, n);
19254 memcpy(pNew, p, db->lookaside.sz);
19255 sqlite3DbFree(db, p);
19264 db->mallocFailed = 1;
19267 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
19277 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
19279 pNew = sqlite3DbRealloc(db, p, n);
19281 sqlite3DbFree(db, p);
19293 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
19301 zNew = sqlite3DbMallocRaw(db, (int)n);
19307 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
19313 zNew = sqlite3DbMallocRaw(db, n+1);
19326 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){
19331 z = sqlite3VMPrintf(db, zFormat, ap);
19333 sqlite3DbFree(db, *pz);
19347 ** If the first argument, db, is not NULL and a malloc() error has occurred,
19351 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
19352 /* If the db handle is not NULL, then we must hold the connection handle
19353 ** mutex here. Otherwise the read (and possible write) of db->mallocFailed
19356 assert( !db || sqlite3_mutex_held(db->mutex) );
19357 if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
19358 sqlite3Error(db, SQLITE_NOMEM, 0);
19359 db->mallocFailed = 0;
19362 return rc & (db ? db->errMask : 0xff);
20086 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
20115 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
20135 sqlite3DbFree(p->db, p->zText);
20148 p->db = 0;
20161 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
20165 assert( db!=0 );
20167 db->aLimit[SQLITE_LIMIT_LENGTH]);
20168 acc.db = db;
20172 db->mallocFailed = 1;
20181 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
20185 z = sqlite3VMPrintf(db, zFormat, ap);
20195 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
20198 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3 *db, char *zStr, const char *zFormat, ...){
20202 z = sqlite3VMPrintf(db, zFormat, ap);
20204 sqlite3DbFree(db, zStr);
20695 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
20759 zOut = sqlite3DbMallocRaw(pMem->db, len);
20923 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
20926 m.db = db;
20929 if( db->mallocFailed ){
20933 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
20934 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
20935 assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
20936 assert( m.z || db->mallocFailed );
20947 ** If a malloc failure occurs, NULL is returned and the db.mallocFailed
20951 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
20954 m.db = db;
20957 assert( db->mallocFailed );
21143 ** handle "db". The error code is set to "err_code".
21158 ** To clear the most recent error for sqlite handle "db", sqlite3Error
21162 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21163 if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21164 db->errCode = err_code;
21169 z = sqlite3VMPrintf(db, zFormat, ap);
21171 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21173 sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
21198 sqlite3 *db = pParse->db;
21200 zMsg = sqlite3VMPrintf(db, zFormat, ap);
21202 if( db->suppressErr ){
21203 sqlite3DbFree(db, zMsg);
21206 sqlite3DbFree(db, pParse->zErrMsg);
22060 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
22064 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
22089 ** Check to make sure we have a valid db pointer. This test is not
22091 ** misuse of the interface such as passing in db pointers that are
22093 ** 1 it means that the db pointer is valid and 0 if it should not be
22097 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
22098 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
22102 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
22104 if( db==0 ){
22108 magic = db->magic;
22110 if( sqlite3SafetyCheckSickOrOk(db) ){
22119 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
22121 magic = db->magic;
22214 ** test.db-journal => test.nal
22215 ** test.db-wal => test.wal
22216 ** test.db-shm => test.shm
22217 ** test.db-mj7f3319fa => test.9fa
24386 /* The main DB, main journal, WAL file and master journal are never
28873 ** is "/home/user1/config.db" then the file that is created and mmapped
28874 ** for shared memory will be called "/home/user1/config.db-shm".
29694 ** proxyLock activation is possible (remote proxy is based on db name)
29999 ** "<path to db>-journal"
30000 ** "<path to db>-wal"
30001 ** "<path to db>-journalNN"
30002 ** "<path to db>-walNN"
30111 /* The main DB, main journal, WAL file and master journal are never
30696 ** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
30698 ** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
30713 ** For database path "/Users/me/foo.db"
30714 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
30847 /* transform the db path to a unique cache name */
31502 /* afp style keeps a reference to the db path in the filePath field
31514 /* all other styles use the locking context to store the db file path */
35198 /* The main DB, main journal, WAL file and master journal are never
37995 sqlite3 *db; /* The database connection */
38007 ** are available at pSpace. The db pointer is used as a memory context
38017 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
38022 p->db = db;
38042 sqlite3DbFree(p->db, pChunk);
38064 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
38441 int sync_flags, /* Flags to sync db file with (or 0) */
38468 ** stored in each frame (i.e. the db page-size when the WAL was created).
38739 ** db size etc.) are consistent with the contents of the file-system.
39152 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
39153 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
40341 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
40787 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
41535 i64 n = 0; /* Size of db file in bytes */
41572 ** function. Because an EXCLUSIVE lock on the db file is required to delete
42854 ROUND8(pVfs->szOsFile) + /* The main db file */
44203 int noSync /* True to omit the xSync on the db file */
44224 /* If this is an in-memory db, or no pages have been written to, or this
44283 /* Update the db file change counter via the direct-write method. The
45725 u32 nBackfill; /* Number of WAL frames backfilled into DB */
46032 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
46059 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
47085 ** about the eventual size of the db file to the VFS layer.
47095 /* Iterate through the contents of the WAL, copying data to the db file. */
48267 int sync_flags, /* Flags to sync db file with (or 0) */
48810 sqlite3 *db; /* The database connection holding this btree */
48813 u8 sharable; /* True if we can share pBt with another db */
48814 u8 locked; /* True if db currently has pBt locked */
48817 Btree *pNext; /* List of other sharable Btrees from the same db */
48872 sqlite3 *db; /* Database connection currently using this Btree */
48952 ** particular database connection identified BtCursor.pBtree.db.
49127 ** set BtShared.db to the database handle associated with p and the
49133 assert( sqlite3_mutex_held(p->db->mutex) );
49136 p->pBt->db = p->db;
49148 assert( sqlite3_mutex_held(p->db->mutex) );
49149 assert( p->db==pBt->db );
49180 assert( p->pNext==0 || p->pNext->db==p->db );
49181 assert( p->pPrev==0 || p->pPrev->db==p->db );
49189 assert( sqlite3_mutex_held(p->db->mutex) );
49191 /* Unless the database is sharable and unlocked, then BtShared.db
49193 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
49204 p->pBt->db = p->db;
49252 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
49254 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
49290 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
49293 assert( sqlite3_mutex_held(db->mutex) );
49294 for(i=0; i<db->nDb; i++){
49295 p = db->aDb[i].pBt;
49299 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
49302 assert( sqlite3_mutex_held(db->mutex) );
49303 for(i=0; i<db->nDb; i++){
49304 p = db->aDb[i].pBt;
49324 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
49326 if( !sqlite3_mutex_held(db->mutex) ){
49329 for(i=0; i<db->nDb; i++){
49331 p = db->aDb[i].pBt;
49344 ** db->aDb[iDb].pSchema structure. The mutexes required for schema
49347 ** (1) The mutex on db
49348 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
49351 ** db using sqlite3SchemaToIndex().
49353 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
49355 assert( db!=0 );
49356 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
49357 assert( iDb>=0 && iDb<db->nDb );
49358 if( !sqlite3_mutex_held(db->mutex) ) return 0;
49360 p = db->aDb[iDb].pBt;
49378 p->pBt->db = p->db;
49380 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
49382 for(i=0; i<db->nDb; i++){
49383 Btree *p = db->aDb[i].pBt;
49385 p->pBt->db = p->db;
49528 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
49599 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
49620 assert( p->db!=0 );
49621 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
49639 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
49656 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
49693 assert( p->db!=0 );
49699 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
50063 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
51065 assert( pBt->db );
51066 assert( sqlite3_mutex_held(pBt->db->mutex) );
51067 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
51094 sqlite3 *db, /* Associated database handle */
51116 || (isTempDb && sqlite3TempInMemory(db));
51119 assert( db!=0 );
51121 assert( sqlite3_mutex_held(db->mutex) );
51141 p->db = db;
51179 for(iDb=db->nDb-1; iDb>=0; iDb--){
51180 Btree *pExisting = db->aDb[iDb].pBt;
51235 pBt->db = db;
51286 db->mallocFailed = 0;
51306 for(i=0; i<db->nDb; i++){
51307 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
51421 assert( sqlite3_mutex_held(p->db->mutex) );
51488 assert( sqlite3_mutex_held(p->db->mutex) );
51511 assert( sqlite3_mutex_held(p->db->mutex) );
51527 assert( sqlite3_mutex_held(p->db->mutex) );
51790 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
51967 pBlock = pBt->pWriter->db;
51972 pBlock = pIter->pBtree->db;
51978 sqlite3ConnectionBlocked(p->db, pBlock);
52006 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
52044 /* If the db-size header field is incorrect (as it may be if an old
52066 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
52539 if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){
52768 assert( iStatement>p->db->nSavepoint );
53524 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53533 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53784 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53807 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53877 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53918 ** would have already detected db corruption. Similarly, pPage must
56676 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
57448 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
57482 assert( sqlite3_mutex_held(p->db->mutex) );
57488 assert( sqlite3_mutex_held(p->db->mutex) );
57530 assert( sqlite3_mutex_held(p->db->mutex) );
57578 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
57621 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57761 pParse->db = pDb;
58005 int nSrcPage = -1; /* Size of source db in pages */
58006 int bCloseTrans = 0; /* True if src db requires unlocking */
58354 b.pSrcDb = pFrom->db;
58424 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58463 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
58465 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
58468 sqlite3DbFree(pMem->db, pMem->zMalloc);
58469 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
58501 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58530 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58554 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58585 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58629 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58632 ctx.s.db = pMem->db;
58637 sqlite3DbFree(pMem->db, pMem->zMalloc);
58650 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
58674 sqlite3DbFree(p->db, p->zMalloc);
58734 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58759 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58783 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58816 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58830 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58849 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58934 sqlite3 *db = pMem->db;
58935 assert( db!=0 );
58938 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
58939 if( db->mallocFailed ){
58943 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
58944 sqlite3DbMallocSize(db, pMem->zMalloc));
58955 assert( p->db!=0 );
58961 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
59040 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
59041 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
59042 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
59077 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
59086 if( pMem->db ){
59087 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
59338 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
59362 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
59363 || pVal->db->mallocFailed );
59374 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
59375 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
59379 p->db = db;
59395 sqlite3 *db, /* The database connection */
59435 pVal = sqlite3ValueNew(db);
59440 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
59456 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
59469 pVal = sqlite3ValueNew(db);
59477 pVal = sqlite3ValueNew(db);
59482 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
59494 db->mallocFailed = 1;
59495 sqlite3DbFree(db, zVal);
59520 sqlite3DbFree(((Mem*)v)->db, v);
59573 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
59575 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
59577 p->db = db;
59578 if( db->pVdbe ){
59579 db->pVdbe->pPrev = p;
59581 p->pNext = db->pVdbe;
59583 db->pVdbe = p;
59598 p->zSql = sqlite3DbStrNDup(p->db, z, n);
59652 pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
59654 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
59747 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
59784 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
59829 ** sqlite3DbFree(v->db, sIter.apSub);
59871 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
59924 sqlite3DbFree(v->db, sIter.apSub);
59931 return ( v->db->mallocFailed || hasAbort==mayAbort );
59985 sqlite3DbFree(p->db, p->aLabel);
60012 assert( aOp && !p->db->mallocFailed );
60114 assert( addr>=0 || p->db->mallocFailed );
60123 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
60125 sqlite3DbFree(db, pDef);
60134 static void freeP4(sqlite3 *db, int p4type, void *p4){
60136 assert( db );
60144 sqlite3DbFree(db, p4);
60148 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
60153 freeEphemeralFunction(db, pVdbeFunc->pFunc);
60154 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
60155 sqlite3DbFree(db, pVdbeFunc);
60159 freeEphemeralFunction(db, (FuncDef*)p4);
60163 if( db->pnBytesFreed==0 ){
60167 sqlite3DbFree(db, p->zMalloc);
60168 sqlite3DbFree(db, p);
60173 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
60185 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
60189 freeP4(db, pOp->p4type, pOp->p4.p);
60191 sqlite3DbFree(db, pOp->zComment);
60195 sqlite3DbFree(db, aOp);
60214 sqlite3 *db = p->db;
60215 freeP4(db, pOp->p4type, pOp->p4.p);
60248 sqlite3 *db;
60250 db = p->db;
60252 if( p->aOp==0 || db->mallocFailed ){
60254 freeP4(db, n, (void*)*(char**)&zP4);
60264 freeP4(db, pOp->p4type, pOp->p4.p);
60292 p->db->mallocFailed = 1;
60302 assert( ((VTable *)zP4)->db==p->db );
60308 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
60322 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
60325 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
60326 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
60380 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
60381 if( p->db->mallocFailed ){
60499 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
60507 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
60510 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
60520 ** sets the BtShared.db member of each of the BtShared structures, ensuring
60524 ** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
60540 sqlite3 *db;
60541 Db *aDb;
60544 db = p->db;
60545 aDb = db->aDb;
60546 nDb = db->nDb;
60562 sqlite3 *db;
60563 Db *aDb;
60566 db = p->db;
60567 aDb = db->aDb;
60568 nDb = db->nDb;
60605 sqlite3 *db = p->db;
60606 u8 malloc_failed = db->mallocFailed;
60607 if( db->pnBytesFreed ){
60609 sqlite3DbFree(db, p->zMalloc);
60614 assert( (&p[1])==pEnd || p[0].db==p[1].db );
60631 sqlite3DbFree(db, p->zMalloc);
60637 db->mallocFailed = malloc_failed;
60653 sqlite3DbFree(p->v->db, p);
60679 sqlite3 *db = p->db; /* The database connection */
60698 db->mallocFailed = 1;
60734 }else if( db->u1.isInterrupted ){
60737 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
60805 assert( p->db->mallocFailed );
60822 assert( p->db->mallocFailed );
60963 assert( p->aMem[i].db==p->db );
61005 sqlite3 *db; /* The database connection */
61020 db = p->db;
61021 assert( db->mallocFailed==0 );
61076 p->pFree = sqlite3DbMallocZero(db, nByte);
61080 }while( nByte && !db->mallocFailed );
61088 p->aVar[n].db = db;
61101 p->aMem[n].db = db;
61116 sqlite3VdbeSorterClose(p->db, pCx);
61150 v->db->lastRowid = pFrame->lastRowid;
61200 sqlite3 *db = p->db;
61212 sqlite3DbFree(db, p->zErrMsg);
61226 sqlite3 *db = p->db;
61229 sqlite3DbFree(db, p->aColName);
61232 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
61236 pColName->db = p->db;
61262 if( p->db->mallocFailed ){
61275 ** db. If a transaction is active, commit it. If there is a
61279 static int vdbeCommit(sqlite3 *db, Vdbe *p){
61298 rc = sqlite3VtabSync(db, &p->zErrMsg);
61306 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61307 Btree *pBt = db->aDb[i].pBt;
61319 if( needXcommit && db->xCommitCallback ){
61320 rc = db->xCommitCallback(db->pCommitArg);
61335 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
61338 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61339 Btree *pBt = db->aDb[i].pBt;
61350 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61351 Btree *pBt = db->aDb[i].pBt;
61357 sqlite3VtabCommit(db);
61367 sqlite3_vfs *pVfs = db->pVfs;
61370 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
61379 zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
61410 sqlite3DbFree(db, zMaster);
61420 for(i=0; i<db->nDb; i++){
61421 Btree *pBt = db->aDb[i].pBt;
61436 sqlite3DbFree(db, zMaster);
61451 sqlite3DbFree(db, zMaster);
61455 /* Sync all the db files involved in the transaction. The same call
61465 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61466 Btree *pBt = db->aDb[i].pBt;
61474 sqlite3DbFree(db, zMaster);
61483 sqlite3DbFree(db, zMaster);
61498 for(i=0; i<db->nDb; i++){
61499 Btree *pBt = db->aDb[i].pBt;
61507 sqlite3VtabCommit(db);
61524 static void checkActiveVdbeCnt(sqlite3 *db){
61528 p = db->pVdbe;
61536 assert( cnt==db->activeVdbeCnt );
61537 assert( nWrite==db->writeVdbeCnt );
61554 sqlite3 *const db = p->db;
61560 ** In this case (db->nStatement==0), and there is nothing to do.
61562 if( db->nStatement && p->iStatement ){
61567 assert( db->nStatement>0 );
61568 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
61570 for(i=0; i<db->nDb; i++){
61572 Btree *pBt = db->aDb[i].pBt;
61585 db->nStatement--;
61590 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
61593 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
61601 db->nDeferredCons = p->nStmtDefCons;
61619 sqlite3 *db = p->db;
61620 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){
61623 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
61645 sqlite3 *db = p->db;
61663 if( p->db->mallocFailed ){
61671 checkActiveVdbeCnt(db);
61707 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
61708 sqlite3CloseSavepoints(db);
61709 db->autoCommit = 1;
61725 if( !sqlite3VtabInSync(db)
61726 && db->autoCommit
61727 && db->writeVdbeCnt==(p->readOnly==0)
61742 rc = vdbeCommit(db, p);
61749 sqlite3RollbackAll(db, SQLITE_OK);
61751 db->nDeferredCons = 0;
61752 sqlite3CommitInternalChanges(db);
61755 sqlite3RollbackAll(db, SQLITE_OK);
61757 db->nStatement = 0;
61764 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
61765 sqlite3CloseSavepoints(db);
61766 db->autoCommit = 1;
61781 sqlite3DbFree(db, p->zErrMsg);
61784 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
61785 sqlite3CloseSavepoints(db);
61786 db->autoCommit = 1;
61795 sqlite3VdbeSetChanges(db, p->nChange);
61797 sqlite3VdbeSetChanges(db, 0);
61808 db->activeVdbeCnt--;
61810 db->writeVdbeCnt--;
61812 assert( db->activeVdbeCnt>=db->writeVdbeCnt );
61815 checkActiveVdbeCnt(db);
61816 if( p->db->mallocFailed ){
61821 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
61824 if( db->autoCommit ){
61825 sqlite3ConnectionUnlocked(db);
61828 assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 );
61850 sqlite3 *db = p->db;
61853 u8 mallocFailed = db->mallocFailed;
61855 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
61857 db->mallocFailed = mallocFailed;
61858 db->errCode = rc;
61860 sqlite3Error(db, rc, 0);
61877 sqlite3 *db;
61878 db = p->db;
61893 sqlite3DbFree(db, p->zErrMsg);
61901 sqlite3Error(db, p->rc, 0);
61902 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
61903 sqlite3DbFree(db, p->zErrMsg);
61936 return p->rc & db->errMask;
61947 assert( (rc & p->db->errMask)==rc );
61978 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
61981 assert( p->db==0 || p->db==db );
61986 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
61987 sqlite3DbFree(db, pSub);
61989 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
61990 vdbeFreeOpArray(db, p->aOp, p->nOp);
61991 sqlite3DbFree(db, p->aLabel);
61992 sqlite3DbFree(db, p->aColName);
61993 sqlite3DbFree(db, p->zSql);
61994 sqlite3DbFree(db, p->pFree);
61996 sqlite3DbFree(db, p->zExplain);
61997 sqlite3DbFree(db, p->pExplain);
61999 sqlite3DbFree(db, p);
62006 sqlite3 *db;
62009 db = p->db;
62013 assert( db->pVdbe==p );
62014 db->pVdbe = p->pNext;
62020 p->db = 0;
62021 sqlite3VdbeDeleteObject(db, p);
62143 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
62409 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
62451 pMem->db = pKeyInfo->db;
62495 mem1.db = pKeyInfo->db;
62585 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
62593 UNUSED_PARAMETER(db);
62697 ** sqlite3_changes() on the database handle 'db'.
62699 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
62700 assert( sqlite3_mutex_held(db->mutex) );
62701 db->nChange = nChange;
62702 db->nTotalChange += nChange;
62723 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
62725 for(p = db->pVdbe; p; p=p->pNext){
62734 return v->db;
62750 sqlite3_value *pRet = sqlite3ValueNew(v->db);
62815 if( p->db==0 ){
62848 sqlite3 *db = v->db;
62854 mutex = v->db->mutex;
62858 rc = sqlite3ApiExit(db, rc);
62878 sqlite3_mutex_enter(v->db->mutex);
62881 assert( (rc & (v->db->errMask))==rc );
62882 rc = sqlite3ApiExit(v->db, rc);
62883 sqlite3_mutex_leave(v->db->mutex);
62896 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
62985 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62989 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62993 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62999 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63005 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63009 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63013 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63022 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63032 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63041 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63050 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63055 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63059 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63072 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63080 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63083 pCtx->s.db->mallocFailed = 1;
63090 static int doWalCallbacks(sqlite3 *db){
63094 for(i=0; i<db->nDb; i++){
63095 Btree *pBt = db->aDb[i].pBt;
63098 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
63099 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
63117 sqlite3 *db;
63150 db = p->db;
63151 if( db->mallocFailed ){
63166 if( db->activeVdbeCnt==0 ){
63167 db->u1.isInterrupted = 0;
63170 assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 );
63173 if( db->xProfile && !db->init.busy ){
63174 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
63178 db->activeVdbeCnt++;
63179 if( p->readOnly==0 ) db->writeVdbeCnt++;
63188 db->vdbeExecCnt++;
63190 db->vdbeExecCnt--;
63196 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
63198 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
63199 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
63205 p->rc = doWalCallbacks(db);
63211 db->errCode = rc;
63212 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
63234 return (rc&db->errMask);
63255 sqlite3 *db; /* The database connection */
63260 db = v->db;
63261 sqlite3_mutex_enter(db->mutex);
63268 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
63277 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
63278 sqlite3DbFree(db, v->zErrMsg);
63279 if( !db->mallocFailed ){
63280 v->zErrMsg = sqlite3DbStrDup(db, zErr);
63287 rc = sqlite3ApiExit(db, rc);
63288 sqlite3_mutex_leave(db->mutex);
63313 return p->s.db;
63346 assert( sqlite3_mutex_held(p->s.db->mutex) );
63373 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63396 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63401 pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
63472 sqlite3_mutex_enter(pVm->db->mutex);
63496 if( pVm && ALWAYS(pVm->db) ){
63497 sqlite3_mutex_enter(pVm->db->mutex);
63498 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
63532 p->rc = sqlite3ApiExit(p->db, p->rc);
63533 sqlite3_mutex_leave(p->db->mutex);
63635 sqlite3 *db = p->db;
63637 assert( db!=0 );
63641 sqlite3_mutex_enter(db->mutex);
63642 assert( db->mallocFailed==0 );
63647 if( db->mallocFailed ){
63648 db->mallocFailed = 0;
63651 sqlite3_mutex_leave(db->mutex);
63760 ** The error code stored in database p->db is overwritten with the return
63768 sqlite3_mutex_enter(p->db->mutex);
63770 sqlite3Error(p->db, SQLITE_MISUSE, 0);
63771 sqlite3_mutex_leave(p->db->mutex);
63777 sqlite3Error(p->db, SQLITE_RANGE, 0);
63778 sqlite3_mutex_leave(p->db->mutex);
63785 sqlite3Error(p->db, SQLITE_OK, 0);
63825 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
63827 sqlite3Error(p->db, rc, 0);
63828 rc = sqlite3ApiExit(p->db, rc);
63830 sqlite3_mutex_leave(p->db->mutex);
63856 sqlite3_mutex_leave(p->db->mutex);
63869 sqlite3_mutex_leave(p->db->mutex);
63878 sqlite3_mutex_leave(p->db->mutex);
63939 sqlite3_mutex_leave(p->db->mutex);
63998 assert( pTo->db==pFrom->db );
64000 sqlite3_mutex_enter(pTo->db->mutex);
64004 sqlite3_mutex_leave(pTo->db->mutex);
64044 return pStmt ? ((Vdbe*)pStmt)->db : 0;
64161 sqlite3 *db; /* The database connection */
64171 db = p->db;
64173 db->aLimit[SQLITE_LIMIT_LENGTH]);
64174 out.db = db;
64175 if( db->vdbeExecCnt>1 ){
64217 u8 enc = ENC(db);
64221 utf8.db = db;
64930 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
64942 ** assert( checkSavepointCount(db) );
64944 static int checkSavepointCount(sqlite3 *db){
64947 for(p=db->pSavepoint; p; p=p->pNext) n++;
64948 assert( n==(db->nSavepoint + db
64959 sqlite3 *db = p->db;
64960 sqlite3DbFree(db, p->zErrMsg);
64961 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
65005 sqlite3 *db = p->db; /* The database */
65007 u8 encoding = ENC(db); /* The database encoding */
65019 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
65172 Db *pDb;
65187 Db *pDb;
65326 Db *pDb;
65459 db->busyHandler.nBusy = 0;
65463 checkProgress = db->xProgress!=0;
65467 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65479 if( db->mallocFailed ) goto no_mem;
65506 sqlite3_interrupt(db);
65519 if( db->nProgressOps==nProgressOps ){
65521 prc = db->xProgress(db->pProgressArg);
65712 sqlite3VdbeSetChanges(db, p->nChange);
65714 lastRowid = db->lastRowid;
65733 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
65746 assert( rc==SQLITE_OK || db->nDeferredCons>0 );
65807 sqlite3DbFree(db, pOp->p4.z);
65814 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
66001 assert( db->flags&SQLITE_CountRows );
66021 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
66044 if( db->mallocFailed ) goto no_mem;
66082 if( u.af.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
66297 u.ah.ctx.s.db = db;
66315 db->lastRowid = lastRowid;
66317 lastRowid = db->lastRowid;
66328 if( db->mallocFailed ){
66340 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ah.ctx.s));
66519 assert( pIn1->flags & MEM_Str || db->mallocFailed );
66539 assert( pIn1->flags & MEM_Str || db->mallocFailed );
66720 if( db->mallocFailed ) goto no_mem;
67128 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
67129 if( u.an.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
67214 u.an.sMem.db = 0;
67447 if( u.ap.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67533 assert( db->pSavepoint==0 || db->autoCommit==0 );
67535 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
67536 assert( checkSavepointCount(db) );
67539 if( db->writeVdbeCnt>0 ){
67543 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
67553 ** that the db->aVTrans[] array is empty. */
67554 assert( db->autoCommit==0 || db->nVTrans==0 );
67555 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
67556 db->nStatement+db->nSavepoint);
67561 u.ar.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.ar.nName+1);
67568 if( db->autoCommit ){
67569 db->autoCommit = 0;
67570 db->isTransactionSavepoint = 1;
67572 db->nSavepoint++;
67576 u.ar.pNew->pNext = db->pSavepoint;
67577 db->pSavepoint = u.ar.pNew;
67578 u.ar.pNew->nDeferredCons = db->nDeferredCons;
67587 u.ar.pSavepoint = db->pSavepoint;
67594 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.ar.zName);
67596 }else if( db->writeVdbeCnt>0 && u.ar.p1==SAVEPOINT_RELEASE ){
67600 sqlite3SetString(&p->zErrMsg, db,
67610 int isTransaction = u.ar.pSavepoint->pNext==0 && db->isTransactionSavepoint;
67615 db->autoCommit = 1;
67618 db->autoCommit = 0;
67622 db->isTransactionSavepoint = 0;
67625 u.ar.iSavepoint = db->nSavepoint - u.ar.iSavepoint - 1;
67626 for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){
67627 sqlite3BtreeTripAllCursors(db->aDb[u.ar.ii].pBt, SQLITE_ABORT);
67629 for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){
67630 rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepoint);
67635 if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
67636 sqlite3ExpirePreparedStatements(db);
67637 sqlite3ResetInternalSchema(db, -1);
67638 db->flags = (db->flags | SQLITE_InternChanges);
67644 while( db->pSavepoint!=u.ar.pSavepoint ){
67645 u.ar.pTmp = db->pSavepoint;
67646 db->pSavepoint = u.ar.pTmp->pNext;
67647 sqlite3DbFree(db, u.ar.pTmp);
67648 db->nSavepoint--;
67656 assert( u.ar.pSavepoint==db->pSavepoint );
67657 db->pSavepoint = u.ar.pSavepoint->pNext;
67658 sqlite3DbFree(db, u.ar.pSavepoint);
67660 db->nSavepoint--;
67663 db->nDeferredCons = u.ar.pSavepoint->nDeferredCons;
67667 rc = sqlite3VtabSavepoint(db, u.ar.p1, u.ar.iSavepoint);
67694 u.as.turnOnAC = u.as.desiredAutoCommit && !db->autoCommit;
67697 assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
67700 if( u.as.turnOnAC && u.as.iRollback && db->activeVdbeCnt>1 ){
67705 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
67710 if( u.as.turnOnAC && !u.as.iRollback && db->writeVdbeCnt>0 ){
67714 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
67717 }else if( u.as.desiredAutoCommit!=db->autoCommit ){
67720 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
67721 db->autoCommit = 1;
67725 db->autoCommit = (u8)u.as.desiredAutoCommit;
67728 db->autoCommit = (u8)(1-u.as.desiredAutoCommit);
67733 assert( db->nStatement==0 );
67734 sqlite3CloseSavepoints(db);
67742 sqlite3SetString(&p->zErrMsg, db,
67788 assert( pOp->p1>=0 && pOp->p1<db->nDb );
67790 u.at.pBt = db->aDb[pOp->p1].pBt;
67804 && (db->autoCommit==0 || db->activeVdbeCnt>1)
67808 assert( dbdb->nSavepoint>=0 );
67809 db->nStatement++;
67810 p->iStatement = db->nSavepoint + db->nStatement;
67813 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
67821 p->nStmtDefCons = db->nDeferredCons;
67849 assert( u.au.iDb>=0 && u.au.iDb<db->nDb );
67850 assert( db->aDb[u.au.iDb].pBt!=0 );
67853 sqlite3BtreeGetMeta(db->aDb[u.au.iDb].pBt, u.au.iCookie, (u32 *)&u.au.iMeta);
67870 Db *pDb;
67873 assert( pOp->p1>=0 && pOp->p1<db->nDb );
67875 u.av.pDb = &db->aDb[pOp->p1];
67877 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
67885 db->flags |= SQLITE_InternChanges;
67893 sqlite3ExpirePreparedStatements(db);
67924 assert( pOp->p1>=0 && pOp->p1<db->nDb );
67926 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
67927 u.aw.pBt = db->aDb[pOp->p1].pBt;
67930 u.aw.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
67935 sqlite3DbFree(db, p->zErrMsg);
67936 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
67950 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){
67951 sqlite3ResetInternalSchema(db, pOp->p1);
68019 Db *pDb;
68031 assert( u.ax.iDb>=0 && u.ax.iDb<db->nDb );
68033 u.ax.pDb = &db->aDb[u.ax.iDb];
68038 assert( sqlite3SchemaMutexHeld(db, u.ax.iDb, 0) );
68064 u.ax.pKeyInfo->enc = ENC(p->db);
68136 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ay.pCx->pBt,
68156 u.ay.pCx->pKeyInfo->enc = ENC(p->db);
68183 u.az.pCx->pKeyInfo->enc = ENC(p->db);
68185 rc = sqlite3VdbeSorterInit(db, u.az.pCx);
68540 sqlite3DbFree(db, u.bd.pFree);
68947 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bh.iKey;
68970 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
68971 u.bh.zDb = db->aDb[u.bh.pC->iDb].zName;
68975 db->xUpdateCallback(db->pUpdateArg, u.bh.op, u.bh.zDb, u.bh.zTbl, u.bh.iKey);
69016 if( db->xUpdateCallback && pOp->p4.z ){
69038 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
69039 const char *zDb = db->aDb[u.bi.pC->iDb].zName;
69041 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bi.iKey);
69055 sqlite3VdbeSetChanges(db, p->nChange);
69162 if( u.bl.n64>db
69169 if( u.bl.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
69339 rc = sqlite3VdbeSorterRewind(db, u.bp.pC, &u.bp.res);
69410 rc = sqlite3VdbeSorterNext(db, u.bq.pC, &u.bq.res);
69468 rc = sqlite3VdbeSorterWrite(db, u.br.pC, pIn2);
69547 rc = sqlite3VdbeIdxRowid(db, u.bt.pCrsr, &u.bt.rowid);
69654 for(u.bv.pVdbe=db->pVdbe; u.bv.pVdbe; u.bv.pVdbe = u.bv.pVdbe->pNext){
69660 u.bv.iCnt = db->activeVdbeCnt;
69670 rc = sqlite3BtreeDropTable(db->aDb[u.bv.iDb].pBt, pOp->p1, &u.bv.iMoved);
69675 sqlite3RootPageMoved(db, u.bv.iDb, u.bv.iMoved, pOp->p1);
69711 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bw.nChange : 0)
69751 Db *pDb;
69755 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69757 u.bx.pDb = &db->aDb[pOp->p1];
69791 for(u.by.iDb=0; u.by.iDb<db->nDb; u.by.iDb++){
69792 assert( u.by.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.by.iDb].pBt) );
69797 assert( u.by.iDb>=0 && u.by.iDb<db->nDb );
69798 assert( DbHasProperty(db, u.by.iDb, DB_SchemaLoaded) );
69801 u.by.initData.db = db;
69804 u.by.zSql = sqlite3MPrintf(db,
69806 db->aDb[u.by.iDb].zName, u.by.zMaster, pOp->p4.z);
69810 assert( db->init.busy==0 );
69811 db->init.busy = 1;
69813 assert( !db->mallocFailed );
69814 rc = sqlite3_exec(db, u.by.zSql, sqlite3InitCallback, &u.by.initData, 0);
69816 sqlite3DbFree(db, u.by.zSql);
69817 db->init.busy = 0;
69820 if( rc ) sqlite3ResetInternalSchema(db, -1);
69835 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69836 rc = sqlite3AnalysisLoad(db, pOp->p1);
69849 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
69861 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
69873 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
69911 u.bz.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.bz.nRoot+1) );
69922 assert( pOp->p5<db->nDb );
69924 u.bz.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bz.aRoot, u.bz.nRoot,
69926 sqlite3DbFree(db, u.bz.aRoot);
70094 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
70096 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
70115 u.cc.pFrame = sqlite3DbMallocZero(db, u.cc.nByte);
70140 u.cc.pMem->db = db;
70204 db->nDeferredCons += pOp->p2;
70224 if( db->nDeferredCons==0 ) pc = pOp->p2-1;
70354 u.cf.ctx.s.db = db;
70366 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cf.ctx.s));
70401 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cg.pMem));
70436 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ch.aRes[1], &u.ch.aRes[2]);
70478 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70480 u.ci.pBt = db->aDb[pOp->p1].pBt;
70502 if( !db->autoCommit || db->activeVdbeCnt>1 ){
70504 sqlite3SetString(&p->zErrMsg, db,
70561 rc = sqlite3RunVacuum(&p->zErrMsg, db);
70578 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70580 u.cj.pBt = db->aDb[pOp->p1].pBt;
70601 sqlite3ExpirePreparedStatements(db);
70625 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
70627 assert( p1>=0 && p1<db->nDb );
70630 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
70633 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
70655 rc = sqlite3VtabBegin(db, u.ck.pVTab);
70668 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
70681 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
70719 db->mallocFailed = 1;
70984 u8 vtabOnConflict = db->vtabOnConflict;
70994 db->vtabOnConflict = pOp->p5;
70996 db->vtabOnConflict = vtabOnConflict;
71000 db->lastRowid = lastRowid = u.cq.rowid;
71022 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
71041 pBt = db->aDb[pOp->p1].pBt;
71065 if( db->xTrace && (u.cr.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
71067 db->xTrace(db->pTraceArg, u.cr.z);
71068 sqlite3DbFree(db, u.cr.z);
71071 if( (db->flags & SQLITE_SqlTrace)!=0
71150 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
71153 sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
71160 db->lastRowid = lastRowid;
71168 sqlite3SetString(&p->zErrMsg, db, "string or blob too big");
71175 db->mallocFailed = 1;
71176 sqlite3SetString(&p->zErrMsg, db, "out of memory");
71185 if( db->mallocFailed ) rc = SQLITE_NOMEM;
71187 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
71195 assert( db
71198 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
71233 sqlite3 *db; /* The associated database */
71270 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
71292 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
71295 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
71310 sqlite3* db, /* The database connection */
71322 ** db/table/row entry. The reason for using a vdbe program instead
71363 sqlite3_mutex_enter(db->mutex);
71365 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
71367 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
71372 pParse->db = db;
71373 sqlite3DbFree(db, zErr);
71376 sqlite3BtreeEnterAll(db);
71390 sqlite3DbFree(db, zErr);
71395 sqlite3BtreeLeaveAll(db);
71406 sqlite3DbFree(db, zErr);
71407 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
71409 sqlite3BtreeLeaveAll(db);
71421 if( db->flags&SQLITE_ForeignKeys ){
71446 sqlite3DbFree(db, zErr);
71447 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
71449 sqlite3BtreeLeaveAll(db);
71454 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
71455 assert( pBlob->pStmt || db->mallocFailed );
71458 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
71500 if( !db->mallocFailed ){
71510 pBlob->db = db;
71511 sqlite3BtreeLeaveAll(db);
71512 if( db->mallocFailed ){
71520 if( rc==SQLITE_OK && db->mallocFailed==0 ){
71524 sqlite3DbFree(db, pBlob);
71526 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
71527 sqlite3DbFree(db, zErr);
71528 sqlite3StackFree(db, pParse);
71529 rc = sqlite3ApiExit(db, rc);
71530 sqlite3_mutex_leave(db->mutex);
71541 sqlite3 *db;
71544 db = p->db;
71545 sqlite3_mutex_enter(db->mutex);
71547 sqlite3DbFree(db, p);
71548 sqlite3_mutex_leave(db->mutex);
71568 sqlite3 *db;
71571 db = p->db;
71572 sqlite3_mutex_enter(db->mutex);
71578 sqlite3Error(db, SQLITE_ERROR, 0);
71588 assert( db == v->db );
71596 db->errCode = rc;
71600 rc = sqlite3ApiExit(db, rc);
71601 sqlite3_mutex_leave(db->mutex);
71643 sqlite3 *db;
71646 db = p->db;
71647 sqlite3_mutex_enter(db->mutex);
71658 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
71659 sqlite3DbFree(db, zErr);
71664 rc = sqlite3ApiExit(db, rc);
71666 sqlite3_mutex_leave(db->mutex);
71816 static void vdbeSorterIterZero(sqlite3 *db, VdbeSorterIter *pIter){
71817 sqlite3DbFree(db, pIter->aAlloc);
71826 sqlite3 *db, /* Database handle (for sqlite3DbMalloc() ) */
71842 vdbeSorterIterZero(db, pIter);
71854 pIter->aAlloc = sqlite3DbReallocOrFree(db, pIter->aAlloc, nNew);
71932 sqlite3 *db, /* Database handle */
71945 pIter->aAlloc = (u8 *)sqlite3DbMallocRaw(db, pIter->nAlloc);
71955 rc = vdbeSorterIterNext(db, pIter);
72057 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *db, VdbeCursor *pCsr){
72064 pCsr->pSorter = pSorter = sqlite3DbMallocZero(db, sizeof(VdbeSorter));
72073 if( !sqlite3TempInMemory(db) ){
72074 pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
72076 mxCache = db->aDb[0].pSchema->cache_size;
72087 static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord){
72092 sqlite3DbFree(db, p);
72099 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){
72105 vdbeSorterIterZero(db, &pSorter->aIter[i]);
72107 sqlite3DbFree(db, pSorter->aIter);
72112 vdbeSorterRecordFree(db, pSorter->pRecord);
72113 sqlite3DbFree(db, pSorter->pUnpacked);
72114 sqlite3DbFree(db, pSorter);
72124 static int vdbeSorterOpenTempFile(sqlite3 *db, sqlite3_file **ppFile){
72126 return sqlite3OsOpenMalloc(db->pVfs, 0, ppFile,
72219 static int vdbeSorterListToPMA(sqlite3 *db, VdbeCursor *pCsr){
72232 rc = vdbeSorterOpenTempFile(db, &pSorter->pTemp1);
72255 sqlite3DbFree(db, p);
72281 sqlite3 *db, /* Database handle */
72292 pNew = (SorterRecord *)sqlite3DbMallocRaw(db, pVal->n + sizeof(SorterRecord));
72316 rc = vdbeSorterListToPMA(db, pCsr);
72327 sqlite3 *db, /* Database handle */
72339 rc = vdbeSorterIterInit(db, pSorter, pSorter->iReadOff, pIter, &nByte);
72358 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *db, VdbeCursor *pCsr, int *pbEof){
72379 rc = vdbeSorterListToPMA(db, pCsr);
72388 pSorter->aIter = (VdbeSorterIter *)sqlite3DbMallocZero(db, nByte);
72411 rc = vdbeSorterInitMerge(db, pCsr, &nWrite);
72420 rc = vdbeSorterOpenTempFile(db, &pTemp2);
72437 rc = sqlite3VdbeSorterNext(db, pCsr, &bEof);
72466 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *db, VdbeCursor *pCsr, int *pbEof){
72474 rc = vdbeSorterIterNext(db, &pSorter->aIter[iPrev]);
72484 vdbeSorterRecordFree(db, pFree);
73259 sqlite3 *db; /* The database connection */
73265 db = pParse->db;
73267 pDup = sqlite3ExprDup(db, pOrig, 0);
73275 pDup = sqlite3ExprDup(db, pOrig, 0);
73281 pDup = sqlite3ExprDup(db, pOrig, 0);
73286 pDup->u.zToken = sqlite3DbStrDup(db, zToken);
73298 sqlite3ExprDelete(db, pExpr);
73300 sqlite3DbFree(db, pDup);
73327 ** pExpr->iDb Set the index in db->aDb[] of the database X
73359 sqlite3 *db = pParse->db; /* The database connection */
73388 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73399 if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
73589 sqlite3ExprDelete(db, pExpr->pLeft);
73591 sqlite3ExprDelete(db, pExpr->pRight);
73616 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
73617 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
73730 u8 enc = ENC(pParse->db); /* The database encoding */
73736 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
73738 pDef = sqlite3FindFunction(pParse->db, zId, nId, -1, enc, 0);
73815 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
73877 sqlite3 *db; /* Database connection */
73879 u8 savedSuppErr; /* Saved value of db->suppressErr */
73892 db = pParse->db;
73893 savedSuppErr = db->suppressErr;
73894 db->suppressErr = 1;
73896 db->suppressErr = savedSuppErr;
73949 sqlite3 *db;
73954 db = pParse->db;
73956 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
73987 pDup = sqlite3ExprDup(db, pE, 0);
73988 if( !db->mallocFailed ){
73992 sqlite3ExprDelete(db, pDup);
73998 sqlite3ExprDelete(db, pE);
73999 pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0);
74039 sqlite3 *db = pParse->db;
74043 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
74045 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
74142 sqlite3 *db; /* Database connection */
74151 db = pParse->db;
74163 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
74220 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
74275 if( db->mallocFailed ){
74285 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
74507 sqlite3 *db = pParse->db;
74508 zColl = sqlite3NameFromToken(db, pCollName);
74511 sqlite3DbFree(db, zColl);
74535 sqlite3 *db = pParse->db;
74537 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
74696 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
74806 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
74822 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
74855 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
74862 return sqlite3ExprAlloc(db, op, &x, 0);
74872 sqlite3 *db,
74878 assert( db->mallocFailed );
74879 sqlite3ExprDelete(db, pLeft);
74880 sqlite3ExprDelete(db, pRight);
74904 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
74914 Expr *p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
74915 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
74926 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
74932 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
74933 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
74944 sqlite3 *db = pParse->db;
74946 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
74948 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
74974 sqlite3 *db = pParse->db;
74997 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
74998 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
74999 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
75001 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
75024 a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
75025 if( a==0 ) return; /* Error reported through db->mallocFailed */
75031 sqlite3DbFree(db, pParse->azVar[x-1]);
75032 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
75036 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
75044 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
75049 sqlite3ExprDelete(db, p->pLeft);
75050 sqlite3ExprDelete(db, p->pRight);
75052 sqlite3DbFree(db, p->u.zToken);
75055 sqlite3SelectDelete(db, p->x.pSelect);
75057 sqlite3ExprListDelete(db, p->x.pList);
75061 sqlite3DbFree(db, p);
75174 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
75188 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
75229 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
75231 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
75239 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
75240 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
75248 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
75249 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
75275 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
75276 return exprDup(db, p, flags, 0);
75278 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
75283 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
75288 pNew->a = pItem = sqlite3DbMallocRaw(db, i*sizeof(p->a[0]) );
75290 sqlite3DbFree(db, pNew);
75296 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
75297 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
75298 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
75315 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
75321 pNew = sqlite3DbMallocRaw(db, nByte );
75328 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
75329 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
75330 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
75336 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
75343 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
75344 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
75345 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
75350 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
75354 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
75357 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
75359 sqlite3DbFree(db, pNew);
75368 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
75373 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
75376 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
75378 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
75379 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
75380 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
75381 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
75382 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
75383 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
75385 pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
75388 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
75389 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
75400 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
75420 sqlite3 *db = pParse->db;
75422 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
75426 pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
75431 a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
75447 sqlite3ExprDelete(db, pExpr);
75448 sqlite3ExprListDelete(db, pList);
75457 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
75466 assert( pList!=0 || pParse->db->mallocFailed!=0 );
75472 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
75482 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
75490 sqlite3 *db = pParse->db;
75491 assert( pList!=0 || db->mallocFailed!=0 );
75495 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
75496 sqlite3DbFree(db, pItem->zSpan);
75497 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
75511 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
75522 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
75528 sqlite3ExprDelete(db, pItem->pExpr);
75529 sqlite3DbFree(db, pItem->zName);
75530 sqlite3DbFree(db, pItem->zSpan);
75532 sqlite3DbFree(db, pList->a);
75533 sqlite3DbFree(db, pList);
75886 sqlite3 *db = pParse->db; /* Database connection */
75901 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
75936 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
76049 pParse->db, "EXECUTE %s%s SUBQUERY %d", testAddr>=0?"":"CORRELATED ",
76199 sqlite3ExprDelete(pParse->db, pSel->pLimit);
76453 if( pParse->db->flags & SQLITE_ColumnCache ) return;
76713 sqlite3 *db = pParse->db; /* The database connection */
76717 assert( pParse->db->mallocFailed );
76982 u8 enc = ENC(db); /* The text encoding used by this database */
76997 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
77045 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
77047 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
77059 if( !pColl ) pColl = db->pDfltColl;
77268 assert( db->mallocFailed || pParse->nErr>0
77339 assert( pParse->pVdbe || pParse->db->mallocFailed );
77762 if( (pParse->db->flags & SQLITE_FactorOutConst)!=0 ) return;
78201 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
78204 db,
78217 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
78220 db,
78269 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
78327 u8 enc = ENC(pParse->db);
78328 i = addAggInfoFunc(pParse->db, pAggInfo);
78335 pItem->pFunc = sqlite3FindFunction(pParse->db,
78518 sqlite3 *db = sqlite3_context_db_handle(context);
78547 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
78574 sqlite3 *db = sqlite3_context_db_handle(context);
78595 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
78599 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
78602 sqlite3DbFree(db, zOutput);
78606 sqlite3DbFree(db, zParent);
78610 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
78612 sqlite3DbFree(db, zOutput);
78638 sqlite3 *db = sqlite3_context_db_handle(context);
78686 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
78731 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
78734 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
78736 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
78737 sqlite3DbFree(db, zWhere);
78753 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
78768 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
78770 /* If the table is not located in the temp-db (in which case NULL is
78772 ** that is not part of the temp-db schema, add a clause to the WHERE
78776 sqlite3 *db = pParse->db;
78779 zWhere = whereOrName(db, zWhere, pTrig->zName);
78784 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
78785 sqlite3DbFree(pParse->db, zWhere);
78809 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
78810 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78816 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
78826 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
78869 sqlite3 *db = pParse->db; /* Database connection */
78877 int savedDbFlags; /* Saved value of db->flags */
78879 savedDbFlags = db->flags;
78880 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
78882 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
78886 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78887 zDb = db->aDb[iDb].zName;
78888 db->flags |= SQLITE_PreferBuiltin;
78891 zName = sqlite3NameFromToken(db, pName);
78897 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
78932 pVTab = sqlite3GetVTable(db, pTab);
78970 if( db->flags&SQLITE_ForeignKeys ){
78979 sqlite3DbFree(db, zWhere);
79013 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
79031 sqlite3DbFree(db, zWhere);
79036 if( db->flags&SQLITE_ForeignKeys ){
79051 sqlite3SrcListDelete(db, pSrc);
79052 sqlite3DbFree(db, zName);
79053 db->flags = savedDbFlags;
79099 sqlite3 *db; /* The database connection; */
79101 db = pParse->db;
79102 if( pParse->nErr || db->mallocFailed ) return;
79106 assert( sqlite3BtreeHoldsAllMutexes(db) );
79107 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
79108 zDb = db->aDb[iDb].zName;
79112 pTab = sqlite3FindTable(db, zTab, zDb);
79142 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
79158 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
79159 db->mallocFailed = 1;
79170 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
79173 int savedDbFlags = db->flags;
79177 db->flags |= SQLITE_PreferBuiltin;
79185 sqlite3DbFree(db, zCol);
79186 db->flags = savedDbFlags;
79221 sqlite3 *db = pParse->db;
79225 assert( sqlite3BtreeHoldsAllMutexes(db) );
79226 if( db->mallocFailed ) goto exit_begin_add_column;
79247 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79256 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
79264 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
79265 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
79267 db->mallocFailed = 1;
79273 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
79279 pNew->pSchema = db->aDb[iDb].pSchema;
79290 sqlite3SrcListDelete(db, pSrc);
79451 sqlite3 *db = pParse->db;
79452 Db *pDb;
79455 assert( sqlite3BtreeHoldsAllMutexes(db) );
79456 assert( sqlite3VdbeDb(v)==db );
79457 pDb = &db->aDb[iDb];
79465 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
79731 sqlite3 *db = pParse->db; /* Database handle */
79776 assert( sqlite3BtreeHoldsAllMutexes(db) );
79777 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79779 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
79782 db->aDb[iDb].zName ) ){
79801 aChngAddr = sqlite3DbMallocRaw(db, sizeof(int)*nCol);
79809 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
79902 sqlite3DbFree(db, aChngAddr);
80014 sqlite3 *db = pParse->db;
80015 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
80025 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
80043 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
80044 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
80070 sqlite3 *db = pParse->db;
80080 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
80088 for(i=0; i<db->nDb; i++){
80094 iDb = sqlite3FindDb(db, pName1);
80098 z = sqlite3NameFromToken(db, pName1);
80100 if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
80105 sqlite3DbFree(db, z);
80112 zDb = db->aDb[iDb].zName;
80113 z = sqlite3NameFromToken(db, pTableName);
80115 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
80120 sqlite3DbFree(db, z);
80132 sqlite3 *db;
80161 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
80166 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
80194 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
80201 sqlite3DbFree(db, p->u.z);
80204 sqlite3DbFree(db, pIdx->aSample);
80206 if( db && db->pnBytesFreed==0 ){
80211 UNUSED_PARAMETER(db);
80221 static int loadStat3(sqlite3 *db, const char *zDb){
80230 assert( db->lookaside.bEnabled==0 );
80231 if( !sqlite3FindTable(db, "sqlite_stat3", zDb) ){
80235 zSql = sqlite3MPrintf(db,
80241 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
80242 sqlite3DbFree(db, zSql);
80253 pIdx = sqlite3FindIndex(db, zIndex, zDb);
80257 pIdx->aSample = sqlite3DbMallocZero(db, nSample*sizeof(IndexSample));
80260 db->mallocFailed = 1;
80268 zSql = sqlite3MPrintf(db,
80273 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
80274 sqlite3DbFree(db, zSql);
80285 pIdx = sqlite3FindIndex(db, zIndex, zDb);
80330 pSample->u.z = sqlite3DbMallocRaw(db, n);
80332 db->mallocFailed = 1;
80361 ** If an OOM error occurs, this function always sets db->mallocFailed.
80365 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
80371 assert( iDb>=0 && iDb<db->nDb );
80372 assert( db->aDb[iDb].pBt!=0 );
80375 db, iDb, 0) );
80376 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
80380 sqlite3DeleteIndexSamples(db, pIdx);
80386 sInfo.db = db;
80387 sInfo.zDatabase = db->aDb[iDb].zName;
80388 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
80393 zSql = sqlite3MPrintf(db,
80398 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
80399 sqlite3DbFree(db, zSql);
80406 int lookasideEnabled = db->lookaside.bEnabled;
80407 db->lookaside.bEnabled = 0;
80408 rc = loadStat3(db, sInfo.zDatabase);
80409 db->lookaside.bEnabled = lookasideEnabled;
80414 db->mallocFailed = 1;
80492 sqlite3 *db = sqlite3_context_db_handle(context);
80498 Db *aNew;
80515 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
80516 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
80517 db->aLimit[SQLITE_LIMIT_ATTACHED]
80521 if( !db->autoCommit ){
80522 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
80525 for(i=0; i<db->nDb; i++){
80526 char *z = db->aDb[i].zName;
80529 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
80534 /* Allocate the new entry in the db->aDb[] array and initialise the schema
80537 if( db->aDb==db->aDbStatic ){
80538 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
80540 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
80542 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
80545 db->aDb = aNew;
80546 aNew = &db->aDb[db->nDb];
80553 flags = db->openFlags;
80554 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
80556 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
80563 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
80565 db->nDb++;
80568 zErrDyn = sqlite3MPrintf(db, "database is already attached");
80571 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
80574 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
80575 zErrDyn = sqlite3MPrintf(db,
80580 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
80582 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
80585 aNew->zName = sqlite3DbStrDup(db, zName);
80601 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
80609 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
80614 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
80615 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
80616 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
80625 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
80629 sqlite3BtreeEnterAll(db);
80630 rc = sqlite3Init(db, &zErrDyn);
80631 sqlite3BtreeLeaveAll(db);
80634 int iDb = db->nDb - 1;
80636 if( db->aDb[iDb].pBt ){
80637 sqlite3BtreeClose(db->aDb[iDb].pBt);
80638 db->aDb[iDb].pBt = 0;
80639 db->aDb[iDb].pSchema = 0;
80641 sqlite3ResetInternalSchema(db, -1);
80642 db->nDb = iDb;
80644 db->mallocFailed = 1;
80645 sqlite3DbFree(db, zErrDyn);
80646 zErrDyn = sqlite3MPrintf(db, "out of memory");
80648 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
80659 sqlite3DbFree(db, zErrDyn);
80678 sqlite3 *db = sqlite3_context_db_handle(context);
80680 Db *pDb = 0;
80686 for(i=0; i<db->nDb; i++){
80687 pDb = &db->aDb[i];
80692 if( i>=db->nDb ){
80700 if( !db->autoCommit ){
80713 sqlite3ResetInternalSchema(db, -1);
80736 sqlite3* db = pParse->db;
80773 assert( v || db->mallocFailed );
80788 sqlite3ExprDelete(db, pFilename);
80789 sqlite3ExprDelete(db, pDbname);
80790 sqlite3ExprDelete(db, pKey);
80852 sqlite3 *db;
80855 db = pParse->db;
80856 assert( db->nDb>iDb );
80858 pFix->zDb = db->aDb[iDb].zName;
80890 pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb);
81052 sqlite3 *db,
81056 sqlite3_mutex_enter(db->mutex);
81057 db->xAuth = xAuth;
81058 db->pAuthArg = pArg;
81059 sqlite3ExpirePreparedStatements(db);
81060 sqlite3_mutex_leave(db->mutex);
81088 sqlite3 *db = pParse->db; /* Database handle */
81089 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
81092 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
81094 if( db->nDb>2 || iDb!=0 ){
81121 sqlite3 *db = pParse->db;
81128 if( db->xAuth==0 ) return;
81129 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
81160 assert( iDb>=0 && iDb<db->nDb );
81179 sqlite3 *db = pParse->db;
81185 if( db->init.busy || IN_DECLARE_VTAB ){
81189 if( db->xAuth==0 ){
81192 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
81313 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
81322 pToplevel->db->mallocFailed = 1;
81359 sqlite3 *db;
81362 db = pParse->db;
81363 if( db->mallocFailed ) return;
81386 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
81390 if( db->init.busy==0 ){
81391 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81394 db->aDb[iDb].pSchema->iGeneration);
81401 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
81426 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
81428 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
81465 sqlite3 *db = pParse->db;
81472 zSql = sqlite3VMPrintf(db, zFormat, ap);
81481 sqlite3DbFree(db, zErrMsg);
81482 sqlite3DbFree(db, zSql);
81499 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
81506 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
81507 for(i=OMIT_TEMPDB; i<db->nDb; i++){
81509 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
81510 assert( sqlite3SchemaMutexHeld(db, j, 0) );
81511 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
81541 p = sqlite3FindTable(pParse->db, zName, zDbase);
81566 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
81571 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
81572 for(i=OMIT_TEMPDB; i<db->nDb; i++){
81574 Schema *pSchema = db->aDb[j].pSchema;
81576 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
81577 assert( sqlite3SchemaMutexHeld(db, j, 0) );
81587 static void freeIndex(sqlite3 *db, Index *p){
81589 sqlite3DeleteIndexSamples(db, p);
81591 sqlite3DbFree(db, p->zColAff);
81592 sqlite3DbFree(db, p);
81601 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
81606 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81607 pHash = &db->aDb[iDb].pSchema->idxHash;
81623 freeIndex(db, pIndex);
81625 db->flags |= SQLITE_InternChanges;
81639 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
81641 assert( iDb<db->nDb );
81645 Db *pDb = &db->aDb[iDb];
81646 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81655 pDb = &db->aDb[1];
81664 sqlite3BtreeEnterAll(db);
81665 for(i=0; i<db->nDb; i++){
81666 Db *pDb = &db->aDb[i];
81671 db->flags &= ~SQLITE_InternChanges;
81672 sqlite3VtabUnlockList(db);
81673 sqlite3BtreeLeaveAll(db);
81681 for(i=j=2; i<db->nDb; i++){
81682 struct Db *pDb = &db->aDb[i];
81684 sqlite3DbFree(db, pDb->zName);
81689 db->aDb[j] = db->aDb[i];
81693 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
81694 db->nDb = j;
81695 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
81696 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
81697 sqlite3DbFree(db, db->aDb);
81698 db->aDb = db->aDbStatic;
81705 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
81706 db->flags &= ~SQLITE_InternChanges;
81713 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
81719 sqlite3DbFree(db, pCol->zName);
81720 sqlite3ExprDelete(db, pCol->pDflt);
81721 sqlite3DbFree(db, pCol->zDflt);
81722 sqlite3DbFree(db, pCol->zType);
81723 sqlite3DbFree(db, pCol->zColl);
81725 sqlite3DbFree(db, pTable->aCol);
81738 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
81745 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
81751 if( !db || db->pnBytesFreed==0 ){
81756 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
81759 freeIndex(db, pIndex);
81763 sqlite3FkDelete(db, pTable);
81767 sqliteDeleteColumnNames(db, pTable);
81768 sqlite3DbFree(db, pTable->zName);
81769 sqlite3DbFree(db, pTable->zColAff);
81770 sqlite3SelectDelete(db, pTable->pSelect);
81772 sqlite3ExprDelete(db, pTable->pCheck);
81775 sqlite3VtabClear(db, pTable);
81777 sqlite3DbFree(db, pTable);
81784 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
81786 Db *pDb;
81788 assert( db!=0 );
81789 assert( iDb>=0 && iDb<db->nDb );
81791 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81793 pDb = &db->aDb[iDb];
81796 sqlite3DeleteTable(db, p);
81797 db->flags |= SQLITE_InternChanges;
81813 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
81816 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
81840 ** of a database ("main", "temp" or the name of an attached db). This
81841 ** function returns the index of the named database in db->aDb[], or
81842 ** -1 if the named db cannot be found.
81844 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
81847 Db *pDb;
81849 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
81861 ** "temp" or the name of an attached db). This routine returns the
81862 ** index of the named database in db->aDb[], or -1 if the named db
81865 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
81868 zName = sqlite3NameFromToken(db, pName);
81869 i = sqlite3FindDbName(db, zName);
81870 sqlite3DbFree(db, zName);
81897 sqlite3 *db = pParse->db;
81900 if( db->init.busy ) {
81906 iDb = sqlite3FindDb(db, pName1);
81913 assert( db->init.iDb==0 || db->init.busy );
81914 iDb = db->init.iDb;
81928 if( !pParse->db->init.busy && pParse->nested==0
81929 && (pParse->db->flags & SQLITE_WriteSchema)==0
81964 sqlite3 *db = pParse->db;
81997 zName = sqlite3NameFromToken(db, pName);
82002 if( db->init.iDb==1 ) isTemp = 1;
82007 char *zDb = db->aDb[iDb].zName;
82038 char *zDb = db->aDb[iDb].zName;
82042 pTable = sqlite3FindTable(db, zName, zDb);
82047 assert( !db->init.busy );
82052 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
82058 pTable = sqlite3DbMallocZero(db, sizeof(Table));
82060 db->mallocFailed = 1;
82067 pTable->pSchema = db->aDb[iDb].pSchema;
82079 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82092 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
82113 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
82117 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
82151 sqlite3DbFree(db, zName);
82181 sqlite3 *db = pParse->db;
82184 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
82189 z = sqlite3NameFromToken(db, pName);
82194 sqlite3DbFree(db, z);
82200 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
82202 sqlite3DbFree(db, z);
82310 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
82327 sqlite3 *db = pParse->db;
82339 sqlite3ExprDelete(db, pCol->pDflt);
82340 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
82341 sqlite3DbFree(db, pCol->zDflt);
82342 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
82346 sqlite3ExprDelete(db, pSpan->pExpr);
82424 sqlite3ExprListDelete(pParse->db, pList);
82435 sqlite3 *db = pParse->db;
82439 pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr);
82443 sqlite3ExprDelete(db, pCheckExpr);
82455 sqlite3 *db;
82459 db = pParse->db;
82460 zColl = sqlite3NameFromToken(db, pToken);
82478 sqlite3DbFree(db, zColl);
82503 sqlite3 *db = pParse->db;
82504 u8 enc = ENC(db);
82505 u8 initbusy = db->init.busy;
82508 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
82510 pColl = sqlite3GetCollSeq(db, enc, pColl, zName);
82538 sqlite3 *db = pParse->db;
82540 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82541 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
82603 static char *createTableStmt(sqlite3 *db, Table *p){
82625 db->mallocFailed = 1;
82676 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
82694 sqlite3 *db = pParse->db;
82697 if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
82703 assert( !db->init.busy || !pSelect );
82705 iDb = sqlite3SchemaToIndex(db, p->pSchema);
82729 /* If the db->init.busy is 1 it means we are reading the SQL off the
82732 ** for the table from the db->init.newTnum field. (The page number
82735 if( db->init.busy ){
82736 p->tnum = db->init.newTnum;
82745 if( !db->init.busy ){
82804 sqlite3DeleteTable(db, pSelTab);
82810 zStmt = createTableStmt(db, p);
82813 zStmt = sqlite3MPrintf(db,
82826 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
82834 sqlite3DbFree(db, zStmt);
82842 Db *pDb = &db->aDb[iDb];
82843 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82855 sqlite3MPrintf(db, "tbl_name='%q'", p->zName));
82861 if( db->init.busy ){
82864 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82869 db->mallocFailed = 1;
82873 db->flags |= SQLITE_InternChanges;
82910 sqlite3 *db = pParse->db;
82914 sqlite3SelectDelete(db, pSelect);
82920 sqlite3SelectDelete(db, pSelect);
82924 db, p->pSchema);
82928 sqlite3SelectDelete(db, pSelect);
82937 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
82938 sqlite3SelectDelete(db, pSelect);
82939 if( db->mallocFailed ){
82942 if( !db->init.busy ){
82977 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
83024 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
83026 u8 enableLookaside = db->lookaside.bEnabled;
83030 db->lookaside.bEnabled = 0;
83032 xAuth = db->xAuth;
83033 db->xAuth = 0;
83035 db->xAuth = xAuth;
83039 db->lookaside.bEnabled = enableLookaside;
83047 sqlite3DeleteTable(db, pSelTab);
83048 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
83054 sqlite3SelectDelete(db, pSel);
83067 static void sqliteViewResetAll(sqlite3 *db, int idx){
83069 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
83070 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
83071 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
83074 sqliteDeleteColumnNames(db, pTab);
83079 DbClearProperty(db, idx, DB_UnresetViews);
83103 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
83106 Db *pDb;
83108 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
83109 pDb = &db->aDb[iDb];
83150 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
83164 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
83206 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
83225 const char *zDbName = pParse->db->aDb[iDb].zName;
83229 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
83243 sqlite3 *db = pParse->db;
83245 Db *pDb = &db->aDb[iDb];
83264 pTrigger->pSchema==db->aDb[1].pSchema );
83305 sqliteViewResetAll(db, iDb);
83315 sqlite3 *db = pParse->db;
83318 if( db->mallocFailed ){
83323 if( noErr ) db->suppressErr++;
83326 if( noErr ) db->suppressErr--;
83332 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
83333 assert( iDb>=0 && iDb<db->nDb );
83345 const char *zDb = db->aDb[iDb].zName;
83359 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
83408 sqlite3SrcListDelete(db, pName);
83434 sqlite3 *db = pParse->db;
83470 pFKey = sqlite3DbMallocZero(db, nByte );
83515 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
83520 db->mallocFailed = 1;
83535 sqlite3DbFree(db, pFKey);
83537 sqlite3ExprListDelete(db, pFromCol);
83538 sqlite3ExprListDelete(db, pToCol);
83583 sqlite3 *db = pParse->db; /* The database connection */
83584 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
83588 db->aDb[iDb].zName ) ){
83715 sqlite3 *db = pParse->db;
83716 Db *pDb; /* The specific table containing the indexed database */
83726 if( db->mallocFailed || IN_DECLARE_VTAB ){
83739 ** to search for the table. 'Fix' the table name to this db
83752 if( !db->init.busy ){
83754 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
83769 if( !pTab || db->mallocFailed ) goto exit_create_index;
83770 assert( db->aDb[iDb].pSchema==pTab->pSchema );
83776 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
83778 pDb = &db->aDb[iDb];
83814 zName = sqlite3NameFromToken(db, pName);
83820 if( !db->init.busy ){
83821 if( sqlite3FindTable(db, zName, 0)!=0 ){
83826 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
83830 assert( !db->init.busy );
83839 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
83894 pIndex = sqlite3DbMallocZero(db,
83903 if( db->mallocFailed ){
83921 pIndex->pSchema = db->aDb[iDb].pSchema;
83922 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
83975 zColl = db->pDfltColl->zName;
83978 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
84050 if( db->init.busy ){
84052 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
84058 db->mallocFailed = 1;
84061 db->flags |= SQLITE_InternChanges;
84063 pIndex->tnum = db->init.newTnum;
84067 /* If the db->init.busy is 0 then create the index on disk. This
84071 ** The db->init.busy is 0 when the user first enters a CREATE INDEX
84072 ** command. db->init.busy is 1 when a database is opened and
84082 else{ /* if( db->init.busy==0 ) */
84102 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
84116 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
84122 sqlite3DbFree(db, zStmt);
84131 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
84142 if( db->init.busy || pTblName==0 ){
84162 sqlite3DbFree(db, pIndex->zColAff);
84163 sqlite3DbFree(db, pIndex);
84165 sqlite3ExprListDelete(db, pList);
84166 sqlite3SrcListDelete(db, pTblName);
84167 sqlite3DbFree(db, zName);
84213 sqlite3 *db = pParse->db;
84217 if( db->mallocFailed ){
84224 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
84239 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
84244 const char *zDb = db->aDb[iDb].zName;
84262 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
84271 sqlite3SrcListDelete(db, pName);
84290 sqlite3 *db, /* Connection to notify of malloc failures */
84300 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
84320 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
84323 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
84327 db,
84334 sqlite3IdListDelete(db, pList);
84337 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
84344 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
84348 sqlite3DbFree(db, pList->a[i].zName);
84350 sqlite3DbFree(db, pList->a);
84351 sqlite3DbFree(db, pList);
84375 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
84384 ** db->mallocFailed flag will be set to true.
84387 sqlite3 *db, /* Database connection to notify of OOM errors */
84405 pNew = sqlite3DbRealloc(db, pSrc,
84408 assert( db->mallocFailed );
84412 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
84469 sqlite3 *db, /* Connection to notify of malloc failures */
84477 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
84481 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
84482 if( db->mallocFailed ){
84483 sqlite3SrcListDelete(db, pList);
84495 pItem->zName = sqlite3NameFromToken(db, pTable);
84496 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
84506 assert(pList || pParse->db->mallocFailed );
84521 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
84526 sqlite3DbFree(db, pItem->zDatabase);
84527 sqlite3DbFree(db, pItem->zName);
84528 sqlite3DbFree(db, pItem->zAlias);
84529 sqlite3DbFree(db, pItem->zIndex);
84530 sqlite3DeleteTable(db, pItem->pTab);
84531 sqlite3SelectDelete(db, pItem->pSelect);
84532 sqlite3ExprDelete(db, pItem->pOn);
84533 sqlite3IdListDelete(db, pItem->pUsing);
84535 sqlite3DbFree(db, pList);
84565 sqlite3 *db = pParse->db;
84572 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
84579 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
84588 sqlite3ExprDelete(db, pOn);
84589 sqlite3IdListDelete(db, pUsing);
84590 sqlite3SelectDelete(db, pSubquery);
84608 pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy);
84643 sqlite3 *db;
84648 db = pParse->db;
84649 assert( db!=0 );
84650 /* if( db->aDb[0].pBt==0 ) return; */
84657 for(i=0; i<db->nDb; i++){
84672 assert( pParse->db!=0 );
84689 assert( pParse->db!=0 );
84704 char *zName = sqlite3NameFromToken(pParse->db, pName);
84712 sqlite3DbFree(pParse->db, zName);
84724 sqlite3 *db = pParse->db;
84725 if( db->aDb[1].pBt==0 && !pParse->explain ){
84735 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
84742 db->aDb[1].pBt = pBt;
84743 assert( db->aDb[1].pSchema );
84744 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
84745 db->mallocFailed = 1;
84783 sqlite3 *db = pToplevel->db;
84786 assert( iDb<db->nDb );
84787 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
84789 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84793 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
84806 sqlite3 *db = pParse->db;
84808 for(i=0; i<db->nDb; i++){
84809 Db *pDb = &db->aDb[i];
84911 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
84926 Db *pDb; /* A single database */
84928 sqlite3 *db = pParse->db; /* The database connection */
84932 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
84933 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
84964 sqlite3 *db = pParse->db; /* The database connection */
84979 zColl = sqlite3NameFromToken(pParse->db, pName1);
84981 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
84984 sqlite3DbFree(db, zColl);
84987 sqlite3DbFree(db, zColl);
84991 z = sqlite3NameFromToken(db, pObjName);
84993 zDb = db->aDb[iDb].zName;
84994 pTab = sqlite3FindTable(db, z, zDb);
84997 sqlite3DbFree(db, z);
85000 pIndex = sqlite3FindIndex(db, z, zDb);
85001 sqlite3DbFree(db, z);
85016 ** the caller is responsible for calling sqlite3DbFree(db, ) on the returned
85025 sqlite3 *db = pParse->db;
85026 KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(db, nBytes);
85029 pKey->db = pParse->db;
85042 sqlite3DbFree(db, pKey);
85071 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
85072 assert( !db->xCollNeeded || !db->xCollNeeded16 );
85073 if( db->xCollNeeded ){
85074 char *zExternal = sqlite3DbStrDup(db, zName);
85076 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
85077 sqlite3DbFree(db, zExternal);
85080 if( db->xCollNeeded16 ){
85082 sqlite3_value *pTmp = sqlite3ValueNew(db);
85086 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
85100 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
85106 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
85125 ** db for collation type name zName, length nName, or NULL, if no collation
85131 sqlite3* db, /* The database connection */
85140 p = sqlite3FindCollSeq(db, enc, zName, 0);
85146 callCollNeeded(db, enc, zName);
85147 p = sqlite3FindCollSeq(db, enc, zName, 0);
85149 if( p && !p->xCmp && synthCollSeq(db, p) ){
85170 sqlite3 *db = pParse->db;
85171 CollSeq *p = sqlite3GetCollSeq(db, ENC(db), pColl, zName);
85185 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
85198 sqlite3 *db, /* Database connection */
85204 pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
85207 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
85218 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
85226 db->mallocFailed = 1;
85227 sqlite3DbFree(db, pDel);
85238 ** for the encoding 'enc' from the database 'db'.
85251 sqlite3 *db,
85258 pColl = findCollSeqEntry(db, zName, create);
85260 pColl = db->pDfltColl;
85360 ** structure is created and liked into the "db" structure if a
85374 sqlite3 *db, /* An open database */
85388 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
85392 p = functionSearch(&db->aFunc, h, zName, nName);
85414 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
85433 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
85439 sqlite3FuncDefInsert(&db->aFunc, pBest);
85450 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
85488 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
85496 db->mallocFailed = 1;
85543 sqlite3DeleteTable(pParse->db, pItem->pTab);
85571 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
85573 && (pParse->db->flags & SQLITE_WriteSchema)==0
85604 sqlite3 *db = pParse->db;
85606 pDup = sqlite3SelectDup(db, pView->pSelect, 0);
85610 pWhere = sqlite3ExprDup(db, pWhere, 0);
85611 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
85614 pFrom->a[0].zAlias = sqlite3DbStrDup(db, pView->zName);
85619 sqlite3SelectDelete(db, pDup);
85625 sqlite3SelectDelete(db, pDup);
85686 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
85688 sqlite3ExprListDelete(pParse->db, pEList);
85710 sqlite3SelectDelete(pParse->db, pSelect);
85714 sqlite3ExprDelete(pParse->db, pWhere);
85715 sqlite3ExprListDelete(pParse->db, pOrderBy);
85716 sqlite3ExprDelete(pParse->db, pLimit);
85717 sqlite3ExprDelete(pParse->db, pOffset);
85742 sqlite3 *db; /* Main database structure */
85755 db = pParse->db;
85756 if( pParse->nErr || db->mallocFailed ){
85793 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
85794 assert( iDb<db->nDb );
85795 zDb = db->aDb[iDb].zName;
85847 if( db->flags & SQLITE_CountRows ){
85886 if( db->flags & SQLITE_CountRows ){
85909 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
85946 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
85954 sqlite3SrcListDelete(db, pTabList);
85955 sqlite3ExprDelete(db, pWhere);
86148 if( pTab->pSelect || (pParse->db->flags & SQLITE_IdxRealAsInt)!=0 ){
86471 sqlite3 *db = sqlite3_context_db_handle(context);
86473 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
86474 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
86475 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
86616 sqlite3 *db = sqlite3_context_db_handle(context);
86621 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
86636 sqlite3 *db = sqlite3_context_db_handle(context);
86638 sqlite3_result_int(context, sqlite3_changes(db));
86650 sqlite3 *db = sqlite3_context_db_handle(context);
86654 sqlite3_result_int(context, sqlite3_total_changes(db));
86854 sqlite3 *db = sqlite3_context_db_handle(context);
86863 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
86864 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
86865 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
87120 sqlite3 *db = sqlite3_context_db_handle(context);
87124 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
87125 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
87126 if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
87190 sqlite3 *db = sqlite3_context_db_handle(context);
87192 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
87193 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
87194 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
87371 sqlite3 *db = sqlite3_context_db_handle(context);
87379 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
87517 ** returns (void *)db, where db is the sqlite3* database pointer.
87560 sqlite3 *db = sqlite3_context_db_handle(context);
87563 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
87599 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
87600 int rc = sqlite3_overload_function(db, "MATCH", 2);
87603 db->mallocFailed = 1;
87610 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
87612 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
87624 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
87631 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
87632 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
87633 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
87635 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
87636 setLikeOptFlag(db, "like",
87647 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
87656 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
87956 ** pParse->db->mallocFailed flag is set.
87997 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
88057 sqlite3DbFree(pParse->db, aiCol);
88256 sqlite3 *db = pParse->db; /* Database handle */
88285 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
88305 pRight = sqlite3Expr(db, TK_ID, zCol);
88307 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
88318 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
88319 pRight = sqlite3Expr(db, TK_COLUMN, 0);
88327 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
88350 sqlite3ExprDelete(db, pWhere);
88412 sqlite3 *db = pParse->db;
88413 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
88434 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
88478 sqlite3 *db = pParse->db; /* Database handle */
88488 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
88490 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
88491 zDb = db->aDb[iDb].zName;
88509 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
88515 if( !isIgnoreErrors || db->mallocFailed ) return;
88550 if( db->xAuth ){
88577 sqlite3DbFree(db, aiFree);
88594 if( !isIgnoreErrors || db->mallocFailed ) return;
88602 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
88623 sqlite3SrcListDelete(db, pSrc);
88625 sqlite3DbFree(db, aiCol);
88640 if( pParse->db->flags&SQLITE_ForeignKeys ){
88677 if( pParse->db->flags&SQLITE_ForeignKeys ){
88752 sqlite3 *db = pParse->db; /* Database handle */
88761 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
88803 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
88821 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
88834 pNew = sqlite3ExprDup(db, pDflt, 0);
88845 sqlite3DbFree(db, aiCol);
88856 pRaise = sqlite3Expr(db, TK_RAISE, "foreign key constraint failed");
88862 sqlite3SrcListAppend(db, 0, &tFrom, 0),
88870 enableLookaside = db->lookaside.bEnabled;
88871 db->lookaside.bEnabled = 0;
88873 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
88884 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
88885 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
88886 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
88889 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
88894 db->lookaside.bEnabled = enableLookaside;
88896 sqlite3ExprDelete(db, pWhere);
88897 sqlite3ExprDelete(db, pWhen);
88898 sqlite3ExprListDelete(db, pList);
88899 sqlite3SelectDelete(db, pSelect);
88900 if( db->mallocFailed==1 ){
88901 fkTriggerDelete(db, pTrigger);
88942 if( pParse->db->flags&SQLITE_ForeignKeys ){
88960 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
88964 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
88968 if( !db || db->pnBytesFreed==0 ){
88988 fkTriggerDelete(db, pFKey->apTrigger[0]);
88989 fkTriggerDelete(db, pFKey->apTrigger[1]);
88993 sqlite3DbFree(db, pFKey);
89067 sqlite3 *db = sqlite3VdbeDb(v);
89070 db->mallocFailed = 1;
89108 sqlite3 *db = sqlite3VdbeDb(v);
89112 db->mallocFailed = 1;
89139 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
89202 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
89223 sqlite3 *db = pParse->db; /* The database connection */
89224 Db *pDb; /* Database only autoinc table */
89236 pDb = &db->aDb[p->iDb];
89238 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
89280 sqlite3 *db = pParse->db;
89284 Db *pDb = &db->aDb[p->iDb];
89290 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
89440 sqlite3 *db; /* The main database structure */
89459 Db *pDb; /* The database containing table being inserted into */
89478 db = pParse->db;
89480 if( pParse->nErr || db->mallocFailed ){
89493 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
89494 assert( iDb<db->nDb );
89495 pDb = &db->aDb[iDb];
89605 if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
89747 if( db->flags & SQLITE_CountRows ){
89758 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
89968 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
89989 if( (db->flags & SQLITE_CountRows)!=0 ){
90034 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
90041 sqlite3SrcListDelete(db, pTabList);
90042 sqlite3ExprListDelete(db, pList);
90043 sqlite3SelectDelete(db, pSelect);
90044 sqlite3IdListDelete(db, pColumn);
90045 sqlite3DbFree(db, aRegIdx);
90193 zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
90215 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
90282 if( pParse->db->flags&SQLITE_RecTriggers ){
90371 errMsg.db = pParse->db;
90383 sqlite3DbFree(errMsg.db, zErr);
90395 if( pParse->db->flags&SQLITE_RecTriggers ){
90495 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
90737 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
90741 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
90752 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
90873 sqlite3 *db, /* The database on which the SQL executes */
90886 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
90889 sqlite3_mutex_enter(db->mutex);
90890 sqlite3Error(db, SQLITE_OK, 0);
90896 rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
90917 && db->flags&SQLITE_NullCallback)) ){
90919 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
90936 db->mallocFailed = 1;
90945 sqlite3Error(db, SQLITE_ABORT, 0);
90962 sqlite3DbFree(db, azCols);
90968 sqlite3DbFree(db, azCols);
90970 rc = sqlite3ApiExit(db, rc);
90971 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
90972 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
90975 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
90978 sqlite3Error(db, SQLITE_NOMEM, 0);
90984 assert( (rc&db->errMask)==rc );
90985 sqlite3_mutex_leave(db->mutex);
91106 int (*errcode)(sqlite3*db);
91832 ** by calling sqlite3DbFree(db, ).
91835 sqlite3 *db, /* Load the extension into this database connection */
91840 sqlite3_vfs *pVfs = db->pVfs;
91855 if( (db->flags & SQLITE_LoadExtension)==0 ){
91892 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
91901 /* Append the new shared library handle to the db->aExtension array. */
91902 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
91906 if( db->nExtension>0 ){
91907 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
91909 sqlite3DbFree(db, db->aExtension);
91910 db->aExtension = aHandle;
91912 db->aExtension[db->nExtension++] = handle;
91916 sqlite3 *db, /* Load the extension into this database connection */
91922 sqlite3_mutex_enter(db->mutex);
91923 rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
91924 rc = sqlite3ApiExit(db, rc);
91925 sqlite3_mutex_leave(db->mutex);
91933 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
91935 assert( sqlite3_mutex_held(db->mutex) );
91936 for(i=0; i<db->nExtension; i++){
91937 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
91939 sqlite3DbFree(db, db->aExtension);
91946 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
91947 sqlite3_mutex_enter(db->mutex);
91949 db->flags |= SQLITE_LoadExtension;
91951 db->flags &= ~SQLITE_LoadExtension;
91953 sqlite3_mutex_leave(db->mutex);
92064 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
92090 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
92091 sqlite3Error(db, rc,
92188 ** Interpret the given string as a temp db location. Return 1 for file
92211 sqlite3 *db = pParse->db;
92212 if( db->aDb[1].pBt!=0 ){
92213 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
92218 sqlite3BtreeClose(db->aDb[1].pBt);
92219 db->aDb[1].pBt = 0;
92220 sqlite3ResetInternalSchema(db, -1);
92234 sqlite3 *db = pParse->db;
92235 if( db->temp_store==ts ) return SQLITE_OK;
92239 db->temp_store = (u8)ts;
92250 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
92263 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
92269 int mask; /* Mask for the db->flags value */
92308 sqlite3 *db = pParse->db;
92314 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
92317 if( db->autoCommit==0 ){
92324 db->flags |= mask;
92326 db->flags &= ~mask;
92416 sqlite3 *db = pParse->db; /* The database connection */
92417 Db *pDb; /* The specific database being pragmaed */
92418 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db); /* Prepared statement */
92425 ** index of the database this pragma is being applied to in db.aDb[]. */
92428 pDb = &db->aDb[iDb];
92437 zLeft = sqlite3NameFromToken(db, pId);
92440 zRight = sqlite3MPrintf(db, "-%T", pValue);
92442 zRight = sqlite3NameFromToken(db, pValue);
92459 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
92523 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
92550 db->nextPagesize = sqlite3Atoi(zRight);
92551 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
92552 db->mallocFailed = 1;
92574 for(ii=0; ii<db->nDb; ii++){
92575 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
92630 eMode = db->dfltLockMode;
92636 ** set on all attached databases, as well as the main db file.
92643 assert(pDb==&db->aDb[0]);
92644 for(ii=2; ii<db->nDb; ii++){
92645 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
92648 db->dfltLockMode = (u8)eMode;
92705 for(ii=db->nDb-1; ii>=0; ii--){
92706 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
92758 db->nextAutovac = (u8)eAuto;
92763 ** as an auto-vacuum capable db.
92832 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
92855 returnSingleInt(pParse, "temp_store", db->temp_store);
92884 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
92891 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
92892 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
92970 if( !db->autoCommit ){
93003 pTab = sqlite3FindTable(db, zRight, zDb);
93042 pIdx = sqlite3FindIndex(db, zRight, zDb);
93066 pTab = sqlite3FindTable(db, zRight, zDb);
93097 for(i=0; i<db->nDb; i++){
93098 if( db->aDb[i].pBt==0 ) continue;
93099 assert( db->aDb[i].zName!=0 );
93101 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
93103 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
93115 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
93129 pTab = sqlite3FindTable(db, zRight, zDb);
93187 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
93235 for(i=0; i<db->nDb; i++){
93252 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93253 pTbls = &db->aDb[i].pSchema->tblHash;
93275 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
93406 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
93415 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
93416 DbHasProperty(db, 0, DB_Empty)
93420 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
93562 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
93565 db->xWalCallback==sqlite3WalDefaultHook ?
93566 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
93577 sqlite3_db_release_memory(db);
93593 for(i=0; i<db->nDb; i++){
93598 if( db->aDb[i].zName==0 ) continue;
93599 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
93600 pBt = db->aDb[i].pBt;
93603 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
93616 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
93619 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
93631 sqlite3_key(db, zKey, i/2);
93633 sqlite3_rekey(db, zKey, i/2);
93660 if( db->autoCommit ){
93662 (db->flags&SQLITE_FullFSync)!=0,
93663 (db->flags&SQLITE_CkptFullFSync)!=0);
93667 sqlite3DbFree(db, zLeft);
93668 sqlite3DbFree(db, zRight);
93700 sqlite3 *db = pData->db;
93701 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
93703 sqlite3SetString(pData->pzErrMsg, db,
93706 *pData->pzErrMsg = sqlite3MAppendf(db, *pData->pzErrMsg,
93710 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT;
93727 sqlite3 *db = pData->db;
93732 assert( sqlite3_mutex_held(db->mutex) );
93733 DbClearProperty(db, iDb, DB_Empty);
93734 if( db->mallocFailed ){
93739 assert( iDb>=0 && iDb<db->nDb );
93745 ** But because db->init.busy is set to 1, no VDBE code is generated
93753 assert( db->init.busy );
93754 db->init.iDb = iDb;
93755 db->init.newTnum = sqlite3Atoi(argv[1]);
93756 db->init.orphanTrigger = 0;
93757 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
93758 rc = db->errCode;
93760 db->init.iDb = 0;
93762 if( db->init.orphanTrigger ){
93767 db->mallocFailed = 1;
93769 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
93784 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
93807 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
93812 Db *pDb;
93846 assert( iDb>=0 && iDb<db->nDb );
93847 assert( db->aDb[iDb].pSchema );
93848 assert( sqlite3_mutex_held(db->mutex) );
93849 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
93867 initData.db = db;
93876 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
93883 pDb = &db->aDb[iDb];
93886 DbSetProperty(db, 1, DB_SchemaLoaded);
93898 sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
93911 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
93928 ** For an attached db, it is an error if the encoding is not the same
93934 /* If opening the main database, set ENC(db). */
93937 ENC(db) = encoding;
93938 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
93940 /* If opening an attached database, the encoding much match ENC(db) */
93941 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
93942 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
93949 DbSetProperty(db, iDb, DB_Empty);
93951 pDb->pSchema->enc = ENC(db);
93975 sqlite3SetString(pzErrMsg, db, "unsupported file format");
93986 db->flags &= ~SQLITE_LegacyFileFmt;
93991 assert( db->init.busy );
93994 zSql = sqlite3MPrintf(db,
93996 db->aDb[iDb].zName, zMasterName);
94000 xAuth = db->xAuth;
94001 db->xAuth = 0;
94003 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
94005 db->xAuth = xAuth;
94009 sqlite3DbFree(db, zSql);
94012 sqlite3AnalysisLoad(db, iDb);
94016 if( db->mallocFailed ){
94018 sqlite3ResetInternalSchema(db, -1);
94020 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
94029 DbSetProperty(db, iDb, DB_SchemaLoaded);
94045 db->mallocFailed = 1;
94057 ** bit is set in the flags field of the Db structure. If the database
94060 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
94062 int commit_internal = !(db->flags&SQLITE_InternChanges);
94064 assert( sqlite3_mutex_held(db->mutex) );
94066 db->init.busy = 1;
94067 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
94068 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
94069 rc = sqlite3InitOne(db, i, pzErrMsg);
94071 sqlite3ResetInternalSchema(db, i);
94080 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
94081 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
94082 rc = sqlite3InitOne(db, 1, pzErrMsg);
94084 sqlite3ResetInternalSchema(db, 1);
94089 db->init.busy = 0;
94091 sqlite3CommitInternalChanges(db);
94103 sqlite3 *db = pParse->db;
94104 assert( sqlite3_mutex_held(db->mutex) );
94105 if( !db->init.busy ){
94106 rc = sqlite3Init(db, &pParse->zErrMsg);
94122 sqlite3 *db = pParse->db;
94128 assert( sqlite3_mutex_held(db->mutex) );
94129 for(iDb=0; iDb<db->nDb; iDb++){
94131 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
94140 db->mallocFailed = 1;
94150 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94151 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
94152 sqlite3ResetInternalSchema(db, iDb);
94165 ** which database file in db->aDb[] the schema refers to.
94170 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
94179 ** -1000000 as the incorrect index into db->aDb[] is much
94183 assert( sqlite3_mutex_held(db->mutex) );
94185 for(i=0; ALWAYS(i<db->nDb); i++){
94186 if( db->aDb[i].pSchema==pSchema ){
94190 assert( i>=0 && i<db->nDb );
94199 sqlite3 *db, /* Database handle. */
94213 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
94220 assert( !db->mallocFailed );
94221 assert( sqlite3_mutex_held(db->mutex) );
94246 for(i=0; i<db->nDb; i++) {
94247 Btree *pBt = db->aDb[i].pBt;
94252 const char *zDb = db->aDb[i].zName;
94253 sqlite3Error(db, rc, "database schema is locked: %s", zDb);
94254 testcase( db->flags & SQLITE_ReadUncommitted );
94260 sqlite3VtabUnlockList(db);
94262 pParse->db = db;
94266 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
94270 sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
94271 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
94274 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
94277 sqlite3DbFree(db, zSqlCopy);
94287 if( db->mallocFailed ){
94294 if( db->mallocFailed ){
94325 assert( db->init.busy==0 || saveSqlFlag==0 );
94326 if( db->init.busy==0 ){
94330 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
94338 sqlite3Error(db, rc, "%s", zErrMsg);
94339 sqlite3DbFree(db, zErrMsg);
94341 sqlite3Error(db, rc, 0);
94348 sqlite3DbFree(db, pT);
94353 sqlite3StackFree(db, pParse);
94354 rc = sqlite3ApiExit(db, rc);
94355 assert( (rc&db->errMask)==rc );
94359 sqlite3 *db, /* Database handle. */
94370 if( !sqlite3SafetyCheckOk(db) ){
94373 sqlite3_mutex_enter(db->mutex);
94374 sqlite3BtreeEnterAll(db);
94375 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
94378 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
94380 sqlite3BtreeLeaveAll(db);
94381 sqlite3_mutex_leave(db->mutex);
94397 sqlite3 *db;
94402 db = sqlite3VdbeDb(p);
94403 assert( sqlite3_mutex_held(db->mutex) );
94404 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
94407 db->mallocFailed = 1;
94431 sqlite3 *db, /* Database handle. */
94438 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
94443 sqlite3 *db, /* Database handle. */
94450 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
94461 sqlite3 *db, /* Database handle. */
94478 if( !sqlite3SafetyCheckOk(db) ){
94481 sqlite3_mutex_enter(db->mutex);
94482 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
94484 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
94496 sqlite3DbFree(db, zSql8);
94497 rc = sqlite3ApiExit(db, rc);
94498 sqlite3_mutex_leave(db->mutex);
94511 sqlite3 *db, /* Database handle. */
94518 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
94523 sqlite3 *db, /* Database handle. */
94530 rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
94559 static void clearSelect(sqlite3 *db, Select *p){
94560 sqlite3ExprListDelete(db, p->pEList);
94561 sqlite3SrcListDelete(db, p->pSrc);
94562 sqlite3ExprDelete(db, p->pWhere);
94563 sqlite3ExprListDelete(db, p->pGroupBy);
94564 sqlite3ExprDelete(db, p->pHaving);
94565 sqlite3ExprListDelete(db, p->pOrderBy);
94566 sqlite3SelectDelete(db, p->pPrior);
94567 sqlite3ExprDelete(db, p->pLimit);
94568 sqlite3ExprDelete(db, p->pOffset);
94601 sqlite3 *db = pParse->db;
94602 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
94603 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
94605 assert( db->mallocFailed );
94610 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
94613 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
94627 if( db->mallocFailed ) {
94628 clearSelect(db, pNew);
94629 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
94641 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
94643 clearSelect(db, p);
94644 sqlite3DbFree(db, p);
94788 sqlite3 *db = pParse->db;
94798 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
94799 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
94808 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
94914 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
95296 sqlite3 *db = pParse->db;
95303 pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
95307 pInfo->enc = ENC(db);
95308 pInfo->db = db;
95313 pColl = db->pDfltColl;
95352 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
95398 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
95629 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
95630 zOriginDb = pNC->pParse->db->aDb[iDb].zName;
95714 sqlite3 *db = pParse->db;
95724 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
95726 fullNames = (db->flags & SQLITE_FullColNames)!=0;
95727 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
95754 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
95757 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
95764 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
95789 sqlite3 *db = pParse->db; /* Database connection */
95799 aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
95809 zName = sqlite3DbStrDup(db, zName);
95822 zName = sqlite3MPrintf(db, "%s",
95826 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
95829 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
95832 if( db->mallocFailed ){
95833 sqlite3DbFree(db, zName);
95845 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
95846 sqlite3DbFree(db, zName);
95854 if( db->mallocFailed ){
95856 sqlite3DbFree(db, aCol[j].zName);
95858 sqlite3DbFree(db, aCol);
95883 sqlite3 *db = pParse->db;
95893 assert( nCol==pSelect->pEList->nExpr || db->mallocFailed );
95894 if( db->mallocFailed ) return;
95900 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0));
95905 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
95916 sqlite3 *db = pParse->db;
95919 savedFlags = db->flags;
95920 db->flags &= ~SQLITE_FullColNames;
95921 db->flags |= SQLITE_ShortColNames;
95925 db->flags = savedFlags;
95926 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
95932 assert( db->lookaside.bEnabled==0 );
95939 if( db->mallocFailed ){
95940 sqlite3DeleteTable(db, pTab);
95953 v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
96107 sqlite3 *db; /* Database connection */
96117 db = pParse->db;
96271 sqlite3ExprListDelete(db, p->pOrderBy);
96276 sqlite3ExprDelete(db, p->pLimit);
96356 sqlite3ExprDelete(db, p->pLimit);
96408 pKeyInfo = sqlite3DbMallocZero(db,
96415 pKeyInfo->enc = ENC(db);
96421 *apColl = db->pDfltColl;
96439 sqlite3DbFree(db, pKeyInfo);
96445 sqlite3SelectDelete(db, pDelete);
96500 if( pParse->db->mallocFailed ) return 0;
96729 sqlite3 *db; /* Database connection */
96740 db = pParse->db;
96761 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
96768 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
96785 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
96793 sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1));
96797 pKeyMerge->enc = ENC(db);
96819 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
96829 assert( nOrderBy>=nExpr || db->mallocFailed );
96832 pKeyDup = sqlite3DbMallocZero(db,
96837 pKeyDup->enc = ENC(db);
96864 sqlite3ExprDelete(db, p->pLimit);
96866 sqlite3ExprDelete(db, p->pOffset);
97032 sqlite3SelectDelete(db, p->pPrior);
97062 sqlite3 *db, /* Report malloc errors to this connection */
97075 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
97079 sqlite3ExprDelete(db, pExpr);
97083 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
97084 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
97086 substSelect(db, pExpr->x.pSelect, iTable, pEList);
97088 substExprList(db, pExpr->x.pList, iTable, pEList);
97094 sqlite3 *db, /* Report malloc errors here */
97102 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
97106 sqlite3 *db, /* Report malloc errors here */
97115 substExprList(db, p->pEList, iTable, pEList);
97116 substExprList(db, p->pGroupBy, iTable, pEList);
97117 substExprList(db, p->pOrderBy, iTable, pEList);
97118 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
97119 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
97120 substSelect(db, p->pPrior, iTable, pEList);
97125 substSelect(db, pItem->pSelect, iTable, pEList);
97265 sqlite3 *db = pParse->db;
97271 if( db->flags & SQLITE_QueryFlattener ) return 0;
97428 pNew = sqlite3SelectDup(db, p, 0);
97441 if( db->mallocFailed ) return 1;
97452 sqlite3DbFree(db, pSubitem->zDatabase);
97453 sqlite3DbFree(db, pSubitem->zName);
97454 sqlite3DbFree(db, pSubitem->zAlias);
97504 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
97506 assert( db->mallocFailed );
97527 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
97528 if( db->mallocFailed ){
97537 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
97560 pList->a[i].zName = sqlite3DbStrDup(db, zSpan);
97564 substExprList(db, pParent->pEList, iParent, pSub->pEList);
97566 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
97567 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
97574 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
97577 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
97585 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
97586 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
97587 sqlite3ExprDup(db, pSub->pHaving, 0));
97589 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
97591 pParent->pWhere = substExpr(db, pParent->pWhere, iParent, pSub->pEList);
97592 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
97615 sqlite3SelectDelete(db, pSub1);
97742 sqlite3 *db = pParse->db;
97744 if( db->mallocFailed ){
97778 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
97781 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
97800 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
97814 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
97843 int flags = pParse->db->flags;
97879 if( db->mallocFailed ) break;
97914 pRight = sqlite3Expr(db, TK_ID, zName);
97919 pLeft = sqlite3Expr(db, TK_ID, zTabName);
97922 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
97932 sqlite3DbFree(db, zToFree);
97944 sqlite3ExprListDelete(db, pEList);
97948 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
97980 ** and/or pParse->db->mallocFailed.
98067 sqlite3 *db;
98069 db = pParse->db;
98072 if( pParse->nErr || db->mallocFailed ) return;
98074 if( pParse->nErr || db->mallocFailed ) return;
98171 pColl = pParse->db->pDfltColl;
98222 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s %s%s(~%d rows)",
98313 sqlite3 *db; /* The database connection */
98320 db = pParse->db;
98321 if( p==0 || db->mallocFailed || pParse->nErr ){
98332 sqlite3ExprListDelete(db, p->pOrderBy);
98340 if( pParse->nErr || db->mallocFailed ){
98422 if( /*pParse->nErr ||*/ db->mallocFailed ){
98451 mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
98471 && (db->flags & SQLITE_GroupByOrder)==0 ){
98494 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
98672 if( db->mallocFailed ) goto select_end;
98906 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
98979 pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->x.pList,0);
98981 if( pMinMax && !db->mallocFailed ){
98994 sqlite3ExprListDelete(db, pDel);
99011 sqlite3ExprListDelete(db, pDel);
99050 sqlite3DbFree(db, sAggInfo.aCol);
99051 sqlite3DbFree(db, sAggInfo.aFunc);
99270 sqlite3 *db, /* The database on which the SQL executes */
99292 db->errCode = SQLITE_NOMEM;
99296 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
99308 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
99321 db->errCode = SQLITE_NOMEM;
99369 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
99374 sqlite3ExprDelete(db, pTmp->pWhere);
99375 sqlite3ExprListDelete(db, pTmp->pExprList);
99376 sqlite3SelectDelete(db, pTmp->pSelect);
99377 sqlite3IdListDelete(db, pTmp->pIdList);
99379 sqlite3DbFree(db, pTmp);
99398 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
99407 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
99445 sqlite3 *db = pParse->db; /* The database connection */
99447 Token *pName; /* The unqualified db name */
99448 DbFixer sFix; /* State vector for the DB fixer */
99464 /* Figure out the db that the the trigger will be created in */
99470 if( !pTableName || db->mallocFailed ){
99482 if( db->init.busy && iDb!=1 ){
99483 sqlite3DbFree(db, pTableName->a[0].zDatabase);
99493 if( db->init.busy==0 && pName2->n==0 && pTab
99494 && pTab->pSchema==db->aDb[1].pSchema ){
99499 if( db->mallocFailed ) goto trigger_cleanup;
99508 if( db->init.iDb==1 ){
99517 db->init.orphanTrigger = 1;
99528 zName = sqlite3NameFromToken(db, pName);
99532 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99533 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
99538 assert( !db->init.busy );
99564 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
99569 const char *zDb = db->aDb[iTabDb].zName;
99570 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
99591 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
99595 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
99596 pTrigger->pSchema = db->aDb[iDb].pSchema;
99600 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
99601 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
99606 sqlite3DbFree(db, zName);
99607 sqlite3SrcListDelete(db, pTableName);
99608 sqlite3IdListDelete(db, pColumns);
99609 sqlite3ExprDelete(db, pWhen);
99611 sqlite3DeleteTrigger(db, pTrigger);
99628 sqlite3 *db = pParse->db; /* The database */
99636 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
99652 if( !db->init.busy ){
99660 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
99663 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
99665 sqlite3DbFree(db, z);
99668 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
99671 if( db->init.busy ){
99673 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
99674 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99677 db->mallocFailed = 1;
99689 sqlite3DeleteTrigger(db, pTrig);
99691 sqlite3DeleteTriggerStep(db, pStepList);
99701 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
99702 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
99704 sqlite3SelectDelete(db, pSelect);
99717 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
99720 sqlite3 *db, /* Database connection */
99726 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
99745 sqlite3 *db, /* The database connection */
99755 assert(pEList != 0 || pSelect != 0 || db->mallocFailed);
99757 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
99759 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99761 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
99764 sqlite3IdListDelete(db, pColumn);
99766 sqlite3ExprListDelete(db, pEList);
99767 sqlite3SelectDelete(db, pSelect);
99778 sqlite3 *db, /* The database connection */
99786 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
99788 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
99789 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99792 sqlite3ExprListDelete(db, pEList);
99793 sqlite3ExprDelete(db, pWhere);
99803 sqlite3 *db, /* Database connection */
99809 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
99811 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99814 sqlite3ExprDelete(db, pWhere);
99821 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
99823 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
99824 sqlite3DbFree(db, pTrigger->zName);
99825 sqlite3DbFree(db, pTrigger->table);
99826 sqlite3ExprDelete(db, pTrigger->pWhen);
99827 sqlite3IdListDelete(db, pTrigger->pColumns);
99828 sqlite3DbFree(db, pTrigger);
99845 sqlite3 *db = pParse->db;
99847 if( db->mallocFailed ) goto drop_trigger_cleanup;
99856 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
99857 for(i=OMIT_TEMPDB; i<db->nDb; i++){
99859 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
99860 assert( sqlite3SchemaMutexHeld(db, j, 0) );
99861 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
99876 sqlite3SrcListDelete(db, pName);
99895 sqlite3 *db = pParse->db;
99898 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
99899 assert( iDb>=0 && iDb<db->nDb );
99906 const char *zDb = db->aDb[iDb].zName;
99950 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
99954 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99955 pHash = &(db->aDb[iDb].pSchema->trigHash);
99964 sqlite3DeleteTrigger(db, pTrigger);
99965 db->flags |= SQLITE_InternChanges;
100004 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
100036 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
100040 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
100042 sqlite3 *db = pParse->db;
100043 assert( iDb<pParse->db->nDb );
100044 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
100061 sqlite3 *db = pParse->db;
100086 sqlite3ExprListDup(db, pStep->pExprList, 0),
100087 sqlite3ExprDup(db, pStep->pWhere, 0),
100095 sqlite3ExprListDup(db, pStep->pExprList, 0),
100096 sqlite3SelectDup(db, pStep->pSelect, 0),
100097 sqlite3IdListDup(db, pStep->pIdList),
100105 sqlite3ExprDup(db, pStep->pWhere, 0)
100111 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
100114 sqlite3SelectDelete(db, pSelect);
100156 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
100171 sqlite3 *db = pParse->db; /* Database handle */
100186 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
100190 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
100200 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
100204 pSubParse->db = db;
100223 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
100231 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
100233 && db->mallocFailed==0
100238 sqlite3ExprDelete(db, pWhen);
100252 if( db->mallocFailed==0 ){
100266 sqlite3StackFree(db, pSubParse);
100322 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
100327 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
100408 || p->pSchema==pParse->db->aDb[1].pSchema );
100580 sqlite3 *db; /* The database structure */
100610 db = pParse->db;
100611 if( pParse->nErr || db->mallocFailed ){
100620 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
100645 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
100699 pTab->aCol[j].zName, db->aDb[iDb].zName);
100718 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
100810 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
100995 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
101030 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
101038 sqlite3DbFree(db, aRegIdx);
101039 sqlite3DbFree(db, aXRef);
101040 sqlite3SrcListDelete(db, pTabList);
101041 sqlite3ExprListDelete(db, pChanges);
101042 sqlite3ExprDelete(db, pWhere);
101093 sqlite3 *db = pParse->db; /* Database connection */
101094 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
101100 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));
101103 sqlite3ExprDup(db, pRowid, 0));
101108 pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);
101110 pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
101147 sqlite3SelectDelete(db, pSelect);
101175 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
101179 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
101185 ** Execute zSql on database db. Return an error code.
101187 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
101193 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
101194 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
101195 return sqlite3_errcode(db);
101198 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
101199 return vacuumFinalize(db, pStmt, pzErrMsg);
101203 ** Execute zSql on database db. The statement returns exactly
101206 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
101210 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
101214 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
101216 vacuumFinalize(db, pStmt, pzErrMsg);
101221 return vacuumFinalize(db, pStmt, pzErrMsg);
101245 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
101250 int saved_flags; /* Saved value of the db->flags */
101251 int saved_nChange; /* Saved value of db->nChange */
101252 int saved_nTotalChange; /* Saved value of db->nTotalChange */
101253 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */
101254 Db *pDb = 0; /* Database to detach at end of vacuum */
101259 if( !db->autoCommit ){
101260 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
101263 if( db->activeVdbeCnt>1 ){
101264 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
101271 saved_flags = db->flags;
101272 saved_nChange = db->nChange;
101273 saved_nTotalChange = db->nTotalChange;
101274 saved_xTrace = db->xTrace;
101275 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
101276 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
101277 db->xTrace = 0;
101279 pMain = db->aDb[0].pBt;
101296 nDb = db->nDb;
101297 if( sqlite3TempInMemory(db) ){
101302 rc = execSql(db, pzErrMsg, zSql);
101303 if( db->nDb>nDb ){
101304 pDb = &db->aDb[db->nDb-1];
101308 pTemp = db->aDb[db->nDb-1].pBt;
101320 if( db->nextPagesize ){
101324 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
101325 if( nKey ) db->nextPagesize = 0;
101329 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
101336 rc = execSql(db, pzErrMsg, "BEGIN;");
101344 db->nextPagesize = 0;
101348 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
101349 || NEVER(db->mallocFailed)
101356 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
101363 rc = execExecSql(db, pzErrMsg,
101369 rc = execExecSql(db, pzErrMsg,
101373 rc = execExecSql(db, pzErrMsg,
101382 rc = execExecSql(db, pzErrMsg,
101393 rc = execExecSql(db, pzErrMsg,
101398 rc = execExecSql(db, pzErrMsg,
101411 rc = execSql(db, pzErrMsg,
101468 /* Restore the original value of db->flags */
101469 db->flags = saved_flags;
101470 db->nChange = saved_nChange;
101471 db->nTotalChange = saved_nTotalChange;
101472 db->xTrace = saved_xTrace;
101482 db->autoCommit = 1;
101490 /* This both clears the schemas and reduces the size of the db->aDb[]
101492 sqlite3ResetInternalSchema(db, -1);
101534 sqlite3 *db, /* Database in which module is registered */
101543 sqlite3_mutex_enter(db->mutex);
101545 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
101554 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
101556 sqlite3ResetInternalSchema(db, -1);
101559 sqlite3DbFree(db, pDel);
101561 db->mallocFailed = 1;
101566 rc = sqlite3ApiExit(db, SQLITE_OK);
101567 sqlite3_mutex_leave(db->mutex);
101576 sqlite3 *db, /* Database in which module is registered */
101581 return createModule(db, zName, pModule, pAux, 0);
101588 sqlite3 *db, /* Database in which module is registered */
101594 return createModule(db, zName, pModule, pAux, xDestroy);
101612 ** Return a pointer to the VTable object used by connection db to access
101615 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
101618 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
101627 sqlite3 *db = pVTab->db;
101629 assert( db );
101631 assert( sqlite3SafetyCheckOk(db) );
101639 sqlite3DbFree(db, pVTab);
101647 ** Except, if argument db is not NULL, then the entry associated with
101648 ** connection db is left in the p->pVTable list.
101650 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
101661 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
101664 sqlite3 *db2 = pVTable->db;
101667 if( db2==db ){
101678 assert( !db || pRet );
101687 ** shared b-tree databases opened using connection db are held by the
101703 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
101704 VTable *p = db->pDisconnect;
101705 db->pDisconnect = 0;
101707 assert( sqlite3BtreeHoldsAllMutexes(db) );
101708 assert( sqlite3_mutex_held(db->mutex) );
101711 sqlite3ExpirePreparedStatements(db);
101729 ** connection db is decremented immediately (which may lead to the
101734 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
101735 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
101739 sqlite3DbFree(db, p->azModuleArg[i]);
101741 sqlite3DbFree(db, p->azModuleArg);
101751 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
101755 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
101759 sqlite3DbFree(db, pTable->azModuleArg[j]);
101761 sqlite3DbFree(db, zArg);
101762 sqlite3DbFree(db, pTable->azModuleArg);
101785 sqlite3 *db; /* Database connection */
101792 db = pParse->db;
101793 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
101798 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
101799 addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName));
101800 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
101811 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
101825 sqlite3 *db = pParse->db;
101826 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
101836 sqlite3 *db = pParse->db; /* The database connection */
101849 if( !db->init.busy ){
101859 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
101869 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
101874 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
101880 sqlite3DbFree(db, zStmt);
101885 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
101901 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
101904 db->mallocFailed = 1;
101943 sqlite3 *db,
101955 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
101961 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
101963 sqlite3DbFree(db, zModuleName);
101966 pVTable->db = db;
101970 assert( &db->pVtabCtx );
101974 db->pVtabCtx = &sCtx;
101975 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
101976 db->pVtabCtx = 0;
101977 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
101981 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
101983 *pzErr = sqlite3MPrintf(db, "%s", zErr);
101986 sqlite3DbFree(db, pVTable);
101994 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
102039 sqlite3DbFree(db, zModuleName);
102051 sqlite3 *db = pParse->db;
102057 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
102063 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
102071 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
102075 sqlite3DbFree(db, zErr);
102081 ** Grow the db->aVTrans[] array so that there is room for at least one
102084 static int growVTrans(sqlite3 *db){
102088 if( (db->nVTrans%ARRAY_INCR)==0 ){
102090 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
102091 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
102095 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
102096 db->aVTrans = aVTrans;
102106 static void addToVTrans(sqlite3 *db, VTable *pVTab){
102108 db->aVTrans[db->nVTrans++] = pVTab;
102118 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
102120 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
102126 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
102131 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
102138 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
102141 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
102146 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
102147 rc = growVTrans(db);
102149 addToVTrans(db, sqlite3GetVTable(db, pTab));
102161 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
102168 sqlite3_mutex_enter(db->mutex);
102169 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
102170 sqlite3Error(db, SQLITE_MISUSE, 0);
102171 sqlite3_mutex_leave(db->mutex);
102176 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
102181 pParse->db = db;
102186 && !db->mallocFailed
102196 db->pVtabCtx->pTab = 0;
102198 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
102199 sqlite3DbFree(db, zErr);
102207 sqlite3DeleteTable(db, pParse->pNewTable);
102208 sqlite3StackFree(db, pParse);
102212 rc = sqlite3ApiExit(db, rc);
102213 sqlite3_mutex_leave(db->mutex);
102224 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
102228 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
102230 VTable *p = vtabDisconnectAll(db, pTab);
102255 static void callFinaliser(sqlite3 *db, int offset){
102257 if( db->aVTrans ){
102258 for(i=0; i<db->nVTrans; i++){
102259 VTable *pVTab = db->aVTrans[i];
102269 sqlite3DbFree(db, db->aVTrans);
102270 db->nVTrans = 0;
102271 db->aVTrans = 0;
102283 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
102286 VTable **aVTrans = db->aVTrans;
102288 db->aVTrans = 0;
102289 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
102294 sqlite3DbFree(db, *pzErrmsg);
102295 *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
102299 db->aVTrans = aVTrans;
102307 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
102308 callFinaliser(db
102316 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
102317 callFinaliser(db, offsetof(sqlite3_module,xCommit));
102329 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
102333 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
102338 if( sqlite3VtabInSync(db) ){
102350 for(i=0; i<db->nVTrans; i++){
102351 if( db->aVTrans[i]==pVTab ){
102358 rc = growVTrans(db);
102362 addToVTrans(db, pVTab);
102384 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
102389 if( db->aVTrans ){
102391 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
102392 VTable *pVTab = db->aVTrans[i];
102431 sqlite3 *db, /* Database connection for reporting malloc problems */
102453 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
102462 zLowerName = sqlite3DbStrDup(db, pDef->zName);
102468 sqlite3DbFree(db, zLowerName);
102476 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
102511 pToplevel->db->mallocFailed = 1;
102522 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
102528 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
102529 return (int)aMap[db->vtabOnConflict-1];
102537 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
102541 sqlite3_mutex_enter(db->mutex);
102546 VtabCtx *p = db->pVtabCtx;
102561 if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0);
102562 sqlite3_mutex_leave(db->mutex);
102682 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
102861 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
102863 sqlite3DbFree(db, p);
102869 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
102871 sqlite3DbFree(db, p);
102881 sqlite3 *db = pWC->pParse->db;
102884 sqlite3ExprDelete(db, a->pExpr);
102887 whereOrInfoDelete(db, a->u.pOrInfo);
102889 whereAndInfoDelete(db, a->u.pAndInfo);
102893 sqlite3DbFree(db, pWC->a);
102903 ** the db->mallocFailed flag so that higher-level functions can detect it.
102922 sqlite3 *db = pWC->pParse->db;
102923 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
102926 sqlite3ExprDelete(db, p);
102933 sqlite3DbFree(db, pOld);
102935 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
103245 sqlite3 *db = pParse->db; /* Database connection */
103249 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
103289 pPrefix = sqlite3Expr(db, TK_STRING, z);
103441 sqlite3 *db = pParse->db; /* Database connection */
103459 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
103466 if( db->mallocFailed ) return;
103480 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
103494 testcase( db->mallocFailed );
103495 if( !db->mallocFailed ){
103642 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
103647 db, pLeft, 0);
103661 sqlite3ExprListDelete(db, pList);
103704 sqlite3 *db = pParse->db; /* Database connection */
103706 if( db->mallocFailed ){
103750 pDup = sqlite3ExprDup(db, pExpr, 0);
103751 if( db->mallocFailed ){
103752 sqlite3ExprDelete(db, pDup);
103803 sqlite3ExprDup(db, pExpr->pLeft, 0),
103804 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
103849 pStr2 = sqlite3ExprDup(db, pStr1, 0);
103850 if( !db->mallocFailed ){
103868 pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0);
103870 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
103876 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
103910 0, sqlite3ExprDup(db, pRight, 0), 0);
103948 sqlite3ExprDup(db, pLeft, 0),
104183 sqlite3 *db = pParse->db;
104221 pColl = db->pDfltColl;
104510 if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
104640 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
104760 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
104830 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
104841 pParse->db->mallocFailed = 1;
104927 assert( sqlite3GetVTable(pParse->db, pTab) );
105093 sqlite3 *db = pParse->db;
105098 pColl = db->pDfltColl;
105101 pColl = sqlite3GetCollSeq(db, SQLITE_UTF8, 0, *pIdx->azColl);
105124 db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
105127 assert( db->mallocFailed );
105131 sqlite3DbFree(db, zSample);
105210 return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
105355 pRhs = sqlite3ValueNew(pParse->db);
105899 if( !pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
105942 sqlite3DbFree(pParse->db, p);
106005 assert( pParse->db->mallocFailed );
106075 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
106163 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
106165 pParse->db->mallocFailed = 1;
106248 static char *explainIndexRange(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
106261 txt.db = db;
106298 sqlite3 *db = pParse->db; /* Database handle */
106310 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
106312 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
106314 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
106318 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
106321 char *zWhere = explainIndexRange(db, pLevel, pItem->pTab);
106322 zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg,
106329 sqlite3DbFree(db, zWhere);
106331 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
106334 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
106336 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
106338 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
106340 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
106346 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
106356 zMsg = sqlite3MAppendf(db, zMsg, "%s (~%lld rows)", zMsg, nRow);
106670 zEndAff = sqlite3DbStrDup(pParse->db, zStartAff);
106755 sqlite3DbFree(pParse->db, zStartAff);
106756 sqlite3DbFree(pParse->db, zEndAff);
106876 pOrTab = sqlite3StackAllocRaw(pParse->db,
106925 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
106926 pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr);
106974 sqlite3ExprDelete(pParse->db, pAndExpr);
106980 if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
107069 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
107075 /* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
107079 sqlite3DbFree(db, pInfo);
107084 sqlite3DbFree(db, pIdx->zColAff);
107085 sqlite3DbFree(db, pIdx);
107090 sqlite3DbFree(db, pWInfo);
107203 sqlite3 *db; /* Database connection */
107228 db = pParse->db;
107230 pWInfo = sqlite3DbMallocZero(db,
107235 if( db->mallocFailed ){
107236 sqlite3DbFree(db, pWInfo);
107251 if( db->flags & SQLITE_DistinctOpt ) pDistinct = 0;
107316 if( db->mallocFailed ){
107538 if( pParse->nErr || db->mallocFailed ){
107574 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107580 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
107621 if( db->mallocFailed ) goto whereBeginError;
107693 whereInfoFree(db, pWInfo);
107708 sqlite3 *db = pParse->db;
107729 sqlite3DbFree(db, pLevel->u.in.aInLoop);
107790 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){
107821 whereInfoFree(db, pWInfo);
107946 sqlite3 *db = pParse->db;
107947 if( db->mallocFailed==0 && pY->op==TK_NULL ){
107949 sqlite3ExprDelete(db, pA->pRight);
109224 sqlite3SelectDelete(pParse->db, (yypminor->yy159));
109230 sqlite3ExprDelete(pParse->db, (yypminor->yy342).pExpr);
109245 sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
109253 sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
109264 sqlite3ExprDelete(pParse->db, (yypminor->yy122));
109271 sqlite3IdListDelete(pParse->db, (yypminor->yy180));
109277 sqlite3ExprListDelete(pParse->db, (yypminor->yy487).pList);
109278 sqlite3SelectDelete(pParse->db, (yypminor->yy487).pSelect);
109285 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
109290 sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
109970 pParse->db->lookaside.bEnabled = 0;
110006 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
110203 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
110215 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
110248 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
110264 {yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
110309 {yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
110439 sqlite3SelectDelete(pParse->db, pRight);
110440 sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy487.pSelect);
110452 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
110455 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
110527 if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
110633 sqlite3ExprListDelete(pParse->db, pList);
110652 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy342.pExpr);
110659 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
110675 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
110689 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
110698 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
110705 sqlite3SrcListDelete(pParse->db, pSrc);
110720 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
110733 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
110760 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy442, yymsp[-9].minor.yy392,
110775 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
110899 { yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-5].minor.yy258); }
110902 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-4].minor.yy258);}
110905 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy258);}
110908 {yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy122);}
110911 {yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
110978 pParse->db->lookaside.bEnabled = 0;
111964 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
111965 sqlite3 *db = pParse->db; /* The database connection */
111969 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
111970 if( db->activeVdbeCnt==0 ){
111971 db->u1.isInterrupted = 0;
111979 db->mallocFailed = 1;
111987 enableLookaside = db->lookaside.bEnabled;
111988 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
111989 while( !db->mallocFailed && zSql[i]!=0 ){
112000 if( db->u1.isInterrupted ){
112008 sqlite3DbFree(db, *pzErrMsg);
112009 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
112042 db->lookaside.bEnabled = enableLookaside;
112043 if( db->mallocFailed ){
112047 sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc));
112062 sqlite3DbFree(db, pParse->aTableLock);
112076 sqlite3DeleteTable(db, pParse->pNewTable);
112079 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
112080 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
112081 sqlite3DbFree(db, pParse->azVar);
112082 sqlite3DbFree(db, pParse->aAlias);
112086 sqlite3DbFree(db, p);
112091 sqlite3DeleteTable(db, p);
112426 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
112458 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
112490 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
112949 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
112951 if( db->lookaside.nOut ){
112958 if( db->lookaside.bMalloced ){
112959 sqlite3_free(db->lookaside.pStart);
112978 db->lookaside.pStart = pStart;
112979 db->lookaside.pFree = 0;
112980 db->lookaside.sz = (u16)sz;
112987 p->pNext = db->lookaside.pFree;
112988 db->lookaside.pFree = p;
112991 db->lookaside.pEnd = p;
112992 db->lookaside.bEnabled = 1;
112993 db->lookaside.bMalloced = pBuf==0 ?1:0;
112995 db->lookaside.pEnd = 0;
112996 db->lookaside.bEnabled = 0;
112997 db->lookaside.bMalloced = 0;
113005 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
113006 return db->mutex;
113013 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
113015 sqlite3_mutex_enter(db->mutex);
113016 sqlite3BtreeEnterAll(db);
113017 for(i=0; i<db->nDb; i++){
113018 Btree *pBt = db->aDb[i].pBt;
113024 sqlite3BtreeLeaveAll(db);
113025 sqlite3_mutex_leave(db->mutex);
113032 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
113041 rc = setupLookaside(db, pBuf, sz, cnt);
113058 int oldFlags = db->flags;
113060 db->flags |= aFlagOp[i].mask;
113062 db->flags &= ~aFlagOp[i].mask;
113064 if( oldFlags!=db->flags ){
113065 sqlite3ExpirePreparedStatements(db);
113068 *pRes = (db->flags & aFlagOp[i].mask)!=0;
113144 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
113145 return db->lastRowid;
113151 SQLITE_API int sqlite3_changes(sqlite3 *db){
113152 return db->nChange;
113158 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
113159 return db->nTotalChange;
113167 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
113168 while( db->pSavepoint ){
113169 Savepoint *pTmp = db->pSavepoint;
113170 db->pSavepoint = pTmp->pNext;
113171 sqlite3DbFree(db, pTmp);
113173 db->nSavepoint = 0;
113174 db->nStatement = 0;
113175 db->isTransactionSavepoint = 0;
113184 static void functionDestroy(sqlite3 *db, FuncDef *p){
113190 sqlite3DbFree(db, pDestructor);
113198 SQLITE_API int sqlite3_close(sqlite3 *db){
113202 if( !db ){
113205 if( !sqlite3SafetyCheckSickOrOk(db) ){
113208 sqlite3_mutex_enter(db->mutex);
113211 sqlite3ResetInternalSchema(db, -1);
113215 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
113220 sqlite3VtabRollback(db);
113223 if( db->pVdbe ){
113224 sqlite3Error(db, SQLITE_BUSY,
113226 sqlite3_mutex_leave(db->mutex);
113229 assert( sqlite3SafetyCheckSickOrOk(db) );
113231 for(j=0; j<db->nDb; j++){
113232 Btree *pBt = db->aDb[j].pBt;
113234 sqlite3Error(db, SQLITE_BUSY,
113236 sqlite3_mutex_leave(db->mutex);
113242 sqlite3CloseSavepoints(db);
113244 for(j=0; j<db->nDb; j++){
113245 struct Db *pDb = &db->aDb[j];
113254 sqlite3ResetInternalSchema(db, -1);
113259 sqlite3ConnectionClosed(db);
113261 assert( db->nDb<=2 );
113262 assert( db->aDb==db->aDbStatic );
113263 for(j=0; j<ArraySize(db->aFunc.a); j++){
113265 for(p=db->aFunc.a[j]; p; p=pHash){
113268 functionDestroy(db, p);
113270 sqlite3DbFree(db, p);
113275 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
113283 sqlite3DbFree(db, pColl);
113285 sqlite3HashClear(&db->aCollSeq);
113287 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
113292 sqlite3DbFree(db, pMod);
113294 sqlite3HashClear(&db->aModule);
113297 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
113298 if( db->pErr ){
113299 sqlite3ValueFree(db->pErr);
113301 sqlite3CloseExtensions(db);
113303 db->magic = SQLITE_MAGIC_ERROR;
113311 sqlite3DbFree(db, db->aDb[1].pSchema);
113312 sqlite3_mutex_leave(db->mutex);
113313 db->magic = SQLITE_MAGIC_CLOSED;
113314 sqlite3_mutex_free(db->mutex);
113315 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
113316 if( db->lookaside.bMalloced ){
113317 sqlite3_free(db->lookaside.pStart);
113319 sqlite3_free(db);
113329 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
113332 assert( sqlite3_mutex_held(db->mutex) );
113334 for(i=0; i<db->nDb; i++){
113335 Btree *p = db->aDb[i].pBt;
113341 db->aDb[i].inTrans = 0;
113344 sqlite3VtabRollback(db);
113347 if( db->flags&SQLITE_InternChanges ){
113348 sqlite3ExpirePreparedStatements(db);
113349 sqlite3ResetInternalSchema(db, -1);
113353 db->nDeferredCons = 0;
113356 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
113357 db->xRollbackCallback(db->pRollbackArg);
113428 sqlite3 *db = (sqlite3 *)ptr;
113429 int timeout = db->busyTimeout;
113444 sqlite3OsSleep(db->pVfs, delay*1000);
113447 sqlite3 *db = (sqlite3 *)ptr;
113452 sqlite3OsSleep(db->pVfs, 1000000);
113481 sqlite3 *db,
113485 sqlite3_mutex_enter(db->mutex);
113486 db->busyHandler.xFunc = xBusy;
113487 db->busyHandler.pArg = pArg;
113488 db->busyHandler.nBusy = 0;
113489 sqlite3_mutex_leave(db->mutex);
113500 sqlite3 *db,
113505 sqlite3_mutex_enter(db->mutex);
113507 db->xProgress = xProgress;
113508 db->nProgressOps = nOps;
113509 db->pProgressArg = pArg;
113511 db->xProgress = 0;
113512 db->nProgressOps = 0;
113513 db->pProgressArg = 0;
113515 sqlite3_mutex_leave(db->mutex);
113524 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
113526 db->busyTimeout = ms;
113527 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
113529 sqlite3_busy_handler(db, 0, 0);
113537 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
113538 db->u1.isInterrupted = 1;
113549 sqlite3 *db,
113562 assert( sqlite3_mutex_held(db->mutex) );
113584 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
113587 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
113604 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
113606 if( db->activeVdbeCnt ){
113607 sqlite3Error(db, SQLITE_BUSY,
113609 assert( !db->mallocFailed );
113612 sqlite3ExpirePreparedStatements(db);
113616 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
113617 assert(p || db->mallocFailed);
113624 functionDestroy(db, p);
113643 sqlite3 *db,
113652 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
113657 sqlite3 *db,
113669 sqlite3_mutex_enter(db->mutex);
113671 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
113679 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
113683 sqlite3DbFree(db, pArg);
113687 rc = sqlite3ApiExit(db, rc);
113688 sqlite3_mutex_leave(db->mutex);
113694 sqlite3 *db,
113705 sqlite3_mutex_enter(db->mutex);
113706 assert( !db->mallocFailed );
113707 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
113708 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
113709 sqlite3DbFree(db, zFunc8);
113710 rc = sqlite3ApiExit(db, rc);
113711 sqlite3_mutex_leave(db->mutex);
113730 sqlite3 *db,
113736 sqlite3_mutex_enter(db->mutex);
113737 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
113738 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
113741 rc = sqlite3ApiExit(db, rc);
113742 sqlite3_mutex_leave(db->mutex);
113755 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
113757 sqlite3_mutex_enter(db->mutex);
113758 pOld = db->pTraceArg;
113759 db->xTrace = xTrace;
113760 db->pTraceArg = pArg;
113761 sqlite3_mutex_leave(db->mutex);
113773 sqlite3 *db,
113778 sqlite3_mutex_enter(db->mutex);
113779 pOld = db->pProfileArg;
113780 db->xProfile = xProfile;
113781 db->pProfileArg = pArg;
113782 sqlite3_mutex_leave(db->mutex);
113793 sqlite3 *db, /* Attach the hook to this database */
113798 sqlite3_mutex_enter(db->mutex);
113799 pOld = db->pCommitArg;
113800 db->xCommitCallback = xCallback;
113801 db->pCommitArg = pArg;
113802 sqlite3_mutex_leave(db->mutex);
113811 sqlite3 *db, /* Attach the hook to this database */
113816 sqlite3_mutex_enter(db->mutex);
113817 pRet = db->pUpdateArg;
113818 db->xUpdateCallback = xCallback;
113819 db->pUpdateArg = pArg;
113820 sqlite3_mutex_leave(db->mutex);
113829 sqlite3 *db, /* Attach the hook to this database */
113834 sqlite3_mutex_enter(db->mutex);
113835 pRet = db->pRollbackArg;
113836 db->xRollbackCallback = xCallback;
113837 db->pRollbackArg = pArg;
113838 sqlite3_mutex_leave(db->mutex);
113851 sqlite3 *db, /* Connection */
113857 sqlite3_wal_checkpoint(db, zDb);
113875 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
113877 UNUSED_PARAMETER(db);
113881 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
113883 sqlite3_wal_hook(db, 0, 0);
113894 sqlite3 *db, /* Attach the hook to this db handle */
113900 sqlite3_mutex_enter(db->mutex);
113901 pRet = db->pWalArg;
113902 db->xWalCallback = xCallback;
113903 db->pWalArg = pArg;
113904 sqlite3_mutex_leave(db->mutex);
113915 sqlite3 *db, /* Database handle */
113925 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
113938 sqlite3_mutex_enter(db->mutex);
113940 iDb = sqlite3FindDbName(db, zDb);
113944 sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb);
113946 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
113947 sqlite3Error(db, rc, 0);
113949 rc = sqlite3ApiExit(db, rc);
113950 sqlite3_mutex_leave(db->mutex);
113961 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
113962 return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0);
113975 ** The mutex on database handle db should be held by the caller. The mutex
113985 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
113990 assert( sqlite3_mutex_held(db->mutex) );
113994 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
113996 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
114013 ** The value returned depends on the value of db->temp_store (runtime
114018 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
114029 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
114031 return ( db->temp_store==2 );
114034 return ( db->temp_store!=1 );
114048 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
114050 if( !db ){
114053 if( !sqlite3SafetyCheckSickOrOk(db) ){
114056 sqlite3_mutex_enter(db->mutex);
114057 if( db->mallocFailed ){
114060 z = (char*)sqlite3_value_text(db->pErr);
114061 assert( !db->mallocFailed );
114063 z = sqlite3ErrStr(db->errCode);
114066 sqlite3_mutex_leave(db->mutex);
114075 SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){
114089 if( !db ){
114092 if( !sqlite3SafetyCheckSickOrOk(db) ){
114095 sqlite3_mutex_enter(db->mutex);
114096 if( db->mallocFailed ){
114099 z = sqlite3_value_text16(db->pErr);
114101 sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
114103 z = sqlite3_value_text16(db->pErr);
114106 ** above. If this is the case, then the db->mallocFailed flag needs to
114110 db->mallocFailed = 0;
114112 sqlite3_mutex_leave(db->mutex);
114121 SQLITE_API int sqlite3_errcode(sqlite3 *db){
114122 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
114125 if( !db || db->mallocFailed ){
114128 return db->errCode & db->errMask;
114130 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
114131 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
114134 if( !db || db->mallocFailed ){
114137 return db->errCode;
114141 ** Create a new collating function for database "db". The name is zName
114145 sqlite3* db,
114156 assert( sqlite3_mutex_held(db->mutex) );
114176 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
114178 if( db->activeVdbeCnt ){
114179 sqlite3Error(db, SQLITE_BUSY,
114183 sqlite3ExpirePreparedStatements(db);
114192 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
114206 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
114212 sqlite3Error(db, SQLITE_OK, 0);
114281 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
114308 oldLimit = db->aLimit[limitId];
114313 db->aLimit[limitId] = newLimit;
114559 sqlite3 *db; /* Store allocated handle here */
114628 db = sqlite3MallocZero( sizeof(sqlite3) );
114629 if( db==0 ) goto opendb_out;
114631 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
114632 if( db->mutex==0 ){
114633 sqlite3_free(db);
114634 db = 0;
114638 sqlite3_mutex_enter(db->mutex);
114639 db->errMask = 0xff;
114640 db->nDb = 2;
114641 db->magic = SQLITE_MAGIC_BUSY;
114642 db->aDb = db->aDbStatic;
114644 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
114645 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
114646 db->autoCommit = 1;
114647 db->nextAutovac = -1;
114648 db->nextPagesize = 0;
114649 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
114663 sqlite3HashInit(&db->aCollSeq);
114665 sqlite3HashInit(&db->aModule);
114672 createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
114673 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
114674 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
114675 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
114676 if( db->mallocFailed ){
114679 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
114680 assert( db->pDfltColl!=0 );
114683 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
114686 db->openFlags = flags;
114687 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
114689 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
114690 sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
114696 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
114702 sqlite3Error(db, rc, 0);
114705 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
114706 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
114712 db->aDb[0].zName = "main";
114713 db->aDb[0].safety_level = 3;
114714 db->aDb[1].zName = "temp";
114715 db->aDb[1].safety_level = 1;
114717 db->magic = SQLITE_MAGIC_OPEN;
114718 if( db->mallocFailed ){
114726 sqlite3Error(db, SQLITE_OK, 0);
114727 sqlite3RegisterBuiltinFunctions(db);
114732 rc = sqlite3_errcode(db);
114734 sqlite3AutoLoadExtensions(db);
114735 rc = sqlite3_errcode(db);
114742 if( !db->mallocFailed ){
114744 rc = sqlite3Fts1Init(db);
114749 if( !db->mallocFailed && rc==SQLITE_OK ){
114751 rc = sqlite3Fts2Init(db);
114756 if( !db->mallocFailed && rc==SQLITE_OK ){
114757 rc = sqlite3Fts3Init(db);
114762 if( !db->mallocFailed && rc==SQLITE_OK ){
114763 rc = sqlite3IcuInit(db);
114768 if( !db->mallocFailed && rc==SQLITE_OK){
114769 rc = sqlite3RtreeInit(db);
114773 sqlite3Error(db, rc, 0);
114780 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
114781 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
114786 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
114789 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
114793 if( db ){
114794 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
114795 sqlite3_mutex_leave(db->mutex);
114797 rc = sqlite3_errcode(db);
114798 assert( db!=0 || rc==SQLITE_NOMEM );
114800 sqlite3_close(db);
114801 db = 0;
114803 db->magic = SQLITE_MAGIC_SICK;
114805 *ppDb = db;
114821 sqlite3 **ppDb, /* OUT: SQLite db handle */
114867 ** Register a new collation sequence with the database handle db.
114870 sqlite3* db,
114877 sqlite3_mutex_enter(db->mutex);
114878 assert( !db->mallocFailed );
114879 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
114880 rc = sqlite3ApiExit(db, rc);
114881 sqlite3_mutex_leave(db->mutex);
114886 ** Register a new collation sequence with the database handle db.
114889 sqlite3* db,
114897 sqlite3_mutex_enter(db->mutex);
114898 assert( !db->mallocFailed );
114899 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
114900 rc = sqlite3ApiExit(db, rc);
114901 sqlite3_mutex_leave(db->mutex);
114907 ** Register a new collation sequence with the database handle db.
114910 sqlite3* db,
114918 sqlite3_mutex_enter(db->mutex);
114919 assert( !db->mallocFailed );
114920 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
114922 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
114923 sqlite3DbFree(db, zName8);
114925 rc = sqlite3ApiExit(db, rc);
114926 sqlite3_mutex_leave(db->mutex);
114933 ** db. Replace any previously installed collation sequence factory.
114936 sqlite3 *db,
114940 sqlite3_mutex_enter(db->mutex);
114941 db->xCollNeeded = xCollNeeded;
114942 db->xCollNeeded16 = 0;
114943 db->pCollNeededArg = pCollNeededArg;
114944 sqlite3_mutex_leave(db->mutex);
114951 ** db. Replace any previously installed collation sequence factory.
114954 sqlite3 *db,
114958 sqlite3_mutex_enter(db->mutex);
114959 db->xCollNeeded = 0;
114960 db->xCollNeeded16 = xCollNeeded16;
114961 db->pCollNeededArg = pCollNeededArg;
114962 sqlite3_mutex_leave(db->mutex);
114985 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
114986 return db->autoCommit;
115041 sqlite3 *db, /* Connection handle */
115064 sqlite3_mutex_enter(db->mutex);
115065 sqlite3BtreeEnterAll(db);
115066 rc = sqlite3Init(db, &zErrMsg);
115072 pTab = sqlite3FindTable(db, zTableName, zDbName);
115122 sqlite3BtreeLeaveAll(db);
115135 sqlite3DbFree(db, zErrMsg);
115136 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
115140 sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
115141 sqlite3DbFree(db, zErrMsg);
115142 rc = sqlite3ApiExit(db, rc);
115143 sqlite3_mutex_leave(db->mutex);
115167 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
115168 sqlite3_mutex_enter(db->mutex);
115169 db->errMask = onoff ? 0xffffffff : 0xff;
115170 sqlite3_mutex_leave(db->mutex);
115177 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
115181 sqlite3_mutex_enter(db->mutex);
115182 pBtree = sqlite3DbNameToBtree(db, zDbName);
115201 sqlite3_mutex_leave(db->mutex);
115349 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
115352 ** connection db.
115355 sqlite3 *db = va_arg(ap, sqlite3*);
115357 sqlite3_mutex_enter(db->mutex);
115358 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
115359 sqlite3_mutex_leave(db->mutex);
115363 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
115373 sqlite3 *db = va_arg(ap, sqlite3*);
115375 db->flags = (x & SQLITE_OptMask) | (db->flags & ~SQLITE_OptMask);
115497 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
115499 for(i=0; i<db->nDb; i++){
115500 if( db->aDb[i].pBt
115501 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
115503 return db->aDb[i].pBt;
115513 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
115514 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
115522 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
115523 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
115579 ** 3) If the argument db is not NULL, then none of the entries in the
115581 ** set to db. This is used when closing connection db.
115583 static void checkListProperties(sqlite3 *db){
115596 assert( db==0 || p->pUnlockConnection!=db );
115597 assert( db==0 || p->pBlockingConnection!=db );
115606 ** Remove connection db from the blocked connections list. If connection
115607 ** db is not currently a part of the list, this function is a no-op.
115609 static void removeFromBlockedList(sqlite3 *db){
115613 if( *pp==db ){
115621 ** Add connection db to the blocked connections list. It is assumed
115624 static void addToBlockedList(sqlite3 *db){
115629 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
115632 db->pNextBlocked = *pp;
115633 *pp = db;
115656 ** This is called after connection "db" has attempted some operation
115659 ** cache. pOther is found by looking at db->pBlockingConnection.
115664 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
115671 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
115675 sqlite3 *db,
115681 sqlite3_mutex_enter(db->mutex);
115685 removeFromBlockedList(db);
115686 db->pBlockingConnection = 0;
115687 db->pUnlockConnection = 0;
115688 db->xUnlockNotify = 0;
115689 db->pUnlockArg = 0;
115690 }else if( 0==db->pBlockingConnection ){
115699 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
115703 db->pUnlockConnection = db->pBlockingConnection;
115704 db->xUnlockNotify = xNotify;
115705 db->pUnlockArg = pArg;
115706 removeFromBlockedList(db);
115707 addToBlockedList(db);
115712 assert( !db->mallocFailed );
115713 sqlite3Error(db, rc, (rc?"database is deadlocked":0));
115714 sqlite3_mutex_leave(db->mutex);
115720 ** associated with connection db. The operation will return SQLITE_LOCKED
115724 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
115726 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
115727 addToBlockedList(db);
115729 db->pBlockingConnection = pBlocker;
115735 ** the transaction opened by database db has just finished. Locks held
115736 ** by database connection db have been released.
115742 ** set to db, then set pBlockingConnection=0.
115745 ** set to db, then invoke the configured unlock-notify callback and
115752 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
115768 if( p->pBlockingConnection==db ){
115773 if( p->pUnlockConnection==db ){
115800 ** is returned the transaction on connection db will still be
115851 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
115852 sqlite3ConnectionUnlocked(db);
115854 removeFromBlockedList(db);
115855 checkListProperties(db);
116619 sqlite3 *db; /* The database connection */
116937 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
116938 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
116946 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
117157 sqlite3 *db, /* Database in which to run SQL */
117170 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
117182 sqlite3 *db = p->db; /* Database handle */
117186 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
117188 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
117189 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
117190 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
117191 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
117219 sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
117235 rc = sqlite3_declare_vtab(p->db, zSql);
117256 sqlite3 *db = p->db; /* The database connection */
117274 fts3DbExec(&rc, db,
117282 fts3DbExec(&rc, db,
117286 fts3DbExec(&rc, db,
117299 fts3DbExec(&rc, db,
117305 fts3DbExec(&rc, db,
117330 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
117640 sqlite3 *db, /* Database handle */
117641 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
117655 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
117712 sqlite3 *db, /* The SQLite database connection */
117889 rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
117941 p->db = db;
118036 sqlite3 *db, /* Database connection */
118043 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
118046 sqlite3 *db, /* Database connection */
118053 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
118197 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
119665 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
120038 sqlite3 *db = p->db; /* Database connection */
120051 fts3DbExec(&rc, db,
120058 fts3DbExec(&rc, db,
120064 fts3DbExec(&rc, db,
120069 fts3DbExec(&rc, db,
120073 fts3DbExec(&rc, db,
120182 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
120194 rc = sqlite3Fts3InitTerm(db);
120198 rc = sqlite3Fts3InitAux(db);
120226 rc = sqlite3Fts3ExprInitTestInterface(db);
120236 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
120238 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
120239 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
120240 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
120241 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
120242 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
120246 db, "fts1", &fts3Module, (void *)pHash, 0
120250 db, "fts2", &fts3Module, (void *)pHash, 0
120255 db, "fts3", &fts3Module, (void *)pHash, hashDestroy
120259 db, "fts4", &fts3Module, (void *)pHash, 0
121144 ** the db. In this case the position-list is not populated at all.
121847 sqlite3 *db,
121852 return sqlite3Fts3Init(db);
121914 sqlite3 *db, /* Database connection */
121944 rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
121955 p->pFts3Tab->db = db;
122297 ** Register the fts3aux module with database connection db. Return SQLITE_OK
122300 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db){
122328 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
123173 sqlite3 *db,
123182 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
123276 sqlite3 *db = sqlite3_context_db_handle(context);
123285 rc = queryTestTokenizer(db,
123338 ** with database connection db.
123340 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
123342 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
124704 sqlite3 *db,
124712 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
124726 sqlite3 *db,
124735 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
124778 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
124785 rc = queryTokenizer(db, "simple", &p2);
124788 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
124791 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
124794 rc = registerTokenizer(db, "nosuchtokenizer", p1);
124796 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
124806 ** Set up SQL objects in database db used to access the contents of
124823 sqlite3 *db,
124834 void *pdb = (void *)db;
124843 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
124846 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
124850 rc = sqlite3_create_function(db, zTest, 2, any, p, testFunc, 0, 0);
124853 rc = sqlite3_create_function(db, zTest, 3, any, p, testFunc, 0, 0);
124856 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
125417 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
126013 *piDocid = sqlite3_last_insert_rowid(p->db);
126203 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
127078 ** blocks were written to the db). Otherwise, an SQLite error code is
127290 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
127297 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
128223 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
128474 if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1;
128583 if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
128641 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
128645 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
128648 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
128649 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
130306 sqlite3 *db; /* Host database connection */
130786 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
130876 sqlite3 *db,
130882 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
130889 sqlite3 *db,
130895 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
130950 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
132790 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
132943 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
133011 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
133045 sqlite3 *db,
133072 pRtree->db = db;
133085 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
133105 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
133118 ** using database connection db. If successful, the integer value returned
133122 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
133126 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
133153 sqlite3 *db, /* Database handle */
133162 rc = getIntFromStmt(db, zSql, &iPageSize);
133174 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
133191 sqlite3 *db, /* Database connection */
133217 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
133238 rc = getNodeSize(db, pRtree, isCreate);
133245 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
133246 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
133263 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
133264 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
133347 ** Register the r-tree module with database handle db. This creates the
133351 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
133355 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
133357 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
133361 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
133365 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
133415 sqlite3 *db,
133430 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
133437 sqlite3 *db,
133442 return sqlite3RtreeInit(db);
133864 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
133886 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
133896 ** Register the ICU extension functions with database db.
133898 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
133921 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
133930 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
133939 sqlite3 *db,
133944 return sqlite3IcuInit(db);