-C Tables\sand\sindices\suse\sthe\ssame\srecord\sformat.\s(CVS\s1482)
-D 2004-05-28T08:21:06
+C Allow\sCREATE\sTABLE\sand\sCREATE\sINDEX\son\sattached\sdatabases.\s(CVS\s1483)
+D 2004-05-28T11:37:27
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F src/auth.c 5c2f0bea4729c98c2be3b69d6b466fc51448fe79
F src/btree.c 6db76fbf63efd6008c5e6cb038ea40f94abffcf7
F src/btree.h b65140b5ae891f30d2a39e64b9f0343225553545
-F src/build.c 35cbeb439b49cca5eb5e8a1de010a5194f4523e8
+F src/build.c 7ae5b3efeb30c7bd9e74d0ef6f41c2aa43d9c586
F src/date.c 0eb922af5c5f5e2455f8dc2f98023ed3e04a857e
F src/delete.c 66c5ab98cbad7e6b315fc997bfe6c8080784a701
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
F src/os_win.h 5d41af24caaef6c13a2d8e2399caa1c57d45c84d
F src/pager.c 6ff6b906427d4824099140776cb8768f922f3dc5
F src/pager.h 78a00ac280899bcba1a89dc51585dcae6b7b3253
-F src/parse.y 63d39b6fe17d0c2c2c1f691e75a119a71d25439a
+F src/parse.y 1ab0393a97a17fa528b6762e14912d6ed982a28a
F src/pragma.c f2b05b087a5764802296a28d7abdd75728beedee
F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
F src/select.c 26f726b398af8708c81178acc9c68d64e78e6f5e
F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f
F src/sqlite.h.in edc6408c7f53c2104f781a76b926036e17018ec9
-F src/sqliteInt.h 7978f406b41819f37fb6fb1be64115a2e7a28ab5
+F src/sqliteInt.h a52ac00d36fd231068c92df169474c473a5b4a61
F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2
F src/tclsqlite.c 877d0b96013a25b03ed6bd2d32917c42e84403bc
F src/test1.c 32934478366531503d634968db414df17cb38238
F src/test4.c 34848a9fd31aa65857b20a8bfc03aff77d8c3426
F src/test5.c 9a1f15133f6955f067c5246e564723b5f23ff221
F src/tokenize.c 50a87c7414de54a008427c9fed22e4e86efb6844
-F src/trigger.c 11afe9abfba13a2ba142944c797c952e162d117f
+F src/trigger.c 9ab75040aec65b593b54a7c1d4546f2f9ca058ef
F src/update.c 96461bcf4e946697e83c09c77c7e61b545a2f66e
F src/utf.c 59b5c8f06a4384a9f64933d6c57a2de02ce3673b
-F src/util.c d299404febd509556e720fbecadd880756b0f899
+F src/util.c 79a813dfc81329c5a1c5c9f7f40fbd4c570a7c75
F src/vacuum.c 8734f89742f246abd91dbd3e087fc153bddbfbad
-F src/vdbe.c c661752ea19a8b5a041d8c4f234e1524f6b3250e
+F src/vdbe.c 3b208964add3da0c35c41955a95e6aa44ce75850
F src/vdbe.h e73f890e0f2a6c42b183d7d6937947930fe4fdeb
F src/vdbeInt.h c2bcd6e5a6e6a3753e4c5a368629c3a625719bfc
F src/vdbeapi.c b0bb1f98c899ba00c8a5cbca612c2a28a1bb79de
-F src/vdbeaux.c 75428f01c80382b5e2c91ba424c2f73db7645cbc
+F src/vdbeaux.c 7a0dd0fb224285e8c5f0b2edf68a10b29fd512a8
F src/vdbemem.c c97c145ff6d9fc5b4236704c04a65849117e6214
F src/where.c efe5d25fe18cd7381722457898cd863e84097a0c
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
F test/attach.test cb9b884344e6cfa5e165965d5b1adea679a24c83
F test/attach2.test 5472d442bb2ef1ee587e0ae7472bb68b52509a38
+F test/attach3.test 2cdfb3933e89a2336f68396f7505aa8dfcb88e9c
F test/auth.test 95809b8f6a9bec18b94d28cafd03fe27d2f8a9e9
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
F test/quick.test 8800cd2f6b45ce2cafadb0e3d5161688c61c946a
F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
F test/rowid.test 863e6e75878cccf03d166fe52023f20e09508683
-F test/select1.test 3bfcccd2eadcddbb07f1f5da6550aee8484ea4fb
-F test/select2.test a7226dc9de4ae713943a408bb8f9d3de46ee8015
+F test/select1.test 2f161f9cdf9fb577336bc8c930edade538567123
+F test/select2.test 91a2225926039b0d1687840735c284dbbf89f0bc
F test/select3.test f8ff60d98c7b4898f5e7326f0c5929ba56f5d047
F test/select4.test 86e72fc3b07de4fe11439aa419e37db3c49467e2
F test/select5.test 3f3f0f31e674fa61f8a3bdb6af1517dfae674081
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P ebd564d10b0ecd7ff15cbd6cd2b979c9f767476c
-R b3ce60af64a3cb61111b582624bafa84
-U drh
-Z 4321dd90c98a1981140d1a57a35baa0c
+P 1b15b32bdbccae555243e67aa011139c50dc2fb3
+R c5dc6cd70bfe11dc9fe64e163f737f43
+U danielk1977
+Z d391601bb46c037bdbb5671f03408a15
** ROLLBACK
** PRAGMA
**
-** $Id: build.c,v 1.193 2004/05/22 08:09:11 danielk1977 Exp $
+** $Id: build.c,v 1.194 2004/05/28 11:37:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
}
/*
-** Generate code to open the appropriate master table. The table
-** opened will be SQLITE_MASTER for persistent tables and
-** SQLITE_TEMP_MASTER for temporary tables. The table is opened
-** on cursor 0.
+** Open the sqlite_master table stored in database number iDb for
+** writing. The table is opened using cursor 0.
*/
-void sqlite3OpenMasterTable(Vdbe *v, int isTemp){
- sqlite3VdbeAddOp(v, OP_Integer, isTemp, 0);
+void sqlite3OpenMasterTable(Vdbe *v, int iDb){
+ sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenWrite, 0, MASTER_ROOT);
sqlite3VdbeAddOp(v, OP_SetNumColumns, 0, 5); /* sqlite_master has 5 columns */
}
+/*
+** The token *pName contains the name of a database (either "main" or
+** "temp" or the name of an attached db). This routine returns the
+** index of the named database in db->aDb[], or -1 if the named db
+** does not exist.
+*/
+int findDb(sqlite3 *db, Token *pName){
+ int i;
+ for(i=0; i<db->nDb; i++){
+ if( pName->n==strlen(db->aDb[i].zName) &&
+ 0==sqlite3StrNICmp(db->aDb[i].zName, pName->z, pName->n) ){
+ return i;
+ }
+ }
+ return -1;
+}
+
+static int resolveSchemaName(
+ Parse *pParse,
+ Token *pName1,
+ Token *pName2,
+ Token **pUnqual
+){
+ int iDb;
+ sqlite3 *db = pParse->db;
+
+ if( pName2 && pName2->n>0 ){
+ assert( !db->init.busy );
+ *pUnqual = pName2;
+ iDb = findDb(db, pName1);
+ if( iDb<0 ){
+ sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
+ pParse->nErr++;
+ return -1;
+ }
+ }else{
+ assert( db->init.iDb==0 || db->init.busy );
+ iDb = db->init.iDb;
+ *pUnqual = pName1;
+ }
+ return iDb;
+}
+
/*
** Begin constructing a new table representation in memory. This is
** the first of several action routines that get called in response
void sqlite3StartTable(
Parse *pParse, /* Parser context */
Token *pStart, /* The "CREATE" token */
- Token *pName, /* Name of table or view to create */
+ Token *pName1, /* First part of the name of the table or view */
+ Token *pName2, /* Second part of the name of the table or view */
int isTemp, /* True if this is a TEMP table */
int isView /* True if this is a VIEW */
){
char *zName;
sqlite *db = pParse->db;
Vdbe *v;
- int iDb;
+ int iDb; /* Database number to create the table in */
+ Token *pName; /* Unqualified name of the table to create */
+
+ /* The table or view name to create is passed to this routine via tokens
+ ** pName1 and pName2. If the table name was fully qualified, for example:
+ **
+ ** CREATE TABLE xxx.yyy (...);
+ **
+ ** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if
+ ** the table name is not fully qualified, i.e.:
+ **
+ ** CREATE TABLE yyy(...);
+ **
+ ** Then pName1 is set to "yyy" and pName2 is "".
+ **
+ ** The call below sets the pName pointer to point at the token (pName1 or
+ ** pName2) that stores the unqualified table name. The variable iDb is
+ ** set to the index of the database that the table or view is to be
+ ** created in.
+ */
+ iDb = resolveSchemaName(pParse, pName1, pName2, &pName);
+ if( iDb<0 ) return;
+ if( isTemp && iDb>1 ){
+ /* If creating a temp table, the name may not be qualified */
+ sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
+ pParse->nErr++;
+ return;
+ }
+ if( isTemp ) iDb = 1;
- pParse->sFirstToken = *pStart;
+ pParse->sNameToken = *pName;
zName = sqlite3TableNameFromToken(pName);
if( zName==0 ) return;
if( db->init.iDb==1 ) isTemp = 1;
assert( (isTemp & 1)==isTemp );
{
int code;
- char *zDb = isTemp ? "temp" : "main";
+ char *zDb = db->aDb[iDb].zName;
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
sqliteFree(zName);
return;
}
}
#endif
-
/* Before trying to create a temporary table, make sure the Btree for
** holding temporary tables is open.
** an existing temporary table, that is not an error.
*/
pTable = sqlite3FindTable(db, zName, 0);
- iDb = isTemp ? 1 : db->init.iDb;
if( pTable!=0 && (pTable->iDb==iDb || !db->init.busy) ){
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
sqliteFree(zName);
** now.
*/
if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
- sqlite3BeginWriteOperation(pParse, 0, isTemp);
+ sqlite3BeginWriteOperation(pParse, 0, iDb);
if( !isTemp ){
+ /* Every time a new table is created the file-format
+ ** and encoding meta-values are set in the database, in
+ ** case this is the first table created.
+ */
sqlite3VdbeAddOp(v, OP_Integer, db->file_format, 0);
- sqlite3VdbeAddOp(v, OP_SetCookie, 0, 1);
+ sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1);
sqlite3VdbeAddOp(v, OP_Integer, db->enc, 0);
- sqlite3VdbeAddOp(v, OP_SetCookie, 0, 4);
+ sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 4);
}
- sqlite3OpenMasterTable(v, isTemp);
+ sqlite3OpenMasterTable(v, iDb);
sqlite3VdbeAddOp(v, OP_NewRecno, 0, 0);
sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
sqlite3VdbeAddOp(v, OP_String, 0, 0);
pTab->iPKey = iCol;
pTab->keyConf = onError;
}else{
- sqlite3CreateIndex(pParse, 0, 0, pList, onError, 0, 0);
+ sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0, 0);
pList = 0;
}
** and the probability of hitting the same cookie value is only
** 1 chance in 2^32. So we're safe enough.
*/
-void sqlite3ChangeCookie(sqlite *db, Vdbe *v){
+void sqlite3ChangeCookie(sqlite *db, Vdbe *v, int iDb){
if( db->next_cookie==db->aDb[0].schema_cookie ){
unsigned char r;
sqlite3Randomness(1, &r);
db->next_cookie = db->aDb[0].schema_cookie + r + 1;
db->flags |= SQLITE_InternChanges;
sqlite3VdbeAddOp(v, OP_Integer, db->next_cookie, 0);
- sqlite3VdbeAddOp(v, OP_SetCookie, 0, 0);
+ sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 0);
}
}
sqlite3VdbeOp3(v, OP_String, 0, 0, p->zName, 0);
sqlite3VdbeOp3(v, OP_String, 0, 0, p->zName, 0);
sqlite3VdbeAddOp(v, OP_Dup, 4, 0);
- sqlite3VdbeAddOp(v, OP_String, 0, 0);
if( pSelect ){
char *z = createTableStmt(p);
n = z ? strlen(z) : 0;
+ sqlite3VdbeAddOp(v, OP_String, 0, 0);
sqlite3VdbeChangeP3(v, -1, z, n);
sqliteFree(z);
}else{
+ if( p->pSelect ){
+ sqlite3VdbeOp3(v, OP_String, 0, 0, "CREATE VIEW ", P3_STATIC);
+ }else{
+ sqlite3VdbeOp3(v, OP_String, 0, 0, "CREATE TABLE ", P3_STATIC);
+ }
assert( pEnd!=0 );
- n = Addr(pEnd->z) - Addr(pParse->sFirstToken.z) + 1;
- sqlite3VdbeChangeP3(v, -1, pParse->sFirstToken.z, n);
+ n = Addr(pEnd->z) - Addr(pParse->sNameToken.z) + 1;
+ sqlite3VdbeAddOp(v, OP_String, 0, 0);
+ sqlite3VdbeChangeP3(v, -1, pParse->sNameToken.z, n);
+ sqlite3VdbeAddOp(v, OP_Concat, 2, 0);
}
sqlite3VdbeOp3(v, OP_MakeRecord, 5, 0, "tttit", P3_STATIC);
sqlite3VdbeAddOp(v, OP_PutIntKey, 0, 0);
if( !p->iDb ){
- sqlite3ChangeCookie(db, v);
+ sqlite3ChangeCookie(db, v, p->iDb);
}
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
if( pSelect ){
Token sEnd;
DbFixer sFix;
- sqlite3StartTable(pParse, pBegin, pName, isTemp, 1);
+ sqlite3StartTable(pParse, pBegin, pName, 0, isTemp, 1);
p = pParse->pNewTable;
if( p==0 || pParse->nErr ){
sqlite3SelectDelete(pSelect);
sqlite3VdbeChangeP3(v, base+1, pTable->zName, 0);
}
- if( pTable->iDb==0 ){
- sqlite3ChangeCookie(db, v);
+ if( pTable->iDb!=1 ){ /* Temp database has no schema cookie */
+ sqlite3ChangeCookie(db, v, pTable->iDb);
}
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
if( !isView ){
*/
void sqlite3CreateIndex(
Parse *pParse, /* All information about this parse */
- Token *pName, /* Name of the index. May be NULL */
- SrcList *pTable, /* Name of the table to index. Use pParse->pNewTable if 0 */
+ Token *pName1, /* First part of index name. May be NULL */
+ Token *pName2, /* Second part of index name. May be NULL */
+ Token *pTblName, /* Name of the table to index. Use pParse->pNewTable if 0 */
IdList *pList, /* A list of columns to be indexed */
int onError, /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
Token *pStart, /* The CREATE token that begins a CREATE TABLE statement */
Token *pEnd /* The ")" that closes the CREATE INDEX statement */
){
- Table *pTab; /* Table to be indexed */
+ Table *pTab = 0; /* Table to be indexed */
Index *pIndex; /* The index to be created */
char *zName = 0;
int i, j;
int isTemp; /* True for a temporary index */
sqlite *db = pParse->db;
+ int iDb; /* Index of the database that is being written */
+ Token *pName = 0; /* Unqualified name of the index to create */
+
+/*
if( pParse->nErr || sqlite3_malloc_failed ) goto exit_create_index;
if( db->init.busy
&& sqlite3FixInit(&sFix, pParse, db->init.iDb, "index", pName)
){
goto exit_create_index;
}
+*/
/*
** Find the table that is to be indexed. Return early if not found.
*/
- if( pTable!=0 ){
- assert( pName!=0 );
- assert( pTable->nSrc==1 );
- pTab = sqlite3SrcListLookup(pParse, pTable);
+ if( pTblName!=0 ){
+ char *zTblName;
+
+ /* Use the two-part index name to determine the database
+ ** to search for the table. If no database name is specified,
+ ** iDb is set to 0. In this case search both the temp and main
+ ** databases for the named table.
+ */
+ assert( pName1 && pName2 );
+ iDb = resolveSchemaName(pParse, pName1, pName2, &pName);
+ if( iDb<0 ) goto exit_create_index;
+
+ /* Now search for the table in the database iDb. If iDb is
+ ** zero, then search both the "main" and "temp" databases.
+ */
+ zTblName = sqlite3TableNameFromToken(pTblName);
+ if( !zTblName ){
+ pParse->nErr++;
+ pParse->rc = SQLITE_NOMEM;
+ goto exit_create_index;
+ }
+ assert( pName1!=0 );
+ if( iDb==0 ){
+ pTab = sqlite3FindTable(db, zTblName, "temp");
+ }
+ if( !pTab ){
+ pTab = sqlite3LocateTable(pParse, zTblName, db->aDb[iDb].zName);
+ }
+ sqliteFree( zTblName );
+ if( !pTab ) goto exit_create_index;
+ iDb = pTab->iDb;
}else{
assert( pName==0 );
pTab = pParse->pNewTable;
+ iDb = pTab->iDb;
}
+
if( pTab==0 || pParse->nErr ) goto exit_create_index;
if( pTab->readOnly ){
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
goto exit_create_index;
}
+/*
if( pTab->iDb>=2 && db->init.busy==0 ){
sqlite3ErrorMsg(pParse, "table %s may not have indices added", pTab->zName);
goto exit_create_index;
}
+*/
if( pTab->pSelect ){
sqlite3ErrorMsg(pParse, "views may not be indexed");
goto exit_create_index;
#ifndef SQLITE_OMIT_AUTHORIZATION
{
const char *zDb = db->aDb[pTab->iDb].zName;
-
- assert( pTab->iDb==db->init.iDb || isTemp );
if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
goto exit_create_index;
}
pIndex->nColumn = pList->nId;
pIndex->onError = onError;
pIndex->autoIndex = pName==0;
- pIndex->iDb = isTemp ? 1 : db->init.iDb;
+ pIndex->iDb = iDb;
/* Scan the names of the columns of the table to be indexed and
** load the column indices into the Index structure. Report an error
** "sqlite_master" table on the disk. So do not write to the disk
** again. Extract the table number from the db->init.newTnum field.
*/
- if( db->init.busy && pTable!=0 ){
+ if( db->init.busy && pTblName!=0 ){
pIndex->tnum = db->init.newTnum;
}
** the latter case the index already exists on disk, which is why
** we don't want to recreate it.
**
- ** If pTable==0 it means this index is generated as a primary key
+ ** If pTblName==0 it means this index is generated as a primary key
** or UNIQUE constraint of a CREATE TABLE statement. Since the table
** has just been created, it contains no data and the index initialization
** step can be skipped.
Vdbe *v;
int lbl1, lbl2;
int i;
- int addr;
v = sqlite3GetVdbe(pParse);
if( v==0 ) goto exit_create_index;
- if( pTable!=0 ){
- sqlite3BeginWriteOperation(pParse, 0, isTemp);
- sqlite3OpenMasterTable(v, isTemp);
+ if( pTblName!=0 ){
+ sqlite3BeginWriteOperation(pParse, 0, iDb);
+ sqlite3OpenMasterTable(v, iDb);
}
sqlite3VdbeAddOp(v, OP_NewRecno, 0, 0);
sqlite3VdbeOp3(v, OP_String, 0, 0, "index", P3_STATIC);
sqlite3VdbeOp3(v, OP_String, 0, 0, pIndex->zName, 0);
sqlite3VdbeOp3(v, OP_String, 0, 0, pTab->zName, 0);
- sqlite3VdbeOp3(v, OP_CreateIndex, 0, isTemp,(char*)&pIndex->tnum,P3_POINTER);
+ sqlite3VdbeOp3(v, OP_CreateIndex, 0, iDb,(char*)&pIndex->tnum,P3_POINTER);
pIndex->tnum = 0;
- if( pTable ){
+ if( pTblName ){
sqlite3VdbeCode(v,
OP_Dup, 0, 0,
- OP_Integer, isTemp, 0,
+ OP_Integer, iDb, 0,
0);
sqlite3VdbeOp3(v, OP_OpenWrite, 1, 0,
(char*)&pIndex->keyInfo, P3_KEYINFO);
}
- addr = sqlite3VdbeAddOp(v, OP_String, 0, 0);
+ sqlite3VdbeAddOp(v, OP_String, 0, 0);
if( pStart && pEnd ){
- n = Addr(pEnd->z) - Addr(pStart->z) + 1;
- sqlite3VdbeChangeP3(v, addr, pStart->z, n);
+ sqlite3VdbeChangeP3(v, -1, "CREATE INDEX ", n);
+ sqlite3VdbeAddOp(v, OP_String, 0, 0);
+ n = Addr(pEnd->z) - Addr(pName->z) + 1;
+ sqlite3VdbeChangeP3(v, -1, pName->z, n);
+ sqlite3VdbeAddOp(v, OP_Concat, 2, 0);
}
sqlite3VdbeOp3(v, OP_MakeRecord, 5, 0, "tttit", P3_STATIC);
sqlite3VdbeAddOp(v, OP_PutIntKey, 0, 0);
- if( pTable ){
+ if( pTblName ){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenRead, 2, pTab->tnum);
/* VdbeComment((v, "%s", pTab->zName)); */
sqlite3VdbeAddOp(v, OP_Close, 2, 0);
sqlite3VdbeAddOp(v, OP_Close, 1, 0);
}
- if( pTable!=0 ){
+ if( pTblName!=0 ){
if( !isTemp ){
- sqlite3ChangeCookie(db, v);
+ sqlite3ChangeCookie(db, v, iDb);
}
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
sqlite3EndWriteOperation(pParse);
/* Clean up before exiting */
exit_create_index:
sqlite3IdListDelete(pList);
- sqlite3SrcListDelete(pTable);
+ /* sqlite3SrcListDelete(pTable); */
sqliteFree(zName);
return;
}
sqlite3OpenMasterTable(v, pIndex->iDb);
base = sqlite3VdbeAddOpList(v, ArraySize(dropIndex), dropIndex);
sqlite3VdbeChangeP3(v, base+1, pIndex->zName, 0);
- if( pIndex->iDb==0 ){
- sqlite3ChangeCookie(db, v);
+ if( pIndex->iDb!=1 ){
+ sqlite3ChangeCookie(db, v, pIndex->iDb);
}
sqlite3VdbeAddOp(v, OP_Close, 0, 0);
sqlite3VdbeAddOp(v, OP_Destroy, pIndex->tnum, pIndex->iDb);