From ac442f41c134b1242baf488cd53ff57e64deb448 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 01:28:46 +0000 Subject: [PATCH 01/67] Add support for the "memdb" VFS and the sqlite3_memdb_ptr() and sqlite3_memdb_config() interfaces, to enable an SQLite database to be manipulated as an in-memory object. FossilOrigin-Name: fb2ac2d2fa6374084f3325b41b257c7a3ace43aade4b666ec4be93b6b70dc39a --- Makefile.in | 6 +- Makefile.msc | 6 +- main.mk | 3 +- manifest | 35 ++-- manifest.uuid | 2 +- src/main.c | 7 +- src/memdb.c | 497 ++++++++++++++++++++++++++++++++++++++++++++ src/pager.c | 6 +- src/sqlite.h.in | 40 ++++ src/sqliteInt.h | 4 + src/tclsqlite.c | 77 +++++-- src/test_config.c | 6 + test/memdb1.test | 57 +++++ tool/mksqlite3c.tcl | 1 + 14 files changed, 710 insertions(+), 37 deletions(-) create mode 100644 src/memdb.c create mode 100644 test/memdb1.test diff --git a/Makefile.in b/Makefile.in index e3dfb01baa..0b326ebd59 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 \ @@ -824,6 +825,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 diff --git a/Makefile.msc b/Makefile.msc index 2f038ab1c1..35eb97261d 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1101,7 +1101,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 \ @@ -1174,6 +1174,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 \ @@ -1807,6 +1808,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\memjournal.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 diff --git a/main.mk b/main.mk index 85588cd01a..4e13c3e608 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 \ diff --git a/manifest b/manifest index 774549626b..f282ff78d7 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Fix\scode\sindentation.\s\sNo\slogic\schanges. -D 2018-01-02T21:29:42.540 -F Makefile.in 1b11037c5ed3399a79433cc82c59b5e36a7b3a3e4e195bb27640d0d2145e03e1 +C Add\ssupport\sfor\sthe\s"memdb"\sVFS\sand\sthe\ssqlite3_memdb_ptr()\sand\nsqlite3_memdb_config()\sinterfaces,\sto\senable\san\sSQLite\sdatabase\sto\sbe\nmanipulated\sas\san\sin-memory\sobject. +D 2018-01-03T01:28:46.871 +F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc f68b4f9b83cfeb057b6265e0288ad653f319e2ceacca731e0f22e19617829a89 +F Makefile.msc bddc04c05f1ab348be051da17827b123fa004005c9ee47489eaf3a2759dcdc45 F README.md eeae1e552f93ef72ef7c5b8f6647b368a001c28820ad1df179d3dae602bef681 F VERSION 0c10cdfed866fdd2d80434f64f042c3330f1daaed12e54287beb104f04b3faaf F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -401,7 +401,7 @@ F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 59744c818d349d170ff56cdbdfb5af0e0a2029db18ce2824fcd1b0a3fa317d84 +F main.mk da996649117a4563f04b046d73ce82237ff544138b252245111703f6b916fcd4 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -443,13 +443,14 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 14686083cedc198540b15a79586cdd4be2acf6d5fa97627e355f817ab07e9fee F src/legacy.c 134ab3e3fae00a0f67a5187981d6935b24b337bcf0f4b3e5c9fa5763da95bf4e F src/loadext.c 55bcc3c741059a1056859e8adaf133aa179e22be12215c0936b2f354ef71209b -F src/main.c 690c4134f944cbd5b71d59dd6e61ce4131f6a50ab774f38108e57d07d79cf876 +F src/main.c 37139a23caa1a9864b42b0e4bd6416b0d9387e8a7423ebd0ca70f32d03018f46 F src/malloc.c 6f684fd039f53bf9195193eb0cde731a2954970fabc6ef054ba379b6052dc296 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 46109bc6c890c21a802b6aad6e667c81aee53e5623e2068c6fa9ded1b9634558 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -465,7 +466,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c 7fc2735390a7809d5d893ed735d994ff12521224b89738226fff6f1a0aa1c932 F src/os_win.c 0a4afa35cc8e812000df3ea2f64b476131b39e29e75d8007d0504726e4761de4 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 9b9cb4e06c03d43d62480a7a685a012d645fcf3a39e7767ccb505fb41ee083ec +F src/pager.c ede1e65f465f6c507c876b87c3f796a7809b52bd9f82da14bac2680f5df8ebe6 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a F src/parse.y 44cbbc3e132ea128258eff7be7f6d5c5dfa25522f89ec8b5501276966511bd50 F src/pcache.c 7ae91a4557a43d77d449accbfdc68846e6516f8e2eda46e8bbe4536fb669b201 @@ -480,14 +481,14 @@ F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 8b22abe193e4d8243befa2038e4ae2405802fed1c446e5e502d11f652e09ba74 F src/shell.c.in a418ddceef7a2789f18bdc2bcdd481b2562fe4a7754b8009c8dd33d5a67da332 -F src/sqlite.h.in c597ba5d11666bb2d0179a173cd25e44f0b0333f9e18ce60b07eac8bdc3de67f +F src/sqlite.h.in 8b6cd7fd8b286d567bcc1ee3a750686cbb1c0962dc453b2cfa034684fe5808db F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34 -F src/sqliteInt.h fd8702c65994d7de3e2d8f7d85d958731da1ed29476571fdfa2290fd8ec0bf80 +F src/sqliteInt.h 2567341e37050ad542d57f3027b8717cb9b14ff363fdfeecf85421e0d973787f F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 1833388c01e3b77f4c712185ee7250b9423ee0981ce6ae7e401e47db0319a696 +F src/tclsqlite.c 45bcce558f40f245e25d1dd7c208f6845137fbee042cced2a4116f05349ffd9d F src/test1.c 8ef15f7a357f85dfc41c6c748ce9c947b4f676e01bb5ae6a45bee4923dff8b51 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -503,7 +504,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 cc8a1d44648d9392a14f4ecfc841d027daaf61f952b9f70792edf11373aaa3dd +F src/test_config.c 6b749332d98924c52d5b08d1fd847bbe8ff049fc4446af738e64e2532a804348 F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf9f8f F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e F src/test_devsym.c 1960abbb234b97e9b920f07e99503fc04b443f62bbc3c6ff2c2cea2133e3b8a2 @@ -1055,6 +1056,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 3d8ebffdc64ea1a7b4ccacd5502e61191233d979451747f4af88c9f2ee9b34c5 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1628,7 +1630,7 @@ F tool/mkshellc.tcl 574307265b49d813301fba91ccd74e6a26d33f65f74b6891c320a0ffbee0 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 @@ -1688,7 +1690,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2846458af5d029a8e4fdcc8f50873a44e57897bbfe6aee8a23a01ffc34c5579f -R 9613ba300b7bd9cce413f2672960fb05 +P e115f2583499df0c7ee991d372bed4b89aa717b10a4e4b10977864390cb4fc11 +R dd0ff0dcdd2908eb59154bae6d4e7abd +T *branch * memdb +T *sym-memdb * +T -sym-trunk * U drh -Z 9fca118926b581510cc96e0ce3702687 +Z 4f847deac1204c1b3d7c3decd276393a diff --git a/manifest.uuid b/manifest.uuid index 4bf24d86c2..1ad14f7d1d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e115f2583499df0c7ee991d372bed4b89aa717b10a4e4b10977864390cb4fc11 \ No newline at end of file +fb2ac2d2fa6374084f3325b41b257c7a3ace43aade4b666ec4be93b6b70dc39a \ No newline at end of file diff --git a/src/main.c b/src/main.c index 3c8035c120..bcede6483f 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_MEMDB + 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..7392513126 --- /dev/null +++ b/src/memdb.c @@ -0,0 +1,497 @@ +/* +** 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 is an in-memory VFS implementation. The application supplies +** a chunk of memory to hold the database file. +** +** USAGE: +** +** sqlite3_open_v2("whatever", &db, SQLITE_OPEN_READWRITE, "memdb"); +** void *sqlite3_memdb_ptr(db, "main", &sz); +** int sqlite3_memdb_config(db, "main", pMem, szData, szMem, mFlags); +** +** Flags: +** +** SQLITE_MEMDB_FREEONCLOSE Free pMem when closing the connection +** SQLITE_MEMDB_RESIZEABLE Use sqlite3_realloc64() to resize pMem +*/ +#ifdef SQLITE_ENABLE_MEMDB +#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); +static int memdbFileControl(sqlite3_file*, int op, void *pArg); +static int memdbSectorSize(sqlite3_file*); +static int memdbDeviceCharacteristics(sqlite3_file*); +static int memdbShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**); +static int memdbShmLock(sqlite3_file*, int offset, int n, int flags); +static void memdbShmBarrier(sqlite3_file*); +static int memdbShmUnmap(sqlite3_file*, int deleteFlag); +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 */ + memdbDelete, /* xDelete */ + memdbAccess, /* xAccess */ + memdbFullPathname, /* xFullPathname */ + memdbDlOpen, /* xDlOpen */ + memdbDlError, /* xDlError */ + memdbDlSym, /* xDlSym */ + memdbDlClose, /* xDlClose */ + memdbRandomness, /* xRandomness */ + memdbSleep, /* xSleep */ + 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 */ + memdbCheckReservedLock, /* xCheckReservedLock */ + memdbFileControl, /* xFileControl */ + memdbSectorSize, /* xSectorSize */ + memdbDeviceCharacteristics, /* xDeviceCharacteristics */ + memdbShmMap, /* xShmMap */ + memdbShmLock, /* xShmLock */ + memdbShmBarrier, /* xShmBarrier */ + memdbShmUnmap, /* 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_MEMDB_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); + 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_MEMDB_RESIZEABLE)==0 ) return SQLITE_FULL; + if( p->nMmap>0 ) return SQLITE_FULL; + pNew = sqlite3_realloc64(p->aData, newSz); + if( pNew==0 ) return SQLITE_FULL; + 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 ){ + if( iOfst+iAmt>p->szMax && memdbEnlarge(p, (iOfst+iAmt)*2) ){ + return SQLITE_FULL; + } + 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. +*/ +static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ + MemFile *p = (MemFile *)pFile; + if( size>p->sz ){ + if( size>p->szMax && memdbEnlarge(p, size) ) return SQLITE_FULL; + memset(p->aData+p->sz, 0, size-p->sz); + } + 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; +} + +/* +** 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; +} + +/* +** 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; +} + +/* +** Return the sector-size in bytes for an memdb-file. +*/ +static int memdbSectorSize(sqlite3_file *pFile){ + return 1024; +} + +/* +** 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; +} + +/* Create a shared memory file mapping */ +static int memdbShmMap( + sqlite3_file *pFile, + int iPg, + int pgsz, + int bExtend, + void volatile **pp +){ + return SQLITE_IOERR_SHMMAP; +} + +/* Perform locking on a shared-memory segment */ +static int memdbShmLock(sqlite3_file *pFile, int offset, int n, int flags){ + return SQLITE_IOERR_SHMLOCK; +} + +/* Memory barrier operation on shared memory */ +static void memdbShmBarrier(sqlite3_file *pFile){ + return; +} + +/* Unmap a shared memory segment */ +static int memdbShmUnmap(sqlite3_file *pFile, int deleteFlag){ + return SQLITE_OK; +} + +/* 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; + memset(p, 0, sizeof(*p)); + if( (flags & SQLITE_OPEN_MAIN_DB)==0 ) return SQLITE_CANTOPEN; + p->mFlags = SQLITE_MEMDB_RESIZEABLE | SQLITE_MEMDB_FREEONCLOSE; + *pOutFlags = flags | SQLITE_OPEN_MEMORY; + p->base.pMethods = &memdb_io_methods; + return SQLITE_OK; +} + +/* +** 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; +} + +/* +** Test for access permissions. Return true if the requested permission +** is available, or false otherwise. +*/ +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); +} + +/* +** 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); +} + +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 a pointer to the memory used to hold the database. +** Return NULL if the arguments do not describe a memdb database. +*/ +void *sqlite3_memdb_ptr(sqlite3 *db, const char *zSchema, sqlite3_int64 *pSz){ + MemFile *p = memdbFromDbSchema(db, zSchema); + if( p==0 ){ + *pSz = 0; + return 0; + } + *pSz = p->sz; + return p->aData; +} + +/* +** Reconfigure a memdb database. +*/ +int sqlite3_memdb_config( + sqlite3 *db, + const char *zSchema, + void *aData, + sqlite3_int64 sz, + sqlite3_int64 szMax, + unsigned int mFlags +){ + MemFile *p = memdbFromDbSchema(db, zSchema); + if( p==0 ) return SQLITE_ERROR; + if( p->eLock!=SQLITE_LOCK_NONE || p->nMmap>0 ) return SQLITE_BUSY; + if( p->mFlags & SQLITE_MEMDB_FREEONCLOSE ) sqlite3_free(p->aData); + p->aData = aData; + p->sz = sz; + p->szMax = szMax; + p->mFlags = mFlags; + return SQLITE_OK; +} + +/* +** This routine is called when the extension is loaded. +** Register the new VFS. +*/ +int sqlite3MemdbInit(void){ + memdb_vfs.pAppData = sqlite3_vfs_find(0); + memdb_vfs.szOsFile = sizeof(MemFile); + return sqlite3_vfs_register(&memdb_vfs, 0); +} +#endif /* SQLITE_ENABLE_MEMDB */ diff --git a/src/pager.c b/src/pager.c index 295cbe04c5..4f50963b22 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4694,6 +4694,7 @@ 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 */ + int memJM = 0; /* Memory journal mode */ 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 */ @@ -4821,7 +4822,8 @@ 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); + memJM = (fout&SQLITE_OPEN_MEMORY)!=0; + 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 @@ -4952,7 +4954,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; */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index a6d328360a..1434485532 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8758,6 +8758,46 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( */ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); +/* +** CAPI3REF: Retrieve the current MEMDB buffer +** EXPERIMENTAL +** +** This interface is only available when SQLite is compiled +** with SQLITE_ENABLE_MEMDB. +** +** The sqlite3_memdb_ptr(D,S,P) interface returns a pointer to the +** memory buffer that is the database file used for [database connection] D +** and schema S. If schema S of database connection D is not a MEMDB +** database, then this routine returns NULL. If P is not NULL, then it must +** be a pointer to a 64-bit signed integer into which the size of the +** database file is written. +*/ +SQLITE_EXPERIMENTAL void *sqlite3_memdb_ptr(sqlite3*,const char*,sqlite3_int64*); + +/* +** CAPI3REF: Set the current MEMDB buffer +** EXPERIMENTAL +** +** This interface is only available when SQLite is compiled +** with SQLITE_ENABLE_MEMDB. +** +** The sqlite3_memdb_config(D,S,P,N,M,F) interface initializes a MEMDB database. +** The database identified by D and S must not be in active use when this +** interface is called, or [SQLITE_BUSY] is returned. +*/ +SQLITE_EXPERIMENTAL int sqlite3_memdb_config(sqlite3*,const char*,void*,sqlite3_int64,sqlite3_int64,unsigned); + +/* +** CAPI3REF: Flags for configuring MEMDB databases +** EXPERIMENTAL +** +** The following are allowed values for the 6th argument (the "flags" +** argument) of the [sqlite3_memdb_config()] interface. +*/ +#define SQLITE_MEMDB_FREEONCLOSE 0x001 /* Free the memory buffer on close */ +#define SQLITE_MEMDB_RESIZEABLE 0x002 /* Resize using sqlite3_realloc64() */ + + /* ** 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 8e79133200..002fb4e916 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4019,6 +4019,10 @@ int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); const char *sqlite3ErrName(int); #endif +#ifdef SQLITE_ENABLE_MEMDB +int sqlite3MemdbInit(void); +#endif + const char *sqlite3ErrStr(int); int sqlite3ReadSchema(Parse *pParse); CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); diff --git a/src/tclsqlite.c b/src/tclsqlite.c index eed86eee34..0e86d727b3 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1852,14 +1852,13 @@ static int SQLITE_TCLAPI DbObjCmd( "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 + "last_insert_rowid", "memdb", "nullvalue", + "onecolumn", "preupdate", "profile", + "progress", "rekey", "restore", + "rollback_hook", "status", "timeout", + "total_changes", "trace", "trace_v", + "transaction", "unlock_notify", "update_hook", + "version", "wal_hook", 0 }; enum DB_enum { DB_AUTHORIZER, DB_BACKUP, DB_BUSY, @@ -1868,13 +1867,13 @@ static int SQLITE_TCLAPI DbObjCmd( 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_LAST_INSERT_ROWID, DB_MEMDB, 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 }; /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ @@ -2667,6 +2666,54 @@ static int SQLITE_TCLAPI DbObjCmd( break; } + /* + ** $db memdb DATABASE ?BLOB? + ** + ** Set or query the content of a MEMDB database. + ** + */ + case DB_MEMDB: { +#ifndef SQLITE_ENABLE_MEMDB + Tcl_AppendResult(interp, "MEMDB not available in this build", + (char*)0); + rc = TCL_ERROR; +#else + const char *zSchema = Tcl_GetString(objv[2]); + sqlite3_int64 sz = 0; + unsigned char *pData; + if( objc==3 ){ + pData = sqlite3_memdb_ptr(pDb->db, zSchema, &sz); + if( pData==0 ){ + Tcl_AppendResult(interp, "not a MEMDB database", (char*)0); + rc = TCL_ERROR; + }else{ + Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pData,sz)); + } + }else if( objc==4 ){ + int len = 0, xrc; + unsigned char *pBA = Tcl_GetByteArrayFromObj(objv[3], &len); + pData = sqlite3_malloc64( len ); + if( pData==0 ){ + Tcl_AppendResult(interp, "out of memory", (char*)0); + rc = TCL_ERROR; + }else{ + memcpy(pData, pBA, len); + xrc = sqlite3_memdb_config(pDb->db, zSchema, pData, len, len, + SQLITE_MEMDB_FREEONCLOSE|SQLITE_MEMDB_RESIZEABLE); + if( xrc ){ + sqlite3_free(pData); + Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0); + rc = TCL_ERROR; + } + } + }else{ + Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); + rc = TCL_ERROR; + } +#endif + break; + } + /* ** $db nullvalue ?STRING? ** diff --git a/src/test_config.c b/src/test_config.c index ad63016baf..aeb3393f0b 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_MEMDB + Tcl_SetVar2(interp, "sqlite_options", "memdb", "1", TCL_GLOBAL_ONLY); +#else + Tcl_SetVar2(interp, "sqlite_options", "memdb", "0", TCL_GLOBAL_ONLY); +#endif + #ifdef SQLITE_ENABLE_MEMSYS3 Tcl_SetVar2(interp, "sqlite_options", "mem3", "1", TCL_GLOBAL_ONLY); #else diff --git a/test/memdb1.test b/test/memdb1.test new file mode 100644 index 0000000000..2be9cf62c5 --- /dev/null +++ b/test/memdb1.test @@ -0,0 +1,57 @@ +# 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 !memdb { + 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. +# +db close +sqlite3 db dummy -vfs memdb +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 memdb main] + expr {[string length $::db1]==$::sz1} +} 1 + +# Create a new MEMDB and initialize it to the content of $::db1 +# Verify that the content is the same. +# +db close +sqlite3 db dummy2 -vfs memdb +db memdb main $db1 +do_execsql_test 110 { + SELECT * FROM t1; +} {1 2} + + +finish_test 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 From 7de2c3e5eee332de01158b6f99bb71af86e28de5 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 3 Jan 2018 12:39:35 +0000 Subject: [PATCH 02/67] Fix typo in the Makefile for MSVC. FossilOrigin-Name: e5c6ade8ee596eaffd98d1d7ce9c7c968cd2d45f206603b894026e7ad7ac15b6 --- Makefile.msc | 2 +- manifest | 17 +++++++---------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 35eb97261d..b063b1226f 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1808,7 +1808,7 @@ 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\memjournal.c $(HDR) +memdb.lo: $(TOP)\src\memdb.c $(HDR) $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\memdb.c memjournal.lo: $(TOP)\src\memjournal.c $(HDR) diff --git a/manifest b/manifest index f282ff78d7..375e1b52c1 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Add\ssupport\sfor\sthe\s"memdb"\sVFS\sand\sthe\ssqlite3_memdb_ptr()\sand\nsqlite3_memdb_config()\sinterfaces,\sto\senable\san\sSQLite\sdatabase\sto\sbe\nmanipulated\sas\san\sin-memory\sobject. -D 2018-01-03T01:28:46.871 +C Fix\stypo\sin\sthe\sMakefile\sfor\sMSVC. +D 2018-01-03T12:39:35.460 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc bddc04c05f1ab348be051da17827b123fa004005c9ee47489eaf3a2759dcdc45 +F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 F README.md eeae1e552f93ef72ef7c5b8f6647b368a001c28820ad1df179d3dae602bef681 F VERSION 0c10cdfed866fdd2d80434f64f042c3330f1daaed12e54287beb104f04b3faaf F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1690,10 +1690,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 e115f2583499df0c7ee991d372bed4b89aa717b10a4e4b10977864390cb4fc11 -R dd0ff0dcdd2908eb59154bae6d4e7abd -T *branch * memdb -T *sym-memdb * -T -sym-trunk * -U drh -Z 4f847deac1204c1b3d7c3decd276393a +P fb2ac2d2fa6374084f3325b41b257c7a3ace43aade4b666ec4be93b6b70dc39a +R 025ad5693b1eb347e4b6ac2d4f7892d8 +U mistachkin +Z 11bcd34cb283c66a6b2991d9a37cef7f diff --git a/manifest.uuid b/manifest.uuid index 1ad14f7d1d..624e8aa98f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fb2ac2d2fa6374084f3325b41b257c7a3ace43aade4b666ec4be93b6b70dc39a \ No newline at end of file +e5c6ade8ee596eaffd98d1d7ce9c7c968cd2d45f206603b894026e7ad7ac15b6 \ No newline at end of file From 4dcac40e3d4cf02513c84c95ccd4198ef35f2320 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 13:20:02 +0000 Subject: [PATCH 03/67] Simplify the "sqlite3" command in the TCL interface. The filename is now optional. There is a new --memdb option with an argument that is the blob to which the database content should be initialized. FossilOrigin-Name: 47398ae77236a92f6b9345aa397361b6df127a9a2895c0771d506b0be10822b9 --- manifest | 20 +++++----- manifest.uuid | 2 +- src/memdb.c | 23 ++++++++---- src/tclsqlite.c | 89 ++++++++++++++++++++++++++++++++------------- test/memdb1.test | 3 +- test/tclsqlite.test | 6 +-- 6 files changed, 94 insertions(+), 49 deletions(-) diff --git a/manifest b/manifest index 375e1b52c1..9d5dca5c2b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypo\sin\sthe\sMakefile\sfor\sMSVC. -D 2018-01-03T12:39:35.460 +C Simplify\sthe\s"sqlite3"\scommand\sin\sthe\sTCL\sinterface.\s\sThe\sfilename\sis\snow\noptional.\s\sThere\sis\sa\snew\s--memdb\soption\swith\san\sargument\sthat\sis\sthe\sblob\nto\swhich\sthe\sdatabase\scontent\sshould\sbe\sinitialized. +D 2018-01-03T13:20:02.897 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 @@ -450,7 +450,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c 46109bc6c890c21a802b6aad6e667c81aee53e5623e2068c6fa9ded1b9634558 +F src/memdb.c 13c69aee0185614a25303e2be3802b73416e655e95e1f1c607a9f963b35a1def F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -488,7 +488,7 @@ F src/sqliteInt.h 2567341e37050ad542d57f3027b8717cb9b14ff363fdfeecf85421e0d97378 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 45bcce558f40f245e25d1dd7c208f6845137fbee042cced2a4116f05349ffd9d +F src/tclsqlite.c 907133153d3194ddfd728e84f55fa106de696dc644c9508a054c72b9f833972e F src/test1.c 8ef15f7a357f85dfc41c6c748ce9c947b4f676e01bb5ae6a45bee4923dff8b51 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -1056,7 +1056,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 3d8ebffdc64ea1a7b4ccacd5502e61191233d979451747f4af88c9f2ee9b34c5 +F test/memdb1.test 1d94a4bf153201f16a0a755a5a0a5d7f33b001c972e3086acb1f76ad3fb7e0e5 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1282,7 +1282,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 45462ee8dd0ca4fd95a476c9253d332ce2cf90985cb0ad5c7eae6e8c7fe24ae8 F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/tempdb2.test 27e41ed540b2f9b056c2e77e9bddc1b875358507 F test/tempfault.test 0c0d349c9a99bf5f374655742577f8712c647900 @@ -1690,7 +1690,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 fb2ac2d2fa6374084f3325b41b257c7a3ace43aade4b666ec4be93b6b70dc39a -R 025ad5693b1eb347e4b6ac2d4f7892d8 -U mistachkin -Z 11bcd34cb283c66a6b2991d9a37cef7f +P e5c6ade8ee596eaffd98d1d7ce9c7c968cd2d45f206603b894026e7ad7ac15b6 +R 66054801a2fc399d3dc7a916643e1819 +U drh +Z 2a01cfd70faa22757159c69df08c3c76 diff --git a/manifest.uuid b/manifest.uuid index 624e8aa98f..2905c1c5a6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e5c6ade8ee596eaffd98d1d7ce9c7c968cd2d45f206603b894026e7ad7ac15b6 \ No newline at end of file +47398ae77236a92f6b9345aa397361b6df127a9a2895c0771d506b0be10822b9 \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 7392513126..215bfbb24a 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -475,13 +475,22 @@ int sqlite3_memdb_config( unsigned int mFlags ){ MemFile *p = memdbFromDbSchema(db, zSchema); - if( p==0 ) return SQLITE_ERROR; - if( p->eLock!=SQLITE_LOCK_NONE || p->nMmap>0 ) return SQLITE_BUSY; - if( p->mFlags & SQLITE_MEMDB_FREEONCLOSE ) sqlite3_free(p->aData); - p->aData = aData; - p->sz = sz; - p->szMax = szMax; - p->mFlags = mFlags; + int rc; + if( p==0 ){ + rc = SQLITE_ERROR; + }else if( p->eLock!=SQLITE_LOCK_NONE || p->nMmap>0 ){ + rc = SQLITE_BUSY; + }else{ + if( p->mFlags & SQLITE_MEMDB_FREEONCLOSE ) sqlite3_free(p->aData); + p->aData = aData; + p->sz = sz; + p->szMax = szMax; + p->mFlags = mFlags; + rc = SQLITE_OK; + } + if( rc!=SQLITE_OK && (mFlags & SQLITE_MEMDB_FREEONCLOSE)!=0 ){ + sqlite3_free(aData); + } return SQLITE_OK; } diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 0e86d727b3..d02d94baf5 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1856,7 +1856,7 @@ static int SQLITE_TCLAPI DbObjCmd( "onecolumn", "preupdate", "profile", "progress", "rekey", "restore", "rollback_hook", "status", "timeout", - "total_changes", "trace", "trace_v", + "total_changes", "trace", "trace_v2", "transaction", "unlock_notify", "update_hook", "version", "wal_hook", 0 }; @@ -2701,7 +2701,6 @@ static int SQLITE_TCLAPI DbObjCmd( xrc = sqlite3_memdb_config(pDb->db, zSchema, pData, len, len, SQLITE_MEMDB_FREEONCLOSE|SQLITE_MEMDB_RESIZEABLE); if( xrc ){ - sqlite3_free(pData); Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0); rc = TCL_ERROR; } @@ -3394,6 +3393,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? @@ -3419,7 +3436,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; @@ -3428,9 +3445,12 @@ static int SQLITE_TCLAPI DbMain( int nKey = 0; #endif int rc; +#ifdef SQLITE_ENABLE_MEMDB + Tcl_Obj *pDbObj = 0; +#endif /* 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. @@ -3459,18 +3479,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); +#ifdef SQLITE_ENABLE_MEMDB + if( pDbObj ){ + rc = sqlite3_open_v2("x", &p->db, flags, "memdb"); + if( rc==SQLITE_OK ){ + int len; + unsigned char *aData = Tcl_GetByteArrayFromObj(pDbObj, &len); + unsigned char *a = sqlite3_malloc64( len ); + memcpy(a, aData, len); + sqlite3_memdb_config(p->db, "main", a, len, sqlite3_msize(a), + SQLITE_MEMDB_FREEONCLOSE | SQLITE_MEMDB_RESIZEABLE); + } + }else +#endif + { + if( zFile==0 ) zFile = ":memory:"; + zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); + rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs); + Tcl_DStringFree(&translatedFilename); + } if( p->db ){ if( SQLITE_OK!=sqlite3_errcode(p->db) ){ zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); diff --git a/test/memdb1.test b/test/memdb1.test index 2be9cf62c5..13ef57ace4 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -47,8 +47,7 @@ do_test 100 { # Verify that the content is the same. # db close -sqlite3 db dummy2 -vfs memdb -db memdb main $db1 +sqlite3 db -memdb $db1 do_execsql_test 110 { SELECT * FROM t1; } {1 2} diff --git a/test/tclsqlite.test b/test/tclsqlite.test index 1b95a45a5c..ca53710ec2 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, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, memdb, 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}} do_test tcl-1.2.1 { set v [catch {db cache bogus} msg] lappend v $msg From cb7d541d3ae005e24bb0d36bb138d84a3ca3d415 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 16:49:52 +0000 Subject: [PATCH 04/67] Replace the sqlite3_memdb_ptr() interface with the more general sqlite3_serialize() interface. FossilOrigin-Name: 8cf2ed4eff6d2e0958656e23384b05ead2128b678b0b69a591878af4190cd077 --- manifest | 20 ++++----- manifest.uuid | 2 +- src/memdb.c | 81 ++++++++++++++++++++++++++++------ src/sqlite.h.in | 111 +++++++++++++++++++++++++++++++++++++++-------- src/tclsqlite.c | 108 ++++++++++++++++++++++++++++++--------------- test/memdb1.test | 7 +-- tool/mkopts.tcl | 4 +- 7 files changed, 250 insertions(+), 83 deletions(-) diff --git a/manifest b/manifest index 9d5dca5c2b..892a7572e4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplify\sthe\s"sqlite3"\scommand\sin\sthe\sTCL\sinterface.\s\sThe\sfilename\sis\snow\noptional.\s\sThere\sis\sa\snew\s--memdb\soption\swith\san\sargument\sthat\sis\sthe\sblob\nto\swhich\sthe\sdatabase\scontent\sshould\sbe\sinitialized. -D 2018-01-03T13:20:02.897 +C Replace\sthe\ssqlite3_memdb_ptr()\sinterface\swith\sthe\smore\sgeneral\nsqlite3_serialize()\sinterface. +D 2018-01-03T16:49:52.676 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 @@ -450,7 +450,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c 13c69aee0185614a25303e2be3802b73416e655e95e1f1c607a9f963b35a1def +F src/memdb.c 39dd9443f902759b858e598f17afc425c094b0d5f057b7ec988d224d812bd2a3 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -481,14 +481,14 @@ F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 8b22abe193e4d8243befa2038e4ae2405802fed1c446e5e502d11f652e09ba74 F src/shell.c.in a418ddceef7a2789f18bdc2bcdd481b2562fe4a7754b8009c8dd33d5a67da332 -F src/sqlite.h.in 8b6cd7fd8b286d567bcc1ee3a750686cbb1c0962dc453b2cfa034684fe5808db +F src/sqlite.h.in 16bbb15a5fc53bfd725305ec9a201a7f57df7770749aa758b33a0636946d1bb4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34 F src/sqliteInt.h 2567341e37050ad542d57f3027b8717cb9b14ff363fdfeecf85421e0d973787f F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 907133153d3194ddfd728e84f55fa106de696dc644c9508a054c72b9f833972e +F src/tclsqlite.c 322ad6b4e613aba84eee8cf6239eae668167f8b9891ca9e4aa53b78cd3aaff35 F src/test1.c 8ef15f7a357f85dfc41c6c748ce9c947b4f676e01bb5ae6a45bee4923dff8b51 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -1056,7 +1056,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 1d94a4bf153201f16a0a755a5a0a5d7f33b001c972e3086acb1f76ad3fb7e0e5 +F test/memdb1.test 062cdf3b7de2f861878e4275d3a67b80982d9f792f693418c844fade15ec7537 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1624,7 +1624,7 @@ F tool/mkkeywordhash.c 2e852ac0dfdc5af18886dc1ce7e9676d11714ae3df0a282dc7d90b3a0 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 574307265b49d813301fba91ccd74e6a26d33f65f74b6891c320a0ffbee07895 F tool/mksourceid.c d458f9004c837bee87a6382228ac20d3eae3c49ea3b0a5aace936f8b60748d3b @@ -1690,7 +1690,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 e5c6ade8ee596eaffd98d1d7ce9c7c968cd2d45f206603b894026e7ad7ac15b6 -R 66054801a2fc399d3dc7a916643e1819 +P 47398ae77236a92f6b9345aa397361b6df127a9a2895c0771d506b0be10822b9 +R bfc121db68c7d1b10b977a508d74da37 U drh -Z 2a01cfd70faa22757159c69df08c3c76 +Z 6064e9ffbc398d82aebface075258c56 diff --git a/manifest.uuid b/manifest.uuid index 2905c1c5a6..a6d77e2b7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -47398ae77236a92f6b9345aa397361b6df127a9a2895c0771d506b0be10822b9 \ No newline at end of file +8cf2ed4eff6d2e0958656e23384b05ead2128b678b0b69a591878af4190cd077 \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 215bfbb24a..0a81978cce 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -157,6 +157,7 @@ static int memdbRead( 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); @@ -449,20 +450,6 @@ static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){ return p; } -/* -** Return a pointer to the memory used to hold the database. -** Return NULL if the arguments do not describe a memdb database. -*/ -void *sqlite3_memdb_ptr(sqlite3 *db, const char *zSchema, sqlite3_int64 *pSz){ - MemFile *p = memdbFromDbSchema(db, zSchema); - if( p==0 ){ - *pSz = 0; - return 0; - } - *pSz = p->sz; - return p->aData; -} - /* ** Reconfigure a memdb database. */ @@ -494,6 +481,72 @@ int sqlite3_memdb_config( return SQLITE_OK; } +/* +** 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 = memdbFromDbSchema(db, zSchema); + int iDb = sqlite3FindDbName(db, zSchema); + Btree *pBt; + sqlite3_int64 sz; + int szPage = 0; + sqlite3_stmt *pStmt = 0; + unsigned char *pOut; + char *zSql; + int rc; + + 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; + sqlite3_step(pStmt); + 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; +} + /* ** This routine is called when the extension is loaded. ** Register the new VFS. diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 1434485532..6b6a5655b3 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8758,22 +8758,6 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( */ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); -/* -** CAPI3REF: Retrieve the current MEMDB buffer -** EXPERIMENTAL -** -** This interface is only available when SQLite is compiled -** with SQLITE_ENABLE_MEMDB. -** -** The sqlite3_memdb_ptr(D,S,P) interface returns a pointer to the -** memory buffer that is the database file used for [database connection] D -** and schema S. If schema S of database connection D is not a MEMDB -** database, then this routine returns NULL. If P is not NULL, then it must -** be a pointer to a 64-bit signed integer into which the size of the -** database file is written. -*/ -SQLITE_EXPERIMENTAL void *sqlite3_memdb_ptr(sqlite3*,const char*,sqlite3_int64*); - /* ** CAPI3REF: Set the current MEMDB buffer ** EXPERIMENTAL @@ -8785,7 +8769,7 @@ SQLITE_EXPERIMENTAL void *sqlite3_memdb_ptr(sqlite3*,const char*,sqlite3_int64*) ** The database identified by D and S must not be in active use when this ** interface is called, or [SQLITE_BUSY] is returned. */ -SQLITE_EXPERIMENTAL int sqlite3_memdb_config(sqlite3*,const char*,void*,sqlite3_int64,sqlite3_int64,unsigned); +int sqlite3_memdb_config(sqlite3*,const char*,void*,sqlite3_int64,sqlite3_int64,unsigned); /* ** CAPI3REF: Flags for configuring MEMDB databases @@ -8797,6 +8781,99 @@ SQLITE_EXPERIMENTAL int sqlite3_memdb_config(sqlite3*,const char*,void*,sqlite3_ #define SQLITE_MEMDB_FREEONCLOSE 0x001 /* Free the memory buffer on close */ #define SQLITE_MEMDB_RESIZEABLE 0x002 /* Resize using sqlite3_realloc64() */ +/* +** CAPI3REF: Serialize a database +** EXPERIMENTAL +** +** 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 contigous 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. +*/ +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 +** EXPERIMENTAL +*/ +#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ + +/* +** CAPI3REF: Set the current MEMDB buffer +** EXPERIMENTAL +** +** 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. +*/ +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() +** EXPERIMENTAL +** +** The following are allowed values for the 6th argument (the "flags" or "F" +** argument) of the [sqlite3_deserialize()] interface. +*/ +#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 diff --git a/src/tclsqlite.c b/src/tclsqlite.c index d02d94baf5..2c6e1bbe27 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1846,34 +1846,36 @@ 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", "memdb", "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", "memdb", + "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_MEMDB, 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_MEMDB, + 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 */ @@ -2411,6 +2413,16 @@ static int SQLITE_TCLAPI DbObjCmd( break; } + /* + ** $db deserialize ?DATABASE? VALUE + ** + ** Reopen DATABASE (default "main") using the content in $VALUE + */ + case DB_DESERIALIZE: { + rc = TCL_ERROR; /* TBD */ + break; + } + /* ** $db enable_load_extension BOOLEAN ** @@ -2679,17 +2691,8 @@ static int SQLITE_TCLAPI DbObjCmd( rc = TCL_ERROR; #else const char *zSchema = Tcl_GetString(objv[2]); - sqlite3_int64 sz = 0; unsigned char *pData; - if( objc==3 ){ - pData = sqlite3_memdb_ptr(pDb->db, zSchema, &sz); - if( pData==0 ){ - Tcl_AppendResult(interp, "not a MEMDB database", (char*)0); - rc = TCL_ERROR; - }else{ - Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pData,sz)); - } - }else if( objc==4 ){ + if( objc==4 ){ int len = 0, xrc; unsigned char *pBA = Tcl_GetByteArrayFromObj(objv[3], &len); pData = sqlite3_malloc64( len ); @@ -2933,6 +2936,39 @@ static int SQLITE_TCLAPI DbObjCmd( break; } + /* + ** $db serialize ?DATABASE? + ** + ** Return a serialization of a database. + */ + case DB_SERIALIZE: { +#ifndef SQLITE_ENABLE_MEMDB + 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) ** diff --git a/test/memdb1.test b/test/memdb1.test index 13ef57ace4..36184e2e4e 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -27,8 +27,6 @@ ifcapable !memdb { # Verify that the size of $::db1 is the same as the size of # the database. # -db close -sqlite3 db dummy -vfs memdb unset -nocomplain db1 unset -nocomplain sz1 unset -nocomplain pgsz @@ -39,9 +37,12 @@ do_test 100 { } set ::pgsz [db one {PRAGMA page_size}] set ::sz1 [expr {$::pgsz*[db one {PRAGMA page_count}]}] - set ::db1 [db memdb main] + 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. 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 From 3ec8665e22a6fe5cf6a2b98c04de1d350d519c8c Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 19:03:31 +0000 Subject: [PATCH 05/67] Replace sqlite3_memdb_config() with sqlite3_deserialize(). Remove the "db memdb" command from the TCL interface, replacing it with "db serialize" and "db deserialize". FossilOrigin-Name: 2f6e9df9f0c5a9e5b1acb99cfa9486850cc1822d35b0989e779a7a10f3b1f1ac --- manifest | 24 ++++---- manifest.uuid | 2 +- src/attach.c | 126 +++++++++++++++++++++++----------------- src/memdb.c | 99 ++++++++++++++++--------------- src/sqlite.h.in | 25 +------- src/sqliteInt.h | 5 +- src/tclsqlite.c | 138 ++++++++++++++++++-------------------------- test/memdb1.test | 3 +- test/tclsqlite.test | 2 +- 9 files changed, 203 insertions(+), 221 deletions(-) diff --git a/manifest b/manifest index 892a7572e4..cde71db315 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sthe\ssqlite3_memdb_ptr()\sinterface\swith\sthe\smore\sgeneral\nsqlite3_serialize()\sinterface. -D 2018-01-03T16:49:52.676 +C Replace\ssqlite3_memdb_config()\swith\ssqlite3_deserialize().\s\sRemove\sthe\n"db\smemdb"\scommand\sfrom\sthe\sTCL\sinterface,\sreplacing\sit\swith\s"db\sserialize"\nand\s"db\sdeserialize". +D 2018-01-03T19:03:31.558 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 @@ -415,7 +415,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 0d0ccf7520a201d8747ea2f02c92c26e26f801bc161f714f27b9f7630dde0421 -F src/attach.c 84c477e856b24c2b9a0983b438a707c0cf4d616cee7a425401d418e58afec24c +F src/attach.c 52c34c2fb1a8852739aca3c4ae797f02660d826d1e79c067dadac97fe3335b6c F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 @@ -450,7 +450,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c 39dd9443f902759b858e598f17afc425c094b0d5f057b7ec988d224d812bd2a3 +F src/memdb.c 67c01e51b9e515721fbb4a27375233c67a8a8e5d66bd3fa6f4f84c85de43c05e F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -481,14 +481,14 @@ F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 8b22abe193e4d8243befa2038e4ae2405802fed1c446e5e502d11f652e09ba74 F src/shell.c.in a418ddceef7a2789f18bdc2bcdd481b2562fe4a7754b8009c8dd33d5a67da332 -F src/sqlite.h.in 16bbb15a5fc53bfd725305ec9a201a7f57df7770749aa758b33a0636946d1bb4 +F src/sqlite.h.in 95a2e67c1ff46365eef3cb14e73d0b279a7435c0d0fb7e59c89cde9d4353dae2 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34 -F src/sqliteInt.h 2567341e37050ad542d57f3027b8717cb9b14ff363fdfeecf85421e0d973787f +F src/sqliteInt.h 713ee4be20beddf2f053b3ac1871c1f0d9ab54d1cc21c24a4365b560181b5d7d F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 322ad6b4e613aba84eee8cf6239eae668167f8b9891ca9e4aa53b78cd3aaff35 +F src/tclsqlite.c 8370ce15f97277304e7a17c47e18d47c1a31701fcd213eded727d09c547da2fc F src/test1.c 8ef15f7a357f85dfc41c6c748ce9c947b4f676e01bb5ae6a45bee4923dff8b51 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -1056,7 +1056,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 062cdf3b7de2f861878e4275d3a67b80982d9f792f693418c844fade15ec7537 +F test/memdb1.test 6ae9f9fe51c918bf203ee5135f88d74f6e4446b573a9c07b141356f8f5fbeaf1 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1282,7 +1282,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 45462ee8dd0ca4fd95a476c9253d332ce2cf90985cb0ad5c7eae6e8c7fe24ae8 +F test/tclsqlite.test 5337e8890b96dad1ee541b15fbeec32e6bac2fe7fa096f91089057385aadba9b F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6 F test/tempdb2.test 27e41ed540b2f9b056c2e77e9bddc1b875358507 F test/tempfault.test 0c0d349c9a99bf5f374655742577f8712c647900 @@ -1690,7 +1690,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 47398ae77236a92f6b9345aa397361b6df127a9a2895c0771d506b0be10822b9 -R bfc121db68c7d1b10b977a508d74da37 +P 8cf2ed4eff6d2e0958656e23384b05ead2128b678b0b69a591878af4190cd077 +R 752064346b8d3ad9381bcf73633be499 U drh -Z 6064e9ffbc398d82aebface075258c56 +Z 59a3fb5e3f8eae3c5ea078db9efbd371 diff --git a/manifest.uuid b/manifest.uuid index a6d77e2b7f..08b82513bb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8cf2ed4eff6d2e0958656e23384b05ead2128b678b0b69a591878af4190cd077 \ No newline at end of file +2f6e9df9f0c5a9e5b1acb99cfa9486850cc1822d35b0989e779a7a10f3b1f1ac \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index fa38e84159..151b52e7a4 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,79 @@ 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); + if( db->init.reopenMemdb ){ + /* 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]; + 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 +178,7 @@ static void attachFunc( sqlite3BtreeLeave(pNew->pBt); } pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; - pNew->zDbSName = sqlite3DbStrDup(db, zName); + if( !db->init.reopenMemdb ) pNew->zDbSName = sqlite3DbStrDup(db, zName); if( rc==SQLITE_OK && pNew->zDbSName==0 ){ rc = SQLITE_NOMEM_BKPT; } @@ -200,8 +218,8 @@ 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); diff --git a/src/memdb.c b/src/memdb.c index 0a81978cce..5a1f12dcbb 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -12,17 +12,6 @@ ** ** This is an in-memory VFS implementation. The application supplies ** a chunk of memory to hold the database file. -** -** USAGE: -** -** sqlite3_open_v2("whatever", &db, SQLITE_OPEN_READWRITE, "memdb"); -** void *sqlite3_memdb_ptr(db, "main", &sz); -** int sqlite3_memdb_config(db, "main", pMem, szData, szMem, mFlags); -** -** Flags: -** -** SQLITE_MEMDB_FREEONCLOSE Free pMem when closing the connection -** SQLITE_MEMDB_RESIZEABLE Use sqlite3_realloc64() to resize pMem */ #ifdef SQLITE_ENABLE_MEMDB #include "sqliteInt.h" @@ -141,7 +130,7 @@ static const sqlite3_io_methods memdb_io_methods = { */ static int memdbClose(sqlite3_file *pFile){ MemFile *p = (MemFile *)pFile; - if( p->mFlags & SQLITE_MEMDB_FREEONCLOSE ) sqlite3_free(p->aData); + if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData); return SQLITE_OK; } @@ -169,7 +158,7 @@ static int memdbRead( */ static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){ unsigned char *pNew; - if( (p->mFlags & SQLITE_MEMDB_RESIZEABLE)==0 ) return SQLITE_FULL; + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 ) return SQLITE_FULL; if( p->nMmap>0 ) return SQLITE_FULL; pNew = sqlite3_realloc64(p->aData, newSz); if( pNew==0 ) return SQLITE_FULL; @@ -334,7 +323,7 @@ static int memdbOpen( MemFile *p = (MemFile*)pFile; memset(p, 0, sizeof(*p)); if( (flags & SQLITE_OPEN_MAIN_DB)==0 ) return SQLITE_CANTOPEN; - p->mFlags = SQLITE_MEMDB_RESIZEABLE | SQLITE_MEMDB_FREEONCLOSE; + p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; *pOutFlags = flags | SQLITE_OPEN_MEMORY; p->base.pMethods = &memdb_io_methods; return SQLITE_OK; @@ -450,37 +439,6 @@ static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){ return p; } -/* -** Reconfigure a memdb database. -*/ -int sqlite3_memdb_config( - sqlite3 *db, - const char *zSchema, - void *aData, - sqlite3_int64 sz, - sqlite3_int64 szMax, - unsigned int mFlags -){ - MemFile *p = memdbFromDbSchema(db, zSchema); - int rc; - if( p==0 ){ - rc = SQLITE_ERROR; - }else if( p->eLock!=SQLITE_LOCK_NONE || p->nMmap>0 ){ - rc = SQLITE_BUSY; - }else{ - if( p->mFlags & SQLITE_MEMDB_FREEONCLOSE ) sqlite3_free(p->aData); - p->aData = aData; - p->sz = sz; - p->szMax = szMax; - p->mFlags = mFlags; - rc = SQLITE_OK; - } - if( rc!=SQLITE_OK && (mFlags & SQLITE_MEMDB_FREEONCLOSE)!=0 ){ - sqlite3_free(aData); - } - return SQLITE_OK; -} - /* ** Return the serialization of a database */ @@ -547,6 +505,57 @@ unsigned char *sqlite3_serialize( 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; + + 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. diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 6b6a5655b3..233a2cf60e 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8758,29 +8758,6 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( */ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); -/* -** CAPI3REF: Set the current MEMDB buffer -** EXPERIMENTAL -** -** This interface is only available when SQLite is compiled -** with SQLITE_ENABLE_MEMDB. -** -** The sqlite3_memdb_config(D,S,P,N,M,F) interface initializes a MEMDB database. -** The database identified by D and S must not be in active use when this -** interface is called, or [SQLITE_BUSY] is returned. -*/ -int sqlite3_memdb_config(sqlite3*,const char*,void*,sqlite3_int64,sqlite3_int64,unsigned); - -/* -** CAPI3REF: Flags for configuring MEMDB databases -** EXPERIMENTAL -** -** The following are allowed values for the 6th argument (the "flags" -** argument) of the [sqlite3_memdb_config()] interface. -*/ -#define SQLITE_MEMDB_FREEONCLOSE 0x001 /* Free the memory buffer on close */ -#define SQLITE_MEMDB_RESIZEABLE 0x002 /* Resize using sqlite3_realloc64() */ - /* ** CAPI3REF: Serialize a database ** EXPERIMENTAL @@ -8829,7 +8806,7 @@ unsigned char *sqlite3_serialize( #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ /* -** CAPI3REF: Set the current MEMDB buffer +** CAPI3REF: Deserialize a database ** EXPERIMENTAL ** ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 002fb4e916..35074ee81a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1365,8 +1365,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 */ + u8 orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ + u8 imposterTable : 1; /* Building an imposter table */ + u8 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 */ diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 2c6e1bbe27..c9b4ff6107 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1852,14 +1852,14 @@ static int SQLITE_TCLAPI DbObjCmd( "complete", "copy", "deserialize", "enable_load_extension", "errorcode", "eval", "exists", "function", "incrblob", - "interrupt", "last_insert_rowid", "memdb", - "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 + "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, @@ -1868,14 +1868,13 @@ static int SQLITE_TCLAPI DbObjCmd( 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_MEMDB, - 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 + 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 */ @@ -2419,7 +2418,44 @@ static int SQLITE_TCLAPI DbObjCmd( ** Reopen DATABASE (default "main") using the content in $VALUE */ case DB_DESERIALIZE: { - rc = TCL_ERROR; /* TBD */ +#ifndef SQLITE_ENABLE_MEMDB + 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 ){ + Tcl_AppendResult(interp, "out of memory", (char*)0); + rc = TCL_ERROR; + }else{ + 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; } @@ -2678,44 +2714,6 @@ static int SQLITE_TCLAPI DbObjCmd( break; } - /* - ** $db memdb DATABASE ?BLOB? - ** - ** Set or query the content of a MEMDB database. - ** - */ - case DB_MEMDB: { -#ifndef SQLITE_ENABLE_MEMDB - Tcl_AppendResult(interp, "MEMDB not available in this build", - (char*)0); - rc = TCL_ERROR; -#else - const char *zSchema = Tcl_GetString(objv[2]); - unsigned char *pData; - if( objc==4 ){ - int len = 0, xrc; - unsigned char *pBA = Tcl_GetByteArrayFromObj(objv[3], &len); - pData = sqlite3_malloc64( len ); - if( pData==0 ){ - Tcl_AppendResult(interp, "out of memory", (char*)0); - rc = TCL_ERROR; - }else{ - memcpy(pData, pBA, len); - xrc = sqlite3_memdb_config(pDb->db, zSchema, pData, len, len, - SQLITE_MEMDB_FREEONCLOSE|SQLITE_MEMDB_RESIZEABLE); - if( xrc ){ - Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0); - rc = TCL_ERROR; - } - } - }else{ - Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); - rc = TCL_ERROR; - } -#endif - break; - } - /* ** $db nullvalue ?STRING? ** @@ -3481,9 +3479,6 @@ static int SQLITE_TCLAPI DbMain( int nKey = 0; #endif int rc; -#ifdef SQLITE_ENABLE_MEMDB - Tcl_Obj *pDbObj = 0; -#endif /* In normal use, each TCL interpreter runs in a single thread. So ** by default, we can turn off mutexing on SQLite database connections. @@ -3576,10 +3571,6 @@ static int SQLITE_TCLAPI DbMain( }else{ flags &= ~SQLITE_OPEN_URI; } -#ifdef SQLITE_ENABLE_MEMDB - }else if( strcmp(zArg, "-memdb")==0 ){ - pDbObj = objv[i]; -#endif }else{ Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0); return TCL_ERROR; @@ -3588,25 +3579,10 @@ static int SQLITE_TCLAPI DbMain( zErrMsg = 0; p = (SqliteDb*)Tcl_Alloc( sizeof(*p) ); memset(p, 0, sizeof(*p)); -#ifdef SQLITE_ENABLE_MEMDB - if( pDbObj ){ - rc = sqlite3_open_v2("x", &p->db, flags, "memdb"); - if( rc==SQLITE_OK ){ - int len; - unsigned char *aData = Tcl_GetByteArrayFromObj(pDbObj, &len); - unsigned char *a = sqlite3_malloc64( len ); - memcpy(a, aData, len); - sqlite3_memdb_config(p->db, "main", a, len, sqlite3_msize(a), - SQLITE_MEMDB_FREEONCLOSE | SQLITE_MEMDB_RESIZEABLE); - } - }else -#endif - { - if( zFile==0 ) zFile = ":memory:"; - zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); - rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs); - Tcl_DStringFree(&translatedFilename); - } + if( zFile==0 ) zFile = ""; + zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); + rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs); + Tcl_DStringFree(&translatedFilename); if( p->db ){ if( SQLITE_OK!=sqlite3_errcode(p->db) ){ zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); diff --git a/test/memdb1.test b/test/memdb1.test index 36184e2e4e..c37cac2664 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -48,7 +48,8 @@ close $fd # Verify that the content is the same. # db close -sqlite3 db -memdb $db1 +sqlite3 db +db deserialize $db1 do_execsql_test 110 { SELECT * FROM t1; } {1 2} diff --git a/test/tclsqlite.test b/test/tclsqlite.test index ca53710ec2..fb4be3dfcb 100644 --- a/test/tclsqlite.test +++ b/test/tclsqlite.test @@ -34,7 +34,7 @@ do_test tcl-1.1 { 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, memdb, 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 From 99abe5c478d5340616bc9418f7fd7c07b33dedfe Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 22:48:38 +0000 Subject: [PATCH 06/67] Miscellaneous code and comment cleanup. FossilOrigin-Name: fa6069fb3b0a4411fd6661dec7de40ece3064a2fe4b94ebfbda9e5e524e04e86 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/attach.c | 18 ++++++++++++------ src/memdb.c | 45 +++++++++------------------------------------ 4 files changed, 29 insertions(+), 50 deletions(-) diff --git a/manifest b/manifest index cde71db315..4f22c2b67d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\ssqlite3_memdb_config()\swith\ssqlite3_deserialize().\s\sRemove\sthe\n"db\smemdb"\scommand\sfrom\sthe\sTCL\sinterface,\sreplacing\sit\swith\s"db\sserialize"\nand\s"db\sdeserialize". -D 2018-01-03T19:03:31.558 +C Miscellaneous\scode\sand\scomment\scleanup. +D 2018-01-03T22:48:38.759 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 @@ -415,7 +415,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 0d0ccf7520a201d8747ea2f02c92c26e26f801bc161f714f27b9f7630dde0421 -F src/attach.c 52c34c2fb1a8852739aca3c4ae797f02660d826d1e79c067dadac97fe3335b6c +F src/attach.c af582a55cdb0435dc21da926cfcd5545eadfd99ea201b5b9e067cbeae1077077 F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 @@ -450,7 +450,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c 67c01e51b9e515721fbb4a27375233c67a8a8e5d66bd3fa6f4f84c85de43c05e +F src/memdb.c d58bb51e6029a7bd91b2148b98ab00c3a271c6cd2632eb756cfcd91e1252930b F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1690,7 +1690,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 8cf2ed4eff6d2e0958656e23384b05ead2128b678b0b69a591878af4190cd077 -R 752064346b8d3ad9381bcf73633be499 +P 2f6e9df9f0c5a9e5b1acb99cfa9486850cc1822d35b0989e779a7a10f3b1f1ac +R bb0359f4210b8aee0e32802f6ef52a4c U drh -Z 59a3fb5e3f8eae3c5ea078db9efbd371 +Z c49fae41835e3bd8d0d8eeb0cf1f4a88 diff --git a/manifest.uuid b/manifest.uuid index 08b82513bb..cf39388ce7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2f6e9df9f0c5a9e5b1acb99cfa9486850cc1822d35b0989e779a7a10f3b1f1ac \ No newline at end of file +fa6069fb3b0a4411fd6661dec7de40ece3064a2fe4b94ebfbda9e5e524e04e86 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 151b52e7a4..f177f1a5b5 100644 --- a/src/attach.c +++ b/src/attach.c @@ -84,7 +84,13 @@ static void attachFunc( if( zFile==0 ) zFile = ""; if( zName==0 ) zName = ""; - if( db->init.reopenMemdb ){ +#ifdef SQLITE_ENABLE_MEMDB +# 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 */ @@ -96,9 +102,9 @@ static void attachFunc( 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: + /* This is a real ATTACH + ** + ** Check for the following errors: ** ** * Too many attached databases, ** * Transaction currently open @@ -178,7 +184,7 @@ static void attachFunc( sqlite3BtreeLeave(pNew->pBt); } pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; - if( !db->init.reopenMemdb ) 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; } @@ -235,7 +241,7 @@ static void attachFunc( } } #endif - if( rc ){ + if( rc && !REOPEN_AS_MEMDB(db) ){ int iDb = db->nDb - 1; assert( iDb>=2 ); if( db->aDb[iDb].pBt ){ diff --git a/src/memdb.c b/src/memdb.c index 5a1f12dcbb..5aa66f1fde 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -10,8 +10,11 @@ ** ****************************************************************************** ** -** This is an in-memory VFS implementation. The application supplies -** a chunk of memory to hold the database file. +** 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_MEMDB #include "sqliteInt.h" @@ -52,10 +55,6 @@ static int memdbCheckReservedLock(sqlite3_file*, int *pResOut); static int memdbFileControl(sqlite3_file*, int op, void *pArg); static int memdbSectorSize(sqlite3_file*); static int memdbDeviceCharacteristics(sqlite3_file*); -static int memdbShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**); -static int memdbShmLock(sqlite3_file*, int offset, int n, int flags); -static void memdbShmBarrier(sqlite3_file*); -static int memdbShmUnmap(sqlite3_file*, int deleteFlag); static int memdbFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); static int memdbUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p); @@ -112,10 +111,10 @@ static const sqlite3_io_methods memdb_io_methods = { memdbFileControl, /* xFileControl */ memdbSectorSize, /* xSectorSize */ memdbDeviceCharacteristics, /* xDeviceCharacteristics */ - memdbShmMap, /* xShmMap */ - memdbShmLock, /* xShmLock */ - memdbShmBarrier, /* xShmBarrier */ - memdbShmUnmap, /* xShmUnmap */ + 0, /* xShmMap */ + 0, /* xShmLock */ + 0, /* xShmBarrier */ + 0, /* xShmUnmap */ memdbFetch, /* xFetch */ memdbUnfetch /* xUnfetch */ }; @@ -264,32 +263,6 @@ static int memdbDeviceCharacteristics(sqlite3_file *pFile){ SQLITE_IOCAP_SEQUENTIAL; } -/* Create a shared memory file mapping */ -static int memdbShmMap( - sqlite3_file *pFile, - int iPg, - int pgsz, - int bExtend, - void volatile **pp -){ - return SQLITE_IOERR_SHMMAP; -} - -/* Perform locking on a shared-memory segment */ -static int memdbShmLock(sqlite3_file *pFile, int offset, int n, int flags){ - return SQLITE_IOERR_SHMLOCK; -} - -/* Memory barrier operation on shared memory */ -static void memdbShmBarrier(sqlite3_file *pFile){ - return; -} - -/* Unmap a shared memory segment */ -static int memdbShmUnmap(sqlite3_file *pFile, int deleteFlag){ - return SQLITE_OK; -} - /* Fetch a page of a memory-mapped file */ static int memdbFetch( sqlite3_file *pFile, From a5bb43518b406098d4545c98fcffc80724c9f1fc Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 23:40:02 +0000 Subject: [PATCH 07/67] New test cases and fixes for minor problems. FossilOrigin-Name: e0da2cc382e0db33d0423372133115f52c77bd0093dbf816c7e88a0aad5f6582 --- manifest | 16 ++++---- manifest.uuid | 2 +- src/attach.c | 1 + src/tclsqlite.c | 4 +- test/memdb1.test | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 4f22c2b67d..77a6b3f324 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Miscellaneous\scode\sand\scomment\scleanup. -D 2018-01-03T22:48:38.759 +C New\stest\scases\sand\sfixes\sfor\sminor\sproblems. +D 2018-01-03T23:40:02.979 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 @@ -415,7 +415,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 0d0ccf7520a201d8747ea2f02c92c26e26f801bc161f714f27b9f7630dde0421 -F src/attach.c af582a55cdb0435dc21da926cfcd5545eadfd99ea201b5b9e067cbeae1077077 +F src/attach.c 8158394251d62a6513d6e395f14c9b8ad3f3447d8a1249c242c940cde5c1453e F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 @@ -488,7 +488,7 @@ F src/sqliteInt.h 713ee4be20beddf2f053b3ac1871c1f0d9ab54d1cc21c24a4365b560181b5d F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 8370ce15f97277304e7a17c47e18d47c1a31701fcd213eded727d09c547da2fc +F src/tclsqlite.c 4f4ca19af1a666da6f80d35443e58905d1fb7cbdb9899cf9ce7da60aeede5830 F src/test1.c 8ef15f7a357f85dfc41c6c748ce9c947b4f676e01bb5ae6a45bee4923dff8b51 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -1056,7 +1056,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 6ae9f9fe51c918bf203ee5135f88d74f6e4446b573a9c07b141356f8f5fbeaf1 +F test/memdb1.test 526252d466ecc3701550000651e1405d08ccefe0bf23e2dc86ada90e81a8eacc F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1690,7 +1690,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 2f6e9df9f0c5a9e5b1acb99cfa9486850cc1822d35b0989e779a7a10f3b1f1ac -R bb0359f4210b8aee0e32802f6ef52a4c +P fa6069fb3b0a4411fd6661dec7de40ece3064a2fe4b94ebfbda9e5e524e04e86 +R 80c4d802a2eb305cbf9b2f9ece314afe U drh -Z c49fae41835e3bd8d0d8eeb0cf1f4a88 +Z e7e409e5145088df0792d1925f4056dd diff --git a/manifest.uuid b/manifest.uuid index cf39388ce7..069635c8d7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa6069fb3b0a4411fd6661dec7de40ece3064a2fe4b94ebfbda9e5e524e04e86 \ No newline at end of file +e0da2cc382e0db33d0423372133115f52c77bd0093dbf816c7e88a0aad5f6582 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index f177f1a5b5..597351fa39 100644 --- a/src/attach.c +++ b/src/attach.c @@ -229,6 +229,7 @@ static void attachFunc( */ if( rc==SQLITE_OK ){ sqlite3BtreeEnterAll(db); + db->init.iDb = 0; rc = sqlite3Init(db, &zErrDyn); sqlite3BtreeLeaveAll(db); } diff --git a/src/tclsqlite.c b/src/tclsqlite.c index c9b4ff6107..f3261d1e79 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -2442,11 +2442,11 @@ static int SQLITE_TCLAPI DbObjCmd( } pBA = Tcl_GetByteArrayFromObj(pValue, &len); pData = sqlite3_malloc64( len ); - if( pData==0 ){ + if( pData==0 && len>0 ){ Tcl_AppendResult(interp, "out of memory", (char*)0); rc = TCL_ERROR; }else{ - memcpy(pData, pBA, len); + if( len>0 ) memcpy(pData, pBA, len); xrc = sqlite3_deserialize(pDb->db, zSchema, pData, len, len, SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE); diff --git a/test/memdb1.test b/test/memdb1.test index c37cac2664..48f9fca5ec 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -54,5 +54,109 @@ 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 From e616735cb190447097b83af23734dafd9fcda548 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 3 Jan 2018 23:54:18 +0000 Subject: [PATCH 08/67] Fix compiler warnings on Windows. FossilOrigin-Name: 512b8e40c4ce2066d230b5f007bd704dc3577e21c55131ef07d90bf2fcf91b40 --- ext/misc/unionvtab.c | 2 +- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c.in | 2 +- src/sqliteInt.h | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ext/misc/unionvtab.c b/ext/misc/unionvtab.c index 14cce84510..92d0b833c4 100644 --- a/ext/misc/unionvtab.c +++ b/ext/misc/unionvtab.c @@ -799,7 +799,7 @@ static void unionConfigureVtab( zVal = zOpt; if( *zVal==':' ) zVal++; while( union_isidchar(*zVal) ) zVal++; - nOpt = zVal-zOpt; + nOpt = (int)(zVal-zOpt); while( union_isspace(*zVal) ) zVal++; if( *zVal=='=' ){ diff --git a/manifest b/manifest index 77a6b3f324..29c6ed4690 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\stest\scases\sand\sfixes\sfor\sminor\sproblems. -D 2018-01-03T23:40:02.979 +C Fix\scompiler\swarnings\son\sWindows. +D 2018-01-03T23:54:18.421 F Makefile.in 892bf253c48f3d2d8d4e4e89b44b71aa548a0eba11b148c338690cfb99822859 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 3b7ee2ebaf579fe7d30bece93e61e52782c3ff836455cba3a192f7a8f6f269d6 @@ -293,7 +293,7 @@ F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c 41cf26c6b89fcaa8798ae10ae64d39c1f1d9d6995152e545bd491c13058b8fac F ext/misc/stmt.c 6f16443abb3551e3f5813bb13ba19a30e7032830015b0f92fe0c0453045c0a11 F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512 -F ext/misc/unionvtab.c de36c2c45583d68f99e45b392311967066b02e2651d05697da783698b245b387 +F ext/misc/unionvtab.c 2aa94902ea646e1aaf6c05eac944a14276cddd67735b2ad856030ffffbb6626c F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178 F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9 @@ -480,11 +480,11 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 8b22abe193e4d8243befa2038e4ae2405802fed1c446e5e502d11f652e09ba74 -F src/shell.c.in a418ddceef7a2789f18bdc2bcdd481b2562fe4a7754b8009c8dd33d5a67da332 +F src/shell.c.in 23b0207a222c1a1fcd0a3b9d790c79c0713212d63be94d96c0be0e62ccac3cd0 F src/sqlite.h.in 95a2e67c1ff46365eef3cb14e73d0b279a7435c0d0fb7e59c89cde9d4353dae2 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34 -F src/sqliteInt.h 713ee4be20beddf2f053b3ac1871c1f0d9ab54d1cc21c24a4365b560181b5d7d +F src/sqliteInt.h 315d863d61ac951d125934bc0946db15e94c61890d93fd6c6ff29c3c9881b39c F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1690,7 +1690,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 fa6069fb3b0a4411fd6661dec7de40ece3064a2fe4b94ebfbda9e5e524e04e86 -R 80c4d802a2eb305cbf9b2f9ece314afe +P e0da2cc382e0db33d0423372133115f52c77bd0093dbf816c7e88a0aad5f6582 +R 3114b544cf591fa5de64b7bed571adcc U drh -Z e7e409e5145088df0792d1925f4056dd +Z b9d8faa03d64775d21ab162e0db38bba diff --git a/manifest.uuid b/manifest.uuid index 069635c8d7..e191c40967 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e0da2cc382e0db33d0423372133115f52c77bd0093dbf816c7e88a0aad5f6582 \ No newline at end of file +512b8e40c4ce2066d230b5f007bd704dc3577e21c55131ef07d90bf2fcf91b40 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 4c9e60769a..1421ab4199 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -4272,7 +4272,7 @@ static int expertDotCommand( char *z = azArg[i]; int n; if( z[0]=='-' && z[1]=='-' ) z++; - n = strlen(z); + n = strlen30(z); if( n>=2 && 0==strncmp(z, "-verbose", n) ){ pState->expert.bVerbose = 1; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 35074ee81a..757cfcb994 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1365,9 +1365,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 : 1; /* Last statement is orphaned TEMP trigger */ - u8 imposterTable : 1; /* Building an imposter table */ - u8 reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ + 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 */ From b2194cea4ef650935e1b2bc0ea611d295e2eade4 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 1 Mar 2018 22:18:26 +0000 Subject: [PATCH 09/67] Allow the zSchema argument to sqlite3_serialize() to be NULL to mean the main database. FossilOrigin-Name: 5b01b9914fb612ceece34f40d45c7eb97c3504fc5a0a5ff0e67120bdee67f6ee --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/memdb.c | 7 +++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 737fe75fb0..ad80e19ef4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\slatest\senhancements\sfrom\strunk. -D 2018-03-01T13:44:40.762 +C Allow\sthe\szSchema\sargument\sto\ssqlite3_serialize()\sto\sbe\sNULL\sto\smean\sthe\nmain\sdatabase. +D 2018-03-01T22:18:26.726 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -460,7 +460,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c d58bb51e6029a7bd91b2148b98ab00c3a271c6cd2632eb756cfcd91e1252930b +F src/memdb.c f01e30a224d22e0487bf42028249d09ddccfed18ac03002d24b70a832d53ac1e F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1710,7 +1710,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 6ef3de810d54563c227045b16197b8011ce285ea867261946f93b2de55344f29 745a9a7fef0f28a57ea3f44899058993f6ecdedda52c81a09a4a9ce09c9004d6 -R 130ade233524cab0a0641e76e7f210be +P c8083de14b54fba1071385f8530d03d5684efd4963fde0f83ddc53ae3118a75b +R 4b7ab64dd9b0ddcbf834b7f0ea1bb2ba U drh -Z 8606a5979f84a0a30cbed3690217d5a2 +Z fef65347c0470682ba0a8e9f51beb02d diff --git a/manifest.uuid b/manifest.uuid index cfa0aa6b38..a69ed8658a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c8083de14b54fba1071385f8530d03d5684efd4963fde0f83ddc53ae3118a75b \ No newline at end of file +5b01b9914fb612ceece34f40d45c7eb97c3504fc5a0a5ff0e67120bdee67f6ee \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 5aa66f1fde..24c676e75d 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -421,8 +421,8 @@ unsigned char *sqlite3_serialize( sqlite3_int64 *piSize, /* Write size here, if not NULL */ unsigned int mFlags /* Maybe SQLITE_SERIALIZE_NOCOPY */ ){ - MemFile *p = memdbFromDbSchema(db, zSchema); - int iDb = sqlite3FindDbName(db, zSchema); + MemFile *p; + int iDb; Btree *pBt; sqlite3_int64 sz; int szPage = 0; @@ -431,6 +431,9 @@ unsigned char *sqlite3_serialize( char *zSql; int rc; + 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 ){ From 9c42626e43fb12a14fd52017198bf2c9128809a0 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 2 Mar 2018 20:00:42 +0000 Subject: [PATCH 10/67] In sqlite3_checker, wrap the call to "SELECT checkfreelist()" in a transaction. FossilOrigin-Name: 02906e55d73ea3521ad1e6807cffed5c759147f7b2d89efc4add984e53e3ad49 --- ext/repair/sqlite3_checker.tcl | 2 ++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) 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/manifest b/manifest index dea915e8ca..d4eea35cf9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sa\scheckpoint,\sfigure\sout\sif\sit\sis\spossible\sto\scheckpoint\sany\sframes\sat\sall\nbefore\screating\sthe\swal-iterator. -D 2018-03-02T16:52:47.523 +C In\ssqlite3_checker,\swrap\sthe\scall\sto\s"SELECT\scheckfreelist()"\sin\sa\ntransaction. +D 2018-03-02T20:00:42.454 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -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 @@ -1708,7 +1708,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 0f5057dffa9be1bccab04894709d25bf1f066c4b1aef50d67ee635d46d300a4d -R de1a2fcd17a7874df266511eaa97ccfc +P 044b0b65e716bffeddedbd1b0360c4c332f6d2359167c1d327a5ff96539474cb +R 5617c0cb2b4786d2069667d5badd72e3 U dan -Z 77af2128f3c4feb420234b4cd2eef89e +Z c724546c7342e99a479e8d8eca82215b diff --git a/manifest.uuid b/manifest.uuid index 4f3871ee75..eb557b9a5b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -044b0b65e716bffeddedbd1b0360c4c332f6d2359167c1d327a5ff96539474cb \ No newline at end of file +02906e55d73ea3521ad1e6807cffed5c759147f7b2d89efc4add984e53e3ad49 \ No newline at end of file From da57d9676a0628354d3686e5e9bb8cc4ea944ea5 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 5 Mar 2018 19:34:05 +0000 Subject: [PATCH 11/67] In the CLI, add a new command-line option "--archive" (also "--ar") that passes all subsequent arguments to the ".archive" command. FossilOrigin-Name: a5c4d30af1271dea2d322b0679fe963bbd0d5db6bba8904caf5e30e510d01832 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d4eea35cf9..a9f0afdfd1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\ssqlite3_checker,\swrap\sthe\scall\sto\s"SELECT\scheckfreelist()"\sin\sa\ntransaction. -D 2018-03-02T20:00:42.454 +C In\sthe\sCLI,\sadd\sa\snew\scommand-line\soption\s"--archive"\s(also\s"--ar")\sthat\npasses\sall\ssubsequent\sarguments\sto\sthe\s".archive"\scommand. +D 2018-03-05T19:34:05.494 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -489,7 +489,7 @@ 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/shell.c.in 2115621cbc5a45ad5031f45c5473585963d061d8af184ffdf0c1ac86a4b9dd80 F src/sqlite.h.in 235e942dd8c01b414c2996828b4d0d2500faf8850f8b24ae17d31c172f519e69 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1708,7 +1708,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 044b0b65e716bffeddedbd1b0360c4c332f6d2359167c1d327a5ff96539474cb -R 5617c0cb2b4786d2069667d5badd72e3 -U dan -Z c724546c7342e99a479e8d8eca82215b +P 02906e55d73ea3521ad1e6807cffed5c759147f7b2d89efc4add984e53e3ad49 +R 62ee6aafe33e5110a232a85ca1148daf +U drh +Z 2528010afb5b7373fd589a90e5b5beae diff --git a/manifest.uuid b/manifest.uuid index eb557b9a5b..7930d2e3b8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -02906e55d73ea3521ad1e6807cffed5c759147f7b2d89efc4add984e53e3ad49 \ No newline at end of file +a5c4d30af1271dea2d322b0679fe963bbd0d5db6bba8904caf5e30e510d01832 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 121a6c3506..2fff49dfcb 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7967,6 +7967,9 @@ static void process_sqliterc( ** Show available command line options */ static const char zOptions[] = +#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) + " -archive ARGS... pass ARGS to the \".archive\" command\n" +#endif " -ascii set output mode to 'ascii'\n" " -bail stop after hitting an error\n" " -batch force batch I/O\n" @@ -8263,6 +8266,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( strcmp(z, "-archive")==0 || strcmp(z, "-ar")==0 ){ + /* All remaining command-line arguments are passed to the ".archive" + ** command, so ignore them */ + break; +#endif } } if( data.zDbFilename==0 ){ @@ -8408,6 +8417,17 @@ 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( strcmp(z, "-archive")==0 || strcmp(z, "-ar")==0 ){ + if( nCmd>0 ){ + utf8_printf(stderr, "Error: cannot mix regular SQL or dot-commands" + " with \"%s\"\n", z); + return 1; + } + 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"); From 93b7731485e8e33fc032383372fde0a24653435f Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 5 Mar 2018 20:20:22 +0000 Subject: [PATCH 12/67] A new way of doing archive commands on the command-line for the CLI. The -A option means that everything that follows is a ".archive" command, including any suffix on the -A option. FossilOrigin-Name: 9d8081fabc491ba75d26ea81b3548bd10aeeb3334b0ad1462d7ab656c8d7c35e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 14 ++++++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index a9f0afdfd1..a61c73cdd2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sCLI,\sadd\sa\snew\scommand-line\soption\s"--archive"\s(also\s"--ar")\sthat\npasses\sall\ssubsequent\sarguments\sto\sthe\s".archive"\scommand. -D 2018-03-05T19:34:05.494 +C A\snew\sway\sof\sdoing\sarchive\scommands\son\sthe\scommand-line\sfor\sthe\sCLI.\s\sThe\s-A\noption\smeans\sthat\severything\sthat\sfollows\sis\sa\s".archive"\scommand,\sincluding\nany\ssuffix\son\sthe\s-A\soption. +D 2018-03-05T20:20:22.408 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -489,7 +489,7 @@ 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 2115621cbc5a45ad5031f45c5473585963d061d8af184ffdf0c1ac86a4b9dd80 +F src/shell.c.in 4b2b00d2818b6bf11650f0cb15a4b20c61e854a8021fd9c7ea366910bc7ff9c4 F src/sqlite.h.in 235e942dd8c01b414c2996828b4d0d2500faf8850f8b24ae17d31c172f519e69 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1708,7 +1708,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 02906e55d73ea3521ad1e6807cffed5c759147f7b2d89efc4add984e53e3ad49 -R 62ee6aafe33e5110a232a85ca1148daf +P a5c4d30af1271dea2d322b0679fe963bbd0d5db6bba8904caf5e30e510d01832 +R a4b2268f5e0028154fa1ed86e680a46b U drh -Z 2528010afb5b7373fd589a90e5b5beae +Z 4b53179cde3abacde999cf5c4a9643a2 diff --git a/manifest.uuid b/manifest.uuid index 7930d2e3b8..92184b68ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a5c4d30af1271dea2d322b0679fe963bbd0d5db6bba8904caf5e30e510d01832 \ No newline at end of file +9d8081fabc491ba75d26ea81b3548bd10aeeb3334b0ad1462d7ab656c8d7c35e \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 2fff49dfcb..89635f7150 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7968,7 +7968,7 @@ static void process_sqliterc( */ static const char zOptions[] = #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) - " -archive ARGS... pass ARGS to the \".archive\" command\n" + " -Aopts ARGS... run \".archive -opts ARGS\" and exit\n" #endif " -ascii set output mode to 'ascii'\n" " -bail stop after hitting an error\n" @@ -8267,7 +8267,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( strcmp(z,"-readonly")==0 ){ data.openMode = SHELL_OPEN_READONLY; #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) - }else if( strcmp(z, "-archive")==0 || strcmp(z, "-ar")==0 ){ + }else if( strncmp(z, "-A",2)==0 ){ /* All remaining command-line arguments are passed to the ".archive" ** command, so ignore them */ break; @@ -8418,13 +8418,19 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ } } #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) - }else if( strcmp(z, "-archive")==0 || strcmp(z, "-ar")==0 ){ + }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; } - arDotCommand(&data, argv+i, argc-i); + 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 From ad7fd5d0962c7ec1f116ac15404ce7a0da0c5c3f Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 5 Mar 2018 20:21:50 +0000 Subject: [PATCH 13/67] Improved command-line help for the -A option on the CLI. FossilOrigin-Name: d937ac181c5c78b9e5068db4ff1dab6becdba8c22cd27a3cfa0d4c12da1ec7ad --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index a61c73cdd2..2c9a313961 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\snew\sway\sof\sdoing\sarchive\scommands\son\sthe\scommand-line\sfor\sthe\sCLI.\s\sThe\s-A\noption\smeans\sthat\severything\sthat\sfollows\sis\sa\s".archive"\scommand,\sincluding\nany\ssuffix\son\sthe\s-A\soption. -D 2018-03-05T20:20:22.408 +C Improved\scommand-line\shelp\sfor\sthe\s-A\soption\son\sthe\sCLI. +D 2018-03-05T20:21:50.703 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -489,7 +489,7 @@ 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 4b2b00d2818b6bf11650f0cb15a4b20c61e854a8021fd9c7ea366910bc7ff9c4 +F src/shell.c.in 8c6ea9b4da9450c26551bbe7de24170e5c6c6e3af4dedaa663e3f5ef05659a96 F src/sqlite.h.in 235e942dd8c01b414c2996828b4d0d2500faf8850f8b24ae17d31c172f519e69 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1708,7 +1708,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 a5c4d30af1271dea2d322b0679fe963bbd0d5db6bba8904caf5e30e510d01832 -R a4b2268f5e0028154fa1ed86e680a46b +P 9d8081fabc491ba75d26ea81b3548bd10aeeb3334b0ad1462d7ab656c8d7c35e +R cf208e3188f8857ac2b128855f71c9f9 U drh -Z 4b53179cde3abacde999cf5c4a9643a2 +Z b77ef973214333cff99a9bfbab13dccb diff --git a/manifest.uuid b/manifest.uuid index 92184b68ca..01c92aabe5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d8081fabc491ba75d26ea81b3548bd10aeeb3334b0ad1462d7ab656c8d7c35e \ No newline at end of file +d937ac181c5c78b9e5068db4ff1dab6becdba8c22cd27a3cfa0d4c12da1ec7ad \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 89635f7150..0782782a44 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7968,7 +7968,7 @@ static void process_sqliterc( */ static const char zOptions[] = #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) - " -Aopts ARGS... run \".archive -opts ARGS\" and exit\n" + " -A ARGS... run \".archive ARGS\" and exit\n" #endif " -ascii set output mode to 'ascii'\n" " -bail stop after hitting an error\n" From 6344edda80117a6e5853ecb4454e383fc5342d2a Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 5 Mar 2018 21:17:20 +0000 Subject: [PATCH 14/67] Fix another crash in the sessions module triggered by malformed input. FossilOrigin-Name: 7e70c9b86af557e86152748ddf1da467e62817b35df1da0d7d3b67941b198897 --- ext/session/session4.test | 1 + ext/session/sqlite3session.c | 9 ++++++++- manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) 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 04ca5b2b30..9b96c5ca6f 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -2786,7 +2786,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/manifest b/manifest index 2c9a313961..045661d802 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scommand-line\shelp\sfor\sthe\s-A\soption\son\sthe\sCLI. -D 2018-03-05T20:21:50.703 +C Fix\sanother\scrash\sin\sthe\ssessions\smodule\striggered\sby\smalformed\sinput. +D 2018-03-05T21:17:20.992 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -381,7 +381,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 @@ -402,7 +402,7 @@ F ext/session/sessionfault.test da273f2712b6411e85e71465a1733b8501dbf6f7 F ext/session/sessionfault2.test 04aa0bc9aa70ea43d8de82c4f648db4de1e990b0 F ext/session/sessionstat1.test 41cd97c2e48619a41cdf8ae749e1b25f34719de638689221aa43971be693bf4e F ext/session/sessionwor.test 2f3744236dc8b170a695b7d8ddc8c743c7e79fdc -F ext/session/sqlite3session.c 0b7f1b8eb5b5a83fd96127b93139eadd2f2e2915c1eaceab4f5d771719c0c22f +F ext/session/sqlite3session.c 9edfaaa74977ddecd7bbd94e8f844d9b0f6eec22d1d547e806361670db814c1e F ext/session/sqlite3session.h 2e1584b030fbd841cefdce15ba984871978d305f586da2d1972f6e1958fa10b1 F ext/session/test_session.c eb0bd6c1ea791c1d66ee4ef94c16500dad936386 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 @@ -1708,7 +1708,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 9d8081fabc491ba75d26ea81b3548bd10aeeb3334b0ad1462d7ab656c8d7c35e -R cf208e3188f8857ac2b128855f71c9f9 -U drh -Z b77ef973214333cff99a9bfbab13dccb +P d937ac181c5c78b9e5068db4ff1dab6becdba8c22cd27a3cfa0d4c12da1ec7ad +R 81faf4bc4e37be1b18b8f0d06bd24da5 +U dan +Z b0ded38a3d14d974acb7e101a7fd9d64 diff --git a/manifest.uuid b/manifest.uuid index 01c92aabe5..7ccd9d570f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d937ac181c5c78b9e5068db4ff1dab6becdba8c22cd27a3cfa0d4c12da1ec7ad \ No newline at end of file +7e70c9b86af557e86152748ddf1da467e62817b35df1da0d7d3b67941b198897 \ No newline at end of file From 49cc2f3b9cf788722a3e6de6b9721a9cbfaa4f0b Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 5 Mar 2018 23:23:28 +0000 Subject: [PATCH 15/67] Fix walIteratorInit() so that it always leaves the iterator as a NULL pointer if an OOM occurs. This fixes an assertion fault introduced by check-in [044b0b65e716bff]. FossilOrigin-Name: e5ce256aa1f7a8ae995b79c9da895827bee5d8d0724fc15413ff203dc9e2602d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wal.c | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 045661d802..8c32f61309 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\scrash\sin\sthe\ssessions\smodule\striggered\sby\smalformed\sinput. -D 2018-03-05T21:17:20.992 +C Fix\swalIteratorInit()\sso\sthat\sit\salways\sleaves\sthe\siterator\sas\sa\sNULL\spointer\nif\san\sOOM\soccurs.\s\sThis\sfixes\san\sassertion\sfault\sintroduced\sby\s\ncheck-in\s[044b0b65e716bff]. +D 2018-03-05T23:23:28.467 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -568,7 +568,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 60e5c938c4858c72f0cb0c7220282d3066efa215ad5e82f3cf4c0b833fbe60dc +F src/wal.c aa9cffc7a2bad6b826a86c8562dd4978398720ed41cb8ee7aa9d054eb8b456a0 F src/wal.h 8de5d2d3de0956d6f6cb48c83a4012d5f227b8fe940f3a349a4b7e85ebcb492a F src/walker.c da987a20d40145c0a03c07d8fefcb2ed363becc7680d0500d9c79915591f5b1f F src/where.c 7cae47e813393d70c6d327fdf000fcb30f76b1b0b5a5b52ff6402e0c658de32c @@ -1708,7 +1708,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 d937ac181c5c78b9e5068db4ff1dab6becdba8c22cd27a3cfa0d4c12da1ec7ad -R 81faf4bc4e37be1b18b8f0d06bd24da5 -U dan -Z b0ded38a3d14d974acb7e101a7fd9d64 +P 7e70c9b86af557e86152748ddf1da467e62817b35df1da0d7d3b67941b198897 +R 8e40d6345e942fd404ec54ebfeaa69d8 +U drh +Z f09301629be2ce9f9dae3a5519749c5f diff --git a/manifest.uuid b/manifest.uuid index 7ccd9d570f..feb65fba83 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e70c9b86af557e86152748ddf1da467e62817b35df1da0d7d3b67941b198897 \ No newline at end of file +e5ce256aa1f7a8ae995b79c9da895827bee5d8d0724fc15413ff203dc9e2602d \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index c42bf39bcd..69a89a709b 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1667,6 +1667,7 @@ static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ if( rc!=SQLITE_OK ){ walIteratorFree(p); + p = 0; } *pp = p; return rc; From 5f9d192de9a336f8bb3ed63181cf190d06c60ee0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Mar 2018 04:01:08 +0000 Subject: [PATCH 16/67] Improvements to the memdb VFS. FossilOrigin-Name: a14fed69d0d4932fc6c71cf8acc5199cca4efbd10bca563a8e86038d6afd5c64 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/memdb.c | 38 ++++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 0daa75ee51..3dabf8b492 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\swalIteratorInit()\sfix\sfrom\strunk. -D 2018-03-06T02:00:20.576 +C Improvements\sto\sthe\smemdb\sVFS. +D 2018-03-06T04:01:08.317 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -460,7 +460,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c f01e30a224d22e0487bf42028249d09ddccfed18ac03002d24b70a832d53ac1e +F src/memdb.c a559d61e55a715ec48b48685d20431fde1e114fb4df689df89334cedf4c0101c F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1710,7 +1710,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 6274cf1f397d36be9e9b65b1935a776c834e4512e0e89f82c132efd4d1e8ef82 e5ce256aa1f7a8ae995b79c9da895827bee5d8d0724fc15413ff203dc9e2602d -R 4fdec0179640fc276902d16463f8cb6d +P 6399e101d5f6b8582640e0d90783e56042eaa1600db3bd02f8df5e7b01ac1cab +R 308fbe14b615cda601b7af6fc89baf23 U drh -Z bbb52f4afaed03841603241952a4da37 +Z b79ee0d17ceeeb3759cd662f53a7e6c2 diff --git a/manifest.uuid b/manifest.uuid index 854da70375..bbe7322aa5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6399e101d5f6b8582640e0d90783e56042eaa1600db3bd02f8df5e7b01ac1cab \ No newline at end of file +a14fed69d0d4932fc6c71cf8acc5199cca4efbd10bca563a8e86038d6afd5c64 \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 24c676e75d..ec917e776b 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -53,7 +53,7 @@ static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize); static int memdbLock(sqlite3_file*, int); static int memdbCheckReservedLock(sqlite3_file*, int *pResOut); static int memdbFileControl(sqlite3_file*, int op, void *pArg); -static int memdbSectorSize(sqlite3_file*); +/* 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); @@ -109,7 +109,7 @@ static const sqlite3_io_methods memdb_io_methods = { memdbLock, /* xUnlock - same as xLock in this case */ memdbCheckReservedLock, /* xCheckReservedLock */ memdbFileControl, /* xFileControl */ - memdbSectorSize, /* xSectorSize */ + 0, /* memdbSectorSize,*/ /* xSectorSize */ memdbDeviceCharacteristics, /* xDeviceCharacteristics */ 0, /* xShmMap */ 0, /* xShmLock */ @@ -157,10 +157,11 @@ static int memdbRead( */ static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){ unsigned char *pNew; - if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 ) return SQLITE_FULL; - if( p->nMmap>0 ) return SQLITE_FULL; + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ + return SQLITE_FULL; + } pNew = sqlite3_realloc64(p->aData, newSz); - if( pNew==0 ) return SQLITE_FULL; + if( pNew==0 ) return SQLITE_NOMEM; p->aData = pNew; p->szMax = newSz; return SQLITE_OK; @@ -177,8 +178,11 @@ static int memdbWrite( ){ MemFile *p = (MemFile *)pFile; if( iOfst+iAmt>p->sz ){ - if( iOfst+iAmt>p->szMax && memdbEnlarge(p, (iOfst+iAmt)*2) ){ - return SQLITE_FULL; + 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; @@ -193,7 +197,10 @@ static int memdbWrite( static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ MemFile *p = (MemFile *)pFile; if( size>p->sz ){ - if( size>p->szMax && memdbEnlarge(p, size) ) return SQLITE_FULL; + int rc; + if( size>p->szMax && (rc = memdbEnlarge(p, size))!=SQLITE_OK ){ + return rc; + } memset(p->aData+p->sz, 0, size-p->sz); } p->sz = size; @@ -246,12 +253,14 @@ static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){ 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. @@ -294,10 +303,12 @@ static int memdbOpen( 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)); - if( (flags & SQLITE_OPEN_MAIN_DB)==0 ) return SQLITE_CANTOPEN; p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; - *pOutFlags = flags | SQLITE_OPEN_MEMORY; + if( pOutFlags ) *pOutFlags = flags | SQLITE_OPEN_MEMORY; p->base.pMethods = &memdb_io_methods; return SQLITE_OK; } @@ -537,8 +548,11 @@ end_deserialize: ** Register the new VFS. */ int sqlite3MemdbInit(void){ - memdb_vfs.pAppData = sqlite3_vfs_find(0); - memdb_vfs.szOsFile = sizeof(MemFile); + sqlite3_vfs *pLower = sqlite3_vfs_find(0); + int sz = pLower->szOsFile; + memdb_vfs.pAppData = pLower; + if( sz Date: Tue, 6 Mar 2018 11:46:34 +0000 Subject: [PATCH 17/67] Avoid running a couple of tests in crash8.test that depend on the presence of the journal file if running on an F2FS file-system that does not require a journal file. FossilOrigin-Name: 797e02e0ee703ab0fd53e26ba5c96ac7429b8022522bec201423718d508acf24 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/crash8.test | 6 +++++- test/speed4p.test | 1 - 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 8c32f61309..1ac1644837 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\swalIteratorInit()\sso\sthat\sit\salways\sleaves\sthe\siterator\sas\sa\sNULL\spointer\nif\san\sOOM\soccurs.\s\sThis\sfixes\san\sassertion\sfault\sintroduced\sby\s\ncheck-in\s[044b0b65e716bff]. -D 2018-03-05T23:23:28.467 +C Avoid\srunning\sa\scouple\sof\stests\sin\scrash8.test\sthat\sdepend\son\sthe\spresence\sof\nthe\sjournal\sfile\sif\srunning\son\san\sF2FS\sfile-system\sthat\sdoes\snot\srequire\sa\njournal\sfile. +D 2018-03-06T11:46:34.560 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -727,7 +727,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 @@ -1261,7 +1261,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 @@ -1708,7 +1708,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 7e70c9b86af557e86152748ddf1da467e62817b35df1da0d7d3b67941b198897 -R 8e40d6345e942fd404ec54ebfeaa69d8 -U drh -Z f09301629be2ce9f9dae3a5519749c5f +P e5ce256aa1f7a8ae995b79c9da895827bee5d8d0724fc15413ff203dc9e2602d +R 86215704ed447a309e260641c8831065 +U dan +Z a677dbe568f73fc26f67f245e10dea7a diff --git a/manifest.uuid b/manifest.uuid index feb65fba83..1f79fcf006 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e5ce256aa1f7a8ae995b79c9da895827bee5d8d0724fc15413ff203dc9e2602d \ No newline at end of file +797e02e0ee703ab0fd53e26ba5c96ac7429b8022522bec201423718d508acf24 \ No newline at end of file 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/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 From 14714167f700c005ad08007677d6ef40adfd54ea Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Mar 2018 19:14:32 +0000 Subject: [PATCH 18/67] Simplifications to the memdb VFS. FossilOrigin-Name: 6c3f723a6856fa38ea3f11a36b56f46c5c1fcf17f4daf712e5e0b42562d5f4c6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/memdb.c | 54 +++++++++++++++++++++++++++++---------------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index 3dabf8b492..f599a85e45 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\smemdb\sVFS. -D 2018-03-06T04:01:08.317 +C Simplifications\sto\sthe\smemdb\sVFS. +D 2018-03-06T19:14:32.801 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -460,7 +460,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c a559d61e55a715ec48b48685d20431fde1e114fb4df689df89334cedf4c0101c +F src/memdb.c ffdca40946f9cff49c6d0f452648233d1a5234bb1dfa456787ee82333164d126 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1710,7 +1710,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 6399e101d5f6b8582640e0d90783e56042eaa1600db3bd02f8df5e7b01ac1cab -R 308fbe14b615cda601b7af6fc89baf23 +P a14fed69d0d4932fc6c71cf8acc5199cca4efbd10bca563a8e86038d6afd5c64 +R b9fff9a384a4ae44f14923e3716823bc U drh -Z b79ee0d17ceeeb3759cd662f53a7e6c2 +Z ed8ab2a467fe746aa3cc4991867879e0 diff --git a/manifest.uuid b/manifest.uuid index bbe7322aa5..77b67bccf4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a14fed69d0d4932fc6c71cf8acc5199cca4efbd10bca563a8e86038d6afd5c64 \ No newline at end of file +6c3f723a6856fa38ea3f11a36b56f46c5c1fcf17f4daf712e5e0b42562d5f4c6 \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index ec917e776b..b2eefde955 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -51,7 +51,7 @@ 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); +/* 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*); @@ -62,7 +62,7 @@ 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 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); @@ -71,7 +71,7 @@ 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 memdbCurrentTime(sqlite3_vfs*, double*); */ static int memdbGetLastError(sqlite3_vfs*, int, char *); static int memdbCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); @@ -83,7 +83,7 @@ static sqlite3_vfs memdb_vfs = { "memdb", /* zName */ 0, /* pAppData (set when registered) */ memdbOpen, /* xOpen */ - memdbDelete, /* xDelete */ + 0, /* memdbDelete, */ /* xDelete */ memdbAccess, /* xAccess */ memdbFullPathname, /* xFullPathname */ memdbDlOpen, /* xDlOpen */ @@ -92,7 +92,7 @@ static sqlite3_vfs memdb_vfs = { memdbDlClose, /* xDlClose */ memdbRandomness, /* xRandomness */ memdbSleep, /* xSleep */ - memdbCurrentTime, /* xCurrentTime */ + 0, /* memdbCurrentTime, */ /* xCurrentTime */ memdbGetLastError, /* xGetLastError */ memdbCurrentTimeInt64 /* xCurrentTimeInt64 */ }; @@ -107,7 +107,7 @@ static const sqlite3_io_methods memdb_io_methods = { memdbFileSize, /* xFileSize */ memdbLock, /* xLock */ memdbLock, /* xUnlock - same as xLock in this case */ - memdbCheckReservedLock, /* xCheckReservedLock */ + 0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */ memdbFileControl, /* xFileControl */ 0, /* memdbSectorSize,*/ /* xSectorSize */ memdbDeviceCharacteristics, /* xDeviceCharacteristics */ @@ -193,16 +193,14 @@ static int memdbWrite( /* ** 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( size>p->sz ){ - int rc; - if( size>p->szMax && (rc = memdbEnlarge(p, size))!=SQLITE_OK ){ - return rc; - } - memset(p->aData+p->sz, 0, size-p->sz); - } + if( NEVER(size>p->sz) ) return SQLITE_FULL; p->sz = size; return SQLITE_OK; } @@ -232,6 +230,7 @@ static int memdbLock(sqlite3_file *pFile, int 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. */ @@ -239,6 +238,7 @@ static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){ *pResOut = 0; return SQLITE_OK; } +#endif /* ** File control method. For custom operations on an memdb-file. @@ -308,11 +308,14 @@ static int memdbOpen( } memset(p, 0, sizeof(*p)); p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; - if( pOutFlags ) *pOutFlags = flags | SQLITE_OPEN_MEMORY; + 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 @@ -321,10 +324,13 @@ static int memdbOpen( 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, @@ -397,12 +403,14 @@ 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); @@ -528,15 +536,15 @@ int sqlite3_deserialize( 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; - } + /* The memdbFromDbSchema() call can only fail if zSchema is not + ** a valid schema name or if the schema is not a memdb schema. But + ** neither of those things can be true here, so failure is not possible */ + assert( p!=0 ); + 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); From 8784efaea94ea2ad37549db66e2c2b596223c26b Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Mar 2018 20:54:27 +0000 Subject: [PATCH 19/67] Handle some boundary cases in memdb associated with OOM faults. FossilOrigin-Name: b58ca4cb0c921e81efad527c80b220be120263cfdb04528ae26ecf8b8f66f44a --- manifest | 14 ++++++------ manifest.uuid | 2 +- src/attach.c | 37 +++++++++++++++++--------------- src/memdb.c | 59 ++++++++++++++++++++++++++++----------------------- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/manifest b/manifest index f599a85e45..962981e679 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\smemdb\sVFS. -D 2018-03-06T19:14:32.801 +C Handle\ssome\sboundary\scases\sin\smemdb\sassociated\swith\sOOM\sfaults. +D 2018-03-06T20:54:27.966 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -425,7 +425,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 6b42e36a5dcc2703a771f2411bd5e99524bd62c7ecde209bb88dfb04c72f046e -F src/attach.c e79ef463dc0a457281512c5a67c02d886a1a4502001bc9b7eb008e9b7c0f7bf3 +F src/attach.c 6a5619eaf0101b355922cb006e63458312d1067b80499e1df41cdd0ce37af99f F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 @@ -460,7 +460,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c ffdca40946f9cff49c6d0f452648233d1a5234bb1dfa456787ee82333164d126 +F src/memdb.c 3f14ea29aea3a43c39b83c392016a03790692007d751320ea8c19df03bb0b393 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1710,7 +1710,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 a14fed69d0d4932fc6c71cf8acc5199cca4efbd10bca563a8e86038d6afd5c64 -R b9fff9a384a4ae44f14923e3716823bc +P 6c3f723a6856fa38ea3f11a36b56f46c5c1fcf17f4daf712e5e0b42562d5f4c6 +R 93b06b41fb0db58473fe3890ab6bb440 U drh -Z ed8ab2a467fe746aa3cc4991867879e0 +Z f2d702ac0939e1489f368e13dd72bca2 diff --git a/manifest.uuid b/manifest.uuid index 77b67bccf4..fb3d8af9ee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c3f723a6856fa38ea3f11a36b56f46c5c1fcf17f4daf712e5e0b42562d5f4c6 \ No newline at end of file +b58ca4cb0c921e81efad527c80b220be120263cfdb04528ae26ecf8b8f66f44a \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 9b07f89b79..09bd02be89 100644 --- a/src/attach.c +++ b/src/attach.c @@ -97,7 +97,7 @@ static void attachFunc( pVfs = sqlite3_vfs_find("memdb"); if( pVfs==0 ) return; pNew = &db->aDb[db->init.iDb]; - sqlite3BtreeClose(pNew->pBt); + if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt); pNew->pBt = 0; pNew->pSchema = 0; rc = sqlite3BtreeOpen(pVfs, "x", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB); @@ -232,6 +232,7 @@ static void attachFunc( db->init.iDb = 0; rc = sqlite3Init(db, &zErrDyn); sqlite3BtreeLeaveAll(db); + assert( zErrDyn==0 || rc!=SQLITE_OK ); } #ifdef SQLITE_USER_AUTHENTICATION if( rc==SQLITE_OK ){ @@ -242,22 +243,24 @@ static void attachFunc( } } #endif - if( rc && !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); + if( rc ){ + 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/memdb.c b/src/memdb.c index b2eefde955..88eaaba4ee 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -472,27 +472,31 @@ unsigned char *sqlite3_serialize( rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM; sqlite3_free(zSql); if( rc ) return 0; - sqlite3_step(pStmt); - sz = sqlite3_column_int64(pStmt, 0)*szPage; - if( piSize ) *piSize = sz; - if( mFlags & SQLITE_SERIALIZE_NOCOPY ){ + rc = sqlite3_step(pStmt); + if( rc!=SQLITE_ROW ){ 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); + 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); } - sqlite3PagerUnref(pPage); } } } @@ -536,15 +540,16 @@ int sqlite3_deserialize( goto end_deserialize; } p = memdbFromDbSchema(db, zSchema); - /* The memdbFromDbSchema() call can only fail if zSchema is not - ** a valid schema name or if the schema is not a memdb schema. But - ** neither of those things can be true here, so failure is not possible */ - assert( p!=0 ); - p->aData = pData; - p->sz = szDb; - p->szMax = szBuf; - p->mFlags = mFlags; - rc = SQLITE_OK; + 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); From 9c6396ecc788531b166dcbba833ab65a39abf501 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 6 Mar 2018 21:43:19 +0000 Subject: [PATCH 20/67] Improved documentation for sqlite3_serialize() and sqlite3_deserialize(). Change the name of the compile-time option to enable these interfaces from SQLITE_ENABLE_MEMDB to SQLITE_ENABLE_DESERIALIZE. FossilOrigin-Name: f07e97aed435b02e1473053c0257ec5c89bf0b3e46076b7a9382de432bbc2497 --- manifest | 28 ++++++++++++++-------------- manifest.uuid | 2 +- src/attach.c | 2 +- src/main.c | 2 +- src/memdb.c | 4 ++-- src/pager.c | 6 ++++++ src/sqlite.h.in | 36 ++++++++++++++++++++++++++++++++++-- src/sqliteInt.h | 2 +- src/tclsqlite.c | 4 ++-- src/test_config.c | 6 +++--- test/memdb1.test | 2 +- 11 files changed, 66 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index 962981e679..18c42ee4e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Handle\ssome\sboundary\scases\sin\smemdb\sassociated\swith\sOOM\sfaults. -D 2018-03-06T20:54:27.966 +C Improved\sdocumentation\sfor\ssqlite3_serialize()\sand\ssqlite3_deserialize().\nChange\sthe\sname\sof\sthe\scompile-time\soption\sto\senable\sthese\sinterfaces\nfrom\sSQLITE_ENABLE_MEMDB\sto\sSQLITE_ENABLE_DESERIALIZE. +D 2018-03-06T21:43:19.244 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -425,7 +425,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 6b42e36a5dcc2703a771f2411bd5e99524bd62c7ecde209bb88dfb04c72f046e -F src/attach.c 6a5619eaf0101b355922cb006e63458312d1067b80499e1df41cdd0ce37af99f +F src/attach.c f6f212c43dddba79dfcb723fb9470785f3ff55bde8953cd9d2546f3022070a41 F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 @@ -453,14 +453,14 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 14686083cedc198540b15a79586cdd4be2acf6d5fa97627e355f817ab07e9fee F src/legacy.c 134ab3e3fae00a0f67a5187981d6935b24b337bcf0f4b3e5c9fa5763da95bf4e F src/loadext.c f6e4e416a736369f9e80eba609f0acda97148a8b0453784d670c78d3eed2f302 -F src/main.c d45d07a1c707f88cf734ec7699d9c393247f18682d748ab53065fb669231f66a +F src/main.c c1e97e4c6fffff1fb1a6f1c48807386819af78657b4ae4acfd6d6d17353b8277 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 3f14ea29aea3a43c39b83c392016a03790692007d751320ea8c19df03bb0b393 +F src/memdb.c f5d49ef349a07df3b855885c4a0f3d8d688ca9a9c82093e9ed6a399a4826abea F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -476,7 +476,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c 928586cbde31890538854f1657463392d63b2d7794f577774573ae53ec283d7b F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 0dc92667c803ed2e9566c35521bed2c53717197b011bc7b64d17cd552a241a7b +F src/pager.c aa764a01a5548e633ea083521f48c2b128245fae1a8157a16a3490b9b9718f55 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a F src/parse.y 3be4b2b5e33ef7dab3128b765898ee786fc6cd698a7f053f756a68f2f238f0aa F src/pcache.c 7ae91a4557a43d77d449accbfdc68846e6516f8e2eda46e8bbe4536fb669b201 @@ -491,14 +491,14 @@ F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c f02352ac5cbb6fad3804add825743b924cfb6c742ba2e8666d726828a9985d73 F src/shell.c.in 8c6ea9b4da9450c26551bbe7de24170e5c6c6e3af4dedaa663e3f5ef05659a96 -F src/sqlite.h.in 82eb2b02de6dda3ca9797a5a5418c8409e2aaf5b4f20530a9036722faa0cc43c +F src/sqlite.h.in 8125abd15ff083591e53e1bc874319fbfaf239b1c57563c9685bd42723f8926a F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d -F src/sqliteInt.h 574a0dd6978197cc1f9b8d571744c9a30e256d29a3092050bd8a95e37c7229b9 +F src/sqliteInt.h 2ef60a6d9a50e6eef224e9eae71b29a9fb91c301e882d9fbbb77afd50b6cf815 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c d05dde2bb9534ee39a5095c4c4a43625997e0f3ab6889b55e76393b05b6895b1 +F src/tclsqlite.c 3c3e085e02edf4c416792050d288944fd0fad3f7b283a81fa45241a633d78c80 F src/test1.c 1ab7cbbb6693e08364c1a9241e2aee17f8c4925e4cc52396be77ae6845a05828 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -514,7 +514,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 09bd69f7e59bad08b67dd7bd8e7de6d992f1a668466b4500c870139fe1792126 +F src/test_config.c 097c6189803886a1fb26ec37d8bc62b90512cb53ab79a1fb6d35196c1ec42ded F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf9f8f F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e F src/test_devsym.c 1960abbb234b97e9b920f07e99503fc04b443f62bbc3c6ff2c2cea2133e3b8a2 @@ -1067,7 +1067,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 526252d466ecc3701550000651e1405d08ccefe0bf23e2dc86ada90e81a8eacc +F test/memdb1.test fbe47f36c12725ebdd2760f846371e6eb09f403bd7236fbdddb21aa6e3c652b4 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2 F test/memsubsys1.test 9e7555a22173b8f1c96c281ce289b338fcba2abe8b157f8798ca195bbf1d347e F test/memsubsys2.test 3e4a8d0c05fd3e5fa92017c64666730a520c7e08 @@ -1710,7 +1710,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 6c3f723a6856fa38ea3f11a36b56f46c5c1fcf17f4daf712e5e0b42562d5f4c6 -R 93b06b41fb0db58473fe3890ab6bb440 +P b58ca4cb0c921e81efad527c80b220be120263cfdb04528ae26ecf8b8f66f44a +R 8d936538e4c856e0f588396347b85dcc U drh -Z f2d702ac0939e1489f368e13dd72bca2 +Z c61ba7a8db0957766315d0dc5cf0b993 diff --git a/manifest.uuid b/manifest.uuid index fb3d8af9ee..6fe0b07e1f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b58ca4cb0c921e81efad527c80b220be120263cfdb04528ae26ecf8b8f66f44a \ No newline at end of file +f07e97aed435b02e1473053c0257ec5c89bf0b3e46076b7a9382de432bbc2497 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 09bd02be89..f85952f7c6 100644 --- a/src/attach.c +++ b/src/attach.c @@ -84,7 +84,7 @@ static void attachFunc( if( zFile==0 ) zFile = ""; if( zName==0 ) zName = ""; -#ifdef SQLITE_ENABLE_MEMDB +#ifdef SQLITE_ENABLE_DESERIALIZE # define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb) #else # define REOPEN_AS_MEMDB(db) (0) diff --git a/src/main.c b/src/main.c index 2fef116868..af93a011e3 100644 --- a/src/main.c +++ b/src/main.c @@ -239,7 +239,7 @@ int sqlite3_initialize(void){ sqlite3GlobalConfig.isPCacheInit = 1; rc = sqlite3OsInit(); } -#ifdef SQLITE_ENABLE_MEMDB +#ifdef SQLITE_ENABLE_DESERIALIZE if( rc==SQLITE_OK ){ rc = sqlite3MemdbInit(); } diff --git a/src/memdb.c b/src/memdb.c index 88eaaba4ee..646f788feb 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -16,7 +16,7 @@ ** This file also implements interface sqlite3_serialize() and ** sqlite3_deserialize(). */ -#ifdef SQLITE_ENABLE_MEMDB +#ifdef SQLITE_ENABLE_DESERIALIZE #include "sqliteInt.h" /* @@ -568,4 +568,4 @@ int sqlite3MemdbInit(void){ memdb_vfs.szOsFile = sz; return sqlite3_vfs_register(&memdb_vfs, 0); } -#endif /* SQLITE_ENABLE_MEMDB */ +#endif /* SQLITE_ENABLE_DESERIALIZE */ diff --git a/src/pager.c b/src/pager.c index 175c94ddd8..f4ac88c206 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4723,7 +4723,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 */ @@ -4851,7 +4855,9 @@ int sqlite3PagerOpen( int fout = 0; /* VFS flags returned by xOpen() */ rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); assert( !memDb ); +#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, diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 75a96d50d6..4e7939ebda 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8762,6 +8762,9 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); ** 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 */ @@ -8773,6 +8776,17 @@ unsigned char *sqlite3_serialize( /* ** CAPI3REF: Flags for sqlite3_serialize ** EXPERIMENTAL +** +** 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 */ @@ -8802,6 +8816,9 @@ unsigned char *sqlite3_serialize( ** 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 */ @@ -8816,8 +8833,23 @@ int sqlite3_deserialize( ** CAPI3REF: Flags for sqlite3_deserialize() ** EXPERIMENTAL ** -** The following are allowed values for the 6th argument (the "flags" or "F" -** argument) of the [sqlite3_deserialize()] interface. +** 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 usign 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() */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 341cfe97a6..3f34f48e15 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4024,7 +4024,7 @@ int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); const char *sqlite3ErrName(int); #endif -#ifdef SQLITE_ENABLE_MEMDB +#ifdef SQLITE_ENABLE_DESERIALIZE int sqlite3MemdbInit(void); #endif diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 878cdd961d..285fbbda2e 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -2420,7 +2420,7 @@ static int SQLITE_TCLAPI DbObjCmd( ** Reopen DATABASE (default "main") using the content in $VALUE */ case DB_DESERIALIZE: { -#ifndef SQLITE_ENABLE_MEMDB +#ifndef SQLITE_ENABLE_DESERIALIZE Tcl_AppendResult(interp, "MEMDB not available in this build", (char*)0); rc = TCL_ERROR; @@ -2942,7 +2942,7 @@ static int SQLITE_TCLAPI DbObjCmd( ** Return a serialization of a database. */ case DB_SERIALIZE: { -#ifndef SQLITE_ENABLE_MEMDB +#ifndef SQLITE_ENABLE_DESERIALIZE Tcl_AppendResult(interp, "MEMDB not available in this build", (char*)0); rc = TCL_ERROR; diff --git a/src/test_config.c b/src/test_config.c index de693850d3..aa0626ab2d 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -148,10 +148,10 @@ static void set_options(Tcl_Interp *interp){ Tcl_SetVar2(interp, "sqlite_options", "hiddencolumns", "0", TCL_GLOBAL_ONLY); #endif -#ifdef SQLITE_ENABLE_MEMDB - Tcl_SetVar2(interp, "sqlite_options", "memdb", "1", TCL_GLOBAL_ONLY); +#ifdef SQLITE_ENABLE_DESERIALIZE + Tcl_SetVar2(interp, "sqlite_options", "deserialize", "1", TCL_GLOBAL_ONLY); #else - Tcl_SetVar2(interp, "sqlite_options", "memdb", "0", TCL_GLOBAL_ONLY); + Tcl_SetVar2(interp, "sqlite_options", "deserialize", "0", TCL_GLOBAL_ONLY); #endif #ifdef SQLITE_ENABLE_MEMSYS3 diff --git a/test/memdb1.test b/test/memdb1.test index 48f9fca5ec..b52517fcf3 100644 --- a/test/memdb1.test +++ b/test/memdb1.test @@ -17,7 +17,7 @@ source $testdir/tester.tcl set testprefix memdb1 do_not_use_codec -ifcapable !memdb { +ifcapable !deserialize { finish_test return } From 4811a710af213de51e1ca93d293878d87fe69ef6 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 7 Mar 2018 01:37:05 +0000 Subject: [PATCH 21/67] Mark an unreachable branch using NEVER(). FossilOrigin-Name: fadbc5e23f93bedd705bdc83cd3781b3821a231034bae5b942c94da77227721c --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/memdb.c | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 18c42ee4e2..815ce0cb70 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sdocumentation\sfor\ssqlite3_serialize()\sand\ssqlite3_deserialize().\nChange\sthe\sname\sof\sthe\scompile-time\soption\sto\senable\sthese\sinterfaces\nfrom\sSQLITE_ENABLE_MEMDB\sto\sSQLITE_ENABLE_DESERIALIZE. -D 2018-03-06T21:43:19.244 +C Mark\san\sunreachable\sbranch\susing\sNEVER(). +D 2018-03-07T01:37:05.387 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -460,7 +460,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c f5d49ef349a07df3b855885c4a0f3d8d688ca9a9c82093e9ed6a399a4826abea +F src/memdb.c 00ece105cf2cc1fcf0faf8151a1bcde50d19ae99437ee646b0cad457e469a896 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1710,7 +1710,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 b58ca4cb0c921e81efad527c80b220be120263cfdb04528ae26ecf8b8f66f44a -R 8d936538e4c856e0f588396347b85dcc +P f07e97aed435b02e1473053c0257ec5c89bf0b3e46076b7a9382de432bbc2497 +R 1be29732572fe3143eab743f97b3559e U drh -Z c61ba7a8db0957766315d0dc5cf0b993 +Z fc974f7768a62ed16a0f51a5a0679333 diff --git a/manifest.uuid b/manifest.uuid index 6fe0b07e1f..0219ff2513 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f07e97aed435b02e1473053c0257ec5c89bf0b3e46076b7a9382de432bbc2497 \ No newline at end of file +fadbc5e23f93bedd705bdc83cd3781b3821a231034bae5b942c94da77227721c \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 646f788feb..320c70865f 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -564,7 +564,10 @@ int sqlite3MemdbInit(void){ sqlite3_vfs *pLower = sqlite3_vfs_find(0); int sz = pLower->szOsFile; memdb_vfs.pAppData = pLower; - if( sz Date: Wed, 7 Mar 2018 14:42:17 +0000 Subject: [PATCH 22/67] Fix utility compilation issues with MSVC. FossilOrigin-Name: 5bd5a79898790bef150b2bc7f275333444b1a723385e595931377ff4d32190bf --- Makefile.msc | 13 ++++++------- ext/expert/expert.c | 3 ++- ext/misc/scrub.c | 4 ++-- manifest | 30 ++++++++++++++++-------------- manifest.uuid | 2 +- test/fuzzcheck.c | 8 +++++++- test/kvtest.c | 6 ++++-- test/ossfuzz.c | 8 +++++++- test/ossshell.c | 8 +++++++- 9 files changed, 52 insertions(+), 30 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 0f906c80d5..a34377b4d3 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1621,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. @@ -1689,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 @@ -2370,11 +2369,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 @@ -2427,9 +2426,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) @@ -2470,6 +2466,9 @@ clean: 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 dbfuzz.exe 2>NUL + del /Q kvtest.exe ossshell.exe scrub.exe 2>NUL + del /Q showshm.exe sqlite3_checker.exe sqlite3_expert.exe 2>NUL del /Q fts5.* fts5parse.* 2>NUL del /Q lsm.h lsm1.c 2>NUL # <> 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/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/manifest b/manifest index 2b24be0d1e..bf79846a39 100644 --- a/manifest +++ b/manifest @@ -1,10 +1,10 @@ -C Add\sthe\ssqlite3_serialize()\sand\ssqlite3_deserialize()\sinterfaces,\senabled\nwhen\sthe\s-DSQLITE_ENABLE_DESERIALIZE\scompile-time\soption\sis\sused. -D 2018-03-07T13:01:54.138 +C Fix\sutility\scompilation\sissues\swith\sMSVC. +D 2018-03-07T14:42:17.408 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 28df1e20dd77b9613ce5b65659a4ab9ab19a1f0d885f1eae2399baf0ebc43f46 +F Makefile.msc 7e8763e25bc88dd517e8475bcd61d77cf643c8e9e904d2a0c3c1d3012b298641 F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 F VERSION cdf91ac446255ecf3d8f6d8c3ee40d64123235ae5b3cef29d344e61b45ec3759 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -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 @@ -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 @@ -935,7 +935,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 @@ -1020,7 +1020,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 @@ -1120,8 +1120,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 @@ -1710,8 +1710,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 797e02e0ee703ab0fd53e26ba5c96ac7429b8022522bec201423718d508acf24 fadbc5e23f93bedd705bdc83cd3781b3821a231034bae5b942c94da77227721c -R 9c6c7f909066e499dd8cfc98440c4493 -T +closed fadbc5e23f93bedd705bdc83cd3781b3821a231034bae5b942c94da77227721c -U drh -Z f6ec1840cf83626768a920eb621f59f9 +P fc42d31d6fca21abc5377a463ed800e3066b2f3fbd2d85cb486f402d2ae7cb15 +R 49f05f1d65bbeae0b87d971f79e7a40c +T *branch * msvcFixes +T *sym-msvcFixes * +T -sym-trunk * +U mistachkin +Z 37796102b64447100403e8be38ecf33a diff --git a/manifest.uuid b/manifest.uuid index 7e63a2f179..1639470573 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc42d31d6fca21abc5377a463ed800e3066b2f3fbd2d85cb486f402d2ae7cb15 \ No newline at end of file +5bd5a79898790bef150b2bc7f275333444b1a723385e595931377ff4d32190bf \ No newline at end of file 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/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 */ From 23355215fb0559fc078084abb2d160f7009d9844 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 7 Mar 2018 14:49:32 +0000 Subject: [PATCH 23/67] Fix harmless compiler warning in FTS5. FossilOrigin-Name: 2d544711c7e9f4c2c3ca7ee7d588948d048da82e63c82f41c999fce947d6661d --- ext/fts5/fts5_expr.c | 2 +- manifest | 15 ++++++--------- manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) 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/manifest b/manifest index bf79846a39..8691ecbc73 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sutility\scompilation\sissues\swith\sMSVC. -D 2018-03-07T14:42:17.408 +C Fix\sharmless\scompiler\swarning\sin\sFTS5. +D 2018-03-07T14:49:32.294 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -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 @@ -1710,10 +1710,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 fc42d31d6fca21abc5377a463ed800e3066b2f3fbd2d85cb486f402d2ae7cb15 -R 49f05f1d65bbeae0b87d971f79e7a40c -T *branch * msvcFixes -T *sym-msvcFixes * -T -sym-trunk * +P 5bd5a79898790bef150b2bc7f275333444b1a723385e595931377ff4d32190bf +R 8691caa0eeb15b0c1d92fa042c93988a U mistachkin -Z 37796102b64447100403e8be38ecf33a +Z 4c51f8288d5bfd11277f1046c62d8466 diff --git a/manifest.uuid b/manifest.uuid index 1639470573..b925eeca5a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5bd5a79898790bef150b2bc7f275333444b1a723385e595931377ff4d32190bf \ No newline at end of file +2d544711c7e9f4c2c3ca7ee7d588948d048da82e63c82f41c999fce947d6661d \ No newline at end of file From b649be3c3b225e6fb1f15d73f222820bf48e5ba3 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 7 Mar 2018 14:53:36 +0000 Subject: [PATCH 24/67] Another tweak to the MSVC clean target. FossilOrigin-Name: 493abf10bf7b2ea5a4bc430bec786598776f76985ab2d99c7d5117a9a9ff632c --- Makefile.msc | 4 ++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index a34377b4d3..daedea2945 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2465,10 +2465,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 2>NUL del /Q kvtest.exe ossshell.exe scrub.exe 2>NUL - del /Q showshm.exe sqlite3_checker.exe sqlite3_expert.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/manifest b/manifest index 8691ecbc73..a4d377faba 100644 --- a/manifest +++ b/manifest @@ -1,10 +1,10 @@ -C Fix\sharmless\scompiler\swarning\sin\sFTS5. -D 2018-03-07T14:49:32.294 +C Another\stweak\sto\sthe\sMSVC\sclean\starget. +D 2018-03-07T14:53:36.069 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 7e8763e25bc88dd517e8475bcd61d77cf643c8e9e904d2a0c3c1d3012b298641 +F Makefile.msc 9d5201ef7e4f575d94ec6cd8a29a40ec3e4e150a01903afad385ccde72b30759 F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 F VERSION cdf91ac446255ecf3d8f6d8c3ee40d64123235ae5b3cef29d344e61b45ec3759 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1710,7 +1710,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 5bd5a79898790bef150b2bc7f275333444b1a723385e595931377ff4d32190bf -R 8691caa0eeb15b0c1d92fa042c93988a +P 2d544711c7e9f4c2c3ca7ee7d588948d048da82e63c82f41c999fce947d6661d +R c3c40587d5d534a8ffacd8dd767d10ed U mistachkin -Z 4c51f8288d5bfd11277f1046c62d8466 +Z aac660c249afe01430b67bc20c08481b diff --git a/manifest.uuid b/manifest.uuid index b925eeca5a..e2afda9942 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2d544711c7e9f4c2c3ca7ee7d588948d048da82e63c82f41c999fce947d6661d \ No newline at end of file +493abf10bf7b2ea5a4bc430bec786598776f76985ab2d99c7d5117a9a9ff632c \ No newline at end of file From 391ac1b95976456b8a494bedb39a44851e85e905 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 7 Mar 2018 15:54:39 +0000 Subject: [PATCH 25/67] Update the autoconf Makefile for MSVC. FossilOrigin-Name: 36fec7a4a75006d860aaf3ea6707cea25c5e16f2ac05c21c27fde80f3bfeec63 --- autoconf/Makefile.msc | 1 + manifest | 13 ++++++------- manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) 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/manifest b/manifest index 23c9ad5e33..c7b99317a7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\svarious\scompilation\sissues\sseen\swith\sMSVC. -D 2018-03-07T15:19:22.741 +C Update\sthe\sautoconf\sMakefile\sfor\sMSVC. +D 2018-03-07T15:54:39.405 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 @@ -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 @@ -1710,8 +1710,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 fc42d31d6fca21abc5377a463ed800e3066b2f3fbd2d85cb486f402d2ae7cb15 493abf10bf7b2ea5a4bc430bec786598776f76985ab2d99c7d5117a9a9ff632c -R c3c40587d5d534a8ffacd8dd767d10ed -T +closed 493abf10bf7b2ea5a4bc430bec786598776f76985ab2d99c7d5117a9a9ff632c +P d6fa938919dbb3fe73ccdd3cbf0e9264d524ed79125f93f977a7d91c425db821 +R 2a9575451278c1a4c315fccdfdca1672 U mistachkin -Z e2b35eb80754b116b2f8675d8dc4cf43 +Z e57bc875167796d343177373820c09eb diff --git a/manifest.uuid b/manifest.uuid index 64342d3a6e..00e217aaf3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d6fa938919dbb3fe73ccdd3cbf0e9264d524ed79125f93f977a7d91c425db821 \ No newline at end of file +36fec7a4a75006d860aaf3ea6707cea25c5e16f2ac05c21c27fde80f3bfeec63 \ No newline at end of file From f94c1902b95bf9f4b963972e9e5090a3d537607e Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 7 Mar 2018 20:48:21 +0000 Subject: [PATCH 26/67] Add the sessionfuzz test program and data obtained from a week of running AFL. Automatically run this test program on any "make test" on unix. FossilOrigin-Name: ecaedfe596d4c05546bfd798fdca94aff6a81f55be7b17ddb65fc5547c4b5aa6 --- Makefile.in | 12 +- main.mk | 13 +- manifest | 18 +- manifest.uuid | 2 +- test/sessionfuzz-data1.db | Bin 0 -> 258048 bytes test/sessionfuzz.c | 1010 +++++++++++++++++++++++++++++++++++++ 6 files changed, 1040 insertions(+), 15 deletions(-) create mode 100644 test/sessionfuzz-data1.db create mode 100644 test/sessionfuzz.c diff --git a/Makefile.in b/Makefile.in index 862f397977..96ef34009e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -650,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) @@ -1166,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/main.mk b/main.mk index cdbef4e44e..e5722c5827 100644 --- a/main.mk +++ b/main.mk @@ -575,6 +575,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 +898,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. # @@ -1066,6 +1072,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 c7b99317a7..340c35486e 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Update\sthe\sautoconf\sMakefile\sfor\sMSVC. -D 2018-03-07T15:54:39.405 +C Add\sthe\ssessionfuzz\stest\sprogram\sand\sdata\sobtained\sfrom\sa\sweek\sof\srunning\nAFL.\s\sAutomatically\srun\sthis\stest\sprogram\son\sany\s"make\stest"\son\sunix. +D 2018-03-07T20:48:21.666 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea -F Makefile.in 1d5a68043cc4d8a6e45b37e2639b148cdd7973aa75e90ec71e12d55cd95e32c0 +F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 9d5201ef7e4f575d94ec6cd8a29a40ec3e4e150a01903afad385ccde72b30759 F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 @@ -411,7 +411,7 @@ F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 761e48fd24449071b8f8480449122fa59c052904666f72d803c64ae09b139298 +F main.mk 63668484c95454af7fc04a384da27ac556f27368d6d0c345e405e1677c66768f F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -1215,6 +1215,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 8167652afa13b6363825151c44ebcad9c993651e84537be94ec58e5004823f3d F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 F test/shared3.test ab693f9b6e156b8bfb2a0ad94f29fe69602a5d38 @@ -1710,7 +1712,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 d6fa938919dbb3fe73ccdd3cbf0e9264d524ed79125f93f977a7d91c425db821 -R 2a9575451278c1a4c315fccdfdca1672 -U mistachkin -Z e57bc875167796d343177373820c09eb +P 36fec7a4a75006d860aaf3ea6707cea25c5e16f2ac05c21c27fde80f3bfeec63 +R e9b5633f22c17863b715b8220bf589aa +U drh +Z 0dea7c28192df29380ebcdd90caa6963 diff --git a/manifest.uuid b/manifest.uuid index 00e217aaf3..2cbb84b4ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -36fec7a4a75006d860aaf3ea6707cea25c5e16f2ac05c21c27fde80f3bfeec63 \ No newline at end of file +ecaedfe596d4c05546bfd798fdca94aff6a81f55be7b17ddb65fc5547c4b5aa6 \ No newline at end of file diff --git a/test/sessionfuzz-data1.db b/test/sessionfuzz-data1.db new file mode 100644 index 0000000000000000000000000000000000000000..df10e10bcd7ad96b512dac036861c4e485aa5268 GIT binary patch literal 258048 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 R%*YZYMtM +#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!=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 *pStmt; + 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, &pStmt, 0); + if( rc ){ + fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db2)); + exit(1); + } + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + if( bVerbose ){ + printf("%s/%s:", fileTail(argv[i]), sqlite3_column_text(pStmt,0)); + fflush(stdout); + } + runSql(db, "BEGIN"); + pChgset = (unsigned char*)sqlite3_column_blob(pStmt, 1); + nChgset = sqlite3_column_bytes(pStmt, 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(pStmt); + 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; +} From 98cb7a489424aa1a8849de40f3d25a9d26675f53 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 7 Mar 2018 21:13:49 +0000 Subject: [PATCH 27/67] Enable compilation of 'sessionfuzz' tool using MSVC. FossilOrigin-Name: c58de43b8f2723d659fc9820caf667e215fdfa9aa2d7337fc82ba5b6f8db2e4c --- Makefile.msc | 3 +++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- test/sessionfuzz.c | 10 +++++++++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index daedea2945..efb99085b6 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -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) diff --git a/manifest b/manifest index 340c35486e..ea00f944ce 100644 --- a/manifest +++ b/manifest @@ -1,10 +1,10 @@ -C Add\sthe\ssessionfuzz\stest\sprogram\sand\sdata\sobtained\sfrom\sa\sweek\sof\srunning\nAFL.\s\sAutomatically\srun\sthis\stest\sprogram\son\sany\s"make\stest"\son\sunix. -D 2018-03-07T20:48:21.666 +C Enable\scompilation\sof\s'sessionfuzz'\stool\susing\sMSVC. +D 2018-03-07T21:13:49.693 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 9d5201ef7e4f575d94ec6cd8a29a40ec3e4e150a01903afad385ccde72b30759 +F Makefile.msc 07126468817b997702c049d78522c4cd48405e2a4961f6822b4103925d61934a F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 F VERSION cdf91ac446255ecf3d8f6d8c3ee40d64123235ae5b3cef29d344e61b45ec3759 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1216,7 +1216,7 @@ F test/selectG.test 089f7d3d7e6db91566f00b036cb353107a2cca6220eb1cb264085a836dae F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be F test/sessionfuzz-data1.db 1f8d5def831f19b1c74571037f0d53a588ea49a6c4ca2a028fc0c27ef896dbcb -F test/sessionfuzz.c 8167652afa13b6363825151c44ebcad9c993651e84537be94ec58e5004823f3d +F test/sessionfuzz.c e23de0749df7d100aae33c1c3e371eaad2a1a1dab316f4ed62f73b2b0497e487 F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 F test/shared3.test ab693f9b6e156b8bfb2a0ad94f29fe69602a5d38 @@ -1712,7 +1712,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 36fec7a4a75006d860aaf3ea6707cea25c5e16f2ac05c21c27fde80f3bfeec63 -R e9b5633f22c17863b715b8220bf589aa -U drh -Z 0dea7c28192df29380ebcdd90caa6963 +P ecaedfe596d4c05546bfd798fdca94aff6a81f55be7b17ddb65fc5547c4b5aa6 +R b75a518c9fa7503c62c63e3b78fba859 +U mistachkin +Z d724806c5b56199e78b36c783819acb6 diff --git a/manifest.uuid b/manifest.uuid index 2cbb84b4ca..98bc1d6fcb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ecaedfe596d4c05546bfd798fdca94aff6a81f55be7b17ddb65fc5547c4b5aa6 \ No newline at end of file +c58de43b8f2723d659fc9820caf667e215fdfa9aa2d7337fc82ba5b6f8db2e4c \ No newline at end of file diff --git a/test/sessionfuzz.c b/test/sessionfuzz.c index 7a23b12343..0a97750b16 100644 --- a/test/sessionfuzz.c +++ b/test/sessionfuzz.c @@ -50,6 +50,14 @@ /* ** 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 @@ -802,7 +810,7 @@ static void readFile(const char *zName, void **ppData, int *pnData){ } nRead = fread(pBuf, 1, nIn, in); fclose(in); - if( nRead!=nIn ){ + if( nRead!=(size_t)nIn ){ fprintf(stderr, "Read only %d of %d bytes from %s\n", (int)nRead, (int)nIn, zName); exit(1); From 069720ea8bdd376e94a8b886aaa0e95ffbfbfbfe Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 7 Mar 2018 21:29:15 +0000 Subject: [PATCH 28/67] Fix harmless compiler warning. FossilOrigin-Name: 706800ba377e4a1f615ee6ab44530742f23e1d1be5b658608ca2fd352b363cb2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/sessionfuzz.c | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index ea00f944ce..bc75fd54b4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enable\scompilation\sof\s'sessionfuzz'\stool\susing\sMSVC. -D 2018-03-07T21:13:49.693 +C Fix\sharmless\scompiler\swarning. +D 2018-03-07T21:29:15.655 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -1216,7 +1216,7 @@ F test/selectG.test 089f7d3d7e6db91566f00b036cb353107a2cca6220eb1cb264085a836dae F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be F test/sessionfuzz-data1.db 1f8d5def831f19b1c74571037f0d53a588ea49a6c4ca2a028fc0c27ef896dbcb -F test/sessionfuzz.c e23de0749df7d100aae33c1c3e371eaad2a1a1dab316f4ed62f73b2b0497e487 +F test/sessionfuzz.c b0fcdcf757451957e17396a3af5171f1fdf9b2babc81da9fa35675df46c4729a F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 F test/shared3.test ab693f9b6e156b8bfb2a0ad94f29fe69602a5d38 @@ -1712,7 +1712,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 ecaedfe596d4c05546bfd798fdca94aff6a81f55be7b17ddb65fc5547c4b5aa6 -R b75a518c9fa7503c62c63e3b78fba859 +P c58de43b8f2723d659fc9820caf667e215fdfa9aa2d7337fc82ba5b6f8db2e4c +R b5cfebcb148b6bd12ea0f9c75b98d805 U mistachkin -Z d724806c5b56199e78b36c783819acb6 +Z d81d750d5f0547895baa87956059aaca diff --git a/manifest.uuid b/manifest.uuid index 98bc1d6fcb..473964b8a1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c58de43b8f2723d659fc9820caf667e215fdfa9aa2d7337fc82ba5b6f8db2e4c \ No newline at end of file +706800ba377e4a1f615ee6ab44530742f23e1d1be5b658608ca2fd352b363cb2 \ No newline at end of file diff --git a/test/sessionfuzz.c b/test/sessionfuzz.c index 0a97750b16..7f2de51092 100644 --- a/test/sessionfuzz.c +++ b/test/sessionfuzz.c @@ -940,7 +940,7 @@ int main(int argc, char **argv){ && memcmp(pChgset, "SQLite format 3", 16)==0 ){ sqlite3 *db2; - sqlite3_stmt *pStmt; + sqlite3_stmt *pStmt2; int nCase = 0; /* This file is an SQL Archive containing many changesets */ if( !bVerbose ){ printf("%s: ", fileTail(argv[i])); fflush(stdout); } @@ -951,19 +951,19 @@ int main(int argc, char **argv){ 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, &pStmt, 0); + " FROM sqlar", -1, &pStmt2, 0); if( rc ){ fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db2)); exit(1); } - while( SQLITE_ROW==sqlite3_step(pStmt) ){ + while( SQLITE_ROW==sqlite3_step(pStmt2) ){ if( bVerbose ){ - printf("%s/%s:", fileTail(argv[i]), sqlite3_column_text(pStmt,0)); + printf("%s/%s:", fileTail(argv[i]), sqlite3_column_text(pStmt2,0)); fflush(stdout); } runSql(db, "BEGIN"); - pChgset = (unsigned char*)sqlite3_column_blob(pStmt, 1); - nChgset = sqlite3_column_bytes(pStmt, 1); + 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); @@ -972,7 +972,7 @@ int main(int argc, char **argv){ runSql(db, "ROLLBACK"); nCase++; } - sqlite3_finalize(pStmt); + sqlite3_finalize(pStmt2); sqlite3_close(db2); if( bVerbose ) printf("%s: ", fileTail(argv[i])); printf(" %d cases, 0 crashes\n", nCase); From f7c8a35b8d19cc7db456b815814d574340501b40 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 7 Mar 2018 21:39:25 +0000 Subject: [PATCH 29/67] Fix harmless compiler warnings in the 'dbdump' tool. FossilOrigin-Name: 2b9bb2664c56dd3280b4aad05b7f64dd23e5b992b5621a48dbfdb7c358d0f3ae --- ext/misc/dbdump.c | 29 ++++++++++++++--------------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 21 insertions(+), 22 deletions(-) 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/manifest b/manifest index bc75fd54b4..2e92b3372e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarning. -D 2018-03-07T21:29:15.655 +C Fix\sharmless\scompiler\swarnings\sin\sthe\s'dbdump'\stool. +D 2018-03-07T21:39:25.185 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -275,7 +275,7 @@ F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/completion.c 52c3f01523e3e387eb321b4739a89d1fe47cbe6025aa1f2d8d3685e9e365df0f 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/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 @@ -1712,7 +1712,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 c58de43b8f2723d659fc9820caf667e215fdfa9aa2d7337fc82ba5b6f8db2e4c -R b5cfebcb148b6bd12ea0f9c75b98d805 +P 706800ba377e4a1f615ee6ab44530742f23e1d1be5b658608ca2fd352b363cb2 +R e2a5b0d26438383f9f88dd639ce8d76f U mistachkin -Z d81d750d5f0547895baa87956059aaca +Z f5b3b21114d3dd71d665bb1ec24db52c diff --git a/manifest.uuid b/manifest.uuid index 473964b8a1..c939e0bff3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -706800ba377e4a1f615ee6ab44530742f23e1d1be5b658608ca2fd352b363cb2 \ No newline at end of file +2b9bb2664c56dd3280b4aad05b7f64dd23e5b992b5621a48dbfdb7c358d0f3ae \ No newline at end of file From 7bdbe301f6cd3a5d085a6db275a530789b4cf1e4 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 8 Mar 2018 16:36:23 +0000 Subject: [PATCH 30/67] Updates to documentation on sqlite3_serialize() and sqlite3_deserialize(). No changes to code. FossilOrigin-Name: e71ceb6089695c651aaf1fa8662c5caf771ac9efc2f2e8efa0eddae6a6a389ea --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 6 +----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 2e92b3372e..25b6a5d96b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sthe\s'dbdump'\stool. -D 2018-03-07T21:39:25.185 +C Updates\sto\sdocumentation\son\ssqlite3_serialize()\sand\ssqlite3_deserialize().\nNo\schanges\sto\scode. +D 2018-03-08T16:36:23.940 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -491,7 +491,7 @@ F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c f02352ac5cbb6fad3804add825743b924cfb6c742ba2e8666d726828a9985d73 F src/shell.c.in 8c6ea9b4da9450c26551bbe7de24170e5c6c6e3af4dedaa663e3f5ef05659a96 -F src/sqlite.h.in 8125abd15ff083591e53e1bc874319fbfaf239b1c57563c9685bd42723f8926a +F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d F src/sqliteInt.h 2ef60a6d9a50e6eef224e9eae71b29a9fb91c301e882d9fbbb77afd50b6cf815 @@ -1712,7 +1712,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 706800ba377e4a1f615ee6ab44530742f23e1d1be5b658608ca2fd352b363cb2 -R e2a5b0d26438383f9f88dd639ce8d76f -U mistachkin -Z f5b3b21114d3dd71d665bb1ec24db52c +P 2b9bb2664c56dd3280b4aad05b7f64dd23e5b992b5621a48dbfdb7c358d0f3ae +R a4ddb21e887f89343503f6fedbd962f4 +U drh +Z 8348571f1e5e7d50ec4cea61e99d0d9b diff --git a/manifest.uuid b/manifest.uuid index c939e0bff3..afde4aed5e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2b9bb2664c56dd3280b4aad05b7f64dd23e5b992b5621a48dbfdb7c358d0f3ae \ No newline at end of file +e71ceb6089695c651aaf1fa8662c5caf771ac9efc2f2e8efa0eddae6a6a389ea \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 4e7939ebda..1d7e191442 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8731,7 +8731,6 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); /* ** CAPI3REF: Serialize a database -** EXPERIMENTAL ** ** 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. @@ -8751,7 +8750,7 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); ** 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 contigous memory +** 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. @@ -8775,7 +8774,6 @@ unsigned char *sqlite3_serialize( /* ** CAPI3REF: Flags for sqlite3_serialize -** EXPERIMENTAL ** ** Zero or more of the following constants can be OR-ed together for ** the F argument to [sqlite3_serialize(D,S,P,F)]. @@ -8792,7 +8790,6 @@ unsigned char *sqlite3_serialize( /* ** CAPI3REF: Deserialize a database -** EXPERIMENTAL ** ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the ** [database connection] D to disconnection from database S and then @@ -8831,7 +8828,6 @@ int sqlite3_deserialize( /* ** CAPI3REF: Flags for sqlite3_deserialize() -** EXPERIMENTAL ** ** The following are allowed values for 6th argument (the F argument) to ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. From 83686928156ce3da8067ddab96c9a18695f51103 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 8 Mar 2018 18:09:22 +0000 Subject: [PATCH 31/67] Include the 'sessionfuzz' tool in the clean target for MSVC. FossilOrigin-Name: 0f5a8666b8b479bb6e470590659c1775fb9b0d6a9eee931cb48f98651cd7ffcb --- Makefile.msc | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index efb99085b6..bb64a05d11 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2469,7 +2469,7 @@ clean: del /Q sqlite-*-output.vsix 2>NUL del /Q fuzzershell.exe fuzzcheck.exe sqldiff.exe dbhash.exe 2>NUL del /Q sqltclsh.* 2>NUL - del /Q dbfuzz.exe 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 diff --git a/manifest b/manifest index 25b6a5d96b..ce370d8866 100644 --- a/manifest +++ b/manifest @@ -1,10 +1,10 @@ -C Updates\sto\sdocumentation\son\ssqlite3_serialize()\sand\ssqlite3_deserialize().\nNo\schanges\sto\scode. -D 2018-03-08T16:36:23.940 +C Include\sthe\s'sessionfuzz'\stool\sin\sthe\sclean\starget\sfor\sMSVC. +D 2018-03-08T18:09:22.587 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 07126468817b997702c049d78522c4cd48405e2a4961f6822b4103925d61934a +F Makefile.msc 8a6727b41a4626a5552016f4b0088b43fb14a32f53db1f47e83a0fefcb63c49a F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 F VERSION cdf91ac446255ecf3d8f6d8c3ee40d64123235ae5b3cef29d344e61b45ec3759 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1712,7 +1712,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 2b9bb2664c56dd3280b4aad05b7f64dd23e5b992b5621a48dbfdb7c358d0f3ae -R a4ddb21e887f89343503f6fedbd962f4 -U drh -Z 8348571f1e5e7d50ec4cea61e99d0d9b +P e71ceb6089695c651aaf1fa8662c5caf771ac9efc2f2e8efa0eddae6a6a389ea +R 1fe031cd6bb058f8744a7e6f09875326 +U mistachkin +Z 227831a2dc9b17b95cb11caffe20b647 diff --git a/manifest.uuid b/manifest.uuid index afde4aed5e..4d5a921a87 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e71ceb6089695c651aaf1fa8662c5caf771ac9efc2f2e8efa0eddae6a6a389ea \ No newline at end of file +0f5a8666b8b479bb6e470590659c1775fb9b0d6a9eee931cb48f98651cd7ffcb \ No newline at end of file From 3baed31edc4846f28f1cdb5ee445e09917561ceb Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 8 Mar 2018 18:14:41 +0000 Subject: [PATCH 32/67] Add the --append and --zip options of the CLI to the --help message. FossilOrigin-Name: f010c86ecef4a1aaad986fa8ceb8230814d6c909cc28ce19e55d63f592fee9d0 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 10 +++++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index ce370d8866..32c6698687 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Include\sthe\s'sessionfuzz'\stool\sin\sthe\sclean\starget\sfor\sMSVC. -D 2018-03-08T18:09:22.587 +C Add\sthe\s--append\sand\s--zip\soptions\sof\sthe\sCLI\sto\sthe\s--help\smessage. +D 2018-03-08T18:14:41.098 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ 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 8c6ea9b4da9450c26551bbe7de24170e5c6c6e3af4dedaa663e3f5ef05659a96 +F src/shell.c.in edbc1b73b1933faa1d6d4a3334df8b28ce72d98f4dac6e188f0f7e8247a5921f F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 e71ceb6089695c651aaf1fa8662c5caf771ac9efc2f2e8efa0eddae6a6a389ea -R 1fe031cd6bb058f8744a7e6f09875326 -U mistachkin -Z 227831a2dc9b17b95cb11caffe20b647 +P 0f5a8666b8b479bb6e470590659c1775fb9b0d6a9eee931cb48f98651cd7ffcb +R ce1d77085644868fc33b4f8c93cfe769 +U drh +Z 904d1e9f892c4a18cbcf09fc2991f0df diff --git a/manifest.uuid b/manifest.uuid index 4d5a921a87..eb81d37780 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f5a8666b8b479bb6e470590659c1775fb9b0d6a9eee931cb48f98651cd7ffcb \ No newline at end of file +f010c86ecef4a1aaad986fa8ceb8230814d6c909cc28ce19e55d63f592fee9d0 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 0782782a44..4324ef1bda 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -6307,7 +6307,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 @@ -7970,6 +7970,7 @@ 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" @@ -8004,6 +8005,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, @@ -8258,7 +8262,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 @@ -8325,7 +8329,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 From 6630f9407c1d1494c673349b4817f06668fee5b2 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 8 Mar 2018 19:56:52 +0000 Subject: [PATCH 33/67] Enable API armor handling for the new deserialize APIs. FossilOrigin-Name: 0798c91aa9d5d347680a9d80d420224297360e03341365d48aca829cd7c423db --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/memdb.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 32c6698687..a9e54d2b23 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--append\sand\s--zip\soptions\sof\sthe\sCLI\sto\sthe\s--help\smessage. -D 2018-03-08T18:14:41.098 +C Enable\sAPI\sarmor\shandling\sfor\sthe\snew\sdeserialize\sAPIs. +D 2018-03-08T19:56:52.999 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -460,7 +460,7 @@ F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 -F src/memdb.c 00ece105cf2cc1fcf0faf8151a1bcde50d19ae99437ee646b0cad457e469a896 +F src/memdb.c 2bcebf99f77270e4b30ee5fad749347a6296db1662b3a196593e5410780aea85 F src/memjournal.c 6f3d36a0a8f72f48f6c3c722f04301ac64f2515435fa42924293e46fc7994661 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c b021263554c8a3995e9d53193b8194b96d1ed28e06c3b532dd7f7d29cf0c7d53 @@ -1712,7 +1712,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 0f5a8666b8b479bb6e470590659c1775fb9b0d6a9eee931cb48f98651cd7ffcb -R ce1d77085644868fc33b4f8c93cfe769 -U drh -Z 904d1e9f892c4a18cbcf09fc2991f0df +P f010c86ecef4a1aaad986fa8ceb8230814d6c909cc28ce19e55d63f592fee9d0 +R 2cf64c7279465827e47c06ffb1b6ff5e +U mistachkin +Z 6649db53fbf91dfe5807c11f88365132 diff --git a/manifest.uuid b/manifest.uuid index eb81d37780..1ddf00bf2d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f010c86ecef4a1aaad986fa8ceb8230814d6c909cc28ce19e55d63f592fee9d0 \ No newline at end of file +0798c91aa9d5d347680a9d80d420224297360e03341365d48aca829cd7c423db \ No newline at end of file diff --git a/src/memdb.c b/src/memdb.c index 320c70865f..68bec75ea9 100644 --- a/src/memdb.c +++ b/src/memdb.c @@ -450,6 +450,13 @@ unsigned char *sqlite3_serialize( 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); @@ -520,6 +527,14 @@ int sqlite3_deserialize( 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); From 980e2cd39a950521a62fb1017825db3e035e7230 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 9 Mar 2018 12:46:34 +0000 Subject: [PATCH 34/67] Attempt to fix a harmless compiler warning from Clang. FossilOrigin-Name: bba1bfbde62733e14f458bf3b71cb00d4899a4ebae2553d6ed24d48495cdced1 --- ext/misc/zipfile.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index a400ae30e1..245dfefd39 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -1400,7 +1400,7 @@ 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. */ return SQLITE_CONSTRAINT; diff --git a/manifest b/manifest index a9e54d2b23..16434f9274 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enable\sAPI\sarmor\shandling\sfor\sthe\snew\sdeserialize\sAPIs. -D 2018-03-08T19:56:52.999 +C Attempt\sto\sfix\sa\sharmless\scompiler\swarning\sfrom\sClang. +D 2018-03-09T12:46:34.612 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -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 b326d0e789daf41faa9641609143c5be4aa5b76b7919955085f8d95359316251 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1712,7 +1712,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 f010c86ecef4a1aaad986fa8ceb8230814d6c909cc28ce19e55d63f592fee9d0 -R 2cf64c7279465827e47c06ffb1b6ff5e -U mistachkin -Z 6649db53fbf91dfe5807c11f88365132 +P 0798c91aa9d5d347680a9d80d420224297360e03341365d48aca829cd7c423db +R a4a63f736128503f57643dafdbf79b24 +U drh +Z be320216d4ac5b5f28d3cdb731b32cdb diff --git a/manifest.uuid b/manifest.uuid index 1ddf00bf2d..c262f42ab3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0798c91aa9d5d347680a9d80d420224297360e03341365d48aca829cd7c423db \ No newline at end of file +bba1bfbde62733e14f458bf3b71cb00d4899a4ebae2553d6ed24d48495cdced1 \ No newline at end of file From 6131adc074b94a33e5e64bb2bcbb125041d566e4 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 9 Mar 2018 14:06:11 +0000 Subject: [PATCH 35/67] Fix a test case in zipfilefault.test so that it only runs if JSON1 is available. FossilOrigin-Name: 072b244790893a699dc49d7a2cead85bed016f8e28d18ae7662fbeb3298cb235 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/zipfilefault.test | 15 ++++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 16434f9274..4a98be3ae3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Attempt\sto\sfix\sa\sharmless\scompiler\swarning\sfrom\sClang. -D 2018-03-09T12:46:34.612 +C Fix\sa\stest\scase\sin\szipfilefault.test\sso\sthat\sit\sonly\sruns\sif\sJSON1\sis\navailable. +D 2018-03-09T14:06:11.274 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -1613,7 +1613,7 @@ F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test 9c41628db7e8d9e8a0181e59ea5f189df311a9f6ce99cc376dc461f66db6f8dc F test/zipfile.test 44aa8af115cc3e8c905468768dc761260650a8fdfca57e10f9818f5f8008d340 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 @@ -1712,7 +1712,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 0798c91aa9d5d347680a9d80d420224297360e03341365d48aca829cd7c423db -R a4a63f736128503f57643dafdbf79b24 +P bba1bfbde62733e14f458bf3b71cb00d4899a4ebae2553d6ed24d48495cdced1 +R 496e24bddf44b574e82eb8175834be8d U drh -Z be320216d4ac5b5f28d3cdb731b32cdb +Z 073b37ca69ee0603afa6670c9845f5c1 diff --git a/manifest.uuid b/manifest.uuid index c262f42ab3..2a3f7fedb3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bba1bfbde62733e14f458bf3b71cb00d4899a4ebae2553d6ed24d48495cdced1 \ No newline at end of file +072b244790893a699dc49d7a2cead85bed016f8e28d18ae7662fbeb3298cb235 \ No newline at end of file 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 - From 2d066bbfd8bd9c2ce449306ba9fabb0a0e37b6fb Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 9 Mar 2018 14:11:36 +0000 Subject: [PATCH 36/67] Fix a problem in test file nockpt.test causing errors with SQLITE_DEFAULT_AUTOVACUUM builds. FossilOrigin-Name: e547c83f3eb71175574d4b49a0981b048bf525f57d36a2410d955cf1832bec22 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/nockpt.test | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4a98be3ae3..2c75a87646 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stest\scase\sin\szipfilefault.test\sso\sthat\sit\sonly\sruns\sif\sJSON1\sis\navailable. -D 2018-03-09T14:06:11.274 +C Fix\sa\sproblem\sin\stest\sfile\snockpt.test\scausing\serrors\swith\nSQLITE_DEFAULT_AUTOVACUUM\sbuilds. +D 2018-03-09T14:11:36.226 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -1098,7 +1098,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 @@ -1712,7 +1712,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 bba1bfbde62733e14f458bf3b71cb00d4899a4ebae2553d6ed24d48495cdced1 -R 496e24bddf44b574e82eb8175834be8d -U drh -Z 073b37ca69ee0603afa6670c9845f5c1 +P 072b244790893a699dc49d7a2cead85bed016f8e28d18ae7662fbeb3298cb235 +R 6dc3b230fc06bcdb426f0d9df4507aae +U dan +Z 04fd8a7a5b286ff443a6e6914aaf294b diff --git a/manifest.uuid b/manifest.uuid index 2a3f7fedb3..73ec81ab56 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -072b244790893a699dc49d7a2cead85bed016f8e28d18ae7662fbeb3298cb235 \ No newline at end of file +e547c83f3eb71175574d4b49a0981b048bf525f57d36a2410d955cf1832bec22 \ No newline at end of file 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'); From a10b999d1432302b4ff17730e18bc2928accd2fa Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 9 Mar 2018 15:24:33 +0000 Subject: [PATCH 37/67] Simplification to the shell_exec() mechanism in the CLI. FossilOrigin-Name: 72e8f529ac8a268611f16456b13d55cc6c62df7f1a0aaa78a169338a0d95b960 --- manifest | 14 +++--- manifest.uuid | 2 +- src/shell.c.in | 119 ++++++++++++++++++++++--------------------------- 3 files changed, 61 insertions(+), 74 deletions(-) diff --git a/manifest b/manifest index 2c75a87646..637047562e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\stest\sfile\snockpt.test\scausing\serrors\swith\nSQLITE_DEFAULT_AUTOVACUUM\sbuilds. -D 2018-03-09T14:11:36.226 +C Simplification\sto\sthe\sshell_exec()\smechanism\sin\sthe\sCLI. +D 2018-03-09T15:24:33.360 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ 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 edbc1b73b1933faa1d6d4a3334df8b28ce72d98f4dac6e188f0f7e8247a5921f +F src/shell.c.in 23eb750155ada4ff0b08b3c30897775ec1e2a286c984e32e329e3cdd6a43857e F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 072b244790893a699dc49d7a2cead85bed016f8e28d18ae7662fbeb3298cb235 -R 6dc3b230fc06bcdb426f0d9df4507aae -U dan -Z 04fd8a7a5b286ff443a6e6914aaf294b +P e547c83f3eb71175574d4b49a0981b048bf525f57d36a2410d955cf1832bec22 +R 259a72bbfbca34339b82532b413ba7d7 +U drh +Z 7e5be2d207864b4ee33e5e8cbd3e697a diff --git a/manifest.uuid b/manifest.uuid index 73ec81ab56..83f0cc2fff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e547c83f3eb71175574d4b49a0981b048bf525f57d36a2410d955cf1832bec22 \ No newline at end of file +72e8f529ac8a268611f16456b13d55cc6c62df7f1a0aaa78a169338a0d95b960 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 4324ef1bda..beb414851c 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2564,8 +2564,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 +2574,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 +2760,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,7 +2839,7 @@ 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); @@ -2875,7 +2865,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 +3128,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; @@ -5819,14 +5809,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 @@ -7096,7 +7083,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 +7722,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]; @@ -8412,7 +8399,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; @@ -8457,7 +8444,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; From 393344f928696129b887e37729eed7162f66def8 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 9 Mar 2018 16:37:05 +0000 Subject: [PATCH 38/67] Setting ".stats 2" in the CLI causes column metadata for each prepared statement to be displayed. FossilOrigin-Name: 7fea00fd96a8ab7e65734540edb907b6224659ae95d7e0504755f2610c545587 --- manifest | 12 ++++----- manifest.uuid | 2 +- src/shell.c.in | 71 +++++++++++++++++++++++++++++++++++--------------- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index 637047562e..139ec8eb62 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplification\sto\sthe\sshell_exec()\smechanism\sin\sthe\sCLI. -D 2018-03-09T15:24:33.360 +C Setting\s".stats\s2"\sin\sthe\sCLI\scauses\scolumn\smetadata\sfor\seach\nprepared\sstatement\sto\sbe\sdisplayed. +D 2018-03-09T16:37:05.324 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ 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 23eb750155ada4ff0b08b3c30897775ec1e2a286c984e32e329e3cdd6a43857e +F src/shell.c.in 754905107134107564345d43e74921f3a3b3f964827b2e2d5bc437ebba843eaf F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 e547c83f3eb71175574d4b49a0981b048bf525f57d36a2410d955cf1832bec22 -R 259a72bbfbca34339b82532b413ba7d7 +P 72e8f529ac8a268611f16456b13d55cc6c62df7f1a0aaa78a169338a0d95b960 +R e31c00c5775bc8c440f35c0a79819b6a U drh -Z 7e5be2d207864b4ee33e5e8cbd3e697a +Z c4b88c9fba10493862085e7979f0eebb diff --git a/manifest.uuid b/manifest.uuid index 83f0cc2fff..88ef7d3805 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -72e8f529ac8a268611f16456b13d55cc6c62df7f1a0aaa78a169338a0d95b960 \ No newline at end of file +7fea00fd96a8ab7e65734540edb907b6224659ae95d7e0504755f2610c545587 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index beb414851c..31e284c3ea 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2273,29 +2273,52 @@ 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); + 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, @@ -2339,7 +2362,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 +2372,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__ From 1bf208c7014eeab385f55e437189cee0974e2d44 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 9 Mar 2018 21:54:01 +0000 Subject: [PATCH 39/67] Enhance the ".ar" command in the CLI so that it is able to update and create ZIP Archives. FossilOrigin-Name: 9404765ef7487013f01ecf24c0a1f70040cd11e7dbb6378646d15de4e5660a40 --- manifest | 12 +++---- manifest.uuid | 2 +- src/shell.c.in | 93 +++++++++++++++++++++++++++++++++++++------------- 3 files changed, 77 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index 139ec8eb62..6776f25637 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Setting\s".stats\s2"\sin\sthe\sCLI\scauses\scolumn\smetadata\sfor\seach\nprepared\sstatement\sto\sbe\sdisplayed. -D 2018-03-09T16:37:05.324 +C Enhance\sthe\s".ar"\scommand\sin\sthe\sCLI\sso\sthat\sit\sis\sable\sto\supdate\sand\ncreate\sZIP\sArchives. +D 2018-03-09T21:54:01.608 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ 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 754905107134107564345d43e74921f3a3b3f964827b2e2d5bc437ebba843eaf +F src/shell.c.in b499275d69fffce0012681ddf0c00a2856b65af0028a7e5b9aee3886180e91e9 F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 72e8f529ac8a268611f16456b13d55cc6c62df7f1a0aaa78a169338a0d95b960 -R e31c00c5775bc8c440f35c0a79819b6a +P 7fea00fd96a8ab7e65734540edb907b6224659ae95d7e0504755f2610c545587 +R 85f130d4e717fcf952736cd9ba56b3e7 U drh -Z c4b88c9fba10493862085e7979f0eebb +Z 22e107de180218309232866a05b8494f diff --git a/manifest.uuid b/manifest.uuid index 88ef7d3805..cf7a4ad9e0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7fea00fd96a8ab7e65734540edb907b6224659ae95d7e0504755f2610c545587 \ No newline at end of file +9404765ef7487013f01ecf24c0a1f70040cd11e7dbb6378646d15de4e5660a40 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 31e284c3ea..facbca9979 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -3432,13 +3432,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 ){ @@ -3449,6 +3457,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); @@ -3463,7 +3473,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: { @@ -5258,8 +5268,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" @@ -5268,30 +5278,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" + " 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; } @@ -5313,20 +5363,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 ){ @@ -5358,7 +5405,7 @@ static int arDotCommand( 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) ){ From 69d2d35523b594667ece042307098667d89515a1 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 9 Mar 2018 22:18:53 +0000 Subject: [PATCH 40/67] Fix the .archive command in the CLI so that it actually compresses content. FossilOrigin-Name: 3c2e3c2d3dd5d951099ad8d9f74d3c20dae11dd5615d86a6e2283b28ff5b19aa --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 4 +--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 6776f25637..9f9966817e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\s".ar"\scommand\sin\sthe\sCLI\sso\sthat\sit\sis\sable\sto\supdate\sand\ncreate\sZIP\sArchives. -D 2018-03-09T21:54:01.608 +C Fix\sthe\s.archive\scommand\sin\sthe\sCLI\sso\sthat\sit\sactually\scompresses\scontent. +D 2018-03-09T22:18:53.260 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ 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 b499275d69fffce0012681ddf0c00a2856b65af0028a7e5b9aee3886180e91e9 +F src/shell.c.in b0aad8855b1c04ff4637c9f244a5537255f5d3dc6625e334454f5bd7d9794c61 F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 7fea00fd96a8ab7e65734540edb907b6224659ae95d7e0504755f2610c545587 -R 85f130d4e717fcf952736cd9ba56b3e7 +P 9404765ef7487013f01ecf24c0a1f70040cd11e7dbb6378646d15de4e5660a40 +R 1cd3e74076aeeddb27298f9b682d994e U drh -Z 22e107de180218309232866a05b8494f +Z bc56d5f75527153520ea094ccb89c567 diff --git a/manifest.uuid b/manifest.uuid index cf7a4ad9e0..a264a73a73 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9404765ef7487013f01ecf24c0a1f70040cd11e7dbb6378646d15de4e5660a40 \ No newline at end of file +3c2e3c2d3dd5d951099ad8d9f74d3c20dae11dd5615d86a6e2283b28ff5b19aa \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index facbca9979..7cdd361779 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -5278,7 +5278,7 @@ static int arCreateOrUpdateCommand( " WHEN '-' THEN length(data)\n" " WHEN 'd' THEN 0\n" " ELSE -1 END,\n" - " data\n" + " sqlar_compress(data)\n" " FROM fsdir(%Q,%Q)\n" " WHERE lsmode(mode) NOT LIKE '?%%';", "REPLACE INTO %s(name,mode,mtime,data)\n" @@ -5398,9 +5398,7 @@ 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); From ef29f73479509bde4964cef8c1699c5cb38854b5 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 10 Mar 2018 12:34:08 +0000 Subject: [PATCH 41/67] Fix the zipfile extension so that it is able to create symbolic link entries in the ZIP file even on systems like Win32 that do not support symbolic links on the native filesystem. FossilOrigin-Name: 2a4493f4ad2d09c1097e98e7086623669f3f252571884d515e51a98b1c6855e1 --- ext/misc/zipfile.c | 2 -- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index 245dfefd39..e6e611ba47 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -1390,9 +1390,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++){ diff --git a/manifest b/manifest index 9f9966817e..e6cd840a72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s.archive\scommand\sin\sthe\sCLI\sso\sthat\sit\sactually\scompresses\scontent. -D 2018-03-09T22:18:53.260 +C Fix\sthe\szipfile\sextension\sso\sthat\sit\sis\sable\sto\screate\ssymbolic\slink\sentries\nin\sthe\sZIP\sfile\seven\son\ssystems\slike\sWin32\sthat\sdo\snot\ssupport\ssymbolic\slinks\non\sthe\snative\sfilesystem. +D 2018-03-10T12:34:08.954 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -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 b326d0e789daf41faa9641609143c5be4aa5b76b7919955085f8d95359316251 +F ext/misc/zipfile.c ac84e5d65715746936d1c04ce172af0fbedb548823edd0cf33a76a2c0404e684 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1712,7 +1712,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 9404765ef7487013f01ecf24c0a1f70040cd11e7dbb6378646d15de4e5660a40 -R 1cd3e74076aeeddb27298f9b682d994e +P 3c2e3c2d3dd5d951099ad8d9f74d3c20dae11dd5615d86a6e2283b28ff5b19aa +R e466aae4911321d84355a45be2eb40b1 U drh -Z bc56d5f75527153520ea094ccb89c567 +Z 99fcb9daa2a8873fb80c767ff438d914 diff --git a/manifest.uuid b/manifest.uuid index a264a73a73..a783e24e92 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3c2e3c2d3dd5d951099ad8d9f74d3c20dae11dd5615d86a6e2283b28ff5b19aa \ No newline at end of file +2a4493f4ad2d09c1097e98e7086623669f3f252571884d515e51a98b1c6855e1 \ No newline at end of file From 70acb0aa6b89365df2ee284b9bd850128488a973 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 10 Mar 2018 12:53:20 +0000 Subject: [PATCH 42/67] Avoid harmless left-shifts of negative numbers in the zipfile extension when building ZIP archives of files with pre-DOS dates. FossilOrigin-Name: 16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d --- ext/misc/zipfile.c | 8 ++++++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index e6e611ba47..ae0e54813e 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -751,8 +751,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) diff --git a/manifest b/manifest index e6cd840a72..22ccaac86e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\szipfile\sextension\sso\sthat\sit\sis\sable\sto\screate\ssymbolic\slink\sentries\nin\sthe\sZIP\sfile\seven\son\ssystems\slike\sWin32\sthat\sdo\snot\ssupport\ssymbolic\slinks\non\sthe\snative\sfilesystem. -D 2018-03-10T12:34:08.954 +C Avoid\sharmless\sleft-shifts\sof\snegative\snumbers\sin\sthe\szipfile\sextension\nwhen\sbuilding\sZIP\sarchives\sof\sfiles\swith\spre-DOS\sdates. +D 2018-03-10T12:53:20.192 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -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 ac84e5d65715746936d1c04ce172af0fbedb548823edd0cf33a76a2c0404e684 +F ext/misc/zipfile.c 1a234c4e822a11e2e5aa6d402309b527e34e0813dba1b34d2723f050862864d2 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1712,7 +1712,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 3c2e3c2d3dd5d951099ad8d9f74d3c20dae11dd5615d86a6e2283b28ff5b19aa -R e466aae4911321d84355a45be2eb40b1 +P 2a4493f4ad2d09c1097e98e7086623669f3f252571884d515e51a98b1c6855e1 +R b996514daf8ccd4118140541121adf76 U drh -Z 99fcb9daa2a8873fb80c767ff438d914 +Z 3a20f1e017065f65b485c6880eea221e diff --git a/manifest.uuid b/manifest.uuid index a783e24e92..22a9a1cccd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2a4493f4ad2d09c1097e98e7086623669f3f252571884d515e51a98b1c6855e1 \ No newline at end of file +16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d \ No newline at end of file From 41a6f2cb6d07fdab445ec93bb8ce92e348134f0e Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 10 Mar 2018 13:21:41 +0000 Subject: [PATCH 43/67] Improved error messages from the zipfile extension. FossilOrigin-Name: f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 --- ext/misc/zipfile.c | 26 ++++++++++++++++++++------ manifest | 14 +++++++------- manifest.uuid | 2 +- test/zipfile.test | 17 ++++++++--------- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index ae0e54813e..96a2815951 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -473,9 +473,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); } @@ -1238,7 +1246,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]); @@ -1256,7 +1264,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); @@ -1405,6 +1413,7 @@ static int zipfileGetMode( 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; @@ -1535,9 +1544,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; } @@ -1557,6 +1569,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 ){ @@ -1603,6 +1616,7 @@ static int zipfileUpdate( ZipfileEntry *p; for(p=pTab->pFirstEntry; p; p=p->pNext){ if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){ + zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath); rc = SQLITE_CONSTRAINT; break; } diff --git a/manifest b/manifest index 22ccaac86e..43bf7a1064 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sharmless\sleft-shifts\sof\snegative\snumbers\sin\sthe\szipfile\sextension\nwhen\sbuilding\sZIP\sarchives\sof\sfiles\swith\spre-DOS\sdates. -D 2018-03-10T12:53:20.192 +C Improved\serror\smessages\sfrom\sthe\szipfile\sextension. +D 2018-03-10T13:21:41.393 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -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 1a234c4e822a11e2e5aa6d402309b527e34e0813dba1b34d2723f050862864d2 +F ext/misc/zipfile.c 1e5a27b6cf84171af95a763f21db990f690dc13eed42b84bc2e5b90eca2e9e1c F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1611,7 +1611,7 @@ 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 d4efc5547c2105fdc54b61d6b167ddd5a1a4b9b70993b402d7f20836b1eceef2 F test/zipfile2.test 67d5f08a202796d4b7a71dfa4b8dcb74aa7a9d1f42c5f17bedff9855c1ba7aa5 F test/zipfilefault.test 44d4d7a7f7cca7521d569d7f71026b241d65a6b1757aa409c1a168827edbbc2c F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 @@ -1712,7 +1712,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 2a4493f4ad2d09c1097e98e7086623669f3f252571884d515e51a98b1c6855e1 -R b996514daf8ccd4118140541121adf76 +P 16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d +R b511ebdd2c624217586a293149d65f0f U drh -Z 3a20f1e017065f65b485c6880eea221e +Z 5119f4749bf9fb79b4a57766ed83d519 diff --git a/manifest.uuid b/manifest.uuid index 22a9a1cccd..7032bdb217 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d \ No newline at end of file +f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 \ No newline at end of file diff --git a/test/zipfile.test b/test/zipfile.test index 2bb3f07892..18f7b25bfd 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 { @@ -637,4 +637,3 @@ do_execsql_test 9.0 { SELECT name FROM zipfile((SELECT zipfile(nm, NULL) FROM src)) } {dir1/ dir2/ dir3/ dir4/ /} finish_test - From 42f3c5ff25ab12b2b9a9c96d657e89f13ec186a0 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 10 Mar 2018 14:17:01 +0000 Subject: [PATCH 44/67] Add support for INSERT OR REPLACE and INSERT OR IGNORE on the zipfile extension. FossilOrigin-Name: 8ad35d483e4293d5571eeacc20fd26cdc4064fbee7b63d974879d507a0ee5792 --- ext/misc/zipfile.c | 19 +++++++++++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/zipfile.test | 31 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index 96a2815951..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]; @@ -1616,8 +1618,20 @@ static int zipfileUpdate( ZipfileEntry *p; for(p=pTab->pFirstEntry; p; p=p->pNext){ if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){ - zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath); - 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; } } @@ -1661,6 +1675,7 @@ static int zipfileUpdate( zipfileEntryFree(pOld); } +zipfile_update_done: sqlite3_free(pFree); sqlite3_free(zFree); return rc; diff --git a/manifest b/manifest index 43bf7a1064..e63d93b314 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\serror\smessages\sfrom\sthe\szipfile\sextension. -D 2018-03-10T13:21:41.393 +C Add\ssupport\sfor\sINSERT\sOR\sREPLACE\sand\sINSERT\sOR\sIGNORE\son\sthe\szipfile\nextension. +D 2018-03-10T14:17:01.651 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -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 1e5a27b6cf84171af95a763f21db990f690dc13eed42b84bc2e5b90eca2e9e1c +F ext/misc/zipfile.c e4e4f8289a8dee7e4f78547dacfb6548bcd83a02b52c0bc9205d8fbfb7f4b8a1 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1611,7 +1611,7 @@ F test/wordcount.c cb589cec469a1d90add05b1f8cee75c7210338d87a5afd65260ed5c0f4bbf F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test 9c41628db7e8d9e8a0181e59ea5f189df311a9f6ce99cc376dc461f66db6f8dc -F test/zipfile.test d4efc5547c2105fdc54b61d6b167ddd5a1a4b9b70993b402d7f20836b1eceef2 +F test/zipfile.test a9806a86e5a153d897f320de624a83a9e9774515eb79ad2419496187b1acc7d7 F test/zipfile2.test 67d5f08a202796d4b7a71dfa4b8dcb74aa7a9d1f42c5f17bedff9855c1ba7aa5 F test/zipfilefault.test 44d4d7a7f7cca7521d569d7f71026b241d65a6b1757aa409c1a168827edbbc2c F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 @@ -1712,7 +1712,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 16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d -R b511ebdd2c624217586a293149d65f0f +P f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 +R 7cc91e86ee07cd0fc984888021d66796 U drh -Z 5119f4749bf9fb79b4a57766ed83d519 +Z 9fc20201e1cf7d0b9deeae9a18f08a6b diff --git a/manifest.uuid b/manifest.uuid index 7032bdb217..900e882aeb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 \ No newline at end of file +8ad35d483e4293d5571eeacc20fd26cdc4064fbee7b63d974879d507a0ee5792 \ No newline at end of file diff --git a/test/zipfile.test b/test/zipfile.test index 18f7b25bfd..e17bc17726 100644 --- a/test/zipfile.test +++ b/test/zipfile.test @@ -636,4 +636,35 @@ do_execsql_test 9.0 { ) SELECT name FROM zipfile((SELECT zipfile(nm, NULL) FROM src)) } {dir1/ dir2/ dir3/ dir4/ /} + +#------------------------------------------------------------------------- +# 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 From ffdab721a38756d4301ae90bae104fb6fcdbd393 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 10 Mar 2018 20:25:08 +0000 Subject: [PATCH 45/67] Fix the second callback argument to the "profile" response of the "trace_v2" method in the TCL interface so that it shows the actual number of nanoseconds for the command, not the address of the variable containing the number of nanoseconds. FossilOrigin-Name: 8f9a12518642e5be9760956ff345fe54ed5bd3cab55328e88312278d3d78bc76 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/tclsqlite.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e63d93b314..2127b2a120 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sINSERT\sOR\sREPLACE\sand\sINSERT\sOR\sIGNORE\son\sthe\szipfile\nextension. -D 2018-03-10T14:17:01.651 +C Fix\sthe\ssecond\scallback\sargument\sto\sthe\s"profile"\sresponse\sof\sthe\n"trace_v2"\smethod\sin\sthe\sTCL\sinterface\sso\sthat\sit\sshows\sthe\sactual\nnumber\sof\snanoseconds\sfor\sthe\scommand,\snot\sthe\saddress\sof\sthe\svariable\ncontaining\sthe\snumber\sof\snanoseconds. +D 2018-03-10T20:25:08.263 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -498,7 +498,7 @@ F src/sqliteInt.h 2ef60a6d9a50e6eef224e9eae71b29a9fb91c301e882d9fbbb77afd50b6cf8 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 -F src/tclsqlite.c 3c3e085e02edf4c416792050d288944fd0fad3f7b283a81fa45241a633d78c80 +F src/tclsqlite.c 916a92de77ec5cbe27818ca194d8cf0c58aa7ad5b87527098f6aa5a6068800ce F src/test1.c 1ab7cbbb6693e08364c1a9241e2aee17f8c4925e4cc52396be77ae6845a05828 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b @@ -1712,7 +1712,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 f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 -R 7cc91e86ee07cd0fc984888021d66796 +P 8ad35d483e4293d5571eeacc20fd26cdc4064fbee7b63d974879d507a0ee5792 +R 279cd3192a7c1f331d05cc752480bd6c U drh -Z 9fc20201e1cf7d0b9deeae9a18f08a6b +Z 18b5539ad20c19ffcad336c52433ff73 diff --git a/manifest.uuid b/manifest.uuid index 900e882aeb..435e071afc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8ad35d483e4293d5571eeacc20fd26cdc4064fbee7b63d974879d507a0ee5792 \ No newline at end of file +8f9a12518642e5be9760956ff345fe54ed5bd3cab55328e88312278d3d78bc76 \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 285fbbda2e..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); From 840c300f4a830eb92c602c9ee8e95a0bc1b07892 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Sat, 10 Mar 2018 20:45:44 +0000 Subject: [PATCH 46/67] Add more tests for the profile output of the Tcl trace_v2 method. FossilOrigin-Name: 61eeb48f03f8a9a32330a5cae4387bb4e5618078cf669a5831910f99126900ec --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/trace3.test | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2127b2a120..154b7755d4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssecond\scallback\sargument\sto\sthe\s"profile"\sresponse\sof\sthe\n"trace_v2"\smethod\sin\sthe\sTCL\sinterface\sso\sthat\sit\sshows\sthe\sactual\nnumber\sof\snanoseconds\sfor\sthe\scommand,\snot\sthe\saddress\sof\sthe\svariable\ncontaining\sthe\snumber\sof\snanoseconds. -D 2018-03-10T20:25:08.263 +C Add\smore\stests\sfor\sthe\sprofile\soutput\sof\sthe\sTcl\strace_v2\smethod. +D 2018-03-10T20:45:44.303 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -1464,7 +1464,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 @@ -1712,7 +1712,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 8ad35d483e4293d5571eeacc20fd26cdc4064fbee7b63d974879d507a0ee5792 -R 279cd3192a7c1f331d05cc752480bd6c -U drh -Z 18b5539ad20c19ffcad336c52433ff73 +P 8f9a12518642e5be9760956ff345fe54ed5bd3cab55328e88312278d3d78bc76 +R 48d81d5066bd833c124296a55bfd94e5 +U mistachkin +Z 000a9a6266d4feb17fadafdd3f3d2026 diff --git a/manifest.uuid b/manifest.uuid index 435e071afc..ea63cde5bf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8f9a12518642e5be9760956ff345fe54ed5bd3cab55328e88312278d3d78bc76 \ No newline at end of file +61eeb48f03f8a9a32330a5cae4387bb4e5618078cf669a5831910f99126900ec \ No newline at end of file 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 From 58db4c760ff32ad4204bf48b1cf224c9900bbef1 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 12 Mar 2018 21:09:16 +0000 Subject: [PATCH 47/67] Fix a typo causing SQLITE_LOG_CACHE_SPILL builds to fail. FossilOrigin-Name: 0171d4a71ca7911a9fd409a42eeed0eda4521b6e48df5cd058364c0a736313b7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pcache.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 154b7755d4..6228a19578 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\smore\stests\sfor\sthe\sprofile\soutput\sof\sthe\sTcl\strace_v2\smethod. -D 2018-03-10T20:45:44.303 +C Fix\sa\stypo\scausing\sSQLITE_LOG_CACHE_SPILL\sbuilds\sto\sfail. +D 2018-03-12T21:09:16.462 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -479,7 +479,7 @@ F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c aa764a01a5548e633ea083521f48c2b128245fae1a8157a16a3490b9b9718f55 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a F src/parse.y 3be4b2b5e33ef7dab3128b765898ee786fc6cd698a7f053f756a68f2f238f0aa -F src/pcache.c 7ae91a4557a43d77d449accbfdc68846e6516f8e2eda46e8bbe4536fb669b201 +F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170 F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880 F src/pragma.c bea56df3ae0637768c0da4fbbb8f2492f780980d95000034a105ff291bf7ca69 @@ -1712,7 +1712,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 8f9a12518642e5be9760956ff345fe54ed5bd3cab55328e88312278d3d78bc76 -R 48d81d5066bd833c124296a55bfd94e5 -U mistachkin -Z 000a9a6266d4feb17fadafdd3f3d2026 +P 61eeb48f03f8a9a32330a5cae4387bb4e5618078cf669a5831910f99126900ec +R cc8ceb6c97c49d267aa8c6c8a3936381 +U dan +Z 467f1d68de166a5be6bc42e03b4e2dce diff --git a/manifest.uuid b/manifest.uuid index ea63cde5bf..a718ce1460 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -61eeb48f03f8a9a32330a5cae4387bb4e5618078cf669a5831910f99126900ec \ No newline at end of file +0171d4a71ca7911a9fd409a42eeed0eda4521b6e48df5cd058364c0a736313b7 \ No newline at end of file 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)); From 68cf69ed8d8248467c40c0a9bde493a72fab4004 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 14 Mar 2018 08:27:39 +0000 Subject: [PATCH 48/67] Improve detection of out-of-range parameters in sqlite3_stmt_status() for SQLITE_ENABLE_API_ARMOR builds. FossilOrigin-Name: 21ecbce1378f3cc4b1051628b8c1580bb807c8745a1f525bc089036af93a54af --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeapi.c | 4 +++- test/dbstatus.test | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6228a19578..9a05c02d0e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\scausing\sSQLITE_LOG_CACHE_SPILL\sbuilds\sto\sfail. -D 2018-03-12T21:09:16.462 +C Improve\sdetection\sof\sout-of-range\sparameters\sin\ssqlite3_stmt_status()\sfor\nSQLITE_ENABLE_API_ARMOR\sbuilds. +D 2018-03-14T08:27:39.022 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -561,7 +561,7 @@ F src/vacuum.c 762ee9bbf8733d87d8cd06f58d950e881982e416f8c767334a40ffd341b6bff5 F src/vdbe.c 88d8e0797bf49624d056014f34f302a7370cc119915cc0ece8f2b7bf5e7c30fb F src/vdbe.h 134beb7a12a6213c00eba58febaede33447cc4441bc568a0d9c144b33fc3720a F src/vdbeInt.h 95f7adfdc5c8f1353321f55a6c5ec00a90877e3b85af5159e393afb41ff54110 -F src/vdbeapi.c fea41171884a4de119f8b10ab514c788674eeeb7f27218bb6d008e1310bfd07f +F src/vdbeapi.c 29d2baf9c1233131ec467d7bed1b7c8a03c27579048d768c4b04acf427838858 F src/vdbeaux.c 2756ac68ac259c416554100598fc291870063288cd7e1af22847f57b3e130e56 F src/vdbeblob.c f5c70f973ea3a9e915d1693278a5f890dc78594300cf4d54e64f2b0917c94191 F src/vdbemem.c 414e28d3a7e2a8bee2bb247de115dcbc68e3cbac284d5862d077002f7a93bce1 @@ -741,7 +741,7 @@ 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/dbstatus.test 76e317d26476ffba00faa724f383b97e6f9b7d037270fc924f15b6cd4d0bd99d F test/dbstatus2.test e93ab03bfae6d62d4d935f20de928c19ca0ed0ab F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d F test/delete.test acc38fca8ee4851467705b1c2cfea64cd26667e5 @@ -1712,7 +1712,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 61eeb48f03f8a9a32330a5cae4387bb4e5618078cf669a5831910f99126900ec -R cc8ceb6c97c49d267aa8c6c8a3936381 +P 0171d4a71ca7911a9fd409a42eeed0eda4521b6e48df5cd058364c0a736313b7 +R a2badd15fc27350d38828fa175bb36a1 U dan -Z 467f1d68de166a5be6bc42e03b4e2dce +Z 1e5c4dfa2e88b466a3e12b606bfaedf6 diff --git a/manifest.uuid b/manifest.uuid index a718ce1460..a5dc53cc26 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0171d4a71ca7911a9fd409a42eeed0eda4521b6e48df5cd058364c0a736313b7 \ No newline at end of file +21ecbce1378f3cc4b1051628b8c1580bb807c8745a1f525bc089036af93a54af \ No newline at end of file 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/test/dbstatus.test b/test/dbstatus.test index 711d66ebb3..5c8f41d510 100644 --- a/test/dbstatus.test +++ b/test/dbstatus.test @@ -415,4 +415,42 @@ 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} + +do_test 5.2 { sqlite3_stmt_status $::stmt -1 0 } 0 +do_test 5.3 { sqlite3_stmt_status $::stmt 7 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 + From ffc78a41ea2e13fb17a2528e53551342d3957e15 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 14 Mar 2018 14:53:50 +0000 Subject: [PATCH 49/67] Add the SQLITE_DBSTATUS_CACHE_SPILL option to sqlite3_db_status() FossilOrigin-Name: 3faeb851374471a6f94a6fab3a62c73d03330eae6fc72cd1a277b03ad12dcdd0 --- manifest | 27 +++++++++++++++------------ manifest.uuid | 2 +- src/pager.c | 21 +++++++++++++++------ src/shell.c.in | 3 +++ src/sqlite.h.in | 12 +++++++++++- src/status.c | 3 +++ src/test_malloc.c | 1 + test/dbstatus2.test | 13 +++++++++++++ 8 files changed, 62 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index 9a05c02d0e..ed2f8c84a0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sdetection\sof\sout-of-range\sparameters\sin\ssqlite3_stmt_status()\sfor\nSQLITE_ENABLE_API_ARMOR\sbuilds. -D 2018-03-14T08:27:39.022 +C Add\sthe\sSQLITE_DBSTATUS_CACHE_SPILL\soption\sto\ssqlite3_db_status() +D 2018-03-14T14:53:50.744 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -476,7 +476,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c 928586cbde31890538854f1657463392d63b2d7794f577774573ae53ec283d7b F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c aa764a01a5548e633ea083521f48c2b128245fae1a8157a16a3490b9b9718f55 +F src/pager.c 3e3b659b6b3f40b5a5efef6b8890ced490c397a81d96feb5266fde1f7362e608 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a F src/parse.y 3be4b2b5e33ef7dab3128b765898ee786fc6cd698a7f053f756a68f2f238f0aa F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd @@ -490,13 +490,13 @@ 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 b0aad8855b1c04ff4637c9f244a5537255f5d3dc6625e334454f5bd7d9794c61 -F src/sqlite.h.in 49d776d536076894e38de837a6c999e5150949baf008aa02d91fea70471eae78 +F src/shell.c.in 9b7e7ac1ccdbc045e285e745ff6d21dbec6ce91330f2bdd5db50d5c39f40679e +F src/sqlite.h.in 6283ece8dbc3749d78593415a2373f4e7050afce7d18f87acea3b9a48f6fa576 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d F src/sqliteInt.h 2ef60a6d9a50e6eef224e9eae71b29a9fb91c301e882d9fbbb77afd50b6cf815 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b -F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 +F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 F src/tclsqlite.c 916a92de77ec5cbe27818ca194d8cf0c58aa7ad5b87527098f6aa5a6068800ce F src/test1.c 1ab7cbbb6693e08364c1a9241e2aee17f8c4925e4cc52396be77ae6845a05828 @@ -526,7 +526,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 @@ -742,7 +742,7 @@ F test/date2.test 74c234bece1b016e94dd4ef9c8cc7a199a8806c0e2291cab7ba64bace6350b F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbpage.test dbf50a4d361f9e45a979432c727506065113124478a7d2db12074fa655e65d6c F test/dbstatus.test 76e317d26476ffba00faa724f383b97e6f9b7d037270fc924f15b6cd4d0bd99d -F test/dbstatus2.test e93ab03bfae6d62d4d935f20de928c19ca0ed0ab +F test/dbstatus2.test 35a987036fefbbc696e65b6a3fbd860864cfd54941c52f50c61b55d4778ac66c F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d F test/delete.test acc38fca8ee4851467705b1c2cfea64cd26667e5 F test/delete2.test 3a03f2cca1f9a67ec469915cb8babd6485db43fa @@ -1712,7 +1712,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0171d4a71ca7911a9fd409a42eeed0eda4521b6e48df5cd058364c0a736313b7 -R a2badd15fc27350d38828fa175bb36a1 -U dan -Z 1e5c4dfa2e88b466a3e12b606bfaedf6 +P 21ecbce1378f3cc4b1051628b8c1580bb807c8745a1f525bc089036af93a54af +R d33a89781051cd16ed43afc1ec7bbcef +T *branch * dbstatus-cache-spill +T *sym-dbstatus-cache-spill * +T -sym-trunk * +U drh +Z ec7615ff5aac967dc56fabc66432aa1b diff --git a/manifest.uuid b/manifest.uuid index a5dc53cc26..5d0cc6dacb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -21ecbce1378f3cc4b1051628b8c1580bb807c8745a1f525bc089036af93a54af \ No newline at end of file +3faeb851374471a6f94a6fab3a62c73d03330eae6fc72cd1a277b03ad12dcdd0 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index f4ac88c206..e3881c6a89 100644 --- a/src/pager.c +++ b/src/pager.c @@ -699,7 +699,7 @@ struct Pager { char *zJournal; /* Name of the journal file */ int (*xBusyHandler)(void*); /* Function to call when busy */ void *pBusyHandlerArg; /* Context argument for xBusyHandler */ - int aStat[3]; /* Total cache hits, misses and writes */ + int aStat[4]; /* Total cache hits, misses, writes, spills */ #ifdef SQLITE_TEST int nRead; /* Database pages read */ #endif @@ -727,6 +727,7 @@ struct Pager { #define PAGER_STAT_HIT 0 #define PAGER_STAT_MISS 1 #define PAGER_STAT_WRITE 2 +#define PAGER_STAT_SPILL 3 /* ** The following global variables hold counters used for @@ -4618,6 +4619,7 @@ static int pagerStress(void *p, PgHdr *pPg){ return SQLITE_OK; } + pPager->aStat[PAGER_STAT_SPILL]++; pPg->pDirty = 0; if( pagerUseWal(pPager) ){ /* Write a single frame for this page to the log. */ @@ -6738,8 +6740,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. @@ -6749,15 +6755,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/shell.c.in b/src/shell.c.in index 7cdd361779..f7389f3097 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2353,6 +2353,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); diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 1d7e191442..9b477d84bc 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -7230,6 +7230,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 +7258,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 */ /* 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/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/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 From 15ca9e3e8c0c7642656bd3a9c82e2b105b936f19 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 14 Mar 2018 15:06:42 +0000 Subject: [PATCH 50/67] Disable one of the test cases from check-in [21ecbce1378f3cc4] when API_ARMOR is not enabled. FossilOrigin-Name: 8fb23d4281915b4507e4d42a300f4b5f958ad88ad408218659c7459775d7b114 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/dbstatus.test | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 9a05c02d0e..42454216e6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sdetection\sof\sout-of-range\sparameters\sin\ssqlite3_stmt_status()\sfor\nSQLITE_ENABLE_API_ARMOR\sbuilds. -D 2018-03-14T08:27:39.022 +C Disable\sone\sof\sthe\stest\scases\sfrom\scheck-in\s[21ecbce1378f3cc4]\swhen\nAPI_ARMOR\sis\snot\senabled. +D 2018-03-14T15:06:42.860 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -741,7 +741,7 @@ F test/date.test 9b73bbeb1b82d9c1f44dec5cf563bf7da58d2373 F test/date2.test 74c234bece1b016e94dd4ef9c8cc7a199a8806c0e2291cab7ba64bace6350b10 F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbpage.test dbf50a4d361f9e45a979432c727506065113124478a7d2db12074fa655e65d6c -F test/dbstatus.test 76e317d26476ffba00faa724f383b97e6f9b7d037270fc924f15b6cd4d0bd99d +F test/dbstatus.test c15fa97f743dac7ce996814c84b56317e138895ee15ce27f15b608aa6924c90a F test/dbstatus2.test e93ab03bfae6d62d4d935f20de928c19ca0ed0ab F test/default.test 0cb49b1c315a0d81c81d775e407f66906a2a604d F test/delete.test acc38fca8ee4851467705b1c2cfea64cd26667e5 @@ -1712,7 +1712,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 0171d4a71ca7911a9fd409a42eeed0eda4521b6e48df5cd058364c0a736313b7 -R a2badd15fc27350d38828fa175bb36a1 -U dan -Z 1e5c4dfa2e88b466a3e12b606bfaedf6 +P 21ecbce1378f3cc4b1051628b8c1580bb807c8745a1f525bc089036af93a54af +R 15674337c0931617c995ce33bfb1e806 +U drh +Z 292f237c407ee25cacfa05dd8c59e736 diff --git a/manifest.uuid b/manifest.uuid index a5dc53cc26..57b12f99d2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -21ecbce1378f3cc4b1051628b8c1580bb807c8745a1f525bc089036af93a54af \ No newline at end of file +8fb23d4281915b4507e4d42a300f4b5f958ad88ad408218659c7459775d7b114 \ No newline at end of file diff --git a/test/dbstatus.test b/test/dbstatus.test index 5c8f41d510..57b91cda1a 100644 --- a/test/dbstatus.test +++ b/test/dbstatus.test @@ -433,8 +433,10 @@ do_test 5.1 { sqlite3_reset $::stmt } {SQLITE_OK} -do_test 5.2 { sqlite3_stmt_status $::stmt -1 0 } 0 -do_test 5.3 { sqlite3_stmt_status $::stmt 7 0 } 0 +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 @@ -453,4 +455,3 @@ if {$tn==2} breakpoint sqlite3_finalize $::stmt finish_test - From 093d63bf341a325ae78f0af0c7cde2efe785feac Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 15 Mar 2018 05:25:57 +0000 Subject: [PATCH 51/67] Draft fix for an fsdir() issue reported via the mailing list. FossilOrigin-Name: 48641010c24bf37f13d68c4d19c5c3e9b41404af12a4947705cc53a31db04178 --- ext/misc/fileio.c | 1 + manifest | 18 ++++++++++-------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) 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/manifest b/manifest index 7967a2c672..61501182e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sSQLITE_DBSTATUS_CACHE_SPILL\soption\sto\ssqlite3_db_status(). -D 2018-03-14T15:25:43.797 +C Draft\sfix\sfor\san\sfsdir()\sissue\sreported\svia\sthe\smailing\slist. +D 2018-03-15T05:25:57.098 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -277,7 +277,7 @@ F ext/misc/compress.c dd4f8a6d0baccff3c694757db5b430f3bbd821d8686d1fc24df55cf9f0 F ext/misc/csv.c 1a009b93650732e22334edc92459c4630b9fa703397cbb3c8ca279921a36ca11 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 @@ -1712,8 +1712,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8fb23d4281915b4507e4d42a300f4b5f958ad88ad408218659c7459775d7b114 3faeb851374471a6f94a6fab3a62c73d03330eae6fc72cd1a277b03ad12dcdd0 -R 447376723b1921d647ac6ba35140d6b2 -T +closed 3faeb851374471a6f94a6fab3a62c73d03330eae6fc72cd1a277b03ad12dcdd0 -U drh -Z 289c0efb0552dcd852e2b3f3f5063bbc +P 48a06eb02b42a021b835ff9766535805723259b9701b87fb17fa488b133cb53a +R f348889711b0641611a4541c43f0ef77 +T *branch * fsDirFix +T *sym-fsDirFix * +T -sym-trunk * +U mistachkin +Z e35ad5809ec8c5cee9fda8092826113a diff --git a/manifest.uuid b/manifest.uuid index 5cd60cc429..6598f7e096 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -48a06eb02b42a021b835ff9766535805723259b9701b87fb17fa488b133cb53a \ No newline at end of file +48641010c24bf37f13d68c4d19c5c3e9b41404af12a4947705cc53a31db04178 \ No newline at end of file From b39161647ec5f72aa93c20132f384036b127dde3 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Mar 2018 17:46:42 +0000 Subject: [PATCH 52/67] Fix a typo in a comment used to generate documentation. No code changes. FossilOrigin-Name: f1784aff4e6ff1c84d3fa0069034290154220fd2fa85c7df342c717ad54f4b91 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 6552966e20..e2d75a3e4c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sissue\swith\sthe\sfsdir()\stable-valued\sfunction\snot\sresetting\scorrectly\nafter\seach\spass\sof\sa\sjoin. -D 2018-03-15T15:09:45.238 +C Fix\sa\stypo\sin\sa\scomment\sused\sto\sgenerate\sdocumentation.\s\sNo\scode\schanges. +D 2018-03-15T17:46:42.911 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -491,7 +491,7 @@ F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c f02352ac5cbb6fad3804add825743b924cfb6c742ba2e8666d726828a9985d73 F src/shell.c.in 9b7e7ac1ccdbc045e285e745ff6d21dbec6ce91330f2bdd5db50d5c39f40679e -F src/sqlite.h.in 6283ece8dbc3749d78593415a2373f4e7050afce7d18f87acea3b9a48f6fa576 +F src/sqlite.h.in 2619d00bccc0454e875bce5e90b1dc986f87975c267dd7bbbe251f1be297d2f3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d F src/sqliteInt.h 2ef60a6d9a50e6eef224e9eae71b29a9fb91c301e882d9fbbb77afd50b6cf815 @@ -1712,8 +1712,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 48a06eb02b42a021b835ff9766535805723259b9701b87fb17fa488b133cb53a 48641010c24bf37f13d68c4d19c5c3e9b41404af12a4947705cc53a31db04178 -R 330f102279784dfe2b3068c419da3e7a -T +closed 48641010c24bf37f13d68c4d19c5c3e9b41404af12a4947705cc53a31db04178 +P 7ce4e71c1b7251be9e922b21dfeba1f9aef6a47ce6495ecb7f94fd785ab564f2 +R 89b0b99e50f1168361f0a0d02a7a50f5 U drh -Z 5d98223a84f13b8cca1846191fd9b4d5 +Z 77e08b27601e854563175f463a1b9793 diff --git a/manifest.uuid b/manifest.uuid index 264409e297..5c657dc3f1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7ce4e71c1b7251be9e922b21dfeba1f9aef6a47ce6495ecb7f94fd785ab564f2 \ No newline at end of file +f1784aff4e6ff1c84d3fa0069034290154220fd2fa85c7df342c717ad54f4b91 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9b477d84bc..c718a6faab 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -8849,7 +8849,7 @@ int sqlite3_deserialize( ** 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 usign calls to [sqlite3_realloc64()]. This +** 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. From 9f2b04533e7d388ee3fb2fe49f9c7bc3328521b1 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 16 Mar 2018 07:48:43 +0000 Subject: [PATCH 53/67] Fix a problem in test script thread001.test causing a spurious "-1 files were left open" error when run separately. FossilOrigin-Name: 1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/thread001.test | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e2d75a3e4c..d12cd67b79 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sa\scomment\sused\sto\sgenerate\sdocumentation.\s\sNo\scode\schanges. -D 2018-03-15T17:46:42.911 +C Fix\sa\sproblem\sin\stest\sscript\sthread001.test\scausing\sa\sspurious\s"-1\sfiles\swere\nleft\sopen"\serror\swhen\srun\sseparately. +D 2018-03-16T07:48:43.361 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -1307,7 +1307,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 @@ -1712,7 +1712,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 7ce4e71c1b7251be9e922b21dfeba1f9aef6a47ce6495ecb7f94fd785ab564f2 -R 89b0b99e50f1168361f0a0d02a7a50f5 -U drh -Z 77e08b27601e854563175f463a1b9793 +P f1784aff4e6ff1c84d3fa0069034290154220fd2fa85c7df342c717ad54f4b91 +R 6365d4cb8120ab9ac72d818a9b1d70a0 +U dan +Z b450edce4db91ca834c891cd7015f37d diff --git a/manifest.uuid b/manifest.uuid index 5c657dc3f1..0e8f474cb2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f1784aff4e6ff1c84d3fa0069034290154220fd2fa85c7df342c717ad54f4b91 \ No newline at end of file +1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 \ No newline at end of file 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 From c8abbc11cdf57ccdc593a5adbcd71f288dba6565 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 16 Mar 2018 18:46:30 +0000 Subject: [PATCH 54/67] Avoid writing the sqlite_sequence table when it has not actually changed. FossilOrigin-Name: 3e3849a9d1a06673e6c713a42194f5da339fbf6533fa418c38f63d09bc045867 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/insert.c | 34 +++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index d12cd67b79..03ed1cf06c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\stest\sscript\sthread001.test\scausing\sa\sspurious\s"-1\sfiles\swere\nleft\sopen"\serror\swhen\srun\sseparately. -D 2018-03-16T07:48:43.361 +C Avoid\swriting\sthe\ssqlite_sequence\stable\swhen\sit\shas\snot\sactually\schanged. +D 2018-03-16T18:46:30.654 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -450,7 +450,7 @@ 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 c1e97e4c6fffff1fb1a6f1c48807386819af78657b4ae4acfd6d6d17353b8277 @@ -1712,7 +1712,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f1784aff4e6ff1c84d3fa0069034290154220fd2fa85c7df342c717ad54f4b91 -R 6365d4cb8120ab9ac72d818a9b1d70a0 -U dan -Z b450edce4db91ca834c891cd7015f37d +P 1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 +R d0bd8d3f666390fa87cc4ce598933023 +T *branch * autoinc-enhancement +T *sym-autoinc-enhancement * +T -sym-trunk * +U drh +Z 5d34c90db248f39c50f1168b98361d2f diff --git a/manifest.uuid b/manifest.uuid index 0e8f474cb2..d11343282b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 \ No newline at end of file +3e3849a9d1a06673e6c713a42194f5da339fbf6533fa418c38f63d09bc045867 \ No newline at end of file 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; From 8bbddd804990caf0ec19235e128c25c631e40f8b Mon Sep 17 00:00:00 2001 From: mistachkin Date: Fri, 16 Mar 2018 19:10:05 +0000 Subject: [PATCH 55/67] Fix a parsing issue associated with a corrupt sqlite_master table. FossilOrigin-Name: 5f779ff6b48ec97efacd49b1715b7e5272694fa839be349c90667812bbffe22b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/parse.y | 9 +++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d12cd67b79..ed8d0b92d8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\stest\sscript\sthread001.test\scausing\sa\sspurious\s"-1\sfiles\swere\nleft\sopen"\serror\swhen\srun\sseparately. -D 2018-03-16T07:48:43.361 +C Fix\sa\sparsing\sissue\sassociated\swith\sa\scorrupt\ssqlite_master\stable. +D 2018-03-16T19:10:05.855 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -478,7 +478,7 @@ F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 3e3b659b6b3f40b5a5efef6b8890ced490c397a81d96feb5266fde1f7362e608 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a -F src/parse.y 3be4b2b5e33ef7dab3128b765898ee786fc6cd698a7f053f756a68f2f238f0aa +F src/parse.y 927e287566764c08e3dbf663a433518e2599fe1d3780386db69df64b4d70a146 F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170 F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880 @@ -1712,7 +1712,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 f1784aff4e6ff1c84d3fa0069034290154220fd2fa85c7df342c717ad54f4b91 -R 6365d4cb8120ab9ac72d818a9b1d70a0 -U dan -Z b450edce4db91ca834c891cd7015f37d +P 1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 +R 28201db53ed454b9421b2d31c19681b6 +U mistachkin +Z 278594336baa790fc171fbd2e9db3256 diff --git a/manifest.uuid b/manifest.uuid index 0e8f474cb2..e23a8d1434 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 \ No newline at end of file +5f779ff6b48ec97efacd49b1715b7e5272694fa839be349c90667812bbffe22b \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 9c41484ab2..638960d242 100644 --- a/src/parse.y +++ b/src/parse.y @@ -169,8 +169,13 @@ create_table_args ::= LP columnlist conslist_opt(X) RP(E) table_options(F). { sqlite3EndTable(pParse,&X,&E,F,0); } create_table_args ::= AS select(S). { - sqlite3EndTable(pParse,0,0,0,S); - sqlite3SelectDelete(pParse->db, S); + if( pParse->db->init.busy==0 ){ + sqlite3EndTable(pParse,0,0,0,S); + sqlite3SelectDelete(pParse->db, S); + }else{ + sqlite3SelectDelete(pParse->db, S); + sqlite3ErrorMsg(pParse, "corrupt schema"); + } } %type table_options {int} table_options(A) ::= . {A = 0;} From 1e9c47be1e81e94a67f788c98fd70e8bf70e3746 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 16 Mar 2018 20:15:58 +0000 Subject: [PATCH 56/67] Better error message text when the schema is corrupted by a CREATE TABLE AS entry. FossilOrigin-Name: e13993cf833423eec5f94082cee7213b2d97bcf40dddb2683cf5a8ebf50a33e3 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/build.c | 6 ++++-- src/parse.y | 9 ++------- src/prepare.c | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index ed8d0b92d8..1f25e1a6a1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sparsing\sissue\sassociated\swith\sa\scorrupt\ssqlite_master\stable. -D 2018-03-16T19:10:05.855 +C Better\serror\smessage\stext\swhen\sthe\sschema\sis\scorrupted\sby\sa\sCREATE\sTABLE\sAS\nentry. +D 2018-03-16T20:15:58.956 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -433,7 +433,7 @@ F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca F src/btree.c 18a53540aa35dbdf77f715ea928422a4ed9011dc16ea7b50f803fd1617fcc4f5 F src/btree.h 0866c0a08255142ea0e754aabd211c843cab32045c978a592a43152405ed0c84 F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96 -F src/build.c 672022c06e1a5c2653f80c77a687de11f7e65ce81d20fe2825aadfa13a875c33 +F src/build.c 8b53aacc26944bb7fd9ab5ddeedecb4cc7c4b84df3a420cf6d2b8f772ad421df F src/callback.c fe677cb5f5abb02f7a772a62a98c2f516426081df68856e8f2d5f950929b966a F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c ff1be3eed7bdd75aaca61ca8dc848f7c9f850ef2fb9cb56f2734e922a098f9c0 @@ -478,13 +478,13 @@ F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 3e3b659b6b3f40b5a5efef6b8890ced490c397a81d96feb5266fde1f7362e608 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a -F src/parse.y 927e287566764c08e3dbf663a433518e2599fe1d3780386db69df64b4d70a146 +F src/parse.y 3be4b2b5e33ef7dab3128b765898ee786fc6cd698a7f053f756a68f2f238f0aa 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 @@ -1712,7 +1712,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 1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 -R 28201db53ed454b9421b2d31c19681b6 -U mistachkin -Z 278594336baa790fc171fbd2e9db3256 +P 5f779ff6b48ec97efacd49b1715b7e5272694fa839be349c90667812bbffe22b +R a2c5b8eddcb12d3bb2fe3e3879b722e7 +U drh +Z 082ab73893d53982ab87629d2ac22c11 diff --git a/manifest.uuid b/manifest.uuid index e23a8d1434..6bf1c78a67 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f779ff6b48ec97efacd49b1715b7e5272694fa839be349c90667812bbffe22b \ No newline at end of file +e13993cf833423eec5f94082cee7213b2d97bcf40dddb2683cf5a8ebf50a33e3 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 3a656def3e..eaddef5b17 100644 --- a/src/build.c +++ b/src/build.c @@ -1870,8 +1870,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 @@ -1882,6 +1880,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/parse.y b/src/parse.y index 638960d242..9c41484ab2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -169,13 +169,8 @@ create_table_args ::= LP columnlist conslist_opt(X) RP(E) table_options(F). { sqlite3EndTable(pParse,&X,&E,F,0); } create_table_args ::= AS select(S). { - if( pParse->db->init.busy==0 ){ - sqlite3EndTable(pParse,0,0,0,S); - sqlite3SelectDelete(pParse->db, S); - }else{ - sqlite3SelectDelete(pParse->db, S); - sqlite3ErrorMsg(pParse, "corrupt schema"); - } + sqlite3EndTable(pParse,0,0,0,S); + sqlite3SelectDelete(pParse->db, S); } %type table_options {int} table_options(A) ::= . {A = 0;} 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; } From 0d060a071e7e2a0a26ddf4518112f9243f6b49fb Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 16 Mar 2018 23:59:36 +0000 Subject: [PATCH 57/67] Detect corruption in the form of the sqlite_sequence table pointing to the wrong type of btree. FossilOrigin-Name: 525deb7a67fbd64726c89d5cc36a54b090111e31239431efeeb2bda9836828e0 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/vdbe.c | 4 ++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4853d707ed..2eed7d4ead 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Detect\sdatabases\swhose\sschema\sis\scorrupted\susing\sa\sCREATE\sTABLE\sAS\sstatement\nand\sissue\san\sappropriate\serror\smessage. -D 2018-03-16T20:23:01.801 +C Detect\scorruption\sin\sthe\sform\sof\sthe\ssqlite_sequence\stable\spointing\sto\sthe\nwrong\stype\sof\sbtree. +D 2018-03-16T23:59:36.251 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -558,7 +558,7 @@ F src/update.c a90a32ffc0100265b0693dbbdbe490756447af181f5ea2c138cce515b08c8795 F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5 F src/util.c d9eb0a6c4aae1b00a7369eadd7ca0bbe946cb4c953b6751aa20d357c2f482157 F src/vacuum.c 762ee9bbf8733d87d8cd06f58d950e881982e416f8c767334a40ffd341b6bff5 -F src/vdbe.c 88d8e0797bf49624d056014f34f302a7370cc119915cc0ece8f2b7bf5e7c30fb +F src/vdbe.c 066a4e1de2ed83e253adfd2e97a684cf562eaa41d31ee7f3d3e4c8aea4485a55 F src/vdbe.h 134beb7a12a6213c00eba58febaede33447cc4441bc568a0d9c144b33fc3720a F src/vdbeInt.h 95f7adfdc5c8f1353321f55a6c5ec00a90877e3b85af5159e393afb41ff54110 F src/vdbeapi.c 29d2baf9c1233131ec467d7bed1b7c8a03c27579048d768c4b04acf427838858 @@ -1712,8 +1712,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 1774f1c3baf0bc3d83a53c52702696ff21814fa1de07cc38fd098832e6757b09 e13993cf833423eec5f94082cee7213b2d97bcf40dddb2683cf5a8ebf50a33e3 -R a2c5b8eddcb12d3bb2fe3e3879b722e7 -T +closed e13993cf833423eec5f94082cee7213b2d97bcf40dddb2683cf5a8ebf50a33e3 +P d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a +R f10ec81e9dd7a9fb3bb6a420e0c1ce3e U drh -Z 374d2eb65795866b294a2545ae7eea24 +Z 47544520ddc0ffb0778dcedfa74bdb17 diff --git a/manifest.uuid b/manifest.uuid index 1f593da4e9..d56f7038a2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a \ No newline at end of file +525deb7a67fbd64726c89d5cc36a54b090111e31239431efeeb2bda9836828e0 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 4a506dd592..70537ce114 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4287,6 +4287,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 ); From 929cce88902e01911578e5ab79ae78c07b6558d2 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 17 Mar 2018 16:26:36 +0000 Subject: [PATCH 58/67] Do not use sqlite3_column_decltype() in the CLI if it is compiled with SQLITE_OMIT_DECLTYPE. FossilOrigin-Name: 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 2eed7d4ead..a41fa9e1c3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Detect\scorruption\sin\sthe\sform\sof\sthe\ssqlite_sequence\stable\spointing\sto\sthe\nwrong\stype\sof\sbtree. -D 2018-03-16T23:59:36.251 +C Do\snot\suse\ssqlite3_column_decltype()\sin\sthe\sCLI\sif\sit\sis\scompiled\swith\nSQLITE_OMIT_DECLTYPE. +D 2018-03-17T16:26:36.591 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ 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 9b7e7ac1ccdbc045e285e745ff6d21dbec6ce91330f2bdd5db50d5c39f40679e +F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f F src/sqlite.h.in 2619d00bccc0454e875bce5e90b1dc986f87975c267dd7bbbe251f1be297d2f3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a -R f10ec81e9dd7a9fb3bb6a420e0c1ce3e +P 525deb7a67fbd64726c89d5cc36a54b090111e31239431efeeb2bda9836828e0 +R 6c453226fb8e12f07481da05e5a67557 U drh -Z 47544520ddc0ffb0778dcedfa74bdb17 +Z 8727ea63840dc9ecc5e33e6710240d8e diff --git a/manifest.uuid b/manifest.uuid index d56f7038a2..3634e0f9b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -525deb7a67fbd64726c89d5cc36a54b090111e31239431efeeb2bda9836828e0 \ No newline at end of file +442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index f7389f3097..26e58aef3a 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2286,18 +2286,20 @@ static int display_stats( for(i=0; i Date: Mon, 19 Mar 2018 16:06:11 +0000 Subject: [PATCH 59/67] Improved ".selecttrace" output formatting. No changes in non-debug code. FossilOrigin-Name: 30704d2a52d37717d8b34a402c99ea32453e5c1a9840037dba96591f4acc1503 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- src/treeview.c | 10 ++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index a41fa9e1c3..57d1183635 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\suse\ssqlite3_column_decltype()\sin\sthe\sCLI\sif\sit\sis\scompiled\swith\nSQLITE_OMIT_DECLTYPE. -D 2018-03-17T16:26:36.591 +C Improved\s".selecttrace"\soutput\sformatting.\s\sNo\schanges\sin\snon-debug\scode. +D 2018-03-19T16:06:11.475 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -489,7 +489,7 @@ 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/select.c 1e9f53890f746f26d6955b38a6be37e65e32a6e5aea098c19cf7114730ea72e6 F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f F src/sqlite.h.in 2619d00bccc0454e875bce5e90b1dc986f87975c267dd7bbbe251f1be297d2f3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -552,7 +552,7 @@ 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 @@ -1712,7 +1712,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 525deb7a67fbd64726c89d5cc36a54b090111e31239431efeeb2bda9836828e0 -R 6c453226fb8e12f07481da05e5a67557 +P 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540 +R 4f358dadf4a5480f7a1f516d99ba5684 U drh -Z 8727ea63840dc9ecc5e33e6710240d8e +Z dafbc788d38e72c2958479a7a802aa86 diff --git a/manifest.uuid b/manifest.uuid index 3634e0f9b9..287314654d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540 \ No newline at end of file +30704d2a52d37717d8b34a402c99ea32453e5c1a9840037dba96591f4acc1503 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 9ac4f9f198..4ceca44a8d 100644 --- a/src/select.c +++ b/src/select.c @@ -21,7 +21,7 @@ /***/ int sqlite3SelectTrace = 0; # define SELECTTRACE(K,P,S,X) \ if(sqlite3SelectTrace&(K)) \ - sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",\ + sqlite3DebugPrintf("%*s%s/%p: ",(P)->nSelectIndent*2-2,"",\ (S)->zSelName,(S)),\ sqlite3DebugPrintf X #else 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; From 9d03f63a7c6be9bb38f2c40b372fdbbd98d2ab9c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Mar 2018 16:09:36 +0000 Subject: [PATCH 60/67] In the compile_options pragma, show the actual value of the SQLITE_ENABLE_CEROD compile-time option, if it exists. FossilOrigin-Name: 1ec339fd109b31e1d2b1e73345bd7a00c3d755f2c45c14d050a8203969163d60 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/ctime.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 57d1183635..29697c247e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\s".selecttrace"\soutput\sformatting.\s\sNo\schanges\sin\snon-debug\scode. -D 2018-03-19T16:06:11.475 +C In\sthe\scompile_options\spragma,\sshow\sthe\sactual\svalue\sof\sthe\nSQLITE_ENABLE_CEROD\scompile-time\soption,\sif\sit\sexists. +D 2018-03-19T16:09:36.383 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -436,7 +436,7 @@ F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd9 F src/build.c 8b53aacc26944bb7fd9ab5ddeedecb4cc7c4b84df3a420cf6d2b8f772ad421df 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 @@ -1712,7 +1712,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 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540 -R 4f358dadf4a5480f7a1f516d99ba5684 +P 30704d2a52d37717d8b34a402c99ea32453e5c1a9840037dba96591f4acc1503 +R 948fd22db623d1822c5dd56df59e09be U drh -Z dafbc788d38e72c2958479a7a802aa86 +Z ea6de7e0ab684bd3025cd78cad9267f5 diff --git a/manifest.uuid b/manifest.uuid index 287314654d..3815614650 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30704d2a52d37717d8b34a402c99ea32453e5c1a9840037dba96591f4acc1503 \ No newline at end of file +1ec339fd109b31e1d2b1e73345bd7a00c3d755f2c45c14d050a8203969163d60 \ No newline at end of file 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", From 8c1eba75a3465c628c59ce95623794b9012b664a Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Mar 2018 19:05:45 +0000 Subject: [PATCH 61/67] Enhance the command-line completion extension to return the names of triggers and views along with the names of tables. FossilOrigin-Name: 10e32204e1850354ff16fc052145726e903f87185a37f172831dddad1955184e --- ext/misc/completion.c | 5 ++--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) 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/manifest b/manifest index 29697c247e..56b8d3e8d4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\scompile_options\spragma,\sshow\sthe\sactual\svalue\sof\sthe\nSQLITE_ENABLE_CEROD\scompile-time\soption,\sif\sit\sexists. -D 2018-03-19T16:09:36.383 +C Enhance\sthe\scommand-line\scompletion\sextension\sto\sreturn\sthe\snames\sof\ntriggers\sand\sviews\salong\swith\sthe\snames\sof\stables. +D 2018-03-19T19:05:45.247 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -272,7 +272,7 @@ 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 22018e00eb50e9ebf9067c92d4e7162dc5006a3efc4e0c19bc3829825a1043b0 @@ -1712,7 +1712,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 30704d2a52d37717d8b34a402c99ea32453e5c1a9840037dba96591f4acc1503 -R 948fd22db623d1822c5dd56df59e09be +P 1ec339fd109b31e1d2b1e73345bd7a00c3d755f2c45c14d050a8203969163d60 +R 69307f298767656da036188fd7e04892 U drh -Z ea6de7e0ab684bd3025cd78cad9267f5 +Z 6ac86335f2d36be7a35b1bb439cc07e4 diff --git a/manifest.uuid b/manifest.uuid index 3815614650..d45eedd311 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ec339fd109b31e1d2b1e73345bd7a00c3d755f2c45c14d050a8203969163d60 \ No newline at end of file +10e32204e1850354ff16fc052145726e903f87185a37f172831dddad1955184e \ No newline at end of file From cfd74700daed6fea12dd06b3245768b213003375 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 19 Mar 2018 22:28:34 +0000 Subject: [PATCH 62/67] Minor improvements to ".selecttrace". No changes to non-debug code. FossilOrigin-Name: 03e541f606ead1a13e1084db88e168278c82a2ba72b18c89baafeab3141367b4 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/parse.y | 3 +-- src/select.c | 9 ++++----- src/sqliteInt.h | 1 - 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 56b8d3e8d4..735c0d956a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\scommand-line\scompletion\sextension\sto\sreturn\sthe\snames\sof\ntriggers\sand\sviews\salong\swith\sthe\snames\sof\stables. -D 2018-03-19T19:05:45.247 +C Minor\simprovements\sto\s".selecttrace".\s\sNo\schanges\sto\snon-debug\scode. +D 2018-03-19T22:28:34.252 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -478,7 +478,7 @@ F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 3e3b659b6b3f40b5a5efef6b8890ced490c397a81d96feb5266fde1f7362e608 F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a -F src/parse.y 3be4b2b5e33ef7dab3128b765898ee786fc6cd698a7f053f756a68f2f238f0aa +F src/parse.y 140bbc53b5f67f731239f7fc8704a4f1e60cbbc10fb84bf9577322f974725f19 F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170 F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880 @@ -489,12 +489,12 @@ F src/printf.c d3b7844ddeb11fbbdd38dd84d09c9c1ac171d21fb038473c3aa97981201cc660 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac -F src/select.c 1e9f53890f746f26d6955b38a6be37e65e32a6e5aea098c19cf7114730ea72e6 +F src/select.c a69962ae4faa8afd8149ca2897714580ff212c19bdcc2c733c3f5375295ffe98 F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f F src/sqlite.h.in 2619d00bccc0454e875bce5e90b1dc986f87975c267dd7bbbe251f1be297d2f3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d -F src/sqliteInt.h 2ef60a6d9a50e6eef224e9eae71b29a9fb91c301e882d9fbbb77afd50b6cf815 +F src/sqliteInt.h 51d03b44036108edf29cec31765c4b9706a2189cce17f25e9eed83efe80bbf14 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1712,7 +1712,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 1ec339fd109b31e1d2b1e73345bd7a00c3d755f2c45c14d050a8203969163d60 -R 69307f298767656da036188fd7e04892 +P 10e32204e1850354ff16fc052145726e903f87185a37f172831dddad1955184e +R 012c6c14620983eaab087972d93c496b U drh -Z 6ac86335f2d36be7a35b1bb439cc07e4 +Z c34bb330da7e0cc04245a4c39fd98568 diff --git a/manifest.uuid b/manifest.uuid index d45eedd311..edc06f4488 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -10e32204e1850354ff16fc052145726e903f87185a37f172831dddad1955184e \ No newline at end of file +03e541f606ead1a13e1084db88e168278c82a2ba72b18c89baafeab3141367b4 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 9c41484ab2..6b31e4c483 100644 --- a/src/parse.y +++ b/src/parse.y @@ -523,8 +523,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/select.c b/src/select.c index 4ceca44a8d..846f3cd154 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; } @@ -5547,6 +5544,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 +5733,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 +5989,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 +6045,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/sqliteInt.h b/src/sqliteInt.h index 3f34f48e15..dff3f61360 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2993,7 +2993,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 */ From 2d277bb5cb4c71c34205719442dadc4c19b44f59 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Mar 2018 11:24:30 +0000 Subject: [PATCH 63/67] Add the ability to disable the push-down optimization using the 0x1000 bit of SQLITE_TESTCTRL_OPTIMIZATIONS. FossilOrigin-Name: eddc35f3057e59fdc25a6911abfaa53a10cc43d8030925b65737b2f51f907421 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 4 ++++ src/sqliteInt.h | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 735c0d956a..e2136c8de1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\simprovements\sto\s".selecttrace".\s\sNo\schanges\sto\snon-debug\scode. -D 2018-03-19T22:28:34.252 +C Add\sthe\sability\sto\sdisable\sthe\spush-down\soptimization\susing\sthe\s0x1000\sbit\sof\nSQLITE_TESTCTRL_OPTIMIZATIONS. +D 2018-03-20T11:24:30.894 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -489,12 +489,12 @@ F src/printf.c d3b7844ddeb11fbbdd38dd84d09c9c1ac171d21fb038473c3aa97981201cc660 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac -F src/select.c a69962ae4faa8afd8149ca2897714580ff212c19bdcc2c733c3f5375295ffe98 +F src/select.c 0502980145d371c2e9ab31bdaef62c65355f4f815059324f8d764359cc1dcc21 F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f F src/sqlite.h.in 2619d00bccc0454e875bce5e90b1dc986f87975c267dd7bbbe251f1be297d2f3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d -F src/sqliteInt.h 51d03b44036108edf29cec31765c4b9706a2189cce17f25e9eed83efe80bbf14 +F src/sqliteInt.h 5c07bbc55d9eb3389a10536bd008e2d6f20f586871972610431d943595b40ca4 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1712,7 +1712,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 10e32204e1850354ff16fc052145726e903f87185a37f172831dddad1955184e -R 012c6c14620983eaab087972d93c496b +P 03e541f606ead1a13e1084db88e168278c82a2ba72b18c89baafeab3141367b4 +R 1ece0ada3df1cea55ee78c94a52ab76c U drh -Z c34bb330da7e0cc04245a4c39fd98568 +Z 21a1dc5431382fcb6e69355078bceb48 diff --git a/manifest.uuid b/manifest.uuid index edc06f4488..b9cb815672 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -03e541f606ead1a13e1084db88e168278c82a2ba72b18c89baafeab3141367b4 \ No newline at end of file +eddc35f3057e59fdc25a6911abfaa53a10cc43d8030925b65737b2f51f907421 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 846f3cd154..5dc831c367 100644 --- a/src/select.c +++ b/src/select.c @@ -3853,6 +3853,7 @@ static int pushDownWhereTerms( Expr *pNew; int nChng = 0; if( pWhere==0 ) return 0; +return 0; if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ #ifdef SQLITE_DEBUG @@ -5334,6 +5335,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 @@ -5342,6 +5344,8 @@ int sqlite3Select( sqlite3TreeViewSelect(0, p, 0); } #endif + }else{ + SELECTTRACE(0x100,pParse,p,("Push-down not possible\n")); } zSavedAuthContext = pParse->zAuthContext; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index dff3f61360..038fd5da88 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1532,6 +1532,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 */ /* From d06b5357a4d11e506940e4843e512ac21f5781e5 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Mar 2018 11:51:36 +0000 Subject: [PATCH 64/67] Fix a minor formatting issue on the sqlite3_db_config() documentation. No changes to code. FossilOrigin-Name: 8a439a6dda390d7486feb837f87a83e16abd283c882e81e637bd1235d2684379 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index e2136c8de1..574b308b2a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sability\sto\sdisable\sthe\spush-down\soptimization\susing\sthe\s0x1000\sbit\sof\nSQLITE_TESTCTRL_OPTIMIZATIONS. -D 2018-03-20T11:24:30.894 +C Fix\sa\sminor\sformatting\sissue\son\sthe\ssqlite3_db_config()\sdocumentation.\nNo\schanges\sto\scode. +D 2018-03-20T11:51:36.092 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -491,7 +491,7 @@ F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 0502980145d371c2e9ab31bdaef62c65355f4f815059324f8d764359cc1dcc21 F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f -F src/sqlite.h.in 2619d00bccc0454e875bce5e90b1dc986f87975c267dd7bbbe251f1be297d2f3 +F src/sqlite.h.in 9366a3fc56d96fc405492296a2245796a8899b4882e5c911f39b21c45d3742e6 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d F src/sqliteInt.h 5c07bbc55d9eb3389a10536bd008e2d6f20f586871972610431d943595b40ca4 @@ -1712,7 +1712,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 03e541f606ead1a13e1084db88e168278c82a2ba72b18c89baafeab3141367b4 -R 1ece0ada3df1cea55ee78c94a52ab76c +P eddc35f3057e59fdc25a6911abfaa53a10cc43d8030925b65737b2f51f907421 +R b459fde9f9fc6bed9a55f4e4cc80ea3a U drh -Z 21a1dc5431382fcb6e69355078bceb48 +Z 424309a260ffc365c6d17df4cbe208e8 diff --git a/manifest.uuid b/manifest.uuid index b9cb815672..57195b8326 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eddc35f3057e59fdc25a6911abfaa53a10cc43d8030925b65737b2f51f907421 \ No newline at end of file +8a439a6dda390d7486feb837f87a83e16abd283c882e81e637bd1235d2684379 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index c718a6faab..cc5244f002 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2059,6 +2059,7 @@ struct sqlite3_mem_methods { ** 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, @@ -2069,6 +2070,7 @@ struct sqlite3_mem_methods { ** the QPSG active, SQLite will always use the same query plan in the field as ** was used during testing in the lab. **
+** **
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 From 8b3424d4ee78c031032d161f4879325c1e34e847 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Mar 2018 11:58:28 +0000 Subject: [PATCH 65/67] Closer reading of the sqlite3_db_config() documentation show that it is subtly incorrect. This check-in fixes the problem. No code changes. FossilOrigin-Name: 44d90e7f4bc83680e8fbbf1a0423c6f5cc2cc2aed118b7af1c4c3d9e09b05dd7 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 13 ++++++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 574b308b2a..c7f460229b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sminor\sformatting\sissue\son\sthe\ssqlite3_db_config()\sdocumentation.\nNo\schanges\sto\scode. -D 2018-03-20T11:51:36.092 +C Closer\sreading\sof\sthe\ssqlite3_db_config()\sdocumentation\sshow\sthat\sit\sis\nsubtly\sincorrect.\s\sThis\scheck-in\sfixes\sthe\sproblem.\s\sNo\scode\schanges. +D 2018-03-20T11:58:28.771 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -491,7 +491,7 @@ F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 0502980145d371c2e9ab31bdaef62c65355f4f815059324f8d764359cc1dcc21 F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f -F src/sqlite.h.in 9366a3fc56d96fc405492296a2245796a8899b4882e5c911f39b21c45d3742e6 +F src/sqlite.h.in 19762b57baa1ade67531f254de94374428fb9c82452ef305017847945f9c2911 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d F src/sqliteInt.h 5c07bbc55d9eb3389a10536bd008e2d6f20f586871972610431d943595b40ca4 @@ -1712,7 +1712,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 eddc35f3057e59fdc25a6911abfaa53a10cc43d8030925b65737b2f51f907421 -R b459fde9f9fc6bed9a55f4e4cc80ea3a +P 8a439a6dda390d7486feb837f87a83e16abd283c882e81e637bd1235d2684379 +R 4a8d2973e82f63e78c33aea4d4a98f42 U drh -Z 424309a260ffc365c6d17df4cbe208e8 +Z 941c6c30265726a1112c988a7aaa89dd diff --git a/manifest.uuid b/manifest.uuid index 57195b8326..75a8262559 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8a439a6dda390d7486feb837f87a83e16abd283c882e81e637bd1235d2684379 \ No newline at end of file +44d90e7f4bc83680e8fbbf1a0423c6f5cc2cc2aed118b7af1c4c3d9e09b05dd7 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index cc5244f002..e7de61bce0 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -2054,8 +2054,9 @@ 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. **
@@ -2069,6 +2070,11 @@ 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
@@ -2076,7 +2082,8 @@ struct sqlite3_mem_methods { ** 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. From 51efe098f4ba50b8af47bcddf8f266741808fde6 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Mar 2018 12:04:38 +0000 Subject: [PATCH 66/67] In the CLI, avoid extra .selecttrace and .wheretrace output when in ".eqp full" mode. FossilOrigin-Name: 427bbf318a28e827bf03d43c2912c8ad937dd52f829feaf7fe374093692ed61b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 7 ++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c7f460229b..6e2f69705c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Closer\sreading\sof\sthe\ssqlite3_db_config()\sdocumentation\sshow\sthat\sit\sis\nsubtly\sincorrect.\s\sThis\scheck-in\sfixes\sthe\sproblem.\s\sNo\scode\schanges. -D 2018-03-20T11:58:28.771 +C In\sthe\sCLI,\savoid\sextra\s.selecttrace\sand\s.wheretrace\soutput\swhen\sin\s".eqp\sfull"\nmode. +D 2018-03-20T12:04:38.276 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -490,7 +490,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 0502980145d371c2e9ab31bdaef62c65355f4f815059324f8d764359cc1dcc21 -F src/shell.c.in 52b1b3f52159144391d598f43ef7ce13f58f35fcc18ae04df68e879695a1747f +F src/shell.c.in 911b9e3bce40413c78fdba28efa28363e98183819bd4b300780bf57bacfc4b84 F src/sqlite.h.in 19762b57baa1ade67531f254de94374428fb9c82452ef305017847945f9c2911 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d @@ -1712,7 +1712,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 8a439a6dda390d7486feb837f87a83e16abd283c882e81e637bd1235d2684379 -R 4a8d2973e82f63e78c33aea4d4a98f42 +P 44d90e7f4bc83680e8fbbf1a0423c6f5cc2cc2aed118b7af1c4c3d9e09b05dd7 +R 1f5ff659ead58dfc9d628c41aebcf2de U drh -Z 941c6c30265726a1112c988a7aaa89dd +Z c69f433226dc8ea5cb136d594ea65a55 diff --git a/manifest.uuid b/manifest.uuid index 75a8262559..5462851834 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -44d90e7f4bc83680e8fbbf1a0423c6f5cc2cc2aed118b7af1c4c3d9e09b05dd7 \ No newline at end of file +427bbf318a28e827bf03d43c2912c8ad937dd52f829feaf7fe374093692ed61b \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 26e58aef3a..a8342f5b17 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2879,7 +2879,12 @@ static int shell_exec( 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(); } From 9579947c556de5074c4a0928888627de61d52b50 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Mar 2018 13:00:33 +0000 Subject: [PATCH 67/67] Remove a debugging statement accidently left in check-in [eddc35f3057e59fd] FossilOrigin-Name: 85a31557ac0d0401c1bf2e23a502dc2ea57d9b1bc23c01de693f5d3fe22d8341 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6e2f69705c..908f93c3b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sCLI,\savoid\sextra\s.selecttrace\sand\s.wheretrace\soutput\swhen\sin\s".eqp\sfull"\nmode. -D 2018-03-20T12:04:38.276 +C Remove\sa\sdebugging\sstatement\saccidently\sleft\sin\s\ncheck-in\s[eddc35f3057e59fd] +D 2018-03-20T13:00:33.520 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -489,7 +489,7 @@ F src/printf.c d3b7844ddeb11fbbdd38dd84d09c9c1ac171d21fb038473c3aa97981201cc660 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac -F src/select.c 0502980145d371c2e9ab31bdaef62c65355f4f815059324f8d764359cc1dcc21 +F src/select.c 97a2131f02c605c52a6d5deac5b2ae6604db8c346829eb6b185bc38512a9b49a F src/shell.c.in 911b9e3bce40413c78fdba28efa28363e98183819bd4b300780bf57bacfc4b84 F src/sqlite.h.in 19762b57baa1ade67531f254de94374428fb9c82452ef305017847945f9c2911 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1712,7 +1712,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 44d90e7f4bc83680e8fbbf1a0423c6f5cc2cc2aed118b7af1c4c3d9e09b05dd7 -R 1f5ff659ead58dfc9d628c41aebcf2de +P 427bbf318a28e827bf03d43c2912c8ad937dd52f829feaf7fe374093692ed61b +R d3a1ae3cc198f0c3a9d536dfeb97a4db U drh -Z c69f433226dc8ea5cb136d594ea65a55 +Z bda748e312ea59415f3538d4e402a9df diff --git a/manifest.uuid b/manifest.uuid index 5462851834..a82fa52ae8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -427bbf318a28e827bf03d43c2912c8ad937dd52f829feaf7fe374093692ed61b \ No newline at end of file +85a31557ac0d0401c1bf2e23a502dc2ea57d9b1bc23c01de693f5d3fe22d8341 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 5dc831c367..5b60fc6a67 100644 --- a/src/select.c +++ b/src/select.c @@ -3853,7 +3853,6 @@ static int pushDownWhereTerms( Expr *pNew; int nChng = 0; if( pWhere==0 ) return 0; -return 0; if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */ #ifdef SQLITE_DEBUG