Index: ext/lsm1/Makefile ================================================================== --- ext/lsm1/Makefile +++ ext/lsm1/Makefile @@ -2,11 +2,11 @@ # # This is a temporary makefile for use during experimental development. # Replace with something more portable, if the experiments actually work out. # CC = gcc -CFLAGS =-g -fPIC -Wall -I. -I/home/drh/sqlite/bld +CFLAGS =-g -fPIC -Wall -I. -I../.. LSMOBJ = \ lsm_ckpt.o \ lsm_file.o \ lsm_log.o \ Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -1047,22 +1047,23 @@ begin_table_error: sqlite3DbFree(db, zName); return; } -/* -** This macro is used to compare two strings in a case-insensitive manner. -** It is slightly faster than calling sqlite3StrICmp() directly, but -** produces larger code. -** -** WARNING: This macro is not compatible with the strcmp() family. It -** returns true if the two strings are equal, otherwise false. +/* Set properties of a table column based on the (magical) +** name of the column. */ -#define STRICMP(x, y) (\ -sqlite3UpperToLower[*(unsigned char *)(x)]== \ -sqlite3UpperToLower[*(unsigned char *)(y)] \ -&& sqlite3StrICmp((x)+1,(y)+1)==0 ) +void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){ +#if SQLITE_ENABLE_HIDDEN_COLUMNS + if( sqlite3_strnicmp(pCol->zName, "__hidden__", 10)==0 ){ + pCol->colFlags |= COLFLAG_HIDDEN; + }else if( pTab && pCol!=pTab->aCol && (pCol[-1].colFlags & COLFLAG_HIDDEN) ){ + pTab->tabFlags |= TF_OOOHidden; + } +#endif +} + /* ** Add a new column to the table currently being constructed. ** ** The parser calls this routine once for each column declaration @@ -1084,11 +1085,11 @@ } #endif z = sqlite3NameFromToken(db, pName); if( z==0 ) return; for(i=0; inCol; i++){ - if( STRICMP(z, p->aCol[i].zName) ){ + if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); sqlite3DbFree(db, z); return; } } @@ -1102,10 +1103,11 @@ p->aCol = aNew; } pCol = &p->aCol[p->nCol]; memset(pCol, 0, sizeof(p->aCol[0])); pCol->zName = z; + sqlite3ColumnPropertiesFromName(p, pCol); /* If there is no type specified, columns have the default affinity ** 'BLOB'. If there is a type specified, then sqlite3AddColumnType() will ** be called next to set pCol->affinity correctly. */ Index: src/delete.c ================================================================== --- src/delete.c +++ src/delete.c @@ -104,11 +104,12 @@ pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName); pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); assert( pFrom->a[0].pOn==0 ); assert( pFrom->a[0].pUsing==0 ); } - pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); + pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, + SF_IncludeHidden, 0, 0); sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); sqlite3Select(pParse, pSel, &dest); sqlite3SelectDelete(db, pSel); } #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ Index: src/insert.c ================================================================== --- src/insert.c +++ src/insert.c @@ -734,14 +734,12 @@ } /* Make sure the number of columns in the source data matches the number ** of columns to be inserted into the table. */ - if( IsVirtual(pTab) ){ - for(i=0; inCol; i++){ - nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0); - } + for(i=0; inCol; i++){ + nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0); } if( pColumn==0 && nColumn && nColumn!=(pTab->nCol-nHidden) ){ sqlite3ErrorMsg(pParse, "table %S has %d columns but %d values were supplied", pTabList, 0, pTab->nCol-nHidden, nColumn); @@ -833,26 +831,26 @@ */ assert( !IsVirtual(pTab) ); /* Create the new column data */ - for(i=0; inCol; i++){ - if( pColumn==0 ){ - j = i; - }else{ + for(i=j=0; inCol; i++){ + if( pColumn ){ for(j=0; jnId; j++){ if( pColumn->a[j].idx==i ) break; } } - if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){ + if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) + || (pColumn==0 && IsOrdinaryHiddenColumn(&pTab->aCol[i])) ){ sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1); }else if( useTempTable ){ sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1); }else{ assert( pSelect==0 ); /* Otherwise useTempTable is true */ sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1); } + if( pColumn==0 && !IsOrdinaryHiddenColumn(&pTab->aCol[i]) ) j++; } /* If this is an INSERT on a view with an INSTEAD OF INSERT trigger, ** do not attempt any conversions before assembling the record. ** If this is a real table, attempt conversions as required by the @@ -932,11 +930,10 @@ sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore); continue; } if( pColumn==0 ){ if( IsHiddenColumn(&pTab->aCol[i]) ){ - assert( IsVirtual(pTab) ); j = -1; nHidden++; }else{ j = i - nHidden; } @@ -1874,11 +1871,11 @@ assert( pEList!=0 ); if( pEList->nExpr!=1 ){ return 0; /* The result set must have exactly one column */ } assert( pEList->a[0].pExpr ); - if( pEList->a[0].pExpr->op!=TK_ALL ){ + if( pEList->a[0].pExpr->op!=TK_ASTERISK ){ return 0; /* The result set must be the special operator "*" */ } /* At this point we have established that the statement is of the ** correct syntactic form to participate in this optimization. Now @@ -1910,10 +1907,17 @@ return 0; /* Both tables must have the same INTEGER PRIMARY KEY */ } for(i=0; inCol; i++){ Column *pDestCol = &pDest->aCol[i]; Column *pSrcCol = &pSrc->aCol[i]; +#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS + if( (db->flags & SQLITE_Vacuum)==0 + && (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN + ){ + return 0; /* Neither table may have __hidden__ columns */ + } +#endif if( pDestCol->affinity!=pSrcCol->affinity ){ return 0; /* Affinity must be the same on all columns */ } if( !xferCompatibleCollation(pDestCol->zColl, pSrcCol->zColl) ){ return 0; /* Collating sequence must be the same on all columns */ Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -3347,11 +3347,11 @@ } } } #endif -#if SQLITE_MAX_MMAP_SIZE>0 +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 /* Deal with as much of this write request as possible by transfering ** data from the memory mapping using memcpy(). */ if( offsetmmapSize ){ if( offset+amt <= pFile->mmapSize ){ memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); @@ -4772,11 +4772,13 @@ assert( nNew<=pFd->mmapSizeMax ); assert( nNew>0 ); assert( pFd->mmapSizeActual>=pFd->mmapSize ); assert( MAP_FAILED!=0 ); +#ifdef SQLITE_MMAP_READWRITE if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; +#endif if( pOrig ){ #if HAVE_MREMAP i64 nReuse = pFd->mmapSize; #else Index: src/os_win.c ================================================================== --- src/os_win.c +++ src/os_win.c @@ -2600,11 +2600,11 @@ OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, pFile->h, pBuf, amt, offset, pFile->locktype)); -#if SQLITE_MAX_MMAP_SIZE>0 +#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 /* Deal with as much of this write request as possible by transfering ** data from the memory mapping using memcpy(). */ if( offsetmmapSize ){ if( offset+amt <= pFile->mmapSize ){ memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); @@ -4094,14 +4094,16 @@ void *pNew = 0; DWORD protect = PAGE_READONLY; DWORD flags = FILE_MAP_READ; winUnmapfile(pFd); +#ifdef SQLITE_MMAP_READWRITE if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ protect = PAGE_READWRITE; flags |= FILE_MAP_WRITE; } +#endif #if SQLITE_OS_WINRT pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); #elif defined(SQLITE_WIN32_HAS_WIDE) pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, (DWORD)((nMap>>32) & 0xffffffff), Index: src/parse.y ================================================================== --- src/parse.y +++ src/parse.y @@ -544,11 +544,11 @@ distinct(A) ::= . {A = 0;} // selcollist is a list of expressions that are to become the return // values of the SELECT statement. The "*" in statements like // "SELECT * FROM ..." is encoded as a special expression with an -// opcode of TK_ALL. +// opcode of TK_ASTERISK. // %type selcollist {ExprList*} %destructor selcollist {sqlite3ExprListDelete(pParse->db, $$);} %type sclp {ExprList*} %destructor sclp {sqlite3ExprListDelete(pParse->db, $$);} @@ -558,15 +558,15 @@ A = sqlite3ExprListAppend(pParse, P, X.pExpr); if( Y.n>0 ) sqlite3ExprListSetName(pParse, A, &Y, 1); sqlite3ExprListSetSpan(pParse,A,&X); } selcollist(A) ::= sclp(P) STAR. { - Expr *p = sqlite3Expr(pParse->db, TK_ALL, 0); + Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0); A = sqlite3ExprListAppend(pParse, P, p); } selcollist(A) ::= sclp(P) nm(X) DOT STAR(Y). { - Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &Y); + Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0, &Y); Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); A = sqlite3ExprListAppend(pParse,P, pDot); } Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -116,11 +116,11 @@ assert( db->mallocFailed ); pNew = &standin; memset(pNew, 0, sizeof(*pNew)); } if( pEList==0 ){ - pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ALL,0)); + pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0)); } pNew->pEList = pEList; if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc)); pNew->pSrc = pSrc; pNew->pWhere = pWhere; @@ -1657,10 +1657,11 @@ } zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); } pCol->zName = zName; + sqlite3ColumnPropertiesFromName(0, pCol); if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ db->mallocFailed = 1; } } sqlite3HashClear(&ht); @@ -3935,11 +3936,11 @@ memset(&dummy, 0, sizeof(dummy)); pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0,0); if( pNewSrc==0 ) return WRC_Abort; *pNew = *p; p->pSrc = pNewSrc; - p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ALL, 0)); + p->pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ASTERISK, 0)); p->op = TK_SELECT; p->pWhere = 0; pNew->pGroupBy = 0; pNew->pHaving = 0; pNew->pOrderBy = 0; @@ -4276,23 +4277,24 @@ } /* For every "*" that occurs in the column list, insert the names of ** all columns in all tables. And for every TABLE.* insert the names ** of all columns in TABLE. The parser inserted a special expression - ** with the TK_ALL operator for each "*" that it found in the column list. - ** The following code just has to locate the TK_ALL expressions and expand - ** each one to the list of all columns in all tables. + ** with the TK_ASTERISK operator for each "*" that it found in the column + ** list. The following code just has to locate the TK_ASTERISK + ** expressions and expand each one to the list of all columns in + ** all tables. ** ** The first loop just checks to see if there are any "*" operators ** that need expanding. */ for(k=0; knExpr; k++){ pE = pEList->a[k].pExpr; - if( pE->op==TK_ALL ) break; + if( pE->op==TK_ASTERISK ) break; assert( pE->op!=TK_DOT || pE->pRight!=0 ); assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) ); - if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break; + if( pE->op==TK_DOT && pE->pRight->op==TK_ASTERISK ) break; } if( knExpr ){ /* ** If we get here it means the result set contains one or more "*" ** operators that need to be expanded. Loop through each expression @@ -4306,11 +4308,13 @@ for(k=0; knExpr; k++){ pE = a[k].pExpr; pRight = pE->pRight; assert( pE->op!=TK_DOT || pRight!=0 ); - if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pRight->op!=TK_ALL) ){ + if( pE->op!=TK_ASTERISK + && (pE->op!=TK_DOT || pRight->op!=TK_ASTERISK) + ){ /* This particular expression does not need to be expanded. */ pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); if( pNew ){ pNew->a[pNew->nExpr-1].zName = a[k].zName; @@ -4358,16 +4362,17 @@ && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0 ){ continue; } - /* If a column is marked as 'hidden' (currently only possible - ** for virtual tables), do not include it in the expanded - ** result-set list. + /* If a column is marked as 'hidden', omit it from the expanded + ** result-set list unless the SELECT has the SF_IncludeHidden + ** bit set. */ - if( IsHiddenColumn(&pTab->aCol[j]) ){ - assert(IsVirtual(pTab)); + if( (p->selFlags & SF_IncludeHidden)==0 + && IsHiddenColumn(&pTab->aCol[j]) + ){ continue; } tableSeen = 1; if( i>0 && zTName==0 ){ Index: src/shell.c ================================================================== --- src/shell.c +++ src/shell.c @@ -2558,11 +2558,11 @@ { "number of views:", "SELECT count(*) FROM %s WHERE type='view'" }, { "schema size:", "SELECT total(length(sql)) FROM %s" }, }; - sqlite3_file *pFile; + sqlite3_file *pFile = 0; int i; char *zSchemaTab; char *zDb = nArg>=2 ? azArg[1] : "main"; unsigned char aHdr[100]; open_db(p, 0); Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -1671,11 +1671,11 @@ }; /* ** Allowed values for Table.tabFlags. ** -** TF_OOOHidden applies to virtual tables that have hidden columns that are +** TF_OOOHidden applies to tables or view that have hidden columns that are ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, ** the TF_OOOHidden attribute would apply in this case. Such tables require ** special handling during INSERT processing. */ @@ -1694,15 +1694,31 @@ ** done as a macro so that it will be optimized out when virtual ** table support is omitted from the build. */ #ifndef SQLITE_OMIT_VIRTUALTABLE # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) -# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) #else # define IsVirtual(X) 0 -# define IsHiddenColumn(X) 0 #endif + +/* +** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() +** only works for non-virtual tables (ordinary tables and views) and is +** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The +** IsHiddenColumn() macro is general purpose. +*/ +#if defined(SQLITE_ENABLE_HIDDEN_COLUMNS) +# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) +# define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) +#elif !defined(SQLITE_OMIT_VIRTUALTABLE) +# define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) +# define IsOrdinaryHiddenColumn(X) 0 +#else +# define IsHiddenColumn(X) 0 +# define IsOrdinaryHiddenColumn(X) 0 +#endif + /* Does the table have a rowid */ #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0) #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0) @@ -2493,10 +2509,11 @@ #define SF_NestedFrom 0x0400 /* Part of a parenthesized FROM clause */ #define SF_MaybeConvert 0x0800 /* Need convertCompoundSelectToSubquery() */ #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */ #define SF_Recursive 0x2000 /* The recursive part of a recursive CTE */ #define SF_Converted 0x4000 /* By convertCompoundSelectToSubquery() */ +#define SF_IncludeHidden 0x8000 /* Include hidden columns in output */ /* ** The results of a SELECT can be distributed in several ways, as defined ** by one of the following macros. The "SRT" prefix means "SELECT Result @@ -3312,10 +3329,11 @@ Table *sqlite3ResultSetOfSelect(Parse*,Select*); void sqlite3OpenMasterTable(Parse *, int); Index *sqlite3PrimaryKeyIndex(Table*); i16 sqlite3ColumnOfIndex(Index*, i16); void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); +void sqlite3ColumnPropertiesFromName(Table*, Column*); void sqlite3AddColumn(Parse*,Token*); void sqlite3AddNotNull(Parse*, int); void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); void sqlite3AddCheckConstraint(Parse*, Expr*); void sqlite3AddColumnType(Parse*,Token*); Index: src/test1.c ================================================================== --- src/test1.c +++ src/test1.c @@ -2236,19 +2236,40 @@ void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ - sqlite3_stmt *pStmt; /* First argument */ if( objc!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, ""); return TCL_ERROR; } sqlite3_config(SQLITE_CONFIG_SQLLOG, 0, 0); return TCL_OK; } #endif + +/* +** Usage: vfs_current_time_int64 +** +** Return the value returned by the default VFS's xCurrentTimeInt64 method. +*/ +static int vfsCurrentTimeInt64( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + i64 t; + sqlite3_vfs *pVfs = sqlite3_vfs_find(0); + if( objc!=1 ){ + Tcl_WrongNumArgs(interp, 1, objv, ""); + return TCL_ERROR; + } + pVfs->xCurrentTimeInt64(pVfs, &t); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(t)); + return TCL_OK; +} /* ** Usage: sqlite3_next_stmt DB STMT ** ** Return the next statment in sequence after STMT. @@ -7059,11 +7080,11 @@ { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset, 0 }, #endif #ifdef SQLITE_ENABLE_SQLLOG { "sqlite3_config_sqllog", test_config_sqllog, 0 }, #endif - + { "vfs_current_time_int64", vfsCurrentTimeInt64, 0 }, }; static int bitmask_size = sizeof(Bitmask)*8; static int longdouble_size = sizeof(LONGDOUBLE_TYPE); int i; extern int sqlite3_sync_count, sqlite3_fullsync_count; Index: src/test_config.c ================================================================== --- src/test_config.c +++ src/test_config.c @@ -122,10 +122,16 @@ #ifdef SQLITE_ENABLE_CURSOR_HINTS Tcl_SetVar2(interp, "sqlite_options", "cursorhints", "1", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "sqlite_options", "cursorhints", "0", TCL_GLOBAL_ONLY); #endif + +#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS + Tcl_SetVar2(interp, "sqlite_options", "hiddencolumns", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "hiddencolumns", "0", TCL_GLOBAL_ONLY); +#endif #ifdef SQLITE_ENABLE_MEMSYS3 Tcl_SetVar2(interp, "sqlite_options", "mem3", "1", TCL_GLOBAL_ONLY); #else Tcl_SetVar2(interp, "sqlite_options", "mem3", "0", TCL_GLOBAL_ONLY); ADDED test/hidden.test Index: test/hidden.test ================================================================== --- /dev/null +++ test/hidden.test @@ -0,0 +1,153 @@ +# 2015 November 18 +# +# 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. +# +#*********************************************************************** +# +# Test the __hidden__ hack. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix hidden + +ifcapable !hiddencolumns { + finish_test + return +} + +do_execsql_test 1.1 { + CREATE TABLE t1(__hidden__a, b); + INSERT INTO t1 VALUES('1'); + INSERT INTO t1(__hidden__a, b) VALUES('x', 'y'); +} {} + +do_execsql_test 1.2 { + SELECT * FROM t1; +} {1 y} + +do_execsql_test 1.3 { + SELECT __hidden__a, * FROM t1; +} {{} 1 x y} + +foreach {tn view} { + 1 { CREATE VIEW v1(a, b, __hidden__c) AS SELECT a, b, c FROM x1 } + 2 { CREATE VIEW v1 AS SELECT a, b, c AS __hidden__c FROM x1 } +} { + do_execsql_test 2.$tn.1 { + DROP TABLE IF EXISTS x1; + CREATE TABLE x1(a, b, c); + INSERT INTO x1 VALUES(1, 2, 3); + } + + catchsql { DROP VIEW v1 } + execsql $view + + do_execsql_test 2.$tn.2 { + SELECT a, b, __hidden__c FROM v1; + } {1 2 3} + + do_execsql_test 2.$tn.3 { + SELECT * FROM v1; + } {1 2} + + do_execsql_test 2.$tn.4 { + CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN + INSERT INTO x1 VALUES(new.a, new.b, new.__hidden__c); + END; + + INSERT INTO v1 VALUES(4, 5); + SELECT * FROM x1; + } {1 2 3 4 5 {}} + + do_execsql_test 2.$tn.5 { + INSERT INTO v1(a, b, __hidden__c) VALUES(7, 8, 9); + SELECT * FROM x1; + } {1 2 3 4 5 {} 7 8 9} +} + +#------------------------------------------------------------------------- +# Test INSERT INTO ... SELECT ... statements that write to tables with +# hidden columns. +# +do_execsql_test 3.1 { + CREATE TABLE t4(a, __hidden__b, c); + INSERT INTO t4 SELECT 1, 2; + SELECT a, __hidden__b, c FROM t4; +} {1 {} 2} + +do_execsql_test 3.2.1 { + CREATE TABLE t5(__hidden__a, b, c); + CREATE TABLE t6(__hidden__a, b, c); + INSERT INTO t6(__hidden__a, b, c) VALUES(1, 2, 3); + INSERT INTO t6(__hidden__a, b, c) VALUES(4, 5, 6); + INSERT INTO t6(__hidden__a, b, c) VALUES(7, 8, 9); +} + +do_execsql_test 3.2.2 { + INSERT INTO t5 SELECT * FROM t6; + SELECT * FROM t5; +} {2 3 5 6 8 9} + +do_execsql_test 3.2.3 { + SELECT __hidden__a FROM t5; +} {{} {} {}} + + +do_execsql_test 3.3.1 { + CREATE TABLE t5a(a, b, __hidden__c); + CREATE TABLE t6a(a, b, __hidden__c); + INSERT INTO t6a(a, b, __hidden__c) VALUES(1, 2, 3); + INSERT INTO t6a(a, b, __hidden__c) VALUES(4, 5, 6); + INSERT INTO t6a(a, b, __hidden__c) VALUES(7, 8, 9); +} + +do_execsql_test 3.3.2 { + INSERT INTO t5a SELECT * FROM t6a; + SELECT * FROM t5a; +} {1 2 4 5 7 8} + +do_execsql_test 3.3.3 { + SELECT __hidden__c FROM t5a; +} {{} {} {}} + +do_execsql_test 3.4.1 { + CREATE TABLE t5b(a, __hidden__b, c); + CREATE TABLE t6b(a, b, __hidden__c); + INSERT INTO t6b(a, b, __hidden__c) VALUES(1, 2, 3); + INSERT INTO t6b(a, b, __hidden__c) VALUES(4, 5, 6); + INSERT INTO t6b(a, b, __hidden__c) VALUES(7, 8, 9); +} + +do_execsql_test 3.4.2 { + INSERT INTO t5b SELECT * FROM t6b; + SELECT * FROM t5b; +} {1 2 4 5 7 8} + +do_execsql_test 3.4.3 { + SELECT __hidden__b FROM t5b; +} {{} {} {}} + +#------------------------------------------------------------------------- +# Test VACUUM +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t1(a, __hidden__b, c UNIQUE); + INSERT INTO t1(a, __hidden__b, c) VALUES(1, 2, 3); + INSERT INTO t1(a, __hidden__b, c) VALUES(4, 5, 6); + INSERT INTO t1(a, __hidden__b, c) VALUES(7, 8, 9); + DELETE FROM t1 WHERE __hidden__b = 5; + SELECT rowid, a, __hidden__b, c FROM t1; +} {1 1 2 3 3 7 8 9} +do_execsql_test 4.2 { + VACUUM; + SELECT rowid, a, __hidden__b, c FROM t1; +} {1 1 2 3 3 7 8 9} + +finish_test Index: test/releasetest.tcl ================================================================== --- test/releasetest.tcl +++ test/releasetest.tcl @@ -117,10 +117,11 @@ -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_MEMSYS5=1 -DSQLITE_ENABLE_MEMSYS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_STAT4 + -DSQLITE_ENABLE_HIDDEN_COLUMNS -DSQLITE_MAX_ATTACHED=125 } "Fast-One" { -O6 -DSQLITE_ENABLE_FTS4=1 @@ -143,10 +144,11 @@ -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 -DSQLITE_MAX_PAGE_SIZE=4096 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_OMIT_PROGRESS_CALLBACK=1 -DSQLITE_OMIT_VIRTUALTABLE=1 + -DSQLITE_ENABLE_HIDDEN_COLUMNS -DSQLITE_TEMP_STORE=3 --enable-json1 } "Device-Two" { -DSQLITE_4_BYTE_ALIGNED_MALLOC=1 @@ -211,10 +213,11 @@ } "Valgrind" { -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE + -DSQLITE_ENABLE_HIDDEN_COLUMNS --enable-json1 } # The next group of configurations are used only by the # Failure-Detection platform. They are all the same, but we need Index: tool/addopcodes.tcl ================================================================== --- tool/addopcodes.tcl +++ tool/addopcodes.tcl @@ -35,10 +35,11 @@ AGG_FUNCTION AGG_COLUMN UMINUS UPLUS REGISTER + ASTERISK SPACE ILLEGAL } if {[lrange $extras end-1 end]!="SPACE ILLEGAL"} { error "SPACE and ILLEGAL must be the last two token codes and they\ Index: tool/mkkeywordhash.c ================================================================== --- tool/mkkeywordhash.c +++ tool/mkkeywordhash.c @@ -326,11 +326,11 @@ /* ** This routine does the work. The generated code is printed on standard ** output. */ int main(int argc, char **argv){ - int i, j, k, h, m; + int i, j, k, h; int bestSize, bestCount; int count; int nChar; int totalLen = 0; int aHash[1000]; /* 1000 is much bigger than nKeyword */