Home | History | Annotate | Download | only in orig

Lines Matching refs:Db

2479   sqlite3 *db,          /* An open database */
2547 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2575 ** sqlite3_exec(db, zSQL, 0, 0, 0);
3146 ** <tr><td> file:data.db <td>
3147 ** Open the file "data.db" in the current directory.
3148 ** <tr><td> file:/home/fred/data.db<br>
3149 ** file:///home/fred/data.db <br>
3150 ** file://localhost/home/fred/data.db <br> <td>
3151 ** Open the database file "/home/fred/data.db".
3152 ** <tr><td> file://darkstar/home/fred/data.db <td>
3155 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3156 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3160 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3161 ** Open file "data.db" in the current directory for read-only access.
3164 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3165 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3167 ** <tr><td> file:data.db?mode=readonly <td>
3194 sqlite3 **ppDb /* OUT: SQLite db handle */
3198 sqlite3 **ppDb /* OUT: SQLite db handle */
3202 sqlite3 **ppDb, /* OUT: SQLite db handle */
3292 SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
3293 SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
3444 ** The first argument, "db", is a [database connection] obtained from a
3517 sqlite3 *db, /* Database handle */
3524 sqlite3 *db, /* Database handle */
3531 sqlite3 *db, /* Database handle */
3538 sqlite3 *db, /* Database handle */
4443 sqlite3 *db,
4453 sqlite3 *db,
4463 sqlite3 *db,
5056 sqlite3 *db, /* Database to be rekeyed */
5060 sqlite3 *db, /* Database to be rekeyed */
5074 sqlite3 *db, /* Database to be rekeyed */
5078 sqlite3 *db, /* Database to be rekeyed */
5268 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5278 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5599 sqlite3 *db, /* Connection handle */
5646 sqlite3 *db, /* Load the extension into this database connection */
5666 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5683 ** &nbsp; sqlite3 *db,
5954 sqlite3 *db, /* SQLite connection to register module with */
5960 sqlite3 *db, /* SQLite connection to register module with */
7679 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7701 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7772 ** [database connection] db. In this case the
7796 sqlite3 *db, /* Database handle */
7843 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
8061 sqlite3 *db,
8087 sqlite3 *db,
9944 typedef struct Db Db;
10038 sqlite3 *db, /* Associated database connection */
10051 #define BTREE_MEMORY 2 /* This is an in-memory DB */
11528 struct Db {
11568 ** Db.pSchema->flags field.
11576 ** Allowed values for the DB.pSchema->flags field.
11687 Db *aDb; /* All backends */
11713 u8 iDb; /* Which db file is being initialized */
11767 Db aDbStatic[2]; /* Static space for the 2 default backends */
11800 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
11801 #define ENC(db) ((db)->enc)
11863 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
11864 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
11866 #define OptimizationDisabled(db, mask) 0
11867 #define OptimizationEnabled(db, mask) 1
12167 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
12171 sqlite3 *db; /* Database connection associated with this table */
12352 sqlite3 *db; /* The database connection */
12431 int tnum; /* DB Page containing root of this index */
12754 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
13206 sqlite3 *db; /* The main database structure */
13298 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
13331 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
13333 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
13454 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
13470 sqlite3 *db; /* The database being initialized */
14225 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
14238 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
14293 # define sqlite3VtabInSync(db) 0
14300 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
14301 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p);
14302 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*);
14303 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
14304 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
14311 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
14441 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
14442 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
15320 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
15398 int nDbChange; /* Value of db->nChange */
15431 sqlite3 *db; /* The associated database connection */
15576 sqlite3 *db; /* The database connection that owns this statement */
15588 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
15612 int nChange; /* Number of db changes made since last reset */
15613 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
15912 sqlite3 *db, /* The database connection whose status is desired */
15920 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
15924 sqlite3_mutex_enter(db->mutex);
15927 *pCurrent = db->lookaside.nOut;
15928 *pHighwater = db->lookaside.mxOut;
15930 db->lookaside.mxOut = db->lookaside.nOut;
15944 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
15946 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
15959 sqlite3BtreeEnterAll(db);
15960 for(i=0; i<db->nDb; i++){
15961 Btree *pBt = db->aDb[i].pBt;
15967 sqlite3BtreeLeaveAll(db);
15982 sqlite3BtreeEnterAll(db);
15983 db->pnBytesFreed = &nByte;
15984 for(i=0; i<db->nDb; i++){
15985 Schema *pSchema = db->aDb[i].pSchema;
16001 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
16004 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
16008 db->pnBytesFreed = 0;
16009 sqlite3BtreeLeaveAll(db);
16025 db->pnBytesFreed = &nByte;
16026 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
16027 sqlite3VdbeClearObject(db, pVdbe);
16028 sqlite3DbFree(db, pVdbe);
16030 db->pnBytesFreed = 0;
16051 for(i=0; i<db->nDb; i++){
16052 if( db->aDb[i].pBt ){
16053 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
16070 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0;
16078 sqlite3_mutex_leave(db->mutex);
16980 sqlite3 *db;
16986 db = sqlite3_context_db_handle(context);
17022 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
17023 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
17026 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
17030 z = sqlite3DbMallocRaw(db, (int)n);
17166 sqlite3 *db;
21738 ** TRUE if p is a lookaside memory allocation from db
21741 static int isLookaside(sqlite3 *db, void *p){
21742 return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
21756 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
21757 if( db==0 || !isLookaside(db,p) ){
21759 if( db==0 ){
21769 assert( sqlite3_mutex_held(db->mutex) );
21770 return db->lookaside.sz;
21799 ** *db->pnBytesFreed.
21801 static SQLITE_NOINLINE void measureAllocationSize(sqlite3 *db, void *p){
21802 *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
21809 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
21810 assert( db==0 || sqlite3_mutex_held(db->mutex) );
21812 if( db ){
21813 if( db->pnBytesFreed ){
21814 measureAllocationSize(db, p);
21817 if( isLookaside(db, p) ){
21821 memset(p, 0xaa, db->lookaside.sz);
21823 pBuf->pNext = db->lookaside.pFree;
21824 db->lookaside.pFree = pBuf;
21825 db->lookaside.nOut--;
21831 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
21921 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, u64 n){
21922 void *p = sqlite3DbMallocRaw(db, n);
21933 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
21940 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
21941 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
21947 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){
21949 assert( db==0 || sqlite3_mutex_held(db->mutex) );
21950 assert( db==0 || db->pnBytesFreed==0 );
21952 if( db ){
21954 if( db->mallocFailed ){
21957 if( db->lookaside.bEnabled ){
21958 if( n>db->lookaside.sz ){
21959 db->lookaside.anStat[1]++;
21960 }else if( (pBuf = db->lookaside.pFree)==0 ){
21961 db->lookaside.anStat[2]++;
21963 db->lookaside.pFree = pBuf->pNext;
21964 db->lookaside.nOut++;
21965 db->lookaside.anStat[0]++;
21966 if( db->lookaside.nOut>db->lookaside.mxOut ){
21967 db->lookaside.mxOut = db->lookaside.nOut;
21974 if( db && db->mallocFailed ){
21979 if( !p && db ){
21980 db->mallocFailed = 1;
21983 (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
21991 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
21993 assert( db!=0 );
21994 assert( sqlite3_mutex_held(db->mutex) );
21995 if( db->mallocFailed==0 ){
21997 return sqlite3DbMallocRaw(db, n);
21999 if( isLookaside(db, p) ){
22000 if( n<=db->lookaside.sz ){
22003 pNew = sqlite3DbMallocRaw(db, n);
22005 memcpy(pNew, p, db->lookaside.sz);
22006 sqlite3DbFree(db, p);
22014 db->mallocFailed = 1;
22017 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
22027 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){
22029 pNew = sqlite3DbRealloc(db, p, n);
22031 sqlite3DbFree(db, p);
22043 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
22051 zNew = sqlite3DbMallocRaw(db, (int)n);
22057 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
22063 zNew = sqlite3DbMallocRaw(db, n+1);
22074 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
22075 sqlite3DbFree(db, *pz);
22076 *pz = sqlite3DbStrDup(db, zNew);
22082 static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
22083 db->mallocFailed = 0;
22084 sqlite3Error(db, SQLITE_NOMEM);
22100 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
22101 /* If the db handle must hold the connection handle mutex here.
22102 ** Otherwise the read (and possible write) of db->mallocFailed
22105 assert( db!=0 );
22106 assert( sqlite3_mutex_held(db->mutex) );
22107 if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
22108 return apiOomError(db);
22110 return rc & db->errMask;
22884 if( p->db ){
22885 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
22893 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
22965 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
22981 sqlite3DbFree(p->db, p->zText);
22990 ** db: Pointer to a database connection. May be NULL. Lookaside
22991 ** memory is used if not NULL. db->mallocFailed is set appropriately
23000 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
23002 p->db = db;
23013 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
23017 assert( db!=0 );
23018 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
23019 db->aLimit[SQLITE_LIMIT_LENGTH]);
23023 db->mallocFailed = 1;
23032 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
23036 z = sqlite3VMPrintf(db, zFormat, ap);
24255 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
24319 zOut = sqlite3DbMallocRaw(pMem->db, len);
24368 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
24482 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
24485 m.db = db;
24488 if( db->mallocFailed ){
24492 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
24493 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
24494 assert( m.z || db->mallocFailed );
24693 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code){
24694 assert( db!=0 );
24695 db->errCode = err_code;
24696 if( db->pErr ) sqlite3ValueSetNull(db->pErr);
24701 ** handle "db". The error code is set to "err_code".
24716 ** To clear the most recent error for sqlite handle "db", sqlite3Error
24720 SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3 *db, int err_code, const char *zFormat, ...){
24721 assert( db!=0 );
24722 db->errCode = err_code;
24724 sqlite3Error(db, err_code);
24725 }else if( db->pErr || (db->pErr = sqlite3ValueNew(db))!=0 ){
24729 z = sqlite3VMPrintf(db, zFormat, ap);
24731 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
24755 sqlite3 *db = pParse->db;
24757 zMsg = sqlite3VMPrintf(db, zFormat, ap);
24759 if( db->suppressErr ){
24760 sqlite3DbFree(db, zMsg);
24763 sqlite3DbFree(db, pParse->zErrMsg);
25717 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
25721 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
25746 ** Check to make sure we have a valid db pointer. This test is not
25748 ** misuse of the interface such as passing in db pointers that are
25750 ** 1 it means that the db pointer is valid and 0 if it should not be
25754 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
25755 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
25759 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
25761 if( db==0 ){
25765 magic = db->magic;
25767 if( sqlite3SafetyCheckSickOrOk(db) ){
25776 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
25778 magic = db->magic;
25879 ** test.db-journal => test.nal
25880 ** test.db-wal => test.wal
25881 ** test.db-shm => test.shm
25882 ** test.db-mj7f3319fa => test.9fa
27984 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
30857 ** is "/home/user1/config.db" then the file that is created and mmapped
30858 ** for shared memory will be called "/home/user1/config.db-shm".
31383 int h = pFd->h; /* File descriptor open on db file */
31929 ** proxyLock activation is possible (remote proxy is based on db name)
32236 ** "<path to db>-journal"
32237 ** "<path to db>-wal"
32238 ** "<path to db>-journalNN"
32239 ** "<path to db>-walNN"
32348 /* The main DB, main journal, WAL file and master journal are never
32941 ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE,
32943 ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE,
32959 ** For database path "/Users/me/foo.db"
32960 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
33094 /* transform the db path to a unique cache name */
33752 /* afp style keeps a reference to the db path in the filePath field
33765 /* all other styles use the locking context to store the db file path */
39049 /* The main DB, main journal, WAL file and master journal are never
42465 sqlite3 *db; /* The database connection */
42483 ** are available at pSpace. The db pointer is used as a memory context
42493 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
42498 p->db = db;
42518 sqlite3DbFree(p->db, pChunk);
42533 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
42540 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
42995 int sync_flags, /* Flags to sync db file with (or 0) */
43022 ** stored in each frame (i.e. the db page-size when the WAL was created).
43293 ** db size etc.) are consistent with the contents of the file-system.
43731 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
43732 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
44931 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
45415 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
46183 i64 n = 0; /* Size of db file in bytes */
46220 ** function. Because an EXCLUSIVE lock on the db file is required to delete
47619 ROUND8(pVfs->szOsFile) + /* The main db file */
48163 ** possibility by unmapping the db here. */
48277 ** flag was specified by the caller. And so long as the db is not a
49128 int noSync /* True to omit the xSync on the db file */
49149 /* If this is an in-memory db, or no pages have been written to, or this
49208 /* Update the db file change counter via the direct-write method. The
49257 ** last page in the db image moved to the free-list. In this case the
50665 u32 nBackfill; /* Number of WAL frames backfilled into DB */
50973 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
51000 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
52074 ** about the eventual size of the db file to the VFS layer.
52085 /* Iterate through the contents of the WAL, copying data to the db file */
53287 int sync_flags, /* Flags to sync db file with (or 0) */
53855 sqlite3 *db; /* The database connection holding this btree */
53858 u8 sharable; /* True if we can share pBt with another db */
53859 u8 locked; /* True if db currently has pBt locked */
53864 Btree *pNext; /* List of other sharable Btrees from the same db */
53919 sqlite3 *db; /* Database connection currently using this Btree */
53926 u8 bDoTruncate; /* True to truncate db on commit */
54000 ** particular database connection identified BtCursor.pBtree.db.
54180 u8 *aPgRef; /* 1 bit per page in the db (see above) */
54223 ** set BtShared.db to the database handle associated with p and the
54229 assert( sqlite3_mutex_held(p->db->mutex) );
54232 p->pBt->db = p->db;
54244 assert( sqlite3_mutex_held(p->db->mutex) );
54245 assert( p->db==pBt->db );
54277 assert( p->pNext==0 || p->pNext->db==p->db );
54278 assert( p->pPrev==0 || p->pPrev->db==p->db );
54286 assert( sqlite3_mutex_held(p->db->mutex) );
54288 /* Unless the database is sharable and unlocked, then BtShared.db
54290 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
54312 p->pBt->db = p->db;
54343 assert( sqlite3_mutex_held(p->db->mutex) );
54362 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
54364 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
54400 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
54403 assert( sqlite3_mutex_held(db->mutex) );
54404 for(i=0; i<db->nDb; i++){
54405 p = db->aDb[i].pBt;
54409 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
54412 assert( sqlite3_mutex_held(db->mutex) );
54413 for(i=0; i<db->nDb; i++){
54414 p = db->aDb[i].pBt;
54434 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
54436 if( !sqlite3_mutex_held(db->mutex) ){
54439 for(i=0; i<db->nDb; i++){
54441 p = db->aDb[i].pBt;
54454 ** db->aDb[iDb].pSchema structure. The mutexes required for schema
54457 ** (1) The mutex on db
54458 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
54461 ** db using sqlite3SchemaToIndex().
54463 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
54465 assert( db!=0 );
54466 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
54467 assert( iDb>=0 && iDb<db->nDb );
54468 if( !sqlite3_mutex_held(db->mutex) ) return 0;
54470 p = db->aDb[iDb].pBt;
54488 p->pBt->db = p->db;
54490 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
54492 for(i=0; i<db->nDb; i++){
54493 Btree *p = db->aDb[i].pBt;
54495 p->pBt->db = p->db;
54658 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
54735 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
54756 assert( p->db!=0 );
54757 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
54775 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
54792 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
54829 assert( p->db!=0 );
54835 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
55269 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
55277 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
56220 assert( pPage->pBt->db!=0 );
56280 if( pBt->db->flags & SQLITE_CellSizeCk ){
56592 assert( pBt->db );
56593 assert( sqlite3_mutex_held(pBt->db->mutex) );
56594 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
56621 sqlite3 *db, /* Associated database handle */
56643 || (isTempDb && sqlite3TempInMemory(db))
56647 assert( db!=0 );
56649 assert( sqlite3_mutex_held(db->mutex) );
56669 p->db = db;
56714 for(iDb=db->nDb-1; iDb>=0; iDb--){
56715 Btree *pExisting = db->aDb[iDb].pBt;
56764 sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
56771 pBt->db = db;
56828 db->mallocFailed = 0;
56848 for(i=0; i<db->nDb; i++){
56849 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
56987 assert( sqlite3_mutex_held(p->db->mutex) );
57054 assert( sqlite3_mutex_held(p->db->mutex) );
57068 assert( sqlite3_mutex_held(p->db->mutex) );
57090 assert( sqlite3_mutex_held(p->db->mutex) );
57105 assert( sqlite3_mutex_held(p->db->mutex) );
57411 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
57630 pBlock = pBt->pWriter->db;
57635 pBlock = pIter->pBtree->db;
57641 sqlite3ConnectionBlocked(p->db, pBlock);
57669 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
57707 /* If the db-size header field is incorrect (as it may be if an old
57729 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
58221 sqlite3 *db = p->db;
58227 if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){
58469 assert( iStatement>p->db->nSavepoint );
59021 assert( pCur->pBtree->db==pBt->db );
59173 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59432 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59455 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59531 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
59584 ** would have already detected db corruption. Similarly, pPage must
59692 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
63015 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
63782 int savedDbFlags = pBt->db->flags;
63828 testcase( pBt->db->flags & SQLITE_CellSizeCk );
63829 pBt->db->flags &= ~SQLITE_CellSizeCk;
63840 pBt->db->flags = savedDbFlags;
63911 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
63945 assert( sqlite3_mutex_held(p->db->mutex) );
63951 assert( sqlite3_mutex_held(p->db->mutex) );
63993 assert( sqlite3_mutex_held(p->db->mutex) );
64041 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
64252 pParse->db = pDb;
64288 ** message in database handle db.
64290 static int checkReadTransaction(sqlite3 *db, Btree *p){
64292 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
64534 int nSrcPage = -1; /* Size of source db in pages */
64535 int bCloseTrans = 0; /* True if src db requires unlocking */
64926 b.pSrcDb = pFrom->db;
65005 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
65051 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65086 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
65090 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
65093 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
65094 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
65102 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
65152 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65182 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65219 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65247 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65293 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65297 t.db = pMem->db;
65303 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
65320 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
65354 sqlite3DbFree(p->db, p->zMalloc);
65420 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65444 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65469 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65494 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65508 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65527 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65554 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
65578 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
65590 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){
65593 pMem->db = db;
65678 sqlite3 *db = pMem->db;
65679 assert( db!=0 );
65682 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
65683 if( db->mallocFailed ){
65688 pMem->szMalloc = sqlite3DbMallocSize(db, pMem->zMalloc);
65689 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, pMem->szMalloc);
65700 assert( p->db!=0 );
65706 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
65747 assert( pTo->db==pFrom->db );
65767 assert( pTo->db==pFrom->db || pFrom->db==0 );
65789 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
65790 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
65791 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
65825 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
65834 if( pMem->db ){
65835 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
65873 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
65982 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
66005 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
66006 || pVal->db->mallocFailed );
66026 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
66041 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
66042 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
66045 p->db = db;
66072 static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
66084 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
66089 assert( pRec->pKeyInfo->enc==ENC(db) );
66093 pRec->aMem[i].db = db;
66096 sqlite3DbFree(db, pRec);
66110 return sqlite3ValueNew(db);
66135 sqlite3 *db, /* The database connection */
66157 pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
66166 apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
66172 rc = sqlite3ValueFromExpr(db, pList->a[i].pExpr, enc, aff, &apVal[i]);
66177 pVal = valueNew(db, pCtx);
66210 sqlite3DbFree(db, apVal);
66231 sqlite3 *db, /* The database connection */
66260 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
66281 pVal = valueNew(db, pCtx);
66286 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
66301 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal)
66316 pVal = valueNew(db, pCtx);
66324 pVal = valueNew(db, pCtx);
66329 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
66336 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
66344 db->mallocFailed = 1;
66345 sqlite3DbFree(db, zVal);
66366 sqlite3 *db, /* The database connection */
66372 return valueFromExpr(db, pExpr, enc, affinity, ppVal, 0);
66394 sqlite3 *db;
66401 db = sqlite3_context_db_handle(context);
66404 aRet = sqlite3DbMallocRaw(db, nRet);
66412 sqlite3DbFree(db, aRet);
66458 sqlite3 *db = pParse->db;
66464 pVal = valueNew(db, pAlloc);
66475 pVal = valueNew(db, pAlloc);
66479 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
66481 pVal->db = pParse->db;
66485 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, pAlloc);
66488 assert( pVal==0 || pVal->db==db );
66542 assert( pVal==0 || pVal->db==pParse->db );
66575 sqlite3 *db, /* Database handle */
66606 pMem = *ppVal = sqlite3ValueNew(db);
66610 pMem->enc = ENC(db);
66624 sqlite3 *db = aMem[0].db;
66629 sqlite3DbFree(db, pRec);
66653 sqlite3DbFree(((Mem*)v)->db, v);
66704 sqlite3 *db = pParse->db;
66706 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
66708 p->db = db;
66709 if( db->pVdbe ){
66710 db->pVdbe->pPrev = p;
66712 p->pNext = db->pVdbe;
66714 db->pVdbe = p;
66728 sqlite3DbFree(p->db, p->zErrMsg);
66730 p->zErrMsg = sqlite3VMPrintf(p->db, zFormat, ap);
66744 p->zSql = sqlite3DbStrNDup(p->db, z, n);
66807 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
66809 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
66867 if( p->db->flags & SQLITE_VdbeAddopTrace ){
66986 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
67024 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
67072 ** sqlite3DbFree(v->db, sIter.apSub);
67114 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
67175 sqlite3DbFree(v->db, sIter.apSub);
67182 return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
67271 sqlite3DbFree(p->db, pParse->aLabel);
67299 assert( aOp && !p->db->mallocFailed );
67347 if( p->db->flags & SQLITE_VdbeAddopTrace ){
67370 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
67377 pNew->zName = sqlite3DbStrDup(p->db, zName);
67418 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
67420 sqlite3DbFree(db, pDef);
67429 static void freeP4(sqlite3 *db, int p4type, void *p4){
67431 assert( db );
67434 freeEphemeralFunction(db, ((sqlite3_context*)p4)->pFunc);
67441 sqlite3DbFree(db, p4);
67445 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
67449 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
67453 freeEphemeralFunction(db, (FuncDef*)p4);
67457 if( db->pnBytesFreed==0 ){
67461 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
67462 sqlite3DbFree(db, p);
67467 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
67479 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
67483 freeP4(db, pOp->p4type, pOp->p4.p);
67485 sqlite3DbFree(db, pOp->zComment);
67489 sqlite3DbFree(db, aOp);
67508 sqlite3 *db = p->db;
67509 freeP4(db, pOp->p4type, pOp->p4.p);
67548 sqlite3 *db;
67550 db = p->db;
67552 if( p->aOp==0 || db->mallocFailed ){
67554 freeP4(db, n, (void*)*(char**)&zP4);
67567 freeP4(db, pOp->p4type, pOp->p4.p);
67584 assert( ((VTable *)zP4)->db==p->db );
67590 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
67616 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
67619 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
67620 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
67672 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
67673 if( p->db->mallocFailed ){
67890 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
67898 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
67901 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
67911 ** sets the BtShared.db member of each of the BtShared structures, ensuring
67915 ** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
67930 sqlite3 *db;
67931 Db *aDb;
67934 db = p->db;
67935 aDb = db->aDb;
67936 nDb = db->nDb;
67951 sqlite3 *db;
67952 Db *aDb;
67954 db = p->db;
67955 aDb = db->aDb;
67956 nDb = db->nDb;
68002 sqlite3 *db = p->db;
68003 u8 malloc_failed = db->mallocFailed;
68004 if( db->pnBytesFreed ){
68006 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
68011 assert( (&p[1])==pEnd || p[0].db==p[1].db );
68033 sqlite3DbFree(db, p->zMalloc);
68039 db->mallocFailed = malloc_failed;
68055 sqlite3DbFree(p->v->db, p);
68081 sqlite3 *db = p->db; /* The database connection */
68100 db->mallocFailed = 1;
68136 }else if( db->u1.isInterrupted ){
68202 assert( p->db->mallocFailed );
68218 assert( p->db->mallocFailed );
68229 assert( p->db->mallocFailed );
68358 assert( p->aMem[i].db==p->db );
68400 sqlite3 *db; /* The database connection */
68416 db = p->db;
68417 assert( db->mallocFailed==0 );
68475 p->pFree = sqlite3DbMallocZero(db, nByte);
68479 }while( nByte && !db->mallocFailed );
68487 p->aVar[n].db = db;
68500 p->aMem[n].db = db;
68515 sqlite3VdbeSorterClose(p->db, pCx);
68569 v->db->lastRowid = pFrame->lastRowid;
68571 v->db->nChange = pFrame->nDbChange;
68611 sqlite3 *db = p->db;
68623 sqlite3DbFree(db, p->zErrMsg);
68637 sqlite3 *db = p->db;
68640 sqlite3DbFree(db, p->aColName);
68643 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
68647 pColName->db = p->db;
68673 if( p->db->mallocFailed ){
68686 ** db. If a transaction is active, commit it. If there is a
68690 static int vdbeCommit(sqlite3 *db, Vdbe *p){
68709 rc = sqlite3VtabSync(db, p);
68717 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68718 Btree *pBt = db->aDb[i].pBt;
68732 if( needXcommit && db->xCommitCallback ){
68733 rc = db->xCommitCallback(db->pCommitArg);
68748 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
68751 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68752 Btree *pBt = db->aDb[i].pBt;
68763 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68764 Btree *pBt = db->aDb[i].pBt;
68770 sqlite3VtabCommit(db);
68780 sqlite3_vfs *pVfs = db->pVfs;
68783 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
68792 zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
68823 sqlite3DbFree(db, zMaster);
68833 for(i=0; i<db->nDb; i++){
68834 Btree *pBt = db->aDb[i].pBt;
68849 sqlite3DbFree(db, zMaster);
68864 sqlite3DbFree(db, zMaster);
68868 /* Sync all the db files involved in the transaction. The same call
68878 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
68879 Btree *pBt = db->aDb[i].pBt;
68887 sqlite3DbFree(db, zMaster);
68896 sqlite3DbFree(db, zMaster);
68911 for(i=0; i<db->nDb; i++){
68912 Btree *pBt = db->aDb[i].pBt;
68920 sqlite3VtabCommit(db);
68937 static void checkActiveVdbeCnt(sqlite3 *db){
68942 p = db->pVdbe;
68951 assert( cnt==db->nVdbeActive );
68952 assert( nWrite==db->nVdbeWrite );
68953 assert( nRead==db->nVdbeRead );
68970 sqlite3 *const db = p->db;
68976 ** In this case (db->nStatement==0), and there is nothing to do.
68978 if( db->nStatement && p->iStatement ){
68983 assert( db->nStatement>0 );
68984 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
68986 for(i=0; i<db->nDb; i++){
68988 Btree *pBt = db->aDb[i].pBt;
69001 db->nStatement--;
69006 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
69009 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
69017 db->nDeferredCons = p->nStmtDefCons;
69018 db->nDeferredImmCons = p->nStmtDefImmCons;
69036 sqlite3 *db = p->db;
69037 if( (deferred && (db->nDeferredCons+db->nDeferredImmCons)>0)
69064 sqlite3 *db = p->db;
69082 if( p->db->mallocFailed ){
69090 checkActiveVdbeCnt(db);
69126 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69127 sqlite3CloseSavepoints(db);
69128 db->autoCommit = 1;
69145 if( !sqlite3VtabInSync(db)
69146 && db->autoCommit
69147 && db->nVdbeWrite==(p->readOnly==0)
69162 rc = vdbeCommit(db, p);
69169 sqlite3RollbackAll(db, SQLITE_OK);
69172 db->nDeferredCons = 0;
69173 db->nDeferredImmCons = 0;
69174 db->flags &= ~SQLITE_DeferFKs;
69175 sqlite3CommitInternalChanges(db);
69178 sqlite3RollbackAll(db, SQLITE_OK);
69181 db->nStatement = 0;
69188 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69189 sqlite3CloseSavepoints(db);
69190 db->autoCommit = 1;
69206 sqlite3DbFree(db, p->zErrMsg);
69209 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69210 sqlite3CloseSavepoints(db);
69211 db->autoCommit = 1;
69221 sqlite3VdbeSetChanges(db, p->nChange);
69223 sqlite3VdbeSetChanges(db, 0);
69234 db->nVdbeActive--;
69235 if( !p->readOnly ) db->nVdbeWrite--;
69236 if( p->bIsReader ) db->nVdbeRead--;
69237 assert( db->nVdbeActive>=db->nVdbeRead );
69238 assert( db->nVdbeRead>=db->nVdbeWrite );
69239 assert( db->nVdbeWrite>=0 );
69242 checkActiveVdbeCnt(db);
69243 if( p->db->mallocFailed ){
69248 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
69251 if( db->autoCommit ){
69252 sqlite3ConnectionUnlocked(db);
69255 assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
69277 sqlite3 *db = p->db;
69280 u8 mallocFailed = db->mallocFailed;
69282 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
69283 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
69285 db->mallocFailed = mallocFailed;
69286 db->errCode = rc;
69288 sqlite3Error(db, rc);
69301 assert( v->db->init.busy==0 );
69304 sqlite3GlobalConfig.pSqllogArg, v->db, zExpanded, 1
69306 sqlite3DbFree(v->db, zExpanded);
69326 sqlite3 *db;
69327 db = p->db;
69343 sqlite3DbFree(db, p->zErrMsg);
69351 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
69352 sqlite3DbFree(db, p->zErrMsg);
69398 return p->rc & db->errMask;
69409 assert( (rc & p->db->errMask)==rc );
69443 sqlite3DbFree(pVdbe->db, pAux);
69458 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
69461 assert( p->db==0 || p->db==db );
69466 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
69467 sqlite3DbFree(db, pSub);
69469 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
69470 vdbeFreeOpArray(db, p->aOp, p->nOp);
69471 sqlite3DbFree(db, p->aColName);
69472 sqlite3DbFree(db, p->zSql);
69473 db, p->pFree);
69476 sqlite3DbFree(db, p->aScan[i].zName);
69478 sqlite3DbFree(db, p->aScan);
69486 sqlite3 *db;
69489 db = p->db;
69490 assert( sqlite3_mutex_held(db->mutex) );
69491 sqlite3VdbeClearObject(db, p);
69495 assert( db->pVdbe==p );
69496 db->pVdbe = p->pNext;
69502 p->db = 0;
69503 sqlite3DbFree(db, p);
69654 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
69949 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
69992 pMem->db = pKeyInfo->db;
70030 if( pKeyInfo->db==0 ) return 1;
70032 mem1.db = pKeyInfo->db;
70103 if( pKeyInfo->db->mallocFailed ) return 1;
70166 sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null);
70167 sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null);
70342 ** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
70460 mem1.db = pKeyInfo->db;
70526 || pKeyInfo->db->mallocFailed
70688 || pPKey2->pKeyInfo->db->mallocFailed
70744 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
70763 sqlite3VdbeMemInit(&m, db, 0);
70823 sqlite3 *db, /* Database connection */
70842 sqlite3VdbeMemInit(&m, db, 0);
70854 ** sqlite3_changes() on the database handle 'db'.
70856 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
70857 assert( sqlite3_mutex_held(db->mutex) );
70858 db->nChange = nChange;
70859 db->nTotalChange += nChange;
70880 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
70882 for(p = db->pVdbe; p; p=p->pNext){
70891 return v->db;
70907 sqlite3_value *pRet = sqlite3ValueNew(v->db);
70939 sqlite3 *db = p->db;
70940 sqlite3DbFree(db, p->zErrMsg);
70941 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
70988 if( p->db==0 ){
71009 static SQLITE_NOINLINE void invokeProfileCallback(sqlite3 *db, Vdbe *p){
71012 assert( db->xProfile!=0 );
71013 assert( db->init.busy==0 );
71015 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
71016 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
71020 ** The checkProfileCallback(DB,P) macro checks to see if a profile callback
71023 # define checkProfileCallback(DB,P) \
71024 if( ((P)->startTime)>0 ){ invokeProfileCallback(DB,P); }
71026 # define checkProfileCallback(DB,P) /*no-op*/
71046 sqlite3 *db = v->db;
71048 sqlite3_mutex_enter(db->mutex);
71049 checkProfileCallback(db, v);
71051 rc = sqlite3ApiExit(db, rc);
71052 sqlite3LeaveMutexAndCloseZombie(db);
71071 sqlite3 *db = v->db;
71072 sqlite3_mutex_enter(db->mutex);
71073 checkProfileCallback(db, v);
71076 assert( (rc & (db->errMask))==rc );
71077 rc = sqlite3ApiExit(db, rc);
71078 sqlite3_mutex_leave(db->mutex);
71091 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
71207 pNew->db = 0;
71272 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71281 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71290 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71294 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71301 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71308 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71312 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71316 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71320 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71329 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71339 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71355 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71364 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71373 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71378 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71382 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71387 assert( sqlite3_mutex_held(pOut->db->mutex) );
71388 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
71408 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71417 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71421 pCtx->pOut->db->mallocFailed = 1;
71428 static int doWalCallbacks(sqlite3 *db){
71432 for(i=0; i<db->nDb; i++){
71433 Btree *pBt = db->aDb[i].pBt;
71439 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
71440 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
71459 sqlite3 *db;
71492 db = p->db;
71493 if( db->mallocFailed ){
71508 if( db->nVdbeActive==0 ){
71509 db->u1.isInterrupted = 0;
71512 assert( db->nVdbeWrite>0 || db->autoCommit==0
71513 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
71517 if( db->xProfile && !db->init.busy && p->zSql ){
71518 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
71524 db->nVdbeActive++;
71525 if( p->readOnly==0 ) db->nVdbeWrite++;
71526 if( p->bIsReader ) db->nVdbeRead++;
71538 db->nVdbeExec++;
71540 db->nVdbeExec--;
71545 if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
71550 p->rc = doWalCallbacks(db);
71556 db->errCode = rc;
71557 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
71579 return (rc&db->errMask);
71592 sqlite3 *db; /* The database connection */
71597 db = v->db;
71598 sqlite3_mutex_enter(db->mutex);
71618 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
71619 sqlite3DbFree(db, v->zErrMsg);
71620 if( !db->mallocFailed ){
71621 v->zErrMsg = sqlite3DbStrDup(db, zErr);
71628 rc = sqlite3ApiExit(db, rc);
71629 sqlite3_mutex_leave(db->mutex);
71655 return p->pOut->db;
71675 rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime);
71731 assert( sqlite3_mutex_held(p->pOut->db->mutex) );
71747 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71774 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
71786 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
71871 /* .db = */ (sqlite3*)0,
71893 sqlite3_mutex_enter(pVm->db->mutex);
71896 if( pVm && ALWAYS(pVm->db) ){
71897 sqlite3_mutex_enter(pVm->db->mutex);
71898 sqlite3Error(pVm->db, SQLITE_RANGE);
71932 p->rc = sqlite3ApiExit(p->db, p->rc);
71933 sqlite3_mutex_leave(p->db->mutex);
72028 sqlite3 *db;
72037 db = p->db;
72038 assert( db!=0 );
72042 sqlite3_mutex_enter(db->mutex);
72043 assert( db->mallocFailed==0 );
72048 if( db->mallocFailed ){
72049 db->mallocFailed = 0;
72052 sqlite3_mutex_leave(db->mutex);
72161 ** The error code stored in database p->db is overwritten with the return
72169 sqlite3_mutex_enter(p->db->mutex);
72171 sqlite3Error(p->db, SQLITE_MISUSE);
72172 sqlite3_mutex_leave(p->db->mutex);
72178 sqlite3Error(p->db, SQLITE_RANGE);
72179 sqlite3_mutex_leave(p->db->mutex);
72186 sqlite3Error(p->db, SQLITE_OK);
72226 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
72228 sqlite3Error(p->db, rc);
72229 rc = sqlite3ApiExit(p->db, rc);
72231 sqlite3_mutex_leave(p->db->mutex);
72271 sqlite3_mutex_leave(p->db->mutex);
72284 sqlite3_mutex_leave(p->db->mutex);
72293 sqlite3_mutex_leave(p->db->mutex);
72370 sqlite3_mutex_leave(p->db->mutex);
72377 sqlite3_mutex_enter(p->db->mutex);
72378 if( n>(u64)p->db->aLimit[SQLITE_LIMIT_LENGTH] ){
72384 rc = sqlite3ApiExit(p->db, rc);
72385 sqlite3_mutex_leave(p->db->mutex);
72443 assert( pTo->db==pFrom->db );
72445 sqlite3_mutex_enter(pTo->db->mutex);
72449 sqlite3_mutex_leave(pTo->db->mutex);
72489 return pStmt ? ((Vdbe*)pStmt)->db : 0;
72695 sqlite3 *db; /* The database connection */
72705 db = p->db;
72706 sqlite3StrAccumInit(&out, db, zBase, sizeof(zBase),
72707 db->aLimit[SQLITE_LIMIT_LENGTH]);
72708 if( db->nVdbeExec>1 ){
72756 u8 enc = ENC(db);
72760 utf8.db = db;
73292 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
73406 ** assert( checkSavepointCount(db) );
73408 static int checkSavepointCount(sqlite3 *db){
73411 for(p=db->pSavepoint; p; p=p->pNext) n++;
73412 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
73446 sqlite3 *db = p->db; /* The database */
73448 u8 encoding = ENC(db); /* The database encoding */
73460 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
73479 db->busyHandler.nBusy = 0;
73480 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
73483 if( db->xProgress ){
73485 assert( 0 < db->nProgressOps );
73486 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
73492 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
73497 if( p->db->flags & SQLITE_VdbeListing ){
73503 if( p->db
73512 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n");
73518 if( db->mallocFailed ) goto no_mem;
73530 if( db->flags & SQLITE_VdbeTrace ){
73543 sqlite3_interrupt(db);
73651 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
73659 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
73660 assert( db->nProgressOps!=0 );
73661 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
73662 if( db->xProgress(db->pProgressArg) ){
73831 sqlite3VdbeSetChanges(db, p->nChange);
73833 lastRowid = db->lastRowid;
73880 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
73950 sqlite3DbFree(db, pOp->p4.z);
73957 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
74186 if( db->xProgress!=0
74188 && db->xProgress(db->pProgressArg)!=0
74199 assert( db->flags&SQLITE_CountRows );
74219 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
74241 if( db->mallocFailed ) goto no_mem;
74278 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
74498 pCtx = sqlite3DbMallocRaw(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
74536 db->lastRowid = lastRowid;
74538 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
74901 if( db->mallocFailed ) goto no_mem;
75308 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
75632 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){
75719 assert( db->pSavepoint==0 || db->autoCommit==0 );
75721 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
75722 assert( checkSavepointCount(db) );
75726 if( db->nVdbeWrite>0 ){
75739 ** that the db->aVTrans[] array is empty. */
75740 assert( db->autoCommit==0 || db->nVTrans==0 );
75741 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
75742 db->nStatement+db->nSavepoint);
75747 pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
75754 if( db->autoCommit ){
75755 db->autoCommit = 0;
75756 db->isTransactionSavepoint = 1;
75758 db->nSavepoint++;
75762 pNew->pNext = db->pSavepoint;
75763 db->pSavepoint = pNew;
75764 pNew->nDeferredCons = db->nDeferredCons;
75765 pNew->nDeferredImmCons = db->nDeferredImmCons;
75774 pSavepoint = db->pSavepoint;
75783 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
75796 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
75801 db->autoCommit = 1;
75804 db->autoCommit = 0;
75808 db->isTransactionSavepoint = 0;
75812 iSavepoint = db->nSavepoint - iSavepoint - 1;
75814 isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
75815 for(ii=0; ii<db->nDb; ii++){
75816 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
75824 for(ii=0; ii<db->nDb; ii++){
75825 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
75831 sqlite3ExpirePreparedStatements(db);
75832 sqlite3ResetAllSchemasOfConnection(db);
75833 db->flags = (db->flags | SQLITE_InternChanges);
75839 while( db->pSavepoint!=pSavepoint ){
75840 pTmp = db->pSavepoint;
75841 db->pSavepoint = pTmp->pNext;
75842 sqlite3DbFree(db, pTmp);
75843 db->nSavepoint--;
75851 assert( pSavepoint==db->pSavepoint );
75852 db->pSavepoint = pSavepoint->pNext;
75853 sqlite3DbFree(db, pSavepoint);
75855 db->nSavepoint--;
75858 db->nDeferredCons = pSavepoint->nDeferredCons;
75859 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
75863 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
75888 turnOnAC = desiredAutoCommit && !db->autoCommit;
75891 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
75894 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
75901 }else if( desiredAutoCommit!=db->autoCommit ){
75904 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
75905 db->autoCommit = 1;
75909 db->autoCommit = (u8)desiredAutoCommit;
75913 db->autoCommit = (u8)(1-desiredAutoCommit);
75917 assert( db->nStatement==0 );
75918 sqlite3CloseSavepoints(db);
75977 assert( pOp->p1>=0 && pOp->p1<db->nDb );
75979 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
75983 pBt = db->aDb[pOp->p1].pBt;
75999 && (db->autoCommit==0 || db->nVdbeRead>1)
76003 assert( db->nStatement>=0 && db->nSavepoint>=0 );
76004 db->nStatement++;
76005 p->iStatement = db->nSavepoint + db->nStatement;
76008 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
76016 p->nStmtDefCons = db->nDeferredCons;
76017 p->nStmtDefImmCons = db->nDeferredImmCons;
76027 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
76033 sqlite3DbFree(db, p->zErrMsg);
76034 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
76048 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
76049 sqlite3ResetOneSchema(db, pOp->p1);
76078 assert( iDb>=0 && iDb<db->nDb );
76079 assert( db->aDb[iDb].pBt!=0 );
76082 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
76099 Db *pDb;
76101 assert( pOp->p1>=0 && pOp->p1<db->nDb );
76104 pDb = &db->aDb[pOp->p1];
76106 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
76114 db->flags |= SQLITE_InternChanges;
76122 sqlite3ExpirePreparedStatements(db);
76201 Db *pDb;
76230 assert( iDb>=0 && iDb<db->nDb );
76232 pDb = &db->aDb[iDb];
76237 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
76263 assert( pKeyInfo->enc==ENC(db) );
76264 assert( pKeyInfo->db==db );
76336 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
76353 assert( pKeyInfo->db==db );
76354 assert( pKeyInfo->enc==ENC(db) );
76386 assert( pCx->pKeyInfo->db==db );
76387 assert( pCx->pKeyInfo->enc==ENC(db) );
76388 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx);
76846 sqlite3DbFree(db, pFree);
77153 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
77174 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
77175 zDb = db->aDb[pC->iDb].zName;
77179 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
77216 hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable;
77237 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
77238 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
77252 sqlite3VdbeSetChanges(db, p->nChange);
77376 if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
77383 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
77644 rc = sqlite3VdbeSorterNext(db, pC, &res);
77815 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
77899 rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
77940 if( db->nVdbeRead > db->nVDestroy+1 ){
77947 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
77952 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
77987 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
78015 sqlite3VdbeSorterReset(db, pC->pSorter);
78051 Db *pDb;
78055 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78058 pDb = &db->aDb[pOp->p1];
78090 for(iDb=0; iDb<db->nDb; iDb++){
78091 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
78096 assert( iDb>=0 && iDb<db->nDb );
78097 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
78100 initData.db = db;
78103 zSql = sqlite3MPrintf(db,
78105 db->aDb[iDb].zName, zMaster, pOp->p4.z);
78109 assert( db->init.busy==0 );
78110 db->init.busy = 1;
78112 assert( !db->mallocFailed );
78113 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
78115 sqlite3DbFree(db, zSql);
78116 db->init.busy = 0;
78119 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
78134 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78135 rc = sqlite3AnalysisLoad(db, pOp->p1);
78149 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
78162 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
78175 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
78212 aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
78223 assert( pOp->p5<db->nDb );
78225 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
78227 sqlite3DbFree(db, aRoot);
78392 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
78413 pFrame = sqlite3DbMallocZero(db, nByte);
78441 pMem->db = db;
78454 pFrame->nDbChange = p->db->nChange;
78508 if( db->flags & SQLITE_DeferFKs ){
78509 db->nDeferredImmCons += pOp->p2;
78511 db->nDeferredCons += pOp->p2;
78532 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
78533 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
78535 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
78536 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2;
78698 pCtx = sqlite3DbMallocRaw(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
78737 sqlite3VdbeMemInit(&t, db, MEM_Null);
78814 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
78857 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78860 pBt = db->aDb[pOp->p1].pBt;
78882 if( !db->autoCommit || db->nVdbeRead>1 ){
78941 rc = sqlite3RunVacuum(&p->zErrMsg, db);
78956 assert( pOp->p1>=0 && pOp->p1<db->nDb );
78959 pBt = db->aDb[pOp->p1].pBt;
78982 sqlite3ExpirePreparedStatements(db);
79007 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
79009 assert( p1>=0 && p1<db->nDb );
79012 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
79035 rc = sqlite3VtabBegin(db, pVTab);
79052 sMem.db = db;
79060 assert( zTab || db->mallocFailed );
79062 rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg);
79076 db->nVDestroy++;
79077 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
79078 db->nVDestroy--;
79117 assert( db->mallocFailed );
79361 u8 vtabOnConflict = db->vtabOnConflict;
79370 db->vtabOnConflict = pOp->p5;
79372 db->vtabOnConflict = vtabOnConflict;
79376 db->lastRowid = lastRowid = rowid;
79399 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
79419 pBt = db->aDb[pOp->p1].pBt;
79448 if( db
79453 db->xTrace(db->pTraceArg, z);
79454 sqlite3DbFree(db, z);
79460 for(i=0; i<db->nDb; i++){
79462 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
79467 if( (db->flags & SQLITE_SqlTrace)!=0
79520 if( db->flags & SQLITE_VdbeTrace ){
79543 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
79546 sqlite3ResetOneSchema(db, resetSchemaOnFault-1);
79553 db->lastRowid = lastRowid;
79570 db->mallocFailed = 1;
79580 if( db->mallocFailed ) rc = SQLITE_NOMEM;
79590 assert( db->u1.isInterrupted );
79631 sqlite3 *db; /* The associated database */
79669 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
79689 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
79692 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
79707 sqlite3* db, /* The database connection */
79719 ** db/table/row entry. The reason for using a vdbe program instead
79762 if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
79768 sqlite3_mutex_enter(db->mutex);
79770 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
79772 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
79777 pParse->db = db;
79778 sqlite3DbFree(db, zErr);
79781 sqlite3BtreeEnterAll(db);
79799 sqlite3DbFree(db, zErr);
79804 sqlite3BtreeLeaveAll(db);
79815 sqlite3DbFree(db, zErr);
79816 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
79818 sqlite3BtreeLeaveAll(db);
79830 if( db->flags&SQLITE_ForeignKeys ){
79856 sqlite3DbFree(db, zErr);
79857 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
79859 sqlite3BtreeLeaveAll(db);
79865 assert( pBlob->pStmt || db->mallocFailed );
79868 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79905 if( !db->mallocFailed ){
79915 pBlob->db = db;
79916 sqlite3BtreeLeaveAll(db);
79917 if( db->mallocFailed ){
79925 if( rc==SQLITE_OK && db->mallocFailed==0 ){
79929 sqlite3DbFree(db, pBlob);
79931 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
79932 sqlite3DbFree(db, zErr);
79934 sqlite3StackFree(db, pParse);
79935 rc = sqlite3ApiExit(db, rc);
79936 sqlite3_mutex_leave(db->mutex);
79947 sqlite3 *db;
79950 db = p->db;
79951 sqlite3_mutex_enter(db->mutex);
79953 sqlite3DbFree(db, p);
79954 sqlite3_mutex_leave(db->mutex);
79974 sqlite3 *db;
79977 db = p->db;
79978 sqlite3_mutex_enter(db->mutex);
79993 assert( db == v->db );
80004 sqlite3Error(db, rc);
80005 rc = sqlite3ApiExit(db, rc);
80006 sqlite3_mutex_leave(db->mutex);
80048 sqlite3 *db;
80051 db = p->db;
80052 sqlite3_mutex_enter(db->mutex);
80063 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
80064 sqlite3DbFree(db, zErr);
80069 rc = sqlite3ApiExit(db, rc);
80071 sqlite3_mutex_leave(db->mutex);
80402 sqlite3 *db; /* Database connection */
80693 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
81006 sqlite3 *db, /* Database connection (for malloc()) */
81014 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
81026 if( sqlite3TempInMemory(db) || sqlite3GlobalConfig.bCoreMutex==0 ){
81029 nWorker = db->aLimit[SQLITE_LIMIT_WORKER_THREADS];
81045 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
81052 pKeyInfo->db = 0;
81057 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
81061 pSorter->db = db;
81067 if( !sqlite3TempInMemory(db) ){
81070 mxCache = db->aDb[0].pSchema->cache_size;
81087 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
81100 static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord){
81105 sqlite3DbFree(db, p);
81113 static void vdbeSortSubtaskCleanup(sqlite3 *db, SortSubtask *pTask){
81114 sqlite3DbFree(db, pTask->pUnpacked);
81139 sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t);
81153 sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t);
81163 sqlite3OsCurrentTimeInt64(pTask->pSorter->db->pVfs, &t);
81296 SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *db, VdbeSorter *pSorter){
81303 sqlite3DbFree(db, pSorter->pReader);
81311 vdbeSortSubtaskCleanup(db, pTask);
81322 sqlite3DbFree(db, pSorter->pUnpacked);
81329 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){
81332 sqlite3VdbeSorterReset(db, pSorter);
81334 sqlite3DbFree(db, pSorter);
81349 static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
81350 if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
81369 sqlite3 *db, /* Database handle doing sort */
81375 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
81384 vdbeSorterExtendFile(db, *ppFd, nExtend);
81614 sqlite3 *db = pTask->pSorter->db;
81630 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
81638 vdbeSorterExtendFile(db, pTask->file.pFd, pTask->file.iEof+pList->szPMA+9);
82244 sqlite3 *db = pTask->pSorter->db;
82258 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd);
82260 rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1].pFd);
82267 rc = vdbeSorterOpenTempFile(db, pTask->file2.iEof, &pTask->file2.pFd);
82555 sqlite3 *db = pTask0->pSorter->db;
82573 pReadr = (PmaReader*)sqlite3DbMallocZero(db, sizeof(PmaReader));
82678 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *db, const VdbeCursor *pCsr, int *pbEof){
82702 if( pSorter->list.aMemory==0 ) vdbeSorterRecordFree(db, pFree);
83558 sqlite3 *db; /* The database connection */
83563 db = pParse->db;
83564 pDup = sqlite3ExprDup(db, pOrig, 0);
83576 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
83580 sqlite3ExprDelete(db, pExpr);
83584 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
83587 sqlite3DbFree(db, pDup);
83643 ** pExpr->iDb Set the index in db->aDb[] of the database X
83676 sqlite3 *db = pParse->db; /* The database connection */
83708 for(i=0; i<db->nDb; i++){
83709 assert( db->aDb[i].zName );
83710 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
83711 pSchema = db->aDb[i].pSchema;
83959 sqlite3ExprDelete(db, pExpr->pLeft);
83961 sqlite3ExprDelete(db, pExpr->pRight);
83988 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
83989 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
84139 u8 enc = ENC(pParse->db); /* The database encoding */
84145 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
84147 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
84207 }else if( no_such_func && pParse->db->init.busy==0 ){
84261 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
84323 sqlite3 *db; /* Database connection */
84325 u8 savedSuppErr; /* Saved value of db->suppressErr */
84338 db = pParse->db;
84339 savedSuppErr = db->suppressErr;
84340 db->suppressErr = 1;
84342 db->suppressErr = savedSuppErr;
84395 sqlite3 *db;
84400 db = pParse->db;
84402 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
84433 pDup = sqlite3ExprDup(db, pE, 0);
84434 if( !db->mallocFailed ){
84438 sqlite3ExprDelete(db, pDup);
84444 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
84457 sqlite3ExprDelete(db, pE);
84493 sqlite3 *db = pParse->db;
84497 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
84499 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
84604 sqlite3 *db; /* Database connection */
84613 db = pParse->db;
84625 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
84679 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
84770 if( db->mallocFailed ){
84780 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
85048 ** If a memory allocation error occurs, that fact is recorded in pParse->db
85058 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
85104 sqlite3 *db = pParse->db;
85115 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
85127 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
85303 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
85430 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
85446 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
85479 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
85486 return sqlite3ExprAlloc(db, op, &x, 0);
85496 sqlite3 *db,
85502 assert( db->mallocFailed );
85503 sqlite3ExprDelete(db, pLeft);
85504 sqlite3ExprDelete(db, pRight);
85522 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
85535 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
85537 p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
85538 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
85581 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
85587 sqlite3ExprDelete(db, pLeft);
85588 sqlite3ExprDelete(db, pRight);
85589 return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
85591 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
85592 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
85603 sqlite3 *db = pParse->db;
85605 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
85607 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
85633 sqlite3 *db = pParse->db;
85656 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
85657 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
85658 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
85660 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
85683 a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
85684 if( a==0 ) return; /* Error reported through db->mallocFailed */
85690 sqlite3DbFree(db, pParse->azVar[x-1]);
85691 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
85695 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
85703 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
85710 sqlite3ExprDelete(db, p->pLeft);
85711 sqlite3ExprDelete(db, p->pRight);
85712 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
85714 sqlite3SelectDelete(db, p->x.pSelect);
85716 sqlite3ExprListDelete(db, p->x.pList);
85720 sqlite3DbFree(db, p);
85836 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
85850 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
85891 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
85893 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
85901 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
85902 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
85909 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
85910 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
85922 ** and the db->mallocFailed flag set.
85925 static With *withDup(sqlite3 *db, With *p){
85929 pRet = sqlite3DbMallocZero(db, nByte);
85934 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
85935 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
85936 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
85963 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
85964 return exprDup(db, p, flags, 0);
85966 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
85971 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
85975 pNew->a = pItem = sqlite3DbMallocRaw(db, i*sizeof(p->a[0]) );
85977 sqlite3DbFree(db, pNew);
85983 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
85984 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
85985 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
86002 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
86008 pNew = sqlite3DbMallocRaw(db, nByte );
86016 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
86017 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
86018 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
86024 pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
86029 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
86035 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
86036 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
86037 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
86042 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
86046 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
86049 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
86051 sqlite3DbFree(db, pNew);
86060 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
86065 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
86068 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
86070 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
86071 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
86072 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
86073 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
86074 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
86075 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
86077 pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
86080 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
86081 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
86088 pNew->pWith = withDup(db, p->pWith);
86093 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
86113 sqlite3 *db = pParse->db;
86115 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
86119 pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
86124 a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
86140 sqlite3ExprDelete(db, pExpr);
86141 sqlite3ExprListDelete(db, pList);
86164 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
86173 assert( pList!=0 || pParse->db->mallocFailed!=0 );
86179 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
86189 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
86197 sqlite3 *db = pParse->db;
86198 assert( pList!=0 || db->mallocFailed!=0 );
86202 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
86203 sqlite3DbFree(db, pItem->zSpan);
86204 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
86218 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
86229 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
86235 sqlite3ExprDelete(db, pItem->pExpr);
86236 sqlite3DbFree(db, pItem->zName);
86237 sqlite3DbFree(db, pItem->zSpan);
86239 sqlite3DbFree(db, pList->a);
86240 sqlite3DbFree(db, pList);
86694 sqlite3 *db = pParse->db; /* Database connection */
86709 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
86742 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
86859 pParse->db, "EXECUTE %s%s SUBQUERY %d", jmpIfDynamic>=0?"":"CORRELATED ",
86890 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
87014 sqlite3ExprDelete(pParse->db, pSel->pLimit);
87293 assert( iReg>0 || pParse->nErr || pParse->db->mallocFailed );
87300 if( OptimizationDisabled(pParse->db, SQLITE_ColumnCache) ) return;
87372 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
87389 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
87510 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
87587 sqlite3 *db = pParse->db; /* The database connection */
87592 assert( pParse->db->mallocFailed );
87831 u8 enc = ENC(db); /* The text encoding used by this database */
87844 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
87936 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
87938 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
87942 if( !pColl ) pColl = db->pDfltColl;
88151 assert( db->mallocFailed || pParse->nErr>0
88202 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
88271 assert( pParse->pVdbe || pParse->db->mallocFailed );
88716 sqlite3 *db = pParse->db;
88717 Expr *pCopy = sqlite3ExprDup(db, pExpr, 0);
88718 if( db->mallocFailed==0 ){
88721 sqlite3ExprDelete(db, pCopy);
88920 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
88923 db,
88936 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
88939 db,
88988 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
89046 u8 enc = ENC(pParse->db);
89047 i = addAggInfoFunc(pParse->db, pAggInfo);
89054 pItem->pFunc = sqlite3FindFunction(pParse->db,
89236 sqlite3 *db = sqlite3_context_db_handle(context);
89265 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
89292 sqlite3 *db = sqlite3_context_db_handle(context);
89315 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
89319 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
89322 sqlite3DbFree(db, zOutput);
89326 sqlite3DbFree(db, zParent);
89330 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
89332 sqlite3DbFree(db, zOutput);
89358 sqlite3 *db = sqlite3_context_db_handle(context);
89406 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
89451 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
89454 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
89456 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
89457 sqlite3DbFree(db, zWhere);
89473 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
89488 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
89490 /* If the table is not located in the temp-db (in which case NULL is
89492 ** that is not part of the temp-db schema, add a clause to the WHERE
89496 sqlite3 *db = pParse->db;
89499 zWhere = whereOrName(db, zWhere, pTrig->zName);
89504 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
89505 sqlite3DbFree(pParse->db, zWhere);
89529 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
89530 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
89536 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
89546 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
89589 sqlite3 *db = pParse->db; /* Database connection */
89597 int savedDbFlags; /* Saved value of db->flags */
89599 savedDbFlags = db->flags;
89600 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
89602 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
89606 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
89607 zDb = db->aDb[iDb].zName;
89608 db->flags |= SQLITE_PreferBuiltin;
89611 zName = sqlite3NameFromToken(db, pName);
89617 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
89652 pVTab = sqlite3GetVTable(db, pTab);
89690 if( db->flags&SQLITE_ForeignKeys ){
89699 sqlite3DbFree(db, zWhere);
89733 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
89751 sqlite3DbFree(db, zWhere);
89756 if( db->flags&SQLITE_ForeignKeys ){
89771 sqlite3SrcListDelete(db, pSrc);
89772 sqlite3DbFree(db, zName);
89773 db->flags = savedDbFlags;
89820 sqlite3 *db; /* The database connection; */
89822 db = pParse->db;
89823 if( pParse->nErr || db->mallocFailed ) return;
89827 assert( sqlite3BtreeHoldsAllMutexes(db) );
89828 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
89829 zDb = db->aDb[iDb].zName;
89833 pTab = sqlite3FindTable(db, zTab, zDb);
89863 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
89880 rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal);
89883 db->mallocFailed = 1;
89894 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
89897 int savedDbFlags = db->flags;
89901 db->flags |= SQLITE_PreferBuiltin;
89909 sqlite3DbFree(db, zCol);
89910 db->flags = savedDbFlags;
89945 sqlite3 *db = pParse->db;
89949 assert( sqlite3BtreeHoldsAllMutexes(db) );
89950 if( db->mallocFailed ) goto exit_begin_add_column;
89971 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
89980 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
89988 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
89989 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
89991 db->mallocFailed = 1;
89997 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
90003 pNew->pSchema = db->aDb[iDb].pSchema;
90014 sqlite3SrcListDelete(db, pSrc);
90216 sqlite3 *db = pParse->db;
90217 Db *pDb;
90223 assert( sqlite3BtreeHoldsAllMutexes(db) );
90224 assert( sqlite3VdbeDb(v)==db );
90225 pDb = &db->aDb[iDb];
90233 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
90315 sqlite3 *db; /* Database connection, for malloc() */
90321 static void sampleClear(sqlite3 *db, Stat4Sample *p){
90322 assert( db!=0 );
90324 sqlite3DbFree(db, p->u.aRowid);
90333 static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
90334 assert( db!=0 );
90335 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
90336 p->u.aRowid = sqlite3DbMallocRaw(db, n);
90349 static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
90350 assert( db!=0 );
90351 if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
90370 sampleSetRowid(p->db, pTo, pFrom->nRowid, pFrom->u.aRowid);
90372 sampleSetRowidInt64(p->db, pTo, pFrom->u.iRowid);
90384 for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i);
90385 for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i);
90386 sampleClear(p->db, &p->current);
90388 sqlite3DbFree(p->db, p);
90424 sqlite3 *db; /* Database connection */
90448 db = sqlite3_context_db_handle(context);
90449 p = sqlite3DbMallocZero(db, n);
90455 p->db = db;
90613 sampleClear(p->db, pMin);
90767 sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
90769 sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
90983 sqlite3 *db = pParse->db; /* Database handle */
91017 assert( sqlite3BtreeHoldsAllMutexes(db) );
91018 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91020 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
91023 db->aDb[iDb].zName ) ){
91101 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
91141 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*nColTest);
91189 sqlite3DbFree(db, aGotoChng);
91312 sqlite3 *db = pParse->db;
91313 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
91325 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
91343 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
91344 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
91370 sqlite3 *db = pParse->db;
91381 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
91389 for(i=0; i<db->nDb; i++){
91395 iDb = sqlite3FindDb(db, pName1);
91399 z = sqlite3NameFromToken(db, pName1);
91401 if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
91406 sqlite3DbFree(db, z);
91413 zDb = db->aDb[iDb].zName;
91414 z = sqlite3NameFromToken(db, pTableName);
91416 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
91421 sqlite3DbFree(db, z);
91435 sqlite3 *db;
91527 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
91536 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
91549 if( pIndex->aiRowEst==0 ) pInfo->db->mallocFailed = 1;
91573 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
91579 sqlite3DbFree(db, p->p);
91581 sqlite3DbFree(db, pIdx->aSample);
91583 if( db && db->pnBytesFreed==0 ){
91588 UNUSED_PARAMETER(db);
91658 sqlite3 *db,
91662 Index *pIdx = sqlite3FindIndex(db, zName, zDb);
91664 Table *pTab = sqlite3FindTable(db, zName, zDb);
91684 sqlite3 *db, /* Database handle */
91696 assert( db->lookaside.bEnabled==0 );
91697 zSql = sqlite3MPrintf(db, zSql1, zDb);
91701 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
91702 sqlite3DbFree(db, zSql);
91718 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
91736 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
91753 zSql = sqlite3MPrintf(db, zSql2, zDb);
91757 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
91758 sqlite3DbFree(db, zSql);
91768 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
91790 pSample->p = sqlite3DbMallocZero(db, pSample->n + 2);
91807 static int loadStat4(sqlite3 *db, const char *zDb){
91810 assert( db->lookaside.bEnabled==0 );
91811 if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){
91812 rc = loadStatTbl(db, 0,
91819 if( rc==SQLITE_OK && sqlite3FindTable(db, "sqlite_stat3", zDb) ){
91820 rc = loadStatTbl(db, 1,
91847 ** If an OOM error occurs, this function always sets db->mallocFailed.
91851 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
91857 assert( iDb>=0 && iDb<db->nDb );
91858 assert( db->aDb[iDb].pBt!=0 );
91861 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
91862 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
91866 sqlite3DeleteIndexSamples(db, pIdx);
91872 sInfo.db = db;
91873 sInfo.zDatabase = db->aDb[iDb].zName;
91874 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
91879 zSql = sqlite3MPrintf(db,
91884 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
91885 sqlite3DbFree(db, zSql);
91891 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
91892 int lookasideEnabled = db->lookaside.bEnabled;
91893 db->lookaside.bEnabled = 0;
91894 rc = loadStat4(db, sInfo.zDatabase);
91895 db->lookaside.bEnabled = lookasideEnabled;
91897 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
91905 db->mallocFailed = 1;
91980 sqlite3 *db = sqlite3_context_db_handle(context);
91986 Db *aNew;
92003 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
92004 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
92005 db->aLimit[SQLITE_LIMIT_ATTACHED]
92009 if( !db->autoCommit ){
92010 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
92013 for(i=0; i<db->nDb; i++){
92014 char *z = db->aDb[i].zName;
92017 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
92022 /* Allocate the new entry in the db->aDb[] array and initialize the schema
92025 if( db->aDb==db->aDbStatic ){
92026 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
92028 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
92030 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
92033 db->aDb = aNew;
92034 aNew = &db->aDb[db->nDb];
92041 flags = db->openFlags;
92042 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
92044 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
92051 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
92053 db->nDb++;
92056 zErrDyn = sqlite3MPrintf(db, "database is already attached");
92059 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
92062 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
92063 zErrDyn = sqlite3MPrintf(db,
92069 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
92071 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
92073 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
92078 aNew->zName = sqlite3DbStrDup(db, zName);
92094 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
92102 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
92107 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
92108 if( nKey>0 || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
92109 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
92118 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
92122 sqlite3BtreeEnterAll(db);
92123 rc = sqlite3Init(db, &zErrDyn);
92124 sqlite3BtreeLeaveAll(db);
92129 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
92130 if( newAuth<db->auth.authLevel ){
92136 int iDb = db->nDb - 1;
92138 if( db->aDb[iDb].pBt ){
92139 sqlite3BtreeClose(db->aDb[iDb].pBt);
92140 db->aDb[iDb].pBt = 0;
92141 db->aDb[iDb].pSchema = 0;
92143 sqlite3ResetAllSchemasOfConnection(db);
92144 db->nDb = iDb;
92146 db->mallocFailed = 1;
92147 sqlite3DbFree(db, zErrDyn);
92148 zErrDyn = sqlite3MPrintf(db, "out of memory");
92150 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
92161 sqlite3DbFree(db, zErrDyn);
92180 sqlite3 *db = sqlite3_context_db_handle(context);
92182 Db *pDb = 0;
92188 for(i=0; i<db->nDb; i++){
92189 pDb = &db->aDb[i];
92194 if( i>=db->nDb ){
92202 if( !db->autoCommit ){
92215 sqlite3CollapseDatabaseArray(db);
92238 sqlite3* db = pParse->db;
92274 assert( v || db->mallocFailed );
92289 sqlite3ExprDelete(db, pFilename);
92290 sqlite3ExprDelete(db, pDbname);
92291 sqlite3ExprDelete(db, pKey);
92348 sqlite3 *db;
92350 db = pParse->db;
92351 assert( db->nDb>iDb );
92353 pFix->zDb = db->aDb[iDb].zName;
92354 pFix->pSchema = db->aDb[iDb].pSchema;
92392 sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
92443 if( pFix->pParse->db->init.busy ){
92572 sqlite3 *db,
92577 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
92579 sqlite3_mutex_enter(db->mutex);
92580 db->xAuth = (sqlite3_xauth)xAuth;
92581 db->pAuthArg = pArg;
92582 sqlite3ExpirePreparedStatements(db);
92583 sqlite3_mutex_leave(db->mutex);
92611 sqlite3 *db = pParse->db; /* Database handle */
92612 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
92615 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext
92617 ,db->auth.zAuthUser
92621 if( db->nDb>2 || iDb!=0 ){
92648 sqlite3 *db = pParse->db;
92655 if( db->xAuth==0 ) return;
92656 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
92687 assert( iDb>=0 && iDb<db->nDb );
92706 sqlite3 *db = pParse->db;
92712 if( db->init.busy || IN_DECLARE_VTAB ){
92716 if( db->xAuth==0 ){
92719 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
92721 ,db->auth.zAuthUser
92845 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
92854 pToplevel->db->mallocFailed = 1;
92904 sqlite3 *db;
92908 db = pParse->db;
92910 if( db->mallocFailed || pParse->nErr ){
92926 if( pParse->nTableLock>0 && db->init.busy==0 ){
92927 sqlite3UserAuthInit(db);
92928 if( db->auth.authLevel<UAUTH_User ){
92942 if( db->mallocFailed==0
92948 for(iDb=0; iDb<db->nDb; iDb++){
92956 db->aDb[iDb].pSchema->iGeneration /* P4 */
92958 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
92964 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
92997 if( v && pParse->nErr==0 && !db->mallocFailed ){
93031 sqlite3 *db = pParse->db;
93038 zSql = sqlite3VMPrintf(db, zFormat, ap);
93047 sqlite3DbFree(db, zErrMsg);
93048 sqlite3DbFree(db, zSql);
93075 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
93080 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
93084 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
93088 for(i=OMIT_TEMPDB; i<db->nDb; i++){
93090 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
93091 assert( sqlite3SchemaMutexHeld(db, j, 0) );
93092 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
93122 p = sqlite3FindTable(pParse->db, zName, zDbase);
93126 if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
93130 Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
93144 else if( pParse->db->auth.authLevel<UAUTH_User ){
93169 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
93170 zDb = pParse->db->aDb[iDb].zName;
93189 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
93193 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
93194 for(i=OMIT_TEMPDB; i<db->nDb; i++){
93196 Schema *pSchema = db->aDb[j].pSchema;
93198 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
93199 assert( sqlite3SchemaMutexHeld(db, j, 0) );
93209 static void freeIndex(sqlite3 *db, Index *p){
93211 sqlite3DeleteIndexSamples(db, p);
93213 sqlite3ExprDelete(db, p->pPartIdxWhere);
93214 sqlite3ExprListDelete(db, p->aColExpr);
93215 sqlite3DbFree(db, p->zColAff);
93216 if( p->isResized ) sqlite3DbFree(db, p->azColl);
93220 sqlite3DbFree(db, p);
93229 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
93233 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93234 pHash = &db->aDb[iDb].pSchema->idxHash;
93249 freeIndex(db, pIndex);
93251 db->flags |= SQLITE_InternChanges;
93255 ** Look through the list of open database files in db->aDb[] and if
93257 ** db->aDb[] structure to a smaller size, if possible.
93262 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3 *db){
93264 for(i=j=2; i<db->nDb; i++){
93265 struct Db *pDb = &db->aDb[i];
93267 sqlite3DbFree(db, pDb->zName);
93272 db->aDb[j] = db->aDb[i];
93276 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
93277 db->nDb = j;
93278 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
93279 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
93280 sqlite3DbFree(db, db->aDb);
93281 db->aDb = db->aDbStatic;
93289 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){
93290 Db *pDb;
93291 assert( iDb<db->nDb );
93294 pDb = &db->aDb[iDb];
93295 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93304 pDb = &db->aDb[1];
93315 db){
93317 sqlite3BtreeEnterAll(db);
93318 for(i=0; i<db->nDb; i++){
93319 Db *pDb = &db->aDb[i];
93324 db->flags &= ~SQLITE_InternChanges;
93325 sqlite3VtabUnlockList(db);
93326 sqlite3BtreeLeaveAll(db);
93327 sqlite3CollapseDatabaseArray(db);
93333 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
93334 db->flags &= ~SQLITE_InternChanges;
93341 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
93347 sqlite3DbFree(db, pCol->zName);
93348 sqlite3ExprDelete(db, pCol->pDflt);
93349 sqlite3DbFree(db, pCol->zDflt);
93350 sqlite3DbFree(db, pCol->zType);
93351 sqlite3DbFree(db, pCol->zColl);
93353 sqlite3DbFree(db, pTable->aCol);
93366 ** The db parameter is optional. It is needed if the Table object
93369 ** db parameter can be used with db->pnBytesFreed to measure the memory
93372 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
93380 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
93385 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
93386 db->lookaside.nOut : 0 );
93392 if( !db || db->pnBytesFreed==0 ){
93397 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
93400 freeIndex(db, pIndex);
93404 sqlite3FkDelete(db, pTable);
93408 sqlite3DeleteColumnNames(db, pTable);
93409 sqlite3DbFree(db, pTable->zName);
93410 sqlite3DbFree(db, pTable->zColAff);
93411 sqlite3SelectDelete(db, pTable->pSelect);
93412 sqlite3ExprListDelete(db, pTable->pCheck);
93414 sqlite3VtabClear(db, pTable);
93416 sqlite3DbFree(db, pTable);
93419 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
93426 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
93428 Db *pDb;
93430 assert( db!=0 );
93431 assert( iDb>=0 && iDb<db->nDb );
93433 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93435 pDb = &db->aDb[iDb];
93437 sqlite3DeleteTable(db, p);
93438 db->flags |= SQLITE_InternChanges;
93454 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
93457 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
93480 ** of a database ("main", "temp" or the name of an attached db). This
93481 ** function returns the index of the named database in db->aDb[], or
93482 ** -1 if the named db cannot be found.
93484 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
93487 Db *pDb;
93489 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
93501 ** "temp" or the name of an attached db). This routine returns the
93502 ** index of the named database in db->aDb[], or -1 if the named db
93505 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
93508 zName = sqlite3NameFromToken(db, pName);
93509 i = sqlite3FindDbName(db, zName);
93510 sqlite3DbFree(db, zName);
93537 sqlite3 *db = pParse->db;
93540 if( db->init.busy ) {
93545 iDb = sqlite3FindDb(db, pName1);
93551 assert( db->init.iDb==0 || db->init.busy );
93552 iDb = db->init.iDb;
93566 if( !pParse->db->init.busy && pParse->nested==0
93567 && (pParse->db->flags & SQLITE_WriteSchema)==0
93623 sqlite3 *db = pParse->db;
93656 zName = sqlite3NameFromToken(db, pName);
93661 if( db->init.iDb==1 ) isTemp = 1;
93666 char *zDb = db->aDb[iDb].zName;
93697 char *zDb = db->aDb[iDb].zName;
93701 pTable = sqlite3FindTable(db, zName, zDb);
93706 assert( !db->init.busy || CORRUPT_DB );
93711 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
93717 pTable = sqlite3DbMallocZero(db, sizeof(Table));
93719 db->mallocFailed = 1;
93726 pTable->pSchema = db->aDb[iDb].pSchema;
93738 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93751 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
93774 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
93778 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
93812 sqlite3DbFree(db, zName);
93842 sqlite3 *db = pParse->db;
93845 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
93850 z = sqlite3NameFromToken(db, pName);
93855 sqlite3DbFree(db, z);
93861 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
93863 sqlite3DbFree(db, z);
93998 sqlite3DbFree(pParse->db, pCol->zType);
93999 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
94016 sqlite3 *db = pParse->db;
94020 if( !sqlite3ExprIsConstantOrFunction(pSpan->pExpr, db->init.busy) ){
94028 sqlite3ExprDelete(db, pCol->pDflt);
94029 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
94030 sqlite3DbFree(db, pCol->zDflt);
94031 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
94035 sqlite3ExprDelete(db, pSpan->pExpr);
94146 sqlite3ExprListDelete(pParse->db, pList);
94159 sqlite3 *db = pParse->db;
94161 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
94170 sqlite3ExprDelete(pParse->db, pCheckExpr);
94182 sqlite3 *db;
94186 db = pParse->db;
94187 zColl = sqlite3NameFromToken(db, pToken);
94192 sqlite3DbFree(db, p->aCol[i].zColl);
94206 sqlite3DbFree(db, zColl);
94231 sqlite3 *db = pParse->db;
94232 u8 enc = ENC(db);
94233 u8 initbusy = db->init.busy;
94236 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
94263 sqlite3 *db = pParse->db;
94265 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94266 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
94328 static char *createTableStmt(sqlite3 *db, Table *p){
94350 db->mallocFailed = 1;
94396 static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
94402 zExtra = sqlite3DbMallocZero(db, nByte);
94481 sqlite3 *db = pParse->db;
94502 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
94518 assert( db->init.busy==0 );
94542 if( !db->init.imposterTable ){
94566 if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
94581 if( resizeIndexObject(db, pPk, pTab->nCol) ) return;
94606 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
94625 sqlite3 *db = pParse->db; /* The database connection */
94632 assert( !db->mallocFailed );
94636 assert( !db->init.busy || !pSelect );
94638 /* If the db->init.busy is 1 it means we are reading the SQL off the
94641 ** for the table from the db->init.newTnum field. (The page number
94644 if( db->init.busy ){
94645 p->tnum = db->init.newTnum;
94663 iDb = sqlite3SchemaToIndex(db, p->pSchema);
94685 if( !db->init.busy ){
94756 sqlite3DeleteTable(db, pSelTab);
94770 zStmt = createTableStmt(db, p);
94775 zStmt = sqlite3MPrintf(db,
94788 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
94796 sqlite3DbFree(db, zStmt);
94804 Db *pDb = &db->aDb[iDb];
94805 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94817 sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
94823 if( db->init.busy ){
94826 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94830 db->mallocFailed = 1;
94834 db->flags |= SQLITE_InternChanges;
94872 sqlite3 *db = pParse->db;
94882 iDb = sqlite3SchemaToIndex(db, p->pSchema);
94891 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
94892 p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
94893 if( db->mallocFailed ) goto create_view_fail;
94915 sqlite3SelectDelete(db, pSelect);
94916 sqlite3ExprListDelete(db, pCNames);
94932 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
94934 u8 bEnabledLA; /* Saved db->lookaside.bEnabled state */
94980 bEnabledLA = db->lookaside.bEnabled;
94982 db->lookaside.bEnabled = 0;
94986 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
94991 db->lookaside.bEnabled = 0;
94993 xAuth = db->xAuth;
94994 db->xAuth = 0;
94996 db->xAuth = xAuth;
95007 sqlite3DeleteTable(db, pSelTab);
95008 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
95013 sqlite3SelectDelete(db, pSel);
95018 db->lookaside.bEnabled = bEnabledLA;
95029 static void sqliteViewResetAll(sqlite3 *db, int idx){
95031 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
95032 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
95033 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
95036 sqlite3DeleteColumnNames(db, pTab);
95041 DbClearProperty(db, idx, DB_UnresetViews);
95065 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
95068 Db *pDb;
95070 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95071 pDb = &db->aDb[iDb];
95112 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
95126 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
95168 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
95169 assert( iDb>=0 && iDb<pParse->db->nDb );
95188 const char *zDbName = pParse->db->aDb[iDb].zName;
95192 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
95206 sqlite3 *db = pParse->db;
95208 Db *pDb = &db->aDb[iDb];
95227 pTrigger->pSchema==db->aDb[1].pSchema );
95268 sqliteViewResetAll(db, iDb);
95278 sqlite3 *db = pParse->db;
95281 if( db->mallocFailed ){
95287 if( noErr ) db->suppressErr++;
95289 if( noErr ) db->suppressErr--;
95295 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95296 assert( iDb>=0 && iDb<db->nDb );
95308 const char *zDb = db->aDb[iDb].zName;
95322 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
95371 sqlite3SrcListDelete(db, pName);
95397 sqlite3 *db = pParse->db;
95433 pFKey = sqlite3DbMallocZero(db, nByte );
95478 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
95483 db->mallocFailed = 1;
95498 sqlite3DbFree(db, pFKey);
95500 sqlite3ExprListDelete(db, pFromCol);
95501 sqlite3ExprListDelete(db, pToCol);
95544 sqlite3 *db = pParse->db; /* The database connection */
95545 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
95549 db->aDb[iDb].zName ) ){
95588 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
95620 sqlite3 *db, /* Database connection */
95633 p = sqlite3DbMallocZero(db, nByte + nExtra);
95683 sqlite3 *db = pParse->db;
95684 Db *pDb; /* The specific table containing the indexed database */
95693 if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
95706 ** to search for the table. 'Fix' the table name to this db
95719 if( !db->init.busy ){
95721 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
95734 assert( db->mallocFailed==0 || pTab==0 );
95736 if( iDb==1 && db->aDb[iDb].pSchema!=pTab->pSchema ){
95748 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
95750 pDb = &db->aDb[iDb];
95755 && db->init.busy==0
95790 zName = sqlite3NameFromToken(db, pName);
95796 if( !db->init.busy ){
95797 if( sqlite3FindTable(db, zName, 0)!=0 ){
95802 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
95806 assert( !db->init.busy );
95815 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
95846 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
95870 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
95872 if( db->mallocFailed ){
95884 pIndex->pSchema = db->aDb[iDb].pSchema;
95891 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95926 ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
95928 if( !db->mallocFailed ){
95960 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
96059 if( db->init.busy ){
96061 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
96066 db->mallocFailed = 1;
96069 db->flags |= SQLITE_InternChanges;
96071 pIndex->tnum = db->init.newTnum;
96114 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
96126 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
96132 sqlite3DbFree(db, zStmt);
96141 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
96154 if( db->init.busy || pTblName==0 ){
96173 if( pIndex ) freeIndex(db, pIndex);
96174 sqlite3ExprDelete(db, pPIWhere);
96175 sqlite3ExprListDelete(db, pList);
96176 sqlite3SrcListDelete(db, pTblName);
96177 sqlite3DbFree(db, zName);
96230 sqlite3 *db = pParse->db;
96234 if( db->mallocFailed ){
96241 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
96256 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
96261 const char *zDb = db->aDb[iDb].zName;
96279 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
96288 sqlite3SrcListDelete(db, pName);
96309 sqlite3 *db, /* Connection to notify of malloc failures */
96319 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
96339 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
96342 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
96346 db,
96353 sqlite3IdListDelete(db, pList);
96356 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
96363 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
96367 sqlite3DbFree(db, pList->a[i].zName);
96369 sqlite3DbFree(db, pList->a);
96370 sqlite3DbFree(db, pList);
96394 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
96403 ** db->mallocFailed flag will be set to true.
96406 sqlite3 *db, /* Database connection to notify of OOM errors */
96424 pNew = sqlite3DbRealloc(db, pSrc,
96427 assert( db->mallocFailed );
96431 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
96488 sqlite3 *db, /* Connection to notify of malloc failures */
96496 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
96500 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
96501 if( db->mallocFailed ){
96502 sqlite3SrcListDelete(db, pList);
96514 pItem->zName = sqlite3NameFromToken(db, pTable);
96515 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
96525 assert(pList || pParse->db->mallocFailed );
96540 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
96545 sqlite3DbFree(db, pItem->zDatabase);
96546 sqlite3DbFree(db, pItem->zName);
96547 sqlite3DbFree(db, pItem->zAlias);
96548 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
96549 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
96550 sqlite3DeleteTable(db, pItem->pTab);
96551 sqlite3SelectDelete(db, pItem->pSelect);
96552 sqlite3ExprDelete(db, pItem->pOn);
96553 sqlite3IdListDelete(db, pItem->pUsing);
96555 sqlite3DbFree(db, pList);
96585 sqlite3 *db = pParse->db;
96592 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
96599 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
96608 sqlite3ExprDelete(db, pOn);
96609 sqlite3IdListDelete(db, pUsing);
96610 sqlite3SelectDelete(db, pSubquery);
96630 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
96649 sqlite3ExprListDelete(pParse->db, pList);
96682 sqlite3 *db;
96687 db = pParse->db;
96688 assert( db!=0 );
96689 /* if( db->aDb[0].pBt==0 ) return; */
96696 for(i=0; i<db->nDb; i++){
96711 assert( pParse->db!=0 );
96728 assert( pParse->db!=0 );
96743 char *zName = sqlite3NameFromToken(pParse->db, pName);
96751 sqlite3DbFree(pParse->db, zName);
96763 sqlite3 *db = pParse->db;
96764 if( db->aDb[1].pBt==0 && !pParse->explain ){
96774 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
96781 db->aDb[1].pBt = pBt;
96782 assert( db->aDb[1].pSchema );
96783 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
96784 db->mallocFailed = 1;
96799 sqlite3 *db = pToplevel->db;
96801 assert( iDb>=0 && iDb<db->nDb );
96802 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
96804 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
96807 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
96819 sqlite3 *db = pParse->db;
96821 for(i=0; i<db->nDb; i++){
96822 Db *pDb = &db->aDb[i];
96917 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
96948 zMsg = sqlite3MPrintf(pParse->db, "%s.%s", pTab->zName,
96952 zMsg = sqlite3MPrintf(pParse->db, "%s.rowid", pTab->zName);
96988 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
97003 Db *pDb; /* A single database */
97005 sqlite3 *db = pParse->db; /* The database connection */
97009 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
97010 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
97041 sqlite3 *db = pParse->db; /* The database connection */
97056 zColl = sqlite3NameFromToken(pParse->db, pName1);
97058 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
97061 sqlite3DbFree(db, zColl);
97064 sqlite3DbFree(db, zColl);
97068 z = sqlite3NameFromToken(db, pObjName);
97070 zDb = db->aDb[iDb].zName;
97071 pTab = sqlite3FindTable(db, z, zDb);
97074 sqlite3DbFree(db, z);
97077 pIndex = sqlite3FindIndex(db, z, zDb);
97078 sqlite3DbFree(db, z);
97105 pKey = sqlite3KeyInfoAlloc(pParse->db, nKey, nCol-nKey);
97107 pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
97138 sqlite3 *db = pParse->db;
97144 zName = sqlite3NameFromToken(pParse->db, pName);
97156 pNew = sqlite3DbRealloc(db, pWith, nByte);
97158 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
97161 assert( db->mallocFailed==0 || pNew==0 );
97164 sqlite3ExprListDelete(db, pArglist);
97165 sqlite3SelectDelete(db, pQuery);
97166 sqlite3DbFree(db, zName);
97182 SQLITE_PRIVATE void sqlite3WithDelete(sqlite3 *db, With *pWith){
97187 sqlite3ExprListDelete(db, pCte->pCols);
97188 db, pCte->pSelect);
97189 sqlite3DbFree(db, pCte->zName);
97191 sqlite3DbFree(db, pWith);
97220 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
97221 assert( !db->xCollNeeded || !db->xCollNeeded16 );
97222 if( db->xCollNeeded ){
97223 char *zExternal = sqlite3DbStrDup(db, zName);
97225 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
97226 sqlite3DbFree(db, zExternal);
97229 if( db->xCollNeeded16 ){
97231 sqlite3_value *pTmp = sqlite3ValueNew(db);
97235 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
97249 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
97255 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
97274 ** db for collation type name zName, length nName, or NULL, if no collation
97286 sqlite3 *db = pParse->db;
97290 p = sqlite3FindCollSeq(db, enc, zName, 0);
97296 callCollNeeded(db, enc, zName);
97297 p = sqlite3FindCollSeq(db, enc, zName, 0);
97299 if( p && !p->xCmp && synthCollSeq(db, p) ){
97323 sqlite3 *db = pParse->db;
97324 CollSeq *p = sqlite3GetCollSeq(pParse, ENC(db), pColl, zName);
97336 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
97349 sqlite3 *db, /* Database connection */
97354 pColl = sqlite3HashFind(&db->aCollSeq, zName);
97358 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1);
97369 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
97377 db->mallocFailed = 1;
97378 sqlite3DbFree(db, pDel);
97389 ** for the encoding 'enc' from the database 'db'.
97402 sqlite3 *db,
97409 pColl = findCollSeqEntry(db, zName, create);
97411 pColl = db->pDfltColl;
97530 ** structure is created and liked into the "db" structure if a
97543 sqlite3 *db, /* An open database */
97557 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
97561 p = functionSearch(&db->aFunc, h, zName, nName);
97583 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
97602 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
97608 sqlite3FuncDefInsert(&db->aFunc, pBest);
97619 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
97657 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
97665 db->mallocFailed = 1;
97713 sqlite3DeleteTable(pParse->db, pItem->pTab);
97741 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
97743 && (pParse->db->flags & SQLITE_WriteSchema)==0
97775 sqlite3 *db = pParse->db;
97776 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
97777 pWhere = sqlite3ExprDup(db, pWhere, 0);
97778 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
97781 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
97782 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
97789 sqlite3SelectDelete(db, pSel);
97850 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
97852 sqlite3ExprListDelete(pParse->db, pEList);
97874 sqlite3SelectDelete(pParse->db, pSelect);
97878 sqlite3ExprDelete(pParse->db, pWhere);
97879 sqlite3ExprListDelete(pParse->db, pOrderBy);
97880 sqlite3ExprDelete(pParse->db, pLimit);
97881 sqlite3ExprDelete(pParse->db, pOffset);
97909 sqlite3 *db; /* Main database structure */
97936 db = pParse->db;
97937 if( pParse->nErr || db->mallocFailed ){
97976 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
97977 assert( iDb<db->nDb );
97978 zDb = db->aDb[iDb].zName;
98031 if( db->flags & SQLITE_CountRows ){
98095 if( db->flags & SQLITE_CountRows ){
98118 aToOpen = sqlite3DbMallocRaw(db, nIdx+2);
98134 sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
98192 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
98246 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
98254 sqlite3SrcListDelete(db, pTabList);
98255 sqlite3ExprDelete(db, pWhere);
98256 sqlite3DbFree(db, aToOpen);
98807 sqlite3 *db = sqlite3_context_db_handle(context);
98813 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
98971 sqlite3 *db = sqlite3_context_db_handle(context);
98973 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
98974 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
98975 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
99097 sqlite3 *db = sqlite3_context_db_handle(context);
99102 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
99117 sqlite3 *db = sqlite3_context_db_handle(context);
99119 sqlite3_result_int(context, sqlite3_changes(db));
99131 sqlite3 *db = sqlite3_context_db_handle(context);
99135 sqlite3_result_int(context, sqlite3_total_changes(db));
99368 sqlite3 *db = sqlite3_context_db_handle(context);
99377 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
99378 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
99379 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
99765 sqlite3 *db = sqlite3_context_db_handle(context);
99767 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
99768 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
99769 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
99946 sqlite3 *db = sqlite3_context_db_handle(context);
99954 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
100092 ** returns (void *)db, where db is the sqlite3* database pointer.
100104 pBest->db = sqlite3_context_db_handle(context);
100136 sqlite3 *db = sqlite3_context_db_handle(context);
100138 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
100174 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
100175 int rc = sqlite3_overload_function(db, "MATCH", 2);
100178 db->mallocFailed = 1;
100185 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
100187 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
100199 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
100206 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
100207 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
100208 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
100210 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
100211 setLikeOptFlag(db, "like",
100227 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
100236 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
100552 ** pParse->db->mallocFailed flag is set.
100593 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
100657 sqlite3DbFree(pParse->db, aiCol);
100793 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
100801 if( !pFKey->isDeferred && !(pParse->db->flags & SQLITE_DeferFKs)
100841 sqlite3 *db = pParse->db;
100843 pExpr = sqlite3Expr(db, TK_REGISTER, 0);
100850 if( zColl==0 ) zColl = db->pDfltColl->zName;
100865 sqlite3 *db, /* The database connection */
100870 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
100887 ** the number of FK violations in the db) or +1 when deleting one (as this
100921 sqlite3 *db = pParse->db; /* Database handle */
100959 pRight = sqlite3Expr(db, TK_ID, zCol);
100961 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
100981 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
100991 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
100993 pAll = sqlite3ExprAnd(db, pAll, pEq);
100997 pWhere = sqlite3ExprAnd(db, pWhere, pNe);
101016 sqlite3ExprDelete(db, pWhere);
101077 sqlite3 *db = pParse->db;
101078 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
101091 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
101099 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
101111 if( (db->flags & SQLITE_DeferFKs)==0 ){
101234 sqlite3 *db = pParse->db; /* Database handle */
101244 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
101246 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
101247 zDb = db->aDb[iDb].zName;
101272 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
101278 if( !isIgnoreErrors || db->mallocFailed ) return;
101314 if( db->xAuth ){
101347 sqlite3DbFree(db, aiFree);
101361 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
101371 if( !isIgnoreErrors || db->mallocFailed ) return;
101378 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
101414 sqlite3SrcListDelete(db, pSrc);
101416 sqlite3DbFree(db, aiCol);
101431 if( pParse->db->flags&SQLITE_ForeignKeys ){
101472 if( pParse->db->flags&SQLITE_ForeignKeys ){
101532 sqlite3 *db = pParse->db; /* Database handle */
101541 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
101580 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
101581 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
101583 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
101585 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
101595 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
101596 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
101599 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
101600 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
101603 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
101610 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
101611 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
101616 pNew = sqlite3ExprDup(db, pDflt, 0);
101627 sqlite3DbFree(db, aiCol);
101638 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
101644 sqlite3SrcListAppend(db, 0, &tFrom, 0),
101652 enableLookaside = db->lookaside.bEnabled;
101653 db->lookaside.bEnabled = 0;
101655 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
101665 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
101666 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
101667 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
101670 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
101675 db->lookaside.bEnabled = enableLookaside;
101677 sqlite3ExprDelete(db, pWhere);
101678 sqlite3ExprDelete(db, pWhen);
101679 sqlite3ExprListDelete(db, pList);
101680 sqlite3SelectDelete(db, pSelect);
101681 if( db->mallocFailed==1 ){
101682 fkTriggerDelete(db, pTrigger);
101725 if( pParse->db->flags&SQLITE_ForeignKeys ){
101745 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
101749 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
101753 if( !db || db->pnBytesFreed==0 ){
101773 fkTriggerDelete(db, pFKey->apTrigger[0]);
101774 fkTriggerDelete(db, pFKey->apTrigger[1]);
101778 sqlite3DbFree(db, pFKey);
101856 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
101870 db->mallocFailed = 1;
101918 sqlite3 *db = sqlite3VdbeDb(v);
101921 db->mallocFailed = 1;
101954 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
102017 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
102038 sqlite3 *db = pParse->db; /* The database connection */
102039 Db *pDb; /* Database only autoinc table */
102051 pDb = &db->aDb[p->iDb];
102053 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
102095 sqlite3 *db = pParse->db;
102099 Db *pDb = &db->aDb[p->iDb];
102105 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
102240 sqlite3 *db; /* The main database structure */
102258 Db *pDb; /* The database containing table being inserted into */
102280 db = pParse->db;
102282 if( pParse->nErr || db->mallocFailed ){
102293 sqlite3SelectDelete(db, pSelect);
102306 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
102307 assert( iDb<db->nDb );
102308 pDb = &db->aDb[iDb];
102446 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
102541 if( db->flags & SQLITE_CountRows ){
102551 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
102750 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
102770 if( (db->flags & SQLITE_CountRows)!=0 ){
102815 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
102822 sqlite3SrcListDelete(db, pTabList);
102823 sqlite3ExprListDelete(db, pList);
102824 sqlite3SelectDelete(db, pSelect);
102825 sqlite3IdListDelete(db, pColumn);
102826 sqlite3DbFree(db, aRegIdx);
102941 sqlite3 *db; /* Database connection */
102956 db = pParse->db;
103002 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
103029 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
103129 if( db->flags&SQLITE_RecTriggers ){
103317 if( db->flags&SQLITE_RecTriggers ){
103455 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
103589 sqlite3 *db = pParse->db;
103737 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
103741 if( (db->flags & SQLITE_CountRows)!=0 ){
103752 iDbSrc = sqlite3SchemaToIndex(db, pSrc->pSchema);
103762 if( (db->flags & SQLITE_Vacuum)==0 && (
103830 if( db->flags & SQLITE_Vacuum ){
103911 sqlite3 *db, /* The database on which the SQL executes */
103923 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
103926 sqlite3_mutex_enter(db->mutex);
103927 sqlite3Error(db, SQLITE_OK);
103933 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
103954 && db->flags&SQLITE_NullCallback)) ){
103956 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
103973 db->mallocFailed = 1;
103985 sqlite3Error(db, SQLITE_ABORT);
103999 sqlite3DbFree(db, azCols);
104005 sqlite3DbFree(db, azCols);
104007 rc = sqlite3ApiExit(db, rc);
104009 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
104012 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
104015 sqlite3Error(db, SQLITE_NOMEM);
104021 assert( (rc&db->errMask)==rc );
104022 sqlite3_mutex_leave(db->mutex);
104144 int (*errcode)(sqlite3*db);
104991 ** by calling sqlite3DbFree(db, ).
104994 sqlite3 *db, /* Load the extension into this database connection */
104999 sqlite3_vfs *pVfs = db->pVfs;
105029 if( (db->flags & SQLITE_LoadExtension)==0 ){
105109 if( xInit(db, &zErrmsg, &sqlite3Apis) ){
105118 /* Append the new shared library handle to the db->aExtension array. */
105119 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
105123 if( db->nExtension>0 ){
105124 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
105126 sqlite3DbFree(db, db->aExtension);
105127 db->aExtension = aHandle;
105129 db->aExtension[db->nExtension++] = handle;
105133 sqlite3 *db, /* Load the extension into this database connection */
105139 sqlite3_mutex_enter(db->mutex);
105140 rc = sqlite3LoadExtension(db
105141 rc = sqlite3ApiExit(db, rc);
105142 sqlite3_mutex_leave(db->mutex);
105150 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
105152 assert( sqlite3_mutex_held(db->mutex) );
105153 for(i=0; i<db->nExtension; i++){
105154 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
105156 sqlite3DbFree(db, db->aExtension);
105163 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
105164 sqlite3_mutex_enter(db->mutex);
105166 db->flags |= SQLITE_LoadExtension;
105168 db->flags &= ~SQLITE_LoadExtension;
105170 sqlite3_mutex_leave(db->mutex);
105310 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
105336 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
105337 sqlite3ErrorWithMsg(db, rc,
105919 ** Interpret the given string as a temp db location. Return 1 for file
105942 sqlite3 *db = pParse->db;
105943 if( db->aDb[1].pBt!=0 ){
105944 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
105949 sqlite3BtreeClose(db->aDb[1].pBt);
105950 db->aDb[1].pBt = 0;
105951 sqlite3ResetAllSchemasOfConnection(db);
105965 sqlite3 *db = pParse->db;
105966 if( db->temp_store==ts ) return SQLITE_OK;
105970 db->temp_store = (u8)ts;
106023 static void setAllPagerFlags(sqlite3 *db){
106024 if( db->autoCommit ){
106025 Db *pDb = db->aDb;
106026 int n = db->nDb;
106036 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) );
106120 sqlite3 *db = pParse->db; /* The database connection */
106121 Db *pDb; /* The specific database being pragmaed */
106130 ** index of the database this pragma is being applied to in db.aDb[]. */
106133 pDb = &db->aDb[iDb];
106142 zLeft = sqlite3NameFromToken(db, pId);
106145 zRight = sqlite3MPrintf(db, "-%T", pValue);
106147 zRight = sqlite3NameFromToken(db, pValue);
106175 db->busyHandler.nBusy = 0;
106176 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
106260 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
106288 db->nextPagesize = sqlite3Atoi(zRight);
106289 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
106290 db->mallocFailed = 1;
106313 for(ii=0; ii<db->nDb; ii++){
106314 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
106368 eMode = db->dfltLockMode;
106374 ** set on all attached databases, as well as the main db file.
106381 assert(pDb==&db->aDb[0]);
106382 for(ii=2; ii<db->nDb; ii++){
106383 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
106386 db->dfltLockMode = (u8)eMode;
106432 for(ii=db->nDb-1; ii>=0; ii--){
106433 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
106478 db->nextAutovac = (u8)eAuto;
106482 ** as an auto-vacuum capable db.
106549 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
106579 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
106584 if( pId2->n==0 ) db->szMmap = sz;
106585 for(ii=db->nDb-1; ii>=0; ii--){
106586 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
106587 sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz);
106592 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
106619 returnSingleInt(v, "temp_store", db->temp_store);
106643 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
106650 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
106651 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
106687 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
106755 if( !db->autoCommit ){
106762 setAllPagerFlags(db);
106772 returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
106775 if( db->autoCommit==0 ){
106781 if( db->auth.authLevel==UAUTH_User ){
106788 db->flags |= mask;
106790 db->flags &= ~mask;
106791 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
106799 setAllPagerFlags(db);
106820 pTab = sqlite3FindTable(db, zRight, zDb);
106888 pIdx = sqlite3FindIndex(db, zRight, zDb);
106928 pTab = sqlite3FindTable(db, zRight, zDb);
106956 for(i=0; i<db->nDb; i++){
106957 if( db->aDb[i].pBt==0 ) continue;
106958 assert( db->aDb[i].zName!=0 );
106961 db->aDb[i].zName,
106962 sqlite3BtreeGetFilename(db->aDb[i].pBt));
106974 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
106987 pTab = sqlite3FindTable(db, zRight, zDb);
107049 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
107064 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
107086 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
107117 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
107126 sqlite3DbFree(db, aiCols);
107154 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
107185 /* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
107186 ** then iDb is set to the index of the database identified by <db>.
107213 for(i=0; i<db->nDb; i++){
107232 assert( sqlite3SchemaMutexHeld(db, i, 0) );
107233 pTbls = &db->aDb[i].pSchema->tblHash;
107257 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
107300 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
107431 returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
107439 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
107440 DbHasProperty(db, 0, DB_Empty)
107444 SCHEMA_ENC(db) = ENC(db) =
107578 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
107581 db->xWalCallback==sqlite3WalDefaultHook ?
107582 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
107595 sqlite3_db_release_memory(db);
107603 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
107611 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
107613 returnSingleInt(v, "timeout", db->busyTimeout);
107650 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
107653 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
107669 for(i=0; i<db->nDb; i++){
107673 if( db->aDb[i].zName==0 ) continue;
107674 pBt = db->aDb[i].pBt;
107677 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
107681 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
107690 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
107694 if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
107707 sqlite3_key_v2(db, zDb, zKey, i/2);
107709 sqlite3_rekey_v2(db, zDb, zKey, i/2);
107734 sqlite3DbFree(db, zLeft);
107735 sqlite3DbFree(db, zRight);
107768 sqlite3 *db = pData->db;
107769 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
107774 sqlite3DbFree(db, *pData->pzErrMsg);
107776 if( z==0 ) db->mallocFailed = 1;
107778 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT;
107795 sqlite3 *db = pData->db;
107800 assert( sqlite3_mutex_held(db->mutex) );
107801 DbClearProperty(db, iDb, DB_Empty);
107802 if( db->mallocFailed ){
107807 assert( iDb>=0 && iDb<db->nDb );
107813 ** But because db->init.busy is set to 1, no VDBE code is generated
107821 assert( db->init.busy );
107822 db->init.iDb = iDb;
107823 db->init.newTnum = sqlite3Atoi(argv[1]);
107824 db->init.orphanTrigger = 0;
107825 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
107826 rc = db->errCode;
107828 db->init.iDb = 0;
107830 if( db->init.orphanTrigger ){
107835 db->mallocFailed = 1;
107837 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
107852 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
107875 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
107882 Db *pDb;
107916 assert( iDb>=0 && iDb<db->nDb );
107917 assert( db->aDb[iDb].pSchema );
107918 assert( sqlite3_mutex_held(db->mutex) );
107919 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
107937 initData.db = db;
107946 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
107953 pDb = &db->aDb[iDb];
107956 DbSetProperty(db, 1, DB_SchemaLoaded);
107968 sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc));
107981 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
107998 ** For an attached db, it is an error if the encoding is not the same
108005 /* If opening the main database, set ENC(db). */
108008 ENC(db) = encoding;
108010 ENC(db) = SQLITE_UTF8;
108013 /* If opening an attached database, the encoding much match ENC(db) */
108014 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
108015 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
108022 DbSetProperty(db, iDb, DB_Empty);
108024 pDb->pSchema->enc = ENC(db);
108048 sqlite3SetString(pzErrMsg, db, "unsupported file format");
108059 db->flags &= ~SQLITE_LegacyFileFmt;
108064 assert( db->init.busy );
108067 zSql = sqlite3MPrintf(db,
108069 db->aDb[iDb].zName, zMasterName);
108073 xAuth = db->xAuth;
108074 db->xAuth = 0;
108076 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
108078 db->xAuth = xAuth;
108082 sqlite3DbFree(db, zSql);
108085 sqlite3AnalysisLoad(db, iDb);
108089 if( db->mallocFailed ){
108091 sqlite3ResetAllSchemasOfConnection(db);
108093 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
108102 DbSetProperty(db, iDb, DB_SchemaLoaded);
108118 db->mallocFailed = 1;
108130 ** bit is set in the flags field of the Db structure. If the database
108133 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
108135 int commit_internal = !(db->flags&SQLITE_InternChanges);
108137 assert( sqlite3_mutex_held(db->mutex) );
108138 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
108139 assert( db->init.busy==0 );
108141 db->init.busy = 1;
108142 ENC(db) = SCHEMA_ENC(db);
108143 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
108144 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
108145 rc = sqlite3InitOne(db, i, pzErrMsg);
108147 sqlite3ResetOneSchema(db, i);
108156 assert( db->nDb>1 );
108157 if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
108158 rc = sqlite3InitOne(db, 1, pzErrMsg);
108160 sqlite3ResetOneSchema(db, 1);
108165 db->init.busy = 0;
108167 sqlite3CommitInternalChanges(db);
108179 sqlite3 *db = pParse->db;
108180 assert( sqlite3_mutex_held(db->mutex) );
108181 if( !db->init.busy ){
108182 rc = sqlite3Init(db, &pParse->zErrMsg);
108198 sqlite3 *db = pParse->db;
108204 assert( sqlite3_mutex_held(db->mutex) );
108205 for(iDb=0; iDb<db->nDb; iDb++){
108207 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
108216 db->mallocFailed = 1;
108226 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
108227 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
108228 sqlite3ResetOneSchema(db, iDb);
108241 ** which database file in db->aDb[] the schema refers to.
108246 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
108255 ** -1000000 as the incorrect index into db->aDb[] is much
108259 assert( sqlite3_mutex_held(db->mutex) );
108261 for(i=0; ALWAYS(i<db->nDb); i++){
108262 if( db->aDb[i].pSchema==pSchema ){
108266 assert( i>=0 && i<db->nDb );
108276 sqlite3 *db = pParse->db;
108277 sqlite3DbFree(db, pParse->aLabel);
108278 sqlite3ExprListDelete(db, pParse->pConstExpr);
108286 sqlite3 *db, /* Database handle. */
108300 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
108307 assert( !db->mallocFailed );
108308 assert( sqlite3_mutex_held(db->mutex) );
108333 for(i=0; i<db->nDb; i++) {
108334 Btree *pBt = db->aDb[i].pBt;
108339 const char *zDb = db->aDb[i].zName;
108340 sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
108341 testcase( db->flags & SQLITE_ReadUncommitted );
108347 sqlite3VtabUnlockList(db);
108349 pParse->db = db;
108353 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
108357 sqlite3ErrorWithMsg(db, SQLITE_TOOBIG, "statement too long");
108358 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
108361 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
108364 sqlite3DbFree(db, zSqlCopy);
108374 if( db->mallocFailed ){
108381 if( db->mallocFailed ){
108412 if( db->init.busy==0 ){
108416 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
108424 sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg);
108425 sqlite3DbFree(db, zErrMsg);
108427 sqlite3Error(db, rc);
108434 sqlite3DbFree(db, pT);
108440 sqlite3StackFree(db, pParse);
108441 rc = sqlite3ApiExit(db, rc);
108442 assert( (rc&db->errMask)==rc );
108446 sqlite3 *db, /* Database handle. */
108460 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
108463 sqlite3_mutex_enter(db->mutex);
108464 sqlite3BtreeEnterAll(db);
108465 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
108468 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
108470 sqlite3BtreeLeaveAll(db);
108471 sqlite3_mutex_leave(db->mutex);
108488 sqlite3 *db;
108493 db = sqlite3VdbeDb(p);
108494 assert( sqlite3_mutex_held(db->mutex) );
108495 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
108498 db->mallocFailed = 1;
108522 sqlite3 *db, /* Database handle. */
108529 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
108534 sqlite3 *db, /* Database handle. */
108541 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
108552 sqlite3 *db, /* Database handle. */
108571 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
108580 sqlite3_mutex_enter(db->mutex);
108581 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
108583 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
108595 sqlite3DbFree(db, zSql8);
108596 rc = sqlite3ApiExit(db, rc);
108597 sqlite3_mutex_leave(db->mutex);
108610 sqlite3 *db, /* Database handle. */
108617 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
108622 sqlite3 *db, /* Database handle. */
108629 rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
108702 static void clearSelect(sqlite3 *db, Select *p, int bFree){
108705 sqlite3ExprListDelete(db, p->pEList);
108706 sqlite3SrcListDelete(db, p->pSrc);
108707 sqlite3ExprDelete(db, p->pWhere);
108708 sqlite3ExprListDelete(db, p->pGroupBy);
108709 sqlite3ExprDelete(db, p->pHaving);
108710 sqlite3ExprListDelete(db, p->pOrderBy);
108711 sqlite3ExprDelete(db, p->pLimit);
108712 sqlite3ExprDelete(db, p->pOffset);
108713 sqlite3WithDelete(db, p->pWith);
108714 if( bFree ) sqlite3DbFree(db, p);
108750 sqlite3 *db = pParse->db;
108751 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
108753 assert( db->mallocFailed );
108758 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
108761 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
108771 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
108774 if( db->mallocFailed ) {
108775 clearSelect(db, pNew, pNew!=&standin);
108799 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
108800 clearSelect(db, p, 1);
108951 sqlite3 *db = pParse->db;
108961 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
108962 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
108971 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
109083 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
109187 if( pParse->db->mallocFailed ) return;
109409 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );
109634 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
109641 p->enc = ENC(db);
109642 p->db = db;
109645 db->mallocFailed = 1;
109705 sqlite3 *db = pParse->db;
109709 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
109715 if( !pColl ) pColl = db->pDfltColl;
109751 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
109797 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
110062 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
110063 zOrigDb = pNC->pParse->db->aDb[iDb].zName;
110158 sqlite3 *db = pParse->db;
110168 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
110170 fullNames = (db->flags & SQLITE_FullColNames)!=0;
110171 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
110198 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
110201 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
110208 z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z);
110234 sqlite3 *db = pParse->db; /* Database connection */
110245 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
110260 zName = sqlite3DbStrDup(db, zName);
110273 zName = sqlite3MPrintf(db, "%s",
110277 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
110280 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
110283 if( db->mallocFailed ){
110284 sqlite3DbFree(db, zName);
110299 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
110300 sqlite3DbFree(db, zName);
110308 if( db->mallocFailed ){
110310 sqlite3DbFree(db, aCol[j].zName);
110312 sqlite3DbFree(db, aCol);
110336 sqlite3 *db = pParse->db;
110347 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
110348 if( db->mallocFailed ) return;
110355 pCol->zType = sqlite3DbStrDup(db,
110363 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
110375 sqlite3 *db = pParse->db;
110378 savedFlags = db->flags;
110379 db->flags &= ~SQLITE_FullColNames;
110380 db->flags |= SQLITE_ShortColNames;
110384 db->flags = savedFlags;
110385 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
110391 assert( db->lookaside.bEnabled==0 );
110398 if( db->mallocFailed ){
110399 sqlite3DeleteTable(db, pTab);
110415 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
110533 sqlite3 *db = pParse->db;
110534 KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1);
110546 if( pColl==0 ) pColl = db->pDfltColl;
110719 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
110818 sqlite3 *db; /* Database connection */
110829 db = pParse->db;
110990 sqlite3ExprListDelete(db, p->pOrderBy);
110995 sqlite3ExprDelete(db, p->pLimit);
111075 sqlite3ExprDelete(db, p->pLimit);
111127 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
111135 *apColl = db->pDfltColl;
111160 sqlite3SelectDelete(db, pDelete);
111227 if( pParse->db->mallocFailed ) return 0;
111444 sqlite3 *db; /* Database connection */
111455 db = pParse->db;
111476 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
111483 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
111500 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
111516 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
111526 assert( nOrderBy>=nExpr || db->mallocFailed );
111530 pKeyDup = sqlite3KeyInfoAlloc(db, nExpr, 1);
111560 sqlite3ExprDelete(db, p->pLimit);
111562 sqlite3ExprDelete(db, p->pOffset);
111707 sqlite3SelectDelete(db, p->pPrior);
111738 sqlite3 *db, /* Report malloc errors to this connection */
111751 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
111752 sqlite3ExprDelete(db, pExpr);
111756 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
111757 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
111759 substSelect(db, pExpr->x.pSelect, iTable, pEList, 1);
111761 substExprList(db, pExpr->x.pList, iTable, pEList);
111767 sqlite3 *db, /* Report malloc errors here */
111775 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
111779 sqlite3 *db, /* Report malloc errors here */
111790 substExprList(db, p->pEList, iTable, pEList);
111791 substExprList(db, p->pGroupBy, iTable, pEList);
111792 substExprList(db, p->pOrderBy, iTable, pEList);
111793 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
111794 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
111798 substSelect(db, pItem->pSelect, iTable, pEList, 1);
111800 substExprList(db, pItem->u1.pFuncArg, iTable, pEList);
111965 sqlite3 *db = pParse->db;
111971 if( OptimizationDisabled(db, SQLITE_QueryFlattener) ) return 0;
112151 pNew = sqlite3SelectDup(db, p, 0);
112169 if( db->mallocFailed ) return 1;
112180 sqlite3DbFree(db, pSubitem->zDatabase);
112181 sqlite3DbFree(db, pSubitem->zName);
112182 sqlite3DbFree(db, pSubitem->zAlias);
112232 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
112234 assert( db->mallocFailed );
112255 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
112256 if( db->mallocFailed ){
112265 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
112286 char *zName = sqlite3DbStrDup(db, pList->a[i].zSpan);
112311 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
112316 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
112317 sqlite3ExprDup(db, pSub->pHaving, 0));
112319 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
112321 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
112323 substSelect(db, pParent, iParent, pSub->pEList, 0);
112345 sqlite3SelectDelete(db, pSub1);
112397 sqlite3 *db, /* The database connection (for malloc()) */
112412 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
112419 pNew = sqlite3ExprDup(db, pWhere, 0);
112420 pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
112421 pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew);
112554 sqlite3 *db;
112573 db = pParse->db;
112574 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
112581 p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0));
112671 sqlite3 *db = pParse->db;
112696 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
112699 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
112703 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
112704 if( db->mallocFailed ) return SQLITE_NOMEM;
112822 sqlite3 *db = pParse->db;
112827 if( db->mallocFailed ){
112864 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
112867 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
112895 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
112913 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
112942 int flags = pParse->db->flags;
112980 if( db->mallocFailed ) break;
112986 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
112987 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
113026 pRight = sqlite3Expr(db, TK_ID, zName);
113031 pLeft = sqlite3Expr(db, TK_ID, zTabName);
113034 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
113038 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
113051 pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
113054 pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s",
113060 sqlite3DbFree(db, zToFree);
113072 sqlite3ExprListDelete(db, pEList);
113076 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
113108 ** and/or pParse->db->mallocFailed.
113204 sqlite3 *db;
113206 db = pParse->db;
113207 if( db->mallocFailed ) return;
113210 if( pParse->nErr || db->mallocFailed ) return;
113212 if( pParse->nErr || db->mallocFailed ) return;
113319 pColl = pParse->db->pDfltColl;
113371 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
113417 sqlite3 *db; /* The database connection */
113424 db = pParse->db;
113425 if( p==0 || db->mallocFailed || pParse->nErr ){
113449 sqlite3ExprListDelete(db, p->pOrderBy);
113457 if( pParse->nErr || db->mallocFailed ){
113507 if( db->mallocFailed ) goto select_end;
113569 && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
113583 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
113634 if( db->mallocFailed ) goto select_end;
113673 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
113841 if( db->mallocFailed ) goto select_end;
113968 if( orderByGrp && OptimizationEnabled(db, SQLITE_GroupByOrder)
114093 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
114174 pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
114176 if( pMinMax && !db->mallocFailed ){
114189 sqlite3ExprListDelete(db, pDel);
114207 sqlite3ExprListDelete(db, pDel);
114246 sqlite3DbFree(db, sAggInfo.aCol);
114247 sqlite3DbFree(db, sAggInfo.aFunc);
114375 sqlite3 *db, /* The database on which the SQL executes */
114386 if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
114400 db->errCode = SQLITE_NOMEM;
114404 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
114416 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
114429 db->errCode = SQLITE_NOMEM;
114478 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
114483 sqlite3ExprDelete(db, pTmp->pWhere);
114484 sqlite3ExprListDelete(db, pTmp->pExprList);
114485 sqlite3SelectDelete(db, pTmp->pSelect);
114486 sqlite3IdListDelete(db, pTmp->pIdList);
114488 sqlite3DbFree(db, pTmp);
114507 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
114516 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
114554 sqlite3 *db = pParse->db; /* The database connection */
114556 Token *pName; /* The unqualified db name */
114557 DbFixer sFix; /* State vector for the DB fixer */
114573 /* Figure out the db that the trigger will be created in */
114579 if( !pTableName || db->mallocFailed ){
114591 if( db->init.busy && iDb!=1 ){
114592 sqlite3DbFree(db, pTableName->a[0].zDatabase);
114602 if( db->init.busy==0 && pName2->n==0 && pTab
114603 && pTab->pSchema==db->aDb[1].pSchema ){
114608 if( db->mallocFailed ) goto trigger_cleanup;
114617 if( db->init.iDb==1 ){
114626 db->init.orphanTrigger = 1;
114637 zName = sqlite3NameFromToken(db, pName);
114641 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114642 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
114646 assert( !db->init.busy );
114671 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
114676 const char *zDb = db->aDb[iTabDb].zName;
114677 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
114698 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
114702 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
114703 pTrigger->pSchema = db->aDb[iDb].pSchema;
114707 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
114708 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
114713 sqlite3DbFree(db, zName);
114714 sqlite3SrcListDelete(db, pTableName);
114715 sqlite3IdListDelete(db, pColumns);
114716 sqlite3ExprDelete(db, pWhen);
114718 sqlite3DeleteTrigger(db, pTrigger);
114735 sqlite3 *db = pParse->db; /* The database */
114743 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
114761 if( !db->init.busy ){
114769 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
114772 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
114774 sqlite3DbFree(db, z);
114777 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
114780 if( db->init.busy ){
114782 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
114783 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114786 db->mallocFailed = 1;
114797 sqlite3DeleteTrigger(db, pTrig);
114799 sqlite3DeleteTriggerStep(db, pStepList);
114809 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
114810 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
114812 sqlite3SelectDelete(db, pSelect);
114825 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
114828 sqlite3 *db, /* Database connection */
114834 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
114853 sqlite3 *db, /* The database connection */
114861 assert(pSelect != 0 || db->mallocFailed);
114863 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
114865 db, pSelect, EXPRDUP_REDUCE);
114869 sqlite3IdListDelete(db, pColumn);
114871 sqlite3SelectDelete(db, pSelect);
114882 sqlite3 *db, /* The database connection */
114890 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
114892 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
114893 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
114896 sqlite3ExprListDelete(db, pEList);
114897 sqlite3ExprDelete(db, pWhere);
114907 sqlite3 *db, /* Database connection */
114913 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
114915 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
114918 sqlite3ExprDelete(db, pWhere);
114925 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
114927 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
114928 sqlite3DbFree(db, pTrigger->zName);
114929 sqlite3DbFree(db, pTrigger->table);
114930 sqlite3ExprDelete(db, pTrigger->pWhen);
114931 sqlite3IdListDelete(db, pTrigger->pColumns);
114932 sqlite3DbFree(db, pTrigger);
114948 sqlite3 *db = pParse->db;
114950 if( db->mallocFailed ) goto drop_trigger_cleanup;
114958 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
114959 for(i=OMIT_TEMPDB; i<db->nDb; i++){
114961 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
114962 assert( sqlite3SchemaMutexHeld(db, j, 0) );
114963 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
114978 sqlite3SrcListDelete(db, pName);
114996 sqlite3 *db = pParse->db;
114999 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
115000 assert( iDb>=0 && iDb<db->nDb );
115007 const char *zDb = db->aDb[iDb].zName;
115052 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
115056 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
115057 pHash = &(db->aDb[iDb].pSchema->trigHash);
115066 sqlite3DeleteTrigger(db, pTrigger);
115067 db->flags |= SQLITE_InternChanges;
115106 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
115135 sqlite3 *db = pParse->db;
115139 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
115142 pSrc->a[pSrc->nSrc-1].zName = sqlite3DbStrDup(db, pStep->zTarget);
115143 iDb = sqlite3SchemaToIndex(db, pStep->pTrig->pSchema);
115145 assert( iDb<db->nDb );
115146 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
115163 sqlite3 *db = pParse->db;
115189 sqlite3ExprListDup(db, pStep->pExprList, 0),
115190 sqlite3ExprDup(db, pStep->pWhere, 0),
115198 sqlite3SelectDup(db, pStep->pSelect, 0),
115199 sqlite3IdListDup(db, pStep->pIdList),
115207 sqlite3ExprDup(db, pStep->pWhere, 0)
115213 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
115216 sqlite3SelectDelete(db, pSelect);
115259 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
115274 sqlite3 *db = pParse->db; /* Database handle */
115289 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
115293 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
115303 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
115307 pSubParse->db = db;
115326 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
115334 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
115336 && db->mallocFailed==0
115341 sqlite3ExprDelete(db, pWhen);
115355 if( db->mallocFailed==0 ){
115370 sqlite3StackFree(db, pSubParse);
115426 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
115431 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
115512 || p->pSchema==pParse->db->aDb[1].pSchema );
115688 sqlite3 *db; /* The database structure */
115726 db = pParse->db;
115727 if( pParse->nErr || db->mallocFailed ){
115736 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
115781 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 );
115833 db->aDb[iDb].zName);
115978 sqlite3IndexAffinityStr(db, pPk), nPk);
115986 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
116198 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
116240 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
116248 sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
116249 sqlite3SrcListDelete(db, pTabList);
116250 sqlite3ExprListDelete(db, pChanges);
116251 sqlite3ExprDelete(db, pWhere);
116299 sqlite3 *db = pParse->db; /* Database connection */
116300 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
116416 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
116420 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
116426 ** Execute zSql on database db. Return an error code.
116428 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
116434 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
116435 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
116436 return sqlite3_errcode(db);
116439 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
116440 return vacuumFinalize(db, pStmt, pzErrMsg);
116444 ** Execute zSql on database db. The statement returns exactly
116447 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
116451 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
116455 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
116457 vacuumFinalize(db, pStmt, pzErrMsg);
116462 return vacuumFinalize(db, pStmt, pzErrMsg);
116507 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
116512 int saved_flags; /* Saved value of the db->flags */
116513 int saved_nChange; /* Saved value of db->nChange */
116514 int saved_nTotalChange; /* Saved value of db->nTotalChange */
116515 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */
116516 Db *pDb = 0; /* Database to detach at end of vacuum */
116521 if( !db->autoCommit ){
116522 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
116525 if( db->nVdbeActive>1 ){
116526 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
116533 saved_flags = db->flags;
116534 saved_nChange = db->nChange;
116535 saved_nTotalChange = db->nTotalChange;
116536 saved_xTrace = db->xTrace;
116537 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
116538 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
116539 db->xTrace = 0;
116541 pMain = db->aDb[0].pBt;
116558 nDb = db->nDb;
116559 if( sqlite3TempInMemory(db) ){
116564 rc = execSql(db, pzErrMsg, zSql);
116565 if( db->nDb>nDb ){
116566 pDb = &db->aDb[db->nDb-1];
116570 pTemp = db->aDb[db->nDb-1].pBt;
116582 if( db->nextPagesize ){
116586 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
116587 if( nKey ) db->nextPagesize = 0;
116591 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
116598 rc = execSql(db, pzErrMsg, "BEGIN;");
116606 db->nextPagesize = 0;
116610 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
116611 || NEVER(db->mallocFailed)
116618 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
116625 rc = execExecSql(db, pzErrMsg,
116631 rc = execExecSql(db, pzErrMsg,
116635 rc = execExecSql(db, pzErrMsg,
116644 assert( (db->flags & SQLITE_Vacuum)==0 );
116645 db->flags |= SQLITE_Vacuum;
116646 rc = execExecSql(db, pzErrMsg,
116653 assert( (db->flags & SQLITE_Vacuum)!=0 );
116654 db->flags &= ~SQLITE_Vacuum;
116659 rc = execExecSql(db, pzErrMsg,
116664 rc = execExecSql(db, pzErrMsg,
116677 rc = execSql(db, pzErrMsg,
116735 /* Restore the original value of db->flags */
116736 db->flags = saved_flags;
116737 db->nChange = saved_nChange;
116738 db->nTotalChange = saved_nTotalChange;
116739 db->xTrace = saved_xTrace;
116749 db->autoCommit = 1;
116757 /* This both clears the schemas and reduces the size of the db->aDb[]
116759 sqlite3ResetAllSchemasOfConnection(db);
116804 sqlite3 *db, /* Database in which module is registered */
116813 sqlite3_mutex_enter(db->mutex);
116815 if( sqlite3HashFind(&db->aModule, zName) ){
116819 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
116829 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
116832 db->mallocFailed = 1;
116833 sqlite3DbFree(db, pDel);
116837 rc = sqlite3ApiExit(db, rc);
116840 sqlite3_mutex_leave(db->mutex);
116849 sqlite3 *db, /* Database in which module is registered */
116855 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
116857 return createModule(db, zName, pModule, pAux, 0);
116864 sqlite3 *db, /* Database in which module is registered */
116871 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
116873 return createModule(db, zName, pModule, pAux, xDestroy);
116891 ** Return a pointer to the VTable object used by connection db to access
116894 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
116897 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
116906 sqlite3 *db = pVTab->db;
116908 assert( db );
116910 assert( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ZOMBIE );
116918 sqlite3DbFree(db, pVTab);
116926 ** Except, if argument db is not NULL, then the entry associated with
116927 ** connection db is left in the p->pVTable list.
116929 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
116940 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
116943 sqlite3 *db2 = pVTable->db;
116946 if( db2==db ){
116957 assert( !db || pRet );
116963 ** for table *p associated with database connection db from the linked
116965 ** used when closing database connection db to free all of its VTable
116969 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p){
116973 assert( sqlite3BtreeHoldsAllMutexes(db) );
116974 assert( sqlite3_mutex_held(db->mutex) );
116977 if( (*ppVTab)->db==db ){
116991 ** shared b-tree databases opened using connection db are held by the
117007 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
117008 VTable *p = db->pDisconnect;
117009 db->pDisconnect = 0;
117011 assert( sqlite3BtreeHoldsAllMutexes(db) );
117012 assert( sqlite3_mutex_held(db->mutex) );
117015 sqlite3ExpirePreparedStatements(db);
117033 ** connection db is decremented immediately (which may lead to the
117038 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
117039 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
117043 if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
117045 sqlite3DbFree(db, p->azModuleArg);
117055 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
117058 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
117060 sqlite3DbFree(db, zArg);
117083 sqlite3 *db; /* Database connection */
117090 db = pParse->db;
117091 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
117096 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
117097 addModuleArgument(db, pTable, 0);
117098 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
117114 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
117128 sqlite3 *db = pParse->db;
117129 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
117139 sqlite3 *db = pParse->db; /* The database connection */
117152 if( !db->init.busy ){
117163 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
117173 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117178 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
117184 sqlite3DbFree(db, zStmt);
117189 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
117206 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
117209 db->mallocFailed = 1;
117248 sqlite3 *db,
117265 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
117267 *pzErr = sqlite3MPrintf(db,
117274 zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
117279 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
117281 sqlite3DbFree(db, zModuleName);
117284 pVTable->db = db;
117287 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117288 pTab->azModuleArg[1] = db->aDb[iDb].zName;
117291 assert( &db->pVtabCtx );
117295 sCtx.pPrior = db->pVtabCtx;
117297 db->pVtabCtx = &sCtx;
117298 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
117299 db->pVtabCtx = sCtx.pPrior;
117300 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
117305 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
117307 *pzErr = sqlite3MPrintf(db, "%s", zErr);
117310 sqlite3DbFree(db, pVTable);
117319 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
117371 sqlite3DbFree(db, zModuleName);
117383 sqlite3 *db = pParse->db;
117389 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
117395 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
117403 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
117407 sqlite3DbFree(db, zErr);
117413 ** Grow the db->aVTrans[] array so that there is room for at least one
117416 static int growVTrans(sqlite3 *db){
117420 if( (db->nVTrans%ARRAY_INCR)==0 ){
117422 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
117423 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
117427 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
117428 db->aVTrans = aVTrans;
117438 static void addToVTrans(sqlite3 *db, VTable *pVTab){
117440 db->aVTrans[db->nVTrans++] = pVTab;
117450 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
117452 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
117458 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
117463 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
117470 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
117473 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
117478 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
117479 rc = growVTrans(db);
117481 addToVTrans(db, sqlite3GetVTable(db, pTab));
117493 SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
117501 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
117505 sqlite3_mutex_enter(db->mutex);
117506 pCtx = db->pVtabCtx;
117508 sqlite3Error(db, SQLITE_MISUSE);
117509 sqlite3_mutex_leave(db->mutex);
117515 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
117520 pParse->db = db;
117525 && !db->mallocFailed
117537 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
117538 sqlite3DbFree(db, zErr);
117546 sqlite3DeleteTable(db, pParse->pNewTable);
117548 sqlite3StackFree(db, pParse);
117552 rc = sqlite3ApiExit(db, rc);
117553 sqlite3_mutex_leave(db->mutex);
117564 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
117568 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
117578 p = vtabDisconnectAll(db, pTab);
117602 static void callFinaliser(sqlite3 *db, int offset){
117604 if( db->aVTrans ){
117605 VTable **aVTrans = db->aVTrans;
117606 db->aVTrans = 0;
117607 for(i=0; i<db->nVTrans; i++){
117618 sqlite3DbFree(db, aVTrans);
117619 db->nVTrans = 0;
117630 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe *p){
117633 VTable **aVTrans = db->aVTrans;
117635 db->aVTrans = 0;
117636 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
117644 db->aVTrans = aVTrans;
117652 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
117653 callFinaliser(db, offsetof(sqlite3_module,xRollback));
117661 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
117662 callFinaliser(db, offsetof(sqlite3_module,xCommit));
117674 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
117678 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
117683 if( sqlite3VtabInSync(db) ){
117695 for(i=0; i<db->nVTrans; i++){
117696 if( db->aVTrans[i]==pVTab ){
117703 rc = growVTrans(db);
117707 int iSvpt = db->nStatement + db->nSavepoint;
117708 addToVTrans(db, pVTab);
117709 if( iSvpt ) rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, iSvpt-1);
117731 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
117736 if( db->aVTrans ){
117738 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
117739 VTable *pVTab = db->aVTrans[i];
117778 sqlite3 *db, /* Database connection for reporting malloc problems */
117800 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
117809 zLowerName = sqlite3DbStrDup(db, pDef->zName);
117815 sqlite3DbFree(db, zLowerName);
117823 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
117858 pToplevel->db->mallocFailed = 1;
117882 sqlite3 *db = pParse->db;
117886 pTab = sqlite3DbMallocZero(db, sizeof(Table) + nName);
117892 pTab->pSchema = db->aDb[0].pSchema;
117896 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117897 addModuleArgument(db, pTab, 0);
117898 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117899 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
117902 sqlite3DbFree(db, zErr);
117903 sqlite3VtabEponymousTableClear(db, pMod);
117913 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *db, Module *pMod){
117916 sqlite3DeleteColumnNames(db, pTab);
117917 sqlite3VtabClear(db, pTab);
117918 sqlite3DbFree(db, pTab);
117930 SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *db){
117935 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
117939 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
117940 return (int)aMap[db->vtabOnConflict-1];
117948 SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3 *db, int op, ...){
117953 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
117955 sqlite3_mutex_enter(db->mutex);
117959 VtabCtx *p = db->pVtabCtx;
117974 if( rc!=SQLITE_OK ) sqlite3Error(db, rc);
117975 sqlite3_mutex_leave(db->mutex);
118268 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
118636 sqlite3 *db = pParse->db; /* Database handle */
118653 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
118829 assert( pParse->db->mallocFailed );
118917 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
119016 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
119018 pParse->db->mallocFailed = 1;
119105 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
119131 sqlite3 *db; /* Database connection */
119142 db = pParse->db;
119566 sqlite3DbFree(db, zStartAff);
119703 pOrTab = sqlite3StackAllocRaw(db,
119766 pExpr = sqlite3ExprDup(db, pExpr, 0);
119767 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
119796 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
119907 sqlite3ExprDelete(db, pAndExpr);
119913 if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
120000 pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
120005 sqlite3StackFree(db, pEAlt);
120063 static void whereOrInfoDelete(sqlite3 *db
120065 sqlite3DbFree(db, p);
120071 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
120073 sqlite3DbFree(db, p);
120082 ** the db->mallocFailed flag so that higher-level functions can detect it.
120101 sqlite3 *db = pWC->pWInfo->pParse->db;
120102 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
120105 sqlite3ExprDelete(db, p);
120112 sqlite3DbFree(db, pOld);
120114 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
120237 sqlite3 *db = pParse->db; /* Database connection */
120241 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
120281 pPrefix = sqlite3Expr(db, TK_STRING, z);
120403 sqlite3 *db; /* Database connection (for malloc) */
120425 db = pWC->pWInfo->pParse->db;
120426 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
120529 sqlite3 *db = pParse->db; /* Database connection */
120546 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
120553 if( db->mallocFailed ) return;
120566 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
120580 testcase( db->mallocFailed );
120581 if( !db->mallocFailed ){
120741 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
120746 pDup = sqlite3ExprDup(db, pLeft, 0);
120759 sqlite3ExprListDelete(db, pList);
120786 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
120913 sqlite3 *db = pParse->db; /* Database connection */
120915 if( db->mallocFailed ){
120966 pDup = sqlite3ExprDup(db, pExpr, 0);
120967 if( db->mallocFailed ){
120968 sqlite3ExprDelete(db, pDup);
121023 sqlite3ExprDup(db, pExpr->pLeft, 0),
121024 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
121073 pStr2 = sqlite3ExprDup(db, pStr1, 0);
121079 if( noCase && !pParse->db->mallocFailed ){
121089 if( !db->mallocFailed ){
121106 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
121114 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
121150 0, sqlite3ExprDup(db, pRight, 0), 0);
121177 && OptimizationEnabled(db, SQLITE_Stat34)
121185 sqlite3ExprDup(db, pLeft, 0),
121265 sqlite3 *db = pWC->pWInfo->pParse->db;
121268 sqlite3ExprDelete(db, a->pExpr);
121271 whereOrInfoDelete(db, a->u.pOrInfo);
121273 whereAndInfoDelete(db, a->u.pAndInfo);
121277 sqlite3DbFree(db, pWC->a);
121368 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
121604 if( pColl==0 ) pColl = pParse->db->pDfltColl;
122029 pPartial = sqlite3ExprAnd(pParse->db, pPartial,
122030 sqlite3ExprDup(pParse->db, pExpr, 0));
122044 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
122077 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
122171 sqlite3ExprDelete(pParse->db, pPartial);
122231 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
122307 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
122317 pParse->db->mallocFailed = 1;
122460 if( pParse->db->mallocFailed==0 ){
122467 || pParse->db->mallocFailed
122477 || pParse->db->mallocFailed );
122486 || pParse->db->mallocFailed );
122491 || pParse->db->mallocFailed );
122561 static char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
122564 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
122616 sqlite3 *db = pParse->db;
122620 u8 aff = sqlite3IndexColumnAffinity(db, p, nEq);
122641 rc = sqlite3Stat4Column(db, p->aSample[i].p, p->aSample[i].n, nEq, &pVal);
122768 aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq);
122927 aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1);
123079 static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){
123086 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
123087 sqlite3DbFree(db, p->u.btree.pIndex);
123096 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
123097 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
123098 whereLoopClearUnion(db, p);
123105 static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
123109 paNew = sqlite3DbMallocRaw(db, sizeof(p->aLTerm[0])*n);
123112 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
123121 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
123122 whereLoopClearUnion(db, pTo);
123123 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
123140 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
123141 whereLoopClear(db, p);
123142 sqlite3DbFree(db, p);
123148 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
123154 sqlite3DbFree(db, pLevel->u.in.aInLoop);
123161 whereLoopDelete(db, p);
123163 sqlite3DbFree(db, pWInfo);
123348 sqlite3 *db = pWInfo->pParse->db;
123406 *ppPrev = p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
123428 whereLoopDelete(db, pToDel);
123431 whereLoopXfer(db, p, pTemplate);
123546 sqlite3 *db = pParse->db; /* Database connection malloc context */
123563 if( db->mallocFailed ) return SQLITE_NOMEM;
123611 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
123662 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
123790 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
123989 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
124085 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan)
124156 sqlite3 *db;
124173 db = pParse->db;
124188 if( whereLoopResize(db, pNew, nConstraint) ){
124189 sqlite3DbFree(db, pIdxInfo);
124317 sqlite3DbFree(db, pIdxInfo);
124459 sqlite3 *db = pWInfo->pParse->db;
124492 if( rc || db->mallocFailed ) break;
124495 whereLoopClear(db, pNew);
124543 sqlite3 *db = pWInfo->pParse->db; /* Database connection */
124572 if( nLoop && OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return 0;
124606 if( !pColl ) pColl = db->pDfltColl;
124609 if( !pColl ) pColl = db->pDfltColl;
124698 if( !pColl ) pColl = db->pDfltColl;
124860 sqlite3 *db; /* The database connection */
124879 db = pParse->db;
124902 pSpace = sqlite3DbMallocRaw(db, nSpace);
125127 sqlite3DbFree(db, pSpace);
125185 sqlite3DbFree(db, pSpace);
125385 sqlite3 *db; /* Database connection */
125394 db = pParse->db;
125404 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
125432 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
125433 if( db->mallocFailed ){
125434 sqlite3DbFree(db, pWInfo);
125512 if( db->mallocFailed ) goto whereBeginError;
125555 if( db->mallocFailed ) goto whereBeginError;
125558 if( db->mallocFailed ) goto whereBeginError;
125561 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
125564 if( pParse->nErr || NEVER(db->mallocFailed) ){
125596 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
125658 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
125665 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
125760 if( db->mallocFailed ) goto whereBeginError;
125776 db->mallocFailed ) goto whereBeginError;
125798 whereInfoFree(db, pWInfo);
125814 sqlite3 *db = pParse->db;
125903 if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
125948 && !db->mallocFailed
125980 whereInfoFree(db, pWInfo);
126061 (mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])>0 &&
126120 sqlite3 *db = pParse->db;
126123 sqlite3ExprDelete(db, pA->pRight);
126156 && pParse->db->init.busy==0
127419 sqlite3SelectDelete(pParse->db, (yypminor->yy3));
127425 sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
127440 sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
127448 sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
127454 sqlite3WithDelete(pParse->db, (yypminor->yy59));
127465 sqlite3ExprDelete(pParse->db, (yypminor->yy132));
127472 sqlite3IdListDelete(pParse->db, (yypminor->yy408));
127478 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy473));
127483 sqlite3IdListDelete(pParse->db, (yypminor->yy378).b);
128178 pParse->db->lookaside.bEnabled = 0;
128213 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
128423 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
128433 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
128461 sqlite3SelectDelete(pParse->db, pLhs);
128547 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
128563 {yygotominor.yy65 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy65));}
128612 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy65);
128626 {yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
128749 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
128752 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
128822 if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
128921 sqlite3ExprListDelete(pParse->db, pList);
128940 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy346.pExpr);
128960 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy14);
128974 db, yymsp[-1].minor.yy14);
128990 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
129004 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
129013 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
129020 sqlite3SrcListDelete(pParse->db, pSrc);
129035 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
129048 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
129049 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
129076 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
129196 { yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
129199 {yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
129202 {yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
129205 {yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
129272 pParse->db->lookaside.bEnabled = 0;
130283 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
130284 sqlite3 *db = pParse->db; /* The database connection */
130288 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
130289 if( db->nVdbeActive==0 ){
130290 db->u1.isInterrupted = 0;
130299 db->mallocFailed = 1;
130307 enableLookaside = db->lookaside.bEnabled;
130308 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
130309 while( !db->mallocFailed && zSql[i]!=0 ){
130320 if( db->u1.isInterrupted ){
130348 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
130354 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
130366 db->lookaside.bEnabled = enableLookaside;
130367 if( db->mallocFailed ){
130371 pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
130386 sqlite3DbFree(db, pParse->aTableLock);
130400 sqlite3DeleteTable(db, pParse->pNewTable);
130403 if( pParse->bFreeWith ) sqlite3WithDelete(db, pParse->pWith);
130404 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
130405 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
130406 sqlite3DbFree(db, pParse->azVar);
130410 sqlite3DbFree(db, p);
130415 sqlite3DeleteTable(db, p);
130758 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
130791 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
130824 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
131456 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
131459 if( db->lookaside.nOut ){
131466 if( db->lookaside.bMalloced ){
131467 sqlite3_free(db->lookaside.pStart);
131486 db->lookaside.pStart = pStart;
131487 db->lookaside.pFree = 0;
131488 db->lookaside.sz = (u16)sz;
131495 p->pNext = db->lookaside.pFree;
131496 db->lookaside.pFree = p;
131499 db->lookaside.pEnd = p;
131500 db->lookaside.bEnabled = 1;
131501 db->lookaside.bMalloced = pBuf==0 ?1:0;
131503 db->lookaside.pStart = db;
131504 db->lookaside.pEnd = db;
131505 db->lookaside.bEnabled = 0;
131506 db->lookaside.bMalloced = 0;
131515 SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3 *db){
131517 if( !sqlite3SafetyCheckOk(db) ){
131522 return db->mutex;
131529 SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3 *db){
131533 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
131535 sqlite3_mutex_enter(db->mutex);
131536 sqlite3BtreeEnterAll(db);
131537 for(i=0; i<db->nDb; i++){
131538 Btree *pBt = db->aDb[i].pBt;
131544 sqlite3BtreeLeaveAll(db);
131545 sqlite3_mutex_leave(db->mutex);
131552 SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3 *db, int op, ...){
131561 rc = setupLookaside(db, pBuf, sz, cnt);
131578 int oldFlags = db->flags;
131580 db->flags |= aFlagOp[i].mask;
131582 db->flags &= ~aFlagOp[i].mask;
131584 if( oldFlags!=db->flags ){
131585 sqlite3ExpirePreparedStatements(db);
131588 *pRes = (db->flags & aFlagOp[i].mask)!=0;
131671 SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3 *db){
131673 if( !sqlite3SafetyCheckOk(db) ){
131678 return db->lastRowid;
131684 SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3 *db){
131686 if( !sqlite3SafetyCheckOk(db) ){
131691 return db->nChange;
131697 SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3 *db){
131699 if( !sqlite3SafetyCheckOk(db) ){
131704 return db->nTotalChange;
131712 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
131713 while( db->pSavepoint ){
131714 Savepoint *pTmp = db->pSavepoint;
131715 db->pSavepoint = pTmp->pNext;
131716 sqlite3DbFree(db, pTmp);
131718 db->nSavepoint = 0;
131719 db->nStatement = 0;
131720 db->isTransactionSavepoint = 0;
131729 static void functionDestroy(sqlite3 *db, FuncDef *p){
131735 sqlite3DbFree(db, pDestructor);
131742 ** db. This is called when db is being closed.
131744 static void disconnectAllVtab(sqlite3 *db){
131748 sqlite3BtreeEnterAll(db);
131749 for(i=0; i<db->nDb; i++){
131750 Schema *pSchema = db->aDb[i].pSchema;
131751 if( db->aDb[i].pSchema ){
131754 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
131758 for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
131761 sqlite3VtabDisconnect(db, pMod->pEpoTab);
131764 sqlite3VtabUnlockList(db);
131765 sqlite3BtreeLeaveAll(db);
131767 UNUSED_PARAMETER(db);
131772 ** Return TRUE if database connection db has unfinalized prepared
131775 static int connectionIsBusy(sqlite3 *db){
131777 assert( sqlite3_mutex_held(db->mutex) );
131778 if( db->pVdbe ) return 1;
131779 for(j=0; j<db->nDb; j++){
131780 Btree *pBt = db->aDb[j].pBt;
131789 static int sqlite3Close(sqlite3 *db, int forceZombie){
131790 if( !db ){
131795 if( !sqlite3SafetyCheckSickOrOk(db) ){
131798 sqlite3_mutex_enter(db->mutex);
131801 disconnectAllVtab(db);
131805 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
131810 sqlite3VtabRollback(db);
131815 if( !forceZombie && connectionIsBusy(db) ){
131816 sqlite3ErrorWithMsg(db, SQLITE_BUSY, "unable to close due to unfinalized "
131818 sqlite3_mutex_leave(db->mutex);
131825 sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
131831 db->magic = SQLITE_MAGIC_ZOMBIE;
131832 sqlite3LeaveMutexAndCloseZombie(db);
131845 SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
131846 SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
131850 ** Close the mutex on database connection db.
131852 ** Furthermore, if database connection db is a zombie (meaning that there
131853 ** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
131857 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
131865 if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
131866 sqlite3_mutex_leave(db->mutex);
131880 sqlite3RollbackAll(db, SQLITE_OK);
131883 sqlite3CloseSavepoints(db);
131886 for(j=0; j<db->nDb; j++){
131887 struct Db *pDb = &db->aDb[j];
131897 if( db->aDb[1].pSchema ){
131898 sqlite3SchemaClear(db->aDb[1].pSchema);
131900 sqlite3VtabUnlockList(db);
131903 sqlite3CollapseDatabaseArray(db);
131904 assert( db->nDb<=2 );
131905 assert( db->aDb==db->aDbStatic );
131910 sqlite3ConnectionClosed(db);
131912 for(j=0; j<ArraySize(db->aFunc.a); j++){
131914 for(p=db->aFunc.a[j]; p; p=pHash){
131917 functionDestroy(db, p);
131919 sqlite3DbFree(db, p);
131924 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
131932 sqlite3DbFree(db, pColl);
131934 sqlite3HashClear(&db->aCollSeq);
131936 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
131941 sqlite3VtabEponymousTableClear(db, pMod);
131942 sqlite3DbFree(db, pMod);
131944 sqlite3HashClear(&db->aModule);
131947 sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
131948 sqlite3ValueFree(db->pErr);
131949 sqlite3CloseExtensions(db);
131951 sqlite3_free(db->auth.zAuthUser);
131952 sqlite3_free(db->auth.zAuthPW);
131955 db->magic = SQLITE_MAGIC_ERROR;
131963 sqlite3DbFree(db, db->aDb[1].pSchema);
131964 sqlite3_mutex_leave(db->mutex);
131965 db->magic = SQLITE_MAGIC_CLOSED;
131966 sqlite3_mutex_free(db->mutex);
131967 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
131968 if( db->lookaside.bMalloced ){
131969 sqlite3_free(db->lookaside.pStart);
131971 sqlite3_free(db);
131981 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
131985 assert( sqlite3_mutex_held(db->mutex) );
131994 sqlite3BtreeEnterAll(db);
131995 schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
131997 for(i=0; i<db->nDb; i++){
131998 Btree *p = db->aDb[i].pBt;
132006 sqlite3VtabRollback(db);
132009 if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
132010 sqlite3ExpirePreparedStatements(db);
132011 sqlite3ResetAllSchemasOfConnection(db);
132013 sqlite3BtreeLeaveAll(db);
132016 db->nDeferredCons = 0;
132017 db->nDeferredImmCons = 0;
132018 db->flags &= ~SQLITE_DeferFKs;
132021 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
132022 db->xRollbackCallback(db->pRollbackArg);
132202 sqlite3 *db = (sqlite3 *)ptr;
132203 int timeout = db->busyTimeout;
132218 sqlite3OsSleep(db->pVfs, delay*1000);
132221 sqlite3 *db = (sqlite3 *)ptr;
132226 sqlite3OsSleep(db->pVfs, 1000000);
132255 sqlite3 *db,
132260 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132262 sqlite3_mutex_enter(db->mutex);
132263 db->busyHandler.xFunc = xBusy;
132264 db->busyHandler.pArg = pArg;
132265 db->busyHandler.nBusy = 0;
132266 db->busyTimeout = 0;
132267 sqlite3_mutex_leave(db->mutex);
132278 sqlite3 *db,
132284 if( !sqlite3SafetyCheckOk(db) ){
132289 sqlite3_mutex_enter(db->mutex);
132291 db->xProgress = xProgress;
132292 db->nProgressOps = (unsigned)nOps;
132293 db->pProgressArg = pArg;
132295 db->xProgress = 0;
132296 db->nProgressOps = 0;
132297 db->pProgressArg = 0;
132299 sqlite3_mutex_leave(db->mutex);
132308 SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3 *db, int ms){
132310 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132313 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
132314 db->busyTimeout = ms;
132316 sqlite3_busy_handler(db, 0, 0);
132324 SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3 *db){
132326 if( !sqlite3SafetyCheckOk(db) ){
132331 db->u1.isInterrupted = 1;
132342 sqlite3 *db,
132356 assert( sqlite3_mutex_held(db->mutex) );
132382 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
132385 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
132402 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
132404 if( db->nVdbeActive ){
132405 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
132407 assert( !db->mallocFailed );
132410 sqlite3ExpirePreparedStatements(db);
132414 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
132415 assert(p || db->mallocFailed);
132422 functionDestroy(db, p);
132442 sqlite3 *db,
132451 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
132456 sqlite3 *db,
132470 if( !sqlite3SafetyCheckOk(db) ){
132474 sqlite3_mutex_enter(db->mutex);
132476 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
132484 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
132488 sqlite3DbFree(db, pArg);
132492 rc = sqlite3ApiExit(db, rc);
132493 sqlite3_mutex_leave(db->mutex);
132499 sqlite3 *db,
132512 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
132514 sqlite3_mutex_enter(db->mutex);
132515 assert( !db->mallocFailed );
132516 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
132517 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
132518 sqlite3DbFree(db, zFunc8);
132519 rc = sqlite3ApiExit(db, rc);
132520 sqlite3_mutex_leave(db->mutex);
132539 sqlite3 *db,
132547 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
132551 sqlite3_mutex_enter(db->mutex);
132552 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
132553 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
132556 rc = sqlite3ApiExit(db, rc);
132557 sqlite3_mutex_leave(db->mutex);
132570 SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
132574 if( !sqlite3SafetyCheckOk(db) ){
132579 sqlite3_mutex_enter(db->mutex);
132580 pOld = db->pTraceArg;
132581 db->xTrace = xTrace;
132582 db->pTraceArg = pArg;
132583 sqlite3_mutex_leave(db->mutex);
132595 sqlite3 *db,
132602 if( !sqlite3SafetyCheckOk(db) ){
132607 sqlite3_mutex_enter(db->mutex);
132608 pOld = db->pProfileArg;
132609 db->xProfile = xProfile;
132610 db->pProfileArg = pArg;
132611 db->mutex);
132622 sqlite3 *db, /* Attach the hook to this database */
132629 if( !sqlite3SafetyCheckOk(db) ){
132634 sqlite3_mutex_enter(db->mutex);
132635 pOld = db->pCommitArg;
132636 db->xCommitCallback = xCallback;
132637 db->pCommitArg = pArg;
132638 sqlite3_mutex_leave(db->mutex);
132647 sqlite3 *db, /* Attach the hook to this database */
132654 if( !sqlite3SafetyCheckOk(db) ){
132659 sqlite3_mutex_enter(db->mutex);
132660 pRet = db->pUpdateArg;
132661 db->xUpdateCallback = xCallback;
132662 db->pUpdateArg = pArg;
132663 sqlite3_mutex_leave(db->mutex);
132672 sqlite3 *db, /* Attach the hook to this database */
132679 if( !sqlite3SafetyCheckOk(db) ){
132684 sqlite3_mutex_enter(db->mutex);
132685 pRet = db->pRollbackArg;
132686 db->xRollbackCallback = xCallback;
132687 db->pRollbackArg = pArg;
132688 sqlite3_mutex_leave(db->mutex);
132701 sqlite3 *db, /* Connection */
132707 sqlite3_wal_checkpoint(db, zDb);
132725 SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
132727 UNUSED_PARAMETER(db);
132731 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132734 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
132736 sqlite3_wal_hook(db, 0, 0);
132747 sqlite3 *db, /* Attach the hook to this db handle */
132754 if( !sqlite3SafetyCheckOk(db) ){
132759 sqlite3_mutex_enter(db->mutex);
132760 pRet = db->pWalArg;
132761 db->xWalCallback = xCallback;
132762 db->pWalArg = pArg;
132763 sqlite3_mutex_leave(db->mutex);
132774 sqlite3 *db, /* Database handle */
132784 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
132787 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
132804 sqlite3_mutex_enter(db->mutex);
132806 iDb = sqlite3FindDbName(db, zDb);
132810 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb);
132812 db->busyHandler.nBusy = 0;
132813 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
132814 sqlite3Error(db, rc);
132816 rc = sqlite3ApiExit(db, rc);
132817 sqlite3_mutex_leave(db->mutex);
132828 SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
132831 return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
132844 ** The mutex on database handle db should be held by the caller. The mutex
132854 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
132859 assert( sqlite3_mutex_held(db->mutex) );
132863 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
132865 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
132882 ** The value returned depends on the value of db->temp_store (runtime
132887 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
132898 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
132900 return ( db->temp_store==2 );
132903 return ( db->temp_store!=1 );
132906 UNUSED_PARAMETER(db);
132910 UNUSED_PARAMETER(db);
132919 SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3 *db){
132921 if( !db ){
132924 if( !sqlite3SafetyCheckSickOrOk(db) ){
132927 sqlite3_mutex_enter(db->mutex);
132928 if( db->mallocFailed ){
132931 testcase( db->pErr==0 );
132932 z = (char*)sqlite3_value_text(db->pErr);
132933 assert( !db->mallocFailed );
132935 z = sqlite3ErrStr(db->errCode);
132938 sqlite3_mutex_leave(db->mutex);
132947 SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3 *db){
132961 if( !db ){
132964 if( !sqlite3SafetyCheckSickOrOk(db) ){
132967 sqlite3_mutex_enter(db->mutex);
132968 if( db->mallocFailed ){
132971 z = sqlite3_value_text16(db->pErr);
132973 sqlite3ErrorWithMsg(db, db->errCode, sqlite3ErrStr(db->errCode));
132974 z = sqlite3_value_text16(db->pErr);
132977 ** above. If this is the case, then the db->mallocFailed flag needs to
132981 db->mallocFailed = 0;
132983 sqlite3_mutex_leave(db->mutex);
132992 SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db){
132993 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
132996 if( !db || db->mallocFailed ){
132999 return db->errCode & db->errMask;
133001 SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db){
133002 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
133005 if( !db || db->mallocFailed ){
133008 return db->errCode;
133021 ** Create a new collating function for database "db". The name is zName
133025 sqlite3* db,
133035 assert( sqlite3_mutex_held(db->mutex) );
133055 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
133057 if( db->nVdbeActive ){
133058 sqlite3ErrorWithMsg(db, SQLITE_BUSY,
133062 sqlite3ExpirePreparedStatements(db);
133071 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
133085 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
133091 sqlite3Error(db, SQLITE_OK);
133164 SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
133168 if( !sqlite3SafetyCheckOk(db) ){
133198 oldLimit = db->aLimit[limitId];
133203 db->aLimit[limitId] = newLimit;
133465 sqlite3 *db; /* Store allocated handle here */
133539 db = sqlite3MallocZero( sizeof(sqlite3) );
133540 if( db==0 ) goto opendb_out;
133542 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
133543 if( db->mutex==0 ){
133544 sqlite3_free(db);
133545 db = 0;
133549 sqlite3_mutex_enter(db->mutex);
133550 db->errMask = 0xff;
133551 db->nDb = 2;
133552 db->magic = SQLITE_MAGIC_BUSY;
133553 db->aDb = db->aDbStatic;
133555 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
133556 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
133557 db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = SQLITE_DEFAULT_WORKER_THREADS;
133558 db->autoCommit = 1;
133559 db->nextAutovac = -1;
133560 db->szMmap = sqlite3GlobalConfig.szMmap;
133561 db->nextPagesize = 0;
133562 db->nMaxSorterMmap = 0x7FFFFFFF;
133563 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
133589 sqlite3HashInit(&db->aCollSeq);
133591 sqlite3HashInit(&db->aModule);
133601 createCollation(db
133602 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
133603 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
133604 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
133605 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
133606 if( db->mallocFailed ){
133612 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
133613 assert( db->pDfltColl!=0 );
133616 db->openFlags = flags;
133617 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
133619 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
133620 sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
133626 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
133632 sqlite3Error(db, rc);
133635 sqlite3BtreeEnter(db->aDb[0].pBt);
133636 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
133637 if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
133638 sqlite3BtreeLeave(db->aDb[0].pBt);
133639 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
133644 db->aDb[0].zName = "main";
133645 db->aDb[0].safety_level = 3;
133646 db->aDb[1].zName = "temp";
133647 db->aDb[1].safety_level = 1;
133649 db->magic = SQLITE_MAGIC_OPEN;
133650 if( db->mallocFailed ){
133658 sqlite3Error(db, SQLITE_OK);
133659 sqlite3RegisterBuiltinFunctions(db);
133664 rc = sqlite3_errcode(db);
133666 sqlite3AutoLoadExtensions(db);
133667 rc = sqlite3_errcode(db);
133674 if( !db->mallocFailed ){
133676 rc = sqlite3Fts1Init(db);
133681 if( !db->mallocFailed && rc==SQLITE_OK ){
133683 rc = sqlite3Fts2Init(db);
133688 if( !db->mallocFailed && rc==SQLITE_OK ){
133689 rc = sqlite3Fts3Init(db);
133694 if( !db->mallocFailed && rc==SQLITE_OK ){
133695 rc = sqlite3Fts5Init(db);
133700 if( !db->mallocFailed && rc==SQLITE_OK ){
133701 rc = sqlite3IcuInit(db);
133706 if( !db->mallocFailed && rc==SQLITE_OK){
133707 rc = sqlite3RtreeInit(db);
133712 if( !db->mallocFailed && rc==SQLITE_OK){
133713 rc = sqlite3DbstatRegister(db);
133718 if( !db->mallocFailed && rc==SQLITE_OK){
133719 rc = sqlite3Json1Init(db);
133728 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
133729 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
133733 if( rc ) sqlite3Error(db, rc);
133736 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
133739 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
133743 if( db ){
133744 assert( db->mutex!=0 || isThreadsafe==0
133746 sqlite3_mutex_leave(db->mutex);
133748 rc = sqlite3_errcode(db);
133749 assert( db!=0 || rc==SQLITE_NOMEM );
133751 sqlite3_close(db);
133752 db = 0;
133754 db->magic = SQLITE_MAGIC_SICK;
133756 *ppDb = db;
133759 /* Opening a db handle. Fourth parameter is passed 0. */
133761 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
133779 sqlite3 **ppDb, /* OUT: SQLite db handle */
133827 ** Register a new collation sequence with the database handle db.
133830 sqlite3* db,
133836 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
133840 ** Register a new collation sequence with the database handle db.
133843 sqlite3* db,
133853 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
133855 sqlite3_mutex_enter(db->mutex);
133856 assert( !db->mallocFailed );
133857 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
133858 rc = sqlite3ApiExit(db, rc);
133859 sqlite3_mutex_leave(db->mutex);
133865 ** Register a new collation sequence with the database handle db.
133868 sqlite3* db,
133878 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
133880 sqlite3_mutex_enter(db->mutex);
133881 assert( !db->mallocFailed );
133882 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
133884 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
133885 sqlite3DbFree(db, zName8);
133887 rc = sqlite3ApiExit(db, rc);
133888 sqlite3_mutex_leave(db->mutex);
133895 ** db. Replace any previously installed collation sequence factory.
133898 sqlite3 *db,
133903 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
133905 sqlite3_mutex_enter(db->mutex);
133906 db->xCollNeeded = xCollNeeded;
133907 db->xCollNeeded16 = 0;
133908 db->pCollNeededArg = pCollNeededArg;
133909 sqlite3_mutex_leave(db->mutex);
133916 ** db. Replace any previously installed collation sequence factory.
133919 sqlite3 *db,
133924 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
133926 sqlite3_mutex_enter(db->mutex);
133927 db->xCollNeeded = 0;
133928 db->xCollNeeded16 = xCollNeeded16;
133929 db->pCollNeededArg = pCollNeededArg;
133930 sqlite3_mutex_leave(db->mutex);
133951 SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3 *db){
133953 if( !sqlite3SafetyCheckOk(db) ){
133958 return db->autoCommit;
134012 sqlite3 *db, /* Connection handle */
134035 if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
134041 sqlite3_mutex_enter(db->mutex);
134042 sqlite3BtreeEnterAll(db);
134043 rc = sqlite3Init(db, &zErrMsg);
134049 pTab = sqlite3FindTable(db, zTableName, zDbName);
134101 sqlite3BtreeLeaveAll(db);
134114 sqlite3DbFree(db, zErrMsg);
134115 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
134119 sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
134120 sqlite3DbFree(db, zErrMsg);
134121 rc = sqlite3ApiExit(db, rc);
134122 sqlite3_mutex_leave(db->mutex);
134145 SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3 *db, int onoff){
134147 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
134149 sqlite3_mutex_enter(db->mutex);
134150 db->errMask = onoff ? 0xffffffff : 0xff;
134151 sqlite3_mutex_leave(db->mutex);
134158 SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
134163 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
134165 sqlite3_mutex_enter(db->mutex);
134166 db, zDbName);
134185 sqlite3_mutex_leave(db->mutex);
134373 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
134376 ** connection db.
134379 sqlite3 *db = va_arg(ap, sqlite3*);
134381 sqlite3_mutex_enter(db->mutex);
134382 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
134383 sqlite3_mutex_leave(db->mutex);
134387 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
134397 sqlite3 *db = va_arg(ap, sqlite3*);
134398 db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
134475 /* sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */
134477 sqlite3 *db = va_arg(ap, sqlite3*);
134478 db->nMaxSorterMmap = va_arg(ap, int);
134492 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
134494 ** This test control is used to create imposter tables. "db" is a pointer
134509 sqlite3 *db = va_arg(ap, sqlite3*);
134510 sqlite3_mutex_enter(db->mutex);
134511 db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
134512 db->init.busy = db->init.imposterTable = va_arg(ap,int);
134513 db->init.newTnum = va_arg(ap,int);
134514 if( db->init.busy==0 && db->init.newTnum>0 ){
134515 sqlite3ResetAllSchemasOfConnection(db);
134517 sqlite3_mutex_leave(db->mutex);
134577 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
134579 for(i=0; i<db->nDb; i++){
134580 if( db->aDb[i].pBt
134581 && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
134583 return db->aDb[i].pBt;
134593 SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName){
134596 if( !sqlite3SafetyCheckOk(db) ){
134601 pBt = sqlite3DbNameToBtree(db, zDbName);
134609 SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
134612 if( !sqlite3SafetyCheckOk(db) ){
134617 pBt = sqlite3DbNameToBtree(db, zDbName);
134675 ** 3) If the argument db is not NULL, then none of the entries in the
134677 ** set to db. This is used when closing connection db.
134679 static void checkListProperties(sqlite3 *db){
134692 assert( db==0 || p->pUnlockConnection!=db );
134693 assert( db==0 || p->pBlockingConnection!=db );
134702 ** Remove connection db from the blocked connections list. If connection
134703 ** db is not currently a part of the list, this function is a no-op.
134705 static void removeFromBlockedList(sqlite3 *db){
134709 if( *pp==db ){
134717 ** Add connection db to the blocked connections list. It is assumed
134720 static void addToBlockedList(sqlite3 *db){
134725 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
134728 db->pNextBlocked = *pp;
134729 *pp = db;
134752 ** This is called after connection "db" has attempted some operation
134755 ** cache. pOther is found by looking at db->pBlockingConnection.
134760 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
134767 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
134771 sqlite3 *db,
134777 sqlite3_mutex_enter(db->mutex);
134781 removeFromBlockedList(db);
134782 db->pBlockingConnection = 0;
134783 db->pUnlockConnection = 0;
134784 db->xUnlockNotify = 0;
134785 db->pUnlockArg = 0;
134786 }else if( 0==db->pBlockingConnection ){
134795 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
134799 db->pUnlockConnection = db->pBlockingConnection;
134800 db->xUnlockNotify = xNotify;
134801 db->pUnlockArg = pArg;
134802 removeFromBlockedList(db);
134803 addToBlockedList(db);
134808 assert( !db->mallocFailed );
134809 sqlite3ErrorWithMsg(db, rc, (rc?"database is deadlocked":0));
134810 sqlite3_mutex_leave(db->mutex);
134816 ** associated with connection db. The operation will return SQLITE_LOCKED
134820 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
134822 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
134823 addToBlockedList(db);
134825 db->pBlockingConnection = pBlocker;
134831 ** the transaction opened by database db has just finished. Locks held
134832 ** by database connection db have been released.
134838 ** set to db, then set pBlockingConnection=0.
134841 ** set to db, then invoke the configured unlock-notify callback and
134848 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
134864 if( p->pBlockingConnection==db ){
134869 if( p->pUnlockConnection==db ){
134896 ** is returned the transaction on connection db will still be
134947 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
134948 sqlite3ConnectionUnlocked(db);
134950 removeFromBlockedList(db);
134951 checkListProperties(db);
135741 sqlite3 *db; /* The database connection */
136109 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
136110 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
136118 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
136384 sqlite3 *db, /* Database in which to run SQL */
136397 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
136409 sqlite3 *db = p->db; /* Database handle */
136413 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
136415 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
136416 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
136417 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
136418 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
136446 sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
136462 rc = sqlite3_declare_vtab(p->db, zSql);
136475 fts3DbExec(pRc, p->db,
136495 sqlite3 *db = p->db; /* The database connection */
136513 fts3DbExec(&rc, db,
136521 fts3DbExec(&rc, db,
136525 fts3DbExec(&rc, db,
136538 fts3DbExec(&rc, db,
136567 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
136888 sqlite3 *db, /* Database handle */
136889 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
136904 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
136906 sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
136964 sqlite3 *db, /* The SQLite database connection */
137159 rc = fts3ContentColumns(db, argv[1], zContent,&aCol,&nCol,&nString,pzErr);
137212 p->db = db;
137340 sqlite3 *db, /* Database connection */
137347 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
137350 sqlite3 *db, /* Database connection */
137357 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
137571 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
139108 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
139248 int mxLevel = 0; /* Maximum relative level value in db */
139274 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
139568 sqlite3 *db = p->db; /* Database connection */
139587 fts3DbExec(&rc, db,
139594 fts3DbExec(&rc, db,
139600 fts3DbExec(&rc, db,
139605 fts3DbExec(&rc, db,
139609 fts3DbExec(&rc, db,
139725 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
139744 rc = sqlite3Fts3InitTerm(db);
139748 rc = sqlite3Fts3InitAux(db);
139780 rc = sqlite3Fts3ExprInitTestInterface(db);
139789 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
139790 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
139791 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
139792 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
139793 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
139794 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
139797 db, "fts3", &fts3Module, (void *)pHash, hashDestroy
139801 db, "fts4", &fts3Module, (void *)pHash, 0
139805 rc = sqlite3Fts3InitTok(db, (void *)pHash);
140933 ** the db. In this case the position-list is not populated at all.
141768 sqlite3 *db,
141773 return sqlite3Fts3Init(db);
141838 sqlite3 *db, /* Database connection */
141858 ** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
141877 rc = sqlite3_declare_vtab(db, FTS3_AUX_SCHEMA);
141888 p->pFts3Tab->db = db;
142295 ** Register the fts3aux module with database connection db. Return SQLITE_OK
142298 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db){
142326 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
143448 sqlite3 *db,
143457 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
143554 sqlite3 *db = sqlite3_context_db_handle(context);
143563 rc = queryTestTokenizer(db,
143627 ** with database connection db.
143629 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
143631 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
143634 rc = sqlite3_create_function(db, "fts3_exprtest_rebalance",
145029 sqlite3 *db,
145037 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
145051 sqlite3 *db,
145060 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
145103 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
145110 rc = queryTokenizer(db, "simple", &p2);
145113 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
145116 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
145119 rc = registerTokenizer(db, "nosuchtokenizer", p1);
145121 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
145131 ** Set up SQL objects in database db used to access the contents of
145148 sqlite3 *db,
145159 void *pdb = (void *)db;
145168 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
145171 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
145175 rc = sqlite3_create_function(db, zTest, -1, any, p, testFunc, 0, 0);
145178 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
145589 sqlite3 *db, /* Database connection */
145603 rc = sqlite3_declare_vtab(db, FTS3_TOK_SCHEMA);
145849 ** Register the fts3tok module with database connection db. Return SQLITE_OK
145852 SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){
145880 rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
146220 ** of the oldest level in the db that contains at least ? segments. Or,
146296 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
146901 *piDocid = sqlite3_last_insert_rowid(p->db);
147099 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
148014 ** blocks were written to the db). Otherwise, an SQLite error code is
148230 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
148237 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
149395 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
150532 ** Each input segment is either removed from the db completely (if all of
151070 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
151490 if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
151548 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
151552 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
151555 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
151556 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
154155 sqlite3 *db; /* Host database connection */
154706 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
154799 sqlite3 *db,
154805 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
154812 sqlite3 *db,
154818 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
154873 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
156725 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
156921 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
156989 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
157000 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
157011 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
157060 sqlite3 *db,
157087 pRtree->db = db;
157101 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
157118 rc = rtreeQueryStat1(db, pRtree);
157122 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
157135 ** using database connection db. If successful, the integer value returned
157139 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
157143 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
157170 sqlite3 *db, /* Database handle */
157180 rc = getIntFromStmt(db, zSql, &iPageSize);
157187 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157194 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
157196 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157214 sqlite3 *db, /* Database connection */
157240 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
157261 rc = getNodeSize(db, pRtree, isCreate, pzErr);
157268 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
157269 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157286 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
157287 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
157387 ** Register the r-tree module with database handle db. This creates the
157391 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
157395 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
157397 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
157405 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
157409 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
157493 sqlite3 *db, /* Register SQL function on this connection */
157507 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
157517 sqlite3 *db, /* Register SQL function on this connection */
157532 return sqlite3_create_function_v2(db, zQueryFunc, -1, SQLITE_ANY,
157542 sqlite3 *db,
157547 return sqlite3RtreeInit(db);
157970 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
157993 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
158003 ** Register the ICU extension functions with database db.
158005 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
158028 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
158037 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
158049 sqlite3 *db,
158054 return sqlite3IcuInit(db);
158534 ** example, if the target db contains either of the following:
158751 ** the rbu update db handle to any required virtual table
158765 ** Do some work towards applying the RBU update to the target db.
158933 ** target db file.
159029 const char *zTbl; /* Name of target db table */
159030 const char *zDataTbl; /* Name of rbu db table (or null) */
159031 const char *zIdx; /* Name of target db index (or null) */
159092 char *zTarget; /* Path to target db */
159093 char *zRbu; /* Path to rbu db */
159094 char *zState; /* Path to state db (or NULL if zRbu) */
159095 char zStateDb[5]; /* Db name for state ("stat" or "main") */
159102 rbu_file *pTargetFd; /* File handle open on target db */
159125 rbu_file *pMain; /* Linked list of main db files */
159139 u32 iCookie; /* Cookie value for main db files */
159140 u8 iWriteVer; /* "write-version" value for main db files */
159146 const char *zWal; /* Wal filename for this main db file */
159147 rbu_file *pWalFd; /* Wal file descriptor for this main db */
159399 ** Prepare the SQL statement in buffer zSql against database handle db.
159409 sqlite3 *db,
159414 int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0);
159416 *pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
159441 ** statement against database db and frees the buffer. If statement
159454 sqlite3 *db,
159465 rc = prepareAndCollectError(db, ppStmt, pzErrmsg, zSql);
159695 static int rbuMPrintfExec(sqlite3rbu *p, sqlite3 *db, const char *zFmt, ...){
159704 p->rc = sqlite3_exec(db, zSql, 0, 0, &p->zErrmsg);
159792 sqlite3 *db = sqlite3_db_handle(pStmt);
159796 db));
160903 sqlite3 *db = 0;
160906 p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
160908 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
160909 sqlite3_close(db);
160910 db = 0;
160913 return db;
160929 ** the RBU db handle now. */
160988 ** test.db-journal => test.nal
160989 ** test.db-wal => test.wal
160990 ** test.db-shm => test.shm
160991 ** test.db-mj7f3319fa => test.9fa
161032 ** (wal frame -> db page) copy operations required to checkpoint the
161219 /* Move the *-oal file to *-wal. At this point connection p->db is
161221 ** in WAL mode). So no other connection may be writing the db.
161597 /* Sync the db file */
161889 sqlite3 *db = p->dbMain;
161893 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
161898 /* Check if the main database is a zipvfs db. If it is, set the upper
161902 int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
161904 p->rc = sqlite3_exec(db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
161945 sqlite3 *db = 0;
161947 db = (bRbu ? pRbu->dbRbu : pRbu->dbMain);
161949 return db;
162060 ** db fds opened using a particular RBU VFS is maintained at
162063 ** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
162082 ** 3b. The *-shm pages returned by xShmMap() for a target db file in
162543 ** the name of the *-wal file this db connection will use. SQLite
162979 sqlite3 *db;
162991 sqlite3 *db,
163002 iDb = sqlite3FindDbName(db, argv[3]);
163010 rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
163019 pTab->db = db;
163261 Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
163290 Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt;
163435 pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
163453 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
163457 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
163505 sqlite3 *db = sqlite3_context_db_handle(ctx);
163507 sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
163523 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){
163546 return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
163549 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
165090 sqlite3 *db,
165115 rc = sqlite3_declare_vtab(db,
165539 SQLITE_PRIVATE int sqlite3Json1Init(sqlite3 *db){
165578 rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg,
165585 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
165597 sqlite3 *db,
165603 return sqlite3Json1Init(db);
166282 sqlite3 *db; /* Database handle */
169358 sqlite3 *db,
169372 pRet->db = db;
169517 rc = sqlite3_declare_vtab(pConfig->db, zSql);
169731 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p, 0);
171809 sqlite3 *db = sqlite3_context_db_handle(pCtx);
171851 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
171943 static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
171959 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
173138 rc = sqlite3_blob_open(pConfig->db,
173196 p->rc = sqlite3_prepare_v2(p->pConfig->db, zSql, -1, ppStmt, 0);
173245 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &p->pDeleter, 0);
177332 rc = sqlite3_blob_open(pConfig->db, pConfig->zDb, p->zDataTbl,
178191 ** connection db. It registers several user-defined scalar functions useful
178197 static int sqlite3Fts5IndexInit(sqlite3 *db){
178199 db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0
178203 db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0
178286 sqlite3 *db; /* Associated database connection */
178565 sqlite3 *db, /* The SQLite database connection */
178581 rc = sqlite3Fts5ConfigParse(pGlobal, db, argc, azConfig, &pConfig, pzErr);
178621 sqlite3 *db, /* Database connection */
178628 return fts5InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
178631 sqlite3 *db, /* Database connection */
178638 return fts5InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
179069 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pSorter->pStmt, 0);
179166 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pStmt, 0);
179659 int eConflict = sqlite3_vtab_on_conflict(pConfig->db);
180416 fts5_api *pApi, /* Global context (one per db handle) */
180423 int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
180455 fts5_api *pApi, /* Global context (one per db handle) */
180511 fts5_api *pApi, /* Global context (one per db handle) */
180608 static int fts5Init(sqlite3 *db){
180644 pGlobal->db = db;
180649 rc = sqlite3_create_module_v2(db, "fts5", &fts5Mod, p, fts5ModuleDestroy);
180650 if( rc==SQLITE_OK ) rc = sqlite3Fts5IndexInit(db);
180651 if( rc==SQLITE_OK ) rc = sqlite3Fts5ExprInit(pGlobal, db);
180654 if( rc==SQLITE_OK ) rc = sqlite3Fts5VocabInit(pGlobal, db);
180657 db, "fts5", 0, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
180662 db, "fts5_source_id", 0, SQLITE_UTF8, p, fts5SourceIdFunc, 0, 0
180683 sqlite3 *db,
180689 return fts5Init(db);
180696 sqlite3 *db,
180702 return fts5Init(db);
180705 SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3 *db){
180706 return fts5Init(db);
180847 rc = sqlite3_prepare_v2(pC->db, zSql, -1, &p->aStmt[eStmt], 0);
180850 *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
180861 sqlite3 *db,
180876 rc = sqlite3_exec(db, zSql, 0, 0, pzErr);
180889 int rc = fts5ExecPrintf(pConfig->db, 0,
180898 rc = fts5ExecPrintf(pConfig->db, 0,
180904 rc = fts5ExecPrintf(pConfig->db, 0,
180919 *pRc = fts5ExecPrintf(pConfig->db, 0,
180956 rc = fts5ExecPrintf(pConfig->db, &zErr, "CREATE TABLE %Q.'%q_%q'(%s)%s",
181304 rc = fts5ExecPrintf(pConfig->db, 0,
181311 rc = fts5ExecPrintf(pConfig->db, 0,
181409 *piRowid = sqlite3_last_insert_rowid(p->pConfig->db);
181454 *piRowid = sqlite3_last_insert_rowid(pConfig->db);
181522 rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pCnt, 0);
183801 char *zFts5Db; /* Db containing fts5 table */
183802 sqlite3 *db; /* Database handle */
183902 sqlite3 *db, /* The SQLite database connection */
183935 rc = sqlite3_declare_vtab(db, azSchema[eType]);
183943 pRet->db = db;
183963 sqlite3 *db, /* Database connection */
183970 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
183973 sqlite3 *db, /* Database connection */
183980 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
184014 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
184214 static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){
184242 return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);