Fix bugs caused by assuming that shared-schemas are initialized. (CVS 2917)

FossilOrigin-Name: 3970eb875d1830d35b3a70a7583a8ab6b238cad6
This commit is contained in:
danielk1977 2006-01-11 14:09:31 +00:00
parent 003437a0a7
commit b82e7edae9
12 changed files with 117 additions and 84 deletions

@ -1,5 +1,5 @@
C Fix\stypo\snoted\sby\s#1599.\s(CVS\s2916)
D 2006-01-11T05:49:50
C Fix\sbugs\scaused\sby\sassuming\sthat\sshared-schemas\sare\sinitialized.\s(CVS\s2917)
D 2006-01-11T14:09:31
F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -32,11 +32,11 @@ F sqlite3.def ccf06c86eaa2c123271db41352d2b3c9e4ec42a5
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
F src/alter.c d0dd079b9ef0d551ff4a4ce09ee270c07b307bbb
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
F src/attach.c 8438a2808f89c01cfd472e676a27d771ac4405aa
F src/attach.c fb93d00ab7cb392579ea7db0a1247196d7220788
F src/auth.c cdec356a5cd8b217c346f816c5912221537fe87f
F src/btree.c 874eaba6dec1660c7c917d5afc790f69de82cf2e
F src/btree.c e1f6b2e22484d754b79b7c9b43e7a09af259f0f6
F src/btree.h 5663c4f43e8521546ccebc8fc95acb013b8f3184
F src/build.c 59c4a6fc0e89590c7eec3154acb4cf6644674d7d
F src/build.c c7847f299ded7fec899bfda74d4d31ba9f80aa75
F src/callback.c 51fe813309f7cf69d3d19a2e7be2103130186efd
F src/complete.c df1681cef40dec33a286006981845f87b194e7a4
F src/date.c a927bdbb51296ac398d2f667086a7072c099e5ab
@ -62,18 +62,18 @@ F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 0a59a320b0da6b22d2dd4411d16e300ff1b947c8
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c
F src/pragma.c 711992e440ce78569322dd625d2cfe1cd696ccfb
F src/prepare.c 3283bb65b4b217a092c9cbf65014774e6c3a142d
F src/pragma.c d439d257c1bcacbc09d38820ac578749df900562
F src/prepare.c 65b166b806e4af6e0035acdd5f6a24e2ec02b66d
F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c 579cfdd250c5598de7c867134f7d35a2099b1dcc
F src/server.c 519e308651e30102dd3d1f4053ac64c14267e44c
F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
F src/sqlite.h.in 821b93f918d126c54d9a91fc928434945655edc3
F src/sqliteInt.h d7584dc5b8e15f1732a195ece9e93049ccde35fa
F src/sqliteInt.h 829f8c22767ceaed717042087e7fb4d599a3c44c
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c d650bea0248fc0a310ddc2cb94273a3a5021fddf
F src/test1.c 5f634ce9aa452dbcc362993c9612047df800216c
F src/test1.c b2923fd22ec44cf05d6d51dc460e8ed8e0d5f241
F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b
F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
@ -155,7 +155,7 @@ F test/descidx3.test 56daed47e2eb91cef15a21a656691bb82a4699ba
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
F test/enc2.test 6ea55732ddffd340f3d3a29cc33645e9ded481c7
F test/enc2.test 0c8d3142c032c4f907b546d99e00b787f9700bb7
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
F test/expr.test a513aceb5d89042232e0d07ac5a1591965cf3963
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
@ -225,7 +225,7 @@ F test/select5.test 07a90ab3c7e3f0a241a9cdea1d997b2c8a89ff0b
F test/select6.test f459a19bdac0501c4d3eb1a4df4b7a76f1bb8ad4
F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
F test/server1.test 9d2d5b17b537911214a7e2a2728ff4f6ff16319c
F test/shared.test 2c0089652d936771ca7eeab51cc3c93a9e2dce36
F test/shared.test b94678497bf6051faf68ecb1f692d5cc04b8d330
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
F test/subquery.test e6de53332c0301b3cfa34edc3f3cd5fa1e859efd
F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
@ -264,7 +264,7 @@ F test/types3.test e5f789503849294de74a23b433168e8211523a25
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
F test/utf16.test f9c13f4e2b48c42d0bfc96647d82fdf7bc11fc55
F test/vacuum.test 61e2b6e7dcf0eec90cdf6cc63e30321c8b037b1f
F test/vacuum.test 37f998b841cb335397c26d9bbc3457182af2565f
F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
@ -340,7 +340,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 59a7a56c1bba84b5c60a2f3e25bf51d933075aaf
R c2e57d06b8aad90e5d4817eb22be0455
P 1b368c7c5ca7974e0975dc4e3c931680c9e8df1f
R 1449ef4e2e811b71b71db6703a8a24ab
U danielk1977
Z 4e9d5528a047a73ba151041fd7b20eeb
Z 8596c20274e6f745d3adfacf59742397

@ -1 +1 @@
1b368c7c5ca7974e0975dc4e3c931680c9e8df1f
3970eb875d1830d35b3a70a7583a8ab6b238cad6

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.44 2006/01/10 07:14:23 danielk1977 Exp $
** $Id: attach.c,v 1.45 2006/01/11 14:09:31 danielk1977 Exp $
*/
#include "sqliteInt.h"
@ -171,7 +171,6 @@ static void attachFunc(
** we found it.
*/
if( rc==SQLITE_OK ){
db->flags &= ~SQLITE_Initialized;
sqlite3SafetyOn(db);
rc = sqlite3Init(db, &zErrDyn);
sqlite3SafetyOff(db);

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.289 2006/01/10 13:58:48 drh Exp $
** $Id: btree.c,v 1.290 2006/01/11 14:09:31 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@ -1579,6 +1579,7 @@ int sqlite3BtreeOpen(
return SQLITE_NOMEM;
}
for(pBt=pTsd->pBtree; pBt; pBt=pBt->pNext){
assert( pBt->nRef>0 );
if( 0==strcmp(zFullPathname, sqlite3pager_filename(pBt->pPager)) ){
p->pBt = pBt;
*ppBtree = p;
@ -6498,3 +6499,27 @@ int sqlite3BtreeLockTable(Btree *p, int iTab, u8 isWriteLock){
#endif
return rc;
}
#if defined(SQLITE_TEST) && !defined(NO_TCL)
#include <tcl.h>
int sqlite3_shared_cache_report(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
ThreadData *pTd = sqlite3ThreadData();
if( pTd->useSharedData ){
BtShared *pBt;
Tcl_Obj *pRet = Tcl_NewObj();
for(pBt=pTd->pBtree; pBt; pBt=pBt->pNext){
const char *zFile = sqlite3pager_filename(pBt->pPager);
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
}
Tcl_SetObjResult(interp, pRet);
}
return TCL_OK;
}
#endif

@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.375 2006/01/10 17:58:23 danielk1977 Exp $
** $Id: build.c,v 1.376 2006/01/11 14:09:32 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -255,7 +255,6 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
Table *p = 0;
int i;
assert( zName!=0 );
assert( (db->flags & SQLITE_Initialized) || db->init.busy );
for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
@ -311,7 +310,6 @@ Table *sqlite3LocateTable(Parse *pParse, const char *zName, const char *zDbase){
Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
Index *p = 0;
int i;
assert( (db->flags & SQLITE_Initialized) || db->init.busy );
for(i=OMIT_TEMPDB; i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
Schema *pSchema = db->aDb[j].pSchema;
@ -393,7 +391,6 @@ void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
int i, j;
assert( iDb>=0 && iDb<db->nDb );
db->flags &= ~SQLITE_Initialized;
for(i=iDb; i<db->nDb; i++){
Db *pDb = &db->aDb[i];
if( pDb->pSchema ){

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.112 2006/01/10 17:58:23 danielk1977 Exp $
** $Id: pragma.c,v 1.113 2006/01/11 14:09:32 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -808,7 +808,10 @@ void sqlite3Pragma(
** will be overwritten when the schema is next loaded. If it does not
** already exists, it will be created to use the new encoding value.
*/
if( !(pParse->db->flags&SQLITE_Initialized) ){
if(
!(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
DbHasProperty(db, 0, DB_Empty)
){
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
ENC(pParse->db) = pEnc->enc;

@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.18 2006/01/10 17:58:23 danielk1977 Exp $
** $Id: prepare.c,v 1.19 2006/01/11 14:09:32 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -154,27 +154,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
#endif
assert( iDb>=0 && iDb<db->nDb );
assert( db->aDb[iDb].pSchema );
#if 0
if( 0==db->aDb[iDb].pSchema ){
Schema *pS = sqlite3SchemaGet(db->aDb[iDb].pBt);
db->aDb[iDb].pSchema = pS;
if( !pS ){
return SQLITE_NOMEM;
}else if( pS->file_format!=0 ){
/* This means that the shared-schema associated with the the btree
** is already open and populated.
*/
if( pS->enc!=ENC(db) ){
sqlite3SetString(pzErrMsg, "attached databases must use the same"
" text encoding as main database", (char*)0);
return SQLITE_ERROR;
}
return SQLITE_OK;
}
}
#endif
/* zMasterSchema and zInitScript are set to point at the master schema
** and initialisation script appropriate for the database being
@ -212,7 +192,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
*/
pDb = &db->aDb[iDb];
if( pDb->pBt==0 ){
if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
if( !OMIT_TEMPDB && iDb==1 ){
DbSetProperty(db, 1, DB_SchemaLoaded);
}
return SQLITE_OK;
}
rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, 0, &curMain);
@ -272,6 +254,8 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
return SQLITE_ERROR;
}
}
}else{
DbSetProperty(db, iDb, DB_Empty);
}
pDb->pSchema->enc = ENC(db);
@ -343,9 +327,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
*/
int sqlite3Init(sqlite3 *db, char **pzErrMsg){
int i, rc;
int called_initone = 0;
if( db->init.busy ) return SQLITE_OK;
assert( (db->flags & SQLITE_Initialized)==0 );
rc = SQLITE_OK;
db->init.busy = 1;
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
@ -354,6 +338,7 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){
if( rc ){
sqlite3ResetInternalSchema(db, i);
}
called_initone = 1;
}
/* Once all the other databases have been initialised, load the schema
@ -366,19 +351,16 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){
if( rc ){
sqlite3ResetInternalSchema(db, 1);
}
called_initone = 1;
}
#endif
db->init.busy = 0;
if( rc==SQLITE_OK ){
db->flags |= SQLITE_Initialized;
if( rc==SQLITE_OK && called_initone ){
sqlite3CommitInternalChanges(db);
}
if( rc!=SQLITE_OK ){
db->flags &= ~SQLITE_Initialized;
}
return rc;
return rc;
}
/*
@ -389,11 +371,8 @@ int sqlite3ReadSchema(Parse *pParse){
int rc = SQLITE_OK;
sqlite3 *db = pParse->db;
if( !db->init.busy ){
if( (db->flags & SQLITE_Initialized)==0 ){
rc = sqlite3Init(db, &pParse->zErrMsg);
}
rc = sqlite3Init(db, &pParse->zErrMsg);
}
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy );
if( rc!=SQLITE_OK ){
pParse->rc = rc;
pParse->nErr++;

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.460 2006/01/10 17:58:23 danielk1977 Exp $
** @(#) $Id: sqliteInt.h,v 1.461 2006/01/11 14:09:32 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@ -423,6 +423,7 @@ struct Schema {
*/
#define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
#define DB_UnresetViews 0x0002 /* Some views have defined column names */
#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
@ -522,7 +523,6 @@ struct sqlite3 {
** transaction is active on that particular database file.
*/
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
#define SQLITE_Initialized 0x00000002 /* True after initialization */
#define SQLITE_Interrupt 0x00000004 /* Cancel current operation */
#define SQLITE_InTrans 0x00000008 /* True if in a transaction */
#define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.186 2006/01/09 16:12:05 danielk1977 Exp $
** $Id: test1.c,v 1.187 2006/01/11 14:09:32 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -3523,5 +3523,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_fullsync_count, TCL_LINK_INT);
#endif /* OS_UNIX */
set_options(interp);
int sqlite3_shared_cache_report(void *, Tcl_Interp *, int, Tcl_Obj *CONST[]);
Tcl_CreateObjCommand(interp, "sqlite_shared_cache_report",
sqlite3_shared_cache_report, 0, 0);
return TCL_OK;
}

@ -13,7 +13,7 @@
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.25 2006/01/03 00:33:50 drh Exp $
# $Id: enc2.test,v 1.26 2006/01/11 14:09:32 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -473,4 +473,45 @@ ifcapable {complete} {
} {0}
}
# Test that the encoding of an empty database may still be set after the
# (empty) schema has been initialized.
file delete -force test.db
do_test enc2-9.1 {
sqlite3 db test.db
execsql {
PRAGMA encoding = 'UTF-8';
PRAGMA encoding;
}
} {UTF-8}
do_test enc2-9.2 {
sqlite3 db test.db
execsql {
PRAGMA encoding = 'UTF-16le';
PRAGMA encoding;
}
} {UTF-16le}
do_test enc2-9.3 {
sqlite3 db test.db
execsql {
SELECT * FROM sqlite_master;
PRAGMA encoding = 'UTF-8';
PRAGMA encoding;
}
} {UTF-8}
do_test enc2-9.4 {
sqlite3 db test.db
execsql {
PRAGMA encoding = 'UTF-16le';
CREATE TABLE abc(a, b, c);
PRAGMA encoding;
}
} {UTF-16le}
do_test enc2-9.5 {
sqlite3 db test.db
execsql {
PRAGMA encoding = 'UTF-8';
PRAGMA encoding;
}
} {UTF-16le}
finish_test

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: shared.test,v 1.10 2006/01/11 01:08:34 drh Exp $
# $Id: shared.test,v 1.11 2006/01/11 14:09:32 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -608,26 +608,6 @@ catch {db close}
catch {db2 close}
file delete -force test.db test2.db
if 0 {
do_test shared-9.1 {
sqlite3 db test.db
} {}
do_test shared-9.2 {
execsql {CREATE TABLE t1(a);}
} {}
file delete -force test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
do_test shared-9.3 {
execsql {
CREATE TABLE t5(a);
INSERT INTO t5 VALUES('one');
} db
} {}
}
#---------------------------------------------------------------------------
# The following tests - shared-9.* - test interactions between TEMP triggers
# and shared-schemas.

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the VACUUM statement.
#
# $Id: vacuum.test,v 1.36 2006/01/03 00:33:50 drh Exp $
# $Id: vacuum.test,v 1.37 2006/01/11 14:09:32 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -164,6 +164,11 @@ do_test vacuum-2.5 {
}
sqlite3 db3 test.db
execsql {
-- The "SELECT * FROM sqlite_master" statement ensures that this test
-- works when shared-cache is enabled. If shared-cache is enabled, then
-- db3 shares a cache with db2 (but not db - it was opened as
-- "./test.db").
SELECT * FROM sqlite_master;
SELECT * FROM t7 LIMIT 1
} db3
execsql {