Home | History | Annotate | Download | only in orig

Lines Matching defs:Db

2560   sqlite3 *db,          /* An open database */
2624 ** sqlite3_exec(db, zSQL, 0, 0, 0);
2652 ** sqlite3_exec(db, zSQL, 0, 0, 0);
3159 ** <tr><td> file:data.db <td>
3160 ** Open the file "data.db" in the current directory.
3161 ** <tr><td> file:/home/fred/data.db<br>
3162 ** file:///home/fred/data.db <br>
3163 ** file://localhost/home/fred/data.db <br> <td>
3164 ** Open the database file "/home/fred/data.db".
3165 ** <tr><td> file://darkstar/home/fred/data.db <td>
3168 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3169 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3173 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3174 ** Open file "data.db" in the current directory for read-only access.
3177 ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
3178 ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
3179 ** <tr><td> file:data.db?mode=readonly <td>
3200 sqlite3 **ppDb /* OUT: SQLite db handle */
3204 sqlite3 **ppDb /* OUT: SQLite db handle */
3208 sqlite3 **ppDb, /* OUT: SQLite db handle */
3290 SQLITE_API int sqlite3_errcode(sqlite3 *db);
3291 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
3433 ** The first argument, "db", is a [database connection] obtained from a
3508 sqlite3 *db, /* Database handle */
3515 sqlite3 *db, /* Database handle */
3522 sqlite3 *db, /* Database handle */
3529 sqlite3 *db, /* Database handle */
4389 sqlite3 *db,
4399 sqlite3 *db,
4409 sqlite3 *db,
4915 sqlite3 *db, /* Database to be rekeyed */
4928 sqlite3 *db, /* Database to be rekeyed */
5050 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5059 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
5362 sqlite3 *db, /* Connection handle */
5399 sqlite3 *db, /* Load the extension into this database connection */
5418 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5435 ** &nbsp; sqlite3 *db,
5653 sqlite3 *db, /* SQLite connection to register module with */
5659 sqlite3 *db, /* SQLite connection to register module with */
7283 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7301 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7307 ** handle db. The specific operation is determined by the value of the
7313 ** readers or writers to finish. Sync the db file if all frames in the log
7374 sqlite3 *db, /* Database handle */
7419 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
7524 sqlite3 *db,
8130 typedef struct Db Db;
8221 sqlite3 *db, /* Associated database connection */
8234 #define BTREE_MEMORY 2 /* This is an in-memory DB */
9597 struct Db {
9638 ** Db.pSchema->flags field.
9646 ** Allowed values for the DB.pSchema->flags field.
9718 Db *aDb; /* All backends */
9740 u8 iDb; /* Which db file is being initialized */
9794 Db aDbStatic[2]; /* Static space for the 2 default backends */
9824 #define ENC(db) ((db)->aDb[0].pSchema->enc)
10131 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
10135 sqlite3 *db; /* Database connection associated with this table */
10309 sqlite3 *db; /* The database connection */
11084 sqlite3 *db; /* The main database structure */
11161 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
11193 #define OPFLAG_NCHANGE 0x01 /* Set to update db->nChange */
11194 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
11308 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
11324 sqlite3 *db; /* The database being initialized */
11944 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
11951 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
11997 # define sqlite3VtabInSync(db) 0
12004 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
12005 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
12006 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
12007 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
12013 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
12115 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db);
12116 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db);
12880 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12975 sqlite3 *db; /* The associated database connection */
13119 sqlite3 *db; /* The database connection that owns this statement */
13134 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
13153 int nChange; /* Number of db changes made since last reset */
13154 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13388 sqlite3 *db, /* The database connection whose status is desired */
13395 sqlite3_mutex_enter(db->mutex);
13398 *pCurrent = db->lookaside.nOut;
13399 *pHighwater = db->lookaside.mxOut;
13401 db->lookaside.mxOut = db->lookaside.nOut;
13415 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
13417 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
13430 sqlite3BtreeEnterAll(db);
13431 for(i=0; i<db->nDb; i++){
13432 Btree *pBt = db->aDb[i].pBt;
13438 sqlite3BtreeLeaveAll(db);
13453 sqlite3BtreeEnterAll(db);
13454 db->pnBytesFreed = &nByte;
13455 for(i=0; i<db->nDb; i++){
13456 Schema *pSchema = db->aDb[i].pSchema;
13472 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
13475 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
13479 db->pnBytesFreed = 0;
13480 sqlite3BtreeLeaveAll(db);
13496 db->pnBytesFreed = &nByte;
13497 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
13498 sqlite3VdbeDeleteObject(db, pVdbe);
13500 db->pnBytesFreed = 0;
13519 for(i=0; i<db->nDb; i++){
13520 if( db->aDb[i].pBt ){
13521 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt);
13534 sqlite3_mutex_leave(db->mutex);
13835 sqlite3 *db = sqlite3_context_db_handle(context);
13836 if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
14426 sqlite3 *db;
14430 db = sqlite3_context_db_handle(context);
14466 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
14467 testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
14470 }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
14474 z = sqlite3DbMallocRaw(db, (int)n);
14610 sqlite3 *db;
14619 db = sqlite3_context_db_handle(context);
14620 if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
19017 ** TRUE if p is a lookaside memory allocation from db
19020 static int isLookaside(sqlite3 *db, void *p){
19021 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19036 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19037 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19038 if( db && isLookaside(db, p) ){
19039 return db->lookaside.sz;
19043 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
19070 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
19071 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19072 if( db ){
19073 if( db->pnBytesFreed ){
19074 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
19077 if( isLookaside(db, p) ){
19079 pBuf->pNext = db->lookaside.pFree;
19080 db->lookaside.pFree = pBuf;
19081 db->lookaside.nOut--;
19087 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
19170 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3 *db, int n){
19171 void *p = sqlite3DbMallocRaw(db, n);
19182 ** If db!=0 and db->mallocFailed is true (indicating a prior malloc
19189 ** int *a = (int*)sqlite3DbMallocRaw(db, 100);
19190 ** int *b = (int*)sqlite3DbMallocRaw(db, 200);
19196 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3 *db, int n){
19198 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19199 assert( db==0 || db->pnBytesFreed==0 );
19201 if( db ){
19203 if( db->mallocFailed ){
19206 if( db->lookaside.bEnabled ){
19207 if( n>db->lookaside.sz ){
19208 db->lookaside.anStat[1]++;
19209 }else if( (pBuf = db->lookaside.pFree)==0 ){
19210 db->lookaside.anStat[2]++;
19212 db->lookaside.pFree = pBuf->pNext;
19213 db->lookaside.nOut++;
19214 db->lookaside.anStat[0]++;
19215 if( db->lookaside.nOut>db->lookaside.mxOut ){
19216 db->lookaside.mxOut = db->lookaside.nOut;
19223 if( db && db->mallocFailed ){
19228 if( !p && db ){
19229 db->mallocFailed = 1;
19232 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
19240 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
19242 assert( db!=0 );
19243 assert( sqlite3_mutex_held(db->mutex) );
19244 if( db->mallocFailed==0 ){
19246 return sqlite3DbMallocRaw(db, n);
19248 if( isLookaside(db, p) ){
19249 if( n<=db->lookaside.sz ){
19252 pNew = sqlite3DbMallocRaw(db, n);
19254 memcpy(pNew, p, db->lookaside.sz);
19255 sqlite3DbFree(db, p);
19264 db->mallocFailed = 1;
19267 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
19277 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
19279 pNew = sqlite3DbRealloc(db, p, n);
19281 sqlite3DbFree(db, p);
19293 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3 *db, const char *z){
19301 zNew = sqlite3DbMallocRaw(db, (int)n);
19307 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
19313 zNew = sqlite3DbMallocRaw(db, n+1);
19326 SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zFormat, ...){
19331 z = sqlite3VMPrintf(db, zFormat, ap);
19333 sqlite3DbFree(db, *pz);
19347 ** If the first argument, db, is not NULL and a malloc() error has occurred,
19351 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
19352 /* If the db handle is not NULL, then we must hold the connection handle
19353 ** mutex here. Otherwise the read (and possible write) of db->mallocFailed
19356 assert( !db || sqlite3_mutex_held(db->mutex) );
19357 if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
19358 sqlite3Error(db, SQLITE_NOMEM, 0);
19359 db->mallocFailed = 0;
19362 return rc & (db ? db->errMask : 0xff);
20086 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
20115 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
20135 sqlite3DbFree(p->db, p->zText);
20148 p->db = 0;
20161 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
20165 assert( db!=0 );
20167 db->aLimit[SQLITE_LIMIT_LENGTH]);
20168 acc.db = db;
20172 db->mallocFailed = 1;
20181 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
20185 z = sqlite3VMPrintf(db, zFormat, ap);
20195 ** x = sqlite3MPrintf(db, x, "prefix %s suffix", x);
20198 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3 *db, char *zStr, const char *zFormat, ...){
20202 z = sqlite3VMPrintf(db, zFormat, ap);
20204 sqlite3DbFree(db, zStr);
20695 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
20759 zOut = sqlite3DbMallocRaw(pMem->db, len);
20923 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte, u8 enc){
20926 m.db = db;
20929 if( db->mallocFailed ){
20933 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
20934 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
20935 assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
20936 assert( m.z || db->mallocFailed );
20947 ** If a malloc failure occurs, NULL is returned and the db.mallocFailed
20951 SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
20954 m.db = db;
20957 assert( db->mallocFailed );
21143 ** handle "db". The error code is set to "err_code".
21158 ** To clear the most recent error for sqlite handle "db", sqlite3Error
21162 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21163 if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21164 db->errCode = err_code;
21169 z = sqlite3VMPrintf(db, zFormat, ap);
21171 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21173 sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
21198 sqlite3 *db = pParse->db;
21200 zMsg = sqlite3VMPrintf(db, zFormat, ap);
21202 if( db->suppressErr ){
21203 sqlite3DbFree(db, zMsg);
21206 sqlite3DbFree(db, pParse->zErrMsg);
22060 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
22064 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
22089 ** Check to make sure we have a valid db pointer. This test is not
22091 ** misuse of the interface such as passing in db pointers that are
22093 ** 1 it means that the db pointer is valid and 0 if it should not be
22097 ** sqlite3SafetyCheckOk() requires that the db pointer be valid for
22098 ** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
22102 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3 *db){
22104 if( db==0 ){
22108 magic = db->magic;
22110 if( sqlite3SafetyCheckSickOrOk(db) ){
22119 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
22121 magic = db->magic;
22214 ** test.db-journal => test.nal
22215 ** test.db-wal => test.wal
22216 ** test.db-shm => test.shm
22217 ** test.db-mj7f3319fa => test.9fa
24386 /* The main DB, main journal, WAL file and master journal are never
28853 ** is "/home/user1/config.db" then the file that is created and mmapped
28854 ** for shared memory will be called "/home/user1/config.db-shm".
29666 ** proxyLock activation is possible (remote proxy is based on db name)
29971 ** "<path to db>-journal"
29972 ** "<path to db>-wal"
29973 ** "<path to db>-journalNN"
29974 ** "<path to db>-walNN"
30083 /* The main DB, main journal, WAL file and master journal are never
30668 ** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE,
30670 ** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &<proxy_path>);
30685 ** For database path "/Users/me/foo.db"
30686 ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
30819 /* transform the db path to a unique cache name */
31474 /* afp style keeps a reference to the db path in the filePath field
31486 /* all other styles use the locking context to store the db file path */
35170 /* The main DB, main journal, WAL file and master journal are never
37967 sqlite3 *db; /* The database connection */
37979 ** are available at pSpace. The db pointer is used as a memory context
37989 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3 *db, void *pSpace, unsigned int N){
37994 p->db = db;
38014 sqlite3DbFree(p->db, pChunk);
38036 pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew));
38413 int sync_flags, /* Flags to sync db file with (or 0) */
38440 ** stored in each frame (i.e. the db page-size when the WAL was created).
38711 ** db size etc.) are consistent with the contents of the file-system.
39124 SQLITE_API int sqlite3_pager_readdb_count = 0; /* Number of full pages read from DB */
39125 SQLITE_API int sqlite3_pager_writedb_count = 0; /* Number of full pages written to DB */
40313 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
40759 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
41507 i64 n = 0; /* Size of db file in bytes */
41544 ** function. Because an EXCLUSIVE lock on the db file is required to delete
42826 ROUND8(pVfs->szOsFile) + /* The main db file */
44175 int noSync /* True to omit the xSync on the db file */
44196 /* If this is an in-memory db, or no pages have been written to, or this
44255 /* Update the db file change counter via the direct-write method. The
45697 u32 nBackfill; /* Number of WAL frames backfilled into DB */
46004 u32 nTruncate, /* New db size (or 0 for non-commit frames) */
46031 u32 *pnTruncate, /* OUT: New db size (or 0 if not commit) */
47057 ** about the eventual size of the db file to the VFS layer.
47067 /* Iterate through the contents of the WAL, copying data to the db file. */
48239 int sync_flags, /* Flags to sync db file with (or 0) */
48782 sqlite3 *db; /* The database connection holding this btree */
48785 u8 sharable; /* True if we can share pBt with another db */
48786 u8 locked; /* True if db currently has pBt locked */
48789 Btree *pNext; /* List of other sharable Btrees from the same db */
48844 sqlite3 *db; /* Database connection currently using this Btree */
48924 ** particular database connection identified BtCursor.pBtree.db.
49099 ** set BtShared.db to the database handle associated with p and the
49105 assert( sqlite3_mutex_held(p->db->mutex) );
49108 p->pBt->db = p->db;
49120 assert( sqlite3_mutex_held(p->db->mutex) );
49121 assert( p->db==pBt->db );
49152 assert( p->pNext==0 || p->pNext->db==p->db );
49153 assert( p->pPrev==0 || p->pPrev->db==p->db );
49161 assert( sqlite3_mutex_held(p->db->mutex) );
49163 /* Unless the database is sharable and unlocked, then BtShared.db
49165 assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db );
49176 p->pBt->db = p->db;
49224 assert( p->sharable==0 || p->locked==0 || p->db==p->pBt->db );
49226 assert( p->sharable==0 || p->locked==0 || sqlite3_mutex_held(p->db->mutex) );
49262 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
49265 assert( sqlite3_mutex_held(db->mutex) );
49266 for(i=0; i<db->nDb; i++){
49267 p = db->aDb[i].pBt;
49271 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
49274 assert( sqlite3_mutex_held(db->mutex) );
49275 for(i=0; i<db->nDb; i++){
49276 p = db->aDb[i].pBt;
49296 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
49298 if( !sqlite3_mutex_held(db->mutex) ){
49301 for(i=0; i<db->nDb; i++){
49303 p = db->aDb[i].pBt;
49316 ** db->aDb[iDb].pSchema structure. The mutexes required for schema
49319 ** (1) The mutex on db
49320 ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
49323 ** db using sqlite3SchemaToIndex().
49325 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
49327 assert( db!=0 );
49328 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
49329 assert( iDb>=0 && iDb<db->nDb );
49330 if( !sqlite3_mutex_held(db->mutex) ) return 0;
49332 p = db->aDb[iDb].pBt;
49350 p->pBt->db = p->db;
49352 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
49354 for(i=0; i<db->nDb; i++){
49355 Btree *p = db->aDb[i].pBt;
49357 p->pBt->db = p->db;
49500 || (eLockType==READ_LOCK && (pBtree->db->flags & SQLITE_ReadUncommitted))
49571 && 0==(p->pBtree->db->flags & SQLITE_ReadUncommitted)
49592 assert( p->db!=0 );
49593 assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
49611 sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
49628 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
49665 assert( p->db!=0 );
49671 assert( 0==(p->db->flags&SQLITE_ReadUncommitted) || eLock==WRITE_LOCK );
50035 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
51037 assert( pBt->db );
51038 assert( sqlite3_mutex_held(pBt->db->mutex) );
51039 return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
51066 sqlite3 *db, /* Associated database handle */
51088 || (isTempDb && sqlite3TempInMemory(db));
51091 assert( db!=0 );
51093 assert( sqlite3_mutex_held(db->mutex) );
51113 p->db = db;
51151 for(iDb=db->nDb-1; iDb>=0; iDb--){
51152 Btree *pExisting = db->aDb[iDb].pBt;
51207 pBt->db = db;
51258 db->mallocFailed = 0;
51278 for(i=0; i<db->nDb; i++){
51279 if( (pSib = db->aDb[i].pBt)!=0 && pSib->sharable ){
51393 assert( sqlite3_mutex_held(p->db->mutex) );
51460 assert( sqlite3_mutex_held(p->db->mutex) );
51483 assert( sqlite3_mutex_held(p->db->mutex) );
51499 assert( sqlite3_mutex_held(p->db->mutex) );
51762 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
51939 pBlock = pBt->pWriter->db;
51944 pBlock = pIter->pBtree->db;
51950 sqlite3ConnectionBlocked(p->db, pBlock);
51978 rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
52016 /* If the db-size header field is incorrect (as it may be if an old
52038 rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
52511 if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){
52740 assert( iStatement>p->db->nSavepoint );
53496 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53505 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53756 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53779 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53849 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
53890 ** would have already detected db corruption. Similarly, pPage must
56648 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
57420 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
57454 assert( sqlite3_mutex_held(p->db->mutex) );
57460 assert( sqlite3_mutex_held(p->db->mutex) );
57502 assert( sqlite3_mutex_held(p->db->mutex) );
57550 assert( sqlite3_mutex_held(pCsr->pBtree->db->mutex) );
57593 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
57733 pParse->db = pDb;
57977 int nSrcPage = -1; /* Size of source db in pages */
57978 int bCloseTrans = 0; /* True if src db requires unlocking */
58326 b.pSrcDb = pFrom->db;
58396 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58435 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
58437 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
58440 sqlite3DbFree(pMem->db, pMem->zMalloc);
58441 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
58473 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58502 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58526 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58557 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58601 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58604 ctx.s.db = pMem->db;
58609 sqlite3DbFree(pMem->db, pMem->zMalloc);
58622 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
58646 sqlite3DbFree(p->db, p->zMalloc);
58706 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58731 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58755 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58788 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58802 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58821 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
58906 sqlite3 *db = pMem->db;
58907 assert( db!=0 );
58910 pMem->zMalloc = sqlite3DbMallocRaw(db, 64);
58911 if( db->mallocFailed ){
58915 pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc,
58916 sqlite3DbMallocSize(db, pMem->zMalloc));
58927 assert( p->db!=0 );
58933 return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
59012 assert( pFrom->db==0 || sqlite3_mutex_held(pFrom->db->mutex) );
59013 assert( pTo->db==0 || sqlite3_mutex_held(pTo->db->mutex) );
59014 assert( pFrom->db==0 || pTo->db==0 || pFrom->db==pTo->db );
59049 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
59058 if( pMem->db ){
59059 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
59310 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
59334 assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || pVal->db==0
59335 || pVal->db->mallocFailed );
59346 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
59347 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
59351 p->db = db;
59367 sqlite3 *db, /* The database connection */
59407 pVal = sqlite3ValueNew(db);
59412 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
59428 if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
59441 pVal = sqlite3ValueNew(db);
59449 pVal = sqlite3ValueNew(db);
59454 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
59466 db->mallocFailed = 1;
59467 sqlite3DbFree(db, zVal);
59492 sqlite3DbFree(((Mem*)v)->db, v);
59545 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
59547 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
59549 p->db = db;
59550 if( db->pVdbe ){
59551 db->pVdbe->pPrev = p;
59553 p->pNext = db->pVdbe;
59555 db->pVdbe = p;
59570 p->zSql = sqlite3DbStrNDup(p->db, z, n);
59624 pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
59626 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
59719 for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
59756 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
59801 ** sqlite3DbFree(v->db, sIter.apSub);
59843 p->apSub = sqlite3DbReallocOrFree(v->db, p->apSub, nByte);
59896 sqlite3DbFree(v->db, sIter.apSub);
59903 return ( v->db->mallocFailed || hasAbort==mayAbort );
59957 sqlite3DbFree(p->db, p->aLabel);
59984 assert( aOp && !p->db->mallocFailed );
60086 assert( addr>=0 || p->db->mallocFailed );
60095 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
60097 sqlite3DbFree(db, pDef);
60106 static void freeP4(sqlite3 *db, int p4type, void *p4){
60108 assert( db );
60116 sqlite3DbFree(db, p4);
60120 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
60125 freeEphemeralFunction(db, pVdbeFunc->pFunc);
60126 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
60127 sqlite3DbFree(db, pVdbeFunc);
60131 freeEphemeralFunction(db, (FuncDef*)p4);
60135 if( db->pnBytesFreed==0 ){
60139 sqlite3DbFree(db, p->zMalloc);
60140 sqlite3DbFree(db, p);
60145 if( db->pnBytesFreed==0 ) sqlite3VtabUnlock((VTable *)p4);
60157 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
60161 freeP4(db, pOp->p4type, pOp->p4.p);
60163 sqlite3DbFree(db, pOp->zComment);
60167 sqlite3DbFree(db, aOp);
60186 sqlite3 *db = p->db;
60187 freeP4(db, pOp->p4type, pOp->p4.p);
60220 sqlite3 *db;
60222 db = p->db;
60224 if( p->aOp==0 || db->mallocFailed ){
60226 freeP4(db, n, (void*)*(char**)&zP4);
60236 freeP4(db, pOp->p4type, pOp->p4.p);
60264 p->db->mallocFailed = 1;
60274 assert( ((VTable *)zP4)->db==p->db );
60280 pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n);
60294 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
60297 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
60298 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
60352 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
60353 if( p->db->mallocFailed ){
60471 ** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
60479 assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 );
60482 if( i!=1 && sqlite3BtreeSharable(p->db->aDb[i].pBt) ){
60492 ** sets the BtShared.db member of each of the BtShared structures, ensuring
60496 ** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
60512 sqlite3 *db;
60513 Db *aDb;
60516 db = p->db;
60517 aDb = db->aDb;
60518 nDb = db->nDb;
60534 sqlite3 *db;
60535 Db *aDb;
60538 db = p->db;
60539 aDb = db->aDb;
60540 nDb = db->nDb;
60577 sqlite3 *db = p->db;
60578 u8 malloc_failed = db->mallocFailed;
60579 if( db->pnBytesFreed ){
60581 sqlite3DbFree(db, p->zMalloc);
60586 assert( (&p[1])==pEnd || p[0].db==p[1].db );
60603 sqlite3DbFree(db, p->zMalloc);
60609 db->mallocFailed = malloc_failed;
60625 sqlite3DbFree(p->v->db, p);
60651 sqlite3 *db = p->db; /* The database connection */
60670 db->mallocFailed = 1;
60706 }else if( db->u1.isInterrupted ){
60709 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(p->rc));
60777 assert( p->db->mallocFailed );
60794 assert( p->db->mallocFailed );
60935 assert( p->aMem[i].db==p->db );
60977 sqlite3 *db; /* The database connection */
60992 db = p->db;
60993 assert( db->mallocFailed==0 );
61048 p->pFree = sqlite3DbMallocZero(db, nByte);
61052 }while( nByte && !db->mallocFailed );
61060 p->aVar[n].db = db;
61073 p->aMem[n].db = db;
61088 sqlite3VdbeSorterClose(p->db, pCx);
61122 v->db->lastRowid = pFrame->lastRowid;
61172 sqlite3 *db = p->db;
61184 sqlite3DbFree(db, p->zErrMsg);
61198 sqlite3 *db = p->db;
61201 sqlite3DbFree(db, p->aColName);
61204 p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n );
61208 pColName->db = p->db;
61234 if( p->db->mallocFailed ){
61247 ** db. If a transaction is active, commit it. If there is a
61251 static int vdbeCommit(sqlite3 *db, Vdbe *p){
61270 rc = sqlite3VtabSync(db, &p->zErrMsg);
61278 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61279 Btree *pBt = db->aDb[i].pBt;
61291 if( needXcommit && db->xCommitCallback ){
61292 rc = db->xCommitCallback(db->pCommitArg);
61307 if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db->aDb[0].pBt))
61310 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61311 Btree *pBt = db->aDb[i].pBt;
61322 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61323 Btree *pBt = db->aDb[i].pBt;
61329 sqlite3VtabCommit(db);
61339 sqlite3_vfs *pVfs = db->pVfs;
61342 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
61351 zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
61382 sqlite3DbFree(db, zMaster);
61392 for(i=0; i<db->nDb; i++){
61393 Btree *pBt = db->aDb[i].pBt;
61408 sqlite3DbFree(db, zMaster);
61423 sqlite3DbFree(db, zMaster);
61427 /* Sync all the db files involved in the transaction. The same call
61437 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
61438 Btree *pBt = db->aDb[i].pBt;
61446 sqlite3DbFree(db, zMaster);
61455 sqlite3DbFree(db, zMaster);
61470 for(i=0; i<db->nDb; i++){
61471 Btree *pBt = db->aDb[i].pBt;
61479 sqlite3VtabCommit(db);
61496 static void checkActiveVdbeCnt(sqlite3 *db){
61500 p = db->pVdbe;
61508 assert( cnt==db->activeVdbeCnt );
61509 assert( nWrite==db->writeVdbeCnt );
61526 sqlite3 *const db = p->db;
61532 ** In this case (db->nStatement==0), and there is nothing to do.
61534 if( db->nStatement && p->iStatement ){
61539 assert( db->nStatement>0 );
61540 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
61542 for(i=0; i<db->nDb; i++){
61544 Btree *pBt = db->aDb[i].pBt;
61557 db->nStatement--;
61562 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
61565 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
61573 db->nDeferredCons = p->nStmtDefCons;
61591 sqlite3 *db = p->db;
61592 if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){
61595 sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed");
61617 sqlite3 *db = p->db;
61635 if( p->db->mallocFailed ){
61643 checkActiveVdbeCnt(db);
61679 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
61680 sqlite3CloseSavepoints(db);
61681 db->autoCommit = 1;
61697 if( !sqlite3VtabInSync(db)
61698 && db->autoCommit
61699 && db->writeVdbeCnt==(p->readOnly==0)
61714 rc = vdbeCommit(db, p);
61721 sqlite3RollbackAll(db, SQLITE_OK);
61723 db->nDeferredCons = 0;
61724 sqlite3CommitInternalChanges(db);
61727 sqlite3RollbackAll(db, SQLITE_OK);
61729 db->nStatement = 0;
61736 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
61737 sqlite3CloseSavepoints(db);
61738 db->autoCommit = 1;
61753 sqlite3DbFree(db, p->zErrMsg);
61756 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
61757 sqlite3CloseSavepoints(db);
61758 db->autoCommit = 1;
61767 sqlite3VdbeSetChanges(db, p->nChange);
61769 sqlite3VdbeSetChanges(db, 0);
61780 db->activeVdbeCnt--;
61782 db->writeVdbeCnt--;
61784 assert( db->activeVdbeCnt>=db->writeVdbeCnt );
61787 checkActiveVdbeCnt(db);
61788 if( p->db->mallocFailed ){
61793 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
61796 if( db->autoCommit ){
61797 sqlite3ConnectionUnlocked(db);
61800 assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 );
61822 sqlite3 *db = p->db;
61825 u8 mallocFailed = db->mallocFailed;
61827 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
61829 db->mallocFailed = mallocFailed;
61830 db->errCode = rc;
61832 sqlite3Error(db, rc, 0);
61849 sqlite3 *db;
61850 db = p->db;
61865 sqlite3DbFree(db, p->zErrMsg);
61873 sqlite3Error(db, p->rc, 0);
61874 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
61875 sqlite3DbFree(db, p->zErrMsg);
61908 return p->rc & db->errMask;
61919 assert( (rc & p->db->errMask)==rc );
61950 SQLITE_PRIVATE void sqlite3VdbeDeleteObject(sqlite3 *db, Vdbe *p){
61953 assert( p->db==0 || p->db==db );
61958 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
61959 sqlite3DbFree(db, pSub);
61961 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
61962 vdbeFreeOpArray(db, p->aOp, p->nOp);
61963 sqlite3DbFree(db, p->aLabel);
61964 sqlite3DbFree(db, p->aColName);
61965 sqlite3DbFree(db, p->zSql);
61966 sqlite3DbFree(db, p->pFree);
61968 sqlite3DbFree(db, p->zExplain);
61969 sqlite3DbFree(db, p->pExplain);
61971 sqlite3DbFree(db, p);
61978 sqlite3 *db;
61981 db = p->db;
61985 assert( db->pVdbe==p );
61986 db->pVdbe = p->pNext;
61992 p->db = 0;
61993 sqlite3VdbeDeleteObject(db, p);
62115 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
62381 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
62423 pMem->db = pKeyInfo->db;
62467 mem1.db = pKeyInfo->db;
62557 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
62565 UNUSED_PARAMETER(db);
62669 ** sqlite3_changes() on the database handle 'db'.
62671 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
62672 assert( sqlite3_mutex_held(db->mutex) );
62673 db->nChange = nChange;
62674 db->nTotalChange += nChange;
62695 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
62697 for(p = db->pVdbe; p; p=p->pNext){
62706 return v->db;
62722 sqlite3_value *pRet = sqlite3ValueNew(v->db);
62787 if( p->db==0 ){
62820 sqlite3 *db = v->db;
62826 mutex = v->db->mutex;
62830 rc = sqlite3ApiExit(db, rc);
62850 sqlite3_mutex_enter(v->db->mutex);
62853 assert( (rc & (v->db->errMask))==rc );
62854 rc = sqlite3ApiExit(v->db, rc);
62855 sqlite3_mutex_leave(v->db->mutex);
62868 sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
62957 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62961 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62965 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62971 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62977 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62981 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62985 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
62994 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63004 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63013 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63022 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63027 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63031 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63044 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63052 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63055 pCtx->s.db->mallocFailed = 1;
63062 static int doWalCallbacks(sqlite3 *db){
63066 for(i=0; i<db->nDb; i++){
63067 Btree *pBt = db->aDb[i].pBt;
63070 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
63071 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
63089 sqlite3 *db;
63122 db = p->db;
63123 if( db->mallocFailed ){
63138 if( db->activeVdbeCnt==0 ){
63139 db->u1.isInterrupted = 0;
63142 assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 );
63145 if( db->xProfile && !db->init.busy ){
63146 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
63150 db->activeVdbeCnt++;
63151 if( p->readOnly==0 ) db->writeVdbeCnt++;
63160 db->vdbeExecCnt++;
63162 db->vdbeExecCnt--;
63168 if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
63170 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
63171 db->xProfile(db->pProfileArg, p->zSql, (iNow - p->startTime)*1000000);
63177 p->rc = doWalCallbacks(db);
63183 db->errCode = rc;
63184 if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
63206 return (rc&db->errMask);
63227 sqlite3 *db; /* The database connection */
63232 db = v->db;
63233 sqlite3_mutex_enter(db->mutex);
63240 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
63249 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
63250 sqlite3DbFree(db, v->zErrMsg);
63251 if( !db->mallocFailed ){
63252 v->zErrMsg = sqlite3DbStrDup(db, zErr);
63259 rc = sqlite3ApiExit(db, rc);
63260 sqlite3_mutex_leave(db->mutex);
63285 return p->s.db;
63318 assert( sqlite3_mutex_held(p->s.db->mutex) );
63345 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63368 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63373 pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
63444 sqlite3_mutex_enter(pVm->db->mutex);
63468 if( pVm && ALWAYS(pVm->db) ){
63469 sqlite3_mutex_enter(pVm->db->mutex);
63470 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
63504 p->rc = sqlite3ApiExit(p->db, p->rc);
63505 sqlite3_mutex_leave(p->db->mutex);
63607 sqlite3 *db = p->db;
63609 assert( db!=0 );
63613 sqlite3_mutex_enter(db->mutex);
63614 assert( db->mallocFailed==0 );
63619 if( db->mallocFailed ){
63620 db->mallocFailed = 0;
63623 sqlite3_mutex_leave(db->mutex);
63732 ** The error code stored in database p->db is overwritten with the return
63740 sqlite3_mutex_enter(p->db->mutex);
63742 sqlite3Error(p->db, SQLITE_MISUSE, 0);
63743 sqlite3_mutex_leave(p->db->mutex);
63749 sqlite3Error(p->db, SQLITE_RANGE, 0);
63750 sqlite3_mutex_leave(p->db->mutex);
63757 sqlite3Error(p->db, SQLITE_OK, 0);
63797 rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
63799 sqlite3Error(p->db, rc, 0);
63800 rc = sqlite3ApiExit(p->db, rc);
63802 sqlite3_mutex_leave(p->db->mutex);
63828 sqlite3_mutex_leave(p->db->mutex);
63841 sqlite3_mutex_leave(p->db->mutex);
63850 sqlite3_mutex_leave(p->db->mutex);
63911 sqlite3_mutex_leave(p->db->mutex);
63970 assert( pTo->db==pFrom->db );
63972 sqlite3_mutex_enter(pTo->db->mutex);
63976 sqlite3_mutex_leave(pTo->db->mutex);
64016 return pStmt ? ((Vdbe*)pStmt)->db : 0;
64133 sqlite3 *db; /* The database connection */
64143 db = p->db;
64145 db->aLimit[SQLITE_LIMIT_LENGTH]);
64146 out.db = db;
64147 if( db->vdbeExecCnt>1 ){
64189 u8 enc = ENC(db);
64193 utf8.db = db;
64902 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
64914 ** assert( checkSavepointCount(db) );
64916 static int checkSavepointCount(sqlite3 *db){
64919 for(p=db->pSavepoint; p; p=p->pNext) n++;
64920 assert( n==(db->nSavepoint + db->isTransactionSavepoint) );
64931 sqlite3 *db = p->db;
64932 sqlite3DbFree(db, p->zErrMsg);
64933 p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
64977 sqlite3 *db = p->db; /* The database */
64979 u8 encoding = ENC(db); /* The database encoding */
64991 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
65144 Db *pDb;
65159 Db *pDb;
65298 Db *pDb;
65431 db->busyHandler.nBusy = 0;
65435 checkProgress = db->xProgress!=0;
65439 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65451 if( db->mallocFailed ) goto no_mem;
65478 sqlite3_interrupt(db);
65491 if( db->nProgressOps==nProgressOps ){
65493 prc = db->xProgress(db->pProgressArg);
65684 sqlite3VdbeSetChanges(db, p->nChange);
65686 lastRowid = db->lastRowid;
65705 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
65718 assert( rc==SQLITE_OK || db->nDeferredCons>0 );
65779 sqlite3DbFree(db, pOp->p4.z);
65786 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
65973 assert( db->flags&SQLITE_CountRows );
65993 assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
66016 if( db->mallocFailed ) goto no_mem;
66054 if( u.af.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
66269 u.ah.ctx.s.db = db;
66287 db->lastRowid = lastRowid;
66289 lastRowid = db->lastRowid;
66300 if( db->mallocFailed ){
66312 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ah.ctx.s));
66491 assert( pIn1->flags & MEM_Str || db->mallocFailed );
66511 assert( pIn1->flags & MEM_Str || db->mallocFailed );
66692 if( db->mallocFailed ) goto no_mem;
67100 assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
67101 if( u.an.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
67186 u.an.sMem.db = 0;
67419 if( u.ap.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67505 assert( db->pSavepoint==0 || db->autoCommit==0 );
67507 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
67508 assert( checkSavepointCount(db) );
67511 if( db->writeVdbeCnt>0 ){
67515 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
67525 ** that the db->aVTrans[] array is empty. */
67526 assert( db->autoCommit==0 || db->nVTrans==0 );
67527 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
67528 db->nStatement+db->nSavepoint);
67533 u.ar.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.ar.nName+1);
67540 if( db->autoCommit ){
67541 db->autoCommit = 0;
67542 db->isTransactionSavepoint = 1;
67544 db->nSavepoint++;
67548 u.ar.pNew->pNext = db->pSavepoint;
67549 db->pSavepoint = u.ar.pNew;
67550 u.ar.pNew->nDeferredCons = db->nDeferredCons;
67559 u.ar.pSavepoint = db->pSavepoint;
67566 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.ar.zName);
67568 }else if( db->writeVdbeCnt>0 && u.ar.p1==SAVEPOINT_RELEASE ){
67572 sqlite3SetString(&p->zErrMsg, db,
67582 int isTransaction = u.ar.pSavepoint->pNext==0 && db->isTransactionSavepoint;
67587 db->autoCommit = 1;
67590 db->autoCommit = 0;
67594 db->isTransactionSavepoint = 0;
67597 u.ar.iSavepoint = db->nSavepoint - u.ar.iSavepoint - 1;
67598 for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){
67599 sqlite3BtreeTripAllCursors(db->aDb[u.ar.ii].pBt, SQLITE_ABORT);
67601 for(u.ar.ii=0; u.ar.ii<db->nDb; u.ar.ii++){
67602 rc = sqlite3BtreeSavepoint(db->aDb[u.ar.ii].pBt, u.ar.p1, u.ar.iSavepoint);
67607 if( u.ar.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
67608 sqlite3ExpirePreparedStatements(db);
67609 sqlite3ResetInternalSchema(db, -1);
67610 db->flags = (db->flags | SQLITE_InternChanges);
67616 while( db->pSavepoint!=u.ar.pSavepoint ){
67617 u.ar.pTmp = db->pSavepoint;
67618 db->pSavepoint = u.ar.pTmp->pNext;
67619 sqlite3DbFree(db, u.ar.pTmp);
67620 db->nSavepoint--;
67628 assert( u.ar.pSavepoint==db->pSavepoint );
67629 db->pSavepoint = u.ar.pSavepoint->pNext;
67630 sqlite3DbFree(db, u.ar.pSavepoint);
67632 db->nSavepoint--;
67635 db->nDeferredCons = u.ar.pSavepoint->nDeferredCons;
67639 rc = sqlite3VtabSavepoint(db, u.ar.p1, u.ar.iSavepoint);
67666 u.as.turnOnAC = u.as.desiredAutoCommit && !db->autoCommit;
67669 assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
67672 if( u.as.turnOnAC && u.as.iRollback && db->activeVdbeCnt>1 ){
67677 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
67682 if( u.as.turnOnAC && !u.as.iRollback && db->writeVdbeCnt>0 ){
67686 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
67689 }else if( u.as.desiredAutoCommit!=db->autoCommit ){
67692 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
67693 db->autoCommit = 1;
67697 db->autoCommit = (u8)u.as.desiredAutoCommit;
67700 db->autoCommit = (u8)(1-u.as.desiredAutoCommit);
67705 assert( db->nStatement==0 );
67706 sqlite3CloseSavepoints(db);
67714 sqlite3SetString(&p->zErrMsg, db,
67760 assert( pOp->p1>=0 && pOp->p1<db->nDb );
67762 u.at.pBt = db->aDb[pOp->p1].pBt;
67776 && (db->autoCommit==0 || db->activeVdbeCnt>1)
67780 assert( db->nStatement>=0 && db->nSavepoint>=0 );
67781 db->nStatement++;
67782 p->iStatement = db->nSavepoint + db->nStatement;
67785 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
67793 p->nStmtDefCons = db->nDeferredCons;
67821 assert( u.au.iDb>=0 && u.au.iDb<db->nDb );
67822 assert( db->aDb[u.au.iDb].pBt!=0 );
67825 sqlite3BtreeGetMeta(db->aDb[u.au.iDb].pBt, u.au.iCookie, (u32 *)&u.au.iMeta);
67842 Db *pDb;
67845 assert( pOp->p1>=0 && pOp->p1<db->nDb );
67847 u.av.pDb = &db->aDb[pOp->p1];
67849 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
67857 db->flags |= SQLITE_InternChanges;
67865 sqlite3ExpirePreparedStatements(db);
67896 assert( pOp->p1>=0 && pOp->p1<db->nDb );
67898 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
67899 u.aw.pBt = db->aDb[pOp->p1].pBt;
67902 u.aw.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
67907 sqlite3DbFree(db, p->zErrMsg);
67908 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
67922 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.aw.iMeta ){
67923 sqlite3ResetInternalSchema(db, pOp->p1);
67991 Db *pDb;
68003 assert( u.ax.iDb>=0 && u.ax.iDb<db->nDb );
68005 u.ax.pDb = &db->aDb[u.ax.iDb];
68010 assert( sqlite3SchemaMutexHeld(db, u.ax.iDb, 0) );
68036 u.ax.pKeyInfo->enc = ENC(p->db);
68108 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ay.pCx->pBt,
68128 u.ay.pCx->pKeyInfo->enc = ENC(p->db);
68155 u.az.pCx->pKeyInfo->enc = ENC(p->db);
68157 rc = sqlite3VdbeSorterInit(db, u.az.pCx);
68512 sqlite3DbFree(db, u.bd.pFree);
68919 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bh.iKey;
68942 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
68943 u.bh.zDb = db->aDb[u.bh.pC->iDb].zName;
68947 db->xUpdateCallback(db->pUpdateArg, u.bh.op, u.bh.zDb, u.bh.zTbl, u.bh.iKey);
68988 if( db->xUpdateCallback && pOp->p4.z ){
69010 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
69011 const char *zDb = db->aDb[u.bi.pC->iDb].zName;
69013 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, u.bi.iKey);
69027 sqlite3VdbeSetChanges(db, p->nChange);
69134 if( u.bl.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69141 if( u.bl.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
69311 rc = sqlite3VdbeSorterRewind(db, u.bp.pC, &u.bp.res);
69382 rc = sqlite3VdbeSorterNext(db, u.bq.pC, &u.bq.res);
69440 rc = sqlite3VdbeSorterWrite(db, u.br.pC, pIn2);
69519 rc = sqlite3VdbeIdxRowid(db, u.bt.pCrsr, &u.bt.rowid);
69626 for(u.bv.pVdbe=db->pVdbe; u.bv.pVdbe; u.bv.pVdbe = u.bv.pVdbe->pNext){
69632 u.bv.iCnt = db->activeVdbeCnt;
69642 rc = sqlite3BtreeDropTable(db->aDb[u.bv.iDb].pBt, pOp->p1, &u.bv.iMoved);
69647 sqlite3RootPageMoved(db, u.bv.iDb, u.bv.iMoved, pOp->p1);
69683 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bw.nChange : 0)
69723 Db *pDb;
69727 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69729 u.bx.pDb = &db->aDb[pOp->p1];
69763 for(u.by.iDb=0; u.by.iDb<db->nDb; u.by.iDb++){
69764 assert( u.by.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.by.iDb].pBt) );
69769 assert( u.by.iDb>=0 && u.by.iDb<db->nDb );
69770 assert( DbHasProperty(db, u.by.iDb, DB_SchemaLoaded) );
69773 u.by.initData.db = db;
69776 u.by.zSql = sqlite3MPrintf(db,
69778 db->aDb[u.by.iDb].zName, u.by.zMaster, pOp->p4.z);
69782 assert( db->init.busy==0 );
69783 db->init.busy = 1;
69785 assert( !db->mallocFailed );
69786 rc = sqlite3_exec(db, u.by.zSql, sqlite3InitCallback, &u.by.initData, 0);
69788 sqlite3DbFree(db, u.by.zSql);
69789 db->init.busy = 0;
69792 if( rc ) sqlite3ResetInternalSchema(db, -1);
69807 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69808 rc = sqlite3AnalysisLoad(db, pOp->p1);
69821 sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p4.z);
69833 sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p4.z);
69845 sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
69883 u.bz.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.bz.nRoot+1) );
69894 assert( pOp->p5<db->nDb );
69896 u.bz.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bz.aRoot, u.bz.nRoot,
69898 sqlite3DbFree(db, u.bz.aRoot);
70066 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
70068 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
70087 u.cc.pFrame = sqlite3DbMallocZero(db, u.cc.nByte);
70112 u.cc.pMem->db = db;
70176 db->nDeferredCons += pOp->p2;
70196 if( db->nDeferredCons==0 ) pc = pOp->p2-1;
70326 u.cf.ctx.s.db = db;
70338 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cf.ctx.s));
70373 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cg.pMem));
70408 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ch.aRes[1], &u.ch.aRes[2]);
70450 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70452 u.ci.pBt = db->aDb[pOp->p1].pBt;
70474 if( !db->autoCommit || db->activeVdbeCnt>1 ){
70476 sqlite3SetString(&p->zErrMsg, db,
70533 rc = sqlite3RunVacuum(&p->zErrMsg, db);
70550 assert( pOp->p1>=0 && pOp->p1<db->nDb );
70552 u.cj.pBt = db->aDb[pOp->p1].pBt;
70573 sqlite3ExpirePreparedStatements(db);
70597 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){
70599 assert( p1>=0 && p1<db->nDb );
70602 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock);
70605 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z);
70627 rc = sqlite3VtabBegin(db, u.ck.pVTab);
70640 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
70653 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
70691 db->mallocFailed = 1;
70956 u8 vtabOnConflict = db->vtabOnConflict;
70966 db->vtabOnConflict = pOp->p5;
70968 db->vtabOnConflict = vtabOnConflict;
70972 db->lastRowid = lastRowid = u.cq.rowid;
70994 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
71013 pBt = db->aDb[pOp->p1].pBt;
71037 if( db->xTrace && (u.cr.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 ){
71039 db->xTrace(db->pTraceArg, u.cr.z);
71040 sqlite3DbFree(db, u.cr.z);
71043 if( (db->flags & SQLITE_SqlTrace)!=0
71122 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1;
71125 sqlite3ResetInternalSchema(db, resetSchemaOnFault-1);
71132 db->lastRowid = lastRowid;
71140 sqlite3SetString(&p->zErrMsg, db, "string or blob too big");
71147 db->mallocFailed = 1;
71148 sqlite3SetString(&p->zErrMsg, db, "out of memory");
71157 if( db->mallocFailed ) rc = SQLITE_NOMEM;
71159 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
71167 assert( db->u1.isInterrupted );
71170 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
71205 sqlite3 *db; /* The associated database */
71242 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
71264 zErr = sqlite3MPrintf(p->db, "no such rowid: %lld", iRow);
71267 zErr = sqlite3MPrintf(p->db, "%s", sqlite3_errmsg(p->db));
71282 sqlite3* db, /* The database connection */
71294 ** db/table/row entry. The reason for using a vdbe program instead
71335 sqlite3_mutex_enter(db->mutex);
71337 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
71339 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
71344 pParse->db = db;
71345 sqlite3DbFree(db, zErr);
71348 sqlite3BtreeEnterAll(db);
71362 sqlite3DbFree(db, zErr);
71367 sqlite3BtreeLeaveAll(db);
71378 sqlite3DbFree(db, zErr);
71379 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
71381 sqlite3BtreeLeaveAll(db);
71393 if( db->flags&SQLITE_ForeignKeys ){
71418 sqlite3DbFree(db, zErr);
71419 zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
71421 sqlite3BtreeLeaveAll(db);
71426 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
71427 assert( pBlob->pStmt || db->mallocFailed );
71430 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
71472 if( !db->mallocFailed ){
71482 pBlob->db = db;
71483 sqlite3BtreeLeaveAll(db);
71484 if( db->mallocFailed ){
71492 if( rc==SQLITE_OK && db->mallocFailed==0 ){
71496 sqlite3DbFree(db, pBlob);
71498 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
71499 sqlite3DbFree(db, zErr);
71500 sqlite3StackFree(db, pParse);
71501 rc = sqlite3ApiExit(db, rc);
71502 sqlite3_mutex_leave(db->mutex);
71513 sqlite3 *db;
71516 db = p->db;
71517 sqlite3_mutex_enter(db->mutex);
71519 sqlite3DbFree(db, p);
71520 sqlite3_mutex_leave(db->mutex);
71540 sqlite3 *db;
71543 db = p->db;
71544 sqlite3_mutex_enter(db->mutex);
71550 sqlite3Error(db, SQLITE_ERROR, 0);
71560 assert( db == v->db );
71568 db->errCode = rc;
71572 rc = sqlite3ApiExit(db, rc);
71573 sqlite3_mutex_leave(db->mutex);
71615 sqlite3 *db;
71618 db = p->db;
71619 sqlite3_mutex_enter(db->mutex);
71630 sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr);
71631 sqlite3DbFree(db, zErr);
71636 rc = sqlite3ApiExit(db, rc);
71638 sqlite3_mutex_leave(db->mutex);
71788 static void vdbeSorterIterZero(sqlite3 *db, VdbeSorterIter *pIter){
71789 sqlite3DbFree(db, pIter->aAlloc);
71798 sqlite3 *db, /* Database handle (for sqlite3DbMalloc() ) */
71814 vdbeSorterIterZero(db, pIter);
71826 pIter->aAlloc = sqlite3DbReallocOrFree(db, pIter->aAlloc, nNew);
71904 sqlite3 *db, /* Database handle */
71917 pIter->aAlloc = (u8 *)sqlite3DbMallocRaw(db, pIter->nAlloc);
71927 rc = vdbeSorterIterNext(db, pIter);
72029 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *db, VdbeCursor *pCsr){
72036 pCsr->pSorter = pSorter = sqlite3DbMallocZero(db, sizeof(VdbeSorter));
72045 if( !sqlite3TempInMemory(db) ){
72046 pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
72048 mxCache = db->aDb[0].pSchema->cache_size;
72059 static void vdbeSorterRecordFree(sqlite3 *db, SorterRecord *pRecord){
72064 sqlite3DbFree(db, p);
72071 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *db, VdbeCursor *pCsr){
72077 vdbeSorterIterZero(db, &pSorter->aIter[i]);
72079 sqlite3DbFree(db, pSorter->aIter);
72084 vdbeSorterRecordFree(db, pSorter->pRecord);
72085 sqlite3DbFree(db, pSorter->pUnpacked);
72086 sqlite3DbFree(db, pSorter);
72096 static int vdbeSorterOpenTempFile(sqlite3 *db, sqlite3_file **ppFile){
72098 return sqlite3OsOpenMalloc(db->pVfs, 0, ppFile,
72191 db, VdbeCursor *pCsr){
72204 rc = vdbeSorterOpenTempFile(db, &pSorter->pTemp1);
72227 sqlite3DbFree(db, p);
72253 sqlite3 *db, /* Database handle */
72264 pNew = (SorterRecord *)sqlite3DbMallocRaw(db, pVal->n + sizeof(SorterRecord));
72288 rc = vdbeSorterListToPMA(db, pCsr);
72299 sqlite3 *db, /* Database handle */
72311 rc = vdbeSorterIterInit(db, pSorter, pSorter->iReadOff, pIter, &nByte);
72330 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *db, VdbeCursor *pCsr, int *pbEof){
72351 rc = vdbeSorterListToPMA(db, pCsr);
72360 pSorter->aIter = (VdbeSorterIter *)sqlite3DbMallocZero(db, nByte);
72383 rc = vdbeSorterInitMerge(db, pCsr, &nWrite);
72392 rc = vdbeSorterOpenTempFile(db, &pTemp2);
72409 rc = sqlite3VdbeSorterNext(db, pCsr, &bEof);
72438 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *db, VdbeCursor *pCsr, int *pbEof){
72446 rc = vdbeSorterIterNext(db, &pSorter->aIter[iPrev]);
72456 vdbeSorterRecordFree(db, pFree);
73223 sqlite3 *db; /* The database connection */
73229 db = pParse->db;
73231 pDup = sqlite3ExprDup(db, pOrig, 0);
73239 pDup = sqlite3ExprDup(db, pOrig, 0);
73245 pDup = sqlite3ExprDup(db, pOrig, 0);
73250 pDup->u.zToken = sqlite3DbStrDup(db, zToken);
73262 sqlite3ExprDelete(db, pExpr);
73264 sqlite3DbFree(db, pDup);
73291 ** pExpr->iDb Set the index in db->aDb[] of the database X
73323 sqlite3 *db = pParse->db; /* The database connection */
73352 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73363 if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
73553 sqlite3ExprDelete(db, pExpr->pLeft);
73555 sqlite3ExprDelete(db, pExpr->pRight);
73580 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
73581 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
73694 u8 enc = ENC(pParse->db); /* The database encoding */
73700 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
73702 pDef = sqlite3FindFunction(pParse->db, zId, nId, -1, enc, 0);
73779 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
73841 sqlite3 *db; /* Database connection */
73843 u8 savedSuppErr; /* Saved value of db->suppressErr */
73856 db = pParse->db;
73857 savedSuppErr = db->suppressErr;
73858 db->suppressErr = 1;
73860 db->suppressErr = savedSuppErr;
73913 sqlite3 *db;
73918 db = pParse->db;
73920 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
73951 pDup = sqlite3ExprDup(db, pE, 0);
73952 if( !db->mallocFailed ){
73956 sqlite3ExprDelete(db, pDup);
73962 sqlite3ExprDelete(db, pE);
73963 pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0);
74003 sqlite3 *db = pParse->db;
74007 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
74009 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
74106 sqlite3 *db; /* Database connection */
74115 db = pParse->db;
74127 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
74184 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
74239 if( db->mallocFailed ){
74249 if( resolveOrderGroupBy(&sNC, p, pGroupBy, "GROUP") || db->mallocFailed ){
74471 sqlite3 *db = pParse->db;
74472 zColl = sqlite3NameFromToken(db, pCollName);
74475 sqlite3DbFree(db, zColl);
74499 sqlite3 *db = pParse->db;
74501 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
74660 int mxHeight = pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
74770 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
74786 pNew = sqlite3DbMallocZero(db, sizeof(Expr)+nExtra);
74819 sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */
74826 return sqlite3ExprAlloc(db, op, &x, 0);
74836 sqlite3 *db,
74842 assert( db->mallocFailed );
74843 sqlite3ExprDelete(db, pLeft);
74844 sqlite3ExprDelete(db, pRight);
74868 ** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
74878 Expr *p = sqlite3ExprAlloc(pParse->db, op, pToken, 1);
74879 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
74890 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
74896 Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
74897 sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
74908 sqlite3 *db = pParse->db;
74910 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
74912 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
74938 sqlite3 *db = pParse->db;
74961 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
74962 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
74963 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
74965 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
74988 a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
74989 if( a==0 ) return; /* Error reported through db->mallocFailed */
74995 sqlite3DbFree(db, pParse->azVar[x-1]);
74996 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
75000 if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
75008 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
75013 sqlite3ExprDelete(db, p->pLeft);
75014 sqlite3ExprDelete(db, p->pRight);
75016 sqlite3DbFree(db, p->u.zToken);
75019 sqlite3SelectDelete(db, p->x.pSelect);
75021 sqlite3ExprListDelete(db, p->x.pList);
75025 sqlite3DbFree(db, p);
75138 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
75152 zAlloc = sqlite3DbMallocRaw(db, dupedExprSize(p, flags));
75193 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
75195 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
75203 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
75204 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
75212 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
75213 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
75239 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
75240 return exprDup(db, p, flags, 0);
75242 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
75247 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
75252 pNew->a = pItem = sqlite3DbMallocRaw(db, i*sizeof(p->a[0]) );
75254 sqlite3DbFree(db, pNew);
75260 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
75261 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
75262 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
75279 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, SrcList *p, int flags){
75285 pNew = sqlite3DbMallocRaw(db, nByte );
75292 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
75293 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
75294 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
75300 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
75307 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
75308 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
75309 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
75314 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){
75318 pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) );
75321 pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) );
75323 sqlite3DbFree(db, pNew);
75332 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
75337 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
75340 pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
75342 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
75343 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
75344 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
75345 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
75346 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
75347 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
75349 pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
75352 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
75353 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
75364 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
75384 sqlite3 *db = pParse->db;
75386 pList = sqlite3DbMallocZero(db, sizeof(ExprList) );
75390 pList->a = sqlite3DbMallocRaw(db, sizeof(pList->a[0]));
75395 a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
75411 sqlite3ExprDelete(db, pExpr);
75412 sqlite3ExprListDelete(db, pList);
75421 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
75430 assert( pList!=0 || pParse->db->mallocFailed!=0 );
75436 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
75446 ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
75454 sqlite3 *db = pParse->db;
75455 assert( pList!=0 || db->mallocFailed!=0 );
75459 assert( db->mallocFailed || pItem->pExpr==pSpan->pExpr );
75460 sqlite3DbFree(db, pItem->zSpan);
75461 pItem->zSpan = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
75475 int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
75486 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
75492 sqlite3ExprDelete(db, pItem->pExpr);
75493 sqlite3DbFree(db, pItem->zName);
75494 sqlite3DbFree(db, pItem->zSpan);
75496 sqlite3DbFree(db, pList->a);
75497 sqlite3DbFree(db, pList);
75850 sqlite3 *db = pParse->db; /* Database connection */
75865 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
75900 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
76013 pParse->db, "EXECUTE %s%s SUBQUERY %d", testAddr>=0?"":"CORRELATED ",
76163 sqlite3ExprDelete(pParse->db, pSel->pLimit);
76417 if( pParse->db->flags & SQLITE_ColumnCache ) return;
76677 sqlite3 *db = pParse->db; /* The database connection */
76681 assert( pParse->db->mallocFailed );
76946 u8 enc = ENC(db); /* The text encoding used by this database */
76961 pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
77009 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
77011 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
77023 if( !pColl ) pColl = db->pDfltColl;
77232 assert( db->mallocFailed || pParse->nErr>0
77303 assert( pParse->pVdbe || pParse->db->mallocFailed );
77726 if( (pParse->db->flags & SQLITE_FactorOutConst)!=0 ) return;
78165 static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){
78168 db,
78181 static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
78184 db,
78233 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
78291 u8 enc = ENC(pParse->db);
78292 i = addAggInfoFunc(pParse->db, pAggInfo);
78299 pItem->pFunc = sqlite3FindFunction(pParse->db,
78482 sqlite3 *db = sqlite3_context_db_handle(context);
78511 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
78538 sqlite3 *db = sqlite3_context_db_handle(context);
78559 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
78563 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
78566 sqlite3DbFree(db, zOutput);
78570 sqlite3DbFree(db, zParent);
78574 zResult = sqlite3MPrintf(db, "%s%s", (zOutput?zOutput:""), zInput),
78576 sqlite3DbFree(db, zOutput);
78602 sqlite3 *db = sqlite3_context_db_handle(context);
78650 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
78695 static char *whereOrName(sqlite3 *db, char *zWhere, char *zConstant){
78698 zNew = sqlite3MPrintf(db, "name=%Q", zConstant);
78700 zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
78701 sqlite3DbFree(db, zWhere);
78717 zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
78732 const Schema *pTempSchema = pParse->db->aDb[1].pSchema; /* Temp db schema */
78734 /* If the table is not located in the temp-db (in which case NULL is
78736 ** that is not part of the temp-db schema, add a clause to the WHERE
78740 sqlite3 *db = pParse->db;
78743 zWhere = whereOrName(db, zWhere, pTrig->zName);
78748 char *zNew = sqlite3MPrintf(pParse->db, "type='trigger' AND (%s)", zWhere);
78749 sqlite3DbFree(pParse->db, zWhere);
78773 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
78774 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78780 int iTrigDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
78790 zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
78833 sqlite3 *db = pParse->db; /* Database connection */
78841 int savedDbFlags; /* Saved value of db->flags */
78843 savedDbFlags = db->flags;
78844 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
78846 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
78850 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
78851 zDb = db->aDb[iDb].zName;
78852 db->flags |= SQLITE_PreferBuiltin;
78855 zName = sqlite3NameFromToken(db, pName);
78861 if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
78896 pVTab = sqlite3GetVTable(db, pTab);
78934 if( db->flags&SQLITE_ForeignKeys ){
78943 sqlite3DbFree(db, zWhere);
78977 if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
78995 sqlite3DbFree(db, zWhere);
79000 if( db->flags&SQLITE_ForeignKeys ){
79015 sqlite3SrcListDelete(db, pSrc);
79016 sqlite3DbFree(db, zName);
79017 db->flags = savedDbFlags;
79063 sqlite3 *db; /* The database connection; */
79065 db = pParse->db;
79066 if( pParse->nErr || db->mallocFailed ) return;
79070 assert( sqlite3BtreeHoldsAllMutexes(db) );
79071 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
79072 zDb = db->aDb[iDb].zName;
79076 pTab = sqlite3FindTable(db, zTab, zDb);
79106 if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
79122 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
79123 db->mallocFailed = 1;
79134 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
79137 int savedDbFlags = db->flags;
79141 db->flags |= SQLITE_PreferBuiltin;
79149 sqlite3DbFree(db, zCol);
79150 db->flags = savedDbFlags;
79185 sqlite3 *db = pParse->db;
79189 assert( sqlite3BtreeHoldsAllMutexes(db) );
79190 if( db->mallocFailed ) goto exit_begin_add_column;
79211 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79220 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
79228 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
79229 pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
79231 db->mallocFailed = 1;
79237 pCol->zName = sqlite3DbStrDup(db, pCol->zName);
79243 pNew->pSchema = db->aDb[iDb].pSchema;
79254 sqlite3SrcListDelete(db, pSrc);
79415 sqlite3 *db = pParse->db;
79416 Db *pDb;
79419 assert( sqlite3BtreeHoldsAllMutexes(db) );
79420 assert( sqlite3VdbeDb(v)==db );
79421 pDb = &db->aDb[iDb];
79429 if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
79695 sqlite3 *db = pParse->db; /* Database handle */
79740 assert( sqlite3BtreeHoldsAllMutexes(db) );
79741 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
79743 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
79746 db->aDb[iDb].zName ) ){
79765 aChngAddr = sqlite3DbMallocRaw(db, sizeof(int)*nCol);
79773 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
79866 sqlite3DbFree(db, aChngAddr);
79978 sqlite3 *db = pParse->db;
79979 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
79989 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
80007 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
80008 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
80034 sqlite3 *db = pParse->db;
80044 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
80052 for(i=0; i<db->nDb; i++){
80058 iDb = sqlite3FindDb(db, pName1);
80062 z = sqlite3NameFromToken(db, pName1);
80064 if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
80069 sqlite3DbFree(db, z);
80076 zDb = db->aDb[iDb].zName;
80077 z = sqlite3NameFromToken(db, pTableName);
80079 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
80084 sqlite3DbFree(db, z);
80096 sqlite3 *db;
80125 pTable = sqlite3FindTable(pInfo->db, argv[0], pInfo->zDatabase);
80130 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
80158 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
80165 sqlite3DbFree(db, p->u.z);
80168 sqlite3DbFree(db, pIdx->aSample);
80170 if( db && db->pnBytesFreed==0 ){
80175 UNUSED_PARAMETER(db);
80185 static int loadStat3(sqlite3 *db, const char *zDb){
80194 assert( db->lookaside.bEnabled==0 );
80195 if( !sqlite3FindTable(db, "sqlite_stat3", zDb) ){
80199 zSql = sqlite3MPrintf(db,
80205 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
80206 sqlite3DbFree(db, zSql);
80217 pIdx = sqlite3FindIndex(db, zIndex, zDb);
80221 pIdx->aSample = sqlite3DbMallocZero(db, nSample*sizeof(IndexSample));
80224 db->mallocFailed = 1;
80232 zSql = sqlite3MPrintf(db,
80237 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
80238 sqlite3DbFree(db, zSql);
80249 pIdx = sqlite3FindIndex(db, zIndex, zDb);
80294 pSample->u.z = sqlite3DbMallocRaw(db, n);
80296 db->mallocFailed = 1;
80325 ** If an OOM error occurs, this function always sets db->mallocFailed.
80329 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
80335 assert( iDb>=0 && iDb<db->nDb );
80336 assert( db->aDb[iDb].pBt!=0 );
80339 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
80340 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
80344 sqlite3DeleteIndexSamples(db, pIdx);
80350 sInfo.db = db;
80351 sInfo.zDatabase = db->aDb[iDb].zName;
80352 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
80357 zSql = sqlite3MPrintf(db,
80362 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
80363 sqlite3DbFree(db, zSql);
80370 int lookasideEnabled = db->lookaside.bEnabled;
80371 db->lookaside.bEnabled = 0;
80372 rc = loadStat3(db, sInfo.zDatabase);
80373 db->lookaside.bEnabled = lookasideEnabled;
80378 db->mallocFailed = 1;
80456 sqlite3 *db = sqlite3_context_db_handle(context);
80462 Db *aNew;
80479 if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
80480 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
80481 db->aLimit[SQLITE_LIMIT_ATTACHED]
80485 if( !db->autoCommit ){
80486 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
80489 for(i=0; i<db->nDb; i++){
80490 char *z = db->aDb[i].zName;
80493 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
80498 /* Allocate the new entry in the db->aDb[] array and initialise the schema
80501 if( db->aDb==db->aDbStatic ){
80502 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 );
80504 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
80506 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
80509 db->aDb = aNew;
80510 aNew = &db->aDb[db->nDb];
80517 flags = db->openFlags;
80518 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
80520 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
80527 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
80529 db->nDb++;
80532 zErrDyn = sqlite3MPrintf(db, "database is already attached");
80535 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
80538 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
80539 zErrDyn = sqlite3MPrintf(db,
80544 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
80546 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
80549 aNew->zName = sqlite3DbStrDup(db, zName);
80565 zErrDyn = sqlite3DbStrDup(db, "Invalid key value");
80573 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
80578 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
80579 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){
80580 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
80589 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
80593 sqlite3BtreeEnterAll(db);
80594 rc = sqlite3Init(db, &zErrDyn);
80595 sqlite3BtreeLeaveAll(db);
80598 int iDb = db->nDb - 1;
80600 if( db->aDb[iDb].pBt ){
80601 sqlite3BtreeClose(db->aDb[iDb].pBt);
80602 db->aDb[iDb].pBt = 0;
80603 db->aDb[iDb].pSchema = 0;
80605 sqlite3ResetInternalSchema(db, -1);
80606 db->nDb = iDb;
80608 db->mallocFailed = 1;
80609 sqlite3DbFree(db, zErrDyn);
80610 zErrDyn = sqlite3MPrintf(db, "out of memory");
80612 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
80623 sqlite3DbFree(db, zErrDyn);
80642 sqlite3 *db = sqlite3_context_db_handle(context);
80644 Db *pDb = 0;
80650 for(i=0; i<db->nDb; i++){
80651 pDb = &db->aDb[i];
80656 if( i>=db->nDb ){
80664 if( !db->autoCommit ){
80677 sqlite3ResetInternalSchema(db, -1);
80700 sqlite3* db = pParse->db;
80737 assert( v || db->mallocFailed );
80752 sqlite3ExprDelete(db, pFilename);
80753 sqlite3ExprDelete(db, pDbname);
80754 sqlite3ExprDelete(db, pKey);
80816 sqlite3 *db;
80819 db = pParse->db;
80820 assert( db->nDb>iDb );
80822 pFix->zDb = db->aDb[iDb].zName;
80854 pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb);
81016 sqlite3 *db,
81020 sqlite3_mutex_enter(db->mutex);
81021 db->xAuth = xAuth;
81022 db->pAuthArg = pArg;
81023 sqlite3ExpirePreparedStatements(db);
81024 sqlite3_mutex_leave(db->mutex);
81052 sqlite3 *db = pParse->db; /* Database handle */
81053 char *zDb = db->aDb[iDb].zName; /* Name of attached database */
81056 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext);
81058 if( db->nDb>2 || iDb!=0 ){
81085 sqlite3 *db = pParse->db;
81092 if( db->xAuth==0 ) return;
81093 iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
81124 assert( iDb>=0 && iDb<db->nDb );
81143 sqlite3 *db = pParse->db;
81149 if( db->init.busy || IN_DECLARE_VTAB ){
81153 if( db->xAuth==0 ){
81156 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
81277 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
81286 pToplevel->db->mallocFailed = 1;
81323 sqlite3 *db;
81326 db = pParse->db;
81327 if( db->mallocFailed ) return;
81350 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
81354 if( db->init.busy==0 ){
81355 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81358 db->aDb[iDb].pSchema->iGeneration);
81365 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
81390 if( v && ALWAYS(pParse->nErr==0) && !db->mallocFailed ){
81392 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
81429 db = pParse->db;
81436 zSql = sqlite3VMPrintf(db, zFormat, ap);
81445 sqlite3DbFree(db, zErrMsg);
81446 sqlite3DbFree(db, zSql);
81463 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
81470 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
81471 for(i=OMIT_TEMPDB; i<db->nDb; i++){
81473 if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
81474 assert( sqlite3SchemaMutexHeld(db, j, 0) );
81475 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
81505 p = sqlite3FindTable(pParse->db, zName, zDbase);
81530 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
81535 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
81536 for(i=OMIT_TEMPDB; i<db->nDb; i++){
81538 Schema *pSchema = db->aDb[j].pSchema;
81540 if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
81541 assert( sqlite3SchemaMutexHeld(db, j, 0) );
81551 static void freeIndex(sqlite3 *db, Index *p){
81553 sqlite3DeleteIndexSamples(db, p);
81555 sqlite3DbFree(db, p->zColAff);
81556 sqlite3DbFree(db, p);
81565 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
81570 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81571 pHash = &db->aDb[iDb].pSchema->idxHash;
81587 freeIndex(db, pIndex);
81589 db->flags |= SQLITE_InternChanges;
81603 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
81605 assert( iDb<db->nDb );
81609 Db *pDb = &db->aDb[iDb];
81610 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81619 pDb = &db->aDb[1];
81628 sqlite3BtreeEnterAll(db);
81629 for(i=0; i<db->nDb; i++){
81630 Db *pDb = &db->aDb[i];
81635 db->flags &= ~SQLITE_InternChanges;
81636 sqlite3VtabUnlockList(db);
81637 sqlite3BtreeLeaveAll(db);
81645 for(i=j=2; i<db->nDb; i++){
81646 struct Db *pDb = &db->aDb[i];
81648 sqlite3DbFree(db, pDb->zName);
81653 db->aDb[j] = db->aDb[i];
81657 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j]));
81658 db->nDb = j;
81659 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){
81660 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0]));
81661 sqlite3DbFree(db, db->aDb);
81662 db->aDb = db->aDbStatic;
81669 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
81670 db->flags &= ~SQLITE_InternChanges;
81677 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
81683 sqlite3DbFree(db, pCol->zName);
81684 sqlite3ExprDelete(db, pCol->pDflt);
81685 sqlite3DbFree(db, pCol->zDflt);
81686 sqlite3DbFree(db, pCol->zType);
81687 sqlite3DbFree(db, pCol->zColl);
81689 sqlite3DbFree(db, pTable->aCol);
81702 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
81709 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
81715 if( !db || db->pnBytesFreed==0 ){
81720 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
81723 freeIndex(db, pIndex);
81727 sqlite3FkDelete(db, pTable);
81731 sqliteDeleteColumnNames(db, pTable);
81732 sqlite3DbFree(db, pTable->zName);
81733 sqlite3DbFree(db, pTable->zColAff);
81734 sqlite3SelectDelete(db, pTable->pSelect);
81736 sqlite3ExprDelete(db, pTable->pCheck);
81739 sqlite3VtabClear(db, pTable);
81741 sqlite3DbFree(db, pTable);
81748 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
81750 Db *pDb;
81752 assert( db!=0 );
81753 assert( iDb>=0 && iDb<db->nDb );
81755 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
81757 pDb = &db->aDb[iDb];
81760 sqlite3DeleteTable(db, p);
81761 db->flags |= SQLITE_InternChanges;
81777 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3 *db, Token *pName){
81780 zName = sqlite3DbStrNDup(db, (char*)pName->z, pName->n);
81804 ** of a database ("main", "temp" or the name of an attached db). This
81805 ** function returns the index of the named database in db->aDb[], or
81806 ** -1 if the named db cannot be found.
81808 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
81811 Db *pDb;
81813 for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
81825 ** "temp" or the name of an attached db). This routine returns the
81826 ** index of the named database in db->aDb[], or -1 if the named db
81829 SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
81832 zName = sqlite3NameFromToken(db, pName);
81833 i = sqlite3FindDbName(db, zName);
81834 sqlite3DbFree(db, zName);
81861 sqlite3 *db = pParse->db;
81864 if( db->init.busy ) {
81870 iDb = sqlite3FindDb(db, pName1);
81877 assert( db->init.iDb==0 || db->init.busy );
81878 iDb = db->init.iDb;
81892 if( !pParse->db->init.busy && pParse->nested==0
81893 && (pParse->db->flags & SQLITE_WriteSchema)==0
81928 sqlite3 *db = pParse->db;
81961 zName = sqlite3NameFromToken(db, pName);
81966 if( db->init.iDb==1 ) isTemp = 1;
81971 char *zDb = db->aDb[iDb].zName;
82002 char *zDb = db->aDb[iDb].zName;
82006 pTable = sqlite3FindTable(db, zName, zDb);
82011 assert( !db->init.busy );
82016 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
82022 pTable = sqlite3DbMallocZero(db, sizeof(Table));
82024 db->mallocFailed = 1;
82031 pTable->pSchema = db->aDb[iDb].pSchema;
82043 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82056 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
82077 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
82081 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
82115 sqlite3DbFree(db, zName);
82145 sqlite3 *db = pParse->db;
82148 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
82153 z = sqlite3NameFromToken(db, pName);
82158 sqlite3DbFree(db, z);
82164 aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+8)*sizeof(p->aCol[0]));
82166 sqlite3DbFree(db, z);
82274 pCol->zType = sqlite3NameFromToken(pParse->db, pType);
82291 sqlite3 *db = pParse->db;
82303 sqlite3ExprDelete(db, pCol->pDflt);
82304 pCol->pDflt = sqlite3ExprDup(db, pSpan->pExpr, EXPRDUP_REDUCE);
82305 sqlite3DbFree(db, pCol->zDflt);
82306 pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
82310 sqlite3ExprDelete(db, pSpan->pExpr);
82388 sqlite3ExprListDelete(pParse->db, pList);
82399 sqlite3 *db = pParse->db;
82403 pTab->pCheck = sqlite3ExprAnd(db, pTab->pCheck, pCheckExpr);
82407 sqlite3ExprDelete(db, pCheckExpr);
82419 sqlite3 *db;
82423 db = pParse->db;
82424 zColl = sqlite3NameFromToken(db, pToken);
82442 sqlite3DbFree(db, zColl);
82467 sqlite3 *db = pParse->db;
82468 u8 enc = ENC(db);
82469 u8 initbusy = db->init.busy;
82472 pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
82474 pColl = sqlite3GetCollSeq(db, enc, pColl, zName);
82502 sqlite3 *db = pParse->db;
82504 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82505 sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
82567 static char *createTableStmt(sqlite3 *db, Table *p){
82589 db->mallocFailed = 1;
82640 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
82658 sqlite3 *db = pParse->db;
82661 if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
82667 assert( !db->init.busy || !pSelect );
82669 iDb = sqlite3SchemaToIndex(db, p->pSchema);
82693 /* If the db->init.busy is 1 it means we are reading the SQL off the
82696 ** for the table from the db->init.newTnum field. (The page number
82699 if( db->init.busy ){
82700 p->tnum = db->init.newTnum;
82709 if( !db->init.busy ){
82768 sqlite3DeleteTable(db, pSelTab);
82774 zStmt = createTableStmt(db, p);
82777 zStmt = sqlite3MPrintf(db,
82790 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
82798 sqlite3DbFree(db, zStmt);
82806 Db *pDb = &db->aDb[iDb];
82807 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82819 sqlite3MPrintf(db, "tbl_name='%q'", p->zName));
82825 if( db->init.busy ){
82828 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
82833 db->mallocFailed = 1;
82837 db->flags |= SQLITE_InternChanges;
82874 sqlite3 *db = pParse->db;
82878 sqlite3SelectDelete(db, pSelect);
82884 sqlite3SelectDelete(db, pSelect);
82888 iDb = sqlite3SchemaToIndex(db, p->pSchema);
82892 sqlite3SelectDelete(db, pSelect);
82901 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
82902 sqlite3SelectDelete(db, pSelect);
82903 if( db->mallocFailed ){
82906 if( !db->init.busy ){
82941 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
82988 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
82990 u8 enableLookaside = db->lookaside.bEnabled;
82994 db->lookaside.bEnabled = 0;
82996 xAuth = db->xAuth;
82997 db->xAuth = 0;
82999 db->xAuth = xAuth;
83003 db->lookaside.bEnabled = enableLookaside;
83011 sqlite3DeleteTable(db, pSelTab);
83012 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
83018 sqlite3SelectDelete(db, pSel);
83031 static void sqliteViewResetAll(sqlite3 *db, int idx){
83033 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
83034 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
83035 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
83038 sqliteDeleteColumnNames(db, pTab);
83043 DbClearProperty(db, idx, DB_UnresetViews);
83067 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){
83070 Db *pDb;
83072 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
83073 pDb = &db->aDb[iDb];
83114 pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable, r1, r1);
83128 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
83170 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
83189 const char *zDbName = pParse->db->aDb[iDb].zName;
83193 if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
83207 sqlite3 *db = pParse->db;
83209 Db *pDb = &db->aDb[iDb];
83228 pTrigger->pSchema==db->aDb[1].pSchema );
83269 sqliteViewResetAll(db, iDb);
83279 sqlite3 *db = pParse->db;
83282 if( db->mallocFailed ){
83287 if( noErr ) db->suppressErr++;
83290 if( noErr ) db->suppressErr--;
83296 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
83297 assert( iDb>=0 && iDb<db->nDb );
83309 const char *zDb = db->aDb[iDb].zName;
83323 zArg2 = sqlite3GetVTable(db, pTab)->pMod->zName;
83372 sqlite3SrcListDelete(db, pName);
83398 sqlite3 *db = pParse->db;
83434 pFKey = sqlite3DbMallocZero(db, nByte );
83479 assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
83484 db->mallocFailed = 1;
83499 sqlite3DbFree(db, pFKey);
83501 sqlite3ExprListDelete(db, pFromCol);
83502 sqlite3ExprListDelete(db, pToCol);
83547 sqlite3 *db = pParse->db; /* The database connection */
83548 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
83552 db->aDb[iDb].zName ) ){
83679 sqlite3 *db = pParse->db;
83680 Db *pDb; /* The specific table containing the indexed database */
83690 if( db->mallocFailed || IN_DECLARE_VTAB ){
83703 ** to search for the table. 'Fix' the table name to this db
83716 if( !db->init.busy ){
83718 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
83733 if( !pTab || db->mallocFailed ) goto exit_create_index;
83734 assert( db->aDb[iDb].pSchema==pTab->pSchema );
83740 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
83742 pDb = &db->aDb[iDb];
83778 zName = sqlite3NameFromToken(db, pName);
83784 if( !db->init.busy ){
83785 if( sqlite3FindTable(db, zName, 0)!=0 ){
83790 if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
83794 assert( !db->init.busy );
83803 zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
83858 pIndex = sqlite3DbMallocZero(db,
83867 if( db->mallocFailed ){
83885 pIndex->pSchema = db->aDb[iDb].pSchema;
83886 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
83939 zColl = db->pDfltColl->zName;
83942 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
84014 if( db->init.busy ){
84016 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
84022 db->mallocFailed = 1;
84025 db->flags |= SQLITE_InternChanges;
84027 pIndex->tnum = db->init.newTnum;
84031 /* If the db->init.busy is 0 then create the index on disk. This
84035 ** The db->init.busy is 0 when the user first enters a CREATE INDEX
84036 ** command. db->init.busy is 1 when a database is opened and
84046 else{ /* if( db->init.busy==0 ) */
84066 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
84080 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
84086 sqlite3DbFree(db, zStmt);
84095 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
84106 if( db->init.busy || pTblName==0 ){
84126 sqlite3DbFree(db, pIndex->zColAff);
84127 sqlite3DbFree(db, pIndex);
84129 sqlite3ExprListDelete(db, pList);
84130 sqlite3SrcListDelete(db, pTblName);
84131 sqlite3DbFree(db, zName);
84177 sqlite3 *db = pParse->db;
84181 if( db->mallocFailed ){
84188 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
84203 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
84208 const char *zDb = db->aDb[iDb].zName;
84226 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), pIndex->zName
84235 sqlite3SrcListDelete(db, pName);
84254 sqlite3 *db, /* Connection to notify of malloc failures */
84264 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
84284 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){
84287 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
84291 db,
84298 sqlite3IdListDelete(db, pList);
84301 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
84308 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
84312 sqlite3DbFree(db, pList->a[i].zName);
84314 sqlite3DbFree(db, pList->a);
84315 sqlite3DbFree(db, pList);
84339 ** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
84348 ** db->mallocFailed flag will be set to true.
84351 sqlite3 *db, /* Database connection to notify of OOM errors */
84369 pNew = sqlite3DbRealloc(db, pSrc,
84372 assert( db->mallocFailed );
84376 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
84433 sqlite3 *db, /* Connection to notify of malloc failures */
84441 pList = sqlite3DbMallocZero(db, sizeof(SrcList) );
84445 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
84446 if( db->mallocFailed ){
84447 sqlite3SrcListDelete(db, pList);
84459 pItem->zName = sqlite3NameFromToken(db, pTable);
84460 pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
84470 assert(pList || pParse->db->mallocFailed );
84485 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
84490 sqlite3DbFree(db, pItem->zDatabase);
84491 sqlite3DbFree(db, pItem->zName);
84492 sqlite3DbFree(db, pItem->zAlias);
84493 sqlite3DbFree(db, pItem->zIndex);
84494 sqlite3DeleteTable(db, pItem->pTab);
84495 sqlite3SelectDelete(db, pItem->pSelect);
84496 sqlite3ExprDelete(db, pItem->pOn);
84497 sqlite3IdListDelete(db, pItem->pUsing);
84499 sqlite3DbFree(db, pList);
84529 sqlite3 *db = pParse->db;
84536 p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
84543 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
84552 sqlite3ExprDelete(db, pOn);
84553 sqlite3IdListDelete(db, pUsing);
84554 sqlite3SelectDelete(db, pSubquery);
84572 pItem->zIndex = sqlite3NameFromToken(pParse->db, pIndexedBy);
84607 sqlite3 *db;
84612 db = pParse->db;
84613 assert( db!=0 );
84614 /* if( db->aDb[0].pBt==0 ) return; */
84621 for(i=0; i<db->nDb; i++){
84636 assert( pParse->db!=0 );
84653 assert( pParse->db!=0 );
84668 char *zName = sqlite3NameFromToken(pParse->db, pName);
84676 sqlite3DbFree(pParse->db, zName);
84688 sqlite3 *db = pParse->db;
84689 if( db->aDb[1].pBt==0 && !pParse->explain ){
84699 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
84706 db->aDb[1].pBt = pBt;
84707 assert( db->aDb[1].pSchema );
84708 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
84709 db->mallocFailed = 1;
84747 sqlite3 *db = pToplevel->db;
84750 assert( iDb<db->nDb );
84751 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
84753 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84757 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
84770 sqlite3 *db = pParse->db;
84772 for(i=0; i<db->nDb; i++){
84773 Db *pDb = &db->aDb[i];
84875 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
84890 Db *pDb; /* A single database */
84892 sqlite3 *db = pParse->db; /* The database connection */
84896 assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */
84897 for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){
84928 sqlite3 *db = pParse->db; /* The database connection */
84943 zColl = sqlite3NameFromToken(pParse->db, pName1);
84945 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
84948 sqlite3DbFree(db, zColl);
84951 sqlite3DbFree(db, zColl);
84955 z = sqlite3NameFromToken(db, pObjName);
84957 zDb = db->aDb[iDb].zName;
84958 pTab = sqlite3FindTable(db, z, zDb);
84961 sqlite3DbFree(db, z);
84964 pIndex = sqlite3FindIndex(db, z, zDb);
84965 sqlite3DbFree(db, z);
84980 ** the caller is responsible for calling sqlite3DbFree(db, ) on the returned
84989 sqlite3 *db = pParse->db;
84990 KeyInfo *pKey = (KeyInfo *)sqlite3DbMallocZero(db, nBytes);
84993 pKey->db = pParse->db;
85006 sqlite3DbFree(db, pKey);
85035 static void callCollNeeded(sqlite3 *db, int enc, const char *zName){
85036 assert( !db->xCollNeeded || !db->xCollNeeded16 );
85037 if( db->xCollNeeded ){
85038 char *zExternal = sqlite3DbStrDup(db, zName);
85040 db->xCollNeeded(db->pCollNeededArg, db, enc, zExternal);
85041 sqlite3DbFree(db, zExternal);
85044 if( db->xCollNeeded16 ){
85046 sqlite3_value *pTmp = sqlite3ValueNew(db);
85050 db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
85064 static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
85070 pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0);
85089 ** db for collation type name zName, length nName, or NULL, if no collation
85095 sqlite3* db, /* The database connection */
85104 p = sqlite3FindCollSeq(db, enc, zName, 0);
85110 callCollNeeded(db, enc, zName);
85111 p = sqlite3FindCollSeq(db, enc, zName, 0);
85113 if( p && !p->xCmp && synthCollSeq(db, p) ){
85134 sqlite3 *db = pParse->db;
85135 CollSeq *p = sqlite3GetCollSeq(db, ENC(db), pColl, zName);
85149 ** Locate and return an entry from the db.aCollSeq hash table. If the entry
85162 sqlite3 *db, /* Database connection */
85168 pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
85171 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
85182 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
85190 db->mallocFailed = 1;
85191 sqlite3DbFree(db, pDel);
85202 ** for the encoding 'enc' from the database 'db'.
85215 sqlite3 *db,
85222 pColl = findCollSeqEntry(db, zName, create);
85224 pColl = db->pDfltColl;
85324 ** structure is created and liked into the "db" structure if a
85338 sqlite3 *db, /* An open database */
85352 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
85356 p = functionSearch(&db->aFunc, h, zName, nName);
85378 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
85397 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
85403 sqlite3FuncDefInsert(&db->aFunc, pBest);
85414 ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
85452 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
85460 db->mallocFailed = 1;
85507 sqlite3DeleteTable(pParse->db, pItem->pTab);
85535 && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 )
85537 && (pParse->db->flags & SQLITE_WriteSchema)==0
85568 sqlite3 *db = pParse->db;
85570 pDup = sqlite3SelectDup(db, pView->pSelect, 0);
85574 pWhere = sqlite3ExprDup(db, pWhere, 0);
85575 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
85578 pFrom->a[0].zAlias = sqlite3DbStrDup(db, pView->zName);
85583 sqlite3SelectDelete(db, pDup);
85589 sqlite3SelectDelete(db, pDup);
85650 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
85652 sqlite3ExprListDelete(pParse->db, pEList);
85674 sqlite3SelectDelete(pParse->db, pSelect);
85678 sqlite3ExprDelete(pParse->db, pWhere);
85679 sqlite3ExprListDelete(pParse->db, pOrderBy);
85680 sqlite3ExprDelete(pParse->db, pLimit);
85681 sqlite3ExprDelete(pParse->db, pOffset);
85706 sqlite3 *db; /* Main database structure */
85719 db = pParse->db;
85720 if( pParse->nErr || db->mallocFailed ){
85757 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
85758 assert( iDb<db->nDb );
85759 zDb = db->aDb[iDb].zName;
85811 if( db->flags & SQLITE_CountRows ){
85850 if( db->flags & SQLITE_CountRows ){
85873 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
85910 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
85918 sqlite3SrcListDelete(db, pTabList);
85919 sqlite3ExprDelete(db, pWhere);
86112 if( pTab->pSelect || (pParse->db->flags & SQLITE_IdxRealAsInt)!=0 ){
86435 sqlite3 *db = sqlite3_context_db_handle(context);
86437 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH] );
86438 testcase( nByte==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
86439 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
86580 sqlite3 *db = sqlite3_context_db_handle(context);
86585 sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
86600 sqlite3 *db = sqlite3_context_db_handle(context);
86602 sqlite3_result_int(context, sqlite3_changes(db));
86614 sqlite3 *db = sqlite3_context_db_handle(context);
86618 sqlite3_result_int(context, sqlite3_total_changes(db));
86818 sqlite3 *db = sqlite3_context_db_handle(context);
86827 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] );
86828 testcase( nPat==db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]+1 );
86829 if( nPat > db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
87084 sqlite3 *db = sqlite3_context_db_handle(context);
87088 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH] );
87089 testcase( n==db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
87090 if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
87154 sqlite3 *db = sqlite3_context_db_handle(context);
87156 testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
87157 testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
87158 if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
87335 sqlite3 *db = sqlite3_context_db_handle(context);
87343 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){
87481 ** returns (void *)db, where db is the sqlite3* database pointer.
87524 sqlite3 *db = sqlite3_context_db_handle(context);
87527 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
87563 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
87564 int rc = sqlite3_overload_function(db, "MATCH", 2);
87567 db->mallocFailed = 1;
87574 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
87576 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
87588 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
87595 sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
87596 sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
87597 sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8,
87599 setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
87600 setLikeOptFlag(db, "like",
87611 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
87620 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
87920 ** pParse->db->mallocFailed flag is set.
87961 aiCol = (int *)sqlite3DbMallocRaw(pParse->db, nCol*sizeof(int));
88021 sqlite3DbFree(pParse->db, aiCol);
88220 sqlite3 *db = pParse->db; /* Database handle */
88249 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
88269 pRight = sqlite3Expr(db, TK_ID, zCol);
88271 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
88282 pLeft = sqlite3Expr(db, TK_REGISTER, 0);
88283 pRight = sqlite3Expr(db, TK_COLUMN, 0);
88291 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
88314 sqlite3ExprDelete(db, pWhere);
88376 sqlite3 *db = pParse->db;
88377 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) && !pTab->pSelect ){
88398 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
88442 sqlite3 *db = pParse->db; /* Database handle */
88452 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
88454 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
88455 zDb = db->aDb[iDb].zName;
88473 pTo = sqlite3FindTable(db, pFKey->zTo, zDb);
88479 if( !isIgnoreErrors || db->mallocFailed ) return;
88514 if( db->xAuth ){
88541 sqlite3DbFree(db, aiFree);
88558 if( !isIgnoreErrors || db->mallocFailed ) return;
88566 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
88587 sqlite3SrcListDelete(db, pSrc);
88589 sqlite3DbFree(db, aiCol);
88604 if( pParse->db->flags&SQLITE_ForeignKeys ){
88641 if( pParse->db->flags&SQLITE_ForeignKeys ){
88716 sqlite3 *db = pParse->db; /* Database handle */
88725 u8 enableLookaside; /* Copy of db->lookaside.bEnabled */
88767 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
88785 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
88798 pNew = sqlite3ExprDup(db, pDflt, 0);
88809 sqlite3DbFree(db, aiCol);
88820 pRaise = sqlite3Expr(db, TK_RAISE, "foreign key constraint failed");
88826 sqlite3SrcListAppend(db, 0, &tFrom, 0),
88834 enableLookaside = db->lookaside.bEnabled;
88835 db->lookaside.bEnabled = 0;
88837 pTrigger = (Trigger *)sqlite3DbMallocZero(db,
88848 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
88849 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
88850 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
88853 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
88858 db->lookaside.bEnabled = enableLookaside;
88860 sqlite3ExprDelete(db, pWhere);
88861 sqlite3ExprDelete(db, pWhen);
88862 sqlite3ExprListDelete(db, pList);
88863 sqlite3SelectDelete(db, pSelect);
88864 if( db->mallocFailed==1 ){
88865 fkTriggerDelete(db, pTrigger);
88906 if( pParse->db->flags&SQLITE_ForeignKeys ){
88924 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
88928 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
88932 if( !db || db->pnBytesFreed==0 ){
88952 fkTriggerDelete(db, pFKey->apTrigger[0]);
88953 fkTriggerDelete(db, pFKey->apTrigger[1]);
88957 sqlite3DbFree(db, pFKey);
89031 sqlite3 *db = sqlite3VdbeDb(v);
89034 db->mallocFailed = 1;
89072 sqlite3 *db = sqlite3VdbeDb(v);
89076 db->mallocFailed = 1;
89103 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
89166 pInfo = sqlite3DbMallocRaw(pParse->db, sizeof(*pInfo));
89187 sqlite3 *db = pParse->db; /* The database connection */
89188 Db *pDb; /* Database only autoinc table */
89200 pDb = &db->aDb[p->iDb];
89202 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
89244 sqlite3 *db = pParse->db;
89248 Db *pDb = &db->aDb[p->iDb];
89254 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
89404 sqlite3 *db; /* The main database structure */
89423 Db *pDb; /* The database containing table being inserted into */
89442 db = pParse->db;
89444 if( pParse->nErr || db->mallocFailed ){
89457 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
89458 assert( iDb<db->nDb );
89459 pDb = &db->aDb[iDb];
89569 if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
89711 if( db->flags & SQLITE_CountRows ){
89722 aRegIdx = sqlite3DbMallocRaw(db, sizeof(int)*(nIdx+1));
89932 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
89953 if( (db->flags & SQLITE_CountRows)!=0 ){
89998 if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
90005 sqlite3SrcListDelete(db, pTabList);
90006 sqlite3ExprListDelete(db, pList);
90007 sqlite3SelectDelete(db, pSelect);
90008 sqlite3IdListDelete(db, pColumn);
90009 sqlite3DbFree(db, aRegIdx);
90157 zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL",
90179 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){
90246 if( pParse->db->flags&SQLITE_RecTriggers ){
90335 errMsg.db = pParse->db;
90347 sqlite3DbFree(errMsg.db, zErr);
90359 if( pParse->db->flags&SQLITE_RecTriggers ){
90459 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
90701 if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
90705 if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
90716 iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
90837 sqlite3 *db, /* The database on which the SQL executes */
90850 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
90853 sqlite3_mutex_enter(db->mutex);
90854 sqlite3Error(db, SQLITE_OK, 0);
90860 rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
90881 && db->flags&SQLITE_NullCallback)) ){
90883 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
90900 db->mallocFailed = 1;
90909 sqlite3Error(db, SQLITE_ABORT, 0);
90926 sqlite3DbFree(db, azCols);
90932 sqlite3DbFree(db, azCols);
90934 rc = sqlite3ApiExit(db, rc);
90935 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){
90936 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
90939 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
90942 sqlite3Error(db, SQLITE_NOMEM, 0);
90948 assert( (rc&db->errMask)==rc );
90949 sqlite3_mutex_leave(db->mutex);
91070 int (*errcode)(sqlite3*db);
91796 ** by calling sqlite3DbFree(db, ).
91799 sqlite3 *db, /* Load the extension into this database connection */
91804 sqlite3_vfs *pVfs = db->pVfs;
91819 if( (db->flags & SQLITE_LoadExtension)==0 ){
91856 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
91865 /* Append the new shared library handle to the db->aExtension array. */
91866 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
91870 if( db->nExtension>0 ){
91871 memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
91873 sqlite3DbFree(db, db->aExtension);
91874 db->aExtension = aHandle;
91876 db->aExtension[db->nExtension++] = handle;
91880 sqlite3 *db, /* Load the extension into this database connection */
91886 sqlite3_mutex_enter(db->mutex);
91887 rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
91888 rc = sqlite3ApiExit(db, rc);
91889 sqlite3_mutex_leave(db->mutex);
91897 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3 *db){
91899 assert( sqlite3_mutex_held(db->mutex) );
91900 for(i=0; i<db->nExtension; i++){
91901 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
91903 sqlite3DbFree(db, db->aExtension);
91910 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
91911 sqlite3_mutex_enter(db->mutex);
91913 db->flags |= SQLITE_LoadExtension;
91915 db->flags &= ~SQLITE_LoadExtension;
91917 sqlite3_mutex_leave(db->mutex);
92028 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
92054 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
92055 sqlite3Error(db, rc,
92152 ** Interpret the given string as a temp db location. Return 1 for file
92175 sqlite3 *db = pParse->db;
92176 if( db->aDb[1].pBt!=0 ){
92177 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
92182 sqlite3BtreeClose(db->aDb[1].pBt);
92183 db->aDb[1].pBt = 0;
92184 sqlite3ResetInternalSchema(db, -1);
92198 sqlite3 *db = pParse->db;
92199 if( db->temp_store==ts ) return SQLITE_OK;
92203 db->temp_store = (u8)ts;
92214 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
92227 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
92233 int mask; /* Mask for the db->flags value */
92272 sqlite3 *db = pParse->db;
92278 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
92281 if( db->autoCommit==0 ){
92288 db->flags |= mask;
92290 db->flags &= ~mask;
92380 sqlite3 *db = pParse->db; /* The database connection */
92381 Db *pDb; /* The specific database being pragmaed */
92382 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(db); /* Prepared statement */
92389 ** index of the database this pragma is being applied to in db.aDb[]. */
92392 pDb = &db->aDb[iDb];
92401 zLeft = sqlite3NameFromToken(db, pId);
92404 zRight = sqlite3MPrintf(db, "-%T", pValue);
92406 zRight = sqlite3NameFromToken(db, pValue);
92423 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
92487 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
92514 db->nextPagesize = sqlite3Atoi(zRight);
92515 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
92516 db->mallocFailed = 1;
92538 for(ii=0; ii<db->nDb; ii++){
92539 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
92594 eMode = db->dfltLockMode;
92600 ** set on all attached databases, as well as the main db file.
92607 assert(pDb==&db->aDb[0]);
92608 for(ii=2; ii<db->nDb; ii++){
92609 pPager = sqlite3BtreePager(db->aDb[ii].pBt);
92612 db->dfltLockMode = (u8)eMode;
92669 for(ii=db->nDb-1; ii>=0; ii--){
92670 if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
92722 db->nextAutovac = (u8)eAuto;
92727 ** as an auto-vacuum capable db.
92796 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
92819 returnSingleInt(pParse, "temp_store", db->temp_store);
92848 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
92855 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
92856 || (SQLITE_TEMP_STORE==2 && db->temp_store==1)
92934 if( !db->autoCommit ){
92967 pTab = sqlite3FindTable(db, zRight, zDb);
93006 pIdx = sqlite3FindIndex(db, zRight, zDb);
93030 pTab = sqlite3FindTable(db, zRight, zDb);
93061 for(i=0; i<db->nDb; i++){
93062 if( db->aDb[i].pBt==0 ) continue;
93063 assert( db->aDb[i].zName!=0 );
93065 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
93067 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
93079 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
93093 pTab = sqlite3FindTable(db, zRight, zDb);
93151 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
93199 for(i=0; i<db->nDb; i++){
93216 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
93217 pTbls = &db->aDb[i].pSchema->tblHash;
93239 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
93370 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
93379 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
93380 DbHasProperty(db, 0, DB_Empty)
93384 ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
93526 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
93529 db->xWalCallback==sqlite3WalDefaultHook ?
93530 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
93541 sqlite3_db_release_memory(db);
93557 for(i=0; i<db->nDb; i++){
93562 if( db->aDb[i].zName==0 ) continue;
93563 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
93564 pBt = db->aDb[i].pBt;
93567 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
93580 sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
93583 sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
93595 sqlite3_key(db, zKey, i/2);
93597 sqlite3_rekey(db, zKey, i/2);
93624 if( db->autoCommit ){
93626 (db->flags&SQLITE_FullFSync)!=0,
93627 (db->flags&SQLITE_CkptFullFSync)!=0);
93631 sqlite3DbFree(db, zLeft);
93632 sqlite3DbFree(db, zRight);
93664 sqlite3 *db = pData->db;
93665 if( !db->mallocFailed && (db->flags & SQLITE_RecoveryMode)==0 ){
93667 sqlite3SetString(pData->pzErrMsg, db,
93670 *pData->pzErrMsg = sqlite3MAppendf(db, *pData->pzErrMsg,
93674 pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT;
93691 sqlite3 *db = pData->db;
93696 assert( sqlite3_mutex_held(db->mutex) );
93697 DbClearProperty(db, iDb, DB_Empty);
93698 if( db->mallocFailed ){
93703 assert( iDb>=0 && iDb<db->nDb );
93709 ** But because db->init.busy is set to 1, no VDBE code is generated
93717 assert( db->init.busy );
93718 db->init.iDb = iDb;
93719 db->init.newTnum = sqlite3Atoi(argv[1]);
93720 db->init.orphanTrigger = 0;
93721 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
93722 rc = db->errCode;
93724 db->init.iDb = 0;
93726 if( db->init.orphanTrigger ){
93731 db->mallocFailed = 1;
93733 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
93748 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
93771 static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
93776 Db *pDb;
93810 assert( iDb>=0 && iDb<db->nDb );
93811 assert( db->aDb[iDb].pSchema );
93812 assert( sqlite3_mutex_held(db->mutex) );
93813 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
93831 initData.db = db;
93840 pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
93847 pDb = &db->aDb[iDb];
93850 DbSetProperty(db, 1, DB_SchemaLoaded);
93862 sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
93875 ** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
93892 ** For an attached db, it is an error if the encoding is not the same
93898 /* If opening the main database, set ENC(db). */
93901 ENC(db) = encoding;
93902 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
93904 /* If opening an attached database, the encoding much match ENC(db) */
93905 if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
93906 sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
93913 DbSetProperty(db, iDb, DB_Empty);
93915 pDb->pSchema->enc = ENC(db);
93939 sqlite3SetString(pzErrMsg, db, "unsupported file format");
93950 db->flags &= ~SQLITE_LegacyFileFmt;
93955 assert( db->init.busy );
93958 zSql = sqlite3MPrintf(db,
93960 db->aDb[iDb].zName, zMasterName);
93964 xAuth = db->xAuth;
93965 db->xAuth = 0;
93967 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
93969 db->xAuth = xAuth;
93973 sqlite3DbFree(db, zSql);
93976 sqlite3AnalysisLoad(db, iDb);
93980 if( db->mallocFailed ){
93982 sqlite3ResetInternalSchema(db, -1);
93984 if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
93993 DbSetProperty(db, iDb, DB_SchemaLoaded);
94009 db->mallocFailed = 1;
94021 ** bit is set in the flags field of the Db structure. If the database
94024 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
94026 int commit_internal = !(db->flags&SQLITE_InternChanges);
94028 assert( sqlite3_mutex_held(db->mutex) );
94030 db->init.busy = 1;
94031 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
94032 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
94033 rc = sqlite3InitOne(db, i, pzErrMsg);
94035 sqlite3ResetInternalSchema(db, i);
94044 if( rc==SQLITE_OK && ALWAYS(db->nDb>1)
94045 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
94046 rc = sqlite3InitOne(db, 1, pzErrMsg);
94048 sqlite3ResetInternalSchema(db, 1);
94053 db->init.busy = 0;
94055 sqlite3CommitInternalChanges(db);
94067 sqlite3 *db = pParse->db;
94068 assert( sqlite3_mutex_held(db->mutex) );
94069 if( !db->init.busy ){
94070 rc = sqlite3Init(db, &pParse->zErrMsg);
94086 sqlite3 *db = pParse->db;
94092 assert( sqlite3_mutex_held(db->mutex) );
94093 for(iDb=0; iDb<db->nDb; iDb++){
94095 Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
94104 db->mallocFailed = 1;
94114 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
94115 if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
94116 sqlite3ResetInternalSchema(db, iDb);
94129 ** which database file in db->aDb[] the schema refers to.
94134 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *pSchema){
94143 ** -1000000 as the incorrect index into db->aDb[] is much
94147 assert( sqlite3_mutex_held(db->mutex) );
94149 for(i=0; ALWAYS(i<db->nDb); i++){
94150 if( db->aDb[i].pSchema==pSchema ){
94154 assert( i>=0 && i<db->nDb );
94163 sqlite3 *db, /* Database handle. */
94177 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
94184 assert( !db->mallocFailed );
94185 assert( sqlite3_mutex_held(db->mutex) );
94210 for(i=0; i<db->nDb; i++) {
94211 Btree *pBt = db->aDb[i].pBt;
94216 const char *zDb = db->aDb[i].zName;
94217 sqlite3Error(db, rc, "database schema is locked: %s", zDb);
94218 testcase( db->flags & SQLITE_ReadUncommitted );
94224 sqlite3VtabUnlockList(db);
94226 pParse->db = db;
94230 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
94234 sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
94235 rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
94238 zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
94241 sqlite3DbFree(db, zSqlCopy);
94251 if( db->mallocFailed ){
94258 if( db->mallocFailed ){
94289 assert( db->init.busy==0 || saveSqlFlag==0 );
94290 if( db->init.busy==0 ){
94294 if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
94302 sqlite3Error(db, rc, "%s", zErrMsg);
94303 sqlite3DbFree(db, zErrMsg);
94305 sqlite3Error(db, rc, 0);
94312 sqlite3DbFree(db, pT);
94317 sqlite3StackFree(db, pParse);
94318 rc = sqlite3ApiExit(db, rc);
94319 assert( (rc&db->errMask)==rc );
94323 sqlite3 *db, /* Database handle. */
94334 if( !sqlite3SafetyCheckOk(db) ){
94337 sqlite3_mutex_enter(db->mutex);
94338 sqlite3BtreeEnterAll(db);
94339 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
94342 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
94344 sqlite3BtreeLeaveAll(db);
94345 sqlite3_mutex_leave(db->mutex);
94361 sqlite3 *db;
94366 db = sqlite3VdbeDb(p);
94367 assert( sqlite3_mutex_held(db->mutex) );
94368 rc = sqlite3LockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
94371 db->mallocFailed = 1;
94395 sqlite3 *db, /* Database handle. */
94402 rc = sqlite3LockAndPrepare(db,zSql,nBytes,0,0,ppStmt,pzTail);
94407 sqlite3 *db, /* Database handle. */
94414 rc = sqlite3LockAndPrepare(db,zSql,nBytes,1,0,ppStmt,pzTail);
94425 sqlite3 *db, /* Database handle. */
94442 if( !sqlite3SafetyCheckOk(db) ){
94445 sqlite3_mutex_enter(db->mutex);
94446 zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
94448 rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
94460 sqlite3DbFree(db, zSql8);
94461 rc = sqlite3ApiExit(db, rc);
94462 sqlite3_mutex_leave(db->mutex);
94475 sqlite3 *db, /* Database handle. */
94482 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
94487 sqlite3 *db, /* Database handle. */
94494 rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
94523 static void clearSelect(sqlite3 *db, Select *p){
94524 sqlite3ExprListDelete(db, p->pEList);
94525 sqlite3SrcListDelete(db, p->pSrc);
94526 sqlite3ExprDelete(db, p->pWhere);
94527 sqlite3ExprListDelete(db, p->pGroupBy);
94528 sqlite3ExprDelete(db, p->pHaving);
94529 sqlite3ExprListDelete(db, p->pOrderBy);
94530 sqlite3SelectDelete(db, p->pPrior);
94531 sqlite3ExprDelete(db, p->pLimit);
94532 sqlite3ExprDelete(db, p->pOffset);
94565 sqlite3 *db = pParse->db;
94566 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
94567 assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
94569 assert( db->mallocFailed );
94574 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0));
94577 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
94591 if( db->mallocFailed ) {
94592 clearSelect(db, pNew);
94593 if( pNew!=&standin ) sqlite3DbFree(db, pNew);
94605 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
94607 clearSelect(db, p);
94608 sqlite3DbFree(db, p);
94752 sqlite3 *db = pParse->db;
94762 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
94763 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
94772 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
94878 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
95260 sqlite3 *db = pParse->db;
95267 pInfo = sqlite3DbMallocZero(db, sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
95271 pInfo->enc = ENC(db);
95272 pInfo->db = db;
95277 pColl = db->pDfltColl;
95316 char *zMsg = sqlite3MPrintf(pParse->db, "USE TEMP B-TREE FOR %s", zUsage);
95362 pParse->db, "COMPOUND SUBQUERIES %d AND %d %s(%s)", iSub1, iSub2,
95593 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
95594 zOriginDb = pNC->pParse->db->aDb[iDb].zName;
95678 sqlite3 *db = pParse->db;
95688 if( pParse->colNamesSet || NEVER(v==0) || db->mallocFailed ) return;
95690 fullNames = (db->flags & SQLITE_FullColNames)!=0;
95691 shortNames = (db->flags & SQLITE_ShortColNames)!=0;
95718 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
95721 zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
95728 sqlite3DbStrDup(db, pEList->a[i].zSpan), SQLITE_DYNAMIC);
95753 sqlite3 *db = pParse->db; /* Database connection */
95763 aCol = *paCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
95773 zName = sqlite3DbStrDup(db, zName);
95786 zName = sqlite3MPrintf(db, "%s",
95790 zName = sqlite3MPrintf(db, "%s", pColExpr->u.zToken);
95793 zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
95796 if( db->mallocFailed ){
95797 sqlite3DbFree(db, zName);
95809 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
95810 sqlite3DbFree(db, zName);
95818 if( db->mallocFailed ){
95820 sqlite3DbFree(db, aCol[j].zName);
95822 sqlite3DbFree(db, aCol);
95847 sqlite3 *db = pParse->db;
95857 assert( nCol==pSelect->pEList->nExpr || db->mallocFailed );
95858 if( db->mallocFailed ) return;
95864 pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0));
95869 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
95880 sqlite3 *db = pParse->db;
95883 savedFlags = db->flags;
95884 db->flags &= ~SQLITE_FullColNames;
95885 db->flags |= SQLITE_ShortColNames;
95889 db->flags = savedFlags;
95890 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
95896 assert( db->lookaside.bEnabled==0 );
95903 if( db->mallocFailed ){
95904 sqlite3DeleteTable(db, pTab);
95917 v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
96071 sqlite3 *db; /* Database connection */
96081 db = pParse->db;
96235 sqlite3ExprListDelete(db, p->pOrderBy);
96240 sqlite3ExprDelete(db, p->pLimit);
96320 sqlite3ExprDelete(db, p->pLimit);
96372 pKeyInfo = sqlite3DbMallocZero(db,
96379 pKeyInfo->enc = ENC(db);
96385 *apColl = db->pDfltColl;
96403 sqlite3DbFree(db, pKeyInfo);
96409 sqlite3SelectDelete(db, pDelete);
96464 if( pParse->db->mallocFailed ) return 0;
96693 sqlite3 *db; /* Database connection */
96704 db = pParse->db;
96725 for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
96732 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
96749 aPermute = sqlite3DbMallocRaw(db, sizeof(int)*nOrderBy);
96757 sqlite3DbMallocRaw(db, sizeof(*pKeyMerge)+nOrderBy*(sizeof(CollSeq*)+1));
96761 pKeyMerge->enc = ENC(db);
96783 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
96793 assert( nOrderBy>=nExpr || db->mallocFailed );
96796 pKeyDup = sqlite3DbMallocZero(db,
96801 pKeyDup->enc = ENC(db);
96828 sqlite3ExprDelete(db, p->pLimit);
96830 sqlite3ExprDelete(db, p->pOffset);
96996 sqlite3SelectDelete(db, p->pPrior);
97026 sqlite3 *db, /* Report malloc errors to this connection */
97039 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
97043 sqlite3ExprDelete(db, pExpr);
97047 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
97048 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
97050 substSelect(db, pExpr->x.pSelect, iTable, pEList);
97052 substExprList(db, pExpr->x.pList, iTable, pEList);
97058 sqlite3 *db, /* Report malloc errors here */
97066 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
97070 sqlite3 *db, /* Report malloc errors here */
97079 substExprList(db, p->pEList, iTable, pEList);
97080 substExprList(db, p->pGroupBy, iTable, pEList);
97081 substExprList(db, p->pOrderBy, iTable, pEList);
97082 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
97083 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
97084 substSelect(db, p->pPrior, iTable, pEList);
97089 substSelect(db, pItem->pSelect, iTable, pEList);
97229 sqlite3 *db = pParse->db;
97235 if( db->flags & SQLITE_QueryFlattener ) return 0;
97392 pNew = sqlite3SelectDup(db, p, 0);
97405 if( db->mallocFailed ) return 1;
97416 sqlite3DbFree(db, pSubitem->zDatabase);
97417 sqlite3DbFree(db, pSubitem->zName);
97418 sqlite3DbFree(db, pSubitem->zAlias);
97468 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
97470 assert( db->mallocFailed );
97491 pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
97492 if( db->mallocFailed ){
97501 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
97524 pList->a[i].zName = sqlite3DbStrDup(db, zSpan);
97528 substExprList(db, pParent->pEList, iParent, pSub->pEList);
97530 substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
97531 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
97538 substExprList(db, pParent->pOrderBy, iParent, pSub->pEList);
97541 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
97549 pParent->pHaving = substExpr(db, pParent->pHaving, iParent, pSub->pEList);
97550 pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
97551 sqlite3ExprDup(db, pSub->pHaving, 0));
97553 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
97555 pParent->pWhere = substExpr(db, pParent->pWhere, iParent, pSub->pEList);
97556 pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
97579 sqlite3SelectDelete(db, pSub1);
97706 sqlite3 *db = pParse->db;
97708 if( db->mallocFailed ){
97742 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
97745 pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
97764 pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
97778 if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
97807 int flags = pParse->db->flags;
97843 if( db->mallocFailed ) break;
97878 pRight = sqlite3Expr(db, TK_ID, zName);
97883 pLeft = sqlite3Expr(db, TK_ID, zTabName);
97886 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
97896 sqlite3DbFree(db, zToFree);
97908 sqlite3ExprListDelete(db, pEList);
97912 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
97944 ** and/or pParse->db->mallocFailed.
98031 sqlite3 *db;
98033 db = pParse->db;
98036 if( pParse->nErr || db->mallocFailed ) return;
98038 if( pParse->nErr || db->mallocFailed ) return;
98135 pColl = pParse->db->pDfltColl;
98186 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s %s%s(~%d rows)",
98277 sqlite3 *db; /* The database connection */
98284 db = pParse->db;
98285 if( p==0 || db->mallocFailed || pParse->nErr ){
98296 sqlite3ExprListDelete(db, p->pOrderBy);
98304 if( pParse->nErr || db->mallocFailed ){
98386 if( /*pParse->nErr ||*/ db->mallocFailed ){
98415 mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
98435 && (db->flags & SQLITE_GroupByOrder)==0 ){
98458 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
98636 if( db->mallocFailed ) goto select_end;
98870 const int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
98943 pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->x.pList,0);
98945 if( pMinMax && !db->mallocFailed ){
98958 sqlite3ExprListDelete(db, pDel);
98975 sqlite3ExprListDelete(db, pDel);
99014 sqlite3DbFree(db, sAggInfo.aCol);
99015 sqlite3DbFree(db, sAggInfo.aFunc);
99234 sqlite3 *db, /* The database on which the SQL executes */
99256 db->errCode = SQLITE_NOMEM;
99260 rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
99272 db->errCode = res.rc; /* Assume 32-bit assignment is atomic */
99285 db->errCode = SQLITE_NOMEM;
99333 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3 *db, TriggerStep *pTriggerStep){
99338 sqlite3ExprDelete(db, pTmp->pWhere);
99339 sqlite3ExprListDelete(db, pTmp->pExprList);
99340 sqlite3SelectDelete(db, pTmp->pSelect);
99341 sqlite3IdListDelete(db, pTmp->pIdList);
99343 sqlite3DbFree(db, pTmp);
99362 Schema * const pTmpSchema = pParse->db->aDb[1].pSchema;
99371 assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) );
99409 sqlite3 *db = pParse->db; /* The database connection */
99411 Token *pName; /* The unqualified db name */
99412 DbFixer sFix; /* State vector for the DB fixer */
99428 /* Figure out the db that the the trigger will be created in */
99434 if( !pTableName || db->mallocFailed ){
99446 if( db->init.busy && iDb!=1 ){
99447 sqlite3DbFree(db, pTableName->a[0].zDatabase);
99457 if( db->init.busy==0 && pName2->n==0 && pTab
99458 && pTab->pSchema==db->aDb[1].pSchema ){
99463 if( db->mallocFailed ) goto trigger_cleanup;
99472 if( db->init.iDb==1 ){
99481 db->init.orphanTrigger = 1;
99492 zName = sqlite3NameFromToken(db, pName);
99496 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99497 if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
99502 assert( !db->init.busy );
99528 iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
99533 const char *zDb = db->aDb[iTabDb].zName;
99534 const char *zDbTrig = isTemp ? db->aDb[1].zName : zDb;
99555 pTrigger = (Trigger*)sqlite3DbMallocZero(db, sizeof(Trigger));
99559 pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName);
99560 pTrigger->pSchema = db->aDb[iDb].pSchema;
99564 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
99565 pTrigger->pColumns = sqlite3IdListDup(db, pColumns);
99570 sqlite3DbFree(db, zName);
99571 sqlite3SrcListDelete(db, pTableName);
99572 sqlite3IdListDelete(db, pColumns);
99573 sqlite3ExprDelete(db, pWhen);
99575 sqlite3DeleteTrigger(db, pTrigger);
99592 sqlite3 *db = pParse->db; /* The database */
99600 iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);
99616 if( !db->init.busy ){
99624 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
99627 db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
99629 sqlite3DbFree(db, z);
99632 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
99635 if( db->init.busy ){
99637 Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
99638 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99641 db->mallocFailed = 1;
99653 sqlite3DeleteTrigger(db, pTrig);
99655 sqlite3DeleteTriggerStep(db, pStepList);
99665 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3 *db, Select *pSelect){
99666 TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
99668 sqlite3SelectDelete(db, pSelect);
99681 ** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
99684 sqlite3 *db, /* Database connection */
99690 pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n);
99709 sqlite3 *db, /* The database connection */
99719 assert(pEList != 0 || pSelect != 0 || db->mallocFailed);
99721 pTriggerStep = triggerStepAllocate(db, TK_INSERT, pTableName);
99723 pTriggerStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
99725 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
99728 sqlite3IdListDelete(db, pColumn);
99730 sqlite3ExprListDelete(db, pEList);
99731 sqlite3SelectDelete(db, pSelect);
99742 sqlite3 *db, /* The database connection */
99750 pTriggerStep = triggerStepAllocate(db, TK_UPDATE, pTableName);
99752 pTriggerStep->pExprList = sqlite3ExprListDup(db, pEList, EXPRDUP_REDUCE);
99753 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99756 sqlite3ExprListDelete(db, pEList);
99757 sqlite3ExprDelete(db, pWhere);
99767 sqlite3 *db, /* Database connection */
99773 pTriggerStep = triggerStepAllocate(db, TK_DELETE, pTableName);
99775 pTriggerStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
99778 sqlite3ExprDelete(db, pWhere);
99785 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3 *db, Trigger *pTrigger){
99787 sqlite3DeleteTriggerStep(db, pTrigger->step_list);
99788 sqlite3DbFree(db, pTrigger->zName);
99789 sqlite3DbFree(db, pTrigger->table);
99790 sqlite3ExprDelete(db, pTrigger->pWhen);
99791 sqlite3IdListDelete(db, pTrigger->pColumns);
99792 sqlite3DbFree(db, pTrigger);
99809 sqlite3 *db = pParse->db;
99811 if( db->mallocFailed ) goto drop_trigger_cleanup;
99820 assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
99821 for(i=OMIT_TEMPDB; i<db->nDb; i++){
99823 if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
99824 assert( sqlite3SchemaMutexHeld(db, j, 0) );
99825 pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
99840 sqlite3SrcListDelete(db, pName);
99859 sqlite3 *db = pParse->db;
99862 iDb = sqlite3SchemaToIndex(pParse->db, pTrigger->pSchema);
99863 assert( iDb>=0 && iDb<db->nDb );
99870 const char *zDb = db->aDb[iDb].zName;
99914 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
99918 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
99919 pHash = &(db->aDb[iDb].pSchema->trigHash);
99928 sqlite3DeleteTrigger(db, pTrigger);
99929 db->flags |= SQLITE_InternChanges;
99968 if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
100000 pSrc = sqlite3SrcListAppend(pParse->db, 0, &pStep->target, 0);
100004 iDb = sqlite3SchemaToIndex(pParse->db, pStep->pTrig->pSchema);
100006 sqlite3 *db = pParse->db;
100007 assert( iDb<pParse->db->nDb );
100008 pSrc->a[pSrc->nSrc-1].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
100025 sqlite3 *db = pParse->db;
100050 sqlite3ExprListDup(db, pStep->pExprList, 0),
100051 sqlite3ExprDup(db, pStep->pWhere, 0),
100059 sqlite3ExprListDup(db, pStep->pExprList, 0),
100060 sqlite3SelectDup(db, pStep->pSelect, 0),
100061 sqlite3IdListDup(db, pStep->pIdList),
100069 sqlite3ExprDup(db, pStep->pWhere, 0)
100075 Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
100078 sqlite3SelectDelete(db, pSelect);
100120 sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
100135 sqlite3 *db = pParse->db; /* Database handle */
100150 pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg));
100154 pPrg->pProgram = pProgram = sqlite3DbMallocZero(db, sizeof(SubProgram));
100164 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
100168 pSubParse->db = db;
100187 sqlite3MPrintf(db, "-- TRIGGER %s", pTrigger->zName), P4_DYNAMIC
100195 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
100197 && db->mallocFailed==0
100202 sqlite3ExprDelete(db, pWhen);
100216 if( db->mallocFailed==0 ){
100230 sqlite3StackFree(db, pSubParse);
100286 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
100291 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
100372 || p->pSchema==pParse->db->aDb[1].pSchema );
100544 sqlite3 *db; /* The database structure */
100574 db = pParse->db;
100575 if( pParse->nErr || db->mallocFailed ){
100584 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
100609 aXRef = sqlite3DbMallocRaw(db, sizeof(int) * pTab->nCol );
100663 pTab->aCol[j].zName, db->aDb[iDb].zName);
100682 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
100774 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
100959 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab){
100994 if( (db->flags&SQLITE_CountRows) && !pParse->pTriggerTab && !pParse->nested ){
101002 sqlite3DbFree(db, aRegIdx);
101003 sqlite3DbFree(db, aXRef);
101004 sqlite3SrcListDelete(db, pTabList);
101005 sqlite3ExprListDelete(db, pChanges);
101006 sqlite3ExprDelete(db, pWhere);
101057 sqlite3 *db = pParse->db; /* Database connection */
101058 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
101064 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));
101067 sqlite3ExprDup(db, pRowid, 0));
101072 pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);
101074 pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
101111 sqlite3SelectDelete(db, pSelect);
101139 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
101143 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
101149 ** Execute zSql on database db. Return an error code.
101151 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
101157 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
101158 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
101159 return sqlite3_errcode(db);
101162 assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
101163 return vacuumFinalize(db, pStmt, pzErrMsg);
101167 ** Execute zSql on database db. The statement returns exactly
101170 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
101174 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
101178 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
101180 vacuumFinalize(db, pStmt, pzErrMsg);
101185 return vacuumFinalize(db, pStmt, pzErrMsg);
101209 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
101214 int saved_flags; /* Saved value of the db->flags */
101215 int saved_nChange; /* Saved value of db->nChange */
101216 int saved_nTotalChange; /* Saved value of db->nTotalChange */
101217 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */
101218 Db *pDb = 0; /* Database to detach at end of vacuum */
101223 if( !db->autoCommit ){
101224 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
101227 if( db->activeVdbeCnt>1 ){
101228 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
101235 saved_flags = db->flags;
101236 saved_nChange = db->nChange;
101237 saved_nTotalChange = db->nTotalChange;
101238 saved_xTrace = db->xTrace;
101239 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin;
101240 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder);
101241 db->xTrace = 0;
101243 pMain = db->aDb[0].pBt;
101260 nDb = db->nDb;
101261 if( sqlite3TempInMemory(db) ){
101266 rc = execSql(db, pzErrMsg, zSql);
101267 if( db->nDb>nDb ){
101268 pDb = &db->aDb[db->nDb-1];
101272 pTemp = db->aDb[db->nDb-1].pBt;
101284 if( db->nextPagesize ){
101288 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
101289 if( nKey ) db->nextPagesize = 0;
101293 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF");
101300 rc = execSql(db, pzErrMsg, "BEGIN;");
101308 db->nextPagesize = 0;
101312 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
101313 || NEVER(db->mallocFailed)
101320 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
101327 rc = execExecSql(db, pzErrMsg,
101333 rc = execExecSql(db, pzErrMsg,
101337 rc = execExecSql(db, pzErrMsg,
101346 rc = execExecSql(db, pzErrMsg,
101357 rc = execExecSql(db, pzErrMsg,
101362 rc = execExecSql(db, pzErrMsg,
101375 rc = execSql(db, pzErrMsg,
101432 /* Restore the original value of db->flags */
101433 db->flags = saved_flags;
101434 db->nChange = saved_nChange;
101435 db->nTotalChange = saved_nTotalChange;
101436 db->xTrace = saved_xTrace;
101446 db->autoCommit = 1;
101454 /* This both clears the schemas and reduces the size of the db->aDb[]
101456 sqlite3ResetInternalSchema(db, -1);
101498 sqlite3 *db, /* Database in which module is registered */
101507 sqlite3_mutex_enter(db->mutex);
101509 pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
101518 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
101520 sqlite3ResetInternalSchema(db, -1);
101523 sqlite3DbFree(db, pDel);
101525 db->mallocFailed = 1;
101530 rc = sqlite3ApiExit(db, SQLITE_OK);
101531 sqlite3_mutex_leave(db->mutex);
101540 sqlite3 *db, /* Database in which module is registered */
101545 return createModule(db, zName, pModule, pAux, 0);
101552 sqlite3 *db, /* Database in which module is registered */
101558 return createModule(db, zName, pModule, pAux, xDestroy);
101576 ** Return a pointer to the VTable object used by connection db to access
101579 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
101582 for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
101591 sqlite3 *db = pVTab->db;
101593 assert( db );
101595 assert( sqlite3SafetyCheckOk(db) );
101603 sqlite3DbFree(db, pVTab);
101611 ** Except, if argument db is not NULL, then the entry associated with
101612 ** connection db is left in the p->pVTable list.
101614 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
101625 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
101628 sqlite3 *db2 = pVTable->db;
101631 if( db2==db ){
101642 assert( !db || pRet );
101651 ** shared b-tree databases opened using connection db are held by the
101667 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3 *db){
101668 VTable *p = db->pDisconnect;
101669 db->pDisconnect = 0;
101671 assert( sqlite3BtreeHoldsAllMutexes(db) );
101672 assert( sqlite3_mutex_held(db->mutex) );
101675 sqlite3ExpirePreparedStatements(db);
101693 ** connection db is decremented immediately (which may lead to the
101698 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
101699 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
101703 sqlite3DbFree(db, p->azModuleArg[i]);
101705 sqlite3DbFree(db, p->azModuleArg);
101715 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
101719 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
101723 sqlite3DbFree(db, pTable->azModuleArg[j]);
101725 sqlite3DbFree(db, zArg);
101726 sqlite3DbFree(db, pTable->azModuleArg);
101749 sqlite3 *db; /* Database connection */
101756 db = pParse->db;
101757 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
101762 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
101763 addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName));
101764 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
101775 pTable->azModuleArg[0], pParse->db->aDb[iDb].zName);
101789 sqlite3 *db = pParse->db;
101790 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
101800 sqlite3 *db = pParse->db; /* The database connection */
101813 if( !db->init.busy ){
101823 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
101833 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
101838 db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
101844 sqlite3DbFree(db, zStmt);
101849 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
101865 assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
101868 db->mallocFailed = 1;
101907 sqlite3 *db,
101919 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
101925 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
101927 sqlite3DbFree(db, zModuleName);
101930 pVTable->db = db;
101934 assert( &db->pVtabCtx );
101938 db->pVtabCtx = &sCtx;
101939 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
101940 db->pVtabCtx = 0;
101941 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
101945 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
101947 *pzErr = sqlite3MPrintf(db, "%s", zErr);
101950 sqlite3DbFree(db, pVTable);
101958 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
102003 sqlite3DbFree(db, zModuleName);
102015 sqlite3 *db = pParse->db;
102021 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
102027 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
102035 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
102039 sqlite3DbFree(db, zErr);
102045 ** Grow the db->aVTrans[] array so that there is room for at least one
102048 static int growVTrans(sqlite3 *db){
102052 if( (db->nVTrans%ARRAY_INCR)==0 ){
102054 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
102055 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
102059 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
102060 db->aVTrans = aVTrans;
102070 static void addToVTrans(sqlite3 *db, VTable *pVTab){
102072 db->aVTrans[db->nVTrans++] = pVTab;
102082 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
102084 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
102090 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
102095 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
102102 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
102105 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
102110 if( rc==SQLITE_OK && ALWAYS(sqlite3GetVTable(db, pTab)) ){
102111 rc = growVTrans(db);
102113 addToVTrans(db, sqlite3GetVTable(db, pTab));
102125 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
102132 sqlite3_mutex_enter(db->mutex);
102133 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
102134 sqlite3Error(db, SQLITE_MISUSE, 0);
102135 sqlite3_mutex_leave(db->mutex);
102140 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
102145 pParse->db = db;
102150 && !db->mallocFailed
102160 db->pVtabCtx->pTab = 0;
102162 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
102163 sqlite3DbFree(db, zErr);
102171 sqlite3DeleteTable(db, pParse->pNewTable);
102172 sqlite3StackFree(db, pParse);
102176 rc = sqlite3ApiExit(db, rc);
102177 sqlite3_mutex_leave(db->mutex);
102188 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
102192 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
102194 VTable *p = vtabDisconnectAll(db, pTab);
102219 static void callFinaliser(sqlite3 *db, int offset){
102221 if( db->aVTrans ){
102222 for(i=0; i<db->nVTrans; i++){
102223 VTable *pVTab = db->aVTrans[i];
102233 sqlite3DbFree(db, db->aVTrans);
102234 db->nVTrans = 0;
102235 db->aVTrans = 0;
102247 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
102250 VTable **aVTrans = db->aVTrans;
102252 db->aVTrans = 0;
102253 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
102258 sqlite3DbFree(db, *pzErrmsg);
102259 *pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
102263 db->aVTrans = aVTrans;
102271 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db){
102272 callFinaliser(db, offsetof(sqlite3_module,xRollback));
102280 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db){
102281 callFinaliser(db, offsetof(sqlite3_module,xCommit));
102293 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *db, VTable *pVTab){
102297 /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
102302 if( sqlite3VtabInSync(db) ){
102314 for(i=0; i<db->nVTrans; i++){
102315 if( db->aVTrans[i]==pVTab ){
102322 rc = growVTrans(db);
102326 addToVTrans(db, pVTab);
102348 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
102353 if( db->aVTrans ){
102355 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
102356 VTable *pVTab = db->aVTrans[i];
102395 sqlite3 *db, /* Database connection for reporting malloc problems */
102417 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
102426 zLowerName = sqlite3DbStrDup(db, pDef->zName);
102432 sqlite3DbFree(db, zLowerName);
102440 pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
102475 pToplevel->db->mallocFailed = 1;
102486 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
102492 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
102493 return (int)aMap[db->vtabOnConflict-1];
102501 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
102505 sqlite3_mutex_enter(db->mutex);
102510 VtabCtx *p = db->pVtabCtx;
102525 if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0);
102526 sqlite3_mutex_leave(db->mutex);
102646 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
102825 static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
102827 sqlite3DbFree(db, p);
102833 static void whereAndInfoDelete(sqlite3 *db, WhereAndInfo *p){
102835 sqlite3DbFree(db, p);
102845 sqlite3 *db = pWC->pParse->db;
102848 sqlite3ExprDelete(db, a->pExpr);
102851 whereOrInfoDelete(db, a->u.pOrInfo);
102853 whereAndInfoDelete(db, a->u.pAndInfo);
102857 sqlite3DbFree(db, pWC->a);
102867 ** the db->mallocFailed flag so that higher-level functions can detect it.
102886 sqlite3 *db = pWC->pParse->db;
102887 pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 );
102890 sqlite3ExprDelete(db, p);
102897 sqlite3DbFree(db, pOld);
102899 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
103209 sqlite3 *db = pParse->db; /* Database connection */
103213 if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, wc) ){
103253 pPrefix = sqlite3Expr(db, TK_STRING, z);
103405 sqlite3 *db = pParse->db; /* Database connection */
103423 pTerm->u.pOrInfo = pOrInfo = sqlite3DbMallocZero(db, sizeof(*pOrInfo));
103430 if( db->mallocFailed ) return;
103444 pAndInfo = sqlite3DbMallocRaw(db, sizeof(*pAndInfo));
103458 testcase( db->mallocFailed );
103459 if( !db->mallocFailed ){
103606 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
103611 pDup = sqlite3ExprDup(db, pLeft, 0);
103625 sqlite3ExprListDelete(db, pList);
103668 sqlite3 *db = pParse->db; /* Database connection */
103670 if( db->mallocFailed ){
103714 pDup = sqlite3ExprDup(db, pExpr, 0);
103715 if( db->mallocFailed ){
103716 sqlite3ExprDelete(db, pDup);
103767 sqlite3ExprDup(db, pExpr->pLeft, 0),
103768 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
103813 pStr2 = sqlite3ExprDup(db, pStr1, 0);
103814 if( !db->mallocFailed ){
103832 pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0);
103834 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
103840 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl),
103874 0, sqlite3ExprDup(db, pRight, 0), 0);
103912 sqlite3ExprDup(db, pLeft, 0),
104147 sqlite3 *db = pParse->db;
104185 pColl = db->pDfltColl;
104474 if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
104604 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
104724 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
104794 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
104805 pParse->db->mallocFailed = 1;
104891 assert( sqlite3GetVTable(pParse->db, pTab) );
105057 sqlite3 *db = pParse->db;
105062 pColl = db->pDfltColl;
105065 pColl = sqlite3GetCollSeq(db, SQLITE_UTF8, 0, *pIdx->azColl);
105088 db, pColl->enc, aSample[i].u.z, aSample[i].nByte, &nSample
105091 assert( db->mallocFailed );
105095 sqlite3DbFree(db, zSample);
105174 return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
105319 pRhs = sqlite3ValueNew(pParse->db);
105863 if( !pOrderBy && pParse->db->flags & SQLITE_ReverseOrder ){
105906 sqlite3DbFree(pParse->db, p);
105969 assert( pParse->db->mallocFailed );
106039 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
106127 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
106129 pParse->db->mallocFailed = 1;
106212 static char *explainIndexRange(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
106225 txt.db = db;
106262 sqlite3 *db = pParse->db; /* Database handle */
106274 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
106276 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
106278 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
106282 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
106285 char *zWhere = explainIndexRange(db, pLevel, pItem->pTab);
106286 zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg,
106293 sqlite3DbFree(db, zWhere);
106295 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
106298 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
106300 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
106302 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
106304 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
106310 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
106320 zMsg = sqlite3MAppendf(db, zMsg, "%s (~%lld rows)", zMsg, nRow);
106634 zEndAff = sqlite3DbStrDup(pParse->db, zStartAff);
106719 sqlite3DbFree(pParse->db, zStartAff);
106720 sqlite3DbFree(pParse->db, zEndAff);
106840 pOrTab = sqlite3StackAllocRaw(pParse->db,
106889 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
106890 pAndExpr = sqlite3ExprAnd(pParse->db, pAndExpr, pExpr);
106938 sqlite3ExprDelete(pParse->db, pAndExpr);
106944 if( pWInfo->nLevel>1 ) sqlite3StackFree(pParse->db, pOrTab);
107033 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
107039 /* assert( pInfo->needToFreeIdxStr==0 || db->mallocFailed ); */
107043 sqlite3DbFree(db, pInfo);
107048 sqlite3DbFree(db, pIdx->zColAff);
107049 sqlite3DbFree(db, pIdx);
107054 sqlite3DbFree(db, pWInfo);
107167 sqlite3 *db; /* Database connection */
107192 db = pParse->db;
107194 pWInfo = sqlite3DbMallocZero(db,
107199 if( db->mallocFailed ){
107200 sqlite3DbFree(db, pWInfo);
107215 if( db->flags & SQLITE_DistinctOpt ) pDistinct = 0;
107280 if( db->mallocFailed ){
107502 if( pParse->nErr || db->mallocFailed ){
107538 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
107544 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
107585 if( db->mallocFailed ) goto whereBeginError;
107657 whereInfoFree(db, pWInfo);
107672 sqlite3 *db = pParse->db;
107693 sqlite3DbFree(db, pLevel->u.in.aInLoop);
107754 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){
107785 whereInfoFree(db, pWInfo);
107910 sqlite3 *db = pParse->db;
107911 if( db->mallocFailed==0 && pY->op==TK_NULL ){
107913 sqlite3ExprDelete(db, pA->pRight);
109188 sqlite3SelectDelete(pParse->db, (yypminor->yy159));
109194 sqlite3ExprDelete(pParse->db, (yypminor->yy342).pExpr);
109209 sqlite3ExprListDelete(pParse->db, (yypminor->yy442));
109217 sqlite3SrcListDelete(pParse->db, (yypminor->yy347));
109228 sqlite3ExprDelete(pParse->db, (yypminor->yy122));
109235 sqlite3IdListDelete(pParse->db, (yypminor->yy180));
109241 sqlite3ExprListDelete(pParse->db, (yypminor->yy487).pList);
109242 sqlite3SelectDelete(pParse->db, (yypminor->yy487).pSelect);
109249 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy327));
109254 sqlite3IdListDelete(pParse->db, (yypminor->yy410).b);
109934 pParse->db->lookaside.bEnabled = 0;
109970 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
110167 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy159);
110179 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy159);
110212 Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0);
110228 {yygotominor.yy347 = sqlite3DbMallocZero(pParse->db, sizeof(*yygotominor.yy347));}
110273 {yygotominor.yy347 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
110403 sqlite3SelectDelete(pParse->db, pRight);
110404 sqlite3SelectDelete(pParse->db, yymsp[-4].minor.yy487.pSelect);
110416 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy180,&yymsp[0].minor.yy0);}
110419 {yygotominor.yy180 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
110491 if( yymsp[-1].minor.yy442 && yymsp[-1].minor.yy442->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
110597 sqlite3ExprListDelete(pParse->db, pList);
110616 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy342.pExpr);
110623 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy442);
110639 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
110653 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
110662 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
110669 sqlite3SrcListDelete(pParse->db, pSrc);
110684 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
110697 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
110724 sqlite3SrcListAppend(pParse->db,0,&yymsp[-3].minor.yy0,0), yymsp[-1].minor.yy442, yymsp[-9].minor.yy392,
110739 p = sqlite3Expr(pParse->db, TK_COLUMN, 0);
110863 { yygotominor.yy327 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy442, yymsp[0].minor.yy122, yymsp[-5].minor.yy258); }
110866 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, yymsp[0].minor.yy487.pList, yymsp[0].minor.yy487.pSelect, yymsp[-4].minor.yy258);}
110869 {yygotominor.yy327 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy180, 0, yymsp[0].minor.yy159, yymsp[-4].minor.yy258);}
110872 {yygotominor.yy327 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy122);}
110875 {yygotominor.yy327 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy159); }
110942 pParse->db->lookaside.bEnabled = 0;
111928 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
111929 sqlite3 *db = pParse->db; /* The database connection */
111933 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
111934 if( db->activeVdbeCnt==0 ){
111935 db->u1.isInterrupted = 0;
111943 db->mallocFailed = 1;
111951 enableLookaside = db->lookaside.bEnabled;
111952 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
111953 while( !db->mallocFailed && zSql[i]!=0 ){
111964 if( db->u1.isInterrupted ){
111972 sqlite3DbFree(db, *pzErrMsg);
111973 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
112006 db->lookaside.bEnabled = enableLookaside;
112007 if( db->mallocFailed ){
112011 sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc));
112026 sqlite3DbFree(db, pParse->aTableLock);
112040 sqlite3DeleteTable(db, pParse->pNewTable);
112043 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
112044 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
112045 sqlite3DbFree(db, pParse->azVar);
112046 sqlite3DbFree(db, pParse->aAlias);
112050 sqlite3DbFree(db, p);
112055 sqlite3DeleteTable(db, p);
112390 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
112422 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
112454 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db);
112913 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
112915 if( db->lookaside.nOut ){
112922 if( db->lookaside.bMalloced ){
112923 sqlite3_free(db->lookaside.pStart);
112942 db->lookaside.pStart = pStart;
112943 db->lookaside.pFree = 0;
112944 db->lookaside.sz = (u16)sz;
112951 p->pNext = db->lookaside.pFree;
112952 db->lookaside.pFree = p;
112955 db->lookaside.pEnd = p;
112956 db->lookaside.bEnabled = 1;
112957 db->lookaside.bMalloced = pBuf==0 ?1:0;
112959 db->lookaside.pEnd = 0;
112960 db->lookaside.bEnabled = 0;
112961 db->lookaside.bMalloced = 0;
112969 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
112970 return db->mutex;
112977 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
112979 sqlite3_mutex_enter(db->mutex);
112980 sqlite3BtreeEnterAll(db);
112981 for(i=0; i<db->nDb; i++){
112982 Btree *pBt = db->aDb[i].pBt;
112988 sqlite3BtreeLeaveAll(db);
112989 sqlite3_mutex_leave(db->mutex);
112996 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
113005 rc = setupLookaside(db, pBuf, sz, cnt);
113022 int oldFlags = db->flags;
113024 db->flags |= aFlagOp[i].mask;
113026 db->flags &= ~aFlagOp[i].mask;
113028 if( oldFlags!=db->flags ){
113029 sqlite3ExpirePreparedStatements(db);
113032 *pRes = (db->flags & aFlagOp[i].mask)!=0;
113108 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
113109 return db->lastRowid;
113115 SQLITE_API int sqlite3_changes(sqlite3 *db){
113116 return db->nChange;
113122 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
113123 return db->nTotalChange;
113131 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *db){
113132 while( db->pSavepoint ){
113133 Savepoint *pTmp = db->pSavepoint;
113134 db->pSavepoint = pTmp->pNext;
113135 sqlite3DbFree(db, pTmp);
113137 db->nSavepoint = 0;
113138 db->nStatement = 0;
113139 db->isTransactionSavepoint = 0;
113148 static void functionDestroy(sqlite3 *db, FuncDef *p){
113154 sqlite3DbFree(db, pDestructor);
113162 SQLITE_API int sqlite3_close(sqlite3 *db){
113166 if( !db ){
113169 if( !sqlite3SafetyCheckSickOrOk(db) ){
113172 sqlite3_mutex_enter(db->mutex);
113175 sqlite3ResetInternalSchema(db, -1);
113179 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
113184 sqlite3VtabRollback(db);
113187 if( db->pVdbe ){
113188 sqlite3Error(db, SQLITE_BUSY,
113190 sqlite3_mutex_leave(db->mutex);
113193 assert( sqlite3SafetyCheckSickOrOk(db) );
113195 for(j=0; j<db->nDb; j++){
113196 Btree *pBt = db->aDb[j].pBt;
113198 sqlite3Error(db, SQLITE_BUSY,
113200 sqlite3_mutex_leave(db->mutex);
113206 sqlite3CloseSavepoints(db);
113208 for(j=0; j<db->nDb; j++){
113209 struct Db *pDb = &db->aDb[j];
113218 sqlite3ResetInternalSchema(db, -1);
113223 sqlite3ConnectionClosed(db);
113225 assert( db->nDb<=2 );
113226 assert( db->aDb==db->aDbStatic );
113227 for(j=0; j<ArraySize(db->aFunc.a); j++){
113229 for(p=db->aFunc.a[j]; p; p=pHash){
113232 functionDestroy(db, p);
113234 sqlite3DbFree(db, p);
113239 for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
113247 sqlite3DbFree(db, pColl);
113249 sqlite3HashClear(&db->aCollSeq);
113251 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
113256 sqlite3DbFree(db, pMod);
113258 sqlite3HashClear(&db->aModule);
113261 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
113262 if( db->pErr ){
113263 sqlite3ValueFree(db->pErr);
113265 sqlite3CloseExtensions(db);
113267 db->magic = SQLITE_MAGIC_ERROR;
113275 sqlite3DbFree(db, db->aDb[1].pSchema);
113276 sqlite3_mutex_leave(db->mutex);
113277 db->magic = SQLITE_MAGIC_CLOSED;
113278 sqlite3_mutex_free(db->mutex);
113279 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
113280 if( db->lookaside.bMalloced ){
113281 sqlite3_free(db->lookaside.pStart);
113283 sqlite3_free(db);
113293 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
113296 assert( sqlite3_mutex_held(db->mutex) );
113298 for(i=0; i<db->nDb; i++){
113299 Btree *p = db->aDb[i].pBt;
113305 db->aDb[i].inTrans = 0;
113308 sqlite3VtabRollback(db);
113311 if( db->flags&SQLITE_InternChanges ){
113312 sqlite3ExpirePreparedStatements(db);
113313 sqlite3ResetInternalSchema(db, -1);
113317 db->nDeferredCons = 0;
113320 if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
113321 db->xRollbackCallback(db->pRollbackArg);
113392 sqlite3 *db = (sqlite3 *)ptr;
113393 int timeout = db->busyTimeout;
113408 sqlite3OsSleep(db->pVfs, delay*1000);
113411 sqlite3 *db = (sqlite3 *)ptr;
113416 sqlite3OsSleep(db->pVfs, 1000000);
113445 sqlite3 *db,
113449 sqlite3_mutex_enter(db->mutex);
113450 db->busyHandler.xFunc = xBusy;
113451 db->busyHandler.pArg = pArg;
113452 db->busyHandler.nBusy = 0;
113453 sqlite3_mutex_leave(db->mutex);
113464 sqlite3 *db,
113469 sqlite3_mutex_enter(db->mutex);
113471 db->xProgress = xProgress;
113472 db->nProgressOps = nOps;
113473 db->pProgressArg = pArg;
113475 db->xProgress = 0;
113476 db->nProgressOps = 0;
113477 db->pProgressArg = 0;
113479 sqlite3_mutex_leave(db->mutex);
113488 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
113490 db->busyTimeout = ms;
113491 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
113493 sqlite3_busy_handler(db, 0, 0);
113501 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
113502 db->u1.isInterrupted = 1;
113513 sqlite3 *db,
113526 assert( sqlite3_mutex_held(db->mutex) );
113548 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
113551 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
113568 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
113570 if( db->activeVdbeCnt ){
113571 sqlite3Error(db, SQLITE_BUSY,
113573 assert( !db->mallocFailed );
113576 sqlite3ExpirePreparedStatements(db);
113580 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
113581 assert(p || db->mallocFailed);
113588 functionDestroy(db, p);
113607 sqlite3 *db,
113616 return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xFunc, xStep,
113621 sqlite3 *db,
113633 sqlite3_mutex_enter(db->mutex);
113635 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
113643 rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xFunc, xStep, xFinal, pArg);
113647 sqlite3DbFree(db, pArg);
113651 rc = sqlite3ApiExit(db, rc);
113652 sqlite3_mutex_leave(db->mutex);
113658 sqlite3 *db,
113669 sqlite3_mutex_enter(db->mutex);
113670 assert( !db->mallocFailed );
113671 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
113672 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
113673 sqlite3DbFree(db, zFunc8);
113674 rc = sqlite3ApiExit(db, rc);
113675 sqlite3_mutex_leave(db->mutex);
113694 sqlite3 *db,
113700 sqlite3_mutex_enter(db->mutex);
113701 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
113702 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
113705 rc = sqlite3ApiExit(db, rc);
113706 sqlite3_mutex_leave(db->mutex);
113719 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
113721 sqlite3_mutex_enter(db->mutex);
113722 pOld = db->pTraceArg;
113723 db->xTrace = xTrace;
113724 db->pTraceArg = pArg;
113725 sqlite3_mutex_leave(db->mutex);
113737 sqlite3 *db,
113742 sqlite3_mutex_enter(db->mutex);
113743 pOld = db->pProfileArg;
113744 db->xProfile = xProfile;
113745 db->pProfileArg = pArg;
113746 sqlite3_mutex_leave(db->mutex);
113757 sqlite3 *db, /* Attach the hook to this database */
113762 sqlite3_mutex_enter(db->mutex);
113763 pOld = db->pCommitArg;
113764 db->xCommitCallback = xCallback;
113765 db->pCommitArg = pArg;
113766 sqlite3_mutex_leave(db->mutex);
113775 sqlite3 *db, /* Attach the hook to this database */
113780 sqlite3_mutex_enter(db->mutex);
113781 pRet = db->pUpdateArg;
113782 db->xUpdateCallback = xCallback;
113783 db->pUpdateArg = pArg;
113784 sqlite3_mutex_leave(db->mutex);
113793 sqlite3 *db, /* Attach the hook to this database */
113798 sqlite3_mutex_enter(db->mutex);
113799 pRet = db->pRollbackArg;
113800 db->xRollbackCallback = xCallback;
113801 db->pRollbackArg = pArg;
113802 sqlite3_mutex_leave(db->mutex);
113815 sqlite3 *db, /* Connection */
113821 sqlite3_wal_checkpoint(db, zDb);
113839 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
113841 UNUSED_PARAMETER(db);
113845 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
113847 sqlite3_wal_hook(db, 0, 0);
113858 sqlite3 *db, /* Attach the hook to this db handle */
113864 sqlite3_mutex_enter(db->mutex);
113865 pRet = db->pWalArg;
113866 db->xWalCallback = xCallback;
113867 db->pWalArg = pArg;
113868 sqlite3_mutex_leave(db->mutex);
113879 sqlite3 *db, /* Database handle */
113889 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
113902 sqlite3_mutex_enter(db->mutex);
113904 iDb = sqlite3FindDbName(db, zDb);
113908 sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb);
113910 rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
113911 sqlite3Error(db, rc, 0);
113913 rc = sqlite3ApiExit(db, rc);
113914 sqlite3_mutex_leave(db->mutex);
113925 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
113926 return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0);
113939 ** The mutex on database handle db should be held by the caller. The mutex
113949 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
113954 assert( sqlite3_mutex_held(db->mutex) );
113958 for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
113960 rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
113977 ** The value returned depends on the value of db->temp_store (runtime
113982 ** SQLITE_TEMP_STORE db->temp_store Location of temporary database
113993 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3 *db){
113995 return ( db->temp_store==2 );
113998 return ( db->temp_store!=1 );
114012 SQLITE_API const char *sqlite3_errmsg(sqlite3 *db){
114014 if( !db ){
114017 if( !sqlite3SafetyCheckSickOrOk(db) ){
114020 sqlite3_mutex_enter(db->mutex);
114021 if( db->mallocFailed ){
114024 z = (char*)sqlite3_value_text(db->pErr);
114025 assert( !db->mallocFailed );
114027 z = sqlite3ErrStr(db->errCode);
114030 sqlite3_mutex_leave(db->mutex);
114039 SQLITE_API const void *sqlite3_errmsg16(sqlite3 *db){
114053 if( !db ){
114056 if( !sqlite3SafetyCheckSickOrOk(db) ){
114059 sqlite3_mutex_enter(db->mutex);
114060 if( db->mallocFailed ){
114063 z = sqlite3_value_text16(db->pErr);
114065 sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
114067 z = sqlite3_value_text16(db->pErr);
114070 ** above. If this is the case, then the db->mallocFailed flag needs to
114074 db->mallocFailed = 0;
114076 sqlite3_mutex_leave(db->mutex);
114085 SQLITE_API int sqlite3_errcode(sqlite3 *db){
114086 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
114089 if( !db || db->mallocFailed ){
114092 return db->errCode & db->errMask;
114094 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
114095 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
114098 if( !db || db->mallocFailed ){
114101 return db->errCode;
114105 ** Create a new collating function for database "db". The name is zName
114109 sqlite3* db,
114120 assert( sqlite3_mutex_held(db->mutex) );
114140 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
114142 if( db->activeVdbeCnt ){
114143 sqlite3Error(db, SQLITE_BUSY,
114147 sqlite3ExpirePreparedStatements(db);
114156 CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
114170 pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
114176 sqlite3Error(db, SQLITE_OK, 0);
114245 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
114272 oldLimit = db->aLimit[limitId];
114277 db->aLimit[limitId] = newLimit;
114523 sqlite3 *db; /* Store allocated handle here */
114592 db = sqlite3MallocZero( sizeof(sqlite3) );
114593 if( db==0 ) goto opendb_out;
114595 db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
114596 if( db->mutex==0 ){
114597 sqlite3_free(db);
114598 db = 0;
114602 sqlite3_mutex_enter(db->mutex);
114603 db->errMask = 0xff;
114604 db->nDb = 2;
114605 db->magic = SQLITE_MAGIC_BUSY;
114606 db->aDb = db->aDbStatic;
114608 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
114609 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
114610 db->autoCommit = 1;
114611 db->nextAutovac = -1;
114612 db->nextPagesize = 0;
114613 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
114627 sqlite3HashInit(&db->aCollSeq);
114629 sqlite3HashInit(&db->aModule);
114636 createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
114637 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
114638 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
114639 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
114640 if( db->mallocFailed ){
114643 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
114644 assert( db->pDfltColl!=0 );
114647 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
114650 db->openFlags = flags;
114651 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
114653 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
114654 sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
114660 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
114666 sqlite3Error(db, rc, 0);
114669 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
114670 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
114676 db->aDb[0].zName = "main";
114677 db->aDb[0].safety_level = 3;
114678 db->aDb[1].zName = "temp";
114679 db->aDb[1].safety_level = 1;
114681 db->magic = SQLITE_MAGIC_OPEN;
114682 if( db->mallocFailed ){
114690 sqlite3Error(db, SQLITE_OK, 0);
114691 sqlite3RegisterBuiltinFunctions(db);
114696 rc = sqlite3_errcode(db);
114698 sqlite3AutoLoadExtensions(db);
114699 rc = sqlite3_errcode(db);
114706 if( !db->mallocFailed ){
114708 rc = sqlite3Fts1Init(db);
114713 if( !db->mallocFailed && rc==SQLITE_OK ){
114715 rc = sqlite3Fts2Init(db);
114720 if( !db->mallocFailed && rc==SQLITE_OK ){
114721 rc = sqlite3Fts3Init(db);
114726 if( !db->mallocFailed && rc==SQLITE_OK ){
114727 rc = sqlite3IcuInit(db);
114732 if( !db->mallocFailed && rc==SQLITE_OK){
114733 rc = sqlite3RtreeInit(db);
114737 sqlite3Error(db, rc, 0);
114744 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
114745 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
114750 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
114753 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
114757 if( db ){
114758 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
114759 sqlite3_mutex_leave(db->mutex);
114761 rc = sqlite3_errcode(db);
114762 assert( db!=0 || rc==SQLITE_NOMEM );
114764 sqlite3_close(db);
114765 db = 0;
114767 db->magic = SQLITE_MAGIC_SICK;
114769 *ppDb = db;
114785 sqlite3 **ppDb, /* OUT: SQLite db handle */
114831 ** Register a new collation sequence with the database handle db.
114834 sqlite3* db,
114841 sqlite3_mutex_enter(db->mutex);
114842 assert( !db->mallocFailed );
114843 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
114844 rc = sqlite3ApiExit(db, rc);
114845 sqlite3_mutex_leave(db->mutex);
114850 ** Register a new collation sequence with the database handle db.
114853 sqlite3* db,
114861 sqlite3_mutex_enter(db->mutex);
114862 assert( !db->mallocFailed );
114863 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
114864 rc = sqlite3ApiExit(db, rc);
114865 sqlite3_mutex_leave(db->mutex);
114871 ** Register a new collation sequence with the database handle db.
114874 sqlite3* db,
114882 sqlite3_mutex_enter(db->mutex);
114883 assert( !db->mallocFailed );
114884 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
114886 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
114887 sqlite3DbFree(db, zName8);
114889 rc = sqlite3ApiExit(db, rc);
114890 sqlite3_mutex_leave(db->mutex);
114897 ** db. Replace any previously installed collation sequence factory.
114900 sqlite3 *db,
114904 sqlite3_mutex_enter(db->mutex);
114905 db->xCollNeeded = xCollNeeded;
114906 db->xCollNeeded16 = 0;
114907 db->pCollNeededArg = pCollNeededArg;
114908 sqlite3_mutex_leave(db->mutex);
114915 ** db. Replace any previously installed collation sequence factory.
114918 sqlite3 *db,
114922 sqlite3_mutex_enter(db->mutex);
114923 db->xCollNeeded = 0;
114924 db->xCollNeeded16 = xCollNeeded16;
114925 db->pCollNeededArg = pCollNeededArg;
114926 sqlite3_mutex_leave(db->mutex);
114949 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
114950 return db->autoCommit;
115005 sqlite3 *db, /* Connection handle */
115028 sqlite3_mutex_enter(db->mutex);
115029 sqlite3BtreeEnterAll(db);
115030 rc = sqlite3Init(db, &zErrMsg);
115036 pTab = sqlite3FindTable(db, zTableName, zDbName);
115086 sqlite3BtreeLeaveAll(db);
115099 sqlite3DbFree(db, zErrMsg);
115100 zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
115104 sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
115105 sqlite3DbFree(db, zErrMsg);
115106 rc = sqlite3ApiExit(db, rc);
115107 sqlite3_mutex_leave(db->mutex);
115131 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
115132 sqlite3_mutex_enter(db->mutex);
115133 db->errMask = onoff ? 0xffffffff : 0xff;
115134 sqlite3_mutex_leave(db->mutex);
115141 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
115145 sqlite3_mutex_enter(db->mutex);
115146 pBtree = sqlite3DbNameToBtree(db, zDbName);
115165 sqlite3_mutex_leave(db->mutex);
115313 /* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
115316 ** connection db.
115319 sqlite3 *db = va_arg(ap, sqlite3*);
115321 sqlite3_mutex_enter(db->mutex);
115322 sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
115323 sqlite3_mutex_leave(db->mutex);
115327 /* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
115337 sqlite3 *db = va_arg(ap, sqlite3*);
115339 db->flags = (x & SQLITE_OptMask) | (db->flags & ~SQLITE_OptMask);
115461 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
115463 for(i=0; i<db->nDb; i++){
115464 if( db->aDb[i].pBt
115465 && (zDbName==0 || sqlite3StrICmp(zDbName, db
115467 return db->aDb[i].pBt;
115477 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
115478 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
115486 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
115487 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
115543 ** 3) If the argument db is not NULL, then none of the entries in the
115545 ** set to db. This is used when closing connection db.
115547 static void checkListProperties(sqlite3 *db){
115560 assert( db==0 || p->pUnlockConnection!=db );
115561 assert( db==0 || p->pBlockingConnection!=db );
115570 ** Remove connection db from the blocked connections list. If connection
115571 ** db is not currently a part of the list, this function is a no-op.
115573 static void removeFromBlockedList(sqlite3 *db){
115577 if( *pp==db ){
115585 ** Add connection db to the blocked connections list. It is assumed
115588 static void addToBlockedList(sqlite3 *db){
115593 *pp && (*pp)->xUnlockNotify!=db->xUnlockNotify;
115596 db->pNextBlocked = *pp;
115597 *pp = db;
115620 ** This is called after connection "db" has attempted some operation
115623 ** cache. pOther is found by looking at db->pBlockingConnection.
115628 ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
115635 ** on the same "db". If xNotify==0 then any prior callbacks are immediately
115639 sqlite3 *db,
115645 sqlite3_mutex_enter(db->mutex);
115649 removeFromBlockedList(db);
115650 db->pBlockingConnection = 0;
115651 db->pUnlockConnection = 0;
115652 db->xUnlockNotify = 0;
115653 db->pUnlockArg = 0;
115654 }else if( 0==db->pBlockingConnection ){
115663 for(p=db->pBlockingConnection; p && p!=db; p=p->pUnlockConnection){}
115667 db->pUnlockConnection = db->pBlockingConnection;
115668 db->xUnlockNotify = xNotify;
115669 db->pUnlockArg = pArg;
115670 removeFromBlockedList(db);
115671 addToBlockedList(db);
115676 assert( !db->mallocFailed );
115677 sqlite3Error(db, rc, (rc?"database is deadlocked":0));
115678 sqlite3_mutex_leave(db->mutex);
115684 ** associated with connection db. The operation will return SQLITE_LOCKED
115688 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *db, sqlite3 *pBlocker){
115690 if( db->pBlockingConnection==0 && db->pUnlockConnection==0 ){
115691 addToBlockedList(db);
115693 db->pBlockingConnection = pBlocker;
115699 ** the transaction opened by database db has just finished. Locks held
115700 ** by database connection db have been released.
115706 ** set to db, then set pBlockingConnection=0.
115709 ** set to db, then invoke the configured unlock-notify callback and
115716 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
115732 if( p->pBlockingConnection==db ){
115737 if( p->pUnlockConnection==db ){
115764 ** is returned the transaction on connection db will still be
115815 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
115816 sqlite3ConnectionUnlocked(db);
115818 removeFromBlockedList(db);
115819 checkListProperties(db);
116583 sqlite3 *db; /* The database connection */
116901 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
116902 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
116910 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
117121 sqlite3 *db, /* Database in which to run SQL */
117134 *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
117146 sqlite3 *db = p->db; /* Database handle */
117150 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
117152 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
117153 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
117154 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
117155 fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
117183 sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
117199 rc = sqlite3_declare_vtab(p->db, zSql);
117220 sqlite3 *db = p->db; /* The database connection */
117238 fts3DbExec(&rc, db,
117246 fts3DbExec(&rc, db,
117250 fts3DbExec(&rc, db,
117263 fts3DbExec(&rc, db,
117269 fts3DbExec(&rc, db,
117294 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
117604 sqlite3 *db, /* Database handle */
117605 const char *zDb, /* Name of db (i.e. "main", "temp" etc.) */
117619 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
117676 sqlite3 *db, /* The SQLite database connection */
117853 rc = fts3ContentColumns(db, argv[1], zContent, &aCol, &nCol, &nString);
117905 p->db = db;
118000 sqlite3 *db, /* Database connection */
118007 return fts3InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
118010 sqlite3 *db, /* Database connection */
118017 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
118161 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
119629 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
120002 sqlite3 *db = p->db; /* Database connection */
120015 fts3DbExec(&rc, db,
120022 fts3DbExec(&rc, db,
120028 fts3DbExec(&rc, db,
120033 fts3DbExec(&rc, db,
120037 fts3DbExec(&rc, db,
120146 SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){
120158 rc = sqlite3Fts3InitTerm(db);
120162 rc = sqlite3Fts3InitAux(db);
120190 rc = sqlite3Fts3ExprInitTestInterface(db);
120199 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
120200 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
120201 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
120202 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
120203 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
120204 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
120207 db, "fts3", &fts3Module, (void *)pHash, hashDestroy
120211 db, "fts4", &fts3Module, (void *)pHash, 0
121096 ** the db. In this case the position-list is not populated at all.
121799 sqlite3 *db,
121804 return sqlite3Fts3Init(db);
121866 sqlite3 *db, /* Database connection */
121896 rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
121907 p->pFts3Tab->db = db;
122249 ** Register the fts3aux module with database connection db. Return SQLITE_OK
122252 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db){
122280 rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
123125 sqlite3 *db,
123134 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
123228 sqlite3 *db = sqlite3_context_db_handle(context);
123237 rc = queryTestTokenizer(db,
123290 ** with database connection db.
123292 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
123294 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
124656 sqlite3 *db,
124664 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
124678 sqlite3 *db,
124687 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
124730 sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
124737 rc = queryTokenizer(db, "simple", &p2);
124740 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
124743 assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
124746 rc = registerTokenizer(db, "nosuchtokenizer", p1);
124748 rc = queryTokenizer(db, "nosuchtokenizer", &p2);
124758 ** Set up SQL objects in database db used to access the contents of
124775 sqlite3 *db,
124786 void *pdb = (void *)db;
124795 rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0);
124798 rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0);
124802 rc = sqlite3_create_function(db, zTest, 2, any, p, testFunc, 0, 0);
124805 rc = sqlite3_create_function(db, zTest, 3, any, p, testFunc, 0, 0);
124808 rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0);
125369 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, NULL);
125965 *piDocid = sqlite3_last_insert_rowid(p->db);
126155 p->db, p->zDb, p->zSegmentsTbl, "block", iBlockid, 0, &p->pSegments
127030 ** blocks were written to the db). Otherwise, an SQLite error code is
127242 SegmentWriter *pWriter, /* SegmentWriter to flush to the db */
127249 sqlite3_int64 iLastLeaf; /* Largest leaf block id written to db */
128175 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
128426 if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1;
128535 if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
128593 rc = sqlite3_exec(p->db, "SAVEPOINT fts3", 0, 0, 0);
128597 int rc2 = sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
128600 sqlite3_exec(p->db, "ROLLBACK TO fts3", 0, 0, 0);
128601 sqlite3_exec(p->db, "RELEASE fts3", 0, 0, 0);
130258 sqlite3 *db; /* Host database connection */
130738 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
130828 sqlite3 *db,
130834 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
130841 sqlite3 *db,
130847 return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
130902 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
132742 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
132895 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
132963 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
132997 sqlite3 *db,
133024 pRtree->db = db;
133037 rc = sqlite3_exec(db, zCreate, 0, 0, 0);
133057 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
133070 ** using database connection db. If successful, the integer value returned
133074 static int getIntFromStmt(sqlite3 *db, const char *zSql, int *piVal){
133078 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
133105 sqlite3 *db, /* Database handle */
133114 rc = getIntFromStmt(db, zSql, &iPageSize);
133126 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
133143 sqlite3 *db, /* Database connection */
133169 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
133190 rc = getNodeSize(db, pRtree, isCreate);
133197 if( (rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate)) ){
133198 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
133215 }else if( SQLITE_OK!=(rc = sqlite3_declare_vtab(db, zSql)) ){
133216 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
133299 ** Register the r-tree module with database handle db. This creates the
133303 SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
133307 rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
133309 rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
133313 rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
133317 rc = sqlite3_create_module_v2(db, "rtree_i32", &rtreeModule, c, 0);
133367 sqlite3 *db,
133382 return sqlite3_create_function_v2(db, zGeom, -1, SQLITE_ANY,
133389 sqlite3 *db,
133394 return sqlite3RtreeInit(db);
133816 sqlite3 *db = (sqlite3 *)sqlite3_user_data(p);
133838 rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator,
133848 ** Register the ICU extension functions with database db.
133850 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
133873 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
133882 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
133891 sqlite3 *db,
133896 return sqlite3IcuInit(db);