Lines Matching refs:db
38 sqlite *db = pParse->db; in sqliteBeginParse() local
41 if((db->flags & SQLITE_Initialized)==0 && db->init.busy==0 ){ in sqliteBeginParse()
42 int rc = sqliteInit(db, &pParse->zErrMsg); in sqliteBeginParse()
48 for(i=0; i<db->nDb; i++){ in sqliteBeginParse()
49 DbClearProperty(db, i, DB_Locked); in sqliteBeginParse()
50 if( !db->aDb[i].inTrans ){ in sqliteBeginParse()
51 DbClearProperty(db, i, DB_Cookie); in sqliteBeginParse()
68 sqlite *db = pParse->db; in sqliteExec() local
76 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0; in sqliteExec()
105 Table *sqliteFindTable(sqlite *db, const char *zName, const char *zDatabase){ in sqliteFindTable() argument
108 for(i=0; i<db->nDb; i++){ in sqliteFindTable()
110 if( zDatabase!=0 && sqliteStrICmp(zDatabase, db->aDb[j].zName) ) continue; in sqliteFindTable()
111 p = sqliteHashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1); in sqliteFindTable()
131 p = sqliteFindTable(pParse->db, zName, zDbase); in sqliteLocateTable()
135 }else if( sqliteFindTable(pParse->db, zName, 0)!=0 ){ in sqliteLocateTable()
157 Index *sqliteFindIndex(sqlite *db, const char *zName, const char *zDb){ in sqliteFindIndex() argument
160 for(i=0; i<db->nDb; i++){ in sqliteFindIndex()
162 if( zDb && sqliteStrICmp(zDb, db->aDb[j].zName) ) continue; in sqliteFindIndex()
163 p = sqliteHashFind(&db->aDb[j].idxHash, zName, strlen(zName)+1); in sqliteFindIndex()
177 static void sqliteDeleteIndex(sqlite *db, Index *p){ in sqliteDeleteIndex() argument
180 assert( db!=0 && p->zName!=0 ); in sqliteDeleteIndex()
181 pOld = sqliteHashInsert(&db->aDb[p->iDb].idxHash, p->zName, in sqliteDeleteIndex()
184 sqliteHashInsert(&db->aDb[p->iDb].idxHash, pOld->zName, in sqliteDeleteIndex()
195 void sqliteUnlinkAndDeleteIndex(sqlite *db, Index *pIndex){ in sqliteUnlinkAndDeleteIndex() argument
205 sqliteDeleteIndex(db, pIndex); in sqliteUnlinkAndDeleteIndex()
218 void sqliteResetInternalSchema(sqlite *db, int iDb){ in sqliteResetInternalSchema() argument
224 assert( iDb>=0 && iDb<db->nDb ); in sqliteResetInternalSchema()
225 db->flags &= ~SQLITE_Initialized; in sqliteResetInternalSchema()
226 for(i=iDb; i<db->nDb; i++){ in sqliteResetInternalSchema()
227 Db *pDb = &db->aDb[i]; in sqliteResetInternalSchema()
241 sqliteDeleteTable(db, pTab); in sqliteResetInternalSchema()
244 DbClearProperty(db, i, DB_SchemaLoaded); in sqliteResetInternalSchema()
248 db->flags &= ~SQLITE_InternChanges; in sqliteResetInternalSchema()
256 for(i=0; i<db->nDb; i++){ in sqliteResetInternalSchema()
257 struct Db *pDb = &db->aDb[i]; in sqliteResetInternalSchema()
263 for(i=j=2; i<db->nDb; i++){ in sqliteResetInternalSchema()
264 struct Db *pDb = &db->aDb[i]; in sqliteResetInternalSchema()
271 db->aDb[j] = db->aDb[i]; in sqliteResetInternalSchema()
275 memset(&db->aDb[j], 0, (db->nDb-j)*sizeof(db->aDb[j])); in sqliteResetInternalSchema()
276 db->nDb = j; in sqliteResetInternalSchema()
277 if( db->nDb<=2 && db->aDb!=db->aDbStatic ){ in sqliteResetInternalSchema()
278 memcpy(db->aDbStatic, db->aDb, 2*sizeof(db->aDb[0])); in sqliteResetInternalSchema()
279 sqliteFree(db->aDb); in sqliteResetInternalSchema()
280 db->aDb = db->aDbStatic; in sqliteResetInternalSchema()
289 void sqliteRollbackInternalChanges(sqlite *db){ in sqliteRollbackInternalChanges() argument
290 if( db->flags & SQLITE_InternChanges ){ in sqliteRollbackInternalChanges()
291 sqliteResetInternalSchema(db, 0); in sqliteRollbackInternalChanges()
298 void sqliteCommitInternalChanges(sqlite *db){ in sqliteCommitInternalChanges() argument
299 db->aDb[0].schema_cookie = db->next_cookie; in sqliteCommitInternalChanges()
300 db->flags &= ~SQLITE_InternChanges; in sqliteCommitInternalChanges()
318 void sqliteDeleteTable(sqlite *db, Table *pTable){ in sqliteDeleteTable() argument
330 sqliteDeleteIndex(db, pIndex); in sqliteDeleteTable()
338 assert( pTable->iDb<db->nDb ); in sqliteDeleteTable()
339 assert( sqliteHashFind(&db->aDb[pTable->iDb].aFKey, in sqliteDeleteTable()
361 static void sqliteUnlinkAndDeleteTable(sqlite *db, Table *p){ in sqliteUnlinkAndDeleteTable() argument
365 assert( db!=0 ); in sqliteUnlinkAndDeleteTable()
366 pOld = sqliteHashInsert(&db->aDb[i].tblHash, p->zName, strlen(p->zName)+1, 0); in sqliteUnlinkAndDeleteTable()
370 pF2 = sqliteHashFind(&db->aDb[i].aFKey, pF1->zTo, nTo); in sqliteUnlinkAndDeleteTable()
372 sqliteHashInsert(&db->aDb[i].aFKey, pF1->zTo, nTo, pF1->pNextTo); in sqliteUnlinkAndDeleteTable()
380 sqliteDeleteTable(db, p); in sqliteUnlinkAndDeleteTable()
433 sqlite *db = pParse->db; in sqliteStartTable() local
440 if( db->init.iDb==1 ) isTemp = 1; in sqliteStartTable()
474 if( isTemp && db->aDb[1].pBt==0 && !pParse->explain ){ in sqliteStartTable()
475 int rc = sqliteBtreeFactory(db, 0, 0, MAX_PAGES, &db->aDb[1].pBt); in sqliteStartTable()
482 if( db->flags & SQLITE_InTrans ){ in sqliteStartTable()
483 rc = sqliteBtreeBeginTrans(db->aDb[1].pBt); in sqliteStartTable()
499 pTable = sqliteFindTable(db, zName, 0); in sqliteStartTable()
500 iDb = isTemp ? 1 : db->init.iDb; in sqliteStartTable()
501 if( pTable!=0 && (pTable->iDb==iDb || !db->init.busy) ){ in sqliteStartTable()
506 if( (pIdx = sqliteFindIndex(db, zName, 0))!=0 && in sqliteStartTable()
507 (pIdx->iDb==0 || !db->init.busy) ){ in sqliteStartTable()
523 if( pParse->pNewTable ) sqliteDeleteTable(db, pParse->pNewTable); in sqliteStartTable()
534 if( !db->init.busy && (v = sqliteGetVdbe(pParse))!=0 ){ in sqliteStartTable()
537 sqliteVdbeAddOp(v, OP_Integer, db->file_format, 0); in sqliteStartTable()
629 if( pParse->db->file_format>=4 ){ in sqliteAddColumnType()
706 if( pParse->db->file_format>=1 && in sqliteAddPrimaryKey()
776 void sqliteChangeCookie(sqlite *db, Vdbe *v){ in sqliteChangeCookie() argument
777 if( db->next_cookie==db->aDb[0].schema_cookie ){ in sqliteChangeCookie()
780 db->next_cookie = db->aDb[0].schema_cookie + r + 1; in sqliteChangeCookie()
781 db->flags |= SQLITE_InternChanges; in sqliteChangeCookie()
782 sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0); in sqliteChangeCookie()
885 sqlite *db = pParse->db; in sqliteEndTable() local
911 if( db->init.busy ){ in sqliteEndTable()
912 p->tnum = db->init.newTnum; in sqliteEndTable()
922 if( !db->init.busy ){ in sqliteEndTable()
955 sqliteChangeCookie(db, v); in sqliteEndTable()
972 pOld = sqliteHashInsert(&db->aDb[p->iDb].tblHash, in sqliteEndTable()
980 pFKey->pNextTo = sqliteHashFind(&db->aDb[p->iDb].aFKey, pFKey->zTo, nTo); in sqliteEndTable()
981 sqliteHashInsert(&db->aDb[p->iDb].aFKey, pFKey->zTo, nTo, pFKey); in sqliteEndTable()
984 db->nTable++; in sqliteEndTable()
985 db->flags |= SQLITE_InternChanges; in sqliteEndTable()
1025 if( !pParse->db->init.busy ){ in sqliteCreateView()
1106 DbSetProperty(pParse->db, pTable->iDb, DB_UnresetViews); in sqliteViewGetColumnNames()
1142 static void sqliteViewResetAll(sqlite *db, int idx){ in sqliteViewResetAll() argument
1144 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return; in sqliteViewResetAll()
1145 for(i=sqliteHashFirst(&db->aDb[idx].tblHash); i; i=sqliteHashNext(i)){ in sqliteViewResetAll()
1151 DbClearProperty(db, idx, DB_UnresetViews); in sqliteViewResetAll()
1163 pTab = sqliteFindTable(pParse->db, zName, 0); in sqliteTableFromToken()
1179 sqlite *db = pParse->db; in sqliteDropTable() local
1186 assert( iDb>=0 && iDb<db->nDb ); in sqliteDropTable()
1191 const char *zDb = db->aDb[pTable->iDb].zName; in sqliteDropTable()
1274 sqliteChangeCookie(db, v); in sqliteDropTable()
1292 sqliteUnlinkAndDeleteTable(db, pTable); in sqliteDropTable()
1293 db->flags |= SQLITE_InternChanges; in sqliteDropTable()
1295 sqliteViewResetAll(db, iDb); in sqliteDropTable()
1488 sqlite *db = pParse->db; in sqliteCreateIndex() local
1491 if( db->init.busy in sqliteCreateIndex()
1492 && sqliteFixInit(&sFix, pParse, db->init.iDb, "index", pName) in sqliteCreateIndex()
1514 if( pTab->iDb>=2 && db->init.busy==0 ){ in sqliteCreateIndex()
1537 if( pName && !db->init.busy ){ in sqliteCreateIndex()
1542 if( (pISameName = sqliteFindIndex(db, zName, 0))!=0 ){ in sqliteCreateIndex()
1546 if( (pTSameName = sqliteFindTable(db, zName, 0))!=0 ){ in sqliteCreateIndex()
1567 const char *zDb = db->aDb[pTab->iDb].zName; in sqliteCreateIndex()
1569 assert( pTab->iDb==db->init.iDb || isTemp ); in sqliteCreateIndex()
1605 pIndex->iDb = isTemp ? 1 : db->init.iDb; in sqliteCreateIndex()
1629 p = sqliteHashInsert(&db->aDb[pIndex->iDb].idxHash, in sqliteCreateIndex()
1636 db->flags |= SQLITE_InternChanges; in sqliteCreateIndex()
1661 if( db->init.busy && pTable!=0 ){ in sqliteCreateIndex()
1662 pIndex->tnum = db->init.newTnum; in sqliteCreateIndex()
1680 else if( db->init.busy==0 ){ in sqliteCreateIndex()
1728 if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIndex); in sqliteCreateIndex()
1738 sqliteChangeCookie(db, v); in sqliteCreateIndex()
1760 sqlite *db = pParse->db; in sqliteDropIndex() local
1764 pIndex = sqliteFindIndex(db, pName->a[0].zName, pName->a[0].zDatabase); in sqliteDropIndex()
1783 const char *zDb = db->aDb[pIndex->iDb].zName; in sqliteDropIndex()
1816 sqliteChangeCookie(db, v); in sqliteDropIndex()
1826 sqliteUnlinkAndDeleteIndex(db, pIndex); in sqliteDropIndex()
1827 db->flags |= SQLITE_InternChanges; in sqliteDropIndex()
2020 sqlite *db; in sqliteBeginTransaction() local
2022 if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return; in sqliteBeginTransaction()
2025 if( db->flags & SQLITE_InTrans ){ in sqliteBeginTransaction()
2031 db->flags |= SQLITE_InTrans; in sqliteBeginTransaction()
2032 db->onError = onError; in sqliteBeginTransaction()
2040 sqlite *db; in sqliteCommitTransaction() local
2042 if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return; in sqliteCommitTransaction()
2045 if( (db->flags & SQLITE_InTrans)==0 ){ in sqliteCommitTransaction()
2050 db->flags &= ~SQLITE_InTrans; in sqliteCommitTransaction()
2054 db->onError = OE_Default; in sqliteCommitTransaction()
2062 sqlite *db; in sqliteRollbackTransaction() local
2065 if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return; in sqliteRollbackTransaction()
2068 if( (db->flags & SQLITE_InTrans)==0 ){ in sqliteRollbackTransaction()
2077 db->flags &= ~SQLITE_InTrans; in sqliteRollbackTransaction()
2078 db->onError = OE_Default; in sqliteRollbackTransaction()
2087 sqlite *db = pParse->db; in sqliteCodeVerifySchema() local
2089 assert( iDb>=0 && iDb<db->nDb ); in sqliteCodeVerifySchema()
2090 assert( db->aDb[iDb].pBt!=0 ); in sqliteCodeVerifySchema()
2091 if( iDb!=1 && !DbHasProperty(db, iDb, DB_Cookie) ){ in sqliteCodeVerifySchema()
2092 sqliteVdbeAddOp(v, OP_VerifyCookie, iDb, db->aDb[iDb].schema_cookie); in sqliteCodeVerifySchema()
2093 DbSetProperty(db, iDb, DB_Cookie); in sqliteCodeVerifySchema()
2117 sqlite *db = pParse->db; in sqliteBeginWriteOperation() local
2118 if( DbHasProperty(db, iDb, DB_Locked) ) return; in sqliteBeginWriteOperation()
2121 if( !db->aDb[iDb].inTrans ){ in sqliteBeginWriteOperation()
2123 DbSetProperty(db, iDb, DB_Locked); in sqliteBeginWriteOperation()
2130 DbSetProperty(db, iDb, DB_Locked); in sqliteBeginWriteOperation()
2146 sqlite *db = pParse->db; in sqliteEndWriteOperation() local
2150 if( db->flags & SQLITE_InTrans ){ in sqliteEndWriteOperation()