diff options
author | Wez Furlong <wez@php.net> | 2004-07-10 12:25:35 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2004-07-10 12:25:35 +0000 |
commit | 902f9d52cfaf665c12b6b033da8fbf8ee8150ed0 (patch) | |
tree | 344507642ff8f13091214b8268d115c3132bc3c4 | |
parent | 1da45c2873d59fffc6535010b168824b2af5db67 (diff) | |
download | php-git-902f9d52cfaf665c12b6b033da8fbf8ee8150ed0.tar.gz |
Upgrade bundled library to 2.8.14 + misc fixes
(http://www.sqlite.org/cvstrac/chngview?cn=1742)
44 files changed, 5987 insertions, 5393 deletions
diff --git a/ext/sqlite/config.m4 b/ext/sqlite/config.m4 index 2e8fdd9586..797b6a00c0 100644 --- a/ext/sqlite/config.m4 +++ b/ext/sqlite/config.m4 @@ -68,18 +68,21 @@ if test "$PHP_SQLITE" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/libsqlite/src) AC_CHECK_SIZEOF(char *,4) AC_DEFINE(SQLITE_PTR_SZ, SIZEOF_CHAR_P, [Size of a pointer]) - dnl use latin 1 for now; the utf-8 handling in funcs.c uses assert(), - dnl which is a bit silly and something we want to avoid - SQLITE_ENCODING="ISO8859" - dnl SQLITE_ENCODING="UTF-8" - dnl AC_DEFINE(SQLITE_UTF8,1,[if SQLite should use utf-8 encoding]) + dnl use latin 1 for SQLite older than 2.8.9; the utf-8 handling + dnl in funcs.c uses assert(), which is a bit silly and something + dnl we want to avoid. This assert() was removed in SQLite 2.8.9. + if test "$PHP_SQLITE_UTF8" = "yes"; then + SQLITE_ENCODING="UTF8" + AC_DEFINE(SQLITE_UTF8, 1, [ ]) + else + SQLITE_ENCODING="ISO8859" + fi PHP_SUBST(SQLITE_ENCODING) - AC_PATH_PROG(LEMON,lemon,no) - PHP_SUBST(LEMON) - SQLITE_VERSION=`cat $ext_srcdir/libsqlite/VERSION` PHP_SUBST(SQLITE_VERSION) + + sed -e s/--VERS--/$SQLITE_VERSION/ -e s/--ENCODING--/$SQLITE_ENCODING/ $ext_srcdir/libsqlite/src/sqlite.h.in >$ext_srcdir/libsqlite/src/sqlite.h if test "$ext_shared" = "no"; then echo '#include "php_config.h"' > $ext_srcdir/libsqlite/src/config.h @@ -96,8 +99,6 @@ if test "$PHP_SQLITE" != "no"; then #endif EOF - PHP_ADD_MAKEFILE_FRAGMENT - fi AC_CHECK_FUNCS(usleep nanosleep) diff --git a/ext/sqlite/libsqlite/VERSION b/ext/sqlite/libsqlite/VERSION index 38bc52136e..63cb62ffdb 100644 --- a/ext/sqlite/libsqlite/VERSION +++ b/ext/sqlite/libsqlite/VERSION @@ -1 +1 @@ -2.8.11 +2.8.14 diff --git a/ext/sqlite/libsqlite/src/attach.c b/ext/sqlite/libsqlite/src/attach.c index 5269238e0f..4e445ec413 100644 --- a/ext/sqlite/libsqlite/src/attach.c +++ b/ext/sqlite/libsqlite/src/attach.c @@ -23,12 +23,15 @@ ** The pFilename and pDbname arguments are the tokens that define the ** filename and dbname in the ATTACH statement. */ -void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){ +void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname, Token *pKey){ Db *aNew; int rc, i; char *zFile, *zName; sqlite *db; + Vdbe *v; + v = sqliteGetVdbe(pParse); + sqliteVdbeAddOp(v, OP_Halt, 0, 0); if( pParse->explain ) return; db = pParse->db; if( db->file_format<4 ){ @@ -88,6 +91,22 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){ if( rc ){ sqliteErrorMsg(pParse, "unable to open database: %s", zFile); } +#if SQLITE_HAS_CODEC + { + extern int sqliteCodecAttach(sqlite*, int, void*, int); + char *zKey = 0; + int nKey; + if( pKey && pKey->z && pKey->n ){ + sqliteSetNString(&zKey, pKey->z, pKey->n, 0); + sqliteDequote(zKey); + nKey = strlen(zKey); + }else{ + zKey = 0; + nKey = 0; + } + sqliteCodecAttach(db, db->nDb-1, zKey, nKey); + } +#endif sqliteFree(zFile); db->flags &= ~SQLITE_Initialized; if( pParse->nErr ) return; @@ -117,13 +136,18 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){ void sqliteDetach(Parse *pParse, Token *pDbname){ int i; sqlite *db; + Vdbe *v; + Db *pDb; + v = sqliteGetVdbe(pParse); + sqliteVdbeAddOp(v, OP_Halt, 0, 0); if( pParse->explain ) return; db = pParse->db; for(i=0; i<db->nDb; i++){ - if( db->aDb[i].pBt==0 || db->aDb[i].zName==0 ) continue; - if( strlen(db->aDb[i].zName)!=pDbname->n ) continue; - if( sqliteStrNICmp(db->aDb[i].zName, pDbname->z, pDbname->n)==0 ) break; + pDb = &db->aDb[i]; + if( pDb->pBt==0 || pDb->zName==0 ) continue; + if( strlen(pDb->zName)!=pDbname->n ) continue; + if( sqliteStrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break; } if( i>=db->nDb ){ sqliteErrorMsg(pParse, "no such database: %T", pDbname); @@ -138,10 +162,11 @@ void sqliteDetach(Parse *pParse, Token *pDbname){ return; } #endif /* SQLITE_OMIT_AUTHORIZATION */ - sqliteBtreeClose(db->aDb[i].pBt); - db->aDb[i].pBt = 0; - sqliteFree(db->aDb[i].zName); + sqliteBtreeClose(pDb->pBt); + pDb->pBt = 0; + sqliteFree(pDb->zName); sqliteResetInternalSchema(db, i); + if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux); db->nDb--; if( i<db->nDb ){ db->aDb[i] = db->aDb[db->nDb]; diff --git a/ext/sqlite/libsqlite/src/auth.c b/ext/sqlite/libsqlite/src/auth.c index 06b8126ae0..3f861c710d 100644 --- a/ext/sqlite/libsqlite/src/auth.c +++ b/ext/sqlite/libsqlite/src/auth.c @@ -85,12 +85,9 @@ int sqlite_set_authorizer( ** user-supplied authorization function returned an illegal value. */ static void sqliteAuthBadReturnCode(Parse *pParse, int rc){ - char zBuf[20]; - sprintf(zBuf, "(%d)", rc); - sqliteSetString(&pParse->zErrMsg, "illegal return value ", zBuf, - " from the authorization function - should be SQLITE_OK, " - "SQLITE_IGNORE, or SQLITE_DENY", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "illegal return value (%d) from the " + "authorization function - should be SQLITE_OK, SQLITE_IGNORE, " + "or SQLITE_DENY", rc); pParse->rc = SQLITE_MISUSE; } @@ -150,13 +147,11 @@ void sqliteAuthRead( pExpr->op = TK_NULL; }else if( rc==SQLITE_DENY ){ if( db->nDb>2 || pExpr->iDb!=0 ){ - sqliteSetString(&pParse->zErrMsg,"access to ", zDBase, ".", - pTab->zName, ".", zCol, " is prohibited", (char*)0); + sqliteErrorMsg(pParse, "access to %s.%s.%s is prohibited", + zDBase, pTab->zName, zCol); }else{ - sqliteSetString(&pParse->zErrMsg,"access to ", pTab->zName, ".", - zCol, " is prohibited", (char*)0); + sqliteErrorMsg(pParse, "access to %s.%s is prohibited", pTab->zName,zCol); } - pParse->nErr++; pParse->rc = SQLITE_AUTH; }else if( rc!=SQLITE_OK ){ sqliteAuthBadReturnCode(pParse, rc); @@ -179,14 +174,13 @@ int sqliteAuthCheck( sqlite *db = pParse->db; int rc; - if( db->xAuth==0 ){ + if( db->init.busy || db->xAuth==0 ){ return SQLITE_OK; } rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext); if( rc==SQLITE_DENY ){ - sqliteSetString(&pParse->zErrMsg, "not authorized", (char*)0); + sqliteErrorMsg(pParse, "not authorized"); pParse->rc = SQLITE_AUTH; - pParse->nErr++; }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){ rc = SQLITE_DENY; sqliteAuthBadReturnCode(pParse, rc); diff --git a/ext/sqlite/libsqlite/src/btree.c b/ext/sqlite/libsqlite/src/btree.c index 1133b1a353..a367092501 100644 --- a/ext/sqlite/libsqlite/src/btree.c +++ b/ext/sqlite/libsqlite/src/btree.c @@ -210,13 +210,13 @@ struct CellHdr { ** The maximum number of database entries that can be held in a single ** page of the database. */ -#define MX_CELL ((SQLITE_PAGE_SIZE-sizeof(PageHdr))/MIN_CELL_SIZE) +#define MX_CELL ((SQLITE_USABLE_SIZE-sizeof(PageHdr))/MIN_CELL_SIZE) /* ** The amount of usable space on a single page of the BTree. This is the ** page size minus the overhead of the page header. */ -#define USABLE_SPACE (SQLITE_PAGE_SIZE - sizeof(PageHdr)) +#define USABLE_SPACE (SQLITE_USABLE_SIZE - sizeof(PageHdr)) /* ** The maximum amount of payload (in bytes) that can be stored locally for @@ -261,7 +261,7 @@ struct FreeBlk { /* ** The number of bytes of payload that will fit on a single overflow page. */ -#define OVERFLOW_SIZE (SQLITE_PAGE_SIZE-sizeof(Pgno)) +#define OVERFLOW_SIZE (SQLITE_USABLE_SIZE-sizeof(Pgno)) /* ** When the key and data for a single entry in the BTree will not fit in @@ -319,7 +319,7 @@ struct FreelistInfo { ** The pageDestructor() routine handles that chore. */ struct MemPage { - union { + union u_page_data { char aDisk[SQLITE_PAGE_SIZE]; /* Page data stored on disk */ PageHdr hdr; /* Overlay page header */ } u; @@ -338,7 +338,7 @@ struct MemPage { ** to the end. EXTRA_SIZE is the number of bytes of space needed to hold ** that extra information. */ -#define EXTRA_SIZE (sizeof(MemPage)-SQLITE_PAGE_SIZE) +#define EXTRA_SIZE (sizeof(MemPage)-sizeof(union u_page_data)) /* ** Everything we need to know about an open database @@ -421,7 +421,7 @@ static int cellSize(Btree *pBt, Cell *pCell){ static void defragmentPage(Btree *pBt, MemPage *pPage){ int pc, i, n; FreeBlk *pFBlk; - char newPage[SQLITE_PAGE_SIZE]; + char newPage[SQLITE_USABLE_SIZE]; assert( sqlitepager_iswriteable(pPage) ); assert( pPage->isInit ); @@ -434,7 +434,7 @@ static void defragmentPage(Btree *pBt, MemPage *pPage){ /* This routine should never be called on an overfull page. The ** following asserts verify that constraint. */ assert( Addr(pCell) > Addr(pPage) ); - assert( Addr(pCell) < Addr(pPage) + SQLITE_PAGE_SIZE ); + assert( Addr(pCell) < Addr(pPage) + SQLITE_USABLE_SIZE ); n = cellSize(pBt, pCell); pCell->h.iNext = SWAB16(pBt, pc + n); @@ -442,16 +442,16 @@ static void defragmentPage(Btree *pBt, MemPage *pPage){ pPage->apCell[i] = (Cell*)&pPage->u.aDisk[pc]; pc += n; } - assert( pPage->nFree==SQLITE_PAGE_SIZE-pc ); + assert( pPage->nFree==SQLITE_USABLE_SIZE-pc ); memcpy(pPage->u.aDisk, newPage, pc); if( pPage->nCell>0 ){ pPage->apCell[pPage->nCell-1]->h.iNext = 0; } pFBlk = (FreeBlk*)&pPage->u.aDisk[pc]; - pFBlk->iSize = SWAB16(pBt, SQLITE_PAGE_SIZE - pc); + pFBlk->iSize = SWAB16(pBt, SQLITE_USABLE_SIZE - pc); pFBlk->iNext = 0; pPage->u.hdr.firstFree = SWAB16(pBt, pc); - memset(&pFBlk[1], 0, SQLITE_PAGE_SIZE - pc - sizeof(FreeBlk)); + memset(&pFBlk[1], 0, SQLITE_USABLE_SIZE - pc - sizeof(FreeBlk)); } /* @@ -483,7 +483,7 @@ static int allocateSpace(Btree *pBt, MemPage *pPage, int nByte){ pIdx = &pPage->u.hdr.firstFree; p = (FreeBlk*)&pPage->u.aDisk[SWAB16(pBt, *pIdx)]; while( (iSize = SWAB16(pBt, p->iSize))<nByte ){ - assert( cnt++ < SQLITE_PAGE_SIZE/4 ); + assert( cnt++ < SQLITE_USABLE_SIZE/4 ); if( p->iNext==0 ){ defragmentPage(pBt, pPage); pIdx = &pPage->u.hdr.firstFree; @@ -598,12 +598,12 @@ static int initPage(Bt *pBt, MemPage *pPage, Pgno pgnoThis, MemPage *pParent){ freeSpace = USABLE_SPACE; idx = SWAB16(pBt, pPage->u.hdr.firstCell); while( idx!=0 ){ - if( idx>SQLITE_PAGE_SIZE-MIN_CELL_SIZE ) goto page_format_error; + if( idx>SQLITE_USABLE_SIZE-MIN_CELL_SIZE ) goto page_format_error; if( idx<sizeof(PageHdr) ) goto page_format_error; if( idx!=ROUNDUP(idx) ) goto page_format_error; pCell = (Cell*)&pPage->u.aDisk[idx]; sz = cellSize(pBt, pCell); - if( idx+sz > SQLITE_PAGE_SIZE ) goto page_format_error; + if( idx+sz > SQLITE_USABLE_SIZE ) goto page_format_error; freeSpace -= sz; pPage->apCell[pPage->nCell++] = pCell; idx = SWAB16(pBt, pCell->h.iNext); @@ -612,7 +612,7 @@ static int initPage(Bt *pBt, MemPage *pPage, Pgno pgnoThis, MemPage *pParent){ idx = SWAB16(pBt, pPage->u.hdr.firstFree); while( idx!=0 ){ int iNext; - if( idx>SQLITE_PAGE_SIZE-sizeof(FreeBlk) ) goto page_format_error; + if( idx>SQLITE_USABLE_SIZE-sizeof(FreeBlk) ) goto page_format_error; if( idx<sizeof(PageHdr) ) goto page_format_error; pFBlk = (FreeBlk*)&pPage->u.aDisk[idx]; pPage->nFree += SWAB16(pBt, pFBlk->iSize); @@ -640,13 +640,13 @@ static void zeroPage(Btree *pBt, MemPage *pPage){ PageHdr *pHdr; FreeBlk *pFBlk; assert( sqlitepager_iswriteable(pPage) ); - memset(pPage, 0, SQLITE_PAGE_SIZE); + memset(pPage, 0, SQLITE_USABLE_SIZE); pHdr = &pPage->u.hdr; pHdr->firstCell = 0; pHdr->firstFree = SWAB16(pBt, sizeof(*pHdr)); pFBlk = (FreeBlk*)&pHdr[1]; pFBlk->iNext = 0; - pPage->nFree = SQLITE_PAGE_SIZE - sizeof(*pHdr); + pPage->nFree = SQLITE_USABLE_SIZE - sizeof(*pHdr); pFBlk->iSize = SWAB16(pBt, pPage->nFree); pPage->nCell = 0; pPage->isOverfull = 0; @@ -697,7 +697,7 @@ int sqliteBtreeOpen( assert( sizeof(PageHdr)==8 ); assert( sizeof(CellHdr)==12 ); assert( sizeof(FreeBlk)==4 ); - assert( sizeof(OverflowPage)==SQLITE_PAGE_SIZE ); + assert( sizeof(OverflowPage)==SQLITE_USABLE_SIZE ); assert( sizeof(FreelistInfo)==OVERFLOW_SIZE ); assert( sizeof(ptr)==sizeof(char*) ); assert( sizeof(uptr)==sizeof(ptr) ); @@ -793,7 +793,7 @@ static int lockBtree(Btree *pBt){ PageOne *pP1 = pBt->page1; if( strcmp(pP1->zMagic,zMagicHeader)!=0 || (pP1->iMagic!=MAGIC && swab32(pP1->iMagic)!=MAGIC) ){ - rc = SQLITE_CORRUPT; + rc = SQLITE_NOTADB; goto page1_init_failed; } pBt->needSwab = pP1->iMagic!=MAGIC; @@ -1031,10 +1031,15 @@ static int fileBtreeRollbackCkpt(Btree *pBt){ ** root page of a b-tree. If it is not, then the cursor acquired ** will not work correctly. */ -static int fileBtreeCursor(Btree *pBt, int iTable, int wrFlag, BtCursor **ppCur){ +static +int fileBtreeCursor(Btree *pBt, int iTable, int wrFlag, BtCursor **ppCur){ int rc; BtCursor *pCur, *pRing; + if( pBt->readOnly && wrFlag ){ + *ppCur = 0; + return SQLITE_READONLY; + } if( pBt->page1==0 ){ rc = lockBtree(pBt); if( rc!=SQLITE_OK ){ @@ -2082,7 +2087,7 @@ static void relinkCellList(Btree *pBt, MemPage *pPage){ pIdx = &pPage->u.hdr.firstCell; for(i=0; i<pPage->nCell; i++){ int idx = Addr(pPage->apCell[i]) - Addr(pPage); - assert( idx>0 && idx<SQLITE_PAGE_SIZE ); + assert( idx>0 && idx<SQLITE_USABLE_SIZE ); *pIdx = SWAB16(pBt, idx); pIdx = &pPage->apCell[i]->h.iNext; } @@ -2098,7 +2103,7 @@ static void relinkCellList(Btree *pBt, MemPage *pPage){ static void copyPage(MemPage *pTo, MemPage *pFrom){ uptr from, to; int i; - memcpy(pTo->u.aDisk, pFrom->u.aDisk, SQLITE_PAGE_SIZE); + memcpy(pTo->u.aDisk, pFrom->u.aDisk, SQLITE_USABLE_SIZE); pTo->pParent = 0; pTo->isInit = 1; pTo->nCell = pFrom->nCell; @@ -2108,7 +2113,7 @@ static void copyPage(MemPage *pTo, MemPage *pFrom){ from = Addr(pFrom); for(i=0; i<pTo->nCell; i++){ uptr x = Addr(pFrom->apCell[i]); - if( x>from && x<from+SQLITE_PAGE_SIZE ){ + if( x>from && x<from+SQLITE_USABLE_SIZE ){ *((uptr*)&pTo->apCell[i]) = x + to - from; }else{ pTo->apCell[i] = pFrom->apCell[i]; @@ -2203,7 +2208,7 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){ ** underfull. */ assert( sqlitepager_iswriteable(pPage) ); - if( !pPage->isOverfull && pPage->nFree<SQLITE_PAGE_SIZE/2 + if( !pPage->isOverfull && pPage->nFree<SQLITE_USABLE_SIZE/2 && pPage->nCell>=2){ relinkCellList(pBt, pPage); return SQLITE_OK; @@ -2229,7 +2234,7 @@ static int balance(Btree *pBt, MemPage *pPage, BtCursor *pCur){ pgnoChild = SWAB32(pBt, pPage->u.hdr.rightChild); rc = sqlitepager_get(pBt->pPager, pgnoChild, (void**)&pChild); if( rc ) return rc; - memcpy(pPage, pChild, SQLITE_PAGE_SIZE); + memcpy(pPage, pChild, SQLITE_USABLE_SIZE); pPage->isInit = 0; rc = initPage(pBt, pPage, sqlitepager_pagenumber(pPage), 0); assert( rc==SQLITE_OK ); @@ -2724,7 +2729,8 @@ static int fileBtreeDelete(BtCursor *pCur){ getTempCursor(pCur, &leafCur); rc = fileBtreeNext(&leafCur, ¬Used); if( rc!=SQLITE_OK ){ - return SQLITE_CORRUPT; + if( rc!=SQLITE_NOMEM ) rc = SQLITE_CORRUPT; + return rc; } rc = sqlitepager_write(leafCur.pPage); if( rc ) return rc; @@ -2907,7 +2913,7 @@ static int copyCell(Btree *pBtFrom, BTree *pBtTo, Cell *pCell){ if( rc==SQLITE_OK ){ rc = sqlitepager_write(pNew); if( rc==SQLITE_OK ){ - memcpy(pNew, pOvfl, SQLITE_PAGE_SIZE); + memcpy(pNew, pOvfl, SQLITE_USABLE_SIZE); *pPrev = SWAB32(pBtTo, new); if( pPrevPg ){ sqlitepager_unref(pPrevPg); @@ -2950,7 +2956,7 @@ static int copyDatabasePage( rc = sqlitepager_write(pPage); } if( rc==SQLITE_OK ){ - memcpy(pPage, pPageFrom, SQLITE_PAGE_SIZE); + memcpy(pPage, pPageFrom, SQLITE_USABLE_SIZE); idx = SWAB16(pBt, pPage->u.hdr.firstCell); while( idx>0 ){ pCell = (Cell*)&pPage->u.aDisk[idx]; @@ -3040,7 +3046,7 @@ static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){ if( recursive ) printf("PAGE %d:\n", pgno); i = 0; idx = SWAB16(pBt, pPage->u.hdr.firstCell); - while( idx>0 && idx<=SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){ + while( idx>0 && idx<=SQLITE_USABLE_SIZE-MIN_CELL_SIZE ){ Cell *pCell = (Cell*)&pPage->u.aDisk[idx]; int sz = cellSize(pBt, pCell); sprintf(range,"%d..%d", idx, idx+sz-1); @@ -3070,7 +3076,7 @@ static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){ nFree = 0; i = 0; idx = SWAB16(pBt, pPage->u.hdr.firstFree); - while( idx>0 && idx<SQLITE_PAGE_SIZE ){ + while( idx>0 && idx<SQLITE_USABLE_SIZE ){ FreeBlk *p = (FreeBlk*)&pPage->u.aDisk[idx]; sprintf(range,"%d..%d", idx, idx+p->iSize-1); nFree += SWAB16(pBt, p->iSize); @@ -3084,7 +3090,7 @@ static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){ } if( recursive && pPage->u.hdr.rightChild!=0 ){ idx = SWAB16(pBt, pPage->u.hdr.firstCell); - while( idx>0 && idx<SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){ + while( idx>0 && idx<SQLITE_USABLE_SIZE-MIN_CELL_SIZE ){ Cell *pCell = (Cell*)&pPage->u.aDisk[idx]; fileBtreePageDump(pBt, SWAB32(pBt, pCell->h.leftChild), 1); idx = SWAB16(pBt, pCell->h.iNext); @@ -3129,7 +3135,7 @@ static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){ aResult[4] = pPage->nFree; cnt = 0; idx = SWAB16(pBt, pPage->u.hdr.firstFree); - while( idx>0 && idx<SQLITE_PAGE_SIZE ){ + while( idx>0 && idx<SQLITE_USABLE_SIZE ){ cnt++; idx = SWAB16(pBt, ((FreeBlk*)&pPage->u.aDisk[idx])->iNext); } @@ -3139,7 +3145,6 @@ static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){ } #endif -#ifdef SQLITE_TEST /* ** Return the pager associated with a BTree. This routine is used for ** testing and debugging only. @@ -3147,7 +3152,6 @@ static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){ static Pager *fileBtreePager(Btree *pBt){ return pBt->pPager; } -#endif /* ** This structure is passed around through all the sanity checking routines @@ -3293,7 +3297,7 @@ static int checkTreePage( Btree *pBt; char zMsg[100]; char zContext[100]; - char hit[SQLITE_PAGE_SIZE]; + char hit[SQLITE_USABLE_SIZE]; /* Check that the page exists */ @@ -3369,19 +3373,19 @@ static int checkTreePage( */ memset(hit, 0, sizeof(hit)); memset(hit, 1, sizeof(PageHdr)); - for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_PAGE_SIZE; ){ + for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_USABLE_SIZE; ){ Cell *pCell = (Cell*)&pPage->u.aDisk[i]; int j; for(j=i+cellSize(pBt, pCell)-1; j>=i; j--) hit[j]++; i = SWAB16(pBt, pCell->h.iNext); } - for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_PAGE_SIZE; ){ + for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_USABLE_SIZE; ){ FreeBlk *pFBlk = (FreeBlk*)&pPage->u.aDisk[i]; int j; for(j=i+SWAB16(pBt,pFBlk->iSize)-1; j>=i; j--) hit[j]++; i = SWAB16(pBt,pFBlk->iNext); } - for(i=0; i<SQLITE_PAGE_SIZE; i++){ + for(i=0; i<SQLITE_USABLE_SIZE; i++){ if( hit[i]==0 ){ sprintf(zMsg, "Unused space at byte %d of page %d", i, iPage); checkAppendMsg(pCheck, zMsg, 0); @@ -3396,9 +3400,9 @@ static int checkTreePage( /* Check that free space is kept to a minimum */ #if 0 - if( pParent && pParent->nCell>2 && pPage->nFree>3*SQLITE_PAGE_SIZE/4 ){ + if( pParent && pParent->nCell>2 && pPage->nFree>3*SQLITE_USABLE_SIZE/4 ){ sprintf(zMsg, "free space (%d) greater than max (%d)", pPage->nFree, - SQLITE_PAGE_SIZE/3); + SQLITE_USABLE_SIZE/3); checkAppendMsg(pCheck, zContext, zMsg); } #endif @@ -3500,7 +3504,7 @@ static int fileBtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){ if( !pBtTo->inTrans || !pBtFrom->inTrans ) return SQLITE_ERROR; if( pBtTo->needSwab!=pBtFrom->needSwab ) return SQLITE_ERROR; if( pBtTo->pCursor ) return SQLITE_BUSY; - memcpy(pBtTo->page1, pBtFrom->page1, SQLITE_PAGE_SIZE); + memcpy(pBtTo->page1, pBtFrom->page1, SQLITE_USABLE_SIZE); rc = sqlitepager_overwrite(pBtTo->pPager, 1, pBtFrom->page1); nToPage = sqlitepager_pagecount(pBtTo->pPager); nPage = sqlitepager_pagecount(pBtFrom->pPager); @@ -3555,9 +3559,9 @@ static BtOps sqliteBtreeOps = { fileBtreeIntegrityCheck, fileBtreeGetFilename, fileBtreeCopyFile, + fileBtreePager, #ifdef SQLITE_TEST fileBtreePageDump, - fileBtreePager #endif }; static BtCursorOps sqliteBtreeCursorOps = { diff --git a/ext/sqlite/libsqlite/src/btree.h b/ext/sqlite/libsqlite/src/btree.h index 1e1b2163d7..8d318a3c03 100644 --- a/ext/sqlite/libsqlite/src/btree.h +++ b/ext/sqlite/libsqlite/src/btree.h @@ -57,9 +57,9 @@ struct BtOps { char *(*IntegrityCheck)(Btree*, int*, int); const char *(*GetFilename)(Btree*); int (*Copyfile)(Btree*,Btree*); + struct Pager *(*Pager)(Btree*); #ifdef SQLITE_TEST int (*PageDump)(Btree*, int, int); - struct Pager *(*Pager)(Btree*); #endif }; @@ -142,13 +142,13 @@ int sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree); (btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot)) #define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt)) #define sqliteBtreeCopyFile(pBt1, pBt2) (btOps(pBt1)->Copyfile(pBt1, pBt2)) +#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt)) #ifdef SQLITE_TEST #define sqliteBtreePageDump(pBt, pgno, recursive)\ (btOps(pBt)->PageDump(pBt, pgno, recursive)) #define sqliteBtreeCursorDump(pCur, aResult)\ (btCOps(pCur)->CursorDump(pCur, aResult)) -#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt)) int btree_native_byte_order; #endif /* SQLITE_TEST */ diff --git a/ext/sqlite/libsqlite/src/build.c b/ext/sqlite/libsqlite/src/build.c index 9d41db21ff..4b5ed56139 100644 --- a/ext/sqlite/libsqlite/src/build.c +++ b/ext/sqlite/libsqlite/src/build.c @@ -38,7 +38,7 @@ void sqliteBeginParse(Parse *pParse, int explainFlag){ sqlite *db = pParse->db; int i; pParse->explain = explainFlag; - if((db->flags & SQLITE_Initialized)==0 && pParse->initFlag==0 ){ + if((db->flags & SQLITE_Initialized)==0 && db->init.busy==0 ){ int rc = sqliteInit(db, &pParse->zErrMsg); if( rc!=SQLITE_OK ){ pParse->rc = rc; @@ -55,17 +55,6 @@ void sqliteBeginParse(Parse *pParse, int explainFlag){ } /* -** This is a fake callback procedure used when sqlite_exec() is -** invoked with a NULL callback pointer. If we pass a NULL callback -** pointer into sqliteVdbeExec() it will return at every OP_Callback, -** which we do not want it to do. So we substitute a pointer to this -** procedure in place of the NULL. -*/ -static int fakeCallback(void *NotUsed, int n, char **az1, char **az2){ - return 0; -} - -/* ** This routine is called after a single SQL statement has been ** parsed and we want to execute the VDBE code to implement ** that statement. Prior action routines should have already @@ -76,36 +65,20 @@ static int fakeCallback(void *NotUsed, int n, char **az1, char **az2){ ** no VDBE code was generated. */ void sqliteExec(Parse *pParse){ - int rc = SQLITE_OK; sqlite *db = pParse->db; Vdbe *v = pParse->pVdbe; - int (*xCallback)(void*,int,char**,char**); + if( v==0 && (v = sqliteGetVdbe(pParse))!=0 ){ + sqliteVdbeAddOp(v, OP_Halt, 0, 0); + } if( sqlite_malloc_failed ) return; - xCallback = pParse->xCallback; - if( xCallback==0 && pParse->useCallback ) xCallback = fakeCallback; if( v && pParse->nErr==0 ){ FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0; sqliteVdbeTrace(v, trace); - sqliteVdbeMakeReady(v, pParse->nVar, xCallback, pParse->pArg, - pParse->explain); - if( pParse->useCallback ){ - if( pParse->explain ){ - rc = sqliteVdbeList(v); - db->next_cookie = db->aDb[0].schema_cookie; - }else{ - sqliteVdbeExec(v); - } - rc = sqliteVdbeFinalize(v, &pParse->zErrMsg); - if( rc ) pParse->nErr++; - pParse->pVdbe = 0; - pParse->rc = rc; - if( rc ) pParse->nErr++; - }else{ - pParse->rc = pParse->nErr ? SQLITE_ERROR : SQLITE_DONE; - } + sqliteVdbeMakeReady(v, pParse->nVar, pParse->explain); + pParse->rc = pParse->nErr ? SQLITE_ERROR : SQLITE_DONE; pParse->colNamesSet = 0; - }else if( pParse->useCallback==0 ){ + }else if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; } pParse->nTab = 0; @@ -240,7 +213,7 @@ void sqliteUnlinkAndDeleteIndex(sqlite *db, Index *pIndex){ ** ** If iDb<=0 then reset the internal schema tables for all database ** files. If iDb>=2 then reset the internal schema for only the -** single file indicates. +** single file indicated. */ void sqliteResetInternalSchema(sqlite *db, int iDb){ HashElem *pElem; @@ -280,10 +253,18 @@ void sqliteResetInternalSchema(sqlite *db, int iDb){ ** schema hash tables and therefore do not have to make any changes ** to any of those tables. */ + for(i=0; i<db->nDb; i++){ + struct Db *pDb = &db->aDb[i]; + if( pDb->pBt==0 ){ + if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux); + pDb->pAux = 0; + } + } for(i=j=2; i<db->nDb; i++){ - if( db->aDb[i].pBt==0 ){ - sqliteFree(db->aDb[i].zName); - db->aDb[i].zName = 0; + struct Db *pDb = &db->aDb[i]; + if( pDb->pBt==0 ){ + sqliteFree(pDb->zName); + pDb->zName = 0; continue; } if( j<i ){ @@ -456,7 +437,7 @@ void sqliteStartTable( pParse->sFirstToken = *pStart; zName = sqliteTableNameFromToken(pName); if( zName==0 ) return; - if( pParse->iDb==1 ) isTemp = 1; + if( db->init.iDb==1 ) isTemp = 1; #ifndef SQLITE_OMIT_AUTHORIZATION assert( (isTemp & 1)==isTemp ); { @@ -493,17 +474,16 @@ void sqliteStartTable( if( isTemp && db->aDb[1].pBt==0 && !pParse->explain ){ int rc = sqliteBtreeFactory(db, 0, 0, MAX_PAGES, &db->aDb[1].pBt); if( rc!=SQLITE_OK ){ - sqliteSetString(&pParse->zErrMsg, "unable to open a temporary database " - "file for storing temporary tables", (char*)0); + sqliteErrorMsg(pParse, "unable to open a temporary database " + "file for storing temporary tables"); pParse->nErr++; return; } if( db->flags & SQLITE_InTrans ){ rc = sqliteBtreeBeginTrans(db->aDb[1].pBt); if( rc!=SQLITE_OK ){ - sqliteSetNString(&pParse->zErrMsg, "unable to get a write lock on " - "the temporary database file", 0); - pParse->nErr++; + sqliteErrorMsg(pParse, "unable to get a write lock on " + "the temporary database file"); return; } } @@ -517,20 +497,16 @@ void sqliteStartTable( ** an existing temporary table, that is not an error. */ pTable = sqliteFindTable(db, zName, 0); - iDb = isTemp ? 1 : pParse->iDb; - if( pTable!=0 && (pTable->iDb==iDb || !pParse->initFlag) ){ - sqliteSetNString(&pParse->zErrMsg, "table ", 0, pName->z, pName->n, - " already exists", 0, 0); + iDb = isTemp ? 1 : db->init.iDb; + if( pTable!=0 && (pTable->iDb==iDb || !db->init.busy) ){ + sqliteErrorMsg(pParse, "table %T already exists", pName); sqliteFree(zName); - pParse->nErr++; return; } if( (pIdx = sqliteFindIndex(db, zName, 0))!=0 && - (pIdx->iDb==0 || !pParse->initFlag) ){ - sqliteSetString(&pParse->zErrMsg, "there is already an index named ", - zName, (char*)0); + (pIdx->iDb==0 || !db->init.busy) ){ + sqliteErrorMsg(pParse, "there is already an index named %s", zName); sqliteFree(zName); - pParse->nErr++; return; } pTable = sqliteMalloc( sizeof(Table) ); @@ -555,7 +531,7 @@ void sqliteStartTable( ** indices. Hence, the record number for the table must be allocated ** now. */ - if( !pParse->initFlag && (v = sqliteGetVdbe(pParse))!=0 ){ + if( !db->init.busy && (v = sqliteGetVdbe(pParse))!=0 ){ sqliteBeginWriteOperation(pParse, 0, isTemp); if( !isTemp ){ sqliteVdbeAddOp(v, OP_Integer, db->file_format, 0); @@ -588,8 +564,7 @@ void sqliteAddColumn(Parse *pParse, Token *pName){ sqliteDequote(z); for(i=0; i<p->nCol; i++){ if( sqliteStrICmp(z, p->aCol[i].zName)==0 ){ - sqliteSetString(&pParse->zErrMsg, "duplicate column name: ", z, (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "duplicate column name: %s", z); sqliteFree(z); return; } @@ -708,9 +683,8 @@ void sqliteAddPrimaryKey(Parse *pParse, IdList *pList, int onError){ int iCol = -1, i; if( pTab==0 ) goto primary_key_exit; if( pTab->hasPrimKey ){ - sqliteSetString(&pParse->zErrMsg, "table \"", pTab->zName, - "\" has more than one primary key", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, + "table \"%s\" has more than one primary key", pTab->zName); goto primary_key_exit; } pTab->hasPrimKey = 1; @@ -753,34 +727,16 @@ primary_key_exit: */ int sqliteCollateType(const char *zType, int nType){ int i; - for(i=0; i<nType-1; i++){ - switch( zType[i] ){ - case 'b': - case 'B': { - if( i<nType-3 && sqliteStrNICmp(&zType[i],"blob",4)==0 ){ - return SQLITE_SO_TEXT; - } - break; - } - case 'c': - case 'C': { - if( i<nType-3 && (sqliteStrNICmp(&zType[i],"char",4)==0 || - sqliteStrNICmp(&zType[i],"clob",4)==0) - ){ - return SQLITE_SO_TEXT; - } - break; - } - case 'x': - case 'X': { - if( i>=2 && sqliteStrNICmp(&zType[i-2],"text",4)==0 ){ - return SQLITE_SO_TEXT; - } - break; - } - default: { - break; - } + for(i=0; i<nType-3; i++){ + int c = *(zType++) | 0x60; + if( (c=='b' || c=='c') && sqliteStrNICmp(zType, "lob", 3)==0 ){ + return SQLITE_SO_TEXT; + } + if( c=='c' && sqliteStrNICmp(zType, "har", 3)==0 ){ + return SQLITE_SO_TEXT; + } + if( c=='t' && sqliteStrNICmp(zType, "ext", 3)==0 ){ + return SQLITE_SO_TEXT; } } return SQLITE_SO_NUM; @@ -819,7 +775,9 @@ void sqliteAddCollateType(Parse *pParse, int collType){ */ void sqliteChangeCookie(sqlite *db, Vdbe *v){ if( db->next_cookie==db->aDb[0].schema_cookie ){ - db->next_cookie = db->aDb[0].schema_cookie + sqliteRandomByte() + 1; + unsigned char r; + sqliteRandomness(1, &r); + db->next_cookie = db->aDb[0].schema_cookie + r + 1; db->flags |= SQLITE_InternChanges; sqliteVdbeAddOp(v, OP_Integer, db->next_cookie, 0); sqliteVdbeAddOp(v, OP_SetCookie, 0, 0); @@ -910,8 +868,8 @@ static char *createTableStmt(Table *p){ ** is added to the internal hash tables, assuming no errors have ** occurred. ** -** An entry for the table is made in the master table on disk, -** unless this is a temporary table or initFlag==1. When initFlag==1, +** An entry for the table is made in the master table on disk, unless +** this is a temporary table or db->init.busy==1. When db->init.busy==1 ** it means we are reading the sqlite_master table because we just ** connected to the database or because the sqlite_master table has ** recently changes, so the entry for this table already exists in @@ -944,14 +902,14 @@ void sqliteEndTable(Parse *pParse, Token *pEnd, Select *pSelect){ sqliteDeleteTable(0, pSelTab); } - /* If the initFlag is 1 it means we are reading the SQL off the + /* If the db->init.busy is 1 it means we are reading the SQL off the ** "sqlite_master" or "sqlite_temp_master" table on the disk. ** So do not write to the disk again. Extract the root page number - ** for the table from the pParse->newTnum field. (The page number + ** for the table from the db->init.newTnum field. (The page number ** should have been put there by the sqliteOpenCb routine.) */ - if( pParse->initFlag ){ - p->tnum = pParse->newTnum; + if( db->init.busy ){ + p->tnum = db->init.newTnum; } /* If not initializing, then create a record for the new table @@ -961,7 +919,7 @@ void sqliteEndTable(Parse *pParse, Token *pEnd, Select *pSelect){ ** If this is a TEMPORARY table, write the entry into the auxiliary ** file instead of into the main database file. */ - if( !pParse->initFlag ){ + if( !db->init.busy ){ int n; Vdbe *v; @@ -969,24 +927,16 @@ void sqliteEndTable(Parse *pParse, Token *pEnd, Select *pSelect){ if( v==0 ) return; if( p->pSelect==0 ){ /* A regular table */ - sqliteVdbeAddOp(v, OP_CreateTable, 0, p->iDb); - sqliteVdbeChangeP3(v, -1, (char *)&p->tnum, P3_POINTER); + sqliteVdbeOp3(v, OP_CreateTable, 0, p->iDb, (char*)&p->tnum, P3_POINTER); }else{ /* A view */ sqliteVdbeAddOp(v, OP_Integer, 0, 0); } p->tnum = 0; sqliteVdbeAddOp(v, OP_Pull, 1, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - if( p->pSelect==0 ){ - sqliteVdbeChangeP3(v, -1, "table", P3_STATIC); - }else{ - sqliteVdbeChangeP3(v, -1, "view", P3_STATIC); - } - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, p->zName, P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, p->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, p->pSelect==0?"table":"view", P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, p->zName, 0); + sqliteVdbeOp3(v, OP_String, 0, 0, p->zName, 0); sqliteVdbeAddOp(v, OP_Dup, 4, 0); sqliteVdbeAddOp(v, OP_String, 0, 0); if( pSelect ){ @@ -1072,7 +1022,7 @@ void sqliteCreateView( */ p->pSelect = sqliteSelectDup(pSelect); sqliteSelectDelete(pSelect); - if( !pParse->initFlag ){ + if( !pParse->db->init.busy ){ sqliteViewGetColumnNames(pParse, p); } @@ -1084,7 +1034,7 @@ void sqliteCreateView( sEnd.z += sEnd.n; } sEnd.n = 0; - n = (char *) sEnd.z - (char *) pBegin->z; + n = sEnd.z - pBegin->z; z = pBegin->z; while( n>0 && (z[n-1]==';' || isspace(z[n-1])) ){ n--; } sEnd.z = &z[n-1]; @@ -1098,7 +1048,7 @@ void sqliteCreateView( /* ** The Table structure pTable is really a VIEW. Fill in the names of ** the columns of the view in the pTable structure. Return the number -** of errors. If an error is seen leave an error message in pPare->zErrMsg. +** of errors. If an error is seen leave an error message in pParse->zErrMsg. */ int sqliteViewGetColumnNames(Parse *pParse, Table *pTable){ ExprList *pEList; @@ -1124,9 +1074,7 @@ int sqliteViewGetColumnNames(Parse *pParse, Table *pTable){ ** should always fail. But we will leave it in place just to be safe. */ if( pTable->nCol<0 ){ - sqliteSetString(&pParse->zErrMsg, "view ", pTable->zName, - " is circularly defined", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } @@ -1176,12 +1124,12 @@ int sqliteViewGetColumnNames(Parse *pParse, Table *pTable){ */ static void sqliteViewResetColumnNames(Table *pTable){ int i; - if( pTable==0 || pTable->pSelect==0 ) return; - if( pTable->nCol==0 ) return; - for(i=0; i<pTable->nCol; i++){ - sqliteFree(pTable->aCol[i].zName); - sqliteFree(pTable->aCol[i].zDflt); - sqliteFree(pTable->aCol[i].zType); + Column *pCol; + assert( pTable!=0 && pTable->pSelect!=0 ); + for(i=0, pCol=pTable->aCol; i<pTable->nCol; i++, pCol++){ + sqliteFree(pCol->zName); + sqliteFree(pCol->zDflt); + sqliteFree(pCol->zType); } sqliteFree(pTable->aCol); pTable->aCol = 0; @@ -1215,9 +1163,7 @@ Table *sqliteTableFromToken(Parse *pParse, Token *pTok){ pTab = sqliteFindTable(pParse->db, zName, 0); sqliteFree(zName); if( pTab==0 ){ - sqliteSetNString(&pParse->zErrMsg, "no such table: ", 0, - pTok->z, pTok->n, 0); - pParse->nErr++; + sqliteErrorMsg(pParse, "no such table: %T", pTok); } return pTab; } @@ -1268,21 +1214,16 @@ void sqliteDropTable(Parse *pParse, Token *pName, int isView){ } #endif if( pTable->readOnly ){ - sqliteSetString(&pParse->zErrMsg, "table ", pTable->zName, - " may not be dropped", (char*)0); + sqliteErrorMsg(pParse, "table %s may not be dropped", pTable->zName); pParse->nErr++; return; } if( isView && pTable->pSelect==0 ){ - sqliteSetString(&pParse->zErrMsg, "use DROP TABLE to delete table ", - pTable->zName, (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "use DROP TABLE to delete table %s", pTable->zName); return; } if( !isView && pTable->pSelect ){ - sqliteSetString(&pParse->zErrMsg, "use DROP VIEW to delete view ", - pTable->zName, (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "use DROP VIEW to delete view %s", pTable->zName); return; } @@ -1291,7 +1232,7 @@ void sqliteDropTable(Parse *pParse, Token *pName, int isView){ */ v = sqliteGetVdbe(pParse); if( v ){ - static VdbeOp dropTable[] = { + static VdbeOpList dropTable[] = { { OP_Rewind, 0, ADDR(8), 0}, { OP_String, 0, 0, 0}, /* 1 */ { OP_MemStore, 1, 1, 0}, @@ -1425,19 +1366,16 @@ void sqliteCreateForeignKey( int iCol = p->nCol-1; if( iCol<0 ) goto fk_end; if( pToCol && pToCol->nId!=1 ){ - sqliteSetNString(&pParse->zErrMsg, "foreign key on ", -1, - p->aCol[iCol].zName, -1, - " should reference only one column of table ", -1, - pTo->z, pTo->n, 0); - pParse->nErr++; + sqliteErrorMsg(pParse, "foreign key on %s" + " should reference only one column of table %T", + p->aCol[iCol].zName, pTo); goto fk_end; } nCol = 1; }else if( pToCol && pToCol->nId!=pFromCol->nId ){ - sqliteSetString(&pParse->zErrMsg, + sqliteErrorMsg(pParse, "number of columns in foreign key does not match the number of " - "columns in the referenced table", (char*)0); - pParse->nErr++; + "columns in the referenced table"); goto fk_end; }else{ nCol = pFromCol->nId; @@ -1473,9 +1411,9 @@ void sqliteCreateForeignKey( } } if( j>=p->nCol ){ - sqliteSetString(&pParse->zErrMsg, "unknown column \"", - pFromCol->a[i].zName, "\" in foreign key definition", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, + "unknown column \"%s\" in foreign key definition", + pFromCol->a[i].zName); goto fk_end; } } @@ -1550,8 +1488,8 @@ void sqliteCreateIndex( sqlite *db = pParse->db; if( pParse->nErr || sqlite_malloc_failed ) goto exit_create_index; - if( pParse->initFlag - && sqliteFixInit(&sFix, pParse, pParse->iDb, "index", pName) + if( db->init.busy + && sqliteFixInit(&sFix, pParse, db->init.iDb, "index", pName) && sqliteFixSrcList(&sFix, pTable) ){ goto exit_create_index; @@ -1570,20 +1508,15 @@ void sqliteCreateIndex( } if( pTab==0 || pParse->nErr ) goto exit_create_index; if( pTab->readOnly ){ - sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName, - " may not be indexed", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "table %s may not be indexed", pTab->zName); goto exit_create_index; } - if( pTab->iDb>=2 && pParse->initFlag==0 ){ - sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName, - " may not have indices added", (char*)0); - pParse->nErr++; + if( pTab->iDb>=2 && db->init.busy==0 ){ + sqliteErrorMsg(pParse, "table %s may not have indices added", pTab->zName); goto exit_create_index; } if( pTab->pSelect ){ - sqliteSetString(&pParse->zErrMsg, "views may not be indexed", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "views may not be indexed"); goto exit_create_index; } isTemp = pTab->iDb==1; @@ -1601,21 +1534,17 @@ void sqliteCreateIndex( ** dealing with a primary key or UNIQUE constraint. We have to invent our ** own name. */ - if( pName && !pParse->initFlag ){ + if( pName && !db->init.busy ){ Index *pISameName; /* Another index with the same name */ Table *pTSameName; /* A table with same name as the index */ zName = sqliteStrNDup(pName->z, pName->n); if( zName==0 ) goto exit_create_index; if( (pISameName = sqliteFindIndex(db, zName, 0))!=0 ){ - sqliteSetString(&pParse->zErrMsg, "index ", zName, - " already exists", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "index %s already exists", zName); goto exit_create_index; } if( (pTSameName = sqliteFindTable(db, zName, 0))!=0 ){ - sqliteSetString(&pParse->zErrMsg, "there is already a table named ", - zName, (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "there is already a table named %s", zName); goto exit_create_index; } }else if( pName==0 ){ @@ -1637,7 +1566,7 @@ void sqliteCreateIndex( { const char *zDb = db->aDb[pTab->iDb].zName; - assert( pTab->iDb==pParse->iDb || isTemp ); + assert( pTab->iDb==db->init.iDb || isTemp ); if( sqliteAuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){ goto exit_create_index; } @@ -1673,7 +1602,7 @@ void sqliteCreateIndex( pIndex->nColumn = pList->nId; pIndex->onError = onError; pIndex->autoIndex = pName==0; - pIndex->iDb = isTemp ? 1 : pParse->iDb; + pIndex->iDb = isTemp ? 1 : db->init.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 @@ -1684,9 +1613,8 @@ void sqliteCreateIndex( if( sqliteStrICmp(pList->a[i].zName, pTab->aCol[j].zName)==0 ) break; } if( j>=pTab->nCol ){ - sqliteSetString(&pParse->zErrMsg, "table ", pTab->zName, - " has no column named ", pList->a[i].zName, (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "table %s has no column named %s", + pTab->zName, pList->a[i].zName); sqliteFree(pIndex); goto exit_create_index; } @@ -1726,20 +1654,20 @@ void sqliteCreateIndex( pOther->pNext = pIndex; } - /* If the initFlag is 1 it means we are reading the SQL off the + /* If the db->init.busy is 1 it means we are reading the SQL off the ** "sqlite_master" table on the disk. So do not write to the disk - ** again. Extract the table number from the pParse->newTnum field. + ** again. Extract the table number from the db->init.newTnum field. */ - if( pParse->initFlag && pTable!=0 ){ - pIndex->tnum = pParse->newTnum; + if( db->init.busy && pTable!=0 ){ + pIndex->tnum = db->init.newTnum; } - /* If the initFlag is 0 then create the index on disk. This + /* If the db->init.busy is 0 then create the index on disk. This ** involves writing the index into the master table and filling in the ** index with the current table contents. ** - ** The initFlag is 0 when the user first enters a CREATE INDEX - ** command. The initFlag is 1 when a database is opened and + ** The db->init.busy is 0 when the user first enters a CREATE INDEX + ** command. db->init.busy is 1 when a database is opened and ** CREATE INDEX statements are read out of the master table. In ** the latter case the index already exists on disk, which is why ** we don't want to recreate it. @@ -1749,7 +1677,7 @@ void sqliteCreateIndex( ** has just been created, it contains no data and the index initialization ** step can be skipped. */ - else if( pParse->initFlag==0 ){ + else if( db->init.busy==0 ){ int n; Vdbe *v; int lbl1, lbl2; @@ -1763,19 +1691,17 @@ void sqliteCreateIndex( sqliteOpenMasterTable(v, isTemp); } sqliteVdbeAddOp(v, OP_NewRecno, 0, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, "index", P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pIndex->zName, P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); - addr = sqliteVdbeAddOp(v, OP_CreateIndex, 0, isTemp); - sqliteVdbeChangeP3(v, addr, (char*)&pIndex->tnum, P3_POINTER); + sqliteVdbeOp3(v, OP_String, 0, 0, "index", P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pIndex->zName, 0); + sqliteVdbeOp3(v, OP_String, 0, 0, pTab->zName, 0); + sqliteVdbeOp3(v, OP_CreateIndex, 0, isTemp,(char*)&pIndex->tnum,P3_POINTER); pIndex->tnum = 0; if( pTable ){ - sqliteVdbeAddOp(v, OP_Dup, 0, 0); - sqliteVdbeAddOp(v, OP_Integer, isTemp, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, 1, 0); + sqliteVdbeCode(v, + OP_Dup, 0, 0, + OP_Integer, isTemp, 0, + OP_OpenWrite, 1, 0, + 0); } addr = sqliteVdbeAddOp(v, OP_String, 0, 0); if( pStart && pEnd ){ @@ -1786,8 +1712,7 @@ void sqliteCreateIndex( sqliteVdbeAddOp(v, OP_PutIntKey, 0, 0); if( pTable ){ sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenRead, 2, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_OpenRead, 2, pTab->tnum, pTab->zName, 0); lbl2 = sqliteVdbeMakeLabel(v); sqliteVdbeAddOp(v, OP_Rewind, 2, lbl2); lbl1 = sqliteVdbeAddOp(v, OP_Recno, 2, 0); @@ -1801,8 +1726,8 @@ void sqliteCreateIndex( } sqliteVdbeAddOp(v, OP_MakeIdxKey, pIndex->nColumn, 0); if( db->file_format>=4 ) sqliteAddIdxKeyType(v, pIndex); - sqliteVdbeAddOp(v, OP_IdxPut, 1, pIndex->onError!=OE_None); - sqliteVdbeChangeP3(v, -1, "indexed columns are not unique", P3_STATIC); + sqliteVdbeOp3(v, OP_IdxPut, 1, pIndex->onError!=OE_None, + "indexed columns are not unique", P3_STATIC); sqliteVdbeAddOp(v, OP_Next, 2, lbl1); sqliteVdbeResolveLabel(v, lbl2); sqliteVdbeAddOp(v, OP_Close, 2, 0); @@ -1870,7 +1795,7 @@ void sqliteDropIndex(Parse *pParse, SrcList *pName){ /* Generate code to remove the index and from the master table */ v = sqliteGetVdbe(pParse); if( v ){ - static VdbeOp dropIndex[] = { + static VdbeOpList dropIndex[] = { { OP_Rewind, 0, ADDR(9), 0}, { OP_String, 0, 0, 0}, /* 1 */ { OP_MemStore, 1, 1, 0}, @@ -2102,8 +2027,10 @@ void sqliteBeginTransaction(Parse *pParse, int onError){ return; } sqliteBeginWriteOperation(pParse, 0, 0); - db->flags |= SQLITE_InTrans; - db->onError = onError; + if( !pParse->explain ){ + db->flags |= SQLITE_InTrans; + db->onError = onError; + } } /* @@ -2119,9 +2046,13 @@ void sqliteCommitTransaction(Parse *pParse){ sqliteErrorMsg(pParse, "cannot commit - no transaction is active"); return; } - db->flags &= ~SQLITE_InTrans; + if( !pParse->explain ){ + db->flags &= ~SQLITE_InTrans; + } sqliteEndWriteOperation(pParse); - db->onError = OE_Default; + if( !pParse->explain ){ + db->onError = OE_Default; + } } /* @@ -2142,8 +2073,10 @@ void sqliteRollbackTransaction(Parse *pParse){ if( v ){ sqliteVdbeAddOp(v, OP_Rollback, 0, 0); } - db->flags &= ~SQLITE_InTrans; - db->onError = OE_Default; + if( !pParse->explain ){ + db->flags &= ~SQLITE_InTrans; + db->onError = OE_Default; + } } /* diff --git a/ext/sqlite/libsqlite/src/copy.c b/ext/sqlite/libsqlite/src/copy.c index 5fca758d63..2f70fce17b 100644 --- a/ext/sqlite/libsqlite/src/copy.c +++ b/ext/sqlite/libsqlite/src/copy.c @@ -37,7 +37,6 @@ void sqliteCopy( int i; Vdbe *v; int addr, end; - Index *pIdx; char *zFile = 0; const char *zDb; sqlite *db = pParse->db; @@ -58,18 +57,9 @@ void sqliteCopy( v = sqliteGetVdbe(pParse); if( v ){ sqliteBeginWriteOperation(pParse, 1, pTab->iDb); - addr = sqliteVdbeAddOp(v, OP_FileOpen, 0, 0); - sqliteVdbeChangeP3(v, addr, pFilename->z, pFilename->n); + addr = sqliteVdbeOp3(v, OP_FileOpen, 0, 0, pFilename->z, pFilename->n); sqliteVdbeDequoteP3(v, addr); - sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, 0, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); - for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ - assert( pIdx->iDb==1 || pIdx->iDb==pTab->iDb ); - sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, i, pIdx->tnum); - sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); - } + sqliteOpenTableAndIndices(pParse, pTab, 0); if( db->flags & SQLITE_CountRows ){ sqliteVdbeAddOp(v, OP_Integer, 0, 0); /* Initialize the row count */ } @@ -107,7 +97,7 @@ void sqliteCopy( sqliteVdbeAddOp(v, OP_Noop, 0, 0); sqliteEndWriteOperation(pParse); if( db->flags & SQLITE_CountRows ){ - sqliteVdbeAddOp(v, OP_ColumnName, 0, 0); + sqliteVdbeAddOp(v, OP_ColumnName, 0, 1); sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC); sqliteVdbeAddOp(v, OP_Callback, 1, 0); } diff --git a/ext/sqlite/libsqlite/src/date.c b/ext/sqlite/libsqlite/src/date.c index 64fc3bccdf..d7382aefae 100644 --- a/ext/sqlite/libsqlite/src/date.c +++ b/ext/sqlite/libsqlite/src/date.c @@ -47,7 +47,6 @@ ** Willmann-Bell, Inc ** Richmond, Virginia (USA) */ -#ifndef SQLITE_OMIT_DATETIME_FUNCS #include "os.h" #include "sqliteInt.h" #include <ctype.h> @@ -55,6 +54,8 @@ #include <assert.h> #include <time.h> +#ifndef SQLITE_OMIT_DATETIME_FUNCS + /* ** A structure for holding a single date and time. */ @@ -73,17 +74,50 @@ struct DateTime { /* -** Convert N digits from zDate into an integer. Return -** -1 if zDate does not begin with N digits. +** Convert zDate into one or more integers. Additional arguments +** come in groups of 5 as follows: +** +** N number of digits in the integer +** min minimum allowed value of the integer +** max maximum allowed value of the integer +** nextC first character after the integer +** pVal where to write the integers value. +** +** Conversions continue until one with nextC==0 is encountered. +** The function returns the number of successful conversions. */ -static int getDigits(const char *zDate, int N){ - int val = 0; - while( N-- ){ - if( !isdigit(*zDate) ) return -1; - val = val*10 + *zDate - '0'; +static int getDigits(const char *zDate, ...){ + va_list ap; + int val; + int N; + int min; + int max; + int nextC; + int *pVal; + int cnt = 0; + va_start(ap, zDate); + do{ + N = va_arg(ap, int); + min = va_arg(ap, int); + max = va_arg(ap, int); + nextC = va_arg(ap, int); + pVal = va_arg(ap, int*); + val = 0; + while( N-- ){ + if( !isdigit(*zDate) ){ + return cnt; + } + val = val*10 + *zDate - '0'; + zDate++; + } + if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){ + return cnt; + } + *pVal = val; zDate++; - } - return val; + cnt++; + }while( nextC ); + return cnt; } /* @@ -91,38 +125,9 @@ static int getDigits(const char *zDate, int N){ ** the number of digits converted. */ static int getValue(const char *z, double *pR){ - double r = 0.0; - double rDivide = 1.0; - int isNeg = 0; - int nChar = 0; - if( *z=='+' ){ - z++; - nChar++; - }else if( *z=='-' ){ - z++; - isNeg = 1; - nChar++; - } - if( !isdigit(*z) ) return 0; - while( isdigit(*z) ){ - r = r*10.0 + *z - '0'; - nChar++; - z++; - } - if( *z=='.' && isdigit(z[1]) ){ - z++; - nChar++; - while( isdigit(*z) ){ - r = r*10.0 + *z - '0'; - rDivide *= 10.0; - nChar++; - z++; - } - r /= rDivide; - } - if( *z!=0 && !isspace(*z) ) return 0; - *pR = isNeg ? -r : r; - return nChar; + const char *zEnd; + *pR = sqliteAtoF(z, &zEnd); + return zEnd - z; } /* @@ -150,14 +155,10 @@ static int parseTimezone(const char *zDate, DateTime *p){ return *zDate!=0; } zDate++; - nHr = getDigits(zDate, 2); - if( nHr<0 || nHr>14 ) return 1; - zDate += 2; - if( zDate[0]!=':' ) return 1; - zDate++; - nMn = getDigits(zDate, 2); - if( nMn<0 || nMn>59 ) return 1; - zDate += 2; + if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){ + return 1; + } + zDate += 5; p->tz = sgn*(nMn + nHr*60); while( isspace(*zDate) ){ zDate++; } return *zDate!=0; @@ -173,16 +174,16 @@ static int parseTimezone(const char *zDate, DateTime *p){ static int parseHhMmSs(const char *zDate, DateTime *p){ int h, m, s; double ms = 0.0; - h = getDigits(zDate, 2); - if( h<0 || zDate[2]!=':' ) return 1; - zDate += 3; - m = getDigits(zDate, 2); - if( m<0 || m>59 ) return 1; - zDate += 2; + if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){ + return 1; + } + zDate += 5; if( *zDate==':' ){ - s = getDigits(&zDate[1], 2); - if( s<0 || s>59 ) return 1; - zDate += 3; + zDate++; + if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){ + return 1; + } + zDate += 2; if( *zDate=='.' && isdigit(zDate[1]) ){ double rScale = 1.0; zDate++; @@ -259,20 +260,21 @@ static void computeJD(DateTime *p){ ** date. */ static int parseYyyyMmDd(const char *zDate, DateTime *p){ - int Y, M, D; + int Y, M, D, neg; - Y = getDigits(zDate, 4); - if( Y<0 || zDate[4]!='-' ) return 1; - zDate += 5; - M = getDigits(zDate, 2); - if( M<=0 || M>12 || zDate[2]!='-' ) return 1; - zDate += 3; - D = getDigits(zDate, 2); - if( D<=0 || D>31 ) return 1; - zDate += 2; + if( zDate[0]=='-' ){ + zDate++; + neg = 1; + }else{ + neg = 0; + } + if( getDigits(zDate,4,0,9999,'-',&Y,2,1,12,'-',&M,2,1,31,0,&D)!=3 ){ + return 1; + } + zDate += 10; while( isspace(*zDate) ){ zDate++; } - if( isdigit(*zDate) ){ - if( parseHhMmSs(zDate, p) ) return 1; + if( parseHhMmSs(zDate, p)==0 ){ + /* We got the time */ }else if( *zDate==0 ){ p->validHMS = 0; }else{ @@ -280,7 +282,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){ } p->validJD = 0; p->validYMD = 1; - p->Y = Y; + p->Y = neg ? -Y : Y; p->M = M; p->D = D; if( p->validTZ ){ @@ -306,15 +308,12 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){ ** as there is a year and date. */ static int parseDateOrTime(const char *zDate, DateTime *p){ - int i; memset(p, 0, sizeof(*p)); - for(i=0; isdigit(zDate[i]); i++){} - if( i==4 && zDate[i]=='-' ){ - return parseYyyyMmDd(zDate, p); - }else if( i==2 && zDate[i]==':' ){ - return parseHhMmSs(zDate, p); + if( parseYyyyMmDd(zDate,p)==0 ){ + return 0; + }else if( parseHhMmSs(zDate, p)==0 ){ return 0; - }else if( i==0 && sqliteStrICmp(zDate,"now")==0 ){ + }else if( sqliteStrICmp(zDate,"now")==0){ double r; if( sqliteOsCurrentTime(&r)==0 ){ p->rJD = r; @@ -323,7 +322,7 @@ static int parseDateOrTime(const char *zDate, DateTime *p){ } return 1; }else if( sqliteIsNumber(zDate) ){ - p->rJD = sqliteAtoF(zDate); + p->rJD = sqliteAtoF(zDate, 0); p->validJD = 1; return 0; } @@ -336,17 +335,23 @@ static int parseDateOrTime(const char *zDate, DateTime *p){ static void computeYMD(DateTime *p){ int Z, A, B, C, D, E, X1; if( p->validYMD ) return; - Z = p->rJD + 0.5; - A = (Z - 1867216.25)/36524.25; - A = Z + 1 + A - (A/4); - B = A + 1524; - C = (B - 122.1)/365.25; - D = 365.25*C; - E = (B-D)/30.6001; - X1 = 30.6001*E; - p->D = B - D - X1; - p->M = E<14 ? E-1 : E-13; - p->Y = p->M>2 ? C - 4716 : C - 4715; + if( !p->validJD ){ + p->Y = 2000; + p->M = 1; + p->D = 1; + }else{ + Z = p->rJD + 0.5; + A = (Z - 1867216.25)/36524.25; + A = Z + 1 + A - (A/4); + B = A + 1524; + C = (B - 122.1)/365.25; + D = 365.25*C; + E = (B-D)/30.6001; + X1 = 30.6001*E; + p->D = B - D - X1; + p->M = E<14 ? E-1 : E-13; + p->Y = p->M>2 ? C - 4716 : C - 4715; + } p->validYMD = 1; } @@ -452,8 +457,9 @@ static int parseModifier(const char *zMod, DateTime *p){ int rc = 1; int n; double r; - char z[30]; - for(n=0; n<sizeof(z)-1 && zMod[n]; n++){ + char *z, zBuf[30]; + z = zBuf; + for(n=0; n<sizeof(zBuf)-1 && zMod[n]; n++){ z[n] = tolower(zMod[n]); } z[n] = 0; @@ -526,22 +532,22 @@ static int parseModifier(const char *zMod, DateTime *p){ ** or month or year. */ if( strncmp(z, "start of ", 9)!=0 ) break; - zMod = &z[9]; + z += 9; computeYMD(p); p->validHMS = 1; p->h = p->m = 0; p->s = 0.0; p->validTZ = 0; p->validJD = 0; - if( strcmp(zMod,"month")==0 ){ + if( strcmp(z,"month")==0 ){ p->D = 1; rc = 0; - }else if( strcmp(zMod,"year")==0 ){ + }else if( strcmp(z,"year")==0 ){ computeYMD(p); p->M = 1; p->D = 1; rc = 0; - }else if( strcmp(zMod,"day")==0 ){ + }else if( strcmp(z,"day")==0 ){ rc = 0; } break; @@ -560,11 +566,33 @@ static int parseModifier(const char *zMod, DateTime *p){ case '9': { n = getValue(z, &r); if( n<=0 ) break; - zMod = &z[n]; - while( isspace(zMod[0]) ) zMod++; - n = strlen(zMod); + if( z[n]==':' ){ + /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the + ** specified number of hours, minutes, seconds, and fractional seconds + ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be + ** omitted. + */ + const char *z2 = z; + DateTime tx; + int day; + if( !isdigit(*z2) ) z2++; + memset(&tx, 0, sizeof(tx)); + if( parseHhMmSs(z2, &tx) ) break; + computeJD(&tx); + tx.rJD -= 0.5; + day = (int)tx.rJD; + tx.rJD -= day; + if( z[0]=='-' ) tx.rJD = -tx.rJD; + computeJD(p); + clearYMD_HMS_TZ(p); + p->rJD += tx.rJD; + rc = 0; + break; + } + z += n; + while( isspace(z[0]) ) z++; + n = strlen(z); if( n>10 || n<3 ) break; - strcpy(z, zMod); if( z[n-1]=='s' ){ z[n-1] = 0; n--; } computeJD(p); rc = 0; diff --git a/ext/sqlite/libsqlite/src/delete.c b/ext/sqlite/libsqlite/src/delete.c index 20c07be47e..d83c314c79 100644 --- a/ext/sqlite/libsqlite/src/delete.c +++ b/ext/sqlite/libsqlite/src/delete.c @@ -189,7 +189,7 @@ void sqliteDeleteFrom( } /* The usual case: There is a WHERE clause so we have to scan through - ** the table an pick which records to delete. + ** the table and pick which records to delete. */ else{ /* Begin the database scan @@ -253,12 +253,7 @@ void sqliteDeleteFrom( ** cursors are opened only once on the outside the loop. */ pParse->nTab = iCur + 1; - sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum); - for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){ - sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, pParse->nTab++, pIdx->tnum); - } + sqliteOpenTableAndIndices(pParse, pTab, iCur); /* This is the beginning of the delete loop when there are no ** row triggers */ @@ -299,13 +294,14 @@ void sqliteDeleteFrom( pParse->nTab = iCur; } } + sqliteVdbeAddOp(v, OP_SetCounts, 0, 0); sqliteEndWriteOperation(pParse); /* ** Return the number of rows that were deleted. */ if( db->flags & SQLITE_CountRows ){ - sqliteVdbeAddOp(v, OP_ColumnName, 0, 0); + sqliteVdbeAddOp(v, OP_ColumnName, 0, 1); sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC); sqliteVdbeAddOp(v, OP_Callback, 1, 0); } @@ -347,7 +343,8 @@ void sqliteGenerateRowDelete( int addr; addr = sqliteVdbeAddOp(v, OP_NotExists, iCur, 0); sqliteGenerateRowIndexDelete(db, v, pTab, iCur, 0); - sqliteVdbeAddOp(v, OP_Delete, iCur, count); + sqliteVdbeAddOp(v, OP_Delete, iCur, + (count?OPFLAG_NCHANGE:0) | OPFLAG_CSCHANGE); sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v)); } diff --git a/ext/sqlite/libsqlite/src/encode.c b/ext/sqlite/libsqlite/src/encode.c index 5614999ab9..7d959b00ca 100644 --- a/ext/sqlite/libsqlite/src/encode.c +++ b/ext/sqlite/libsqlite/src/encode.c @@ -18,6 +18,7 @@ ** $Id$ */ #include <string.h> +#include <assert.h> /* ** How This Encoder Works @@ -26,7 +27,7 @@ ** 0x00. This is accomplished by using an escape character to encode ** 0x27 and 0x00 as a two-byte sequence. The escape character is always ** 0x01. An 0x00 is encoded as the two byte sequence 0x01 0x01. The -** 0x27 character is encoded as the two byte sequence 0x01 0x03. Finally, +** 0x27 character is encoded as the two byte sequence 0x01 0x28. Finally, ** the escape character itself is encoded as the two-character sequence ** 0x01 0x02. ** @@ -34,7 +35,7 @@ ** ** 0x00 -> 0x01 0x01 ** 0x01 -> 0x01 0x02 -** 0x27 -> 0x01 0x03 +** 0x27 -> 0x01 0x28 ** ** If that were all the encoder did, it would work, but in certain cases ** it could double the size of the encoded string. For example, to @@ -80,7 +81,7 @@ ** the offset in step 7 below. ** ** (6) Convert each 0x01 0x01 sequence into a single character 0x00. -** Convert 0x01 0x02 into 0x01. Convert 0x01 0x03 into 0x27. +** Convert 0x01 0x02 into 0x01. Convert 0x01 0x28 into 0x27. ** ** (7) Subtract the offset value that was the first character of ** the encoded buffer from all characters in the output buffer. @@ -114,13 +115,20 @@ ** ** The return value is the number of characters in the encoded ** string, excluding the "\000" terminator. +** +** If out==NULL then no output is generated but the routine still returns +** the number of characters that would have been generated if out had +** not been NULL. */ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){ int i, j, e, m; + unsigned char x; int cnt[256]; if( n<=0 ){ - out[0] = 'x'; - out[1] = 0; + if( out ){ + out[0] = 'x'; + out[1] = 0; + } return 1; } memset(cnt, 0, sizeof(cnt)); @@ -136,24 +144,21 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){ if( m==0 ) break; } } + if( out==0 ){ + return n+m+1; + } out[0] = e; j = 1; for(i=0; i<n; i++){ - int c = (in[i] - e)&0xff; - if( c==0 ){ - out[j++] = 1; - out[j++] = 1; - }else if( c==1 ){ + x = in[i] - e; + if( x==0 || x==1 || x=='\''){ out[j++] = 1; - out[j++] = 2; - }else if( c=='\'' ){ - out[j++] = 1; - out[j++] = 3; - }else{ - out[j++] = c; + x++; } + out[j++] = x; } out[j] = 0; + assert( j==n+m+1 ); return j; } @@ -168,38 +173,32 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out){ ** to decode a string in place. */ int sqlite_decode_binary(const unsigned char *in, unsigned char *out){ - int i, c, e; + int i, e; + unsigned char c; e = *(in++); i = 0; while( (c = *(in++))!=0 ){ if( c==1 ){ - c = *(in++); - if( c==1 ){ - c = 0; - }else if( c==2 ){ - c = 1; - }else if( c==3 ){ - c = '\''; - }else{ - return -1; - } + c = *(in++) - 1; } - out[i++] = (c + e)&0xff; + out[i++] = c + e; } return i; } #ifdef ENCODER_TEST +#include <stdio.h> /* ** The subroutines above are not tested by the usual test suite. To test ** these routines, compile just this one file with a -DENCODER_TEST=1 option ** and run the result. */ int main(int argc, char **argv){ - int i, j, n, m, nOut; + int i, j, n, m, nOut, nByteIn, nByteOut; unsigned char in[30000]; unsigned char out[33000]; + nByteIn = nByteOut = 0; for(i=0; i<sizeof(in); i++){ printf("Test %d: ", i+1); n = rand() % (i+1); @@ -213,11 +212,17 @@ int main(int argc, char **argv){ }else{ for(j=0; j<n; j++) in[j] = rand() & 0xff; } + nByteIn += n; nOut = sqlite_encode_binary(in, n, out); + nByteOut += nOut; if( nOut!=strlen(out) ){ printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out)); exit(1); } + if( nOut!=sqlite_encode_binary(in, n, 0) ){ + printf(" ERROR actual output size disagrees with predicted size\n"); + exit(1); + } m = (256*n + 1262)/253; printf("size %d->%d (max %d)", n, strlen(out)+1, m); if( strlen(out)+1>m ){ @@ -241,5 +246,9 @@ int main(int argc, char **argv){ } printf(" OK\n"); } + fprintf(stderr,"Finished. Total encoding: %d->%d bytes\n", + nByteIn, nByteOut); + fprintf(stderr,"Avg size increase: %.3f%%\n", + (nByteOut-nByteIn)*100.0/(double)nByteIn); } #endif /* ENCODER_TEST */ diff --git a/ext/sqlite/libsqlite/src/expr.c b/ext/sqlite/libsqlite/src/expr.c index 273b3a0a01..44c0f6967a 100644 --- a/ext/sqlite/libsqlite/src/expr.c +++ b/ext/sqlite/libsqlite/src/expr.c @@ -26,8 +26,7 @@ Expr *sqliteExpr(int op, Expr *pLeft, Expr *pRight, Token *pToken){ Expr *pNew; pNew = sqliteMalloc( sizeof(Expr) ); if( pNew==0 ){ - sqliteExprDelete(pLeft); - sqliteExprDelete(pRight); + /* When malloc fails, we leak memory from pLeft and pRight */ return 0; } pNew->op = op; @@ -38,9 +37,9 @@ Expr *sqliteExpr(int op, Expr *pLeft, Expr *pRight, Token *pToken){ pNew->token = *pToken; pNew->span = *pToken; }else{ - pNew->token.dyn = 0; - pNew->token.z = 0; - pNew->token.n = 0; + assert( pNew->token.dyn==0 ); + assert( pNew->token.z==0 ); + assert( pNew->token.n==0 ); if( pLeft && pRight ){ sqliteExprSpan(pNew, &pLeft->span, &pRight->span); }else{ @@ -55,14 +54,15 @@ Expr *sqliteExpr(int op, Expr *pLeft, Expr *pRight, Token *pToken){ ** text between the two given tokens. */ void sqliteExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){ - if( pExpr && pRight && pRight->z && pLeft && pLeft->z ){ + assert( pRight!=0 ); + assert( pLeft!=0 ); + /* Note: pExpr might be NULL due to a prior malloc failure */ + if( pExpr && pRight->z && pLeft->z ){ if( pLeft->dyn==0 && pRight->dyn==0 ){ pExpr->span.z = pLeft->z; pExpr->span.n = pRight->n + Addr(pRight->z) - Addr(pLeft->z); }else{ pExpr->span.z = 0; - pExpr->span.n = 0; - pExpr->span.dyn = 0; } } } @@ -75,18 +75,16 @@ Expr *sqliteExprFunction(ExprList *pList, Token *pToken){ Expr *pNew; pNew = sqliteMalloc( sizeof(Expr) ); if( pNew==0 ){ - sqliteExprListDelete(pList); + /* sqliteExprListDelete(pList); // Leak pList when malloc fails */ return 0; } pNew->op = TK_FUNCTION; pNew->pList = pList; - pNew->token.dyn = 0; if( pToken ){ assert( pToken->dyn==0 ); pNew->token = *pToken; }else{ pNew->token.z = 0; - pNew->token.n = 0; } pNew->span = pNew->token; return pNew; @@ -97,12 +95,12 @@ Expr *sqliteExprFunction(ExprList *pList, Token *pToken){ */ void sqliteExprDelete(Expr *p){ if( p==0 ) return; - if( p->span.dyn && p->span.z ) sqliteFree((char*)p->span.z); - if( p->token.dyn && p->token.z ) sqliteFree((char*)p->token.z); - if( p->pLeft ) sqliteExprDelete(p->pLeft); - if( p->pRight ) sqliteExprDelete(p->pRight); - if( p->pList ) sqliteExprListDelete(p->pList); - if( p->pSelect ) sqliteSelectDelete(p->pSelect); + if( p->span.dyn ) sqliteFree((char*)p->span.z); + if( p->token.dyn ) sqliteFree((char*)p->token.z); + sqliteExprDelete(p->pLeft); + sqliteExprDelete(p->pRight); + sqliteExprListDelete(p->pList); + sqliteSelectDelete(p->pSelect); sqliteFree(p); } @@ -129,13 +127,9 @@ Expr *sqliteExprDup(Expr *p){ pNew->token.z = sqliteStrDup(p->token.z); pNew->token.dyn = 1; }else{ - pNew->token.z = 0; - pNew->token.n = 0; - pNew->token.dyn = 0; + assert( pNew->token.z==0 ); } pNew->span.z = 0; - pNew->span.n = 0; - pNew->span.dyn = 0; pNew->pLeft = sqliteExprDup(p->pLeft); pNew->pRight = sqliteExprDup(p->pRight); pNew->pList = sqliteExprListDup(p->pList); @@ -149,23 +143,22 @@ void sqliteTokenCopy(Token *pTo, Token *pFrom){ pTo->z = sqliteStrNDup(pFrom->z, pFrom->n); pTo->dyn = 1; }else{ - pTo->n = 0; pTo->z = 0; - pTo->dyn = 0; } } ExprList *sqliteExprListDup(ExprList *p){ ExprList *pNew; + struct ExprList_item *pItem; int i; if( p==0 ) return 0; pNew = sqliteMalloc( sizeof(*pNew) ); if( pNew==0 ) return 0; pNew->nExpr = pNew->nAlloc = p->nExpr; - pNew->a = sqliteMalloc( p->nExpr*sizeof(p->a[0]) ); - if( pNew->a==0 ) return 0; - for(i=0; i<p->nExpr; i++){ + pNew->a = pItem = sqliteMalloc( p->nExpr*sizeof(p->a[0]) ); + if( pItem==0 ) return 0; /* Leaks memory after a malloc failure */ + for(i=0; i<p->nExpr; i++, pItem++){ Expr *pNewExpr, *pOldExpr; - pNew->a[i].pExpr = pNewExpr = sqliteExprDup(pOldExpr = p->a[i].pExpr); + pItem->pExpr = pNewExpr = sqliteExprDup(pOldExpr = p->a[i].pExpr); if( pOldExpr->span.z!=0 && pNewExpr ){ /* Always make a copy of the span for top-level expressions in the ** expression list. The logic in SELECT processing that determines @@ -174,10 +167,10 @@ ExprList *sqliteExprListDup(ExprList *p){ } assert( pNewExpr==0 || pNewExpr->span.z!=0 || pOldExpr->span.z==0 || sqlite_malloc_failed ); - pNew->a[i].zName = sqliteStrDup(p->a[i].zName); - pNew->a[i].sortOrder = p->a[i].sortOrder; - pNew->a[i].isAgg = p->a[i].isAgg; - pNew->a[i].done = 0; + pItem->zName = sqliteStrDup(p->a[i].zName); + pItem->sortOrder = p->a[i].sortOrder; + pItem->isAgg = p->a[i].isAgg; + pItem->done = 0; } return pNew; } @@ -187,19 +180,21 @@ SrcList *sqliteSrcListDup(SrcList *p){ int nByte; if( p==0 ) return 0; nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0); - pNew = sqliteMalloc( nByte ); + pNew = sqliteMallocRaw( nByte ); if( pNew==0 ) return 0; pNew->nSrc = pNew->nAlloc = p->nSrc; for(i=0; i<p->nSrc; i++){ - pNew->a[i].zDatabase = sqliteStrDup(p->a[i].zDatabase); - pNew->a[i].zName = sqliteStrDup(p->a[i].zName); - pNew->a[i].zAlias = sqliteStrDup(p->a[i].zAlias); - pNew->a[i].jointype = p->a[i].jointype; - pNew->a[i].iCursor = p->a[i].iCursor; - pNew->a[i].pTab = 0; - pNew->a[i].pSelect = sqliteSelectDup(p->a[i].pSelect); - pNew->a[i].pOn = sqliteExprDup(p->a[i].pOn); - pNew->a[i].pUsing = sqliteIdListDup(p->a[i].pUsing); + struct SrcList_item *pNewItem = &pNew->a[i]; + struct SrcList_item *pOldItem = &p->a[i]; + pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase); + pNewItem->zName = sqliteStrDup(pOldItem->zName); + pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias); + pNewItem->jointype = pOldItem->jointype; + pNewItem->iCursor = pOldItem->iCursor; + pNewItem->pTab = 0; + pNewItem->pSelect = sqliteSelectDup(pOldItem->pSelect); + pNewItem->pOn = sqliteExprDup(pOldItem->pOn); + pNewItem->pUsing = sqliteIdListDup(pOldItem->pUsing); } return pNew; } @@ -207,21 +202,23 @@ IdList *sqliteIdListDup(IdList *p){ IdList *pNew; int i; if( p==0 ) return 0; - pNew = sqliteMalloc( sizeof(*pNew) ); + pNew = sqliteMallocRaw( sizeof(*pNew) ); if( pNew==0 ) return 0; pNew->nId = pNew->nAlloc = p->nId; - pNew->a = sqliteMalloc( p->nId*sizeof(p->a[0]) ); + pNew->a = sqliteMallocRaw( p->nId*sizeof(p->a[0]) ); if( pNew->a==0 ) return 0; for(i=0; i<p->nId; i++){ - pNew->a[i].zName = sqliteStrDup(p->a[i].zName); - pNew->a[i].idx = p->a[i].idx; + struct IdList_item *pNewItem = &pNew->a[i]; + struct IdList_item *pOldItem = &p->a[i]; + pNewItem->zName = sqliteStrDup(pOldItem->zName); + pNewItem->idx = pOldItem->idx; } return pNew; } Select *sqliteSelectDup(Select *p){ Select *pNew; if( p==0 ) return 0; - pNew = sqliteMalloc( sizeof(*p) ); + pNew = sqliteMallocRaw( sizeof(*p) ); if( pNew==0 ) return 0; pNew->isDistinct = p->isDistinct; pNew->pEList = sqliteExprListDup(p->pEList); @@ -246,32 +243,31 @@ Select *sqliteSelectDup(Select *p){ ** initially NULL, then create a new expression list. */ ExprList *sqliteExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){ - int i; if( pList==0 ){ pList = sqliteMalloc( sizeof(ExprList) ); if( pList==0 ){ - sqliteExprDelete(pExpr); + /* sqliteExprDelete(pExpr); // Leak memory if malloc fails */ return 0; } - pList->nAlloc = 0; + assert( pList->nAlloc==0 ); } if( pList->nAlloc<=pList->nExpr ){ - struct ExprList_item *a; pList->nAlloc = pList->nAlloc*2 + 4; - a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0])); - if( a==0 ){ - sqliteExprDelete(pExpr); + pList->a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0])); + if( pList->a==0 ){ + /* sqliteExprDelete(pExpr); // Leak memory if malloc fails */ + pList->nExpr = pList->nAlloc = 0; return pList; } - pList->a = a; } - if( pList->a && (pExpr || pName) ){ - i = pList->nExpr++; - memset(&pList->a[i], 0, sizeof(pList->a[i])); - pList->a[i].pExpr = pExpr; + assert( pList->a!=0 ); + if( pExpr || pName ){ + struct ExprList_item *pItem = &pList->a[pList->nExpr++]; + memset(pItem, 0, sizeof(*pItem)); + pItem->pExpr = pExpr; if( pName ){ - sqliteSetNString(&pList->a[i].zName, pName->z, pName->n, 0); - sqliteDequote(pList->a[i].zName); + sqliteSetNString(&pItem->zName, pName->z, pName->n, 0); + sqliteDequote(pItem->zName); } } return pList; @@ -283,6 +279,8 @@ ExprList *sqliteExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){ void sqliteExprListDelete(ExprList *pList){ int i; if( pList==0 ) return; + assert( pList->a!=0 || (pList->nExpr==0 && pList->nAlloc==0) ); + assert( pList->nExpr<=pList->nAlloc ); for(i=0; i<pList->nExpr; i++){ sqliteExprDelete(pList->a[i].pExpr); sqliteFree(pList->a[i].zName); @@ -380,6 +378,221 @@ int sqliteIsRowid(const char *z){ } /* +** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up +** that name in the set of source tables in pSrcList and make the pExpr +** expression node refer back to that source column. The following changes +** are made to pExpr: +** +** pExpr->iDb Set the index in db->aDb[] of the database holding +** the table. +** pExpr->iTable Set to the cursor number for the table obtained +** from pSrcList. +** pExpr->iColumn Set to the column number within the table. +** pExpr->dataType Set to the appropriate data type for the column. +** pExpr->op Set to TK_COLUMN. +** pExpr->pLeft Any expression this points to is deleted +** pExpr->pRight Any expression this points to is deleted. +** +** The pDbToken is the name of the database (the "X"). This value may be +** NULL meaning that name is of the form Y.Z or Z. Any available database +** can be used. The pTableToken is the name of the table (the "Y"). This +** value can be NULL if pDbToken is also NULL. If pTableToken is NULL it +** means that the form of the name is Z and that columns from any table +** can be used. +** +** If the name cannot be resolved unambiguously, leave an error message +** in pParse and return non-zero. Return zero on success. +*/ +static int lookupName( + Parse *pParse, /* The parsing context */ + Token *pDbToken, /* Name of the database containing table, or NULL */ + Token *pTableToken, /* Name of table containing column, or NULL */ + Token *pColumnToken, /* Name of the column. */ + SrcList *pSrcList, /* List of tables used to resolve column names */ + ExprList *pEList, /* List of expressions used to resolve "AS" */ + Expr *pExpr /* Make this EXPR node point to the selected column */ +){ + char *zDb = 0; /* Name of the database. The "X" in X.Y.Z */ + char *zTab = 0; /* Name of the table. The "Y" in X.Y.Z or Y.Z */ + char *zCol = 0; /* Name of the column. The "Z" */ + int i, j; /* Loop counters */ + int cnt = 0; /* Number of matching column names */ + int cntTab = 0; /* Number of matching table names */ + sqlite *db = pParse->db; /* The database */ + + assert( pColumnToken && pColumnToken->z ); /* The Z in X.Y.Z cannot be NULL */ + if( pDbToken && pDbToken->z ){ + zDb = sqliteStrNDup(pDbToken->z, pDbToken->n); + sqliteDequote(zDb); + }else{ + zDb = 0; + } + if( pTableToken && pTableToken->z ){ + zTab = sqliteStrNDup(pTableToken->z, pTableToken->n); + sqliteDequote(zTab); + }else{ + assert( zDb==0 ); + zTab = 0; + } + zCol = sqliteStrNDup(pColumnToken->z, pColumnToken->n); + sqliteDequote(zCol); + if( sqlite_malloc_failed ){ + return 1; /* Leak memory (zDb and zTab) if malloc fails */ + } + assert( zTab==0 || pEList==0 ); + + pExpr->iTable = -1; + for(i=0; i<pSrcList->nSrc; i++){ + struct SrcList_item *pItem = &pSrcList->a[i]; + Table *pTab = pItem->pTab; + Column *pCol; + + if( pTab==0 ) continue; + assert( pTab->nCol>0 ); + if( zTab ){ + if( pItem->zAlias ){ + char *zTabName = pItem->zAlias; + if( sqliteStrICmp(zTabName, zTab)!=0 ) continue; + }else{ + char *zTabName = pTab->zName; + if( zTabName==0 || sqliteStrICmp(zTabName, zTab)!=0 ) continue; + if( zDb!=0 && sqliteStrICmp(db->aDb[pTab->iDb].zName, zDb)!=0 ){ + continue; + } + } + } + if( 0==(cntTab++) ){ + pExpr->iTable = pItem->iCursor; + pExpr->iDb = pTab->iDb; + } + for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ + if( sqliteStrICmp(pCol->zName, zCol)==0 ){ + cnt++; + pExpr->iTable = pItem->iCursor; + pExpr->iDb = pTab->iDb; + /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */ + pExpr->iColumn = j==pTab->iPKey ? -1 : j; + pExpr->dataType = pCol->sortOrder & SQLITE_SO_TYPEMASK; + break; + } + } + } + + /* If we have not already resolved the name, then maybe + ** it is a new.* or old.* trigger argument reference + */ + if( zDb==0 && zTab!=0 && cnt==0 && pParse->trigStack!=0 ){ + TriggerStack *pTriggerStack = pParse->trigStack; + Table *pTab = 0; + if( pTriggerStack->newIdx != -1 && sqliteStrICmp("new", zTab) == 0 ){ + pExpr->iTable = pTriggerStack->newIdx; + assert( pTriggerStack->pTab ); + pTab = pTriggerStack->pTab; + }else if( pTriggerStack->oldIdx != -1 && sqliteStrICmp("old", zTab) == 0 ){ + pExpr->iTable = pTriggerStack->oldIdx; + assert( pTriggerStack->pTab ); + pTab = pTriggerStack->pTab; + } + + if( pTab ){ + int j; + Column *pCol = pTab->aCol; + + pExpr->iDb = pTab->iDb; + cntTab++; + for(j=0; j < pTab->nCol; j++, pCol++) { + if( sqliteStrICmp(pCol->zName, zCol)==0 ){ + cnt++; + pExpr->iColumn = j==pTab->iPKey ? -1 : j; + pExpr->dataType = pCol->sortOrder & SQLITE_SO_TYPEMASK; + break; + } + } + } + } + + /* + ** Perhaps the name is a reference to the ROWID + */ + if( cnt==0 && cntTab==1 && sqliteIsRowid(zCol) ){ + cnt = 1; + pExpr->iColumn = -1; + pExpr->dataType = SQLITE_SO_NUM; + } + + /* + ** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z + ** might refer to an result-set alias. This happens, for example, when + ** we are resolving names in the WHERE clause of the following command: + ** + ** SELECT a+b AS x FROM table WHERE x<10; + ** + ** In cases like this, replace pExpr with a copy of the expression that + ** forms the result set entry ("a+b" in the example) and return immediately. + ** Note that the expression in the result set should have already been + ** resolved by the time the WHERE clause is resolved. + */ + if( cnt==0 && pEList!=0 ){ + for(j=0; j<pEList->nExpr; j++){ + char *zAs = pEList->a[j].zName; + if( zAs!=0 && sqliteStrICmp(zAs, zCol)==0 ){ + assert( pExpr->pLeft==0 && pExpr->pRight==0 ); + pExpr->op = TK_AS; + pExpr->iColumn = j; + pExpr->pLeft = sqliteExprDup(pEList->a[j].pExpr); + sqliteFree(zCol); + assert( zTab==0 && zDb==0 ); + return 0; + } + } + } + + /* + ** If X and Y are NULL (in other words if only the column name Z is + ** supplied) and the value of Z is enclosed in double-quotes, then + ** Z is a string literal if it doesn't match any column names. In that + ** case, we need to return right away and not make any changes to + ** pExpr. + */ + if( cnt==0 && zTab==0 && pColumnToken->z[0]=='"' ){ + sqliteFree(zCol); + return 0; + } + + /* + ** cnt==0 means there was not match. cnt>1 means there were two or + ** more matches. Either way, we have an error. + */ + if( cnt!=1 ){ + char *z = 0; + char *zErr; + zErr = cnt==0 ? "no such column: %s" : "ambiguous column name: %s"; + if( zDb ){ + sqliteSetString(&z, zDb, ".", zTab, ".", zCol, 0); + }else if( zTab ){ + sqliteSetString(&z, zTab, ".", zCol, 0); + }else{ + z = sqliteStrDup(zCol); + } + sqliteErrorMsg(pParse, zErr, z); + sqliteFree(z); + } + + /* Clean up and return + */ + sqliteFree(zDb); + sqliteFree(zTab); + sqliteFree(zCol); + sqliteExprDelete(pExpr->pLeft); + pExpr->pLeft = 0; + sqliteExprDelete(pExpr->pRight); + pExpr->pRight = 0; + pExpr->op = TK_COLUMN; + sqliteAuthRead(pParse, pExpr, pSrcList); + return cnt!=1; +} + +/* ** This routine walks an expression tree and resolves references to ** table columns. Nodes of the form ID.ID or ID resolve into an ** index to the table in the table list and a column offset. The @@ -412,15 +625,15 @@ int sqliteIsRowid(const char *z){ */ int sqliteExprResolveIds( Parse *pParse, /* The parser context */ - SrcList *pTabList, /* List of tables used to resolve column names */ + SrcList *pSrcList, /* List of tables used to resolve column names */ ExprList *pEList, /* List of expressions used to resolve "AS" */ Expr *pExpr /* The expression to be analyzed. */ ){ int i; - if( pExpr==0 || pTabList==0 ) return 0; - for(i=0; i<pTabList->nSrc; i++){ - assert( pTabList->a[i].iCursor>=0 && pTabList->a[i].iCursor<pParse->nTab ); + if( pExpr==0 || pSrcList==0 ) return 0; + for(i=0; i<pSrcList->nSrc; i++){ + assert( pSrcList->a[i].iCursor>=0 && pSrcList->a[i].iCursor<pParse->nTab ); } switch( pExpr->op ){ /* Double-quoted strings (ex: "abc") are used as identifiers if @@ -431,79 +644,11 @@ int sqliteExprResolveIds( if( pExpr->token.z[0]=='\'' ) break; /* Fall thru into the TK_ID case if this is a double-quoted string */ } - /* A lone identifier. Try and match it as follows: - ** - ** 1. To the name of a column of one of the tables in pTabList - ** - ** 2. To the right side of an AS keyword in the column list of - ** a SELECT statement. (For example, match against 'x' in - ** "SELECT a+b AS 'x' FROM t1".) - ** - ** 3. One of the special names "ROWID", "OID", or "_ROWID_". + /* A lone identifier is the name of a columnd. */ case TK_ID: { - int cnt = 0; /* Number of matches */ - char *z; - int iDb = -1; - - assert( pExpr->token.z ); - z = sqliteStrNDup(pExpr->token.z, pExpr->token.n); - sqliteDequote(z); - if( z==0 ) return 1; - for(i=0; i<pTabList->nSrc; i++){ - int j; - Table *pTab = pTabList->a[i].pTab; - if( pTab==0 ) continue; - iDb = pTab->iDb; - assert( pTab->nCol>0 ); - for(j=0; j<pTab->nCol; j++){ - if( sqliteStrICmp(pTab->aCol[j].zName, z)==0 ){ - cnt++; - pExpr->iTable = pTabList->a[i].iCursor; - pExpr->iDb = pTab->iDb; - if( j==pTab->iPKey ){ - /* Substitute the record number for the INTEGER PRIMARY KEY */ - pExpr->iColumn = -1; - pExpr->dataType = SQLITE_SO_NUM; - }else{ - pExpr->iColumn = j; - pExpr->dataType = pTab->aCol[j].sortOrder & SQLITE_SO_TYPEMASK; - } - pExpr->op = TK_COLUMN; - } - } - } - if( cnt==0 && pEList!=0 ){ - int j; - for(j=0; j<pEList->nExpr; j++){ - char *zAs = pEList->a[j].zName; - if( zAs!=0 && sqliteStrICmp(zAs, z)==0 ){ - cnt++; - assert( pExpr->pLeft==0 && pExpr->pRight==0 ); - pExpr->op = TK_AS; - pExpr->iColumn = j; - pExpr->pLeft = sqliteExprDup(pEList->a[j].pExpr); - } - } - } - if( cnt==0 && iDb>=0 && sqliteIsRowid(z) ){ - pExpr->iColumn = -1; - pExpr->iTable = pTabList->a[0].iCursor; - pExpr->iDb = iDb; - cnt = 1 + (pTabList->nSrc>1); - pExpr->op = TK_COLUMN; - pExpr->dataType = SQLITE_SO_NUM; - } - sqliteFree(z); - if( cnt==0 && pExpr->token.z[0]!='"' ){ - sqliteErrorMsg(pParse, "no such column: %T", &pExpr->token); + if( lookupName(pParse, 0, 0, &pExpr->token, pSrcList, pEList, pExpr) ){ return 1; - }else if( cnt>1 ){ - sqliteErrorMsg(pParse, "ambiguous column name: %T", &pExpr->token); - return 1; - } - if( pExpr->op==TK_COLUMN ){ - sqliteAuthRead(pParse, pExpr, pTabList); } break; } @@ -512,134 +657,32 @@ int sqliteExprResolveIds( ** Or a database, table and column: ID.ID.ID */ case TK_DOT: { - int cnt = 0; /* Number of matches */ - int cntTab = 0; /* Number of matching tables */ - int i; /* Loop counter */ - Expr *pLeft, *pRight; /* Left and right subbranches of the expr */ - char *zLeft, *zRight; /* Text of an identifier */ - char *zDb; /* Name of database holding table */ - sqlite *db = pParse->db; + Token *pColumn; + Token *pTable; + Token *pDb; + Expr *pRight; pRight = pExpr->pRight; if( pRight->op==TK_ID ){ - pLeft = pExpr->pLeft; - zDb = 0; + pDb = 0; + pTable = &pExpr->pLeft->token; + pColumn = &pRight->token; }else{ - Expr *pDb = pExpr->pLeft; - assert( pDb && pDb->op==TK_ID && pDb->token.z ); - zDb = sqliteStrNDup(pDb->token.z, pDb->token.n); - pLeft = pRight->pLeft; - pRight = pRight->pRight; + assert( pRight->op==TK_DOT ); + pDb = &pExpr->pLeft->token; + pTable = &pRight->pLeft->token; + pColumn = &pRight->pRight->token; } - assert( pLeft && pLeft->op==TK_ID && pLeft->token.z ); - assert( pRight && pRight->op==TK_ID && pRight->token.z ); - zLeft = sqliteStrNDup(pLeft->token.z, pLeft->token.n); - zRight = sqliteStrNDup(pRight->token.z, pRight->token.n); - if( zLeft==0 || zRight==0 ){ - sqliteFree(zLeft); - sqliteFree(zRight); - sqliteFree(zDb); + if( lookupName(pParse, pDb, pTable, pColumn, pSrcList, 0, pExpr) ){ return 1; } - sqliteDequote(zDb); - sqliteDequote(zLeft); - sqliteDequote(zRight); - pExpr->iTable = -1; - for(i=0; i<pTabList->nSrc; i++){ - int j; - char *zTab; - Table *pTab = pTabList->a[i].pTab; - if( pTab==0 ) continue; - assert( pTab->nCol>0 ); - if( pTabList->a[i].zAlias ){ - zTab = pTabList->a[i].zAlias; - if( sqliteStrICmp(zTab, zLeft)!=0 ) continue; - }else{ - zTab = pTab->zName; - if( zTab==0 || sqliteStrICmp(zTab, zLeft)!=0 ) continue; - if( zDb!=0 && sqliteStrICmp(db->aDb[pTab->iDb].zName, zDb)!=0 ){ - continue; - } - } - if( 0==(cntTab++) ){ - pExpr->iTable = pTabList->a[i].iCursor; - pExpr->iDb = pTab->iDb; - } - for(j=0; j<pTab->nCol; j++){ - if( sqliteStrICmp(pTab->aCol[j].zName, zRight)==0 ){ - cnt++; - pExpr->iTable = pTabList->a[i].iCursor; - pExpr->iDb = pTab->iDb; - /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */ - pExpr->iColumn = j==pTab->iPKey ? -1 : j; - pExpr->dataType = pTab->aCol[j].sortOrder & SQLITE_SO_TYPEMASK; - } - } - } - - /* If we have not already resolved this *.* expression, then maybe - * it is a new.* or old.* trigger argument reference */ - if( cnt == 0 && pParse->trigStack != 0 ){ - TriggerStack *pTriggerStack = pParse->trigStack; - int t = 0; - if( pTriggerStack->newIdx != -1 && sqliteStrICmp("new", zLeft) == 0 ){ - pExpr->iTable = pTriggerStack->newIdx; - assert( pTriggerStack->pTab ); - pExpr->iDb = pTriggerStack->pTab->iDb; - cntTab++; - t = 1; - } - if( pTriggerStack->oldIdx != -1 && sqliteStrICmp("old", zLeft) == 0 ){ - pExpr->iTable = pTriggerStack->oldIdx; - assert( pTriggerStack->pTab ); - pExpr->iDb = pTriggerStack->pTab->iDb; - cntTab++; - t = 1; - } - - if( t ){ - int j; - Table *pTab = pTriggerStack->pTab; - for(j=0; j < pTab->nCol; j++) { - if( sqliteStrICmp(pTab->aCol[j].zName, zRight)==0 ){ - cnt++; - pExpr->iColumn = j==pTab->iPKey ? -1 : j; - pExpr->dataType = pTab->aCol[j].sortOrder & SQLITE_SO_TYPEMASK; - } - } - } - } - - if( cnt==0 && cntTab==1 && sqliteIsRowid(zRight) ){ - cnt = 1; - pExpr->iColumn = -1; - pExpr->dataType = SQLITE_SO_NUM; - } - sqliteFree(zDb); - sqliteFree(zLeft); - sqliteFree(zRight); - if( cnt==0 ){ - sqliteErrorMsg(pParse, "no such column: %T.%T", - &pLeft->token, &pRight->token); - return 1; - }else if( cnt>1 ){ - sqliteErrorMsg(pParse, "ambiguous column name: %T.%T", - &pLeft->token, &pRight->token); - return 1; - } - sqliteExprDelete(pExpr->pLeft); - pExpr->pLeft = 0; - sqliteExprDelete(pExpr->pRight); - pExpr->pRight = 0; - pExpr->op = TK_COLUMN; - sqliteAuthRead(pParse, pExpr, pTabList); break; } case TK_IN: { Vdbe *v = sqliteGetVdbe(pParse); if( v==0 ) return 1; - if( sqliteExprResolveIds(pParse, pTabList, pEList, pExpr->pLeft) ){ + if( sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){ return 1; } if( pExpr->pSelect ){ @@ -677,9 +720,10 @@ int sqliteExprResolveIds( case TK_FLOAT: case TK_INTEGER: case TK_STRING: { - int addr = sqliteVdbeAddOp(v, OP_SetInsert, iSet, 0); + int addr; assert( pE2->token.z ); - sqliteVdbeChangeP3(v, addr, pE2->token.z, pE2->token.n); + addr = sqliteVdbeOp3(v, OP_SetInsert, iSet, 0, + pE2->token.z, pE2->token.n); sqliteVdbeDequoteP3(v, addr); break; } @@ -709,11 +753,11 @@ int sqliteExprResolveIds( /* For all else, just recursively walk the tree */ default: { if( pExpr->pLeft - && sqliteExprResolveIds(pParse, pTabList, pEList, pExpr->pLeft) ){ + && sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){ return 1; } if( pExpr->pRight - && sqliteExprResolveIds(pParse, pTabList, pEList, pExpr->pRight) ){ + && sqliteExprResolveIds(pParse, pSrcList, pEList, pExpr->pRight) ){ return 1; } if( pExpr->pList ){ @@ -721,7 +765,7 @@ int sqliteExprResolveIds( ExprList *pList = pExpr->pList; for(i=0; i<pList->nExpr; i++){ Expr *pArg = pList->a[i].pExpr; - if( sqliteExprResolveIds(pParse, pTabList, pEList, pArg) ){ + if( sqliteExprResolveIds(pParse, pSrcList, pEList, pArg) ){ return 1; } } @@ -782,7 +826,6 @@ int sqliteExprCheck(Parse *pParse, Expr *pExpr, int allowAgg, int *pIsAgg){ case TK_FUNCTION: { int n = pExpr->pList ? pExpr->pList->nExpr : 0; /* Number of arguments */ int no_such_func = 0; /* True if no such function exists */ - int is_type_of = 0; /* True if is the special TypeOf() function */ int wrong_num_args = 0; /* True if wrong number of arguments */ int is_agg = 0; /* True if is an aggregate function */ int i; @@ -795,11 +838,7 @@ int sqliteExprCheck(Parse *pParse, Expr *pExpr, int allowAgg, int *pIsAgg){ if( pDef==0 ){ pDef = sqliteFindFunction(pParse->db, zId, nId, -1, 0); if( pDef==0 ){ - if( n==1 && nId==6 && sqliteStrNICmp(zId, "typeof", 6)==0 ){ - is_type_of = 1; - }else { - no_such_func = 1; - } + no_such_func = 1; }else{ wrong_num_args = 1; } @@ -807,38 +846,27 @@ int sqliteExprCheck(Parse *pParse, Expr *pExpr, int allowAgg, int *pIsAgg){ is_agg = pDef->xFunc==0; } if( is_agg && !allowAgg ){ - sqliteSetNString(&pParse->zErrMsg, "misuse of aggregate function ", -1, - zId, nId, "()", 2, 0); - pParse->nErr++; + sqliteErrorMsg(pParse, "misuse of aggregate function %.*s()", nId, zId); nErr++; is_agg = 0; }else if( no_such_func ){ - sqliteSetNString(&pParse->zErrMsg, "no such function: ", -1, zId,nId,0); - pParse->nErr++; + sqliteErrorMsg(pParse, "no such function: %.*s", nId, zId); nErr++; }else if( wrong_num_args ){ - sqliteSetNString(&pParse->zErrMsg, - "wrong number of arguments to function ", -1, zId, nId, "()", 2, 0); - pParse->nErr++; + sqliteErrorMsg(pParse,"wrong number of arguments to function %.*s()", + nId, zId); nErr++; } - if( is_agg ) pExpr->op = TK_AGG_FUNCTION; - if( is_agg && pIsAgg ) *pIsAgg = 1; + if( is_agg ){ + pExpr->op = TK_AGG_FUNCTION; + if( pIsAgg ) *pIsAgg = 1; + } for(i=0; nErr==0 && i<n; i++){ nErr = sqliteExprCheck(pParse, pExpr->pList->a[i].pExpr, allowAgg && !is_agg, pIsAgg); } if( pDef==0 ){ - if( is_type_of ){ - pExpr->op = TK_STRING; - if( sqliteExprType(pExpr->pList->a[0].pExpr)==SQLITE_SO_NUM ){ - pExpr->token.z = "numeric"; - pExpr->token.n = 7; - }else{ - pExpr->token.z = "text"; - pExpr->token.n = 4; - } - } + /* Already reported an error */ }else if( pDef->dataType>=0 ){ if( pDef->dataType<n ){ pExpr->dataType = @@ -973,8 +1001,6 @@ int sqliteExprType(Expr *p){ return SQLITE_SO_NUM; } -/* Run */ - /* ** Generate code into the current Vdbe to evaluate the given ** expression and leave the result on the top of stack. @@ -1019,26 +1045,17 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ } break; } + case TK_STRING: + case TK_FLOAT: case TK_INTEGER: { - if( !sqliteFitsIn32Bits(pExpr->token.z) ){ - sqliteVdbeAddOp(v, OP_String, 0, 0); - }else{ + if( pExpr->op==TK_INTEGER && sqliteFitsIn32Bits(pExpr->token.z) ){ sqliteVdbeAddOp(v, OP_Integer, atoi(pExpr->token.z), 0); + }else{ + sqliteVdbeAddOp(v, OP_String, 0, 0); } - sqliteVdbeChangeP3(v, -1, pExpr->token.z, pExpr->token.n); - break; - } - case TK_FLOAT: { - sqliteVdbeAddOp(v, OP_String, 0, 0); assert( pExpr->token.z ); sqliteVdbeChangeP3(v, -1, pExpr->token.z, pExpr->token.n); - break; - } - case TK_STRING: { - int addr = sqliteVdbeAddOp(v, OP_String, 0, 0); - assert( pExpr->token.z ); - sqliteVdbeChangeP3(v, addr, pExpr->token.z, pExpr->token.n); - sqliteVdbeDequoteP3(v, addr); + sqliteVdbeDequoteP3(v, -1); break; } case TK_NULL: { @@ -1087,23 +1104,6 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ sqliteVdbeAddOp(v, OP_Concat, 2, 0); break; } - case TK_UPLUS: { - Expr *pLeft = pExpr->pLeft; - if( pLeft && pLeft->op==TK_INTEGER ){ - if( sqliteFitsIn32Bits(pLeft->token.z) ){ - sqliteVdbeAddOp(v, OP_Integer, atoi(pLeft->token.z), 0); - }else{ - sqliteVdbeAddOp(v, OP_String, 0, 0); - } - sqliteVdbeChangeP3(v, -1, pLeft->token.z, pLeft->token.n); - }else if( pLeft && pLeft->op==TK_FLOAT ){ - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pLeft->token.z, pLeft->token.n); - }else{ - sqliteExprCode(pParse, pExpr->pLeft); - } - break; - } case TK_UMINUS: { assert( pExpr->pLeft ); if( pExpr->pLeft->op==TK_FLOAT || pExpr->pLeft->op==TK_INTEGER ){ @@ -1144,7 +1144,6 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ case TK_GLOB: case TK_LIKE: case TK_FUNCTION: { - int i; ExprList *pList = pExpr->pList; int nExpr = pList ? pList->nExpr : 0; FuncDef *pDef; @@ -1153,11 +1152,8 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ getFunctionName(pExpr, &zId, &nId); pDef = sqliteFindFunction(pParse->db, zId, nId, nExpr, 0); assert( pDef!=0 ); - for(i=0; i<nExpr; i++){ - sqliteExprCode(pParse, pList->a[i].pExpr); - } - sqliteVdbeAddOp(v, OP_Function, nExpr, 0); - sqliteVdbeChangeP3(v, -1, (char*)pDef, P3_POINTER); + nExpr = sqliteExprCodeExprList(pParse, pList, pDef->includeTypes); + sqliteVdbeOp3(v, OP_Function, nExpr, 0, (char*)pDef, P3_POINTER); break; } case TK_SELECT: { @@ -1170,7 +1166,7 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ sqliteExprCode(pParse, pExpr->pLeft); addr = sqliteVdbeCurrentAddr(v); sqliteVdbeAddOp(v, OP_NotNull, -1, addr+4); - sqliteVdbeAddOp(v, OP_Pop, 1, 0); + sqliteVdbeAddOp(v, OP_Pop, 2, 0); sqliteVdbeAddOp(v, OP_String, 0, 0); sqliteVdbeAddOp(v, OP_Goto, 0, addr+6); if( pExpr->pSelect ){ @@ -1192,6 +1188,7 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ sqliteVdbeAddOp(v, OP_And, 0, 0); break; } + case TK_UPLUS: case TK_AS: { sqliteExprCode(pParse, pExpr->pLeft); break; @@ -1246,15 +1243,13 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ if( pExpr->iColumn == OE_Rollback || pExpr->iColumn == OE_Abort || pExpr->iColumn == OE_Fail ){ - char * msg = sqliteStrNDup(pExpr->token.z, pExpr->token.n); - sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn); - sqliteDequote(msg); - sqliteVdbeChangeP3(v, -1, msg, 0); - sqliteFree(msg); + sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn, + pExpr->token.z, pExpr->token.n); + sqliteVdbeDequoteP3(v, -1); } else { assert( pExpr->iColumn == OE_Ignore ); - sqliteVdbeAddOp(v, OP_Goto, 0, pParse->trigStack->ignoreJump); - sqliteVdbeChangeP3(v, -1, "(IGNORE jump)", 0); + sqliteVdbeOp3(v, OP_Goto, 0, pParse->trigStack->ignoreJump, + "(IGNORE jump)", 0); } } break; @@ -1262,6 +1257,36 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){ } /* +** Generate code that pushes the value of every element of the given +** expression list onto the stack. If the includeTypes flag is true, +** then also push a string that is the datatype of each element onto +** the stack after the value. +** +** Return the number of elements pushed onto the stack. +*/ +int sqliteExprCodeExprList( + Parse *pParse, /* Parsing context */ + ExprList *pList, /* The expression list to be coded */ + int includeTypes /* TRUE to put datatypes on the stack too */ +){ + struct ExprList_item *pItem; + int i, n; + Vdbe *v; + if( pList==0 ) return 0; + v = sqliteGetVdbe(pParse); + n = pList->nExpr; + for(pItem=pList->a, i=0; i<n; i++, pItem++){ + sqliteExprCode(pParse, pItem->pExpr); + if( includeTypes ){ + sqliteVdbeOp3(v, OP_String, 0, 0, + sqliteExprType(pItem->pExpr)==SQLITE_SO_NUM ? "numeric" : "text", + P3_STATIC); + } + } + return includeTypes ? n*2 : n; +} + +/* ** Generate code for a boolean expression such that a jump is made ** to the label "dest" if the expression is true but execution ** continues straight thru if the expression is false. diff --git a/ext/sqlite/libsqlite/src/func.c b/ext/sqlite/libsqlite/src/func.c index c348db21c5..d54f341472 100644 --- a/ext/sqlite/libsqlite/src/func.c +++ b/ext/sqlite/libsqlite/src/func.c @@ -28,35 +28,36 @@ /* ** Implementation of the non-aggregate min() and max() functions */ -static void minFunc(sqlite_func *context, int argc, const char **argv){ +static void minmaxFunc(sqlite_func *context, int argc, const char **argv){ const char *zBest; int i; + int (*xCompare)(const char*, const char*); + int mask; /* 0 for min() or 0xffffffff for max() */ if( argc==0 ) return; + mask = (int)sqlite_user_data(context); zBest = argv[0]; if( zBest==0 ) return; - for(i=1; i<argc; i++){ + if( argv[1][0]=='n' ){ + xCompare = sqliteCompare; + }else{ + xCompare = strcmp; + } + for(i=2; i<argc; i+=2){ if( argv[i]==0 ) return; - if( sqliteCompare(argv[i], zBest)<0 ){ + if( (xCompare(argv[i], zBest)^mask)<0 ){ zBest = argv[i]; } } sqlite_set_result_string(context, zBest, -1); } -static void maxFunc(sqlite_func *context, int argc, const char **argv){ - const char *zBest; - int i; - if( argc==0 ) return; - zBest = argv[0]; - if( zBest==0 ) return; - for(i=1; i<argc; i++){ - if( argv[i]==0 ) return; - if( sqliteCompare(argv[i], zBest)>0 ){ - zBest = argv[i]; - } - } - sqlite_set_result_string(context, zBest, -1); +/* +** Return the type of the argument. +*/ +static void typeofFunc(sqlite_func *context, int argc, const char **argv){ + assert( argc==2 ); + sqlite_set_result_string(context, argv[1], -1); } /* @@ -147,7 +148,7 @@ static void roundFunc(sqlite_func *context, int argc, const char **argv){ n = argc==2 ? atoi(argv[1]) : 0; if( n>30 ) n = 30; if( n<0 ) n = 0; - r = sqliteAtoF(argv[0]); + r = sqliteAtoF(argv[0], 0); sprintf(zBuf,"%.*f",n,r); sqlite_set_result_string(context, zBuf, -1); } @@ -178,8 +179,8 @@ static void lowerFunc(sqlite_func *context, int argc, const char **argv){ /* ** Implementation of the IFNULL(), NVL(), and COALESCE() functions. -** All three do the same thing. They return the first argument -** non-NULL argument. +** All three do the same thing. They return the first non-NULL +** argument. */ static void ifnullFunc(sqlite_func *context, int argc, const char **argv){ int i; @@ -195,7 +196,9 @@ static void ifnullFunc(sqlite_func *context, int argc, const char **argv){ ** Implementation of random(). Return a random integer. */ static void randomFunc(sqlite_func *context, int argc, const char **argv){ - sqlite_set_result_int(context, sqliteRandomInteger()); + int r; + sqliteRandomness(sizeof(r), &r); + sqlite_set_result_int(context, r); } /* @@ -208,6 +211,25 @@ static void last_insert_rowid(sqlite_func *context, int arg, const char **argv){ } /* +** Implementation of the change_count() SQL function. The return +** value is the same as the sqlite_changes() API function. +*/ +static void change_count(sqlite_func *context, int arg, const char **argv){ + sqlite *db = sqlite_user_data(context); + sqlite_set_result_int(context, sqlite_changes(db)); +} + +/* +** Implementation of the last_statement_change_count() SQL function. The +** return value is the same as the sqlite_last_statement_changes() API function. +*/ +static void last_statement_change_count(sqlite_func *context, int arg, + const char **argv){ + sqlite *db = sqlite_user_data(context); + sqlite_set_result_int(context, sqlite_last_statement_changes(db)); +} + +/* ** Implementation of the like() SQL function. This function implements ** the build-in LIKE operator. The first argument to the function is the ** string and the second argument is the pattern. So, the SQL statements: @@ -341,13 +363,13 @@ static void soundexFunc(sqlite_func *context, int argc, const char **argv){ ** generating test data. */ static void randStr(sqlite_func *context, int argc, const char **argv){ - static const char zSrc[] = + static const unsigned char zSrc[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" ".-!,:*^+=_|?/<> "; int iMin, iMax, n, r, i; - char zBuf[1000]; + unsigned char zBuf[1000]; if( argc>=1 ){ iMin = atoi(argv[0]); if( iMin<0 ) iMin = 0; @@ -358,19 +380,20 @@ static void randStr(sqlite_func *context, int argc, const char **argv){ if( argc>=2 ){ iMax = atoi(argv[1]); if( iMax<iMin ) iMax = iMin; - if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf); + if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1; }else{ iMax = 50; } n = iMin; if( iMax>iMin ){ - r = sqliteRandomInteger() & 0x7fffffff; + sqliteRandomness(sizeof(r), &r); + r &= 0x7fffffff; n += r%(iMax + 1 - iMin); } - r = 0; + assert( n<sizeof(zBuf) ); + sqliteRandomness(n, zBuf); for(i=0; i<n; i++){ - r = (r + sqliteRandomByte())% (sizeof(zSrc)-1); - zBuf[i] = zSrc[r]; + zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)]; } zBuf[n] = 0; sqlite_set_result_string(context, zBuf, n); @@ -395,7 +418,7 @@ static void sumStep(sqlite_func *context, int argc, const char **argv){ if( argc<1 ) return; p = sqlite_aggregate_context(context, sizeof(*p)); if( p && argv[0] ){ - p->sum += sqliteAtoF(argv[0]); + p->sum += sqliteAtoF(argv[0], 0); p->cnt++; } } @@ -433,7 +456,7 @@ static void stdDevStep(sqlite_func *context, int argc, const char **argv){ if( argc<1 ) return; p = sqlite_aggregate_context(context, sizeof(*p)); if( p && argv[0] ){ - x = sqliteAtoF(argv[0]); + x = sqliteAtoF(argv[0], 0); p->sum += x; p->sum2 += x*x; p->cnt++; @@ -488,39 +511,32 @@ struct MinMaxCtx { /* ** Routines to implement min() and max() aggregate functions. */ -static void minStep(sqlite_func *context, int argc, const char **argv){ +static void minmaxStep(sqlite_func *context, int argc, const char **argv){ MinMaxCtx *p; - p = sqlite_aggregate_context(context, sizeof(*p)); - if( p==0 || argc<1 || argv[0]==0 ) return; - if( p->z==0 || sqliteCompare(argv[0],p->z)<0 ){ - int len; - if( p->z && p->z!=p->zBuf ){ - sqliteFree(p->z); - } - len = strlen(argv[0]); - if( len < sizeof(p->zBuf) ){ - p->z = p->zBuf; - }else{ - p->z = sqliteMalloc( len+1 ); - if( p->z==0 ) return; - } - strcpy(p->z, argv[0]); + int (*xCompare)(const char*, const char*); + int mask; /* 0 for min() or 0xffffffff for max() */ + + assert( argc==2 ); + if( argv[1][0]=='n' ){ + xCompare = sqliteCompare; + }else{ + xCompare = strcmp; } -} -static void maxStep(sqlite_func *context, int argc, const char **argv){ - MinMaxCtx *p; + mask = (int)sqlite_user_data(context); p = sqlite_aggregate_context(context, sizeof(*p)); if( p==0 || argc<1 || argv[0]==0 ) return; - if( p->z==0 || sqliteCompare(argv[0],p->z)>0 ){ + if( p->z==0 || (xCompare(argv[0],p->z)^mask)<0 ){ int len; - if( p->z && p->z!=p->zBuf ){ + if( !p->zBuf[0] ){ sqliteFree(p->z); } len = strlen(argv[0]); - if( len < sizeof(p->zBuf) ){ - p->z = p->zBuf; + if( len < sizeof(p->zBuf)-1 ){ + p->z = &p->zBuf[1]; + p->zBuf[0] = 1; }else{ p->z = sqliteMalloc( len+1 ); + p->zBuf[0] = 0; if( p->z==0 ) return; } strcpy(p->z, argv[0]); @@ -532,7 +548,7 @@ static void minMaxFinalize(sqlite_func *context){ if( p && p->z ){ sqlite_set_result_string(context, p->z, strlen(p->z)); } - if( p && p->z && p->z!=p->zBuf ){ + if( p && !p->zBuf[0] ){ sqliteFree(p->z); } } @@ -545,71 +561,86 @@ static void minMaxFinalize(sqlite_func *context){ void sqliteRegisterBuiltinFunctions(sqlite *db){ static struct { char *zName; - int nArg; - int dataType; + signed char nArg; + signed char dataType; + u8 argType; /* 0: none. 1: db 2: (-1) */ void (*xFunc)(sqlite_func*,int,const char**); } aFuncs[] = { - { "min", -1, SQLITE_ARGS, minFunc }, - { "min", 0, 0, 0 }, - { "max", -1, SQLITE_ARGS, maxFunc }, - { "max", 0, 0, 0 }, - { "length", 1, SQLITE_NUMERIC, lengthFunc }, - { "substr", 3, SQLITE_TEXT, substrFunc }, - { "abs", 1, SQLITE_NUMERIC, absFunc }, - { "round", 1, SQLITE_NUMERIC, roundFunc }, - { "round", 2, SQLITE_NUMERIC, roundFunc }, - { "upper", 1, SQLITE_TEXT, upperFunc }, - { "lower", 1, SQLITE_TEXT, lowerFunc }, - { "coalesce", -1, SQLITE_ARGS, ifnullFunc }, - { "coalesce", 0, 0, 0 }, - { "coalesce", 1, 0, 0 }, - { "ifnull", 2, SQLITE_ARGS, ifnullFunc }, - { "random", -1, SQLITE_NUMERIC, randomFunc }, - { "like", 2, SQLITE_NUMERIC, likeFunc }, - { "glob", 2, SQLITE_NUMERIC, globFunc }, - { "nullif", 2, SQLITE_ARGS, nullifFunc }, - { "sqlite_version",0,SQLITE_TEXT, versionFunc}, - { "quote", 1, SQLITE_ARGS, quoteFunc }, + { "min", -1, SQLITE_ARGS, 0, minmaxFunc }, + { "min", 0, 0, 0, 0 }, + { "max", -1, SQLITE_ARGS, 2, minmaxFunc }, + { "max", 0, 0, 2, 0 }, + { "typeof", 1, SQLITE_TEXT, 0, typeofFunc }, + { "length", 1, SQLITE_NUMERIC, 0, lengthFunc }, + { "substr", 3, SQLITE_TEXT, 0, substrFunc }, + { "abs", 1, SQLITE_NUMERIC, 0, absFunc }, + { "round", 1, SQLITE_NUMERIC, 0, roundFunc }, + { "round", 2, SQLITE_NUMERIC, 0, roundFunc }, + { "upper", 1, SQLITE_TEXT, 0, upperFunc }, + { "lower", 1, SQLITE_TEXT, 0, lowerFunc }, + { "coalesce", -1, SQLITE_ARGS, 0, ifnullFunc }, + { "coalesce", 0, 0, 0, 0 }, + { "coalesce", 1, 0, 0, 0 }, + { "ifnull", 2, SQLITE_ARGS, 0, ifnullFunc }, + { "random", -1, SQLITE_NUMERIC, 0, randomFunc }, + { "like", 2, SQLITE_NUMERIC, 0, likeFunc }, + { "glob", 2, SQLITE_NUMERIC, 0, globFunc }, + { "nullif", 2, SQLITE_ARGS, 0, nullifFunc }, + { "sqlite_version",0,SQLITE_TEXT, 0, versionFunc}, + { "quote", 1, SQLITE_ARGS, 0, quoteFunc }, + { "last_insert_rowid", 0, SQLITE_NUMERIC, 1, last_insert_rowid }, + { "change_count", 0, SQLITE_NUMERIC, 1, change_count }, + { "last_statement_change_count", + 0, SQLITE_NUMERIC, 1, last_statement_change_count }, #ifdef SQLITE_SOUNDEX - { "soundex", 1, SQLITE_TEXT, soundexFunc}, + { "soundex", 1, SQLITE_TEXT, 0, soundexFunc}, #endif #ifdef SQLITE_TEST - { "randstr", 2, SQLITE_TEXT, randStr }, + { "randstr", 2, SQLITE_TEXT, 0, randStr }, #endif }; static struct { char *zName; - int nArg; - int dataType; + signed char nArg; + signed char dataType; + u8 argType; void (*xStep)(sqlite_func*,int,const char**); void (*xFinalize)(sqlite_func*); } aAggs[] = { - { "min", 1, 0, minStep, minMaxFinalize }, - { "max", 1, 0, maxStep, minMaxFinalize }, - { "sum", 1, SQLITE_NUMERIC, sumStep, sumFinalize }, - { "avg", 1, SQLITE_NUMERIC, sumStep, avgFinalize }, - { "count", 0, SQLITE_NUMERIC, countStep, countFinalize }, - { "count", 1, SQLITE_NUMERIC, countStep, countFinalize }, + { "min", 1, 0, 0, minmaxStep, minMaxFinalize }, + { "max", 1, 0, 2, minmaxStep, minMaxFinalize }, + { "sum", 1, SQLITE_NUMERIC, 0, sumStep, sumFinalize }, + { "avg", 1, SQLITE_NUMERIC, 0, sumStep, avgFinalize }, + { "count", 0, SQLITE_NUMERIC, 0, countStep, countFinalize }, + { "count", 1, SQLITE_NUMERIC, 0, countStep, countFinalize }, #if 0 - { "stddev", 1, SQLITE_NUMERIC, stdDevStep, stdDevFinalize }, + { "stddev", 1, SQLITE_NUMERIC, 0, stdDevStep, stdDevFinalize }, #endif }; + static const char *azTypeFuncs[] = { "min", "max", "typeof" }; int i; for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){ + void *pArg = aFuncs[i].argType==2 ? (void*)(-1) : db; sqlite_create_function(db, aFuncs[i].zName, - aFuncs[i].nArg, aFuncs[i].xFunc, 0); + aFuncs[i].nArg, aFuncs[i].xFunc, pArg); if( aFuncs[i].xFunc ){ sqlite_function_type(db, aFuncs[i].zName, aFuncs[i].dataType); } } - sqlite_create_function(db, "last_insert_rowid", 0, - last_insert_rowid, db); - sqlite_function_type(db, "last_insert_rowid", SQLITE_NUMERIC); for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){ + void *pArg = aAggs[i].argType==2 ? (void*)(-1) : db; sqlite_create_aggregate(db, aAggs[i].zName, - aAggs[i].nArg, aAggs[i].xStep, aAggs[i].xFinalize, 0); + aAggs[i].nArg, aAggs[i].xStep, aAggs[i].xFinalize, pArg); sqlite_function_type(db, aAggs[i].zName, aAggs[i].dataType); } + for(i=0; i<sizeof(azTypeFuncs)/sizeof(azTypeFuncs[0]); i++){ + int n = strlen(azTypeFuncs[i]); + FuncDef *p = sqliteHashFind(&db->aFunc, azTypeFuncs[i], n); + while( p ){ + p->includeTypes = 1; + p = p->pNext; + } + } sqliteRegisterDateTimeFunctions(db); } diff --git a/ext/sqlite/libsqlite/src/insert.c b/ext/sqlite/libsqlite/src/insert.c index ab72cb761d..86c581edee 100644 --- a/ext/sqlite/libsqlite/src/insert.c +++ b/ext/sqlite/libsqlite/src/insert.c @@ -330,14 +330,7 @@ void sqliteInsert( /* Open tables and indices if there are no row triggers */ if( !row_triggers_exist ){ base = pParse->nTab; - sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, base, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); - for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){ - sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, idx+base, pIdx->tnum); - sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); - } + idx = sqliteOpenTableAndIndices(pParse, pTab, base); pParse->nTab += idx; } @@ -391,8 +384,7 @@ void sqliteInsert( } } if( pColumn && j>=pColumn->nId ){ - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC); }else if( useTempTable ){ sqliteVdbeAddOp(v, OP_Column, srcTab, j); }else if( pSelect ){ @@ -416,14 +408,7 @@ void sqliteInsert( */ if( row_triggers_exist && !isView ){ base = pParse->nTab; - sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, base, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); - for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){ - sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenWrite, idx+base, pIdx->tnum); - sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); - } + idx = sqliteOpenTableAndIndices(pParse, pTab, base); pParse->nTab += idx; } @@ -472,8 +457,7 @@ void sqliteInsert( } } if( pColumn && j>=pColumn->nId ){ - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC); }else if( useTempTable ){ sqliteVdbeAddOp(v, OP_Column, srcTab, j); }else if( pSelect ){ @@ -535,14 +519,14 @@ void sqliteInsert( } } + sqliteVdbeAddOp(v, OP_SetCounts, 0, 0); sqliteEndWriteOperation(pParse); /* ** Return the number of rows inserted. */ if( db->flags & SQLITE_CountRows ){ - sqliteVdbeAddOp(v, OP_ColumnName, 0, 0); - sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC); + sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows inserted", P3_STATIC); sqliteVdbeAddOp(v, OP_MemLoad, iCntMem, 0); sqliteVdbeAddOp(v, OP_Callback, 1, 0); } @@ -698,8 +682,7 @@ void sqliteGenerateConstraintChecks( break; } case OE_Replace: { - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zDflt, P3_STATIC); sqliteVdbeAddOp(v, OP_Push, nCol-i, 0); break; } @@ -741,8 +724,8 @@ void sqliteGenerateConstraintChecks( case OE_Rollback: case OE_Abort: case OE_Fail: { - sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError); - sqliteVdbeChangeP3(v, -1, "PRIMARY KEY must be unique", P3_STATIC); + sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, + "PRIMARY KEY must be unique", P3_STATIC); break; } case OE_Replace: { @@ -839,8 +822,7 @@ void sqliteGenerateConstraintChecks( } strcpy(&zErrMsg[n1], pIdx->nColumn>1 ? " are not unique" : " is not unique"); - sqliteVdbeAddOp(v, OP_Halt, SQLITE_CONSTRAINT, onError); - sqliteVdbeChangeP3(v, -1, sqliteStrDup(zErrMsg), P3_DYNAMIC); + sqliteVdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, zErrMsg, 0); break; } case OE_Ignore: { @@ -906,8 +888,32 @@ void sqliteCompleteInsertion( sqliteVdbeAddOp(v, OP_Dup, 1, 0); sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0); } - sqliteVdbeAddOp(v, OP_PutIntKey, base, pParse->trigStack?0:1); + sqliteVdbeAddOp(v, OP_PutIntKey, base, + (pParse->trigStack?0:OPFLAG_NCHANGE) | + (isUpdate?0:OPFLAG_LASTROWID) | OPFLAG_CSCHANGE); if( isUpdate && recnoChng ){ sqliteVdbeAddOp(v, OP_Pop, 1, 0); } } + +/* +** Generate code that will open write cursors for a table and for all +** indices of that table. The "base" parameter is the cursor number used +** for the table. Indices are opened on subsequent cursors. +** +** Return the total number of cursors opened. This is always at least +** 1 (for the main table) plus more for each cursor. +*/ +int sqliteOpenTableAndIndices(Parse *pParse, Table *pTab, int base){ + int i; + Index *pIdx; + Vdbe *v = sqliteGetVdbe(pParse); + assert( v!=0 ); + sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); + sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC); + for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ + sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); + sqliteVdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC); + } + return i; +} diff --git a/ext/sqlite/libsqlite/src/main.c b/ext/sqlite/libsqlite/src/main.c index e2b269738b..e6cc80f450 100644 --- a/ext/sqlite/libsqlite/src/main.c +++ b/ext/sqlite/libsqlite/src/main.c @@ -33,8 +33,9 @@ typedef struct { ** Fill the InitData structure with an error message that indicates ** that the database is corrupt. */ -static void corruptSchema(InitData *pData){ - sqliteSetString(pData->pzErrMsg, "malformed database schema", (char*)0); +static void corruptSchema(InitData *pData, const char *zExtra){ + sqliteSetString(pData->pzErrMsg, "malformed database schema", + zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0); } /* @@ -54,36 +55,39 @@ static void corruptSchema(InitData *pData){ static int sqliteInitCallback(void *pInit, int argc, char **argv, char **azColName){ InitData *pData = (InitData*)pInit; - Parse sParse; int nErr = 0; assert( argc==5 ); if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */ if( argv[0]==0 ){ - corruptSchema(pData); + corruptSchema(pData, 0); return 1; } switch( argv[0][0] ){ case 'v': case 'i': case 't': { /* CREATE TABLE, CREATE INDEX, or CREATE VIEW statements */ + sqlite *db = pData->db; if( argv[2]==0 || argv[4]==0 ){ - corruptSchema(pData); + corruptSchema(pData, 0); return 1; } if( argv[3] && argv[3][0] ){ /* Call the parser to process a CREATE TABLE, INDEX or VIEW. - ** But because sParse.initFlag is set to 1, no VDBE code is generated + ** But because db->init.busy is set to 1, no VDBE code is generated ** or executed. All the parser does is build the internal data ** structures that describe the table, index, or view. */ - memset(&sParse, 0, sizeof(sParse)); - sParse.db = pData->db; - sParse.initFlag = 1; - sParse.iDb = atoi(argv[4]); - sParse.newTnum = atoi(argv[2]); - sParse.useCallback = 1; - sqliteRunParser(&sParse, argv[3], pData->pzErrMsg); + char *zErr; + assert( db->init.busy ); + db->init.iDb = atoi(argv[4]); + assert( db->init.iDb>=0 && db->init.iDb<db->nDb ); + db->init.newTnum = atoi(argv[2]); + if( sqlite_exec(db, argv[3], 0, 0, &zErr) ){ + corruptSchema(pData, zErr); + sqlite_freemem(zErr); + } + db->init.iDb = 0; }else{ /* If the SQL column is blank it means this is an index that ** was created to be the PRIMARY KEY or to fulfill a UNIQUE @@ -95,8 +99,8 @@ int sqliteInitCallback(void *pInit, int argc, char **argv, char **azColName){ Index *pIndex; iDb = atoi(argv[4]); - assert( iDb>=0 && iDb<pData->db->nDb ); - pIndex = sqliteFindIndex(pData->db, argv[1], pData->db->aDb[iDb].zName); + assert( iDb>=0 && iDb<db->nDb ); + pIndex = sqliteFindIndex(db, argv[1], db->aDb[iDb].zName); if( pIndex==0 || pIndex->tnum!=0 ){ /* This can occur if there exists an index on a TEMP table which ** has the same name as another index on a permanent index. Since @@ -127,6 +131,9 @@ int sqliteInitCallback(void *pInit, int argc, char **argv, char **azColName){ ** format version 1 or 2 to version 3. The correct operation of ** this routine relys on the fact that no indices are used when ** copying a table out to a temporary file. +** +** The change from version 2 to version 3 occurred between SQLite +** version 2.5.6 and 2.6.0 on 2002-July-18. */ static int upgrade_3_callback(void *pInit, int argc, char **argv, char **NotUsed){ @@ -150,8 +157,8 @@ int upgrade_3_callback(void *pInit, int argc, char **argv, char **NotUsed){ "DROP TABLE sqlite_x;", 0, 0, &zErr, argv[0], argv[0], argv[0]); if( zErr ){ - sqliteSetString(pData->pzErrMsg, zErr, (char*)0); - sqlite_freemem(zErr); + if( *pData->pzErrMsg ) sqlite_freemem(*pData->pzErrMsg); + *pData->pzErrMsg = zErr; } /* If an error occurred in the SQL above, then the transaction will @@ -185,7 +192,6 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ char *azArg[6]; char zDbNum[30]; int meta[SQLITE_N_BTREE_META]; - Parse sParse; InitData initData; /* @@ -242,6 +248,7 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ /* Construct the schema tables: sqlite_master and sqlite_temp_master */ + sqliteSafetyOff(db); azArg[0] = "table"; azArg[1] = MASTER_NAME; azArg[2] = "2"; @@ -266,6 +273,7 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ pTab->readOnly = 1; } } + sqliteSafetyOn(db); /* Create a cursor to hold the database open */ @@ -292,6 +300,9 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ if( size==0 ){ size = MAX_PAGES; } db->cache_size = size; db->safety_level = meta[4]; + if( meta[6]>0 && meta[6]<=2 && db->temp_store==0 ){ + db->temp_store = meta[6]; + } if( db->safety_level==0 ) db->safety_level = 2; /* @@ -327,31 +338,28 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ /* Read the schema information out of the schema tables */ - memset(&sParse, 0, sizeof(sParse)); - sParse.db = db; - sParse.xCallback = sqliteInitCallback; - sParse.pArg = (void*)&initData; - sParse.initFlag = 1; - sParse.useCallback = 1; + assert( db->init.busy ); + sqliteSafetyOff(db); if( iDb==0 ){ - sqliteRunParser(&sParse, + rc = sqlite_exec(db, db->file_format>=2 ? init_script : older_init_script, - pzErrMsg); + sqliteInitCallback, &initData, 0); }else{ char *zSql = 0; sqliteSetString(&zSql, "SELECT type, name, rootpage, sql, ", zDbNum, " FROM \"", db->aDb[iDb].zName, "\".sqlite_master", (char*)0); - sqliteRunParser(&sParse, zSql, pzErrMsg); + rc = sqlite_exec(db, zSql, sqliteInitCallback, &initData, 0); sqliteFree(zSql); } + sqliteSafetyOn(db); sqliteBtreeCloseCursor(curMain); if( sqlite_malloc_failed ){ sqliteSetString(pzErrMsg, "out of memory", (char*)0); - sParse.rc = SQLITE_NOMEM; + rc = SQLITE_NOMEM; sqliteResetInternalSchema(db, 0); } - if( sParse.rc==SQLITE_OK ){ + if( rc==SQLITE_OK ){ DbSetProperty(db, iDb, DB_SchemaLoaded); if( iDb==0 ){ DbSetProperty(db, 1, DB_SchemaLoaded); @@ -359,7 +367,7 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ }else{ sqliteResetInternalSchema(db, iDb); } - return sParse.rc; + return rc; } /* @@ -378,17 +386,58 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){ int sqliteInit(sqlite *db, char **pzErrMsg){ int i, rc; + if( db->init.busy ) return SQLITE_OK; assert( (db->flags & SQLITE_Initialized)==0 ); rc = SQLITE_OK; + db->init.busy = 1; for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ if( DbHasProperty(db, i, DB_SchemaLoaded) ) continue; assert( i!=1 ); /* Should have been initialized together with 0 */ rc = sqliteInitOne(db, i, pzErrMsg); + if( rc ){ + sqliteResetInternalSchema(db, i); + } } + db->init.busy = 0; if( rc==SQLITE_OK ){ db->flags |= SQLITE_Initialized; sqliteCommitInternalChanges(db); - }else{ + } + + /* If the database is in formats 1 or 2, then upgrade it to + ** version 3. This will reconstruct all indices. If the + ** upgrade fails for any reason (ex: out of disk space, database + ** is read only, interrupt received, etc.) then fail the init. + */ + if( rc==SQLITE_OK && db->file_format<3 ){ + char *zErr = 0; + InitData initData; + int meta[SQLITE_N_BTREE_META]; + + db->magic = SQLITE_MAGIC_OPEN; + initData.db = db; + initData.pzErrMsg = &zErr; + db->file_format = 3; + rc = sqlite_exec(db, + "BEGIN; SELECT name FROM sqlite_master WHERE type='table';", + upgrade_3_callback, + &initData, + &zErr); + if( rc==SQLITE_OK ){ + sqliteBtreeGetMeta(db->aDb[0].pBt, meta); + meta[2] = 4; + sqliteBtreeUpdateMeta(db->aDb[0].pBt, meta); + sqlite_exec(db, "COMMIT", 0, 0, 0); + } + if( rc!=SQLITE_OK ){ + sqliteSetString(pzErrMsg, + "unable to upgrade database to the version 2.6 format", + zErr ? ": " : 0, zErr, (char*)0); + } + sqlite_freemem(zErr); + } + + if( rc!=SQLITE_OK ){ db->flags &= ~SQLITE_Initialized; } return rc; @@ -432,6 +481,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){ db->magic = SQLITE_MAGIC_BUSY; db->nDb = 2; db->aDb = db->aDbStatic; + /* db->flags |= SQLITE_ShortColNames; */ sqliteHashInit(&db->aFunc, SQLITE_HASH_STRING, 1); for(i=0; i<db->nDb; i++){ sqliteHashInit(&db->aDb[i].tblHash, SQLITE_HASH_STRING, 0); @@ -475,42 +525,6 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){ *pzErrMsg = 0; } - /* If the database is in formats 1 or 2, then upgrade it to - ** version 3. This will reconstruct all indices. If the - ** upgrade fails for any reason (ex: out of disk space, database - ** is read only, interrupt received, etc.) then refuse to open. - */ - if( rc==SQLITE_OK && db->file_format<3 ){ - char *zErr = 0; - InitData initData; - int meta[SQLITE_N_BTREE_META]; - - initData.db = db; - initData.pzErrMsg = &zErr; - db->file_format = 3; - rc = sqlite_exec(db, - "BEGIN; SELECT name FROM sqlite_master WHERE type='table';", - upgrade_3_callback, - &initData, - &zErr); - if( rc==SQLITE_OK ){ - sqliteBtreeGetMeta(db->aDb[0].pBt, meta); - meta[2] = 4; - sqliteBtreeUpdateMeta(db->aDb[0].pBt, meta); - sqlite_exec(db, "COMMIT", 0, 0, 0); - } - if( rc!=SQLITE_OK ){ - sqliteSetString(pzErrMsg, - "unable to upgrade database to the version 2.6 format", - zErr ? ": " : 0, zErr, (char*)0); - sqlite_freemem(zErr); - sqliteStrRealloc(pzErrMsg); - sqlite_close(db); - return 0; - } - sqlite_freemem(zErr); - } - /* Return a pointer to the newly opened database structure */ return db; @@ -535,6 +549,16 @@ int sqlite_changes(sqlite *db){ } /* +** Return the number of changes produced by the last INSERT, UPDATE, or +** DELETE statement to complete execution. The count does not include +** changes due to SQL statements executed in trigger programs that were +** triggered by that statement +*/ +int sqlite_last_statement_changes(sqlite *db){ + return db->lsChange; +} + +/* ** Close an existing SQLite database */ void sqlite_close(sqlite *db){ @@ -547,13 +571,10 @@ void sqlite_close(sqlite *db){ } db->magic = SQLITE_MAGIC_CLOSED; for(j=0; j<db->nDb; j++){ - if( db->aDb[j].pBt ){ - sqliteBtreeClose(db->aDb[j].pBt); - db->aDb[j].pBt = 0; - } - if( j>=2 ){ - sqliteFree(db->aDb[j].zName); - db->aDb[j].zName = 0; + struct Db *pDb = &db->aDb[j]; + if( pDb->pBt ){ + sqliteBtreeClose(pDb->pBt); + pDb->pBt = 0; } } sqliteResetInternalSchema(db, 0); @@ -581,19 +602,91 @@ void sqliteRollbackAll(sqlite *db){ db->aDb[i].inTrans = 0; } } - sqliteRollbackInternalChanges(db); + sqliteResetInternalSchema(db, 0); + /* sqliteRollbackInternalChanges(db); */ } /* -** This routine does the work of either sqlite_exec() or sqlite_compile(). -** It works like sqlite_exec() if pVm==NULL and it works like sqlite_compile() -** otherwise. +** Execute SQL code. Return one of the SQLITE_ success/failure +** codes. Also write an error message into memory obtained from +** malloc() and make *pzErrMsg point to that message. +** +** If the SQL is a query, then for each row in the query result +** the xCallback() function is called. pArg becomes the first +** argument to xCallback(). If xCallback=NULL then no callback +** is invoked, even for queries. */ -static int sqliteMain( +int sqlite_exec( sqlite *db, /* The database on which the SQL executes */ const char *zSql, /* The SQL to be executed */ sqlite_callback xCallback, /* Invoke this callback routine */ void *pArg, /* First argument to xCallback() */ + char **pzErrMsg /* Write error messages here */ +){ + int rc = SQLITE_OK; + const char *zLeftover; + sqlite_vm *pVm; + int nRetry = 0; + int nChange = 0; + int nCallback; + + if( zSql==0 ) return SQLITE_OK; + while( rc==SQLITE_OK && zSql[0] ){ + pVm = 0; + rc = sqlite_compile(db, zSql, &zLeftover, &pVm, pzErrMsg); + if( rc!=SQLITE_OK ){ + assert( pVm==0 || sqlite_malloc_failed ); + return rc; + } + if( pVm==0 ){ + /* This happens if the zSql input contained only whitespace */ + break; + } + db->nChange += nChange; + nCallback = 0; + while(1){ + int nArg; + char **azArg, **azCol; + rc = sqlite_step(pVm, &nArg, (const char***)&azArg,(const char***)&azCol); + if( rc==SQLITE_ROW ){ + if( xCallback!=0 && xCallback(pArg, nArg, azArg, azCol) ){ + sqlite_finalize(pVm, 0); + return SQLITE_ABORT; + } + nCallback++; + }else{ + if( rc==SQLITE_DONE && nCallback==0 + && (db->flags & SQLITE_NullCallback)!=0 && xCallback!=0 ){ + xCallback(pArg, nArg, azArg, azCol); + } + rc = sqlite_finalize(pVm, pzErrMsg); + if( rc==SQLITE_SCHEMA && nRetry<2 ){ + nRetry++; + rc = SQLITE_OK; + break; + } + if( db->pVdbe==0 ){ + nChange = db->nChange; + } + nRetry = 0; + zSql = zLeftover; + while( isspace(zSql[0]) ) zSql++; + break; + } + } + } + return rc; +} + + +/* +** Compile a single statement of SQL into a virtual machine. Return one +** of the SQLITE_ success/failure codes. Also write an error message into +** memory obtained from malloc() and make *pzErrMsg point to that message. +*/ +int sqlite_compile( + sqlite *db, /* The database on which the SQL executes */ + const char *zSql, /* The SQL to be executed */ const char **pzTail, /* OUT: Next statement after the first */ sqlite_vm **ppVm, /* OUT: The virtual machine */ char **pzErrMsg /* OUT: Write error messages here */ @@ -602,33 +695,56 @@ static int sqliteMain( if( pzErrMsg ) *pzErrMsg = 0; if( sqliteSafetyOn(db) ) goto exec_misuse; - if( (db->flags & SQLITE_Initialized)==0 ){ - int rc, cnt = 1; - while( (rc = sqliteInit(db, pzErrMsg))==SQLITE_BUSY - && db->xBusyCallback && db->xBusyCallback(db->pBusyArg, "", cnt++)!=0 ){} - if( rc!=SQLITE_OK ){ - sqliteStrRealloc(pzErrMsg); - sqliteSafetyOff(db); - return rc; + if( !db->init.busy ){ + if( (db->flags & SQLITE_Initialized)==0 ){ + int rc, cnt = 1; + while( (rc = sqliteInit(db, pzErrMsg))==SQLITE_BUSY + && db->xBusyCallback + && db->xBusyCallback(db->pBusyArg, "", cnt++)!=0 ){} + if( rc!=SQLITE_OK ){ + sqliteStrRealloc(pzErrMsg); + sqliteSafetyOff(db); + return rc; + } + if( pzErrMsg ){ + sqliteFree(*pzErrMsg); + *pzErrMsg = 0; + } } - if( pzErrMsg ){ - sqliteFree(*pzErrMsg); - *pzErrMsg = 0; + if( db->file_format<3 ){ + sqliteSafetyOff(db); + sqliteSetString(pzErrMsg, "obsolete database file format", (char*)0); + return SQLITE_ERROR; } } - if( db->file_format<3 ){ - sqliteSafetyOff(db); - sqliteSetString(pzErrMsg, "obsolete database file format", (char*)0); - return SQLITE_ERROR; - } + assert( (db->flags & SQLITE_Initialized)!=0 || db->init.busy ); if( db->pVdbe==0 ){ db->nChange = 0; } memset(&sParse, 0, sizeof(sParse)); sParse.db = db; - sParse.xCallback = xCallback; - sParse.pArg = pArg; - sParse.useCallback = ppVm==0; - if( db->xTrace ) db->xTrace(db->pTraceArg, zSql); sqliteRunParser(&sParse, zSql, pzErrMsg); + if( db->xTrace && !db->init.busy ){ + /* Trace only the statment that was compiled. + ** Make a copy of that part of the SQL string since zSQL is const + ** and we must pass a zero terminated string to the trace function + ** The copy is unnecessary if the tail pointer is pointing at the + ** beginnig or end of the SQL string. + */ + if( sParse.zTail && sParse.zTail!=zSql && *sParse.zTail ){ + char *tmpSql = sqliteStrNDup(zSql, sParse.zTail - zSql); + if( tmpSql ){ + db->xTrace(db->pTraceArg, tmpSql); + free(tmpSql); + }else{ + /* If a memory error occurred during the copy, + ** trace entire SQL string and fall through to the + ** sqlite_malloc_failed test to report the error. + */ + db->xTrace(db->pTraceArg, zSql); + } + }else{ + db->xTrace(db->pTraceArg, zSql); + } + } if( sqlite_malloc_failed ){ sqliteSetString(pzErrMsg, "out of memory", (char*)0); sParse.rc = SQLITE_NOMEM; @@ -644,11 +760,9 @@ static int sqliteMain( if( sParse.rc==SQLITE_SCHEMA ){ sqliteResetInternalSchema(db, 0); } - if( sParse.useCallback==0 ){ - assert( ppVm ); - *ppVm = (sqlite_vm*)sParse.pVdbe; - if( pzTail ) *pzTail = sParse.zTail; - } + assert( ppVm ); + *ppVm = (sqlite_vm*)sParse.pVdbe; + if( pzTail ) *pzTail = sParse.zTail; if( sqliteSafetyOff(db) ) goto exec_misuse; return sParse.rc; @@ -661,41 +775,6 @@ exec_misuse: return SQLITE_MISUSE; } -/* -** Execute SQL code. Return one of the SQLITE_ success/failure -** codes. Also write an error message into memory obtained from -** malloc() and make *pzErrMsg point to that message. -** -** If the SQL is a query, then for each row in the query result -** the xCallback() function is called. pArg becomes the first -** argument to xCallback(). If xCallback=NULL then no callback -** is invoked, even for queries. -*/ -int sqlite_exec( - sqlite *db, /* The database on which the SQL executes */ - const char *zSql, /* The SQL to be executed */ - sqlite_callback xCallback, /* Invoke this callback routine */ - void *pArg, /* First argument to xCallback() */ - char **pzErrMsg /* Write error messages here */ -){ - return sqliteMain(db, zSql, xCallback, pArg, 0, 0, pzErrMsg); -} - -/* -** Compile a single statement of SQL into a virtual machine. Return one -** of the SQLITE_ success/failure codes. Also write an error message into -** memory obtained from malloc() and make *pzErrMsg point to that message. -*/ -int sqlite_compile( - sqlite *db, /* The database on which the SQL executes */ - const char *zSql, /* The SQL to be executed */ - const char **pzTail, /* OUT: Next statement after the first */ - sqlite_vm **ppVm, /* OUT: The virtual machine */ - char **pzErrMsg /* OUT: Write error messages here */ -){ - return sqliteMain(db, zSql, 0, 0, pzTail, ppVm, pzErrMsg); -} - /* ** The following routine destroys a virtual machine that is created by @@ -729,7 +808,7 @@ int sqlite_reset( char **pzErrMsg /* OUT: Write error messages here */ ){ int rc = sqliteVdbeReset((Vdbe*)pVm, pzErrMsg); - sqliteVdbeMakeReady((Vdbe*)pVm, -1, 0, 0, 0); + sqliteVdbeMakeReady((Vdbe*)pVm, -1, 0); sqliteStrRealloc(pzErrMsg); return rc; } @@ -767,6 +846,7 @@ const char *sqlite_error_string(int rc){ case SQLITE_AUTH: z = "authorization denied"; break; case SQLITE_FORMAT: z = "auxiliary database format error"; break; case SQLITE_RANGE: z = "bind index out of range"; break; + case SQLITE_NOTADB: z = "file is encrypted or is not a database";break; default: z = "unknown error"; break; } return z; @@ -784,22 +864,23 @@ static int sqliteDefaultBusyCallback( int count /* Number of times table has been busy */ ){ #if SQLITE_MIN_SLEEP_MS==1 - int delay = 10; - int prior_delay = 0; + static const char delays[] = + { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 50, 100}; + static const short int totals[] = + { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228, 287}; +# define NDELAY (sizeof(delays)/sizeof(delays[0])) int timeout = (int)(long)Timeout; - int i; + int delay, prior; - for(i=1; i<count; i++){ - prior_delay += delay; - delay = delay*2; - if( delay>=1000 ){ - delay = 1000; - prior_delay += 1000*(count - i - 1); - break; - } + if( count <= NDELAY ){ + delay = delays[count-1]; + prior = totals[count-1]; + }else{ + delay = delays[NDELAY-1]; + prior = totals[NDELAY-1] + delay*(count-NDELAY-1); } - if( prior_delay + delay > timeout ){ - delay = timeout - prior_delay; + if( prior + delay > timeout ){ + delay = timeout - prior; if( delay<=0 ) return 0; } sqliteOsSleep(delay); @@ -858,7 +939,7 @@ void sqlite_progress_handler( */ void sqlite_busy_timeout(sqlite *db, int ms){ if( ms>0 ){ - sqlite_busy_handler(db, sqliteDefaultBusyCallback, (void*)ms); + sqlite_busy_handler(db, sqliteDefaultBusyCallback, (void*)(long)ms); }else{ sqlite_busy_handler(db, 0, 0); } @@ -903,7 +984,7 @@ const char *sqlite_libencoding(void){ return sqlite_encoding; } ** sqlite_create_aggregate(), and vice versa. ** ** If nArg is -1 it means that this function will accept any number -** of arguments, including 0. +** of arguments, including 0. The maximum allowed value of nArg is 127. */ int sqlite_create_function( sqlite *db, /* Add the function to this database connection */ @@ -915,6 +996,7 @@ int sqlite_create_function( FuncDef *p; int nName; if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1; + if( nArg<-1 || nArg>127 ) return 1; nName = strlen(zName); if( nName>255 ) return 1; p = sqliteFindFunction(db, zName, nName, nArg, 1); @@ -936,6 +1018,7 @@ int sqlite_create_aggregate( FuncDef *p; int nName; if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1; + if( nArg<-1 || nArg>127 ) return 1; nName = strlen(zName); if( nName>255 ) return 1; p = sqliteFindFunction(db, zName, nName, nArg, 1); @@ -976,6 +1059,24 @@ void *sqlite_trace(sqlite *db, void (*xTrace)(void*,const char*), void *pArg){ return pOld; } +/*** EXPERIMENTAL *** +** +** Register a function to be invoked when a transaction comments. +** If either function returns non-zero, then the commit becomes a +** rollback. +*/ +void *sqlite_commit_hook( + sqlite *db, /* Attach the hook to this database */ + int (*xCallback)(void*), /* Function to invoke on each commit */ + void *pArg /* Argument to the function */ +){ + void *pOld = db->pCommitArg; + db->xCommitCallback = xCallback; + db->pCommitArg = pArg; + return pOld; +} + + /* ** This routine is called to create a connection to a database BTree ** driver. If zFilename is the name of a file, then that file is diff --git a/ext/sqlite/libsqlite/src/opcodes.c b/ext/sqlite/libsqlite/src/opcodes.c index 59061b7c0a..0907e0e797 100644 --- a/ext/sqlite/libsqlite/src/opcodes.c +++ b/ext/sqlite/libsqlite/src/opcodes.c @@ -13,7 +13,6 @@ char *sqliteOpcodeNames[] = { "???", "Push", "ColumnName", "Callback", - "NullCallback", "Concat", "Add", "Subtract", @@ -26,7 +25,7 @@ char *sqliteOpcodeNames[] = { "???", "ShiftLeft", "ShiftRight", "AddImm", - "IsNumeric", + "ForceInt", "MustBeInt", "Eq", "Ne", @@ -78,6 +77,7 @@ char *sqliteOpcodeNames[] = { "???", "PutIntKey", "PutStrKey", "Delete", + "SetCounts", "KeyAsData", "RowKey", "RowData", @@ -107,6 +107,8 @@ char *sqliteOpcodeNames[] = { "???", "ListReset", "ListPush", "ListPop", + "ContextPush", + "ContextPop", "SortPut", "SortMakeRec", "SortMakeKey", @@ -133,4 +135,6 @@ char *sqliteOpcodeNames[] = { "???", "SetFirst", "SetNext", "Vacuum", + "StackDepth", + "StackReset", }; diff --git a/ext/sqlite/libsqlite/src/opcodes.h b/ext/sqlite/libsqlite/src/opcodes.h index ac274022d1..35e050697f 100644 --- a/ext/sqlite/libsqlite/src/opcodes.h +++ b/ext/sqlite/libsqlite/src/opcodes.h @@ -12,71 +12,71 @@ #define OP_Push 11 #define OP_ColumnName 12 #define OP_Callback 13 -#define OP_NullCallback 14 -#define OP_Concat 15 -#define OP_Add 16 -#define OP_Subtract 17 -#define OP_Multiply 18 -#define OP_Divide 19 -#define OP_Remainder 20 -#define OP_Function 21 -#define OP_BitAnd 22 -#define OP_BitOr 23 -#define OP_ShiftLeft 24 -#define OP_ShiftRight 25 -#define OP_AddImm 26 -#define OP_IsNumeric 27 -#define OP_MustBeInt 28 -#define OP_Eq 29 -#define OP_Ne 30 -#define OP_Lt 31 -#define OP_Le 32 -#define OP_Gt 33 -#define OP_Ge 34 -#define OP_StrEq 35 -#define OP_StrNe 36 -#define OP_StrLt 37 -#define OP_StrLe 38 -#define OP_StrGt 39 -#define OP_StrGe 40 -#define OP_And 41 -#define OP_Or 42 -#define OP_Negative 43 -#define OP_AbsValue 44 -#define OP_Not 45 -#define OP_BitNot 46 -#define OP_Noop 47 -#define OP_If 48 -#define OP_IfNot 49 -#define OP_IsNull 50 -#define OP_NotNull 51 -#define OP_MakeRecord 52 -#define OP_MakeIdxKey 53 -#define OP_MakeKey 54 -#define OP_IncrKey 55 -#define OP_Checkpoint 56 -#define OP_Transaction 57 -#define OP_Commit 58 -#define OP_Rollback 59 -#define OP_ReadCookie 60 -#define OP_SetCookie 61 -#define OP_VerifyCookie 62 -#define OP_OpenRead 63 -#define OP_OpenWrite 64 -#define OP_OpenTemp 65 -#define OP_OpenPseudo 66 -#define OP_Close 67 -#define OP_MoveLt 68 -#define OP_MoveTo 69 -#define OP_Distinct 70 -#define OP_NotFound 71 -#define OP_Found 72 -#define OP_IsUnique 73 -#define OP_NotExists 74 -#define OP_NewRecno 75 -#define OP_PutIntKey 76 -#define OP_PutStrKey 77 -#define OP_Delete 78 +#define OP_Concat 14 +#define OP_Add 15 +#define OP_Subtract 16 +#define OP_Multiply 17 +#define OP_Divide 18 +#define OP_Remainder 19 +#define OP_Function 20 +#define OP_BitAnd 21 +#define OP_BitOr 22 +#define OP_ShiftLeft 23 +#define OP_ShiftRight 24 +#define OP_AddImm 25 +#define OP_ForceInt 26 +#define OP_MustBeInt 27 +#define OP_Eq 28 +#define OP_Ne 29 +#define OP_Lt 30 +#define OP_Le 31 +#define OP_Gt 32 +#define OP_Ge 33 +#define OP_StrEq 34 +#define OP_StrNe 35 +#define OP_StrLt 36 +#define OP_StrLe 37 +#define OP_StrGt 38 +#define OP_StrGe 39 +#define OP_And 40 +#define OP_Or 41 +#define OP_Negative 42 +#define OP_AbsValue 43 +#define OP_Not 44 +#define OP_BitNot 45 +#define OP_Noop 46 +#define OP_If 47 +#define OP_IfNot 48 +#define OP_IsNull 49 +#define OP_NotNull 50 +#define OP_MakeRecord 51 +#define OP_MakeIdxKey 52 +#define OP_MakeKey 53 +#define OP_IncrKey 54 +#define OP_Checkpoint 55 +#define OP_Transaction 56 +#define OP_Commit 57 +#define OP_Rollback 58 +#define OP_ReadCookie 59 +#define OP_SetCookie 60 +#define OP_VerifyCookie 61 +#define OP_OpenRead 62 +#define OP_OpenWrite 63 +#define OP_OpenTemp 64 +#define OP_OpenPseudo 65 +#define OP_Close 66 +#define OP_MoveLt 67 +#define OP_MoveTo 68 +#define OP_Distinct 69 +#define OP_NotFound 70 +#define OP_Found 71 +#define OP_IsUnique 72 +#define OP_NotExists 73 +#define OP_NewRecno 74 +#define OP_PutIntKey 75 +#define OP_PutStrKey 76 +#define OP_Delete 77 +#define OP_SetCounts 78 #define OP_KeyAsData 79 #define OP_RowKey 80 #define OP_RowData 81 @@ -106,29 +106,33 @@ #define OP_ListReset 105 #define OP_ListPush 106 #define OP_ListPop 107 -#define OP_SortPut 108 -#define OP_SortMakeRec 109 -#define OP_SortMakeKey 110 -#define OP_Sort 111 -#define OP_SortNext 112 -#define OP_SortCallback 113 -#define OP_SortReset 114 -#define OP_FileOpen 115 -#define OP_FileRead 116 -#define OP_FileColumn 117 -#define OP_MemStore 118 -#define OP_MemLoad 119 -#define OP_MemIncr 120 -#define OP_AggReset 121 -#define OP_AggInit 122 -#define OP_AggFunc 123 -#define OP_AggFocus 124 -#define OP_AggSet 125 -#define OP_AggGet 126 -#define OP_AggNext 127 -#define OP_SetInsert 128 -#define OP_SetFound 129 -#define OP_SetNotFound 130 -#define OP_SetFirst 131 -#define OP_SetNext 132 -#define OP_Vacuum 133 +#define OP_ContextPush 108 +#define OP_ContextPop 109 +#define OP_SortPut 110 +#define OP_SortMakeRec 111 +#define OP_SortMakeKey 112 +#define OP_Sort 113 +#define OP_SortNext 114 +#define OP_SortCallback 115 +#define OP_SortReset 116 +#define OP_FileOpen 117 +#define OP_FileRead 118 +#define OP_FileColumn 119 +#define OP_MemStore 120 +#define OP_MemLoad 121 +#define OP_MemIncr 122 +#define OP_AggReset 123 +#define OP_AggInit 124 +#define OP_AggFunc 125 +#define OP_AggFocus 126 +#define OP_AggSet 127 +#define OP_AggGet 128 +#define OP_AggNext 129 +#define OP_SetInsert 130 +#define OP_SetFound 131 +#define OP_SetNotFound 132 +#define OP_SetFirst 133 +#define OP_SetNext 134 +#define OP_Vacuum 135 +#define OP_StackDepth 136 +#define OP_StackReset 137 diff --git a/ext/sqlite/libsqlite/src/os.c b/ext/sqlite/libsqlite/src/os.c index 12761bb2a3..0e2930c0ca 100644 --- a/ext/sqlite/libsqlite/src/os.c +++ b/ext/sqlite/libsqlite/src/os.c @@ -34,9 +34,6 @@ # ifndef O_BINARY # define O_BINARY 0 # endif -# ifndef EISDIR -# define EISDIR 21 -# endif #endif @@ -467,9 +464,11 @@ int sqliteOsOpenReadWrite( id->dirfd = -1; id->fd = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, 0644); if( id->fd<0 ){ - if (errno == EISDIR) { +#ifdef EISDIR + if( errno==EISDIR ){ return SQLITE_CANTOPEN; } +#endif id->fd = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY); if( id->fd<0 ){ return SQLITE_CANTOPEN; @@ -780,25 +779,35 @@ int sqliteOsOpenDirectory( } /* +** If the following global variable points to a string which is the +** name of a directory, then that directory will be used to store +** temporary files. +*/ +const char *sqlite_temp_directory = 0; + +/* ** Create a temporary file name in zBuf. zBuf must be big enough to ** hold at least SQLITE_TEMPNAME_SIZE characters. */ int sqliteOsTempFileName(char *zBuf){ #if OS_UNIX static const char *azDirs[] = { + 0, "/var/tmp", "/usr/tmp", "/tmp", ".", }; - static char zChars[] = + static unsigned char zChars[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; struct stat buf; const char *zDir = "."; + azDirs[0] = sqlite_temp_directory; for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){ + if( azDirs[i]==0 ) continue; if( stat(azDirs[i], &buf) ) continue; if( !S_ISDIR(buf.st_mode) ) continue; if( access(azDirs[i], 07) ) continue; @@ -808,9 +817,9 @@ int sqliteOsTempFileName(char *zBuf){ do{ sprintf(zBuf, "%s/"TEMP_FILE_PREFIX, zDir); j = strlen(zBuf); - for(i=0; i<15; i++){ - int n = sqliteRandomByte() % (sizeof(zChars)-1); - zBuf[j++] = zChars[n]; + sqliteRandomness(15, &zBuf[j]); + for(i=0; i<15; i++, j++){ + zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; }while( access(zBuf,0)==0 ); @@ -821,16 +830,22 @@ int sqliteOsTempFileName(char *zBuf){ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; + char *zDir; char zTempPath[SQLITE_TEMPNAME_SIZE]; - GetTempPath(SQLITE_TEMPNAME_SIZE-30, zTempPath); - for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} - zTempPath[i] = 0; + if( sqlite_temp_directory==0 ){ + GetTempPath(SQLITE_TEMPNAME_SIZE-30, zTempPath); + for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} + zTempPath[i] = 0; + zDir = zTempPath; + }else{ + zDir = sqlite_temp_directory; + } for(;;){ - sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath); + sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zDir); j = strlen(zBuf); - for(i=0; i<15; i++){ - int n = sqliteRandomByte() % (sizeof(zChars) - 1); - zBuf[j++] = zChars[n]; + sqliteRandomness(15, &zBuf[j]); + for(i=0; i<15; i++, j++){ + zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; if( !sqliteOsFileExists(zBuf) ) break; @@ -842,13 +857,16 @@ int sqliteOsTempFileName(char *zBuf){ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; + char *zDir; char zTempPath[SQLITE_TEMPNAME_SIZE]; char zdirName[32]; CInfoPBRec infoRec; Str31 dirName; memset(&infoRec, 0, sizeof(infoRec)); memset(zTempPath, 0, SQLITE_TEMPNAME_SIZE); - if( FindFolder(kOnSystemDisk, kTemporaryFolderType, kCreateFolder, + if( sqlite_temp_directory!=0 ){ + zDir = sqlite_temp_directory; + }else if( FindFolder(kOnSystemDisk, kTemporaryFolderType, kCreateFolder, &(infoRec.dirInfo.ioVRefNum), &(infoRec.dirInfo.ioDrParID)) == noErr ){ infoRec.dirInfo.ioNamePtr = dirName; do{ @@ -865,15 +883,18 @@ int sqliteOsTempFileName(char *zBuf){ break; } } while( infoRec.dirInfo.ioDrDirID != fsRtDirID ); + zDir = zTempPath; } - if( *zTempPath == 0 ) + if( zDir[0]==0 ){ getcwd(zTempPath, SQLITE_TEMPNAME_SIZE-24); + zDir = zTempPath; + } for(;;){ - sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zTempPath); + sprintf(zBuf, "%s"TEMP_FILE_PREFIX, zDir); j = strlen(zBuf); - for(i=0; i<15; i++){ - int n = sqliteRandomByte() % sizeof(zChars); - zBuf[j++] = zChars[n]; + sqliteRandomness(15, &zBuf[j]); + for(i=0; i<15; i++, j++){ + zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; } zBuf[j] = 0; if( !sqliteOsFileExists(zBuf) ) break; @@ -1220,7 +1241,7 @@ int sqliteOsFileSize(OsFile *id, off_t *pSize){ ** the LockFileEx() API. */ int isNT(void){ - static osType = 0; /* 0=unknown 1=win95 2=winNT */ + static int osType = 0; /* 0=unknown 1=win95 2=winNT */ if( osType==0 ){ OSVERSIONINFO sInfo; sInfo.dwOSVersionInfoSize = sizeof(sInfo); @@ -1331,9 +1352,11 @@ int sqliteOsReadLock(OsFile *id){ if( id->locked>0 ){ rc = SQLITE_OK; }else{ - int lk = (sqliteRandomInteger() & 0x7ffffff)%N_LOCKBYTE+1; + int lk; int res; int cnt = 100; + sqliteRandomness(sizeof(lk), &lk); + lk = (lk & 0x7fffffff)%N_LOCKBYTE + 1; while( cnt-->0 && (res = LockFile(id->h, FIRST_LOCKBYTE, 0, 1, 0))==0 ){ Sleep(1); } @@ -1365,10 +1388,12 @@ int sqliteOsReadLock(OsFile *id){ if( id->locked>0 || id->refNumRF == -1 ){ rc = SQLITE_OK; }else{ - int lk = (sqliteRandomInteger() & 0x7ffffff)%N_LOCKBYTE+1; + int lk; OSErr res; int cnt = 5; ParamBlockRec params; + sqliteRandomness(sizeof(lk), &lk); + lk = (lk & 0x7fffffff)%N_LOCKBYTE + 1; memset(¶ms, 0, sizeof(params)); params.ioParam.ioRefNum = id->refNumRF; params.ioParam.ioPosMode = fsFromStart; @@ -1783,7 +1808,7 @@ char *sqliteOsFullPathname(const char *zRelative){ } /* -** The following variable, if set to a now-zero value, become the result +** The following variable, if set to a non-zero value, becomes the result ** returned from sqliteOsCurrentTime(). This is used for testing. */ #ifdef SQLITE_TEST diff --git a/ext/sqlite/libsqlite/src/os.h b/ext/sqlite/libsqlite/src/os.h index 681f831b66..d1395841d2 100644 --- a/ext/sqlite/libsqlite/src/os.h +++ b/ext/sqlite/libsqlite/src/os.h @@ -39,7 +39,9 @@ */ #ifndef SQLITE_DISABLE_LFS # define _LARGE_FILE 1 -# define _FILE_OFFSET_BITS 64 +# ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +# endif # define _LARGEFILE_SOURCE 1 #endif @@ -118,9 +120,6 @@ #endif #if OS_WIN -# if defined(__CYGWIN__) -# define __CYGWIN_USE_BIG_TYPES__ -# endif #include <windows.h> #include <winbase.h> typedef struct OsFile OsFile; diff --git a/ext/sqlite/libsqlite/src/pager.c b/ext/sqlite/libsqlite/src/pager.c index f593862104..23d3fb8009 100644 --- a/ext/sqlite/libsqlite/src/pager.c +++ b/ext/sqlite/libsqlite/src/pager.c @@ -84,6 +84,19 @@ static Pager *mainPager = 0; ** Each in-memory image of a page begins with the following header. ** This header is only visible to this pager module. The client ** code that calls pager sees only the data that follows the header. +** +** Client code should call sqlitepager_write() on a page prior to making +** any modifications to that page. The first time sqlitepager_write() +** is called, the original page contents are written into the rollback +** journal and PgHdr.inJournal and PgHdr.needSync are set. Later, once +** the journal page has made it onto the disk surface, PgHdr.needSync +** is cleared. The modified page cannot be written back into the original +** database file until the journal pages has been synced to disk and the +** PgHdr.needSync has been cleared. +** +** The PgHdr.dirty flag is set when sqlitepager_write() is called and +** is cleared again when the page content is written back to the original +** database file. */ typedef struct PgHdr PgHdr; struct PgHdr { @@ -104,6 +117,16 @@ struct PgHdr { /* Pager.nExtra bytes of local data follow the page data */ }; + +/* +** A macro used for invoking the codec if there is one +*/ +#ifdef SQLITE_HAS_CODEC +# define CODEC(P,D,N,X) if( P->xCodec ){ P->xCodec(P->pCodecArg,D,N,X); } +#else +# define CODEC(P,D,N,X) +#endif + /* ** Convert a pointer to a PgHdr into a pointer to its data ** and back again. @@ -145,9 +168,11 @@ struct Pager { int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */ int mxPage; /* Maximum number of pages to hold in cache */ int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */ + void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ + void *pCodecArg; /* First argument to xCodec() */ u8 journalOpen; /* True if journal file descriptors is valid */ - u8 journalStarted; /* True if initial magic of journal is synced */ - u8 useJournal; /* Do not use a rollback journal on this file */ + u8 journalStarted; /* True if header of journal is synced */ + u8 useJournal; /* Use a rollback journal on this file */ u8 ckptOpen; /* True if the checkpoint journal is open */ u8 ckptInUse; /* True we are in a checkpoint */ u8 ckptAutoopen; /* Open ckpt journal when main journal is opened*/ @@ -188,8 +213,8 @@ struct Pager { */ typedef struct PageRecord PageRecord; struct PageRecord { - Pgno pgno; /* The page number */ - char aData[SQLITE_PAGE_SIZE]; /* Original data for page pgno */ + Pgno pgno; /* The page number */ + char aData[SQLITE_PAGE_SIZE]; /* Original data for page pgno */ }; /* @@ -279,7 +304,13 @@ int journal_format = 3; #endif /* -** Read a 32-bit integer from the given file descriptor +** Read a 32-bit integer from the given file descriptor. Store the integer +** that is read in *pRes. Return SQLITE_OK if everything worked, or an +** error code is something goes wrong. +** +** If the journal format is 2 or 3, read a big-endian integer. If the +** journal format is 1, read an integer in the native byte-order of the +** host machine. */ static int read32bits(int format, OsFile *fd, u32 *pRes){ u32 res; @@ -295,8 +326,13 @@ static int read32bits(int format, OsFile *fd, u32 *pRes){ } /* -** Write a 32-bit integer into the given file descriptor. Writing -** is always done using the new journal format. +** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK +** on success or an error code is something goes wrong. +** +** If the journal format is 2 or 3, write the integer as 4 big-endian +** bytes. If the journal format is 1, write the integer in the native +** byte order. In normal operation, only formats 2 and 3 are used. +** Journal format 1 is only used for testing. */ static int write32bits(OsFile *fd, u32 val){ unsigned char ac[4]; @@ -313,6 +349,9 @@ static int write32bits(OsFile *fd, u32 val){ /* ** Write a 32-bit integer into a page header right before the ** page data. This will overwrite the PgHdr.pDirty pointer. +** +** The integer is big-endian for formats 2 and 3 and native byte order +** for journal format 1. */ static void store32bits(u32 val, PgHdr *p, int offset){ unsigned char *ac; @@ -469,6 +508,10 @@ static int pager_unwritelock(Pager *pPager){ /* ** Compute and return a checksum for the page of data. +** +** This is not a real checksum. It is really just the sum of the +** random initial value and the page number. We considered do a checksum +** of the database, but that was found to be too slow. */ static u32 pager_cksum(Pager *pPager, Pgno pgno, const char *aData){ u32 cksum = pPager->cksumInit + pgno; @@ -529,6 +572,7 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int format){ memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra); pPg->dirty = 0; pPg->needSync = 0; + CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); } return rc; } @@ -537,21 +581,53 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int format){ ** Playback the journal and thus restore the database file to ** the state it was in before we started making changes. ** -** The journal file format is as follows: There is an initial -** file-type string for sanity checking. Then there is a single -** Pgno number which is the number of pages in the database before -** changes were made. The database is truncated to this size. -** Next come zero or more page records where each page record -** consists of a Pgno and SQLITE_PAGE_SIZE bytes of data. See -** the PageRecord structure for details. +** The journal file format is as follows: +** +** * 8 byte prefix. One of the aJournalMagic123 vectors defined +** above. The format of the journal file is determined by which +** of the three prefix vectors is seen. +** * 4 byte big-endian integer which is the number of valid page records +** in the journal. If this value is 0xffffffff, then compute the +** number of page records from the journal size. This field appears +** in format 3 only. +** * 4 byte big-endian integer which is the initial value for the +** sanity checksum. This field appears in format 3 only. +** * 4 byte integer which is the number of pages to truncate the +** database to during a rollback. +** * Zero or more pages instances, each as follows: +** + 4 byte page number. +** + SQLITE_PAGE_SIZE bytes of data. +** + 4 byte checksum (format 3 only) +** +** When we speak of the journal header, we mean the first 4 bullets above. +** Each entry in the journal is an instance of the 5th bullet. Note that +** bullets 2 and 3 only appear in format-3 journals. +** +** Call the value from the second bullet "nRec". nRec is the number of +** valid page entries in the journal. In most cases, you can compute the +** value of nRec from the size of the journal file. But if a power +** failure occurred while the journal was being written, it could be the +** case that the size of the journal file had already been increased but +** the extra entries had not yet made it safely to disk. In such a case, +** the value of nRec computed from the file size would be too large. For +** that reason, we always use the nRec value in the header. +** +** If the nRec value is 0xffffffff it means that nRec should be computed +** from the file size. This value is used when the user selects the +** no-sync option for the journal. A power failure could lead to corruption +** in this case. But for things like temporary table (which will be +** deleted when the power is restored) we don't care. +** +** Journal formats 1 and 2 do not have an nRec value in the header so we +** have to compute nRec from the file size. This has risks (as described +** above) which is why all persistent tables have been changed to use +** format 3. ** ** If the file opened as the journal file is not a well-formed -** journal file (as determined by looking at the magic number -** at the beginning) then this routine returns SQLITE_PROTOCOL. -** If any other errors occur during playback, the database will -** likely be corrupted, so the PAGER_ERR_CORRUPT bit is set in -** pPager->errMask and SQLITE_CORRUPT is returned. If it all -** works, then this routine returns SQLITE_OK. +** journal file then the database will likely already be +** corrupted, so the PAGER_ERR_CORRUPT bit is set in pPager->errMask +** and SQLITE_CORRUPT is returned. If it all works, then this routine +** returns SQLITE_OK. */ static int pager_playback(Pager *pPager, int useJournalSize){ off_t szJ; /* Size of the journal file in bytes */ @@ -571,6 +647,13 @@ static int pager_playback(Pager *pPager, int useJournalSize){ if( rc!=SQLITE_OK ){ goto end_playback; } + + /* If the journal file is too small to contain a complete header, + ** it must mean that the process that created the journal was just + ** beginning to write the journal file when it died. In that case, + ** the database file should have still been completely unchanged. + ** Nothing needs to be rolled back. We can safely ignore this journal. + */ if( szJ < sizeof(aMagic)+sizeof(Pgno) ){ goto end_playback; } @@ -594,6 +677,15 @@ static int pager_playback(Pager *pPager, int useJournalSize){ goto end_playback; } if( format>=JOURNAL_FORMAT_3 ){ + if( szJ < sizeof(aMagic) + 3*sizeof(u32) ){ + /* Ignore the journal if it is too small to contain a complete + ** header. We already did this test once above, but at the prior + ** test, we did not know the journal format and so we had to assume + ** the smallest possible header. Now we know the header is bigger + ** than the minimum so we test again. + */ + goto end_playback; + } rc = read32bits(format, &pPager->jfd, (u32*)&nRec); if( rc ) goto end_playback; rc = read32bits(format, &pPager->jfd, &pPager->cksumInit); @@ -630,7 +722,7 @@ static int pager_playback(Pager *pPager, int useJournalSize){ /* Pages that have been written to the journal but never synced ** where not restored by the loop above. We have to restore those - ** pages by reading the back from the original database. + ** pages by reading them back from the original database. */ if( rc==SQLITE_OK ){ PgHdr *pPg; @@ -640,6 +732,8 @@ static int pager_playback(Pager *pPager, int useJournalSize){ if( (int)pPg->pgno <= pPager->origDbSize ){ sqliteOsSeek(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)(pPg->pgno-1)); rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_PAGE_SIZE); + TRACE2("REFETCH %d\n", pPg->pgno); + CODEC(pPager, zBuf, pPg->pgno, 2); if( rc ) break; }else{ memset(zBuf, 0, SQLITE_PAGE_SIZE); @@ -747,6 +841,7 @@ end_ckpt_playback: void sqlitepager_set_cachesize(Pager *pPager, int mxPage){ if( mxPage>=0 ){ pPager->noSync = pPager->tempFile; + if( pPager->noSync==0 ) pPager->needSync = 0; }else{ pPager->noSync = 1; mxPage = -mxPage; @@ -772,8 +867,9 @@ void sqlitepager_set_cachesize(Pager *pPager, int mxPage){ ** when it is rolled back. ** ** FULL The journal is synced twice before writes begin on the -** database (with some additional information being written -** in between the two syncs. If we assume that writing a +** database (with some additional information - the nRec field +** of the journal header - being written in between the two +** syncs). If we assume that writing a ** single disk sector is atomic, then this mode provides ** assurance that the journal will not be corrupted to the ** point of causing damage to the database during rollback. @@ -784,6 +880,7 @@ void sqlitepager_set_cachesize(Pager *pPager, int mxPage){ void sqlitepager_set_safety_level(Pager *pPager, int level){ pPager->noSync = level==1 || pPager->tempFile; pPager->fullSync = level==3 && !pPager->tempFile; + if( pPager->noSync==0 ) pPager->needSync = 0; } /* @@ -933,7 +1030,7 @@ int sqlitepager_pagecount(Pager *pPager){ /* ** Forward declaration */ -static int syncAllPages(Pager*); +static int syncJournal(Pager*); /* ** Truncate the file to the number of pages specified. @@ -950,7 +1047,7 @@ int sqlitepager_truncate(Pager *pPager, Pgno nPage){ if( nPage>=(unsigned)pPager->dbSize ){ return SQLITE_OK; } - syncAllPages(pPager); + syncJournal(pPager); rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)nPage); if( rc==SQLITE_OK ){ pPager->dbSize = nPage; @@ -1056,23 +1153,26 @@ int sqlitepager_ref(void *pData){ } /* -** Sync the journal and then write all free dirty pages to the database -** file. +** Sync the journal. In other words, make sure all the pages that have +** been written to the journal have actually reached the surface of the +** disk. It is not safe to modify the original database file until after +** the journal has been synced. If the original database is modified before +** the journal is synced and a power failure occurs, the unsynced journal +** data would be lost and we would be unable to completely rollback the +** database changes. Database corruption would occur. +** +** This routine also updates the nRec field in the header of the journal. +** (See comments on the pager_playback() routine for additional information.) +** If the sync mode is FULL, two syncs will occur. First the whole journal +** is synced, then the nRec field is updated, then a second sync occurs. ** -** Writing all free dirty pages to the database after the sync is a -** non-obvious optimization. fsync() is an expensive operation so we -** want to minimize the number ot times it is called. After an fsync() call, -** we are free to write dirty pages back to the database. It is best -** to go ahead and write as many dirty pages as possible to minimize -** the risk of having to do another fsync() later on. Writing dirty -** free pages in this way was observed to make database operations go -** up to 10 times faster. +** For temporary databases, we do not care if we are able to rollback +** after a power failure, so sync occurs. ** -** If we are writing to temporary database, there is no need to preserve -** the integrity of the journal file, so we can save time and skip the -** fsync(). +** This routine clears the needSync field of every page current held in +** memory. */ -static int syncAllPages(Pager *pPager){ +static int syncJournal(Pager *pPager){ PgHdr *pPg; int rc = SQLITE_OK; @@ -1082,9 +1182,13 @@ static int syncAllPages(Pager *pPager){ if( pPager->needSync ){ if( !pPager->tempFile ){ assert( pPager->journalOpen ); - assert( !pPager->noSync ); + /* assert( !pPager->noSync ); // noSync might be set if synchronous + ** was turned off after the transaction was started. Ticket #615 */ #ifndef NDEBUG { + /* Make sure the pPager->nRec counter we are keeping agrees + ** with the nRec computed from the size of the journal file. + */ off_t hdrSz, pgSz, jSz; hdrSz = JOURNAL_HDR_SZ(journal_format); pgSz = JOURNAL_PG_SZ(journal_format); @@ -1094,6 +1198,7 @@ static int syncAllPages(Pager *pPager){ } #endif if( journal_format>=3 ){ + /* Write the nRec value into the journal file header */ off_t szJ; if( pPager->fullSync ){ TRACE1("SYNC\n"); @@ -1152,7 +1257,10 @@ static int pager_write_pagelist(PgHdr *pList){ while( pList ){ assert( pList->dirty ); sqliteOsSeek(&pPager->fd, (pList->pgno-1)*(off_t)SQLITE_PAGE_SIZE); + CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6); + TRACE2("STORE %d\n", pList->pgno); rc = sqliteOsWrite(&pPager->fd, PGHDR_TO_DATA(pList), SQLITE_PAGE_SIZE); + CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0); if( rc ) return rc; pList->dirty = 0; pList = pList->pDirty; @@ -1304,7 +1412,7 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){ ** it can't be helped. */ if( pPg==0 ){ - int rc = syncAllPages(pPager); + int rc = syncJournal(pPager); if( rc!=0 ){ sqlitepager_rollback(pPager); return SQLITE_IOERR; @@ -1413,6 +1521,8 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){ int rc; sqliteOsSeek(&pPager->fd, (pgno-1)*(off_t)SQLITE_PAGE_SIZE); rc = sqliteOsRead(&pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE); + TRACE2("FETCH %d\n", pPg->pgno); + CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); if( rc!=SQLITE_OK ){ off_t fileSize; if( sqliteOsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK @@ -1557,7 +1667,7 @@ static int pager_open_journal(Pager *pPager){ rc = write32bits(&pPager->jfd, pPager->noSync ? 0xffffffff : 0); } if( rc==SQLITE_OK ){ - pPager->cksumInit = (u32)sqliteRandomInteger(); + sqliteRandomness(sizeof(pPager->cksumInit), &pPager->cksumInit); rc = write32bits(&pPager->jfd, pPager->cksumInit); } }else if( journal_format==JOURNAL_FORMAT_2 ){ @@ -1700,7 +1810,10 @@ int sqlitepager_write(void *pData){ szPg = SQLITE_PAGE_SIZE+4; } store32bits(pPg->pgno, pPg, -4); + CODEC(pPager, pData, pPg->pgno, 7); rc = sqliteOsWrite(&pPager->jfd, &((char*)pData)[-4], szPg); + TRACE3("JOURNAL %d %d\n", pPg->pgno, pPg->needSync); + CODEC(pPager, pData, pPg->pgno, 0); if( journal_format>=JOURNAL_FORMAT_3 ){ *(u32*)PGHDR_TO_EXTRA(pPg) = saved; } @@ -1718,7 +1831,6 @@ int sqlitepager_write(void *pData){ pPager->aInCkpt[pPg->pgno/8] |= 1<<(pPg->pgno&7); page_add_to_ckpt_list(pPg); } - TRACE3("JOURNAL %d %d\n", pPg->pgno, pPg->needSync); }else{ pPg->needSync = !pPager->journalStarted && !pPager->noSync; TRACE3("APPEND %d %d\n", pPg->pgno, pPg->needSync); @@ -1736,7 +1848,10 @@ int sqlitepager_write(void *pData){ if( pPager->ckptInUse && !pPg->inCkpt && (int)pPg->pgno<=pPager->ckptSize ){ assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize ); store32bits(pPg->pgno, pPg, -4); + CODEC(pPager, pData, pPg->pgno, 7); rc = sqliteOsWrite(&pPager->cpfd, &((char*)pData)[-4], SQLITE_PAGE_SIZE+4); + TRACE2("CKPT-JOURNAL %d\n", pPg->pgno); + CODEC(pPager, pData, pPg->pgno, 0); if( rc!=SQLITE_OK ){ sqlitepager_rollback(pPager); pPager->errMask |= PAGER_ERR_FULL; @@ -1896,7 +2011,8 @@ int sqlitepager_commit(Pager *pPager){ return rc; } assert( pPager->journalOpen ); - if( pPager->needSync && sqliteOsSync(&pPager->jfd)!=SQLITE_OK ){ + rc = syncJournal(pPager); + if( rc!=SQLITE_OK ){ goto commit_abort; } pPg = pager_get_all_dirty_pages(pPager); @@ -2077,6 +2193,18 @@ const char *sqlitepager_filename(Pager *pPager){ return pPager->zFilename; } +/* +** Set the codec for this pager +*/ +void sqlitepager_set_codec( + Pager *pPager, + void (*xCodec)(void*,void*,Pgno,int), + void *pCodecArg +){ + pPager->xCodec = xCodec; + pPager->pCodecArg = pCodecArg; +} + #ifdef SQLITE_TEST /* ** Print a listing of all referenced pages and their ref count. diff --git a/ext/sqlite/libsqlite/src/pager.h b/ext/sqlite/libsqlite/src/pager.h index 42fa3dc378..7172db88f5 100644 --- a/ext/sqlite/libsqlite/src/pager.h +++ b/ext/sqlite/libsqlite/src/pager.h @@ -19,12 +19,35 @@ /* ** The size of one page ** -** You can change this value to another (reasonable) power of two -** such as 512, 2048, 4096, or 8192 and things will still work. But -** experiments show that a page size of 1024 gives the best speed. -** (The speed differences are minimal.) +** You can change this value to another (reasonable) value you want. +** It need not be a power of two, though the interface to the disk +** will likely be faster if it is. +** +** Experiments show that a page size of 1024 gives the best speed +** for common usages. The speed differences for different sizes +** such as 512, 2048, 4096, an so forth, is minimal. Note, however, +** that changing the page size results in a completely imcompatible +** file format. */ +#ifndef SQLITE_PAGE_SIZE #define SQLITE_PAGE_SIZE 1024 +#endif + +/* +** Number of extra bytes of data allocated at the end of each page and +** stored on disk but not used by the higher level btree layer. Changing +** this value results in a completely incompatible file format. +*/ +#ifndef SQLITE_PAGE_RESERVE +#define SQLITE_PAGE_RESERVE 0 +#endif + +/* +** The total number of usable bytes stored on disk for each page. +** The usable bytes come at the beginning of the page and the reserve +** bytes come at the end. +*/ +#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE) /* ** Maximum number of pages in one database. (This is a limitation of @@ -75,6 +98,7 @@ int *sqlitepager_stats(Pager*); void sqlitepager_set_safety_level(Pager*,int); const char *sqlitepager_filename(Pager*); int sqlitepager_rename(Pager*, const char *zNewName); +void sqlitepager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*); #ifdef SQLITE_TEST void sqlitepager_refdump(Pager*); diff --git a/ext/sqlite/libsqlite/src/parse.c b/ext/sqlite/libsqlite/src/parse.c index 74a95f42d7..463536915c 100644 --- a/ext/sqlite/libsqlite/src/parse.c +++ b/ext/sqlite/libsqlite/src/parse.c @@ -4,7 +4,7 @@ /* First off, code is include which follows the "include" declaration ** in the input file. */ #include <stdio.h> -#line 35 "parse.y" +#line 33 "parse.y" #include "sqliteInt.h" #include "parse.h" @@ -81,34 +81,34 @@ struct TrigEvent { int a; IdList * b; }; */ /* */ #define YYCODETYPE unsigned char -#define YYNOCODE 219 +#define YYNOCODE 221 #define YYACTIONTYPE unsigned short int #define sqliteParserTOKENTYPE Token typedef union { sqliteParserTOKENTYPE yy0; - Select* yy11; - int yy52; - ExprList* yy62; - IdList* yy92; - Token yy210; - struct TrigEvent yy234; - Expr * yy270; - struct {int value; int mask;} yy279; - struct LimitVal yy280; - Expr* yy334; - SrcList* yy335; - TriggerStep * yy347; - int yy437; + TriggerStep * yy19; + struct LimitVal yy124; + Select* yy179; + Expr * yy182; + Expr* yy242; + struct TrigEvent yy290; + Token yy298; + SrcList* yy307; + IdList* yy320; + ExprList* yy322; + int yy372; + struct {int value; int mask;} yy407; + int yy441; } YYMINORTYPE; #define YYSTACKDEPTH 100 #define sqliteParserARG_SDECL Parse *pParse; #define sqliteParserARG_PDECL ,Parse *pParse #define sqliteParserARG_FETCH Parse *pParse = yypParser->pParse #define sqliteParserARG_STORE yypParser->pParse = pParse -#define YYNSTATE 555 -#define YYNRULE 287 -#define YYERRORSYMBOL 155 -#define YYERRSYMDT yy437 +#define YYNSTATE 563 +#define YYNRULE 293 +#define YYERRORSYMBOL 131 +#define YYERRSYMDT yy441 #define YYFALLBACK 1 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) @@ -162,504 +162,445 @@ typedef union { ** yy_default[] Default action for each state. */ static YYACTIONTYPE yy_action[] = { - /* 0 */ 104, 258, 174, 219, 215, 10, 162, 129, 20, 131, - /* 10 */ 258, 2, 327, 3, 40, 62, 474, 325, 368, 329, - /* 20 */ 154, 643, 49, 22, 41, 827, 106, 355, 330, 327, - /* 30 */ 69, 83, 537, 324, 385, 37, 32, 5, 1, 530, - /* 40 */ 127, 168, 539, 14, 36, 37, 86, 352, 458, 123, - /* 50 */ 143, 371, 119, 554, 256, 3, 84, 221, 166, 20, - /* 60 */ 560, 21, 307, 256, 177, 380, 157, 156, 183, 843, - /* 70 */ 309, 121, 142, 351, 22, 133, 117, 47, 146, 125, - /* 80 */ 139, 161, 46, 351, 44, 8, 115, 73, 144, 103, - /* 90 */ 15, 386, 54, 152, 302, 357, 174, 219, 229, 135, - /* 100 */ 112, 143, 16, 150, 443, 148, 384, 257, 104, 225, - /* 110 */ 64, 9, 21, 106, 162, 129, 257, 131, 60, 111, - /* 120 */ 106, 363, 368, 142, 69, 67, 293, 154, 154, 455, - /* 130 */ 68, 355, 97, 220, 179, 227, 175, 62, 105, 325, - /* 140 */ 35, 17, 256, 13, 181, 43, 449, 193, 127, 103, - /* 150 */ 106, 327, 209, 779, 69, 371, 555, 123, 143, 324, - /* 160 */ 119, 297, 154, 66, 31, 70, 166, 174, 219, 295, - /* 170 */ 310, 340, 177, 106, 157, 156, 183, 185, 113, 121, - /* 180 */ 142, 332, 201, 133, 117, 285, 146, 125, 139, 161, - /* 190 */ 333, 106, 231, 95, 115, 257, 144, 553, 184, 357, - /* 200 */ 152, 152, 319, 553, 46, 337, 44, 135, 112, 341, - /* 210 */ 150, 150, 148, 148, 54, 334, 302, 104, 64, 260, - /* 220 */ 146, 631, 106, 162, 129, 363, 131, 111, 172, 205, - /* 230 */ 144, 137, 780, 67, 331, 152, 299, 154, 68, 189, - /* 240 */ 60, 195, 179, 18, 175, 150, 105, 148, 174, 219, - /* 250 */ 238, 171, 181, 20, 172, 193, 552, 127, 317, 20, - /* 260 */ 106, 389, 552, 563, 73, 435, 123, 143, 22, 119, - /* 270 */ 424, 66, 106, 248, 22, 166, 20, 171, 6, 11, - /* 280 */ 4, 172, 197, 157, 156, 292, 113, 29, 121, 142, - /* 290 */ 250, 22, 133, 117, 172, 146, 125, 139, 161, 564, - /* 300 */ 797, 256, 169, 115, 171, 144, 21, 307, 69, 18, - /* 310 */ 152, 173, 21, 502, 368, 309, 135, 171, 353, 437, - /* 320 */ 150, 343, 148, 355, 20, 69, 104, 191, 169, 21, - /* 330 */ 440, 438, 162, 129, 20, 131, 489, 12, 228, 22, - /* 340 */ 241, 20, 350, 532, 277, 529, 154, 371, 583, 22, - /* 350 */ 172, 279, 531, 533, 257, 169, 22, 245, 69, 129, - /* 360 */ 172, 131, 483, 172, 778, 19, 127, 390, 169, 437, - /* 370 */ 242, 396, 154, 171, 315, 123, 143, 21, 119, 114, - /* 380 */ 440, 442, 392, 171, 166, 289, 171, 21, 65, 38, - /* 390 */ 342, 357, 157, 156, 21, 24, 788, 121, 142, 632, - /* 400 */ 567, 133, 117, 106, 146, 125, 139, 161, 246, 247, - /* 410 */ 575, 479, 115, 172, 144, 486, 450, 363, 52, 152, - /* 420 */ 653, 382, 381, 832, 169, 135, 481, 133, 137, 150, - /* 430 */ 146, 148, 104, 269, 169, 370, 171, 169, 162, 129, - /* 440 */ 144, 131, 174, 218, 411, 152, 423, 53, 270, 272, - /* 450 */ 266, 135, 154, 434, 172, 150, 420, 148, 316, 272, - /* 460 */ 322, 306, 172, 419, 270, 312, 106, 291, 272, 360, - /* 470 */ 283, 75, 127, 830, 270, 26, 412, 171, 272, 365, - /* 480 */ 409, 123, 143, 270, 119, 171, 58, 169, 91, 410, - /* 490 */ 166, 272, 374, 270, 272, 431, 528, 568, 157, 156, - /* 500 */ 710, 290, 473, 121, 142, 116, 270, 133, 117, 270, - /* 510 */ 146, 125, 139, 161, 655, 59, 473, 170, 115, 469, - /* 520 */ 144, 421, 716, 30, 239, 152, 106, 118, 169, 106, - /* 530 */ 540, 135, 413, 510, 120, 150, 169, 148, 122, 124, - /* 540 */ 106, 104, 213, 126, 128, 130, 132, 162, 129, 134, - /* 550 */ 131, 106, 136, 34, 138, 89, 141, 804, 106, 145, - /* 560 */ 147, 154, 106, 106, 149, 824, 217, 106, 106, 106, - /* 570 */ 106, 151, 153, 106, 155, 28, 106, 159, 106, 158, - /* 580 */ 106, 127, 163, 106, 106, 165, 217, 176, 106, 261, - /* 590 */ 123, 143, 268, 119, 69, 106, 106, 243, 106, 166, - /* 600 */ 178, 180, 182, 253, 190, 278, 106, 157, 156, 106, - /* 610 */ 217, 106, 121, 142, 192, 280, 133, 117, 658, 146, - /* 620 */ 125, 139, 161, 260, 106, 106, 106, 115, 106, 144, - /* 630 */ 314, 210, 212, 268, 152, 214, 416, 222, 106, 294, - /* 640 */ 135, 336, 224, 339, 150, 104, 148, 216, 235, 260, - /* 650 */ 240, 162, 129, 274, 131, 106, 106, 284, 346, 106, - /* 660 */ 335, 106, 338, 369, 268, 154, 106, 230, 69, 275, - /* 670 */ 268, 268, 106, 267, 106, 406, 268, 106, 414, 387, - /* 680 */ 819, 287, 69, 453, 405, 127, 313, 106, 415, 457, - /* 690 */ 463, 296, 416, 395, 123, 143, 470, 119, 418, 106, - /* 700 */ 418, 645, 275, 166, 820, 471, 73, 106, 69, 680, - /* 710 */ 710, 157, 156, 106, 323, 275, 121, 142, 455, 466, - /* 720 */ 133, 117, 444, 146, 125, 139, 161, 467, 470, 106, - /* 730 */ 69, 115, 73, 144, 239, 500, 39, 33, 152, 345, - /* 740 */ 569, 507, 42, 300, 135, 361, 275, 536, 150, 104, - /* 750 */ 148, 366, 375, 508, 10, 162, 129, 432, 131, 680, - /* 760 */ 45, 796, 570, 574, 48, 543, 535, 7, 51, 154, - /* 770 */ 680, 50, 55, 464, 56, 63, 584, 472, 585, 521, - /* 780 */ 57, 23, 680, 73, 61, 515, 388, 71, 74, 127, - /* 790 */ 72, 490, 239, 76, 549, 77, 236, 478, 123, 143, - /* 800 */ 25, 119, 79, 78, 234, 93, 80, 166, 82, 511, - /* 810 */ 85, 81, 88, 87, 90, 157, 156, 92, 94, 96, - /* 820 */ 121, 142, 100, 512, 133, 117, 98, 146, 125, 139, - /* 830 */ 161, 99, 101, 102, 10, 115, 137, 144, 107, 108, - /* 840 */ 104, 110, 152, 109, 140, 825, 162, 129, 135, 131, - /* 850 */ 154, 526, 150, 160, 148, 167, 514, 659, 27, 660, - /* 860 */ 154, 661, 73, 211, 186, 187, 188, 194, 177, 198, - /* 870 */ 196, 199, 183, 200, 202, 203, 206, 204, 208, 495, - /* 880 */ 127, 207, 524, 233, 226, 237, 217, 244, 232, 123, - /* 890 */ 143, 249, 119, 252, 262, 251, 254, 275, 166, 255, - /* 900 */ 259, 273, 264, 263, 112, 265, 157, 156, 276, 281, - /* 910 */ 271, 121, 142, 288, 64, 133, 117, 282, 146, 125, - /* 920 */ 139, 161, 298, 111, 303, 301, 115, 321, 144, 67, - /* 930 */ 304, 344, 308, 152, 68, 326, 348, 328, 179, 135, - /* 940 */ 175, 306, 105, 150, 349, 148, 104, 305, 181, 311, - /* 950 */ 318, 193, 162, 129, 320, 131, 358, 347, 356, 359, - /* 960 */ 372, 364, 373, 376, 362, 383, 154, 66, 367, 354, - /* 970 */ 377, 49, 391, 379, 378, 393, 394, 397, 400, 401, - /* 980 */ 398, 402, 113, 407, 781, 812, 127, 403, 404, 408, - /* 990 */ 817, 818, 399, 417, 422, 123, 143, 426, 119, 425, - /* 1000 */ 427, 429, 428, 430, 166, 786, 433, 787, 436, 439, - /* 1010 */ 811, 441, 157, 156, 826, 446, 444, 121, 142, 447, - /* 1020 */ 448, 133, 117, 445, 146, 125, 139, 161, 452, 828, - /* 1030 */ 454, 451, 115, 456, 144, 459, 462, 460, 461, 152, - /* 1040 */ 465, 468, 829, 475, 476, 135, 831, 485, 480, 150, - /* 1050 */ 652, 148, 164, 477, 482, 654, 484, 794, 162, 129, - /* 1060 */ 487, 131, 488, 491, 837, 492, 493, 709, 498, 712, - /* 1070 */ 494, 497, 154, 496, 503, 499, 501, 504, 505, 506, - /* 1080 */ 509, 513, 715, 717, 718, 519, 522, 518, 516, 517, - /* 1090 */ 520, 523, 127, 795, 527, 525, 798, 534, 799, 800, - /* 1100 */ 801, 123, 143, 802, 119, 805, 807, 541, 808, 538, - /* 1110 */ 166, 806, 542, 803, 548, 545, 546, 507, 157, 156, - /* 1120 */ 507, 544, 838, 121, 142, 841, 547, 133, 117, 550, - /* 1130 */ 146, 125, 139, 161, 551, 507, 507, 507, 115, 507, - /* 1140 */ 144, 507, 507, 507, 507, 152, 507, 507, 507, 507, - /* 1150 */ 507, 135, 507, 507, 507, 150, 507, 148, 223, 507, - /* 1160 */ 507, 507, 507, 507, 162, 129, 507, 131, 507, 507, - /* 1170 */ 507, 507, 507, 507, 507, 507, 507, 507, 154, 507, - /* 1180 */ 507, 507, 507, 507, 507, 507, 507, 507, 507, 507, - /* 1190 */ 507, 507, 507, 507, 507, 507, 507, 507, 127, 507, - /* 1200 */ 507, 507, 507, 507, 507, 507, 507, 123, 143, 507, - /* 1210 */ 119, 507, 507, 507, 507, 507, 166, 507, 507, 507, - /* 1220 */ 507, 507, 507, 507, 157, 156, 507, 507, 507, 121, - /* 1230 */ 142, 507, 507, 133, 117, 507, 146, 125, 139, 161, - /* 1240 */ 507, 507, 507, 507, 115, 507, 144, 507, 507, 507, - /* 1250 */ 507, 152, 507, 507, 507, 507, 507, 135, 507, 507, - /* 1260 */ 507, 150, 507, 148, 104, 507, 507, 507, 507, 507, - /* 1270 */ 162, 129, 507, 131, 507, 507, 507, 507, 507, 507, - /* 1280 */ 507, 507, 507, 507, 154, 507, 507, 507, 507, 507, - /* 1290 */ 507, 507, 507, 507, 507, 507, 507, 507, 507, 507, - /* 1300 */ 507, 507, 507, 507, 127, 507, 507, 507, 507, 507, - /* 1310 */ 507, 507, 507, 123, 143, 507, 119, 507, 507, 507, - /* 1320 */ 507, 507, 166, 507, 507, 507, 507, 507, 507, 507, - /* 1330 */ 157, 156, 507, 507, 507, 121, 142, 507, 507, 133, - /* 1340 */ 117, 507, 146, 125, 139, 161, 507, 162, 129, 507, - /* 1350 */ 131, 507, 144, 507, 507, 507, 507, 152, 507, 507, - /* 1360 */ 507, 154, 507, 135, 507, 507, 507, 150, 507, 148, - /* 1370 */ 507, 507, 507, 507, 507, 507, 507, 507, 507, 507, - /* 1380 */ 507, 127, 507, 507, 507, 507, 507, 507, 507, 507, - /* 1390 */ 123, 143, 507, 119, 507, 507, 507, 507, 507, 166, - /* 1400 */ 507, 507, 507, 507, 507, 177, 507, 157, 156, 183, - /* 1410 */ 507, 507, 121, 142, 507, 507, 133, 117, 507, 146, - /* 1420 */ 125, 139, 161, 177, 507, 507, 507, 183, 507, 144, - /* 1430 */ 507, 507, 507, 507, 152, 507, 507, 507, 507, 507, - /* 1440 */ 135, 112, 507, 507, 150, 507, 148, 507, 507, 507, - /* 1450 */ 507, 64, 507, 507, 507, 507, 507, 507, 507, 112, - /* 1460 */ 111, 507, 507, 507, 507, 507, 67, 507, 507, 64, - /* 1470 */ 507, 68, 507, 507, 507, 179, 507, 175, 111, 105, - /* 1480 */ 507, 507, 507, 507, 67, 181, 507, 507, 193, 68, - /* 1490 */ 507, 507, 507, 179, 507, 175, 507, 105, 129, 507, - /* 1500 */ 131, 507, 286, 181, 66, 507, 193, 507, 507, 507, - /* 1510 */ 507, 154, 507, 507, 507, 507, 507, 507, 507, 113, - /* 1520 */ 507, 507, 66, 507, 507, 507, 507, 507, 507, 507, - /* 1530 */ 507, 507, 507, 507, 507, 507, 507, 113, 507, 507, - /* 1540 */ 123, 507, 507, 119, 507, 507, 507, 507, 507, 507, - /* 1550 */ 507, 507, 507, 507, 507, 507, 507, 507, 507, 507, - /* 1560 */ 507, 507, 121, 507, 507, 507, 133, 117, 507, 146, - /* 1570 */ 507, 507, 507, 507, 507, 507, 507, 507, 507, 144, - /* 1580 */ 507, 507, 507, 507, 152, 507, 507, 507, 507, 507, - /* 1590 */ 135, 507, 507, 507, 150, 507, 148, + /* 0 */ 264, 5, 262, 119, 123, 117, 121, 129, 131, 133, + /* 10 */ 135, 144, 146, 148, 150, 152, 154, 568, 106, 106, + /* 20 */ 143, 857, 1, 562, 3, 142, 129, 131, 133, 135, + /* 30 */ 144, 146, 148, 150, 152, 154, 174, 103, 8, 115, + /* 40 */ 104, 139, 127, 125, 156, 161, 157, 162, 166, 119, + /* 50 */ 123, 117, 121, 129, 131, 133, 135, 144, 146, 148, + /* 60 */ 150, 152, 154, 31, 361, 392, 263, 143, 363, 369, + /* 70 */ 374, 97, 142, 148, 150, 152, 154, 68, 75, 377, + /* 80 */ 167, 64, 218, 46, 20, 289, 115, 104, 139, 127, + /* 90 */ 125, 156, 161, 157, 162, 166, 119, 123, 117, 121, + /* 100 */ 129, 131, 133, 135, 144, 146, 148, 150, 152, 154, + /* 110 */ 193, 41, 336, 563, 44, 54, 60, 62, 308, 331, + /* 120 */ 175, 20, 560, 561, 572, 333, 640, 18, 359, 144, + /* 130 */ 146, 148, 150, 152, 154, 143, 181, 179, 303, 18, + /* 140 */ 142, 84, 86, 20, 177, 66, 67, 111, 21, 22, + /* 150 */ 112, 105, 83, 792, 115, 104, 139, 127, 125, 156, + /* 160 */ 161, 157, 162, 166, 119, 123, 117, 121, 129, 131, + /* 170 */ 133, 135, 144, 146, 148, 150, 152, 154, 790, 560, + /* 180 */ 561, 46, 13, 113, 183, 21, 22, 534, 361, 2, + /* 190 */ 3, 14, 363, 369, 374, 338, 361, 690, 544, 542, + /* 200 */ 363, 369, 374, 377, 836, 143, 15, 21, 22, 16, + /* 210 */ 142, 377, 44, 54, 60, 62, 308, 331, 396, 535, + /* 220 */ 17, 9, 191, 333, 115, 104, 139, 127, 125, 156, + /* 230 */ 161, 157, 162, 166, 119, 123, 117, 121, 129, 131, + /* 240 */ 133, 135, 144, 146, 148, 150, 152, 154, 571, 230, + /* 250 */ 340, 343, 143, 20, 536, 537, 538, 142, 402, 337, + /* 260 */ 398, 339, 357, 68, 346, 347, 32, 64, 266, 391, + /* 270 */ 37, 115, 104, 139, 127, 125, 156, 161, 157, 162, + /* 280 */ 166, 119, 123, 117, 121, 129, 131, 133, 135, 144, + /* 290 */ 146, 148, 150, 152, 154, 839, 193, 651, 291, 298, + /* 300 */ 300, 221, 357, 43, 173, 689, 175, 251, 330, 36, + /* 310 */ 37, 106, 232, 40, 335, 58, 137, 21, 22, 330, + /* 320 */ 411, 143, 181, 179, 47, 59, 142, 358, 390, 174, + /* 330 */ 177, 66, 67, 111, 448, 49, 112, 105, 583, 213, + /* 340 */ 115, 104, 139, 127, 125, 156, 161, 157, 162, 166, + /* 350 */ 119, 123, 117, 121, 129, 131, 133, 135, 144, 146, + /* 360 */ 148, 150, 152, 154, 306, 301, 106, 249, 259, 113, + /* 370 */ 183, 793, 70, 253, 281, 219, 20, 106, 20, 11, + /* 380 */ 106, 482, 454, 444, 299, 143, 169, 10, 171, 172, + /* 390 */ 142, 169, 73, 171, 172, 103, 688, 69, 174, 169, + /* 400 */ 252, 171, 172, 12, 115, 104, 139, 127, 125, 156, + /* 410 */ 161, 157, 162, 166, 119, 123, 117, 121, 129, 131, + /* 420 */ 133, 135, 144, 146, 148, 150, 152, 154, 95, 237, + /* 430 */ 313, 20, 143, 295, 244, 424, 169, 142, 171, 172, + /* 440 */ 21, 22, 21, 22, 219, 386, 316, 323, 325, 837, + /* 450 */ 19, 115, 104, 139, 127, 125, 156, 161, 157, 162, + /* 460 */ 166, 119, 123, 117, 121, 129, 131, 133, 135, 144, + /* 470 */ 146, 148, 150, 152, 154, 106, 661, 20, 264, 143, + /* 480 */ 262, 844, 315, 169, 142, 171, 172, 333, 38, 842, + /* 490 */ 10, 356, 348, 184, 421, 21, 22, 282, 115, 104, + /* 500 */ 139, 127, 125, 156, 161, 157, 162, 166, 119, 123, + /* 510 */ 117, 121, 129, 131, 133, 135, 144, 146, 148, 150, + /* 520 */ 152, 154, 69, 254, 262, 251, 143, 639, 663, 35, + /* 530 */ 65, 142, 726, 313, 283, 259, 185, 417, 419, 418, + /* 540 */ 284, 21, 22, 690, 263, 115, 104, 139, 127, 125, + /* 550 */ 156, 161, 157, 162, 166, 119, 123, 117, 121, 129, + /* 560 */ 131, 133, 135, 144, 146, 148, 150, 152, 154, 256, + /* 570 */ 20, 791, 424, 143, 169, 52, 171, 172, 142, 169, + /* 580 */ 24, 171, 172, 247, 53, 315, 26, 169, 263, 171, + /* 590 */ 172, 253, 115, 164, 139, 127, 125, 156, 161, 157, + /* 600 */ 162, 166, 119, 123, 117, 121, 129, 131, 133, 135, + /* 610 */ 144, 146, 148, 150, 152, 154, 426, 349, 252, 425, + /* 620 */ 143, 262, 575, 297, 591, 142, 169, 296, 171, 172, + /* 630 */ 169, 471, 171, 172, 21, 22, 427, 221, 91, 115, + /* 640 */ 227, 139, 127, 125, 156, 161, 157, 162, 166, 119, + /* 650 */ 123, 117, 121, 129, 131, 133, 135, 144, 146, 148, + /* 660 */ 150, 152, 154, 388, 312, 106, 89, 143, 720, 376, + /* 670 */ 387, 170, 142, 487, 666, 248, 320, 216, 319, 217, + /* 680 */ 28, 459, 30, 305, 189, 263, 209, 104, 139, 127, + /* 690 */ 125, 156, 161, 157, 162, 166, 119, 123, 117, 121, + /* 700 */ 129, 131, 133, 135, 144, 146, 148, 150, 152, 154, + /* 710 */ 106, 106, 809, 494, 143, 489, 106, 816, 33, 142, + /* 720 */ 395, 234, 273, 217, 274, 420, 20, 545, 114, 481, + /* 730 */ 137, 429, 576, 321, 116, 139, 127, 125, 156, 161, + /* 740 */ 157, 162, 166, 119, 123, 117, 121, 129, 131, 133, + /* 750 */ 135, 144, 146, 148, 150, 152, 154, 7, 322, 23, + /* 760 */ 25, 27, 394, 68, 415, 416, 10, 64, 197, 477, + /* 770 */ 577, 533, 266, 548, 578, 831, 276, 201, 520, 4, + /* 780 */ 6, 245, 430, 557, 29, 266, 491, 106, 441, 497, + /* 790 */ 21, 22, 205, 168, 443, 195, 193, 531, 276, 448, + /* 800 */ 276, 808, 267, 272, 529, 174, 175, 318, 440, 341, + /* 810 */ 344, 106, 342, 345, 69, 286, 68, 582, 69, 69, + /* 820 */ 64, 540, 181, 179, 541, 328, 302, 366, 217, 118, + /* 830 */ 177, 66, 67, 111, 34, 143, 112, 105, 445, 510, + /* 840 */ 142, 215, 278, 800, 467, 276, 498, 503, 444, 193, + /* 850 */ 106, 219, 486, 443, 42, 73, 231, 73, 45, 175, + /* 860 */ 449, 39, 225, 229, 278, 451, 278, 68, 174, 113, + /* 870 */ 183, 64, 371, 55, 106, 181, 179, 292, 69, 276, + /* 880 */ 276, 69, 48, 177, 66, 67, 111, 224, 276, 112, + /* 890 */ 105, 106, 481, 393, 106, 106, 63, 106, 106, 106, + /* 900 */ 193, 653, 106, 467, 233, 51, 380, 437, 526, 120, + /* 910 */ 175, 278, 122, 124, 219, 126, 128, 130, 69, 453, + /* 920 */ 132, 106, 113, 183, 451, 106, 181, 179, 159, 106, + /* 930 */ 106, 106, 518, 106, 177, 66, 67, 111, 106, 134, + /* 940 */ 112, 105, 422, 136, 106, 278, 278, 138, 141, 145, + /* 950 */ 720, 147, 106, 329, 275, 274, 149, 106, 852, 158, + /* 960 */ 106, 106, 151, 106, 106, 351, 106, 352, 106, 464, + /* 970 */ 153, 106, 106, 113, 183, 155, 106, 106, 163, 165, + /* 980 */ 106, 176, 178, 106, 180, 106, 182, 106, 401, 190, + /* 990 */ 192, 106, 106, 293, 210, 212, 106, 367, 214, 274, + /* 1000 */ 372, 226, 274, 228, 381, 241, 274, 106, 106, 246, + /* 1010 */ 280, 290, 106, 69, 375, 438, 472, 274, 422, 832, + /* 1020 */ 106, 73, 474, 73, 458, 412, 462, 480, 464, 478, + /* 1030 */ 466, 690, 515, 519, 475, 478, 516, 50, 479, 221, + /* 1040 */ 690, 221, 56, 57, 61, 592, 71, 69, 593, 73, + /* 1050 */ 72, 74, 245, 242, 93, 81, 76, 69, 77, 240, + /* 1060 */ 78, 82, 79, 245, 85, 554, 80, 88, 87, 90, + /* 1070 */ 92, 94, 96, 102, 100, 99, 101, 107, 109, 160, + /* 1080 */ 154, 667, 98, 508, 108, 668, 110, 220, 211, 669, + /* 1090 */ 137, 140, 188, 194, 186, 196, 187, 199, 198, 200, + /* 1100 */ 203, 204, 202, 207, 206, 208, 221, 223, 222, 235, + /* 1110 */ 236, 239, 238, 217, 250, 258, 243, 261, 279, 270, + /* 1120 */ 271, 255, 257, 260, 269, 265, 285, 294, 277, 268, + /* 1130 */ 287, 304, 309, 307, 327, 312, 288, 354, 389, 314, + /* 1140 */ 364, 365, 370, 378, 379, 382, 310, 49, 311, 362, + /* 1150 */ 368, 373, 317, 324, 326, 332, 350, 355, 383, 400, + /* 1160 */ 353, 397, 399, 403, 404, 334, 405, 406, 407, 384, + /* 1170 */ 413, 409, 824, 414, 360, 385, 829, 423, 410, 431, + /* 1180 */ 428, 432, 830, 433, 434, 436, 439, 798, 799, 447, + /* 1190 */ 442, 450, 727, 728, 446, 823, 452, 838, 455, 445, + /* 1200 */ 456, 457, 408, 435, 460, 461, 463, 840, 465, 468, + /* 1210 */ 470, 469, 476, 841, 483, 485, 843, 660, 662, 493, + /* 1220 */ 806, 496, 473, 849, 499, 719, 501, 484, 488, 490, + /* 1230 */ 492, 502, 504, 495, 500, 507, 505, 506, 509, 722, + /* 1240 */ 513, 511, 512, 514, 517, 725, 528, 522, 524, 525, + /* 1250 */ 527, 523, 807, 530, 810, 532, 811, 812, 813, 814, + /* 1260 */ 817, 819, 539, 820, 818, 815, 521, 543, 546, 552, + /* 1270 */ 556, 550, 850, 547, 549, 851, 555, 558, 551, 855, + /* 1280 */ 553, 559, }; static YYCODETYPE yy_lookahead[] = { - /* 0 */ 5, 6, 157, 158, 159, 90, 11, 12, 59, 14, - /* 10 */ 6, 154, 32, 156, 132, 18, 34, 20, 18, 137, - /* 20 */ 25, 106, 32, 74, 27, 43, 181, 27, 31, 32, - /* 30 */ 185, 68, 83, 151, 142, 143, 144, 106, 139, 90, - /* 40 */ 45, 196, 93, 1, 142, 143, 83, 145, 66, 54, - /* 50 */ 55, 51, 57, 154, 59, 156, 93, 11, 63, 59, - /* 60 */ 106, 112, 82, 59, 13, 85, 71, 72, 17, 170, - /* 70 */ 90, 76, 77, 181, 74, 80, 81, 87, 83, 84, - /* 80 */ 85, 86, 85, 181, 87, 206, 91, 105, 93, 157, - /* 90 */ 48, 6, 95, 98, 97, 95, 157, 158, 159, 104, - /* 100 */ 49, 55, 60, 108, 122, 110, 204, 112, 5, 63, - /* 110 */ 59, 184, 112, 181, 11, 12, 112, 14, 121, 68, - /* 120 */ 181, 121, 18, 77, 185, 74, 157, 25, 25, 181, - /* 130 */ 79, 27, 200, 87, 83, 196, 85, 18, 87, 20, - /* 140 */ 22, 99, 59, 101, 93, 137, 198, 96, 45, 157, - /* 150 */ 181, 32, 42, 43, 185, 51, 0, 54, 55, 151, - /* 160 */ 57, 110, 25, 112, 79, 196, 63, 157, 158, 159, - /* 170 */ 34, 49, 13, 181, 71, 72, 17, 136, 127, 76, - /* 180 */ 77, 59, 1, 80, 81, 131, 83, 84, 85, 86, - /* 190 */ 68, 181, 200, 201, 91, 112, 93, 47, 157, 95, - /* 200 */ 98, 98, 66, 47, 85, 83, 87, 104, 49, 87, - /* 210 */ 108, 108, 110, 110, 95, 93, 97, 5, 59, 165, - /* 220 */ 83, 103, 181, 11, 12, 121, 14, 68, 46, 48, - /* 230 */ 93, 177, 129, 74, 112, 98, 157, 25, 79, 129, - /* 240 */ 121, 60, 83, 116, 85, 108, 87, 110, 157, 158, - /* 250 */ 159, 69, 93, 59, 46, 96, 106, 45, 122, 59, - /* 260 */ 181, 205, 106, 106, 105, 209, 54, 55, 74, 57, - /* 270 */ 214, 112, 181, 73, 74, 63, 59, 69, 138, 26, - /* 280 */ 140, 46, 101, 71, 72, 103, 127, 147, 76, 77, - /* 290 */ 73, 74, 80, 81, 46, 83, 84, 85, 86, 106, - /* 300 */ 106, 59, 120, 91, 69, 93, 112, 82, 185, 116, - /* 310 */ 98, 103, 112, 173, 18, 90, 104, 69, 22, 196, - /* 320 */ 108, 79, 110, 27, 59, 185, 5, 115, 120, 112, - /* 330 */ 207, 208, 11, 12, 59, 14, 196, 193, 103, 74, - /* 340 */ 22, 59, 165, 179, 79, 181, 25, 51, 39, 74, - /* 350 */ 46, 103, 188, 189, 112, 120, 74, 22, 185, 12, - /* 360 */ 46, 14, 64, 46, 43, 181, 45, 113, 120, 196, - /* 370 */ 52, 117, 25, 69, 16, 54, 55, 112, 57, 157, - /* 380 */ 207, 208, 128, 69, 63, 110, 69, 112, 79, 212, - /* 390 */ 213, 95, 71, 72, 112, 206, 64, 76, 77, 103, - /* 400 */ 106, 80, 81, 181, 83, 84, 85, 86, 73, 74, - /* 410 */ 106, 113, 91, 46, 93, 117, 22, 121, 33, 98, - /* 420 */ 106, 151, 152, 106, 120, 104, 128, 80, 177, 108, - /* 430 */ 83, 110, 5, 166, 120, 184, 69, 120, 11, 12, - /* 440 */ 93, 14, 157, 158, 34, 98, 114, 62, 181, 166, - /* 450 */ 167, 104, 25, 121, 46, 108, 2, 110, 100, 166, - /* 460 */ 167, 191, 46, 9, 181, 107, 181, 4, 166, 167, - /* 470 */ 194, 195, 45, 106, 181, 206, 66, 69, 166, 167, - /* 480 */ 102, 54, 55, 181, 57, 69, 7, 120, 22, 111, - /* 490 */ 63, 166, 167, 181, 166, 167, 45, 106, 71, 72, - /* 500 */ 106, 38, 157, 76, 77, 157, 181, 80, 81, 181, - /* 510 */ 83, 84, 85, 86, 106, 36, 157, 4, 91, 174, - /* 520 */ 93, 67, 106, 148, 130, 98, 181, 157, 120, 181, - /* 530 */ 79, 104, 122, 174, 157, 108, 120, 110, 157, 157, - /* 540 */ 181, 5, 115, 157, 157, 157, 157, 11, 12, 157, - /* 550 */ 14, 181, 157, 103, 157, 89, 157, 106, 181, 157, - /* 560 */ 157, 25, 181, 181, 157, 10, 22, 181, 181, 181, - /* 570 */ 181, 157, 157, 181, 157, 206, 181, 85, 181, 87, - /* 580 */ 181, 45, 157, 181, 181, 157, 22, 157, 181, 131, - /* 590 */ 54, 55, 22, 57, 185, 181, 181, 197, 181, 63, - /* 600 */ 157, 157, 157, 203, 157, 196, 181, 71, 72, 181, - /* 610 */ 22, 181, 76, 77, 157, 131, 80, 81, 105, 83, - /* 620 */ 84, 85, 86, 165, 181, 181, 181, 91, 181, 93, - /* 630 */ 31, 157, 157, 22, 98, 157, 22, 157, 181, 103, - /* 640 */ 104, 49, 157, 49, 108, 5, 110, 103, 157, 165, - /* 650 */ 157, 11, 12, 157, 14, 181, 181, 157, 22, 181, - /* 660 */ 68, 181, 68, 157, 22, 25, 181, 103, 185, 39, - /* 670 */ 22, 22, 181, 103, 181, 157, 22, 181, 88, 196, - /* 680 */ 90, 181, 185, 157, 129, 45, 87, 181, 171, 157, - /* 690 */ 171, 103, 22, 196, 54, 55, 22, 57, 181, 181, - /* 700 */ 181, 70, 39, 63, 90, 157, 105, 181, 185, 79, - /* 710 */ 106, 71, 72, 181, 103, 39, 76, 77, 181, 196, - /* 720 */ 80, 81, 91, 83, 84, 85, 86, 126, 22, 181, - /* 730 */ 185, 91, 105, 93, 130, 198, 133, 146, 98, 103, - /* 740 */ 106, 196, 181, 103, 104, 103, 39, 49, 108, 5, - /* 750 */ 110, 103, 103, 126, 90, 11, 12, 103, 14, 52, - /* 760 */ 184, 106, 106, 106, 184, 8, 68, 10, 65, 25, - /* 770 */ 107, 169, 75, 103, 202, 79, 39, 103, 39, 124, - /* 780 */ 184, 24, 106, 105, 184, 28, 29, 180, 153, 45, - /* 790 */ 185, 34, 130, 161, 37, 217, 56, 40, 54, 55, - /* 800 */ 43, 57, 163, 162, 58, 92, 187, 63, 78, 103, - /* 810 */ 68, 178, 199, 68, 199, 71, 72, 199, 15, 22, - /* 820 */ 76, 77, 20, 66, 80, 81, 141, 83, 84, 85, - /* 830 */ 86, 202, 59, 164, 90, 91, 177, 93, 39, 181, - /* 840 */ 5, 181, 98, 39, 177, 10, 11, 12, 104, 14, - /* 850 */ 25, 94, 108, 87, 110, 79, 99, 105, 101, 105, - /* 860 */ 25, 105, 105, 129, 135, 134, 43, 79, 13, 22, - /* 870 */ 103, 181, 17, 103, 22, 181, 22, 103, 103, 122, - /* 880 */ 45, 181, 125, 202, 79, 15, 22, 175, 141, 54, - /* 890 */ 55, 181, 57, 73, 183, 181, 181, 39, 63, 150, - /* 900 */ 181, 90, 124, 215, 49, 79, 71, 72, 181, 183, - /* 910 */ 202, 76, 77, 39, 59, 80, 81, 215, 83, 84, - /* 920 */ 85, 86, 103, 68, 181, 184, 91, 79, 93, 74, - /* 930 */ 168, 199, 181, 98, 79, 164, 103, 169, 83, 104, - /* 940 */ 85, 191, 87, 108, 165, 110, 5, 192, 93, 190, - /* 950 */ 190, 96, 11, 12, 190, 14, 75, 199, 181, 79, - /* 960 */ 75, 79, 79, 97, 184, 204, 25, 112, 184, 204, - /* 970 */ 181, 32, 181, 192, 168, 181, 6, 181, 90, 181, - /* 980 */ 211, 150, 127, 50, 129, 10, 45, 160, 216, 41, - /* 990 */ 90, 90, 210, 181, 88, 54, 55, 181, 57, 64, - /* 1000 */ 90, 150, 181, 79, 63, 106, 184, 64, 10, 43, - /* 1010 */ 106, 106, 71, 72, 43, 186, 91, 76, 77, 181, - /* 1020 */ 107, 80, 81, 193, 83, 84, 85, 86, 45, 106, - /* 1030 */ 217, 181, 91, 45, 93, 186, 79, 70, 181, 98, - /* 1040 */ 172, 79, 106, 52, 181, 104, 106, 150, 181, 108, - /* 1050 */ 106, 110, 5, 217, 181, 106, 181, 106, 11, 12, - /* 1060 */ 181, 14, 150, 52, 106, 181, 150, 106, 150, 106, - /* 1070 */ 217, 181, 25, 186, 70, 107, 217, 181, 150, 172, - /* 1080 */ 79, 186, 106, 70, 70, 52, 35, 150, 186, 181, - /* 1090 */ 181, 112, 45, 106, 165, 181, 106, 182, 106, 106, - /* 1100 */ 106, 54, 55, 106, 57, 106, 106, 181, 106, 182, - /* 1110 */ 63, 106, 103, 106, 30, 165, 6, 218, 71, 72, - /* 1120 */ 218, 149, 106, 76, 77, 106, 181, 80, 81, 149, - /* 1130 */ 83, 84, 85, 86, 181, 218, 218, 218, 91, 218, - /* 1140 */ 93, 218, 218, 218, 218, 98, 218, 218, 218, 218, - /* 1150 */ 218, 104, 218, 218, 218, 108, 218, 110, 5, 218, - /* 1160 */ 218, 218, 218, 218, 11, 12, 218, 14, 218, 218, - /* 1170 */ 218, 218, 218, 218, 218, 218, 218, 218, 25, 218, - /* 1180 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1190 */ 218, 218, 218, 218, 218, 218, 218, 218, 45, 218, - /* 1200 */ 218, 218, 218, 218, 218, 218, 218, 54, 55, 218, - /* 1210 */ 57, 218, 218, 218, 218, 218, 63, 218, 218, 218, - /* 1220 */ 218, 218, 218, 218, 71, 72, 218, 218, 218, 76, - /* 1230 */ 77, 218, 218, 80, 81, 218, 83, 84, 85, 86, - /* 1240 */ 218, 218, 218, 218, 91, 218, 93, 218, 218, 218, - /* 1250 */ 218, 98, 218, 218, 218, 218, 218, 104, 218, 218, - /* 1260 */ 218, 108, 218, 110, 5, 218, 218, 218, 218, 218, - /* 1270 */ 11, 12, 218, 14, 218, 218, 218, 218, 218, 218, - /* 1280 */ 218, 218, 218, 218, 25, 218, 218, 218, 218, 218, - /* 1290 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1300 */ 218, 218, 218, 218, 45, 218, 218, 218, 218, 218, - /* 1310 */ 218, 218, 218, 54, 55, 218, 57, 218, 218, 218, - /* 1320 */ 218, 218, 63, 218, 218, 218, 218, 218, 218, 218, - /* 1330 */ 71, 72, 218, 218, 218, 76, 77, 218, 218, 80, - /* 1340 */ 81, 218, 83, 84, 85, 86, 218, 11, 12, 218, - /* 1350 */ 14, 218, 93, 218, 218, 218, 218, 98, 218, 218, - /* 1360 */ 218, 25, 218, 104, 218, 218, 218, 108, 218, 110, - /* 1370 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1380 */ 218, 45, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1390 */ 54, 55, 218, 57, 218, 218, 218, 218, 218, 63, - /* 1400 */ 218, 218, 218, 218, 218, 13, 218, 71, 72, 17, - /* 1410 */ 218, 218, 76, 77, 218, 218, 80, 81, 218, 83, - /* 1420 */ 84, 85, 86, 13, 218, 218, 218, 17, 218, 93, - /* 1430 */ 218, 218, 218, 218, 98, 218, 218, 218, 218, 218, - /* 1440 */ 104, 49, 218, 218, 108, 218, 110, 218, 218, 218, - /* 1450 */ 218, 59, 218, 218, 218, 218, 218, 218, 218, 49, - /* 1460 */ 68, 218, 218, 218, 218, 218, 74, 218, 218, 59, - /* 1470 */ 218, 79, 218, 218, 218, 83, 218, 85, 68, 87, - /* 1480 */ 218, 218, 218, 218, 74, 93, 218, 218, 96, 79, - /* 1490 */ 218, 218, 218, 83, 218, 85, 218, 87, 12, 218, - /* 1500 */ 14, 218, 110, 93, 112, 218, 96, 218, 218, 218, - /* 1510 */ 218, 25, 218, 218, 218, 218, 218, 218, 218, 127, - /* 1520 */ 218, 218, 112, 218, 218, 218, 218, 218, 218, 218, - /* 1530 */ 218, 218, 218, 218, 218, 218, 218, 127, 218, 218, - /* 1540 */ 54, 218, 218, 57, 218, 218, 218, 218, 218, 218, - /* 1550 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1560 */ 218, 218, 76, 218, 218, 218, 80, 81, 218, 83, - /* 1570 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 93, - /* 1580 */ 218, 218, 218, 218, 98, 218, 218, 218, 218, 218, - /* 1590 */ 104, 218, 218, 218, 108, 218, 110, + /* 0 */ 21, 9, 23, 70, 71, 72, 73, 74, 75, 76, + /* 10 */ 77, 78, 79, 80, 81, 82, 83, 9, 140, 140, + /* 20 */ 41, 132, 133, 134, 135, 46, 74, 75, 76, 77, + /* 30 */ 78, 79, 80, 81, 82, 83, 158, 158, 138, 60, + /* 40 */ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + /* 50 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + /* 60 */ 81, 82, 83, 19, 90, 21, 87, 41, 94, 95, + /* 70 */ 96, 192, 46, 80, 81, 82, 83, 19, 174, 105, + /* 80 */ 19, 23, 204, 62, 23, 181, 60, 61, 62, 63, + /* 90 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + /* 100 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + /* 110 */ 52, 90, 91, 0, 93, 94, 95, 96, 97, 98, + /* 120 */ 62, 23, 9, 10, 9, 104, 20, 12, 22, 78, + /* 130 */ 79, 80, 81, 82, 83, 41, 78, 79, 80, 12, + /* 140 */ 46, 78, 79, 23, 86, 87, 88, 89, 87, 88, + /* 150 */ 92, 93, 89, 127, 60, 61, 62, 63, 64, 65, + /* 160 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 170 */ 76, 77, 78, 79, 80, 81, 82, 83, 14, 9, + /* 180 */ 10, 62, 15, 125, 126, 87, 88, 140, 90, 134, + /* 190 */ 135, 24, 94, 95, 96, 23, 90, 9, 78, 79, + /* 200 */ 94, 95, 96, 105, 11, 41, 39, 87, 88, 42, + /* 210 */ 46, 105, 93, 94, 95, 96, 97, 98, 17, 99, + /* 220 */ 53, 139, 128, 104, 60, 61, 62, 63, 64, 65, + /* 230 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 240 */ 76, 77, 78, 79, 80, 81, 82, 83, 9, 19, + /* 250 */ 78, 79, 41, 23, 207, 208, 209, 46, 57, 87, + /* 260 */ 59, 89, 140, 19, 92, 93, 144, 23, 152, 147, + /* 270 */ 148, 60, 61, 62, 63, 64, 65, 66, 67, 68, + /* 280 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, + /* 290 */ 79, 80, 81, 82, 83, 14, 52, 9, 182, 20, + /* 300 */ 20, 113, 140, 156, 20, 20, 62, 22, 161, 147, + /* 310 */ 148, 140, 20, 155, 156, 26, 200, 87, 88, 161, + /* 320 */ 127, 41, 78, 79, 93, 36, 46, 165, 166, 158, + /* 330 */ 86, 87, 88, 89, 53, 104, 92, 93, 9, 128, + /* 340 */ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + /* 350 */ 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + /* 360 */ 80, 81, 82, 83, 20, 194, 140, 183, 184, 125, + /* 370 */ 126, 127, 146, 88, 19, 204, 23, 140, 23, 31, + /* 380 */ 140, 100, 101, 102, 158, 41, 107, 99, 109, 110, + /* 390 */ 46, 107, 111, 109, 110, 158, 20, 171, 158, 107, + /* 400 */ 115, 109, 110, 170, 60, 61, 62, 63, 64, 65, + /* 410 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 420 */ 76, 77, 78, 79, 80, 81, 82, 83, 191, 192, + /* 430 */ 47, 23, 41, 80, 194, 140, 107, 46, 109, 110, + /* 440 */ 87, 88, 87, 88, 204, 62, 100, 101, 102, 11, + /* 450 */ 140, 60, 61, 62, 63, 64, 65, 66, 67, 68, + /* 460 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, + /* 470 */ 79, 80, 81, 82, 83, 140, 9, 23, 21, 41, + /* 480 */ 23, 9, 99, 107, 46, 109, 110, 104, 149, 9, + /* 490 */ 99, 152, 153, 158, 199, 87, 88, 146, 60, 61, + /* 500 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + /* 510 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, + /* 520 */ 82, 83, 171, 115, 23, 22, 41, 20, 9, 22, + /* 530 */ 19, 46, 9, 47, 183, 184, 201, 100, 101, 102, + /* 540 */ 189, 87, 88, 19, 87, 60, 61, 62, 63, 64, + /* 550 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + /* 560 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 115, + /* 570 */ 23, 14, 140, 41, 107, 34, 109, 110, 46, 107, + /* 580 */ 138, 109, 110, 22, 43, 99, 138, 107, 87, 109, + /* 590 */ 110, 88, 60, 61, 62, 63, 64, 65, 66, 67, + /* 600 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + /* 610 */ 78, 79, 80, 81, 82, 83, 25, 19, 115, 28, + /* 620 */ 41, 23, 9, 108, 113, 46, 107, 112, 109, 110, + /* 630 */ 107, 199, 109, 110, 87, 88, 45, 113, 22, 60, + /* 640 */ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + /* 650 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + /* 660 */ 81, 82, 83, 161, 162, 140, 50, 41, 9, 139, + /* 670 */ 168, 108, 46, 17, 111, 114, 91, 20, 93, 22, + /* 680 */ 138, 22, 142, 158, 127, 87, 129, 61, 62, 63, + /* 690 */ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + /* 700 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + /* 710 */ 140, 140, 9, 57, 41, 59, 140, 9, 145, 46, + /* 720 */ 143, 20, 20, 22, 22, 49, 23, 19, 158, 158, + /* 730 */ 200, 18, 9, 29, 158, 62, 63, 64, 65, 66, + /* 740 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + /* 750 */ 77, 78, 79, 80, 81, 82, 83, 11, 54, 13, + /* 760 */ 14, 15, 16, 19, 55, 56, 99, 23, 15, 198, + /* 770 */ 9, 63, 152, 27, 9, 99, 140, 24, 32, 136, + /* 780 */ 137, 122, 205, 37, 141, 152, 130, 140, 211, 146, + /* 790 */ 87, 88, 39, 146, 146, 42, 52, 51, 140, 53, + /* 800 */ 140, 9, 182, 167, 58, 158, 62, 103, 95, 89, + /* 810 */ 89, 140, 92, 92, 171, 182, 19, 9, 171, 171, + /* 820 */ 23, 89, 78, 79, 92, 167, 20, 167, 22, 158, + /* 830 */ 86, 87, 88, 89, 20, 41, 92, 93, 60, 196, + /* 840 */ 46, 194, 206, 130, 196, 140, 100, 101, 102, 52, + /* 850 */ 140, 204, 106, 146, 140, 111, 146, 111, 139, 62, + /* 860 */ 212, 150, 68, 69, 206, 217, 206, 19, 158, 125, + /* 870 */ 126, 23, 167, 48, 140, 78, 79, 80, 171, 140, + /* 880 */ 140, 171, 139, 86, 87, 88, 89, 93, 140, 92, + /* 890 */ 93, 140, 158, 146, 140, 140, 19, 140, 140, 140, + /* 900 */ 52, 123, 140, 196, 194, 44, 167, 167, 116, 158, + /* 910 */ 62, 206, 158, 158, 204, 158, 158, 158, 171, 212, + /* 920 */ 158, 140, 125, 126, 217, 140, 78, 79, 62, 140, + /* 930 */ 140, 140, 198, 140, 86, 87, 88, 89, 140, 158, + /* 940 */ 92, 93, 22, 158, 140, 206, 206, 158, 158, 158, + /* 950 */ 9, 158, 140, 20, 206, 22, 158, 140, 9, 93, + /* 960 */ 140, 140, 158, 140, 140, 20, 140, 22, 140, 140, + /* 970 */ 158, 140, 140, 125, 126, 158, 140, 140, 158, 158, + /* 980 */ 140, 158, 158, 140, 158, 140, 158, 140, 146, 158, + /* 990 */ 158, 140, 140, 140, 158, 158, 140, 20, 158, 22, + /* 1000 */ 20, 158, 22, 158, 20, 158, 22, 140, 140, 158, + /* 1010 */ 158, 158, 140, 171, 158, 20, 20, 22, 22, 99, + /* 1020 */ 140, 111, 146, 111, 195, 158, 158, 20, 140, 22, + /* 1030 */ 158, 103, 146, 20, 124, 22, 124, 164, 158, 113, + /* 1040 */ 114, 113, 157, 139, 139, 113, 172, 171, 113, 111, + /* 1050 */ 171, 173, 122, 119, 117, 180, 175, 171, 176, 120, + /* 1060 */ 177, 121, 178, 122, 89, 116, 179, 154, 89, 154, + /* 1070 */ 154, 118, 22, 151, 98, 157, 23, 113, 113, 93, + /* 1080 */ 83, 111, 193, 195, 140, 111, 140, 140, 127, 111, + /* 1090 */ 200, 200, 14, 19, 202, 20, 203, 140, 22, 20, + /* 1100 */ 140, 20, 22, 140, 22, 20, 113, 186, 140, 140, + /* 1110 */ 186, 157, 193, 22, 185, 115, 118, 186, 99, 116, + /* 1120 */ 19, 140, 140, 140, 188, 140, 20, 113, 157, 187, + /* 1130 */ 187, 20, 140, 139, 19, 162, 188, 20, 166, 140, + /* 1140 */ 48, 19, 19, 48, 19, 97, 159, 104, 160, 140, + /* 1150 */ 139, 139, 163, 163, 163, 151, 154, 152, 140, 21, + /* 1160 */ 154, 140, 140, 140, 213, 164, 214, 99, 140, 159, + /* 1170 */ 40, 215, 11, 38, 166, 160, 99, 140, 216, 130, + /* 1180 */ 49, 140, 99, 99, 140, 19, 139, 9, 130, 169, + /* 1190 */ 11, 14, 123, 123, 170, 9, 9, 14, 169, 60, + /* 1200 */ 140, 103, 186, 186, 140, 63, 176, 9, 63, 123, + /* 1210 */ 19, 140, 19, 9, 114, 176, 9, 9, 9, 186, + /* 1220 */ 9, 186, 197, 9, 114, 9, 186, 140, 140, 140, + /* 1230 */ 140, 176, 169, 140, 140, 103, 140, 186, 176, 9, + /* 1240 */ 186, 123, 140, 197, 19, 9, 87, 140, 114, 140, + /* 1250 */ 35, 186, 9, 140, 9, 152, 9, 9, 9, 9, + /* 1260 */ 9, 9, 210, 9, 9, 9, 169, 210, 140, 140, + /* 1270 */ 33, 152, 9, 20, 218, 9, 152, 218, 21, 9, + /* 1280 */ 219, 140, }; -#define YY_SHIFT_USE_DFLT (-86) +#define YY_SHIFT_USE_DFLT (-68) static short yy_shift_ofst[] = { - /* 0 */ 150, 156, -86, 757, -69, -86, -46, 127, -85, 157, - /* 10 */ 253, 42, -86, -86, -86, -86, -86, -86, 282, -86, - /* 20 */ -86, -86, -86, 193, 294, 193, 391, 193, 634, 85, - /* 30 */ 656, 282, 118, 450, 657, 0, -86, 83, -86, -3, - /* 40 */ -86, 282, 119, -86, 664, -86, -10, 664, -86, 703, - /* 50 */ -86, 385, -86, -86, 697, 479, 664, -86, -86, -86, - /* 60 */ 664, -86, 696, 1410, 309, 51, 737, 739, 159, -86, - /* 70 */ 182, 678, -86, 463, -86, 318, 662, 740, 746, 713, - /* 80 */ 730, -86, -37, -86, 742, -86, 745, -86, 466, -37, - /* 90 */ -86, -37, -86, 803, 1410, 797, 1410, 802, 479, -86, - /* 100 */ 773, -86, -86, 941, 1410, -86, 799, 282, 804, 282, - /* 110 */ -86, -86, -86, -86, 1336, 1410, 1259, 1410, 347, 1410, - /* 120 */ 347, 1410, 347, 1410, 347, 1410, 1486, 1410, 1486, 1410, - /* 130 */ 137, 1410, 137, 1410, 137, 1410, 137, 1410, 1486, 46, - /* 140 */ 1410, 1486, -86, -86, 1410, 102, 1410, 102, 1410, 825, - /* 150 */ 1410, 825, 1410, 825, 1410, -86, -86, 492, -86, 766, - /* 160 */ -86, -86, 1410, 1047, 1410, 1486, 776, 159, 208, 513, - /* 170 */ 752, 754, 756, -86, 941, 1410, 1336, 1410, -86, 1410, - /* 180 */ -86, 1410, -86, 855, 103, 734, 110, 823, -86, 1410, - /* 190 */ 212, 1410, 941, 788, 181, 767, -86, 847, 282, 770, - /* 200 */ -86, 852, 282, 774, -86, 854, 282, 775, -86, 1410, - /* 210 */ 321, 1410, 427, 1410, 941, 544, -86, 1410, -86, -86, - /* 220 */ -86, 1410, 1153, 1410, 1336, 805, 159, 235, -86, 564, - /* 230 */ -86, 802, 479, -86, 1410, 941, 870, 1410, 864, 1410, - /* 240 */ 941, -86, -86, 335, -86, -86, -86, 200, -86, 217, - /* 250 */ -86, 820, -86, 265, 858, 4, -86, -86, 282, -86, - /* 260 */ -86, 811, 778, -86, 826, 282, 570, -86, 282, -86, - /* 270 */ 479, -86, -86, 1410, 941, 282, -86, 678, 248, 4, - /* 280 */ 811, 778, -86, 1392, -5, -86, -86, 874, 275, -86, - /* 290 */ -86, -86, -86, 536, -86, 588, -86, 819, -86, 640, - /* 300 */ 664, -86, 282, 848, -86, 225, -86, 282, -86, 136, - /* 310 */ 358, -86, 599, -86, -86, -86, -86, 358, -86, 358, - /* 320 */ -86, 282, 611, -86, -86, 773, -86, 703, -86, -86, - /* 330 */ 122, -86, -86, -86, 592, -86, -86, 594, -86, -86, - /* 340 */ -86, -86, 242, -37, 636, -86, -37, 833, -86, -86, - /* 350 */ -86, -86, 296, 104, -86, 282, -86, 881, 880, 282, - /* 360 */ 642, 664, -86, 882, 282, 648, 664, -86, 1410, 744, - /* 370 */ -86, 885, 883, 282, 649, 866, 282, 848, -86, -20, - /* 380 */ 939, -86, -86, -86, -86, -86, 678, 304, 332, 254, - /* 390 */ 282, -86, 282, 970, 678, 314, 282, 454, 410, 888, - /* 400 */ 282, 858, 933, 555, 975, 1410, 835, 948, 378, -86, - /* 410 */ -86, 900, 901, 590, 282, 614, 282, -86, -86, -86, - /* 420 */ -86, 906, -86, -86, 935, 282, 910, 282, 630, 924, - /* 430 */ 282, 654, -85, 899, 943, 998, -18, 317, 966, 904, - /* 440 */ 905, -18, 971, 925, 42, -86, 282, 913, 282, 394, - /* 450 */ 282, 983, 1410, 941, 923, 988, 1410, 941, 631, 967, - /* 460 */ 282, 957, 282, 670, -86, 601, 367, 962, 1410, 674, - /* 470 */ 1410, 941, 936, 941, 991, 282, 604, 940, 298, 282, - /* 480 */ 944, 282, 949, 282, 676, 951, 282, 676, 958, 408, - /* 490 */ 1011, 282, 858, 604, 961, 925, 282, 663, 968, 282, - /* 500 */ 394, 963, 1004, 282, 858, 957, 627, 416, 1001, 1410, - /* 510 */ 706, 976, 631, 1013, 1014, 925, 282, 707, 1033, 282, - /* 520 */ 655, 1051, 979, 987, 194, 990, 83, 451, -51, 992, - /* 530 */ 993, 994, 997, 698, 999, 1000, 1002, 698, 1005, -86, - /* 540 */ 282, 1009, 1007, 1084, 83, 1110, 282, 1016, -86, 1084, - /* 550 */ 282, 1019, -86, -86, -86, + /* 0 */ 170, 113, -68, 746, -8, -68, 8, 127, 288, 239, + /* 10 */ 348, 167, -68, -68, -68, -68, -68, -68, 547, -68, + /* 20 */ -68, -68, -68, 115, 613, 115, 723, 115, 761, 44, + /* 30 */ 765, 547, 507, 814, 808, 98, -68, 501, -68, 21, + /* 40 */ -68, 547, 119, -68, 667, -68, 231, 667, -68, 861, + /* 50 */ -68, 541, -68, -68, 825, 289, 667, -68, -68, -68, + /* 60 */ 667, -68, 877, 848, 511, 58, 932, 935, 744, -68, + /* 70 */ 279, 938, -68, 515, -68, 561, 930, 934, 939, 937, + /* 80 */ 940, -68, 63, -68, 975, -68, 979, -68, 616, 63, + /* 90 */ -68, 63, -68, 953, 848, 1050, 848, 976, 289, -68, + /* 100 */ 1053, -68, -68, 485, 848, -68, 964, 547, 965, 547, + /* 110 */ -68, -68, -68, -68, 673, 848, 626, 848, -48, 848, + /* 120 */ -48, 848, -48, 848, -48, 848, -67, 848, -67, 848, + /* 130 */ 51, 848, 51, 848, 51, 848, 51, 848, -67, 794, + /* 140 */ 848, -67, -68, -68, 848, -7, 848, -7, 848, 997, + /* 150 */ 848, 997, 848, 997, 848, -68, -68, 866, -68, 986, + /* 160 */ -68, -68, 848, 532, 848, -67, 61, 744, 284, 563, + /* 170 */ 970, 974, 978, -68, 485, 848, 673, 848, -68, 848, + /* 180 */ -68, 848, -68, 244, 26, 961, 557, 1078, -68, 848, + /* 190 */ 94, 848, 485, 1074, 753, 1075, -68, 1076, 547, 1079, + /* 200 */ -68, 1080, 547, 1081, -68, 1082, 547, 1085, -68, 848, + /* 210 */ 164, 848, 211, 848, 485, 657, -68, 848, -68, -68, + /* 220 */ 993, 547, -68, -68, -68, 848, 579, 848, 673, 230, + /* 230 */ 744, 292, -68, 701, -68, 993, -68, 976, 289, -68, + /* 240 */ 848, 485, 998, 848, 1091, 848, 485, -68, -68, 503, + /* 250 */ -68, -68, -68, 408, -68, 454, -68, 1000, -68, 355, + /* 260 */ 993, 457, -68, -68, 547, -68, -68, 1019, 1003, -68, + /* 270 */ 1101, 547, 702, -68, 547, -68, 289, -68, -68, 848, + /* 280 */ 485, 938, 376, 285, 1106, 457, 1019, 1003, -68, 797, + /* 290 */ -21, -68, -68, 1014, 353, -68, -68, -68, -68, 280, + /* 300 */ -68, 806, -68, 1111, -68, 344, 667, -68, 547, 1115, + /* 310 */ -68, 486, -68, 547, -68, 346, 704, -68, 585, -68, + /* 320 */ -68, -68, -68, 704, -68, 704, -68, 547, 933, -68, + /* 330 */ -68, 1053, -68, 861, -68, -68, 172, -68, -68, -68, + /* 340 */ 720, -68, -68, 721, -68, -68, -68, -68, 598, 63, + /* 350 */ 945, -68, 63, 1117, -68, -68, -68, -68, 106, -26, + /* 360 */ -68, 547, -68, 1092, 1122, 547, 977, 667, -68, 1123, + /* 370 */ 547, 980, 667, -68, 848, 391, -68, 1095, 1125, 547, + /* 380 */ 984, 1048, 547, 1115, -68, 383, 1043, -68, -68, -68, + /* 390 */ -68, -68, 938, 329, 713, 201, 547, -68, 547, 1138, + /* 400 */ 938, 467, 547, 591, 437, 1068, 547, 993, 1130, 193, + /* 410 */ 1161, 848, 438, 1135, 709, -68, -68, 1077, 1083, 676, + /* 420 */ 547, 920, 547, -68, -68, -68, -68, 1131, -68, -68, + /* 430 */ 1049, 547, 1084, 547, 524, 1166, 547, 995, 288, 1178, + /* 440 */ 1058, 1179, 281, 472, 778, 167, -68, 1069, 1070, 1177, + /* 450 */ 1186, 1187, 281, 1183, 1139, 547, 1098, 547, 659, 547, + /* 460 */ 1142, 848, 485, 1198, 1145, 848, 485, 1086, 547, 1191, + /* 470 */ 547, 996, -68, 910, 480, 1193, 848, 1007, 848, 485, + /* 480 */ 1204, 485, 1100, 547, 941, 1207, 656, 547, 1208, 547, + /* 490 */ 1209, 547, 188, 1211, 547, 188, 1214, 519, 1110, 547, + /* 500 */ 993, 941, 1216, 1139, 547, 928, 1132, 547, 659, 1230, + /* 510 */ 1118, 547, 993, 1191, 912, 523, 1225, 848, 1013, 1236, + /* 520 */ 1139, 547, 926, 1134, 547, 792, 1215, 1159, 1243, 703, + /* 530 */ 1245, 501, 708, 120, 1247, 1248, 1249, 1250, 732, 1251, + /* 540 */ 1252, 1254, 732, 1255, -68, 547, 1253, 1256, 1237, 501, + /* 550 */ 1257, 547, 949, 1263, 501, 1266, -68, 1237, 547, 1270, + /* 560 */ -68, -68, -68, }; -#define YY_REDUCE_USE_DFLT (-156) +#define YY_REDUCE_USE_DFLT (-123) static short yy_reduce_ofst[] = { - /* 0 */ -101, -143, -156, 140, -156, -156, -156, -121, -73, -156, - /* 10 */ -156, 144, -156, -156, -156, -156, -156, -156, 184, -156, - /* 20 */ -156, -156, -156, 189, -156, 269, -156, 369, -156, 375, - /* 30 */ -156, -108, 591, -156, -156, -98, -156, 177, 603, -118, - /* 40 */ -156, 561, 8, -156, 576, -156, -156, 580, -156, 602, - /* 50 */ -156, -156, -156, -156, -156, 572, 596, -156, -156, -156, - /* 60 */ 600, -156, -156, 79, -156, 10, -156, -156, -31, -156, - /* 70 */ 607, 605, -156, 635, 276, 632, 578, 641, 639, 619, - /* 80 */ 633, -156, 613, -156, -156, -156, -156, -156, -156, 615, - /* 90 */ -156, 618, -156, -156, -8, -156, -68, 685, 629, -156, - /* 100 */ 669, -156, -156, 659, 222, -156, -156, 658, -156, 660, - /* 110 */ -156, -156, -156, -156, 659, 348, 659, 370, 659, 377, - /* 120 */ 659, 381, 659, 382, 659, 386, 659, 387, 659, 388, - /* 130 */ 659, 389, 659, 392, 659, 395, 659, 397, 659, 667, - /* 140 */ 399, 659, -156, -156, 402, 659, 403, 659, 407, 659, - /* 150 */ 414, 659, 415, 659, 417, 659, -156, -156, -156, -156, - /* 160 */ -156, -156, 425, 659, 428, 659, -156, -155, 607, -156, - /* 170 */ -156, -156, -156, -156, 659, 430, 659, 443, 659, 444, - /* 180 */ 659, 445, 659, 41, 659, 729, 731, -156, -156, 447, - /* 190 */ 659, 457, 659, -156, -156, -156, -156, -156, 690, -156, - /* 200 */ -156, -156, 694, -156, -156, -156, 700, -156, -156, 474, - /* 210 */ 659, 475, 659, 478, 659, -156, -156, 285, -156, -156, - /* 220 */ -156, 480, 659, 485, 659, -156, -61, 607, -156, -156, - /* 230 */ -156, 747, 681, -156, 491, 659, -156, 91, -156, 493, - /* 240 */ 659, -156, 400, 712, -156, -156, -156, 710, -156, 714, - /* 250 */ -156, -156, -156, 715, 749, 458, -156, -156, 719, -156, - /* 260 */ -156, 711, 688, -156, -156, 283, -156, -156, 267, -156, - /* 270 */ 708, -156, -156, 496, 659, 727, -156, 409, 607, 484, - /* 280 */ 726, 702, -156, 500, 54, -156, -156, -156, 658, -156, - /* 290 */ -156, -156, -156, 659, -156, -156, -156, -156, -156, 659, - /* 300 */ 741, -156, 743, 762, 755, 750, -156, 751, -156, -156, - /* 310 */ 759, -156, -156, -156, -156, -156, -156, 760, -156, 764, - /* 320 */ -156, 293, -156, -156, -156, 771, -156, 768, -156, -156, - /* 330 */ -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, - /* 340 */ -156, -156, 779, 732, -156, -156, 758, -156, -156, -156, - /* 350 */ -156, -156, 761, 765, -156, 777, -156, -156, -156, 302, - /* 360 */ -156, 780, -156, -156, 312, -156, 784, -156, 506, 251, - /* 370 */ -156, -156, -156, 325, -156, -156, 789, 806, 781, 270, - /* 380 */ -156, -156, -156, -156, -156, -156, 483, 607, 56, -156, - /* 390 */ 791, -156, 794, -156, 497, 607, 796, 769, 782, -156, - /* 400 */ 798, 831, 827, 772, -156, 518, 659, -156, -156, -156, - /* 410 */ -156, -156, -156, -156, 517, -156, 812, -156, -156, -156, - /* 420 */ -156, -156, -156, -156, -156, 816, -156, 821, 851, -156, - /* 430 */ 328, -156, 822, -156, -156, -156, 123, 607, -156, -156, - /* 440 */ -156, 173, -156, 829, 830, -156, 838, -156, -52, 813, - /* 450 */ 850, -156, 526, 659, -156, -156, 532, 659, 849, -156, - /* 460 */ 857, 868, 519, -156, -156, 523, 607, -156, 345, -156, - /* 470 */ 548, 659, -156, 659, -156, 863, 836, -156, -156, 867, - /* 480 */ -156, 873, -156, 875, 897, -156, 879, 912, -156, 607, - /* 490 */ -156, 884, 916, 853, -156, 887, 890, 918, -156, 537, - /* 500 */ 859, -156, -156, 896, 928, 907, 545, 607, -156, 359, - /* 510 */ -156, -156, 895, -156, -156, 902, 908, 937, -156, 909, - /* 520 */ -156, -156, -156, -156, 914, -156, 929, -156, 164, -156, - /* 530 */ -156, -156, -156, 915, -156, -156, -156, 927, -156, -156, - /* 540 */ 926, -156, -156, 972, 950, -156, 945, -156, -156, 980, - /* 550 */ 953, -156, -156, -156, -156, + /* 0 */ -111, 55, -123, 643, -123, -123, -123, -100, 82, -123, + /* 10 */ -123, 233, -123, -123, -123, -123, -123, -123, 310, -123, + /* 20 */ -123, -123, -123, 442, -123, 448, -123, 542, -123, 540, + /* 30 */ -123, 122, 573, -123, -123, 162, -123, 339, 711, 158, + /* 40 */ -123, 714, 147, -123, 719, -123, -123, 743, -123, 873, + /* 50 */ -123, -123, -123, -123, -123, 885, 904, -123, -123, -123, + /* 60 */ 905, -123, -123, 525, -123, 171, -123, -123, 226, -123, + /* 70 */ 874, 879, -123, 878, -96, 881, 882, 883, 884, 887, + /* 80 */ 875, -123, 913, -123, -123, -123, -123, -123, -123, 915, + /* 90 */ -123, 916, -123, -123, 237, -123, -121, 889, 918, -123, + /* 100 */ 922, -123, -123, 890, 570, -123, -123, 944, -123, 946, + /* 110 */ -123, -123, -123, -123, 890, 576, 890, 671, 890, 751, + /* 120 */ 890, 754, 890, 755, 890, 757, 890, 758, 890, 759, + /* 130 */ 890, 762, 890, 781, 890, 785, 890, 789, 890, 891, + /* 140 */ 790, 890, -123, -123, 791, 890, 793, 890, 798, 890, + /* 150 */ 804, 890, 812, 890, 817, 890, -123, -123, -123, -123, + /* 160 */ -123, -123, 820, 890, 821, 890, 947, 647, 874, -123, + /* 170 */ -123, -123, -123, -123, 890, 823, 890, 824, 890, 826, + /* 180 */ 890, 828, 890, 335, 890, 892, 893, -123, -123, 831, + /* 190 */ 890, 832, 890, -123, -123, -123, -123, -123, 957, -123, + /* 200 */ -123, -123, 960, -123, -123, -123, 963, -123, -123, 836, + /* 210 */ 890, 837, 890, 840, 890, -123, -123, -122, -123, -123, + /* 220 */ 921, 968, -123, -123, -123, 843, 890, 845, 890, 969, + /* 230 */ 710, 874, -123, -123, -123, 924, -123, 919, 954, -123, + /* 240 */ 847, 890, -123, 240, -123, 851, 890, -123, 184, 929, + /* 250 */ -123, -123, -123, 981, -123, 982, -123, -123, -123, 983, + /* 260 */ 931, 620, -123, -123, 985, -123, -123, 942, 936, -123, + /* 270 */ -123, 636, -123, -123, 748, -123, 971, -123, -123, 852, + /* 280 */ 890, 351, 874, 929, -123, 633, 943, 948, -123, 853, + /* 290 */ 116, -123, -123, -123, 944, -123, -123, -123, -123, 890, + /* 300 */ -123, -123, -123, -123, -123, 890, 994, -123, 992, 987, + /* 310 */ 988, 973, -123, 999, -123, -123, 989, -123, -123, -123, + /* 320 */ -123, -123, -123, 990, -123, 991, -123, 658, -123, -123, + /* 330 */ -123, 1004, -123, 1001, -123, -123, -123, -123, -123, -123, + /* 340 */ -123, -123, -123, -123, -123, -123, -123, -123, 1005, 1002, + /* 350 */ -123, -123, 1006, -123, -123, -123, -123, -123, 972, 1008, + /* 360 */ -123, 1009, -123, -123, -123, 660, -123, 1011, -123, -123, + /* 370 */ 705, -123, 1012, -123, 856, 530, -123, -123, -123, 739, + /* 380 */ -123, -123, 1018, 1010, 1015, 502, -123, -123, -123, -123, + /* 390 */ -123, -123, 747, 874, 577, -123, 1021, -123, 1022, -123, + /* 400 */ 842, 874, 1023, 951, 952, -123, 1028, 1016, 956, 962, + /* 410 */ -123, 867, 890, -123, -123, -123, -123, -123, -123, -123, + /* 420 */ 295, -123, 1037, -123, -123, -123, -123, -123, -123, -123, + /* 430 */ -123, 1041, -123, 1044, 1017, -123, 740, -123, 1047, -123, + /* 440 */ -123, -123, 648, 874, 1020, 1024, -123, -123, -123, -123, + /* 450 */ -123, -123, 707, -123, 1029, 1060, -123, 829, 1030, 1064, + /* 460 */ -123, 868, 890, -123, -123, 872, 890, -123, 1071, 1025, + /* 470 */ 432, -123, -123, 876, 874, -123, 571, -123, 880, 890, + /* 480 */ -123, 890, -123, 1087, 1039, -123, -123, 1088, -123, 1089, + /* 490 */ -123, 1090, 1033, -123, 1093, 1035, -123, 874, -123, 1094, + /* 500 */ 1040, 1055, -123, 1063, 1096, 1051, -123, 888, 1062, -123, + /* 510 */ -123, 1102, 1054, 1046, 886, 874, -123, 734, -123, -123, + /* 520 */ 1097, 1107, 1065, -123, 1109, -123, -123, -123, -123, 1113, + /* 530 */ -123, 1103, -123, 47, -123, -123, -123, -123, 1052, -123, + /* 540 */ -123, -123, 1057, -123, -123, 1128, -123, -123, 1056, 1119, + /* 550 */ -123, 1129, 1061, -123, 1124, -123, -123, 1059, 1141, -123, + /* 560 */ -123, -123, -123, }; static YYACTIONTYPE yy_default[] = { - /* 0 */ 562, 562, 557, 842, 842, 558, 842, 564, 842, 842, - /* 10 */ 842, 842, 644, 647, 648, 649, 650, 651, 565, 566, - /* 20 */ 583, 584, 585, 842, 842, 842, 842, 842, 842, 842, - /* 30 */ 842, 842, 842, 842, 842, 842, 576, 586, 596, 578, - /* 40 */ 595, 842, 842, 597, 643, 608, 842, 643, 609, 628, - /* 50 */ 626, 842, 629, 630, 842, 698, 643, 610, 696, 697, - /* 60 */ 643, 611, 842, 842, 727, 785, 733, 728, 842, 656, - /* 70 */ 842, 842, 657, 665, 667, 674, 710, 701, 703, 691, - /* 80 */ 705, 662, 842, 592, 842, 593, 842, 594, 706, 842, - /* 90 */ 707, 842, 708, 842, 842, 692, 842, 699, 698, 693, - /* 100 */ 842, 580, 700, 695, 842, 726, 842, 842, 729, 842, - /* 110 */ 730, 731, 732, 734, 737, 842, 738, 842, 739, 842, - /* 120 */ 740, 842, 741, 842, 742, 842, 743, 842, 744, 842, - /* 130 */ 745, 842, 746, 842, 747, 842, 748, 842, 749, 842, - /* 140 */ 842, 750, 751, 752, 842, 753, 842, 754, 842, 755, - /* 150 */ 842, 756, 842, 757, 842, 758, 759, 842, 760, 842, - /* 160 */ 763, 761, 842, 842, 842, 769, 842, 785, 842, 842, - /* 170 */ 842, 842, 842, 772, 784, 842, 764, 842, 765, 842, - /* 180 */ 766, 842, 767, 842, 842, 842, 842, 842, 775, 842, - /* 190 */ 842, 842, 776, 842, 842, 842, 833, 842, 842, 842, - /* 200 */ 834, 842, 842, 842, 835, 842, 842, 842, 836, 842, - /* 210 */ 842, 842, 842, 842, 777, 842, 771, 785, 782, 783, - /* 220 */ 762, 842, 842, 842, 770, 842, 785, 842, 774, 842, - /* 230 */ 773, 699, 698, 694, 842, 704, 842, 785, 702, 842, - /* 240 */ 711, 666, 677, 675, 676, 682, 683, 842, 684, 842, - /* 250 */ 685, 842, 686, 842, 680, 673, 581, 582, 842, 671, - /* 260 */ 672, 688, 690, 678, 842, 842, 842, 689, 842, 791, - /* 270 */ 698, 793, 792, 842, 687, 842, 681, 842, 842, 673, - /* 280 */ 688, 690, 679, 842, 673, 668, 669, 842, 842, 670, - /* 290 */ 663, 664, 768, 842, 725, 842, 735, 842, 736, 842, - /* 300 */ 643, 612, 842, 789, 616, 613, 617, 842, 618, 842, - /* 310 */ 842, 619, 842, 622, 623, 624, 625, 842, 620, 842, - /* 320 */ 621, 842, 842, 790, 614, 842, 615, 628, 627, 598, - /* 330 */ 842, 599, 600, 601, 842, 602, 605, 842, 603, 606, - /* 340 */ 604, 607, 587, 842, 842, 588, 842, 842, 589, 591, - /* 350 */ 590, 579, 842, 842, 633, 842, 636, 842, 842, 842, - /* 360 */ 842, 643, 637, 842, 842, 842, 643, 638, 842, 643, - /* 370 */ 639, 842, 842, 842, 842, 842, 842, 789, 616, 641, - /* 380 */ 842, 640, 642, 634, 635, 577, 842, 842, 573, 842, - /* 390 */ 842, 571, 842, 842, 842, 842, 842, 816, 842, 842, - /* 400 */ 842, 680, 821, 842, 842, 842, 842, 842, 842, 822, - /* 410 */ 823, 842, 842, 842, 842, 842, 842, 723, 724, 813, - /* 420 */ 814, 842, 815, 572, 842, 842, 842, 842, 842, 842, - /* 430 */ 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - /* 440 */ 842, 842, 842, 645, 842, 646, 842, 842, 842, 842, - /* 450 */ 842, 842, 842, 713, 842, 842, 842, 714, 842, 842, - /* 460 */ 842, 721, 842, 842, 722, 842, 842, 842, 842, 842, - /* 470 */ 842, 719, 842, 720, 842, 842, 842, 842, 842, 842, - /* 480 */ 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - /* 490 */ 842, 842, 680, 842, 842, 645, 842, 842, 842, 842, - /* 500 */ 842, 842, 842, 842, 680, 721, 842, 842, 842, 842, - /* 510 */ 842, 842, 842, 842, 842, 645, 842, 842, 842, 842, - /* 520 */ 842, 842, 842, 842, 842, 842, 842, 842, 810, 842, - /* 530 */ 842, 842, 842, 842, 842, 842, 842, 842, 842, 809, - /* 540 */ 842, 842, 842, 840, 842, 842, 842, 842, 839, 840, - /* 550 */ 842, 842, 559, 561, 556, + /* 0 */ 570, 570, 564, 856, 856, 566, 856, 572, 856, 856, + /* 10 */ 856, 856, 652, 655, 656, 657, 658, 659, 573, 574, + /* 20 */ 591, 592, 593, 856, 856, 856, 856, 856, 856, 856, + /* 30 */ 856, 856, 856, 856, 856, 856, 584, 594, 604, 586, + /* 40 */ 603, 856, 856, 605, 651, 616, 856, 651, 617, 636, + /* 50 */ 634, 856, 637, 638, 856, 708, 651, 618, 706, 707, + /* 60 */ 651, 619, 856, 856, 737, 797, 743, 738, 856, 664, + /* 70 */ 856, 856, 665, 673, 675, 682, 720, 711, 713, 701, + /* 80 */ 715, 670, 856, 600, 856, 601, 856, 602, 716, 856, + /* 90 */ 717, 856, 718, 856, 856, 702, 856, 709, 708, 703, + /* 100 */ 856, 588, 710, 705, 856, 736, 856, 856, 739, 856, + /* 110 */ 740, 741, 742, 744, 747, 856, 748, 856, 749, 856, + /* 120 */ 750, 856, 751, 856, 752, 856, 753, 856, 754, 856, + /* 130 */ 755, 856, 756, 856, 757, 856, 758, 856, 759, 856, + /* 140 */ 856, 760, 761, 762, 856, 763, 856, 764, 856, 765, + /* 150 */ 856, 766, 856, 767, 856, 768, 769, 856, 770, 856, + /* 160 */ 773, 771, 856, 856, 856, 779, 856, 797, 856, 856, + /* 170 */ 856, 856, 856, 782, 796, 856, 774, 856, 775, 856, + /* 180 */ 776, 856, 777, 856, 856, 856, 856, 856, 787, 856, + /* 190 */ 856, 856, 788, 856, 856, 856, 845, 856, 856, 856, + /* 200 */ 846, 856, 856, 856, 847, 856, 856, 856, 848, 856, + /* 210 */ 856, 856, 856, 856, 789, 856, 781, 797, 794, 795, + /* 220 */ 690, 856, 691, 785, 772, 856, 856, 856, 780, 856, + /* 230 */ 797, 856, 784, 856, 783, 690, 786, 709, 708, 704, + /* 240 */ 856, 714, 856, 797, 712, 856, 721, 674, 685, 683, + /* 250 */ 684, 692, 693, 856, 694, 856, 695, 856, 696, 856, + /* 260 */ 690, 681, 589, 590, 856, 679, 680, 698, 700, 686, + /* 270 */ 856, 856, 856, 699, 856, 803, 708, 805, 804, 856, + /* 280 */ 697, 685, 856, 856, 856, 681, 698, 700, 687, 856, + /* 290 */ 681, 676, 677, 856, 856, 678, 671, 672, 778, 856, + /* 300 */ 735, 856, 745, 856, 746, 856, 651, 620, 856, 801, + /* 310 */ 624, 621, 625, 856, 626, 856, 856, 627, 856, 630, + /* 320 */ 631, 632, 633, 856, 628, 856, 629, 856, 856, 802, + /* 330 */ 622, 856, 623, 636, 635, 606, 856, 607, 608, 609, + /* 340 */ 856, 610, 613, 856, 611, 614, 612, 615, 595, 856, + /* 350 */ 856, 596, 856, 856, 597, 599, 598, 587, 856, 856, + /* 360 */ 641, 856, 644, 856, 856, 856, 856, 651, 645, 856, + /* 370 */ 856, 856, 651, 646, 856, 651, 647, 856, 856, 856, + /* 380 */ 856, 856, 856, 801, 624, 649, 856, 648, 650, 642, + /* 390 */ 643, 585, 856, 856, 581, 856, 856, 579, 856, 856, + /* 400 */ 856, 856, 856, 828, 856, 856, 856, 690, 833, 856, + /* 410 */ 856, 856, 856, 856, 856, 834, 835, 856, 856, 856, + /* 420 */ 856, 856, 856, 733, 734, 825, 826, 856, 827, 580, + /* 430 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 440 */ 856, 856, 856, 856, 856, 856, 654, 856, 856, 856, + /* 450 */ 856, 856, 856, 856, 653, 856, 856, 856, 856, 856, + /* 460 */ 856, 856, 723, 856, 856, 856, 724, 856, 856, 731, + /* 470 */ 856, 856, 732, 856, 856, 856, 856, 856, 856, 729, + /* 480 */ 856, 730, 856, 856, 856, 856, 856, 856, 856, 856, + /* 490 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 500 */ 690, 856, 856, 653, 856, 856, 856, 856, 856, 856, + /* 510 */ 856, 856, 690, 731, 856, 856, 856, 856, 856, 856, + /* 520 */ 653, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 530 */ 856, 856, 856, 822, 856, 856, 856, 856, 856, 856, + /* 540 */ 856, 856, 856, 856, 821, 856, 856, 856, 854, 856, + /* 550 */ 856, 856, 856, 856, 856, 856, 853, 854, 856, 856, + /* 560 */ 567, 569, 565, }; #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) @@ -676,136 +617,136 @@ static YYACTIONTYPE yy_default[] = { #ifdef YYFALLBACK static const YYCODETYPE yyFallback[] = { 0, /* $ => nothing */ - 59, /* ABORT => ID */ - 59, /* AFTER => ID */ + 0, /* END_OF_FILE => nothing */ + 0, /* ILLEGAL => nothing */ + 0, /* SPACE => nothing */ + 0, /* UNCLOSED_STRING => nothing */ + 0, /* COMMENT => nothing */ + 0, /* FUNCTION => nothing */ + 0, /* COLUMN => nothing */ 0, /* AGG_FUNCTION => nothing */ - 0, /* ALL => nothing */ - 0, /* AND => nothing */ + 0, /* SEMI => nothing */ + 23, /* EXPLAIN => ID */ + 23, /* BEGIN => ID */ + 0, /* TRANSACTION => nothing */ + 0, /* COMMIT => nothing */ + 23, /* END => ID */ + 0, /* ROLLBACK => nothing */ + 0, /* CREATE => nothing */ + 0, /* TABLE => nothing */ + 23, /* TEMP => ID */ + 0, /* LP => nothing */ + 0, /* RP => nothing */ 0, /* AS => nothing */ - 59, /* ASC => ID */ - 59, /* ATTACH => ID */ - 59, /* BEFORE => ID */ - 59, /* BEGIN => ID */ + 0, /* COMMA => nothing */ + 0, /* ID => nothing */ + 23, /* ABORT => ID */ + 23, /* AFTER => ID */ + 23, /* ASC => ID */ + 23, /* ATTACH => ID */ + 23, /* BEFORE => ID */ + 23, /* CASCADE => ID */ + 23, /* CLUSTER => ID */ + 23, /* CONFLICT => ID */ + 23, /* COPY => ID */ + 23, /* DATABASE => ID */ + 23, /* DEFERRED => ID */ + 23, /* DELIMITERS => ID */ + 23, /* DESC => ID */ + 23, /* DETACH => ID */ + 23, /* EACH => ID */ + 23, /* FAIL => ID */ + 23, /* FOR => ID */ + 23, /* GLOB => ID */ + 23, /* IGNORE => ID */ + 23, /* IMMEDIATE => ID */ + 23, /* INITIALLY => ID */ + 23, /* INSTEAD => ID */ + 23, /* LIKE => ID */ + 23, /* MATCH => ID */ + 23, /* KEY => ID */ + 23, /* OF => ID */ + 23, /* OFFSET => ID */ + 23, /* PRAGMA => ID */ + 23, /* RAISE => ID */ + 23, /* REPLACE => ID */ + 23, /* RESTRICT => ID */ + 23, /* ROW => ID */ + 23, /* STATEMENT => ID */ + 23, /* TRIGGER => ID */ + 23, /* VACUUM => ID */ + 23, /* VIEW => ID */ + 0, /* OR => nothing */ + 0, /* AND => nothing */ + 0, /* NOT => nothing */ + 0, /* EQ => nothing */ + 0, /* NE => nothing */ + 0, /* ISNULL => nothing */ + 0, /* NOTNULL => nothing */ + 0, /* IS => nothing */ 0, /* BETWEEN => nothing */ + 0, /* IN => nothing */ + 0, /* GT => nothing */ + 0, /* GE => nothing */ + 0, /* LT => nothing */ + 0, /* LE => nothing */ 0, /* BITAND => nothing */ - 0, /* BITNOT => nothing */ 0, /* BITOR => nothing */ - 0, /* BY => nothing */ - 59, /* CASCADE => ID */ - 0, /* CASE => nothing */ - 0, /* CHECK => nothing */ - 59, /* CLUSTER => ID */ - 0, /* COLLATE => nothing */ - 0, /* COLUMN => nothing */ - 0, /* COMMA => nothing */ - 0, /* COMMENT => nothing */ - 0, /* COMMIT => nothing */ + 0, /* LSHIFT => nothing */ + 0, /* RSHIFT => nothing */ + 0, /* PLUS => nothing */ + 0, /* MINUS => nothing */ + 0, /* STAR => nothing */ + 0, /* SLASH => nothing */ + 0, /* REM => nothing */ 0, /* CONCAT => nothing */ - 59, /* CONFLICT => ID */ + 0, /* UMINUS => nothing */ + 0, /* UPLUS => nothing */ + 0, /* BITNOT => nothing */ + 0, /* STRING => nothing */ + 0, /* JOIN_KW => nothing */ + 0, /* INTEGER => nothing */ 0, /* CONSTRAINT => nothing */ - 59, /* COPY => ID */ - 0, /* CREATE => nothing */ - 59, /* DATABASE => ID */ 0, /* DEFAULT => nothing */ - 0, /* DEFERRABLE => nothing */ - 59, /* DEFERRED => ID */ - 0, /* DELETE => nothing */ - 59, /* DELIMITERS => ID */ - 59, /* DESC => ID */ - 59, /* DETACH => ID */ - 0, /* DISTINCT => nothing */ - 0, /* DOT => nothing */ - 0, /* DROP => nothing */ - 59, /* EACH => ID */ - 0, /* ELSE => nothing */ - 59, /* END => ID */ - 0, /* END_OF_FILE => nothing */ - 0, /* EQ => nothing */ - 0, /* EXCEPT => nothing */ - 59, /* EXPLAIN => ID */ - 59, /* FAIL => ID */ 0, /* FLOAT => nothing */ - 59, /* FOR => ID */ - 0, /* FOREIGN => nothing */ - 0, /* FROM => nothing */ - 0, /* FUNCTION => nothing */ - 0, /* GE => nothing */ - 59, /* GLOB => ID */ - 0, /* GROUP => nothing */ - 0, /* GT => nothing */ - 0, /* HAVING => nothing */ - 0, /* ID => nothing */ - 59, /* IGNORE => ID */ - 0, /* ILLEGAL => nothing */ - 59, /* IMMEDIATE => ID */ - 0, /* IN => nothing */ - 0, /* INDEX => nothing */ - 59, /* INITIALLY => ID */ - 0, /* INSERT => nothing */ - 59, /* INSTEAD => ID */ - 0, /* INTEGER => nothing */ - 0, /* INTERSECT => nothing */ - 0, /* INTO => nothing */ - 0, /* IS => nothing */ - 0, /* ISNULL => nothing */ - 0, /* JOIN => nothing */ - 0, /* JOIN_KW => nothing */ - 59, /* KEY => ID */ - 0, /* LE => nothing */ - 59, /* LIKE => ID */ - 0, /* LIMIT => nothing */ - 0, /* LP => nothing */ - 0, /* LSHIFT => nothing */ - 0, /* LT => nothing */ - 59, /* MATCH => ID */ - 0, /* MINUS => nothing */ - 0, /* NE => nothing */ - 0, /* NOT => nothing */ - 0, /* NOTNULL => nothing */ 0, /* NULL => nothing */ - 59, /* OF => ID */ - 59, /* OFFSET => ID */ - 0, /* ON => nothing */ - 0, /* OR => nothing */ - 0, /* ORDER => nothing */ - 0, /* PLUS => nothing */ - 59, /* PRAGMA => ID */ 0, /* PRIMARY => nothing */ - 59, /* RAISE => ID */ + 0, /* UNIQUE => nothing */ + 0, /* CHECK => nothing */ 0, /* REFERENCES => nothing */ - 0, /* REM => nothing */ - 59, /* REPLACE => ID */ - 59, /* RESTRICT => ID */ - 0, /* ROLLBACK => nothing */ - 59, /* ROW => ID */ - 0, /* RP => nothing */ - 0, /* RSHIFT => nothing */ - 0, /* SELECT => nothing */ - 0, /* SEMI => nothing */ + 0, /* COLLATE => nothing */ + 0, /* ON => nothing */ + 0, /* DELETE => nothing */ + 0, /* UPDATE => nothing */ + 0, /* INSERT => nothing */ 0, /* SET => nothing */ - 0, /* SLASH => nothing */ - 0, /* SPACE => nothing */ - 0, /* STAR => nothing */ - 59, /* STATEMENT => ID */ - 0, /* STRING => nothing */ - 0, /* TABLE => nothing */ - 59, /* TEMP => ID */ - 0, /* THEN => nothing */ - 0, /* TRANSACTION => nothing */ - 59, /* TRIGGER => ID */ - 0, /* UMINUS => nothing */ - 0, /* UNCLOSED_STRING => nothing */ + 0, /* DEFERRABLE => nothing */ + 0, /* FOREIGN => nothing */ + 0, /* DROP => nothing */ 0, /* UNION => nothing */ - 0, /* UNIQUE => nothing */ - 0, /* UPDATE => nothing */ - 0, /* UPLUS => nothing */ + 0, /* ALL => nothing */ + 0, /* INTERSECT => nothing */ + 0, /* EXCEPT => nothing */ + 0, /* SELECT => nothing */ + 0, /* DISTINCT => nothing */ + 0, /* DOT => nothing */ + 0, /* FROM => nothing */ + 0, /* JOIN => nothing */ 0, /* USING => nothing */ - 59, /* VACUUM => ID */ + 0, /* ORDER => nothing */ + 0, /* BY => nothing */ + 0, /* GROUP => nothing */ + 0, /* HAVING => nothing */ + 0, /* LIMIT => nothing */ + 0, /* WHERE => nothing */ + 0, /* INTO => nothing */ 0, /* VALUES => nothing */ 0, /* VARIABLE => nothing */ - 59, /* VIEW => ID */ + 0, /* CASE => nothing */ 0, /* WHEN => nothing */ - 0, /* WHERE => nothing */ + 0, /* THEN => nothing */ + 0, /* ELSE => nothing */ + 0, /* INDEX => nothing */ }; #endif /* YYFALLBACK */ @@ -876,61 +817,61 @@ void sqliteParserTrace(FILE *TraceFILE, char *zTracePrompt){ /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *yyTokenName[] = { - "$", "ABORT", "AFTER", "AGG_FUNCTION", - "ALL", "AND", "AS", "ASC", - "ATTACH", "BEFORE", "BEGIN", "BETWEEN", - "BITAND", "BITNOT", "BITOR", "BY", - "CASCADE", "CASE", "CHECK", "CLUSTER", - "COLLATE", "COLUMN", "COMMA", "COMMENT", - "COMMIT", "CONCAT", "CONFLICT", "CONSTRAINT", - "COPY", "CREATE", "DATABASE", "DEFAULT", - "DEFERRABLE", "DEFERRED", "DELETE", "DELIMITERS", - "DESC", "DETACH", "DISTINCT", "DOT", - "DROP", "EACH", "ELSE", "END", - "END_OF_FILE", "EQ", "EXCEPT", "EXPLAIN", - "FAIL", "FLOAT", "FOR", "FOREIGN", - "FROM", "FUNCTION", "GE", "GLOB", - "GROUP", "GT", "HAVING", "ID", - "IGNORE", "ILLEGAL", "IMMEDIATE", "IN", - "INDEX", "INITIALLY", "INSERT", "INSTEAD", - "INTEGER", "INTERSECT", "INTO", "IS", - "ISNULL", "JOIN", "JOIN_KW", "KEY", - "LE", "LIKE", "LIMIT", "LP", - "LSHIFT", "LT", "MATCH", "MINUS", - "NE", "NOT", "NOTNULL", "NULL", - "OF", "OFFSET", "ON", "OR", - "ORDER", "PLUS", "PRAGMA", "PRIMARY", - "RAISE", "REFERENCES", "REM", "REPLACE", - "RESTRICT", "ROLLBACK", "ROW", "RP", - "RSHIFT", "SELECT", "SEMI", "SET", - "SLASH", "SPACE", "STAR", "STATEMENT", - "STRING", "TABLE", "TEMP", "THEN", - "TRANSACTION", "TRIGGER", "UMINUS", "UNCLOSED_STRING", - "UNION", "UNIQUE", "UPDATE", "UPLUS", - "USING", "VACUUM", "VALUES", "VARIABLE", - "VIEW", "WHEN", "WHERE", "as", - "carg", "carglist", "case_else", "case_exprlist", - "case_operand", "ccons", "cmd", "cmdlist", - "cmdx", "collate", "column", "columnid", - "columnlist", "conslist", "conslist_opt", "create_table", - "create_table_args", "database_kw_opt", "dbnm", "defer_subclause", - "defer_subclause_opt", "distinct", "ecmd", "error", - "explain", "expr", "expritem", "exprlist", - "foreach_clause", "from", "groupby_opt", "having_opt", - "id", "ids", "idxitem", "idxlist", - "idxlist_opt", "init_deferred_pred_opt", "input", "inscollist", - "inscollist_opt", "insert_cmd", "itemlist", "joinop", - "joinop2", "likeop", "limit_opt", "minus_num", - "multiselect_op", "nm", "number", "on_opt", - "onconf", "oneselect", "orconf", "orderby_opt", - "plus_num", "plus_opt", "refact", "refarg", - "refargs", "resolvetype", "sclp", "selcollist", - "select", "seltablist", "setlist", "signed", - "sortitem", "sortlist", "sortorder", "stl_prefix", - "tcons", "temp", "trans_opt", "trigger_cmd", - "trigger_cmd_list", "trigger_decl", "trigger_event", "trigger_time", - "type", "typename", "uniqueflag", "using_opt", - "when_clause", "where_opt", + "$", "END_OF_FILE", "ILLEGAL", "SPACE", + "UNCLOSED_STRING", "COMMENT", "FUNCTION", "COLUMN", + "AGG_FUNCTION", "SEMI", "EXPLAIN", "BEGIN", + "TRANSACTION", "COMMIT", "END", "ROLLBACK", + "CREATE", "TABLE", "TEMP", "LP", + "RP", "AS", "COMMA", "ID", + "ABORT", "AFTER", "ASC", "ATTACH", + "BEFORE", "CASCADE", "CLUSTER", "CONFLICT", + "COPY", "DATABASE", "DEFERRED", "DELIMITERS", + "DESC", "DETACH", "EACH", "FAIL", + "FOR", "GLOB", "IGNORE", "IMMEDIATE", + "INITIALLY", "INSTEAD", "LIKE", "MATCH", + "KEY", "OF", "OFFSET", "PRAGMA", + "RAISE", "REPLACE", "RESTRICT", "ROW", + "STATEMENT", "TRIGGER", "VACUUM", "VIEW", + "OR", "AND", "NOT", "EQ", + "NE", "ISNULL", "NOTNULL", "IS", + "BETWEEN", "IN", "GT", "GE", + "LT", "LE", "BITAND", "BITOR", + "LSHIFT", "RSHIFT", "PLUS", "MINUS", + "STAR", "SLASH", "REM", "CONCAT", + "UMINUS", "UPLUS", "BITNOT", "STRING", + "JOIN_KW", "INTEGER", "CONSTRAINT", "DEFAULT", + "FLOAT", "NULL", "PRIMARY", "UNIQUE", + "CHECK", "REFERENCES", "COLLATE", "ON", + "DELETE", "UPDATE", "INSERT", "SET", + "DEFERRABLE", "FOREIGN", "DROP", "UNION", + "ALL", "INTERSECT", "EXCEPT", "SELECT", + "DISTINCT", "DOT", "FROM", "JOIN", + "USING", "ORDER", "BY", "GROUP", + "HAVING", "LIMIT", "WHERE", "INTO", + "VALUES", "VARIABLE", "CASE", "WHEN", + "THEN", "ELSE", "INDEX", "error", + "input", "cmdlist", "ecmd", "explain", + "cmdx", "cmd", "trans_opt", "onconf", + "nm", "create_table", "create_table_args", "temp", + "columnlist", "conslist_opt", "select", "column", + "columnid", "type", "carglist", "id", + "ids", "typename", "signed", "carg", + "ccons", "sortorder", "expr", "idxlist_opt", + "refargs", "defer_subclause", "refarg", "refact", + "init_deferred_pred_opt", "conslist", "tcons", "idxlist", + "defer_subclause_opt", "orconf", "resolvetype", "oneselect", + "multiselect_op", "distinct", "selcollist", "from", + "where_opt", "groupby_opt", "having_opt", "orderby_opt", + "limit_opt", "sclp", "as", "seltablist", + "stl_prefix", "joinop", "dbnm", "on_opt", + "using_opt", "seltablist_paren", "joinop2", "sortlist", + "sortitem", "collate", "exprlist", "setlist", + "insert_cmd", "inscollist_opt", "itemlist", "inscollist", + "likeop", "case_operand", "case_exprlist", "case_else", + "expritem", "uniqueflag", "idxitem", "plus_num", + "minus_num", "plus_opt", "number", "trigger_decl", + "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause", + "when_clause", "trigger_cmd", "database_kw_opt", "key_opt", }; #endif /* NDEBUG */ @@ -939,8 +880,8 @@ static const char *yyTokenName[] = { */ static const char *yyRuleName[] = { /* 0 */ "input ::= cmdlist", - /* 1 */ "cmdlist ::= ecmd", - /* 2 */ "cmdlist ::= cmdlist ecmd", + /* 1 */ "cmdlist ::= cmdlist ecmd", + /* 2 */ "cmdlist ::= ecmd", /* 3 */ "ecmd ::= explain cmdx SEMI", /* 4 */ "ecmd ::= SEMI", /* 5 */ "cmdx ::= cmd", @@ -1062,169 +1003,175 @@ static const char *yyRuleName[] = { /* 121 */ "stl_prefix ::= seltablist joinop", /* 122 */ "stl_prefix ::=", /* 123 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt", - /* 124 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt", - /* 125 */ "dbnm ::=", - /* 126 */ "dbnm ::= DOT nm", - /* 127 */ "joinop ::= COMMA", - /* 128 */ "joinop ::= JOIN", - /* 129 */ "joinop ::= JOIN_KW JOIN", - /* 130 */ "joinop ::= JOIN_KW nm JOIN", - /* 131 */ "joinop ::= JOIN_KW nm nm JOIN", - /* 132 */ "on_opt ::= ON expr", - /* 133 */ "on_opt ::=", - /* 134 */ "using_opt ::= USING LP idxlist RP", - /* 135 */ "using_opt ::=", - /* 136 */ "orderby_opt ::=", - /* 137 */ "orderby_opt ::= ORDER BY sortlist", - /* 138 */ "sortlist ::= sortlist COMMA sortitem collate sortorder", - /* 139 */ "sortlist ::= sortitem collate sortorder", - /* 140 */ "sortitem ::= expr", - /* 141 */ "sortorder ::= ASC", - /* 142 */ "sortorder ::= DESC", - /* 143 */ "sortorder ::=", - /* 144 */ "collate ::=", - /* 145 */ "collate ::= COLLATE id", - /* 146 */ "groupby_opt ::=", - /* 147 */ "groupby_opt ::= GROUP BY exprlist", - /* 148 */ "having_opt ::=", - /* 149 */ "having_opt ::= HAVING expr", - /* 150 */ "limit_opt ::=", - /* 151 */ "limit_opt ::= LIMIT signed", - /* 152 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 153 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 154 */ "cmd ::= DELETE FROM nm dbnm where_opt", - /* 155 */ "where_opt ::=", - /* 156 */ "where_opt ::= WHERE expr", - /* 157 */ "cmd ::= UPDATE orconf nm dbnm SET setlist where_opt", - /* 158 */ "setlist ::= setlist COMMA nm EQ expr", - /* 159 */ "setlist ::= nm EQ expr", - /* 160 */ "cmd ::= insert_cmd INTO nm dbnm inscollist_opt VALUES LP itemlist RP", - /* 161 */ "cmd ::= insert_cmd INTO nm dbnm inscollist_opt select", - /* 162 */ "insert_cmd ::= INSERT orconf", - /* 163 */ "insert_cmd ::= REPLACE", - /* 164 */ "itemlist ::= itemlist COMMA expr", - /* 165 */ "itemlist ::= expr", - /* 166 */ "inscollist_opt ::=", - /* 167 */ "inscollist_opt ::= LP inscollist RP", - /* 168 */ "inscollist ::= inscollist COMMA nm", - /* 169 */ "inscollist ::= nm", - /* 170 */ "expr ::= LP expr RP", - /* 171 */ "expr ::= NULL", - /* 172 */ "expr ::= ID", - /* 173 */ "expr ::= JOIN_KW", - /* 174 */ "expr ::= nm DOT nm", - /* 175 */ "expr ::= nm DOT nm DOT nm", - /* 176 */ "expr ::= INTEGER", - /* 177 */ "expr ::= FLOAT", - /* 178 */ "expr ::= STRING", - /* 179 */ "expr ::= VARIABLE", - /* 180 */ "expr ::= ID LP exprlist RP", - /* 181 */ "expr ::= ID LP STAR RP", - /* 182 */ "expr ::= expr AND expr", - /* 183 */ "expr ::= expr OR expr", - /* 184 */ "expr ::= expr LT expr", - /* 185 */ "expr ::= expr GT expr", - /* 186 */ "expr ::= expr LE expr", - /* 187 */ "expr ::= expr GE expr", - /* 188 */ "expr ::= expr NE expr", - /* 189 */ "expr ::= expr EQ expr", - /* 190 */ "expr ::= expr BITAND expr", - /* 191 */ "expr ::= expr BITOR expr", - /* 192 */ "expr ::= expr LSHIFT expr", - /* 193 */ "expr ::= expr RSHIFT expr", - /* 194 */ "expr ::= expr likeop expr", - /* 195 */ "expr ::= expr NOT likeop expr", - /* 196 */ "likeop ::= LIKE", - /* 197 */ "likeop ::= GLOB", - /* 198 */ "expr ::= expr PLUS expr", - /* 199 */ "expr ::= expr MINUS expr", - /* 200 */ "expr ::= expr STAR expr", - /* 201 */ "expr ::= expr SLASH expr", - /* 202 */ "expr ::= expr REM expr", - /* 203 */ "expr ::= expr CONCAT expr", - /* 204 */ "expr ::= expr ISNULL", - /* 205 */ "expr ::= expr IS NULL", - /* 206 */ "expr ::= expr NOTNULL", - /* 207 */ "expr ::= expr NOT NULL", - /* 208 */ "expr ::= expr IS NOT NULL", - /* 209 */ "expr ::= NOT expr", - /* 210 */ "expr ::= BITNOT expr", - /* 211 */ "expr ::= MINUS expr", - /* 212 */ "expr ::= PLUS expr", - /* 213 */ "expr ::= LP select RP", - /* 214 */ "expr ::= expr BETWEEN expr AND expr", - /* 215 */ "expr ::= expr NOT BETWEEN expr AND expr", - /* 216 */ "expr ::= expr IN LP exprlist RP", - /* 217 */ "expr ::= expr IN LP select RP", - /* 218 */ "expr ::= expr NOT IN LP exprlist RP", - /* 219 */ "expr ::= expr NOT IN LP select RP", - /* 220 */ "expr ::= CASE case_operand case_exprlist case_else END", - /* 221 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", - /* 222 */ "case_exprlist ::= WHEN expr THEN expr", - /* 223 */ "case_else ::= ELSE expr", - /* 224 */ "case_else ::=", - /* 225 */ "case_operand ::= expr", - /* 226 */ "case_operand ::=", - /* 227 */ "exprlist ::= exprlist COMMA expritem", - /* 228 */ "exprlist ::= expritem", - /* 229 */ "expritem ::= expr", - /* 230 */ "expritem ::=", - /* 231 */ "cmd ::= CREATE uniqueflag INDEX nm ON nm dbnm LP idxlist RP onconf", - /* 232 */ "uniqueflag ::= UNIQUE", - /* 233 */ "uniqueflag ::=", - /* 234 */ "idxlist_opt ::=", - /* 235 */ "idxlist_opt ::= LP idxlist RP", - /* 236 */ "idxlist ::= idxlist COMMA idxitem", - /* 237 */ "idxlist ::= idxitem", - /* 238 */ "idxitem ::= nm sortorder", - /* 239 */ "cmd ::= DROP INDEX nm dbnm", - /* 240 */ "cmd ::= COPY orconf nm dbnm FROM nm USING DELIMITERS STRING", - /* 241 */ "cmd ::= COPY orconf nm dbnm FROM nm", - /* 242 */ "cmd ::= VACUUM", - /* 243 */ "cmd ::= VACUUM nm", - /* 244 */ "cmd ::= PRAGMA ids EQ nm", - /* 245 */ "cmd ::= PRAGMA ids EQ ON", - /* 246 */ "cmd ::= PRAGMA ids EQ plus_num", - /* 247 */ "cmd ::= PRAGMA ids EQ minus_num", - /* 248 */ "cmd ::= PRAGMA ids LP nm RP", - /* 249 */ "cmd ::= PRAGMA ids", - /* 250 */ "plus_num ::= plus_opt number", - /* 251 */ "minus_num ::= MINUS number", - /* 252 */ "number ::= INTEGER", - /* 253 */ "number ::= FLOAT", - /* 254 */ "plus_opt ::= PLUS", - /* 255 */ "plus_opt ::=", - /* 256 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", - /* 257 */ "trigger_decl ::= temp TRIGGER nm trigger_time trigger_event ON nm dbnm foreach_clause when_clause", - /* 258 */ "trigger_time ::= BEFORE", - /* 259 */ "trigger_time ::= AFTER", - /* 260 */ "trigger_time ::= INSTEAD OF", - /* 261 */ "trigger_time ::=", - /* 262 */ "trigger_event ::= DELETE", - /* 263 */ "trigger_event ::= INSERT", - /* 264 */ "trigger_event ::= UPDATE", - /* 265 */ "trigger_event ::= UPDATE OF inscollist", - /* 266 */ "foreach_clause ::=", - /* 267 */ "foreach_clause ::= FOR EACH ROW", - /* 268 */ "foreach_clause ::= FOR EACH STATEMENT", - /* 269 */ "when_clause ::=", - /* 270 */ "when_clause ::= WHEN expr", - /* 271 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list", - /* 272 */ "trigger_cmd_list ::=", - /* 273 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", - /* 274 */ "trigger_cmd ::= INSERT orconf INTO nm inscollist_opt VALUES LP itemlist RP", - /* 275 */ "trigger_cmd ::= INSERT orconf INTO nm inscollist_opt select", - /* 276 */ "trigger_cmd ::= DELETE FROM nm where_opt", - /* 277 */ "trigger_cmd ::= select", - /* 278 */ "expr ::= RAISE LP IGNORE RP", - /* 279 */ "expr ::= RAISE LP ROLLBACK COMMA nm RP", - /* 280 */ "expr ::= RAISE LP ABORT COMMA nm RP", - /* 281 */ "expr ::= RAISE LP FAIL COMMA nm RP", - /* 282 */ "cmd ::= DROP TRIGGER nm dbnm", - /* 283 */ "cmd ::= ATTACH database_kw_opt ids AS nm", - /* 284 */ "database_kw_opt ::= DATABASE", - /* 285 */ "database_kw_opt ::=", - /* 286 */ "cmd ::= DETACH database_kw_opt nm", + /* 124 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt", + /* 125 */ "seltablist_paren ::= select", + /* 126 */ "seltablist_paren ::= seltablist", + /* 127 */ "dbnm ::=", + /* 128 */ "dbnm ::= DOT nm", + /* 129 */ "joinop ::= COMMA", + /* 130 */ "joinop ::= JOIN", + /* 131 */ "joinop ::= JOIN_KW JOIN", + /* 132 */ "joinop ::= JOIN_KW nm JOIN", + /* 133 */ "joinop ::= JOIN_KW nm nm JOIN", + /* 134 */ "on_opt ::= ON expr", + /* 135 */ "on_opt ::=", + /* 136 */ "using_opt ::= USING LP idxlist RP", + /* 137 */ "using_opt ::=", + /* 138 */ "orderby_opt ::=", + /* 139 */ "orderby_opt ::= ORDER BY sortlist", + /* 140 */ "sortlist ::= sortlist COMMA sortitem collate sortorder", + /* 141 */ "sortlist ::= sortitem collate sortorder", + /* 142 */ "sortitem ::= expr", + /* 143 */ "sortorder ::= ASC", + /* 144 */ "sortorder ::= DESC", + /* 145 */ "sortorder ::=", + /* 146 */ "collate ::=", + /* 147 */ "collate ::= COLLATE id", + /* 148 */ "groupby_opt ::=", + /* 149 */ "groupby_opt ::= GROUP BY exprlist", + /* 150 */ "having_opt ::=", + /* 151 */ "having_opt ::= HAVING expr", + /* 152 */ "limit_opt ::=", + /* 153 */ "limit_opt ::= LIMIT signed", + /* 154 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 155 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 156 */ "cmd ::= DELETE FROM nm dbnm where_opt", + /* 157 */ "where_opt ::=", + /* 158 */ "where_opt ::= WHERE expr", + /* 159 */ "cmd ::= UPDATE orconf nm dbnm SET setlist where_opt", + /* 160 */ "setlist ::= setlist COMMA nm EQ expr", + /* 161 */ "setlist ::= nm EQ expr", + /* 162 */ "cmd ::= insert_cmd INTO nm dbnm inscollist_opt VALUES LP itemlist RP", + /* 163 */ "cmd ::= insert_cmd INTO nm dbnm inscollist_opt select", + /* 164 */ "insert_cmd ::= INSERT orconf", + /* 165 */ "insert_cmd ::= REPLACE", + /* 166 */ "itemlist ::= itemlist COMMA expr", + /* 167 */ "itemlist ::= expr", + /* 168 */ "inscollist_opt ::=", + /* 169 */ "inscollist_opt ::= LP inscollist RP", + /* 170 */ "inscollist ::= inscollist COMMA nm", + /* 171 */ "inscollist ::= nm", + /* 172 */ "expr ::= LP expr RP", + /* 173 */ "expr ::= NULL", + /* 174 */ "expr ::= ID", + /* 175 */ "expr ::= JOIN_KW", + /* 176 */ "expr ::= nm DOT nm", + /* 177 */ "expr ::= nm DOT nm DOT nm", + /* 178 */ "expr ::= INTEGER", + /* 179 */ "expr ::= FLOAT", + /* 180 */ "expr ::= STRING", + /* 181 */ "expr ::= VARIABLE", + /* 182 */ "expr ::= ID LP exprlist RP", + /* 183 */ "expr ::= ID LP STAR RP", + /* 184 */ "expr ::= expr AND expr", + /* 185 */ "expr ::= expr OR expr", + /* 186 */ "expr ::= expr LT expr", + /* 187 */ "expr ::= expr GT expr", + /* 188 */ "expr ::= expr LE expr", + /* 189 */ "expr ::= expr GE expr", + /* 190 */ "expr ::= expr NE expr", + /* 191 */ "expr ::= expr EQ expr", + /* 192 */ "expr ::= expr BITAND expr", + /* 193 */ "expr ::= expr BITOR expr", + /* 194 */ "expr ::= expr LSHIFT expr", + /* 195 */ "expr ::= expr RSHIFT expr", + /* 196 */ "expr ::= expr likeop expr", + /* 197 */ "expr ::= expr NOT likeop expr", + /* 198 */ "likeop ::= LIKE", + /* 199 */ "likeop ::= GLOB", + /* 200 */ "expr ::= expr PLUS expr", + /* 201 */ "expr ::= expr MINUS expr", + /* 202 */ "expr ::= expr STAR expr", + /* 203 */ "expr ::= expr SLASH expr", + /* 204 */ "expr ::= expr REM expr", + /* 205 */ "expr ::= expr CONCAT expr", + /* 206 */ "expr ::= expr ISNULL", + /* 207 */ "expr ::= expr IS NULL", + /* 208 */ "expr ::= expr NOTNULL", + /* 209 */ "expr ::= expr NOT NULL", + /* 210 */ "expr ::= expr IS NOT NULL", + /* 211 */ "expr ::= NOT expr", + /* 212 */ "expr ::= BITNOT expr", + /* 213 */ "expr ::= MINUS expr", + /* 214 */ "expr ::= PLUS expr", + /* 215 */ "expr ::= LP select RP", + /* 216 */ "expr ::= expr BETWEEN expr AND expr", + /* 217 */ "expr ::= expr NOT BETWEEN expr AND expr", + /* 218 */ "expr ::= expr IN LP exprlist RP", + /* 219 */ "expr ::= expr IN LP select RP", + /* 220 */ "expr ::= expr NOT IN LP exprlist RP", + /* 221 */ "expr ::= expr NOT IN LP select RP", + /* 222 */ "expr ::= expr IN nm dbnm", + /* 223 */ "expr ::= expr NOT IN nm dbnm", + /* 224 */ "expr ::= CASE case_operand case_exprlist case_else END", + /* 225 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", + /* 226 */ "case_exprlist ::= WHEN expr THEN expr", + /* 227 */ "case_else ::= ELSE expr", + /* 228 */ "case_else ::=", + /* 229 */ "case_operand ::= expr", + /* 230 */ "case_operand ::=", + /* 231 */ "exprlist ::= exprlist COMMA expritem", + /* 232 */ "exprlist ::= expritem", + /* 233 */ "expritem ::= expr", + /* 234 */ "expritem ::=", + /* 235 */ "cmd ::= CREATE uniqueflag INDEX nm ON nm dbnm LP idxlist RP onconf", + /* 236 */ "uniqueflag ::= UNIQUE", + /* 237 */ "uniqueflag ::=", + /* 238 */ "idxlist_opt ::=", + /* 239 */ "idxlist_opt ::= LP idxlist RP", + /* 240 */ "idxlist ::= idxlist COMMA idxitem", + /* 241 */ "idxlist ::= idxitem", + /* 242 */ "idxitem ::= nm sortorder", + /* 243 */ "cmd ::= DROP INDEX nm dbnm", + /* 244 */ "cmd ::= COPY orconf nm dbnm FROM nm USING DELIMITERS STRING", + /* 245 */ "cmd ::= COPY orconf nm dbnm FROM nm", + /* 246 */ "cmd ::= VACUUM", + /* 247 */ "cmd ::= VACUUM nm", + /* 248 */ "cmd ::= PRAGMA ids EQ nm", + /* 249 */ "cmd ::= PRAGMA ids EQ ON", + /* 250 */ "cmd ::= PRAGMA ids EQ plus_num", + /* 251 */ "cmd ::= PRAGMA ids EQ minus_num", + /* 252 */ "cmd ::= PRAGMA ids LP nm RP", + /* 253 */ "cmd ::= PRAGMA ids", + /* 254 */ "plus_num ::= plus_opt number", + /* 255 */ "minus_num ::= MINUS number", + /* 256 */ "number ::= INTEGER", + /* 257 */ "number ::= FLOAT", + /* 258 */ "plus_opt ::= PLUS", + /* 259 */ "plus_opt ::=", + /* 260 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", + /* 261 */ "trigger_decl ::= temp TRIGGER nm trigger_time trigger_event ON nm dbnm foreach_clause when_clause", + /* 262 */ "trigger_time ::= BEFORE", + /* 263 */ "trigger_time ::= AFTER", + /* 264 */ "trigger_time ::= INSTEAD OF", + /* 265 */ "trigger_time ::=", + /* 266 */ "trigger_event ::= DELETE", + /* 267 */ "trigger_event ::= INSERT", + /* 268 */ "trigger_event ::= UPDATE", + /* 269 */ "trigger_event ::= UPDATE OF inscollist", + /* 270 */ "foreach_clause ::=", + /* 271 */ "foreach_clause ::= FOR EACH ROW", + /* 272 */ "foreach_clause ::= FOR EACH STATEMENT", + /* 273 */ "when_clause ::=", + /* 274 */ "when_clause ::= WHEN expr", + /* 275 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list", + /* 276 */ "trigger_cmd_list ::=", + /* 277 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", + /* 278 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", + /* 279 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", + /* 280 */ "trigger_cmd ::= DELETE FROM nm where_opt", + /* 281 */ "trigger_cmd ::= select", + /* 282 */ "expr ::= RAISE LP IGNORE RP", + /* 283 */ "expr ::= RAISE LP ROLLBACK COMMA nm RP", + /* 284 */ "expr ::= RAISE LP ABORT COMMA nm RP", + /* 285 */ "expr ::= RAISE LP FAIL COMMA nm RP", + /* 286 */ "cmd ::= DROP TRIGGER nm dbnm", + /* 287 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt", + /* 288 */ "key_opt ::= USING ids", + /* 289 */ "key_opt ::=", + /* 290 */ "database_kw_opt ::= DATABASE", + /* 291 */ "database_kw_opt ::=", + /* 292 */ "cmd ::= DETACH database_kw_opt nm", }; #endif /* NDEBUG */ @@ -1282,145 +1229,150 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ - case 135: -#line 675 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1288 "parse.c" - break; - case 157: -#line 520 "parse.y" -{sqliteExprDelete((yypminor->yy334));} -#line 1293 "parse.c" + case 146: +#line 286 "parse.y" +{sqliteSelectDelete((yypminor->yy179));} +#line 1235 "parse.c" break; case 158: -#line 694 "parse.y" -{sqliteExprDelete((yypminor->yy334));} -#line 1298 "parse.c" +#line 533 "parse.y" +{sqliteExprDelete((yypminor->yy242));} +#line 1240 "parse.c" break; case 159: -#line 692 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1303 "parse.c" +#line 746 "parse.y" +{sqliteIdListDelete((yypminor->yy320));} +#line 1245 "parse.c" break; - case 161: -#line 342 "parse.y" -{sqliteSrcListDelete((yypminor->yy335));} -#line 1308 "parse.c" + case 167: +#line 744 "parse.y" +{sqliteIdListDelete((yypminor->yy320));} +#line 1250 "parse.c" + break; + case 171: +#line 288 "parse.y" +{sqliteSelectDelete((yypminor->yy179));} +#line 1255 "parse.c" break; - case 162: -#line 436 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1313 "parse.c" + case 174: +#line 322 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1260 "parse.c" break; - case 163: -#line 441 "parse.y" -{sqliteExprDelete((yypminor->yy334));} -#line 1318 "parse.c" + case 175: +#line 353 "parse.y" +{sqliteSrcListDelete((yypminor->yy307));} +#line 1265 "parse.c" break; - case 167: -#line 717 "parse.y" -{sqliteIdListDelete((yypminor->yy92));} -#line 1323 "parse.c" + case 176: +#line 483 "parse.y" +{sqliteExprDelete((yypminor->yy242));} +#line 1270 "parse.c" break; - case 168: -#line 719 "parse.y" -{sqliteIdListDelete((yypminor->yy92));} -#line 1328 "parse.c" + case 177: +#line 459 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1275 "parse.c" break; - case 171: -#line 499 "parse.y" -{sqliteIdListDelete((yypminor->yy92));} -#line 1333 "parse.c" + case 178: +#line 464 "parse.y" +{sqliteExprDelete((yypminor->yy242));} +#line 1280 "parse.c" break; - case 172: -#line 497 "parse.y" -{sqliteIdListDelete((yypminor->yy92));} -#line 1338 "parse.c" + case 179: +#line 431 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1285 "parse.c" break; - case 174: -#line 491 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1343 "parse.c" + case 181: +#line 324 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1290 "parse.c" break; case 183: -#line 397 "parse.y" -{sqliteExprDelete((yypminor->yy334));} -#line 1348 "parse.c" +#line 349 "parse.y" +{sqliteSrcListDelete((yypminor->yy307));} +#line 1295 "parse.c" break; - case 185: -#line 277 "parse.y" -{sqliteSelectDelete((yypminor->yy11));} -#line 1353 "parse.c" + case 184: +#line 351 "parse.y" +{sqliteSrcListDelete((yypminor->yy307));} +#line 1300 "parse.c" break; case 187: -#line 408 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1358 "parse.c" +#line 420 "parse.y" +{sqliteExprDelete((yypminor->yy242));} +#line 1305 "parse.c" + break; + case 188: +#line 425 "parse.y" +{sqliteIdListDelete((yypminor->yy320));} +#line 1310 "parse.c" + break; + case 189: +#line 400 "parse.y" +{sqliteSelectDelete((yypminor->yy179));} +#line 1315 "parse.c" + break; + case 191: +#line 433 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1320 "parse.c" + break; + case 192: +#line 435 "parse.y" +{sqliteExprDelete((yypminor->yy242));} +#line 1325 "parse.c" break; case 194: -#line 313 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1363 "parse.c" +#line 719 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1330 "parse.c" break; case 195: -#line 311 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1368 "parse.c" - break; - case 196: -#line 275 "parse.y" -{sqliteSelectDelete((yypminor->yy11));} -#line 1373 "parse.c" +#line 489 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1335 "parse.c" break; case 197: -#line 338 "parse.y" -{sqliteSrcListDelete((yypminor->yy335));} -#line 1378 "parse.c" +#line 520 "parse.y" +{sqliteIdListDelete((yypminor->yy320));} +#line 1340 "parse.c" break; case 198: -#line 466 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1383 "parse.c" +#line 514 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1345 "parse.c" break; - case 200: -#line 412 "parse.y" -{sqliteExprDelete((yypminor->yy334));} -#line 1388 "parse.c" - break; - case 201: -#line 410 "parse.y" -{sqliteExprListDelete((yypminor->yy62));} -#line 1393 "parse.c" + case 199: +#line 522 "parse.y" +{sqliteIdListDelete((yypminor->yy320));} +#line 1350 "parse.c" break; - case 203: -#line 340 "parse.y" -{sqliteSrcListDelete((yypminor->yy335));} -#line 1398 "parse.c" + case 202: +#line 702 "parse.y" +{sqliteExprListDelete((yypminor->yy322));} +#line 1355 "parse.c" break; - case 207: -#line 809 "parse.y" -{sqliteDeleteTriggerStep((yypminor->yy347));} -#line 1403 "parse.c" + case 204: +#line 721 "parse.y" +{sqliteExprDelete((yypminor->yy242));} +#line 1360 "parse.c" break; - case 208: -#line 801 "parse.y" -{sqliteDeleteTriggerStep((yypminor->yy347));} -#line 1408 "parse.c" + case 212: +#line 828 "parse.y" +{sqliteDeleteTriggerStep((yypminor->yy19));} +#line 1365 "parse.c" break; - case 210: -#line 785 "parse.y" -{sqliteIdListDelete((yypminor->yy234).b);} -#line 1413 "parse.c" - break; - case 215: -#line 402 "parse.y" -{sqliteIdListDelete((yypminor->yy92));} -#line 1418 "parse.c" + case 214: +#line 812 "parse.y" +{sqliteIdListDelete((yypminor->yy290).b);} +#line 1370 "parse.c" break; case 217: -#line 460 "parse.y" -{sqliteExprDelete((yypminor->yy334));} -#line 1423 "parse.c" +#line 836 "parse.y" +{sqliteDeleteTriggerStep((yypminor->yy19));} +#line 1375 "parse.c" break; default: break; /* If no destructor action specified: do nothing */ } @@ -1596,293 +1548,299 @@ static struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { - { 170, 1 }, - { 139, 1 }, - { 139, 2 }, - { 154, 3 }, - { 154, 1 }, - { 140, 1 }, - { 156, 1 }, - { 156, 0 }, - { 138, 3 }, - { 206, 0 }, - { 206, 1 }, - { 206, 2 }, - { 138, 2 }, - { 138, 2 }, - { 138, 2 }, - { 138, 2 }, - { 147, 4 }, - { 205, 1 }, - { 205, 0 }, - { 148, 4 }, - { 148, 2 }, - { 144, 3 }, - { 144, 1 }, - { 142, 3 }, - { 143, 1 }, - { 164, 1 }, - { 165, 1 }, - { 165, 1 }, - { 181, 1 }, - { 181, 1 }, - { 181, 1 }, - { 212, 0 }, - { 212, 1 }, - { 212, 4 }, - { 212, 6 }, - { 213, 1 }, - { 213, 2 }, - { 199, 1 }, - { 199, 2 }, - { 199, 2 }, - { 133, 2 }, - { 133, 0 }, - { 132, 3 }, { 132, 1 }, - { 132, 2 }, - { 132, 2 }, - { 132, 2 }, - { 132, 3 }, - { 132, 3 }, - { 132, 2 }, - { 132, 3 }, - { 132, 3 }, - { 132, 2 }, - { 137, 2 }, + { 133, 2 }, + { 133, 1 }, + { 134, 3 }, + { 134, 1 }, + { 136, 1 }, + { 135, 1 }, + { 135, 0 }, { 137, 3 }, - { 137, 4 }, + { 138, 0 }, + { 138, 1 }, + { 138, 2 }, { 137, 2 }, - { 137, 5 }, - { 137, 4 }, - { 137, 1 }, { 137, 2 }, - { 192, 0 }, - { 192, 2 }, - { 191, 2 }, - { 191, 3 }, - { 191, 3 }, - { 191, 3 }, - { 190, 2 }, - { 190, 2 }, - { 190, 1 }, - { 190, 1 }, - { 151, 3 }, - { 151, 2 }, - { 169, 0 }, - { 169, 2 }, - { 169, 2 }, - { 146, 0 }, - { 146, 2 }, - { 145, 3 }, - { 145, 2 }, - { 145, 1 }, - { 204, 2 }, - { 204, 6 }, - { 204, 5 }, - { 204, 3 }, - { 204, 10 }, - { 152, 0 }, + { 137, 2 }, + { 137, 2 }, + { 141, 4 }, + { 143, 1 }, + { 143, 0 }, + { 142, 4 }, + { 142, 2 }, + { 144, 3 }, + { 144, 1 }, + { 147, 3 }, + { 148, 1 }, + { 151, 1 }, { 152, 1 }, - { 184, 0 }, - { 184, 3 }, - { 186, 0 }, - { 186, 2 }, - { 193, 1 }, - { 193, 1 }, - { 193, 1 }, - { 193, 1 }, - { 193, 1 }, - { 138, 3 }, - { 138, 6 }, - { 138, 3 }, - { 138, 1 }, - { 196, 1 }, - { 196, 3 }, - { 180, 1 }, - { 180, 2 }, - { 180, 1 }, - { 180, 1 }, - { 185, 9 }, - { 153, 1 }, + { 152, 1 }, + { 140, 1 }, + { 140, 1 }, + { 140, 1 }, + { 149, 0 }, + { 149, 1 }, + { 149, 4 }, + { 149, 6 }, { 153, 1 }, - { 153, 0 }, - { 194, 2 }, - { 194, 0 }, - { 195, 3 }, - { 195, 2 }, - { 195, 4 }, - { 131, 2 }, - { 131, 1 }, - { 131, 0 }, - { 161, 0 }, - { 161, 2 }, - { 203, 2 }, - { 203, 0 }, - { 197, 6 }, - { 197, 7 }, - { 150, 0 }, + { 153, 2 }, + { 154, 1 }, + { 154, 2 }, + { 154, 2 }, { 150, 2 }, - { 175, 1 }, - { 175, 1 }, - { 175, 2 }, - { 175, 3 }, - { 175, 4 }, - { 183, 2 }, - { 183, 0 }, - { 215, 4 }, - { 215, 0 }, - { 187, 0 }, - { 187, 3 }, - { 201, 5 }, - { 201, 3 }, - { 200, 1 }, - { 202, 1 }, - { 202, 1 }, - { 202, 0 }, - { 141, 0 }, - { 141, 2 }, - { 162, 0 }, + { 150, 0 }, + { 155, 3 }, + { 155, 1 }, + { 155, 2 }, + { 155, 2 }, + { 155, 2 }, + { 155, 3 }, + { 155, 3 }, + { 155, 2 }, + { 155, 3 }, + { 155, 3 }, + { 155, 2 }, + { 156, 2 }, + { 156, 3 }, + { 156, 4 }, + { 156, 2 }, + { 156, 5 }, + { 156, 4 }, + { 156, 1 }, + { 156, 2 }, + { 160, 0 }, + { 160, 2 }, + { 162, 2 }, + { 162, 3 }, + { 162, 3 }, { 162, 3 }, - { 163, 0 }, { 163, 2 }, - { 178, 0 }, - { 178, 2 }, - { 178, 4 }, - { 178, 4 }, - { 138, 5 }, - { 217, 0 }, - { 217, 2 }, - { 138, 7 }, - { 198, 5 }, - { 198, 3 }, - { 138, 9 }, - { 138, 6 }, - { 173, 2 }, + { 163, 2 }, + { 163, 1 }, + { 163, 1 }, + { 161, 3 }, + { 161, 2 }, + { 164, 0 }, + { 164, 2 }, + { 164, 2 }, + { 145, 0 }, + { 145, 2 }, + { 165, 3 }, + { 165, 2 }, + { 165, 1 }, + { 166, 2 }, + { 166, 6 }, + { 166, 5 }, + { 166, 3 }, + { 166, 10 }, + { 168, 0 }, + { 168, 1 }, + { 139, 0 }, + { 139, 3 }, + { 169, 0 }, + { 169, 2 }, + { 170, 1 }, + { 170, 1 }, + { 170, 1 }, + { 170, 1 }, + { 170, 1 }, + { 137, 3 }, + { 137, 6 }, + { 137, 3 }, + { 137, 1 }, + { 146, 1 }, + { 146, 3 }, + { 172, 1 }, + { 172, 2 }, + { 172, 1 }, + { 172, 1 }, + { 171, 9 }, + { 173, 1 }, { 173, 1 }, + { 173, 0 }, + { 181, 2 }, + { 181, 0 }, { 174, 3 }, - { 174, 1 }, - { 172, 0 }, - { 172, 3 }, - { 171, 3 }, - { 171, 1 }, - { 157, 3 }, - { 157, 1 }, - { 157, 1 }, - { 157, 1 }, - { 157, 3 }, - { 157, 5 }, - { 157, 1 }, - { 157, 1 }, + { 174, 2 }, + { 174, 4 }, + { 182, 2 }, + { 182, 1 }, + { 182, 0 }, + { 175, 0 }, + { 175, 2 }, + { 184, 2 }, + { 184, 0 }, + { 183, 6 }, + { 183, 7 }, + { 189, 1 }, + { 189, 1 }, + { 186, 0 }, + { 186, 2 }, + { 185, 1 }, + { 185, 1 }, + { 185, 2 }, + { 185, 3 }, + { 185, 4 }, + { 187, 2 }, + { 187, 0 }, + { 188, 4 }, + { 188, 0 }, + { 179, 0 }, + { 179, 3 }, + { 191, 5 }, + { 191, 3 }, + { 192, 1 }, { 157, 1 }, { 157, 1 }, - { 157, 4 }, - { 157, 4 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 4 }, - { 177, 1 }, - { 177, 1 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 3 }, - { 157, 2 }, - { 157, 3 }, - { 157, 2 }, - { 157, 3 }, - { 157, 4 }, - { 157, 2 }, - { 157, 2 }, - { 157, 2 }, - { 157, 2 }, - { 157, 3 }, - { 157, 5 }, - { 157, 6 }, - { 157, 5 }, - { 157, 5 }, - { 157, 6 }, - { 157, 6 }, - { 157, 5 }, - { 135, 5 }, - { 135, 4 }, - { 134, 2 }, - { 134, 0 }, - { 136, 1 }, - { 136, 0 }, - { 159, 3 }, - { 159, 1 }, + { 157, 0 }, + { 193, 0 }, + { 193, 2 }, + { 177, 0 }, + { 177, 3 }, + { 178, 0 }, + { 178, 2 }, + { 180, 0 }, + { 180, 2 }, + { 180, 4 }, + { 180, 4 }, + { 137, 5 }, + { 176, 0 }, + { 176, 2 }, + { 137, 7 }, + { 195, 5 }, + { 195, 3 }, + { 137, 9 }, + { 137, 6 }, + { 196, 2 }, + { 196, 1 }, + { 198, 3 }, + { 198, 1 }, + { 197, 0 }, + { 197, 3 }, + { 199, 3 }, + { 199, 1 }, + { 158, 3 }, { 158, 1 }, - { 158, 0 }, - { 138, 11 }, - { 214, 1 }, - { 214, 0 }, - { 168, 0 }, - { 168, 3 }, + { 158, 1 }, + { 158, 1 }, + { 158, 3 }, + { 158, 5 }, + { 158, 1 }, + { 158, 1 }, + { 158, 1 }, + { 158, 1 }, + { 158, 4 }, + { 158, 4 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 4 }, + { 200, 1 }, + { 200, 1 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 3 }, + { 158, 2 }, + { 158, 3 }, + { 158, 2 }, + { 158, 3 }, + { 158, 4 }, + { 158, 2 }, + { 158, 2 }, + { 158, 2 }, + { 158, 2 }, + { 158, 3 }, + { 158, 5 }, + { 158, 6 }, + { 158, 5 }, + { 158, 5 }, + { 158, 6 }, + { 158, 6 }, + { 158, 4 }, + { 158, 5 }, + { 158, 5 }, + { 202, 5 }, + { 202, 4 }, + { 203, 2 }, + { 203, 0 }, + { 201, 1 }, + { 201, 0 }, + { 194, 3 }, + { 194, 1 }, + { 204, 1 }, + { 204, 0 }, + { 137, 11 }, + { 205, 1 }, + { 205, 0 }, + { 159, 0 }, + { 159, 3 }, { 167, 3 }, { 167, 1 }, - { 166, 2 }, - { 138, 4 }, - { 138, 9 }, - { 138, 6 }, - { 138, 1 }, - { 138, 2 }, - { 138, 4 }, - { 138, 4 }, - { 138, 4 }, - { 138, 4 }, - { 138, 5 }, - { 138, 2 }, - { 188, 2 }, - { 179, 2 }, - { 182, 1 }, - { 182, 1 }, - { 189, 1 }, - { 189, 0 }, - { 138, 5 }, - { 209, 10 }, - { 211, 1 }, - { 211, 1 }, - { 211, 2 }, - { 211, 0 }, - { 210, 1 }, + { 206, 2 }, + { 137, 4 }, + { 137, 9 }, + { 137, 6 }, + { 137, 1 }, + { 137, 2 }, + { 137, 4 }, + { 137, 4 }, + { 137, 4 }, + { 137, 4 }, + { 137, 5 }, + { 137, 2 }, + { 207, 2 }, + { 208, 2 }, { 210, 1 }, { 210, 1 }, - { 210, 3 }, - { 160, 0 }, - { 160, 3 }, - { 160, 3 }, + { 209, 1 }, + { 209, 0 }, + { 137, 5 }, + { 211, 10 }, + { 213, 1 }, + { 213, 1 }, + { 213, 2 }, + { 213, 0 }, + { 214, 1 }, + { 214, 1 }, + { 214, 1 }, + { 214, 3 }, + { 215, 0 }, + { 215, 3 }, + { 215, 3 }, { 216, 0 }, { 216, 2 }, - { 208, 3 }, - { 208, 0 }, - { 207, 6 }, - { 207, 9 }, - { 207, 6 }, - { 207, 4 }, - { 207, 1 }, - { 157, 4 }, - { 157, 6 }, - { 157, 6 }, - { 157, 6 }, - { 138, 4 }, - { 138, 5 }, - { 149, 1 }, - { 149, 0 }, - { 138, 3 }, + { 212, 3 }, + { 212, 0 }, + { 217, 6 }, + { 217, 8 }, + { 217, 5 }, + { 217, 4 }, + { 217, 1 }, + { 158, 4 }, + { 158, 6 }, + { 158, 6 }, + { 158, 6 }, + { 137, 4 }, + { 137, 6 }, + { 219, 2 }, + { 219, 0 }, + { 218, 1 }, + { 218, 0 }, + { 137, 3 }, }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1923,10 +1881,10 @@ static void yy_reduce( /* No destructor defined for cmdlist */ break; case 1: + /* No destructor defined for cmdlist */ /* No destructor defined for ecmd */ break; case 2: - /* No destructor defined for cmdlist */ /* No destructor defined for ecmd */ break; case 3: @@ -1938,26 +1896,26 @@ static void yy_reduce( /* No destructor defined for SEMI */ break; case 5: -#line 77 "parse.y" +#line 72 "parse.y" { sqliteExec(pParse); } -#line 1943 "parse.c" +#line 1901 "parse.c" /* No destructor defined for cmd */ break; case 6: -#line 78 "parse.y" +#line 73 "parse.y" { sqliteBeginParse(pParse, 1); } -#line 1949 "parse.c" +#line 1907 "parse.c" /* No destructor defined for EXPLAIN */ break; case 7: -#line 79 "parse.y" +#line 74 "parse.y" { sqliteBeginParse(pParse, 0); } -#line 1955 "parse.c" +#line 1913 "parse.c" break; case 8: -#line 84 "parse.y" -{sqliteBeginTransaction(pParse,yymsp[0].minor.yy52);} -#line 1960 "parse.c" +#line 79 "parse.y" +{sqliteBeginTransaction(pParse,yymsp[0].minor.yy372);} +#line 1918 "parse.c" /* No destructor defined for BEGIN */ /* No destructor defined for trans_opt */ break; @@ -1971,23 +1929,23 @@ static void yy_reduce( /* No destructor defined for nm */ break; case 12: -#line 88 "parse.y" +#line 83 "parse.y" {sqliteCommitTransaction(pParse);} -#line 1976 "parse.c" +#line 1934 "parse.c" /* No destructor defined for COMMIT */ /* No destructor defined for trans_opt */ break; case 13: -#line 89 "parse.y" +#line 84 "parse.y" {sqliteCommitTransaction(pParse);} -#line 1983 "parse.c" +#line 1941 "parse.c" /* No destructor defined for END */ /* No destructor defined for trans_opt */ break; case 14: -#line 90 "parse.y" +#line 85 "parse.y" {sqliteRollbackTransaction(pParse);} -#line 1990 "parse.c" +#line 1948 "parse.c" /* No destructor defined for ROLLBACK */ /* No destructor defined for trans_opt */ break; @@ -1996,41 +1954,41 @@ static void yy_reduce( /* No destructor defined for create_table_args */ break; case 16: -#line 95 "parse.y" +#line 90 "parse.y" { - sqliteStartTable(pParse,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy210,yymsp[-2].minor.yy52,0); + sqliteStartTable(pParse,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy298,yymsp[-2].minor.yy372,0); } -#line 2003 "parse.c" +#line 1961 "parse.c" /* No destructor defined for TABLE */ break; case 17: -#line 99 "parse.y" -{yygotominor.yy52 = 1;} -#line 2009 "parse.c" +#line 94 "parse.y" +{yygotominor.yy372 = 1;} +#line 1967 "parse.c" /* No destructor defined for TEMP */ break; case 18: -#line 100 "parse.y" -{yygotominor.yy52 = 0;} -#line 2015 "parse.c" +#line 95 "parse.y" +{yygotominor.yy372 = 0;} +#line 1973 "parse.c" break; case 19: -#line 101 "parse.y" +#line 96 "parse.y" { sqliteEndTable(pParse,&yymsp[0].minor.yy0,0); } -#line 2022 "parse.c" +#line 1980 "parse.c" /* No destructor defined for LP */ /* No destructor defined for columnlist */ /* No destructor defined for conslist_opt */ break; case 20: -#line 104 "parse.y" +#line 99 "parse.y" { - sqliteEndTable(pParse,0,yymsp[0].minor.yy11); - sqliteSelectDelete(yymsp[0].minor.yy11); + sqliteEndTable(pParse,0,yymsp[0].minor.yy179); + sqliteSelectDelete(yymsp[0].minor.yy179); } -#line 2033 "parse.c" +#line 1991 "parse.c" /* No destructor defined for AS */ break; case 21: @@ -2047,89 +2005,89 @@ static void yy_reduce( /* No destructor defined for carglist */ break; case 24: -#line 116 "parse.y" -{sqliteAddColumn(pParse,&yymsp[0].minor.yy210);} -#line 2052 "parse.c" +#line 111 "parse.y" +{sqliteAddColumn(pParse,&yymsp[0].minor.yy298);} +#line 2010 "parse.c" break; case 25: -#line 122 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 2057 "parse.c" +#line 117 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 2015 "parse.c" break; case 26: -#line 138 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 2062 "parse.c" +#line 149 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 2020 "parse.c" break; case 27: -#line 139 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 2067 "parse.c" +#line 150 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 2025 "parse.c" break; case 28: -#line 144 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 2072 "parse.c" +#line 155 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 2030 "parse.c" break; case 29: -#line 145 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 2077 "parse.c" +#line 156 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 2035 "parse.c" break; case 30: -#line 146 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 2082 "parse.c" +#line 157 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 2040 "parse.c" break; case 31: break; case 32: -#line 149 "parse.y" -{sqliteAddColumnType(pParse,&yymsp[0].minor.yy210,&yymsp[0].minor.yy210);} -#line 2089 "parse.c" +#line 160 "parse.y" +{sqliteAddColumnType(pParse,&yymsp[0].minor.yy298,&yymsp[0].minor.yy298);} +#line 2047 "parse.c" break; case 33: -#line 150 "parse.y" -{sqliteAddColumnType(pParse,&yymsp[-3].minor.yy210,&yymsp[0].minor.yy0);} -#line 2094 "parse.c" +#line 161 "parse.y" +{sqliteAddColumnType(pParse,&yymsp[-3].minor.yy298,&yymsp[0].minor.yy0);} +#line 2052 "parse.c" /* No destructor defined for LP */ /* No destructor defined for signed */ break; case 34: -#line 152 "parse.y" -{sqliteAddColumnType(pParse,&yymsp[-5].minor.yy210,&yymsp[0].minor.yy0);} -#line 2101 "parse.c" +#line 163 "parse.y" +{sqliteAddColumnType(pParse,&yymsp[-5].minor.yy298,&yymsp[0].minor.yy0);} +#line 2059 "parse.c" /* No destructor defined for LP */ /* No destructor defined for signed */ /* No destructor defined for COMMA */ /* No destructor defined for signed */ break; case 35: -#line 154 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy210;} -#line 2110 "parse.c" +#line 165 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy298;} +#line 2068 "parse.c" break; case 36: -#line 155 "parse.y" -{yygotominor.yy210 = yymsp[-1].minor.yy210;} -#line 2115 "parse.c" +#line 166 "parse.y" +{yygotominor.yy298 = yymsp[-1].minor.yy298;} +#line 2073 "parse.c" /* No destructor defined for ids */ break; case 37: -#line 157 "parse.y" -{ yygotominor.yy52 = atoi(yymsp[0].minor.yy0.z); } -#line 2121 "parse.c" +#line 168 "parse.y" +{ yygotominor.yy372 = atoi(yymsp[0].minor.yy0.z); } +#line 2079 "parse.c" break; case 38: -#line 158 "parse.y" -{ yygotominor.yy52 = atoi(yymsp[0].minor.yy0.z); } -#line 2126 "parse.c" +#line 169 "parse.y" +{ yygotominor.yy372 = atoi(yymsp[0].minor.yy0.z); } +#line 2084 "parse.c" /* No destructor defined for PLUS */ break; case 39: -#line 159 "parse.y" -{ yygotominor.yy52 = -atoi(yymsp[0].minor.yy0.z); } -#line 2132 "parse.c" +#line 170 "parse.y" +{ yygotominor.yy372 = -atoi(yymsp[0].minor.yy0.z); } +#line 2090 "parse.c" /* No destructor defined for MINUS */ break; case 40: @@ -2147,54 +2105,54 @@ static void yy_reduce( /* No destructor defined for ccons */ break; case 44: -#line 164 "parse.y" +#line 175 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,0);} -#line 2152 "parse.c" +#line 2110 "parse.c" /* No destructor defined for DEFAULT */ break; case 45: -#line 165 "parse.y" +#line 176 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,0);} -#line 2158 "parse.c" +#line 2116 "parse.c" /* No destructor defined for DEFAULT */ break; case 46: -#line 166 "parse.y" +#line 177 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,0);} -#line 2164 "parse.c" +#line 2122 "parse.c" /* No destructor defined for DEFAULT */ break; case 47: -#line 167 "parse.y" +#line 178 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,0);} -#line 2170 "parse.c" +#line 2128 "parse.c" /* No destructor defined for DEFAULT */ /* No destructor defined for PLUS */ break; case 48: -#line 168 "parse.y" +#line 179 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,1);} -#line 2177 "parse.c" +#line 2135 "parse.c" /* No destructor defined for DEFAULT */ /* No destructor defined for MINUS */ break; case 49: -#line 169 "parse.y" +#line 180 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,0);} -#line 2184 "parse.c" +#line 2142 "parse.c" /* No destructor defined for DEFAULT */ break; case 50: -#line 170 "parse.y" +#line 181 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,0);} -#line 2190 "parse.c" +#line 2148 "parse.c" /* No destructor defined for DEFAULT */ /* No destructor defined for PLUS */ break; case 51: -#line 171 "parse.y" +#line 182 "parse.y" {sqliteAddDefaultValue(pParse,&yymsp[0].minor.yy0,1);} -#line 2197 "parse.c" +#line 2155 "parse.c" /* No destructor defined for DEFAULT */ /* No destructor defined for MINUS */ break; @@ -2207,145 +2165,145 @@ static void yy_reduce( /* No destructor defined for onconf */ break; case 54: -#line 178 "parse.y" -{sqliteAddNotNull(pParse, yymsp[0].minor.yy52);} -#line 2212 "parse.c" +#line 189 "parse.y" +{sqliteAddNotNull(pParse, yymsp[0].minor.yy372);} +#line 2170 "parse.c" /* No destructor defined for NOT */ /* No destructor defined for NULL */ break; case 55: -#line 179 "parse.y" -{sqliteAddPrimaryKey(pParse,0,yymsp[0].minor.yy52);} -#line 2219 "parse.c" +#line 190 "parse.y" +{sqliteAddPrimaryKey(pParse,0,yymsp[0].minor.yy372);} +#line 2177 "parse.c" /* No destructor defined for PRIMARY */ /* No destructor defined for KEY */ /* No destructor defined for sortorder */ break; case 56: -#line 180 "parse.y" -{sqliteCreateIndex(pParse,0,0,0,yymsp[0].minor.yy52,0,0);} -#line 2227 "parse.c" +#line 191 "parse.y" +{sqliteCreateIndex(pParse,0,0,0,yymsp[0].minor.yy372,0,0);} +#line 2185 "parse.c" /* No destructor defined for UNIQUE */ break; case 57: /* No destructor defined for CHECK */ /* No destructor defined for LP */ - yy_destructor(157,&yymsp[-2].minor); + yy_destructor(158,&yymsp[-2].minor); /* No destructor defined for RP */ /* No destructor defined for onconf */ break; case 58: -#line 183 "parse.y" -{sqliteCreateForeignKey(pParse,0,&yymsp[-2].minor.yy210,yymsp[-1].minor.yy92,yymsp[0].minor.yy52);} -#line 2240 "parse.c" +#line 194 "parse.y" +{sqliteCreateForeignKey(pParse,0,&yymsp[-2].minor.yy298,yymsp[-1].minor.yy320,yymsp[0].minor.yy372);} +#line 2198 "parse.c" /* No destructor defined for REFERENCES */ break; case 59: -#line 184 "parse.y" -{sqliteDeferForeignKey(pParse,yymsp[0].minor.yy52);} -#line 2246 "parse.c" +#line 195 "parse.y" +{sqliteDeferForeignKey(pParse,yymsp[0].minor.yy372);} +#line 2204 "parse.c" break; case 60: -#line 185 "parse.y" +#line 196 "parse.y" { - sqliteAddCollateType(pParse, sqliteCollateType(yymsp[0].minor.yy210.z, yymsp[0].minor.yy210.n)); + sqliteAddCollateType(pParse, sqliteCollateType(yymsp[0].minor.yy298.z, yymsp[0].minor.yy298.n)); } -#line 2253 "parse.c" +#line 2211 "parse.c" /* No destructor defined for COLLATE */ break; case 61: -#line 195 "parse.y" -{ yygotominor.yy52 = OE_Restrict * 0x010101; } -#line 2259 "parse.c" +#line 206 "parse.y" +{ yygotominor.yy372 = OE_Restrict * 0x010101; } +#line 2217 "parse.c" break; case 62: -#line 196 "parse.y" -{ yygotominor.yy52 = (yymsp[-1].minor.yy52 & yymsp[0].minor.yy279.mask) | yymsp[0].minor.yy279.value; } -#line 2264 "parse.c" +#line 207 "parse.y" +{ yygotominor.yy372 = (yymsp[-1].minor.yy372 & yymsp[0].minor.yy407.mask) | yymsp[0].minor.yy407.value; } +#line 2222 "parse.c" break; case 63: -#line 198 "parse.y" -{ yygotominor.yy279.value = 0; yygotominor.yy279.mask = 0x000000; } -#line 2269 "parse.c" +#line 209 "parse.y" +{ yygotominor.yy407.value = 0; yygotominor.yy407.mask = 0x000000; } +#line 2227 "parse.c" /* No destructor defined for MATCH */ /* No destructor defined for nm */ break; case 64: -#line 199 "parse.y" -{ yygotominor.yy279.value = yymsp[0].minor.yy52; yygotominor.yy279.mask = 0x0000ff; } -#line 2276 "parse.c" +#line 210 "parse.y" +{ yygotominor.yy407.value = yymsp[0].minor.yy372; yygotominor.yy407.mask = 0x0000ff; } +#line 2234 "parse.c" /* No destructor defined for ON */ /* No destructor defined for DELETE */ break; case 65: -#line 200 "parse.y" -{ yygotominor.yy279.value = yymsp[0].minor.yy52<<8; yygotominor.yy279.mask = 0x00ff00; } -#line 2283 "parse.c" +#line 211 "parse.y" +{ yygotominor.yy407.value = yymsp[0].minor.yy372<<8; yygotominor.yy407.mask = 0x00ff00; } +#line 2241 "parse.c" /* No destructor defined for ON */ /* No destructor defined for UPDATE */ break; case 66: -#line 201 "parse.y" -{ yygotominor.yy279.value = yymsp[0].minor.yy52<<16; yygotominor.yy279.mask = 0xff0000; } -#line 2290 "parse.c" +#line 212 "parse.y" +{ yygotominor.yy407.value = yymsp[0].minor.yy372<<16; yygotominor.yy407.mask = 0xff0000; } +#line 2248 "parse.c" /* No destructor defined for ON */ /* No destructor defined for INSERT */ break; case 67: -#line 203 "parse.y" -{ yygotominor.yy52 = OE_SetNull; } -#line 2297 "parse.c" +#line 214 "parse.y" +{ yygotominor.yy372 = OE_SetNull; } +#line 2255 "parse.c" /* No destructor defined for SET */ /* No destructor defined for NULL */ break; case 68: -#line 204 "parse.y" -{ yygotominor.yy52 = OE_SetDflt; } -#line 2304 "parse.c" +#line 215 "parse.y" +{ yygotominor.yy372 = OE_SetDflt; } +#line 2262 "parse.c" /* No destructor defined for SET */ /* No destructor defined for DEFAULT */ break; case 69: -#line 205 "parse.y" -{ yygotominor.yy52 = OE_Cascade; } -#line 2311 "parse.c" +#line 216 "parse.y" +{ yygotominor.yy372 = OE_Cascade; } +#line 2269 "parse.c" /* No destructor defined for CASCADE */ break; case 70: -#line 206 "parse.y" -{ yygotominor.yy52 = OE_Restrict; } -#line 2317 "parse.c" +#line 217 "parse.y" +{ yygotominor.yy372 = OE_Restrict; } +#line 2275 "parse.c" /* No destructor defined for RESTRICT */ break; case 71: -#line 208 "parse.y" -{yygotominor.yy52 = yymsp[0].minor.yy52;} -#line 2323 "parse.c" +#line 219 "parse.y" +{yygotominor.yy372 = yymsp[0].minor.yy372;} +#line 2281 "parse.c" /* No destructor defined for NOT */ /* No destructor defined for DEFERRABLE */ break; case 72: -#line 209 "parse.y" -{yygotominor.yy52 = yymsp[0].minor.yy52;} -#line 2330 "parse.c" +#line 220 "parse.y" +{yygotominor.yy372 = yymsp[0].minor.yy372;} +#line 2288 "parse.c" /* No destructor defined for DEFERRABLE */ break; case 73: -#line 211 "parse.y" -{yygotominor.yy52 = 0;} -#line 2336 "parse.c" +#line 222 "parse.y" +{yygotominor.yy372 = 0;} +#line 2294 "parse.c" break; case 74: -#line 212 "parse.y" -{yygotominor.yy52 = 1;} -#line 2341 "parse.c" +#line 223 "parse.y" +{yygotominor.yy372 = 1;} +#line 2299 "parse.c" /* No destructor defined for INITIALLY */ /* No destructor defined for DEFERRED */ break; case 75: -#line 213 "parse.y" -{yygotominor.yy52 = 0;} -#line 2348 "parse.c" +#line 224 "parse.y" +{yygotominor.yy372 = 0;} +#line 2306 "parse.c" /* No destructor defined for INITIALLY */ /* No destructor defined for IMMEDIATE */ break; @@ -2372,34 +2330,34 @@ static void yy_reduce( /* No destructor defined for nm */ break; case 82: -#line 225 "parse.y" -{sqliteAddPrimaryKey(pParse,yymsp[-2].minor.yy92,yymsp[0].minor.yy52);} -#line 2377 "parse.c" +#line 236 "parse.y" +{sqliteAddPrimaryKey(pParse,yymsp[-2].minor.yy320,yymsp[0].minor.yy372);} +#line 2335 "parse.c" /* No destructor defined for PRIMARY */ /* No destructor defined for KEY */ /* No destructor defined for LP */ /* No destructor defined for RP */ break; case 83: -#line 227 "parse.y" -{sqliteCreateIndex(pParse,0,0,yymsp[-2].minor.yy92,yymsp[0].minor.yy52,0,0);} -#line 2386 "parse.c" +#line 238 "parse.y" +{sqliteCreateIndex(pParse,0,0,yymsp[-2].minor.yy320,yymsp[0].minor.yy372,0,0);} +#line 2344 "parse.c" /* No destructor defined for UNIQUE */ /* No destructor defined for LP */ /* No destructor defined for RP */ break; case 84: /* No destructor defined for CHECK */ - yy_destructor(157,&yymsp[-1].minor); + yy_destructor(158,&yymsp[-1].minor); /* No destructor defined for onconf */ break; case 85: -#line 230 "parse.y" +#line 241 "parse.y" { - sqliteCreateForeignKey(pParse, yymsp[-6].minor.yy92, &yymsp[-3].minor.yy210, yymsp[-2].minor.yy92, yymsp[-1].minor.yy52); - sqliteDeferForeignKey(pParse, yymsp[0].minor.yy52); + sqliteCreateForeignKey(pParse, yymsp[-6].minor.yy320, &yymsp[-3].minor.yy298, yymsp[-2].minor.yy320, yymsp[-1].minor.yy372); + sqliteDeferForeignKey(pParse, yymsp[0].minor.yy372); } -#line 2402 "parse.c" +#line 2360 "parse.c" /* No destructor defined for FOREIGN */ /* No destructor defined for KEY */ /* No destructor defined for LP */ @@ -2407,1405 +2365,1450 @@ static void yy_reduce( /* No destructor defined for REFERENCES */ break; case 86: -#line 235 "parse.y" -{yygotominor.yy52 = 0;} -#line 2412 "parse.c" +#line 246 "parse.y" +{yygotominor.yy372 = 0;} +#line 2370 "parse.c" break; case 87: -#line 236 "parse.y" -{yygotominor.yy52 = yymsp[0].minor.yy52;} -#line 2417 "parse.c" +#line 247 "parse.y" +{yygotominor.yy372 = yymsp[0].minor.yy372;} +#line 2375 "parse.c" break; case 88: -#line 244 "parse.y" -{ yygotominor.yy52 = OE_Default; } -#line 2422 "parse.c" +#line 255 "parse.y" +{ yygotominor.yy372 = OE_Default; } +#line 2380 "parse.c" break; case 89: -#line 245 "parse.y" -{ yygotominor.yy52 = yymsp[0].minor.yy52; } -#line 2427 "parse.c" +#line 256 "parse.y" +{ yygotominor.yy372 = yymsp[0].minor.yy372; } +#line 2385 "parse.c" /* No destructor defined for ON */ /* No destructor defined for CONFLICT */ break; case 90: -#line 246 "parse.y" -{ yygotominor.yy52 = OE_Default; } -#line 2434 "parse.c" +#line 257 "parse.y" +{ yygotominor.yy372 = OE_Default; } +#line 2392 "parse.c" break; case 91: -#line 247 "parse.y" -{ yygotominor.yy52 = yymsp[0].minor.yy52; } -#line 2439 "parse.c" +#line 258 "parse.y" +{ yygotominor.yy372 = yymsp[0].minor.yy372; } +#line 2397 "parse.c" /* No destructor defined for OR */ break; case 92: -#line 248 "parse.y" -{ yygotominor.yy52 = OE_Rollback; } -#line 2445 "parse.c" +#line 259 "parse.y" +{ yygotominor.yy372 = OE_Rollback; } +#line 2403 "parse.c" /* No destructor defined for ROLLBACK */ break; case 93: -#line 249 "parse.y" -{ yygotominor.yy52 = OE_Abort; } -#line 2451 "parse.c" +#line 260 "parse.y" +{ yygotominor.yy372 = OE_Abort; } +#line 2409 "parse.c" /* No destructor defined for ABORT */ break; case 94: -#line 250 "parse.y" -{ yygotominor.yy52 = OE_Fail; } -#line 2457 "parse.c" +#line 261 "parse.y" +{ yygotominor.yy372 = OE_Fail; } +#line 2415 "parse.c" /* No destructor defined for FAIL */ break; case 95: -#line 251 "parse.y" -{ yygotominor.yy52 = OE_Ignore; } -#line 2463 "parse.c" +#line 262 "parse.y" +{ yygotominor.yy372 = OE_Ignore; } +#line 2421 "parse.c" /* No destructor defined for IGNORE */ break; case 96: -#line 252 "parse.y" -{ yygotominor.yy52 = OE_Replace; } -#line 2469 "parse.c" +#line 263 "parse.y" +{ yygotominor.yy372 = OE_Replace; } +#line 2427 "parse.c" /* No destructor defined for REPLACE */ break; case 97: -#line 256 "parse.y" -{sqliteDropTable(pParse,&yymsp[0].minor.yy210,0);} -#line 2475 "parse.c" +#line 267 "parse.y" +{sqliteDropTable(pParse,&yymsp[0].minor.yy298,0);} +#line 2433 "parse.c" /* No destructor defined for DROP */ /* No destructor defined for TABLE */ break; case 98: -#line 260 "parse.y" +#line 271 "parse.y" { - sqliteCreateView(pParse, &yymsp[-5].minor.yy0, &yymsp[-2].minor.yy210, yymsp[0].minor.yy11, yymsp[-4].minor.yy52); + sqliteCreateView(pParse, &yymsp[-5].minor.yy0, &yymsp[-2].minor.yy298, yymsp[0].minor.yy179, yymsp[-4].minor.yy372); } -#line 2484 "parse.c" +#line 2442 "parse.c" /* No destructor defined for VIEW */ /* No destructor defined for AS */ break; case 99: -#line 263 "parse.y" +#line 274 "parse.y" { - sqliteDropTable(pParse, &yymsp[0].minor.yy210, 1); + sqliteDropTable(pParse, &yymsp[0].minor.yy298, 1); } -#line 2493 "parse.c" +#line 2451 "parse.c" /* No destructor defined for DROP */ /* No destructor defined for VIEW */ break; case 100: -#line 269 "parse.y" +#line 280 "parse.y" { - sqliteSelect(pParse, yymsp[0].minor.yy11, SRT_Callback, 0, 0, 0, 0); - sqliteSelectDelete(yymsp[0].minor.yy11); + sqliteSelect(pParse, yymsp[0].minor.yy179, SRT_Callback, 0, 0, 0, 0); + sqliteSelectDelete(yymsp[0].minor.yy179); } -#line 2503 "parse.c" +#line 2461 "parse.c" break; case 101: -#line 279 "parse.y" -{yygotominor.yy11 = yymsp[0].minor.yy11;} -#line 2508 "parse.c" +#line 290 "parse.y" +{yygotominor.yy179 = yymsp[0].minor.yy179;} +#line 2466 "parse.c" break; case 102: -#line 280 "parse.y" +#line 291 "parse.y" { - if( yymsp[0].minor.yy11 ){ - yymsp[0].minor.yy11->op = yymsp[-1].minor.yy52; - yymsp[0].minor.yy11->pPrior = yymsp[-2].minor.yy11; + if( yymsp[0].minor.yy179 ){ + yymsp[0].minor.yy179->op = yymsp[-1].minor.yy372; + yymsp[0].minor.yy179->pPrior = yymsp[-2].minor.yy179; } - yygotominor.yy11 = yymsp[0].minor.yy11; + yygotominor.yy179 = yymsp[0].minor.yy179; } -#line 2519 "parse.c" +#line 2477 "parse.c" break; case 103: -#line 288 "parse.y" -{yygotominor.yy52 = TK_UNION;} -#line 2524 "parse.c" +#line 299 "parse.y" +{yygotominor.yy372 = TK_UNION;} +#line 2482 "parse.c" /* No destructor defined for UNION */ break; case 104: -#line 289 "parse.y" -{yygotominor.yy52 = TK_ALL;} -#line 2530 "parse.c" +#line 300 "parse.y" +{yygotominor.yy372 = TK_ALL;} +#line 2488 "parse.c" /* No destructor defined for UNION */ /* No destructor defined for ALL */ break; case 105: -#line 290 "parse.y" -{yygotominor.yy52 = TK_INTERSECT;} -#line 2537 "parse.c" +#line 301 "parse.y" +{yygotominor.yy372 = TK_INTERSECT;} +#line 2495 "parse.c" /* No destructor defined for INTERSECT */ break; case 106: -#line 291 "parse.y" -{yygotominor.yy52 = TK_EXCEPT;} -#line 2543 "parse.c" +#line 302 "parse.y" +{yygotominor.yy372 = TK_EXCEPT;} +#line 2501 "parse.c" /* No destructor defined for EXCEPT */ break; case 107: -#line 293 "parse.y" +#line 304 "parse.y" { - yygotominor.yy11 = sqliteSelectNew(yymsp[-6].minor.yy62,yymsp[-5].minor.yy335,yymsp[-4].minor.yy334,yymsp[-3].minor.yy62,yymsp[-2].minor.yy334,yymsp[-1].minor.yy62,yymsp[-7].minor.yy52,yymsp[0].minor.yy280.limit,yymsp[0].minor.yy280.offset); + yygotominor.yy179 = sqliteSelectNew(yymsp[-6].minor.yy322,yymsp[-5].minor.yy307,yymsp[-4].minor.yy242,yymsp[-3].minor.yy322,yymsp[-2].minor.yy242,yymsp[-1].minor.yy322,yymsp[-7].minor.yy372,yymsp[0].minor.yy124.limit,yymsp[0].minor.yy124.offset); } -#line 2551 "parse.c" +#line 2509 "parse.c" /* No destructor defined for SELECT */ break; case 108: -#line 301 "parse.y" -{yygotominor.yy52 = 1;} -#line 2557 "parse.c" +#line 312 "parse.y" +{yygotominor.yy372 = 1;} +#line 2515 "parse.c" /* No destructor defined for DISTINCT */ break; case 109: -#line 302 "parse.y" -{yygotominor.yy52 = 0;} -#line 2563 "parse.c" +#line 313 "parse.y" +{yygotominor.yy372 = 0;} +#line 2521 "parse.c" /* No destructor defined for ALL */ break; case 110: -#line 303 "parse.y" -{yygotominor.yy52 = 0;} -#line 2569 "parse.c" +#line 314 "parse.y" +{yygotominor.yy372 = 0;} +#line 2527 "parse.c" break; case 111: -#line 314 "parse.y" -{yygotominor.yy62 = yymsp[-1].minor.yy62;} -#line 2574 "parse.c" +#line 325 "parse.y" +{yygotominor.yy322 = yymsp[-1].minor.yy322;} +#line 2532 "parse.c" /* No destructor defined for COMMA */ break; case 112: -#line 315 "parse.y" -{yygotominor.yy62 = 0;} -#line 2580 "parse.c" +#line 326 "parse.y" +{yygotominor.yy322 = 0;} +#line 2538 "parse.c" break; case 113: -#line 316 "parse.y" +#line 327 "parse.y" { - yygotominor.yy62 = sqliteExprListAppend(yymsp[-2].minor.yy62,yymsp[-1].minor.yy334,yymsp[0].minor.yy210.n?&yymsp[0].minor.yy210:0); + yygotominor.yy322 = sqliteExprListAppend(yymsp[-2].minor.yy322,yymsp[-1].minor.yy242,yymsp[0].minor.yy298.n?&yymsp[0].minor.yy298:0); } -#line 2587 "parse.c" +#line 2545 "parse.c" break; case 114: -#line 319 "parse.y" +#line 330 "parse.y" { - yygotominor.yy62 = sqliteExprListAppend(yymsp[-1].minor.yy62, sqliteExpr(TK_ALL, 0, 0, 0), 0); + yygotominor.yy322 = sqliteExprListAppend(yymsp[-1].minor.yy322, sqliteExpr(TK_ALL, 0, 0, 0), 0); } -#line 2594 "parse.c" +#line 2552 "parse.c" /* No destructor defined for STAR */ break; case 115: -#line 322 "parse.y" +#line 333 "parse.y" { Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0); - Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &yymsp[-2].minor.yy210); - yygotominor.yy62 = sqliteExprListAppend(yymsp[-3].minor.yy62, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0); + Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &yymsp[-2].minor.yy298); + yygotominor.yy322 = sqliteExprListAppend(yymsp[-3].minor.yy322, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0); } -#line 2604 "parse.c" +#line 2562 "parse.c" /* No destructor defined for DOT */ /* No destructor defined for STAR */ break; case 116: -#line 332 "parse.y" -{ yygotominor.yy210 = yymsp[0].minor.yy210; } -#line 2611 "parse.c" +#line 343 "parse.y" +{ yygotominor.yy298 = yymsp[0].minor.yy298; } +#line 2569 "parse.c" /* No destructor defined for AS */ break; case 117: -#line 333 "parse.y" -{ yygotominor.yy210 = yymsp[0].minor.yy210; } -#line 2617 "parse.c" +#line 344 "parse.y" +{ yygotominor.yy298 = yymsp[0].minor.yy298; } +#line 2575 "parse.c" break; case 118: -#line 334 "parse.y" -{ yygotominor.yy210.n = 0; } -#line 2622 "parse.c" +#line 345 "parse.y" +{ yygotominor.yy298.n = 0; } +#line 2580 "parse.c" break; case 119: -#line 346 "parse.y" -{yygotominor.yy335 = sqliteMalloc(sizeof(*yygotominor.yy335));} -#line 2627 "parse.c" +#line 357 "parse.y" +{yygotominor.yy307 = sqliteMalloc(sizeof(*yygotominor.yy307));} +#line 2585 "parse.c" break; case 120: -#line 347 "parse.y" -{yygotominor.yy335 = yymsp[0].minor.yy335;} -#line 2632 "parse.c" +#line 358 "parse.y" +{yygotominor.yy307 = yymsp[0].minor.yy307;} +#line 2590 "parse.c" /* No destructor defined for FROM */ break; case 121: -#line 352 "parse.y" +#line 363 "parse.y" { - yygotominor.yy335 = yymsp[-1].minor.yy335; - if( yygotominor.yy335 && yygotominor.yy335->nSrc>0 ) yygotominor.yy335->a[yygotominor.yy335->nSrc-1].jointype = yymsp[0].minor.yy52; + yygotominor.yy307 = yymsp[-1].minor.yy307; + if( yygotominor.yy307 && yygotominor.yy307->nSrc>0 ) yygotominor.yy307->a[yygotominor.yy307->nSrc-1].jointype = yymsp[0].minor.yy372; } -#line 2641 "parse.c" +#line 2599 "parse.c" break; case 122: -#line 356 "parse.y" -{yygotominor.yy335 = 0;} -#line 2646 "parse.c" +#line 367 "parse.y" +{yygotominor.yy307 = 0;} +#line 2604 "parse.c" break; case 123: -#line 357 "parse.y" +#line 368 "parse.y" { - yygotominor.yy335 = sqliteSrcListAppend(yymsp[-5].minor.yy335,&yymsp[-4].minor.yy210,&yymsp[-3].minor.yy210); - if( yymsp[-2].minor.yy210.n ) sqliteSrcListAddAlias(yygotominor.yy335,&yymsp[-2].minor.yy210); - if( yymsp[-1].minor.yy334 ){ - if( yygotominor.yy335 && yygotominor.yy335->nSrc>1 ){ yygotominor.yy335->a[yygotominor.yy335->nSrc-2].pOn = yymsp[-1].minor.yy334; } - else { sqliteExprDelete(yymsp[-1].minor.yy334); } + yygotominor.yy307 = sqliteSrcListAppend(yymsp[-5].minor.yy307,&yymsp[-4].minor.yy298,&yymsp[-3].minor.yy298); + if( yymsp[-2].minor.yy298.n ) sqliteSrcListAddAlias(yygotominor.yy307,&yymsp[-2].minor.yy298); + if( yymsp[-1].minor.yy242 ){ + if( yygotominor.yy307 && yygotominor.yy307->nSrc>1 ){ yygotominor.yy307->a[yygotominor.yy307->nSrc-2].pOn = yymsp[-1].minor.yy242; } + else { sqliteExprDelete(yymsp[-1].minor.yy242); } } - if( yymsp[0].minor.yy92 ){ - if( yygotominor.yy335 && yygotominor.yy335->nSrc>1 ){ yygotominor.yy335->a[yygotominor.yy335->nSrc-2].pUsing = yymsp[0].minor.yy92; } - else { sqliteIdListDelete(yymsp[0].minor.yy92); } + if( yymsp[0].minor.yy320 ){ + if( yygotominor.yy307 && yygotominor.yy307->nSrc>1 ){ yygotominor.yy307->a[yygotominor.yy307->nSrc-2].pUsing = yymsp[0].minor.yy320; } + else { sqliteIdListDelete(yymsp[0].minor.yy320); } } } -#line 2662 "parse.c" +#line 2620 "parse.c" break; case 124: -#line 369 "parse.y" +#line 381 "parse.y" { - yygotominor.yy335 = sqliteSrcListAppend(yymsp[-6].minor.yy335,0,0); - yygotominor.yy335->a[yygotominor.yy335->nSrc-1].pSelect = yymsp[-4].minor.yy11; - if( yymsp[-2].minor.yy210.n ) sqliteSrcListAddAlias(yygotominor.yy335,&yymsp[-2].minor.yy210); - if( yymsp[-1].minor.yy334 ){ - if( yygotominor.yy335 && yygotominor.yy335->nSrc>1 ){ yygotominor.yy335->a[yygotominor.yy335->nSrc-2].pOn = yymsp[-1].minor.yy334; } - else { sqliteExprDelete(yymsp[-1].minor.yy334); } + yygotominor.yy307 = sqliteSrcListAppend(yymsp[-6].minor.yy307,0,0); + yygotominor.yy307->a[yygotominor.yy307->nSrc-1].pSelect = yymsp[-4].minor.yy179; + if( yymsp[-2].minor.yy298.n ) sqliteSrcListAddAlias(yygotominor.yy307,&yymsp[-2].minor.yy298); + if( yymsp[-1].minor.yy242 ){ + if( yygotominor.yy307 && yygotominor.yy307->nSrc>1 ){ yygotominor.yy307->a[yygotominor.yy307->nSrc-2].pOn = yymsp[-1].minor.yy242; } + else { sqliteExprDelete(yymsp[-1].minor.yy242); } } - if( yymsp[0].minor.yy92 ){ - if( yygotominor.yy335 && yygotominor.yy335->nSrc>1 ){ yygotominor.yy335->a[yygotominor.yy335->nSrc-2].pUsing = yymsp[0].minor.yy92; } - else { sqliteIdListDelete(yymsp[0].minor.yy92); } + if( yymsp[0].minor.yy320 ){ + if( yygotominor.yy307 && yygotominor.yy307->nSrc>1 ){ yygotominor.yy307->a[yygotominor.yy307->nSrc-2].pUsing = yymsp[0].minor.yy320; } + else { sqliteIdListDelete(yymsp[0].minor.yy320); } } } -#line 2679 "parse.c" +#line 2637 "parse.c" /* No destructor defined for LP */ /* No destructor defined for RP */ break; case 125: -#line 384 "parse.y" -{yygotominor.yy210.z=0; yygotominor.yy210.n=0;} -#line 2686 "parse.c" +#line 401 "parse.y" +{yygotominor.yy179 = yymsp[0].minor.yy179;} +#line 2644 "parse.c" break; case 126: -#line 385 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy210;} -#line 2691 "parse.c" - /* No destructor defined for DOT */ +#line 402 "parse.y" +{ + yygotominor.yy179 = sqliteSelectNew(0,yymsp[0].minor.yy307,0,0,0,0,0,-1,0); +} +#line 2651 "parse.c" break; case 127: -#line 389 "parse.y" -{ yygotominor.yy52 = JT_INNER; } -#line 2697 "parse.c" - /* No destructor defined for COMMA */ +#line 407 "parse.y" +{yygotominor.yy298.z=0; yygotominor.yy298.n=0;} +#line 2656 "parse.c" break; case 128: -#line 390 "parse.y" -{ yygotominor.yy52 = JT_INNER; } -#line 2703 "parse.c" - /* No destructor defined for JOIN */ +#line 408 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy298;} +#line 2661 "parse.c" + /* No destructor defined for DOT */ break; case 129: -#line 391 "parse.y" -{ yygotominor.yy52 = sqliteJoinType(pParse,&yymsp[-1].minor.yy0,0,0); } -#line 2709 "parse.c" - /* No destructor defined for JOIN */ +#line 412 "parse.y" +{ yygotominor.yy372 = JT_INNER; } +#line 2667 "parse.c" + /* No destructor defined for COMMA */ break; case 130: -#line 392 "parse.y" -{ yygotominor.yy52 = sqliteJoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy210,0); } -#line 2715 "parse.c" +#line 413 "parse.y" +{ yygotominor.yy372 = JT_INNER; } +#line 2673 "parse.c" /* No destructor defined for JOIN */ break; case 131: -#line 394 "parse.y" -{ yygotominor.yy52 = sqliteJoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy210,&yymsp[-1].minor.yy210); } -#line 2721 "parse.c" +#line 414 "parse.y" +{ yygotominor.yy372 = sqliteJoinType(pParse,&yymsp[-1].minor.yy0,0,0); } +#line 2679 "parse.c" /* No destructor defined for JOIN */ break; case 132: -#line 398 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 2727 "parse.c" - /* No destructor defined for ON */ +#line 415 "parse.y" +{ yygotominor.yy372 = sqliteJoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy298,0); } +#line 2685 "parse.c" + /* No destructor defined for JOIN */ break; case 133: -#line 399 "parse.y" -{yygotominor.yy334 = 0;} -#line 2733 "parse.c" +#line 417 "parse.y" +{ yygotominor.yy372 = sqliteJoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy298,&yymsp[-1].minor.yy298); } +#line 2691 "parse.c" + /* No destructor defined for JOIN */ break; case 134: -#line 403 "parse.y" -{yygotominor.yy92 = yymsp[-1].minor.yy92;} -#line 2738 "parse.c" - /* No destructor defined for USING */ - /* No destructor defined for LP */ - /* No destructor defined for RP */ +#line 421 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 2697 "parse.c" + /* No destructor defined for ON */ break; case 135: -#line 404 "parse.y" -{yygotominor.yy92 = 0;} -#line 2746 "parse.c" +#line 422 "parse.y" +{yygotominor.yy242 = 0;} +#line 2703 "parse.c" break; case 136: -#line 414 "parse.y" -{yygotominor.yy62 = 0;} -#line 2751 "parse.c" +#line 426 "parse.y" +{yygotominor.yy320 = yymsp[-1].minor.yy320;} +#line 2708 "parse.c" + /* No destructor defined for USING */ + /* No destructor defined for LP */ + /* No destructor defined for RP */ break; case 137: -#line 415 "parse.y" -{yygotominor.yy62 = yymsp[0].minor.yy62;} -#line 2756 "parse.c" +#line 427 "parse.y" +{yygotominor.yy320 = 0;} +#line 2716 "parse.c" + break; + case 138: +#line 437 "parse.y" +{yygotominor.yy322 = 0;} +#line 2721 "parse.c" + break; + case 139: +#line 438 "parse.y" +{yygotominor.yy322 = yymsp[0].minor.yy322;} +#line 2726 "parse.c" /* No destructor defined for ORDER */ /* No destructor defined for BY */ break; - case 138: -#line 416 "parse.y" + case 140: +#line 439 "parse.y" { - yygotominor.yy62 = sqliteExprListAppend(yymsp[-4].minor.yy62,yymsp[-2].minor.yy334,0); - if( yygotominor.yy62 ) yygotominor.yy62->a[yygotominor.yy62->nExpr-1].sortOrder = yymsp[-1].minor.yy52+yymsp[0].minor.yy52; + yygotominor.yy322 = sqliteExprListAppend(yymsp[-4].minor.yy322,yymsp[-2].minor.yy242,0); + if( yygotominor.yy322 ) yygotominor.yy322->a[yygotominor.yy322->nExpr-1].sortOrder = yymsp[-1].minor.yy372+yymsp[0].minor.yy372; } -#line 2766 "parse.c" +#line 2736 "parse.c" /* No destructor defined for COMMA */ break; - case 139: -#line 420 "parse.y" + case 141: +#line 443 "parse.y" { - yygotominor.yy62 = sqliteExprListAppend(0,yymsp[-2].minor.yy334,0); - if( yygotominor.yy62 ) yygotominor.yy62->a[0].sortOrder = yymsp[-1].minor.yy52+yymsp[0].minor.yy52; + yygotominor.yy322 = sqliteExprListAppend(0,yymsp[-2].minor.yy242,0); + if( yygotominor.yy322 ) yygotominor.yy322->a[0].sortOrder = yymsp[-1].minor.yy372+yymsp[0].minor.yy372; } -#line 2775 "parse.c" - break; - case 140: -#line 424 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 2780 "parse.c" - break; - case 141: -#line 429 "parse.y" -{yygotominor.yy52 = SQLITE_SO_ASC;} -#line 2785 "parse.c" - /* No destructor defined for ASC */ +#line 2745 "parse.c" break; case 142: -#line 430 "parse.y" -{yygotominor.yy52 = SQLITE_SO_DESC;} -#line 2791 "parse.c" - /* No destructor defined for DESC */ +#line 447 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 2750 "parse.c" break; case 143: -#line 431 "parse.y" -{yygotominor.yy52 = SQLITE_SO_ASC;} -#line 2797 "parse.c" +#line 452 "parse.y" +{yygotominor.yy372 = SQLITE_SO_ASC;} +#line 2755 "parse.c" + /* No destructor defined for ASC */ break; case 144: -#line 432 "parse.y" -{yygotominor.yy52 = SQLITE_SO_UNK;} -#line 2802 "parse.c" +#line 453 "parse.y" +{yygotominor.yy372 = SQLITE_SO_DESC;} +#line 2761 "parse.c" + /* No destructor defined for DESC */ break; case 145: -#line 433 "parse.y" -{yygotominor.yy52 = sqliteCollateType(yymsp[0].minor.yy210.z, yymsp[0].minor.yy210.n);} -#line 2807 "parse.c" - /* No destructor defined for COLLATE */ +#line 454 "parse.y" +{yygotominor.yy372 = SQLITE_SO_ASC;} +#line 2767 "parse.c" break; case 146: -#line 437 "parse.y" -{yygotominor.yy62 = 0;} -#line 2813 "parse.c" +#line 455 "parse.y" +{yygotominor.yy372 = SQLITE_SO_UNK;} +#line 2772 "parse.c" break; case 147: -#line 438 "parse.y" -{yygotominor.yy62 = yymsp[0].minor.yy62;} -#line 2818 "parse.c" - /* No destructor defined for GROUP */ - /* No destructor defined for BY */ +#line 456 "parse.y" +{yygotominor.yy372 = sqliteCollateType(yymsp[0].minor.yy298.z, yymsp[0].minor.yy298.n);} +#line 2777 "parse.c" + /* No destructor defined for COLLATE */ break; case 148: -#line 442 "parse.y" -{yygotominor.yy334 = 0;} -#line 2825 "parse.c" +#line 460 "parse.y" +{yygotominor.yy322 = 0;} +#line 2783 "parse.c" break; case 149: -#line 443 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 2830 "parse.c" - /* No destructor defined for HAVING */ +#line 461 "parse.y" +{yygotominor.yy322 = yymsp[0].minor.yy322;} +#line 2788 "parse.c" + /* No destructor defined for GROUP */ + /* No destructor defined for BY */ break; case 150: -#line 446 "parse.y" -{yygotominor.yy280.limit = -1; yygotominor.yy280.offset = 0;} -#line 2836 "parse.c" +#line 465 "parse.y" +{yygotominor.yy242 = 0;} +#line 2795 "parse.c" break; case 151: -#line 447 "parse.y" -{yygotominor.yy280.limit = yymsp[0].minor.yy52; yygotominor.yy280.offset = 0;} -#line 2841 "parse.c" - /* No destructor defined for LIMIT */ +#line 466 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 2800 "parse.c" + /* No destructor defined for HAVING */ break; case 152: -#line 449 "parse.y" -{yygotominor.yy280.limit = yymsp[-2].minor.yy52; yygotominor.yy280.offset = yymsp[0].minor.yy52;} -#line 2847 "parse.c" +#line 469 "parse.y" +{yygotominor.yy124.limit = -1; yygotominor.yy124.offset = 0;} +#line 2806 "parse.c" + break; + case 153: +#line 470 "parse.y" +{yygotominor.yy124.limit = yymsp[0].minor.yy372; yygotominor.yy124.offset = 0;} +#line 2811 "parse.c" + /* No destructor defined for LIMIT */ + break; + case 154: +#line 472 "parse.y" +{yygotominor.yy124.limit = yymsp[-2].minor.yy372; yygotominor.yy124.offset = yymsp[0].minor.yy372;} +#line 2817 "parse.c" /* No destructor defined for LIMIT */ /* No destructor defined for OFFSET */ break; - case 153: -#line 451 "parse.y" -{yygotominor.yy280.limit = yymsp[0].minor.yy52; yygotominor.yy280.offset = yymsp[-2].minor.yy52;} -#line 2854 "parse.c" + case 155: +#line 474 "parse.y" +{yygotominor.yy124.limit = yymsp[0].minor.yy372; yygotominor.yy124.offset = yymsp[-2].minor.yy372;} +#line 2824 "parse.c" /* No destructor defined for LIMIT */ /* No destructor defined for COMMA */ break; - case 154: -#line 455 "parse.y" + case 156: +#line 478 "parse.y" { - sqliteDeleteFrom(pParse, sqliteSrcListAppend(0,&yymsp[-2].minor.yy210,&yymsp[-1].minor.yy210), yymsp[0].minor.yy334); + sqliteDeleteFrom(pParse, sqliteSrcListAppend(0,&yymsp[-2].minor.yy298,&yymsp[-1].minor.yy298), yymsp[0].minor.yy242); } -#line 2863 "parse.c" +#line 2833 "parse.c" /* No destructor defined for DELETE */ /* No destructor defined for FROM */ break; - case 155: -#line 462 "parse.y" -{yygotominor.yy334 = 0;} -#line 2870 "parse.c" + case 157: +#line 485 "parse.y" +{yygotominor.yy242 = 0;} +#line 2840 "parse.c" break; - case 156: -#line 463 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 2875 "parse.c" + case 158: +#line 486 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 2845 "parse.c" /* No destructor defined for WHERE */ break; - case 157: -#line 471 "parse.y" -{sqliteUpdate(pParse,sqliteSrcListAppend(0,&yymsp[-4].minor.yy210,&yymsp[-3].minor.yy210),yymsp[-1].minor.yy62,yymsp[0].minor.yy334,yymsp[-5].minor.yy52);} -#line 2881 "parse.c" + case 159: +#line 494 "parse.y" +{sqliteUpdate(pParse,sqliteSrcListAppend(0,&yymsp[-4].minor.yy298,&yymsp[-3].minor.yy298),yymsp[-1].minor.yy322,yymsp[0].minor.yy242,yymsp[-5].minor.yy372);} +#line 2851 "parse.c" /* No destructor defined for UPDATE */ /* No destructor defined for SET */ break; - case 158: -#line 474 "parse.y" -{yygotominor.yy62 = sqliteExprListAppend(yymsp[-4].minor.yy62,yymsp[0].minor.yy334,&yymsp[-2].minor.yy210);} -#line 2888 "parse.c" + case 160: +#line 497 "parse.y" +{yygotominor.yy322 = sqliteExprListAppend(yymsp[-4].minor.yy322,yymsp[0].minor.yy242,&yymsp[-2].minor.yy298);} +#line 2858 "parse.c" /* No destructor defined for COMMA */ /* No destructor defined for EQ */ break; - case 159: -#line 475 "parse.y" -{yygotominor.yy62 = sqliteExprListAppend(0,yymsp[0].minor.yy334,&yymsp[-2].minor.yy210);} -#line 2895 "parse.c" + case 161: +#line 498 "parse.y" +{yygotominor.yy322 = sqliteExprListAppend(0,yymsp[0].minor.yy242,&yymsp[-2].minor.yy298);} +#line 2865 "parse.c" /* No destructor defined for EQ */ break; - case 160: -#line 481 "parse.y" -{sqliteInsert(pParse, sqliteSrcListAppend(0,&yymsp[-6].minor.yy210,&yymsp[-5].minor.yy210), yymsp[-1].minor.yy62, 0, yymsp[-4].minor.yy92, yymsp[-8].minor.yy52);} -#line 2901 "parse.c" + case 162: +#line 504 "parse.y" +{sqliteInsert(pParse, sqliteSrcListAppend(0,&yymsp[-6].minor.yy298,&yymsp[-5].minor.yy298), yymsp[-1].minor.yy322, 0, yymsp[-4].minor.yy320, yymsp[-8].minor.yy372);} +#line 2871 "parse.c" /* No destructor defined for INTO */ /* No destructor defined for VALUES */ /* No destructor defined for LP */ /* No destructor defined for RP */ break; - case 161: -#line 483 "parse.y" -{sqliteInsert(pParse, sqliteSrcListAppend(0,&yymsp[-3].minor.yy210,&yymsp[-2].minor.yy210), 0, yymsp[0].minor.yy11, yymsp[-1].minor.yy92, yymsp[-5].minor.yy52);} -#line 2910 "parse.c" - /* No destructor defined for INTO */ - break; - case 162: -#line 486 "parse.y" -{yygotominor.yy52 = yymsp[0].minor.yy52;} -#line 2916 "parse.c" - /* No destructor defined for INSERT */ - break; case 163: -#line 487 "parse.y" -{yygotominor.yy52 = OE_Replace;} -#line 2922 "parse.c" - /* No destructor defined for REPLACE */ +#line 506 "parse.y" +{sqliteInsert(pParse, sqliteSrcListAppend(0,&yymsp[-3].minor.yy298,&yymsp[-2].minor.yy298), 0, yymsp[0].minor.yy179, yymsp[-1].minor.yy320, yymsp[-5].minor.yy372);} +#line 2880 "parse.c" + /* No destructor defined for INTO */ break; case 164: -#line 493 "parse.y" -{yygotominor.yy62 = sqliteExprListAppend(yymsp[-2].minor.yy62,yymsp[0].minor.yy334,0);} -#line 2928 "parse.c" - /* No destructor defined for COMMA */ +#line 509 "parse.y" +{yygotominor.yy372 = yymsp[0].minor.yy372;} +#line 2886 "parse.c" + /* No destructor defined for INSERT */ break; case 165: -#line 494 "parse.y" -{yygotominor.yy62 = sqliteExprListAppend(0,yymsp[0].minor.yy334,0);} -#line 2934 "parse.c" +#line 510 "parse.y" +{yygotominor.yy372 = OE_Replace;} +#line 2892 "parse.c" + /* No destructor defined for REPLACE */ break; case 166: -#line 501 "parse.y" -{yygotominor.yy92 = 0;} -#line 2939 "parse.c" +#line 516 "parse.y" +{yygotominor.yy322 = sqliteExprListAppend(yymsp[-2].minor.yy322,yymsp[0].minor.yy242,0);} +#line 2898 "parse.c" + /* No destructor defined for COMMA */ break; case 167: -#line 502 "parse.y" -{yygotominor.yy92 = yymsp[-1].minor.yy92;} -#line 2944 "parse.c" - /* No destructor defined for LP */ - /* No destructor defined for RP */ +#line 517 "parse.y" +{yygotominor.yy322 = sqliteExprListAppend(0,yymsp[0].minor.yy242,0);} +#line 2904 "parse.c" break; case 168: -#line 503 "parse.y" -{yygotominor.yy92 = sqliteIdListAppend(yymsp[-2].minor.yy92,&yymsp[0].minor.yy210);} -#line 2951 "parse.c" - /* No destructor defined for COMMA */ +#line 524 "parse.y" +{yygotominor.yy320 = 0;} +#line 2909 "parse.c" break; case 169: -#line 504 "parse.y" -{yygotominor.yy92 = sqliteIdListAppend(0,&yymsp[0].minor.yy210);} -#line 2957 "parse.c" +#line 525 "parse.y" +{yygotominor.yy320 = yymsp[-1].minor.yy320;} +#line 2914 "parse.c" + /* No destructor defined for LP */ + /* No destructor defined for RP */ break; case 170: -#line 522 "parse.y" -{yygotominor.yy334 = yymsp[-1].minor.yy334; sqliteExprSpan(yygotominor.yy334,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } -#line 2962 "parse.c" +#line 526 "parse.y" +{yygotominor.yy320 = sqliteIdListAppend(yymsp[-2].minor.yy320,&yymsp[0].minor.yy298);} +#line 2921 "parse.c" + /* No destructor defined for COMMA */ break; case 171: -#line 523 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_NULL, 0, 0, &yymsp[0].minor.yy0);} -#line 2967 "parse.c" +#line 527 "parse.y" +{yygotominor.yy320 = sqliteIdListAppend(0,&yymsp[0].minor.yy298);} +#line 2927 "parse.c" break; case 172: -#line 524 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} -#line 2972 "parse.c" +#line 535 "parse.y" +{yygotominor.yy242 = yymsp[-1].minor.yy242; sqliteExprSpan(yygotominor.yy242,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } +#line 2932 "parse.c" break; case 173: -#line 525 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} -#line 2977 "parse.c" +#line 536 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_NULL, 0, 0, &yymsp[0].minor.yy0);} +#line 2937 "parse.c" break; case 174: -#line 526 "parse.y" +#line 537 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} +#line 2942 "parse.c" + break; + case 175: +#line 538 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} +#line 2947 "parse.c" + break; + case 176: +#line 539 "parse.y" { - Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &yymsp[-2].minor.yy210); - Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy210); - yygotominor.yy334 = sqliteExpr(TK_DOT, temp1, temp2, 0); + Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &yymsp[-2].minor.yy298); + Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy298); + yygotominor.yy242 = sqliteExpr(TK_DOT, temp1, temp2, 0); } -#line 2986 "parse.c" +#line 2956 "parse.c" /* No destructor defined for DOT */ break; - case 175: -#line 531 "parse.y" + case 177: +#line 544 "parse.y" { - Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &yymsp[-4].minor.yy210); - Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &yymsp[-2].minor.yy210); - Expr *temp3 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy210); + Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &yymsp[-4].minor.yy298); + Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &yymsp[-2].minor.yy298); + Expr *temp3 = sqliteExpr(TK_ID, 0, 0, &yymsp[0].minor.yy298); Expr *temp4 = sqliteExpr(TK_DOT, temp2, temp3, 0); - yygotominor.yy334 = sqliteExpr(TK_DOT, temp1, temp4, 0); + yygotominor.yy242 = sqliteExpr(TK_DOT, temp1, temp4, 0); } -#line 2998 "parse.c" +#line 2968 "parse.c" /* No destructor defined for DOT */ /* No destructor defined for DOT */ break; - case 176: -#line 538 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_INTEGER, 0, 0, &yymsp[0].minor.yy0);} -#line 3005 "parse.c" - break; - case 177: -#line 539 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_FLOAT, 0, 0, &yymsp[0].minor.yy0);} -#line 3010 "parse.c" - break; case 178: -#line 540 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_STRING, 0, 0, &yymsp[0].minor.yy0);} -#line 3015 "parse.c" +#line 551 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_INTEGER, 0, 0, &yymsp[0].minor.yy0);} +#line 2975 "parse.c" break; case 179: -#line 541 "parse.y" +#line 552 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_FLOAT, 0, 0, &yymsp[0].minor.yy0);} +#line 2980 "parse.c" + break; + case 180: +#line 553 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_STRING, 0, 0, &yymsp[0].minor.yy0);} +#line 2985 "parse.c" + break; + case 181: +#line 554 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_VARIABLE, 0, 0, &yymsp[0].minor.yy0); - if( yygotominor.yy334 ) yygotominor.yy334->iTable = ++pParse->nVar; + yygotominor.yy242 = sqliteExpr(TK_VARIABLE, 0, 0, &yymsp[0].minor.yy0); + if( yygotominor.yy242 ) yygotominor.yy242->iTable = ++pParse->nVar; } -#line 3023 "parse.c" +#line 2993 "parse.c" break; - case 180: -#line 545 "parse.y" + case 182: +#line 558 "parse.y" { - yygotominor.yy334 = sqliteExprFunction(yymsp[-1].minor.yy62, &yymsp[-3].minor.yy0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExprFunction(yymsp[-1].minor.yy322, &yymsp[-3].minor.yy0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } -#line 3031 "parse.c" +#line 3001 "parse.c" /* No destructor defined for LP */ break; - case 181: -#line 549 "parse.y" + case 183: +#line 562 "parse.y" { - yygotominor.yy334 = sqliteExprFunction(0, &yymsp[-3].minor.yy0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExprFunction(0, &yymsp[-3].minor.yy0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } -#line 3040 "parse.c" +#line 3010 "parse.c" /* No destructor defined for LP */ /* No destructor defined for STAR */ break; - case 182: -#line 553 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_AND, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3047 "parse.c" + case 184: +#line 566 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_AND, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3017 "parse.c" /* No destructor defined for AND */ break; - case 183: -#line 554 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_OR, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3053 "parse.c" + case 185: +#line 567 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_OR, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3023 "parse.c" /* No destructor defined for OR */ break; - case 184: -#line 555 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_LT, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3059 "parse.c" + case 186: +#line 568 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_LT, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3029 "parse.c" /* No destructor defined for LT */ break; - case 185: -#line 556 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_GT, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3065 "parse.c" + case 187: +#line 569 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_GT, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3035 "parse.c" /* No destructor defined for GT */ break; - case 186: -#line 557 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_LE, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3071 "parse.c" + case 188: +#line 570 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_LE, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3041 "parse.c" /* No destructor defined for LE */ break; - case 187: -#line 558 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_GE, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3077 "parse.c" + case 189: +#line 571 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_GE, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3047 "parse.c" /* No destructor defined for GE */ break; - case 188: -#line 559 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_NE, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3083 "parse.c" + case 190: +#line 572 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_NE, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3053 "parse.c" /* No destructor defined for NE */ break; - case 189: -#line 560 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_EQ, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3089 "parse.c" + case 191: +#line 573 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_EQ, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3059 "parse.c" /* No destructor defined for EQ */ break; - case 190: -#line 561 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_BITAND, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3095 "parse.c" + case 192: +#line 574 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_BITAND, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3065 "parse.c" /* No destructor defined for BITAND */ break; - case 191: -#line 562 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_BITOR, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3101 "parse.c" + case 193: +#line 575 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_BITOR, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3071 "parse.c" /* No destructor defined for BITOR */ break; - case 192: -#line 563 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_LSHIFT, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3107 "parse.c" + case 194: +#line 576 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_LSHIFT, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3077 "parse.c" /* No destructor defined for LSHIFT */ break; - case 193: -#line 564 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_RSHIFT, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3113 "parse.c" + case 195: +#line 577 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_RSHIFT, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3083 "parse.c" /* No destructor defined for RSHIFT */ break; - case 194: -#line 565 "parse.y" + case 196: +#line 578 "parse.y" { - ExprList *pList = sqliteExprListAppend(0, yymsp[0].minor.yy334, 0); - pList = sqliteExprListAppend(pList, yymsp[-2].minor.yy334, 0); - yygotominor.yy334 = sqliteExprFunction(pList, 0); - if( yygotominor.yy334 ) yygotominor.yy334->op = yymsp[-1].minor.yy52; - sqliteExprSpan(yygotominor.yy334, &yymsp[-2].minor.yy334->span, &yymsp[0].minor.yy334->span); + ExprList *pList = sqliteExprListAppend(0, yymsp[0].minor.yy242, 0); + pList = sqliteExprListAppend(pList, yymsp[-2].minor.yy242, 0); + yygotominor.yy242 = sqliteExprFunction(pList, 0); + if( yygotominor.yy242 ) yygotominor.yy242->op = yymsp[-1].minor.yy372; + sqliteExprSpan(yygotominor.yy242, &yymsp[-2].minor.yy242->span, &yymsp[0].minor.yy242->span); } -#line 3125 "parse.c" +#line 3095 "parse.c" break; - case 195: -#line 572 "parse.y" + case 197: +#line 585 "parse.y" { - ExprList *pList = sqliteExprListAppend(0, yymsp[0].minor.yy334, 0); - pList = sqliteExprListAppend(pList, yymsp[-3].minor.yy334, 0); - yygotominor.yy334 = sqliteExprFunction(pList, 0); - if( yygotominor.yy334 ) yygotominor.yy334->op = yymsp[-1].minor.yy52; - yygotominor.yy334 = sqliteExpr(TK_NOT, yygotominor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-3].minor.yy334->span,&yymsp[0].minor.yy334->span); + ExprList *pList = sqliteExprListAppend(0, yymsp[0].minor.yy242, 0); + pList = sqliteExprListAppend(pList, yymsp[-3].minor.yy242, 0); + yygotominor.yy242 = sqliteExprFunction(pList, 0); + if( yygotominor.yy242 ) yygotominor.yy242->op = yymsp[-1].minor.yy372; + yygotominor.yy242 = sqliteExpr(TK_NOT, yygotominor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-3].minor.yy242->span,&yymsp[0].minor.yy242->span); } -#line 3137 "parse.c" +#line 3107 "parse.c" /* No destructor defined for NOT */ break; - case 196: -#line 581 "parse.y" -{yygotominor.yy52 = TK_LIKE;} -#line 3143 "parse.c" - /* No destructor defined for LIKE */ - break; - case 197: -#line 582 "parse.y" -{yygotominor.yy52 = TK_GLOB;} -#line 3149 "parse.c" - /* No destructor defined for GLOB */ - break; case 198: -#line 583 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_PLUS, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3155 "parse.c" - /* No destructor defined for PLUS */ +#line 594 "parse.y" +{yygotominor.yy372 = TK_LIKE;} +#line 3113 "parse.c" + /* No destructor defined for LIKE */ break; case 199: -#line 584 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_MINUS, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3161 "parse.c" - /* No destructor defined for MINUS */ +#line 595 "parse.y" +{yygotominor.yy372 = TK_GLOB;} +#line 3119 "parse.c" + /* No destructor defined for GLOB */ break; case 200: -#line 585 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_STAR, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3167 "parse.c" - /* No destructor defined for STAR */ +#line 596 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_PLUS, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3125 "parse.c" + /* No destructor defined for PLUS */ break; case 201: -#line 586 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_SLASH, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3173 "parse.c" - /* No destructor defined for SLASH */ +#line 597 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_MINUS, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3131 "parse.c" + /* No destructor defined for MINUS */ break; case 202: -#line 587 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_REM, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3179 "parse.c" - /* No destructor defined for REM */ +#line 598 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_STAR, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3137 "parse.c" + /* No destructor defined for STAR */ break; case 203: -#line 588 "parse.y" -{yygotominor.yy334 = sqliteExpr(TK_CONCAT, yymsp[-2].minor.yy334, yymsp[0].minor.yy334, 0);} -#line 3185 "parse.c" - /* No destructor defined for CONCAT */ +#line 599 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_SLASH, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3143 "parse.c" + /* No destructor defined for SLASH */ break; case 204: -#line 589 "parse.y" -{ - yygotominor.yy334 = sqliteExpr(TK_ISNULL, yymsp[-1].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-1].minor.yy334->span,&yymsp[0].minor.yy0); -} -#line 3194 "parse.c" +#line 600 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_REM, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3149 "parse.c" + /* No destructor defined for REM */ break; case 205: -#line 593 "parse.y" -{ - yygotominor.yy334 = sqliteExpr(TK_ISNULL, yymsp[-2].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-2].minor.yy334->span,&yymsp[0].minor.yy0); -} -#line 3202 "parse.c" - /* No destructor defined for IS */ +#line 601 "parse.y" +{yygotominor.yy242 = sqliteExpr(TK_CONCAT, yymsp[-2].minor.yy242, yymsp[0].minor.yy242, 0);} +#line 3155 "parse.c" + /* No destructor defined for CONCAT */ break; case 206: -#line 597 "parse.y" +#line 602 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_NOTNULL, yymsp[-1].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-1].minor.yy334->span,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_ISNULL, yymsp[-1].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-1].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3211 "parse.c" +#line 3164 "parse.c" break; case 207: -#line 601 "parse.y" +#line 606 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_NOTNULL, yymsp[-2].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-2].minor.yy334->span,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_ISNULL, yymsp[-2].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-2].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3219 "parse.c" - /* No destructor defined for NOT */ +#line 3172 "parse.c" + /* No destructor defined for IS */ break; case 208: -#line 605 "parse.y" +#line 610 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_NOTNULL, yymsp[-3].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-3].minor.yy334->span,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_NOTNULL, yymsp[-1].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-1].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3228 "parse.c" - /* No destructor defined for IS */ - /* No destructor defined for NOT */ +#line 3181 "parse.c" break; case 209: -#line 609 "parse.y" +#line 614 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_NOT, yymsp[0].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy334->span); + yygotominor.yy242 = sqliteExpr(TK_NOTNULL, yymsp[-2].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-2].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3238 "parse.c" +#line 3189 "parse.c" + /* No destructor defined for NOT */ break; case 210: -#line 613 "parse.y" +#line 618 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_BITNOT, yymsp[0].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy334->span); + yygotominor.yy242 = sqliteExpr(TK_NOTNULL, yymsp[-3].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-3].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3246 "parse.c" +#line 3198 "parse.c" + /* No destructor defined for IS */ + /* No destructor defined for NOT */ break; case 211: -#line 617 "parse.y" +#line 622 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_UMINUS, yymsp[0].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy334->span); + yygotominor.yy242 = sqliteExpr(TK_NOT, yymsp[0].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy242->span); } -#line 3254 "parse.c" +#line 3208 "parse.c" break; case 212: -#line 621 "parse.y" +#line 626 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_UPLUS, yymsp[0].minor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy334->span); + yygotominor.yy242 = sqliteExpr(TK_BITNOT, yymsp[0].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy242->span); } -#line 3262 "parse.c" +#line 3216 "parse.c" break; case 213: -#line 625 "parse.y" +#line 630 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_SELECT, 0, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pSelect = yymsp[-1].minor.yy11; - sqliteExprSpan(yygotominor.yy334,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_UMINUS, yymsp[0].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy242->span); } -#line 3271 "parse.c" +#line 3224 "parse.c" break; case 214: -#line 630 "parse.y" +#line 634 "parse.y" { - ExprList *pList = sqliteExprListAppend(0, yymsp[-2].minor.yy334, 0); - pList = sqliteExprListAppend(pList, yymsp[0].minor.yy334, 0); - yygotominor.yy334 = sqliteExpr(TK_BETWEEN, yymsp[-4].minor.yy334, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pList = pList; - sqliteExprSpan(yygotominor.yy334,&yymsp[-4].minor.yy334->span,&yymsp[0].minor.yy334->span); + yygotominor.yy242 = sqliteExpr(TK_UPLUS, yymsp[0].minor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy242->span); } -#line 3282 "parse.c" - /* No destructor defined for BETWEEN */ - /* No destructor defined for AND */ +#line 3232 "parse.c" break; case 215: -#line 637 "parse.y" +#line 638 "parse.y" { - ExprList *pList = sqliteExprListAppend(0, yymsp[-2].minor.yy334, 0); - pList = sqliteExprListAppend(pList, yymsp[0].minor.yy334, 0); - yygotominor.yy334 = sqliteExpr(TK_BETWEEN, yymsp[-5].minor.yy334, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pList = pList; - yygotominor.yy334 = sqliteExpr(TK_NOT, yygotominor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-5].minor.yy334->span,&yymsp[0].minor.yy334->span); -} -#line 3296 "parse.c" - /* No destructor defined for NOT */ - /* No destructor defined for BETWEEN */ - /* No destructor defined for AND */ + yygotominor.yy242 = sqliteExpr(TK_SELECT, 0, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pSelect = yymsp[-1].minor.yy179; + sqliteExprSpan(yygotominor.yy242,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); +} +#line 3241 "parse.c" break; case 216: -#line 645 "parse.y" +#line 643 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_IN, yymsp[-4].minor.yy334, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pList = yymsp[-1].minor.yy62; - sqliteExprSpan(yygotominor.yy334,&yymsp[-4].minor.yy334->span,&yymsp[0].minor.yy0); + ExprList *pList = sqliteExprListAppend(0, yymsp[-2].minor.yy242, 0); + pList = sqliteExprListAppend(pList, yymsp[0].minor.yy242, 0); + yygotominor.yy242 = sqliteExpr(TK_BETWEEN, yymsp[-4].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pList = pList; + sqliteExprSpan(yygotominor.yy242,&yymsp[-4].minor.yy242->span,&yymsp[0].minor.yy242->span); } -#line 3308 "parse.c" - /* No destructor defined for IN */ - /* No destructor defined for LP */ +#line 3252 "parse.c" + /* No destructor defined for BETWEEN */ + /* No destructor defined for AND */ break; case 217: #line 650 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_IN, yymsp[-4].minor.yy334, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pSelect = yymsp[-1].minor.yy11; - sqliteExprSpan(yygotominor.yy334,&yymsp[-4].minor.yy334->span,&yymsp[0].minor.yy0); -} -#line 3319 "parse.c" - /* No destructor defined for IN */ - /* No destructor defined for LP */ + ExprList *pList = sqliteExprListAppend(0, yymsp[-2].minor.yy242, 0); + pList = sqliteExprListAppend(pList, yymsp[0].minor.yy242, 0); + yygotominor.yy242 = sqliteExpr(TK_BETWEEN, yymsp[-5].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pList = pList; + yygotominor.yy242 = sqliteExpr(TK_NOT, yygotominor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-5].minor.yy242->span,&yymsp[0].minor.yy242->span); +} +#line 3266 "parse.c" + /* No destructor defined for NOT */ + /* No destructor defined for BETWEEN */ + /* No destructor defined for AND */ break; case 218: -#line 655 "parse.y" +#line 658 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_IN, yymsp[-5].minor.yy334, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pList = yymsp[-1].minor.yy62; - yygotominor.yy334 = sqliteExpr(TK_NOT, yygotominor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-5].minor.yy334->span,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_IN, yymsp[-4].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pList = yymsp[-1].minor.yy322; + sqliteExprSpan(yygotominor.yy242,&yymsp[-4].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3331 "parse.c" - /* No destructor defined for NOT */ +#line 3278 "parse.c" /* No destructor defined for IN */ /* No destructor defined for LP */ break; case 219: -#line 661 "parse.y" +#line 663 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_IN, yymsp[-5].minor.yy334, 0, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pSelect = yymsp[-1].minor.yy11; - yygotominor.yy334 = sqliteExpr(TK_NOT, yygotominor.yy334, 0, 0); - sqliteExprSpan(yygotominor.yy334,&yymsp[-5].minor.yy334->span,&yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_IN, yymsp[-4].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pSelect = yymsp[-1].minor.yy179; + sqliteExprSpan(yygotominor.yy242,&yymsp[-4].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3344 "parse.c" - /* No destructor defined for NOT */ +#line 3289 "parse.c" /* No destructor defined for IN */ /* No destructor defined for LP */ break; case 220: -#line 669 "parse.y" +#line 668 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_CASE, yymsp[-3].minor.yy334, yymsp[-1].minor.yy334, 0); - if( yygotominor.yy334 ) yygotominor.yy334->pList = yymsp[-2].minor.yy62; - sqliteExprSpan(yygotominor.yy334, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_IN, yymsp[-5].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pList = yymsp[-1].minor.yy322; + yygotominor.yy242 = sqliteExpr(TK_NOT, yygotominor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-5].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3356 "parse.c" +#line 3301 "parse.c" + /* No destructor defined for NOT */ + /* No destructor defined for IN */ + /* No destructor defined for LP */ break; case 221: -#line 676 "parse.y" +#line 674 "parse.y" { - yygotominor.yy62 = sqliteExprListAppend(yymsp[-4].minor.yy62, yymsp[-2].minor.yy334, 0); - yygotominor.yy62 = sqliteExprListAppend(yygotominor.yy62, yymsp[0].minor.yy334, 0); + yygotominor.yy242 = sqliteExpr(TK_IN, yymsp[-5].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pSelect = yymsp[-1].minor.yy179; + yygotominor.yy242 = sqliteExpr(TK_NOT, yygotominor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-5].minor.yy242->span,&yymsp[0].minor.yy0); } -#line 3364 "parse.c" - /* No destructor defined for WHEN */ - /* No destructor defined for THEN */ +#line 3314 "parse.c" + /* No destructor defined for NOT */ + /* No destructor defined for IN */ + /* No destructor defined for LP */ break; case 222: #line 680 "parse.y" { - yygotominor.yy62 = sqliteExprListAppend(0, yymsp[-2].minor.yy334, 0); - yygotominor.yy62 = sqliteExprListAppend(yygotominor.yy62, yymsp[0].minor.yy334, 0); + SrcList *pSrc = sqliteSrcListAppend(0, &yymsp[-1].minor.yy298, &yymsp[0].minor.yy298); + yygotominor.yy242 = sqliteExpr(TK_IN, yymsp[-3].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-3].minor.yy242->span,yymsp[0].minor.yy298.z?&yymsp[0].minor.yy298:&yymsp[-1].minor.yy298); } -#line 3374 "parse.c" - /* No destructor defined for WHEN */ - /* No destructor defined for THEN */ +#line 3327 "parse.c" + /* No destructor defined for IN */ break; case 223: -#line 685 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 3381 "parse.c" - /* No destructor defined for ELSE */ +#line 686 "parse.y" +{ + SrcList *pSrc = sqliteSrcListAppend(0, &yymsp[-1].minor.yy298, &yymsp[0].minor.yy298); + yygotominor.yy242 = sqliteExpr(TK_IN, yymsp[-4].minor.yy242, 0, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0); + yygotominor.yy242 = sqliteExpr(TK_NOT, yygotominor.yy242, 0, 0); + sqliteExprSpan(yygotominor.yy242,&yymsp[-4].minor.yy242->span,yymsp[0].minor.yy298.z?&yymsp[0].minor.yy298:&yymsp[-1].minor.yy298); +} +#line 3339 "parse.c" + /* No destructor defined for NOT */ + /* No destructor defined for IN */ break; case 224: -#line 686 "parse.y" -{yygotominor.yy334 = 0;} -#line 3387 "parse.c" +#line 696 "parse.y" +{ + yygotominor.yy242 = sqliteExpr(TK_CASE, yymsp[-3].minor.yy242, yymsp[-1].minor.yy242, 0); + if( yygotominor.yy242 ) yygotominor.yy242->pList = yymsp[-2].minor.yy322; + sqliteExprSpan(yygotominor.yy242, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); +} +#line 3350 "parse.c" break; case 225: -#line 688 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 3392 "parse.c" +#line 703 "parse.y" +{ + yygotominor.yy322 = sqliteExprListAppend(yymsp[-4].minor.yy322, yymsp[-2].minor.yy242, 0); + yygotominor.yy322 = sqliteExprListAppend(yygotominor.yy322, yymsp[0].minor.yy242, 0); +} +#line 3358 "parse.c" + /* No destructor defined for WHEN */ + /* No destructor defined for THEN */ break; case 226: -#line 689 "parse.y" -{yygotominor.yy334 = 0;} -#line 3397 "parse.c" +#line 707 "parse.y" +{ + yygotominor.yy322 = sqliteExprListAppend(0, yymsp[-2].minor.yy242, 0); + yygotominor.yy322 = sqliteExprListAppend(yygotominor.yy322, yymsp[0].minor.yy242, 0); +} +#line 3368 "parse.c" + /* No destructor defined for WHEN */ + /* No destructor defined for THEN */ break; case 227: -#line 697 "parse.y" -{yygotominor.yy62 = sqliteExprListAppend(yymsp[-2].minor.yy62,yymsp[0].minor.yy334,0);} -#line 3402 "parse.c" - /* No destructor defined for COMMA */ +#line 712 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 3375 "parse.c" + /* No destructor defined for ELSE */ break; case 228: -#line 698 "parse.y" -{yygotominor.yy62 = sqliteExprListAppend(0,yymsp[0].minor.yy334,0);} -#line 3408 "parse.c" +#line 713 "parse.y" +{yygotominor.yy242 = 0;} +#line 3381 "parse.c" break; case 229: -#line 699 "parse.y" -{yygotominor.yy334 = yymsp[0].minor.yy334;} -#line 3413 "parse.c" +#line 715 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 3386 "parse.c" break; case 230: -#line 700 "parse.y" -{yygotominor.yy334 = 0;} -#line 3418 "parse.c" +#line 716 "parse.y" +{yygotominor.yy242 = 0;} +#line 3391 "parse.c" break; case 231: -#line 705 "parse.y" +#line 724 "parse.y" +{yygotominor.yy322 = sqliteExprListAppend(yymsp[-2].minor.yy322,yymsp[0].minor.yy242,0);} +#line 3396 "parse.c" + /* No destructor defined for COMMA */ + break; + case 232: +#line 725 "parse.y" +{yygotominor.yy322 = sqliteExprListAppend(0,yymsp[0].minor.yy242,0);} +#line 3402 "parse.c" + break; + case 233: +#line 726 "parse.y" +{yygotominor.yy242 = yymsp[0].minor.yy242;} +#line 3407 "parse.c" + break; + case 234: +#line 727 "parse.y" +{yygotominor.yy242 = 0;} +#line 3412 "parse.c" + break; + case 235: +#line 732 "parse.y" { - SrcList *pSrc = sqliteSrcListAppend(0, &yymsp[-5].minor.yy210, &yymsp[-4].minor.yy210); - if( yymsp[-9].minor.yy52!=OE_None ) yymsp[-9].minor.yy52 = yymsp[0].minor.yy52; - if( yymsp[-9].minor.yy52==OE_Default) yymsp[-9].minor.yy52 = OE_Abort; - sqliteCreateIndex(pParse, &yymsp[-7].minor.yy210, pSrc, yymsp[-2].minor.yy92, yymsp[-9].minor.yy52, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0); + SrcList *pSrc = sqliteSrcListAppend(0, &yymsp[-5].minor.yy298, &yymsp[-4].minor.yy298); + if( yymsp[-9].minor.yy372!=OE_None ) yymsp[-9].minor.yy372 = yymsp[0].minor.yy372; + if( yymsp[-9].minor.yy372==OE_Default) yymsp[-9].minor.yy372 = OE_Abort; + sqliteCreateIndex(pParse, &yymsp[-7].minor.yy298, pSrc, yymsp[-2].minor.yy320, yymsp[-9].minor.yy372, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0); } -#line 3428 "parse.c" +#line 3422 "parse.c" /* No destructor defined for INDEX */ /* No destructor defined for ON */ /* No destructor defined for LP */ break; - case 232: -#line 713 "parse.y" -{ yygotominor.yy52 = OE_Abort; } -#line 3436 "parse.c" + case 236: +#line 740 "parse.y" +{ yygotominor.yy372 = OE_Abort; } +#line 3430 "parse.c" /* No destructor defined for UNIQUE */ break; - case 233: -#line 714 "parse.y" -{ yygotominor.yy52 = OE_None; } -#line 3442 "parse.c" + case 237: +#line 741 "parse.y" +{ yygotominor.yy372 = OE_None; } +#line 3436 "parse.c" break; - case 234: -#line 722 "parse.y" -{yygotominor.yy92 = 0;} -#line 3447 "parse.c" + case 238: +#line 749 "parse.y" +{yygotominor.yy320 = 0;} +#line 3441 "parse.c" break; - case 235: -#line 723 "parse.y" -{yygotominor.yy92 = yymsp[-1].minor.yy92;} -#line 3452 "parse.c" + case 239: +#line 750 "parse.y" +{yygotominor.yy320 = yymsp[-1].minor.yy320;} +#line 3446 "parse.c" /* No destructor defined for LP */ /* No destructor defined for RP */ break; - case 236: -#line 724 "parse.y" -{yygotominor.yy92 = sqliteIdListAppend(yymsp[-2].minor.yy92,&yymsp[0].minor.yy210);} -#line 3459 "parse.c" + case 240: +#line 751 "parse.y" +{yygotominor.yy320 = sqliteIdListAppend(yymsp[-2].minor.yy320,&yymsp[0].minor.yy298);} +#line 3453 "parse.c" /* No destructor defined for COMMA */ break; - case 237: -#line 725 "parse.y" -{yygotominor.yy92 = sqliteIdListAppend(0,&yymsp[0].minor.yy210);} -#line 3465 "parse.c" + case 241: +#line 752 "parse.y" +{yygotominor.yy320 = sqliteIdListAppend(0,&yymsp[0].minor.yy298);} +#line 3459 "parse.c" break; - case 238: -#line 726 "parse.y" -{yygotominor.yy210 = yymsp[-1].minor.yy210;} -#line 3470 "parse.c" + case 242: +#line 753 "parse.y" +{yygotominor.yy298 = yymsp[-1].minor.yy298;} +#line 3464 "parse.c" /* No destructor defined for sortorder */ break; - case 239: -#line 731 "parse.y" + case 243: +#line 758 "parse.y" { - sqliteDropIndex(pParse, sqliteSrcListAppend(0,&yymsp[-1].minor.yy210,&yymsp[0].minor.yy210)); + sqliteDropIndex(pParse, sqliteSrcListAppend(0,&yymsp[-1].minor.yy298,&yymsp[0].minor.yy298)); } -#line 3478 "parse.c" +#line 3472 "parse.c" /* No destructor defined for DROP */ /* No destructor defined for INDEX */ break; - case 240: -#line 739 "parse.y" -{sqliteCopy(pParse,sqliteSrcListAppend(0,&yymsp[-6].minor.yy210,&yymsp[-5].minor.yy210),&yymsp[-3].minor.yy210,&yymsp[0].minor.yy0,yymsp[-7].minor.yy52);} -#line 3485 "parse.c" + case 244: +#line 766 "parse.y" +{sqliteCopy(pParse,sqliteSrcListAppend(0,&yymsp[-6].minor.yy298,&yymsp[-5].minor.yy298),&yymsp[-3].minor.yy298,&yymsp[0].minor.yy0,yymsp[-7].minor.yy372);} +#line 3479 "parse.c" /* No destructor defined for COPY */ /* No destructor defined for FROM */ /* No destructor defined for USING */ /* No destructor defined for DELIMITERS */ break; - case 241: -#line 741 "parse.y" -{sqliteCopy(pParse,sqliteSrcListAppend(0,&yymsp[-3].minor.yy210,&yymsp[-2].minor.yy210),&yymsp[0].minor.yy210,0,yymsp[-4].minor.yy52);} -#line 3494 "parse.c" + case 245: +#line 768 "parse.y" +{sqliteCopy(pParse,sqliteSrcListAppend(0,&yymsp[-3].minor.yy298,&yymsp[-2].minor.yy298),&yymsp[0].minor.yy298,0,yymsp[-4].minor.yy372);} +#line 3488 "parse.c" /* No destructor defined for COPY */ /* No destructor defined for FROM */ break; - case 242: -#line 745 "parse.y" + case 246: +#line 772 "parse.y" {sqliteVacuum(pParse,0);} -#line 3501 "parse.c" +#line 3495 "parse.c" /* No destructor defined for VACUUM */ break; - case 243: -#line 746 "parse.y" -{sqliteVacuum(pParse,&yymsp[0].minor.yy210);} -#line 3507 "parse.c" + case 247: +#line 773 "parse.y" +{sqliteVacuum(pParse,&yymsp[0].minor.yy298);} +#line 3501 "parse.c" /* No destructor defined for VACUUM */ break; - case 244: -#line 750 "parse.y" -{sqlitePragma(pParse,&yymsp[-2].minor.yy210,&yymsp[0].minor.yy210,0);} -#line 3513 "parse.c" + case 248: +#line 777 "parse.y" +{sqlitePragma(pParse,&yymsp[-2].minor.yy298,&yymsp[0].minor.yy298,0);} +#line 3507 "parse.c" /* No destructor defined for PRAGMA */ /* No destructor defined for EQ */ break; - case 245: -#line 751 "parse.y" -{sqlitePragma(pParse,&yymsp[-2].minor.yy210,&yymsp[0].minor.yy0,0);} -#line 3520 "parse.c" + case 249: +#line 778 "parse.y" +{sqlitePragma(pParse,&yymsp[-2].minor.yy298,&yymsp[0].minor.yy0,0);} +#line 3514 "parse.c" /* No destructor defined for PRAGMA */ /* No destructor defined for EQ */ break; - case 246: -#line 752 "parse.y" -{sqlitePragma(pParse,&yymsp[-2].minor.yy210,&yymsp[0].minor.yy210,0);} -#line 3527 "parse.c" + case 250: +#line 779 "parse.y" +{sqlitePragma(pParse,&yymsp[-2].minor.yy298,&yymsp[0].minor.yy298,0);} +#line 3521 "parse.c" /* No destructor defined for PRAGMA */ /* No destructor defined for EQ */ break; - case 247: -#line 753 "parse.y" -{sqlitePragma(pParse,&yymsp[-2].minor.yy210,&yymsp[0].minor.yy210,1);} -#line 3534 "parse.c" + case 251: +#line 780 "parse.y" +{sqlitePragma(pParse,&yymsp[-2].minor.yy298,&yymsp[0].minor.yy298,1);} +#line 3528 "parse.c" /* No destructor defined for PRAGMA */ /* No destructor defined for EQ */ break; - case 248: -#line 754 "parse.y" -{sqlitePragma(pParse,&yymsp[-3].minor.yy210,&yymsp[-1].minor.yy210,0);} -#line 3541 "parse.c" + case 252: +#line 781 "parse.y" +{sqlitePragma(pParse,&yymsp[-3].minor.yy298,&yymsp[-1].minor.yy298,0);} +#line 3535 "parse.c" /* No destructor defined for PRAGMA */ /* No destructor defined for LP */ /* No destructor defined for RP */ break; - case 249: -#line 755 "parse.y" -{sqlitePragma(pParse,&yymsp[0].minor.yy210,&yymsp[0].minor.yy210,0);} -#line 3549 "parse.c" + case 253: +#line 782 "parse.y" +{sqlitePragma(pParse,&yymsp[0].minor.yy298,&yymsp[0].minor.yy298,0);} +#line 3543 "parse.c" /* No destructor defined for PRAGMA */ break; - case 250: -#line 756 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy210;} -#line 3555 "parse.c" + case 254: +#line 783 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy298;} +#line 3549 "parse.c" /* No destructor defined for plus_opt */ break; - case 251: -#line 757 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy210;} -#line 3561 "parse.c" + case 255: +#line 784 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy298;} +#line 3555 "parse.c" /* No destructor defined for MINUS */ break; - case 252: -#line 758 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 3567 "parse.c" + case 256: +#line 785 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 3561 "parse.c" break; - case 253: -#line 759 "parse.y" -{yygotominor.yy210 = yymsp[0].minor.yy0;} -#line 3572 "parse.c" + case 257: +#line 786 "parse.y" +{yygotominor.yy298 = yymsp[0].minor.yy0;} +#line 3566 "parse.c" break; - case 254: + case 258: /* No destructor defined for PLUS */ break; - case 255: + case 259: break; - case 256: -#line 765 "parse.y" + case 260: +#line 792 "parse.y" { Token all; all.z = yymsp[-4].minor.yy0.z; all.n = (yymsp[0].minor.yy0.z - yymsp[-4].minor.yy0.z) + yymsp[0].minor.yy0.n; - sqliteFinishTrigger(pParse, yymsp[-1].minor.yy347, &all); + sqliteFinishTrigger(pParse, yymsp[-1].minor.yy19, &all); } -#line 3587 "parse.c" +#line 3581 "parse.c" /* No destructor defined for trigger_decl */ /* No destructor defined for BEGIN */ break; - case 257: -#line 773 "parse.y" + case 261: +#line 800 "parse.y" { - SrcList *pTab = sqliteSrcListAppend(0, &yymsp[-3].minor.yy210, &yymsp[-2].minor.yy210); - sqliteBeginTrigger(pParse, &yymsp[-7].minor.yy210, yymsp[-6].minor.yy52, yymsp[-5].minor.yy234.a, yymsp[-5].minor.yy234.b, pTab, yymsp[-1].minor.yy52, yymsp[0].minor.yy270, yymsp[-9].minor.yy52); + SrcList *pTab = sqliteSrcListAppend(0, &yymsp[-3].minor.yy298, &yymsp[-2].minor.yy298); + sqliteBeginTrigger(pParse, &yymsp[-7].minor.yy298, yymsp[-6].minor.yy372, yymsp[-5].minor.yy290.a, yymsp[-5].minor.yy290.b, pTab, yymsp[-1].minor.yy372, yymsp[0].minor.yy182, yymsp[-9].minor.yy372); } -#line 3597 "parse.c" +#line 3591 "parse.c" /* No destructor defined for TRIGGER */ /* No destructor defined for ON */ break; - case 258: -#line 779 "parse.y" -{ yygotominor.yy52 = TK_BEFORE; } -#line 3604 "parse.c" + case 262: +#line 806 "parse.y" +{ yygotominor.yy372 = TK_BEFORE; } +#line 3598 "parse.c" /* No destructor defined for BEFORE */ break; - case 259: -#line 780 "parse.y" -{ yygotominor.yy52 = TK_AFTER; } -#line 3610 "parse.c" + case 263: +#line 807 "parse.y" +{ yygotominor.yy372 = TK_AFTER; } +#line 3604 "parse.c" /* No destructor defined for AFTER */ break; - case 260: -#line 781 "parse.y" -{ yygotominor.yy52 = TK_INSTEAD;} -#line 3616 "parse.c" + case 264: +#line 808 "parse.y" +{ yygotominor.yy372 = TK_INSTEAD;} +#line 3610 "parse.c" /* No destructor defined for INSTEAD */ /* No destructor defined for OF */ break; - case 261: -#line 782 "parse.y" -{ yygotominor.yy52 = TK_BEFORE; } -#line 3623 "parse.c" + case 265: +#line 809 "parse.y" +{ yygotominor.yy372 = TK_BEFORE; } +#line 3617 "parse.c" break; - case 262: -#line 786 "parse.y" -{ yygotominor.yy234.a = TK_DELETE; yygotominor.yy234.b = 0; } -#line 3628 "parse.c" + case 266: +#line 813 "parse.y" +{ yygotominor.yy290.a = TK_DELETE; yygotominor.yy290.b = 0; } +#line 3622 "parse.c" /* No destructor defined for DELETE */ break; - case 263: -#line 787 "parse.y" -{ yygotominor.yy234.a = TK_INSERT; yygotominor.yy234.b = 0; } -#line 3634 "parse.c" + case 267: +#line 814 "parse.y" +{ yygotominor.yy290.a = TK_INSERT; yygotominor.yy290.b = 0; } +#line 3628 "parse.c" /* No destructor defined for INSERT */ break; - case 264: -#line 788 "parse.y" -{ yygotominor.yy234.a = TK_UPDATE; yygotominor.yy234.b = 0;} -#line 3640 "parse.c" + case 268: +#line 815 "parse.y" +{ yygotominor.yy290.a = TK_UPDATE; yygotominor.yy290.b = 0;} +#line 3634 "parse.c" /* No destructor defined for UPDATE */ break; - case 265: -#line 789 "parse.y" -{yygotominor.yy234.a = TK_UPDATE; yygotominor.yy234.b = yymsp[0].minor.yy92; } -#line 3646 "parse.c" + case 269: +#line 816 "parse.y" +{yygotominor.yy290.a = TK_UPDATE; yygotominor.yy290.b = yymsp[0].minor.yy320; } +#line 3640 "parse.c" /* No destructor defined for UPDATE */ /* No destructor defined for OF */ break; - case 266: -#line 792 "parse.y" -{ yygotominor.yy52 = TK_ROW; } -#line 3653 "parse.c" + case 270: +#line 819 "parse.y" +{ yygotominor.yy372 = TK_ROW; } +#line 3647 "parse.c" break; - case 267: -#line 793 "parse.y" -{ yygotominor.yy52 = TK_ROW; } -#line 3658 "parse.c" + case 271: +#line 820 "parse.y" +{ yygotominor.yy372 = TK_ROW; } +#line 3652 "parse.c" /* No destructor defined for FOR */ /* No destructor defined for EACH */ /* No destructor defined for ROW */ break; - case 268: -#line 794 "parse.y" -{ yygotominor.yy52 = TK_STATEMENT; } -#line 3666 "parse.c" + case 272: +#line 821 "parse.y" +{ yygotominor.yy372 = TK_STATEMENT; } +#line 3660 "parse.c" /* No destructor defined for FOR */ /* No destructor defined for EACH */ /* No destructor defined for STATEMENT */ break; - case 269: -#line 797 "parse.y" -{ yygotominor.yy270 = 0; } -#line 3674 "parse.c" + case 273: +#line 824 "parse.y" +{ yygotominor.yy182 = 0; } +#line 3668 "parse.c" break; - case 270: -#line 798 "parse.y" -{ yygotominor.yy270 = yymsp[0].minor.yy334; } -#line 3679 "parse.c" + case 274: +#line 825 "parse.y" +{ yygotominor.yy182 = yymsp[0].minor.yy242; } +#line 3673 "parse.c" /* No destructor defined for WHEN */ break; - case 271: -#line 802 "parse.y" + case 275: +#line 829 "parse.y" { - yymsp[-2].minor.yy347->pNext = yymsp[0].minor.yy347; - yygotominor.yy347 = yymsp[-2].minor.yy347; + yymsp[-2].minor.yy19->pNext = yymsp[0].minor.yy19; + yygotominor.yy19 = yymsp[-2].minor.yy19; } -#line 3688 "parse.c" +#line 3682 "parse.c" /* No destructor defined for SEMI */ break; - case 272: -#line 806 "parse.y" -{ yygotominor.yy347 = 0; } -#line 3694 "parse.c" + case 276: +#line 833 "parse.y" +{ yygotominor.yy19 = 0; } +#line 3688 "parse.c" break; - case 273: -#line 812 "parse.y" -{ yygotominor.yy347 = sqliteTriggerUpdateStep(&yymsp[-3].minor.yy210, yymsp[-1].minor.yy62, yymsp[0].minor.yy334, yymsp[-4].minor.yy52); } -#line 3699 "parse.c" + case 277: +#line 839 "parse.y" +{ yygotominor.yy19 = sqliteTriggerUpdateStep(&yymsp[-3].minor.yy298, yymsp[-1].minor.yy322, yymsp[0].minor.yy242, yymsp[-4].minor.yy372); } +#line 3693 "parse.c" /* No destructor defined for UPDATE */ /* No destructor defined for SET */ break; - case 274: -#line 817 "parse.y" -{yygotominor.yy347 = sqliteTriggerInsertStep(&yymsp[-5].minor.yy210, yymsp[-4].minor.yy92, yymsp[-1].minor.yy62, 0, yymsp[-7].minor.yy52);} -#line 3706 "parse.c" - /* No destructor defined for INSERT */ + case 278: +#line 844 "parse.y" +{yygotominor.yy19 = sqliteTriggerInsertStep(&yymsp[-5].minor.yy298, yymsp[-4].minor.yy320, yymsp[-1].minor.yy322, 0, yymsp[-7].minor.yy372);} +#line 3700 "parse.c" /* No destructor defined for INTO */ /* No destructor defined for VALUES */ /* No destructor defined for LP */ /* No destructor defined for RP */ break; - case 275: -#line 820 "parse.y" -{yygotominor.yy347 = sqliteTriggerInsertStep(&yymsp[-2].minor.yy210, yymsp[-1].minor.yy92, 0, yymsp[0].minor.yy11, yymsp[-4].minor.yy52);} -#line 3716 "parse.c" - /* No destructor defined for INSERT */ + case 279: +#line 847 "parse.y" +{yygotominor.yy19 = sqliteTriggerInsertStep(&yymsp[-2].minor.yy298, yymsp[-1].minor.yy320, 0, yymsp[0].minor.yy179, yymsp[-4].minor.yy372);} +#line 3709 "parse.c" /* No destructor defined for INTO */ break; - case 276: -#line 824 "parse.y" -{yygotominor.yy347 = sqliteTriggerDeleteStep(&yymsp[-1].minor.yy210, yymsp[0].minor.yy334);} -#line 3723 "parse.c" + case 280: +#line 851 "parse.y" +{yygotominor.yy19 = sqliteTriggerDeleteStep(&yymsp[-1].minor.yy298, yymsp[0].minor.yy242);} +#line 3715 "parse.c" /* No destructor defined for DELETE */ /* No destructor defined for FROM */ break; - case 277: -#line 827 "parse.y" -{yygotominor.yy347 = sqliteTriggerSelectStep(yymsp[0].minor.yy11); } -#line 3730 "parse.c" + case 281: +#line 854 "parse.y" +{yygotominor.yy19 = sqliteTriggerSelectStep(yymsp[0].minor.yy179); } +#line 3722 "parse.c" break; - case 278: -#line 830 "parse.y" + case 282: +#line 857 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_RAISE, 0, 0, 0); - yygotominor.yy334->iColumn = OE_Ignore; - sqliteExprSpan(yygotominor.yy334, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_RAISE, 0, 0, 0); + yygotominor.yy242->iColumn = OE_Ignore; + sqliteExprSpan(yygotominor.yy242, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } -#line 3739 "parse.c" +#line 3731 "parse.c" /* No destructor defined for LP */ /* No destructor defined for IGNORE */ break; - case 279: -#line 835 "parse.y" + case 283: +#line 862 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy210); - yygotominor.yy334->iColumn = OE_Rollback; - sqliteExprSpan(yygotominor.yy334, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy298); + yygotominor.yy242->iColumn = OE_Rollback; + sqliteExprSpan(yygotominor.yy242, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } -#line 3750 "parse.c" +#line 3742 "parse.c" /* No destructor defined for LP */ /* No destructor defined for ROLLBACK */ /* No destructor defined for COMMA */ break; - case 280: -#line 840 "parse.y" + case 284: +#line 867 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy210); - yygotominor.yy334->iColumn = OE_Abort; - sqliteExprSpan(yygotominor.yy334, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy298); + yygotominor.yy242->iColumn = OE_Abort; + sqliteExprSpan(yygotominor.yy242, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } -#line 3762 "parse.c" +#line 3754 "parse.c" /* No destructor defined for LP */ /* No destructor defined for ABORT */ /* No destructor defined for COMMA */ break; - case 281: -#line 845 "parse.y" + case 285: +#line 872 "parse.y" { - yygotominor.yy334 = sqliteExpr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy210); - yygotominor.yy334->iColumn = OE_Fail; - sqliteExprSpan(yygotominor.yy334, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy242 = sqliteExpr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy298); + yygotominor.yy242->iColumn = OE_Fail; + sqliteExprSpan(yygotominor.yy242, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } -#line 3774 "parse.c" +#line 3766 "parse.c" /* No destructor defined for LP */ /* No destructor defined for FAIL */ /* No destructor defined for COMMA */ break; - case 282: -#line 852 "parse.y" + case 286: +#line 879 "parse.y" { - sqliteDropTrigger(pParse,sqliteSrcListAppend(0,&yymsp[-1].minor.yy210,&yymsp[0].minor.yy210)); + sqliteDropTrigger(pParse,sqliteSrcListAppend(0,&yymsp[-1].minor.yy298,&yymsp[0].minor.yy298)); } -#line 3784 "parse.c" +#line 3776 "parse.c" /* No destructor defined for DROP */ /* No destructor defined for TRIGGER */ break; - case 283: -#line 857 "parse.y" + case 287: +#line 884 "parse.y" { - sqliteAttach(pParse, &yymsp[-2].minor.yy210, &yymsp[0].minor.yy210); + sqliteAttach(pParse, &yymsp[-3].minor.yy298, &yymsp[-1].minor.yy298, &yymsp[0].minor.yy298); } -#line 3793 "parse.c" +#line 3785 "parse.c" /* No destructor defined for ATTACH */ /* No destructor defined for database_kw_opt */ /* No destructor defined for AS */ break; - case 284: + case 288: +#line 888 "parse.y" +{ yygotominor.yy298 = yymsp[0].minor.yy298; } +#line 3793 "parse.c" + /* No destructor defined for USING */ + break; + case 289: +#line 889 "parse.y" +{ yygotominor.yy298.z = 0; yygotominor.yy298.n = 0; } +#line 3799 "parse.c" + break; + case 290: /* No destructor defined for DATABASE */ break; - case 285: + case 291: break; - case 286: -#line 865 "parse.y" + case 292: +#line 895 "parse.y" { - sqliteDetach(pParse, &yymsp[0].minor.yy210); + sqliteDetach(pParse, &yymsp[0].minor.yy298); } -#line 3808 "parse.c" +#line 3811 "parse.c" /* No destructor defined for DETACH */ /* No destructor defined for database_kw_opt */ break; @@ -3853,15 +3856,13 @@ static void yy_syntax_error( if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ - sqliteSetNString(&pParse->zErrMsg, - "near \"", -1, TOKEN.z, TOKEN.n, "\": syntax error", -1, 0); + sqliteErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); }else{ - sqliteSetString(&pParse->zErrMsg, "incomplete SQL statement", (char*)0); + sqliteErrorMsg(pParse, "incomplete SQL statement"); } } - pParse->nErr++; -#line 3864 "parse.c" +#line 3865 "parse.c" sqliteParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } diff --git a/ext/sqlite/libsqlite/src/parse.h b/ext/sqlite/libsqlite/src/parse.h index 60e93cc501..188a336c8d 100644 --- a/ext/sqlite/libsqlite/src/parse.h +++ b/ext/sqlite/libsqlite/src/parse.h @@ -1,130 +1,130 @@ -#define TK_ABORT 1 -#define TK_AFTER 2 -#define TK_AGG_FUNCTION 3 -#define TK_ALL 4 -#define TK_AND 5 -#define TK_AS 6 -#define TK_ASC 7 -#define TK_ATTACH 8 -#define TK_BEFORE 9 -#define TK_BEGIN 10 -#define TK_BETWEEN 11 -#define TK_BITAND 12 -#define TK_BITNOT 13 -#define TK_BITOR 14 -#define TK_BY 15 -#define TK_CASCADE 16 -#define TK_CASE 17 -#define TK_CHECK 18 -#define TK_CLUSTER 19 -#define TK_COLLATE 20 -#define TK_COLUMN 21 +#define TK_END_OF_FILE 1 +#define TK_ILLEGAL 2 +#define TK_SPACE 3 +#define TK_UNCLOSED_STRING 4 +#define TK_COMMENT 5 +#define TK_FUNCTION 6 +#define TK_COLUMN 7 +#define TK_AGG_FUNCTION 8 +#define TK_SEMI 9 +#define TK_EXPLAIN 10 +#define TK_BEGIN 11 +#define TK_TRANSACTION 12 +#define TK_COMMIT 13 +#define TK_END 14 +#define TK_ROLLBACK 15 +#define TK_CREATE 16 +#define TK_TABLE 17 +#define TK_TEMP 18 +#define TK_LP 19 +#define TK_RP 20 +#define TK_AS 21 #define TK_COMMA 22 -#define TK_COMMENT 23 -#define TK_COMMIT 24 -#define TK_CONCAT 25 -#define TK_CONFLICT 26 -#define TK_CONSTRAINT 27 -#define TK_COPY 28 -#define TK_CREATE 29 -#define TK_DATABASE 30 -#define TK_DEFAULT 31 -#define TK_DEFERRABLE 32 -#define TK_DEFERRED 33 -#define TK_DELETE 34 +#define TK_ID 23 +#define TK_ABORT 24 +#define TK_AFTER 25 +#define TK_ASC 26 +#define TK_ATTACH 27 +#define TK_BEFORE 28 +#define TK_CASCADE 29 +#define TK_CLUSTER 30 +#define TK_CONFLICT 31 +#define TK_COPY 32 +#define TK_DATABASE 33 +#define TK_DEFERRED 34 #define TK_DELIMITERS 35 #define TK_DESC 36 #define TK_DETACH 37 -#define TK_DISTINCT 38 -#define TK_DOT 39 -#define TK_DROP 40 -#define TK_EACH 41 -#define TK_ELSE 42 -#define TK_END 43 -#define TK_END_OF_FILE 44 -#define TK_EQ 45 -#define TK_EXCEPT 46 -#define TK_EXPLAIN 47 -#define TK_FAIL 48 -#define TK_FLOAT 49 -#define TK_FOR 50 -#define TK_FOREIGN 51 -#define TK_FROM 52 -#define TK_FUNCTION 53 -#define TK_GE 54 -#define TK_GLOB 55 -#define TK_GROUP 56 -#define TK_GT 57 -#define TK_HAVING 58 -#define TK_ID 59 -#define TK_IGNORE 60 -#define TK_ILLEGAL 61 -#define TK_IMMEDIATE 62 -#define TK_IN 63 -#define TK_INDEX 64 -#define TK_INITIALLY 65 -#define TK_INSERT 66 -#define TK_INSTEAD 67 -#define TK_INTEGER 68 -#define TK_INTERSECT 69 -#define TK_INTO 70 -#define TK_IS 71 -#define TK_ISNULL 72 -#define TK_JOIN 73 -#define TK_JOIN_KW 74 -#define TK_KEY 75 -#define TK_LE 76 -#define TK_LIKE 77 -#define TK_LIMIT 78 -#define TK_LP 79 -#define TK_LSHIFT 80 -#define TK_LT 81 -#define TK_MATCH 82 -#define TK_MINUS 83 -#define TK_NE 84 -#define TK_NOT 85 -#define TK_NOTNULL 86 -#define TK_NULL 87 -#define TK_OF 88 -#define TK_OFFSET 89 -#define TK_ON 90 -#define TK_OR 91 -#define TK_ORDER 92 -#define TK_PLUS 93 -#define TK_PRAGMA 94 -#define TK_PRIMARY 95 -#define TK_RAISE 96 +#define TK_EACH 38 +#define TK_FAIL 39 +#define TK_FOR 40 +#define TK_GLOB 41 +#define TK_IGNORE 42 +#define TK_IMMEDIATE 43 +#define TK_INITIALLY 44 +#define TK_INSTEAD 45 +#define TK_LIKE 46 +#define TK_MATCH 47 +#define TK_KEY 48 +#define TK_OF 49 +#define TK_OFFSET 50 +#define TK_PRAGMA 51 +#define TK_RAISE 52 +#define TK_REPLACE 53 +#define TK_RESTRICT 54 +#define TK_ROW 55 +#define TK_STATEMENT 56 +#define TK_TRIGGER 57 +#define TK_VACUUM 58 +#define TK_VIEW 59 +#define TK_OR 60 +#define TK_AND 61 +#define TK_NOT 62 +#define TK_EQ 63 +#define TK_NE 64 +#define TK_ISNULL 65 +#define TK_NOTNULL 66 +#define TK_IS 67 +#define TK_BETWEEN 68 +#define TK_IN 69 +#define TK_GT 70 +#define TK_GE 71 +#define TK_LT 72 +#define TK_LE 73 +#define TK_BITAND 74 +#define TK_BITOR 75 +#define TK_LSHIFT 76 +#define TK_RSHIFT 77 +#define TK_PLUS 78 +#define TK_MINUS 79 +#define TK_STAR 80 +#define TK_SLASH 81 +#define TK_REM 82 +#define TK_CONCAT 83 +#define TK_UMINUS 84 +#define TK_UPLUS 85 +#define TK_BITNOT 86 +#define TK_STRING 87 +#define TK_JOIN_KW 88 +#define TK_INTEGER 89 +#define TK_CONSTRAINT 90 +#define TK_DEFAULT 91 +#define TK_FLOAT 92 +#define TK_NULL 93 +#define TK_PRIMARY 94 +#define TK_UNIQUE 95 +#define TK_CHECK 96 #define TK_REFERENCES 97 -#define TK_REM 98 -#define TK_REPLACE 99 -#define TK_RESTRICT 100 -#define TK_ROLLBACK 101 -#define TK_ROW 102 -#define TK_RP 103 -#define TK_RSHIFT 104 -#define TK_SELECT 105 -#define TK_SEMI 106 -#define TK_SET 107 -#define TK_SLASH 108 -#define TK_SPACE 109 -#define TK_STAR 110 -#define TK_STATEMENT 111 -#define TK_STRING 112 -#define TK_TABLE 113 -#define TK_TEMP 114 -#define TK_THEN 115 -#define TK_TRANSACTION 116 -#define TK_TRIGGER 117 -#define TK_UMINUS 118 -#define TK_UNCLOSED_STRING 119 -#define TK_UNION 120 -#define TK_UNIQUE 121 -#define TK_UPDATE 122 -#define TK_UPLUS 123 -#define TK_USING 124 -#define TK_VACUUM 125 -#define TK_VALUES 126 -#define TK_VARIABLE 127 -#define TK_VIEW 128 -#define TK_WHEN 129 -#define TK_WHERE 130 +#define TK_COLLATE 98 +#define TK_ON 99 +#define TK_DELETE 100 +#define TK_UPDATE 101 +#define TK_INSERT 102 +#define TK_SET 103 +#define TK_DEFERRABLE 104 +#define TK_FOREIGN 105 +#define TK_DROP 106 +#define TK_UNION 107 +#define TK_ALL 108 +#define TK_INTERSECT 109 +#define TK_EXCEPT 110 +#define TK_SELECT 111 +#define TK_DISTINCT 112 +#define TK_DOT 113 +#define TK_FROM 114 +#define TK_JOIN 115 +#define TK_USING 116 +#define TK_ORDER 117 +#define TK_BY 118 +#define TK_GROUP 119 +#define TK_HAVING 120 +#define TK_LIMIT 121 +#define TK_WHERE 122 +#define TK_INTO 123 +#define TK_VALUES 124 +#define TK_VARIABLE 125 +#define TK_CASE 126 +#define TK_WHEN 127 +#define TK_THEN 128 +#define TK_ELSE 129 +#define TK_INDEX 130 diff --git a/ext/sqlite/libsqlite/src/parse.y b/ext/sqlite/libsqlite/src/parse.y index 3aee9f0c95..cc236a5df8 100644 --- a/ext/sqlite/libsqlite/src/parse.y +++ b/ext/sqlite/libsqlite/src/parse.y @@ -23,13 +23,11 @@ %syntax_error { if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ - sqliteSetNString(&pParse->zErrMsg, - "near \"", -1, TOKEN.z, TOKEN.n, "\": syntax error", -1, 0); + sqliteErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); }else{ - sqliteSetString(&pParse->zErrMsg, "incomplete SQL statement", (char*)0); + sqliteErrorMsg(pParse, "incomplete SQL statement"); } } - pParse->nErr++; } %name sqliteParser %include { @@ -65,13 +63,10 @@ struct TrigEvent { int a; IdList * b; }; %nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION COLUMN AGG_FUNCTION. -// Input is zero or more commands. +// Input is a single SQL command input ::= cmdlist. - -// A list of commands is zero or more commands -// -cmdlist ::= ecmd. cmdlist ::= cmdlist ecmd. +cmdlist ::= ecmd. ecmd ::= explain cmdx SEMI. ecmd ::= SEMI. cmdx ::= cmd. { sqliteExec(pParse); } @@ -132,6 +127,22 @@ id(A) ::= ID(X). {A = X;} OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT TEMP TRIGGER VACUUM VIEW. +// Define operator precedence early so that this is the first occurance +// of the operator tokens in the grammer. Keeping the operators together +// causes them to be assigned integer values that are close together, +// which keeps parser tables smaller. +// +%left OR. +%left AND. +%right NOT. +%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN. +%left GT GE LT LE. +%left BITAND BITOR LSHIFT RSHIFT. +%left PLUS MINUS. +%left STAR SLASH REM. +%left CONCAT. +%right UMINUS UPLUS BITNOT. + // And "ids" is an identifer-or-string. // %type ids {Token} @@ -366,7 +377,8 @@ seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). { else { sqliteIdListDelete(U); } } } -seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). { +seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP + as(Z) on_opt(N) using_opt(U). { A = sqliteSrcListAppend(X,0,0); A->a[A->nSrc-1].pSelect = S; if( Z.n ) sqliteSrcListAddAlias(A,&Z); @@ -380,6 +392,17 @@ seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). { } } +// A seltablist_paren nonterminal represents anything in a FROM that +// is contained inside parentheses. This can be either a subquery or +// a grouping of table and subqueries. +// +%type seltablist_paren {Select*} +%destructor seltablist_paren {sqliteSelectDelete($$);} +seltablist_paren(A) ::= select(S). {A = S;} +seltablist_paren(A) ::= seltablist(F). { + A = sqliteSelectNew(0,F,0,0,0,0,0,-1,0); +} + %type dbnm {Token} dbnm(A) ::= . {A.z=0; A.n=0;} dbnm(A) ::= DOT nm(X). {A = X;} @@ -505,16 +528,6 @@ inscollist(A) ::= nm(Y). {A = sqliteIdListAppend(0,&Y);} /////////////////////////// Expression Processing ///////////////////////////// // -%left OR. -%left AND. -%right NOT. -%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN. -%left GT GE LT LE. -%left BITAND BITOR LSHIFT RSHIFT. -%left PLUS MINUS. -%left STAR SLASH REM. -%left CONCAT. -%right UMINUS UPLUS BITNOT. %type expr {Expr*} %destructor expr {sqliteExprDelete($$);} @@ -664,6 +677,20 @@ expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). { A = sqliteExpr(TK_NOT, A, 0, 0); sqliteExprSpan(A,&X->span,&E); } +expr(A) ::= expr(X) IN nm(Y) dbnm(D). { + SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D); + A = sqliteExpr(TK_IN, X, 0, 0); + if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0); + sqliteExprSpan(A,&X->span,D.z?&D:&Y); +} +expr(A) ::= expr(X) NOT IN nm(Y) dbnm(D). { + SrcList *pSrc = sqliteSrcListAppend(0, &Y, &D); + A = sqliteExpr(TK_IN, X, 0, 0); + if( A ) A->pSelect = sqliteSelectNew(0,pSrc,0,0,0,0,0,-1,0); + A = sqliteExpr(TK_NOT, A, 0, 0); + sqliteExprSpan(A,&X->span,D.z?&D:&Y); +} + /* CASE expressions */ expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { @@ -812,11 +839,11 @@ trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z). { A = sqliteTriggerUpdateStep(&X, Y, Z, R); } // INSERT -trigger_cmd(A) ::= INSERT orconf(R) INTO nm(X) inscollist_opt(F) +trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) VALUES LP itemlist(Y) RP. {A = sqliteTriggerInsertStep(&X, F, Y, 0, R);} -trigger_cmd(A) ::= INSERT orconf(R) INTO nm(X) inscollist_opt(F) select(S). +trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S). {A = sqliteTriggerInsertStep(&X, F, 0, S, R);} // DELETE @@ -854,9 +881,12 @@ cmd ::= DROP TRIGGER nm(X) dbnm(D). { } //////////////////////// ATTACH DATABASE file AS name ///////////////////////// -cmd ::= ATTACH database_kw_opt ids(F) AS nm(D). { - sqliteAttach(pParse, &F, &D); +cmd ::= ATTACH database_kw_opt ids(F) AS nm(D) key_opt(K). { + sqliteAttach(pParse, &F, &D, &K); } +%type key_opt {Token} +key_opt(A) ::= USING ids(X). { A = X; } +key_opt(A) ::= . { A.z = 0; A.n = 0; } database_kw_opt ::= DATABASE. database_kw_opt ::= . diff --git a/ext/sqlite/libsqlite/src/pragma.c b/ext/sqlite/libsqlite/src/pragma.c index 064ec6b1f5..965dbb9da6 100644 --- a/ext/sqlite/libsqlite/src/pragma.c +++ b/ext/sqlite/libsqlite/src/pragma.c @@ -19,7 +19,7 @@ /* ** Interpret the given string as a boolean value. */ -static int getBoolean(char *z){ +static int getBoolean(const char *z){ static char *azTrue[] = { "yes", "on", "true" }; int i; if( z[0]==0 ) return 0; @@ -34,7 +34,8 @@ static int getBoolean(char *z){ /* ** Interpret the given string as a safety level. Return 0 for OFF, -** 1 for ON or NORMAL and 2 for FULL. +** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or +** unrecognized string argument. ** ** Note that the values returned are one less that the values that ** should be passed into sqliteBtreeSetSafetyLevel(). The is done @@ -70,8 +71,8 @@ static int getSafetyLevel(char *z){ ** backed temporary databases, 2 for the Red-Black tree in memory database ** and 0 to use the compile-time default. */ -static int getTempStore(char *z){ - if( z[0]>='0' || z[0]<='2' ){ +static int getTempStore(const char *z){ + if( z[0]>='0' && z[0]<='2' ){ return z[0] - '0'; }else if( sqliteStrICmp(z, "file")==0 ){ return 1; @@ -83,6 +84,68 @@ static int getTempStore(char *z){ } /* +** If the TEMP database is open, close it and mark the database schema +** as needing reloading. This must be done when using the TEMP_STORE +** or DEFAULT_TEMP_STORE pragmas. +*/ +static int changeTempStorage(Parse *pParse, const char *zStorageType){ + int ts = getTempStore(zStorageType); + sqlite *db = pParse->db; + if( db->temp_store==ts ) return SQLITE_OK; + if( db->aDb[1].pBt!=0 ){ + if( db->flags & SQLITE_InTrans ){ + sqliteErrorMsg(pParse, "temporary storage cannot be changed " + "from within a transaction"); + return SQLITE_ERROR; + } + sqliteBtreeClose(db->aDb[1].pBt); + db->aDb[1].pBt = 0; + sqliteResetInternalSchema(db, 0); + } + db->temp_store = ts; + return SQLITE_OK; +} + +/* +** Check to see if zRight and zLeft refer to a pragma that queries +** or changes one of the flags in db->flags. Return 1 if so and 0 if not. +** Also, implement the pragma. +*/ +static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ + static const struct { + const char *zName; /* Name of the pragma */ + int mask; /* Mask for the db->flags value */ + } aPragma[] = { + { "vdbe_trace", SQLITE_VdbeTrace }, + { "full_column_names", SQLITE_FullColNames }, + { "short_column_names", SQLITE_ShortColNames }, + { "show_datatypes", SQLITE_ReportTypes }, + { "count_changes", SQLITE_CountRows }, + { "empty_result_callbacks", SQLITE_NullCallback }, + }; + int i; + for(i=0; i<sizeof(aPragma)/sizeof(aPragma[0]); i++){ + if( sqliteStrICmp(zLeft, aPragma[i].zName)==0 ){ + sqlite *db = pParse->db; + Vdbe *v; + if( strcmp(zLeft,zRight)==0 && (v = sqliteGetVdbe(pParse))!=0 ){ + sqliteVdbeOp3(v, OP_ColumnName, 0, 1, aPragma[i].zName, P3_STATIC); + sqliteVdbeOp3(v, OP_ColumnName, 1, 0, "boolean", P3_STATIC); + sqliteVdbeCode(v, OP_Integer, (db->flags & aPragma[i].mask)!=0, 0, + OP_Callback, 1, 0, + 0); + }else if( getBoolean(zRight) ){ + db->flags |= aPragma[i].mask; + }else{ + db->flags &= ~aPragma[i].mask; + } + return 1; + } + } + return 0; +} + +/* ** Process a pragma statement. ** ** Pragmas are of this form: @@ -132,20 +195,21 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** and a positive value means synchronous is on. */ if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){ - static VdbeOp getCacheSize[] = { + static VdbeOpList getCacheSize[] = { { OP_ReadCookie, 0, 2, 0}, { OP_AbsValue, 0, 0, 0}, { OP_Dup, 0, 0, 0}, { OP_Integer, 0, 0, 0}, { OP_Ne, 0, 6, 0}, - { OP_Integer, MAX_PAGES,0, 0}, - { OP_ColumnName, 0, 0, "cache_size"}, + { OP_Integer, 0, 0, 0}, /* 5 */ + { OP_ColumnName, 0, 1, "cache_size"}, { OP_Callback, 1, 0, 0}, }; + int addr; if( pRight->z==pLeft->z ){ - sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); + addr = sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); + sqliteVdbeChangeP1(v, addr+5, MAX_PAGES); }else{ - int addr; int size = atoi(zRight); if( size<0 ) size = -size; sqliteBeginWriteOperation(pParse, 0, 0); @@ -176,8 +240,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** N should be a positive integer. */ if( sqliteStrICmp(zLeft,"cache_size")==0 ){ - static VdbeOp getCacheSize[] = { - { OP_ColumnName, 0, 0, "cache_size"}, + static VdbeOpList getCacheSize[] = { + { OP_ColumnName, 0, 1, "cache_size"}, { OP_Callback, 1, 0, 0}, }; if( pRight->z==pLeft->z ){ @@ -214,8 +278,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** zero, but with a write performance penalty. The default mode is NORMAL. */ if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){ - static VdbeOp getSync[] = { - { OP_ColumnName, 0, 0, "synchronous"}, + static VdbeOpList getSync[] = { + { OP_ColumnName, 0, 1, "synchronous"}, { OP_ReadCookie, 0, 3, 0}, { OP_Dup, 0, 0, 0}, { OP_If, 0, 0, 0}, /* 3 */ @@ -267,8 +331,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** opened. */ if( sqliteStrICmp(zLeft,"synchronous")==0 ){ - static VdbeOp getSync[] = { - { OP_ColumnName, 0, 0, "synchronous"}, + static VdbeOpList getSync[] = { + { OP_ColumnName, 0, 1, "synchronous"}, { OP_Callback, 1, 0, 0}, }; if( pRight->z==pLeft->z ){ @@ -285,6 +349,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ } }else +#ifndef NDEBUG if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){ if( getBoolean(zRight) ){ always_code_trigger_setup = 1; @@ -292,72 +357,35 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ always_code_trigger_setup = 0; } }else +#endif - if( sqliteStrICmp(zLeft, "vdbe_trace")==0 ){ - if( getBoolean(zRight) ){ - db->flags |= SQLITE_VdbeTrace; - }else{ - db->flags &= ~SQLITE_VdbeTrace; - } - }else - - if( sqliteStrICmp(zLeft, "full_column_names")==0 ){ - if( getBoolean(zRight) ){ - db->flags |= SQLITE_FullColNames; - }else{ - db->flags &= ~SQLITE_FullColNames; - } - }else - - if( sqliteStrICmp(zLeft, "show_datatypes")==0 ){ - if( getBoolean(zRight) ){ - db->flags |= SQLITE_ReportTypes; - }else{ - db->flags &= ~SQLITE_ReportTypes; - } - }else - - if( sqliteStrICmp(zLeft, "count_changes")==0 ){ - if( getBoolean(zRight) ){ - db->flags |= SQLITE_CountRows; - }else{ - db->flags &= ~SQLITE_CountRows; - } - }else - - if( sqliteStrICmp(zLeft, "empty_result_callbacks")==0 ){ - if( getBoolean(zRight) ){ - db->flags |= SQLITE_NullCallback; - }else{ - db->flags &= ~SQLITE_NullCallback; - } + if( flagPragma(pParse, zLeft, zRight) ){ + /* The flagPragma() call also generates any necessary code */ }else if( sqliteStrICmp(zLeft, "table_info")==0 ){ Table *pTab; pTab = sqliteFindTable(db, zRight, 0); if( pTab ){ - static VdbeOp tableInfoPreface[] = { + static VdbeOpList tableInfoPreface[] = { { OP_ColumnName, 0, 0, "cid"}, { OP_ColumnName, 1, 0, "name"}, { OP_ColumnName, 2, 0, "type"}, { OP_ColumnName, 3, 0, "notnull"}, { OP_ColumnName, 4, 0, "dflt_value"}, - { OP_ColumnName, 5, 0, "pk"}, + { OP_ColumnName, 5, 1, "pk"}, }; int i; sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface); sqliteViewGetColumnNames(pParse, pTab); for(i=0; i<pTab->nCol; i++){ sqliteVdbeAddOp(v, OP_Integer, i, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zName, P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, - pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[i].zName, 0); + sqliteVdbeOp3(v, OP_String, 0, 0, + pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0); sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, + pTab->aCol[i].zDflt, P3_STATIC); sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0); sqliteVdbeAddOp(v, OP_Callback, 6, 0); } @@ -369,10 +397,10 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ Table *pTab; pIdx = sqliteFindIndex(db, zRight, 0); if( pIdx ){ - static VdbeOp tableInfoPreface[] = { + static VdbeOpList tableInfoPreface[] = { { OP_ColumnName, 0, 0, "seqno"}, { OP_ColumnName, 1, 0, "cid"}, - { OP_ColumnName, 2, 0, "name"}, + { OP_ColumnName, 2, 1, "name"}, }; int i; pTab = pIdx->pTable; @@ -381,9 +409,8 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ int cnum = pIdx->aiColumn[i]; sqliteVdbeAddOp(v, OP_Integer, i, 0); sqliteVdbeAddOp(v, OP_Integer, cnum, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); assert( pTab->nCol>cnum ); - sqliteVdbeChangeP3(v, -1, pTab->aCol[cnum].zName, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pTab->aCol[cnum].zName, 0); sqliteVdbeAddOp(v, OP_Callback, 3, 0); } } @@ -399,17 +426,16 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ } if( pTab && pIdx ){ int i = 0; - static VdbeOp indexListPreface[] = { + static VdbeOpList indexListPreface[] = { { OP_ColumnName, 0, 0, "seq"}, { OP_ColumnName, 1, 0, "name"}, - { OP_ColumnName, 2, 0, "unique"}, + { OP_ColumnName, 2, 1, "unique"}, }; sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface); while(pIdx){ sqliteVdbeAddOp(v, OP_Integer, i, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pIdx->zName, 0); sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0); sqliteVdbeAddOp(v, OP_Callback, 3, 0); ++i; @@ -428,12 +454,12 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ } if( pTab && pFK ){ int i = 0; - static VdbeOp indexListPreface[] = { + static VdbeOpList indexListPreface[] = { { OP_ColumnName, 0, 0, "id"}, { OP_ColumnName, 1, 0, "seq"}, { OP_ColumnName, 2, 0, "table"}, { OP_ColumnName, 3, 0, "from"}, - { OP_ColumnName, 4, 0, "to"}, + { OP_ColumnName, 4, 1, "to"}, }; sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface); @@ -442,13 +468,10 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ for(j=0; j<pFK->nCol; j++){ sqliteVdbeAddOp(v, OP_Integer, i, 0); sqliteVdbeAddOp(v, OP_Integer, j, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pFK->zTo, P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pTab->aCol[pFK->aCol[j].iFrom].zName, - P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, pFK->aCol[j].zCol, P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, pFK->zTo, 0); + sqliteVdbeOp3(v, OP_String, 0, 0, + pTab->aCol[pFK->aCol[j].iFrom].zName, 0); + sqliteVdbeOp3(v, OP_String, 0, 0, pFK->aCol[j].zCol, 0); sqliteVdbeAddOp(v, OP_Callback, 5, 0); } ++i; @@ -459,10 +482,10 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ if( sqliteStrICmp(zLeft, "database_list")==0 ){ int i; - static VdbeOp indexListPreface[] = { + static VdbeOpList indexListPreface[] = { { OP_ColumnName, 0, 0, "seq"}, { OP_ColumnName, 1, 0, "name"}, - { OP_ColumnName, 2, 0, "file"}, + { OP_ColumnName, 2, 1, "file"}, }; sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface); @@ -470,11 +493,9 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ if( db->aDb[i].pBt==0 ) continue; assert( db->aDb[i].zName!=0 ); sqliteVdbeAddOp(v, OP_Integer, i, 0); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, db->aDb[i].zName, P3_STATIC); - sqliteVdbeAddOp(v, OP_String, 0, 0); - sqliteVdbeChangeP3(v, -1, sqliteBtreeGetFilename(db->aDb[i].pBt), - P3_STATIC); + sqliteVdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, 0); + sqliteVdbeOp3(v, OP_String, 0, 0, + sqliteBtreeGetFilename(db->aDb[i].pBt), 0); sqliteVdbeAddOp(v, OP_Callback, 3, 0); } }else @@ -492,20 +513,15 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** override this setting */ if( sqliteStrICmp(zLeft, "temp_store")==0 ){ - static VdbeOp getTmpDbLoc[] = { - { OP_ColumnName, 0, 0, "temp_store"}, + static VdbeOpList getTmpDbLoc[] = { + { OP_ColumnName, 0, 1, "temp_store"}, { OP_Callback, 1, 0, 0}, }; if( pRight->z==pLeft->z ){ sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0); sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc); }else{ - if (&db->aDb[1].pBt != 0) { - sqliteErrorMsg(pParse, "The temporary database already exists - " - "its location cannot now be changed"); - } else { - db->temp_store = getTempStore(zRight); - } + changeTempStorage(pParse, zRight); } }else @@ -513,30 +529,25 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** PRAGMA default_temp_store ** PRAGMA default_temp_store = "default"|"memory"|"file" ** - ** Return or set the value of the persistent temp_store flag (as - ** well as the value currently in force). + ** Return or set the value of the persistent temp_store flag. Any + ** change does not take effect until the next time the database is + ** opened. ** ** Note that it is possible for the library compile-time options to ** override this setting */ if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){ - static VdbeOp getTmpDbLoc[] = { - { OP_ColumnName, 0, 0, "temp_store"}, + static VdbeOpList getTmpDbLoc[] = { + { OP_ColumnName, 0, 1, "temp_store"}, { OP_ReadCookie, 0, 5, 0}, { OP_Callback, 1, 0, 0}}; if( pRight->z==pLeft->z ){ sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc); }else{ - if (&db->aDb[1].pBt != 0) { - sqliteErrorMsg(pParse, "The temporary database already exists - " - "its location cannot now be changed"); - } else { - sqliteBeginWriteOperation(pParse, 0, 0); - db->temp_store = getTempStore(zRight); - sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0); - sqliteVdbeAddOp(v, OP_SetCookie, 0, 5); - sqliteEndWriteOperation(pParse); - } + sqliteBeginWriteOperation(pParse, 0, 0); + sqliteVdbeAddOp(v, OP_Integer, getTempStore(zRight), 0); + sqliteVdbeAddOp(v, OP_SetCookie, 0, 5); + sqliteEndWriteOperation(pParse); } }else @@ -557,15 +568,15 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ /* Code that initializes the integrity check program. Set the ** error count 0 */ - static VdbeOp initCode[] = { + static VdbeOpList initCode[] = { { OP_Integer, 0, 0, 0}, { OP_MemStore, 0, 1, 0}, - { OP_ColumnName, 0, 0, "integrity_check"}, + { OP_ColumnName, 0, 1, "integrity_check"}, }; /* Code to do an BTree integrity check on a single database file. */ - static VdbeOp checkDb[] = { + static VdbeOpList checkDb[] = { { OP_SetInsert, 0, 0, "2"}, { OP_Integer, 0, 0, 0}, /* 1 */ { OP_OpenRead, 0, 2, 0}, @@ -590,7 +601,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ ** messages have been generated, output OK. Otherwise output the ** error message */ - static VdbeOp endCode[] = { + static VdbeOpList endCode[] = { { OP_MemLoad, 0, 0, 0}, { OP_Integer, 0, 0, 0}, { OP_Ne, 0, 0, 0}, /* 2 */ @@ -625,13 +636,11 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ if( pTab->pIndex==0 ) continue; sqliteVdbeAddOp(v, OP_Integer, i, 0); - sqliteVdbeAddOp(v, OP_OpenRead, 1, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0); for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ if( pIdx->tnum==0 ) continue; sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenRead, j+2, pIdx->tnum); - sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_OpenRead, j+2, pIdx->tnum, pIdx->zName, 0); } sqliteVdbeAddOp(v, OP_Integer, 0, 0); sqliteVdbeAddOp(v, OP_MemStore, 1, 1); @@ -639,7 +648,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ sqliteVdbeAddOp(v, OP_MemIncr, 1, 0); for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ int k, jmp2; - static VdbeOp idxErr[] = { + static VdbeOpList idxErr[] = { { OP_MemIncr, 0, 0, 0}, { OP_String, 0, 0, "rowid "}, { OP_Recno, 1, 0, 0}, @@ -667,7 +676,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ sqliteVdbeAddOp(v, OP_Next, 1, loopTop+1); sqliteVdbeChangeP2(v, loopTop, sqliteVdbeCurrentAddr(v)); for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ - static VdbeOp cntIdx[] = { + static VdbeOpList cntIdx[] = { { OP_Integer, 0, 0, 0}, { OP_MemStore, 2, 1, 0}, { OP_Rewind, 0, 0, 0}, /* 2 */ diff --git a/ext/sqlite/libsqlite/src/printf.c b/ext/sqlite/libsqlite/src/printf.c index a8af91434e..620578d76e 100644 --- a/ext/sqlite/libsqlite/src/printf.c +++ b/ext/sqlite/libsqlite/src/printf.c @@ -1,7 +1,11 @@ /* ** The "printf" code that follows dates from the 1980's. It is in ** the public domain. The original comments are included here for -** completeness. They are slightly out-of-date. +** completeness. They are very out-of-date but might be useful as +** an historical reference. Most of the "enhancements" have been backed +** out so that the functionality is now the same as standard printf(). +** +************************************************************************** ** ** The following modules is an enhanced replacement for the "printf" subroutines ** found in the standard C library. The following enhancements are @@ -49,75 +53,79 @@ #include "sqliteInt.h" /* -** Undefine COMPATIBILITY to make some slight changes in the way things -** work. I think the changes are an improvement, but they are not -** backwards compatible. -*/ -/* #define COMPATIBILITY / * Compatible with SUN OS 4.1 */ - -/* ** Conversion types fall into various categories as defined by the ** following enumeration. */ -enum et_type { /* The type of the format field */ - etRADIX, /* Integer types. %d, %x, %o, and so forth */ - etFLOAT, /* Floating point. %f */ - etEXP, /* Exponentional notation. %e and %E */ - etGENERIC, /* Floating or exponential, depending on exponent. %g */ - etSIZE, /* Return number of characters processed so far. %n */ - etSTRING, /* Strings. %s */ - etDYNSTRING, /* Dynamically allocated strings. %z */ - etPERCENT, /* Percent symbol. %% */ - etCHARX, /* Characters. %c */ - etERROR, /* Used to indicate no such conversion type */ +#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */ +#define etFLOAT 2 /* Floating point. %f */ +#define etEXP 3 /* Exponentional notation. %e and %E */ +#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */ +#define etSIZE 5 /* Return number of characters processed so far. %n */ +#define etSTRING 6 /* Strings. %s */ +#define etDYNSTRING 7 /* Dynamically allocated strings. %z */ +#define etPERCENT 8 /* Percent symbol. %% */ +#define etCHARX 9 /* Characters. %c */ +#define etERROR 10 /* Used to indicate no such conversion type */ /* The rest are extensions, not normally found in printf() */ - etCHARLIT, /* Literal characters. %' */ - etSQLESCAPE, /* Strings with '\'' doubled. %q */ - etSQLESCAPE2, /* Strings with '\'' doubled and enclosed in '', +#define etCHARLIT 11 /* Literal characters. %' */ +#define etSQLESCAPE 12 /* Strings with '\'' doubled. %q */ +#define etSQLESCAPE2 13 /* Strings with '\'' doubled and enclosed in '', NULL pointers replaced by SQL NULL. %Q */ - etORDINAL /* 1st, 2nd, 3rd and so forth */ -}; +#define etTOKEN 14 /* a pointer to a Token structure */ +#define etSRCLIST 15 /* a pointer to a SrcList */ + + +/* +** An "etByte" is an 8-bit unsigned value. +*/ +typedef unsigned char etByte; /* ** Each builtin conversion character (ex: the 'd' in "%d") is described ** by an instance of the following structure */ typedef struct et_info { /* Information about each format field */ - int fmttype; /* The format field code letter */ - int base; /* The base for radix conversion */ - char *charset; /* The character set for conversion */ - int flag_signed; /* Is the quantity signed? */ - char *prefix; /* Prefix on non-zero values in alt format */ - enum et_type type; /* Conversion paradigm */ + char fmttype; /* The format field code letter */ + etByte base; /* The base for radix conversion */ + etByte flags; /* One or more of FLAG_ constants below */ + etByte type; /* Conversion paradigm */ + char *charset; /* The character set for conversion */ + char *prefix; /* Prefix on non-zero values in alt format */ } et_info; /* +** Allowed values for et_info.flags +*/ +#define FLAG_SIGNED 1 /* True if the value to convert is signed */ +#define FLAG_INTERN 2 /* True if for internal use only */ + + +/* ** The following table is searched linearly, so it is good to put the ** most frequently used conversion types first. */ static et_info fmtinfo[] = { - { 'd', 10, "0123456789", 1, 0, etRADIX, }, - { 's', 0, 0, 0, 0, etSTRING, }, - { 'z', 0, 0, 0, 0, etDYNSTRING, }, - { 'q', 0, 0, 0, 0, etSQLESCAPE, }, - { 'Q', 0, 0, 0, 0, etSQLESCAPE2, }, - { 'c', 0, 0, 0, 0, etCHARX, }, - { 'o', 8, "01234567", 0, "0", etRADIX, }, - { 'u', 10, "0123456789", 0, 0, etRADIX, }, - { 'x', 16, "0123456789abcdef", 0, "x0", etRADIX, }, - { 'X', 16, "0123456789ABCDEF", 0, "X0", etRADIX, }, - { 'r', 10, "0123456789", 0, 0, etORDINAL, }, - { 'f', 0, 0, 1, 0, etFLOAT, }, - { 'e', 0, "e", 1, 0, etEXP, }, - { 'E', 0, "E", 1, 0, etEXP, }, - { 'g', 0, "e", 1, 0, etGENERIC, }, - { 'G', 0, "E", 1, 0, etGENERIC, }, - { 'i', 10, "0123456789", 1, 0, etRADIX, }, - { 'n', 0, 0, 0, 0, etSIZE, }, - { '%', 0, 0, 0, 0, etPERCENT, }, - { 'b', 2, "01", 0, "b0", etRADIX, }, /* Binary */ - { 'p', 10, "0123456789", 0, 0, etRADIX, }, /* Pointers */ - { '\'', 0, 0, 0, 0, etCHARLIT, }, /* Literal char */ + { 'd', 10, 1, etRADIX, "0123456789", 0 }, + { 's', 0, 0, etSTRING, 0, 0 }, + { 'z', 0, 2, etDYNSTRING, 0, 0 }, + { 'q', 0, 0, etSQLESCAPE, 0, 0 }, + { 'Q', 0, 0, etSQLESCAPE2, 0, 0 }, + { 'c', 0, 0, etCHARX, 0, 0 }, + { 'o', 8, 0, etRADIX, "01234567", "0" }, + { 'u', 10, 0, etRADIX, "0123456789", 0 }, + { 'x', 16, 0, etRADIX, "0123456789abcdef", "x0" }, + { 'X', 16, 0, etRADIX, "0123456789ABCDEF", "X0" }, + { 'f', 0, 1, etFLOAT, 0, 0 }, + { 'e', 0, 1, etEXP, "e", 0 }, + { 'E', 0, 1, etEXP, "E", 0 }, + { 'g', 0, 1, etGENERIC, "e", 0 }, + { 'G', 0, 1, etGENERIC, "E", 0 }, + { 'i', 10, 1, etRADIX, "0123456789", 0 }, + { 'n', 0, 0, etSIZE, 0, 0 }, + { '%', 0, 0, etPERCENT, 0, 0 }, + { 'p', 10, 0, etRADIX, "0123456789", 0 }, + { 'T', 0, 2, etTOKEN, 0, 0 }, + { 'S', 0, 2, etSRCLIST, 0, 0 }, }; #define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0])) @@ -181,52 +189,49 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){ ** will run. */ static int vxprintf( - void (*func)(void*,char*,int), - void *arg, - const char *format, - va_list ap + void (*func)(void*,const char*,int), /* Consumer of text */ + void *arg, /* First argument to the consumer */ + int useExtended, /* Allow extended %-conversions */ + const char *fmt, /* Format string */ + va_list ap /* arguments */ ){ - register const char *fmt; /* The format string. */ - register int c; /* Next character in the format string */ - register char *bufpt; /* Pointer to the conversion buffer */ - register int precision; /* Precision of the current field */ - register int length; /* Length of the field */ - register int idx; /* A general purpose loop counter */ - int count; /* Total number of characters output */ - int width; /* Width of the current field */ - int flag_leftjustify; /* True if "-" flag is present */ - int flag_plussign; /* True if "+" flag is present */ - int flag_blanksign; /* True if " " flag is present */ - int flag_alternateform; /* True if "#" flag is present */ - int flag_zeropad; /* True if field width constant starts with zero */ - int flag_long; /* True if "l" flag is present */ - int flag_center; /* True if "=" flag is present */ - unsigned long longvalue; /* Value for integer types */ + int c; /* Next character in the format string */ + char *bufpt; /* Pointer to the conversion buffer */ + int precision; /* Precision of the current field */ + int length; /* Length of the field */ + int idx; /* A general purpose loop counter */ + int count; /* Total number of characters output */ + int width; /* Width of the current field */ + etByte flag_leftjustify; /* True if "-" flag is present */ + etByte flag_plussign; /* True if "+" flag is present */ + etByte flag_blanksign; /* True if " " flag is present */ + etByte flag_alternateform; /* True if "#" flag is present */ + etByte flag_zeropad; /* True if field width constant starts with zero */ + etByte flag_long; /* True if "l" flag is present */ + unsigned long longvalue; /* Value for integer types */ LONGDOUBLE_TYPE realvalue; /* Value for real types */ - et_info *infop; /* Pointer to the appropriate info structure */ - char buf[etBUFSIZE]; /* Conversion buffer */ - char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ - int errorflag = 0; /* True if an error is encountered */ - enum et_type xtype; /* Conversion paradigm */ - char *zExtra; /* Extra memory used for etTCLESCAPE conversions */ - static char spaces[] = " " - " "; + et_info *infop; /* Pointer to the appropriate info structure */ + char buf[etBUFSIZE]; /* Conversion buffer */ + char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ + etByte errorflag = 0; /* True if an error is encountered */ + etByte xtype; /* Conversion paradigm */ + char *zExtra; /* Extra memory used for etTCLESCAPE conversions */ + static char spaces[] = " "; #define etSPACESIZE (sizeof(spaces)-1) #ifndef etNOFLOATINGPOINT - int exp; /* exponent of real numbers */ - double rounder; /* Used for rounding floating point values */ - int flag_dp; /* True if decimal point should be shown */ - int flag_rtz; /* True if trailing zeros should be removed */ - int flag_exp; /* True to force display of the exponent */ - int nsd; /* Number of significant digits returned */ + int exp; /* exponent of real numbers */ + double rounder; /* Used for rounding floating point values */ + etByte flag_dp; /* True if decimal point should be shown */ + etByte flag_rtz; /* True if trailing zeros should be removed */ + etByte flag_exp; /* True to force display of the exponent */ + int nsd; /* Number of significant digits returned */ #endif - fmt = format; /* Put in a register for speed */ count = length = 0; bufpt = 0; for(; (c=(*fmt))!=0; ++fmt){ if( c!='%' ){ - register int amt; + int amt; bufpt = (char *)fmt; amt = 1; while( (c=(*++fmt))!='%' && c!=0 ) amt++; @@ -242,7 +247,7 @@ static int vxprintf( } /* Find out what flags are present */ flag_leftjustify = flag_plussign = flag_blanksign = - flag_alternateform = flag_zeropad = flag_center = 0; + flag_alternateform = flag_zeropad = 0; do{ switch( c ){ case '-': flag_leftjustify = 1; c = 0; break; @@ -250,11 +255,9 @@ static int vxprintf( case ' ': flag_blanksign = 1; c = 0; break; case '#': flag_alternateform = 1; c = 0; break; case '0': flag_zeropad = 1; c = 0; break; - case '=': flag_center = 1; c = 0; break; default: break; } }while( c==0 && (c=(*++fmt))!=0 ); - if( flag_center ) flag_leftjustify = 0; /* Get the field width */ width = 0; if( c=='*' ){ @@ -279,10 +282,7 @@ static int vxprintf( c = *++fmt; if( c=='*' ){ precision = va_arg(ap,int); -#ifndef etCOMPATIBILITY - /* This is sensible, but SUN OS 4.1 doesn't do it. */ if( precision<0 ) precision = -precision; -#endif c = *++fmt; }else{ while( c>='0' && c<='9' ){ @@ -304,18 +304,16 @@ static int vxprintf( } /* Fetch the info entry for the field */ infop = 0; + xtype = etERROR; for(idx=0; idx<etNINFO; idx++){ if( c==fmtinfo[idx].fmttype ){ infop = &fmtinfo[idx]; + if( useExtended || (infop->flags & FLAG_INTERN)==0 ){ + xtype = infop->type; + } break; } } - /* No info entry found. It must be an error. */ - if( infop==0 ){ - xtype = etERROR; - }else{ - xtype = infop->type; - } zExtra = 0; /* @@ -337,11 +335,10 @@ static int vxprintf( ** infop Pointer to the appropriate info struct. */ switch( xtype ){ - case etORDINAL: case etRADIX: if( flag_long ) longvalue = va_arg(ap,long); else longvalue = va_arg(ap,int); -#ifdef etCOMPATIBILITY +#if 1 /* For the format %#x, the value zero is printed "0" not "0x0". ** I think this is stupid. */ if( longvalue==0 ) flag_alternateform = 0; @@ -350,7 +347,7 @@ static int vxprintf( ** but leave the prefix for hex. */ if( longvalue==0 && infop->base==8 ) flag_alternateform = 0; #endif - if( infop->flag_signed ){ + if( infop->flags & FLAG_SIGNED ){ if( *(long*)&longvalue<0 ){ longvalue = -*(long*)&longvalue; prefix = '-'; @@ -361,26 +358,7 @@ static int vxprintf( if( flag_zeropad && precision<width-(prefix!=0) ){ precision = width-(prefix!=0); } - bufpt = &buf[etBUFSIZE]; - if( xtype==etORDINAL ){ - long a,b; - a = longvalue%10; - b = longvalue%100; - bufpt -= 2; - if( a==0 || a>3 || (b>10 && b<14) ){ - bufpt[0] = 't'; - bufpt[1] = 'h'; - }else if( a==1 ){ - bufpt[0] = 's'; - bufpt[1] = 't'; - }else if( a==2 ){ - bufpt[0] = 'n'; - bufpt[1] = 'd'; - }else if( a==3 ){ - bufpt[0] = 'r'; - bufpt[1] = 'd'; - } - } + bufpt = &buf[etBUFSIZE-1]; { register char *cset; /* Use registers for speed */ register int base; @@ -391,7 +369,7 @@ static int vxprintf( longvalue = longvalue/base; }while( longvalue>0 ); } - length = &buf[etBUFSIZE]-bufpt; + length = &buf[etBUFSIZE-1]-bufpt; for(idx=precision-length; idx>0; idx--){ *(--bufpt) = '0'; /* Zero pad */ } @@ -403,7 +381,7 @@ static int vxprintf( for(pre=infop->prefix; (x=(*pre))!=0; pre++) *(--bufpt) = x; } } - length = &buf[etBUFSIZE]-bufpt; + length = &buf[etBUFSIZE-1]-bufpt; break; case etFLOAT: case etEXP: @@ -422,7 +400,7 @@ static int vxprintf( } if( infop->type==etGENERIC && precision>0 ) precision--; rounder = 0.0; -#ifdef COMPATIBILITY +#if 0 /* Rounding works like BSD when the constant 0.4999 is used. Wierd! */ for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1); #else @@ -433,12 +411,11 @@ static int vxprintf( /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ exp = 0; if( realvalue>0.0 ){ - int k = 0; - while( realvalue>=1e8 && k++<100 ){ realvalue *= 1e-8; exp+=8; } - while( realvalue>=10.0 && k++<100 ){ realvalue *= 0.1; exp++; } - while( realvalue<1e-8 && k++<100 ){ realvalue *= 1e8; exp-=8; } - while( realvalue<1.0 && k++<100 ){ realvalue *= 10.0; exp--; } - if( k>=100 ){ + while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; } + while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; } + while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; } + while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; } + if( exp>350 || exp<-350 ){ bufpt = "NaN"; length = 3; break; @@ -590,6 +567,25 @@ static int vxprintf( if( precision>=0 && precision<length ) length = precision; } break; + case etTOKEN: { + Token *pToken = va_arg(ap, Token*); + (*func)(arg, pToken->z, pToken->n); + length = width = 0; + break; + } + case etSRCLIST: { + SrcList *pSrc = va_arg(ap, SrcList*); + int k = va_arg(ap, int); + struct SrcList_item *pItem = &pSrc->a[k]; + assert( k>=0 && k<pSrc->nSrc ); + if( pItem->zDatabase && pItem->zDatabase[0] ){ + (*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase)); + (*func)(arg, ".", 1); + } + (*func)(arg, pItem->zName, strlen(pItem->zName)); + length = width = 0; + break; + } case etERROR: buf[0] = '%'; buf[1] = c; @@ -609,11 +605,6 @@ static int vxprintf( register int nspace; nspace = width-length; if( nspace>0 ){ - if( flag_center ){ - nspace = nspace/2; - width -= nspace; - flag_leftjustify = 1; - } count += nspace; while( nspace>=etSPACESIZE ){ (*func)(arg,spaces,etSPACESIZE); @@ -639,11 +630,7 @@ static int vxprintf( } } if( zExtra ){ - if( xtype==etDYNSTRING ){ - free(zExtra); - }else{ - sqliteFree(zExtra); - } + sqliteFree(zExtra); } }/* End for loop over the format string */ return errorflag ? -1 : count; @@ -657,7 +644,9 @@ struct sgMprintf { char *zBase; /* A base allocation */ char *zText; /* The string collected so far */ int nChar; /* Length of the string so far */ + int nTotal; /* Output size if unconstrained */ int nAlloc; /* Amount of space allocated in zText */ + void *(*xRealloc)(void*,int); /* Function used to realloc memory */ }; /* @@ -666,24 +655,25 @@ struct sgMprintf { ** This routine add nNewChar characters of text in zNewText to ** the sgMprintf structure pointed to by "arg". */ -static void mout(void *arg, char *zNewText, int nNewChar){ +static void mout(void *arg, const char *zNewText, int nNewChar){ struct sgMprintf *pM = (struct sgMprintf*)arg; + pM->nTotal += nNewChar; if( pM->nChar + nNewChar + 1 > pM->nAlloc ){ - pM->nAlloc = pM->nChar + nNewChar*2 + 1; - if( pM->zText==pM->zBase ){ - pM->zText = sqliteMalloc(pM->nAlloc); - if( pM->zText && pM->nChar ) memcpy(pM->zText,pM->zBase,pM->nChar); + if( pM->xRealloc==0 ){ + nNewChar = pM->nAlloc - pM->nChar - 1; }else{ - char *z = sqliteRealloc(pM->zText, pM->nAlloc); - if( z==0 ){ - sqliteFree(pM->zText); - pM->nChar = 0; - pM->nAlloc = 0; + pM->nAlloc = pM->nChar + nNewChar*2 + 1; + if( pM->zText==pM->zBase ){ + pM->zText = pM->xRealloc(0, pM->nAlloc); + if( pM->zText && pM->nChar ){ + memcpy(pM->zText, pM->zBase, pM->nChar); + } + }else{ + pM->zText = pM->xRealloc(pM->zText, pM->nAlloc); } - pM->zText = z; } } - if( pM->zText ){ + if( pM->zText && nNewChar>0 ){ memcpy(&pM->zText[pM->nChar], zNewText, nNewChar); pM->nChar += nNewChar; pM->zText[pM->nChar] = 0; @@ -691,114 +681,104 @@ static void mout(void *arg, char *zNewText, int nNewChar){ } /* -** sqlite_mprintf() works like printf(), but allocations memory to hold the -** resulting string and returns a pointer to the allocated memory. Use -** sqliteFree() to release the memory allocated. +** This routine is a wrapper around xprintf() that invokes mout() as +** the consumer. +*/ +static char *base_vprintf( + void *(*xRealloc)(void*,int), /* Routine to realloc memory. May be NULL */ + int useInternal, /* Use internal %-conversions if true */ + char *zInitBuf, /* Initially write here, before mallocing */ + int nInitBuf, /* Size of zInitBuf[] */ + const char *zFormat, /* format string */ + va_list ap /* arguments */ +){ + struct sgMprintf sM; + sM.zBase = sM.zText = zInitBuf; + sM.nChar = sM.nTotal = 0; + sM.nAlloc = nInitBuf; + sM.xRealloc = xRealloc; + vxprintf(mout, &sM, useInternal, zFormat, ap); + if( xRealloc ){ + if( sM.zText==sM.zBase ){ + sM.zText = xRealloc(0, sM.nChar+1); + memcpy(sM.zText, sM.zBase, sM.nChar+1); + }else if( sM.nAlloc>sM.nChar+10 ){ + sM.zText = xRealloc(sM.zText, sM.nChar+1); + } + } + return sM.zText; +} + +/* +** Realloc that is a real function, not a macro. +*/ +static void *printf_realloc(void *old, int size){ + return sqliteRealloc(old,size); +} + +/* +** Print into memory obtained from sqliteMalloc(). Use the internal +** %-conversion extensions. +*/ +char *sqliteVMPrintf(const char *zFormat, va_list ap){ + char zBase[1000]; + return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap); +} + +/* +** Print into memory obtained from sqliteMalloc(). Use the internal +** %-conversion extensions. */ char *sqliteMPrintf(const char *zFormat, ...){ va_list ap; - struct sgMprintf sMprintf; - char zBuf[200]; - - sMprintf.nChar = 0; - sMprintf.nAlloc = sizeof(zBuf); - sMprintf.zText = zBuf; - sMprintf.zBase = zBuf; - va_start(ap,zFormat); - vxprintf(mout,&sMprintf,zFormat,ap); + char *z; + char zBase[1000]; + va_start(ap, zFormat); + z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap); va_end(ap); - sMprintf.zText[sMprintf.nChar] = 0; - return sqliteRealloc(sMprintf.zText, sMprintf.nChar+1); + return z; } /* -** sqlite_mprintf() works like printf(), but allocations memory to hold the -** resulting string and returns a pointer to the allocated memory. Use -** sqliteFree() to release the memory allocated. +** Print into memory obtained from malloc(). Do not use the internal +** %-conversion extensions. This routine is for use by external users. */ char *sqlite_mprintf(const char *zFormat, ...){ va_list ap; - struct sgMprintf sMprintf; - char *zNew; + char *z; char zBuf[200]; - sMprintf.nChar = 0; - sMprintf.nAlloc = sizeof(zBuf); - sMprintf.zText = zBuf; - sMprintf.zBase = zBuf; va_start(ap,zFormat); - vxprintf(mout,&sMprintf,zFormat,ap); + z = base_vprintf((void*(*)(void*,int))realloc, 0, + zBuf, sizeof(zBuf), zFormat, ap); va_end(ap); - sMprintf.zText[sMprintf.nChar] = 0; - zNew = malloc( sMprintf.nChar+1 ); - if( zNew ) strcpy(zNew,sMprintf.zText); - if( sMprintf.zText!=sMprintf.zBase ){ - sqliteFree(sMprintf.zText); - } - return zNew; + return z; } /* This is the varargs version of sqlite_mprintf. */ char *sqlite_vmprintf(const char *zFormat, va_list ap){ - struct sgMprintf sMprintf; - char *zNew; char zBuf[200]; - sMprintf.nChar = 0; - sMprintf.zText = zBuf; - sMprintf.nAlloc = sizeof(zBuf); - sMprintf.zBase = zBuf; - vxprintf(mout,&sMprintf,zFormat,ap); - sMprintf.zText[sMprintf.nChar] = 0; - zNew = malloc( sMprintf.nChar+1 ); - if( zNew ) strcpy(zNew,sMprintf.zText); - if( sMprintf.zText!=sMprintf.zBase ){ - sqliteFree(sMprintf.zText); - } - return zNew; -} - -/* -** This function implements the callback from vxprintf. -** -** This routine add nNewChar characters of text in zNewText to -** the sgMprintf structure pointed to by "arg". Unlike mout() above, -** this routine does not allocate new space when the buffer fills. -** It just truncates. -*/ -static void sout(void *arg, char *zNewText, int nNewChar){ - struct sgMprintf *pM = (struct sgMprintf*)arg; - if( pM->nChar + nNewChar + 1 > pM->nAlloc ){ - nNewChar = pM->nAlloc - pM->nChar - 1; - if( nNewChar<=0 ) return; - } - memcpy(&pM->zText[pM->nChar], zNewText, nNewChar); - pM->nChar += nNewChar; - pM->zText[pM->nChar] = 0; + return base_vprintf((void*(*)(void*,int))realloc, 0, + zBuf, sizeof(zBuf), zFormat, ap); } /* -** sqlite_sprintf() works like sprintf() except that it ignores the +** sqlite_snprintf() works like snprintf() except that it ignores the ** current locale settings. This is important for SQLite because we ** are not able to use a "," as the decimal point in place of "." as ** specified by some locales. */ -int sqlite_snprintf(int n, char *zBuf, const char *zFormat, ...){ +char *sqlite_snprintf(int n, char *zBuf, const char *zFormat, ...){ + char *z; va_list ap; - struct sgMprintf sMprintf; - sMprintf.nChar = 0; - sMprintf.nAlloc = n; - sMprintf.zText = zBuf; - sMprintf.zBase = zBuf; va_start(ap,zFormat); - vxprintf(sout,&sMprintf,zFormat,ap); + z = base_vprintf(0, 0, zBuf, n, zFormat, ap); va_end(ap); - return sMprintf.nChar; + return z; } - - /* ** The following four routines implement the varargs versions of the ** sqlite_exec() and sqlite_get_table() interfaces. See the sqlite.h diff --git a/ext/sqlite/libsqlite/src/random.c b/ext/sqlite/libsqlite/src/random.c index d18bebff6b..dd8bdd4c58 100644 --- a/ext/sqlite/libsqlite/src/random.c +++ b/ext/sqlite/libsqlite/src/random.c @@ -35,15 +35,15 @@ ** on RC4, which we know works very well. */ static int randomByte(){ - int t; + unsigned char t; /* All threads share a single random number generator. ** This structure is the current state of the generator. */ static struct { - int isInit; /* True if initialized */ - int i, j; /* State variables */ - int s[256]; /* State variables */ + unsigned char isInit; /* True if initialized */ + unsigned char i, j; /* State variables */ + unsigned char s[256]; /* State variables */ } prng; /* Initialize the state of the random number generator once, @@ -65,8 +65,7 @@ static int randomByte(){ prng.s[i] = i; } for(i=0; i<256; i++){ - int t; - prng.j = (prng.j + prng.s[i] + k[i]) & 0xff; + prng.j += prng.s[i] + k[i]; t = prng.s[prng.j]; prng.s[prng.j] = prng.s[i]; prng.s[i] = t; @@ -76,38 +75,23 @@ static int randomByte(){ /* Generate and return single random byte */ - prng.i = (prng.i + 1) & 0xff; - prng.j = (prng.j + prng.s[prng.i]) & 0xff; + prng.i++; t = prng.s[prng.i]; + prng.j += t; prng.s[prng.i] = prng.s[prng.j]; prng.s[prng.j] = t; - t = prng.s[prng.i] + prng.s[prng.j]; - return prng.s[t & 0xff]; + t += prng.s[prng.i]; + return prng.s[t]; } /* -** Return an random 8-bit integer. +** Return N random bytes. */ -int sqliteRandomByte(){ - int r; +void sqliteRandomness(int N, void *pBuf){ + unsigned char *zBuf = pBuf; sqliteOsEnterMutex(); - r = randomByte(); - sqliteOsLeaveMutex(); - return r; -} - -/* -** Return a random 32-bit integer. The integer is generated by making -** 4 calls to sqliteRandomByte(). -*/ -int sqliteRandomInteger(){ - int r; - int i; - sqliteOsEnterMutex(); - r = randomByte(); - for(i=1; i<4; i++){ - r = (r<<8) + randomByte(); + while( N-- ){ + *(zBuf++) = randomByte(); } sqliteOsLeaveMutex(); - return r; } diff --git a/ext/sqlite/libsqlite/src/select.c b/ext/sqlite/libsqlite/src/select.c index c7525b3b6b..871f2e2c71 100644 --- a/ext/sqlite/libsqlite/src/select.c +++ b/ext/sqlite/libsqlite/src/select.c @@ -42,6 +42,9 @@ Select *sqliteSelectNew( sqliteExprDelete(pHaving); sqliteExprListDelete(pOrderBy); }else{ + if( pEList==0 ){ + pEList = sqliteExprListAppend(0, sqliteExpr(TK_ALL,0,0,0), 0); + } pNew->pEList = pEList; pNew->pSrc = pSrc; pNew->pWhere = pWhere; @@ -335,9 +338,7 @@ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){ sqliteExprCode(pParse, pOrderBy->a[i].pExpr); } zSortOrder[pOrderBy->nExpr] = 0; - sqliteVdbeAddOp(v, OP_SortMakeKey, pOrderBy->nExpr, 0); - sqliteVdbeChangeP3(v, -1, zSortOrder, strlen(zSortOrder)); - sqliteFree(zSortOrder); + sqliteVdbeOp3(v, OP_SortMakeKey, pOrderBy->nExpr, 0, zSortOrder, P3_DYNAMIC); sqliteVdbeAddOp(v, OP_SortPut, 0, 0); } @@ -360,8 +361,7 @@ void sqliteAddKeyType(Vdbe *v, ExprList *pEList){ zType[i] = sqliteExprType(pEList->a[i].pExpr)==SQLITE_SO_NUM ? 'n' : 't'; } zType[i] = 0; - sqliteVdbeChangeP3(v, -1, zType, nColumn); - sqliteFree(zType); + sqliteVdbeChangeP3(v, -1, zType, P3_DYNAMIC); } /* @@ -564,18 +564,19 @@ static void generateSortTail( int eDest, /* Write the sorted results here */ int iParm /* Optional parameter associated with eDest */ ){ - int end = sqliteVdbeMakeLabel(v); + int end1 = sqliteVdbeMakeLabel(v); + int end2 = sqliteVdbeMakeLabel(v); int addr; if( eDest==SRT_Sorter ) return; sqliteVdbeAddOp(v, OP_Sort, 0, 0); - addr = sqliteVdbeAddOp(v, OP_SortNext, 0, end); + addr = sqliteVdbeAddOp(v, OP_SortNext, 0, end1); if( p->iOffset>=0 ){ sqliteVdbeAddOp(v, OP_MemIncr, p->iOffset, addr+4); sqliteVdbeAddOp(v, OP_Pop, 1, 0); sqliteVdbeAddOp(v, OP_Goto, 0, addr); } if( p->iLimit>=0 ){ - sqliteVdbeAddOp(v, OP_MemIncr, p->iLimit, end); + sqliteVdbeAddOp(v, OP_MemIncr, p->iLimit, end2); } switch( eDest ){ case SRT_Callback: { @@ -601,7 +602,7 @@ static void generateSortTail( case SRT_Mem: { assert( nColumn==1 ); sqliteVdbeAddOp(v, OP_MemStore, iParm, 1); - sqliteVdbeAddOp(v, OP_Goto, 0, end); + sqliteVdbeAddOp(v, OP_Goto, 0, end1); break; } case SRT_Subroutine: { @@ -619,7 +620,9 @@ static void generateSortTail( } } sqliteVdbeAddOp(v, OP_Goto, 0, addr); - sqliteVdbeResolveLabel(v, end); + sqliteVdbeResolveLabel(v, end2); + sqliteVdbeAddOp(v, OP_Pop, 1, 0); + sqliteVdbeResolveLabel(v, end1); sqliteVdbeAddOp(v, OP_SortReset, 0, 0); } @@ -645,9 +648,6 @@ static void generateColumnTypes( ){ Vdbe *v = pParse->pVdbe; int i, j; - if( pParse->useCallback && (pParse->db->flags & SQLITE_ReportTypes)==0 ){ - return; - } for(i=0; i<pEList->nExpr; i++){ Expr *p = pEList->a[i].pExpr; char *zType = 0; @@ -672,15 +672,14 @@ static void generateColumnTypes( zType = "NUMERIC"; } } - sqliteVdbeAddOp(v, OP_ColumnName, i + pEList->nExpr, 0); - sqliteVdbeChangeP3(v, -1, zType, P3_STATIC); + sqliteVdbeOp3(v, OP_ColumnName, i + pEList->nExpr, 0, zType, 0); } } /* ** Generate code that will tell the VDBE the names of columns ** in the result set. This information is used to provide the -** azCol[] vaolues in the callback. +** azCol[] values in the callback. */ static void generateColumnNames( Parse *pParse, /* Parser context */ @@ -689,21 +688,24 @@ static void generateColumnNames( ){ Vdbe *v = pParse->pVdbe; int i, j; + sqlite *db = pParse->db; + int fullNames, shortNames; + + assert( v!=0 ); if( pParse->colNamesSet || v==0 || sqlite_malloc_failed ) return; pParse->colNamesSet = 1; + fullNames = (db->flags & SQLITE_FullColNames)!=0; + shortNames = (db->flags & SQLITE_ShortColNames)!=0; for(i=0; i<pEList->nExpr; i++){ Expr *p; - char *zType = 0; - int showFullNames; + int p2 = i==pEList->nExpr-1; p = pEList->a[i].pExpr; if( p==0 ) continue; if( pEList->a[i].zName ){ char *zName = pEList->a[i].zName; - sqliteVdbeAddOp(v, OP_ColumnName, i, 0); - sqliteVdbeChangeP3(v, -1, zName, strlen(zName)); + sqliteVdbeOp3(v, OP_ColumnName, i, p2, zName, 0); continue; } - showFullNames = (pParse->db->flags & SQLITE_FullColNames)!=0; if( p->op==TK_COLUMN && pTabList ){ Table *pTab; char *zCol; @@ -715,39 +717,31 @@ static void generateColumnNames( assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); if( iCol<0 ){ zCol = "_ROWID_"; - zType = "INTEGER"; }else{ zCol = pTab->aCol[iCol].zName; - zType = pTab->aCol[iCol].zType; } - if( p->span.z && p->span.z[0] && !showFullNames ){ - int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0); - sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n); + if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){ + int addr = sqliteVdbeOp3(v,OP_ColumnName, i, p2, p->span.z, p->span.n); sqliteVdbeCompressSpace(v, addr); - }else if( pTabList->nSrc>1 || showFullNames ){ + }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){ char *zName = 0; char *zTab; zTab = pTabList->a[j].zAlias; - if( showFullNames || zTab==0 ) zTab = pTab->zName; + if( fullNames || zTab==0 ) zTab = pTab->zName; sqliteSetString(&zName, zTab, ".", zCol, 0); - sqliteVdbeAddOp(v, OP_ColumnName, i, 0); - sqliteVdbeChangeP3(v, -1, zName, strlen(zName)); - sqliteFree(zName); + sqliteVdbeOp3(v, OP_ColumnName, i, p2, zName, P3_DYNAMIC); }else{ - sqliteVdbeAddOp(v, OP_ColumnName, i, 0); - sqliteVdbeChangeP3(v, -1, zCol, 0); + sqliteVdbeOp3(v, OP_ColumnName, i, p2, zCol, 0); } }else if( p->span.z && p->span.z[0] ){ - int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0); - sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n); + int addr = sqliteVdbeOp3(v,OP_ColumnName, i, p2, p->span.z, p->span.n); sqliteVdbeCompressSpace(v, addr); }else{ char zName[30]; assert( p->op!=TK_COLUMN || pTabList==0 ); sprintf(zName, "column%d", i+1); - sqliteVdbeAddOp(v, OP_ColumnName, i, 0); - sqliteVdbeChangeP3(v, -1, zName, strlen(zName)); + sqliteVdbeOp3(v, OP_ColumnName, i, p2, zName, 0); } } } @@ -777,8 +771,9 @@ static int fillInColumnList(Parse*, Select*); */ Table *sqliteResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ Table *pTab; - int i; + int i, j; ExprList *pEList; + Column *aCol; if( fillInColumnList(pParse, pSelect) ){ return 0; @@ -791,17 +786,27 @@ Table *sqliteResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ pEList = pSelect->pEList; pTab->nCol = pEList->nExpr; assert( pTab->nCol>0 ); - pTab->aCol = sqliteMalloc( sizeof(pTab->aCol[0])*pTab->nCol ); + pTab->aCol = aCol = sqliteMalloc( sizeof(pTab->aCol[0])*pTab->nCol ); for(i=0; i<pTab->nCol; i++){ - Expr *p; + Expr *p, *pR; if( pEList->a[i].zName ){ - pTab->aCol[i].zName = sqliteStrDup(pEList->a[i].zName); - }else if( (p=pEList->a[i].pExpr)->span.z && p->span.z[0] ){ + aCol[i].zName = sqliteStrDup(pEList->a[i].zName); + }else if( (p=pEList->a[i].pExpr)->op==TK_DOT + && (pR=p->pRight)!=0 && pR->token.z && pR->token.z[0] ){ + int cnt; + sqliteSetNString(&aCol[i].zName, pR->token.z, pR->token.n, 0); + for(j=cnt=0; j<i; j++){ + if( sqliteStrICmp(aCol[j].zName, aCol[i].zName)==0 ){ + int n; + char zBuf[30]; + sprintf(zBuf,"_%d",++cnt); + n = strlen(zBuf); + sqliteSetNString(&aCol[i].zName, pR->token.z, pR->token.n, zBuf, n,0); + j = -1; + } + } + }else if( p->span.z && p->span.z[0] ){ sqliteSetNString(&pTab->aCol[i].zName, p->span.z, p->span.n, 0); - }else if( p->op==TK_DOT && p->pRight && p->pRight->token.z && - p->pRight->token.z[0] ){ - sqliteSetNString(&pTab->aCol[i].zName, - p->pRight->token.z, p->pRight->token.n, 0); }else{ char zBuf[30]; sprintf(zBuf, "column%d", i+1); @@ -1262,7 +1267,7 @@ static void computeLimitRegisters(Parse *pParse, Select *p){ ** | ** `-----> SELECT b FROM t2 ** | -** `------> SELECT c FROM t1 +** `------> SELECT a FROM t1 ** ** The arrows in the diagram above represent the Select.pPrior pointer. ** So if this routine is called with p equal to the t3 query, then @@ -1485,14 +1490,6 @@ static int multiSelect(Parse *pParse, Select *p, int eDest, int iParm){ " do not have the same number of result columns", selectOpName(p->op)); return 1; } - - /* Issue a null callback if that is what the user wants. - */ - if( eDest==SRT_Callback && - (pParse->useCallback==0 || (pParse->db->flags & SQLITE_NullCallback)!=0) - ){ - sqliteVdbeAddOp(v, OP_NullCallback, p->pEList->nExpr, 0); - } return 0; } @@ -1512,25 +1509,29 @@ static int multiSelect(Parse *pParse, Select *p, int eDest, int iParm){ static void substExprList(ExprList*,int,ExprList*); /* Forward Decl */ static void substExpr(Expr *pExpr, int iTable, ExprList *pEList){ if( pExpr==0 ) return; - if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable && pExpr->iColumn>=0 ){ - Expr *pNew; - assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); - assert( pExpr->pLeft==0 && pExpr->pRight==0 && pExpr->pList==0 ); - pNew = pEList->a[pExpr->iColumn].pExpr; - assert( pNew!=0 ); - pExpr->op = pNew->op; - pExpr->dataType = pNew->dataType; - assert( pExpr->pLeft==0 ); - pExpr->pLeft = sqliteExprDup(pNew->pLeft); - assert( pExpr->pRight==0 ); - pExpr->pRight = sqliteExprDup(pNew->pRight); - assert( pExpr->pList==0 ); - pExpr->pList = sqliteExprListDup(pNew->pList); - pExpr->iTable = pNew->iTable; - pExpr->iColumn = pNew->iColumn; - pExpr->iAgg = pNew->iAgg; - sqliteTokenCopy(&pExpr->token, &pNew->token); - sqliteTokenCopy(&pExpr->span, &pNew->span); + if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){ + if( pExpr->iColumn<0 ){ + pExpr->op = TK_NULL; + }else{ + Expr *pNew; + assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); + assert( pExpr->pLeft==0 && pExpr->pRight==0 && pExpr->pList==0 ); + pNew = pEList->a[pExpr->iColumn].pExpr; + assert( pNew!=0 ); + pExpr->op = pNew->op; + pExpr->dataType = pNew->dataType; + assert( pExpr->pLeft==0 ); + pExpr->pLeft = sqliteExprDup(pNew->pLeft); + assert( pExpr->pRight==0 ); + pExpr->pRight = sqliteExprDup(pNew->pRight); + assert( pExpr->pList==0 ); + pExpr->pList = sqliteExprListDup(pNew->pList); + pExpr->iTable = pNew->iTable; + pExpr->iColumn = pNew->iColumn; + pExpr->iAgg = pNew->iAgg; + sqliteTokenCopy(&pExpr->token, &pNew->token); + sqliteTokenCopy(&pExpr->span, &pNew->span); + } }else{ substExpr(pExpr->pLeft, iTable, pEList); substExpr(pExpr->pRight, iTable, pEList); @@ -1835,18 +1836,23 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){ Vdbe *v; int seekOp; int cont; - ExprList eList; + ExprList *pEList, *pList, eList; struct ExprList_item eListItem; + SrcList *pSrc; + /* Check to see if this query is a simple min() or max() query. Return ** zero if it is not. */ if( p->pGroupBy || p->pHaving || p->pWhere ) return 0; - if( p->pSrc->nSrc!=1 ) return 0; - if( p->pEList->nExpr!=1 ) return 0; - pExpr = p->pEList->a[0].pExpr; + pSrc = p->pSrc; + if( pSrc->nSrc!=1 ) return 0; + pEList = p->pEList; + if( pEList->nExpr!=1 ) return 0; + pExpr = pEList->a[0].pExpr; if( pExpr->op!=TK_AGG_FUNCTION ) return 0; - if( pExpr->pList==0 || pExpr->pList->nExpr!=1 ) return 0; + pList = pExpr->pList; + if( pList==0 || pList->nExpr!=1 ) return 0; if( pExpr->token.n!=3 ) return 0; if( sqliteStrNICmp(pExpr->token.z,"min",3)==0 ){ seekOp = OP_Rewind; @@ -1855,10 +1861,10 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){ }else{ return 0; } - pExpr = pExpr->pList->a[0].pExpr; + pExpr = pList->a[0].pExpr; if( pExpr->op!=TK_COLUMN ) return 0; iCol = pExpr->iColumn; - pTab = p->pSrc->a[0].pTab; + pTab = pSrc->a[0].pTab; /* If we get to here, it means the query is of the correct form. ** Check to make sure we have an index and make pIdx point to the @@ -1886,24 +1892,30 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){ generateColumnTypes(pParse, p->pSrc, p->pEList); } + /* If the output is destined for a temporary table, open that table. + */ + if( eDest==SRT_TempTable ){ + sqliteVdbeAddOp(v, OP_OpenTemp, iParm, 0); + } + /* Generating code to find the min or the max. Basically all we have ** to do is find the first or the last entry in the chosen index. If ** the min() or max() is on the INTEGER PRIMARY KEY, then find the first ** or last entry in the main table. */ sqliteCodeVerifySchema(pParse, pTab->iDb); - base = p->pSrc->a[0].iCursor; + base = pSrc->a[0].iCursor; computeLimitRegisters(pParse, p); - sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenRead, base, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); + if( pSrc->a[0].pSelect==0 ){ + sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); + sqliteVdbeOp3(v, OP_OpenRead, base, pTab->tnum, pTab->zName, 0); + } cont = sqliteVdbeMakeLabel(v); if( pIdx==0 ){ sqliteVdbeAddOp(v, seekOp, base, 0); }else{ sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenRead, base+1, pIdx->tnum); - sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_OpenRead, base+1, pIdx->tnum, pIdx->zName, P3_STATIC); sqliteVdbeAddOp(v, seekOp, base+1, 0); sqliteVdbeAddOp(v, OP_IdxRecno, base+1, 0); sqliteVdbeAddOp(v, OP_Close, base+1, 0); @@ -1916,6 +1928,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){ selectInnerLoop(pParse, p, &eList, 0, 0, 0, -1, eDest, iParm, cont, cont); sqliteVdbeResolveLabel(v, cont); sqliteVdbeAddOp(v, OP_Close, base, 0); + return 1; } @@ -1935,7 +1948,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){ ** ** SRT_Union Store results as a key in a temporary table iParm ** -** SRT_Except Remove results form the temporary table iParm. +** SRT_Except Remove results from the temporary table iParm. ** ** SRT_Table Store results in temporary table iParm ** @@ -2156,14 +2169,6 @@ int sqliteSelect( generateColumnNames(pParse, pTabList, pEList); } - /* Check for the special case of a min() or max() function by itself - ** in the result set. - */ - if( simpleMinMaxQuery(pParse, p, eDest, iParm) ){ - rc = 0; - goto select_end; - } - /* Generate code for all sub-queries in the FROM clause */ for(i=0; i<pTabList->nSrc; i++){ @@ -2193,6 +2198,14 @@ int sqliteSelect( isDistinct = p->isDistinct; } + /* Check for the special case of a min() or max() function by itself + ** in the result set. + */ + if( simpleMinMaxQuery(pParse, p, eDest, iParm) ){ + rc = 0; + goto select_end; + } + /* Check to see if this is a subquery that can be "flattened" into its parent. ** If flattening is a possiblity, do so and return immediately. */ @@ -2262,8 +2275,7 @@ int sqliteSelect( for(i=0; i<pParse->nAgg; i++){ FuncDef *pFunc; if( (pFunc = pParse->aAgg[i].pFunc)!=0 && pFunc->xFinalize!=0 ){ - sqliteVdbeAddOp(v, OP_AggInit, 0, i); - sqliteVdbeChangeP3(v, -1, (char*)pFunc, P3_POINTER); + sqliteVdbeOp3(v, OP_AggInit, 0, i, (char*)pFunc, P3_POINTER); } } if( pGroupBy==0 ){ @@ -2308,6 +2320,7 @@ int sqliteSelect( ** processing. */ else{ + AggExpr *pAgg; if( pGroupBy ){ int lbl1; for(i=0; i<pGroupBy->nExpr; i++){ @@ -2317,29 +2330,27 @@ int sqliteSelect( if( pParse->db->file_format>=4 ) sqliteAddKeyType(v, pGroupBy); lbl1 = sqliteVdbeMakeLabel(v); sqliteVdbeAddOp(v, OP_AggFocus, 0, lbl1); - for(i=0; i<pParse->nAgg; i++){ - if( pParse->aAgg[i].isAgg ) continue; - sqliteExprCode(pParse, pParse->aAgg[i].pExpr); + for(i=0, pAgg=pParse->aAgg; i<pParse->nAgg; i++, pAgg++){ + if( pAgg->isAgg ) continue; + sqliteExprCode(pParse, pAgg->pExpr); sqliteVdbeAddOp(v, OP_AggSet, 0, i); } sqliteVdbeResolveLabel(v, lbl1); } - for(i=0; i<pParse->nAgg; i++){ + for(i=0, pAgg=pParse->aAgg; i<pParse->nAgg; i++, pAgg++){ Expr *pE; - int j; - if( !pParse->aAgg[i].isAgg ) continue; - pE = pParse->aAgg[i].pExpr; + int nExpr; + FuncDef *pDef; + if( !pAgg->isAgg ) continue; + assert( pAgg->pFunc!=0 ); + assert( pAgg->pFunc->xStep!=0 ); + pDef = pAgg->pFunc; + pE = pAgg->pExpr; + assert( pE!=0 ); assert( pE->op==TK_AGG_FUNCTION ); - if( pE->pList ){ - for(j=0; j<pE->pList->nExpr; j++){ - sqliteExprCode(pParse, pE->pList->a[j].pExpr); - } - } + nExpr = sqliteExprCodeExprList(pParse, pE->pList, pDef->includeTypes); sqliteVdbeAddOp(v, OP_Integer, i, 0); - sqliteVdbeAddOp(v, OP_AggFunc, 0, pE->pList ? pE->pList->nExpr : 0); - assert( pParse->aAgg[i].pFunc!=0 ); - assert( pParse->aAgg[i].pFunc->xStep!=0 ); - sqliteVdbeChangeP3(v, -1, (char*)pParse->aAgg[i].pFunc, P3_POINTER); + sqliteVdbeOp3(v, OP_AggFunc, 0, nExpr, (char*)pDef, P3_POINTER); } } @@ -2375,13 +2386,16 @@ int sqliteSelect( generateSortTail(p, v, pEList->nExpr, eDest, iParm); } - - /* Issue a null callback if that is what the user wants. + /* If this was a subquery, we have now converted the subquery into a + ** temporary table. So delete the subquery structure from the parent + ** to prevent this subquery from being evaluated again and to force the + ** the use of the temporary table. */ - if( eDest==SRT_Callback && - (pParse->useCallback==0 || (pParse->db->flags & SQLITE_NullCallback)!=0) - ){ - sqliteVdbeAddOp(v, OP_NullCallback, pEList->nExpr, 0); + if( pParent ){ + assert( pParent->pSrc->nSrc>parentTab ); + assert( pParent->pSrc->a[parentTab].pSelect==p ); + sqliteSelectDelete(p); + pParent->pSrc->a[parentTab].pSelect = 0; } /* The SELECT was successfully coded. Set the return code to 0 diff --git a/ext/sqlite/libsqlite/src/sqlite.h.in b/ext/sqlite/libsqlite/src/sqlite.h.in index 228cecfe8d..11edb43489 100644 --- a/ext/sqlite/libsqlite/src/sqlite.h.in +++ b/ext/sqlite/libsqlite/src/sqlite.h.in @@ -167,6 +167,7 @@ int sqlite_exec( #define SQLITE_AUTH 23 /* Authorization denied */ #define SQLITE_FORMAT 24 /* Auxiliary database format error */ #define SQLITE_RANGE 25 /* 2nd parameter to sqlite_bind out of range */ +#define SQLITE_NOTADB 26 /* File opened that is not a database file */ #define SQLITE_ROW 100 /* sqlite_step() has another row ready */ #define SQLITE_DONE 101 /* sqlite_step() has finished executing */ @@ -203,6 +204,32 @@ int sqlite_last_insert_rowid(sqlite*); */ int sqlite_changes(sqlite*); +/* +** This function returns the number of database rows that were changed +** by the last INSERT, UPDATE, or DELETE statment executed by sqlite_exec(), +** or by the last VM to run to completion. The change count is not updated +** by SQL statements other than INSERT, UPDATE or DELETE. +** +** Changes are counted, even if they are later undone by a ROLLBACK or +** ABORT. Changes associated with trigger programs that execute as a +** result of the INSERT, UPDATE, or DELETE statement are not counted. +** +** If a callback invokes sqlite_exec() recursively, then the changes +** in the inner, recursive call are counted together with the changes +** in the outer call. +** +** SQLite implements the command "DELETE FROM table" without a WHERE clause +** by dropping and recreating the table. (This is much faster than going +** through and deleting individual elements form the table.) Because of +** this optimization, the change count for "DELETE FROM table" will be +** zero regardless of the number of elements that were originally in the +** table. To get an accurate count of the number of rows deleted, use +** "DELETE FROM table WHERE 1" instead. +** +******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** +*/ +int sqlite_last_statement_changes(sqlite*); + /* If the parameter to this routine is one of the return value constants ** defined above, then this routine returns a constant text string which ** descripts (in English) the meaning of the return value. @@ -439,13 +466,12 @@ int sqlite_create_aggregate( ** Use the following routine to define the datatype returned by a ** user-defined function. The second argument can be one of the ** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it -** can be an integer greater than or equal to zero. The datatype -** will be numeric or text (the only two types supported) if the -** argument is SQLITE_NUMERIC or SQLITE_TEXT. If the argument is -** SQLITE_ARGS, then the datatype is numeric if any argument to the -** function is numeric and is text otherwise. If the second argument -** is an integer, then the datatype of the result is the same as the -** parameter to the function that corresponds to that integer. +** can be an integer greater than or equal to zero. When the datatype +** parameter is non-negative, the type of the result will be the +** same as the datatype-th argument. If datatype==SQLITE_NUMERIC +** then the result is always numeric. If datatype==SQLITE_TEXT then +** the result is always text. If datatype==SQLITE_ARGS then the result +** is numeric if any argument is numeric and is text otherwise. */ int sqlite_function_type( sqlite *db, /* The database there the function is registered */ @@ -753,9 +779,88 @@ int sqlite_bind(sqlite_vm*, int idx, const char *value, int len, int copy); ** query is immediately terminated and any database changes rolled back. If the ** query was part of a larger transaction, then the transaction is not rolled ** back and remains active. The sqlite_exec() call returns SQLITE_ABORT. +** +******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** */ void sqlite_progress_handler(sqlite*, int, int(*)(void*), void*); +/* +** Register a callback function to be invoked whenever a new transaction +** is committed. The pArg argument is passed through to the callback. +** callback. If the callback function returns non-zero, then the commit +** is converted into a rollback. +** +** If another function was previously registered, its pArg value is returned. +** Otherwise NULL is returned. +** +** Registering a NULL function disables the callback. +** +******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** +*/ +void *sqlite_commit_hook(sqlite*, int(*)(void*), void*); + +/* +** Open an encrypted SQLite database. If pKey==0 or nKey==0, this routine +** is the same as sqlite_open(). +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +sqlite *sqlite_open_encrypted( + const char *zFilename, /* Name of the encrypted database */ + const void *pKey, /* Pointer to the key */ + int nKey, /* Number of bytes in the key */ + int *pErrcode, /* Write error code here */ + char **pzErrmsg /* Write error message here */ +); + +/* +** Change the key on an open database. If the current database is not +** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the +** database is decrypted. +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +int sqlite_rekey( + sqlite *db, /* Database to be rekeyed */ + const void *pKey, int nKey /* The new key */ +); + +/* +** Encode a binary buffer "in" of size n bytes so that it contains +** no instances of characters '\'' or '\000'. The output is +** null-terminated and can be used as a string value in an INSERT +** or UPDATE statement. Use sqlite_decode_binary() to convert the +** string back into its original binary. +** +** The result is written into a preallocated output buffer "out". +** "out" must be able to hold at least 2 +(257*n)/254 bytes. +** In other words, the output will be expanded by as much as 3 +** bytes for every 254 bytes of input plus 2 bytes of fixed overhead. +** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.) +** +** The return value is the number of characters in the encoded +** string, excluding the "\000" terminator. +** +** If out==NULL then no output is generated but the routine still returns +** the number of characters that would have been generated if out had +** not been NULL. +*/ +int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out); + +/* +** Decode the string "in" into binary data and write it into "out". +** This routine reverses the encoding created by sqlite_encode_binary(). +** The output will always be a few bytes less than the input. The number +** of bytes of output is returned. If the input is not a well-formed +** encoding, -1 is returned. +** +** The "in" and "out" parameters may point to the same buffer in order +** to decode a string in place. +*/ +int sqlite_decode_binary(const unsigned char *in, unsigned char *out); + #ifdef __cplusplus } /* End of the 'extern "C"' block */ #endif diff --git a/ext/sqlite/libsqlite/src/sqlite.w32.h b/ext/sqlite/libsqlite/src/sqlite.w32.h index becef09790..92e59b9eed 100644 --- a/ext/sqlite/libsqlite/src/sqlite.w32.h +++ b/ext/sqlite/libsqlite/src/sqlite.w32.h @@ -28,7 +28,7 @@ extern "C" { /* ** The version of the SQLite library. */ -#define SQLITE_VERSION "2.8.11" +#define SQLITE_VERSION "2.8.14" /* ** The version string is also compiled into the library so that a program @@ -167,6 +167,7 @@ int sqlite_exec( #define SQLITE_AUTH 23 /* Authorization denied */ #define SQLITE_FORMAT 24 /* Auxiliary database format error */ #define SQLITE_RANGE 25 /* 2nd parameter to sqlite_bind out of range */ +#define SQLITE_NOTADB 26 /* File opened that is not a database file */ #define SQLITE_ROW 100 /* sqlite_step() has another row ready */ #define SQLITE_DONE 101 /* sqlite_step() has finished executing */ @@ -203,6 +204,32 @@ int sqlite_last_insert_rowid(sqlite*); */ int sqlite_changes(sqlite*); +/* +** This function returns the number of database rows that were changed +** by the last INSERT, UPDATE, or DELETE statment executed by sqlite_exec(), +** or by the last VM to run to completion. The change count is not updated +** by SQL statements other than INSERT, UPDATE or DELETE. +** +** Changes are counted, even if they are later undone by a ROLLBACK or +** ABORT. Changes associated with trigger programs that execute as a +** result of the INSERT, UPDATE, or DELETE statement are not counted. +** +** If a callback invokes sqlite_exec() recursively, then the changes +** in the inner, recursive call are counted together with the changes +** in the outer call. +** +** SQLite implements the command "DELETE FROM table" without a WHERE clause +** by dropping and recreating the table. (This is much faster than going +** through and deleting individual elements form the table.) Because of +** this optimization, the change count for "DELETE FROM table" will be +** zero regardless of the number of elements that were originally in the +** table. To get an accurate count of the number of rows deleted, use +** "DELETE FROM table WHERE 1" instead. +** +******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** +*/ +int sqlite_last_statement_changes(sqlite*); + /* If the parameter to this routine is one of the return value constants ** defined above, then this routine returns a constant text string which ** descripts (in English) the meaning of the return value. @@ -439,13 +466,12 @@ int sqlite_create_aggregate( ** Use the following routine to define the datatype returned by a ** user-defined function. The second argument can be one of the ** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it -** can be an integer greater than or equal to zero. The datatype -** will be numeric or text (the only two types supported) if the -** argument is SQLITE_NUMERIC or SQLITE_TEXT. If the argument is -** SQLITE_ARGS, then the datatype is numeric if any argument to the -** function is numeric and is text otherwise. If the second argument -** is an integer, then the datatype of the result is the same as the -** parameter to the function that corresponds to that integer. +** can be an integer greater than or equal to zero. When the datatype +** parameter is non-negative, the type of the result will be the +** same as the datatype-th argument. If datatype==SQLITE_NUMERIC +** then the result is always numeric. If datatype==SQLITE_TEXT then +** the result is always text. If datatype==SQLITE_ARGS then the result +** is numeric if any argument is numeric and is text otherwise. */ int sqlite_function_type( sqlite *db, /* The database there the function is registered */ @@ -753,9 +779,88 @@ int sqlite_bind(sqlite_vm*, int idx, const char *value, int len, int copy); ** query is immediately terminated and any database changes rolled back. If the ** query was part of a larger transaction, then the transaction is not rolled ** back and remains active. The sqlite_exec() call returns SQLITE_ABORT. +** +******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** */ void sqlite_progress_handler(sqlite*, int, int(*)(void*), void*); +/* +** Register a callback function to be invoked whenever a new transaction +** is committed. The pArg argument is passed through to the callback. +** callback. If the callback function returns non-zero, then the commit +** is converted into a rollback. +** +** If another function was previously registered, its pArg value is returned. +** Otherwise NULL is returned. +** +** Registering a NULL function disables the callback. +** +******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** +*/ +void *sqlite_commit_hook(sqlite*, int(*)(void*), void*); + +/* +** Open an encrypted SQLite database. If pKey==0 or nKey==0, this routine +** is the same as sqlite_open(). +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +sqlite *sqlite_open_encrypted( + const char *zFilename, /* Name of the encrypted database */ + const void *pKey, /* Pointer to the key */ + int nKey, /* Number of bytes in the key */ + int *pErrcode, /* Write error code here */ + char **pzErrmsg /* Write error message here */ +); + +/* +** Change the key on an open database. If the current database is not +** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the +** database is decrypted. +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +int sqlite_rekey( + sqlite *db, /* Database to be rekeyed */ + const void *pKey, int nKey /* The new key */ +); + +/* +** Encode a binary buffer "in" of size n bytes so that it contains +** no instances of characters '\'' or '\000'. The output is +** null-terminated and can be used as a string value in an INSERT +** or UPDATE statement. Use sqlite_decode_binary() to convert the +** string back into its original binary. +** +** The result is written into a preallocated output buffer "out". +** "out" must be able to hold at least 2 +(257*n)/254 bytes. +** In other words, the output will be expanded by as much as 3 +** bytes for every 254 bytes of input plus 2 bytes of fixed overhead. +** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.) +** +** The return value is the number of characters in the encoded +** string, excluding the "\000" terminator. +** +** If out==NULL then no output is generated but the routine still returns +** the number of characters that would have been generated if out had +** not been NULL. +*/ +int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out); + +/* +** Decode the string "in" into binary data and write it into "out". +** This routine reverses the encoding created by sqlite_encode_binary(). +** The output will always be a few bytes less than the input. The number +** of bytes of output is returned. If the input is not a well-formed +** encoding, -1 is returned. +** +** The "in" and "out" parameters may point to the same buffer in order +** to decode a string in place. +*/ +int sqlite_decode_binary(const unsigned char *in, unsigned char *out); + #ifdef __cplusplus } /* End of the 'extern "C"' block */ #endif diff --git a/ext/sqlite/libsqlite/src/sqliteInt.h b/ext/sqlite/libsqlite/src/sqliteInt.h index 04a90dccf2..57e3ab6e36 100644 --- a/ext/sqlite/libsqlite/src/sqliteInt.h +++ b/ext/sqlite/libsqlite/src/sqliteInt.h @@ -16,7 +16,6 @@ #include "config.h" #include "sqlite.h" #include "hash.h" -#include "vdbe.h" #include "parse.h" #include "btree.h" #include <stdio.h> @@ -106,6 +105,9 @@ #ifndef UINT8_TYPE # define UINT8_TYPE unsigned char #endif +#ifndef INT8_TYPE +# define INT8_TYPE signed char +#endif #ifndef INTPTR_TYPE # if SQLITE_PTR_SZ==4 # define INTPTR_TYPE int @@ -116,10 +118,16 @@ typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ +typedef UINT8_TYPE i8; /* 1-byte signed integer */ typedef INTPTR_TYPE ptr; /* Big enough to hold a pointer */ typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */ /* +** Defer sourcing vdbe.h until after the "u8" typedef is defined. +*/ +#include "vdbe.h" + +/* ** Most C compilers these days recognize "long double", don't they? ** Just in case we encounter one that does not, we will create a macro ** for long double so that it can be easily changed to just "double". @@ -174,6 +182,7 @@ typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */ # define sqliteStrNDup(X,Y) sqliteStrNDup_(X,Y,__FILE__,__LINE__) void sqliteStrRealloc(char**); #else +# define sqliteRealloc_(X,Y) sqliteRealloc(X,Y) # define sqliteStrRealloc(X) #endif @@ -254,6 +263,8 @@ struct Db { Hash aFKey; /* Foreign keys indexed by to-table */ u8 inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ u16 flags; /* Flags associated with this database */ + void *pAux; /* Auxiliary data. Usually NULL */ + void (*xFreeAux)(void*); /* Routine to free pAux */ }; /* @@ -307,6 +318,24 @@ struct Db { ** are stored. If 1, then a file is created to hold those tables. If ** 2, then they are held in memory. 0 means use the default value in ** the TEMP_STORE macro. +** +** The sqlite.lastRowid records the last insert rowid generated by an +** insert statement. Inserts on views do not affect its value. Each +** trigger has its own context, so that lastRowid can be updated inside +** triggers as usual. The previous value will be restored once the trigger +** exits. Upon entering a before or instead of trigger, lastRowid is no +** longer (since after version 2.8.12) reset to -1. +** +** The sqlite.nChange does not count changes within triggers and keeps no +** context. It is reset at start of sqlite_exec. +** The sqlite.lsChange represents the number of changes made by the last +** insert, update, or delete statement. It remains constant throughout the +** length of a statement and is then updated by OP_SetCounts. It keeps a +** context stack just like lastRowid so that the count of changes +** within a trigger is not seen outside the trigger. Changes to views do not +** affect the value of lsChange. +** The sqlite.csChange keeps track of the number of current changes (since +** the last statement) and is used to update sqlite_lsChange. */ struct sqlite { int nDb; /* Number of backends currently in use */ @@ -316,18 +345,27 @@ struct sqlite { u8 file_format; /* What file format version is this database? */ u8 safety_level; /* How aggressive at synching data to disk */ u8 want_to_close; /* Close after all VDBEs are deallocated */ + u8 temp_store; /* 1=file, 2=memory, 0=compile-time default */ + u8 onError; /* Default conflict algorithm */ int next_cookie; /* Next value of aDb[0].schema_cookie */ int cache_size; /* Number of pages to use in the cache */ - int temp_store; /* 1=file, 2=memory, 0=compile-time default */ int nTable; /* Number of tables in the database */ void *pBusyArg; /* 1st Argument to the busy callback */ int (*xBusyCallback)(void *,const char*,int); /* The busy callback */ + void *pCommitArg; /* Argument to xCommitCallback() */ + int (*xCommitCallback)(void*);/* Invoked at every commit. */ Hash aFunc; /* All functions that can be in SQL exprs */ - int lastRowid; /* ROWID of most recent insert */ + int lastRowid; /* ROWID of most recent insert (see above) */ int priorNewRowid; /* Last randomly generated ROWID */ - int onError; /* Default conflict algorithm */ int magic; /* Magic number for detect library misuse */ - int nChange; /* Number of rows changed */ + int nChange; /* Number of rows changed (see above) */ + int lsChange; /* Last statement change count (see above) */ + int csChange; /* Current statement change count (see above) */ + struct sqliteInitInfo { /* Information used during initialization */ + int iDb; /* When back is being initialized */ + int newTnum; /* Rootpage of table being initialized */ + u8 busy; /* TRUE if currently initializing */ + } init; struct Vdbe *pVdbe; /* List of active virtual machines */ void (*xTrace)(void*,const char*); /* Trace function */ void *pTraceArg; /* Argument to the trace function */ @@ -356,10 +394,11 @@ struct sqlite { #define SQLITE_InTrans 0x00000008 /* True if in a transaction */ #define SQLITE_InternChanges 0x00000010 /* Uncommitted Hash table changes */ #define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */ -#define SQLITE_CountRows 0x00000040 /* Count rows changed by INSERT, */ +#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ +#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ /* DELETE, or UPDATE and return */ /* the count using a callback. */ -#define SQLITE_NullCallback 0x00000080 /* Invoke the callback once if the */ +#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ /* result set is empty */ #define SQLITE_ReportTypes 0x00000200 /* Include information on datatypes */ /* in 4th argument of callback */ @@ -384,10 +423,12 @@ struct FuncDef { void (*xFunc)(sqlite_func*,int,const char**); /* Regular function */ void (*xStep)(sqlite_func*,int,const char**); /* Aggregate function step */ void (*xFinalize)(sqlite_func*); /* Aggregate function finializer */ - int nArg; /* Number of arguments */ - int dataType; /* Datatype of the result */ - void *pUserData; /* User data parameter */ - FuncDef *pNext; /* Next function with same name */ + signed char nArg; /* Number of arguments. -1 means unlimited */ + signed char dataType; /* Arg that determines datatype. -1=NUMERIC, */ + /* -2=TEXT. -3=SQLITE_ARGS */ + u8 includeTypes; /* Add datatypes to args of xFunc and xStep */ + void *pUserData; /* User data parameter */ + FuncDef *pNext; /* Next function with same name */ }; /* @@ -401,6 +442,7 @@ struct Column { u8 notNull; /* True if there is a NOT NULL constraint */ u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */ u8 sortOrder; /* Some combination of SQLITE_SO_... values */ + u8 dottedName; /* True if zName contains a "." character */ }; /* @@ -585,6 +627,10 @@ struct Index { /* ** Each token coming out of the lexer is an instance of ** this structure. Tokens are also used as part of an expression. +** +** Note if Token.z==0 then Token.dyn and Token.n are undefined and +** may contain random values. Do not make any assuptions about Token.dyn +** and Token.n when Token.z==0. */ struct Token { const char *z; /* Text of the token. Not NULL-terminated! */ @@ -859,8 +905,6 @@ struct AggExpr { struct Parse { sqlite *db; /* The main database structure */ int rc; /* Return code from execution */ - sqlite_callback xCallback; /* The callback function */ - void *pArg; /* First argument to the callback function */ char *zErrMsg; /* An error message */ Token sErrToken; /* The token at which the error occurred */ Token sFirstToken; /* The first token parsed */ @@ -870,13 +914,9 @@ struct Parse { Vdbe *pVdbe; /* An engine for executing database bytecode */ u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ u8 explain; /* True if the EXPLAIN flag is found on the query */ - u8 initFlag; /* True if reparsing CREATE TABLEs */ u8 nameClash; /* A permanent table name clashes with temp table name */ u8 useAgg; /* If true, extract field values from the aggregator ** while generating expressions. Normally false */ - u8 iDb; /* Index of database whose schema is being parsed */ - u8 useCallback; /* True if callbacks should be used to report results */ - int newTnum; /* Table number to use when reparsing CREATE TABLEs */ int nErr; /* Number of errors seen */ int nTab; /* Number of previously allocated VDBE cursors */ int nMem; /* Number of memory cells used so far */ @@ -899,6 +939,13 @@ struct AuthContext { }; /* +** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete +*/ +#define OPFLAG_NCHANGE 1 /* Set to update db->nChange */ +#define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */ +#define OPFLAG_CSCHANGE 4 /* Set to update db->csChange */ + +/* * Each trigger present in the database schema is stored as an instance of * struct Trigger. * @@ -1067,7 +1114,8 @@ void sqliteRealToSortable(double r, char *); char *sqliteStrNDup(const char*, int); # define sqliteCheckMemory(a,b) #endif -char *sqliteMPrintf(const char *,...); +char *sqliteMPrintf(const char*, ...); +char *sqliteVMPrintf(const char*, va_list); void sqliteSetString(char **, const char *, ...); void sqliteSetNString(char **, ...); void sqliteErrorMsg(Parse*, const char*, ...); @@ -1126,6 +1174,7 @@ void sqliteUpdate(Parse*, SrcList*, ExprList*, Expr*, int); WhereInfo *sqliteWhereBegin(Parse*, SrcList*, Expr*, int, ExprList**); void sqliteWhereEnd(WhereInfo*); void sqliteExprCode(Parse*, Expr*); +int sqliteExprCodeExprList(Parse*, ExprList*, int); void sqliteExprIfTrue(Parse*, Expr*, int, int); void sqliteExprIfFalse(Parse*, Expr*, int, int); Table *sqliteFindTable(sqlite*,const char*, const char*); @@ -1145,8 +1194,7 @@ int sqliteFuncId(Token*); int sqliteExprResolveIds(Parse*, SrcList*, ExprList*, Expr*); int sqliteExprAnalyzeAggregates(Parse*, Expr*); Vdbe *sqliteGetVdbe(Parse*); -int sqliteRandomByte(void); -int sqliteRandomInteger(void); +void sqliteRandomness(int, void*); void sqliteRollbackAll(sqlite*); void sqliteCodeVerifySchema(Parse*, int); void sqliteBeginTransaction(Parse*, int); @@ -1159,6 +1207,7 @@ void sqliteGenerateRowDelete(sqlite*, Vdbe*, Table*, int, int); void sqliteGenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*); void sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int); void sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int, int); +int sqliteOpenTableAndIndices(Parse*, Table*, int); void sqliteBeginWriteOperation(Parse*, int, int); void sqliteEndWriteOperation(Parse*); Expr *sqliteExprDup(Expr*); @@ -1202,7 +1251,7 @@ void sqliteDeferForeignKey(Parse*, int); # define sqliteAuthContextPush(a,b,c) # define sqliteAuthContextPop(a) ((void)(a)) #endif -void sqliteAttach(Parse*, Token*, Token*); +void sqliteAttach(Parse*, Token*, Token*, Token*); void sqliteDetach(Parse*, Token*); int sqliteBtreeFactory(const sqlite *db, const char *zFilename, int mode, int nPg, Btree **ppBtree); @@ -1212,6 +1261,6 @@ int sqliteFixSelect(DbFixer*, Select*); int sqliteFixExpr(DbFixer*, Expr*); int sqliteFixExprList(DbFixer*, ExprList*); int sqliteFixTriggerStep(DbFixer*, TriggerStep*); -double sqliteAtoF(const char *z); -int sqlite_snprintf(int,char*,const char*,...); +double sqliteAtoF(const char *z, const char **); +char *sqlite_snprintf(int,char*,const char*,...); int sqliteFitsIn32Bits(const char *); diff --git a/ext/sqlite/libsqlite/src/table.c b/ext/sqlite/libsqlite/src/table.c index dc2d9fa7e5..48c852d487 100644 --- a/ext/sqlite/libsqlite/src/table.c +++ b/ext/sqlite/libsqlite/src/table.c @@ -31,7 +31,7 @@ typedef struct TabResult { int nAlloc; int nRow; int nColumn; - int nData; + long nData; int rc; } TabResult; diff --git a/ext/sqlite/libsqlite/src/tokenize.c b/ext/sqlite/libsqlite/src/tokenize.c index ddf014f8fe..978c53418d 100644 --- a/ext/sqlite/libsqlite/src/tokenize.c +++ b/ext/sqlite/libsqlite/src/tokenize.c @@ -474,7 +474,7 @@ abort_parse: pParse->zErrMsg = 0; if( !nErr ) nErr++; } - if( pParse->pVdbe && (pParse->useCallback || pParse->nErr>0) ){ + if( pParse->pVdbe && pParse->nErr>0 ){ sqliteVdbeDelete(pParse->pVdbe); pParse->pVdbe = 0; } diff --git a/ext/sqlite/libsqlite/src/trigger.c b/ext/sqlite/libsqlite/src/trigger.c index 82b679755a..8442bb5dd8 100644 --- a/ext/sqlite/libsqlite/src/trigger.c +++ b/ext/sqlite/libsqlite/src/trigger.c @@ -65,8 +65,8 @@ void sqliteBeginTrigger( */ if( sqlite_malloc_failed ) goto trigger_cleanup; assert( pTableName->nSrc==1 ); - if( pParse->initFlag - && sqliteFixInit(&sFix, pParse, pParse->iDb, "trigger", pName) + if( db->init.busy + && sqliteFixInit(&sFix, pParse, db->init.iDb, "trigger", pName) && sqliteFixSrcList(&sFix, pTableName) ){ goto trigger_cleanup; @@ -76,7 +76,7 @@ void sqliteBeginTrigger( goto trigger_cleanup; } iDb = isTemp ? 1 : tab->iDb; - if( iDb>=2 && !pParse->initFlag ){ + if( iDb>=2 && !db->init.busy ){ sqliteErrorMsg(pParse, "triggers may not be added to auxiliary " "database %s", db->aDb[tab->iDb].zName); goto trigger_cleanup; @@ -181,8 +181,8 @@ void sqliteFinishTrigger( /* if we are not initializing, and this trigger is not on a TEMP table, ** build the sqlite_master entry */ - if( !pParse->initFlag ){ - static VdbeOp insertTrig[] = { + if( !db->init.busy ){ + static VdbeOpList insertTrig[] = { { OP_NewRecno, 0, 0, 0 }, { OP_String, 0, 0, "trigger" }, { OP_String, 0, 0, 0 }, /* 2: trigger name */ @@ -450,7 +450,7 @@ void sqliteDropTriggerPtr(Parse *pParse, Trigger *pTrigger, int nested){ */ if( pTable!=0 && !nested && (v = sqliteGetVdbe(pParse))!=0 ){ int base; - static VdbeOp dropTrigger[] = { + static VdbeOpList dropTrigger[] = { { OP_Rewind, 0, ADDR(9), 0}, { OP_String, 0, 0, 0}, /* 1 */ { OP_Column, 0, 1, 0}, @@ -746,7 +746,9 @@ int sqliteCodeRowTrigger( sqliteExprIfFalse(pParse, whenExpr, endTrigger, 1); sqliteExprDelete(whenExpr); + sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPush, 0, 0); codeTriggerProgram(pParse, pTrigger->step_list, orconf); + sqliteVdbeAddOp(pParse->pVdbe, OP_ContextPop, 0, 0); /* Pop the entry off the trigger stack */ pParse->trigStack = pParse->trigStack->pNext; diff --git a/ext/sqlite/libsqlite/src/update.c b/ext/sqlite/libsqlite/src/update.c index 7a69a9d6cd..f20cc9b531 100644 --- a/ext/sqlite/libsqlite/src/update.c +++ b/ext/sqlite/libsqlite/src/update.c @@ -32,7 +32,8 @@ void sqliteUpdate( ){ int i, j; /* Loop counters */ Table *pTab; /* The table to be updated */ - int addr; /* VDBE instruction address of the start of the loop */ + int loopStart; /* VDBE instruction address of the start of the loop */ + int jumpInst; /* Addr of VDBE instruction to jump out of loop */ WhereInfo *pWInfo; /* Information about the WHERE clause */ Vdbe *v; /* The virtual database engine */ Index *pIdx; /* For looping over indices */ @@ -49,6 +50,7 @@ void sqliteUpdate( Expr *pRecnoExpr; /* Expression defining the new record number */ int openAll; /* True if all indices need to be opened */ int isView; /* Trying to update a view */ + int iStackDepth; /* Index of memory cell holding stack depth */ AuthContext sContext; /* The authorization context */ int before_triggers; /* True if there are any BEFORE triggers */ @@ -62,6 +64,7 @@ void sqliteUpdate( if( pParse->nErr || sqlite_malloc_failed ) goto update_cleanup; db = pParse->db; assert( pTabList->nSrc==1 ); + iStackDepth = pParse->nMem++; /* Locate the table which we want to update. */ @@ -248,7 +251,11 @@ void sqliteUpdate( /* The top of the update loop for when there are triggers. */ sqliteVdbeAddOp(v, OP_ListRewind, 0, 0); - addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0); + sqliteVdbeAddOp(v, OP_StackDepth, 0, 0); + sqliteVdbeAddOp(v, OP_MemStore, iStackDepth, 1); + loopStart = sqliteVdbeAddOp(v, OP_MemLoad, iStackDepth, 0); + sqliteVdbeAddOp(v, OP_StackReset, 0, 0); + jumpInst = sqliteVdbeAddOp(v, OP_ListRead, 0, 0); sqliteVdbeAddOp(v, OP_Dup, 0, 0); /* Open a cursor and make it point to the record that is @@ -295,7 +302,7 @@ void sqliteUpdate( /* Fire the BEFORE and INSTEAD OF triggers */ if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab, - newIdx, oldIdx, onError, addr) ){ + newIdx, oldIdx, onError, loopStart) ){ goto update_cleanup; } } @@ -336,10 +343,10 @@ void sqliteUpdate( */ if( !row_triggers_exist ){ sqliteVdbeAddOp(v, OP_ListRewind, 0, 0); - addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0); + jumpInst = loopStart = sqliteVdbeAddOp(v, OP_ListRead, 0, 0); sqliteVdbeAddOp(v, OP_Dup, 0, 0); } - sqliteVdbeAddOp(v, OP_NotExists, iCur, addr); + sqliteVdbeAddOp(v, OP_NotExists, iCur, loopStart); /* If the record number will change, push the record number as it ** will be after the update. (The old record number is currently @@ -368,7 +375,7 @@ void sqliteUpdate( /* Do constraint checks */ sqliteGenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, - onError, addr); + onError, loopStart); /* Delete the old indices for the current record. */ @@ -404,7 +411,7 @@ void sqliteUpdate( pParse->nTab = iCur; } if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab, - newIdx, oldIdx, onError, addr) ){ + newIdx, oldIdx, onError, loopStart) ){ goto update_cleanup; } } @@ -412,8 +419,8 @@ void sqliteUpdate( /* Repeat the above with the next record to be updated, until ** all record selected by the WHERE clause have been updated. */ - sqliteVdbeAddOp(v, OP_Goto, 0, addr); - sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v)); + sqliteVdbeAddOp(v, OP_Goto, 0, loopStart); + sqliteVdbeChangeP2(v, jumpInst, sqliteVdbeCurrentAddr(v)); sqliteVdbeAddOp(v, OP_ListReset, 0, 0); /* Close all tables if there were no FOR EACH ROW triggers */ @@ -430,14 +437,14 @@ void sqliteUpdate( sqliteVdbeAddOp(v, OP_Close, oldIdx, 0); } + sqliteVdbeAddOp(v, OP_SetCounts, 0, 0); sqliteEndWriteOperation(pParse); /* ** Return the number of rows that were changed. */ if( db->flags & SQLITE_CountRows && !pParse->trigStack ){ - sqliteVdbeAddOp(v, OP_ColumnName, 0, 0); - sqliteVdbeChangeP3(v, -1, "rows updated", P3_STATIC); + sqliteVdbeOp3(v, OP_ColumnName, 0, 1, "rows updated", P3_STATIC); sqliteVdbeAddOp(v, OP_Callback, 1, 0); } diff --git a/ext/sqlite/libsqlite/src/util.c b/ext/sqlite/libsqlite/src/util.c index 2e896ee8b6..21d7b15057 100644 --- a/ext/sqlite/libsqlite/src/util.c +++ b/ext/sqlite/libsqlite/src/util.c @@ -417,120 +417,11 @@ void sqliteSetNString(char **pz, ...){ */ void sqliteErrorMsg(Parse *pParse, const char *zFormat, ...){ va_list ap; - int nByte; - int i, j; - char *z; - static char zNull[] = "NULL"; - pParse->nErr++; - nByte = 1 + strlen(zFormat); - va_start(ap, zFormat); - for(i=0; zFormat[i]; i++){ - if( zFormat[i]!='%' || zFormat[i+1]==0 ) continue; - i++; - switch( zFormat[i] ){ - case 'd': { - (void)va_arg(ap, int); - nByte += 20; - break; - } - case 'z': - case 's': { - char *z2 = va_arg(ap, char*); - if( z2==0 ) z2 = zNull; - nByte += strlen(z2); - break; - } - case 'T': { - Token *p = va_arg(ap, Token*); - nByte += p->n; - break; - } - case 'S': { - SrcList *p = va_arg(ap, SrcList*); - int k = va_arg(ap, int); - assert( p->nSrc>k && k>=0 ); - nByte += strlen(p->a[k].zName); - if( p->a[k].zDatabase && p->a[k].zDatabase[0] ){ - nByte += strlen(p->a[k].zDatabase)+1; - } - break; - } - default: { - nByte++; - break; - } - } - } - va_end(ap); - z = sqliteMalloc( nByte ); - if( z==0 ) return; sqliteFree(pParse->zErrMsg); - pParse->zErrMsg = z; va_start(ap, zFormat); - for(i=j=0; zFormat[i]; i++){ - if( zFormat[i]!='%' || zFormat[i+1]==0 ) continue; - if( i>j ){ - memcpy(z, &zFormat[j], i-j); - z += i-j; - } - j = i+2; - i++; - switch( zFormat[i] ){ - case 'd': { - int x = va_arg(ap, int); - sprintf(z, "%d", x); - z += strlen(z); - break; - } - case 'z': - case 's': { - int len; - char *z2 = va_arg(ap, char*); - if( z2==0 ) z2 = zNull; - len = strlen(z2); - memcpy(z, z2, len); - z += len; - if( zFormat[i]=='z' && z2!=zNull ){ - sqliteFree(z2); - } - break; - } - case 'T': { - Token *p = va_arg(ap, Token*); - memcpy(z, p->z, p->n); - z += p->n; - break; - } - case 'S': { - int len; - SrcList *p = va_arg(ap, SrcList*); - int k = va_arg(ap, int); - assert( p->nSrc>k && k>=0 ); - if( p->a[k].zDatabase && p->a[k].zDatabase[0] ){ - len = strlen(p->a[k].zDatabase); - memcpy(z, p->a[k].zDatabase, len); - z += len; - *(z++) = '.'; - } - len = strlen(p->a[k].zName); - memcpy(z, p->a[k].zName, len); - z += len; - break; - } - default: { - *(z++) = zFormat[i]; - break; - } - } - } + pParse->zErrMsg = sqliteVMPrintf(zFormat, ap); va_end(ap); - if( i>j ){ - memcpy(z, &zFormat[j], i-j); - z += i-j; - } - assert( (z - pParse->zErrMsg) < nByte ); - *z = 0; } /* @@ -662,7 +553,7 @@ int sqliteIsNumber(const char *z){ ** of "." depending on how locale is set. But that would cause problems ** for SQL. So this routine always uses "." regardless of locale. */ -double sqliteAtoF(const char *z){ +double sqliteAtoF(const char *z, const char **pzEnd){ int sign = 1; LONGDOUBLE_TYPE v1 = 0.0; if( *z=='-' ){ @@ -710,6 +601,7 @@ double sqliteAtoF(const char *z){ v1 *= scale; } } + if( pzEnd ) *pzEnd = z; return sign<0 ? -v1 : v1; } @@ -759,8 +651,8 @@ int sqliteCompare(const char *atext, const char *btext){ result = -1; }else{ double rA, rB; - rA = sqliteAtoF(atext); - rB = sqliteAtoF(btext); + rA = sqliteAtoF(atext, 0); + rB = sqliteAtoF(btext, 0); if( rA<rB ){ result = -1; }else if( rA>rB ){ @@ -852,8 +744,8 @@ int sqliteSortCompare(const char *a, const char *b){ res = -1; break; } - rA = sqliteAtoF(&a[1]); - rB = sqliteAtoF(&b[1]); + rA = sqliteAtoF(&a[1], 0); + rB = sqliteAtoF(&b[1], 0); if( rA<rB ){ res = -1; break; diff --git a/ext/sqlite/libsqlite/src/vacuum.c b/ext/sqlite/libsqlite/src/vacuum.c index 9cad4008e6..06cc6b0a4c 100644 --- a/ext/sqlite/libsqlite/src/vacuum.c +++ b/ext/sqlite/libsqlite/src/vacuum.c @@ -108,7 +108,6 @@ static int execsql(char **pzErrMsg, sqlite *db, const char *zSql){ */ static int vacuumCallback2(void *pArg, int argc, char **argv, char **NotUsed){ vacuumStruct *p = (vacuumStruct*)pArg; - int rc = 0; const char *zSep = "("; int i; @@ -127,8 +126,8 @@ static int vacuumCallback2(void *pArg, int argc, char **argv, char **NotUsed){ } } appendText(&p->s2,")", 1); - rc = execsql(p->pzErrMsg, p->dbNew, p->s2.z); - return rc; + p->rc = execsql(p->pzErrMsg, p->dbNew, p->s2.z); + return p->rc; } /* @@ -160,6 +159,7 @@ static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){ sqlite_freemem(zErrMsg); } } + if( rc!=SQLITE_ABORT ) p->rc = rc; return rc; } @@ -170,7 +170,6 @@ static int vacuumCallback1(void *pArg, int argc, char **argv, char **NotUsed){ */ static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){ vacuumStruct *p = (vacuumStruct*)pArg; - int rc = 0; char zBuf[200]; assert( argc==1 ); if( argv==0 ) return 0; @@ -178,21 +177,21 @@ static int vacuumCallback3(void *pArg, int argc, char **argv, char **NotUsed){ assert( strlen(p->zPragma)<100 ); assert( strlen(argv[0])<30 ); sprintf(zBuf,"PRAGMA %s=%s;", p->zPragma, argv[0]); - rc = execsql(p->pzErrMsg, p->dbNew, zBuf); - return rc; + p->rc = execsql(p->pzErrMsg, p->dbNew, zBuf); + return p->rc; } /* ** Generate a random name of 20 character in length. */ -static void randomName(char *zBuf){ - static const char zChars[] = +static void randomName(unsigned char *zBuf){ + static const unsigned char zChars[] = "abcdefghijklmnopqrstuvwxyz" "0123456789"; int i; + sqliteRandomness(20, zBuf); for(i=0; i<20; i++){ - int n = sqliteRandomByte() % (sizeof(zChars)-1); - zBuf[i] = zChars[n]; + zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ]; } } #endif @@ -240,6 +239,9 @@ int sqliteRunVacuum(char **pzErrMsg, sqlite *db){ (char*)0); return SQLITE_ERROR; } + if( db->flags & SQLITE_Interrupt ){ + return SQLITE_INTERRUPT; + } memset(&sVac, 0, sizeof(sVac)); /* Get the full pathname of the database file and create two @@ -257,7 +259,7 @@ int sqliteRunVacuum(char **pzErrMsg, sqlite *db){ strcpy(zTemp, zFilename); for(i=0; i<10; i++){ zTemp[nFilename] = '-'; - randomName(&zTemp[nFilename+1]); + randomName((unsigned char*)&zTemp[nFilename+1]); if( !sqliteOsFileExists(zTemp) ) break; } if( i>=10 ){ @@ -273,8 +275,8 @@ int sqliteRunVacuum(char **pzErrMsg, sqlite *db){ zTemp, " - ", zErrMsg, (char*)0); goto end_of_vacuum; } - if( execsql(pzErrMsg, db, "BEGIN") ) goto end_of_vacuum; - if( execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN") ){ + if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum; + if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){ goto end_of_vacuum; } @@ -309,13 +311,17 @@ end_of_vacuum: zErrMsg, (char*)0); } sqlite_exec(db, "ROLLBACK", 0, 0, 0); + if( (dbNew && (dbNew->flags & SQLITE_Interrupt)) + || (db->flags & SQLITE_Interrupt) ){ + rc = SQLITE_INTERRUPT; + } if( dbNew ) sqlite_close(dbNew); sqliteOsDelete(zTemp); sqliteFree(zTemp); sqliteFree(sVac.s1.z); sqliteFree(sVac.s2.z); if( zErrMsg ) sqlite_freemem(zErrMsg); - if( rc==SQLITE_ABORT ) rc = SQLITE_ERROR; - return rc; + if( rc==SQLITE_ABORT && sVac.rc!=SQLITE_INTERRUPT ) sVac.rc = SQLITE_ERROR; + return sVac.rc; #endif } diff --git a/ext/sqlite/libsqlite/src/vdbe.c b/ext/sqlite/libsqlite/src/vdbe.c index b0dd210049..09332560df 100644 --- a/ext/sqlite/libsqlite/src/vdbe.c +++ b/ext/sqlite/libsqlite/src/vdbe.c @@ -59,6 +59,15 @@ */ int sqlite_search_count = 0; +/* +** When this global variable is positive, it gets decremented once before +** each instruction in the VDBE. When reaches zero, the SQLITE_Interrupt +** of the db.flags field is set in order to simulate an interrupt. +** +** This facility is used for testing purposes only. It does not function +** in an ordinary build. +*/ +int sqlite_interrupt_count = 0; /* ** Advance the virtual machine to the next output row. @@ -110,6 +119,7 @@ int sqlite_step( } db = p->db; if( sqliteSafetyOn(db) ){ + p->rc = SQLITE_MISUSE; return SQLITE_MISUSE; } if( p->explain ){ @@ -146,6 +156,7 @@ int sqlite_step( static int AggInsert(Agg *p, char *zKey, int nKey){ AggElem *pElem, *pOld; int i; + Mem *pMem; pElem = sqliteMalloc( sizeof(AggElem) + nKey + (p->nMem-1)*sizeof(pElem->aMem[0]) ); if( pElem==0 ) return 1; @@ -158,8 +169,8 @@ static int AggInsert(Agg *p, char *zKey, int nKey){ sqliteFree(pOld); return 0; } - for(i=0; i<p->nMem; i++){ - pElem->aMem[i].s.flags = STK_Null; + for(i=0, pMem=pElem->aMem; i<p->nMem; i++, pMem++){ + pMem->flags = MEM_Null; } p->pCurrent = pElem; return 0; @@ -182,20 +193,19 @@ static AggElem *_AggInFocus(Agg *p){ ** Convert the given stack entity into a string if it isn't one ** already. */ -#define Stringify(P,I) if((aStack[I].flags & STK_Str)==0){hardStringify(P,I);} -static int hardStringify(Vdbe *p, int i){ - Stack *pStack = &p->aStack[i]; +#define Stringify(P) if(((P)->flags & MEM_Str)==0){hardStringify(P);} +static int hardStringify(Mem *pStack){ int fg = pStack->flags; - if( fg & STK_Real ){ - sqlite_snprintf(sizeof(pStack->z),pStack->z,"%.15g",pStack->r); - }else if( fg & STK_Int ){ - sqlite_snprintf(sizeof(pStack->z),pStack->z,"%d",pStack->i); + if( fg & MEM_Real ){ + sqlite_snprintf(sizeof(pStack->zShort),pStack->zShort,"%.15g",pStack->r); + }else if( fg & MEM_Int ){ + sqlite_snprintf(sizeof(pStack->zShort),pStack->zShort,"%d",pStack->i); }else{ - pStack->z[0] = 0; + pStack->zShort[0] = 0; } - p->zStack[i] = pStack->z; - pStack->n = strlen(pStack->z)+1; - pStack->flags = STK_Str; + pStack->z = pStack->zShort; + pStack->n = strlen(pStack->zShort)+1; + pStack->flags = MEM_Str | MEM_Short; return 0; } @@ -206,25 +216,24 @@ static int hardStringify(Vdbe *p, int i){ ** will fit but this routine always mallocs for space. ** Return non-zero if we run out of memory. */ -#define Dynamicify(P,I) ((aStack[I].flags & STK_Dyn)==0 ? hardDynamicify(P,I):0) -static int hardDynamicify(Vdbe *p, int i){ - Stack *pStack = &p->aStack[i]; +#define Dynamicify(P) (((P)->flags & MEM_Dyn)==0 ? hardDynamicify(P):0) +static int hardDynamicify(Mem *pStack){ int fg = pStack->flags; char *z; - if( (fg & STK_Str)==0 ){ - hardStringify(p, i); + if( (fg & MEM_Str)==0 ){ + hardStringify(pStack); } - assert( (fg & STK_Dyn)==0 ); + assert( (fg & MEM_Dyn)==0 ); z = sqliteMallocRaw( pStack->n ); if( z==0 ) return 1; - memcpy(z, p->zStack[i], pStack->n); - p->zStack[i] = z; - pStack->flags |= STK_Dyn; + memcpy(z, pStack->z, pStack->n); + pStack->z = z; + pStack->flags |= MEM_Dyn; return 0; } /* -** An ephemeral string value (signified by the STK_Ephem flag) contains +** An ephemeral string value (signified by the MEM_Ephem flag) contains ** a pointer to a dynamically allocated string where some other entity ** is responsible for deallocating that string. Because the stack entry ** does not control the string, it might be deleted without the stack @@ -232,32 +241,39 @@ static int hardDynamicify(Vdbe *p, int i){ ** ** This routine converts an ephemeral string into a dynamically allocated ** string that the stack entry itself controls. In other words, it -** converts an STK_Ephem string into an STK_Dyn string. +** converts an MEM_Ephem string into an MEM_Dyn string. */ -#define Deephemeralize(P,I) \ - if( ((P)->aStack[I].flags&STK_Ephem)!=0 && hardDeephem(P,I) ){ goto no_mem;} -static int hardDeephem(Vdbe *p, int i){ - Stack *pStack = &p->aStack[i]; - char **pzStack = &p->zStack[i]; +#define Deephemeralize(P) \ + if( ((P)->flags&MEM_Ephem)!=0 && hardDeephem(P) ){ goto no_mem;} +static int hardDeephem(Mem *pStack){ char *z; - assert( (pStack->flags & STK_Ephem)!=0 ); + assert( (pStack->flags & MEM_Ephem)!=0 ); z = sqliteMallocRaw( pStack->n ); if( z==0 ) return 1; - memcpy(z, *pzStack, pStack->n); - *pzStack = z; - pStack->flags &= ~STK_Ephem; - pStack->flags |= STK_Dyn; + memcpy(z, pStack->z, pStack->n); + pStack->z = z; + pStack->flags &= ~MEM_Ephem; + pStack->flags |= MEM_Dyn; return 0; } /* -** Release the memory associated with the given stack level +** Release the memory associated with the given stack level. This +** leaves the Mem.flags field in an inconsistent state. */ -#define Release(P,I) if((P)->aStack[I].flags&STK_Dyn){ hardRelease(P,I); } -static void hardRelease(Vdbe *p, int i){ - sqliteFree(p->zStack[i]); - p->zStack[i] = 0; - p->aStack[i].flags &= ~(STK_Str|STK_Dyn|STK_Static|STK_Ephem); +#define Release(P) if((P)->flags&MEM_Dyn){ sqliteFree((P)->z); } + +/* +** Pop the stack N times. +*/ +static void popStack(Mem **ppTos, int N){ + Mem *pTos = *ppTos; + while( N>0 ){ + N--; + Release(pTos); + pTos--; + } + *ppTos = pTos; } /* @@ -296,19 +312,18 @@ static int toInt(const char *zNum, int *pNum){ ** Any prior string or real representation is invalidated. ** NULLs are converted into 0. */ -#define Integerify(P,I) \ - if(((P)->aStack[(I)].flags&STK_Int)==0){ hardIntegerify(P,I); } -static void hardIntegerify(Vdbe *p, int i){ - if( p->aStack[i].flags & STK_Real ){ - p->aStack[i].i = (int)p->aStack[i].r; - Release(p, i); - }else if( p->aStack[i].flags & STK_Str ){ - toInt(p->zStack[i], &p->aStack[i].i); - Release(p, i); +#define Integerify(P) if(((P)->flags&MEM_Int)==0){ hardIntegerify(P); } +static void hardIntegerify(Mem *pStack){ + if( pStack->flags & MEM_Real ){ + pStack->i = (int)pStack->r; + Release(pStack); + }else if( pStack->flags & MEM_Str ){ + toInt(pStack->z, &pStack->i); + Release(pStack); }else{ - p->aStack[i].i = 0; + pStack->i = 0; } - p->aStack[i].flags = STK_Int; + pStack->flags = MEM_Int; } /* @@ -317,17 +332,16 @@ static void hardIntegerify(Vdbe *p, int i){ ** Any prior string or integer representation is retained. ** NULLs are converted into 0.0. */ -#define Realify(P,I) \ - if(((P)->aStack[(I)].flags&STK_Real)==0){ hardRealify(P,I); } -static void hardRealify(Vdbe *p, int i){ - if( p->aStack[i].flags & STK_Str ){ - p->aStack[i].r = sqliteAtoF(p->zStack[i]); - }else if( p->aStack[i].flags & STK_Int ){ - p->aStack[i].r = p->aStack[i].i; +#define Realify(P) if(((P)->flags&MEM_Real)==0){ hardRealify(P); } +static void hardRealify(Mem *pStack){ + if( pStack->flags & MEM_Str ){ + pStack->r = sqliteAtoF(pStack->z, 0); + }else if( pStack->flags & MEM_Int ){ + pStack->r = pStack->i; }else{ - p->aStack[i].r = 0.0; + pStack->r = 0.0; } - p->aStack[i].flags |= STK_Real; + pStack->flags |= MEM_Real; } /* @@ -363,17 +377,6 @@ static Sorter *Merge(Sorter *pLeft, Sorter *pRight){ } /* -** Code contained within the VERIFY() macro is not needed for correct -** execution. It is there only to catch errors. So when we compile -** with NDEBUG=1, the VERIFY() code is omitted. -*/ -#ifdef NDEBUG -# define VERIFY(X) -#else -# define VERIFY(X) X -#endif - -/* ** The following routine works like a replacement for the standard ** library routine fgets(). The difference is in how end-of-line (EOL) ** is handled. Standard fgets() uses LF for EOL under unix, CRLF @@ -486,8 +489,7 @@ int sqliteVdbeExec( Op *pOp; /* Current operation */ int rc = SQLITE_OK; /* Value to return */ sqlite *db = p->db; /* The database */ - char **zStack = p->zStack; /* Text stack */ - Stack *aStack = p->aStack; /* Additional stack information */ + Mem *pTos; /* Top entry in the operand stack */ char zBuf[100]; /* Space to sprintf() an integer */ #ifdef VDBE_PROFILE unsigned long long start; /* CPU clock count at start of opcode */ @@ -503,13 +505,15 @@ int sqliteVdbeExec( p->rc = SQLITE_OK; assert( p->explain==0 ); if( sqlite_malloc_failed ) goto no_mem; + pTos = p->pTos; if( p->popStack ){ - sqliteVdbePopStack(p, p->popStack); + popStack(&pTos, p->popStack); p->popStack = 0; } + CHECK_FOR_INTERRUPT; for(pc=p->pc; rc==SQLITE_OK; pc++){ assert( pc>=0 && pc<p->nOp ); - assert( p->tos<=pc ); + assert( pTos<=&p->aStack[pc] ); #ifdef VDBE_PROFILE origPc = pc; start = hwtime(); @@ -524,6 +528,18 @@ int sqliteVdbeExec( } #endif + /* Check to see if we need to simulate an interrupt. This only happens + ** if we have a special test build. + */ +#ifdef SQLITE_TEST + if( sqlite_interrupt_count>0 ){ + sqlite_interrupt_count--; + if( sqlite_interrupt_count==0 ){ + sqlite_interrupt(db); + } + } +#endif + #ifndef SQLITE_OMIT_PROGRESS_CALLBACK /* Call the progress callback if it is configured and the required number ** of VDBE ops have been executed (either since this invocation of @@ -531,14 +547,16 @@ int sqliteVdbeExec( ** If the progress callback returns non-zero, exit the virtual machine with ** a return code SQLITE_ABORT. */ - if( db->xProgress && (db->nProgressOps==nProgressOps) ){ - if( db->xProgress(db->pProgressArg)!=0 ){ - rc = SQLITE_ABORT; - continue; /* skip to the next iteration of the for loop */ + if( db->xProgress ){ + if( db->nProgressOps==nProgressOps ){ + if( db->xProgress(db->pProgressArg)!=0 ){ + rc = SQLITE_ABORT; + continue; /* skip to the next iteration of the for loop */ + } + nProgressOps = 0; } - nProgressOps = 0; + nProgressOps++; } - nProgressOps++; #endif switch( pOp->opcode ){ @@ -641,6 +659,7 @@ case OP_Return: { */ case OP_Halt: { p->magic = VDBE_MAGIC_HALT; + p->pTos = pTos; if( pOp->p1!=SQLITE_OK ){ p->rc = pOp->p1; p->errorAction = pOp->p2; @@ -660,13 +679,13 @@ case OP_Halt: { ** then it is assumed to be a string representation of the same integer. */ case OP_Integer: { - int i = ++p->tos; - aStack[i].i = pOp->p1; - aStack[i].flags = STK_Int; + pTos++; + pTos->i = pOp->p1; + pTos->flags = MEM_Int; if( pOp->p3 ){ - zStack[i] = pOp->p3; - aStack[i].flags |= STK_Str | STK_Static; - aStack[i].n = strlen(pOp->p3)+1; + pTos->z = pOp->p3; + pTos->flags |= MEM_Str | MEM_Static; + pTos->n = strlen(pOp->p3)+1; } break; } @@ -677,17 +696,14 @@ case OP_Integer: { ** NULL is pushed onto the stack. */ case OP_String: { - int i = ++p->tos; - char *z; - z = pOp->p3; + char *z = pOp->p3; + pTos++; if( z==0 ){ - zStack[i] = 0; - aStack[i].n = 0; - aStack[i].flags = STK_Null; + pTos->flags = MEM_Null; }else{ - zStack[i] = z; - aStack[i].n = strlen(z) + 1; - aStack[i].flags = STK_Str | STK_Static; + pTos->z = z; + pTos->n = strlen(z) + 1; + pTos->flags = MEM_Str | MEM_Static; } break; } @@ -702,16 +718,14 @@ case OP_String: { ** sqlite_bind() API. */ case OP_Variable: { - int i = ++p->tos; int j = pOp->p1 - 1; + pTos++; if( j>=0 && j<p->nVar && p->azVar[j]!=0 ){ - zStack[i] = p->azVar[j]; - aStack[i].n = p->anVar[j]; - aStack[i].flags = STK_Str | STK_Static; + pTos->z = p->azVar[j]; + pTos->n = p->anVar[j]; + pTos->flags = MEM_Str | MEM_Static; }else{ - zStack[i] = 0; - aStack[i].n = 0; - aStack[i].flags = STK_Null; + pTos->flags = MEM_Null; } break; } @@ -721,8 +735,9 @@ case OP_Variable: { ** P1 elements are popped off of the top of stack and discarded. */ case OP_Pop: { - assert( p->tos+1>=pOp->p1 ); - sqliteVdbePopStack(p, pOp->p1); + assert( pOp->p1>=0 ); + popStack(&pTos, pOp->p1); + assert( pTos>=&p->aStack[-1] ); break; } @@ -742,26 +757,23 @@ case OP_Pop: { ** Also see the Pull instruction. */ case OP_Dup: { - int i = p->tos - pOp->p1; - int j = ++p->tos; - VERIFY( if( i<0 ) goto not_enough_stack; ) - memcpy(&aStack[j], &aStack[i], sizeof(aStack[i])-NBFS); - if( aStack[j].flags & STK_Str ){ - int isStatic = (aStack[j].flags & STK_Static)!=0; - if( pOp->p2 || isStatic ){ - zStack[j] = zStack[i]; - aStack[j].flags &= ~STK_Dyn; - if( !isStatic ) aStack[j].flags |= STK_Ephem; - }else if( aStack[i].n<=NBFS ){ - memcpy(aStack[j].z, zStack[i], aStack[j].n); - zStack[j] = aStack[j].z; - aStack[j].flags &= ~(STK_Static|STK_Dyn|STK_Ephem); - }else{ - zStack[j] = sqliteMallocRaw( aStack[j].n ); - if( zStack[j]==0 ) goto no_mem; - memcpy(zStack[j], zStack[i], aStack[j].n); - aStack[j].flags &= ~(STK_Static|STK_Ephem); - aStack[j].flags |= STK_Dyn; + Mem *pFrom = &pTos[-pOp->p1]; + assert( pFrom<=pTos && pFrom>=p->aStack ); + pTos++; + memcpy(pTos, pFrom, sizeof(*pFrom)-NBFS); + if( pTos->flags & MEM_Str ){ + if( pOp->p2 && (pTos->flags & (MEM_Dyn|MEM_Ephem)) ){ + pTos->flags &= ~MEM_Dyn; + pTos->flags |= MEM_Ephem; + }else if( pTos->flags & MEM_Short ){ + memcpy(pTos->zShort, pFrom->zShort, pTos->n); + pTos->z = pTos->zShort; + }else if( (pTos->flags & MEM_Static)==0 ){ + pTos->z = sqliteMallocRaw(pFrom->n); + if( sqlite_malloc_failed ) goto no_mem; + memcpy(pTos->z, pFrom->z, pFrom->n); + pTos->flags &= ~(MEM_Static|MEM_Ephem|MEM_Short); + pTos->flags |= MEM_Dyn; } } break; @@ -778,32 +790,27 @@ case OP_Dup: { ** See also the Dup instruction. */ case OP_Pull: { - int from = p->tos - pOp->p1; - int to = p->tos; + Mem *pFrom = &pTos[-pOp->p1]; int i; - Stack ts; - char *tz; - VERIFY( if( from<0 ) goto not_enough_stack; ) - Deephemeralize(p, from); - ts = aStack[from]; - tz = zStack[from]; - Deephemeralize(p, to); - for(i=from; i<to; i++){ - Deephemeralize(p, i+1); - aStack[i] = aStack[i+1]; - assert( (aStack[i].flags & STK_Ephem)==0 ); - if( aStack[i].flags & (STK_Dyn|STK_Static) ){ - zStack[i] = zStack[i+1]; - }else{ - zStack[i] = aStack[i].z; + Mem ts; + + ts = *pFrom; + Deephemeralize(pTos); + for(i=0; i<pOp->p1; i++, pFrom++){ + Deephemeralize(&pFrom[1]); + *pFrom = pFrom[1]; + assert( (pFrom->flags & MEM_Ephem)==0 ); + if( pFrom->flags & MEM_Short ){ + assert( pFrom->flags & MEM_Str ); + assert( pFrom->z==pFrom[1].zShort ); + pFrom->z = pFrom->zShort; } } - aStack[to] = ts; - assert( (aStack[to].flags & STK_Ephem)==0 ); - if( aStack[to].flags & (STK_Dyn|STK_Static) ){ - zStack[to] = tz; - }else{ - zStack[to] = aStack[to].z; + *pTos = ts; + if( pTos->flags & MEM_Short ){ + assert( pTos->flags & MEM_Str ); + assert( pTos->z==pTos[-pOp->p1].zShort ); + pTos->z = pTos->zShort; } break; } @@ -815,34 +822,36 @@ case OP_Pull: { ** of the top of the stack. Then pop the top of the stack. */ case OP_Push: { - int from = p->tos; - int to = p->tos - pOp->p1; + Mem *pTo = &pTos[-pOp->p1]; - VERIFY( if( to<0 ) goto not_enough_stack; ) - if( aStack[to].flags & STK_Dyn ){ - sqliteFree(zStack[to]); + assert( pTo>=p->aStack ); + Deephemeralize(pTos); + Release(pTo); + *pTo = *pTos; + if( pTo->flags & MEM_Short ){ + assert( pTo->z==pTos->zShort ); + pTo->z = pTo->zShort; } - Deephemeralize(p, from); - aStack[to] = aStack[from]; - if( aStack[to].flags & (STK_Dyn|STK_Static|STK_Ephem) ){ - zStack[to] = zStack[from]; - }else{ - zStack[to] = aStack[to].z; - } - aStack[from].flags = 0; - p->tos--; + pTos--; break; } -/* Opcode: ColumnName P1 * P3 + +/* Opcode: ColumnName P1 P2 P3 ** ** P3 becomes the P1-th column name (first is 0). An array of pointers ** to all column names is passed as the 4th parameter to the callback. +** If P2==1 then this is the last column in the result set and thus the +** number of columns in the result set will be P1. There must be at least +** one OP_ColumnName with a P2==1 before invoking OP_Callback and the +** number of columns specified in OP_Callback must one more than the P1 +** value of the OP_ColumnName that has P2==1. */ case OP_ColumnName: { assert( pOp->p1>=0 && pOp->p1<p->nOp ); p->azColName[pOp->p1] = pOp->p3; p->nCallback = 0; + if( pOp->p2 ) p->nResColumn = pOp->p1+1; break; } @@ -853,63 +862,28 @@ case OP_ColumnName: { ** 3rd parameter. */ case OP_Callback: { - int i = p->tos - pOp->p1 + 1; - int j; - VERIFY( if( i<0 ) goto not_enough_stack; ) - for(j=i; j<=p->tos; j++){ - if( aStack[j].flags & STK_Null ){ - zStack[j] = 0; + int i; + char **azArgv = p->zArgv; + Mem *pCol; + + pCol = &pTos[1-pOp->p1]; + assert( pCol>=p->aStack ); + for(i=0; i<pOp->p1; i++, pCol++){ + if( pCol->flags & MEM_Null ){ + azArgv[i] = 0; }else{ - Stringify(p, j); + Stringify(pCol); + azArgv[i] = pCol->z; } } - zStack[p->tos+1] = 0; - if( p->xCallback==0 ){ - p->azResColumn = &zStack[i]; - p->nResColumn = pOp->p1; - p->popStack = pOp->p1; - p->pc = pc + 1; - return SQLITE_ROW; - } - if( sqliteSafetyOff(db) ) goto abort_due_to_misuse; - if( p->xCallback(p->pCbArg, pOp->p1, &zStack[i], p->azColName)!=0 ){ - rc = SQLITE_ABORT; - } - if( sqliteSafetyOn(db) ) goto abort_due_to_misuse; + azArgv[i] = 0; p->nCallback++; - sqliteVdbePopStack(p, pOp->p1); - if( sqlite_malloc_failed ) goto no_mem; - break; -} - -/* Opcode: NullCallback P1 * * -** -** Invoke the callback function once with the 2nd argument (the -** number of columns) equal to P1 and with the 4th argument (the -** names of the columns) set according to prior OP_ColumnName -** instructions. This is all like the regular -** OP_Callback or OP_SortCallback opcodes. But the 3rd argument -** which normally contains a pointer to an array of pointers to -** data is NULL. -** -** The callback is only invoked if there have been no prior calls -** to OP_Callback or OP_SortCallback. -** -** This opcode is used to report the number and names of columns -** in cases where the result set is empty. -*/ -case OP_NullCallback: { - if( p->nCallback==0 && p->xCallback!=0 ){ - if( sqliteSafetyOff(db) ) goto abort_due_to_misuse; - if( p->xCallback(p->pCbArg, pOp->p1, 0, p->azColName)!=0 ){ - rc = SQLITE_ABORT; - } - if( sqliteSafetyOn(db) ) goto abort_due_to_misuse; - p->nCallback++; - if( sqlite_malloc_failed ) goto no_mem; - } - p->nResColumn = pOp->p1; - break; + p->azResColumn = azArgv; + assert( p->nResColumn==pOp->p1 ); + p->popStack = pOp->p1; + p->pc = pc + 1; + p->pTos = pTos; + return SQLITE_ROW; } /* Opcode: Concat P1 P2 P3 @@ -931,48 +905,53 @@ case OP_Concat: { int i, j; char *zSep; int nSep; + Mem *pTerm; nField = pOp->p1; zSep = pOp->p3; if( zSep==0 ) zSep = ""; nSep = strlen(zSep); - VERIFY( if( p->tos+1<nField ) goto not_enough_stack; ) + assert( &pTos[1-nField] >= p->aStack ); nByte = 1 - nSep; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( aStack[i].flags & STK_Null ){ + pTerm = &pTos[1-nField]; + for(i=0; i<nField; i++, pTerm++){ + if( pTerm->flags & MEM_Null ){ nByte = -1; break; }else{ - Stringify(p, i); - nByte += aStack[i].n - 1 + nSep; + Stringify(pTerm); + nByte += pTerm->n - 1 + nSep; } } if( nByte<0 ){ - if( pOp->p2==0 ) sqliteVdbePopStack(p, nField); - p->tos++; - aStack[p->tos].flags = STK_Null; - zStack[p->tos] = 0; + if( pOp->p2==0 ){ + popStack(&pTos, nField); + } + pTos++; + pTos->flags = MEM_Null; break; } zNew = sqliteMallocRaw( nByte ); if( zNew==0 ) goto no_mem; j = 0; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( (aStack[i].flags & STK_Null)==0 ){ - memcpy(&zNew[j], zStack[i], aStack[i].n-1); - j += aStack[i].n-1; - } - if( nSep>0 && i<p->tos ){ + pTerm = &pTos[1-nField]; + for(i=j=0; i<nField; i++, pTerm++){ + assert( pTerm->flags & MEM_Str ); + memcpy(&zNew[j], pTerm->z, pTerm->n-1); + j += pTerm->n-1; + if( nSep>0 && i<nField-1 ){ memcpy(&zNew[j], zSep, nSep); j += nSep; } } zNew[j] = 0; - if( pOp->p2==0 ) sqliteVdbePopStack(p, nField); - p->tos++; - aStack[p->tos].n = nByte; - aStack[p->tos].flags = STK_Str|STK_Dyn; - zStack[p->tos] = zNew; + if( pOp->p2==0 ){ + popStack(&pTos, nField); + } + pTos++; + pTos->n = nByte; + pTos->flags = MEM_Str|MEM_Dyn; + pTos->z = zNew; break; } @@ -1027,17 +1006,17 @@ case OP_Subtract: case OP_Multiply: case OP_Divide: case OP_Remainder: { - int tos = p->tos; - int nos = tos - 1; - VERIFY( if( nos<0 ) goto not_enough_stack; ) - if( ((aStack[tos].flags | aStack[nos].flags) & STK_Null)!=0 ){ - POPSTACK; - Release(p, nos); - aStack[nos].flags = STK_Null; - }else if( (aStack[tos].flags & aStack[nos].flags & STK_Int)==STK_Int ){ + Mem *pNos = &pTos[-1]; + assert( pNos>=p->aStack ); + if( ((pTos->flags | pNos->flags) & MEM_Null)!=0 ){ + Release(pTos); + pTos--; + Release(pTos); + pTos->flags = MEM_Null; + }else if( (pTos->flags & pNos->flags & MEM_Int)==MEM_Int ){ int a, b; - a = aStack[tos].i; - b = aStack[nos].i; + a = pTos->i; + b = pNos->i; switch( pOp->opcode ){ case OP_Add: b += a; break; case OP_Subtract: b -= a; break; @@ -1053,16 +1032,17 @@ case OP_Remainder: { break; } } - POPSTACK; - Release(p, nos); - aStack[nos].i = b; - aStack[nos].flags = STK_Int; + Release(pTos); + pTos--; + Release(pTos); + pTos->i = b; + pTos->flags = MEM_Int; }else{ double a, b; - Realify(p, tos); - Realify(p, nos); - a = aStack[tos].r; - b = aStack[nos].r; + Realify(pTos); + Realify(pNos); + a = pTos->r; + b = pNos->r; switch( pOp->opcode ){ case OP_Add: b += a; break; case OP_Subtract: b -= a; break; @@ -1080,17 +1060,19 @@ case OP_Remainder: { break; } } - POPSTACK; - Release(p, nos); - aStack[nos].r = b; - aStack[nos].flags = STK_Real; + Release(pTos); + pTos--; + Release(pTos); + pTos->r = b; + pTos->flags = MEM_Real; } break; divide_by_zero: - sqliteVdbePopStack(p, 2); - p->tos = nos; - aStack[nos].flags = STK_Null; + Release(pTos); + pTos--; + Release(pTos); + pTos->flags = MEM_Null; break; } @@ -1104,39 +1086,38 @@ divide_by_zero: */ case OP_Function: { int n, i; + Mem *pArg; + char **azArgv; sqlite_func ctx; n = pOp->p1; - VERIFY( if( n<0 ) goto bad_instruction; ) - VERIFY( if( p->tos+1<n ) goto not_enough_stack; ) - for(i=p->tos-n+1; i<=p->tos; i++){ - if( aStack[i].flags & STK_Null ){ - zStack[i] = 0; + pArg = &pTos[1-n]; + azArgv = p->zArgv; + for(i=0; i<n; i++, pArg++){ + if( pArg->flags & MEM_Null ){ + azArgv[i] = 0; }else{ - Stringify(p, i); + Stringify(pArg); + azArgv[i] = pArg->z; } } ctx.pFunc = (FuncDef*)pOp->p3; - ctx.s.flags = STK_Null; - ctx.z = 0; + ctx.s.flags = MEM_Null; + ctx.s.z = 0; ctx.isError = 0; ctx.isStep = 0; if( sqliteSafetyOff(db) ) goto abort_due_to_misuse; - (*ctx.pFunc->xFunc)(&ctx, n, (const char**)&zStack[p->tos-n+1]); + (*ctx.pFunc->xFunc)(&ctx, n, (const char**)azArgv); if( sqliteSafetyOn(db) ) goto abort_due_to_misuse; - sqliteVdbePopStack(p, n); - p->tos++; - aStack[p->tos] = ctx.s; - if( ctx.s.flags & STK_Dyn ){ - zStack[p->tos] = ctx.z; - }else if( ctx.s.flags & STK_Str ){ - zStack[p->tos] = aStack[p->tos].z; - }else{ - zStack[p->tos] = 0; + popStack(&pTos, n); + pTos++; + *pTos = ctx.s; + if( pTos->flags & MEM_Short ){ + pTos->z = pTos->zShort; } if( ctx.isError ){ sqliteSetString(&p->zErrMsg, - zStack[p->tos] ? zStack[p->tos] : "user function error", (char*)0); + (pTos->flags & MEM_Str)!=0 ? pTos->z : "user function error", (char*)0); rc = SQLITE_ERROR; } break; @@ -1174,20 +1155,20 @@ case OP_BitAnd: case OP_BitOr: case OP_ShiftLeft: case OP_ShiftRight: { - int tos = p->tos; - int nos = tos - 1; + Mem *pNos = &pTos[-1]; int a, b; - VERIFY( if( nos<0 ) goto not_enough_stack; ) - if( (aStack[tos].flags | aStack[nos].flags) & STK_Null ){ - POPSTACK; - Release(p,nos); - aStack[nos].flags = STK_Null; + + assert( pNos>=p->aStack ); + if( (pTos->flags | pNos->flags) & MEM_Null ){ + popStack(&pTos, 2); + pTos++; + pTos->flags = MEM_Null; break; } - Integerify(p, tos); - Integerify(p, nos); - a = aStack[tos].i; - b = aStack[nos].i; + Integerify(pTos); + Integerify(pNos); + a = pTos->i; + b = pNos->i; switch( pOp->opcode ){ case OP_BitAnd: a &= b; break; case OP_BitOr: a |= b; break; @@ -1195,10 +1176,12 @@ case OP_ShiftRight: { case OP_ShiftRight: a >>= b; break; default: /* CANT HAPPEN */ break; } - POPSTACK; - Release(p, nos); - aStack[nos].i = a; - aStack[nos].flags = STK_Int; + assert( (pTos->flags & MEM_Dyn)==0 ); + assert( (pNos->flags & MEM_Dyn)==0 ); + pTos--; + Release(pTos); + pTos->i = a; + pTos->flags = MEM_Int; break; } @@ -1210,34 +1193,43 @@ case OP_ShiftRight: { ** To force the top of the stack to be an integer, just add 0. */ case OP_AddImm: { - int tos = p->tos; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - Integerify(p, tos); - aStack[tos].i += pOp->p1; + assert( pTos>=p->aStack ); + Integerify(pTos); + pTos->i += pOp->p1; break; } -/* Opcode: IsNumeric P1 P2 * -** -** Check the top of the stack to see if it is a numeric value. A numeric -** value is an integer, a real number, or a string that looks like an -** integer or a real number. When P1==0, pop the stack and jump to P2 -** if the value is numeric. Otherwise fall through and leave the stack -** unchanged. The sense of the test is inverted when P1==1. -*/ -case OP_IsNumeric: { - int tos = p->tos; - int r; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - r = (aStack[tos].flags & (STK_Int|STK_Real))!=0 - || (zStack[tos] && sqliteIsNumber(zStack[tos])); - if( pOp->p1 ){ - r = !r; - } - if( r ){ - POPSTACK; +/* Opcode: ForceInt P1 P2 * +** +** Convert the top of the stack into an integer. If the current top of +** the stack is not numeric (meaning that is is a NULL or a string that +** does not look like an integer or floating point number) then pop the +** stack and jump to P2. If the top of the stack is numeric then +** convert it into the least integer that is greater than or equal to its +** current value if P1==0, or to the least integer that is strictly +** greater than its current value if P1==1. +*/ +case OP_ForceInt: { + int v; + assert( pTos>=p->aStack ); + if( (pTos->flags & (MEM_Int|MEM_Real))==0 + && ((pTos->flags & MEM_Str)==0 || sqliteIsNumber(pTos->z)==0) ){ + Release(pTos); + pTos--; pc = pOp->p2 - 1; + break; } + if( pTos->flags & MEM_Int ){ + v = pTos->i + (pOp->p1!=0); + }else{ + Realify(pTos); + v = (int)pTos->r; + if( pTos->r>(double)v ) v++; + if( pOp->p1 && pTos->r==(double)v ) v++; + } + Release(pTos); + pTos->i = v; + pTos->flags = MEM_Int; break; } @@ -1253,38 +1245,36 @@ case OP_IsNumeric: { ** of the stack is unchanged. */ case OP_MustBeInt: { - int tos = p->tos; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - if( aStack[tos].flags & STK_Int ){ + assert( pTos>=p->aStack ); + if( pTos->flags & MEM_Int ){ /* Do nothing */ - }else if( aStack[tos].flags & STK_Real ){ - int i = aStack[tos].r; + }else if( pTos->flags & MEM_Real ){ + int i = (int)pTos->r; double r = (double)i; - if( r!=aStack[tos].r ){ + if( r!=pTos->r ){ goto mismatch; } - aStack[tos].i = i; - }else if( aStack[tos].flags & STK_Str ){ + pTos->i = i; + }else if( pTos->flags & MEM_Str ){ int v; - if( !toInt(zStack[tos], &v) ){ + if( !toInt(pTos->z, &v) ){ double r; - if( !sqliteIsNumber(zStack[tos]) ){ + if( !sqliteIsNumber(pTos->z) ){ goto mismatch; } - Realify(p, tos); - assert( (aStack[tos].flags & STK_Real)!=0 ); - v = aStack[tos].r; + Realify(pTos); + v = (int)pTos->r; r = (double)v; - if( r!=aStack[tos].r ){ + if( r!=pTos->r ){ goto mismatch; } } - aStack[tos].i = v; + pTos->i = v; }else{ goto mismatch; } - Release(p, tos); - aStack[tos].flags = STK_Int; + Release(pTos); + pTos->flags = MEM_Int; break; mismatch: @@ -1292,7 +1282,7 @@ mismatch: rc = SQLITE_MISMATCH; goto abort_due_to_error; }else{ - if( pOp->p1 ) POPSTACK; + if( pOp->p1 ) popStack(&pTos, 1); pc = pOp->p2 - 1; } break; @@ -1415,39 +1405,31 @@ case OP_Lt: case OP_Le: case OP_Gt: case OP_Ge: { - int tos = p->tos; - int nos = tos - 1; + Mem *pNos = &pTos[-1]; int c, v; int ft, fn; - VERIFY( if( nos<0 ) goto not_enough_stack; ) - ft = aStack[tos].flags; - fn = aStack[nos].flags; - if( (ft | fn) & STK_Null ){ - POPSTACK; - POPSTACK; + assert( pNos>=p->aStack ); + ft = pTos->flags; + fn = pNos->flags; + if( (ft | fn) & MEM_Null ){ + popStack(&pTos, 2); if( pOp->p2 ){ if( pOp->p1 ) pc = pOp->p2-1; }else{ - p->tos++; - aStack[nos].flags = STK_Null; + pTos++; + pTos->flags = MEM_Null; } break; - }else if( (ft & fn & STK_Int)==STK_Int ){ - c = aStack[nos].i - aStack[tos].i; - }else if( (ft & STK_Int)!=0 && (fn & STK_Str)!=0 && toInt(zStack[nos],&v) ){ - Release(p, nos); - aStack[nos].i = v; - aStack[nos].flags = STK_Int; - c = aStack[nos].i - aStack[tos].i; - }else if( (fn & STK_Int)!=0 && (ft & STK_Str)!=0 && toInt(zStack[tos],&v) ){ - Release(p, tos); - aStack[tos].i = v; - aStack[tos].flags = STK_Int; - c = aStack[nos].i - aStack[tos].i; + }else if( (ft & fn & MEM_Int)==MEM_Int ){ + c = pNos->i - pTos->i; + }else if( (ft & MEM_Int)!=0 && (fn & MEM_Str)!=0 && toInt(pNos->z,&v) ){ + c = v - pTos->i; + }else if( (fn & MEM_Int)!=0 && (ft & MEM_Str)!=0 && toInt(pTos->z,&v) ){ + c = pNos->i - v; }else{ - Stringify(p, tos); - Stringify(p, nos); - c = sqliteCompare(zStack[nos], zStack[tos]); + Stringify(pTos); + Stringify(pNos); + c = sqliteCompare(pNos->z, pTos->z); } switch( pOp->opcode ){ case OP_Eq: c = c==0; break; @@ -1457,14 +1439,13 @@ case OP_Ge: { case OP_Gt: c = c>0; break; default: c = c>=0; break; } - POPSTACK; - POPSTACK; + popStack(&pTos, 2); if( pOp->p2 ){ if( c ) pc = pOp->p2-1; }else{ - p->tos++; - aStack[nos].flags = STK_Int; - aStack[nos].i = c; + pTos++; + pTos->i = c; + pTos->flags = MEM_Int; } break; } @@ -1581,24 +1562,22 @@ case OP_StrLt: case OP_StrLe: case OP_StrGt: case OP_StrGe: { - int tos = p->tos; - int nos = tos - 1; + Mem *pNos = &pTos[-1]; int c; - VERIFY( if( nos<0 ) goto not_enough_stack; ) - if( (aStack[nos].flags | aStack[tos].flags) & STK_Null ){ - POPSTACK; - POPSTACK; + assert( pNos>=p->aStack ); + if( (pNos->flags | pTos->flags) & MEM_Null ){ + popStack(&pTos, 2); if( pOp->p2 ){ if( pOp->p1 ) pc = pOp->p2-1; }else{ - p->tos++; - aStack[nos].flags = STK_Null; + pTos++; + pTos->flags = MEM_Null; } break; }else{ - Stringify(p, tos); - Stringify(p, nos); - c = strcmp(zStack[nos], zStack[tos]); + Stringify(pTos); + Stringify(pNos); + c = strcmp(pNos->z, pTos->z); } /* The asserts on each case of the following switch are there to verify ** that string comparison opcodes are always exactly 6 greater than the @@ -1613,14 +1592,13 @@ case OP_StrGe: { case OP_StrGt: c = c>0; assert( pOp->opcode-6==OP_Gt ); break; default: c = c>=0; assert( pOp->opcode-6==OP_Ge ); break; } - POPSTACK; - POPSTACK; + popStack(&pTos, 2); if( pOp->p2 ){ if( c ) pc = pOp->p2-1; }else{ - p->tos++; - aStack[nos].flags = STK_Int; - aStack[nos].i = c; + pTos++; + pTos->flags = MEM_Int; + pTos->i = c; } break; } @@ -1639,22 +1617,21 @@ case OP_StrGe: { */ case OP_And: case OP_Or: { - int tos = p->tos; - int nos = tos - 1; + Mem *pNos = &pTos[-1]; int v1, v2; /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */ - VERIFY( if( nos<0 ) goto not_enough_stack; ) - if( aStack[tos].flags & STK_Null ){ + assert( pNos>=p->aStack ); + if( pTos->flags & MEM_Null ){ v1 = 2; }else{ - Integerify(p, tos); - v1 = aStack[tos].i==0; + Integerify(pTos); + v1 = pTos->i==0; } - if( aStack[nos].flags & STK_Null ){ + if( pNos->flags & MEM_Null ){ v2 = 2; }else{ - Integerify(p, nos); - v2 = aStack[nos].i==0; + Integerify(pNos); + v2 = pNos->i==0; } if( pOp->opcode==OP_And ){ static const unsigned char and_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 }; @@ -1663,13 +1640,13 @@ case OP_Or: { static const unsigned char or_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; v1 = or_logic[v1*3+v2]; } - POPSTACK; - Release(p, nos); + popStack(&pTos, 2); + pTos++; if( v1==2 ){ - aStack[nos].flags = STK_Null; + pTos->flags = MEM_Null; }else{ - aStack[nos].i = v1==0; - aStack[nos].flags = STK_Int; + pTos->i = v1==0; + pTos->flags = MEM_Int; } break; } @@ -1688,29 +1665,28 @@ case OP_Or: { */ case OP_Negative: case OP_AbsValue: { - int tos = p->tos; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - if( aStack[tos].flags & STK_Real ){ - Release(p, tos); - if( pOp->opcode==OP_Negative || aStack[tos].r<0.0 ){ - aStack[tos].r = -aStack[tos].r; + assert( pTos>=p->aStack ); + if( pTos->flags & MEM_Real ){ + Release(pTos); + if( pOp->opcode==OP_Negative || pTos->r<0.0 ){ + pTos->r = -pTos->r; } - aStack[tos].flags = STK_Real; - }else if( aStack[tos].flags & STK_Int ){ - Release(p, tos); - if( pOp->opcode==OP_Negative || aStack[tos].i<0 ){ - aStack[tos].i = -aStack[tos].i; + pTos->flags = MEM_Real; + }else if( pTos->flags & MEM_Int ){ + Release(pTos); + if( pOp->opcode==OP_Negative || pTos->i<0 ){ + pTos->i = -pTos->i; } - aStack[tos].flags = STK_Int; - }else if( aStack[tos].flags & STK_Null ){ + pTos->flags = MEM_Int; + }else if( pTos->flags & MEM_Null ){ /* Do nothing */ }else{ - Realify(p, tos); - Release(p, tos); - if( pOp->opcode==OP_Negative || aStack[tos].r<0.0 ){ - aStack[tos].r = -aStack[tos].r; + Realify(pTos); + Release(pTos); + if( pOp->opcode==OP_Negative || pTos->r<0.0 ){ + pTos->r = -pTos->r; } - aStack[tos].flags = STK_Real; + pTos->flags = MEM_Real; } break; } @@ -1722,13 +1698,12 @@ case OP_AbsValue: { ** is unchanged. */ case OP_Not: { - int tos = p->tos; - VERIFY( if( p->tos<0 ) goto not_enough_stack; ) - if( aStack[tos].flags & STK_Null ) break; /* Do nothing to NULLs */ - Integerify(p, tos); - Release(p, tos); - aStack[tos].i = !aStack[tos].i; - aStack[tos].flags = STK_Int; + assert( pTos>=p->aStack ); + if( pTos->flags & MEM_Null ) break; /* Do nothing to NULLs */ + Integerify(pTos); + Release(pTos); + pTos->i = !pTos->i; + pTos->flags = MEM_Int; break; } @@ -1739,13 +1714,12 @@ case OP_Not: { ** value is unchanged. */ case OP_BitNot: { - int tos = p->tos; - VERIFY( if( p->tos<0 ) goto not_enough_stack; ) - if( aStack[tos].flags & STK_Null ) break; /* Do nothing to NULLs */ - Integerify(p, tos); - Release(p, tos); - aStack[tos].i = ~aStack[tos].i; - aStack[tos].flags = STK_Int; + assert( pTos>=p->aStack ); + if( pTos->flags & MEM_Null ) break; /* Do nothing to NULLs */ + Integerify(pTos); + Release(pTos); + pTos->i = ~pTos->i; + pTos->flags = MEM_Int; break; } @@ -1781,15 +1755,16 @@ case OP_Noop: { case OP_If: case OP_IfNot: { int c; - VERIFY( if( p->tos<0 ) goto not_enough_stack; ) - if( aStack[p->tos].flags & STK_Null ){ + assert( pTos>=p->aStack ); + if( pTos->flags & MEM_Null ){ c = pOp->p1; }else{ - Integerify(p, p->tos); - c = aStack[p->tos].i; + Integerify(pTos); + c = pTos->i; if( pOp->opcode==OP_IfNot ) c = !c; } - POPSTACK; + assert( (pTos->flags & MEM_Dyn)==0 ); + pTos--; if( c ) pc = pOp->p2-1; break; } @@ -1802,16 +1777,18 @@ case OP_IfNot: { */ case OP_IsNull: { int i, cnt; + Mem *pTerm; cnt = pOp->p1; if( cnt<0 ) cnt = -cnt; - VERIFY( if( p->tos+1-cnt<0 ) goto not_enough_stack; ) - for(i=0; i<cnt; i++){ - if( aStack[p->tos-i].flags & STK_Null ){ + pTerm = &pTos[1-cnt]; + assert( pTerm>=p->aStack ); + for(i=0; i<cnt; i++, pTerm++){ + if( pTerm->flags & MEM_Null ){ pc = pOp->p2-1; break; } } - if( pOp->p1>0 ) sqliteVdbePopStack(p, cnt); + if( pOp->p1>0 ) popStack(&pTos, cnt); break; } @@ -1825,10 +1802,10 @@ case OP_NotNull: { int i, cnt; cnt = pOp->p1; if( cnt<0 ) cnt = -cnt; - VERIFY( if( p->tos+1-cnt<0 ) goto not_enough_stack; ) - for(i=0; i<cnt && (aStack[p->tos-i].flags & STK_Null)==0; i++){} + assert( &pTos[1-cnt] >= p->aStack ); + for(i=0; i<cnt && (pTos[1+i-cnt].flags & MEM_Null)==0; i++){} if( i>=cnt ) pc = pOp->p2-1; - if( pOp->p1>0 ) sqliteVdbePopStack(p, cnt); + if( pOp->p1>0 ) popStack(&pTos, cnt); break; } @@ -1860,6 +1837,7 @@ case OP_MakeRecord: { int i, j; int idxWidth; u32 addr; + Mem *pRec; int addUnique = 0; /* True to cause bytes to be added to make the ** generated record distinct */ char zTemp[NBFS]; /* Temp space for small records */ @@ -1883,14 +1861,15 @@ case OP_MakeRecord: { ** Idx(N) contains the total number of bytes in the record. */ nField = pOp->p1; - VERIFY( if( p->tos+1<nField ) goto not_enough_stack; ) + pRec = &pTos[1-nField]; + assert( pRec>=p->aStack ); nByte = 0; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( (aStack[i].flags & STK_Null) ){ + for(i=0; i<nField; i++, pRec++){ + if( pRec->flags & MEM_Null ){ addUnique = pOp->p2; }else{ - Stringify(p, i); - nByte += aStack[i].n; + Stringify(pRec); + nByte += pRec->n; } } if( addUnique ) nByte += sizeof(p->uniqueCnt); @@ -1914,7 +1893,7 @@ case OP_MakeRecord: { } j = 0; addr = idxWidth*(nField+1) + addUnique*sizeof(p->uniqueCnt); - for(i=p->tos-nField+1; i<=p->tos; i++){ + for(i=0, pRec=&pTos[1-nField]; i<nField; i++, pRec++){ zNewRecord[j++] = addr & 0xff; if( idxWidth>1 ){ zNewRecord[j++] = (addr>>8)&0xff; @@ -1922,8 +1901,8 @@ case OP_MakeRecord: { zNewRecord[j++] = (addr>>16)&0xff; } } - if( (aStack[i].flags & STK_Null)==0 ){ - addr += aStack[i].n; + if( (pRec->flags & MEM_Null)==0 ){ + addr += pRec->n; } } zNewRecord[j++] = addr & 0xff; @@ -1938,24 +1917,24 @@ case OP_MakeRecord: { p->uniqueCnt++; j += sizeof(p->uniqueCnt); } - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( (aStack[i].flags & STK_Null)==0 ){ - memcpy(&zNewRecord[j], zStack[i], aStack[i].n); - j += aStack[i].n; + for(i=0, pRec=&pTos[1-nField]; i<nField; i++, pRec++){ + if( (pRec->flags & MEM_Null)==0 ){ + memcpy(&zNewRecord[j], pRec->z, pRec->n); + j += pRec->n; } } - sqliteVdbePopStack(p, nField); - p->tos++; - aStack[p->tos].n = nByte; + popStack(&pTos, nField); + pTos++; + pTos->n = nByte; if( nByte<=NBFS ){ assert( zNewRecord==zTemp ); - memcpy(aStack[p->tos].z, zTemp, nByte); - zStack[p->tos] = aStack[p->tos].z; - aStack[p->tos].flags = STK_Str; + memcpy(pTos->zShort, zTemp, nByte); + pTos->z = pTos->zShort; + pTos->flags = MEM_Str | MEM_Short; }else{ assert( zNewRecord!=zTemp ); - aStack[p->tos].flags = STK_Str | STK_Dyn; - zStack[p->tos] = zNewRecord; + pTos->z = zNewRecord; + pTos->flags = MEM_Str | MEM_Dyn; } break; } @@ -2040,39 +2019,41 @@ case OP_MakeKey: { int addRowid; int i, j; int containsNull = 0; + Mem *pRec; char zTemp[NBFS]; addRowid = pOp->opcode==OP_MakeIdxKey; nField = pOp->p1; - VERIFY( if( p->tos+1+addRowid<nField ) goto not_enough_stack; ) + pRec = &pTos[1-nField]; + assert( pRec>=p->aStack ); nByte = 0; - for(j=0, i=p->tos-nField+1; i<=p->tos; i++, j++){ - int flags = aStack[i].flags; + for(j=0, i=0; i<nField; i++, j++, pRec++){ + int flags = pRec->flags; int len; char *z; - if( flags & STK_Null ){ + if( flags & MEM_Null ){ nByte += 2; containsNull = 1; }else if( pOp->p3 && pOp->p3[j]=='t' ){ - Stringify(p, i); - aStack[i].flags &= ~(STK_Int|STK_Real); - nByte += aStack[i].n+1; - }else if( (flags & (STK_Real|STK_Int))!=0 || sqliteIsNumber(zStack[i]) ){ - if( (flags & (STK_Real|STK_Int))==STK_Int ){ - aStack[i].r = aStack[i].i; - }else if( (flags & (STK_Real|STK_Int))==0 ){ - aStack[i].r = sqliteAtoF(zStack[i]); + Stringify(pRec); + pRec->flags &= ~(MEM_Int|MEM_Real); + nByte += pRec->n+1; + }else if( (flags & (MEM_Real|MEM_Int))!=0 || sqliteIsNumber(pRec->z) ){ + if( (flags & (MEM_Real|MEM_Int))==MEM_Int ){ + pRec->r = pRec->i; + }else if( (flags & (MEM_Real|MEM_Int))==0 ){ + pRec->r = sqliteAtoF(pRec->z, 0); } - Release(p, i); - z = aStack[i].z; - sqliteRealToSortable(aStack[i].r, z); + Release(pRec); + z = pRec->zShort; + sqliteRealToSortable(pRec->r, z); len = strlen(z); - zStack[i] = 0; - aStack[i].flags = STK_Real; - aStack[i].n = len+1; - nByte += aStack[i].n+1; + pRec->z = 0; + pRec->flags = MEM_Real; + pRec->n = len+1; + nByte += pRec->n+1; }else{ - nByte += aStack[i].n+1; + nByte += pRec->n+1; } } if( nByte+sizeof(u32)>MAX_BYTES_PER_ROW ){ @@ -2087,40 +2068,44 @@ case OP_MakeKey: { if( zNewKey==0 ) goto no_mem; } j = 0; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( aStack[i].flags & STK_Null ){ + pRec = &pTos[1-nField]; + for(i=0; i<nField; i++, pRec++){ + if( pRec->flags & MEM_Null ){ zNewKey[j++] = 'a'; zNewKey[j++] = 0; + }else if( pRec->flags==MEM_Real ){ + zNewKey[j++] = 'b'; + memcpy(&zNewKey[j], pRec->zShort, pRec->n); + j += pRec->n; }else{ - if( aStack[i].flags & (STK_Int|STK_Real) ){ - zNewKey[j++] = 'b'; - }else{ - zNewKey[j++] = 'c'; - } - memcpy(&zNewKey[j], zStack[i] ? zStack[i] : aStack[i].z, aStack[i].n); - j += aStack[i].n; + assert( pRec->flags & MEM_Str ); + zNewKey[j++] = 'c'; + memcpy(&zNewKey[j], pRec->z, pRec->n); + j += pRec->n; } } if( addRowid ){ u32 iKey; - Integerify(p, p->tos-nField); - iKey = intToKey(aStack[p->tos-nField].i); + pRec = &pTos[-nField]; + assert( pRec>=p->aStack ); + Integerify(pRec); + iKey = intToKey(pRec->i); memcpy(&zNewKey[j], &iKey, sizeof(u32)); - sqliteVdbePopStack(p, nField+1); + popStack(&pTos, nField+1); if( pOp->p2 && containsNull ) pc = pOp->p2 - 1; }else{ - if( pOp->p2==0 ) sqliteVdbePopStack(p, nField+addRowid); + if( pOp->p2==0 ) popStack(&pTos, nField); } - p->tos++; - aStack[p->tos].n = nByte; + pTos++; + pTos->n = nByte; if( nByte<=NBFS ){ assert( zNewKey==zTemp ); - zStack[p->tos] = aStack[p->tos].z; - memcpy(zStack[p->tos], zTemp, nByte); - aStack[p->tos].flags = STK_Str; + pTos->z = pTos->zShort; + memcpy(pTos->zShort, zTemp, nByte); + pTos->flags = MEM_Str | MEM_Short; }else{ - aStack[p->tos].flags = STK_Str|STK_Dyn; - zStack[p->tos] = zNewKey; + pTos->z = zNewKey; + pTos->flags = MEM_Str | MEM_Dyn; } break; } @@ -2134,18 +2119,14 @@ case OP_MakeKey: { ** the key itself. */ case OP_IncrKey: { - int tos = p->tos; - - VERIFY( if( tos<0 ) goto bad_instruction ); - Stringify(p, tos); - if( aStack[tos].flags & (STK_Static|STK_Ephem) ){ - /* CANT HAPPEN. The IncrKey opcode is only applied to keys - ** generated by MakeKey or MakeIdxKey and the results of those - ** operands are always dynamic strings. - */ - goto abort_due_to_error; - } - zStack[tos][aStack[tos].n-1]++; + assert( pTos>=p->aStack ); + /* The IncrKey opcode is only applied to keys generated by + ** MakeKey or MakeIdxKey and the results of those operands + ** are always dynamic strings or zShort[] strings. So we + ** are always free to modify the string in place. + */ + assert( pTos->flags & (MEM_Dyn|MEM_Short) ); + pTos->z[pTos->n-1]++; break; } @@ -2198,6 +2179,7 @@ case OP_Transaction: { p->pc = pc; p->undoTransOnError = 1; p->rc = SQLITE_BUSY; + p->pTos = pTos; return SQLITE_BUSY; }else if( (*db->xBusyCallback)(db->pBusyArg, "", busy++)==0 ){ sqliteSetString(&p->zErrMsg, sqlite_error_string(rc), (char*)0); @@ -2234,6 +2216,13 @@ case OP_Transaction: { */ case OP_Commit: { int i; + if( db->xCommitCallback!=0 ){ + if( sqliteSafetyOff(db) ) goto abort_due_to_misuse; + if( db->xCommitCallback(db->pCommitArg)!=0 ){ + rc = SQLITE_CONSTRAINT; + } + if( sqliteSafetyOn(db) ) goto abort_due_to_misuse; + } for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ if( db->aDb[i].inTrans ){ rc = sqliteBtreeCommit(db->aDb[i].pBt); @@ -2280,14 +2269,14 @@ case OP_Rollback: { ** executing this instruction. */ case OP_ReadCookie: { - int i = ++p->tos; int aMeta[SQLITE_N_BTREE_META]; assert( pOp->p2<SQLITE_N_BTREE_META ); assert( pOp->p1>=0 && pOp->p1<db->nDb ); assert( db->aDb[pOp->p1].pBt!=0 ); rc = sqliteBtreeGetMeta(db->aDb[pOp->p1].pBt, aMeta); - aStack[i].i = aMeta[1+pOp->p2]; - aStack[i].flags = STK_Int; + pTos++; + pTos->i = aMeta[1+pOp->p2]; + pTos->flags = MEM_Int; break; } @@ -2306,14 +2295,15 @@ case OP_SetCookie: { assert( pOp->p2<SQLITE_N_BTREE_META ); assert( pOp->p1>=0 && pOp->p1<db->nDb ); assert( db->aDb[pOp->p1].pBt!=0 ); - VERIFY( if( p->tos<0 ) goto not_enough_stack; ) - Integerify(p, p->tos) + assert( pTos>=p->aStack ); + Integerify(pTos) rc = sqliteBtreeGetMeta(db->aDb[pOp->p1].pBt, aMeta); if( rc==SQLITE_OK ){ - aMeta[1+pOp->p2] = aStack[p->tos].i; + aMeta[1+pOp->p2] = pTos->i; rc = sqliteBtreeUpdateMeta(db->aDb[pOp->p1].pBt, aMeta); } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -2392,32 +2382,31 @@ case OP_OpenRead: case OP_OpenWrite: { int busy = 0; int i = pOp->p1; - int tos = p->tos; int p2 = pOp->p2; int wrFlag; Btree *pX; int iDb; - VERIFY( if( tos<0 ) goto not_enough_stack; ); - Integerify(p, tos); - iDb = p->aStack[tos].i; - tos--; - VERIFY( if( iDb<0 || iDb>=db->nDb ) goto bad_instruction; ); - VERIFY( if( db->aDb[iDb].pBt==0 ) goto bad_instruction; ); + assert( pTos>=p->aStack ); + Integerify(pTos); + iDb = pTos->i; + pTos--; + assert( iDb>=0 && iDb<db->nDb ); pX = db->aDb[iDb].pBt; + assert( pX!=0 ); wrFlag = pOp->opcode==OP_OpenWrite; if( p2<=0 ){ - VERIFY( if( tos<0 ) goto not_enough_stack; ); - Integerify(p, tos); - p2 = p->aStack[tos].i; - POPSTACK; + assert( pTos>=p->aStack ); + Integerify(pTos); + p2 = pTos->i; + pTos--; if( p2<2 ){ sqliteSetString(&p->zErrMsg, "root page number less than 2", (char*)0); rc = SQLITE_INTERNAL; break; } } - VERIFY( if( i<0 ) goto bad_instruction; ) + assert( i>=0 ); if( expandCursorArraySize(p, i) ) goto no_mem; sqliteVdbeCleanupCursor(&p->aCsr[i]); memset(&p->aCsr[i], 0, sizeof(Cursor)); @@ -2430,6 +2419,7 @@ case OP_OpenWrite: { if( db->xBusyCallback==0 ){ p->pc = pc; p->rc = SQLITE_BUSY; + p->pTos = &pTos[1 + (pOp->p2<=0)]; /* Operands must remain on stack */ return SQLITE_BUSY; }else if( (*db->xBusyCallback)(db->pBusyArg, pOp->p3, ++busy)==0 ){ sqliteSetString(&p->zErrMsg, sqlite_error_string(rc), (char*)0); @@ -2446,10 +2436,6 @@ case OP_OpenWrite: { } } }while( busy ); - if( p2<=0 ){ - POPSTACK; - } - POPSTACK; break; } @@ -2474,7 +2460,7 @@ case OP_OpenWrite: { case OP_OpenTemp: { int i = pOp->p1; Cursor *pCx; - VERIFY( if( i<0 ) goto bad_instruction; ) + assert( i>=0 ); if( expandCursorArraySize(p, i) ) goto no_mem; pCx = &p->aCsr[i]; sqliteVdbeCleanupCursor(pCx); @@ -2512,7 +2498,7 @@ case OP_OpenTemp: { case OP_OpenPseudo: { int i = pOp->p1; Cursor *pCx; - VERIFY( if( i<0 ) goto bad_instruction; ) + assert( i>=0 ); if( expandCursorArraySize(p, i) ) goto no_mem; pCx = &p->aCsr[i]; sqliteVdbeCleanupCursor(pCx); @@ -2559,29 +2545,29 @@ case OP_Close: { case OP_MoveLt: case OP_MoveTo: { int i = pOp->p1; - int tos = p->tos; Cursor *pC; - VERIFY( if( tos<0 ) goto not_enough_stack; ) + assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); pC = &p->aCsr[i]; if( pC->pCursor!=0 ){ int res, oc; pC->nullRow = 0; - if( aStack[tos].flags & STK_Int ){ - int iKey = intToKey(aStack[tos].i); + if( pTos->flags & MEM_Int ){ + int iKey = intToKey(pTos->i); if( pOp->p2==0 && pOp->opcode==OP_MoveTo ){ pC->movetoTarget = iKey; pC->deferredMoveto = 1; - POPSTACK; + Release(pTos); + pTos--; break; } sqliteBtreeMoveto(pC->pCursor, (char*)&iKey, sizeof(int), &res); - pC->lastRecno = aStack[tos].i; + pC->lastRecno = pTos->i; pC->recnoIsValid = res==0; }else{ - Stringify(p, tos); - sqliteBtreeMoveto(pC->pCursor, zStack[tos], aStack[tos].n, &res); + Stringify(pTos); + sqliteBtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res); pC->recnoIsValid = 0; } pC->deferredMoveto = 0; @@ -2609,7 +2595,8 @@ case OP_MoveTo: { } } } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -2650,14 +2637,14 @@ case OP_Distinct: case OP_NotFound: case OP_Found: { int i = pOp->p1; - int tos = p->tos; int alreadyExists = 0; Cursor *pC; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - if( VERIFY( i>=0 && i<p->nCursor && ) (pC = &p->aCsr[i])->pCursor!=0 ){ + assert( pTos>=p->aStack ); + assert( i>=0 && i<p->nCursor ); + if( (pC = &p->aCsr[i])->pCursor!=0 ){ int res, rx; - Stringify(p, tos); - rx = sqliteBtreeMoveto(pC->pCursor, zStack[tos], aStack[tos].n, &res); + Stringify(pTos); + rx = sqliteBtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res); alreadyExists = rx==SQLITE_OK && res==0; pC->deferredMoveto = 0; } @@ -2667,7 +2654,8 @@ case OP_Found: { if( !alreadyExists ) pc = pOp->p2 - 1; } if( pOp->opcode!=OP_Distinct ){ - POPSTACK; + Release(pTos); + pTos--; } break; } @@ -2694,18 +2682,18 @@ case OP_Found: { */ case OP_IsUnique: { int i = pOp->p1; - int tos = p->tos; - int nos = tos-1; + Mem *pNos = &pTos[-1]; BtCursor *pCrsr; int R; /* Pop the value R off the top of the stack */ - VERIFY( if( nos<0 ) goto not_enough_stack; ) - Integerify(p, tos); - R = aStack[tos].i; - POPSTACK; - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ + assert( pNos>=p->aStack ); + Integerify(pTos); + R = pTos->i; + pTos--; + assert( i>=0 && i<=p->nCursor ); + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int res, rc; int v; /* The record number on the P1 entry that matches K */ char *zKey; /* The value of K */ @@ -2713,9 +2701,9 @@ case OP_IsUnique: { /* Make sure K is a string and make zKey point to K */ - Stringify(p, nos); - zKey = zStack[nos]; - nKey = aStack[nos].n; + Stringify(pNos); + zKey = pNos->z; + nKey = pNos->n; assert( nKey >= 4 ); /* Search for an entry in P1 where all but the last four bytes match K. @@ -2755,9 +2743,9 @@ case OP_IsUnique: { ** stack. (These bytes are the record number of an entry that ** violates a UNIQUE constraint.) */ - p->tos++; - aStack[tos].i = v; - aStack[tos].flags = STK_Int; + pTos++; + pTos->i = v; + pTos->flags = MEM_Int; } break; } @@ -2777,15 +2765,15 @@ case OP_IsUnique: { */ case OP_NotExists: { int i = pOp->p1; - int tos = p->tos; BtCursor *pCrsr; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ + assert( pTos>=p->aStack ); + assert( i>=0 && i<p->nCursor ); + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int res, rx, iKey; - assert( aStack[tos].flags & STK_Int ); - iKey = intToKey(aStack[tos].i); + assert( pTos->flags & MEM_Int ); + iKey = intToKey(pTos->i); rx = sqliteBtreeMoveto(pCrsr, (char*)&iKey, sizeof(int), &res); - p->aCsr[i].lastRecno = aStack[tos].i; + p->aCsr[i].lastRecno = pTos->i; p->aCsr[i].recnoIsValid = res==0; p->aCsr[i].nullRow = 0; if( rx!=SQLITE_OK || res!=0 ){ @@ -2793,7 +2781,8 @@ case OP_NotExists: { p->aCsr[i].recnoIsValid = 0; } } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -2808,7 +2797,8 @@ case OP_NewRecno: { int i = pOp->p1; int v = 0; Cursor *pC; - if( VERIFY( i<0 || i>=p->nCursor || ) (pC = &p->aCsr[i])->pCursor==0 ){ + assert( i>=0 && i<p->nCursor ); + if( (pC = &p->aCsr[i])->pCursor==0 ){ v = 0; }else{ /* The next rowid or record number (different terms for the same @@ -2873,10 +2863,12 @@ case OP_NewRecno: { cnt = 0; do{ if( v==0 || cnt>2 ){ - v = sqliteRandomInteger(); + sqliteRandomness(sizeof(v), &v); if( cnt<5 ) v &= 0xffffff; }else{ - v += sqliteRandomByte() + 1; + unsigned char r; + sqliteRandomness(1, &r); + v += r + 1; } if( v==0 ) continue; x = intToKey(v); @@ -2892,9 +2884,9 @@ case OP_NewRecno: { pC->recnoIsValid = 0; pC->deferredMoveto = 0; } - p->tos++; - aStack[p->tos].i = v; - aStack[p->tos].flags = STK_Int; + pTos++; + pTos->i = v; + pTos->flags = MEM_Int; break; } @@ -2906,9 +2898,12 @@ case OP_NewRecno: { ** stack. The key is the next value down on the stack. The key must ** be an integer. The stack is popped twice by this instruction. ** -** If P2==1 then the row change count is incremented. If P2==0 the -** row change count is unmodified. The rowid is stored for subsequent -** return by the sqlite_last_insert_rowid() function if P2 is 1. +** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is +** incremented (otherwise not). If the OPFLAG_CSCHANGE flag is set, +** then the current statement change count is incremented (otherwise not). +** If the OPFLAG_LASTROWID flag of P2 is set, then rowid is +** stored for subsequent return by the sqlite_last_insert_rowid() function +** (otherwise it's unmodified). */ /* Opcode: PutStrKey P1 * * ** @@ -2922,32 +2917,36 @@ case OP_NewRecno: { */ case OP_PutIntKey: case OP_PutStrKey: { - int tos = p->tos; - int nos = p->tos-1; + Mem *pNos = &pTos[-1]; int i = pOp->p1; Cursor *pC; - VERIFY( if( nos<0 ) goto not_enough_stack; ) - if( VERIFY( i>=0 && i<p->nCursor && ) - ((pC = &p->aCsr[i])->pCursor!=0 || pC->pseudoTable) ){ + assert( pNos>=p->aStack ); + assert( i>=0 && i<p->nCursor ); + if( ((pC = &p->aCsr[i])->pCursor!=0 || pC->pseudoTable) ){ char *zKey; int nKey, iKey; if( pOp->opcode==OP_PutStrKey ){ - Stringify(p, nos); - nKey = aStack[nos].n; - zKey = zStack[nos]; + Stringify(pNos); + nKey = pNos->n; + zKey = pNos->z; }else{ - assert( aStack[nos].flags & STK_Int ); + assert( pNos->flags & MEM_Int ); nKey = sizeof(int); - iKey = intToKey(aStack[nos].i); + iKey = intToKey(pNos->i); zKey = (char*)&iKey; - if( pOp->p2 ){ - db->nChange++; - db->lastRowid = aStack[nos].i; - } - if( pC->nextRowidValid && aStack[nos].i>=pC->nextRowid ){ + if( pOp->p2 & OPFLAG_NCHANGE ) db->nChange++; + if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->i; + if( pOp->p2 & OPFLAG_CSCHANGE ) db->csChange++; + if( pC->nextRowidValid && pTos->i>=pC->nextRowid ){ pC->nextRowidValid = 0; } } + if( pTos->flags & MEM_Null ){ + pTos->z = 0; + pTos->n = 0; + }else{ + assert( pTos->flags & MEM_Str ); + } if( pC->pseudoTable ){ /* PutStrKey does not work for pseudo-tables. ** The following assert makes sure we are not trying to use @@ -2956,27 +2955,24 @@ case OP_PutStrKey: { assert( pOp->opcode==OP_PutIntKey ); sqliteFree(pC->pData); pC->iKey = iKey; - pC->nData = aStack[tos].n; - if( aStack[tos].flags & STK_Dyn ){ - pC->pData = zStack[tos]; - zStack[tos] = 0; - aStack[tos].flags = STK_Null; + pC->nData = pTos->n; + if( pTos->flags & MEM_Dyn ){ + pC->pData = pTos->z; + pTos->flags = MEM_Null; }else{ pC->pData = sqliteMallocRaw( pC->nData ); if( pC->pData ){ - memcpy(pC->pData, zStack[tos], pC->nData); + memcpy(pC->pData, pTos->z, pC->nData); } } pC->nullRow = 0; }else{ - rc = sqliteBtreeInsert(pC->pCursor, zKey, nKey, - zStack[tos], aStack[tos].n); + rc = sqliteBtreeInsert(pC->pCursor, zKey, nKey, pTos->z, pTos->n); } pC->recnoIsValid = 0; pC->deferredMoveto = 0; } - POPSTACK; - POPSTACK; + popStack(&pTos, 2); break; } @@ -2989,8 +2985,9 @@ case OP_PutStrKey: { ** the next Next instruction will be a no-op. Hence it is OK to delete ** a record from within an Next loop. ** -** The row change counter is incremented if P2==1 and is unmodified -** if P2==0. +** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is +** incremented (otherwise not). If OPFLAG_CSCHANGE flag is set, +** then the current statement change count is incremented (otherwise not). ** ** If P1 is a pseudo-table, then this instruction is a no-op. */ @@ -3004,7 +3001,19 @@ case OP_Delete: { rc = sqliteBtreeDelete(pC->pCursor); pC->nextRowidValid = 0; } - if( pOp->p2 ) db->nChange++; + if( pOp->p2 & OPFLAG_NCHANGE ) db->nChange++; + if( pOp->p2 & OPFLAG_CSCHANGE ) db->csChange++; + break; +} + +/* Opcode: SetCounts * * * +** +** Called at end of statement. Updates lsChange (last statement change count) +** and resets csChange (current statement change count) to 0. +*/ +case OP_SetCounts: { + db->lsChange=db->csChange; + db->csChange=0; break; } @@ -3043,46 +3052,46 @@ case OP_KeyAsData: { case OP_RowKey: case OP_RowData: { int i = pOp->p1; - int tos = ++p->tos; Cursor *pC; int n; + pTos++; assert( i>=0 && i<p->nCursor ); pC = &p->aCsr[i]; if( pC->nullRow ){ - aStack[tos].flags = STK_Null; + pTos->flags = MEM_Null; }else if( pC->pCursor!=0 ){ BtCursor *pCrsr = pC->pCursor; sqliteVdbeCursorMoveto(pC); if( pC->nullRow ){ - aStack[tos].flags = STK_Null; + pTos->flags = MEM_Null; break; }else if( pC->keyAsData || pOp->opcode==OP_RowKey ){ sqliteBtreeKeySize(pCrsr, &n); }else{ sqliteBtreeDataSize(pCrsr, &n); } - aStack[tos].n = n; + pTos->n = n; if( n<=NBFS ){ - aStack[tos].flags = STK_Str; - zStack[tos] = aStack[tos].z; + pTos->flags = MEM_Str | MEM_Short; + pTos->z = pTos->zShort; }else{ char *z = sqliteMallocRaw( n ); if( z==0 ) goto no_mem; - aStack[tos].flags = STK_Str | STK_Dyn; - zStack[tos] = z; + pTos->flags = MEM_Str | MEM_Dyn; + pTos->z = z; } if( pC->keyAsData || pOp->opcode==OP_RowKey ){ - sqliteBtreeKey(pCrsr, 0, n, zStack[tos]); + sqliteBtreeKey(pCrsr, 0, n, pTos->z); }else{ - sqliteBtreeData(pCrsr, 0, n, zStack[tos]); + sqliteBtreeData(pCrsr, 0, n, pTos->z); } }else if( pC->pseudoTable ){ - aStack[tos].n = pC->nData; - zStack[tos] = pC->pData; - aStack[tos].flags = STK_Str|STK_Ephem; + pTos->n = pC->nData; + pTos->z = pC->pData; + pTos->flags = MEM_Str|MEM_Ephem; }else{ - aStack[tos].flags = STK_Null; + pTos->flags = MEM_Null; } break; } @@ -3110,7 +3119,6 @@ case OP_Column: { int amt, offset, end, payloadSize; int i = pOp->p1; int p2 = pOp->p2; - int tos = p->tos+1; Cursor *pC; char *zRec; BtCursor *pCrsr; @@ -3118,11 +3126,12 @@ case OP_Column: { unsigned char aHdr[10]; assert( i<p->nCursor ); + pTos++; if( i<0 ){ - VERIFY( if( tos+i<0 ) goto bad_instruction; ) - VERIFY( if( (aStack[tos+i].flags & STK_Str)==0 ) goto bad_instruction; ) - zRec = zStack[tos+i]; - payloadSize = aStack[tos+i].n; + assert( &pTos[i]>=p->aStack ); + assert( pTos[i].flags & MEM_Str ); + zRec = pTos[i].z; + payloadSize = pTos[i].n; }else if( (pC = &p->aCsr[i])->pCursor!=0 ){ sqliteVdbeCursorMoveto(pC); zRec = 0; @@ -3146,8 +3155,7 @@ case OP_Column: { ** data begins. */ if( payloadSize==0 ){ - aStack[tos].flags = STK_Null; - p->tos = tos; + pTos->flags = MEM_Null; break; }else if( payloadSize<256 ){ idxWidth = 1; @@ -3189,31 +3197,28 @@ case OP_Column: { /* amt and offset now hold the offset to the start of data and the ** amount of data. Go get the data and put it on the stack. */ + pTos->n = amt; if( amt==0 ){ - aStack[tos].flags = STK_Null; + pTos->flags = MEM_Null; }else if( zRec ){ - aStack[tos].flags = STK_Str | STK_Ephem; - aStack[tos].n = amt; - zStack[tos] = &zRec[offset]; + pTos->flags = MEM_Str | MEM_Ephem; + pTos->z = &zRec[offset]; }else{ if( amt<=NBFS ){ - aStack[tos].flags = STK_Str; - zStack[tos] = aStack[tos].z; - aStack[tos].n = amt; + pTos->flags = MEM_Str | MEM_Short; + pTos->z = pTos->zShort; }else{ char *z = sqliteMallocRaw( amt ); if( z==0 ) goto no_mem; - aStack[tos].flags = STK_Str | STK_Dyn; - zStack[tos] = z; - aStack[tos].n = amt; + pTos->flags = MEM_Str | MEM_Dyn; + pTos->z = z; } if( pC->keyAsData ){ - sqliteBtreeKey(pCrsr, offset, amt, zStack[tos]); + sqliteBtreeKey(pCrsr, offset, amt, pTos->z); }else{ - sqliteBtreeData(pCrsr, offset, amt, zStack[tos]); + sqliteBtreeData(pCrsr, offset, amt, pTos->z); } } - p->tos = tos; break; } @@ -3226,27 +3231,27 @@ case OP_Column: { */ case OP_Recno: { int i = pOp->p1; - int tos = ++p->tos; Cursor *pC; int v; assert( i>=0 && i<p->nCursor ); pC = &p->aCsr[i]; sqliteVdbeCursorMoveto(pC); + pTos++; if( pC->recnoIsValid ){ v = pC->lastRecno; }else if( pC->pseudoTable ){ v = keyToInt(pC->iKey); }else if( pC->nullRow || pC->pCursor==0 ){ - aStack[tos].flags = STK_Null; + pTos->flags = MEM_Null; break; }else{ assert( pC->pCursor!=0 ); sqliteBtreeKey(pC->pCursor, 0, sizeof(u32), (char*)&v); v = keyToInt(v); } - aStack[tos].i = v; - aStack[tos].flags = STK_Int; + pTos->i = v; + pTos->flags = MEM_Int; break; } @@ -3263,12 +3268,13 @@ case OP_Recno: { */ case OP_FullKey: { int i = pOp->p1; - int tos = ++p->tos; BtCursor *pCrsr; - VERIFY( if( !p->aCsr[i].keyAsData ) goto bad_instruction; ) - VERIFY( if( p->aCsr[i].pseudoTable ) goto bad_instruction; ) - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ + assert( p->aCsr[i].keyAsData ); + assert( !p->aCsr[i].pseudoTable ); + assert( i>=0 && i<p->nCursor ); + pTos++; + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int amt; char *z; @@ -3281,14 +3287,14 @@ case OP_FullKey: { if( amt>NBFS ){ z = sqliteMallocRaw( amt ); if( z==0 ) goto no_mem; - aStack[tos].flags = STK_Str | STK_Dyn; + pTos->flags = MEM_Str | MEM_Dyn; }else{ - z = aStack[tos].z; - aStack[tos].flags = STK_Str; + z = pTos->zShort; + pTos->flags = MEM_Str | MEM_Short; } sqliteBtreeKey(pCrsr, 0, amt, z); - zStack[tos] = z; - aStack[tos].n = amt; + pTos->z = z; + pTos->n = amt; } break; } @@ -3425,15 +3431,16 @@ case OP_Next: { */ case OP_IdxPut: { int i = pOp->p1; - int tos = p->tos; BtCursor *pCrsr; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ - int nKey = aStack[tos].n; - const char *zKey = zStack[tos]; + assert( pTos>=p->aStack ); + assert( i>=0 && i<p->nCursor ); + assert( pTos->flags & MEM_Str ); + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ + int nKey = pTos->n; + const char *zKey = pTos->z; if( pOp->p2 ){ int res, n; - assert( aStack[tos].n >= 4 ); + assert( nKey >= 4 ); rc = sqliteBtreeMoveto(pCrsr, zKey, nKey-4, &res); if( rc!=SQLITE_OK ) goto abort_due_to_error; while( res!=0 ){ @@ -3460,7 +3467,8 @@ case OP_IdxPut: { rc = sqliteBtreeInsert(pCrsr, zKey, nKey, "", 0); assert( p->aCsr[i].deferredMoveto==0 ); } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -3471,18 +3479,20 @@ case OP_IdxPut: { */ case OP_IdxDelete: { int i = pOp->p1; - int tos = p->tos; BtCursor *pCrsr; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ + assert( pTos>=p->aStack ); + assert( pTos->flags & MEM_Str ); + assert( i>=0 && i<p->nCursor ); + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int rx, res; - rx = sqliteBtreeMoveto(pCrsr, zStack[tos], aStack[tos].n, &res); + rx = sqliteBtreeMoveto(pCrsr, pTos->z, pTos->n, &res); if( rx==SQLITE_OK && res==0 ){ rc = sqliteBtreeDelete(pCrsr); } assert( p->aCsr[i].deferredMoveto==0 ); } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -3497,22 +3507,25 @@ case OP_IdxDelete: { */ case OP_IdxRecno: { int i = pOp->p1; - int tos = ++p->tos; BtCursor *pCrsr; - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ + assert( i>=0 && i<p->nCursor ); + pTos++; + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int v; int sz; assert( p->aCsr[i].deferredMoveto==0 ); sqliteBtreeKeySize(pCrsr, &sz); if( sz<sizeof(u32) ){ - aStack[tos].flags = STK_Null; + pTos->flags = MEM_Null; }else{ sqliteBtreeKey(pCrsr, sz - sizeof(u32), sizeof(u32), (char*)&v); v = keyToInt(v); - aStack[tos].i = v; - aStack[tos].flags = STK_Int; + pTos->i = v; + pTos->flags = MEM_Int; } + }else{ + pTos->flags = MEM_Null; } break; } @@ -3546,15 +3559,16 @@ case OP_IdxLT: case OP_IdxGT: case OP_IdxGE: { int i= pOp->p1; - int tos = p->tos; BtCursor *pCrsr; - if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){ + assert( i>=0 && i<p->nCursor ); + assert( pTos>=p->aStack ); + if( (pCrsr = p->aCsr[i].pCursor)!=0 ){ int res, rc; - Stringify(p, tos); + Stringify(pTos); assert( p->aCsr[i].deferredMoveto==0 ); - rc = sqliteBtreeKeyCompare(pCrsr, zStack[tos], aStack[tos].n, 4, &res); + rc = sqliteBtreeKeyCompare(pCrsr, pTos->z, pTos->n, 4, &res); if( rc!=SQLITE_OK ){ break; } @@ -3567,7 +3581,8 @@ case OP_IdxGE: { pc = pOp->p2 - 1 ; } } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -3582,14 +3597,13 @@ case OP_IdxGE: { */ case OP_IdxIsNull: { int i = pOp->p1; - int tos = p->tos; int k, n; const char *z; - assert( tos>=0 ); - assert( aStack[tos].flags & STK_Str ); - z = zStack[tos]; - n = aStack[tos].n; + assert( pTos>=p->aStack ); + assert( pTos->flags & MEM_Str ); + z = pTos->z; + n = pTos->n; for(k=0; k<n && i>0; i--){ if( z[k]=='a' ){ pc = pOp->p2-1; @@ -3598,7 +3612,8 @@ case OP_IdxIsNull: { while( k<n && z[k] ){ k++; } k++; } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -3662,7 +3677,6 @@ case OP_Clear: { */ case OP_CreateIndex: case OP_CreateTable: { - int i = ++p->tos; int pgno; assert( pOp->p3!=0 && pOp->p3type==P3_POINTER ); assert( pOp->p2>=0 && pOp->p2<db->nDb ); @@ -3672,11 +3686,14 @@ case OP_CreateTable: { }else{ rc = sqliteBtreeCreateIndex(db->aDb[pOp->p2].pBt, &pgno); } + pTos++; if( rc==SQLITE_OK ){ - aStack[i].i = pgno; - aStack[i].flags = STK_Int; + pTos->i = pgno; + pTos->flags = MEM_Int; *(u32*)pOp->p3 = pgno; pOp->p3 = 0; + }else{ + pTos->flags = MEM_Null; } break; } @@ -3700,14 +3717,14 @@ case OP_CreateTable: { case OP_IntegrityCk: { int nRoot; int *aRoot; - int tos = ++p->tos; int iSet = pOp->p1; Set *pSet; int j; HashElem *i; char *z; - VERIFY( if( iSet<0 || iSet>=p->nSet ) goto bad_instruction; ) + assert( iSet>=0 && iSet<p->nSet ); + pTos++; pSet = &p->aSet[iSet]; nRoot = sqliteHashCount(&pSet->hash); aRoot = sqliteMallocRaw( sizeof(int)*(nRoot+1) ); @@ -3721,13 +3738,13 @@ case OP_IntegrityCk: { z = sqliteBtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot); if( z==0 || z[0]==0 ){ if( z ) sqliteFree(z); - zStack[tos] = "ok"; - aStack[tos].n = 3; - aStack[tos].flags = STK_Str | STK_Static; + pTos->z = "ok"; + pTos->n = 3; + pTos->flags = MEM_Str | MEM_Static; }else{ - zStack[tos] = z; - aStack[tos].n = strlen(z) + 1; - aStack[tos].flags = STK_Str | STK_Dyn; + pTos->z = z; + pTos->n = strlen(z) + 1; + pTos->flags = MEM_Str | MEM_Dyn; } sqliteFree(aRoot); break; @@ -3740,7 +3757,7 @@ case OP_IntegrityCk: { */ case OP_ListWrite: { Keylist *pKeylist; - VERIFY( if( p->tos<0 ) goto not_enough_stack; ) + assert( pTos>=p->aStack ); pKeylist = p->pList; if( pKeylist==0 || pKeylist->nUsed>=pKeylist->nKey ){ pKeylist = sqliteMallocRaw( sizeof(Keylist)+999*sizeof(pKeylist->aKey[0]) ); @@ -3751,19 +3768,30 @@ case OP_ListWrite: { pKeylist->pNext = p->pList; p->pList = pKeylist; } - Integerify(p, p->tos); - pKeylist->aKey[pKeylist->nUsed++] = aStack[p->tos].i; - POPSTACK; + Integerify(pTos); + pKeylist->aKey[pKeylist->nUsed++] = pTos->i; + Release(pTos); + pTos--; break; } /* Opcode: ListRewind * * * ** -** Rewind the temporary buffer back to the beginning. This is -** now a no-op. +** Rewind the temporary buffer back to the beginning. */ case OP_ListRewind: { - /* This is now a no-op */ + /* 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. */ + Keylist *pRev, *pTop; + pRev = 0; + while( p->pList ){ + pTop = p->pList; + p->pList = pTop->pNext; + pTop->pNext = pRev; + pRev = pTop; + } + p->pList = pRev; break; } @@ -3778,15 +3806,12 @@ case OP_ListRead: { CHECK_FOR_INTERRUPT; pKeylist = p->pList; if( pKeylist!=0 ){ - VERIFY( - if( pKeylist->nRead<0 - || pKeylist->nRead>=pKeylist->nUsed - || pKeylist->nRead>=pKeylist->nKey ) goto bad_instruction; - ) - p->tos++; - aStack[p->tos].i = pKeylist->aKey[pKeylist->nRead++]; - aStack[p->tos].flags = STK_Int; - zStack[p->tos] = 0; + assert( pKeylist->nRead>=0 ); + assert( pKeylist->nRead<pKeylist->nUsed ); + assert( pKeylist->nRead<pKeylist->nKey ); + pTos++; + pTos->i = pKeylist->aKey[pKeylist->nRead++]; + pTos->flags = MEM_Int; if( pKeylist->nRead>=pKeylist->nUsed ){ p->pList = pKeylist->pNext; sqliteFree(pKeylist); @@ -3843,6 +3868,43 @@ case OP_ListPop: { break; } +/* Opcode: ContextPush * * * +** +** Save the current Vdbe context such that it can be restored by a ContextPop +** opcode. The context stores the last insert row id, the last statement change +** count, and the current statement change count. +*/ +case OP_ContextPush: { + p->contextStackDepth++; + assert(p->contextStackDepth > 0); + p->contextStack = sqliteRealloc(p->contextStack, + sizeof(Context) * p->contextStackDepth); + if( p->contextStack==0 ) goto no_mem; + p->contextStack[p->contextStackDepth - 1].lastRowid = p->db->lastRowid; + p->contextStack[p->contextStackDepth - 1].lsChange = p->db->lsChange; + p->contextStack[p->contextStackDepth - 1].csChange = p->db->csChange; + break; +} + +/* Opcode: ContextPop * * * +** +** Restore the Vdbe context to the state it was in when contextPush was last +** executed. The context stores the last insert row id, the last statement +** change count, and the current statement change count. +*/ +case OP_ContextPop: { + assert(p->contextStackDepth > 0); + p->contextStackDepth--; + p->db->lastRowid = p->contextStack[p->contextStackDepth].lastRowid; + p->db->lsChange = p->contextStack[p->contextStackDepth].lsChange; + p->db->csChange = p->contextStack[p->contextStackDepth].csChange; + if( p->contextStackDepth == 0 ){ + sqliteFree(p->contextStack); + p->contextStack = 0; + } + break; +} + /* Opcode: SortPut * * * ** ** The TOS is the key and the NOS is the data. Pop both from the stack @@ -3850,29 +3912,21 @@ case OP_ListPop: { ** made using SortMakeKey and SortMakeRec, respectively. */ case OP_SortPut: { - int tos = p->tos; - int nos = tos - 1; + Mem *pNos = &pTos[-1]; Sorter *pSorter; - VERIFY( if( tos<1 ) goto not_enough_stack; ) - if( Dynamicify(p, tos) || Dynamicify(p, nos) ) goto no_mem; + assert( pNos>=p->aStack ); + if( Dynamicify(pTos) || Dynamicify(pNos) ) goto no_mem; pSorter = sqliteMallocRaw( sizeof(Sorter) ); if( pSorter==0 ) goto no_mem; pSorter->pNext = p->pSort; p->pSort = pSorter; - assert( aStack[tos].flags & STK_Dyn ); - pSorter->nKey = aStack[tos].n; - pSorter->zKey = zStack[tos]; - pSorter->nData = aStack[nos].n; - if( aStack[nos].flags & STK_Dyn ){ - pSorter->pData = zStack[nos]; - }else{ - pSorter->pData = sqliteStrDup(zStack[nos]); - } - aStack[tos].flags = 0; - aStack[nos].flags = 0; - zStack[tos] = 0; - zStack[nos] = 0; - p->tos -= 2; + assert( pTos->flags & MEM_Dyn ); + pSorter->nKey = pTos->n; + pSorter->zKey = pTos->z; + assert( pNos->flags & MEM_Dyn ); + pSorter->nData = pNos->n; + pSorter->pData = pNos->z; + pTos -= 2; break; } @@ -3887,35 +3941,37 @@ case OP_SortMakeRec: { char **azArg; int nByte; int nField; - int i, j; + int i; + Mem *pRec; nField = pOp->p1; - VERIFY( if( p->tos+1<nField ) goto not_enough_stack; ) + pRec = &pTos[1-nField]; + assert( pRec>=p->aStack ); nByte = 0; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( (aStack[i].flags & STK_Null)==0 ){ - Stringify(p, i); - nByte += aStack[i].n; + for(i=0; i<nField; i++, pRec++){ + if( (pRec->flags & MEM_Null)==0 ){ + Stringify(pRec); + nByte += pRec->n; } } nByte += sizeof(char*)*(nField+1); azArg = sqliteMallocRaw( nByte ); if( azArg==0 ) goto no_mem; z = (char*)&azArg[nField+1]; - for(j=0, i=p->tos-nField+1; i<=p->tos; i++, j++){ - if( aStack[i].flags & STK_Null ){ - azArg[j] = 0; + for(pRec=&pTos[1-nField], i=0; i<nField; i++, pRec++){ + if( pRec->flags & MEM_Null ){ + azArg[i] = 0; }else{ - azArg[j] = z; - strcpy(z, zStack[i]); - z += aStack[i].n; + azArg[i] = z; + memcpy(z, pRec->z, pRec->n); + z += pRec->n; } } - sqliteVdbePopStack(p, nField); - p->tos++; - aStack[p->tos].n = nByte; - zStack[p->tos] = (char*)azArg; - aStack[p->tos].flags = STK_Str|STK_Dyn; + popStack(&pTos, nField); + pTos++; + pTos->n = nByte; + pTos->z = (char*)azArg; + pTos->flags = MEM_Str | MEM_Dyn; break; } @@ -3939,41 +3995,42 @@ case OP_SortMakeKey: { int nByte; int nField; int i, j, k; + Mem *pRec; nField = strlen(pOp->p3); - VERIFY( if( p->tos+1<nField ) goto not_enough_stack; ) + pRec = &pTos[1-nField]; nByte = 1; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( (aStack[i].flags & STK_Null)!=0 ){ + for(i=0; i<nField; i++, pRec++){ + if( pRec->flags & MEM_Null ){ nByte += 2; }else{ - Stringify(p, i); - nByte += aStack[i].n+2; + Stringify(pRec); + nByte += pRec->n+2; } } zNewKey = sqliteMallocRaw( nByte ); if( zNewKey==0 ) goto no_mem; j = 0; k = 0; - for(i=p->tos-nField+1; i<=p->tos; i++){ - if( (aStack[i].flags & STK_Null)!=0 ){ + for(pRec=&pTos[1-nField], i=0; i<nField; i++, pRec++){ + if( pRec->flags & MEM_Null ){ zNewKey[j++] = 'N'; zNewKey[j++] = 0; k++; }else{ zNewKey[j++] = pOp->p3[k++]; - memcpy(&zNewKey[j], zStack[i], aStack[i].n-1); - j += aStack[i].n-1; + memcpy(&zNewKey[j], pRec->z, pRec->n-1); + j += pRec->n-1; zNewKey[j++] = 0; } } zNewKey[j] = 0; assert( j<nByte ); - sqliteVdbePopStack(p, nField); - p->tos++; - aStack[p->tos].n = nByte; - aStack[p->tos].flags = STK_Str|STK_Dyn; - zStack[p->tos] = zNewKey; + popStack(&pTos, nField); + pTos++; + pTos->n = nByte; + pTos->flags = MEM_Str|MEM_Dyn; + pTos->z = zNewKey; break; } @@ -4026,10 +4083,10 @@ case OP_SortNext: { CHECK_FOR_INTERRUPT; if( pSorter!=0 ){ p->pSort = pSorter->pNext; - p->tos++; - zStack[p->tos] = pSorter->pData; - aStack[p->tos].n = pSorter->nData; - aStack[p->tos].flags = STK_Str|STK_Dyn; + pTos++; + pTos->z = pSorter->pData; + pTos->n = pSorter->nData; + pTos->flags = MEM_Str|MEM_Dyn; sqliteFree(pSorter->zKey); sqliteFree(pSorter); }else{ @@ -4046,25 +4103,15 @@ case OP_SortNext: { ** callback on it. */ case OP_SortCallback: { - int i = p->tos; - VERIFY( if( i<0 ) goto not_enough_stack; ) - if( p->xCallback==0 ){ - p->pc = pc+1; - p->azResColumn = (char**)zStack[i]; - p->nResColumn = pOp->p1; - p->popStack = 1; - return SQLITE_ROW; - }else{ - if( sqliteSafetyOff(db) ) goto abort_due_to_misuse; - if( p->xCallback(p->pCbArg, pOp->p1, (char**)zStack[i], p->azColName)!=0 ){ - rc = SQLITE_ABORT; - } - if( sqliteSafetyOn(db) ) goto abort_due_to_misuse; - p->nCallback++; - } - POPSTACK; - if( sqlite_malloc_failed ) goto no_mem; - break; + assert( pTos>=p->aStack ); + assert( pTos->flags & MEM_Str ); + p->nCallback++; + p->pc = pc+1; + p->azResColumn = (char**)pTos->z; + assert( p->nResColumn==pOp->p1 ); + p->popStack = 1; + p->pTos = pTos; + return SQLITE_ROW; } /* Opcode: SortReset * * * @@ -4082,7 +4129,7 @@ case OP_SortReset: { ** If P3 is "stdin" then open standard input for reading. */ case OP_FileOpen: { - VERIFY( if( pOp->p3==0 ) goto bad_instruction; ) + assert( pOp->p3!=0 ); if( p->pFile ){ if( p->pFile!=stdin ) fclose(p->pFile); p->pFile = 0; @@ -4227,20 +4274,19 @@ fileread_jump: case OP_FileColumn: { int i = pOp->p1; char *z; - if( VERIFY( i>=0 && i<p->nField && ) p->azField ){ + assert( i>=0 && i<p->nField ); + if( p->azField ){ z = p->azField[i]; }else{ z = 0; } - p->tos++; + pTos++; if( z ){ - aStack[p->tos].n = strlen(z) + 1; - zStack[p->tos] = z; - aStack[p->tos].flags = STK_Str; + pTos->n = strlen(z) + 1; + pTos->z = z; + pTos->flags = MEM_Str | MEM_Ephem; }else{ - aStack[p->tos].n = 0; - zStack[p->tos] = 0; - aStack[p->tos].flags = STK_Null; + pTos->flags = MEM_Null; } break; } @@ -4257,11 +4303,8 @@ case OP_FileColumn: { */ case OP_MemStore: { int i = pOp->p1; - int tos = p->tos; - char *zOld; Mem *pMem; - int flags; - VERIFY( if( tos<0 ) goto not_enough_stack; ) + assert( pTos>=p->aStack ); if( i>=p->nMem ){ int nOld = p->nMem; Mem *aMem; @@ -4271,8 +4314,8 @@ case OP_MemStore: { if( aMem!=p->aMem ){ int j; for(j=0; j<nOld; j++){ - if( aMem[j].z==p->aMem[j].s.z ){ - aMem[j].z = aMem[j].s.z; + if( aMem[j].flags & MEM_Short ){ + aMem[j].z = aMem[j].zShort; } } } @@ -4281,33 +4324,24 @@ case OP_MemStore: { memset(&p->aMem[nOld], 0, sizeof(p->aMem[0])*(p->nMem-nOld)); } } + Deephemeralize(pTos); pMem = &p->aMem[i]; - flags = pMem->s.flags; - if( flags & STK_Dyn ){ - zOld = pMem->z; - }else{ - zOld = 0; - } - pMem->s = aStack[tos]; - flags = pMem->s.flags; - if( flags & (STK_Static|STK_Dyn|STK_Ephem) ){ - if( (flags & STK_Static)!=0 || (pOp->p2 && (flags & STK_Dyn)!=0) ){ - pMem->z = zStack[tos]; - }else if( flags & STK_Str ){ - pMem->z = sqliteMallocRaw( pMem->s.n ); + Release(pMem); + *pMem = *pTos; + if( pMem->flags & MEM_Dyn ){ + if( pOp->p2 ){ + pTos->flags = MEM_Null; + }else{ + pMem->z = sqliteMallocRaw( pMem->n ); if( pMem->z==0 ) goto no_mem; - memcpy(pMem->z, zStack[tos], pMem->s.n); - pMem->s.flags |= STK_Dyn; - pMem->s.flags &= ~(STK_Static|STK_Ephem); + memcpy(pMem->z, pTos->z, pMem->n); } - }else{ - pMem->z = pMem->s.z; + }else if( pMem->flags & MEM_Short ){ + pMem->z = pMem->zShort; } - if( zOld ) sqliteFree(zOld); if( pOp->p2 ){ - zStack[tos] = 0; - aStack[tos].flags = 0; - POPSTACK; + Release(pTos); + pTos--; } break; } @@ -4322,14 +4356,13 @@ case OP_MemStore: { ** value pushed onto the stack will change too. */ case OP_MemLoad: { - int tos = ++p->tos; int i = pOp->p1; - VERIFY( if( i<0 || i>=p->nMem ) goto bad_instruction; ) - memcpy(&aStack[tos], &p->aMem[i].s, sizeof(aStack[tos])-NBFS);; - if( aStack[tos].flags & STK_Str ){ - zStack[tos] = p->aMem[i].z; - aStack[tos].flags |= STK_Ephem; - aStack[tos].flags &= ~(STK_Dyn|STK_Static); + assert( i>=0 && i<p->nMem ); + pTos++; + memcpy(pTos, &p->aMem[i], sizeof(pTos[0])-NBFS);; + if( pTos->flags & MEM_Str ){ + pTos->flags |= MEM_Ephem; + pTos->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short); } break; } @@ -4346,11 +4379,11 @@ case OP_MemLoad: { case OP_MemIncr: { int i = pOp->p1; Mem *pMem; - VERIFY( if( i<0 || i>=p->nMem ) goto bad_instruction; ) + assert( i>=0 && i<p->nMem ); pMem = &p->aMem[i]; - VERIFY( if( pMem->s.flags != STK_Int ) goto bad_instruction; ) - pMem->s.i++; - if( pOp->p2>0 && pMem->s.i>0 ){ + assert( pMem->flags==MEM_Int ); + pMem->i++; + if( pOp->p2>0 && pMem->i>0 ){ pc = pOp->p2 - 1; } break; @@ -4377,7 +4410,7 @@ case OP_AggReset: { */ case OP_AggInit: { int i = pOp->p2; - VERIFY( if( i<0 || i>=p->agg.nMem ) goto bad_instruction; ) + assert( i>=0 && i<p->agg.nMem ); p->agg.apFunc[i] = (FuncDef*)pOp->p3; break; } @@ -4396,32 +4429,35 @@ case OP_AggInit: { case OP_AggFunc: { int n = pOp->p2; int i; - Mem *pMem; + Mem *pMem, *pRec; + char **azArgv = p->zArgv; sqlite_func ctx; - VERIFY( if( n<0 ) goto bad_instruction; ) - VERIFY( if( p->tos+1<n ) goto not_enough_stack; ) - VERIFY( if( aStack[p->tos].flags!=STK_Int ) goto bad_instruction; ) - for(i=p->tos-n; i<p->tos; i++){ - if( aStack[i].flags & STK_Null ){ - zStack[i] = 0; + assert( n>=0 ); + assert( pTos->flags==MEM_Int ); + pRec = &pTos[-n]; + assert( pRec>=p->aStack ); + for(i=0; i<n; i++, pRec++){ + if( pRec->flags & MEM_Null ){ + azArgv[i] = 0; }else{ - Stringify(p, i); + Stringify(pRec); + azArgv[i] = pRec->z; } } - i = aStack[p->tos].i; - VERIFY( if( i<0 || i>=p->agg.nMem ) goto bad_instruction; ) + i = pTos->i; + assert( i>=0 && i<p->agg.nMem ); ctx.pFunc = (FuncDef*)pOp->p3; pMem = &p->agg.pCurrent->aMem[i]; - ctx.z = pMem->s.z; + ctx.s.z = pMem->zShort; /* Space used for small aggregate contexts */ ctx.pAgg = pMem->z; - ctx.cnt = ++pMem->s.i; + ctx.cnt = ++pMem->i; ctx.isError = 0; ctx.isStep = 1; - (ctx.pFunc->xStep)(&ctx, n, (const char**)&zStack[p->tos-n]); + (ctx.pFunc->xStep)(&ctx, n, (const char**)azArgv); pMem->z = ctx.pAgg; - pMem->s.flags = STK_AggCtx; - sqliteVdbePopStack(p, n+1); + pMem->flags = MEM_AggCtx; + popStack(&pTos, n+1); if( ctx.isError ){ rc = SQLITE_ERROR; } @@ -4443,15 +4479,14 @@ case OP_AggFunc: { ** in between an AggNext and an AggReset. */ case OP_AggFocus: { - int tos = p->tos; AggElem *pElem; char *zKey; int nKey; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - Stringify(p, tos); - zKey = zStack[tos]; - nKey = aStack[tos].n; + assert( pTos>=p->aStack ); + Stringify(pTos); + zKey = pTos->z; + nKey = pTos->n; pElem = sqliteHashFind(&p->agg.hash, zKey, nKey); if( pElem ){ p->agg.pCurrent = pElem; @@ -4460,7 +4495,8 @@ case OP_AggFocus: { AggInsert(&p->agg, zKey, nKey); if( sqlite_malloc_failed ) goto no_mem; } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -4471,32 +4507,22 @@ case OP_AggFocus: { */ case OP_AggSet: { AggElem *pFocus = AggInFocus(p->agg); + Mem *pMem; int i = pOp->p2; - int tos = p->tos; - VERIFY( if( tos<0 ) goto not_enough_stack; ) + assert( pTos>=p->aStack ); if( pFocus==0 ) goto no_mem; - if( VERIFY( i>=0 && ) i<p->agg.nMem ){ - Mem *pMem = &pFocus->aMem[i]; - char *zOld; - if( pMem->s.flags & STK_Dyn ){ - zOld = pMem->z; - }else{ - zOld = 0; - } - Deephemeralize(p, tos); - pMem->s = aStack[tos]; - if( pMem->s.flags & STK_Dyn ){ - pMem->z = zStack[tos]; - zStack[tos] = 0; - aStack[tos].flags = 0; - }else if( pMem->s.flags & (STK_Static|STK_AggCtx) ){ - pMem->z = zStack[tos]; - }else if( pMem->s.flags & STK_Str ){ - pMem->z = pMem->s.z; - } - if( zOld ) sqliteFree(zOld); - } - POPSTACK; + assert( i>=0 && i<p->agg.nMem ); + Deephemeralize(pTos); + pMem = &pFocus->aMem[i]; + Release(pMem); + *pMem = *pTos; + if( pMem->flags & MEM_Dyn ){ + pTos->flags = MEM_Null; + }else if( pMem->flags & MEM_Short ){ + pMem->z = pMem->zShort; + } + Release(pTos); + pTos--; break; } @@ -4508,15 +4534,16 @@ case OP_AggSet: { */ case OP_AggGet: { AggElem *pFocus = AggInFocus(p->agg); + Mem *pMem; int i = pOp->p2; - int tos = ++p->tos; if( pFocus==0 ) goto no_mem; - if( VERIFY( i>=0 && ) i<p->agg.nMem ){ - Mem *pMem = &pFocus->aMem[i]; - aStack[tos] = pMem->s; - zStack[tos] = pMem->z; - aStack[tos].flags &= ~STK_Dyn; - aStack[tos].flags |= STK_Ephem; + assert( i>=0 && i<p->agg.nMem ); + pTos++; + pMem = &pFocus->aMem[i]; + *pTos = *pMem; + if( pTos->flags & MEM_Str ){ + pTos->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short); + pTos->flags |= MEM_Ephem; } break; } @@ -4552,22 +4579,20 @@ case OP_AggNext: { int freeCtx; if( p->agg.apFunc[i]==0 ) continue; if( p->agg.apFunc[i]->xFinalize==0 ) continue; - ctx.s.flags = STK_Null; - ctx.z = 0; + ctx.s.flags = MEM_Null; + ctx.s.z = aMem[i].zShort; ctx.pAgg = (void*)aMem[i].z; - freeCtx = aMem[i].z && aMem[i].z!=aMem[i].s.z; - ctx.cnt = aMem[i].s.i; + freeCtx = aMem[i].z && aMem[i].z!=aMem[i].zShort; + ctx.cnt = aMem[i].i; ctx.isStep = 0; ctx.pFunc = p->agg.apFunc[i]; (*p->agg.apFunc[i]->xFinalize)(&ctx); if( freeCtx ){ sqliteFree( aMem[i].z ); } - aMem[i].s = ctx.s; - aMem[i].z = ctx.z; - if( (aMem[i].s.flags & STK_Str) && - (aMem[i].s.flags & (STK_Dyn|STK_Static|STK_Ephem))==0 ){ - aMem[i].z = aMem[i].s.z; + aMem[i] = ctx.s; + if( aMem[i].flags & MEM_Short ){ + aMem[i].z = aMem[i].zShort; } } } @@ -4595,11 +4620,11 @@ case OP_SetInsert: { if( pOp->p3 ){ sqliteHashInsert(&p->aSet[i].hash, pOp->p3, strlen(pOp->p3)+1, p); }else{ - int tos = p->tos; - if( tos<0 ) goto not_enough_stack; - Stringify(p, tos); - sqliteHashInsert(&p->aSet[i].hash, zStack[tos], aStack[tos].n, p); - POPSTACK; + assert( pTos>=p->aStack ); + Stringify(pTos); + sqliteHashInsert(&p->aSet[i].hash, pTos->z, pTos->n, p); + Release(pTos); + pTos--; } if( sqlite_malloc_failed ) goto no_mem; break; @@ -4613,14 +4638,13 @@ case OP_SetInsert: { */ case OP_SetFound: { int i = pOp->p1; - int tos = p->tos; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - Stringify(p, tos); - if( i>=0 && i<p->nSet && - sqliteHashFind(&p->aSet[i].hash, zStack[tos], aStack[tos].n)){ + assert( pTos>=p->aStack ); + Stringify(pTos); + if( i>=0 && i<p->nSet && sqliteHashFind(&p->aSet[i].hash, pTos->z, pTos->n)){ pc = pOp->p2 - 1; } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -4632,14 +4656,14 @@ case OP_SetFound: { */ case OP_SetNotFound: { int i = pOp->p1; - int tos = p->tos; - VERIFY( if( tos<0 ) goto not_enough_stack; ) - Stringify(p, tos); + assert( pTos>=p->aStack ); + Stringify(pTos); if( i<0 || i>=p->nSet || - sqliteHashFind(&p->aSet[i].hash, zStack[tos], aStack[tos].n)==0 ){ + sqliteHashFind(&p->aSet[i].hash, pTos->z, pTos->n)==0 ){ pc = pOp->p2 - 1; } - POPSTACK; + Release(pTos); + pTos--; break; } @@ -4658,7 +4682,6 @@ case OP_SetNotFound: { case OP_SetFirst: case OP_SetNext: { Set *pSet; - int tos; CHECK_FOR_INTERRUPT; if( pOp->p1<0 || pOp->p1>=p->nSet ){ if( pOp->opcode==OP_SetFirst ) pc = pOp->p2 - 1; @@ -4672,7 +4695,7 @@ case OP_SetNext: { break; } }else{ - VERIFY( if( pSet->prev==0 ) goto bad_instruction; ) + assert( pSet->prev ); pSet->prev = sqliteHashNext(pSet->prev); if( pSet->prev==0 ){ break; @@ -4680,10 +4703,10 @@ case OP_SetNext: { pc = pOp->p2 - 1; } } - tos = ++p->tos; - zStack[tos] = sqliteHashKey(pSet->prev); - aStack[tos].n = sqliteHashKeysize(pSet->prev); - aStack[tos].flags = STK_Str | STK_Ephem; + pTos++; + pTos->z = sqliteHashKey(pSet->prev); + pTos->n = sqliteHashKeysize(pSet->prev); + pTos->flags = MEM_Str | MEM_Ephem; break; } @@ -4700,6 +4723,36 @@ case OP_Vacuum: { break; } +/* Opcode: StackDepth * * * +** +** Push an integer onto the stack which is the depth of the stack prior +** to that integer being pushed. +*/ +case OP_StackDepth: { + int depth = (&pTos[1]) - p->aStack; + pTos++; + pTos->i = depth; + pTos->flags = MEM_Int; + break; +} + +/* Opcode: StackReset * * * +** +** Pop a single integer off of the stack. Then pop the stack +** as many times as necessary to get the depth of the stack down +** to the value of the integer that was popped. +*/ +case OP_StackReset: { + int depth, goal; + assert( pTos>=p->aStack ); + Integerify(pTos); + goal = pTos->i; + depth = (&pTos[1]) - p->aStack; + assert( goal<depth ); + popStack(&pTos, depth-goal); + break; +} + /* An other opcode is illegal... */ default: { @@ -4735,43 +4788,61 @@ default: { ** the evaluator loop. So we can leave it out when NDEBUG is defined. */ #ifndef NDEBUG + /* Sanity checking on the top element of the stack */ + if( pTos>=p->aStack ){ + assert( pTos->flags!=0 ); /* Must define some type */ + if( pTos->flags & MEM_Str ){ + int x = pTos->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short); + assert( x!=0 ); /* Strings must define a string subtype */ + assert( (x & (x-1))==0 ); /* Only one string subtype can be defined */ + assert( pTos->z!=0 ); /* Strings must have a value */ + /* Mem.z points to Mem.zShort iff the subtype is MEM_Short */ + assert( (pTos->flags & MEM_Short)==0 || pTos->z==pTos->zShort ); + assert( (pTos->flags & MEM_Short)!=0 || pTos->z!=pTos->zShort ); + }else{ + /* Cannot define a string subtype for non-string objects */ + assert( (pTos->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 ); + } + /* MEM_Null excludes all other types */ + assert( pTos->flags==MEM_Null || (pTos->flags&MEM_Null)==0 ); + } if( pc<-1 || pc>=p->nOp ){ sqliteSetString(&p->zErrMsg, "jump destination out of range", (char*)0); rc = SQLITE_INTERNAL; } - if( p->trace && p->tos>=0 ){ + if( p->trace && pTos>=p->aStack ){ int i; fprintf(p->trace, "Stack:"); - for(i=p->tos; i>=0 && i>p->tos-5; i--){ - if( aStack[i].flags & STK_Null ){ + for(i=0; i>-5 && &pTos[i]>=p->aStack; i--){ + if( pTos[i].flags & MEM_Null ){ fprintf(p->trace, " NULL"); - }else if( (aStack[i].flags & (STK_Int|STK_Str))==(STK_Int|STK_Str) ){ - fprintf(p->trace, " si:%d", aStack[i].i); - }else if( aStack[i].flags & STK_Int ){ - fprintf(p->trace, " i:%d", aStack[i].i); - }else if( aStack[i].flags & STK_Real ){ - fprintf(p->trace, " r:%g", aStack[i].r); - }else if( aStack[i].flags & STK_Str ){ + }else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ + fprintf(p->trace, " si:%d", pTos[i].i); + }else if( pTos[i].flags & MEM_Int ){ + fprintf(p->trace, " i:%d", pTos[i].i); + }else if( pTos[i].flags & MEM_Real ){ + fprintf(p->trace, " r:%g", pTos[i].r); + }else if( pTos[i].flags & MEM_Str ){ int j, k; char zBuf[100]; zBuf[0] = ' '; - if( aStack[i].flags & STK_Dyn ){ + if( pTos[i].flags & MEM_Dyn ){ zBuf[1] = 'z'; - assert( (aStack[i].flags & (STK_Static|STK_Ephem))==0 ); - }else if( aStack[i].flags & STK_Static ){ + assert( (pTos[i].flags & (MEM_Static|MEM_Ephem))==0 ); + }else if( pTos[i].flags & MEM_Static ){ zBuf[1] = 't'; - assert( (aStack[i].flags & (STK_Dyn|STK_Ephem))==0 ); - }else if( aStack[i].flags & STK_Ephem ){ + assert( (pTos[i].flags & (MEM_Dyn|MEM_Ephem))==0 ); + }else if( pTos[i].flags & MEM_Ephem ){ zBuf[1] = 'e'; - assert( (aStack[i].flags & (STK_Static|STK_Dyn))==0 ); + assert( (pTos[i].flags & (MEM_Static|MEM_Dyn))==0 ); }else{ zBuf[1] = 's'; } zBuf[2] = '['; k = 3; - for(j=0; j<20 && j<aStack[i].n; j++){ - int c = zStack[i][j]; - if( c==0 && j==aStack[i].n-1 ) break; + for(j=0; j<20 && j<pTos[i].n; j++){ + int c = pTos[i].z[j]; + if( c==0 && j==pTos[i].n-1 ) break; if( isprint(c) && !isspace(c) ){ zBuf[k++] = c; }else{ @@ -4794,6 +4865,7 @@ default: { /* If we reach this point, it means that execution is finished. */ vdbe_halt: + CHECK_FOR_INTERRUPT if( rc ){ p->rc = rc; rc = SQLITE_ERROR; @@ -4801,6 +4873,7 @@ vdbe_halt: rc = SQLITE_DONE; } p->magic = VDBE_MAGIC_HALT; + p->pTos = pTos; return rc; /* Jump to here if a malloc() fails. It's hard to get a malloc() @@ -4822,6 +4895,7 @@ abort_due_to_misuse: */ abort_due_to_error: if( p->zErrMsg==0 ){ + if( sqlite_malloc_failed ) rc = SQLITE_NOMEM; sqliteSetString(&p->zErrMsg, sqlite_error_string(rc), (char*)0); } goto vdbe_halt; @@ -4839,23 +4913,4 @@ abort_due_to_interrupt: } sqliteSetString(&p->zErrMsg, sqlite_error_string(rc), (char*)0); goto vdbe_halt; - - /* Jump to here if a operator is encountered that requires more stack - ** operands than are currently available on the stack. - */ -not_enough_stack: - sqlite_snprintf(sizeof(zBuf),zBuf,"%d",pc); - sqliteSetString(&p->zErrMsg, "too few operands on stack at ", zBuf, (char*)0); - rc = SQLITE_INTERNAL; - goto vdbe_halt; - - /* Jump here if an illegal or illformed instruction is executed. - */ -VERIFY( -bad_instruction: - sqlite_snprintf(sizeof(zBuf),zBuf,"%d",pc); - sqliteSetString(&p->zErrMsg, "illegal operation at ", zBuf, (char*)0); - rc = SQLITE_INTERNAL; - goto vdbe_halt; -) } diff --git a/ext/sqlite/libsqlite/src/vdbe.h b/ext/sqlite/libsqlite/src/vdbe.h index d56fe49014..6428598075 100644 --- a/ext/sqlite/libsqlite/src/vdbe.h +++ b/ext/sqlite/libsqlite/src/vdbe.h @@ -34,7 +34,7 @@ typedef struct Vdbe Vdbe; ** as an instance of the following structure: */ struct VdbeOp { - int opcode; /* What operation to perform */ + u8 opcode; /* What operation to perform */ int p1; /* First operand */ int p2; /* Second parameter (often the jump destination) */ char *p3; /* Third parameter */ @@ -47,6 +47,18 @@ struct VdbeOp { typedef struct VdbeOp VdbeOp; /* +** A smaller version of VdbeOp used for the VdbeAddOpList() function because +** it takes up less space. +*/ +struct VdbeOpList { + u8 opcode; /* What operation to perform */ + signed char p1; /* First operand */ + short int p2; /* Second parameter (often the jump destination) */ + char *p3; /* Third parameter */ +}; +typedef struct VdbeOpList VdbeOpList; + +/* ** Allowed values of VdbeOp.p3type */ #define P3_NOTUSED 0 /* The P3 parameter is not used */ @@ -75,7 +87,9 @@ typedef struct VdbeOp VdbeOp; Vdbe *sqliteVdbeCreate(sqlite*); void sqliteVdbeCreateCallback(Vdbe*, int*); int sqliteVdbeAddOp(Vdbe*,int,int,int); -int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOp const *aOp); +int sqliteVdbeOp3(Vdbe*,int,int,int,const char *zP3,int); +int sqliteVdbeCode(Vdbe*,...); +int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); void sqliteVdbeChangeP1(Vdbe*, int addr, int P1); void sqliteVdbeChangeP2(Vdbe*, int addr, int P2); void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N); @@ -84,7 +98,7 @@ int sqliteVdbeFindOp(Vdbe*, int, int); VdbeOp *sqliteVdbeGetOp(Vdbe*, int); int sqliteVdbeMakeLabel(Vdbe*); void sqliteVdbeDelete(Vdbe*); -void sqliteVdbeMakeReady(Vdbe*,int,sqlite_callback,void*,int); +void sqliteVdbeMakeReady(Vdbe*,int,int); int sqliteVdbeExec(Vdbe*); int sqliteVdbeList(Vdbe*); int sqliteVdbeFinalize(Vdbe*,char**); diff --git a/ext/sqlite/libsqlite/src/vdbeInt.h b/ext/sqlite/libsqlite/src/vdbeInt.h index d58523ad28..79b6b51a58 100644 --- a/ext/sqlite/libsqlite/src/vdbeInt.h +++ b/ext/sqlite/libsqlite/src/vdbeInt.h @@ -106,47 +106,36 @@ struct Sorter { #define NBFS 32 /* -** A single level of the stack is an instance of the following -** structure. Except, string values are stored on a separate -** list of of pointers to character. The reason for storing -** strings separately is so that they can be easily passed -** to the callback function. -*/ -struct Stack { - int i; /* Integer value */ - int n; /* Number of characters in string value, including '\0' */ - int flags; /* Some combination of STK_Null, STK_Str, STK_Dyn, etc. */ - double r; /* Real value */ - char z[NBFS]; /* Space for short strings */ -}; -typedef struct Stack Stack; - -/* -** Memory cells use the same structure as the stack except that space -** for an arbitrary string is added. +** A single level of the stack or a single memory cell +** is an instance of the following structure. */ struct Mem { - Stack s; /* All values of the memory cell besides string */ - char *z; /* String value for this memory cell */ + int i; /* Integer value */ + int n; /* Number of characters in string value, including '\0' */ + int flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ + double r; /* Real value */ + char *z; /* String value */ + char zShort[NBFS]; /* Space for short strings */ }; typedef struct Mem Mem; /* -** Allowed values for Stack.flags +** Allowed values for Mem.flags */ -#define STK_Null 0x0001 /* Value is NULL */ -#define STK_Str 0x0002 /* Value is a string */ -#define STK_Int 0x0004 /* Value is an integer */ -#define STK_Real 0x0008 /* Value is a real number */ -#define STK_Dyn 0x0010 /* Need to call sqliteFree() on zStack[] */ -#define STK_Static 0x0020 /* zStack[] points to a static string */ -#define STK_Ephem 0x0040 /* zStack[] points to an ephemeral string */ +#define MEM_Null 0x0001 /* Value is NULL */ +#define MEM_Str 0x0002 /* Value is a string */ +#define MEM_Int 0x0004 /* Value is an integer */ +#define MEM_Real 0x0008 /* Value is a real number */ +#define MEM_Dyn 0x0010 /* Need to call sqliteFree() on Mem.z */ +#define MEM_Static 0x0020 /* Mem.z points to a static string */ +#define MEM_Ephem 0x0040 /* Mem.z points to an ephemeral string */ +#define MEM_Short 0x0080 /* Mem.z points to Mem.zShort */ -/* The following STK_ value appears only in AggElem.aMem.s.flag fields. +/* The following MEM_ value appears only in AggElem.aMem.s.flag fields. ** It indicates that the corresponding AggElem.aMem.z points to a ** aggregate function context that needs to be finalized. */ -#define STK_AggCtx 0x0040 /* zStack[] points to an agg function context */ +#define MEM_AggCtx 0x0100 /* Mem.z points to an agg function context */ /* ** The "context" argument for a installable function. A pointer to an @@ -159,12 +148,11 @@ typedef struct Mem Mem; ** structure are known. ** ** This structure is defined inside of vdbe.c because it uses substructures -** (Stack) which are only defined there. +** (Mem) which are only defined there. */ struct sqlite_func { FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ - Stack s; /* Small strings, ints, and double values go here */ - char *z; /* Space for holding dynamic string results */ + Mem s; /* The return value is stored here */ void *pAgg; /* Aggregate context */ u8 isError; /* Set to true for an error */ u8 isStep; /* Current in the step function */ @@ -220,6 +208,19 @@ struct Keylist { }; /* +** A Context stores the last insert rowid, the last statement change count, +** and the current statement change count (i.e. changes since last statement). +** Elements of Context structure type make up the ContextStack, which is +** updated by the ContextPush and ContextPop opcodes (used by triggers) +*/ +typedef struct Context Context; +struct Context { + int lastRowid; /* Last insert rowid (from db->lastRowid) */ + int lsChange; /* Last statement change count (from db->lsChange) */ + int csChange; /* Current statement change count (from db->csChange) */ +}; + +/* ** An instance of the virtual machine. This structure contains the complete ** state of the virtual machine. ** @@ -236,9 +237,9 @@ struct Vdbe { int nLabel; /* Number of labels used */ int nLabelAlloc; /* Number of slots allocated in aLabel[] */ int *aLabel; /* Space to hold the labels */ - int tos; /* Index of top of stack */ - Stack *aStack; /* The operand stack, except string values */ - char **zStack; /* Text or binary values of the stack */ + Mem *aStack; /* The operand stack, except string values */ + Mem *pTos; /* Top entry in the operand stack */ + char **zArgv; /* Text values used by the callback */ char **azColName; /* Becomes the 4th parameter to callbacks */ int nCursor; /* Number of slots in aCsr[] */ Cursor *aCsr; /* One element of this array for each open cursor */ @@ -262,6 +263,8 @@ struct Vdbe { Keylist *pList; /* A list of ROWIDs */ int keylistStackDepth; /* The size of the "keylist" stack */ Keylist **keylistStack; /* The stack used by opcodes ListPush & ListPop */ + int contextStackDepth; /* The size of the "context" stack */ + Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/ int pc; /* The program counter */ int rc; /* Value to return */ unsigned uniqueCnt; /* Used by OP_MakeRecord when P2!=0 */ @@ -271,9 +274,7 @@ struct Vdbe { int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */ int returnDepth; /* Next unused element in returnStack[] */ int nResColumn; /* Number of columns in one row of the result set */ - char **azResColumn; /* Values for one row of result */ - int (*xCallback)(void*,int,char**,char**); /* Callback for SELECT results */ - void *pCbArg; /* First argument to xCallback() */ + char **azResColumn; /* Values for one row of result */ int popStack; /* Pop the stack this much on entry to VdbeExec() */ char *zErrMsg; /* Error message written here */ u8 explain; /* True if EXPLAIN present on SQL command */ @@ -288,16 +289,6 @@ struct Vdbe { #define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */ /* -** Here is a macro to handle the common case of popping the stack -** once. This macro only works from within the sqliteVdbeExec() -** function. -*/ -#define POPSTACK \ - assert(p->tos>=0); \ - if( aStack[p->tos].flags & STK_Dyn ) sqliteFree(zStack[p->tos]); \ - p->tos--; - -/* ** Function prototypes */ void sqliteVdbeCleanupCursor(Cursor*); diff --git a/ext/sqlite/libsqlite/src/vdbeaux.c b/ext/sqlite/libsqlite/src/vdbeaux.c index 6249a29f0b..c206bad4ab 100644 --- a/ext/sqlite/libsqlite/src/vdbeaux.c +++ b/ext/sqlite/libsqlite/src/vdbeaux.c @@ -73,6 +73,7 @@ void sqliteVdbeTrace(Vdbe *p, FILE *trace){ */ int sqliteVdbeAddOp(Vdbe *p, int op, int p1, int p2){ int i; + VdbeOp *pOp; i = p->nOp; p->nOp++; @@ -89,14 +90,15 @@ int sqliteVdbeAddOp(Vdbe *p, int op, int p1, int p2){ p->aOp = aNew; memset(&p->aOp[oldSize], 0, (p->nOpAlloc-oldSize)*sizeof(Op)); } - p->aOp[i].opcode = op; - p->aOp[i].p1 = p1; + pOp = &p->aOp[i]; + pOp->opcode = op; + pOp->p1 = p1; if( p2<0 && (-1-p2)<p->nLabel && p->aLabel[-1-p2]>=0 ){ p2 = p->aLabel[-1-p2]; } - p->aOp[i].p2 = p2; - p->aOp[i].p3 = 0; - p->aOp[i].p3type = P3_NOTUSED; + pOp->p2 = p2; + pOp->p3 = 0; + pOp->p3type = P3_NOTUSED; #ifndef NDEBUG if( sqlite_vdbe_addop_trace ) sqliteVdbePrintOp(0, i, &p->aOp[i]); #endif @@ -104,6 +106,35 @@ int sqliteVdbeAddOp(Vdbe *p, int op, int p1, int p2){ } /* +** Add an opcode that includes the p3 value. +*/ +int sqliteVdbeOp3(Vdbe *p, int op, int p1, int p2, const char *zP3, int p3type){ + int addr = sqliteVdbeAddOp(p, op, p1, p2); + sqliteVdbeChangeP3(p, addr, zP3, p3type); + return addr; +} + +/* +** Add multiple opcodes. The list is terminated by an opcode of 0. +*/ +int sqliteVdbeCode(Vdbe *p, ...){ + int addr; + va_list ap; + int opcode, p1, p2; + va_start(ap, p); + addr = p->nOp; + while( (opcode = va_arg(ap,int))!=0 ){ + p1 = va_arg(ap,int); + p2 = va_arg(ap,int); + sqliteVdbeAddOp(p, opcode, p1, p2); + } + va_end(ap); + return addr; +} + + + +/* ** Create a new symbolic label for an instruction that has yet to be ** coded. The symbolic label is really just a negative number. The ** label can be used as the P2 value of an operation. Later, when @@ -167,7 +198,7 @@ int sqliteVdbeCurrentAddr(Vdbe *p){ ** Add a whole list of operations to the operation stack. Return the ** address of the first operation added. */ -int sqliteVdbeAddOpList(Vdbe *p, int nOp, VdbeOp const *aOp){ +int sqliteVdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ int addr; assert( p->magic==VDBE_MAGIC_INIT ); if( p->nOp + nOp >= p->nOpAlloc ){ @@ -185,11 +216,15 @@ int sqliteVdbeAddOpList(Vdbe *p, int nOp, VdbeOp const *aOp){ addr = p->nOp; if( nOp>0 ){ int i; - for(i=0; i<nOp; i++){ - int p2 = aOp[i].p2; - p->aOp[i+addr] = aOp[i]; - if( p2<0 ) p->aOp[i+addr].p2 = addr + ADDR(p2); - p->aOp[i+addr].p3type = aOp[i].p3 ? P3_STATIC : P3_NOTUSED; + VdbeOpList const *pIn = aOp; + for(i=0; i<nOp; i++, pIn++){ + int p2 = pIn->p2; + VdbeOp *pOut = &p->aOp[i+addr]; + pOut->opcode = pIn->opcode; + pOut->p1 = pIn->p1; + pOut->p2 = p2<0 ? addr + ADDR(p2) : p2; + pOut->p3 = pIn->p3; + pOut->p3type = pIn->p3 ? P3_STATIC : P3_NOTUSED; #ifndef NDEBUG if( sqlite_vdbe_addop_trace ){ sqliteVdbePrintOp(0, i+addr, &p->aOp[i+addr]); @@ -280,7 +315,11 @@ void sqliteVdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ void sqliteVdbeDequoteP3(Vdbe *p, int addr){ Op *pOp; assert( p->magic==VDBE_MAGIC_INIT ); - if( p->aOp==0 || addr<0 || addr>=p->nOp ) return; + if( p->aOp==0 ) return; + if( addr<0 || addr>=p->nOp ){ + addr = p->nOp - 1; + if( addr<0 ) return; + } pOp = &p->aOp[addr]; if( pOp->p3==0 || pOp->p3[0]==0 ) return; if( pOp->p3type==P3_POINTER ) return; @@ -371,48 +410,48 @@ VdbeOp *sqliteVdbeGetOp(Vdbe *p, int addr){ */ char *sqlite_set_result_string(sqlite_func *p, const char *zResult, int n){ assert( !p->isStep ); - if( p->s.flags & STK_Dyn ){ - sqliteFree(p->z); + if( p->s.flags & MEM_Dyn ){ + sqliteFree(p->s.z); } if( zResult==0 ){ - p->s.flags = STK_Null; + p->s.flags = MEM_Null; n = 0; - p->z = 0; + p->s.z = 0; p->s.n = 0; }else{ if( n<0 ) n = strlen(zResult); if( n<NBFS-1 ){ - memcpy(p->s.z, zResult, n); - p->s.z[n] = 0; - p->s.flags = STK_Str; - p->z = p->s.z; + memcpy(p->s.zShort, zResult, n); + p->s.zShort[n] = 0; + p->s.flags = MEM_Str | MEM_Short; + p->s.z = p->s.zShort; }else{ - p->z = sqliteMallocRaw( n+1 ); - if( p->z ){ - memcpy(p->z, zResult, n); - p->z[n] = 0; + p->s.z = sqliteMallocRaw( n+1 ); + if( p->s.z ){ + memcpy(p->s.z, zResult, n); + p->s.z[n] = 0; } - p->s.flags = STK_Str | STK_Dyn; + p->s.flags = MEM_Str | MEM_Dyn; } p->s.n = n+1; } - return p->z; + return p->s.z; } void sqlite_set_result_int(sqlite_func *p, int iResult){ assert( !p->isStep ); - if( p->s.flags & STK_Dyn ){ - sqliteFree(p->z); + if( p->s.flags & MEM_Dyn ){ + sqliteFree(p->s.z); } p->s.i = iResult; - p->s.flags = STK_Int; + p->s.flags = MEM_Int; } void sqlite_set_result_double(sqlite_func *p, double rResult){ assert( !p->isStep ); - if( p->s.flags & STK_Dyn ){ - sqliteFree(p->z); + if( p->s.flags & MEM_Dyn ){ + sqliteFree(p->s.z); } p->s.r = rResult; - p->s.flags = STK_Real; + p->s.flags = MEM_Real; } void sqlite_set_result_error(sqlite_func *p, const char *zMsg, int n){ assert( !p->isStep ); @@ -442,7 +481,8 @@ void *sqlite_aggregate_context(sqlite_func *p, int nByte){ assert( p && p->pFunc && p->pFunc->xStep ); if( p->pAgg==0 ){ if( nByte<=NBFS ){ - p->pAgg = (void*)p->z; + p->pAgg = (void*)p->s.z; + memset(p->pAgg, 0, nByte); }else{ p->pAgg = sqliteMalloc( nByte ); } @@ -471,7 +511,7 @@ void sqliteVdbePrintOp(FILE *pOut, int pc, Op *pOp){ char *zP3; char zPtr[40]; if( pOp->p3type==P3_POINTER ){ - sprintf(zPtr, "ptr(%#x)", (int)pOp->p3); + sprintf(zPtr, "ptr(%#lx)", (long)pOp->p3); zP3 = zPtr; }else{ zP3 = pOp->p3; @@ -495,6 +535,7 @@ int sqliteVdbeList( ){ sqlite *db = p->db; int i; + int rc = SQLITE_OK; static char *azColumnNames[] = { "addr", "opcode", "p1", "p2", "p3", "int", "text", "int", "int", "text", @@ -504,48 +545,39 @@ int sqliteVdbeList( assert( p->popStack==0 ); assert( p->explain ); p->azColName = azColumnNames; - p->azResColumn = p->zStack; - for(i=0; i<5; i++) p->zStack[i] = p->aStack[i].z; - p->rc = SQLITE_OK; - for(i=p->pc; p->rc==SQLITE_OK && i<p->nOp; i++){ - if( db->flags & SQLITE_Interrupt ){ - db->flags &= ~SQLITE_Interrupt; - if( db->magic!=SQLITE_MAGIC_BUSY ){ - p->rc = SQLITE_MISUSE; - }else{ - p->rc = SQLITE_INTERRUPT; - } - sqliteSetString(&p->zErrMsg, sqlite_error_string(p->rc), (char*)0); - break; + p->azResColumn = p->zArgv; + for(i=0; i<5; i++) p->zArgv[i] = p->aStack[i].zShort; + i = p->pc; + if( i>=p->nOp ){ + p->rc = SQLITE_OK; + rc = SQLITE_DONE; + }else if( db->flags & SQLITE_Interrupt ){ + db->flags &= ~SQLITE_Interrupt; + if( db->magic!=SQLITE_MAGIC_BUSY ){ + p->rc = SQLITE_MISUSE; + }else{ + p->rc = SQLITE_INTERRUPT; } - sprintf(p->zStack[0],"%d",i); - sprintf(p->zStack[2],"%d", p->aOp[i].p1); - sprintf(p->zStack[3],"%d", p->aOp[i].p2); + rc = SQLITE_ERROR; + sqliteSetString(&p->zErrMsg, sqlite_error_string(p->rc), (char*)0); + }else{ + sprintf(p->zArgv[0],"%d",i); + sprintf(p->zArgv[2],"%d", p->aOp[i].p1); + sprintf(p->zArgv[3],"%d", p->aOp[i].p2); if( p->aOp[i].p3type==P3_POINTER ){ - sprintf(p->aStack[4].z, "ptr(%#x)", (int)p->aOp[i].p3); - p->zStack[4] = p->aStack[4].z; + sprintf(p->aStack[4].zShort, "ptr(%#lx)", (long)p->aOp[i].p3); + p->zArgv[4] = p->aStack[4].zShort; }else{ - p->zStack[4] = p->aOp[i].p3; - } - p->zStack[1] = sqliteOpcodeNames[p->aOp[i].opcode]; - if( p->xCallback==0 ){ - p->pc = i+1; - p->azResColumn = p->zStack; - p->nResColumn = 5; - return SQLITE_ROW; - } - if( sqliteSafetyOff(db) ){ - p->rc = SQLITE_MISUSE; - break; - } - if( p->xCallback(p->pCbArg, 5, p->zStack, p->azColName) ){ - p->rc = SQLITE_ABORT; - } - if( sqliteSafetyOn(db) ){ - p->rc = SQLITE_MISUSE; + p->zArgv[4] = p->aOp[i].p3; } + p->zArgv[1] = sqliteOpcodeNames[p->aOp[i].opcode]; + p->pc = i+1; + p->azResColumn = p->zArgv; + p->nResColumn = 5; + p->rc = SQLITE_OK; + rc = SQLITE_ROW; } - return p->rc==SQLITE_OK ? SQLITE_DONE : SQLITE_ERROR; + return rc; } /* @@ -553,20 +585,10 @@ int sqliteVdbeList( ** as allocating stack space and initializing the program counter. ** After the VDBE has be prepped, it can be executed by one or more ** calls to sqliteVdbeExec(). -** -** The behavior of sqliteVdbeExec() is influenced by the parameters to -** this routine. If xCallback is NULL, then sqliteVdbeExec() will return -** with SQLITE_ROW whenever there is a row of the result set ready -** to be delivered. p->azResColumn will point to the row and -** p->nResColumn gives the number of columns in the row. If xCallback -** is not NULL, then the xCallback() routine is invoked to process each -** row in the result set. */ void sqliteVdbeMakeReady( Vdbe *p, /* The VDBE */ int nVar, /* Number of '?' see in the SQL statement */ - sqlite_callback xCallback, /* Result callback */ - void *pCallbackArg, /* 1st argument to xCallback() */ int isExplain /* True if the EXPLAIN keywords is present */ ){ int n; @@ -592,11 +614,11 @@ void sqliteVdbeMakeReady( assert( nVar>=0 ); n = isExplain ? 10 : p->nOp; p->aStack = sqliteMalloc( - n*(sizeof(p->aStack[0]) + 2*sizeof(char*)) /* aStack and zStack */ - + p->nVar*(sizeof(char*)+sizeof(int)+1) /* azVar, anVar, abVar */ + n*(sizeof(p->aStack[0]) + 2*sizeof(char*)) /* aStack and zArgv */ + + p->nVar*(sizeof(char*)+sizeof(int)+1) /* azVar, anVar, abVar */ ); - p->zStack = (char**)&p->aStack[n]; - p->azColName = (char**)&p->zStack[n]; + p->zArgv = (char**)&p->aStack[n]; + p->azColName = (char**)&p->zArgv[n]; p->azVar = (char**)&p->azColName[n]; p->anVar = (int*)&p->azVar[p->nVar]; p->abVar = (u8*)&p->anVar[p->nVar]; @@ -609,15 +631,13 @@ void sqliteVdbeMakeReady( p->trace = stdout; } #endif - p->tos = -1; + p->pTos = &p->aStack[-1]; p->pc = 0; p->rc = SQLITE_OK; p->uniqueCnt = 0; p->returnDepth = 0; p->errorAction = OE_Abort; p->undoTransOnError = 0; - p->xCallback = xCallback; - p->pCbArg = pCallbackArg; p->popStack = 0; p->explain |= isExplain; p->magic = VDBE_MAGIC_RUN; @@ -647,25 +667,6 @@ void sqliteVdbeSorterReset(Vdbe *p){ } /* -** Pop the stack N times. Free any memory associated with the -** popped stack elements. -*/ -void sqliteVdbePopStack(Vdbe *p, int N){ - assert( N>=0 ); - if( p->zStack==0 ) return; - assert( p->aStack || sqlite_malloc_failed ); - if( p->aStack==0 ) return; - while( N-- > 0 ){ - if( p->aStack[p->tos].flags & STK_Dyn ){ - sqliteFree(p->zStack[p->tos]); - } - p->aStack[p->tos].flags = 0; - p->zStack[p->tos] = 0; - p->tos--; - } -} - -/* ** Reset an Agg structure. Delete all its contents. ** ** For installable aggregate functions, if the step function has been @@ -682,20 +683,22 @@ void sqliteVdbeAggReset(Agg *pAgg){ assert( pAgg->apFunc!=0 ); for(i=0; i<pAgg->nMem; i++){ Mem *pMem = &pElem->aMem[i]; - if( pAgg->apFunc[i] && (pMem->s.flags & STK_AggCtx)!=0 ){ + if( pAgg->apFunc[i] && (pMem->flags & MEM_AggCtx)!=0 ){ sqlite_func ctx; ctx.pFunc = pAgg->apFunc[i]; - ctx.s.flags = STK_Null; - ctx.z = 0; + ctx.s.flags = MEM_Null; ctx.pAgg = pMem->z; - ctx.cnt = pMem->s.i; + ctx.cnt = pMem->i; ctx.isStep = 0; ctx.isError = 0; (*pAgg->apFunc[i]->xFinalize)(&ctx); - if( pMem->z!=0 && pMem->z!=pMem->s.z ){ + if( pMem->z!=0 && pMem->z!=pMem->zShort ){ sqliteFree(pMem->z); } - }else if( pMem->s.flags & STK_Dyn ){ + if( ctx.s.flags & MEM_Dyn ){ + sqliteFree(ctx.s.z); + } + }else if( pMem->flags & MEM_Dyn ){ sqliteFree(pMem->z); } } @@ -757,11 +760,20 @@ static void closeAllCursors(Vdbe *p){ */ static void Cleanup(Vdbe *p){ int i; - sqliteVdbePopStack(p, p->tos+1); + if( p->aStack ){ + Mem *pTos = p->pTos; + while( pTos>=p->aStack ){ + if( pTos->flags & MEM_Dyn ){ + sqliteFree(pTos->z); + } + pTos--; + } + p->pTos = pTos; + } closeAllCursors(p); if( p->aMem ){ for(i=0; i<p->nMem; i++){ - if( p->aMem[i].s.flags & STK_Dyn ){ + if( p->aMem[i].flags & MEM_Dyn ){ sqliteFree(p->aMem[i].z); } } @@ -806,6 +818,8 @@ static void Cleanup(Vdbe *p){ p->keylistStackDepth = 0; p->keylistStack = 0; } + sqliteFree(p->contextStack); + p->contextStack = 0; sqliteFree(p->zErrMsg); p->zErrMsg = 0; } @@ -832,6 +846,8 @@ int sqliteVdbeReset(Vdbe *p, char **pzErrMsg){ sqliteFree(p->zErrMsg); } p->zErrMsg = 0; + }else if( p->rc ){ + sqliteSetString(pzErrMsg, sqlite_error_string(p->rc), (char*)0); } Cleanup(p); if( p->rc!=SQLITE_OK ){ @@ -870,7 +886,7 @@ int sqliteVdbeReset(Vdbe *p, char **pzErrMsg){ db->aDb[i].inTrans = 1; } } - assert( p->tos<p->pc || sqlite_malloc_failed==1 ); + assert( p->pTos<&p->aStack[p->pc] || sqlite_malloc_failed==1 ); #ifdef VDBE_PROFILE { FILE *out = fopen("vdbe_profile.out", "a"); @@ -915,6 +931,9 @@ int sqliteVdbeFinalize(Vdbe *p, char **pzErrMsg){ if( db->want_to_close && db->pVdbe==0 ){ sqlite_close(db); } + if( rc==SQLITE_SCHEMA ){ + sqliteResetInternalSchema(db, 0); + } return rc; } diff --git a/ext/sqlite/libsqlite/src/where.c b/ext/sqlite/libsqlite/src/where.c index 11358e413c..a3a31a2e84 100644 --- a/ext/sqlite/libsqlite/src/where.c +++ b/ext/sqlite/libsqlite/src/where.c @@ -380,11 +380,8 @@ WhereInfo *sqliteWhereBegin( memset(aExpr, 0, sizeof(aExpr)); nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere); if( nExpr==ARRAYSIZE(aExpr) ){ - char zBuf[50]; - sprintf(zBuf, "%d", (int)ARRAYSIZE(aExpr)-1); - sqliteSetString(&pParse->zErrMsg, "WHERE clause too complex - no more " - "than ", zBuf, " terms allowed", (char*)0); - pParse->nErr++; + sqliteErrorMsg(pParse, "WHERE clause too complex - no more " + "than %d terms allowed", (int)ARRAYSIZE(aExpr)-1); return 0; } @@ -672,18 +669,17 @@ WhereInfo *sqliteWhereBegin( */ for(i=0; i<pTabList->nSrc; i++){ Table *pTab; + Index *pIx; pTab = pTabList->a[i].pTab; if( pTab->isTransient || pTab->pSelect ) continue; sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum); - sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC); + sqliteVdbeOp3(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum, + pTab->zName, P3_STATIC); sqliteCodeVerifySchema(pParse, pTab->iDb); - if( pWInfo->a[i].pIdx!=0 ){ - sqliteVdbeAddOp(v, OP_Integer, pWInfo->a[i].pIdx->iDb, 0); - sqliteVdbeAddOp(v, OP_OpenRead, - pWInfo->a[i].iCur, pWInfo->a[i].pIdx->tnum); - sqliteVdbeChangeP3(v, -1, pWInfo->a[i].pIdx->zName, P3_STATIC); + if( (pIx = pWInfo->a[i].pIdx)!=0 ){ + sqliteVdbeAddOp(v, OP_Integer, pIx->iDb, 0); + sqliteVdbeOp3(v, OP_OpenRead, pWInfo->a[i].iCur, pIx->tnum, pIx->zName,0); } } @@ -855,10 +851,8 @@ WhereInfo *sqliteWhereBegin( }else{ sqliteExprCode(pParse, aExpr[k].p->pLeft); } - sqliteVdbeAddOp(v, OP_IsNumeric, 1, brk); - if( aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT ){ - sqliteVdbeAddOp(v, OP_AddImm, 1, 0); - } + sqliteVdbeAddOp(v, OP_ForceInt, + aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT, brk); sqliteVdbeAddOp(v, OP_MoveTo, iCur, brk); aExpr[k].p = 0; }else{ diff --git a/ext/sqlite/package.xml b/ext/sqlite/package.xml index b2ad19889d..78f1554ae0 100644 --- a/ext/sqlite/package.xml +++ b/ext/sqlite/package.xml @@ -43,12 +43,9 @@ <release> <state>stable</state> <version>1.0.2</version> -<date>2004-01-17</date> +<date>2004-07-10</date> <notes> -Upgraded libsqlite to version 2.9.11 -Fixed crash bug in module shutdown -Fixed crash with empty queries -Fixed column name mangling bug +Upgraded libsqlite to version 2.9.14 </notes> <filelist> @@ -57,7 +54,6 @@ Fixed column name mangling bug <file role="src" name="sqlite.dsp"/> <file role="src" name="php_sqlite.h"/> <file role="src" name="php_sqlite.def"/> - <file role="src" name="Makefile.frag"/> <file role="doc" name="CREDITS"/> <file role="doc" name="README"/> <file role="doc" name="TODO"/> @@ -136,6 +132,19 @@ Fixed column name mangling bug </release> <changelog> + +<release> +<state>stable</state> +<version>1.0.2</version> +<date>2004-01-17</date> +<notes> +Upgraded libsqlite to version 2.9.11 +Fixed crash bug in module shutdown +Fixed crash with empty queries +Fixed column name mangling bug +</notes> +</release> + <release> <state>stable</state> <version>1.0</version> diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c index b2b13483a4..540ccb49a1 100644 --- a/ext/sqlite/sqlite.c +++ b/ext/sqlite/sqlite.c @@ -24,7 +24,7 @@ #include "config.h" #endif -#define PHP_SQLITE_MODULE_VERSION "1.0" +#define PHP_SQLITE_MODULE_VERSION "1.0.3" #include "php.h" #include "php_ini.h" |