Home | History | Annotate | Download | only in dist

Lines Matching refs:Db

956 #define SQLITE_UNCLOSED    27   /* db can't be closed due unfinalized stmts */
2373 sqlite3 *db, /* An open database */
2435 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2463 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2902 sqlite3 **ppDb /* OUT: SQLite db handle */
2906 sqlite3 **ppDb /* OUT: SQLite db handle */
2910 sqlite3 **ppDb, /* OUT: SQLite db handle */
2948 SQLITE_API int sqlite3_errcode(sqlite3 *db);
2949 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3089 ** The first argument, "db", is a [database connection] obtained from a
3163 sqlite3 *db, /* Database handle */
3170 sqlite3 *db, /* Database handle */
3177 sqlite3 *db, /* Database handle */
3184 sqlite3 *db, /* Database handle */
3987 sqlite3 *db,
3997 sqlite3 *db,
4007 sqlite3 *db,
4508 sqlite3 *db, /* Database to be rekeyed */
4521 sqlite3 *db, /* Database to be rekeyed */
4912 sqlite3 *db, /* Connection handle */
4949 sqlite3 *db, /* Load the extension into this database connection */
4968 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4985 **   sqlite3 *db,
5198 sqlite3 *db, /* SQLite connection to register module with */
5204 sqlite3 *db, /* SQLite connection to register module with */
6720 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6736 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
6781 sqlite3 *db,
7371 typedef struct Db Db;
7472 sqlite3 *db, /* Associated database connection */
7486 #define BTREE_MEMORY 4 /* This is an in-memory DB */
8808 struct Db {
8834 ** Db.pSchema->flags field.
8842 ** Allowed values for the DB.pSchema->flags field.
8934 Db *aDb; /* All backends */
9011 Db aDbStatic[2]; /* Static space for the 2 default backends */
9041 #define ENC(db) ((db)->aDb[0].pSchema->enc)
9356 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
9360 sqlite3 *db; /* Database connection associated with this table */
9534 sqlite3 *db; /* The database connection */
10288 sqlite3 *db; /* The main database structure */
10361 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
10396 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
10397 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
10511 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
10527 sqlite3 *db; /* The database being initialized */
11075 SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
11104 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11111 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
11156 # define sqlite3VtabInSync(db) 0
11161 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
11162 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
11163 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
11164 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
11168 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
11271 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
11272 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
12020 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12127 sqlite3 *db; /* The associated database connection */
12265 sqlite3 *db; /* The database connection that owns this statement */
12266 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12300 int nChange; /* Number of db changes made since last reset */
12301 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12501 sqlite3 *db, /* The database connection whose status is desired */
12508 sqlite3_mutex_enter(db->mutex);
12511 *pCurrent = db->lookaside.nOut;
12512 *pHighwater = db->lookaside.mxOut;
12514 db->lookaside.mxOut = db->lookaside.nOut;
12527 sqlite3BtreeEnterAll(db);
12528 for(i=0; i<db->nDb; i++){
12529 Btree *pBt = db->aDb[i].pBt;
12535 sqlite3BtreeLeaveAll(db);
12550 db->pnBytesFreed = &nByte;
12551 for(i=0; i<db->nDb; i++){
12552 Schema *pSchema = db->aDb[i].pSchema;
12568 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
12571 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
12575 db->pnBytesFreed = 0;
12591 db->pnBytesFreed = &nByte;
12592 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
12593 sqlite3VdbeDeleteObject(db, pVdbe);
12595 db->pnBytesFreed = 0;
12607 sqlite3_mutex_leave(db->mutex);
12920 sqlite3 *db = sqlite3_context_db_handle(context);
12921 sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
13459 sqlite3 *db;
13463 db = sqlite3_context_db_handle(context);
13499 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
13500 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
13503 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
13507 z = sqlite3DbMallocRaw(db, (int)n);
13643 sqlite3 *db;
13650 db = sqlite3_context_db_handle(context);
13651 sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
17892 ** TRUE if p is a lookaside memory allocation from db
17895 static int isLookaside(sqlite3 *db, void *p){
17896 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
17911 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
17912 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17913 if( db && isLookaside(db, p) ){
17914 return db->lookaside.sz;
17918 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17945 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
17946 assert( db==0 || sqlite3_mutex_held(db->mutex) );
17947 if( db ){
17948 if( db->pnBytesFreed ){
17949 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
17952 if( isLookaside(db, p) ){
17954 pBuf->pNext = db->lookaside.pFree;
17955 db
17956 db->lookaside.nOut--;
17962 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
18044 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
18045 void *p = sqlite3DbMallocRaw(db, n);
18056 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
18063 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
18064 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
18070 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
18072 assert( db==0 || sqlite3_mutex_held(db->mutex) );
18073 assert( db==0 || db->pnBytesFreed==0 );
18075 if( db ){
18077 if( db->mallocFailed ){
18080 if( db->lookaside.bEnabled && n<=db->lookaside.sz
18081 && (pBuf = db->lookaside.pFree)!=0 ){
18082 db->lookaside.pFree = pBuf->pNext;
18083 db->lookaside.nOut++;
18084 if( db->lookaside.nOut>db->lookaside.mxOut ){
18085 db->lookaside.mxOut = db->lookaside.nOut;
18091 if( db && db->mallocFailed ){
18096 if( !p && db ){
18097 db->mallocFailed = 1;
18100 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
18108 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
18110 assert( db!=0 );
18111 assert( sqlite3_mutex_held(db->mutex) );
18112 if( db->mallocFailed==0 ){
18114 return sqlite3DbMallocRaw(db, n);
18116 if( isLookaside(db, p) ){
18117 if( n<=db->lookaside.sz ){
18120 pNew = sqlite3DbMallocRaw(db, n);
18122 memcpy(pNew, p, db->lookaside.sz);
18123 sqlite3DbFree(db, p);
18132 db->mallocFailed = 1;
18135 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
18145 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
18147 pNew = sqlite3DbRealloc(db, p, n);
18149 sqlite3DbFree(db, p);
18161 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
18169 zNew = sqlite3DbMallocRaw(db, (int)n);
18175 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
18181 zNew = sqlite3DbMallocRaw(db, n+1);
18194 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){
18199 z = sqlite3VMPrintf(db, zFormat, ap);
18201 sqlite3DbFree(db, *pz);
18215 ** If the first argument, db, is not NULL and a malloc() error has occurred,
18219 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
18220 /* If the db handle is not NULL, then we must hold the connection handle
18221 ** mutex here. Otherwise the read (and possible write) of db->mallocFailed
18224 assert( !db || sqlite3_mutex_held(db->mutex) );
18225 if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
18226 sqlite3Error(db, SQLITE_NOMEM, 0);
18227 db->mallocFailed = 0;
18230 return rc & (db ? db->errMask : 0xff);
19009 zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
19038 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
19058 sqlite3DbFree(p->db, p->zText);
19071 p->db = 0;
19084 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
19088 assert( db!=0 );
19090 db->aLimit[SQLITE_LIMIT_LENGTH]);
19091 acc.db = db;
19095 db->mallocFailed = 1;
19104 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
19108 z = sqlite3VMPrintf(db, zFormat, ap);
19118 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
19121 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3 *db, char *zStr, const char *zFormat, ...){
19125 z = sqlite3VMPrintf(db, zFormat, ap);
19127 sqlite3DbFree(db, zStr);
19610 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
19674 zOut = sqlite3DbMallocRaw(pMem->db, len);
19838 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
19841 m.db = db;
19844 if( db->mallocFailed ){
19848 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
19849 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
19850 assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
19851 assert( m.z || db->mallocFailed );
19862 ** If a malloc failure occurs, NULL is returned and the db.mallocFailed
19866 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
19869 m.db = db;
19872 assert( db->mallocFailed );
20057 ** handle "db". The error code is set to "err_code".
20072 ** To clear the most recent error for sqlite handle "db", sqlite3Error
20076 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
20077 if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
20078 db->errCode = err_code;
20083 z = sqlite3VMPrintf(db, zFormat, ap);
20085 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
20087 sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
20112 sqlite3 *db = pParse->db;
20114 zMsg = sqlite3VMPrintf(db, zFormat, ap);
20116 if( db->suppressErr ){
20117 sqlite3DbFree(db, zMsg);
20120 sqlite3DbFree(db, pParse->zErrMsg);
20950 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
20954 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
20979 ** Check to make sure we have a valid db pointer. This test is not
20981 ** misuse of the interface such as passing in db pointers that are
20983 ** 1 it means that the db pointer is valid and 0 if it should not be
20987 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
20988 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
20992 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
20994 if( db==0 ){
20998 magic = db->magic;
21000 if( sqlite3SafetyCheckSickOrOk(db) ){
21009 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
21011 magic = db->magic;
26440 ** is "/home/user1/config.db" then the file that is created and mmapped
26441 ** for shared memory will be called "/home/user1/config.db-shm".
27206 ** proxyLock activation is possible (remote proxy is based on db name)
27533 ** "<path to db>-journal"
27534 ** "<path to db>-wal"
27535 ** "<path to db>-journal-NNNN"
27536 ** "<path to db>-wal-NNNN"
27634 /* The main DB, main journal, WAL file and master journal are never
28200 ** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
28202 ** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
28217 ** For database path "/Users/me/foo.db"
28218 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
28351 /* transform the db path to a unique cache name */
29009 /* afp style keeps a reference to the db path in the filePath field
29021 /* all other styles use the locking context to store the db file path */
31730 /* The main DB, main journal, WAL file and master journal are never
34375 sqlite3 *db; /* The database connection */
34387 ** are available at pSpace. The db pointer is used as a memory context
34397 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
34402 p->db = db;
34422 sqlite3DbFree(p->db, pChunk);
34444 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
34807 int sync_flags, /* Flags to sync db file with (or 0) */
35096 ** db size etc.) are consistent with the contents of the file-system.
35509 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
35510 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
36698 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
37144 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
37861 i64 n = 0; /* Size of db file in bytes */
37901 ** function. Because an EXCLUSIVE lock on the db file is required to delete
39162 ROUND8(pVfs->szOsFile) + /* The main db file */
40500 int noSync /* True to omit the xSync on the db file */
40521 /* If this is an in-memory db, or no pages have been written to, or this
40572 /* Update the db file change counter via the direct-write method. The
41947 u32 nBackfill; /* Number of WAL frames backfilled into DB */
42237 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
42264 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
43210 ** about the eventual size of the db file to the VFS layer.
43220 /* Iterate through the contents of the WAL, copying data to the db file. */
44122 u32 nDbsize; /* Db-size field for frame header */
44230 int sync_flags, /* Flags to sync db file with (or 0) */
44719 sqlite3 *db; /* The database connection holding this btree */
44722 u8 sharable; /* True if we can share pBt with another db */
44723 u8 locked; /* True if db currently has pBt locked */
44726 Btree *pNext; /* List of other sharable Btrees from the same db */
44781 sqlite3 *db; /* Database connection currently using this Btree */
44812 u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
44855 ** particular database connection identified BtCursor.pBtree.db.
45028 ** set BtShared.db to the database handle associated with p and the
45034 assert( sqlite3_mutex_held(p->db->mutex) );
45037 p->pBt->db = p->db;
45048 assert( sqlite3_mutex_held(p->db->mutex) );
45049 assert( p->db==p->pBt->db );
45080 assert( p->pNext==0 || p->pNext->db==p->db );
45081 assert( p->pPrev==0 || p->pPrev->db==p->db );
45089 assert( sqlite3_mutex_held(p->db->mutex) );
45091 /* Unless the database is sharable and unlocked, then BtShared.db
45093 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
45104 p->pBt->db = p->db;
45152 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
45154 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
45190 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
45193 assert( sqlite3_mutex_held(db->mutex) );
45194 for(i=0; i<db->nDb; i++){
45195 p = db->aDb[i].pBt;
45196 assert( !p || (p->locked==0 && p->sharable) || p->pBt->db==p->db );
45218 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
45221 assert( sqlite3_mutex_held(db->mutex) );
45222 for(i=0; i<db->nDb; i++){
45223 p = db->aDb[i].pBt;
45241 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
45243 if( !sqlite3_mutex_held(db->mutex) ){
45246 for(i=0; i<db->nDb; i++){
45248 p = db->aDb[i].pBt;
45313 assert( sqlite3_mutex_held(p->db->mutex) );
45339 assert( sqlite3_mutex_held(p->db->mutex) );
45350 p->pBt->db = p->db;
45352 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
45354 for(i=0; i<db->nDb; i++){
45355 Btree *p = db->aDb[i].pBt;
45357 p->pBt->db = p->db;
45500 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
45571 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
45592 assert( p->db!=0 );
45593 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
45611 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
45628 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
45665 assert( p->db!=0 );
45671 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
47030 assert( pBt->db );
47031 assert( sqlite3_mutex_held(pBt->db->mutex) );
47032 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
47049 ** bit is also set if the SQLITE_NoReadlock flags is set in db->flags.
47061 sqlite3 *db, /* Associated database handle */
47084 || (isTempDb && sqlite3TempInMemory(db));
47087 assert( db!=0 );
47088 assert( sqlite3_mutex_held(db->mutex) );
47097 if( db->flags & SQLITE_NoReadlock ){
47106 pVfs = db->pVfs;
47112 p->db = db;
47143 for(iDb=db->nDb-1; iDb>=0; iDb--){
47144 Btree *pExisting = db->aDb[iDb].pBt;
47199 pBt->db = db;
47250 db->mallocFailed = 0;
47270 for(i=0; i<db->nDb; i++){
47271 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
47385 assert( sqlite3_mutex_held(p->db->mutex) );
47452 assert( sqlite3_mutex_held(p->db->mutex) );
47475 assert( sqlite3_mutex_held(p->db->mutex) );
47491 assert( sqlite3_mutex_held(p->db->mutex) );
47753 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
47923 pBlock = pBt->pWriter->db;
47928 pBlock = pIter->pBtree->db;
47934 sqlite3ConnectionBlocked(p->db, pBlock);
47961 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
47998 /* If the db-size header field is incorrect (as it may be if an old
48020 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
48492 if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){
48714 assert( iStatement>p->db->nSavepoint );
49433 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49442 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49680 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49703 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49773 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
49814 ** would have already detected db corruption. Similarly, pPage must
52529 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
53294 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
53326 assert( sqlite3_mutex_held(p->db->mutex) );
53332 assert( sqlite3_mutex_held(p->db->mutex) );
53374 assert( sqlite3_mutex_held(p->db->mutex) );
53422 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
53464 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53604 pParse->db = pDb;
53822 int nSrcPage = -1; /* Size of source db in pages */
53823 int bCloseTrans = 0; /* True if src db requires unlocking */
54139 b.pSrcDb = pFrom->db;
54211 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54250 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
54252 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
54255 sqlite3DbFree(pMem->db, pMem->zMalloc);
54256 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
54287 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54316 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54340 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54371 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54415 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54418 ctx.s.db = pMem->db;
54423 sqlite3DbFree(pMem->db, pMem->zMalloc);
54436 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
54465 sqlite3DbFree(p->db, p->zMalloc);
54525 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54550 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54574 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54601 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54615 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54634 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54719 sqlite3 *db = pMem->db;
54720 assert( db!=0 );
54723 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
54724 if( db->mallocFailed ){
54728 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
54729 sqlite3DbMallocSize(db, pMem->zMalloc));
54740 assert( p->db!=0 );
54746 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
54825 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
54826 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
54827 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
54862 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
54871 if( pMem->db ){
54872 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
55123 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
55147 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
55148 || pVal->db->mallocFailed );
55159 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
55160 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
55164 p->db = db;
55180 sqlite3 *db, /* The database connection */
55220 pVal = sqlite3ValueNew(db);
55225 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
55241 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
55254 pVal = sqlite3ValueNew(db);
55259 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
55271 db->mallocFailed = 1;
55272 sqlite3DbFree(db, zVal);
55297 sqlite3DbFree(((Mem*)v)->db, v);
55350 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
55352 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
55354 p->db = db;
55355 if( db->pVdbe ){
55356 db->pVdbe->pPrev = p;
55358 p->pNext = db->pVdbe;
55360 db->pVdbe = p;
55375 p->zSql = sqlite3DbStrNDup(p->db, z, n);
55429 pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
55431 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
55549 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
55551 p->nLabelAlloc = sqlite3DbMallocSize(p->db, p->aLabel)/sizeof(p->aLabel[0]);
55595 ** sqlite3DbFree(v->db
55637 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
55690 sqlite3DbFree(v->db, sIter.apSub);
55697 return ( v->db->mallocFailed || hasAbort==mayAbort );
55745 sqlite3DbFree(p->db, p->aLabel);
55772 assert( aOp && !p->db->mallocFailed );
55885 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
55887 sqlite3DbFree(db, pDef);
55896 static void freeP4(sqlite3 *db, int p4type, void *p4){
55898 assert( db );
55906 sqlite3DbFree(db, p4);
55910 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
55915 freeEphemeralFunction(db, pVdbeFunc->pFunc);
55916 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
55917 sqlite3DbFree(db, pVdbeFunc);
55921 freeEphemeralFunction(db, (FuncDef*)p4);
55925 if( db->pnBytesFreed==0 ){
55929 sqlite3DbFree(db, p->zMalloc);
55930 sqlite3DbFree(db, p);
55935 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
55947 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
55951 freeP4(db, pOp->p4type, pOp->p4.p);
55953 sqlite3DbFree(db, pOp->zComment);
55957 sqlite3DbFree(db, aOp);
55976 sqlite3 *db = p->db;
55978 freeP4(db, pOp->p4type, pOp->p4.p);
56013 sqlite3 *db;
56015 db = p->db;
56017 if( p->aOp==0 || db->mallocFailed ){
56019 freeP4(db, n, (void*)*(char**)&zP4);
56029 freeP4(db, pOp->p4type, pOp->p4.p);
56057 p->db->mallocFailed = 1;
56067 assert( ((VTable *)zP4)->db==p->db );
56073 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
56089 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
56093 sqlite3DbFree(p->db, *pz);
56094 *pz = sqlite3VMPrintf(p->db, zFormat, ap);
56103 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
56107 sqlite3DbFree(p->db, *pz);
56108 *pz = sqlite3VMPrintf(p->db, zFormat, ap);
56146 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
56147 if( p->db->mallocFailed ){
56260 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
56269 assert( i>=0 && i<p->db->nDb && i<sizeof(u32)*8 );
56274 sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt);
56307 sqlite3 *db = p->db;
56308 u8 malloc_failed = db->mallocFailed;
56309 if( db->pnBytesFreed ){
56311 sqlite3DbFree(db, p->zMalloc);
56316 assert( (&p[1])==pEnd || p[0].db==p[1].db );
56333 sqlite3DbFree(db, p->zMalloc);
56339 db->mallocFailed = malloc_failed;
56355 sqlite3DbFree(p->v->db, p);
56381 sqlite3 *db = p->db; /* The database connection */
56399 db->mallocFailed = 1;
56435 }else if( db->u1.isInterrupted ){
56438 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
56506 assert( p->db->mallocFailed );
56523 assert( p->db->mallocFailed );
56670 sqlite3 *db = p->db;
56698 if( nVar>=0 && ALWAYS(db->mallocFailed==0) ){
56731 p->pFree = sqlite3DbMallocZero(db, nByte);
56735 }while( nByte && !db->mallocFailed );
56742 p->aVar[n].db = db;
56750 p->aMem[n].db = db;
56756 assert( p->aMem[n].db==db );
56820 v->db->lastRowid = pFrame->lastRowid;
56870 sqlite3 *db = p->db;
56880 sqlite3DbFree(db, p->zErrMsg);
56894 sqlite3 *db = p->db;
56897 sqlite3DbFree(db, p->aColName);
56900 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
56904 pColName->db = p->db;
56930 if( p->db->mallocFailed ){
56943 ** db. If a transaction is active, commit it. If there is a
56947 static int vdbeCommit(sqlite3 *db, Vdbe *p){
56966 rc = sqlite3VtabSync(db, &p->zErrMsg);
56974 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
56975 Btree *pBt = db->aDb[i].pBt;
56987 if( needXcommit && db->xCommitCallback ){
56988 rc = db->xCommitCallback(db->pCommitArg);
57003 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
57006 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
57007 Btree *pBt = db->aDb[i].pBt;
57018 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
57019 Btree *pBt = db->aDb[i].pBt;
57025 sqlite3VtabCommit(db);
57035 sqlite3_vfs *pVfs = db->pVfs;
57038 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
57046 sqlite3DbFree(db, zMaster);
57048 zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
57062 sqlite3DbFree(db, zMaster);
57072 for(i=0; i<db->nDb; i++){
57073 Btree *pBt = db->aDb[i].pBt;
57088 sqlite3DbFree(db, zMaster);
57103 sqlite3DbFree(db, zMaster);
57107 /* Sync all the db files involved in the transaction. The same call
57117 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
57118 Btree *pBt = db->aDb[i].pBt;
57126 sqlite3DbFree(db, zMaster);
57135 sqlite3DbFree(db, zMaster);
57150 for(i=0; i<db->nDb; i++){
57151 Btree *pBt = db->aDb[i].pBt;
57159 sqlite3VtabCommit(db);
57176 static void checkActiveVdbeCnt(sqlite3 *db){
57180 p = db->pVdbe;
57188 assert( cnt==db->activeVdbeCnt );
57189 assert( nWrite==db->writeVdbeCnt );
57196 ** For every Btree that in database connection db which
57211 static void invalidateCursorsOnModifiedBtrees(sqlite3 *db){
57213 for(i=0; i<db->nDb; i++){
57214 Btree *p = db->aDb[i].pBt;
57232 sqlite3 *const db = p->db;
57238 ** In this case (db->nStatement==0), and there is nothing to do.
57240 if( db->nStatement && p->iStatement ){
57245 assert( db->nStatement>0 );
57246 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
57248 for(i=0; i<db->nDb; i++){
57250 Btree *pBt = db->aDb[i].pBt;
57263 db->nStatement--;
57270 db->nDeferredCons = p->nStmtDefCons;
57280 ** sets the BtShared.db member of each of the BtShared structures, ensuring
57284 ** sqlite3BtreeEnterAll() is invoked to set the BtShared.db variables
57298 sqlite3BtreeEnterAll(p->db);
57315 sqlite3 *db = p->db;
57316 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){
57319 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
57341 sqlite3 *db = p->db;
57359 if( p->db->mallocFailed ){
57366 checkActiveVdbeCnt(db);
57402 invalidateCursorsOnModifiedBtrees(db);
57403 sqlite3RollbackAll(db);
57404 sqlite3CloseSavepoints(db);
57405 db->autoCommit = 1;
57421 if( !sqlite3VtabInSync(db)
57422 && db->autoCommit
57423 && db->writeVdbeCnt==(p->readOnly==0)
57434 rc = vdbeCommit(db, p);
57440 sqlite3RollbackAll(db);
57442 db->nDeferredCons = 0;
57443 sqlite3CommitInternalChanges(db);
57446 sqlite3RollbackAll(db);
57448 db->nStatement = 0;
57455 invalidateCursorsOnModifiedBtrees(db);
57456 sqlite3RollbackAll(db);
57457 sqlite3CloseSavepoints(db);
57458 db->autoCommit = 1;
57479 sqlite3DbFree(db, p->zErrMsg);
57482 invalidateCursorsOnModifiedBtrees(db);
57483 sqlite3RollbackAll(db);
57484 sqlite3CloseSavepoints(db);
57485 db->autoCommit = 1;
57494 sqlite3VdbeSetChanges(db, p->nChange);
57496 sqlite3VdbeSetChanges(db, 0);
57502 if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){
57503 sqlite3ResetInternalSchema(db, 0);
57504 db->flags = (db->flags | SQLITE_InternChanges);
57513 db->activeVdbeCnt--;
57515 db->writeVdbeCnt--;
57517 assert( db->activeVdbeCnt>=db->writeVdbeCnt );
57520 checkActiveVdbeCnt(db);
57521 if( p->db->mallocFailed ){
57526 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
57529 if( db->autoCommit ){
57530 sqlite3ConnectionUnlocked(db);
57533 assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 );
57558 sqlite3 *db;
57559 db = p->db;
57575 sqlite3ValueSetStr(db->pErr,-1,p->zErrMsg,SQLITE_UTF8,SQLITE_TRANSIENT);
57577 db->errCode = p->rc;
57578 sqlite3DbFree(db, p->zErrMsg);
57581 sqlite3Error(db, p->rc, 0);
57583 sqlite3Error(db, SQLITE_OK, 0);
57591 sqlite3Error(db, p->rc, 0);
57592 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
57593 sqlite3DbFree(db, p->zErrMsg);
57626 return p->rc & db->errMask;
57637 assert( (rc & p->db
57668 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
57670 assert( p->db==0 || p->db==db );
57675 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
57676 sqlite3DbFree(db, pSub);
57678 vdbeFreeOpArray(db, p->aOp, p->nOp);
57679 sqlite3DbFree(db, p->aLabel);
57680 sqlite3DbFree(db, p->aColName);
57681 sqlite3DbFree(db, p->zSql);
57682 sqlite3DbFree(db, p->pFree);
57683 sqlite3DbFree(db, p);
57690 sqlite3 *db;
57693 db = p->db;
57697 assert( db->pVdbe==p );
57698 db->pVdbe = p->pNext;
57704 p->db = 0;
57705 sqlite3VdbeDeleteObject(db, p);
57821 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
58097 p = sqlite3DbMallocRaw(pKeyInfo->db, nByte);
58116 pMem->db = pKeyInfo->db;
58146 sqlite3DbFree(p->pKeyInfo->db, p);
58192 mem1.db = pKeyInfo->db;
58285 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
58293 UNUSED_PARAMETER(db);
58397 ** sqlite3_changes() on the database handle 'db'.
58399 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
58400 assert( sqlite3_mutex_held(db->mutex) );
58401 db->nChange = nChange;
58402 db->nTotalChange += nChange;
58423 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
58425 for(p = db->pVdbe; p; p=p->pNext){
58434 return v->db;
58450 sqlite3_value *pRet = sqlite3ValueNew(v->db);
58515 if( p->db==0 ){
58548 sqlite3 *db = v->db;
58554 mutex = v->db->mutex;
58558 rc = sqlite3ApiExit(db, rc);
58578 sqlite3_mutex_enter(v->db->mutex);
58581 assert( (rc & (v->db->errMask))==rc );
58582 rc = sqlite3ApiExit(v->db, rc);
58583 sqlite3_mutex_leave(v->db->mutex);
58596 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
58685 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58689 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58693 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58699 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58705 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58709 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58713 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58722 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58732 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58741 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58750 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58755 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58759 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58772 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58780 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
58783 pCtx->s.db->mallocFailed = 1;
58790 static int doWalCallbacks(sqlite3 *db){
58794 for(i=0; i<db->nDb; i++){
58795 Btree *pBt = db->aDb[i].pBt;
58798 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
58799 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
58817 sqlite3 *db;
58831 db = p->db;
58832 if( db->mallocFailed ){
58847 if( db->activeVdbeCnt==0 ){
58848 db->u1.isInterrupted = 0;
58851 assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 );
58854 if( db->xProfile && !db->init.busy ){
58855 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
58859 db->activeVdbeCnt++;
58860 if( p->readOnly==0 ) db->writeVdbeCnt++;
58875 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
58877 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
58878 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
58884 p->rc = doWalCallbacks(db);
58890 db->errCode = rc;
58891 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
58911 rc = db->errCode = p->rc;
58913 return (rc&db->errMask);
58926 sqlite3 *db; /* The database connection */
58931 db = v->db;
58932 sqlite3_mutex_enter(db->mutex);
58939 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
58948 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
58949 sqlite3DbFree(db, v->zErrMsg);
58950 if( !db->mallocFailed ){
58951 v->zErrMsg = sqlite3DbStrDup(db, zErr);
58958 rc = sqlite3ApiExit(db, rc);
58959 sqlite3_mutex_leave(db->mutex);
58984 return p->s.db;
59017 assert( sqlite3_mutex_held(p->s.db->mutex) );
59044 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
59067 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
59072 pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
59144 sqlite3_mutex_enter(pVm->db->mutex);
59165 if( pVm && ALWAYS(pVm->db) ){
59166 sqlite3_mutex_enter(pVm->db->mutex);
59167 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
59201 p->rc = sqlite3ApiExit(p->db, p->rc);
59202 sqlite3_mutex_leave(p->db->mutex);
59304 sqlite3 *db = p->db;
59306 assert( db!=0 );
59310 sqlite3_mutex_enter(db->mutex);
59311 assert( db->mallocFailed==0 );
59316 if( db->mallocFailed ){
59317 db->mallocFailed = 0;
59320 sqlite3_mutex_leave(db->mutex);
59429 ** The error code stored in database p->db is overwritten with the return
59437 sqlite3_mutex_enter(p->db->mutex);
59439 sqlite3Error(p->db, SQLITE_MISUSE, 0);
59440 sqlite3_mutex_leave(p->db->mutex);
59446 sqlite3Error(p->db, SQLITE_RANGE, 0);
59447 sqlite3_mutex_leave(p->db->mutex);
59454 sqlite3Error(p->db, SQLITE_OK, 0);
59494 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
59496 sqlite3Error(p->db, rc, 0);
59497 rc = sqlite3ApiExit(p->db, rc);
59499 sqlite3_mutex_leave(p->db->mutex);
59525 sqlite3_mutex_leave(p->db->mutex);
59538 sqlite3_mutex_leave(p->db->mutex);
59547 sqlite3_mutex_leave(p->db->mutex);
59608 sqlite3_mutex_leave(p->db->mutex);
59631 sqlite3_mutex_enter(p->db->mutex);
59644 sqlite3_mutex_leave(p->db->mutex);
59695 assert( pTo->db==pFrom->db );
59697 sqlite3_mutex_enter(pTo->db->mutex);
59701 sqlite3_mutex_leave(pTo->db->mutex);
59741 return pStmt ? ((Vdbe*)pStmt)->db : 0;
59845 sqlite3 *db; /* The database connection */
59855 db = p->db;
59857 db->aLimit[SQLITE_LIMIT_LENGTH]);
59858 out.db = db;
59893 u8 enc = ENC(db);
59897 utf8.db = db;
60489 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
60501 ** assert( checkSavepointCount(db) );
60503 static int checkSavepointCount(sqlite3 *db){
60506 for(p=db->pSavepoint; p; p=p->pNext) n++;
60507 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
60518 sqlite3 *db = p->db;
60519 sqlite3DbFree(db, p->zErrMsg);
60520 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
60564 sqlite3 *db = p->db; /* The database */
60566 u8 encoding = ENC(db); /* The database encoding */
60724 Db *pDb;
60738 Db *pDb;
60867 Db *pDb;
60994 db->busyHandler.nBusy = 0;
60998 checkProgress = db->xProgress!=0;
61002 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
61014 if( db->mallocFailed ) goto no_mem;
61041 sqlite3_interrupt(db);
61054 if( db->nProgressOps==nProgressOps ){
61056 prc = db->xProgress(db->pProgressArg);
61246 sqlite3VdbeSetChanges(db, p->nChange);
61266 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
61279 assert( rc==SQLITE_OK || db->nDeferredCons>0 );
61340 sqlite3DbFree(db, pOp->p4.z);
61347 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
61513 assert( db->flags&SQLITE_CountRows );
61533 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
61556 if( db->mallocFailed ) goto no_mem;
61594 if( u.ae.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
61808 u.ag.ctx.s.db = db;
61827 if( db->mallocFailed ){
61848 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ag.ctx.s));
61994 assert( pIn1->flags & MEM_Str || db->mallocFailed );
62014 assert( pIn1->flags & MEM_Str || db->mallocFailed );
62195 if( db->mallocFailed ) goto no_mem;
62585 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
62586 if( u.am.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
62671 u.am.sMem.db = 0;
62899 if( u.ao.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
62985 assert( db->pSavepoint==0 || db->autoCommit==0 );
62987 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
62988 assert( checkSavepointCount(db) );
62991 if( db->writeVdbeCnt>0 ){
62995 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
63002 u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
63009 if( db->autoCommit ){
63010 db->autoCommit = 0;
63011 db->isTransactionSavepoint = 1;
63013 db->nSavepoint++;
63017 u.aq.pNew->pNext = db->pSavepoint;
63018 db->pSavepoint = u.aq.pNew;
63019 u.aq.pNew->nDeferredCons = db->nDeferredCons;
63028 u.aq.pSavepoint = db->pSavepoint;
63035 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.aq.zName);
63038 db->writeVdbeCnt>0 || (u.aq.p1==SAVEPOINT_ROLLBACK && db->activeVdbeCnt>1)
63044 sqlite3SetString(&p->zErrMsg, db,
63055 int isTransaction = u.aq.pSavepoint->pNext==0 && db->isTransactionSavepoint;
63060 db->autoCommit = 1;
63063 db->autoCommit = 0;
63067 db->isTransactionSavepoint = 0;
63070 u.aq.iSavepoint = db->nSavepoint - u.aq.iSavepoint - 1;
63071 for(u.aq.ii=0; u.aq.ii<db->nDb; u.aq.ii++){
63072 rc = sqlite3BtreeSavepoint(db->aDb[u.aq.ii].pBt, u.aq.p1, u.aq.iSavepoint);
63077 if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
63078 sqlite3ExpirePreparedStatements(db);
63079 sqlite3ResetInternalSchema(db, 0);
63080 db->flags = (db->flags | SQLITE_InternChanges);
63086 while( db->pSavepoint!=u.aq.pSavepoint ){
63087 u.aq.pTmp = db->pSavepoint;
63088 db->pSavepoint = u.aq.pTmp->pNext;
63089 sqlite3DbFree(db, u.aq.pTmp);
63090 db->nSavepoint--;
63098 assert( u.aq.pSavepoint==db->pSavepoint );
63099 db->pSavepoint = u.aq.pSavepoint->pNext;
63100 sqlite3DbFree(db, u.aq.pSavepoint);
63102 db->nSavepoint--;
63105 db->nDeferredCons = u.aq.pSavepoint->nDeferredCons;
63131 u.ar.turnOnAC = u.ar.desiredAutoCommit && !db->autoCommit;
63134 assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
63136 if( u.ar.turnOnAC && u.ar.iRollback && db->activeVdbeCnt>1 ){
63141 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
63144 }else if( u.ar.turnOnAC && !u.ar.iRollback && db->writeVdbeCnt>0 ){
63148 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
63151 }else if( u.ar.desiredAutoCommit!=db->autoCommit ){
63154 sqlite3RollbackAll(db);
63155 db->autoCommit = 1;
63159 db->autoCommit = (u8)u.ar.desiredAutoCommit;
63162 db->autoCommit = (u8)(1-u.ar.desiredAutoCommit);
63167 assert( db->nStatement==0 );
63168 sqlite3CloseSavepoints(db);
63176 sqlite3SetString(&p->zErrMsg, db,
63222 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63224 u.as.pBt = db->aDb[pOp->p1].pBt;
63238 && (db->autoCommit==0 || db->activeVdbeCnt>1)
63242 assert( db->nStatement>=0 && db->nSavepoint>=0 );
63243 db->nStatement++;
63244 p->iStatement = db->nSavepoint + db->nStatement;
63251 p->nStmtDefCons = db->nDeferredCons;
63279 assert( u.at.iDb>=0 && u.at.iDb<db->nDb );
63280 assert( db->aDb[u.at.iDb].pBt!=0 );
63283 sqlite3BtreeGetMeta(db->aDb[u.at.iDb].pBt, u.at.iCookie, (u32 *)&u.at.iMeta);
63300 Db *pDb;
63303 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63305 u.au.pDb = &db->aDb[pOp->p1];
63314 db->flags |= SQLITE_InternChanges;
63322 sqlite3ExpirePreparedStatements(db);
63349 assert( pOp->p1>=0 && pOp->p1<db->nDb );
63351 u.av.pBt = db->aDb[pOp->p1].pBt;
63358 sqlite3DbFree(db, p->zErrMsg);
63359 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
63373 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){
63374 sqlite3ResetInternalSchema(db, pOp->p1);
63377 sqlite3ExpirePreparedStatements(db);
63442 Db *pDb;
63454 assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
63456 u.aw.pDb = &db->aDb[u.aw.iDb];
63486 u.aw.pKeyInfo->enc = ENC(p->db);
63559 rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt,
63579 u.ax.pCx->pKeyInfo->enc = ENC(p->db);
64234 u.be.v = db->lastRowid;
64346 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = u.bf.iKey;
64369 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
64370 u.bf.zDb = db->aDb[u.bf.pC->iDb].zName;
64374 db->xUpdateCallback(db->pUpdateArg, u.bf.op, u.bf.zDb, u.bf.zTbl, u.bf.iKey);
64415 if( db->xUpdateCallback && pOp->p4.z ){
64437 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
64438 const char *zDb = db->aDb[u.bg.pC->iDb].zName;
64440 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bg.iKey);
64454 sqlite3VdbeSetChanges(db, p->nChange);
64516 if( u.bh.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
64523 if( u.bh.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
64871 rc = sqlite3VdbeIdxRowid(db, u.bp.pCrsr, &u.bp.rowid);
64978 for(u.br.pVdbe=db->pVdbe; u.br.pVdbe; u.br.pVdbe = u.br.pVdbe->pNext){
64984 u.br.iCnt = db->activeVdbeCnt;
64994 rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved);
64999 sqlite3RootPageMoved(&db->aDb[u.br.iDb], u.br.iMoved, pOp->p1);
65033 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0)
65073 Db *pDb;
65077 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65079 u.bt.pDb = &db->aDb[pOp->p1];
65113 assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb );
65132 ** will not be reloaded becuase the db->init.busy flag is set. This
65136 assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) );
65137 sqlite3BtreeEnterAll(db);
65138 if( pOp->p2 || DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded) ){
65140 u.bu.initData.db = db;
65143 u.bu.zSql = sqlite3MPrintf(db,
65145 db->aDb[u.bu.iDb].zName, u.bu.zMaster, pOp->p4.z);
65149 assert( db->init.busy==0 );
65150 db->init.busy = 1;
65152 assert( !db->mallocFailed );
65153 rc = sqlite3_exec(db, u.bu.zSql, sqlite3InitCallback, &u.bu.initData, 0);
65155 sqlite3DbFree(db, u.bu.zSql);
65156 db->init.busy = 0;
65159 sqlite3BtreeLeaveAll(db);
65174 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65175 rc = sqlite3AnalysisLoad(db, pOp->p1);
65188 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
65200 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
65212 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
65250 u.bv.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.bv.nRoot+1) );
65261 assert( pOp->p5<db->nDb );
65263 u.bv.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bv.aRoot, u.bv.nRoot,
65265 sqlite3DbFree(db, u.bv.aRoot);
65434 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
65436 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
65454 u.by.pFrame = sqlite3DbMallocZero(db, u.by.nByte);
65477 u.by.pMem->db = db;
65488 u.by.pFrame->lastRowid = db->lastRowid;
65538 db->nDeferredCons += pOp->p2;
65558 if( db->nDeferredCons==0 ) pc = pOp->p2-1;
65688 u.cb.ctx.s.db = db;
65699 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s));
65727 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem));
65744 rc = sqlite3Checkpoint(db, pOp->p1);
65779 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65800 u.cd.pBt = db->aDb[pOp->p1].pBt;
65822 if( !db->autoCommit || db->activeVdbeCnt>1 ){
65824 sqlite3SetString(&p->zErrMsg, db,
65881 rc = sqlite3RunVacuum(&p->zErrMsg, db);
65898 assert( pOp->p1>=0 && pOp->p1<db->nDb );
65900 u.ce.pBt = db->aDb[pOp->p1].pBt;
65921 sqlite3ExpirePreparedStatements(db);
65945 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
65947 assert( p1>=0 && p1<db->nDb );
65950 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
65953 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
65975 rc = sqlite3VtabBegin(db, u.cf.pVTab);
65988 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
66001 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
66039 db->mallocFailed = 1;
66309 db->lastRowid = u.cl.rowid;
66323 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
66342 pBt = db->aDb[pOp->p1].pBt;
66367 if( db->xTrace ){
66369 db->xTrace(db->pTraceArg, z);
66370 sqlite3DbFree(db, z);
66373 if( (db->flags & SQLITE_SqlTrace)!=0 ){
66451 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
66453 if( resetSchemaOnFault ) sqlite3ResetInternalSchema(db, 0);
66466 sqlite3SetString(&p->zErrMsg, db, "string or blob too big");
66473 db->mallocFailed = 1;
66474 sqlite3SetString(&p->zErrMsg, db, "out of memory");
66483 if( db->mallocFailed ) rc = SQLITE_NOMEM;
66485 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
66493 assert( db->u1.isInterrupted );
66496 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
66531 sqlite3 *db; /* The associated database */
66568 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
66590 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
66593 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
66608 sqlite3* db, /* The database connection */
66620 ** db/table/row entry. The reason for using a vdbe program instead
66661 sqlite3_mutex_enter(db->mutex);
66663 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
66665 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
66670 pParse->db = db;
66671 sqlite3DbFree(db, zErr);
66674 sqlite3BtreeEnterAll(db);
66688 sqlite3DbFree(db, zErr);
66693 sqlite3BtreeLeaveAll(db);
66704 sqlite3DbFree(db, zErr);
66705 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
66707 sqlite3BtreeLeaveAll(db);
66719 if( db->flags&SQLITE_ForeignKeys ){
66744 sqlite3DbFree(db, zErr);
66745 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
66747 sqlite3BtreeLeaveAll(db);
66752 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
66753 assert( pBlob->pStmt || db->mallocFailed );
66756 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
66797 if( !db->mallocFailed ){
66804 pBlob->db = db;
66805 sqlite3BtreeLeaveAll(db);
66806 if( db->mallocFailed ){
66814 if( rc==SQLITE_OK && db->mallocFailed==0 ){
66818 sqlite3DbFree(db, pBlob);
66820 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
66821 sqlite3DbFree(db, zErr);
66822 sqlite3StackFree(db, pParse);
66823 rc = sqlite3ApiExit(db, rc);
66824 sqlite3_mutex_leave(db->mutex);
66835 sqlite3 *db;
66838 db = p->db;
66839 sqlite3_mutex_enter(db->mutex);
66841 sqlite3DbFree(db, p);
66842 sqlite3_mutex_leave(db->mutex);
66862 sqlite3 *db;
66865 db = p->db;
66866 sqlite3_mutex_enter(db->mutex);
66872 sqlite3Error(db, SQLITE_ERROR, 0);
66882 assert( db == v->db );
66890 db->errCode = rc;
66894 rc = sqlite3ApiExit(db, rc);
66895 sqlite3_mutex_leave(db->mutex);
66937 sqlite3 *db;
66940 db = p->db;
66941 sqlite3_mutex_enter(db->mutex);
66952 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
66953 sqlite3DbFree(db, zErr);
66958 rc = sqlite3ApiExit(db, rc);
66960 sqlite3_mutex_leave(db->mutex);
67658 sqlite3 *db; /* The database connection */
67664 db = pParse->db;
67666 pDup = sqlite3ExprDup(db, pOrig, 0);
67674 pDup = sqlite3ExprDup(db, pOrig, 0);
67680 pDup = sqlite3ExprDup(db, pOrig, 0);
67685 pDup->u.zToken = sqlite3DbStrDup(db, zToken);
67697 sqlite3ExprDelete(db, pExpr);
67699 sqlite3DbFree(db, pDup);
67708 ** pExpr->iDb Set the index in db->aDb[] of the database X
67740 sqlite3 *db = pParse->db; /* The database connection */
67769 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
67780 if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
67983 sqlite3ExprDelete(db, pExpr->pLeft);
67985 sqlite3ExprDelete(db, pExpr->pRight);
68010 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
68011 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
68124 u8 enc = ENC(pParse->db); /* The database encoding */
68130 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
68132 pDef = sqlite3FindFunction(pParse->db, zId, nId, -1, enc, 0);
68209 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
68271 sqlite3 *db; /* Database connection */
68273 u8 savedSuppErr; /* Saved value of db->suppressErr */
68286 db = pParse->db;
68287 savedSuppErr = db->suppressErr;
68288 db->suppressErr = 1;
68290 db->suppressErr = savedSuppErr;
68343 sqlite3 *db;
68348 db = pParse->db;
68350 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
68381 pDup = sqlite3ExprDup(db, pE, 0);
68382 if( !db->mallocFailed ){
68386 sqlite3ExprDelete(db, pDup);
68392 sqlite3ExprDelete(db, pE);
68393 pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0);
68433 sqlite3 *db = pParse->db;
68437 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
68439 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
68536 sqlite3 *db; /* Database connection */
68545 db = pParse->db;
68557 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
68604 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
68655 if( db->mallocFailed ){
68665 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
68887 sqlite3 *db = pParse->db;
68888 zColl = sqlite3NameFromToken(db, pCollName);
68891 sqlite3DbFree(db, zColl);
68915 sqlite3 *db = pParse->db;
68917 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
69076 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
69186 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
69201 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
69233 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
69240 return sqlite3ExprAlloc(db, op, &x, 0);
69250 sqlite3 *db,
69256 assert( db->mallocFailed );
69257 sqlite3ExprDelete(db, pLeft);
69258 sqlite3ExprDelete(db, pRight);
69282 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
69292 Expr *p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
69293 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
69304 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
69310 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
69311 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
69322 sqlite3 *db = pParse->db;
69324 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
69326 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
69352 sqlite3 *db = pParse->db;
69372 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
69373 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
69374 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
69376 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
69403 db,
69408 if( !db->mallocFailed ){
69414 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
69422 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
69425 sqlite3ExprDelete(db, p->pLeft);
69426 sqlite3ExprDelete(db, p->pRight);
69428 sqlite3DbFree(db, p->u.zToken);
69431 sqlite3SelectDelete(db, p->x.pSelect);
69433 sqlite3ExprListDelete(db, p->x.pList);
69437 sqlite3DbFree(db, p);
69550 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
69564 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
69605 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
69607 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
69615 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
69616 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
69624 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
69625 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
69651 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
69652 return exprDup(db, p, flags, 0);
69654 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
69659 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
69663 pNew->a = pItem = sqlite3DbMallocRaw(db, p->nExpr*sizeof(p->a[0]) );
69665 sqlite3DbFree(db, pNew);
69671 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
69672 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
69673 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
69690 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
69696 pNew = sqlite3DbMallocRaw(db, nByte );
69703 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
69704 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
69705 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
69709 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
69716 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
69717 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
69718 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
69723 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
69727 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
69730 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
69732 sqlite3DbFree(db, pNew);
69738 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
69743 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
69746 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
69748 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
69749 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
69750 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
69751 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
69752 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
69753 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
69755 pNew->pPrior = sqlite3SelectDup(db, p->pPrior, flags);
69756 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
69757 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
69768 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
69788 sqlite3 *db = pParse->db;
69790 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
69799 a = sqlite3DbRealloc(db, pList->a, n*sizeof(pList->a[0]));
69804 pList->nAlloc = sqlite3DbMallocSize(db, a)/sizeof(a[0]);
69816 sqlite3ExprDelete(db, pExpr);
69817 sqlite3ExprListDelete(db, pList);
69826 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
69835 assert( pList!=0 || pParse->db->mallocFailed!=0 );
69841 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
69851 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
69859 sqlite3 *db = pParse->db;
69860 assert( pList!=0 || db->mallocFailed!=0 );
69864 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
69865 sqlite3DbFree(db, pItem->zSpan);
69866 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
69880 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
69891 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
69898 sqlite3ExprDelete(db, pItem->pExpr);
69899 sqlite3DbFree(db, pItem->zName);
69900 sqlite3DbFree(db, pItem->zSpan);
69902 sqlite3DbFree(db, pList->a);
69903 db, pList);
70252 sqlite3 *db = pParse->db; /* Database connection */
70260 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
70297 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
70407 assert( testAddr>0 || pParse->db->mallocFailed );
70413 pParse->db, "EXECUTE %s%s SUBQUERY %d", testAddr?"":"CORRELATED ",
70563 sqlite3ExprDelete(pParse->db, pSel->pLimit);
70816 if( pParse->db->flags & SQLITE_ColumnCache ) return;
71076 sqlite3 *db = pParse->db; /* The database connection */
71080 assert( pParse->db->mallocFailed );
71343 u8 enc = ENC(db); /* The text encoding used by this database */
71358 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
71406 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
71408 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
71420 if( !pColl ) pColl = db->pDfltColl;
71629 assert( db->mallocFailed || pParse->nErr>0
71700 assert( pParse->pVdbe || pParse->db->mallocFailed );
71865 if( (pParse->db->flags & SQLITE_FactorOutConst)!=0 ) return;
72300 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
72303 db,
72318 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
72321 db,
72372 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
72430 u8 enc = ENC(pParse->db);
72431 i = addAggInfoFunc(pParse->db, pAggInfo);
72438 pItem->pFunc = sqlite3FindFunction(pParse->db,
72613 sqlite3 *db = sqlite3_context_db_handle(context);
72642 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
72669 sqlite3 *db = sqlite3_context_db_handle(context);
72690 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
72694 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
72697 sqlite3DbFree(db, zOutput);
72701 sqlite3DbFree(db, zParent);
72705 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
72707 sqlite3DbFree(db, zOutput);
72733 sqlite3 *db = sqlite3_context_db_handle(context);
72781 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
72826 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
72829 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
72831 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
72832 sqlite3DbFree(db, zWhere);
72848 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
72863 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
72865 /* If the table is not located in the temp-db (in which case NULL is
72867 ** that is not part of the temp-db schema, add a clause to the WHERE
72871 sqlite3 *db = pParse->db;
72874 zWhere = whereOrName(db, zWhere, pTrig->zName);
72879 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
72880 sqlite3DbFree(pParse->db, zWhere);
72904 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
72905 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
72911 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
72921 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
72948 sqlite3 *db = pParse->db; /* Database connection */
72956 int savedDbFlags; /* Saved value of db->flags */
72958 savedDbFlags = db->flags;
72959 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
72961 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
72965 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
72966 zDb = db->aDb[iDb].zName;
72967 db->flags |= SQLITE_PreferBuiltin;
72970 zName = sqlite3NameFromToken(db, pName);
72976 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
73014 pVTab = sqlite3GetVTable(db, pTab);
73052 if( db->flags&SQLITE_ForeignKeys ){
73061 sqlite3DbFree(db, zWhere);
73095 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
73113 sqlite3DbFree(db, zWhere);
73118 if( db->flags&SQLITE_ForeignKeys ){
73133 sqlite3SrcListDelete(db, pSrc);
73134 sqlite3DbFree(db, zName);
73135 db->flags = savedDbFlags;
73181 sqlite3 *db; /* The database connection; */
73183 db = pParse->db;
73184 if( pParse->nErr || db->mallocFailed ) return;
73188 assert( sqlite3BtreeHoldsAllMutexes(db) );
73189 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
73190 zDb = db->aDb[iDb].zName;
73194 pTab = sqlite3FindTable(db, zTab, zDb);
73224 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
73240 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
73241 db->mallocFailed = 1;
73252 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
73255 int savedDbFlags = db->flags;
73259 db->flags |= SQLITE_PreferBuiltin;
73267 sqlite3DbFree(db, zCol);
73268 db->flags = savedDbFlags;
73303 sqlite3 *db = pParse->db;
73307 assert( sqlite3BtreeHoldsAllMutexes(db) );
73308 if( db->mallocFailed ) goto exit_begin_add_column;
73326 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73335 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
73343 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
73344 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
73346 db->mallocFailed = 1;
73352 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
73358 pNew->pSchema = db->aDb[iDb].pSchema;
73369 sqlite3SrcListDelete(db, pSrc);
73427 sqlite3 *db = pParse->db;
73428 Db *pDb;
73431 assert( sqlite3BtreeHoldsAllMutexes(db) );
73432 assert( sqlite3VdbeDb(v)==db );
73433 pDb = &db->aDb[iDb];
73438 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
73483 sqlite3 *db = pParse->db; /* Database handle */
73521 assert( sqlite3BtreeHoldsAllMutexes(db) );
73522 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73526 db->aDb[iDb].zName ) ){
73545 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
73648 if( db->mallocFailed ){
73743 sqlite3 *db = pParse->db;
73744 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
73770 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
73771 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
73793 sqlite3 *db = pParse->db;
73802 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
73810 for(i=0; i<db->nDb; i++){
73816 iDb = sqlite3FindDb(db, pName1);
73820 z = sqlite3NameFromToken(db, pName1);
73823 sqlite3DbFree(db, z);
73833 zDb = db->aDb[iDb].zName;
73834 z = sqlite3NameFromToken(db, pTableName);
73837 sqlite3DbFree(db, z);
73852 sqlite3 *db;
73881 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
73886 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
73910 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
73917 sqlite3DbFree(db, p->u.z);
73920 sqlite3DbFree(db, pIdx->aSample);
73923 UNUSED_PARAMETER(db);
73944 ** If an OOM error occurs, this function always sets db->mallocFailed.
73948 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
73954 assert( iDb>=0 && iDb<db->nDb );
73955 assert( db->aDb[iDb].pBt!=0 );
73956 assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
73959 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
73962 sqlite3DeleteIndexSamples(db, pIdx);
73967 sInfo.db = db;
73968 sInfo.zDatabase = db->aDb[iDb].zName;
73969 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
73974 zSql = sqlite3MPrintf(db,
73979 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
73980 sqlite3DbFree(db, zSql);
73986 if( rc==SQLITE_OK && !sqlite3FindTable(db, "sqlite_stat2", sInfo.zDatabase) ){
73992 zSql = sqlite3MPrintf(db,
73997 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
73998 sqlite3DbFree(db, zSql);
74004 Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
74014 db->mallocFailed = 1;
74042 db->mallocFailed = 1;
74057 db->mallocFailed = 1;
74135 sqlite3 *db = sqlite3_context_db_handle(context);
74138 Db *aNew;
74154 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
74155 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
74156 db->aLimit[SQLITE_LIMIT_ATTACHED]
74160 if( !db->autoCommit ){
74161 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
74164 for(i=0; i<db->nDb; i++){
74165 char *z = db->aDb[i].zName;
74168 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
74173 /* Allocate the new entry in the db->aDb[] array and initialise the schema
74176 if( db->aDb==db->aDbStatic ){
74177 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
74179 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
74181 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
74184 db->aDb = aNew;
74185 aNew = &db->aDb[db->nDb];
74192 rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
74193 db->openFlags | SQLITE_OPEN_MAIN_DB);
74194 db->nDb++;
74197 zErrDyn = sqlite3MPrintf(db, "database is already attached");
74200 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
74203 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
74204 zErrDyn = sqlite3MPrintf(db,
74209 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
74211 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
74214 aNew->zName = sqlite3DbStrDup(db, zName);
74230 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
74238 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
74243 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
74244 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
74252 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
74256 sqlite3BtreeEnterAll(db);
74257 rc = sqlite3Init(db, &zErrDyn);
74258 sqlite3BtreeLeaveAll(db);
74261 int iDb = db->nDb - 1;
74263 if( db->aDb[iDb].pBt ){
74264 sqlite3BtreeClose(db->aDb[iDb].pBt);
74265 db->aDb[iDb].pBt = 0;
74266 db->aDb[iDb].pSchema = 0;
74268 sqlite3ResetInternalSchema(db, 0);
74269 db->nDb = iDb;
74271 db->mallocFailed = 1;
74272 sqlite3DbFree(db, zErrDyn);
74273 zErrDyn = sqlite3MPrintf(db, "out of memory");
74275 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
74286 sqlite3DbFree(db, zErrDyn);
74305 sqlite3 *db = sqlite3_context_db_handle(context);
74307 Db *pDb = 0;
74313 for(i=0; i<db->nDb; i++){
74314 pDb = &db->aDb[i];
74319 if( i>=db->nDb ){
74327 if( !db->autoCommit ){
74340 sqlite3ResetInternalSchema(db, 0);
74363 sqlite3* db = pParse->db;
74398 assert( v || db->mallocFailed );
74413 sqlite3ExprDelete(db, pFilename);
74414 sqlite3ExprDelete(db, pDbname);
74415 sqlite3ExprDelete(db, pKey);
74477 sqlite3 *db;
74480 db = pParse->db;
74481 assert( db->nDb>iDb );
74483 pFix->zDb = db->aDb[iDb].zName;
74515 pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb);
74677 sqlite3 *db,
74681 sqlite3_mutex_enter(db->mutex);
74682 db->xAuth = xAuth;
74683 db->pAuthArg = pArg;
74684 sqlite3ExpirePreparedStatements(db);
74685 sqlite3_mutex_leave(db->mutex);
74713 sqlite3 *db = pParse->db; /* Database handle */
74714 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
74717 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
74719 if( db->nDb>2 || iDb!=0 ){
74746 sqlite3 *db = pParse->db;
74753 if( db->xAuth==0 ) return;
74754 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
74785 assert( iDb>=0 && iDb<db->nDb );
74804 sqlite3 *db = pParse->db;
74810 if( db->init.busy || IN_DECLARE_VTAB ){
74814 if( db->xAuth==0 ){
74817 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
74938 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
74947 pToplevel->db->mallocFailed = 1;
74984 sqlite3 *db;
74987 db = pParse->db;
74988 if( db->mallocFailed ) return;
75011 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
75015 if( db->init.busy==0 ){
75023 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
75048 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
75050 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
75089 sqlite3 *db = pParse->db;
75096 zSql = sqlite3VMPrintf(db, zFormat, ap);
75105 sqlite3DbFree(db, zErrMsg);
75106 sqlite3DbFree(db, zSql);
75123 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
75129 for(i=OMIT_TEMPDB; i<db->nDb; i++){
75131 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
75132 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
75162 p = sqlite3FindTable(pParse->db, zName, zDbase);
75187 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
75191 for(i=OMIT_TEMPDB; i<db->nDb; i++){
75193 Schema *pSchema = db->aDb[j].pSchema;
75195 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
75205 static void freeIndex(sqlite3 *db, Index *p){
75207 sqlite3DeleteIndexSamples(db, p);
75209 sqlite3DbFree(db, p->zColAff);
75210 sqlite3DbFree(db, p);
75219 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
75222 Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
75239 freeIndex(db, pIndex);
75241 db->flags |= SQLITE_InternChanges;
75255 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
75257 assert( iDb>=0 && iDb<db->nDb );
75260 sqlite3BtreeEnterAll(db);
75262 for(i=iDb; i<db->nDb; i++){
75263 Db *pDb = &db->aDb[i];
75271 db->flags &= ~SQLITE_InternChanges;
75272 sqlite3VtabUnlockList(db);
75273 sqlite3BtreeLeaveAll(db);
75281 for(i=j=2; i<db->nDb; i++){
75282 struct Db *pDb = &db->aDb[i];
75284 sqlite3DbFree(db, pDb->zName);
75289 db->aDb[j] = db->aDb[i];
75293 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
75294 db->nDb = j;
75295 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
75296 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
75297 sqlite3DbFree(db, db->aDb);
75298 db->aDb = db->aDbStatic;
75305 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
75306 db->flags &= ~SQLITE_InternChanges;
75313 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
75319 sqlite3DbFree(db, pCol->zName);
75320 sqlite3ExprDelete(db, pCol->pDflt);
75321 sqlite3DbFree(db, pCol->zDflt);
75322 sqlite3DbFree(db, pCol->zType);
75323 sqlite3DbFree(db, pCol->zColl);
75325 sqlite3DbFree(db, pTable->aCol);
75338 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
75345 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
75351 if( !db || db->pnBytesFreed==0 ){
75358 freeIndex(db, pIndex);
75362 sqlite3FkDelete(db, pTable);
75366 sqliteDeleteColumnNames(db, pTable);
75367 sqlite3DbFree(db, pTable->zName);
75368 sqlite3DbFree(db, pTable->zColAff);
75369 sqlite3SelectDelete(db, pTable->pSelect);
75371 sqlite3ExprDelete(db, pTable->pCheck);
75374 sqlite3VtabClear(db, pTable);
75376 sqlite3DbFree(db, pTable);
75383 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
75385 Db *pDb;
75387 assert( db!=0 );
75388 assert( iDb>=0 && iDb<db->nDb );
75391 pDb = &db->aDb[iDb];
75394 sqlite3DeleteTable(db, p);
75395 db->flags |= SQLITE_InternChanges;
75411 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
75414 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
75438 ** of a database ("main", "temp" or the name of an attached db). This
75439 ** function returns the index of the named database in db->aDb[], or
75440 ** -1 if the named db cannot be found.
75442 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
75445 Db *pDb;
75447 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
75459 ** "temp" or the name of an attached db). This routine returns the
75460 ** index of the named database in db->aDb[], or -1 if the named db
75463 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
75466 zName = sqlite3NameFromToken(db, pName);
75467 i = sqlite3FindDbName(db, zName);
75468 sqlite3DbFree(db, zName);
75495 sqlite3 *db = pParse->db;
75498 if( db->init.busy ) {
75504 iDb = sqlite3FindDb(db, pName1);
75511 assert( db->init.iDb==0 || db->init.busy );
75512 iDb = db->init.iDb;
75526 if( !pParse->db->init.busy && pParse->nested==0
75527 && (pParse->db->flags & SQLITE_WriteSchema)==0
75562 sqlite3 *db = pParse->db;
75595 zName = sqlite3NameFromToken(db, pName);
75600 if( db->init.iDb==1 ) isTemp = 1;
75605 char *zDb = db->aDb[iDb].zName;
75636 char *zDb = db->aDb[iDb].zName;
75640 pTable = sqlite3FindTable(db, zName, zDb);
75647 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
75653 pTable = sqlite3DbMallocZero(db, sizeof(Table));
75655 db->mallocFailed = 1;
75662 pTable->pSchema = db->aDb[iDb].pSchema;
75686 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
75707 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
75711 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
75745 sqlite3DbFree(db, zName);
75775 sqlite3 *db = pParse->db;
75778 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
75783 z = sqlite3NameFromToken(db, pName);
75788 sqlite3DbFree(db, z);
75794 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
75796 sqlite3DbFree(db, z);
75904 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
75921 sqlite3 *db = pParse->db;
75933 sqlite3ExprDelete(db, pCol->pDflt);
75934 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
75935 sqlite3DbFree(db, pCol->zDflt);
75936 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
75940 sqlite3ExprDelete(db, pSpan->pExpr);
76018 sqlite3ExprListDelete(pParse->db, pList);
76029 sqlite3 *db = pParse->db;
76033 pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr);
76037 sqlite3ExprDelete(db, pCheckExpr);
76049 sqlite3 *db;
76053 db = pParse->db;
76054 zColl = sqlite3NameFromToken(db, pToken);
76072 sqlite3DbFree(db, zColl);
76097 sqlite3 *db = pParse->db;
76098 u8 enc = ENC(db);
76099 u8 initbusy = db->init.busy;
76102 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
76104 pColl = sqlite3GetCollSeq(db, enc, pColl, zName);
76132 sqlite3 *db = pParse->db;
76134 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
76196 static char *createTableStmt(sqlite3 *db, Table *p){
76218 db->mallocFailed = 1;
76269 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
76287 sqlite3 *db = pParse->db;
76290 if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
76296 assert( !db->init.busy || !pSelect );
76298 iDb = sqlite3SchemaToIndex(db, p->pSchema);
76322 /* If the db->init.busy is 1 it means we are reading the SQL off the
76325 ** for the table from the db->init.newTnum field. (The page number
76328 if( db->init.busy ){
76329 p->tnum = db->init.newTnum;
76338 if( !db->init.busy ){
76397 sqlite3DeleteTable(db, pSelTab);
76403 zStmt = createTableStmt(db, p);
76406 zStmt = sqlite3MPrintf(db,
76419 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
76427 sqlite3DbFree(db, zStmt);
76435 Db *pDb = &db->aDb[iDb];
76447 sqlite3MPrintf(db, "tbl_name='%q'",p->zName), P4_DYNAMIC);
76453 if( db->init.busy ){
76460 db->mallocFailed = 1;
76464 db->nTable++;
76465 db->flags |= SQLITE_InternChanges;
76502 sqlite3 *db = pParse->db;
76506 sqlite3SelectDelete(db, pSelect);
76512 sqlite3SelectDelete(db, pSelect);
76516 iDb = sqlite3SchemaToIndex(db, p->pSchema);
76520 sqlite3SelectDelete(db, pSelect);
76529 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
76530 sqlite3SelectDelete(db, pSelect);
76531 if( db->mallocFailed ){
76534 if( !db->init.busy ){
76569 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
76616 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
76618 u8 enableLookaside = db->lookaside.bEnabled;
76622 db->lookaside.bEnabled = 0;
76624 xAuth = db->xAuth;
76625 db->xAuth = 0;
76627 db->xAuth = xAuth;
76631 db->lookaside.bEnabled = enableLookaside;
76639 sqlite3DeleteTable(db, pSelTab);
76645 sqlite3SelectDelete(db, pSel);
76658 static void sqliteViewResetAll(sqlite3 *db, int idx){
76660 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
76661 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
76664 sqliteDeleteColumnNames(db, pTab);
76669 DbClearProperty(db, idx, DB_UnresetViews);
76693 SQLITE_PRIVATE void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){
76737 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
76751 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
76793 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
76808 sqlite3 *db = pParse->db;
76811 if( db->mallocFailed ){
76816 if( noErr ) db->suppressErr++;
76819 if( noErr ) db->suppressErr--;
76824 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
76825 assert( iDb>=0 && iDb<db->nDb );
76837 const char *zDb = db->aDb[iDb].zName;
76851 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
76893 Db *pDb = &db->aDb[iDb];
76910 pTrigger->pSchema==db->aDb[1].pSchema );
76941 if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
76960 sqliteViewResetAll(db, iDb);
76963 sqlite3SrcListDelete(db, pName);
76989 sqlite3 *db = pParse->db;
77025 pFKey = sqlite3DbMallocZero(db, nByte );
77074 db->mallocFailed = 1;
77089 sqlite3DbFree(db, pFKey);
77091 sqlite3ExprListDelete(db, pFromCol);
77092 sqlite3ExprListDelete(db, pToCol);
77133 sqlite3 *db = pParse->db; /* The database connection */
77134 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
77138 db->aDb[iDb].zName ) ){
77228 sqlite3 *db = pParse->db;
77229 Db *pDb; /* The specific table containing the indexed database */
77239 if( db->mallocFailed || IN_DECLARE_VTAB ){
77252 ** to search for the table. 'Fix' the table name to this db
77264 if( !db->init.busy ){
77266 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
77281 if( !pTab || db->mallocFailed ) goto exit_create_index;
77282 assert( db->aDb[iDb].pSchema==pTab->pSchema );
77287 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
77289 pDb = &db->aDb[iDb];
77325 zName = sqlite3NameFromToken(db, pName);
77330 if( !db->init.busy ){
77331 if( sqlite3FindTable(db, zName, 0)!=0 ){
77336 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
77346 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
77401 pIndex = sqlite3DbMallocZero(db,
77410 if( db->mallocFailed ){
77424 pIndex->pSchema = db->aDb[iDb].pSchema;
77477 zColl = db->pDfltColl->zName;
77480 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
77552 if( db->init.busy ){
77559 db->mallocFailed = 1;
77562 db->flags |= SQLITE_InternChanges;
77564 pIndex->tnum = db->init.newTnum;
77568 /* If the db->init.busy is 0 then create the index on disk. This
77572 ** The db->init.busy is 0 when the user first enters a CREATE INDEX
77573 ** command. db->init.busy is 1 when a database is opened and
77583 else{ /* if( db->init.busy==0 ) */
77603 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
77617 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
77623 sqlite3DbFree(db, zStmt);
77632 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName),
77644 if( db->init.busy || pTblName==0 ){
77664 sqlite3DbFree(db, pIndex->zColAff);
77665 sqlite3DbFree(db, pIndex);
77667 sqlite3ExprListDelete(db, pList);
77668 sqlite3SrcListDelete(db, pTblName);
77669 sqlite3DbFree(db, zName);
77715 sqlite3 *db = pParse->db;
77719 if( db->mallocFailed ){
77726 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
77739 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
77744 const char *zDb = db->aDb[iDb].zName;
77762 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
77765 if( sqlite3FindTable(db, "sqlite_stat1", db->aDb[iDb].zName) ){
77768 db->aDb[iDb].zName, pIndex->zName
77777 sqlite3SrcListDelete(db, pName);
77796 sqlite3 *db, /* Connection to notify of malloc failures */
77809 pNew = sqlite3DbRealloc(db, pArray, newSize*szEntry);
77814 *pnAlloc = sqlite3DbMallocSize(db, pNew)/szEntry;
77830 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
77833 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
77838 db,
77847 sqlite3IdListDelete(db, pList);
77850 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
77857 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
77861 sqlite3DbFree(db, pList->a[i].zName);
77863 sqlite3DbFree(db, pList->a);
77864 sqlite3DbFree(db, pList);
77888 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
77897 ** db->mallocFailed flag will be set to true.
77900 sqlite3 *db, /* Database connection to notify of OOM errors */
77918 pNew = sqlite3DbRealloc(db, pSrc,
77921 assert( db->mallocFailed );
77925 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
77982 sqlite3 *db, /* Connection to notify of malloc failures */
77990 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
77994 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
77995 if( db->mallocFailed ){
77996 sqlite3SrcListDelete(db, pList);
78008 pItem->zName = sqlite3NameFromToken(db, pTable);
78009 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
78019 assert(pList || pParse->db->mallocFailed );
78034 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
78039 sqlite3DbFree(db, pItem->zDatabase);
78040 sqlite3DbFree(db, pItem->zName);
78041 sqlite3DbFree(db, pItem->zAlias);
78042 sqlite3DbFree(db, pItem->zIndex);
78043 sqlite3DeleteTable(db, pItem->pTab);
78044 sqlite3SelectDelete(db, pItem->pSelect);
78045 sqlite3ExprDelete(db, pItem->pOn);
78046 sqlite3IdListDelete(db, pItem->pUsing);
78048 sqlite3DbFree(db, pList);
78078 sqlite3 *db = pParse->db;
78085 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
78092 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
78101 sqlite3ExprDelete(db, pOn);
78102 sqlite3IdListDelete(db, pUsing);
78103 sqlite3SelectDelete(db, pSubquery);
78121 pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy);
78155 sqlite3 *db;
78160 db = pParse->db;
78161 assert( db!=0 );
78162 /* if( db->aDb[0].pBt==0 ) return; */
78169 for(i=0; i<db->nDb; i++){
78181 sqlite3 *db;
78185 db = pParse->db;
78186 assert( db!=0 );
78187 /* if( db->aDb[0].pBt==0 ) return; */
78201 sqlite3 *db;
78205 db = pParse->db;
78206 assert( db!=0 );
78207 /* if( db->aDb[0].pBt==0 ) return; */
78222 char *zName = sqlite3NameFromToken(pParse->db, pName);
78230 sqlite3DbFree(pParse->db, zName);
78242 sqlite3 *db = pParse->db;
78243 if( db->aDb[1].pBt==0 && !pParse->explain ){
78253 rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
78260 db->aDb[1].pBt = pBt;
78261 assert( db->aDb[1].pSchema );
78262 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
78263 db->mallocFailed = 1;
78301 sqlite3 *db = pToplevel->db;
78304 assert( iDb<db->nDb );
78305 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
78310 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
78413 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78428 Db *pDb; /* A single database */
78430 sqlite3 *db = pParse->db; /* The database connection */
78434 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
78465 sqlite3 *db = pParse->db; /* The database connection */
78480 zColl = sqlite3NameFromToken(pParse->db, pName1);
78482 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
78485 sqlite3DbFree(db, zColl);
78488 sqlite3DbFree(db, zColl);
78492 z = sqlite3NameFromToken(db, pObjName);
78494 zDb = db->aDb[iDb].zName;
78495 pTab = sqlite3FindTable(db, z, zDb);
78498 sqlite3DbFree(db, z);
78501 pIndex = sqlite3FindIndex(db, z, zDb);
78502 sqlite3DbFree(db, z);
78517 ** the caller is responsible for calling sqlite3DbFree(db, ) on the returned
78526 sqlite3 *db = pParse->db;
78527 KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(db, nBytes);
78530 pKey->db = pParse->db;
78543 sqlite3DbFree(db, pKey);
78572 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
78573 assert( !db->xCollNeeded || !db->xCollNeeded16 );
78574 if( db->xCollNeeded ){
78575 char *zExternal = sqlite3DbStrDup(db, zName);
78577 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
78578 sqlite3DbFree(db, zExternal);
78581 if( db->xCollNeeded16 ){
78583 sqlite3_value *pTmp = sqlite3ValueNew(db);
78587 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
78601 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
78607 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
78626 ** db for collation type name zName, length nName, or NULL, if no collation
78632 sqlite3* db, /* The database connection */
78641 p = sqlite3FindCollSeq(db, enc, zName, 0);
78647 callCollNeeded(db, enc, zName);
78648 p = sqlite3FindCollSeq(db, enc, zName, 0);
78650 if( p && !p->xCmp && synthCollSeq(db
78671 sqlite3 *db = pParse->db;
78672 CollSeq *p = sqlite3GetCollSeq(db, ENC(db), pColl, zName);
78686 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
78699 sqlite3 *db, /* Database connection */
78705 pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
78708 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
78719 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
78727 db->mallocFailed = 1;
78728 sqlite3DbFree(db, pDel);
78739 ** for the encoding 'enc' from the database 'db'.
78752 sqlite3 *db,
78759 pColl = findCollSeqEntry(db, zName, create);
78761 pColl = db->pDfltColl;
78861 ** structure is created and liked into the "db" structure if a
78875 sqlite3 *db, /* An open database */
78889 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
78893 p = functionSearch(&db->aFunc, h, zName, nName);
78915 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
78934 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
78940 sqlite3FuncDefInsert(&db->aFunc, pBest);
78951 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
78986 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
78994 db->mallocFailed = 1;
79032 sqlite3DeleteTable(pParse->db, pItem->pTab);
79060 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
79062 && (pParse->db->flags & SQLITE_WriteSchema)==0
79093 sqlite3 *db = pParse->db;
79095 pDup = sqlite3SelectDup(db, pView->pSelect, 0);
79099 pWhere = sqlite3ExprDup(db, pWhere, 0);
79100 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
79103 pFrom->a[0].zAlias = sqlite3DbStrDup(db, pView->zName);
79108 sqlite3SelectDelete(db, pDup);
79114 sqlite3SelectDelete(db, pDup);
79176 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
79178 sqlite3ExprListDelete(pParse->db, pEList);
79200 sqlite3SelectDelete(pParse->db, pSelect);
79204 sqlite3ExprDelete(pParse->db, pWhere);
79205 sqlite3ExprListDelete(pParse->db, pOrderBy);
79206 sqlite3ExprDelete(pParse->db, pLimit);
79207 sqlite3ExprDelete(pParse->db, pOffset);
79232 sqlite3 *db; /* Main database structure */
79245 db = pParse->db;
79246 if( pParse->nErr || db->mallocFailed ){
79283 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79284 assert( iDb<db->nDb );
79285 zDb = db->aDb[iDb].zName;
79337 if( db->flags & SQLITE_CountRows ){
79374 if( db->flags & SQLITE_CountRows ){
79397 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
79433 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
79441 sqlite3SrcListDelete(db, pTabList);
79442 sqlite3ExprDelete(db, pWhere);
79942 sqlite3 *db = sqlite3_context_db_handle(context);
79944 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
79945 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
79946 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
80089 sqlite3 *db = sqlite3_context_db_handle(context);
80094 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
80109 sqlite3 *db = sqlite3_context_db_handle(context);
80111 sqlite3_result_int(context, sqlite3_changes(db));
80123 sqlite3 *db = sqlite3_context_db_handle(context);
80127 sqlite3_result_int(context, sqlite3_total_changes(db));
80327 sqlite3 *db = sqlite3_context_db_handle(context);
80336 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
80337 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
80338 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
80578 sqlite3 *db = sqlite3_context_db_handle(context);
80582 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
80583 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
80584 if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
80648 sqlite3 *db = sqlite3_context_db_handle(context);
80650 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
80651 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
80652 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
80829 sqlite3 *db = sqlite3_context_db_handle(context);
80837 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
80979 ** returns (void *)db, where db is the sqlite3* database pointer.
81020 sqlite3 *db = sqlite3_context_db_handle(context);
81023 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
81059 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
81060 int rc = sqlite3_overload_function(db, "MATCH", 2);
81063 db->mallocFailed = 1;
81070 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
81072 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
81084 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
81091 sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
81092 sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
81093 sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
81095 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
81096 setLikeOptFlag(db, "like",
81107 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
81116 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
81415 ** pParse->db->mallocFailed flag is set.
81456 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
81516 sqlite3DbFree(pParse->db, aiCol);
81703 sqlite3 *db = pParse->db; /* Database handle */
81732 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
81752 pRight = sqlite3Expr(db, TK_ID, zCol);
81754 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
81765 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
81766 pRight = sqlite3Expr(db, TK_COLUMN, 0);
81774 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
81797 sqlite3ExprDelete(db, pWhere);
81859 sqlite3 *db = pParse->db;
81860 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
81881 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
81925 sqlite3 *db = pParse->db; /* Database handle */
81936 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
81939 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
81940 zDb = db->aDb[iDb].zName;
81958 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
81963 if( !isIgnoreErrors || db->mallocFailed ) return;
81982 if( db->xAuth ){
82009 sqlite3DbFree(db, aiFree);
82026 if( !isIgnoreErrors || db->mallocFailed ) return;
82034 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
82055 sqlite3SrcListDelete(db, pSrc);
82057 sqlite3DbFree(db, aiCol);
82072 if( pParse->db->flags&SQLITE_ForeignKeys ){
82109 if( pParse->db->flags&SQLITE_ForeignKeys ){
82184 sqlite3 *db = pParse->db; /* Database handle */
82193 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
82235 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
82253 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
82266 pNew = sqlite3ExprDup(db, pDflt, 0);
82277 sqlite3DbFree(db, aiCol);
82288 pRaise = sqlite3Expr(db, TK_RAISE, "foreign key constraint failed");
82294 sqlite3SrcListAppend(db, 0, &tFrom, 0),
82302 enableLookaside = db->lookaside.bEnabled;
82303 db->lookaside.bEnabled = 0;
82305 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
82316 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
82317 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
82318 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
82321 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
82326 db->lookaside.bEnabled = enableLookaside;
82328 sqlite3ExprDelete(db, pWhere);
82329 sqlite3ExprDelete(db, pWhen);
82330 sqlite3ExprListDelete(db, pList);
82331 sqlite3SelectDelete(db, pSelect);
82332 if( db->mallocFailed==1 ){
82333 fkTriggerDelete(db, pTrigger);
82373 if( pParse->db->flags&SQLITE_ForeignKeys ){
82391 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
82398 if( !db || db->pnBytesFreed==0 ){
82418 fkTriggerDelete(db, pFKey->apTrigger[0]);
82419 fkTriggerDelete(db, pFKey->apTrigger[1]);
82423 sqlite3DbFree(db, pFKey);
82497 sqlite3 *db = sqlite3VdbeDb(v);
82500 db->mallocFailed = 1;
82538 sqlite3 *db = sqlite3VdbeDb(v);
82542 db->mallocFailed = 1;
82569 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
82632 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
82653 sqlite3 *db = pParse->db; /* The database connection */
82654 Db *pDb; /* Database only autoinc table */
82666 pDb = &db->aDb[p->iDb];
82708 sqlite3 *db = pParse->db;
82712 Db *pDb = &db->aDb[p->iDb];
82867 sqlite3 *db; /* The main database structure */
82886 Db *pDb; /* The database containing table being inserted into */
82906 db = pParse->db;
82908 if( pParse->nErr || db->mallocFailed ){
82921 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
82922 assert( iDb<db->nDb );
82923 pDb = &db->aDb[iDb];
83033 if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
83175 if( db->flags & SQLITE_CountRows ){
83186 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
83397 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
83417 if( (db->flags & SQLITE_CountRows)!=0 ){
83462 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
83469 sqlite3SrcListDelete(db, pTabList);
83470 sqlite3ExprListDelete(db, pList);
83471 sqlite3SelectDelete(db, pSelect);
83472 sqlite3IdListDelete(db, pColumn);
83473 sqlite3DbFree(db, aRegIdx);
83621 zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
83643 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
83710 if( pParse->db->flags&SQLITE_RecTriggers ){
83799 errMsg.db = pParse->db;
83811 sqlite3DbFree(errMsg.db, zErr);
83823 if( pParse->db->flags&SQLITE_RecTriggers ){
83923 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
84177 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
84291 sqlite3 *db, /* The database on which the SQL executes */
84304 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
84307 sqlite3_mutex_enter(db->mutex);
84308 sqlite3Error(db, SQLITE_OK, 0);
84314 rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
84335 && db->flags&SQLITE_NullCallback)) ){
84337 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
84354 db->mallocFailed = 1;
84363 sqlite3Error(db, SQLITE_ABORT, 0);
84380 sqlite3DbFree(db, azCols);
84386 sqlite3DbFree(db, azCols);
84388 rc = sqlite3ApiExit(db, rc);
84389 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
84390 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
84393 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
84396 sqlite3Error(db, SQLITE_NOMEM, 0);
84402 assert( (rc&db->errMask)==rc );
84403 sqlite3_mutex_leave(db->mutex);
84514 int (*errcode)(sqlite3*db);
85211 ** by calling sqlite3DbFree(db, ).
85214 sqlite3 *db, /* Load the extension into this database connection */
85219 sqlite3_vfs *pVfs = db->pVfs;
85234 if( (db->flags & SQLITE_LoadExtension)==0 ){
85270 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
85279 /* Append the new shared library handle to the db->aExtension array. */
85280 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
85284 if( db->nExtension>0 ){
85285 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
85287 sqlite3DbFree(db, db->aExtension);
85288 db->aExtension = aHandle;
85290 db->aExtension[db->nExtension++] = handle;
85294 sqlite3 *db, /* Load the extension into this database connection */
85300 sqlite3_mutex_enter(db->mutex);
85301 rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
85302 rc = sqlite3ApiExit(db, rc);
85303 sqlite3_mutex_leave(db->mutex);
85311 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
85313 assert( sqlite3_mutex_held(db->mutex) );
85314 for(i=0; i<db->nExtension; i++){
85315 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
85317 sqlite3DbFree(db, db->aExtension);
85324 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
85325 sqlite3_mutex_enter(db->mutex);
85327 db->flags |= SQLITE_LoadExtension;
85329 db->flags &= ~SQLITE_LoadExtension;
85331 sqlite3_mutex_leave(db->mutex);
85442 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
85467 if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){
85468 sqlite3Error(db, SQLITE_ERROR,
85562 ** Interpret the given string as a temp db location. Return 1 for file
85585 sqlite3 *db = pParse->db;
85586 if( db->aDb[1].pBt!=0 ){
85587 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
85592 sqlite3BtreeClose(db->aDb[1].pBt);
85593 db->aDb[1].pBt = 0;
85594 sqlite3ResetInternalSchema(db, 0);
85608 sqlite3 *db = pParse->db;
85609 if( db->temp_store==ts ) return SQLITE_OK;
85613 db->temp_store = (u8)ts;
85624 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
85637 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
85643 int mask; /* Mask for the db->flags value */
85683 sqlite3 *db = pParse->db;
85689 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
85692 if( db->autoCommit==0 ){
85699 db->flags |= mask;
85701 db->flags &= ~mask;
85789 sqlite3 *db = pParse->db;
85790 Db *pDb;
85791 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db);
85797 ** index of the database this pragma is being applied to in db.aDb[]. */
85800 pDb = &db->aDb[iDb];
85809 zLeft = sqlite3NameFromToken(db, pId);
85812 zRight = sqlite3MPrintf(db, "-%T", pValue);
85814 zRight = sqlite3NameFromToken(db, pValue);
85892 db->nextPagesize = sqlite3Atoi(zRight);
85893 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
85894 db->mallocFailed = 1;
85916 for(ii=0; ii<db->nDb; ii++){
85917 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
85967 eMode = db->dfltLockMode;
85973 ** set on all attached databases, as well as the main db file.
85980 assert(pDb==&db->aDb[0]);
85981 for(ii=2; ii<db->nDb; ii++){
85982 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
85985 db->dfltLockMode = (u8)eMode;
86040 for(ii=db->nDb-1; ii>=0; ii--){
86041 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
86093 db->nextAutovac = (u8)eAuto;
86098 ** as an auto-vacuum capable db.
86193 returnSingleInt(pParse, "temp_store", db->temp_store);
86223 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
86230 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
86231 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
86309 if( !db->autoCommit ){
86342 pTab = sqlite3FindTable(db, zRight, zDb);
86381 pIdx = sqlite3FindIndex(db, zRight, zDb);
86405 pTab = sqlite3FindTable(db, zRight, zDb);
86436 for(i=0; i<db
86437 if( db->aDb[i].pBt==0 ) continue;
86438 assert( db->aDb[i].zName!=0 );
86440 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
86442 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
86454 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
86468 pTab = sqlite3FindTable(db, zRight, zDb);
86526 sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
86574 for(i=0; i<db->nDb; i++){
86591 pTbls = &db->aDb[i].pSchema->tblHash;
86613 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
86744 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
86753 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
86754 DbHasProperty(db, 0, DB_Empty)
86758 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
86884 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
86887 db->xWalCallback==sqlite3WalDefaultHook ?
86888 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
86905 for(i=0; i<db->nDb; i++){
86910 if( db->aDb[i].zName==0 ) continue;
86911 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
86912 pBt = db->aDb[i].pBt;
86915 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
86928 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
86931 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
86943 sqlite3_key(db, zKey, i/2);
86945 sqlite3_rekey(db, zKey, i/2);
86972 if( db->autoCommit ){
86974 (db->flags&SQLITE_FullFSync)!=0,
86975 (db->flags&SQLITE_CkptFullFSync)!=0);
86979 sqlite3DbFree(db, zLeft);
86980 sqlite3DbFree(db, zRight);
87012 sqlite3 *db = pData->db;
87013 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
87015 sqlite3SetString(pData->pzErrMsg, db,
87018 *pData->pzErrMsg = sqlite3MAppendf(db, *pData->pzErrMsg,
87022 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT;
87039 sqlite3 *db = pData->db;
87044 assert( sqlite3_mutex_held(db->mutex) );
87045 DbClearProperty(db, iDb, DB_Empty);
87046 if( db->mallocFailed ){
87051 assert( iDb>=0 && iDb<db->nDb );
87057 ** But because db->init.busy is set to 1, no VDBE code is generated
87065 assert( db->init.busy );
87066 db->init.iDb = iDb;
87067 db->init.newTnum = sqlite3Atoi(argv[1]);
87068 db->init.orphanTrigger = 0;
87069 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
87070 rc = db->errCode;
87072 db->init.iDb = 0;
87074 if( db->init.orphanTrigger ){
87079 db->mallocFailed = 1;
87081 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
87096 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
87119 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
87124 Db *pDb;
87158 assert( iDb>=0 && iDb<db->nDb );
87159 assert( db->aDb[iDb].pSchema );
87160 assert( sqlite3_mutex_held(db->mutex) );
87161 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
87179 initData.db = db;
87188 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
87195 pDb = &db->aDb[iDb];
87198 DbSetProperty(db, 1, DB_SchemaLoaded);
87210 sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
87223 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
87240 ** For an attached db, it is an error if the encoding is not the same
87246 /* If opening the main database, set ENC(db). */
87249 ENC(db) = encoding;
87250 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
87252 /* If opening an attached database, the encoding much match ENC(db) */
87253 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
87254 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
87261 DbSetProperty(db, iDb, DB_Empty);
87263 pDb->pSchema->enc = ENC(db);
87284 sqlite3SetString(pzErrMsg, db, "unsupported file format");
87295 db->flags &= ~SQLITE_LegacyFileFmt;
87300 assert( db->init.busy );
87303 zSql = sqlite3MPrintf(db,
87305 db->aDb[iDb].zName, zMasterName);
87309 xAuth = db->xAuth;
87310 db->xAuth = 0;
87312 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
87314 db->xAuth = xAuth;
87318 sqlite3DbFree(db, zSql);
87321 sqlite3AnalysisLoad(db, iDb);
87325 if( db->mallocFailed ){
87327 sqlite3ResetInternalSchema(db, 0);
87329 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
87338 DbSetProperty(db, iDb, DB_SchemaLoaded);
87354 db->mallocFailed = 1;
87366 ** bit is set in the flags field of the Db structure. If the database
87369 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
87371 int commit_internal = !(db->flags&SQLITE_InternChanges);
87373 assert( sqlite3_mutex_held(db->mutex) );
87375 db->init.busy = 1;
87376 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
87377 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
87378 rc = sqlite3InitOne(db, i, pzErrMsg);
87380 sqlite3ResetInternalSchema(db, i);
87389 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
87390 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
87391 rc = sqlite3InitOne(db, 1, pzErrMsg);
87393 sqlite3ResetInternalSchema(db, 1);
87398 db->init.busy = 0;
87400 sqlite3CommitInternalChanges(db);
87412 sqlite3 *db = pParse->db;
87413 assert( sqlite3_mutex_held(db->mutex) );
87414 if( !db->init.busy ){
87415 rc = sqlite3Init(db, &pParse->zErrMsg);
87431 sqlite3 *db = pParse->db;
87437 assert( sqlite3_mutex_held(db->mutex) );
87438 for(iDb=0; iDb<db->nDb; iDb++){
87440 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
87449 db->mallocFailed = 1;
87459 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
87472 ** which database file in db->aDb[] the schema refers to.
87477 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
87486 ** -1000000 as the incorrect index into db->aDb[] is much
87490 assert( sqlite3_mutex_held(db->mutex) );
87492 for(i=0; ALWAYS(i<db->nDb); i++){
87493 if( db->aDb[i].pSchema==pSchema ){
87497 assert( i>=0 && i<db->nDb );
87506 sqlite3 *db, /* Database handle. */
87520 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
87527 assert( !db->mallocFailed );
87528 assert( sqlite3_mutex_held(db->mutex) );
87553 for(i=0; i<db->nDb; i++) {
87554 Btree *pBt = db->aDb[i].pBt;
87559 const char *zDb = db->aDb[i].zName;
87560 sqlite3Error(db, rc, "database schema is locked: %s", zDb);
87561 testcase( db->flags & SQLITE_ReadUncommitted );
87567 sqlite3VtabUnlockList(db);
87569 pParse->db = db;
87573 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
87577 sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
87578 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
87581 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
87584 sqlite3DbFree(db, zSqlCopy);
87594 if( db->mallocFailed ){
87602 sqlite3ResetInternalSchema(db, 0);
87604 if( db->mallocFailed ){
87635 assert( db->init.busy==0 || saveSqlFlag==0 );
87636 if( db->init.busy==0 ){
87640 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
87648 sqlite3Error(db, rc, "%s", zErrMsg);
87649 sqlite3DbFree(db, zErrMsg);
87651 sqlite3Error(db, rc, 0);
87658 sqlite3DbFree(db, pT);
87663 sqlite3StackFree(db, pParse);
87664 rc = sqlite3ApiExit(db, rc);
87665 assert( (rc&db->errMask)==rc );
87669 sqlite3 *db, /* Database handle. */
87680 if( !sqlite3SafetyCheckOk(db) ){
87683 sqlite3_mutex_enter(db->mutex);
87684 sqlite3BtreeEnterAll(db);
87685 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
87688 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
87690 sqlite3BtreeLeaveAll(db);
87691 sqlite3_mutex_leave(db->mutex);
87707 sqlite3 *db;
87712 db = sqlite3VdbeDb(p);
87713 assert( sqlite3_mutex_held(db->mutex) );
87714 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
87717 db->mallocFailed = 1;
87741 sqlite3 *db, /* Database handle. */
87748 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
87753 sqlite3 *db, /* Database handle. */
87760 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
87771 sqlite3 *db, /* Database handle. */
87788 if( !sqlite3SafetyCheckOk(db) ){
87791 sqlite3_mutex_enter(db->mutex);
87792 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
87794 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
87806 sqlite3DbFree(db, zSql8);
87807 rc = sqlite3ApiExit(db, rc);
87808 sqlite3_mutex_leave(db->mutex);
87821 sqlite3 *db, /* Database handle. */
87828 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
87833 sqlite3 *db, /* Database handle. */
87840 rc = sqlite3Prepare16(db
87869 static void clearSelect(sqlite3 *db, Select *p){
87870 sqlite3ExprListDelete(db, p->pEList);
87871 sqlite3SrcListDelete(db, p->pSrc);
87872 sqlite3ExprDelete(db, p->pWhere);
87873 sqlite3ExprListDelete(db, p->pGroupBy);
87874 sqlite3ExprDelete(db, p->pHaving);
87875 sqlite3ExprListDelete(db, p->pOrderBy);
87876 sqlite3SelectDelete(db, p->pPrior);
87877 sqlite3ExprDelete(db, p->pLimit);
87878 sqlite3ExprDelete(db, p->pOffset);
87911 sqlite3 *db = pParse->db;
87912 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
87913 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
87919 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
87935 if( db->mallocFailed ) {
87936 clearSelect(db, pNew);
87937 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
87946 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
87948 clearSelect(db, p);
87949 sqlite3DbFree(db, p);
88093 sqlite3 *db = pParse->db;
88103 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
88104 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
88113 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
88219 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
88595 sqlite3 *db = pParse->db;
88602 pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
88606 pInfo->enc = ENC(db);
88607 pInfo->db = db;
88612 pColl = db->pDfltColl;
88651 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
88681 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
88909 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
88910 zOriginDb = pNC->pParse->db->aDb[iDb].zName;
88994 sqlite3 *db = pParse->db;
89004 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
89006 fullNames = (db->flags & SQLITE_FullColNames)!=0;
89007 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
89034 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
89037 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
89044 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
89069 sqlite3 *db = pParse->db; /* Database connection */
89079 aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
89089 zName = sqlite3DbStrDup(db, zName);
89099 zName = sqlite3MPrintf(db, "%s",
89103 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
89106 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
89109 if( db->mallocFailed ){
89110 sqlite3DbFree(db, zName);
89122 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
89123 sqlite3DbFree(db, zName);
89131 if( db->mallocFailed ){
89133 sqlite3DbFree(db, aCol[j].zName);
89135 sqlite3DbFree(db, aCol);
89160 sqlite3 *db = pParse->db;
89170 assert( nCol==pSelect->pEList->nExpr || db->mallocFailed );
89171 if( db->mallocFailed ) return;
89177 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0));
89182 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
89193 sqlite3 *db = pParse->db;
89196 savedFlags = db->flags;
89197 db->flags &= ~SQLITE_FullColNames;
89198 db->flags |= SQLITE_ShortColNames;
89202 db->flags = savedFlags;
89203 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
89209 assert( db->lookaside.bEnabled==0 );
89216 if( db->mallocFailed ){
89217 sqlite3DeleteTable(db, pTab);
89230 v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
89384 sqlite3 *db; /* Database connection */
89394 db = pParse->db;
89544 sqlite3ExprListDelete(db, p->pOrderBy);
89549 sqlite3ExprDelete(db, p->pLimit);
89629 sqlite3ExprDelete(db, p->pLimit);
89681 pKeyInfo = sqlite3DbMallocZero(db,
89688 pKeyInfo->enc = ENC(db);
89694 *apColl = db->pDfltColl;
89712 sqlite3DbFree(db, pKeyInfo);
89718 sqlite3SelectDelete(db, pDelete);
89773 if( pParse->db->mallocFailed ) return 0;
90002 sqlite3 *db; /* Database connection */
90013 db = pParse->db;
90034 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
90041 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
90058 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
90066 sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1));
90070 pKeyMerge->enc = ENC(db);
90092 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
90102 assert( nOrderBy>=nExpr || db->mallocFailed );
90105 pKeyDup = sqlite3DbMallocZero(db,
90110 pKeyDup->enc = ENC(db);
90137 sqlite3ExprDelete(db, p->pLimit);
90139 sqlite3ExprDelete(db, p->pOffset);
90305 sqlite3SelectDelete(db, p->pPrior);
90335 sqlite3 *db, /* Report malloc errors to this connection */
90348 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
90352 sqlite3ExprDelete(db, pExpr);
90356 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
90357 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
90359 substSelect(db, pExpr->x.pSelect, iTable, pEList);
90361 substExprList(db, pExpr->x.pList, iTable, pEList);
90367 sqlite3 *db, /* Report malloc errors here */
90375 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
90379 sqlite3 *db, /* Report malloc errors here */
90388 substExprList(db, p->pEList, iTable, pEList);
90389 substExprList(db, p->pGroupBy, iTable, pEList);
90390 substExprList(db, p->pOrderBy, iTable, pEList);
90391 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
90392 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
90393 substSelect(db, p->pPrior, iTable, pEList);
90398 substSelect(db, pItem->pSelect, iTable, pEList);
90530 sqlite3 *db = pParse->db;
90536 if( db->flags & SQLITE_QueryFlattener ) return 0;
90688 pNew = sqlite3SelectDup(db, p, 0);
90701 if( db->mallocFailed ) return 1;
90712 sqlite3DbFree(db, pSubitem->zDatabase);
90713 sqlite3DbFree(db, pSubitem->zName);
90714 sqlite3DbFree(db, pSubitem->zAlias);
90764 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
90766 assert( db->mallocFailed );
90787 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
90788 if( db->mallocFailed ){
90797 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
90820 pList->a[i].zName = sqlite3DbStrDup(db, zSpan);
90824 substExprList(db, pParent->pEList, iParent, pSub->pEList);
90826 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
90827 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
90834 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
90837 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
90845 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
90846 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
90847 sqlite3ExprDup(db, pSub->pHaving, 0));
90849 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
90851 pParent->pWhere = substExpr(db, pParent->pWhere, iParent, pSub->pEList);
90852 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
90875 sqlite3SelectDelete(db, pSub1);
91002 sqlite3 *db = pParse->db;
91004 if( db->mallocFailed ){
91038 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
91041 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
91060 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
91074 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
91103 int flags = pParse->db->flags;
91139 if( db->mallocFailed ) break;
91174 pRight = sqlite3Expr(db, TK_ID, zName);
91179 pLeft = sqlite3Expr(db, TK_ID, zTabName);
91182 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
91192 sqlite3DbFree(db, zToFree);
91204 sqlite3ExprListDelete(db, pEList);
91208 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
91240 ** and/or pParse->db->mallocFailed.
91327 sqlite3 *db;
91329 db = pParse->db;
91332 if( pParse->nErr || db->mallocFailed ) return;
91334 if( pParse->nErr || db->mallocFailed ) return;
91429 pColl = pParse->db->pDfltColl;
91537 sqlite3 *db; /* The database connection */
91544 db = pParse->db;
91545 if( p==0 || db->mallocFailed || pParse->nErr ){
91556 sqlite3ExprListDelete(db, p->pOrderBy);
91564 if( pParse->nErr || db->mallocFailed ){
91620 if( /*pParse->nErr ||*/ db->mallocFailed ){
91649 mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
91666 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
91679 && (db->flags & SQLITE_GroupByOrder)==0 ){
91809 if( db->mallocFailed ) goto select_end;
92035 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
92105 pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->x.pList,0);
92107 if( pMinMax && !db->mallocFailed ){
92120 sqlite3ExprListDelete(db, pDel);
92137 sqlite3ExprListDelete(db, pDel);
92176 sqlite3DbFree(db, sAggInfo.aCol);
92177 sqlite3DbFree(db, sAggInfo.aFunc);
92394 sqlite3 *db, /* The database on which the SQL executes */
92416 db->errCode = SQLITE_NOMEM;
92420 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
92432 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
92445 db->errCode = SQLITE_NOMEM;
92493 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
92498 sqlite3ExprDelete(db, pTmp->pWhere);
92499 sqlite3ExprListDelete(db, pTmp->pExprList);
92500 sqlite3SelectDelete(db, pTmp->pSelect);
92501 sqlite3IdListDelete(db, pTmp->pIdList);
92503 sqlite3DbFree(db, pTmp);
92522 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
92568 sqlite3 *db = pParse->db; /* The database connection */
92570 Token *pName; /* The unqualified db name */
92571 DbFixer sFix; /* State vector for the DB fixer */
92587 /* Figure out the db that the the trigger will be created in */
92599 if( !pTableName || db->mallocFailed ){
92603 if( db->init.busy==0 && pName2->n==0 && pTab
92604 && pTab->pSchema==db->aDb[1].pSchema ){
92609 if( db->mallocFailed ) goto trigger_cleanup;
92618 if( db->init.iDb==1 ){
92627 db->init.orphanTrigger = 1;
92638 zName = sqlite3NameFromToken(db, pName);
92642 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
92670 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
92675 const char *zDb = db->aDb[iTabDb].zName;
92676 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
92697 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
92701 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
92702 pTrigger->pSchema = db->aDb[iDb].pSchema;
92706 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
92707 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
92712 sqlite3DbFree(db, zName);
92713 sqlite3SrcListDelete(db, pTableName);
92714 sqlite3IdListDelete(db, pColumns);
92715 sqlite3ExprDelete(db, pWhen);
92717 sqlite3DeleteTrigger(db, pTrigger);
92734 sqlite3 *db = pParse->db; /* The database */
92743 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
92759 if( !db->init.busy ){
92767 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
92770 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
92772 sqlite3DbFree(db, z);
92775 db, "type='trigger' AND name='%q'", zName), P4_DYNAMIC
92779 if( db->init.busy ){
92781 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
92784 db->mallocFailed = 1;
92796 sqlite3DeleteTrigger(db, pTrig);
92798 sqlite3DeleteTriggerStep(db, pStepList);
92808 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
92809 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
92811 sqlite3SelectDelete(db, pSelect);
92824 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
92827 sqlite3 *db, /* Database connection */
92833 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
92852 sqlite3 *db, /* The database connection */
92862 assert(pEList != 0 || pSelect != 0 || db->mallocFailed);
92864 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
92866 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
92868 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
92871 db, pColumn);
92873 sqlite3ExprListDelete(db, pEList);
92874 sqlite3SelectDelete(db, pSelect);
92885 sqlite3 *db, /* The database connection */
92893 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
92895 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
92896 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
92899 sqlite3ExprListDelete(db, pEList);
92900 sqlite3ExprDelete(db, pWhere);
92910 sqlite3 *db, /* Database connection */
92916 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
92918 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
92921 sqlite3ExprDelete(db, pWhere);
92928 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
92930 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
92931 sqlite3DbFree(db, pTrigger->zName);
92932 sqlite3DbFree(db, pTrigger->table);
92933 sqlite3ExprDelete(db, pTrigger->pWhen);
92934 sqlite3IdListDelete(db, pTrigger->pColumns);
92935 sqlite3DbFree(db, pTrigger);
92952 sqlite3 *db = pParse->db;
92954 if( db->mallocFailed ) goto drop_trigger_cleanup;
92963 for(i=OMIT_TEMPDB; i<db->nDb; i++){
92965 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
92966 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
92979 sqlite3SrcListDelete(db, pName);
92998 sqlite3 *db = pParse->db;
93001 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
93002 assert( iDb>=0 && iDb<db->nDb );
93009 const char *zDb = db->aDb[iDb].zName;
93053 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
93054 Hash *pHash = &(db->aDb[iDb].pSchema->trigHash);
93064 sqlite3DeleteTrigger(db, pTrigger);
93065 db->flags |= SQLITE_InternChanges;
93132 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
93136 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
93138 sqlite3 *db = pParse->db;
93139 assert( iDb<pParse->db->nDb );
93140 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
93157 sqlite3 *db = pParse->db;
93182 sqlite3ExprListDup(db, pStep->pExprList, 0),
93183 sqlite3ExprDup(db, pStep->pWhere, 0),
93191 sqlite3ExprListDup(db, pStep->pExprList, 0),
93192 sqlite3SelectDup(db, pStep->pSelect, 0),
93193 sqlite3IdListDup(db, pStep->pIdList),
93201 sqlite3ExprDup(db, pStep->pWhere, 0)
93207 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
93210 sqlite3SelectDelete(db, pSelect);
93252 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
93267 sqlite3 *db = pParse->db; /* Database handle */
93282 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
93286 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
93296 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
93300 pSubParse->db = db;
93319 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
93327 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
93329 && db->mallocFailed==0
93334 sqlite3ExprDelete(db, pWhen);
93348 if( db->mallocFailed==0 ){
93361 sqlite3StackFree(db, pSubParse);
93417 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
93422 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
93503 || p->pSchema==pParse->db->aDb[1].pSchema );
93674 sqlite3 *db; /* The database structure */
93705 db = pParse->db;
93706 if( pParse->nErr || db->mallocFailed ){
93715 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
93740 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
93794 pTab->aCol[j].zName, db->aDb[iDb].zName);
93813 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
93904 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
94087 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
94121 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
94129 sqlite3DbFree(db, aRegIdx);
94130 sqlite3DbFree(db, aXRef);
94131 sqlite3SrcListDelete(db, pTabList);
94132 sqlite3ExprListDelete(db, pChanges);
94133 sqlite3ExprDelete(db, pWhere);
94183 sqlite3 *db = pParse->db; /* Database connection */
94184 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
94190 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));
94193 sqlite3ExprDup(db, pRowid, 0));
94198 pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);
94200 pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
94236 sqlite3SelectDelete(db, pSelect);
94264 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
94268 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
94274 ** Execute zSql on database db. Return an error code.
94276 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
94282 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
94283 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
94284 return sqlite3_errcode(db);
94288 return vacuumFinalize(db, pStmt, pzErrMsg);
94292 ** Execute zSql on database db. The statement returns exactly
94295 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
94299 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
94303 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
94305 vacuumFinalize(db, pStmt, pzErrMsg);
94310 return vacuumFinalize(db, pStmt, pzErrMsg);
94334 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
94339 int saved_flags; /* Saved value of the db->flags */
94340 int saved_nChange; /* Saved value of db->nChange */
94341 int saved_nTotalChange; /* Saved value of db->nTotalChange */
94342 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */
94343 Db *pDb = 0; /* Database to detach at end of vacuum */
94348 if( !db->autoCommit ){
94349 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
94352 if( db->activeVdbeCnt>1 ){
94353 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
94360 saved_flags = db->flags;
94361 saved_nChange = db->nChange;
94362 saved_nTotalChange = db->nTotalChange;
94363 saved_xTrace = db->xTrace;
94364 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
94365 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
94366 db->xTrace = 0;
94368 pMain = db->aDb[0].pBt;
94385 nDb = db->nDb;
94386 if( sqlite3TempInMemory(db) ){
94391 rc = execSql(db, pzErrMsg, zSql);
94392 if( db->nDb>nDb ){
94393 pDb = &db->aDb[db->nDb-1];
94397 pTemp = db->aDb[db->nDb-1].pBt;
94409 if( db->nextPagesize ){
94413 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
94414 if( nKey ) db->nextPagesize = 0;
94421 db->nextPagesize = 0;
94425 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
94426 || NEVER(db->mallocFailed)
94431 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
94437 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
94442 rc = execSql(db, pzErrMsg, "BEGIN EXCLUSIVE;");
94448 rc = execExecSql(db, pzErrMsg,
94454 rc = execExecSql(db, pzErrMsg,
94458 rc = execExecSql(db, pzErrMsg,
94467 rc = execExecSql(db, pzErrMsg,
94478 rc = execExecSql(db, pzErrMsg,
94483 rc = execExecSql(db, pzErrMsg,
94496 rc = execSql(db, pzErrMsg,
94505 /* At this point, unless the main db was completely empty, there is now a
94555 /* Restore the original value of db->flags */
94556 db->flags = saved_flags;
94557 db->nChange = saved_nChange;
94558 db->nTotalChange = saved_nTotalChange;
94559 db->xTrace = saved_xTrace;
94569 db->autoCommit = 1;
94577 sqlite3ResetInternalSchema(db, 0);
94606 sqlite3 *db, /* Database in which module is registered */
94615 sqlite3_mutex_enter(db->mutex);
94617 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
94626 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
94630 sqlite3DbFree(db, pDel);
94632 db->mallocFailed = 1;
94634 sqlite3ResetInternalSchema(db, 0);
94638 rc = sqlite3ApiExit(db, SQLITE_OK);
94639 sqlite3_mutex_leave(db->mutex);
94648 sqlite3 *db, /* Database in which module is registered */
94653 return createModule(db, zName, pModule, pAux, 0);
94660 sqlite3 *db, /* Database in which module is registered */
94666 return createModule(db, zName, pModule, pAux, xDestroy);
94684 ** Return a pointer to the VTable object used by connection db to access
94687 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
94690 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
94699 sqlite3 *db = pVTab->db;
94701 assert( db );
94703 assert( sqlite3SafetyCheckOk(db) );
94711 sqlite3DbFree(db, pVTab);
94719 ** Except, if argument db is not NULL, then the entry associated with
94720 ** connection db is left in the p->pVTable list.
94722 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
94732 assert( db==0 ||
94733 sqlite3BtreeHoldsMutex(db->aDb[sqlite3SchemaToIndex(db, p->pSchema)].pBt)
94737 sqlite3 *db2 = pVTable->db;
94740 if( db2==db ){
94751 assert( !db || pRet );
94760 ** shared b-tree databases opened using connection db are held by the
94776 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
94777 VTable *p = db->pDisconnect;
94778 db->pDisconnect = 0;
94780 assert( sqlite3BtreeHoldsAllMutexes(db) );
94781 assert( sqlite3_mutex_held(db->mutex) );
94784 sqlite3ExpirePreparedStatements(db);
94802 ** connection db is decremented immediately (which may lead to the
94807 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
94808 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
94812 sqlite3DbFree(db, p->azModuleArg[i]);
94814 sqlite3DbFree(db, p->azModuleArg);
94824 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
94828 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
94832 sqlite3DbFree(db, pTable->azModuleArg[j]);
94834 sqlite3DbFree(db, zArg);
94835 sqlite3DbFree(db, pTable->azModuleArg);
94857 sqlite3 *db; /* Database connection */
94864 db = pParse->db;
94865 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
94870 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
94871 addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName));
94872 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
94883 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
94897 sqlite3 *db = pParse->db;
94898 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
94908 sqlite3 *db = pParse->db; /* The database connection */
94921 if( !db->init.busy ){
94931 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
94941 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
94946 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
94952 sqlite3DbFree(db, zStmt);
94957 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
94975 db->mallocFailed = 1;
95014 sqlite3 *db,
95025 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
95031 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
95033 sqlite3DbFree(db, zModuleName);
95036 pVTable->db = db;
95039 assert( !db->pVTab );
95041 db->pVTab = pTab;
95044 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
95045 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
95049 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
95051 *pzErr = sqlite3MPrintf(db, "%s", zErr);
95054 sqlite3DbFree(db, pVTable);
95060 if( db->pVTab ){
95062 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
95107 sqlite3DbFree(db, zModuleName);
95108 db->pVTab = 0;
95120 sqlite3 *db = pParse->db;
95126 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
95132 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
95140 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
95144 sqlite3DbFree(db, zErr);
95153 static int addToVTrans(sqlite3 *db, VTable *pVTab){
95157 if( (db->nVTrans%ARRAY_INCR)==0 ){
95159 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
95160 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
95164 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
95165 db->aVTrans = aVTrans;
95169 db->aVTrans[db->nVTrans++] = pVTab;
95180 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
95182 db, int iDb, const char *zTab, char **pzErr){
95188 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
95193 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
95200 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
95203 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
95208 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
95209 rc = addToVTrans(db, sqlite3GetVTable(db, pTab));
95220 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
95227 sqlite3_mutex_enter(db->mutex);
95228 pTab = db->pVTab;
95230 sqlite3Error(db, SQLITE_MISUSE, 0);
95231 sqlite3_mutex_leave(db->mutex);
95236 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
95241 pParse->db = db;
95246 && !db->mallocFailed
95256 db->pVTab = 0;
95258 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
95259 sqlite3DbFree(db, zErr);
95267 sqlite3DeleteTable(db, pParse->pNewTable);
95268 sqlite3StackFree(db, pParse);
95272 rc = sqlite3ApiExit(db, rc);
95273 sqlite3_mutex_leave(db->mutex);
95284 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
95288 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
95290 VTable *p = vtabDisconnectAll(db, pTab);
95315 static void callFinaliser(sqlite3 *db, int offset){
95317 if( db->aVTrans ){
95318 for(i=0; i<db->nVTrans; i++){
95319 VTable *pVTab = db->aVTrans[i];
95328 sqlite3DbFree(db, db->aVTrans);
95329 db->nVTrans = 0;
95330 db->aVTrans = 0;
95342 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
95345 VTable **aVTrans = db->aVTrans;
95347 db->aVTrans = 0;
95348 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
95353 sqlite3DbFree(db, *pzErrmsg);
95354 *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
95358 db->aVTrans = aVTrans;
95366 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
95367 callFinaliser(db, offsetof(sqlite3_module,xRollback));
95375 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
95376 callFinaliser(db, offsetof(sqlite3_module,xCommit));
95388 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
95392 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
95397 if( sqlite3VtabInSync(db) ){
95410 for(i=0; i<db->nVTrans; i++){
95411 if( db->aVTrans[i]==pVTab ){
95419 rc = addToVTrans(db, pVTab);
95439 sqlite3 *db, /* Database connection for reporting malloc problems */
95461 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
95470 zLowerName = sqlite3DbStrDup(db, pDef->zName);
95476 sqlite3DbFree(db, zLowerName);
95484 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
95519 pToplevel->db->mallocFailed = 1;
95638 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
95797 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
95799 sqlite3DbFree(db, p);
95805 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
95807 sqlite3DbFree(db, p);
95817 sqlite3 *db = pWC->pParse->db;
95820 sqlite3ExprDelete(db, a->pExpr);
95823 whereOrInfoDelete(db, a->u.pOrInfo);
95825 whereAndInfoDelete(db, a->u.pAndInfo);
95829 sqlite3DbFree(db, pWC->a);
95839 ** the db->mallocFailed flag so that higher-level functions can detect it.
95858 sqlite3 *db = pWC->pParse->db;
95859 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
95862 sqlite3ExprDelete(db, p);
95869 sqlite3DbFree(db, pOld);
95871 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
96171 sqlite3 *db = pParse->db; /* Database connection */
96175 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
96215 pPrefix = sqlite3Expr(db, TK_STRING, z);
96367 sqlite3 *db = pParse->db; /* Database connection */
96385 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
96392 if( db->mallocFailed ) return;
96406 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
96419 testcase( db->mallocFailed );
96420 if( !db->mallocFailed ){
96567 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
96572 pDup = sqlite3ExprDup(db, pLeft, 0);
96586 sqlite3ExprListDelete(db, pList);
96629 sqlite3 *db = pParse->db; /* Database connection */
96631 if( db->mallocFailed ){
96675 pDup = sqlite3ExprDup(db, pExpr, 0);
96676 if( db->mallocFailed ){
96677 sqlite3ExprDelete(db, pDup);
96728 sqlite3ExprDup(db, pExpr->pLeft, 0),
96729 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
96774 pStr2 = sqlite3ExprDup(db, pStr1, 0);
96775 if( !db->mallocFailed ){
96793 pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0);
96795 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
96801 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
96835 0, sqlite3ExprDup(db, pRight, 0), 0);
96910 sqlite3 *db = pParse->db;
96945 pColl = db->pDfltColl;
97222 if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
97351 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
97470 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
97539 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
97550 pParse->db->mallocFailed = 1;
97636 assert( sqlite3GetVTable(pParse->db, pTab) );
97760 sqlite3 *db = pParse->db;
97770 pColl = db->pDfltColl;
97773 pColl = sqlite3GetCollSeq(db, SQLITE_UTF8, 0, *pIdx->azColl);
97796 db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
97799 assert( db->mallocFailed );
97803 sqlite3DbFree(db, zSample);
97851 return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
98349 if( !pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
98392 sqlite3DbFree(pParse->db, p);
98455 assert( pParse->db->mallocFailed );
98525 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
98613 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
98615 pParse->db->mallocFailed = 1;
98698 static char *explainIndexRange(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
98711 txt.db = db;
98746 sqlite3 *db = pParse->db; /* Database handle */
98758 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
98760 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
98762 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
98766 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
98769 char *zWhere = explainIndexRange(db, pLevel, pItem->pTab);
98770 zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg,
98777 sqlite3DbFree(db, zWhere);
98779 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
98782 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
98784 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
98786 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
98788 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
98794 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
98804 zMsg = sqlite3MAppendf(db, zMsg, "%s (~%lld rows)", zMsg, nRow);
99118 zEndAff = sqlite3DbStrDup(pParse->db, zStartAff);
99197 sqlite3DbFree(pParse->db, zStartAff);
99198 sqlite3DbFree(pParse->db, zEndAff);
99313 pOrTab = sqlite3StackAllocRaw(pParse->db,
99383 if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
99474 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
99480 /* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
99484 sqlite3DbFree(db, pInfo);
99489 sqlite3DbFree(db, pIdx->zColAff);
99490 sqlite3DbFree(db, pIdx);
99495 sqlite3DbFree(db, pWInfo);
99607 sqlite3 *db; /* Database connection */
99632 db = pParse->db;
99634 pWInfo = sqlite3DbMallocZero(db,
99639 if( db->mallocFailed ){
99640 sqlite3DbFree(db, pWInfo);
99716 if( db->mallocFailed ){
99923 if( pParse->nErr || db->mallocFailed ){
99959 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
99965 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
100006 if( db->mallocFailed ) goto whereBeginError;
100078 whereInfoFree(db, pWInfo);
100093 sqlite3 *db = pParse->db;
100114 sqlite3DbFree(db, pLevel->u.in.aInLoop);
100175 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){
100206 whereInfoFree(db, pWInfo);
100322 sqlite3 *db = pParse->db;
100323 if( db->mallocFailed==0 && pY->op==TK_NULL ){
100325 sqlite3ExprDelete(db, pA->pRight);
101597 sqlite3SelectDelete(pParse->db, (yypminor->yy387));
101603 sqlite3ExprDelete(pParse->db, (yypminor->yy118).pExpr);
101619 sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
101627 sqlite3SrcListDelete(pParse->db, (yypminor->yy259));
101639 sqlite3ExprDelete(pParse->db, (yypminor->yy314));
101646 sqlite3IdListDelete(pParse->db, (yypminor->yy384));
101652 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy203));
101657 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
102340 pParse->db->lookaside.bEnabled = 0;
102376 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
102569 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy387);
102581 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy387);
102614 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
102630 {yygotominor.yy259 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy259));}
102675 {yygotominor.yy259 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
102800 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy384,&yymsp[0].minor.yy0);}
102803 {yygotominor.yy384 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
102875 if( yymsp[-1].minor.yy322 && yymsp[-1].minor.yy322->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
102981 sqlite3ExprListDelete(pParse->db, pList);
103000 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy118.pExpr);
103007 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
103023 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
103037 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
103046 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
103053 sqlite3SrcListDelete(pParse->db, pSrc);
103068 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy387);
103081 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
103102 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy322, yymsp[-9].minor.yy4,
103117 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
103241 { yygotominor.yy203 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy322, yymsp[0].minor.yy314, yymsp[-5].minor.yy210); }
103244 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy384, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy210);}
103247 {yygotominor.yy203 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy384, 0, yymsp[0].minor.yy387, yymsp[-4].minor.yy210);}
103250 {yygotominor.yy203 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy314);}
103253 {yygotominor.yy203 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy387); }
103320 pParse->db->lookaside.bEnabled = 0;
104306 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
104307 sqlite3 *db = pParse->db; /* The database connection */
104311 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
104312 if( db->activeVdbeCnt==0 ){
104313 db->u1.isInterrupted = 0;
104321 db->mallocFailed = 1;
104330 enableLookaside = db->lookaside.bEnabled;
104331 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
104332 while( !db->mallocFailed && zSql[i]!=0 ){
104343 if( db->u1.isInterrupted ){
104351 sqlite3DbFree(db, *pzErrMsg);
104352 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
104385 db->lookaside.bEnabled = enableLookaside;
104386 if( db->mallocFailed ){
104390 sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc));
104405 sqlite3DbFree(db, pParse->aTableLock);
104419 sqlite3DeleteTable(db, pParse->pNewTable);
104422 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
104423 sqlite3DbFree(db, pParse->apVarExpr);
104424 sqlite3DbFree(db, pParse->aAlias);
104428 sqlite3DbFree(db, p);
104433 sqlite3DeleteTable(db, p);
104768 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db, const char* registerAs); // Android Change
104800 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
104832 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
105256 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
105258 if( db->lookaside.nOut ){
105265 if( db->lookaside.bMalloced ){
105266 sqlite3_free(db->lookaside.pStart);
105285 db->lookaside.pStart = pStart;
105286 db->lookaside.pFree = 0;
105287 db->lookaside.sz = (u16)sz;
105294 p->pNext = db->lookaside.pFree;
105295 db->lookaside.pFree = p;
105298 db->lookaside.pEnd = p;
105299 db->lookaside.bEnabled = 1;
105300 db->lookaside.bMalloced = pBuf==0 ?1:0;
105302 db->lookaside.pEnd = 0;
105303 db->lookaside.bEnabled = 0;
105304 db->lookaside.bMalloced = 0;
105312 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
105313 return db->mutex;
105319 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
105328 rc = setupLookaside(db, pBuf, sz, cnt);
105403 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
105404 return db->lastRowid;
105410 SQLITE_API int sqlite3_changes(sqlite3 *db){
105411 return db->nChange;
105417 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
105418 return db->nTotalChange;
105426 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
105427 while( db->pSavepoint ){
105428 Savepoint *pTmp = db->pSavepoint;
105429 db->pSavepoint = pTmp->pNext;
105430 sqlite3DbFree(db, pTmp);
105432 db->nSavepoint = 0;
105433 db->nStatement = 0;
105434 db->isTransactionSavepoint = 0;
105443 static void functionDestroy(sqlite3 *db, FuncDef *p){
105449 sqlite3DbFree(db, pDestructor);
105457 SQLITE_API int sqlite3_close(sqlite3 *db){
105461 if( !db ){
105464 if( !sqlite3SafetyCheckSickOrOk(db) ){
105467 sqlite3_mutex_enter(db->mutex);
105469 sqlite3ResetInternalSchema(db, 0);
105473 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
105478 sqlite3VtabRollback(db);
105481 if( db->pVdbe ){
105486 snprintf(buff, sizeof(buff), "%d,%s", (int)db->pVdbe, db->pVdbe->zSql);
105487 sqlite3Error(db, SQLITE_UNCLOSED, buff);
105490 sqlite3_mutex_leave(db->mutex);
105493 assert( sqlite3SafetyCheckSickOrOk(db) );
105495 for(j=0; j<db->nDb; j++){
105496 Btree *pBt = db->aDb[j].pBt;
105498 sqlite3Error(db, SQLITE_BUSY,
105500 sqlite3_mutex_leave(db->mutex);
105506 sqlite3CloseSavepoints(db);
105508 for(j=0; j<db->nDb; j++){
105509 struct Db *pDb = &db->aDb[j];
105518 sqlite3ResetInternalSchema(db, 0);
105523 sqlite3ConnectionClosed(db);
105525 assert( db->nDb<=2 );
105526 assert( db->aDb==db->aDbStatic );
105527 for(j=0; j<ArraySize(db->aFunc.a); j++){
105529 for(p=db->aFunc.a[j]; p; p=pHash){
105532 functionDestroy(db, p);
105534 sqlite3DbFree(db, p);
105539 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
105547 sqlite3DbFree(db, pColl);
105549 sqlite3HashClear(&db->aCollSeq);
105551 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
105556 sqlite3DbFree(db, pMod);
105558 sqlite3HashClear(&db->aModule);
105561 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
105562 if( db->pErr ){
105563 sqlite3ValueFree(db->pErr);
105565 sqlite3CloseExtensions(db);
105567 db->magic = SQLITE_MAGIC_ERROR;
105575 sqlite3DbFree(db, db->aDb[1].pSchema);
105576 sqlite3_mutex_leave(db->mutex);
105577 db->magic = SQLITE_MAGIC_CLOSED;
105578 sqlite3_mutex_free(db->mutex);
105579 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
105580 if( db->lookaside.bMalloced ){
105581 sqlite3_free(db->lookaside.pStart);
105583 sqlite3_free(db);
105590 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db){
105593 assert( sqlite3_mutex_held(db->mutex) );
105595 for(i=0; i<db->nDb; i++){
105596 if( db->aDb[i].pBt ){
105597 if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){
105600 sqlite3BtreeRollback(db->aDb[i].pBt);
105601 db->aDb[i].inTrans = 0;
105604 sqlite3VtabRollback(db);
105607 if( db->flags&SQLITE_InternChanges ){
105608 sqlite3ExpirePreparedStatements(db);
105609 sqlite3ResetInternalSchema(db, 0);
105613 db->nDeferredCons = 0;
105616 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
105617 db->xRollbackCallback(db->pRollbackArg);
105679 sqlite3 *db = (sqlite3 *)ptr;
105680 int timeout = db->busyTimeout;
105695 sqlite3OsSleep(db->pVfs, delay*1000);
105698 sqlite3 *db = (sqlite3 *)ptr;
105703 sqlite3OsSleep(db->pVfs, 1000000);
105732 sqlite3 *db,
105736 sqlite3_mutex_enter(db->mutex);
105737 db->busyHandler.xFunc = xBusy;
105738 db->busyHandler.pArg = pArg;
105739 db->busyHandler.nBusy = 0;
105740 sqlite3_mutex_leave(db->mutex);
105751 sqlite3 *db,
105756 sqlite3_mutex_enter(db->mutex);
105758 db->xProgress = xProgress;
105759 db->nProgressOps = nOps;
105760 db->pProgressArg = pArg;
105762 db->xProgress = 0;
105763 db->nProgressOps = 0;
105764 db->pProgressArg = 0;
105766 sqlite3_mutex_leave(db->mutex);
105775 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
105777 db->busyTimeout = ms;
105778 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
105780 sqlite3_busy_handler(db, 0, 0);
105788 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
105789 db->u1.isInterrupted = 1;
105800 sqlite3 *db,
105813 assert( sqlite3_mutex_held(db->mutex) );
105835 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
105838 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
105855 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
105857 if( db->activeVdbeCnt ){
105858 db, SQLITE_BUSY,
105860 assert( !db->mallocFailed );
105863 sqlite3ExpirePreparedStatements(db);
105867 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
105868 assert(p || db->mallocFailed);
105875 functionDestroy(db, p);
105894 sqlite3 *db,
105903 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
105908 sqlite3 *db,
105920 sqlite3_mutex_enter(db->mutex);
105922 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
105930 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
105934 sqlite3DbFree(db, pArg);
105938 rc = sqlite3ApiExit(db, rc);
105939 sqlite3_mutex_leave(db->mutex);
105945 sqlite3 *db,
105956 sqlite3_mutex_enter(db->mutex);
105957 assert( !db->mallocFailed );
105958 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
105959 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
105960 sqlite3DbFree(db, zFunc8);
105961 rc = sqlite3ApiExit(db, rc);
105962 sqlite3_mutex_leave(db->mutex);
105981 sqlite3 *db,
105987 sqlite3_mutex_enter(db->mutex);
105988 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
105989 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
105992 rc = sqlite3ApiExit(db, SQLITE_OK);
105993 sqlite3_mutex_leave(db->mutex);
106006 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
106008 sqlite3_mutex_enter(db->mutex);
106009 pOld = db->pTraceArg;
106010 db->xTrace = xTrace;
106011 db->pTraceArg = pArg;
106012 sqlite3_mutex_leave(db->mutex);
106024 sqlite3 *db,
106029 sqlite3_mutex_enter(db->mutex);
106030 pOld = db->pProfileArg;
106031 db->xProfile = xProfile;
106032 db->pProfileArg = pArg;
106033 sqlite3_mutex_leave(db->mutex);
106045 sqlite3 *db, /* Attach the hook to this database */
106050 sqlite3_mutex_enter(db->mutex);
106051 pOld = db->pCommitArg;
106052 db->xCommitCallback = xCallback;
106053 db->pCommitArg = pArg;
106054 sqlite3_mutex_leave(db->mutex);
106063 sqlite3 *db, /* Attach the hook to this database */
106068 sqlite3_mutex_enter(db->mutex);
106069 pRet = db->pUpdateArg;
106070 db->xUpdateCallback = xCallback;
106071 db->pUpdateArg = pArg;
106072 sqlite3_mutex_leave(db->mutex);
106081 sqlite3 *db, /* Attach the hook to this database */
106086 sqlite3_mutex_enter(db->mutex);
106087 pRet = db->pRollbackArg;
106088 db->xRollbackCallback = xCallback;
106089 db->pRollbackArg = pArg;
106090 sqlite3_mutex_leave(db->mutex);
106103 sqlite3 *db, /* Connection */
106109 sqlite3_wal_checkpoint(db, zDb);
106127 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
106129 UNUSED_PARAMETER(db);
106133 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
106135 sqlite3_wal_hook(db, 0, 0);
106146 sqlite3 *db, /* Attach the hook to this db handle */
106152 sqlite3_mutex_enter(db->mutex);
106153 pRet = db->pWalArg;
106154 db->xWalCallback = xCallback;
106155 db->pWalArg = pArg;
106156 sqlite3_mutex_leave(db->mutex);
106169 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
106174 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
106176 sqlite3_mutex_enter(db->mutex);
106178 iDb = sqlite3FindDbName(db, zDb);
106182 sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb);
106184 rc = sqlite3Checkpoint(db, iDb);
106185 sqlite3Error(db, rc, 0);
106187 rc = sqlite3ApiExit(db, rc);
106188 sqlite3_mutex_leave(db->mutex);
106203 ** The mutex on database handle db should be held by the caller. The mutex
106211 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb){
106215 assert( sqlite3_mutex_held(db->mutex) );
106217 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
106219 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt);
106230 ** The value returned depends on the value of db->temp_store (runtime
106235 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
106246 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
106248 return ( db->temp_store==2 );
106251 return ( db->temp_store!=1 );
106265 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
106267 if( !db ){
106270 if( !sqlite3SafetyCheckSickOrOk(db) ){
106273 sqlite3_mutex_enter(db->mutex);
106274 if( db->mallocFailed ){
106277 z = (char*)sqlite3_value_text(db->pErr);
106278 assert( !db->mallocFailed );
106280 z = sqlite3ErrStr(db->errCode);
106283 sqlite3_mutex_leave(db->mutex);
106292 SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){
106306 if( !db ){
106309 if( !sqlite3SafetyCheckSickOrOk(db) ){
106312 sqlite3_mutex_enter(db->mutex);
106313 if( db->mallocFailed ){
106316 z = sqlite3_value_text16(db->pErr);
106318 sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
106320 z = sqlite3_value_text16(db->pErr);
106323 ** above. If this is the case, then the db->mallocFailed flag needs to
106327 db->mallocFailed = 0;
106329 sqlite3_mutex_leave(db->mutex);
106338 SQLITE_API int sqlite3_errcode(sqlite3 *db){
106339 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
106342 if( !db || db->mallocFailed ){
106345 return db->errCode & db->errMask;
106347 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
106348 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
106351 if( !db || db->mallocFailed ){
106354 return db->errCode;
106358 ** Create a new collating function for database "db". The name is zName
106362 sqlite3* db,
106374 assert( sqlite3_mutex_held(db->mutex) );
106394 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
106396 if( db->activeVdbeCnt ){
106397 sqlite3Error(db, SQLITE_BUSY,
106401 sqlite3ExpirePreparedStatements(db);
106410 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
106424 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
106431 sqlite3Error(db, SQLITE_OK, 0);
106500 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
106527 oldLimit = db->aLimit[limitId];
106532 db->aLimit[limitId] = newLimit;
106548 sqlite3 *db;
106614 db = sqlite3MallocZero( sizeof(sqlite3) );
106615 if( db==0 ) goto opendb_out;
106617 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
106618 if( db->mutex==0 ){
106619 sqlite3_free(db);
106620 db = 0;
106624 sqlite3_mutex_enter(db->mutex);
106625 db->errMask = 0xff;
106626 db->nDb = 2;
106627 db->magic = SQLITE_MAGIC_BUSY;
106628 db->aDb = db->aDbStatic;
106630 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
106631 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
106632 db->autoCommit = 1;
106633 db->nextAutovac = -1;
106634 db->nextPagesize = 0;
106635 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
106646 sqlite3HashInit(&db->aCollSeq);
106648 sqlite3HashInit(&db->aModule);
106651 db->pVfs = sqlite3_vfs_find(zVfs);
106652 if( !db->pVfs ){
106654 sqlite3Error(db, rc, "no such vfs: %s", zVfs);
106662 createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
106664 createCollation(db, "BINARY", SQLITE_UTF16BE, SQLITE_COLL_BINARY, 0,
106666 createCollation(db, "BINARY", SQLITE_UTF16LE, SQLITE_COLL_BINARY, 0,
106668 createCollation(db, "RTRIM", SQLITE_UTF8, SQLITE_COLL_USER, (void*)1,
106670 if( db->mallocFailed ){
106673 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
106674 assert( db->pDfltColl!=0 );
106677 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
106681 db->openFlags = flags;
106682 rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0,
106688 sqlite3Error(db, rc, 0);
106691 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
106692 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
106698 db->aDb[0].zName = "main";
106699 db->aDb[0].safety_level = 3;
106700 db->aDb[1].zName = "temp";
106701 db->aDb[1].safety_level = 1;
106703 db->magic = SQLITE_MAGIC_OPEN;
106704 if( db->mallocFailed ){
106712 sqlite3Error(db, SQLITE_OK, 0);
106713 sqlite3RegisterBuiltinFunctions(db);
106718 sqlite3AutoLoadExtensions(db);
106719 rc = sqlite3_errcode(db);
106725 if( !db->mallocFailed ){
106727 rc = sqlite3Fts1Init(db);
106732 if( !db->mallocFailed && rc==SQLITE_OK ){
106734 rc = sqlite3Fts2Init(db);
106744 if( !db->mallocFailed && rc==SQLITE_OK ){
106745 rc = sqlite3Fts3Init(db, "fts1");
106748 if( !db->mallocFailed && rc==SQLITE_OK ){
106749 rc = sqlite3Fts3Init(db, "fts2");
106753 if( !db->mallocFailed && rc==SQLITE_OK ){
106754 rc = sqlite3Fts3Init(db, "fts3");
106760 if( !db->mallocFailed && rc==SQLITE_OK ){
106761 rc = sqlite3IcuInit(db);
106766 if( !db->mallocFailed && rc==SQLITE_OK){
106767 rc = sqlite3RtreeInit(db);
106771 sqlite3Error(db, rc, 0);
106778 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
106779 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
106784 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
106787 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
106790 if( db ){
106791 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
106792 sqlite3_mutex_leave(db->mutex);
106794 rc = sqlite3_errcode(db);
106796 sqlite3_close(db);
106797 db = 0;
106799 db->magic = SQLITE_MAGIC_SICK;
106801 *ppDb = db;
106817 sqlite3 **ppDb, /* OUT: SQLite db handle */
106863 ** Register a new collation sequence with the database handle db.
106866 sqlite3* db,
106873 sqlite3_mutex_enter(db->mutex);
106874 assert( !db->mallocFailed );
106875 rc = createCollation(db, zName, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
106876 rc = sqlite3ApiExit(db, rc);
106877 sqlite3_mutex_leave(db->mutex);
106882 ** Register a new collation sequence with the database handle db.
106885 sqlite3* db,
106893 sqlite3_mutex_enter(db->mutex);
106894 assert( !db->mallocFailed );
106895 rc = createCollation(db, zName, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, xDel);
106896 rc = sqlite3ApiExit(db, rc);
106897 sqlite3_mutex_leave(db->mutex);
106903 ** Register a new collation sequence with the database handle db.
106906 sqlite3* db,
106914 sqlite3_mutex_enter(db->mutex);
106915 assert( !db->mallocFailed );
106916 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
106918 rc = createCollation(db, zName8, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
106919 sqlite3DbFree(db, zName8);
106921 rc = sqlite3ApiExit(db, rc);
106922 sqlite3_mutex_leave(db->mutex);
106929 ** db. Replace any previously installed collation sequence factory.
106932 sqlite3 *db,
106936 sqlite3_mutex_enter(db->mutex);
106937 db->xCollNeeded = xCollNeeded;
106938 db->xCollNeeded16 = 0;
106939 db->pCollNeededArg = pCollNeededArg;
106940 sqlite3_mutex_leave(db->mutex);
106947 ** db. Replace any previously installed collation sequence factory.
106950 sqlite3 *db,
106954 sqlite3_mutex_enter(db->mutex);
106955 db->xCollNeeded = 0;
106956 db->xCollNeeded16 = xCollNeeded16;
106957 db
106958 sqlite3_mutex_leave(db->mutex);
106981 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
106982 return db->autoCommit;
107037 sqlite3 *db, /* Connection handle */
107060 sqlite3_mutex_enter(db->mutex);
107061 sqlite3BtreeEnterAll(db);
107062 rc = sqlite3Init(db, &zErrMsg);
107068 pTab = sqlite3FindTable(db, zTableName, zDbName);
107118 sqlite3BtreeLeaveAll(db);
107131 sqlite3DbFree(db, zErrMsg);
107132 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
107136 sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
107137 sqlite3DbFree(db, zErrMsg);
107138 rc = sqlite3ApiExit(db, rc);
107139 sqlite3_mutex_leave(db->mutex);
107163 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
107164 sqlite3_mutex_enter(db->mutex);
107165 db->errMask = onoff ? 0xffffffff : 0xff;
107166 sqlite3_mutex_leave(db->mutex);
107173 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
107176 sqlite3_mutex_enter(db->mutex);
107180 for(iDb=0; iDb<db->nDb; iDb++){
107181 if( strcmp(db->aDb[iDb].zName, zDbName)==0 ) break;
107184 if( iDb<db->nDb ){
107185 Btree *pBtree = db->aDb[iDb].pBt;
107203 sqlite3_mutex_leave(db->mutex);
107351 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
107354 ** connection db.
107357 sqlite3 *db = va_arg(ap, sqlite3*);
107359 sqlite3_mutex_enter(db->mutex);
107360 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
107361 sqlite3_mutex_leave(db->mutex);
107365 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
107375 sqlite3 *db = va_arg(ap, sqlite3*);
107377 db->flags = (x & SQLITE_OptMask) | (db->flags & ~SQLITE_OptMask);
107482 db is not NULL, then none of the entries in the
107484 ** set to db. This is used when closing connection db.
107486 static void checkListProperties(sqlite3 *db){
107499 assert( db==0 || p->pUnlockConnection!=db );
107500 assert( db==0 || p->pBlockingConnection!=db );
107509 ** Remove connection db from the blocked connections list. If connection
107510 ** db is not currently a part of the list, this function is a no-op.
107512 static void removeFromBlockedList(sqlite3 *db){
107516 if( *pp==db ){
107524 ** Add connection db to the blocked connections list. It is assumed
107527 static void addToBlockedList(sqlite3 *db){
107532 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
107535 db->pNextBlocked = *pp;
107536 *pp = db;
107559 ** This is called after connection "db" has attempted some operation
107562 ** cache. pOther is found by looking at db->pBlockingConnection.
107567 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
107574 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
107578 sqlite3 *db,
107584 sqlite3_mutex_enter(db->mutex);
107588 removeFromBlockedList(db);
107589 db->pBlockingConnection = 0;
107590 db->pUnlockConnection = 0;
107591 db->xUnlockNotify = 0;
107592 db->pUnlockArg = 0;
107593 }else if( 0==db->pBlockingConnection ){
107602 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
107606 db->pUnlockConnection = db->pBlockingConnection;
107607 db->xUnlockNotify = xNotify;
107608 db->pUnlockArg = pArg;
107609 removeFromBlockedList(db);
107610 addToBlockedList(db);
107615 assert( !db->mallocFailed );
107616 sqlite3Error(db, rc, (rc?"database is deadlocked":0));
107617 sqlite3_mutex_leave(db->mutex);
107623 ** associated with connection db. The operation will return SQLITE_LOCKED
107627 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
107629 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
107630 addToBlockedList(db);
107632 db->pBlockingConnection = pBlocker;
107638 ** the transaction opened by database db has just finished. Locks held
107639 ** by database connection db have been released.
107645 ** set to db, then set pBlockingConnection=0.
107648 ** set to db, then invoke the configured unlock-notify callback and
107655 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
107671 if( p->pBlockingConnection==db ){
107676 if( p->pUnlockConnection==db ){
107703 ** is returned the transaction on connection db will still be
107754 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
107755 sqlite3ConnectionUnlocked(db);
107757 removeFromBlockedList(db);
107758 checkListProperties(db);
108457 sqlite3 *db; /* The database connection */
108691 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
108856 sqlite3 *db, /* Database in which to run SQL */
108869 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
108880 sqlite3 *db = p->db;
108883 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", p->zDb, p->zName);
108884 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", p->zDb,p->zName);
108885 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", p->zDb, p->zName);
108886 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", p->zDb, p->zName);
108887 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", p->zDb, p->zName);
108926 rc = sqlite3_declare_vtab(p->db, zSql);
108948 sqlite3 *db = p->db; /* The database connection */
108959 fts3DbExec(&rc, db,
108965 fts3DbExec(&rc, db,
108969 fts3DbExec(&rc, db,
108982 fts3DbExec(&rc, db,
108988 fts3DbExec(&rc, db,
109013 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
109069 sqlite3 *db, /* The SQLite database connection */
109183 p->db = db;
109252 sqlite3 *db, /* Database connection */
109259 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
109262 sqlite3 *db, /* Database connection */
109269 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
111323 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
111728 sqlite3 *db = p->db; /* Database connection */
111736 fts3DbExec(&rc, db,
111741 fts3DbExec(&rc, db,
111747 fts3DbExec(&rc, db,
111752 fts3DbExec(&rc, db,
111756 fts3DbExec(&rc, db,
111819 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db, const char* registerAs){ // Android Change
111855 rc = sqlite3Fts3ExprInitTestInterface(db);
111864 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
111865 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
111866 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
111867 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
111868 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
111869 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
111874 db, registerAs, &fts3Module, (void *)pHash, hashDestroy
111879 db, "fts4", &fts3Module, (void *)pHash, 0
111896 sqlite3 *db,
111901 return sqlite3Fts3Init(db);
112667 sqlite3 *db,
112676 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
112770 sqlite3 *db = sqlite3_context_db_handle(context);
112779 rc = queryTestTokenizer(db,
112832 ** with database connection db.
112834 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
112836 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
114192 sqlite3 *db,
114200 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
114214 sqlite3 *db,
114223 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
114266 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
114273 rc = queryTokenizer(db, "simple", &p2);
114276 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
114279 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
114282 rc = registerTokenizer(db, "nosuchtokenizer", p1);
114284 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
114294 ** Set up SQL objects in database db used to access the contents of
114311 sqlite3 *db,
114322 void *pdb = (void *)db;
114331 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
114334 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
114338 rc = sqlite3_create_function(db, zTest, 2, any, p, testFunc, 0, 0);
114341 rc = sqlite3_create_function(db, zTest, 3, any, p, testFunc, 0, 0);
114344 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
114855 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
115295 *piDocid = sqlite3_last_insert_rowid(p->db);
115460 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
116251 ** blocks were written to the db). Otherwise, an SQLite error code is
116463 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
116470 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
116669 char *zTerm, /* Term to write to the db */
116685 char *zTerm, /* Term to write to the db */
117460 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
117464 rc = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
117469 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
117470 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
119261 sqlite3 *db; /* Host database connection */
119741 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
119831 sqlite3 *db,
119837 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
119844 sqlite3 *db,
119850 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
119905 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
121769 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
121953 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
121984 sqlite3 *db,
122011 pRtree->db = db;
122024 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
122044 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
122057 ** using database connection db. If successful, the integer value returned
122061 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
122065 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
122092 sqlite3 *db, /* Database handle */
122101 rc = getIntFromStmt(db, zSql, &iPageSize);
122113 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
122130 sqlite3 *db, /* Database connection */
122175 rc = getNodeSize(db, pRtree, isCreate);
122182 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
122183 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
122200 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
122201 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
122284 ** Register the r-tree module with database handle db. This creates the
122288 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
122292 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
122294 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
122298 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
122302 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
122352 sqlite3 *db,
122367 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
122374 sqlite3 *db,
122379 return sqlite3RtreeInit(db);
122798 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
122820 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
122830 ** Register the ICU extension functions with database db.
122832 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
122855 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
122864 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
122873 sqlite3 *db,
122878 return sqlite3IcuInit(db);