Lines Matching refs:Db
2366 sqlite3 *db, /* An open database */
2428 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2456 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2895 sqlite3 **ppDb /* OUT: SQLite db handle */
2899 sqlite3 **ppDb /* OUT: SQLite db handle */
2903 sqlite3 **ppDb, /* OUT: SQLite db handle */
2941 SQLITE_API int sqlite3_errcode(sqlite3 *db);
2942 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3082 ** The first argument, "db", is a [database connection] obtained from a
3156 sqlite3 *db, /* Database handle */
3163 sqlite3 *db, /* Database handle */
3170 sqlite3 *db, /* Database handle */
3177 sqlite3 *db, /* Database handle */
3980 sqlite3 *db,
3990 sqlite3 *db,
4000 sqlite3 *db,
4501 sqlite3 *db, /* Database to be rekeyed */
4514 sqlite3 *db, /* Database to be rekeyed */
4905 sqlite3 *db, /* Connection handle */
4942 sqlite3 *db, /* Load the extension into this database connection */
4961 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4978 ** sqlite3 *db,
5191 sqlite3 *db, /* SQLite connection to register module with */
5197 sqlite3 *db, /* SQLite connection to register module with */
6713 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6729 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
6774 sqlite3 *db,
7364 typedef struct Db Db;
7465 sqlite3 *db, /* Associated database connection */
7479 #define BTREE_MEMORY 4 /* This is an in-memory DB */
8801 struct Db {
8827 ** Db.pSchema->flags field.
8835 ** Allowed values for the DB.pSchema->flags field.
8927 Db *aDb; /* All backends */
9004 Db aDbStatic[2]; /* Static space for the 2 default backends */
9034 #define ENC(db) ((db)->aDb[0].pSchema->enc)
9349 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
9353 sqlite3 *db; /* Database connection associated with this table */
9527 sqlite3 *db; /* The database connection */
10281 sqlite3 *db; /* The main database structure */
10354 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
10389 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
10390 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
10504 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
10520 sqlite3 *db; /* The database being initialized */
11068 SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
11097 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11104 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
11149 # define sqlite3VtabInSync(db) 0
11154 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
11155 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
11156 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
11157 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
11161 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
11264 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
11265 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
12013 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12120 sqlite3 *db; /* The associated database connection */
12258 sqlite3 *db; /* The database connection that owns this statement */
12259 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12293 int nChange; /* Number of db changes made since last reset */
12294 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12494 sqlite3 *db, /* The database connection whose status is desired */
12501 sqlite3_mutex_enter(db->mutex);
12504 *pCurrent = db->lookaside.nOut;
12505 *pHighwater = db->lookaside.mxOut;
12507 db->lookaside.mxOut = db->lookaside.nOut;
12520 sqlite3BtreeEnterAll(db);
12521 for(i=0; i<db->nDb; i++){
12522 Btree *pBt = db->aDb[i].pBt;
12528 sqlite3BtreeLeaveAll(db);
12543 db->pnBytesFreed = &nByte;
12544 for(i=0; i<db->nDb; i++){
12545 Schema *pSchema = db->aDb[i].pSchema;
12561 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
12564 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
12568 db->pnBytesFreed = 0;
12584 db->pnBytesFreed = &nByte;
12585 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
12586 sqlite3VdbeDeleteObject(db, pVdbe);
12588 db->pnBytesFreed = 0;
12600 sqlite3_mutex_leave(db->mutex);
12913 sqlite3 *db = sqlite3_context_db_handle(context);
12914 sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
13452 sqlite3 *db;
13456 db = sqlite3_context_db_handle(context);
13492 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
13493 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
13496 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
13500 z = sqlite3DbMallocRaw(db, (int)n);
13636 sqlite3 *db;
13643 db = sqlite3_context_db_handle(context);
13644 sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
17885 ** TRUE if p is a lookaside memory allocation from db
17888 static int isLookaside(sqlite3 *db, void *p){
17889 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
17904 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
17905 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17906 if( db && isLookaside(db, p) ){
17907 return db->lookaside.sz;
17911 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17938 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
17939 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17940 if( db ){
17941 if( db->pnBytesFreed ){
17942 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
17945 if( isLookaside(db, p) ){
17947 pBuf->pNext = db->lookaside.pFree;
17948 db->lookaside.pFree = pBuf;
17949 db->lookaside.nOut--;
17955 assert( db
18037 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
18038 void *p = sqlite3DbMallocRaw(db, n);
18049 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
18056 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
18057 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
18063 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
18065 assert( db==0 || sqlite3_mutex_held(db->mutex) );
18066 assert( db==0 || db->pnBytesFreed==0 );
18068 if( db ){
18070 if( db->mallocFailed ){
18073 if( db->lookaside.bEnabled && n<=db->lookaside.sz
18074 && (pBuf = db->lookaside.pFree)!=0 ){
18075 db->lookaside.pFree = pBuf->pNext;
18076 db->lookaside.nOut++;
18077 if( db->lookaside.nOut>db->lookaside.mxOut ){
18078 db->lookaside.mxOut = db->lookaside.nOut;
18084 if( db && db->mallocFailed ){
18089 if( !p && db ){
18090 db->mallocFailed = 1;
18093 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
18101 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
18103 assert( db!=0 );
18104 assert( sqlite3_mutex_held(db->mutex) );
18105 if( db->mallocFailed==0 ){
18107 return sqlite3DbMallocRaw(db, n);
18109 if( isLookaside(db, p) ){
18110 if( n<=db->lookaside.sz ){
18113 pNew = sqlite3DbMallocRaw(db, n);
18115 memcpy(pNew, p, db->lookaside.sz);
18116 sqlite3DbFree(db, p);
18125 db->mallocFailed = 1;
18128 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
18138 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
18140 pNew = sqlite3DbRealloc(db, p, n);
18142 sqlite3DbFree(db, p);
18154 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
18162 zNew = sqlite3DbMallocRaw(db, (int)n);
18168 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
18174 zNew = sqlite3DbMallocRaw(db, n+1);
18187 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){
18192 z = sqlite3VMPrintf(db, zFormat, ap);
18194 sqlite3DbFree(db, *pz);
18208 ** If the first argument, db, is not NULL and a malloc() error has occurred,
18212 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
18213 /* If the db handle is not NULL, then we must hold the connection handle
18214 ** mutex here. Otherwise the read (and possible write) of db->mallocFailed
18217 assert( !db || sqlite3_mutex_held(db->mutex) );
18218 if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
18219 sqlite3Error(db, SQLITE_NOMEM, 0);
18220 db->mallocFailed = 0;
18223 return rc & (db ? db->errMask : 0xff);
19002 zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
19031 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
19051 sqlite3DbFree(p->db, p->zText);
19064 p->db = 0;
19077 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
19081 assert( db!=0 );
19083 db->aLimit[SQLITE_LIMIT_LENGTH]);
19084 acc.db = db;
19088 db->mallocFailed = 1;
19097 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
19101 z = sqlite3VMPrintf(db, zFormat, ap);
19111 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
19114 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3 *db, char *zStr, const char *zFormat, ...){
19118 z = sqlite3VMPrintf(db, zFormat, ap);
19120 sqlite3DbFree(db, zStr);
19603 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
19667 zOut = sqlite3DbMallocRaw(pMem->db, len);
19831 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
19834 m.db = db;
19837 if( db->mallocFailed ){
19841 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
19842 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
19843 assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
19844 assert( m.z || db->mallocFailed );
19855 ** If a malloc failure occurs, NULL is returned and the db.mallocFailed
19859 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
19862 m.db = db;
19865 assert( db->mallocFailed );
20050 ** handle "db". The error code is set to "err_code".
20065 ** To clear the most recent error for sqlite handle "db", sqlite3Error
20069 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
20070 if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
20071 db->errCode = err_code;
20076 z = sqlite3VMPrintf(db, zFormat, ap);
20078 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
20080 sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
20105 sqlite3 *db = pParse->db;
20107 zMsg = sqlite3VMPrintf(db, zFormat, ap);
20109 if( db->suppressErr ){
20110 sqlite3DbFree(db, zMsg);
20113 sqlite3DbFree(db, pParse->zErrMsg);
20943 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
20947 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
20972 ** Check to make sure we have a valid db pointer. This test is not
20974 ** misuse of the interface such as passing in db pointers that are
20976 ** 1 it means that the db pointer is valid and 0 if it should not be
20980 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
20981 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
20985 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
20987 if( db==0 ){
20991 magic = db->magic;
20993 if( sqlite3SafetyCheckSickOrOk(db) ){
21002 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
21004 magic = db->magic;
26433 ** is "/home/user1/config.db" then the file that is created and mmapped
26434 ** for shared memory will be called "/home/user1/config.db-shm".
27199 ** proxyLock activation is possible (remote proxy is based on db name)
27526 ** "<path to db>-journal"
27527 ** "<path to db>-wal"
27528 ** "<path to db>-journal-NNNN"
27529 ** "<path to db>-wal-NNNN"
27627 /* The main DB, main journal, WAL file and master journal are never
28193 ** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
28195 ** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
28210 ** For database path "/Users/me/foo.db"
28211 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
28344 /* transform the db path to a unique cache name */
29002 /* afp style keeps a reference to the db path in the filePath field
29014 /* all other styles use the locking context to store the db file path */
31723 /* The main DB, main journal, WAL file and master journal are never
34368 sqlite3 *db; /* The database connection */
34380 ** are available at pSpace. The db pointer is used as a memory context
34390 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
34395 p->db = db;
34415 sqlite3DbFree(p->db, pChunk);
34437 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
34800 int sync_flags, /* Flags to sync db file with (or 0) */
35089 ** db size etc.) are consistent with the contents of the file-system.
35502 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
35503 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
36691 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
37137 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
37854 i64 n = 0; /* Size of db file in bytes */
37894 ** function. Because an EXCLUSIVE lock on the db file is required to delete
39155 ROUND8(pVfs->szOsFile) + /* The main db file */
40493 int noSync /* True to omit the xSync on the db file */
40514 /* If this is an in-memory db, or no pages have been written to, or this
40565 /* Update the db file change counter via the direct-write method. The
41940 u32 nBackfill; /* Number of WAL frames backfilled into DB */
42230 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
42257 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
43203 ** about the eventual size of the db file to the VFS layer.
43213 /* Iterate through the contents of the WAL, copying data to the db file. */
44115 u32 nDbsize; /* Db
44223 int sync_flags, /* Flags to sync db file with (or 0) */
44712 sqlite3 *db; /* The database connection holding this btree */
44715 u8 sharable; /* True if we can share pBt with another db */
44716 u8 locked; /* True if db currently has pBt locked */
44719 Btree *pNext; /* List of other sharable Btrees from the same db */
44774 sqlite3 *db; /* Database connection currently using this Btree */
44805 u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
44848 ** particular database connection identified BtCursor.pBtree.db.
45021 ** set BtShared.db to the database handle associated with p and the
45027 assert( sqlite3_mutex_held(p->db->mutex) );
45030 p->pBt->db = p->db;
45041 assert( sqlite3_mutex_held(p->db->mutex) );
45042 assert( p->db==p->pBt->db );
45073 assert( p->pNext==0 || p->pNext->db==p->db );
45074 assert( p->pPrev==0 || p->pPrev->db==p->db );
45082 assert( sqlite3_mutex_held(p->db->mutex) );
45084 /* Unless the database is sharable and unlocked, then BtShared.db
45086 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
45097 p->pBt->db = p->db;
45145 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
45147 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
45183 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
45186 assert( sqlite3_mutex_held(db->mutex) );
45187 for(i=0; i<db->nDb; i++){
45188 p = db->aDb[i].pBt;
45189 assert( !p || (p->locked==0 && p->sharable) || p->pBt->db==p->db );
45211 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
45214 assert( sqlite3_mutex_held(db->mutex) );
45215 for(i=0; i<db->nDb; i++){
45216 p = db->aDb[i].pBt;
45234 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
45236 if( !sqlite3_mutex_held(db->mutex) ){
45239 for(i=0; i<db->nDb; i++){
45241 p = db->aDb[i].pBt;
45306 assert( sqlite3_mutex_held(p->db->mutex) );
45332 assert( sqlite3_mutex_held(p->db->mutex) );
45343 p->pBt->db = p->db;
45345 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
45347 for(i=0; i<db->nDb; i++){
45348 Btree *p = db->aDb[i].pBt;
45350 p->pBt->db = p->db;
45493 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
45564 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
45585 assert( p->db!=0 );
45586 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
45604 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
45621 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
45658 assert( p->db!=0 );
45664 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
47023 assert( pBt->db );
47024 assert( sqlite3_mutex_held(pBt->db->mutex) );
47025 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
47042 ** bit is also set if the SQLITE_NoReadlock flags is set in db->flags.
47054 sqlite3 *db, /* Associated database handle */
47077 || (isTempDb && sqlite3TempInMemory(db));
47080 assert( db!=0 );
47081 assert( sqlite3_mutex_held(db->mutex) );
47090 if( db->flags & SQLITE_NoReadlock ){
47099 pVfs = db->pVfs;
47105 p->db = db;
47136 for(iDb=db->nDb-1; iDb>=0; iDb--){
47137 Btree *pExisting = db->aDb[iDb].pBt;
47192 pBt->db = db;
47243 db->mallocFailed = 0;
47263 for(i=0; i<db->nDb; i++){
47264 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
47378 assert( sqlite3_mutex_held(p->db->mutex) );
47445 assert( sqlite3_mutex_held(p->db->mutex) );
47468 assert( sqlite3_mutex_held(p->db->mutex) );
47484 assert( sqlite3_mutex_held(p->db->mutex) );
47746 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
47916 pBlock = pBt->pWriter->db;
47921 pBlock = pIter->pBtree->db;
47927 sqlite3ConnectionBlocked(p->db, pBlock);
47954 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
47991 /* If the db-size header field is incorrect (as it may be if an old
48013 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
48485 if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){
48707 assert( iStatement>p->db->nSavepoint );
49426 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49435 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49673 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49696 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49766 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49807 ** would have already detected db corruption. Similarly, pPage must
52522 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
53287 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
53319 assert( sqlite3_mutex_held(p->db->mutex) );
53325 assert( sqlite3_mutex_held(p->db->mutex) );
53367 assert( sqlite3_mutex_held(p->db->mutex) );
53415 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
53457 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53597 pParse->db = pDb;
53815 int nSrcPage = -1; /* Size of source db in pages */
53816 int bCloseTrans = 0; /* True if src db requires unlocking */
54132 b.pSrcDb = pFrom->db;
54204 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54243 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
54245 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
54248 sqlite3DbFree(pMem->db, pMem->zMalloc);
54249 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
54280 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54309 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54333 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54364 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54408 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54411 ctx.s.db = pMem->db;
54416 sqlite3DbFree(pMem->db, pMem->zMalloc);
54429 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
54458 sqlite3DbFree(p->db, p->zMalloc);
54518 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54543 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54567 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54594 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54608 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54627 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54712 sqlite3 *db = pMem->db;
54713 assert( db!=0 );
54716 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
54717 if( db->mallocFailed ){
54721 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
54722 sqlite3DbMallocSize(db, pMem->zMalloc));
54733 assert( p->db!=0 );
54739 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
54818 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
54819 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
54820 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
54855 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54864 if( pMem->db ){
54865 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
55116 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
55140 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
55141 || pVal->db->mallocFailed );
55152 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
55153 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
55157 p->db = db;
55173 sqlite3 *db, /* The database connection */
55213 pVal = sqlite3ValueNew(db);
55218 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
55234 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
55247 pVal = sqlite3ValueNew(db);
55252 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
55264 db->mallocFailed = 1;
55265 sqlite3DbFree(db, zVal);
55290 sqlite3DbFree(((Mem*)v)->db, v);
55343 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
55345 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
55347 p->db = db;
55348 if( db->pVdbe ){
55349 db->pVdbe->pPrev = p;
55351 p->pNext = db->pVdbe;
55353 db->pVdbe = p;
55368 p->zSql = sqlite3DbStrNDup(p->db, z, n);
55422 pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
55424 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
55542 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
55544 p->nLabelAlloc = sqlite3DbMallocSize(p->db, p->aLabel)/sizeof(p->aLabel[0]);
55588 ** sqlite3DbFree(v->db, sIter.apSub);
55630 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
55683 sqlite3DbFree(v->db, sIter.apSub);
55690 return ( v->db->mallocFailed || hasAbort==mayAbort );
55738 sqlite3DbFree(p->db, p->aLabel);
55765 assert( aOp && !p->db->mallocFailed );
55878 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
55880 sqlite3DbFree(db, pDef);
55889 static void freeP4(sqlite3 *db, int p4type, void *p4){
55891 assert( db );
55899 sqlite3DbFree(db, p4);
55903 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
55908 freeEphemeralFunction(db, pVdbeFunc->pFunc);
55909 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
55910 sqlite3DbFree(db, pVdbeFunc);
55914 freeEphemeralFunction(db, (FuncDef*)p4);
55918 if( db->pnBytesFreed==0 ){
55922 sqlite3DbFree(db, p->zMalloc);
55923 sqlite3DbFree(db, p);
55928 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
55940 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
55944 freeP4(db, pOp->p4type, pOp->p4.p);
55946 sqlite3DbFree(db, pOp->zComment);
55950 sqlite3DbFree(db, aOp);
55969 sqlite3 *db = p->db;
55971 freeP4(db, pOp->p4type, pOp->p4.p);
56006 sqlite3 *db;
56008 db = p->db;
56010 if( p->aOp==0 || db->mallocFailed ){
56012 freeP4(db, n, (void*)*(char**)&zP4);
56022 freeP4(db, pOp->p4type, pOp->p4.p);
56050 p->db->mallocFailed = 1;
56060 assert( ((VTable *)zP4)->db==p->db );
56066 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
56082 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
56086 sqlite3DbFree(p->db, *pz);
56087 *pz = sqlite3VMPrintf(p->db, zFormat, ap);
56096 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
56100 sqlite3DbFree(p->db, *pz);
56101 *pz = sqlite3VMPrintf(p->db, zFormat, ap);
56139 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
56140 if( p->db->mallocFailed ){
56253 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
56262 assert( i>=0 && i<p->db->nDb && i<sizeof(u32)*8 );
56267 sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt);
56300 sqlite3 *db = p->db;
56301 u8 malloc_failed = db->mallocFailed;
56302 if( db->pnBytesFreed ){
56304 sqlite3DbFree(db, p->zMalloc);
56309 assert( (&p[1])==pEnd || p[0].db==p[1].db );
56326 sqlite3DbFree(db, p->zMalloc);
56332 db->mallocFailed = malloc_failed;
56348 sqlite3DbFree(p->v->db, p);
56374 sqlite3 *db = p->db; /* The database connection */
56392 db->mallocFailed = 1;
56428 }else if( db->u1.isInterrupted ){
56431 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
56499 assert( p->db->mallocFailed );
56516 assert( p->db->mallocFailed );
56663 sqlite3 *db = p->db;
56691 if( nVar>=0 && ALWAYS(db->mallocFailed==0) ){
56724 p->pFree = sqlite3DbMallocZero(db, nByte);
56728 }while( nByte && !db->mallocFailed );
56735 p->aVar[n].db = db;
56743 p->aMem[n].db = db;
56749 assert( p->aMem[n].db==db );
56813 v->db->lastRowid = pFrame->lastRowid;
56863 sqlite3 *db = p->db;
56873 sqlite3DbFree(db, p->zErrMsg);
56887 sqlite3 *db = p->db;
56890 sqlite3DbFree(db, p->aColName);
56893 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
56897 pColName->db = p->db;
56923 if( p->db->mallocFailed ){
56936 ** db. If a transaction is active, commit it. If there is a
56940 static int vdbeCommit(sqlite3 *db, Vdbe *p){
56959 rc = sqlite3VtabSync(db, &p->zErrMsg);
56967 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
56968 Btree *pBt = db->aDb[i].pBt;
56980 if( needXcommit && db->xCommitCallback ){
56981 rc = db->xCommitCallback(db->pCommitArg);
56996 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
56999 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
57000 Btree *pBt = db->aDb[i].pBt;
57011 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
57012 Btree *pBt = db->aDb[i].pBt;
57018 sqlite3VtabCommit(db);
57028 sqlite3_vfs *pVfs = db->pVfs;
57031 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
57039 sqlite3DbFree(db, zMaster);
57041 zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
57055 sqlite3DbFree(db, zMaster);
57065 for(i=0; i<db->nDb; i++){
57066 Btree *pBt = db->aDb[i].pBt;
57081 sqlite3DbFree(db, zMaster);
57096 sqlite3DbFree(db, zMaster);
57100 /* Sync all the db files involved in the transaction. The same call
57110 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
57111 Btree *pBt = db->aDb[i].pBt;
57119 sqlite3DbFree(db, zMaster);
57128 sqlite3DbFree(db, zMaster);
57143 for(i=0; i<db->nDb; i++){
57144 Btree *pBt = db->aDb[i].pBt;
57152 sqlite3VtabCommit(db);
57169 static void checkActiveVdbeCnt(sqlite3 *db){
57173 p = db->pVdbe;
57181 assert( cnt==db->activeVdbeCnt );
57182 assert( nWrite==db->writeVdbeCnt );
57189 ** For every Btree that in database connection db which
57204 static void invalidateCursorsOnModifiedBtrees(sqlite3 *db){
57206 for(i=0; i<db->nDb; i++){
57207 Btree *p = db->aDb[i].pBt;
57225 sqlite3 *const db = p->db;
57231 ** In this case (db->nStatement==0), and there is nothing to do.
57233 if( db->nStatement && p->iStatement ){
57238 assert( db->nStatement>0 );
57239 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
57241 for(i=0; i<db->nDb; i++){
57243 Btree *pBt = db->aDb[i].pBt;
57256 db->nStatement--;
57263 db->nDeferredCons = p->nStmtDefCons;
57273 ** sets the BtShared.db member of each of the BtShared structures, ensuring
57277 ** sqlite3BtreeEnterAll() is invoked to set the BtShared.db variables
57291 sqlite3BtreeEnterAll(p->db);
57308 sqlite3 *db = p->db;
57309 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){
57312 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
57334 sqlite3 *db = p->db;
57352 if( p->db->mallocFailed ){
57359 checkActiveVdbeCnt(db);
57395 invalidateCursorsOnModifiedBtrees(db);
57396 sqlite3RollbackAll(db);
57397 sqlite3CloseSavepoints(db);
57398 db->autoCommit = 1;
57414 if( !sqlite3VtabInSync(db)
57415 && db->autoCommit
57416 && db->writeVdbeCnt==(p->readOnly==0)
57427 rc = vdbeCommit(db, p);
57433 sqlite3RollbackAll(db);
57435 db->nDeferredCons = 0;
57436 sqlite3CommitInternalChanges(db);
57439 sqlite3RollbackAll(db);
57441 db->nStatement = 0;
57448 invalidateCursorsOnModifiedBtrees(db);
57449 sqlite3RollbackAll(db);
57450 sqlite3CloseSavepoints(db);
57451 db->autoCommit = 1;
57472 sqlite3DbFree(db, p->zErrMsg);
57475 invalidateCursorsOnModifiedBtrees(db);
57476 sqlite3RollbackAll(db);
57477 sqlite3CloseSavepoints(db);
57478 db->autoCommit = 1;
57487 sqlite3VdbeSetChanges(db, p->nChange);
57489 sqlite3VdbeSetChanges(db, 0);
57495 if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
57496 sqlite3ResetInternalSchema(db, 0);
57497 db->flags = (db->flags | SQLITE_InternChanges);
57506 db->activeVdbeCnt--;
57508 db->writeVdbeCnt--;
57510 assert( db->activeVdbeCnt>=db->writeVdbeCnt );
57513 checkActiveVdbeCnt(db);
57514 if( p->db->mallocFailed ){
57519 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
57522 if( db->autoCommit ){
57523 sqlite3ConnectionUnlocked(db);
57526 assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 );
57551 sqlite3 *db;
57552 db = p->db;
57568 sqlite3ValueSetStr(db->pErr,-1,p->zErrMsg,SQLITE_UTF8,SQLITE_TRANSIENT);
57570 db->errCode = p->rc;
57571 sqlite3DbFree(db, p->zErrMsg);
57574 sqlite3Error(db, p->rc, 0);
57576 sqlite3Error(db, SQLITE_OK, 0);
57584 sqlite3Error(db, p->rc, 0);
57585 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
57586 sqlite3DbFree(db, p->zErrMsg);
57619 return p->rc & db->errMask;
57630 assert( (rc & p->db->errMask)==rc );
57661 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
57663 assert( p->db==0 || p->db==db );
57668 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
57669 sqlite3DbFree(db, pSub);
57671 vdbeFreeOpArray(db, p->aOp, p->nOp);
57672 sqlite3DbFree(db, p->aLabel);
57673 sqlite3DbFree(db, p->aColName);
57674 sqlite3DbFree(db, p->zSql);
57675 sqlite3DbFree(db, p->pFree);
57676 sqlite3DbFree(db, p);
57683 sqlite3 *db;
57686 db = p->db;
57690 assert( db->pVdbe==p );
57691 db->pVdbe = p->pNext;
57697 p->db = 0;
57698 sqlite3VdbeDeleteObject(db, p);
57814 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
58090 p = sqlite3DbMallocRaw(pKeyInfo->db, nByte);
58109 pMem->db = pKeyInfo->db;
58139 sqlite3DbFree(p->pKeyInfo->db, p);
58185 mem1.db = pKeyInfo->db;
58278 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
58286 UNUSED_PARAMETER(db);
58390 ** sqlite3_changes() on the database handle 'db'.
58392 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
58393 assert( sqlite3_mutex_held(db->mutex) );
58394 db->nChange = nChange;
58395 db->nTotalChange += nChange;
58416 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
58418 for(p = db->pVdbe; p; p=p->pNext){
58427 return v->db;
58443 sqlite3_value *pRet = sqlite3ValueNew(v->db);
58508 if( p->db==0 ){
58541 sqlite3 *db = v->db;
58547 mutex = v->db->mutex;
58551 rc = sqlite3ApiExit(db, rc);
58571 sqlite3_mutex_enter(v->db->mutex);
58574 assert( (rc & (v->db->errMask))==rc );
58575 rc = sqlite3ApiExit(v->db, rc);
58576 sqlite3_mutex_leave(v->db->mutex);
58589 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
58678 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58682 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58686 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58692 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58698 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58702 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58706 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58715 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58725 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58734 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58743 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58748 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58752 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58765 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58773 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58776 pCtx->s.db->mallocFailed = 1;
58783 static int doWalCallbacks(sqlite3 *db){
58787 for(i=0; i<db->nDb; i++){
58788 Btree *pBt = db->aDb[i].pBt;
58791 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
58792 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
58810 sqlite3 *db;
58824 db = p->db;
58825 if( db->mallocFailed ){
58840 if( db->activeVdbeCnt==0 ){
58841 db->u1.isInterrupted = 0;
58844 assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 );
58847 if( db->xProfile && !db->init.busy ){
58848 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
58852 db->activeVdbeCnt++;
58853 if( p->readOnly==0 ) db->writeVdbeCnt++;
58868 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
58870 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
58871 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
58877 p->rc = doWalCallbacks(db);
58883 db->errCode = rc;
58884 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
58904 rc = db->errCode = p->rc;
58906 return (rc&db->errMask);
58919 sqlite3 *db; /* The database connection */
58924 db = v->db;
58925 sqlite3_mutex_enter(db->mutex);
58932 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
58941 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
58942 sqlite3DbFree(db, v->zErrMsg);
58943 if( !db->mallocFailed ){
58944 v->zErrMsg = sqlite3DbStrDup(db, zErr);
58951 rc = sqlite3ApiExit(db, rc);
58952 sqlite3_mutex_leave(db->mutex);
58977 return p->s.db;
59010 assert( sqlite3_mutex_held(p->s.db->mutex) );
59037 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
59060 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
59065 pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
59137 sqlite3_mutex_enter(pVm->db->mutex);
59158 if( pVm && ALWAYS(pVm->db) ){
59159 sqlite3_mutex_enter(pVm->db->mutex);
59160 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
59194 p->rc = sqlite3ApiExit(p->db, p->rc);
59195 sqlite3_mutex_leave(p->db->mutex);
59297 sqlite3 *db = p->db;
59299 assert( db!=0 );
59303 sqlite3_mutex_enter(db->mutex);
59304 assert( db->mallocFailed==0 );
59309 if( db->mallocFailed ){
59310 db->mallocFailed = 0;
59313 sqlite3_mutex_leave(db->mutex);
59422 ** The error code stored in database p->db is overwritten with the return
59430 sqlite3_mutex_enter(p->db->mutex);
59432 sqlite3Error(p->db, SQLITE_MISUSE, 0);
59433 sqlite3_mutex_leave(p->db->mutex);
59439 sqlite3Error(p->db, SQLITE_RANGE, 0);
59440 sqlite3_mutex_leave(p->db->mutex);
59447 sqlite3Error(p->db, SQLITE_OK, 0);
59487 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
59489 sqlite3Error(p->db, rc, 0);
59490 rc = sqlite3ApiExit(p->db, rc);
59492 sqlite3_mutex_leave(p->db->mutex);
59518 sqlite3_mutex_leave(p->db->mutex);
59531 sqlite3_mutex_leave(p->db->mutex);
59540 sqlite3_mutex_leave(p->db->mutex);
59601 sqlite3_mutex_leave(p->db->mutex);
59624 sqlite3_mutex_enter(p->db->mutex);
59637 sqlite3_mutex_leave(p->db->mutex);
59688 assert( pTo->db==pFrom->db );
59690 sqlite3_mutex_enter(pTo->db->mutex);
59694 sqlite3_mutex_leave(pTo->db->mutex);
59734 return pStmt ? ((Vdbe*)pStmt)->db : 0;
59838 sqlite3 *db; /* The database connection */
59848 db = p->db;
59850 db->aLimit[SQLITE_LIMIT_LENGTH]);
59851 out.db = db;
59886 u8 enc = ENC(db);
59890 utf8.db = db;
60482 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
60494 ** assert( checkSavepointCount(db) );
60496 static int checkSavepointCount(sqlite3 *db){
60499 for(p=db->pSavepoint; p; p=p->pNext) n++;
60500 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
60511 sqlite3 *db = p->db;
60512 sqlite3DbFree(db, p->zErrMsg);
60513 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
60557 sqlite3 *db = p->db; /* The database */
60559 u8 encoding = ENC(db); /* The database encoding */
60717 Db *pDb;
60731 Db *pDb;
60860 Db *pDb;
60987 db->busyHandler.nBusy = 0;
60991 checkProgress = db->xProgress!=0;
60995 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
61007 if( db->mallocFailed ) goto no_mem;
61034 sqlite3_interrupt(db);
61047 if( db->nProgressOps==nProgressOps ){
61049 prc = db->xProgress(db->pProgressArg);
61239 sqlite3VdbeSetChanges(db, p->nChange);
61259 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
61272 assert( rc==SQLITE_OK || db->nDeferredCons>0 );
61333 sqlite3DbFree(db, pOp->p4.z);
61340 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
61506 assert( db->flags&SQLITE_CountRows );
61526 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
61549 if( db->mallocFailed ) goto no_mem;
61587 if( u.ae.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
61801 u.ag.ctx.s.db = db;
61820 if( db->mallocFailed ){
61841 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ag.ctx.s));
61987 assert( pIn1->flags & MEM_Str || db->mallocFailed );
62007 assert( pIn1->flags & MEM_Str || db->mallocFailed );
62188 if( db->mallocFailed ) goto no_mem;
62578 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
62579 if( u.am.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
62664 u.am.sMem.db = 0;
62892 if( u.ao.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
62978 assert( db->pSavepoint==0 || db->autoCommit==0 );
62980 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
62981 assert( checkSavepointCount(db) );
62984 if( db->writeVdbeCnt>0 ){
62988 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
62995 u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
63002 if( db->autoCommit ){
63003 db->autoCommit = 0;
63004 db->isTransactionSavepoint = 1;
63006 db->nSavepoint++;
63010 u.aq.pNew->pNext = db->pSavepoint;
63011 db->pSavepoint = u.aq.pNew;
63012 u.aq.pNew->nDeferredCons = db->nDeferredCons;
63021 u.aq.pSavepoint = db->pSavepoint;
63028 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.aq.zName);
63031 db->writeVdbeCnt>0 || (u.aq.p1==SAVEPOINT_ROLLBACK && db->activeVdbeCnt>1)
63037 sqlite3SetString(&p->zErrMsg, db,
63048 int isTransaction = u.aq.pSavepoint->pNext==0 && db->isTransactionSavepoint;
63053 db->autoCommit = 1;
63056 db->autoCommit = 0;
63060 db->isTransactionSavepoint = 0;
63063 u.aq.iSavepoint = db
63064 for(u.aq.ii=0; u.aq.ii<db->nDb; u.aq.ii++){
63065 rc = sqlite3BtreeSavepoint(db->aDb[u.aq.ii].pBt, u.aq.p1, u.aq.iSavepoint);
63070 if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
63071 sqlite3ExpirePreparedStatements(db);
63072 sqlite3ResetInternalSchema(db, 0);
63073 db->flags = (db->flags | SQLITE_InternChanges);
63079 while( db->pSavepoint!=u.aq.pSavepoint ){
63080 u.aq.pTmp = db->pSavepoint;
63081 db->pSavepoint = u.aq.pTmp->pNext;
63082 sqlite3DbFree(db, u.aq.pTmp);
63083 db->nSavepoint--;
63091 assert( u.aq.pSavepoint==db->pSavepoint );
63092 db->pSavepoint = u.aq.pSavepoint->pNext;
63093 sqlite3DbFree(db, u.aq.pSavepoint);
63095 db->nSavepoint--;
63098 db->nDeferredCons = u.aq.pSavepoint->nDeferredCons;
63124 u.ar.turnOnAC = u.ar.desiredAutoCommit && !db->autoCommit;
63127 assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
63129 if( u.ar.turnOnAC && u.ar.iRollback && db->activeVdbeCnt>1 ){
63134 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
63137 }else if( u.ar.turnOnAC && !u.ar.iRollback && db->writeVdbeCnt>0 ){
63141 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
63144 }else if( u.ar.desiredAutoCommit!=db->autoCommit ){
63147 sqlite3RollbackAll(db);
63148 db->autoCommit = 1;
63152 db->autoCommit = (u8)u.ar.desiredAutoCommit;
63155 db->autoCommit = (u8)(1-u.ar.desiredAutoCommit);
63160 assert( db->nStatement==0 );
63161 sqlite3CloseSavepoints(db);
63169 sqlite3SetString(&p->zErrMsg, db,
63215 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63217 u.as.pBt = db->aDb[pOp->p1].pBt;
63231 && (db->autoCommit==0 || db->activeVdbeCnt>1)
63235 assert( db->nStatement>=0 && db->nSavepoint>=0 );
63236 db->nStatement++;
63237 p->iStatement = db->nSavepoint + db->nStatement;
63244 p->nStmtDefCons = db->nDeferredCons;
63272 assert( u.at.iDb>=0 && u.at.iDb<db->nDb );
63273 assert( db->aDb[u.at.iDb].pBt!=0 );
63276 sqlite3BtreeGetMeta(db->aDb[u.at.iDb].pBt, u.at.iCookie, (u32 *)&u.at.iMeta);
63293 Db *pDb;
63296 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63298 u.au.pDb = &db->aDb[pOp->p1];
63307 db->flags |= SQLITE_InternChanges;
63315 sqlite3ExpirePreparedStatements(db);
63342 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63344 u.av.pBt = db->aDb[pOp->p1].pBt;
63351 sqlite3DbFree(db, p->zErrMsg);
63352 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
63366 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
63367 sqlite3ResetInternalSchema(db, pOp->p1);
63370 sqlite3ExpirePreparedStatements(db);
63435 Db *pDb;
63447 assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
63449 u.aw.pDb = &db->aDb[u.aw.iDb];
63479 u.aw.pKeyInfo->enc = ENC(p->db);
63552 rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt,
63572 u.ax.pCx->pKeyInfo->enc = ENC(p->db);
64227 u.be.v = db->lastRowid;
64339 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = u.bf.iKey;
64362 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
64363 u.bf.zDb = db->aDb[u.bf.pC->iDb].zName;
64367 db->xUpdateCallback(db->pUpdateArg, u.bf.op, u.bf.zDb, u.bf.zTbl, u.bf.iKey);
64408 if( db->xUpdateCallback && pOp->p4.z ){
64430 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
64431 const char *zDb = db->aDb[u.bg.pC->iDb].zName;
64433 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bg.iKey);
64447 sqlite3VdbeSetChanges(db, p->nChange);
64509 if( u.bh.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
64516 if( u.bh.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
64864 rc = sqlite3VdbeIdxRowid(db, u.bp.pCrsr, &u.bp.rowid);
64971 for(u.br.pVdbe=db->pVdbe; u.br.pVdbe; u.br.pVdbe = u.br.pVdbe->pNext){
64977 u.br.iCnt = db->activeVdbeCnt;
64987 rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved);
64992 sqlite3RootPageMoved(&db->aDb[u.br.iDb], u.br.iMoved, pOp->p1);
65026 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0)
65066 Db *pDb;
65070 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65072 u.bt.pDb = &db->aDb[pOp->p1];
65106 assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb );
65125 ** will not be reloaded becuase the db->init.busy flag is set. This
65129 assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) );
65130 sqlite3BtreeEnterAll(db);
65131 if( pOp->p2 || DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded) ){
65133 u.bu.initData.db = db;
65136 u.bu.zSql = sqlite3MPrintf(db,
65138 db->aDb[u.bu.iDb].zName, u.bu.zMaster, pOp->p4.z);
65142 assert( db->init.busy==0 );
65143 db->init.busy = 1;
65145 assert( !db->mallocFailed );
65146 rc = sqlite3_exec(db, u.bu.zSql, sqlite3InitCallback, &u.bu.initData, 0);
65148 sqlite3DbFree(db, u.bu.zSql);
65149 db->init.busy = 0;
65152 sqlite3BtreeLeaveAll(db);
65167 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65168 rc = sqlite3AnalysisLoad(db, pOp->p1);
65181 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
65193 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
65205 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
65243 u.bv.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.bv.nRoot+1) );
65254 assert( pOp->p5<db->nDb );
65256 u.bv.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bv.aRoot, u.bv.nRoot,
65258 sqlite3DbFree(db, u.bv.aRoot);
65427 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
65429 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
65447 u.by.pFrame = sqlite3DbMallocZero(db, u.by.nByte);
65470 u.by.pMem->db = db;
65481 u.by.pFrame->lastRowid = db->lastRowid;
65531 db->nDeferredCons += pOp->p2;
65551 if( db->nDeferredCons==0 ) pc = pOp->p2-1;
65681 u.cb.ctx.s.db = db;
65692 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
65720 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem));
65737 rc = sqlite3Checkpoint(db, pOp->p1);
65772 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65793 u.cd.pBt = db->aDb[pOp->p1].pBt;
65815 if( !db->autoCommit || db->activeVdbeCnt>1 ){
65817 sqlite3SetString(&p->zErrMsg, db,
65874 rc = sqlite3RunVacuum(&p->zErrMsg, db);
65891 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65893 u.ce.pBt = db->aDb[pOp->p1].pBt;
65914 sqlite3ExpirePreparedStatements(db);
65938 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
65940 assert( p1>=0 && p1<db->nDb );
65943 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
65946 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
65968 rc = sqlite3VtabBegin(db, u.cf.pVTab);
65981 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
65994 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
66032 db->mallocFailed = 1;
66302 db->lastRowid = u.cl.rowid;
66316 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
66335 pBt = db->aDb[pOp->p1].pBt;
66360 if( db->xTrace ){
66362 db->xTrace(db->pTraceArg, z);
66363 sqlite3DbFree(db, z);
66366 if( (db->flags & SQLITE_SqlTrace)!=0 ){
66444 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
66446 if( resetSchemaOnFault ) sqlite3ResetInternalSchema(db, 0);
66459 sqlite3SetString(&p->zErrMsg, db, "string or blob too big");
66466 db->mallocFailed = 1;
66467 sqlite3SetString(&p->zErrMsg, db, "out of memory");
66476 if( db->mallocFailed ) rc = SQLITE_NOMEM;
66478 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
66486 assert( db->u1.isInterrupted );
66489 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
66524 sqlite3 *db; /* The associated database */
66561 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
66583 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
66586 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
66601 sqlite3* db, /* The database connection */
66613 ** db/table/row entry. The reason for using a vdbe program instead
66654 sqlite3_mutex_enter(db->mutex);
66656 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
66658 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
66663 pParse->db = db;
66664 sqlite3DbFree(db, zErr);
66667 sqlite3BtreeEnterAll(db);
66681 sqlite3DbFree(db, zErr);
66686 sqlite3BtreeLeaveAll(db);
66697 sqlite3DbFree(db, zErr);
66698 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
66700 sqlite3BtreeLeaveAll(db);
66712 if( db->flags&SQLITE_ForeignKeys ){
66737 sqlite3DbFree(db, zErr);
66738 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
66740 sqlite3BtreeLeaveAll(db);
66745 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
66746 assert( pBlob->pStmt || db->mallocFailed );
66749 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
66790 if( !db->mallocFailed ){
66797 pBlob->db = db;
66798 sqlite3BtreeLeaveAll(db);
66799 if( db->mallocFailed ){
66807 if( rc==SQLITE_OK && db->mallocFailed==0 ){
66811 sqlite3DbFree(db, pBlob);
66813 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
66814 sqlite3DbFree(db, zErr);
66815 sqlite3StackFree(db, pParse);
66816 rc = sqlite3ApiExit(db, rc);
66817 sqlite3_mutex_leave(db->mutex);
66828 sqlite3 *db;
66831 db = p->db;
66832 sqlite3_mutex_enter(db->mutex);
66834 sqlite3DbFree(db, p);
66835 sqlite3_mutex_leave(db->mutex);
66855 sqlite3 *db;
66858 db = p->db;
66859 sqlite3_mutex_enter(db->mutex);
66865 sqlite3Error(db, SQLITE_ERROR, 0);
66875 assert( db == v->db );
66883 db->errCode = rc;
66887 rc = sqlite3ApiExit(db, rc);
66888 sqlite3_mutex_leave(db->mutex);
66930 sqlite3 *db;
66933 db = p->db;
66934 sqlite3_mutex_enter(db->mutex);
66945 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
66946 sqlite3DbFree(db, zErr);
66951 rc = sqlite3ApiExit(db, rc);
66953 sqlite3_mutex_leave(db->mutex);
67651 sqlite3 *db; /* The database connection */
67657 db = pParse->db;
67659 pDup = sqlite3ExprDup(db, pOrig, 0);
67667 pDup = sqlite3ExprDup(db, pOrig, 0);
67673 pDup = sqlite3ExprDup(db, pOrig, 0);
67678 pDup->u.zToken = sqlite3DbStrDup(db, zToken);
67690 sqlite3ExprDelete(db, pExpr);
67692 sqlite3DbFree(db, pDup);
67701 ** pExpr->iDb Set the index in db->aDb[] of the database X
67733 sqlite3 *db = pParse->db; /* The database connection */
67762 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
67773 if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
67976 sqlite3ExprDelete(db, pExpr->pLeft);
67978 sqlite3ExprDelete(db, pExpr->pRight);
68003 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
68004 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
68117 u8 enc = ENC(pParse->db); /* The database encoding */
68123 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
68125 pDef = sqlite3FindFunction(pParse->db, zId, nId, -1, enc, 0);
68202 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
68264 sqlite3 *db; /* Database connection */
68266 u8 savedSuppErr; /* Saved value of db->suppressErr */
68279 db = pParse->db;
68280 savedSuppErr = db->suppressErr;
68281 db->suppressErr = 1;
68283 db->suppressErr = savedSuppErr;
68336 sqlite3 *db;
68341 db = pParse->db;
68343 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
68374 pDup = sqlite3ExprDup(db, pE, 0);
68375 if( !db->mallocFailed ){
68379 sqlite3ExprDelete(db, pDup);
68385 sqlite3ExprDelete(db, pE);
68386 pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0);
68426 sqlite3 *db = pParse->db;
68430 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
68432 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
68529 sqlite3 *db; /* Database connection */
68538 db = pParse->db;
68550 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
68597 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
68648 if( db->mallocFailed ){
68658 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
68880 sqlite3 *db = pParse->db;
68881 zColl = sqlite3NameFromToken(db, pCollName);
68884 sqlite3DbFree(db, zColl);
68908 sqlite3 *db = pParse->db;
68910 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
69069 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
69179 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
69194 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
69226 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
69233 return sqlite3ExprAlloc(db, op, &x, 0);
69243 sqlite3 *db,
69249 assert( db->mallocFailed );
69250 sqlite3ExprDelete(db, pLeft);
69251 sqlite3ExprDelete(db, pRight);
69275 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
69285 Expr *p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
69286 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
69297 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
69303 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
69304 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
69315 sqlite3 *db = pParse->db;
69317 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
69319 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
69345 sqlite3 *db = pParse->db;
69365 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
69366 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
69367 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
69369 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
69396 db,
69401 if( !db->mallocFailed ){
69407 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
69415 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
69418 sqlite3ExprDelete(db, p->pLeft);
69419 sqlite3ExprDelete(db, p->pRight);
69421 sqlite3DbFree(db, p->u.zToken);
69424 sqlite3SelectDelete(db, p->x.pSelect);
69426 sqlite3ExprListDelete(db, p->x.pList);
69430 sqlite3DbFree(db, p);
69543 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
69557 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
69598 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
69600 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
69608 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
69609 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
69617 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
69618 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
69644 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
69645 return exprDup(db, p, flags, 0);
69647 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
69652 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
69656 pNew->a = pItem = sqlite3DbMallocRaw(db, p->nExpr*sizeof(p->a[0]) );
69658 sqlite3DbFree(db, pNew);
69664 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
69665 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
69666 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
69683 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
69689 pNew = sqlite3DbMallocRaw(db, nByte );
69696 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
69697 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
69698 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
69702 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
69709 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
69710 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
69711 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
69716 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
69720 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
69723 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
69725 sqlite3DbFree(db, pNew);
69731 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
69736 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
69739 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
69741 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
69742 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
69743 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
69744 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
69745 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
69746 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
69748 pNew->pPrior = sqlite3SelectDup(db, p->pPrior, flags);
69749 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
69750 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
69761 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
69781 sqlite3 *db = pParse->db;
69783 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
69792 a = sqlite3DbRealloc(db, pList->a, n*sizeof(pList->a[0]));
69797 pList->nAlloc = sqlite3DbMallocSize(db, a)/sizeof(a[0]);
69809 sqlite3ExprDelete(db, pExpr);
69810 sqlite3ExprListDelete(db, pList);
69819 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
69828 assert( pList!=0 || pParse->db->mallocFailed!=0 );
69834 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
69844 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
69852 sqlite3 *db = pParse->db;
69853 assert( pList!=0 || db->mallocFailed!=0 );
69857 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
69858 sqlite3DbFree(db, pItem->zSpan);
69859 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
69873 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
69884 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
69891 sqlite3ExprDelete(db, pItem->pExpr);
69892 sqlite3DbFree(db, pItem->zName);
69893 sqlite3DbFree(db, pItem->zSpan);
69895 sqlite3DbFree(db, pList->a);
69896 sqlite3DbFree(db, pList);
70245 sqlite3 *db = pParse->db; /* Database connection */
70253 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
70290 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
70400 assert( testAddr>0 || pParse->db->mallocFailed );
70406 pParse->db, "EXECUTE %s%s SUBQUERY %d", testAddr?"":"CORRELATED ",
70556 sqlite3ExprDelete(pParse->db, pSel->pLimit);
70809 if( pParse->db->flags & SQLITE_ColumnCache ) return;
71069 sqlite3 *db = pParse->db; /* The database connection */
71073 assert( pParse->db->mallocFailed );
71336 u8 enc = ENC(db); /* The text encoding used by this database */
71351 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
71399 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
71401 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
71413 if( !pColl ) pColl = db->pDfltColl;
71622 assert( db->mallocFailed || pParse->nErr>0
71693 assert( pParse->pVdbe || pParse->db->mallocFailed );
71858 if( (pParse->db->flags & SQLITE_FactorOutConst)!=0 ) return;
72293 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
72296 db,
72311 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
72314 db,
72365 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
72423 u8 enc = ENC(pParse->db);
72424 i = addAggInfoFunc(pParse->db, pAggInfo);
72431 pItem->pFunc = sqlite3FindFunction(pParse->db,
72606 sqlite3 *db = sqlite3_context_db_handle(context);
72635 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
72662 sqlite3 *db = sqlite3_context_db_handle(context);
72683 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
72687 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
72690 sqlite3DbFree(db, zOutput);
72694 sqlite3DbFree(db, zParent);
72698 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
72700 sqlite3DbFree(db, zOutput);
72726 sqlite3 *db = sqlite3_context_db_handle(context);
72774 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
72819 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
72822 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
72824 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
72825 sqlite3DbFree(db, zWhere);
72841 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
72856 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
72858 /* If the table is not located in the temp-db (in which case NULL is
72860 ** that is not part of the temp-db schema, add a clause to the WHERE
72864 sqlite3 *db = pParse->db;
72867 zWhere = whereOrName(db, zWhere, pTrig->zName);
72872 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
72873 sqlite3DbFree(pParse->db, zWhere);
72897 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
72898 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
72904 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
72914 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
72941 sqlite3 *db = pParse->db; /* Database connection */
72949 int savedDbFlags; /* Saved value of db->flags */
72951 savedDbFlags = db->flags;
72952 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
72954 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
72958 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
72959 zDb = db->aDb[iDb].zName;
72960 db->flags |= SQLITE_PreferBuiltin;
72963 zName = sqlite3NameFromToken(db, pName);
72969 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
73007 pVTab = sqlite3GetVTable(db, pTab);
73045 if( db->flags&SQLITE_ForeignKeys ){
73054 sqlite3DbFree(db, zWhere);
73088 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
73106 sqlite3DbFree(db, zWhere);
73111 if( db->flags&SQLITE_ForeignKeys ){
73126 sqlite3SrcListDelete(db, pSrc);
73127 sqlite3DbFree(db, zName);
73128 db->flags = savedDbFlags;
73174 sqlite3 *db; /* The database connection; */
73176 db = pParse->db;
73177 if( pParse->nErr || db->mallocFailed ) return;
73181 assert( sqlite3BtreeHoldsAllMutexes(db) );
73182 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
73183 zDb = db->aDb[iDb].zName;
73187 pTab = sqlite3FindTable(db, zTab, zDb);
73217 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
73233 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
73234 db->mallocFailed = 1;
73245 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
73248 int savedDbFlags = db->flags;
73252 db->flags |= SQLITE_PreferBuiltin;
73260 sqlite3DbFree(db, zCol);
73261 db->flags = savedDbFlags;
73296 sqlite3 *db = pParse->db;
73300 assert( sqlite3BtreeHoldsAllMutexes(db) );
73301 if( db->mallocFailed ) goto exit_begin_add_column;
73319 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73328 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
73336 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
73337 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
73339 db->mallocFailed = 1;
73345 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
73351 pNew->pSchema = db->aDb[iDb].pSchema;
73362 sqlite3SrcListDelete(db, pSrc);
73420 sqlite3 *db = pParse->db;
73421 Db *pDb;
73424 assert( sqlite3BtreeHoldsAllMutexes(db) );
73425 assert( sqlite3VdbeDb(v)==db );
73426 pDb = &db->aDb[iDb];
73431 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
73476 sqlite3 *db = pParse->db; /* Database handle */
73514 assert( sqlite3BtreeHoldsAllMutexes(db) );
73515 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73519 db->aDb[iDb].zName ) ){
73538 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
73641 if( db->mallocFailed ){
73736 sqlite3 *db = pParse->db;
73737 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
73763 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
73764 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
73786 sqlite3 *db = pParse->db;
73795 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
73803 for(i=0; i<db->nDb; i++){
73809 iDb = sqlite3FindDb(db, pName1);
73813 z = sqlite3NameFromToken(db, pName1);
73816 sqlite3DbFree(db, z);
73826 zDb = db->aDb[iDb].zName;
73827 z = sqlite3NameFromToken(db, pTableName);
73830 sqlite3DbFree(db, z);
73845 sqlite3 *db;
73874 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
73879 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
73903 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
73910 sqlite3DbFree(db, p->u.z);
73913 sqlite3DbFree(db, pIdx->aSample);
73916 UNUSED_PARAMETER(db);
73937 ** If an OOM error occurs, this function always sets db->mallocFailed.
73941 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
73947 assert( iDb>=0 && iDb<db->nDb );
73948 assert( db->aDb[iDb].pBt!=0 );
73949 assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
73952 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
73955 sqlite3DeleteIndexSamples(db, pIdx);
73960 sInfo.db = db;
73961 sInfo.zDatabase = db->aDb[iDb].zName;
73962 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
73967 zSql = sqlite3MPrintf(db,
73972 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
73973 sqlite3DbFree(db, zSql);
73979 if( rc==SQLITE_OK && !sqlite3FindTable(db, "sqlite_stat2", sInfo.zDatabase) ){
73985 zSql = sqlite3MPrintf(db,
73990 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
73991 sqlite3DbFree(db, zSql);
73997 Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
74007 db->mallocFailed = 1;
74035 db->mallocFailed = 1;
74050 db->mallocFailed = 1;
74128 sqlite3 *db = sqlite3_context_db_handle(context);
74131 Db *aNew;
74147 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
74148 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
74149 db->aLimit[SQLITE_LIMIT_ATTACHED]
74153 if( !db->autoCommit ){
74154 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
74157 for(i=0; i<db->nDb; i++){
74158 char *z = db->aDb[i].zName;
74161 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
74166 /* Allocate the new entry in the db->aDb[] array and initialise the schema
74169 if( db->aDb==db->aDbStatic ){
74170 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
74172 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
74174 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
74177 db->aDb = aNew;
74178 aNew = &db->aDb[db->nDb];
74185 rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
74186 db
74187 db->nDb++;
74190 zErrDyn = sqlite3MPrintf(db, "database is already attached");
74193 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
74196 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
74197 zErrDyn = sqlite3MPrintf(db,
74202 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
74204 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
74207 aNew->zName = sqlite3DbStrDup(db, zName);
74223 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
74231 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
74236 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
74237 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
74245 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
74249 sqlite3BtreeEnterAll(db);
74250 rc = sqlite3Init(db, &zErrDyn);
74251 sqlite3BtreeLeaveAll(db);
74254 int iDb = db->nDb - 1;
74256 if( db->aDb[iDb].pBt ){
74257 sqlite3BtreeClose(db->aDb[iDb].pBt);
74258 db->aDb[iDb].pBt = 0;
74259 db->aDb[iDb].pSchema = 0;
74261 sqlite3ResetInternalSchema(db, 0);
74262 db->nDb = iDb;
74264 db->mallocFailed = 1;
74265 sqlite3DbFree(db, zErrDyn);
74266 zErrDyn = sqlite3MPrintf(db, "out of memory");
74268 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
74279 sqlite3DbFree(db, zErrDyn);
74298 sqlite3 *db = sqlite3_context_db_handle(context);
74300 Db *pDb = 0;
74306 for(i=0; i<db->nDb; i++){
74307 pDb = &db->aDb[i];
74312 if( i>=db->nDb ){
74320 if( !db->autoCommit ){
74333 sqlite3ResetInternalSchema(db, 0);
74356 sqlite3* db = pParse->db;
74391 assert( v || db->mallocFailed );
74406 sqlite3ExprDelete(db, pFilename);
74407 sqlite3ExprDelete(db, pDbname);
74408 sqlite3ExprDelete(db, pKey);
74470 sqlite3 *db;
74473 db = pParse->db;
74474 assert( db->nDb>iDb );
74476 pFix->zDb = db->aDb[iDb].zName;
74508 pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb);
74670 sqlite3 *db,
74674 sqlite3_mutex_enter(db->mutex);
74675 db->xAuth = xAuth;
74676 db->pAuthArg = pArg;
74677 sqlite3ExpirePreparedStatements(db);
74678 sqlite3_mutex_leave(db->mutex);
74706 sqlite3 *db = pParse->db; /* Database handle */
74707 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
74710 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
74712 if( db->nDb>2 || iDb!=0 ){
74739 sqlite3 *db = pParse->db;
74746 if( db->xAuth==0 ) return;
74747 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
74778 assert( iDb>=0 && iDb<db->nDb );
74797 sqlite3 *db = pParse->db;
74803 if( db->init.busy || IN_DECLARE_VTAB ){
74807 if( db->xAuth==0 ){
74810 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
74931 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
74940 pToplevel->db->mallocFailed = 1;
74977 sqlite3 *db;
74980 db = pParse->db;
74981 if( db->mallocFailed ) return;
75004 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
75008 if( db->init.busy==0 ){
75016 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
75041 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
75043 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
75082 sqlite3 *db = pParse->db;
75089 zSql = sqlite3VMPrintf(db, zFormat, ap);
75098 sqlite3DbFree(db, zErrMsg);
75099 sqlite3DbFree(db, zSql);
75116 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
75122 for(i=OMIT_TEMPDB; i<db->nDb; i++){
75124 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
75125 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
75155 p = sqlite3FindTable(pParse->db, zName, zDbase);
75180 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
75184 for(i=OMIT_TEMPDB; i<db->nDb; i++){
75186 Schema *pSchema = db->aDb[j].pSchema;
75188 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
75198 static void freeIndex(sqlite3 *db, Index *p){
75200 sqlite3DeleteIndexSamples(db, p);
75202 sqlite3DbFree(db, p->zColAff);
75203 sqlite3DbFree(db, p);
75212 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
75215 Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
75232 freeIndex(db, pIndex);
75234 db->flags |= SQLITE_InternChanges;
75248 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
75250 assert( iDb>=0 && iDb<db->nDb );
75253 sqlite3BtreeEnterAll(db);
75255 for(i=iDb; i<db->nDb; i++){
75256 Db *pDb = &db->aDb[i];
75264 db->flags &= ~SQLITE_InternChanges;
75265 sqlite3VtabUnlockList(db);
75266 sqlite3BtreeLeaveAll(db);
75274 for(i=j=2; i<db->nDb; i++){
75275 struct Db *pDb = &db->aDb[i];
75277 sqlite3DbFree(db, pDb->zName);
75282 db->aDb[j] = db->aDb[i];
75286 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
75287 db->nDb = j;
75288 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
75289 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
75290 sqlite3DbFree(db, db->aDb);
75291 db->aDb = db->aDbStatic;
75298 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
75299 db->flags &= ~SQLITE_InternChanges;
75306 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
75312 sqlite3DbFree(db, pCol->zName);
75313 sqlite3ExprDelete(db, pCol->pDflt);
75314 sqlite3DbFree(db, pCol->zDflt);
75315 sqlite3DbFree(db, pCol->zType);
75316 sqlite3DbFree(db, pCol->zColl);
75318 sqlite3DbFree(db, pTable->aCol);
75331 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
75338 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
75344 if( !db || db->pnBytesFreed==0 ){
75351 freeIndex(db, pIndex);
75355 sqlite3FkDelete(db, pTable);
75359 sqliteDeleteColumnNames(db, pTable);
75360 sqlite3DbFree(db, pTable->zName);
75361 sqlite3DbFree(db, pTable->zColAff);
75362 sqlite3SelectDelete(db, pTable->pSelect);
75364 sqlite3ExprDelete(db, pTable->pCheck);
75367 sqlite3VtabClear(db, pTable);
75369 sqlite3DbFree(db, pTable);
75376 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
75378 Db *pDb;
75380 assert( db!=0 );
75381 assert( iDb>=0 && iDb<db->nDb );
75384 pDb = &db->aDb[iDb];
75387 sqlite3DeleteTable(db, p);
75388 db->flags |= SQLITE_InternChanges;
75404 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
75407 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
75431 ** of a database ("main", "temp" or the name of an attached db). This
75432 ** function returns the index of the named database in db->aDb[], or
75433 ** -1 if the named db cannot be found.
75435 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
75438 Db *pDb;
75440 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
75452 ** "temp" or the name of an attached db). This routine returns the
75453 ** index of the named database in db->aDb[], or -1 if the named db
75456 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
75459 zName = sqlite3NameFromToken(db, pName);
75460 i = sqlite3FindDbName(db, zName);
75461 sqlite3DbFree(db, zName);
75488 sqlite3 *db = pParse->db;
75491 if( db->init.busy ) {
75497 iDb = sqlite3FindDb(db, pName1);
75504 assert( db->init.iDb==0 || db->init.busy );
75505 iDb = db->init.iDb;
75519 if( !pParse->db->init.busy && pParse->nested==0
75520 && (pParse->db->flags & SQLITE_WriteSchema)==0
75555 sqlite3 *db = pParse->db;
75588 zName = sqlite3NameFromToken(db, pName);
75593 if( db->init.iDb==1 ) isTemp = 1;
75598 char *zDb = db->aDb[iDb].zName;
75629 char *zDb = db->aDb[iDb].zName;
75633 pTable = sqlite3FindTable(db, zName, zDb);
75640 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
75646 pTable = sqlite3DbMallocZero(db, sizeof(Table));
75648 db->mallocFailed = 1;
75655 pTable->pSchema = db->aDb[iDb].pSchema;
75679 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
75700 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
75704 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
75738 sqlite3DbFree(db, zName);
75768 sqlite3 *db = pParse->db;
75771 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
75776 z = sqlite3NameFromToken(db, pName);
75781 sqlite3DbFree(db, z);
75787 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
75789 sqlite3DbFree(db, z);
75897 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
75914 sqlite3 *db = pParse->db;
75926 sqlite3ExprDelete(db, pCol->pDflt);
75927 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
75928 sqlite3DbFree(db, pCol->zDflt);
75929 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
75933 sqlite3ExprDelete(db, pSpan->pExpr);
76011 sqlite3ExprListDelete(pParse->db, pList);
76022 sqlite3 *db = pParse->db;
76026 pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr);
76030 sqlite3ExprDelete(db, pCheckExpr);
76042 sqlite3 *db;
76046 db = pParse->db;
76047 zColl = sqlite3NameFromToken(db, pToken);
76065 sqlite3DbFree(db, zColl);
76090 sqlite3 *db = pParse->db;
76091 u8 enc = ENC(db);
76092 u8 initbusy = db->init.busy;
76095 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
76097 pColl = sqlite3GetCollSeq(db, enc, pColl, zName);
76125 sqlite3 *db = pParse->db;
76127 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
76189 static char *createTableStmt(sqlite3 *db, Table *p){
76211 db->mallocFailed = 1;
76262 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
76280 sqlite3 *db = pParse->db;
76283 if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
76289 assert( !db->init.busy || !pSelect );
76291 iDb = sqlite3SchemaToIndex(db, p->pSchema);
76315 /* If the db->init.busy is 1 it means we are reading the SQL off the
76318 ** for the table from the db->init.newTnum field. (The page number
76321 if( db->init.busy ){
76322 p->tnum = db->init.newTnum;
76331 if( !db->init.busy ){
76390 sqlite3DeleteTable(db, pSelTab);
76396 zStmt = createTableStmt(db, p);
76399 zStmt = sqlite3MPrintf(db,
76412 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
76420 sqlite3DbFree(db, zStmt);
76428 Db *pDb = &db->aDb[iDb];
76440 sqlite3MPrintf(db, "tbl_name='%q'",p->zName), P4_DYNAMIC);
76446 if( db->init.busy ){
76453 db->mallocFailed = 1;
76457 db->nTable++;
76458 db->flags |= SQLITE_InternChanges;
76495 sqlite3 *db = pParse->db;
76499 sqlite3SelectDelete(db, pSelect);
76505 sqlite3SelectDelete(db, pSelect);
76509 iDb = sqlite3SchemaToIndex(db, p->pSchema);
76513 sqlite3SelectDelete(db, pSelect);
76522 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
76523 sqlite3SelectDelete(db, pSelect);
76524 if( db->mallocFailed ){
76527 if( !db->init.busy ){
76562 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
76609 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
76611 u8 enableLookaside = db->lookaside.bEnabled;
76615 db->lookaside.bEnabled = 0;
76617 xAuth = db->xAuth;
76618 db->xAuth = 0;
76620 db->xAuth = xAuth;
76624 db->lookaside.bEnabled = enableLookaside;
76632 sqlite3DeleteTable(db, pSelTab);
76638 sqlite3SelectDelete(db, pSel);
76651 static void sqliteViewResetAll(sqlite3 *db, int idx){
76653 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
76654 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
76657 sqliteDeleteColumnNames(db, pTab);
76662 DbClearProperty(db, idx, DB_UnresetViews);
76686 SQLITE_PRIVATE void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){
76730 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
76744 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
76786 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
76801 sqlite3 *db = pParse->db;
76804 if( db->mallocFailed ){
76809 if( noErr ) db->suppressErr++;
76812 if( noErr ) db->suppressErr--;
76817 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
76818 assert( iDb>=0 && iDb<db->nDb );
76830 const char *zDb = db->aDb[iDb].zName;
76844 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
76886 Db *pDb = &db->aDb[iDb];
76903 pTrigger->pSchema==db->aDb[1].pSchema );
76934 if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
76953 sqliteViewResetAll(db, iDb);
76956 sqlite3SrcListDelete(db, pName);
76982 sqlite3 *db = pParse->db;
77018 pFKey = sqlite3DbMallocZero(db, nByte );
77067 db->mallocFailed = 1;
77082 sqlite3DbFree(db, pFKey);
77084 sqlite3ExprListDelete(db, pFromCol);
77085 sqlite3ExprListDelete(db, pToCol);
77126 sqlite3 *db = pParse->db; /* The database connection */
77127 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
77131 db->aDb[iDb].zName ) ){
77221 sqlite3 *db = pParse->db;
77222 Db *pDb; /* The specific table containing the indexed database */
77232 if( db->mallocFailed || IN_DECLARE_VTAB ){
77245 ** to search for the table. 'Fix' the table name to this db
77257 if( !db->init.busy ){
77259 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
77274 if( !pTab || db->mallocFailed ) goto exit_create_index;
77275 assert( db->aDb[iDb].pSchema==pTab->pSchema );
77280 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
77282 pDb = &db->aDb[iDb];
77318 zName = sqlite3NameFromToken(db, pName);
77323 if( !db->init.busy ){
77324 if( sqlite3FindTable(db, zName, 0)!=0 ){
77329 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
77339 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
77394 pIndex = sqlite3DbMallocZero(db,
77403 if( db->mallocFailed ){
77417 pIndex->pSchema = db->aDb[iDb].pSchema;
77470 zColl = db->pDfltColl->zName;
77473 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
77545 if( db->init.busy ){
77552 db->mallocFailed = 1;
77555 db->flags |= SQLITE_InternChanges;
77557 pIndex->tnum = db->init.newTnum;
77561 /* If the db->init.busy is 0 then create the index on disk. This
77565 ** The db->init.busy is 0 when the user first enters a CREATE INDEX
77566 ** command. db->init.busy is 1 when a database is opened and
77576 else{ /* if( db->init.busy==0 ) */
77596 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
77610 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
77616 sqlite3DbFree(db, zStmt);
77625 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName),
77637 if( db->init.busy || pTblName==0 ){
77657 sqlite3DbFree(db, pIndex->zColAff);
77658 sqlite3DbFree(db, pIndex);
77660 sqlite3ExprListDelete(db, pList);
77661 sqlite3SrcListDelete(db, pTblName);
77662 sqlite3DbFree(db, zName);
77708 sqlite3 *db = pParse->db;
77712 if( db->mallocFailed ){
77719 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
77732 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
77737 const char *zDb = db->aDb[iDb].zName;
77755 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
77758 if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
77761 db->aDb[iDb].zName, pIndex->zName
77770 sqlite3SrcListDelete(db, pName);
77789 sqlite3 *db, /* Connection to notify of malloc failures */
77802 pNew = sqlite3DbRealloc(db, pArray, newSize*szEntry);
77807 *pnAlloc = sqlite3DbMallocSize(db, pNew)/szEntry;
77823 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
77826 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
77831 db,
77840 sqlite3IdListDelete(db, pList);
77843 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
77850 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
77854 sqlite3DbFree(db, pList->a[i].zName);
77856 sqlite3DbFree(db, pList->a);
77857 sqlite3DbFree(db, pList);
77881 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
77890 ** db->mallocFailed flag will be set to true.
77893 sqlite3 *db, /* Database connection to notify of OOM errors */
77911 pNew = sqlite3DbRealloc(db, pSrc,
77914 assert( db->mallocFailed );
77918 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
77975 sqlite3 *db, /* Connection to notify of malloc failures */
77983 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
77987 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
77988 if( db->mallocFailed ){
77989 sqlite3SrcListDelete(db, pList);
78001 pItem->zName = sqlite3NameFromToken(db, pTable);
78002 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
78012 assert(pList || pParse->db->mallocFailed );
78027 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
78032 sqlite3DbFree(db, pItem->zDatabase);
78033 sqlite3DbFree(db, pItem->zName);
78034 sqlite3DbFree(db, pItem->zAlias);
78035 sqlite3DbFree(db, pItem->zIndex);
78036 sqlite3DeleteTable(db, pItem->pTab);
78037 sqlite3SelectDelete(db, pItem->pSelect);
78038 sqlite3ExprDelete(db, pItem->pOn);
78039 sqlite3IdListDelete(db, pItem->pUsing);
78041 sqlite3DbFree(db, pList);
78071 sqlite3 *db = pParse->db;
78078 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
78085 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
78094 sqlite3ExprDelete(db, pOn);
78095 sqlite3IdListDelete(db, pUsing);
78096 sqlite3SelectDelete(db, pSubquery);
78114 pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy);
78148 sqlite3 *db;
78153 db = pParse->db;
78154 assert( db!=0 );
78155 /* if( db->aDb[0].pBt==0 ) return; */
78162 for(i=0; i<db->nDb; i++){
78174 db;
78178 db = pParse->db;
78179 assert( db!=0 );
78180 /* if( db->aDb[0].pBt==0 ) return; */
78194 sqlite3 *db;
78198 db = pParse->db;
78199 assert( db!=0 );
78200 /* if( db->aDb[0].pBt==0 ) return; */
78215 char *zName = sqlite3NameFromToken(pParse->db, pName);
78223 sqlite3DbFree(pParse->db, zName);
78235 sqlite3 *db = pParse->db;
78236 if( db->aDb[1].pBt==0 && !pParse->explain ){
78246 rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
78253 db->aDb[1].pBt = pBt;
78254 assert( db->aDb[1].pSchema );
78255 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
78256 db->mallocFailed = 1;
78294 sqlite3 *db = pToplevel->db;
78297 assert( iDb<db->nDb );
78298 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
78303 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
78406 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78421 Db *pDb; /* A single database */
78423 sqlite3 *db = pParse->db; /* The database connection */
78427 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
78458 sqlite3 *db = pParse->db; /* The database connection */
78473 zColl = sqlite3NameFromToken(pParse->db, pName1);
78475 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
78478 sqlite3DbFree(db, zColl);
78481 sqlite3DbFree(db, zColl);
78485 z = sqlite3NameFromToken(db, pObjName);
78487 zDb = db->aDb[iDb].zName;
78488 pTab = sqlite3FindTable(db, z, zDb);
78491 sqlite3DbFree(db, z);
78494 pIndex = sqlite3FindIndex(db, z, zDb);
78495 sqlite3DbFree(db, z);
78510 ** the caller is responsible for calling sqlite3DbFree(db, ) on the returned
78519 sqlite3 *db = pParse->db;
78520 KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(db, nBytes);
78523 pKey->db = pParse->db;
78536 sqlite3DbFree(db, pKey);
78565 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
78566 assert( !db->xCollNeeded || !db->xCollNeeded16 );
78567 if( db->xCollNeeded ){
78568 char *zExternal = sqlite3DbStrDup(db, zName);
78570 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
78571 sqlite3DbFree(db, zExternal);
78574 if( db->xCollNeeded16 ){
78576 sqlite3_value *pTmp = sqlite3ValueNew(db);
78580 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
78594 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
78600 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
78619 ** db for collation type name zName, length nName, or NULL, if no collation
78625 sqlite3* db, /* The database connection */
78634 p = sqlite3FindCollSeq(db, enc, zName, 0);
78640 callCollNeeded(db, enc, zName);
78641 p = sqlite3FindCollSeq(db, enc, zName, 0);
78643 if( p && !p->xCmp && synthCollSeq(db, p) ){
78664 sqlite3 *db = pParse->db;
78665 CollSeq *p = sqlite3GetCollSeq(db, ENC(db), pColl, zName);
78679 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
78692 sqlite3 *db, /* Database connection */
78698 pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
78701 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
78712 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
78720 db->mallocFailed = 1;
78721 sqlite3DbFree(db, pDel);
78732 ** for the encoding 'enc' from the database 'db'.
78745 sqlite3 *db,
78752 pColl = findCollSeqEntry(db, zName, create);
78754 pColl = db->pDfltColl;
78854 ** structure is created and liked into the "db" structure if a
78868 sqlite3 *db, /* An open database */
78882 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
78886 p = functionSearch(&db->aFunc, h, zName, nName);
78908 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
78927 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
78933 sqlite3FuncDefInsert(&db->aFunc, pBest);
78944 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
78979 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
78987 db->mallocFailed = 1;
79025 sqlite3DeleteTable(pParse->db, pItem->pTab);
79053 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
79055 && (pParse->db->flags & SQLITE_WriteSchema)==0
79086 sqlite3 *db = pParse->db;
79088 pDup = sqlite3SelectDup(db, pView->pSelect, 0);
79092 pWhere = sqlite3ExprDup(db, pWhere, 0);
79093 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
79096 pFrom->a[0].zAlias = sqlite3DbStrDup(db, pView->zName);
79101 sqlite3SelectDelete(db, pDup);
79107 sqlite3SelectDelete(db, pDup);
79169 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
79171 sqlite3ExprListDelete(pParse->db, pEList);
79193 sqlite3SelectDelete(pParse->db, pSelect);
79197 sqlite3ExprDelete(pParse->db, pWhere);
79198 sqlite3ExprListDelete(pParse->db, pOrderBy);
79199 sqlite3ExprDelete(pParse->db, pLimit);
79200 sqlite3ExprDelete(pParse->db, pOffset);
79225 sqlite3 *db; /* Main database structure */
79238 db = pParse->db;
79239 if( pParse->nErr || db->mallocFailed ){
79276 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79277 assert( iDb<db->nDb );
79278 zDb = db->aDb[iDb].zName;
79330 if( db->flags & SQLITE_CountRows ){
79367 if( db->flags & SQLITE_CountRows ){
79390 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
79426 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
79434 sqlite3SrcListDelete(db, pTabList);
79435 sqlite3ExprDelete(db, pWhere);
79935 sqlite3 *db = sqlite3_context_db_handle(context);
79937 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
79938 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
79939 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
80082 sqlite3 *db = sqlite3_context_db_handle(context);
80087 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
80102 sqlite3 *db = sqlite3_context_db_handle(context);
80104 sqlite3_result_int(context, sqlite3_changes(db));
80116 sqlite3 *db = sqlite3_context_db_handle(context);
80120 sqlite3_result_int(context, sqlite3_total_changes(db));
80320 sqlite3 *db = sqlite3_context_db_handle(context);
80329 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
80330 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
80331 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
80571 sqlite3 *db = sqlite3_context_db_handle(context);
80575 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
80576 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
80577 if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
80641 sqlite3 *db = sqlite3_context_db_handle(context);
80643 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
80644 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
80645 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
80822 sqlite3 *db = sqlite3_context_db_handle(context);
80830 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
80972 ** returns (void *)db, where db is the sqlite3* database pointer.
81013 sqlite3 *db = sqlite3_context_db_handle(context);
81016 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
81052 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
81053 int rc = sqlite3_overload_function(db, "MATCH", 2);
81056 db->mallocFailed = 1;
81063 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
81065 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
81077 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
81084 sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
81085 sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
81086 sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
81088 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
81089 setLikeOptFlag(db, "like",
81100 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
81109 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
81408 ** pParse->db->mallocFailed flag is set.
81449 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
81509 sqlite3DbFree(pParse->db, aiCol);
81696 sqlite3 *db = pParse->db; /* Database handle */
81725 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
81745 pRight = sqlite3Expr(db, TK_ID, zCol);
81747 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
81758 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
81759 pRight = sqlite3Expr(db, TK_COLUMN, 0);
81767 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
81790 sqlite3ExprDelete(db, pWhere);
81852 sqlite3 *db = pParse->db;
81853 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
81874 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
81918 sqlite3 *db = pParse->db; /* Database handle */
81929 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
81932 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
81933 zDb = db->aDb[iDb].zName;
81951 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
81956 if( !isIgnoreErrors || db->mallocFailed ) return;
81975 if( db->xAuth ){
82002 sqlite3DbFree(db, aiFree);
82019 if( !isIgnoreErrors || db->mallocFailed ) return;
82027 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
82048 sqlite3SrcListDelete(db, pSrc);
82050 sqlite3DbFree(db, aiCol);
82065 if( pParse->db->flags&SQLITE_ForeignKeys ){
82102 if( pParse->db->flags&SQLITE_ForeignKeys ){
82177 sqlite3 *db = pParse->db; /* Database handle */
82186 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
82228 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
82246 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
82259 pNew = sqlite3ExprDup(db, pDflt, 0);
82270 sqlite3DbFree(db, aiCol);
82281 pRaise = sqlite3Expr(db, TK_RAISE, "foreign key constraint failed");
82287 sqlite3SrcListAppend(db, 0, &tFrom, 0),
82295 enableLookaside = db->lookaside.bEnabled;
82296 db->lookaside.bEnabled = 0;
82298 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
82309 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
82310 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
82311 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
82314 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
82319 db->lookaside.bEnabled = enableLookaside;
82321 sqlite3ExprDelete(db, pWhere);
82322 sqlite3ExprDelete(db, pWhen);
82323 sqlite3ExprListDelete(db, pList);
82324 sqlite3SelectDelete(db, pSelect);
82325 if( db->mallocFailed==1 ){
82326 fkTriggerDelete(db, pTrigger);
82366 if( pParse->db->flags&SQLITE_ForeignKeys ){
82384 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
82391 if( !db || db->pnBytesFreed==0 ){
82411 fkTriggerDelete(db, pFKey->apTrigger[0]);
82412 fkTriggerDelete(db, pFKey->apTrigger[1]);
82416 sqlite3DbFree(db, pFKey);
82490 sqlite3 *db = sqlite3VdbeDb(v);
82493 db->mallocFailed = 1;
82531 sqlite3 *db = sqlite3VdbeDb(v);
82535 db->mallocFailed = 1;
82562 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
82625 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
82646 sqlite3 *db = pParse->db; /* The database connection */
82647 Db *pDb; /* Database only autoinc table */
82659 pDb = &db->aDb[p->iDb];
82701 sqlite3 *db = pParse->db;
82705 Db *pDb = &db->aDb[p->iDb];
82860 sqlite3 *db; /* The main database structure */
82879 Db *pDb; /* The database containing table being inserted into */
82899 db = pParse->db;
82901 if( pParse->nErr || db->mallocFailed ){
82914 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
82915 assert( iDb<db->nDb );
82916 pDb = &db->aDb[iDb];
83026 if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
83168 if( db->flags & SQLITE_CountRows ){
83179 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
83390 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
83410 if( (db->flags & SQLITE_CountRows)!=0 ){
83455 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
83462 sqlite3SrcListDelete(db, pTabList);
83463 sqlite3ExprListDelete(db, pList);
83464 sqlite3SelectDelete(db, pSelect);
83465 sqlite3IdListDelete(db, pColumn);
83466 sqlite3DbFree(db, aRegIdx);
83614 zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
83636 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
83703 if( pParse->db->flags&SQLITE_RecTriggers ){
83792 errMsg.db = pParse->db;
83804 sqlite3DbFree(errMsg.db, zErr);
83816 if( pParse->db->flags&SQLITE_RecTriggers ){
83916 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
84170 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
84284 sqlite3 *db, /* The database on which the SQL executes */
84297 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
84300 sqlite3_mutex_enter(db->mutex);
84301 sqlite3Error(db, SQLITE_OK, 0);
84307 rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
84328 && db->flags&SQLITE_NullCallback)) ){
84330 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
84347 db->mallocFailed = 1;
84356 sqlite3Error(db, SQLITE_ABORT, 0);
84373 sqlite3DbFree(db, azCols);
84379 sqlite3DbFree(db, azCols);
84381 rc = sqlite3ApiExit(db, rc);
84382 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
84383 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
84386 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
84389 sqlite3Error(db, SQLITE_NOMEM, 0);
84395 assert( (rc&db->errMask)==rc );
84396 sqlite3_mutex_leave(db->mutex);
84507 int (*errcode)(sqlite3*db);
85204 ** by calling sqlite3DbFree(db, ).
85207 sqlite3 *db, /* Load the extension into this database connection */
85212 sqlite3_vfs *pVfs = db->pVfs;
85227 if( (db->flags & SQLITE_LoadExtension)==0 ){
85263 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
85272 /* Append the new shared library handle to the db->aExtension array. */
85273 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
85277 if( db->nExtension>0 ){
85278 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
85280 sqlite3DbFree(db, db->aExtension);
85281 db->aExtension = aHandle;
85283 db->aExtension[db->nExtension++] = handle;
85287 sqlite3 *db, /* Load the extension into this database connection */
85293 sqlite3_mutex_enter(db->mutex);
85294 rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
85295 rc = sqlite3ApiExit(db, rc);
85296 sqlite3_mutex_leave(db->mutex);
85304 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
85306 assert( sqlite3_mutex_held(db->mutex) );
85307 for(i=0; i<db->nExtension; i++){
85308 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
85310 sqlite3DbFree(db, db->aExtension);
85317 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
85318 sqlite3_mutex_enter(db->mutex);
85320 db->flags |= SQLITE_LoadExtension;
85322 db->flags &= ~SQLITE_LoadExtension;
85324 sqlite3_mutex_leave(db->mutex);
85435 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
85460 if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){
85461 sqlite3Error(db, SQLITE_ERROR,
85555 ** Interpret the given string as a temp db location. Return 1 for file
85578 sqlite3 *db = pParse->db;
85579 if( db->aDb[1].pBt!=0 ){
85580 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
85585 sqlite3BtreeClose(db->aDb[1].pBt);
85586 db->aDb[1].pBt = 0;
85587 sqlite3ResetInternalSchema(db, 0);
85601 sqlite3 *db = pParse->db;
85602 if( db->temp_store==ts ) return SQLITE_OK;
85606 db->temp_store = (u8)ts;
85617 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
85630 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
85636 int mask; /* Mask for the db->flags value */
85676 sqlite3 *db = pParse->db;
85682 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
85685 if( db->autoCommit==0 ){
85692 db->flags |= mask;
85694 db->flags &= ~mask;
85782 sqlite3 *db = pParse->db;
85783 Db *pDb;
85784 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db);
85790 ** index of the database this pragma is being applied to in db.aDb[]. */
85793 pDb = &db->aDb[iDb];
85802 zLeft = sqlite3NameFromToken(db, pId);
85805 zRight = sqlite3MPrintf(db, "-%T", pValue);
85807 zRight = sqlite3NameFromToken(db, pValue);
85885 db->nextPagesize = sqlite3Atoi(zRight);
85886 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
85887 db->mallocFailed = 1;
85909 for(ii=0; ii<db->nDb; ii++){
85910 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
85960 eMode = db->dfltLockMode;
85966 ** set on all attached databases, as well as the main db file.
85973 assert(pDb==&db->aDb[0]);
85974 for(ii=2; ii<db
85975 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
85978 db->dfltLockMode = (u8)eMode;
86033 for(ii=db->nDb-1; ii>=0; ii--){
86034 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
86086 db->nextAutovac = (u8)eAuto;
86091 ** as an auto-vacuum capable db.
86186 returnSingleInt(pParse, "temp_store", db->temp_store);
86216 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
86223 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
86224 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
86302 if( !db->autoCommit ){
86335 pTab = sqlite3FindTable(db, zRight, zDb);
86374 pIdx = sqlite3FindIndex(db, zRight, zDb);
86398 pTab = sqlite3FindTable(db, zRight, zDb);
86429 for(i=0; i<db->nDb; i++){
86430 if( db->aDb[i].pBt==0 ) continue;
86431 assert( db->aDb[i].zName!=0 );
86433 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
86435 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
86447 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
86461 pTab = sqlite3FindTable(db, zRight, zDb);
86519 sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
86567 for(i=0; i<db->nDb; i++){
86584 pTbls = &db->aDb[i].pSchema->tblHash;
86606 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
86737 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
86746 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
86747 DbHasProperty(db, 0, DB_Empty)
86751 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
86877 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
86880 db->xWalCallback==sqlite3WalDefaultHook ?
86881 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
86898 for(i=0; i<db->nDb; i++){
86903 if( db->aDb[i].zName==0 ) continue;
86904 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
86905 pBt = db->aDb[i].pBt;
86908 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
86921 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
86924 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
86936 sqlite3_key(db, zKey, i/2);
86938 sqlite3_rekey(db, zKey, i/2);
86965 if( db->autoCommit ){
86967 (db->flags&SQLITE_FullFSync)!=0,
86968 (db->flags&SQLITE_CkptFullFSync)!=0);
86972 sqlite3DbFree(db, zLeft);
86973 sqlite3DbFree(db, zRight);
87005 sqlite3 *db = pData->db;
87006 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
87008 sqlite3SetString(pData->pzErrMsg, db,
87011 *pData->pzErrMsg = sqlite3MAppendf(db, *pData->pzErrMsg,
87015 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT;
87032 sqlite3 *db = pData->db;
87037 assert( sqlite3_mutex_held(db->mutex) );
87038 DbClearProperty(db, iDb, DB_Empty);
87039 if( db->mallocFailed ){
87044 assert( iDb>=0 && iDb<db->nDb );
87050 ** But because db->init.busy is set to 1, no VDBE code is generated
87058 assert( db->init.busy );
87059 db->init.iDb = iDb;
87060 db->init.newTnum = sqlite3Atoi(argv[1]);
87061 db->init.orphanTrigger = 0;
87062 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
87063 rc = db->errCode;
87065 db->init.iDb = 0;
87067 if( db->init.orphanTrigger ){
87072 db->mallocFailed = 1;
87074 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
87089 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
87112 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
87117 Db *pDb;
87151 assert( iDb>=0 && iDb<db->nDb );
87152 assert( db->aDb[iDb].pSchema );
87153 assert( sqlite3_mutex_held(db->mutex) );
87154 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
87172 initData.db = db;
87181 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
87188 pDb = &db->aDb[iDb];
87191 DbSetProperty(db, 1, DB_SchemaLoaded);
87203 sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
87216 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
87233 ** For an attached db, it is an error if the encoding is not the same
87239 /* If opening the main database, set ENC(db). */
87242 ENC(db) = encoding;
87243 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
87245 /* If opening an attached database, the encoding much match ENC(db) */
87246 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
87247 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
87254 DbSetProperty(db, iDb, DB_Empty);
87256 pDb->pSchema->enc = ENC(db);
87277 sqlite3SetString(pzErrMsg, db, "unsupported file format");
87288 db->flags &= ~SQLITE_LegacyFileFmt;
87293 assert( db->init.busy );
87296 zSql = sqlite3MPrintf(db,
87298 db->aDb[iDb].zName, zMasterName);
87302 xAuth = db->xAuth;
87303 db->xAuth = 0;
87305 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
87307 db->xAuth = xAuth;
87311 sqlite3DbFree(db, zSql);
87314 sqlite3AnalysisLoad(db, iDb);
87318 if( db->mallocFailed ){
87320 sqlite3ResetInternalSchema(db, 0);
87322 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
87331 DbSetProperty(db, iDb, DB_SchemaLoaded);
87347 db->mallocFailed = 1;
87359 ** bit is set in the flags field of the Db structure. If the database
87362 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
87364 int commit_internal = !(db->flags&SQLITE_InternChanges);
87366 assert( sqlite3_mutex_held(db->mutex) );
87368 db->init.busy = 1;
87369 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
87370 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
87371 rc = sqlite3InitOne(db, i, pzErrMsg);
87373 sqlite3ResetInternalSchema(db, i);
87382 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
87383 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
87384 rc = sqlite3InitOne(db, 1, pzErrMsg);
87386 sqlite3ResetInternalSchema(db, 1);
87391 db->init.busy = 0;
87393 sqlite3CommitInternalChanges(db);
87405 sqlite3 *db = pParse->db;
87406 assert( sqlite3_mutex_held(db->mutex) );
87407 if( !db->init.busy ){
87408 rc = sqlite3Init(db, &pParse->zErrMsg);
87424 sqlite3 *db = pParse->db;
87430 assert( sqlite3_mutex_held(db->mutex) );
87431 for(iDb=0; iDb<db->nDb; iDb++){
87433 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
87442 db->mallocFailed = 1;
87452 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
87465 ** which database file in db->aDb[] the schema refers to.
87470 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
87479 ** -1000000 as the incorrect index into db->aDb[] is much
87483 assert( sqlite3_mutex_held(db->mutex) );
87485 for(i=0; ALWAYS(i<db->nDb); i++){
87486 if( db->aDb[i].pSchema==pSchema ){
87490 assert( i>=0 && i<db->nDb );
87499 sqlite3 *db, /* Database handle. */
87513 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
87520 assert( !db->mallocFailed );
87521 assert( sqlite3_mutex_held(db->mutex) );
87546 for(i=0; i<db->nDb; i++) {
87547 Btree *pBt = db->aDb[i].pBt;
87552 const char *zDb = db->aDb[i].zName;
87553 sqlite3Error(db, rc, "database schema is locked: %s", zDb);
87554 testcase( db->flags & SQLITE_ReadUncommitted );
87560 sqlite3VtabUnlockList(db);
87562 pParse->db = db;
87566 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
87570 sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
87571 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
87574 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
87577 sqlite3DbFree(db, zSqlCopy);
87587 if( db->mallocFailed ){
87595 sqlite3ResetInternalSchema(db, 0);
87597 if( db->mallocFailed ){
87628 assert( db->init.busy==0 || saveSqlFlag==0 );
87629 if( db->init.busy==0 ){
87633 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
87641 sqlite3Error(db, rc, "%s", zErrMsg);
87642 sqlite3DbFree(db, zErrMsg);
87644 sqlite3Error(db, rc, 0);
87651 sqlite3DbFree(db, pT);
87656 sqlite3StackFree(db, pParse);
87657 rc = sqlite3ApiExit(db, rc);
87658 assert( (rc&db->errMask)==rc );
87662 sqlite3 *db, /* Database handle. */
87673 if( !sqlite3SafetyCheckOk(db) ){
87676 sqlite3_mutex_enter(db->mutex);
87677 sqlite3BtreeEnterAll(db);
87678 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
87681 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
87683 sqlite3BtreeLeaveAll(db);
87684 sqlite3_mutex_leave(db->mutex);
87700 sqlite3 *db;
87705 db = sqlite3VdbeDb(p);
87706 assert( sqlite3_mutex_held(db->mutex) );
87707 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
87710 db->mallocFailed = 1;
87734 sqlite3 *db, /* Database handle. */
87741 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
87746 sqlite3 *db, /* Database handle. */
87753 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
87764 sqlite3 *db, /* Database handle. */
87781 if( !sqlite3SafetyCheckOk(db) ){
87784 sqlite3_mutex_enter(db->mutex);
87785 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
87787 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
87799 sqlite3DbFree(db, zSql8);
87800 rc = sqlite3ApiExit(db, rc);
87801 sqlite3_mutex_leave(db->mutex);
87814 sqlite3 *db, /* Database handle. */
87821 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
87826 sqlite3 *db, /* Database handle. */
87833 rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
87862 static void clearSelect(sqlite3 *db, Select *p){
87863 sqlite3ExprListDelete(db, p->pEList);
87864 sqlite3SrcListDelete(db, p->pSrc);
87865 sqlite3ExprDelete(db, p->pWhere);
87866 sqlite3ExprListDelete(db, p->pGroupBy);
87867 sqlite3ExprDelete(db, p->pHaving);
87868 sqlite3ExprListDelete(db, p->pOrderBy);
87869 sqlite3SelectDelete(db, p->pPrior);
87870 sqlite3ExprDelete(db, p->pLimit);
87871 sqlite3ExprDelete(db, p->pOffset);
87904 sqlite3 *db = pParse->db;
87905 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
87906 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
87912 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
87928 if( db->mallocFailed ) {
87929 clearSelect(db, pNew);
87930 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
87939 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
87941 clearSelect(db, p);
87942 sqlite3DbFree(db, p);
88086 sqlite3 *db = pParse->db;
88096 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
88097 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
88106 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
88212 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
88588 sqlite3 *db = pParse->db;
88595 pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
88599 pInfo->enc = ENC(db);
88600 pInfo->db = db;
88605 pColl = db->pDfltColl;
88644 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
88674 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
88902 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
88903 zOriginDb = pNC->pParse->db->aDb[iDb].zName;
88987 sqlite3 *db = pParse->db;
88997 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
88999 fullNames = (db->flags & SQLITE_FullColNames)!=0;
89000 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
89027 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
89030 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
89037 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
89062 sqlite3 *db = pParse->db; /* Database connection */
89072 aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
89082 zName = sqlite3DbStrDup(db, zName);
89092 zName = sqlite3MPrintf(db, "%s",
89096 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
89099 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
89102 if( db->mallocFailed ){
89103 sqlite3DbFree(db, zName);
89115 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
89116 sqlite3DbFree(db, zName);
89124 if( db->mallocFailed ){
89126 sqlite3DbFree(db, aCol[j].zName);
89128 sqlite3DbFree(db, aCol);
89153 sqlite3 *db = pParse->db;
89163 assert( nCol==pSelect->pEList->nExpr || db->mallocFailed );
89164 if( db->mallocFailed ) return;
89170 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0));
89175 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
89186 sqlite3 *db = pParse->db;
89189 savedFlags = db->flags;
89190 db->flags &= ~SQLITE_FullColNames;
89191 db->flags |= SQLITE_ShortColNames;
89195 db->flags = savedFlags;
89196 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
89202 assert( db->lookaside.bEnabled==0 );
89209 if( db->mallocFailed ){
89210 sqlite3DeleteTable(db, pTab);
89223 v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
89377 sqlite3 *db; /* Database connection */
89387 db = pParse->db;
89537 sqlite3ExprListDelete(db, p->pOrderBy);
89542 sqlite3ExprDelete(db, p->pLimit);
89622 sqlite3ExprDelete(db, p->pLimit);
89674 pKeyInfo = sqlite3DbMallocZero(db,
89681 pKeyInfo->enc = ENC(db);
89687 *apColl = db->pDfltColl;
89705 sqlite3DbFree(db, pKeyInfo);
89711 sqlite3SelectDelete(db, pDelete);
89766 if( pParse->db->mallocFailed ) return 0;
89995 sqlite3 *db; /* Database connection */
90006 db = pParse->db;
90027 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
90034 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
90051 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
90059 sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1));
90063 pKeyMerge->enc = ENC(db);
90085 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
90095 assert( nOrderBy>=nExpr || db->mallocFailed );
90098 pKeyDup = sqlite3DbMallocZero(db,
90103 pKeyDup->enc = ENC(db);
90130 sqlite3ExprDelete(db, p->pLimit);
90132 sqlite3ExprDelete(db, p->pOffset);
90298 sqlite3SelectDelete(db, p->pPrior);
90328 sqlite3 *db, /* Report malloc errors to this connection */
90341 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
90345 sqlite3ExprDelete(db, pExpr);
90349 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
90350 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
90352 substSelect(db, pExpr->x.pSelect, iTable, pEList);
90354 substExprList(db, pExpr->x.pList, iTable, pEList);
90360 sqlite3 *db, /* Report malloc errors here */
90368 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
90372 sqlite3 *db, /* Report malloc errors here */
90381 substExprList(db, p->pEList, iTable, pEList);
90382 substExprList(db, p->pGroupBy, iTable, pEList);
90383 substExprList(db, p->pOrderBy, iTable, pEList);
90384 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
90385 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
90386 substSelect(db, p->pPrior, iTable, pEList);
90391 substSelect(db, pItem->pSelect, iTable, pEList);
90523 sqlite3 *db = pParse->db;
90529 if( db->flags & SQLITE_QueryFlattener ) return 0;
90681 pNew = sqlite3SelectDup(db, p, 0);
90694 if( db->mallocFailed ) return 1;
90705 sqlite3DbFree(db, pSubitem->zDatabase);
90706 sqlite3DbFree(db, pSubitem->zName);
90707 sqlite3DbFree(db, pSubitem->zAlias);
90757 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
90759 assert( db->mallocFailed );
90780 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
90781 if( db->mallocFailed ){
90790 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
90813 pList->a[i].zName = sqlite3DbStrDup(db, zSpan);
90817 substExprList(db, pParent->pEList, iParent, pSub->pEList);
90819 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
90820 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
90827 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
90830 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
90838 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
90839 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
90840 sqlite3ExprDup(db, pSub->pHaving, 0));
90842 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
90844 pParent->pWhere = substExpr(db, pParent->pWhere, iParent, pSub->pEList);
90845 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
90868 sqlite3SelectDelete(db, pSub1);
90995 sqlite3 *db = pParse->db;
90997 if( db->mallocFailed ){
91031 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
91034 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
91053 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
91067 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
91096 int flags = pParse->db->flags;
91132 if( db->mallocFailed ) break;
91167 pRight = sqlite3Expr(db, TK_ID, zName);
91172 pLeft = sqlite3Expr(db, TK_ID, zTabName);
91175 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
91185 sqlite3DbFree(db, zToFree);
91197 sqlite3ExprListDelete(db, pEList);
91201 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
91233 ** and/or pParse->db->mallocFailed.
91320 sqlite3 *db;
91322 db = pParse->db;
91325 if( pParse->nErr || db->mallocFailed ) return;
91327 if( pParse->nErr || db->mallocFailed ) return;
91422 pColl = pParse->db->pDfltColl;
91530 sqlite3 *db; /* The database connection */
91537 db = pParse->db;
91538 if( p==0 || db->mallocFailed || pParse->nErr ){
91549 sqlite3ExprListDelete(db, p->pOrderBy);
91557 if( pParse->nErr || db->mallocFailed ){
91613 if( /*pParse->nErr ||*/ db->mallocFailed ){
91642 mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
91659 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
91672 && (db->flags & SQLITE_GroupByOrder)==0 ){
91802 if( db->mallocFailed ) goto select_end;
92028 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
92098 pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->x.pList,0);
92100 if( pMinMax && !db->mallocFailed ){
92113 sqlite3ExprListDelete(db, pDel);
92130 sqlite3ExprListDelete(db, pDel);
92169 sqlite3DbFree(db, sAggInfo.aCol);
92170 sqlite3DbFree(db, sAggInfo.aFunc);
92387 sqlite3 *db, /* The database on which the SQL executes */
92409 db->errCode = SQLITE_NOMEM;
92413 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
92425 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
92438 db->errCode = SQLITE_NOMEM;
92486 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
92491 sqlite3ExprDelete(db, pTmp->pWhere);
92492 sqlite3ExprListDelete(db, pTmp->pExprList);
92493 sqlite3SelectDelete(db, pTmp->pSelect);
92494 sqlite3IdListDelete(db, pTmp->pIdList);
92496 sqlite3DbFree(db, pTmp);
92515 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
92561 sqlite3 *db = pParse->db; /* The database connection */
92563 Token *pName; /* The unqualified db name */
92564 DbFixer sFix; /* State vector for the DB fixer */
92580 /* Figure out the db that the the trigger will be created in */
92592 if( !pTableName || db->mallocFailed ){
92596 if( db->init.busy==0 && pName2->n==0 && pTab
92597 && pTab->pSchema==db->aDb[1].pSchema ){
92602 if( db->mallocFailed ) goto trigger_cleanup;
92611 if( db->init.iDb==1 ){
92620 db->init.orphanTrigger = 1;
92631 zName = sqlite3NameFromToken(db, pName);
92635 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
92663 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
92668 const char *zDb = db->aDb[iTabDb].zName;
92669 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
92690 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
92694 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
92695 pTrigger->pSchema = db->aDb[iDb].pSchema;
92699 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
92700 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
92705 sqlite3DbFree(db, zName);
92706 sqlite3SrcListDelete(db, pTableName);
92707 sqlite3IdListDelete(db, pColumns);
92708 sqlite3ExprDelete(db, pWhen);
92710 sqlite3DeleteTrigger(db, pTrigger);
92727 sqlite3 *db = pParse->db; /* The database */
92736 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
92752 if( !db->init.busy ){
92760 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
92763 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
92765 sqlite3DbFree(db, z);
92768 db, "type='trigger' AND name='%q'", zName), P4_DYNAMIC
92772 if( db->init.busy ){
92774 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
92777 db->mallocFailed = 1;
92789 sqlite3DeleteTrigger(db, pTrig);
92791 sqlite3DeleteTriggerStep(db, pStepList);
92801 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
92802 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
92804 sqlite3SelectDelete(db, pSelect);
92817 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
92820 sqlite3 *db, /* Database connection */
92826 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
92845 sqlite3 *db, /* The database connection */
92855 assert(pEList != 0 || pSelect != 0 || db->mallocFailed);
92857 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
92859 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
92861 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
92864 sqlite3IdListDelete(db, pColumn);
92866 sqlite3ExprListDelete(db, pEList);
92867 sqlite3SelectDelete(db, pSelect);
92878 sqlite3 *db, /* The database connection */
92886 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
92888 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
92889 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
92892 sqlite3ExprListDelete(db, pEList);
92893 sqlite3ExprDelete(db, pWhere);
92903 sqlite3 *db, /* Database connection */
92909 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
92911 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
92914 sqlite3ExprDelete(db, pWhere);
92921 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
92923 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
92924 sqlite3DbFree(db, pTrigger->zName);
92925 sqlite3DbFree(db, pTrigger->table);
92926 sqlite3ExprDelete(db, pTrigger->pWhen);
92927 sqlite3IdListDelete(db, pTrigger->pColumns);
92928 sqlite3DbFree(db, pTrigger);
92945 sqlite3 *db = pParse->db;
92947 if( db->mallocFailed ) goto drop_trigger_cleanup;
92956 for(i=OMIT_TEMPDB; i<db->nDb; i++){
92958 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
92959 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
92972 sqlite3SrcListDelete(db, pName);
92991 sqlite3 *db = pParse->db;
92994 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
92995 assert( iDb>=0 && iDb<db->nDb );
93002 const char *zDb = db->aDb[iDb].zName;
93046 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
93047 Hash *pHash = &(db->aDb[iDb].pSchema->trigHash);
93057 sqlite3DeleteTrigger(db, pTrigger);
93058 db->flags |= SQLITE_InternChanges;
93125 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
93129 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
93131 sqlite3 *db = pParse->db;
93132 assert( iDb<pParse->db->nDb );
93133 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
93150 sqlite3 *db = pParse->db;
93175 sqlite3ExprListDup(db, pStep->pExprList, 0),
93176 sqlite3ExprDup(db, pStep->pWhere, 0),
93184 sqlite3ExprListDup(db, pStep->pExprList, 0),
93185 sqlite3SelectDup(db, pStep->pSelect, 0),
93186 sqlite3IdListDup(db, pStep->pIdList),
93194 sqlite3ExprDup(db, pStep->pWhere, 0)
93200 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
93203 sqlite3SelectDelete(db, pSelect);
93245 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
93260 sqlite3 *db = pParse->db; /* Database handle */
93275 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
93279 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
93289 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
93293 pSubParse->db = db;
93312 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
93320 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
93322 && db->mallocFailed==0
93327 sqlite3ExprDelete(db, pWhen);
93341 if( db->mallocFailed==0 ){
93354 db, pSubParse);
93410 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
93415 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
93496 || p->pSchema==pParse->db->aDb[1].pSchema );
93667 sqlite3 *db; /* The database structure */
93698 db = pParse->db;
93699 if( pParse->nErr || db->mallocFailed ){
93708 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
93733 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
93787 pTab->aCol[j].zName, db->aDb[iDb].zName);
93806 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
93897 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
94080 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
94114 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
94122 sqlite3DbFree(db, aRegIdx);
94123 sqlite3DbFree(db, aXRef);
94124 sqlite3SrcListDelete(db, pTabList);
94125 sqlite3ExprListDelete(db, pChanges);
94126 sqlite3ExprDelete(db, pWhere);
94176 sqlite3 *db = pParse->db; /* Database connection */
94177 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
94183 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));
94186 sqlite3ExprDup(db, pRowid, 0));
94191 pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);
94193 pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
94229 sqlite3SelectDelete(db, pSelect);
94257 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
94261 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
94267 ** Execute zSql on database db. Return an error code.
94269 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
94275 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
94276 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
94277 return sqlite3_errcode(db);
94281 return vacuumFinalize(db, pStmt, pzErrMsg);
94285 ** Execute zSql on database db. The statement returns exactly
94288 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
94292 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
94296 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
94298 vacuumFinalize(db, pStmt, pzErrMsg);
94303 return vacuumFinalize(db, pStmt, pzErrMsg);
94327 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
94332 int saved_flags; /* Saved value of the db->flags */
94333 int saved_nChange; /* Saved value of db->nChange */
94334 int saved_nTotalChange; /* Saved value of db->nTotalChange */
94335 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */
94336 Db *pDb = 0; /* Database to detach at end of vacuum */
94341 if( !db->autoCommit ){
94342 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
94345 if( db->activeVdbeCnt>1 ){
94346 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
94353 saved_flags = db->flags;
94354 saved_nChange = db->nChange;
94355 saved_nTotalChange = db->nTotalChange;
94356 saved_xTrace = db->xTrace;
94357 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
94358 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
94359 db->xTrace = 0;
94361 pMain = db->aDb[0].pBt;
94378 nDb = db->nDb;
94379 if( sqlite3TempInMemory(db) ){
94384 rc = execSql(db, pzErrMsg, zSql);
94385 if( db->nDb>nDb ){
94386 pDb = &db->aDb[db->nDb-1];
94390 pTemp = db->aDb[db->nDb-1].pBt;
94402 if( db->nextPagesize ){
94406 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
94407 if( nKey ) db->nextPagesize = 0;
94414 db->nextPagesize = 0;
94418 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
94419 || NEVER(db->mallocFailed)
94424 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
94430 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
94435 rc = execSql(db, pzErrMsg, "BEGIN EXCLUSIVE;");
94441 rc = execExecSql(db, pzErrMsg,
94447 rc = execExecSql(db, pzErrMsg,
94451 rc = execExecSql(db, pzErrMsg,
94460 rc = execExecSql(db, pzErrMsg,
94471 rc = execExecSql(db, pzErrMsg,
94476 rc = execExecSql(db, pzErrMsg,
94489 rc = execSql(db, pzErrMsg,
94498 /* At this point, unless the main db was completely empty, there is now a
94548 /* Restore the original value of db->flags */
94549 db->flags = saved_flags;
94550 db->nChange = saved_nChange;
94551 db->nTotalChange = saved_nTotalChange;
94552 db->xTrace = saved_xTrace;
94562 db->autoCommit = 1;
94570 sqlite3ResetInternalSchema(db, 0);
94599 sqlite3 *db, /* Database in which module is registered */
94608 sqlite3_mutex_enter(db->mutex);
94610 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
94619 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
94623 sqlite3DbFree(db, pDel);
94625 db->mallocFailed = 1;
94627 sqlite3ResetInternalSchema(db, 0);
94631 rc = sqlite3ApiExit(db, SQLITE_OK);
94632 sqlite3_mutex_leave(db->mutex);
94641 sqlite3 *db, /* Database in which module is registered */
94646 return createModule(db, zName, pModule, pAux, 0);
94653 sqlite3 *db, /* Database in which module is registered */
94659 return createModule(db, zName, pModule, pAux, xDestroy);
94677 ** Return a pointer to the VTable object used by connection db to access
94680 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
94683 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
94692 sqlite3 *db = pVTab->db;
94694 assert( db );
94696 assert( sqlite3SafetyCheckOk(db) );
94704 sqlite3DbFree(db, pVTab);
94712 ** Except, if argument db is not NULL, then the entry associated with
94713 ** connection db is left in the p->pVTable list.
94715 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
94725 assert( db==0 ||
94726 sqlite3BtreeHoldsMutex(db->aDb[sqlite3SchemaToIndex(db, p->pSchema)].pBt)
94730 sqlite3 *db2 = pVTable->db;
94733 if( db2==db ){
94744 assert( !db || pRet );
94753 ** shared b-tree databases opened using connection db are held by the
94769 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
94770 VTable *p = db->pDisconnect;
94771 db->pDisconnect = 0;
94773 assert( sqlite3BtreeHoldsAllMutexes(db) );
94774 assert( sqlite3_mutex_held(db->mutex) );
94777 sqlite3ExpirePreparedStatements(db);
94795 ** connection db is decremented immediately (which may lead to the
94800 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
94801 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
94805 sqlite3DbFree(db, p->azModuleArg[i]);
94807 sqlite3DbFree(db, p->azModuleArg);
94817 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
94821 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
94825 sqlite3DbFree(db, pTable->azModuleArg[j]);
94827 sqlite3DbFree(db, zArg);
94828 sqlite3DbFree(db, pTable->azModuleArg);
94850 sqlite3 *db; /* Database connection */
94857 db = pParse->db;
94858 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
94863 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
94864 addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName));
94865 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
94876 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
94890 sqlite3 *db = pParse->db;
94891 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
94901 sqlite3 *db = pParse->db; /* The database connection */
94914 if( !db->init.busy ){
94924 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
94934 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
94939 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
94945 sqlite3DbFree(db, zStmt);
94950 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
94968 db->mallocFailed = 1;
95007 sqlite3 *db,
95018 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
95024 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
95026 sqlite3DbFree(db, zModuleName);
95029 pVTable->db = db;
95032 assert( !db->pVTab );
95034 db->pVTab = pTab;
95037 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
95038 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
95042 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
95044 *pzErr = sqlite3MPrintf(db, "%s", zErr);
95047 sqlite3DbFree(db, pVTable);
95053 if( db->pVTab ){
95055 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
95100 sqlite3DbFree(db, zModuleName);
95101 db->pVTab = 0;
95113 sqlite3 *db = pParse->db;
95119 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
95125 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
95133 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
95137 sqlite3DbFree(db, zErr);
95146 static int addToVTrans(sqlite3 *db, VTable *pVTab){
95150 if( (db->nVTrans%ARRAY_INCR)==0 ){
95152 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
95153 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
95157 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
95158 db->aVTrans = aVTrans;
95162 db->aVTrans[db->nVTrans++] = pVTab;
95173 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
95175 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
95181 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
95186 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
95193 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
95196 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
95201 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
95202 rc = addToVTrans(db, sqlite3GetVTable(db, pTab));
95213 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
95220 sqlite3_mutex_enter(db->mutex);
95221 pTab = db->pVTab;
95223 sqlite3Error(db, SQLITE_MISUSE, 0);
95224 sqlite3_mutex_leave(db->mutex);
95229 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
95234 pParse->db = db;
95239 && !db->mallocFailed
95249 db->pVTab = 0;
95251 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
95252 sqlite3DbFree(db, zErr);
95260 sqlite3DeleteTable(db, pParse->pNewTable);
95261 sqlite3StackFree(db, pParse);
95265 rc = sqlite3ApiExit(db, rc);
95266 sqlite3_mutex_leave(db->mutex);
95277 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
95281 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
95283 VTable *p = vtabDisconnectAll(db, pTab);
95308 static void callFinaliser(sqlite3 *db, int offset){
95310 if( db->aVTrans ){
95311 for(i=0; i<db->nVTrans; i++){
95312 VTable *pVTab = db->aVTrans[i];
95321 sqlite3DbFree(db, db->aVTrans);
95322 db->nVTrans = 0;
95323 db->aVTrans = 0;
95335 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
95338 VTable **aVTrans = db->aVTrans;
95340 db->aVTrans = 0;
95341 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
95346 sqlite3DbFree(db, *pzErrmsg);
95347 *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
95351 db->aVTrans = aVTrans;
95359 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
95360 callFinaliser(db, offsetof(sqlite3_module,xRollback));
95368 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
95369 callFinaliser(db, offsetof(sqlite3_module,xCommit));
95381 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
95385 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
95390 if( sqlite3VtabInSync(db) ){
95403 for(i=0; i<db->nVTrans; i++){
95404 if( db->aVTrans[i]==pVTab ){
95412 rc = addToVTrans(db, pVTab);
95432 sqlite3 *db, /* Database connection for reporting malloc problems */
95454 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
95463 zLowerName = sqlite3DbStrDup(db, pDef->zName);
95469 sqlite3DbFree(db, zLowerName);
95477 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
95512 pToplevel->db->mallocFailed = 1;
95631 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
95790 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
95792 sqlite3DbFree(db, p);
95798 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
95800 sqlite3DbFree(db, p);
95810 sqlite3 *db = pWC->pParse->db;
95813 sqlite3ExprDelete(db, a->pExpr);
95816 whereOrInfoDelete(db, a->u.pOrInfo);
95818 whereAndInfoDelete(db, a->u.pAndInfo);
95822 sqlite3DbFree(db, pWC->a);
95832 ** the db->mallocFailed flag so that higher-level functions can detect it.
95851 sqlite3 *db = pWC->pParse->db;
95852 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
95855 sqlite3ExprDelete(db, p);
95862 sqlite3DbFree(db, pOld);
95864 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
96164 sqlite3 *db = pParse->db; /* Database connection */
96168 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
96208 pPrefix = sqlite3Expr(db, TK_STRING, z);
96360 sqlite3 *db = pParse->db; /* Database connection */
96378 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
96385 if( db->mallocFailed ) return;
96399 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
96412 testcase( db->mallocFailed );
96413 if( !db->mallocFailed ){
96560 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
96565 pDup = sqlite3ExprDup(db, pLeft, 0);
96579 sqlite3ExprListDelete(db, pList);
96622 sqlite3 *db = pParse->db; /* Database connection */
96624 if( db->mallocFailed ){
96668 pDup = sqlite3ExprDup(db, pExpr, 0);
96669 if( db->mallocFailed ){
96670 sqlite3ExprDelete(db, pDup);
96721 sqlite3ExprDup(db, pExpr->pLeft, 0),
96722 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
96767 pStr2 = sqlite3ExprDup(db, pStr1, 0);
96768 if( !db->mallocFailed ){
96786 pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0);
96788 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
96794 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
96828 0, sqlite3ExprDup(db, pRight, 0), 0);
96903 sqlite3 *db = pParse->db;
96938 pColl = db->pDfltColl;
97215 if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
97344 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
97463 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
97532 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
97543 pParse->db->mallocFailed = 1;
97629 assert( sqlite3GetVTable(pParse->db, pTab) );
97753 sqlite3 *db = pParse->db;
97763 pColl = db->pDfltColl;
97766 pColl = sqlite3GetCollSeq(db, SQLITE_UTF8, 0, *pIdx->azColl);
97789 db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
97792 assert( db->mallocFailed );
97796 sqlite3DbFree(db, zSample);
97844 return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
98342 if( !pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
98385 sqlite3DbFree(pParse->db, p);
98448 assert( pParse->db->mallocFailed );
98518 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
98606 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
98608 pParse->db->mallocFailed = 1;
98691 static char *explainIndexRange(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
98704 txt.db = db;
98739 sqlite3 *db = pParse->db; /* Database handle */
98751 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
98753 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
98755 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
98759 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
98762 char *zWhere = explainIndexRange(db, pLevel, pItem->pTab);
98763 zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg,
98770 sqlite3DbFree(db, zWhere);
98772 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
98775 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
98777 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
98779 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
98781 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
98787 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
98797 zMsg = sqlite3MAppendf(db, zMsg, "%s (~%lld rows)", zMsg, nRow);
99111 zEndAff = sqlite3DbStrDup(pParse->db, zStartAff);
99190 sqlite3DbFree(pParse->db, zStartAff);
99191 sqlite3DbFree(pParse->db, zEndAff);
99306 pOrTab = sqlite3StackAllocRaw(pParse->db,
99376 if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
99467 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
99473 /* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
99477 sqlite3DbFree(db, pInfo);
99482 sqlite3DbFree(db, pIdx->zColAff);
99483 sqlite3DbFree(db, pIdx);
99488 sqlite3DbFree(db, pWInfo);
99600 sqlite3 *db; /* Database connection */
99625 db = pParse->db;
99627 pWInfo = sqlite3DbMallocZero(db,
99632 if( db->mallocFailed ){
99633 sqlite3DbFree(db, pWInfo);
99709 if( db->mallocFailed ){
99916 if( pParse->nErr || db->mallocFailed ){
99952 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
99958 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
99999 if( db->mallocFailed ) goto whereBeginError;
100071 whereInfoFree(db, pWInfo);
100086 sqlite3 *db = pParse->db;
100107 sqlite3DbFree(db, pLevel->u.in.aInLoop);
100168 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){
100199 whereInfoFree(db, pWInfo);
100315 sqlite3 *db = pParse->db;
100316 if( db->mallocFailed==0 && pY->op==TK_NULL ){
100318 sqlite3ExprDelete(db, pA->pRight);
101590 sqlite3SelectDelete(pParse->db, (yypminor->yy387));
101596 sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
101612 sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
101620 sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
101632 sqlite3ExprDelete(pParse->db, (yypminor->yy314));
101639 sqlite3IdListDelete(pParse->db, (yypminor->yy384));
101645 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
101650 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
102333 pParse->db->lookaside.bEnabled = 0;
102369 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
102562 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
102574 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
102607 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
102623 {yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
102668 {yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
102793 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
102796 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
102868 if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
102974 sqlite3ExprListDelete(pParse->db, pList);
102993 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy118.pExpr);
103000 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
103016 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
103030 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
103039 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
103046 sqlite3SrcListDelete(pParse->db, pSrc);
103061 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
103074 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
103095 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy322, yymsp[-9].minor.yy4,
103110 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
103234 { yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
103237 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy384, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy210);}
103240 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
103243 {yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
103246 {yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
103313 pParse->db->lookaside.bEnabled = 0;
104299 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
104300 sqlite3 *db = pParse->db
104304 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
104305 if( db->activeVdbeCnt==0 ){
104306 db->u1.isInterrupted = 0;
104314 db->mallocFailed = 1;
104323 enableLookaside = db->lookaside.bEnabled;
104324 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
104325 while( !db->mallocFailed && zSql[i]!=0 ){
104336 if( db->u1.isInterrupted ){
104344 sqlite3DbFree(db, *pzErrMsg);
104345 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
104378 db->lookaside.bEnabled = enableLookaside;
104379 if( db->mallocFailed ){
104383 sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc));
104398 sqlite3DbFree(db, pParse->aTableLock);
104412 sqlite3DeleteTable(db, pParse->pNewTable);
104415 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
104416 sqlite3DbFree(db, pParse->apVarExpr);
104417 sqlite3DbFree(db, pParse->aAlias);
104421 sqlite3DbFree(db, p);
104426 sqlite3DeleteTable(db, p);
104761 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
104793 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
104825 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
105249 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
105251 if( db->lookaside.nOut ){
105258 if( db->lookaside.bMalloced ){
105259 sqlite3_free(db->lookaside.pStart);
105278 db->lookaside.pStart = pStart;
105279 db->lookaside.pFree = 0;
105280 db->lookaside.sz = (u16)sz;
105287 p->pNext = db->lookaside.pFree;
105288 db
105291 db->lookaside.pEnd = p;
105292 db->lookaside.bEnabled = 1;
105293 db->lookaside.bMalloced = pBuf==0 ?1:0;
105295 db->lookaside.pEnd = 0;
105296 db->lookaside.bEnabled = 0;
105297 db->lookaside.bMalloced = 0;
105305 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
105306 return db->mutex;
105312 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
105321 rc = setupLookaside(db, pBuf, sz, cnt);
105396 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
105397 return db->lastRowid;
105403 SQLITE_API int sqlite3_changes(sqlite3 *db){
105404 return db->nChange;
105410 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
105411 return db->nTotalChange;
105419 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
105420 while( db->pSavepoint ){
105421 Savepoint *pTmp = db->pSavepoint;
105422 db->pSavepoint = pTmp->pNext;
105423 sqlite3DbFree(db, pTmp);
105425 db->nSavepoint = 0;
105426 db->nStatement = 0;
105427 db->isTransactionSavepoint = 0;
105436 static void functionDestroy(sqlite3 *db, FuncDef *p){
105442 sqlite3DbFree(db, pDestructor);
105450 SQLITE_API int sqlite3_close(sqlite3 *db){
105454 if( !db ){
105457 if( !sqlite3SafetyCheckSickOrOk(db) ){
105460 sqlite3_mutex_enter(db->mutex);
105462 sqlite3ResetInternalSchema(db, 0);
105466 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
105471 sqlite3VtabRollback(db);
105474 if( db->pVdbe ){
105475 sqlite3Error(db, SQLITE_BUSY,
105477 sqlite3_mutex_leave(db->mutex);
105480 assert( sqlite3SafetyCheckSickOrOk(db) );
105482 for(j=0; j<db->nDb; j++){
105483 Btree *pBt = db->aDb[j].pBt;
105485 sqlite3Error(db, SQLITE_BUSY,
105487 sqlite3_mutex_leave(db->mutex);
105493 sqlite3CloseSavepoints(db);
105495 for(j=0; j<db->nDb; j++){
105496 struct Db *pDb = &db->aDb[j];
105505 sqlite3ResetInternalSchema(db, 0);
105510 sqlite3ConnectionClosed(db);
105512 assert( db->nDb<=2 );
105513 assert( db->aDb==db->aDbStatic );
105514 for(j=0; j<ArraySize(db->aFunc.a); j++){
105516 for(p=db->aFunc.a[j]; p; p=pHash){
105519 functionDestroy(db, p);
105521 sqlite3DbFree(db, p);
105526 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
105534 sqlite3DbFree(db, pColl);
105536 sqlite3HashClear(&db->aCollSeq);
105538 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
105543 sqlite3DbFree(db, pMod);
105545 sqlite3HashClear(&db->aModule);
105548 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
105549 if( db->pErr ){
105550 sqlite3ValueFree(db->pErr);
105552 sqlite3CloseExtensions(db);
105554 db->magic = SQLITE_MAGIC_ERROR;
105562 sqlite3DbFree(db, db->aDb[1].pSchema);
105563 sqlite3_mutex_leave(db->mutex);
105564 db->magic = SQLITE_MAGIC_CLOSED;
105565 sqlite3_mutex_free(db->mutex);
105566 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
105567 if( db->lookaside.bMalloced ){
105568 sqlite3_free(db->lookaside.pStart);
105570 sqlite3_free(db);
105577 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db){
105580 assert( sqlite3_mutex_held(db->mutex) );
105582 for(i=0; i<db->nDb; i++){
105583 if( db->aDb[i].pBt ){
105584 if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){
105587 sqlite3BtreeRollback(db->aDb[i].pBt);
105588 db->aDb[i].inTrans = 0;
105591 sqlite3VtabRollback(db);
105594 if( db->flags&SQLITE_InternChanges ){
105595 sqlite3ExpirePreparedStatements(db);
105596 sqlite3ResetInternalSchema(db, 0);
105600 db->nDeferredCons = 0;
105603 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
105604 db->xRollbackCallback(db->pRollbackArg);
105666 sqlite3 *db = (sqlite3 *)ptr;
105667 int timeout = db->busyTimeout;
105682 sqlite3OsSleep(db->pVfs, delay*1000);
105685 sqlite3 *db = (sqlite3 *)ptr;
105690 sqlite3OsSleep(db->pVfs, 1000000);
105719 sqlite3 *db,
105723 sqlite3_mutex_enter(db->mutex);
105724 db->busyHandler.xFunc = xBusy;
105725 db->busyHandler.pArg = pArg;
105726 db->busyHandler.nBusy = 0;
105727 sqlite3_mutex_leave(db->mutex);
105738 sqlite3 *db,
105743 sqlite3_mutex_enter(db->mutex);
105745 db->xProgress = xProgress;
105746 db->nProgressOps = nOps;
105747 db->pProgressArg = pArg;
105749 db->xProgress = 0;
105750 db->nProgressOps = 0;
105751 db->pProgressArg = 0;
105753 sqlite3_mutex_leave(db->mutex);
105762 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
105764 db->busyTimeout = ms;
105765 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
105767 sqlite3_busy_handler(db, 0, 0);
105775 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
105776 db->u1.isInterrupted = 1;
105787 sqlite3 *db,
105800 assert( sqlite3_mutex_held(db->mutex) );
105822 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
105825 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
105842 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
105844 if( db->activeVdbeCnt ){
105845 sqlite3Error(db, SQLITE_BUSY,
105847 assert( !db->mallocFailed );
105850 sqlite3ExpirePreparedStatements(db);
105854 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
105855 assert(p || db->mallocFailed);
105862 db, p);
105881 sqlite3 *db,
105890 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
105895 sqlite3 *db,
105907 sqlite3_mutex_enter(db->mutex);
105909 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
105917 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
105921 sqlite3DbFree(db, pArg);
105925 rc = sqlite3ApiExit(db, rc);
105926 sqlite3_mutex_leave(db->mutex);
105932 sqlite3 *db,
105943 sqlite3_mutex_enter(db->mutex);
105944 assert( !db->mallocFailed );
105945 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
105946 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
105947 sqlite3DbFree(db, zFunc8);
105948 rc = sqlite3ApiExit(db, rc);
105949 sqlite3_mutex_leave(db->mutex);
105968 sqlite3 *db,
105974 sqlite3_mutex_enter(db->mutex);
105975 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
105976 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
105979 rc = sqlite3ApiExit(db, SQLITE_OK);
105980 sqlite3_mutex_leave(db->mutex);
105993 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
105995 sqlite3_mutex_enter(db->mutex);
105996 pOld = db->pTraceArg;
105997 db->xTrace = xTrace;
105998 db->pTraceArg = pArg;
105999 sqlite3_mutex_leave(db->mutex);
106011 sqlite3 *db,
106016 sqlite3_mutex_enter(db->mutex);
106017 pOld = db->pProfileArg;
106018 db->xProfile = xProfile;
106019 db->pProfileArg = pArg;
106020 sqlite3_mutex_leave(db->mutex);
106032 sqlite3 *db, /* Attach the hook to this database */
106037 sqlite3_mutex_enter(db->mutex);
106038 pOld = db->pCommitArg;
106039 db->xCommitCallback = xCallback;
106040 db->pCommitArg = pArg;
106041 sqlite3_mutex_leave(db->mutex);
106050 sqlite3 *db, /* Attach the hook to this database */
106055 sqlite3_mutex_enter(db->mutex);
106056 pRet = db->pUpdateArg;
106057 db->xUpdateCallback = xCallback;
106058 db->pUpdateArg = pArg;
106059 sqlite3_mutex_leave(db->mutex);
106068 sqlite3 *db, /* Attach the hook to this database */
106073 sqlite3_mutex_enter(db->mutex);
106074 pRet = db->pRollbackArg;
106075 db->xRollbackCallback = xCallback;
106076 db->pRollbackArg = pArg;
106077 sqlite3_mutex_leave(db->mutex);
106090 sqlite3 *db, /* Connection */
106096 sqlite3_wal_checkpoint(db, zDb);
106114 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
106116 UNUSED_PARAMETER(db);
106120 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
106122 sqlite3_wal_hook(db, 0, 0);
106133 sqlite3 *db, /* Attach the hook to this db handle */
106139 sqlite3_mutex_enter(db->mutex);
106140 pRet = db->pWalArg;
106141 db->xWalCallback = xCallback;
106142 db->pWalArg = pArg;
106143 sqlite3_mutex_leave(db->mutex);
106156 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
106161 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
106163 sqlite3_mutex_enter(db->mutex);
106165 iDb = sqlite3FindDbName(db, zDb);
106169 sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb);
106171 rc = sqlite3Checkpoint(db, iDb);
106172 sqlite3Error(db, rc, 0);
106174 rc = sqlite3ApiExit(db, rc);
106175 sqlite3_mutex_leave(db->mutex);
106190 ** The mutex on database handle db should be held by the caller. The mutex
106198 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb){
106202 assert( sqlite3_mutex_held(db->mutex) );
106204 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
106206 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt);
106217 ** The value returned depends on the value of db->temp_store (runtime
106222 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
106233 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
106235 return ( db->temp_store==2 );
106238 return ( db->temp_store!=1 );
106252 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
106254 if( !db ){
106257 if( !sqlite3SafetyCheckSickOrOk(db) ){
106260 sqlite3_mutex_enter(db->mutex);
106261 if( db->mallocFailed ){
106264 z = (char*)sqlite3_value_text(db->pErr);
106265 assert( !db->mallocFailed );
106267 z = sqlite3ErrStr(db->errCode);
106270 sqlite3_mutex_leave(db->mutex);
106279 SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){
106293 if( !db ){
106296 if( !sqlite3SafetyCheckSickOrOk(db) ){
106299 sqlite3_mutex_enter(db->mutex);
106300 if( db->mallocFailed ){
106303 z = sqlite3_value_text16(db->pErr);
106305 sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
106307 z = sqlite3_value_text16(db->pErr);
106310 ** above. If this is the case, then the db->mallocFailed flag needs to
106314 db->mallocFailed = 0;
106316 sqlite3_mutex_leave(db->mutex);
106325 SQLITE_API int sqlite3_errcode(sqlite3 *db){
106326 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
106329 if( !db || db->mallocFailed ){
106332 return db->errCode & db->errMask;
106334 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
106335 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
106338 if( !db || db->mallocFailed ){
106341 return db->errCode;
106345 ** Create a new collating function for database "db". The name is zName
106349 sqlite3* db,
106361 assert( sqlite3_mutex_held(db->mutex) );
106381 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
106383 if( db->activeVdbeCnt ){
106384 sqlite3Error(db, SQLITE_BUSY,
106388 sqlite3ExpirePreparedStatements(db);
106397 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
106411 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
106418 sqlite3Error(db, SQLITE_OK, 0);
106487 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
106514 oldLimit = db->aLimit[limitId];
106519 db->aLimit[limitId] = newLimit;
106535 sqlite3 *db;
106601 db = sqlite3MallocZero( sizeof(sqlite3) );
106602 if( db==0 ) goto opendb_out;
106604 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
106605 if( db->mutex==0 ){
106606 sqlite3_free(db);
106607 db = 0;
106611 sqlite3_mutex_enter(db->mutex);
106612 db->errMask = 0xff;
106613 db->nDb = 2;
106614 db->magic = SQLITE_MAGIC_BUSY;
106615 db->aDb = db->aDbStatic;
106617 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
106618 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
106619 db->autoCommit = 1;
106620 db->nextAutovac = -1;
106621 db->nextPagesize = 0;
106622 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
106633 sqlite3HashInit(&db->aCollSeq);
106635 sqlite3HashInit(&db->aModule);
106638 db->pVfs = sqlite3_vfs_find(zVfs);
106639 if( !db->pVfs ){
106641 sqlite3Error(db, rc, "no such vfs: %s", zVfs);
106649 createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
106651 createCollation(db, "BINARY", SQLITE_UTF16BE, SQLITE_COLL_BINARY, 0,
106653 createCollation(db, "BINARY", SQLITE_UTF16LE, SQLITE_COLL_BINARY, 0,
106655 createCollation(db, "RTRIM", SQLITE_UTF8, SQLITE_COLL_USER, (void*)1,
106657 if( db->mallocFailed ){
106660 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
106661 assert( db->pDfltColl!=0 );
106664 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
106668 db->openFlags = flags;
106669 rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0,
106675 sqlite3Error(db, rc, 0);
106678 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
106679 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
106685 db->aDb[0].zName = "main";
106686 db->aDb[0].safety_level = 3;
106687 db->aDb[1].zName = "temp";
106688 db->aDb[1].safety_level = 1;
106690 db->magic = SQLITE_MAGIC_OPEN;
106691 if( db->mallocFailed ){
106699 sqlite3Error(db, SQLITE_OK, 0);
106700 sqlite3RegisterBuiltinFunctions(db);
106705 sqlite3AutoLoadExtensions(db);
106706 rc = sqlite3_errcode(db);
106712 if( !db->mallocFailed ){
106714 rc = sqlite3Fts1Init(db);
106719 if( !db->mallocFailed && rc==SQLITE_OK ){
106721 rc = sqlite3Fts2Init(db);
106726 if( !db->mallocFailed && rc==SQLITE_OK ){
106727 rc = sqlite3Fts3Init(db);
106732 if( !db->mallocFailed && rc==SQLITE_OK ){
106733 rc = sqlite3IcuInit(db);
106738 if( !db->mallocFailed && rc==SQLITE_OK){
106739 rc = sqlite3RtreeInit(db);
106743 sqlite3Error(db, rc, 0);
106750 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
106751 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
106756 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
106759 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
106762 if( db ){
106763 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
106764 sqlite3_mutex_leave(db->mutex);
106766 rc = sqlite3_errcode(db);
106768 sqlite3_close(db);
106769 db = 0;
106771 db->magic = SQLITE_MAGIC_SICK;
106773 *ppDb = db;
106789 sqlite3 **ppDb, /* OUT: SQLite db handle */
106835 ** Register a new collation sequence with the database handle db.
106838 sqlite3* db,
106845 sqlite3_mutex_enter(db->mutex);
106846 assert( !db->mallocFailed );
106847 rc = createCollation(db, zName, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
106848 rc = sqlite3ApiExit(db, rc);
106849 sqlite3_mutex_leave(db->mutex);
106854 ** Register a new collation sequence with the database handle db.
106857 sqlite3* db,
106865 sqlite3_mutex_enter(db->mutex);
106866 assert( !db->mallocFailed );
106867 rc = createCollation(db, zName, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, xDel);
106868 rc = sqlite3ApiExit(db, rc);
106869 sqlite3_mutex_leave(db->mutex);
106875 ** Register a new collation sequence with the database handle db.
106878 sqlite3* db,
106886 sqlite3_mutex_enter(db->mutex);
106887 assert( !db->mallocFailed );
106888 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
106890 rc = createCollation(db, zName8, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
106891 sqlite3DbFree(db, zName8);
106893 rc = sqlite3ApiExit(db, rc);
106894 sqlite3_mutex_leave(db->mutex);
106901 ** db. Replace any previously installed collation sequence factory.
106904 sqlite3 *db,
106908 sqlite3_mutex_enter(db->mutex);
106909 db->xCollNeeded = xCollNeeded;
106910 db->xCollNeeded16 = 0;
106911 db->pCollNeededArg = pCollNeededArg;
106912 sqlite3_mutex_leave(db->mutex);
106919 ** db. Replace any previously installed collation sequence factory.
106922 sqlite3 *db,
106926 sqlite3_mutex_enter(db->mutex);
106927 db->xCollNeeded = 0;
106928 db->xCollNeeded16 = xCollNeeded16;
106929 db->pCollNeededArg = pCollNeededArg;
106930 sqlite3_mutex_leave(db->mutex);
106953 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
106954 return db->autoCommit;
107009 sqlite3 *db, /* Connection handle */
107032 sqlite3_mutex_enter(db->mutex);
107033 sqlite3BtreeEnterAll(db);
107034 rc = sqlite3Init(db, &zErrMsg);
107040 pTab = sqlite3FindTable(db, zTableName, zDbName);
107090 sqlite3BtreeLeaveAll(db);
107103 sqlite3DbFree(db, zErrMsg);
107104 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
107108 sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
107109 sqlite3DbFree(db, zErrMsg);
107110 rc = sqlite3ApiExit(db, rc);
107111 sqlite3_mutex_leave(db->mutex);
107135 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
107136 sqlite3_mutex_enter(db->mutex);
107137 db->errMask = onoff ? 0xffffffff : 0xff;
107138 sqlite3_mutex_leave(db->mutex);
107145 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
107148 sqlite3_mutex_enter(db->mutex);
107152 for(iDb=0; iDb<db->nDb; iDb++){
107153 if( strcmp(db->aDb[iDb].zName, zDbName)==0 ) break;
107156 if( iDb<db->nDb ){
107157 Btree *pBtree = db->aDb[iDb].pBt;
107175 sqlite3_mutex_leave(db->mutex);
107323 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
107326 ** connection db.
107329 sqlite3 *db = va_arg(ap, sqlite3*);
107331 sqlite3_mutex_enter(db->mutex);
107332 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
107333 sqlite3_mutex_leave(db->mutex);
107337 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
107347 sqlite3 *db = va_arg(ap, sqlite3*);
107349 db->flags = (x & SQLITE_OptMask) | (db->flags & ~SQLITE_OptMask);
107454 ** 3) If the argument db is not NULL, then none of the entries in the
107456 ** set to db. This is used when closing connection db.
107458 static void checkListProperties(sqlite3 *db){
107471 assert( db==0 || p->pUnlockConnection!=db );
107472 assert( db==0 || p->pBlockingConnection!=db );
107481 ** Remove connection db from the blocked connections list. If connection
107482 ** db
107484 static void removeFromBlockedList(sqlite3 *db){
107488 if( *pp==db ){
107496 ** Add connection db to the blocked connections list. It is assumed
107499 static void addToBlockedList(sqlite3 *db){
107504 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
107507 db->pNextBlocked = *pp;
107508 *pp = db;
107531 ** This is called after connection "db" has attempted some operation
107534 ** cache. pOther is found by looking at db->pBlockingConnection.
107539 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
107546 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
107550 sqlite3 *db,
107556 sqlite3_mutex_enter(db->mutex);
107560 removeFromBlockedList(db);
107561 db->pBlockingConnection = 0;
107562 db->pUnlockConnection = 0;
107563 db->xUnlockNotify = 0;
107564 db->pUnlockArg = 0;
107565 }else if( 0==db->pBlockingConnection ){
107574 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
107578 db->pUnlockConnection = db->pBlockingConnection;
107579 db->xUnlockNotify = xNotify;
107580 db->pUnlockArg = pArg;
107581 removeFromBlockedList(db);
107582 addToBlockedList(db);
107587 assert( !db->mallocFailed );
107588 sqlite3Error(db, rc, (rc?"database is deadlocked":0));
107589 sqlite3_mutex_leave(db->mutex);
107595 ** associated with connection db. The operation will return SQLITE_LOCKED
107599 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
107601 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
107602 addToBlockedList(db);
107604 db->pBlockingConnection = pBlocker;
107610 ** the transaction opened by database db has just finished. Locks held
107611 ** by database connection db have been released.
107617 ** set to db, then set pBlockingConnection=0.
107620 ** set to db, then invoke the configured unlock-notify callback and
107627 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
107643 if( p->pBlockingConnection==db ){
107648 if( p->pUnlockConnection==db ){
107675 ** is returned the transaction on connection db will still be
107726 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
107727 sqlite3ConnectionUnlocked(db);
107729 removeFromBlockedList(db);
107730 checkListProperties(db);
108429 sqlite3 *db; /* The database connection */
108663 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
108828 sqlite3 *db, /* Database in which to run SQL */
108841 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
108852 sqlite3 *db = p->db;
108855 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", p->zDb, p->zName);
108856 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", p->zDb,p->zName);
108857 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", p->zDb, p->zName);
108858 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", p->zDb, p->zName);
108859 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", p->zDb, p->zName);
108898 rc = sqlite3_declare_vtab(p->db, zSql);
108920 sqlite3 *db = p->db; /* The database connection */
108931 fts3DbExec(&rc, db,
108937 fts3DbExec(&rc, db,
108941 fts3DbExec(&rc, db,
108954 fts3DbExec(&rc, db,
108960 fts3DbExec(&rc, db,
108985 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
109041 sqlite3 *db, /* The SQLite database connection */
109155 p->db = db;
109224 sqlite3 *db, /* Database connection */
109231 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
109234 sqlite3 *db, /* Database connection */
109241 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
111295 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
111700 sqlite3 *db = p->db; /* Database connection */
111708 fts3DbExec(&rc, db,
111713 fts3DbExec(&rc, db,
111719 fts3DbExec(&rc, db,
111724 fts3DbExec(&rc, db,
111728 fts3DbExec(&rc, db,
111791 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
111827 rc = sqlite3Fts3ExprInitTestInterface(db);
111836 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
111837 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
111838 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
111839 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
111840 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
111841 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
111844 db, "fts3", &fts3Module, (void *)pHash, hashDestroy
111848 db, "fts4", &fts3Module, (void *)pHash, 0
111865 sqlite3 *db,
111870 return sqlite3Fts3Init(db);
112636 sqlite3 *db,
112645 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
112739 sqlite3 *db = sqlite3_context_db_handle(context);
112748 rc = queryTestTokenizer(db,
112801 ** with database connection db.
112803 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
112805 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
114161 sqlite3 *db,
114169 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
114183 sqlite3 *db,
114192 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
114235 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
114242 rc = queryTokenizer(db, "simple", &p2);
114245 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
114248 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
114251 rc = registerTokenizer(db, "nosuchtokenizer", p1);
114253 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
114263 ** Set up SQL objects in database db used to access the contents of
114280 sqlite3 *db,
114291 void *pdb = (void *)db;
114300 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
114303 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
114307 rc = sqlite3_create_function(db, zTest, 2, any, p, testFunc, 0, 0);
114310 rc = sqlite3_create_function(db, zTest, 3, any, p, testFunc, 0, 0);
114313 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
114824 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
115264 *piDocid = sqlite3_last_insert_rowid(p->db);
115429 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
116220 ** blocks were written to the db). Otherwise, an SQLite error code is
116432 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
116439 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
116638 char *zTerm, /* Term to write to the db */
116654 char *zTerm, /* Term to write to the db */
117429 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
117433 rc = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
117438 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
117439 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
119230 sqlite3 *db; /* Host database connection */
119710 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
119800 sqlite3 *db,
119806 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
119813 sqlite3 *db,
119819 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
119874 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
121738 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
121922 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
121953 sqlite3 *db,
121980 pRtree->db = db;
121993 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
122013 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
122026 ** using database connection db. If successful, the integer value returned
122030 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
122034 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
122061 sqlite3 *db, /* Database handle */
122070 rc = getIntFromStmt(db, zSql, &iPageSize);
122082 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
122099 sqlite3 *db, /* Database connection */
122144 rc = getNodeSize(db, pRtree, isCreate);
122151 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
122152 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
122169 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
122170 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
122253 ** Register the r-tree module with database handle db. This creates the
122257 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
122261 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
122263 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
122267 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
122271 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
122321 sqlite3 *db,
122336 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
122343 sqlite3 *db,
122348 return sqlite3RtreeInit(db);
122767 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
122789 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
122799 ** Register the ICU extension functions with database db.
122801 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
122824 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
122833 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
122842 sqlite3 *db,
122847 return sqlite3IcuInit(db);