Lines Matching refs:db
28 sqlite *db; /* The database being initialized */ member
70 sqlite *db = pData->db; in sqliteInitCallback() local
82 assert( db->init.busy ); in sqliteInitCallback()
83 db->init.iDb = atoi(argv[4]); in sqliteInitCallback()
84 assert( db->init.iDb>=0 && db->init.iDb<db->nDb ); in sqliteInitCallback()
85 db->init.newTnum = atoi(argv[2]); in sqliteInitCallback()
86 if( sqlite_exec(db, argv[3], 0, 0, &zErr) ){ in sqliteInitCallback()
90 db->init.iDb = 0; in sqliteInitCallback()
102 assert( iDb>=0 && iDb<db->nDb ); in sqliteInitCallback()
103 pIndex = sqliteFindIndex(db, argv[1], db->aDb[iDb].zName); in sqliteInitCallback()
146 pTab = sqliteFindTable(pData->db, argv[0], 0); in upgrade_3_callback()
153 rc = sqlite_exec_printf(pData->db, in upgrade_3_callback()
169 pTab = sqliteFindTable(pData->db, argv[0], 0); in upgrade_3_callback()
187 static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ in sqliteInitOne() argument
222 assert( iDb>=0 && iDb<db->nDb ); in sqliteInitOne()
238 sqliteSafetyOff(db); in sqliteInitOne()
246 initData.db = db; in sqliteInitOne()
249 pTab = sqliteFindTable(db, zMasterName, db->aDb[iDb].zName); in sqliteInitOne()
255 sqliteSafetyOn(db); in sqliteInitOne()
259 if( db->aDb[iDb].pBt==0 ) return SQLITE_OK; in sqliteInitOne()
260 rc = sqliteBtreeCursor(db->aDb[iDb].pBt, 2, 0, &curMain); in sqliteInitOne()
268 rc = sqliteBtreeGetMeta(db->aDb[iDb].pBt, meta); in sqliteInitOne()
274 db->aDb[iDb].schema_cookie = meta[1]; in sqliteInitOne()
276 db->next_cookie = meta[1]; in sqliteInitOne()
277 db->file_format = meta[2]; in sqliteInitOne()
280 db->cache_size = size; in sqliteInitOne()
281 db->safety_level = meta[4]; in sqliteInitOne()
282 if( meta[6]>0 && meta[6]<=2 && db->temp_store==0 ){ in sqliteInitOne()
283 db->temp_store = meta[6]; in sqliteInitOne()
285 if( db->safety_level==0 ) db->safety_level = 2; in sqliteInitOne()
294 if( db->file_format==0 ){ in sqliteInitOne()
296 db->file_format = 4; in sqliteInitOne()
297 }else if( db->file_format>4 ){ in sqliteInitOne()
302 }else if( iDb!=1 && (db->file_format!=meta[2] || db->file_format<4) ){ in sqliteInitOne()
303 assert( db->file_format>=4 ); in sqliteInitOne()
306 db->aDb[iDb].zName, (char*)0); in sqliteInitOne()
309 "database: ", db->aDb[iDb].zName, (char*)0); in sqliteInitOne()
311 sqliteBtreeClose(db->aDb[iDb].pBt); in sqliteInitOne()
312 db->aDb[iDb].pBt = 0; in sqliteInitOne()
315 sqliteBtreeSetCacheSize(db->aDb[iDb].pBt, db->cache_size); in sqliteInitOne()
316 sqliteBtreeSetSafetyLevel(db->aDb[iDb].pBt, meta[4]==0 ? 2 : meta[4]); in sqliteInitOne()
320 assert( db->init.busy ); in sqliteInitOne()
321 sqliteSafetyOff(db); in sqliteInitOne()
337 if( db->file_format>=2 ){ in sqliteInitOne()
340 db->aDb[iDb].zName, "\".", zMasterName, (char*)0); in sqliteInitOne()
344 db->aDb[iDb].zName, "\".", zMasterName, in sqliteInitOne()
348 rc = sqlite_exec(db, zSql, sqliteInitCallback, &initData, 0); in sqliteInitOne()
351 sqliteSafetyOn(db); in sqliteInitOne()
356 sqliteResetInternalSchema(db, 0); in sqliteInitOne()
359 DbSetProperty(db, iDb, DB_SchemaLoaded); in sqliteInitOne()
361 sqliteResetInternalSchema(db, iDb); in sqliteInitOne()
379 int sqliteInit(sqlite *db, char **pzErrMsg){ in sqliteInit() argument
382 if( db->init.busy ) return SQLITE_OK; in sqliteInit()
383 assert( (db->flags & SQLITE_Initialized)==0 ); in sqliteInit()
385 db->init.busy = 1; in sqliteInit()
386 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ in sqliteInit()
387 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue; in sqliteInit()
388 rc = sqliteInitOne(db, i, pzErrMsg); in sqliteInit()
390 sqliteResetInternalSchema(db, i); in sqliteInit()
398 if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ in sqliteInit()
399 rc = sqliteInitOne(db, 1, pzErrMsg); in sqliteInit()
401 sqliteResetInternalSchema(db, 1); in sqliteInit()
405 db->init.busy = 0; in sqliteInit()
407 db->flags |= SQLITE_Initialized; in sqliteInit()
408 sqliteCommitInternalChanges(db); in sqliteInit()
416 if( rc==SQLITE_OK && db->file_format<3 ){ in sqliteInit()
421 db->magic = SQLITE_MAGIC_OPEN; in sqliteInit()
422 initData.db = db; in sqliteInit()
424 db->file_format = 3; in sqliteInit()
425 rc = sqlite_exec(db, in sqliteInit()
431 sqliteBtreeGetMeta(db->aDb[0].pBt, meta); in sqliteInit()
433 sqliteBtreeUpdateMeta(db->aDb[0].pBt, meta); in sqliteInit()
434 sqlite_exec(db, "COMMIT", 0, 0, 0); in sqliteInit()
445 db->flags &= ~SQLITE_Initialized; in sqliteInit()
476 sqlite *db; in sqlite_open() local
480 db = sqliteMalloc( sizeof(sqlite) ); in sqlite_open()
482 if( db==0 ) goto no_mem_on_open; in sqlite_open()
483 db->onError = OE_Default; in sqlite_open()
484 db->priorNewRowid = 0; in sqlite_open()
485 db->magic = SQLITE_MAGIC_BUSY; in sqlite_open()
486 db->nDb = 2; in sqlite_open()
487 db->aDb = db->aDbStatic; in sqlite_open()
489 sqliteHashInit(&db->aFunc, SQLITE_HASH_STRING, 1); in sqlite_open()
490 for(i=0; i<db->nDb; i++){ in sqlite_open()
491 sqliteHashInit(&db->aDb[i].tblHash, SQLITE_HASH_STRING, 0); in sqlite_open()
492 sqliteHashInit(&db->aDb[i].idxHash, SQLITE_HASH_STRING, 0); in sqlite_open()
493 sqliteHashInit(&db->aDb[i].trigHash, SQLITE_HASH_STRING, 0); in sqlite_open()
494 sqliteHashInit(&db->aDb[i].aFKey, SQLITE_HASH_STRING, 1); in sqlite_open()
499 db->temp_store = 2; in sqlite_open()
501 rc = sqliteBtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt); in sqlite_open()
509 sqliteFree(db); in sqlite_open()
513 db->aDb[0].zName = "main"; in sqlite_open()
514 db->aDb[1].zName = "temp"; in sqlite_open()
517 sqliteRegisterBuiltinFunctions(db); in sqlite_open()
518 rc = sqliteInit(db, pzErrMsg); in sqlite_open()
519 db->magic = SQLITE_MAGIC_OPEN; in sqlite_open()
521 sqlite_close(db); in sqlite_open()
524 sqlite_close(db); in sqlite_open()
533 return db; in sqlite_open()
544 int sqlite_last_insert_rowid(sqlite *db){ in sqlite_last_insert_rowid() argument
545 return db->lastRowid; in sqlite_last_insert_rowid()
551 int sqlite_changes(sqlite *db){ in sqlite_changes() argument
552 return db->nChange; in sqlite_changes()
561 int sqlite_last_statement_changes(sqlite *db){ in sqlite_last_statement_changes() argument
562 return db->lsChange; in sqlite_last_statement_changes()
568 void sqlite_close(sqlite *db){ in sqlite_close() argument
571 db->want_to_close = 1; in sqlite_close()
572 if( sqliteSafetyCheck(db) || sqliteSafetyOn(db) ){ in sqlite_close()
576 db->magic = SQLITE_MAGIC_CLOSED; in sqlite_close()
577 for(j=0; j<db->nDb; j++){ in sqlite_close()
578 struct Db *pDb = &db->aDb[j]; in sqlite_close()
584 sqliteResetInternalSchema(db, 0); in sqlite_close()
585 assert( db->nDb<=2 ); in sqlite_close()
586 assert( db->aDb==db->aDbStatic ); in sqlite_close()
587 for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){ in sqlite_close()
594 sqliteHashClear(&db->aFunc); in sqlite_close()
595 sqliteFree(db); in sqlite_close()
601 void sqliteRollbackAll(sqlite *db){ in sqliteRollbackAll() argument
603 for(i=0; i<db->nDb; i++){ in sqliteRollbackAll()
604 if( db->aDb[i].pBt ){ in sqliteRollbackAll()
605 sqliteBtreeRollback(db->aDb[i].pBt); in sqliteRollbackAll()
606 db->aDb[i].inTrans = 0; in sqliteRollbackAll()
609 sqliteResetInternalSchema(db, 0); in sqliteRollbackAll()
624 sqlite *db, /* The database on which the SQL executes */ in sqlite_exec() argument
640 rc = sqlite_compile(db, zSql, &zLeftover, &pVm, pzErrMsg); in sqlite_exec()
649 db->nChange += nChange; in sqlite_exec()
663 && (db->flags & SQLITE_NullCallback)!=0 && xCallback!=0 ){ in sqlite_exec()
672 if( db->pVdbe==0 ){ in sqlite_exec()
673 nChange = db->nChange; in sqlite_exec()
692 sqlite *db, /* The database on which the SQL executes */ in sqlite_compile() argument
701 if( sqliteSafetyOn(db) ) goto exec_misuse; in sqlite_compile()
702 if( !db->init.busy ){ in sqlite_compile()
703 if( (db->flags & SQLITE_Initialized)==0 ){ in sqlite_compile()
705 while( (rc = sqliteInit(db, pzErrMsg))==SQLITE_BUSY in sqlite_compile()
706 && db->xBusyCallback in sqlite_compile()
707 && db->xBusyCallback(db->pBusyArg, "", cnt++)!=0 ){} in sqlite_compile()
710 sqliteSafetyOff(db); in sqlite_compile()
718 if( db->file_format<3 ){ in sqlite_compile()
719 sqliteSafetyOff(db); in sqlite_compile()
724 assert( (db->flags & SQLITE_Initialized)!=0 || db->init.busy ); in sqlite_compile()
725 if( db->pVdbe==0 ){ db->nChange = 0; } in sqlite_compile()
727 sParse.db = db; in sqlite_compile()
729 if( db->xTrace && !db->init.busy ){ in sqlite_compile()
739 db->xTrace(db->pTraceArg, tmpSql); in sqlite_compile()
746 db->xTrace(db->pTraceArg, zSql); in sqlite_compile()
749 db->xTrace(db->pTraceArg, zSql); in sqlite_compile()
755 sqliteRollbackAll(db); in sqlite_compile()
756 sqliteResetInternalSchema(db, 0); in sqlite_compile()
757 db->flags &= ~SQLITE_InTrans; in sqlite_compile()
765 sqliteResetInternalSchema(db, 0); in sqlite_compile()
770 if( sqliteSafetyOff(db) ) goto exec_misuse; in sqlite_compile()
907 sqlite *db, in sqlite_busy_handler() argument
911 db->xBusyCallback = xBusy; in sqlite_busy_handler()
912 db->pBusyArg = pArg; in sqlite_busy_handler()
922 sqlite *db, in sqlite_progress_handler() argument
928 db->xProgress = xProgress; in sqlite_progress_handler()
929 db->nProgressOps = nOps; in sqlite_progress_handler()
930 db->pProgressArg = pArg; in sqlite_progress_handler()
932 db->xProgress = 0; in sqlite_progress_handler()
933 db->nProgressOps = 0; in sqlite_progress_handler()
934 db->pProgressArg = 0; in sqlite_progress_handler()
944 void sqlite_busy_timeout(sqlite *db, int ms){ in sqlite_busy_timeout() argument
946 sqlite_busy_handler(db, sqliteDefaultBusyCallback, (void*)(long)ms); in sqlite_busy_timeout()
948 sqlite_busy_handler(db, 0, 0); in sqlite_busy_timeout()
955 void sqlite_interrupt(sqlite *db){ in sqlite_interrupt() argument
956 db->flags |= SQLITE_Interrupt; in sqlite_interrupt()
994 sqlite *db, /* Add the function to this database connection */ in sqlite_create_function() argument
1002 if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1; in sqlite_create_function()
1006 p = sqliteFindFunction(db, zName, nName, nArg, 1); in sqlite_create_function()
1015 sqlite *db, /* Add the function to this database connection */ in sqlite_create_aggregate() argument
1024 if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1; in sqlite_create_aggregate()
1028 p = sqliteFindFunction(db, zName, nName, nArg, 1); in sqlite_create_aggregate()
1042 int sqlite_function_type(sqlite *db, const char *zName, int dataType){ in sqlite_function_type() argument
1043 FuncDef *p = (FuncDef*)sqliteHashFind(&db->aFunc, zName, strlen(zName)); in sqlite_function_type()
1059 void *sqlite_trace(sqlite *db, void (*xTrace)(void*,const char*), void *pArg){ in sqlite_trace() argument
1060 void *pOld = db->pTraceArg; in sqlite_trace()
1061 db->xTrace = xTrace; in sqlite_trace()
1062 db->pTraceArg = pArg; in sqlite_trace()
1073 sqlite *db, /* Attach the hook to this database */ in sqlite_commit_hook() argument
1077 void *pOld = db->pCommitArg; in sqlite_commit_hook()
1078 db->xCommitCallback = xCallback; in sqlite_commit_hook()
1079 db->pCommitArg = pArg; in sqlite_commit_hook()
1110 const sqlite *db, /* Main database when opening aux otherwise 0 */ in sqliteBtreeFactory() argument
1125 int location = db->temp_store==0 ? TEMP_STORE : db->temp_store; in sqliteBtreeFactory()