diff --git a/Makefile.in b/Makefile.in index 1766ca580e..96ef34009e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -180,7 +180,7 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \ func.lo global.lo hash.lo \ icu.lo insert.lo json1.lo legacy.lo loadext.lo \ main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \ - memjournal.lo \ + memdb.lo memjournal.lo \ mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \ notify.lo opcodes.lo os.lo os_unix.lo os_win.lo \ pager.lo parse.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \ @@ -240,6 +240,7 @@ SRC = \ $(TOP)/src/mem2.c \ $(TOP)/src/mem3.c \ $(TOP)/src/mem5.c \ + $(TOP)/src/memdb.c \ $(TOP)/src/memjournal.c \ $(TOP)/src/msvc.h \ $(TOP)/src/mutex.c \ @@ -649,6 +650,9 @@ ossshell$(TEXE): $(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c sqlite3. $(LTLINK) -o $@ $(FUZZCHECK_OPT) $(TOP)/test/ossshell.c \ $(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS) +sessionfuzz$(TEXE): $(TOP)/test/sessionfuzz.c sqlite3.c sqlite3.h + $(CC) $(CFLAGS) -I. -o $@ $(TOP)/test/sessionfuzz.c $(TLIBS) + dbfuzz$(TEXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h $(LTLINK) -o $@ $(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c $(TLIBS) @@ -829,6 +833,9 @@ mem3.lo: $(TOP)/src/mem3.c $(HDR) mem5.lo: $(TOP)/src/mem5.c $(HDR) $(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem5.c +memdb.lo: $(TOP)/src/memdb.c $(HDR) + $(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/memdb.c + memjournal.lo: $(TOP)/src/memjournal.c $(HDR) $(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/memjournal.c @@ -1162,14 +1169,17 @@ fulltestonly: $(TESTPROGS) fuzztest ./testfixture$(TEXE) $(TOP)/test/full.test # Fuzz testing -fuzztest: fuzzcheck$(TEXE) $(FUZZDATA) +fuzztest: fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db ./fuzzcheck$(TEXE) $(FUZZDATA) + ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db -fastfuzztest: fuzzcheck$(TEXE) $(FUZZDATA) +fastfuzztest: fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db ./fuzzcheck$(TEXE) --limit-mem 100M $(FUZZDATA) + ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db -valgrindfuzz: fuzzcheck$(TEXT) $(FUZZDATA) +valgrindfuzz: fuzzcheck$(TEXT) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA) + valgrind ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db # The veryquick.test TCL tests. # diff --git a/Makefile.msc b/Makefile.msc index 1b2bcb55ac..bb64a05d11 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1186,7 +1186,7 @@ LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \ func.lo global.lo hash.lo \ icu.lo insert.lo legacy.lo loadext.lo \ main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \ - memjournal.lo \ + memdb.lo memjournal.lo \ mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \ notify.lo opcodes.lo os.lo os_unix.lo os_win.lo \ pager.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \ @@ -1259,6 +1259,7 @@ SRC00 = \ $(TOP)\src\mem2.c \ $(TOP)\src\mem3.c \ $(TOP)\src\mem5.c \ + $(TOP)\src\memdb.c \ $(TOP)\src\memjournal.c \ $(TOP)\src\mutex.c \ $(TOP)\src\mutex_noop.c \ @@ -1620,7 +1621,6 @@ FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION KV_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ -DBSELFTEST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 ST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 # Standard options to testfixture. @@ -1688,7 +1688,7 @@ dbhash.exe: $(TOP)\tool\dbhash.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(TOP)\tool\dbhash.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) scrub.exe: $(TOP)\ext\misc\scrub.c $(SQLITE3C) $(SQLITE3H) - $(LTLINK) $(NO_WARN) $(TOP)\ext\misc\scrub.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) + $(LTLINK) $(NO_WARN) -DSCRUB_STANDALONE=1 $(TOP)\ext\misc\scrub.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) srcck1.exe: $(TOP)\tool\srcck1.c $(BCC) $(NO_WARN) -Fe$@ $(TOP)\tool\srcck1.c @@ -1708,6 +1708,9 @@ fuzzcheck.exe: $(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H) ossshell.exe: $(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) +sessionfuzz.exe: zlib $(TOP)\test\sessionfuzz.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) -I$(ZLIBINCDIR) $(TOP)\test\sessionfuzz.c /link $(LDFLAGS) $(LTLINKOPTS) /LIBPATH:$(ZLIBLIBDIR) $(ZLIBLIB) + mptester.exe: $(TOP)\mptest\mptest.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(MPTESTER_COMPILE_OPTS) $(TOP)\mptest\mptest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) @@ -1909,6 +1912,9 @@ mem3.lo: $(TOP)\src\mem3.c $(HDR) mem5.lo: $(TOP)\src\mem5.c $(HDR) $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\mem5.c +memdb.lo: $(TOP)\src\memdb.c $(HDR) + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\memdb.c + memjournal.lo: $(TOP)\src\memjournal.c $(HDR) $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\memjournal.c @@ -2366,11 +2372,11 @@ sqlite3_checker.exe: sqlite3_checker.c $(LIBRESOBJS) $(LTLINK) $(NO_WARN) -DBUILD_sqlite -I$(TCLINCDIR) sqlite3_checker.c \ /link $(LDFLAGS) $(LTLINKOPTS) $(TCLLIBPATHS) $(LTLIBPATHS) $(LIBRESOBJS) $(TCLLIBS) $(LTLIBS) $(TLIBS) -dbdump.exe: $(TOP)\ext\misc\dbdump.c $(SQLITE3C) $(SQLITE3H) +dbdump.exe: $(TOP)\ext\misc\dbdump.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS) $(LTLINK) $(NO_WARN) -DDBDUMP_STANDALONE $(TOP)\ext\misc\dbdump.c $(SQLITE3C) \ /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) -testloadext.lo: $(TOP)\src\test_loadext.c +testloadext.lo: $(TOP)\src\test_loadext.c $(SQLITE3H) $(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c testloadext.dll: testloadext.lo @@ -2423,9 +2429,6 @@ kvtest.exe: $(TOP)\test\kvtest.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(KV_COMPILE_OPTS) \ $(TOP)\test\kvtest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) -dbselftest.exe: $(TOP)\test\dbselftest.c $(SQLITE3C) $(SQLITE3H) - $(LTLINK) $(NO_WARN) $(DBSELFTEST_COMPILE_OPTS) $(TOP)\test\dbselftest.c $(SQLITE3C) - rbu.exe: $(TOP)\ext\rbu\rbu.c $(TOP)\ext\rbu\sqlite3rbu.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) -DSQLITE_ENABLE_RBU \ $(TOP)\ext\rbu\rbu.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) @@ -2465,7 +2468,10 @@ clean: del /Q sqlite3_analyzer.exe sqlite3_analyzer.c 2>NUL del /Q sqlite-*-output.vsix 2>NUL del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe dbhash.exe 2>NUL - del /Q sqltclsh.exe 2>NUL + del /Q sqltclsh.* 2>NUL + del /Q dbfuzz.exe sessionfuzz.exe 2>NUL + del /Q kvtest.exe ossshell.exe scrub.exe 2>NUL + del /Q showshm.exe sqlite3_checker.* sqlite3_expert.exe 2>NUL del /Q fts5.* fts5parse.* 2>NUL del /Q lsm.h lsm1.c 2>NUL # <> diff --git a/autoconf/Makefile.msc b/autoconf/Makefile.msc index 5f7c693d42..d99549b966 100644 --- a/autoconf/Makefile.msc +++ b/autoconf/Makefile.msc @@ -931,6 +931,7 @@ LIBRESOBJS = SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_STMTVTAB SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC -DSQLITE_INTROSPECTION_PRAGMAS +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_RTREE !ENDIF diff --git a/ext/expert/expert.c b/ext/expert/expert.c index 13fc87ea89..051480f896 100644 --- a/ext/expert/expert.c +++ b/ext/expert/expert.c @@ -93,8 +93,9 @@ int main(int argc, char **argv){ }else{ for(i=1; i<(argc-1); i++){ char *zArg = argv[i]; + int nArg; if( zArg[0]=='-' && zArg[1]=='-' && zArg[2]!=0 ) zArg++; - int nArg = (int)strlen(zArg); + nArg = (int)strlen(zArg); if( nArg>=2 && 0==sqlite3_strnicmp(zArg, "-file", nArg) ){ if( ++i==(argc-1) ) option_requires_argument("-file"); rc = readSqlFromFile(p, argv[i], &zErr); diff --git a/ext/fts5/fts5_expr.c b/ext/fts5/fts5_expr.c index a86dbebdf9..03c3d703dd 100644 --- a/ext/fts5/fts5_expr.c +++ b/ext/fts5/fts5_expr.c @@ -1676,7 +1676,7 @@ Fts5ExprPhrase *sqlite3Fts5ParseTerm( ** no token characters at all. (e.g ... MATCH '""'). */ sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase)); }else if( sCtx.pPhrase->nTerm ){ - sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = bPrefix; + sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = (u8)bPrefix; } pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase; } diff --git a/ext/misc/completion.c b/ext/misc/completion.c index 79f889abf1..780963515e 100644 --- a/ext/misc/completion.c +++ b/ext/misc/completion.c @@ -78,7 +78,7 @@ struct completion_cursor { #define COMPLETION_INDEXES 5 #define COMPLETION_TRIGGERS 6 #define COMPLETION_DATABASES 7 -#define COMPLETION_TABLES 8 +#define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */ #define COMPLETION_COLUMNS 9 #define COMPLETION_MODULES 10 #define COMPLETION_EOF 11 @@ -250,8 +250,7 @@ static int completionNext(sqlite3_vtab_cursor *cur){ const char *zDb = (const char*)sqlite3_column_text(pS2, 1); zSql = sqlite3_mprintf( "%z%s" - "SELECT name FROM \"%w\".sqlite_master" - " WHERE type='table'", + "SELECT name FROM \"%w\".sqlite_master", zSql, zSep, zDb ); if( zSql==0 ) return SQLITE_NOMEM; diff --git a/ext/misc/dbdump.c b/ext/misc/dbdump.c index 90c2dd4c44..b4d642286e 100644 --- a/ext/misc/dbdump.c +++ b/ext/misc/dbdump.c @@ -293,7 +293,6 @@ static char **tableColumnList(DState *p, const char *zTab){ ** ordinary column in the table. Verify that azRowid[j] is a valid ** name for the rowid before adding it to azCol[0]. WITHOUT ROWID ** tables will fail this last check */ - int rc; rc = sqlite3_table_column_metadata(p->db,0,zTab,azRowid[j],0,0,0,0,0); if( rc==SQLITE_OK ) azCol[0] = azRowid[j]; break; @@ -455,12 +454,12 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ if( strcmp(zType, "table")==0 ){ DText sSelect; DText sTable; - char **azCol; + char **azTCol; int i; int nCol; - azCol = tableColumnList(p, zTable); - if( azCol==0 ) return 0; + azTCol = tableColumnList(p, zTable); + if( azTCol==0 ) return 0; initText(&sTable); appendText(&sTable, "INSERT INTO ", 0); @@ -473,12 +472,12 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ ** In other words: "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)" ** instead of the usual "INSERT INTO tab VALUES(...)". */ - if( azCol[0] ){ + if( azTCol[0] ){ appendText(&sTable, "(", 0); - appendText(&sTable, azCol[0], 0); - for(i=1; azCol[i]; i++){ + appendText(&sTable, azTCol[0], 0); + for(i=1; azTCol[i]; i++){ appendText(&sTable, ",", 0); - appendText(&sTable, azCol[i], quoteChar(azCol[i])); + appendText(&sTable, azTCol[i], quoteChar(azTCol[i])); } appendText(&sTable, ")", 0); } @@ -487,19 +486,19 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ /* Build an appropriate SELECT statement */ initText(&sSelect); appendText(&sSelect, "SELECT ", 0); - if( azCol[0] ){ - appendText(&sSelect, azCol[0], 0); + if( azTCol[0] ){ + appendText(&sSelect, azTCol[0], 0); appendText(&sSelect, ",", 0); } - for(i=1; azCol[i]; i++){ - appendText(&sSelect, azCol[i], quoteChar(azCol[i])); - if( azCol[i+1] ){ + for(i=1; azTCol[i]; i++){ + appendText(&sSelect, azTCol[i], quoteChar(azTCol[i])); + if( azTCol[i+1] ){ appendText(&sSelect, ",", 0); } } nCol = i; - if( azCol[0]==0 ) nCol--; - freeColumnList(azCol); + if( azTCol[0]==0 ) nCol--; + freeColumnList(azTCol); appendText(&sSelect, " FROM ", 0); appendText(&sSelect, zTable, quoteChar(zTable)); diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index 7226ff18b3..83ba124375 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -496,6 +496,7 @@ static void fsdirResetCursor(fsdir_cursor *pCur){ pCur->zPath = 0; pCur->zBase = 0; pCur->nBase = 0; + pCur->nLvl = 0; pCur->iLvl = -1; pCur->iRowid = 1; } diff --git a/ext/misc/scrub.c b/ext/misc/scrub.c index 92718e23d1..4eb56b0fc2 100644 --- a/ext/misc/scrub.c +++ b/ext/misc/scrub.c @@ -131,7 +131,7 @@ static void scrubBackupWrite(ScrubState *p, int pgno, const u8 *pData){ scrubBackupErr(p, "write failed for page %d", pgno); p->rcErr = SQLITE_IOERR; } - if( pgno>p->iLastPage ) p->iLastPage = pgno; + if( (u32)pgno>p->iLastPage ) p->iLastPage = pgno; } /* Prepare a statement against the "db" database. */ @@ -459,7 +459,7 @@ static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){ nLocal = K<=X ? K : M; if( pc+nLocal > p->szUsable-4 ){ ln=__LINE__; goto btree_corrupt; } iChild = scrubBackupInt32(&a[pc+nLocal]); - scrubBackupOverflow(p, iChild, P-nLocal); + scrubBackupOverflow(p, iChild, (u32)(P-nLocal)); } /* Walk the right-most tree */ diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index a400ae30e1..a685ae0622 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -268,6 +268,7 @@ typedef struct ZipfileTab ZipfileTab; struct ZipfileTab { sqlite3_vtab base; /* Base class - must be first */ char *zFile; /* Zip file this table accesses (may be NULL) */ + sqlite3 *db; /* Host database connection */ u8 *aBuffer; /* Temporary buffer used for various tasks */ ZipfileCsr *pCsrList; /* List of cursors */ @@ -360,6 +361,7 @@ static int zipfileConnect( pNew = (ZipfileTab*)sqlite3_malloc(nByte+nFile); if( pNew==0 ) return SQLITE_NOMEM; memset(pNew, 0, nByte+nFile); + pNew->db = db; pNew->aBuffer = (u8*)&pNew[1]; if( zFile ){ pNew->zFile = (char*)&pNew->aBuffer[ZIPFILE_BUFFER_SIZE]; @@ -473,9 +475,17 @@ static int zipfileClose(sqlite3_vtab_cursor *cur){ ** Set the error message for the virtual table associated with cursor ** pCsr to the results of vprintf(zFmt, ...). */ -static void zipfileSetErrmsg(ZipfileCsr *pCsr, const char *zFmt, ...){ +static void zipfileTableErr(ZipfileTab *pTab, const char *zFmt, ...){ va_list ap; va_start(ap, zFmt); + sqlite3_free(pTab->base.zErrMsg); + pTab->base.zErrMsg = sqlite3_vmprintf(zFmt, ap); + va_end(ap); +} +static void zipfileCursorErr(ZipfileCsr *pCsr, const char *zFmt, ...){ + va_list ap; + va_start(ap, zFmt); + sqlite3_free(pCsr->base.pVtab->zErrMsg); pCsr->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap); va_end(ap); } @@ -751,8 +761,12 @@ static void zipfileMtimeToDos(ZipfileCDS *pCds, u32 mUnixTime){ min = (mUnixTime % (60*60)) / 60; sec = (mUnixTime % 60); - pCds->mDate = (u16)(day + (mon << 5) + ((yr-1980) << 9)); - pCds->mTime = (u16)(sec/2 + (min<<5) + (hr<<11)); + if( yr>=1980 ){ + pCds->mDate = (u16)(day + (mon << 5) + ((yr-1980) << 9)); + pCds->mTime = (u16)(sec/2 + (min<<5) + (hr<<11)); + }else{ + pCds->mDate = pCds->mTime = 0; + } assert( mUnixTime<315507600 || mUnixTime==zipfileMtime(pCds) @@ -1234,7 +1248,7 @@ static int zipfileFilter( if( pTab->zFile ){ zFile = pTab->zFile; }else if( idxNum==0 ){ - zipfileSetErrmsg(pCsr, "zipfile() function requires an argument"); + zipfileCursorErr(pCsr, "zipfile() function requires an argument"); return SQLITE_ERROR; }else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){ const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]); @@ -1252,7 +1266,7 @@ static int zipfileFilter( if( 0==pTab->pWriteFd && 0==bInMemory ){ pCsr->pFile = fopen(zFile, "rb"); if( pCsr->pFile==0 ){ - zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile); + zipfileCursorErr(pCsr, "cannot open file: %s", zFile); rc = SQLITE_ERROR; }else{ rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd); @@ -1390,9 +1404,7 @@ static int zipfileGetMode( switch( z[0] ){ case '-': mode |= S_IFREG; break; case 'd': mode |= S_IFDIR; break; -#if !defined(_WIN32) && !defined(WIN32) case 'l': mode |= S_IFLNK; break; -#endif default: goto parse_error; } for(i=1; i<10; i++){ @@ -1400,9 +1412,10 @@ static int zipfileGetMode( else if( z[i]!='-' ) goto parse_error; } } - if( (bIsDir == ((mode & S_IFDIR)==0)) ){ + if( ((mode & S_IFDIR)==0)==bIsDir ){ /* The "mode" attribute is a directory, but data has been specified. ** Or vice-versa - no data but "mode" is a file or symlink. */ + *pzErr = sqlite3_mprintf("zipfile: mode does not match data"); return SQLITE_CONSTRAINT; } *pMode = mode; @@ -1533,9 +1546,12 @@ static int zipfileUpdate( if( nVal>1 ){ /* Check that "sz" and "rawdata" are both NULL: */ - if( sqlite3_value_type(apVal[5])!=SQLITE_NULL - || sqlite3_value_type(apVal[6])!=SQLITE_NULL - ){ + if( sqlite3_value_type(apVal[5])!=SQLITE_NULL ){ + zipfileTableErr(pTab, "sz must be NULL"); + rc = SQLITE_CONSTRAINT; + } + if( sqlite3_value_type(apVal[6])!=SQLITE_NULL ){ + zipfileTableErr(pTab, "rawdata must be NULL"); rc = SQLITE_CONSTRAINT; } @@ -1555,6 +1571,7 @@ static int zipfileUpdate( pData = aIn; nData = nIn; if( iMethod!=0 && iMethod!=8 ){ + zipfileTableErr(pTab, "unknown compression method: %d", iMethod); rc = SQLITE_CONSTRAINT; }else{ if( bAuto || iMethod ){ @@ -1601,7 +1618,20 @@ static int zipfileUpdate( ZipfileEntry *p; for(p=pTab->pFirstEntry; p; p=p->pNext){ if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){ - rc = SQLITE_CONSTRAINT; + switch( sqlite3_vtab_on_conflict(pTab->db) ){ + case SQLITE_IGNORE: { + goto zipfile_update_done; + } + case SQLITE_REPLACE: { + pOld = p; + break; + } + default: { + zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath); + rc = SQLITE_CONSTRAINT; + break; + } + } break; } } @@ -1645,6 +1675,7 @@ static int zipfileUpdate( zipfileEntryFree(pOld); } +zipfile_update_done: sqlite3_free(pFree); sqlite3_free(zFree); return rc; diff --git a/ext/repair/sqlite3_checker.tcl b/ext/repair/sqlite3_checker.tcl index 88c265f93c..2ae6e15b12 100644 --- a/ext/repair/sqlite3_checker.tcl +++ b/ext/repair/sqlite3_checker.tcl @@ -220,7 +220,9 @@ if {[catch {sqlite3 db $file_to_analyze} res]} { if {$bFreelistCheck || $bAll} { puts -nonewline "freelist-check: " flush stdout + db eval BEGIN puts [db one {SELECT checkfreelist('main')}] + db eval END } if {$bSummary} { set scale 0 diff --git a/ext/session/session4.test b/ext/session/session4.test index bf55e362c6..0b4af9e779 100644 --- a/ext/session/session4.test +++ b/ext/session/session4.test @@ -129,6 +129,7 @@ foreach {tn blob} { 53 540101743400120003001200010000000000000002120002400C000000000000500401000000743100170001000002400C00000000000050040110000074310017000000000000050100000000000000030100000003001700010000666F7572 54 540101743400120003001200010000000000000002120002400C000000000002120002400C00000000000050040100000074310017FF0050040100000074310017FF7F00000000000000050100000000000000030100000003001700010000666F7572 55 540101743400120003001200010000000000000002120002400C00000000000050040100000074310017000100010080000001000000020003010100000300170100000003001700010000666F7572 + 56 5487ffffff7f } { do_test 2.$tn { set changeset [binary decode hex $blob] diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index 29f19719e1..bc17191d83 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -2807,7 +2807,14 @@ static int sessionChangesetBufferTblhdr(SessionInput *pIn, int *pnByte){ rc = sessionInputBuffer(pIn, 9); if( rc==SQLITE_OK ){ nRead += sessionVarintGet(&pIn->aData[pIn->iNext + nRead], &nCol); - if( nCol<0 ){ + /* The hard upper limit for the number of columns in an SQLite + ** database table is, according to sqliteLimit.h, 32676. So + ** consider any table-header that purports to have more than 65536 + ** columns to be corrupt. This is convenient because otherwise, + ** if the (nCol>65536) condition below were omitted, a sufficiently + ** large value for nCol may cause nRead to wrap around and become + ** negative. Leading to a crash. */ + if( nCol<0 || nCol>65536 ){ rc = SQLITE_CORRUPT_BKPT; }else{ rc = sessionInputBuffer(pIn, nRead+nCol+100); diff --git a/main.mk b/main.mk index d833d2fa93..4ffe3b0f6c 100644 --- a/main.mk +++ b/main.mk @@ -65,7 +65,7 @@ LIBOBJ+= vdbe.o parse.o \ fts3_write.o fts5.o func.o global.o hash.o \ icu.o insert.o json1.o legacy.o loadext.o \ main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \ - memjournal.o \ + memdb.o memjournal.o \ mutex.o mutex_noop.o mutex_unix.o mutex_w32.o \ notify.o opcodes.o os.o os_unix.o os_win.o \ pager.o pcache.o pcache1.o pragma.o prepare.o printf.o \ @@ -118,6 +118,7 @@ SRC = \ $(TOP)/src/mem2.c \ $(TOP)/src/mem3.c \ $(TOP)/src/mem5.c \ + $(TOP)/src/memdb.c \ $(TOP)/src/memjournal.c \ $(TOP)/src/msvc.h \ $(TOP)/src/mutex.c \ @@ -575,6 +576,9 @@ ossshell$(EXE): $(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c sqlite3.h -DSQLITE_ENABLE_MEMSYS5 $(FUZZCHECK_OPT) \ $(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c $(TLIBS) $(THREADLIB) +sessionfuzz$(EXE): $(TOP)/test/sessionfuzz.c sqlite3.c sqlite3.h + $(TCC) -o sessionfuzz$(EXE) $(TOP)/test/sessionfuzz.c -lz $(TLIBS) $(THREADLIB) + mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c $(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \ $(TLIBS) $(THREADLIB) @@ -895,14 +899,17 @@ fulltestonly: $(TESTPROGS) fuzztest queryplantest: testfixture$(EXE) sqlite3$(EXE) ./testfixture$(EXE) $(TOP)/test/permutations.test queryplanner $(TESTOPTS) -fuzztest: fuzzcheck$(EXE) $(FUZZDATA) +fuzztest: fuzzcheck$(EXE) $(FUZZDATA) sessionfuzz$(EXE) $(TOP)/test/sessionfuzz-data1.db ./fuzzcheck$(EXE) $(FUZZDATA) + ./sessionfuzz run $(TOP)/test/sessionfuzz-data1.db -fastfuzztest: fuzzcheck$(EXE) $(FUZZDATA) +fastfuzztest: fuzzcheck$(EXE) $(FUZZDATA) sessionfuzz$(EXE) $(TOP)/test/sessionfuzz-data1.db ./fuzzcheck$(EXE) --limit-mem 100M $(FUZZDATA) + ./sessionfuzz run $(TOP)/test/sessionfuzz-data1.db -valgrindfuzz: fuzzcheck$(EXE) $(FUZZDATA) +valgrindfuzz: fuzzcheck$(EXE) $(FUZZDATA) sessionfuzz$(EXE) $(TOP)/test/sessionfuzz-data1.db valgrind ./fuzzcheck$(EXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA) + valgrind ./sessionfuzz run $(TOP)/test/sessionfuzz-data1.db # The veryquick.test TCL tests. # @@ -1069,6 +1076,7 @@ clean: rm -f mptester mptester.exe rm -f fuzzershell fuzzershell.exe rm -f fuzzcheck fuzzcheck.exe + rm -f sessionfuzz rm -f sqldiff sqldiff.exe rm -f fts5.* fts5parse.* rm -f lsm.h lsm1.c diff --git a/manifest b/manifest index 22fa622242..25807c5b4c 100644 --- a/manifest +++ b/manifest @@ -1,10 +1,10 @@ -C Update\sthis\sbranch\swith\srecent\scheckpoint\srelated\schanges\sfrom\strunk. -D 2018-03-02T17:59:37.964 +C Merge\sall\srecent\senhancements\sfrom\strunk. +D 2018-03-20T13:52:42.504 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea -F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 +F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc bf19d3a0eb849bd3b114653b0e455aa5b2799a96f413287a5866013db0e47f30 +F Makefile.msc 8a6727b41a4626a5552016f4b0088b43fb14a32f53db1f47e83a0fefcb63c49a F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 F VERSION cdf91ac446255ecf3d8f6d8c3ee40d64123235ae5b3cef29d344e61b45ec3759 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -13,7 +13,7 @@ F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 2c274948734e03c51790ff51468f91db8d570bcca864284d9c6d6e777264cd7e -F autoconf/Makefile.msc 2c50a59319af7da4eaca8c13e3240881b1bc245fd175845a055faab7d03d6e67 +F autoconf/Makefile.msc 1223d1520e0b833041ad87b377fae61cc3e08d14c5aae4c1a9e36249225bd4e6 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt 4f04b0819303aabaa35fff5f7b257fb0c1ef95f1 F autoconf/configure.ac 18fca06f884213be062dd5e07c5297079cc45893d9cd3f522ce426e715033e3d @@ -43,7 +43,7 @@ F ext/async/README.txt e12275968f6fde133a80e04387d0e839b0c51f91 F ext/async/sqlite3async.c 0f3070cc3f5ede78f2b9361fb3b629ce200d7d74 F ext/async/sqlite3async.h f489b080af7e72aec0e1ee6f1d98ab6cf2e4dcef F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3 -F ext/expert/expert.c 4791c5e064aea81b2b829fa95228b22283380ee370ea88a1e580103b75516ebf +F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4 F ext/expert/expert1.test fd21496d8e52c817a7741f467f42b0502c0ac7e07dcdd1d6e15a3e8154ed4e41 F ext/expert/sqlite3expert.c 1dfa561e64dc0f89d56b96e6afda87468c34b43604c2df50c47e3f4362778fb2 F ext/expert/sqlite3expert.h af6354f8ee5c9e025024e63fec3bd640a802afcc3099a44d804752cf0791d811 @@ -111,7 +111,7 @@ F ext/fts5/fts5Int.h eda28e3a0a5d87c412e8355fe35da875b04cb389908c8eb0d867ad662ad F ext/fts5/fts5_aux.c ca666a3bbe07c5a3bbe9fffaea19c935a1efaf337333e28bad7bdd1971ffd093 F ext/fts5/fts5_buffer.c 1dd1ec0446b3acfc2d7d407eb894762a461613e2695273f48e449bfd13e973ff F ext/fts5/fts5_config.c 5af9c360e99669d29f06492c370892394aba0857 -F ext/fts5/fts5_expr.c 01048018d21524e2c302b063ff5c3cdcf546e03297215e577205d85b47499deb +F ext/fts5/fts5_expr.c c23a2e4c14c401a147c4a730460e5b37057627bf4be95515ee281cd87f4d277c F ext/fts5/fts5_hash.c 32be400cf761868c9db33efe81a06eb19a17c5402ad477ee9efb51301546dd55 F ext/fts5/fts5_index.c 22b71d0e9e4b3ddd123a39ae27174e0012da2806f91b64087a68584f13f189de F ext/fts5/fts5_main.c 24868f88ab2a865defbba7a92eebeb726cc991eb092b71b5f5508f180c72605b @@ -272,12 +272,12 @@ F ext/misc/appendvfs.c 3777f22ec1057dc4e5fd89f2fbddcc7a29fbeef1ad038c736c54411bb F ext/misc/btreeinfo.c 78c8c57d325185ccc04b7679e5b020e34a4d9c87453e6b7ac943d0a26cee3256 F ext/misc/carray.c ed96c218ea940b85c9a274c4d9c59fe9491c299147a38a8bba537687bd6c6005 F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 -F ext/misc/completion.c 52c3f01523e3e387eb321b4739a89d1fe47cbe6025aa1f2d8d3685e9e365df0f +F ext/misc/completion.c 0d0bd16378415b982e7119baddef52a0d2cc25860c238a9d2832b0cc6a84a16d F ext/misc/compress.c dd4f8a6d0baccff3c694757db5b430f3bbd821d8686d1fc24df55cf9f035b189 F ext/misc/csv.c 1a009b93650732e22334edc92459c4630b9fa703397cbb3c8ca279921a36ca11 -F ext/misc/dbdump.c 3509fa6b8932d04e932d6b6b827b6a82ca362781b8e8f3c77336f416793e215e +F ext/misc/dbdump.c 22018e00eb50e9ebf9067c92d4e7162dc5006a3efc4e0c19bc3829825a1043b0 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 -F ext/misc/fileio.c 4cad3a78bfbbea9b1414b4405fd704ee57fbe2621254b011888dae7b0ba8c513 +F ext/misc/fileio.c 673d6bde25cab00ad40cc95b89fa99c9f00870c565de3beaab9d6a9658bbc3e0 F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c F ext/misc/json1.c dbe086615b9546c156bf32b9378fc09383b58bd17513b866cfd24c1e15281984 @@ -289,7 +289,7 @@ F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e F ext/misc/regexp.c a68d25c659bd2d893cd1215667bbf75ecb9dc7d4 F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c F ext/misc/rot13.c 540a169cb0d74f15522a8930b0cccdcb37a4fd071d219a5a083a319fc6e8db77 -F ext/misc/scrub.c 1c5bfb8b0cd18b602fcb55755e84abf0023ac2fb +F ext/misc/scrub.c db9fff56fed322ca587d73727c6021b11ae79ce3f31b389e1d82891d144f22ad F ext/misc/series.c f3c0dba5c5c749ce1782b53076108f87cf0b71041eb6023f727a9c50681da564 F ext/misc/sha1.c 0b9e9b855354910d3ca467bf39099d570e73db56 F ext/misc/shathree.c 9e960ba50483214c6a7a4b1517f8d8cef799e9db381195178c3fd3ad207e10c0 @@ -304,7 +304,7 @@ F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178 F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 -F ext/misc/zipfile.c bc88dbf9aa26c24595d158c1398208786ef34e7aee19ea29e8f0110c752fca03 +F ext/misc/zipfile.c e4e4f8289a8dee7e4f78547dacfb6548bcd83a02b52c0bc9205d8fbfb7f4b8a1 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -346,7 +346,7 @@ F ext/repair/README.md 92f5e8aae749a4dae14f02eea8e1bb42d4db2b6ce5e83dbcdd6b14469 F ext/repair/checkfreelist.c 0dbae18c1b552f58d64f8969e4fb1e7f11930c60a8c2a9a8d50b7f15bdfd54bd F ext/repair/checkindex.c 7d28c01a2e012ac64257d230fc452b2cafb78311a91a343633d01d95220f66f3 F ext/repair/sqlite3_checker.c.in 4a5a3af3f450fe503e5a2985e98516dc2a6b9ad247449e284c1cf140fc91720f -F ext/repair/sqlite3_checker.tcl cc69e7fbc163f94da4a6400609be001543442d9f8f57a797d1eeb7b897585730 +F ext/repair/sqlite3_checker.tcl a9a2caa9660567257c177a91124d8c0dccdfa341e25c51e6da7f1fd9e601eafa F ext/repair/test/README.md 34b2f542cf5be7bffe479242b33ee3492cea30711e447cc4a1a86cb5915f419e F ext/repair/test/checkfreelist01.test 3e8aa6aeb4007680c94a8d07b41c339aa635cc78249442da72ff3f8297398a69 F ext/repair/test/checkindex01.test 6945d0ffc0c1dc993b2ce88036b26e0f5d6fcc65da70fc9df27c2647bb358b0f @@ -383,7 +383,7 @@ F ext/session/changeset.c 4ccbaa4531944c24584bf6a61ba3a39c62b6267a F ext/session/session1.test 736d7ff178662f0b717c37f46531b84a5ce0210ccb0c4edf629c55dbcbbc3ea1 F ext/session/session2.test 284de45abae4cc1082bc52012ee81521d5ac58e0 F ext/session/session3.test ce9ce3dfa489473987f899e9f6a0f2db9bde3479 -F ext/session/session4.test efd7a46ed6a954d51ab00bdc4d656d2bc31e46be64393224cf6acf1319fbd32c +F ext/session/session4.test 3eea8058643e5adbd3293a5c553255c35e774ed90e7cbec09c9b010d176ad396 F ext/session/session5.test 716bc6fafd625ce60dfa62ae128971628c1a1169 F ext/session/session6.test 443789bc2fca12e4f7075cf692c60b8a2bea1a26 F ext/session/session8.test 8e194b3f655d861ca36de5d4de53f702751bab3b @@ -406,7 +406,7 @@ F ext/session/sessionstat1.test 41cd97c2e48619a41cdf8ae749e1b25f34719de638689221 F ext/session/sessionwor.test 2f3744236dc8b170a695b7d8ddc8c743c7e79fdc F ext/session/sqlite3changebatch.c d5553b79e012ee2cb06c0a96bdf9dfe19e66354390ea0036cc46c4953142d517 F ext/session/sqlite3changebatch.h e72016998c9a22d439ddfd547b69e1ebac810c24 -F ext/session/sqlite3session.c 21810bc8a5571ebd4263053a2e4bc4e534444336a62248d60a08bae43ea62f20 +F ext/session/sqlite3session.c 1c1164008ad756d4dd7a2cb651647925cd0a88378853b4f225bbc5aa18c042e2 F ext/session/sqlite3session.h 1eb6bc132e1e23eba7290b8cb85141fa4ef6cb5c8104a6851a4c4e88512996b6 F ext/session/test_session.c badd5da3cb561564b093745f7d843430d1d76347 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 @@ -415,7 +415,7 @@ F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 2263d738b707d420c24535a85aad10ab35be5d90a14660b325b2bc99e8b91085 +F main.mk 451db1a4c9a37a1a3c725a100d4169a0c797451c7aeb512fb07f1d32b78782c9 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -429,7 +429,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 6b42e36a5dcc2703a771f2411bd5e99524bd62c7ecde209bb88dfb04c72f046e -F src/attach.c 79cb6b365d79b96b15dd429aa3e4c3b99335039e059baca8df28f1708fbff261 +F src/attach.c f6f212c43dddba79dfcb723fb9470785f3ff55bde8953cd9d2546f3022070a41 F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 8433d9e98dd6f2ea3286e0d2fe5d65de1bfc18a706486eb2026b01be066b5806 @@ -437,10 +437,10 @@ F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca F src/btree.c d070d79e81d76e521992a1f2e6b55892da04c35bbe493a07a3904a404e4416cc F src/btree.h 0cd745755efd1f3df4c70544c54253920ea32fe6b179b97e9daeb786ba0de4ba F src/btreeInt.h 6c65e6c96f561596f6870c79a64d4706af81613881d7947e3f063e923f14115f -F src/build.c 4584d3b8bf05dc3c6b58a3869d66707adf1a2d0c0dd278cbdf6698a3bfc95cc6 +F src/build.c adf56922a67ae5cbfe4dd993ae3643b6cc319e3cb6768a8a7052c69e60054527 F src/callback.c fe677cb5f5abb02f7a772a62a98c2f516426081df68856e8f2d5f950929b966a F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e -F src/ctime.c ff1be3eed7bdd75aaca61ca8dc848f7c9f850ef2fb9cb56f2734e922a098f9c0 +F src/ctime.c bd9da3f1ff21b432564a16ef0b154cff03585dc43742842e99c58907c6cb4bef F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957 F src/dbpage.c 8db4c97f630e7d83f884ea75caf1ffd0988c160e9d530194d93721c80821e0f6 F src/dbstat.c 7a4ba8518b6369ef3600c49cf9c918ad979acba610b2aebef1b656d649b96720 @@ -454,16 +454,17 @@ F src/hash.c a12580e143f10301ed5166ea4964ae2853d3905a511d4e0c44497245c7ce1f7a F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 14686083cedc198540b15a79586cdd4be2acf6d5fa97627e355f817ab07e9fee +F src/insert.c b9ff71cc2913d1d57698a1e22bf853261a9a642baf62bdf40ddeb3809adb85b5 F src/legacy.c 134ab3e3fae00a0f67a5187981d6935b24b337bcf0f4b3e5c9fa5763da95bf4e F src/loadext.c f6e4e416a736369f9e80eba609f0acda97148a8b0453784d670c78d3eed2f302 -F src/main.c 64a93806e98950ee872ee0952b43b62bb5f6cb10452b99ae5e5f77502d6b622d +F src/main.c e4e95e03b9bfc5ecf14f1b5f547f822cc85e39b95890683e5a148283035a569a F src/malloc.c 07295435093ce354c6d9063ac05a2eeae28bd251d2e63c48b3d67c12c76f7e18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 +F src/memdb.c 2bcebf99f77270e4b30ee5fad749347a6296db1662b3a196593e5410780aea85 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -479,29 +480,29 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c da5704d0c54eec4b8e02095782c0360af4edfbf7832191f5ff697fddfbb4f9ef F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c fa0c6d8cc7483bcf5a3c02bc80a5162b81bf948e567113fda8bf548edc187131 +F src/pager.c e9b4176a83e86d4113757d2ad4ca82fd3961402e226e08274e3569ce39ae25a2 F src/pager.h 72e1a29470f2c2ad482ce944f61c7818098a842740d94c2bd167f348da4fdbac -F src/parse.y 678b3afe0d9e79534295d8be4d4f4eebae5d6df2b0c402ac73650b240caedc30 -F src/pcache.c 7ae91a4557a43d77d449accbfdc68846e6516f8e2eda46e8bbe4536fb669b201 +F src/parse.y 5e4afc0ca16cf5a0b464f49554f49bba03c455b9b973ec57665286f3f5abfbdb +F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170 F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880 F src/pragma.c bea56df3ae0637768c0da4fbbb8f2492f780980d95000034a105ff291bf7ca69 F src/pragma.h bb83728944b42f6d409c77f5838a8edbdb0fe83046c5496ffc9602b40340a324 -F src/prepare.c 259f4e7960c47082c9653f3d5f0c294abd68bb9c3aab86de7630700cba1c20fb +F src/prepare.c b086fea6a1952db88beca31fdd621201ee5e4ce3f02905248cc3035a8174aa89 F src/printf.c d3b7844ddeb11fbbdd38dd84d09c9c1ac171d21fb038473c3aa97981201cc660 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac -F src/select.c f02352ac5cbb6fad3804add825743b924cfb6c742ba2e8666d726828a9985d73 -F src/shell.c.in 47dac081e15544f4d4373a837215391459971b312c8bed15903e7e9045c3e652 -F src/sqlite.h.in 5576a6e50560b23fb072d5824e5b60084275897eaec8235d98a81fcaa316db6d +F src/select.c 97a2131f02c605c52a6d5deac5b2ae6604db8c346829eb6b185bc38512a9b49a +F src/shell.c.in 911b9e3bce40413c78fdba28efa28363e98183819bd4b300780bf57bacfc4b84 +F src/sqlite.h.in a95e2ac3a11c2d44faf18700c5ecc8beffc1409a0d21d8b855f1821469dd32c1 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d -F src/sqliteInt.h 51c1a7062421433bd7b352e51b4fbce9aad1d74f10fdf2597760df24dfb87024 +F src/sqliteInt.h 29a4735667bcc384d9b329ebbb1a2a172a9194f4dd5f392fdaf830cbcdccae0e F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b -F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 +F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 11a2618c227fd13ccad73ee02d1199f9880c59db2b3144fd7432db1980a2577d +F src/tclsqlite.c 916a92de77ec5cbe27818ca194d8cf0c58aa7ad5b87527098f6aa5a6068800ce F src/test1.c c2b5de91195cf2911760cfe543eb1bf315a01e1db32a95d2ba5d8fe6be06f41c F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -517,7 +518,7 @@ F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 F src/test_bestindex.c 78809f11026f18a93fcfd798d9479cba37e1201c830260bf1edc674b2fa9b857 F src/test_blob.c ae4a0620b478548afb67963095a7417cd06a4ec0a56adb453542203bfdcb31ce F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 -F src/test_config.c 621e3330989efdacce8e7b1e2ea4c0864bada1e7ea746ce3ba01e7466409580c +F src/test_config.c 7f049288c6174ba7038f37b68c809897426790170b25c178bf18d7358e6eed69 F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf9f8f F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e F src/test_devsym.c 1960abbb234b97e9b920f07e99503fc04b443f62bbc3c6ff2c2cea2133e3b8a2 @@ -529,7 +530,7 @@ F src/test_intarray.c 988fc61cb0ff539f4172c0d95f15287c92516f64 F src/test_intarray.h f3b7672f5d1056eac563c0d6ea8480a660b1475c F src/test_journal.c 619f2aa10e0d7a5f87c0f06825bc61dfce1c6b9c7f3ad990fb13de6c3b8874a3 F src/test_loadext.c 337056bae59f80b9eb00ba82088b39d0f4fe6dfd -F src/test_malloc.c 4f06a805de86be5216a127b3777ca2d5a1ff99d1a9238374ce136a47411be36c +F src/test_malloc.c 5201422e2403e66a7a9c2b7d8df806acd8d2a0429822adb7e932f324e7b5b3c6 F src/test_md5.c 7268e1e8c399d4a5e181b64ac20e1e6f3bc4dd9fc87abac02db145a3d951fa8c F src/test_multiplex.c e054459f7633f3ff8ce1245da724f9a8be189e4e F src/test_multiplex.h 5436d03f2d0501d04f3ed50a75819e190495b635 @@ -555,16 +556,16 @@ F src/test_windirent.h 90dfbe95442c9762357fe128dc7ae3dc199d006de93eb33ba3972e0a9 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 5b0c661a85f783d35b9883830736eeb63be4aefc4f6b7d9cd081d48782c041e2 -F src/treeview.c e0d62678314abf0e1e6d09ea405f4de3f404a17b4641c2169c304b5edf509320 +F src/treeview.c 14d5d1254702ec96876aa52642cb31548612384134970409fae333b25b39d6bb F src/trigger.c a34539c69433276d37b0da9a89c117726ff2d292c0902895af1f393a983cd3a1 F src/update.c a90a32ffc0100265b0693dbbdbe490756447af181f5ea2c138cce515b08c8795 F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5 F src/util.c d9eb0a6c4aae1b00a7369eadd7ca0bbe946cb4c953b6751aa20d357c2f482157 F src/vacuum.c f0b8302219b00461ac0edbb790b5ef52d3d454a7ef9b78030a44b32bbdc39e8a -F src/vdbe.c 213097212a5e1836a57cd4faa396996234481d8351c29a417d9b648f0f53a10b +F src/vdbe.c 6f4b0624d493d3abe189658593716854e531de1b043a20e23f4b960c32792e1e F src/vdbe.h 134beb7a12a6213c00eba58febaede33447cc4441bc568a0d9c144b33fc3720a F src/vdbeInt.h 95f7adfdc5c8f1353321f55a6c5ec00a90877e3b85af5159e393afb41ff54110 -F src/vdbeapi.c fea41171884a4de119f8b10ab514c788674eeeb7f27218bb6d008e1310bfd07f +F src/vdbeapi.c 29d2baf9c1233131ec467d7bed1b7c8a03c27579048d768c4b04acf427838858 F src/vdbeaux.c db9d38ca41466d5cc845bedbf88f470eefb5c4edaff2070249fa08a40273d1a1 F src/vdbeblob.c f5c70f973ea3a9e915d1693278a5f890dc78594300cf4d54e64f2b0917c94191 F src/vdbemem.c 414e28d3a7e2a8bee2bb247de115dcbc68e3cbac284d5862d077002f7a93bce1 @@ -572,7 +573,7 @@ F src/vdbesort.c 731a09e5cb9e96b70c394c1b7cf3860fbe84acca7682e178615eb941a3a0ef2 F src/vdbetrace.c 48e11ebe040c6b41d146abed2602e3d00d621d7ebe4eb29b0a0f1617fd3c2f6c F src/vtab.c 0e4885495172e1bdf54b12cce23b395ac74ef5729031f15e1bc1e3e6b360ed1a F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 -F src/wal.c b6ad12df144846d02db4a18cadf9e5fcf39f1d7b7156f94131ab4076384dec07 +F src/wal.c 05d9364fefacdff639b7fb63b1113317e045e2ae5c7908fa50157f9f24883257 F src/wal.h 1713fefe4587678c295bbeb91c4e7442998ad74f19249869ce49dda9e8ce5d53 F src/walker.c da987a20d40145c0a03c07d8fefcb2ed363becc7680d0500d9c79915591f5b1f F src/where.c 7cae47e813393d70c6d327fdf000fcb30f76b1b0b5a5b52ff6402e0c658de32c @@ -738,7 +739,7 @@ F test/crash4.test fe2821baf37168dc59dd733dcf7dba2a401487bc F test/crash5.test 05dd3aa9dbb751a22d5cdaf22a9c49b6667aa219 F test/crash6.test 4c56f1e40d0291e1110790a99807aa875b1647ba F test/crash7.test 1a194c4900a255258cf94b7fcbfd29536db572df -F test/crash8.test 63cd5aea313222d7a69637cf7174c34d151676cc187d57193b66d4c89dedede3 +F test/crash8.test 64366e459c28dd62edfb7ad87253a409c7533b92d16fcc479a6a8131bdcc3100 F test/crashM.test d95f59046fa749b0d0822edf18a717788c8f318d F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8 @@ -751,8 +752,8 @@ F test/date.test 9b73bbeb1b82d9c1f44dec5cf563bf7da58d2373 F test/date2.test 74c234bece1b016e94dd4ef9c8cc7a199a8806c0e2291cab7ba64bace6350b10 F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbpage.test dbf50a4d361f9e45a979432c727506065113124478a7d2db12074fa655e65d6c -F test/dbstatus.test 73149851b3aff14fc6db478e58f9083a66422cf5 -F test/dbstatus2.test e93ab03bfae6d62d4d935f20de928c19ca0ed0ab +F test/dbstatus.test c15fa97f743dac7ce996814c84b56317e138895ee15ce27f15b608aa6924c90a +F test/dbstatus2.test 35a987036fefbbc696e65b6a3fbd860864cfd54941c52f50c61b55d4778ac66c F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d F test/delete.test acc38fca8ee4851467705b1c2cfea64cd26667e5 F test/delete2.test 3a03f2cca1f9a67ec469915cb8babd6485db43fa @@ -945,7 +946,7 @@ F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 F test/fuzz3.test 9c813e6613b837cb7a277b0383cd66bfa07042b4cf0317157c35852f30043c31 F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 -F test/fuzzcheck.c 2152602232c96d9c790eff3013e1369ce59de3203fa0b75bc613531448454e61 +F test/fuzzcheck.c 5eb86c6ac96833ee622f45bf47e8045999c1b4b10d05e4eb809894a4b39f2f84 F test/fuzzdata1.db 7ee3227bad0e7ccdeb08a9e6822916777073c664 F test/fuzzdata2.db f03a420d3b822cc82e4f894ca957618fbe9c4973 F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -1030,7 +1031,7 @@ F test/json102.test eeb54efa221e50b74a2d6fb9259963b48d7414dca3ce2fdfdeed45cb2848 F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 F test/json104.test 877d5845f6303899b7889ea5dd1bea99076e3100574d5c536082245c5805dcaa F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff -F test/kvtest.c fcb38ffe3db028a3138b4818fc098359c80dc51a0d1278a91c99c554cc1abb92 +F test/kvtest.c 23452e653e6b0254dc2fd1d242d4c7c65644504de8951d7d60f7e4291c52c231 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200 F test/like.test 11cfd7d4ef8625389df9efc46735ff0b0b41d5e62047ef0f3bc24c380d28a7a6 @@ -1077,6 +1078,7 @@ F test/malloc_common.tcl aac62499b76be719fac31e7a3e54a7fd53272e7f F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f F test/memdb.test c1f2a343ad14398d5d6debda6ea33e80d0dafcc7 +F test/memdb1.test fbe47f36c12725ebdd2760f846371e6eb09f403bd7236fbdddb21aa6e3c652b4 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1107,7 +1109,7 @@ F test/multiplex4.test e8ae4c4bd70606a5727743241f13b5701990abe4 F test/mutex1.test ea2cc74d97f077b9e74c84cbd024f14d79a8126f F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660 F test/nan.test 437d40e6d0778b050d7750726c0cbd2c9936b81962926e8f8c48ca698f00f4d1 -F test/nockpt.test fd5473e30a84848b25ab06524750c05095383e191be83ccb4e6951c8beddfb5b +F test/nockpt.test 8c43b25af63b0bd620cf1b003529e37b6f1dc53bd22690e96a1bd73f78dde53a F test/nolock.test f196cf8b8fbea4e2ca345140a2b3f3b0da45c76e F test/normalize.test 501630ab49b0b26b65c74124bf03e3374c1b57fa97aae750f84803609141d167 F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf @@ -1129,8 +1131,8 @@ F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3 F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f -F test/ossfuzz.c 3613bc516386234cf2e513fb94dc677ab3862eb7ebc5b3671c319a80f86839fb -F test/ossshell.c 296ab63067841bd1b1e97b46a0b2af48ee7f69d50d1a723008bee12dd7122622 +F test/ossfuzz.c c4c4547e2c92ac52f10038b073a03248251a23c1c559728f63a18aeca0e79f03 +F test/ossshell.c f125c5bd16e537a2549aa579b328dd1c59905e7ab1338dfc210e755bb7b69f17 F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f F test/pager1.test f596d3bd53ce96e1d87d44d223d2ae6c8867dd782c425e5eb28b5721fa6aaa97 F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71 @@ -1223,6 +1225,8 @@ F test/selectF.test 21c94e6438f76537b72532fa9fd4710cdd455fc3 F test/selectG.test 089f7d3d7e6db91566f00b036cb353107a2cca6220eb1cb264085a836dae8840 F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be +F test/sessionfuzz-data1.db 1f8d5def831f19b1c74571037f0d53a588ea49a6c4ca2a028fc0c27ef896dbcb +F test/sessionfuzz.c b0fcdcf757451957e17396a3af5171f1fdf9b2babc81da9fa35675df46c4729a F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 F test/shared3.test ab693f9b6e156b8bfb2a0ad94f29fe69602a5d38 @@ -1271,7 +1275,7 @@ F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded F test/speed3.test 694affeb9100526007436334cf7d08f3d74b85ef F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa -F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b +F test/speed4p.test 377a0c48e5a92e0b11c1c5ebb1bc9d83a7312c922bc0cb05970ef5d6a96d1f0c F test/speedtest1.c a5faf4cbe5769eee4b721b3875cb3f12520a9b99d9026b1063b47c39603375b8 F test/spellfix.test 951a6405d49d1a23d6b78027d3877b4a33eeb8221dcab5704b499755bb4f552e F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 @@ -1304,7 +1308,7 @@ F test/tabfunc01.test c47171c36b3d411df2bd49719dcaa5d034f8d277477fd41d253940723b F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 -F test/tclsqlite.test c3d7ac9449634b9f17fd048a3c0212e88a7448be810a9c5bd051acc1ffa00d2f +F test/tclsqlite.test 5337e8890b96dad1ee541b15fbeec32e6bac2fe7fa096f91089057385aadba9b F test/tempdb.test 4cdaa23ddd8acb4d79cbb1b68ccdfd09b0537aaba909ca69a876157c2a2cbd08 F test/tempdb2.test 27e41ed540b2f9b056c2e77e9bddc1b875358507 F test/tempfault.test 0c0d349c9a99bf5f374655742577f8712c647900 @@ -1313,7 +1317,7 @@ F test/temptable2.test cd396beb41117a5302fff61767c35fa4270a0d5e F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637 F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc F test/tester.tcl 94901a4625d9a2229666dd5c44120ddf7f0fb639470710ef74a4cefc7b039e07 -F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 +F test/thread001.test b61a29dd87cf669f5f6ac96124a7c97d71b0c80d9012746072055877055cf9ef F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 F test/thread004.test f51dfc3936184aaf73ee85f315224baad272a87f @@ -1470,7 +1474,7 @@ F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/tpch01.test 04adbf8d8300fa60a222f28d901abd76e7be6dd4 F test/trace.test a659a9862957f4789e37a92b3bf6d2caf5c86b02cdeefc41e850ae53acf6992a F test/trace2.test f5cb67ad3bc09e0c58e8cca78dfd0b5639259983 -F test/trace3.test 56ab944fddacf628b118cc298503fc45c2e50ab0 +F test/trace3.test b41076f536876b6edf661c0cf8f9216771316efd0fe78905576cc23ce269e7f2 F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6 F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76 F test/trans3.test 91a100e5412b488e22a655fe423a14c26403ab94 @@ -1618,9 +1622,9 @@ F test/wordcount.c cb589cec469a1d90add05b1f8cee75c7210338d87a5afd65260ed5c0f4bbf F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test 9c41628db7e8d9e8a0181e59ea5f189df311a9f6ce99cc376dc461f66db6f8dc -F test/zipfile.test 44aa8af115cc3e8c905468768dc761260650a8fdfca57e10f9818f5f8008d340 +F test/zipfile.test fd865048725bb138ef3024cee704cd9da9250de4b6f78ad27ff8e7e6d46caefe F test/zipfile2.test 67d5f08a202796d4b7a71dfa4b8dcb74aa7a9d1f42c5f17bedff9855c1ba7aa5 -F test/zipfilefault.test 050be76778d2ec83566a542800fc3967f65ce719671a819016ada8b654bc14f7 +F test/zipfilefault.test 44d4d7a7f7cca7521d569d7f71026b241d65a6b1757aa409c1a168827edbbc2c F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetTclKit.bat 8995df40c4209808b31f24de0b58f90930239a234f7591e3675d45bfbb990c5d F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91 @@ -1651,13 +1655,13 @@ F tool/mkkeywordhash.c 09ee7db43e6143fc6feb7490b9b56027efab5ae7257ee1f2014b07cd9 F tool/mkmsvcmin.tcl 8baf26690b80d861d0ac341b29880eec6ade39e4f11fe690271ded9cb90563a3 F tool/mkopcodec.tcl d1b6362bd3aa80d5520d4d6f3765badf01f6c43c F tool/mkopcodeh.tcl 4ee2a30ccbd900dc4d5cdb61bdab87cd2166cd2affcc78c9cc0b8d22a65b2eee -F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e +F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa F tool/mkpragmatab.tcl 2144bc8550a6471a029db262a132d2df4b9e0db61b90398bf64f5b7b3f8d92cd F tool/mkshellc.tcl 1f45770aea226ac093a9c72f718efbb88a2a2833409ec2e1c4cecae4202626f5 F tool/mksourceid.c d458f9004c837bee87a6382228ac20d3eae3c49ea3b0a5aace936f8b60748d3b F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl fef88397668ae83166735c41af99d79f56afaabb -F tool/mksqlite3c.tcl 1fb69d39166f52d802a70ec37d99bca51d011c8ab30be27bc495be493196ae41 +F tool/mksqlite3c.tcl a03cee30de81a2e67b93e5c659f24113a003677c557daeb008205c8e6d4345d6 F tool/mksqlite3h.tcl f92f994d9709aeb9e2b6e6f9fc8b069d2f55202c8e23f453edc44390a25982dc F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b F tool/mkvsix.tcl b9e0777a213c23156b6542842c238479e496ebf5 @@ -1719,7 +1723,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 36801effa9ec67b551f58972e21794466420f10cd0420701fcd87695e6cd11ee 044b0b65e716bffeddedbd1b0360c4c332f6d2359167c1d327a5ff96539474cb -R db5621b69ea924f8256c1ea108391b00 -U dan -Z 5f73e55771155cb4923ea7c8cff8af6b +P fb6b7938601505186c0b1f0df6c45630039027f85ff394d290bc2c86b16a3a07 ec7addc87f97bcff3c3694b14a680453b52de3f8c106436f0708a1cc04b90faa +R 43c5e6204e5e1e748f1b8270da37c665 +U drh +Z dfd53febd46dc841536127bb8e42a571 diff --git a/manifest.uuid b/manifest.uuid index fc240c969c..e069a3d23c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb6b7938601505186c0b1f0df6c45630039027f85ff394d290bc2c86b16a3a07 \ No newline at end of file +b0c2f760a637ee973f4dcc27308eec44950e6d0a9c5ab5c828c1210c1f868efa \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index f3d68553b6..f85952f7c6 100644 --- a/src/attach.c +++ b/src/attach.c @@ -55,6 +55,10 @@ static int resolveAttachExpr(NameContext *pName, Expr *pExpr) ** ** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the ** third argument. +** +** If the db->init.reopenMemdb flags is set, then instead of attaching a +** new database, close the database on db->init.iDb and reopen it as an +** empty MemDB. */ static void attachFunc( sqlite3_context *context, @@ -75,65 +79,85 @@ static void attachFunc( sqlite3_vfs *pVfs; UNUSED_PARAMETER(NotUsed); - zFile = (const char *)sqlite3_value_text(argv[0]); zName = (const char *)sqlite3_value_text(argv[1]); if( zFile==0 ) zFile = ""; if( zName==0 ) zName = ""; - /* Check for the following errors: - ** - ** * Too many attached databases, - ** * Transaction currently open - ** * Specified database name already being used. - */ - if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ - zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", - db->aLimit[SQLITE_LIMIT_ATTACHED] - ); - goto attach_error; - } - for(i=0; inDb; i++){ - char *z = db->aDb[i].zDbSName; - assert( z && zName ); - if( sqlite3StrICmp(z, zName)==0 ){ - zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); +#ifdef SQLITE_ENABLE_DESERIALIZE +# define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb) +#else +# define REOPEN_AS_MEMDB(db) (0) +#endif + + if( REOPEN_AS_MEMDB(db) ){ + /* This is not a real ATTACH. Instead, this routine is being called + ** from sqlite3_deserialize() to close database db->init.iDb and + ** reopen it as a MemDB */ + pVfs = sqlite3_vfs_find("memdb"); + if( pVfs==0 ) return; + pNew = &db->aDb[db->init.iDb]; + if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt); + pNew->pBt = 0; + pNew->pSchema = 0; + rc = sqlite3BtreeOpen(pVfs, "x", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB); + }else{ + /* This is a real ATTACH + ** + ** Check for the following errors: + ** + ** * Too many attached databases, + ** * Transaction currently open + ** * Specified database name already being used. + */ + if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ + zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", + db->aLimit[SQLITE_LIMIT_ATTACHED] + ); goto attach_error; } + for(i=0; inDb; i++){ + char *z = db->aDb[i].zDbSName; + assert( z && zName ); + if( sqlite3StrICmp(z, zName)==0 ){ + zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); + goto attach_error; + } + } + + /* Allocate the new entry in the db->aDb[] array and initialize the schema + ** hash tables. + */ + if( db->aDb==db->aDbStatic ){ + aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); + if( aNew==0 ) return; + memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); + }else{ + aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); + if( aNew==0 ) return; + } + db->aDb = aNew; + pNew = &db->aDb[db->nDb]; + memset(pNew, 0, sizeof(*pNew)); + + /* Open the database file. If the btree is successfully opened, use + ** it to obtain the database schema. At this point the schema may + ** or may not be initialized. + */ + flags = db->openFlags; + rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); + if( rc!=SQLITE_OK ){ + if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); + sqlite3_result_error(context, zErr, -1); + sqlite3_free(zErr); + return; + } + assert( pVfs ); + flags |= SQLITE_OPEN_MAIN_DB; + rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); + sqlite3_free( zPath ); + db->nDb++; } - - /* Allocate the new entry in the db->aDb[] array and initialize the schema - ** hash tables. - */ - if( db->aDb==db->aDbStatic ){ - aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); - if( aNew==0 ) return; - memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); - }else{ - aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); - if( aNew==0 ) return; - } - db->aDb = aNew; - pNew = &db->aDb[db->nDb]; - memset(pNew, 0, sizeof(*pNew)); - - /* Open the database file. If the btree is successfully opened, use - ** it to obtain the database schema. At this point the schema may - ** or may not be initialized. - */ - flags = db->openFlags; - rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); - if( rc!=SQLITE_OK ){ - if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); - sqlite3_result_error(context, zErr, -1); - sqlite3_free(zErr); - return; - } - assert( pVfs ); - flags |= SQLITE_OPEN_MAIN_DB; - rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); - sqlite3_free( zPath ); - db->nDb++; db->skipBtreeMutex = 0; if( rc==SQLITE_CONSTRAINT ){ rc = SQLITE_ERROR; @@ -160,7 +184,7 @@ static void attachFunc( sqlite3BtreeLeave(pNew->pBt); } pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; - pNew->zDbSName = sqlite3DbStrDup(db, zName); + if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName); if( rc==SQLITE_OK && pNew->zDbSName==0 ){ rc = SQLITE_NOMEM_BKPT; } @@ -200,13 +224,15 @@ static void attachFunc( /* If the file was opened successfully, read the schema for the new database. ** If this fails, or if opening the file failed, then close the file and - ** remove the entry from the db->aDb[] array. i.e. put everything back the way - ** we found it. + ** remove the entry from the db->aDb[] array. i.e. put everything back the + ** way we found it. */ if( rc==SQLITE_OK ){ sqlite3BtreeEnterAll(db); + db->init.iDb = 0; rc = sqlite3Init(db, &zErrDyn); sqlite3BtreeLeaveAll(db); + assert( zErrDyn==0 || rc!=SQLITE_OK ); } #ifdef SQLITE_USER_AUTHENTICATION if( rc==SQLITE_OK ){ @@ -218,21 +244,23 @@ static void attachFunc( } #endif if( rc ){ - int iDb = db->nDb - 1; - assert( iDb>=2 ); - if( db->aDb[iDb].pBt ){ - sqlite3BtreeClose(db->aDb[iDb].pBt); - db->aDb[iDb].pBt = 0; - db->aDb[iDb].pSchema = 0; - } - sqlite3ResetAllSchemasOfConnection(db); - db->nDb = iDb; - if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ - sqlite3OomFault(db); - sqlite3DbFree(db, zErrDyn); - zErrDyn = sqlite3MPrintf(db, "out of memory"); - }else if( zErrDyn==0 ){ - zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); + if( !REOPEN_AS_MEMDB(db) ){ + int iDb = db->nDb - 1; + assert( iDb>=2 ); + if( db->aDb[iDb].pBt ){ + sqlite3BtreeClose(db->aDb[iDb].pBt); + db->aDb[iDb].pBt = 0; + db->aDb[iDb].pSchema = 0; + } + sqlite3ResetAllSchemasOfConnection(db); + db->nDb = iDb; + if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ + sqlite3OomFault(db); + sqlite3DbFree(db, zErrDyn); + zErrDyn = sqlite3MPrintf(db, "out of memory"); + }else if( zErrDyn==0 ){ + zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); + } } goto attach_error; } diff --git a/src/build.c b/src/build.c index 8e69363b0a..7566a37e37 100644 --- a/src/build.c +++ b/src/build.c @@ -1872,8 +1872,6 @@ void sqlite3EndTable( p = pParse->pNewTable; if( p==0 ) return; - assert( !db->init.busy || !pSelect ); - /* If the db->init.busy is 1 it means we are reading the SQL off the ** "sqlite_master" or "sqlite_temp_master" table on the disk. ** So do not write to the disk again. Extract the root page number @@ -1884,6 +1882,10 @@ void sqlite3EndTable( ** table itself. So mark it read-only. */ if( db->init.busy ){ + if( pSelect ){ + sqlite3ErrorMsg(pParse, ""); + return; + } p->tnum = db->init.newTnum; if( p->tnum==1 ) p->tabFlags |= TF_Readonly; } diff --git a/src/ctime.c b/src/ctime.c index e8f4e7f90b..1877aee10a 100644 --- a/src/ctime.c +++ b/src/ctime.c @@ -188,7 +188,7 @@ static const char * const sqlite3azCompileOpt[] = { "ENABLE_BATCH_ATOMIC_WRITE", #endif #if SQLITE_ENABLE_CEROD - "ENABLE_CEROD", + "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD), #endif #if SQLITE_ENABLE_COLUMN_METADATA "ENABLE_COLUMN_METADATA", diff --git a/src/insert.c b/src/insert.c index e1514692cc..9f7032c52c 100644 --- a/src/insert.c +++ b/src/insert.c @@ -210,11 +210,12 @@ static int readsTable(Parse *p, int iDb, Table *pTab){ ** first use of table pTab. On 2nd and subsequent uses, the original ** AutoincInfo structure is used. ** -** Three memory locations are allocated: +** Four consecutive registers are allocated: ** -** (1) Register to hold the name of the pTab table. -** (2) Register to hold the maximum ROWID of pTab. -** (3) Register to hold the rowid in sqlite_sequence of pTab +** (1) The name of the pTab table. +** (2) The maximum ROWID of pTab. +** (3) The rowid in sqlite_sequence of pTab +** (4) The original value of the max ROWID in pTab, or NULL if none ** ** The 2nd register is the one that is returned. That is all the ** insert routine needs to know about. @@ -242,7 +243,7 @@ static int autoIncBegin( pInfo->iDb = iDb; pToplevel->nMem++; /* Register to hold name of table */ pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */ - pToplevel->nMem++; /* Rowid in sqlite_sequence */ + pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */ } memId = pInfo->regCtr; } @@ -270,15 +271,17 @@ void sqlite3AutoincrementBegin(Parse *pParse){ static const int iLn = VDBE_OFFSET_LINENO(2); static const VdbeOpList autoInc[] = { /* 0 */ {OP_Null, 0, 0, 0}, - /* 1 */ {OP_Rewind, 0, 9, 0}, + /* 1 */ {OP_Rewind, 0, 10, 0}, /* 2 */ {OP_Column, 0, 0, 0}, - /* 3 */ {OP_Ne, 0, 7, 0}, + /* 3 */ {OP_Ne, 0, 9, 0}, /* 4 */ {OP_Rowid, 0, 0, 0}, /* 5 */ {OP_Column, 0, 1, 0}, - /* 6 */ {OP_Goto, 0, 9, 0}, - /* 7 */ {OP_Next, 0, 2, 0}, - /* 8 */ {OP_Integer, 0, 0, 0}, - /* 9 */ {OP_Close, 0, 0, 0} + /* 6 */ {OP_AddImm, 0, 0, 0}, + /* 7 */ {OP_Copy, 0, 0, 0}, + /* 8 */ {OP_Goto, 0, 11, 0}, + /* 9 */ {OP_Next, 0, 2, 0}, + /* 10 */ {OP_Integer, 0, 0, 0}, + /* 11 */ {OP_Close, 0, 0, 0} }; VdbeOp *aOp; pDb = &db->aDb[p->iDb]; @@ -289,14 +292,17 @@ void sqlite3AutoincrementBegin(Parse *pParse){ aOp = sqlite3VdbeAddOpList(v, ArraySize(autoInc), autoInc, iLn); if( aOp==0 ) break; aOp[0].p2 = memId; - aOp[0].p3 = memId+1; + aOp[0].p3 = memId+2; aOp[2].p3 = memId; aOp[3].p1 = memId-1; aOp[3].p3 = memId; aOp[3].p5 = SQLITE_JUMPIFNULL; aOp[4].p2 = memId+1; aOp[5].p3 = memId; - aOp[8].p2 = memId; + aOp[6].p1 = memId; + aOp[7].p2 = memId+2; + aOp[7].p1 = memId; + aOp[10].p2 = memId; } } @@ -343,6 +349,8 @@ static SQLITE_NOINLINE void autoIncrementEnd(Parse *pParse){ iRec = sqlite3GetTempReg(pParse); assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); + sqlite3VdbeAddOp3(v, OP_Le, memId+2, sqlite3VdbeCurrentAddr(v)+7, memId); + VdbeCoverage(v); sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite); aOp = sqlite3VdbeAddOpList(v, ArraySize(autoIncEnd), autoIncEnd, iLn); if( aOp==0 ) break; diff --git a/src/main.c b/src/main.c index bfe38e1093..a78691d396 100644 --- a/src/main.c +++ b/src/main.c @@ -239,6 +239,11 @@ int sqlite3_initialize(void){ sqlite3GlobalConfig.isPCacheInit = 1; rc = sqlite3OsInit(); } +#ifdef SQLITE_ENABLE_DESERIALIZE + if( rc==SQLITE_OK ){ + rc = sqlite3MemdbInit(); + } +#endif if( rc==SQLITE_OK ){ sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); @@ -271,7 +276,7 @@ int sqlite3_initialize(void){ #ifndef NDEBUG #ifndef SQLITE_OMIT_FLOATING_POINT /* This section of code's only "output" is via assert() statements. */ - if ( rc==SQLITE_OK ){ + if( rc==SQLITE_OK ){ u64 x = (((u64)1)<<63)-1; double y; assert(sizeof(x)==8); diff --git a/src/memdb.c b/src/memdb.c new file mode 100644 index 0000000000..68bec75ea9 --- /dev/null +++ b/src/memdb.c @@ -0,0 +1,589 @@ +/* +** 2016-09-07 +** +** 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 implements in-memory VFS. A database is held as a contiguous +** block of memory. +** +** This file also implements interface sqlite3_serialize() and +** sqlite3_deserialize(). +*/ +#ifdef SQLITE_ENABLE_DESERIALIZE +#include "sqliteInt.h" + +/* +** Forward declaration of objects used by this utility +*/ +typedef struct sqlite3_vfs MemVfs; +typedef struct MemFile MemFile; + +/* Access to a lower-level VFS that (might) implement dynamic loading, +** access to randomness, etc. +*/ +#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData)) + +/* An open file */ +struct MemFile { + sqlite3_file base; /* IO methods */ + sqlite3_int64 sz; /* Size of the file */ + sqlite3_int64 szMax; /* Space allocated to aData */ + unsigned char *aData; /* content of the file */ + int nMmap; /* Number of memory mapped pages */ + unsigned mFlags; /* Flags */ + int eLock; /* Most recent lock against this file */ +}; + +/* +** Methods for MemFile +*/ +static int memdbClose(sqlite3_file*); +static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); +static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst); +static int memdbTruncate(sqlite3_file*, sqlite3_int64 size); +static int memdbSync(sqlite3_file*, int flags); +static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize); +static int memdbLock(sqlite3_file*, int); +/* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */ +static int memdbFileControl(sqlite3_file*, int op, void *pArg); +/* static int memdbSectorSize(sqlite3_file*); // not used */ +static int memdbDeviceCharacteristics(sqlite3_file*); +static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); +static int memdbUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p); + +/* +** Methods for MemVfs +*/ +static int memdbOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); +/* static int memdbDelete(sqlite3_vfs*, const char *zName, int syncDir); */ +static int memdbAccess(sqlite3_vfs*, const char *zName, int flags, int *); +static int memdbFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); +static void *memdbDlOpen(sqlite3_vfs*, const char *zFilename); +static void memdbDlError(sqlite3_vfs*, int nByte, char *zErrMsg); +static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void); +static void memdbDlClose(sqlite3_vfs*, void*); +static int memdbRandomness(sqlite3_vfs*, int nByte, char *zOut); +static int memdbSleep(sqlite3_vfs*, int microseconds); +/* static int memdbCurrentTime(sqlite3_vfs*, double*); */ +static int memdbGetLastError(sqlite3_vfs*, int, char *); +static int memdbCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); + +static sqlite3_vfs memdb_vfs = { + 2, /* iVersion */ + 0, /* szOsFile (set when registered) */ + 1024, /* mxPathname */ + 0, /* pNext */ + "memdb", /* zName */ + 0, /* pAppData (set when registered) */ + memdbOpen, /* xOpen */ + 0, /* memdbDelete, */ /* xDelete */ + memdbAccess, /* xAccess */ + memdbFullPathname, /* xFullPathname */ + memdbDlOpen, /* xDlOpen */ + memdbDlError, /* xDlError */ + memdbDlSym, /* xDlSym */ + memdbDlClose, /* xDlClose */ + memdbRandomness, /* xRandomness */ + memdbSleep, /* xSleep */ + 0, /* memdbCurrentTime, */ /* xCurrentTime */ + memdbGetLastError, /* xGetLastError */ + memdbCurrentTimeInt64 /* xCurrentTimeInt64 */ +}; + +static const sqlite3_io_methods memdb_io_methods = { + 3, /* iVersion */ + memdbClose, /* xClose */ + memdbRead, /* xRead */ + memdbWrite, /* xWrite */ + memdbTruncate, /* xTruncate */ + memdbSync, /* xSync */ + memdbFileSize, /* xFileSize */ + memdbLock, /* xLock */ + memdbLock, /* xUnlock - same as xLock in this case */ + 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */ + memdbFileControl, /* xFileControl */ + 0, /* memdbSectorSize,*/ /* xSectorSize */ + memdbDeviceCharacteristics, /* xDeviceCharacteristics */ + 0, /* xShmMap */ + 0, /* xShmLock */ + 0, /* xShmBarrier */ + 0, /* xShmUnmap */ + memdbFetch, /* xFetch */ + memdbUnfetch /* xUnfetch */ +}; + + + +/* +** Close an memdb-file. +** +** The pData pointer is owned by the application, so there is nothing +** to free. +*/ +static int memdbClose(sqlite3_file *pFile){ + MemFile *p = (MemFile *)pFile; + if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData); + return SQLITE_OK; +} + +/* +** Read data from an memdb-file. +*/ +static int memdbRead( + sqlite3_file *pFile, + void *zBuf, + int iAmt, + sqlite_int64 iOfst +){ + MemFile *p = (MemFile *)pFile; + if( iOfst+iAmt>p->sz ){ + memset(zBuf, 0, iAmt); + if( iOfstsz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst); + return SQLITE_IOERR_SHORT_READ; + } + memcpy(zBuf, p->aData+iOfst, iAmt); + return SQLITE_OK; +} + +/* +** Try to enlarge the memory allocation to hold at least sz bytes +*/ +static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){ + unsigned char *pNew; + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ + return SQLITE_FULL; + } + pNew = sqlite3_realloc64(p->aData, newSz); + if( pNew==0 ) return SQLITE_NOMEM; + p->aData = pNew; + p->szMax = newSz; + return SQLITE_OK; +} + +/* +** Write data to an memdb-file. +*/ +static int memdbWrite( + sqlite3_file *pFile, + const void *z, + int iAmt, + sqlite_int64 iOfst +){ + MemFile *p = (MemFile *)pFile; + if( iOfst+iAmt>p->sz ){ + int rc; + if( iOfst+iAmt>p->szMax + && (rc = memdbEnlarge(p, (iOfst+iAmt)*2))!=SQLITE_OK + ){ + return rc; + } + if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz); + p->sz = iOfst+iAmt; + } + memcpy(p->aData+iOfst, z, iAmt); + return SQLITE_OK; +} + +/* +** Truncate an memdb-file. +** +** In rollback mode (which is always the case for memdb, as it does not +** support WAL mode) the truncate() method is only used to reduce +** the size of a file, never to increase the size. +*/ +static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ + MemFile *p = (MemFile *)pFile; + if( NEVER(size>p->sz) ) return SQLITE_FULL; + p->sz = size; + return SQLITE_OK; +} + +/* +** Sync an memdb-file. +*/ +static int memdbSync(sqlite3_file *pFile, int flags){ + return SQLITE_OK; +} + +/* +** Return the current file-size of an memdb-file. +*/ +static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ + MemFile *p = (MemFile *)pFile; + *pSize = p->sz; + return SQLITE_OK; +} + +/* +** Lock an memdb-file. +*/ +static int memdbLock(sqlite3_file *pFile, int eLock){ + MemFile *p = (MemFile *)pFile; + p->eLock = eLock; + return SQLITE_OK; +} + +#if 0 /* Never used because memdbAccess() always returns false */ +/* +** Check if another file-handle holds a RESERVED lock on an memdb-file. +*/ +static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){ + *pResOut = 0; + return SQLITE_OK; +} +#endif + +/* +** File control method. For custom operations on an memdb-file. +*/ +static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){ + MemFile *p = (MemFile *)pFile; + int rc = SQLITE_NOTFOUND; + if( op==SQLITE_FCNTL_VFSNAME ){ + *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz); + rc = SQLITE_OK; + } + return rc; +} + +#if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */ +/* +** Return the sector-size in bytes for an memdb-file. +*/ +static int memdbSectorSize(sqlite3_file *pFile){ + return 1024; +} +#endif + +/* +** Return the device characteristic flags supported by an memdb-file. +*/ +static int memdbDeviceCharacteristics(sqlite3_file *pFile){ + return SQLITE_IOCAP_ATOMIC | + SQLITE_IOCAP_POWERSAFE_OVERWRITE | + SQLITE_IOCAP_SAFE_APPEND | + SQLITE_IOCAP_SEQUENTIAL; +} + +/* Fetch a page of a memory-mapped file */ +static int memdbFetch( + sqlite3_file *pFile, + sqlite3_int64 iOfst, + int iAmt, + void **pp +){ + MemFile *p = (MemFile *)pFile; + p->nMmap++; + *pp = (void*)(p->aData + iOfst); + return SQLITE_OK; +} + +/* Release a memory-mapped page */ +static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){ + MemFile *p = (MemFile *)pFile; + p->nMmap--; + return SQLITE_OK; +} + +/* +** Open an mem file handle. +*/ +static int memdbOpen( + sqlite3_vfs *pVfs, + const char *zName, + sqlite3_file *pFile, + int flags, + int *pOutFlags +){ + MemFile *p = (MemFile*)pFile; + if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ + return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags); + } + memset(p, 0, sizeof(*p)); + p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; + assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ + *pOutFlags = flags | SQLITE_OPEN_MEMORY; + p->base.pMethods = &memdb_io_methods; + return SQLITE_OK; +} + +#if 0 /* Only used to delete rollback journals, master journals, and WAL + ** files, none of which exist in memdb. So this routine is never used */ +/* +** Delete the file located at zPath. If the dirSync argument is true, +** ensure the file-system modifications are synced to disk before +** returning. +*/ +static int memdbDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ + return SQLITE_IOERR_DELETE; +} +#endif + +/* +** Test for access permissions. Return true if the requested permission +** is available, or false otherwise. +** +** With memdb, no files ever exist on disk. So always return false. +*/ +static int memdbAccess( + sqlite3_vfs *pVfs, + const char *zPath, + int flags, + int *pResOut +){ + *pResOut = 0; + return SQLITE_OK; +} + +/* +** Populate buffer zOut with the full canonical pathname corresponding +** to the pathname in zPath. zOut is guaranteed to point to a buffer +** of at least (INST_MAX_PATHNAME+1) bytes. +*/ +static int memdbFullPathname( + sqlite3_vfs *pVfs, + const char *zPath, + int nOut, + char *zOut +){ + sqlite3_snprintf(nOut, zOut, "%s", zPath); + return SQLITE_OK; +} + +/* +** Open the dynamic library located at zPath and return a handle. +*/ +static void *memdbDlOpen(sqlite3_vfs *pVfs, const char *zPath){ + return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath); +} + +/* +** Populate the buffer zErrMsg (size nByte bytes) with a human readable +** utf-8 string describing the most recent error encountered associated +** with dynamic libraries. +*/ +static void memdbDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){ + ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg); +} + +/* +** Return a pointer to the symbol zSymbol in the dynamic library pHandle. +*/ +static void (*memdbDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){ + return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym); +} + +/* +** Close the dynamic library handle pHandle. +*/ +static void memdbDlClose(sqlite3_vfs *pVfs, void *pHandle){ + ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle); +} + +/* +** Populate the buffer pointed to by zBufOut with nByte bytes of +** random data. +*/ +static int memdbRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ + return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut); +} + +/* +** Sleep for nMicro microseconds. Return the number of microseconds +** actually slept. +*/ +static int memdbSleep(sqlite3_vfs *pVfs, int nMicro){ + return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro); +} + +#if 0 /* Never used. Modern cores only call xCurrentTimeInt64() */ +/* +** Return the current time as a Julian Day number in *pTimeOut. +*/ +static int memdbCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ + return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut); +} +#endif + +static int memdbGetLastError(sqlite3_vfs *pVfs, int a, char *b){ + return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b); +} +static int memdbCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){ + return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p); +} + +/* +** Translate a database connection pointer and schema name into a +** MemFile pointer. +*/ +static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){ + MemFile *p = 0; + int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p); + if( rc ) return 0; + if( p->base.pMethods!=&memdb_io_methods ) return 0; + return p; +} + +/* +** Return the serialization of a database +*/ +unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which database within the connection */ + sqlite3_int64 *piSize, /* Write size here, if not NULL */ + unsigned int mFlags /* Maybe SQLITE_SERIALIZE_NOCOPY */ +){ + MemFile *p; + int iDb; + Btree *pBt; + sqlite3_int64 sz; + int szPage = 0; + sqlite3_stmt *pStmt = 0; + unsigned char *pOut; + char *zSql; + int rc; + +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) ){ + (void)SQLITE_MISUSE_BKPT; + return 0; + } +#endif + + if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; + p = memdbFromDbSchema(db, zSchema); + iDb = sqlite3FindDbName(db, zSchema); + if( piSize ) *piSize = -1; + if( iDb<0 ) return 0; + if( p ){ + if( piSize ) *piSize = p->sz; + if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ + pOut = p->aData; + }else{ + pOut = sqlite3_malloc64( p->sz ); + if( pOut ) memcpy(pOut, p->aData, p->sz); + } + return pOut; + } + pBt = db->aDb[iDb].pBt; + if( pBt==0 ) return 0; + szPage = sqlite3BtreeGetPageSize(pBt); + zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema); + rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM; + sqlite3_free(zSql); + if( rc ) return 0; + rc = sqlite3_step(pStmt); + if( rc!=SQLITE_ROW ){ + pOut = 0; + }else{ + sz = sqlite3_column_int64(pStmt, 0)*szPage; + if( piSize ) *piSize = sz; + if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ + pOut = 0; + }else{ + pOut = sqlite3_malloc64( sz ); + if( pOut ){ + int nPage = sqlite3_column_int(pStmt, 0); + Pager *pPager = sqlite3BtreePager(pBt); + int pgno; + for(pgno=1; pgno<=nPage; pgno++){ + DbPage *pPage = 0; + unsigned char *pTo = pOut + szPage*(sqlite3_int64)(pgno-1); + rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0); + if( rc==SQLITE_OK ){ + memcpy(pTo, sqlite3PagerGetData(pPage), szPage); + }else{ + memset(pTo, 0, szPage); + } + sqlite3PagerUnref(pPage); + } + } + } + } + sqlite3_finalize(pStmt); + return pOut; +} + +/* Convert zSchema to a MemDB and initialize its content. +*/ +int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +){ + MemFile *p; + char *zSql; + sqlite3_stmt *pStmt = 0; + int rc; + int iDb; + +#ifdef SQLITE_ENABLE_API_ARMOR + if( !sqlite3SafetyCheckOk(db) ){ + return SQLITE_MISUSE_BKPT; + } + if( szDb<0 ) return SQLITE_MISUSE_BKPT; + if( szBuf<0 ) return SQLITE_MISUSE_BKPT; +#endif + + sqlite3_mutex_enter(db->mutex); + if( zSchema==0 ) zSchema = db->aDb[0].zDbSName; + iDb = sqlite3FindDbName(db, zSchema); + if( iDb<0 ){ + rc = SQLITE_ERROR; + goto end_deserialize; + } + zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema); + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); + sqlite3_free(zSql); + if( rc ) goto end_deserialize; + db->init.iDb = (u8)iDb; + db->init.reopenMemdb = 1; + rc = sqlite3_step(pStmt); + db->init.reopenMemdb = 0; + if( rc!=SQLITE_DONE ){ + rc = SQLITE_ERROR; + goto end_deserialize; + } + p = memdbFromDbSchema(db, zSchema); + if( p==0 ){ + rc = SQLITE_ERROR; + }else{ + p->aData = pData; + p->sz = szDb; + p->szMax = szBuf; + p->mFlags = mFlags; + rc = SQLITE_OK; + } + +end_deserialize: + sqlite3_finalize(pStmt); + sqlite3_mutex_leave(db->mutex); + return rc; +} + +/* +** This routine is called when the extension is loaded. +** Register the new VFS. +*/ +int sqlite3MemdbInit(void){ + sqlite3_vfs *pLower = sqlite3_vfs_find(0); + int sz = pLower->szOsFile; + memdb_vfs.pAppData = pLower; + /* In all known configurations of SQLite, the size of a default + ** sqlite3_file is greater than the size of a memdb sqlite3_file. + ** Should that ever change, remove the following NEVER() */ + if( NEVER(szaStat[PAGER_STAT_SPILL]++; pPg->pDirty = 0; if( pagerUseWal(pPager) ){ #ifndef SQLITE_OMIT_CONCURRENT @@ -4791,6 +4793,11 @@ int sqlite3PagerOpen( int rc = SQLITE_OK; /* Return code */ int tempFile = 0; /* True for temp files (incl. in-memory files) */ int memDb = 0; /* True if this is an in-memory file */ +#ifdef SQLITE_ENABLE_DESERIALIZE + int memJM = 0; /* Memory journal mode */ +#else +# define memJM 0 +#endif int readOnly = 0; /* True if this is a read-only file */ int journalFileSize; /* Bytes to allocate for each journal fd */ char *zPathname = 0; /* Full path to database file */ @@ -4918,7 +4925,10 @@ int sqlite3PagerOpen( int fout = 0; /* VFS flags returned by xOpen() */ rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); assert( !memDb ); - readOnly = (fout&SQLITE_OPEN_READONLY); +#ifdef SQLITE_ENABLE_DESERIALIZE + memJM = (fout&SQLITE_OPEN_MEMORY)!=0; +#endif + readOnly = (fout&SQLITE_OPEN_READONLY)!=0; /* If the file was successfully opened for read/write access, ** choose a default page size in case we have to create the @@ -5049,7 +5059,7 @@ act_like_temp_file: setSectorSize(pPager); if( !useJournal ){ pPager->journalMode = PAGER_JOURNALMODE_OFF; - }else if( memDb ){ + }else if( memDb || memJM ){ pPager->journalMode = PAGER_JOURNALMODE_MEMORY; } /* pPager->xBusyHandler = 0; */ @@ -6885,8 +6895,12 @@ int *sqlite3PagerStats(Pager *pPager){ #endif /* -** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or -** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the +** Parameter eStat must be one of SQLITE_DBSTATUS_CACHE_HIT, _MISS, _WRITE, +** or _WRITE+1. The SQLITE_DBSTATUS_CACHE_WRITE+1 case is a translation +** of SQLITE_DBSTATUS_CACHE_SPILL. The _SPILL case is not contiguous because +** it was added later. +** +** Before returning, *pnVal is incremented by the ** current cache hit or miss count, according to the value of eStat. If the ** reset parameter is non-zero, the cache hit or miss count is zeroed before ** returning. @@ -6896,15 +6910,18 @@ void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){ assert( eStat==SQLITE_DBSTATUS_CACHE_HIT || eStat==SQLITE_DBSTATUS_CACHE_MISS || eStat==SQLITE_DBSTATUS_CACHE_WRITE + || eStat==SQLITE_DBSTATUS_CACHE_WRITE+1 ); assert( SQLITE_DBSTATUS_CACHE_HIT+1==SQLITE_DBSTATUS_CACHE_MISS ); assert( SQLITE_DBSTATUS_CACHE_HIT+2==SQLITE_DBSTATUS_CACHE_WRITE ); - assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 && PAGER_STAT_WRITE==2 ); + assert( PAGER_STAT_HIT==0 && PAGER_STAT_MISS==1 + && PAGER_STAT_WRITE==2 && PAGER_STAT_SPILL==3 ); - *pnVal += pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT]; + eStat -= SQLITE_DBSTATUS_CACHE_HIT; + *pnVal += pPager->aStat[eStat]; if( reset ){ - pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0; + pPager->aStat[eStat] = 0; } } diff --git a/src/parse.y b/src/parse.y index 1665346048..e9b063f716 100644 --- a/src/parse.y +++ b/src/parse.y @@ -538,8 +538,7 @@ oneselect(A) ::= SELECT(S) distinct(D) selcollist(W) from(X) where_opt(Y) if( A!=0 ){ const char *z = s.z+6; int i; - sqlite3_snprintf(sizeof(A->zSelName), A->zSelName, "#%d", - ++pParse->nSelect); + sqlite3_snprintf(sizeof(A->zSelName), A->zSelName,"#%d",++pParse->nSelect); while( z[0]==' ' ) z++; if( z[0]=='/' && z[1]=='*' ){ z += 2; diff --git a/src/pcache.c b/src/pcache.c index 4b2e481c27..41fb03100c 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -431,7 +431,7 @@ int sqlite3PcacheFetchStress( sqlite3_log(SQLITE_FULL, "spill page %d making room for %d - cache used: %d/%d", pPg->pgno, pgno, - sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), + sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache), numberOfCachePages(pCache)); #endif pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno)); diff --git a/src/prepare.c b/src/prepare.c index 65a4afcbbd..c1bd20f16b 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -29,7 +29,7 @@ static void corruptSchema( char *z; if( zObj==0 ) zObj = "?"; z = sqlite3MPrintf(db, "malformed database schema (%s)", zObj); - if( zExtra ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); + if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); sqlite3DbFree(db, *pData->pzErrMsg); *pData->pzErrMsg = z; } diff --git a/src/select.c b/src/select.c index 9ac4f9f198..5b60fc6a67 100644 --- a/src/select.c +++ b/src/select.c @@ -21,8 +21,7 @@ /***/ int sqlite3SelectTrace = 0; # define SELECTTRACE(K,P,S,X) \ if(sqlite3SelectTrace&(K)) \ - sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",\ - (S)->zSelName,(S)),\ + sqlite3DebugPrintf("%s/%p: ",(S)->zSelName,(S)),\ sqlite3DebugPrintf X #else # define SELECTTRACE(K,P,S,X) @@ -5142,7 +5141,6 @@ int sqlite3Select( if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; memset(&sAggInfo, 0, sizeof(sAggInfo)); #if SELECTTRACE_ENABLED - pParse->nSelectIndent++; SELECTTRACE(1,pParse,p, ("begin processing:\n")); if( sqlite3SelectTrace & 0x100 ){ sqlite3TreeViewSelect(0, p, 0); @@ -5263,7 +5261,6 @@ int sqlite3Select( explainSetInteger(pParse->iSelectId, iRestoreSelectId); #if SELECTTRACE_ENABLED SELECTTRACE(1,pParse,p,("end compound-select processing\n")); - pParse->nSelectIndent--; #endif return rc; } @@ -5337,6 +5334,7 @@ int sqlite3Select( ** inside the subquery. This can help the subquery to run more efficiently. */ if( (pItem->fg.jointype & JT_OUTER)==0 + && OptimizationEnabled(db, SQLITE_PushDown) && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor) ){ #if SELECTTRACE_ENABLED @@ -5345,6 +5343,8 @@ int sqlite3Select( sqlite3TreeViewSelect(0, p, 0); } #endif + }else{ + SELECTTRACE(0x100,pParse,p,("Push-down not possible\n")); } zSavedAuthContext = pParse->zAuthContext; @@ -5547,6 +5547,7 @@ int sqlite3Select( wctrlFlags |= p->selFlags & SF_FixedLimit; /* Begin the database scan. */ + SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy, p->pEList, wctrlFlags, p->nSelectRow); if( pWInfo==0 ) goto select_end; @@ -5735,6 +5736,7 @@ int sqlite3Select( ** in the right order to begin with. */ sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); + SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0, WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0 ); @@ -5990,6 +5992,7 @@ int sqlite3Select( assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 ); assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 ); + SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy, 0, minMaxFlag, 0); if( pWInfo==0 ){ @@ -6045,7 +6048,6 @@ select_end: sqlite3DbFree(db, sAggInfo.aFunc); #if SELECTTRACE_ENABLED SELECTTRACE(1,pParse,p,("end processing\n")); - pParse->nSelectIndent--; #endif return rc; } diff --git a/src/shell.c.in b/src/shell.c.in index 121a6c3506..a8342f5b17 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2273,29 +2273,54 @@ static int display_stats( ){ int iCur; int iHiwtr; + FILE *out; + if( pArg==0 || pArg->out==0 ) return 0; + out = pArg->out; - if( pArg && pArg->out ){ - displayStatLine(pArg, "Memory Used:", - "%lld (max %lld) bytes", SQLITE_STATUS_MEMORY_USED, bReset); - displayStatLine(pArg, "Number of Outstanding Allocations:", - "%lld (max %lld)", SQLITE_STATUS_MALLOC_COUNT, bReset); - if( pArg->shellFlgs & SHFLG_Pagecache ){ - displayStatLine(pArg, "Number of Pcache Pages Used:", - "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset); - } - displayStatLine(pArg, "Number of Pcache Overflow Bytes:", - "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset); - displayStatLine(pArg, "Largest Allocation:", - "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset); - displayStatLine(pArg, "Largest Pcache Allocation:", - "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset); -#ifdef YYTRACKMAXSTACKDEPTH - displayStatLine(pArg, "Deepest Parser Stack:", - "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset); + if( pArg->pStmt && (pArg->statsOn & 2) ){ + int nCol, i, x; + sqlite3_stmt *pStmt = pArg->pStmt; + char z[100]; + nCol = sqlite3_column_count(pStmt); + raw_printf(out, "%-36s %d\n", "Number of output columns:", nCol); + for(i=0; iout && db ){ + displayStatLine(pArg, "Memory Used:", + "%lld (max %lld) bytes", SQLITE_STATUS_MEMORY_USED, bReset); + displayStatLine(pArg, "Number of Outstanding Allocations:", + "%lld (max %lld)", SQLITE_STATUS_MALLOC_COUNT, bReset); + if( pArg->shellFlgs & SHFLG_Pagecache ){ + displayStatLine(pArg, "Number of Pcache Pages Used:", + "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset); + } + displayStatLine(pArg, "Number of Pcache Overflow Bytes:", + "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset); + displayStatLine(pArg, "Largest Allocation:", + "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset); + displayStatLine(pArg, "Largest Pcache Allocation:", + "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset); +#ifdef YYTRACKMAXSTACKDEPTH + displayStatLine(pArg, "Deepest Parser Stack:", + "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset); +#endif + + if( db ){ if( pArg->shellFlgs & SHFLG_Lookaside ){ iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, @@ -2330,6 +2355,9 @@ static int display_stats( sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1); raw_printf(pArg->out, "Page cache writes: %d\n", iCur); iHiwtr = iCur = -1; + sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_SPILL, &iCur, &iHiwtr, 1); + raw_printf(pArg->out, "Page cache spills: %d\n", iCur); + iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset); raw_printf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur); @@ -2339,7 +2367,7 @@ static int display_stats( iCur); } - if( pArg && pArg->out && db && pArg->pStmt ){ + if( pArg->pStmt ){ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset); raw_printf(pArg->out, "Fullscan Steps: %d\n", iCur); @@ -2349,6 +2377,12 @@ static int display_stats( raw_printf(pArg->out, "Autoindex Inserts: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); raw_printf(pArg->out, "Virtual Machine Steps: %d\n", iCur); + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_REPREPARE, bReset); + raw_printf(pArg->out, "Reprepare operations: %d\n", iCur); + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_RUN, bReset); + raw_printf(pArg->out, "Number of times run: %d\n", iCur); + iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_MEMUSED, bReset); + raw_printf(pArg->out, "Memory used by prepared stmt: %d\n", iCur); } #ifdef __linux__ @@ -2564,8 +2598,7 @@ static void restore_debug_trace_modes(void){ */ static void exec_prepared_stmt( ShellState *pArg, /* Pointer to ShellState */ - sqlite3_stmt *pStmt, /* Statment to run */ - int (*xCallback)(void*,int,char**,char**,int*) /* Callback function */ + sqlite3_stmt *pStmt /* Statment to run */ ){ int rc; @@ -2575,54 +2608,47 @@ static void exec_prepared_stmt( rc = sqlite3_step(pStmt); /* if we have a result set... */ if( SQLITE_ROW == rc ){ - /* if we have a callback... */ - if( xCallback ){ - /* allocate space for col name ptr, value ptr, and type */ - int nCol = sqlite3_column_count(pStmt); - void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1); - if( !pData ){ - rc = SQLITE_NOMEM; - }else{ - char **azCols = (char **)pData; /* Names of result columns */ - char **azVals = &azCols[nCol]; /* Results */ - int *aiTypes = (int *)&azVals[nCol]; /* Result types */ - int i, x; - assert(sizeof(int) <= sizeof(char *)); - /* save off ptrs to column names */ - for(i=0; icMode==MODE_Insert ){ - azVals[i] = ""; - }else{ - azVals[i] = (char*)sqlite3_column_text(pStmt, i); - } - if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){ - rc = SQLITE_NOMEM; - break; /* from for */ - } - } /* end for */ - - /* if data and types extracted successfully... */ - if( SQLITE_ROW == rc ){ - /* call the supplied callback with the result row data */ - if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){ - rc = SQLITE_ABORT; - }else{ - rc = sqlite3_step(pStmt); - } - } - } while( SQLITE_ROW == rc ); - sqlite3_free(pData); - } + /* allocate space for col name ptr, value ptr, and type */ + int nCol = sqlite3_column_count(pStmt); + void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1); + if( !pData ){ + rc = SQLITE_NOMEM; }else{ + char **azCols = (char **)pData; /* Names of result columns */ + char **azVals = &azCols[nCol]; /* Results */ + int *aiTypes = (int *)&azVals[nCol]; /* Result types */ + int i, x; + assert(sizeof(int) <= sizeof(char *)); + /* save off ptrs to column names */ + for(i=0; icMode==MODE_Insert ){ + azVals[i] = ""; + }else{ + azVals[i] = (char*)sqlite3_column_text(pStmt, i); + } + if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){ + rc = SQLITE_NOMEM; + break; /* from for */ + } + } /* end for */ + + /* if data and types extracted successfully... */ + if( SQLITE_ROW == rc ){ + /* call the supplied callback with the result row data */ + if( shell_callback(pArg, nCol, azVals, azCols, aiTypes) ){ + rc = SQLITE_ABORT; + }else{ + rc = sqlite3_step(pStmt); + } + } + } while( SQLITE_ROW == rc ); + sqlite3_free(pData); } } } @@ -2768,17 +2794,15 @@ static int expertDotCommand( ** and callback data argument. */ static int shell_exec( - sqlite3 *db, /* An open database */ - const char *zSql, /* SQL to be evaluated */ - int (*xCallback)(void*,int,char**,char**,int*), /* Callback function */ - /* (not the same as sqlite3_exec) */ ShellState *pArg, /* Pointer to ShellState */ + const char *zSql, /* SQL to be evaluated */ char **pzErrMsg /* Error msg written here */ ){ sqlite3_stmt *pStmt = NULL; /* Statement to execute. */ int rc = SQLITE_OK; /* Return Code */ int rc2; const char *zLeftover; /* Tail of unprocessed SQL */ + sqlite3 *db = pArg->db; if( pzErrMsg ){ *pzErrMsg = NULL; @@ -2849,13 +2873,18 @@ static int shell_exec( if( rc==SQLITE_OK ){ pArg->cMode = MODE_Explain; explain_data_prepare(pArg, pExplain); - exec_prepared_stmt(pArg, pExplain, xCallback); + exec_prepared_stmt(pArg, pExplain); explain_data_delete(pArg); } sqlite3_finalize(pExplain); sqlite3_free(zEQP); } - sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0); + if( pArg->autoEQP>=AUTOEQP_trigger && triggerEQP==0 ){ + sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0); + /* Reprepare pStmt before reactiving trace modes */ + sqlite3_finalize(pStmt); + sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); + } restore_debug_trace_modes(); } @@ -2875,7 +2904,7 @@ static int shell_exec( } } - exec_prepared_stmt(pArg, pStmt, xCallback); + exec_prepared_stmt(pArg, pStmt); explain_data_delete(pArg); /* print usage stats if stats on */ @@ -3138,11 +3167,11 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ savedMode = p->mode; p->zDestTable = sTable.z; p->mode = p->cMode = MODE_Insert; - rc = shell_exec(p->db, sSelect.z, shell_callback, p, 0); + rc = shell_exec(p, sSelect.z, 0); if( (rc&0xff)==SQLITE_CORRUPT ){ raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n"); toggleSelectOrder(p->db); - shell_exec(p->db, sSelect.z, shell_callback, p, 0); + shell_exec(p, sSelect.z, 0); toggleSelectOrder(p->db); } p->zDestTable = savedDestTable; @@ -3413,13 +3442,21 @@ static int session_filter(void *pCtx, const char *zTab){ /* ** Try to deduce the type of file for zName based on its content. Return ** one of the SHELL_OPEN_* constants. +** +** If the file does not exist or is empty but its name looks like a ZIP +** archive and the dfltZip flag is true, then assume it is a ZIP archive. +** Otherwise, assume an ordinary database regardless of the filename if +** the type cannot be determined from content. */ -static int deduceDatabaseType(const char *zName){ +static int deduceDatabaseType(const char *zName, int dfltZip){ FILE *f = fopen(zName, "rb"); size_t n; int rc = SHELL_OPEN_UNSPEC; char zBuf[100]; - if( f==0 ) return SHELL_OPEN_NORMAL; + if( f==0 ){ + if( dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ) return SHELL_OPEN_ZIPFILE; + return SHELL_OPEN_NORMAL; + } fseek(f, -25, SEEK_END); n = fread(zBuf, 25, 1, f); if( n==1 && memcmp(zBuf, "Start-Of-SQLite3-", 17)==0 ){ @@ -3430,6 +3467,8 @@ static int deduceDatabaseType(const char *zName){ if( n==1 && zBuf[0]==0x50 && zBuf[1]==0x4b && zBuf[2]==0x05 && zBuf[3]==0x06 ){ rc = SHELL_OPEN_ZIPFILE; + }else if( n==0 && dfltZip && sqlite3_strlike("%.zip",zName,0)==0 ){ + return SHELL_OPEN_ZIPFILE; } } fclose(f); @@ -3444,7 +3483,7 @@ static void open_db(ShellState *p, int keepAlive){ if( p->db==0 ){ sqlite3_initialize(); if( p->openMode==SHELL_OPEN_UNSPEC && access(p->zDbFilename,0)==0 ){ - p->openMode = (u8)deduceDatabaseType(p->zDbFilename); + p->openMode = (u8)deduceDatabaseType(p->zDbFilename, 0); } switch( p->openMode ){ case SHELL_OPEN_APPENDVFS: { @@ -5239,8 +5278,8 @@ static int arCreateOrUpdateCommand( " data BLOB -- compressed content\n" ")"; const char *zDrop = "DROP TABLE IF EXISTS sqlar"; - const char *zInsertFmt = - "REPLACE INTO sqlar(name,mode,mtime,sz,data)\n" + const char *zInsertFmt[2] = { + "REPLACE INTO %s(name,mode,mtime,sz,data)\n" " SELECT\n" " %s,\n" " mode,\n" @@ -5249,30 +5288,70 @@ static int arCreateOrUpdateCommand( " WHEN '-' THEN length(data)\n" " WHEN 'd' THEN 0\n" " ELSE -1 END,\n" - " CASE WHEN lsmode(mode) LIKE 'd%%' THEN NULL else data END\n" + " sqlar_compress(data)\n" " FROM fsdir(%Q,%Q)\n" - " WHERE lsmode(mode) NOT LIKE '?%%';"; + " WHERE lsmode(mode) NOT LIKE '?%%';", + "REPLACE INTO %s(name,mode,mtime,data)\n" + " SELECT\n" + " %s,\n" + " mode,\n" + " mtime,\n" + " data\n" + " FROM fsdir(%Q,%Q)\n" + " WHERE lsmode(mode) NOT LIKE '?%%';" + }; int i; /* For iterating through azFile[] */ int rc; /* Return code */ + const char *zTab = 0; /* SQL table into which to insert */ + char *zSql; + char zTemp[50]; + arExecSql(pAr, "PRAGMA page_size=512"); rc = arExecSql(pAr, "SAVEPOINT ar;"); if( rc!=SQLITE_OK ) return rc; - if( bUpdate==0 ){ - rc = arExecSql(pAr, zDrop); - if( rc!=SQLITE_OK ) return rc; + zTemp[0] = 0; + if( pAr->bZip ){ + /* Initialize the zipfile virtual table, if necessary */ + if( pAr->zFile ){ + sqlite3_uint64 r; + sqlite3_randomness(sizeof(r),&r); + sqlite3_snprintf(sizeof(zTemp),zTemp,"zip%016llx",r); + zTab = zTemp; + zSql = sqlite3_mprintf( + "CREATE VIRTUAL TABLE temp.%s USING zipfile(%Q)", + zTab, pAr->zFile + ); + rc = arExecSql(pAr, zSql); + sqlite3_free(zSql); + }else{ + zTab = "zip"; + } + }else{ + /* Initialize the table for an SQLAR */ + zTab = "sqlar"; + if( bUpdate==0 ){ + rc = arExecSql(pAr, zDrop); + if( rc!=SQLITE_OK ) goto end_ar_transaction; + } + rc = arExecSql(pAr, zCreate); } - rc = arExecSql(pAr, zCreate); for(i=0; inArg && rc==SQLITE_OK; i++){ - char *zSql = sqlite3_mprintf(zInsertFmt, + char *zSql = sqlite3_mprintf(zInsertFmt[pAr->bZip], zTab, pAr->bVerbose ? "shell_putsnl(name)" : "name", pAr->azArg[i], pAr->zDir); rc = arExecSql(pAr, zSql); sqlite3_free(zSql); } +end_ar_transaction: if( rc!=SQLITE_OK ){ arExecSql(pAr, "ROLLBACK TO ar; RELEASE ar;"); }else{ rc = arExecSql(pAr, "RELEASE ar;"); + if( pAr->bZip && pAr->zFile ){ + zSql = sqlite3_mprintf("DROP TABLE %s", zTemp); + arExecSql(pAr, zSql); + sqlite3_free(zSql); + } } return rc; } @@ -5294,20 +5373,17 @@ static int arDotCommand( cmd.p = pState; cmd.db = pState->db; if( cmd.zFile ){ - eDbType = deduceDatabaseType(cmd.zFile); + eDbType = deduceDatabaseType(cmd.zFile, 1); }else{ eDbType = pState->openMode; } if( eDbType==SHELL_OPEN_ZIPFILE ){ - if( cmd.zFile==0 ){ - cmd.zSrcTable = sqlite3_mprintf("zip"); - }else{ - cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile); - } - if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){ - utf8_printf(stderr, "zip archives are read-only\n"); - rc = SQLITE_ERROR; - goto end_ar_command; + if( cmd.eCmd==AR_CMD_EXTRACT || cmd.eCmd==AR_CMD_LIST ){ + if( cmd.zFile==0 ){ + cmd.zSrcTable = sqlite3_mprintf("zip"); + }else{ + cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile); + } } cmd.bZip = 1; }else if( cmd.zFile ){ @@ -5332,14 +5408,12 @@ static int arDotCommand( goto end_ar_command; } sqlite3_fileio_init(cmd.db, 0, 0); -#ifdef SQLITE_HAVE_ZLIB sqlite3_sqlar_init(cmd.db, 0, 0); -#endif sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p, shellPutsFunc, 0, 0); } - if( cmd.zSrcTable==0 ){ + if( cmd.zSrcTable==0 && cmd.bZip==0 ){ if( cmd.eCmd!=AR_CMD_CREATE && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0) ){ @@ -5819,14 +5893,11 @@ static int do_meta_command(char *zLine, ShellState *p){ callback, &data, &zErrMsg); data.cMode = data.mode = MODE_Insert; data.zDestTable = "sqlite_stat1"; - shell_exec(p->db, "SELECT * FROM sqlite_stat1", - shell_callback, &data,&zErrMsg); + shell_exec(p, "SELECT * FROM sqlite_stat1", &zErrMsg); data.zDestTable = "sqlite_stat3"; - shell_exec(p->db, "SELECT * FROM sqlite_stat3", - shell_callback, &data,&zErrMsg); + shell_exec(p, "SELECT * FROM sqlite_stat3", &zErrMsg); data.zDestTable = "sqlite_stat4"; - shell_exec(p->db, "SELECT * FROM sqlite_stat4", - shell_callback, &data, &zErrMsg); + shell_exec(p, "SELECT * FROM sqlite_stat4", &zErrMsg); raw_printf(p->out, "ANALYZE sqlite_master;\n"); } }else @@ -6307,7 +6378,7 @@ static int do_meta_command(char *zLine, ShellState *p){ const char *z = azArg[iName]; if( optionMatch(z,"new") ){ newFlag = 1; -#ifdef SQLITE_HAVE_ZIP +#ifdef SQLITE_HAVE_ZLIB }else if( optionMatch(z, "zip") ){ p->openMode = SHELL_OPEN_ZIPFILE; #endif @@ -7096,7 +7167,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( bDebug ){ utf8_printf(p->out, "%s\n", zSql); }else{ - shell_exec(p->db, zSql, shell_callback, p, 0); + shell_exec(p, zSql, 0); } sqlite3_free(zSql); }else @@ -7735,7 +7806,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ open_db(p, 0); if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql); BEGIN_TIMER; - rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg); + rc = shell_exec(p, zSql, &zErrMsg); END_TIMER; if( rc || zErrMsg ){ char zPrefix[100]; @@ -7967,6 +8038,10 @@ static void process_sqliterc( ** Show available command line options */ static const char zOptions[] = +#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) + " -A ARGS... run \".archive ARGS\" and exit\n" +#endif + " -append append the database to the end of the file\n" " -ascii set output mode to 'ascii'\n" " -bail stop after hitting an error\n" " -batch force batch I/O\n" @@ -8001,6 +8076,9 @@ static const char zOptions[] = #ifdef SQLITE_ENABLE_VFSTRACE " -vfstrace enable tracing of all VFS calls\n" #endif +#ifdef SQLITE_HAVE_ZLIB + " -zip open the file as a ZIP Archive\n" +#endif ; static void usage(int showDetail){ utf8_printf(stderr, @@ -8255,7 +8333,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ utf8_printf(stderr, "no such VFS: \"%s\"\n", argv[i]); exit(1); } -#ifdef SQLITE_HAVE_ZIP +#ifdef SQLITE_HAVE_ZLIB }else if( strcmp(z,"-zip")==0 ){ data.openMode = SHELL_OPEN_ZIPFILE; #endif @@ -8263,6 +8341,12 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ data.openMode = SHELL_OPEN_APPENDVFS; }else if( strcmp(z,"-readonly")==0 ){ data.openMode = SHELL_OPEN_READONLY; +#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) + }else if( strncmp(z, "-A",2)==0 ){ + /* All remaining command-line arguments are passed to the ".archive" + ** command, so ignore them */ + break; +#endif } } if( data.zDbFilename==0 ){ @@ -8316,7 +8400,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( strcmp(z,"-csv")==0 ){ data.mode = MODE_Csv; memcpy(data.colSeparator,",",2); -#ifdef SQLITE_HAVE_ZIP +#ifdef SQLITE_HAVE_ZLIB }else if( strcmp(z,"-zip")==0 ){ data.openMode = SHELL_OPEN_ZIPFILE; #endif @@ -8399,7 +8483,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( rc && bail_on_error ) return rc==2 ? 0 : rc; }else{ open_db(&data, 0); - rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg); + rc = shell_exec(&data, z, &zErrMsg); if( zErrMsg!=0 ){ utf8_printf(stderr,"Error: %s\n", zErrMsg); if( bail_on_error ) return rc!=0 ? rc : 1; @@ -8408,6 +8492,23 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( bail_on_error ) return rc; } } +#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) + }else if( strncmp(z, "-A", 2)==0 ){ + if( nCmd>0 ){ + utf8_printf(stderr, "Error: cannot mix regular SQL or dot-commands" + " with \"%s\"\n", z); + return 1; + } + open_db(&data, 0); + if( z[2] ){ + argv[i] = &z[2]; + arDotCommand(&data, argv+(i-1), argc-(i-1)); + }else{ + arDotCommand(&data, argv+i, argc-i); + } + readStdin = 0; + break; +#endif }else{ utf8_printf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); raw_printf(stderr,"Use -help for a list of options.\n"); @@ -8427,7 +8528,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( rc ) return rc==2 ? 0 : rc; }else{ open_db(&data, 0); - rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg); + rc = shell_exec(&data, azCmd[i], &zErrMsg); if( zErrMsg!=0 ){ utf8_printf(stderr,"Error: %s\n", zErrMsg); return rc!=0 ? rc : 1; diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 13e9a59cf6..a8657979e3 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2054,11 +2054,13 @@ struct sqlite3_mem_methods { ** connections at all to the database. If so, it performs a checkpoint ** operation before closing the connection. This option may be used to ** override this behaviour. The first parameter passed to this operation -** is an integer - non-zero to disable checkpoints-on-close, or zero (the -** default) to enable them. The second parameter is a pointer to an integer +** is an integer - positive to disable checkpoints-on-close, or zero (the +** default) to enable them, and negative to leave the setting unchanged. +** The second parameter is a pointer to an integer ** into which is written 0 or 1 to indicate whether checkpoints-on-close ** have been disabled - 0 if they are not disabled, 1 if they are. ** +** **
SQLITE_DBCONFIG_ENABLE_QPSG
**
^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates ** the [query planner stability guarantee] (QPSG). When the QPSG is active, @@ -2068,13 +2070,20 @@ struct sqlite3_mem_methods { ** slower. But the QPSG has the advantage of more predictable behavior. With ** the QPSG active, SQLite will always use the same query plan in the field as ** was used during testing in the lab. +** The first argument to this setting is an integer which is 0 to disable +** the QPSG, positive to enable QPSG, or negative to leave the setting +** unchanged. The second parameter is a pointer to an integer into which +** is written 0 or 1 to indicate whether the QPSG is disabled or enabled +** following this call. **
+** **
SQLITE_DBCONFIG_TRIGGER_EQP
**
By default, the output of EXPLAIN QUERY PLAN commands does not ** include output for any operations performed by trigger programs. This ** option is used to set or clear (the default) a flag that governs this ** behavior. The first parameter passed to this operation is an integer - -** non-zero to enable output for trigger programs, or zero to disable it. +** positive to enable output for trigger programs, or zero to disable it, +** or negative to leave the setting unchanged. ** The second parameter is a pointer to an integer into which is written ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if ** it is not disabled, 1 if it is. @@ -7230,6 +7239,15 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. **
** +** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(
SQLITE_DBSTATUS_CACHE_SPILL
+**
This parameter returns the number of dirty cache entries that have +** been written to disk in the middle of a transaction due to the page +** cache overflowing. Transactions are more efficient if they are written +** to disk all at once. When pages spill mid-transaction, that introduces +** additional overhead. This parameter can be used help identify +** inefficiencies that can be resolve by increasing the cache size. +**
+** ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(
SQLITE_DBSTATUS_DEFERRED_FKS
**
This parameter returns zero for the current value if and only if ** all foreign key constraints (deferred or immediate) have been @@ -7249,7 +7267,8 @@ int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); #define SQLITE_DBSTATUS_CACHE_WRITE 9 #define SQLITE_DBSTATUS_DEFERRED_FKS 10 #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 -#define SQLITE_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */ +#define SQLITE_DBSTATUS_CACHE_SPILL 12 +#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */ /* @@ -8754,6 +8773,128 @@ SQLITE_EXPERIMENTAL int sqlite3_wal_info( unsigned int *pnPrior, unsigned int *pnFrame ); +/* +** CAPI3REF: Serialize a database +** +** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory +** that is a serialization of the S database on [database connection] D. +** If P is not a NULL pointer, then the size of the database in bytes +** is written into *P. +** +** For an ordinary on-disk database file, the serialization is just a +** copy of the disk file. For an in-memory database or a "TEMP" database, +** the serialization is the same sequence of bytes which would be written +** to disk if that database where backed up to disk. +** +** The usual case is that sqlite3_serialize() copies the serialization of +** the database into memory obtained from [sqlite3_malloc64()] and returns +** a pointer to that memory. The caller is responsible for freeing the +** returned value to avoid a memory leak. However, if the F argument +** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations +** are made, and the sqlite3_serialize() function will return a pointer +** to the contiguous memory representation of the database that SQLite +** is currently using for that database, or NULL if the no such contiguous +** memory representation of the database exists. A contiguous memory +** representation of the database will usually only exist if there has +** been a prior call to [sqlite3_deserialize(D,S,...)] with the same +** values of D and S. +** The size of the database is written into *P even if the +** SQLITE_SERIALIZE_NOCOPY bit is set but no contigious copy +** of the database exists. +** +** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the +** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory +** allocation error occurs. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_serialize +** +** Zero or more of the following constants can be OR-ed together for +** the F argument to [sqlite3_serialize(D,S,P,F)]. +** +** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return +** a pointer to contiguous in-memory database that it is currently using, +** without making a copy of the database. If SQLite is not currently using +** a contiguous in-memory database, then this option causes +** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be +** using a contiguous in-memory database if it has been initialized by a +** prior call to [sqlite3_deserialize()]. +*/ +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ + +/* +** CAPI3REF: Deserialize a database +** +** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the +** [database connection] D to disconnection from database S and then +** reopen S as an in-memory database based on the serialization contained +** in P. The serialized database P is N bytes in size. M is the size of +** the buffer P, which might be larger than N. If M is larger than N, and +** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is +** permitted to add content to the in-memory database as long as the total +** size does not exceed M bytes. +** +** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will +** invoke sqlite3_free() on the serialization buffer when the database +** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then +** SQLite will try to increase the buffer size using sqlite3_realloc64() +** if writes on the database cause it to grow larger than M bytes. +** +** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the +** database is currently in a read transaction or is involved in a backup +** operation. +** +** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the +** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then +** [sqlite3_free()] is invoked on argument P prior to returning. +** +** This interface is only available if SQLite is compiled with the +** [SQLITE_ENABLE_DESERIALIZE] option. +*/ +int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ +); + +/* +** CAPI3REF: Flags for sqlite3_deserialize() +** +** The following are allowed values for 6th argument (the F argument) to +** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. +** +** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization +** in the P argument is held in memory obtained from [sqlite3_malloc64()] +** and that SQLite should take ownership of this memory and automatically +** free it when it has finished using it. Without this flag, the caller +** is resposible for freeing any dynamically allocated memory. +** +** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to +** grow the size of the database using calls to [sqlite3_realloc64()]. This +** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. +** Without this flag, the deserialized database cannot increase in size beyond +** the number of bytes specified by the M parameter. +** +** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database +** should be treated as read-only. +*/ +#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ +#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ +#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ + /* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 43883d3979..9ae48c840b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1366,8 +1366,9 @@ struct sqlite3 { int newTnum; /* Rootpage of table being initialized */ u8 iDb; /* Which db file is being initialized */ u8 busy; /* TRUE if currently initializing */ - u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ - u8 imposterTable; /* Building an imposter table */ + unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ + unsigned imposterTable : 1; /* Building an imposter table */ + unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ } init; int nVdbeActive; /* Number of VDBEs currently running */ int nVdbeRead; /* Number of active VDBEs that read or write */ @@ -1532,6 +1533,7 @@ struct sqlite3 { #define SQLITE_CursorHints 0x0400 /* Add OP_CursorHint opcodes */ #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ /* TH3 expects the Stat34 ^^^^^^ value to be 0x0800. Don't change it */ +#define SQLITE_PushDown 0x1000 /* The push-down optimization */ #define SQLITE_AllOpts 0xffff /* All optimizations */ /* @@ -2993,7 +2995,6 @@ struct Parse { int nMaxArg; /* Max args passed to user function by sub-program */ #if SELECTTRACE_ENABLED int nSelect; /* Number of SELECT statements seen */ - int nSelectIndent; /* How far to indent SELECTTRACE() output */ #endif #ifndef SQLITE_OMIT_SHARED_CACHE int nTableLock; /* Number of locks in aTableLock */ @@ -4024,6 +4025,10 @@ int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); const char *sqlite3ErrName(int); #endif +#ifdef SQLITE_ENABLE_DESERIALIZE +int sqlite3MemdbInit(void); +#endif + const char *sqlite3ErrStr(int); int sqlite3ReadSchema(Parse *pParse); CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); diff --git a/src/status.c b/src/status.c index 6e5b0e573b..a5a39f4c18 100644 --- a/src/status.c +++ b/src/status.c @@ -337,6 +337,9 @@ int sqlite3_db_status( ** pagers the database handle is connected to. *pHighwater is always set ** to zero. */ + case SQLITE_DBSTATUS_CACHE_SPILL: + op = SQLITE_DBSTATUS_CACHE_WRITE+1; + /* Fall through into the next case */ case SQLITE_DBSTATUS_CACHE_HIT: case SQLITE_DBSTATUS_CACHE_MISS: case SQLITE_DBSTATUS_CACHE_WRITE:{ diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 252b246e6e..e5984ec804 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -648,7 +648,7 @@ static int DbTraceV2Handler( } case SQLITE_TRACE_PROFILE: { sqlite3_stmt *pStmt = (sqlite3_stmt *)pd; - sqlite3_int64 ns = (sqlite3_int64)xd; + sqlite3_int64 ns = *(sqlite3_int64*)xd; pCmd = Tcl_NewStringObj(pDb->zTraceV2, -1); Tcl_IncrRefCount(pCmd); @@ -1848,35 +1848,35 @@ static int SQLITE_TCLAPI DbObjCmd( int choice; int rc = TCL_OK; static const char *DB_strs[] = { - "authorizer", "backup", "busy", - "cache", "changes", "close", - "collate", "collation_needed", "commit_hook", - "complete", "copy", "enable_load_extension", - "errorcode", "eval", "exists", - "function", "incrblob", "interrupt", - "last_insert_rowid", "nullvalue", "onecolumn", - "preupdate", "profile", "progress", - "rekey", "restore", "rollback_hook", - "status", "timeout", "total_changes", - "trace", "trace_v2", "transaction", - "unlock_notify", "update_hook", "version", - "wal_hook", - 0 + "authorizer", "backup", "busy", + "cache", "changes", "close", + "collate", "collation_needed", "commit_hook", + "complete", "copy", "deserialize", + "enable_load_extension", "errorcode", "eval", + "exists", "function", "incrblob", + "interrupt", "last_insert_rowid", "nullvalue", + "onecolumn", "preupdate", "profile", + "progress", "rekey", "restore", + "rollback_hook", "serialize", "status", + "timeout", "total_changes", "trace", + "trace_v2", "transaction", "unlock_notify", + "update_hook", "version", "wal_hook", + 0 }; enum DB_enum { - DB_AUTHORIZER, DB_BACKUP, DB_BUSY, - DB_CACHE, DB_CHANGES, DB_CLOSE, - DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK, - DB_COMPLETE, DB_COPY, DB_ENABLE_LOAD_EXTENSION, - DB_ERRORCODE, DB_EVAL, DB_EXISTS, - DB_FUNCTION, DB_INCRBLOB, DB_INTERRUPT, - DB_LAST_INSERT_ROWID, DB_NULLVALUE, DB_ONECOLUMN, - DB_PREUPDATE, DB_PROFILE, DB_PROGRESS, - DB_REKEY, DB_RESTORE, DB_ROLLBACK_HOOK, - DB_STATUS, DB_TIMEOUT, DB_TOTAL_CHANGES, - DB_TRACE, DB_TRACE_V2, DB_TRANSACTION, - DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK, DB_VERSION, - DB_WAL_HOOK, + DB_AUTHORIZER, DB_BACKUP, DB_BUSY, + DB_CACHE, DB_CHANGES, DB_CLOSE, + DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK, + DB_COMPLETE, DB_COPY, DB_DESERIALIZE, + DB_ENABLE_LOAD_EXTENSION, DB_ERRORCODE, DB_EVAL, + DB_EXISTS, DB_FUNCTION, DB_INCRBLOB, + DB_INTERRUPT, DB_LAST_INSERT_ROWID, DB_NULLVALUE, + DB_ONECOLUMN, DB_PREUPDATE, DB_PROFILE, + DB_PROGRESS, DB_REKEY, DB_RESTORE, + DB_ROLLBACK_HOOK, DB_SERIALIZE, DB_STATUS, + DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE, + DB_TRACE_V2, DB_TRANSACTION, DB_UNLOCK_NOTIFY, + DB_UPDATE_HOOK, DB_VERSION, DB_WAL_HOOK }; /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ @@ -2414,6 +2414,53 @@ static int SQLITE_TCLAPI DbObjCmd( break; } + /* + ** $db deserialize ?DATABASE? VALUE + ** + ** Reopen DATABASE (default "main") using the content in $VALUE + */ + case DB_DESERIALIZE: { +#ifndef SQLITE_ENABLE_DESERIALIZE + Tcl_AppendResult(interp, "MEMDB not available in this build", + (char*)0); + rc = TCL_ERROR; +#else + const char *zSchema; + Tcl_Obj *pValue; + unsigned char *pBA; + unsigned char *pData; + int len, xrc; + + if( objc==3 ){ + zSchema = 0; + pValue = objv[2]; + }else if( objc==4 ){ + zSchema = Tcl_GetString(objv[2]); + pValue = objv[3]; + }else{ + Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? VALUE"); + rc = TCL_ERROR; + break; + } + pBA = Tcl_GetByteArrayFromObj(pValue, &len); + pData = sqlite3_malloc64( len ); + if( pData==0 && len>0 ){ + Tcl_AppendResult(interp, "out of memory", (char*)0); + rc = TCL_ERROR; + }else{ + if( len>0 ) memcpy(pData, pBA, len); + xrc = sqlite3_deserialize(pDb->db, zSchema, pData, len, len, + SQLITE_DESERIALIZE_FREEONCLOSE | + SQLITE_DESERIALIZE_RESIZEABLE); + if( xrc ){ + Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0); + rc = TCL_ERROR; + } + } +#endif + break; + } + /* ** $db enable_load_extension BOOLEAN ** @@ -2889,6 +2936,39 @@ static int SQLITE_TCLAPI DbObjCmd( break; } + /* + ** $db serialize ?DATABASE? + ** + ** Return a serialization of a database. + */ + case DB_SERIALIZE: { +#ifndef SQLITE_ENABLE_DESERIALIZE + Tcl_AppendResult(interp, "MEMDB not available in this build", + (char*)0); + rc = TCL_ERROR; +#else + const char *zSchema = objc>=3 ? Tcl_GetString(objv[2]) : "main"; + sqlite3_int64 sz = 0; + unsigned char *pData; + if( objc!=2 && objc!=3 ){ + Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE?"); + rc = TCL_ERROR; + }else{ + int needFree; + pData = sqlite3_serialize(pDb->db, zSchema, &sz, SQLITE_SERIALIZE_NOCOPY); + if( pData ){ + needFree = 0; + }else{ + pData = sqlite3_serialize(pDb->db, zSchema, &sz, 0); + needFree = 1; + } + Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pData,sz)); + if( needFree ) sqlite3_free(pData); + } +#endif + break; + } + /* ** $db status (step|sort|autoindex|vmstep) ** @@ -3349,6 +3429,24 @@ static int SQLITE_TCLAPI DbObjCmdAdaptor( } #endif /* SQLITE_TCL_NRE */ +/* +** Issue the usage message when the "sqlite3" command arguments are +** incorrect. +*/ +static int sqliteCmdUsage( + Tcl_Interp *interp, + Tcl_Obj *const*objv +){ + Tcl_WrongNumArgs(interp, 1, objv, + "HANDLE ?FILENAME? ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?" + " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) + " ?-key CODECKEY?" +#endif + ); + return TCL_ERROR; +} + /* ** sqlite3 DBNAME FILENAME ?-vfs VFSNAME? ?-key KEY? ?-readonly BOOLEAN? ** ?-create BOOLEAN? ?-nomutex BOOLEAN? @@ -3374,7 +3472,7 @@ static int SQLITE_TCLAPI DbMain( const char *zArg; char *zErrMsg; int i; - const char *zFile; + const char *zFile = 0; const char *zVfs = 0; int flags; Tcl_DString translatedFilename; @@ -3385,7 +3483,7 @@ static int SQLITE_TCLAPI DbMain( int rc; /* In normal use, each TCL interpreter runs in a single thread. So - ** by default, we can turn of mutexing on SQLite database connections. + ** by default, we can turn off mutexing on SQLite database connections. ** However, for testing purposes it is useful to have mutexes turned ** on. So, by default, mutexes default off. But if compiled with ** SQLITE_TCL_DEFAULT_FULLMUTEX then mutexes default on. @@ -3414,18 +3512,26 @@ static int SQLITE_TCLAPI DbMain( #endif return TCL_OK; } + if( zArg[0]=='-' ) return sqliteCmdUsage(interp, objv); } - for(i=3; i+1db, flags, zVfs); Tcl_DStringFree(&translatedFilename); diff --git a/src/test_config.c b/src/test_config.c index c9f6e6941e..17257676f5 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -148,6 +148,12 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "hiddencolumns", "0", TCL_GLOBAL_ONLY); #endif +#ifdef SQLITE_ENABLE_DESERIALIZE + Tcl_SetVar2(interp, "sqlite_options", "deserialize", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "deserialize", "0", TCL_GLOBAL_ONLY); +#endif + #ifdef SQLITE_ENABLE_MEMSYS3 Tcl_SetVar2(interp, "sqlite_options", "mem3", "1", TCL_GLOBAL_ONLY); #else diff --git a/src/test_malloc.c b/src/test_malloc.c index b13d9b2b2c..33bc3807ba 100644 --- a/src/test_malloc.c +++ b/src/test_malloc.c @@ -1383,6 +1383,7 @@ static int SQLITE_TCLAPI test_db_status( { "CACHE_WRITE", SQLITE_DBSTATUS_CACHE_WRITE }, { "DEFERRED_FKS", SQLITE_DBSTATUS_DEFERRED_FKS }, { "CACHE_USED_SHARED", SQLITE_DBSTATUS_CACHE_USED_SHARED }, + { "CACHE_SPILL", SQLITE_DBSTATUS_CACHE_SPILL }, }; Tcl_Obj *pResult; if( objc!=4 ){ diff --git a/src/treeview.c b/src/treeview.c index e33fe6e227..2e92c999ca 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -137,11 +137,21 @@ void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ sqlite3TreeViewPush(pView, 1); } do{ +#if SELECTTRACE_ENABLED + sqlite3TreeViewLine(pView, + "SELECT%s%s (%s/%p) selFlags=0x%x nSelectRow=%d", + ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), + ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), + p->zSelName, p, p->selFlags, + (int)p->nSelectRow + ); +#else sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d", ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags, (int)p->nSelectRow ); +#endif if( cnt++ ) sqlite3TreeViewPop(pView); if( p->pPrior ){ n = 1000; diff --git a/src/vdbe.c b/src/vdbe.c index cb12332df8..627f685b21 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4318,6 +4318,10 @@ case OP_NewRowid: { /* out2 */ pOut = out2Prerelease(p, pOp); assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; + if( !pC->isTable ){ + rc = SQLITE_CORRUPT_BKPT; + goto abort_due_to_error; + } assert( pC!=0 ); assert( pC->eCurType==CURTYPE_BTREE ); assert( pC->uc.pCursor!=0 ); diff --git a/src/vdbeapi.c b/src/vdbeapi.c index dd4a352003..2a6e1f8f0e 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1668,7 +1668,9 @@ int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ Vdbe *pVdbe = (Vdbe*)pStmt; u32 v; #ifdef SQLITE_ENABLE_API_ARMOR - if( !pStmt ){ + if( !pStmt + || (op!=SQLITE_STMTSTATUS_MEMUSED && (op<0||op>=ArraySize(pVdbe->aCounter))) + ){ (void)SQLITE_MISUSE_BKPT; return 0; } diff --git a/src/wal.c b/src/wal.c index 6f2911ab38..5c9a106e3b 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1668,6 +1668,7 @@ static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ if( rc!=SQLITE_OK ){ walIteratorFree(p); + p = 0; } *pp = p; return rc; diff --git a/test/crash8.test b/test/crash8.test index 7916e9b641..c07829979f 100644 --- a/test/crash8.test +++ b/test/crash8.test @@ -352,7 +352,11 @@ ifcapable pragma { # Since the following tests (crash8-5.*) rely upon being able # to copy a file while open, they will not work on Windows. # -if {$::tcl_platform(platform)=="unix"} { +# They also depend on being able to copy the journal file, which +# is not created on F2FS file-systems that support atomic +# write. So do not run these tests in that case either. +# +if {$::tcl_platform(platform)=="unix" && [atomic_batch_write test.db]==0 } { for {set i 1} {$i < 10} {incr i} { catch { db close } forcedelete test.db test.db-journal diff --git a/test/dbstatus.test b/test/dbstatus.test index 711d66ebb3..57b91cda1a 100644 --- a/test/dbstatus.test +++ b/test/dbstatus.test @@ -415,4 +415,43 @@ ifcapable shared_cache { } } +#------------------------------------------------------------------------- +# Test that passing an out-of-range value to sqlite3_stmt_status does +# not cause a crash. +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); +} + +do_test 5.1 { + set ::stmt [sqlite3_prepare db "SELECT * FROM t1" -1 dummy] + sqlite3_step $::stmt + sqlite3_step $::stmt + sqlite3_step $::stmt + sqlite3_reset $::stmt +} {SQLITE_OK} + +ifcapable api_armor { + do_test 5.2 { sqlite3_stmt_status $::stmt -1 0 } 0 +} +do_test 5.3 { sqlite3_stmt_status $::stmt 0 0 } 0 +do_test 5.4 { + expr [sqlite3_stmt_status $::stmt 99 0]>0 +} 1 +foreach {tn id res} { + 1 SQLITE_STMTSTATUS_MEMUSED 1 + 2 SQLITE_STMTSTATUS_FULLSCAN_STEP 1 + 3 SQLITE_STMTSTATUS_SORT 0 + 4 SQLITE_STMTSTATUS_AUTOINDEX 0 + 5 SQLITE_STMTSTATUS_VM_STEP 1 + 6 SQLITE_STMTSTATUS_REPREPARE 0 + 7 SQLITE_STMTSTATUS_RUN 1 +} { +if {$tn==2} breakpoint + do_test 5.5.$tn { expr [sqlite3_stmt_status $::stmt $id 0]>0 } $res +} + +sqlite3_finalize $::stmt finish_test diff --git a/test/dbstatus2.test b/test/dbstatus2.test index eff4b0207f..b75f40b062 100644 --- a/test/dbstatus2.test +++ b/test/dbstatus2.test @@ -37,6 +37,10 @@ proc db_write {db {reset 0}} { sqlite3_db_status $db CACHE_WRITE $reset } +proc db_spill {db {reset 0}} { + sqlite3_db_status $db CACHE_SPILL $reset +} + do_test 1.1 { db close sqlite3 db test.db @@ -98,5 +102,14 @@ do_test 2.7 { } {0 4 0} do_test 2.8 { db_write db 1 } {0 4 0} do_test 2.9 { db_write db 0 } {0 0 0} + +do_test 3.0 { db_spill db 1 } {0 0 0} +do_test 3.1 { db_spill db 0 } {0 0 0} +do_execsql_test 3.2 { + PRAGMA journal_mode=DELETE; + PRAGMA cache_size=3; + UPDATE t1 SET b=randomblob(1000); +} {delete} +do_test 3.2 { db_spill db 0 } {0 8 0} finish_test diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index fd72273f34..01efc82ee5 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -81,7 +81,13 @@ #ifdef SQLITE_OSS_FUZZ # include -# include +# if !defined(_MSC_VER) +# include +# endif +#endif + +#if defined(_MSC_VER) +typedef unsigned char uint8_t; #endif /* diff --git a/test/kvtest.c b/test/kvtest.c index 9193586a1e..eec7c25be1 100644 --- a/test/kvtest.c +++ b/test/kvtest.c @@ -132,7 +132,9 @@ static const char zHelp[] = # define access _access #endif -#include +#if !defined(_MSC_VER) +# include +#endif /* ** The following macros are used to cast pointers to integers and @@ -557,7 +559,7 @@ static int exportMain(int argc, char **argv){ iKey/10000, (iKey/100)%100, iKey%100); } out = fopen(zFN, "wb"); - nWrote = fwrite(pData, 1, nData, out); + nWrote = fwrite(pData, 1, (size_t)nData, out); fclose(out); printf("\r%s ", zTail); fflush(stdout); if( nWrote!=nData ){ diff --git a/test/memdb1.test b/test/memdb1.test new file mode 100644 index 0000000000..b52517fcf3 --- /dev/null +++ b/test/memdb1.test @@ -0,0 +1,162 @@ +# 2018-01-02 +# +# 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 implements regression tests for SQLite library. The +# focus of this file is the "memdb" VFS +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix memdb1 +do_not_use_codec + +ifcapable !deserialize { + finish_test + return +} + +# Create a MEMDB and populate it with some dummy data. +# Then extract the database into the $::db1 variable. +# Verify that the size of $::db1 is the same as the size of +# the database. +# +unset -nocomplain db1 +unset -nocomplain sz1 +unset -nocomplain pgsz +do_test 100 { + db eval { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + } + set ::pgsz [db one {PRAGMA page_size}] + set ::sz1 [expr {$::pgsz*[db one {PRAGMA page_count}]}] + set ::db1 [db serialize] + expr {[string length $::db1]==$::sz1} +} 1 +set fd [open db1.db wb] +puts -nonewline $fd $db1 +close $fd + +# Create a new MEMDB and initialize it to the content of $::db1 +# Verify that the content is the same. +# +db close +sqlite3 db +db deserialize $db1 +do_execsql_test 110 { + SELECT * FROM t1; +} {1 2} + +# What happens when we try to VACUUM a MEMDB database? +# +do_execsql_test 120 { + VACUUM; +} {} +do_execsql_test 130 { + CREATE TABLE t2(x, y); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t2(x, y) SELECT x, randomblob(1000) FROM c; + DROP TABLE t2; + PRAGMA page_count; +} {116} +do_execsql_test 140 { + VACUUM; + PRAGMA page_count; +} {2} + +# Build a largish on-disk database and serialize it. Verify that the +# serialization works. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 200 { + CREATE TABLE t3(x, y); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<400) + INSERT INTO t3(x, y) SELECT x, randomblob(1000) FROM c; + PRAGMA quick_check; +} {ok} +set fd [open test.db rb] +unset -nocomplain direct +set direct [read $fd] +close $fd +do_test 210 { + string length [db serialize] +} [string length $direct] +do_test 220 { + db eval {ATTACH ':memory:' AS aux1} + db deserialize aux1 $::direct + db eval { + SELECT x, y FROM main.t3 EXCEPT SELECT x, y FROM aux1.t3; + } +} {} +unset -nocomplain direct + +# Do the same with a :memory: database. +# +db close +sqlite3 db :memory: +do_execsql_test 300 { + CREATE TABLE t3(x, y); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<400) + INSERT INTO t3(x, y) SELECT x, randomblob(1000) FROM c; + PRAGMA quick_check; +} {ok} +do_test 310 { + db eval {ATTACH ':memory:' AS aux1} + db deserialize aux1 [db serialize main] + db eval { + SELECT x, y FROM main.t3 EXCEPT SELECT x, y FROM aux1.t3; + } +} {} + +# Deserialize an empty database +# +db close +sqlite3 db +db deserialize {} +do_execsql_test 400 { + PRAGMA integrity_check; +} {ok} +do_execsql_test 410 { + CREATE TABLE t4(a,b); + INSERT INTO t4 VALUES('hello','world!'); + PRAGMA integrity_check; + SELECT * FROM t4; +} {ok hello world!} + +# Deserialize something that is not a database. +# +db close +sqlite3 db +do_test 500 { + set rc [catch {db deserialize not-a-database} msg] + lappend rc $msg +} {0 {}} +do_catchsql_test 510 { + PRAGMA integrity_check; +} {1 {file is not a database}} + +# Abuse the serialize and deserialize commands. Make sure errors are caught. +# +do_test 600 { + set rc [catch {db deserialize} msg] + lappend rc $msg +} {1 {wrong # args: should be "db deserialize ?DATABASE? VALUE"}} +do_test 610 { + set rc [catch {db deserialize a b c} msg] + lappend rc $msg +} {1 {wrong # args: should be "db deserialize ?DATABASE? VALUE"}} +do_test 620 { + set rc [catch {db serialize a b} msg] + lappend rc $msg +} {1 {wrong # args: should be "db serialize ?DATABASE?"}} + +finish_test diff --git a/test/nockpt.test b/test/nockpt.test index 6da3313ad8..4cc61d11e1 100644 --- a/test/nockpt.test +++ b/test/nockpt.test @@ -110,6 +110,7 @@ forcedelete test.db test.db-wal test.db-shm sqlite3 db test.db sqlite3 db2 test.db do_execsql_test 2.1 { + PRAGMA auto_vacuum=OFF; PRAGMA journal_mode = wal; CREATE TABLE y1(a PRIMARY KEY, b UNIQUE, c); INSERT INTO y1 VALUES('a', 'b', 'c'); diff --git a/test/ossfuzz.c b/test/ossfuzz.c index fa6e9142fe..a8a637f2ac 100644 --- a/test/ossfuzz.c +++ b/test/ossfuzz.c @@ -3,11 +3,17 @@ ** (https://github.com/google/oss-fuzz) */ #include -#include +#if !defined(_MSC_VER) +# include +#endif #include #include #include "sqlite3.h" +#if defined(_MSC_VER) +typedef unsigned char uint8_t; +#endif + /* Global debugging settings. OSS-Fuzz will have all debugging turned ** off. But if LLVMFuzzerTestOneInput() is called interactively from ** the ossshell utility program, then these flags might be set. diff --git a/test/ossshell.c b/test/ossshell.c index 00cc3391c8..54849f97f6 100644 --- a/test/ossshell.c +++ b/test/ossshell.c @@ -6,12 +6,18 @@ ** command line and passes them one by one into ossfuzz.c. */ #include -#include +#if !defined(_MSC_VER) +# include +#endif #include #include #include #include "sqlite3.h" +#if defined(_MSC_VER) +typedef unsigned char uint8_t; +#endif + /* ** The entry point in ossfuzz.c that this routine will be calling */ diff --git a/test/sessionfuzz-data1.db b/test/sessionfuzz-data1.db new file mode 100644 index 0000000000..df10e10bcd Binary files /dev/null and b/test/sessionfuzz-data1.db differ diff --git a/test/sessionfuzz.c b/test/sessionfuzz.c new file mode 100644 index 0000000000..7f2de51092 --- /dev/null +++ b/test/sessionfuzz.c @@ -0,0 +1,1018 @@ +/* +** 2018-03-01 +** +** 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 implements a program used for fuzz-testing the session +** module. +** +** Usage: +** +** sessionfuzz setup -- Generate starter test cases +** sessionfuzz run FILE ... -- Run a test fuzz on FILE +** sesssiofuzz run SQLAR ... -- Run all test cases in the SQL Archive +** +** Compiling: +** +** (1) Have a version of SQLite that supports SQLITE_ENABLE_MEMDB +** in the local directory. +** (2) Run: +** +** gcc -Wall -O3 -o sessionfuzz sessionfuzz.c -lz +** +** Use with AFL (American Fuzzy Lop - http://lcamtuf.coredump.cx/afl/) +** +** (1) ./afl-gcc -O3 -o sessionfuzz sessionfuzz.c -lz +** (2) mkdir session-init session-run session-cases +** (3) cd session-init; ../sessionfuzz setup; cd .. +** (4) ./afl -i session-init -o session-run -- ./sessionfuzz run @@ +** ... let the previous step run for a while. Weeks, maybe. +** (5) ./afl-cmin -i session-run -o session-cases +** +** The afl-cmin command on step (5) writes a minimal set of test cases +** for coverage into the session-cases directory. Gather the cases written +** there into an SQL Archive using a command like this: +** +** sqlite3 session-cases.db -Ac session-cases +** +** Then repeat the test using: +** +** ./sessionfuzz run session-cases.db +*/ + +/* +** We will import the entire SQLite source file to make compiling easier +*/ +#ifdef SQLITE_DEBUG +#undef SQLITE_DEBUG +#endif + +#ifdef SQLITE_THREADSAFE +#undef SQLITE_THREADSAFE +#endif + +#define SQLITE_DEBUG 1 +#define SQLITE_THREADSAFE 0 +#define SQLITE_OMIT_LOAD_EXTENSION 0 +#define SQLITE_ENABLE_SESSION 1 +#define SQLITE_ENABLE_PREUPDATE_HOOK 1 +#define SQLITE_ENABLE_DESERIALIZE 1 +#include "sqlite3.c" + +/* Create a test database. This will be an in-memory database */ +static const char zInitSql[] = + "CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);\n" + "CREATE TABLE t2(e TEXT PRIMARY KEY NOT NULL,f,g);\n" + "CREATE TABLE t3(w REAL PRIMARY KEY NOT NULL,x,y);\n" + "CREATE TABLE t4(z PRIMARY KEY) WITHOUT ROWID;\n" +; + +/* Code to populate the database */ +static const char zFillSql[] = + "INSERT INTO t1(a,b,c,d) VALUES\n" + " (1,2,3,4),\n" + " (2,3.5,'four',x'556677'),\n" + " (3,null,'xyz',15),\n" + " (4,'bubba',0x80000000,0.0);\n" + "INSERT INTO t1 SELECT a+4,c,d,b FROM t1;\n" + "INSERT INTO t1 SELECT a+8,d,b,c FROM t1;\n" + "INSERT INTO t1 SELECT a+16,d,c,b FROM t1;\n" + "INSERT INTO t1 SELECT a+32,b,d,c FROM t1;\n" + "INSERT INTO t2 SELECT printf('x%dy',a),b,c FROM t1;\n" + "INSERT INTO t3 SELECT a*1.1,b,c FROM t1;\n" + "INSERT INTO t4 SELECT a||','||quote(b) FROM t1;\n" +; + +/* A database file created by running the two scripts above */ +static const unsigned char aDbBytes[] = { + 83, 81, 76,105,116,101, 32,102,111,114,109, 97,116, 32, 51, 0, 2, 0, 1, + 1, 0, 64, 32, 32, 0, 0, 0, 13, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 13, 0, 46, 32,152, 13, 1,186, 0, 6, 0,176, 0, 1,194, 1, 84, 1,150, + 0,238, 1, 48, 0,176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 60, 6, 6, 23, 17, 17, 1,101,116, 97, 98,108,101,116, + 52,116, 52, 7, 67, 82, 69, 65, 84, 69, 32, 84, 65, 66, 76, 69, 32,116, 52, + 40,122, 32, 80, 82, 73, 77, 65, 82, 89, 32, 75, 69, 89, 41, 32, 87, 73, 84, + 72, 79, 85, 84, 32, 82, 79, 87, 73, 68, 64, 4, 6, 23, 17, 17, 1,109,116, + 97, 98,108,101,116, 51,116, 51, 5, 67, 82, 69, 65, 84, 69, 32, 84, 65, 66, + 76, 69, 32,116, 51, 40,119, 32, 82, 69, 65, 76, 32, 80, 82, 73, 77, 65, 82, + 89, 32, 75, 69, 89, 32, 78, 79, 84, 32, 78, 85, 76, 76, 44,120, 44,121, 41, + 34, 5, 5, 23, 55, 17, 1,105,110,100,101,120,115,113,108,105,116,101, 95, + 97,117,116,111,105,110,100,101,120, 95,116, 51, 95, 49,116, 51, 6, 64, 2, + 6, 23, 17, 17, 1,109,116, 97, 98,108,101,116, 50,116, 50, 3, 67, 82, 69, + 65, 84, 69, 32, 84, 65, 66, 76, 69, 32,116, 50, 40,101, 32, 84, 69, 88, 84, + 32, 80, 82, 73, 77, 65, 82, 89, 32, 75, 69, 89, 32, 78, 79, 84, 32, 78, 85, + 76, 76, 44,102, 44,103, 41, 34, 3, 5, 23, 55, 17, 1,105,110,100,101,120, + 115,113,108,105,116,101, 95, 97,117,116,111,105,110,100,101,120, 95,116, 50, + 95, 49,116, 50, 4, 0, 0, 0, 8, 0, 0, 0, 0, 60, 1, 6, 23, 17, 17, + 1,101,116, 97, 98,108,101,116, 49,116, 49, 2, 67, 82, 69, 65, 84, 69, 32, + 84, 65, 66, 76, 69, 32,116, 49, 40, 97, 32, 73, 78, 84, 69, 71, 69, 82, 32, + 80, 82, 73, 77, 65, 82, 89, 32, 75, 69, 89, 44, 98, 44, 99, 44,100, 41, 5, + 0, 0, 0, 2, 1,246, 0, 0, 0, 0, 10, 1,251, 1,246, 1,177, 1,155, + 1,145, 1,119, 1,109, 1, 87, 1, 76, 1, 50, 1, 40, 1, 18, 1, 7, 0, + 237, 0,227, 0,205, 0,195, 0,169, 0,159, 0,137, 0,126, 0,100, 0, 90, + 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 20, 26, 5, 0, 21, 7, 18,102,111, + 117,114, 64, 12, 0, 0, 0, 0, 0, 0, 85,102,119, 8, 25, 5, 0, 1, 1, + 1, 3, 2, 4, 24, 24, 5, 0, 23, 7, 5, 98,117, 98, 98, 97, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 9, 23, 5, 0, 0, 1, 19, 15, + 120,121,122, 20, 22, 5, 0, 7, 18, 21, 64, 12, 0, 0, 0, 0, 0, 0, 85, + 102,119,102,111,117,114, 8, 21, 5, 0, 1, 1, 1, 2, 4, 3, 24, 20, 5, + 0, 7, 5, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 98, + 117, 98, 98, 97, 8, 19, 4, 0, 1, 19, 15,120,121,122, 20, 18, 5, 0, 18, + 21, 7, 85,102,119,102,111,117,114, 64, 12, 0, 0, 0, 0, 0, 0, 8, 17, + 5, 0, 1, 1, 1, 4, 3, 2, 24, 16, 5, 0, 23, 5, 7, 98,117, 98, 98, + 97, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 15, 5, 0, + 0, 19, 1,120,121,122, 15, 20, 14, 5, 0, 7, 21, 18, 64, 12, 0, 0, 0, + 0, 0, 0,102,111,117,114, 85,102,119, 8, 13, 5, 0, 1, 1, 1, 2, 3, + 4, 24, 12, 5, 0, 7, 23, 5, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, + 98, 97, 0, 0,128, 0, 0, 0, 9, 11, 5, 0, 1, 0, 19, 15,120,121,122, + 20, 10, 5, 0, 18, 7, 21, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0,102, + 111,117,114, 8, 9, 5, 0, 1, 1, 1, 4, 2, 3, 24, 8, 5, 0, 5, 7, + 23, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, + 97, 8, 7, 4, 0, 19, 1,120,121,122, 15, 20, 6, 5, 0, 21, 18, 7,102, + 111,117,114, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0, 8, 5, 5, 0, 1, + 1, 1, 3, 4, 2, 24, 4, 5, 0, 23, 5, 7, 98,117, 98, 98, 97, 0, 0, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 3, 5, 0, 0, 19, 1, + 120,121,122, 15, 20, 2, 5, 0, 7, 21, 18, 64, 12, 0, 0, 0, 0, 0, 0, + 102,111,117,114, 85,102,119, 0, 0, 0, 9, 52, 0, 0, 0, 8, 26, 5, 0, + 0, 0, 2, 1,246, 0, 0, 0, 0, 13, 1,251, 1,246, 1,181, 1,165, 1, + 152, 1,129, 1,118, 1, 97, 1, 87, 1, 64, 1, 52, 1, 30, 1, 17, 0,252, + 0,240, 0,223, 0,209, 0,185, 0,173, 0,152, 0,141, 0,118, 0,106, 0, + 84, 0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 27, 3, 21, 19,120, + 50, 55,121,120,121,122, 20, 26, 4, 21, 21, 7,120, 50, 54,121,102,111,117, + 114, 64, 12, 0, 0, 0, 0, 0, 0, 10, 25, 4, 21, 1, 1,120, 50, 53,121, + 3, 2, 21, 24, 4, 21, 23, 7,120, 50, 52,121, 98,117, 98, 98, 97, 0, 0, + 0, 0, 0, 0, 0, 0, 9, 23, 4, 21, 0, 1,120, 50, 51,121, 15, 19, 22, + 4, 21, 7, 18,120, 50, 50,121, 64, 12, 0, 0, 0, 0, 0, 0, 85,102,119, + 10, 21, 4, 21, 1, 1,120, 50, 49,121, 2, 4, 22, 20, 4, 21, 7, 5,120, + 50, 48,121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 12, 19, + 4, 21, 1, 19,120, 49, 57,121, 15,120,121,122, 15, 18, 4, 21, 18, 21,120, + 49, 56,121, 85,102,119,102,111,117,114, 10, 17, 4, 21, 1, 1,120, 49, 55, + 121, 4, 3, 19, 16, 4, 21, 23, 5,120, 49, 54,121, 98,117, 98, 98, 97, 0, + 0,128, 0, 0, 0, 11, 15, 4, 21, 0, 19,120, 49, 53,121,120,121,122, 20, + 14, 4, 21, 7, 21,120, 49, 52,121, 64, 12, 0, 0, 0, 0, 0, 0,102,111, + 117,114, 10, 13, 4, 21, 1, 1,120, 49, 51,121, 2, 3, 21, 12, 4, 21, 7, + 23,120, 49, 50,121, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 8, + 11, 3, 21, 1,120, 49, 49,121, 15, 19, 10, 4, 21, 18, 7,120, 49, 48,121, + 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0, 9, 9, 4, 19, 1, 1,120, 57, + 121, 4, 2, 21, 8, 4, 19, 5, 7,120, 56,121, 0, 0,128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 11, 7, 4, 19, 19, 1,120, 55,121,120,121,122, + 15, 14, 6, 4, 19, 21, 18,120, 54,121,102,111,117,114, 85,102,119, 9, 5, + 4, 19, 1, 1,120, 53,121, 3, 4, 18, 4, 4, 19, 23, 5,120, 52,121, 98, + 117, 98, 98, 97, 0, 0,128, 0, 0, 0, 10, 3, 4, 19, 0, 19,120, 51,121, + 120,121,122, 19, 2, 4, 19, 7, 21,120, 50,121, 64, 12, 0, 0, 0, 0, 0, + 0,102,111,117,114, 9, 0, 0, 0, 12, 53, 0, 0, 0, 11, 27, 2, 0, 0, + 0, 1, 1,243, 0, 0, 0, 0, 15, 1,243, 1,220, 1,211, 1,202, 1,193, + 1,184, 1,175, 1,166, 1,159, 1,150, 1,141, 1,132, 1,123, 1,114, 1, + 105, 1, 96, 1, 87, 1, 78, 1, 69, 1, 61, 1, 52, 1, 43, 1, 34, 1, 25, + 1, 16, 1, 7, 0,254, 0,245, 0,236, 0,227, 0,219, 0,210, 0,201, 0, + 192, 0,183, 0,174, 0,165, 0,156, 0,147, 0,138, 0,129, 0,121, 0,112, + 0,103, 0, 0, 0, 8, 3, 21, 1,120, 53, 49,121, 51, 8, 3, 21, 1,120, + 53, 48,121, 50, 7, 3, 19, 1,120, 52,121, 4, 8, 3, 21, 1,120, 52, 57, + 121, 49, 8, 3, 21, 1,120, 52, 56,121, 48, 8, 3, 21, 1,120, 52, 55,121, + 47, 8, 3, 21, 1,120, 52, 54,121, 46, 8, 3, 21, 1,120, 52, 53,121, 45, + 8, 3, 21, 1,120, 52, 52,121, 44, 8, 3, 21, 1,120, 52, 51,121, 43, 8, + 3, 21, 1,120, 52, 50,121, 42, 8, 3, 21, 1,120, 52, 49,121, 41, 8, 3, + 21, 1,120, 52, 48,121, 40, 7, 3, 19, 1,120, 51,121, 3, 8, 3, 21, 1, + 120, 51, 57,121, 39, 8, 3, 21, 1,120, 51, 56,121, 38, 8, 3, 21, 1,120, + 51, 55,121, 37, 8, 3, 21, 1,120, 51, 54,121, 36, 8, 3, 21, 1,120, 51, + 53,121, 35, 8, 3, 21, 1,120, 51, 52,121, 34, 8, 3, 21, 1,120, 51, 51, + 121, 33, 8, 3, 21, 1,120, 51, 50,121, 32, 8, 3, 21, 1,120, 51, 49,121, + 31, 8, 3, 21, 1,120, 51, 48,121, 30, 7, 3, 19, 1,120, 50,121, 2, 8, + 3, 21, 1,120, 50, 57,121, 29, 8, 3, 21, 1,120, 50, 56,121, 28, 8, 3, + 21, 1,120, 50, 55,121, 27, 8, 3, 21, 1,120, 50, 54,121, 26, 8, 3, 21, + 1,120, 50, 53,121, 25, 8, 3, 21, 1,120, 50, 52,121, 24, 8, 3, 21, 1, + 120, 50, 51,121, 23, 8, 3, 21, 1,120, 50, 50,121, 22, 8, 3, 21, 1,120, + 50, 49,121, 21, 8, 3, 21, 1,120, 50, 48,121, 20, 6, 3, 19, 9,120, 49, + 121, 8, 3, 21, 1,120, 49, 57,121, 19, 8, 3, 21, 1,120, 49, 56,121, 18, + 8, 3, 21, 1,120, 49, 55,121, 17, 8, 3, 21, 1,120, 49, 54,121, 16, 8, + 3, 21, 1,120, 49, 53,121, 15, 8, 3, 21, 1,120, 49, 52,121, 14, 8, 3, + 21, 1,120, 49, 51,121, 13, 8, 3, 21, 1,120, 49, 50,121, 12, 8, 3, 21, + 1,120, 0, 0, 0, 14, 8, 3, 21, 1,120, 53, 49,121, 51, 5, 0, 0, 0, + 2, 1,246, 0, 0, 0, 0, 18, 1,251, 1,246, 1,156, 1,135, 1,117, 1, + 89, 1, 73, 1, 55, 1, 41, 1, 14, 0,254, 0,228, 0,211, 0,186, 0,170, + 0,149, 0,131, 0,110, 0, 94, 0, 69, 0, 54, 13, 23, 4, 7, 0, 1, 64, + 57, 76,204,204,204,204,205, 15, 23, 22, 4, 7, 7, 18, 64, 56, 51, 51, 51, + 51, 51, 52, 64, 12, 0, 0, 0, 0, 0, 0, 85,102,119, 14, 21, 4, 7, 1, + 1, 64, 55, 25,153,153,153,153,154, 2, 4, 19, 20, 4, 1, 7, 5, 22, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 16, 19, 4, 7, 1, 19, + 64, 52,230,102,102,102,102,103, 15,120,121,122, 19, 18, 4, 7, 18, 21, 64, + 51,204,204,204,204,204,205, 85,102,119,102,111,117,114, 14, 17, 4, 7, 1, + 1, 64, 50,179, 51, 51, 51, 51, 52, 4, 3, 23, 16, 4, 7, 23, 5, 64, 49, + 153,153,153,153,153,154, 98,117, 98, 98, 97, 0, 0,128, 0, 0, 0, 15, 15, + 4, 7, 0, 19, 64, 48,128, 0, 0, 0, 0, 0,120,121,122, 24, 14, 4, 7, + 7, 21, 64, 46,204,204,204,204,204,206, 64, 12, 0, 0, 0, 0, 0, 0,102, + 111,117,114, 14, 13, 4, 7, 1, 1, 64, 44,153,153,153,153,153,154, 2, 3, + 25, 12, 4, 7, 7, 23, 64, 42,102,102,102,102,102,103, 0, 0, 0, 0, 0, + 0, 0, 0, 98,117, 98, 98, 97, 12, 11, 3, 7, 1, 64, 40, 51, 51, 51, 51, + 51, 52, 15, 16, 10, 4, 1, 18, 7, 11, 85,102,119, 64, 12, 0, 0, 0, 0, + 0, 0, 14, 9, 4, 7, 1, 1, 64, 35,204,204,204,204,204,205, 4, 2, 26, + 8, 4, 7, 5, 7, 64, 33,153,153,153,153,153,154, 0, 0,128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 16, 7, 4, 7, 19, 1, 64, 30,204,204,204, + 204,204,206,120,121,122, 15, 19, 6, 4, 7, 21, 18, 64, 26,102,102,102,102, + 102,103,102,111,117,114, 85,102,119, 14, 5, 4, 7, 1, 1, 64, 22, 0, 0, + 0, 0, 0, 0, 3, 4, 23, 4, 4, 7, 23, 5, 64, 17,153,153,153,153,153, + 154, 98,117, 98, 98, 97, 0, 0,128, 0, 0, 0, 15, 3, 4, 7, 0, 19, 64, + 10,102,102,102,102,102,103,120,121,122, 24, 2, 4, 7, 7, 21, 64, 1,153, + 153,153,153,153,154, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 14, 1, + 4, 7, 1, 1, 0, 0, 0, 17, 45, 0, 0, 0, 16, 23, 2, 0, 0, 0, 1, + 1,239, 0, 0, 0, 0, 20, 1,239, 1,205, 1,192, 1,179, 1,166, 1,153, + 1,140, 1,134, 1,121, 1,108, 1, 95, 1, 82, 1, 69, 1, 56, 1, 43, 1, + 30, 1, 17, 1, 11, 0,254, 0,241, 0,228, 0,215, 0,202, 0,189, 0,176, + 0,163, 0,150, 0,144, 0,131, 0,118, 0,105, 0, 92, 0, 79, 0, 12, 3, + 7, 1, 64, 67, 64, 0, 0, 0, 0, 0, 35, 12, 3, 7, 1, 64, 66,179, 51, + 51, 51, 51, 52, 34, 12, 3, 7, 1, 64, 66, 38,102,102,102,102,103, 33, 12, + 3, 7, 1, 64, 65,153,153,153,153,153,154, 32, 12, 3, 7, 1, 64, 65, 12, + 204,204,204,204,205, 31, 5, 3, 1, 1, 33, 30, 12, 3, 7, 1, 64, 63,230, + 102,102,102,102,103, 29, 12, 3, 7, 1, 64, 62,204,204,204,204,204,206, 28, + 12, 3, 7, 1, 64, 61,179, 51, 51, 51, 51, 52, 27, 12, 3, 7, 1, 64, 60, + 153,153,153,153,153,154, 26, 12, 3, 7, 1, 64, 59,128, 0, 0, 0, 0, 1, + 25, 12, 3, 7, 1, 64, 58,102,102,102,102,102,103, 24, 12, 3, 7, 1, 64, + 57, 76,204,204,204,204,205, 23, 12, 3, 7, 1, 64, 56, 51, 51, 51, 51, 51, + 52, 22, 12, 3, 7, 1, 64, 55, 25,153,153,153,153,154, 21, 5, 3, 1, 1, + 22, 20, 12, 3, 7, 1, 64, 52,230,102,102,102,102,103, 19, 12, 3, 7, 1, + 64, 51,204,204,204,204,204,205, 18, 12, 3, 7, 1, 64, 50,179, 51, 51, 51, + 51, 52, 17, 12, 3, 7, 1, 64, 49,153,153,153,153,153,154, 16, 12, 3, 7, + 1, 64, 48,128, 0, 0, 0, 0, 0, 15, 12, 3, 7, 1, 64, 46,204,204,204, + 204,204,206, 14, 12, 3, 7, 1, 64, 44,153,153,153,153,153,154, 13, 12, 3, + 7, 1, 64, 42,102,102,102,102,102,103, 12, 12, 3, 7, 1, 64, 40, 51, 51, + 51, 51, 51, 52, 11, 5, 3, 1, 1, 11, 10, 12, 3, 7, 1, 64, 35,204,204, + 204,204,204,205, 9, 12, 3, 7, 1, 64, 33,153,153,153,153,153,154, 8, 12, + 3, 7, 1, 64, 30,204,204,204,204,204,206, 7, 12, 3, 7, 1, 64, 26,102, + 102,102,102,102,103, 6, 12, 3, 7, 1, 64, 22, 0, 0, 0, 0, 0, 0, 5, + 12, 3, 7, 1, 64, 17,153,153,153,153,153,154, 4, 12, 3, 7, 1, 64, 10, + 102,102,102,102,102,103, 3, 12, 3, 7, 1, 64, 1,153,153, 0, 0, 0, 19, + 12, 3, 7, 1, 64, 67, 64, 0, 0, 0, 0, 0, 35, 2, 0, 0, 0, 1, 1, + 242, 0, 0, 0, 0, 22, 1,242, 1,218, 1,211, 1,202, 1,192, 1,179, 1, + 172, 1,157, 1,149, 1,141, 1,132, 1,125, 1,116, 1,106, 1, 93, 1, 86, + 1, 74, 1, 63, 1, 47, 1, 40, 1, 31, 1, 16, 1, 8, 0,255, 0,248, 0, + 239, 0,229, 0,216, 0,209, 0,197, 0,186, 0,174, 0,158, 0,151, 0,136, + 0,128, 0,119, 0,112, 0,103, 0, 93, 0, 9, 2, 27, 52, 55, 44, 78, 85, + 76, 76, 8, 2, 25, 52, 54, 44, 51, 46, 53, 6, 2, 21, 52, 53, 44, 50, 8, + 2, 25, 52, 52, 44, 48, 46, 48, 7, 2, 23, 52, 51, 44, 49, 53, 14, 2, 37, + 52, 50, 44, 88, 39, 53, 53, 54, 54, 55, 55, 39, 6, 2, 21, 52, 49, 44, 52, + 15, 2, 39, 52, 48, 44, 50, 49, 52, 55, 52, 56, 51, 54, 52, 56, 11, 2, 31, + 52, 44, 39, 98,117, 98, 98, 97, 39, 10, 2, 29, 51, 57, 44, 39,120,121,122, + 39, 11, 2, 31, 51, 56, 44, 39,102,111,117,114, 39, 6, 2, 21, 51, 55, 44, + 51, 12, 2, 33, 51, 54, 44, 39, 98,117, 98, 98, 97, 39, 9, 2, 27, 51, 53, + 44, 78, 85, 76, 76, 8, 2, 25, 51, 52, 44, 51, 46, 53, 6, 2, 21, 51, 51, + 44, 50, 8, 2, 25, 51, 50, 44, 48, 46, 48, 7, 2, 23, 51, 49, 44, 49, 53, + 14, 2, 37, 51, 48, 44, 88, 39, 53, 53, 54, 54, 55, 55, 39, 8, 2, 25, 51, + 44, 78, 85, 76, 76, 6, 2, 21, 50, 57, 44, 52, 15, 2, 39, 50, 56, 44, 50, + 49, 52, 55, 52, 56, 51, 54, 52, 56, 10, 2, 29, 50, 55, 44, 39,120,121,122, + 39, 11, 2, 31, 50, 54, 44, 39,102,111,117,114, 39, 6, 2, 21, 50, 53, 44, + 51, 12, 2, 33, 50, 52, 44, 39, 98,117, 98, 98, 97, 39, 9, 2, 27, 50, 51, + 44, 78, 85, 76, 76, 8, 2, 25, 50, 50, 44, 51, 46, 53, 6, 2, 21, 50, 49, + 44, 50, 8, 2, 25, 50, 48, 44, 48, 46, 48, 7, 2, 23, 50, 44, 51, 46, 53, + 7, 2, 23, 49, 57, 44, 49, 53, 14, 2, 37, 49, 56, 44, 88, 39, 53, 53, 54, + 54, 55, 55, 39, 6, 2, 21, 49, 55, 44, 52, 12, 2, 33, 49, 54, 44, 39, 98, + 117, 98, 98, 97, 39, 9, 2, 27, 49, 53, 44, 78, 85, 76, 76, 8, 2, 25, 49, + 52, 44, 51, 46, 53, 6, 2, 21, 49, 51, 44, 50, 8, 2, 25, 49, 50, 44, 48, + 46, 48, 7, 2, 23, 49, 49, 44, 49, 53, 14, 2, 37, 49, 48, 44, 88, 0, 0, + 0, 21, 9, 2, 27, 52, 55, 44, 78, 85, 76, 76, 13, 0, 0, 0, 26, 0, 68, + 0, 1,246, 1,224, 1,213, 1,187, 1,177, 1,155, 1,145, 1,119, 1,109, + 1, 87, 1, 76, 1, 50, 1, 40, 1, 18, 1, 7, 0,237, 0,227, 0,205, 0, + 195, 0,169, 0,159, 0,137, 0,126, 0,100, 0, 90, 0, 68, 0, 0, 0, 0, + 0, 0, 0, 0, 20, 26, 5, 0, 21, 7, 18,102,111,117,114, 64, 12, 0, 0, + 0, 0, 0, 0, 85,102,119, 8, 25, 5, 0, 1, 1, 1, 3, 2, 4, 24, 24, + 5, 0, 23, 7, 5, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0,128, 0, 0, 0, 9, 23, 5, 0, 0, 1, 19, 15,120,121,122, 20, 22, 5, + 0, 7, 18, 21, 64, 12, 0, 0, 0, 0, 0, 0, 85,102,119,102,111,117,114, + 8, 21, 5, 0, 1, 1, 1, 2, 4, 3, 24, 20, 5, 0, 7, 5, 23, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 98,117, 98, 98, 97, 8, 19, + 4, 0, 1, 19, 15,120,121,122, 20, 18, 5, 0, 18, 21, 7, 85,102,119,102, + 111,117,114, 64, 12, 0, 0, 0, 0, 0, 0, 8, 17, 5, 0, 1, 1, 1, 4, + 3, 2, 24, 16, 5, 0, 23, 5, 7, 98,117, 98, 98, 97, 0, 0,128, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 15, 5, 0, 0, 19, 1,120,121,122, + 15, 20, 14, 5, 0, 7, 21, 18, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117, + 114, 85,102,119, 8, 13, 5, 0, 1, 1, 1, 2, 3, 4, 24, 12, 5, 0, 7, + 23, 5, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 0, 0,128, 0, + 0, 0, 9, 11, 5, 0, 1, 0, 19, 15,120,121,122, 20, 10, 5, 0, 18, 7, + 21, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 8, 9, 5, + 0, 1, 1, 1, 4, 2, 3, 24, 8, 5, 0, 5, 7, 23, 0, 0,128, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 8, 7, 4, 0, 19, + 1,120,121,122, 15, 20, 6, 5, 0, 21, 18, 7,102,111,117,114, 85,102,119, + 64, 12, 0, 0, 0, 0, 0, 0, 8, 5, 5, 0, 1, 1, 1, 3, 4, 2, 24, + 4, 5, 0, 23, 5, 7, 98,117, 98, 98, 97, 0, 0,128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 9, 3, 5, 0, 0, 19, 1,120,121,122, 15, 20, 2, + 5, 0, 7, 21, 18, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 85,102, + 119, 8, 1, 5, 0, 1, 1, 1, 2, 3, 4, 13, 0, 0, 0, 26, 0, 63, 0, + 1,245, 1,219, 1,209, 1,187, 1,177, 1,151, 1,141, 1,119, 1,108, 1, + 82, 1, 72, 1, 50, 1, 39, 1, 13, 1, 3, 0,237, 0,227, 0,201, 0,191, + 0,169, 0,158, 0,132, 0,122, 0,100, 0, 89, 0, 63, 0, 0, 0, 24, 52, + 5, 0, 7, 23, 5, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 0, + 0,128, 0, 0, 0, 9, 51, 5, 0, 1, 0, 19, 15,120,121,122, 20, 50, 5, + 0, 18, 7, 21, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, + 8, 49, 5, 0, 1, 1, 1, 4, 2, 3, 24, 48, 5, 0, 23, 7, 5, 98,117, + 98, 98, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 9, 47, + 5, 0, 0, 1, 19, 15,120,121,122, 20, 46, 5, 0, 7, 18, 21, 64, 12, 0, + 0, 0, 0, 0, 0, 85,102,119,102,111,117,114, 8, 45, 5, 0, 1, 1, 1, + 2, 4, 3, 24, 44, 5, 0, 7, 5, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0,128, 0, 0, 0, 98,117, 98, 98, 97, 8, 43, 4, 0, 1, 19, 15,120,121, + 122, 20, 42, 5, 0, 18, 21, 7, 85,102,119,102,111,117,114, 64, 12, 0, 0, + 0, 0, 0, 0, 8, 41, 5, 0, 1, 1, 1, 4, 3, 2, 24, 40, 5, 0, 5, + 23, 7, 0, 0,128, 0, 0, 0, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, + 0, 0, 9, 39, 5, 0, 19, 0, 1,120,121,122, 15, 20, 38, 5, 0, 21, 7, + 18,102,111,117,114, 64, 12, 0, 0, 0, 0, 0, 0, 85,102,119, 8, 37, 5, + 0, 1, 1, 1, 3, 2, 4, 24, 36, 5, 0, 23, 7, 5, 98,117, 98, 98, 97, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 9, 35, 5, 0, 0, + 1, 19, 15,120,121,122, 20, 34, 5, 0, 7, 18, 21, 64, 12, 0, 0, 0, 0, + 0, 0, 85,102,119,102,111,117,114, 8, 33, 5, 0, 1, 1, 1, 2, 4, 3, + 24, 32, 5, 0, 7, 5, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, + 0, 0, 98,117, 98, 98, 97, 8, 31, 4, 0, 1, 19, 15,120,121,122, 20, 30, + 5, 0, 18, 21, 7, 85,102,119,102,111,117,114, 64, 12, 0, 0, 0, 0, 0, + 0, 8, 29, 5, 0, 1, 1, 1, 4, 3, 2, 24, 28, 5, 0, 5, 23, 7, 0, + 0,128, 0, 0, 0, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, 0, 0, 9, + 27, 5, 0, 19, 0, 1,120,121,122, 15, 13, 0, 0, 0, 12, 1, 50, 0, 1, + 246, 1,224, 1,213, 1,187, 1,177, 1,155, 1,145, 1,119, 1,109, 1, 87, + 1, 76, 1, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 64, 5, 0, 7, 23, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 0, 0,128, 0, 0, 0, + 9, 63, 5, 0, 1, 0, 19, 15,120,121,122, 20, 62, 5, 0, 18, 7, 21, 85, + 102,119, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 8, 61, 5, 0, 1, + 1, 1, 4, 2, 3, 24, 60, 5, 0, 5, 7, 23, 0, 0,128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 8, 59, 4, 0, 19, 1,120, + 121,122, 15, 20, 58, 5, 0, 21, 18, 7,102,111,117,114, 85,102,119, 64, 12, + 0, 0, 0, 0, 0, 0, 8, 57, 5, 0, 1, 1, 1, 3, 4, 2, 24, 56, 5, + 0, 23, 5, 7, 98,117, 98, 98, 97, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 9, 55, 5, 0, 0, 19, 1,120,121,122, 15, 20, 54, 5, 0, + 7, 21, 18, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 85,102,119, 8, + 53, 5, 0, 1, 1, 1, 2, 3, 4, 13, 0, 0, 0, 27, 0, 72, 0, 1,245, + 1,224, 1,212, 1,192, 1,181, 1,165, 1,152, 1,129, 1,118, 1, 97, 1, + 87, 1, 64, 1, 52, 1, 30, 1, 17, 0,252, 0,240, 0,223, 0,209, 0,185, + 0,173, 0,152, 0,141, 0,118, 0,106, 0, 84, 0, 72, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 10, 27, 3, 21, 19,120, 50, 55,121,120,121,122, 20, 26, + 4, 21, 21, 7,120, 50, 54,121,102,111,117,114, 64, 12, 0, 0, 0, 0, 0, + 0, 10, 25, 4, 21, 1, 1,120, 50, 53,121, 3, 2, 21, 24, 4, 21, 23, 7, + 120, 50, 52,121, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, 0, 0, 9, 23, + 4, 21, 0, 1,120, 50, 51,121, 15, 19, 22, 4, 21, 7, 18,120, 50, 50,121, + 64, 12, 0, 0, 0, 0, 0, 0, 85,102,119, 10, 21, 4, 21, 1, 1,120, 50, + 49,121, 2, 4, 22, 20, 4, 21, 7, 5,120, 50, 48,121, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0,128, 0, 0, 0, 12, 19, 4, 21, 1, 19,120, 49, 57,121, + 15,120,121,122, 15, 18, 4, 21, 18, 21,120, 49, 56,121, 85,102,119,102,111, + 117,114, 10, 17, 4, 21, 1, 1,120, 49, 55,121, 4, 3, 19, 16, 4, 21, 23, + 5,120, 49, 54,121, 98,117, 98, 98, 97, 0, 0,128, 0, 0, 0, 11, 15, 4, + 21, 0, 19,120, 49, 53,121,120,121,122, 20, 14, 4, 21, 7, 21,120, 49, 52, + 121, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 10, 13, 4, 21, 1, 1, + 120, 49, 51,121, 2, 3, 21, 12, 4, 21, 7, 23,120, 49, 50,121, 0, 0, 0, + 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 8, 11, 3, 21, 1,120, 49, 49,121, + 15, 19, 10, 4, 21, 18, 7,120, 49, 48,121, 85,102,119, 64, 12, 0, 0, 0, + 0, 0, 0, 9, 9, 4, 19, 1, 1,120, 57,121, 4, 2, 21, 8, 4, 19, 5, + 7,120, 56,121, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, + 7, 4, 19, 19, 1,120, 55,121,120,121,122, 15, 14, 6, 4, 19, 21, 18,120, + 54,121,102,111,117,114, 85,102,119, 9, 5, 4, 19, 1, 1,120, 53,121, 3, + 4, 18, 4, 4, 19, 23, 5,120, 52,121, 98,117, 98, 98, 97, 0, 0,128, 0, + 0, 0, 10, 3, 4, 19, 0, 19,120, 51,121,120,121,122, 19, 2, 4, 19, 7, + 21,120, 50,121, 64, 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 9, 1, 4, + 19, 1, 1,120, 49,121, 2, 3, 13, 0, 0, 0, 26, 0, 78, 0, 1,235, 1, + 223, 1,206, 1,192, 1,168, 1,156, 1,135, 1,124, 1,101, 1, 89, 1, 67, + 1, 55, 1, 34, 1, 22, 1, 5, 0,247, 0,223, 0,211, 0,190, 0,179, 0, + 156, 0,144, 0,123, 0,113, 0, 90, 0, 78, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 53, 4, 21, 1, 1,120, 53, 51, + 121, 2, 3, 21, 52, 4, 21, 7, 23,120, 53, 50,121, 0, 0, 0, 0, 0, 0, + 0, 0, 98,117, 98, 98, 97, 8, 51, 3, 21, 1,120, 53, 49,121, 15, 19, 50, + 4, 21, 18, 7,120, 53, 48,121, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0, + 10, 49, 4, 21, 1, 1,120, 52, 57,121, 4, 2, 21, 48, 4, 21, 23, 7,120, + 52, 56,121, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, 0, 0, 9, 47, 4, + 21, 0, 1,120, 52, 55,121, 15, 19, 46, 4, 21, 7, 18,120, 52, 54,121, 64, + 12, 0, 0, 0, 0, 0, 0, 85,102,119, 10, 45, 4, 21, 1, 1,120, 52, 53, + 121, 2, 4, 22, 44, 4, 21, 7, 5,120, 52, 52,121, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0,128, 0, 0, 0, 12, 43, 4, 21, 1, 19,120, 52, 51,121, 15, + 120,121,122, 15, 42, 4, 21, 18, 21,120, 52, 50,121, 85,102,119,102,111,117, + 114, 10, 41, 4, 21, 1, 1,120, 52, 49,121, 4, 3, 19, 40, 4, 21, 5, 23, + 120, 52, 48,121, 0, 0,128, 0, 0, 0, 98,117, 98, 98, 97, 10, 39, 3, 21, + 19,120, 51, 57,121,120,121,122, 20, 38, 4, 21, 21, 7,120, 51, 56,121,102, + 111,117,114, 64, 12, 0, 0, 0, 0, 0, 0, 10, 37, 4, 21, 1, 1,120, 51, + 55,121, 3, 2, 21, 36, 4, 21, 23, 7,120, 51, 54,121, 98,117, 98, 98, 97, + 0, 0, 0, 0, 0, 0, 0, 0, 9, 35, 4, 21, 0, 1,120, 51, 53,121, 15, + 19, 34, 4, 21, 7, 18,120, 51, 52,121, 64, 12, 0, 0, 0, 0, 0, 0, 85, + 102,119, 10, 33, 4, 21, 1, 1,120, 51, 51,121, 2, 4, 22, 32, 4, 21, 7, + 5,120, 51, 50,121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, + 12, 31, 4, 21, 1, 19,120, 51, 49,121, 15,120,121,122, 15, 30, 4, 21, 18, + 21,120, 51, 48,121, 85,102,119,102,111,117,114, 10, 29, 4, 21, 1, 1,120, + 50, 57,121, 4, 3, 19, 28, 4, 21, 5, 23,120, 50, 56,121, 0, 0,128, 0, + 0, 0, 98,117, 98, 98, 97, 13, 0, 0, 0, 11, 1, 67, 0, 1,234, 1,221, + 1,200, 1,188, 1,171, 1,157, 1,133, 1,121, 1,100, 1, 90, 1, 67, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 21, 64, 4, 21, 7, 23,120, 54, 52,121, 0, 0, + 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 8, 63, 3, 21, 1,120, 54, 51, + 121, 15, 19, 62, 4, 21, 18, 7,120, 54, 50,121, 85,102,119, 64, 12, 0, 0, + 0, 0, 0, 0, 10, 61, 4, 21, 1, 1,120, 54, 49,121, 4, 2, 22, 60, 4, + 21, 5, 7,120, 54, 48,121, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 12, 59, 4, 21, 19, 1,120, 53, 57,121,120,121,122, 15, 15, 58, 4, + 21, 21, 18,120, 53, 56,121,102,111,117,114, 85,102,119, 10, 57, 4, 21, 1, + 1,120, 53, 55,121, 3, 4, 19, 56, 4, 21, 23, 5,120, 53, 54,121, 98,117, + 98, 98, 97, 0, 0,128, 0, 0, 0, 11, 55, 4, 21, 0, 19,120, 53, 53,121, + 120,121,122, 20, 54, 4, 21, 7, 21,120, 53, 52,121, 64, 12, 0, 0, 0, 0, + 0, 0,102,111,117,114, 10, 0, 0, 0, 45, 0,112, 0, 1,247, 1,238, 1, + 229, 1,220, 1,211, 1,202, 1,193, 1,184, 1,175, 1,166, 1,159, 1,150, + 1,141, 1,132, 1,123, 1,114, 1,105, 1, 96, 1, 87, 1, 78, 1, 69, 1, + 61, 1, 52, 1, 43, 1, 34, 1, 25, 1, 16, 1, 7, 0,254, 0,245, 0,236, + 0,227, 0,219, 0,210, 0,201, 0,192, 0,183, 0,174, 0,165, 0,156, 0, + 147, 0,138, 0,129, 0,121, 0,112, 0,103, 0, 0, 0, 0, 0, 0, 9,120, + 53, 49,121, 51, 8, 3, 21, 1,120, 53, 48,121, 50, 7, 3, 19, 1,120, 52, + 121, 4, 8, 3, 21, 1,120, 52, 57,121, 49, 8, 3, 21, 1,120, 52, 56,121, + 48, 8, 3, 21, 1,120, 52, 55,121, 47, 8, 3, 21, 1,120, 52, 54,121, 46, + 8, 3, 21, 1,120, 52, 53,121, 45, 8, 3, 21, 1,120, 52, 52,121, 44, 8, + 3, 21, 1,120, 52, 51,121, 43, 8, 3, 21, 1,120, 52, 50,121, 42, 8, 3, + 21, 1,120, 52, 49,121, 41, 8, 3, 21, 1,120, 52, 48,121, 40, 7, 3, 19, + 1,120, 51,121, 3, 8, 3, 21, 1,120, 51, 57,121, 39, 8, 3, 21, 1,120, + 51, 56,121, 38, 8, 3, 21, 1,120, 51, 55,121, 37, 8, 3, 21, 1,120, 51, + 54,121, 36, 8, 3, 21, 1,120, 51, 53,121, 35, 8, 3, 21, 1,120, 51, 52, + 121, 34, 8, 3, 21, 1,120, 51, 51,121, 33, 8, 3, 21, 1,120, 51, 50,121, + 32, 8, 3, 21, 1,120, 51, 49,121, 31, 8, 3, 21, 1,120, 51, 48,121, 30, + 7, 3, 19, 1,120, 50,121, 2, 8, 3, 21, 1,120, 50, 57,121, 29, 8, 3, + 21, 1,120, 50, 56,121, 28, 8, 3, 21, 1,120, 50, 55,121, 27, 8, 3, 21, + 1,120, 50, 54,121, 26, 8, 3, 21, 1,120, 50, 53,121, 25, 8, 3, 21, 1, + 120, 50, 52,121, 24, 8, 3, 21, 1,120, 50, 51,121, 23, 8, 3, 21, 1,120, + 50, 50,121, 22, 8, 3, 21, 1,120, 50, 49,121, 21, 8, 3, 21, 1,120, 50, + 48,121, 20, 6, 3, 19, 9,120, 49,121, 8, 3, 21, 1,120, 49, 57,121, 19, + 8, 3, 21, 1,120, 49, 56,121, 18, 8, 3, 21, 1,120, 49, 55,121, 17, 8, + 3, 21, 1,120, 49, 54,121, 16, 8, 3, 21, 1,120, 49, 53,121, 15, 8, 3, + 21, 1,120, 49, 52,121, 14, 8, 3, 21, 1,120, 49, 51,121, 13, 8, 3, 21, + 1,120, 49, 50,121, 12, 8, 3, 21, 1,120, 49, 49,121, 11, 8, 3, 21, 1, + 120, 49, 48,121, 10, 10, 0, 0, 0, 18, 1, 99, 0, 1,247, 1,238, 1,229, + 1,220, 1,211, 1,202, 1,193, 1,184, 1,176, 1,167, 1,158, 1,149, 1, + 140, 1,131, 1,123, 1,115, 1,107, 1, 99, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, + 3, 19, 1,120, 57,121, 9, 7, 3, 19, 1,120, 56,121, 8, 7, 3, 19, 1, + 120, 55,121, 7, 7, 3, 19, 1,120, 54,121, 6, 8, 3, 21, 1,120, 54, 52, + 121, 64, 8, 3, 21, 1,120, 54, 51,121, 63, 8, 3, 21, 1,120, 54, 50,121, + 62, 8, 3, 21, 1,120, 54, 49,121, 61, 8, 3, 21, 1,120, 54, 48,121, 60, + 7, 3, 19, 1,120, 53,121, 5, 8, 3, 21, 1,120, 53, 57,121, 59, 8, 3, + 21, 1,120, 53, 56,121, 58, 8, 3, 21, 1,120, 53, 55,121, 57, 8, 3, 21, + 1,120, 53, 54,121, 56, 8, 3, 21, 1,120, 53, 53,121, 55, 8, 3, 21, 1, + 120, 53, 52,121, 54, 8, 3, 21, 1,120, 53, 51,121, 53, 8, 3, 21, 1,120, + 53, 50,121, 52, 13, 0, 0, 0, 23, 0, 54, 0, 1,240, 1,214, 1,197, 1, + 172, 1,156, 1,135, 1,117, 1, 89, 1, 73, 1, 55, 1, 41, 1, 14, 0,254, + 0,228, 0,211, 0,186, 0,170, 0,149, 0,131, 0,110, 0, 94, 0, 69, 0, + 54, 13, 23, 4, 7, 0, 1, 64, 57, 76,204,204,204,204,205, 15, 23, 22, 4, + 7, 7, 18, 64, 56, 51, 51, 51, 51, 51, 52, 64, 12, 0, 0, 0, 0, 0, 0, + 85,102,119, 14, 21, 4, 7, 1, 1, 64, 55, 25,153,153,153,153,154, 2, 4, + 19, 20, 4, 1, 7, 5, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, + 0, 0, 16, 19, 4, 7, 1, 19, 64, 52,230,102,102,102,102,103, 15,120,121, + 122, 19, 18, 4, 7, 18, 21, 64, 51,204,204,204,204,204,205, 85,102,119,102, + 111,117,114, 14, 17, 4, 7, 1, 1, 64, 50,179, 51, 51, 51, 51, 52, 4, 3, + 23, 16, 4, 7, 23, 5, 64, 49,153,153,153,153,153,154, 98,117, 98, 98, 97, + 0, 0,128, 0, 0, 0, 15, 15, 4, 7, 0, 19, 64, 48,128, 0, 0, 0, 0, + 0,120,121,122, 24, 14, 4, 7, 7, 21, 64, 46,204,204,204,204,204,206, 64, + 12, 0, 0, 0, 0, 0, 0,102,111,117,114, 14, 13, 4, 7, 1, 1, 64, 44, + 153,153,153,153,153,154, 2, 3, 25, 12, 4, 7, 7, 23, 64, 42,102,102,102, + 102,102,103, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 12, 11, 3, + 7, 1, 64, 40, 51, 51, 51, 51, 51, 52, 15, 16, 10, 4, 1, 18, 7, 11, 85, + 102,119, 64, 12, 0, 0, 0, 0, 0, 0, 14, 9, 4, 7, 1, 1, 64, 35,204, + 204,204,204,204,205, 4, 2, 26, 8, 4, 7, 5, 7, 64, 33,153,153,153,153, + 153,154, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 7, 4, + 7, 19, 1, 64, 30,204,204,204,204,204,206,120,121,122, 15, 19, 6, 4, 7, + 21, 18, 64, 26,102,102,102,102,102,103,102,111,117,114, 85,102,119, 14, 5, + 4, 7, 1, 1, 64, 22, 0, 0, 0, 0, 0, 0, 3, 4, 23, 4, 4, 7, 23, + 5, 64, 17,153,153,153,153,153,154, 98,117, 98, 98, 97, 0, 0,128, 0, 0, + 0, 15, 3, 4, 7, 0, 19, 64, 10,102,102,102,102,102,103,120,121,122, 24, + 2, 4, 7, 7, 21, 64, 1,153,153,153,153,153,154, 64, 12, 0, 0, 0, 0, + 0, 0,102,111,117,114, 14, 1, 4, 7, 1, 1, 63,241,153,153,153,153,153, + 154, 2, 3, 13, 0, 0, 0, 22, 0, 68, 0, 1,229, 1,213, 1,187, 1,171, + 1,146, 1,130, 1,116, 1, 98, 1, 70, 1, 54, 1, 29, 1, 14, 0,243, 0, + 227, 0,201, 0,185, 0,167, 0,151, 0,130, 0,112, 0, 84, 0, 68, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 45, 4, 7, 1, + 1, 64, 72,192, 0, 0, 0, 0, 1, 2, 4, 26, 44, 4, 7, 7, 5, 64, 72, + 51, 51, 51, 51, 51, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, + 0, 16, 43, 4, 7, 1, 19, 64, 71,166,102,102,102,102,103, 15,120,121,122, + 19, 42, 4, 7, 18, 21, 64, 71, 25,153,153,153,153,154, 85,102,119,102,111, + 117,114, 14, 41, 4, 7, 1, 1, 64, 70,140,204,204,204,204,205, 4, 3, 16, + 40, 4, 1, 5, 23, 44, 0, 0,128, 0, 0, 0, 98,117, 98, 98, 97, 14, 39, + 3, 7, 19, 64, 69,115, 51, 51, 51, 51, 52,120,121,122, 24, 38, 4, 7, 21, + 7, 64, 68,230,102,102,102,102,103,102,111,117,114, 64, 12, 0, 0, 0, 0, + 0, 0, 14, 37, 4, 7, 1, 1, 64, 68, 89,153,153,153,153,154, 3, 2, 25, + 36, 4, 7, 23, 7, 64, 67,204,204,204,204,204,205, 98,117, 98, 98, 97, 0, + 0, 0, 0, 0, 0, 0, 0, 13, 35, 4, 7, 0, 1, 64, 67, 64, 0, 0, 0, + 0, 0, 15, 23, 34, 4, 7, 7, 18, 64, 66,179, 51, 51, 51, 51, 52, 64, 12, + 0, 0, 0, 0, 0, 0, 85,102,119, 14, 33, 4, 7, 1, 1, 64, 66, 38,102, + 102,102,102,103, 2, 4, 26, 32, 4, 7, 7, 5, 64, 65,153,153,153,153,153, + 154, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 16, 31, 4, 7, + 1, 19, 64, 65, 12,204,204,204,204,205, 15,120,121,122, 12, 30, 4, 1, 18, + 21, 33, 85,102,119,102,111,117,114, 14, 29, 4, 7, 1, 1, 64, 63,230,102, + 102,102,102,103, 4, 3, 23, 28, 4, 7, 5, 23, 64, 62,204,204,204,204,204, + 206, 0, 0,128, 0, 0, 0, 98,117, 98, 98, 97, 14, 27, 3, 7, 19, 64, 61, + 179, 51, 51, 51, 51, 52,120,121,122, 24, 26, 4, 7, 21, 7, 64, 60,153,153, + 153,153,153,154,102,111,117,114, 64, 12, 0, 0, 0, 0, 0, 0, 14, 25, 4, + 7, 1, 1, 64, 59,128, 0, 0, 0, 0, 1, 3, 2, 25, 24, 4, 7, 23, 7, + 64, 58,102,102,102,102,102,103, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, + 0, 0, 13, 0, 0, 0, 19, 0,121, 0, 1,231, 1,216, 1,189, 1,173, 1, + 148, 1,134, 1,107, 1, 91, 1, 65, 1, 48, 1, 23, 1, 7, 0,242, 0,224, + 0,203, 0,187, 0,162, 0,148, 0,121, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 64, 4, 7, 7, 23, 64, 81,153,153, + 153,153,153,154, 0, 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 12, 63, + 3, 7, 1, 64, 81, 83, 51, 51, 51, 51, 52, 15, 23, 62, 4, 7, 18, 7, 64, + 81, 12,204,204,204,204,205, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0, 14, + 61, 4, 7, 1, 1, 64, 80,198,102,102,102,102,103, 4, 2, 19, 60, 4, 1, + 5, 7, 66, 0, 0,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 59, + 4, 7, 19, 1, 64, 80, 57,153,153,153,153,154,120,121,122, 15, 19, 58, 4, + 7, 21, 18, 64, 79,230,102,102,102,102,103,102,111,117,114, 85,102,119, 14, + 57, 4, 7, 1, 1, 64, 79, 89,153,153,153,153,154, 3, 4, 23, 56, 4, 7, + 23, 5, 64, 78,204,204,204,204,204,206, 98,117, 98, 98, 97, 0, 0,128, 0, + 0, 0, 15, 55, 4, 7, 0, 19, 64, 78, 64, 0, 0, 0, 0, 1,120,121,122, + 24, 54, 4, 7, 7, 21, 64, 77,179, 51, 51, 51, 51, 52, 64, 12, 0, 0, 0, + 0, 0, 0,102,111,117,114, 14, 53, 4, 7, 1, 1, 64, 77, 38,102,102,102, + 102,103, 2, 3, 25, 52, 4, 7, 7, 23, 64, 76,153,153,153,153,153,154, 0, + 0, 0, 0, 0, 0, 0, 0, 98,117, 98, 98, 97, 12, 51, 3, 7, 1, 64, 76, + 12,204,204,204,204,205, 15, 23, 50, 4, 7, 18, 7, 64, 75,128, 0, 0, 0, + 0, 1, 85,102,119, 64, 12, 0, 0, 0, 0, 0, 0, 14, 49, 4, 7, 1, 1, + 64, 74,243, 51, 51, 51, 51, 52, 4, 2, 25, 48, 4, 7, 23, 7, 64, 74,102, + 102,102,102,102,103, 98,117, 98, 98, 97, 0, 0, 0, 0, 0, 0, 0, 0, 13, + 47, 4, 7, 0, 1, 64, 73,217,153,153,153,153,154, 15, 23, 46, 4, 7, 7, + 18, 64, 73, 76,204,204,204,204,205, 64, 12, 0, 0, 0, 0, 0, 0, 85,102, + 119, 10, 0, 0, 0, 34, 0, 92, 0, 1,244, 1,231, 1,218, 1,205, 1,192, + 1,179, 1,166, 1,153, 1,140, 1,134, 1,121, 1,108, 1, 95, 1, 82, 1, + 69, 1, 56, 1, 43, 1, 30, 1, 17, 1, 11, 0,254, 0,241, 0,228, 0,215, + 0,202, 0,189, 0,176, 0,163, 0,150, 0,144, 0,131, 0,118, 0,105, 0, + 92, 0, 79, 0, 0, 0, 0, 13, 64, 67, 64, 0, 0, 0, 0, 0, 35, 12, 3, + 7, 1, 64, 66,179, 51, 51, 51, 51, 52, 34, 12, 3, 7, 1, 64, 66, 38,102, + 102,102,102,103, 33, 12, 3, 7, 1, 64, 65,153,153,153,153,153,154, 32, 12, + 3, 7, 1, 64, 65, 12,204,204,204,204,205, 31, 5, 3, 1, 1, 33, 30, 12, + 3, 7, 1, 64, 63,230,102,102,102,102,103, 29, 12, 3, 7, 1, 64, 62,204, + 204,204,204,204,206, 28, 12, 3, 7, 1, 64, 61,179, 51, 51, 51, 51, 52, 27, + 12, 3, 7, 1, 64, 60,153,153,153,153,153,154, 26, 12, 3, 7, 1, 64, 59, + 128, 0, 0, 0, 0, 1, 25, 12, 3, 7, 1, 64, 58,102,102,102,102,102,103, + 24, 12, 3, 7, 1, 64, 57, 76,204,204,204,204,205, 23, 12, 3, 7, 1, 64, + 56, 51, 51, 51, 51, 51, 52, 22, 12, 3, 7, 1, 64, 55, 25,153,153,153,153, + 154, 21, 5, 3, 1, 1, 22, 20, 12, 3, 7, 1, 64, 52,230,102,102,102,102, + 103, 19, 12, 3, 7, 1, 64, 51,204,204,204,204,204,205, 18, 12, 3, 7, 1, + 64, 50,179, 51, 51, 51, 51, 52, 17, 12, 3, 7, 1, 64, 49,153,153,153,153, + 153,154, 16, 12, 3, 7, 1, 64, 48,128, 0, 0, 0, 0, 0, 15, 12, 3, 7, + 1, 64, 46,204,204,204,204,204,206, 14, 12, 3, 7, 1, 64, 44,153,153,153, + 153,153,154, 13, 12, 3, 7, 1, 64, 42,102,102,102,102,102,103, 12, 12, 3, + 7, 1, 64, 40, 51, 51, 51, 51, 51, 52, 11, 5, 3, 1, 1, 11, 10, 12, 3, + 7, 1, 64, 35,204,204,204,204,204,205, 9, 12, 3, 7, 1, 64, 33,153,153, + 153,153,153,154, 8, 12, 3, 7, 1, 64, 30,204,204,204,204,204,206, 7, 12, + 3, 7, 1, 64, 26,102,102,102,102,102,103, 6, 12, 3, 7, 1, 64, 22, 0, + 0, 0, 0, 0, 0, 5, 12, 3, 7, 1, 64, 17,153,153,153,153,153,154, 4, + 12, 3, 7, 1, 64, 10,102,102,102,102,102,103, 3, 12, 3, 7, 1, 64, 1, + 153,153,153,153,153,154, 2, 11, 3, 7, 9, 63,241,153,153,153,153,153,154, + 10, 0, 0, 0, 29, 0,149, 0, 1,243, 1,230, 1,217, 1,204, 1,198, 1, + 185, 1,172, 1,159, 1,146, 1,133, 1,120, 1,107, 1, 94, 1, 81, 1, 68, + 1, 55, 1, 42, 1, 29, 1, 16, 1, 3, 0,246, 0,233, 0,220, 0,207, 0, + 201, 0,188, 0,175, 0,162, 0,149, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 3, 7, + 1, 64, 81,153,153,153,153,153,154, 64, 12, 3, 7, 1, 64, 81, 83, 51, 51, + 51, 51, 52, 63, 12, 3, 7, 1, 64, 81, 12,204,204,204,204,205, 62, 12, 3, + 7, 1, 64, 80,198,102,102,102,102,103, 61, 5, 3, 1, 1, 66, 60, 12, 3, + 7, 1, 64, 80, 57,153,153,153,153,154, 59, 12, 3, 7, 1, 64, 79,230,102, + 102,102,102,103, 58, 12, 3, 7, 1, 64, 79, 89,153,153,153,153,154, 57, 12, + 3, 7, 1, 64, 78,204,204,204,204,204,206, 56, 12, 3, 7, 1, 64, 78, 64, + 0, 0, 0, 0, 1, 55, 12, 3, 7, 1, 64, 77,179, 51, 51, 51, 51, 52, 54, + 12, 3, 7, 1, 64, 77, 38,102,102,102,102,103, 53, 12, 3, 7, 1, 64, 76, + 153,153,153,153,153,154, 52, 12, 3, 7, 1, 64, 76, 12,204,204,204,204,205, + 51, 12, 3, 7, 1, 64, 75,128, 0, 0, 0, 0, 1, 50, 12, 3, 7, 1, 64, + 74,243, 51, 51, 51, 51, 52, 49, 12, 3, 7, 1, 64, 74,102,102,102,102,102, + 103, 48, 12, 3, 7, 1, 64, 73,217,153,153,153,153,154, 47, 12, 3, 7, 1, + 64, 73, 76,204,204,204,204,205, 46, 12, 3, 7, 1, 64, 72,192, 0, 0, 0, + 0, 1, 45, 12, 3, 7, 1, 64, 72, 51, 51, 51, 51, 51, 52, 44, 12, 3, 7, + 1, 64, 71,166,102,102,102,102,103, 43, 12, 3, 7, 1, 64, 71, 25,153,153, + 153,153,154, 42, 12, 3, 7, 1, 64, 70,140,204,204,204,204,205, 41, 5, 3, + 1, 1, 44, 40, 12, 3, 7, 1, 64, 69,115, 51, 51, 51, 51, 52, 39, 12, 3, + 7, 1, 64, 68,230,102,102,102,102,103, 38, 12, 3, 7, 1, 64, 68, 89,153, + 153,153,153,154, 37, 12, 3, 7, 1, 64, 67,204,204,204,204,204,205, 36, 10, + 0, 0, 0, 41, 0,103, 0, 1,250, 1,235, 1,227, 1,218, 1,211, 1,202, + 1,192, 1,179, 1,172, 1,157, 1,149, 1,141, 1,132, 1,125, 1,116, 1, + 106, 1, 93, 1, 86, 1, 74, 1, 63, 1, 47, 1, 40, 1, 31, 1, 16, 1, 8, + 0,255, 0,248, 0,239, 0,229, 0,216, 0,209, 0,197, 0,186, 0,174, 0, + 158, 0,151, 0,136, 0,128, 0,119, 0,112, 0,103, 0, 93, 0, 0, 0, 0, + 10, 55, 44, 78, 85, 76, 76, 8, 2, 25, 52, 54, 44, 51, 46, 53, 6, 2, 21, + 52, 53, 44, 50, 8, 2, 25, 52, 52, 44, 48, 46, 48, 7, 2, 23, 52, 51, 44, + 49, 53, 14, 2, 37, 52, 50, 44, 88, 39, 53, 53, 54, 54, 55, 55, 39, 6, 2, + 21, 52, 49, 44, 52, 15, 2, 39, 52, 48, 44, 50, 49, 52, 55, 52, 56, 51, 54, + 52, 56, 11, 2, 31, 52, 44, 39, 98,117, 98, 98, 97, 39, 10, 2, 29, 51, 57, + 44, 39,120,121,122, 39, 11, 2, 31, 51, 56, 44, 39,102,111,117,114, 39, 6, + 2, 21, 51, 55, 44, 51, 12, 2, 33, 51, 54, 44, 39, 98,117, 98, 98, 97, 39, + 9, 2, 27, 51, 53, 44, 78, 85, 76, 76, 8, 2, 25, 51, 52, 44, 51, 46, 53, + 6, 2, 21, 51, 51, 44, 50, 8, 2, 25, 51, 50, 44, 48, 46, 48, 7, 2, 23, + 51, 49, 44, 49, 53, 14, 2, 37, 51, 48, 44, 88, 39, 53, 53, 54, 54, 55, 55, + 39, 8, 2, 25, 51, 44, 78, 85, 76, 76, 6, 2, 21, 50, 57, 44, 52, 15, 2, + 39, 50, 56, 44, 50, 49, 52, 55, 52, 56, 51, 54, 52, 56, 10, 2, 29, 50, 55, + 44, 39,120,121,122, 39, 11, 2, 31, 50, 54, 44, 39,102,111,117,114, 39, 6, + 2, 21, 50, 53, 44, 51, 12, 2, 33, 50, 52, 44, 39, 98,117, 98, 98, 97, 39, + 9, 2, 27, 50, 51, 44, 78, 85, 76, 76, 8, 2, 25, 50, 50, 44, 51, 46, 53, + 6, 2, 21, 50, 49, 44, 50, 8, 2, 25, 50, 48, 44, 48, 46, 48, 7, 2, 23, + 50, 44, 51, 46, 53, 7, 2, 23, 49, 57, 44, 49, 53, 14, 2, 37, 49, 56, 44, + 88, 39, 53, 53, 54, 54, 55, 55, 39, 6, 2, 21, 49, 55, 44, 52, 12, 2, 33, + 49, 54, 44, 39, 98,117, 98, 98, 97, 39, 9, 2, 27, 49, 53, 44, 78, 85, 76, + 76, 8, 2, 25, 49, 52, 44, 51, 46, 53, 6, 2, 21, 49, 51, 44, 50, 8, 2, + 25, 49, 50, 44, 48, 46, 48, 7, 2, 23, 49, 49, 44, 49, 53, 14, 2, 37, 49, + 48, 44, 88, 39, 53, 53, 54, 54, 55, 55, 39, 5, 2, 19, 49, 44, 50, 10, 0, + 0, 0, 22, 1, 32, 0, 1,243, 1,236, 1,230, 1,215, 1,207, 1,198, 1, + 191, 1,182, 1,172, 1,159, 1,152, 1,140, 1,129, 1,118, 1,102, 1, 95, + 1, 80, 1, 72, 1, 63, 1, 53, 1, 38, 1, 32, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 5, 2, 19, 57, 44, 52, 14, 2, 37, 56, 44, 50, 49, 52, 55, 52, 56, 51, + 54, 52, 56, 9, 2, 27, 55, 44, 39,120,121,122, 39, 8, 2, 25, 54, 52, 44, + 48, 46, 48, 7, 2, 23, 54, 51, 44, 49, 53, 14, 2, 37, 54, 50, 44, 88, 39, + 53, 53, 54, 54, 55, 55, 39, 6, 2, 21, 54, 49, 44, 52, 15, 2, 39, 54, 48, + 44, 50, 49, 52, 55, 52, 56, 51, 54, 52, 56, 10, 2, 29, 54, 44, 39,102,111, + 117,114, 39, 10, 2, 29, 53, 57, 44, 39,120,121,122, 39, 11, 2, 31, 53, 56, + 44, 39,102,111,117,114, 39, 6, 2, 21, 53, 55, 44, 51, 12, 2, 33, 53, 54, + 44, 39, 98,117, 98, 98, 97, 39, 9, 2, 27, 53, 53, 44, 78, 85, 76, 76, 8, + 2, 25, 53, 52, 44, 51, 46, 53, 6, 2, 21, 53, 51, 44, 50, 8, 2, 25, 53, + 50, 44, 48, 46, 48, 7, 2, 23, 53, 49, 44, 49, 53, 14, 2, 37, 53, 48, 44, + 88, 39, 53, 53, 54, 54, 55, 55, 39, 5, 2, 19, 53, 44, 51, 6, 2, 21, 52, + 57, 44, 52, 12, 2, 33, 52, 56, 44, 39, 98,117, 98, 98, 97, 39, +}; + +/* Help message */ +static const char zHelp[] = + "Usage:\n" + " sessionfuzz setup -- Generate seed files c1.txt, c2.txt, etc.\n" + " sessionfuzz run FILE ... -- Run against fuzzed changeset FILE\n" + " sessionfuzz run SQLAR ... -- Run against all files in the SQL Archive\n" +; + +#include +#include +#include +#include "zlib.h" + +/* +** Implementation of the "sqlar_uncompress(X,SZ)" SQL function +** +** Parameter SZ is interpreted as an integer. If it is less than or +** equal to zero, then this function returns a copy of X. Or, if +** SZ is equal to the size of X when interpreted as a blob, also +** return a copy of X. Otherwise, decompress blob X using zlib +** utility function uncompress() and return the results (another +** blob). +*/ +static void sqlarUncompressFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + uLong nData; + uLongf sz; + + assert( argc==2 ); + sz = sqlite3_value_int(argv[1]); + + if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){ + sqlite3_result_value(context, argv[0]); + }else{ + const Bytef *pData= sqlite3_value_blob(argv[0]); + Bytef *pOut = sqlite3_malloc(sz); + if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){ + sqlite3_result_error(context, "error in uncompress()", -1); + }else{ + sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT); + } + sqlite3_free(pOut); + } +} + + +/* Run a chunk of SQL. If any errors happen, print an error message +** and exit. +*/ +static void runSql(sqlite3 *db, const char *zSql){ + int rc; + char *zErr = 0; + rc = sqlite3_exec(db, zSql, 0, 0, &zErr); + if( rc || zErr ){ + fprintf(stderr, "SQL failed: rc=%d zErr=[%s]\n", rc, zErr); + fprintf(stderr, "SQL: [%s]\n", zSql); + exit(1); + } +} + +/* +** Write buffer to disk +*/ +static void writeFile(const char *zFilename, const void *pData, int nData){ + FILE *out; + int n; + out = fopen(zFilename, "wb"); + if( out==0 ){ + fprintf(stderr, "cannot open \"%s\" for writing\n", zFilename); + exit(1); + } + n = (int)fwrite(pData, 1, nData, out); + fclose(out); + if( n!=nData ){ + fprintf(stderr, "only wrote %d of %d bytes to \"%s\"\n",n,nData,zFilename); + exit(1); + } +} + +/* +** Generate a changeset from session pSess and write it to zFile +*/ +static void makeChangeset(const char *zFile, sqlite3_session *pSess){ + void *pChg; + int nChg; + int rc; + rc = sqlite3session_changeset(pSess, &nChg, &pChg); + if( rc ){ + fprintf(stderr, "sqlite3session_changeset() returned %d\n", rc); + exit(1); + } + writeFile(zFile, pChg, nChg); + sqlite3_free(pChg); +} + +/* +** Read a file from disk. Space to hold the answer is obtained from +** sqlite3_malloc64(). +*/ +static void readFile(const char *zName, void **ppData, int *pnData){ + FILE *in = fopen(zName, "rb"); + long nIn; + size_t nRead; + char *pBuf; + *ppData = 0; + *pnData = 0; + if( in==0 ){ + fprintf(stderr, "Cannot open \"%s\" for reading\n", zName); + exit(1); + } + fseek(in, 0, SEEK_END); + nIn = ftell(in); + rewind(in); + pBuf = sqlite3_malloc64( nIn+1 ); + if( pBuf==0 ){ + fprintf(stderr, "Failed to malloc %lld bytes\n", (sqlite3_int64)(nIn+1)); + exit(1); + } + nRead = fread(pBuf, 1, nIn, in); + fclose(in); + if( nRead!=(size_t)nIn ){ + fprintf(stderr, "Read only %d of %d bytes from %s\n", (int)nRead, (int)nIn, + zName); + exit(1); + } + pBuf[nIn] = 0; + *pnData = nIn; + *ppData = pBuf; +} + +/* +** The conflict callback +*/ +static int conflictCall( + void *NotUsed, + int eConflict, + sqlite3_changeset_iter *p +){ + (void)NotUsed; + (void)p; + printf("Conflict %d\n", eConflict); + return SQLITE_CHANGESET_OMIT; +} + +/* +** Reset the database file +*/ +static void db_reset(sqlite3 *db){ + unsigned char *pData; + int nData; + int rc; + + nData = sizeof(aDbBytes); + pData = sqlite3_malloc64( nData ); + if( pData==0 ){ + fprintf(stderr, "could not allocate %d bytes\n", nData); + exit(1); + } + memcpy(pData, aDbBytes, nData); + rc = sqlite3_deserialize(db, 0, pData, nData, nData, + SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE); + if( rc ){ + fprintf(stderr, "sqlite3_deserialize() failed with %d: %s\n", + rc, sqlite3_errmsg(db)); + exit(1); + } +} + +/* +** Given a full file pathname, return a pointer to the tail. +** Example: +** +** input: /home/drh/sqlite/abc.db +** output: abc.db +*/ +static const char *fileTail(const char *z){ + const char *zOut = z; + while( z[0] ){ + if( z[0]=='/' && z[1]!=0 ) zOut = &z[1]; + z++; + } + return zOut; +} + +int main(int argc, char **argv){ + const char *zCmd; + sqlite3 *db; + int rc; + sqlite3_session *pSess; + sqlite3_stmt *pStmt; + void *pChgset; + int nChgset; + int bVerbose = 0; + + if( argc<2 ){ + fprintf(stderr, "%s", zHelp); + exit(1); + } + rc = sqlite3_open_v2(":memory:",&db, + SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "memdb"); + if( rc ){ + fprintf(stderr, "Failed to open :memory: database: %s\n", + sqlite3_errmsg(db)); + exit(1); + } + db_reset(db); + zCmd = argv[1]; + if( strcmp(zCmd, "setup")==0 ){ + if( argc!=2 ){ + fprintf(stdout, "Wrong number of arguments.\n%s", zHelp); + exit(1); + } + runSql(db, zFillSql); + rc = sqlite3session_create(db, "main", &pSess); + if( rc ){ + fprintf(stderr, "sqlite3session_create() returns %d\n", rc); + exit(1); + } + rc = sqlite3session_attach(pSess, 0); + if( rc ){ + fprintf(stderr, "sqlite3session_attach(db,0) returns %d\n", rc); + exit(1); + } + runSql(db, "INSERT INTO t4(z) VALUES('');"); + makeChangeset("c1.txt", pSess); + runSql(db, + "UPDATE t1 SET b=c, c=b WHERE a IN (5,7);\n" + "DELETE FROM t2 WHERE rowid IN (8,2);\n" + "INSERT OR IGNORE INTO t4 SELECT b FROM t1 WHERE b IS TRUE LIMIT 2;"); + makeChangeset("c2.txt", pSess); + runSql(db, "UPDATE t3 SET x=y, y=NULL WHERE rowid IN (1,3);"); + makeChangeset("c3.txt", pSess); + sqlite3session_delete(pSess); + }else + if( strcmp(zCmd, "run")==0 ){ + int i; + if( argc<3 ){ + fprintf(stdout, "Wrong number of arguments.\n%s", zHelp); + exit(1); + } + for(i=2; i= 512 + && memcmp(pChgset, "SQLite format 3", 16)==0 + ){ + sqlite3 *db2; + sqlite3_stmt *pStmt2; + int nCase = 0; + /* This file is an SQL Archive containing many changesets */ + if( !bVerbose ){ printf("%s: ", fileTail(argv[i])); fflush(stdout); } + sqlite3_open_v2(":memory:", &db2, + SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE, "memdb"); + sqlite3_deserialize(db2, 0, pChgset, nChgset, nChgset, + SQLITE_DESERIALIZE_READONLY | SQLITE_DESERIALIZE_FREEONCLOSE); + sqlite3_create_function(db2, "sqlar_uncompress", 2, SQLITE_UTF8, 0, + sqlarUncompressFunc, 0, 0); + rc = sqlite3_prepare_v2(db2, "SELECT name, sqlar_uncompress(data,sz)" + " FROM sqlar", -1, &pStmt2, 0); + if( rc ){ + fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db2)); + exit(1); + } + while( SQLITE_ROW==sqlite3_step(pStmt2) ){ + if( bVerbose ){ + printf("%s/%s:", fileTail(argv[i]), sqlite3_column_text(pStmt2,0)); + fflush(stdout); + } + runSql(db, "BEGIN"); + pChgset = (unsigned char*)sqlite3_column_blob(pStmt2, 1); + nChgset = sqlite3_column_bytes(pStmt2, 1); + rc = sqlite3changeset_apply(db, nChgset, pChgset, 0, conflictCall, 0); + if( bVerbose ){ + printf(" Ok. rc=%d\n", rc); + fflush(stdout); + } + runSql(db, "ROLLBACK"); + nCase++; + } + sqlite3_finalize(pStmt2); + sqlite3_close(db2); + if( bVerbose ) printf("%s: ", fileTail(argv[i])); + printf(" %d cases, 0 crashes\n", nCase); + fflush(stdout); + }else{ + /* The named file is just an ordinary changeset */ + printf("%s:", fileTail(argv[i])); + fflush(stdout); + runSql(db, "BEGIN"); + rc = sqlite3changeset_apply(db, nChgset, pChgset, 0, conflictCall, 0); + printf(" %d\n", rc); + fflush(stdout); + runSql(db, "ROLLBACK"); + sqlite3_free(pChgset); + } + } + }else + { + fprintf(stderr, "%s", zHelp); + exit(1); + } + rc = sqlite3_prepare_v2(db, "PRAGMA integrity_check;", -1, &pStmt, 0); + if( rc ){ + fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); + exit(1); + } + if( sqlite3_step(pStmt)!=SQLITE_ROW + || strcmp((const char*)sqlite3_column_text(pStmt,0),"ok")!=0 + ){ + fprintf(stderr, "Integrity check failed!\n"); + do{ + fprintf(stderr, "%s\n", sqlite3_column_text(pStmt,0)); + }while( sqlite3_step(pStmt)==SQLITE_ROW ); + } + sqlite3_finalize(pStmt); + sqlite3_close(db); + if( sqlite3_memory_used()>0 ){ + fprintf(stderr, "memory leak of %lld bytes\n", + sqlite3_memory_used()); + exit(1); + } + return 0; +} diff --git a/test/speed4p.test b/test/speed4p.test index 024232e1b8..78ff9138db 100644 --- a/test/speed4p.test +++ b/test/speed4p.test @@ -168,7 +168,6 @@ speed_trial_tcl speed4p-subselect1 10000 stmt $script set script { db eval BEGIN for {set ii 1} {$ii < 10000} {incr ii} { - set v [expr {$ii*3}] db eval {UPDATE t1 SET i=i+1 WHERE rowid=$ii} } db eval COMMIT diff --git a/test/tclsqlite.test b/test/tclsqlite.test index 1b95a45a5c..fb4be3dfcb 100644 --- a/test/tclsqlite.test +++ b/test/tclsqlite.test @@ -22,19 +22,19 @@ source $testdir/tester.tcl # Check the error messages generated by tclsqlite # -set r "sqlite_orig HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" +set r "sqlite_orig HANDLE ?FILENAME? ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?" if {[sqlite3 -has-codec]} { append r " ?-key CODECKEY?" } do_test tcl-1.1 { - set v [catch {sqlite3 bogus} msg] + set v [catch {sqlite3 -bogus} msg] regsub {really_sqlite3} $msg {sqlite3} msg lappend v $msg } [list 1 "wrong # args: should be \"$r\""] do_test tcl-1.2 { set v [catch {db bogus} msg] lappend v $msg -} {1 {bad option "bogus": must be authorizer, backup, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, preupdate, profile, progress, rekey, restore, rollback_hook, status, timeout, total_changes, trace, trace_v2, transaction, unlock_notify, update_hook, version, or wal_hook}} +} {1 {bad option "bogus": must be authorizer, backup, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, deserialize, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, preupdate, profile, progress, rekey, restore, rollback_hook, serialize, status, timeout, total_changes, trace, trace_v2, transaction, unlock_notify, update_hook, version, or wal_hook}} do_test tcl-1.2.1 { set v [catch {db cache bogus} msg] lappend v $msg diff --git a/test/thread001.test b/test/thread001.test index a796c57b4a..7f21fb0738 100644 --- a/test/thread001.test +++ b/test/thread001.test @@ -141,5 +141,6 @@ foreach {tn same_db shared_cache} [list \ } sqlite3_enable_shared_cache $::enable_shared_cache +catch { db close } set sqlite_open_file_count 0 finish_test diff --git a/test/trace3.test b/test/trace3.test index 271009a3fc..a2f7c3f3a1 100644 --- a/test/trace3.test +++ b/test/trace3.test @@ -121,6 +121,27 @@ do_test trace3-4.2 { set ::stmtlist(record) } {/^\{-?\d+ -?\d+\}$/} +do_test trace3-4.3 { + set ::stmtlist(record) {} + db trace_v2 trace_v2_record profile + execsql { + SELECT a, b FROM t1 ORDER BY a; + } + set stmt [lindex [lindex $::stmtlist(record) 0] 0] + set ns [lindex [lindex $::stmtlist(record) 0] 1] + list $stmt [expr {$ns >= 0 && $ns <= 1000000}]; # less than 0.001 second +} {/^-?\d+ 1$/} +do_test trace3-4.4 { + set ::stmtlist(record) {} + db trace_v2 trace_v2_record 2 + execsql { + SELECT a, b FROM t1 ORDER BY a; + } + set stmt [lindex [lindex $::stmtlist(record) 0] 0] + set ns [lindex [lindex $::stmtlist(record) 0] 1] + list $stmt [expr {$ns >= 0 && $ns <= 1000000}]; # less than 0.001 second +} {/^-?\d+ 1$/} + do_test trace3-5.1 { set ::stmtlist(record) {} db trace_v2 trace_v2_record row diff --git a/test/zipfile.test b/test/zipfile.test index 2bb3f07892..c23e120f77 100644 --- a/test/zipfile.test +++ b/test/zipfile.test @@ -150,19 +150,19 @@ do_execsql_test 1.0 { do_catchsql_test 1.1.0.1 { INSERT INTO zz(name, mode, mtime, sz, rawdata, method) VALUES('f.txt', '-rw-r--r--', 1000000000, 5, 'abcde', 0); -} {1 {constraint failed}} +} {1 {rawdata must be NULL}} do_catchsql_test 1.1.0.2 { INSERT INTO zz(name, mtime, sz, data, method) VALUES('g.txt', 1000000002, 5, '12345', 0); -} {1 {constraint failed}} +} {1 {sz must be NULL}} do_catchsql_test 1.1.0.3 { INSERT INTO zz(name, mtime, rawdata, method) VALUES('g.txt', 1000000002, '12345', 0); -} {1 {constraint failed}} +} {1 {rawdata must be NULL}} do_catchsql_test 1.1.0.4 { INSERT INTO zz(name, data, method) VALUES('g.txt', '12345', 7); -} {1 {constraint failed}} +} {1 {unknown compression method: 7}} do_execsql_test 1.1.1 { INSERT INTO zz(name, mode, mtime, data, method) @@ -287,7 +287,7 @@ do_execsql_test 1.6.6 { do_catchsql_test 1.6.7 { UPDATE zz SET data=NULL WHERE name='i.txt' -} {1 {constraint failed}} +} {1 {zipfile: mode does not match data}} do_execsql_test 1.6.8 { SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { @@ -398,13 +398,13 @@ foreach {tn fname} { } { do_catchsql_test 3.1.$tn.0 { INSERT INTO x1(name, data) VALUES($fname, NULL); - } {1 {constraint failed}} + } [list 1 "duplicate name: \"$fname/\""] do_catchsql_test 3.1.$tn.1 { INSERT INTO x1(name, data) VALUES($fname || '/', NULL); - } {1 {constraint failed}} + } [list 1 "duplicate name: \"$fname/\""] do_catchsql_test 3.1.$tn.2 { INSERT INTO x1(name, data) VALUES($fname, 'abcd'); - } {1 {constraint failed}} + } [list 1 "duplicate name: \"$fname\""] } do_catchsql_test 3.2 { @@ -515,6 +515,14 @@ ifcapable datetime { test_unzip/c.txt 1111111000 }] + # fsdir() issue reported on the mailing list on 2018-03-14 by Jack Thaw. + do_test 6.0b { + db eval { + SELECT sum(name LIKE '%/a.txt') + FROM (VALUES(1),(2),(3)) CROSS JOIN fsdir('test_unzip') + } + } {3} + do_execsql_test 6.1 { SELECT name, mtime, data FROM zipfile('test1.zip') } { @@ -636,5 +644,35 @@ do_execsql_test 9.0 { ) SELECT name FROM zipfile((SELECT zipfile(nm, NULL) FROM src)) } {dir1/ dir2/ dir3/ dir4/ /} -finish_test +#------------------------------------------------------------------------- +# INSERT OR REPLACE and INSERT OR IGNORE +# +catch {db close} +forcedelete test.zip test.db +sqlite3 db :memory: +load_static_extension db zipfile +do_execsql_test 10.0 { + CREATE VIRTUAL TABLE z USING zipfile('test.zip'); +} {} +do_catchsql_test 10.1 { + INSERT INTO z(name,data) VALUES('a0','one'),('a0','two'); +} {1 {duplicate name: "a0"}} +do_execsql_test 10.2 { + SELECT name, data FROM z; +} {a0 one} +do_execsql_test 10.3 { + REPLACE INTO z(name,data) VALUES('a0','three'),('a0','four'); +} {} +do_execsql_test 10.4 { + SELECT name, data FROM z; +} {a0 four} +do_execsql_test 10.5 { + INSERT OR IGNORE INTO z(name,data) VALUES('a0','five'),('a0','six'); +} {} +do_execsql_test 10.6 { + SELECT name, data FROM z; +} {a0 four} + + +finish_test diff --git a/test/zipfilefault.test b/test/zipfilefault.test index 158370695e..f5e2cd5cb6 100644 --- a/test/zipfilefault.test +++ b/test/zipfilefault.test @@ -47,13 +47,15 @@ do_faultsim_test 2.1 -faults oom* -body { } -test { faultsim_test_result {0 {a.txt 1234567890}} } -do_faultsim_test 2.2 -faults oom* -body { - execsql { - SELECT json_extract( zipfile_cds(z), '$.version-made-by' ) - FROM zipfile('test.zip') +ifcapable json1 { + do_faultsim_test 2.2 -faults oom* -body { + execsql { + SELECT json_extract( zipfile_cds(z), '$.version-made-by' ) + FROM zipfile('test.zip') + } + } -test { + faultsim_test_result {0 798} } -} -test { - faultsim_test_result {0 798} } forcedelete test.zip @@ -162,4 +164,3 @@ do_faultsim_test 7.0 -faults oom* -prep { finish_test - diff --git a/tool/mkopts.tcl b/tool/mkopts.tcl index e3ddcb9eeb..88f645bbe3 100644 --- a/tool/mkopts.tcl +++ b/tool/mkopts.tcl @@ -11,7 +11,7 @@ while {![eof stdin]} { if {$line==""} continue regsub -all "\[ \t\n,\]+" [string trim $line] { } line foreach token [split $line { }] { - if {![regexp {(([a-zA-Z]+)_)?([_a-zA-Z]+)} $token all px p2 name]} continue + if {![regexp {(([a-zA-Z]+)_)?([_a-zA-Z0-9]+)} $token all px p2 name]} continue lappend namelist [string tolower $name] if {$px!=""} {set prefix $p2} } @@ -23,7 +23,7 @@ proc put_item x { global col if {$col==0} {puts -nonewline " "} if {$col<2} { - puts -nonewline [format " %-21s" $x] + puts -nonewline [format " %-25s" $x] incr col } else { puts $x diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index 8ea3e81c91..f2d93aadd0 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -320,6 +320,7 @@ foreach file { os_unix.c os_win.c + memdb.c bitvec.c pcache.c