1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Check for schema updates if the parser fails to find a table. More locking

test updates. (CVS 1555)

FossilOrigin-Name: a22283512afe2df09d5783d189fbd7389ed313ad
This commit is contained in:
drh
2004-06-10 00:29:09 +00:00
parent f8646695a2
commit a6ecd33851
6 changed files with 69 additions and 37 deletions

View File

@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.210 2004/06/09 20:03:09 drh Exp $
** $Id: main.c,v 1.211 2004/06/10 00:29:09 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -855,6 +855,34 @@ int sqlite3_errcode(sqlite3 *db){
return db->errCode;
}
/*
** Check schema cookies in all databases except TEMP. If any cookie is out
** of date, return 0. If all schema cookies are current, return 1.
*/
static int schemaIsValid(sqlite *db){
int iDb;
int rc;
BtCursor *curTemp;
int cookie;
int allOk = 1;
for(iDb=0; allOk && iDb<db->nDb; iDb++){
Btree *pBt;
if( iDb==1 ) continue;
pBt = db->aDb[iDb].pBt;
if( pBt==0 ) continue;
rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
if( rc==SQLITE_OK ){
rc = sqlite3BtreeGetMeta(pBt, 1, &cookie);
if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
allOk = 0;
}
sqlite3BtreeCloseCursor(curTemp);
}
}
return allOk;
}
/*
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
*/
@@ -911,6 +939,9 @@ int sqlite3_prepare(
goto prepare_out;
}
if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
if( sParse.checkSchema && !schemaIsValid(db) ){
sParse.rc = SQLITE_SCHEMA;
}
if( sParse.rc==SQLITE_SCHEMA ){
sqlite3ResetInternalSchema(db, 0);
}