Home | History | Annotate | Download | only in dist

Lines Matching defs:Db

2298   sqlite3 *db,          /* An open database */
2362 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2390 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2930 ** <tr><td> file:data.db <td>
2931 ** Open the file "data.db" in the current directory.
2932 ** <tr><td> file:/home/fred/data.db<br>
2933 ** file:///home/fred/data.db <br>
2934 ** file://localhost/home/fred/data.db <br> <td>
2935 ** Open the database file "/home/fred/data.db".
2936 ** <tr><td> file://darkstar/home/fred/data.db <td>
2939 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
2940 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
2944 ** <tr><td> file:data.db?mode=ro&cache=private <td>
2945 ** Open file "data.db" in the current directory for read-only access.
2948 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
2949 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
2951 ** <tr><td> file:data.db?mode=readonly <td>
2978 sqlite3 **ppDb /* OUT: SQLite db handle */
2982 sqlite3 **ppDb /* OUT: SQLite db handle */
2986 sqlite3 **ppDb, /* OUT: SQLite db handle */
3073 SQLITE_API int sqlite3_errcode(sqlite3 *db);
3074 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3217 ** The first argument, "db", is a [database connection] obtained from a
3292 sqlite3 *db, /* Database handle */
3299 sqlite3 *db, /* Database handle */
3306 sqlite3 *db, /* Database handle */
3313 sqlite3 *db, /* Database handle */
4188 sqlite3 *db,
4198 sqlite3 *db,
4208 sqlite3 *db,
4736 sqlite3 *db, /* Database to be rekeyed */
4740 sqlite3 *db, /* Database to be rekeyed */
4754 sqlite3 *db, /* Database to be rekeyed */
4758 sqlite3 *db, /* Database to be rekeyed */
4945 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4954 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5261 sqlite3 *db, /* Connection handle */
5307 sqlite3 *db, /* Load the extension into this database connection */
5326 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5343 ** &nbsp; sqlite3 *db,
5588 sqlite3 *db, /* SQLite connection to register module with */
5594 sqlite3 *db, /* SQLite connection to register module with */
7276 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7298 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7304 ** handle db. The specific operation is determined by the value of the
7310 ** 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,
7535 sqlite3 *db,
7561 sqlite3 *db,
8786 typedef struct Db Db;
8878 sqlite3 *db, /* Associated database connection */
8891 #define BTREE_MEMORY 2 /* This is an in-memory DB */
10319 struct Db {
10359 ** Db.pSchema->flags field.
10367 ** Allowed values for the DB.pSchema->flags field.
10439 Db *aDb; /* All backends */
10463 u8 iDb; /* Which db file is being initialized */
10516 Db aDbStatic[2]; /* Static space for the 2 default backends */
10547 #define ENC(db) ((db)->aDb[0].pSchema->enc)
10608 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
10609 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
10611 #define OptimizationDisabled(db, mask) 0
10612 #define OptimizationEnabled(db, mask) 1
10895 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
10899 sqlite3 *db; /* Database connection associated with this table */
11098 sqlite3 *db; /* The database connection */
11169 int tnum; /* DB Page containing root of this index */
11475 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11908 sqlite3 *db; /* The main database structure */
11997 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
12030 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
12031 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
12152 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
12169 sqlite3 *db; /* The database being initialized */
12898 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
12911 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12966 # define sqlite3VtabInSync(db) 0
12973 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12974 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
12975 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*);
12976 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12977 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12984 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
13113 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
13114 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
13932 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
14022 sqlite3 *db; /* The associated database connection */
14171 sqlite3 *db; /* The database connection that owns this statement */
14183 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
14205 int nChange; /* Number of db changes made since last reset */
14206 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
14431 sqlite3 *db, /* The database connection whose status is desired */
14438 sqlite3_mutex_enter(db->mutex);
14441 *pCurrent = db->lookaside.nOut;
14442 *pHighwater = db->lookaside.mxOut;
14444 db->lookaside.mxOut = db->lookaside.nOut;
14458 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
14460 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
14473 sqlite3BtreeEnterAll(db);
14474 for(i=0; i<db->nDb; i++){
14475 Btree *pBt = db->aDb[i].pBt;
14481 sqlite3BtreeLeaveAll(db);
14496 sqlite3BtreeEnterAll(db);
14497 db->pnBytesFreed = &nByte;
14498 for(i=0; i<db->nDb; i++){
14499 Schema *pSchema = db->aDb[i].pSchema;
14515 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
14518 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
14522 db->pnBytesFreed = 0;
14523 sqlite3BtreeLeaveAll(db);
14539 db->pnBytesFreed = &nByte;
14540 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
14541 sqlite3VdbeClearObject(db, pVdbe);
14542 sqlite3DbFree(db, pVdbe);
14544 db->pnBytesFreed = 0;
14565 for(i=0; i<db->nDb; i++){
14566 if( db->aDb[i].pBt ){
14567 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
14582 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
14590 sqlite3_mutex_leave(db->mutex);
15491 sqlite3 *db;
15495 db = sqlite3_context_db_handle(context);
15531 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
15532 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
15535 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
15539 z = sqlite3DbMallocRaw(db, (int)n);
15675 sqlite3 *db;
20175 ** TRUE if p is a lookaside memory allocation from db
20178 static int isLookaside(sqlite3 *db, void *p){
20179 return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
20194 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20195 assert( db!=0 );
20196 assert( sqlite3_mutex_held(db->mutex) );
20197 if( isLookaside(db, p) ){
20198 return db->lookaside.sz;
20202 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20229 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
20230 assert( db==0 || sqlite3_mutex_held(db->mutex) );
20232 if( db ){
20233 if( db->pnBytesFreed ){
20234 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
20237 if( isLookaside(db, p) ){
20241 memset(p, 0xaa, db->lookaside.sz);
20243 pBuf->pNext = db->lookaside.pFree;
20244 db->lookaside.pFree = pBuf;
20245 db->lookaside.nOut--;
20251 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20334 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
20335 void *p = sqlite3DbMallocRaw(db, n);
20346 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
20353 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
20354 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
20360 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
20362 assert( db==0 || sqlite3_mutex_held(db->mutex) );
20363 assert( db==0 || db->pnBytesFreed==0 );
20365 if( db ){
20367 if( db->mallocFailed ){
20370 if( db->lookaside.bEnabled ){
20371 if( n>db->lookaside.sz ){
20372 db->lookaside.anStat[1]++;
20373 }else if( (pBuf = db->lookaside.pFree)==0 ){
20374 db->lookaside.anStat[2]++;
20376 db->lookaside.pFree = pBuf->pNext;
20377 db->lookaside.nOut++;
20378 db->lookaside.anStat[0]++;
20379 if( db->lookaside.nOut>db->lookaside.mxOut ){
20380 db->lookaside.mxOut = db->lookaside.nOut;
20387 if( db && db->mallocFailed ){
20392 if( !p && db ){
20393 db->mallocFailed = 1;
20396 ((db && db
20404 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
20406 assert( db!=0 );
20407 assert( sqlite3_mutex_held(db->mutex) );
20408 if( db->mallocFailed==0 ){
20410 return sqlite3DbMallocRaw(db, n);
20412 if( isLookaside(db, p) ){
20413 if( n<=db->lookaside.sz ){
20416 pNew = sqlite3DbMallocRaw(db, n);
20418 memcpy(pNew, p, db->lookaside.sz);
20419 sqlite3DbFree(db, p);
20428 db->mallocFailed = 1;
20431 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20441 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
20443 pNew = sqlite3DbRealloc(db, p, n);
20445 sqlite3DbFree(db, p);
20457 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
20465 zNew = sqlite3DbMallocRaw(db, (int)n);
20471 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
20477 zNew = sqlite3DbMallocRaw(db, n+1);
20490 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){
20495 z = sqlite3VMPrintf(db, zFormat, ap);
20497 sqlite3DbFree(db, *pz);
20511 ** If the first argument, db, is not NULL and a malloc() error has occurred,
20515 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
20516 /* If the db handle is not NULL, then we must hold the connection handle
20517 ** mutex here. Otherwise the read (and possible write) of db->mallocFailed
20520 assert( !db || sqlite3_mutex_held(db->mutex) );
20521 if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
20522 sqlite3Error(db, SQLITE_NOMEM, 0);
20523 db->mallocFailed = 0;
20526 return rc & (db ? db->errMask : 0xff);
21283 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
21360 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
21380 sqlite3DbFree(p->db, p->zText);
21393 p->db = 0;
21405 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
21409 assert( db!=0 );
21411 db->aLimit[SQLITE_LIMIT_LENGTH]);
21412 acc.db = db;
21416 db->mallocFailed = 1;
21425 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
21429 z = sqlite3VMPrintf(db, zFormat, ap);
21439 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
21442 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3 *db, char *zStr, const char *zFormat, ...){
21446 z = sqlite3VMPrintf(db, zFormat, ap);
21448 sqlite3DbFree(db, zStr);
21916 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
21980 zOut = sqlite3DbMallocRaw(pMem->db, len);
22142 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
22145 m.db = db;
22148 if( db->mallocFailed ){
22152 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
22153 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
22154 assert( m.z || db->mallocFailed );
22353 ** handle "db". The error code is set to "err_code".
22368 ** To clear the most recent error for sqlite handle "db", sqlite3Error
22372 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
22373 assert( db!=0 );
22374 db->errCode = err_code;
22375 if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
22379 z = sqlite3VMPrintf(db, zFormat, ap);
22381 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
22382 }else if( db->pErr ){
22383 sqlite3ValueSetNull(db->pErr);
22407 sqlite3 *db = pParse->db;
22409 zMsg = sqlite3VMPrintf(db, zFormat, ap);
22411 if( db->suppressErr ){
22412 sqlite3DbFree(db, zMsg);
22415 sqlite3DbFree(db, pParse->zErrMsg);
23346 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
23350 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
23375 ** Check to make sure we have a valid db pointer. This test is not
23377 ** misuse of the interface such as passing in db pointers that are
23379 ** 1 it means that the db pointer is valid and 0 if it should not be
23383 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
23384 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
23388 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
23390 if( db==0 ){
23394 magic = db->magic;
23396 if( sqlite3SafetyCheckSickOrOk(db) ){
23405 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
23407 magic = db->magic;
23508 ** test.db-journal => test.nal
23509 ** test.db-wal => test.wal
23510 ** test.db-shm => test.shm
23511 ** test.db-mj7f3319fa => test.9fa
25617 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
28477 ** is "/home/user1/config.db" then the file that is created and mmapped
28478 ** for shared memory will be called "/home/user1/config.db-shm".
28997 int h = pFd->h; /* File descriptor open on db file */
29537 ** proxyLock activation is possible (remote proxy is based on db name)
29844 ** "<path to db>-journal"
29845 ** "<path to db>-wal"
29846 ** "<path to db>-journalNN"
29847 ** "<path to db>-walNN"
29956 /* The main DB, main journal, WAL file and master journal are never
30559 ** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
30561 ** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
30576 ** For database path "/Users/me/foo.db"
30577 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
30710 /* transform the db path to a unique cache name */
31365 /* afp style keeps a reference to the db path in the filePath field
31377 /* all other styles use the locking context to store the db file path */
36570 /* The main DB, main journal, WAL file and master journal are never
39725 sqlite3 *db; /* The database connection */
39743 ** are available at pSpace. The db pointer is used as a memory context
39753 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
39758 p->db = db;
39778 sqlite3DbFree(p->db, pChunk);
39793 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
39800 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
40253 int sync_flags, /* Flags to sync db file with (or 0) */
40280 ** stored in each frame (i.e. the db page-size when the WAL was created).
40551 ** db size etc.) are consistent with the contents of the file-system.
40987 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
40988 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
42190 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
42652 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
43425 i64 n = 0; /* Size of db file in bytes */
43462 ** function. Because an EXCLUSIVE lock on the db file is required to delete
44887 ROUND8(pVfs->szOsFile) + /* The main db file */
45434 ** possibility by unmapping the db here. */
45547 ** flag was specified by the caller. And so long as the db is not a
46355 int noSync /* True to omit the xSync on the db file */
46376 /* If this is an in-memory db, or no pages have been written to, or this
46435 /* Update the db file change counter via the direct-write method. The
46484 ** last page in the db image moved to the free-list. In this case the
47865 u32 nBackfill; /* Number of WAL frames backfilled into DB */
48172 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
48199 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
49227 ** about the eventual size of the db file to the VFS layer.
49238 /* Iterate through the contents of the WAL, copying data to the db file. */
50414 int sync_flags, /* Flags to sync db file with (or 0) */
50961 sqlite3 *db; /* The database connection holding this btree */
50964 u8 sharable; /* True if we can share pBt with another db */
50965 u8 locked; /* True if db currently has pBt locked */
50968 Btree *pNext; /* List of other sharable Btrees from the same db */
51023 sqlite3 *db; /* Database connection currently using this Btree */
51030 u8 bDoTruncate; /* True to truncate db on commit */
51104 ** particular database connection identified BtCursor.pBtree.db.
51271 u8 *aPgRef; /* 1 bit per page in the db (see above) */
51294 ** set BtShared.db to the database handle associated with p and the
51300 assert( sqlite3_mutex_held(p->db->mutex) );
51303 p->pBt->db = p->db;
51315 assert( sqlite3_mutex_held(p->db->mutex) );
51316 assert( p->db==pBt->db );
51347 assert( p->pNext==0 || p->pNext->db==p->db );
51348 assert( p->pPrev==0 || p->pPrev->db==p->db );
51356 assert( sqlite3_mutex_held(p->db->mutex) );
51358 /* Unless the database is sharable and unlocked, then BtShared.db
51360 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
51371 p->pBt->db = p->db;
51419 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
51421 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
51457 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
51460 assert( sqlite3_mutex_held(db->mutex) );
51461 for(i=0; i<db->nDb; i++){
51462 p = db->aDb[i].pBt;
51466 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
51469 assert( sqlite3_mutex_held(db->mutex) );
51470 for(i=0; i<db->nDb; i++){
51471 p = db->aDb[i].pBt;
51491 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
51493 if( !sqlite3_mutex_held(db->mutex) ){
51496 for(i=0; i<db->nDb; i++){
51498 p = db->aDb[i].pBt;
51511 ** db->aDb[iDb].pSchema structure. The mutexes required for schema
51514 ** (1) The mutex on db
51515 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
51518 ** db using sqlite3SchemaToIndex().
51520 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
51522 assert( db!=0 );
51523 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
51524 assert( iDb>=0 && iDb<db->nDb );
51525 if( !sqlite3_mutex_held(db->mutex) ) return 0;
51527 p = db->aDb[iDb].pBt;
51545 p->pBt->db = p->db;
51547 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
51549 for(i=0; i<db->nDb; i++){
51550 Btree *p = db->aDb[i].pBt;
51552 p->pBt->db = p->db;
51714 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
51785 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
51806 assert( p->db!=0 );
51807 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
51825 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
51842 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
51879 assert( p->db!=0 );
51885 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
52251 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
52259 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
53280 assert( pBt->db );
53281 assert( sqlite3_mutex_held(pBt->db->mutex) );
53282 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
53309 sqlite3 *db, /* Associated database handle */
53331 || (isTempDb && sqlite3TempInMemory(db))
53335 assert( db!=0 );
53337 assert( sqlite3_mutex_held(db->mutex) );
53357 p->db = db;
53400 for(iDb=db->nDb-1; iDb>=0; iDb--){
53401 Btree *pExisting = db->aDb[iDb].pBt;
53450 sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
53457 pBt->db = db;
53508 db->mallocFailed = 0;
53528 for(i=0; i<db->nDb; i++){
53529 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
53655 assert( sqlite3_mutex_held(p->db->mutex) );
53722 assert( sqlite3_mutex_held(p->db->mutex) );
53736 assert( sqlite3_mutex_held(p->db->mutex) );
53758 assert( sqlite3_mutex_held(p->db->mutex) );
53773 assert( sqlite3_mutex_held(p->db->mutex) );
54054 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
54270 pBlock = pBt->pWriter->db;
54275 pBlock = pIter->pBtree->db;
54281 sqlite3ConnectionBlocked(p->db, pBlock);
54309 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
54347 /* If the db-size header field is incorrect (as it may be if an old
54369 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
54859 sqlite3 *db = p->db;
54865 if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){
55075 assert( iStatement>p->db->nSavepoint );
55266 sqlite3DbFree(pBtree->db, pCur->aOverflow);
55584 pCur->pBtree->db, pCur->aOverflow, nOvfl*2*sizeof(Pgno)
55776 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
56045 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
56068 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
56144 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
56196 ** would have already detected db corruption. Similarly, pPage must
59068 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
59859 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
59893 assert( sqlite3_mutex_held(p->db->mutex) );
59899 assert( sqlite3_mutex_held(p->db->mutex) );
59941 assert( sqlite3_mutex_held(p->db->mutex) );
59989 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
60183 pParse->db = pDb;
60438 int nSrcPage = -1; /* Size of source db in pages */
60439 int bCloseTrans = 0; /* True if src db requires unlocking */
60811 b.pSrcDb = pFrom->db;
60919 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
60953 if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
60956 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
60959 sqlite3DbFree(pMem->db, pMem->zMalloc);
60960 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
60994 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61023 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61047 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61078 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61122 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61125 ctx.s.db = pMem->db;
61130 sqlite3DbFree(pMem->db, pMem->zMalloc);
61143 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
61169 sqlite3DbFree(p->db, p->zMalloc);
61219 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61244 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61268 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61295 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61309 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61328 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61412 sqlite3 *db = pMem->db;
61413 assert( db!=0 );
61416 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
61417 if( db->mallocFailed ){
61421 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
61422 sqlite3DbMallocSize(db, pMem->zMalloc));
61433 assert( p->db!=0 );
61439 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
61519 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
61520 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
61521 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
61556 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
61565 if( pMem->db ){
61566 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
61698 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
61722 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
61723 || pVal->db->mallocFailed );
61734 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
61735 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
61738 p->db = db;
61765 static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
61777 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
61782 assert( pRec->pKeyInfo->enc==ENC(db) );
61786 pRec->aMem[i].db = db;
61789 sqlite3DbFree(db, pRec);
61803 return sqlite3ValueNew(db);
61817 sqlite3 *db, /* The database connection */
61850 pVal = valueNew(db, pCtx);
61855 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
61870 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal)
61885 pVal = valueNew(db, pCtx);
61893 pVal = valueNew(db, pCtx);
61898 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
61907 db->mallocFailed = 1;
61908 sqlite3DbFree(db, zVal);
61929 sqlite3 *db, /* The database connection */
61935 return valueFromExpr(db, pExpr, enc, affinity, ppVal, 0);
61957 sqlite3 *db;
61964 db = sqlite3_context_db_handle(context);
61967 aRet = sqlite3DbMallocRaw(db, nRet);
61975 sqlite3DbFree(db, aRet);
62021 sqlite3 *db = pParse->db;
62027 pVal = valueNew(db, pAlloc);
62038 pVal = valueNew(db, pAlloc);
62042 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
62044 pVal->db = pParse->db;
62048 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, pAlloc);
62051 assert( pVal==0 || pVal->db==db );
62105 assert( pVal==0 || pVal->db==pParse->db );
62138 sqlite3 *db, /* Database handle */
62169 pMem = *ppVal = sqlite3ValueNew(db);
62173 pMem->enc = ENC(db);
62187 sqlite3 *db = aMem[0].db;
62189 sqlite3DbFree(db, aMem[i].zMalloc);
62192 sqlite3DbFree(db, pRec);
62216 sqlite3DbFree(((Mem*)v)->db, v);
62258 sqlite3 *db = pParse->db;
62260 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
62262 p->db = db;
62263 if( db->pVdbe ){
62264 db->pVdbe->pPrev = p;
62266 p->pNext = db->pVdbe;
62268 db->pVdbe = p;
62287 p->zSql = sqlite3DbStrNDup(p->db, z, n);
62350 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
62352 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
62410 if( p->db->flags & SQLITE_VdbeAddopTrace ){
62473 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
62511 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
62558 ** sqlite3DbFree(v->db, sIter.apSub);
62600 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
62653 sqlite3DbFree(v->db, sIter.apSub);
62660 return ( v->db->mallocFailed || hasAbort==mayAbort );
62749 sqlite3DbFree(p->db, pParse->aLabel);
62777 assert( aOp && !p->db->mallocFailed );
62826 if( p->db->flags & SQLITE_VdbeAddopTrace ){
62896 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
62898 sqlite3DbFree(db, pDef);
62907 static void freeP4(sqlite3 *db, int p4type, void *p4){
62909 assert( db );
62915 sqlite3DbFree(db, p4);
62919 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
62923 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
62927 freeEphemeralFunction(db, (FuncDef*)p4);
62931 if( db->pnBytesFreed==0 ){
62935 sqlite3DbFree(db, p->zMalloc);
62936 sqlite3DbFree(db, p);
62941 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
62953 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
62957 freeP4(db, pOp->p4type, pOp->p4.p);
62959 sqlite3DbFree(db, pOp->zComment);
62963 sqlite3DbFree(db, aOp);
62982 sqlite3 *db = p->db;
62983 freeP4(db, pOp->p4type, pOp->p4.p);
63021 sqlite3 *db;
63023 db = p->db;
63025 if( p->aOp==0 || db->mallocFailed ){
63027 freeP4(db, n, (void*)*(char**)&zP4);
63040 freeP4(db, pOp->p4type, pOp->p4.p);
63057 assert( ((VTable *)zP4)->db==p->db );
63063 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
63089 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
63092 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
63093 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
63145 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
63146 if( p->db->mallocFailed ){
63355 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
63363 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
63366 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
63376 ** sets the BtShared.db member of each of the BtShared structures, ensuring
63380 ** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
63395 sqlite3 *db;
63396 Db *aDb;
63399 db = p->db;
63400 aDb = db->aDb;
63401 nDb = db->nDb;
63416 sqlite3 *db;
63417 Db *aDb;
63420 db = p->db;
63421 aDb = db->aDb;
63422 nDb = db->nDb;
63464 sqlite3 *db = p->db;
63465 u8 malloc_failed = db->mallocFailed;
63466 if( db->pnBytesFreed ){
63468 sqlite3DbFree(db, p->zMalloc);
63473 assert( (&p[1])==pEnd || p[0].db==p[1].db );
63495 sqlite3DbFree(db, p->zMalloc);
63501 db->mallocFailed = malloc_failed;
63517 sqlite3DbFree(p->v->db, p);
63543 sqlite3 *db = p->db; /* The database connection */
63562 db->mallocFailed = 1;
63598 }else if( db->u1.isInterrupted ){
63601 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
63664 assert( p->db->mallocFailed );
63680 assert( p->db->mallocFailed );
63691 assert( p->db->mallocFailed );
63820 assert( p->aMem[i].db==p->db );
63862 sqlite3 *db; /* The database connection */
63878 db = p->db;
63879 assert( db->mallocFailed==0 );
63934 p->pFree = sqlite3DbMallocZero(db, nByte);
63938 }while( nByte && !db->mallocFailed );
63946 p->aVar[n].db = db;
63959 p->aMem[n].db = db;
63974 sqlite3VdbeSorterClose(p->db, pCx);
64008 v->db->lastRowid = pFrame->lastRowid;
64062 sqlite3 *db = p->db;
64074 sqlite3DbFree(db, p->zErrMsg);
64088 sqlite3 *db = p->db;
64091 sqlite3DbFree(db, p->aColName);
64094 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
64098 pColName->db = p->db;
64124 if( p->db->mallocFailed ){
64137 ** db. If a transaction is active, commit it. If there is a
64141 static int vdbeCommit(sqlite3 *db, Vdbe *p){
64160 rc = sqlite3VtabSync(db, p);
64168 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
64169 Btree *pBt = db->aDb[i].pBt;
64183 if( needXcommit && db->xCommitCallback ){
64184 rc = db->xCommitCallback(db->pCommitArg);
64199 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
64202 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
64203 Btree *pBt = db->aDb[i].pBt;
64214 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
64215 Btree *pBt = db->aDb[i].pBt;
64221 sqlite3VtabCommit(db);
64231 sqlite3_vfs *pVfs = db->pVfs;
64234 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
64243 zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
64274 sqlite3DbFree(db, zMaster);
64284 for(i=0; i<db->nDb; i++){
64285 Btree *pBt = db->aDb[i].pBt;
64300 sqlite3DbFree(db, zMaster);
64315 sqlite3DbFree(db, zMaster);
64319 /* Sync all the db files involved in the transaction. The same call
64329 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
64330 Btree *pBt = db->aDb[i].pBt;
64338 sqlite3DbFree(db, zMaster);
64347 sqlite3DbFree(db, zMaster);
64362 for(i=0; i<db->nDb; i++){
64363 Btree *pBt = db->aDb[i].pBt;
64371 sqlite3VtabCommit(db);
64388 static void checkActiveVdbeCnt(sqlite3 *db){
64393 p = db->pVdbe;
64402 assert( cnt==db->nVdbeActive );
64403 assert( nWrite==db->nVdbeWrite );
64404 assert( nRead==db->nVdbeRead );
64421 sqlite3 *const db = p->db;
64427 ** In this case (db->nStatement==0), and there is nothing to do.
64429 if( db->nStatement && p->iStatement ){
64434 assert( db->nStatement>0 );
64435 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
64437 for(i=0; i<db->nDb; i++){
64439 Btree *pBt = db->aDb[i].pBt;
64452 db->nStatement--;
64457 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
64460 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
64468 db->nDeferredCons = p->nStmtDefCons;
64469 db->nDeferredImmCons = p->nStmtDefImmCons;
64487 sqlite3 *db = p->db;
64488 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
64493 sqlite3SetString(&p->zErrMsg, db, "FOREIGN KEY constraint failed");
64515 sqlite3 *db = p->db;
64533 if( p->db->mallocFailed ){
64541 checkActiveVdbeCnt(db);
64577 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
64578 sqlite3CloseSavepoints(db);
64579 db->autoCommit = 1;
64595 if( !sqlite3VtabInSync(db)
64596 && db->autoCommit
64597 && db->nVdbeWrite==(p->readOnly==0)
64612 rc = vdbeCommit(db, p);
64619 sqlite3RollbackAll(db, SQLITE_OK);
64621 db->nDeferredCons = 0;
64622 db->nDeferredImmCons = 0;
64623 db->flags &= ~SQLITE_DeferFKs;
64624 sqlite3CommitInternalChanges(db);
64627 sqlite3RollbackAll(db, SQLITE_OK);
64629 db->nStatement = 0;
64636 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
64637 sqlite3CloseSavepoints(db);
64638 db->autoCommit = 1;
64653 sqlite3DbFree(db, p->zErrMsg);
64656 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
64657 sqlite3CloseSavepoints(db);
64658 db->autoCommit = 1;
64667 sqlite3VdbeSetChanges(db, p->nChange);
64669 sqlite3VdbeSetChanges(db, 0);
64680 db->nVdbeActive--;
64681 if( !p->readOnly ) db->nVdbeWrite--;
64682 if( p->bIsReader ) db->nVdbeRead--;
64683 assert( db->nVdbeActive>=db->nVdbeRead );
64684 assert( db->nVdbeRead>=db->nVdbeWrite );
64685 assert( db->nVdbeWrite>=0 );
64688 checkActiveVdbeCnt(db);
64689 if( p->db->mallocFailed ){
64694 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
64697 if( db->autoCommit ){
64698 sqlite3ConnectionUnlocked(db);
64701 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
64723 sqlite3 *db = p->db;
64726 u8 mallocFailed = db->mallocFailed;
64728 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
64729 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
64731 db->mallocFailed = mallocFailed;
64732 db->errCode = rc;
64734 sqlite3Error(db, rc, 0);
64747 assert( v->db->init.busy==0 );
64750 sqlite3GlobalConfig.pSqllogArg, v->db, zExpanded, 1
64752 sqlite3DbFree(v->db, zExpanded);
64772 sqlite3 *db;
64773 db = p->db;
64789 sqlite3DbFree(db, p->zErrMsg);
64797 sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
64798 sqlite3DbFree(db, p->zErrMsg);
64844 return p->rc & db->errMask;
64855 assert( (rc & p->db->errMask)==rc );
64889 sqlite3DbFree(pVdbe->db, pAux);
64904 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
64907 assert( p->db==0 || p->db==db );
64912 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
64913 sqlite3DbFree(db, pSub);
64915 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
64916 vdbeFreeOpArray(db, p->aOp, p->nOp);
64917 sqlite3DbFree(db, p->aColName);
64918 sqlite3DbFree(db, p->zSql);
64919 sqlite3DbFree(db, p->pFree);
64921 sqlite3DbFree(db, p->zExplain);
64922 sqlite3DbFree(db, p->pExplain);
64930 sqlite3 *db;
64933 db = p->db;
64934 assert( sqlite3_mutex_held(db->mutex) );
64935 sqlite3VdbeClearObject(db, p);
64939 db->pVdbe==p );
64940 db->pVdbe = p->pNext;
64946 p->db = 0;
64947 sqlite3DbFree(db, p);
65068 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
65326 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
65369 pMem->db = pKeyInfo->db;
65404 mem1.db = pKeyInfo->db;
65772 mem1.db = pKeyInfo->db;
65818 || pKeyInfo->db->mallocFailed
65840 || pKeyInfo->db->mallocFailed
66006 || pPKey2->pKeyInfo->db->mallocFailed
66062 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
66070 UNUSED_PARAMETER(db);
66173 ** sqlite3_changes() on the database handle 'db'.
66175 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
66176 assert( sqlite3_mutex_held(db->mutex) );
66177 db->nChange = nChange;
66178 db->nTotalChange += nChange;
66199 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
66201 for(p = db->pVdbe; p; p=p->pNext){
66210 return v->db;
66226 sqlite3_value *pRet = sqlite3ValueNew(v->db);
66258 sqlite3 *db = p->db;
66259 sqlite3DbFree(db, p->zErrMsg);
66260 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
66305 if( p->db==0 ){
66338 sqlite3 *db = v->db;
66340 sqlite3_mutex_enter(db->mutex);
66342 rc = sqlite3ApiExit(db, rc);
66343 sqlite3LeaveMutexAndCloseZombie(db);
66362 sqlite3_mutex_enter(v->db->mutex);
66365 assert( (rc & (v->db->errMask))==rc );
66366 rc = sqlite3ApiExit(v->db, rc);
66367 sqlite3_mutex_leave(v->db->mutex);
66380 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
66502 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66506 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66510 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66517 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66524 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66528 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66532 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66541 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66551 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66560 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66569 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66574 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66578 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66592 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66601 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66605 pCtx->s.db->mallocFailed = 1;
66612 static int doWalCallbacks(sqlite3 *db){
66616 for(i=0; i<db->nDb; i++){
66617 Btree *pBt = db->aDb[i].pBt;
66620 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
66621 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
66639 sqlite3 *db;
66672 db = p->db;
66673 if( db->mallocFailed ){
66688 if( db->nVdbeActive==0 ){
66689 db->u1.isInterrupted = 0;
66692 assert( db->nVdbeWrite>0 || db->autoCommit==0
66693 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
66697 if( db->xProfile && !db->init.busy ){
66698 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
66702 db->nVdbeActive++;
66703 if( p->readOnly==0 ) db->nVdbeWrite++;
66704 if( p->bIsReader ) db->nVdbeRead++;
66713 db->nVdbeExec++;
66715 db->nVdbeExec--;
66721 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
66723 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
66724 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
66730 p->rc = doWalCallbacks(db);
66736 db->errCode = rc;
66737 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
66759 return (rc&db->errMask);
66772 sqlite3 *db; /* The database connection */
66777 db = v->db;
66778 sqlite3_mutex_enter(db->mutex);
66796 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
66797 assert( zErr!=0 || db->mallocFailed );
66798 sqlite3DbFree(db, v->zErrMsg);
66799 if( !db->mallocFailed ){
66800 v->zErrMsg = sqlite3DbStrDup(db, zErr);
66807 rc = sqlite3ApiExit(db, rc);
66808 sqlite3_mutex_leave(db->mutex);
66834 return p->s.db;
66844 rc = sqlite3OsCurrentTimeInt64(p->s.db->pVfs, &v->iCurrentTime);
66880 assert( sqlite3_mutex_held(p->s.db->mutex) );
66907 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66929 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
66936 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
67031 sqlite3_mutex_enter(pVm->db->mutex);
67034 if( pVm && ALWAYS(pVm->db) ){
67035 sqlite3_mutex_enter(pVm->db->mutex);
67036 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
67070 p->rc = sqlite3ApiExit(p->db, p->rc);
67071 sqlite3_mutex_leave(p->db->mutex);
67166 sqlite3 *db = p->db;
67168 assert( db!=0 );
67172 sqlite3_mutex_enter(db->mutex);
67173 assert( db->mallocFailed==0 );
67178 if( db->mallocFailed ){
67179 db->mallocFailed = 0;
67182 sqlite3_mutex_leave(db->mutex);
67291 ** The error code stored in database p->db is overwritten with the return
67299 sqlite3_mutex_enter(p->db->mutex);
67301 sqlite3Error(p->db, SQLITE_MISUSE, 0);
67302 sqlite3_mutex_leave(p->db->mutex);
67308 sqlite3Error(p->db, SQLITE_RANGE, 0);
67309 sqlite3_mutex_leave(p->db->mutex);
67316 sqlite3Error(p->db, SQLITE_OK, 0);
67356 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
67358 sqlite3Error(p->db, rc, 0);
67359 rc = sqlite3ApiExit(p->db, rc);
67361 sqlite3_mutex_leave(p->db->mutex);
67387 sqlite3_mutex_leave(p->db->mutex);
67400 sqlite3_mutex_leave(p->db->mutex);
67409 sqlite3_mutex_leave(p->db->mutex);
67470 sqlite3_mutex_leave(p->db->mutex);
67529 assert( pTo->db==pFrom->db );
67531 sqlite3_mutex_enter(pTo->db->mutex);
67535 sqlite3_mutex_leave(pTo->db->mutex);
67575 return pStmt ? ((Vdbe*)pStmt)->db : 0;
67697 sqlite3 *db; /* The database connection */
67707 db = p->db;
67709 db->aLimit[SQLITE_LIMIT_LENGTH]);
67710 out.db = db;
67711 if( db->nVdbeExec>1 ){
67755 u8 enc = ENC(db);
67759 utf8.db = db;
68380 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
68494 ** assert( checkSavepointCount(db) );
68496 static int checkSavepointCount(sqlite3 *db){
68499 for(p=db->pSavepoint; p; p=p->pNext) n++;
68500 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
68517 sqlite3 *db = p->db; /* The database */
68519 u8 encoding = ENC(db); /* The database encoding */
68531 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
68550 db->busyHandler.nBusy = 0;
68551 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
68554 if( db->xProgress ){
68555 assert( 0 < db->nProgressOps );
68558 nProgressLimit = db->nProgressOps;
68560 nProgressLimit %= (unsigned)db->nProgressOps;
68567 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
68572 if( p->db->flags & SQLITE_VdbeListing ){
68578 if( p->db->flags & SQLITE_VdbeEQP ){
68587 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
68593 if( db->mallocFailed ) goto no_mem;
68603 if( db->flags & SQLITE_VdbeTrace ){
68616 sqlite3_interrupt(db);
68734 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
68742 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
68743 assert( db->nProgressOps!=0 );
68744 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
68745 if( db->xProgress(db->pProgressArg) ){
68907 sqlite3VdbeSetChanges(db, p->nChange);
68909 lastRowid = db->lastRowid;
68941 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
68944 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
68946 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
68956 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
69022 sqlite3DbFree(db, pOp->p4.z);
69029 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69247 if( db->xProgress!=0
69249 && db->xProgress(db->pProgressArg)!=0
69260 assert( db->flags&SQLITE_CountRows );
69280 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
69302 if( db->mallocFailed ) goto no_mem;
69339 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69572 db->lastRowid = lastRowid;
69574 lastRowid = db->lastRowid;
69576 if( db->mallocFailed ){
69589 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
69777 assert( pIn1->flags & MEM_Str || db->mallocFailed );
69797 assert( pIn1->flags & MEM_Str || db->mallocFailed );
69998 if( db->mallocFailed ) goto no_mem;
70408 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70719 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70802 assert( db->pSavepoint==0 || db->autoCommit==0 );
70804 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
70805 assert( checkSavepointCount(db) );
70809 if( db->nVdbeWrite>0 ){
70813 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
70823 ** that the db->aVTrans[] array is empty. */
70824 assert( db->autoCommit==0 || db->nVTrans==0 );
70825 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
70826 db->nStatement+db->nSavepoint);
70831 pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
70838 if( db->autoCommit ){
70839 db->autoCommit = 0;
70840 db->isTransactionSavepoint = 1;
70842 db->nSavepoint++;
70846 pNew->pNext = db->pSavepoint;
70847 db->pSavepoint = pNew;
70848 pNew->nDeferredCons = db->nDeferredCons;
70849 pNew->nDeferredImmCons = db->nDeferredImmCons;
70858 pSavepoint = db->pSavepoint;
70865 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
70867 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
70871 sqlite3SetString(&p->zErrMsg, db,
70881 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
70886 db->autoCommit = 1;
70889 db->autoCommit = 0;
70893 db->isTransactionSavepoint = 0;
70896 iSavepoint = db->nSavepoint - iSavepoint - 1;
70898 for(ii=0; ii<db->nDb; ii++){
70899 sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
70902 for(ii=0; ii<db->nDb; ii++){
70903 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
70908 if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
70909 sqlite3ExpirePreparedStatements(db);
70910 sqlite3ResetAllSchemasOfConnection(db);
70911 db->flags = (db->flags | SQLITE_InternChanges);
70917 while( db->pSavepoint!=pSavepoint ){
70918 pTmp = db->pSavepoint;
70919 db->pSavepoint = pTmp->pNext;
70920 sqlite3DbFree(db, pTmp);
70921 db->nSavepoint--;
70929 assert( pSavepoint==db->pSavepoint );
70930 db->pSavepoint = pSavepoint->pNext;
70931 sqlite3DbFree(db, pSavepoint);
70933 db->nSavepoint--;
70936 db->nDeferredCons = pSavepoint->nDeferredCons;
70937 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
70941 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
70966 turnOnAC = desiredAutoCommit && !db->autoCommit;
70969 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
70973 if( turnOnAC && iRollback && db->nVdbeActive>1 ){
70978 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
70983 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
70987 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
70990 }else if( desiredAutoCommit!=db->autoCommit ){
70993 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
70994 db->autoCommit = 1;
70998 db->autoCommit = (u8)desiredAutoCommit;
71001 db
71006 assert( db->nStatement==0 );
71007 sqlite3CloseSavepoints(db);
71015 sqlite3SetString(&p->zErrMsg, db,
71066 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71068 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
71072 pBt = db->aDb[pOp->p1].pBt;
71086 && (db->autoCommit==0 || db->nVdbeRead>1)
71090 assert( db->nStatement>=0 && db->nSavepoint>=0 );
71091 db->nStatement++;
71092 p->iStatement = db->nSavepoint + db->nStatement;
71095 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
71103 p->nStmtDefCons = db->nDeferredCons;
71104 p->nStmtDefImmCons = db->nDeferredImmCons;
71109 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
71115 sqlite3DbFree(db, p->zErrMsg);
71116 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
71130 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
71131 sqlite3ResetOneSchema(db, pOp->p1);
71160 assert( iDb>=0 && iDb<db->nDb );
71161 assert( db->aDb[iDb].pBt!=0 );
71164 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
71180 Db *pDb;
71182 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71185 pDb = &db->aDb[pOp->p1];
71187 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
71195 db->flags |= SQLITE_InternChanges;
71203 sqlite3ExpirePreparedStatements(db);
71296 Db *pDb;
71313 assert( iDb>=0 && iDb<db->nDb );
71315 pDb = &db->aDb[iDb];
71320 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
71346 assert( pKeyInfo->enc==ENC(db) );
71347 assert( pKeyInfo->db==db );
71420 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
71437 assert( pKeyInfo->db==db );
71438 assert( pKeyInfo->enc==ENC(db) );
71466 assert( pCx->pKeyInfo->db==db );
71467 assert( pCx->pKeyInfo->enc==ENC(db) );
71468 rc = sqlite3VdbeSorterInit(db, pCx);
71877 sqlite3DbFree(db, pFree);
72191 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
72213 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
72214 zDb = db->aDb[pC->iDb].zName;
72218 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
72269 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
72270 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
72271 db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
72285 sqlite3VdbeSetChanges(db, p->nChange);
72397 if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
72404 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
72579 rc = sqlite3VdbeSorterRewind(db, pC, &res);
72667 rc = sqlite3VdbeSorterNext(db, pC, &res);
72757 rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
72834 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
72963 for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
72971 iCnt = db->nVdbeRead;
72982 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
72987 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
73022 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
73050 sqlite3VdbeSorterReset(db, pC->pSorter);
73086 Db *pDb;
73089 assert( pOp->p1>=0 && pOp->p1<db->nDb );
73092 pDb = &db->aDb[pOp->p1];
73124 for(iDb=0; iDb<db->nDb; iDb++){
73125 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
73130 assert( iDb>=0 && iDb<db->nDb );
73131 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
73134 initData.db = db;
73137 zSql = sqlite3MPrintf(db,
73139 db->aDb[iDb].zName, zMaster, pOp->p4.z);
73143 assert( db->init.busy==0 );
73144 db->init.busy = 1;
73146 assert( !db->mallocFailed );
73147 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
73149 sqlite3DbFree(db, zSql);
73150 db->init.busy = 0;
73153 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
73168 assert( pOp->p1>=0 && pOp->p1<db->nDb );
73169 rc = sqlite3AnalysisLoad(db, pOp->p1);
73183 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
73196 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
73209 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
73246 aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
73257 assert( pOp->p5<db->nDb );
73259 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
73261 sqlite3DbFree(db, aRoot);
73429 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
73431 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
73450 pFrame = sqlite3DbMallocZero(db, nByte);
73475 pMem->db = db;
73537 if( db->flags & SQLITE_DeferFKs ){
73538 db->nDeferredImmCons += pOp->p2;
73540 db->nDeferredCons += pOp->p2;
73561 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
73562 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
73564 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
73565 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
73691 ctx.s.db = db;
73703 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
73737 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
73771 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
73813 assert( pOp->p1>=0 && pOp->p1<db->nDb );
73816 pBt = db->aDb[pOp->p1].pBt;
73838 if( !db->autoCommit || db->nVdbeRead>1 ){
73840 sqlite3SetString(&p->zErrMsg, db,
73898 rc = sqlite3RunVacuum(&p->zErrMsg, db);
73913 assert( pOp->p1>=0 && pOp->p1<db->nDb );
73916 pBt = db->aDb[pOp->p1].pBt;
73939 sqlite3ExpirePreparedStatements(db);
73964 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
73966 assert( p1>=0 && p1<db->nDb );
73969 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
73972 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
73992 rc = sqlite3VtabBegin(db, pVTab);
74005 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
74018 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
74054 db->mallocFailed = 1;
74316 u8 vtabOnConflict = db->vtabOnConflict;
74325 db->vtabOnConflict = pOp->p5;
74327 db->vtabOnConflict = vtabOnConflict;
74331 db->lastRowid = lastRowid = rowid;
74353 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
74372 pBt = db->aDb[pOp->p1].pBt;
74404 if( db->xTrace
74409 db->xTrace(db->pTraceArg, z);
74410 sqlite3DbFree(db, z);
74416 for(i=0; i<db->nDb; i++){
74418 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
74423 if( (db->flags & SQLITE_SqlTrace)!=0
74475 if( db->flags & SQLITE_VdbeTrace ){
74498 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
74501 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
74508 db->lastRowid = lastRowid;
74518 sqlite3SetString(&p->zErrMsg, db, "string or blob too big");
74525 db->mallocFailed = 1;
74526 sqlite3SetString(&p->zErrMsg, db, "out of memory");
74535 if( db->mallocFailed ) rc = SQLITE_NOMEM;
74537 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
74545 assert( db->u1.isInterrupted );
74548 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
74584 sqlite3 *db; /* The associated database */
74622 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
74642 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
74645 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
74660 sqlite3* db, /* The database connection */
74672 ** db/table/row entry. The reason for using a vdbe program instead
74711 sqlite3_mutex_enter(db->mutex);
74713 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
74715 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
74720 pParse->db = db;
74721 sqlite3DbFree(db, zErr);
74724 sqlite3BtreeEnterAll(db);
74742 sqlite3DbFree(db, zErr);
74747 sqlite3BtreeLeaveAll(db);
74758 sqlite3DbFree(db, zErr);
74759 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
74761 sqlite3BtreeLeaveAll(db);
74773 if( db->flags&SQLITE_ForeignKeys ){
74798 sqlite3DbFree(db, zErr);
74799 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
74801 sqlite3BtreeLeaveAll(db);
74807 assert( pBlob->pStmt || db->mallocFailed );
74810 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
74847 if( !db->mallocFailed ){
74857 pBlob->db = db;
74858 sqlite3BtreeLeaveAll(db);
74859 if( db->mallocFailed ){
74867 if( rc==SQLITE_OK && db->mallocFailed==0 ){
74871 sqlite3DbFree(db, pBlob);
74873 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
74874 sqlite3DbFree(db, zErr);
74876 sqlite3StackFree(db, pParse);
74877 rc = sqlite3ApiExit(db, rc);
74878 sqlite3_mutex_leave(db->mutex);
74889 sqlite3 *db;
74892 db = p->db;
74893 sqlite3_mutex_enter(db->mutex);
74895 sqlite3DbFree(db, p);
74896 sqlite3_mutex_leave(db->mutex);
74916 sqlite3 *db;
74919 db = p->db;
74920 sqlite3_mutex_enter(db->mutex);
74926 sqlite3Error(db, SQLITE_ERROR, 0);
74936 assert( db == v->db );
74944 db->errCode = rc;
74948 rc = sqlite3ApiExit(db, rc);
74949 sqlite3_mutex_leave(db->mutex);
74991 sqlite3 *db;
74994 db = p->db;
74995 sqlite3_mutex_enter(db->mutex);
75006 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
75007 sqlite3DbFree(db, zErr);
75012 rc = sqlite3ApiExit(db, rc);
75014 sqlite3_mutex_leave(db->mutex);
75182 static void vdbeSorterIterZero(sqlite3 *db, VdbeSorterIter *pIter){
75183 sqlite3DbFree(db, pIter->aAlloc);
75184 sqlite3DbFree(db, pIter->aBuffer);
75198 sqlite3 *db, /* Database handle (for malloc) */
75246 p->aAlloc = sqlite3DbReallocOrFree(db, p->aAlloc, nNew);
75266 rc = vdbeSorterIterRead(db, p, nCopy, &aNext);
75283 static int vdbeSorterIterVarint(sqlite3 *db, VdbeSorterIter *p, u64 *pnOut){
75293 rc = vdbeSorterIterRead(db, p, 1, &a);
75309 sqlite3 *db, /* Database handle (for sqlite3DbMalloc() ) */
75317 vdbeSorterIterZero(db, pIter);
75321 rc = vdbeSorterIterVarint(db, pIter, &nRec);
75324 rc = vdbeSorterIterRead(db, pIter, (int)nRec, &pIter->aKey);
75337 sqlite3 *db, /* Database handle */
75346 nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
75354 pIter->aAlloc = (u8 *)sqlite3DbMallocRaw(db, pIter->nAlloc);
75356 pIter->aBuffer = (u8 *)sqlite3DbMallocRaw(db, nBuf);
75377 rc = vdbeSorterIterVarint(db, pIter, &nByte);
75384 rc = vdbeSorterIterNext(db, pIter);
75485 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *db, VdbeCursor *pCsr){
75492 pCsr->pSorter = pSorter = sqlite3DbMallocZero(db, sizeof(VdbeSorter));
75501 if( !sqlite3TempInMemory(db) ){
75502 pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
75504 mxCache = db->aDb[0].pSchema->cache_size;
75515 static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord){
75520 sqlite3DbFree(db, p);
75527 SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *db, VdbeSorter *pSorter){
75531 vdbeSorterIterZero(db, &pSorter->aIter[i]);
75533 sqlite3DbFree(db, pSorter->aIter);
75540 vdbeSorterRecordFree(db, pSorter->pRecord);
75554 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){
75557 sqlite3VdbeSorterReset(db, pSorter);
75558 sqlite3DbFree(db, pSorter->pUnpacked);
75559 sqlite3DbFree(db, pSorter);
75569 static int vdbeSorterOpenTempFile(sqlite3 *db, sqlite3_file **ppFile){
75571 return sqlite3OsOpenMalloc(db->pVfs, 0, ppFile,
75654 sqlite3 *db, /* Database (for malloc) */
75659 int nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
75662 p->aBuffer = (u8 *)sqlite3DbMallocRaw(db, nBuf);
75710 static int fileWriterFinish(sqlite3 *db, FileWriter *p, i64 *piEof){
75719 sqlite3DbFree(db, p->aBuffer);
75749 static int vdbeSorterListToPMA(sqlite3 *db, const VdbeCursor *pCsr){
75765 rc = vdbeSorterOpenTempFile(db, &pSorter->pTemp1);
75775 fileWriterInit(db, pSorter->pTemp1, &writer, pSorter->iWriteOff);
75782 sqlite3DbFree(db, p);
75785 rc = fileWriterFinish(db, &writer, &pSorter->iWriteOff);
75795 sqlite3 *db, /* Database handle */
75806 pNew = (SorterRecord *)sqlite3DbMallocRaw(db, pVal->n + sizeof(SorterRecord));
75835 rc = vdbeSorterListToPMA(db, pCsr);
75847 sqlite3 *db, /* Database handle */
75859 rc = vdbeSorterIterInit(db, pSorter, pSorter->iReadOff, pIter, &nByte);
75878 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *db, const VdbeCursor *pCsr, int *pbEof){
75899 rc = vdbeSorterListToPMA(db, pCsr);
75908 pSorter->aIter = (VdbeSorterIter *)sqlite3DbMallocZero(db, nByte);
75935 rc = vdbeSorterInitMerge(db, pCsr, &nWrite);
75944 rc = vdbeSorterOpenTempFile(db, &pTemp2);
75949 fileWriterInit(db, pTemp2, &writer, iWrite2);
75957 rc = sqlite3VdbeSorterNext(db, pCsr, &bEof);
75959 rc2 = fileWriterFinish(db, &writer, &iWrite2);
75987 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *db, const VdbeCursor *pCsr, int *pbEof){
75993 rc = vdbeSorterIterNext(db, &pSorter->aIter[iPrev]);
76046 vdbeSorterRecordFree(db, pFree);
76884 sqlite3 *db; /* The database connection */
76890 db = pParse->db;
76891 pDup = sqlite3ExprDup(db, pOrig, 0);
76911 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
76915 sqlite3ExprDelete(db, pExpr);
76919 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
76922 sqlite3DbFree(db, pDup);
76978 ** pExpr->iDb Set the index in db->aDb[] of the database X
77011 sqlite3 *db = pParse->db; /* The database connection */
77042 for(i=0; i<db->nDb; i++){
77043 assert( db->aDb[i].zName );
77044 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
77045 pSchema = db->aDb[i].pSchema;
77283 sqlite3ExprDelete(db, pExpr->pLeft);
77285 sqlite3ExprDelete(db, pExpr->pRight);
77312 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
77313 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
77471 u8 enc = ENC(pParse->db); /* The database encoding */
77477 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
77479 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
77529 }else if( no_such_func && pParse->db->init.busy==0 ){
77579 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
77641 sqlite3 *db; /* Database connection */
77643 u8 savedSuppErr; /* Saved value of db->suppressErr */
77656 db = pParse->db;
77657 savedSuppErr = db->suppressErr;
77658 db->suppressErr = 1;
77660 db->suppressErr = savedSuppErr;
77713 sqlite3 *db;
77718 db = pParse->db;
77720 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
77751 pDup = sqlite3ExprDup(db, pE, 0);
77752 if( !db->mallocFailed ){
77756 sqlite3ExprDelete(db, pDup);
77762 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
77773 sqlite3ExprDelete(db, pE);
77809 sqlite3 *db = pParse->db;
77813 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
77815 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
77920 sqlite3 *db; /* Database connection */
77929 db = pParse->db;
77941 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
77981 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
78050 if( db->mallocFailed ){
78060 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
78312 ** If a memory allocation error occurs, that fact is recorded in pParse->db
78321 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
78367 sqlite3 *db = pParse->db;
78378 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
78390 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
78551 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
78661 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
78677 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
78710 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
78717 return sqlite3ExprAlloc(db, op, &x, 0);
78727 sqlite3 *db,
78733 assert( db->mallocFailed );
78734 sqlite3ExprDelete(db, pLeft);
78735 sqlite3ExprDelete(db, pRight);
78753 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
78766 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
78768 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
78769 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
78812 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
78818 sqlite3ExprDelete(db, pLeft);
78819 sqlite3ExprDelete(db, pRight);
78820 return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
78822 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
78823 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
78834 sqlite3 *db = pParse->db;
78836 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
78838 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
78864 sqlite3 *db = pParse->db;
78887 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
78888 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
78889 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
78891 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
78914 a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
78915 if( a==0 ) return; /* Error reported through db->mallocFailed */
78921 sqlite3DbFree(db, pParse->azVar[x-1]);
78922 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
78926 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
78934 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
78941 sqlite3ExprDelete(db, p->pLeft);
78942 sqlite3ExprDelete(db, p->pRight);
78943 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
78945 sqlite3SelectDelete(db, p->x.pSelect);
78947 sqlite3ExprListDelete(db, p->x.pList);
78951 sqlite3DbFree(db, p);
79067 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
79081 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
79122 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
79124 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
79132 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
79133 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
79140 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
79141 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
79153 ** and the db->mallocFailed flag set.
79156 static With *withDup(sqlite3 *db, With *p){
79160 pRet = sqlite3DbMallocZero(db, nByte);
79165 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
79166 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
79167 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
79194 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
79195 return exprDup(db, p, flags, 0);
79197 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
79202 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
79206 pNew->a = pItem = sqlite3DbMallocRaw(db, i*sizeof(p->a[0]) );
79208 sqlite3DbFree(db, pNew);
79214 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
79215 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
79216 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
79233 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
79239 pNew = sqlite3DbMallocRaw(db, nByte );
79247 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
79248 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
79249 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
79257 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
79264 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
79265 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
79266 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
79271 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
79275 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
79278 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
79280 sqlite3DbFree(db, pNew);
79289 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
79294 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
79297 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
79299 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
79300 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
79301 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
79302 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
79303 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
79304 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
79306 pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
79309 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
79310 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
79317 pNew->pWith = withDup(db, p->pWith);
79321 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
79341 sqlite3 *db = pParse->db;
79343 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
79347 pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
79352 a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
79368 sqlite3ExprDelete(db, pExpr);
79369 sqlite3ExprListDelete(db, pList);
79378 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
79387 assert( pList!=0 || pParse->db->mallocFailed!=0 );
79393 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
79403 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
79411 sqlite3 *db = pParse->db;
79412 assert( pList!=0 || db->mallocFailed!=0 );
79416 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
79417 sqlite3DbFree(db, pItem->zSpan);
79418 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
79432 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
79443 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
79449 sqlite3ExprDelete(db, pItem->pExpr);
79450 sqlite3DbFree(db, pItem->zName);
79451 sqlite3DbFree(db, pItem->zSpan);
79453 sqlite3DbFree(db, pList->a);
79454 sqlite3DbFree(db, pList);
79848 sqlite3 *db = pParse->db; /* Database connection */
79863 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79896 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
80013 pParse->db, "EXECUTE %s%s SUBQUERY %d", jmpIfDynamic>=0?"":"CORRELATED ",
80044 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
80168 sqlite3ExprDelete(pParse->db, pSel->pLimit);
80467 if( OptimizationDisabled(pParse->db, SQLITE_ColumnCache) ) return;
80539 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
80556 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
80655 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
80739 sqlite3 *db = pParse->db; /* The database connection */
80744 assert( pParse->db->mallocFailed );
80999 u8 enc = ENC(db); /* The text encoding used by this database */
81012 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
81104 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
81106 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
81110 if( !pColl ) pColl = db->pDfltColl;
81316 assert( db->mallocFailed || pParse->nErr>0
81367 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
81436 assert( pParse->pVdbe || pParse->db->mallocFailed );
82336 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
82339 db,
82352 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
82355 db,
82404 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
82462 u8 enc = ENC(pParse->db);
82463 i = addAggInfoFunc(pParse->db, pAggInfo);
82470 pItem->pFunc = sqlite3FindFunction(pParse->db,
82651 sqlite3 *db = sqlite3_context_db_handle(context);
82680 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
82707 sqlite3 *db = sqlite3_context_db_handle(context);
82729 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
82733 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
82736 sqlite3DbFree(db, zOutput);
82740 sqlite3DbFree(db, zParent);
82744 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
82746 sqlite3DbFree(db, zOutput);
82772 sqlite3 *db = sqlite3_context_db_handle(context);
82820 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
82865 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
82868 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
82870 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
82871 sqlite3DbFree(db, zWhere);
82887 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
82902 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
82904 /* If the table is not located in the temp-db (in which case NULL is
82906 ** that is not part of the temp-db schema, add a clause to the WHERE
82910 sqlite3 *db = pParse->db;
82913 zWhere = whereOrName(db, zWhere, pTrig->zName);
82918 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
82919 sqlite3DbFree(pParse->db, zWhere);
82943 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
82944 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
82950 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
82960 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
83003 sqlite3 *db = pParse->db; /* Database connection */
83011 int savedDbFlags; /* Saved value of db->flags */
83013 savedDbFlags = db->flags;
83014 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
83016 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
83020 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
83021 zDb = db->aDb[iDb].zName;
83022 db->flags |= SQLITE_PreferBuiltin;
83025 zName = sqlite3NameFromToken(db, pName);
83031 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
83066 pVTab = sqlite3GetVTable(db, pTab);
83104 if( db->flags&SQLITE_ForeignKeys ){
83113 sqlite3DbFree(db, zWhere);
83147 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
83165 sqlite3DbFree(db, zWhere);
83170 if( db->flags&SQLITE_ForeignKeys ){
83185 sqlite3SrcListDelete(db, pSrc);
83186 sqlite3DbFree(db, zName);
83187 db->flags = savedDbFlags;
83234 sqlite3 *db; /* The database connection; */
83236 db = pParse->db;
83237 if( pParse->nErr || db->mallocFailed ) return;
83241 assert( sqlite3BtreeHoldsAllMutexes(db) );
83242 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
83243 zDb = db->aDb[iDb].zName;
83247 pTab = sqlite3FindTable(db, zTab, zDb);
83277 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
83293 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
83294 db->mallocFailed = 1;
83305 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
83308 int savedDbFlags = db->flags;
83312 db->flags |= SQLITE_PreferBuiltin;
83320 sqlite3DbFree(db, zCol);
83321 db->flags = savedDbFlags;
83356 sqlite3 *db = pParse->db;
83360 assert( sqlite3BtreeHoldsAllMutexes(db) );
83361 if( db->mallocFailed ) goto exit_begin_add_column;
83382 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
83391 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
83399 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
83400 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
83402 db->mallocFailed = 1;
83408 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
83414 pNew->pSchema = db->aDb[iDb].pSchema;
83425 sqlite3SrcListDelete(db, pSrc);
83626 sqlite3 *db = pParse->db;
83627 Db *pDb;
83633 assert( sqlite3BtreeHoldsAllMutexes(db) );
83634 assert( sqlite3VdbeDb(v)==db );
83635 pDb = &db->aDb[iDb];
83643 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
83725 sqlite3 *db; /* Database connection, for malloc() */
83731 static void sampleClear(sqlite3 *db, Stat4Sample *p){
83732 assert( db!=0 );
83734 sqlite3DbFree(db, p->u.aRowid);
83743 static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
83744 assert( db!=0 );
83745 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
83746 p->u.aRowid = sqlite3DbMallocRaw(db, n);
83759 static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
83760 assert( db!=0 );
83761 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
83780 sampleSetRowid(p->db, pTo, pFrom->nRowid, pFrom->u.aRowid);
83782 sampleSetRowidInt64(p->db, pTo, pFrom->u.iRowid);
83794 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
83795 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
83796 sampleClear(p->db, &p->current);
83798 sqlite3DbFree(p->db, p);
83833 sqlite3 *db; /* Database connection */
83857 db = sqlite3_context_db_handle(context);
83858 p = sqlite3DbMallocZero(db, n);
83864 p->db = db;
84019 sampleClear(p->db, pMin);
84173 sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
84175 sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
84389 sqlite3 *db = pParse->db; /* Database handle */
84423 assert( sqlite3BtreeHoldsAllMutexes(db) );
84424 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
84426 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84429 db->aDb[iDb].zName ) ){
84507 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
84547 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*nColTest);
84595 sqlite3DbFree(db, aGotoChng);
84717 sqlite3 *db = pParse->db;
84718 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
84730 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84748 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
84749 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
84775 sqlite3 *db = pParse->db;
84786 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
84794 for(i=0; i<db->nDb; i++){
84800 iDb = sqlite3FindDb(db, pName1);
84804 z = sqlite3NameFromToken(db, pName1);
84806 if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
84811 sqlite3DbFree(db, z);
84818 zDb = db->aDb[iDb].zName;
84819 z = sqlite3NameFromToken(db, pTableName);
84821 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
84826 sqlite3DbFree(db, z);
84840 sqlite3 *db;
84929 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
84938 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
84963 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
84969 sqlite3DbFree(db, p->p);
84971 sqlite3DbFree(db, pIdx->aSample);
84973 if( db && db->pnBytesFreed==0 ){
84978 UNUSED_PARAMETER(db);
85034 sqlite3 *db,
85038 Index *pIdx = sqlite3FindIndex(db, zName, zDb);
85040 Table *pTab = sqlite3FindTable(db, zName, zDb);
85060 sqlite3 *db, /* Database handle */
85072 assert( db->lookaside.bEnabled==0 );
85073 zSql = sqlite3MPrintf(db, zSql1, zDb);
85077 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
85078 sqlite3DbFree(db, zSql);
85094 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
85112 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
85129 zSql = sqlite3MPrintf(db, zSql2, zDb);
85133 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
85134 sqlite3DbFree(db, zSql);
85144 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
85166 pSample->p = sqlite3DbMallocZero(db, pSample->n + 2);
85183 static int loadStat4(sqlite3 *db, const char *zDb){
85186 assert( db->lookaside.bEnabled==0 );
85187 if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){
85188 rc = loadStatTbl(db, 0,
85195 if( rc==SQLITE_OK && sqlite3FindTable(db, "sqlite_stat3", zDb) ){
85196 rc = loadStatTbl(db, 1,
85223 ** If an OOM error occurs, this function always sets db->mallocFailed.
85227 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
85233 assert( iDb>=0 && iDb<db->nDb );
85234 assert( db->aDb[iDb].pBt!=0 );
85237 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
85238 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
85242 sqlite3DeleteIndexSamples(db, pIdx);
85248 sInfo.db = db;
85249 sInfo.zDatabase = db->aDb[iDb].zName;
85250 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
85255 zSql = sqlite3MPrintf(db,
85260 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
85261 sqlite3DbFree(db, zSql);
85268 int lookasideEnabled = db->lookaside.bEnabled;
85269 db->lookaside.bEnabled = 0;
85270 rc = loadStat4(db, sInfo.zDatabase);
85271 db->lookaside.bEnabled = lookasideEnabled;
85276 db->mallocFailed = 1;
85350 sqlite3 *db = sqlite3_context_db_handle(context);
85356 Db *aNew;
85373 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
85374 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
85375 db->aLimit[SQLITE_LIMIT_ATTACHED]
85379 if( !db->autoCommit ){
85380 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
85383 for(i=0; i<db->nDb; i++){
85384 char *z = db->aDb[i].zName;
85387 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
85392 /* Allocate the new entry in the db->aDb[] array and initialize the schema
85395 if( db->aDb==db->aDbStatic ){
85396 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
85398 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
85400 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
85403 db->aDb = aNew;
85404 aNew = &db->aDb[db->nDb];
85411 flags = db->openFlags;
85412 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
85414 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
85421 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
85423 db->nDb++;
85426 zErrDyn = sqlite3MPrintf(db, "database is already attached");
85429 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
85432 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
85433 zErrDyn = sqlite3MPrintf(db,
85438 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
85440 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
85442 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
85446 aNew->zName = sqlite3DbStrDup(db, zName);
85462 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
85470 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
85475 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
85476 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
85477 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
85486 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
85490 sqlite3BtreeEnterAll(db);
85491 rc = sqlite3Init(db, &zErrDyn);
85492 sqlite3BtreeLeaveAll(db);
85495 int iDb = db->nDb - 1;
85497 if( db->aDb[iDb].pBt ){
85498 sqlite3BtreeClose(db->aDb[iDb].pBt);
85499 db->aDb[iDb].pBt = 0;
85500 db->aDb[iDb].pSchema = 0;
85502 sqlite3ResetAllSchemasOfConnection(db);
85503 db->nDb = iDb;
85505 db->mallocFailed = 1;
85506 sqlite3DbFree(db, zErrDyn);
85507 zErrDyn = sqlite3MPrintf(db, "out of memory");
85509 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
85520 sqlite3DbFree(db, zErrDyn);
85539 sqlite3 *db = sqlite3_context_db_handle(context);
85541 Db *pDb = 0;
85547 for(i=0; i<db->nDb; i++){
85548 pDb = &db->aDb[i];
85553 if( i>=db->nDb ){
85561 if( !db->autoCommit ){
85574 sqlite3ResetAllSchemasOfConnection(db);
85597 sqlite3* db = pParse->db;
85634 assert( v || db->mallocFailed );
85649 sqlite3ExprDelete(db, pFilename);
85650 sqlite3ExprDelete(db, pDbname);
85651 sqlite3ExprDelete(db, pKey);
85708 sqlite3 *db;
85710 db = pParse->db;
85711 assert( db->nDb>iDb );
85713 pFix->zDb = db->aDb[iDb].zName;
85714 pFix->pSchema = db->aDb[iDb].pSchema;
85752 sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
85803 if( pFix->pParse->db->init.busy ){
85931 sqlite3 *db,
85935 sqlite3_mutex_enter(db->mutex);
85936 db->xAuth = xAuth;
85937 db->pAuthArg = pArg;
85938 sqlite3ExpirePreparedStatements(db);
85939 sqlite3_mutex_leave(db->mutex);
85967 sqlite3 *db = pParse->db; /* Database handle */
85968 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
85971 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
85973 if( db->nDb>2 || iDb!=0 ){
86000 sqlite3 *db = pParse->db;
86007 if( db->xAuth==0 ) return;
86008 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
86039 assert( iDb>=0 && iDb<db->nDb );
86058 sqlite3 *db = pParse->db;
86064 if( db->init.busy || IN_DECLARE_VTAB ){
86068 if( db->xAuth==0 ){
86071 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
86192 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
86201 pToplevel->db->mallocFailed = 1;
86251 sqlite3 *db;
86255 db = pParse->db;
86256 if( db->mallocFailed ) return;
86276 if( db->mallocFailed==0
86282 for(iDb=0; iDb<db->nDb; iDb++){
86290 db->aDb[iDb].pSchema->iGeneration /* P4 */
86292 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
86296 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
86329 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
86363 sqlite3 *db = pParse->db;
86370 zSql = sqlite3VMPrintf(db, zFormat, ap);
86379 sqlite3DbFree(db, zErrMsg);
86380 sqlite3DbFree(db, zSql);
86397 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
86404 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
86405 for(i=OMIT_TEMPDB; i<db->nDb; i++){
86407 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
86408 assert( sqlite3SchemaMutexHeld(db, j, 0) );
86409 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
86439 p = sqlite3FindTable(pParse->db, zName, zDbase);
86469 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
86470 zDb = pParse->db->aDb[iDb].zName;
86489 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
86494 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
86495 for(i=OMIT_TEMPDB; i<db->nDb; i++){
86497 Schema *pSchema = db->aDb[j].pSchema;
86499 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
86500 assert( sqlite3SchemaMutexHeld(db, j, 0) );
86510 static void freeIndex(sqlite3 *db, Index *p){
86512 sqlite3DeleteIndexSamples(db, p);
86514 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
86515 sqlite3ExprDelete(db, p->pPartIdxWhere);
86516 sqlite3DbFree(db, p->zColAff);
86517 if( p->isResized ) sqlite3DbFree(db, p->azColl);
86518 sqlite3DbFree(db, p);
86527 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
86532 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
86533 pHash = &db->aDb[iDb].pSchema->idxHash;
86549 freeIndex(db, pIndex);
86551 db->flags |= SQLITE_InternChanges;
86555 ** Look through the list of open database files in db->aDb[] and if
86557 ** db->aDb[] structure to a smaller size, if possible.
86562 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
86564 for(i=j=2; i<db->nDb; i++){
86565 struct Db *pDb = &db->aDb[i];
86567 sqlite3DbFree(db, pDb->zName);
86572 db->aDb[j] = db->aDb[i];
86576 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
86577 db->nDb = j;
86578 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
86579 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
86580 sqlite3DbFree(db, db->aDb);
86581 db->aDb = db->aDbStatic;
86589 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){
86590 Db *pDb;
86591 assert( iDb<db->nDb );
86594 pDb = &db->aDb[iDb];
86595 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
86604 pDb = &db->aDb[1];
86615 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){
86617 sqlite3BtreeEnterAll(db);
86618 for(i=0; i<db->nDb; i++){
86619 Db *pDb = &db->aDb[i];
86624 db->flags &= ~SQLITE_InternChanges;
86625 sqlite3VtabUnlockList(db);
86626 sqlite3BtreeLeaveAll(db);
86627 sqlite3CollapseDatabaseArray(db);
86633 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
86634 db->flags &= ~SQLITE_InternChanges;
86641 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
86647 sqlite3DbFree(db, pCol->zName);
86648 sqlite3ExprDelete(db, pCol->pDflt);
86649 sqlite3DbFree(db, pCol->zDflt);
86650 sqlite3DbFree(db, pCol->zType);
86651 sqlite3DbFree(db, pCol->zColl);
86653 sqlite3DbFree(db, pTable->aCol);
86666 ** The db parameter is optional. It is needed if the Table object
86669 ** db parameter can be used with db->pnBytesFreed to measure the memory
86672 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
86680 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
86685 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
86686 db->lookaside.nOut : 0 );
86692 if( !db || db->pnBytesFreed==0 ){
86697 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
86700 freeIndex(db, pIndex);
86704 sqlite3FkDelete(db, pTable);
86708 sqliteDeleteColumnNames(db, pTable);
86709 sqlite3DbFree(db, pTable->zName);
86710 sqlite3DbFree(db, pTable->zColAff);
86711 sqlite3SelectDelete(db, pTable->pSelect);
86713 sqlite3ExprListDelete(db, pTable->pCheck);
86716 sqlite3VtabClear(db, pTable);
86718 sqlite3DbFree(db, pTable);
86721 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
86728 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
86730 Db *pDb;
86732 assert( db!=0 );
86733 assert( iDb>=0 && iDb<db->nDb );
86735 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
86737 pDb = &db->aDb[iDb];
86740 sqlite3DeleteTable(db, p);
86741 db->flags |= SQLITE_InternChanges;
86757 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
86760 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
86783 ** of a database ("main", "temp" or the name of an attached db). This
86784 ** function returns the index of the named database in db->aDb[], or
86785 ** -1 if the named db cannot be found.
86787 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
86790 Db *pDb;
86792 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
86804 ** "temp" or the name of an attached db). This routine returns the
86805 ** index of the named database in db->aDb[], or -1 if the named db
86808 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
86811 zName = sqlite3NameFromToken(db, pName);
86812 i = sqlite3FindDbName(db, zName);
86813 sqlite3DbFree(db, zName);
86840 sqlite3 *db = pParse->db;
86843 if( db->init.busy ) {
86849 iDb = sqlite3FindDb(db, pName1);
86856 assert( db->init.iDb==0 || db->init.busy );
86857 iDb = db->init.iDb;
86871 if( !pParse->db->init.busy && pParse->nested==0
86872 && (pParse->db->flags & SQLITE_WriteSchema)==0
86928 sqlite3 *db = pParse->db;
86961 zName = sqlite3NameFromToken(db, pName);
86966 if( db->init.iDb==1 ) isTemp = 1;
86971 char *zDb = db->aDb[iDb].zName;
87002 char *zDb = db->aDb[iDb].zName;
87006 pTable = sqlite3FindTable(db, zName, zDb);
87011 assert( !db->init.busy );
87016 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
87022 pTable = sqlite3DbMallocZero(db, sizeof(Table));
87024 db->mallocFailed = 1;
87031 pTable->pSchema = db->aDb[iDb].pSchema;
87043 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87056 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
87077 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
87081 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
87115 sqlite3DbFree(db, zName);
87145 sqlite3 *db = pParse->db;
87148 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
87153 z = sqlite3NameFromToken(db, pName);
87158 sqlite3DbFree(db, z);
87164 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
87166 sqlite3DbFree(db, z);
87301 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
87318 sqlite3 *db = pParse->db;
87330 sqlite3ExprDelete(db, pCol->pDflt);
87331 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
87332 sqlite3DbFree(db, pCol->zDflt);
87333 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
87337 sqlite3ExprDelete(db, pSpan->pExpr);
87421 sqlite3ExprListDelete(pParse->db, pList);
87434 sqlite3 *db = pParse->db;
87436 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
87445 sqlite3ExprDelete(pParse->db, pCheckExpr);
87457 sqlite3 *db;
87461 db = pParse->db;
87462 zColl = sqlite3NameFromToken(db, pToken);
87467 sqlite3DbFree(db, p->aCol[i].zColl);
87481 sqlite3DbFree(db, zColl);
87506 sqlite3 *db = pParse->db;
87507 u8 enc = ENC(db);
87508 u8 initbusy = db->init.busy;
87511 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
87538 sqlite3 *db = pParse->db;
87540 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87541 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
87603 static char *createTableStmt(sqlite3 *db, Table *p){
87625 db->mallocFailed = 1;
87671 static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
87677 zExtra = sqlite3DbMallocZero(db, nByte);
87756 sqlite3 *db = pParse->db;
87783 pList->a[0].zName = sqlite3DbStrDup(pParse->db,
87821 if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
87836 if( resizeIndexObject(db, pPk, pTab->nCol) ) return;
87861 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
87880 sqlite3 *db = pParse->db; /* The database connection */
87884 if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
87890 assert( !db->init.busy || !pSelect );
87892 /* If the db->init.busy is 1 it means we are reading the SQL off the
87895 ** for the table from the db->init.newTnum field. (The page number
87898 if( db->init.busy ){
87899 p->tnum = db->init.newTnum;
87917 iDb = sqlite3SchemaToIndex(db, p->pSchema);
87939 if( !db->init.busy ){
87998 sqlite3DeleteTable(db, pSelTab);
88004 zStmt = createTableStmt(db, p);
88009 zStmt = sqlite3MPrintf(db,
88022 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
88030 sqlite3DbFree(db, zStmt);
88038 Db *pDb = &db->aDb[iDb];
88039 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88051 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
88057 if( db->init.busy ){
88060 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88065 db->mallocFailed = 1;
88069 db->flags |= SQLITE_InternChanges;
88106 sqlite3 *db = pParse->db;
88110 sqlite3SelectDelete(db, pSelect);
88116 sqlite3SelectDelete(db, pSelect);
88120 iDb = sqlite3SchemaToIndex(db
88123 sqlite3SelectDelete(db, pSelect);
88132 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
88133 sqlite3SelectDelete(db, pSelect);
88134 if( db->mallocFailed ){
88137 if( !db->init.busy ){
88172 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
88219 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
88221 u8 enableLookaside = db->lookaside.bEnabled;
88225 db->lookaside.bEnabled = 0;
88227 xAuth = db->xAuth;
88228 db->xAuth = 0;
88230 db->xAuth = xAuth;
88234 db->lookaside.bEnabled = enableLookaside;
88242 sqlite3DeleteTable(db, pSelTab);
88243 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
88249 sqlite3SelectDelete(db, pSel);
88262 static void sqliteViewResetAll(sqlite3 *db, int idx){
88264 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
88265 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
88266 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
88269 sqliteDeleteColumnNames(db, pTab);
88274 DbClearProperty(db, idx, DB_UnresetViews);
88298 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
88301 Db *pDb;
88303 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88304 pDb = &db->aDb[iDb];
88345 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
88359 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
88401 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
88402 assert( iDb>=0 && iDb<pParse->db->nDb );
88421 const char *zDbName = pParse->db->aDb[iDb].zName;
88425 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
88439 sqlite3 *db = pParse->db;
88441 Db *pDb = &db->aDb[iDb];
88460 pTrigger->pSchema==db->aDb[1].pSchema );
88501 sqliteViewResetAll(db, iDb);
88511 sqlite3 *db = pParse->db;
88514 if( db->mallocFailed ){
88519 if( noErr ) db->suppressErr++;
88521 if( noErr ) db->suppressErr--;
88527 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
88528 assert( iDb>=0 && iDb<db->nDb );
88540 const char *zDb = db->aDb[iDb].zName;
88554 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
88603 sqlite3SrcListDelete(db, pName);
88629 sqlite3 *db = pParse->db;
88665 pFKey = sqlite3DbMallocZero(db, nByte );
88710 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
88715 db->mallocFailed = 1;
88730 sqlite3DbFree(db, pFKey);
88732 sqlite3ExprListDelete(db, pFromCol);
88733 sqlite3ExprListDelete(db, pToCol);
88776 sqlite3 *db = pParse->db; /* The database connection */
88777 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
88781 db->aDb[iDb].zName ) ){
88820 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
88851 sqlite3 *db, /* Database connection */
88864 p = sqlite3DbMallocZero(db, nByte + nExtra);
88914 sqlite3 *db = pParse->db;
88915 Db *pDb; /* The specific table containing the indexed database */
88926 if( db->mallocFailed || IN_DECLARE_VTAB ){
88939 ** to search for the table. 'Fix' the table name to this db
88952 if( !db->init.busy ){
88954 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
88967 assert( db->mallocFailed==0 || pTab==0 );
88969 if( iDb==1 && db->aDb[iDb].pSchema!=pTab->pSchema ){
88981 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
88983 pDb = &db->aDb[iDb];
89019 zName = sqlite3NameFromToken(db, pName);
89025 if( !db->init.busy ){
89026 if( sqlite3FindTable(db, zName, 0)!=0 ){
89031 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
89035 assert( !db->init.busy );
89044 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
89073 pList->a[0].zName = sqlite3DbStrDup(pParse->db,
89094 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
89096 if( db->mallocFailed ){
89108 pIndex->pSchema = db->aDb[iDb].pSchema;
89115 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
89165 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
89256 if( db->init.busy ){
89258 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
89264 db->mallocFailed = 1;
89267 db->flags |= SQLITE_InternChanges;
89269 pIndex->tnum = db->init.newTnum;
89307 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
89319 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
89325 sqlite3DbFree(db, zStmt);
89334 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
89345 if( db->init.busy || pTblName==0 ){
89364 if( pIndex ) freeIndex(db, pIndex);
89365 sqlite3ExprDelete(db, pPIWhere);
89366 sqlite3ExprListDelete(db, pList);
89367 sqlite3SrcListDelete(db, pTblName);
89368 sqlite3DbFree(db, zName);
89421 sqlite3 *db = pParse->db;
89425 if( db->mallocFailed ){
89432 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
89447 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
89452 const char *zDb = db->aDb[iDb].zName;
89470 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
89479 sqlite3SrcListDelete(db, pName);
89500 sqlite3 *db, /* Connection to notify of malloc failures */
89510 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
89530 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
89533 db, sizeof(IdList) );
89537 db,
89544 sqlite3IdListDelete(db, pList);
89547 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
89554 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
89558 sqlite3DbFree(db, pList->a[i].zName);
89560 sqlite3DbFree(db, pList->a);
89561 sqlite3DbFree(db, pList);
89585 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
89594 ** db->mallocFailed flag will be set to true.
89597 sqlite3 *db, /* Database connection to notify of OOM errors */
89615 pNew = sqlite3DbRealloc(db, pSrc,
89618 assert( db->mallocFailed );
89622 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
89679 sqlite3 *db, /* Connection to notify of malloc failures */
89687 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
89691 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
89692 if( db->mallocFailed ){
89693 sqlite3SrcListDelete(db, pList);
89705 pItem->zName = sqlite3NameFromToken(db, pTable);
89706 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
89716 assert(pList || pParse->db->mallocFailed );
89731 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
89736 sqlite3DbFree(db, pItem->zDatabase);
89737 sqlite3DbFree(db, pItem->zName);
89738 sqlite3DbFree(db, pItem->zAlias);
89739 sqlite3DbFree(db, pItem->zIndex);
89740 sqlite3DeleteTable(db, pItem->pTab);
89741 sqlite3SelectDelete(db, pItem->pSelect);
89742 sqlite3ExprDelete(db, pItem->pOn);
89743 sqlite3IdListDelete(db, pItem->pUsing);
89745 sqlite3DbFree(db, pList);
89775 sqlite3 *db = pParse->db;
89782 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
89789 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
89798 sqlite3ExprDelete(db, pOn);
89799 sqlite3IdListDelete(db, pUsing);
89800 sqlite3SelectDelete(db, pSubquery);
89818 pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy);
89853 sqlite3 *db;
89858 db = pParse->db;
89859 assert( db!=0 );
89860 /* if( db->aDb[0].pBt==0 ) return; */
89867 for(i=0; i<db->nDb; i++){
89882 assert( pParse->db!=0 );
89899 assert( pParse->db!=0 );
89914 char *zName = sqlite3NameFromToken(pParse->db, pName);
89922 sqlite3DbFree(pParse->db, zName);
89934 sqlite3 *db = pParse->db;
89935 if( db->aDb[1].pBt==0 && !pParse->explain ){
89945 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
89952 db->aDb[1].pBt = pBt;
89953 assert( db->aDb[1].pSchema );
89954 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
89955 db->mallocFailed = 1;
89970 sqlite3 *db = pToplevel->db;
89972 assert( iDb>=0 && iDb<db->nDb );
89973 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
89975 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
89978 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
89990 sqlite3 *db = pParse->db;
89992 for(i=0; i<db->nDb; i++){
89993 Db *pDb = &db->aDb[i];
90089 errMsg.db = pParse->db;
90116 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
90120 zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
90156 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
90171 Db *pDb; /* A single database */
90173 sqlite3 *db = pParse->db; /* The database connection */
90177 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
90178 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
90209 sqlite3 *db = pParse->db; /* The database connection */
90224 zColl = sqlite3NameFromToken(pParse->db, pName1);
90226 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
90229 sqlite3DbFree(db, zColl);
90232 sqlite3DbFree(db, zColl);
90236 z = sqlite3NameFromToken(db, pObjName);
90238 zDb = db->aDb[iDb].zName;
90239 pTab = sqlite3FindTable(db, z, zDb);
90242 sqlite3DbFree(db, z);
90245 pIndex = sqlite3FindIndex(db, z, zDb);
90246 sqlite3DbFree(db, z);
90269 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db!=pParse->db ){
90280 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
90282 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
90315 sqlite3 *db = pParse->db;
90321 zName = sqlite3NameFromToken(pParse->db, pName);
90333 pNew = sqlite3DbRealloc(db, pWith, nByte);
90335 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
90338 assert( db->mallocFailed==0 || pNew==0 );
90341 sqlite3ExprListDelete(db, pArglist);
90342 sqlite3SelectDelete(db, pQuery);
90343 sqlite3DbFree(db, zName);
90359 SQLITE_PRIVATE void sqlite3WithDelete(sqlite3 *db, With *pWith){
90364 sqlite3ExprListDelete(db, pCte->pCols);
90365 sqlite3SelectDelete(db, pCte->pSelect);
90366 sqlite3DbFree(db, pCte->zName);
90368 sqlite3DbFree(db, pWith);
90396 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
90397 assert( !db->xCollNeeded || !db->xCollNeeded16 );
90398 if( db->xCollNeeded ){
90399 char *zExternal = sqlite3DbStrDup(db, zName);
90401 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
90402 sqlite3DbFree(db, zExternal);
90405 if( db->xCollNeeded16 ){
90407 sqlite3_value *pTmp = sqlite3ValueNew(db);
90411 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
90425 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
90431 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
90450 ** db for collation type name zName, length nName, or NULL, if no collation
90462 sqlite3 *db = pParse->db;
90466 p = sqlite3FindCollSeq(db, enc, zName, 0);
90472 callCollNeeded(db, enc, zName);
90473 p = sqlite3FindCollSeq(db, enc, zName, 0);
90475 if( p && !p->xCmp && synthCollSeq(db, p) ){
90499 sqlite3 *db = pParse->db;
90500 CollSeq *p = sqlite3GetCollSeq(pParse, ENC(db), pColl, zName);
90512 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
90525 sqlite3 *db, /* Database connection */
90531 pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
90534 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
90545 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
90553 db->mallocFailed = 1;
90554 sqlite3DbFree(db, pDel);
90565 ** for the encoding 'enc' from the database 'db'.
90578 sqlite3 *db,
90585 pColl = findCollSeqEntry(db, zName, create);
90587 pColl = db->pDfltColl;
90706 ** structure is created and liked into the "db" structure if a
90719 sqlite3 *db, /* An open database */
90733 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
90737 p = functionSearch(&db->aFunc, h, zName, nName);
90759 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
90778 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
90784 sqlite3FuncDefInsert(&db->aFunc, pBest);
90795 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
90833 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
90841 db->mallocFailed = 1;
90888 sqlite3DeleteTable(pParse->db, pItem->pTab);
90916 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
90918 && (pParse->db->flags & SQLITE_WriteSchema)==0
90950 sqlite3 *db = pParse->db;
90951 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
90952 pWhere = sqlite3ExprDup(db, pWhere, 0);
90953 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
90956 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
90957 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
90964 sqlite3SelectDelete(db, pSel);
91025 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
91027 sqlite3ExprListDelete(pParse->db, pEList);
91049 sqlite3SelectDelete(pParse->db, pSelect);
91053 sqlite3ExprDelete(pParse->db, pWhere);
91054 sqlite3ExprListDelete(pParse->db, pOrderBy);
91055 sqlite3ExprDelete(pParse->db, pLimit);
91056 sqlite3ExprDelete(pParse->db, pOffset);
91084 sqlite3 *db; /* Main database structure */
91111 db = pParse->db;
91112 if( pParse->nErr || db->mallocFailed ){
91149 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91150 assert( iDb<db->nDb );
91151 zDb = db->aDb[iDb].zName;
91204 if( db->flags & SQLITE_CountRows ){
91259 if( db->flags & SQLITE_CountRows ){
91282 aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
91351 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
91396 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
91404 sqlite3SrcListDelete(db, pTabList);
91405 sqlite3ExprDelete(db, pWhere);
91406 sqlite3DbFree(db, aToOpen);
91926 str.db = sqlite3_context_db_handle(context);
92075 sqlite3 *db = sqlite3_context_db_handle(context);
92077 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
92078 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
92079 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
92201 sqlite3 *db = sqlite3_context_db_handle(context);
92206 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
92221 sqlite3 *db = sqlite3_context_db_handle(context);
92223 sqlite3_result_int(context, sqlite3_changes(db));
92235 sqlite3 *db = sqlite3_context_db_handle(context);
92239 sqlite3_result_int(context, sqlite3_total_changes(db));
92446 sqlite3 *db = sqlite3_context_db_handle(context);
92455 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
92456 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
92457 if( nPat > db
92775 sqlite3 *db = sqlite3_context_db_handle(context);
92779 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
92780 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
92781 if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
92845 sqlite3 *db = sqlite3_context_db_handle(context);
92847 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
92848 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
92849 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
93026 sqlite3 *db = sqlite3_context_db_handle(context);
93034 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
93172 ** returns (void *)db, where db is the sqlite3* database pointer.
93215 sqlite3 *db = sqlite3_context_db_handle(context);
93218 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
93254 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
93255 int rc = sqlite3_overload_function(db, "MATCH", 2);
93258 db->mallocFailed = 1;
93265 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
93267 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
93279 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
93286 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
93287 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
93288 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
93290 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
93291 setLikeOptFlag(db, "like",
93302 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
93311 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
93621 ** pParse->db->mallocFailed flag is set.
93662 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
93724 sqlite3DbFree(pParse->db, aiCol);
93867 if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
93907 sqlite3 *db = pParse->db;
93909 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
93916 if( zColl==0 ) zColl = db->pDfltColl->zName;
93931 sqlite3 *db, /* The database connection */
93936 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
93983 sqlite3 *db = pParse->db; /* Database handle */
94021 pRight = sqlite3Expr(db, TK_ID, zCol);
94023 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
94043 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
94052 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
94054 pAll = sqlite3ExprAnd(db, pAll, pEq);
94058 pWhere = sqlite3ExprAnd(db, pWhere, pNe);
94081 sqlite3ExprDelete(db, pWhere);
94143 sqlite3 *db = pParse->db;
94144 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
94157 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
94165 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
94177 if( (db->flags & SQLITE_DeferFKs)==0 ){
94282 sqlite3 *db = pParse->db; /* Database handle */
94292 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
94294 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
94295 zDb = db->aDb[iDb].zName;
94320 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
94326 if( !isIgnoreErrors || db->mallocFailed ) return;
94361 if( db->xAuth ){
94388 sqlite3DbFree(db, aiFree);
94402 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
94412 if( !isIgnoreErrors || db->mallocFailed ) return;
94419 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
94440 sqlite3SrcListDelete(db, pSrc);
94442 sqlite3DbFree(db, aiCol);
94457 if( pParse->db->flags&SQLITE_ForeignKeys ){
94495 if( pParse->db->flags&SQLITE_ForeignKeys ){
94555 sqlite3 *db = pParse->db; /* Database handle */
94564 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
94606 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
94624 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
94637 pNew = sqlite3ExprDup(db, pDflt, 0);
94648 sqlite3DbFree(db, aiCol);
94659 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
94665 sqlite3SrcListAppend(db, 0, &tFrom, 0),
94673 enableLookaside = db->lookaside.bEnabled;
94674 db->lookaside.bEnabled = 0;
94676 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
94687 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
94688 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
94689 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
94692 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
94697 db->lookaside.bEnabled = enableLookaside;
94699 sqlite3ExprDelete(db, pWhere);
94700 sqlite3ExprDelete(db, pWhen);
94701 sqlite3ExprListDelete(db, pList);
94702 sqlite3SelectDelete(db, pSelect);
94703 if( db->mallocFailed==1 ){
94704 fkTriggerDelete(db, pTrigger);
94747 if( pParse->db->flags&SQLITE_ForeignKeys ){
94767 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
94771 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
94775 if( !db || db->pnBytesFreed==0 ){
94795 fkTriggerDelete(db, pFKey->apTrigger[0]);
94796 fkTriggerDelete(db, pFKey->apTrigger[1]);
94800 sqlite3DbFree(db, pFKey);
94889 sqlite3 *db = sqlite3VdbeDb(v);
94892 db->mallocFailed = 1;
94929 sqlite3 *db = sqlite3VdbeDb(v);
94932 db->mallocFailed = 1;
94965 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
95028 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
95049 sqlite3 *db = pParse->db; /* The database connection */
95050 Db *pDb; /* Database only autoinc table */
95062 pDb = &db->aDb[p->iDb];
95064 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
95106 sqlite3 *db = pParse->db;
95110 Db *pDb = &db->aDb[p->iDb];
95116 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
95248 sqlite3 *db; /* The main database structure */
95266 Db *pDb; /* The database containing table being inserted into */
95288 db = pParse->db;
95290 if( pParse->nErr || db->mallocFailed ){
95301 sqlite3SelectDelete(db, pSelect);
95314 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95315 assert( iDb<db->nDb );
95316 pDb = &db->aDb[iDb];
95453 if( rc || db->mallocFailed ) goto insert_cleanup;
95546 if( db->flags & SQLITE_CountRows ){
95556 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
95755 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
95775 if( (db->flags & SQLITE_CountRows)!=0 ){
95820 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
95827 sqlite3SrcListDelete(db, pTabList);
95828 sqlite3ExprListDelete(db, pList);
95829 sqlite3SelectDelete(db, pSelect);
95830 sqlite3IdListDelete(db, pColumn);
95831 sqlite3DbFree(db, aRegIdx);
95946 sqlite3 *db; /* Database connection */
95961 db = pParse->db;
96007 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
96033 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
96133 if( db->flags&SQLITE_RecTriggers ){
96309 if( db->flags&SQLITE_RecTriggers ){
96443 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
96717 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
96721 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
96732 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
96856 sqlite3 *db, /* The database on which the SQL executes */
96868 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
96871 sqlite3_mutex_enter(db->mutex);
96872 sqlite3Error(db, SQLITE_OK, 0);
96878 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
96899 && db->flags&SQLITE_NullCallback)) ){
96901 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
96918 db->mallocFailed = 1;
96930 sqlite3Error(db, SQLITE_ABORT, 0);
96944 sqlite3DbFree(db, azCols);
96950 sqlite3DbFree(db, azCols);
96952 rc = sqlite3ApiExit(db, rc);
96953 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
96954 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
96957 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
96960 sqlite3Error(db, SQLITE_NOMEM, 0);
96966 assert( (rc&db->errMask)==rc );
96967 sqlite3_mutex_leave(db->mutex);
97088 int (*errcode)(sqlite3*db);
97867 ** by calling sqlite3DbFree(db, ).
97870 sqlite3 *db, /* Load the extension into this database connection */
97875 sqlite3_vfs *pVfs = db->pVfs;
97905 if( (db->flags & SQLITE_LoadExtension)==0 ){
97985 if( xInit(db, &zErrmsg, &sqlite3Apis) ){
97994 /* Append the new shared library handle to the db->aExtension array. */
97995 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
97999 if( db->nExtension>0 ){
98000 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
98002 sqlite3DbFree(db, db->aExtension);
98003 db->aExtension = aHandle;
98005 db->aExtension[db->nExtension++] = handle;
98009 sqlite3 *db, /* Load the extension into this database connection */
98015 sqlite3_mutex_enter(db->mutex);
98016 rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
98017 rc = sqlite3ApiExit(db, rc);
98018 sqlite3_mutex_leave(db->mutex);
98026 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
98028 assert( sqlite3_mutex_held(db->mutex) );
98029 for(i=0; i<db->nExtension; i++){
98030 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
98032 sqlite3DbFree(db, db->aExtension);
98039 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
98040 sqlite3_mutex_enter(db->mutex);
98042 db->flags |= SQLITE_LoadExtension;
98044 db->flags &= ~SQLITE_LoadExtension;
98046 sqlite3_mutex_leave(db->mutex);
98186 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
98212 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
98213 sqlite3Error(db, rc,
98766 ** Interpret the given string as a temp db location. Return 1 for file
98789 sqlite3 *db = pParse->db;
98790 if( db->aDb[1].pBt!=0 ){
98791 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
98796 sqlite3BtreeClose(db->aDb[1].pBt);
98797 db->aDb[1].pBt = 0;
98798 sqlite3ResetAllSchemasOfConnection(db);
98812 sqlite3 *db = pParse->db;
98813 if( db->temp_store==ts ) return SQLITE_OK;
98817 db->temp_store = (u8)ts;
98828 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
98844 static void setAllPagerFlags(sqlite3 *db){
98845 if( db->autoCommit ){
98846 Db *pDb = db->aDb;
98847 int n = db->nDb;
98857 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) );
98941 sqlite3 *db = pParse->db; /* The database connection */
98942 Db *pDb; /* The specific database being pragmaed */
98950 ** index of the database this pragma is being applied to in db.aDb[]. */
98953 pDb = &db->aDb[iDb];
98962 zLeft = sqlite3NameFromToken(db, pId);
98965 zRight = sqlite3MPrintf(db, "-%T", pValue);
98967 zRight = sqlite3NameFromToken(db, pValue);
98984 db->busyHandler.nBusy = 0;
98985 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
99075 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99103 db->nextPagesize = sqlite3Atoi(zRight);
99104 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
99105 db->mallocFailed = 1;
99128 for(ii=0; ii<db->nDb; ii++){
99129 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
99183 eMode = db->dfltLockMode;
99189 ** set on all attached databases, as well as the main db file.
99196 assert(pDb==&db->aDb[0]);
99197 for(ii=2; ii<db->nDb; ii++){
99198 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
99201 db->dfltLockMode = (u8)eMode;
99252 for(ii=db->nDb-1; ii>=0; ii--){
99253 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
99298 db->nextAutovac = (u8)eAuto;
99302 ** as an auto-vacuum capable db.
99369 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99397 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99402 if( pId2->n==0 ) db->szMmap = sz;
99403 for(ii=db->nDb-1; ii>=0; ii--){
99404 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
99405 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
99410 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
99437 returnSingleInt(pParse, "temp_store", db->temp_store);
99467 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
99474 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
99475 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
99517 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
99592 if( !db->autoCommit ){
99597 setAllPagerFlags(db);
99608 (db->flags & aPragmaNames[mid].iArg)!=0 );
99611 if( db->autoCommit==0 ){
99618 db->flags |= mask;
99620 db->flags &= ~mask;
99621 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
99629 setAllPagerFlags(db);
99650 pTab = sqlite3FindTable(db, zRight, zDb);
99730 pIdx = sqlite3FindIndex(db, zRight, zDb);
99756 pTab = sqlite3FindTable(db, zRight, zDb);
99782 for(i=0; i<db->nDb; i++){
99783 if( db->aDb[i].pBt==0 ) continue;
99784 assert( db->aDb[i].zName!=0 );
99786 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
99788 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
99801 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
99815 pTab = sqlite3FindTable(db, zRight, zDb);
99887 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
99903 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
99925 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
99967 sqlite3DbFree(db, aiCols);
99995 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
100025 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
100026 ** then iDb is set to the index of the database identified by <db>.
100054 for(i=0; i<db->nDb; i++){
100073 assert( sqlite3SchemaMutexHeld(db, i, 0) );
100074 pTbls = &db->aDb[i].pSchema->tblHash;
100098 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
100141 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
100279 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
100288 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
100289 DbHasProperty(db, 0, DB_Empty)
100293 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
100443 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
100446 db->xWalCallback==sqlite3WalDefaultHook ?
100447 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
100459 sqlite3_db_release_memory(db);
100467 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
100475 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
100477 returnSingleInt(pParse, "timeout", db->busyTimeout);
100510 for(i=0; i<db->nDb; i++){
100514 if( db->aDb[i].zName==0 ) continue;
100515 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
100516 pBt = db->aDb[i].pBt;
100519 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
100532 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
100536 if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
100549 sqlite3_key_v2(db, zDb, zKey, i/2);
100551 sqlite3_rekey_v2(db, zDb, zKey, i/2);
100576 sqlite3DbFree(db, zLeft);
100577 sqlite3DbFree(db, zRight);
100609 sqlite3 *db = pData->db;
100610 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
100612 sqlite3SetString(pData->pzErrMsg, db,
100615 *pData->pzErrMsg = sqlite3MAppendf(db, *pData->pzErrMsg,
100619 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT;
100636 sqlite3 *db = pData->db;
100641 assert( sqlite3_mutex_held(db->mutex) );
100642 DbClearProperty(db, iDb, DB_Empty);
100643 if( db->mallocFailed ){
100648 assert( iDb>=0 && iDb<db->nDb );
100654 ** But because db->init.busy is set to 1, no VDBE code is generated
100662 assert( db->init.busy );
100663 db->init.iDb = iDb;
100664 db->init.newTnum = sqlite3Atoi(argv[1]);
100665 db->init.orphanTrigger = 0;
100666 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
100667 rc = db->errCode;
100669 db->init.iDb = 0;
100671 if( db->init.orphanTrigger ){
100676 db->mallocFailed = 1;
100678 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
100693 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
100716 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
100723 Db *pDb;
100757 assert( iDb>=0 && iDb<db->nDb );
100758 assert( db->aDb[iDb].pSchema );
100759 assert( sqlite3_mutex_held(db->mutex) );
100760 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
100778 initData.db = db;
100787 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
100794 pDb = &db->aDb[iDb];
100797 DbSetProperty(db, 1, DB_SchemaLoaded);
100809 sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
100822 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
100839 ** For an attached db, it is an error if the encoding is not the same
100846 /* If opening the main database, set ENC(db). */
100849 ENC(db) = encoding;
100851 ENC(db) = SQLITE_UTF8;
100854 /* If opening an attached database, the encoding much match ENC(db) */
100855 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
100856 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
100863 DbSetProperty(db, iDb, DB_Empty);
100865 pDb->pSchema->enc = ENC(db);
100889 sqlite3SetString(pzErrMsg, db, "unsupported file format");
100900 db->flags &= ~SQLITE_LegacyFileFmt;
100905 assert( db->init.busy );
100908 zSql = sqlite3MPrintf(db,
100910 db->aDb[iDb].zName, zMasterName);
100914 xAuth = db->xAuth;
100915 db->xAuth = 0;
100917 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
100919 db->xAuth = xAuth;
100923 sqlite3DbFree(db, zSql);
100926 sqlite3AnalysisLoad(db, iDb);
100930 if( db->mallocFailed ){
100932 sqlite3ResetAllSchemasOfConnection(db);
100934 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
100943 DbSetProperty(db, iDb, DB_SchemaLoaded);
100959 db->mallocFailed = 1;
100971 ** bit is set in the flags field of the Db structure. If the database
100974 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
100976 int commit_internal = !(db->flags&SQLITE_InternChanges);
100978 assert( sqlite3_mutex_held(db->mutex) );
100980 db->init.busy = 1;
100981 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
100982 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
100983 rc = sqlite3InitOne(db, i, pzErrMsg);
100985 sqlite3ResetOneSchema(db, i);
100994 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
100995 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
100996 rc = sqlite3InitOne(db, 1, pzErrMsg);
100998 sqlite3ResetOneSchema(db, 1);
101003 db->init.busy = 0;
101005 sqlite3CommitInternalChanges(db);
101017 sqlite3 *db = pParse->db;
101018 assert( sqlite3_mutex_held(db->mutex) );
101019 if( !db->init.busy ){
101020 rc = sqlite3Init(db, &pParse->zErrMsg);
101036 sqlite3 *db = pParse->db;
101042 assert( sqlite3_mutex_held(db->mutex) );
101043 for(iDb=0; iDb<db->nDb; iDb++){
101045 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
101054 db->mallocFailed = 1;
101064 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
101065 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
101066 sqlite3ResetOneSchema(db, iDb);
101079 ** which database file in db->aDb[] the schema refers to.
101084 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
101093 ** -1000000 as the incorrect index into db->aDb[] is much
101097 assert( sqlite3_mutex_held(db->mutex) );
101099 for(i=0; ALWAYS(i<db->nDb); i++){
101100 if( db->aDb[i].pSchema==pSchema ){
101104 assert( i>=0 && i<db->nDb );
101114 sqlite3 *db = pParse->db;
101115 sqlite3DbFree(db, pParse->aLabel);
101116 sqlite3ExprListDelete(db, pParse->pConstExpr);
101124 sqlite3 *db, /* Database handle. */
101138 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
101145 assert( !db->mallocFailed );
101146 assert( sqlite3_mutex_held(db->mutex) );
101171 for(i=0; i<db->nDb; i++) {
101172 Btree *pBt = db->aDb[i].pBt;
101177 const char *zDb = db->aDb[i].zName;
101178 sqlite3Error(db, rc, "database schema is locked: %s", zDb);
101179 testcase( db->flags & SQLITE_ReadUncommitted );
101185 sqlite3VtabUnlockList(db);
101187 pParse->db = db;
101191 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
101195 sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
101196 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
101199 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
101202 sqlite3DbFree(db, zSqlCopy);
101212 if( db->mallocFailed ){
101219 if( db->mallocFailed ){
101250 if( db->init.busy==0 ){
101254 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
101262 sqlite3Error(db, rc, "%s", zErrMsg);
101263 sqlite3DbFree(db, zErrMsg);
101265 sqlite3Error(db, rc, 0);
101272 sqlite3DbFree(db, pT);
101278 sqlite3StackFree(db, pParse);
101279 rc = sqlite3ApiExit(db, rc);
101280 assert( (rc&db->errMask)==rc );
101284 sqlite3 *db, /* Database handle. */
101295 if( !sqlite3SafetyCheckOk(db) ){
101298 sqlite3_mutex_enter(db->mutex);
101299 sqlite3BtreeEnterAll(db);
101300 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
101303 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
101305 sqlite3BtreeLeaveAll(db);
101306 sqlite3_mutex_leave(db->mutex);
101323 sqlite3 *db;
101328 db = sqlite3VdbeDb(p);
101329 assert( sqlite3_mutex_held(db->mutex) );
101330 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
101333 db->mallocFailed = 1;
101357 sqlite3 *db, /* Database handle. */
101364 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
101369 sqlite3 *db, /* Database handle. */
101376 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
101387 sqlite3 *db, /* Database handle. */
101404 if( !sqlite3SafetyCheckOk(db) ){
101413 sqlite3_mutex_enter(db->mutex);
101414 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
101416 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
101428 sqlite3DbFree(db, zSql8);
101429 rc = sqlite3ApiExit(db, rc);
101430 sqlite3_mutex_leave(db->mutex);
101443 sqlite3 *db, /* Database handle. */
101450 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
101455 sqlite3 *db, /* Database handle. */
101462 rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
101519 static void clearSelect(sqlite3 *db, Select *p){
101520 sqlite3ExprListDelete(db, p->pEList);
101521 sqlite3SrcListDelete(db, p->pSrc);
101522 sqlite3ExprDelete(db, p->pWhere);
101523 sqlite3ExprListDelete(db, p->pGroupBy);
101524 sqlite3ExprDelete(db, p->pHaving);
101525 sqlite3ExprListDelete(db, p->pOrderBy);
101526 sqlite3SelectDelete(db, p->pPrior);
101527 sqlite3ExprDelete(db, p->pLimit);
101528 sqlite3ExprDelete(db, p->pOffset);
101529 sqlite3WithDelete(db, p->pWith);
101562 sqlite3 *db = pParse->db;
101563 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
101564 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
101566 assert( db->mallocFailed );
101571 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
101574 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
101587 if( db->mallocFailed ) {
101588 clearSelect(db, pNew);
101589 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
101601 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
101603 clearSelect(db, p);
101604 sqlite3DbFree(db, p);
101756 sqlite3 *db = pParse->db;
101766 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
101767 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
101776 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
101882 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
101963 if( pParse->db->mallocFailed ) return;
102178 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
102401 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
102408 p->enc = ENC(db);
102409 p->db = db;
102412 db->mallocFailed = 1;
102472 sqlite3 *db = pParse->db;
102476 pInfo = sqlite3KeyInfoAlloc(db, nExpr+nExtra-iStart, 1);
102482 if( !pColl ) pColl = db->pDfltColl;
102520 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
102566 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
102827 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
102828 zOrigDb = pNC->pParse->db->aDb[iDb].zName;
102923 sqlite3 *db = pParse->db;
102933 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
102935 fullNames = (db->flags & SQLITE_FullColNames)!=0;
102936 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
102963 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
102966 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
102973 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
102999 sqlite3 *db = pParse->db; /* Database connection */
103010 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
103025 zName = sqlite3DbStrDup(db, zName);
103038 zName = sqlite3MPrintf(db, "%s",
103042 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
103045 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
103048 if( db->mallocFailed ){
103049 sqlite3DbFree(db, zName);
103064 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
103065 sqlite3DbFree(db, zName);
103073 if( db->mallocFailed ){
103075 sqlite3DbFree(db, aCol[j].zName);
103077 sqlite3DbFree(db, aCol);
103101 sqlite3 *db = pParse->db;
103112 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
103113 if( db->mallocFailed ) return;
103119 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst));
103125 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
103137 sqlite3 *db = pParse->db;
103140 savedFlags = db->flags;
103141 db->flags &= ~SQLITE_FullColNames;
103142 db->flags |= SQLITE_ShortColNames;
103146 db->flags = savedFlags;
103147 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
103153 assert( db->lookaside.bEnabled==0 );
103160 if( db->mallocFailed ){
103161 sqlite3DeleteTable(db, pTab);
103177 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
103296 sqlite3 *db = pParse->db;
103297 KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
103309 if( pColl==0 ) pColl = db->pDfltColl;
103478 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
103535 sqlite3 *db; /* Database connection */
103546 db = pParse->db;
103704 sqlite3ExprListDelete(db, p->pOrderBy);
103709 sqlite3ExprDelete(db, p->pLimit);
103789 sqlite3ExprDelete(db, p->pLimit);
103841 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
103849 *apColl = db->pDfltColl;
103874 sqlite3SelectDelete(db, pDelete);
103928 if( pParse->db->mallocFailed ) return 0;
104156 sqlite3 *db; /* Database connection */
104167 db = pParse->db;
104188 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
104195 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
104212 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
104228 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
104238 assert( nOrderBy>=nExpr || db->mallocFailed );
104242 pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
104272 sqlite3ExprDelete(db, p->pLimit);
104274 sqlite3ExprDelete(db, p->pOffset);
104419 sqlite3SelectDelete(db, p->pPrior);
104450 sqlite3 *db, /* Report malloc errors to this connection */
104463 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
104464 sqlite3ExprDelete(db, pExpr);
104468 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
104469 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
104471 substSelect(db, pExpr->x.pSelect, iTable, pEList);
104473 substExprList(db, pExpr->x.pList, iTable, pEList);
104479 sqlite3 *db, /* Report malloc errors here */
104487 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
104491 sqlite3 *db, /* Report malloc errors here */
104500 substExprList(db, p->pEList, iTable, pEList);
104501 substExprList(db, p->pGroupBy, iTable, pEList);
104502 substExprList(db, p->pOrderBy, iTable, pEList);
104503 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
104504 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
104505 substSelect(db, p->pPrior, iTable, pEList);
104510 substSelect(db, pItem->pSelect, iTable, pEList);
104664 sqlite3 *db = pParse->db;
104670 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
104833 pNew = sqlite3SelectDup(db, p, 0);
104847 if( db->mallocFailed ) return 1;
104858 sqlite3DbFree(db, pSubitem->zDatabase);
104859 sqlite3DbFree(db, pSubitem->zName);
104860 sqlite3DbFree(db, pSubitem->zAlias);
104910 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
104912 assert( db->mallocFailed );
104933 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
104934 if( db->mallocFailed ){
104943 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
104964 char *zName = sqlite3DbStrDup(db, pList->a[i].zSpan);
104969 substExprList(db, pParent->pEList, iParent, pSub->pEList);
104971 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
104972 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
104979 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
104982 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
104990 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
104991 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
104992 sqlite3ExprDup(db, pSub->pHaving, 0));
104994 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
104996 pParent->pWhere = substExpr(db, pParent->pWhere, iParent, pSub->pEList);
104997 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
105020 sqlite3SelectDelete(db, pSub1);
105151 sqlite3 *db;
105170 db = pParse->db;
105171 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
105178 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0));
105265 sqlite3 *db = pParse->db;
105290 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
105293 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
105297 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
105298 if( db->mallocFailed ) return SQLITE_NOMEM;
105416 sqlite3 *db = pParse->db;
105421 if( db->mallocFailed ){
105464 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
105467 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
105491 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
105505 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
105534 int flags = pParse->db->flags;
105579 if( db->mallocFailed ) break;
105585 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
105586 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
105625 pRight = sqlite3Expr(db, TK_ID, zName);
105630 pLeft = sqlite3Expr(db, TK_ID, zTabName);
105633 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
105637 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
105650 pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
105653 pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s",
105659 sqlite3DbFree(db, zToFree);
105671 sqlite3ExprListDelete(db, pEList);
105675 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
105707 ** and/or pParse->db->mallocFailed.
105801 sqlite3 *db;
105803 db = pParse->db;
105804 if( db->mallocFailed ) return;
105807 if( pParse->nErr || db->mallocFailed ) return;
105809 if( pParse->nErr || db->mallocFailed ) return;
105915 pColl = pParse->db->pDfltColl;
105967 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
106013 sqlite3 *db; /* The database connection */
106020 db = pParse->db;
106021 if( p==0 || db->mallocFailed || pParse->nErr ){
106038 sqlite3ExprListDelete(db, p->pOrderBy);
106047 if( pParse->nErr || db->mallocFailed ){
106109 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
106160 if( /*pParse->nErr ||*/ db->mallocFailed ){
106205 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
106374 if( db->mallocFailed ) goto select_end;
106502 if( orderByGrp && OptimizationEnabled(db, SQLITE_GroupByOrder)
106626 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
106707 pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
106709 if( pMinMax && !db->mallocFailed ){
106722 sqlite3ExprListDelete(db, pDel);
106740 sqlite3ExprListDelete(db, pDel);
106779 sqlite3DbFree(db, sAggInfo.aCol);
106780 sqlite3DbFree(db, sAggInfo.aFunc);
106998 sqlite3 *db, /* The database on which the SQL executes */
107020 db->errCode = SQLITE_NOMEM;
107024 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
107036 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
107049 db->errCode = SQLITE_NOMEM;
107097 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
107102 sqlite3ExprDelete(db, pTmp->pWhere);
107103 sqlite3ExprListDelete(db, pTmp->pExprList);
107104 sqlite3SelectDelete(db, pTmp->pSelect);
107105 sqlite3IdListDelete(db, pTmp->pIdList);
107107 sqlite3DbFree(db, pTmp);
107126 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
107135 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
107173 sqlite3 *db = pParse->db; /* The database connection */
107175 Token *pName; /* The unqualified db name */
107176 DbFixer sFix; /* State vector for the DB fixer */
107192 /* Figure out the db that the trigger will be created in */
107198 if( !pTableName || db->mallocFailed ){
107210 if( db->init.busy && iDb!=1 ){
107211 sqlite3DbFree(db, pTableName->a[0].zDatabase);
107221 if( db->init.busy==0 && pName2->n==0 && pTab
107222 && pTab->pSchema==db->aDb[1].pSchema ){
107227 if( db->mallocFailed ) goto trigger_cleanup;
107236 if( db->init.iDb==1 ){
107245 db->init.orphanTrigger = 1;
107256 zName = sqlite3NameFromToken(db, pName);
107260 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
107261 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
107266 assert( !db->init.busy );
107292 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107297 const char *zDb = db->aDb[iTabDb].zName;
107298 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
107319 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
107323 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
107324 pTrigger->pSchema = db->aDb[iDb].pSchema;
107328 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
107329 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
107334 sqlite3DbFree(db, zName);
107335 sqlite3SrcListDelete(db, pTableName);
107336 sqlite3IdListDelete(db, pColumns);
107337 sqlite3ExprDelete(db, pWhen);
107339 sqlite3DeleteTrigger(db, pTrigger);
107356 sqlite3 *db = pParse->db; /* The database */
107364 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
107382 if( !db->init.busy ){
107390 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
107393 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
107395 sqlite3DbFree(db, z);
107398 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
107401 if( db->init.busy ){
107403 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
107404 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
107407 db->mallocFailed = 1;
107419 sqlite3DeleteTrigger(db, pTrig);
107421 sqlite3DeleteTriggerStep(db, pStepList);
107431 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
107432 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
107434 sqlite3SelectDelete(db, pSelect);
107447 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
107450 sqlite3 *db, /* Database connection */
107456 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
107475 sqlite3 *db, /* The database connection */
107483 assert(pSelect != 0 || db->mallocFailed);
107485 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
107487 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
107491 sqlite3IdListDelete(db, pColumn);
107493 sqlite3SelectDelete(db, pSelect);
107504 sqlite3 *db, /* The database connection */
107512 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
107514 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
107515 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
107518 sqlite3ExprListDelete(db, pEList);
107519 sqlite3ExprDelete(db, pWhere);
107529 sqlite3 *db, /* Database connection */
107535 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
107537 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
107540 sqlite3ExprDelete(db, pWhere);
107547 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
107549 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
107550 sqlite3DbFree(db, pTrigger->zName);
107551 sqlite3DbFree(db, pTrigger->table);
107552 sqlite3ExprDelete(db, pTrigger->pWhen);
107553 sqlite3IdListDelete(db, pTrigger->pColumns);
107554 sqlite3DbFree(db, pTrigger);
107571 sqlite3 *db = pParse->db;
107573 if( db->mallocFailed ) goto drop_trigger_cleanup;
107582 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
107583 for(i=OMIT_TEMPDB; i<db->nDb; i++){
107585 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
107586 assert( sqlite3SchemaMutexHeld(db, j, 0) );
107587 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
107602 sqlite3SrcListDelete(db, pName);
107621 sqlite3 *db = pParse->db;
107624 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
107625 assert( iDb>=0 && iDb<db->nDb );
107632 const char *zDb = db->aDb[iDb].zName;
107677 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
107681 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
107682 pHash = &(db->aDb[iDb].pSchema->trigHash);
107691 sqlite3DeleteTrigger(db, pTrigger);
107692 db->flags |= SQLITE_InternChanges;
107731 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
107763 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
107767 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
107769 sqlite3 *db = pParse->db;
107770 assert( iDb<pParse->db->nDb );
107771 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
107788 sqlite3 *db = pParse->db;
107814 sqlite3ExprListDup(db, pStep->pExprList, 0),
107815 sqlite3ExprDup(db, pStep->pWhere, 0),
107823 sqlite3SelectDup(db, pStep->pSelect, 0),
107824 sqlite3IdListDup(db, pStep->pIdList),
107832 sqlite3ExprDup(db, pStep->pWhere, 0)
107838 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
107841 sqlite3SelectDelete(db, pSelect);
107883 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
107898 sqlite3 *db = pParse->db; /* Database handle */
107913 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
107917 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
107927 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
107931 pSubParse->db = db;
107950 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
107958 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
107960 && db->mallocFailed==0
107965 sqlite3ExprDelete(db, pWhen);
107979 if( db->mallocFailed==0 ){
107994 sqlite3StackFree(db, pSubParse);
108050 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
108055 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
108136 || p->pSchema==pParse->db->aDb[1].pSchema );
108311 sqlite3 *db; /* The database structure */
108349 db = pParse->db;
108350 if( pParse->nErr || db->mallocFailed ){
108359 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
108404 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
108456 db->aDb[iDb].zName);
108605 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
108818 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
108860 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
108868 sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
108869 sqlite3SrcListDelete(db, pTabList);
108870 sqlite3ExprListDelete(db, pChanges);
108871 sqlite3ExprDelete(db, pWhere);
108922 sqlite3 *db = pParse->db; /* Database connection */
108923 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
108929 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));
108932 sqlite3ExprDup(db, pRowid, 0));
108937 pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);
108939 pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
108976 sqlite3SelectDelete(db, pSelect);
109004 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
109008 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
109014 ** Execute zSql on database db. Return an error code.
109016 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
109022 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
109023 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
109024 return sqlite3_errcode(db);
109027 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
109028 return vacuumFinalize(db, pStmt, pzErrMsg);
109032 ** Execute zSql on database db. The statement returns exactly
109035 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
109039 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
109043 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
109045 vacuumFinalize(db, pStmt, pzErrMsg);
109050 return vacuumFinalize(db, pStmt, pzErrMsg);
109095 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
109100 int saved_flags; /* Saved value of the db->flags */
109101 int saved_nChange; /* Saved value of db->nChange */
109102 int saved_nTotalChange; /* Saved value of db->nTotalChange */
109103 db->xTrace */
109104 Db *pDb = 0; /* Database to detach at end of vacuum */
109109 if( !db->autoCommit ){
109110 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
109113 if( db->nVdbeActive>1 ){
109114 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
109121 saved_flags = db->flags;
109122 saved_nChange = db->nChange;
109123 saved_nTotalChange = db->nTotalChange;
109124 saved_xTrace = db->xTrace;
109125 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
109126 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
109127 db->xTrace = 0;
109129 pMain = db->aDb[0].pBt;
109146 nDb = db->nDb;
109147 if( sqlite3TempInMemory(db) ){
109152 rc = execSql(db, pzErrMsg, zSql);
109153 if( db->nDb>nDb ){
109154 pDb = &db->aDb[db->nDb-1];
109158 pTemp = db->aDb[db->nDb-1].pBt;
109170 if( db->nextPagesize ){
109174 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
109175 if( nKey ) db->nextPagesize = 0;
109179 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
109186 rc = execSql(db, pzErrMsg, "BEGIN;");
109194 db->nextPagesize = 0;
109198 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
109199 || NEVER(db->mallocFailed)
109206 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
109213 rc = execExecSql(db, pzErrMsg,
109219 rc = execExecSql(db, pzErrMsg,
109223 rc = execExecSql(db, pzErrMsg,
109232 rc = execExecSql(db, pzErrMsg,
109243 rc = execExecSql(db, pzErrMsg,
109248 rc = execExecSql(db, pzErrMsg,
109261 rc = execSql(db, pzErrMsg,
109319 /* Restore the original value of db->flags */
109320 db->flags = saved_flags;
109321 db->nChange = saved_nChange;
109322 db->nTotalChange = saved_nTotalChange;
109323 db->xTrace = saved_xTrace;
109333 db->autoCommit = 1;
109341 /* This both clears the schemas and reduces the size of the db->aDb[]
109343 sqlite3ResetAllSchemasOfConnection(db);
109385 sqlite3 *db, /* Database in which module is registered */
109394 sqlite3_mutex_enter(db->mutex);
109396 if( sqlite3HashFind(&db->aModule, zName, nName) ){
109400 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
109409 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,nName,(void*)pMod);
109412 db->mallocFailed = 1;
109413 sqlite3DbFree(db, pDel);
109417 rc = sqlite3ApiExit(db, rc);
109420 sqlite3_mutex_leave(db->mutex);
109429 sqlite3 *db, /* Database in which module is registered */
109434 return createModule(db, zName, pModule, pAux, 0);
109441 sqlite3 *db, /* Database in which module is registered */
109447 return createModule(db, zName, pModule, pAux, xDestroy);
109465 ** Return a pointer to the VTable object used by connection db to access
109468 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
109471 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
109480 sqlite3 *db = pVTab->db;
109482 assert( db );
109484 assert( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ZOMBIE );
109492 sqlite3DbFree(db, pVTab);
109500 ** Except, if argument db is not NULL, then the entry associated with
109501 ** connection db is left in the p->pVTable list.
109503 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
109514 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
109517 sqlite3 *db2 = pVTable->db;
109520 if( db2==db ){
109531 assert( !db || pRet );
109537 ** for table *p associated with database connection db from the linked
109539 ** used when closing database connection db to free all of its VTable
109543 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){
109547 assert( sqlite3BtreeHoldsAllMutexes(db) );
109548 assert( sqlite3_mutex_held(db->mutex) );
109551 if( (*ppVTab)->db==db ){
109565 ** shared b-tree databases opened using connection db are held by the
109581 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
109582 VTable *p = db->pDisconnect;
109583 db->pDisconnect = 0;
109585 assert( sqlite3BtreeHoldsAllMutexes(db) );
109586 assert( sqlite3_mutex_held(db->mutex) );
109589 sqlite3ExpirePreparedStatements(db);
109607 ** connection db is decremented immediately (which may lead to the
109612 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
109613 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
109617 if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
109619 sqlite3DbFree(db, p->azModuleArg);
109629 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
109633 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
109637 sqlite3DbFree(db, pTable->azModuleArg[j]);
109639 sqlite3DbFree(db, zArg);
109640 sqlite3DbFree(db, pTable->azModuleArg);
109663 sqlite3 *db; /* Database connection */
109670 db = pParse->db;
109671 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
109676 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
109677 addModuleArgument(db, pTable, 0);
109678 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
109689 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
109703 sqlite3 *db = pParse->db;
109704 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
109714 sqlite3 *db = pParse->db; /* The database connection */
109727 if( !db->init.busy ){
109737 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
109747 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
109752 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
109758 sqlite3DbFree(db, zStmt);
109763 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
109779 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
109782 db->mallocFailed = 1;
109821 sqlite3 *db,
109833 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
109840 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
109842 sqlite3DbFree(db, zModuleName);
109845 pVTable->db = db;
109848 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
109849 pTab->azModuleArg[1] = db->aDb[iDb].zName;
109852 assert( &db->pVtabCtx );
109856 pPriorCtx = db->pVtabCtx;
109857 db->pVtabCtx = &sCtx;
109858 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
109859 db->pVtabCtx = pPriorCtx;
109860 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
109864 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
109866 *pzErr = sqlite3MPrintf(db, "%s", zErr);
109869 sqlite3DbFree(db, pVTable);
109877 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
109922 sqlite3DbFree(db, zModuleName);
109934 sqlite3 *db = pParse->db;
109940 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
109946 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
109954 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
109958 sqlite3DbFree(db, zErr);
109964 ** Grow the db->aVTrans[] array so that there is room for at least one
109967 static int growVTrans(sqlite3 *db){
109971 if( (db->nVTrans%ARRAY_INCR)==0 ){
109973 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
109974 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
109978 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
109979 db->aVTrans = aVTrans;
109989 static void addToVTrans(sqlite3 *db, VTable *pVTab){
109991 db->aVTrans[db->nVTrans++] = pVTab;
110001 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
110003 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
110009 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
110014 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
110021 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
110024 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
110029 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
110030 rc = growVTrans(db);
110032 addToVTrans(db, sqlite3GetVTable(db, pTab));
110044 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
110051 sqlite3_mutex_enter(db->mutex);
110052 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
110053 sqlite3Error(db
110054 sqlite3_mutex_leave(db->mutex);
110059 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
110064 pParse->db = db;
110069 && !db->mallocFailed
110079 db->pVtabCtx->pTab = 0;
110081 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
110082 sqlite3DbFree(db, zErr);
110090 sqlite3DeleteTable(db, pParse->pNewTable);
110092 sqlite3StackFree(db, pParse);
110096 rc = sqlite3ApiExit(db, rc);
110097 sqlite3_mutex_leave(db->mutex);
110108 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
110112 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
110114 VTable *p = vtabDisconnectAll(db, pTab);
110139 static void callFinaliser(sqlite3 *db, int offset){
110141 if( db->aVTrans ){
110142 for(i=0; i<db->nVTrans; i++){
110143 VTable *pVTab = db->aVTrans[i];
110153 sqlite3DbFree(db, db->aVTrans);
110154 db->nVTrans = 0;
110155 db->aVTrans = 0;
110166 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *p){
110169 VTable **aVTrans = db->aVTrans;
110171 db->aVTrans = 0;
110172 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
110180 db->aVTrans = aVTrans;
110188 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
110189 callFinaliser(db, offsetof(sqlite3_module,xRollback));
110197 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
110198 callFinaliser(db, offsetof(sqlite3_module,xCommit));
110210 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
110214 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
110219 if( sqlite3VtabInSync(db) ){
110231 for(i=0; i<db->nVTrans; i++){
110232 if( db->aVTrans[i]==pVTab ){
110239 rc = growVTrans(db);
110243 addToVTrans(db, pVTab);
110265 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
110270 if( db->aVTrans ){
110272 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
110273 VTable *pVTab = db->aVTrans[i];
110312 sqlite3 *db, /* Database connection for reporting malloc problems */
110334 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
110343 zLowerName = sqlite3DbStrDup(db, pDef->zName);
110349 sqlite3DbFree(db, zLowerName);
110357 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
110392 pToplevel->db->mallocFailed = 1;
110403 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
110409 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
110410 return (int)aMap[db->vtabOnConflict-1];
110418 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
110422 sqlite3_mutex_enter(db->mutex);
110427 VtabCtx *p = db->pVtabCtx;
110442 if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0);
110443 sqlite3_mutex_leave(db->mutex);
110733 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
111064 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
111066 sqlite3DbFree(db, p);
111072 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
111074 sqlite3DbFree(db, p);
111084 sqlite3 *db = pWC->pWInfo->pParse->db;
111087 sqlite3ExprDelete(db, a->pExpr);
111090 whereOrInfoDelete(db, a->u.pOrInfo);
111092 whereAndInfoDelete(db, a->u.pAndInfo);
111096 sqlite3DbFree(db, pWC->a);
111106 ** the db->mallocFailed flag so that higher-level functions can detect it.
111125 sqlite3 *db = pWC->pWInfo->pParse->db;
111126 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
111129 sqlite3ExprDelete(db, p);
111136 sqlite3DbFree(db, pOld);
111138 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
111402 if( pColl==0 ) pColl = pParse->db->pDfltColl;
111563 sqlite3 *db = pParse->db; /* Database connection */
111567 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
111607 pPrefix = sqlite3Expr(db, TK_STRING, z);
111762 sqlite3 *db = pParse->db; /* Database connection */
111779 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
111786 if( db->mallocFailed ) return;
111799 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
111813 testcase( db->mallocFailed );
111814 if( !db->mallocFailed ){
111959 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
111964 pDup = sqlite3ExprDup(db, pLeft, 0);
111978 sqlite3ExprListDelete(db, pList);
112021 sqlite3 *db = pParse->db; /* Database connection */
112023 if( db->mallocFailed ){
112070 pDup = sqlite3ExprDup(db, pExpr, 0);
112071 if( db->mallocFailed ){
112072 sqlite3ExprDelete(db, pDup);
112084 && OptimizationEnabled(db, SQLITE_Transitive)
112130 sqlite3ExprDup(db, pExpr->pLeft, 0),
112131 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
112177 pStr2 = sqlite3ExprDup(db, pStr1, 0);
112178 if( !db->mallocFailed ){
112196 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
112204 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
112241 0, sqlite3ExprDup(db, pRight, 0), 0);
112272 && OptimizationEnabled(db, SQLITE_Stat3)
112280 sqlite3ExprDup(db, pLeft, 0),
112540 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
112572 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
112692 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
112765 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
112775 pParse->db->mallocFailed = 1;
112846 || pParse->db->mallocFailed );
112852 || pParse->db->mallocFailed );
112855 || pParse->db->mallocFailed );
112960 sqlite3 *db = pParse->db;
112986 rc = sqlite3Stat4Column(db, p->aSample[i].p, p->aSample[i].n, nEq, &pVal);
113081 && OptimizationEnabled(pParse->db, SQLITE_Stat3)
113367 assert( pParse->db->mallocFailed );
113455 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
113554 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
113556 pParse->db->mallocFailed = 1;
113660 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
113673 txt.db = db;
113720 sqlite3 *db = pParse->db; /* Database handle */
113735 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
113737 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
113739 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
113743 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
113750 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
113761 zMsg = sqlite3MAppendf(db, zMsg, zFmt, zMsg, pIdx->zName, zWhere);
113762 sqlite3DbFree(db, zWhere);
113764 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
113767 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
113769 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
113771 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
113773 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
113778 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
113782 zMsg = sqlite3MAppendf(db, zMsg, "%s", zMsg);
113810 sqlite3 *db; /* Database connection */
113821 db = pParse->db;
114228 sqlite3DbFree(db, zStartAff);
114360 pOrTab = sqlite3StackAllocRaw(db,
114424 pExpr = sqlite3ExprDup(db, pExpr, 0);
114425 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
114451 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
114555 sqlite3ExprDelete(db, pAndExpr);
114561 if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
114634 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
114639 sqlite3StackFree(db, pEAlt);
114760 static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){
114767 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
114769 sqlite3DbFree(db, p->u.btree.pIndex);
114778 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
114779 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
114780 whereLoopClearUnion(db, p);
114787 static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
114791 paNew = sqlite3DbMallocRaw(db, sizeof(p->aLTerm[0])*n);
114794 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
114803 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
114804 whereLoopClearUnion(db, pTo);
114805 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
114822 db, WhereLoop *p){
114823 whereLoopClear(db, p);
114824 sqlite3DbFree(db, p);
114830 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
114836 whereLoopDelete(db, p);
114838 sqlite3DbFree(db, pWInfo);
115024 sqlite3 *db = pWInfo->pParse->db;
115080 *ppPrev = p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
115102 whereLoopDelete(db, pToDel);
115105 whereLoopXfer(db, p, pTemplate);
115129 if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
115178 sqlite3 *db = pParse->db; /* Database connection malloc context */
115195 if( db->mallocFailed ) return SQLITE_NOMEM;
115237 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
115267 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
115343 && OptimizationEnabled(db, SQLITE_Stat3)
115577 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
115665 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan)
115714 sqlite3 *db;
115730 db = pParse->db;
115745 if( whereLoopResize(db, pNew, nConstraint) ){
115746 sqlite3DbFree(db, pIdxInfo);
115864 sqlite3DbFree(db, pIdxInfo);
115988 sqlite3 *db = pWInfo->pParse->db;
116013 if( rc || db->mallocFailed ) break;
116015 whereLoopClear(db, pNew);
116063 sqlite3 *db = pWInfo->pParse->db; /* Database connection */
116092 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
116126 if( !pColl ) pColl = db->pDfltColl;
116129 db->pDfltColl;
116210 if( !pColl ) pColl = db->pDfltColl;
116372 sqlite3 *db; /* The database connection */
116391 db = pParse->db;
116414 pSpace = sqlite3DbMallocRaw(db, nSpace);
116639 sqlite3DbFree(db, pSpace);
116694 sqlite3DbFree(db, pSpace);
116891 sqlite3 *db; /* Database connection */
116896 db = pParse->db;
116906 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
116934 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
116935 if( db->mallocFailed ){
116936 sqlite3DbFree(db, pWInfo);
117022 if( db->mallocFailed ){
117075 if( db->mallocFailed ) goto whereBeginError;
117078 if( db->mallocFailed ) goto whereBeginError;
117081 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
117084 if( pParse->nErr || NEVER(db->mallocFailed) ){
117117 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
117173 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117180 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
117251 if( db->mallocFailed ) goto whereBeginError;
117264 if( db->mallocFailed ) goto whereBeginError;
117281 whereInfoFree(db, pWInfo);
117297 sqlite3 *db = pParse->db;
117328 sqlite3DbFree(db, pLevel->u.in.aInLoop);
117377 if( pTabItem->viaCoroutine && !db->mallocFailed ){
117434 if( pIdx && !db->mallocFailed ){
117464 whereInfoFree(db, pWInfo);
117581 sqlite3 *db = pParse->db;
117582 if( db->mallocFailed==0 && pY->op==TK_NULL ){
117584 sqlite3ExprDelete(db, pA->pRight);
118853 sqlite3SelectDelete(pParse->db, (yypminor->yy3));
118859 sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
118874 sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
118882 sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
118888 sqlite3WithDelete(pParse->db, (yypminor->yy59));
118899 sqlite3ExprDelete(pParse->db, (yypminor->yy132));
118906 sqlite3IdListDelete(pParse->db, (yypminor->yy408));
118912 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy473));
118917 sqlite3IdListDelete(pParse->db, (yypminor->yy378).b);
119597 pParse->db->lookaside.bEnabled = 0;
119630 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
119844 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
119859 mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
119865 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
119889 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
119946 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
119962 {yygotominor.yy65 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy65));}
120005 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy65);
120019 {yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
120140 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
120143 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
120213 if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
120312 sqlite3ExprListDelete(pParse->db, pList);
120331 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy346.pExpr);
120351 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
120365 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
120381 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
120395 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
120404 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
120411 sqlite3SrcListDelete(pParse->db, pSrc);
120426 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
120439 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
120440 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
120467 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
120598 { yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
120601 {yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
120604 {yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
120607 {yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
120674 pParse->db->lookaside.bEnabled = 0;
121674 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
121675 sqlite3 *db = pParse->db; /* The database connection */
121679 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
121680 if( db->nVdbeActive==0 ){
121681 db->u1.isInterrupted = 0;
121689 db->mallocFailed = 1;
121697 enableLookaside = db->lookaside.bEnabled;
121698 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
121699 while( !db->mallocFailed && zSql[i]!=0 ){
121710 if( db->u1.isInterrupted ){
121718 sqlite3DbFree(db, *pzErrMsg);
121719 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
121752 db->lookaside.bEnabled = enableLookaside;
121753 if( db->mallocFailed ){
121757 sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc));
121772 sqlite3DbFree(db, pParse->aTableLock);
121786 sqlite3DeleteTable(db, pParse->pNewTable);
121789 if( pParse->bFreeWith ) sqlite3WithDelete(db, pParse->pWith);
121790 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
121791 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
121792 sqlite3DbFree(db, pParse->azVar);
121796 sqlite3DbFree(db, p);
121801 sqlite3DeleteTable(db, p);
122136 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
122168 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
122200 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
122720 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
122722 if( db->lookaside.nOut ){
122729 if( db->lookaside.bMalloced ){
122730 sqlite3_free(db->lookaside.pStart);
122749 db->lookaside.pStart = pStart;
122750 db->lookaside.pFree = 0;
122751 db->lookaside.sz = (u16)sz;
122758 p->pNext = db->lookaside.pFree;
122759 db->lookaside.pFree = p;
122762 db->lookaside.pEnd = p;
122763 db->lookaside.bEnabled = 1;
122764 db->lookaside.bMalloced = pBuf==0 ?1:0;
122766 db->lookaside.pStart = db;
122767 db->lookaside.pEnd = db;
122768 db->lookaside.bEnabled = 0;
122769 db->lookaside.bMalloced = 0;
122777 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
122778 return db->mutex;
122785 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
122787 sqlite3_mutex_enter(db->mutex);
122788 sqlite3BtreeEnterAll(db);
122789 for(i=0; i<db->nDb; i++){
122790 Btree *pBt = db->aDb[i].pBt;
122796 sqlite3BtreeLeaveAll(db);
122797 sqlite3_mutex_leave(db->mutex);
122804 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
122813 rc = setupLookaside(db, pBuf, sz, cnt);
122830 int oldFlags = db->flags;
122832 db->flags |= aFlagOp[i].mask;
122834 db->flags &= ~aFlagOp[i].mask;
122836 if( oldFlags!=db->flags ){
122837 sqlite3ExpirePreparedStatements(db);
122840 *pRes = (db->flags & aFlagOp[i].mask)!=0;
122916 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
122917 return db->lastRowid;
122923 SQLITE_API int sqlite3_changes(sqlite3 *db){
122924 return db->nChange;
122930 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
122931 return db->nTotalChange;
122939 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
122940 while( db->pSavepoint ){
122941 Savepoint *pTmp = db->pSavepoint;
122942 db->pSavepoint = pTmp->pNext;
122943 sqlite3DbFree(db, pTmp);
122945 db->nSavepoint = 0;
122946 db->nStatement = 0;
122947 db->isTransactionSavepoint = 0;
122956 static void functionDestroy(sqlite3 *db, FuncDef *p){
122962 sqlite3DbFree(db, pDestructor);
122969 ** db. This is called when db is being closed.
122971 static void disconnectAllVtab(sqlite3 *db){
122974 sqlite3BtreeEnterAll(db);
122975 for(i=0; i<db->nDb; i++){
122976 Schema *pSchema = db->aDb[i].pSchema;
122977 if( db->aDb[i].pSchema ){
122981 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
122985 sqlite3VtabUnlockList(db);
122986 sqlite3BtreeLeaveAll(db);
122988 UNUSED_PARAMETER(db);
122993 ** Return TRUE if database connection db has unfinalized prepared
122996 static int connectionIsBusy(sqlite3 *db){
122998 assert( sqlite3_mutex_held(db->mutex) );
122999 if( db->pVdbe ) return 1;
123000 for(j=0; j<db->nDb; j++){
123001 Btree *pBt = db->aDb[j].pBt;
123010 static int sqlite3Close(sqlite3 *db, int forceZombie){
123011 if( !db ){
123016 if( !sqlite3SafetyCheckSickOrOk(db) ){
123019 sqlite3_mutex_enter(db->mutex);
123022 disconnectAllVtab(db);
123026 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
123031 sqlite3VtabRollback(db);
123036 if( !forceZombie && connectionIsBusy(db) ){
123037 sqlite3Error(db, SQLITE_BUSY, "unable to close due to unfinalized "
123039 sqlite3_mutex_leave(db->mutex);
123046 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
123052 db->magic = SQLITE_MAGIC_ZOMBIE;
123053 sqlite3LeaveMutexAndCloseZombie(db);
123066 SQLITE_API int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
123067 SQLITE_API int sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
123071 ** Close the mutex on database connection db.
123073 ** Furthermore, if database connection db is a zombie (meaning that there
123074 ** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
123078 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
123086 if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
123087 sqlite3_mutex_leave(db->mutex);
123101 sqlite3RollbackAll(db, SQLITE_OK);
123104 sqlite3CloseSavepoints(db);
123107 for(j=0; j<db->nDb; j++){
123108 struct Db *pDb = &db->aDb[j];
123118 if( db->aDb[1].pSchema ){
123119 sqlite3SchemaClear(db->aDb[1].pSchema);
123121 sqlite3VtabUnlockList(db);
123124 sqlite3CollapseDatabaseArray(db);
123125 assert( db->nDb<=2 );
123126 assert( db->aDb==db->aDbStatic );
123131 sqlite3ConnectionClosed(db);
123133 for(j=0; j<ArraySize(db->aFunc.a); j++){
123135 for(p=db->aFunc.a[j]; p; p=pHash){
123138 functionDestroy(db, p);
123140 sqlite3DbFree(db, p);
123145 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
123153 sqlite3DbFree(db, pColl);
123155 sqlite3HashClear(&db->aCollSeq);
123157 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
123162 sqlite3DbFree(db, pMod);
123164 sqlite3HashClear(&db->aModule);
123167 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
123168 sqlite3ValueFree(db->pErr);
123169 sqlite3CloseExtensions(db);
123171 db->magic = SQLITE_MAGIC_ERROR;
123179 sqlite3DbFree(db, db->aDb[1].pSchema);
123180 sqlite3_mutex_leave(db->mutex);
123181 db->magic = SQLITE_MAGIC_CLOSED;
123182 sqlite3_mutex_free(db->mutex);
123183 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
123184 if( db->lookaside.bMalloced ){
123185 sqlite3_free(db->lookaside.pStart);
123187 sqlite3_free(db);
123196 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
123199 assert( sqlite3_mutex_held(db->mutex) );
123208 sqlite3BtreeEnterAll(db);
123210 for(i=0; i<db->nDb; i++){
123211 Btree *p = db->aDb[i].pBt;
123219 sqlite3VtabRollback(db);
123222 if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
123223 sqlite3ExpirePreparedStatements(db);
123224 sqlite3ResetAllSchemasOfConnection(db);
123226 sqlite3BtreeLeaveAll(db);
123229 db->nDeferredCons = 0;
123230 db->nDeferredImmCons = 0;
123231 db->flags &= ~SQLITE_DeferFKs;
123234 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
123235 db->xRollbackCallback(db->pRollbackArg);
123415 sqlite3 *db = (sqlite3 *)ptr;
123416 int timeout = db->busyTimeout;
123431 sqlite3OsSleep(db->pVfs, delay*1000);
123434 sqlite3 *db = (sqlite3 *)ptr;
123439 sqlite3OsSleep(db->pVfs, 1000000);
123468 sqlite3 *db,
123472 sqlite3_mutex_enter(db->mutex);
123473 db->busyHandler.xFunc = xBusy;
123474 db->busyHandler.pArg = pArg;
123475 db->busyHandler.nBusy = 0;
123476 db->busyTimeout = 0;
123477 sqlite3_mutex_leave(db->mutex);
123488 sqlite3 *db,
123493 sqlite3_mutex_enter(db->mutex);
123495 db->xProgress = xProgress;
123496 db->nProgressOps = (unsigned)nOps;
123497 db->pProgressArg = pArg;
123499 db->xProgress = 0;
123500 db->nProgressOps = 0;
123501 db->pProgressArg = 0;
123503 sqlite3_mutex_leave(db->mutex);
123512 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
123514 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
123515 db->busyTimeout = ms;
123517 sqlite3_busy_handler(db, 0, 0);
123525 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
123526 db->u1.isInterrupted = 1;
123537 sqlite3 *db,
123551 assert( sqlite3_mutex_held(db->mutex) );
123577 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
123580 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
123597 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
123599 if( db->nVdbeActive ){
123600 sqlite3Error(db, SQLITE_BUSY,
123602 assert( !db->mallocFailed );
123605 sqlite3ExpirePreparedStatements(db);
123609 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
123610 assert(p || db->mallocFailed);
123617 functionDestroy(db, p);
123637 sqlite3 *db,
123646 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
123651 sqlite3 *db,
123663 sqlite3_mutex_enter(db->mutex);
123665 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
123673 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
123677 sqlite3DbFree(db, pArg);
123681 rc = sqlite3ApiExit(db, rc);
123682 sqlite3_mutex_leave(db->mutex);
123688 sqlite3 *db,
123699 sqlite3_mutex_enter(db->mutex);
123700 assert( !db->mallocFailed );
123701 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
123702 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
123703 sqlite3DbFree(db, zFunc8);
123704 rc = sqlite3ApiExit(db, rc);
123705 sqlite3_mutex_leave(db->mutex);
123724 sqlite3 *db,
123730 sqlite3_mutex_enter(db->mutex);
123731 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
123732 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
123735 rc = sqlite3ApiExit(db, rc);
123736 sqlite3_mutex_leave(db->mutex);
123749 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
123751 sqlite3_mutex_enter(db->mutex);
123752 pOld = db->pTraceArg;
123753 db->xTrace = xTrace;
123754 db->pTraceArg = pArg;
123755 sqlite3_mutex_leave(db->mutex);
123767 sqlite3 *db,
123772 sqlite3_mutex_enter(db->mutex);
123773 pOld = db->pProfileArg;
123774 db->xProfile = xProfile;
123775 db->pProfileArg = pArg;
123776 sqlite3_mutex_leave(db->mutex);
123787 sqlite3 *db, /* Attach the hook to this database */
123792 sqlite3_mutex_enter(db->mutex);
123793 pOld = db->pCommitArg;
123794 db->xCommitCallback = xCallback;
123795 db->pCommitArg = pArg;
123796 sqlite3_mutex_leave(db->mutex);
123805 sqlite3 *db, /* Attach the hook to this database */
123810 sqlite3_mutex_enter(db->mutex);
123811 pRet = db->pUpdateArg;
123812 db->xUpdateCallback = xCallback;
123813 db->pUpdateArg = pArg;
123814 sqlite3_mutex_leave(db->mutex);
123823 sqlite3 *db, /* Attach the hook to this database */
123828 sqlite3_mutex_enter(db->mutex);
123829 pRet = db->pRollbackArg;
123830 db->xRollbackCallback = xCallback;
123831 db->pRollbackArg = pArg;
123832 sqlite3_mutex_leave(db->mutex);
123845 sqlite3 *db, /* Connection */
123851 sqlite3_wal_checkpoint(db, zDb);
123869 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
123871 UNUSED_PARAMETER(db);
123875 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
123877 sqlite3_wal_hook(db, 0, 0);
123888 sqlite3 *db, /* Attach the hook to this db handle */
123894 sqlite3_mutex_enter(db->mutex);
123895 pRet = db->pWalArg;
123896 db->xWalCallback = xCallback;
123897 db->pWalArg = pArg;
123898 sqlite3_mutex_leave(db->mutex);
123909 sqlite3 *db, /* Database handle */
123919 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
123932 sqlite3_mutex_enter(db->mutex);
123934 iDb = sqlite3FindDbName(db, zDb);
123938 sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb);
123940 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
123941 sqlite3Error(db, rc, 0);
123943 rc = sqlite3ApiExit(db, rc);
123944 sqlite3_mutex_leave(db->mutex);
123955 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
123956 return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0);
123969 ** The mutex on database handle db should be held by the caller. The mutex
123979 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
123984 assert( sqlite3_mutex_held(db->mutex) );
123988 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
123990 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
124007 ** The value returned depends on the value of db->temp_store (runtime
124012 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
124023 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
124025 return ( db->temp_store==2 );
124028 return ( db->temp_store!=1 );
124042 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
124044 if( !db ){
124047 if( !sqlite3SafetyCheckSickOrOk(db) ){
124050 sqlite3_mutex_enter(db->mutex);
124051 if( db->mallocFailed ){
124054 testcase( db->pErr==0 );
124055 z = (char*)sqlite3_value_text(db->pErr);
124056 assert( !db->mallocFailed );
124058 z = sqlite3ErrStr(db->errCode);
124061 sqlite3_mutex_leave(db->mutex);
124070 SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){
124084 if( !db ){
124087 if( !sqlite3SafetyCheckSickOrOk(db) ){
124090 sqlite3_mutex_enter(db->mutex);
124091 if( db->mallocFailed ){
124094 z = sqlite3_value_text16(db->pErr);
124096 sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode));
124097 z = sqlite3_value_text16(db->pErr);
124100 ** above. If this is the case, then the db->mallocFailed flag needs to
124104 db->mallocFailed = 0;
124106 sqlite3_mutex_leave(db->mutex);
124115 SQLITE_API int sqlite3_errcode(sqlite3 *db){
124116 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
124119 if( !db || db->mallocFailed ){
124122 return db->errCode & db->errMask;
124124 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
124125 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
124128 if( !db || db->mallocFailed ){
124131 return db->errCode;
124144 ** Invalidate all cached KeyInfo objects for database connection "db"
124146 static void invalidateCachedKeyInfo(sqlite3 *db){
124147 Db *pDb; /* A single database */
124153 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
124159 if( pIdx->pKeyInfo && pIdx->pKeyInfo->db==db ){
124170 ** Create a new collating function for database "db". The name is zName
124174 sqlite3* db,
124185 assert( sqlite3_mutex_held(db->mutex) );
124205 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
124207 if( db->nVdbeActive ){
124208 sqlite3Error(db, SQLITE_BUSY,
124212 sqlite3ExpirePreparedStatements(db);
124213 invalidateCachedKeyInfo(db);
124222 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
124236 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
124242 sqlite3Error(db, SQLITE_OK, 0);
124311 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
124338 oldLimit = db->aLimit[limitId];
124343 db->aLimit[limitId] = newLimit;
124592 sqlite3 *db; /* Store allocated handle here */
124661 db = sqlite3MallocZero( sizeof(sqlite3) );
124662 if( db==0 ) goto opendb_out;
124664 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
124665 if( db->mutex==0 ){
124666 sqlite3_free(db);
124667 db = 0;
124671 sqlite3_mutex_enter(db->mutex);
124672 db->errMask = 0xff;
124673 db->nDb = 2;
124674 db->magic = SQLITE_MAGIC_BUSY;
124675 db->aDb = db->aDbStatic;
124677 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
124678 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
124679 db->autoCommit = 1;
124680 db->nextAutovac = -1;
124681 db->szMmap = sqlite3GlobalConfig.szMmap;
124682 db->nextPagesize = 0;
124683 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
124700 sqlite3HashInit(&db->aCollSeq);
124702 sqlite3HashInit(&db->aModule);
124709 createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
124710 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
124711 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
124712 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
124713 if( db->mallocFailed ){
124716 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
124717 assert( db->pDfltColl!=0 );
124720 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
124723 db->openFlags = flags;
124724 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
124726 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
124727 sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
124733 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
124739 sqlite3Error(db, rc, 0);
124742 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
124743 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
124749 db->aDb[0].zName = "main";
124750 db->aDb[0].safety_level = 3;
124751 db->aDb[1].zName = "temp";
124752 db->aDb[1].safety_level = 1;
124754 db->magic = SQLITE_MAGIC_OPEN;
124755 if( db->mallocFailed ){
124763 sqlite3Error(db, SQLITE_OK, 0);
124764 sqlite3RegisterBuiltinFunctions(db);
124769 rc = sqlite3_errcode(db);
124771 sqlite3AutoLoadExtensions(db);
124772 rc = sqlite3_errcode(db);
124779 if( !db->mallocFailed ){
124781 rc = sqlite3Fts1Init(db);
124786 if( !db->mallocFailed && rc==SQLITE_OK ){
124788 rc = sqlite3Fts2Init(db);
124793 if( !db->mallocFailed && rc==SQLITE_OK ){
124794 rc = sqlite3Fts3Init(db);
124799 if( !db->mallocFailed && rc==SQLITE_OK ){
124800 rc = sqlite3IcuInit(db);
124805 if( !db->mallocFailed && rc==SQLITE_OK){
124806 rc = sqlite3RtreeInit(db);
124815 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
124816 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
124820 if( rc ) sqlite3Error(db, rc, 0);
124823 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
124826 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
124830 if( db ){
124831 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
124832 sqlite3_mutex_leave(db->mutex);
124834 rc = sqlite3_errcode(db);
124835 assert( db!=0 || rc==SQLITE_NOMEM );
124837 sqlite3_close(db);
124838 db = 0;
124840 db->magic = SQLITE_MAGIC_SICK;
124842 *ppDb = db;
124845 /* Opening a db handle. Fourth parameter is passed 0. */
124847 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
124865 sqlite3 **ppDb, /* OUT: SQLite db handle */
124911 ** Register a new collation sequence with the database handle db.
124914 sqlite3* db,
124921 sqlite3_mutex_enter(db->mutex);
124922 assert( !db->mallocFailed );
124923 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
124924 rc = sqlite3ApiExit(db, rc);
124925 sqlite3_mutex_leave(db->mutex);
124930 ** Register a new collation sequence with the database handle db.
124933 sqlite3* db,
124941 sqlite3_mutex_enter(db->mutex);
124942 assert( !db->mallocFailed );
124943 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
124944 rc = sqlite3ApiExit(db, rc);
124945 sqlite3_mutex_leave(db->mutex);
124951 ** Register a new collation sequence with the database handle db.
124954 sqlite3* db,
124962 sqlite3_mutex_enter(db->mutex);
124963 assert( !db->mallocFailed );
124964 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
124966 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
124967 sqlite3DbFree(db, zName8);
124969 rc = sqlite3ApiExit(db, rc);
124970 sqlite3_mutex_leave(db->mutex);
124977 ** db. Replace any previously installed collation sequence factory.
124980 sqlite3 *db,
124984 sqlite3_mutex_enter(db->mutex);
124985 db->xCollNeeded = xCollNeeded;
124986 db->xCollNeeded16 = 0;
124987 db->pCollNeededArg = pCollNeededArg;
124988 sqlite3_mutex_leave(db->mutex);
124995 ** db. Replace any previously installed collation sequence factory.
124998 sqlite3 *db,
125002 sqlite3_mutex_enter(db->mutex);
125003 db->xCollNeeded = 0;
125004 db->xCollNeeded16 = xCollNeeded16;
125005 db->pCollNeededArg = pCollNeededArg;
125006 sqlite3_mutex_leave(db->mutex);
125027 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
125028 return db->autoCommit;
125083 sqlite3 *db, /* Connection handle */
125106 sqlite3_mutex_enter(db->mutex);
125107 sqlite3BtreeEnterAll(db);
125108 rc = sqlite3Init(db, &zErrMsg);
125114 pTab = sqlite3FindTable(db, zTableName, zDbName);
125164 sqlite3BtreeLeaveAll(db);
125177 sqlite3DbFree(db, zErrMsg);
125178 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
125182 sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
125183 sqlite3DbFree(db, zErrMsg);
125184 rc = sqlite3ApiExit(db, rc);
125185 sqlite3_mutex_leave(db->mutex);
125209 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
125210 sqlite3_mutex_enter(db->mutex);
125211 db->errMask = onoff ? 0xffffffff : 0xff;
125212 sqlite3_mutex_leave(db->mutex);
125219 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
125223 sqlite3_mutex_enter(db->mutex);
125224 pBtree = sqlite3DbNameToBtree(db, zDbName);
125243 sqlite3_mutex_leave(db->mutex);
125429 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
125432 ** connection db.
125435 sqlite3 *db = va_arg(ap, sqlite3*);
125437 sqlite3_mutex_enter(db->mutex);
125438 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
125439 sqlite3_mutex_leave(db->mutex);
125443 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
125453 sqlite3 *db = va_arg(ap, sqlite3*);
125454 db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
125614 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
125616 for(i=0; i<db->nDb; i++){
125617 if( db->aDb[i].pBt
125618 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
125620 return db->aDb[i].pBt;
125630 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
125631 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
125639 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
125640 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
125696 ** 3) If the argument db is not NULL, then none of the entries in the
125698 ** set to db. This is used when closing connection db.
125700 static void checkListProperties(sqlite3 *db){
125713 assert( db==0 || p->pUnlockConnection!=db );
125714 assert( db==0 || p->pBlockingConnection!=db );
125723 ** Remove connection db from the blocked connections list. If connection
125724 ** db is not currently a part of the list, this function is a no-op.
125726 static void removeFromBlockedList(sqlite3 *db){
125730 if( *pp==db ){
125738 ** Add connection db to the blocked connections list. It is assumed
125741 static void addToBlockedList(sqlite3 *db){
125746 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
125749 db->pNextBlocked = *pp;
125750 *pp = db;
125773 ** This is called after connection "db" has attempted some operation
125776 ** cache. pOther is found by looking at db->pBlockingConnection.
125781 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
125788 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
125792 sqlite3 *db,
125798 sqlite3_mutex_enter(db->mutex);
125802 removeFromBlockedList(db);
125803 db->pBlockingConnection = 0;
125804 db->pUnlockConnection = 0;
125805 db->xUnlockNotify = 0;
125806 db->pUnlockArg = 0;
125807 }else if( 0==db->pBlockingConnection ){
125816 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
125820 db->pUnlockConnection = db->pBlockingConnection;
125821 db->xUnlockNotify = xNotify;
125822 db->pUnlockArg = pArg;
125823 removeFromBlockedList(db);
125824 addToBlockedList(db);
125829 assert( !db->mallocFailed );
125830 sqlite3Error(db, rc, (rc?"database is deadlocked":0));
125831 sqlite3_mutex_leave(db->mutex);
125837 ** associated with connection db. The operation will return SQLITE_LOCKED
125841 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
125843 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
125844 addToBlockedList(db);
125846 db->pBlockingConnection = pBlocker;
125852 ** the transaction opened by database db has just finished. Locks held
125853 ** by database connection db have been released.
125859 ** set to db, then set pBlockingConnection=0.
125862 ** set to db, then invoke the configured unlock-notify callback and
125869 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
125885 if( p->pBlockingConnection==db ){
125890 if( p->pUnlockConnection==db ){
125917 ** is returned the transaction on connection db will still be
125968 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
125969 sqlite3ConnectionUnlocked(db);
125971 removeFromBlockedList(db);
125972 checkListProperties(db);
126752 sqlite3 *db; /* The database connection */
127111 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
127112 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
127120 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
127366 sqlite3 *db, /* Database in which to run SQL */
127379 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
127391 sqlite3 *db = p->db; /* Database handle */
127395 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
127397 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
127398 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
127399 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
127400 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
127428 sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
127444 rc = sqlite3_declare_vtab(p->db, zSql);
127457 fts3DbExec(pRc, p->db,
127477 sqlite3 *db = p->db; /* The database connection */
127495 fts3DbExec(&rc, db,
127503 fts3DbExec(&rc, db,
127507 fts3DbExec(&rc, db,
127520 fts3DbExec(&rc, db,
127549 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
127859 sqlite3 *db, /* Database handle */
127860 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
127874 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
127931 sqlite3 *db, /* The SQLite database connection */
128126 rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
128179 p->db = db;
128307 sqlite3 *db, /* Database connection */
128314 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
128317 sqlite3 *db, /* Database connection */
128324 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
128522 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
130024 db, zSql, -1, &pCsr->pStmt, 0);
130164 int mxLevel = 0; /* Maximum relative level value in db */
130190 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
130462 sqlite3 *db = p->db; /* Database connection */
130481 fts3DbExec(&rc, db,
130488 fts3DbExec(&rc, db,
130494 fts3DbExec(&rc, db,
130499 fts3DbExec(&rc, db,
130503 fts3DbExec(&rc, db,
130619 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
130638 rc = sqlite3Fts3InitTerm(db);
130642 rc = sqlite3Fts3InitAux(db);
130674 rc = sqlite3Fts3ExprInitTestInterface(db);
130684 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
130686 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
130687 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
130688 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
130689 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
130690 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
130694 db, "fts1", &fts3Module, (void *)pHash, 0
130698 db, "fts2", &fts3Module, (void *)pHash, 0
130703 db, "fts3", &fts3Module, (void *)pHash, hashDestroy
130707 db, "fts4", &fts3Module, (void *)pHash, 0
130711 rc = sqlite3Fts3InitTok(db, (void *)pHash);
131827 ** the db. In this case the position-list is not populated at all.
132655 sqlite3 *db,
132660 return sqlite3Fts3Init(db);
132724 sqlite3 *db, /* Database connection */
132744 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
132763 rc = sqlite3_declare_vtab(db, FTS3_AUX_SCHEMA);
132774 p->pFts3Tab->db = db;
133181 ** Register the fts3aux module with database connection db. Return SQLITE_OK
133184 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db){
133212 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
134307 sqlite3 *db,
134316 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
134413 sqlite3 *db = sqlite3_context_db_handle(context);
134422 rc = queryTestTokenizer(db,
134486 ** with database connection db.
134488 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
134490 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
134493 rc = sqlite3_create_function(db
135877 sqlite3 *db,
135885 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
135899 sqlite3 *db,
135908 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
135951 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
135958 rc = queryTokenizer(db, "simple", &p2);
135961 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
135964 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
135967 rc = registerTokenizer(db, "nosuchtokenizer", p1);
135969 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
135979 ** Set up SQL objects in database db used to access the contents of
135996 sqlite3 *db,
136007 void *pdb = (void *)db;
136016 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
136019 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
136023 rc = sqlite3_create_function(db, zTest, -1, any, p, testFunc, 0, 0);
136026 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
136434 sqlite3 *db, /* Database connection */
136448 rc = sqlite3_declare_vtab(db, FTS3_TOK_SCHEMA);
136694 ** Register the fts3tok module with database connection db. Return SQLITE_OK
136697 SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){
136725 rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
137064 ** of the oldest level in the db that contains at least ? segments. Or,
137140 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
137741 *piDocid = sqlite3_last_insert_rowid(p->db);
137938 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
138843 ** blocks were written to the db). Otherwise, an SQLite error code is
139059 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
139066 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
140223 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
141360 ** Each input segment is either removed from the db completely (if all of
141898 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
142318 if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
142376 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
142380 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
142383 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
142384 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
144793 sqlite3 *db; /* Host database connection */
145344 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
145438 sqlite3 *db,
145444 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
145451 sqlite3 *db,
145457 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
145512 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
147351 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
147537 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
147605 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
147616 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
147627 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
147676 sqlite3 *db,
147703 pRtree->db = db;
147717 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
147734 rc = rtreeQueryStat1(db, pRtree);
147738 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
147751 ** using database connection db. If successful, the integer value returned
147755 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
147759 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
147786 sqlite3 *db, /* Database handle */
147796 rc = getIntFromStmt(db, zSql, &iPageSize);
147803 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
147810 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
147812 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
147830 sqlite3 *db, /* Database connection */
147856 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
147877 rc = getNodeSize(db, pRtree, isCreate, pzErr);
147884 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
147885 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
147902 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
147903 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
148003 ** Register the r-tree module with database handle db. This creates the
148007 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
148011 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
148013 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
148021 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
148025 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
148087 sqlite3 *db, /* Register SQL function on this connection */
148101 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
148111 sqlite3 *db, /* Register SQL function on this connection */
148126 return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
148136 sqlite3 *db,
148141 return sqlite3RtreeInit(db);
148563 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
148585 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
148595 ** Register the ICU extension functions with database db.
148597 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
148620 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
148629 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
148641 sqlite3 *db,
148646 return sqlite3IcuInit(db);