Fix error reporting when trying to attach a database with a foriegn text

encoding. (CVS 1545)

FossilOrigin-Name: beab038c71eecbabb1351b0c98a71f32ea013285
This commit is contained in:
danielk1977 2004-06-09 12:30:04 +00:00
parent 0202b29ef7
commit c039139807
9 changed files with 107 additions and 48 deletions

View File

@ -1,5 +1,5 @@
C Some\sprogress\son\suser-defined\scollation\ssequences.\s(CVS\s1544)
D 2004-06-09T09:55:17
C Fix\serror\sreporting\swhen\strying\sto\sattach\sa\sdatabase\swith\sa\sforiegn\stext\nencoding.\s(CVS\s1545)
D 2004-06-09T12:30:05
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -23,11 +23,11 @@ F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c e76e4590ec5dd389e5646b171881b5243a6ef391
F src/attach.c 93b8ecec4a8d7b4e9f2479e2327d90c9d01765e8
F src/auth.c 5c2f0bea4729c98c2be3b69d6b466fc51448fe79
F src/btree.c edb38affc2e83f4299e49104cfe14e6570d8bd32
F src/btree.h 589427ac13bb544d298cd99726e2572a6fe4bdaa
F src/build.c 763cb50521ee88873522ae2e836b121f312d2bb2
F src/build.c 4ea78aba171f02b96254dd7a312e4266d3693bfe
F src/date.c 8e6fa3173386fb29fdef012ee08a853c1e9908b2
F src/delete.c b30f08250c9ed53a25a13c7c04599c1e8753992d
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
@ -37,7 +37,7 @@ F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f
F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
F src/insert.c 4268d9e3959cc845ea243fb4ec7507269404dad9
F src/legacy.c ad23746f15f67e34577621b1875f639c94839e1f
F src/main.c ac8a6e871be5917775d2728b9abbb1659d59f8fd
F src/main.c 8a7725b40fbe645883b2162aee782ad1063435b4
F src/md5.c 4302e84ae516c616bb079c4e6d038c0addb33481
F src/os.h a3a9c2df29acbff54aef742e85c302d23634019f
F src/os_common.h 12074232439f904b3805beeff1245bd1b5532994
@ -50,13 +50,13 @@ F src/os_win.h 004eec47b1780fcaf07420ddc2072294b698d48c
F src/pager.c 3fddd1e5b3e449b19e4f762ab1f1d10786d56d28
F src/pager.h 0c7b5ac45c69e690c45d160d03bdc8fbd2d4657b
F src/parse.y 097438674976355a10cf177bd97326c548820b86
F src/pragma.c 9328a31c22615758077e8ded1126affe8f5e7fbe
F src/pragma.c d63b011bf860cec032b7da90b56643d189602ee5
F src/printf.c 63b15f1ea9fe3daa066bb7430fd20d4a2d717dc8
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
F src/select.c 1f8355e702f109f6771f82a9bfe7aac4c82cbaf2
F src/shell.c ca519519dcbbc582f6d88f7d0e7583b857fd3469
F src/sqlite.h.in 6ad05abc7fd72da74691e1eb45f0eff4117eba4e
F src/sqliteInt.h 55525f9a2d7b238ea4a89c04ae86fe9339452d6d
F src/sqliteInt.h f445d8085f826158a5ad28939987d52c3d14ed88
F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2
F src/tclsqlite.c f5c5116720baefb7de5d6acf18baedf1e42756cc
F src/test1.c 73770f2cd2bf97027e2edf62ee345e90c78dfcef
@ -65,7 +65,7 @@ F src/test3.c beafd0ccf7b9ae784744be1b1e66ffe8f64c25da
F src/test4.c a921a69821fd30209589228e64f94e9f715b6fe2
F src/test5.c 862784cd7a68e7d36f00287aac6e413ca996eaf8
F src/tokenize.c 183c5d7da11affab5d70d903d33409c8c0ce6c5b
F src/trigger.c 2c28bf37f21e1ca2fc39cd88db8dbe3ad6ac5419
F src/trigger.c d1a4d7a59b34c811bf6070d64d0497baa0140dcf
F src/update.c 259f06e7b22c684b2d3dda54a18185892d6e9573
F src/utf.c c2c8e445bfea724f3502609d6389fe66651f02ab
F src/util.c ad379519d8267ea1f626874ad4e629e982e8ca58
@ -102,7 +102,7 @@ F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d
F test/delete.test ddb1d4e172a01c0165804f82f81df556fb48a856
F test/enc.test a55481d45ff493804e8d88357feb4642fc50a6b2
F test/enc2.test a46170cc3a3fdc3e8647abf8eebca584886cf611
F test/enc2.test fb00c4954b4f3eca1e8ec9c26671c68f6170226d
F test/expr.test 521588701dae8cf5aa2b8a18c5c897711f754332
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
F test/func.test 9816fbed0a5e87e00f4fc88b4cdcd638abc524c4
@ -218,7 +218,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248
F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 1086196460e261718e78512d77e25dde021a117d
R 20d537aca227a4420895d927bae8916e
P c634e71f1909819fb55c728bc410e5cc390428e3
R 9b06499f09555f5a8d25ad8905d9a708
U danielk1977
Z 480a8bf4fe8242d162be76603ac93c57
Z 94cfe73075b9a13ff300fa5270c56964

View File

@ -1 +1 @@
c634e71f1909819fb55c728bc410e5cc390428e3
beab038c71eecbabb1351b0c98a71f32ea013285

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.13 2004/06/07 07:52:18 danielk1977 Exp $
** $Id: attach.c,v 1.14 2004/06/09 12:30:05 danielk1977 Exp $
*/
#include "sqliteInt.h"
@ -105,7 +105,7 @@ void sqlite3Attach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey)
db->flags &= ~SQLITE_Initialized;
if( pParse->nErr ) return;
if( rc==SQLITE_OK ){
rc = sqlite3ReadSchema(pParse->db);
rc = sqlite3ReadSchema(pParse->db, &pParse->zErrMsg);
}
if( rc ){
int i = db->nDb - 1;

View File

@ -23,7 +23,7 @@
** ROLLBACK
** PRAGMA
**
** $Id: build.c,v 1.211 2004/06/09 09:55:17 danielk1977 Exp $
** $Id: build.c,v 1.212 2004/06/09 12:30:05 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -130,7 +130,7 @@ void sqlite3FinishCoding(Parse *pParse){
Table *sqlite3FindTable(sqlite *db, const char *zName, const char *zDatabase){
Table *p = 0;
int i;
int rc = sqlite3ReadSchema(db);
int rc = sqlite3ReadSchema(db, 0);
for(i=0; rc==SQLITE_OK && 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;
@ -183,7 +183,7 @@ Table *sqlite3LocateTable(Parse *pParse, const char *zName, const char *zDbase){
Index *sqlite3FindIndex(sqlite *db, const char *zName, const char *zDb){
Index *p = 0;
int i;
int rc = sqlite3ReadSchema(db);
int rc = sqlite3ReadSchema(db, 0);
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;

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.208 2004/06/09 09:55:18 danielk1977 Exp $
** $Id: main.c,v 1.209 2004/06/09 12:30:06 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -382,21 +382,15 @@ int sqlite3Init(sqlite *db, char **pzErrMsg){
** This routine is a no-op if the database schema is already initialised.
** Otherwise, the schema is loaded. An error code is returned.
*/
int sqlite3ReadSchema(sqlite *db){
int sqlite3ReadSchema(sqlite *db, char **pzErrMsg){
int rc = SQLITE_OK;
char *zErrMsg = 0;
if( !db->init.busy ){
if( (db->flags & SQLITE_Initialized)==0 ){
rc = sqlite3Init(db, &zErrMsg);
rc = sqlite3Init(db, pzErrMsg);
}
}
assert( (db->flags & SQLITE_Initialized)!=0 || db->init.busy );
sqlite3Error(db, rc, zErrMsg);
if( zErrMsg ){
sqliteFree(zErrMsg);
}
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized)||db->init.busy );
return rc;
}

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.38 2004/06/09 00:48:13 drh Exp $
** $Id: pragma.c,v 1.39 2004/06/09 12:30:06 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -203,7 +203,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
{ OP_Callback, 1, 0, 0},
};
int addr;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( pRight->z==pLeft->z ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "cache_size", P3_STATIC);
@ -243,7 +246,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOpList getCacheSize[] = {
{ OP_Callback, 1, 0, 0},
};
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( pRight->z==pLeft->z ){
int size = db->cache_size;;
if( size<0 ) size = -size;
@ -294,7 +300,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
{ OP_Callback, 1, 0, 0}
};
int addr;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( pRight->z==pLeft->z ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "synchronous", P3_STATIC);
@ -338,7 +347,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOpList getSync[] = {
{ OP_Callback, 1, 0, 0},
};
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( pRight->z==pLeft->z ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "synchronous", P3_STATIC);
@ -371,7 +383,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
if( sqlite3StrICmp(zLeft, "table_info")==0 ){
Table *pTab;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
pTab = sqlite3FindTable(db, zRight, 0);
if( pTab ){
int i;
@ -400,7 +415,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
if( sqlite3StrICmp(zLeft, "index_info")==0 ){
Index *pIdx;
Table *pTab;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
pIdx = sqlite3FindIndex(db, zRight, 0);
if( pIdx ){
int i;
@ -423,7 +441,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
if( sqlite3StrICmp(zLeft, "index_list")==0 ){
Index *pIdx;
Table *pTab;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
pTab = sqlite3FindTable(db, zRight, 0);
if( pTab ){
v = sqlite3GetVdbe(pParse);
@ -449,7 +470,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 ){
FKey *pFK;
Table *pTab;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
pTab = sqlite3FindTable(db, zRight, 0);
if( pTab ){
v = sqlite3GetVdbe(pParse);
@ -482,7 +506,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
if( sqlite3StrICmp(zLeft, "database_list")==0 ){
int i;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
sqlite3VdbeSetNumCols(v, 3);
sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
@ -514,7 +541,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOpList getTmpDbLoc[] = {
{ OP_Callback, 1, 0, 0},
};
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( pRight->z==pLeft->z ){
sqlite3VdbeAddOp(v, OP_Integer, db->temp_store, 0);
sqlite3VdbeSetNumCols(v, 1);
@ -540,7 +570,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOpList getTmpDbLoc[] = {
{ OP_ReadCookie, 0, 5, 0},
{ OP_Callback, 1, 0, 0}};
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( pRight->z==pLeft->z ){
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "temp_store", P3_STATIC);
@ -556,7 +589,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
#ifndef NDEBUG
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
extern void sqlite3ParserTrace(FILE*, char *);
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
if( getBoolean(zRight) ){
sqlite3ParserTrace(stdout, "parser: ");
}else{
@ -589,7 +625,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
};
/* Initialize the VDBE program */
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);
@ -734,7 +773,10 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
};
struct EncName *pEnc;
if( pRight->z==pLeft->z ){ /* "PRAGMA encoding" */
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db) ) return;
if( SQLITE_OK!=sqlite3ReadSchema(pParse->db, &pParse->zErrMsg) ){
pParse->nErr++;
return;
}
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, "encoding", P3_STATIC);
sqlite3VdbeAddOp(v, OP_String8, 0, 0);

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.273 2004/06/09 09:55:19 danielk1977 Exp $
** @(#) $Id: sqliteInt.h,v 1.274 2004/06/09 12:30:06 danielk1977 Exp $
*/
#include "config.h"
#include "sqlite3.h"
@ -1389,7 +1389,7 @@ void *sqlite3HexToBlob(const char *z);
int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
const char *sqlite3ErrStr(int);
int sqlite3ReadUniChar(const char *zStr, int *pOffset, u8 *pEnc, int fold);
int sqlite3ReadSchema(sqlite *db);
int sqlite3ReadSchema(sqlite *db, char **);
CollSeq *sqlite3FindCollSeq(sqlite *,const char *,int,int);
CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
CollSeq *sqlite3ExprCollSeq(Expr *pExpr);

View File

@ -421,7 +421,10 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
sqlite *db = pParse->db;
if( sqlite3_malloc_failed ) goto drop_trigger_cleanup;
if( SQLITE_OK!=sqlite3ReadSchema(db) ) goto drop_trigger_cleanup;
if( SQLITE_OK!=sqlite3ReadSchema(db, &pParse->zErrMsg) ){
pParse->nErr++;
goto drop_trigger_cleanup;
}
assert( pName->nSrc==1 );
zDb = pName->a[0].zDatabase;

View File

@ -13,7 +13,7 @@
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.5 2004/06/07 07:52:19 danielk1977 Exp $
# $Id: enc2.test,v 1.6 2004/06/09 12:30:06 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -114,7 +114,7 @@ set encodings [list UTF-8 UTF-16le UTF-16be]
set i 1
foreach enc $encodings {
file delete -force test.db
sqlite db test.db $enc
sqlite db test.db
db eval "PRAGMA encoding = \"$enc\""
execsql $dbcontents
db close
@ -122,4 +122,24 @@ foreach enc $encodings {
incr i
}
# Test that it is an error to try to attach a database with a different
# encoding to the main database.
do_test enc2-4.1 {
file delete -force test.db
sqlite db test.db
db eval "PRAGMA encoding = 'UTF-8'"
db eval "CREATE TABLE abc(a, b, c);"
} {}
do_test enc2-4.2 {
file delete -force test2.db
sqlite db2 test2.db
db2 eval "PRAGMA encoding = 'UTF-16'"
db2 eval "CREATE TABLE abc(a, b, c);"
} {}
do_test enc2-4.3 {
catchsql {
ATTACH 'test2.db' as aux;
}
} {1 {attached databases must use the same text encoding as main database}}
finish_test