From 9cdb31d07ca927d41b63b8ff009b275fed351636 Mon Sep 17 00:00:00 2001 From: "vladimir%pobox.com" Date: Wed, 30 Mar 2005 21:49:20 +0000 Subject: [PATCH] Update to sqlite 3.2.1, r=me --- db/sqlite3/src/Makefile.in | 2 +- db/sqlite3/src/alter.c | 8 +- db/sqlite3/src/btree.c | 69 ++++--- db/sqlite3/src/build.c | 51 +++--- db/sqlite3/src/main.c | 29 +-- db/sqlite3/src/opcodes.h | 11 ++ db/sqlite3/src/pager.c | 18 +- db/sqlite3/src/parse.c | 360 ++++++++++++++++++------------------- db/sqlite3/src/pragma.c | 4 +- db/sqlite3/src/select.c | 9 +- db/sqlite3/src/sqlite.h.in | 14 ++ db/sqlite3/src/sqliteInt.h | 15 +- db/sqlite3/src/trigger.c | 4 +- db/sqlite3/src/vdbe.c | 234 +++++++++++++----------- db/sqlite3/src/vdbe.h | 4 +- db/sqlite3/src/vdbeInt.h | 1 + db/sqlite3/src/vdbeapi.c | 12 ++ db/sqlite3/src/vdbeaux.c | 102 ++++++++++- 18 files changed, 575 insertions(+), 372 deletions(-) diff --git a/db/sqlite3/src/Makefile.in b/db/sqlite3/src/Makefile.in index 1542e210306..51d55958641 100644 --- a/db/sqlite3/src/Makefile.in +++ b/db/sqlite3/src/Makefile.in @@ -48,7 +48,7 @@ LIBRARY_NAME = sqlite3_s MODULE_NAME = sqlite3 FORCE_STATIC_LIB = 1 -VERSION = 3.2.0 +VERSION = 3.2.1 EXPORTS = sqlite3.h diff --git a/db/sqlite3/src/alter.c b/db/sqlite3/src/alter.c index d20d91e22f3..be363872a2b 100644 --- a/db/sqlite3/src/alter.c +++ b/db/sqlite3/src/alter.c @@ -12,7 +12,7 @@ ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** -** $Id: alter.c,v 1.1 2005-03-22 23:10:06 vladimir%pobox.com Exp $ +** $Id: alter.c,v 1.2 2005-03-30 21:49:20 vladimir%pobox.com Exp $ */ #include "sqliteInt.h" #include @@ -449,7 +449,7 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ } sqlite3NestedParse(pParse, "UPDATE %Q.%s SET " - "sql = substr(sql,0,%d) || ', ' || %Q || substr(sql,%d,length(sql)) " + "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d,length(sql)) " "WHERE type = 'table' AND name = %Q", zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1, zTab @@ -521,7 +521,9 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ if( !pNew ) goto exit_begin_add_column; pParse->pNewTable = pNew; pNew->nCol = pTab->nCol; - nAlloc = ((pNew->nCol)/8)+8; + assert( pNew->nCol>0 ); + nAlloc = (((pNew->nCol-1)/8)*8)+8; + assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 ); pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc); pNew->zName = sqliteStrDup(pTab->zName); if( !pNew->aCol || !pNew->zName ){ diff --git a/db/sqlite3/src/btree.c b/db/sqlite3/src/btree.c index b2c34e533fa..a27568344d7 100644 --- a/db/sqlite3/src/btree.c +++ b/db/sqlite3/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.253 2005/03/21 04:04:02 danielk1977 Exp $ +** $Id: btree.c,v 1.256 2005/03/29 13:17:46 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -3757,7 +3757,8 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){ static int balance_nonroot(MemPage *pPage){ MemPage *pParent; /* The parent of pPage */ Btree *pBt; /* The whole database */ - int nCell = 0; /* Number of cells in aCell[] */ + int nCell = 0; /* Number of cells in apCell[] */ + int nMaxCells = 0; /* Allocated size of apCell, szCell, aFrom. */ int nOld; /* Number of pages in apOld[] */ int nNew; /* Number of pages in apNew[] */ int nDiv; /* Number of cells in apDiv[] */ @@ -3771,7 +3772,6 @@ static int balance_nonroot(MemPage *pPage){ int pageFlags; /* Value of pPage->aData[0] */ int subtotal; /* Subtotal of bytes in cells on one page */ int iSpace = 0; /* First unused byte of aSpace[] */ - int mxCellPerPage; /* Maximum number of cells in one page */ MemPage *apOld[NB]; /* pPage and up to two siblings */ Pgno pgnoOld[NB]; /* Page numbers for each page in apOld[] */ MemPage *apCopy[NB]; /* Private copies of apOld[] pages */ @@ -3781,7 +3781,7 @@ static int balance_nonroot(MemPage *pPage){ u8 *apDiv[NB]; /* Divider cells in pParent */ int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */ int szNew[NB+2]; /* Combined size of cells place on i-th page */ - u8 **apCell; /* All cells begin balanced */ + u8 **apCell = 0; /* All cells begin balanced */ int *szCell; /* Local size of all cells in apCell[] */ u8 *aCopy[NB]; /* Space for holding data of apCopy[] */ u8 *aSpace; /* Space to hold copies of dividers cells */ @@ -3825,31 +3825,6 @@ static int balance_nonroot(MemPage *pPage){ } #endif - /* - ** Allocate space for memory structures - */ - mxCellPerPage = MX_CELL(pBt); - apCell = sqliteMallocRaw( - (mxCellPerPage+2)*NB*(sizeof(u8*)+sizeof(int)) - + sizeof(MemPage)*NB - + pBt->psAligned*(5+NB) - + (ISAUTOVACUUM ? (mxCellPerPage+2)*NN*2 : 0) - ); - if( apCell==0 ){ - return SQLITE_NOMEM; - } - szCell = (int*)&apCell[(mxCellPerPage+2)*NB]; - aCopy[0] = (u8*)&szCell[(mxCellPerPage+2)*NB]; - for(i=1; ipsAligned+sizeof(MemPage)]; - } - aSpace = &aCopy[NB-1][pBt->psAligned+sizeof(MemPage)]; -#ifndef SQLITE_OMIT_AUTOVACUUM - if( pBt->autoVacuum ){ - aFrom = &aSpace[5*pBt->psAligned]; - } -#endif - /* ** Find the cell in the parent page whose left child points back ** to pPage. The "idx" variable is the index of that cell. If pPage @@ -3910,8 +3885,35 @@ static int balance_nonroot(MemPage *pPage){ apCopy[i] = 0; assert( i==nOld ); nOld++; + nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow; } + /* + ** Allocate space for memory structures + */ + apCell = sqliteMallocRaw( + nMaxCells*sizeof(u8*) /* apCell */ + + nMaxCells*sizeof(int) /* szCell */ + + sizeof(MemPage)*NB /* aCopy */ + + pBt->psAligned*(5+NB) /* aSpace */ + + (ISAUTOVACUUM ? nMaxCells : 0) /* aFrom */ + ); + if( apCell==0 ){ + rc = SQLITE_NOMEM; + goto balance_cleanup; + } + szCell = (int*)&apCell[nMaxCells]; + aCopy[0] = (u8*)&szCell[nMaxCells]; + for(i=1; ipsAligned+sizeof(MemPage)]; + } + aSpace = &aCopy[NB-1][pBt->psAligned+sizeof(MemPage)]; +#ifndef SQLITE_OMIT_AUTOVACUUM + if( pBt->autoVacuum ){ + aFrom = &aSpace[5*pBt->psAligned]; + } +#endif + /* ** Make copies of the content of pPage and its siblings into aOld[]. ** The rest of this function will use data from the copies rather @@ -3948,6 +3950,7 @@ static int balance_nonroot(MemPage *pPage){ MemPage *pOld = apCopy[i]; int limit = pOld->nCell+pOld->nOverflow; for(j=0; jusableSize - 12 + leafCorrection; for(subtotal=k=i=0; i usableSpace ){ szNew[k] = subtotal - szCell[i]; @@ -4051,6 +4056,8 @@ static int balance_nonroot(MemPage *pPage){ r = cntNew[i-1] - 1; d = r + 1 - leafData; + assert( dpgno==pgnoNew[i] ); assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]); assert( pNew->nCell>0 ); @@ -4160,6 +4168,7 @@ static int balance_nonroot(MemPage *pPage){ */ if( pBt->autoVacuum ){ for(k=j; kpgno!=pNew->pgno ){ rc = ptrmapPutOvfl(pNew, k-j); if( rc!=SQLITE_OK ){ @@ -4179,6 +4188,8 @@ static int balance_nonroot(MemPage *pPage){ u8 *pCell; u8 *pTemp; int sz; + + assert( jleaf ){ diff --git a/db/sqlite3/src/build.c b/db/sqlite3/src/build.c index c9339313f17..bff72c40c05 100644 --- a/db/sqlite3/src/build.c +++ b/db/sqlite3/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.316 2005/03/21 03:53:38 danielk1977 Exp $ +** $Id: build.c,v 1.318 2005/03/29 03:10:59 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -168,7 +168,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){ int i; assert( zName!=0 ); assert( (db->flags & SQLITE_Initialized) || db->init.busy ); - for(i=0; inDb; i++){ + for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; p = sqlite3HashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1); @@ -227,7 +227,7 @@ 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=0; inDb; i++){ + for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; p = sqlite3HashFind(&db->aDb[j].idxHash, zName, strlen(zName)+1); @@ -393,12 +393,14 @@ static void sqliteResetColumnNames(Table *pTable){ int i; Column *pCol; assert( pTable!=0 ); - for(i=0, pCol=pTable->aCol; inCol; i++, pCol++){ - sqliteFree(pCol->zName); - sqlite3ExprDelete(pCol->pDflt); - sqliteFree(pCol->zType); + if( (pCol = pTable->aCol)!=0 ){ + for(i=0; inCol; i++, pCol++){ + sqliteFree(pCol->zName); + sqlite3ExprDelete(pCol->pDflt); + sqliteFree(pCol->zType); + } + sqliteFree(pTable->aCol); } - sqliteFree(pTable->aCol); pTable->aCol = 0; pTable->nCol = 0; } @@ -535,7 +537,8 @@ static int findDb(sqlite3 *db, Token *pName){ if( zName ){ n = strlen(zName); for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){ - if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){ + if( (!OMIT_TEMPDB || i!=1 ) && n==strlen(pDb->zName) && + 0==sqlite3StrICmp(pDb->zName, zName) ){ break; } } @@ -654,12 +657,12 @@ void sqlite3StartTable( */ iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); if( iDb<0 ) return; - if( isTemp && iDb>1 ){ + if( !OMIT_TEMPDB && isTemp && iDb>1 ){ /* If creating a temp table, the name may not be qualified */ sqlite3ErrorMsg(pParse, "temporary table name must be unqualified"); return; } - if( isTemp ) iDb = 1; + if( !OMIT_TEMPDB && isTemp ) iDb = 1; pParse->sNameToken = *pName; zName = sqlite3NameFromToken(pName); @@ -677,13 +680,13 @@ void sqlite3StartTable( goto begin_table_error; } if( isView ){ - if( isTemp ){ + if( !OMIT_TEMPDB && isTemp ){ code = SQLITE_CREATE_TEMP_VIEW; }else{ code = SQLITE_CREATE_VIEW; } }else{ - if( isTemp ){ + if( !OMIT_TEMPDB && isTemp ){ code = SQLITE_CREATE_TEMP_TABLE; }else{ code = SQLITE_CREATE_TABLE; @@ -1374,7 +1377,7 @@ static char *createTableStmt(Table *p){ n += 35 + 6*p->nCol; zStmt = sqliteMallocRaw( n ); if( zStmt==0 ) return 0; - strcpy(zStmt, p->iDb==1 ? "CREATE TEMP TABLE " : "CREATE TABLE "); + strcpy(zStmt, !OMIT_TEMPDB&&p->iDb==1 ? "CREATE TEMP TABLE ":"CREATE TABLE "); k = strlen(zStmt); identPut(zStmt, &k, p->zName); zStmt[k++] = '('; @@ -1863,13 +1866,13 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView){ goto exit_drop_table; } if( isView ){ - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ code = SQLITE_DROP_TEMP_VIEW; }else{ code = SQLITE_DROP_VIEW; } }else{ - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ code = SQLITE_DROP_TEMP_TABLE; }else{ code = SQLITE_DROP_TABLE; @@ -2187,7 +2190,6 @@ void sqlite3CreateIndex( int i, j; Token nullId; /* Fake token for an empty ID list */ DbFixer sFix; /* For assigning database names to pTable */ - int isTemp; /* True for a temporary index */ sqlite3 *db = pParse->db; int iDb; /* Index of the database that is being written */ @@ -2208,6 +2210,7 @@ void sqlite3CreateIndex( iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName); if( iDb<0 ) goto exit_create_index; +#ifndef SQLITE_OMIT_TEMPDB /* If the index name was unqualified, check if the the table ** is a temp table. If so, set the database to 1. */ @@ -2215,6 +2218,7 @@ void sqlite3CreateIndex( if( pName2 && pName2->n==0 && pTab && pTab->iDb==1 ){ iDb = 1; } +#endif if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) @@ -2242,7 +2246,6 @@ void sqlite3CreateIndex( goto exit_create_index; } #endif - isTemp = pTab->iDb==1; /* ** Find the name of the index. Make sure there is not already another @@ -2292,12 +2295,12 @@ void sqlite3CreateIndex( */ #ifndef SQLITE_OMIT_AUTHORIZATION { - const char *zDb = db->aDb[pTab->iDb].zName; - if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){ + const char *zDb = db->aDb[iDb].zName; + if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){ goto exit_create_index; } i = SQLITE_CREATE_INDEX; - if( isTemp ) i = SQLITE_CREATE_TEMP_INDEX; + if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX; if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){ goto exit_create_index; } @@ -2560,7 +2563,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName){ if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){ goto exit_drop_index; } - if( pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX; + if( !OMIT_TEMPDB && pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX; if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){ goto exit_drop_index; } @@ -2868,7 +2871,7 @@ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ if( (pParse->cookieMask & mask)==0 ){ pParse->cookieMask |= mask; pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie; - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ sqlite3OpenTempDatabase(pParse); } } @@ -2901,7 +2904,7 @@ void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){ if( setStatement && pParse->nested==0 ){ sqlite3VdbeAddOp(v, OP_Statement, iDb, 0); } - if( iDb!=1 && pParse->db->aDb[1].pBt!=0 ){ + if( (OMIT_TEMPDB || iDb!=1) && pParse->db->aDb[1].pBt!=0 ){ sqlite3BeginWriteOperation(pParse, setStatement, 1); } } diff --git a/db/sqlite3/src/main.c b/db/sqlite3/src/main.c index dca52977c43..20335a01d3d 100644 --- a/db/sqlite3/src/main.c +++ b/db/sqlite3/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.283 2005/03/21 04:04:03 danielk1977 Exp $ +** $Id: main.c,v 1.284 2005/03/29 03:10:59 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -133,7 +133,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ int meta[10]; InitData initData; char const *zMasterSchema; - char const *zMasterName; + char const *zMasterName = SCHEMA_TABLE(iDb); /* ** The master database table has a structure like this @@ -147,6 +147,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ " sql text\n" ")" ; +#ifndef SQLITE_OMIT_TEMPDB static const char temp_master_schema[] = "CREATE TEMP TABLE sqlite_temp_master(\n" " type text,\n" @@ -156,6 +157,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ " sql text\n" ")" ; +#else + #define temp_master_schema 0 +#endif assert( iDb>=0 && iDbnDb ); @@ -163,13 +167,12 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ ** and initialisation script appropriate for the database being ** initialised. zMasterName is the name of the master table. */ - if( iDb==1 ){ + if( !OMIT_TEMPDB && iDb==1 ){ zMasterSchema = temp_master_schema; - zMasterName = TEMP_MASTER_NAME; }else{ zMasterSchema = master_schema; - zMasterName = MASTER_NAME; } + zMasterName = SCHEMA_TABLE(iDb); /* Construct the schema tables. */ sqlite3SafetyOff(db); @@ -195,7 +198,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){ /* Create a cursor to hold the database open */ if( db->aDb[iDb].pBt==0 ){ - if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded); + if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded); return SQLITE_OK; } rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain); @@ -351,12 +354,14 @@ int sqlite3Init(sqlite3 *db, char **pzErrMsg){ ** for the TEMP database. This is loaded last, as the TEMP database ** schema may contain references to objects in other databases. */ +#ifndef SQLITE_OMIT_TEMPDB if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){ rc = sqlite3InitOne(db, 1, pzErrMsg); if( rc ){ sqlite3ResetInternalSchema(db, 1); } } +#endif db->init.busy = 0; if( rc==SQLITE_OK ){ @@ -1205,13 +1210,17 @@ static int openDatabase( db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; } - db->aDb[0].zName = "main"; - db->aDb[1].zName = "temp"; - /* The default safety_level for the main database is 'full' for the temp - ** database it is 'NONE'. This matches the pager layer defaults. */ + /* The default safety_level for the main database is 'full'; for the temp + ** database it is 'NONE'. This matches the pager layer defaults. + */ + db->aDb[0].zName = "main"; db->aDb[0].safety_level = 3; +#ifndef SQLITE_OMIT_TEMPDB + db->aDb[1].zName = "temp"; db->aDb[1].safety_level = 1; +#endif + /* Register all built-in functions, but do not attempt to read the ** database schema yet. This is delayed until the first time the database diff --git a/db/sqlite3/src/opcodes.h b/db/sqlite3/src/opcodes.h index 8be3dc7ea17..69abb829815 100644 --- a/db/sqlite3/src/opcodes.h +++ b/db/sqlite3/src/opcodes.h @@ -133,3 +133,14 @@ #define OP_NotUsed_127 127 #define OP_NotUsed_128 128 #define OP_NotUsed_129 129 + +#define NOPUSH_MASK_0 65144 +#define NOPUSH_MASK_1 59007 +#define NOPUSH_MASK_2 63483 +#define NOPUSH_MASK_3 48975 +#define NOPUSH_MASK_4 65535 +#define NOPUSH_MASK_5 52991 +#define NOPUSH_MASK_6 60410 +#define NOPUSH_MASK_7 32421 +#define NOPUSH_MASK_8 0 +#define NOPUSH_MASK_9 0 diff --git a/db/sqlite3/src/pager.c b/db/sqlite3/src/pager.c index 9c6040a6285..1bacc132659 100644 --- a/db/sqlite3/src/pager.c +++ b/db/sqlite3/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.198 2005/03/21 04:04:02 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.201 2005/03/28 18:04:28 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -213,9 +213,16 @@ struct PgHistory { /* ** How big to make the hash table used for locating in-memory pages -** by page number. +** by page number. This macro looks a little silly, but is evaluated +** at compile-time, not run-time (at least for gcc this is true). */ -#define N_PG_HASH 2048 +#define N_PG_HASH (\ + (MAX_PAGES>1024)?2048: \ + (MAX_PAGES>512)?1024: \ + (MAX_PAGES>256)?512: \ + (MAX_PAGES>128)?256: \ + (MAX_PAGES>64)?128:64 \ +) /* ** Hash a page number @@ -906,6 +913,7 @@ static int pager_unwritelock(Pager *pPager){ pPager->dirtyCache = 0; pPager->nRec = 0; }else{ + assert( pPager->aInJournal==0 ); assert( pPager->dirtyCache==0 || pPager->useJournal==0 ); } rc = sqlite3OsUnlock(&pPager->fd, SHARED_LOCK); @@ -1978,6 +1986,7 @@ int sqlite3pager_close(Pager *pPager){ if( pPager->journalOpen ){ sqlite3OsClose(&pPager->jfd); } + sqliteFree(pPager->aInJournal); if( pPager->stmtOpen ){ sqlite3OsClose(&pPager->stfd); } @@ -2611,6 +2620,7 @@ static int pager_open_journal(Pager *pPager){ assert( pPager->state>=PAGER_RESERVED ); assert( pPager->journalOpen==0 ); assert( pPager->useJournal ); + assert( pPager->aInJournal==0 ); sqlite3pager_pagecount(pPager); pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 ); if( pPager->aInJournal==0 ){ @@ -2634,7 +2644,7 @@ static int pager_open_journal(Pager *pPager){ pPager->nRec = 0; if( pPager->errMask!=0 ){ rc = pager_errcode(pPager); - return rc; + goto failed_to_open_journal; } pPager->origDbSize = pPager->dbSize; diff --git a/db/sqlite3/src/parse.c b/db/sqlite3/src/parse.c index 65591aaf2a7..6dee4ff6311 100644 --- a/db/sqlite3/src/parse.c +++ b/db/sqlite3/src/parse.c @@ -1315,7 +1315,7 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ case 159: case 191: case 208: -#line 332 "parse.y" +#line 334 "parse.y" {sqlite3SelectDelete((yypminor->yy91));} #line 1322 "parse.c" break; @@ -1326,7 +1326,7 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ case 206: case 212: case 226: -#line 591 "parse.y" +#line 593 "parse.y" {sqlite3ExprDelete((yypminor->yy418));} #line 1333 "parse.c" break; @@ -1341,7 +1341,7 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ case 215: case 218: case 224: -#line 810 "parse.y" +#line 812 "parse.y" {sqlite3ExprListDelete((yypminor->yy322));} #line 1348 "parse.c" break; @@ -1349,12 +1349,12 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ case 195: case 203: case 204: -#line 461 "parse.y" +#line 463 "parse.y" {sqlite3SrcListDelete((yypminor->yy439));} #line 1356 "parse.c" break; case 200: -#line 523 "parse.y" +#line 525 "parse.y" { sqlite3ExprDelete((yypminor->yy388).pLimit); sqlite3ExprDelete((yypminor->yy388).pOffset); @@ -1364,18 +1364,18 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ case 207: case 210: case 217: -#line 479 "parse.y" +#line 481 "parse.y" {sqlite3IdListDelete((yypminor->yy232));} #line 1371 "parse.c" break; case 232: case 237: -#line 903 "parse.y" +#line 905 "parse.y" {sqlite3DeleteTriggerStep((yypminor->yy451));} #line 1377 "parse.c" break; case 234: -#line 887 "parse.y" +#line 889 "parse.y" {sqlite3IdListDelete((yypminor->yy378).b);} #line 1382 "parse.c" break; @@ -1969,7 +1969,7 @@ static void yy_reduce( case 106: case 224: case 227: -#line 115 "parse.y" +#line 116 "parse.y" {yygotominor.yy328 = 1;} #line 1976 "parse.c" break; @@ -1982,19 +1982,19 @@ static void yy_reduce( case 108: case 223: case 226: -#line 116 "parse.y" +#line 118 "parse.y" {yygotominor.yy328 = 0;} #line 1989 "parse.c" break; case 23: -#line 117 "parse.y" +#line 119 "parse.y" { sqlite3EndTable(pParse,&yymsp[-1].minor.yy430,&yymsp[0].minor.yy0,0); } #line 1996 "parse.c" break; case 24: -#line 120 "parse.y" +#line 122 "parse.y" { sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy91); sqlite3SelectDelete(yymsp[0].minor.yy91); @@ -2002,7 +2002,7 @@ static void yy_reduce( #line 2004 "parse.c" break; case 27: -#line 131 "parse.y" +#line 133 "parse.y" { yygotominor.yy430.z = yymsp[-2].minor.yy430.z; yygotominor.yy430.n = (pParse->sLastToken.z-yymsp[-2].minor.yy430.z) + pParse->sLastToken.n; @@ -2010,7 +2010,7 @@ static void yy_reduce( #line 2012 "parse.c" break; case 28: -#line 135 "parse.y" +#line 137 "parse.y" { sqlite3AddColumn(pParse,&yymsp[0].minor.yy430); yygotominor.yy430 = yymsp[0].minor.yy430; @@ -2025,22 +2025,22 @@ static void yy_reduce( case 34: case 263: case 264: -#line 145 "parse.y" +#line 147 "parse.y" {yygotominor.yy430 = yymsp[0].minor.yy0;} #line 2032 "parse.c" break; case 36: -#line 200 "parse.y" +#line 202 "parse.y" {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy430,&yymsp[0].minor.yy430);} #line 2037 "parse.c" break; case 37: -#line 201 "parse.y" +#line 203 "parse.y" {sqlite3AddColumnType(pParse,&yymsp[-3].minor.yy430,&yymsp[0].minor.yy0);} #line 2042 "parse.c" break; case 38: -#line 203 "parse.y" +#line 205 "parse.y" {sqlite3AddColumnType(pParse,&yymsp[-5].minor.yy430,&yymsp[0].minor.yy0);} #line 2047 "parse.c" break; @@ -2052,33 +2052,33 @@ static void yy_reduce( case 251: case 261: case 262: -#line 205 "parse.y" +#line 207 "parse.y" {yygotominor.yy430 = yymsp[0].minor.yy430;} #line 2059 "parse.c" break; case 40: -#line 206 "parse.y" +#line 208 "parse.y" {yygotominor.yy430.z=yymsp[-1].minor.yy430.z; yygotominor.yy430.n=yymsp[0].minor.yy430.n+(yymsp[0].minor.yy430.z-yymsp[-1].minor.yy430.z);} #line 2064 "parse.c" break; case 41: -#line 208 "parse.y" +#line 210 "parse.y" { yygotominor.yy328 = atoi(yymsp[0].minor.yy430.z); } #line 2069 "parse.c" break; case 42: -#line 209 "parse.y" +#line 211 "parse.y" { yygotominor.yy328 = -atoi(yymsp[0].minor.yy430.z); } #line 2074 "parse.c" break; case 47: case 48: -#line 214 "parse.y" +#line 216 "parse.y" {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy418);} #line 2080 "parse.c" break; case 49: -#line 216 "parse.y" +#line 218 "parse.y" { Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy418, 0, 0); sqlite3AddDefaultValue(pParse,p); @@ -2086,7 +2086,7 @@ static void yy_reduce( #line 2088 "parse.c" break; case 50: -#line 220 "parse.y" +#line 222 "parse.y" { Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy430); sqlite3AddDefaultValue(pParse,p); @@ -2094,87 +2094,87 @@ static void yy_reduce( #line 2096 "parse.c" break; case 52: -#line 229 "parse.y" +#line 231 "parse.y" {sqlite3AddNotNull(pParse, yymsp[0].minor.yy328);} #line 2101 "parse.c" break; case 53: -#line 231 "parse.y" +#line 233 "parse.y" {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy328,yymsp[0].minor.yy328);} #line 2106 "parse.c" break; case 54: -#line 232 "parse.y" +#line 234 "parse.y" {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy328,0,0);} #line 2111 "parse.c" break; case 55: -#line 233 "parse.y" +#line 235 "parse.y" {sqlite3ExprDelete(yymsp[-2].minor.yy418);} #line 2116 "parse.c" break; case 56: -#line 235 "parse.y" +#line 237 "parse.y" {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy430,yymsp[-1].minor.yy322,yymsp[0].minor.yy328);} #line 2121 "parse.c" break; case 57: -#line 236 "parse.y" +#line 238 "parse.y" {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy328);} #line 2126 "parse.c" break; case 58: -#line 237 "parse.y" +#line 239 "parse.y" {sqlite3AddCollateType(pParse, yymsp[0].minor.yy430.z, yymsp[0].minor.yy430.n);} #line 2131 "parse.c" break; case 61: -#line 250 "parse.y" +#line 252 "parse.y" { yygotominor.yy328 = OE_Restrict * 0x010101; } #line 2136 "parse.c" break; case 62: -#line 251 "parse.y" +#line 253 "parse.y" { yygotominor.yy328 = (yymsp[-1].minor.yy328 & yymsp[0].minor.yy319.mask) | yymsp[0].minor.yy319.value; } #line 2141 "parse.c" break; case 63: -#line 253 "parse.y" +#line 255 "parse.y" { yygotominor.yy319.value = 0; yygotominor.yy319.mask = 0x000000; } #line 2146 "parse.c" break; case 64: -#line 254 "parse.y" +#line 256 "parse.y" { yygotominor.yy319.value = yymsp[0].minor.yy328; yygotominor.yy319.mask = 0x0000ff; } #line 2151 "parse.c" break; case 65: -#line 255 "parse.y" +#line 257 "parse.y" { yygotominor.yy319.value = yymsp[0].minor.yy328<<8; yygotominor.yy319.mask = 0x00ff00; } #line 2156 "parse.c" break; case 66: -#line 256 "parse.y" +#line 258 "parse.y" { yygotominor.yy319.value = yymsp[0].minor.yy328<<16; yygotominor.yy319.mask = 0xff0000; } #line 2161 "parse.c" break; case 67: -#line 258 "parse.y" +#line 260 "parse.y" { yygotominor.yy328 = OE_SetNull; } #line 2166 "parse.c" break; case 68: -#line 259 "parse.y" +#line 261 "parse.y" { yygotominor.yy328 = OE_SetDflt; } #line 2171 "parse.c" break; case 69: -#line 260 "parse.y" +#line 262 "parse.y" { yygotominor.yy328 = OE_Cascade; } #line 2176 "parse.c" break; case 70: -#line 261 "parse.y" +#line 263 "parse.y" { yygotominor.yy328 = OE_Restrict; } #line 2181 "parse.c" break; @@ -2185,32 +2185,32 @@ static void yy_reduce( case 91: case 92: case 163: -#line 263 "parse.y" +#line 265 "parse.y" {yygotominor.yy328 = yymsp[0].minor.yy328;} #line 2192 "parse.c" break; case 76: -#line 273 "parse.y" +#line 275 "parse.y" {yygotominor.yy430.n = 0; yygotominor.yy430.z = 0;} #line 2197 "parse.c" break; case 77: -#line 274 "parse.y" +#line 276 "parse.y" {yygotominor.yy430 = yymsp[-1].minor.yy0;} #line 2202 "parse.c" break; case 82: -#line 280 "parse.y" +#line 282 "parse.y" {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy328,yymsp[-2].minor.yy328);} #line 2207 "parse.c" break; case 83: -#line 282 "parse.y" +#line 284 "parse.y" {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy328,0,0);} #line 2212 "parse.c" break; case 85: -#line 285 "parse.y" +#line 287 "parse.y" { sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy430, yymsp[-2].minor.yy322, yymsp[-1].minor.yy328); sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy328); @@ -2219,44 +2219,44 @@ static void yy_reduce( break; case 88: case 90: -#line 299 "parse.y" +#line 301 "parse.y" {yygotominor.yy328 = OE_Default;} #line 2226 "parse.c" break; case 93: -#line 304 "parse.y" +#line 306 "parse.y" {yygotominor.yy328 = OE_Ignore;} #line 2231 "parse.c" break; case 94: case 164: -#line 305 "parse.y" +#line 307 "parse.y" {yygotominor.yy328 = OE_Replace;} #line 2237 "parse.c" break; case 95: -#line 309 "parse.y" +#line 311 "parse.y" { sqlite3DropTable(pParse, yymsp[0].minor.yy439, 0); } #line 2244 "parse.c" break; case 96: -#line 316 "parse.y" +#line 318 "parse.y" { sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy430, &yymsp[-2].minor.yy430, yymsp[0].minor.yy91, yymsp[-5].minor.yy328); } #line 2251 "parse.c" break; case 97: -#line 319 "parse.y" +#line 321 "parse.y" { sqlite3DropTable(pParse, yymsp[0].minor.yy439, 1); } #line 2258 "parse.c" break; case 98: -#line 326 "parse.y" +#line 328 "parse.y" { sqlite3Select(pParse, yymsp[0].minor.yy91, SRT_Callback, 0, 0, 0, 0, 0); sqlite3SelectDelete(yymsp[0].minor.yy91); @@ -2265,12 +2265,12 @@ static void yy_reduce( break; case 99: case 123: -#line 336 "parse.y" +#line 338 "parse.y" {yygotominor.yy91 = yymsp[0].minor.yy91;} #line 2272 "parse.c" break; case 100: -#line 338 "parse.y" +#line 340 "parse.y" { if( yymsp[0].minor.yy91 ){ yymsp[0].minor.yy91->op = yymsp[-1].minor.yy328; @@ -2281,12 +2281,12 @@ static void yy_reduce( #line 2283 "parse.c" break; case 102: -#line 347 "parse.y" +#line 349 "parse.y" {yygotominor.yy328 = TK_ALL;} #line 2288 "parse.c" break; case 105: -#line 352 "parse.y" +#line 354 "parse.y" { yygotominor.yy91 = sqlite3SelectNew(yymsp[-6].minor.yy322,yymsp[-5].minor.yy439,yymsp[-4].minor.yy418,yymsp[-3].minor.yy322,yymsp[-2].minor.yy418,yymsp[-1].minor.yy322,yymsp[-7].minor.yy328,yymsp[0].minor.yy388.pLimit,yymsp[0].minor.yy388.pOffset); } @@ -2294,7 +2294,7 @@ static void yy_reduce( break; case 109: case 248: -#line 373 "parse.y" +#line 375 "parse.y" {yygotominor.yy322 = yymsp[-1].minor.yy322;} #line 2301 "parse.c" break; @@ -2302,26 +2302,26 @@ static void yy_reduce( case 137: case 147: case 247: -#line 374 "parse.y" +#line 376 "parse.y" {yygotominor.yy322 = 0;} #line 2309 "parse.c" break; case 111: -#line 375 "parse.y" +#line 377 "parse.y" { yygotominor.yy322 = sqlite3ExprListAppend(yymsp[-2].minor.yy322,yymsp[-1].minor.yy418,yymsp[0].minor.yy430.n?&yymsp[0].minor.yy430:0); } #line 2316 "parse.c" break; case 112: -#line 378 "parse.y" +#line 380 "parse.y" { yygotominor.yy322 = sqlite3ExprListAppend(yymsp[-1].minor.yy322, sqlite3Expr(TK_ALL, 0, 0, 0), 0); } #line 2323 "parse.c" break; case 113: -#line 381 "parse.y" +#line 383 "parse.y" { Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0); Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy430); @@ -2330,22 +2330,22 @@ static void yy_reduce( #line 2332 "parse.c" break; case 116: -#line 393 "parse.y" +#line 395 "parse.y" {yygotominor.yy430.n = 0;} #line 2337 "parse.c" break; case 117: -#line 405 "parse.y" +#line 407 "parse.y" {yygotominor.yy439 = sqliteMalloc(sizeof(*yygotominor.yy439));} #line 2342 "parse.c" break; case 118: -#line 406 "parse.y" +#line 408 "parse.y" {yygotominor.yy439 = yymsp[0].minor.yy439;} #line 2347 "parse.c" break; case 119: -#line 411 "parse.y" +#line 413 "parse.y" { yygotominor.yy439 = yymsp[-1].minor.yy439; if( yygotominor.yy439 && yygotominor.yy439->nSrc>0 ) yygotominor.yy439->a[yygotominor.yy439->nSrc-1].jointype = yymsp[0].minor.yy328; @@ -2353,12 +2353,12 @@ static void yy_reduce( #line 2355 "parse.c" break; case 120: -#line 415 "parse.y" +#line 417 "parse.y" {yygotominor.yy439 = 0;} #line 2360 "parse.c" break; case 121: -#line 416 "parse.y" +#line 418 "parse.y" { yygotominor.yy439 = sqlite3SrcListAppend(yymsp[-5].minor.yy439,&yymsp[-4].minor.yy430,&yymsp[-3].minor.yy430); if( yymsp[-2].minor.yy430.n ) sqlite3SrcListAddAlias(yygotominor.yy439,&yymsp[-2].minor.yy430); @@ -2374,7 +2374,7 @@ static void yy_reduce( #line 2376 "parse.c" break; case 122: -#line 430 "parse.y" +#line 432 "parse.y" { yygotominor.yy439 = sqlite3SrcListAppend(yymsp[-6].minor.yy439,0,0); yygotominor.yy439->a[yygotominor.yy439->nSrc-1].pSelect = yymsp[-4].minor.yy91; @@ -2391,40 +2391,40 @@ static void yy_reduce( #line 2393 "parse.c" break; case 124: -#line 451 "parse.y" +#line 453 "parse.y" { yygotominor.yy91 = sqlite3SelectNew(0,yymsp[0].minor.yy439,0,0,0,0,0,0,0); } #line 2400 "parse.c" break; case 125: -#line 457 "parse.y" +#line 459 "parse.y" {yygotominor.yy430.z=0; yygotominor.yy430.n=0;} #line 2405 "parse.c" break; case 127: -#line 462 "parse.y" +#line 464 "parse.y" {yygotominor.yy439 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy430,&yymsp[0].minor.yy430);} #line 2410 "parse.c" break; case 128: case 129: -#line 466 "parse.y" +#line 468 "parse.y" { yygotominor.yy328 = JT_INNER; } #line 2416 "parse.c" break; case 130: -#line 468 "parse.y" +#line 470 "parse.y" { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } #line 2421 "parse.c" break; case 131: -#line 469 "parse.y" +#line 471 "parse.y" { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy430,0); } #line 2426 "parse.c" break; case 132: -#line 471 "parse.y" +#line 473 "parse.y" { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy430,&yymsp[-1].minor.yy430); } #line 2431 "parse.c" break; @@ -2437,7 +2437,7 @@ static void yy_reduce( case 236: case 238: case 242: -#line 475 "parse.y" +#line 477 "parse.y" {yygotominor.yy418 = yymsp[0].minor.yy418;} #line 2444 "parse.c" break; @@ -2448,30 +2448,30 @@ static void yy_reduce( case 237: case 239: case 243: -#line 476 "parse.y" +#line 478 "parse.y" {yygotominor.yy418 = 0;} #line 2455 "parse.c" break; case 135: case 168: -#line 480 "parse.y" +#line 482 "parse.y" {yygotominor.yy232 = yymsp[-1].minor.yy232;} #line 2461 "parse.c" break; case 136: case 167: -#line 481 "parse.y" +#line 483 "parse.y" {yygotominor.yy232 = 0;} #line 2467 "parse.c" break; case 138: case 148: -#line 492 "parse.y" +#line 494 "parse.y" {yygotominor.yy322 = yymsp[0].minor.yy322;} #line 2473 "parse.c" break; case 139: -#line 493 "parse.y" +#line 495 "parse.y" { yygotominor.yy322 = sqlite3ExprListAppend(yymsp[-4].minor.yy322,yymsp[-2].minor.yy418,yymsp[-1].minor.yy430.n>0?&yymsp[-1].minor.yy430:0); if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = yymsp[0].minor.yy328; @@ -2479,7 +2479,7 @@ static void yy_reduce( #line 2481 "parse.c" break; case 140: -#line 497 "parse.y" +#line 499 "parse.y" { yygotominor.yy322 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy418,yymsp[-1].minor.yy430.n>0?&yymsp[-1].minor.yy430:0); if( yygotominor.yy322 && yygotominor.yy322->a ) yygotominor.yy322->a[0].sortOrder = yymsp[0].minor.yy328; @@ -2488,94 +2488,94 @@ static void yy_reduce( break; case 142: case 144: -#line 506 "parse.y" +#line 508 "parse.y" {yygotominor.yy328 = SQLITE_SO_ASC;} #line 2495 "parse.c" break; case 143: -#line 507 "parse.y" +#line 509 "parse.y" {yygotominor.yy328 = SQLITE_SO_DESC;} #line 2500 "parse.c" break; case 145: -#line 509 "parse.y" +#line 511 "parse.y" {yygotominor.yy430.z = 0; yygotominor.yy430.n = 0;} #line 2505 "parse.c" break; case 151: -#line 527 "parse.y" +#line 529 "parse.y" {yygotominor.yy388.pLimit = 0; yygotominor.yy388.pOffset = 0;} #line 2510 "parse.c" break; case 152: -#line 528 "parse.y" +#line 530 "parse.y" {yygotominor.yy388.pLimit = yymsp[0].minor.yy418; yygotominor.yy388.pOffset = 0;} #line 2515 "parse.c" break; case 153: -#line 530 "parse.y" +#line 532 "parse.y" {yygotominor.yy388.pLimit = yymsp[-2].minor.yy418; yygotominor.yy388.pOffset = yymsp[0].minor.yy418;} #line 2520 "parse.c" break; case 154: -#line 532 "parse.y" +#line 534 "parse.y" {yygotominor.yy388.pOffset = yymsp[-2].minor.yy418; yygotominor.yy388.pLimit = yymsp[0].minor.yy418;} #line 2525 "parse.c" break; case 155: -#line 536 "parse.y" +#line 538 "parse.y" {sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy439,yymsp[0].minor.yy418);} #line 2530 "parse.c" break; case 158: -#line 550 "parse.y" +#line 552 "parse.y" {sqlite3Update(pParse,yymsp[-3].minor.yy439,yymsp[-1].minor.yy322,yymsp[0].minor.yy418,yymsp[-4].minor.yy328);} #line 2535 "parse.c" break; case 159: -#line 553 "parse.y" +#line 555 "parse.y" {yygotominor.yy322 = sqlite3ExprListAppend(yymsp[-4].minor.yy322,yymsp[0].minor.yy418,&yymsp[-2].minor.yy430);} #line 2540 "parse.c" break; case 160: -#line 554 "parse.y" +#line 556 "parse.y" {yygotominor.yy322 = sqlite3ExprListAppend(0,yymsp[0].minor.yy418,&yymsp[-2].minor.yy430);} #line 2545 "parse.c" break; case 161: -#line 560 "parse.y" +#line 562 "parse.y" {sqlite3Insert(pParse, yymsp[-5].minor.yy439, yymsp[-1].minor.yy322, 0, yymsp[-4].minor.yy232, yymsp[-7].minor.yy328);} #line 2550 "parse.c" break; case 162: -#line 562 "parse.y" +#line 564 "parse.y" {sqlite3Insert(pParse, yymsp[-2].minor.yy439, 0, yymsp[0].minor.yy91, yymsp[-1].minor.yy232, yymsp[-4].minor.yy328);} #line 2555 "parse.c" break; case 165: case 240: -#line 572 "parse.y" +#line 574 "parse.y" {yygotominor.yy322 = sqlite3ExprListAppend(yymsp[-2].minor.yy322,yymsp[0].minor.yy418,0);} #line 2561 "parse.c" break; case 166: case 241: -#line 573 "parse.y" +#line 575 "parse.y" {yygotominor.yy322 = sqlite3ExprListAppend(0,yymsp[0].minor.yy418,0);} #line 2567 "parse.c" break; case 169: -#line 582 "parse.y" +#line 584 "parse.y" {yygotominor.yy232 = sqlite3IdListAppend(yymsp[-2].minor.yy232,&yymsp[0].minor.yy430);} #line 2572 "parse.c" break; case 170: -#line 583 "parse.y" +#line 585 "parse.y" {yygotominor.yy232 = sqlite3IdListAppend(0,&yymsp[0].minor.yy430);} #line 2577 "parse.c" break; case 172: -#line 594 "parse.y" +#line 596 "parse.y" {yygotominor.yy418 = yymsp[-1].minor.yy418; sqlite3ExprSpan(yygotominor.yy418,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } #line 2582 "parse.c" break; @@ -2584,18 +2584,18 @@ static void yy_reduce( case 179: case 180: case 181: -#line 595 "parse.y" +#line 597 "parse.y" {yygotominor.yy418 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} #line 2591 "parse.c" break; case 174: case 175: -#line 596 "parse.y" +#line 598 "parse.y" {yygotominor.yy418 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} #line 2597 "parse.c" break; case 176: -#line 598 "parse.y" +#line 600 "parse.y" { Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy430); Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy430); @@ -2604,7 +2604,7 @@ static void yy_reduce( #line 2606 "parse.c" break; case 177: -#line 603 "parse.y" +#line 605 "parse.y" { Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy430); Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy430); @@ -2615,12 +2615,12 @@ static void yy_reduce( #line 2617 "parse.c" break; case 182: -#line 614 "parse.y" +#line 616 "parse.y" {yygotominor.yy418 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} #line 2622 "parse.c" break; case 183: -#line 615 "parse.y" +#line 617 "parse.y" { Token *pToken = &yymsp[0].minor.yy0; Expr *pExpr = yygotominor.yy418 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); @@ -2629,7 +2629,7 @@ static void yy_reduce( #line 2631 "parse.c" break; case 184: -#line 620 "parse.y" +#line 622 "parse.y" { yygotominor.yy418 = sqlite3ExprFunction(yymsp[-1].minor.yy322, &yymsp[-3].minor.yy0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); @@ -2637,7 +2637,7 @@ static void yy_reduce( #line 2639 "parse.c" break; case 185: -#line 624 "parse.y" +#line 626 "parse.y" { yygotominor.yy418 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); @@ -2647,7 +2647,7 @@ static void yy_reduce( case 186: case 187: case 188: -#line 628 "parse.y" +#line 630 "parse.y" {yygotominor.yy418 = sqlite3Expr(yymsp[0].major,0,0,0);} #line 2654 "parse.c" break; @@ -2669,32 +2669,32 @@ static void yy_reduce( case 204: case 205: case 206: -#line 631 "parse.y" +#line 633 "parse.y" {yygotominor.yy418 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy418, yymsp[0].minor.yy418, 0);} #line 2676 "parse.c" break; case 207: -#line 650 "parse.y" +#line 652 "parse.y" {yygotominor.yy30.opcode = TK_LIKE; yygotominor.yy30.not = 0;} #line 2681 "parse.c" break; case 208: -#line 651 "parse.y" +#line 653 "parse.y" {yygotominor.yy30.opcode = TK_GLOB; yygotominor.yy30.not = 0;} #line 2686 "parse.c" break; case 209: -#line 652 "parse.y" +#line 654 "parse.y" {yygotominor.yy30.opcode = TK_LIKE; yygotominor.yy30.not = 1;} #line 2691 "parse.c" break; case 210: -#line 653 "parse.y" +#line 655 "parse.y" {yygotominor.yy30.opcode = TK_GLOB; yygotominor.yy30.not = 1;} #line 2696 "parse.c" break; case 213: -#line 657 "parse.y" +#line 659 "parse.y" { ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy418, 0); pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy418, 0); @@ -2709,7 +2709,7 @@ static void yy_reduce( #line 2711 "parse.c" break; case 214: -#line 669 "parse.y" +#line 671 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-1].minor.yy418->span,&yymsp[0].minor.yy0); @@ -2717,7 +2717,7 @@ static void yy_reduce( #line 2719 "parse.c" break; case 215: -#line 673 "parse.y" +#line 675 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-2].minor.yy418->span,&yymsp[0].minor.yy0); @@ -2725,7 +2725,7 @@ static void yy_reduce( #line 2727 "parse.c" break; case 216: -#line 677 "parse.y" +#line 679 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-1].minor.yy418->span,&yymsp[0].minor.yy0); @@ -2733,7 +2733,7 @@ static void yy_reduce( #line 2735 "parse.c" break; case 217: -#line 681 "parse.y" +#line 683 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-2].minor.yy418->span,&yymsp[0].minor.yy0); @@ -2741,7 +2741,7 @@ static void yy_reduce( #line 2743 "parse.c" break; case 218: -#line 685 "parse.y" +#line 687 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-3].minor.yy418->span,&yymsp[0].minor.yy0); @@ -2750,7 +2750,7 @@ static void yy_reduce( break; case 219: case 220: -#line 689 "parse.y" +#line 691 "parse.y" { yygotominor.yy418 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy418->span); @@ -2758,7 +2758,7 @@ static void yy_reduce( #line 2760 "parse.c" break; case 221: -#line 697 "parse.y" +#line 699 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy418->span); @@ -2766,7 +2766,7 @@ static void yy_reduce( #line 2768 "parse.c" break; case 222: -#line 701 "parse.y" +#line 703 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy418, 0, 0); sqlite3ExprSpan(yygotominor.yy418,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy418->span); @@ -2774,7 +2774,7 @@ static void yy_reduce( #line 2776 "parse.c" break; case 225: -#line 708 "parse.y" +#line 710 "parse.y" { ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy418, 0); pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy418, 0); @@ -2786,7 +2786,7 @@ static void yy_reduce( #line 2788 "parse.c" break; case 228: -#line 720 "parse.y" +#line 722 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy418, 0, 0); if( yygotominor.yy418 ){ @@ -2800,7 +2800,7 @@ static void yy_reduce( #line 2802 "parse.c" break; case 229: -#line 730 "parse.y" +#line 732 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_SELECT, 0, 0, 0); if( yygotominor.yy418 ) yygotominor.yy418->pSelect = yymsp[-1].minor.yy91; @@ -2810,7 +2810,7 @@ static void yy_reduce( #line 2812 "parse.c" break; case 230: -#line 736 "parse.y" +#line 738 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy418, 0, 0); if( yygotominor.yy418 ) yygotominor.yy418->pSelect = yymsp[-1].minor.yy91; @@ -2821,7 +2821,7 @@ static void yy_reduce( #line 2823 "parse.c" break; case 231: -#line 743 "parse.y" +#line 745 "parse.y" { SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy430,&yymsp[0].minor.yy430); yygotominor.yy418 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy418, 0, 0); @@ -2832,7 +2832,7 @@ static void yy_reduce( #line 2834 "parse.c" break; case 232: -#line 750 "parse.y" +#line 752 "parse.y" { Expr *p = yygotominor.yy418 = sqlite3Expr(TK_EXISTS, 0, 0, 0); if( p ){ @@ -2844,7 +2844,7 @@ static void yy_reduce( #line 2846 "parse.c" break; case 233: -#line 761 "parse.y" +#line 763 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy418, yymsp[-1].minor.yy418, 0); if( yygotominor.yy418 ) yygotominor.yy418->pList = yymsp[-2].minor.yy322; @@ -2853,7 +2853,7 @@ static void yy_reduce( #line 2855 "parse.c" break; case 234: -#line 768 "parse.y" +#line 770 "parse.y" { yygotominor.yy322 = sqlite3ExprListAppend(yymsp[-4].minor.yy322, yymsp[-2].minor.yy418, 0); yygotominor.yy322 = sqlite3ExprListAppend(yygotominor.yy322, yymsp[0].minor.yy418, 0); @@ -2861,7 +2861,7 @@ static void yy_reduce( #line 2863 "parse.c" break; case 235: -#line 772 "parse.y" +#line 774 "parse.y" { yygotominor.yy322 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy418, 0); yygotominor.yy322 = sqlite3ExprListAppend(yygotominor.yy322, yymsp[0].minor.yy418, 0); @@ -2869,7 +2869,7 @@ static void yy_reduce( #line 2871 "parse.c" break; case 244: -#line 797 "parse.y" +#line 799 "parse.y" { if( yymsp[-9].minor.yy328!=OE_None ) yymsp[-9].minor.yy328 = yymsp[0].minor.yy328; if( yymsp[-9].minor.yy328==OE_Default) yymsp[-9].minor.yy328 = OE_Abort; @@ -2879,17 +2879,17 @@ static void yy_reduce( break; case 245: case 292: -#line 804 "parse.y" +#line 806 "parse.y" {yygotominor.yy328 = OE_Abort;} #line 2886 "parse.c" break; case 246: -#line 805 "parse.y" +#line 807 "parse.y" {yygotominor.yy328 = OE_None;} #line 2891 "parse.c" break; case 249: -#line 815 "parse.y" +#line 817 "parse.y" { Expr *p = 0; if( yymsp[-1].minor.yy430.n>0 ){ @@ -2901,7 +2901,7 @@ static void yy_reduce( #line 2903 "parse.c" break; case 250: -#line 823 "parse.y" +#line 825 "parse.y" { Expr *p = 0; if( yymsp[-1].minor.yy430.n>0 ){ @@ -2913,46 +2913,46 @@ static void yy_reduce( #line 2915 "parse.c" break; case 252: -#line 836 "parse.y" +#line 838 "parse.y" {sqlite3DropIndex(pParse, yymsp[0].minor.yy439);} #line 2920 "parse.c" break; case 253: case 254: -#line 840 "parse.y" +#line 842 "parse.y" {sqlite3Vacuum(pParse,0);} #line 2926 "parse.c" break; case 255: case 257: -#line 846 "parse.y" +#line 848 "parse.y" {sqlite3Pragma(pParse,&yymsp[-3].minor.yy430,&yymsp[-2].minor.yy430,&yymsp[0].minor.yy430,0);} #line 2932 "parse.c" break; case 256: -#line 847 "parse.y" +#line 849 "parse.y" {sqlite3Pragma(pParse,&yymsp[-3].minor.yy430,&yymsp[-2].minor.yy430,&yymsp[0].minor.yy0,0);} #line 2937 "parse.c" break; case 258: -#line 849 "parse.y" +#line 851 "parse.y" { sqlite3Pragma(pParse,&yymsp[-3].minor.yy430,&yymsp[-2].minor.yy430,&yymsp[0].minor.yy430,1); } #line 2944 "parse.c" break; case 259: -#line 852 "parse.y" +#line 854 "parse.y" {sqlite3Pragma(pParse,&yymsp[-4].minor.yy430,&yymsp[-3].minor.yy430,&yymsp[-1].minor.yy430,0);} #line 2949 "parse.c" break; case 260: -#line 853 "parse.y" +#line 855 "parse.y" {sqlite3Pragma(pParse,&yymsp[-1].minor.yy430,&yymsp[0].minor.yy430,0,0);} #line 2954 "parse.c" break; case 267: -#line 866 "parse.y" +#line 868 "parse.y" { Token all; all.z = yymsp[-3].minor.yy430.z; @@ -2962,7 +2962,7 @@ static void yy_reduce( #line 2964 "parse.c" break; case 268: -#line 875 "parse.y" +#line 877 "parse.y" { sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy430, &yymsp[-6].minor.yy430, yymsp[-5].minor.yy328, yymsp[-4].minor.yy378.a, yymsp[-4].minor.yy378.b, yymsp[-2].minor.yy439, yymsp[-1].minor.yy328, yymsp[0].minor.yy418, yymsp[-9].minor.yy328); yygotominor.yy430 = (yymsp[-6].minor.yy430.n==0?yymsp[-7].minor.yy430:yymsp[-6].minor.yy430); @@ -2971,55 +2971,55 @@ static void yy_reduce( break; case 269: case 272: -#line 881 "parse.y" +#line 883 "parse.y" { yygotominor.yy328 = TK_BEFORE; } #line 2978 "parse.c" break; case 270: -#line 882 "parse.y" +#line 884 "parse.y" { yygotominor.yy328 = TK_AFTER; } #line 2983 "parse.c" break; case 271: -#line 883 "parse.y" +#line 885 "parse.y" { yygotominor.yy328 = TK_INSTEAD;} #line 2988 "parse.c" break; case 273: case 274: case 275: -#line 888 "parse.y" +#line 890 "parse.y" {yygotominor.yy378.a = yymsp[0].major; yygotominor.yy378.b = 0;} #line 2995 "parse.c" break; case 276: -#line 891 "parse.y" +#line 893 "parse.y" {yygotominor.yy378.a = TK_UPDATE; yygotominor.yy378.b = yymsp[0].minor.yy232;} #line 3000 "parse.c" break; case 277: case 278: -#line 894 "parse.y" +#line 896 "parse.y" { yygotominor.yy328 = TK_ROW; } #line 3006 "parse.c" break; case 279: -#line 896 "parse.y" +#line 898 "parse.y" { yygotominor.yy328 = TK_STATEMENT; } #line 3011 "parse.c" break; case 280: -#line 899 "parse.y" +#line 901 "parse.y" { yygotominor.yy418 = 0; } #line 3016 "parse.c" break; case 281: -#line 900 "parse.y" +#line 902 "parse.y" { yygotominor.yy418 = yymsp[0].minor.yy418; } #line 3021 "parse.c" break; case 282: -#line 904 "parse.y" +#line 906 "parse.y" { yymsp[-2].minor.yy451->pNext = yymsp[0].minor.yy451; yygotominor.yy451 = yymsp[-2].minor.yy451; @@ -3027,37 +3027,37 @@ static void yy_reduce( #line 3029 "parse.c" break; case 283: -#line 908 "parse.y" +#line 910 "parse.y" { yygotominor.yy451 = 0; } #line 3034 "parse.c" break; case 284: -#line 914 "parse.y" +#line 916 "parse.y" { yygotominor.yy451 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy430, yymsp[-1].minor.yy322, yymsp[0].minor.yy418, yymsp[-4].minor.yy328); } #line 3039 "parse.c" break; case 285: -#line 919 "parse.y" +#line 921 "parse.y" {yygotominor.yy451 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy430, yymsp[-4].minor.yy232, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy328);} #line 3044 "parse.c" break; case 286: -#line 922 "parse.y" +#line 924 "parse.y" {yygotominor.yy451 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy430, yymsp[-1].minor.yy232, 0, yymsp[0].minor.yy91, yymsp[-4].minor.yy328);} #line 3049 "parse.c" break; case 287: -#line 926 "parse.y" +#line 928 "parse.y" {yygotominor.yy451 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy430, yymsp[0].minor.yy418);} #line 3054 "parse.c" break; case 288: -#line 929 "parse.y" +#line 931 "parse.y" {yygotominor.yy451 = sqlite3TriggerSelectStep(yymsp[0].minor.yy91); } #line 3059 "parse.c" break; case 289: -#line 932 "parse.y" +#line 934 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_RAISE, 0, 0, 0); yygotominor.yy418->iColumn = OE_Ignore; @@ -3066,7 +3066,7 @@ static void yy_reduce( #line 3068 "parse.c" break; case 290: -#line 937 "parse.y" +#line 939 "parse.y" { yygotominor.yy418 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy430); yygotominor.yy418->iColumn = yymsp[-3].minor.yy328; @@ -3075,77 +3075,77 @@ static void yy_reduce( #line 3077 "parse.c" break; case 291: -#line 945 "parse.y" +#line 947 "parse.y" {yygotominor.yy328 = OE_Rollback;} #line 3082 "parse.c" break; case 293: -#line 947 "parse.y" +#line 949 "parse.y" {yygotominor.yy328 = OE_Fail;} #line 3087 "parse.c" break; case 294: -#line 952 "parse.y" +#line 954 "parse.y" { sqlite3DropTrigger(pParse,yymsp[0].minor.yy439); } #line 3094 "parse.c" break; case 295: -#line 958 "parse.y" +#line 960 "parse.y" { sqlite3Attach(pParse, &yymsp[-3].minor.yy430, &yymsp[-1].minor.yy430, yymsp[0].minor.yy92.type, &yymsp[0].minor.yy92.key); } #line 3101 "parse.c" break; case 296: -#line 962 "parse.y" +#line 964 "parse.y" { yygotominor.yy92.type = 0; } #line 3106 "parse.c" break; case 297: -#line 963 "parse.y" +#line 965 "parse.y" { yygotominor.yy92.type=1; yygotominor.yy92.key = yymsp[0].minor.yy430; } #line 3111 "parse.c" break; case 298: -#line 964 "parse.y" +#line 966 "parse.y" { yygotominor.yy92.type=2; yygotominor.yy92.key = yymsp[0].minor.yy0; } #line 3116 "parse.c" break; case 301: -#line 970 "parse.y" +#line 972 "parse.y" { sqlite3Detach(pParse, &yymsp[0].minor.yy430); } #line 3123 "parse.c" break; case 302: -#line 976 "parse.y" +#line 978 "parse.y" {sqlite3Reindex(pParse, 0, 0);} #line 3128 "parse.c" break; case 303: -#line 977 "parse.y" +#line 979 "parse.y" {sqlite3Reindex(pParse, &yymsp[-1].minor.yy430, &yymsp[0].minor.yy430);} #line 3133 "parse.c" break; case 304: -#line 982 "parse.y" +#line 984 "parse.y" { sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy439,&yymsp[0].minor.yy430); } #line 3140 "parse.c" break; case 305: -#line 985 "parse.y" +#line 987 "parse.y" { sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy430); } #line 3147 "parse.c" break; case 306: -#line 988 "parse.y" +#line 990 "parse.y" { sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy439); } diff --git a/db/sqlite3/src/pragma.c b/db/sqlite3/src/pragma.c index e46d374b586..22b47af9d21 100644 --- a/db/sqlite3/src/pragma.c +++ b/db/sqlite3/src/pragma.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.90 2005/02/26 18:10:44 drh Exp $ +** $Id: pragma.c,v 1.91 2005/03/29 03:10:59 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -645,6 +645,8 @@ void sqlite3Pragma( HashElem *x; int cnt = 0; + if( OMIT_TEMPDB && i==1 ) continue; + sqlite3CodeVerifySchema(pParse, i); /* Do an integrity check of the B-Tree diff --git a/db/sqlite3/src/select.c b/db/sqlite3/src/select.c index bdc799fe4f6..aa2d296e2e1 100644 --- a/db/sqlite3/src/select.c +++ b/db/sqlite3/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.242 2005/03/21 03:53:38 danielk1977 Exp $ +** $Id: select.c,v 1.243 2005/03/28 03:39:56 drh Exp $ */ #include "sqliteInt.h" @@ -890,7 +890,11 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ zName = sqlite3MPrintf("column%d", i+1); } sqlite3Dequote(zName); - if( sqlite3_malloc_failed ) return 0; + if( sqlite3_malloc_failed ){ + sqliteFree(zName); + sqlite3DeleteTable(0, pTab); + return 0; + } /* Make sure the column name is unique. If the name is not unique, ** append a integer to the name so that it becomes unique. @@ -900,6 +904,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){ zName = sqlite3MPrintf("%s:%d", zBasename, ++cnt); j = -1; + if( zName==0 ) break; } } if( zBasename!=zName ){ diff --git a/db/sqlite3/src/sqlite.h.in b/db/sqlite3/src/sqlite.h.in index 0f44f6a2b43..d38c6b5ce71 100644 --- a/db/sqlite3/src/sqlite.h.in +++ b/db/sqlite3/src/sqlite.h.in @@ -686,6 +686,20 @@ const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); */ int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); +/* +** Given a wildcard parameter name, return the set of indexes of the +** variables with that name. If there are no variables with the given +** name, return 0. Otherwise, return the number of indexes returned +** in *pIndexes. The array should be freed with +** sqlite3_free_parameter_indexes. +*/ +int sqlite3_bind_parameter_indexes( + sqlite3_stmt *pStmt, + const char *zName, + int **pIndexes +); +void sqlite3_free_parameter_indexes(int *pIndexes); + /* ** Set all the parameters in the compiled SQL statement to NULL. ** diff --git a/db/sqlite3/src/sqliteInt.h b/db/sqlite3/src/sqliteInt.h index 3934a6b6317..2cd0e95950a 100644 --- a/db/sqlite3/src/sqliteInt.h +++ b/db/sqlite3/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.374 2005/03/21 04:04:03 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.375 2005/03/29 03:10:59 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -67,6 +67,17 @@ # define TEMP_PAGES 500 #endif +/* +** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 +** afterward. Having this macro allows us to cause the C compiler +** to omit code used by TEMP tables without messy #ifndef statements. +*/ +#ifdef SQLITE_OMIT_TEMPDB +#define OMIT_TEMPDB 1 +#else +#define OMIT_TEMPDB 0 +#endif + /* ** If the following macro is set to 1, then NULL values are considered ** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT @@ -292,7 +303,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */ /* ** The name of the schema table. */ -#define SCHEMA_TABLE(x) (x==1?TEMP_MASTER_NAME:MASTER_NAME) +#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) /* ** A convenience macro that returns the number of elements in diff --git a/db/sqlite3/src/trigger.c b/db/sqlite3/src/trigger.c index cdae012ead6..29cbc377967 100644 --- a/db/sqlite3/src/trigger.c +++ b/db/sqlite3/src/trigger.c @@ -197,9 +197,9 @@ void sqlite3FinishTrigger( sqlite3 *db = pParse->db; /* The database */ DbFixer sFix; - if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup; pTrig = pParse->pNewTrigger; pParse->pNewTrigger = 0; + if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup; pTrig->step_list = pStepList; while( pStepList ){ pStepList->pTrig = pTrig; @@ -439,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){ zDb = pName->a[0].zDatabase; zName = pName->a[0].zName; nName = strlen(zName); - for(i=0; inDb; i++){ + for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue; pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1); diff --git a/db/sqlite3/src/vdbe.c b/db/sqlite3/src/vdbe.c index 434183a5a39..7804a316118 100644 --- a/db/sqlite3/src/vdbe.c +++ b/db/sqlite3/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.460 2005/03/21 03:53:38 danielk1977 Exp $ +** $Id: vdbe.c,v 1.463 2005/03/29 13:07:00 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -462,6 +462,9 @@ int sqlite3VdbeExec( #ifndef SQLITE_OMIT_PROGRESS_CALLBACK int nProgressOps = 0; /* Opcodes executed since progress callback. */ #endif +#ifndef NDEBUG + Mem *pStackLimit; +#endif if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE; assert( db->magic==SQLITE_MAGIC_BUSY ); @@ -533,6 +536,23 @@ int sqlite3VdbeExec( } #endif +#ifndef NDEBUG + /* This is to check that the return value of static function + ** opcodeNoPush() (see vdbeaux.c) returns values that match the + ** implementation of the virtual machine in this file. If + ** opcodeNoPush() returns non-zero, then the stack is guarenteed + ** not to grow when the opcode is executed. If it returns zero, then + ** the stack may grow by at most 1. + ** + ** The global wrapper function sqlite3VdbeOpcodeUsesStack() is not + ** available if NDEBUG is defined at build time. + */ + pStackLimit = pTos; + if( !sqlite3VdbeOpcodeNoPush(pOp->opcode) ){ + pStackLimit++; + } +#endif + switch( pOp->opcode ){ /***************************************************************************** @@ -553,6 +573,11 @@ int sqlite3VdbeExec( ** case statement is followed by a comment of the form "/# same as ... #/" ** that comment is used to determine the particular value of the opcode. ** +** If a comment on the same line as the "case OP_" construction contains +** the word "no-push", then the opcode is guarenteed not to grow the +** vdbe stack when it is executed. See function opcode() in +** vdbeaux.c for details. +** ** Documentation about VDBE opcodes is generated by scanning this file ** for lines of that contain "Opcode:". That line and all subsequent ** comment lines are used in the generation of the opcode.html documentation @@ -572,7 +597,7 @@ int sqlite3VdbeExec( ** the one at index P2 from the beginning of ** the program. */ -case OP_Goto: { +case OP_Goto: { /* no-push */ CHECK_FOR_INTERRUPT; pc = pOp->p2 - 1; break; @@ -588,7 +613,7 @@ case OP_Goto: { ** the return address stack will fill up and processing will abort ** with a fatal error. */ -case OP_Gosub: { +case OP_Gosub: { /* no-push */ assert( p->returnDepthreturnStack)/sizeof(p->returnStack[0]) ); p->returnStack[p->returnDepth++] = pc+1; pc = pOp->p2 - 1; @@ -601,7 +626,7 @@ case OP_Gosub: { ** OP_Gosub. If an OP_Return has occurred for all OP_Gosubs, then ** processing aborts with a fatal error. */ -case OP_Return: { +case OP_Return: { /* no-push */ assert( p->returnDepth>0 ); p->returnDepth--; pc = p->returnStack[p->returnDepth] - 1; @@ -625,7 +650,7 @@ case OP_Return: { ** every program. So a jump past the last instruction of the program ** is the same as executing Halt. */ -case OP_Halt: { +case OP_Halt: { /* no-push */ p->pTos = pTos; p->rc = pOp->p1; p->pc = pc; @@ -671,7 +696,7 @@ case OP_Integer: { ** ** The string value P3 is converted to a real and pushed on to the stack. */ -case OP_Real: { /* same as TK_FLOAT */ +case OP_Real: { /* same as TK_FLOAT, */ pTos++; pTos->flags = MEM_Str|MEM_Static|MEM_Term; pTos->z = pOp->p3; @@ -807,7 +832,7 @@ case OP_Variable: { ** ** P1 elements are popped off of the top of stack and discarded. */ -case OP_Pop: { +case OP_Pop: { /* no-push */ assert( pOp->p1>=0 ); popStack(&pTos, pOp->p1); assert( pTos>=&p->aStack[-1] ); @@ -850,7 +875,7 @@ case OP_Dup: { ** ** See also the Dup instruction. */ -case OP_Pull: { +case OP_Pull: { /* no-push */ Mem *pFrom = &pTos[-pOp->p1]; int i; Mem ts; @@ -882,7 +907,7 @@ case OP_Pull: { ** stack (P1==0 is the top of the stack) with the value ** of the top of the stack. Then pop the top of the stack. */ -case OP_Push: { +case OP_Push: { /* no-push */ Mem *pTo = &pTos[-pOp->p1]; assert( pTo>=p->aStack ); @@ -897,7 +922,7 @@ case OP_Push: { ** invoke the callback function using the newly formed array as the ** 3rd parameter. */ -case OP_Callback: { +case OP_Callback: { /* no-push */ int i; assert( p->nResColumn==pOp->p1 ); @@ -1033,11 +1058,11 @@ case OP_Concat: { /* same as TK_CONCAT */ ** function before the division. Division by zero returns NULL. ** If either operand is NULL, the result is NULL. */ -case OP_Add: /* same as TK_PLUS */ -case OP_Subtract: /* same as TK_MINUS */ -case OP_Multiply: /* same as TK_STAR */ -case OP_Divide: /* same as TK_SLASH */ -case OP_Remainder: { /* same as TK_REM */ +case OP_Add: /* same as TK_PLUS, no-push */ +case OP_Subtract: /* same as TK_MINUS, no-push */ +case OP_Multiply: /* same as TK_STAR, no-push */ +case OP_Divide: /* same as TK_SLASH, no-push */ +case OP_Remainder: { /* same as TK_REM, no-push */ Mem *pNos = &pTos[-1]; assert( pNos>=p->aStack ); if( ((pTos->flags | pNos->flags) & MEM_Null)!=0 ){ @@ -1117,7 +1142,7 @@ divide_by_zero: ** to retrieve the collation sequence set by this opcode is not available ** publicly, only to user functions defined in func.c. */ -case OP_CollSeq: { +case OP_CollSeq: { /* no-push */ assert( pOp->p3type==P3_COLLSEQ ); break; } @@ -1235,10 +1260,10 @@ case OP_Function: { ** right by N bits where N is the top element on the stack. ** If either operand is NULL, the result is NULL. */ -case OP_BitAnd: /* same as TK_BITAND */ -case OP_BitOr: /* same as TK_BITOR */ -case OP_ShiftLeft: /* same as TK_LSHIFT */ -case OP_ShiftRight: { /* same as TK_RSHIFT */ +case OP_BitAnd: /* same as TK_BITAND, no-push */ +case OP_BitOr: /* same as TK_BITOR, no-push */ +case OP_ShiftLeft: /* same as TK_LSHIFT, no-push */ +case OP_ShiftRight: { /* same as TK_RSHIFT, no-push */ Mem *pNos = &pTos[-1]; int a, b; @@ -1273,7 +1298,7 @@ case OP_ShiftRight: { /* same as TK_RSHIFT */ ** ** To force the top of the stack to be an integer, just add 0. */ -case OP_AddImm: { +case OP_AddImm: { /* no-push */ assert( pTos>=p->aStack ); Integerify(pTos); pTos->i += pOp->p1; @@ -1290,7 +1315,7 @@ case OP_AddImm: { ** current value if P1==0, or to the least integer that is strictly ** greater than its current value if P1==1. */ -case OP_ForceInt: { +case OP_ForceInt: { /* no-push */ int v; assert( pTos>=p->aStack ); applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc); @@ -1325,7 +1350,7 @@ case OP_ForceInt: { ** P1 is 1, then the stack is popped. In all other cases, the depth ** of the stack is unchanged. */ -case OP_MustBeInt: { +case OP_MustBeInt: { /* no-push */ assert( pTos>=p->aStack ); applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc); if( (pTos->flags & MEM_Int)==0 ){ @@ -1400,12 +1425,12 @@ case OP_MustBeInt: { ** the 2nd element down on the stack is greater than or equal to the ** top of the stack. See the Eq opcode for additional information. */ -case OP_Eq: /* same as TK_EQ */ -case OP_Ne: /* same as TK_NE */ -case OP_Lt: /* same as TK_LT */ -case OP_Le: /* same as TK_LE */ -case OP_Gt: /* same as TK_GT */ -case OP_Ge: { /* same as TK_GE */ +case OP_Eq: /* same as TK_EQ, no-push */ +case OP_Ne: /* same as TK_NE, no-push */ +case OP_Lt: /* same as TK_LT, no-push */ +case OP_Le: /* same as TK_LE, no-push */ +case OP_Gt: /* same as TK_GT, no-push */ +case OP_Ge: { /* same as TK_GE, no-push */ Mem *pNos; int flags; int res; @@ -1471,8 +1496,8 @@ case OP_Ge: { /* same as TK_GE */ ** two values and push the resulting boolean value back onto the ** stack. */ -case OP_And: /* same as TK_AND */ -case OP_Or: { /* same as TK_OR */ +case OP_And: /* same as TK_AND, no-push */ +case OP_Or: { /* same as TK_OR, no-push */ Mem *pNos = &pTos[-1]; int v1, v2; /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */ @@ -1519,7 +1544,7 @@ case OP_Or: { /* same as TK_OR */ ** with its absolute value. If the top of the stack is NULL ** its value is unchanged. */ -case OP_Negative: /* same as TK_UMINUS */ +case OP_Negative: /* same as TK_UMINUS, no-push */ case OP_AbsValue: { assert( pTos>=p->aStack ); if( pTos->flags & MEM_Real ){ @@ -1552,7 +1577,7 @@ case OP_AbsValue: { ** with its complement. If the top of the stack is NULL its value ** is unchanged. */ -case OP_Not: { /* same as TK_NOT */ +case OP_Not: { /* same as TK_NOT, no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; /* Do nothing to NULLs */ Integerify(pTos); @@ -1568,7 +1593,7 @@ case OP_Not: { /* same as TK_NOT */ ** with its ones-complement. If the top of the stack is NULL its ** value is unchanged. */ -case OP_BitNot: { /* same as TK_BITNOT */ +case OP_BitNot: { /* same as TK_BITNOT, no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; /* Do nothing to NULLs */ Integerify(pTos); @@ -1583,7 +1608,7 @@ case OP_BitNot: { /* same as TK_BITNOT */ ** Do nothing. This instruction is often useful as a jump ** destination. */ -case OP_Noop: { +case OP_Noop: { /* no-push */ break; } @@ -1607,8 +1632,8 @@ case OP_Noop: { ** If the value popped of the stack is NULL, then take the jump if P1 ** is true and fall through if P1 is false. */ -case OP_If: -case OP_IfNot: { +case OP_If: /* no-push */ +case OP_IfNot: { /* no-push */ int c; assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ){ @@ -1629,7 +1654,7 @@ case OP_IfNot: { ** to P2. Pop the stack P1 times if P1>0. If P1<0 leave the stack ** unchanged. */ -case OP_IsNull: { /* same as TK_ISNULL */ +case OP_IsNull: { /* same as TK_ISNULL, no-push */ int i, cnt; Mem *pTerm; cnt = pOp->p1; @@ -1652,7 +1677,7 @@ case OP_IsNull: { /* same as TK_ISNULL */ ** stack if P1 times if P1 is greater than zero. If P1 is less than ** zero then leave the stack unchanged. */ -case OP_NotNull: { /* same as TK_NOTNULL */ +case OP_NotNull: { /* same as TK_NOTNULL, no-push */ int i, cnt; cnt = pOp->p1; if( cnt<0 ) cnt = -cnt; @@ -1673,7 +1698,7 @@ case OP_NotNull: { /* same as TK_NOTNULL */ ** If OP_KeyAsData is to be applied to cursor P1, it must be executed ** before this op-code. */ -case OP_SetNumColumns: { +case OP_SetNumColumns: { /* no-push */ Cursor *pC; assert( (pOp->p1)nCursor ); assert( p->apCsr[pOp->p1]!=0 ); @@ -2131,7 +2156,7 @@ case OP_MakeRecord: { ** database file has an index of 0 and the file used for temporary tables ** has an index of 1. */ -case OP_Statement: { +case OP_Statement: { /* no-push */ int i = pOp->p1; Btree *pBt; if( i>=0 && inDb && (pBt = db->aDb[i].pBt) && !(db->autoCommit) ){ @@ -2151,7 +2176,7 @@ case OP_Statement: { ** ** This instruction causes the VM to halt. */ -case OP_AutoCommit: { +case OP_AutoCommit: { /* no-push */ u8 i = pOp->p1; u8 rollback = pOp->p2; @@ -2212,7 +2237,7 @@ case OP_AutoCommit: { ** ** If P2 is zero, then a read-lock is obtained on the database file. */ -case OP_Transaction: { +case OP_Transaction: { /* no-push */ int i = pOp->p1; Btree *pBt; @@ -2275,7 +2300,7 @@ case OP_ReadCookie: { ** ** A transaction must be started before executing this opcode. */ -case OP_SetCookie: { +case OP_SetCookie: { /* no-push */ Db *pDb; assert( pOp->p2p1>=0 && pOp->p1nDb ); @@ -2311,7 +2336,7 @@ case OP_SetCookie: { ** to be executed (to establish a read lock) before this opcode is ** invoked. */ -case OP_VerifyCookie: { +case OP_VerifyCookie: { /* no-push */ int iMeta; Btree *pBt; assert( pOp->p1>=0 && pOp->p1nDb ); @@ -2371,8 +2396,8 @@ case OP_VerifyCookie: { ** ** See also OpenRead. */ -case OP_OpenRead: -case OP_OpenWrite: { +case OP_OpenRead: /* no-push */ +case OP_OpenWrite: { /* no-push */ int i = pOp->p1; int p2 = pOp->p2; int wrFlag; @@ -2460,7 +2485,7 @@ case OP_OpenWrite: { ** whereas "Temporary" in the context of CREATE TABLE means for the duration ** of the connection to the database. Same word; different meanings. */ -case OP_OpenTemp: { +case OP_OpenTemp: { /* no-push */ int i = pOp->p1; Cursor *pCx; assert( i>=0 ); @@ -2509,7 +2534,7 @@ case OP_OpenTemp: { ** A pseudo-table created by this opcode is useful for holding the ** NEW or OLD tables in a trigger. */ -case OP_OpenPseudo: { +case OP_OpenPseudo: { /* no-push */ int i = pOp->p1; Cursor *pCx; assert( i>=0 ); @@ -2527,7 +2552,7 @@ case OP_OpenPseudo: { ** Close a cursor previously opened as P1. If P1 is not ** currently open, this instruction is a no-op. */ -case OP_Close: { +case OP_Close: { /* no-push */ int i = pOp->p1; if( i>=0 && inCursor ){ sqlite3VdbeFreeCursor(p->apCsr[i]); @@ -2576,10 +2601,10 @@ case OP_Close: { ** ** See also: Found, NotFound, Distinct, MoveGt, MoveGe, MoveLt */ -case OP_MoveLt: -case OP_MoveLe: -case OP_MoveGe: -case OP_MoveGt: { +case OP_MoveLt: /* no-push */ +case OP_MoveLe: /* no-push */ +case OP_MoveGe: /* no-push */ +case OP_MoveGt: { /* no-push */ int i = pOp->p1; Cursor *pC; @@ -2688,9 +2713,9 @@ case OP_MoveGt: { ** ** See also: Distinct, Found, MoveTo, NotExists, IsUnique */ -case OP_Distinct: -case OP_NotFound: -case OP_Found: { +case OP_Distinct: /* no-push */ +case OP_NotFound: /* no-push */ +case OP_Found: { /* no-push */ int i = pOp->p1; int alreadyExists = 0; Cursor *pC; @@ -2739,7 +2764,7 @@ case OP_Found: { ** ** See also: Distinct, NotFound, NotExists, Found */ -case OP_IsUnique: { +case OP_IsUnique: { /* no-push */ int i = pOp->p1; Mem *pNos = &pTos[-1]; Cursor *pCx; @@ -2833,7 +2858,7 @@ case OP_IsUnique: { ** ** See also: Distinct, Found, MoveTo, NotFound, IsUnique */ -case OP_NotExists: { +case OP_NotExists: { /* no-push */ int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; @@ -3036,8 +3061,8 @@ case OP_NewRecno: { ** ** P1 may not be a pseudo-table opened using the OpenPseudo opcode. */ -case OP_PutIntKey: -case OP_PutStrKey: { +case OP_PutIntKey: /* no-push */ +case OP_PutStrKey: { /* no-push */ Mem *pNos = &pTos[-1]; int i = pOp->p1; Cursor *pC; @@ -3131,7 +3156,7 @@ case OP_PutStrKey: { ** ** If P1 is a pseudo-table, then this instruction is a no-op. */ -case OP_Delete: { +case OP_Delete: { /* no-push */ int i = pOp->p1; Cursor *pC; assert( i>=0 && inCursor ); @@ -3155,7 +3180,7 @@ case OP_Delete: { ** change counter (returned by subsequent calls to sqlite3_changes()) ** before it is reset. This is used by trigger programs. */ -case OP_ResetCount: { +case OP_ResetCount: { /* no-push */ if( pOp->p1 ){ sqlite3VdbeSetChanges(db, p->nChange); } @@ -3170,7 +3195,7 @@ case OP_ResetCount: { ** data off of the key rather than the data. This is used for ** processing compound selects. */ -case OP_KeyAsData: { +case OP_KeyAsData: { /* no-push */ int i = pOp->p1; Cursor *pC; assert( i>=0 && inCursor ); @@ -3346,7 +3371,7 @@ case OP_FullKey: { ** that occur while the cursor is on the null row will always push ** a NULL onto the stack. */ -case OP_NullRow: { +case OP_NullRow: { /* no-push */ int i = pOp->p1; Cursor *pC; @@ -3366,7 +3391,7 @@ case OP_NullRow: { ** If P2 is 0 or if the table or index is not empty, fall through ** to the following instruction. */ -case OP_Last: { +case OP_Last: { /* no-push */ int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; @@ -3397,7 +3422,7 @@ case OP_Last: { ** If P2 is 0 or if the table or index is not empty, fall through ** to the following instruction. */ -case OP_Rewind: { +case OP_Rewind: { /* no-push */ int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; @@ -3437,8 +3462,8 @@ case OP_Rewind: { ** to the following instruction. But if the cursor backup was successful, ** jump immediately to P2. */ -case OP_Prev: -case OP_Next: { +case OP_Prev: /* no-push */ +case OP_Next: { /* no-push */ Cursor *pC; BtCursor *pCrsr; @@ -3479,7 +3504,7 @@ case OP_Next: { ** is rolled back. If P3 is not null, then it becomes part of the ** error message returned with the SQLITE_CONSTRAINT. */ -case OP_IdxPut: { +case OP_IdxPut: { /* no-push */ int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; @@ -3531,7 +3556,7 @@ case OP_IdxPut: { ** The top of the stack is an index key built using the MakeIdxKey opcode. ** This opcode removes that entry from the index. */ -case OP_IdxDelete: { +case OP_IdxDelete: { /* no-push */ int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; @@ -3633,9 +3658,9 @@ case OP_IdxRecno: { ** an epsilon prior to the comparison. This makes the opcode work ** like IdxLE. */ -case OP_IdxLT: -case OP_IdxGT: -case OP_IdxGE: { +case OP_IdxLT: /* no-push */ +case OP_IdxGT: /* no-push */ +case OP_IdxGE: { /* no-push */ int i= pOp->p1; BtCursor *pCrsr; Cursor *pC; @@ -3679,7 +3704,7 @@ case OP_IdxGE: { ** ** The index entry is always popped from the stack. */ -case OP_IdxIsNull: { +case OP_IdxIsNull: { /* no-push */ int i = pOp->p1; int k, n; const char *z; @@ -3753,7 +3778,7 @@ case OP_Destroy: { ** ** See also: Destroy */ -case OP_Clear: { +case OP_Clear: { /* no-push */ rc = sqlite3BtreeClearTable(db->aDb[pOp->p2].pBt, pOp->p1); break; } @@ -3811,7 +3836,7 @@ case OP_CreateTable: { ** This opcode invokes the parser to create a new virtual machine, ** then runs the new virtual machine. It is thus a reentrant opcode. */ -case OP_ParseSchema: { +case OP_ParseSchema: { /* no-push */ char *zSql; int iDb = pOp->p1; const char *zMaster; @@ -3819,7 +3844,7 @@ case OP_ParseSchema: { assert( iDb>=0 && iDbnDb ); if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break; - zMaster = iDb==1 ? TEMP_MASTER_NAME : MASTER_NAME; + zMaster = SCHEMA_TABLE(iDb); initData.db = db; initData.pzErrMsg = &p->zErrMsg; zSql = sqlite3MPrintf( @@ -3843,7 +3868,7 @@ case OP_ParseSchema: { ** is dropped in order to keep the internal representation of the ** schema consistent with what is on disk. */ -case OP_DropTable: { +case OP_DropTable: { /* no-push */ sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p3); break; } @@ -3855,7 +3880,7 @@ case OP_DropTable: { ** is dropped in order to keep the internal representation of the ** schema consistent with what is on disk. */ -case OP_DropIndex: { +case OP_DropIndex: { /* no-push */ sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p3); break; } @@ -3867,7 +3892,7 @@ case OP_DropIndex: { ** is dropped in order to keep the internal representation of the ** schema consistent with what is on disk. */ -case OP_DropTrigger: { +case OP_DropTrigger: { /* no-push */ sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p3); break; } @@ -3932,7 +3957,7 @@ case OP_IntegrityCk: { ** Write the integer on the top of the stack ** into the temporary storage list. */ -case OP_ListWrite: { +case OP_ListWrite: { /* no-push */ Keylist *pKeylist; assert( pTos>=p->aStack ); pKeylist = p->pList; @@ -3956,7 +3981,7 @@ case OP_ListWrite: { ** ** Rewind the temporary buffer back to the beginning. */ -case OP_ListRewind: { +case OP_ListRewind: { /* no-push */ /* What this opcode codes, really, is reverse the order of the ** linked list of Keylist structures so that they are read out ** in the same order that they were read in. */ @@ -4003,7 +4028,7 @@ case OP_ListRead: { ** ** Reset the temporary storage buffer so that it holds nothing. */ -case OP_ListReset: { +case OP_ListReset: { /* no-push */ if( p->pList ){ sqlite3VdbeKeylistFree(p->pList); p->pList = 0; @@ -4018,7 +4043,7 @@ case OP_ListReset: { ** AggContextPop opcode. ** */ -case OP_AggContextPush: { +case OP_AggContextPush: { /* no-push */ p->pAgg++; assert( p->pAgg<&p->apAgg[p->nAgg] ); break; @@ -4029,7 +4054,7 @@ case OP_AggContextPush: { ** Restore the aggregator to the state it was in when AggContextPush ** was last called. Any data in the current aggregator is deleted. */ -case OP_AggContextPop: { +case OP_AggContextPop: { /* no-push */ p->pAgg--; assert( p->pAgg>=p->apAgg ); break; @@ -4043,7 +4068,7 @@ case OP_AggContextPop: { ** opcode. The context stores the last insert row id, the last statement change ** count, and the current statement change count. */ -case OP_ContextPush: { +case OP_ContextPush: { /* no-push */ int i = p->contextStackTop++; Context *pContext; @@ -4068,7 +4093,7 @@ case OP_ContextPush: { ** executed. The context stores the last insert row id, the last statement ** change count, and the current statement change count. */ -case OP_ContextPop: { +case OP_ContextPop: { /* no-push */ Context *pContext = &p->contextStack[--p->contextStackTop]; assert( p->contextStackTop>=0 ); db->lastRowid = pContext->lastRowid; @@ -4085,7 +4110,7 @@ case OP_ContextPop: { ** and put them on the sorter. The key and data should have been ** made using the MakeRecord opcode. */ -case OP_SortPut: { +case OP_SortPut: { /* no-push */ Mem *pNos = &pTos[-1]; Sorter *pSorter; assert( pNos>=p->aStack ); @@ -4109,7 +4134,7 @@ case OP_SortPut: { ** mergesort. The P3 argument is a pointer to a KeyInfo structure ** that describes the keys to be sorted. */ -case OP_Sort: { +case OP_Sort: { /* no-push */ int i; KeyInfo *pKeyInfo = (KeyInfo*)pOp->p3; Sorter *pElem; @@ -4171,7 +4196,7 @@ case OP_SortNext: { ** ** Remove any elements that remain on the sorter. */ -case OP_SortReset: { +case OP_SortReset: { /* no-push */ sqlite3VdbeSorterReset(p); break; } @@ -4186,7 +4211,7 @@ case OP_SortReset: { ** stack is popped once if P2 is 1. If P2 is zero, then ** the original data remains on the stack. */ -case OP_MemStore: { +case OP_MemStore: { /* no-push */ assert( pTos>=p->aStack ); assert( pOp->p1>=0 && pOp->p1nMem ); rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], pTos); @@ -4225,7 +4250,7 @@ case OP_MemLoad: { ** This instruction throws an error if the memory cell is not initially ** an integer. */ -case OP_MemMax: { +case OP_MemMax: { /* no-push */ int i = pOp->p1; Mem *pMem; assert( pTos>=p->aStack ); @@ -4249,7 +4274,7 @@ case OP_MemMax: { ** This instruction throws an error if the memory cell is not initially ** an integer. */ -case OP_MemIncr: { +case OP_MemIncr: { /* no-push */ int i = pOp->p1; Mem *pMem; assert( i>=0 && inMem ); @@ -4267,7 +4292,7 @@ case OP_MemIncr: { ** If the value of memory cell P1 is 1 or greater, jump to P2. This ** opcode assumes that memory cell P1 holds an integer value. */ -case OP_IfMemPos: { +case OP_IfMemPos: { /* no-push */ int i = pOp->p1; Mem *pMem; assert( i>=0 && inMem ); @@ -4289,7 +4314,7 @@ case OP_IfMemPos: { ** there is no GROUP BY expression). In this case it is illegal to invoke ** OP_AggFocus. */ -case OP_AggReset: { +case OP_AggReset: { /* no-push */ assert( !pOp->p3 || pOp->p3type==P3_KEYINFO ); if( pOp->p1 ){ rc = sqlite3VdbeAggReset(0, p->pAgg, (KeyInfo *)pOp->p3); @@ -4313,7 +4338,7 @@ case OP_AggReset: { ** The aggregate will operate out of aggregate column P2. ** P3 is a pointer to the FuncDef structure for the function. */ -case OP_AggInit: { +case OP_AggInit: { /* no-push */ int i = pOp->p2; assert( i>=0 && ipAgg->nMem ); p->pAgg->apFunc[i] = (FuncDef*)pOp->p3; @@ -4331,7 +4356,7 @@ case OP_AggInit: { ** Ideally, this index would be another parameter, but there are ** no free parameters left. The integer is popped from the stack. */ -case OP_AggFunc: { +case OP_AggFunc: { /* no-push */ int n = pOp->p2; int i; Mem *pMem, *pRec; @@ -4389,7 +4414,7 @@ case OP_AggFunc: { ** zero or more AggNext operations. You must not execute an AggFocus ** in between an AggNext and an AggReset. */ -case OP_AggFocus: { +case OP_AggFocus: { /* no-push */ char *zKey; int nKey; int res; @@ -4423,7 +4448,7 @@ case OP_AggFocus: { ** Move the top of the stack into the P2-th field of the current ** aggregate. String values are duplicated into new memory. */ -case OP_AggSet: { +case OP_AggSet: { /* no-push */ AggElem *pFocus; int i = pOp->p2; pFocus = p->pAgg->pCurrent; @@ -4488,7 +4513,7 @@ case OP_AggGet: { ** zero or more AggNext operations. You must not execute an AggFocus ** in between an AggNext and an AggReset. */ -case OP_AggNext: { +case OP_AggNext: { /* no-push */ int res; assert( rc==SQLITE_OK ); CHECK_FOR_INTERRUPT; @@ -4549,7 +4574,7 @@ case OP_AggNext: { ** machines to be created and run. It may not be called from within ** a transaction. */ -case OP_Vacuum: { +case OP_Vacuum: { /* no-push */ if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; rc = sqlite3RunVacuum(&p->zErrMsg, db); if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse; @@ -4565,7 +4590,7 @@ case OP_Vacuum: { ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero, ** then only the currently executing statement is affected. */ -case OP_Expire: { +case OP_Expire: { /* no-push */ if( !pOp->p1 ){ sqlite3ExpirePreparedStatements(db); }else{ @@ -4592,6 +4617,9 @@ default: { *****************************************************************************/ } + /* Make sure the stack limit was not exceeded */ + assert( pTos<=pStackLimit ); + #ifdef VDBE_PROFILE { long long elapse = hwtime() - start; diff --git a/db/sqlite3/src/vdbe.h b/db/sqlite3/src/vdbe.h index 37882f251b0..903b676124c 100644 --- a/db/sqlite3/src/vdbe.h +++ b/db/sqlite3/src/vdbe.h @@ -15,7 +15,7 @@ ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** -** $Id: vdbe.h,v 1.93 2005/03/09 12:26:51 danielk1977 Exp $ +** $Id: vdbe.h,v 1.94 2005/03/23 01:48:48 drh Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ @@ -78,7 +78,7 @@ typedef struct VdbeOpList VdbeOpList; ** from a single sqliteMalloc(). But no copy is made and the calling ** function should *not* try to free the KeyInfo. */ -#define P3_KEYINFO_HANDOFF (-7) +#define P3_KEYINFO_HANDOFF (-9) /* ** The following macro converts a relative address in the p2 field diff --git a/db/sqlite3/src/vdbeInt.h b/db/sqlite3/src/vdbeInt.h index 42682d1e25a..37dada46dac 100644 --- a/db/sqlite3/src/vdbeInt.h +++ b/db/sqlite3/src/vdbeInt.h @@ -406,6 +406,7 @@ int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); void sqlite3VdbeMemRelease(Mem *p); #ifndef NDEBUG void sqlite3VdbeMemSanity(Mem*, u8); +int sqlite3VdbeOpcodeNoPush(u8); #endif int sqlite3VdbeMemTranslate(Mem*, u8); void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf); diff --git a/db/sqlite3/src/vdbeapi.c b/db/sqlite3/src/vdbeapi.c index ca1612875ab..663bc9a60b2 100644 --- a/db/sqlite3/src/vdbeapi.c +++ b/db/sqlite3/src/vdbeapi.c @@ -622,3 +622,15 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ } return 0; } + +int sqlite3_bind_parameter_indexes( + sqlite3_stmt *pStmt, + const char *zName, + int **pIndexes +){ + return 0; +} + +void sqlite3_free_parameter_indexes(int *pIndexes) +{ +} diff --git a/db/sqlite3/src/vdbeaux.c b/db/sqlite3/src/vdbeaux.c index fa67a41abfb..e8a324e9cbe 100644 --- a/db/sqlite3/src/vdbeaux.c +++ b/db/sqlite3/src/vdbeaux.c @@ -57,10 +57,16 @@ void sqlite3VdbeTrace(Vdbe *p, FILE *trace){ /* ** Resize the Vdbe.aOp array so that it contains at least N +** elements. If the Vdbe is in VDBE_MAGIC_RUN state, then +** the Vdbe.aOp array will be sized to contain exactly N ** elements. */ static void resizeOpArray(Vdbe *p, int N){ - if( p->nOpAllocmagic==VDBE_MAGIC_RUN ){ + assert( N==p->nOp ); + p->nOpAlloc = N; + p->aOp = sqliteRealloc(p->aOp, N*sizeof(Op)); + }else if( p->nOpAllocnOpAlloc; p->nOpAlloc = N+100; p->aOp = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op)); @@ -160,25 +166,92 @@ void sqlite3VdbeResolveLabel(Vdbe *p, int x){ } } +/* +** Return non-zero if opcode 'op' is guarenteed not to push more values +** onto the VDBE stack than it pops off. +*/ +static int opcodeNoPush(u8 op){ + /* The 10 NOPUSH_MASK_n constants are defined in the automatically + ** generated header file opcodes.h. Each is a 16-bit bitmask, one + ** bit corresponding to each opcode implemented by the virtual + ** machine in vdbe.c. The bit is true if the word "no-push" appears + ** in a comment on the same line as the "case OP_XXX:" in + ** sqlite3VdbeExec() in vdbe.c. + ** + ** If the bit is true, then the corresponding opcode is guarenteed not + ** to grow the stack when it is executed. Otherwise, it may grow the + ** stack by at most one entry. + ** + ** NOPUSH_MASK_0 corresponds to opcodes 0 to 15. NOPUSH_MASK_1 contains + ** one bit for opcodes 16 to 31, and so on. + ** + ** 16-bit bitmasks (rather than 32-bit) are specified in opcodes.h + ** because the file is generated by an awk program. Awk manipulates + ** all numbers as floating-point and we don't want to risk a rounding + ** error if someone builds with an awk that uses (for example) 32-bit + ** IEEE floats. + */ + static u32 masks[5] = { + NOPUSH_MASK_0 + (NOPUSH_MASK_1<<16), + NOPUSH_MASK_2 + (NOPUSH_MASK_3<<16), + NOPUSH_MASK_4 + (NOPUSH_MASK_5<<16), + NOPUSH_MASK_6 + (NOPUSH_MASK_7<<16), + NOPUSH_MASK_8 + (NOPUSH_MASK_9<<16) + }; + return (masks[op>>5] & (1<<(op&0x1F))); +} + +#ifndef NDEBUG +int sqlite3VdbeOpcodeNoPush(u8 op){ + return opcodeNoPush(op); +} +#endif + /* ** Loop through the program looking for P2 values that are negative. ** Each such value is a label. Resolve the label by setting the P2 ** value to its correct non-zero value. ** ** This routine is called once after all opcodes have been inserted. +** +** Variable *pMaxFuncArgs is set to the maximum value of any P1 argument +** to an OP_Function or P2 to an OP_AggFunc opcode. This is used by +** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array. +** +** The integer *pMaxStack is set to the maximum number of vdbe stack +** entries that static analysis reveals this program might need. */ -static void resolveP2Values(Vdbe *p){ +static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs, int *pMaxStack){ int i; + int nMaxArgs = 0; + int nMaxStack = p->nOp; Op *pOp; int *aLabel = p->aLabel; - if( aLabel==0 ) return; for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ + u8 opcode = pOp->opcode; + + /* Todo: Maybe OP_AggFunc should change to use P1 in the same + * way as OP_Function. + */ + if( opcode==OP_Function ){ + if( pOp->p1>nMaxArgs ) nMaxArgs = pOp->p1; + }else if( opcode==OP_AggFunc ){ + if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; + } + + if( opcodeNoPush(opcode) ){ + nMaxStack--; + } + if( pOp->p2>=0 ) continue; assert( -1-pOp->p2nLabel ); pOp->p2 = aLabel[-1-pOp->p2]; } sqliteFree(p->aLabel); p->aLabel = 0; + + *pMaxFuncArgs = nMaxArgs; + *pMaxStack = nMaxStack; } /* @@ -603,6 +676,13 @@ void sqlite3VdbeMakeReady( */ assert( p->nOp>0 ); + /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. This + * is because the call to resizeOpArray() below may shrink the + * p->aOp[] array to save memory if called when in VDBE_MAGIC_RUN + * state. + */ + p->magic = VDBE_MAGIC_RUN; + /* No instruction ever pushes more than a single element onto the ** stack. And the stack never grows on successive executions of the ** same loop. So the total number of instructions is an upper bound @@ -611,12 +691,16 @@ void sqlite3VdbeMakeReady( ** Allocation all the stack space we will ever need. */ if( p->aStack==0 ){ - resolveP2Values(p); + int nArg; /* Maximum number of args passed to a user function. */ + int nStack; /* Maximum number of stack entries required */ + resolveP2Values(p, &nArg, &nStack); + resizeOpArray(p, p->nOp); assert( nVar>=0 ); - n = isExplain ? 10 : p->nOp; + assert( nStacknOp ); + nStack = isExplain ? 10 : nStack; p->aStack = sqliteMalloc( - n*sizeof(p->aStack[0]) /* aStack */ - + n*sizeof(Mem*) /* apArg */ + nStack*sizeof(p->aStack[0]) /* aStack */ + + nArg*sizeof(Mem*) /* apArg */ + nVar*sizeof(Mem) /* aVar */ + nVar*sizeof(char*) /* azVar */ + nMem*sizeof(Mem) /* aMem */ @@ -624,13 +708,13 @@ void sqlite3VdbeMakeReady( + nAgg*sizeof(Agg) /* Aggregate contexts */ ); if( !sqlite3_malloc_failed ){ - p->aMem = &p->aStack[n]; + p->aMem = &p->aStack[nStack]; p->nMem = nMem; p->aVar = &p->aMem[nMem]; p->nVar = nVar; p->okVar = 0; p->apArg = (Mem**)&p->aVar[nVar]; - p->azVar = (char**)&p->apArg[n]; + p->azVar = (char**)&p->apArg[nArg]; p->apCsr = (Cursor**)&p->azVar[nVar]; if( nAgg>0 ){ p->nAgg = nAgg;