# # add_file "sqlite/analyze.c" # # add_file "sqlite/complete.c" # # add_file "sqlite/vdbefifo.c" # # patch "ChangeLog" # from [883818accc112ef7043512ae7196b4a564bd417c] # to [0ba8d9b1dc7b4ae558e26303d8e917b9c551bcfe] # # patch "Makefile.am" # from [37d234104aa51fb9f169ed0be12208e4b5be0669] # to [f64733542ba308ba4047d2e7cfc8a18f95d0eb4c] # # patch "sqlite/alter.c" # from [03041f2464e22532601254f87cb49997fa21dcdf] # to [26d755f2143719dd3f5b8aaf6cbe3c7f95332528] # # patch "sqlite/analyze.c" # from [] # to [43a2d91242bdd71b6c299378f6b11e896ee5e43d] # # patch "sqlite/attach.c" # from [3615dbe960cbee4aa5ea300b8a213dad36527b0f] # to [4b21689700a72ae281fa85dbaff06b2a62bd49ee] # # patch "sqlite/auth.c" # from [18c5a0befe20f3a58a41e3ddd78f372faeeefe1f] # to [31e2304bef67f44d635655f44234387ea7d21454] # # patch "sqlite/btree.c" # from [d2e09ebf755bfd665727133361b22c6a915b12d7] # to [236126155d5607da945d33514218cbec762d887e] # # patch "sqlite/btree.h" # from [41a71ce027db9ddee72cb43df2316bbe3a1d92af] # to [1ed561263ca0e335bc3e81d761c9d5ff8c22f61e] # # patch "sqlite/build.c" # from [593d8fda0576a72e6f1fbf8f1a61db110dde9264] # to [74653e045581bfbadb8b35a0cb38a62f4a2c850e] # # patch "sqlite/callback.c" # from [0910b611e0c158f107ee3ff86f8a371654971e2b] # to [9a1162c8f9dae9fad6d548339669aacb5f6cf76b] # # patch "sqlite/complete.c" # from [] # to [641713ef01657f74037840abb9c0a4552c07b0d0] # # patch "sqlite/date.c" # from [2134ef4388256e8247405178df8a61bd60dc180a] # to [7444b0900a28da77e57e3337a636873cff0ae940] # # patch "sqlite/delete.c" # from [4b68127f55971c7fb459146e0b6cf3bd70cfffe9] # to [16a0e19460b14d219f39ff5c7a9eef808aa1969c] # # patch "sqlite/expr.c" # from [6d7058944c5f4b7e4304be3fe63ada91dac221a1] # to [b8dbd5a30e80b83b0c1e137dcfcd687bd5d2b76c] # # patch "sqlite/func.c" # from [f208d71f741d47b63277530939f552815af8ce35] # to [f63d417248808ff2632a3b576536abffcc21d858] # # patch "sqlite/insert.c" # from [8c0868a975fe37366ed92e1b976853be96284607] # to [484c73bc1309f283a31baa0e114f3ee980536397] # # patch "sqlite/keywordhash.h" # from [9f753ca12591e9ac7d627850e28217bf1fb96c26] # to [32380a4bfe997d18e3ecd5b85fd948cf7b52aec8] # # patch "sqlite/main.c" # from [16ab37b7b3aa57bcfb6b687474b2553c67b1a7fe] # to [422014201f22aa17b96c76650163178a91a825af] # # patch "sqlite/opcodes.c" # from [09ba45fa2716974a205f0514fda43e0d52c50ecc] # to [8b23c96979492cba740a2e3c67f6646e8b323b12] # # patch "sqlite/opcodes.h" # from [c350694b63ef80daafa7d04f71a6d921aa4935e2] # to [1848e78f249e09e0b773754679d6584412f8900f] # # patch "sqlite/os.h" # from [c4b34bd4d6fea51a420f337468b907f4edecb161] # to [c51f2747f7bd1840447e2c7d26db749604626814] # # patch "sqlite/os_common.h" # from [0e7f428ba0a6c40a61bc56c4e96f493231301b73] # to [1ff88c7e7e6bd3e5f85443106c91cc26a4f8600b] # # patch "sqlite/os_unix.c" # from [45540d7ee5095566da6685d584598edee5be857c] # to [c86cf43b7ca9200e6fb7bc202ad2cc7da2f69367] # # patch "sqlite/os_unix.h" # from [39a393252e69e72b06715c9958df05ddbc4aa971] # to [5768d56d28240d3fe4537fac08cc85e4fb52279e] # # patch "sqlite/os_win.c" # from [fe7b99cfcfb61d9bf54493ddf5857885a657fb89] # to [ed03a35b2894f9b99840415f941a9f8594dea756] # # patch "sqlite/pager.c" # from [841a2cdddd4275de36cda26ed9dc54ae942660ce] # to [adbb27f13ac75cd5bc29a3d84803e0cab1edfa88] # # patch "sqlite/pager.h" # from [0d9153d6269d60d04af3dd84a0cc0a96253cf4a4] # to [17b13225abd93c1e9f470060f40a21b9edb5a164] # # patch "sqlite/parse.c" # from [6671523c392fcf8287c08e5896cc2513987fc5cb] # to [9f03b15f12e12a7952705f50d01e3ac97bb81e34] # # patch "sqlite/parse.h" # from [55c238b9c97ae9a71722f2fabf3e0d23660e4e63] # to [c3a865a73a9e4988142a3008f99d3cc91fdf77b4] # # patch "sqlite/pragma.c" # from [5ea2ba0e43f6a83968a936b071b77bd4516d11f0] # to [6d773e25e8af13ef0820531ad2793417f8a8959d] # # patch "sqlite/prepare.c" # from [d53602d2f8e097225ae7c76ec764ae68f759ba47] # to [fc098db25d2a121affb08686cf04833fd50452d4] # # patch "sqlite/printf.c" # from [3d20b21cfecadacecac3fb7274e746cb81d3d357] # to [bd421c1ad5e01013c89af63c60eab02852ccd15e] # # patch "sqlite/select.c" # from [28b752e58955c7920711fbdbfdcd369a2bd09448] # to [9ef1dddd436e1ea86a6bf64ae0ed71bf4a0b894f] # # patch "sqlite/sqlite3.h" # from [97fec5750fa71f8b162c9571a7e08413de9886ed] # to [d1ab08a3d92270801782adad0dad0f31d6df7761] # # patch "sqlite/sqliteInt.h" # from [0722b47bae7acb182bf43be3585537027c63f741] # to [e78a7c53a97a2e5d8d6370b6836b2921124ac26f] # # patch "sqlite/tokenize.c" # from [4b45f8c000202c877bcc567688c2ec21a01984b3] # to [e1faf5637f3f4f90933785a0ecf64595f3ac3530] # # patch "sqlite/update.c" # from [e96c7b342cd8903c672162f4cf84d2c737943347] # to [c2716c2115533ffae3d08bf8853aaba4f970f37e] # # patch "sqlite/util.c" # from [96008b52604d08b9cc57ed37350149d6ac8a1bf3] # to [55caaffbb2716f9928ab452d20f3e9cbbeab872d] # # patch "sqlite/vdbe.c" # from [c2511f392598928254504e3b2c5ec47f4fef2b53] # to [de007d59f036fcd1b89a7d4172aa0d028e8689eb] # # patch "sqlite/vdbe.h" # from [75e466d84d362b0c4498978a9d6b1e6bd32ecf3b] # to [c8e105979fc7aaf5b8004e9621904e3bd096dfa2] # # patch "sqlite/vdbeInt.h" # from [4312faf41630a6c215924b6c7c2f39ebb1af8ffb] # to [3dd2a29c7b0a55404c35f93caae81fb42f4cb70a] # # patch "sqlite/vdbeapi.c" # from [3f858d2236df0d127249a6a166e0e25b5de650ed] # to [85bbe1d0243a89655433d60711b4bd71979b59cd] # # patch "sqlite/vdbeaux.c" # from [c99e32abeba4b7522e3922afff2c32ff4bd17eb5] # to [57a6ced8417bdc6f06c391d9c560ecbbed644ef3] # # patch "sqlite/vdbefifo.c" # from [] # to [9efb94c8c3f4c979ebd0028219483f88e57584f5] # # patch "sqlite/vdbemem.c" # from [48a64ae95a9edc6e8d940300dad15d70d1670398] # to [fea0744936008831daa17cdc75056c3ca1469690] # # patch "sqlite/where.c" # from [3a9a2258ab3364655e9ea215ad5ae7bf41813f54] # to [1cc55c9aa142c7ef09b427f5fd0bf0488e365fc4] # ======================================================================== --- ChangeLog 883818accc112ef7043512ae7196b4a564bd417c +++ ChangeLog 0ba8d9b1dc7b4ae558e26303d8e917b9c551bcfe @@ -1,5 +1,8 @@ 2005-09-20 Matthew Gregan + * sqlite*: Update in-tree SQLite from 3.2.2 to 3.2.6. + * Makefile.am: Add sqlite/{analyze,vbdefifo,complete}.c to + SQLITE_SOURCES * schema_migration.cc (calculate_schema_id): Explicitly exclude sqlite_stat1 table from schema ID calculation. This is a new magic table created by the 'analyze' command in SQLite >= 3.2.3. ======================================================================== --- Makefile.am 37d234104aa51fb9f169ed0be12208e4b5be0669 +++ Makefile.am f64733542ba308ba4047d2e7cfc8a18f95d0eb4c @@ -167,6 +167,8 @@ sqlite/vdbe.c sqlite/vdbeapi.c sqlite/vdbeaux.c \ sqlite/vdbemem.c sqlite/where.c \ sqlite/prepare.c sqlite/callback.c \ + sqlite/analyze.c sqlite/vdbefifo.c \ + sqlite/complete.c \ \ sqlite/btree.h sqlite/config.h sqlite/hash.h sqlite/opcodes.h sqlite/os.h \ sqlite/os_common.h sqlite/os_unix.h sqlite/os_win.h \ ======================================================================== --- sqlite/alter.c 03041f2464e22532601254f87cb49997fa21dcdf +++ sqlite/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528 @@ -12,7 +12,7 @@ ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** -** $Id: alter.c,v 1.7 2005/06/06 21:19:57 drh Exp $ +** $Id: alter.c,v 1.8 2005/08/19 19:14:13 drh Exp $ */ #include "sqliteInt.h" #include @@ -258,6 +258,7 @@ char *zWhere = 0; /* Where clause to locate temp triggers */ #endif + if( sqlite3_malloc_failed ) goto exit_rename_table; assert( pSrc->nSrc==1 ); pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); @@ -500,8 +501,10 @@ int i; int nAlloc; + /* Look up the table being altered. */ - assert( !pParse->pNewTable ); + assert( pParse->pNewTable==0 ); + if( sqlite3_malloc_failed ) goto exit_begin_add_column; pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); if( !pTab ) goto exit_begin_add_column; @@ -520,6 +523,7 @@ pNew = (Table *)sqliteMalloc(sizeof(Table)); if( !pNew ) goto exit_begin_add_column; pParse->pNewTable = pNew; + pNew->nRef = 1; pNew->nCol = pTab->nCol; assert( pNew->nCol>0 ); nAlloc = (((pNew->nCol-1)/8)*8)+8; ======================================================================== --- sqlite/analyze.c +++ sqlite/analyze.c 43a2d91242bdd71b6c299378f6b11e896ee5e43d @@ -0,0 +1,388 @@ +/* +** 2005 July 8 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This file contains code associated with the ANALYZE command. +** +** @(#) $Id: analyze.c,v 1.8 2005/09/10 22:40:54 drh Exp $ +*/ +#ifndef SQLITE_OMIT_ANALYZE +#include "sqliteInt.h" + +/* +** This routine generates code that opens the sqlite_stat1 table on cursor +** iStatCur. +** +** If the sqlite_stat1 tables does not previously exist, it is created. +** If it does previously exist, all entires associated with table zWhere +** are removed. If zWhere==0 then all entries are removed. +*/ +static void openStatTable( + Parse *pParse, /* Parsing context */ + int iDb, /* The database we are looking in */ + int iStatCur, /* Open the sqlite_stat1 table on this cursor */ + const char *zWhere /* Delete entries associated with this table */ +){ + sqlite3 *db = pParse->db; + Db *pDb; + int iRootPage; + Table *pStat; + Vdbe *v = sqlite3GetVdbe(pParse); + + pDb = &db->aDb[iDb]; + if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){ + /* The sqlite_stat1 tables does not exist. Create it. + ** Note that a side-effect of the CREATE TABLE statement is to leave + ** the rootpage of the new table on the top of the stack. This is + ** important because the OpenWrite opcode below will be needing it. */ + sqlite3NestedParse(pParse, + "CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)", + pDb->zName + ); + iRootPage = 0; /* Cause rootpage to be taken from top of stack */ + }else if( zWhere ){ + /* The sqlite_stat1 table exists. Delete all entries associated with + ** the table zWhere. */ + sqlite3NestedParse(pParse, + "DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q", + pDb->zName, zWhere + ); + iRootPage = pStat->tnum; + }else{ + /* The sqlite_stat1 table already exists. Delete all rows. */ + iRootPage = pStat->tnum; + sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb); + } + + /* Open the sqlite_stat1 table for writing. + */ + sqlite3VdbeAddOp(v, OP_Integer, iDb, 0); + sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage); + sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3); +} + +/* +** Generate code to do an analysis of all indices associated with +** a single table. +*/ +static void analyzeOneTable( + Parse *pParse, /* Parser context */ + Table *pTab, /* Table whose indices are to be analyzed */ + int iStatCur, /* Cursor that writes to the sqlite_stat1 table */ + int iMem /* Available memory locations begin here */ +){ + Index *pIdx; /* An index to being analyzed */ + int iIdxCur; /* Cursor number for index being analyzed */ + int nCol; /* Number of columns in the index */ + Vdbe *v; /* The virtual machine being built up */ + int i; /* Loop counter */ + int topOfLoop; /* The top of the loop */ + int endOfLoop; /* The end of the loop */ + int addr; /* The address of an instruction */ + + v = sqlite3GetVdbe(pParse); + if( pTab==0 || pTab->pIndex==0 ){ + /* Do no analysis for tables that have no indices */ + return; + } + +#ifndef SQLITE_OMIT_AUTHORIZATION + if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0, + pParse->db->aDb[pTab->iDb].zName ) ){ + return; + } +#endif + + iIdxCur = pParse->nTab; + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + /* Open a cursor to the index to be analyzed + */ + sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0); + VdbeComment((v, "# %s", pIdx->zName)); + sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, + (char*)&pIdx->keyInfo, P3_KEYINFO); + nCol = pIdx->nColumn; + if( iMem+nCol*2>=pParse->nMem ){ + pParse->nMem = iMem+nCol*2+1; + } + sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, nCol+1); + + /* Memory cells are used as follows: + ** + ** mem[iMem]: The total number of rows in the table. + ** mem[iMem+1]: Number of distinct values in column 1 + ** ... + ** mem[iMem+nCol]: Number of distinct values in column N + ** mem[iMem+nCol+1] Last observed value of column 1 + ** ... + ** mem[iMem+nCol+nCol]: Last observed value of column N + ** + ** Cells iMem through iMem+nCol are initialized to 0. The others + ** are initialized to NULL. + */ + sqlite3VdbeAddOp(v, OP_Integer, 0, 0); + for(i=0; i<=nCol; i++){ + sqlite3VdbeAddOp(v, OP_MemStore, iMem+i, i==nCol); + } + sqlite3VdbeAddOp(v, OP_Null, 0, 0); + for(i=0; i0 then it is always the case the D>0 so division by zero + ** is never possible. + */ + sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0); + addr = sqlite3VdbeAddOp(v, OP_IfNot, 0, 0); + sqlite3VdbeAddOp(v, OP_NewRowid, iStatCur, 0); + sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0); + sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0); + sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0); + sqlite3VdbeOp3(v, OP_String8, 0, 0, " ", 0); + for(i=0; idb; + HashElem *k; + int iStatCur; + int iMem; + + sqlite3BeginWriteOperation(pParse, 0, iDb); + iStatCur = pParse->nTab++; + openStatTable(pParse, iDb, iStatCur, 0); + iMem = pParse->nMem; + for(k=sqliteHashFirst(&db->aDb[iDb].tblHash); k; k=sqliteHashNext(k)){ + Table *pTab = (Table*)sqliteHashData(k); + analyzeOneTable(pParse, pTab, iStatCur, iMem); + } + loadAnalysis(pParse, iDb); +} + +/* +** Generate code that will do an analysis of a single table in +** a database. +*/ +static void analyzeTable(Parse *pParse, Table *pTab){ + int iDb; + int iStatCur; + + assert( pTab!=0 ); + iDb = pTab->iDb; + sqlite3BeginWriteOperation(pParse, 0, iDb); + iStatCur = pParse->nTab++; + openStatTable(pParse, iDb, iStatCur, pTab->zName); + analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem); + loadAnalysis(pParse, iDb); +} + +/* +** Generate code for the ANALYZE command. The parser calls this routine +** when it recognizes an ANALYZE command. +** +** ANALYZE -- 1 +** ANALYZE -- 2 +** ANALYZE ?.? -- 3 +** +** Form 1 causes all indices in all attached databases to be analyzed. +** Form 2 analyzes all indices the single database named. +** Form 3 analyzes all indices associated with the named table. +*/ +void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ + sqlite3 *db = pParse->db; + int iDb; + int i; + char *z, *zDb; + Table *pTab; + Token *pTableName; + + /* Read the database schema. If an error occurs, leave an error message + ** and code in pParse and return NULL. */ + if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ + return; + } + + if( pName1==0 ){ + /* Form 1: Analyze everything */ + for(i=0; inDb; i++){ + if( i==1 ) continue; /* Do not analyze the TEMP database */ + analyzeDatabase(pParse, i); + } + }else if( pName2==0 || pName2->n==0 ){ + /* Form 2: Analyze the database or table named */ + iDb = sqlite3FindDb(db, pName1); + if( iDb>=0 ){ + analyzeDatabase(pParse, iDb); + }else{ + z = sqlite3NameFromToken(pName1); + pTab = sqlite3LocateTable(pParse, z, 0); + sqliteFree(z); + if( pTab ){ + analyzeTable(pParse, pTab); + } + } + }else{ + /* Form 3: Analyze the fully qualified table name */ + iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName); + if( iDb>=0 ){ + zDb = db->aDb[iDb].zName; + z = sqlite3NameFromToken(pTableName); + pTab = sqlite3LocateTable(pParse, z, zDb); + sqliteFree(z); + if( pTab ){ + analyzeTable(pParse, pTab); + } + } + } +} + +/* +** Used to pass information from the analyzer reader through to the +** callback routine. +*/ +typedef struct analysisInfo analysisInfo; +struct analysisInfo { + sqlite3 *db; + const char *zDatabase; +}; + +/* +** This callback is invoked once for each index when reading the +** sqlite_stat1 table. +** +** argv[0] = name of the index +** argv[1] = results of analysis - on integer for each column +*/ +static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){ + analysisInfo *pInfo = (analysisInfo*)pData; + Index *pIndex; + int i, c; + unsigned int v; + const char *z; + + assert( argc==2 ); + if( argv==0 || argv[0]==0 || argv[1]==0 ){ + return 0; + } + pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase); + if( pIndex==0 ){ + return 0; + } + z = argv[1]; + for(i=0; *z && i<=pIndex->nColumn; i++){ + v = 0; + while( (c=z[0])>='0' && c<='9' ){ + v = v*10 + c - '0'; + z++; + } + pIndex->aiRowEst[i] = v; + if( *z==' ' ) z++; + } + return 0; +} + +/* +** Load the content of the sqlite_stat1 table into the index hash tables. +*/ +void sqlite3AnalysisLoad(sqlite3 *db, int iDb){ + analysisInfo sInfo; + HashElem *i; + char *zSql; + + /* Clear any prior statistics */ + for(i=sqliteHashFirst(&db->aDb[iDb].idxHash); i; i=sqliteHashNext(i)){ + Index *pIdx = sqliteHashData(i); + sqlite3DefaultRowEst(pIdx); + } + + /* Check to make sure the sqlite_stat1 table existss */ + sInfo.db = db; + sInfo.zDatabase = db->aDb[iDb].zName; + if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){ + return; + } + + + /* Load new statistics out of the sqlite_stat1 table */ + zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1", + sInfo.zDatabase); + sqlite3SafetyOff(db); + sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0); + sqlite3SafetyOn(db); + sqliteFree(zSql); +} + + +#endif /* SQLITE_OMIT_ANALYZE */ ======================================================================== --- sqlite/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f +++ sqlite/attach.c 4b21689700a72ae281fa85dbaff06b2a62bd49ee @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.33 2005/03/16 12:15:21 danielk1977 Exp $ +** $Id: attach.c,v 1.34 2005/08/20 03:03:04 drh Exp $ */ #include "sqliteInt.h" @@ -146,8 +146,8 @@ db->aDb[i].pBt = 0; } sqlite3ResetInternalSchema(db, 0); - if( 0==pParse->nErr ){ - pParse->nErr++; + assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */ + if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; } } ======================================================================== --- sqlite/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f +++ sqlite/auth.c 31e2304bef67f44d635655f44234387ea7d21454 @@ -14,7 +14,7 @@ ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ** -** $Id: auth.c,v 1.21 2005/01/29 08:32:44 danielk1977 Exp $ +** $Id: auth.c,v 1.22 2005/07/29 15:36:15 drh Exp $ */ #include "sqliteInt.h" @@ -114,6 +114,7 @@ TriggerStack *pStack; /* The stack of current triggers */ if( db->xAuth==0 ) return; + if( pExpr->op==TK_AS ) return; assert( pExpr->op==TK_COLUMN ); for(iSrc=0; pTabList && iSrcnSrc; iSrc++){ if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break; ======================================================================== --- sqlite/btree.c d2e09ebf755bfd665727133361b22c6a915b12d7 +++ sqlite/btree.c 236126155d5607da945d33514218cbec762d887e @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.261 2005/05/24 20:19:58 drh Exp $ +** $Id: btree.c,v 1.269 2005/09/17 15:20:27 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -234,8 +234,19 @@ /* ** This is a magic string that appears at the beginning of every ** SQLite database in order to identify the file as a real database. -** 123456789 123456 */ -static const char zMagicHeader[] = "SQLite format 3"; +** +** You can change this value at compile-time by specifying a +** -DSQLITE_FILE_HEADER="..." on the compiler command-line. The +** header must be exactly 16 bytes including the zero-terminator so +** the string itself should be 15 characters long. If you change +** the header, then your custom library will not be able to read +** databases generated by the standard tools and the standard tools +** will not be able to read databases created by your custom library. +*/ +#ifndef SQLITE_FILE_HEADER /* 123456789 123456 */ +# define SQLITE_FILE_HEADER "SQLite format 3" +#endif +static const char zMagicHeader[] = SQLITE_FILE_HEADER; /* ** Page type flags. An ORed combination of these flags appear as the @@ -483,7 +494,7 @@ assert( pBt->autoVacuum ); if( key==0 ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } iPtrmap = PTRMAP_PAGENO(pBt->usableSize, key); rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap); @@ -529,7 +540,7 @@ if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); sqlite3pager_unref(pPtrmap); - if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT; + if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT; return SQLITE_OK; } @@ -1019,7 +1030,7 @@ assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] ); if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){ /* The parent page should never change unless the file is corrupt */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } if( pPage->isInit ) return SQLITE_OK; if( pPage->pParent==0 && pParent!=0 ){ @@ -1037,11 +1048,11 @@ pPage->nCell = get2byte(&data[hdr+3]); if( pPage->nCell>MX_CELL(pBt) ){ /* To many cells for a single page. The page must be corrupt */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } if( pPage->nCell==0 && pParent!=0 && pParent->pgno!=1 ){ /* All pages must have at least one cell, except for root pages */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } /* Compute the total free space on the page */ @@ -1051,13 +1062,13 @@ int next, size; if( pc>usableSize-4 ){ /* Free block is off the page */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } next = get2byte(&data[pc]); size = get2byte(&data[pc+2]); if( next>0 && next<=pc+size+3 ){ /* Free blocks must be in accending order */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } nFree += size; pc = next; @@ -1065,7 +1076,7 @@ pPage->nFree = nFree; if( nFree>=usableSize ){ /* Free space cannot exceed total page size */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } pPage->isInit = 1; @@ -1135,7 +1146,7 @@ ){ int rc; if( pgno==0 ){ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } rc = getPage(pBt, pgno, ppPage); if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){ @@ -1334,6 +1345,15 @@ } #endif +/* +** Return TRUE if the given btree is set to safety level 1. In other +** words, return TRUE if no sync() occurs on the disk files. +*/ +int sqlite3BtreeSyncDisabled(Btree *pBt){ + assert( pBt && pBt->pPager ); + return sqlite3pager_nosync(pBt->pPager); +} + #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) /* ** Change the default pages size and the number of reserved bytes per page. @@ -1595,8 +1615,6 @@ */ int sqlite3BtreeBeginTrans(Btree *pBt, int wrflag){ int rc = SQLITE_OK; - int busy = 0; - BusyHandler *pH; /* If the btree is already in a write-transaction, or it ** is already in a read-transaction and a read-transaction @@ -1630,9 +1648,7 @@ unlockBtreeIfUnused(pBt); } }while( rc==SQLITE_BUSY && pBt->inTrans==TRANS_NONE && - (pH = pBt->pBusyHandler)!=0 && - pH->xFunc && pH->xFunc(pH->pArg, busy++) - ); + sqlite3InvokeBusyHandler(pBt->pBusyHandler) ); return rc; } @@ -1698,7 +1714,7 @@ if( eType==PTRMAP_OVERFLOW2 ){ /* The pointer is always the first 4 bytes of the page in this case. */ if( get4byte(pPage->aData)!=iFrom ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } put4byte(pPage->aData, iTo); }else{ @@ -1731,7 +1747,7 @@ if( i==nCell ){ if( eType!=PTRMAP_BTREE || get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } put4byte(&pPage->aData[pPage->hdrOffset+8], iTo); } @@ -1844,7 +1860,7 @@ assert( pBt->autoVacuum ); if( PTRMAP_ISPAGE(pgsz, sqlite3pager_pagecount(pPager)) ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } /* Figure out how many free-pages are in the database. If there are no @@ -1859,7 +1875,7 @@ origSize = sqlite3pager_pagecount(pPager); nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pgsz, origSize)+pgsz/5)/(pgsz/5); finSize = origSize - nFreeList - nPtrMap; - if( origSize>PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){ + if( origSize>=PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){ finSize--; if( PTRMAP_ISPAGE(pBt->usableSize, finSize) ){ finSize--; @@ -1882,7 +1898,7 @@ rc = ptrmapGet(pBt, iDbPage, &eType, &iPtrPage); if( rc!=SQLITE_OK ) goto autovacuum_out; if( eType==PTRMAP_ROOTPAGE ){ - rc = SQLITE_CORRUPT; + rc = SQLITE_CORRUPT_BKPT; goto autovacuum_out; } @@ -2398,7 +2414,7 @@ } if( amt>0 ){ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } return SQLITE_OK; } @@ -2416,7 +2432,7 @@ assert( pCur->isValid ); assert( pCur->pPage!=0 ); if( pCur->pPage->intKey ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } assert( pCur->pPage->intKey==0 ); assert( pCur->idx>=0 && pCur->idxpPage->nCell ); @@ -2465,13 +2481,11 @@ ){ unsigned char *aPayload; MemPage *pPage; - Btree *pBt; u32 nKey; int nLocal; assert( pCur!=0 && pCur->pPage!=0 ); assert( pCur->isValid ); - pBt = pCur->pBt; pPage = pCur->pPage; pageIntegrity(pPage); assert( pCur->idx>=0 && pCur->idxnCell ); @@ -2538,7 +2552,7 @@ pCur->idx = 0; pCur->info.nSize = 0; if( pNewPage->nCell<1 ){ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } return SQLITE_OK; } @@ -2569,7 +2583,6 @@ ** the largest cell index. */ static void moveToParent(BtCursor *pCur){ - Pgno oldPgno; MemPage *pParent; MemPage *pPage; int idxParent; @@ -2584,7 +2597,6 @@ pageIntegrity(pParent); idxParent = pPage->idxParent; sqlite3pager_ref(pParent->aData); - oldPgno = pPage->pgno; releasePage(pPage); pCur->pPage = pParent; pCur->info.nSize = 0; @@ -2749,7 +2761,7 @@ lwr = 0; upr = pPage->nCell-1; if( !pPage->intKey && pKey==0 ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } pageIntegrity(pPage); while( lwr<=upr ){ @@ -3034,7 +3046,7 @@ TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1)); }else if( k>pBt->usableSize/4 - 8 ){ /* Value of k is out of range. Database corruption */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; #ifndef SQLITE_OMIT_AUTOVACUUM }else if( searchList && nearby==iTrunk ){ /* The list is being searched and this trunk page is the page @@ -3109,7 +3121,7 @@ *pPgno = iPage; if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){ /* Free page off the end of the file */ - return SQLITE_CORRUPT; /* bkpt-CORRUPT */ + return SQLITE_CORRUPT_BKPT; } TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d" ": %d more free pages\n", @@ -3250,7 +3262,7 @@ while( ovflPgno!=0 ){ MemPage *pOvfl; if( ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } rc = getPage(pBt, ovflPgno, &pOvfl); if( rc ) return rc; @@ -3595,17 +3607,19 @@ data = pPage->aData; hdr = pPage->hdrOffset; put2byte(&data[hdr+3], nCell); - cellbody = allocateSpace(pPage, totalSize); - assert( cellbody>0 ); - assert( pPage->nFree >= 2*nCell ); - pPage->nFree -= 2*nCell; - for(i=0; i0 ); + assert( pPage->nFree >= 2*nCell ); + pPage->nFree -= 2*nCell; + for(i=0; ipBt->usableSize ); } - assert( cellbody==pPage->pBt->usableSize ); pPage->nCell = nCell; } @@ -3809,7 +3823,7 @@ /* ** A special case: If a new entry has just been inserted into a ** table (that is, a btree with integer keys and all data at the leaves) - ** an the new entry is the right-most entry in the tree (it has the + ** and the new entry is the right-most entry in the tree (it has the ** largest key) then use the special balance_quick() routine for ** balancing. balance_quick() is much faster and results in a tighter ** packing of data in the common case. @@ -4082,8 +4096,13 @@ szNew[i] = szRight; szNew[i-1] = szLeft; } - assert( cntNew[0]>0 ); + /* Either we found one or more cells (cntnew[0])>0) or we are the + ** a virtual root page. A virtual root page is when the real root + ** page is page 1 and we are the only child of that page. + */ + assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) ); + /* ** Allocate k new pages. Reuse old pages where possible. */ @@ -4171,7 +4190,7 @@ assert( jpgno==pgnoNew[i] ); assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]); - assert( pNew->nCell>0 ); + assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) ); assert( pNew->nOverflow==0 ); #ifndef SQLITE_OMIT_AUTOVACUUM @@ -4649,7 +4668,7 @@ rc = sqlite3BtreeNext(&leafCur, ¬Used); if( rc!=SQLITE_OK ){ if( rc!=SQLITE_NOMEM ){ - rc = SQLITE_CORRUPT; /* bkpt-CORRUPT */ + rc = SQLITE_CORRUPT_BKPT; } } if( rc==SQLITE_OK ){ @@ -4835,7 +4854,7 @@ int i; if( pgno>sqlite3pager_pagecount(pBt->pPager) ){ - return SQLITE_CORRUPT; + return SQLITE_CORRUPT_BKPT; } rc = getAndInitPage(pBt, pgno, &pPage, pParent); @@ -5457,7 +5476,7 @@ u8 *data; BtCursor cur; Btree *pBt; - int maxLocal, usableSize; + int usableSize; char zContext[100]; char *hit; @@ -5474,7 +5493,6 @@ "unable to get the page. error code=%d", rc); return 0; } - maxLocal = pPage->leafData ? pBt->maxLeaf : pBt->maxLocal; if( (rc = initPage(pPage, pParent))!=0 ){ checkAppendMsg(pCheck, zContext, "initPage() returns error code %d", rc); releasePage(pPage); @@ -5721,7 +5739,7 @@ */ int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){ int rc = SQLITE_OK; - Pgno i, nPage, nToPage; + Pgno i, nPage, nToPage, iSkip; if( pBtTo->inTrans!=TRANS_WRITE || pBtFrom->inTrans!=TRANS_WRITE ){ return SQLITE_ERROR; @@ -5729,8 +5747,10 @@ if( pBtTo->pCursor ) return SQLITE_BUSY; nToPage = sqlite3pager_pagecount(pBtTo->pPager); nPage = sqlite3pager_pagecount(pBtFrom->pPager); + iSkip = PENDING_BYTE_PAGE(pBtTo); for(i=1; rc==SQLITE_OK && i<=nPage; i++){ void *pPage; + if( i==iSkip ) continue; rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage); if( rc ) break; rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage); @@ -5739,6 +5759,7 @@ } for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){ void *pPage; + if( i==iSkip ) continue; rc = sqlite3pager_get(pBtTo->pPager, i, &pPage); if( rc ) break; rc = sqlite3pager_write(pPage); ======================================================================== --- sqlite/btree.h 41a71ce027db9ddee72cb43df2316bbe3a1d92af +++ sqlite/btree.h 1ed561263ca0e335bc3e81d761c9d5ff8c22f61e @@ -13,7 +13,7 @@ ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** -** @(#) $Id: btree.h,v 1.63 2005/03/21 04:04:03 danielk1977 Exp $ +** @(#) $Id: btree.h,v 1.64 2005/08/27 16:36:49 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ @@ -58,6 +58,7 @@ int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*); int sqlite3BtreeSetCacheSize(Btree*,int); int sqlite3BtreeSetSafetyLevel(Btree*,int); +int sqlite3BtreeSyncDisabled(Btree*); int sqlite3BtreeSetPageSize(Btree*,int,int); int sqlite3BtreeGetPageSize(Btree*); int sqlite3BtreeGetReserve(Btree*); ======================================================================== --- sqlite/build.c 593d8fda0576a72e6f1fbf8f1a61db110dde9264 +++ sqlite/build.c 74653e045581bfbadb8b35a0cb38a62f4a2c850e @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.326 2005/06/12 21:35:52 drh Exp $ +** $Id: build.c,v 1.350 2005/09/16 02:48:02 drh Exp $ */ #include "sqliteInt.h" #include @@ -85,6 +85,7 @@ sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->cookieGoto); } +#ifndef SQLITE_OMIT_TRACE /* Add a No-op that contains the complete text of the compiled SQL ** statement as its P3 argument. This does not change the functionality ** of the program. @@ -92,6 +93,7 @@ ** This is used to implement sqlite3_trace(). */ sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail-pParse->zSql); +#endif /* SQLITE_OMIT_TRACE */ } @@ -101,7 +103,7 @@ FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0; sqlite3VdbeTrace(v, trace); sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem+3, - pParse->nTab+3, pParse->nMaxDepth+1, pParse->explain); + pParse->nTab+3, pParse->explain); pParse->rc = SQLITE_DONE; pParse->colNamesSet = 0; }else if( pParse->rc==SQLITE_OK ){ @@ -130,7 +132,6 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ va_list ap; char *zSql; - int rc; # define SAVE_SZ (sizeof(Parse) - offsetof(Parse,nVar)) char saveBuf[SAVE_SZ]; @@ -145,7 +146,7 @@ pParse->nested++; memcpy(saveBuf, &pParse->nVar, SAVE_SZ); memset(&pParse->nVar, 0, SAVE_SZ); - rc = sqlite3RunParser(pParse, zSql, 0); + sqlite3RunParser(pParse, zSql, 0); sqliteFree(zSql); memcpy(&pParse->nVar, saveBuf, SAVE_SZ); pParse->nested--; @@ -200,9 +201,6 @@ if( p==0 ){ if( zDbase ){ sqlite3ErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); - }else if( sqlite3FindTable(pParse->db, zName, 0)!=0 ){ - sqlite3ErrorMsg(pParse, "table \"%s\" is not in database \"%s\"", - zName, zDbase); }else{ sqlite3ErrorMsg(pParse, "no such table: %s", zName); } @@ -258,10 +256,7 @@ assert( db!=0 && p->zName!=0 ); pOld = sqlite3HashInsert(&db->aDb[p->iDb].idxHash, p->zName, strlen(p->zName)+1, 0); - if( pOld!=0 && pOld!=p ){ - sqlite3HashInsert(&db->aDb[p->iDb].idxHash, pOld->zName, - strlen(pOld->zName)+1, pOld); - } + assert( pOld==0 || pOld==p ); freeIndex(p); } @@ -535,7 +530,7 @@ ** index of the named database in db->aDb[], or -1 if the named db ** does not exist. */ -static int findDb(sqlite3 *db, Token *pName){ +int sqlite3FindDb(sqlite3 *db, Token *pName){ int i = -1; /* Database number */ int n; /* Number of characters in the name */ Db *pDb; /* A database whose name space is being searched */ @@ -583,7 +578,7 @@ if( pName2 && pName2->n>0 ){ assert( !db->init.busy ); *pUnqual = pName2; - iDb = findDb(db, pName1); + iDb = sqlite3FindDb(db, pName1); if( iDb<0 ){ sqlite3ErrorMsg(pParse, "unknown database %T", pName1); pParse->nErr++; @@ -640,7 +635,6 @@ int isView /* True if this is a VIEW */ ){ Table *pTable; - Index *pIdx; char *zName = 0; /* The name of the new table */ sqlite3 *db = pParse->db; Vdbe *v; @@ -719,8 +713,7 @@ sqlite3ErrorMsg(pParse, "table %T already exists", pName); goto begin_table_error; } - if( (pIdx = sqlite3FindIndex(db, zName, 0))!=0 && - ( iDb==0 || !db->init.busy) ){ + if( sqlite3FindIndex(db, zName, 0)!=0 && (iDb==0 || !db->init.busy) ){ sqlite3ErrorMsg(pParse, "there is already an index named %s", zName); goto begin_table_error; } @@ -745,7 +738,7 @@ ** so that INSERT can find the table easily. */ #ifndef SQLITE_OMIT_AUTOINCREMENT - if( strcmp(zName, "sqlite_sequence")==0 ){ + if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){ db->aDb[iDb].pSeqTab = pTable; } #endif @@ -902,11 +895,11 @@ ** If none of the substrings in the above table are found, ** SQLITE_AFF_NUMERIC is returned. */ -static char sqlite3AffinityType(const char *zType, int nType){ +char sqlite3AffinityType(const Token *pType){ u32 h = 0; char aff = SQLITE_AFF_NUMERIC; - const unsigned char *zIn = zType; - const unsigned char *zEnd = (zIn+nType); + const unsigned char *zIn = pType->z; + const unsigned char *zEnd = &pType->z[pType->n]; while( zIn!=zEnd ){ h = (h<<8) + sqlite3UpperToLower[*zIn]; @@ -938,30 +931,18 @@ ** that contains the typename of the column and store that string ** in zType. */ -void sqlite3AddColumnType(Parse *pParse, Token *pFirst, Token *pLast){ +void sqlite3AddColumnType(Parse *pParse, Token *pType){ Table *p; - int i, j; - int n; - char *z; - const unsigned char *zIn; - + int i; Column *pCol; + if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; - zIn = pFirst->z; - n = pLast->n + (pLast->z - zIn); - assert( pCol->zType==0 ); - z = pCol->zType = sqliteMallocRaw(n+1); - if( z==0 ) return; - for(i=j=0; iaffinity = sqlite3AffinityType(z, n); + sqliteFree(pCol->zType); + pCol->zType = sqlite3NameFromToken(pType); + pCol->affinity = sqlite3AffinityType(pType); } /* @@ -977,14 +958,15 @@ void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){ Table *p; Column *pCol; - if( (p = pParse->pNewTable)==0 ) return; - pCol = &(p->aCol[p->nCol-1]); - if( !sqlite3ExprIsConstant(pExpr) ){ - sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", - pCol->zName); - }else{ - sqlite3ExprDelete(pCol->pDflt); - pCol->pDflt = sqlite3ExprDup(pExpr); + if( (p = pParse->pNewTable)!=0 ){ + pCol = &(p->aCol[p->nCol-1]); + if( !sqlite3ExprIsConstantOrFunction(pExpr) ){ + sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", + pCol->zName); + }else{ + sqlite3ExprDelete(pCol->pDflt); + pCol->pDflt = sqlite3ExprDup(pExpr); + } } sqlite3ExprDelete(pExpr); } @@ -1033,7 +1015,9 @@ break; } } - if( iColnCol ) pTab->aCol[iCol].isPrimKey = 1; + if( iColnCol ){ + pTab->aCol[iCol].isPrimKey = 1; + } } if( pList->nExpr>1 ) iCol = -1; } @@ -1317,13 +1301,11 @@ */ if( p->pSelect==0 ){ /* A regular table */ - /* sqlite3VdbeAddOp(v, OP_CreateTable, p->iDb, 0); */ zType = "table"; zType2 = "TABLE"; #ifndef SQLITE_OMIT_VIEW }else{ /* A view */ - /* sqlite3VdbeAddOp(v, OP_Integer, 0, 0); */ zType = "view"; zType2 = "VIEW"; #endif @@ -1535,10 +1517,13 @@ ** Actually, this error is caught previously and so the following test ** should always fail. But we will leave it in place just to be safe. */ +#if 0 if( pTable->nCol<0 ){ sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } +#endif + assert( pTable->nCol>=0 ); /* If we get this far, it means we need to compute the table names. ** Note that the call to sqlite3ResultSetOfSelect() will expand any @@ -1973,7 +1958,6 @@ int addr1; /* Address of top of loop */ int tnum; /* Root page of index */ Vdbe *v; /* Generate code into this virtual machine */ - int isUnique; /* True for a unique index */ #ifndef SQLITE_OMIT_AUTHORIZATION if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0, @@ -2002,16 +1986,21 @@ sqlite3VdbeAddOp(v, OP_Integer, pIndex->iDb, 0); sqlite3VdbeOp3(v, OP_OpenWrite, iIdx, tnum, (char*)&pIndex->keyInfo, P3_KEYINFO); - sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqlite3VdbeAddOp(v, OP_OpenRead, iTab, pTab->tnum); - sqlite3VdbeAddOp(v, OP_SetNumColumns, iTab, pTab->nCol); + sqlite3OpenTableForReading(v, iTab, pTab); addr1 = sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0); sqlite3GenerateIndexKey(v, pIndex, iTab); - isUnique = pIndex->onError!=OE_None; - sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, isUnique); - if( isUnique ){ - sqlite3VdbeChangeP3(v, -1, "indexed columns are not unique", P3_STATIC); + if( pIndex->onError!=OE_None ){ + int curaddr = sqlite3VdbeCurrentAddr(v); + int addr2 = curaddr+4; + sqlite3VdbeChangeP2(v, curaddr-1, addr2); + sqlite3VdbeAddOp(v, OP_Rowid, iTab, 0); + sqlite3VdbeAddOp(v, OP_AddImm, 1, 0); + sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2); + sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort, + "indexed columns are not unique", P3_STATIC); + assert( addr2==sqlite3VdbeCurrentAddr(v) ); } + sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0); sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1); sqlite3VdbeChangeP2(v, addr1, sqlite3VdbeCurrentAddr(v)); sqlite3VdbeAddOp(v, OP_Close, iTab, 0); @@ -2079,7 +2068,9 @@ if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) ){ - goto exit_create_index; + /* Because the parser constructs pTblName from a single identifier, + ** sqlite3FixSrcList can never fail. */ + assert(0); } pTab = sqlite3LocateTable(pParse, pTblName->a[0].zName, pTblName->a[0].zDatabase); @@ -2124,14 +2115,12 @@ goto exit_create_index; } if( !db->init.busy ){ - Index *pISameName; /* Another index with the same name */ - Table *pTSameName; /* A table with same name as the index */ if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index; - if( (pISameName = sqlite3FindIndex(db, zName, db->aDb[iDb].zName))!=0 ){ + if( sqlite3FindIndex(db, zName, db->aDb[iDb].zName)!=0 ){ sqlite3ErrorMsg(pParse, "index %s already exists", zName); goto exit_create_index; } - if( (pTSameName = sqlite3FindTable(db, zName, 0))!=0 ){ + if( sqlite3FindTable(db, zName, 0)!=0 ){ sqlite3ErrorMsg(pParse, "there is already a table named %s", zName); goto exit_create_index; } @@ -2177,11 +2166,12 @@ /* ** Allocate the index structure. */ - pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 + - (sizeof(int) + sizeof(CollSeq*))*pList->nExpr ); + pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 + sizeof(int) + + (sizeof(int)*2 + sizeof(CollSeq*))*pList->nExpr ); if( sqlite3_malloc_failed ) goto exit_create_index; pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr]; - pIndex->zName = (char*)&pIndex->aiColumn[pList->nExpr]; + pIndex->aiRowEst = (unsigned*)&pIndex->aiColumn[pList->nExpr]; + pIndex->zName = (char*)&pIndex->aiRowEst[pList->nExpr+1]; strcpy(pIndex->zName, zName); pIndex->pTable = pTab; pIndex->nColumn = pList->nExpr; @@ -2217,6 +2207,7 @@ } } pIndex->keyInfo.nField = pList->nExpr; + sqlite3DefaultRowEst(pIndex); if( pTab==pParse->pNewTable ){ /* This routine has been called to create an automatic index as a @@ -2384,6 +2375,37 @@ } /* +** Fill the Index.aiRowEst[] array with default information - information +** to be used when we have not run the ANALYZE command. +** +** aiRowEst[0] is suppose to contain the number of elements in the index. +** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the +** number of rows in the table that match any particular value of the +** first column of the index. aiRowEst[2] is an estimate of the number +** of rows that match any particular combiniation of the first 2 columns +** of the index. And so forth. It must always be the case that +* +** aiRowEst[N]<=aiRowEst[N-1] +** aiRowEst[N]>=1 +** +** Apart from that, we have little to go on besides intuition as to +** how aiRowEst[] should be initialized. The numbers generated here +** are based on typical values found in actual indices. +*/ +void sqlite3DefaultRowEst(Index *pIdx){ + unsigned *a = pIdx->aiRowEst; + int i; + assert( a!=0 ); + a[0] = 1000000; + for(i=pIdx->nColumn; i>=1; i--){ + a[i] = 10; + } + if( pIdx->onError!=OE_None ){ + a[pIdx->nColumn] = 1; + } +} + +/* ** This routine will drop an existing named index. This routine ** implements the DROP INDEX statement. */ @@ -2445,34 +2467,95 @@ } /* +** ppArray points into a structure where there is an array pointer +** followed by two integers. The first integer is the +** number of elements in the structure array. The second integer +** is the number of allocated slots in the array. +** +** In other words, the structure looks something like this: +** +** struct Example1 { +** struct subElem *aEntry; +** int nEntry; +** int nAlloc; +** } +** +** The pnEntry parameter points to the equivalent of Example1.nEntry. +** +** This routine allocates a new slot in the array, zeros it out, +** and returns its index. If malloc fails a negative number is returned. +** +** szEntry is the sizeof of a single array entry. initSize is the +** number of array entries allocated on the initial allocation. +*/ +int sqlite3ArrayAllocate(void **ppArray, int szEntry, int initSize){ + char *p; + int *an = (int*)&ppArray[1]; + if( an[0]>=an[1] ){ + void *pNew; + int newSize; + newSize = an[1]*2 + initSize; + pNew = sqliteRealloc(*ppArray, newSize*szEntry); + if( pNew==0 ){ + return -1; + } + an[1] = newSize; + *ppArray = pNew; + } + p = *ppArray; + memset(&p[an[0]*szEntry], 0, szEntry); + return an[0]++; +} + +/* ** Append a new element to the given IdList. Create a new IdList if ** need be. ** ** A new IdList is returned, or NULL if malloc() fails. */ IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){ + int i; if( pList==0 ){ pList = sqliteMalloc( sizeof(IdList) ); if( pList==0 ) return 0; pList->nAlloc = 0; } - if( pList->nId>=pList->nAlloc ){ - struct IdList_item *a; - pList->nAlloc = pList->nAlloc*2 + 5; - a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]) ); - if( a==0 ){ - sqlite3IdListDelete(pList); - return 0; - } - pList->a = a; + i = sqlite3ArrayAllocate((void**)&pList->a, sizeof(pList->a[0]), 5); + if( i<0 ){ + sqlite3IdListDelete(pList); + return 0; } - memset(&pList->a[pList->nId], 0, sizeof(pList->a[0])); - pList->a[pList->nId].zName = sqlite3NameFromToken(pToken); - pList->nId++; + pList->a[i].zName = sqlite3NameFromToken(pToken); return pList; } /* +** Delete an IdList. +*/ +void sqlite3IdListDelete(IdList *pList){ + int i; + if( pList==0 ) return; + for(i=0; inId; i++){ + sqliteFree(pList->a[i].zName); + } + sqliteFree(pList->a); + sqliteFree(pList); +} + +/* +** Return the index in pList of the identifier named zId. Return -1 +** if not found. +*/ +int sqlite3IdListIndex(IdList *pList, const char *zName){ + int i; + if( pList==0 ) return -1; + for(i=0; inId; i++){ + if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i; + } + return -1; +} + +/* ** Append a new table name to the given SrcList. Create a new SrcList if ** need be. A new entry is created in the SrcList even if pToken is NULL. ** @@ -2557,32 +2640,6 @@ } /* -** Delete an IdList. -*/ -void sqlite3IdListDelete(IdList *pList){ - int i; - if( pList==0 ) return; - for(i=0; inId; i++){ - sqliteFree(pList->a[i].zName); - } - sqliteFree(pList->a); - sqliteFree(pList); -} - -/* -** Return the index in pList of the identifier named zId. Return -1 -** if not found. -*/ -int sqlite3IdListIndex(IdList *pList, const char *zName){ - int i; - if( pList==0 ) return -1; - for(i=0; inId; i++){ - if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i; - } - return -1; -} - -/* ** Delete an entire SrcList including all its substructure. */ void sqlite3SrcListDelete(SrcList *pList){ @@ -2784,7 +2841,7 @@ ** If pColl==0 then recompute all indices of pTab. */ #ifndef SQLITE_OMIT_REINDEX -void reindexTable(Parse *pParse, Table *pTab, CollSeq *pColl){ +static void reindexTable(Parse *pParse, Table *pTab, CollSeq *pColl){ Index *pIndex; /* An index associated with pTab */ for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){ @@ -2802,7 +2859,7 @@ ** all indices everywhere. */ #ifndef SQLITE_OMIT_REINDEX -void reindexDatabases(Parse *pParse, CollSeq *pColl){ +static void reindexDatabases(Parse *pParse, CollSeq *pColl){ Db *pDb; /* A single database */ int iDb; /* The database index number */ sqlite3 *db = pParse->db; /* The database connection */ @@ -2811,7 +2868,7 @@ for(iDb=0, pDb=db->aDb; iDbnDb; iDb++, pDb++){ if( pDb==0 ) continue; - for(k=sqliteHashFirst(&pDb->tblHash); k; k=sqliteHashNext(k)){ + for(k=sqliteHashFirst(&pDb->tblHash); k; k=sqliteHashNext(k)){ pTab = (Table*)sqliteHashData(k); reindexTable(pParse, pTab, pColl); } ======================================================================== --- sqlite/callback.c 0910b611e0c158f107ee3ff86f8a371654971e2b +++ sqlite/callback.c 9a1162c8f9dae9fad6d548339669aacb5f6cf76b @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.2 2005/05/25 10:45:10 danielk1977 Exp $ +** $Id: callback.c,v 1.3 2005/08/14 01:20:38 drh Exp $ */ #include "sqliteInt.h" @@ -147,7 +147,7 @@ ** the collation sequence name. A pointer to this string is stored in ** each collation sequence structure. */ -static CollSeq * findCollSeqEntry( +static CollSeq *findCollSeqEntry( sqlite3 *db, const char *zName, int nName, @@ -286,10 +286,9 @@ ** new entry to the hash table and return it. */ if( createFlag && bestmatch<6 && - (pBest = sqliteMalloc(sizeof(*pBest)+nName+1)) ){ + (pBest = sqliteMalloc(sizeof(*pBest)+nName)) ){ pBest->nArg = nArg; pBest->pNext = pFirst; - pBest->zName = (char*)&pBest[1]; pBest->iPrefEnc = enc; memcpy(pBest->zName, zName, nName); pBest->zName[nName] = 0; ======================================================================== --- sqlite/complete.c +++ sqlite/complete.c 641713ef01657f74037840abb9c0a4552c07b0d0 @@ -0,0 +1,272 @@ +/* +** 2001 September 15 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** An tokenizer for SQL +** +** This file contains C code that implements the sqlite3_complete() API. +** This code used to be part of the tokenizer.c source file. But by +** separating it out, the code will be automatically omitted from +** static links that do not use it. +** +** $Id: complete.c,v 1.1 2005/08/14 17:53:21 drh Exp $ +*/ +#include "sqliteInt.h" +#ifndef SQLITE_OMIT_COMPLETE + +/* +** This is defined in tokenize.c. We just have to import the definition. +*/ +extern const char sqlite3IsIdChar[]; +#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20])) + + +/* +** Token types used by the sqlite3_complete() routine. See the header +** comments on that procedure for additional information. +*/ +#define tkSEMI 0 +#define tkWS 1 +#define tkOTHER 2 +#define tkEXPLAIN 3 +#define tkCREATE 4 +#define tkTEMP 5 +#define tkTRIGGER 6 +#define tkEND 7 + +/* +** Return TRUE if the given SQL string ends in a semicolon. +** +** Special handling is require for CREATE TRIGGER statements. +** Whenever the CREATE TRIGGER keywords are seen, the statement +** must end with ";END;". +** +** This implementation uses a state machine with 7 states: +** +** (0) START At the beginning or end of an SQL statement. This routine +** returns 1 if it ends in the START state and 0 if it ends +** in any other state. +** +** (1) NORMAL We are in the middle of statement which ends with a single +** semicolon. +** +** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of +** a statement. +** +** (3) CREATE The keyword CREATE has been seen at the beginning of a +** statement, possibly preceeded by EXPLAIN and/or followed by +** TEMP or TEMPORARY +** +** (4) TRIGGER We are in the middle of a trigger definition that must be +** ended by a semicolon, the keyword END, and another semicolon. +** +** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at +** the end of a trigger definition. +** +** (6) END We've seen the ";END" of the ";END;" that occurs at the end +** of a trigger difinition. +** +** Transitions between states above are determined by tokens extracted +** from the input. The following tokens are significant: +** +** (0) tkSEMI A semicolon. +** (1) tkWS Whitespace +** (2) tkOTHER Any other SQL token. +** (3) tkEXPLAIN The "explain" keyword. +** (4) tkCREATE The "create" keyword. +** (5) tkTEMP The "temp" or "temporary" keyword. +** (6) tkTRIGGER The "trigger" keyword. +** (7) tkEND The "end" keyword. +** +** Whitespace never causes a state transition and is always ignored. +** +** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed +** to recognize the end of a trigger can be omitted. All we have to do +** is look for a semicolon that is not part of an string or comment. +*/ +int sqlite3_complete(const char *zSql){ + const char *tmp; + return sqlite3_complete_last(zSql, &tmp); +} + +int sqlite3_complete_last(const char *zSql, const char **last){ + u8 state = 0; /* Current state, using numbers defined in header comment */ + u8 token; /* Value of the next token */ + const char* lastseen = 0; + +#ifndef SQLITE_OMIT_TRIGGER + /* A complex statement machine used to detect the end of a CREATE TRIGGER + ** statement. This is the normal case. + */ + static const u8 trans[7][8] = { + /* Token: */ + /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */ + /* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, }, + /* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, }, + /* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, }, + /* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, }, + /* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, }, + /* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, }, + /* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, }, + }; +#else + /* If triggers are not suppored by this compile then the statement machine + ** used to detect the end of a statement is much simplier + */ + static const u8 trans[2][3] = { + /* Token: */ + /* State: ** SEMI WS OTHER */ + /* 0 START: */ { 0, 0, 1, }, + /* 1 NORMAL: */ { 0, 1, 1, }, + }; +#endif /* SQLITE_OMIT_TRIGGER */ + + while( *zSql ){ + switch( *zSql ){ + case ';': { /* A semicolon */ + token = tkSEMI; + break; + } + case ' ': + case '\r': + case '\t': + case '\n': + case '\f': { /* White space is ignored */ + token = tkWS; + break; + } + case '/': { /* C-style comments */ + if( zSql[1]!='*' ){ + token = tkOTHER; + break; + } + zSql += 2; + while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; } + if( zSql[0]==0 ) { *last = lastseen; return 0; } + zSql++; + token = tkWS; + break; + } + case '-': { /* SQL-style comments from "--" to end of line */ + if( zSql[1]!='-' ){ + token = tkOTHER; + break; + } + while( *zSql && *zSql!='\n' ){ zSql++; } + if( *zSql==0 ) { *last = lastseen; return state==0; } + token = tkWS; + break; + } + case '[': { /* Microsoft-style identifiers in [...] */ + zSql++; + while( *zSql && *zSql!=']' ){ zSql++; } + if( *zSql==0 ) { *last = lastseen; return 0; } + token = tkOTHER; + break; + } + case '`': /* Grave-accent quoted symbols used by MySQL */ + case '"': /* single- and double-quoted strings */ + case '\'': { + int c = *zSql; + zSql++; + while( *zSql && *zSql!=c ){ zSql++; } + if( *zSql==0 ) {*last = lastseen; return 0; } + token = tkOTHER; + break; + } + default: { + int c; + if( IdChar((u8)*zSql) ){ + /* Keywords and unquoted identifiers */ + int nId; + for(nId=1; IdChar(zSql[nId]); nId++){} +#ifdef SQLITE_OMIT_TRIGGER + token = tkOTHER; +#else + switch( *zSql ){ + case 'c': case 'C': { + if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){ + token = tkCREATE; + }else{ + token = tkOTHER; + } + break; + } + case 't': case 'T': { + if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){ + token = tkTRIGGER; + }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){ + token = tkTEMP; + }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){ + token = tkTEMP; + }else{ + token = tkOTHER; + } + break; + } + case 'e': case 'E': { + if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){ + token = tkEND; + }else +#ifndef SQLITE_OMIT_EXPLAIN + if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){ + token = tkEXPLAIN; + }else +#endif + { + token = tkOTHER; + } + break; + } + default: { + token = tkOTHER; + break; + } + } +#endif /* SQLITE_OMIT_TRIGGER */ + zSql += nId-1; + }else{ + /* Operators and special symbols */ + token = tkOTHER; + } + break; + } + } + state = trans[state][token]; + if (state == 0) + lastseen = zSql; + zSql++; + } + *last = lastseen; + return state==0; +} + +#ifndef SQLITE_OMIT_UTF16 +/* +** This routine is the same as the sqlite3_complete() routine described +** above, except that the parameter is required to be UTF-16 encoded, not +** UTF-8. +*/ +int sqlite3_complete16(const void *zSql){ + sqlite3_value *pVal; + char const *zSql8; + int rc = 0; + + pVal = sqlite3ValueNew(); + sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC); + zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8); + if( zSql8 ){ + rc = sqlite3_complete(zSql8); + } + sqlite3ValueFree(pVal); + return rc; +} +#endif /* SQLITE_OMIT_UTF16 */ +#endif /* SQLITE_OMIT_COMPLETE */ ======================================================================== --- sqlite/date.c 2134ef4388256e8247405178df8a61bd60dc180a +++ sqlite/date.c 7444b0900a28da77e57e3337a636873cff0ae940 @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.44 2005/03/21 00:43:44 drh Exp $ +** $Id: date.c,v 1.45 2005/06/25 18:42:14 drh Exp $ ** ** NOTES: ** @@ -124,11 +124,7 @@ ** Read text from z[] and convert into a floating point number. Return ** the number of digits converted. */ -static int getValue(const char *z, double *pR){ - const char *zEnd; - *pR = sqlite3AtoF(z, &zEnd); - return zEnd - z; -} +#define getValue sqlite3AtoF /* ** Parse a timezone extension on the end of a date-time. @@ -320,7 +316,7 @@ p->validJD = 1; return 0; }else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){ - p->rJD = sqlite3AtoF(zDate, 0); + getValue(zDate, &p->rJD); p->validJD = 1; return 0; } ======================================================================== --- sqlite/delete.c 4b68127f55971c7fb459146e0b6cf3bd70cfffe9 +++ sqlite/delete.c 16a0e19460b14d219f39ff5c7a9eef808aa1969c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** in order to generate code for DELETE FROM statements. ** -** $Id: delete.c,v 1.106 2005/06/12 21:35:52 drh Exp $ +** $Id: delete.c,v 1.110 2005/09/08 01:58:43 drh Exp $ */ #include "sqliteInt.h" @@ -65,8 +65,8 @@ Table *pTab /* The table to be opened */ ){ sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); - sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum); VdbeComment((v, "# %s", pTab->zName)); + sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum); sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol); } @@ -178,12 +178,12 @@ if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb); - /* If we are trying to delete from a view, construct that view into - ** a temporary table. + /* If we are trying to delete from a view, realize that view into + ** a ephemeral table. */ if( isView ){ Select *pView = sqlite3SelectDup(pTab->pSelect); - sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0); + sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0); sqlite3SelectDelete(pView); } @@ -240,7 +240,7 @@ /* Remember the rowid of every item to be deleted. */ sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); - sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0); + sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0); if( db->flags & SQLITE_CountRows ){ sqlite3VdbeAddOp(v, OP_AddImm, 1, 0); } @@ -260,14 +260,13 @@ ** database scan. We have to delete items after the scan is complete ** because deleting an item can change the scan order. */ - sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0); end = sqlite3VdbeMakeLabel(v); /* This is the beginning of the delete loop when there are ** row triggers. */ if( triggers_exist ){ - addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end); + addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end); if( !isView ){ sqlite3VdbeAddOp(v, OP_Dup, 0, 0); sqlite3OpenTableForReading(v, iCur, pTab); @@ -288,7 +287,7 @@ if( !isView ){ /* Open cursors for the table we are deleting from and all its ** indices. If there are row triggers, this happens inside the - ** OP_ListRead loop because the cursor have to all be closed + ** OP_FifoRead loop because the cursor have to all be closed ** before the trigger fires. If there are no row triggers, the ** cursors are opened only once on the outside the loop. */ @@ -297,7 +296,7 @@ /* This is the beginning of the delete loop when there are no ** row triggers */ if( !triggers_exist ){ - addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end); + addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end); } /* Delete the row */ @@ -322,7 +321,6 @@ /* End of the delete loop */ sqlite3VdbeAddOp(v, OP_Goto, 0, addr); sqlite3VdbeResolveLabel(v, end); - sqlite3VdbeAddOp(v, OP_ListReset, 0, 0); /* Close the cursors after the loop if there are no row triggers */ if( !triggers_exist ){ @@ -442,6 +440,6 @@ sqlite3ColumnDefault(v, pTab, idx); } } - sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24)); + sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); } ======================================================================== --- sqlite/expr.c 6d7058944c5f4b7e4304be3fe63ada91dac221a1 +++ sqlite/expr.c b8dbd5a30e80b83b0c1e137dcfcd687bd5d2b76c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.206 2005/06/12 21:35:52 drh Exp $ +** $Id: expr.c,v 1.228 2005/09/16 02:38:10 drh Exp $ */ #include "sqliteInt.h" #include @@ -34,12 +34,18 @@ ** SELECT * FROM t1 WHERE (select a from t1); */ char sqlite3ExprAffinity(Expr *pExpr){ - if( pExpr->op==TK_AS ){ + int op = pExpr->op; + if( op==TK_AS ){ return sqlite3ExprAffinity(pExpr->pLeft); } - if( pExpr->op==TK_SELECT ){ + if( op==TK_SELECT ){ return sqlite3ExprAffinity(pExpr->pSelect->pEList->a[0].pExpr); } +#ifndef SQLITE_OMIT_CAST + if( op==TK_CAST ){ + return sqlite3AffinityType(&pExpr->token); + } +#endif return pExpr->affinity; } @@ -51,7 +57,7 @@ CollSeq *pColl = 0; if( pExpr ){ pColl = pExpr->pColl; - if( pExpr->op==TK_AS && !pColl ){ + if( (pExpr->op==TK_AS || pExpr->op==TK_CAST) && !pColl ){ return sqlite3ExprCollSeq(pParse, pExpr->pLeft); } } @@ -87,6 +93,7 @@ return SQLITE_AFF_NONE; }else{ /* One side is a column, the other is not. Use the columns affinity. */ + assert( aff1==0 || aff2==0 ); return (aff1 + aff2); } } @@ -207,9 +214,8 @@ /* ** When doing a nested parse, you can include terms in an expression ** that look like this: #0 #1 #2 ... These terms refer to elements -** on the stack. "#0" (or just "#") means the top of the stack. -** "#1" means the next down on the stack. And so forth. #-1 means -** memory location 0. #-2 means memory location 1. And so forth. +** on the stack. "#0" means the top of the stack. +** "#1" means the next down on the stack. And so forth. ** ** This routine is called by the parser to deal with on of those terms. ** It immediately generates code to store the value in a memory location. @@ -220,23 +226,19 @@ Vdbe *v = pParse->pVdbe; Expr *p; int depth; - if( v==0 ) return 0; if( pParse->nested==0 ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken); return 0; } + if( v==0 ) return 0; p = sqlite3Expr(TK_REGISTER, 0, 0, pToken); if( p==0 ){ return 0; /* Malloc failed */ } depth = atoi(&pToken->z[1]); - if( depth>=0 ){ - p->iTable = pParse->nMem++; - sqlite3VdbeAddOp(v, OP_Dup, depth, 0); - sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1); - }else{ - p->iTable = -1-depth; - } + p->iTable = pParse->nMem++; + sqlite3VdbeAddOp(v, OP_Dup, depth, 0); + sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1); return p; } @@ -353,7 +355,7 @@ pExpr->iTable = ++pParse->nVar; if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){ pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10; - pParse->apVarExpr = sqliteRealloc(pParse->apVarExpr, + sqlite3ReallocOrFree((void**)&pParse->apVarExpr, pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) ); } if( !sqlite3_malloc_failed ){ @@ -378,7 +380,22 @@ sqliteFree(p); } +/* +** The Expr.token field might be a string literal that is quoted. +** If so, remove the quotation marks. +*/ +void sqlite3DequoteExpr(Expr *p){ + if( ExprHasAnyProperty(p, EP_Dequoted) ){ + return; + } + ExprSetProperty(p, EP_Dequoted); + if( p->token.dyn==0 ){ + sqlite3TokenCopy(&p->token, &p->token); + } + sqlite3Dequote((char*)p->token.z); +} + /* ** The following group of routines make deep copies of expressions, ** expression lists, ID lists, and select statements. The copies can @@ -529,9 +546,12 @@ pNew->pOffset = sqlite3ExprDup(p->pOffset); pNew->iLimit = -1; pNew->iOffset = -1; - pNew->ppOpenTemp = 0; pNew->isResolved = p->isResolved; pNew->isAgg = p->isAgg; + pNew->pRightmost = 0; + pNew->addrOpenVirt[0] = -1; + pNew->addrOpenVirt[1] = -1; + pNew->addrOpenVirt[2] = -1; return pNew; } #else @@ -607,6 +627,8 @@ ** ** The return value from this routine is 1 to abandon the tree walk ** and 0 to continue. +** +** NOTICE: This routine does *not* descend into subqueries. */ static int walkExprList(ExprList *, int (*)(void *, Expr*), void *); static int walkExprTree(Expr *pExpr, int (*xFunc)(void*,Expr*), void *pArg){ @@ -664,17 +686,27 @@ */ static int exprNodeIsConstant(void *pArg, Expr *pExpr){ switch( pExpr->op ){ + /* Consider functions to be constant if all their arguments are constant + ** and *pArg==2 */ + case TK_FUNCTION: + if( *((int*)pArg)==2 ) return 0; + /* Fall through */ case TK_ID: case TK_COLUMN: case TK_DOT: case TK_AGG_FUNCTION: - case TK_FUNCTION: + case TK_AGG_COLUMN: #ifndef SQLITE_OMIT_SUBQUERY case TK_SELECT: case TK_EXISTS: #endif *((int*)pArg) = 0; return 2; + case TK_IN: + if( pExpr->pSelect ){ + *((int*)pArg) = 0; + return 2; + } default: return 0; } @@ -682,7 +714,7 @@ /* ** Walk an expression tree. Return 1 if the expression is constant -** and 0 if it involves variables. +** and 0 if it involves variables or function calls. ** ** For the purposes of this function, a double-quoted string (ex: "abc") ** is considered a variable but a single-quoted string (ex: 'abc') is @@ -695,6 +727,21 @@ } /* +** Walk an expression tree. Return 1 if the expression is constant +** or a function call with constant arguments. Return and 0 if there +** are any variables. +** +** For the purposes of this function, a double-quoted string (ex: "abc") +** is considered a variable but a single-quoted string (ex: 'abc') is +** a constant. +*/ +int sqlite3ExprIsConstantOrFunction(Expr *p){ + int isConst = 2; + walkExprTree(p, exprNodeIsConstant, &isConst); + return isConst!=0; +} + +/* ** If the expression p codes a constant integer that is small enough ** to fit in a 32-bit integer, return 1 and put the value of the integer ** in *pValue. If the expression is not an integer or if it is too big @@ -1184,11 +1231,19 @@ NameContext *pNC, /* Namespace to resolve expressions in. */ Expr *pExpr /* The expression to be analyzed. */ ){ + int savedHasAgg; if( pExpr==0 ) return 0; + savedHasAgg = pNC->hasAgg; + pNC->hasAgg = 0; walkExprTree(pExpr, nameResolverStep, pNC); if( pNC->nErr>0 ){ ExprSetProperty(pExpr, EP_Error); } + if( pNC->hasAgg ){ + ExprSetProperty(pExpr, EP_Agg); + }else if( savedHasAgg ){ + pNC->hasAgg = 1; + } return ExprHasProperty(pExpr, EP_Error); } @@ -1218,37 +1273,39 @@ */ #ifndef SQLITE_OMIT_SUBQUERY void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ - int label = 0; /* Address after sub-select code */ + int testAddr = 0; /* One-time test address */ Vdbe *v = sqlite3GetVdbe(pParse); if( v==0 ) return; - /* If this is not a variable (correlated) select, then execute - ** it only once. Unless this is part of a trigger program. In - ** that case re-execute every time (this could be optimized). + /* This code must be run in its entirety every time it is encountered + ** if any of the following is true: + ** + ** * The right-hand side is a correlated subquery + ** * The right-hand side is an expression list containing variables + ** * We are inside a trigger + ** + ** If all of the above are false, then we can run this code just once + ** save the results, and reuse the same result on subsequent invocations. */ if( !ExprHasAnyProperty(pExpr, EP_VarSelect) && !pParse->trigStack ){ int mem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0); - label = sqlite3VdbeMakeLabel(v); - sqlite3VdbeAddOp(v, OP_If, 0, label); + testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0); + assert( testAddr>0 || sqlite3_malloc_failed ); sqlite3VdbeAddOp(v, OP_Integer, 1, 0); sqlite3VdbeAddOp(v, OP_MemStore, mem, 1); } - if( pExpr->pSelect ){ - sqlite3VdbeAddOp(v, OP_AggContextPush, 0, 0); - } - switch( pExpr->op ){ case TK_IN: { char affinity; KeyInfo keyInfo; - int addr; /* Address of OP_OpenTemp instruction */ + int addr; /* Address of OP_OpenVirtual instruction */ affinity = sqlite3ExprAffinity(pExpr->pLeft); /* Whether this is an 'x IN(SELECT...)' or an 'x IN()' - ** expression it is handled the same way. A temporary table is + ** expression it is handled the same way. A virtual table is ** filled with single-field index keys representing the results ** from the SELECT or the . ** @@ -1261,7 +1318,7 @@ ** is used. */ pExpr->iTable = pParse->nTab++; - addr = sqlite3VdbeAddOp(v, OP_OpenTemp, pExpr->iTable, 0); + addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, pExpr->iTable, 0); memset(&keyInfo, 0, sizeof(keyInfo)); keyInfo.nField = 1; sqlite3VdbeAddOp(v, OP_SetNumColumns, pExpr->iTable, 1); @@ -1290,20 +1347,30 @@ ** a column, use numeric affinity. */ int i; + ExprList *pList = pExpr->pList; + struct ExprList_item *pItem; + if( !affinity ){ affinity = SQLITE_AFF_NUMERIC; } keyInfo.aColl[0] = pExpr->pLeft->pColl; /* Loop through each expression in . */ - for(i=0; ipList->nExpr; i++){ - Expr *pE2 = pExpr->pList->a[i].pExpr; + for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){ + Expr *pE2 = pItem->pExpr; - /* Check that the expression is constant and valid. */ - if( !sqlite3ExprIsConstant(pE2) ){ - sqlite3ErrorMsg(pParse, - "right-hand side of IN operator must be constant"); - return; + /* If the expression is not constant then we will need to + ** disable the test that was generated above that makes sure + ** this code only executes once. Because for a non-constant + ** expression we need to rerun this code each time. + */ + if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){ + VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1); + int i; + for(i=0; i<4; i++){ + aOp[i].opcode = OP_Noop; + } + testAddr = 0; } /* Evaluate the expression and insert it into the temp table */ @@ -1341,12 +1408,9 @@ } } - if( pExpr->pSelect ){ - sqlite3VdbeAddOp(v, OP_AggContextPop, 0, 0); + if( testAddr ){ + sqlite3VdbeChangeP2(v, testAddr, sqlite3VdbeCurrentAddr(v)); } - if( label<0 ){ - sqlite3VdbeResolveLabel(v, label); - } return; } #endif /* SQLITE_OMIT_SUBQUERY */ @@ -1360,7 +1424,7 @@ if( sqlite3GetInt32(z, &i) ){ sqlite3VdbeAddOp(v, OP_Integer, i, 0); }else if( sqlite3FitsIn64Bits(z) ){ - sqlite3VdbeOp3(v, OP_Integer, 0, 0, z, n); + sqlite3VdbeOp3(v, OP_Int64, 0, 0, z, n); }else{ sqlite3VdbeOp3(v, OP_Real, 0, 0, z, n); } @@ -1386,10 +1450,21 @@ } op = pExpr->op; switch( op ){ + case TK_AGG_COLUMN: { + AggInfo *pAggInfo = pExpr->pAggInfo; + struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg]; + if( !pAggInfo->directMode ){ + sqlite3VdbeAddOp(v, OP_MemLoad, pCol->iMem, 0); + break; + }else if( pAggInfo->useSortingIdx ){ + sqlite3VdbeAddOp(v, OP_Column, pAggInfo->sortingIdx, + pCol->iSorterColumn); + break; + } + /* Otherwise, fall thru into the TK_COLUMN case */ + } case TK_COLUMN: { - if( !pParse->fillAgg && pExpr->iAgg>=0 ){ - sqlite3VdbeAddOp(v, OP_AggGet, pExpr->iAggCtx, pExpr->iAgg); - }else if( pExpr->iColumn>=0 ){ + if( pExpr->iColumn>=0 ){ sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn); sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn); }else{ @@ -1405,8 +1480,8 @@ case TK_STRING: { assert( TK_FLOAT==OP_Real ); assert( TK_STRING==OP_String8 ); + sqlite3DequoteExpr(pExpr); sqlite3VdbeOp3(v, op, 0, 0, pExpr->token.z, pExpr->token.n); - sqlite3VdbeDequoteP3(v, -1); break; } case TK_NULL: { @@ -1415,9 +1490,16 @@ } #ifndef SQLITE_OMIT_BLOB_LITERAL case TK_BLOB: { + int n; + const char *z; assert( TK_BLOB==OP_HexBlob ); - sqlite3VdbeOp3(v, op, 0, 0, pExpr->token.z+1, pExpr->token.n-1); - sqlite3VdbeDequoteP3(v, -1); + n = pExpr->token.n - 3; + z = pExpr->token.z + 2; + assert( n>=0 ); + if( n==0 ){ + z = ""; + } + sqlite3VdbeOp3(v, op, 0, 0, z, n); break; } #endif @@ -1432,6 +1514,22 @@ sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iTable, 0); break; } +#ifndef SQLITE_OMIT_CAST + case TK_CAST: { + /* Expressions of the form: CAST(pLeft AS token) */ + int aff, op; + sqlite3ExprCode(pParse, pExpr->pLeft); + aff = sqlite3AffinityType(&pExpr->token); + switch( aff ){ + case SQLITE_AFF_INTEGER: op = OP_ToInt; break; + case SQLITE_AFF_NUMERIC: op = OP_ToNumeric; break; + case SQLITE_AFF_TEXT: op = OP_ToText; break; + case SQLITE_AFF_NONE: op = OP_ToBlob; break; + } + sqlite3VdbeAddOp(v, op, 0, 0); + break; + } +#endif /* SQLITE_OMIT_CAST */ case TK_LT: case TK_LE: case TK_GT: @@ -1515,7 +1613,8 @@ break; } case TK_AGG_FUNCTION: { - sqlite3VdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg); + AggInfo *pInfo = pExpr->pAggInfo; + sqlite3VdbeAddOp(v, OP_MemLoad, pInfo->aFunc[pExpr->iAgg].iMem, 0); break; } case TK_CONST_FUNC: @@ -1525,7 +1624,7 @@ FuncDef *pDef; int nId; const char *zId; - int p2 = 0; + int constMask = 0; int i; u8 enc = pParse->db->enc; CollSeq *pColl = 0; @@ -1536,7 +1635,7 @@ nExpr = sqlite3ExprCodeExprList(pParse, pList); for(i=0; ia[i].pExpr) ){ - p2 |= (1<needCollSeq && !pColl ){ pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); @@ -1546,7 +1645,7 @@ if( !pColl ) pColl = pParse->db->pDfltColl; sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ); } - sqlite3VdbeOp3(v, OP_Function, nExpr, p2, (char*)pDef, P3_FUNCDEF); + sqlite3VdbeOp3(v, OP_Function, constMask, nExpr, (char*)pDef, P3_FUNCDEF); break; } #ifndef SQLITE_OMIT_SUBQUERY @@ -1663,9 +1762,9 @@ assert( pExpr->iColumn==OE_Rollback || pExpr->iColumn == OE_Abort || pExpr->iColumn == OE_Fail ); + sqlite3DequoteExpr(pExpr); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn, pExpr->token.z, pExpr->token.n); - sqlite3VdbeDequoteP3(v, -1); } else { assert( pExpr->iColumn == OE_Ignore ); sqlite3VdbeAddOp(v, OP_ContextPop, 0, 0); @@ -1717,11 +1816,9 @@ ){ struct ExprList_item *pItem; int i, n; - Vdbe *v; if( pList==0 ) return 0; - v = sqlite3GetVdbe(pParse); n = pList->nExpr; - for(pItem=pList->a, i=0; ia, i=n; i>0; i--, pItem++){ sqlite3ExprCode(pParse, pItem->pExpr); } return n; @@ -1941,6 +2038,7 @@ return 0; } if( pA->op!=pB->op ) return 0; + if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 0; if( !sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 0; if( !sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 0; if( pA->pList ){ @@ -1964,25 +2062,34 @@ return 1; } + /* -** Add a new element to the pParse->aAgg[] array and return its index. -** The new element is initialized to zero. The calling function is -** expected to fill it in. +** Add a new element to the pAggInfo->aCol[] array. Return the index of +** the new element. Return a negative number if malloc fails. */ -static int appendAggInfo(Parse *pParse){ - if( (pParse->nAgg & 0x7)==0 ){ - int amt = pParse->nAgg + 8; - AggExpr *aAgg = sqliteRealloc(pParse->aAgg, amt*sizeof(pParse->aAgg[0])); - if( aAgg==0 ){ - return -1; - } - pParse->aAgg = aAgg; +static int addAggInfoColumn(AggInfo *pInfo){ + int i; + i = sqlite3ArrayAllocate((void**)&pInfo->aCol, sizeof(pInfo->aCol[0]), 3); + if( i<0 ){ + return -1; } - memset(&pParse->aAgg[pParse->nAgg], 0, sizeof(pParse->aAgg[0])); - return pParse->nAgg++; -} + return i; +} /* +** Add a new element to the pAggInfo->aFunc[] array. Return the index of +** the new element. Return a negative number if malloc fails. +*/ +static int addAggInfoFunc(AggInfo *pInfo){ + int i; + i = sqlite3ArrayAllocate((void**)&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2); + if( i<0 ){ + return -1; + } + return i; +} + +/* ** This is an xFunc for walkExprTree() used to implement ** sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates ** for additional information. @@ -1991,60 +2098,118 @@ */ static int analyzeAggregate(void *pArg, Expr *pExpr){ int i; - AggExpr *aAgg; NameContext *pNC = (NameContext *)pArg; Parse *pParse = pNC->pParse; SrcList *pSrcList = pNC->pSrcList; + AggInfo *pAggInfo = pNC->pAggInfo; + switch( pExpr->op ){ case TK_COLUMN: { - for(i=0; pSrcList && inSrc; i++){ - if( pExpr->iTable==pSrcList->a[i].iCursor ){ - aAgg = pParse->aAgg; - for(i=0; inAgg; i++){ - if( aAgg[i].isAgg ) continue; - if( aAgg[i].pExpr->iTable==pExpr->iTable - && aAgg[i].pExpr->iColumn==pExpr->iColumn ){ - break; + /* Check to see if the column is in one of the tables in the FROM + ** clause of the aggregate query */ + if( pSrcList ){ + struct SrcList_item *pItem = pSrcList->a; + for(i=0; inSrc; i++, pItem++){ + struct AggInfo_col *pCol; + if( pExpr->iTable==pItem->iCursor ){ + /* If we reach this point, it means that pExpr refers to a table + ** that is in the FROM clause of the aggregate query. + ** + ** Make an entry for the column in pAggInfo->aCol[] if there + ** is not an entry there already. + */ + pCol = pAggInfo->aCol; + for(i=0; inColumn; i++, pCol++){ + if( pCol->iTable==pExpr->iTable && + pCol->iColumn==pExpr->iColumn ){ + break; + } } - } - if( i>=pParse->nAgg ){ - i = appendAggInfo(pParse); - if( i<0 ) return 1; - pParse->aAgg[i].isAgg = 0; - pParse->aAgg[i].pExpr = pExpr; - } - pExpr->iAgg = i; - pExpr->iAggCtx = pNC->nDepth; - return 1; - } + if( i>=pAggInfo->nColumn && (i = addAggInfoColumn(pAggInfo))>=0 ){ + pCol = &pAggInfo->aCol[i]; + pCol->iTable = pExpr->iTable; + pCol->iColumn = pExpr->iColumn; + pCol->iMem = pParse->nMem++; + pCol->iSorterColumn = -1; + pCol->pExpr = pExpr; + if( pAggInfo->pGroupBy ){ + int j, n; + ExprList *pGB = pAggInfo->pGroupBy; + struct ExprList_item *pTerm = pGB->a; + n = pGB->nExpr; + for(j=0; jpExpr; + if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable && + pE->iColumn==pExpr->iColumn ){ + pCol->iSorterColumn = j; + break; + } + } + } + if( pCol->iSorterColumn<0 ){ + pCol->iSorterColumn = pAggInfo->nSortingColumn++; + } + } + /* There is now an entry for pExpr in pAggInfo->aCol[] (either + ** because it was there before or because we just created it). + ** Convert the pExpr to be a TK_AGG_COLUMN referring to that + ** pAggInfo->aCol[] entry. + */ + pExpr->pAggInfo = pAggInfo; + pExpr->op = TK_AGG_COLUMN; + pExpr->iAgg = i; + break; + } /* endif pExpr->iTable==pItem->iCursor */ + } /* end loop over pSrcList */ } return 1; } case TK_AGG_FUNCTION: { + /* The pNC->nDepth==0 test causes aggregate functions in subqueries + ** to be ignored */ if( pNC->nDepth==0 ){ - aAgg = pParse->aAgg; - for(i=0; inAgg; i++){ - if( !aAgg[i].isAgg ) continue; - if( sqlite3ExprCompare(aAgg[i].pExpr, pExpr) ){ + /* Check to see if pExpr is a duplicate of another aggregate + ** function that is already in the pAggInfo structure + */ + struct AggInfo_func *pItem = pAggInfo->aFunc; + for(i=0; inFunc; i++, pItem++){ + if( sqlite3ExprCompare(pItem->pExpr, pExpr) ){ break; } } - if( i>=pParse->nAgg ){ + if( i>=pAggInfo->nFunc ){ + /* pExpr is original. Make a new entry in pAggInfo->aFunc[] + */ u8 enc = pParse->db->enc; - i = appendAggInfo(pParse); - if( i<0 ) return 1; - pParse->aAgg[i].isAgg = 1; - pParse->aAgg[i].pExpr = pExpr; - pParse->aAgg[i].pFunc = sqlite3FindFunction(pParse->db, - pExpr->token.z, pExpr->token.n, - pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0); + i = addAggInfoFunc(pAggInfo); + if( i>=0 ){ + pItem = &pAggInfo->aFunc[i]; + pItem->pExpr = pExpr; + pItem->iMem = pParse->nMem++; + pItem->pFunc = sqlite3FindFunction(pParse->db, + pExpr->token.z, pExpr->token.n, + pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0); + if( pExpr->flags & EP_Distinct ){ + pItem->iDistinct = pParse->nTab++; + }else{ + pItem->iDistinct = -1; + } + } } + /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry + */ pExpr->iAgg = i; + pExpr->pAggInfo = pAggInfo; return 1; } } } + + /* Recursively walk subqueries looking for TK_COLUMN nodes that need + ** to be changed to TK_AGG_COLUMN. But increment nDepth so that + ** TK_AGG_FUNCTION nodes in subqueries will be unchanged. + */ if( pExpr->pSelect ){ pNC->nDepth++; walkSelectExpr(pExpr->pSelect, analyzeAggregate, pNC); @@ -2069,3 +2234,21 @@ walkExprTree(pExpr, analyzeAggregate, pNC); return pNC->pParse->nErr - nErr; } + +/* +** Call sqlite3ExprAnalyzeAggregates() for every expression in an +** expression list. Return the number of errors. +** +** If an error is found, the analysis is cut short. +*/ +int sqlite3ExprAnalyzeAggList(NameContext *pNC, ExprList *pList){ + struct ExprList_item *pItem; + int i; + int nErr = 0; + if( pList ){ + for(pItem=pList->a, i=0; nErr==0 && inExpr; i++, pItem++){ + nErr += sqlite3ExprAnalyzeAggregates(pNC, pItem->pExpr); + } + } + return nErr; +} ======================================================================== --- sqlite/func.c f208d71f741d47b63277530939f552815af8ce35 +++ sqlite/func.c f63d417248808ff2632a3b576536abffcc21d858 @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.98 2005/05/24 12:01:02 danielk1977 Exp $ +** $Id: func.c,v 1.110 2005/09/08 20:37:43 drh Exp $ */ #include "sqliteInt.h" #include @@ -26,6 +26,9 @@ #include "vdbeInt.h" #include "os.h" +/* +** Return the collating function associated with a function. +*/ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ return context->pColl; } @@ -78,6 +81,7 @@ sqlite3_result_text(context, z, -1, SQLITE_STATIC); } + /* ** Implementation of the length() function */ @@ -183,7 +187,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; - char zBuf[100]; + char zBuf[500]; /* larger than the %f representation of the largest double */ assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; @@ -193,7 +197,7 @@ } if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; r = sqlite3_value_double(argv[0]); - sprintf(zBuf,"%.*f",n,r); + sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r); sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } @@ -307,8 +311,14 @@ u8 matchSet; u8 noCase; }; + static const struct compareInfo globInfo = { '*', '?', '[', 0 }; -static const struct compareInfo likeInfo = { '%', '_', 0, 1 }; +/* The correct SQL-92 behavior is for the LIKE operator to ignore +** case. Thus 'a' LIKE 'A' would be true. */ +static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 }; +/* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator +** is case sensitive causing 'a' LIKE 'A' to be false */ +static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }; /* ** X is a pointer to the first byte of a UTF-8 character. Increment @@ -450,7 +460,16 @@ return *zString==0; } +/* +** Count the number of times that the LIKE operator (or GLOB which is +** just a variation of LIKE) gets called. This is used for testing +** only. +*/ +#ifdef SQLITE_TEST +int sqlite3_like_count = 0; +#endif + /* ** Implementation of the like() SQL function. This function implements ** the build-in LIKE operator. The first argument to the function is the @@ -460,8 +479,8 @@ ** ** is implemented as like(B,A). ** -** If the pointer retrieved by via a call to sqlite3_user_data() is -** not NULL, then this function uses UTF-16. Otherwise UTF-8. +** This same function (with a different compareInfo structure) computes +** the GLOB operator. */ static void likeFunc( sqlite3_context *context, @@ -484,28 +503,15 @@ escape = sqlite3ReadUtf8(zEsc); } if( zA && zB ){ - sqlite3_result_int(context, patternCompare(zA, zB, &likeInfo, escape)); + struct compareInfo *pInfo = sqlite3_user_data(context); +#ifdef SQLITE_TEST + sqlite3_like_count++; +#endif + sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape)); } } /* -** Implementation of the glob() SQL function. This function implements -** the build-in GLOB operator. The first argument to the function is the -** string and the second argument is the pattern. So, the SQL statements: -** -** A GLOB B -** -** is implemented as glob(B,A). -*/ -static void globFunc(sqlite3_context *context, int arg, sqlite3_value **argv){ - const unsigned char *zA = sqlite3_value_text(argv[0]); - const unsigned char *zB = sqlite3_value_text(argv[1]); - if( zA && zB ){ - sqlite3_result_int(context, patternCompare(zA, zB, &globInfo, 0)); - } -} - -/* ** Implementation of the NULLIF(x,y) function. The result is the first ** argument if the arguments are different. The result is NULL if the ** arguments are equal to each other. @@ -813,6 +819,7 @@ struct SumCtx { double sum; /* Sum of terms */ int cnt; /* Number of elements summed */ + u8 seenFloat; /* True if there has been any floating point value */ }; /* @@ -820,21 +827,32 @@ */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; - if( argc<1 ) return; + int type; + assert( argc==1 ); p = sqlite3_aggregate_context(context, sizeof(*p)); - if( p && SQLITE_NULL!=sqlite3_value_type(argv[0]) ){ + type = sqlite3_value_type(argv[0]); + if( p && type!=SQLITE_NULL ){ p->sum += sqlite3_value_double(argv[0]); p->cnt++; + if( type==SQLITE_FLOAT ){ + p->seenFloat = 1; + } } } static void sumFinalize(sqlite3_context *context){ SumCtx *p; - p = sqlite3_aggregate_context(context, sizeof(*p)); - sqlite3_result_double(context, p ? p->sum : 0.0); + p = sqlite3_aggregate_context(context, 0); + if( p && p->cnt>0 ){ + if( p->seenFloat ){ + sqlite3_result_double(context, p->sum); + }else{ + sqlite3_result_int64(context, (i64)p->sum); + } + } } static void avgFinalize(sqlite3_context *context){ SumCtx *p; - p = sqlite3_aggregate_context(context, sizeof(*p)); + p = sqlite3_aggregate_context(context, 0); if( p && p->cnt>0 ){ sqlite3_result_double(context, p->sum/(double)p->cnt); } @@ -872,21 +890,11 @@ } static void countFinalize(sqlite3_context *context){ CountCtx *p; - p = sqlite3_aggregate_context(context, sizeof(*p)); + p = sqlite3_aggregate_context(context, 0); sqlite3_result_int(context, p ? p->n : 0); } /* -** This function tracks state information for the min() and max() -** aggregate functions. -*/ -typedef struct MinMaxCtx MinMaxCtx; -struct MinMaxCtx { - char *z; /* The best so far */ - char zBuf[28]; /* Space that can be used for storage */ -}; - -/* ** Routines to implement min() and max() aggregate functions. */ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){ @@ -920,11 +928,13 @@ } static void minMaxFinalize(sqlite3_context *context){ sqlite3_value *pRes; - pRes = (sqlite3_value *)sqlite3_aggregate_context(context, sizeof(Mem)); - if( pRes->flags ){ - sqlite3_result_value(context, pRes); + pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0); + if( pRes ){ + if( pRes->flags ){ + sqlite3_result_value(context, pRes); + } + sqlite3VdbeMemRelease(pRes); } - sqlite3VdbeMemRelease(pRes); } @@ -962,9 +972,6 @@ { "coalesce", 1, 0, SQLITE_UTF8, 0, 0 }, { "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc }, { "random", -1, 0, SQLITE_UTF8, 0, randomFunc }, - { "like", 2, 0, SQLITE_UTF8, 0, likeFunc }, - { "like", 3, 0, SQLITE_UTF8, 0, likeFunc }, - { "glob", 2, 0, SQLITE_UTF8, 0, globFunc }, { "nullif", 2, 0, SQLITE_UTF8, 1, nullifFunc }, { "sqlite_version", 0, 0, SQLITE_UTF8, 0, versionFunc}, { "quote", 1, 0, SQLITE_UTF8, 0, quoteFunc }, @@ -1036,8 +1043,76 @@ } sqlite3RegisterDateTimeFunctions(db); #ifdef SQLITE_SSE - { - sqlite3SseFunctions(db); + sqlite3SseFunctions(db); +#endif +#ifdef SQLITE_CASE_SENSITIVE_LIKE + sqlite3RegisterLikeFunctions(db, 1); +#else + sqlite3RegisterLikeFunctions(db, 0); +#endif +} + +/* +** Set the LIKEOPT flag on the 2-argument function with the given name. +*/ +static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){ + FuncDef *pDef; + pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0); + if( pDef ){ + pDef->flags = flagVal; } -#endif } + +/* +** Register the built-in LIKE and GLOB functions. The caseSensitive +** parameter determines whether or not the LIKE operator is case +** sensitive. GLOB is always case sensitive. +*/ +void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){ + struct compareInfo *pInfo; + if( caseSensitive ){ + pInfo = (struct compareInfo*)&likeInfoAlt; + }else{ + pInfo = (struct compareInfo*)&likeInfoNorm; + } + sqlite3_create_function(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0); + sqlite3_create_function(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0); + sqlite3_create_function(db, "glob", 2, SQLITE_UTF8, + (struct compareInfo*)&globInfo, likeFunc, 0,0); + setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE); + setLikeOptFlag(db, "like", + caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE); +} + +/* +** pExpr points to an expression which implements a function. If +** it is appropriate to apply the LIKE optimization to that function +** then set aWc[0] through aWc[2] to the wildcard characters and +** return TRUE. If the function is not a LIKE-style function then +** return FALSE. +*/ +int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ + FuncDef *pDef; + if( pExpr->op!=TK_FUNCTION ){ + return 0; + } + if( pExpr->pList->nExpr!=2 ){ + return 0; + } + pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2, + SQLITE_UTF8, 0); + if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){ + return 0; + } + + /* The memcpy() statement assumes that the wildcard characters are + ** the first three statements in the compareInfo structure. The + ** asserts() that follow verify that assumption + */ + memcpy(aWc, pDef->pUserData, 3); + assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll ); + assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne ); + assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet ); + *pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0; + return 1; +} ======================================================================== --- sqlite/insert.c 8c0868a975fe37366ed92e1b976853be96284607 +++ sqlite/insert.c 484c73bc1309f283a31baa0e114f3ee980536397 @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.139 2005/06/12 21:35:52 drh Exp $ +** $Id: insert.c,v 1.142 2005/07/21 18:23:20 drh Exp $ */ #include "sqliteInt.h" @@ -373,7 +373,7 @@ ** back up and execute the SELECT code above. */ sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v)); - sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0); + sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn); sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop); sqlite3VdbeResolveLabel(v, iCleanup); @@ -949,7 +949,7 @@ sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1); } } - jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24)); + jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); /* Find out what action to take in case there is an indexing conflict */ @@ -1019,9 +1019,8 @@ } } contAddr = sqlite3VdbeCurrentAddr(v); - assert( contAddr<(1<<24) ); #if NULL_DISTINCT_FOR_UNIQUE - sqlite3VdbeChangeP2(v, jumpInst1, contAddr | (1<<24)); + sqlite3VdbeChangeP2(v, jumpInst1, contAddr); #endif sqlite3VdbeChangeP2(v, jumpInst2, contAddr); } @@ -1097,11 +1096,12 @@ Vdbe *v = sqlite3GetVdbe(pParse); assert( v!=0 ); sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); + VdbeComment((v, "# %s", pTab->zName)); sqlite3VdbeAddOp(v, op, base, pTab->tnum); - VdbeComment((v, "# %s", pTab->zName)); sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol); for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0); + VdbeComment((v, "# %s", pIdx->zName)); sqlite3VdbeOp3(v, op, i+base, pIdx->tnum, (char*)&pIdx->keyInfo, P3_KEYINFO); } ======================================================================== --- sqlite/keywordhash.h 9f753ca12591e9ac7d627850e28217bf1fb96c26 +++ sqlite/keywordhash.h 32380a4bfe997d18e3ecd5b85fd948cf7b52aec8 @@ -1,83 +1,84 @@ -/* Hash score: 153 */ +/* Hash score: 158 */ static int keywordCode(const char *z, int n){ - static const char zText[515] = + static const char zText[535] = "ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER" - "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYAND" - "EFERRABLEXCLUSIVEXISTSTATEMENTATTACHAVINGLOBEFOREIGNOREINDEXAUTOINCREMENT" - "BEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETECASECOLLATECOLUMN" - "COMMITCONFLICTCONSTRAINTERSECTCREATECROSSCURRENT_DATECURRENT_TIMESTAMP" - "RAGMATCHDESCDETACHDISTINCTDROPRIMARYFAILIMITFROMFULLGROUPDATE" - "IMMEDIATEINSERTINSTEADINTOFFSETISNULLJOINORDEREPLACEOUTERESTRICT" - "RIGHTROLLBACKROWHENUNIONUNIQUEUSINGVACUUMVALUESVIEWHERE"; + "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYANALYZE" + "XCLUSIVEXISTSTATEMENTANDEFERRABLEATTACHAVINGLOBEFOREIGNOREINDEX" + "AUTOINCREMENTBEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETE" + "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS" + "CURRENT_DATECURRENT_TIMESTAMPLANDESCDETACHDISTINCTDROPRAGMATCH" + "FAILIMITFROMFULLGROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULL" + "JOINORDEREPLACEOUTERESTRICTPRIMARYQUERYRIGHTROLLBACKROWHENUNION" + "UNIQUEUSINGVACUUMVALUESVIEWHERE"; static const unsigned char aHash[127] = { - 89, 79, 102, 88, 0, 4, 0, 0, 109, 0, 75, 0, 0, - 92, 43, 0, 90, 0, 101, 104, 94, 0, 0, 10, 0, 0, - 108, 0, 105, 100, 0, 28, 47, 0, 40, 0, 0, 63, 69, - 0, 62, 19, 0, 0, 32, 81, 0, 103, 72, 0, 0, 34, - 0, 60, 33, 0, 8, 0, 110, 37, 12, 0, 76, 39, 25, - 64, 0, 0, 31, 80, 52, 30, 49, 20, 86, 0, 35, 0, - 73, 26, 0, 70, 0, 0, 0, 0, 46, 65, 22, 85, 29, - 67, 84, 0, 1, 0, 9, 98, 57, 18, 0, 107, 74, 96, - 53, 6, 83, 0, 0, 48, 91, 0, 99, 0, 68, 0, 0, - 15, 0, 111, 50, 55, 0, 2, 54, 0, 106, + 91, 80, 106, 90, 0, 4, 0, 0, 113, 0, 83, 0, 0, + 94, 44, 76, 92, 0, 105, 108, 96, 0, 0, 10, 0, 0, + 112, 0, 109, 102, 0, 28, 48, 0, 41, 0, 0, 65, 71, + 0, 63, 19, 0, 104, 36, 103, 0, 107, 74, 0, 0, 33, + 0, 61, 37, 0, 8, 0, 114, 38, 12, 0, 77, 40, 25, + 66, 0, 0, 31, 81, 53, 30, 50, 20, 88, 0, 34, 0, + 75, 26, 0, 72, 0, 0, 0, 64, 47, 67, 22, 87, 29, + 69, 86, 0, 1, 0, 9, 100, 58, 18, 0, 111, 82, 98, + 54, 6, 85, 0, 0, 49, 93, 0, 101, 0, 70, 0, 0, + 15, 0, 115, 51, 56, 0, 2, 55, 0, 110, }; - static const unsigned char aNext[111] = { + static const unsigned char aNext[115] = { 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, - 0, 11, 0, 0, 0, 7, 0, 5, 13, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, - 0, 16, 0, 23, 51, 0, 0, 0, 0, 44, 58, 0, 0, - 0, 0, 0, 0, 0, 0, 71, 41, 0, 0, 24, 59, 21, - 0, 78, 0, 66, 0, 0, 82, 45, 0, 0, 0, 0, 0, - 0, 0, 38, 93, 95, 0, 0, 97, 0, 14, 27, 77, 0, - 56, 87, 0, 36, 0, 61, 0, + 0, 11, 0, 0, 0, 0, 5, 13, 0, 7, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, + 0, 0, 16, 0, 23, 52, 0, 0, 0, 0, 45, 0, 59, + 0, 0, 0, 0, 0, 0, 0, 0, 73, 42, 0, 24, 60, + 21, 0, 79, 0, 0, 68, 0, 0, 84, 46, 0, 0, 0, + 0, 0, 0, 0, 39, 95, 97, 0, 0, 99, 0, 32, 0, + 14, 27, 78, 0, 57, 89, 0, 35, 0, 62, 0, }; - static const unsigned char aLen[111] = { + static const unsigned char aLen[115] = { 5, 5, 4, 4, 9, 2, 3, 8, 2, 6, 4, 3, 7, 11, 2, 7, 5, 5, 4, 5, 3, 5, 10, 6, 4, 6, - 7, 6, 7, 9, 3, 3, 10, 9, 6, 9, 6, 6, 4, - 6, 3, 7, 6, 7, 5, 13, 2, 2, 5, 5, 6, 7, - 3, 7, 4, 4, 2, 7, 3, 8, 6, 4, 7, 6, 6, - 8, 10, 9, 6, 5, 12, 12, 17, 6, 5, 4, 6, 8, - 2, 4, 7, 4, 5, 4, 4, 5, 6, 9, 6, 7, 4, - 2, 6, 3, 6, 4, 5, 7, 5, 8, 5, 8, 3, 4, - 5, 6, 5, 6, 6, 4, 5, + 7, 6, 7, 9, 3, 7, 9, 6, 9, 3, 10, 6, 6, + 4, 6, 3, 7, 6, 7, 5, 13, 2, 2, 5, 5, 6, + 7, 3, 7, 4, 4, 2, 7, 3, 8, 6, 4, 4, 7, + 6, 6, 8, 10, 9, 6, 5, 12, 12, 17, 4, 4, 6, + 8, 2, 4, 6, 5, 4, 5, 4, 4, 5, 6, 9, 6, + 7, 4, 2, 6, 3, 6, 4, 5, 7, 5, 8, 7, 5, + 5, 8, 3, 4, 5, 6, 5, 6, 6, 4, 5, }; - static const unsigned short int aOffset[111] = { + static const unsigned short int aOffset[115] = { 0, 4, 7, 10, 10, 14, 19, 21, 26, 27, 32, 34, 36, 42, 51, 52, 57, 61, 65, 67, 71, 74, 78, 86, 91, 94, - 99, 105, 108, 113, 118, 122, 124, 133, 141, 146, 155, 160, 165, - 168, 170, 170, 174, 178, 180, 185, 187, 189, 198, 201, 205, 211, - 217, 217, 220, 223, 227, 229, 230, 234, 241, 247, 251, 258, 264, - 270, 278, 285, 294, 300, 305, 317, 317, 333, 337, 342, 346, 352, - 353, 360, 363, 370, 373, 378, 382, 386, 389, 395, 404, 410, 417, - 420, 420, 423, 426, 432, 436, 440, 447, 451, 459, 464, 472, 474, - 478, 483, 489, 494, 500, 506, 509, + 99, 105, 108, 113, 118, 122, 128, 136, 141, 150, 152, 162, 167, + 172, 175, 177, 177, 181, 185, 187, 192, 194, 196, 205, 208, 212, + 218, 224, 224, 227, 230, 234, 236, 237, 241, 248, 254, 258, 262, + 269, 275, 281, 289, 296, 305, 311, 316, 328, 328, 344, 348, 352, + 358, 359, 366, 369, 373, 378, 381, 386, 390, 394, 397, 403, 412, + 418, 425, 428, 428, 431, 434, 440, 444, 448, 455, 459, 467, 474, + 479, 484, 492, 494, 498, 503, 509, 514, 520, 526, 529, }; - static const unsigned char aCode[111] = { + static const unsigned char aCode[115] = { TK_ABORT, TK_TABLE, TK_JOIN_KW, TK_TEMP, TK_TEMP, TK_OR, TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_THEN, TK_END, TK_DEFAULT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER, TK_RAISE, TK_EACH, TK_CHECK, TK_KEY, TK_AFTER, TK_REFERENCES, TK_ESCAPE, TK_ELSE, TK_EXCEPT, TK_TRIGGER, TK_LIKE_KW, TK_EXPLAIN, TK_INITIALLY, - TK_ALL, TK_AND, TK_DEFERRABLE, TK_EXCLUSIVE, TK_EXISTS, - TK_STATEMENT, TK_ATTACH, TK_HAVING, TK_LIKE_KW, TK_BEFORE, - TK_FOR, TK_FOREIGN, TK_IGNORE, TK_REINDEX, TK_INDEX, - TK_AUTOINCR, TK_TO, TK_IN, TK_BEGIN, TK_JOIN_KW, - TK_RENAME, TK_BETWEEN, TK_NOT, TK_NOTNULL, TK_NULL, - TK_LIKE_KW, TK_BY, TK_CASCADE, TK_ASC, TK_DEFERRED, - TK_DELETE, TK_CASE, TK_COLLATE, TK_COLUMNKW, TK_COMMIT, - TK_CONFLICT, TK_CONSTRAINT, TK_INTERSECT, TK_CREATE, TK_JOIN_KW, - TK_CTIME_KW, TK_CTIME_KW, TK_CTIME_KW, TK_PRAGMA, TK_MATCH, - TK_DESC, TK_DETACH, TK_DISTINCT, TK_IS, TK_DROP, - TK_PRIMARY, TK_FAIL, TK_LIMIT, TK_FROM, TK_JOIN_KW, - TK_GROUP, TK_UPDATE, TK_IMMEDIATE, TK_INSERT, TK_INSTEAD, - TK_INTO, TK_OF, TK_OFFSET, TK_SET, TK_ISNULL, - TK_JOIN, TK_ORDER, TK_REPLACE, TK_JOIN_KW, TK_RESTRICT, - TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_WHEN, TK_UNION, - TK_UNIQUE, TK_USING, TK_VACUUM, TK_VALUES, TK_VIEW, - TK_WHERE, + TK_ALL, TK_ANALYZE, TK_EXCLUSIVE, TK_EXISTS, TK_STATEMENT, + TK_AND, TK_DEFERRABLE, TK_ATTACH, TK_HAVING, TK_LIKE_KW, + TK_BEFORE, TK_FOR, TK_FOREIGN, TK_IGNORE, TK_REINDEX, + TK_INDEX, TK_AUTOINCR, TK_TO, TK_IN, TK_BEGIN, + TK_JOIN_KW, TK_RENAME, TK_BETWEEN, TK_NOT, TK_NOTNULL, + TK_NULL, TK_LIKE_KW, TK_BY, TK_CASCADE, TK_ASC, + TK_DEFERRED, TK_DELETE, TK_CASE, TK_CAST, TK_COLLATE, + TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_CONSTRAINT, TK_INTERSECT, + TK_CREATE, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW, TK_CTIME_KW, + TK_PLAN, TK_DESC, TK_DETACH, TK_DISTINCT, TK_IS, + TK_DROP, TK_PRAGMA, TK_MATCH, TK_FAIL, TK_LIMIT, + TK_FROM, TK_JOIN_KW, TK_GROUP, TK_UPDATE, TK_IMMEDIATE, + TK_INSERT, TK_INSTEAD, TK_INTO, TK_OF, TK_OFFSET, + TK_SET, TK_ISNULL, TK_JOIN, TK_ORDER, TK_REPLACE, + TK_JOIN_KW, TK_RESTRICT, TK_PRIMARY, TK_QUERY, TK_JOIN_KW, + TK_ROLLBACK, TK_ROW, TK_WHEN, TK_UNION, TK_UNIQUE, + TK_USING, TK_VACUUM, TK_VALUES, TK_VIEW, TK_WHERE, }; int h, i; if( n<2 ) return TK_ID; ======================================================================== --- sqlite/main.c 16ab37b7b3aa57bcfb6b687474b2553c67b1a7fe +++ sqlite/main.c 422014201f22aa17b96c76650163178a91a825af @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.293 2005/05/26 16:23:34 drh Exp $ +** $Id: main.c,v 1.302 2005/09/17 15:20:27 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -234,7 +234,6 @@ case SQLITE_DONE: case SQLITE_OK: z = "not an error"; break; case SQLITE_ERROR: z = "SQL logic error or missing database"; break; - case SQLITE_INTERNAL: z = "internal SQLite implementation flaw"; break; case SQLITE_PERM: z = "access permission denied"; break; case SQLITE_ABORT: z = "callback requested query abort"; break; case SQLITE_BUSY: z = "database is locked"; break; @@ -244,13 +243,11 @@ case SQLITE_INTERRUPT: z = "interrupted"; break; case SQLITE_IOERR: z = "disk I/O error"; break; case SQLITE_CORRUPT: z = "database disk image is malformed"; break; - case SQLITE_NOTFOUND: z = "table or record not found"; break; - case SQLITE_FULL: z = "database is full"; break; + case SQLITE_FULL: z = "database or disk is full"; break; case SQLITE_CANTOPEN: z = "unable to open database file"; break; case SQLITE_PROTOCOL: z = "database locking protocol failure"; break; case SQLITE_EMPTY: z = "table contains no data"; break; case SQLITE_SCHEMA: z = "database schema has changed"; break; - case SQLITE_TOOBIG: z = "too much data for one table row"; break; case SQLITE_CONSTRAINT: z = "constraint failed"; break; case SQLITE_MISMATCH: z = "datatype mismatch"; break; case SQLITE_MISUSE: z = "library routine called out of sequence";break; @@ -308,6 +305,25 @@ } /* +** Invoke the given busy handler. +** +** This routine is called when an operation failed with a lock. +** If this routine returns non-zero, the lock is retried. If it +** returns 0, the operation aborts with an SQLITE_BUSY error. +*/ +int sqlite3InvokeBusyHandler(BusyHandler *p){ + int rc; + if( p==0 || p->xFunc==0 || p->nBusy<0 ) return 0; + rc = p->xFunc(p->pArg, p->nBusy); + if( rc==0 ){ + p->nBusy = -1; + }else{ + p->nBusy++; + } + return rc; +} + +/* ** This routine sets the busy callback for an Sqlite database to the ** given callback function with the given argument. */ @@ -321,6 +337,7 @@ } db->busyHandler.xFunc = xBusy; db->busyHandler.pArg = pArg; + db->busyHandler.nBusy = 0; return SQLITE_OK; } @@ -454,6 +471,7 @@ p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1); if( p==0 ) return SQLITE_NOMEM; + p->flags = 0; p->xFunc = xFunc; p->xStep = xStep; p->xFinalize = xFinal; @@ -491,13 +509,14 @@ } #endif +#ifndef SQLITE_OMIT_TRACE /* ** Register a trace function. The pArg from the previously registered trace ** is returned. ** ** A NULL trace function means that no tracing is executes. A non-NULL ** trace is a pointer to a function that is invoked at the start of each -** sqlite3_exec(). +** SQL statement. */ void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ void *pOld = db->pTraceArg; @@ -505,6 +524,25 @@ db->pTraceArg = pArg; return pOld; } +/* +** Register a profile function. The pArg from the previously registered +** profile function is returned. +** +** A NULL profile function means that no profiling is executes. A non-NULL +** profile is a pointer to a function that is invoked at the conclusion of +** each SQL statement that is run. +*/ +void *sqlite3_profile( + sqlite3 *db, + void (*xProfile)(void*,const char*,sqlite_uint64), + void *pArg +){ + void *pOld = db->pProfileArg; + db->xProfile = xProfile; + db->pProfileArg = pArg; + return pOld; +} +#endif /* SQLITE_OMIT_TRACE */ /*** EXPERIMENTAL *** ** @@ -530,11 +568,11 @@ ** opened and used. If zFilename is the magic name ":memory:" then ** the database is stored in memory (and is thus forgotten as soon as ** the connection is closed.) If zFilename is NULL then the database -** is for temporary use only and is deleted as soon as the connection -** is closed. +** is a "virtual" database for transient use only and is deleted as +** soon as the connection is closed. ** -** A temporary database can be either a disk file (that is automatically -** deleted when the file is closed) or a set of red-black trees held in memory, +** A virtual database can be either a disk file (that is automatically +** deleted when the file is closed) or it an be held entirely in memory, ** depending on the values of the TEMP_STORE compile-time macro and the ** db->temp_store variable, according to the following chart: ** @@ -676,6 +714,7 @@ ){ sqlite3 *db; int rc, i; + CollSeq *pColl; /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite3) ); @@ -712,6 +751,13 @@ /* Also add a UTF-8 case-insensitive collation sequence. */ sqlite3_create_collation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc); + /* Set flags on the built-in collating sequences */ + db->pDfltColl->type = SQLITE_COLL_BINARY; + pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 6, 0); + if( pColl ){ + pColl->type = SQLITE_COLL_NOCASE; + } + /* Open the backend database driver */ rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ @@ -829,7 +875,7 @@ rc = SQLITE_OK; }else{ rc = sqlite3VdbeReset((Vdbe*)pStmt); - sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0, 0); + sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0); } return rc; } @@ -883,7 +929,7 @@ pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1); if( 0==pColl ){ - rc = SQLITE_NOMEM; + rc = SQLITE_NOMEM; }else{ pColl->xCmp = xCompare; pColl->pUser = pCtx; @@ -1001,3 +1047,14 @@ int sqlite3_get_autocommit(sqlite3 *db){ return db->autoCommit; } + +#ifdef SQLITE_DEBUG +/* +** The following routine is subtituted for constant SQLITE_CORRUPT in +** debugging builds. This provides a way to set a breakpoint for when +** corruption is first detected. +*/ +int sqlite3Corrupt(void){ + return SQLITE_CORRUPT; +} +#endif ======================================================================== --- sqlite/opcodes.c 09ba45fa2716974a205f0514fda43e0d52c50ecc +++ sqlite/opcodes.c 8b23c96979492cba740a2e3c67f6646e8b323b12 @@ -6,130 +6,135 @@ /* 2 */ "Column", /* 3 */ "SetCookie", /* 4 */ "IfMemPos", - /* 5 */ "MoveGt", - /* 6 */ "AggFocus", + /* 5 */ "Sequence", + /* 6 */ "MoveGt", /* 7 */ "RowKey", - /* 8 */ "AggNext", - /* 9 */ "OpenWrite", - /* 10 */ "If", + /* 8 */ "OpenWrite", + /* 9 */ "If", + /* 10 */ "ToInt", /* 11 */ "Pop", - /* 12 */ "AggContextPush", - /* 13 */ "CollSeq", - /* 14 */ "OpenRead", - /* 15 */ "Expire", - /* 16 */ "SortReset", - /* 17 */ "AutoCommit", - /* 18 */ "Sort", - /* 19 */ "ListRewind", - /* 20 */ "IntegrityCk", - /* 21 */ "SortInsert", - /* 22 */ "Function", - /* 23 */ "Noop", - /* 24 */ "Return", - /* 25 */ "NewRowid", - /* 26 */ "Variable", - /* 27 */ "String", - /* 28 */ "ParseSchema", - /* 29 */ "AggFunc", - /* 30 */ "Close", - /* 31 */ "ListWrite", - /* 32 */ "CreateIndex", - /* 33 */ "IsUnique", - /* 34 */ "IdxIsNull", - /* 35 */ "NotFound", - /* 36 */ "MustBeInt", - /* 37 */ "Halt", - /* 38 */ "Rowid", - /* 39 */ "IdxLT", - /* 40 */ "AddImm", - /* 41 */ "Statement", - /* 42 */ "RowData", - /* 43 */ "MemMax", - /* 44 */ "Push", - /* 45 */ "NotExists", - /* 46 */ "OpenTemp", - /* 47 */ "MemIncr", - /* 48 */ "Gosub", - /* 49 */ "AggSet", - /* 50 */ "Integer", - /* 51 */ "SortNext", - /* 52 */ "Prev", - /* 53 */ "CreateTable", - /* 54 */ "Last", - /* 55 */ "IdxRowid", - /* 56 */ "ResetCount", - /* 57 */ "Callback", - /* 58 */ "ContextPush", - /* 59 */ "DropTrigger", - /* 60 */ "DropIndex", - /* 61 */ "IdxGE", - /* 62 */ "Or", - /* 63 */ "And", - /* 64 */ "Not", - /* 65 */ "IdxDelete", - /* 66 */ "Vacuum", - /* 67 */ "MoveLe", - /* 68 */ "IsNull", - /* 69 */ "NotNull", - /* 70 */ "Ne", - /* 71 */ "Eq", - /* 72 */ "Gt", - /* 73 */ "Le", - /* 74 */ "Lt", - /* 75 */ "Ge", - /* 76 */ "IfNot", - /* 77 */ "BitAnd", - /* 78 */ "BitOr", - /* 79 */ "ShiftLeft", - /* 80 */ "ShiftRight", - /* 81 */ "Add", - /* 82 */ "Subtract", - /* 83 */ "Multiply", - /* 84 */ "Divide", - /* 85 */ "Remainder", - /* 86 */ "Concat", - /* 87 */ "Negative", - /* 88 */ "DropTable", - /* 89 */ "BitNot", - /* 90 */ "String8", - /* 91 */ "MakeRecord", - /* 92 */ "Delete", - /* 93 */ "AggContextPop", - /* 94 */ "ListRead", - /* 95 */ "ListReset", - /* 96 */ "Dup", - /* 97 */ "Goto", - /* 98 */ "Clear", - /* 99 */ "IdxGT", - /* 100 */ "MoveLt", - /* 101 */ "VerifyCookie", - /* 102 */ "Pull", - /* 103 */ "SetNumColumns", - /* 104 */ "AbsValue", - /* 105 */ "Transaction", - /* 106 */ "AggGet", - /* 107 */ "ContextPop", - /* 108 */ "Next", - /* 109 */ "AggInit", - /* 110 */ "IdxInsert", - /* 111 */ "Distinct", - /* 112 */ "AggReset", - /* 113 */ "Insert", - /* 114 */ "Destroy", - /* 115 */ "ReadCookie", - /* 116 */ "ForceInt", - /* 117 */ "OpenPseudo", - /* 118 */ "Null", - /* 119 */ "Blob", - /* 120 */ "MemStore", - /* 121 */ "Rewind", - /* 122 */ "MoveGe", - /* 123 */ "Found", - /* 124 */ "NullRow", + /* 12 */ "CollSeq", + /* 13 */ "OpenRead", + /* 14 */ "Expire", + /* 15 */ "AutoCommit", + /* 16 */ "IntegrityCk", + /* 17 */ "Sort", + /* 18 */ "Function", + /* 19 */ "Noop", + /* 20 */ "Return", + /* 21 */ "NewRowid", + /* 22 */ "Variable", + /* 23 */ "String", + /* 24 */ "ParseSchema", + /* 25 */ "Close", + /* 26 */ "CreateIndex", + /* 27 */ "IsUnique", + /* 28 */ "IdxIsNull", + /* 29 */ "NotFound", + /* 30 */ "Int64", + /* 31 */ "MustBeInt", + /* 32 */ "Halt", + /* 33 */ "Rowid", + /* 34 */ "IdxLT", + /* 35 */ "AddImm", + /* 36 */ "Statement", + /* 37 */ "RowData", + /* 38 */ "MemMax", + /* 39 */ "Push", + /* 40 */ "NotExists", + /* 41 */ "MemIncr", + /* 42 */ "Gosub", + /* 43 */ "Integer", + /* 44 */ "ToNumeric", + /* 45 */ "Prev", + /* 46 */ "CreateTable", + /* 47 */ "Last", + /* 48 */ "IdxRowid", + /* 49 */ "MakeIdxRec", + /* 50 */ "ResetCount", + /* 51 */ "FifoWrite", + /* 52 */ "Callback", + /* 53 */ "ContextPush", + /* 54 */ "DropTrigger", + /* 55 */ "DropIndex", + /* 56 */ "IdxGE", + /* 57 */ "IdxDelete", + /* 58 */ "Vacuum", + /* 59 */ "MoveLe", + /* 60 */ "IfNot", + /* 61 */ "DropTable", + /* 62 */ "MakeRecord", + /* 63 */ "ToBlob", + /* 64 */ "Delete", + /* 65 */ "AggFinal", + /* 66 */ "Dup", + /* 67 */ "Or", + /* 68 */ "And", + /* 69 */ "Not", + /* 70 */ "Goto", + /* 71 */ "FifoRead", + /* 72 */ "Clear", + /* 73 */ "IsNull", + /* 74 */ "NotNull", + /* 75 */ "Ne", + /* 76 */ "Eq", + /* 77 */ "Gt", + /* 78 */ "Le", + /* 79 */ "Lt", + /* 80 */ "Ge", + /* 81 */ "IdxGT", + /* 82 */ "BitAnd", + /* 83 */ "BitOr", + /* 84 */ "ShiftLeft", + /* 85 */ "ShiftRight", + /* 86 */ "Add", + /* 87 */ "Subtract", + /* 88 */ "Multiply", + /* 89 */ "Divide", + /* 90 */ "Remainder", + /* 91 */ "Concat", + /* 92 */ "Negative", + /* 93 */ "MoveLt", + /* 94 */ "BitNot", + /* 95 */ "String8", + /* 96 */ "VerifyCookie", + /* 97 */ "AggStep", + /* 98 */ "Pull", + /* 99 */ "ToText", + /* 100 */ "SetNumColumns", + /* 101 */ "AbsValue", + /* 102 */ "Transaction", + /* 103 */ "ContextPop", + /* 104 */ "Next", + /* 105 */ "IdxInsert", + /* 106 */ "Distinct", + /* 107 */ "Insert", + /* 108 */ "Destroy", + /* 109 */ "ReadCookie", + /* 110 */ "ForceInt", + /* 111 */ "LoadAnalysis", + /* 112 */ "OpenVirtual", + /* 113 */ "Explain", + /* 114 */ "OpenPseudo", + /* 115 */ "Null", + /* 116 */ "Blob", + /* 117 */ "MemStore", + /* 118 */ "Rewind", + /* 119 */ "MoveGe", + /* 120 */ "Found", + /* 121 */ "NullRow", + /* 122 */ "NotUsed_122", + /* 123 */ "NotUsed_123", + /* 124 */ "NotUsed_124", /* 125 */ "NotUsed_125", /* 126 */ "NotUsed_126", /* 127 */ "NotUsed_127", - /* 128 */ "Real", - /* 129 */ "HexBlob", + /* 128 */ "NotUsed_128", + /* 129 */ "NotUsed_129", + /* 130 */ "NotUsed_130", + /* 131 */ "NotUsed_131", + /* 132 */ "NotUsed_132", + /* 133 */ "Real", + /* 134 */ "HexBlob", }; #endif ======================================================================== --- sqlite/opcodes.h c350694b63ef80daafa7d04f71a6d921aa4935e2 +++ sqlite/opcodes.h 1848e78f249e09e0b773754679d6584412f8900f @@ -1,144 +1,149 @@ /* Automatically generated. Do not edit */ /* See the mkopcodeh.awk script for details */ #define OP_MemLoad 1 -#define OP_HexBlob 129 /* same as TK_BLOB */ +#define OP_HexBlob 134 /* same as TK_BLOB */ #define OP_Column 2 #define OP_SetCookie 3 #define OP_IfMemPos 4 -#define OP_Real 128 /* same as TK_FLOAT */ -#define OP_MoveGt 5 -#define OP_Ge 75 /* same as TK_GE */ -#define OP_AggFocus 6 +#define OP_Real 133 /* same as TK_FLOAT */ +#define OP_Sequence 5 +#define OP_MoveGt 6 +#define OP_Ge 80 /* same as TK_GE */ #define OP_RowKey 7 -#define OP_AggNext 8 -#define OP_Eq 71 /* same as TK_EQ */ -#define OP_OpenWrite 9 -#define OP_NotNull 69 /* same as TK_NOTNULL */ -#define OP_If 10 -#define OP_String8 90 /* same as TK_STRING */ +#define OP_Eq 76 /* same as TK_EQ */ +#define OP_OpenWrite 8 +#define OP_NotNull 74 /* same as TK_NOTNULL */ +#define OP_If 9 +#define OP_ToInt 10 +#define OP_String8 95 /* same as TK_STRING */ #define OP_Pop 11 -#define OP_AggContextPush 12 -#define OP_CollSeq 13 -#define OP_OpenRead 14 -#define OP_Expire 15 -#define OP_SortReset 16 -#define OP_AutoCommit 17 -#define OP_Gt 72 /* same as TK_GT */ -#define OP_Sort 18 -#define OP_ListRewind 19 -#define OP_IntegrityCk 20 -#define OP_SortInsert 21 -#define OP_Function 22 -#define OP_And 63 /* same as TK_AND */ -#define OP_Subtract 82 /* same as TK_MINUS */ -#define OP_Noop 23 -#define OP_Return 24 -#define OP_Remainder 85 /* same as TK_REM */ -#define OP_NewRowid 25 -#define OP_Multiply 83 /* same as TK_STAR */ -#define OP_Variable 26 -#define OP_String 27 -#define OP_ParseSchema 28 -#define OP_AggFunc 29 -#define OP_Close 30 -#define OP_ListWrite 31 -#define OP_CreateIndex 32 -#define OP_IsUnique 33 -#define OP_IdxIsNull 34 -#define OP_NotFound 35 -#define OP_MustBeInt 36 -#define OP_Halt 37 -#define OP_Rowid 38 -#define OP_IdxLT 39 -#define OP_AddImm 40 -#define OP_Statement 41 -#define OP_RowData 42 -#define OP_MemMax 43 -#define OP_Push 44 -#define OP_Or 62 /* same as TK_OR */ -#define OP_NotExists 45 -#define OP_OpenTemp 46 -#define OP_MemIncr 47 -#define OP_Gosub 48 -#define OP_Divide 84 /* same as TK_SLASH */ -#define OP_AggSet 49 -#define OP_Integer 50 -#define OP_SortNext 51 -#define OP_Prev 52 -#define OP_Concat 86 /* same as TK_CONCAT */ -#define OP_BitAnd 77 /* same as TK_BITAND */ -#define OP_CreateTable 53 -#define OP_Last 54 -#define OP_IsNull 68 /* same as TK_ISNULL */ -#define OP_IdxRowid 55 -#define OP_ShiftRight 80 /* same as TK_RSHIFT */ -#define OP_ResetCount 56 -#define OP_Callback 57 -#define OP_ContextPush 58 -#define OP_DropTrigger 59 -#define OP_DropIndex 60 -#define OP_IdxGE 61 -#define OP_IdxDelete 65 -#define OP_Vacuum 66 -#define OP_MoveLe 67 -#define OP_IfNot 76 -#define OP_DropTable 88 -#define OP_MakeRecord 91 -#define OP_Delete 92 -#define OP_AggContextPop 93 -#define OP_ListRead 94 -#define OP_ListReset 95 -#define OP_ShiftLeft 79 /* same as TK_LSHIFT */ -#define OP_Dup 96 -#define OP_Goto 97 -#define OP_Clear 98 -#define OP_IdxGT 99 -#define OP_MoveLt 100 -#define OP_Le 73 /* same as TK_LE */ -#define OP_VerifyCookie 101 -#define OP_Pull 102 -#define OP_Not 64 /* same as TK_NOT */ -#define OP_SetNumColumns 103 -#define OP_AbsValue 104 -#define OP_Transaction 105 -#define OP_Negative 87 /* same as TK_UMINUS */ -#define OP_Ne 70 /* same as TK_NE */ -#define OP_AggGet 106 -#define OP_ContextPop 107 -#define OP_BitOr 78 /* same as TK_BITOR */ -#define OP_Next 108 -#define OP_AggInit 109 -#define OP_IdxInsert 110 -#define OP_Distinct 111 -#define OP_Lt 74 /* same as TK_LT */ -#define OP_AggReset 112 -#define OP_Insert 113 -#define OP_Destroy 114 -#define OP_ReadCookie 115 -#define OP_ForceInt 116 -#define OP_OpenPseudo 117 -#define OP_Null 118 -#define OP_Blob 119 -#define OP_Add 81 /* same as TK_PLUS */ -#define OP_MemStore 120 -#define OP_Rewind 121 -#define OP_MoveGe 122 -#define OP_BitNot 89 /* same as TK_BITNOT */ -#define OP_Found 123 -#define OP_NullRow 124 +#define OP_CollSeq 12 +#define OP_OpenRead 13 +#define OP_Expire 14 +#define OP_AutoCommit 15 +#define OP_Gt 77 /* same as TK_GT */ +#define OP_IntegrityCk 16 +#define OP_Sort 17 +#define OP_Function 18 +#define OP_And 68 /* same as TK_AND */ +#define OP_Subtract 87 /* same as TK_MINUS */ +#define OP_Noop 19 +#define OP_Return 20 +#define OP_Remainder 90 /* same as TK_REM */ +#define OP_NewRowid 21 +#define OP_Multiply 88 /* same as TK_STAR */ +#define OP_Variable 22 +#define OP_String 23 +#define OP_ParseSchema 24 +#define OP_Close 25 +#define OP_CreateIndex 26 +#define OP_IsUnique 27 +#define OP_IdxIsNull 28 +#define OP_NotFound 29 +#define OP_Int64 30 +#define OP_MustBeInt 31 +#define OP_Halt 32 +#define OP_Rowid 33 +#define OP_IdxLT 34 +#define OP_AddImm 35 +#define OP_Statement 36 +#define OP_RowData 37 +#define OP_MemMax 38 +#define OP_Push 39 +#define OP_Or 67 /* same as TK_OR */ +#define OP_NotExists 40 +#define OP_MemIncr 41 +#define OP_Gosub 42 +#define OP_Divide 89 /* same as TK_SLASH */ +#define OP_Integer 43 +#define OP_ToNumeric 44 +#define OP_Prev 45 +#define OP_Concat 91 /* same as TK_CONCAT */ +#define OP_BitAnd 82 /* same as TK_BITAND */ +#define OP_CreateTable 46 +#define OP_Last 47 +#define OP_IsNull 73 /* same as TK_ISNULL */ +#define OP_IdxRowid 48 +#define OP_MakeIdxRec 49 +#define OP_ShiftRight 85 /* same as TK_RSHIFT */ +#define OP_ResetCount 50 +#define OP_FifoWrite 51 +#define OP_Callback 52 +#define OP_ContextPush 53 +#define OP_DropTrigger 54 +#define OP_DropIndex 55 +#define OP_IdxGE 56 +#define OP_IdxDelete 57 +#define OP_Vacuum 58 +#define OP_MoveLe 59 +#define OP_IfNot 60 +#define OP_DropTable 61 +#define OP_MakeRecord 62 +#define OP_ToBlob 63 +#define OP_Delete 64 +#define OP_AggFinal 65 +#define OP_ShiftLeft 84 /* same as TK_LSHIFT */ +#define OP_Dup 66 +#define OP_Goto 70 +#define OP_FifoRead 71 +#define OP_Clear 72 +#define OP_IdxGT 81 +#define OP_MoveLt 93 +#define OP_Le 78 /* same as TK_LE */ +#define OP_VerifyCookie 96 +#define OP_AggStep 97 +#define OP_Pull 98 +#define OP_ToText 99 +#define OP_Not 69 /* same as TK_NOT */ +#define OP_SetNumColumns 100 +#define OP_AbsValue 101 +#define OP_Transaction 102 +#define OP_Negative 92 /* same as TK_UMINUS */ +#define OP_Ne 75 /* same as TK_NE */ +#define OP_ContextPop 103 +#define OP_BitOr 83 /* same as TK_BITOR */ +#define OP_Next 104 +#define OP_IdxInsert 105 +#define OP_Distinct 106 +#define OP_Lt 79 /* same as TK_LT */ +#define OP_Insert 107 +#define OP_Destroy 108 +#define OP_ReadCookie 109 +#define OP_ForceInt 110 +#define OP_LoadAnalysis 111 +#define OP_OpenVirtual 112 +#define OP_Explain 113 +#define OP_OpenPseudo 114 +#define OP_Null 115 +#define OP_Blob 116 +#define OP_Add 86 /* same as TK_PLUS */ +#define OP_MemStore 117 +#define OP_Rewind 118 +#define OP_MoveGe 119 +#define OP_BitNot 94 /* same as TK_BITNOT */ +#define OP_Found 120 +#define OP_NullRow 121 /* The following opcode values are never used */ +#define OP_NotUsed_122 122 +#define OP_NotUsed_123 123 +#define OP_NotUsed_124 124 #define OP_NotUsed_125 125 #define OP_NotUsed_126 126 #define OP_NotUsed_127 127 +#define OP_NotUsed_128 128 +#define OP_NotUsed_129 129 +#define OP_NotUsed_130 130 +#define OP_NotUsed_131 131 +#define OP_NotUsed_132 132 -#define NOPUSH_MASK_0 65400 -#define NOPUSH_MASK_1 61871 -#define NOPUSH_MASK_2 64446 -#define NOPUSH_MASK_3 65363 -#define NOPUSH_MASK_4 65535 -#define NOPUSH_MASK_5 46015 -#define NOPUSH_MASK_6 64254 -#define NOPUSH_MASK_7 7987 +#define NOPUSH_MASK_0 65368 +#define NOPUSH_MASK_1 47898 +#define NOPUSH_MASK_2 47069 +#define NOPUSH_MASK_3 49148 +#define NOPUSH_MASK_4 65403 +#define NOPUSH_MASK_5 30719 +#define NOPUSH_MASK_6 53215 +#define NOPUSH_MASK_7 997 #define NOPUSH_MASK_8 0 #define NOPUSH_MASK_9 0 ======================================================================== --- sqlite/os.h c4b34bd4d6fea51a420f337468b907f4edecb161 +++ sqlite/os.h c51f2747f7bd1840447e2c7d26db749604626814 @@ -161,8 +161,13 @@ ** 1GB boundary. ** */ +#ifndef SQLITE_TEST #define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */ -/* #define PENDING_BYTE 0x5400 // Page 22 - for testing */ +#else +extern unsigned int sqlite3_pending_byte; +#define PENDING_BYTE sqlite3_pending_byte +#endif + #define RESERVED_BYTE (PENDING_BYTE+1) #define SHARED_FIRST (PENDING_BYTE+2) #define SHARED_SIZE 510 @@ -181,7 +186,7 @@ int sqlite3OsRead(OsFile*, void*, int amt); int sqlite3OsWrite(OsFile*, const void*, int amt); int sqlite3OsSeek(OsFile*, i64 offset); -int sqlite3OsSync(OsFile*); +int sqlite3OsSync(OsFile*, int); int sqlite3OsTruncate(OsFile*, i64 size); int sqlite3OsFileSize(OsFile*, i64 *pSize); char *sqlite3OsFullPathname(const char*); ======================================================================== --- sqlite/os_common.h 0e7f428ba0a6c40a61bc56c4e96f493231301b73 +++ sqlite/os_common.h 1ff88c7e7e6bd3e5f85443106c91cc26a4f8600b @@ -28,6 +28,14 @@ #endif +/* + * When testing, this global variable stores the location of the + * pending-byte in the database file. + */ +#ifdef SQLITE_TEST +unsigned int sqlite3_pending_byte = 0x40000000; +#endif + int sqlite3_os_trace = 0; #ifdef SQLITE_DEBUG static int last_page = 0; @@ -82,6 +90,7 @@ #ifdef SQLITE_TEST int sqlite3_io_error_pending = 0; int sqlite3_diskfull_pending = 0; +int sqlite3_diskfull = 0; #define SimulateIOError(A) \ if( sqlite3_io_error_pending ) \ if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; } @@ -89,8 +98,15 @@ sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */ } #define SimulateDiskfullError \ - if( sqlite3_diskfull_pending ) \ - if( sqlite3_diskfull_pending-- == 1 ){ local_ioerr(); return SQLITE_FULL; } + if( sqlite3_diskfull_pending ){ \ + if( sqlite3_diskfull_pending == 1 ){ \ + local_ioerr(); \ + sqlite3_diskfull = 1; \ + return SQLITE_FULL; \ + }else{ \ + sqlite3_diskfull_pending--; \ + } \ + } #else #define SimulateIOError(A) #define SimulateDiskfullError ======================================================================== --- sqlite/os_unix.c 45540d7ee5095566da6685d584598edee5be857c +++ sqlite/os_unix.c c86cf43b7ca9200e6fb7bc202ad2cc7da2f69367 @@ -18,6 +18,7 @@ #include +#include #include #include @@ -57,24 +58,35 @@ #endif /* -** Macros used to determine whether or not to use threads. The -** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for -** Posix threads and SQLITE_W32_THREADS is defined if we are -** synchronizing using Win32 threads. +** Include code that is common to all os_*.c files */ -#if defined(THREADSAFE) && THREADSAFE -# include -# define SQLITE_UNIX_THREADS 1 +#include "os_common.h" + +/* +** The threadid macro resolves to the thread-id or to 0. Used for +** testing and debugging only. +*/ +#ifdef SQLITE_UNIX_THREADS +#define threadid pthread_self() +#else +#define threadid 0 #endif - /* -** Include code that is common to all os_*.c files +** Set or check the OsFile.tid field. This field is set when an OsFile +** is first opened. All subsequent uses of the OsFile verify that the +** same thread is operating on the OsFile. Some operating systems do +** not allow locks to be overridden by other threads and that restriction +** means that sqlite3* database handles cannot be moved from one thread +** to another. This logic makes sure a user does not try to do that +** by mistake. */ -#include "os_common.h" - -#if defined(THREADSAFE) && THREADSAFE && defined(__linux__) -#define getpid pthread_self +#ifdef SQLITE_UNIX_THREADS +# define SET_THREADID(X) X->tid = pthread_self() +# define CHECK_THREADID(X) (!pthread_equal(X->tid, pthread_self())) +#else +# define SET_THREADID(X) +# define CHECK_THREADID(X) 0 #endif /* @@ -264,7 +276,66 @@ int result; /* Result of the locking operation */ }; +#ifdef SQLITE_LOCK_TRACE /* +** Print out information about all locking operations. +** +** This routine is used for troubleshooting locks on multithreaded +** platforms. Enable by compiling with the -DSQLITE_LOCK_TRACE +** command-line option on the compiler. This code is normally +** turnned off. +*/ +static int lockTrace(int fd, int op, struct flock *p){ + char *zOpName, *zType; + int s; + int savedErrno; + if( op==F_GETLK ){ + zOpName = "GETLK"; + }else if( op==F_SETLK ){ + zOpName = "SETLK"; + }else{ + s = fcntl(fd, op, p); + sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s); + return s; + } + if( p->l_type==F_RDLCK ){ + zType = "RDLCK"; + }else if( p->l_type==F_WRLCK ){ + zType = "WRLCK"; + }else if( p->l_type==F_UNLCK ){ + zType = "UNLCK"; + }else{ + assert( 0 ); + } + assert( p->l_whence==SEEK_SET ); + s = fcntl(fd, op, p); + savedErrno = errno; + sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n", + threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len, + (int)p->l_pid, s); + if( s && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){ + struct flock l2; + l2 = *p; + fcntl(fd, F_GETLK, &l2); + if( l2.l_type==F_RDLCK ){ + zType = "RDLCK"; + }else if( l2.l_type==F_WRLCK ){ + zType = "WRLCK"; + }else if( l2.l_type==F_UNLCK ){ + zType = "UNLCK"; + }else{ + assert( 0 ); + } + sqlite3DebugPrintf("fcntl-failure-reason: %s %d %d %d\n", + zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid); + } + errno = savedErrno; + return s; +} +#define fcntl lockTrace +#endif /* SQLITE_LOCK_TRACE */ + +/* ** The testThreadLockingBehavior() routine launches two separate ** threads on this routine. This routine attempts to lock a file ** descriptor then returns. The success or failure of that attempt @@ -443,6 +514,7 @@ int rc; assert( !id->isOpen ); id->dirfd = -1; + SET_THREADID(id); id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, SQLITE_DEFAULT_FILE_PERMISSIONS); if( id->h<0 ){ @@ -494,9 +566,11 @@ if( access(zFilename, 0)==0 ){ return SQLITE_CANTOPEN; } + SET_THREADID(id); id->dirfd = -1; id->h = open(zFilename, - O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY, 0600); + O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY, + SQLITE_DEFAULT_FILE_PERMISSIONS); if( id->h<0 ){ return SQLITE_CANTOPEN; } @@ -528,6 +602,7 @@ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ int rc; assert( !id->isOpen ); + SET_THREADID(id); id->dirfd = -1; id->h = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY); if( id->h<0 ){ @@ -572,6 +647,7 @@ ** open. */ return SQLITE_CANTOPEN; } + SET_THREADID(id); assert( id->dirfd<0 ); id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0); if( id->dirfd<0 ){ @@ -696,6 +772,9 @@ int sqlite3OsSeek(OsFile *id, i64 offset){ assert( id->isOpen ); SEEK(offset/1024 + 1); +#ifdef SQLITE_TEST + if( offset ) SimulateDiskfullError +#endif lseek(id->h, offset, SEEK_SET); return SQLITE_OK; } @@ -721,7 +800,7 @@ ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash ** or power failure will likely corrupt the database file. */ -static int full_fsync(int fd, int fullSync){ +static int full_fsync(int fd, int fullSync, int dataOnly){ int rc; /* Record the number of times that we do a normal fsync() and @@ -750,7 +829,11 @@ if( rc ) rc = fsync(fd); #else - rc = fsync(fd); + if( dataOnly ){ + rc = fdatasync(fd); + }else{ + rc = fsync(fd); + } #endif /* defined(F_FULLFSYNC) */ #endif /* defined(SQLITE_NO_SYNC) */ @@ -760,6 +843,10 @@ /* ** Make sure all writes to a particular file are committed to disk. ** +** If dataOnly==0 then both the file itself and its metadata (file +** size, access time, etc) are synced. If dataOnly!=0 then only the +** file data is synced. +** ** Under Unix, also make sure that the directory entry for the file ** has been created by fsync-ing the directory that contains the file. ** If we do not do this and we encounter a power failure, the directory @@ -768,16 +855,16 @@ ** the directory entry for the journal was never created) and the transaction ** will not roll back - possibly leading to database corruption. */ -int sqlite3OsSync(OsFile *id){ +int sqlite3OsSync(OsFile *id, int dataOnly){ assert( id->isOpen ); SimulateIOError(SQLITE_IOERR); TRACE2("SYNC %-3d\n", id->h); - if( full_fsync(id->h, id->fullSync) ){ + if( full_fsync(id->h, id->fullSync, dataOnly) ){ return SQLITE_IOERR; } if( id->dirfd>=0 ){ TRACE2("DIRSYNC %-3d\n", id->dirfd); - full_fsync(id->dirfd, id->fullSync); + full_fsync(id->dirfd, id->fullSync, 0); close(id->dirfd); /* Only need to sync once, so close the directory */ id->dirfd = -1; /* when we are done. */ } @@ -839,6 +926,7 @@ int r = 0; assert( id->isOpen ); + if( CHECK_THREADID(id) ) return SQLITE_MISUSE; sqlite3OsEnterMutex(); /* Needed because id->pLock is shared across threads */ /* Check if a thread in this process holds such a lock */ @@ -956,6 +1044,7 @@ TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype), locktypeName(id->locktype), locktypeName(pLock->locktype), pLock->cnt ,getpid() ); + if( CHECK_THREADID(id) ) return SQLITE_MISUSE; /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as @@ -1002,6 +1091,7 @@ } lock.l_len = 1L; + lock.l_whence = SEEK_SET; /* A PENDING lock is needed before acquiring a SHARED lock and before @@ -1037,7 +1127,10 @@ lock.l_start = PENDING_BYTE; lock.l_len = 1L; lock.l_type = F_UNLCK; - fcntl(id->h, F_SETLK, &lock); + if( fcntl(id->h, F_SETLK, &lock)!=0 ){ + rc = SQLITE_IOERR; /* This should never happen */ + goto end_lock; + } if( s ){ rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY; }else{ @@ -1107,6 +1200,7 @@ assert( id->isOpen ); TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype, id->pLock->locktype, id->pLock->cnt, getpid()); + if( CHECK_THREADID(id) ) return SQLITE_MISUSE; assert( locktype<=SHARED_LOCK ); if( id->locktype<=locktype ){ @@ -1131,8 +1225,11 @@ lock.l_whence = SEEK_SET; lock.l_start = PENDING_BYTE; lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); - fcntl(id->h, F_SETLK, &lock); - pLock->locktype = SHARED_LOCK; + if( fcntl(id->h, F_SETLK, &lock)==0 ){ + pLock->locktype = SHARED_LOCK; + }else{ + rc = SQLITE_IOERR; /* This should never happen */ + } } if( locktype==NO_LOCK ){ struct openCnt *pOpen; @@ -1146,8 +1243,11 @@ lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; lock.l_start = lock.l_len = 0L; - fcntl(id->h, F_SETLK, &lock); - pLock->locktype = NO_LOCK; + if( fcntl(id->h, F_SETLK, &lock)==0 ){ + pLock->locktype = NO_LOCK; + }else{ + rc = SQLITE_IOERR; /* This should never happen */ + } } /* Decrement the count of locks against this same file. When the @@ -1177,6 +1277,7 @@ */ int sqlite3OsClose(OsFile *id){ if( !id->isOpen ) return SQLITE_OK; + if( CHECK_THREADID(id) ) return SQLITE_MISUSE; sqlite3OsUnlock(id, NO_LOCK); if( id->dirfd>=0 ) close(id->dirfd); id->dirfd = -1; @@ -1189,13 +1290,13 @@ */ int *aNew; struct openCnt *pOpen = id->pOpen; - pOpen->nPending++; - aNew = sqliteRealloc( pOpen->aPending, pOpen->nPending*sizeof(int) ); + aNew = sqliteRealloc( pOpen->aPending, (pOpen->nPending+1)*sizeof(int) ); if( aNew==0 ){ /* If a malloc fails, just leak the file descriptor */ }else{ pOpen->aPending = aNew; - pOpen->aPending[pOpen->nPending-1] = id->h; + pOpen->aPending[pOpen->nPending] = id->h; + pOpen->nPending++; } }else{ /* There are no outstanding locks so we can close the file immediately */ @@ -1221,10 +1322,14 @@ if( zRelative[0]=='/' ){ sqlite3SetString(&zFull, zRelative, (char*)0); }else{ - char zBuf[5000]; + char *zBuf = sqliteMalloc(5000); + if( zBuf==0 ){ + return 0; + } zBuf[0] = 0; - sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative, + sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative, (char*)0); + sqliteFree(zBuf); } return zFull; } @@ -1331,9 +1436,16 @@ ** return 0. Return 1 if the time and date cannot be found. */ int sqlite3OsCurrentTime(double *prNow){ +#ifdef NO_GETTOD time_t t; time(&t); *prNow = t/86400.0 + 2440587.5; +#else + struct timeval sNow; + struct timezone sTz; /* Not used */ + gettimeofday(&sNow, &sTz); + *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0; +#endif #ifdef SQLITE_TEST if( sqlite3_current_time ){ *prNow = sqlite3_current_time/86400.0 + 2440587.5; ======================================================================== --- sqlite/os_unix.h 39a393252e69e72b06715c9958df05ddbc4aa971 +++ sqlite/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e @@ -52,6 +52,17 @@ #include /* +** Macros used to determine whether or not to use threads. The +** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for +** Posix threads and SQLITE_W32_THREADS is defined if we are +** synchronizing using Win32 threads. +*/ +#if defined(THREADSAFE) && THREADSAFE +# include +# define SQLITE_UNIX_THREADS 1 +#endif + +/* ** The OsFile structure is a operating-system independing representation ** of an open file handle. It is defined differently for each architecture. ** @@ -70,6 +81,9 @@ unsigned char isOpen; /* True if needs to be closed */ unsigned char fullSync; /* Use F_FULLSYNC if available */ int dirfd; /* File descriptor for the directory */ +#ifdef SQLITE_UNIX_THREADS + pthread_t tid; /* The thread authorized to use this OsFile */ +#endif }; /* ======================================================================== --- sqlite/os_win.c fe7b99cfcfb61d9bf54493ddf5857885a657fb89 +++ sqlite/os_win.c ed03a35b2894f9b99840415f941a9f8594dea756 @@ -42,10 +42,98 @@ #ifndef SQLITE_OMIT_DISKIO /* +** The following variable is (normally) set once and never changes +** thereafter. It records whether the operating system is Win95 +** or WinNT. +** +** 0: Operating system unknown. +** 1: Operating system is Win95. +** 2: Operating system is WinNT. +** +** In order to facilitate testing on a WinNT system, the test fixture +** can manually set this value to 1 to emulate Win98 behavior. +*/ +int sqlite3_os_type = 0; + +/* +** Return true (non-zero) if we are running under WinNT, Win2K or WinXP. +** Return false (zero) for Win95, Win98, or WinME. +** +** Here is an interesting observation: Win95, Win98, and WinME lack +** the LockFileEx() API. But we can still statically link against that +** API as long as we don't call it win running Win95/98/ME. A call to +** this routine is used to determine if the host is Win95/98/ME or +** WinNT/2K/XP so that we will know whether or not we can safely call +** the LockFileEx() API. +*/ +static int isNT(void){ + if( sqlite3_os_type==0 ){ + OSVERSIONINFO sInfo; + sInfo.dwOSVersionInfoSize = sizeof(sInfo); + GetVersionEx(&sInfo); + sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1; + } + return sqlite3_os_type==2; +} + +/* +** Convert a UTF-8 string to UTF-32. Space to hold the returned string +** is obtained from sqliteMalloc. +*/ +static WCHAR *utf8ToUnicode(const char *zFilename){ + int nByte; + WCHAR *zWideFilename; + + if( !isNT() ){ + return 0; + } + nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0)*sizeof(WCHAR); + zWideFilename = sqliteMalloc( nByte*sizeof(zWideFilename[0]) ); + if( zWideFilename==0 ){ + return 0; + } + nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nByte); + if( nByte==0 ){ + sqliteFree(zWideFilename); + zWideFilename = 0; + } + return zWideFilename; +} + +/* +** Convert UTF-32 to UTF-8. Space to hold the returned string is +** obtained from sqliteMalloc(). +*/ +static char *unicodeToUtf8(const WCHAR *zWideFilename){ + int nByte; + char *zFilename; + + nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); + zFilename = sqliteMalloc( nByte ); + if( zFilename==0 ){ + return 0; + } + nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, + 0, 0); + if( nByte == 0 ){ + sqliteFree(zFilename); + zFilename = 0; + } + return zFilename; +} + + +/* ** Delete the named file */ int sqlite3OsDelete(const char *zFilename){ - DeleteFileA(zFilename); + WCHAR *zWide = utf8ToUnicode(zFilename); + if( zWide ){ + DeleteFileW(zWide); + sqliteFree(zWide); + }else{ + DeleteFileA(zFilename); + } TRACE2("DELETE \"%s\"\n", zFilename); return SQLITE_OK; } @@ -54,7 +142,15 @@ ** Return TRUE if the named file exists. */ int sqlite3OsFileExists(const char *zFilename){ - return GetFileAttributesA(zFilename) != 0xffffffff; + int exists = 0; + WCHAR *zWide = utf8ToUnicode(zFilename); + if( zWide ){ + exists = GetFileAttributesW(zWide) != 0xffffffff; + sqliteFree(zWide); + }else{ + exists = GetFileAttributesA(zFilename) != 0xffffffff; + } + return exists; } /* @@ -76,30 +172,60 @@ int *pReadonly ){ HANDLE h; + WCHAR *zWide = utf8ToUnicode(zFilename); assert( !id->isOpen ); - h = CreateFileA(zFilename, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, - NULL - ); - if( h==INVALID_HANDLE_VALUE ){ + if( zWide ){ + h = CreateFileW(zWide, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, + NULL + ); + if( h==INVALID_HANDLE_VALUE ){ + h = CreateFileW(zWide, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, + NULL + ); + if( h==INVALID_HANDLE_VALUE ){ + sqliteFree(zWide); + return SQLITE_CANTOPEN; + } + *pReadonly = 1; + }else{ + *pReadonly = 0; + } + sqliteFree(zWide); + }else{ h = CreateFileA(zFilename, - GENERIC_READ, - FILE_SHARE_READ, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); if( h==INVALID_HANDLE_VALUE ){ - return SQLITE_CANTOPEN; + h = CreateFileA(zFilename, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, + NULL + ); + if( h==INVALID_HANDLE_VALUE ){ + return SQLITE_CANTOPEN; + } + *pReadonly = 1; + }else{ + *pReadonly = 0; } - *pReadonly = 1; - }else{ - *pReadonly = 0; } id->h = h; id->locktype = NO_LOCK; @@ -128,6 +254,7 @@ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ HANDLE h; int fileflags; + WCHAR *zWide = utf8ToUnicode(zFilename); assert( !id->isOpen ); if( delFlag ){ fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS @@ -135,14 +262,26 @@ }else{ fileflags = FILE_FLAG_RANDOM_ACCESS; } - h = CreateFileA(zFilename, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - fileflags, - NULL - ); + if( zWide ){ + h = CreateFileW(zWide, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + fileflags, + NULL + ); + sqliteFree(zWide); + }else{ + h = CreateFileA(zFilename, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + fileflags, + NULL + ); + } if( h==INVALID_HANDLE_VALUE ){ return SQLITE_CANTOPEN; } @@ -164,15 +303,28 @@ */ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ HANDLE h; + WCHAR *zWide = utf8ToUnicode(zFilename); assert( !id->isOpen ); - h = CreateFileA(zFilename, - GENERIC_READ, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, - NULL - ); + if( zWide ){ + h = CreateFileW(zWide, + GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, + NULL + ); + sqliteFree(zWide); + }else{ + h = CreateFileA(zFilename, + GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, + NULL + ); + } if( h==INVALID_HANDLE_VALUE ){ return SQLITE_CANTOPEN; } @@ -229,6 +381,16 @@ if( sqlite3_temp_directory ){ strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30); zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0; + }else if( isNT() ){ + char *zMulti; + WCHAR zWidePath[SQLITE_TEMPNAME_SIZE]; + GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath); + zMulti = unicodeToUtf8(zWidePath); + if( zMulti ){ + strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30); + zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0; + sqliteFree(zMulti); + } }else{ GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath); } @@ -311,16 +473,22 @@ LONG lowerBits = offset & 0xffffffff; DWORD rc; assert( id->isOpen ); +#ifdef SQLITE_TEST + if( offset ) SimulateDiskfullError +#endif SEEK(offset/1024 + 1); rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN); TRACE3("SEEK %d %lld\n", id->h, offset); + if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){ + return SQLITE_FULL; + } return SQLITE_OK; } /* ** Make sure all writes to a particular file are committed to disk. */ -int sqlite3OsSync(OsFile *id){ +int sqlite3OsSync(OsFile *id, int dataOnly){ assert( id->isOpen ); TRACE3("SYNC %d lock=%d\n", id->h, id->locktype); if( FlushFileBuffers(id->h) ){ @@ -365,28 +533,6 @@ } /* -** Return true (non-zero) if we are running under WinNT, Win2K or WinXP. -** Return false (zero) for Win95, Win98, or WinME. -** -** Here is an interesting observation: Win95, Win98, and WinME lack -** the LockFileEx() API. But we can still statically link against that -** API as long as we don't call it win running Win95/98/ME. A call to -** this routine is used to determine if the host is Win95/98/ME or -** WinNT/2K/XP so that we will know whether or not we can safely call -** the LockFileEx() API. -*/ -static int isNT(void){ - static int osType = 0; /* 0=unknown 1=win95 2=winNT */ - if( osType==0 ){ - OSVERSIONINFO sInfo; - sInfo.dwOSVersionInfoSize = sizeof(sInfo); - GetVersionEx(&sInfo); - osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1; - } - return osType==2; -} - -/* ** Acquire a reader lock. ** Different API routines are called depending on whether or not this ** is Win95 or WinNT. @@ -426,11 +572,18 @@ ** Check that a given pathname is a directory and is writable ** */ -int sqlite3OsIsDirWritable(char *zBuf){ +int sqlite3OsIsDirWritable(char *zDirname){ int fileAttr; - if(! zBuf ) return 0; - if(! isNT() && strlen(zBuf) > MAX_PATH ) return 0; - fileAttr = GetFileAttributesA(zBuf); + WCHAR *zWide; + if( zDirname==0 ) return 0; + if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0; + zWide = utf8ToUnicode(zDirname); + if( zWide ){ + fileAttr = GetFileAttributesW(zWide); + sqliteFree(zWide); + }else{ + fileAttr = GetFileAttributesA(zDirname); + } if( fileAttr == 0xffffffff ) return 0; if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){ return 0; @@ -641,6 +794,7 @@ char *sqlite3OsFullPathname(const char *zRelative){ char *zNotUsed; char *zFull; + WCHAR *zWide; int nByte; #ifdef __CYGWIN__ nByte = strlen(zRelative) + MAX_PATH + 1001; @@ -648,10 +802,22 @@ if( zFull==0 ) return 0; if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0; #else - nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1; - zFull = sqliteMalloc( nByte ); - if( zFull==0 ) return 0; - GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed); + zWide = utf8ToUnicode(zRelative); + if( zWide ){ + WCHAR *zTemp, *zNotUsedW; + nByte = GetFullPathNameW(zWide, 0, 0, &zNotUsedW) + 1; + zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) ); + if( zTemp==0 ) return 0; + GetFullPathNameW(zWide, nByte, zTemp, &zNotUsedW); + sqliteFree(zWide); + zFull = unicodeToUtf8(zTemp); + sqliteFree(zTemp); + }else{ + nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1; + zFull = sqliteMalloc( nByte*sizeof(zFull[0]) ); + if( zFull==0 ) return 0; + GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed); + } #endif return zFull; } ======================================================================== --- sqlite/pager.c 841a2cdddd4275de36cda26ed9dc54ae942660ce +++ sqlite/pager.c adbb27f13ac75cd5bc29a3d84803e0cab1edfa88 @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.207 2005/06/07 02:12:30 drh Exp $ +** @(#) $Id: pager.c,v 1.215 2005/09/17 15:20:27 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -657,8 +657,10 @@ ** file descriptor to the end of the journal header sector. */ if( rc==SQLITE_OK ){ - sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1); - rc = sqlite3OsWrite(&pPager->jfd, "\000", 1); + rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1); + if( rc==SQLITE_OK ){ + rc = sqlite3OsWrite(&pPager->jfd, "\000", 1); + } } return rc; } @@ -779,7 +781,7 @@ if( rc!=SQLITE_OK ) return rc; rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic)); - pPager->needSync = 1; + pPager->needSync = !pPager->noSync; return rc; } @@ -1038,8 +1040,10 @@ assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 ); TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno); if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){ - sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); - rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize); + rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); + if( rc==SQLITE_OK ){ + rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize); + } if( pPg ) pPg->dirty = 0; } if( pPg ){ @@ -1168,8 +1172,10 @@ char zBuf[SQLITE_MAX_PAGE_SIZE]; if( !pPg->dirty ) continue; if( (int)pPg->pgno <= pPager->origDbSize ){ - sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1)); - rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize); + rc = sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1)); + if( rc==SQLITE_OK ){ + rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize); + } TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno); if( rc ) break; CODEC(pPager, zBuf, pPg->pgno, 2); @@ -1485,7 +1491,7 @@ end_stmt_playback: if( rc!=SQLITE_OK ){ pPager->errMask |= PAGER_ERR_CORRUPT; - rc = SQLITE_CORRUPT; /* bkpt-CORRUPT */ + rc = SQLITE_CORRUPT; }else{ pPager->journalOff = szJ; /* pager_reload_cache(pPager); */ @@ -1746,25 +1752,35 @@ /* ** Return the total number of pages in the disk file associated with -** pPager. +** pPager. +** +** If the PENDING_BYTE lies on the page directly after the end of the +** file, then consider this page part of the file too. For example, if +** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the +** file is 4096 bytes, 5 is returned instead of 4. */ int sqlite3pager_pagecount(Pager *pPager){ i64 n; assert( pPager!=0 ); if( pPager->dbSize>=0 ){ - return pPager->dbSize; + n = pPager->dbSize; + } else { + if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){ + pPager->errMask |= PAGER_ERR_DISK; + return 0; + } + if( n>0 && npageSize ){ + n = 1; + }else{ + n /= pPager->pageSize; + } + if( pPager->state!=PAGER_UNLOCK ){ + pPager->dbSize = n; + } } - if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){ - pPager->errMask |= PAGER_ERR_DISK; - return 0; - } - n /= pPager->pageSize; - if( !MEMDB && n==PENDING_BYTE/pPager->pageSize ){ + if( n==(PENDING_BYTE/pPager->pageSize) ){ n++; } - if( pPager->state!=PAGER_UNLOCK ){ - pPager->dbSize = n; - } return n; } @@ -1866,7 +1882,7 @@ /* ** Try to obtain a lock on a file. Invoke the busy callback if the lock -** is currently not available. Repeate until the busy callback returns +** is currently not available. Repeat until the busy callback returns ** false or until the lock succeeds. ** ** Return SQLITE_OK on success and an error code if we cannot obtain @@ -1880,14 +1896,9 @@ if( pPager->state>=locktype ){ rc = SQLITE_OK; }else{ - int busy = 1; - BusyHandler *pH; do { rc = sqlite3OsLock(&pPager->fd, locktype); - }while( rc==SQLITE_BUSY && - (pH = pPager->pBusyHandler)!=0 && - pH->xFunc && pH->xFunc(pH->pArg, busy++) - ); + }while( rc==SQLITE_BUSY && sqlite3InvokeBusyHandler(pPager->pBusyHandler) ); if( rc==SQLITE_OK ){ pPager->state = locktype; } @@ -2122,17 +2133,20 @@ */ if( pPager->fullSync ){ TRACE2("SYNC journal of %d\n", PAGERID(pPager)); - rc = sqlite3OsSync(&pPager->jfd); + rc = sqlite3OsSync(&pPager->jfd, 0); if( rc!=0 ) return rc; } - sqlite3OsSeek(&pPager->jfd, pPager->journalHdr + sizeof(aJournalMagic)); + rc = sqlite3OsSeek(&pPager->jfd, + pPager->journalHdr + sizeof(aJournalMagic)); + if( rc ) return rc; rc = write32bits(&pPager->jfd, pPager->nRec); if( rc ) return rc; - sqlite3OsSeek(&pPager->jfd, pPager->journalOff); + rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff); + if( rc ) return rc; } TRACE2("SYNC journal of %d\n", PAGERID(pPager)); - rc = sqlite3OsSync(&pPager->jfd); + rc = sqlite3OsSync(&pPager->jfd, pPager->fullSync); if( rc!=0 ) return rc; pPager->journalStarted = 1; } @@ -2197,7 +2211,8 @@ while( pList ){ assert( pList->dirty ); - sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize); + rc = sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize); + if( rc ) return rc; /* If there are dirty pages in the page cache with page numbers greater ** than Pager.dbSize, this means sqlite3pager_truncate() was called to ** make the file smaller (presumably by auto-vacuum code). Do not write @@ -2292,8 +2307,8 @@ /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page ** number greater than this, or zero, is requested. */ - if( pgno>PAGER_MAX_PGNO || pgno==0 ){ - return SQLITE_CORRUPT; + if( pgno>PAGER_MAX_PGNO || pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ + return SQLITE_CORRUPT_BKPT; } /* Make sure we have not hit any critical errors. @@ -2507,8 +2522,10 @@ }else{ int rc; assert( MEMDB==0 ); - sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); - rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize); + rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); + if( rc==SQLITE_OK ){ + rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize); + } TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno); CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); if( rc!=SQLITE_OK ){ @@ -2816,6 +2833,10 @@ } }else{ u32 cksum; + /* We should never write to the journal file the page that + ** contains the database locks. The following assert verifies + ** that we do not. */ + assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); CODEC(pPager, pData, pPg->pgno, 7); cksum = pager_cksum(pPager, pPg->pgno, pData); saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager); @@ -3172,7 +3193,7 @@ rc = pager_playback(pPager); } if( rc!=SQLITE_OK ){ - rc = SQLITE_CORRUPT; /* bkpt-CORRUPT */ + rc = SQLITE_CORRUPT_BKPT; pPager->errMask |= PAGER_ERR_CORRUPT; } pPager->dbSize = -1; @@ -3347,6 +3368,14 @@ } /* +** Return true if fsync() calls are disabled for this pager. Return FALSE +** if fsync()s are executed normally. +*/ +int sqlite3pager_nosync(Pager *pPager){ + return pPager->noSync; +} + +/* ** Set the codec for this pager */ void sqlite3pager_set_codec( @@ -3434,8 +3463,9 @@ */ Pgno i; void *pPage; + int iSkip = PAGER_MJ_PGNO(pPager); for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ - if( !(pPager->aInJournal[i/8] & (1<<(i&7))) ){ + if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){ rc = sqlite3pager_get(pPager, i, &pPage); if( rc!=SQLITE_OK ) goto sync_exit; rc = sqlite3pager_write(pPage); @@ -3465,7 +3495,7 @@ /* Sync the database file. */ if( !pPager->noSync ){ - rc = sqlite3OsSync(&pPager->fd); + rc = sqlite3OsSync(&pPager->fd, 0); } pPager->state = PAGER_SYNCED; ======================================================================== --- sqlite/pager.h 0d9153d6269d60d04af3dd84a0cc0a96253cf4a4 +++ sqlite/pager.h 17b13225abd93c1e9f470060f40a21b9edb5a164 @@ -13,7 +13,7 @@ ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** -** @(#) $Id: pager.h,v 1.44 2005/05/20 20:01:56 drh Exp $ +** @(#) $Id: pager.h,v 1.45 2005/08/27 16:36:49 drh Exp $ */ /* @@ -100,6 +100,7 @@ const char *sqlite3pager_filename(Pager*); const char *sqlite3pager_dirname(Pager*); const char *sqlite3pager_journalname(Pager*); +int sqlite3pager_nosync(Pager*); int sqlite3pager_rename(Pager*, const char *zNewName); void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*); int sqlite3pager_movepage(Pager*,void*,Pgno); ======================================================================== --- sqlite/parse.c 6671523c392fcf8287c08e5896cc2513987fc5cb +++ sqlite/parse.c 9f03b15f12e12a7952705f50d01e3ac97bb81e34 @@ -1,10 +1,10 @@ /* Driver template for the LEMON parser generator. ** The author disclaims copyright to this source code. */ /* First off, code is include which follows the "include" declaration ** in the input file. */ #include -#line 33 "parse.y" +#line 51 "parse.y" #include "sqliteInt.h" #include "parse.h" @@ -93,35 +93,35 @@ ** defined, then do no error processing. */ #define YYCODETYPE unsigned char -#define YYNOCODE 241 +#define YYNOCODE 247 #define YYACTIONTYPE unsigned short int #define sqlite3ParserTOKENTYPE Token typedef union { sqlite3ParserTOKENTYPE yy0; - Expr* yy2; - struct {int value; int mask;} yy47; - SrcList* yy67; - ExprList* yy82; - struct AttachKey yy132; - struct TrigEvent yy210; + struct TrigEvent yy30; + Expr* yy62; + SrcList* yy151; + Token yy198; + struct LimitVal yy220; + struct LikeOp yy222; IdList* yy240; - struct LimitVal yy244; - Token yy258; - TriggerStep* yy347; - int yy412; - struct LikeOp yy438; - Select* yy459; - int yy481; + int yy280; + struct {int value; int mask;} yy359; + TriggerStep* yy360; + struct AttachKey yy361; + Select* yy375; + ExprList* yy418; + int yy493; } YYMINORTYPE; #define YYSTACKDEPTH 100 #define sqlite3ParserARG_SDECL Parse *pParse; #define sqlite3ParserARG_PDECL ,Parse *pParse #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse #define sqlite3ParserARG_STORE yypParser->pParse = pParse -#define YYNSTATE 565 -#define YYNRULE 305 -#define YYERRORSYMBOL 141 -#define YYERRSYMDT yy481 +#define YYNSTATE 581 +#define YYNRULE 311 +#define YYERRORSYMBOL 146 +#define YYERRSYMDT yy493 #define YYFALLBACK 1 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) @@ -175,467 +175,485 @@ ** yy_default[] Default action for each state. */ static const YYACTIONTYPE yy_action[] = { - /* 0 */ 259, 65, 257, 112, 114, 110, 116, 66, 122, 124, - /* 10 */ 126, 128, 130, 132, 134, 136, 138, 140, 568, 142, - /* 20 */ 150, 122, 124, 126, 128, 130, 132, 134, 136, 138, - /* 30 */ 140, 130, 132, 134, 136, 138, 140, 108, 94, 143, - /* 40 */ 153, 158, 163, 152, 157, 118, 120, 112, 114, 110, - /* 50 */ 116, 72, 122, 124, 126, 128, 130, 132, 134, 136, - /* 60 */ 138, 140, 7, 106, 219, 258, 122, 124, 126, 128, - /* 70 */ 130, 132, 134, 136, 138, 140, 367, 13, 9, 369, - /* 80 */ 376, 381, 142, 871, 1, 564, 92, 27, 4, 399, - /* 90 */ 363, 384, 844, 341, 291, 28, 10, 95, 398, 33, - /* 100 */ 108, 94, 143, 153, 158, 163, 152, 157, 118, 120, - /* 110 */ 112, 114, 110, 116, 96, 122, 124, 126, 128, 130, - /* 120 */ 132, 134, 136, 138, 140, 456, 565, 142, 395, 305, - /* 130 */ 101, 102, 103, 288, 75, 394, 3, 563, 231, 275, - /* 140 */ 14, 15, 575, 597, 437, 108, 94, 143, 153, 158, - /* 150 */ 163, 152, 157, 118, 120, 112, 114, 110, 116, 13, - /* 160 */ 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, - /* 170 */ 573, 77, 142, 223, 232, 13, 490, 462, 452, 167, - /* 180 */ 306, 169, 170, 276, 254, 3, 563, 81, 277, 183, - /* 190 */ 108, 94, 143, 153, 158, 163, 152, 157, 118, 120, - /* 200 */ 112, 114, 110, 116, 52, 122, 124, 126, 128, 130, - /* 210 */ 132, 134, 136, 138, 140, 48, 54, 799, 448, 51, - /* 220 */ 797, 77, 14, 15, 49, 363, 134, 136, 138, 140, - /* 230 */ 16, 17, 18, 32, 33, 50, 308, 197, 14, 15, - /* 240 */ 367, 261, 13, 369, 376, 381, 142, 37, 337, 40, - /* 250 */ 59, 67, 69, 301, 332, 384, 364, 397, 259, 807, - /* 260 */ 257, 334, 51, 193, 108, 94, 143, 153, 158, 163, - /* 270 */ 152, 157, 118, 120, 112, 114, 110, 116, 262, 122, - /* 280 */ 124, 126, 128, 130, 132, 134, 136, 138, 140, 13, - /* 290 */ 171, 142, 40, 59, 67, 69, 301, 332, 642, 148, - /* 300 */ 365, 159, 164, 261, 334, 14, 15, 44, 45, 108, - /* 310 */ 94, 143, 153, 158, 163, 152, 157, 118, 120, 112, - /* 320 */ 114, 110, 116, 258, 122, 124, 126, 128, 130, 132, - /* 330 */ 134, 136, 138, 140, 148, 218, 159, 164, 184, 12, - /* 340 */ 284, 417, 48, 360, 358, 293, 290, 347, 352, 353, - /* 350 */ 289, 49, 14, 15, 688, 2, 96, 148, 4, 159, - /* 360 */ 164, 257, 50, 530, 46, 142, 367, 155, 165, 369, - /* 370 */ 376, 381, 13, 576, 47, 167, 75, 169, 170, 554, - /* 380 */ 172, 384, 207, 108, 94, 143, 153, 158, 163, 152, - /* 390 */ 157, 118, 120, 112, 114, 110, 116, 154, 122, 124, - /* 400 */ 126, 128, 130, 132, 134, 136, 138, 140, 299, 354, - /* 410 */ 350, 352, 353, 96, 96, 13, 34, 20, 294, 362, - /* 420 */ 345, 144, 581, 167, 258, 169, 170, 821, 142, 558, - /* 430 */ 213, 244, 254, 75, 75, 14, 15, 172, 186, 167, - /* 440 */ 533, 169, 170, 146, 147, 417, 108, 94, 143, 153, - /* 450 */ 158, 163, 152, 157, 118, 120, 112, 114, 110, 116, - /* 460 */ 96, 122, 124, 126, 128, 130, 132, 134, 136, 138, - /* 470 */ 140, 145, 354, 142, 22, 239, 383, 589, 14, 15, - /* 480 */ 75, 36, 336, 419, 172, 187, 842, 213, 528, 582, - /* 490 */ 331, 108, 94, 143, 153, 158, 163, 152, 157, 118, - /* 500 */ 120, 112, 114, 110, 116, 249, 122, 124, 126, 128, - /* 510 */ 130, 132, 134, 136, 138, 140, 306, 661, 142, 327, - /* 520 */ 574, 849, 148, 11, 159, 164, 309, 316, 318, 168, - /* 530 */ 42, 327, 666, 327, 212, 393, 108, 94, 143, 153, - /* 540 */ 158, 163, 152, 157, 118, 120, 112, 114, 110, 116, - /* 550 */ 96, 122, 124, 126, 128, 130, 132, 134, 136, 138, - /* 560 */ 140, 847, 83, 142, 321, 641, 372, 31, 663, 282, - /* 570 */ 75, 242, 308, 689, 231, 246, 167, 334, 169, 170, - /* 580 */ 269, 108, 94, 143, 153, 158, 163, 152, 157, 118, - /* 590 */ 120, 112, 114, 110, 116, 324, 122, 124, 126, 128, - /* 600 */ 130, 132, 134, 136, 138, 140, 246, 328, 142, 328, - /* 610 */ 225, 434, 24, 39, 433, 210, 167, 211, 169, 170, - /* 620 */ 167, 331, 169, 170, 583, 435, 108, 161, 143, 153, - /* 630 */ 158, 163, 152, 157, 118, 120, 112, 114, 110, 116, - /* 640 */ 248, 122, 124, 126, 128, 130, 132, 134, 136, 138, - /* 650 */ 140, 57, 58, 142, 624, 837, 323, 727, 271, 261, - /* 660 */ 167, 243, 169, 170, 313, 312, 247, 167, 798, 169, - /* 670 */ 170, 248, 94, 143, 153, 158, 163, 152, 157, 118, - /* 680 */ 120, 112, 114, 110, 116, 96, 122, 124, 126, 128, - /* 690 */ 130, 132, 134, 136, 138, 140, 279, 247, 142, 360, - /* 700 */ 358, 6, 5, 363, 346, 75, 274, 25, 257, 489, - /* 710 */ 13, 561, 33, 503, 13, 268, 267, 269, 143, 153, - /* 720 */ 158, 163, 152, 157, 118, 120, 112, 114, 110, 116, - /* 730 */ 64, 122, 124, 126, 128, 130, 132, 134, 136, 138, - /* 740 */ 140, 26, 76, 96, 400, 77, 71, 584, 96, 451, - /* 750 */ 166, 485, 29, 76, 402, 78, 167, 71, 169, 170, - /* 760 */ 295, 451, 211, 75, 30, 257, 314, 172, 75, 195, - /* 770 */ 514, 258, 292, 14, 15, 690, 77, 14, 15, 106, - /* 780 */ 195, 77, 77, 173, 191, 315, 203, 77, 344, 215, - /* 790 */ 106, 690, 327, 77, 173, 495, 338, 588, 529, 403, - /* 800 */ 179, 177, 296, 453, 251, 209, 475, 327, 175, 73, - /* 810 */ 74, 179, 177, 95, 531, 532, 35, 213, 475, 175, - /* 820 */ 73, 74, 457, 38, 95, 378, 438, 459, 258, 501, - /* 830 */ 449, 497, 841, 411, 461, 406, 653, 76, 311, 459, - /* 840 */ 387, 71, 322, 81, 323, 42, 101, 102, 103, 104, - /* 850 */ 105, 181, 185, 96, 356, 357, 96, 101, 102, 103, - /* 860 */ 104, 105, 181, 185, 195, 76, 655, 544, 328, 71, - /* 870 */ 96, 271, 431, 75, 106, 354, 75, 489, 173, 327, - /* 880 */ 298, 215, 410, 328, 428, 430, 429, 426, 427, 96, - /* 890 */ 75, 721, 195, 76, 91, 179, 177, 71, 348, 379, - /* 900 */ 349, 323, 106, 175, 73, 74, 173, 467, 95, 75, - /* 910 */ 271, 499, 445, 93, 77, 388, 446, 323, 323, 521, - /* 920 */ 195, 454, 45, 179, 177, 285, 836, 42, 41, 432, - /* 930 */ 106, 175, 73, 74, 173, 480, 95, 269, 488, 43, - /* 940 */ 486, 101, 102, 103, 104, 105, 181, 185, 800, 721, - /* 950 */ 417, 179, 177, 229, 422, 328, 96, 96, 96, 175, - /* 960 */ 73, 74, 814, 96, 95, 522, 53, 486, 479, 101, - /* 970 */ 102, 103, 104, 105, 181, 185, 75, 75, 75, 13, - /* 980 */ 107, 109, 423, 75, 55, 8, 106, 111, 496, 857, - /* 990 */ 19, 21, 23, 401, 96, 472, 56, 101, 102, 103, - /* 1000 */ 104, 105, 181, 185, 536, 240, 81, 339, 342, 863, - /* 1010 */ 546, 61, 96, 96, 75, 96, 341, 482, 113, 483, - /* 1020 */ 95, 96, 525, 417, 456, 542, 13, 96, 96, 523, - /* 1030 */ 417, 549, 75, 75, 552, 75, 115, 117, 472, 119, - /* 1040 */ 96, 75, 14, 15, 81, 121, 96, 75, 75, 77, - /* 1050 */ 417, 123, 125, 101, 102, 103, 60, 519, 466, 96, - /* 1060 */ 75, 498, 417, 240, 127, 417, 75, 64, 500, 62, - /* 1070 */ 129, 96, 63, 690, 96, 504, 508, 452, 68, 75, - /* 1080 */ 417, 494, 96, 131, 96, 96, 81, 96, 502, 14, - /* 1090 */ 15, 75, 96, 96, 75, 133, 555, 70, 135, 96, - /* 1100 */ 506, 512, 75, 510, 75, 75, 137, 75, 139, 141, - /* 1110 */ 96, 149, 75, 75, 81, 96, 151, 160, 516, 75, - /* 1120 */ 96, 96, 96, 162, 598, 80, 599, 96, 96, 82, - /* 1130 */ 75, 240, 221, 84, 174, 75, 96, 96, 96, 176, - /* 1140 */ 75, 75, 75, 96, 178, 180, 192, 75, 75, 518, - /* 1150 */ 96, 194, 204, 96, 79, 286, 75, 75, 75, 237, - /* 1160 */ 206, 208, 220, 75, 96, 96, 96, 236, 85, 235, - /* 1170 */ 75, 96, 87, 75, 241, 75, 867, 273, 215, 283, - /* 1180 */ 86, 77, 90, 97, 75, 75, 75, 88, 382, 470, - /* 1190 */ 474, 75, 89, 98, 99, 487, 100, 140, 156, 214, - /* 1200 */ 667, 668, 669, 182, 205, 188, 190, 189, 196, 199, - /* 1210 */ 198, 201, 215, 200, 202, 216, 217, 224, 222, 228, - /* 1220 */ 227, 229, 230, 226, 234, 238, 211, 245, 233, 253, - /* 1230 */ 250, 252, 255, 272, 260, 263, 265, 256, 264, 266, - /* 1240 */ 270, 278, 287, 280, 297, 281, 300, 320, 303, 302, - /* 1250 */ 305, 307, 304, 325, 333, 329, 310, 317, 326, 351, - /* 1260 */ 355, 370, 359, 330, 319, 340, 343, 368, 371, 361, - /* 1270 */ 374, 377, 385, 335, 375, 373, 396, 386, 380, 389, - /* 1280 */ 390, 54, 366, 391, 404, 392, 407, 405, 409, 408, - /* 1290 */ 412, 413, 418, 416, 829, 414, 424, 425, 415, 834, - /* 1300 */ 420, 439, 835, 421, 436, 440, 441, 442, 443, 444, - /* 1310 */ 447, 805, 450, 806, 455, 458, 828, 460, 728, 464, - /* 1320 */ 729, 843, 453, 465, 468, 471, 463, 845, 476, 469, - /* 1330 */ 481, 478, 473, 477, 484, 846, 493, 491, 848, 492, - /* 1340 */ 660, 662, 813, 855, 505, 507, 720, 509, 511, 723, - /* 1350 */ 513, 726, 515, 815, 524, 526, 527, 520, 517, 816, - /* 1360 */ 817, 818, 819, 534, 535, 820, 856, 539, 858, 540, - /* 1370 */ 545, 538, 543, 859, 862, 548, 551, 864, 553, 550, - /* 1380 */ 537, 557, 541, 547, 865, 556, 866, 560, 559, 547, - /* 1390 */ 562, + /* 0 */ 286, 584, 113, 140, 142, 138, 144, 581, 150, 152, + /* 10 */ 154, 156, 158, 160, 162, 164, 166, 168, 3, 577, + /* 20 */ 740, 170, 178, 150, 152, 154, 156, 158, 160, 162, + /* 30 */ 164, 166, 168, 158, 160, 162, 164, 166, 168, 135, + /* 40 */ 97, 171, 181, 186, 191, 180, 185, 146, 148, 140, + /* 50 */ 142, 138, 144, 51, 150, 152, 154, 156, 158, 160, + /* 60 */ 162, 164, 166, 168, 16, 17, 18, 114, 7, 248, + /* 70 */ 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, + /* 80 */ 13, 37, 362, 40, 59, 67, 69, 326, 357, 170, + /* 90 */ 6, 5, 331, 95, 364, 359, 25, 374, 258, 893, + /* 100 */ 1, 580, 514, 13, 4, 575, 33, 135, 97, 171, + /* 110 */ 181, 186, 191, 180, 185, 146, 148, 140, 142, 138, + /* 120 */ 144, 9, 150, 152, 154, 156, 158, 160, 162, 164, + /* 130 */ 166, 168, 374, 136, 592, 80, 112, 99, 269, 34, + /* 140 */ 32, 33, 132, 373, 115, 14, 15, 378, 333, 99, + /* 150 */ 380, 387, 392, 13, 367, 370, 194, 170, 78, 500, + /* 160 */ 525, 315, 395, 369, 375, 408, 10, 98, 14, 15, + /* 170 */ 78, 200, 286, 864, 113, 135, 97, 171, 181, 186, + /* 180 */ 191, 180, 185, 146, 148, 140, 142, 138, 144, 80, + /* 190 */ 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, + /* 200 */ 104, 105, 106, 661, 496, 376, 374, 170, 467, 13, + /* 210 */ 2, 28, 237, 4, 409, 33, 3, 577, 14, 15, + /* 220 */ 51, 132, 133, 115, 241, 135, 97, 171, 181, 186, + /* 230 */ 191, 180, 185, 146, 148, 140, 142, 138, 144, 114, + /* 240 */ 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, + /* 250 */ 40, 59, 67, 69, 326, 357, 136, 44, 45, 501, + /* 260 */ 473, 463, 359, 36, 361, 130, 128, 660, 275, 31, + /* 270 */ 84, 99, 356, 378, 14, 15, 380, 387, 392, 52, + /* 280 */ 170, 117, 122, 123, 113, 541, 369, 643, 395, 348, + /* 290 */ 98, 54, 78, 200, 302, 57, 58, 819, 135, 97, + /* 300 */ 171, 181, 186, 191, 180, 185, 146, 148, 140, 142, + /* 310 */ 138, 144, 861, 150, 152, 154, 156, 158, 160, 162, + /* 320 */ 164, 166, 168, 104, 105, 106, 817, 80, 48, 316, + /* 330 */ 162, 164, 166, 168, 319, 277, 12, 49, 99, 303, + /* 340 */ 283, 818, 99, 124, 304, 99, 241, 172, 593, 114, + /* 350 */ 50, 193, 46, 378, 170, 13, 380, 387, 392, 78, + /* 360 */ 260, 276, 47, 78, 200, 64, 78, 260, 395, 174, + /* 370 */ 175, 221, 135, 97, 171, 181, 186, 191, 180, 185, + /* 380 */ 146, 148, 140, 142, 138, 144, 199, 150, 152, 154, + /* 390 */ 156, 158, 160, 162, 164, 166, 168, 173, 252, 261, + /* 400 */ 120, 122, 123, 212, 170, 268, 254, 130, 128, 288, + /* 410 */ 590, 176, 246, 187, 192, 414, 195, 241, 197, 198, + /* 420 */ 14, 15, 135, 97, 171, 181, 186, 191, 180, 185, + /* 430 */ 146, 148, 140, 142, 138, 144, 433, 150, 152, 154, + /* 440 */ 156, 158, 160, 162, 164, 166, 168, 311, 99, 707, + /* 450 */ 99, 422, 708, 417, 275, 81, 318, 598, 99, 219, + /* 460 */ 13, 231, 124, 13, 176, 48, 187, 192, 20, 78, + /* 470 */ 317, 78, 214, 195, 49, 197, 198, 462, 170, 78, + /* 480 */ 200, 116, 27, 13, 410, 113, 591, 50, 80, 225, + /* 490 */ 195, 11, 197, 198, 506, 235, 135, 97, 171, 181, + /* 500 */ 186, 191, 180, 185, 146, 148, 140, 142, 138, 144, + /* 510 */ 80, 150, 152, 154, 156, 158, 160, 162, 164, 166, + /* 520 */ 168, 277, 215, 324, 606, 14, 15, 301, 14, 15, + /* 530 */ 512, 13, 508, 240, 196, 486, 195, 685, 197, 198, + /* 540 */ 22, 834, 445, 331, 462, 170, 444, 276, 14, 15, + /* 550 */ 114, 468, 278, 394, 599, 280, 470, 288, 446, 680, + /* 560 */ 13, 321, 404, 135, 97, 171, 181, 186, 191, 180, + /* 570 */ 185, 146, 148, 140, 142, 138, 144, 80, 150, 152, + /* 580 */ 154, 156, 158, 160, 162, 164, 166, 168, 74, 99, + /* 590 */ 540, 366, 73, 99, 352, 289, 14, 15, 176, 333, + /* 600 */ 187, 192, 486, 869, 359, 273, 283, 542, 543, 867, + /* 610 */ 78, 500, 510, 170, 78, 323, 682, 176, 472, 187, + /* 620 */ 192, 746, 118, 470, 119, 14, 15, 195, 346, 197, + /* 630 */ 198, 135, 97, 171, 181, 186, 191, 180, 185, 146, + /* 640 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, + /* 650 */ 158, 160, 162, 164, 166, 168, 532, 334, 341, 343, + /* 660 */ 841, 39, 195, 170, 197, 198, 78, 94, 124, 356, + /* 670 */ 271, 353, 439, 441, 440, 544, 883, 428, 72, 862, + /* 680 */ 288, 135, 97, 171, 181, 186, 191, 180, 185, 146, + /* 690 */ 148, 140, 142, 138, 144, 13, 150, 152, 154, 156, + /* 700 */ 158, 160, 162, 164, 166, 168, 195, 99, 197, 198, + /* 710 */ 406, 330, 195, 170, 197, 198, 568, 405, 306, 195, + /* 720 */ 42, 197, 198, 65, 195, 539, 197, 198, 78, 96, + /* 730 */ 66, 135, 97, 171, 181, 186, 191, 180, 185, 146, + /* 740 */ 148, 140, 142, 138, 144, 885, 150, 152, 154, 156, + /* 750 */ 158, 160, 162, 164, 166, 168, 99, 740, 99, 298, + /* 760 */ 14, 15, 272, 170, 13, 74, 572, 86, 600, 73, + /* 770 */ 126, 127, 614, 709, 309, 478, 24, 78, 247, 78, + /* 780 */ 111, 135, 97, 171, 181, 186, 191, 180, 185, 146, + /* 790 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, + /* 800 */ 158, 160, 162, 164, 166, 168, 99, 238, 113, 239, + /* 810 */ 295, 26, 296, 170, 338, 337, 78, 137, 294, 320, + /* 820 */ 347, 239, 348, 390, 211, 348, 30, 78, 139, 14, + /* 830 */ 15, 135, 189, 171, 181, 186, 191, 180, 185, 146, + /* 840 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, + /* 850 */ 158, 160, 162, 164, 166, 168, 99, 80, 99, 372, + /* 860 */ 399, 442, 348, 170, 298, 243, 78, 141, 363, 601, + /* 870 */ 428, 437, 438, 114, 411, 269, 605, 78, 143, 78, + /* 880 */ 145, 448, 97, 171, 181, 186, 191, 180, 185, 146, + /* 890 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, + /* 900 */ 158, 160, 162, 164, 166, 168, 99, 80, 99, 430, + /* 910 */ 99, 296, 555, 170, 413, 856, 78, 147, 672, 457, + /* 920 */ 352, 348, 298, 443, 465, 45, 35, 78, 149, 78, + /* 930 */ 151, 78, 153, 171, 181, 186, 191, 180, 185, 146, + /* 940 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, + /* 950 */ 158, 160, 162, 164, 166, 168, 99, 459, 99, 29, + /* 960 */ 79, 464, 183, 483, 71, 339, 78, 155, 709, 421, + /* 970 */ 428, 79, 109, 99, 491, 71, 296, 78, 157, 78, + /* 980 */ 159, 490, 243, 109, 99, 340, 99, 449, 857, 223, + /* 990 */ 99, 460, 182, 709, 78, 161, 99, 349, 827, 136, + /* 1000 */ 223, 99, 80, 201, 99, 78, 163, 78, 165, 507, + /* 1010 */ 136, 78, 167, 42, 201, 38, 493, 78, 169, 569, + /* 1020 */ 207, 205, 78, 177, 674, 78, 179, 477, 203, 76, + /* 1030 */ 77, 207, 205, 98, 99, 84, 99, 42, 336, 203, + /* 1040 */ 76, 77, 99, 43, 98, 41, 428, 79, 494, 80, + /* 1050 */ 428, 71, 84, 99, 352, 78, 188, 78, 190, 109, + /* 1060 */ 499, 428, 497, 78, 202, 60, 104, 105, 106, 107, + /* 1070 */ 108, 209, 213, 99, 78, 204, 223, 104, 105, 106, + /* 1080 */ 107, 108, 209, 213, 820, 509, 136, 53, 383, 511, + /* 1090 */ 201, 99, 56, 61, 78, 206, 55, 428, 428, 889, + /* 1100 */ 513, 99, 243, 99, 352, 99, 79, 207, 205, 312, + /* 1110 */ 71, 99, 78, 208, 483, 203, 76, 77, 109, 533, + /* 1120 */ 98, 497, 78, 220, 78, 222, 78, 232, 84, 99, + /* 1130 */ 428, 353, 78, 234, 352, 223, 517, 521, 389, 99, + /* 1140 */ 62, 530, 99, 64, 63, 136, 68, 529, 70, 201, + /* 1150 */ 78, 236, 352, 104, 105, 106, 107, 108, 209, 213, + /* 1160 */ 78, 249, 99, 78, 265, 877, 207, 205, 398, 527, + /* 1170 */ 99, 615, 616, 313, 203, 76, 77, 99, 523, 98, + /* 1180 */ 80, 353, 8, 78, 270, 99, 456, 19, 21, 23, + /* 1190 */ 412, 78, 300, 75, 78, 310, 82, 84, 78, 365, + /* 1200 */ 563, 83, 547, 99, 87, 553, 78, 393, 85, 557, + /* 1210 */ 99, 353, 104, 105, 106, 107, 108, 209, 213, 99, + /* 1220 */ 269, 536, 99, 467, 78, 434, 88, 266, 534, 353, + /* 1230 */ 560, 78, 481, 566, 264, 89, 250, 90, 93, 91, + /* 1240 */ 78, 485, 101, 78, 498, 92, 100, 102, 103, 110, + /* 1250 */ 131, 121, 134, 125, 129, 168, 184, 242, 686, 687, + /* 1260 */ 688, 210, 233, 218, 224, 216, 227, 226, 217, 229, + /* 1270 */ 228, 230, 243, 251, 515, 519, 463, 245, 253, 244, + /* 1280 */ 505, 257, 255, 256, 258, 84, 259, 262, 263, 239, + /* 1290 */ 267, 279, 274, 281, 282, 299, 285, 292, 284, 287, + /* 1300 */ 290, 293, 297, 305, 314, 291, 307, 322, 308, 325, + /* 1310 */ 327, 345, 329, 328, 332, 350, 354, 330, 358, 335, + /* 1320 */ 342, 379, 381, 382, 344, 351, 368, 385, 355, 371, + /* 1330 */ 388, 360, 396, 397, 400, 401, 415, 54, 416, 386, + /* 1340 */ 384, 391, 418, 402, 407, 419, 377, 420, 423, 424, + /* 1350 */ 403, 426, 425, 427, 429, 435, 431, 849, 436, 854, + /* 1360 */ 432, 855, 450, 447, 451, 452, 454, 453, 825, 455, + /* 1370 */ 458, 826, 469, 461, 466, 747, 748, 848, 471, 464, + /* 1380 */ 863, 480, 474, 475, 476, 482, 865, 479, 487, 484, + /* 1390 */ 489, 488, 492, 866, 495, 868, 504, 679, 502, 681, + /* 1400 */ 833, 875, 518, 503, 516, 739, 520, 524, 522, 742, + /* 1410 */ 745, 531, 526, 835, 535, 528, 538, 537, 836, 837, + /* 1420 */ 838, 839, 545, 546, 840, 550, 876, 556, 551, 878, + /* 1430 */ 548, 549, 554, 879, 559, 882, 884, 562, 886, 561, + /* 1440 */ 552, 558, 564, 567, 570, 565, 571, 887, 576, 574, + /* 1450 */ 573, 888, 578, 559, 559, 579, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 25, 30, 27, 72, 73, 74, 75, 36, 77, 78, - /* 10 */ 79, 80, 81, 82, 83, 84, 85, 86, 10, 44, - /* 20 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - /* 30 */ 86, 81, 82, 83, 84, 85, 86, 62, 63, 64, - /* 40 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, - /* 50 */ 75, 23, 77, 78, 79, 80, 81, 82, 83, 84, - /* 60 */ 85, 86, 10, 60, 26, 90, 77, 78, 79, 80, - /* 70 */ 81, 82, 83, 84, 85, 86, 92, 27, 148, 95, - /* 80 */ 96, 97, 44, 142, 143, 144, 48, 23, 147, 25, - /* 90 */ 150, 107, 18, 90, 24, 155, 149, 94, 158, 159, - /* 100 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - /* 110 */ 72, 73, 74, 75, 150, 77, 78, 79, 80, 81, - /* 120 */ 82, 83, 84, 85, 86, 51, 0, 44, 177, 178, - /* 130 */ 127, 128, 129, 83, 170, 184, 10, 11, 174, 157, - /* 140 */ 90, 91, 10, 115, 22, 62, 63, 64, 65, 66, - /* 150 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 27, - /* 160 */ 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, - /* 170 */ 10, 189, 44, 209, 210, 27, 102, 103, 104, 109, - /* 180 */ 45, 111, 112, 201, 202, 10, 11, 113, 206, 157, - /* 190 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - /* 200 */ 72, 73, 74, 75, 94, 77, 78, 79, 80, 81, - /* 210 */ 82, 83, 84, 85, 86, 19, 106, 134, 96, 64, - /* 220 */ 18, 189, 90, 91, 28, 150, 83, 84, 85, 86, - /* 230 */ 14, 15, 16, 158, 159, 39, 101, 41, 90, 91, - /* 240 */ 92, 163, 27, 95, 96, 97, 44, 92, 93, 94, - /* 250 */ 95, 96, 97, 98, 99, 107, 181, 182, 25, 137, - /* 260 */ 27, 106, 64, 135, 62, 63, 64, 65, 66, 67, - /* 270 */ 68, 69, 70, 71, 72, 73, 74, 75, 200, 77, - /* 280 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 27, - /* 290 */ 24, 44, 94, 95, 96, 97, 98, 99, 24, 217, - /* 300 */ 26, 219, 220, 163, 106, 90, 91, 186, 187, 62, - /* 310 */ 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - /* 320 */ 73, 74, 75, 90, 77, 78, 79, 80, 81, 82, - /* 330 */ 83, 84, 85, 86, 217, 218, 219, 220, 24, 150, - /* 340 */ 200, 150, 19, 81, 82, 24, 110, 165, 166, 167, - /* 350 */ 114, 28, 90, 91, 24, 144, 150, 217, 147, 219, - /* 360 */ 220, 27, 39, 101, 41, 44, 92, 64, 23, 95, - /* 370 */ 96, 97, 27, 10, 51, 109, 170, 111, 112, 188, - /* 380 */ 174, 107, 135, 62, 63, 64, 65, 66, 67, 68, - /* 390 */ 69, 70, 71, 72, 73, 74, 75, 94, 77, 78, - /* 400 */ 79, 80, 81, 82, 83, 84, 85, 86, 24, 227, - /* 410 */ 165, 166, 167, 150, 150, 27, 160, 149, 212, 163, - /* 420 */ 164, 44, 10, 109, 90, 111, 112, 10, 44, 238, - /* 430 */ 224, 201, 202, 170, 170, 90, 91, 174, 174, 109, - /* 440 */ 23, 111, 112, 66, 67, 150, 62, 63, 64, 65, - /* 450 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - /* 460 */ 150, 77, 78, 79, 80, 81, 82, 83, 84, 85, - /* 470 */ 86, 94, 227, 44, 149, 212, 171, 10, 90, 91, - /* 480 */ 170, 168, 169, 188, 174, 221, 12, 224, 71, 10, - /* 490 */ 177, 62, 63, 64, 65, 66, 67, 68, 69, 70, - /* 500 */ 71, 72, 73, 74, 75, 117, 77, 78, 79, 80, - /* 510 */ 81, 82, 83, 84, 85, 86, 45, 10, 44, 150, - /* 520 */ 10, 10, 217, 13, 219, 220, 102, 103, 104, 110, - /* 530 */ 101, 150, 113, 150, 224, 64, 62, 63, 64, 65, - /* 540 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - /* 550 */ 150, 77, 78, 79, 80, 81, 82, 83, 84, 85, - /* 560 */ 86, 10, 192, 44, 183, 24, 183, 26, 10, 199, - /* 570 */ 170, 26, 101, 24, 174, 26, 109, 106, 111, 112, - /* 580 */ 26, 62, 63, 64, 65, 66, 67, 68, 69, 70, - /* 590 */ 71, 72, 73, 74, 75, 226, 77, 78, 79, 80, - /* 600 */ 81, 82, 83, 84, 85, 86, 26, 226, 44, 226, - /* 610 */ 210, 29, 149, 169, 32, 24, 109, 26, 111, 112, - /* 620 */ 109, 177, 111, 112, 10, 43, 62, 63, 64, 65, - /* 630 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - /* 640 */ 91, 77, 78, 79, 80, 81, 82, 83, 84, 85, - /* 650 */ 86, 14, 15, 44, 24, 101, 26, 10, 150, 163, - /* 660 */ 109, 116, 111, 112, 93, 94, 117, 109, 18, 111, - /* 670 */ 112, 91, 63, 64, 65, 66, 67, 68, 69, 70, - /* 680 */ 71, 72, 73, 74, 75, 150, 77, 78, 79, 80, - /* 690 */ 81, 82, 83, 84, 85, 86, 200, 117, 44, 81, - /* 700 */ 82, 145, 146, 150, 23, 170, 23, 151, 27, 174, - /* 710 */ 27, 158, 159, 157, 27, 24, 208, 26, 64, 65, - /* 720 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - /* 730 */ 100, 77, 78, 79, 80, 81, 82, 83, 84, 85, - /* 740 */ 86, 152, 23, 150, 157, 189, 27, 10, 150, 157, - /* 750 */ 157, 216, 156, 23, 153, 157, 109, 27, 111, 112, - /* 760 */ 24, 157, 26, 170, 24, 27, 33, 174, 170, 50, - /* 770 */ 214, 90, 174, 90, 91, 101, 189, 90, 91, 60, - /* 780 */ 50, 189, 189, 64, 134, 52, 136, 189, 162, 115, - /* 790 */ 60, 25, 150, 189, 64, 21, 170, 10, 150, 21, - /* 800 */ 81, 82, 83, 62, 117, 212, 214, 150, 89, 90, - /* 810 */ 91, 81, 82, 94, 166, 167, 161, 224, 214, 89, - /* 820 */ 90, 91, 230, 150, 94, 183, 225, 235, 90, 55, - /* 830 */ 229, 57, 12, 55, 230, 57, 10, 23, 105, 235, - /* 840 */ 183, 27, 24, 113, 26, 101, 127, 128, 129, 130, - /* 850 */ 131, 132, 133, 150, 127, 128, 150, 127, 128, 129, - /* 860 */ 130, 131, 132, 133, 50, 23, 125, 129, 226, 27, - /* 870 */ 150, 150, 47, 170, 60, 227, 170, 174, 64, 150, - /* 880 */ 174, 115, 157, 226, 102, 103, 104, 53, 54, 150, - /* 890 */ 170, 10, 50, 23, 174, 81, 82, 27, 24, 24, - /* 900 */ 26, 26, 60, 89, 90, 91, 64, 26, 94, 170, - /* 910 */ 150, 137, 183, 174, 189, 24, 24, 26, 26, 216, - /* 920 */ 50, 186, 187, 81, 82, 83, 101, 101, 171, 208, - /* 930 */ 60, 89, 90, 91, 64, 24, 94, 26, 24, 34, - /* 940 */ 26, 127, 128, 129, 130, 131, 132, 133, 134, 10, - /* 950 */ 150, 81, 82, 27, 134, 226, 150, 150, 150, 89, - /* 960 */ 90, 91, 10, 150, 94, 24, 171, 26, 208, 127, - /* 970 */ 128, 129, 130, 131, 132, 133, 170, 170, 170, 27, - /* 980 */ 174, 174, 174, 170, 180, 12, 60, 174, 188, 10, - /* 990 */ 17, 18, 19, 20, 150, 150, 42, 127, 128, 129, - /* 1000 */ 130, 131, 132, 133, 31, 124, 113, 81, 82, 10, - /* 1010 */ 37, 172, 150, 150, 170, 150, 90, 157, 174, 126, - /* 1020 */ 94, 150, 49, 150, 51, 46, 27, 150, 150, 56, - /* 1030 */ 150, 58, 170, 170, 61, 170, 174, 174, 150, 174, - /* 1040 */ 150, 170, 90, 91, 113, 174, 150, 170, 170, 189, - /* 1050 */ 150, 174, 174, 127, 128, 129, 46, 126, 213, 150, - /* 1060 */ 170, 188, 150, 124, 174, 150, 170, 100, 188, 171, - /* 1070 */ 174, 150, 173, 10, 150, 102, 103, 104, 171, 170, - /* 1080 */ 150, 108, 150, 174, 150, 150, 113, 150, 188, 90, - /* 1090 */ 91, 170, 150, 150, 170, 174, 59, 23, 174, 150, - /* 1100 */ 188, 213, 170, 188, 170, 170, 174, 170, 174, 174, - /* 1110 */ 150, 174, 170, 170, 113, 150, 174, 174, 188, 170, - /* 1120 */ 150, 150, 150, 174, 115, 189, 115, 150, 150, 191, - /* 1130 */ 170, 124, 119, 193, 174, 170, 150, 150, 150, 174, - /* 1140 */ 170, 170, 170, 150, 174, 174, 174, 170, 170, 157, - /* 1150 */ 150, 174, 174, 150, 190, 150, 170, 170, 170, 121, - /* 1160 */ 174, 174, 174, 170, 150, 150, 150, 174, 194, 122, - /* 1170 */ 170, 150, 196, 170, 174, 170, 139, 174, 115, 174, - /* 1180 */ 195, 189, 123, 115, 170, 170, 170, 197, 174, 174, - /* 1190 */ 174, 170, 198, 150, 115, 174, 150, 86, 94, 150, - /* 1200 */ 113, 113, 113, 23, 134, 222, 18, 223, 23, 187, - /* 1210 */ 24, 150, 115, 26, 24, 150, 154, 26, 120, 99, - /* 1220 */ 172, 27, 162, 211, 172, 120, 26, 203, 211, 117, - /* 1230 */ 150, 150, 150, 101, 150, 204, 118, 154, 205, 23, - /* 1240 */ 150, 24, 115, 204, 24, 205, 171, 23, 175, 150, - /* 1250 */ 178, 150, 176, 211, 162, 211, 179, 179, 172, 24, - /* 1260 */ 228, 46, 228, 172, 179, 170, 170, 150, 23, 163, - /* 1270 */ 24, 23, 46, 180, 171, 173, 182, 23, 171, 98, - /* 1280 */ 150, 106, 182, 175, 150, 176, 150, 154, 25, 154, - /* 1290 */ 150, 154, 154, 101, 12, 231, 40, 38, 232, 101, - /* 1300 */ 233, 137, 101, 234, 47, 150, 154, 101, 150, 23, - /* 1310 */ 171, 10, 12, 137, 185, 18, 10, 10, 125, 150, - /* 1320 */ 125, 18, 62, 105, 150, 194, 185, 10, 125, 71, - /* 1330 */ 215, 23, 71, 150, 23, 10, 194, 116, 10, 150, - /* 1340 */ 10, 10, 10, 10, 116, 194, 10, 185, 105, 10, - /* 1350 */ 194, 10, 125, 10, 150, 150, 154, 23, 215, 10, - /* 1360 */ 10, 10, 10, 150, 24, 10, 10, 25, 10, 150, - /* 1370 */ 35, 163, 163, 10, 10, 150, 154, 10, 21, 150, - /* 1380 */ 236, 150, 237, 236, 10, 138, 10, 239, 139, 240, - /* 1390 */ 140, + /* 0 */ 28, 11, 30, 77, 78, 79, 80, 0, 82, 83, + /* 10 */ 84, 85, 86, 87, 88, 89, 90, 91, 11, 12, + /* 20 */ 11, 49, 81, 82, 83, 84, 85, 86, 87, 88, + /* 30 */ 89, 90, 91, 86, 87, 88, 89, 90, 91, 67, + /* 40 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + /* 50 */ 78, 79, 80, 69, 82, 83, 84, 85, 86, 87, + /* 60 */ 88, 89, 90, 91, 17, 18, 19, 95, 11, 29, + /* 70 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 80 */ 30, 97, 98, 99, 100, 101, 102, 103, 104, 49, + /* 90 */ 150, 151, 50, 53, 26, 111, 156, 155, 30, 147, + /* 100 */ 148, 149, 162, 30, 152, 163, 164, 67, 68, 69, + /* 110 */ 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + /* 120 */ 80, 153, 82, 83, 84, 85, 86, 87, 88, 89, + /* 130 */ 90, 91, 155, 65, 11, 195, 28, 155, 129, 165, + /* 140 */ 163, 164, 168, 169, 170, 95, 96, 97, 106, 155, + /* 150 */ 100, 101, 102, 30, 86, 87, 162, 49, 176, 177, + /* 160 */ 220, 88, 112, 95, 187, 188, 154, 99, 95, 96, + /* 170 */ 176, 177, 28, 21, 30, 67, 68, 69, 70, 71, + /* 180 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 195, + /* 190 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 200 */ 132, 133, 134, 27, 222, 29, 155, 49, 56, 30, + /* 210 */ 149, 160, 218, 152, 163, 164, 11, 12, 95, 96, + /* 220 */ 69, 168, 169, 170, 230, 67, 68, 69, 70, 71, + /* 230 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 95, + /* 240 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 250 */ 99, 100, 101, 102, 103, 104, 65, 192, 193, 107, + /* 260 */ 108, 109, 111, 174, 175, 86, 87, 27, 29, 29, + /* 270 */ 118, 155, 183, 97, 95, 96, 100, 101, 102, 99, + /* 280 */ 49, 171, 172, 173, 30, 106, 95, 27, 112, 29, + /* 290 */ 99, 111, 176, 177, 162, 17, 18, 139, 67, 68, + /* 300 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, + /* 310 */ 79, 80, 15, 82, 83, 84, 85, 86, 87, 88, + /* 320 */ 89, 90, 91, 132, 133, 134, 21, 195, 22, 27, + /* 330 */ 88, 89, 90, 91, 218, 96, 155, 31, 155, 207, + /* 340 */ 208, 21, 155, 233, 212, 155, 230, 49, 11, 95, + /* 350 */ 44, 26, 46, 97, 49, 30, 100, 101, 102, 176, + /* 360 */ 177, 122, 56, 176, 177, 105, 176, 177, 112, 71, + /* 370 */ 72, 140, 67, 68, 69, 70, 71, 72, 73, 74, + /* 380 */ 75, 76, 77, 78, 79, 80, 27, 82, 83, 84, + /* 390 */ 85, 86, 87, 88, 89, 90, 91, 99, 215, 216, + /* 400 */ 171, 172, 173, 27, 49, 218, 216, 86, 87, 168, + /* 410 */ 11, 223, 224, 225, 226, 24, 114, 230, 116, 117, + /* 420 */ 95, 96, 67, 68, 69, 70, 71, 72, 73, 74, + /* 430 */ 75, 76, 77, 78, 79, 80, 139, 82, 83, 84, + /* 440 */ 85, 86, 87, 88, 89, 90, 91, 206, 155, 27, + /* 450 */ 155, 60, 27, 62, 29, 162, 27, 11, 155, 139, + /* 460 */ 30, 141, 233, 30, 223, 22, 225, 226, 154, 176, + /* 470 */ 177, 176, 177, 114, 31, 116, 117, 162, 49, 176, + /* 480 */ 177, 26, 26, 30, 28, 30, 11, 44, 195, 46, + /* 490 */ 114, 16, 116, 117, 24, 140, 67, 68, 69, 70, + /* 500 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + /* 510 */ 195, 82, 83, 84, 85, 86, 87, 88, 89, 90, + /* 520 */ 91, 96, 227, 27, 11, 95, 96, 26, 95, 96, + /* 530 */ 60, 30, 62, 230, 115, 220, 114, 118, 116, 117, + /* 540 */ 154, 11, 32, 50, 162, 49, 36, 122, 95, 96, + /* 550 */ 95, 236, 122, 178, 11, 122, 241, 168, 48, 11, + /* 560 */ 30, 88, 69, 67, 68, 69, 70, 71, 72, 73, + /* 570 */ 74, 75, 76, 77, 78, 79, 80, 195, 82, 83, + /* 580 */ 84, 85, 86, 87, 88, 89, 90, 91, 115, 155, + /* 590 */ 155, 27, 119, 155, 155, 206, 95, 96, 223, 106, + /* 600 */ 225, 226, 220, 11, 111, 207, 208, 172, 173, 11, + /* 610 */ 176, 177, 142, 49, 176, 177, 11, 223, 236, 225, + /* 620 */ 226, 11, 27, 241, 29, 95, 96, 114, 189, 116, + /* 630 */ 117, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 640 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, + /* 650 */ 86, 87, 88, 89, 90, 91, 222, 107, 108, 109, + /* 660 */ 11, 175, 114, 49, 116, 117, 176, 177, 233, 183, + /* 670 */ 29, 232, 107, 108, 109, 26, 11, 155, 26, 15, + /* 680 */ 168, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 690 */ 76, 77, 78, 79, 80, 30, 82, 83, 84, 85, + /* 700 */ 86, 87, 88, 89, 90, 91, 114, 155, 116, 117, + /* 710 */ 183, 184, 114, 49, 116, 117, 194, 190, 206, 114, + /* 720 */ 106, 116, 117, 34, 114, 76, 116, 117, 176, 177, + /* 730 */ 41, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 740 */ 76, 77, 78, 79, 80, 11, 82, 83, 84, 85, + /* 750 */ 86, 87, 88, 89, 90, 91, 155, 11, 155, 155, + /* 760 */ 95, 96, 121, 49, 30, 115, 244, 198, 11, 119, + /* 770 */ 132, 133, 120, 28, 205, 29, 154, 176, 177, 176, + /* 780 */ 177, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 790 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, + /* 800 */ 86, 87, 88, 89, 90, 91, 155, 27, 30, 29, + /* 810 */ 27, 157, 29, 49, 98, 99, 176, 177, 214, 27, + /* 820 */ 27, 29, 29, 27, 162, 29, 27, 176, 177, 95, + /* 830 */ 96, 67, 68, 69, 70, 71, 72, 73, 74, 75, + /* 840 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, + /* 850 */ 86, 87, 88, 89, 90, 91, 155, 195, 155, 167, + /* 860 */ 27, 52, 29, 49, 155, 120, 176, 177, 176, 11, + /* 870 */ 155, 58, 59, 95, 162, 129, 11, 176, 177, 176, + /* 880 */ 177, 25, 68, 69, 70, 71, 72, 73, 74, 75, + /* 890 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, + /* 900 */ 86, 87, 88, 89, 90, 91, 155, 195, 155, 194, + /* 910 */ 155, 29, 134, 49, 158, 106, 176, 177, 11, 27, + /* 920 */ 155, 29, 155, 214, 192, 193, 166, 176, 177, 176, + /* 930 */ 177, 176, 177, 69, 70, 71, 72, 73, 74, 75, + /* 940 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, + /* 950 */ 86, 87, 88, 89, 90, 91, 155, 101, 155, 161, + /* 960 */ 26, 67, 69, 155, 30, 37, 176, 177, 106, 162, + /* 970 */ 155, 26, 38, 155, 27, 30, 29, 176, 177, 176, + /* 980 */ 177, 214, 120, 38, 155, 57, 155, 231, 106, 55, + /* 990 */ 155, 235, 99, 11, 176, 177, 155, 232, 142, 65, + /* 1000 */ 55, 155, 195, 69, 155, 176, 177, 176, 177, 194, + /* 1010 */ 65, 176, 177, 106, 69, 155, 162, 176, 177, 64, + /* 1020 */ 86, 87, 176, 177, 130, 176, 177, 219, 94, 95, + /* 1030 */ 96, 86, 87, 99, 155, 118, 155, 106, 110, 94, + /* 1040 */ 95, 96, 155, 39, 99, 178, 155, 26, 131, 195, + /* 1050 */ 155, 30, 118, 155, 155, 176, 177, 176, 177, 38, + /* 1060 */ 27, 155, 29, 176, 177, 51, 132, 133, 134, 135, + /* 1070 */ 136, 137, 138, 155, 176, 177, 55, 132, 133, 134, + /* 1080 */ 135, 136, 137, 138, 139, 194, 65, 178, 189, 194, + /* 1090 */ 69, 155, 47, 179, 176, 177, 186, 155, 155, 144, + /* 1100 */ 194, 155, 120, 155, 155, 155, 26, 86, 87, 88, + /* 1110 */ 30, 155, 176, 177, 155, 94, 95, 96, 38, 27, + /* 1120 */ 99, 29, 176, 177, 176, 177, 176, 177, 118, 155, + /* 1130 */ 155, 232, 176, 177, 155, 55, 194, 194, 189, 155, + /* 1140 */ 178, 131, 155, 105, 180, 65, 178, 162, 26, 69, + /* 1150 */ 176, 177, 155, 132, 133, 134, 135, 136, 137, 138, + /* 1160 */ 176, 177, 155, 176, 177, 11, 86, 87, 189, 194, + /* 1170 */ 155, 120, 120, 155, 94, 95, 96, 155, 219, 99, + /* 1180 */ 195, 232, 15, 176, 177, 155, 189, 20, 21, 22, + /* 1190 */ 23, 176, 177, 197, 176, 177, 196, 118, 176, 177, + /* 1200 */ 33, 195, 35, 155, 199, 51, 176, 177, 197, 42, + /* 1210 */ 155, 232, 132, 133, 134, 135, 136, 137, 138, 155, + /* 1220 */ 129, 54, 155, 56, 176, 177, 200, 126, 61, 232, + /* 1230 */ 63, 176, 177, 66, 127, 201, 124, 202, 128, 203, + /* 1240 */ 176, 177, 155, 176, 177, 204, 120, 120, 155, 26, + /* 1250 */ 168, 27, 27, 234, 234, 91, 99, 155, 118, 118, + /* 1260 */ 118, 26, 139, 21, 26, 228, 193, 27, 229, 155, + /* 1270 */ 29, 27, 120, 125, 107, 108, 109, 159, 29, 155, + /* 1280 */ 113, 104, 217, 179, 30, 118, 167, 217, 179, 29, + /* 1290 */ 125, 155, 209, 155, 122, 106, 159, 123, 155, 155, + /* 1300 */ 210, 26, 155, 27, 120, 211, 210, 27, 211, 178, + /* 1310 */ 155, 26, 182, 181, 155, 217, 217, 184, 167, 185, + /* 1320 */ 185, 155, 51, 26, 185, 179, 176, 27, 179, 176, + /* 1330 */ 26, 186, 51, 26, 103, 155, 155, 111, 159, 178, + /* 1340 */ 180, 178, 155, 181, 188, 159, 188, 28, 155, 159, + /* 1350 */ 182, 238, 237, 106, 159, 45, 239, 15, 43, 106, + /* 1360 */ 240, 106, 142, 52, 155, 159, 155, 106, 11, 26, + /* 1370 */ 178, 142, 21, 15, 191, 130, 130, 11, 11, 67, + /* 1380 */ 21, 76, 191, 155, 110, 200, 11, 155, 130, 76, + /* 1390 */ 26, 155, 221, 11, 26, 11, 200, 11, 121, 11, + /* 1400 */ 11, 11, 200, 155, 121, 11, 191, 200, 110, 11, + /* 1410 */ 11, 26, 130, 11, 155, 221, 159, 155, 11, 11, + /* 1420 */ 11, 11, 155, 27, 11, 28, 11, 40, 155, 11, + /* 1430 */ 242, 168, 168, 11, 155, 11, 11, 159, 11, 155, + /* 1440 */ 243, 242, 155, 24, 143, 159, 155, 11, 145, 245, + /* 1450 */ 144, 11, 13, 246, 246, 14, }; -#define YY_SHIFT_USE_DFLT (-70) +#define YY_SHIFT_USE_DFLT (-75) static const short yy_shift_ofst[] = { - /* 0 */ 175, 126, -70, -70, 973, 8, 52, -70, 216, 510, - /* 10 */ 160, 132, 363, -70, -70, -70, -70, -70, -70, 510, - /* 20 */ 412, 510, 479, 510, 614, 64, 737, 215, 541, 740, - /* 30 */ 787, 148, -70, 334, -70, 155, -70, 215, 198, -70, - /* 40 */ 744, -70, 905, 323, -70, -70, -70, -70, -70, -70, - /* 50 */ -70, 110, 744, -70, 954, -70, 637, -70, -70, 1010, - /* 60 */ -29, 744, 967, -70, -70, -70, -70, 744, -70, 1074, - /* 70 */ 870, 28, 719, 1009, 1011, -70, 730, -70, 70, 1001, - /* 80 */ -70, 236, -70, 545, 1007, 1038, 1047, 1013, 1059, -70, - /* 90 */ 870, 38, 870, 519, 870, -70, 1068, 215, 1079, 215, - /* 100 */ -70, -70, -70, -70, -70, -70, -70, 654, 870, 609, - /* 110 */ 870, -11, 870, -11, 870, -11, 870, -11, 870, -69, - /* 120 */ 870, -69, 870, -50, 870, -50, 870, -50, 870, -50, - /* 130 */ 870, 143, 870, 143, 870, 1111, 870, 1111, 870, 1111, - /* 140 */ 870, -70, -70, 377, -70, -70, -70, -70, 870, -56, - /* 150 */ 870, -11, -70, 303, -70, 1104, -70, -70, -70, 870, - /* 160 */ 564, 870, -69, -70, 345, 730, 266, 419, 1087, 1088, - /* 170 */ 1089, -70, 519, 870, 654, 870, -70, 870, -70, 870, - /* 180 */ -70, 1180, 1001, 314, -70, 814, 83, 1070, 650, 1188, - /* 190 */ -70, 870, 128, 870, 519, 1185, 196, 1186, -70, 1187, - /* 200 */ 215, 1190, -70, 870, 202, 870, 247, 870, 519, 591, - /* 210 */ -70, 870, -70, -70, 1097, 215, -70, -70, -70, 870, - /* 220 */ 519, 1098, 870, 1191, 870, 1120, -29, -70, 1194, -70, - /* 230 */ -70, 519, 1120, -29, -70, 870, 519, 1105, 870, 1200, - /* 240 */ 870, 519, -70, -70, 580, -70, -70, -70, 388, -70, - /* 250 */ 687, -70, 1112, -70, 683, 1097, 233, -70, -70, 215, - /* 260 */ -70, -70, 1132, 1118, -70, 1216, 215, 691, -70, 215, - /* 270 */ -70, -70, 870, 519, 1001, 330, 549, 1217, 233, 1132, - /* 280 */ 1118, -70, 842, -25, -70, -70, 1127, 50, -70, -70, - /* 290 */ -70, -70, 321, -70, 736, -70, 1220, -70, 384, 744, - /* 300 */ -70, 215, 1224, -70, 135, -70, 215, -70, 424, 733, - /* 310 */ -70, 571, -70, -70, -70, -70, 733, -70, 733, -70, - /* 320 */ 215, 818, -70, 215, 1120, -29, -70, -70, 1120, -29, - /* 330 */ -70, -70, 1194, -70, 954, -70, -70, 926, -70, 3, - /* 340 */ -70, -70, 3, -70, -70, 681, 618, 874, -70, 618, - /* 350 */ 1235, -70, -70, -70, 727, -70, -70, -70, 727, -70, - /* 360 */ -70, -70, -70, -70, 274, -16, -70, 215, -70, 1215, - /* 370 */ 1245, 215, 630, 1246, 744, -70, 1248, 215, 875, 744, - /* 380 */ -70, 870, 429, -70, 1226, 1254, 215, 891, 1181, 215, - /* 390 */ 1224, -70, 471, 1175, -70, -70, -70, -70, -70, 1001, - /* 400 */ 467, 122, 778, 215, 1097, -70, 215, 766, 1263, 1001, - /* 410 */ 507, 215, 1097, 582, 782, 1192, 215, 1097, -70, 1256, - /* 420 */ 820, 1282, 870, 474, 1259, 834, -70, -70, 1198, 1201, - /* 430 */ 825, 215, 554, -70, -70, 1257, -70, -70, 1164, 215, - /* 440 */ 674, 1206, 215, 1286, 215, 892, 826, 1301, 1176, 1300, - /* 450 */ 74, 511, 741, 323, -70, 1193, 1195, 1297, 1306, 1307, - /* 460 */ 74, 1303, 1260, 215, 1218, 215, 881, 215, 1258, 870, - /* 470 */ 519, 1317, 1261, 870, 519, 1203, 215, 1308, 215, 911, - /* 480 */ -70, 893, 551, 1311, 870, 914, 870, 519, 1325, 519, - /* 490 */ 1221, 215, 939, 1328, 774, 215, 1330, 215, 1331, 215, - /* 500 */ 1332, 215, 1333, 558, 1228, 215, 939, 1336, 1260, 215, - /* 510 */ 1243, 215, 881, 1339, 1227, 215, 1308, 931, 647, 1334, - /* 520 */ 870, 941, 1341, 952, 1343, 215, 1097, 417, 262, 1349, - /* 530 */ 1350, 1351, 1352, 215, 1340, 1355, 1335, 334, 1342, 215, - /* 540 */ 979, 1356, 738, 1358, 1363, -70, 1335, 215, 1364, 999, - /* 550 */ 1063, 1367, 1357, 215, 1037, 1247, 215, 1374, 1249, 1250, - /* 560 */ 215, 1376, -70, -70, -70, + /* 0 */ 205, 7, -75, -75, 1167, -10, 57, -75, 47, 475, + /* 10 */ 399, 123, 337, -75, -75, -75, -75, -75, -75, 475, + /* 20 */ 446, 475, 543, 475, 757, 456, 858, 453, 240, 799, + /* 30 */ 865, 50, -75, 254, -75, -16, -75, 453, 151, -75, + /* 40 */ 931, -75, 1004, 306, -75, -75, -75, -75, -75, -75, + /* 50 */ -75, 180, 931, -75, 1045, -75, 278, -75, -75, 1014, + /* 60 */ 689, 931, 1038, -75, -75, -75, -75, 931, -75, 1122, + /* 70 */ 1080, 652, 473, -75, -75, 1080, 1051, 1052, -75, 934, + /* 80 */ -75, 302, 1079, -75, 650, -75, 641, 1091, 1101, 1107, + /* 90 */ 1112, 1110, -75, 1080, 40, 1080, 714, 1080, -75, 1126, + /* 100 */ 453, 1127, 453, -75, -75, -75, -75, -75, -75, 1223, + /* 110 */ 1080, 108, 254, -75, -75, 455, 321, 595, -75, 321, + /* 120 */ 1224, -75, -75, -75, 638, -75, -75, -75, 638, -75, + /* 130 */ -75, -75, -75, 1225, -75, 1080, -75, 814, 1080, -12, + /* 140 */ 1080, -12, 1080, -12, 1080, -12, 1080, -74, 1080, -74, + /* 150 */ 1080, -53, 1080, -53, 1080, -53, 1080, -53, 1080, 242, + /* 160 */ 1080, 242, 1080, 1164, 1080, 1164, 1080, 1164, 1080, -75, + /* 170 */ -75, 298, -75, -75, -75, -75, 1080, -59, 1080, -12, + /* 180 */ -75, 893, -75, 1157, -75, -75, -75, 1080, 764, 1080, + /* 190 */ -74, -75, 325, 934, 359, 419, 1140, 1141, 1142, -75, + /* 200 */ 714, 1080, 864, 1080, -75, 1080, -75, 1080, -75, 1235, + /* 210 */ 1079, 376, -75, 945, 158, 1123, 320, 1242, -75, 1080, + /* 220 */ 231, 1080, 714, 1238, 443, 1240, -75, 1241, 453, 1244, + /* 230 */ -75, 1080, 305, 1080, 355, 1080, 714, 780, -75, 1080, + /* 240 */ -75, -75, 1152, 453, -75, -75, -75, 864, 1080, 714, + /* 250 */ 1148, 1080, 1249, 1080, 1177, 689, -75, 1254, -75, -75, + /* 260 */ 714, 1177, 689, -75, 1080, 714, 1165, 1080, 1260, 1080, + /* 270 */ 714, -75, -75, 239, -75, -75, -75, 430, -75, 433, + /* 280 */ -75, 1172, -75, 501, 1152, 144, 453, -75, -75, 1189, + /* 290 */ 1174, -75, 1275, 453, 783, -75, 453, -75, -75, 1080, + /* 300 */ 714, 1079, 422, 425, 1276, 144, 1189, 1174, -75, 1021, + /* 310 */ -28, -75, -75, 1184, 73, -75, -75, 429, -75, 792, + /* 320 */ -75, 1280, -75, 496, 931, -75, 453, 1285, -75, 42, + /* 330 */ -75, 453, -75, 550, 928, -75, 716, -75, -75, -75, + /* 340 */ -75, 928, -75, 928, -75, 453, 793, -75, 453, 1177, + /* 350 */ 689, -75, -75, 1177, 689, -75, -75, 1254, -75, 1045, + /* 360 */ -75, -75, 68, -75, 1080, 564, -75, 191, -75, -75, + /* 370 */ 191, -75, -75, -75, -75, 176, 256, -75, 453, -75, + /* 380 */ 1271, 1297, 453, 260, 1300, 931, -75, 1304, 453, 796, + /* 390 */ 931, -75, 1080, 614, -75, 1281, 1307, 453, 833, 1231, + /* 400 */ 453, 1285, -75, 493, 1226, -75, -75, -75, -75, -75, + /* 410 */ 1079, 513, 856, 391, 453, 1152, -75, 453, 745, 1319, + /* 420 */ 1079, 548, 453, 1152, 510, 565, 1247, 453, 1152, -75, + /* 430 */ 1310, 297, 1342, 1080, 664, 1315, 813, -75, -75, 1253, + /* 440 */ 1255, 809, 453, 882, -75, -75, 1311, -75, -75, 1220, + /* 450 */ 453, 862, 1261, 453, 1343, 453, 892, 907, 1357, 1229, + /* 460 */ 1358, 152, 592, 894, 306, -75, 1245, 1246, 1351, 1366, + /* 470 */ 1367, 152, 1359, 1312, 453, 1274, 453, 746, 453, 1305, + /* 480 */ 1080, 714, 1375, 1313, 1080, 714, 1258, 453, 1364, 453, + /* 490 */ 947, -75, 917, 598, 1368, 1080, 1033, 1080, 714, 1382, + /* 500 */ 714, 1277, 453, 9, 1384, 470, 453, 1386, 453, 1388, + /* 510 */ 453, 1389, 453, 1390, 605, 1283, 453, 9, 1394, 1312, + /* 520 */ 453, 1298, 453, 746, 1398, 1282, 453, 1364, 1010, 610, + /* 530 */ 1385, 1080, 1092, 1399, 530, 1402, 453, 1152, 649, 179, + /* 540 */ 1407, 1408, 1409, 1410, 453, 1396, 1413, 1387, 254, 1397, + /* 550 */ 453, 1154, 1415, 778, 1418, 1422, -75, 1387, 453, 1424, + /* 560 */ 665, 982, 1425, 734, 982, 1427, 1419, 453, 955, 1301, + /* 570 */ 453, 1436, 1306, 1303, 453, 1440, -75, 1439, 1441, -75, + /* 580 */ -75, }; -#define YY_REDUCE_USE_DFLT (-71) +#define YY_REDUCE_USE_DFLT (-61) static const short yy_reduce_ofst[] = { - /* 0 */ -59, 211, -71, -71, 556, -71, -71, -71, -70, -53, - /* 10 */ -71, 189, -71, -71, -71, -71, -71, -71, -71, 268, - /* 20 */ -71, 325, -71, 463, -71, 589, -71, -60, 596, -71, - /* 30 */ -71, 75, -71, 256, 655, 313, -71, 673, 444, -71, - /* 40 */ 757, -71, -71, 121, -71, -71, -71, -71, -71, -71, - /* 50 */ -71, -71, 795, -71, 804, -71, -71, -71, -71, -71, - /* 60 */ 839, 898, 899, -71, -71, -71, -71, 907, -71, -71, - /* 70 */ 706, -71, 206, -71, -71, -71, 598, -71, 964, 936, - /* 80 */ -71, 938, 370, 940, 974, 985, 976, 990, 994, -71, - /* 90 */ 720, 82, 739, 82, 806, -71, -71, 1043, -71, 1046, - /* 100 */ -71, -71, -71, -71, -71, -71, -71, 82, 807, 82, - /* 110 */ 813, 82, 844, 82, 862, 82, 863, 82, 865, 82, - /* 120 */ 871, 82, 877, 82, 878, 82, 890, 82, 896, 82, - /* 130 */ 909, 82, 921, 82, 924, 82, 932, 82, 934, 82, - /* 140 */ 935, 82, -71, -71, -71, -71, -71, -71, 937, 117, - /* 150 */ 942, 82, -71, -71, -71, -71, -71, -71, -71, 943, - /* 160 */ 82, 949, 82, -71, 1049, 593, 964, -71, -71, -71, - /* 170 */ -71, -71, 82, 960, 82, 965, 82, 970, 82, 971, - /* 180 */ 82, -71, 32, 964, -71, 264, 82, 983, 984, -71, - /* 190 */ -71, 972, 82, 977, 82, -71, 1022, -71, -71, -71, - /* 200 */ 1061, -71, -71, 978, 82, 986, 82, 987, 82, -71, - /* 210 */ -71, 310, -71, -71, 1062, 1065, -71, -71, -71, 988, - /* 220 */ 82, -71, -36, -71, 400, 1012, 1048, -71, 1060, -71, - /* 230 */ -71, 82, 1017, 1052, -71, 993, 82, -71, 263, -71, - /* 240 */ 1000, 82, -71, 230, 1024, -71, -71, -71, 1080, -71, - /* 250 */ 1081, -71, -71, -71, 1082, 1083, 78, -71, -71, 1084, - /* 260 */ -71, -71, 1031, 1033, -71, -71, 508, -71, -71, 1090, - /* 270 */ -71, -71, 1003, 82, -18, 964, 1024, -71, 496, 1039, - /* 280 */ 1040, -71, 1005, 140, -71, -71, -71, 1043, -71, -71, - /* 290 */ -71, -71, 82, -71, -71, -71, -71, -71, 82, 1075, - /* 300 */ -71, 1099, 1073, 1076, 1072, -71, 1101, -71, -71, 1077, - /* 310 */ -71, -71, -71, -71, -71, -71, 1078, -71, 1085, -71, - /* 320 */ 381, -71, -71, 369, 1042, 1086, -71, -71, 1044, 1091, - /* 330 */ -71, -71, 1092, -71, 1093, -71, -71, 626, -71, 1095, - /* 340 */ -71, -71, 1096, -71, -71, 1106, 182, -71, -71, 245, - /* 350 */ -71, -71, -71, -71, 1032, -71, -71, -71, 1034, -71, - /* 360 */ -71, -71, -71, -71, 1094, 1100, -71, 1117, -71, -71, - /* 370 */ -71, 383, 1102, -71, 1103, -71, -71, 642, -71, 1107, - /* 380 */ -71, 1014, 305, -71, -71, -71, 657, -71, -71, 1130, - /* 390 */ 1108, 1109, -49, -71, -71, -71, -71, -71, -71, 587, - /* 400 */ 964, 601, -71, 1134, 1133, -71, 1136, 1135, -71, 725, - /* 410 */ 964, 1140, 1137, 1064, 1066, -71, 295, 1138, -71, 1067, - /* 420 */ 1069, -71, 808, 82, -71, -71, -71, -71, -71, -71, - /* 430 */ -71, 721, -71, -71, -71, -71, -71, -71, -71, 1155, - /* 440 */ 1152, -71, 1158, -71, 729, -71, 1139, -71, -71, -71, - /* 450 */ 592, 964, 1129, 735, -71, -71, -71, -71, -71, -71, - /* 460 */ 604, -71, 1141, 1169, -71, 845, 1131, 1174, -71, 1015, - /* 470 */ 82, -71, -71, 1016, 82, -71, 1183, 1115, 760, -71, - /* 480 */ -71, 860, 964, -71, 535, -71, 1021, 82, -71, 82, - /* 490 */ -71, 1189, 1142, -71, -71, 800, -71, 873, -71, 880, - /* 500 */ -71, 900, -71, 964, -71, 912, 1151, -71, 1162, 915, - /* 510 */ -71, 888, 1156, -71, -71, 930, 1143, 992, 964, -71, - /* 520 */ 703, -71, -71, 1204, -71, 1205, 1202, -71, 648, -71, - /* 530 */ -71, -71, -71, 1213, -71, -71, 1144, 1208, -71, 1219, - /* 540 */ 1145, -71, 1209, -71, -71, -71, 1147, 1225, -71, 1229, - /* 550 */ 1222, -71, -71, 191, -71, -71, 1231, -71, -71, 1148, - /* 560 */ 553, -71, -71, -71, -71, + /* 0 */ -48, 61, -61, -61, -60, -61, -61, -61, -32, 12, + /* 10 */ -61, 181, -61, -61, -61, -61, -61, -61, -61, 314, + /* 20 */ -61, 386, -61, 622, -61, 654, -61, 51, 798, -61, + /* 30 */ -61, -23, -61, -26, 760, 89, -61, 860, 486, -61, + /* 40 */ 867, -61, -61, 65, -61, -61, -61, -61, -61, -61, + /* 50 */ -61, -61, 909, -61, 910, -61, -61, -61, -61, -61, + /* 60 */ 914, 962, 964, -61, -61, -61, -61, 968, -61, -61, + /* 70 */ 438, -61, 996, -61, -61, 116, -61, -61, -61, 293, + /* 80 */ -61, 1000, 1006, -61, 1011, 569, 1005, 1026, 1034, 1035, + /* 90 */ 1036, 1041, -61, 490, 394, 552, 394, 601, -61, -61, + /* 100 */ 1087, -61, 1093, -61, -61, -61, -61, -61, -61, -61, + /* 110 */ 603, 394, 53, -61, -61, 1082, 110, -61, -61, 229, + /* 120 */ -61, -61, -61, -61, 1019, -61, -61, -61, 1020, -61, + /* 130 */ -61, -61, -61, -61, -61, 640, -61, 394, 651, 394, + /* 140 */ 690, 394, 701, 394, 703, 394, 740, 394, 751, 394, + /* 150 */ 753, 394, 755, 394, 790, 394, 801, 394, 803, 394, + /* 160 */ 818, 394, 829, 394, 831, 394, 835, 394, 841, 394, + /* 170 */ -61, -61, -61, -61, -61, -61, 846, 188, 849, 394, + /* 180 */ -61, -61, -61, -61, -61, -61, -61, 879, 394, 881, + /* 190 */ 394, -61, 1102, -6, 1000, -61, -61, -61, -61, -61, + /* 200 */ 394, 887, 394, 898, 394, 918, 394, 936, 394, -61, + /* 210 */ 662, 1000, -61, 295, 394, 1037, 1039, -61, -61, 946, + /* 220 */ 394, 948, 394, -61, 1073, -61, -61, -61, 1114, -61, + /* 230 */ -61, 950, 394, 956, 394, 974, 394, -61, -61, 303, + /* 240 */ -61, -61, 1118, 1124, -61, -61, -61, 394, 984, 394, + /* 250 */ -61, 183, -61, 190, 1065, 1104, -61, 1119, -61, -61, + /* 260 */ 394, 1070, 1109, -61, 987, 394, -61, 187, -61, 1007, + /* 270 */ 394, -61, 398, 1083, -61, -61, -61, 1136, -61, 1138, + /* 280 */ -61, -61, -61, 1143, 1137, 389, 1144, -61, -61, 1090, + /* 290 */ 1094, -61, -61, 604, -61, -61, 1147, -61, -61, 1015, + /* 300 */ 394, 132, 1000, 1083, -61, 512, 1096, 1097, -61, 1018, + /* 310 */ 241, -61, -61, -61, 1087, -61, -61, 394, -61, -61, + /* 320 */ -61, -61, -61, 394, 1131, -61, 1155, 1132, 1130, 1133, + /* 330 */ -61, 1159, -61, -61, 1134, -61, -61, -61, -61, -61, + /* 340 */ -61, 1135, -61, 1139, -61, 439, -61, -61, 765, 1098, + /* 350 */ 1146, -61, -61, 1099, 1149, -61, -61, 1151, -61, 1145, + /* 360 */ -61, -61, 692, -61, 1022, 394, -61, 1150, -61, -61, + /* 370 */ 1153, -61, -61, -61, -61, 1156, 1158, -61, 1166, -61, + /* 380 */ -61, -61, 899, 1160, -61, 1161, -61, -61, 949, -61, + /* 390 */ 1163, -61, 1030, 375, -61, -61, -61, 979, -61, -61, + /* 400 */ 1180, 1162, 1168, 527, -61, -61, -61, -61, -61, -61, + /* 410 */ 712, 1000, 756, -61, 1181, 1179, -61, 1187, 1186, -61, + /* 420 */ 807, 1000, 1193, 1190, 1115, 1113, -61, 715, 1195, -61, + /* 430 */ 1117, 1120, -61, 1048, 394, -61, -61, -61, -61, -61, + /* 440 */ -61, -61, 709, -61, -61, -61, -61, -61, -61, -61, + /* 450 */ 1209, 1206, -61, 1211, -61, 997, -61, 1192, -61, -61, + /* 460 */ -61, 315, 1000, 1183, 732, -61, -61, -61, -61, -61, + /* 470 */ -61, 382, -61, 1191, 1228, -61, 808, 1185, 1232, -61, + /* 480 */ 1055, 394, -61, -61, 1064, 394, -61, 1236, 1171, 767, + /* 490 */ -61, -61, 854, 1000, -61, -18, -61, 1067, 394, -61, + /* 500 */ 394, -61, 1248, 1196, -61, -61, 815, -61, 891, -61, + /* 510 */ 895, -61, 906, -61, 1000, -61, 942, 1202, -61, 1215, + /* 520 */ 943, -61, 959, 1207, -61, -61, 975, 1194, 985, 1000, + /* 530 */ -61, 434, -61, -61, 1259, -61, 1262, 1257, -61, 435, + /* 540 */ -61, -61, -61, -61, 1267, -61, -61, 1188, 1263, -61, + /* 550 */ 1273, 1197, -61, 1264, -61, -61, -61, 1199, 1279, -61, + /* 560 */ 1284, 1278, -61, 1287, 1286, -61, -61, 522, -61, -61, + /* 570 */ 1291, -61, -61, 1204, -58, -61, -61, -61, -61, -61, + /* 580 */ -61, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 571, 571, 566, 569, 870, 870, 870, 570, 577, 870, - /* 10 */ 870, 870, 870, 597, 598, 599, 578, 579, 580, 870, - /* 20 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 30 */ 870, 870, 590, 600, 609, 592, 608, 870, 870, 610, - /* 40 */ 653, 616, 870, 870, 654, 657, 658, 659, 852, 853, - /* 50 */ 854, 870, 653, 617, 638, 636, 870, 639, 640, 870, - /* 60 */ 709, 653, 624, 618, 625, 707, 708, 653, 619, 870, - /* 70 */ 870, 739, 804, 745, 740, 736, 870, 664, 870, 870, - /* 80 */ 665, 673, 675, 682, 721, 712, 714, 702, 716, 670, - /* 90 */ 870, 717, 870, 718, 870, 738, 870, 870, 741, 870, - /* 100 */ 742, 743, 744, 746, 747, 748, 751, 752, 870, 753, - /* 110 */ 870, 754, 870, 755, 870, 756, 870, 757, 870, 758, - /* 120 */ 870, 759, 870, 760, 870, 761, 870, 762, 870, 763, - /* 130 */ 870, 764, 870, 765, 870, 766, 870, 767, 870, 768, - /* 140 */ 870, 769, 770, 870, 771, 778, 785, 788, 870, 773, - /* 150 */ 870, 772, 775, 870, 776, 870, 779, 777, 784, 870, - /* 160 */ 870, 870, 786, 787, 870, 804, 870, 870, 870, 870, - /* 170 */ 870, 791, 803, 870, 780, 870, 781, 870, 782, 870, - /* 180 */ 783, 870, 870, 870, 793, 870, 870, 870, 870, 870, - /* 190 */ 794, 870, 870, 870, 795, 870, 870, 870, 850, 870, - /* 200 */ 870, 870, 851, 870, 870, 870, 870, 870, 796, 870, - /* 210 */ 789, 804, 801, 802, 690, 870, 691, 792, 774, 870, - /* 220 */ 719, 870, 870, 703, 870, 710, 709, 704, 870, 594, - /* 230 */ 711, 706, 710, 709, 705, 870, 715, 870, 804, 713, - /* 240 */ 870, 722, 674, 685, 683, 684, 693, 694, 870, 695, - /* 250 */ 870, 696, 870, 697, 870, 690, 681, 595, 596, 870, - /* 260 */ 679, 680, 699, 701, 686, 870, 870, 870, 700, 870, - /* 270 */ 734, 735, 870, 698, 685, 870, 870, 870, 681, 699, - /* 280 */ 701, 687, 870, 681, 676, 677, 870, 870, 678, 671, - /* 290 */ 672, 790, 870, 737, 870, 749, 870, 750, 870, 653, - /* 300 */ 620, 870, 808, 626, 621, 627, 870, 628, 870, 870, - /* 310 */ 629, 870, 632, 633, 634, 635, 870, 630, 870, 631, - /* 320 */ 870, 870, 809, 870, 710, 709, 810, 812, 710, 709, - /* 330 */ 811, 622, 870, 623, 638, 637, 611, 870, 612, 870, - /* 340 */ 613, 745, 870, 614, 615, 601, 827, 870, 602, 827, - /* 350 */ 870, 603, 606, 607, 870, 822, 824, 825, 870, 823, - /* 360 */ 826, 605, 604, 593, 870, 870, 643, 870, 646, 870, - /* 370 */ 870, 870, 870, 870, 653, 647, 870, 870, 870, 653, - /* 380 */ 648, 870, 653, 649, 870, 870, 870, 870, 870, 870, - /* 390 */ 808, 626, 651, 870, 650, 652, 644, 645, 591, 870, - /* 400 */ 870, 587, 870, 870, 690, 585, 870, 870, 870, 870, - /* 410 */ 870, 870, 690, 833, 870, 870, 870, 690, 692, 838, - /* 420 */ 870, 870, 870, 870, 870, 870, 839, 840, 870, 870, - /* 430 */ 870, 870, 870, 830, 831, 870, 832, 586, 870, 870, - /* 440 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 450 */ 870, 870, 870, 870, 656, 870, 870, 870, 870, 870, - /* 460 */ 870, 870, 655, 870, 870, 870, 870, 870, 870, 870, - /* 470 */ 724, 870, 870, 870, 725, 870, 870, 732, 870, 870, - /* 480 */ 733, 870, 870, 870, 870, 870, 870, 730, 870, 731, - /* 490 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 500 */ 870, 870, 870, 870, 870, 870, 870, 870, 655, 870, - /* 510 */ 870, 870, 870, 870, 870, 870, 732, 870, 870, 870, - /* 520 */ 870, 870, 870, 870, 870, 870, 690, 870, 827, 870, - /* 530 */ 870, 870, 870, 870, 870, 870, 861, 870, 870, 870, - /* 540 */ 870, 870, 870, 870, 870, 860, 861, 870, 870, 870, - /* 550 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 868, - /* 560 */ 870, 870, 869, 572, 567, + /* 0 */ 587, 587, 582, 585, 892, 892, 892, 586, 594, 892, + /* 10 */ 892, 892, 892, 614, 615, 616, 595, 596, 597, 892, + /* 20 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, + /* 30 */ 892, 892, 607, 617, 627, 609, 626, 892, 892, 628, + /* 40 */ 672, 635, 892, 892, 673, 676, 677, 678, 872, 873, + /* 50 */ 874, 892, 672, 636, 657, 655, 892, 658, 659, 892, + /* 60 */ 728, 672, 643, 637, 644, 726, 727, 672, 638, 892, + /* 70 */ 892, 758, 692, 690, 691, 824, 764, 759, 755, 892, + /* 80 */ 683, 892, 892, 684, 692, 694, 701, 740, 731, 733, + /* 90 */ 721, 735, 689, 892, 736, 892, 737, 892, 757, 892, + /* 100 */ 892, 760, 892, 761, 762, 763, 765, 766, 767, 892, + /* 110 */ 892, 892, 892, 612, 613, 619, 847, 892, 620, 847, + /* 120 */ 892, 621, 624, 625, 892, 842, 844, 845, 892, 843, + /* 130 */ 846, 623, 622, 892, 768, 892, 771, 773, 892, 774, + /* 140 */ 892, 775, 892, 776, 892, 777, 892, 778, 892, 779, + /* 150 */ 892, 780, 892, 781, 892, 782, 892, 783, 892, 784, + /* 160 */ 892, 785, 892, 786, 892, 787, 892, 788, 892, 789, + /* 170 */ 790, 892, 791, 798, 805, 808, 892, 793, 892, 792, + /* 180 */ 795, 892, 796, 892, 799, 797, 804, 892, 892, 892, + /* 190 */ 806, 807, 892, 824, 892, 892, 892, 892, 892, 811, + /* 200 */ 823, 892, 800, 892, 801, 892, 802, 892, 803, 892, + /* 210 */ 892, 892, 813, 892, 892, 892, 892, 892, 814, 892, + /* 220 */ 892, 892, 815, 892, 892, 892, 870, 892, 892, 892, + /* 230 */ 871, 892, 892, 892, 892, 892, 816, 892, 809, 824, + /* 240 */ 821, 822, 709, 892, 710, 812, 794, 772, 892, 738, + /* 250 */ 892, 892, 722, 892, 729, 728, 723, 892, 611, 730, + /* 260 */ 725, 729, 728, 724, 892, 734, 892, 824, 732, 892, + /* 270 */ 741, 693, 704, 702, 703, 712, 713, 892, 714, 892, + /* 280 */ 715, 892, 716, 892, 709, 700, 892, 698, 699, 718, + /* 290 */ 720, 705, 892, 892, 892, 719, 892, 753, 754, 892, + /* 300 */ 717, 704, 892, 892, 892, 700, 718, 720, 706, 892, + /* 310 */ 700, 695, 696, 892, 892, 697, 810, 892, 756, 892, + /* 320 */ 769, 892, 770, 892, 672, 639, 892, 828, 645, 640, + /* 330 */ 646, 892, 647, 892, 892, 648, 892, 651, 652, 653, + /* 340 */ 654, 892, 649, 892, 650, 892, 892, 829, 892, 729, + /* 350 */ 728, 830, 832, 729, 728, 831, 641, 892, 642, 657, + /* 360 */ 656, 629, 892, 630, 892, 892, 631, 892, 632, 764, + /* 370 */ 892, 633, 634, 618, 610, 892, 892, 662, 892, 665, + /* 380 */ 892, 892, 892, 892, 892, 672, 666, 892, 892, 892, + /* 390 */ 672, 667, 892, 672, 668, 892, 892, 892, 892, 892, + /* 400 */ 892, 828, 645, 670, 892, 669, 671, 663, 664, 608, + /* 410 */ 892, 892, 604, 892, 892, 709, 602, 892, 892, 892, + /* 420 */ 892, 892, 892, 709, 853, 892, 892, 892, 709, 711, + /* 430 */ 858, 892, 892, 892, 892, 892, 892, 859, 860, 892, + /* 440 */ 892, 892, 892, 892, 850, 851, 892, 852, 603, 892, + /* 450 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, + /* 460 */ 892, 892, 892, 892, 892, 675, 892, 892, 892, 892, + /* 470 */ 892, 892, 892, 674, 892, 892, 892, 892, 892, 892, + /* 480 */ 892, 743, 892, 892, 892, 744, 892, 892, 751, 892, + /* 490 */ 892, 752, 892, 892, 892, 892, 892, 892, 749, 892, + /* 500 */ 750, 892, 892, 892, 892, 892, 892, 892, 892, 892, + /* 510 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 674, + /* 520 */ 892, 892, 892, 892, 892, 892, 892, 751, 892, 892, + /* 530 */ 892, 892, 892, 892, 892, 892, 892, 709, 892, 847, + /* 540 */ 892, 892, 892, 892, 892, 892, 892, 881, 892, 892, + /* 550 */ 892, 892, 892, 892, 892, 892, 880, 881, 892, 892, + /* 560 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, + /* 570 */ 892, 892, 892, 890, 892, 892, 891, 588, 892, 589, + /* 580 */ 583, }; #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) @@ -660,59 +678,64 @@ 0, /* FUNCTION => nothing */ 0, /* COLUMN => nothing */ 0, /* AGG_FUNCTION => nothing */ + 0, /* AGG_COLUMN => nothing */ 0, /* CONST_FUNC => nothing */ 0, /* SEMI => nothing */ - 27, /* EXPLAIN => ID */ - 27, /* BEGIN => ID */ + 30, /* EXPLAIN => ID */ + 30, /* QUERY => ID */ + 30, /* PLAN => ID */ + 30, /* BEGIN => ID */ 0, /* TRANSACTION => nothing */ - 27, /* DEFERRED => ID */ - 27, /* IMMEDIATE => ID */ - 27, /* EXCLUSIVE => ID */ + 30, /* DEFERRED => ID */ + 30, /* IMMEDIATE => ID */ + 30, /* EXCLUSIVE => ID */ 0, /* COMMIT => nothing */ - 27, /* END => ID */ + 30, /* END => ID */ 0, /* ROLLBACK => nothing */ 0, /* CREATE => nothing */ 0, /* TABLE => nothing */ - 27, /* TEMP => ID */ + 30, /* TEMP => ID */ 0, /* LP => nothing */ 0, /* RP => nothing */ 0, /* AS => nothing */ 0, /* COMMA => nothing */ 0, /* ID => nothing */ - 27, /* ABORT => ID */ - 27, /* AFTER => ID */ - 27, /* ASC => ID */ - 27, /* ATTACH => ID */ - 27, /* BEFORE => ID */ - 27, /* CASCADE => ID */ - 27, /* CONFLICT => ID */ - 27, /* DATABASE => ID */ - 27, /* DESC => ID */ - 27, /* DETACH => ID */ - 27, /* EACH => ID */ - 27, /* FAIL => ID */ - 27, /* FOR => ID */ - 27, /* IGNORE => ID */ - 27, /* INITIALLY => ID */ - 27, /* INSTEAD => ID */ - 27, /* LIKE_KW => ID */ - 27, /* MATCH => ID */ - 27, /* KEY => ID */ - 27, /* OF => ID */ - 27, /* OFFSET => ID */ - 27, /* PRAGMA => ID */ - 27, /* RAISE => ID */ - 27, /* REPLACE => ID */ - 27, /* RESTRICT => ID */ - 27, /* ROW => ID */ - 27, /* STATEMENT => ID */ - 27, /* TRIGGER => ID */ - 27, /* VACUUM => ID */ - 27, /* VIEW => ID */ - 27, /* REINDEX => ID */ - 27, /* RENAME => ID */ - 27, /* CTIME_KW => ID */ - 27, /* ALTER => ID */ + 30, /* ABORT => ID */ + 30, /* AFTER => ID */ + 30, /* ANALYZE => ID */ + 30, /* ASC => ID */ + 30, /* ATTACH => ID */ + 30, /* BEFORE => ID */ + 30, /* CASCADE => ID */ + 30, /* CAST => ID */ + 30, /* CONFLICT => ID */ + 30, /* DATABASE => ID */ + 30, /* DESC => ID */ + 30, /* DETACH => ID */ + 30, /* EACH => ID */ + 30, /* FAIL => ID */ + 30, /* FOR => ID */ + 30, /* IGNORE => ID */ + 30, /* INITIALLY => ID */ + 30, /* INSTEAD => ID */ + 30, /* LIKE_KW => ID */ + 30, /* MATCH => ID */ + 30, /* KEY => ID */ + 30, /* OF => ID */ + 30, /* OFFSET => ID */ + 30, /* PRAGMA => ID */ + 30, /* RAISE => ID */ + 30, /* REPLACE => ID */ + 30, /* RESTRICT => ID */ + 30, /* ROW => ID */ + 30, /* STATEMENT => ID */ + 30, /* TRIGGER => ID */ + 30, /* VACUUM => ID */ + 30, /* VIEW => ID */ + 30, /* REINDEX => ID */ + 30, /* RENAME => ID */ + 30, /* CTIME_KW => ID */ + 30, /* ALTER => ID */ 0, /* OR => nothing */ 0, /* AND => nothing */ 0, /* NOT => nothing */ @@ -864,64 +887,66 @@ static const char *const yyTokenName[] = { "$", "END_OF_FILE", "ILLEGAL", "SPACE", "UNCLOSED_STRING", "COMMENT", "FUNCTION", "COLUMN", - "AGG_FUNCTION", "CONST_FUNC", "SEMI", "EXPLAIN", - "BEGIN", "TRANSACTION", "DEFERRED", "IMMEDIATE", - "EXCLUSIVE", "COMMIT", "END", "ROLLBACK", - "CREATE", "TABLE", "TEMP", "LP", - "RP", "AS", "COMMA", "ID", - "ABORT", "AFTER", "ASC", "ATTACH", - "BEFORE", "CASCADE", "CONFLICT", "DATABASE", - "DESC", "DETACH", "EACH", "FAIL", - "FOR", "IGNORE", "INITIALLY", "INSTEAD", - "LIKE_KW", "MATCH", "KEY", "OF", - "OFFSET", "PRAGMA", "RAISE", "REPLACE", - "RESTRICT", "ROW", "STATEMENT", "TRIGGER", - "VACUUM", "VIEW", "REINDEX", "RENAME", - "CTIME_KW", "ALTER", "OR", "AND", - "NOT", "IS", "BETWEEN", "IN", - "ISNULL", "NOTNULL", "NE", "EQ", - "GT", "LE", "LT", "GE", - "ESCAPE", "BITAND", "BITOR", "LSHIFT", - "RSHIFT", "PLUS", "MINUS", "STAR", - "SLASH", "REM", "CONCAT", "UMINUS", - "UPLUS", "BITNOT", "STRING", "JOIN_KW", - "CONSTRAINT", "DEFAULT", "NULL", "PRIMARY", - "UNIQUE", "CHECK", "REFERENCES", "COLLATE", - "AUTOINCR", "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", "INTEGER", - "FLOAT", "BLOB", "REGISTER", "VARIABLE", - "EXISTS", "CASE", "WHEN", "THEN", - "ELSE", "INDEX", "TO", "ADD", - "COLUMNKW", "error", "input", "cmdlist", - "ecmd", "cmdx", "cmd", "explain", - "transtype", "trans_opt", "nm", "create_table", - "create_table_args", "temp", "dbnm", "columnlist", - "conslist_opt", "select", "column", "columnid", - "type", "carglist", "id", "ids", - "typename", "signed", "plus_num", "minus_num", - "carg", "ccons", "term", "onconf", - "sortorder", "autoinc", "expr", "idxlist_opt", - "refargs", "defer_subclause", "refarg", "refact", - "init_deferred_pred_opt", "conslist", "tcons", "idxlist", - "defer_subclause_opt", "orconf", "resolvetype", "raisetype", - "fullname", "oneselect", "multiselect_op", "distinct", - "selcollist", "from", "where_opt", "groupby_opt", - "having_opt", "orderby_opt", "limit_opt", "sclp", - "as", "seltablist", "stl_prefix", "joinop", - "on_opt", "using_opt", "seltablist_paren", "joinop2", - "inscollist", "sortlist", "sortitem", "collate", - "exprlist", "setlist", "insert_cmd", "inscollist_opt", - "itemlist", "likeop", "escape", "between_op", - "in_op", "case_operand", "case_exprlist", "case_else", - "expritem", "uniqueflag", "idxitem", "plus_opt", - "number", "trigger_decl", "trigger_cmd_list", "trigger_time", - "trigger_event", "foreach_clause", "when_clause", "trigger_cmd", - "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt", + "AGG_FUNCTION", "AGG_COLUMN", "CONST_FUNC", "SEMI", + "EXPLAIN", "QUERY", "PLAN", "BEGIN", + "TRANSACTION", "DEFERRED", "IMMEDIATE", "EXCLUSIVE", + "COMMIT", "END", "ROLLBACK", "CREATE", + "TABLE", "TEMP", "LP", "RP", + "AS", "COMMA", "ID", "ABORT", + "AFTER", "ANALYZE", "ASC", "ATTACH", + "BEFORE", "CASCADE", "CAST", "CONFLICT", + "DATABASE", "DESC", "DETACH", "EACH", + "FAIL", "FOR", "IGNORE", "INITIALLY", + "INSTEAD", "LIKE_KW", "MATCH", "KEY", + "OF", "OFFSET", "PRAGMA", "RAISE", + "REPLACE", "RESTRICT", "ROW", "STATEMENT", + "TRIGGER", "VACUUM", "VIEW", "REINDEX", + "RENAME", "CTIME_KW", "ALTER", "OR", + "AND", "NOT", "IS", "BETWEEN", + "IN", "ISNULL", "NOTNULL", "NE", + "EQ", "GT", "LE", "LT", + "GE", "ESCAPE", "BITAND", "BITOR", + "LSHIFT", "RSHIFT", "PLUS", "MINUS", + "STAR", "SLASH", "REM", "CONCAT", + "UMINUS", "UPLUS", "BITNOT", "STRING", + "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL", + "PRIMARY", "UNIQUE", "CHECK", "REFERENCES", + "COLLATE", "AUTOINCR", "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", + "INTEGER", "FLOAT", "BLOB", "REGISTER", + "VARIABLE", "EXISTS", "CASE", "WHEN", + "THEN", "ELSE", "INDEX", "TO", + "ADD", "COLUMNKW", "error", "input", + "cmdlist", "ecmd", "cmdx", "cmd", + "explain", "transtype", "trans_opt", "nm", + "create_table", "create_table_args", "temp", "dbnm", + "columnlist", "conslist_opt", "select", "column", + "columnid", "type", "carglist", "id", + "ids", "typetoken", "typename", "signed", + "plus_num", "minus_num", "carg", "ccons", + "term", "expr", "onconf", "sortorder", + "autoinc", "idxlist_opt", "refargs", "defer_subclause", + "refarg", "refact", "init_deferred_pred_opt", "conslist", + "tcons", "idxlist", "defer_subclause_opt", "orconf", + "resolvetype", "raisetype", "fullname", "oneselect", + "multiselect_op", "distinct", "selcollist", "from", + "where_opt", "groupby_opt", "having_opt", "orderby_opt", + "limit_opt", "sclp", "as", "seltablist", + "stl_prefix", "joinop", "on_opt", "using_opt", + "seltablist_paren", "joinop2", "inscollist", "sortlist", + "sortitem", "collate", "exprlist", "setlist", + "insert_cmd", "inscollist_opt", "itemlist", "likeop", + "escape", "between_op", "in_op", "case_operand", + "case_exprlist", "case_else", "expritem", "uniqueflag", + "idxitem", "plus_opt", "number", "trigger_decl", + "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause", + "when_clause", "trigger_cmd", "database_kw_opt", "key_opt", + "add_column_fullname", "kwcolumn_opt", }; #endif /* NDEBUG */ @@ -937,303 +962,309 @@ /* 5 */ "ecmd ::= explain cmdx SEMI", /* 6 */ "explain ::=", /* 7 */ "explain ::= EXPLAIN", - /* 8 */ "cmd ::= BEGIN transtype trans_opt", - /* 9 */ "trans_opt ::=", - /* 10 */ "trans_opt ::= TRANSACTION", - /* 11 */ "trans_opt ::= TRANSACTION nm", - /* 12 */ "transtype ::=", - /* 13 */ "transtype ::= DEFERRED", - /* 14 */ "transtype ::= IMMEDIATE", - /* 15 */ "transtype ::= EXCLUSIVE", - /* 16 */ "cmd ::= COMMIT trans_opt", - /* 17 */ "cmd ::= END trans_opt", - /* 18 */ "cmd ::= ROLLBACK trans_opt", - /* 19 */ "cmd ::= create_table create_table_args", - /* 20 */ "create_table ::= CREATE temp TABLE nm dbnm", - /* 21 */ "temp ::= TEMP", - /* 22 */ "temp ::=", - /* 23 */ "create_table_args ::= LP columnlist conslist_opt RP", - /* 24 */ "create_table_args ::= AS select", - /* 25 */ "columnlist ::= columnlist COMMA column", - /* 26 */ "columnlist ::= column", - /* 27 */ "column ::= columnid type carglist", - /* 28 */ "columnid ::= nm", - /* 29 */ "id ::= ID", - /* 30 */ "ids ::= ID", - /* 31 */ "ids ::= STRING", - /* 32 */ "nm ::= ID", - /* 33 */ "nm ::= STRING", - /* 34 */ "nm ::= JOIN_KW", - /* 35 */ "type ::=", - /* 36 */ "type ::= typename", - /* 37 */ "type ::= typename LP signed RP", - /* 38 */ "type ::= typename LP signed COMMA signed RP", - /* 39 */ "typename ::= ids", - /* 40 */ "typename ::= typename ids", - /* 41 */ "signed ::= plus_num", - /* 42 */ "signed ::= minus_num", - /* 43 */ "carglist ::= carglist carg", - /* 44 */ "carglist ::=", - /* 45 */ "carg ::= CONSTRAINT nm ccons", - /* 46 */ "carg ::= ccons", - /* 47 */ "carg ::= DEFAULT term", - /* 48 */ "carg ::= DEFAULT PLUS term", - /* 49 */ "carg ::= DEFAULT MINUS term", - /* 50 */ "carg ::= DEFAULT id", - /* 51 */ "ccons ::= NULL onconf", - /* 52 */ "ccons ::= NOT NULL onconf", - /* 53 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", - /* 54 */ "ccons ::= UNIQUE onconf", - /* 55 */ "ccons ::= CHECK LP expr RP onconf", - /* 56 */ "ccons ::= REFERENCES nm idxlist_opt refargs", - /* 57 */ "ccons ::= defer_subclause", - /* 58 */ "ccons ::= COLLATE id", - /* 59 */ "autoinc ::=", - /* 60 */ "autoinc ::= AUTOINCR", - /* 61 */ "refargs ::=", - /* 62 */ "refargs ::= refargs refarg", - /* 63 */ "refarg ::= MATCH nm", - /* 64 */ "refarg ::= ON DELETE refact", - /* 65 */ "refarg ::= ON UPDATE refact", - /* 66 */ "refarg ::= ON INSERT refact", - /* 67 */ "refact ::= SET NULL", - /* 68 */ "refact ::= SET DEFAULT", - /* 69 */ "refact ::= CASCADE", - /* 70 */ "refact ::= RESTRICT", - /* 71 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", - /* 72 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", - /* 73 */ "init_deferred_pred_opt ::=", - /* 74 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", - /* 75 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", - /* 76 */ "conslist_opt ::=", - /* 77 */ "conslist_opt ::= COMMA conslist", - /* 78 */ "conslist ::= conslist COMMA tcons", - /* 79 */ "conslist ::= conslist tcons", - /* 80 */ "conslist ::= tcons", - /* 81 */ "tcons ::= CONSTRAINT nm", - /* 82 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", - /* 83 */ "tcons ::= UNIQUE LP idxlist RP onconf", - /* 84 */ "tcons ::= CHECK expr onconf", - /* 85 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", - /* 86 */ "defer_subclause_opt ::=", - /* 87 */ "defer_subclause_opt ::= defer_subclause", - /* 88 */ "onconf ::=", - /* 89 */ "onconf ::= ON CONFLICT resolvetype", - /* 90 */ "orconf ::=", - /* 91 */ "orconf ::= OR resolvetype", - /* 92 */ "resolvetype ::= raisetype", - /* 93 */ "resolvetype ::= IGNORE", - /* 94 */ "resolvetype ::= REPLACE", - /* 95 */ "cmd ::= DROP TABLE fullname", - /* 96 */ "cmd ::= CREATE temp VIEW nm dbnm AS select", - /* 97 */ "cmd ::= DROP VIEW fullname", - /* 98 */ "cmd ::= select", - /* 99 */ "select ::= oneselect", - /* 100 */ "select ::= select multiselect_op oneselect", - /* 101 */ "multiselect_op ::= UNION", - /* 102 */ "multiselect_op ::= UNION ALL", - /* 103 */ "multiselect_op ::= INTERSECT", - /* 104 */ "multiselect_op ::= EXCEPT", - /* 105 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", - /* 106 */ "distinct ::= DISTINCT", - /* 107 */ "distinct ::= ALL", - /* 108 */ "distinct ::=", - /* 109 */ "sclp ::= selcollist COMMA", - /* 110 */ "sclp ::=", - /* 111 */ "selcollist ::= sclp expr as", - /* 112 */ "selcollist ::= sclp STAR", - /* 113 */ "selcollist ::= sclp nm DOT STAR", - /* 114 */ "as ::= AS nm", - /* 115 */ "as ::= ids", - /* 116 */ "as ::=", - /* 117 */ "from ::=", - /* 118 */ "from ::= FROM seltablist", - /* 119 */ "stl_prefix ::= seltablist joinop", - /* 120 */ "stl_prefix ::=", - /* 121 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt", - /* 122 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt", - /* 123 */ "seltablist_paren ::= select", - /* 124 */ "seltablist_paren ::= seltablist", - /* 125 */ "dbnm ::=", - /* 126 */ "dbnm ::= DOT nm", - /* 127 */ "fullname ::= nm dbnm", - /* 128 */ "joinop ::= COMMA", - /* 129 */ "joinop ::= JOIN", - /* 130 */ "joinop ::= JOIN_KW JOIN", - /* 131 */ "joinop ::= JOIN_KW nm JOIN", - /* 132 */ "joinop ::= JOIN_KW nm nm JOIN", - /* 133 */ "on_opt ::= ON expr", - /* 134 */ "on_opt ::=", - /* 135 */ "using_opt ::= USING LP inscollist RP", - /* 136 */ "using_opt ::=", - /* 137 */ "orderby_opt ::=", - /* 138 */ "orderby_opt ::= ORDER BY sortlist", - /* 139 */ "sortlist ::= sortlist COMMA sortitem collate sortorder", - /* 140 */ "sortlist ::= sortitem collate sortorder", - /* 141 */ "sortitem ::= expr", - /* 142 */ "sortorder ::= ASC", - /* 143 */ "sortorder ::= DESC", - /* 144 */ "sortorder ::=", - /* 145 */ "collate ::=", - /* 146 */ "collate ::= COLLATE id", - /* 147 */ "groupby_opt ::=", - /* 148 */ "groupby_opt ::= GROUP BY exprlist", - /* 149 */ "having_opt ::=", - /* 150 */ "having_opt ::= HAVING expr", - /* 151 */ "limit_opt ::=", - /* 152 */ "limit_opt ::= LIMIT expr", - /* 153 */ "limit_opt ::= LIMIT expr OFFSET expr", - /* 154 */ "limit_opt ::= LIMIT expr COMMA expr", - /* 155 */ "cmd ::= DELETE FROM fullname where_opt", - /* 156 */ "where_opt ::=", - /* 157 */ "where_opt ::= WHERE expr", - /* 158 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt", - /* 159 */ "setlist ::= setlist COMMA nm EQ expr", - /* 160 */ "setlist ::= nm EQ expr", - /* 161 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP", - /* 162 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", - /* 163 */ "insert_cmd ::= INSERT orconf", - /* 164 */ "insert_cmd ::= REPLACE", - /* 165 */ "itemlist ::= itemlist COMMA expr", - /* 166 */ "itemlist ::= expr", - /* 167 */ "inscollist_opt ::=", - /* 168 */ "inscollist_opt ::= LP inscollist RP", - /* 169 */ "inscollist ::= inscollist COMMA nm", - /* 170 */ "inscollist ::= nm", - /* 171 */ "expr ::= term", - /* 172 */ "expr ::= LP expr RP", - /* 173 */ "term ::= NULL", - /* 174 */ "expr ::= ID", - /* 175 */ "expr ::= JOIN_KW", - /* 176 */ "expr ::= nm DOT nm", - /* 177 */ "expr ::= nm DOT nm DOT nm", - /* 178 */ "term ::= INTEGER", - /* 179 */ "term ::= FLOAT", - /* 180 */ "term ::= STRING", - /* 181 */ "term ::= BLOB", - /* 182 */ "expr ::= REGISTER", - /* 183 */ "expr ::= VARIABLE", - /* 184 */ "expr ::= ID LP exprlist RP", - /* 185 */ "expr ::= ID LP STAR RP", - /* 186 */ "term ::= CTIME_KW", - /* 187 */ "expr ::= expr AND expr", - /* 188 */ "expr ::= expr OR expr", - /* 189 */ "expr ::= expr LT expr", - /* 190 */ "expr ::= expr GT expr", - /* 191 */ "expr ::= expr LE expr", - /* 192 */ "expr ::= expr GE expr", - /* 193 */ "expr ::= expr NE expr", - /* 194 */ "expr ::= expr EQ expr", - /* 195 */ "expr ::= expr BITAND expr", - /* 196 */ "expr ::= expr BITOR expr", - /* 197 */ "expr ::= expr LSHIFT expr", - /* 198 */ "expr ::= expr RSHIFT expr", - /* 199 */ "expr ::= expr PLUS expr", - /* 200 */ "expr ::= expr MINUS expr", - /* 201 */ "expr ::= expr STAR expr", - /* 202 */ "expr ::= expr SLASH expr", - /* 203 */ "expr ::= expr REM expr", - /* 204 */ "expr ::= expr CONCAT expr", - /* 205 */ "likeop ::= LIKE_KW", - /* 206 */ "likeop ::= NOT LIKE_KW", - /* 207 */ "escape ::= ESCAPE expr", - /* 208 */ "escape ::=", - /* 209 */ "expr ::= expr likeop expr escape", - /* 210 */ "expr ::= expr ISNULL", - /* 211 */ "expr ::= expr IS NULL", - /* 212 */ "expr ::= expr NOTNULL", - /* 213 */ "expr ::= expr NOT NULL", - /* 214 */ "expr ::= expr IS NOT NULL", - /* 215 */ "expr ::= NOT expr", - /* 216 */ "expr ::= BITNOT expr", - /* 217 */ "expr ::= MINUS expr", - /* 218 */ "expr ::= PLUS expr", - /* 219 */ "between_op ::= BETWEEN", - /* 220 */ "between_op ::= NOT BETWEEN", - /* 221 */ "expr ::= expr between_op expr AND expr", - /* 222 */ "in_op ::= IN", - /* 223 */ "in_op ::= NOT IN", - /* 224 */ "expr ::= expr in_op LP exprlist RP", - /* 225 */ "expr ::= LP select RP", - /* 226 */ "expr ::= expr in_op LP select RP", - /* 227 */ "expr ::= expr in_op nm dbnm", - /* 228 */ "expr ::= EXISTS LP select RP", - /* 229 */ "expr ::= CASE case_operand case_exprlist case_else END", - /* 230 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", - /* 231 */ "case_exprlist ::= WHEN expr THEN expr", - /* 232 */ "case_else ::= ELSE expr", - /* 233 */ "case_else ::=", - /* 234 */ "case_operand ::= expr", - /* 235 */ "case_operand ::=", - /* 236 */ "exprlist ::= exprlist COMMA expritem", - /* 237 */ "exprlist ::= expritem", - /* 238 */ "expritem ::= expr", - /* 239 */ "expritem ::=", - /* 240 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf", - /* 241 */ "uniqueflag ::= UNIQUE", - /* 242 */ "uniqueflag ::=", - /* 243 */ "idxlist_opt ::=", - /* 244 */ "idxlist_opt ::= LP idxlist RP", - /* 245 */ "idxlist ::= idxlist COMMA idxitem collate sortorder", - /* 246 */ "idxlist ::= idxitem collate sortorder", - /* 247 */ "idxitem ::= nm", - /* 248 */ "cmd ::= DROP INDEX fullname", - /* 249 */ "cmd ::= VACUUM", - /* 250 */ "cmd ::= VACUUM nm", - /* 251 */ "cmd ::= PRAGMA nm dbnm EQ nm", - /* 252 */ "cmd ::= PRAGMA nm dbnm EQ ON", - /* 253 */ "cmd ::= PRAGMA nm dbnm EQ plus_num", - /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", - /* 255 */ "cmd ::= PRAGMA nm dbnm LP nm RP", - /* 256 */ "cmd ::= PRAGMA nm dbnm", - /* 257 */ "plus_num ::= plus_opt number", - /* 258 */ "minus_num ::= MINUS number", - /* 259 */ "number ::= INTEGER", - /* 260 */ "number ::= FLOAT", - /* 261 */ "plus_opt ::= PLUS", - /* 262 */ "plus_opt ::=", - /* 263 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", - /* 264 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", - /* 265 */ "trigger_time ::= BEFORE", - /* 266 */ "trigger_time ::= AFTER", - /* 267 */ "trigger_time ::= INSTEAD OF", - /* 268 */ "trigger_time ::=", - /* 269 */ "trigger_event ::= DELETE", - /* 270 */ "trigger_event ::= INSERT", - /* 271 */ "trigger_event ::= UPDATE", - /* 272 */ "trigger_event ::= UPDATE OF inscollist", - /* 273 */ "foreach_clause ::=", - /* 274 */ "foreach_clause ::= FOR EACH ROW", - /* 275 */ "foreach_clause ::= FOR EACH STATEMENT", - /* 276 */ "when_clause ::=", - /* 277 */ "when_clause ::= WHEN expr", - /* 278 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list", - /* 279 */ "trigger_cmd_list ::=", - /* 280 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", - /* 281 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", - /* 282 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", - /* 283 */ "trigger_cmd ::= DELETE FROM nm where_opt", - /* 284 */ "trigger_cmd ::= select", - /* 285 */ "expr ::= RAISE LP IGNORE RP", - /* 286 */ "expr ::= RAISE LP raisetype COMMA nm RP", - /* 287 */ "raisetype ::= ROLLBACK", - /* 288 */ "raisetype ::= ABORT", - /* 289 */ "raisetype ::= FAIL", - /* 290 */ "cmd ::= DROP TRIGGER fullname", - /* 291 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt", - /* 292 */ "key_opt ::=", - /* 293 */ "key_opt ::= KEY ids", - /* 294 */ "key_opt ::= KEY BLOB", - /* 295 */ "database_kw_opt ::= DATABASE", - /* 296 */ "database_kw_opt ::=", - /* 297 */ "cmd ::= DETACH database_kw_opt nm", - /* 298 */ "cmd ::= REINDEX", - /* 299 */ "cmd ::= REINDEX nm dbnm", - /* 300 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", - /* 301 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", - /* 302 */ "add_column_fullname ::= fullname", - /* 303 */ "kwcolumn_opt ::=", - /* 304 */ "kwcolumn_opt ::= COLUMNKW", + /* 8 */ "explain ::= EXPLAIN QUERY PLAN", + /* 9 */ "cmd ::= BEGIN transtype trans_opt", + /* 10 */ "trans_opt ::=", + /* 11 */ "trans_opt ::= TRANSACTION", + /* 12 */ "trans_opt ::= TRANSACTION nm", + /* 13 */ "transtype ::=", + /* 14 */ "transtype ::= DEFERRED", + /* 15 */ "transtype ::= IMMEDIATE", + /* 16 */ "transtype ::= EXCLUSIVE", + /* 17 */ "cmd ::= COMMIT trans_opt", + /* 18 */ "cmd ::= END trans_opt", + /* 19 */ "cmd ::= ROLLBACK trans_opt", + /* 20 */ "cmd ::= create_table create_table_args", + /* 21 */ "create_table ::= CREATE temp TABLE nm dbnm", + /* 22 */ "temp ::= TEMP", + /* 23 */ "temp ::=", + /* 24 */ "create_table_args ::= LP columnlist conslist_opt RP", + /* 25 */ "create_table_args ::= AS select", + /* 26 */ "columnlist ::= columnlist COMMA column", + /* 27 */ "columnlist ::= column", + /* 28 */ "column ::= columnid type carglist", + /* 29 */ "columnid ::= nm", + /* 30 */ "id ::= ID", + /* 31 */ "ids ::= ID", + /* 32 */ "ids ::= STRING", + /* 33 */ "nm ::= ID", + /* 34 */ "nm ::= STRING", + /* 35 */ "nm ::= JOIN_KW", + /* 36 */ "type ::=", + /* 37 */ "type ::= typetoken", + /* 38 */ "typetoken ::= typename", + /* 39 */ "typetoken ::= typename LP signed RP", + /* 40 */ "typetoken ::= typename LP signed COMMA signed RP", + /* 41 */ "typename ::= ids", + /* 42 */ "typename ::= typename ids", + /* 43 */ "signed ::= plus_num", + /* 44 */ "signed ::= minus_num", + /* 45 */ "carglist ::= carglist carg", + /* 46 */ "carglist ::=", + /* 47 */ "carg ::= CONSTRAINT nm ccons", + /* 48 */ "carg ::= ccons", + /* 49 */ "carg ::= DEFAULT term", + /* 50 */ "carg ::= DEFAULT LP expr RP", + /* 51 */ "carg ::= DEFAULT PLUS term", + /* 52 */ "carg ::= DEFAULT MINUS term", + /* 53 */ "carg ::= DEFAULT id", + /* 54 */ "ccons ::= NULL onconf", + /* 55 */ "ccons ::= NOT NULL onconf", + /* 56 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", + /* 57 */ "ccons ::= UNIQUE onconf", + /* 58 */ "ccons ::= CHECK LP expr RP onconf", + /* 59 */ "ccons ::= REFERENCES nm idxlist_opt refargs", + /* 60 */ "ccons ::= defer_subclause", + /* 61 */ "ccons ::= COLLATE id", + /* 62 */ "autoinc ::=", + /* 63 */ "autoinc ::= AUTOINCR", + /* 64 */ "refargs ::=", + /* 65 */ "refargs ::= refargs refarg", + /* 66 */ "refarg ::= MATCH nm", + /* 67 */ "refarg ::= ON DELETE refact", + /* 68 */ "refarg ::= ON UPDATE refact", + /* 69 */ "refarg ::= ON INSERT refact", + /* 70 */ "refact ::= SET NULL", + /* 71 */ "refact ::= SET DEFAULT", + /* 72 */ "refact ::= CASCADE", + /* 73 */ "refact ::= RESTRICT", + /* 74 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", + /* 75 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", + /* 76 */ "init_deferred_pred_opt ::=", + /* 77 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", + /* 78 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", + /* 79 */ "conslist_opt ::=", + /* 80 */ "conslist_opt ::= COMMA conslist", + /* 81 */ "conslist ::= conslist COMMA tcons", + /* 82 */ "conslist ::= conslist tcons", + /* 83 */ "conslist ::= tcons", + /* 84 */ "tcons ::= CONSTRAINT nm", + /* 85 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", + /* 86 */ "tcons ::= UNIQUE LP idxlist RP onconf", + /* 87 */ "tcons ::= CHECK expr onconf", + /* 88 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", + /* 89 */ "defer_subclause_opt ::=", + /* 90 */ "defer_subclause_opt ::= defer_subclause", + /* 91 */ "onconf ::=", + /* 92 */ "onconf ::= ON CONFLICT resolvetype", + /* 93 */ "orconf ::=", + /* 94 */ "orconf ::= OR resolvetype", + /* 95 */ "resolvetype ::= raisetype", + /* 96 */ "resolvetype ::= IGNORE", + /* 97 */ "resolvetype ::= REPLACE", + /* 98 */ "cmd ::= DROP TABLE fullname", + /* 99 */ "cmd ::= CREATE temp VIEW nm dbnm AS select", + /* 100 */ "cmd ::= DROP VIEW fullname", + /* 101 */ "cmd ::= select", + /* 102 */ "select ::= oneselect", + /* 103 */ "select ::= select multiselect_op oneselect", + /* 104 */ "multiselect_op ::= UNION", + /* 105 */ "multiselect_op ::= UNION ALL", + /* 106 */ "multiselect_op ::= INTERSECT", + /* 107 */ "multiselect_op ::= EXCEPT", + /* 108 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", + /* 109 */ "distinct ::= DISTINCT", + /* 110 */ "distinct ::= ALL", + /* 111 */ "distinct ::=", + /* 112 */ "sclp ::= selcollist COMMA", + /* 113 */ "sclp ::=", + /* 114 */ "selcollist ::= sclp expr as", + /* 115 */ "selcollist ::= sclp STAR", + /* 116 */ "selcollist ::= sclp nm DOT STAR", + /* 117 */ "as ::= AS nm", + /* 118 */ "as ::= ids", + /* 119 */ "as ::=", + /* 120 */ "from ::=", + /* 121 */ "from ::= FROM seltablist", + /* 122 */ "stl_prefix ::= seltablist joinop", + /* 123 */ "stl_prefix ::=", + /* 124 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt", + /* 125 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt", + /* 126 */ "seltablist_paren ::= select", + /* 127 */ "seltablist_paren ::= seltablist", + /* 128 */ "dbnm ::=", + /* 129 */ "dbnm ::= DOT nm", + /* 130 */ "fullname ::= nm dbnm", + /* 131 */ "joinop ::= COMMA", + /* 132 */ "joinop ::= JOIN", + /* 133 */ "joinop ::= JOIN_KW JOIN", + /* 134 */ "joinop ::= JOIN_KW nm JOIN", + /* 135 */ "joinop ::= JOIN_KW nm nm JOIN", + /* 136 */ "on_opt ::= ON expr", + /* 137 */ "on_opt ::=", + /* 138 */ "using_opt ::= USING LP inscollist RP", + /* 139 */ "using_opt ::=", + /* 140 */ "orderby_opt ::=", + /* 141 */ "orderby_opt ::= ORDER BY sortlist", + /* 142 */ "sortlist ::= sortlist COMMA sortitem collate sortorder", + /* 143 */ "sortlist ::= sortitem collate sortorder", + /* 144 */ "sortitem ::= expr", + /* 145 */ "sortorder ::= ASC", + /* 146 */ "sortorder ::= DESC", + /* 147 */ "sortorder ::=", + /* 148 */ "collate ::=", + /* 149 */ "collate ::= COLLATE id", + /* 150 */ "groupby_opt ::=", + /* 151 */ "groupby_opt ::= GROUP BY exprlist", + /* 152 */ "having_opt ::=", + /* 153 */ "having_opt ::= HAVING expr", + /* 154 */ "limit_opt ::=", + /* 155 */ "limit_opt ::= LIMIT expr", + /* 156 */ "limit_opt ::= LIMIT expr OFFSET expr", + /* 157 */ "limit_opt ::= LIMIT expr COMMA expr", + /* 158 */ "cmd ::= DELETE FROM fullname where_opt", + /* 159 */ "where_opt ::=", + /* 160 */ "where_opt ::= WHERE expr", + /* 161 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt", + /* 162 */ "setlist ::= setlist COMMA nm EQ expr", + /* 163 */ "setlist ::= nm EQ expr", + /* 164 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP", + /* 165 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", + /* 166 */ "insert_cmd ::= INSERT orconf", + /* 167 */ "insert_cmd ::= REPLACE", + /* 168 */ "itemlist ::= itemlist COMMA expr", + /* 169 */ "itemlist ::= expr", + /* 170 */ "inscollist_opt ::=", + /* 171 */ "inscollist_opt ::= LP inscollist RP", + /* 172 */ "inscollist ::= inscollist COMMA nm", + /* 173 */ "inscollist ::= nm", + /* 174 */ "expr ::= term", + /* 175 */ "expr ::= LP expr RP", + /* 176 */ "term ::= NULL", + /* 177 */ "expr ::= ID", + /* 178 */ "expr ::= JOIN_KW", + /* 179 */ "expr ::= nm DOT nm", + /* 180 */ "expr ::= nm DOT nm DOT nm", + /* 181 */ "term ::= INTEGER", + /* 182 */ "term ::= FLOAT", + /* 183 */ "term ::= STRING", + /* 184 */ "term ::= BLOB", + /* 185 */ "expr ::= REGISTER", + /* 186 */ "expr ::= VARIABLE", + /* 187 */ "expr ::= CAST LP expr AS typetoken RP", + /* 188 */ "expr ::= ID LP distinct exprlist RP", + /* 189 */ "expr ::= ID LP STAR RP", + /* 190 */ "term ::= CTIME_KW", + /* 191 */ "expr ::= expr AND expr", + /* 192 */ "expr ::= expr OR expr", + /* 193 */ "expr ::= expr LT expr", + /* 194 */ "expr ::= expr GT expr", + /* 195 */ "expr ::= expr LE expr", + /* 196 */ "expr ::= expr GE expr", + /* 197 */ "expr ::= expr NE expr", + /* 198 */ "expr ::= expr EQ expr", + /* 199 */ "expr ::= expr BITAND expr", + /* 200 */ "expr ::= expr BITOR expr", + /* 201 */ "expr ::= expr LSHIFT expr", + /* 202 */ "expr ::= expr RSHIFT expr", + /* 203 */ "expr ::= expr PLUS expr", + /* 204 */ "expr ::= expr MINUS expr", + /* 205 */ "expr ::= expr STAR expr", + /* 206 */ "expr ::= expr SLASH expr", + /* 207 */ "expr ::= expr REM expr", + /* 208 */ "expr ::= expr CONCAT expr", + /* 209 */ "likeop ::= LIKE_KW", + /* 210 */ "likeop ::= NOT LIKE_KW", + /* 211 */ "escape ::= ESCAPE expr", + /* 212 */ "escape ::=", + /* 213 */ "expr ::= expr likeop expr escape", + /* 214 */ "expr ::= expr ISNULL", + /* 215 */ "expr ::= expr IS NULL", + /* 216 */ "expr ::= expr NOTNULL", + /* 217 */ "expr ::= expr NOT NULL", + /* 218 */ "expr ::= expr IS NOT NULL", + /* 219 */ "expr ::= NOT expr", + /* 220 */ "expr ::= BITNOT expr", + /* 221 */ "expr ::= MINUS expr", + /* 222 */ "expr ::= PLUS expr", + /* 223 */ "between_op ::= BETWEEN", + /* 224 */ "between_op ::= NOT BETWEEN", + /* 225 */ "expr ::= expr between_op expr AND expr", + /* 226 */ "in_op ::= IN", + /* 227 */ "in_op ::= NOT IN", + /* 228 */ "expr ::= expr in_op LP exprlist RP", + /* 229 */ "expr ::= LP select RP", + /* 230 */ "expr ::= expr in_op LP select RP", + /* 231 */ "expr ::= expr in_op nm dbnm", + /* 232 */ "expr ::= EXISTS LP select RP", + /* 233 */ "expr ::= CASE case_operand case_exprlist case_else END", + /* 234 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", + /* 235 */ "case_exprlist ::= WHEN expr THEN expr", + /* 236 */ "case_else ::= ELSE expr", + /* 237 */ "case_else ::=", + /* 238 */ "case_operand ::= expr", + /* 239 */ "case_operand ::=", + /* 240 */ "exprlist ::= exprlist COMMA expritem", + /* 241 */ "exprlist ::= expritem", + /* 242 */ "expritem ::= expr", + /* 243 */ "expritem ::=", + /* 244 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf", + /* 245 */ "uniqueflag ::= UNIQUE", + /* 246 */ "uniqueflag ::=", + /* 247 */ "idxlist_opt ::=", + /* 248 */ "idxlist_opt ::= LP idxlist RP", + /* 249 */ "idxlist ::= idxlist COMMA idxitem collate sortorder", + /* 250 */ "idxlist ::= idxitem collate sortorder", + /* 251 */ "idxitem ::= nm", + /* 252 */ "cmd ::= DROP INDEX fullname", + /* 253 */ "cmd ::= VACUUM", + /* 254 */ "cmd ::= VACUUM nm", + /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nm", + /* 256 */ "cmd ::= PRAGMA nm dbnm EQ ON", + /* 257 */ "cmd ::= PRAGMA nm dbnm EQ plus_num", + /* 258 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", + /* 259 */ "cmd ::= PRAGMA nm dbnm LP nm RP", + /* 260 */ "cmd ::= PRAGMA nm dbnm", + /* 261 */ "plus_num ::= plus_opt number", + /* 262 */ "minus_num ::= MINUS number", + /* 263 */ "number ::= INTEGER", + /* 264 */ "number ::= FLOAT", + /* 265 */ "plus_opt ::= PLUS", + /* 266 */ "plus_opt ::=", + /* 267 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", + /* 268 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", + /* 269 */ "trigger_time ::= BEFORE", + /* 270 */ "trigger_time ::= AFTER", + /* 271 */ "trigger_time ::= INSTEAD OF", + /* 272 */ "trigger_time ::=", + /* 273 */ "trigger_event ::= DELETE", + /* 274 */ "trigger_event ::= INSERT", + /* 275 */ "trigger_event ::= UPDATE", + /* 276 */ "trigger_event ::= UPDATE OF inscollist", + /* 277 */ "foreach_clause ::=", + /* 278 */ "foreach_clause ::= FOR EACH ROW", + /* 279 */ "foreach_clause ::= FOR EACH STATEMENT", + /* 280 */ "when_clause ::=", + /* 281 */ "when_clause ::= WHEN expr", + /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list", + /* 283 */ "trigger_cmd_list ::=", + /* 284 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", + /* 285 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", + /* 286 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", + /* 287 */ "trigger_cmd ::= DELETE FROM nm where_opt", + /* 288 */ "trigger_cmd ::= select", + /* 289 */ "expr ::= RAISE LP IGNORE RP", + /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP", + /* 291 */ "raisetype ::= ROLLBACK", + /* 292 */ "raisetype ::= ABORT", + /* 293 */ "raisetype ::= FAIL", + /* 294 */ "cmd ::= DROP TRIGGER fullname", + /* 295 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt", + /* 296 */ "key_opt ::=", + /* 297 */ "key_opt ::= KEY ids", + /* 298 */ "key_opt ::= KEY BLOB", + /* 299 */ "database_kw_opt ::= DATABASE", + /* 300 */ "database_kw_opt ::=", + /* 301 */ "cmd ::= DETACH database_kw_opt nm", + /* 302 */ "cmd ::= REINDEX", + /* 303 */ "cmd ::= REINDEX nm dbnm", + /* 304 */ "cmd ::= ANALYZE", + /* 305 */ "cmd ::= ANALYZE nm dbnm", + /* 306 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", + /* 307 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", + /* 308 */ "add_column_fullname ::= fullname", + /* 309 */ "kwcolumn_opt ::=", + /* 310 */ "kwcolumn_opt ::= COLUMNKW", }; #endif /* NDEBUG */ @@ -1291,72 +1322,72 @@ ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ - case 157: - case 189: - case 206: -#line 334 "parse.y" -{sqlite3SelectDelete((yypminor->yy459));} -#line 1301 "parse.c" + case 162: + case 195: + case 212: +#line 370 "parse.y" +{sqlite3SelectDelete((yypminor->yy375));} +#line 1332 "parse.c" break; - case 170: - case 174: - case 194: - case 196: - case 204: + case 176: + case 177: + case 200: + case 202: case 210: - case 224: -#line 593 "parse.y" -{sqlite3ExprDelete((yypminor->yy2));} -#line 1312 "parse.c" + case 216: + case 230: +#line 629 "parse.y" +{sqlite3ExprDelete((yypminor->yy62));} +#line 1343 "parse.c" break; - case 175: - case 183: - case 192: - case 195: - case 197: - case 199: - case 209: - case 212: - case 213: - case 216: + case 181: + case 189: + case 198: + case 201: + case 203: + case 205: + case 215: + case 218: + case 219: case 222: -#line 812 "parse.y" -{sqlite3ExprListDelete((yypminor->yy82));} -#line 1327 "parse.c" + case 228: +#line 876 "parse.y" +{sqlite3ExprListDelete((yypminor->yy418));} +#line 1358 "parse.c" break; - case 188: - case 193: - case 201: - case 202: -#line 463 "parse.y" -{sqlite3SrcListDelete((yypminor->yy67));} -#line 1335 "parse.c" + case 194: + case 199: + case 207: + case 208: +#line 499 "parse.y" +{sqlite3SrcListDelete((yypminor->yy151));} +#line 1366 "parse.c" break; - case 198: -#line 525 "parse.y" + case 204: +#line 561 "parse.y" { - sqlite3ExprDelete((yypminor->yy244).pLimit); - sqlite3ExprDelete((yypminor->yy244).pOffset); + sqlite3ExprDelete((yypminor->yy220).pLimit); + sqlite3ExprDelete((yypminor->yy220).pOffset); } -#line 1343 "parse.c" +#line 1374 "parse.c" break; - case 205: - case 208: - case 215: -#line 481 "parse.y" + case 211: + case 214: + case 221: +#line 517 "parse.y" {sqlite3IdListDelete((yypminor->yy240));} -#line 1350 "parse.c" +#line 1381 "parse.c" break; - case 230: - case 235: -#line 905 "parse.y" -{sqlite3DeleteTriggerStep((yypminor->yy347));} -#line 1356 "parse.c" + case 236: + case 241: +#line 969 "parse.y" +{sqlite3DeleteTriggerStep((yypminor->yy360));} +#line 1387 "parse.c" break; - case 232: -#line 889 "parse.y" -{sqlite3IdListDelete((yypminor->yy210).b);} -#line 1361 "parse.c" + case 238: +#line 953 "parse.y" +{sqlite3IdListDelete((yypminor->yy30).b);} +#line 1392 "parse.c" break; default: break; /* If no destructor action specified: do nothing */ } @@ -1532,311 +1563,317 @@ YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { - { 142, 1 }, - { 143, 2 }, - { 143, 1 }, - { 145, 1 }, - { 144, 1 }, - { 144, 3 }, - { 147, 0 }, { 147, 1 }, - { 146, 3 }, - { 149, 0 }, + { 148, 2 }, + { 148, 1 }, + { 150, 1 }, { 149, 1 }, - { 149, 2 }, - { 148, 0 }, - { 148, 1 }, - { 148, 1 }, - { 148, 1 }, - { 146, 2 }, - { 146, 2 }, - { 146, 2 }, - { 146, 2 }, - { 151, 5 }, + { 149, 3 }, + { 152, 0 }, + { 152, 1 }, + { 152, 3 }, + { 151, 3 }, + { 154, 0 }, + { 154, 1 }, + { 154, 2 }, + { 153, 0 }, { 153, 1 }, - { 153, 0 }, - { 152, 4 }, - { 152, 2 }, - { 155, 3 }, - { 155, 1 }, - { 158, 3 }, - { 159, 1 }, - { 162, 1 }, - { 163, 1 }, - { 163, 1 }, - { 150, 1 }, - { 150, 1 }, - { 150, 1 }, - { 160, 0 }, + { 153, 1 }, + { 153, 1 }, + { 151, 2 }, + { 151, 2 }, + { 151, 2 }, + { 151, 2 }, + { 156, 5 }, + { 158, 1 }, + { 158, 0 }, + { 157, 4 }, + { 157, 2 }, + { 160, 3 }, { 160, 1 }, - { 160, 4 }, - { 160, 6 }, + { 163, 3 }, { 164, 1 }, - { 164, 2 }, + { 167, 1 }, + { 168, 1 }, + { 168, 1 }, + { 155, 1 }, + { 155, 1 }, + { 155, 1 }, + { 165, 0 }, { 165, 1 }, - { 165, 1 }, - { 161, 2 }, - { 161, 0 }, - { 168, 3 }, - { 168, 1 }, - { 168, 2 }, - { 168, 3 }, - { 168, 3 }, - { 168, 2 }, - { 169, 2 }, - { 169, 3 }, - { 169, 5 }, - { 169, 2 }, - { 169, 5 }, + { 169, 1 }, { 169, 4 }, - { 169, 1 }, - { 169, 2 }, - { 173, 0 }, - { 173, 1 }, - { 176, 0 }, - { 176, 2 }, - { 178, 2 }, - { 178, 3 }, - { 178, 3 }, - { 178, 3 }, - { 179, 2 }, - { 179, 2 }, - { 179, 1 }, - { 179, 1 }, - { 177, 3 }, - { 177, 2 }, + { 169, 6 }, + { 170, 1 }, + { 170, 2 }, + { 171, 1 }, + { 171, 1 }, + { 166, 2 }, + { 166, 0 }, + { 174, 3 }, + { 174, 1 }, + { 174, 2 }, + { 174, 4 }, + { 174, 3 }, + { 174, 3 }, + { 174, 2 }, + { 175, 2 }, + { 175, 3 }, + { 175, 5 }, + { 175, 2 }, + { 175, 5 }, + { 175, 4 }, + { 175, 1 }, + { 175, 2 }, { 180, 0 }, - { 180, 2 }, - { 180, 2 }, - { 156, 0 }, - { 156, 2 }, - { 181, 3 }, - { 181, 2 }, - { 181, 1 }, + { 180, 1 }, + { 182, 0 }, { 182, 2 }, - { 182, 7 }, - { 182, 5 }, - { 182, 3 }, - { 182, 10 }, - { 184, 0 }, - { 184, 1 }, - { 171, 0 }, - { 171, 3 }, - { 185, 0 }, + { 184, 2 }, + { 184, 3 }, + { 184, 3 }, + { 184, 3 }, { 185, 2 }, - { 186, 1 }, - { 186, 1 }, - { 186, 1 }, - { 146, 3 }, - { 146, 7 }, - { 146, 3 }, - { 146, 1 }, - { 157, 1 }, - { 157, 3 }, + { 185, 2 }, + { 185, 1 }, + { 185, 1 }, + { 183, 3 }, + { 183, 2 }, + { 186, 0 }, + { 186, 2 }, + { 186, 2 }, + { 161, 0 }, + { 161, 2 }, + { 187, 3 }, + { 187, 2 }, + { 187, 1 }, + { 188, 2 }, + { 188, 7 }, + { 188, 5 }, + { 188, 3 }, + { 188, 10 }, + { 190, 0 }, { 190, 1 }, - { 190, 2 }, - { 190, 1 }, - { 190, 1 }, - { 189, 9 }, - { 191, 1 }, - { 191, 1 }, + { 178, 0 }, + { 178, 3 }, { 191, 0 }, - { 199, 2 }, - { 199, 0 }, - { 192, 3 }, - { 192, 2 }, - { 192, 4 }, - { 200, 2 }, - { 200, 1 }, - { 200, 0 }, - { 193, 0 }, - { 193, 2 }, - { 202, 2 }, - { 202, 0 }, - { 201, 6 }, - { 201, 7 }, - { 206, 1 }, - { 206, 1 }, - { 154, 0 }, - { 154, 2 }, - { 188, 2 }, - { 203, 1 }, - { 203, 1 }, - { 203, 2 }, - { 203, 3 }, - { 203, 4 }, - { 204, 2 }, - { 204, 0 }, - { 205, 4 }, - { 205, 0 }, + { 191, 2 }, + { 192, 1 }, + { 192, 1 }, + { 192, 1 }, + { 151, 3 }, + { 151, 7 }, + { 151, 3 }, + { 151, 1 }, + { 162, 1 }, + { 162, 3 }, + { 196, 1 }, + { 196, 2 }, + { 196, 1 }, + { 196, 1 }, + { 195, 9 }, + { 197, 1 }, + { 197, 1 }, { 197, 0 }, - { 197, 3 }, - { 209, 5 }, - { 209, 3 }, - { 210, 1 }, - { 172, 1 }, - { 172, 1 }, - { 172, 0 }, - { 211, 0 }, - { 211, 2 }, - { 195, 0 }, - { 195, 3 }, - { 196, 0 }, - { 196, 2 }, - { 198, 0 }, + { 205, 2 }, + { 205, 0 }, + { 198, 3 }, { 198, 2 }, { 198, 4 }, - { 198, 4 }, - { 146, 4 }, - { 194, 0 }, + { 206, 2 }, + { 206, 1 }, + { 206, 0 }, + { 199, 0 }, + { 199, 2 }, + { 208, 2 }, + { 208, 0 }, + { 207, 6 }, + { 207, 7 }, + { 212, 1 }, + { 212, 1 }, + { 159, 0 }, + { 159, 2 }, { 194, 2 }, - { 146, 6 }, - { 213, 5 }, - { 213, 3 }, - { 146, 8 }, - { 146, 5 }, - { 214, 2 }, - { 214, 1 }, - { 216, 3 }, - { 216, 1 }, - { 215, 0 }, + { 209, 1 }, + { 209, 1 }, + { 209, 2 }, + { 209, 3 }, + { 209, 4 }, + { 210, 2 }, + { 210, 0 }, + { 211, 4 }, + { 211, 0 }, + { 203, 0 }, + { 203, 3 }, + { 215, 5 }, { 215, 3 }, - { 208, 3 }, - { 208, 1 }, - { 174, 1 }, - { 174, 3 }, - { 170, 1 }, - { 174, 1 }, - { 174, 1 }, - { 174, 3 }, - { 174, 5 }, - { 170, 1 }, - { 170, 1 }, - { 170, 1 }, - { 170, 1 }, - { 174, 1 }, - { 174, 1 }, - { 174, 4 }, - { 174, 4 }, - { 170, 1 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 174, 3 }, - { 217, 1 }, + { 216, 1 }, + { 179, 1 }, + { 179, 1 }, + { 179, 0 }, + { 217, 0 }, { 217, 2 }, - { 218, 2 }, - { 218, 0 }, - { 174, 4 }, - { 174, 2 }, - { 174, 3 }, - { 174, 2 }, - { 174, 3 }, - { 174, 4 }, - { 174, 2 }, - { 174, 2 }, - { 174, 2 }, - { 174, 2 }, - { 219, 1 }, - { 219, 2 }, - { 174, 5 }, + { 201, 0 }, + { 201, 3 }, + { 202, 0 }, + { 202, 2 }, + { 204, 0 }, + { 204, 2 }, + { 204, 4 }, + { 204, 4 }, + { 151, 4 }, + { 200, 0 }, + { 200, 2 }, + { 151, 6 }, + { 219, 5 }, + { 219, 3 }, + { 151, 8 }, + { 151, 5 }, + { 220, 2 }, { 220, 1 }, - { 220, 2 }, - { 174, 5 }, - { 174, 3 }, - { 174, 5 }, - { 174, 4 }, - { 174, 4 }, - { 174, 5 }, - { 222, 5 }, - { 222, 4 }, + { 222, 3 }, + { 222, 1 }, + { 221, 0 }, + { 221, 3 }, + { 214, 3 }, + { 214, 1 }, + { 177, 1 }, + { 177, 3 }, + { 176, 1 }, + { 177, 1 }, + { 177, 1 }, + { 177, 3 }, + { 177, 5 }, + { 176, 1 }, + { 176, 1 }, + { 176, 1 }, + { 176, 1 }, + { 177, 1 }, + { 177, 1 }, + { 177, 6 }, + { 177, 5 }, + { 177, 4 }, + { 176, 1 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 177, 3 }, + { 223, 1 }, { 223, 2 }, - { 223, 0 }, - { 221, 1 }, - { 221, 0 }, - { 212, 3 }, - { 212, 1 }, - { 224, 1 }, + { 224, 2 }, { 224, 0 }, - { 146, 11 }, + { 177, 4 }, + { 177, 2 }, + { 177, 3 }, + { 177, 2 }, + { 177, 3 }, + { 177, 4 }, + { 177, 2 }, + { 177, 2 }, + { 177, 2 }, + { 177, 2 }, { 225, 1 }, - { 225, 0 }, - { 175, 0 }, - { 175, 3 }, - { 183, 5 }, - { 183, 3 }, + { 225, 2 }, + { 177, 5 }, { 226, 1 }, - { 146, 3 }, - { 146, 1 }, - { 146, 2 }, - { 146, 5 }, - { 146, 5 }, - { 146, 5 }, - { 146, 5 }, - { 146, 6 }, - { 146, 3 }, - { 166, 2 }, - { 167, 2 }, - { 228, 1 }, - { 228, 1 }, + { 226, 2 }, + { 177, 5 }, + { 177, 3 }, + { 177, 5 }, + { 177, 4 }, + { 177, 4 }, + { 177, 5 }, + { 228, 5 }, + { 228, 4 }, + { 229, 2 }, + { 229, 0 }, { 227, 1 }, { 227, 0 }, - { 146, 5 }, - { 229, 10 }, + { 218, 3 }, + { 218, 1 }, + { 230, 1 }, + { 230, 0 }, + { 151, 11 }, { 231, 1 }, - { 231, 1 }, - { 231, 2 }, { 231, 0 }, + { 181, 0 }, + { 181, 3 }, + { 189, 5 }, + { 189, 3 }, { 232, 1 }, - { 232, 1 }, - { 232, 1 }, - { 232, 3 }, + { 151, 3 }, + { 151, 1 }, + { 151, 2 }, + { 151, 5 }, + { 151, 5 }, + { 151, 5 }, + { 151, 5 }, + { 151, 6 }, + { 151, 3 }, + { 172, 2 }, + { 173, 2 }, + { 234, 1 }, + { 234, 1 }, + { 233, 1 }, { 233, 0 }, - { 233, 3 }, - { 233, 3 }, - { 234, 0 }, - { 234, 2 }, - { 230, 3 }, - { 230, 0 }, - { 235, 6 }, - { 235, 8 }, - { 235, 5 }, - { 235, 4 }, - { 235, 1 }, - { 174, 4 }, - { 174, 6 }, - { 187, 1 }, - { 187, 1 }, - { 187, 1 }, - { 146, 3 }, - { 146, 6 }, + { 151, 5 }, + { 235, 10 }, + { 237, 1 }, + { 237, 1 }, + { 237, 2 }, { 237, 0 }, - { 237, 2 }, - { 237, 2 }, - { 236, 1 }, - { 236, 0 }, - { 146, 3 }, - { 146, 1 }, - { 146, 3 }, - { 146, 6 }, - { 146, 6 }, { 238, 1 }, + { 238, 1 }, + { 238, 1 }, + { 238, 3 }, { 239, 0 }, - { 239, 1 }, + { 239, 3 }, + { 239, 3 }, + { 240, 0 }, + { 240, 2 }, + { 236, 3 }, + { 236, 0 }, + { 241, 6 }, + { 241, 8 }, + { 241, 5 }, + { 241, 4 }, + { 241, 1 }, + { 177, 4 }, + { 177, 6 }, + { 193, 1 }, + { 193, 1 }, + { 193, 1 }, + { 151, 3 }, + { 151, 6 }, + { 243, 0 }, + { 243, 2 }, + { 243, 2 }, + { 242, 1 }, + { 242, 0 }, + { 151, 3 }, + { 151, 1 }, + { 151, 3 }, + { 151, 1 }, + { 151, 3 }, + { 151, 6 }, + { 151, 6 }, + { 244, 1 }, + { 245, 0 }, + { 245, 1 }, }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1886,753 +1923,777 @@ ** break; */ case 3: -#line 84 "parse.y" +#line 102 "parse.y" { sqlite3FinishCoding(pParse); } -#line 1893 "parse.c" +#line 1930 "parse.c" break; case 6: -#line 87 "parse.y" +#line 105 "parse.y" { sqlite3BeginParse(pParse, 0); } -#line 1898 "parse.c" +#line 1935 "parse.c" break; case 7: -#line 89 "parse.y" +#line 107 "parse.y" { sqlite3BeginParse(pParse, 1); } -#line 1903 "parse.c" +#line 1940 "parse.c" break; case 8: -#line 95 "parse.y" -{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy412);} -#line 1908 "parse.c" +#line 108 "parse.y" +{ sqlite3BeginParse(pParse, 2); } +#line 1945 "parse.c" break; - case 12: -#line 100 "parse.y" -{yygotominor.yy412 = TK_DEFERRED;} -#line 1913 "parse.c" + case 9: +#line 114 "parse.y" +{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy280);} +#line 1950 "parse.c" break; case 13: +#line 119 "parse.y" +{yygotominor.yy280 = TK_DEFERRED;} +#line 1955 "parse.c" + break; case 14: case 15: - case 101: - case 103: + case 16: case 104: -#line 101 "parse.y" -{yygotominor.yy412 = yymsp[0].major;} -#line 1923 "parse.c" + case 106: + case 107: +#line 120 "parse.y" +{yygotominor.yy280 = yymsp[0].major;} +#line 1965 "parse.c" break; - case 16: case 17: -#line 104 "parse.y" + case 18: +#line 123 "parse.y" {sqlite3CommitTransaction(pParse);} -#line 1929 "parse.c" +#line 1971 "parse.c" break; - case 18: -#line 106 "parse.y" + case 19: +#line 125 "parse.y" {sqlite3RollbackTransaction(pParse);} -#line 1934 "parse.c" +#line 1976 "parse.c" break; - case 20: -#line 111 "parse.y" + case 21: +#line 130 "parse.y" { - sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258,yymsp[-3].minor.yy412,0); + sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198,yymsp[-3].minor.yy280,0); } -#line 1941 "parse.c" +#line 1983 "parse.c" break; - case 21: - case 60: - case 74: - case 106: - case 220: - case 223: -#line 116 "parse.y" -{yygotominor.yy412 = 1;} -#line 1951 "parse.c" - break; case 22: - case 59: - case 73: - case 75: - case 86: - case 107: - case 108: - case 219: - case 222: -#line 118 "parse.y" -{yygotominor.yy412 = 0;} -#line 1964 "parse.c" + case 63: + case 77: + case 109: + case 224: + case 227: +#line 135 "parse.y" +{yygotominor.yy280 = 1;} +#line 1993 "parse.c" break; case 23: -#line 119 "parse.y" -{ - sqlite3EndTable(pParse,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy0,0); -} -#line 1971 "parse.c" + case 62: + case 76: + case 78: + case 89: + case 110: + case 111: + case 223: + case 226: +#line 137 "parse.y" +{yygotominor.yy280 = 0;} +#line 2006 "parse.c" break; case 24: -#line 122 "parse.y" +#line 138 "parse.y" { - sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy459); - sqlite3SelectDelete(yymsp[0].minor.yy459); + sqlite3EndTable(pParse,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy0,0); } -#line 1979 "parse.c" +#line 2013 "parse.c" break; - case 27: -#line 133 "parse.y" + case 25: +#line 141 "parse.y" { - yygotominor.yy258.z = yymsp[-2].minor.yy258.z; - yygotominor.yy258.n = (pParse->sLastToken.z-yymsp[-2].minor.yy258.z) + pParse->sLastToken.n; + sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy375); + sqlite3SelectDelete(yymsp[0].minor.yy375); } -#line 1987 "parse.c" +#line 2021 "parse.c" break; case 28: -#line 137 "parse.y" +#line 153 "parse.y" { - sqlite3AddColumn(pParse,&yymsp[0].minor.yy258); - yygotominor.yy258 = yymsp[0].minor.yy258; + yygotominor.yy198.z = yymsp[-2].minor.yy198.z; + yygotominor.yy198.n = (pParse->sLastToken.z-yymsp[-2].minor.yy198.z) + pParse->sLastToken.n; } -#line 1995 "parse.c" +#line 2029 "parse.c" break; case 29: +#line 157 "parse.y" +{ + sqlite3AddColumn(pParse,&yymsp[0].minor.yy198); + yygotominor.yy198 = yymsp[0].minor.yy198; +} +#line 2037 "parse.c" + break; case 30: case 31: case 32: case 33: case 34: - case 259: - case 260: -#line 147 "parse.y" -{yygotominor.yy258 = yymsp[0].minor.yy0;} -#line 2007 "parse.c" + case 35: + case 263: + case 264: +#line 167 "parse.y" +{yygotominor.yy198 = yymsp[0].minor.yy0;} +#line 2049 "parse.c" break; - case 36: -#line 202 "parse.y" -{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy258,&yymsp[0].minor.yy258);} -#line 2012 "parse.c" - break; case 37: -#line 203 "parse.y" -{sqlite3AddColumnType(pParse,&yymsp[-3].minor.yy258,&yymsp[0].minor.yy0);} -#line 2017 "parse.c" +#line 227 "parse.y" +{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy198);} +#line 2054 "parse.c" break; case 38: -#line 205 "parse.y" -{sqlite3AddColumnType(pParse,&yymsp[-5].minor.yy258,&yymsp[0].minor.yy0);} -#line 2022 "parse.c" + case 41: + case 117: + case 118: + case 129: + case 149: + case 251: + case 261: + case 262: +#line 228 "parse.y" +{yygotominor.yy198 = yymsp[0].minor.yy198;} +#line 2067 "parse.c" break; case 39: - case 114: - case 115: - case 126: - case 146: - case 247: - case 257: - case 258: -#line 207 "parse.y" -{yygotominor.yy258 = yymsp[0].minor.yy258;} -#line 2034 "parse.c" +#line 229 "parse.y" +{ + yygotominor.yy198.z = yymsp[-3].minor.yy198.z; + yygotominor.yy198.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy198.z; +} +#line 2075 "parse.c" break; case 40: -#line 208 "parse.y" -{yygotominor.yy258.z=yymsp[-1].minor.yy258.z; yygotominor.yy258.n=yymsp[0].minor.yy258.n+(yymsp[0].minor.yy258.z-yymsp[-1].minor.yy258.z);} -#line 2039 "parse.c" +#line 233 "parse.y" +{ + yygotominor.yy198.z = yymsp[-5].minor.yy198.z; + yygotominor.yy198.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy198.z; +} +#line 2083 "parse.c" break; - case 41: -#line 210 "parse.y" -{ yygotominor.yy412 = atoi(yymsp[0].minor.yy258.z); } -#line 2044 "parse.c" - break; case 42: -#line 211 "parse.y" -{ yygotominor.yy412 = -atoi(yymsp[0].minor.yy258.z); } -#line 2049 "parse.c" +#line 239 "parse.y" +{yygotominor.yy198.z=yymsp[-1].minor.yy198.z; yygotominor.yy198.n=yymsp[0].minor.yy198.n+(yymsp[0].minor.yy198.z-yymsp[-1].minor.yy198.z);} +#line 2088 "parse.c" break; - case 47: - case 48: -#line 216 "parse.y" -{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy2);} -#line 2055 "parse.c" + case 43: +#line 241 "parse.y" +{ yygotominor.yy280 = atoi(yymsp[0].minor.yy198.z); } +#line 2093 "parse.c" break; + case 44: +#line 242 "parse.y" +{ yygotominor.yy280 = -atoi(yymsp[0].minor.yy198.z); } +#line 2098 "parse.c" + break; case 49: -#line 218 "parse.y" -{ - Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy2, 0, 0); - sqlite3AddDefaultValue(pParse,p); -} -#line 2063 "parse.c" + case 51: +#line 251 "parse.y" +{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy62);} +#line 2104 "parse.c" break; case 50: -#line 222 "parse.y" +#line 252 "parse.y" +{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy62);} +#line 2109 "parse.c" + break; + case 52: +#line 254 "parse.y" { - Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy258); + Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy62, 0, 0); sqlite3AddDefaultValue(pParse,p); } -#line 2071 "parse.c" +#line 2117 "parse.c" break; - case 52: -#line 231 "parse.y" -{sqlite3AddNotNull(pParse, yymsp[0].minor.yy412);} -#line 2076 "parse.c" - break; case 53: -#line 233 "parse.y" -{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy412,yymsp[0].minor.yy412);} -#line 2081 "parse.c" +#line 258 "parse.y" +{ + Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy198); + sqlite3AddDefaultValue(pParse,p); +} +#line 2125 "parse.c" break; - case 54: -#line 234 "parse.y" -{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy412,0,0);} -#line 2086 "parse.c" - break; case 55: -#line 235 "parse.y" -{sqlite3ExprDelete(yymsp[-2].minor.yy2);} -#line 2091 "parse.c" +#line 267 "parse.y" +{sqlite3AddNotNull(pParse, yymsp[0].minor.yy280);} +#line 2130 "parse.c" break; case 56: -#line 237 "parse.y" -{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy258,yymsp[-1].minor.yy82,yymsp[0].minor.yy412);} -#line 2096 "parse.c" +#line 269 "parse.y" +{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy280,yymsp[0].minor.yy280);} +#line 2135 "parse.c" break; case 57: -#line 238 "parse.y" -{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy412);} -#line 2101 "parse.c" +#line 270 "parse.y" +{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy280,0,0);} +#line 2140 "parse.c" break; case 58: -#line 239 "parse.y" -{sqlite3AddCollateType(pParse, yymsp[0].minor.yy258.z, yymsp[0].minor.yy258.n);} -#line 2106 "parse.c" +#line 271 "parse.y" +{sqlite3ExprDelete(yymsp[-2].minor.yy62);} +#line 2145 "parse.c" break; - case 61: -#line 252 "parse.y" -{ yygotominor.yy412 = OE_Restrict * 0x010101; } -#line 2111 "parse.c" + case 59: +#line 273 "parse.y" +{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy198,yymsp[-1].minor.yy418,yymsp[0].minor.yy280);} +#line 2150 "parse.c" break; - case 62: -#line 253 "parse.y" -{ yygotominor.yy412 = (yymsp[-1].minor.yy412 & yymsp[0].minor.yy47.mask) | yymsp[0].minor.yy47.value; } -#line 2116 "parse.c" + case 60: +#line 274 "parse.y" +{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy280);} +#line 2155 "parse.c" break; - case 63: -#line 255 "parse.y" -{ yygotominor.yy47.value = 0; yygotominor.yy47.mask = 0x000000; } -#line 2121 "parse.c" + case 61: +#line 275 "parse.y" +{sqlite3AddCollateType(pParse, yymsp[0].minor.yy198.z, yymsp[0].minor.yy198.n);} +#line 2160 "parse.c" break; case 64: -#line 256 "parse.y" -{ yygotominor.yy47.value = yymsp[0].minor.yy412; yygotominor.yy47.mask = 0x0000ff; } -#line 2126 "parse.c" +#line 288 "parse.y" +{ yygotominor.yy280 = OE_Restrict * 0x010101; } +#line 2165 "parse.c" break; case 65: -#line 257 "parse.y" -{ yygotominor.yy47.value = yymsp[0].minor.yy412<<8; yygotominor.yy47.mask = 0x00ff00; } -#line 2131 "parse.c" +#line 289 "parse.y" +{ yygotominor.yy280 = (yymsp[-1].minor.yy280 & yymsp[0].minor.yy359.mask) | yymsp[0].minor.yy359.value; } +#line 2170 "parse.c" break; case 66: -#line 258 "parse.y" -{ yygotominor.yy47.value = yymsp[0].minor.yy412<<16; yygotominor.yy47.mask = 0xff0000; } -#line 2136 "parse.c" +#line 291 "parse.y" +{ yygotominor.yy359.value = 0; yygotominor.yy359.mask = 0x000000; } +#line 2175 "parse.c" break; case 67: -#line 260 "parse.y" -{ yygotominor.yy412 = OE_SetNull; } -#line 2141 "parse.c" +#line 292 "parse.y" +{ yygotominor.yy359.value = yymsp[0].minor.yy280; yygotominor.yy359.mask = 0x0000ff; } +#line 2180 "parse.c" break; case 68: -#line 261 "parse.y" -{ yygotominor.yy412 = OE_SetDflt; } -#line 2146 "parse.c" +#line 293 "parse.y" +{ yygotominor.yy359.value = yymsp[0].minor.yy280<<8; yygotominor.yy359.mask = 0x00ff00; } +#line 2185 "parse.c" break; case 69: -#line 262 "parse.y" -{ yygotominor.yy412 = OE_Cascade; } -#line 2151 "parse.c" +#line 294 "parse.y" +{ yygotominor.yy359.value = yymsp[0].minor.yy280<<16; yygotominor.yy359.mask = 0xff0000; } +#line 2190 "parse.c" break; case 70: -#line 263 "parse.y" -{ yygotominor.yy412 = OE_Restrict; } -#line 2156 "parse.c" +#line 296 "parse.y" +{ yygotominor.yy280 = OE_SetNull; } +#line 2195 "parse.c" break; case 71: +#line 297 "parse.y" +{ yygotominor.yy280 = OE_SetDflt; } +#line 2200 "parse.c" + break; case 72: - case 87: - case 89: - case 91: - case 92: - case 163: -#line 265 "parse.y" -{yygotominor.yy412 = yymsp[0].minor.yy412;} -#line 2167 "parse.c" +#line 298 "parse.y" +{ yygotominor.yy280 = OE_Cascade; } +#line 2205 "parse.c" break; - case 76: -#line 275 "parse.y" -{yygotominor.yy258.n = 0; yygotominor.yy258.z = 0;} -#line 2172 "parse.c" + case 73: +#line 299 "parse.y" +{ yygotominor.yy280 = OE_Restrict; } +#line 2210 "parse.c" break; - case 77: -#line 276 "parse.y" -{yygotominor.yy258 = yymsp[-1].minor.yy0;} -#line 2177 "parse.c" + case 74: + case 75: + case 90: + case 92: + case 94: + case 95: + case 166: +#line 301 "parse.y" +{yygotominor.yy280 = yymsp[0].minor.yy280;} +#line 2221 "parse.c" break; - case 82: -#line 282 "parse.y" -{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy82,yymsp[0].minor.yy412,yymsp[-2].minor.yy412);} -#line 2182 "parse.c" + case 79: +#line 311 "parse.y" +{yygotominor.yy198.n = 0; yygotominor.yy198.z = 0;} +#line 2226 "parse.c" break; - case 83: -#line 284 "parse.y" -{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy82,yymsp[0].minor.yy412,0,0);} -#line 2187 "parse.c" + case 80: +#line 312 "parse.y" +{yygotominor.yy198 = yymsp[-1].minor.yy0;} +#line 2231 "parse.c" break; case 85: -#line 287 "parse.y" -{ - sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy82, &yymsp[-3].minor.yy258, yymsp[-2].minor.yy82, yymsp[-1].minor.yy412); - sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy412); -} -#line 2195 "parse.c" +#line 318 "parse.y" +{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy418,yymsp[0].minor.yy280,yymsp[-2].minor.yy280);} +#line 2236 "parse.c" break; + case 86: +#line 320 "parse.y" +{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy418,yymsp[0].minor.yy280,0,0);} +#line 2241 "parse.c" + break; case 88: - case 90: -#line 301 "parse.y" -{yygotominor.yy412 = OE_Default;} -#line 2201 "parse.c" +#line 323 "parse.y" +{ + sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy418, &yymsp[-3].minor.yy198, yymsp[-2].minor.yy418, yymsp[-1].minor.yy280); + sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy280); +} +#line 2249 "parse.c" break; + case 91: case 93: -#line 306 "parse.y" -{yygotominor.yy412 = OE_Ignore;} -#line 2206 "parse.c" +#line 337 "parse.y" +{yygotominor.yy280 = OE_Default;} +#line 2255 "parse.c" break; - case 94: - case 164: -#line 307 "parse.y" -{yygotominor.yy412 = OE_Replace;} -#line 2212 "parse.c" + case 96: +#line 342 "parse.y" +{yygotominor.yy280 = OE_Ignore;} +#line 2260 "parse.c" break; - case 95: -#line 311 "parse.y" + case 97: + case 167: +#line 343 "parse.y" +{yygotominor.yy280 = OE_Replace;} +#line 2266 "parse.c" + break; + case 98: +#line 347 "parse.y" { - sqlite3DropTable(pParse, yymsp[0].minor.yy67, 0); + sqlite3DropTable(pParse, yymsp[0].minor.yy151, 0); } -#line 2219 "parse.c" +#line 2273 "parse.c" break; - case 96: -#line 318 "parse.y" + case 99: +#line 354 "parse.y" { - sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy258, &yymsp[-2].minor.yy258, yymsp[0].minor.yy459, yymsp[-5].minor.yy412); + sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy198, &yymsp[-2].minor.yy198, yymsp[0].minor.yy375, yymsp[-5].minor.yy280); } -#line 2226 "parse.c" +#line 2280 "parse.c" break; - case 97: -#line 321 "parse.y" + case 100: +#line 357 "parse.y" { - sqlite3DropTable(pParse, yymsp[0].minor.yy67, 1); + sqlite3DropTable(pParse, yymsp[0].minor.yy151, 1); } -#line 2233 "parse.c" +#line 2287 "parse.c" break; - case 98: -#line 328 "parse.y" + case 101: +#line 364 "parse.y" { - sqlite3Select(pParse, yymsp[0].minor.yy459, SRT_Callback, 0, 0, 0, 0, 0); - sqlite3SelectDelete(yymsp[0].minor.yy459); + sqlite3Select(pParse, yymsp[0].minor.yy375, SRT_Callback, 0, 0, 0, 0, 0); + sqlite3SelectDelete(yymsp[0].minor.yy375); } -#line 2241 "parse.c" +#line 2295 "parse.c" break; - case 99: - case 123: -#line 338 "parse.y" -{yygotominor.yy459 = yymsp[0].minor.yy459;} -#line 2247 "parse.c" + case 102: + case 126: +#line 374 "parse.y" +{yygotominor.yy375 = yymsp[0].minor.yy375;} +#line 2301 "parse.c" break; - case 100: -#line 340 "parse.y" + case 103: +#line 376 "parse.y" { - if( yymsp[0].minor.yy459 ){ - yymsp[0].minor.yy459->op = yymsp[-1].minor.yy412; - yymsp[0].minor.yy459->pPrior = yymsp[-2].minor.yy459; + if( yymsp[0].minor.yy375 ){ + yymsp[0].minor.yy375->op = yymsp[-1].minor.yy280; + yymsp[0].minor.yy375->pPrior = yymsp[-2].minor.yy375; } - yygotominor.yy459 = yymsp[0].minor.yy459; + yygotominor.yy375 = yymsp[0].minor.yy375; } -#line 2258 "parse.c" +#line 2312 "parse.c" break; - case 102: -#line 349 "parse.y" -{yygotominor.yy412 = TK_ALL;} -#line 2263 "parse.c" - break; case 105: -#line 354 "parse.y" +#line 385 "parse.y" +{yygotominor.yy280 = TK_ALL;} +#line 2317 "parse.c" + break; + case 108: +#line 390 "parse.y" { - yygotominor.yy459 = sqlite3SelectNew(yymsp[-6].minor.yy82,yymsp[-5].minor.yy67,yymsp[-4].minor.yy2,yymsp[-3].minor.yy82,yymsp[-2].minor.yy2,yymsp[-1].minor.yy82,yymsp[-7].minor.yy412,yymsp[0].minor.yy244.pLimit,yymsp[0].minor.yy244.pOffset); + yygotominor.yy375 = sqlite3SelectNew(yymsp[-6].minor.yy418,yymsp[-5].minor.yy151,yymsp[-4].minor.yy62,yymsp[-3].minor.yy418,yymsp[-2].minor.yy62,yymsp[-1].minor.yy418,yymsp[-7].minor.yy280,yymsp[0].minor.yy220.pLimit,yymsp[0].minor.yy220.pOffset); } -#line 2270 "parse.c" +#line 2324 "parse.c" break; - case 109: - case 244: -#line 375 "parse.y" -{yygotominor.yy82 = yymsp[-1].minor.yy82;} -#line 2276 "parse.c" + case 112: + case 248: +#line 411 "parse.y" +{yygotominor.yy418 = yymsp[-1].minor.yy418;} +#line 2330 "parse.c" break; - case 110: - case 137: - case 147: - case 243: -#line 376 "parse.y" -{yygotominor.yy82 = 0;} -#line 2284 "parse.c" + case 113: + case 140: + case 150: + case 247: +#line 412 "parse.y" +{yygotominor.yy418 = 0;} +#line 2338 "parse.c" break; - case 111: -#line 377 "parse.y" + case 114: +#line 413 "parse.y" { - yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-2].minor.yy82,yymsp[-1].minor.yy2,yymsp[0].minor.yy258.n?&yymsp[0].minor.yy258:0); + yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-2].minor.yy418,yymsp[-1].minor.yy62,yymsp[0].minor.yy198.n?&yymsp[0].minor.yy198:0); } -#line 2291 "parse.c" +#line 2345 "parse.c" break; - case 112: -#line 380 "parse.y" + case 115: +#line 416 "parse.y" { - yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-1].minor.yy82, sqlite3Expr(TK_ALL, 0, 0, 0), 0); + yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-1].minor.yy418, sqlite3Expr(TK_ALL, 0, 0, 0), 0); } -#line 2298 "parse.c" +#line 2352 "parse.c" break; - case 113: -#line 383 "parse.y" + case 116: +#line 419 "parse.y" { Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0); - Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy258); - yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-3].minor.yy82, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0); + Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198); + yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-3].minor.yy418, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0); } -#line 2307 "parse.c" +#line 2361 "parse.c" break; - case 116: -#line 395 "parse.y" -{yygotominor.yy258.n = 0;} -#line 2312 "parse.c" + case 119: +#line 431 "parse.y" +{yygotominor.yy198.n = 0;} +#line 2366 "parse.c" break; - case 117: -#line 407 "parse.y" -{yygotominor.yy67 = sqliteMalloc(sizeof(*yygotominor.yy67));} -#line 2317 "parse.c" + case 120: +#line 443 "parse.y" +{yygotominor.yy151 = sqliteMalloc(sizeof(*yygotominor.yy151));} +#line 2371 "parse.c" break; - case 118: -#line 408 "parse.y" -{yygotominor.yy67 = yymsp[0].minor.yy67;} -#line 2322 "parse.c" + case 121: +#line 444 "parse.y" +{yygotominor.yy151 = yymsp[0].minor.yy151;} +#line 2376 "parse.c" break; - case 119: -#line 413 "parse.y" + case 122: +#line 449 "parse.y" { - yygotominor.yy67 = yymsp[-1].minor.yy67; - if( yygotominor.yy67 && yygotominor.yy67->nSrc>0 ) yygotominor.yy67->a[yygotominor.yy67->nSrc-1].jointype = yymsp[0].minor.yy412; + yygotominor.yy151 = yymsp[-1].minor.yy151; + if( yygotominor.yy151 && yygotominor.yy151->nSrc>0 ) yygotominor.yy151->a[yygotominor.yy151->nSrc-1].jointype = yymsp[0].minor.yy280; } -#line 2330 "parse.c" +#line 2384 "parse.c" break; - case 120: -#line 417 "parse.y" -{yygotominor.yy67 = 0;} -#line 2335 "parse.c" + case 123: +#line 453 "parse.y" +{yygotominor.yy151 = 0;} +#line 2389 "parse.c" break; - case 121: -#line 418 "parse.y" + case 124: +#line 454 "parse.y" { - yygotominor.yy67 = sqlite3SrcListAppend(yymsp[-5].minor.yy67,&yymsp[-4].minor.yy258,&yymsp[-3].minor.yy258); - if( yymsp[-2].minor.yy258.n ) sqlite3SrcListAddAlias(yygotominor.yy67,&yymsp[-2].minor.yy258); - if( yymsp[-1].minor.yy2 ){ - if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pOn = yymsp[-1].minor.yy2; } - else { sqlite3ExprDelete(yymsp[-1].minor.yy2); } + yygotominor.yy151 = sqlite3SrcListAppend(yymsp[-5].minor.yy151,&yymsp[-4].minor.yy198,&yymsp[-3].minor.yy198); + if( yymsp[-2].minor.yy198.n ) sqlite3SrcListAddAlias(yygotominor.yy151,&yymsp[-2].minor.yy198); + if( yymsp[-1].minor.yy62 ){ + if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pOn = yymsp[-1].minor.yy62; } + else { sqlite3ExprDelete(yymsp[-1].minor.yy62); } } if( yymsp[0].minor.yy240 ){ - if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pUsing = yymsp[0].minor.yy240; } + if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pUsing = yymsp[0].minor.yy240; } else { sqlite3IdListDelete(yymsp[0].minor.yy240); } } } -#line 2351 "parse.c" +#line 2405 "parse.c" break; - case 122: -#line 432 "parse.y" + case 125: +#line 468 "parse.y" { - yygotominor.yy67 = sqlite3SrcListAppend(yymsp[-6].minor.yy67,0,0); - yygotominor.yy67->a[yygotominor.yy67->nSrc-1].pSelect = yymsp[-4].minor.yy459; - if( yymsp[-2].minor.yy258.n ) sqlite3SrcListAddAlias(yygotominor.yy67,&yymsp[-2].minor.yy258); - if( yymsp[-1].minor.yy2 ){ - if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pOn = yymsp[-1].minor.yy2; } - else { sqlite3ExprDelete(yymsp[-1].minor.yy2); } + yygotominor.yy151 = sqlite3SrcListAppend(yymsp[-6].minor.yy151,0,0); + yygotominor.yy151->a[yygotominor.yy151->nSrc-1].pSelect = yymsp[-4].minor.yy375; + if( yymsp[-2].minor.yy198.n ) sqlite3SrcListAddAlias(yygotominor.yy151,&yymsp[-2].minor.yy198); + if( yymsp[-1].minor.yy62 ){ + if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pOn = yymsp[-1].minor.yy62; } + else { sqlite3ExprDelete(yymsp[-1].minor.yy62); } } if( yymsp[0].minor.yy240 ){ - if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pUsing = yymsp[0].minor.yy240; } + if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pUsing = yymsp[0].minor.yy240; } else { sqlite3IdListDelete(yymsp[0].minor.yy240); } } } -#line 2368 "parse.c" +#line 2422 "parse.c" break; - case 124: -#line 453 "parse.y" + case 127: +#line 489 "parse.y" { - yygotominor.yy459 = sqlite3SelectNew(0,yymsp[0].minor.yy67,0,0,0,0,0,0,0); + yygotominor.yy375 = sqlite3SelectNew(0,yymsp[0].minor.yy151,0,0,0,0,0,0,0); } -#line 2375 "parse.c" +#line 2429 "parse.c" break; - case 125: -#line 459 "parse.y" -{yygotominor.yy258.z=0; yygotominor.yy258.n=0;} -#line 2380 "parse.c" - break; - case 127: -#line 464 "parse.y" -{yygotominor.yy67 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258);} -#line 2385 "parse.c" - break; case 128: - case 129: -#line 468 "parse.y" -{ yygotominor.yy412 = JT_INNER; } -#line 2391 "parse.c" +#line 495 "parse.y" +{yygotominor.yy198.z=0; yygotominor.yy198.n=0;} +#line 2434 "parse.c" break; case 130: -#line 470 "parse.y" -{ yygotominor.yy412 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } -#line 2396 "parse.c" +#line 500 "parse.y" +{yygotominor.yy151 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198);} +#line 2439 "parse.c" break; case 131: -#line 471 "parse.y" -{ yygotominor.yy412 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy258,0); } -#line 2401 "parse.c" - break; case 132: -#line 473 "parse.y" -{ yygotominor.yy412 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy258,&yymsp[-1].minor.yy258); } -#line 2406 "parse.c" +#line 504 "parse.y" +{ yygotominor.yy280 = JT_INNER; } +#line 2445 "parse.c" break; case 133: - case 141: - case 150: - case 157: - case 171: - case 207: - case 232: - case 234: - case 238: -#line 477 "parse.y" -{yygotominor.yy2 = yymsp[0].minor.yy2;} -#line 2419 "parse.c" +#line 506 "parse.y" +{ yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } +#line 2450 "parse.c" break; case 134: - case 149: - case 156: - case 208: - case 233: - case 235: - case 239: -#line 478 "parse.y" -{yygotominor.yy2 = 0;} -#line 2430 "parse.c" +#line 507 "parse.y" +{ yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy198,0); } +#line 2455 "parse.c" break; case 135: - case 168: -#line 482 "parse.y" -{yygotominor.yy240 = yymsp[-1].minor.yy240;} -#line 2436 "parse.c" +#line 509 "parse.y" +{ yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy198,&yymsp[-1].minor.yy198); } +#line 2460 "parse.c" break; case 136: - case 167: -#line 483 "parse.y" -{yygotominor.yy240 = 0;} -#line 2442 "parse.c" + case 144: + case 153: + case 160: + case 174: + case 211: + case 236: + case 238: + case 242: +#line 513 "parse.y" +{yygotominor.yy62 = yymsp[0].minor.yy62;} +#line 2473 "parse.c" break; + case 137: + case 152: + case 159: + case 212: + case 237: + case 239: + case 243: +#line 514 "parse.y" +{yygotominor.yy62 = 0;} +#line 2484 "parse.c" + break; case 138: - case 148: -#line 494 "parse.y" -{yygotominor.yy82 = yymsp[0].minor.yy82;} -#line 2448 "parse.c" + case 171: +#line 518 "parse.y" +{yygotominor.yy240 = yymsp[-1].minor.yy240;} +#line 2490 "parse.c" break; case 139: -#line 495 "parse.y" -{ - yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82,yymsp[-2].minor.yy2,yymsp[-1].minor.yy258.n>0?&yymsp[-1].minor.yy258:0); - if( yygotominor.yy82 ) yygotominor.yy82->a[yygotominor.yy82->nExpr-1].sortOrder = yymsp[0].minor.yy412; -} -#line 2456 "parse.c" + case 170: +#line 519 "parse.y" +{yygotominor.yy240 = 0;} +#line 2496 "parse.c" break; - case 140: -#line 499 "parse.y" + case 141: + case 151: +#line 530 "parse.y" +{yygotominor.yy418 = yymsp[0].minor.yy418;} +#line 2502 "parse.c" + break; + case 142: +#line 531 "parse.y" { - yygotominor.yy82 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy2,yymsp[-1].minor.yy258.n>0?&yymsp[-1].minor.yy258:0); - if( yygotominor.yy82 && yygotominor.yy82->a ) yygotominor.yy82->a[0].sortOrder = yymsp[0].minor.yy412; + yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418,yymsp[-2].minor.yy62,yymsp[-1].minor.yy198.n>0?&yymsp[-1].minor.yy198:0); + if( yygotominor.yy418 ) yygotominor.yy418->a[yygotominor.yy418->nExpr-1].sortOrder = yymsp[0].minor.yy280; } -#line 2464 "parse.c" +#line 2510 "parse.c" break; - case 142: - case 144: -#line 508 "parse.y" -{yygotominor.yy412 = SQLITE_SO_ASC;} -#line 2470 "parse.c" - break; case 143: -#line 509 "parse.y" -{yygotominor.yy412 = SQLITE_SO_DESC;} -#line 2475 "parse.c" +#line 535 "parse.y" +{ + yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy62,yymsp[-1].minor.yy198.n>0?&yymsp[-1].minor.yy198:0); + if( yygotominor.yy418 && yygotominor.yy418->a ) yygotominor.yy418->a[0].sortOrder = yymsp[0].minor.yy280; +} +#line 2518 "parse.c" break; case 145: -#line 511 "parse.y" -{yygotominor.yy258.z = 0; yygotominor.yy258.n = 0;} -#line 2480 "parse.c" + case 147: +#line 544 "parse.y" +{yygotominor.yy280 = SQLITE_SO_ASC;} +#line 2524 "parse.c" break; - case 151: -#line 529 "parse.y" -{yygotominor.yy244.pLimit = 0; yygotominor.yy244.pOffset = 0;} -#line 2485 "parse.c" + case 146: +#line 545 "parse.y" +{yygotominor.yy280 = SQLITE_SO_DESC;} +#line 2529 "parse.c" break; - case 152: -#line 530 "parse.y" -{yygotominor.yy244.pLimit = yymsp[0].minor.yy2; yygotominor.yy244.pOffset = 0;} -#line 2490 "parse.c" + case 148: +#line 547 "parse.y" +{yygotominor.yy198.z = 0; yygotominor.yy198.n = 0;} +#line 2534 "parse.c" break; - case 153: -#line 532 "parse.y" -{yygotominor.yy244.pLimit = yymsp[-2].minor.yy2; yygotominor.yy244.pOffset = yymsp[0].minor.yy2;} -#line 2495 "parse.c" - break; case 154: -#line 534 "parse.y" -{yygotominor.yy244.pOffset = yymsp[-2].minor.yy2; yygotominor.yy244.pLimit = yymsp[0].minor.yy2;} -#line 2500 "parse.c" +#line 565 "parse.y" +{yygotominor.yy220.pLimit = 0; yygotominor.yy220.pOffset = 0;} +#line 2539 "parse.c" break; case 155: -#line 538 "parse.y" -{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy67,yymsp[0].minor.yy2);} -#line 2505 "parse.c" +#line 566 "parse.y" +{yygotominor.yy220.pLimit = yymsp[0].minor.yy62; yygotominor.yy220.pOffset = 0;} +#line 2544 "parse.c" break; - case 158: -#line 549 "parse.y" -{sqlite3Update(pParse,yymsp[-3].minor.yy67,yymsp[-1].minor.yy82,yymsp[0].minor.yy2,yymsp[-4].minor.yy412);} -#line 2510 "parse.c" + case 156: +#line 568 "parse.y" +{yygotominor.yy220.pLimit = yymsp[-2].minor.yy62; yygotominor.yy220.pOffset = yymsp[0].minor.yy62;} +#line 2549 "parse.c" break; - case 159: -#line 555 "parse.y" -{yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82,yymsp[0].minor.yy2,&yymsp[-2].minor.yy258);} -#line 2515 "parse.c" + case 157: +#line 570 "parse.y" +{yygotominor.yy220.pOffset = yymsp[-2].minor.yy62; yygotominor.yy220.pLimit = yymsp[0].minor.yy62;} +#line 2554 "parse.c" break; - case 160: -#line 556 "parse.y" -{yygotominor.yy82 = sqlite3ExprListAppend(0,yymsp[0].minor.yy2,&yymsp[-2].minor.yy258);} -#line 2520 "parse.c" + case 158: +#line 574 "parse.y" +{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy151,yymsp[0].minor.yy62);} +#line 2559 "parse.c" break; case 161: -#line 562 "parse.y" -{sqlite3Insert(pParse, yymsp[-5].minor.yy67, yymsp[-1].minor.yy82, 0, yymsp[-4].minor.yy240, yymsp[-7].minor.yy412);} -#line 2525 "parse.c" +#line 585 "parse.y" +{sqlite3Update(pParse,yymsp[-3].minor.yy151,yymsp[-1].minor.yy418,yymsp[0].minor.yy62,yymsp[-4].minor.yy280);} +#line 2564 "parse.c" break; case 162: -#line 564 "parse.y" -{sqlite3Insert(pParse, yymsp[-2].minor.yy67, 0, yymsp[0].minor.yy459, yymsp[-1].minor.yy240, yymsp[-4].minor.yy412);} -#line 2530 "parse.c" +#line 591 "parse.y" +{yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418,yymsp[0].minor.yy62,&yymsp[-2].minor.yy198);} +#line 2569 "parse.c" break; + case 163: +#line 592 "parse.y" +{yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[0].minor.yy62,&yymsp[-2].minor.yy198);} +#line 2574 "parse.c" + break; + case 164: +#line 598 "parse.y" +{sqlite3Insert(pParse, yymsp[-5].minor.yy151, yymsp[-1].minor.yy418, 0, yymsp[-4].minor.yy240, yymsp[-7].minor.yy280);} +#line 2579 "parse.c" + break; case 165: - case 236: -#line 574 "parse.y" -{yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-2].minor.yy82,yymsp[0].minor.yy2,0);} -#line 2536 "parse.c" +#line 600 "parse.y" +{sqlite3Insert(pParse, yymsp[-2].minor.yy151, 0, yymsp[0].minor.yy375, yymsp[-1].minor.yy240, yymsp[-4].minor.yy280);} +#line 2584 "parse.c" break; - case 166: - case 237: -#line 575 "parse.y" -{yygotominor.yy82 = sqlite3ExprListAppend(0,yymsp[0].minor.yy2,0);} -#line 2542 "parse.c" + case 168: + case 240: +#line 610 "parse.y" +{yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-2].minor.yy418,yymsp[0].minor.yy62,0);} +#line 2590 "parse.c" break; case 169: -#line 584 "parse.y" -{yygotominor.yy240 = sqlite3IdListAppend(yymsp[-2].minor.yy240,&yymsp[0].minor.yy258);} -#line 2547 "parse.c" + case 241: +#line 611 "parse.y" +{yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[0].minor.yy62,0);} +#line 2596 "parse.c" break; - case 170: -#line 585 "parse.y" -{yygotominor.yy240 = sqlite3IdListAppend(0,&yymsp[0].minor.yy258);} -#line 2552 "parse.c" - break; case 172: -#line 596 "parse.y" -{yygotominor.yy2 = yymsp[-1].minor.yy2; sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } -#line 2557 "parse.c" +#line 620 "parse.y" +{yygotominor.yy240 = sqlite3IdListAppend(yymsp[-2].minor.yy240,&yymsp[0].minor.yy198);} +#line 2601 "parse.c" break; case 173: - case 178: - case 179: - case 180: - case 181: -#line 597 "parse.y" -{yygotominor.yy2 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} -#line 2566 "parse.c" +#line 621 "parse.y" +{yygotominor.yy240 = sqlite3IdListAppend(0,&yymsp[0].minor.yy198);} +#line 2606 "parse.c" break; - case 174: case 175: -#line 598 "parse.y" -{yygotominor.yy2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} -#line 2572 "parse.c" +#line 632 "parse.y" +{yygotominor.yy62 = yymsp[-1].minor.yy62; sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } +#line 2611 "parse.c" break; case 176: -#line 600 "parse.y" + case 181: + case 182: + case 183: + case 184: +#line 633 "parse.y" +{yygotominor.yy62 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} +#line 2620 "parse.c" + break; + case 177: + case 178: +#line 634 "parse.y" +{yygotominor.yy62 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} +#line 2626 "parse.c" + break; + case 179: +#line 636 "parse.y" { - Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy258); - Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy258); - yygotominor.yy2 = sqlite3Expr(TK_DOT, temp1, temp2, 0); + Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198); + Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy198); + yygotominor.yy62 = sqlite3Expr(TK_DOT, temp1, temp2, 0); } -#line 2581 "parse.c" +#line 2635 "parse.c" break; - case 177: -#line 605 "parse.y" + case 180: +#line 641 "parse.y" { - Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy258); - Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy258); - Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy258); + Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy198); + Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198); + Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy198); Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0); - yygotominor.yy2 = sqlite3Expr(TK_DOT, temp1, temp4, 0); + yygotominor.yy62 = sqlite3Expr(TK_DOT, temp1, temp4, 0); } -#line 2592 "parse.c" +#line 2646 "parse.c" break; - case 182: -#line 616 "parse.y" -{yygotominor.yy2 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} -#line 2597 "parse.c" + case 185: +#line 652 "parse.y" +{yygotominor.yy62 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} +#line 2651 "parse.c" break; - case 183: -#line 617 "parse.y" + case 186: +#line 653 "parse.y" { Token *pToken = &yymsp[0].minor.yy0; - Expr *pExpr = yygotominor.yy2 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); + Expr *pExpr = yygotominor.yy62 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); sqlite3ExprAssignVarNumber(pParse, pExpr); } -#line 2606 "parse.c" +#line 2660 "parse.c" break; - case 184: -#line 622 "parse.y" + case 187: +#line 659 "parse.y" { - yygotominor.yy2 = sqlite3ExprFunction(yymsp[-1].minor.yy82, &yymsp[-3].minor.yy0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_CAST, yymsp[-3].minor.yy62, 0, &yymsp[-1].minor.yy198); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); } -#line 2614 "parse.c" +#line 2668 "parse.c" break; - case 185: -#line 626 "parse.y" + case 188: +#line 664 "parse.y" { - yygotominor.yy2 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3ExprFunction(yymsp[-1].minor.yy418, &yymsp[-4].minor.yy0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); + if( yymsp[-2].minor.yy280 ){ + yygotominor.yy62->flags |= EP_Distinct; + } } -#line 2622 "parse.c" +#line 2679 "parse.c" break; - case 186: -#line 630 "parse.y" + case 189: +#line 671 "parse.y" { + yygotominor.yy62 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); +} +#line 2687 "parse.c" + break; + case 190: +#line 675 "parse.y" +{ /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are ** treated as functions that return constants */ - yygotominor.yy2 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0); - if( yygotominor.yy2 ) yygotominor.yy2->op = TK_CONST_FUNC; + yygotominor.yy62 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0); + if( yygotominor.yy62 ) yygotominor.yy62->op = TK_CONST_FUNC; } -#line 2632 "parse.c" +#line 2697 "parse.c" break; - case 187: - case 188: - case 189: - case 190: case 191: case 192: case 193: @@ -2647,476 +2708,509 @@ case 202: case 203: case 204: -#line 636 "parse.y" -{yygotominor.yy2 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy2, yymsp[0].minor.yy2, 0);} -#line 2654 "parse.c" - break; case 205: -#line 655 "parse.y" -{yygotominor.yy438.operator = yymsp[0].minor.yy0; yygotominor.yy438.not = 0;} -#line 2659 "parse.c" - break; case 206: -#line 656 "parse.y" -{yygotominor.yy438.operator = yymsp[0].minor.yy0; yygotominor.yy438.not = 1;} -#line 2664 "parse.c" + case 207: + case 208: +#line 681 "parse.y" +{yygotominor.yy62 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy62, yymsp[0].minor.yy62, 0);} +#line 2719 "parse.c" break; case 209: -#line 660 "parse.y" +#line 700 "parse.y" +{yygotominor.yy222.operator = yymsp[0].minor.yy0; yygotominor.yy222.not = 0;} +#line 2724 "parse.c" + break; + case 210: +#line 701 "parse.y" +{yygotominor.yy222.operator = yymsp[0].minor.yy0; yygotominor.yy222.not = 1;} +#line 2729 "parse.c" + break; + case 213: +#line 705 "parse.y" { - ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy2, 0); - pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy2, 0); - if( yymsp[0].minor.yy2 ){ - pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy2, 0); + ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy62, 0); + pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy62, 0); + if( yymsp[0].minor.yy62 ){ + pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy62, 0); } - yygotominor.yy2 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy438.operator); - if( yymsp[-2].minor.yy438.not ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2, &yymsp[-3].minor.yy2->span, &yymsp[-1].minor.yy2->span); + yygotominor.yy62 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy222.operator); + if( yymsp[-2].minor.yy222.not ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62, &yymsp[-3].minor.yy62->span, &yymsp[-1].minor.yy62->span); } -#line 2678 "parse.c" +#line 2743 "parse.c" break; - case 210: -#line 671 "parse.y" + case 214: +#line 716 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy2->span,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2686 "parse.c" +#line 2751 "parse.c" break; - case 211: -#line 675 "parse.y" + case 215: +#line 720 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy2->span,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2694 "parse.c" +#line 2759 "parse.c" break; - case 212: -#line 679 "parse.y" + case 216: +#line 724 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy2->span,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2702 "parse.c" +#line 2767 "parse.c" break; - case 213: -#line 683 "parse.y" + case 217: +#line 728 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy2->span,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2710 "parse.c" +#line 2775 "parse.c" break; - case 214: -#line 687 "parse.y" + case 218: +#line 732 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy2->span,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2718 "parse.c" +#line 2783 "parse.c" break; - case 215: - case 216: -#line 691 "parse.y" + case 219: + case 220: +#line 736 "parse.y" { - yygotominor.yy2 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy2->span); + yygotominor.yy62 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span); } -#line 2727 "parse.c" +#line 2792 "parse.c" break; - case 217: -#line 699 "parse.y" + case 221: +#line 744 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy2->span); + yygotominor.yy62 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span); } -#line 2735 "parse.c" +#line 2800 "parse.c" break; - case 218: -#line 703 "parse.y" + case 222: +#line 748 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy2->span); + yygotominor.yy62 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span); } -#line 2743 "parse.c" +#line 2808 "parse.c" break; - case 221: -#line 710 "parse.y" + case 225: +#line 755 "parse.y" { - ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy2, 0); - pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy2, 0); - yygotominor.yy2 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy2, 0, 0); - if( yygotominor.yy2 ) yygotominor.yy2->pList = pList; - if( yymsp[-3].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-4].minor.yy2->span,&yymsp[0].minor.yy2->span); + ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy62, 0); + pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy62, 0); + yygotominor.yy62 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy62, 0, 0); + if( yygotominor.yy62 ){ + yygotominor.yy62->pList = pList; + }else{ + sqlite3ExprListDelete(pList); + } + if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy62->span); } -#line 2755 "parse.c" +#line 2824 "parse.c" break; - case 224: -#line 722 "parse.y" + case 228: +#line 771 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy2, 0, 0); - if( yygotominor.yy2 ){ - yygotominor.yy2->pList = yymsp[-1].minor.yy82; + yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy62, 0, 0); + if( yygotominor.yy62 ){ + yygotominor.yy62->pList = yymsp[-1].minor.yy418; }else{ - sqlite3ExprListDelete(yymsp[-1].minor.yy82); + sqlite3ExprListDelete(yymsp[-1].minor.yy418); } - if( yymsp[-3].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-4].minor.yy2->span,&yymsp[0].minor.yy0); + if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2769 "parse.c" +#line 2838 "parse.c" break; - case 225: -#line 732 "parse.y" + case 229: +#line 781 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_SELECT, 0, 0, 0); - if( yygotominor.yy2 ) yygotominor.yy2->pSelect = yymsp[-1].minor.yy459; - if( !yygotominor.yy2 ) sqlite3SelectDelete(yymsp[-1].minor.yy459); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_SELECT, 0, 0, 0); + if( yygotominor.yy62 ){ + yygotominor.yy62->pSelect = yymsp[-1].minor.yy375; + }else{ + sqlite3SelectDelete(yymsp[-1].minor.yy375); + } + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } -#line 2779 "parse.c" +#line 2851 "parse.c" break; - case 226: -#line 738 "parse.y" + case 230: +#line 790 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy2, 0, 0); - if( yygotominor.yy2 ) yygotominor.yy2->pSelect = yymsp[-1].minor.yy459; - if( !yygotominor.yy2 ) sqlite3SelectDelete(yymsp[-1].minor.yy459); - if( yymsp[-3].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-4].minor.yy2->span,&yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy62, 0, 0); + if( yygotominor.yy62 ){ + yygotominor.yy62->pSelect = yymsp[-1].minor.yy375; + }else{ + sqlite3SelectDelete(yymsp[-1].minor.yy375); + } + if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy0); } -#line 2790 "parse.c" +#line 2865 "parse.c" break; - case 227: -#line 745 "parse.y" + case 231: +#line 800 "parse.y" { - SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258); - yygotominor.yy2 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy2, 0, 0); - if( yygotominor.yy2 ) yygotominor.yy2->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0); - if( yymsp[-2].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0); - sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy2->span,yymsp[0].minor.yy258.z?&yymsp[0].minor.yy258:&yymsp[-1].minor.yy258); + SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198); + yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy62, 0, 0); + if( yygotominor.yy62 ){ + yygotominor.yy62->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0); + }else{ + sqlite3SrcListDelete(pSrc); + } + if( yymsp[-2].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); + sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy62->span,yymsp[0].minor.yy198.z?&yymsp[0].minor.yy198:&yymsp[-1].minor.yy198); } -#line 2801 "parse.c" +#line 2880 "parse.c" break; - case 228: -#line 752 "parse.y" + case 232: +#line 811 "parse.y" { - Expr *p = yygotominor.yy2 = sqlite3Expr(TK_EXISTS, 0, 0, 0); + Expr *p = yygotominor.yy62 = sqlite3Expr(TK_EXISTS, 0, 0, 0); if( p ){ - p->pSelect = yymsp[-1].minor.yy459; + p->pSelect = yymsp[-1].minor.yy375; sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); + }else{ + sqlite3SelectDelete(yymsp[-1].minor.yy375); } - if( !p ) sqlite3SelectDelete(yymsp[-1].minor.yy459); } -#line 2813 "parse.c" +#line 2893 "parse.c" break; - case 229: -#line 763 "parse.y" + case 233: +#line 823 "parse.y" { - yygotominor.yy2 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy2, yymsp[-1].minor.yy2, 0); - if( yygotominor.yy2 ) yygotominor.yy2->pList = yymsp[-2].minor.yy82; - sqlite3ExprSpan(yygotominor.yy2, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy62 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy62, yymsp[-1].minor.yy62, 0); + if( yygotominor.yy62 ){ + yygotominor.yy62->pList = yymsp[-2].minor.yy418; + }else{ + sqlite3ExprListDelete(yymsp[-2].minor.yy418); + } + sqlite3ExprSpan(yygotominor.yy62, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); } -#line 2822 "parse.c" +#line 2906 "parse.c" break; - case 230: -#line 770 "parse.y" + case 234: +#line 834 "parse.y" { - yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82, yymsp[-2].minor.yy2, 0); - yygotominor.yy82 = sqlite3ExprListAppend(yygotominor.yy82, yymsp[0].minor.yy2, 0); + yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418, yymsp[-2].minor.yy62, 0); + yygotominor.yy418 = sqlite3ExprListAppend(yygotominor.yy418, yymsp[0].minor.yy62, 0); } -#line 2830 "parse.c" +#line 2914 "parse.c" break; - case 231: -#line 774 "parse.y" + case 235: +#line 838 "parse.y" { - yygotominor.yy82 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy2, 0); - yygotominor.yy82 = sqlite3ExprListAppend(yygotominor.yy82, yymsp[0].minor.yy2, 0); + yygotominor.yy418 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy62, 0); + yygotominor.yy418 = sqlite3ExprListAppend(yygotominor.yy418, yymsp[0].minor.yy62, 0); } -#line 2838 "parse.c" +#line 2922 "parse.c" break; - case 240: -#line 799 "parse.y" + case 244: +#line 863 "parse.y" { - if( yymsp[-9].minor.yy412!=OE_None ) yymsp[-9].minor.yy412 = yymsp[0].minor.yy412; - if( yymsp[-9].minor.yy412==OE_Default) yymsp[-9].minor.yy412 = OE_Abort; - sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy258, &yymsp[-6].minor.yy258, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy258,0),yymsp[-2].minor.yy82,yymsp[-9].minor.yy412, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0); + if( yymsp[-9].minor.yy280!=OE_None ) yymsp[-9].minor.yy280 = yymsp[0].minor.yy280; + if( yymsp[-9].minor.yy280==OE_Default) yymsp[-9].minor.yy280 = OE_Abort; + sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy198, &yymsp[-6].minor.yy198, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy198,0),yymsp[-2].minor.yy418,yymsp[-9].minor.yy280, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0); } -#line 2847 "parse.c" +#line 2931 "parse.c" break; - case 241: - case 288: -#line 806 "parse.y" -{yygotominor.yy412 = OE_Abort;} -#line 2853 "parse.c" + case 245: + case 292: +#line 870 "parse.y" +{yygotominor.yy280 = OE_Abort;} +#line 2937 "parse.c" break; - case 242: -#line 807 "parse.y" -{yygotominor.yy412 = OE_None;} -#line 2858 "parse.c" + case 246: +#line 871 "parse.y" +{yygotominor.yy280 = OE_None;} +#line 2942 "parse.c" break; - case 245: -#line 817 "parse.y" + case 249: +#line 881 "parse.y" { Expr *p = 0; - if( yymsp[-1].minor.yy258.n>0 ){ + if( yymsp[-1].minor.yy198.n>0 ){ p = sqlite3Expr(TK_COLUMN, 0, 0, 0); - if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy258.z, yymsp[-1].minor.yy258.n); + if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy198.z, yymsp[-1].minor.yy198.n); } - yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82, p, &yymsp[-2].minor.yy258); + yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418, p, &yymsp[-2].minor.yy198); } -#line 2870 "parse.c" +#line 2954 "parse.c" break; - case 246: -#line 825 "parse.y" + case 250: +#line 889 "parse.y" { Expr *p = 0; - if( yymsp[-1].minor.yy258.n>0 ){ + if( yymsp[-1].minor.yy198.n>0 ){ p = sqlite3Expr(TK_COLUMN, 0, 0, 0); - if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy258.z, yymsp[-1].minor.yy258.n); + if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy198.z, yymsp[-1].minor.yy198.n); } - yygotominor.yy82 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy258); + yygotominor.yy418 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy198); } -#line 2882 "parse.c" +#line 2966 "parse.c" break; - case 248: -#line 838 "parse.y" -{sqlite3DropIndex(pParse, yymsp[0].minor.yy67);} -#line 2887 "parse.c" + case 252: +#line 902 "parse.y" +{sqlite3DropIndex(pParse, yymsp[0].minor.yy151);} +#line 2971 "parse.c" break; - case 249: - case 250: -#line 842 "parse.y" + case 253: + case 254: +#line 906 "parse.y" {sqlite3Vacuum(pParse,0);} -#line 2893 "parse.c" +#line 2977 "parse.c" break; - case 251: - case 253: -#line 848 "parse.y" -{sqlite3Pragma(pParse,&yymsp[-3].minor.yy258,&yymsp[-2].minor.yy258,&yymsp[0].minor.yy258,0);} -#line 2899 "parse.c" + case 255: + case 257: +#line 912 "parse.y" +{sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy198,0);} +#line 2983 "parse.c" break; - case 252: -#line 849 "parse.y" -{sqlite3Pragma(pParse,&yymsp[-3].minor.yy258,&yymsp[-2].minor.yy258,&yymsp[0].minor.yy0,0);} -#line 2904 "parse.c" + case 256: +#line 913 "parse.y" +{sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy0,0);} +#line 2988 "parse.c" break; - case 254: -#line 851 "parse.y" + case 258: +#line 915 "parse.y" { - sqlite3Pragma(pParse,&yymsp[-3].minor.yy258,&yymsp[-2].minor.yy258,&yymsp[0].minor.yy258,1); + sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy198,1); } -#line 2911 "parse.c" +#line 2995 "parse.c" break; - case 255: -#line 854 "parse.y" -{sqlite3Pragma(pParse,&yymsp[-4].minor.yy258,&yymsp[-3].minor.yy258,&yymsp[-1].minor.yy258,0);} -#line 2916 "parse.c" + case 259: +#line 918 "parse.y" +{sqlite3Pragma(pParse,&yymsp[-4].minor.yy198,&yymsp[-3].minor.yy198,&yymsp[-1].minor.yy198,0);} +#line 3000 "parse.c" break; - case 256: -#line 855 "parse.y" -{sqlite3Pragma(pParse,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258,0,0);} -#line 2921 "parse.c" + case 260: +#line 919 "parse.y" +{sqlite3Pragma(pParse,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198,0,0);} +#line 3005 "parse.c" break; - case 263: -#line 868 "parse.y" + case 267: +#line 932 "parse.y" { Token all; - all.z = yymsp[-3].minor.yy258.z; - all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy258.z) + yymsp[0].minor.yy0.n; - sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy347, &all); + all.z = yymsp[-3].minor.yy198.z; + all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy198.z) + yymsp[0].minor.yy0.n; + sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy360, &all); } -#line 2931 "parse.c" +#line 3015 "parse.c" break; - case 264: -#line 877 "parse.y" + case 268: +#line 941 "parse.y" { - sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy258, &yymsp[-6].minor.yy258, yymsp[-5].minor.yy412, yymsp[-4].minor.yy210.a, yymsp[-4].minor.yy210.b, yymsp[-2].minor.yy67, yymsp[-1].minor.yy412, yymsp[0].minor.yy2, yymsp[-9].minor.yy412); - yygotominor.yy258 = (yymsp[-6].minor.yy258.n==0?yymsp[-7].minor.yy258:yymsp[-6].minor.yy258); + sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy198, &yymsp[-6].minor.yy198, yymsp[-5].minor.yy280, yymsp[-4].minor.yy30.a, yymsp[-4].minor.yy30.b, yymsp[-2].minor.yy151, yymsp[-1].minor.yy280, yymsp[0].minor.yy62, yymsp[-9].minor.yy280); + yygotominor.yy198 = (yymsp[-6].minor.yy198.n==0?yymsp[-7].minor.yy198:yymsp[-6].minor.yy198); } -#line 2939 "parse.c" +#line 3023 "parse.c" break; - case 265: - case 268: -#line 883 "parse.y" -{ yygotominor.yy412 = TK_BEFORE; } -#line 2945 "parse.c" - break; - case 266: -#line 884 "parse.y" -{ yygotominor.yy412 = TK_AFTER; } -#line 2950 "parse.c" - break; - case 267: -#line 885 "parse.y" -{ yygotominor.yy412 = TK_INSTEAD;} -#line 2955 "parse.c" - break; case 269: + case 272: +#line 947 "parse.y" +{ yygotominor.yy280 = TK_BEFORE; } +#line 3029 "parse.c" + break; case 270: - case 271: -#line 890 "parse.y" -{yygotominor.yy210.a = yymsp[0].major; yygotominor.yy210.b = 0;} -#line 2962 "parse.c" +#line 948 "parse.y" +{ yygotominor.yy280 = TK_AFTER; } +#line 3034 "parse.c" break; - case 272: -#line 893 "parse.y" -{yygotominor.yy210.a = TK_UPDATE; yygotominor.yy210.b = yymsp[0].minor.yy240;} -#line 2967 "parse.c" + case 271: +#line 949 "parse.y" +{ yygotominor.yy280 = TK_INSTEAD;} +#line 3039 "parse.c" break; case 273: case 274: -#line 896 "parse.y" -{ yygotominor.yy412 = TK_ROW; } -#line 2973 "parse.c" - break; case 275: -#line 898 "parse.y" -{ yygotominor.yy412 = TK_STATEMENT; } -#line 2978 "parse.c" +#line 954 "parse.y" +{yygotominor.yy30.a = yymsp[0].major; yygotominor.yy30.b = 0;} +#line 3046 "parse.c" break; case 276: -#line 901 "parse.y" -{ yygotominor.yy2 = 0; } -#line 2983 "parse.c" +#line 957 "parse.y" +{yygotominor.yy30.a = TK_UPDATE; yygotominor.yy30.b = yymsp[0].minor.yy240;} +#line 3051 "parse.c" break; case 277: -#line 902 "parse.y" -{ yygotominor.yy2 = yymsp[0].minor.yy2; } -#line 2988 "parse.c" - break; case 278: -#line 906 "parse.y" -{ - yymsp[-2].minor.yy347->pNext = yymsp[0].minor.yy347; - yygotominor.yy347 = yymsp[-2].minor.yy347; -} -#line 2996 "parse.c" +#line 960 "parse.y" +{ yygotominor.yy280 = TK_ROW; } +#line 3057 "parse.c" break; case 279: -#line 910 "parse.y" -{ yygotominor.yy347 = 0; } -#line 3001 "parse.c" +#line 962 "parse.y" +{ yygotominor.yy280 = TK_STATEMENT; } +#line 3062 "parse.c" break; case 280: -#line 916 "parse.y" -{ yygotominor.yy347 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy258, yymsp[-1].minor.yy82, yymsp[0].minor.yy2, yymsp[-4].minor.yy412); } -#line 3006 "parse.c" +#line 965 "parse.y" +{ yygotominor.yy62 = 0; } +#line 3067 "parse.c" break; case 281: -#line 921 "parse.y" -{yygotominor.yy347 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy258, yymsp[-4].minor.yy240, yymsp[-1].minor.yy82, 0, yymsp[-7].minor.yy412);} -#line 3011 "parse.c" +#line 966 "parse.y" +{ yygotominor.yy62 = yymsp[0].minor.yy62; } +#line 3072 "parse.c" break; case 282: -#line 924 "parse.y" -{yygotominor.yy347 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy258, yymsp[-1].minor.yy240, 0, yymsp[0].minor.yy459, yymsp[-4].minor.yy412);} -#line 3016 "parse.c" +#line 970 "parse.y" +{ + yymsp[-2].minor.yy360->pNext = yymsp[0].minor.yy360; + yygotominor.yy360 = yymsp[-2].minor.yy360; +} +#line 3080 "parse.c" break; case 283: -#line 928 "parse.y" -{yygotominor.yy347 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy258, yymsp[0].minor.yy2);} -#line 3021 "parse.c" +#line 974 "parse.y" +{ yygotominor.yy360 = 0; } +#line 3085 "parse.c" break; case 284: -#line 931 "parse.y" -{yygotominor.yy347 = sqlite3TriggerSelectStep(yymsp[0].minor.yy459); } -#line 3026 "parse.c" +#line 980 "parse.y" +{ yygotominor.yy360 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy198, yymsp[-1].minor.yy418, yymsp[0].minor.yy62, yymsp[-4].minor.yy280); } +#line 3090 "parse.c" break; case 285: -#line 934 "parse.y" -{ - yygotominor.yy2 = sqlite3Expr(TK_RAISE, 0, 0, 0); - yygotominor.yy2->iColumn = OE_Ignore; - sqlite3ExprSpan(yygotominor.yy2, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); -} -#line 3035 "parse.c" +#line 985 "parse.y" +{yygotominor.yy360 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy198, yymsp[-4].minor.yy240, yymsp[-1].minor.yy418, 0, yymsp[-7].minor.yy280);} +#line 3095 "parse.c" break; case 286: -#line 939 "parse.y" -{ - yygotominor.yy2 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy258); - yygotominor.yy2->iColumn = yymsp[-3].minor.yy412; - sqlite3ExprSpan(yygotominor.yy2, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); -} -#line 3044 "parse.c" +#line 988 "parse.y" +{yygotominor.yy360 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy198, yymsp[-1].minor.yy240, 0, yymsp[0].minor.yy375, yymsp[-4].minor.yy280);} +#line 3100 "parse.c" break; case 287: -#line 947 "parse.y" -{yygotominor.yy412 = OE_Rollback;} -#line 3049 "parse.c" +#line 992 "parse.y" +{yygotominor.yy360 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy198, yymsp[0].minor.yy62);} +#line 3105 "parse.c" break; + case 288: +#line 995 "parse.y" +{yygotominor.yy360 = sqlite3TriggerSelectStep(yymsp[0].minor.yy375); } +#line 3110 "parse.c" + break; case 289: -#line 949 "parse.y" -{yygotominor.yy412 = OE_Fail;} -#line 3054 "parse.c" +#line 998 "parse.y" +{ + yygotominor.yy62 = sqlite3Expr(TK_RAISE, 0, 0, 0); + yygotominor.yy62->iColumn = OE_Ignore; + sqlite3ExprSpan(yygotominor.yy62, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); +} +#line 3119 "parse.c" break; case 290: -#line 954 "parse.y" +#line 1003 "parse.y" { - sqlite3DropTrigger(pParse,yymsp[0].minor.yy67); + yygotominor.yy62 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy198); + yygotominor.yy62->iColumn = yymsp[-3].minor.yy280; + sqlite3ExprSpan(yygotominor.yy62, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } -#line 3061 "parse.c" +#line 3128 "parse.c" break; case 291: -#line 960 "parse.y" +#line 1011 "parse.y" +{yygotominor.yy280 = OE_Rollback;} +#line 3133 "parse.c" + break; + case 293: +#line 1013 "parse.y" +{yygotominor.yy280 = OE_Fail;} +#line 3138 "parse.c" + break; + case 294: +#line 1018 "parse.y" { - sqlite3Attach(pParse, &yymsp[-3].minor.yy258, &yymsp[-1].minor.yy258, yymsp[0].minor.yy132.type, &yymsp[0].minor.yy132.key); + sqlite3DropTrigger(pParse,yymsp[0].minor.yy151); } -#line 3068 "parse.c" +#line 3145 "parse.c" break; - case 292: -#line 964 "parse.y" -{ yygotominor.yy132.type = 0; } -#line 3073 "parse.c" + case 295: +#line 1024 "parse.y" +{ + sqlite3Attach(pParse, &yymsp[-3].minor.yy198, &yymsp[-1].minor.yy198, yymsp[0].minor.yy361.type, &yymsp[0].minor.yy361.key); +} +#line 3152 "parse.c" break; - case 293: -#line 965 "parse.y" -{ yygotominor.yy132.type=1; yygotominor.yy132.key = yymsp[0].minor.yy258; } -#line 3078 "parse.c" + case 296: +#line 1028 "parse.y" +{ yygotominor.yy361.type = 0; } +#line 3157 "parse.c" break; - case 294: -#line 966 "parse.y" -{ yygotominor.yy132.type=2; yygotominor.yy132.key = yymsp[0].minor.yy0; } -#line 3083 "parse.c" - break; case 297: -#line 972 "parse.y" +#line 1029 "parse.y" +{ yygotominor.yy361.type=1; yygotominor.yy361.key = yymsp[0].minor.yy198; } +#line 3162 "parse.c" + break; + case 298: +#line 1030 "parse.y" +{ yygotominor.yy361.type=2; yygotominor.yy361.key = yymsp[0].minor.yy0; } +#line 3167 "parse.c" + break; + case 301: +#line 1036 "parse.y" { - sqlite3Detach(pParse, &yymsp[0].minor.yy258); + sqlite3Detach(pParse, &yymsp[0].minor.yy198); } -#line 3090 "parse.c" +#line 3174 "parse.c" break; - case 298: -#line 978 "parse.y" + case 302: +#line 1042 "parse.y" {sqlite3Reindex(pParse, 0, 0);} -#line 3095 "parse.c" +#line 3179 "parse.c" break; - case 299: -#line 979 "parse.y" -{sqlite3Reindex(pParse, &yymsp[-1].minor.yy258, &yymsp[0].minor.yy258);} -#line 3100 "parse.c" + case 303: +#line 1043 "parse.y" +{sqlite3Reindex(pParse, &yymsp[-1].minor.yy198, &yymsp[0].minor.yy198);} +#line 3184 "parse.c" break; - case 300: -#line 984 "parse.y" + case 304: +#line 1048 "parse.y" +{sqlite3Analyze(pParse, 0, 0);} +#line 3189 "parse.c" + break; + case 305: +#line 1049 "parse.y" +{sqlite3Analyze(pParse, &yymsp[-1].minor.yy198, &yymsp[0].minor.yy198);} +#line 3194 "parse.c" + break; + case 306: +#line 1054 "parse.y" { - sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy67,&yymsp[0].minor.yy258); + sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy151,&yymsp[0].minor.yy198); } -#line 3107 "parse.c" +#line 3201 "parse.c" break; - case 301: -#line 987 "parse.y" + case 307: +#line 1057 "parse.y" { - sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy258); + sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy198); } -#line 3114 "parse.c" +#line 3208 "parse.c" break; - case 302: -#line 990 "parse.y" + case 308: +#line 1060 "parse.y" { - sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy67); + sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy151); } -#line 3121 "parse.c" +#line 3215 "parse.c" break; }; yygoto = yyRuleInfo[yyruleno].lhs; @@ -3173,7 +3267,7 @@ ){ sqlite3ParserARG_FETCH; #define TOKEN (yyminor.yy0) -#line 23 "parse.y" +#line 34 "parse.y" if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ @@ -3182,7 +3276,7 @@ sqlite3ErrorMsg(pParse, "incomplete SQL statement"); } } -#line 3188 "parse.c" +#line 3282 "parse.c" sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } ======================================================================== --- sqlite/parse.h 55c238b9c97ae9a71722f2fabf3e0d23660e4e63 +++ sqlite/parse.h c3a865a73a9e4988142a3008f99d3cc91fdf77b4 @@ -6,135 +6,140 @@ #define TK_FUNCTION 6 #define TK_COLUMN 7 #define TK_AGG_FUNCTION 8 +#define TK_AGG_COLUMN 9 +#define TK_CONST_FUNC 10 +#define TK_SEMI 11 +#define TK_EXPLAIN 12 +#define TK_QUERY 13 +#define TK_PLAN 14 +#define TK_BEGIN 15 +#define TK_TRANSACTION 16 +#define TK_DEFERRED 17 +#define TK_IMMEDIATE 18 +#define TK_EXCLUSIVE 19 +#define TK_COMMIT 20 +#define TK_END 21 +#define TK_ROLLBACK 22 +#define TK_CREATE 23 +#define TK_TABLE 24 +#define TK_TEMP 25 +#define TK_LP 26 +#define TK_RP 27 +#define TK_AS 28 +#define TK_COMMA 29 +#define TK_ID 30 +#define TK_ABORT 31 +#define TK_AFTER 32 +#define TK_ANALYZE 33 +#define TK_ASC 34 +#define TK_ATTACH 35 +#define TK_BEFORE 36 +#define TK_CASCADE 37 +#define TK_CAST 38 +#define TK_CONFLICT 39 +#define TK_DATABASE 40 +#define TK_DESC 41 +#define TK_DETACH 42 +#define TK_EACH 43 +#define TK_FAIL 44 +#define TK_FOR 45 +#define TK_IGNORE 46 +#define TK_INITIALLY 47 +#define TK_INSTEAD 48 +#define TK_LIKE_KW 49 +#define TK_MATCH 50 +#define TK_KEY 51 +#define TK_OF 52 +#define TK_OFFSET 53 +#define TK_PRAGMA 54 +#define TK_RAISE 55 +#define TK_REPLACE 56 +#define TK_RESTRICT 57 +#define TK_ROW 58 +#define TK_STATEMENT 59 +#define TK_TRIGGER 60 +#define TK_VACUUM 61 +#define TK_VIEW 62 +#define TK_REINDEX 63 +#define TK_RENAME 64 +#define TK_CTIME_KW 65 +#define TK_ALTER 66 +#define TK_OR 67 +#define TK_AND 68 +#define TK_NOT 69 +#define TK_IS 70 +#define TK_BETWEEN 71 +#define TK_IN 72 +#define TK_ISNULL 73 +#define TK_NOTNULL 74 +#define TK_NE 75 +#define TK_EQ 76 +#define TK_GT 77 +#define TK_LE 78 +#define TK_LT 79 +#define TK_GE 80 +#define TK_ESCAPE 81 +#define TK_BITAND 82 +#define TK_BITOR 83 +#define TK_LSHIFT 84 +#define TK_RSHIFT 85 +#define TK_PLUS 86 +#define TK_MINUS 87 +#define TK_STAR 88 +#define TK_SLASH 89 +#define TK_REM 90 +#define TK_CONCAT 91 +#define TK_UMINUS 92 +#define TK_UPLUS 93 +#define TK_BITNOT 94 +#define TK_STRING 95 +#define TK_JOIN_KW 96 +#define TK_CONSTRAINT 97 +#define TK_DEFAULT 98 +#define TK_NULL 99 +#define TK_PRIMARY 100 +#define TK_UNIQUE 101 +#define TK_CHECK 102 +#define TK_REFERENCES 103 +#define TK_COLLATE 104 +#define TK_AUTOINCR 105 +#define TK_ON 106 +#define TK_DELETE 107 +#define TK_UPDATE 108 +#define TK_INSERT 109 +#define TK_SET 110 +#define TK_DEFERRABLE 111 +#define TK_FOREIGN 112 +#define TK_DROP 113 +#define TK_UNION 114 +#define TK_ALL 115 +#define TK_INTERSECT 116 +#define TK_EXCEPT 117 +#define TK_SELECT 118 +#define TK_DISTINCT 119 +#define TK_DOT 120 +#define TK_FROM 121 +#define TK_JOIN 122 +#define TK_USING 123 +#define TK_ORDER 124 +#define TK_BY 125 +#define TK_GROUP 126 +#define TK_HAVING 127 +#define TK_LIMIT 128 +#define TK_WHERE 129 +#define TK_INTO 130 +#define TK_VALUES 131 +#define TK_INTEGER 132 +#define TK_FLOAT 133 +#define TK_BLOB 134 +#define TK_REGISTER 135 +#define TK_VARIABLE 136 +#define TK_EXISTS 137 +#define TK_CASE 138 +#define TK_WHEN 139 +#define TK_THEN 140 +#define TK_ELSE 141 +#define TK_INDEX 142 +#define TK_TO 143 +#define TK_ADD 144 +#define TK_COLUMNKW 145 -#define TK_CONST_FUNC 9 -#define TK_SEMI 10 -#define TK_EXPLAIN 11 -#define TK_BEGIN 12 -#define TK_TRANSACTION 13 -#define TK_DEFERRED 14 -#define TK_IMMEDIATE 15 -#define TK_EXCLUSIVE 16 -#define TK_COMMIT 17 -#define TK_END 18 -#define TK_ROLLBACK 19 -#define TK_CREATE 20 -#define TK_TABLE 21 -#define TK_TEMP 22 -#define TK_LP 23 -#define TK_RP 24 -#define TK_AS 25 -#define TK_COMMA 26 -#define TK_ID 27 -#define TK_ABORT 28 -#define TK_AFTER 29 -#define TK_ASC 30 -#define TK_ATTACH 31 -#define TK_BEFORE 32 -#define TK_CASCADE 33 -#define TK_CONFLICT 34 -#define TK_DATABASE 35 -#define TK_DESC 36 -#define TK_DETACH 37 -#define TK_EACH 38 -#define TK_FAIL 39 -#define TK_FOR 40 -#define TK_IGNORE 41 -#define TK_INITIALLY 42 -#define TK_INSTEAD 43 -#define TK_LIKE_KW 44 -#define TK_MATCH 45 -#define TK_KEY 46 -#define TK_OF 47 -#define TK_OFFSET 48 -#define TK_PRAGMA 49 -#define TK_RAISE 50 -#define TK_REPLACE 51 -#define TK_RESTRICT 52 -#define TK_ROW 53 -#define TK_STATEMENT 54 -#define TK_TRIGGER 55 -#define TK_VACUUM 56 -#define TK_VIEW 57 -#define TK_REINDEX 58 -#define TK_RENAME 59 -#define TK_CTIME_KW 60 -#define TK_ALTER 61 -#define TK_OR 62 -#define TK_AND 63 -#define TK_NOT 64 -#define TK_IS 65 -#define TK_BETWEEN 66 -#define TK_IN 67 -#define TK_ISNULL 68 -#define TK_NOTNULL 69 -#define TK_NE 70 -#define TK_EQ 71 -#define TK_GT 72 -#define TK_LE 73 -#define TK_LT 74 -#define TK_GE 75 -#define TK_ESCAPE 76 -#define TK_BITAND 77 -#define TK_BITOR 78 -#define TK_LSHIFT 79 -#define TK_RSHIFT 80 -#define TK_PLUS 81 -#define TK_MINUS 82 -#define TK_STAR 83 -#define TK_SLASH 84 -#define TK_REM 85 -#define TK_CONCAT 86 -#define TK_UMINUS 87 -#define TK_UPLUS 88 -#define TK_BITNOT 89 -#define TK_STRING 90 -#define TK_JOIN_KW 91 -#define TK_CONSTRAINT 92 -#define TK_DEFAULT 93 -#define TK_NULL 94 -#define TK_PRIMARY 95 -#define TK_UNIQUE 96 -#define TK_CHECK 97 -#define TK_REFERENCES 98 -#define TK_COLLATE 99 -#define TK_AUTOINCR 100 -#define TK_ON 101 -#define TK_DELETE 102 -#define TK_UPDATE 103 -#define TK_INSERT 104 -#define TK_SET 105 -#define TK_DEFERRABLE 106 -#define TK_FOREIGN 107 -#define TK_DROP 108 -#define TK_UNION 109 -#define TK_ALL 110 -#define TK_INTERSECT 111 -#define TK_EXCEPT 112 -#define TK_SELECT 113 -#define TK_DISTINCT 114 -#define TK_DOT 115 -#define TK_FROM 116 -#define TK_JOIN 117 -#define TK_USING 118 -#define TK_ORDER 119 -#define TK_BY 120 -#define TK_GROUP 121 -#define TK_HAVING 122 -#define TK_LIMIT 123 -#define TK_WHERE 124 -#define TK_INTO 125 -#define TK_VALUES 126 -#define TK_INTEGER 127 -#define TK_FLOAT 128 -#define TK_BLOB 129 -#define TK_REGISTER 130 -#define TK_VARIABLE 131 -#define TK_EXISTS 132 -#define TK_CASE 133 -#define TK_WHEN 134 -#define TK_THEN 135 -#define TK_ELSE 136 -#define TK_INDEX 137 -#define TK_TO 138 -#define TK_ADD 139 -#define TK_COLUMNKW 140 ======================================================================== --- sqlite/pragma.c 5ea2ba0e43f6a83968a936b071b77bd4516d11f0 +++ sqlite/pragma.c 6d773e25e8af13ef0820531ad2793417f8a8959d @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the PRAGMA command. ** -** $Id: pragma.c,v 1.95 2005/06/12 21:35:52 drh Exp $ +** $Id: pragma.c,v 1.99 2005/09/17 16:36:56 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -583,12 +583,13 @@ while(pFK){ int j; for(j=0; jnCol; j++){ + char *zCol = pFK->aCol[j].zCol; sqlite3VdbeAddOp(v, OP_Integer, i, 0); sqlite3VdbeAddOp(v, OP_Integer, j, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[pFK->aCol[j].iFrom].zName, 0); - sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->aCol[j].zCol, 0); + sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0); sqlite3VdbeAddOp(v, OP_Callback, 5, 0); } ++i; @@ -602,14 +603,25 @@ #ifndef NDEBUG if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ extern void sqlite3ParserTrace(FILE*, char *); - if( getBoolean(zRight) ){ - sqlite3ParserTrace(stdout, "parser: "); - }else{ - sqlite3ParserTrace(0, 0); + if( zRight ){ + if( getBoolean(zRight) ){ + sqlite3ParserTrace(stderr, "parser: "); + }else{ + sqlite3ParserTrace(0, 0); + } } }else #endif + /* Reinstall the LIKE and GLOB functions. The variant of LIKE + ** used will be case sensitive or not depending on the RHS. + */ + if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ + if( zRight ){ + sqlite3RegisterLikeFunctions(db, getBoolean(zRight)); + } + }else + #ifndef SQLITE_OMIT_INTEGRITY_CHECK if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){ int i, j, addr; @@ -891,13 +903,13 @@ Btree *pBt; Pager *pPager; if( db->aDb[i].zName==0 ) continue; - sqlite3VdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, P3_STATIC); + sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC); pBt = db->aDb[i].pBt; if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ - sqlite3VdbeOp3(v, OP_String, 0, 0, "closed", P3_STATIC); + sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC); }else{ int j = sqlite3pager_lockstate(pPager); - sqlite3VdbeOp3(v, OP_String, 0, 0, + sqlite3VdbeOp3(v, OP_String8, 0, 0, (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC); } sqlite3VdbeAddOp(v, OP_Callback, 2, 0); ======================================================================== --- sqlite/prepare.c d53602d2f8e097225ae7c76ec764ae68f759ba47 +++ sqlite/prepare.c fc098db25d2a121affb08686cf04833fd50452d4 @@ -13,7 +13,7 @@ ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.1 2005/05/25 04:11:56 danielk1977 Exp $ +** $Id: prepare.c,v 1.4 2005/09/10 16:46:13 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -294,6 +294,11 @@ rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); sqlite3SafetyOn(db); sqliteFree(zSql); +#ifndef SQLITE_OMIT_ANALYZE + if( rc==SQLITE_OK ){ + sqlite3AnalysisLoad(db, iDb); + } +#endif sqlite3BtreeCloseCursor(curMain); } if( sqlite3_malloc_failed ){ @@ -370,7 +375,7 @@ rc = sqlite3Init(db, &pParse->zErrMsg); } } - assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized)||db->init.busy ); + assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy ); if( rc!=SQLITE_OK ){ pParse->rc = rc; pParse->nErr++; @@ -453,12 +458,19 @@ #ifndef SQLITE_OMIT_EXPLAIN if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){ - sqlite3VdbeSetNumCols(sParse.pVdbe, 5); - sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC); - sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC); - sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC); - sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC); - sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC); + if( sParse.explain==2 ){ + sqlite3VdbeSetNumCols(sParse.pVdbe, 3); + sqlite3VdbeSetColName(sParse.pVdbe, 0, "order", P3_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 1, "from", P3_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 2, "detail", P3_STATIC); + }else{ + sqlite3VdbeSetNumCols(sParse.pVdbe, 5); + sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC); + } } #endif @@ -526,4 +538,3 @@ return rc; } #endif /* SQLITE_OMIT_UTF16 */ - ======================================================================== --- sqlite/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357 +++ sqlite/printf.c bd421c1ad5e01013c89af63c60eab02852ccd15e @@ -111,6 +111,7 @@ static const et_info fmtinfo[] = { { 'd', 10, 1, etRADIX, 0, 0 }, { 's', 0, 4, etSTRING, 0, 0 }, + { 'g', 0, 1, etGENERIC, 30, 0 }, { 'z', 0, 6, etDYNSTRING, 0, 0 }, { 'q', 0, 4, etSQLESCAPE, 0, 0 }, { 'Q', 0, 4, etSQLESCAPE2, 0, 0 }, @@ -122,7 +123,6 @@ { 'f', 0, 1, etFLOAT, 0, 0 }, { 'e', 0, 1, etEXP, 30, 0 }, { 'E', 0, 1, etEXP, 14, 0 }, - { 'g', 0, 1, etGENERIC, 30, 0 }, { 'G', 0, 1, etGENERIC, 14, 0 }, { 'i', 10, 1, etRADIX, 0, 0 }, { 'n', 0, 0, etSIZE, 0, 0 }, @@ -163,7 +163,15 @@ } #endif -#define etBUFSIZE 1000 /* Size of the output buffer */ +/* +** On machines with a small stack size, you can redefine the +** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for +** smaller values some %f conversions may go into an infinite loop. +*/ +#ifndef SQLITE_PRINT_BUF_SIZE +# define SQLITE_PRINT_BUF_SIZE 350 +#endif +#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */ /* ** The root program. All variations call this core. @@ -210,9 +218,11 @@ 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_altform2; /* 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 */ etByte flag_longlong; /* True if the "ll" flag is present */ + etByte done; /* Loop termination flag */ UINT64_TYPE longvalue; /* Value for integer types */ LONGDOUBLE_TYPE realvalue; /* Value for real types */ const et_info *infop; /* Pointer to the appropriate info structure */ @@ -225,7 +235,7 @@ " "; #define etSPACESIZE (sizeof(spaces)-1) #ifndef etNOFLOATINGPOINT - int exp; /* exponent of real numbers */ + int exp, e2; /* 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 */ @@ -254,17 +264,19 @@ } /* Find out what flags are present */ flag_leftjustify = flag_plussign = flag_blanksign = - flag_alternateform = flag_zeropad = 0; + flag_alternateform = flag_altform2 = flag_zeropad = 0; + done = 0; do{ switch( c ){ - case '-': flag_leftjustify = 1; c = 0; break; - case '+': flag_plussign = 1; c = 0; break; - case ' ': flag_blanksign = 1; c = 0; break; - case '#': flag_alternateform = 1; c = 0; break; - case '0': flag_zeropad = 1; c = 0; break; - default: break; + case '-': flag_leftjustify = 1; break; + case '+': flag_plussign = 1; break; + case ' ': flag_blanksign = 1; break; + case '#': flag_alternateform = 1; break; + case '!': flag_altform2 = 1; break; + case '0': flag_zeropad = 1; break; + default: done = 1; break; } - }while( c==0 && (c=(*++fmt))!=0 ); + }while( !done && (c=(*++fmt))!=0 ); /* Get the field width */ width = 0; if( c=='*' ){ @@ -336,6 +348,7 @@ ** At this point, variables are initialized as follows: ** ** flag_alternateform TRUE if a '#' is present. + ** flag_altform2 TRUE if a '!' is present. ** flag_plussign TRUE if a '+' is present. ** flag_leftjustify TRUE if a '-' is present or if the ** field width was negative. @@ -414,7 +427,7 @@ realvalue = va_arg(ap,double); #ifndef etNOFLOATINGPOINT if( precision<0 ) precision = 6; /* Set default precision */ - if( precision>etBUFSIZE-10 ) precision = etBUFSIZE-10; + if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10; if( realvalue<0.0 ){ realvalue = -realvalue; prefix = '-'; @@ -423,8 +436,7 @@ else if( flag_blanksign ) prefix = ' '; else prefix = 0; } - if( infop->type==etGENERIC && precision>0 ) precision--; - rounder = 0.0; + if( xtype==etGENERIC && precision>0 ) precision--; #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); @@ -432,10 +444,11 @@ /* It makes more sense to use 0.5 */ for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1); #endif - if( infop->type==etFLOAT ) realvalue += rounder; + if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ exp = 0; if( realvalue>0.0 ){ + while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; } 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; } @@ -467,51 +480,67 @@ }else{ flag_rtz = 0; } - /* - ** The "exp+precision" test causes output to be of type etEXP if - ** the precision is too large to fit in buf[]. - */ + if( xtype==etEXP ){ + e2 = 0; + }else{ + e2 = exp; + } nsd = 0; - if( xtype==etFLOAT && exp+precision0 || flag_alternateform); - if( prefix ) *(bufpt++) = prefix; /* Sign */ - if( exp<0 ) *(bufpt++) = '0'; /* Digits before "." */ - else for(; exp>=0; exp--) *(bufpt++) = et_getdigit(&realvalue,&nsd); - if( flag_dp ) *(bufpt++) = '.'; /* The decimal point */ - for(exp++; exp<0 && precision>0; precision--, exp++){ - *(bufpt++) = '0'; + flag_dp = (precision>0) | flag_alternateform | flag_altform2; + /* The sign in front of the number */ + if( prefix ){ + *(bufpt++) = prefix; + } + /* Digits prior to the decimal point */ + if( e2<0 ){ + *(bufpt++) = '0'; + }else{ + for(; e2>=0; e2--){ + *(bufpt++) = et_getdigit(&realvalue,&nsd); } - while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd); - *(bufpt--) = 0; /* Null terminate */ - if( flag_rtz && flag_dp ){ /* Remove trailing zeros and "." */ - while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0; - if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0; + } + /* The decimal point */ + if( flag_dp ){ + *(bufpt++) = '.'; + } + /* "0" digits after the decimal point but before the first + ** significant digit of the number */ + for(e2++; e2<0 && precision>0; precision--, e2++){ + *(bufpt++) = '0'; + } + /* Significant digits after the decimal point */ + while( (precision--)>0 ){ + *(bufpt++) = et_getdigit(&realvalue,&nsd); + } + /* Remove trailing zeros and the "." if no digits follow the "." */ + if( flag_rtz && flag_dp ){ + while( bufpt[-1]=='0' ) *(--bufpt) = 0; + assert( bufpt>buf ); + if( bufpt[-1]=='.' ){ + if( flag_altform2 ){ + *(bufpt++) = '0'; + }else{ + *(--bufpt) = 0; + } } - bufpt++; /* point to next free slot */ - }else{ /* etEXP or etGENERIC */ - flag_dp = (precision>0 || flag_alternateform); - if( prefix ) *(bufpt++) = prefix; /* Sign */ - *(bufpt++) = et_getdigit(&realvalue,&nsd); /* First digit */ - if( flag_dp ) *(bufpt++) = '.'; /* Decimal point */ - while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd); - bufpt--; /* point to last digit */ - if( flag_rtz && flag_dp ){ /* Remove tail zeros */ - while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0; - if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0; + } + /* Add the "eNNN" suffix */ + if( flag_exp || (xtype==etEXP && exp) ){ + *(bufpt++) = aDigits[infop->charset]; + if( exp<0 ){ + *(bufpt++) = '-'; exp = -exp; + }else{ + *(bufpt++) = '+'; } - bufpt++; /* point to next free slot */ - if( exp || flag_exp ){ - *(bufpt++) = aDigits[infop->charset]; - if( exp<0 ){ *(bufpt++) = '-'; exp = -exp; } /* sign of exp */ - else { *(bufpt++) = '+'; } - if( exp>=100 ){ - *(bufpt++) = (exp/100)+'0'; /* 100's digit */ - exp %= 100; - } - *(bufpt++) = exp/10+'0'; /* 10's digit */ - *(bufpt++) = exp%10+'0'; /* 1's digit */ + if( exp>=100 ){ + *(bufpt++) = (exp/100)+'0'; /* 100's digit */ + exp %= 100; } + *(bufpt++) = exp/10+'0'; /* 10's digit */ + *(bufpt++) = exp%10+'0'; /* 1's digit */ } + *bufpt = 0; + /* The converted number is in buf[] and zero terminated. Output it. ** Note that the number is in the usual order, not reversed as with ** integer conversions. */ @@ -564,36 +593,35 @@ if( precision>=0 && precisionetBUFSIZE ){ - bufpt = zExtra = sqliteMalloc( n ); - if( bufpt==0 ) return -1; - }else{ - bufpt = buf; - } - j = 0; - if( needQuote ) bufpt[j++] = '\''; - for(i=0; (c=arg[i])!=0; i++){ - bufpt[j++] = c; - if( c=='\'' ) bufpt[j++] = c; - } - if( needQuote ) bufpt[j++] = '\''; - bufpt[j] = 0; - length = j; - if( precision>=0 && precisionetBUFSIZE ){ + bufpt = zExtra = sqliteMalloc( n ); + if( bufpt==0 ) return -1; + }else{ + bufpt = buf; + } + j = 0; + if( needQuote ) bufpt[j++] = '\''; + for(i=0; (c=arg[i])!=0; i++){ + bufpt[j++] = c; + if( c=='\'' ) bufpt[j++] = c; + } + if( needQuote ) bufpt[j++] = '\''; + bufpt[j] = 0; + length = j; + if( precision>=0 && precisionz ){ @@ -698,7 +726,11 @@ memcpy(pM->zText, pM->zBase, pM->nChar); } }else{ - pM->zText = pM->xRealloc(pM->zText, pM->nAlloc); + char *zNew; + zNew = pM->xRealloc(pM->zText, pM->nAlloc); + if( zNew ){ + pM->zText = zNew; + } } } } @@ -736,7 +768,10 @@ memcpy(sM.zText, sM.zBase, sM.nChar+1); } }else if( sM.nAlloc>sM.nChar+10 ){ - sM.zText = xRealloc(sM.zText, sM.nChar+1); + char *zNew = xRealloc(sM.zText, sM.nChar+1); + if( zNew ){ + sM.zText = zNew; + } } } return sM.zText; @@ -754,7 +789,7 @@ ** %-conversion extensions. */ char *sqlite3VMPrintf(const char *zFormat, va_list ap){ - char zBase[1000]; + char zBase[SQLITE_PRINT_BUF_SIZE]; return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap); } @@ -765,7 +800,7 @@ char *sqlite3MPrintf(const char *zFormat, ...){ va_list ap; char *z; - char zBase[1000]; + char zBase[SQLITE_PRINT_BUF_SIZE]; va_start(ap, zFormat); z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap); va_end(ap); ======================================================================== --- sqlite/select.c 28b752e58955c7920711fbdbfdcd369a2bd09448 +++ sqlite/select.c 9ef1dddd436e1ea86a6bf64ae0ed71bf4a0b894f @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.252 2005/06/12 21:35:52 drh Exp $ +** $Id: select.c,v 1.269 2005/09/12 23:03:17 drh Exp $ */ #include "sqliteInt.h" @@ -60,6 +60,9 @@ pNew->pOffset = pOffset; pNew->iLimit = -1; pNew->iOffset = -1; + pNew->addrOpenVirt[0] = -1; + pNew->addrOpenVirt[1] = -1; + pNew->addrOpenVirt[2] = -1; } return pNew; } @@ -70,6 +73,7 @@ ** in terms of the following bit values: ** ** JT_INNER +** JT_CROSS ** JT_OUTER ** JT_NATURAL ** JT_LEFT @@ -85,7 +89,7 @@ Token *apAll[3]; Token *p; static const struct { - const char *zKeyword; + const char zKeyword[8]; u8 nChar; u8 code; } keywords[] = { @@ -95,7 +99,7 @@ { "full", 4, JT_LEFT|JT_RIGHT|JT_OUTER }, { "outer", 5, JT_OUTER }, { "inner", 5, JT_INNER }, - { "cross", 5, JT_INNER }, + { "cross", 5, JT_INNER|JT_CROSS }, }; int i, j; apAll[0] = pA; @@ -155,7 +159,16 @@ p->dyn = 0; } +/* +** Create an expression node for an identifier with the name of zName +*/ +static Expr *createIdExpr(const char *zName){ + Token dummy; + setToken(&dummy, zName); + return sqlite3Expr(TK_ID, 0, 0, &dummy); +} + /* ** Add a term to the WHERE expression in *ppExpr that requires the ** zCol column to be equal in the two tables pTab1 and pTab2. @@ -168,24 +181,20 @@ const char *zAlias2, /* Alias for second table. May be NULL */ Expr **ppExpr /* Add the equality term to this expression */ ){ - Token dummy; Expr *pE1a, *pE1b, *pE1c; Expr *pE2a, *pE2b, *pE2c; Expr *pE; - setToken(&dummy, zCol); - pE1a = sqlite3Expr(TK_ID, 0, 0, &dummy); - pE2a = sqlite3Expr(TK_ID, 0, 0, &dummy); + pE1a = createIdExpr(zCol); + pE2a = createIdExpr(zCol); if( zAlias1==0 ){ zAlias1 = pTab1->zName; } - setToken(&dummy, zAlias1); - pE1b = sqlite3Expr(TK_ID, 0, 0, &dummy); + pE1b = createIdExpr(zAlias1); if( zAlias2==0 ){ zAlias2 = pTab2->zName; } - setToken(&dummy, zAlias2); - pE2b = sqlite3Expr(TK_ID, 0, 0, &dummy); + pE2b = createIdExpr(zAlias2); pE1c = sqlite3Expr(TK_DOT, pE1b, pE1a, 0); pE2c = sqlite3Expr(TK_DOT, pE2b, pE2a, 0); pE = sqlite3Expr(TK_EQ, pE1c, pE2c, 0); @@ -321,12 +330,11 @@ ** stack into the sorter. */ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){ - int i; - for(i=0; inExpr; i++){ - sqlite3ExprCode(pParse, pOrderBy->a[i].pExpr); - } - sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr, 0); - sqlite3VdbeAddOp(v, OP_SortInsert, 0, 0); + sqlite3ExprCodeExprList(pParse, pOrderBy); + sqlite3VdbeAddOp(v, OP_Sequence, pOrderBy->iECursor, 0); + sqlite3VdbeAddOp(v, OP_Pull, pOrderBy->nExpr + 1, 0); + sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr + 2, 0); + sqlite3VdbeAddOp(v, OP_IdxInsert, pOrderBy->iECursor, 0); } /* @@ -339,7 +347,7 @@ int iBreak, /* Jump here to end the loop */ int nPop /* Number of times to pop stack when jumping */ ){ - if( p->iOffset>=0 ){ + if( p->iOffset>=0 && iContinue!=0 ){ int addr = sqlite3VdbeCurrentAddr(v) + 3; if( nPop>0 ) addr++; sqlite3VdbeAddOp(v, OP_MemIncr, p->iOffset, 0); @@ -350,13 +358,41 @@ sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue); VdbeComment((v, "# skip OFFSET records")); } - if( p->iLimit>=0 ){ + if( p->iLimit>=0 && iBreak!=0 ){ sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, iBreak); VdbeComment((v, "# exit when LIMIT reached")); } } /* +** Add code that will check to make sure the top N elements of the +** stack are distinct. iTab is a sorting index that holds previously +** seen combinations of the N values. A new entry is made in iTab +** if the current N values are new. +** +** A jump to addrRepeat is made and the K values are popped from the +** stack if the top N elements are not distinct. +*/ +static void codeDistinct( + Vdbe *v, /* Generate code into this VM */ + int iTab, /* A sorting index used to test for distinctness */ + int addrRepeat, /* Jump to here if not distinct */ + int N, /* The top N elements of the stack must be distinct */ + int K /* Pop K elements from the stack if indistinct */ +){ +#if NULL_ALWAYS_DISTINCT + sqlite3VdbeAddOp(v, OP_IsNull, -N, sqlite3VdbeCurrentAddr(v)+6); +#endif + sqlite3VdbeAddOp(v, OP_MakeRecord, -N, 0); + sqlite3VdbeAddOp(v, OP_Distinct, iTab, sqlite3VdbeCurrentAddr(v)+3); + sqlite3VdbeAddOp(v, OP_Pop, K, 0); + sqlite3VdbeAddOp(v, OP_Goto, 0, addrRepeat); + VdbeComment((v, "# skip indistinct records")); + sqlite3VdbeAddOp(v, OP_IdxInsert, iTab, 0); +} + + +/* ** This routine generates the code for the inside of the inner loop ** of a SELECT. ** @@ -402,9 +438,7 @@ } }else{ nColumn = pEList->nExpr; - for(i=0; inExpr; i++){ - sqlite3ExprCode(pParse, pEList->a[i].pExpr); - } + sqlite3ExprCodeExprList(pParse, pEList); } /* If the DISTINCT keyword was present on the SELECT statement @@ -412,30 +446,23 @@ ** part of the result. */ if( hasDistinct ){ -#if NULL_ALWAYS_DISTINCT - sqlite3VdbeAddOp(v, OP_IsNull, -pEList->nExpr, sqlite3VdbeCurrentAddr(v)+7); -#endif - /* Deliberately leave the affinity string off of the following - ** OP_MakeRecord */ - sqlite3VdbeAddOp(v, OP_MakeRecord, pEList->nExpr * -1, 0); - sqlite3VdbeAddOp(v, OP_Distinct, distinct, sqlite3VdbeCurrentAddr(v)+3); - sqlite3VdbeAddOp(v, OP_Pop, pEList->nExpr+1, 0); - sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue); - VdbeComment((v, "# skip indistinct records")); - sqlite3VdbeAddOp(v, OP_IdxInsert, distinct, 0); + int n = pEList->nExpr; + codeDistinct(v, distinct, iContinue, n, n+1); if( pOrderBy==0 ){ codeLimiter(v, p, iContinue, iBreak, nColumn); } } switch( eDest ){ -#ifndef SQLITE_OMIT_COMPOUND_SELECT /* In this mode, write each query result to the key of the temporary ** table iParm. */ +#ifndef SQLITE_OMIT_COMPOUND_SELECT case SRT_Union: { sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, NULL_ALWAYS_DISTINCT); - sqlite3VdbeChangeP3(v, -1, aff, P3_STATIC); + if( aff ){ + sqlite3VdbeChangeP3(v, -1, aff, P3_STATIC); + } sqlite3VdbeAddOp(v, OP_IdxInsert, iParm, 0); break; } @@ -457,7 +484,7 @@ /* Store the result as data using a unique key. */ case SRT_Table: - case SRT_TempTable: { + case SRT_VirtualTab: { sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); if( pOrderBy ){ pushOntoSorter(pParse, v, pOrderBy); @@ -483,6 +510,10 @@ sqlite3VdbeAddOp(v, OP_Pop, 1, 0); addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0); if( pOrderBy ){ + /* At first glance you would think we could optimize out the + ** ORDER BY in this case since the order of entries in the set + ** does not matter. But there might be a LIMIT clause, in which + ** case the order does matter */ pushOntoSorter(pParse, v, pOrderBy); }else{ char aff = (iParm>>16)&0xFF; @@ -511,33 +542,23 @@ } #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ - /* Send the data to the callback function. + /* Send the data to the callback function or to a subroutine. In the + ** case of a subroutine, the subroutine itself is responsible for + ** popping the data from the stack. */ - case SRT_Callback: - case SRT_Sorter: { + case SRT_Subroutine: + case SRT_Callback: { if( pOrderBy ){ sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); pushOntoSorter(pParse, v, pOrderBy); + }else if( eDest==SRT_Subroutine ){ + sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm); }else{ - assert( eDest==SRT_Callback ); sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0); } break; } - /* Invoke a subroutine to handle the results. The subroutine itself - ** is responsible for popping the results off of the stack. - */ - case SRT_Subroutine: { - if( pOrderBy ){ - sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); - pushOntoSorter(pParse, v, pOrderBy); - }else{ - sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm); - } - break; - } - #if !defined(SQLITE_OMIT_TRIGGER) /* Discard the results. This is used for SELECT statements inside ** the body of a TRIGGER. The purpose of such selects is to call @@ -555,6 +576,48 @@ } /* +** Given an expression list, generate a KeyInfo structure that records +** the collating sequence for each expression in that expression list. +** +** If the ExprList is an ORDER BY or GROUP BY clause then the resulting +** KeyInfo structure is appropriate for initializing a virtual index to +** implement that clause. If the ExprList is the result set of a SELECT +** then the KeyInfo structure is appropriate for initializing a virtual +** index to implement a DISTINCT test. +** +** Space to hold the KeyInfo structure is obtain from malloc. The calling +** function is responsible for seeing that this structure is eventually +** freed. Add the KeyInfo structure to the P3 field of an opcode using +** P3_KEYINFO_HANDOFF is the usual way of dealing with this. +*/ +static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){ + sqlite3 *db = pParse->db; + int nExpr; + KeyInfo *pInfo; + struct ExprList_item *pItem; + int i; + + nExpr = pList->nExpr; + pInfo = sqliteMalloc( sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) ); + if( pInfo ){ + pInfo->aSortOrder = (char*)&pInfo->aColl[nExpr]; + pInfo->nField = nExpr; + pInfo->enc = db->enc; + for(i=0, pItem=pList->a; ipExpr); + if( !pColl ){ + pColl = db->pDfltColl; + } + pInfo->aColl[i] = pColl; + pInfo->aSortOrder[i] = pItem->sortOrder; + } + } + return pInfo; +} + + +/* ** If the inner loop was generated using a non-null pOrderBy argument, ** then the results were placed in a sorter. After the loop is terminated ** we need to run the sorter and output the results. The following @@ -568,38 +631,19 @@ int eDest, /* Write the sorted results here */ int iParm /* Optional parameter associated with eDest */ ){ - int end1 = sqlite3VdbeMakeLabel(v); - int end2 = sqlite3VdbeMakeLabel(v); + int brk = sqlite3VdbeMakeLabel(v); + int cont = sqlite3VdbeMakeLabel(v); int addr; - KeyInfo *pInfo; - ExprList *pOrderBy; - int nCol, i; - sqlite3 *db = pParse->db; + int iTab; + ExprList *pOrderBy = p->pOrderBy; - if( eDest==SRT_Sorter ) return; - pOrderBy = p->pOrderBy; - nCol = pOrderBy->nExpr; - pInfo = sqliteMalloc( sizeof(*pInfo) + nCol*(sizeof(CollSeq*)+1) ); - if( pInfo==0 ) return; - pInfo->aSortOrder = (char*)&pInfo->aColl[nCol]; - pInfo->nField = nCol; - for(i=0; ia[i].zName. Otherwise, use the default - ** collation type for the expression. - */ - pInfo->aColl[i] = sqlite3ExprCollSeq(pParse, pOrderBy->a[i].pExpr); - if( !pInfo->aColl[i] ){ - pInfo->aColl[i] = db->pDfltColl; - } - pInfo->aSortOrder[i] = pOrderBy->a[i].sortOrder; - } - sqlite3VdbeOp3(v, OP_Sort, 0, 0, (char*)pInfo, P3_KEYINFO_HANDOFF); - addr = sqlite3VdbeAddOp(v, OP_SortNext, 0, end1); - codeLimiter(v, p, addr, end2, 1); + iTab = pOrderBy->iECursor; + addr = 1 + sqlite3VdbeAddOp(v, OP_Sort, iTab, brk); + codeLimiter(v, p, cont, brk, 0); + sqlite3VdbeAddOp(v, OP_Column, iTab, pOrderBy->nExpr + 1); switch( eDest ){ case SRT_Table: - case SRT_TempTable: { + case SRT_VirtualTab: { sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_Insert, iParm, 0); @@ -619,7 +663,7 @@ case SRT_Mem: { assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); - sqlite3VdbeAddOp(v, OP_Goto, 0, end1); + sqlite3VdbeAddOp(v, OP_Goto, 0, brk); break; } #endif @@ -644,11 +688,9 @@ break; } } - sqlite3VdbeAddOp(v, OP_Goto, 0, addr); - sqlite3VdbeResolveLabel(v, end2); - sqlite3VdbeAddOp(v, OP_Pop, 1, 0); - sqlite3VdbeResolveLabel(v, end1); - sqlite3VdbeAddOp(v, OP_SortReset, 0, 0); + sqlite3VdbeResolveLabel(v, cont); + sqlite3VdbeAddOp(v, OP_Next, iTab, addr); + sqlite3VdbeResolveLabel(v, brk); } /* @@ -1312,59 +1354,33 @@ } /* -** Generate VDBE instructions that will open a transient table that -** will be used for an index or to store keyed results for a compound -** select. In other words, open a transient table that needs a -** KeyInfo structure. The number of columns in the KeyInfo is determined -** by the result set of the SELECT statement in the second argument. -** -** Specifically, this routine is called to open an index table for -** DISTINCT, UNION, INTERSECT and EXCEPT select statements (but not -** UNION ALL). -** -** The value returned is the address of the OP_OpenTemp instruction. +** Allocate a virtual index to use for sorting. */ -static int openTempIndex(Parse *pParse, Select *p, int iTab){ - KeyInfo *pKeyInfo; - int nColumn; - sqlite3 *db = pParse->db; - int i; - Vdbe *v = pParse->pVdbe; - int addr; - - if( prepSelectStmt(pParse, p) ){ - return 0; +static void createSortingIndex(Parse *pParse, Select *p, ExprList *pOrderBy){ + if( pOrderBy ){ + int addr; + assert( pOrderBy->iECursor==0 ); + pOrderBy->iECursor = pParse->nTab++; + addr = sqlite3VdbeAddOp(pParse->pVdbe, OP_OpenVirtual, + pOrderBy->iECursor, pOrderBy->nExpr+1); + assert( p->addrOpenVirt[2] == -1 ); + p->addrOpenVirt[2] = addr; } - nColumn = p->pEList->nExpr; - pKeyInfo = sqliteMalloc( sizeof(*pKeyInfo)+nColumn*sizeof(CollSeq*) ); - if( pKeyInfo==0 ) return 0; - pKeyInfo->enc = db->enc; - pKeyInfo->nField = nColumn; - for(i=0; iaColl[i] = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr); - if( !pKeyInfo->aColl[i] ){ - pKeyInfo->aColl[i] = db->pDfltColl; - } - } - addr = sqlite3VdbeOp3(v, OP_OpenTemp, iTab, 0, - (char*)pKeyInfo, P3_KEYINFO_HANDOFF); - return addr; } -#ifndef SQLITE_OMIT_COMPOUND_SELECT /* -** Add the address "addr" to the set of all OpenTemp opcode addresses -** that are being accumulated in p->ppOpenTemp. +** The opcode at addr is an OP_OpenVirtual that created a sorting +** index tha we ended up not needing. This routine changes that +** opcode to OP_Noop. */ -static int multiSelectOpenTempAddr(Select *p, int addr){ - IdList *pList = *p->ppOpenTemp = sqlite3IdListAppend(*p->ppOpenTemp, 0); - if( pList==0 ){ - return SQLITE_NOMEM; - } - pList->a[pList->nId-1].idx = addr; - return SQLITE_OK; +static void uncreateSortingIndex(Parse *pParse, int addr){ + Vdbe *v = pParse->pVdbe; + VdbeOp *pOp = sqlite3VdbeGetOp(v, addr); + sqlite3VdbeChangeP3(v, addr, 0, 0); + pOp->opcode = OP_Noop; + pOp->p1 = 0; + pOp->p2 = 0; } -#endif /* SQLITE_OMIT_COMPOUND_SELECT */ #ifndef SQLITE_OMIT_COMPOUND_SELECT /* @@ -1430,10 +1446,10 @@ int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ - IdList *pOpenTemp = 0;/* OP_OpenTemp opcodes that need a KeyInfo */ - int aAddr[5]; /* Addresses of SetNumColumns operators */ - int nAddr = 0; /* Number used */ int nCol; /* Number of columns in the result set */ + ExprList *pOrderBy; /* The ORDER BY clause on p */ + int aSetP2[2]; /* Set P2 value of these op to number of columns */ + int nSetP2 = 0; /* Number of slots in aSetP2[] used */ /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT. @@ -1443,6 +1459,8 @@ goto multi_select_end; } pPrior = p->pPrior; + assert( pPrior->pRightmost!=pPrior ); + assert( pPrior->pRightmost==p->pRightmost ); if( pPrior->pOrderBy ){ sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before", selectOpName(p->op)); @@ -1464,32 +1482,21 @@ goto multi_select_end; } - /* If *p this is the right-most select statement, then initialize - ** p->ppOpenTemp to point to pOpenTemp. If *p is not the right most - ** statement then p->ppOpenTemp will have already been initialized - ** by a prior call to this same procedure. Pass along the pOpenTemp - ** pointer to pPrior, the next statement to our left. - */ - if( p->ppOpenTemp==0 ){ - p->ppOpenTemp = &pOpenTemp; - } - pPrior->ppOpenTemp = p->ppOpenTemp; - /* Create the destination temporary table if necessary */ - if( eDest==SRT_TempTable ){ + if( eDest==SRT_VirtualTab ){ assert( p->pEList ); - sqlite3VdbeAddOp(v, OP_OpenTemp, iParm, 0); - assert( nAddr==0 ); - aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 0); + assert( nSetP2pOrderBy; switch( p->op ){ case TK_ALL: { - if( p->pOrderBy==0 ){ + if( pOrderBy==0 ){ assert( !pPrior->pLimit ); pPrior->pLimit = p->pLimit; pPrior->pOffset = p->pOffset; @@ -1517,11 +1524,10 @@ int op = 0; /* One of the SRT_ operations to apply to self */ int priorOp; /* The SRT_ operation to apply to prior selects */ Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */ - ExprList *pOrderBy; /* The ORDER BY clause for the right SELECT */ int addr; priorOp = p->op==TK_ALL ? SRT_Table : SRT_Union; - if( eDest==priorOp && p->pOrderBy==0 && !p->pLimit && !p->pOffset ){ + if( eDest==priorOp && pOrderBy==0 && !p->pLimit && !p->pOffset ){ /* We can reuse a temporary table generated by a SELECT to our ** right. */ @@ -1531,20 +1537,20 @@ ** intermediate results. */ unionTab = pParse->nTab++; - if( p->pOrderBy - && matchOrderbyToColumn(pParse, p, p->pOrderBy, unionTab, 1) ){ + if( pOrderBy && matchOrderbyToColumn(pParse, p, pOrderBy, unionTab,1) ){ rc = 1; goto multi_select_end; } - addr = sqlite3VdbeAddOp(v, OP_OpenTemp, unionTab, 0); - if( p->op!=TK_ALL ){ - rc = multiSelectOpenTempAddr(p, addr); - if( rc!=SQLITE_OK ){ - goto multi_select_end; - } + addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, unionTab, 0); + if( priorOp==SRT_Table ){ + assert( nSetP2addrOpenVirt[0] == -1 ); + p->addrOpenVirt[0] = addr; + p->pRightmost->usesVirt = 1; } - assert( nAddrpEList ); } @@ -1564,7 +1570,6 @@ case TK_ALL: op = SRT_Table; break; } p->pPrior = 0; - pOrderBy = p->pOrderBy; p->pOrderBy = 0; pLimit = p->pLimit; p->pLimit = 0; @@ -1598,7 +1603,7 @@ computeLimitRegisters(pParse, p); iStart = sqlite3VdbeCurrentAddr(v); rc = selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr, - p->pOrderBy, -1, eDest, iParm, + pOrderBy, -1, eDest, iParm, iCont, iBreak, 0); if( rc ){ rc = 1; @@ -1623,18 +1628,16 @@ */ tab1 = pParse->nTab++; tab2 = pParse->nTab++; - if( p->pOrderBy && matchOrderbyToColumn(pParse,p,p->pOrderBy,tab1,1) ){ + if( pOrderBy && matchOrderbyToColumn(pParse,p,pOrderBy,tab1,1) ){ rc = 1; goto multi_select_end; } + createSortingIndex(pParse, p, pOrderBy); - addr = sqlite3VdbeAddOp(v, OP_OpenTemp, tab1, 0); - rc = multiSelectOpenTempAddr(p, addr); - if( rc!=SQLITE_OK ){ - goto multi_select_end; - } - assert( nAddraddrOpenVirt[0] == -1 ); + p->addrOpenVirt[0] = addr; + p->pRightmost->usesVirt = 1; assert( p->pEList ); /* Code the SELECTs to our left into temporary table "tab1". @@ -1646,13 +1649,9 @@ /* Code the current SELECT into temporary table "tab2" */ - addr = sqlite3VdbeAddOp(v, OP_OpenTemp, tab2, 0); - rc = multiSelectOpenTempAddr(p, addr); - if( rc!=SQLITE_OK ){ - goto multi_select_end; - } - assert( nAddraddrOpenVirt[1] == -1 ); + p->addrOpenVirt[1] = addr; p->pPrior = 0; pLimit = p->pLimit; p->pLimit = 0; @@ -1681,7 +1680,7 @@ iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0); sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont); rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr, - p->pOrderBy, -1, eDest, iParm, + pOrderBy, -1, eDest, iParm, iCont, iBreak, 0); if( rc ){ rc = 1; @@ -1710,9 +1709,8 @@ /* Set the number of columns in temporary tables */ nCol = p->pEList->nExpr; - while( nAddr>0 ){ - nAddr--; - sqlite3VdbeChangeP2(v, aAddr[nAddr], nCol); + while( nSetP2 ){ + sqlite3VdbeChangeP2(v, aSetP2[--nSetP2], nCol); } /* Compute collating sequences used by either the ORDER BY clause or @@ -1725,12 +1723,15 @@ ** SELECT might also skip this part if it has no ORDER BY clause and ** no temp tables are required. */ - if( p->pOrderBy || (pOpenTemp && pOpenTemp->nId>0) ){ + if( pOrderBy || p->usesVirt ){ int i; /* Loop counter */ KeyInfo *pKeyInfo; /* Collating sequence for the result set */ + Select *pLoop; /* For looping through SELECT statements */ + CollSeq **apColl; + CollSeq **aCopy; - assert( p->ppOpenTemp == &pOpenTemp ); - pKeyInfo = sqliteMalloc(sizeof(*pKeyInfo)+nCol*sizeof(CollSeq*)); + assert( p->pRightmost==p ); + pKeyInfo = sqliteMalloc(sizeof(*pKeyInfo)+nCol*2*sizeof(CollSeq*) + nCol); if( !pKeyInfo ){ rc = SQLITE_NOMEM; goto multi_select_end; @@ -1739,46 +1740,61 @@ pKeyInfo->enc = pParse->db->enc; pKeyInfo->nField = nCol; - for(i=0; iaColl[i] = multiSelectCollSeq(pParse, p, i); - if( !pKeyInfo->aColl[i] ){ - pKeyInfo->aColl[i] = pParse->db->pDfltColl; + for(i=0, apColl=pKeyInfo->aColl; idb->pDfltColl; } } - for(i=0; pOpenTemp && inId; i++){ - int p3type = (i==0?P3_KEYINFO_HANDOFF:P3_KEYINFO); - int addr = pOpenTemp->a[i].idx; - sqlite3VdbeChangeP3(v, addr, (char *)pKeyInfo, p3type); + for(pLoop=p; pLoop; pLoop=pLoop->pPrior){ + for(i=0; i<2; i++){ + int addr = pLoop->addrOpenVirt[i]; + if( addr<0 ){ + /* If [0] is unused then [1] is also unused. So we can + ** always safely abort as soon as the first unused slot is found */ + assert( pLoop->addrOpenVirt[1]<0 ); + break; + } + sqlite3VdbeChangeP2(v, addr, nCol); + sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO); + } } - if( p->pOrderBy ){ - struct ExprList_item *pOrderByTerm = p->pOrderBy->a; - for(i=0; ipOrderBy->nExpr; i++, pOrderByTerm++){ - Expr *pExpr = pOrderByTerm->pExpr; - char *zName = pOrderByTerm->zName; + if( pOrderBy ){ + struct ExprList_item *pOTerm = pOrderBy->a; + int nExpr = pOrderBy->nExpr; + int addr; + u8 *pSortOrder; + + aCopy = (CollSeq**)&pKeyInfo[1]; + pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nExpr]; + memcpy(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*)); + apColl = pKeyInfo->aColl; + for(i=0; inExpr; i++, pOTerm++, apColl++, pSortOrder++){ + Expr *pExpr = pOTerm->pExpr; + char *zName = pOTerm->zName; assert( pExpr->op==TK_COLUMN && pExpr->iColumnpColl ); */ if( zName ){ - pExpr->pColl = sqlite3LocateCollSeq(pParse, zName, -1); + *apColl = sqlite3LocateCollSeq(pParse, zName, -1); }else{ - pExpr->pColl = pKeyInfo->aColl[pExpr->iColumn]; + *apColl = aCopy[pExpr->iColumn]; } + *pSortOrder = pOTerm->sortOrder; } + assert( p->pRightmost==p ); + assert( p->addrOpenVirt[2]>=0 ); + addr = p->addrOpenVirt[2]; + sqlite3VdbeChangeP2(v, addr, p->pEList->nExpr+2); + sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); + pKeyInfo = 0; generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm); } - if( !pOpenTemp ){ - /* This happens for UNION ALL ... ORDER BY */ - sqliteFree(pKeyInfo); - } + sqliteFree(pKeyInfo); } multi_select_end: - if( pOpenTemp ){ - sqlite3IdListDelete(pOpenTemp); - } - p->ppOpenTemp = 0; return rc; } #endif /* SQLITE_OMIT_COMPOUND_SELECT */ @@ -2182,9 +2198,8 @@ /* If the output is destined for a temporary table, open that table. */ - if( eDest==SRT_TempTable ){ - sqlite3VdbeAddOp(v, OP_OpenTemp, iParm, 0); - sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 1); + if( eDest==SRT_VirtualTab ){ + sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 1); } /* Generating code to find the min or the max. Basically all we have @@ -2293,6 +2308,7 @@ ExprList *pEList; /* Result set. */ int i; /* For-loop variable used in multiple places */ NameContext sNC; /* Local name-context */ + ExprList *pGroupBy; /* The group by clause */ /* If this routine has run before, return immediately. */ if( p->isResolved ){ @@ -2336,18 +2352,6 @@ sNC.pSrcList = p->pSrc; sNC.pNext = pOuterNC; - /* NameContext.nDepth stores the depth of recursion for this query. For - ** an outer query (e.g. SELECT * FROM sqlite_master) this is 1. For - ** a subquery it is 2. For a subquery of a subquery, 3. And so on. - ** Parse.nMaxDepth is the maximum depth for any subquery resolved so - ** far. This is used to determine the number of aggregate contexts - ** required at runtime. - */ - sNC.nDepth = (pOuterNC?pOuterNC->nDepth+1:1); - if( sNC.nDepth>pParse->nMaxDepth ){ - pParse->nMaxDepth = sNC.nDepth; - } - /* Resolve names in the result set. */ pEList = p->pEList; if( !pEList ) return SQLITE_ERROR; @@ -2362,7 +2366,8 @@ ** expression, do not allow aggregates in any of the other expressions. */ assert( !p->isAgg ); - if( p->pGroupBy || sNC.hasAgg ){ + pGroupBy = p->pGroupBy; + if( pGroupBy || sNC.hasAgg ){ p->isAgg = 1; }else{ sNC.allowAgg = 0; @@ -2370,7 +2375,7 @@ /* If a HAVING clause is present, then there must be a GROUP BY clause. */ - if( p->pHaving && !p->pGroupBy ){ + if( p->pHaving && !pGroupBy ){ sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); return SQLITE_ERROR; } @@ -2387,49 +2392,131 @@ if( sqlite3ExprResolveNames(&sNC, p->pWhere) || sqlite3ExprResolveNames(&sNC, p->pHaving) || processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") || - processOrderGroupBy(&sNC, p->pGroupBy, "GROUP") + processOrderGroupBy(&sNC, pGroupBy, "GROUP") ){ return SQLITE_ERROR; } + /* Make sure the GROUP BY clause does not contain aggregate functions. + */ + if( pGroupBy ){ + struct ExprList_item *pItem; + + for(i=0, pItem=pGroupBy->a; inExpr; i++, pItem++){ + if( ExprHasProperty(pItem->pExpr, EP_Agg) ){ + sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in " + "the GROUP BY clause"); + return SQLITE_ERROR; + } + } + } + return SQLITE_OK; } /* -** An instance of the following struct is used by sqlite3Select() -** to save aggregate related information from the Parse object -** at the start of each call and to restore it at the end. See -** saveAggregateInfo() and restoreAggregateInfo(). -*/ -struct AggregateInfo { - int nAgg; - AggExpr *aAgg; -}; -typedef struct AggregateInfo AggregateInfo; +** Reset the aggregate accumulator. +** +** The aggregate accumulator is a set of memory cells that hold +** intermediate results while calculating an aggregate. This +** routine simply stores NULLs in all of those memory cells. +*/ +static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ + Vdbe *v = pParse->pVdbe; + int i; + int addr; + struct AggInfo_func *pFunc; + if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){ + return; + } + sqlite3VdbeAddOp(v, OP_Null, 0, 0); + for(i=0; inColumn; i++){ + addr = sqlite3VdbeAddOp(v, OP_MemStore, pAggInfo->aCol[i].iMem, 0); + } + for(pFunc=pAggInfo->aFunc, i=0; inFunc; i++, pFunc++){ + addr = sqlite3VdbeAddOp(v, OP_MemStore, pFunc->iMem, 0); + if( pFunc->iDistinct>=0 ){ + Expr *pE = pFunc->pExpr; + if( pE->pList==0 || pE->pList->nExpr!=1 ){ + sqlite3ErrorMsg(pParse, "DISTINCT in aggregate must be followed " + "by an expression"); + pFunc->iDistinct = -1; + }else{ + KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->pList); + sqlite3VdbeOp3(v, OP_OpenVirtual, pFunc->iDistinct, 0, + (char*)pKeyInfo, P3_KEYINFO_HANDOFF); + } + } + } + sqlite3VdbeChangeP2(v, addr, 1); +} -/* -** Copy aggregate related information from the Parse structure -** into the AggregateInfo structure. Zero the aggregate related -** values in the Parse struct. +/* +** Invoke the OP_AggFinalize opcode for every aggregate function +** in the AggInfo structure. */ -static void saveAggregateInfo(Parse *pParse, AggregateInfo *pInfo){ - pInfo->aAgg = pParse->aAgg; - pInfo->nAgg = pParse->nAgg; - pParse->aAgg = 0; - pParse->nAgg = 0; +static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){ + Vdbe *v = pParse->pVdbe; + int i; + struct AggInfo_func *pF; + for(i=0, pF=pAggInfo->aFunc; inFunc; i++, pF++){ + ExprList *pList = pF->pExpr->pList; + sqlite3VdbeOp3(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0, + (void*)pF->pFunc, P3_FUNCDEF); + } } /* -** Copy aggregate related information from the AggregateInfo struct -** back into the Parse structure. The aggregate related information -** currently stored in the Parse structure is deleted. +** Update the accumulator memory cells for an aggregate based on +** the current cursor position. */ -static void restoreAggregateInfo(Parse *pParse, AggregateInfo *pInfo){ - sqliteFree(pParse->aAgg); - pParse->aAgg = pInfo->aAgg; - pParse->nAgg = pInfo->nAgg; +static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ + Vdbe *v = pParse->pVdbe; + int i; + struct AggInfo_func *pF; + struct AggInfo_col *pC; + + pAggInfo->directMode = 1; + for(i=0, pF=pAggInfo->aFunc; inFunc; i++, pF++){ + int nArg; + int addrNext = 0; + ExprList *pList = pF->pExpr->pList; + if( pList ){ + nArg = pList->nExpr; + sqlite3ExprCodeExprList(pParse, pList); + }else{ + nArg = 0; + } + if( pF->iDistinct>=0 ){ + addrNext = sqlite3VdbeMakeLabel(v); + assert( nArg==1 ); + codeDistinct(v, pF->iDistinct, addrNext, 1, 2); + } + if( pF->pFunc->needCollSeq ){ + CollSeq *pColl = 0; + struct ExprList_item *pItem; + int j; + for(j=0, pItem=pList->a; !pColl && jnExpr; j++, pItem++){ + pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr); + } + if( !pColl ){ + pColl = pParse->db->pDfltColl; + } + sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ); + } + sqlite3VdbeOp3(v, OP_AggStep, pF->iMem, nArg, (void*)pF->pFunc, P3_FUNCDEF); + if( addrNext ){ + sqlite3VdbeResolveLabel(v, addrNext); + } + } + for(i=0, pC=pAggInfo->aCol; inAccumulator; i++, pC++){ + sqlite3ExprCode(pParse, pC->pExpr); + sqlite3VdbeAddOp(v, OP_MemStore, pC->iMem, 1); + } + pAggInfo->directMode = 0; } - + + /* ** Generate code for the given SELECT statement. ** @@ -2492,9 +2579,9 @@ int *pParentAgg, /* True if pParent uses aggregate functions */ char *aff /* If eDest is SRT_Union, the affinity string */ ){ - int i; - WhereInfo *pWInfo; - Vdbe *v; + int i, j; /* Loop counters */ + WhereInfo *pWInfo; /* Return from sqlite3WhereBegin() */ + Vdbe *v; /* The virtual machine under construction */ int isAgg; /* True for select lists like "count(*)" */ ExprList *pEList; /* List of columns to extract. */ SrcList *pTabList; /* List of tables to select from */ @@ -2505,22 +2592,29 @@ int isDistinct; /* True if the DISTINCT keyword is present */ int distinct; /* Table to use for the distinct set */ int rc = 1; /* Value to return from this function */ - AggregateInfo sAggInfo; + int addrSortIndex; /* Address of an OP_OpenVirtual instruction */ + AggInfo sAggInfo; /* Information used by aggregate queries */ if( sqlite3_malloc_failed || pParse->nErr || p==0 ) return 1; if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; + memset(&sAggInfo, 0, sizeof(sAggInfo)); #ifndef SQLITE_OMIT_COMPOUND_SELECT /* If there is are a sequence of queries, do the earlier ones first. */ if( p->pPrior ){ + if( p->pRightmost==0 ){ + Select *pLoop; + for(pLoop=p; pLoop; pLoop=pLoop->pPrior){ + pLoop->pRightmost = p; + } + } return multiSelect(pParse, p, eDest, iParm, aff); } #endif - saveAggregateInfo(pParse, &sAggInfo); pOrderBy = p->pOrderBy; - if( eDest==SRT_Union || eDest==SRT_Except || eDest==SRT_Discard ){ + if( IgnorableOrderby(eDest) ){ p->pOrderBy = 0; } if( sqlite3SelectResolve(pParse, p, 0) ){ @@ -2559,14 +2653,8 @@ /* ORDER BY is ignored for some destinations. */ - switch( eDest ){ - case SRT_Union: - case SRT_Except: - case SRT_Discard: - pOrderBy = 0; - break; - default: - break; + if( IgnorableOrderby(eDest) ){ + pOrderBy = 0; } /* Begin generating code. @@ -2587,23 +2675,24 @@ for(i=0; inSrc; i++){ const char *zSavedAuthContext = 0; int needRestoreContext; + struct SrcList_item *pItem = &pTabList->a[i]; - if( pTabList->a[i].pSelect==0 ) continue; - if( pTabList->a[i].zName!=0 ){ + if( pItem->pSelect==0 ) continue; + if( pItem->zName!=0 ){ zSavedAuthContext = pParse->zAuthContext; - pParse->zAuthContext = pTabList->a[i].zName; + pParse->zAuthContext = pItem->zName; needRestoreContext = 1; }else{ needRestoreContext = 0; } - sqlite3Select(pParse, pTabList->a[i].pSelect, SRT_TempTable, - pTabList->a[i].iCursor, p, i, &isAgg, 0); + sqlite3Select(pParse, pItem->pSelect, SRT_VirtualTab, + pItem->iCursor, p, i, &isAgg, 0); if( needRestoreContext ){ pParse->zAuthContext = zSavedAuthContext; } pTabList = p->pSrc; pWhere = p->pWhere; - if( eDest!=SRT_Union && eDest!=SRT_Except && eDest!=SRT_Discard ){ + if( !IgnorableOrderby(eDest) ){ pOrderBy = p->pOrderBy; } pGroupBy = p->pGroupBy; @@ -2632,18 +2721,32 @@ #endif /* If there is an ORDER BY clause, resolve any collation sequences - ** names that have been explicitly specified. + ** names that have been explicitly specified and create a sorting index. + ** + ** This sorting index might end up being unused if the data can be + ** extracted in pre-sorted order. If that is the case, then the + ** OP_OpenVirtual instruction will be changed to an OP_Noop once + ** we figure out that the sorting index is not needed. The addrSortIndex + ** variable is used to facilitate that change. */ if( pOrderBy ){ - for(i=0; inExpr; i++){ - if( pOrderBy->a[i].zName ){ - pOrderBy->a[i].pExpr->pColl = - sqlite3LocateCollSeq(pParse, pOrderBy->a[i].zName, -1); + struct ExprList_item *pTerm; + KeyInfo *pKeyInfo; + for(i=0, pTerm=pOrderBy->a; inExpr; i++, pTerm++){ + if( pTerm->zName ){ + pTerm->pExpr->pColl = sqlite3LocateCollSeq(pParse, pTerm->zName, -1); } } if( pParse->nErr ){ goto select_end; } + pKeyInfo = keyInfoFromExprList(pParse, pOrderBy); + pOrderBy->iECursor = pParse->nTab++; + p->addrOpenVirt[2] = addrSortIndex = + sqlite3VdbeOp3(v, OP_OpenVirtual, pOrderBy->iECursor, pOrderBy->nExpr+2, + (char*)pKeyInfo, P3_KEYINFO_HANDOFF); + }else{ + addrSortIndex = -1; } /* Set the limiter. @@ -2652,80 +2755,11 @@ /* If the output is destined for a temporary table, open that table. */ - if( eDest==SRT_TempTable ){ - sqlite3VdbeAddOp(v, OP_OpenTemp, iParm, 0); - sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, pEList->nExpr); + if( eDest==SRT_VirtualTab ){ + sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, pEList->nExpr); } - /* Do an analysis of aggregate expressions. - */ - if( isAgg || pGroupBy ){ - NameContext sNC; - memset(&sNC, 0, sizeof(sNC)); - sNC.pParse = pParse; - sNC.pSrcList = pTabList; - assert( pParse->nAgg==0 ); - isAgg = 1; - for(i=0; inExpr; i++){ - if( sqlite3ExprAnalyzeAggregates(&sNC, pEList->a[i].pExpr) ){ - goto select_end; - } - } - if( pGroupBy ){ - for(i=0; inExpr; i++){ - if( sqlite3ExprAnalyzeAggregates(&sNC, pGroupBy->a[i].pExpr) ){ - goto select_end; - } - } - } - if( pHaving && sqlite3ExprAnalyzeAggregates(&sNC, pHaving) ){ - goto select_end; - } - if( pOrderBy ){ - for(i=0; inExpr; i++){ - if( sqlite3ExprAnalyzeAggregates(&sNC, pOrderBy->a[i].pExpr) ){ - goto select_end; - } - } - } - } - - /* Reset the aggregator - */ - if( isAgg ){ - int addr = sqlite3VdbeAddOp(v, OP_AggReset, (pGroupBy?0:1), pParse->nAgg); - for(i=0; inAgg; i++){ - FuncDef *pFunc; - if( (pFunc = pParse->aAgg[i].pFunc)!=0 && pFunc->xFinalize!=0 ){ - int nExpr = 0; -#ifdef SQLITE_SSE - Expr *pAggExpr = pParse->aAgg[i].pExpr; - if( pAggExpr && pAggExpr->pList ){ - nExpr = pAggExpr->pList->nExpr; - } -#endif - sqlite3VdbeOp3(v, OP_AggInit, nExpr, i, (char*)pFunc, P3_FUNCDEF); - } - } - if( pGroupBy ){ - int sz = sizeof(KeyInfo) + pGroupBy->nExpr*sizeof(CollSeq*); - KeyInfo *pKey = (KeyInfo *)sqliteMalloc(sz); - if( 0==pKey ){ - goto select_end; - } - pKey->enc = pParse->db->enc; - pKey->nField = pGroupBy->nExpr; - for(i=0; inExpr; i++){ - pKey->aColl[i] = sqlite3ExprCollSeq(pParse, pGroupBy->a[i].pExpr); - if( !pKey->aColl[i] ){ - pKey->aColl[i] = pParse->db->pDfltColl; - } - } - sqlite3VdbeChangeP3(v, addr, (char *)pKey, P3_KEYINFO_HANDOFF); - } - } - /* Initialize the memory cell to NULL for SRT_Mem or 0 for SRT_Exists */ if( eDest==SRT_Mem || eDest==SRT_Exists ){ @@ -2733,105 +2767,292 @@ sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); } - /* Open a temporary table to use for the distinct set. + /* Open a virtual index to use for the distinct set. */ if( isDistinct ){ + KeyInfo *pKeyInfo; distinct = pParse->nTab++; - openTempIndex(pParse, p, distinct); + pKeyInfo = keyInfoFromExprList(pParse, p->pEList); + sqlite3VdbeOp3(v, OP_OpenVirtual, distinct, 0, + (char*)pKeyInfo, P3_KEYINFO_HANDOFF); }else{ distinct = -1; } - /* Begin the database scan - */ - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, - pGroupBy ? 0 : &pOrderBy); - if( pWInfo==0 ) goto select_end; + /* Aggregate and non-aggregate queries are handled differently */ + if( !isAgg && pGroupBy==0 ){ + /* This case is for non-aggregate queries + ** Begin the database scan + */ + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy); + if( pWInfo==0 ) goto select_end; - /* Use the standard inner loop if we are not dealing with - ** aggregates - */ - if( !isAgg ){ + /* If sorting index that was created by a prior OP_OpenVirtual + ** instruction ended up not being needed, then change the OP_OpenVirtual + ** into an OP_Noop. + */ + if( addrSortIndex>=0 && pOrderBy==0 ){ + uncreateSortingIndex(pParse, addrSortIndex); + p->addrOpenVirt[2] = -1; + } + + /* Use the standard inner loop + */ if( selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, eDest, iParm, pWInfo->iContinue, pWInfo->iBreak, aff) ){ goto select_end; } - } - /* If we are dealing with aggregates, then do the special aggregate - ** processing. - */ - else{ - AggExpr *pAgg; - int lbl1 = 0; - pParse->fillAgg = 1; - if( pGroupBy ){ - for(i=0; inExpr; i++){ - sqlite3ExprCode(pParse, pGroupBy->a[i].pExpr); - } - /* No affinity string is attached to the following OP_MakeRecord - ** because we do not need to do any coercion of datatypes. */ - sqlite3VdbeAddOp(v, OP_MakeRecord, pGroupBy->nExpr, 0); - lbl1 = sqlite3VdbeMakeLabel(v); - sqlite3VdbeAddOp(v, OP_AggFocus, 0, lbl1); + /* End the database scan loop. + */ + sqlite3WhereEnd(pWInfo); + }else{ + /* This is the processing for aggregate queries */ + NameContext sNC; /* Name context for processing aggregate information */ + int iAMem; /* First Mem address for storing current GROUP BY */ + int iBMem; /* First Mem address for previous GROUP BY */ + int iUseFlag; /* Mem address holding flag indicating that at least + ** one row of the input to the aggregator has been + ** processed */ + int iAbortFlag; /* Mem address which causes query abort if positive */ + int groupBySort; /* Rows come from source in GROUP BY order */ + + + /* The following variables hold addresses or labels for parts of the + ** virtual machine program we are putting together */ + int addrOutputRow; /* Start of subroutine that outputs a result row */ + int addrSetAbort; /* Set the abort flag and return */ + int addrInitializeLoop; /* Start of code that initializes the input loop */ + int addrTopOfLoop; /* Top of the input loop */ + int addrGroupByChange; /* Code that runs when any GROUP BY term changes */ + int addrProcessRow; /* Code to process a single input row */ + int addrEnd; /* End of all processing */ + int addrSortingIdx; /* The OP_OpenVirtual for the sorting index */ + + addrEnd = sqlite3VdbeMakeLabel(v); + + /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in + ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the + ** SELECT statement. + */ + memset(&sNC, 0, sizeof(sNC)); + sNC.pParse = pParse; + sNC.pSrcList = pTabList; + sNC.pAggInfo = &sAggInfo; + sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0; + sAggInfo.pGroupBy = pGroupBy; + if( sqlite3ExprAnalyzeAggList(&sNC, pEList) ){ + goto select_end; } - for(i=0, pAgg=pParse->aAgg; inAgg; i++, pAgg++){ - if( pAgg->isAgg ) continue; - sqlite3ExprCode(pParse, pAgg->pExpr); - sqlite3VdbeAddOp(v, OP_AggSet, 0, i); + if( sqlite3ExprAnalyzeAggList(&sNC, pOrderBy) ){ + goto select_end; } - pParse->fillAgg = 0; - if( lbl1<0 ){ - sqlite3VdbeResolveLabel(v, lbl1); + if( pHaving && sqlite3ExprAnalyzeAggregates(&sNC, pHaving) ){ + goto select_end; } - for(i=0, pAgg=pParse->aAgg; inAgg; i++, pAgg++){ - Expr *pE; - 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 ); - nExpr = sqlite3ExprCodeExprList(pParse, pE->pList); - sqlite3VdbeAddOp(v, OP_Integer, i, 0); - if( pDef->needCollSeq ){ - CollSeq *pColl = 0; - int j; - for(j=0; !pColl && jpList->a[j].pExpr); + sAggInfo.nAccumulator = sAggInfo.nColumn; + for(i=0; ipList) ){ + goto select_end; + } + } + if( sqlite3_malloc_failed ) goto select_end; + + /* Processing for aggregates with GROUP BY is very different and + ** much more complex tha aggregates without a GROUP BY. + */ + if( pGroupBy ){ + KeyInfo *pKeyInfo; /* Keying information for the group by clause */ + + /* Create labels that we will be needing + */ + + addrInitializeLoop = sqlite3VdbeMakeLabel(v); + addrGroupByChange = sqlite3VdbeMakeLabel(v); + addrProcessRow = sqlite3VdbeMakeLabel(v); + + /* If there is a GROUP BY clause we might need a sorting index to + ** implement it. Allocate that sorting index now. If it turns out + ** that we do not need it after all, the OpenVirtual instruction + ** will be converted into a Noop. + */ + sAggInfo.sortingIdx = pParse->nTab++; + pKeyInfo = keyInfoFromExprList(pParse, pGroupBy); + addrSortingIdx = + sqlite3VdbeOp3(v, OP_OpenVirtual, sAggInfo.sortingIdx, + sAggInfo.nSortingColumn, + (char*)pKeyInfo, P3_KEYINFO_HANDOFF); + + /* Initialize memory locations used by GROUP BY aggregate processing + */ + iUseFlag = pParse->nMem++; + iAbortFlag = pParse->nMem++; + iAMem = pParse->nMem; + pParse->nMem += pGroupBy->nExpr; + iBMem = pParse->nMem; + pParse->nMem += pGroupBy->nExpr; + sqlite3VdbeAddOp(v, OP_Integer, 0, 0); + sqlite3VdbeAddOp(v, OP_MemStore, iAbortFlag, 0); + sqlite3VdbeAddOp(v, OP_MemStore, iUseFlag, 1); + sqlite3VdbeAddOp(v, OP_Null, 0, 0); + sqlite3VdbeAddOp(v, OP_MemStore, iAMem, 1); + sqlite3VdbeAddOp(v, OP_Goto, 0, addrInitializeLoop); + + /* Generate a subroutine that outputs a single row of the result + ** set. This subroutine first looks at the iUseFlag. If iUseFlag + ** is less than or equal to zero, the subroutine is a no-op. If + ** the processing calls for the query to abort, this subroutine + ** increments the iAbortFlag memory location before returning in + ** order to signal the caller to abort. + */ + addrSetAbort = sqlite3VdbeCurrentAddr(v); + sqlite3VdbeAddOp(v, OP_MemIncr, iAbortFlag, 0); + sqlite3VdbeAddOp(v, OP_Return, 0, 0); + addrOutputRow = sqlite3VdbeCurrentAddr(v); + sqlite3VdbeAddOp(v, OP_IfMemPos, iUseFlag, addrOutputRow+2); + sqlite3VdbeAddOp(v, OP_Return, 0, 0); + finalizeAggFunctions(pParse, &sAggInfo); + if( pHaving ){ + sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, 1); + } + rc = selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy, + distinct, eDest, iParm, + addrOutputRow+1, addrSetAbort, aff); + if( rc ){ + goto select_end; + } + sqlite3VdbeAddOp(v, OP_Return, 0, 0); + + /* Begin a loop that will extract all source rows in GROUP BY order. + ** This might involve two separate loops with an OP_Sort in between, or + ** it might be a single loop that uses an index to extract information + ** in the right order to begin with. + */ + sqlite3VdbeResolveLabel(v, addrInitializeLoop); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy); + if( pWInfo==0 ) goto select_end; + if( pGroupBy==0 ){ + /* The optimizer is able to deliver rows in group by order so + ** we do not have to sort. The OP_OpenVirtual table will be + ** cancelled later because we still need to use the pKeyInfo + */ + pGroupBy = p->pGroupBy; + groupBySort = 0; + }else{ + /* Rows are coming out in undetermined order. We have to push + ** each row into a sorting index, terminate the first loop, + ** then loop over the sorting index in order to get the output + ** in sorted order + */ + groupBySort = 1; + sqlite3ExprCodeExprList(pParse, pGroupBy); + sqlite3VdbeAddOp(v, OP_Sequence, sAggInfo.sortingIdx, 0); + j = pGroupBy->nExpr+1; + for(i=0; iiSorterColumniColumn<0 ){ + sqlite3VdbeAddOp(v, OP_Rowid, pCol->iTable, 0); + }else{ + sqlite3VdbeAddOp(v, OP_Column, pCol->iTable, pCol->iColumn); + } + j++; } - if( !pColl ) pColl = pParse->db->pDfltColl; - sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ); + sqlite3VdbeAddOp(v, OP_MakeRecord, j, 0); + sqlite3VdbeAddOp(v, OP_IdxInsert, sAggInfo.sortingIdx, 0); + sqlite3WhereEnd(pWInfo); + sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, addrEnd); + sAggInfo.useSortingIdx = 1; } - sqlite3VdbeOp3(v, OP_AggFunc, 0, nExpr, (char*)pDef, P3_FUNCDEF); - } - } - /* End the database scan loop. - */ - sqlite3WhereEnd(pWInfo); + /* Evaluate the current GROUP BY terms and store in b0, b1, b2... + ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth) + ** Then compare the current GROUP BY terms against the GROUP BY terms + ** from the previous row currently stored in a0, a1, a2... + */ + addrTopOfLoop = sqlite3VdbeCurrentAddr(v); + for(j=0; jnExpr; j++){ + if( groupBySort ){ + sqlite3VdbeAddOp(v, OP_Column, sAggInfo.sortingIdx, j); + }else{ + sAggInfo.directMode = 1; + sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr); + } + sqlite3VdbeAddOp(v, OP_MemStore, iBMem+j, jnExpr-1); + } + for(j=pGroupBy->nExpr-1; j>=0; j--){ + if( jnExpr-1 ){ + sqlite3VdbeAddOp(v, OP_MemLoad, iBMem+j, 0); + } + sqlite3VdbeAddOp(v, OP_MemLoad, iAMem+j, 0); + if( j==0 ){ + sqlite3VdbeAddOp(v, OP_Eq, 0, addrProcessRow); + }else{ + sqlite3VdbeAddOp(v, OP_Ne, 0x100, addrGroupByChange); + } + sqlite3VdbeChangeP3(v, -1, (void*)pKeyInfo->aColl[j], P3_COLLSEQ); + } - /* If we are processing aggregates, we need to set up a second loop - ** over all of the aggregate values and process them. - */ - if( isAgg ){ - int endagg = sqlite3VdbeMakeLabel(v); - int startagg; - startagg = sqlite3VdbeAddOp(v, OP_AggNext, 0, endagg); - if( pHaving ){ - sqlite3ExprIfFalse(pParse, pHaving, startagg, 1); + /* Generate code that runs whenever the GROUP BY changes. + ** Change in the GROUP BY are detected by the previous code + ** block. If there were no changes, this block is skipped. + ** + ** This code copies current group by terms in b0,b1,b2,... + ** over to a0,a1,a2. It then calls the output subroutine + ** and resets the aggregate accumulator registers in preparation + ** for the next GROUP BY batch. + */ + sqlite3VdbeResolveLabel(v, addrGroupByChange); + for(j=0; jnExpr; j++){ + sqlite3VdbeAddOp(v, OP_MemLoad, iBMem+j, 0); + sqlite3VdbeAddOp(v, OP_MemStore, iAMem+j, 1); + } + sqlite3VdbeAddOp(v, OP_Gosub, 0, addrOutputRow); + sqlite3VdbeAddOp(v, OP_IfMemPos, iAbortFlag, addrEnd); + resetAccumulator(pParse, &sAggInfo); + + /* Update the aggregate accumulators based on the content of + ** the current row + */ + sqlite3VdbeResolveLabel(v, addrProcessRow); + updateAccumulator(pParse, &sAggInfo); + sqlite3VdbeAddOp(v, OP_MemIncr, iUseFlag, 0); + + /* End of the loop + */ + if( groupBySort ){ + sqlite3VdbeAddOp(v, OP_Next, sAggInfo.sortingIdx, addrTopOfLoop); + }else{ + sqlite3WhereEnd(pWInfo); + uncreateSortingIndex(pParse, addrSortingIdx); + } + + /* Output the final row of result + */ + sqlite3VdbeAddOp(v, OP_Gosub, 0, addrOutputRow); + + } /* endif pGroupBy */ + else { + /* This case runs if the aggregate has no GROUP BY clause. The + ** processing is much simpler since there is only a single row + ** of output. + */ + resetAccumulator(pParse, &sAggInfo); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); + if( pWInfo==0 ) goto select_end; + updateAccumulator(pParse, &sAggInfo); + sqlite3WhereEnd(pWInfo); + finalizeAggFunctions(pParse, &sAggInfo); + pOrderBy = 0; + if( pHaving ){ + sqlite3ExprIfFalse(pParse, pHaving, addrEnd, 1); + } + selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, -1, + eDest, iParm, addrEnd, addrEnd, aff); } - if( selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, eDest, - iParm, startagg, endagg, aff) ){ - goto select_end; - } - sqlite3VdbeAddOp(v, OP_Goto, 0, startagg); - sqlite3VdbeResolveLabel(v, endagg); - sqlite3VdbeAddOp(v, OP_Noop, 0, 0); - } + sqlite3VdbeResolveLabel(v, addrEnd); + + } /* endif aggregate query */ /* If there is an ORDER BY clause, then we need to sort the results ** and send them to the callback one by one. @@ -2863,6 +3084,7 @@ ** successful coding of the SELECT. */ select_end: - restoreAggregateInfo(pParse, &sAggInfo); + sqliteFree(sAggInfo.aCol); + sqliteFree(sAggInfo.aFunc); return rc; } ======================================================================== --- sqlite/sqlite3.h 97fec5750fa71f8b162c9571a7e08413de9886ed +++ sqlite/sqlite3.h d1ab08a3d92270801782adad0dad0f31d6df7761 @@ -12,7 +12,7 @@ ** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.136 2005/06/12 22:12:39 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.141 2005/09/08 10:58:52 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -31,7 +31,7 @@ #ifdef SQLITE_VERSION # undef SQLITE_VERSION #endif -#define SQLITE_VERSION "3.2.2" +#define SQLITE_VERSION "3.2.6" /* ** The format of the version string is "X.Y.Z", where @@ -48,7 +48,7 @@ #ifdef SQLITE_VERSION_NUMBER # undef SQLITE_VERSION_NUMBER #endif -#define SQLITE_VERSION_NUMBER 3002002 +#define SQLITE_VERSION_NUMBER 3002006 /* ** The version string is also compiled into the library so that a program @@ -158,7 +158,7 @@ */ #define SQLITE_OK 0 /* Successful result */ #define SQLITE_ERROR 1 /* SQL error or missing database */ -#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */ +#define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */ #define SQLITE_PERM 3 /* Access permission denied */ #define SQLITE_ABORT 4 /* Callback routine requested an abort */ #define SQLITE_BUSY 5 /* The database file is locked */ @@ -168,13 +168,13 @@ #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ -#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */ +#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ #define SQLITE_FULL 13 /* Insertion failed because database is full */ #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ #define SQLITE_EMPTY 16 /* Database is empty */ #define SQLITE_SCHEMA 17 /* The database schema changed */ -#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */ +#define SQLITE_TOOBIG 18 /* NOT USED. Too much data for one row */ #define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */ #define SQLITE_MISMATCH 20 /* Data type mismatch */ #define SQLITE_MISUSE 21 /* Library used incorrectly */ @@ -260,7 +260,6 @@ int sqlite3_complete_last(const char *sql, const char **last); int sqlite3_complete16(const void *sql); - /* ** This routine identifies a callback function that is invoked ** whenever an attempt is made to open a database table that is @@ -375,8 +374,9 @@ ** ** We can use this text in an SQL statement as follows: ** -** sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')", -** callback1, 0, 0, zText); +** char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText); +** sqlite3_exec(db, z, callback1, 0, 0); +** sqlite3_free(z); ** ** Because the %q format string is used, the '\'' character in zText ** is escaped and the SQL generated is as follows: @@ -454,6 +454,7 @@ #define SQLITE_DETACH 25 /* Database Name NULL */ #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ #define SQLITE_REINDEX 27 /* Index Name NULL */ +#define SQLITE_ANALYZE 28 /* Table Name NULL */ /* @@ -465,11 +466,18 @@ #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ /* -** Register a function that is called at every invocation of sqlite3_exec() -** or sqlite3_prepare(). This function can be used (for example) to generate -** a log file of all SQL executed against a database. +** Register a function for tracing SQL command evaluation. The function +** registered by sqlite3_trace() is invoked at the first sqlite3_step() +** for the evaluation of an SQL statement. The function registered by +** sqlite3_profile() runs at the end of each SQL statement and includes +** information on how long that statement ran. +** +** The sqlite3_profile() API is currently considered experimental and +** is subject to change. */ void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); +void *sqlite3_profile(sqlite3*, + void(*xProfile)(void*,const char*,sqlite_uint64), void*); /* ** This routine configures a callback function - the progress callback - that @@ -1004,10 +1012,9 @@ void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); /* -** The pUserData parameter to the sqlite3_create_function() and -** sqlite3_create_aggregate() routines used to register user functions -** is available to the implementation of the function using this -** call. +** The pUserData parameter to the sqlite3_create_function() +** routine used to register user functions is available to +** the implementation of the function using this call. */ void *sqlite3_user_data(sqlite3_context*); ======================================================================== --- sqlite/sqliteInt.h 0722b47bae7acb182bf43be3585537027c63f741 +++ sqlite/sqliteInt.h e78a7c53a97a2e5d8d6370b6836b2921124ac26f @@ -11,12 +11,23 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.387 2005/06/12 21:35:52 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.419 2005/09/17 15:20:27 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* +** Many people are failing to set -DNDEBUG=1 when compiling SQLite. +** Setting NDEBUG makes the code smaller and run faster. So the following +** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 +** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out +** feature. +*/ +#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) +# define NDEBUG 1 +#endif + +/* ** These #defines should enable >2GB file support on Posix if the ** underlying operating system supports it. If the OS lacks ** large file support, or if the OS is windows, these should be no-ops. @@ -209,6 +220,7 @@ struct BusyHandler { int (*xFunc)(void *,int); /* The busy callback */ void *pArg; /* First arg to busy callback */ + int nBusy; /* Incremented with each busy call */ }; /* @@ -298,30 +310,30 @@ /* ** Forward references to structures */ +typedef struct AggInfo AggInfo; +typedef struct AuthContext AuthContext; +typedef struct CollSeq CollSeq; typedef struct Column Column; -typedef struct Table Table; -typedef struct Index Index; +typedef struct Db Db; typedef struct Expr Expr; typedef struct ExprList ExprList; -typedef struct Parse Parse; -typedef struct Token Token; +typedef struct FKey FKey; +typedef struct FuncDef FuncDef; typedef struct IdList IdList; -typedef struct SrcList SrcList; -typedef struct WhereInfo WhereInfo; -typedef struct WhereLevel WhereLevel; -typedef struct Select Select; -typedef struct AggExpr AggExpr; -typedef struct FuncDef FuncDef; -typedef struct Trigger Trigger; -typedef struct TriggerStep TriggerStep; -typedef struct TriggerStack TriggerStack; -typedef struct FKey FKey; -typedef struct Db Db; -typedef struct AuthContext AuthContext; +typedef struct Index Index; typedef struct KeyClass KeyClass; -typedef struct CollSeq CollSeq; typedef struct KeyInfo KeyInfo; typedef struct NameContext NameContext; +typedef struct Parse Parse; +typedef struct Select Select; +typedef struct SrcList SrcList; +typedef struct Table Table; +typedef struct Token Token; +typedef struct TriggerStack TriggerStack; +typedef struct TriggerStep TriggerStep; +typedef struct Trigger Trigger; +typedef struct WhereInfo WhereInfo; +typedef struct WhereLevel WhereLevel; /* ** Each database file to be accessed by the system is an instance @@ -420,8 +432,10 @@ } init; struct Vdbe *pVdbe; /* List of active virtual machines */ int activeVdbeCnt; /* Number of vdbes currently executing */ - void (*xTrace)(void*,const char*); /* Trace function */ - void *pTraceArg; /* Argument to the trace function */ + void (*xTrace)(void*,const char*); /* Trace function */ + void *pTraceArg; /* Argument to the trace function */ + void (*xProfile)(void*,const char*,u64); /* Profiling function */ + void *pProfileArg; /* Argument to profile function */ void *pCommitArg; /* Argument to xCommitCallback() */ int (*xCommitCallback)(void*);/* Invoked at every commit. */ void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); @@ -496,18 +510,25 @@ ** points to a linked list of these structures. */ struct FuncDef { - char *zName; /* SQL name of the function */ - int nArg; /* Number of arguments. -1 means unlimited */ + i16 nArg; /* Number of arguments. -1 means unlimited */ u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ + u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */ + u8 flags; /* Some combination of SQLITE_FUNC_* */ void *pUserData; /* User data parameter */ FuncDef *pNext; /* Next function with same name */ void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ - u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */ + char zName[1]; /* SQL name of the function. MUST BE LAST */ }; /* +** Possible values for FuncDef.flags +*/ +#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ +#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ + +/* ** information about each column of an SQL table is held in an instance ** of this structure. */ @@ -545,11 +566,20 @@ struct CollSeq { char *zName; /* Name of the collating sequence, UTF-8 encoded */ u8 enc; /* Text encoding handled by xCmp() */ + u8 type; /* One of the SQLITE_COLL_... values below */ void *pUser; /* First argument to xCmp() */ int (*xCmp)(void*,int, const void*, int, const void*); }; /* +** Allowed values of CollSeq flags: +*/ +#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ +#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ +#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ +#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ + +/* ** A sort order can be either ASC or DESC. */ #define SQLITE_SO_ASC 0 /* Sort in ascending order */ @@ -745,6 +775,7 @@ char *zName; /* Name of this index */ int nColumn; /* Number of columns in the table used by this index */ int *aiColumn; /* Which columns are used by this index. 1st is 0 */ + unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ Table *pTable; /* The SQL table being indexed */ int tnum; /* Page containing root of this index in database file */ u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ @@ -770,6 +801,49 @@ }; /* +** An instance of this structure contains information needed to generate +** code for a SELECT that contains aggregate functions. +** +** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a +** pointer to this structure. The Expr.iColumn field is the index in +** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate +** code for that node. +** +** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the +** original Select structure that describes the SELECT statement. These +** fields do not need to be freed when deallocating the AggInfo structure. +*/ +struct AggInfo { + u8 directMode; /* Direct rendering mode means take data directly + ** from source tables rather than from accumulators */ + u8 useSortingIdx; /* In direct mode, reference the sorting index rather + ** than the source table */ + int sortingIdx; /* Cursor number of the sorting index */ + ExprList *pGroupBy; /* The group by clause */ + int nSortingColumn; /* Number of columns in the sorting index */ + struct AggInfo_col { /* For each column used in source tables */ + int iTable; /* Cursor number of the source table */ + int iColumn; /* Column number within the source table */ + int iSorterColumn; /* Column number in the sorting index */ + int iMem; /* Memory location that acts as accumulator */ + Expr *pExpr; /* The original expression */ + } *aCol; + int nColumn; /* Number of used entries in aCol[] */ + int nColumnAlloc; /* Number of slots allocated for aCol[] */ + int nAccumulator; /* Number of columns that show through to the output. + ** Additional columns are used only as parameters to + ** aggregate functions */ + struct AggInfo_func { /* For each aggregate function */ + Expr *pExpr; /* Expression encoding the function */ + FuncDef *pFunc; /* The aggregate function implementation */ + int iMem; /* Memory location that acts as accumulator */ + int iDistinct; /* Virtual table used to enforce DISTINCT */ + } *aFunc; + int nFunc; /* Number of entries in aFunc[] */ + int nFuncAlloc; /* Number of slots allocated for aFunc[] */ +}; + +/* ** Each node of an expression in the parse tree is an instance ** of this structure. ** @@ -828,9 +902,8 @@ Token span; /* Complete text of the expression */ int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the ** iColumn-th field of the iTable-th table. */ - int iAgg; /* When op==TK_COLUMN and pParse->fillAgg==FALSE, pull - ** result from the iAgg-th element of the aggregator */ - int iAggCtx; /* The value to pass as P1 of OP_AggGet. */ + AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ + int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ Select *pSelect; /* When the expression is a sub-select. Also the ** right side of " IN (