Be sure to ignore PRAGMA encoding pragmas if the encoding has already been

set for a database.  Ticket #1987.  This patch also includes some cleanup
of the schema parser and initialization logic. (CVS 3436)

FossilOrigin-Name: dc797bf4fa96deabd9ceb6cc062b98d2ac49a574
This commit is contained in:
drh 2006-09-23 20:36:01 +00:00
parent 7409310ac3
commit ece3c728d0
6 changed files with 65 additions and 31 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sbuild\sproblem\saround\ssqlite3_overload_function.\s\sOnly\saffects\nso/dll\sbuilds.\s(CVS\s3435)
D 2006-09-22T23:38:21
C Be\ssure\sto\signore\sPRAGMA\sencoding\spragmas\sif\sthe\sencoding\shas\salready\sbeen\nset\sfor\sa\sdatabase.\s\sTicket\s#1987.\s\sThis\spatch\salso\sincludes\ssome\scleanup\nof\sthe\sschema\sparser\sand\sinitialization\slogic.\s(CVS\s3436)
D 2006-09-23T20:36:02
F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -80,7 +80,7 @@ F src/pager.c 0f966f7fa225c377da2021fbbfdd50a48d877000
F src/pager.h 0cff9de5e9019cb695a04d18df8caaaff933a272
F src/parse.y 8c79a1debbd92a4f5609511e9bf0222de78f5ecb
F src/pragma.c dcb79b8170231f3aed99d4004b4d0a0fc14c4b4d
F src/prepare.c bc003436a4897b8f30b940e023a70297e860f805
F src/prepare.c 3d9a1bb0644e8bccb3b78cb0833d269719237f4e
F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519
@ -88,7 +88,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 672326e8d90394218509f1820ab0835e7ed2bc06
F src/sqlite.h.in bf935004029631fd93d119bcf2f7259b9cb9ad5e
F src/sqlite3ext.h 2c2156cc32a158e2b7bd9042d42accf94bff2e40
F src/sqliteInt.h c1d28fb13003c03fe7787d7ecc065d30530afc90
F src/sqliteInt.h 637ef229c3d8e0f98096ab31c496efdf5361d678
F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06
F src/tclsqlite.c e029f739bed90071789fe81a226d53e97a80a4d8
F src/test1.c 47f1d62d90fbf131dc5bbcd1b1aa18791fa3bc79
@ -112,7 +112,7 @@ F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129
F src/utf.c 4459801e9b00cfd69993bfca58545d3775682d6e
F src/util.c 91d4cb189476906639ae611927d939691d1365f6
F src/vacuum.c f958275b353bcc54776601582ea35ed427125a9d
F src/vdbe.c 39f775380fc3b8e30f0743b098c15e03d51bb7eb
F src/vdbe.c 84a9c0b0dd037c064ffed651977e20dd9d2bc1d1
F src/vdbe.h 258b5d1c0aaa72192f09ff0568ce42b383f156fa
F src/vdbeInt.h e3eaab262b67b84474625cfc38aec1125c32834b
F src/vdbeapi.c f1858a5edc3a5e32d038514dd9e7e9091400a782
@ -185,7 +185,7 @@ F test/descidx3.test 3a55b8d73bc3e9ad084e0da7fec781cf0d2a0356
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
F test/enc2.test 9f15cb7adc745fbb93d083ae1cf5a2deaa04d25f
F test/enc2.test 45710bacfa9df29720bc84c067dfdf8c8ddfb797
F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030
F test/expr.test c78843f730ccbe973d0c2ad1c99978f936893131
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
@ -399,7 +399,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 757fa22400b363212b4d5f648bdc9fcbd9a7f152
R a5ed36e0e4e279ba62dac19559917c53
U shess
Z db889ecb0c06c31c19fe6fec85c9eeaa
P 791d70936b9c4fed57c95f61e3b4dfdd24221ee4
R 42dffbf0309b331dd39f444b3d5b9fb3
U drh
Z 673fdf08a11b4d0ec87fe86a969bb8eb

View File

@ -1 +1 @@
791d70936b9c4fed57c95f61e3b4dfdd24221ee4
dc797bf4fa96deabd9ceb6cc062b98d2ac49a574

View File

@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.39 2006/09/15 07:28:50 drh Exp $
** $Id: prepare.c,v 1.40 2006/09/23 20:36:02 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -41,28 +41,26 @@ static void corruptSchema(InitData *pData, const char *zExtra){
** argv[0] = name of thing being created
** argv[1] = root page number for table or index. 0 for trigger or view.
** argv[2] = SQL text for the CREATE statement.
** argv[3] = "1" for temporary files, "0" for main database, "2" or more
** for auxiliary database files.
**
*/
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
InitData *pData = (InitData*)pInit;
sqlite3 *db = pData->db;
int iDb;
int iDb = pData->iDb;
pData->rc = SQLITE_OK;
DbClearProperty(db, iDb, DB_Empty);
if( sqlite3MallocFailed() ){
corruptSchema(pData, 0);
return SQLITE_NOMEM;
}
assert( argc==4 );
assert( argc==3 );
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
if( argv[1]==0 || argv[3]==0 ){
if( argv[1]==0 ){
corruptSchema(pData, 0);
return 1;
}
iDb = atoi(argv[3]);
assert( iDb>=0 && iDb<db->nDb );
if( argv[2] && argv[2][0] ){
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
@ -125,8 +123,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
int size;
Table *pTab;
Db *pDb;
char const *azArg[5];
char zDbNum[30];
char const *azArg[4];
int meta[10];
InitData initData;
char const *zMasterSchema;
@ -177,12 +174,11 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
azArg[0] = zMasterName;
azArg[1] = "1";
azArg[2] = zMasterSchema;
sprintf(zDbNum, "%d", iDb);
azArg[3] = zDbNum;
azArg[4] = 0;
azArg[3] = 0;
initData.db = db;
initData.iDb = iDb;
initData.pzErrMsg = pzErrMsg;
rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
rc = sqlite3InitCallback(&initData, 3, (char **)azArg, 0);
if( rc ){
sqlite3SafetyOn(db);
return initData.rc;
@ -295,8 +291,8 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
}else{
char *zSql;
zSql = sqlite3MPrintf(
"SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
zDbNum, db->aDb[iDb].zName, zMasterName);
"SELECT name, rootpage, sql FROM '%q'.%s",
db->aDb[iDb].zName, zMasterName);
sqlite3SafetyOff(db);
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
if( rc==SQLITE_ABORT ) rc = initData.rc;

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.528 2006/09/16 21:45:14 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.529 2006/09/23 20:36:02 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@ -1513,6 +1513,7 @@ struct DbFixer {
*/
typedef struct {
sqlite3 *db; /* The database being initialized */
int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */
char **pzErrMsg; /* Error message stored here */
int rc; /* Result code stored here */
} InitData;

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.576 2006/09/21 11:02:18 drh Exp $
** $Id: vdbe.c,v 1.577 2006/09/23 20:36:02 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -4050,10 +4050,11 @@ case OP_ParseSchema: { /* no-push */
if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
zMaster = SCHEMA_TABLE(iDb);
initData.db = db;
initData.iDb = pOp->p1;
initData.pzErrMsg = &p->zErrMsg;
zSql = sqlite3MPrintf(
"SELECT name, rootpage, sql, %d FROM '%q'.%s WHERE %s",
pOp->p1, db->aDb[iDb].zName, zMaster, pOp->p3);
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s",
db->aDb[iDb].zName, zMaster, pOp->p3);
if( zSql==0 ) goto no_mem;
sqlite3SafetyOff(db);
assert( db->init.busy==0 );

View File

@ -13,7 +13,7 @@
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.27 2006/01/23 15:59:55 drh Exp $
# $Id: enc2.test,v 1.28 2006/09/23 20:36:03 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -146,6 +146,22 @@ foreach enc $encodings {
sqlite3 db test.db
db eval "PRAGMA encoding = \"$enc\""
execsql $dbcontents
do_test enc2-$i.0.1 {
db eval {PRAGMA encoding}
} $enc
do_test enc2-$i.0.2 {
db eval {PRAGMA encoding=UTF8}
db eval {PRAGMA encoding}
} $enc
do_test enc2-$i.0.3 {
db eval {PRAGMA encoding=UTF16le}
db eval {PRAGMA encoding}
} $enc
do_test enc2-$i.0.4 {
db eval {PRAGMA encoding=UTF16be}
db eval {PRAGMA encoding}
} $enc
db close
run_test_script enc2-$i $enc
db close
@ -515,4 +531,24 @@ do_test enc2-9.5 {
}
} {UTF-16le}
# Ticket #1987.
# Disallow encoding changes once the encoding has been set.
#
do_test enc2-10.1 {
db close
file delete -force test.db test.db-journal
sqlite3 db test.db
db eval {
PRAGMA encoding=UTF16;
CREATE TABLE t1(a);
PRAGMA encoding=UTF8;
CREATE TABLE t2(b);
}
db close
sqlite3 db test.db
db eval {
SELECT name FROM sqlite_master
}
} {t1 t2}
finish_test