2000-05-29 18:26:00 +04:00
|
|
|
/*
|
2001-09-16 04:13:26 +04:00
|
|
|
** 2001 September 15
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** The author disclaims copyright to this source code. In place of
|
|
|
|
** a legal notice, here is a blessing:
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** May you do good and not evil.
|
|
|
|
** May you find forgiveness for yourself and forgive others.
|
|
|
|
** May you share freely, never taking more than you give.
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
|
|
|
*************************************************************************
|
|
|
|
** Main file for the SQLite library. The routines in this file
|
|
|
|
** implement the programmer interface to the library. Routines in
|
|
|
|
** other files are for internal use by SQLite and should not be
|
|
|
|
** accessed by users of the library.
|
|
|
|
**
|
2004-02-15 02:05:52 +03:00
|
|
|
** $Id: main.c,v 1.154 2004/02/14 23:05:53 drh Exp $
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
|
|
|
#include "sqliteInt.h"
|
2001-09-19 17:22:39 +04:00
|
|
|
#include "os.h"
|
2002-05-15 18:17:44 +04:00
|
|
|
#include <ctype.h>
|
2000-05-29 18:26:00 +04:00
|
|
|
|
2002-07-19 21:46:38 +04:00
|
|
|
/*
|
|
|
|
** A pointer to this structure is used to communicate information
|
|
|
|
** from sqliteInit into the sqliteInitCallback.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
sqlite *db; /* The database being initialized */
|
|
|
|
char **pzErrMsg; /* Error message stored here */
|
|
|
|
} InitData;
|
|
|
|
|
2003-05-17 21:35:10 +04:00
|
|
|
/*
|
|
|
|
** Fill the InitData structure with an error message that indicates
|
|
|
|
** that the database is corrupt.
|
|
|
|
*/
|
2004-02-15 02:05:52 +03:00
|
|
|
static void corruptSchema(InitData *pData, const char *zExtra){
|
|
|
|
sqliteSetString(pData->pzErrMsg, "malformed database schema",
|
|
|
|
zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
|
2003-05-17 21:35:10 +04:00
|
|
|
}
|
2002-07-19 21:46:38 +04:00
|
|
|
|
2000-05-29 18:26:00 +04:00
|
|
|
/*
|
|
|
|
** This is the callback routine for the code that initializes the
|
2001-10-06 20:33:02 +04:00
|
|
|
** database. See sqliteInit() below for additional information.
|
|
|
|
**
|
|
|
|
** Each callback contains the following information:
|
2001-09-13 20:18:53 +04:00
|
|
|
**
|
2001-12-21 17:30:42 +03:00
|
|
|
** argv[0] = "file-format" or "schema-cookie" or "table" or "index"
|
2001-09-18 00:25:58 +04:00
|
|
|
** argv[1] = table or index name or meta statement type.
|
|
|
|
** argv[2] = root page number for table or index. NULL for meta.
|
2003-01-19 06:59:45 +03:00
|
|
|
** argv[3] = SQL text for a CREATE TABLE or CREATE INDEX statement.
|
2003-03-31 04:30:47 +04:00
|
|
|
** argv[4] = "1" for temporary files, "0" for main database, "2" or more
|
|
|
|
** for auxiliary database files.
|
2000-08-02 17:47:41 +04:00
|
|
|
**
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
2002-07-19 21:46:38 +04:00
|
|
|
static
|
|
|
|
int sqliteInitCallback(void *pInit, int argc, char **argv, char **azColName){
|
|
|
|
InitData *pData = (InitData*)pInit;
|
2001-09-13 20:18:53 +04:00
|
|
|
int nErr = 0;
|
2000-05-29 18:26:00 +04:00
|
|
|
|
2002-06-25 05:09:11 +04:00
|
|
|
assert( argc==5 );
|
2003-07-27 21:26:22 +04:00
|
|
|
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
2003-05-17 21:35:10 +04:00
|
|
|
if( argv[0]==0 ){
|
2004-02-15 02:05:52 +03:00
|
|
|
corruptSchema(pData, 0);
|
2003-05-17 21:35:10 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2001-09-13 20:18:53 +04:00
|
|
|
switch( argv[0][0] ){
|
2002-02-21 15:01:27 +03:00
|
|
|
case 'v':
|
2001-09-13 20:18:53 +04:00
|
|
|
case 'i':
|
2002-02-21 15:01:27 +03:00
|
|
|
case 't': { /* CREATE TABLE, CREATE INDEX, or CREATE VIEW statements */
|
2004-02-15 02:05:52 +03:00
|
|
|
sqlite *db = pData->db;
|
2003-05-17 21:35:10 +04:00
|
|
|
if( argv[2]==0 || argv[4]==0 ){
|
2004-02-15 02:05:52 +03:00
|
|
|
corruptSchema(pData, 0);
|
2003-05-17 21:35:10 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2001-09-27 19:11:53 +04:00
|
|
|
if( argv[3] && argv[3][0] ){
|
2002-02-21 15:01:27 +03:00
|
|
|
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
|
2004-02-15 02:05:52 +03:00
|
|
|
** But because db->init.busy is set to 1, no VDBE code is generated
|
2001-10-06 20:33:02 +04:00
|
|
|
** or executed. All the parser does is build the internal data
|
2002-02-21 15:01:27 +03:00
|
|
|
** structures that describe the table, index, or view.
|
2001-10-06 20:33:02 +04:00
|
|
|
*/
|
2004-02-15 02:05:52 +03:00
|
|
|
char *zErr;
|
|
|
|
assert( db->init.busy );
|
|
|
|
db->init.iDb = atoi(argv[4]);
|
|
|
|
assert( db->init.iDb>=0 && db->init.iDb<db->nDb );
|
|
|
|
db->init.newTnum = atoi(argv[2]);
|
|
|
|
if( sqlite_exec(db, argv[3], 0, 0, &zErr) ){
|
|
|
|
corruptSchema(pData, zErr);
|
|
|
|
sqlite_freemem(zErr);
|
|
|
|
}
|
|
|
|
db->init.iDb = 0;
|
2001-09-27 19:11:53 +04:00
|
|
|
}else{
|
2001-10-06 20:33:02 +04:00
|
|
|
/* If the SQL column is blank it means this is an index that
|
|
|
|
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
|
2002-01-06 20:07:40 +03:00
|
|
|
** constraint for a CREATE TABLE. The index should have already
|
2001-10-06 20:33:02 +04:00
|
|
|
** been created when we processed the CREATE TABLE. All we have
|
2002-01-06 20:07:40 +03:00
|
|
|
** to do here is record the root page number for that index.
|
2001-10-06 20:33:02 +04:00
|
|
|
*/
|
2003-03-27 15:51:24 +03:00
|
|
|
int iDb;
|
|
|
|
Index *pIndex;
|
|
|
|
|
|
|
|
iDb = atoi(argv[4]);
|
2004-02-15 02:05:52 +03:00
|
|
|
assert( iDb>=0 && iDb<db->nDb );
|
|
|
|
pIndex = sqliteFindIndex(db, argv[1], db->aDb[iDb].zName);
|
2001-09-27 19:11:53 +04:00
|
|
|
if( pIndex==0 || pIndex->tnum!=0 ){
|
2002-01-10 17:31:48 +03:00
|
|
|
/* This can occur if there exists an index on a TEMP table which
|
|
|
|
** has the same name as another index on a permanent index. Since
|
|
|
|
** the permanent table is hidden by the TEMP table, we can also
|
|
|
|
** safely ignore the index on the permanent table.
|
|
|
|
*/
|
|
|
|
/* Do Nothing */;
|
2001-09-27 19:11:53 +04:00
|
|
|
}else{
|
|
|
|
pIndex->tnum = atoi(argv[2]);
|
|
|
|
}
|
|
|
|
}
|
2001-09-13 20:18:53 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
/* This can not happen! */
|
|
|
|
nErr = 1;
|
|
|
|
assert( nErr==0 );
|
2000-08-02 17:47:41 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
return nErr;
|
|
|
|
}
|
|
|
|
|
2002-07-18 04:34:09 +04:00
|
|
|
/*
|
|
|
|
** This is a callback procedure used to reconstruct a table. The
|
|
|
|
** name of the table to be reconstructed is passed in as argv[0].
|
|
|
|
**
|
|
|
|
** This routine is used to automatically upgrade a database from
|
|
|
|
** format version 1 or 2 to version 3. The correct operation of
|
|
|
|
** this routine relys on the fact that no indices are used when
|
|
|
|
** copying a table out to a temporary file.
|
2004-02-10 05:27:04 +03:00
|
|
|
**
|
|
|
|
** The change from version 2 to version 3 occurred between SQLite
|
|
|
|
** version 2.5.6 and 2.6.0 on 2002-July-18.
|
2002-07-18 04:34:09 +04:00
|
|
|
*/
|
2002-07-19 21:46:38 +04:00
|
|
|
static
|
|
|
|
int upgrade_3_callback(void *pInit, int argc, char **argv, char **NotUsed){
|
|
|
|
InitData *pData = (InitData*)pInit;
|
2002-07-18 04:34:09 +04:00
|
|
|
int rc;
|
2002-07-18 05:27:17 +04:00
|
|
|
Table *pTab;
|
|
|
|
Trigger *pTrig;
|
2002-07-19 22:52:40 +04:00
|
|
|
char *zErr = 0;
|
2002-07-18 04:34:09 +04:00
|
|
|
|
2003-03-27 15:51:24 +03:00
|
|
|
pTab = sqliteFindTable(pData->db, argv[0], 0);
|
2002-07-31 04:32:50 +04:00
|
|
|
assert( pTab!=0 );
|
|
|
|
assert( sqliteStrICmp(pTab->zName, argv[0])==0 );
|
2002-07-18 05:27:17 +04:00
|
|
|
if( pTab ){
|
|
|
|
pTrig = pTab->pTrigger;
|
|
|
|
pTab->pTrigger = 0; /* Disable all triggers before rebuilding the table */
|
|
|
|
}
|
2002-07-19 21:46:38 +04:00
|
|
|
rc = sqlite_exec_printf(pData->db,
|
2002-07-18 04:34:09 +04:00
|
|
|
"CREATE TEMP TABLE sqlite_x AS SELECT * FROM '%q'; "
|
|
|
|
"DELETE FROM '%q'; "
|
|
|
|
"INSERT INTO '%q' SELECT * FROM sqlite_x; "
|
|
|
|
"DROP TABLE sqlite_x;",
|
2002-07-19 21:46:38 +04:00
|
|
|
0, 0, &zErr, argv[0], argv[0], argv[0]);
|
|
|
|
if( zErr ){
|
2004-02-14 19:31:02 +03:00
|
|
|
if( *pData->pzErrMsg ) sqlite_freemem(*pData->pzErrMsg);
|
|
|
|
*pData->pzErrMsg = zErr;
|
2002-07-19 21:46:38 +04:00
|
|
|
}
|
2002-07-31 04:32:50 +04:00
|
|
|
|
|
|
|
/* If an error occurred in the SQL above, then the transaction will
|
|
|
|
** rollback which will delete the internal symbol tables. This will
|
|
|
|
** cause the structure that pTab points to be deleted. In case that
|
|
|
|
** happened, we need to refetch pTab.
|
|
|
|
*/
|
2003-03-27 15:51:24 +03:00
|
|
|
pTab = sqliteFindTable(pData->db, argv[0], 0);
|
2002-07-31 04:32:50 +04:00
|
|
|
if( pTab ){
|
|
|
|
assert( sqliteStrICmp(pTab->zName, argv[0])==0 );
|
|
|
|
pTab->pTrigger = pTrig; /* Re-enable triggers */
|
|
|
|
}
|
2002-07-18 04:34:09 +04:00
|
|
|
return rc!=SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-29 18:26:00 +04:00
|
|
|
/*
|
2000-06-02 05:17:37 +04:00
|
|
|
** Attempt to read the database schema and initialize internal
|
2003-03-31 04:30:47 +04:00
|
|
|
** data structures for a single database file. The index of the
|
|
|
|
** database file is given by iDb. iDb==0 is used for the main
|
|
|
|
** database. iDb==1 should never be used. iDb>=2 is used for
|
|
|
|
** auxiliary databases. Return one of the SQLITE_ error codes to
|
2000-06-02 05:17:37 +04:00
|
|
|
** indicate success or failure.
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
2003-03-31 04:30:47 +04:00
|
|
|
static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){
|
2000-06-02 05:17:37 +04:00
|
|
|
int rc;
|
2002-06-25 05:09:11 +04:00
|
|
|
BtCursor *curMain;
|
|
|
|
int size;
|
|
|
|
Table *pTab;
|
|
|
|
char *azArg[6];
|
2003-03-31 04:30:47 +04:00
|
|
|
char zDbNum[30];
|
2002-06-25 05:09:11 +04:00
|
|
|
int meta[SQLITE_N_BTREE_META];
|
2002-07-19 21:46:38 +04:00
|
|
|
InitData initData;
|
2000-06-02 05:17:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** The master database table has a structure like this
|
|
|
|
*/
|
2000-05-29 18:26:00 +04:00
|
|
|
static char master_schema[] =
|
2002-06-25 05:09:11 +04:00
|
|
|
"CREATE TABLE sqlite_master(\n"
|
|
|
|
" type text,\n"
|
|
|
|
" name text,\n"
|
|
|
|
" tbl_name text,\n"
|
|
|
|
" rootpage integer,\n"
|
|
|
|
" sql text\n"
|
|
|
|
")"
|
|
|
|
;
|
|
|
|
static char temp_master_schema[] =
|
|
|
|
"CREATE TEMP TABLE sqlite_temp_master(\n"
|
2000-05-29 18:26:00 +04:00
|
|
|
" type text,\n"
|
|
|
|
" name text,\n"
|
|
|
|
" tbl_name text,\n"
|
2001-09-27 19:11:53 +04:00
|
|
|
" rootpage integer,\n"
|
2000-05-29 18:26:00 +04:00
|
|
|
" sql text\n"
|
|
|
|
")"
|
|
|
|
;
|
|
|
|
|
2002-06-25 05:09:11 +04:00
|
|
|
/* The following SQL will read the schema from the master tables.
|
|
|
|
** The first version works with SQLite file formats 2 or greater.
|
|
|
|
** The second version is for format 1 files.
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2002-06-25 05:09:11 +04:00
|
|
|
** Beginning with file format 2, the rowid for new table entries
|
|
|
|
** (including entries in sqlite_master) is an increasing integer.
|
|
|
|
** So for file format 2 and later, we can play back sqlite_master
|
|
|
|
** and all the CREATE statements will appear in the right order.
|
|
|
|
** But with file format 1, table entries were random and so we
|
|
|
|
** have to make sure the CREATE TABLEs occur before their corresponding
|
|
|
|
** CREATE INDEXs. (We don't have to deal with CREATE VIEW or
|
|
|
|
** CREATE TRIGGER in file format 1 because those constructs did
|
|
|
|
** not exist then.)
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
2002-06-25 05:09:11 +04:00
|
|
|
static char init_script[] =
|
|
|
|
"SELECT type, name, rootpage, sql, 1 FROM sqlite_temp_master "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT type, name, rootpage, sql, 0 FROM sqlite_master";
|
|
|
|
static char older_init_script[] =
|
|
|
|
"SELECT type, name, rootpage, sql, 1 FROM sqlite_temp_master "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT type, name, rootpage, sql, 0 FROM sqlite_master "
|
|
|
|
"WHERE type='table' "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT type, name, rootpage, sql, 0 FROM sqlite_master "
|
|
|
|
"WHERE type='index'";
|
|
|
|
|
|
|
|
|
2003-03-31 04:30:47 +04:00
|
|
|
assert( iDb>=0 && iDb!=1 && iDb<db->nDb );
|
|
|
|
|
2002-06-25 05:09:11 +04:00
|
|
|
/* Construct the schema tables: sqlite_master and sqlite_temp_master
|
|
|
|
*/
|
2004-02-15 02:05:52 +03:00
|
|
|
sqliteSafetyOff(db);
|
2002-06-25 05:09:11 +04:00
|
|
|
azArg[0] = "table";
|
|
|
|
azArg[1] = MASTER_NAME;
|
|
|
|
azArg[2] = "2";
|
|
|
|
azArg[3] = master_schema;
|
2003-03-31 04:30:47 +04:00
|
|
|
sprintf(zDbNum, "%d", iDb);
|
|
|
|
azArg[4] = zDbNum;
|
2002-06-25 05:09:11 +04:00
|
|
|
azArg[5] = 0;
|
2002-07-19 21:46:38 +04:00
|
|
|
initData.db = db;
|
|
|
|
initData.pzErrMsg = pzErrMsg;
|
|
|
|
sqliteInitCallback(&initData, 5, azArg, 0);
|
2003-03-27 15:51:24 +03:00
|
|
|
pTab = sqliteFindTable(db, MASTER_NAME, "main");
|
2002-06-25 05:09:11 +04:00
|
|
|
if( pTab ){
|
|
|
|
pTab->readOnly = 1;
|
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
if( iDb==0 ){
|
|
|
|
azArg[1] = TEMP_MASTER_NAME;
|
|
|
|
azArg[3] = temp_master_schema;
|
|
|
|
azArg[4] = "1";
|
|
|
|
sqliteInitCallback(&initData, 5, azArg, 0);
|
|
|
|
pTab = sqliteFindTable(db, TEMP_MASTER_NAME, "temp");
|
|
|
|
if( pTab ){
|
|
|
|
pTab->readOnly = 1;
|
|
|
|
}
|
2002-06-25 05:09:11 +04:00
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
sqliteSafetyOn(db);
|
2002-02-21 15:01:27 +03:00
|
|
|
|
2002-06-25 05:09:11 +04:00
|
|
|
/* Create a cursor to hold the database open
|
|
|
|
*/
|
2003-03-31 04:30:47 +04:00
|
|
|
if( db->aDb[iDb].pBt==0 ) return SQLITE_OK;
|
|
|
|
rc = sqliteBtreeCursor(db->aDb[iDb].pBt, 2, 0, &curMain);
|
2002-07-30 22:43:40 +04:00
|
|
|
if( rc ){
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, sqlite_error_string(rc), (char*)0);
|
2002-07-30 22:43:40 +04:00
|
|
|
return rc;
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
|
2002-06-25 05:09:11 +04:00
|
|
|
/* Get the database meta information
|
2000-06-02 05:17:37 +04:00
|
|
|
*/
|
2003-03-31 04:30:47 +04:00
|
|
|
rc = sqliteBtreeGetMeta(db->aDb[iDb].pBt, meta);
|
2002-06-25 05:09:11 +04:00
|
|
|
if( rc ){
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, sqlite_error_string(rc), (char*)0);
|
2002-06-25 05:09:11 +04:00
|
|
|
sqliteBtreeCloseCursor(curMain);
|
|
|
|
return rc;
|
2000-06-08 03:51:50 +04:00
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
db->aDb[iDb].schema_cookie = meta[1];
|
|
|
|
if( iDb==0 ){
|
|
|
|
db->next_cookie = meta[1];
|
|
|
|
db->file_format = meta[2];
|
|
|
|
size = meta[3];
|
|
|
|
if( size==0 ){ size = MAX_PAGES; }
|
|
|
|
db->cache_size = size;
|
|
|
|
db->safety_level = meta[4];
|
|
|
|
if( db->safety_level==0 ) db->safety_level = 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** file_format==1 Version 2.1.0.
|
|
|
|
** file_format==2 Version 2.2.0. Add support for INTEGER PRIMARY KEY.
|
|
|
|
** file_format==3 Version 2.6.0. Fix empty-string index bug.
|
|
|
|
** file_format==4 Version 2.7.0. Add support for separate numeric and
|
|
|
|
** text datatypes.
|
|
|
|
*/
|
|
|
|
if( db->file_format==0 ){
|
|
|
|
/* This happens if the database was initially empty */
|
|
|
|
db->file_format = 4;
|
|
|
|
}else if( db->file_format>4 ){
|
|
|
|
sqliteBtreeCloseCursor(curMain);
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, "unsupported file format", (char*)0);
|
2003-03-31 04:30:47 +04:00
|
|
|
return SQLITE_ERROR;
|
|
|
|
}
|
2003-04-05 07:42:26 +04:00
|
|
|
}else if( db->file_format!=meta[2] || db->file_format<4 ){
|
|
|
|
assert( db->file_format>=4 );
|
|
|
|
if( meta[2]==0 ){
|
|
|
|
sqliteSetString(pzErrMsg, "cannot attach empty database: ",
|
2003-12-07 00:43:55 +03:00
|
|
|
db->aDb[iDb].zName, (char*)0);
|
2003-04-05 07:42:26 +04:00
|
|
|
}else{
|
|
|
|
sqliteSetString(pzErrMsg, "incompatible file format in auxiliary "
|
2003-12-07 00:43:55 +03:00
|
|
|
"database: ", db->aDb[iDb].zName, (char*)0);
|
2003-04-05 07:42:26 +04:00
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteBtreeClose(db->aDb[iDb].pBt);
|
|
|
|
db->aDb[iDb].pBt = 0;
|
|
|
|
return SQLITE_FORMAT;
|
2000-08-02 17:47:41 +04:00
|
|
|
}
|
2003-06-02 22:17:33 +04:00
|
|
|
sqliteBtreeSetCacheSize(db->aDb[iDb].pBt, db->cache_size);
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteBtreeSetSafetyLevel(db->aDb[iDb].pBt, meta[4]==0 ? 2 : meta[4]);
|
2002-01-06 20:07:40 +03:00
|
|
|
|
2002-06-25 05:09:11 +04:00
|
|
|
/* Read the schema information out of the schema tables
|
2002-01-06 20:07:40 +03:00
|
|
|
*/
|
2004-02-15 02:05:52 +03:00
|
|
|
assert( db->init.busy );
|
|
|
|
sqliteSafetyOff(db);
|
2003-03-31 04:30:47 +04:00
|
|
|
if( iDb==0 ){
|
2004-02-15 02:05:52 +03:00
|
|
|
rc = sqlite_exec(db,
|
2003-03-31 04:30:47 +04:00
|
|
|
db->file_format>=2 ? init_script : older_init_script,
|
2004-02-15 02:05:52 +03:00
|
|
|
sqliteInitCallback, &initData, 0);
|
2003-03-31 04:30:47 +04:00
|
|
|
}else{
|
|
|
|
char *zSql = 0;
|
|
|
|
sqliteSetString(&zSql,
|
|
|
|
"SELECT type, name, rootpage, sql, ", zDbNum, " FROM \"",
|
2003-12-07 00:43:55 +03:00
|
|
|
db->aDb[iDb].zName, "\".sqlite_master", (char*)0);
|
2004-02-15 02:05:52 +03:00
|
|
|
rc = sqlite_exec(db, zSql, sqliteInitCallback, &initData, 0);
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteFree(zSql);
|
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
sqliteSafetyOn(db);
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteBtreeCloseCursor(curMain);
|
2002-06-25 05:09:11 +04:00
|
|
|
if( sqlite_malloc_failed ){
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, "out of memory", (char*)0);
|
2004-02-15 02:05:52 +03:00
|
|
|
rc = SQLITE_NOMEM;
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteResetInternalSchema(db, 0);
|
2002-06-25 05:09:11 +04:00
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
if( rc==SQLITE_OK ){
|
2003-05-17 21:35:10 +04:00
|
|
|
DbSetProperty(db, iDb, DB_SchemaLoaded);
|
|
|
|
if( iDb==0 ){
|
|
|
|
DbSetProperty(db, 1, DB_SchemaLoaded);
|
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
}else{
|
|
|
|
sqliteResetInternalSchema(db, iDb);
|
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
return rc;
|
2003-03-31 04:30:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Initialize all database files - the main database file, the file
|
|
|
|
** used to store temporary tables, and any additional database files
|
|
|
|
** created using ATTACH statements. Return a success code. If an
|
|
|
|
** error occurs, write an error message into *pzErrMsg.
|
|
|
|
**
|
|
|
|
** After the database is initialized, the SQLITE_Initialized
|
|
|
|
** bit is set in the flags field of the sqlite structure. An
|
|
|
|
** attempt is made to initialize the database as soon as it
|
|
|
|
** is opened. If that fails (perhaps because another process
|
|
|
|
** has the sqlite_master table locked) than another attempt
|
|
|
|
** is made the first time the database is accessed.
|
|
|
|
*/
|
|
|
|
int sqliteInit(sqlite *db, char **pzErrMsg){
|
|
|
|
int i, rc;
|
|
|
|
|
2004-02-15 02:05:52 +03:00
|
|
|
if( db->init.busy ) return SQLITE_OK;
|
2003-03-31 04:30:47 +04:00
|
|
|
assert( (db->flags & SQLITE_Initialized)==0 );
|
|
|
|
rc = SQLITE_OK;
|
2004-02-15 02:05:52 +03:00
|
|
|
db->init.busy = 1;
|
2003-03-31 04:30:47 +04:00
|
|
|
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
2003-05-17 21:35:10 +04:00
|
|
|
if( DbHasProperty(db, i, DB_SchemaLoaded) ) continue;
|
|
|
|
assert( i!=1 ); /* Should have been initialized together with 0 */
|
2003-03-31 04:30:47 +04:00
|
|
|
rc = sqliteInitOne(db, i, pzErrMsg);
|
2004-02-12 18:31:21 +03:00
|
|
|
if( rc ){
|
|
|
|
sqliteResetInternalSchema(db, i);
|
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
db->init.busy = 0;
|
2003-03-31 04:30:47 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
2000-06-02 05:17:37 +04:00
|
|
|
db->flags |= SQLITE_Initialized;
|
2001-09-13 17:46:56 +04:00
|
|
|
sqliteCommitInternalChanges(db);
|
2004-02-10 05:27:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the database is in formats 1 or 2, then upgrade it to
|
|
|
|
** version 3. This will reconstruct all indices. If the
|
|
|
|
** upgrade fails for any reason (ex: out of disk space, database
|
|
|
|
** is read only, interrupt received, etc.) then fail the init.
|
|
|
|
*/
|
|
|
|
if( rc==SQLITE_OK && db->file_format<3 ){
|
|
|
|
char *zErr = 0;
|
|
|
|
InitData initData;
|
|
|
|
int meta[SQLITE_N_BTREE_META];
|
|
|
|
|
|
|
|
db->magic = SQLITE_MAGIC_OPEN;
|
|
|
|
initData.db = db;
|
|
|
|
initData.pzErrMsg = &zErr;
|
|
|
|
db->file_format = 3;
|
|
|
|
rc = sqlite_exec(db,
|
|
|
|
"BEGIN; SELECT name FROM sqlite_master WHERE type='table';",
|
|
|
|
upgrade_3_callback,
|
|
|
|
&initData,
|
|
|
|
&zErr);
|
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
sqliteBtreeGetMeta(db->aDb[0].pBt, meta);
|
|
|
|
meta[2] = 4;
|
|
|
|
sqliteBtreeUpdateMeta(db->aDb[0].pBt, meta);
|
|
|
|
sqlite_exec(db, "COMMIT", 0, 0, 0);
|
|
|
|
}
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
sqliteSetString(pzErrMsg,
|
|
|
|
"unable to upgrade database to the version 2.6 format",
|
|
|
|
zErr ? ": " : 0, zErr, (char*)0);
|
|
|
|
}
|
|
|
|
sqlite_freemem(zErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( rc!=SQLITE_OK ){
|
2002-06-25 05:09:11 +04:00
|
|
|
db->flags &= ~SQLITE_Initialized;
|
2000-06-02 05:17:37 +04:00
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
return rc;
|
2000-06-02 05:17:37 +04:00
|
|
|
}
|
|
|
|
|
2000-08-22 17:40:18 +04:00
|
|
|
/*
|
|
|
|
** The version of the library
|
|
|
|
*/
|
2002-07-19 23:03:41 +04:00
|
|
|
const char rcsid[] = "@(#) \044Id: SQLite version " SQLITE_VERSION " $";
|
2000-08-22 17:40:51 +04:00
|
|
|
const char sqlite_version[] = SQLITE_VERSION;
|
2000-08-22 17:40:18 +04:00
|
|
|
|
2001-04-05 19:57:13 +04:00
|
|
|
/*
|
|
|
|
** Does the library expect data to be encoded as UTF-8 or iso8859? The
|
|
|
|
** following global constant always lets us know.
|
|
|
|
*/
|
|
|
|
#ifdef SQLITE_UTF8
|
2001-04-06 20:13:42 +04:00
|
|
|
const char sqlite_encoding[] = "UTF-8";
|
2001-04-05 19:57:13 +04:00
|
|
|
#else
|
2001-04-06 20:13:42 +04:00
|
|
|
const char sqlite_encoding[] = "iso8859";
|
2001-04-05 19:57:13 +04:00
|
|
|
#endif
|
|
|
|
|
2000-06-02 05:17:37 +04:00
|
|
|
/*
|
|
|
|
** Open a new SQLite database. Construct an "sqlite" structure to define
|
|
|
|
** the state of this database and return a pointer to that structure.
|
|
|
|
**
|
|
|
|
** An attempt is made to initialize the in-memory data structures that
|
|
|
|
** hold the database schema. But if this fails (because the schema file
|
|
|
|
** is locked) then that step is deferred until the first call to
|
|
|
|
** sqlite_exec().
|
|
|
|
*/
|
|
|
|
sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
|
|
|
|
sqlite *db;
|
2003-03-27 15:51:24 +03:00
|
|
|
int rc, i;
|
2000-06-02 05:17:37 +04:00
|
|
|
|
|
|
|
/* Allocate the sqlite data structure */
|
2000-05-29 18:26:00 +04:00
|
|
|
db = sqliteMalloc( sizeof(sqlite) );
|
|
|
|
if( pzErrMsg ) *pzErrMsg = 0;
|
2001-04-11 18:28:42 +04:00
|
|
|
if( db==0 ) goto no_mem_on_open;
|
2002-01-31 18:54:21 +03:00
|
|
|
db->onError = OE_Default;
|
2002-02-20 01:42:05 +03:00
|
|
|
db->priorNewRowid = 0;
|
2002-05-10 09:44:55 +04:00
|
|
|
db->magic = SQLITE_MAGIC_BUSY;
|
2003-03-19 06:14:00 +03:00
|
|
|
db->nDb = 2;
|
|
|
|
db->aDb = db->aDbStatic;
|
2003-03-27 15:51:24 +03:00
|
|
|
sqliteHashInit(&db->aFunc, SQLITE_HASH_STRING, 1);
|
|
|
|
for(i=0; i<db->nDb; i++){
|
|
|
|
sqliteHashInit(&db->aDb[i].tblHash, SQLITE_HASH_STRING, 0);
|
|
|
|
sqliteHashInit(&db->aDb[i].idxHash, SQLITE_HASH_STRING, 0);
|
|
|
|
sqliteHashInit(&db->aDb[i].trigHash, SQLITE_HASH_STRING, 0);
|
|
|
|
sqliteHashInit(&db->aDb[i].aFKey, SQLITE_HASH_STRING, 1);
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
|
|
|
|
/* Open the backend database driver */
|
2003-06-04 19:48:33 +04:00
|
|
|
if( zFilename[0]==':' && strcmp(zFilename,":memory:")==0 ){
|
|
|
|
db->temp_store = 2;
|
|
|
|
}
|
2003-04-16 05:28:16 +04:00
|
|
|
rc = sqliteBtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
|
2001-09-13 17:46:56 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
switch( rc ){
|
|
|
|
default: {
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, "unable to open database: ",
|
|
|
|
zFilename, (char*)0);
|
2001-09-13 17:46:56 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
sqliteFree(db);
|
2001-09-14 01:53:09 +04:00
|
|
|
sqliteStrRealloc(pzErrMsg);
|
2001-09-13 18:46:09 +04:00
|
|
|
return 0;
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
2003-03-19 06:14:00 +03:00
|
|
|
db->aDb[0].zName = "main";
|
2003-03-20 04:16:58 +03:00
|
|
|
db->aDb[1].zName = "temp";
|
2000-05-29 18:26:00 +04:00
|
|
|
|
2000-06-02 05:17:37 +04:00
|
|
|
/* Attempt to read the schema */
|
2002-09-06 03:21:37 +04:00
|
|
|
sqliteRegisterBuiltinFunctions(db);
|
2000-06-02 05:17:37 +04:00
|
|
|
rc = sqliteInit(db, pzErrMsg);
|
2002-06-15 00:54:14 +04:00
|
|
|
db->magic = SQLITE_MAGIC_OPEN;
|
2001-04-11 18:28:42 +04:00
|
|
|
if( sqlite_malloc_failed ){
|
2001-10-22 06:58:08 +04:00
|
|
|
sqlite_close(db);
|
2001-04-11 18:28:42 +04:00
|
|
|
goto no_mem_on_open;
|
|
|
|
}else if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
2000-06-02 05:17:37 +04:00
|
|
|
sqlite_close(db);
|
2001-09-14 01:53:09 +04:00
|
|
|
sqliteStrRealloc(pzErrMsg);
|
2000-06-02 05:17:37 +04:00
|
|
|
return 0;
|
2002-01-06 20:07:40 +03:00
|
|
|
}else if( pzErrMsg ){
|
2001-04-11 18:28:42 +04:00
|
|
|
sqliteFree(*pzErrMsg);
|
2000-06-02 17:27:59 +04:00
|
|
|
*pzErrMsg = 0;
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
2002-07-18 04:34:09 +04:00
|
|
|
|
|
|
|
/* Return a pointer to the newly opened database structure */
|
2000-05-29 18:26:00 +04:00
|
|
|
return db;
|
2001-04-11 18:28:42 +04:00
|
|
|
|
|
|
|
no_mem_on_open:
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, "out of memory", (char*)0);
|
2001-04-11 18:28:42 +04:00
|
|
|
sqliteStrRealloc(pzErrMsg);
|
|
|
|
return 0;
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
|
|
|
|
2002-01-17 00:00:27 +03:00
|
|
|
/*
|
|
|
|
** Return the ROWID of the most recent insert
|
|
|
|
*/
|
|
|
|
int sqlite_last_insert_rowid(sqlite *db){
|
|
|
|
return db->lastRowid;
|
|
|
|
}
|
|
|
|
|
2002-04-12 14:08:59 +04:00
|
|
|
/*
|
|
|
|
** Return the number of changes in the most recent call to sqlite_exec().
|
|
|
|
*/
|
|
|
|
int sqlite_changes(sqlite *db){
|
|
|
|
return db->nChange;
|
|
|
|
}
|
|
|
|
|
2001-09-15 04:57:28 +04:00
|
|
|
/*
|
|
|
|
** Close an existing SQLite database
|
|
|
|
*/
|
|
|
|
void sqlite_close(sqlite *db){
|
2002-02-24 02:45:45 +03:00
|
|
|
HashElem *i;
|
2003-03-19 06:14:00 +03:00
|
|
|
int j;
|
2003-02-17 01:21:32 +03:00
|
|
|
db->want_to_close = 1;
|
|
|
|
if( sqliteSafetyCheck(db) || sqliteSafetyOn(db) ){
|
|
|
|
/* printf("DID NOT CLOSE\n"); fflush(stdout); */
|
|
|
|
return;
|
|
|
|
}
|
2002-05-10 09:44:55 +04:00
|
|
|
db->magic = SQLITE_MAGIC_CLOSED;
|
2003-03-19 06:14:00 +03:00
|
|
|
for(j=0; j<db->nDb; j++){
|
2004-02-12 21:46:38 +03:00
|
|
|
struct Db *pDb = &db->aDb[j];
|
|
|
|
if( pDb->pBt ){
|
|
|
|
sqliteBtreeClose(pDb->pBt);
|
|
|
|
pDb->pBt = 0;
|
2003-03-20 04:16:58 +03:00
|
|
|
}
|
2001-10-08 17:22:32 +04:00
|
|
|
}
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteResetInternalSchema(db, 0);
|
|
|
|
assert( db->nDb<=2 );
|
|
|
|
assert( db->aDb==db->aDbStatic );
|
2002-02-28 03:41:10 +03:00
|
|
|
for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){
|
|
|
|
FuncDef *pFunc, *pNext;
|
|
|
|
for(pFunc = (FuncDef*)sqliteHashData(i); pFunc; pFunc=pNext){
|
2002-02-24 02:45:45 +03:00
|
|
|
pNext = pFunc->pNext;
|
|
|
|
sqliteFree(pFunc);
|
|
|
|
}
|
|
|
|
}
|
2002-02-28 03:41:10 +03:00
|
|
|
sqliteHashClear(&db->aFunc);
|
2000-05-29 18:26:00 +04:00
|
|
|
sqliteFree(db);
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:14:00 +03:00
|
|
|
/*
|
|
|
|
** Rollback all database files.
|
|
|
|
*/
|
|
|
|
void sqliteRollbackAll(sqlite *db){
|
|
|
|
int i;
|
|
|
|
for(i=0; i<db->nDb; i++){
|
|
|
|
if( db->aDb[i].pBt ){
|
|
|
|
sqliteBtreeRollback(db->aDb[i].pBt);
|
|
|
|
db->aDb[i].inTrans = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-02-12 18:31:21 +03:00
|
|
|
sqliteResetInternalSchema(db, 0);
|
|
|
|
/* sqliteRollbackInternalChanges(db); */
|
2003-03-19 06:14:00 +03:00
|
|
|
}
|
|
|
|
|
2000-05-29 18:26:00 +04:00
|
|
|
/*
|
2004-02-14 19:31:02 +03:00
|
|
|
** Execute SQL code. Return one of the SQLITE_ success/failure
|
|
|
|
** codes. Also write an error message into memory obtained from
|
|
|
|
** malloc() and make *pzErrMsg point to that message.
|
|
|
|
**
|
|
|
|
** If the SQL is a query, then for each row in the query result
|
|
|
|
** the xCallback() function is called. pArg becomes the first
|
|
|
|
** argument to xCallback(). If xCallback=NULL then no callback
|
|
|
|
** is invoked, even for queries.
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
2004-02-14 19:31:02 +03:00
|
|
|
int sqlite_exec(
|
2000-05-29 18:26:00 +04:00
|
|
|
sqlite *db, /* The database on which the SQL executes */
|
2001-11-04 02:57:09 +03:00
|
|
|
const char *zSql, /* The SQL to be executed */
|
2000-05-29 18:26:00 +04:00
|
|
|
sqlite_callback xCallback, /* Invoke this callback routine */
|
|
|
|
void *pArg, /* First argument to xCallback() */
|
2004-02-14 19:31:02 +03:00
|
|
|
char **pzErrMsg /* Write error messages here */
|
|
|
|
){
|
|
|
|
int rc = SQLITE_OK;
|
|
|
|
const char *zLeftover;
|
|
|
|
sqlite_vm *pVm;
|
|
|
|
int nRetry = 0;
|
|
|
|
int nChange = 0;
|
|
|
|
|
|
|
|
if( zSql==0 ) return SQLITE_OK;
|
|
|
|
while( rc==SQLITE_OK && zSql[0] ){
|
|
|
|
pVm = 0;
|
|
|
|
rc = sqlite_compile(db, zSql, &zLeftover, &pVm, pzErrMsg);
|
|
|
|
if( rc!=SQLITE_OK ){
|
2004-02-14 20:35:07 +03:00
|
|
|
assert( pVm==0 || sqlite_malloc_failed );
|
2004-02-14 19:31:02 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
if( pVm==0 ){
|
|
|
|
/* This happens if the zSql input contained only whitespace */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
db->nChange += nChange;
|
|
|
|
while(1){
|
|
|
|
int nArg;
|
|
|
|
char **azArg, **azCol;
|
|
|
|
rc = sqlite_step(pVm, &nArg, (const char***)&azArg,(const char***)&azCol);
|
|
|
|
if( rc==SQLITE_ROW ){
|
|
|
|
if( xCallback(pArg, nArg, azArg, azCol) ){
|
|
|
|
sqlite_finalize(pVm, 0);
|
|
|
|
return SQLITE_ABORT;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
rc = sqlite_finalize(pVm, pzErrMsg);
|
|
|
|
if( rc==SQLITE_SCHEMA && nRetry<2 ){
|
|
|
|
nRetry++;
|
|
|
|
rc = SQLITE_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( db->pVdbe==0 ){
|
|
|
|
nChange = db->nChange;
|
|
|
|
}
|
|
|
|
nRetry = 0;
|
|
|
|
zSql = zLeftover;
|
|
|
|
while( isspace(zSql[0]) ) zSql++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Compile a single statement of SQL into a virtual machine. Return one
|
|
|
|
** of the SQLITE_ success/failure codes. Also write an error message into
|
|
|
|
** memory obtained from malloc() and make *pzErrMsg point to that message.
|
|
|
|
*/
|
|
|
|
int sqlite_compile(
|
|
|
|
sqlite *db, /* The database on which the SQL executes */
|
|
|
|
const char *zSql, /* The SQL to be executed */
|
2003-01-29 02:13:10 +03:00
|
|
|
const char **pzTail, /* OUT: Next statement after the first */
|
|
|
|
sqlite_vm **ppVm, /* OUT: The virtual machine */
|
|
|
|
char **pzErrMsg /* OUT: Write error messages here */
|
2000-05-29 18:26:00 +04:00
|
|
|
){
|
|
|
|
Parse sParse;
|
|
|
|
|
2003-01-18 20:04:08 +03:00
|
|
|
if( pzErrMsg ) *pzErrMsg = 0;
|
|
|
|
if( sqliteSafetyOn(db) ) goto exec_misuse;
|
2004-02-15 02:05:52 +03:00
|
|
|
if( !db->init.busy ){
|
|
|
|
if( (db->flags & SQLITE_Initialized)==0 ){
|
|
|
|
int rc, cnt = 1;
|
|
|
|
while( (rc = sqliteInit(db, pzErrMsg))==SQLITE_BUSY
|
|
|
|
&& db->xBusyCallback
|
|
|
|
&& db->xBusyCallback(db->pBusyArg, "", cnt++)!=0 ){}
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
sqliteStrRealloc(pzErrMsg);
|
|
|
|
sqliteSafetyOff(db);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
if( pzErrMsg ){
|
|
|
|
sqliteFree(*pzErrMsg);
|
|
|
|
*pzErrMsg = 0;
|
|
|
|
}
|
2001-04-11 18:28:42 +04:00
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
if( db->file_format<3 ){
|
|
|
|
sqliteSafetyOff(db);
|
|
|
|
sqliteSetString(pzErrMsg, "obsolete database file format", (char*)0);
|
|
|
|
return SQLITE_ERROR;
|
2002-11-01 04:55:36 +03:00
|
|
|
}
|
2000-06-02 05:17:37 +04:00
|
|
|
}
|
2004-02-15 02:05:52 +03:00
|
|
|
assert( (db->flags & SQLITE_Initialized)!=0 || db->init.busy );
|
2003-01-29 17:06:07 +03:00
|
|
|
if( db->pVdbe==0 ){ db->nChange = 0; }
|
2000-05-29 18:26:00 +04:00
|
|
|
memset(&sParse, 0, sizeof(sParse));
|
|
|
|
sParse.db = db;
|
2004-02-14 19:31:02 +03:00
|
|
|
sParse.useCallback = 0;
|
2003-01-29 02:13:10 +03:00
|
|
|
if( db->xTrace ) db->xTrace(db->pTraceArg, zSql);
|
2000-10-17 02:06:40 +04:00
|
|
|
sqliteRunParser(&sParse, zSql, pzErrMsg);
|
2001-04-11 18:28:42 +04:00
|
|
|
if( sqlite_malloc_failed ){
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, "out of memory", (char*)0);
|
2001-04-11 18:28:42 +04:00
|
|
|
sParse.rc = SQLITE_NOMEM;
|
2003-03-19 06:14:00 +03:00
|
|
|
sqliteRollbackAll(db);
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteResetInternalSchema(db, 0);
|
2003-03-19 06:14:00 +03:00
|
|
|
db->flags &= ~SQLITE_InTrans;
|
2001-04-11 18:28:42 +04:00
|
|
|
}
|
2003-01-29 17:06:07 +03:00
|
|
|
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
|
2002-09-03 23:43:23 +04:00
|
|
|
if( sParse.rc!=SQLITE_OK && pzErrMsg && *pzErrMsg==0 ){
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, sqlite_error_string(sParse.rc), (char*)0);
|
2002-09-03 23:43:23 +04:00
|
|
|
}
|
2001-04-11 18:28:42 +04:00
|
|
|
sqliteStrRealloc(pzErrMsg);
|
2001-09-15 04:57:28 +04:00
|
|
|
if( sParse.rc==SQLITE_SCHEMA ){
|
2003-03-31 04:30:47 +04:00
|
|
|
sqliteResetInternalSchema(db, 0);
|
2001-09-15 04:57:28 +04:00
|
|
|
}
|
2004-02-14 19:31:02 +03:00
|
|
|
assert( ppVm );
|
|
|
|
*ppVm = (sqlite_vm*)sParse.pVdbe;
|
|
|
|
if( pzTail ) *pzTail = sParse.zTail;
|
2002-05-10 17:14:07 +04:00
|
|
|
if( sqliteSafetyOff(db) ) goto exec_misuse;
|
2000-10-17 02:06:40 +04:00
|
|
|
return sParse.rc;
|
2000-07-28 18:32:48 +04:00
|
|
|
|
2002-05-10 17:14:07 +04:00
|
|
|
exec_misuse:
|
|
|
|
if( pzErrMsg ){
|
|
|
|
*pzErrMsg = 0;
|
2003-12-07 00:43:55 +03:00
|
|
|
sqliteSetString(pzErrMsg, sqlite_error_string(SQLITE_MISUSE), (char*)0);
|
2002-05-10 17:14:07 +04:00
|
|
|
sqliteStrRealloc(pzErrMsg);
|
2002-05-10 09:44:55 +04:00
|
|
|
}
|
2002-05-10 17:14:07 +04:00
|
|
|
return SQLITE_MISUSE;
|
2002-05-10 09:44:55 +04:00
|
|
|
}
|
|
|
|
|
2003-09-06 05:10:47 +04:00
|
|
|
|
2003-01-29 02:13:10 +03:00
|
|
|
/*
|
|
|
|
** The following routine destroys a virtual machine that is created by
|
|
|
|
** the sqlite_compile() routine.
|
|
|
|
**
|
|
|
|
** The integer returned is an SQLITE_ success/failure code that describes
|
|
|
|
** the result of executing the virtual machine. An error message is
|
|
|
|
** written into memory obtained from malloc and *pzErrMsg is made to
|
|
|
|
** point to that error if pzErrMsg is not NULL. The calling routine
|
|
|
|
** should use sqlite_freemem() to delete the message when it has finished
|
|
|
|
** with it.
|
|
|
|
*/
|
|
|
|
int sqlite_finalize(
|
|
|
|
sqlite_vm *pVm, /* The virtual machine to be destroyed */
|
|
|
|
char **pzErrMsg /* OUT: Write error messages here */
|
|
|
|
){
|
2003-01-29 21:46:51 +03:00
|
|
|
int rc = sqliteVdbeFinalize((Vdbe*)pVm, pzErrMsg);
|
|
|
|
sqliteStrRealloc(pzErrMsg);
|
|
|
|
return rc;
|
2003-01-29 02:13:10 +03:00
|
|
|
}
|
|
|
|
|
2003-07-22 13:24:43 +04:00
|
|
|
/*
|
2003-09-06 05:10:47 +04:00
|
|
|
** Terminate the current execution of a virtual machine then
|
|
|
|
** reset the virtual machine back to its starting state so that it
|
|
|
|
** can be reused. Any error message resulting from the prior execution
|
|
|
|
** is written into *pzErrMsg. A success code from the prior execution
|
|
|
|
** is returned.
|
2003-07-22 13:24:43 +04:00
|
|
|
*/
|
|
|
|
int sqlite_reset(
|
|
|
|
sqlite_vm *pVm, /* The virtual machine to be destroyed */
|
2003-09-06 05:10:47 +04:00
|
|
|
char **pzErrMsg /* OUT: Write error messages here */
|
2003-07-22 13:24:43 +04:00
|
|
|
){
|
2003-09-06 05:10:47 +04:00
|
|
|
int rc = sqliteVdbeReset((Vdbe*)pVm, pzErrMsg);
|
2003-09-07 02:18:07 +04:00
|
|
|
sqliteVdbeMakeReady((Vdbe*)pVm, -1, 0, 0, 0);
|
2003-07-22 13:24:43 +04:00
|
|
|
sqliteStrRealloc(pzErrMsg);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-05-10 09:44:55 +04:00
|
|
|
/*
|
2002-05-10 17:14:07 +04:00
|
|
|
** Return a static string that describes the kind of error specified in the
|
|
|
|
** argument.
|
2002-05-10 09:44:55 +04:00
|
|
|
*/
|
2002-05-10 17:14:07 +04:00
|
|
|
const char *sqlite_error_string(int rc){
|
|
|
|
const char *z;
|
|
|
|
switch( rc ){
|
|
|
|
case SQLITE_OK: z = "not an error"; break;
|
|
|
|
case SQLITE_ERROR: z = "SQL logic error or missing database"; break;
|
|
|
|
case SQLITE_INTERNAL: z = "internal SQLite implementation flaw"; break;
|
|
|
|
case SQLITE_PERM: z = "access permission denied"; break;
|
|
|
|
case SQLITE_ABORT: z = "callback requested query abort"; break;
|
|
|
|
case SQLITE_BUSY: z = "database is locked"; break;
|
|
|
|
case SQLITE_LOCKED: z = "database table is locked"; break;
|
|
|
|
case SQLITE_NOMEM: z = "out of memory"; break;
|
|
|
|
case SQLITE_READONLY: z = "attempt to write a readonly database"; break;
|
|
|
|
case SQLITE_INTERRUPT: z = "interrupted"; break;
|
|
|
|
case SQLITE_IOERR: z = "disk I/O error"; break;
|
|
|
|
case SQLITE_CORRUPT: z = "database disk image is malformed"; break;
|
|
|
|
case SQLITE_NOTFOUND: z = "table or record not found"; break;
|
|
|
|
case SQLITE_FULL: z = "database is full"; break;
|
|
|
|
case SQLITE_CANTOPEN: z = "unable to open database file"; break;
|
|
|
|
case SQLITE_PROTOCOL: z = "database locking protocol failure"; break;
|
|
|
|
case SQLITE_EMPTY: z = "table contains no data"; break;
|
|
|
|
case SQLITE_SCHEMA: z = "database schema has changed"; break;
|
|
|
|
case SQLITE_TOOBIG: z = "too much data for one table row"; break;
|
|
|
|
case SQLITE_CONSTRAINT: z = "constraint failed"; break;
|
|
|
|
case SQLITE_MISMATCH: z = "datatype mismatch"; break;
|
|
|
|
case SQLITE_MISUSE: z = "library routine called out of sequence";break;
|
2002-11-09 03:33:15 +03:00
|
|
|
case SQLITE_NOLFS: z = "kernel lacks large file support"; break;
|
2003-01-12 21:02:16 +03:00
|
|
|
case SQLITE_AUTH: z = "authorization denied"; break;
|
2003-06-12 12:59:00 +04:00
|
|
|
case SQLITE_FORMAT: z = "auxiliary database format error"; break;
|
2003-09-07 02:18:07 +04:00
|
|
|
case SQLITE_RANGE: z = "bind index out of range"; break;
|
2004-02-12 22:01:04 +03:00
|
|
|
case SQLITE_NOTADB: z = "file is encrypted or is not a database";break;
|
2002-05-10 17:14:07 +04:00
|
|
|
default: z = "unknown error"; break;
|
2002-05-10 09:44:55 +04:00
|
|
|
}
|
2002-05-10 17:14:07 +04:00
|
|
|
return z;
|
2002-05-10 09:44:55 +04:00
|
|
|
}
|
|
|
|
|
2000-07-28 18:32:48 +04:00
|
|
|
/*
|
|
|
|
** This routine implements a busy callback that sleeps and tries
|
|
|
|
** again until a timeout value is reached. The timeout value is
|
|
|
|
** an integer number of milliseconds passed in as the first
|
|
|
|
** argument.
|
|
|
|
*/
|
2001-04-11 18:28:42 +04:00
|
|
|
static int sqliteDefaultBusyCallback(
|
2000-07-28 18:32:48 +04:00
|
|
|
void *Timeout, /* Maximum amount of time to wait */
|
|
|
|
const char *NotUsed, /* The name of the table that is busy */
|
|
|
|
int count /* Number of times table has been busy */
|
|
|
|
){
|
2001-09-19 17:22:39 +04:00
|
|
|
#if SQLITE_MIN_SLEEP_MS==1
|
2004-01-15 16:29:31 +03:00
|
|
|
static const char delays[] =
|
|
|
|
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 50, 100};
|
|
|
|
static const short int totals[] =
|
|
|
|
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228, 287};
|
|
|
|
# define NDELAY (sizeof(delays)/sizeof(delays[0]))
|
2000-07-28 18:32:48 +04:00
|
|
|
int timeout = (int)Timeout;
|
2004-01-15 16:29:31 +03:00
|
|
|
int delay, prior;
|
2000-07-28 18:32:48 +04:00
|
|
|
|
2004-01-15 16:29:31 +03:00
|
|
|
if( count <= NDELAY ){
|
|
|
|
delay = delays[count-1];
|
|
|
|
prior = totals[count-1];
|
|
|
|
}else{
|
|
|
|
delay = delays[NDELAY-1];
|
|
|
|
prior = totals[NDELAY-1] + delay*(count-NDELAY-1);
|
2000-07-28 18:32:48 +04:00
|
|
|
}
|
2004-01-15 16:29:31 +03:00
|
|
|
if( prior + delay > timeout ){
|
|
|
|
delay = timeout - prior;
|
2000-07-28 18:32:48 +04:00
|
|
|
if( delay<=0 ) return 0;
|
|
|
|
}
|
2001-09-19 17:22:39 +04:00
|
|
|
sqliteOsSleep(delay);
|
2000-07-28 18:32:48 +04:00
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
int timeout = (int)Timeout;
|
|
|
|
if( (count+1)*1000 > timeout ){
|
|
|
|
return 0;
|
|
|
|
}
|
2001-09-19 17:22:39 +04:00
|
|
|
sqliteOsSleep(1000);
|
2000-07-28 18:32:48 +04:00
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This routine sets the busy callback for an Sqlite database to the
|
|
|
|
** given callback function with the given argument.
|
|
|
|
*/
|
|
|
|
void sqlite_busy_handler(
|
|
|
|
sqlite *db,
|
|
|
|
int (*xBusy)(void*,const char*,int),
|
|
|
|
void *pArg
|
|
|
|
){
|
|
|
|
db->xBusyCallback = xBusy;
|
|
|
|
db->pBusyArg = pArg;
|
|
|
|
}
|
|
|
|
|
2003-10-18 13:37:26 +04:00
|
|
|
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
|
|
|
|
/*
|
|
|
|
** This routine sets the progress callback for an Sqlite database to the
|
|
|
|
** given callback function with the given argument. The progress callback will
|
|
|
|
** be invoked every nOps opcodes.
|
|
|
|
*/
|
|
|
|
void sqlite_progress_handler(
|
|
|
|
sqlite *db,
|
|
|
|
int nOps,
|
|
|
|
int (*xProgress)(void*),
|
|
|
|
void *pArg
|
|
|
|
){
|
|
|
|
if( nOps>0 ){
|
|
|
|
db->xProgress = xProgress;
|
|
|
|
db->nProgressOps = nOps;
|
|
|
|
db->pProgressArg = pArg;
|
|
|
|
}else{
|
|
|
|
db->xProgress = 0;
|
|
|
|
db->nProgressOps = 0;
|
|
|
|
db->pProgressArg = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-07-28 18:32:48 +04:00
|
|
|
/*
|
|
|
|
** This routine installs a default busy handler that waits for the
|
|
|
|
** specified number of milliseconds before returning 0.
|
|
|
|
*/
|
|
|
|
void sqlite_busy_timeout(sqlite *db, int ms){
|
|
|
|
if( ms>0 ){
|
2001-04-11 18:28:42 +04:00
|
|
|
sqlite_busy_handler(db, sqliteDefaultBusyCallback, (void*)ms);
|
2000-07-28 18:32:48 +04:00
|
|
|
}else{
|
|
|
|
sqlite_busy_handler(db, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2000-10-17 02:06:40 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Cause any pending operation to stop at its earliest opportunity.
|
|
|
|
*/
|
|
|
|
void sqlite_interrupt(sqlite *db){
|
|
|
|
db->flags |= SQLITE_Interrupt;
|
|
|
|
}
|
2002-02-02 18:01:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Windows systems should call this routine to free memory that
|
|
|
|
** is returned in the in the errmsg parameter of sqlite_open() when
|
|
|
|
** SQLite is a DLL. For some reason, it does not work to call free()
|
|
|
|
** directly.
|
|
|
|
**
|
|
|
|
** Note that we need to call free() not sqliteFree() here, since every
|
|
|
|
** string that is exported from SQLite should have already passed through
|
|
|
|
** sqliteStrRealloc().
|
|
|
|
*/
|
|
|
|
void sqlite_freemem(void *p){ free(p); }
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Windows systems need functions to call to return the sqlite_version
|
2003-01-19 06:59:45 +03:00
|
|
|
** and sqlite_encoding strings since they are unable to access constants
|
|
|
|
** within DLLs.
|
2002-02-02 18:01:15 +03:00
|
|
|
*/
|
|
|
|
const char *sqlite_libversion(void){ return sqlite_version; }
|
|
|
|
const char *sqlite_libencoding(void){ return sqlite_encoding; }
|
2002-02-24 02:45:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Create new user-defined functions. The sqlite_create_function()
|
|
|
|
** routine creates a regular function and sqlite_create_aggregate()
|
|
|
|
** creates an aggregate function.
|
|
|
|
**
|
|
|
|
** Passing a NULL xFunc argument or NULL xStep and xFinalize arguments
|
|
|
|
** disables the function. Calling sqlite_create_function() with the
|
|
|
|
** same name and number of arguments as a prior call to
|
|
|
|
** sqlite_create_aggregate() disables the prior call to
|
|
|
|
** sqlite_create_aggregate(), and vice versa.
|
|
|
|
**
|
|
|
|
** If nArg is -1 it means that this function will accept any number
|
|
|
|
** of arguments, including 0.
|
|
|
|
*/
|
|
|
|
int sqlite_create_function(
|
|
|
|
sqlite *db, /* Add the function to this database connection */
|
|
|
|
const char *zName, /* Name of the function to add */
|
|
|
|
int nArg, /* Number of arguments */
|
2002-02-27 22:00:20 +03:00
|
|
|
void (*xFunc)(sqlite_func*,int,const char**), /* The implementation */
|
|
|
|
void *pUserData /* User data */
|
2002-02-24 02:45:45 +03:00
|
|
|
){
|
2002-02-28 03:41:10 +03:00
|
|
|
FuncDef *p;
|
2002-08-24 22:24:51 +04:00
|
|
|
int nName;
|
2002-05-10 17:14:07 +04:00
|
|
|
if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1;
|
2002-08-24 22:24:51 +04:00
|
|
|
nName = strlen(zName);
|
|
|
|
if( nName>255 ) return 1;
|
|
|
|
p = sqliteFindFunction(db, zName, nName, nArg, 1);
|
2002-02-27 04:53:13 +03:00
|
|
|
if( p==0 ) return 1;
|
2002-02-24 02:45:45 +03:00
|
|
|
p->xFunc = xFunc;
|
|
|
|
p->xStep = 0;
|
|
|
|
p->xFinalize = 0;
|
2002-02-27 22:00:20 +03:00
|
|
|
p->pUserData = pUserData;
|
2002-02-24 02:45:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int sqlite_create_aggregate(
|
|
|
|
sqlite *db, /* Add the function to this database connection */
|
|
|
|
const char *zName, /* Name of the function to add */
|
|
|
|
int nArg, /* Number of arguments */
|
2002-02-27 22:00:20 +03:00
|
|
|
void (*xStep)(sqlite_func*,int,const char**), /* The step function */
|
|
|
|
void (*xFinalize)(sqlite_func*), /* The finalizer */
|
|
|
|
void *pUserData /* User data */
|
2002-02-24 02:45:45 +03:00
|
|
|
){
|
2002-02-28 03:41:10 +03:00
|
|
|
FuncDef *p;
|
2002-08-24 22:24:51 +04:00
|
|
|
int nName;
|
2002-05-10 17:14:07 +04:00
|
|
|
if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1;
|
2002-08-24 22:24:51 +04:00
|
|
|
nName = strlen(zName);
|
|
|
|
if( nName>255 ) return 1;
|
|
|
|
p = sqliteFindFunction(db, zName, nName, nArg, 1);
|
2002-02-27 04:53:13 +03:00
|
|
|
if( p==0 ) return 1;
|
2002-02-24 02:45:45 +03:00
|
|
|
p->xFunc = 0;
|
|
|
|
p->xStep = xStep;
|
|
|
|
p->xFinalize = xFinalize;
|
2002-02-27 22:00:20 +03:00
|
|
|
p->pUserData = pUserData;
|
2002-02-24 02:45:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2002-06-20 15:36:48 +04:00
|
|
|
|
|
|
|
/*
|
2002-06-25 23:31:18 +04:00
|
|
|
** Change the datatype for all functions with a given name. See the
|
|
|
|
** header comment for the prototype of this function in sqlite.h for
|
|
|
|
** additional information.
|
2002-06-20 15:36:48 +04:00
|
|
|
*/
|
|
|
|
int sqlite_function_type(sqlite *db, const char *zName, int dataType){
|
|
|
|
FuncDef *p = (FuncDef*)sqliteHashFind(&db->aFunc, zName, strlen(zName));
|
|
|
|
while( p ){
|
|
|
|
p->dataType = dataType;
|
|
|
|
p = p->pNext;
|
|
|
|
}
|
2002-06-22 06:33:38 +04:00
|
|
|
return SQLITE_OK;
|
2002-06-20 15:36:48 +04:00
|
|
|
}
|
2002-06-25 23:31:18 +04:00
|
|
|
|
2003-01-16 19:28:53 +03:00
|
|
|
/*
|
|
|
|
** Register a trace function. The pArg from the previously registered trace
|
|
|
|
** is returned.
|
|
|
|
**
|
|
|
|
** A NULL trace function means that no tracing is executes. A non-NULL
|
|
|
|
** trace is a pointer to a function that is invoked at the start of each
|
|
|
|
** sqlite_exec().
|
|
|
|
*/
|
|
|
|
void *sqlite_trace(sqlite *db, void (*xTrace)(void*,const char*), void *pArg){
|
|
|
|
void *pOld = db->pTraceArg;
|
|
|
|
db->xTrace = xTrace;
|
|
|
|
db->pTraceArg = pArg;
|
|
|
|
return pOld;
|
2003-04-03 19:46:04 +04:00
|
|
|
}
|
2003-04-13 22:26:49 +04:00
|
|
|
|
2004-01-15 05:44:03 +03:00
|
|
|
/*** EXPERIMENTAL ***
|
|
|
|
**
|
|
|
|
** Register a function to be invoked when a transaction comments.
|
|
|
|
** If either function returns non-zero, then the commit becomes a
|
|
|
|
** rollback.
|
|
|
|
*/
|
|
|
|
void *sqlite_commit_hook(
|
|
|
|
sqlite *db, /* Attach the hook to this database */
|
|
|
|
int (*xCallback)(void*), /* Function to invoke on each commit */
|
|
|
|
void *pArg /* Argument to the function */
|
|
|
|
){
|
|
|
|
void *pOld = db->pCommitArg;
|
|
|
|
db->xCommitCallback = xCallback;
|
|
|
|
db->pCommitArg = pArg;
|
|
|
|
return pOld;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-13 22:26:49 +04:00
|
|
|
/*
|
2003-04-15 05:19:47 +04:00
|
|
|
** This routine is called to create a connection to a database BTree
|
|
|
|
** driver. If zFilename is the name of a file, then that file is
|
|
|
|
** opened and used. If zFilename is the magic name ":memory:" then
|
|
|
|
** the database is stored in memory (and is thus forgotten as soon as
|
|
|
|
** the connection is closed.) If zFilename is NULL then the database
|
|
|
|
** is for temporary use only and is deleted as soon as the connection
|
|
|
|
** is closed.
|
|
|
|
**
|
|
|
|
** A temporary database can be either a disk file (that is automatically
|
|
|
|
** deleted when the file is closed) or a set of red-black trees held in memory,
|
|
|
|
** depending on the values of the TEMP_STORE compile-time macro and the
|
|
|
|
** db->temp_store variable, according to the following chart:
|
|
|
|
**
|
|
|
|
** TEMP_STORE db->temp_store Location of temporary database
|
|
|
|
** ---------- -------------- ------------------------------
|
|
|
|
** 0 any file
|
|
|
|
** 1 1 file
|
|
|
|
** 1 2 memory
|
|
|
|
** 1 0 file
|
|
|
|
** 2 1 file
|
|
|
|
** 2 2 memory
|
|
|
|
** 2 0 memory
|
|
|
|
** 3 any memory
|
2003-04-13 22:26:49 +04:00
|
|
|
*/
|
|
|
|
int sqliteBtreeFactory(
|
|
|
|
const sqlite *db, /* Main database when opening aux otherwise 0 */
|
|
|
|
const char *zFilename, /* Name of the file containing the BTree database */
|
|
|
|
int omitJournal, /* if TRUE then do not journal this file */
|
|
|
|
int nCache, /* How many pages in the page cache */
|
|
|
|
Btree **ppBtree){ /* Pointer to new Btree object written here */
|
|
|
|
|
|
|
|
assert( ppBtree != 0);
|
|
|
|
|
2003-04-15 05:19:47 +04:00
|
|
|
#ifndef SQLITE_OMIT_INMEMORYDB
|
|
|
|
if( zFilename==0 ){
|
|
|
|
if (TEMP_STORE == 0) {
|
2003-04-13 22:26:49 +04:00
|
|
|
/* Always use file based temporary DB */
|
|
|
|
return sqliteBtreeOpen(0, omitJournal, nCache, ppBtree);
|
2003-04-15 05:19:47 +04:00
|
|
|
} else if (TEMP_STORE == 1 || TEMP_STORE == 2) {
|
2003-04-13 22:26:49 +04:00
|
|
|
/* Switch depending on compile-time and/or runtime settings. */
|
2003-04-15 05:19:47 +04:00
|
|
|
int location = db->temp_store==0 ? TEMP_STORE : db->temp_store;
|
2003-04-13 22:26:49 +04:00
|
|
|
|
|
|
|
if (location == 1) {
|
|
|
|
return sqliteBtreeOpen(zFilename, omitJournal, nCache, ppBtree);
|
|
|
|
} else {
|
2003-05-17 21:35:10 +04:00
|
|
|
return sqliteRbtreeOpen(0, 0, 0, ppBtree);
|
2003-04-13 22:26:49 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Always use in-core DB */
|
2003-05-17 21:35:10 +04:00
|
|
|
return sqliteRbtreeOpen(0, 0, 0, ppBtree);
|
2003-04-13 22:26:49 +04:00
|
|
|
}
|
2003-04-15 05:19:47 +04:00
|
|
|
}else if( zFilename[0]==':' && strcmp(zFilename,":memory:")==0 ){
|
2003-05-17 21:35:10 +04:00
|
|
|
return sqliteRbtreeOpen(0, 0, 0, ppBtree);
|
2003-04-15 05:19:47 +04:00
|
|
|
}else
|
|
|
|
#endif
|
|
|
|
{
|
2003-04-13 22:26:49 +04:00
|
|
|
return sqliteBtreeOpen(zFilename, omitJournal, nCache, ppBtree);
|
|
|
|
}
|
|
|
|
}
|