diff options
author | danielk1977 <danielk1977@noemail.net> | 2006-01-09 16:12:04 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2006-01-09 16:12:04 +0000 |
commit | 14db26653ab6cc7fd24a7b4c77596e843b40bee0 (patch) | |
tree | 6495699ed421636be27f583008e99c7b02bb0775 /src | |
parent | 52622828ce62688382404e237179f188fc46b06d (diff) | |
download | sqlite-14db26653ab6cc7fd24a7b4c77596e843b40bee0.tar.gz sqlite-14db26653ab6cc7fd24a7b4c77596e843b40bee0.zip |
Fix some errors to do with attached databases and text encodings in shared-cache mode. (CVS 2895)
FossilOrigin-Name: 3e75d3d5efebc0dfff1adfc13d85e85ec39db3eb
Diffstat (limited to 'src')
-rw-r--r-- | src/attach.c | 7 | ||||
-rw-r--r-- | src/build.c | 17 | ||||
-rw-r--r-- | src/callback.c | 10 | ||||
-rw-r--r-- | src/expr.c | 8 | ||||
-rw-r--r-- | src/func.c | 10 | ||||
-rw-r--r-- | src/main.c | 11 | ||||
-rw-r--r-- | src/pragma.c | 16 | ||||
-rw-r--r-- | src/prepare.c | 36 | ||||
-rw-r--r-- | src/select.c | 7 | ||||
-rw-r--r-- | src/sqliteInt.h | 8 | ||||
-rw-r--r-- | src/test1.c | 6 | ||||
-rw-r--r-- | src/update.c | 4 | ||||
-rw-r--r-- | src/vdbe.c | 56 | ||||
-rw-r--r-- | src/vdbeapi.c | 2 |
14 files changed, 105 insertions, 93 deletions
diff --git a/src/attach.c b/src/attach.c index 57e0a98f8..3192ab149 100644 --- a/src/attach.c +++ b/src/attach.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.41 2006/01/09 06:29:48 danielk1977 Exp $ +** $Id: attach.c,v 1.42 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -127,6 +127,11 @@ static void attachFunc( if( !aNew->pSchema ){ rc = SQLITE_NOMEM; } + if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ + strcpy(zErr, + "attached databases must use the same text encoding as main database"); + goto attach_error; + } } aNew->zName = sqliteStrDup(zName); aNew->safety_level = 3; diff --git a/src/build.c b/src/build.c index 5b3594f2f..e2cee79d3 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.371 2006/01/09 06:29:48 danielk1977 Exp $ +** $Id: build.c,v 1.372 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -68,7 +68,7 @@ void sqlite3TableLock( TableLock *p; ThreadData *pTsd = sqlite3ThreadData(); - if( 0==pTsd->useSharedData ){ + if( 0==pTsd->useSharedData || iDb<0 ){ return; } @@ -846,7 +846,7 @@ void sqlite3StartTable( sqlite3VdbeAddOp(v, OP_If, 0, lbl); sqlite3VdbeAddOp(v, OP_Integer, SQLITE_DEFAULT_FILE_FORMAT, 0); sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1); - sqlite3VdbeAddOp(v, OP_Integer, db->enc, 0); + sqlite3VdbeAddOp(v, OP_Integer, ENC(db), 0); sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 4); sqlite3VdbeResolveLabel(v, lbl); @@ -1220,7 +1220,7 @@ int sqlite3CheckIndexCollSeq(Parse *pParse, Index *pIdx){ */ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){ sqlite3 *db = pParse->db; - u8 enc = db->enc; + u8 enc = ENC(db); u8 initbusy = db->init.busy; CollSeq *pColl = sqlite3FindCollSeq(db, enc, zName, nName, initbusy); @@ -2955,12 +2955,6 @@ static int sqlite3OpenTempDatabase(Parse *pParse){ pParse->rc = rc; return 1; } -/* - db->aDb[1].pSchema = sqlite3SchemaGet(db->aDb[1].pBt); - if( !db->aDb[1].pSchema ){ - return SQLITE_NOMEM; - } -*/ if( db->flags & !db->autoCommit ){ rc = sqlite3BtreeBeginTrans(db->aDb[1].pBt, 1); if( rc!=SQLITE_OK ){ @@ -2970,6 +2964,7 @@ static int sqlite3OpenTempDatabase(Parse *pParse){ return 1; } } + assert( db->aDb[1].pSchema ); } return 0; } @@ -3144,7 +3139,7 @@ void sqlite3Reindex(Parse *pParse, Token *pName1, Token *pName2){ reindexDatabases(pParse, 0); return; }else if( pName2==0 || pName2->z==0 ){ - pColl = sqlite3FindCollSeq(db, db->enc, (char*)pName1->z, pName1->n, 0); + pColl = sqlite3FindCollSeq(db, ENC(db), (char*)pName1->z, pName1->n, 0); if( pColl ){ reindexDatabases(pParse, pColl); return; diff --git a/src/callback.c b/src/callback.c index d753a4d20..bd8e28eeb 100644 --- a/src/callback.c +++ b/src/callback.c @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.8 2006/01/09 06:29:48 danielk1977 Exp $ +** $Id: callback.c,v 1.9 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -29,7 +29,7 @@ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){ if( db->xCollNeeded ){ char *zExternal = sqliteStrNDup(zName, nName); if( !zExternal ) return; - db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal); + db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal); sqliteFree(zExternal); } #ifndef SQLITE_OMIT_UTF16 @@ -39,7 +39,7 @@ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){ sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC); zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE); if( zExternal ){ - db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal); + db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal); } sqlite3ValueFree(pTmp); } @@ -92,14 +92,14 @@ CollSeq *sqlite3GetCollSeq( p = pColl; if( !p ){ - p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0); + p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0); } if( !p || !p->xCmp ){ /* No collation sequence of this type for this encoding is registered. ** Call the collation factory to see if it can supply us with one. */ callCollNeeded(db, zName, nName); - p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0); + p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0); } if( p && !p->xCmp && synthCollSeq(db, p) ){ p = 0; diff --git a/src/expr.c b/src/expr.c index 6c78582ba..d3c31f158 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.245 2006/01/09 06:29:48 danielk1977 Exp $ +** $Id: expr.c,v 1.246 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1149,7 +1149,7 @@ static int nameResolverStep(void *pArg, Expr *pExpr){ int nId; /* Number of characters in function name */ const char *zId; /* The function name. */ FuncDef *pDef; /* Information about the function */ - int enc = pParse->db->enc; /* The database encoding */ + int enc = ENC(pParse->db); /* The database encoding */ zId = (char*)pExpr->token.z; nId = pExpr->token.n; @@ -1666,7 +1666,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){ const char *zId; int constMask = 0; int i; - u8 enc = pParse->db->enc; + u8 enc = ENC(pParse->db); CollSeq *pColl = 0; zId = (char*)pExpr->token.z; nId = pExpr->token.n; @@ -2233,7 +2233,7 @@ static int analyzeAggregate(void *pArg, Expr *pExpr){ if( i>=pAggInfo->nFunc ){ /* pExpr is original. Make a new entry in pAggInfo->aFunc[] */ - u8 enc = pParse->db->enc; + u8 enc = ENC(pParse->db); i = addAggInfoFunc(pAggInfo); if( i>=0 ){ pItem = &pAggInfo->aFunc[i]; diff --git a/src/func.c b/src/func.c index 4744518a8..7c16f70be 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.114 2006/01/06 21:52:50 drh Exp $ +** $Id: func.c,v 1.115 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -728,17 +728,17 @@ static void test_destructor( test_destructor_count_var++; assert( nArg==1 ); if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; - len = sqlite3ValueBytes(argv[0], db->enc); + len = sqlite3ValueBytes(argv[0], ENC(db)); zVal = sqliteMalloc(len+3); zVal[len] = 0; zVal[len-1] = 0; assert( zVal ); zVal++; - memcpy(zVal, sqlite3ValueText(argv[0], db->enc), len); - if( db->enc==SQLITE_UTF8 ){ + memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len); + if( ENC(db)==SQLITE_UTF8 ){ sqlite3_result_text(pCtx, zVal, -1, destructor); #ifndef SQLITE_OMIT_UTF16 - }else if( db->enc==SQLITE_UTF16LE ){ + }else if( ENC(db)==SQLITE_UTF16LE ){ sqlite3_result_text16le(pCtx, zVal, -1, destructor); }else{ sqlite3_result_text16be(pCtx, zVal, -1, destructor); diff --git a/src/main.c b/src/main.c index 236b103ff..b44590868 100644 --- a/src/main.c +++ b/src/main.c @@ -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.319 2006/01/09 06:29:49 danielk1977 Exp $ +** $Id: main.c,v 1.320 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -725,7 +725,6 @@ static int openDatabase( db->magic = SQLITE_MAGIC_BUSY; db->nDb = 2; db->aDb = db->aDbStatic; - db->enc = SQLITE_UTF8; db->autoCommit = 1; db->flags |= SQLITE_ShortColNames; sqlite3HashInit(&db->aFunc, SQLITE_HASH_STRING, 0); @@ -739,14 +738,14 @@ static int openDatabase( sqlite3HashInit(&db->aDb[i].aFKey, SQLITE_HASH_STRING, 1); } #endif - + /* Add the default collation sequence BINARY. BINARY works for both UTF-8 ** and UTF-16, so add a version for each to avoid any unnecessary ** conversions. The only error that can occur here is a malloc() failure. */ if( sqlite3_create_collation(db, "BINARY", SQLITE_UTF8, 0,binCollFunc) || sqlite3_create_collation(db, "BINARY", SQLITE_UTF16, 0,binCollFunc) || - (db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0))==0 + (db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0 ){ /* sqlite3_create_collation() is an external API. So the mallocFailed flag ** will have been cleared before returning. So set it explicitly here. @@ -778,6 +777,10 @@ static int openDatabase( db->aDb[1].pSchema = sqlite3SchemaGet(0); #endif + if( db->aDb[0].pSchema ){ + ENC(db) = SQLITE_UTF8; + } + /* The default safety_level for the main database is 'full'; for the temp ** database it is 'NONE'. This matches the pager layer defaults. */ diff --git a/src/pragma.c b/src/pragma.c index ac08d2ff1..ff694146d 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.110 2006/01/08 18:10:18 drh Exp $ +** $Id: pragma.c,v 1.111 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -287,8 +287,8 @@ void sqlite3Pragma( sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3); sqlite3VdbeAddOp(v, OP_Negative, 0, 0); sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2); - pDb->cache_size = size; - sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size); + pDb->pSchema->cache_size = size; + sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); } }else @@ -349,12 +349,12 @@ void sqlite3Pragma( if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ if( sqlite3ReadSchema(pParse) ) goto pragma_out; if( !zRight ){ - returnSingleInt(pParse, "cache_size", pDb->cache_size); + returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); }else{ int size = atoi(zRight); if( size<0 ) size = -size; - pDb->cache_size = size; - sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size); + pDb->pSchema->cache_size = size; + sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); } }else @@ -797,7 +797,7 @@ void sqlite3Pragma( sqlite3VdbeSetColName(v, 0, "encoding", P3_STATIC); sqlite3VdbeAddOp(v, OP_String8, 0, 0); for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ - if( pEnc->enc==pParse->db->enc ){ + if( pEnc->enc==ENC(pParse->db) ){ sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC); break; } @@ -812,7 +812,7 @@ void sqlite3Pragma( if( !(pParse->db->flags&SQLITE_Initialized) ){ for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ - pParse->db->enc = pEnc->enc; + ENC(pParse->db) = pEnc->enc; break; } } diff --git a/src/prepare.c b/src/prepare.c index 0b24596d2..4efdf1fec 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -13,7 +13,7 @@ ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.16 2006/01/09 06:29:49 danielk1977 Exp $ +** $Id: prepare.c,v 1.17 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -155,21 +155,26 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ assert( iDb>=0 && iDb<db->nDb ); + assert( db->aDb[iDb].pSchema ); +#if 0 if( 0==db->aDb[iDb].pSchema ){ - Schema *pS = sqlite3BtreeSchema(db->aDb[iDb].pBt, sizeof(Schema), - sqlite3SchemaFree); + 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; - }else{ - sqlite3HashInit(&pS->tblHash, SQLITE_HASH_STRING, 0); - sqlite3HashInit(&pS->idxHash, SQLITE_HASH_STRING, 0); - sqlite3HashInit(&pS->trigHash, SQLITE_HASH_STRING, 0); - sqlite3HashInit(&pS->aFKey, SQLITE_HASH_STRING, 1); } } +#endif /* zMasterSchema and zInitScript are set to point at the master schema ** and initialisation script appropriate for the database being @@ -255,12 +260,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ */ if( meta[4] ){ /* text encoding */ if( iDb==0 ){ - /* If opening the main database, set db->enc. */ - db->enc = (u8)meta[4]; - db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0); + /* If opening the main database, set ENC(db). */ + ENC(db) = (u8)meta[4]; + db->pDfltColl = sqlite3FindCollSeq(db, ENC(db), "BINARY", 6, 0); }else{ - /* If opening an attached database, the encoding much match db->enc */ - if( meta[4]!=db->enc ){ + /* If opening an attached database, the encoding much match ENC(db) */ + if( meta[4]!=ENC(db) ){ sqlite3BtreeCloseCursor(curMain); sqlite3SetString(pzErrMsg, "attached databases must use the same" " text encoding as main database", (char*)0); @@ -268,11 +273,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ } } } + pDb->pSchema->enc = ENC(db); size = meta[2]; if( size==0 ){ size = MAX_PAGES; } - pDb->cache_size = size; - sqlite3BtreeSetCacheSize(pDb->pBt, pDb->cache_size); + pDb->pSchema->cache_size = size; + sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); /* ** file_format==1 Version 3.0.0. diff --git a/src/select.c b/src/select.c index 1f42d6423..0b401b392 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.290 2006/01/09 06:29:49 danielk1977 Exp $ +** $Id: select.c,v 1.291 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -650,7 +650,7 @@ static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){ if( pInfo ){ pInfo->aSortOrder = (u8*)&pInfo->aColl[nExpr]; pInfo->nField = nExpr; - pInfo->enc = db->enc; + pInfo->enc = ENC(db); for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){ CollSeq *pColl; pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr); @@ -1828,7 +1828,7 @@ static int multiSelect( goto multi_select_end; } - pKeyInfo->enc = pParse->db->enc; + pKeyInfo->enc = ENC(pParse->db); pKeyInfo->nField = nCol; for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){ @@ -2302,6 +2302,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){ ** or last entry in the main table. */ iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); + assert( iDb>=0 || pTab->isTransient ); sqlite3CodeVerifySchema(pParse, iDb); sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); base = pSrc->a[0].iCursor; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 4ac590b94..a24ad3352 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.455 2006/01/09 09:59:49 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.456 2006/01/09 16:12:05 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -382,7 +382,6 @@ struct Db { Btree *pBt; /* The B*Tree structure for this database file */ u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ u8 safety_level; /* How aggressive at synching data to disk */ - int cache_size; /* Number of pages to use in the cache */ void *pAux; /* Auxiliary data. Usually NULL */ void (*xFreeAux)(void*); /* Routine to free pAux */ Schema *pSchema; /* Pointer to database schema (possibly shared) */ @@ -400,6 +399,8 @@ struct Schema { Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ u8 file_format; /* Schema format version for this file */ u16 flags; /* Flags associated with this schema */ + int cache_size; /* Number of pages to use in the cache */ + u8 enc; /* Text encoding used by this database */ }; /* @@ -457,7 +458,6 @@ struct sqlite3 { Db *aDb; /* All backends */ int flags; /* Miscellanous flags. See below */ int errCode; /* Most recent error code (SQLITE_*) */ - u8 enc; /* Text encoding for this database. */ u8 autoCommit; /* The auto-commit flag. */ u8 temp_store; /* 1: file 2: memory 0: default */ int nTable; /* Number of tables in the database */ @@ -513,6 +513,8 @@ struct sqlite3 { #endif }; +#define ENC(db) ((db)->aDb[0].pSchema->enc) + /* ** Possible values for the sqlite.flags and or Db.flags fields. ** diff --git a/src/test1.c b/src/test1.c index 98b780282..6e54789a9 100644 --- a/src/test1.c +++ b/src/test1.c @@ -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.185 2006/01/09 09:59:49 danielk1977 Exp $ +** $Id: test1.c,v 1.186 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -1389,7 +1389,7 @@ static void test_collate_needed_cb( int eTextRep, const void *pName ){ - int enc = db->enc; + int enc = ENC(db); int i; char *z; for(z = (char*)pName, i=0; *z || z[1]; z++){ @@ -1397,7 +1397,7 @@ static void test_collate_needed_cb( } zNeededCollation[i] = 0; sqlite3_create_collation( - db, "test_collate", db->enc, (void *)enc, test_collate_func); + db, "test_collate", ENC(db), (void *)enc, test_collate_func); } /* diff --git a/src/update.c b/src/update.c index ff10b95e8..3c8cb61a8 100644 --- a/src/update.c +++ b/src/update.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.117 2006/01/09 06:29:49 danielk1977 Exp $ +** $Id: update.c,v 1.118 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -44,7 +44,7 @@ void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){ if( pTab && !pTab->pSelect ){ sqlite3_value *pValue; - u8 enc = sqlite3VdbeDb(v)->enc; + u8 enc = ENC(sqlite3VdbeDb(v)); Column *pCol = &pTab->aCol[i]; sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue); if( pValue ){ diff --git a/src/vdbe.c b/src/vdbe.c index 8de4b1308..10873bc39 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -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.519 2006/01/09 06:29:49 danielk1977 Exp $ +** $Id: vdbe.c,v 1.520 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -639,7 +639,7 @@ case OP_Real: { /* same as TK_FLOAT, */ pTos->enc = SQLITE_UTF8; pTos->r = sqlite3VdbeRealValue(pTos); pTos->flags |= MEM_Real; - sqlite3VdbeChangeEncoding(pTos, db->enc); + sqlite3VdbeChangeEncoding(pTos, ENC(db)); break; } @@ -655,10 +655,10 @@ case OP_String8: { /* same as TK_STRING */ pOp->p1 = strlen(pOp->p3); #ifndef SQLITE_OMIT_UTF16 - if( db->enc!=SQLITE_UTF8 ){ + if( ENC(db)!=SQLITE_UTF8 ){ pTos++; sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC); - if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, db->enc) ) goto no_mem; + if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, ENC(db)) ) goto no_mem; if( SQLITE_OK!=sqlite3VdbeMemDynamicify(pTos) ) goto no_mem; pTos->flags &= ~(MEM_Dyn); pTos->flags |= MEM_Static; @@ -684,7 +684,7 @@ case OP_String: { pTos->flags = MEM_Str|MEM_Static|MEM_Term; pTos->z = pOp->p3; pTos->n = pOp->p1; - pTos->enc = db->enc; + pTos->enc = ENC(db); break; } @@ -888,7 +888,7 @@ case OP_Callback: { /* no-push */ */ for(; pMem<=pTos; pMem++ ){ sqlite3VdbeMemNulTerminate(pMem); - storeTypeInfo(pMem, db->enc); + storeTypeInfo(pMem, ENC(db)); } /* Set up the statement structure so that it will pop the current @@ -929,7 +929,7 @@ case OP_Concat: { /* same as TK_CONCAT */ nByte = -1; break; } - Stringify(pTerm, db->enc); + Stringify(pTerm, ENC(db)); nByte += pTerm->n; } @@ -968,7 +968,7 @@ case OP_Concat: { /* same as TK_CONCAT */ pTos->n = j; pTos->flags = MEM_Str|MEM_Dyn|MEM_Term; pTos->xDel = 0; - pTos->enc = db->enc; + pTos->enc = ENC(db); pTos->z = zNew; } break; @@ -1142,7 +1142,7 @@ case OP_Function: { pArg = &pTos[1-n]; for(i=0; i<n; i++, pArg++){ apVal[i] = pArg; - storeTypeInfo(pArg, db->enc); + storeTypeInfo(pArg, ENC(db)); } assert( pOp->p3type==P3_FUNCDEF || pOp->p3type==P3_VDBEFUNC ); @@ -1180,7 +1180,7 @@ case OP_Function: { } /* Copy the result of the function to the top of the stack */ - sqlite3VdbeChangeEncoding(&ctx.s, db->enc); + sqlite3VdbeChangeEncoding(&ctx.s, ENC(db)); pTos++; pTos->flags = 0; sqlite3VdbeMemMove(pTos, &ctx.s); @@ -1191,7 +1191,7 @@ case OP_Function: { sqlite3SetString(&p->zErrMsg, "user function error", (char*)0); }else{ sqlite3SetString(&p->zErrMsg, sqlite3_value_text(pTos), (char*)0); - sqlite3VdbeChangeEncoding(pTos, db->enc); + sqlite3VdbeChangeEncoding(pTos, ENC(db)); } rc = SQLITE_ERROR; } @@ -1284,7 +1284,7 @@ case OP_AddImm: { /* no-push */ case OP_ForceInt: { /* no-push */ i64 v; assert( pTos>=p->aStack ); - applyAffinity(pTos, SQLITE_AFF_NUMERIC, db->enc); + applyAffinity(pTos, SQLITE_AFF_NUMERIC, ENC(db)); if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){ Release(pTos); pTos--; @@ -1319,7 +1319,7 @@ case OP_ForceInt: { /* no-push */ */ case OP_MustBeInt: { /* no-push */ assert( pTos>=p->aStack ); - applyAffinity(pTos, SQLITE_AFF_NUMERIC, db->enc); + applyAffinity(pTos, SQLITE_AFF_NUMERIC, ENC(db)); if( (pTos->flags & MEM_Int)==0 ){ if( pOp->p2==0 ){ rc = SQLITE_MISMATCH; @@ -1367,7 +1367,7 @@ case OP_ToText: { /* same as TK_TO_TEXT, no-push */ if( pTos->flags & MEM_Null ) break; assert( MEM_Str==(MEM_Blob>>3) ); pTos->flags |= (pTos->flags&MEM_Blob)>>3; - applyAffinity(pTos, SQLITE_AFF_TEXT, db->enc); + applyAffinity(pTos, SQLITE_AFF_TEXT, ENC(db)); assert( pTos->flags & MEM_Str ); pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob); break; @@ -1386,7 +1386,7 @@ case OP_ToBlob: { /* same as TK_TO_BLOB, no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; if( (pTos->flags & MEM_Blob)==0 ){ - applyAffinity(pTos, SQLITE_AFF_TEXT, db->enc); + applyAffinity(pTos, SQLITE_AFF_TEXT, ENC(db)); assert( pTos->flags & MEM_Str ); pTos->flags |= MEM_Blob; } @@ -1567,8 +1567,8 @@ case OP_Ge: { /* same as TK_GE, no-push */ affinity = pOp->p1 & 0xFF; if( affinity ){ - applyAffinity(pNos, affinity, db->enc); - applyAffinity(pTos, affinity, db->enc); + applyAffinity(pNos, affinity, ENC(db)); + applyAffinity(pTos, affinity, ENC(db)); } assert( pOp->p3type==P3_COLLSEQ || pOp->p3==0 ); @@ -2068,7 +2068,7 @@ case OP_Column: { zData = sMem.z; } sqlite3VdbeSerialGet((u8*)zData, aType[p2], pTos); - pTos->enc = db->enc; + pTos->enc = ENC(db); }else{ if( pOp->p3type==P3_MEM ){ sqlite3VdbeMemShallowCopy(pTos, (Mem *)(pOp->p3), MEM_Static); @@ -2192,7 +2192,7 @@ case OP_MakeRecord: { */ for(pRec=pData0; pRec<=pTos; pRec++){ if( zAffinity ){ - applyAffinity(pRec, zAffinity[pRec-pData0], db->enc); + applyAffinity(pRec, zAffinity[pRec-pData0], ENC(db)); } if( pRec->flags&MEM_Null ){ containsNull = 1; @@ -2582,7 +2582,7 @@ case OP_OpenWrite: { /* no-push */ if( pOp->p3type==P3_KEYINFO ){ pCur->pKeyInfo = (KeyInfo*)pOp->p3; pCur->pIncrKey = &pCur->pKeyInfo->incrKey; - pCur->pKeyInfo->enc = p->db->enc; + pCur->pKeyInfo->enc = ENC(p->db); }else{ pCur->pKeyInfo = 0; pCur->pIncrKey = &pCur->bogusIncrKey; @@ -2670,7 +2670,7 @@ case OP_OpenVirtual: { /* no-push */ rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, sqlite3VdbeRecordCompare, pOp->p3, &pCx->pCursor); pCx->pKeyInfo = (KeyInfo*)pOp->p3; - pCx->pKeyInfo->enc = p->db->enc; + pCx->pKeyInfo->enc = ENC(p->db); pCx->pIncrKey = &pCx->pKeyInfo->incrKey; } pCx->isTable = 0; @@ -2800,7 +2800,7 @@ case OP_MoveGt: { /* no-push */ pC->rowidIsValid = res==0; }else{ assert( pTos->flags & MEM_Blob ); - /* Stringify(pTos, db->enc); */ + /* Stringify(pTos, ENC(db)); */ rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res); if( rc!=SQLITE_OK ){ goto abort_due_to_error; @@ -2905,7 +2905,7 @@ case OP_Found: { /* no-push */ if( (pC = p->apCsr[i])->pCursor!=0 ){ int res, rx; assert( pC->isTable==0 ); - Stringify(pTos, db->enc); + Stringify(pTos, ENC(db)); rx = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res); alreadyExists = rx==SQLITE_OK && res==0; pC->deferredMoveto = 0; @@ -2972,7 +2972,7 @@ case OP_IsUnique: { /* no-push */ /* Make sure K is a string and make zKey point to K */ - Stringify(pNos, db->enc); + Stringify(pNos, ENC(db)); zKey = pNos->z; nKey = pNos->n; @@ -3802,7 +3802,7 @@ case OP_IdxGE: { /* no-push */ int res, rc; assert( pTos->flags & MEM_Blob ); /* Created using OP_Make*Key */ - Stringify(pTos, db->enc); + Stringify(pTos, ENC(db)); assert( pC->deferredMoveto==0 ); *pC->pIncrKey = pOp->p3!=0; assert( pOp->p3==0 || pOp->opcode!=OP_IdxGT ); @@ -4131,7 +4131,7 @@ case OP_IntegrityCk: { pTos->xDel = 0; } pTos->enc = SQLITE_UTF8; - sqlite3VdbeChangeEncoding(pTos, db->enc); + sqlite3VdbeChangeEncoding(pTos, ENC(db)); sqliteFree(aRoot); break; } @@ -4407,7 +4407,7 @@ case OP_AggStep: { /* no-push */ assert( apVal || n==0 ); for(i=0; i<n; i++, pRec++){ apVal[i] = pRec; - storeTypeInfo(pRec, db->enc); + storeTypeInfo(pRec, ENC(db)); } ctx.pFunc = (FuncDef*)pOp->p3; assert( pOp->p1>=0 && pOp->p1<p->nMem ); @@ -4552,7 +4552,7 @@ default: { #ifndef NDEBUG /* Sanity checking on the top element of the stack */ if( pTos>=p->aStack ){ - sqlite3VdbeMemSanity(pTos, db->enc); + sqlite3VdbeMemSanity(pTos, ENC(db)); } assert( pc>=-1 && pc<p->nOp ); #ifdef SQLITE_DEBUG diff --git a/src/vdbeapi.c b/src/vdbeapi.c index c18067dfa..462f38023 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -634,7 +634,7 @@ static int bindText( return rc; } if( rc==SQLITE_OK && encoding!=0 ){ - rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc); + rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db)); } return rc; } |