From 688633cb9eb400d8c69cbbcd99a4410a810bf0fb Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Mar 2017 19:26:34 +0000 Subject: [PATCH 01/60] Infrastructure for an extension C-library to implement sqlite3_db_dump() and a corresponding "dbdump" command-line utility - both of which do the same work as the ".dump" command of the CLI. FossilOrigin-Name: 74c5ace498f72d7f5495203678bedd0bc540211131a4e4db7b62115d5322a288 --- Makefile.in | 4 ++ ext/misc/dbdump.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++ main.mk | 4 ++ manifest | 19 +++++---- manifest.uuid | 2 +- 5 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 ext/misc/dbdump.c diff --git a/Makefile.in b/Makefile.in index ba59b3723f..0b40cb458b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1154,6 +1154,10 @@ sqlite3_analyzer.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl sqlite3_analyzer$(TEXE): sqlite3_analyzer.c $(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS) +dbdump$(TEXE): $(TOP)/ext/misc/dbdump.c sqlite3.lo + $(LTLINK) -DDBDUMP_STANDALONE -o $@ \ + $(TOP)/ext/misc/dbdump.c sqlite3.lo $(TLIBS) + showdb$(TEXE): $(TOP)/tool/showdb.c sqlite3.lo $(LTLINK) -o $@ $(TOP)/tool/showdb.c sqlite3.lo $(TLIBS) diff --git a/ext/misc/dbdump.c b/ext/misc/dbdump.c new file mode 100644 index 0000000000..b7fe595e29 --- /dev/null +++ b/ext/misc/dbdump.c @@ -0,0 +1,103 @@ +/* +** 2016-03-13 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +****************************************************************************** +** +** This file implements a C-language subroutine that converts the content +** of an SQLite database into UTF-8 text SQL statements that can be used +** to exactly recreate the original database. +** +** A prototype of the implemented subroutine is this: +** +** int sqlite3_db_dump( +** sqlite3 *db, +** const char *zSchema, +** const char *zTable, +** void (*xCallback)(void*, const char*), +** void *pArg +** ); +** +** The db parameter is the database connection. zSchema is the schema within +** that database which is to be dumped. Usually the zSchema is "main" but +** can also be "temp" or any ATTACH-ed database. If zTable is not NULL, then +** only the content of that one table is dumped. If zTable is NULL, then all +** tables are dumped. +** +** The generate text is passed to xCallback() in multiple calls. The second +** argument to xCallback() is a copy of the pArg parameter. The first +** argument is some of the output text that this routine generates. The +** signature to xCallback() is designed to make it compatible with fputs(). +** +** The sqlite3_db_dump() subroutine returns SQLITE_OK on success or some error +** code if it encounters a problem. +** +** If this file is compiled with -DDBDUMP_STANDALONE then a "main()" routine +** is included so that this routine becomes a command-line utility. The +** command-line utility takes two or three arguments which are the name +** of the database file, the schema, and optionally the table, forming the +** first three arguments of a single call to the library routine. +*/ +#include "sqlite3.h" + +/* +** Convert an SQLite database into SQL statements that will recreate that +** database. +*/ +int sqlite3_db_dump( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which schema to dump. Usually "main". */ + const char *zTable, /* Which table to dump. NULL means everything. */ + int (*xCallback)(const char*,void*), /* Output sent to this callback */ + void *pArg /* Second argument of the callback */ +){ + return SQLITE_OK; +} + + + +/* The generic subroutine is above. The code the follows implements +** the command-line interface. +*/ +#ifdef DBDUMP_STANDALONE +#include + +/* +** Command-line interface +*/ +int main(int argc, char **argv){ + sqlite3 *db; + const char *zDb; + const char *zSchema; + const char *zTable = 0; + int rc; + + if( argc<2 || argc>4 ){ + fprintf(stderr, "Usage: %s DATABASE ?SCHEMA? ?TABLE?\n", argv[0]); + return 1; + } + zDb = argv[1]; + zSchema = argc>=3 ? argv[2] : "main"; + zTable = argc==4 ? argv[3] : 0; + + rc = sqlite3_open(zDb, &db); + if( rc ){ + fprintf(stderr, "Cannot open \"%s\": %s\n", zDb, sqlite3_errmsg(db)); + sqlite3_close(db); + return 1; + } + rc = sqlite3_db_dump(db, zSchema, zTable, + (int(*)(const char*,void*))fputs, (void*)stdout); + if( rc ){ + fprintf(stderr, "Error: sqlite3_db_dump() returns %d\n", rc); + } + sqlite3_close(db); + return rc!=SQLITE_OK; +} +#endif /* DBDUMP_STANDALONE */ diff --git a/main.mk b/main.mk index 8815f0f701..54f223bb56 100644 --- a/main.mk +++ b/main.mk @@ -761,6 +761,10 @@ sqlite3_analyzer.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl sqlite3_analyzer$(EXE): sqlite3_analyzer.c $(TCCX) $(TCL_FLAGS) sqlite3_analyzer.c -o $@ $(LIBTCL) $(THREADLIB) +dbdump$(EXE): $(TOP)/ext/misc/dbdump.c sqlite3.o + $(TCCX) -DDBDUMP_STANDALONE -o dbdump$(EXE) \ + $(TOP)/ext/misc/dbdump.c sqlite3.o $(THREADLIB) + # Rules to build the 'testfixture' application. # TESTFIXTURE_FLAGS = -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 diff --git a/manifest b/manifest index b74ca835a2..4fc996e4ef 100644 --- a/manifest +++ b/manifest @@ -1,6 +1,6 @@ -C In\sthe\soutput\sof\sthe\s".dump"\scommand\sin\sthe\sCLI,\squote\snewline\sand\ncarriage-return\scharacters\susing\sthe\schar()\sfunction,\sso\sthat\sthey\sdo\snot\nget\seaten\sby\send-of-line\sprocessing\slogic\sin\sthe\sOS\sor\sin\sother\scommand-line\nutilities\sand/or\slibraries. -D 2017-03-13T18:24:06.748 -F Makefile.in 2dae2a56457c2885425a480e1053de8096aff924 +C Infrastructure\sfor\san\sextension\sC-library\sto\simplement\ssqlite3_db_dump()\sand\na\scorresponding\s"dbdump"\scommand-line\sutility\s-\sboth\sof\swhich\sdo\sthe\ssame\nwork\sas\sthe\s".dump"\scommand\sof\sthe\sCLI. +D 2017-03-13T19:26:34.140 +F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 9020fa41eb91f657ae0cc44145d0a2f3af520860 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 @@ -211,6 +211,7 @@ F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/csv.c 531a46cbad789fca0aa9db69a0e6c8ac9e68767d +F ext/misc/dbdump.c 5777b95fe1797a7fce841f4cb88bc30f66b8a3c929e988b1d3b3cf4aab044739 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 @@ -322,7 +323,7 @@ F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 0ec10b604f4668f7e85a358954babe75c94dc0d5 +F main.mk 9abb506e717887d57f754bae139b85c1a06d6f2ac25b589f3e792e310567f278 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -1563,8 +1564,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 9034cf7efc603864f51e931c7dc4fbbc2d01904e951e78c88d4d80f9936250e8 8b2954dd8376e2de985cf5dedeb6eec32c430505 -R 73c5fbe608fb0e20ee39173a6198ea04 -T +closed 8b2954dd8376e2de985cf5dedeb6eec32c430505 +P 68f6dc7af1013f296a11db14c007cc13cc3fe56832848bfed835ed8f74dcc676 +R 26910a3d8e71b6c159f5bba8a9a5daac +T *branch * dbdump +T *sym-dbdump * +T -sym-trunk * U drh -Z 5e4a79f0eabba6013ee57f9716ad3797 +Z 0266a8ae90d3841510ebcee8fa626828 diff --git a/manifest.uuid b/manifest.uuid index 35073a3308..f9e622d35f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -68f6dc7af1013f296a11db14c007cc13cc3fe56832848bfed835ed8f74dcc676 \ No newline at end of file +74c5ace498f72d7f5495203678bedd0bc540211131a4e4db7b62115d5322a288 \ No newline at end of file From 473af4fe03643d1cc771a3e394eb8579c3fbf61a Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Mar 2017 21:26:41 +0000 Subject: [PATCH 02/60] First draft of the complete dbdump.c library. FossilOrigin-Name: 84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d --- ext/misc/dbdump.c | 614 +++++++++++++++++++++++++++++++++++++++++++++- manifest | 15 +- manifest.uuid | 2 +- 3 files changed, 619 insertions(+), 12 deletions(-) diff --git a/ext/misc/dbdump.c b/ext/misc/dbdump.c index b7fe595e29..ce51eba0a0 100644 --- a/ext/misc/dbdump.c +++ b/ext/misc/dbdump.c @@ -12,7 +12,7 @@ ** ** This file implements a C-language subroutine that converts the content ** of an SQLite database into UTF-8 text SQL statements that can be used -** to exactly recreate the original database. +** to exactly recreate the original database. ROWID values are preserved. ** ** A prototype of the implemented subroutine is this: ** @@ -45,6 +45,574 @@ ** first three arguments of a single call to the library routine. */ #include "sqlite3.h" +#include +#include +#include + +/* +** The state of the dump process. +*/ +typedef struct DState DState; +struct DState { + sqlite3 *db; /* The database connection */ + int nErr; /* Number of errors seen so far */ + int rc; /* Error code */ + int writableSchema; /* True if in writable_schema mode */ + int (*xCallback)(const char*,void*); /* Send output here */ + void *pArg; /* Argument to xCallback() */ +}; + +/* +** A variable length string to which one can append text. +*/ +typedef struct DText DText; +struct DText { + char *z; /* The text */ + int n; /* Number of bytes of content in z[] */ + int nAlloc; /* Number of bytes allocated to z[] */ +}; + +/* +** Initialize and destroy a DText object +*/ +static void initText(DText *p){ + memset(p, 0, sizeof(*p)); +} +static void freeText(DText *p){ + sqlite3_free(p->z); + initText(p); +} + +/* zIn is either a pointer to a NULL-terminated string in memory obtained +** from malloc(), or a NULL pointer. The string pointed to by zAppend is +** added to zIn, and the result returned in memory obtained from malloc(). +** zIn, if it was not NULL, is freed. +** +** If the third argument, quote, is not '\0', then it is used as a +** quote character for zAppend. +*/ +static void appendText(DText *p, char const *zAppend, char quote){ + int len; + int i; + int nAppend = (int)(strlen(zAppend) & 0x3fffffff); + + len = nAppend+p->n+1; + if( quote ){ + len += 2; + for(i=0; in+len>=p->nAlloc ){ + char *zNew; + p->nAlloc = p->nAlloc*2 + len + 20; + zNew = sqlite3_realloc(p->z, p->nAlloc); + if( zNew==0 ){ + freeText(p); + return; + } + p->z = zNew; + } + + if( quote ){ + char *zCsr = p->z+p->n; + *zCsr++ = quote; + for(i=0; in = (int)(zCsr - p->z); + *zCsr = '\0'; + }else{ + memcpy(p->z+p->n, zAppend, nAppend); + p->n += nAppend; + p->z[p->n] = '\0'; + } +} + +/* +** Attempt to determine if identifier zName needs to be quoted, either +** because it contains non-alphanumeric characters, or because it is an +** SQLite keyword. Be conservative in this estimate: When in doubt assume +** that quoting is required. +** +** Return '"' if quoting is required. Return 0 if no quoting is required. +*/ +static char quoteChar(const char *zName){ + /* All SQLite keywords, in alphabetical order */ + static const char *azKeywords[] = { + "ABORT", "ACTION", "ADD", "AFTER", "ALL", "ALTER", "ANALYZE", "AND", "AS", + "ASC", "ATTACH", "AUTOINCREMENT", "BEFORE", "BEGIN", "BETWEEN", "BY", + "CASCADE", "CASE", "CAST", "CHECK", "COLLATE", "COLUMN", "COMMIT", + "CONFLICT", "CONSTRAINT", "CREATE", "CROSS", "CURRENT_DATE", + "CURRENT_TIME", "CURRENT_TIMESTAMP", "DATABASE", "DEFAULT", "DEFERRABLE", + "DEFERRED", "DELETE", "DESC", "DETACH", "DISTINCT", "DROP", "EACH", + "ELSE", "END", "ESCAPE", "EXCEPT", "EXCLUSIVE", "EXISTS", "EXPLAIN", + "FAIL", "FOR", "FOREIGN", "FROM", "FULL", "GLOB", "GROUP", "HAVING", "IF", + "IGNORE", "IMMEDIATE", "IN", "INDEX", "INDEXED", "INITIALLY", "INNER", + "INSERT", "INSTEAD", "INTERSECT", "INTO", "IS", "ISNULL", "JOIN", "KEY", + "LEFT", "LIKE", "LIMIT", "MATCH", "NATURAL", "NO", "NOT", "NOTNULL", + "NULL", "OF", "OFFSET", "ON", "OR", "ORDER", "OUTER", "PLAN", "PRAGMA", + "PRIMARY", "QUERY", "RAISE", "RECURSIVE", "REFERENCES", "REGEXP", + "REINDEX", "RELEASE", "RENAME", "REPLACE", "RESTRICT", "RIGHT", + "ROLLBACK", "ROW", "SAVEPOINT", "SELECT", "SET", "TABLE", "TEMP", + "TEMPORARY", "THEN", "TO", "TRANSACTION", "TRIGGER", "UNION", "UNIQUE", + "UPDATE", "USING", "VACUUM", "VALUES", "VIEW", "VIRTUAL", "WHEN", "WHERE", + "WITH", "WITHOUT", + }; + int i, lwr, upr, mid, c; + if( !isalpha((unsigned char)zName[0]) && zName[0]!='_' ) return '"'; + for(i=0; zName[i]; i++){ + if( !isalnum((unsigned char)zName[i]) && zName[i]!='_' ) return '"'; + } + lwr = 0; + upr = sizeof(azKeywords)/sizeof(azKeywords[0]) - 1; + while( lwr<=upr ){ + mid = (lwr+upr)/2; + c = sqlite3_stricmp(azKeywords[mid], zName); + if( c==0 ) return '"'; + if( c<0 ){ + lwr = mid+1; + }else{ + upr = mid-1; + } + } + return 0; +} + + +/* +** Release memory previously allocated by tableColumnList(). +*/ +static void freeColumnList(char **azCol){ + int i; + for(i=1; azCol[i]; i++){ + sqlite3_free(azCol[i]); + } + /* azCol[0] is a static string */ + sqlite3_free(azCol); +} + +/* +** Return a list of pointers to strings which are the names of all +** columns in table zTab. The memory to hold the names is dynamically +** allocated and must be released by the caller using a subsequent call +** to freeColumnList(). +** +** The azCol[0] entry is usually NULL. However, if zTab contains a rowid +** value that needs to be preserved, then azCol[0] is filled in with the +** name of the rowid column. +** +** The first regular column in the table is azCol[1]. The list is terminated +** by an entry with azCol[i]==0. +*/ +static char **tableColumnList(DState *p, const char *zTab){ + char **azCol = 0; + sqlite3_stmt *pStmt = 0; + char *zSql; + int nCol = 0; + int nAlloc = 0; + int nPK = 0; /* Number of PRIMARY KEY columns seen */ + int isIPK = 0; /* True if one PRIMARY KEY column of type INTEGER */ + int preserveRowid = 1; + int rc; + + zSql = sqlite3_mprintf("PRAGMA table_info=%Q", zTab); + if( zSql==0 ) return 0; + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); + sqlite3_free(zSql); + if( rc ) return 0; + azCol[0] = 0; + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + if( nCol>=nAlloc-2 ){ + char **azNew; + nAlloc = nAlloc*2 + nCol + 10; + azNew = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0])); + if( azNew==0 ) goto col_oom; + azCol = azNew; + } + azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1)); + if( azCol[nCol]==0 ) goto col_oom; + if( sqlite3_column_int(pStmt, 5) ){ + nPK++; + if( nPK==1 + && sqlite3_stricmp((const char*)sqlite3_column_text(pStmt,2), + "INTEGER")==0 + ){ + isIPK = 1; + }else{ + isIPK = 0; + } + } + } + sqlite3_finalize(pStmt); + pStmt = 0; + azCol[nCol+1] = 0; + + /* The decision of whether or not a rowid really needs to be preserved + ** is tricky. We never need to preserve a rowid for a WITHOUT ROWID table + ** or a table with an INTEGER PRIMARY KEY. We are unable to preserve + ** rowids on tables where the rowid is inaccessible because there are other + ** columns in the table named "rowid", "_rowid_", and "oid". + */ + if( isIPK ){ + /* If a single PRIMARY KEY column with type INTEGER was seen, then it + ** might be an alise for the ROWID. But it might also be a WITHOUT ROWID + ** table or a INTEGER PRIMARY KEY DESC column, neither of which are + ** ROWID aliases. To distinguish these cases, check to see if + ** there is a "pk" entry in "PRAGMA index_list". There will be + ** no "pk" index if the PRIMARY KEY really is an alias for the ROWID. + */ + zSql = sqlite3_mprintf("SELECT 1 FROM pragma_index_list(%Q)" + " WHERE origin='pk'", zTab); + if( zSql==0 ) goto col_oom; + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); + sqlite3_free(zSql); + if( rc ){ + freeColumnList(azCol); + return 0; + } + rc = sqlite3_step(pStmt); + sqlite3_finalize(pStmt); + pStmt = 0; + preserveRowid = rc==SQLITE_ROW; + } + if( preserveRowid ){ + /* Only preserve the rowid if we can find a name to use for the + ** rowid */ + static char *azRowid[] = { "rowid", "_rowid_", "oid" }; + int i, j; + for(j=0; j<3; j++){ + for(i=1; i<=nCol; i++){ + if( sqlite3_stricmp(azRowid[j],azCol[i])==0 ) break; + } + if( i>nCol ){ + /* At this point, we know that azRowid[j] is not the name of any + ** 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; + } + } + } + return azCol; + +col_oom: + sqlite3_finalize(pStmt); + freeColumnList(azCol); + p->nErr++; + p->rc = SQLITE_NOMEM; + return 0; +} + +/* +** Send mprintf-formatted content to the output callback. +*/ +static void output_formatted(DState *p, const char *zFormat, ...){ + va_list ap; + char *z; + va_start(ap, zFormat); + z = sqlite3_mprintf(zFormat, ap); + va_end(ap); + p->xCallback(z, p->pArg); + sqlite3_free(z); +} + +/* +** Output the given string as a quoted string using SQL quoting conventions. +** +** The "\n" and "\r" characters are converted to char(10) and char(13) +** to prevent them from being transformed by end-of-line translators. +*/ +static void output_quoted_string(DState *p, const unsigned char *z){ + int i; + char c; + int inQuote = 0; + int bStarted = 0; + + for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} + if( c==0 ){ + output_formatted(p, "'%s'", z); + return; + } + while( *z ){ + for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){} + if( c=='\'' ) i++; + if( i ){ + if( !inQuote ){ + if( bStarted ) p->xCallback("||", p->pArg); + p->xCallback("'", p->pArg); + inQuote = 1; + } + output_formatted(p, "%.*s", i, z); + z += i; + bStarted = 1; + } + if( c=='\'' ){ + p->xCallback("'", p->pArg); + continue; + } + if( inQuote ){ + p->xCallback("'", p->pArg); + inQuote = 0; + } + if( c==0 ){ + break; + } + for(i=0; (c = z[i])=='\r' || c=='\n'; i++){ + if( bStarted ) p->xCallback("||", p->pArg); + output_formatted(p, "char(%d)", c); + bStarted = 1; + } + z += i; + } + if( inQuote ) p->xCallback("'", p->pArg); +} + +/* +** This is an sqlite3_exec callback routine used for dumping the database. +** Each row received by this callback consists of a table name, +** the table type ("index" or "table") and SQL to create the table. +** This routine should print text sufficient to recreate the table. +*/ +static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ + int rc; + const char *zTable; + const char *zType; + const char *zSql; + DState *p = (DState*)pArg; + sqlite3_stmt *pStmt; + + (void)azCol; + if( nArg!=3 ) return 1; + zTable = azArg[0]; + zType = azArg[1]; + zSql = azArg[2]; + + if( strcmp(zTable, "sqlite_sequence")==0 ){ + p->xCallback("DELETE FROM sqlite_sequence;\n", p->pArg); + }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){ + p->xCallback("ANALYZE sqlite_master;\n", p->pArg); + }else if( strncmp(zTable, "sqlite_", 7)==0 ){ + return 0; + }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ + if( !p->writableSchema ){ + p->xCallback("PRAGMA writable_schema=ON;\n", p->pArg); + p->writableSchema = 1; + } + output_formatted(p, + "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)" + "VALUES('table','%q','%q',0,'%q');", + zTable, zTable, zSql); + return 0; + }else{ + if( sqlite3_strglob("CREATE TABLE ['\"]*", zSql)==0 ){ + p->xCallback("CREATE TABLE IF NOT EXISTS ", p->pArg); + p->xCallback(zSql+13, p->pArg); + }else{ + p->xCallback(zSql, p->pArg); + } + p->xCallback(";\n", p->pArg); + } + + if( strcmp(zType, "table")==0 ){ + DText sSelect; + DText sTable; + char **azCol; + int i; + int nCol; + + azCol = tableColumnList(p, zTable); + if( azCol==0 ) return 0; + + /* Always quote the table name, even if it appears to be pure ascii, + ** in case it is a keyword. Ex: INSERT INTO "table" ... */ + initText(&sTable); + appendText(&sTable, zTable, quoteChar(zTable)); + /* If preserving the rowid, add a column list after the table name. + ** In other words: "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)" + ** instead of the usual "INSERT INTO tab VALUES(...)". + */ + if( azCol[0] ){ + appendText(&sTable, "(", 0); + appendText(&sTable, azCol[0], 0); + for(i=1; azCol[i]; i++){ + appendText(&sTable, ",", 0); + appendText(&sTable, azCol[i], quoteChar(azCol[i])); + } + appendText(&sTable, ")", 0); + } + appendText(&sTable, " VALUES(", 0); + + /* Build an appropriate SELECT statement */ + initText(&sSelect); + appendText(&sSelect, "SELECT ", 0); + if( azCol[0] ){ + appendText(&sSelect, azCol[0], 0); + appendText(&sSelect, ",", 0); + } + for(i=1; azCol[i]; i++){ + appendText(&sSelect, azCol[i], quoteChar(azCol[i])); + if( azCol[i+1] ){ + appendText(&sSelect, ",", 0); + } + } + nCol = i-1; + freeColumnList(azCol); + appendText(&sSelect, " FROM ", 0); + appendText(&sSelect, zTable, quoteChar(zTable)); + + rc = sqlite3_prepare_v2(p->db, sSelect.z, -1, &pStmt, 0); + if( rc!=SQLITE_OK ){ + p->nErr++; + if( p->rc==SQLITE_OK ) p->rc = rc; + }else{ + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + p->xCallback(sTable.z, p->pArg); + for(i=0; ixCallback(",", p->pArg); + switch( sqlite3_column_type(pStmt,i) ){ + case SQLITE_INTEGER: { + output_formatted(p, "%lld", sqlite3_column_int64(pStmt,i)); + break; + } + case SQLITE_FLOAT: { + double r = sqlite3_column_double(pStmt,i); + output_formatted(p, "%!.20g", r); + break; + } + case SQLITE_NULL: { + p->xCallback("NULL", p->pArg); + break; + } + case SQLITE_TEXT: { + output_quoted_string(p, sqlite3_column_text(pStmt,i)); + break; + } + case SQLITE_BLOB: { + int nByte = sqlite3_column_bytes(pStmt,i); + unsigned char *a = (unsigned char*)sqlite3_column_blob(pStmt,i); + int j; + p->xCallback("x'", p->pArg); + for(j=0; j>4)&15]; + zWord[1] = "0123456789abcdef"[a[j]&15]; + zWord[2] = 0; + p->xCallback(zWord, p->pArg); + } + p->xCallback("'", p->pArg); + break; + } + } + } + p->xCallback(");\n", p->pArg); + } + } + sqlite3_finalize(pStmt); + freeText(&sTable); + freeText(&sSelect); + } + return 0; +} + + +/* +** Execute a query statement that will generate SQL output. Print +** the result columns, comma-separated, on a line and then add a +** semicolon terminator to the end of that line. +** +** If the number of columns is 1 and that column contains text "--" +** then write the semicolon on a separate line. That way, if a +** "--" comment occurs at the end of the statement, the comment +** won't consume the semicolon terminator. +*/ +static void output_sql_from_query( + DState *p, /* Query context */ + const char *zSelect, /* SELECT statement to extract content */ + ... +){ + sqlite3_stmt *pSelect; + int rc; + int nResult; + int i; + const char *z; + char *zSql; + va_list ap; + va_start(ap, zSelect); + zSql = sqlite3_mprintf(zSelect, ap); + va_end(ap); + if( zSql==0 ){ + p->rc = SQLITE_NOMEM; + p->nErr++; + return; + } + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pSelect, 0); + sqlite3_free(zSql); + if( rc!=SQLITE_OK || !pSelect ){ + output_formatted(p, "/**** ERROR: (%d) %s *****/\n", rc, + sqlite3_errmsg(p->db)); + p->nErr++; + return; + } + rc = sqlite3_step(pSelect); + nResult = sqlite3_column_count(pSelect); + while( rc==SQLITE_ROW ){ + z = (const char*)sqlite3_column_text(pSelect, 0); + p->xCallback(z, p->pArg); + for(i=1; ixCallback(",", p->pArg); + p->xCallback((const char*)sqlite3_column_text(pSelect,i), p->pArg); + } + if( z==0 ) z = ""; + while( z[0] && (z[0]!='-' || z[1]!='-') ) z++; + if( z[0] ){ + p->xCallback("\n;\n", p->pArg); + }else{ + p->xCallback(";\n", p->pArg); + } + rc = sqlite3_step(pSelect); + } + rc = sqlite3_finalize(pSelect); + if( rc!=SQLITE_OK ){ + output_formatted(p, "/**** ERROR: (%d) %s *****/\n", rc, + sqlite3_errmsg(p->db)); + if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; + } +} + +/* +** Run zQuery. Use dump_callback() as the callback routine so that +** the contents of the query are output as SQL statements. +** +** If we get a SQLITE_CORRUPT error, rerun the query after appending +** "ORDER BY rowid DESC" to the end. +*/ +static void run_schema_dump_query( + DState *p, + const char *zQuery, + ... +){ + char *zErr = 0; + char *z; + va_list ap; + va_start(ap, zQuery); + z = sqlite3_mprintf(zQuery, ap); + va_end(ap); + sqlite3_exec(p->db, z, dump_callback, p, &zErr); + sqlite3_free(z); + if( zErr ){ + output_formatted(p, "/****** %s ******/\n", zErr); + sqlite3_free(zErr); + p->nErr++; + zErr = 0; + } +} /* ** Convert an SQLite database into SQL statements that will recreate that @@ -57,7 +625,49 @@ int sqlite3_db_dump( int (*xCallback)(const char*,void*), /* Output sent to this callback */ void *pArg /* Second argument of the callback */ ){ - return SQLITE_OK; + DState x; + memset(&x, 0, sizeof(x)); + x.rc = sqlite3_exec(db, "BEGIN", 0, 0, 0); + if( x.rc ) return x.rc; + x.db = db; + x.xCallback = xCallback; + x.pArg = pArg; + xCallback("PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\n", pArg); + if( zTable==0 ){ + run_schema_dump_query(&x, + "SELECT name, type, sql FROM \"%w\".sqlite_master " + "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'", + zSchema + ); + run_schema_dump_query(&x, + "SELECT name, type, sql FROM \"%w\".sqlite_master " + "WHERE name=='sqlite_sequence'", zSchema + ); + output_sql_from_query(&x, + "SELECT sql FROM sqlite_master " + "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0 + ); + }else{ + run_schema_dump_query(&x, + "SELECT name, type, sql FROM \"%w\".sqlite_master " + "WHERE tbl_name=%Q COLLATE nocase AND type=='table'" + " AND sql NOT NULL", + zSchema, zTable + ); + output_sql_from_query(&x, + "SELECT sql FROM \"%w\".sqlite_master " + "WHERE sql NOT NULL" + " AND type IN ('index','trigger','view')" + " AND tbl_name=%Q COLLATE nocase", + zSchema, zTable + ); + } + if( x.writableSchema ){ + xCallback("PRAGMA writable_schema=OFF;\n", pArg); + } + xCallback(x.nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n", pArg); + sqlite3_exec(db, "COMMIT", 0, 0, 0); + return x.rc; } diff --git a/manifest b/manifest index 4fc996e4ef..dfbee1c83e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Infrastructure\sfor\san\sextension\sC-library\sto\simplement\ssqlite3_db_dump()\sand\na\scorresponding\s"dbdump"\scommand-line\sutility\s-\sboth\sof\swhich\sdo\sthe\ssame\nwork\sas\sthe\s".dump"\scommand\sof\sthe\sCLI. -D 2017-03-13T19:26:34.140 +C First\sdraft\sof\sthe\scomplete\sdbdump.c\slibrary. +D 2017-03-13T21:26:41.643 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 9020fa41eb91f657ae0cc44145d0a2f3af520860 @@ -211,7 +211,7 @@ F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/csv.c 531a46cbad789fca0aa9db69a0e6c8ac9e68767d -F ext/misc/dbdump.c 5777b95fe1797a7fce841f4cb88bc30f66b8a3c929e988b1d3b3cf4aab044739 +F ext/misc/dbdump.c 819eb33f6ff788a466525557f7ea3742078853cc794b2eb0799a254dd6da81e2 F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 @@ -1564,10 +1564,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 68f6dc7af1013f296a11db14c007cc13cc3fe56832848bfed835ed8f74dcc676 -R 26910a3d8e71b6c159f5bba8a9a5daac -T *branch * dbdump -T *sym-dbdump * -T -sym-trunk * +P 74c5ace498f72d7f5495203678bedd0bc540211131a4e4db7b62115d5322a288 +R dcbc2252d3d150af6e3faa70158994bd U drh -Z 0266a8ae90d3841510ebcee8fa626828 +Z 9a73382dae2ea2eb6bda6a3d74fd54dd diff --git a/manifest.uuid b/manifest.uuid index f9e622d35f..0597c414ba 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74c5ace498f72d7f5495203678bedd0bc540211131a4e4db7b62115d5322a288 \ No newline at end of file +84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d \ No newline at end of file From d3bc75fb941cdadf06bd8d5424ec8d856c89aabe Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Mar 2017 21:49:48 +0000 Subject: [PATCH 03/60] Fixes to the dump logic. All appears to be working in preliminary tests. FossilOrigin-Name: 007b11e301d444361c8eff8734dc2fb968a64343c177ff30cec74a0cf76099e8 --- ext/misc/dbdump.c | 16 ++++++++++------ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ext/misc/dbdump.c b/ext/misc/dbdump.c index ce51eba0a0..db581a8325 100644 --- a/ext/misc/dbdump.c +++ b/ext/misc/dbdump.c @@ -224,7 +224,6 @@ static char **tableColumnList(DState *p, const char *zTab){ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); if( rc ) return 0; - azCol[0] = 0; while( sqlite3_step(pStmt)==SQLITE_ROW ){ if( nCol>=nAlloc-2 ){ char **azNew; @@ -232,6 +231,7 @@ static char **tableColumnList(DState *p, const char *zTab){ azNew = sqlite3_realloc(azCol, nAlloc*sizeof(azCol[0])); if( azNew==0 ) goto col_oom; azCol = azNew; + azCol[0] = 0; } azCol[++nCol] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1)); if( azCol[nCol]==0 ) goto col_oom; @@ -317,7 +317,7 @@ static void output_formatted(DState *p, const char *zFormat, ...){ va_list ap; char *z; va_start(ap, zFormat); - z = sqlite3_mprintf(zFormat, ap); + z = sqlite3_vmprintf(zFormat, ap); va_end(ap); p->xCallback(z, p->pArg); sqlite3_free(z); @@ -430,10 +430,13 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ azCol = tableColumnList(p, zTable); if( azCol==0 ) return 0; + initText(&sTable); + appendText(&sTable, "INSERT INTO ", 0); + /* Always quote the table name, even if it appears to be pure ascii, ** in case it is a keyword. Ex: INSERT INTO "table" ... */ - initText(&sTable); appendText(&sTable, zTable, quoteChar(zTable)); + /* If preserving the rowid, add a column list after the table name. ** In other words: "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)" ** instead of the usual "INSERT INTO tab VALUES(...)". @@ -462,7 +465,8 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ appendText(&sSelect, ",", 0); } } - nCol = i-1; + nCol = i; + if( azCol[0]==0 ) nCol--; freeColumnList(azCol); appendText(&sSelect, " FROM ", 0); appendText(&sSelect, zTable, quoteChar(zTable)); @@ -545,7 +549,7 @@ static void output_sql_from_query( char *zSql; va_list ap; va_start(ap, zSelect); - zSql = sqlite3_mprintf(zSelect, ap); + zSql = sqlite3_vmprintf(zSelect, ap); va_end(ap); if( zSql==0 ){ p->rc = SQLITE_NOMEM; @@ -602,7 +606,7 @@ static void run_schema_dump_query( char *z; va_list ap; va_start(ap, zQuery); - z = sqlite3_mprintf(zQuery, ap); + z = sqlite3_vmprintf(zQuery, ap); va_end(ap); sqlite3_exec(p->db, z, dump_callback, p, &zErr); sqlite3_free(z); diff --git a/manifest b/manifest index dfbee1c83e..57159e7a5c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C First\sdraft\sof\sthe\scomplete\sdbdump.c\slibrary. -D 2017-03-13T21:26:41.643 +C Fixes\sto\sthe\sdump\slogic.\s\sAll\sappears\sto\sbe\sworking\sin\spreliminary\stests. +D 2017-03-13T21:49:48.351 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 9020fa41eb91f657ae0cc44145d0a2f3af520860 @@ -211,7 +211,7 @@ F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/csv.c 531a46cbad789fca0aa9db69a0e6c8ac9e68767d -F ext/misc/dbdump.c 819eb33f6ff788a466525557f7ea3742078853cc794b2eb0799a254dd6da81e2 +F ext/misc/dbdump.c 34174d537318027b159e3341105866c05a4149376ede59988c82280bed144e6d F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 @@ -1564,7 +1564,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 74c5ace498f72d7f5495203678bedd0bc540211131a4e4db7b62115d5322a288 -R dcbc2252d3d150af6e3faa70158994bd +P 84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d +R de364a9f85fa4899d644a897efb72e80 U drh -Z 9a73382dae2ea2eb6bda6a3d74fd54dd +Z 55e9f45d2725daddcac9a1569ce24da7 diff --git a/manifest.uuid b/manifest.uuid index 0597c414ba..db7f312b50 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d \ No newline at end of file +007b11e301d444361c8eff8734dc2fb968a64343c177ff30cec74a0cf76099e8 \ No newline at end of file From 4b34eb3bf5ad83be4ed86a4b5bef65945dfec95c Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 13 Mar 2017 22:02:01 +0000 Subject: [PATCH 04/60] Add dbdump.exe to the MSVC makefile. FossilOrigin-Name: 59241a50ad1d6fe9f5804b73b3467dcd407d359ccbdcb9d72f2f6d94c90c1f40 --- Makefile.msc | 4 ++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index 01307a3e92..ecaa837abb 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2178,6 +2178,10 @@ sqlite3_analyzer.exe: sqlite3_analyzer.c $(LIBRESOBJS) $(LTLINK) $(NO_WARN) -DBUILD_sqlite -I$(TCLINCDIR) sqlite3_analyzer.c \ /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) +dbdump.exe: $(TOP)\ext\misc\dbdump.c sqlite3.c + $(LTLINK) $(NO_WARN) -DDBDUMP_STANDALONE $(TOP)\ext\misc\dbdump.c sqlite3.c \ + /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) + testloadext.lo: $(TOP)\src\test_loadext.c $(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c diff --git a/manifest b/manifest index 57159e7a5c..46a6ae6e2d 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Fixes\sto\sthe\sdump\slogic.\s\sAll\sappears\sto\sbe\sworking\sin\spreliminary\stests. -D 2017-03-13T21:49:48.351 +C Add\sdbdump.exe\sto\sthe\sMSVC\smakefile. +D 2017-03-13T22:02:01.034 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 9020fa41eb91f657ae0cc44145d0a2f3af520860 +F Makefile.msc 5f1194a315c341c14870534652afd34bfa701219e5994fa0ee0bac91389fb740 F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 3605fa447e4623f5ff4a6adc97b1fde9a257b8f2 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -1564,7 +1564,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 84ea4fcc52d0af02648c52989c2e69f4961071e1620382555ec59a39161a7a7d -R de364a9f85fa4899d644a897efb72e80 +P 007b11e301d444361c8eff8734dc2fb968a64343c177ff30cec74a0cf76099e8 +R 6996c48c318cda176124bead4ce6093a U drh -Z 55e9f45d2725daddcac9a1569ce24da7 +Z a94f031011fffd33ab6cd5678ecde717 diff --git a/manifest.uuid b/manifest.uuid index db7f312b50..bf39e3c0d0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -007b11e301d444361c8eff8734dc2fb968a64343c177ff30cec74a0cf76099e8 \ No newline at end of file +59241a50ad1d6fe9f5804b73b3467dcd407d359ccbdcb9d72f2f6d94c90c1f40 \ No newline at end of file From 943d825b544efed6ff58bbfaf4b32d3c399c17d1 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 14 Mar 2017 15:27:56 +0000 Subject: [PATCH 05/60] Updates to the MSVC makefiles. FossilOrigin-Name: 1e4b9e7c9ee32b985c440bf3eb65bbdf28055566e66b6feba438143a3ad8dd07 --- Makefile.msc | 8 ++++---- autoconf/Makefile.msc | 1 + manifest | 17 ++++++++--------- manifest.uuid | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index ecaa837abb..1dfc6bc49d 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2178,9 +2178,9 @@ sqlite3_analyzer.exe: sqlite3_analyzer.c $(LIBRESOBJS) $(LTLINK) $(NO_WARN) -DBUILD_sqlite -I$(TCLINCDIR) sqlite3_analyzer.c \ /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS) -dbdump.exe: $(TOP)\ext\misc\dbdump.c sqlite3.c - $(LTLINK) $(NO_WARN) -DDBDUMP_STANDALONE $(TOP)\ext\misc\dbdump.c sqlite3.c \ - /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) +dbdump.exe: $(TOP)\ext\misc\dbdump.c $(SQLITE3C) $(SQLITE3H) + $(LTLINK) $(NO_WARN) -DDBDUMP_STANDALONE $(TOP)\ext\misc\dbdump.c $(SQLITE3C) \ + /link $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) testloadext.lo: $(TOP)\src\test_loadext.c $(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c @@ -2260,7 +2260,7 @@ clean: del /Q tclsqlite3.exe $(SQLITETCLH) $(SQLITETCLDECLSH) 2>NUL del /Q testloadext.dll 2>NUL del /Q testfixture.exe test.db 2>NUL - del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe 2>NUL + del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL del /Q changeset.exe 2>NUL del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL del /Q mptester.exe wordcount.exe rbu.exe srcck1.exe 2>NUL diff --git a/autoconf/Makefile.msc b/autoconf/Makefile.msc index 32ef1c5434..8c13778fc8 100644 --- a/autoconf/Makefile.msc +++ b/autoconf/Makefile.msc @@ -644,6 +644,7 @@ RCC = $(RCC) -DSQLITE_ENABLE_API_ARMOR=1 !IF $(DEBUG)>2 TCC = $(TCC) -DSQLITE_DEBUG=1 +TCC = $(TCC) -DSQLITE_ENABLE_WHERETRACE -DSQLITE_ENABLE_SELECTTRACE RCC = $(RCC) -DSQLITE_DEBUG=1 !ENDIF diff --git a/manifest b/manifest index a677fe2bf1..3813dabd09 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -C Add\sthe\sdbdump.c\sextension\sthat\simplements\sfunctionality\ssimilar\sto\sthe\n".dump"\scommand\sof\sthe\sCLI,\sthough\sin\sa\sseparate\slibrary. -D 2017-03-13T22:10:05.684 +C Updates\sto\sthe\sMSVC\smakefiles. +D 2017-03-14T15:27:56.153 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 -F Makefile.msc 5f1194a315c341c14870534652afd34bfa701219e5994fa0ee0bac91389fb740 +F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 F VERSION 3605fa447e4623f5ff4a6adc97b1fde9a257b8f2 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -11,7 +11,7 @@ F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903 F autoconf/Makefile.am 1a47d071e3d5435f8f7ebff7eb6703848bbd65d4 -F autoconf/Makefile.msc 3de603bcec5c07462801a20fd7dc1b871400af99 +F autoconf/Makefile.msc 92e3d7fd64dc5c23a23d33824ee4709aaea00a6331c4bb41a1aadcf6600a49f7 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt 4f04b0819303aabaa35fff5f7b257fb0c1ef95f1 F autoconf/configure.ac cacf2616abf6e4a569bde2ef365c143caeec40bc @@ -1564,8 +1564,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 68f6dc7af1013f296a11db14c007cc13cc3fe56832848bfed835ed8f74dcc676 59241a50ad1d6fe9f5804b73b3467dcd407d359ccbdcb9d72f2f6d94c90c1f40 -R 6996c48c318cda176124bead4ce6093a -T +closed 59241a50ad1d6fe9f5804b73b3467dcd407d359ccbdcb9d72f2f6d94c90c1f40 -U drh -Z 2f55f00bb27f982c54090f39d62e41f0 +P 2b9980a292d7f0d995b77d9b3fb217bb2206f6d452e036ac502fa06561af4c12 +R 8e14f9dee9f474ef44485ac6e8f73fc9 +U mistachkin +Z b0310bb4b1f32ecae5a830c4ceeca98b diff --git a/manifest.uuid b/manifest.uuid index 52fbd6fac9..6341cc740e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2b9980a292d7f0d995b77d9b3fb217bb2206f6d452e036ac502fa06561af4c12 \ No newline at end of file +1e4b9e7c9ee32b985c440bf3eb65bbdf28055566e66b6feba438143a3ad8dd07 \ No newline at end of file From 9c4527e57d7f6a0cd2b108ea6fd1fdc5f3e851c1 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Mar 2017 13:47:39 +0000 Subject: [PATCH 06/60] Improved header comment on the shathree.c extension. No changes to code. FossilOrigin-Name: 84f2e3d5f611b35de16684956d842df6c93d858e8187f17eb27452758a752c57 --- ext/misc/shathree.c | 4 ++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ext/misc/shathree.c b/ext/misc/shathree.c index 52bfdb0363..612e395ccb 100644 --- a/ext/misc/shathree.c +++ b/ext/misc/shathree.c @@ -21,6 +21,10 @@ ** ** The sha3_query(Y) function evalutes all queries in the SQL statements of Y ** and returns a hash of their results. +** +** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm +** is used. If SIZE is included it must be one of the integers 224, 256, +** 384, or 512, to determine SHA3 hash variant that is computed. */ #include "sqlite3ext.h" SQLITE_EXTENSION_INIT1 diff --git a/manifest b/manifest index 3813dabd09..ef98d84342 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sto\sthe\sMSVC\smakefiles. -D 2017-03-14T15:27:56.153 +C Improved\sheader\scomment\son\sthe\sshathree.c\sextension.\s\sNo\schanges\sto\scode. +D 2017-03-15T13:47:39.337 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -226,7 +226,7 @@ F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a F ext/misc/scrub.c 1c5bfb8b0cd18b602fcb55755e84abf0023ac2fb F ext/misc/series.c e11e534ada797d5b816d7e7a93c022306563ca35 F ext/misc/sha1.c 0b9e9b855354910d3ca467bf39099d570e73db56 -F ext/misc/shathree.c 38aa4c3c3d3c3fc34b8ea367bed299d8d8a224b2 +F ext/misc/shathree.c fa185d7aee0ad0aca5e091b4a2db7baff11796170e5793b5de99e511a13af448 F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c a4723b6aff748a417b5091b68a46443265c40f0d F ext/misc/totype.c 4a167594e791abeed95e0a8db028822b5e8fe512 @@ -1564,7 +1564,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 2b9980a292d7f0d995b77d9b3fb217bb2206f6d452e036ac502fa06561af4c12 -R 8e14f9dee9f474ef44485ac6e8f73fc9 -U mistachkin -Z b0310bb4b1f32ecae5a830c4ceeca98b +P 1e4b9e7c9ee32b985c440bf3eb65bbdf28055566e66b6feba438143a3ad8dd07 +R 54add779c916bea2d103fd3d0493702d +U drh +Z 250a0bd95a8a1e19df805d19a289213d diff --git a/manifest.uuid b/manifest.uuid index 6341cc740e..a77693e8fa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e4b9e7c9ee32b985c440bf3eb65bbdf28055566e66b6feba438143a3ad8dd07 \ No newline at end of file +84f2e3d5f611b35de16684956d842df6c93d858e8187f17eb27452758a752c57 \ No newline at end of file From 7553c82894a86bcd0cdc6a1e8a3e334f5a761394 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Mar 2017 14:04:03 +0000 Subject: [PATCH 07/60] Make "PRAGMA temp.synchronous=N" a no-op to ensure that the TEMP schema always has synchronous=OFF. This fixes an issue discovered by OSS-Fuzz. FossilOrigin-Name: bcf6bb08d8b07d3c4567bcd367f8d4011ce8baad28c25d4e8870bdf347dd48bd --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ef98d84342..9b3d61974d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sheader\scomment\son\sthe\sshathree.c\sextension.\s\sNo\schanges\sto\scode. -D 2017-03-15T13:47:39.337 +C Make\s"PRAGMA\stemp.synchronous=N"\sa\sno-op\sto\sensure\sthat\sthe\sTEMP\sschema\nalways\shas\ssynchronous=OFF.\s\sThis\sfixes\san\sissue\sdiscovered\sby\sOSS-Fuzz. +D 2017-03-15T14:04:03.559 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -392,7 +392,7 @@ F src/parse.y 48b03113704ee8bd78ee6996d81de7fbee22e105 F src/pcache.c 62835bed959e2914edd26afadfecce29ece0e870 F src/pcache.h 2cedcd8407eb23017d92790b112186886e179490 F src/pcache1.c e3967219b2a92b9edcb9324a4ba75009090d3953 -F src/pragma.c b7bf4f1dd9cdcdd3f72f0bdbce3502d69d0f48ba +F src/pragma.c bfaa7e5cbfc8eacaa0f3611d5ec2dca1339d6d301f1e9b429b49ca460d794a60 F src/pragma.h c9c763958fec92b04125571472c9500b351c5f7f F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a F src/printf.c 67427bbee66d891fc6f6f5aada857e9cdb368c1c @@ -1564,7 +1564,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 1e4b9e7c9ee32b985c440bf3eb65bbdf28055566e66b6feba438143a3ad8dd07 -R 54add779c916bea2d103fd3d0493702d +P 84f2e3d5f611b35de16684956d842df6c93d858e8187f17eb27452758a752c57 +R 6e100ddef7b1acc3bf828911d35ed937 U drh -Z 250a0bd95a8a1e19df805d19a289213d +Z 66f9c74ac924ecc8772889a54467a4f5 diff --git a/manifest.uuid b/manifest.uuid index a77693e8fa..b6378adfd0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -84f2e3d5f611b35de16684956d842df6c93d858e8187f17eb27452758a752c57 \ No newline at end of file +bcf6bb08d8b07d3c4567bcd367f8d4011ce8baad28c25d4e8870bdf347dd48bd \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 2901f4bdc5..488a1d194c 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1015,7 +1015,7 @@ void sqlite3Pragma( if( !db->autoCommit ){ sqlite3ErrorMsg(pParse, "Safety level may not be changed inside a transaction"); - }else{ + }else if( iDb!=1 ){ int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; if( iLevel==0 ) iLevel = 1; pDb->safety_level = iLevel; From a5d75ba9ead98c7721014019f5ff33a20dbbdfbb Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Mar 2017 14:20:34 +0000 Subject: [PATCH 08/60] Mention the ".selftest" command in the ".help" output of the CLI. FossilOrigin-Name: 37f766dbad1f99ff86dd1b771bf443036e928e5b4d8abe55bbe4acf3362c7be2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 9b3d61974d..3d90b0cede 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\s"PRAGMA\stemp.synchronous=N"\sa\sno-op\sto\sensure\sthat\sthe\sTEMP\sschema\nalways\shas\ssynchronous=OFF.\s\sThis\sfixes\san\sissue\sdiscovered\sby\sOSS-Fuzz. -D 2017-03-15T14:04:03.559 +C Mention\sthe\s".selftest"\scommand\sin\sthe\s".help"\soutput\sof\sthe\sCLI. +D 2017-03-15T14:20:34.151 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -400,7 +400,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa -F src/shell.c 353f3cebb938099577494326e2853010512e0625 +F src/shell.c 77054c021069ec0b65d3d620aab031f97c59b4e42ac7c31544ea68933b581104 F src/sqlite.h.in 4d0c08f8640c586564a7032b259c5f69bf397850 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1564,7 +1564,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 84f2e3d5f611b35de16684956d842df6c93d858e8187f17eb27452758a752c57 -R 6e100ddef7b1acc3bf828911d35ed937 +P bcf6bb08d8b07d3c4567bcd367f8d4011ce8baad28c25d4e8870bdf347dd48bd +R 3a48c86458783a20973121829bd123da U drh -Z 66f9c74ac924ecc8772889a54467a4f5 +Z 148bc384ce73e7778d1614d5fa3b82a8 diff --git a/manifest.uuid b/manifest.uuid index b6378adfd0..3ea504fab7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bcf6bb08d8b07d3c4567bcd367f8d4011ce8baad28c25d4e8870bdf347dd48bd \ No newline at end of file +37f766dbad1f99ff86dd1b771bf443036e928e5b4d8abe55bbe4acf3362c7be2 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 602415f8c9..e7652f8e67 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3169,6 +3169,7 @@ static char zHelp[] = ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n" ".schema ?PATTERN? Show the CREATE statements matching PATTERN\n" " Add --indent for pretty-printing\n" + ".selftest ?--init? Run tests defined in the SELFTEST table\n" ".separator COL ?ROW? Change the column separator and optionally the row\n" " separator for both the output mode and .import\n" #if defined(SQLITE_ENABLE_SESSION) From 6295ff1d3eecfc746632b54b543771b97c6e2bab Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Mar 2017 19:11:29 +0000 Subject: [PATCH 09/60] Add the "Obtaining The Code" subsection in the top-level README.md file. No changes to code. FossilOrigin-Name: b1b1aa8b69aa80c83aec3380565f0b4ec0b6a6e033537becee098872da362e9a --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++----------- manifest | 12 ++++----- manifest.uuid | 2 +- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index dbc020574e..7b860c211e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,48 @@ If you are reading this on a Git mirror someplace, you are doing it wrong. The [official repository](https://www.sqlite.org/src/) is better. Go there now. +## Obtaining The Code + +SQLite sources are managed using the +[Fossil](https://www.fossil-scm.org/), a distributed version control system +that was specifically designed to support SQLite development. +If you do not want to use Fossil, you can download tarballs or ZIP +archives as follows: + + * Lastest trunk check-in: + or + . + + * Latest release: + or + . + + * For other check-ins, substitute an appropriate branch name or + tag or hash prefix for "release" in the URLs of the previous + bullet. Or browse the [timeline](https://www.sqlite.org/src/timeline) + to locate the check-in desired, click on its information page link, + then click on the "Tarball" or "ZIP Archive" links on the information + page. + +If you do want to use Fossil to check out the source tree, +first install Fossil version 2.0 or later. +(Source tarballs and precompiled binaries available +[here](https://www.fossil-scm.org/fossil/uv/download.html).) +Then run commands like this: + + mkdir ~/sqlite + cd ~/sqlite + fossil clone https://www.sqlite.org/src sqlite.fossil + fossil open sqlite.fossil + +After setting up a repository using the steps above, you can always +update to the lastest version using: + + fossil update trunk ;# latest trunk check-in + fossil update release ;# latest official release + +Or type "fossil ui" to get a web-based user interface. + ## Compiling First create a directory in which to place @@ -18,13 +60,13 @@ script found at the root of the source tree. Then run "make". For example: - tar xzf sqlite.tar.gz ;# Unpack the source tree into "sqlite" - mkdir bld ;# Build will occur in a sibling directory - cd bld ;# Change to the build directory - ../sqlite/configure ;# Run the configure script - make ;# Run the makefile. - make sqlite3.c ;# Build the "amalgamation" source file - make test ;# Run some tests (requires Tcl) + tar xzf sqlite.tar.gz ;# Unpack the source tree into "sqlite" + mkdir bld ;# Build will occur in a sibling directory + cd bld ;# Change to the build directory + ../sqlite/configure ;# Run the configure script + make ;# Run the makefile. + make sqlite3.c ;# Build the "amalgamation" source file + make test ;# Run some tests (requires Tcl) See the makefile for additional targets. @@ -43,13 +85,13 @@ with the provided "Makefile.msc" to build one of the supported targets. For example: - mkdir bld - cd bld - nmake /f Makefile.msc TOP=..\sqlite - nmake /f Makefile.msc sqlite3.c TOP=..\sqlite - nmake /f Makefile.msc sqlite3.dll TOP=..\sqlite - nmake /f Makefile.msc sqlite3.exe TOP=..\sqlite - nmake /f Makefile.msc test TOP=..\sqlite + mkdir bld + cd bld + nmake /f Makefile.msc TOP=..\sqlite + nmake /f Makefile.msc sqlite3.c TOP=..\sqlite + nmake /f Makefile.msc sqlite3.dll TOP=..\sqlite + nmake /f Makefile.msc sqlite3.exe TOP=..\sqlite + nmake /f Makefile.msc test TOP=..\sqlite There are several build options that can be set via the NMAKE command line. For example, to build for WinRT, simply add "FOR_WINRT=1" argument diff --git a/manifest b/manifest index 3d90b0cede..7ebd38a5c1 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Mention\sthe\s".selftest"\scommand\sin\sthe\s".help"\soutput\sof\sthe\sCLI. -D 2017-03-15T14:20:34.151 +C Add\sthe\s"Obtaining\sThe\sCode"\ssubsection\sin\sthe\stop-level\sREADME.md\sfile.\nNo\schanges\sto\scode. +D 2017-03-15T19:11:29.617 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a -F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7 +F README.md 2b15fae33852f2f53996774c21fb41e1d94181c4401a0e43ac93e11f2cc901b9 F VERSION 3605fa447e4623f5ff4a6adc97b1fde9a257b8f2 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 @@ -1564,7 +1564,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 bcf6bb08d8b07d3c4567bcd367f8d4011ce8baad28c25d4e8870bdf347dd48bd -R 3a48c86458783a20973121829bd123da +P 37f766dbad1f99ff86dd1b771bf443036e928e5b4d8abe55bbe4acf3362c7be2 +R 2482a0aa4c5093969a8d8859e4856dc3 U drh -Z 148bc384ce73e7778d1614d5fa3b82a8 +Z 10bbbdac78940d7fca566277c18da714 diff --git a/manifest.uuid b/manifest.uuid index 3ea504fab7..72a98aae6c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -37f766dbad1f99ff86dd1b771bf443036e928e5b4d8abe55bbe4acf3362c7be2 \ No newline at end of file +b1b1aa8b69aa80c83aec3380565f0b4ec0b6a6e033537becee098872da362e9a \ No newline at end of file From 6f25936c9c12c93a95aad4277964a82b2f18b07a Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 15 Mar 2017 20:27:46 +0000 Subject: [PATCH 10/60] Updates to README files under the ext/ hierarchy. No changes to code. FossilOrigin-Name: 029bc5d224bcbdcca2307710539b133c39e2a27b971c28b294a1f517b80cb418 --- ext/README.md | 8 ++++++++ ext/README.txt | 2 -- ext/misc/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ manifest | 13 +++++++------ manifest.uuid | 2 +- 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 ext/README.md delete mode 100644 ext/README.txt create mode 100644 ext/misc/README.md diff --git a/ext/README.md b/ext/README.md new file mode 100644 index 0000000000..933a33d053 --- /dev/null +++ b/ext/README.md @@ -0,0 +1,8 @@ +## Loadable Extensions + +Various [loadable extensions](https://www.sqlite.org/loadext.html) for +SQLite are found in subfolders. + +Most subfolders are dedicated to a single loadable extension (for +example FTS5, or RTREE). But the misc/ subfolder contains a collection +of smaller single-file extensions. diff --git a/ext/README.txt b/ext/README.txt deleted file mode 100644 index 009495f59d..0000000000 --- a/ext/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -Version loadable extensions to SQLite are found in subfolders -of this folder. diff --git a/ext/misc/README.md b/ext/misc/README.md new file mode 100644 index 0000000000..970a09c2e9 --- /dev/null +++ b/ext/misc/README.md @@ -0,0 +1,40 @@ +## Miscellaneous Extensions + +This folder contains a collection of smaller loadable extensions. +See for instructions on how +to compile and use loadable extensions. +Each extension in this folder is implemented in a single file of C code. + +Each source file contains a description in its header comment. See the +header comments for details about each extension. Additional notes are +as follows: + + * **carray.c** — This module implements the + [carray](https://www.sqlite.org/carray.html) table-valued function. + It is a good example of how to go about implementing a custom + [table-valued function](https://www.sqlite.org/vtab.html#tabfunc2). + + * **dbdump.c** — This is not actually a loadable extension, but + rather a library that implements an approximate equivalent to the + ".dump" command of the + [command-line shell](https://www.sqlite.org/cli.html). + + * **memvfs.c** — This file implements a custom + [VFS](https://www.sqlite.org/vfs.html) that stores an entire database + file in a single block of RAM. It serves as a good example of how + to implement a simple custom VFS. + + * **rot13.c** — This file implements the very simple rot13() + substitution function. This file makes a good template for implementing + new custom SQL functions for SQLite. + + * **series.c** — This is an implementation of the + "generate_series" [virtual table](https://www.sqlite.org/vtab.html). + It can make a good template for new custom virtual table implementations. + + * **shathree.c** — An implementation of the sha3() and + sha3_query() SQL functions. The file is named "shathree.c" instead + of "sha3.c" because the default entry point names in SQLite are based + on the source filename with digits removed, so if we used the name + "sha3.c" then the entry point would conflict with the prior "sha1.c" + extension. diff --git a/manifest b/manifest index 7ebd38a5c1..83da720fa0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"Obtaining\sThe\sCode"\ssubsection\sin\sthe\stop-level\sREADME.md\sfile.\nNo\schanges\sto\scode. -D 2017-03-15T19:11:29.617 +C Updates\sto\sREADME\sfiles\sunder\sthe\sext/\shierarchy.\s\sNo\schanges\sto\scode. +D 2017-03-15T20:27:46.132 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -36,7 +36,7 @@ F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html b5a3c07d33ecb8e019ce8f7660fe2dbbad9d7977 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a -F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1 +F ext/README.md fd5f78013b0a2bc6f0067afb19e6ad040e89a10179b4f6f03eee58fac5f169bd w ext/README.txt F ext/async/README.txt e12275968f6fde133a80e04387d0e839b0c51f91 F ext/async/sqlite3async.c 0f3070cc3f5ede78f2b9361fb3b629ce200d7d74 F ext/async/sqlite3async.h f489b080af7e72aec0e1ee6f1d98ab6cf2e4dcef @@ -206,6 +206,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43 F ext/icu/icu.c 84900472a088a3a172c6c079f58a1d3a1952c332 F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37 +F ext/misc/README.md 8e008c8d2b02e09096b31dfba033253ac27c6c06a18aa5826e299fa7601d90b2 F ext/misc/amatch.c 211108e201105e4bb0c076527b8cfd34330fc234 F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 @@ -1564,7 +1565,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 37f766dbad1f99ff86dd1b771bf443036e928e5b4d8abe55bbe4acf3362c7be2 -R 2482a0aa4c5093969a8d8859e4856dc3 +P b1b1aa8b69aa80c83aec3380565f0b4ec0b6a6e033537becee098872da362e9a +R ed52dc66e6f47f5c1fac043513c8c66c U drh -Z 10bbbdac78940d7fca566277c18da714 +Z 7b77c481896e5fef2abe165dd1f4d320 diff --git a/manifest.uuid b/manifest.uuid index 72a98aae6c..b973ec5b0b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b1b1aa8b69aa80c83aec3380565f0b4ec0b6a6e033537becee098872da362e9a \ No newline at end of file +029bc5d224bcbdcca2307710539b133c39e2a27b971c28b294a1f517b80cb418 \ No newline at end of file From 116b56a2ccb5671bd6ff668ad3aec104d8b4b9a9 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 16 Mar 2017 12:11:07 +0000 Subject: [PATCH 11/60] Fix a crash that could follow an OOM condition in the instr() SQL function. FossilOrigin-Name: 6e59e903e4e956617bddef0b94e5cae02d724ac8145940b57ab5b0f628759736 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/func.c | 6 ++++-- test/mallocM.test | 18 +++++++++++++++++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 83da720fa0..e9aad067d4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sto\sREADME\sfiles\sunder\sthe\sext/\shierarchy.\s\sNo\schanges\sto\scode. -D 2017-03-15T20:27:46.132 +C Fix\sa\scrash\sthat\scould\sfollow\san\sOOM\scondition\sin\sthe\sinstr()\sSQL\sfunction. +D 2017-03-16T12:11:07.597 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -36,7 +36,7 @@ F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/lemon.html b5a3c07d33ecb8e019ce8f7660fe2dbbad9d7977 F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710 F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a -F ext/README.md fd5f78013b0a2bc6f0067afb19e6ad040e89a10179b4f6f03eee58fac5f169bd w ext/README.txt +F ext/README.md fd5f78013b0a2bc6f0067afb19e6ad040e89a10179b4f6f03eee58fac5f169bd F ext/async/README.txt e12275968f6fde133a80e04387d0e839b0c51f91 F ext/async/sqlite3async.c 0f3070cc3f5ede78f2b9361fb3b629ce200d7d74 F ext/async/sqlite3async.h f489b080af7e72aec0e1ee6f1d98ab6cf2e4dcef @@ -356,7 +356,7 @@ F src/delete.c 0d9d5549d42e79ce4d82ff1db1e6c81e36d2f67c F src/expr.c f12a581f342a6fd85d14c31e4fb84f16b3dd107f54d7728dddb62cebc79d7ce1 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 2e9aabe1aee76273aff8a84ee92c464e095400ae -F src/func.c c67273e1ec08abbdcc14c189892a3ff6eeece86b +F src/func.c 72ed1518f59951daca3b3480331006f074041b4753ab652b46bbdaedb77f6d6c F src/global.c 4a34512d82fc5aa13c802db06bcfff5e1d3de955 F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 @@ -955,7 +955,7 @@ F test/mallocI.test 6c23a71df077fa5d387be90e7e669c5b368ca38a F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e F test/mallocK.test 27cb5566a6e5f2d76f9d4aa2eca45524401fd61e F test/mallocL.test fb311ff80afddf3b1a75e52289081f4754d901dc -F test/mallocM.test 491001d1e273233048d265ec6d38fdd23745b0284f0c93bc98c94b64451c9c28 +F test/mallocM.test 78bbe9d3da84a5c679123cdb40d7b2010b18fc46e13897e4f253c6ba6fbff134 F test/malloc_common.tcl aac62499b76be719fac31e7a3e54a7fd53272e7f F test/manydb.test 28385ae2087967aa05c38624cec7d96ec74feb3e F test/mem5.test c6460fba403c5703141348cd90de1c294188c68f @@ -1565,7 +1565,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 b1b1aa8b69aa80c83aec3380565f0b4ec0b6a6e033537becee098872da362e9a -R ed52dc66e6f47f5c1fac043513c8c66c -U drh -Z 7b77c481896e5fef2abe165dd1f4d320 +P 029bc5d224bcbdcca2307710539b133c39e2a27b971c28b294a1f517b80cb418 +R e125f692ae2203427c312740eb052007 +U dan +Z 43eef8b6f1a791e34b2b986222f188cc diff --git a/manifest.uuid b/manifest.uuid index b973ec5b0b..808a7701e3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -029bc5d224bcbdcca2307710539b133c39e2a27b971c28b294a1f517b80cb418 \ No newline at end of file +6e59e903e4e956617bddef0b94e5cae02d724ac8145940b57ab5b0f628759736 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 885725bc6b..181032a5e3 100644 --- a/src/func.c +++ b/src/func.c @@ -204,9 +204,11 @@ static void instrFunc( if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){ zHaystack = sqlite3_value_blob(argv[0]); zNeedle = sqlite3_value_blob(argv[1]); - assert( zNeedle!=0 ); - assert( zHaystack!=0 || nHaystack==0 ); isText = 0; + /* The following condition may be true if the arguments passed to this + ** function are values returned by zeroblob() or similar and an OOM + ** occurs while expanding the blob value. */ + if( zNeedle==0 || (nHaystack && zHaystack==0) ) return; }else{ zHaystack = sqlite3_value_text(argv[0]); zNeedle = sqlite3_value_text(argv[1]); diff --git a/test/mallocM.test b/test/mallocM.test index 85a38acf32..4da3a9e112 100644 --- a/test/mallocM.test +++ b/test/mallocM.test @@ -21,7 +21,7 @@ sqlite3_db_config_lookaside db 0 0 0 do_execsql_test 1.0 { CREATE TABLE t1(x); } -do_faultsim_test 1 -faults oom-t* -body { +do_faultsim_test 1 -faults oom* -body { execsql { SELECT 'abc' FROM ( SELECT 'xyz' FROM t1 WHERE (SELECT 1) ) } @@ -29,4 +29,20 @@ do_faultsim_test 1 -faults oom-t* -body { faultsim_test_result {0 {}} } +do_execsql_test 2.0.1 { SELECT instr(x'', x'') } {1} +do_execsql_test 2.0.2 { SELECT instr(x'12345678', x'') } {1} +do_execsql_test 2.0.3 { SELECT instr(x'', x'1234') } {0} + +do_faultsim_test 2.1 -faults oom* -body { + execsql { SELECT instr (x'00', zeroblob(1)) } +} -test { + faultsim_test_result {0 1} +} + +do_faultsim_test 2.2 -faults oom* -body { + execsql { SELECT instr (zeroblob(1), x'00') } +} -test { + faultsim_test_result {0 1} +} + finish_test From 970ea372c41bf3fda4891740d74130a490809288 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Mar 2017 13:14:03 +0000 Subject: [PATCH 12/60] Fix a problem in the "showdb" utility that prevents it from correctly decoding cells with no content beyond the record header. FossilOrigin-Name: eb7680a1c047b2a33d6a0c9733fafaee11272377c627af10bbd541b6b7ed952b --- manifest | 14 +++++++------- manifest.uuid | 2 +- tool/showdb.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e9aad067d4..e0d90caf8e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scrash\sthat\scould\sfollow\san\sOOM\scondition\sin\sthe\sinstr()\sSQL\sfunction. -D 2017-03-16T12:11:07.597 +C Fix\sa\sproblem\sin\sthe\s"showdb"\sutility\sthat\sprevents\sit\sfrom\scorrectly\ndecoding\scells\swith\sno\scontent\sbeyond\sthe\srecord\sheader. +D 2017-03-16T13:14:03.665 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1518,7 +1518,7 @@ F tool/replace.tcl 60f91e8dd06ab81f74d213ecbd9c9945f32ac048 F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 F tool/run-speed-test.sh f95d19fd669b68c4c38b6b475242841d47c66076 -F tool/showdb.c c695a5d5c8110640e0d9fadf5e254da90c79c36e +F tool/showdb.c e6bc9dba233bf1b57ca0a525a2bba762db4e223de84990739db3f09c46151b1e F tool/showjournal.c 5bad7ae8784a43d2b270d953060423b8bd480818 F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68 F tool/showstat4.c b14159aa062f661b394ba37b6b7b94bfb8012ab9 @@ -1565,7 +1565,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 029bc5d224bcbdcca2307710539b133c39e2a27b971c28b294a1f517b80cb418 -R e125f692ae2203427c312740eb052007 -U dan -Z 43eef8b6f1a791e34b2b986222f188cc +P 6e59e903e4e956617bddef0b94e5cae02d724ac8145940b57ab5b0f628759736 +R e2b1419a7c2797d673769ba867cc93d0 +U drh +Z 979d31964af3fe7c6823fdbe1eb4300f diff --git a/manifest.uuid b/manifest.uuid index 808a7701e3..8782dfa202 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6e59e903e4e956617bddef0b94e5cae02d724ac8145940b57ab5b0f628759736 \ No newline at end of file +eb7680a1c047b2a33d6a0c9733fafaee11272377c627af10bbd541b6b7ed952b \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index d51a2fd83d..ba7a362258 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -535,7 +535,7 @@ static void decodeCell( j = i; nCol = 0; k = nHdr; - while( x+j Date: Thu, 16 Mar 2017 13:30:58 +0000 Subject: [PATCH 13/60] Fix an uninitialized variable reference in the text generator for "PRAGMA vdbe_trace=ON" output. Problem discovered by OSS-Fuzz. FossilOrigin-Name: e3d487162d1596ce125644f754ed9531ef4412f31f6837c3e31b7542b90602fe --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 8 ++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index e0d90caf8e..94d43a58ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sthe\s"showdb"\sutility\sthat\sprevents\sit\sfrom\scorrectly\ndecoding\scells\swith\sno\scontent\sbeyond\sthe\srecord\sheader. -D 2017-03-16T13:14:03.665 +C Fix\san\suninitialized\svariable\sreference\sin\sthe\stext\sgenerator\s\nfor\s"PRAGMA\svdbe_trace=ON"\soutput.\nProblem\sdiscovered\sby\sOSS-Fuzz. +D 2017-03-16T13:30:58.522 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -467,7 +467,7 @@ F src/update.c 456d4a4656f8a03c2abc88a51b19172197400e58 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c ca8440ede81e155d15cff7c101654f60b55a9ae6 F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 -F src/vdbe.c f520378e510fd36bbf289921798dbc8f2b3dc30d +F src/vdbe.c 0e6e5e01aaa57f6d1784b7d6b6a352153e9d2c2ff395c67ca59aef54b8268cf6 F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 @@ -1565,7 +1565,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 6e59e903e4e956617bddef0b94e5cae02d724ac8145940b57ab5b0f628759736 -R e2b1419a7c2797d673769ba867cc93d0 +P eb7680a1c047b2a33d6a0c9733fafaee11272377c627af10bbd541b6b7ed952b +R 698ee80038f5639a9fb93e688b92867d U drh -Z 979d31964af3fe7c6823fdbe1eb4300f +Z 1c91cacf813bcc1311ca42c9e29c59cd diff --git a/manifest.uuid b/manifest.uuid index 8782dfa202..5411cb37d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eb7680a1c047b2a33d6a0c9733fafaee11272377c627af10bbd541b6b7ed952b \ No newline at end of file +e3d487162d1596ce125644f754ed9531ef4412f31f6837c3e31b7542b90602fe \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 5901ba0eb5..20bf09e3a4 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -403,9 +403,7 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){ }else{ c = 's'; } - - sqlite3_snprintf(100, zCsr, "%c", c); - zCsr += sqlite3Strlen30(zCsr); + *(zCsr++) = c; sqlite3_snprintf(100, zCsr, "%d[", pMem->n); zCsr += sqlite3Strlen30(zCsr); for(i=0; i<16 && in; i++){ @@ -417,9 +415,7 @@ void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){ if( z<32 || z>126 ) *zCsr++ = '.'; else *zCsr++ = z; } - - sqlite3_snprintf(100, zCsr, "]%s", encnames[pMem->enc]); - zCsr += sqlite3Strlen30(zCsr); + *(zCsr++) = ']'; if( f & MEM_Zero ){ sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero); zCsr += sqlite3Strlen30(zCsr); From b30574bcae87dd4efe6de37d47a215e112824fe2 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 16 Mar 2017 14:28:52 +0000 Subject: [PATCH 14/60] Simplified OOM detection in the instr() SQL function. FossilOrigin-Name: 6d85eb5736781b43aa674d9544c7523b849b4e634f371702f8764b33e22e1e9f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/func.c | 6 +----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 94d43a58ec..7d0466ed61 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\suninitialized\svariable\sreference\sin\sthe\stext\sgenerator\s\nfor\s"PRAGMA\svdbe_trace=ON"\soutput.\nProblem\sdiscovered\sby\sOSS-Fuzz. -D 2017-03-16T13:30:58.522 +C Simplified\sOOM\sdetection\sin\sthe\sinstr()\sSQL\sfunction. +D 2017-03-16T14:28:52.423 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -356,7 +356,7 @@ F src/delete.c 0d9d5549d42e79ce4d82ff1db1e6c81e36d2f67c F src/expr.c f12a581f342a6fd85d14c31e4fb84f16b3dd107f54d7728dddb62cebc79d7ce1 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 2e9aabe1aee76273aff8a84ee92c464e095400ae -F src/func.c 72ed1518f59951daca3b3480331006f074041b4753ab652b46bbdaedb77f6d6c +F src/func.c 9d52522cc8ae7f5cdadfe14594262f1618bc1f86083c4cd6da861b4cf5af6174 F src/global.c 4a34512d82fc5aa13c802db06bcfff5e1d3de955 F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 @@ -1565,7 +1565,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 eb7680a1c047b2a33d6a0c9733fafaee11272377c627af10bbd541b6b7ed952b -R 698ee80038f5639a9fb93e688b92867d +P e3d487162d1596ce125644f754ed9531ef4412f31f6837c3e31b7542b90602fe +R 6130240157d02268edef1462c36002d9 U drh -Z 1c91cacf813bcc1311ca42c9e29c59cd +Z 5ff31e1a870d72447c943f18c5a0c832 diff --git a/manifest.uuid b/manifest.uuid index 5411cb37d9..eee2f53d07 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e3d487162d1596ce125644f754ed9531ef4412f31f6837c3e31b7542b90602fe \ No newline at end of file +6d85eb5736781b43aa674d9544c7523b849b4e634f371702f8764b33e22e1e9f \ No newline at end of file diff --git a/src/func.c b/src/func.c index 181032a5e3..3d5a059a9f 100644 --- a/src/func.c +++ b/src/func.c @@ -205,16 +205,12 @@ static void instrFunc( zHaystack = sqlite3_value_blob(argv[0]); zNeedle = sqlite3_value_blob(argv[1]); isText = 0; - /* The following condition may be true if the arguments passed to this - ** function are values returned by zeroblob() or similar and an OOM - ** occurs while expanding the blob value. */ - if( zNeedle==0 || (nHaystack && zHaystack==0) ) return; }else{ zHaystack = sqlite3_value_text(argv[0]); zNeedle = sqlite3_value_text(argv[1]); isText = 1; - if( zHaystack==0 || zNeedle==0 ) return; } + if( zNeedle==0 || (nHaystack && zHaystack==0) ) return; while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ N++; do{ From f5da7dbb0773facb0a6a12e25f4139a7c5087c74 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 16 Mar 2017 18:14:39 +0000 Subject: [PATCH 15/60] If the user has not set it explicitly, set the "PRAGMA synchronous" setting to SQLITE_DEFAULT_SYNCHRONOUS when a database connection changes from wal to rollback journal mode. FossilOrigin-Name: 78030c0f52aa39fb2ab32c75c56e6bcefe6382b8df28b1909e3c911e42dbeca3 --- manifest | 19 +++--- manifest.uuid | 2 +- src/btree.c | 42 ++++++++----- src/ctime.c | 6 ++ src/test_config.c | 2 + test/sync2.test | 153 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 200 insertions(+), 24 deletions(-) create mode 100644 test/sync2.test diff --git a/manifest b/manifest index 7d0466ed61..4d61ee44cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplified\sOOM\sdetection\sin\sthe\sinstr()\sSQL\sfunction. -D 2017-03-16T14:28:52.423 +C If\sthe\suser\shas\snot\sset\sit\sexplicitly,\sset\sthe\s"PRAGMA\ssynchronous"\ssetting\sto\nSQLITE_DEFAULT_SYNCHRONOUS\swhen\sa\sdatabase\sconnection\schanges\sfrom\swal\sto\nrollback\sjournal\smode. +D 2017-03-16T18:14:39.798 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -343,13 +343,13 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c e2bae0a03f73d119910fb35c9550987564065137 +F src/btree.c ace24955d01800acec28c79b038e1c291370f48a8955e8347cbd5339e39935de F src/btree.h bf64dfeeddeebdb775a5eba0098bbc00d073290d F src/btreeInt.h cd55d39d9916270837a88c12e701047cba0729b0 F src/build.c 43f903c9082040ced2b421543cb0300c2973647d F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e -F src/ctime.c a9984df73898c042a5cfc8f9d8e7723d02bc35c9 +F src/ctime.c 47d91a25ad8f199a71a5b1b7b169d6dd0d6e98c5719eca801568798743d1161c F src/date.c ee676e7694dfadbdd2fde1a258a71be8360ba5ae F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d F src/delete.c 0d9d5549d42e79ce4d82ff1db1e6c81e36d2f67c @@ -425,7 +425,7 @@ F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 F src/test_bestindex.c d23f80d334c59662af69191854c76b8d3d0c8c96 F src/test_blob.c f65ac717da2618691cf9dad094e6da0219dcd208 F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 -F src/test_config.c 83179ea845479b5be9a651d014649e3f2722a1fe +F src/test_config.c edcba290248dc18736dd814c9b95863c6762e0b35753048d8cbe5bf65f7abfbb F src/test_delete.c af7eab5702f853fb1c62a5f7665e2234cf1ae17b F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e F src/test_devsym.c 4e58dec2602d8e139ca08659f62a62450587cb58 @@ -1165,6 +1165,7 @@ F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test ec94f0556b6488d97f71c79f9061ae08d9ab8f12 F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529 +F test/sync2.test 5ecf56be4c187a191253a1ec0786fe2df975dbf3dc0f0140cdf5d3690c90651c F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 F test/tabfunc01.test 699251cb99651415218a891384510a685c7ab012 @@ -1565,7 +1566,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 e3d487162d1596ce125644f754ed9531ef4412f31f6837c3e31b7542b90602fe -R 6130240157d02268edef1462c36002d9 -U drh -Z 5ff31e1a870d72447c943f18c5a0c832 +P 6d85eb5736781b43aa674d9544c7523b849b4e634f371702f8764b33e22e1e9f +R 549202c1b901efe7d78e47bd0d1adc7f +U dan +Z 959d77178fc349b2ba7589eca45f1aa2 diff --git a/manifest.uuid b/manifest.uuid index eee2f53d07..1973398254 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6d85eb5736781b43aa674d9544c7523b849b4e634f371702f8764b33e22e1e9f \ No newline at end of file +78030c0f52aa39fb2ab32c75c56e6bcefe6382b8df28b1909e3c911e42dbeca3 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index b99cab89ec..47bb460b0c 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2861,6 +2861,31 @@ int sqlite3BtreeGetAutoVacuum(Btree *p){ #endif } +/* +** If the user has not set the safety-level for this database connection +** using "PRAGMA synchronous", and if the safety-level is not already +** set to the value passed to this function as the second parameter, +** set it so. +*/ +#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS +static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){ + sqlite3 *db; + Db *pDb; + if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){ + while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; } + if( pDb->bSyncSet==0 + && pDb->safety_level!=safety_level + && pDb!=&db->aDb[1] + ){ + pDb->safety_level = safety_level; + sqlite3PagerSetFlags(pBt->pPager, + pDb->safety_level | (db->flags & PAGER_FLAGS_MASK)); + } + } +} +#else +# define setDefaultSyncFlag(pBt) +#endif /* ** Get a reference to pPage1 of the database file. This will @@ -2934,26 +2959,15 @@ static int lockBtree(BtShared *pBt){ if( rc!=SQLITE_OK ){ goto page1_init_failed; }else{ -#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS - sqlite3 *db; - Db *pDb; - if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){ - while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; } - if( pDb->bSyncSet==0 - && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS+1 - ){ - pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS+1; - sqlite3PagerSetFlags(pBt->pPager, - pDb->safety_level | (db->flags & PAGER_FLAGS_MASK)); - } - } -#endif + setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1); if( isOpen==0 ){ releasePage(pPage1); return SQLITE_OK; } } rc = SQLITE_NOTADB; + }else{ + setDefaultSyncFlag(pBt, SQLITE_DEFAULT_SYNCHRONOUS+1); } #endif diff --git a/src/ctime.c b/src/ctime.c index 3db3192095..20e94edba5 100644 --- a/src/ctime.c +++ b/src/ctime.c @@ -66,6 +66,12 @@ static const char * const azCompileOpt[] = { #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc) "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), #endif +#if SQLITE_DEFAULT_SYNCHRONOUS + "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS), +#endif +#if SQLITE_DEFAULT_WAL_SYNCHRONOUS + "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS), +#endif #if SQLITE_DIRECT_OVERFLOW_READ "DIRECT_OVERFLOW_READ", #endif diff --git a/src/test_config.c b/src/test_config.c index f409b1ca6f..a25b0b3525 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -740,6 +740,8 @@ Tcl_SetVar2(interp, "sqlite_options", "mergesort", "1", TCL_GLOBAL_ONLY); LINKVAR( DEFAULT_CACHE_SIZE ); LINKVAR( DEFAULT_PAGE_SIZE ); LINKVAR( DEFAULT_FILE_FORMAT ); + LINKVAR( DEFAULT_SYNCHRONOUS ); + LINKVAR( DEFAULT_WAL_SYNCHRONOUS ); LINKVAR( MAX_ATTACHED ); LINKVAR( MAX_DEFAULT_PAGE_SIZE ); LINKVAR( MAX_WORKER_THREADS ); diff --git a/test/sync2.test b/test/sync2.test new file mode 100644 index 0000000000..5f9c9aba93 --- /dev/null +++ b/test/sync2.test @@ -0,0 +1,153 @@ +# 2017 March 16 +# +# 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. +# +# Specificly, it tests that "PRAGMA synchronous" appears to work. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix sync2 + +# +# These tests are only applicable when pager pragma are +# enabled. Also, since every test uses an ATTACHed database, they +# are only run when ATTACH is enabled. +# +ifcapable !pager_pragmas||!attach { + finish_test + return +} + +proc execsql_sync {sql} { + set s $::sqlite_sync_count + set res [execsql $sql] + concat [expr $::sqlite_sync_count-$s] $res +} + +proc do_execsql_sync_test {tn sql res} { + uplevel [list do_test $tn [list execsql_sync $sql] [list {*}$res]] +} + +#----------------------------------------------------------------------- +# Tests for journal mode. +# +sqlite3 db test.db +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); +} + +do_execsql_sync_test 1.1 { INSERT INTO t1 VALUES(3, 4) } 4 + +# synchronous=normal. So, 1 sync on the directory, 1 on the journal, 1 +# on the db file. 3 in total. +do_execsql_test 1.2.1 { PRAGMA main.synchronous = NORMAL } +do_execsql_test 1.2.2 { PRAGMA main.synchronous } 1 +do_execsql_sync_test 1.2.3 { INSERT INTO t1 VALUES(5, 6) } 3 + +# synchronous=off. No syncs. +do_execsql_test 1.3.1 { PRAGMA main.synchronous = OFF } +do_execsql_test 1.3.2 { PRAGMA main.synchronous } 0 +do_execsql_sync_test 1.3.3 { INSERT INTO t1 VALUES(7, 8) } 0 + +# synchronous=full, journal_mode=delete. So, 1 sync on the directory, +# 2 on the journal, 1 on the db file. 4 in total. +do_execsql_test 1.4.1 { PRAGMA main.synchronous = FULL } +do_execsql_test 1.4.2 { PRAGMA main.synchronous } 2 +do_execsql_sync_test 1.4.3 { INSERT INTO t1 VALUES(9, 10) } 4 + +#----------------------------------------------------------------------- +# Tests for wal mode. +# +do_execsql_test 1.5 { PRAGMA journal_mode = wal } {wal} + +# sync=full, journal_mode=wal. One sync on the directory, two on the +# wal file. +do_execsql_sync_test 1.6 { INSERT INTO t1 VALUES(11, 12) } 3 + +# One sync on the wal file. +do_execsql_sync_test 1.7 { INSERT INTO t1 VALUES(13, 14) } 1 + +# No syncs. +do_execsql_test 1.8.1 { PRAGMA main.synchronous = NORMAL } +do_execsql_test 1.8.2 { PRAGMA main.synchronous } 1 +do_execsql_sync_test 1.8.3 { INSERT INTO t1 VALUES(15, 16) } 0 + +# One sync on wal file, one on the db file. +do_execsql_sync_test 1.9 { PRAGMA wal_checkpoint } {2 0 3 3} + +# No syncs. +do_execsql_test 1.10.1 { PRAGMA main.synchronous = OFF } +do_execsql_test 1.10.2 { PRAGMA main.synchronous } 0 +do_execsql_sync_test 1.10.3 { INSERT INTO t1 VALUES(17, 18) } 0 + +#----------------------------------------------------------------------- +# Tests for the compile time settings SQLITE_DEFAULT_SYNCHRONOUS and +# SQLITE_DEFAULT_WAL_SYNCHRONOUS. These tests only run if the former +# is set to "2" and the latter to "1". This is not the default, but +# it is currently the recommended configuration. +# +# https://sqlite.org/compile.html#recommended_compile_time_options +# +if {$SQLITE_DEFAULT_SYNCHRONOUS==2 && $SQLITE_DEFAULT_WAL_SYNCHRONOUS==1} { + + db close + sqlite3 db test.db + + # Wal mode, sync=normal. The first transaction does one sync on directory, + # one on the wal file. The second does no syncs. + do_execsql_sync_test 1.11.1 { INSERT INTO t1 VALUES(19, 20) } 2 + do_execsql_sync_test 1.11.2 { INSERT INTO t1 VALUES(21, 22) } 0 + do_execsql_test 1.11.3 { PRAGMA main.synchronous } 1 + + # One sync on wal file, one on the db file. + do_execsql_sync_test 1.12 { PRAGMA wal_checkpoint } {2 0 2 2} + + # First transaction syncs the wal file once, the second not at all. + # one on the wal file. The second does no syncs. + do_execsql_sync_test 1.13.1 { INSERT INTO t1 VALUES(22, 23) } 1 + do_execsql_sync_test 1.13.2 { INSERT INTO t1 VALUES(24, 25) } 0 + + do_execsql_test 1.14 { PRAGMA journal_mode = delete } {delete} + + # Delete mode, sync=full. The first transaction does one sync on + # directory, two on the journal file, one on the db. The second does + # the same. + do_execsql_sync_test 1.15.1 { INSERT INTO t1 VALUES(26, 27) } 4 + do_execsql_sync_test 1.15.2 { INSERT INTO t1 VALUES(28, 29) } 4 + do_execsql_test 1.15.3 { PRAGMA main.synchronous } 2 + + # Switch back to wal mode. + do_execsql_test 1.16 { PRAGMA journal_mode = wal } {wal} + + do_execsql_sync_test 1.17.1 { INSERT INTO t1 VALUES(30, 31) } 2 + do_execsql_sync_test 1.17.2 { INSERT INTO t1 VALUES(32, 33) } 0 + do_execsql_test 1.17.3 { PRAGMA main.synchronous } 1 + + # Now set synchronous=off, then switch back to delete mode. Check + # that the db handle is still using synchronous=off. + do_execsql_test 1.18.3 { PRAGMA main.synchronous=off } + do_execsql_test 1.18 { PRAGMA journal_mode = delete } {delete} + + do_execsql_sync_test 1.19.1 { INSERT INTO t1 VALUES(34, 35) } 0 + do_execsql_sync_test 1.19.2 { INSERT INTO t1 VALUES(36, 37) } 0 + do_execsql_test 1.19.3 { PRAGMA main.synchronous } 0 + + # Close and reopen the db. Back to synchronous=normal. + db close + sqlite3 db test.db + do_execsql_sync_test 1.20.1 { INSERT INTO t1 VALUES(38, 39) } 4 + do_execsql_sync_test 1.20.2 { INSERT INTO t1 VALUES(40, 41) } 4 + do_execsql_test 1.20.3 { PRAGMA main.synchronous } 2 +} + +finish_test From fc8f4b658ccf5ee626b21115f336e6068623827d Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 16 Mar 2017 18:54:42 +0000 Subject: [PATCH 16/60] Fix a typo causing the build to fail if SQLITE_DEFAULT_SYNCHRONOUS==SQLITE_DEFAULT_WAL_SYNCHRONOUS. FossilOrigin-Name: df39adeaa4d73a3d4ec831843b8ec7fd449f8b2137bdc7d7c320958d00e98db6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4d61ee44cb..27d666d7ff 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\suser\shas\snot\sset\sit\sexplicitly,\sset\sthe\s"PRAGMA\ssynchronous"\ssetting\sto\nSQLITE_DEFAULT_SYNCHRONOUS\swhen\sa\sdatabase\sconnection\schanges\sfrom\swal\sto\nrollback\sjournal\smode. -D 2017-03-16T18:14:39.798 +C Fix\sa\stypo\scausing\sthe\sbuild\sto\sfail\sif\sSQLITE_DEFAULT_SYNCHRONOUS==SQLITE_DEFAULT_WAL_SYNCHRONOUS. +D 2017-03-16T18:54:42.504 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -343,7 +343,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c ace24955d01800acec28c79b038e1c291370f48a8955e8347cbd5339e39935de +F src/btree.c ae0e0397e6ad58465bbf932239ee7539ca22f257c97b16c9d0960a1f5de743a3 F src/btree.h bf64dfeeddeebdb775a5eba0098bbc00d073290d F src/btreeInt.h cd55d39d9916270837a88c12e701047cba0729b0 F src/build.c 43f903c9082040ced2b421543cb0300c2973647d @@ -1566,7 +1566,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 6d85eb5736781b43aa674d9544c7523b849b4e634f371702f8764b33e22e1e9f -R 549202c1b901efe7d78e47bd0d1adc7f +P 78030c0f52aa39fb2ab32c75c56e6bcefe6382b8df28b1909e3c911e42dbeca3 +R ce97b08e421fd719736eea9dd091c75c U dan -Z 959d77178fc349b2ba7589eca45f1aa2 +Z dc5f7c52928823522e8c3e89a1ed9d18 diff --git a/manifest.uuid b/manifest.uuid index 1973398254..57ec040514 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -78030c0f52aa39fb2ab32c75c56e6bcefe6382b8df28b1909e3c911e42dbeca3 \ No newline at end of file +df39adeaa4d73a3d4ec831843b8ec7fd449f8b2137bdc7d7c320958d00e98db6 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 47bb460b0c..52c0c47dd5 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2884,7 +2884,7 @@ static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){ } } #else -# define setDefaultSyncFlag(pBt) +# define setDefaultSyncFlag(pBt,safety_level) #endif /* From a3b2da9889ceb5ca041ca0eb2bc8d35190aae94c Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Mar 2017 03:21:14 +0000 Subject: [PATCH 17/60] Fix a problem in the enhanced PRAGMA integrity_check where it verifies CHECK constraints: Do not be confused by the reuse of the Table.pCheck field by VIEWs with named columns. Problem discovered by OSS-Fuzz. FossilOrigin-Name: 019dd3d5ba4a596c4ec3b5f0de8402c72196af0faca9138edbc0f1f4957cae60 --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/pragma.c | 1 + test/check.test | 11 ++++++++++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index dde0392581..99c6df185c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\suser\shas\snot\sset\sit\sexplicitly,\sset\sthe\s"PRAGMA\ssynchronous"\ssetting\sto\nSQLITE_DEFAULT_SYNCHRONOUS\swhen\sa\sdatabase\sconnection\schanges\sfrom\swal\sto\nrollback\sjournal\smode. -D 2017-03-16T18:55:21.135 +C Fix\sa\sproblem\sin\sthe\senhanced\sPRAGMA\sintegrity_check\swhere\sit\sverifies\nCHECK\sconstraints:\sDo\snot\sbe\sconfused\sby\sthe\sreuse\sof\sthe\sTable.pCheck\sfield\nby\sVIEWs\swith\snamed\scolumns.\s\sProblem\sdiscovered\sby\sOSS-Fuzz. +D 2017-03-17T03:21:14.865 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -393,7 +393,7 @@ F src/parse.y 48b03113704ee8bd78ee6996d81de7fbee22e105 F src/pcache.c 62835bed959e2914edd26afadfecce29ece0e870 F src/pcache.h 2cedcd8407eb23017d92790b112186886e179490 F src/pcache1.c e3967219b2a92b9edcb9324a4ba75009090d3953 -F src/pragma.c bfaa7e5cbfc8eacaa0f3611d5ec2dca1339d6d301f1e9b429b49ca460d794a60 +F src/pragma.c 2b244434e76c7075edbcfd9e4d634899af0944ff01183b126d4671f7407c2368 F src/pragma.h c9c763958fec92b04125571472c9500b351c5f7f F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a F src/printf.c 67427bbee66d891fc6f6f5aada857e9cdb368c1c @@ -582,7 +582,7 @@ F test/capi3d.test 485048dc5cd07bc68011e4917ad035ad6047ab82 F test/capi3e.test 3d49c01ef2a1a55f41d73cba2b23b5059ec460fe F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3 F test/cffault.test 9d6b20606afe712374952eec4f8fd74b1a8097ef -F test/check.test 92b23a91fb7be12fba7ee9ce518217e2919a21da +F test/check.test fb823c1aee9d5187b4a474f1728bb65f2a77303255e294e250a2328ab7e72832 F test/close.test 83947daf3b700631f90f4850ddaab455be4af73d F test/closure01.test b1703ba40639cfc9b295cf478d70739415eec6a4 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 @@ -1566,8 +1566,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 6d85eb5736781b43aa674d9544c7523b849b4e634f371702f8764b33e22e1e9f df39adeaa4d73a3d4ec831843b8ec7fd449f8b2137bdc7d7c320958d00e98db6 -R ce97b08e421fd719736eea9dd091c75c -T +closed df39adeaa4d73a3d4ec831843b8ec7fd449f8b2137bdc7d7c320958d00e98db6 -U dan -Z 3997e48cc61ec2c438e101b7960cfa80 +P 5c604479fda06714500959e121c719d1b6c8e54d1658eb9f560a4af95b7c5829 +R 5046d28129e3bd81658af4ffa15e3f46 +U drh +Z bf308f7cb4f4a256732c0018ceafc10b diff --git a/manifest.uuid b/manifest.uuid index 195d935585..3d54c9e4c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c604479fda06714500959e121c719d1b6c8e54d1658eb9f560a4af95b7c5829 \ No newline at end of file +019dd3d5ba4a596c4ec3b5f0de8402c72196af0faca9138edbc0f1f4957cae60 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 488a1d194c..6c27fdc5c9 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1505,6 +1505,7 @@ void sqlite3Pragma( int iDataCur, iIdxCur; int r1 = -1; + if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ if( pTab->pCheck==0 && (pTab->tabFlags & TF_HasNotNull)==0 && (pTab->pIndex==0 || isQuick) diff --git a/test/check.test b/test/check.test index 19f252677c..2100aebb85 100644 --- a/test/check.test +++ b/test/check.test @@ -481,6 +481,15 @@ do_catchsql_test 9.3 { UPDATE t1 SET c=a*2 WHERE a=1; } {1 {CHECK constraint failed: c-check}} - +# Integrity check on a VIEW with columns. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 10.1 { + CREATE TABLE t1(x); + CREATE VIEW v1(y) AS SELECT x FROM t1; + PRAGMA integrity_check; +} {ok} finish_test From 1f9144ed41cfd73d32347b3be47cbca2e8c3fc4e Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 17 Mar 2017 13:59:06 +0000 Subject: [PATCH 18/60] Fix a buffer overread in debugging routine sqlite3VdbeMemPrettyPrint(). Problem discovered by OSS-Fuzz. FossilOrigin-Name: f336fba7d7d41b91a5000d01dddf785821fa79ea31dbd8d1f769d55f7e871896 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 9 +++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 99c6df185c..77a9eebb02 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\sthe\senhanced\sPRAGMA\sintegrity_check\swhere\sit\sverifies\nCHECK\sconstraints:\sDo\snot\sbe\sconfused\sby\sthe\sreuse\sof\sthe\sTable.pCheck\sfield\nby\sVIEWs\swith\snamed\scolumns.\s\sProblem\sdiscovered\sby\sOSS-Fuzz. -D 2017-03-17T03:21:14.865 +C Fix\sa\sbuffer\soverread\sin\sdebugging\sroutine\ssqlite3VdbeMemPrettyPrint().\nProblem\sdiscovered\sby\sOSS-Fuzz. +D 2017-03-17T13:59:06.018 F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -467,7 +467,7 @@ F src/update.c 456d4a4656f8a03c2abc88a51b19172197400e58 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c ca8440ede81e155d15cff7c101654f60b55a9ae6 F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 -F src/vdbe.c 0e6e5e01aaa57f6d1784b7d6b6a352153e9d2c2ff395c67ca59aef54b8268cf6 +F src/vdbe.c 3b4221473438a047d85839129c5e71eab80d8d19487c71e0ac6802fb330ae834 F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 @@ -1566,7 +1566,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 5c604479fda06714500959e121c719d1b6c8e54d1658eb9f560a4af95b7c5829 -R 5046d28129e3bd81658af4ffa15e3f46 -U drh -Z bf308f7cb4f4a256732c0018ceafc10b +P 019dd3d5ba4a596c4ec3b5f0de8402c72196af0faca9138edbc0f1f4957cae60 +R 6b67c5433a6804d9ab2b5f747ce1957d +U dan +Z cc6693cd745156921be8476a07d72767 diff --git a/manifest.uuid b/manifest.uuid index 3d54c9e4c6..7fc9e0264a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -019dd3d5ba4a596c4ec3b5f0de8402c72196af0faca9138edbc0f1f4957cae60 \ No newline at end of file +f336fba7d7d41b91a5000d01dddf785821fa79ea31dbd8d1f769d55f7e871896 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 20bf09e3a4..7eb2b6f6f7 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2657,8 +2657,13 @@ case OP_Column: { ** 2. the length(X) function if X is a blob, and ** 3. if the content length is zero. ** So we might as well use bogus content rather than reading - ** content from disk. */ - static u8 aZero[8]; /* This is the bogus content */ + ** content from disk. + ** + ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the + ** buffer passed to it, debugging function VdbeMemPrettyPrint() may + ** read up to 16. So 16 bytes of bogus content is supplied. + */ + static u8 aZero[16]; /* This is the bogus content */ sqlite3VdbeSerialGet(aZero, t, pDest); }else{ rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); From 59d705ab808645ac865ad14e19d47f688064005f Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Mar 2017 14:15:06 +0000 Subject: [PATCH 19/60] Fix the Makefile.in so that it builds the ossshell test program correctly. FossilOrigin-Name: 36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900 --- Makefile.in | 3 ++- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Makefile.in b/Makefile.in index 0b40cb458b..9076ffc085 100644 --- a/Makefile.in +++ b/Makefile.in @@ -621,7 +621,8 @@ fuzzcheck$(TEXE): $(FUZZCHECK_SRC) sqlite3.c sqlite3.h $(LTLINK) -o $@ $(FUZZCHECK_OPT) $(FUZZCHECK_SRC) sqlite3.c $(TLIBS) ossshell$(TEXE): $(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c sqlite3.h - $(LTLINK) -o $@ $(FUZZCHECK_OPT) $(TOP)/test/ossshell.c sqlite3.c sqlite3.h $(TLIBS) + $(LTLINK) -o $@ $(FUZZCHECK_OPT) $(TOP)/test/ossshell.c \ + $(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS) dbfuzz$(TEXE): $(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h $(LTLINK) -o $@ $(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c $(TLIBS) diff --git a/manifest b/manifest index 77a9eebb02..6f14fa4cca 100644 --- a/manifest +++ b/manifest @@ -1,6 +1,6 @@ -C Fix\sa\sbuffer\soverread\sin\sdebugging\sroutine\ssqlite3VdbeMemPrettyPrint().\nProblem\sdiscovered\sby\sOSS-Fuzz. -D 2017-03-17T13:59:06.018 -F Makefile.in 9605f4c49eace601d5c12c85dd6e037cc613a6d823e857614ba26b42f1285db0 +C Fix\sthe\sMakefile.in\sso\sthat\sit\sbuilds\sthe\sossshell\stest\sprogram\scorrectly. +D 2017-03-17T14:15:06.628 +F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a F README.md 2b15fae33852f2f53996774c21fb41e1d94181c4401a0e43ac93e11f2cc901b9 @@ -1566,7 +1566,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 019dd3d5ba4a596c4ec3b5f0de8402c72196af0faca9138edbc0f1f4957cae60 -R 6b67c5433a6804d9ab2b5f747ce1957d -U dan -Z cc6693cd745156921be8476a07d72767 +P f336fba7d7d41b91a5000d01dddf785821fa79ea31dbd8d1f769d55f7e871896 +R a0acb13b6691b2f29cdfa3d14a75a6b3 +U drh +Z a464f97090f56a22de007bae0707b7f9 diff --git a/manifest.uuid b/manifest.uuid index 7fc9e0264a..cdf2f41fac 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f336fba7d7d41b91a5000d01dddf785821fa79ea31dbd8d1f769d55f7e871896 \ No newline at end of file +36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900 \ No newline at end of file From f53524b4f72be7e7cf96fdec983000c9e4c5a85a Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Mar 2017 14:59:40 +0000 Subject: [PATCH 20/60] Add the --show-errors and --show-max-delay command-line options to the ossshell test program. FossilOrigin-Name: 626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf --- manifest | 14 +++++------ manifest.uuid | 2 +- test/ossfuzz.c | 67 +++++++++++++++++++++++++++++++++++++++++-------- test/ossshell.c | 33 ++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 6f14fa4cca..24baa432d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sMakefile.in\sso\sthat\sit\sbuilds\sthe\sossshell\stest\sprogram\scorrectly. -D 2017-03-17T14:15:06.628 +C Add\sthe\s--show-errors\sand\s--show-max-delay\scommand-line\soptions\sto\sthe\nossshell\stest\sprogram. +D 2017-03-17T14:59:40.532 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1009,8 +1009,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 6dc75478809cfbd4609409a87179ddc2ffaa092e8adb27c1982c5a944a7dd81f -F test/ossshell.c d9f1a6f43e7bab45d6be857a5800f5d4a1861db3 +F test/ossfuzz.c 756ca4bede67ec22e3a700b1168bad767dc6fc69ede414c4ab87cfcfcceb4075 +F test/ossshell.c 296ab63067841bd1b1e97b46a0b2af48ee7f69d50d1a723008bee12dd7122622 F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f F test/pager1.test 841868017e9dd3cb459b8d78862091a7d9cff21d F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71 @@ -1566,7 +1566,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 f336fba7d7d41b91a5000d01dddf785821fa79ea31dbd8d1f769d55f7e871896 -R a0acb13b6691b2f29cdfa3d14a75a6b3 +P 36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900 +R 78dfbe98cc4f1c1387677674bd1f6a34 U drh -Z a464f97090f56a22de007bae0707b7f9 +Z 8d96b967fb72fb140eaa51fb70892dfa diff --git a/manifest.uuid b/manifest.uuid index cdf2f41fac..6144ff8028 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900 \ No newline at end of file +626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf \ No newline at end of file diff --git a/test/ossfuzz.c b/test/ossfuzz.c index 97d101e17a..6790d194d5 100644 --- a/test/ossfuzz.c +++ b/test/ossfuzz.c @@ -4,8 +4,26 @@ */ #include #include +#include +#include #include "sqlite3.h" +/* 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. +*/ +static unsigned mDebug = 0; +#define FUZZ_SQL_TRACE 0x0001 /* Set an sqlite3_trace() callback */ +#define FUZZ_SHOW_MAX_DELAY 0x0002 /* Show maximum progress callback delay */ +#define FUZZ_SHOW_ERRORS 0x0004 /* Print error messages from SQLite */ + +/* The ossshell utility program invokes this interface to see the +** debugging flags. Unused by OSS-Fuzz. +*/ +void ossfuzz_set_debug_flags(unsigned x){ + mDebug = x; +} + /* Return the current real-world time in milliseconds since the ** Julian epoch (-4714-11-24). */ @@ -23,6 +41,17 @@ static sqlite3_int64 timeOfDay(void){ return t; } +/* An instance of the following object is passed by pointer as the +** client data to various callbacks. +*/ +typedef struct FuzzCtx { + sqlite3 *db; /* The database connection */ + sqlite3_int64 iCutoffTime; /* Stop processing at this time. */ + sqlite3_int64 iLastCb; /* Time recorded for previous progress callback */ + sqlite3_int64 mxInterval; /* Longest interval between two progress calls */ + unsigned nCb; /* Number of progress callbacks */ +} FuzzCtx; + #ifndef SQLITE_OMIT_PROGRESS_CALLBACK /* ** Progress handler callback. @@ -30,9 +59,14 @@ static sqlite3_int64 timeOfDay(void){ ** The argument is the cutoff-time after which all processing should ** stop. So return non-zero if the cut-off time is exceeded. */ -static int progress_handler(void *pReturn) { - sqlite3_int64 iCutoffTime = *(sqlite3_int64*)pReturn; - return timeOfDay()>=iCutoffTime; +static int progress_handler(void *pClientData) { + FuzzCtx *p = (FuzzCtx*)pClientData; + sqlite3_int64 iNow = timeOfDay(); + int rc = iNow>=p->iCutoffTime; + sqlite3_int64 iDiff = iNow - p->iLastCb; + if( iDiff > p->mxInterval ) p->mxInterval = iDiff; + p->nCb++; + return rc; } #endif @@ -54,12 +88,12 @@ static int exec_handler(void *pCnt, int argc, char **argv, char **namev){ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { int execCnt = 0; /* Abort row callback when count reaches zero */ char *zErrMsg = 0; /* Error message returned by sqlite_exec() */ - sqlite3 *db; /* The database connection */ uint8_t uSelector; /* First byte of input data[] */ int rc; /* Return code from various interfaces */ char *zSql; /* Zero-terminated copy of data[] */ - sqlite3_int64 iCutoff; /* Cutoff timer */ + FuzzCtx cx; /* Fuzzing context */ + memset(&cx, 0, sizeof(cx)); if( size<3 ) return 0; /* Early out if unsufficient data */ /* Extract the selector byte from the beginning of the input. But only @@ -72,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { } /* Open the database connection. Only use an in-memory database. */ - rc = sqlite3_open_v2("fuzz.db", &db, + rc = sqlite3_open_v2("fuzz.db", &cx.db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY, 0); if( rc ) return 0; @@ -82,12 +116,13 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { ** (which will block further processing) if more than 10 seconds have ** elapsed since the start of the test. */ - iCutoff = timeOfDay() + 10000; /* Now + 10 seconds */ - sqlite3_progress_handler(db, 10, progress_handler, (void*)&iCutoff); + cx.iLastCb = timeOfDay(); + cx.iCutoffTime = cx.iLastCb + 10000; /* Now + 10 seconds */ + sqlite3_progress_handler(cx.db, 10, progress_handler, (void*)&cx); #endif /* Bit 1 of the selector enables foreign key constraints */ - sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, uSelector&1, &rc); + sqlite3_db_config(cx.db, SQLITE_DBCONFIG_ENABLE_FKEY, uSelector&1, &rc); uSelector >>= 1; /* Remaining bits of the selector determine a limit on the number of @@ -97,11 +132,21 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run the SQL. The sqlite_exec() interface expects a zero-terminated ** string, so make a copy. */ zSql = sqlite3_mprintf("%.*s", (int)size, data); - sqlite3_exec(db, zSql, exec_handler, (void*)&execCnt, &zErrMsg); + sqlite3_exec(cx.db, zSql, exec_handler, (void*)&execCnt, &zErrMsg); + + /* Show any errors */ + if( (mDebug & FUZZ_SHOW_ERRORS)!=0 && zErrMsg ){ + printf("Error: %s\n", zErrMsg); + } /* Cleanup and return */ sqlite3_free(zErrMsg); sqlite3_free(zSql); - sqlite3_close(db); + sqlite3_close(cx.db); + + if( mDebug & FUZZ_SHOW_MAX_DELAY ){ + printf("Progress callback count....... %d\n", cx.nCb); + printf("Max time between callbacks.... %d ms\n", (int)cx.mxInterval); + } return 0; } diff --git a/test/ossshell.c b/test/ossshell.c index 15902a9122..00cc3391c8 100644 --- a/test/ossshell.c +++ b/test/ossshell.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "sqlite3.h" /* @@ -16,6 +17,13 @@ */ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); +/* Must match equivalent #defines in ossfuzz.c */ +#define FUZZ_SQL_TRACE 0x0001 /* Set an sqlite3_trace() callback */ +#define FUZZ_SHOW_MAX_DELAY 0x0002 /* Show maximum progress callback delay */ +#define FUZZ_SHOW_ERRORS 0x0004 /* Show SQL errors */ +extern void ossfuzz_set_debug_flags(unsigned); + + /* ** Read files named on the command-line and invoke the fuzzer for @@ -27,9 +35,32 @@ int main(int argc, char **argv){ int nErr = 0; uint8_t *zBuf = 0; size_t sz; + unsigned mDebug = 0; for(i=1; i Date: Fri, 17 Mar 2017 22:50:16 +0000 Subject: [PATCH 21/60] Begin enforcing the SQLITE_LIMIT_VDBE_OP. The documentation warned that this day might come. FossilOrigin-Name: ef5914617088cbf89bfae88f63ea959a07f02dff387ddc2b43948ad99c6a97b8 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/sqlite.h.in | 8 +++++--- src/sqliteLimit.h | 2 +- src/vdbeaux.c | 6 ++++++ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 24baa432d0..db77af64f9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--show-errors\sand\s--show-max-delay\scommand-line\soptions\sto\sthe\nossshell\stest\sprogram. -D 2017-03-17T14:59:40.532 +C Begin\senforcing\sthe\sSQLITE_LIMIT_VDBE_OP.\s\sThe\sdocumentation\swarned\sthat\sthis\nday\smight\scome. +D 2017-03-17T22:50:16.704 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -402,11 +402,11 @@ F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa F src/shell.c 77054c021069ec0b65d3d620aab031f97c59b4e42ac7c31544ea68933b581104 -F src/sqlite.h.in 4d0c08f8640c586564a7032b259c5f69bf397850 +F src/sqlite.h.in 5f72af637ba0f35c2b25f8f97ea63bac6f4ea133eb904ee0b6d61450401507d3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae F src/sqliteInt.h df268ce1d04df042cf43b557d2309eb0b71e86c4 -F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247 +F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 F src/tclsqlite.c 6c2151b6d8d98e183a04466d40df8889c0574d79 @@ -471,7 +471,7 @@ F src/vdbe.c 3b4221473438a047d85839129c5e71eab80d8d19487c71e0ac6802fb330ae834 F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 -F src/vdbeaux.c 57361f2e761d92a254638bdbfc03fc68ae6aebc6 +F src/vdbeaux.c ecd0468611925d218e1eb4b3f538907904b136f0e15e333291a232b521bfcef1 F src/vdbeblob.c 359891617358deefc85bef7bcf787fa6b77facb9 F src/vdbemem.c 3b5a9a5b375458d3e12a50ae1aaa41eeec2175fd F src/vdbesort.c eda25cb2d1727efca6f7862fea32b8aa33c0face @@ -1566,7 +1566,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 36f5602ec9fb8e404c5250e18b1db877ac7bee643918b94afd51808134ea7900 -R 78dfbe98cc4f1c1387677674bd1f6a34 +P 626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf +R 577cbf1218e05c6f890fd56d3bd8c3f1 U drh -Z 8d96b967fb72fb140eaa51fb70892dfa +Z db7430243d899e77772ca775a4ab8f59 diff --git a/manifest.uuid b/manifest.uuid index 6144ff8028..0f60fb4ebb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf \ No newline at end of file +ef5914617088cbf89bfae88f63ea959a07f02dff387ddc2b43948ad99c6a97b8 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 076a011319..5dd4419f43 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -3424,9 +3424,10 @@ int sqlite3_limit(sqlite3*, int id, int newVal); ** ** [[SQLITE_LIMIT_VDBE_OP]] ^(
SQLITE_LIMIT_VDBE_OP
**
The maximum number of instructions in a virtual machine program -** used to implement an SQL statement. This limit is not currently -** enforced, though that might be added in some future release of -** SQLite.
)^ +** used to implement an SQL statement. If [sqlite3_prepare_v2()] or +** the equivalent tries to allocate space for more than this many opcodes +** in a single prepared statement, an SQLITE_NOMEM error is returned. +** A value of 0 means "unlimited".)^ ** ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(
SQLITE_LIMIT_FUNCTION_ARG
**
The maximum number of arguments on a function.
)^ @@ -3464,6 +3465,7 @@ int sqlite3_limit(sqlite3*, int id, int newVal); #define SQLITE_LIMIT_TRIGGER_DEPTH 10 #define SQLITE_LIMIT_WORKER_THREADS 11 + /* ** CAPI3REF: Compiling An SQL Statement ** KEYWORDS: {SQL statement compiler} diff --git a/src/sqliteLimit.h b/src/sqliteLimit.h index 0554e61581..28e7a41cc3 100644 --- a/src/sqliteLimit.h +++ b/src/sqliteLimit.h @@ -87,7 +87,7 @@ ** Not currently enforced. */ #ifndef SQLITE_MAX_VDBE_OP -# define SQLITE_MAX_VDBE_OP 25000 +# define SQLITE_MAX_VDBE_OP 250000000 #endif /* diff --git a/src/vdbeaux.c b/src/vdbeaux.c index ab4aad7a0f..a8f215420a 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -117,6 +117,12 @@ static int growOpArray(Vdbe *v, int nOp){ UNUSED_PARAMETER(nOp); #endif + /* Ensure that the size of a VDBE does not grow too large */ + if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){ + sqlite3OomFault(p->db); + return SQLITE_NOMEM; + } + assert( nOp<=(1024/sizeof(Op)) ); assert( nNew>=(p->nOpAlloc+nOp) ); pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); From 544cab7651100628ed290acc2a2fee394b7568aa Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Mar 2017 22:51:28 +0000 Subject: [PATCH 22/60] Set a reasonable limit on the number of opcodes in a prepared statement for ossfuzz.c. This should prevent timeouts in OSS-Fuzz when it generates totally unreasonable queries. FossilOrigin-Name: f74899ed2c78019abb406432a74dcd42a0ff8d9add005f8544dc4a8905f232eb --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/ossfuzz.c | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index db77af64f9..3396b9cc13 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Begin\senforcing\sthe\sSQLITE_LIMIT_VDBE_OP.\s\sThe\sdocumentation\swarned\sthat\sthis\nday\smight\scome. -D 2017-03-17T22:50:16.704 +C Set\sa\sreasonable\slimit\son\sthe\snumber\sof\sopcodes\sin\sa\sprepared\sstatement\nfor\sossfuzz.c.\s\sThis\sshould\sprevent\stimeouts\sin\sOSS-Fuzz\swhen\sit\sgenerates\ntotally\sunreasonable\squeries. +D 2017-03-17T22:51:28.665 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1009,7 +1009,7 @@ F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3 F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f -F test/ossfuzz.c 756ca4bede67ec22e3a700b1168bad767dc6fc69ede414c4ab87cfcfcceb4075 +F test/ossfuzz.c 8c4d62e156352ecb97eb868fcff20d828a279af67a1c1310779f63464d6f009f F test/ossshell.c 296ab63067841bd1b1e97b46a0b2af48ee7f69d50d1a723008bee12dd7122622 F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f F test/pager1.test 841868017e9dd3cb459b8d78862091a7d9cff21d @@ -1566,7 +1566,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 626bdca98e0cd78ae873d97e75bb7d544ca18759c9f1e67f4adf03daca7fe5bf -R 577cbf1218e05c6f890fd56d3bd8c3f1 +P ef5914617088cbf89bfae88f63ea959a07f02dff387ddc2b43948ad99c6a97b8 +R 3a60b2fbebe94ced9367e16b751bb1ee U drh -Z db7430243d899e77772ca775a4ab8f59 +Z bc390a309335be50f7a4bf79ab7f90df diff --git a/manifest.uuid b/manifest.uuid index 0f60fb4ebb..e97c1e2b26 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ef5914617088cbf89bfae88f63ea959a07f02dff387ddc2b43948ad99c6a97b8 \ No newline at end of file +f74899ed2c78019abb406432a74dcd42a0ff8d9add005f8544dc4a8905f232eb \ No newline at end of file diff --git a/test/ossfuzz.c b/test/ossfuzz.c index 6790d194d5..0c2b1320e4 100644 --- a/test/ossfuzz.c +++ b/test/ossfuzz.c @@ -121,6 +121,9 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { sqlite3_progress_handler(cx.db, 10, progress_handler, (void*)&cx); #endif + /* Set a limit on the maximum size of a prepared statement */ + sqlite3_limit(cx.db, SQLITE_LIMIT_VDBE_OP, 25000); + /* Bit 1 of the selector enables foreign key constraints */ sqlite3_db_config(cx.db, SQLITE_DBCONFIG_ENABLE_FKEY, uSelector&1, &rc); uSelector >>= 1; From 46acfc2b4737258bf4af6f34f9ba88f0281d73bb Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 17 Mar 2017 23:08:11 +0000 Subject: [PATCH 23/60] Fix an error in the newly revised documentation for SQLITE_LIMIT_VDBE_OP. No changes to code. FossilOrigin-Name: f4cf8635e6fec6f04075cc067aaa71abc4f71739068e0ad2c44609dcb8691009 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 3396b9cc13..0f47d77aec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Set\sa\sreasonable\slimit\son\sthe\snumber\sof\sopcodes\sin\sa\sprepared\sstatement\nfor\sossfuzz.c.\s\sThis\sshould\sprevent\stimeouts\sin\sOSS-Fuzz\swhen\sit\sgenerates\ntotally\sunreasonable\squeries. -D 2017-03-17T22:51:28.665 +C Fix\san\serror\sin\sthe\snewly\srevised\sdocumentation\sfor\sSQLITE_LIMIT_VDBE_OP.\nNo\schanges\sto\scode. +D 2017-03-17T23:08:11.772 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -402,7 +402,7 @@ F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa F src/shell.c 77054c021069ec0b65d3d620aab031f97c59b4e42ac7c31544ea68933b581104 -F src/sqlite.h.in 5f72af637ba0f35c2b25f8f97ea63bac6f4ea133eb904ee0b6d61450401507d3 +F src/sqlite.h.in e992605a306ee4f58d2ecbbc665f71c0404a3c815fe90dd8e0c0e8f7b9b11166 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae F src/sqliteInt.h df268ce1d04df042cf43b557d2309eb0b71e86c4 @@ -1566,7 +1566,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 ef5914617088cbf89bfae88f63ea959a07f02dff387ddc2b43948ad99c6a97b8 -R 3a60b2fbebe94ced9367e16b751bb1ee +P f74899ed2c78019abb406432a74dcd42a0ff8d9add005f8544dc4a8905f232eb +R 2c6af10e620c43369539bc210339bdfc U drh -Z bc390a309335be50f7a4bf79ab7f90df +Z 53bb8f51c26aa8f2582ebee07b281f74 diff --git a/manifest.uuid b/manifest.uuid index e97c1e2b26..5630824735 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f74899ed2c78019abb406432a74dcd42a0ff8d9add005f8544dc4a8905f232eb \ No newline at end of file +f4cf8635e6fec6f04075cc067aaa71abc4f71739068e0ad2c44609dcb8691009 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 5dd4419f43..48e21e175b 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -3426,8 +3426,7 @@ int sqlite3_limit(sqlite3*, int id, int newVal); **
The maximum number of instructions in a virtual machine program ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or ** the equivalent tries to allocate space for more than this many opcodes -** in a single prepared statement, an SQLITE_NOMEM error is returned. -** A value of 0 means "unlimited".
)^ +** in a single prepared statement, an SQLITE_NOMEM error is returned.)^ ** ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(
SQLITE_LIMIT_FUNCTION_ARG
**
The maximum number of arguments on a function.
)^ From a80e160634c95ab4d72ed0760d7a70eca458334a Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 18 Mar 2017 13:59:46 +0000 Subject: [PATCH 24/60] Only do the specialized MacOS single-core zone_malloc initialization if compiled with the SQLITE_MIGHT_BE_SINGLE_CORE flag. This avoids a (harmless) warning about OSAtomicCompareAndSwapPtrBarrier() being deprecated. FossilOrigin-Name: 4e6a03d9e12b120d15946b025f97a97697cb8e8af543c238ffda220c9e3f28f4 --- manifest | 12 +++++------ manifest.uuid | 2 +- src/mem1.c | 59 ++++++++++++++++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 0f47d77aec..d7127e3e78 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\serror\sin\sthe\snewly\srevised\sdocumentation\sfor\sSQLITE_LIMIT_VDBE_OP.\nNo\schanges\sto\scode. -D 2017-03-17T23:08:11.772 +C Only\sdo\sthe\sspecialized\sMacOS\ssingle-core\szone_malloc\sinitialization\sif\ncompiled\swith\sthe\sSQLITE_MIGHT_BE_SINGLE_CORE\sflag.\s\sThis\savoids\sa\s(harmless)\nwarning\sabout\sOSAtomicCompareAndSwapPtrBarrier()\sbeing\sdeprecated. +D 2017-03-18T13:59:46.558 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -368,7 +368,7 @@ F src/loadext.c a68d8d1d14cf7488bb29dc5311cb1ce9a4404258 F src/main.c 158326243c5ddc8b98a1e983fa488650cf76d760 F src/malloc.c 89c98e3619d362dcffa5c1c639b364b65b474751 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 -F src/mem1.c fd7cd6fe21d46fe0a4186367dd8dc26d87b787eb +F src/mem1.c 79bf195f445bf7e66cadd121849837c3152fbd2f542326bbed3073b6902450c2 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 @@ -1566,7 +1566,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 f74899ed2c78019abb406432a74dcd42a0ff8d9add005f8544dc4a8905f232eb -R 2c6af10e620c43369539bc210339bdfc +P f4cf8635e6fec6f04075cc067aaa71abc4f71739068e0ad2c44609dcb8691009 +R 07e88bce7a34b04a1e3a36ad2d4b6f58 U drh -Z 53bb8f51c26aa8f2582ebee07b281f74 +Z 906adb059f738e34206863c58e96feb3 diff --git a/manifest.uuid b/manifest.uuid index 5630824735..4d805efd7a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f4cf8635e6fec6f04075cc067aaa71abc4f71739068e0ad2c44609dcb8691009 \ No newline at end of file +4e6a03d9e12b120d15946b025f97a97697cb8e8af543c238ffda220c9e3f28f4 \ No newline at end of file diff --git a/src/mem1.c b/src/mem1.c index efc84c41d7..02ed59b4d4 100644 --- a/src/mem1.c +++ b/src/mem1.c @@ -57,7 +57,9 @@ */ #include #include +#ifdef SQLITE_MIGHT_BE_SINGLE_CORE #include +#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */ static malloc_zone_t* _sqliteZone_; #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x)) #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x)); @@ -236,33 +238,46 @@ static int sqlite3MemRoundup(int n){ */ static int sqlite3MemInit(void *NotUsed){ #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) - int cpuCount; - size_t len; if( _sqliteZone_ ){ return SQLITE_OK; } - len = sizeof(cpuCount); - /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ - sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); - if( cpuCount>1 ){ - /* defer MT decisions to system malloc */ - _sqliteZone_ = malloc_default_zone(); - }else{ - /* only 1 core, use our own zone to contention over global locks, - ** e.g. we have our own dedicated locks */ - bool success; - malloc_zone_t* newzone = malloc_create_zone(4096, 0); - malloc_set_zone_name(newzone, "Sqlite_Heap"); - do{ - success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, - (void * volatile *)&_sqliteZone_); - }while(!_sqliteZone_); - if( !success ){ - /* somebody registered a zone first */ - malloc_destroy_zone(newzone); +#ifndef SQLITE_MIGHT_BE_SINGLE_CORE + /* If not compiled with the SQLITE_MIGHT_BE_SINGLE_CORE flag, assume + ** that multiple cores are always available. This is the default case. + */ + _sqliteZone_ = malloc_default_zone(); +#else + /* With the SQLITE_MIGHT_BE_SINGLE_CORE compile-time option, check the + ** number of cores. Different malloc() strategies are used for single-core and + ** multi-core machines. + */ + { + int cpuCount; + size_t len; + len = sizeof(cpuCount); + /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ + sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); + if( cpuCount>1 ){ + /* defer MT decisions to system malloc */ + _sqliteZone_ = malloc_default_zone(); + }else{ + /* only 1 core, use our own zone to contention over global locks, + ** e.g. we have our own dedicated locks */ + bool success; + malloc_zone_t* newzone = malloc_create_zone(4096, 0); + malloc_set_zone_name(newzone, "Sqlite_Heap"); + do{ + success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, + (void * volatile *)&_sqliteZone_); + }while(!_sqliteZone_); + if( !success ){ + /* somebody registered a zone first */ + malloc_destroy_zone(newzone); + } } } -#endif +#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */ +#endif /* defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */ UNUSED_PARAMETER(NotUsed); return SQLITE_OK; } From d3d52ef1471c670a1bb04c0dcf05cf7866c98cd7 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Mar 2017 13:03:39 +0000 Subject: [PATCH 25/60] Documentation fix: SQLITE_SOURCE_ID is a now a SHA3-256 hash. FossilOrigin-Name: 2aa22509e7c8a1f09b16e4544c95d0b77503daed1f83106ccc18dee8bd9487a4 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqlite.h.in | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d7127e3e78..5f21e2e7ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Only\sdo\sthe\sspecialized\sMacOS\ssingle-core\szone_malloc\sinitialization\sif\ncompiled\swith\sthe\sSQLITE_MIGHT_BE_SINGLE_CORE\sflag.\s\sThis\savoids\sa\s(harmless)\nwarning\sabout\sOSAtomicCompareAndSwapPtrBarrier()\sbeing\sdeprecated. -D 2017-03-18T13:59:46.558 +C Documentation\sfix:\s\sSQLITE_SOURCE_ID\sis\sa\snow\sa\sSHA3-256\shash. +D 2017-03-20T13:03:39.888 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -402,7 +402,7 @@ F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa F src/shell.c 77054c021069ec0b65d3d620aab031f97c59b4e42ac7c31544ea68933b581104 -F src/sqlite.h.in e992605a306ee4f58d2ecbbc665f71c0404a3c815fe90dd8e0c0e8f7b9b11166 +F src/sqlite.h.in 723107d97f2345a7c103632169dc61366121c4ab65d75a7d83c6dc0e5bbe5ca4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae F src/sqliteInt.h df268ce1d04df042cf43b557d2309eb0b71e86c4 @@ -1566,7 +1566,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 f4cf8635e6fec6f04075cc067aaa71abc4f71739068e0ad2c44609dcb8691009 -R 07e88bce7a34b04a1e3a36ad2d4b6f58 +P 4e6a03d9e12b120d15946b025f97a97697cb8e8af543c238ffda220c9e3f28f4 +R 3e310c01c37c6ac62b74a767e914605e U drh -Z 906adb059f738e34206863c58e96feb3 +Z 061c837491d90260f4d8f777c55b50b5 diff --git a/manifest.uuid b/manifest.uuid index 4d805efd7a..611148833a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4e6a03d9e12b120d15946b025f97a97697cb8e8af543c238ffda220c9e3f28f4 \ No newline at end of file +2aa22509e7c8a1f09b16e4544c95d0b77503daed1f83106ccc18dee8bd9487a4 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 48e21e175b..97294c3f81 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -114,8 +114,8 @@ extern "C" { ** system. ^The SQLITE_SOURCE_ID macro evaluates to ** a string which identifies a particular check-in of SQLite ** within its configuration management system. ^The SQLITE_SOURCE_ID -** string contains the date and time of the check-in (UTC) and an SHA1 -** hash of the entire source tree. +** string contains the date and time of the check-in (UTC) and a SHA1 +** or SHA3-256 hash of the entire source tree. ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], From 978896e0eb0a27354e3a19c195718a9e2e7a13ca Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Mar 2017 14:44:07 +0000 Subject: [PATCH 26/60] Fix the check.test script so that it works on Windows. FossilOrigin-Name: 8822eb5d790bf8d4302c3f2dc05ab672193b309fb11771c4b3eea8a77f37e299 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/check.test | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 5f21e2e7ce..ad0fdedb4c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Documentation\sfix:\s\sSQLITE_SOURCE_ID\sis\sa\snow\sa\sSHA3-256\shash. -D 2017-03-20T13:03:39.888 +C Fix\sthe\scheck.test\sscript\sso\sthat\sit\sworks\son\sWindows. +D 2017-03-20T14:44:07.253 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -582,7 +582,7 @@ F test/capi3d.test 485048dc5cd07bc68011e4917ad035ad6047ab82 F test/capi3e.test 3d49c01ef2a1a55f41d73cba2b23b5059ec460fe F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3 F test/cffault.test 9d6b20606afe712374952eec4f8fd74b1a8097ef -F test/check.test fb823c1aee9d5187b4a474f1728bb65f2a77303255e294e250a2328ab7e72832 +F test/check.test 33a698e8c63613449d85d624a38ef669bf20331daabebe3891c9405dd6df463a F test/close.test 83947daf3b700631f90f4850ddaab455be4af73d F test/closure01.test b1703ba40639cfc9b295cf478d70739415eec6a4 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91 @@ -1566,7 +1566,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 4e6a03d9e12b120d15946b025f97a97697cb8e8af543c238ffda220c9e3f28f4 -R 3e310c01c37c6ac62b74a767e914605e +P 2aa22509e7c8a1f09b16e4544c95d0b77503daed1f83106ccc18dee8bd9487a4 +R 2a38f53db76a379174ef41cee348ccde U drh -Z 061c837491d90260f4d8f777c55b50b5 +Z 993304dc90b274b690e8ef820df2c963 diff --git a/manifest.uuid b/manifest.uuid index 611148833a..83f96a2ae7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2aa22509e7c8a1f09b16e4544c95d0b77503daed1f83106ccc18dee8bd9487a4 \ No newline at end of file +8822eb5d790bf8d4302c3f2dc05ab672193b309fb11771c4b3eea8a77f37e299 \ No newline at end of file diff --git a/test/check.test b/test/check.test index 2100aebb85..a6dbaa6171 100644 --- a/test/check.test +++ b/test/check.test @@ -484,6 +484,7 @@ do_catchsql_test 9.3 { # Integrity check on a VIEW with columns. # db close +db2 close forcedelete test.db sqlite3 db test.db do_execsql_test 10.1 { From 154cc746012d7fddd5436235e9f44ebd72a7ec6c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Mar 2017 15:11:40 +0000 Subject: [PATCH 27/60] Only run sync2.test on unix, as it depends on instrumentation in os_unix.c. FossilOrigin-Name: ecb9321e18dd72ea18d197c61c4d69500e9c4282c0eac67822cb40b2710a2815 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/sync2.test | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ad0fdedb4c..ed725cf65c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scheck.test\sscript\sso\sthat\sit\sworks\son\sWindows. -D 2017-03-20T14:44:07.253 +C Only\srun\ssync2.test\son\sunix,\sas\sit\sdepends\son\sinstrumentation\sin\sos_unix.c. +D 2017-03-20T15:11:40.222 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1165,7 +1165,7 @@ F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test ec94f0556b6488d97f71c79f9061ae08d9ab8f12 F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529 -F test/sync2.test 5ecf56be4c187a191253a1ec0786fe2df975dbf3dc0f0140cdf5d3690c90651c +F test/sync2.test c59ffd63e69854bf41ac407a9762ab5c128894b754253bf94db8a85d15de5444 F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 F test/tabfunc01.test 699251cb99651415218a891384510a685c7ab012 @@ -1566,7 +1566,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 2aa22509e7c8a1f09b16e4544c95d0b77503daed1f83106ccc18dee8bd9487a4 -R 2a38f53db76a379174ef41cee348ccde -U drh -Z 993304dc90b274b690e8ef820df2c963 +P 8822eb5d790bf8d4302c3f2dc05ab672193b309fb11771c4b3eea8a77f37e299 +R 9d22d8b55292860d95cad32e3b689bec +U dan +Z 532b84081e4fb29bc1e9b05f7d75c0ea diff --git a/manifest.uuid b/manifest.uuid index 83f96a2ae7..18bf16e13c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8822eb5d790bf8d4302c3f2dc05ab672193b309fb11771c4b3eea8a77f37e299 \ No newline at end of file +ecb9321e18dd72ea18d197c61c4d69500e9c4282c0eac67822cb40b2710a2815 \ No newline at end of file diff --git a/test/sync2.test b/test/sync2.test index 5f9c9aba93..1fd74ef89b 100644 --- a/test/sync2.test +++ b/test/sync2.test @@ -26,6 +26,10 @@ ifcapable !pager_pragmas||!attach { finish_test return } +if {$::tcl_platform(platform)!="unix"} { + finish_test + return +} proc execsql_sync {sql} { set s $::sqlite_sync_count From 7adbcffcb94531498c2e43b246c4e3e4368691ef Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Mar 2017 15:29:28 +0000 Subject: [PATCH 28/60] Ensure that a "--" prefix is added to sqlite3_trace_v2() output for nested SQL statements. FossilOrigin-Name: 673a7b67c4828acaea3baebea500ef1f8ae763588b0d9c9f2ad6ed5ceb3cfee2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ed725cf65c..6e74d950bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Only\srun\ssync2.test\son\sunix,\sas\sit\sdepends\son\sinstrumentation\sin\sos_unix.c. -D 2017-03-20T15:11:40.222 +C Ensure\sthat\sa\s"--"\sprefix\sis\sadded\sto\ssqlite3_trace_v2()\soutput\sfor\snested\nSQL\sstatements. +D 2017-03-20T15:29:28.021 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -467,7 +467,7 @@ F src/update.c 456d4a4656f8a03c2abc88a51b19172197400e58 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c ca8440ede81e155d15cff7c101654f60b55a9ae6 F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 -F src/vdbe.c 3b4221473438a047d85839129c5e71eab80d8d19487c71e0ac6802fb330ae834 +F src/vdbe.c 89a12451405a17c6e8d39b5826acb6999f1283e4e43d2e83a7ac7c9a7094a86a F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 @@ -1566,7 +1566,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 8822eb5d790bf8d4302c3f2dc05ab672193b309fb11771c4b3eea8a77f37e299 -R 9d22d8b55292860d95cad32e3b689bec -U dan -Z 532b84081e4fb29bc1e9b05f7d75c0ea +P ecb9321e18dd72ea18d197c61c4d69500e9c4282c0eac67822cb40b2710a2815 +R 5262e66ba51f0f0c41b35ecdd4289055 +U drh +Z 6393fe64153a32f9de418b09796f1e18 diff --git a/manifest.uuid b/manifest.uuid index 18bf16e13c..ca8dc248ab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ecb9321e18dd72ea18d197c61c4d69500e9c4282c0eac67822cb40b2710a2815 \ No newline at end of file +673a7b67c4828acaea3baebea500ef1f8ae763588b0d9c9f2ad6ed5ceb3cfee2 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 7eb2b6f6f7..93c20c0aaa 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6950,7 +6950,11 @@ case OP_Init: { /* jump */ sqlite3_free(z); }else #endif - { + if( db->nVdbeExec>1 ){ + char *z = sqlite3MPrintf(db, "-- %s", zTrace); + (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, z); + sqlite3DbFree(db, z); + }else{ (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace); } } From 5b3a3b359a4f31b3776044e864f35557d5dcb2fb Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Mar 2017 16:06:48 +0000 Subject: [PATCH 29/60] Do not run sync2.test as part of the "journaltest" permutation, as it uses "PRAGMA synchronous = off". FossilOrigin-Name: 285005a9bcb210bb2a9aa9fed6a19d4b78641a6e7622d469bd0d2a365b2c0735 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/test_journal.c | 3 +++ test/sync2.test | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 6e74d950bd..1c7dda125d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sa\s"--"\sprefix\sis\sadded\sto\ssqlite3_trace_v2()\soutput\sfor\snested\nSQL\sstatements. -D 2017-03-20T15:29:28.021 +C Do\snot\srun\ssync2.test\sas\spart\sof\sthe\s"journaltest"\spermutation,\sas\sit\suses\n"PRAGMA\ssynchronous\s=\soff". +D 2017-03-20T16:06:48.281 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -435,7 +435,7 @@ F src/test_hexio.c 1d4469ca61ab202a1fcec6543f584d2407205e8d F src/test_init.c 4413c211a94b62157ca4c145b3f27c497f03c664 F src/test_intarray.c 988fc61cb0ff539f4172c0d95f15287c92516f64 F src/test_intarray.h f3b7672f5d1056eac563c0d6ea8480a660b1475c -F src/test_journal.c d3b83f2bcb7792c709e57abddc456a2b1818643a +F src/test_journal.c 619f2aa10e0d7a5f87c0f06825bc61dfce1c6b9c7f3ad990fb13de6c3b8874a3 F src/test_loadext.c 337056bae59f80b9eb00ba82088b39d0f4fe6dfd F src/test_malloc.c c05f6c40bd6c8bfe5f1718212f81fd5687f91766 F src/test_multiplex.c e054459f7633f3ff8ce1245da724f9a8be189e4e @@ -1165,7 +1165,7 @@ F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test ec94f0556b6488d97f71c79f9061ae08d9ab8f12 F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529 -F test/sync2.test c59ffd63e69854bf41ac407a9762ab5c128894b754253bf94db8a85d15de5444 +F test/sync2.test b028aa9ca0bb4793e86140f777c6b88dcc6741f7a918381662e53bc5f2b97c74 F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 F test/tabfunc01.test 699251cb99651415218a891384510a685c7ab012 @@ -1566,7 +1566,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 ecb9321e18dd72ea18d197c61c4d69500e9c4282c0eac67822cb40b2710a2815 -R 5262e66ba51f0f0c41b35ecdd4289055 -U drh -Z 6393fe64153a32f9de418b09796f1e18 +P 673a7b67c4828acaea3baebea500ef1f8ae763588b0d9c9f2ad6ed5ceb3cfee2 +R 547057b8e0709a92c08d29e340a54617 +U dan +Z c38b0bcff9e9a77e6d2ca931cd7486d0 diff --git a/manifest.uuid b/manifest.uuid index ca8dc248ab..7f9fef5671 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -673a7b67c4828acaea3baebea500ef1f8ae763588b0d9c9f2ad6ed5ceb3cfee2 \ No newline at end of file +285005a9bcb210bb2a9aa9fed6a19d4b78641a6e7622d469bd0d2a365b2c0735 \ No newline at end of file diff --git a/src/test_journal.c b/src/test_journal.c index 4e63bccf76..8a449e888c 100644 --- a/src/test_journal.c +++ b/src/test_journal.c @@ -557,6 +557,9 @@ static int jtWrite( u32 pgno = (u32)(iOfst/p->nPagesize + 1); assert( (iAmt==1||iAmt==(int)p->nPagesize) && ((iOfst+iAmt)%p->nPagesize)==0 ); + /* The following assert() statements may fail if this layer is used + ** with a connection in "PRAGMA synchronous=off" mode. If they + ** fail with sync=normal or sync=full, this may indicate problem. */ assert( pgno<=p->nPage || p->nSync>0 ); assert( pgno>p->nPage || sqlite3BitvecTest(p->pWritable, pgno) ); } diff --git a/test/sync2.test b/test/sync2.test index 1fd74ef89b..a88e4bed32 100644 --- a/test/sync2.test +++ b/test/sync2.test @@ -26,7 +26,7 @@ ifcapable !pager_pragmas||!attach { finish_test return } -if {$::tcl_platform(platform)!="unix"} { +if {$::tcl_platform(platform)!="unix" || [permutation] == "journaltest"} { finish_test return } From 5f42995a0a51be942cbb9095829767b175da0a87 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Mar 2017 16:34:18 +0000 Subject: [PATCH 30/60] Avoid the possibility of signed integer overflow with oversized precisions in %d conversions in the printf() implementation. FossilOrigin-Name: ef3a7c877a7549b351aafd983cfa96c863eb2641b6218bdd5cb563f659f879d8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/printf.c | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1c7dda125d..5c8fe10828 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srun\ssync2.test\sas\spart\sof\sthe\s"journaltest"\spermutation,\sas\sit\suses\n"PRAGMA\ssynchronous\s=\soff". -D 2017-03-20T16:06:48.281 +C Avoid\sthe\spossibility\sof\ssigned\sinteger\soverflow\swith\soversized\sprecisions\nin\s%d\sconversions\sin\sthe\sprintf()\simplementation. +D 2017-03-20T16:34:18.983 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -396,7 +396,7 @@ F src/pcache1.c e3967219b2a92b9edcb9324a4ba75009090d3953 F src/pragma.c 2b244434e76c7075edbcfd9e4d634899af0944ff01183b126d4671f7407c2368 F src/pragma.h c9c763958fec92b04125571472c9500b351c5f7f F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a -F src/printf.c 67427bbee66d891fc6f6f5aada857e9cdb368c1c +F src/printf.c 8757834f1b54dae512fb25eb1acc8e94a0d15dd2290b58f2563f65973265adb2 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac @@ -1566,7 +1566,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 673a7b67c4828acaea3baebea500ef1f8ae763588b0d9c9f2ad6ed5ceb3cfee2 -R 547057b8e0709a92c08d29e340a54617 -U dan -Z c38b0bcff9e9a77e6d2ca931cd7486d0 +P 285005a9bcb210bb2a9aa9fed6a19d4b78641a6e7622d469bd0d2a365b2c0735 +R d28630b090e29d249202016ad6a6d827 +U drh +Z dd88d1a97157edc79245fb3d73eca0b6 diff --git a/manifest.uuid b/manifest.uuid index 7f9fef5671..68447cc550 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -285005a9bcb210bb2a9aa9fed6a19d4b78641a6e7622d469bd0d2a365b2c0735 \ No newline at end of file +ef3a7c877a7549b351aafd983cfa96c863eb2641b6218bdd5cb563f659f879d8 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 241338b266..a14e658875 100644 --- a/src/printf.c +++ b/src/printf.c @@ -400,12 +400,13 @@ void sqlite3VXPrintf( nOut = etBUFSIZE; zOut = buf; }else{ - nOut = precision + 10 + precision/3; - zOut = zExtra = sqlite3Malloc( nOut ); + u64 n = (u64)precision + 10 + precision/3; + zOut = zExtra = sqlite3Malloc( n ); if( zOut==0 ){ setStrAccumError(pAccum, STRACCUM_NOMEM); return; } + nOut = (int)n; } bufpt = &zOut[nOut-1]; if( xtype==etORDINAL ){ From 920c83f18fb8cd749774a63ce1a062d07ff56220 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Mar 2017 18:53:32 +0000 Subject: [PATCH 31/60] Fix some problems in fts3 found by address-sanitizer. FossilOrigin-Name: 16a8e84fa7f67a467f824bdd7f72cbd6a6e95dab8cc7aa1e0e751720b98f3e31 --- ext/fts3/fts3.c | 5 +++-- ext/fts3/fts3_unicode.c | 26 +++++++++++++------------- ext/fts3/fts3_unicode2.c | 21 ++++++++++----------- ext/fts3/fts3_write.c | 5 ++++- ext/fts3/unicode/mkunicode.tcl | 2 +- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- 7 files changed, 43 insertions(+), 40 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 8af62cda45..8abc338045 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -349,8 +349,9 @@ int sqlite3Fts3PutVarint(char *p, sqlite_int64 v){ ** Return the number of bytes read, or 0 on error. ** The value is stored in *v. */ -int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){ - const char *pStart = p; +int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){ + const unsigned char *p = (const unsigned char*)pBuf; + const unsigned char *pStart = p; u32 a; u64 b; int shift; diff --git a/ext/fts3/fts3_unicode.c b/ext/fts3/fts3_unicode.c index 94fc27b5b4..dfb2680c50 100644 --- a/ext/fts3/fts3_unicode.c +++ b/ext/fts3/fts3_unicode.c @@ -136,16 +136,16 @@ static int unicodeAddExceptions( ){ const unsigned char *z = (const unsigned char *)zIn; const unsigned char *zTerm = &z[nIn]; - int iCode; + unsigned int iCode; int nEntry = 0; assert( bAlnum==0 || bAlnum==1 ); while( zi; j--) aNew[j] = aNew[j-1]; - aNew[i] = iCode; + aNew[i] = (int)iCode; nNew++; } } @@ -318,7 +318,7 @@ static int unicodeNext( ){ unicode_cursor *pCsr = (unicode_cursor *)pC; unicode_tokenizer *p = ((unicode_tokenizer *)pCsr->base.pTokenizer); - int iCode = 0; + unsigned int iCode = 0; char *zOut; const unsigned char *z = &pCsr->aInput[pCsr->iOff]; const unsigned char *zStart = z; @@ -330,7 +330,7 @@ static int unicodeNext( ** the input. */ while( z=zTerm ) return SQLITE_DONE; @@ -350,7 +350,7 @@ static int unicodeNext( /* Write the folded case of the last character read to the output */ zEnd = z; - iOut = sqlite3FtsUnicodeFold(iCode, p->bRemoveDiacritic); + iOut = sqlite3FtsUnicodeFold((int)iCode, p->bRemoveDiacritic); if( iOut ){ WRITE_UTF8(zOut, iOut); } @@ -358,8 +358,8 @@ static int unicodeNext( /* If the cursor is not at EOF, read the next character */ if( z>=zTerm ) break; READ_UTF8(z, zTerm, iCode); - }while( unicodeIsAlnum(p, iCode) - || sqlite3FtsUnicodeIsdiacritic(iCode) + }while( unicodeIsAlnum(p, (int)iCode) + || sqlite3FtsUnicodeIsdiacritic((int)iCode) ); /* Set the output variables and return. */ diff --git a/ext/fts3/fts3_unicode2.c b/ext/fts3/fts3_unicode2.c index 20b7a25dbf..da7251ed0c 100644 --- a/ext/fts3/fts3_unicode2.c +++ b/ext/fts3/fts3_unicode2.c @@ -127,9 +127,9 @@ int sqlite3FtsUnicodeIsalnum(int c){ 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001, }; - if( c<128 ){ - return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); - }else if( c<(1<<22) ){ + if( (unsigned int)c<128 ){ + return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 ); + }else if( (unsigned int)c<(1<<22) ){ unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; int iRes = 0; int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; @@ -322,16 +322,17 @@ int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){ int ret = c; - assert( c>=0 ); assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 ); if( c<128 ){ if( c>='A' && c<='Z' ) ret = c + ('a' - 'A'); }else if( c<65536 ){ + const struct TableEntry *p; int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; int iLo = 0; int iRes = -1; + assert( c>aEntry[0].iCode ); while( iHi>=iLo ){ int iTest = (iHi + iLo) / 2; int cmp = (c - aEntry[iTest].iCode); @@ -342,14 +343,12 @@ int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){ iHi = iTest-1; } } - assert( iRes<0 || c>=aEntry[iRes].iCode ); - if( iRes>=0 ){ - const struct TableEntry *p = &aEntry[iRes]; - if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){ - ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF; - assert( ret>0 ); - } + assert( iRes>=0 && c>=aEntry[iRes].iCode ); + p = &aEntry[iRes]; + if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){ + ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF; + assert( ret>0 ); } if( bRemoveDiacritic ) ret = remove_diacritic(ret); diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c index 3ff481b0b0..d700c8403c 100644 --- a/ext/fts3/fts3_write.c +++ b/ext/fts3/fts3_write.c @@ -4956,11 +4956,14 @@ int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){ ** Convert the text beginning at *pz into an integer and return ** its value. Advance *pz to point to the first character past ** the integer. +** +** This function used for parameters to merge= and incrmerge= +** commands. */ static int fts3Getint(const char **pz){ const char *z = *pz; int i = 0; - while( (*z)>='0' && (*z)<='9' ) i = 10*i + *(z++) - '0'; + while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0'; *pz = z; return i; } diff --git a/ext/fts3/unicode/mkunicode.tcl b/ext/fts3/unicode/mkunicode.tcl index aafb4e9f9b..de89099122 100644 --- a/ext/fts3/unicode/mkunicode.tcl +++ b/ext/fts3/unicode/mkunicode.tcl @@ -227,7 +227,7 @@ proc print_isalnum {zFunc lRange} { an_print_ascii_bitmap $lRange puts { if( (unsigned int)c<128 ){ - return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); + return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 ); }else if( (unsigned int)c<(1<<22) ){ unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; int iRes = 0; diff --git a/manifest b/manifest index 5c8fe10828..882e3cc273 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sthe\spossibility\sof\ssigned\sinteger\soverflow\swith\soversized\sprecisions\nin\s%d\sconversions\sin\sthe\sprintf()\simplementation. -D 2017-03-20T16:34:18.983 +C Fix\ssome\sproblems\sin\sfts3\sfound\sby\saddress-sanitizer. +D 2017-03-20T18:53:32.346 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -70,7 +70,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 95c7041ea75d82d2d9a4cd058904ba889751f5b8 +F ext/fts3/fts3.c df964dbcc7bb97b8871c53866eb6c4e9c05c0d8af42038fa6439fb411260dd2e F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h eb2502000148e80913b965db3e59f29251266d0a F ext/fts3/fts3_aux.c 9edc3655fcb287f0467d0a4b886a01c6185fe9f1 @@ -86,15 +86,15 @@ F ext/fts3/fts3_tokenize_vtab.c a27593ab19657166f6fa5ec073b678cc29a75860 F ext/fts3/fts3_tokenizer.c a22bf311a71f3efa9d7012d8cc48fc9b0f3dace7 F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3 F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004 -F ext/fts3/fts3_unicode.c a93f5edc0aff44ef8b06d7cb55b52026541ca145 -F ext/fts3/fts3_unicode2.c c3d01968d497bd7001e7dc774ba75b372738c057 -F ext/fts3/fts3_write.c c3863f23b6b4623c8b9d5cf31c12ce4469f78ca9 +F ext/fts3/fts3_unicode.c 525a3bd9a7564603c5c061b7de55403a565307758a94600e8a2f6b00d1c40d9d +F ext/fts3/fts3_unicode2.c cc04fc672bfd42b1e650398cb0bf71f64f9aae032cfe75bbcfe75b9cf966029c +F ext/fts3/fts3_write.c a51d48d646974ee2fb4b17fcd5da0416a5759a32dcacc2cce2ba00d5a767848e F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 F ext/fts3/tool/fts3view.c 202801a2056995b763864d60c2dee744d46f1677 F ext/fts3/unicode/CaseFolding.txt 8c678ca52ecc95e16bc7afc2dbf6fc9ffa05db8c F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 -F ext/fts3/unicode/mkunicode.tcl 2debed3f582d77b3fdd0b8830880250021571fd8 +F ext/fts3/unicode/mkunicode.tcl ab0543a3b2399092ea2dd75df1bef333405b0d7f6b8c4951a0fbb60e780cb69f F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/fts5.h 62f3e33ceeb9a428db139f9c012186b371da1cc7 @@ -1566,7 +1566,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 285005a9bcb210bb2a9aa9fed6a19d4b78641a6e7622d469bd0d2a365b2c0735 -R d28630b090e29d249202016ad6a6d827 -U drh -Z dd88d1a97157edc79245fb3d73eca0b6 +P ef3a7c877a7549b351aafd983cfa96c863eb2641b6218bdd5cb563f659f879d8 +R 646761e50bb7679c40f23d2ddea8c902 +U dan +Z f4376c790f10e78888f80aca2d0f09f6 diff --git a/manifest.uuid b/manifest.uuid index 68447cc550..c4f06f22c9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ef3a7c877a7549b351aafd983cfa96c863eb2641b6218bdd5cb563f659f879d8 \ No newline at end of file +16a8e84fa7f67a467f824bdd7f72cbd6a6e95dab8cc7aa1e0e751720b98f3e31 \ No newline at end of file From 6b904f5e01bb2737b093b154b6ab39b393daa0f6 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Mar 2017 19:26:27 +0000 Subject: [PATCH 32/60] Avoid a technically undefined right-shift of a signed value in rtree.c. FossilOrigin-Name: a144875fe44ff3a30bab299d50b7dbec2ee21f8c73e692a71ee1f7c54b5f0c76 --- ext/rtree/rtree.c | 18 +++++++++--------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 63838a4eef..42f08a9628 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -458,15 +458,15 @@ static i64 readInt64(u8 *p){ memcpy(&x, p, 8); return x; #else - return ( - (((i64)p[0]) << 56) + - (((i64)p[1]) << 48) + - (((i64)p[2]) << 40) + - (((i64)p[3]) << 32) + - (((i64)p[4]) << 24) + - (((i64)p[5]) << 16) + - (((i64)p[6]) << 8) + - (((i64)p[7]) << 0) + return (i64)( + (((u64)p[0]) << 56) + + (((u64)p[1]) << 48) + + (((u64)p[2]) << 40) + + (((u64)p[3]) << 32) + + (((u64)p[4]) << 24) + + (((u64)p[5]) << 16) + + (((u64)p[6]) << 8) + + (((u64)p[7]) << 0) ); #endif } diff --git a/manifest b/manifest index 882e3cc273..180628583d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssome\sproblems\sin\sfts3\sfound\sby\saddress-sanitizer. -D 2017-03-20T18:53:32.346 +C Avoid\sa\stechnically\sundefined\sright-shift\sof\sa\ssigned\svalue\sin\srtree.c. +D 2017-03-20T19:26:27.669 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -270,7 +270,7 @@ F ext/rbu/sqlite3rbu.c 2a89efba9eeba8e6c89a498dc195e8efbdde2694 F ext/rbu/sqlite3rbu.h 6fb6294c34a9ca93b5894a33bca530c6f08decba F ext/rbu/test_rbu.c 5aa22616afac6f71ebd3d9bc9bf1006cfabcca88 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 3f3a595dba485e340246fa2c8ba330a6b9768b00 +F ext/rtree/rtree.c 0acd285bfacc347579a5df9fe947212fb99e2775a40c43f027c3a16936c58e7e F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 42dadfc7b44a436cd74a1bebc0b9b689e4eaf7ec F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1566,7 +1566,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 ef3a7c877a7549b351aafd983cfa96c863eb2641b6218bdd5cb563f659f879d8 -R 646761e50bb7679c40f23d2ddea8c902 +P 16a8e84fa7f67a467f824bdd7f72cbd6a6e95dab8cc7aa1e0e751720b98f3e31 +R 3866887b2e2a6895d2c139049fd577ac U dan -Z f4376c790f10e78888f80aca2d0f09f6 +Z 940954dc69a4e0a1139a0110a41a8583 diff --git a/manifest.uuid b/manifest.uuid index c4f06f22c9..97c8d21348 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -16a8e84fa7f67a467f824bdd7f72cbd6a6e95dab8cc7aa1e0e751720b98f3e31 \ No newline at end of file +a144875fe44ff3a30bab299d50b7dbec2ee21f8c73e692a71ee1f7c54b5f0c76 \ No newline at end of file From 74869e5e52c56bab031e190061afd5d531d88f36 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Mar 2017 19:35:30 +0000 Subject: [PATCH 33/60] Avoid passing NULL as the second argument to memcpy() in fts3. FossilOrigin-Name: 49b93d972de9649abfd6235b65dda1c9d468956671e50704afde6181ffa56dea --- ext/fts3/fts3.c | 4 +++- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 8abc338045..6f059bc95d 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -1398,7 +1398,9 @@ static int fts3InitVtab( char *z; int n = 0; z = (char *)sqlite3Fts3NextToken(aCol[iCol], &n); - memcpy(zCsr, z, n); + if( n>0 ){ + memcpy(zCsr, z, n); + } zCsr[n] = '\0'; sqlite3Fts3Dequote(zCsr); p->azColumn[iCol] = zCsr; diff --git a/manifest b/manifest index 180628583d..9fbd812c57 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sa\stechnically\sundefined\sright-shift\sof\sa\ssigned\svalue\sin\srtree.c. -D 2017-03-20T19:26:27.669 +C Avoid\spassing\sNULL\sas\sthe\ssecond\sargument\sto\smemcpy()\sin\sfts3. +D 2017-03-20T19:35:30.725 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -70,7 +70,7 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c df964dbcc7bb97b8871c53866eb6c4e9c05c0d8af42038fa6439fb411260dd2e +F ext/fts3/fts3.c f0d5de1bc2155ba7cd7c0c1a751779a3a8857fa34d5c12f3b233a23fa2e79ea2 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h eb2502000148e80913b965db3e59f29251266d0a F ext/fts3/fts3_aux.c 9edc3655fcb287f0467d0a4b886a01c6185fe9f1 @@ -1566,7 +1566,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 16a8e84fa7f67a467f824bdd7f72cbd6a6e95dab8cc7aa1e0e751720b98f3e31 -R 3866887b2e2a6895d2c139049fd577ac +P a144875fe44ff3a30bab299d50b7dbec2ee21f8c73e692a71ee1f7c54b5f0c76 +R bd3c42588251ebb6d9905386e3af9ca1 U dan -Z 940954dc69a4e0a1139a0110a41a8583 +Z a06ad4d721634b829ae52c87102c1626 diff --git a/manifest.uuid b/manifest.uuid index 97c8d21348..cd1cb6be7f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a144875fe44ff3a30bab299d50b7dbec2ee21f8c73e692a71ee1f7c54b5f0c76 \ No newline at end of file +49b93d972de9649abfd6235b65dda1c9d468956671e50704afde6181ffa56dea \ No newline at end of file From 16f0582c1b0f059e27df99bf3648d525a3d76dc7 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Mar 2017 20:42:21 +0000 Subject: [PATCH 34/60] Fix the fuzzcheck program so that it can create new databases again. FossilOrigin-Name: 021e8874a7d1bb94debae3ae04f83056a8573148ffc872cd76a186a2d22d0296 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fuzzcheck.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 9fbd812c57..6ce523a998 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\spassing\sNULL\sas\sthe\ssecond\sargument\sto\smemcpy()\sin\sfts3. -D 2017-03-20T19:35:30.725 +C Fix\sthe\sfuzzcheck\sprogram\sso\sthat\sit\scan\screate\snew\sdatabases\sagain. +D 2017-03-20T20:42:21.876 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -833,7 +833,7 @@ F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 F test/fuzz3.test b47377143f0c80f91ed29d722861077ff34415d5 F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 -F test/fuzzcheck.c a87e6067a8d19844bade916841cb76150ecf24a2 +F test/fuzzcheck.c 0cfce51bd5b0b7ab5d2d2ecaf9a82d5962f90852348be6bf5f05a1fb2aaf40e0 F test/fuzzdata1.db 7ee3227bad0e7ccdeb08a9e6822916777073c664 F test/fuzzdata2.db f03a420d3b822cc82e4f894ca957618fbe9c4973 F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -1566,7 +1566,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 a144875fe44ff3a30bab299d50b7dbec2ee21f8c73e692a71ee1f7c54b5f0c76 -R bd3c42588251ebb6d9905386e3af9ca1 -U dan -Z a06ad4d721634b829ae52c87102c1626 +P 49b93d972de9649abfd6235b65dda1c9d468956671e50704afde6181ffa56dea +R 26d368e43476d2b80e7af8c6d59964fd +U drh +Z 95628c590b2b14daadfe6003e34f6d94 diff --git a/manifest.uuid b/manifest.uuid index cd1cb6be7f..db25339f3b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -49b93d972de9649abfd6235b65dda1c9d468956671e50704afde6181ffa56dea \ No newline at end of file +021e8874a7d1bb94debae3ae04f83056a8573148ffc872cd76a186a2d22d0296 \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index 75d519566f..2efe68440a 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -972,7 +972,7 @@ int main(int argc, char **argv){ /* Process each source database separately */ for(iSrcDb=0; iSrcDbzName); + SQLITE_OPEN_READWRITE, pDfltVfs->zName); if( rc ){ fatalError("cannot open source database %s - %s", azSrcDb[iSrcDb], sqlite3_errmsg(db)); @@ -1047,6 +1047,8 @@ int main(int argc, char **argv){ sqlite3_close(db); return 0; } + rc = sqlite3_exec(db, "PRAGMA query_only=1;", 0, 0, 0); + if( rc ) fatalError("cannot set database to query-only"); if( zExpDb!=0 || zExpSql!=0 ){ sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, writefileFunc, 0, 0); From 174f8553068e086e2b7b62bee89d3a8eee6f087a Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Mar 2017 22:58:27 +0000 Subject: [PATCH 35/60] Add the --native-malloc option to fuzzcheck. Fix ossfuzz.c and fuzzcheck.c so that they both deallocate the temp_store_directory before closing. FossilOrigin-Name: 0dd18ec882bb28a87629d6d8dfeb5ea5d82833634b3781a7d14b917272c4dfa0 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/fuzzcheck.c | 22 ++++++++++++++++++---- test/ossfuzz.c | 1 + 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 6ce523a998..e16247c45b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sfuzzcheck\sprogram\sso\sthat\sit\scan\screate\snew\sdatabases\sagain. -D 2017-03-20T20:42:21.876 +C Add\sthe\s--native-malloc\soption\sto\sfuzzcheck.\s\sFix\sossfuzz.c\sand\sfuzzcheck.c\nso\sthat\sthey\sboth\sdeallocate\sthe\stemp_store_directory\sbefore\sclosing. +D 2017-03-20T22:58:27.453 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -833,7 +833,7 @@ F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 F test/fuzz3.test b47377143f0c80f91ed29d722861077ff34415d5 F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 -F test/fuzzcheck.c 0cfce51bd5b0b7ab5d2d2ecaf9a82d5962f90852348be6bf5f05a1fb2aaf40e0 +F test/fuzzcheck.c 2152602232c96d9c790eff3013e1369ce59de3203fa0b75bc613531448454e61 F test/fuzzdata1.db 7ee3227bad0e7ccdeb08a9e6822916777073c664 F test/fuzzdata2.db f03a420d3b822cc82e4f894ca957618fbe9c4973 F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -1009,7 +1009,7 @@ F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3 F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f -F test/ossfuzz.c 8c4d62e156352ecb97eb868fcff20d828a279af67a1c1310779f63464d6f009f +F test/ossfuzz.c f5abed3177f719df3c3109901fcdd26b9fb7f581c8da50fc26f3a81ddfb2c2ae F test/ossshell.c 296ab63067841bd1b1e97b46a0b2af48ee7f69d50d1a723008bee12dd7122622 F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f F test/pager1.test 841868017e9dd3cb459b8d78862091a7d9cff21d @@ -1566,7 +1566,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 49b93d972de9649abfd6235b65dda1c9d468956671e50704afde6181ffa56dea -R 26d368e43476d2b80e7af8c6d59964fd +P 021e8874a7d1bb94debae3ae04f83056a8573148ffc872cd76a186a2d22d0296 +R 694ec38d9cd79a3b1927a92dd170b999 U drh -Z 95628c590b2b14daadfe6003e34f6d94 +Z 6cb1e54838f3a51f8b4c2a137da28ce9 diff --git a/manifest.uuid b/manifest.uuid index db25339f3b..ad7fcf00b1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -021e8874a7d1bb94debae3ae04f83056a8573148ffc872cd76a186a2d22d0296 \ No newline at end of file +0dd18ec882bb28a87629d6d8dfeb5ea5d82833634b3781a7d14b917272c4dfa0 \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index 2efe68440a..fd72273f34 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -805,6 +805,7 @@ static void showHelp(void){ " --load-db ARGS... Load template databases from files into SOURCE_DB\n" " -m TEXT Add a description to the database\n" " --native-vfs Use the native VFS for initially empty database files\n" +" --native-malloc Turn off MEMSYS3/5 and Lookaside\n" " --oss-fuzz Enable OSS-FUZZ testing\n" " --prng-seed N Seed value for the PRGN inside of SQLite\n" " --rebuild Rebuild and vacuum the database file\n" @@ -851,6 +852,7 @@ int main(int argc, char **argv){ void *pHeap = 0; /* Heap for use by SQLite */ int ossFuzz = 0; /* enable OSS-FUZZ testing */ int ossFuzzThisDb = 0; /* ossFuzz value for this particular database */ + int nativeMalloc = 0; /* Turn off MEMSYS3/5 and lookaside if true */ sqlite3_vfs *pDfltVfs; /* The default VFS */ iBegin = timeOfDay(); @@ -911,6 +913,9 @@ int main(int argc, char **argv){ if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]); zMsg = argv[++i]; }else + if( strcmp(z,"native-malloc")==0 ){ + nativeMalloc = 1; + }else if( strcmp(z,"native-vfs")==0 ){ nativeFlag = 1; }else @@ -1013,7 +1018,7 @@ int main(int argc, char **argv){ ossFuzzThisDb = sqlite3_column_int(pStmt,1); if( verboseFlag ) printf("Config: oss-fuzz=%d\n", ossFuzzThisDb); } - if( strcmp(zName, "limit-mem")==0 ){ + if( strcmp(zName, "limit-mem")==0 && !nativeMalloc ){ #if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5) fatalError("the limit-mem option requires -DSQLITE_ENABLE_MEMSYS5" " or _MEMSYS3"); @@ -1143,14 +1148,19 @@ int main(int argc, char **argv){ } /* Limit available memory, if requested */ - if( nMemThisDb>0 ){ - sqlite3_shutdown(); + sqlite3_shutdown(); + if( nMemThisDb>0 && !nativeMalloc ){ pHeap = realloc(pHeap, nMemThisDb); if( pHeap==0 ){ fatalError("failed to allocate %d bytes of heap memory", nMem); } sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMemThisDb, 128); } + + /* Disable lookaside with the --native-malloc option */ + if( nativeMalloc ){ + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); + } /* Reset the in-memory virtual filesystem */ formatVfs(); @@ -1207,9 +1217,13 @@ int main(int argc, char **argv){ runSql(db, (char*)pSql->a, runFlags); }while( timeoutTest ); setAlarm(0); + sqlite3_exec(db, "PRAGMA temp_store_directory=''", 0, 0, 0); sqlite3_close(db); } - if( sqlite3_memory_used()>0 ) fatalError("memory leak"); + if( sqlite3_memory_used()>0 ){ + fatalError("memory leak: %lld bytes outstanding", + sqlite3_memory_used()); + } reformatVfs(); nTest++; g.zTestName[0] = 0; diff --git a/test/ossfuzz.c b/test/ossfuzz.c index 0c2b1320e4..51983548b9 100644 --- a/test/ossfuzz.c +++ b/test/ossfuzz.c @@ -145,6 +145,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Cleanup and return */ sqlite3_free(zErrMsg); sqlite3_free(zSql); + sqlite3_exec(cx.db, "PRAGMA temp_store_directory=''", 0, 0, 0); sqlite3_close(cx.db); if( mDebug & FUZZ_SHOW_MAX_DELAY ){ From a14b7e02e97aecc5712d826e1e7936e6a9219dd2 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 Mar 2017 10:45:38 +0000 Subject: [PATCH 36/60] Do not run sync2.test as part of the "inmemory_journal" permutation. FossilOrigin-Name: 9f680bc7c47f8391adba6ea2b4b2cb6a5a041e22753543d5224da6656c3762fe --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/sync2.test | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e16247c45b..f6d020fb32 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--native-malloc\soption\sto\sfuzzcheck.\s\sFix\sossfuzz.c\sand\sfuzzcheck.c\nso\sthat\sthey\sboth\sdeallocate\sthe\stemp_store_directory\sbefore\sclosing. -D 2017-03-20T22:58:27.453 +C Do\snot\srun\ssync2.test\sas\spart\sof\sthe\s"inmemory_journal"\spermutation. +D 2017-03-21T10:45:38.479 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1165,7 +1165,7 @@ F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test ec94f0556b6488d97f71c79f9061ae08d9ab8f12 F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849 F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529 -F test/sync2.test b028aa9ca0bb4793e86140f777c6b88dcc6741f7a918381662e53bc5f2b97c74 +F test/sync2.test 29af00fe9e468a1e20315d1edced8f8a32ac156df983ae9b53802e7d472675d5 F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 F test/tabfunc01.test 699251cb99651415218a891384510a685c7ab012 @@ -1566,7 +1566,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 021e8874a7d1bb94debae3ae04f83056a8573148ffc872cd76a186a2d22d0296 -R 694ec38d9cd79a3b1927a92dd170b999 -U drh -Z 6cb1e54838f3a51f8b4c2a137da28ce9 +P 0dd18ec882bb28a87629d6d8dfeb5ea5d82833634b3781a7d14b917272c4dfa0 +R 8db91ad0b42e6ccb8a27a4c262ebc723 +U dan +Z 688065de24febc90cf37734d50aa7e01 diff --git a/manifest.uuid b/manifest.uuid index ad7fcf00b1..f7dfbdc10c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0dd18ec882bb28a87629d6d8dfeb5ea5d82833634b3781a7d14b917272c4dfa0 \ No newline at end of file +9f680bc7c47f8391adba6ea2b4b2cb6a5a041e22753543d5224da6656c3762fe \ No newline at end of file diff --git a/test/sync2.test b/test/sync2.test index a88e4bed32..4f6ed7754c 100644 --- a/test/sync2.test +++ b/test/sync2.test @@ -26,7 +26,10 @@ ifcapable !pager_pragmas||!attach { finish_test return } -if {$::tcl_platform(platform)!="unix" || [permutation] == "journaltest"} { +if {$::tcl_platform(platform)!="unix" + || [permutation] == "journaltest" + || [permutation] == "inmemory_journal" +} { finish_test return } From 119fc11eb0b746495df92698fce9696591293519 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 21 Mar 2017 17:19:31 +0000 Subject: [PATCH 37/60] Add short script ext/fts3/tool/fts3cov.sh. To help measure test-coverage of fts3 source code. FossilOrigin-Name: ee9588e873ffebcaa177957950cbb14924e154c391ed7f687116065064ff11b0 --- ext/fts3/tool/fts3cov.sh | 16 ++++++++++++++++ manifest | 13 +++++++------ manifest.uuid | 2 +- test/permutations.test | 34 ++++++++++++++++++---------------- 4 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 ext/fts3/tool/fts3cov.sh diff --git a/ext/fts3/tool/fts3cov.sh b/ext/fts3/tool/fts3cov.sh new file mode 100644 index 0000000000..b1f34dce76 --- /dev/null +++ b/ext/fts3/tool/fts3cov.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +srcdir=`dirname $(dirname $(dirname $(dirname $0)))` +./testfixture $srcdir/test/fts3.test --output=fts3cov-out.txt + +echo "" + +for f in `ls $srcdir/ext/fts3/*.c` +do + f=`basename $f` + echo -ne "$f: " + gcov -b $f | grep Taken | sed 's/Taken at least once://' +done + diff --git a/manifest b/manifest index f6d020fb32..ec8ad84599 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srun\ssync2.test\sas\spart\sof\sthe\s"inmemory_journal"\spermutation. -D 2017-03-21T10:45:38.479 +C Add\sshort\sscript\sext/fts3/tool/fts3cov.sh.\sTo\shelp\smeasure\stest-coverage\sof\nfts3\ssource\scode. +D 2017-03-21T17:19:31.218 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -91,6 +91,7 @@ F ext/fts3/fts3_unicode2.c cc04fc672bfd42b1e650398cb0bf71f64f9aae032cfe75bbcfe75 F ext/fts3/fts3_write.c a51d48d646974ee2fb4b17fcd5da0416a5759a32dcacc2cce2ba00d5a767848e F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9 F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100 +F ext/fts3/tool/fts3cov.sh c331d006359456cf6f8f953e37f2b9c7d568f3863f00bb5f7eb87fea4ac01b73 F ext/fts3/tool/fts3view.c 202801a2056995b763864d60c2dee744d46f1677 F ext/fts3/unicode/CaseFolding.txt 8c678ca52ecc95e16bc7afc2dbf6fc9ffa05db8c F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 @@ -1025,7 +1026,7 @@ F test/parser1.test 391b9bf9a229547a129c61ac345ed1a6f5eb1854 F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442 F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff -F test/permutations.test 46ad98770d3c04ce2418cab2cc527647bfe961a7 +F test/permutations.test af720e7d139e7e5417341d0f0eef2b911c0b067852138dc2f5b6a451b5725118 F test/pragma.test 1e94755164a3a3264cd39836de4bebcb7809e5f8 F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f F test/pragma3.test 14c12bc5352b1e100e0b6b44f371053a81ccf8ed @@ -1566,7 +1567,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 0dd18ec882bb28a87629d6d8dfeb5ea5d82833634b3781a7d14b917272c4dfa0 -R 8db91ad0b42e6ccb8a27a4c262ebc723 +P 9f680bc7c47f8391adba6ea2b4b2cb6a5a041e22753543d5224da6656c3762fe +R 6048d4479132e9b80b95aca588407d4c U dan -Z 688065de24febc90cf37734d50aa7e01 +Z d545083811aa9af855b84bbadd9a61dc diff --git a/manifest.uuid b/manifest.uuid index f7dfbdc10c..c60120ecbc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f680bc7c47f8391adba6ea2b4b2cb6a5a041e22753543d5224da6656c3762fe \ No newline at end of file +ee9588e873ffebcaa177957950cbb14924e154c391ed7f687116065064ff11b0 \ No newline at end of file diff --git a/test/permutations.test b/test/permutations.test index 7f81dcbb27..628e7ba44e 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -247,22 +247,24 @@ test_suite "threads" -prefix "" -description { test_suite "fts3" -prefix "" -description { All FTS3 tests except fts3rnd.test. } -files { - fts3aa.test fts3ab.test fts3ac.test fts3ad.test fts3ae.test - fts3af.test fts3ag.test fts3ah.test fts3ai.test fts3aj.test - fts3ak.test fts3al.test fts3am.test fts3an.test fts3ao.test - fts3atoken.test fts3b.test fts3c.test fts3cov.test fts3d.test - fts3defer.test fts3defer2.test fts3e.test fts3expr.test fts3expr2.test - fts3expr3.test - fts3near.test fts3query.test fts3shared.test fts3snippet.test - fts3sort.test - fts3fault.test fts3malloc.test fts3matchinfo.test - fts3aux1.test fts3comp1.test fts3auto.test - fts4aa.test fts4content.test - fts3conf.test fts3prefix.test fts3fault2.test fts3corrupt.test - fts3corrupt2.test fts3first.test fts4langid.test fts4merge.test - fts4check.test fts4unicode.test fts4noti.test - fts3varint.test - fts4growth.test fts4growth2.test + fts3aa.test fts3ab.test fts3ac.test fts3ad.test + fts3ae.test fts3af.test fts3ag.test fts3ah.test + fts3ai.test fts3aj.test fts3ak.test fts3al.test + fts3am.test fts3an.test fts3ao.test fts3atoken.test + fts3auto.test fts3aux1.test fts3aux2.test fts3b.test + fts3comp1.test fts3conf.test fts3corrupt2.test fts3corrupt.test + fts3cov.test fts3c.test fts3defer2.test fts3defer3.test + fts3defer.test fts3drop.test fts3d.test fts3e.test + fts3expr2.test fts3expr3.test fts3expr4.test fts3expr5.test + fts3expr.test fts3fault2.test fts3fault.test fts3first.test + fts3join.test fts3malloc.test fts3matchinfo.test fts3near.test + fts3offsets.test fts3prefix2.test fts3prefix.test fts3query.test + fts3shared.test fts3snippet.test fts3sort.test fts3tok1.test + fts3tok_err.test fts3varint.test fts4aa.test fts4check.test + fts4content.test fts4docid.test fts4growth2.test fts4growth.test + fts4incr.test fts4langid.test fts4lastrowid.test fts4merge2.test + fts4merge4.test fts4merge.test fts4noti.test fts4onepass.test + fts4opt.test fts4unicode.test } test_suite "fts5" -prefix "" -description { From 49297c86d2f9db1944fd84d00f5cfbfa56fdb1bf Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Mar 2017 18:56:52 +0000 Subject: [PATCH 38/60] Fix an incorrect assert in the ANALYZE logic for STAT4 on WITHOUT ROWID tables. FossilOrigin-Name: ad741976c8c29bcc94f9ea9ed7deb580bb00c8a81d1a7fba1a4e03849728433d --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/analyze.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index ec8ad84599..75a4357e21 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sshort\sscript\sext/fts3/tool/fts3cov.sh.\sTo\shelp\smeasure\stest-coverage\sof\nfts3\ssource\scode. -D 2017-03-21T17:19:31.218 +C Fix\san\sincorrect\sassert\sin\sthe\sANALYZE\slogic\sfor\sSTAT4\son\sWITHOUT\sROWID\ntables. +D 2017-03-21T18:56:52.218 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -338,7 +338,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 3b23977620ce9662ac54443f65b87ba996e36121 -F src/analyze.c 6d8234916c29be943e6ea28b5bef67dff98d9905 +F src/analyze.c 0d0ccf7520a201d8747ea2f02c92c26e26f801bc161f714f27b9f7630dde0421 F src/attach.c 8c476f8bd5d2afe11d925f890d30e527e5b0ce43 F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b @@ -1567,7 +1567,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 9f680bc7c47f8391adba6ea2b4b2cb6a5a041e22753543d5224da6656c3762fe -R 6048d4479132e9b80b95aca588407d4c -U dan -Z d545083811aa9af855b84bbadd9a61dc +P ee9588e873ffebcaa177957950cbb14924e154c391ed7f687116065064ff11b0 +R 5a75fd33dd28f00ec2c9a64301b362e9 +U drh +Z a2519e8e7a444d8c646c2457bd4b758f diff --git a/manifest.uuid b/manifest.uuid index c60120ecbc..e7b01a944f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ee9588e873ffebcaa177957950cbb14924e154c391ed7f687116065064ff11b0 \ No newline at end of file +ad741976c8c29bcc94f9ea9ed7deb580bb00c8a81d1a7fba1a4e03849728433d \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index d1df000943..495cc954ac 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1204,7 +1204,7 @@ static void analyzeOneTable( regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol); for(j=0; jnKeyCol; j++){ k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); - assert( k>=0 && knCol ); + assert( k>=0 && knColumn ); sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j); VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName)); } From 918938f9c205b7fc99b6abd66bfaad1d1895d694 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 21 Mar 2017 20:17:24 +0000 Subject: [PATCH 39/60] New simplified memory initialization for MacOS. FossilOrigin-Name: 055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/mem1.c | 48 +++++++++++++----------------------------------- 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/manifest b/manifest index 75a4357e21..834fc1ba0f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sincorrect\sassert\sin\sthe\sANALYZE\slogic\sfor\sSTAT4\son\sWITHOUT\sROWID\ntables. -D 2017-03-21T18:56:52.218 +C New\ssimplified\smemory\sinitialization\sfor\sMacOS. +D 2017-03-21T20:17:24.121 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -369,7 +369,7 @@ F src/loadext.c a68d8d1d14cf7488bb29dc5311cb1ce9a4404258 F src/main.c 158326243c5ddc8b98a1e983fa488650cf76d760 F src/malloc.c 89c98e3619d362dcffa5c1c639b364b65b474751 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 -F src/mem1.c 79bf195f445bf7e66cadd121849837c3152fbd2f542326bbed3073b6902450c2 +F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 @@ -1567,7 +1567,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 ee9588e873ffebcaa177957950cbb14924e154c391ed7f687116065064ff11b0 -R 5a75fd33dd28f00ec2c9a64301b362e9 +P ad741976c8c29bcc94f9ea9ed7deb580bb00c8a81d1a7fba1a4e03849728433d +R c272fa429602630b64ee19437bd8d503 U drh -Z a2519e8e7a444d8c646c2457bd4b758f +Z a3a73b80a262fb4daeb6a94d5a29c210 diff --git a/manifest.uuid b/manifest.uuid index e7b01a944f..e5a19cd1b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad741976c8c29bcc94f9ea9ed7deb580bb00c8a81d1a7fba1a4e03849728433d \ No newline at end of file +055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 \ No newline at end of file diff --git a/src/mem1.c b/src/mem1.c index 02ed59b4d4..512ab3747f 100644 --- a/src/mem1.c +++ b/src/mem1.c @@ -238,45 +238,23 @@ static int sqlite3MemRoundup(int n){ */ static int sqlite3MemInit(void *NotUsed){ #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) + int cpuCount; + size_t len; if( _sqliteZone_ ){ return SQLITE_OK; } -#ifndef SQLITE_MIGHT_BE_SINGLE_CORE - /* If not compiled with the SQLITE_MIGHT_BE_SINGLE_CORE flag, assume - ** that multiple cores are always available. This is the default case. - */ - _sqliteZone_ = malloc_default_zone(); -#else - /* With the SQLITE_MIGHT_BE_SINGLE_CORE compile-time option, check the - ** number of cores. Different malloc() strategies are used for single-core and - ** multi-core machines. - */ - { - int cpuCount; - size_t len; - len = sizeof(cpuCount); - /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ - sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); - if( cpuCount>1 ){ - /* defer MT decisions to system malloc */ - _sqliteZone_ = malloc_default_zone(); - }else{ - /* only 1 core, use our own zone to contention over global locks, - ** e.g. we have our own dedicated locks */ - bool success; - malloc_zone_t* newzone = malloc_create_zone(4096, 0); - malloc_set_zone_name(newzone, "Sqlite_Heap"); - do{ - success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, - (void * volatile *)&_sqliteZone_); - }while(!_sqliteZone_); - if( !success ){ - /* somebody registered a zone first */ - malloc_destroy_zone(newzone); - } - } + len = sizeof(cpuCount); + /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ + sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); + if( cpuCount>1 ){ + /* defer MT decisions to system malloc */ + _sqliteZone_ = malloc_default_zone(); + }else{ + /* only 1 core, use our own zone to contention over global locks, + ** e.g. we have our own dedicated locks */ + _sqliteZone_ = malloc_create_zone(4096, 0); + malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap"); } -#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */ #endif /* defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */ UNUSED_PARAMETER(NotUsed); return SQLITE_OK; From 701ff6ad2d00fe7f05a4de4e946a2a4893b1c722 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 22 Mar 2017 12:51:34 +0000 Subject: [PATCH 40/60] Fix harmless compiler warnings in the shell. FossilOrigin-Name: a786829783ef65ef270ca360712364cbd47a540d31ed1547d50808aad698bea7 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 834fc1ba0f..560760071c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\ssimplified\smemory\sinitialization\sfor\sMacOS. -D 2017-03-21T20:17:24.121 +C Fix\sharmless\scompiler\swarnings\sin\sthe\sshell. +D 2017-03-22T12:51:34.759 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -402,7 +402,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa -F src/shell.c 77054c021069ec0b65d3d620aab031f97c59b4e42ac7c31544ea68933b581104 +F src/shell.c ce39c4bbbaa02484cb45141034fd363c3bac80a6aa22b0bb3cecea1c6a4c0979 F src/sqlite.h.in 723107d97f2345a7c103632169dc61366121c4ab65d75a7d83c6dc0e5bbe5ca4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1567,7 +1567,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 ad741976c8c29bcc94f9ea9ed7deb580bb00c8a81d1a7fba1a4e03849728433d -R c272fa429602630b64ee19437bd8d503 +P 055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 +R 1f280e53b7c950d24565e873ae0276ec U drh -Z a3a73b80a262fb4daeb6a94d5a29c210 +Z a154993c25ee99ce8fe87b6f82cb272d diff --git a/manifest.uuid b/manifest.uuid index e5a19cd1b9..6c408aa251 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 \ No newline at end of file +a786829783ef65ef270ca360712364cbd47a540d31ed1547d50808aad698bea7 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index e7652f8e67..e71c34e6df 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2926,7 +2926,6 @@ static char **tableColumnList(ShellState *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; @@ -2959,14 +2958,14 @@ static void toggleSelectOrder(sqlite3 *db){ ** the table type ("index" or "table") and SQL to create the table. ** This routine should print text sufficient to recreate the table. */ -static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ +static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ int rc; const char *zTable; const char *zType; const char *zSql; ShellState *p = (ShellState *)pArg; - UNUSED_PARAMETER(azCol); + UNUSED_PARAMETER(azNotUsed); if( nArg!=3 ) return 1; zTable = azArg[0]; zType = azArg[1]; From 633647af75b3e680abe57922a8f1ec495b4150c6 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 22 Mar 2017 21:24:31 +0000 Subject: [PATCH 41/60] Initial implementation of the json_mergepatch(A,B) SQL function. FossilOrigin-Name: a267444039af519f088dd8f8ee33f686cc3071c087677075af2364ebc2587514 --- ext/misc/json1.c | 138 +++++++++++++++++++++++++++++++++++++++------- manifest | 16 ++++-- manifest.uuid | 2 +- test/json104.test | 63 +++++++++++++++++++++ 4 files changed, 192 insertions(+), 27 deletions(-) create mode 100644 test/json104.test diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 3063f9f261..0db946fdc6 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -138,9 +138,10 @@ static const char * const jsonType[] = { #define JNODE_RAW 0x01 /* Content is raw, not JSON encoded */ #define JNODE_ESCAPE 0x02 /* Content is text with \ escapes */ #define JNODE_REMOVE 0x04 /* Do not output */ -#define JNODE_REPLACE 0x08 /* Replace with JsonNode.iVal */ -#define JNODE_APPEND 0x10 /* More ARRAY/OBJECT entries at u.iAppend */ -#define JNODE_LABEL 0x20 /* Is a label of an object */ +#define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */ +#define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */ +#define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */ +#define JNODE_LABEL 0x40 /* Is a label of an object */ /* A single node of parsed JSON @@ -148,12 +149,13 @@ static const char * const jsonType[] = { struct JsonNode { u8 eType; /* One of the JSON_ type values */ u8 jnFlags; /* JNODE flags */ - u8 iVal; /* Replacement value when JNODE_REPLACE */ u32 n; /* Bytes of content, or number of sub-nodes */ union { const char *zJContent; /* Content for INT, REAL, and STRING */ u32 iAppend; /* More terms for ARRAY and OBJECT */ u32 iKey; /* Key for ARRAY objects in json_tree() */ + u32 iReplace; /* Replacement content for JNODE_REPLACE */ + JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */ } u; }; @@ -410,6 +412,13 @@ static void jsonRenderNode( JsonString *pOut, /* Write JSON here */ sqlite3_value **aReplace /* Replacement values */ ){ + if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){ + if( pNode->jnFlags & JNODE_REPLACE ){ + jsonAppendValue(pOut, aReplace[pNode->u.iReplace]); + return; + } + pNode = pNode->u.pPatch; + } switch( pNode->eType ){ default: { assert( pNode->eType==JSON_NULL ); @@ -441,12 +450,7 @@ static void jsonRenderNode( jsonAppendChar(pOut, '['); for(;;){ while( j<=pNode->n ){ - if( pNode[j].jnFlags & (JNODE_REMOVE|JNODE_REPLACE) ){ - if( pNode[j].jnFlags & JNODE_REPLACE ){ - jsonAppendSeparator(pOut); - jsonAppendValue(pOut, aReplace[pNode[j].iVal]); - } - }else{ + if( (pNode[j].jnFlags & JNODE_REMOVE)==0 ){ jsonAppendSeparator(pOut); jsonRenderNode(&pNode[j], pOut, aReplace); } @@ -468,11 +472,7 @@ static void jsonRenderNode( jsonAppendSeparator(pOut); jsonRenderNode(&pNode[j], pOut, aReplace); jsonAppendChar(pOut, ':'); - if( pNode[j+1].jnFlags & JNODE_REPLACE ){ - jsonAppendValue(pOut, aReplace[pNode[j+1].iVal]); - }else{ - jsonRenderNode(&pNode[j+1], pOut, aReplace); - } + jsonRenderNode(&pNode[j+1], pOut, aReplace); } j += 1 + jsonNodeSize(&pNode[j+1]); } @@ -699,7 +699,6 @@ static int jsonParseAddNode( p = &pParse->aNode[pParse->nNode]; p->eType = (u8)eType; p->jnFlags = 0; - p->iVal = 0; p->n = n; p->u.zJContent = zContent; return pParse->nNode++; @@ -1357,6 +1356,104 @@ static void jsonExtractFunc( jsonParseReset(&x); } +/* This is the RFC 7396 MergePatch algorithm. +*/ +static JsonNode *jsonMergePatch( + JsonParse *pParse, /* The JSON parser that contains the TARGET */ + int iTarget, /* Node of the TARGET in pParse */ + JsonNode *pPatch /* The PATCH */ +){ + int i, j; + int iApnd; + JsonNode *pTarget; + if( pPatch->eType!=JSON_OBJECT ){ + return pPatch; + } + assert( iTarget>=0 && iTargetnNode ); + pTarget = &pParse->aNode[iTarget]; + assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); + if( pTarget->eType!=JSON_OBJECT ){ + for(i=2; in; i += jsonNodeSize(&pPatch[i])+1){ + if( pPatch[i].eType==JSON_NULL ){ + pPatch[i-1].jnFlags |= JNODE_REMOVE; + } + } + return pPatch; + } + iApnd = iTarget; + for(i=1; in; i += jsonNodeSize(&pPatch[i+1])+1){ + int nKey; + const char *zKey; + assert( pPatch[i].eType==JSON_STRING ); + assert( pPatch[i].jnFlags & JNODE_LABEL ); + nKey = pPatch[i].n; + zKey = pPatch[i].u.zJContent; + if( (pPatch[i].jnFlags & JNODE_RAW)==0 ){ + assert( nKey>=2 && zKey[0]=='"' && zKey[nKey-1]=='"' ); + nKey -= 2; + zKey ++; + } + for(j=1; jn; j += jsonNodeSize(&pTarget[j+1])+1 ){ + assert( pTarget[j].eType==JSON_STRING ); + assert( pTarget[j].jnFlags & JNODE_LABEL ); + if( jsonLabelCompare(&pTarget[j], zKey, nKey) + && (pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH))==0 + ){ + if( pPatch[i+1].eType==JSON_NULL ){ + pTarget[j+1].jnFlags |= JNODE_REMOVE; + }else{ + JsonNode *pNew = jsonMergePatch(pParse, j+1, &pPatch[i+1]); + if( pNew==0 ) return 0; + pTarget = &pParse->aNode[iTarget]; + if( pNew!=&pTarget[j+1] ){ + pTarget[j+1].u.pPatch = pNew; + pTarget[j+1].jnFlags |= JNODE_PATCH; + } + } + break; + } + } + if( j>=pTarget->n ){ + int iStart, iPatch; + iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0); + jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); + iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); + if( pParse->oom ) return 0; + pTarget = &pParse->aNode[iTarget]; + pParse->aNode[iApnd].jnFlags |= JNODE_APPEND; + pParse->aNode[iApnd].u.iAppend = iStart; + iApnd = iStart; + pParse->aNode[iPatch].jnFlags |= JNODE_PATCH; + pParse->aNode[iPatch].u.pPatch = &pPatch[i+1]; + } + } + return pTarget; +} + +/* +** Implementation of the json_mergepatch(JSON1,JSON2) function. Return a JSON +** object that is the result of running the RFC 7396 MergePatch() algorithm +** on the two arguments. +*/ +static void jsonMergePatchFunc( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonParse x; /* The JSON that is being patched */ + JsonParse y; /* The patch */ + + if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; + if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){ + jsonParseReset(&x); + return; + } + jsonReturnJson(jsonMergePatch(&x, 0, y.aNode), ctx, 0); + jsonParseReset(&x); + jsonParseReset(&y); +} + + /* ** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON ** object that contains all name/value given in arguments. Or if any name @@ -1460,11 +1557,11 @@ static void jsonReplaceFunc( if( x.nErr ) goto replace_err; if( pNode ){ pNode->jnFlags |= (u8)JNODE_REPLACE; - pNode->iVal = (u8)(i+1); + pNode->u.iReplace = i + 1; } } if( x.aNode[0].jnFlags & JNODE_REPLACE ){ - sqlite3_result_value(ctx, argv[x.aNode[0].iVal]); + sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); }else{ jsonReturnJson(x.aNode, ctx, argv); } @@ -1514,11 +1611,11 @@ static void jsonSetFunc( goto jsonSetDone; }else if( pNode && (bApnd || bIsSet) ){ pNode->jnFlags |= (u8)JNODE_REPLACE; - pNode->iVal = (u8)(i+1); + pNode->u.iReplace = i + 1; } } if( x.aNode[0].jnFlags & JNODE_REPLACE ){ - sqlite3_result_value(ctx, argv[x.aNode[0].iVal]); + sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); }else{ jsonReturnJson(x.aNode, ctx, argv); } @@ -2160,6 +2257,7 @@ int sqlite3Json1Init(sqlite3 *db){ { "json_array_length", 2, 0, jsonArrayLengthFunc }, { "json_extract", -1, 0, jsonExtractFunc }, { "json_insert", -1, 0, jsonSetFunc }, + { "json_mergepatch", 2, 0, jsonMergePatchFunc }, { "json_object", -1, 0, jsonObjectFunc }, { "json_quote", 1, 0, jsonQuoteFunc }, { "json_remove", -1, 0, jsonRemoveFunc }, diff --git a/manifest b/manifest index 834fc1ba0f..cceedf00d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\ssimplified\smemory\sinitialization\sfor\sMacOS. -D 2017-03-21T20:17:24.121 +C Initial\simplementation\sof\sthe\sjson_mergepatch(A,B)\sSQL\sfunction. +D 2017-03-22T21:24:31.714 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c 552a7d730863419e05dc947265b28bd411680e2e +F ext/misc/json1.c ca27a98c0a7a90fcbaccd3157204e19afc7eec0ba3f4c08ed06bb638b773f523 F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -913,6 +913,7 @@ F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test c0897616f32d95431f37fd291cb78742181980ac F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 +F test/json104.test 83fd7a15eadb0cde34a37200842318d1cd98abe908e2847fb93d337d969815cc F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c b9a9822dda05a1aa481215a52e2fc93cd8b22ee5 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -1567,7 +1568,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 ad741976c8c29bcc94f9ea9ed7deb580bb00c8a81d1a7fba1a4e03849728433d -R c272fa429602630b64ee19437bd8d503 +P 055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 +R 1d5a57aea0e07c508840a776caf26b14 +T *branch * json_mergepatch +T *sym-json_mergepatch * +T -sym-trunk * U drh -Z a3a73b80a262fb4daeb6a94d5a29c210 +Z 2961dcef6bde9e861663934a25c90d24 diff --git a/manifest.uuid b/manifest.uuid index e5a19cd1b9..980cac0acf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 \ No newline at end of file +a267444039af519f088dd8f8ee33f686cc3071c087677075af2364ebc2587514 \ No newline at end of file diff --git a/test/json104.test b/test/json104.test new file mode 100644 index 0000000000..fc2e0e38b4 --- /dev/null +++ b/test/json104.test @@ -0,0 +1,63 @@ +# 2017-03-22 +# +# 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 tests for json_mergepatch(A,B) SQL function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !json1 { + finish_test + return +} + +# This is the example from pages 2 and 3 of RFC-7396 +do_execsql_test json104-100 { + SELECT json_mergepatch( + json('{ + "a": "b", + "c": { + "d": "e", + "f": "g" + } + }'), + json('{ + "a":"z", + "c": { + "f": null + } + }')); +} {{{"a":"z","c":{"d":"e"}}}} + + +# This is the example from pages 4 and 5 of RFC-7396 +do_execsql_test json104-110 { + SELECT json_mergepatch( + json('{ + "title": "Goodbye!", + "author" : { + "givenName" : "John", + "familyName" : "Doe" + }, + "tags":[ "example", "sample" ], + "content": "This will be unchanged" + }'), + json('{ + "title": "Hello!", + "phoneNumber": "+01-123-456-7890", + "author": { + "familyName": null + }, + "tags": [ "example" ] + }')); +} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged",phoneNumber:"+01-123-456-7890"}}} + +finish_test From f07b249f92fb1d0a37b1444657d14ed7042bafa7 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 22 Mar 2017 21:45:20 +0000 Subject: [PATCH 42/60] Change the name of the new function to "json_merge_patch()". FossilOrigin-Name: 53bf70f37bbca319ea35f70849e2a34ae628a504486158fdad5c4bb7431c68e0 --- ext/misc/json1.c | 2 +- manifest | 17 +++++++---------- manifest.uuid | 2 +- test/json104.test | 16 ++++++---------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 0db946fdc6..c037525c45 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -2257,7 +2257,7 @@ int sqlite3Json1Init(sqlite3 *db){ { "json_array_length", 2, 0, jsonArrayLengthFunc }, { "json_extract", -1, 0, jsonExtractFunc }, { "json_insert", -1, 0, jsonSetFunc }, - { "json_mergepatch", 2, 0, jsonMergePatchFunc }, + { "json_merge_patch", 2, 0, jsonMergePatchFunc }, { "json_object", -1, 0, jsonObjectFunc }, { "json_quote", 1, 0, jsonQuoteFunc }, { "json_remove", -1, 0, jsonRemoveFunc }, diff --git a/manifest b/manifest index cceedf00d1..8c6f009d42 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Initial\simplementation\sof\sthe\sjson_mergepatch(A,B)\sSQL\sfunction. -D 2017-03-22T21:24:31.714 +C Change\sthe\sname\sof\sthe\snew\sfunction\sto\s"json_merge_patch()". +D 2017-03-22T21:45:20.759 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c ca27a98c0a7a90fcbaccd3157204e19afc7eec0ba3f4c08ed06bb638b773f523 +F ext/misc/json1.c be1032c54498ae8d884b7c430da876a0f895dfc734ac3255336014ce79e3f219 F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -913,7 +913,7 @@ F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test c0897616f32d95431f37fd291cb78742181980ac F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 -F test/json104.test 83fd7a15eadb0cde34a37200842318d1cd98abe908e2847fb93d337d969815cc +F test/json104.test 66d3dfc9f76e413c7c957d897325b17b9d1bbdf471225310dbf47279e36f1937 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c b9a9822dda05a1aa481215a52e2fc93cd8b22ee5 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -1568,10 +1568,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 055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 -R 1d5a57aea0e07c508840a776caf26b14 -T *branch * json_mergepatch -T *sym-json_mergepatch * -T -sym-trunk * +P a267444039af519f088dd8f8ee33f686cc3071c087677075af2364ebc2587514 +R f0982f12ae9e098efe5bc17c4edc8338 U drh -Z 2961dcef6bde9e861663934a25c90d24 +Z 17fdf70c56513cf2488f301085ed16e1 diff --git a/manifest.uuid b/manifest.uuid index 980cac0acf..ea9e24d51d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a267444039af519f088dd8f8ee33f686cc3071c087677075af2364ebc2587514 \ No newline at end of file +53bf70f37bbca319ea35f70849e2a34ae628a504486158fdad5c4bb7431c68e0 \ No newline at end of file diff --git a/test/json104.test b/test/json104.test index fc2e0e38b4..be041c5da8 100644 --- a/test/json104.test +++ b/test/json104.test @@ -21,27 +21,24 @@ ifcapable !json1 { # This is the example from pages 2 and 3 of RFC-7396 do_execsql_test json104-100 { - SELECT json_mergepatch( - json('{ + SELECT json_merge_patch('{ "a": "b", "c": { "d": "e", "f": "g" } - }'), - json('{ + }','{ "a":"z", "c": { "f": null } - }')); + }'); } {{{"a":"z","c":{"d":"e"}}}} # This is the example from pages 4 and 5 of RFC-7396 do_execsql_test json104-110 { - SELECT json_mergepatch( - json('{ + SELECT json_merge_patch('{ "title": "Goodbye!", "author" : { "givenName" : "John", @@ -49,15 +46,14 @@ do_execsql_test json104-110 { }, "tags":[ "example", "sample" ], "content": "This will be unchanged" - }'), - json('{ + }','{ "title": "Hello!", "phoneNumber": "+01-123-456-7890", "author": { "familyName": null }, "tags": [ "example" ] - }')); + }'); } {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged",phoneNumber:"+01-123-456-7890"}}} finish_test From bb7aa2d85e684d0db13c93c1e6dbb0e2f3bfb1ab Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 23 Mar 2017 00:13:52 +0000 Subject: [PATCH 43/60] Various fixes to the json_merge_patch() function. FossilOrigin-Name: f49fd2554b0723eb7cf2fd765d655c6820833ee7e5f7d7629d98c27a6fffa1d9 --- ext/misc/json1.c | 39 ++++++++++++++++++++++----------------- manifest | 14 +++++++------- manifest.uuid | 2 +- test/json104.test | 9 ++++++++- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index c037525c45..f03bdc6652 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1364,7 +1364,7 @@ static JsonNode *jsonMergePatch( JsonNode *pPatch /* The PATCH */ ){ int i, j; - int iApnd; + int iRoot; JsonNode *pTarget; if( pPatch->eType!=JSON_OBJECT ){ return pPatch; @@ -1373,14 +1373,14 @@ static JsonNode *jsonMergePatch( pTarget = &pParse->aNode[iTarget]; assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); if( pTarget->eType!=JSON_OBJECT ){ - for(i=2; in; i += jsonNodeSize(&pPatch[i])+1){ + for(i=2; i<=pPatch->n; i += jsonNodeSize(&pPatch[i])+1){ if( pPatch[i].eType==JSON_NULL ){ - pPatch[i-1].jnFlags |= JNODE_REMOVE; + pPatch[i].jnFlags |= JNODE_REMOVE; } } return pPatch; } - iApnd = iTarget; + iRoot = iTarget; for(i=1; in; i += jsonNodeSize(&pPatch[i+1])+1){ int nKey; const char *zKey; @@ -1388,21 +1388,19 @@ static JsonNode *jsonMergePatch( assert( pPatch[i].jnFlags & JNODE_LABEL ); nKey = pPatch[i].n; zKey = pPatch[i].u.zJContent; - if( (pPatch[i].jnFlags & JNODE_RAW)==0 ){ - assert( nKey>=2 && zKey[0]=='"' && zKey[nKey-1]=='"' ); - nKey -= 2; - zKey ++; - } + assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); for(j=1; jn; j += jsonNodeSize(&pTarget[j+1])+1 ){ assert( pTarget[j].eType==JSON_STRING ); assert( pTarget[j].jnFlags & JNODE_LABEL ); - if( jsonLabelCompare(&pTarget[j], zKey, nKey) - && (pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH))==0 + assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); + if( (pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH))==0 + && pTarget[j].n==nKey + && strncmp(pTarget[j].u.zJContent, zKey, nKey)==0 ){ if( pPatch[i+1].eType==JSON_NULL ){ pTarget[j+1].jnFlags |= JNODE_REMOVE; }else{ - JsonNode *pNew = jsonMergePatch(pParse, j+1, &pPatch[i+1]); + JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]); if( pNew==0 ) return 0; pTarget = &pParse->aNode[iTarget]; if( pNew!=&pTarget[j+1] ){ @@ -1413,16 +1411,16 @@ static JsonNode *jsonMergePatch( break; } } - if( j>=pTarget->n ){ + if( j>=pTarget->n && pPatch[i+1].eType!=JSON_NULL ){ int iStart, iPatch; iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0); jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); if( pParse->oom ) return 0; pTarget = &pParse->aNode[iTarget]; - pParse->aNode[iApnd].jnFlags |= JNODE_APPEND; - pParse->aNode[iApnd].u.iAppend = iStart; - iApnd = iStart; + pParse->aNode[iRoot].jnFlags |= JNODE_APPEND; + pParse->aNode[iRoot].u.iAppend = iStart - iRoot; + iRoot = iStart; pParse->aNode[iPatch].jnFlags |= JNODE_PATCH; pParse->aNode[iPatch].u.pPatch = &pPatch[i+1]; } @@ -1442,13 +1440,20 @@ static void jsonMergePatchFunc( ){ JsonParse x; /* The JSON that is being patched */ JsonParse y; /* The patch */ + JsonNode *pResult; /* The result of the merge */ if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){ jsonParseReset(&x); return; } - jsonReturnJson(jsonMergePatch(&x, 0, y.aNode), ctx, 0); + pResult = jsonMergePatch(&x, 0, y.aNode); + assert( pResult!=0 || x.oom ); + if( pResult ){ + jsonReturnJson(pResult, ctx, 0); + }else{ + sqlite3_result_error_nomem(ctx); + } jsonParseReset(&x); jsonParseReset(&y); } diff --git a/manifest b/manifest index 8c6f009d42..31881bdb35 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\sthe\snew\sfunction\sto\s"json_merge_patch()". -D 2017-03-22T21:45:20.759 +C Various\sfixes\sto\sthe\sjson_merge_patch()\sfunction. +D 2017-03-23T00:13:52.903 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c be1032c54498ae8d884b7c430da876a0f895dfc734ac3255336014ce79e3f219 +F ext/misc/json1.c 8a8ba23a0715858ff393aa890e379912759712518afa4d28de6308a79287cb61 F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -913,7 +913,7 @@ F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test c0897616f32d95431f37fd291cb78742181980ac F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 -F test/json104.test 66d3dfc9f76e413c7c957d897325b17b9d1bbdf471225310dbf47279e36f1937 +F test/json104.test 9f8358fd4ec94eca27b31d4ad7f75482edf24c865df378e5129c0b3107c9664e F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c b9a9822dda05a1aa481215a52e2fc93cd8b22ee5 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -1568,7 +1568,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 a267444039af519f088dd8f8ee33f686cc3071c087677075af2364ebc2587514 -R f0982f12ae9e098efe5bc17c4edc8338 +P 53bf70f37bbca319ea35f70849e2a34ae628a504486158fdad5c4bb7431c68e0 +R 7c38ec8ac02c81967ed35b7b062ffaf6 U drh -Z 17fdf70c56513cf2488f301085ed16e1 +Z e95ab9d86e57fcad88a27a5fb020f800 diff --git a/manifest.uuid b/manifest.uuid index ea9e24d51d..23d86ab688 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -53bf70f37bbca319ea35f70849e2a34ae628a504486158fdad5c4bb7431c68e0 \ No newline at end of file +f49fd2554b0723eb7cf2fd765d655c6820833ee7e5f7d7629d98c27a6fffa1d9 \ No newline at end of file diff --git a/test/json104.test b/test/json104.test index be041c5da8..b5a45bc525 100644 --- a/test/json104.test +++ b/test/json104.test @@ -54,6 +54,13 @@ do_execsql_test json104-110 { }, "tags": [ "example" ] }'); -} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged",phoneNumber:"+01-123-456-7890"}}} +} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}} + +do_execsql_test json104-200 { + SELECT json_merge_patch('[1,2,3]','{"x":null}'); +} {{{}}} +do_execsql_test json104-210 { + SELECT json_merge_patch('[1,2,3]','{"x":null,"y":1,"z":null}'); +} {{{"y":1}}} finish_test From 0002d246a94f03b7947c0fe4156f2dcc31cd722b Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 23 Mar 2017 00:46:15 +0000 Subject: [PATCH 44/60] Fix harmless compiler warnings in the new json_merge_patch() logic. FossilOrigin-Name: 5d2cf5a2f8afd88d041d89b3936042ce5a43629d23c48738cb2791b24da3e6af --- ext/misc/json1.c | 4 ++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index f03bdc6652..31e03d1e7d 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1363,8 +1363,8 @@ static JsonNode *jsonMergePatch( int iTarget, /* Node of the TARGET in pParse */ JsonNode *pPatch /* The PATCH */ ){ - int i, j; - int iRoot; + u32 i, j; + u32 iRoot; JsonNode *pTarget; if( pPatch->eType!=JSON_OBJECT ){ return pPatch; diff --git a/manifest b/manifest index 31881bdb35..a21f45f4f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Various\sfixes\sto\sthe\sjson_merge_patch()\sfunction. -D 2017-03-23T00:13:52.903 +C Fix\sharmless\scompiler\swarnings\sin\sthe\snew\sjson_merge_patch()\slogic. +D 2017-03-23T00:46:15.319 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c 8a8ba23a0715858ff393aa890e379912759712518afa4d28de6308a79287cb61 +F ext/misc/json1.c bae7cfb49cda81be573fb159919b502a906940ccc1688dbaab33688489c9cf26 F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -1568,7 +1568,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 53bf70f37bbca319ea35f70849e2a34ae628a504486158fdad5c4bb7431c68e0 -R 7c38ec8ac02c81967ed35b7b062ffaf6 +P f49fd2554b0723eb7cf2fd765d655c6820833ee7e5f7d7629d98c27a6fffa1d9 +R b4e56917a91a0ee0d4fc1a8a4b3db16b U drh -Z e95ab9d86e57fcad88a27a5fb020f800 +Z 39d1ac0a1922cab73356f035d8da0baa diff --git a/manifest.uuid b/manifest.uuid index 23d86ab688..19e8a627a7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f49fd2554b0723eb7cf2fd765d655c6820833ee7e5f7d7629d98c27a6fffa1d9 \ No newline at end of file +5d2cf5a2f8afd88d041d89b3936042ce5a43629d23c48738cb2791b24da3e6af \ No newline at end of file From 1fe162fd0ce451dacee29c9d7164415c8815ca7b Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 23 Mar 2017 12:56:44 +0000 Subject: [PATCH 45/60] Avoid redundant edits in the json_merge_patch() function. FossilOrigin-Name: 4a8e6437dd610c5376a07867a73e5a7e2ea90357a018e1788ecce6f4e10bc939 --- ext/misc/json1.c | 6 ++---- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 31e03d1e7d..80b654d68d 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1393,10 +1393,8 @@ static JsonNode *jsonMergePatch( assert( pTarget[j].eType==JSON_STRING ); assert( pTarget[j].jnFlags & JNODE_LABEL ); assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); - if( (pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH))==0 - && pTarget[j].n==nKey - && strncmp(pTarget[j].u.zJContent, zKey, nKey)==0 - ){ + if( pTarget[j].n==nKey && strncmp(pTarget[j].u.zJContent,zKey,nKey)==0 ){ + if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break; if( pPatch[i+1].eType==JSON_NULL ){ pTarget[j+1].jnFlags |= JNODE_REMOVE; }else{ diff --git a/manifest b/manifest index a21f45f4f1..0c77a3ba53 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sthe\snew\sjson_merge_patch()\slogic. -D 2017-03-23T00:46:15.319 +C Avoid\sredundant\sedits\sin\sthe\sjson_merge_patch()\sfunction. +D 2017-03-23T12:56:44.298 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c bae7cfb49cda81be573fb159919b502a906940ccc1688dbaab33688489c9cf26 +F ext/misc/json1.c dbb168b0a7640a896a565c647dcabb7c7d116c9d2b1a23b963b1d177edc0ddba F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -1568,7 +1568,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 f49fd2554b0723eb7cf2fd765d655c6820833ee7e5f7d7629d98c27a6fffa1d9 -R b4e56917a91a0ee0d4fc1a8a4b3db16b +P 5d2cf5a2f8afd88d041d89b3936042ce5a43629d23c48738cb2791b24da3e6af +R 76e620c002fc08a86767847f533fe70a U drh -Z 39d1ac0a1922cab73356f035d8da0baa +Z 538e213b7e95dcafcfcd2e7dd4b1a792 diff --git a/manifest.uuid b/manifest.uuid index 19e8a627a7..da2d4e0201 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d2cf5a2f8afd88d041d89b3936042ce5a43629d23c48738cb2791b24da3e6af \ No newline at end of file +4a8e6437dd610c5376a07867a73e5a7e2ea90357a018e1788ecce6f4e10bc939 \ No newline at end of file From a77edc69eebe610d309f62234f4d5b277a80102a Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 23 Mar 2017 17:03:35 +0000 Subject: [PATCH 46/60] Remove an invalid assert() statement failing when VACUUMing a database that contains an index on a column explicitly declared "COLLATE BINARY". FossilOrigin-Name: 9f2e04d3c3526b5ff60d941aa6d5446f602cab37cb93972937f39eefabd6868d --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/insert.c | 2 -- test/collateB.test | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 560760071c..a838663224 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompiler\swarnings\sin\sthe\sshell. -D 2017-03-22T12:51:34.759 +C Remove\san\sinvalid\sassert()\sstatement\sfailing\swhen\sVACUUMing\sa\sdatabase\sthat\ncontains\san\sindex\son\sa\scolumn\sexplicitly\sdeclared\s"COLLATE\sBINARY". +D 2017-03-23T17:03:35.684 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -363,7 +363,7 @@ F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 3ed64afc49c0a2221e397b9f65d231ffbef506fe +F src/insert.c d4bb3a135948553d18cf992f76f7ed7b18aa0327f250607b5a6671e55d9947d5 F src/legacy.c e88ed13c2d531decde75d42c2e35623fb9ce3cb0 F src/loadext.c a68d8d1d14cf7488bb29dc5311cb1ce9a4404258 F src/main.c 158326243c5ddc8b98a1e983fa488650cf76d760 @@ -597,7 +597,7 @@ F test/collate7.test 8ec29d98f3ee4ccebce6e16ce3863fb6b8c7b868 F test/collate8.test cd9b3d3f999b8520ffaa7cc1647061fc5bab1334 F test/collate9.test 3adcc799229545940df2f25308dd1ad65869145a F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6 -F test/collateB.test 8ec2accd2d7166c1eff0d2a39bc90262c6f89632 +F test/collateB.test 1e68906951b846570f29f20102ed91d29e634854ee47454d725f2151ecac0b95 F test/colmeta.test 2c765ea61ee37bc43bbe6d6047f89004e6508eb1 F test/colname.test 08948a4809d22817e0e5de89c7c0a8bd90cb551b F test/conflict.test 029faa2d81a0d1cafb5f88614beb663d972c01db @@ -1567,7 +1567,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 055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882 -R 1f280e53b7c950d24565e873ae0276ec -U drh -Z a154993c25ee99ce8fe87b6f82cb272d +P a786829783ef65ef270ca360712364cbd47a540d31ed1547d50808aad698bea7 +R 85624f613e7e3af447c83f8947d69a8d +U dan +Z 3c9d547950272a881cd381bfe4f2d9b9 diff --git a/manifest.uuid b/manifest.uuid index 6c408aa251..1f6f43e2c5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a786829783ef65ef270ca360712364cbd47a540d31ed1547d50808aad698bea7 \ No newline at end of file +9f2e04d3c3526b5ff60d941aa6d5446f602cab37cb93972937f39eefabd6868d \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index f1f3807244..a1f5442515 100644 --- a/src/insert.c +++ b/src/insert.c @@ -2227,8 +2227,6 @@ static int xferOptimization( ** sorted order. */ for(i=0; inColumn; i++){ const char *zColl = pSrcIdx->azColl[i]; - assert( sqlite3_stricmp(sqlite3StrBINARY, zColl)!=0 - || sqlite3StrBINARY==zColl ); if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break; } if( i==pSrcIdx->nColumn ){ diff --git a/test/collateB.test b/test/collateB.test index 4815de83ee..3c8d50d8e6 100644 --- a/test/collateB.test +++ b/test/collateB.test @@ -13,6 +13,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix collateB do_execsql_test collateB-1.1 { CREATE TABLE t1(a INTEGER PRIMARY KEY); @@ -60,4 +61,17 @@ do_execsql_test collateB-1.17 { SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a; } {1 11 1 11 |} +#------------------------------------------------------------------------- +# Test an assert() failure that was occuring if an index were created +# on a column explicitly declared "COLLATE binary". +reset_db +do_execsql_test 2.1 { + CREATE TABLE t4(a COLLATE binary); + CREATE INDEX i4 ON t4(a); + INSERT INTO t4 VALUES('one'), ('two'), ('three'); + VACUUM; +} + +integrity_check 2.2 + finish_test From 8fe3e9d882c8e667ac20e3b090687b1fc5c23003 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 23 Mar 2017 17:22:09 +0000 Subject: [PATCH 47/60] Do not run test file autoanalyze1.test if OMIT_VIRTUALTABLE is defined. FossilOrigin-Name: e1d06a573ee56bf6a14e4dc8086d6a4df1464f2914834cf4596a0a406688f608 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/autoanalyze1.test | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index a838663224..24dc30b166 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sinvalid\sassert()\sstatement\sfailing\swhen\sVACUUMing\sa\sdatabase\sthat\ncontains\san\sindex\son\sa\scolumn\sexplicitly\sdeclared\s"COLLATE\sBINARY". -D 2017-03-23T17:03:35.684 +C Do\snot\srun\stest\sfile\sautoanalyze1.test\sif\sOMIT_VIRTUALTABLE\sis\sdefined. +D 2017-03-23T17:22:09.188 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -528,7 +528,7 @@ F test/attachmalloc.test 3a4bfca9545bfe906a8d2e622de10fbac5b711b0 F test/auth.test c6ede04bee65637ff354b43fc1235aa560c0863e F test/auth2.test 9eb7fce9f34bf1f50d3f366fb3e606be5a2000a1 F test/auth3.test 0d48b901cf111c14b4b1b5205c7d28f1a278190f -F test/autoanalyze1.test 1ba80d5e1412d46503566b70741a5eea060da929 +F test/autoanalyze1.test b9cc3f32a990fa56669b668d237c6d53e983554ae80c0604992e18869a0b2dec F test/autoinc.test 6ae8fb69c9f656962464ae4e6667045d0dfc3b46 F test/autoindex1.test 14b63a9f1e405fe6d5bfc8c8d00249c2ebaf13ea F test/autoindex2.test 12ef578928102baaa0dc23ad397601a2f4ecb0df @@ -1567,7 +1567,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 a786829783ef65ef270ca360712364cbd47a540d31ed1547d50808aad698bea7 -R 85624f613e7e3af447c83f8947d69a8d +P 9f2e04d3c3526b5ff60d941aa6d5446f602cab37cb93972937f39eefabd6868d +R c389878b6e059490204890f1ea916f73 U dan -Z 3c9d547950272a881cd381bfe4f2d9b9 +Z b2d2e5c74dc6093684311a4bed08a5d2 diff --git a/manifest.uuid b/manifest.uuid index 1f6f43e2c5..aed4b7d66c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f2e04d3c3526b5ff60d941aa6d5446f602cab37cb93972937f39eefabd6868d \ No newline at end of file +e1d06a573ee56bf6a14e4dc8086d6a4df1464f2914834cf4596a0a406688f608 \ No newline at end of file diff --git a/test/autoanalyze1.test b/test/autoanalyze1.test index 77e767a89e..71e5d6c163 100644 --- a/test/autoanalyze1.test +++ b/test/autoanalyze1.test @@ -29,7 +29,7 @@ source $testdir/tester.tcl # These tests also use "PRAGMA stats" which are only enabled for # debugging builds. # -ifcapable {!debug || !analyze} { +ifcapable {!debug || !analyze || !vtab} { finish_test return } From db528529bf9b1524c5d31c52ee04aaaa6466b0e5 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 23 Mar 2017 19:51:38 +0000 Subject: [PATCH 48/60] Improvement to the amalgamation configure.ac file contributed by Bob Friesenhahn. FossilOrigin-Name: bf28a55d8185e370fea39de297c37387f852f43fac0a316e5900e633f99b367f --- autoconf/configure.ac | 4 ++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/autoconf/configure.ac b/autoconf/configure.ac index b9a11aac8f..5a607de054 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -55,9 +55,9 @@ AS_IF([ test x"$enable_editline" != xno ],[ LIBS="" AC_SEARCH_LIBS([readline],[edit],[ AC_DEFINE([HAVE_EDITLINE],1,Define to use BSD editline) - READLINE_LIBS=$LIBS + READLINE_LIBS="$LIBS -ltinfo" enable_readline=no - ]) + ],[],[-ltinfo]) AS_UNSET(ac_cv_search_readline) LIBS=$sLIBS ]) diff --git a/manifest b/manifest index 24dc30b166..c5b123ea51 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srun\stest\sfile\sautoanalyze1.test\sif\sOMIT_VIRTUALTABLE\sis\sdefined. -D 2017-03-23T17:22:09.188 +C Improvement\sto\sthe\samalgamation\sconfigure.ac\sfile\scontributed\sby\nBob\sFriesenhahn. +D 2017-03-23T19:51:38.579 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -14,7 +14,7 @@ F autoconf/Makefile.am 1a47d071e3d5435f8f7ebff7eb6703848bbd65d4 F autoconf/Makefile.msc 92e3d7fd64dc5c23a23d33824ee4709aaea00a6331c4bb41a1aadcf6600a49f7 F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7 F autoconf/README.txt 4f04b0819303aabaa35fff5f7b257fb0c1ef95f1 -F autoconf/configure.ac cacf2616abf6e4a569bde2ef365c143caeec40bc +F autoconf/configure.ac 2893b823ecc86cea13739f6c8109a41392254d1db08235c5615e0af5722c8578 F autoconf/tea/Makefile.in b438a7020446c8a8156e8d97c8914a04833da6fd F autoconf/tea/README 3e9a3c060f29a44344ab50aec506f4db903fb873 F autoconf/tea/aclocal.m4 52c47aac44ce0ddb1f918b6993e8beb8eee88f43 @@ -1567,7 +1567,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 9f2e04d3c3526b5ff60d941aa6d5446f602cab37cb93972937f39eefabd6868d -R c389878b6e059490204890f1ea916f73 -U dan -Z b2d2e5c74dc6093684311a4bed08a5d2 +P e1d06a573ee56bf6a14e4dc8086d6a4df1464f2914834cf4596a0a406688f608 +R 05b216864be03a3eba3ef1e51323e9ca +U drh +Z 5c18c26b109b1904b072f9a45f7157f5 diff --git a/manifest.uuid b/manifest.uuid index aed4b7d66c..d40ca490c9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e1d06a573ee56bf6a14e4dc8086d6a4df1464f2914834cf4596a0a406688f608 \ No newline at end of file +bf28a55d8185e370fea39de297c37387f852f43fac0a316e5900e633f99b367f \ No newline at end of file From 37f03dfb1f1f0c5668ef9d8ab61352712d368c96 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 23 Mar 2017 20:33:49 +0000 Subject: [PATCH 49/60] Change the name of the json_merge_patch() function to just json_patch(). FossilOrigin-Name: 04d4100445a3373986ee962618bc03ec304f6ba2f867c8e9eee415daffb593fc --- ext/misc/json1.c | 4 ++-- manifest | 14 +++++++------- manifest.uuid | 2 +- test/json104.test | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 80b654d68d..acec87c1b8 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1431,7 +1431,7 @@ static JsonNode *jsonMergePatch( ** object that is the result of running the RFC 7396 MergePatch() algorithm ** on the two arguments. */ -static void jsonMergePatchFunc( +static void jsonPatchFunc( sqlite3_context *ctx, int argc, sqlite3_value **argv @@ -2260,8 +2260,8 @@ int sqlite3Json1Init(sqlite3 *db){ { "json_array_length", 2, 0, jsonArrayLengthFunc }, { "json_extract", -1, 0, jsonExtractFunc }, { "json_insert", -1, 0, jsonSetFunc }, - { "json_merge_patch", 2, 0, jsonMergePatchFunc }, { "json_object", -1, 0, jsonObjectFunc }, + { "json_patch", 2, 0, jsonPatchFunc }, { "json_quote", 1, 0, jsonQuoteFunc }, { "json_remove", -1, 0, jsonRemoveFunc }, { "json_replace", -1, 0, jsonReplaceFunc }, diff --git a/manifest b/manifest index 0c77a3ba53..d5d959a6f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sredundant\sedits\sin\sthe\sjson_merge_patch()\sfunction. -D 2017-03-23T12:56:44.298 +C Change\sthe\sname\sof\sthe\sjson_merge_patch()\sfunction\sto\sjust\sjson_patch(). +D 2017-03-23T20:33:49.228 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c dbb168b0a7640a896a565c647dcabb7c7d116c9d2b1a23b963b1d177edc0ddba +F ext/misc/json1.c c065914b126b5f4696b824286fca153da8035bb8c660a15193ea2711668f1d14 F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -913,7 +913,7 @@ F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test c0897616f32d95431f37fd291cb78742181980ac F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 -F test/json104.test 9f8358fd4ec94eca27b31d4ad7f75482edf24c865df378e5129c0b3107c9664e +F test/json104.test b6808a3efb973235331c274ebe251bfbf75c6fff0ff12956fb9719cc227a9f5b F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c b9a9822dda05a1aa481215a52e2fc93cd8b22ee5 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -1568,7 +1568,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 5d2cf5a2f8afd88d041d89b3936042ce5a43629d23c48738cb2791b24da3e6af -R 76e620c002fc08a86767847f533fe70a +P 4a8e6437dd610c5376a07867a73e5a7e2ea90357a018e1788ecce6f4e10bc939 +R d0e9240b8b29f168e87723d2f33d4c1f U drh -Z 538e213b7e95dcafcfcd2e7dd4b1a792 +Z bc4bcd04349b5b8bc6712e6bdee5b622 diff --git a/manifest.uuid b/manifest.uuid index da2d4e0201..7097a2526e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4a8e6437dd610c5376a07867a73e5a7e2ea90357a018e1788ecce6f4e10bc939 \ No newline at end of file +04d4100445a3373986ee962618bc03ec304f6ba2f867c8e9eee415daffb593fc \ No newline at end of file diff --git a/test/json104.test b/test/json104.test index b5a45bc525..ff17147723 100644 --- a/test/json104.test +++ b/test/json104.test @@ -8,7 +8,7 @@ # May you share freely, never taking more than you give. # #*********************************************************************** -# This file implements tests for json_mergepatch(A,B) SQL function. +# This file implements tests for json_patch(A,B) SQL function. # set testdir [file dirname $argv0] @@ -21,7 +21,7 @@ ifcapable !json1 { # This is the example from pages 2 and 3 of RFC-7396 do_execsql_test json104-100 { - SELECT json_merge_patch('{ + SELECT json_patch('{ "a": "b", "c": { "d": "e", @@ -38,7 +38,7 @@ do_execsql_test json104-100 { # This is the example from pages 4 and 5 of RFC-7396 do_execsql_test json104-110 { - SELECT json_merge_patch('{ + SELECT json_patch('{ "title": "Goodbye!", "author" : { "givenName" : "John", @@ -57,10 +57,10 @@ do_execsql_test json104-110 { } {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}} do_execsql_test json104-200 { - SELECT json_merge_patch('[1,2,3]','{"x":null}'); + SELECT json_patch('[1,2,3]','{"x":null}'); } {{{}}} do_execsql_test json104-210 { - SELECT json_merge_patch('[1,2,3]','{"x":null,"y":1,"z":null}'); + SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}'); } {{{"y":1}}} finish_test From 29c996987114728518feb15903b5366c00023164 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Mar 2017 12:35:17 +0000 Subject: [PATCH 50/60] Fix an error in the new json_patch() routine discovered by Ralf Junker. FossilOrigin-Name: 9d5350418b2f6113e0b50c57e8a872006f27753067baf08ffdfa7943c0c9a148 --- ext/misc/json1.c | 26 +++++++++++++++++++++----- manifest | 15 +++++++-------- manifest.uuid | 2 +- test/json104.test | 10 ++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index acec87c1b8..2689726302 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1164,6 +1164,25 @@ static void jsonWrongNumArgs( sqlite3_free(zMsg); } +/* +** Mark all NULL entries in the Object passed in as JNODE_REMOVE. +*/ +static void jsonRemoveAllNulls(JsonNode *pNode){ + int i, n; + assert( pNode->eType==JSON_OBJECT ); + n = pNode->n; + for(i=2; i<=n; i += jsonNodeSize(&pNode[i])+1){ + switch( pNode[i].eType ){ + case JSON_NULL: + pNode[i].jnFlags |= JNODE_REMOVE; + break; + case JSON_OBJECT: + jsonRemoveAllNulls(&pNode[i]); + break; + } + } +} + /**************************************************************************** ** SQL functions used for testing and debugging @@ -1373,11 +1392,7 @@ static JsonNode *jsonMergePatch( pTarget = &pParse->aNode[iTarget]; assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); if( pTarget->eType!=JSON_OBJECT ){ - for(i=2; i<=pPatch->n; i += jsonNodeSize(&pPatch[i])+1){ - if( pPatch[i].eType==JSON_NULL ){ - pPatch[i].jnFlags |= JNODE_REMOVE; - } - } + jsonRemoveAllNulls(pPatch); return pPatch; } iRoot = iTarget; @@ -1415,6 +1430,7 @@ static JsonNode *jsonMergePatch( jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); if( pParse->oom ) return 0; + jsonRemoveAllNulls(pPatch); pTarget = &pParse->aNode[iTarget]; pParse->aNode[iRoot].jnFlags |= JNODE_APPEND; pParse->aNode[iRoot].u.iAppend = iStart - iRoot; diff --git a/manifest b/manifest index b843ff3c58..b1f0b85dcc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sjson_patch()\sSQL\sfunction\sto\sthe\sJSON1\sextension. -D 2017-03-23T23:44:55.894 +C Fix\san\serror\sin\sthe\snew\sjson_patch()\sroutine\sdiscovered\sby\sRalf\sJunker. +D 2017-03-24T12:35:17.534 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c c065914b126b5f4696b824286fca153da8035bb8c660a15193ea2711668f1d14 +F ext/misc/json1.c 52f93b91b8bbbfcd84dca34be383974137e83a1673c71d5f728b16b68bb57d9c F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -913,7 +913,7 @@ F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test c0897616f32d95431f37fd291cb78742181980ac F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 -F test/json104.test b6808a3efb973235331c274ebe251bfbf75c6fff0ff12956fb9719cc227a9f5b +F test/json104.test 2966101e14463655546eb8f639db25382957e9b7136de717e17db945a6f539fb F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c b9a9822dda05a1aa481215a52e2fc93cd8b22ee5 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -1568,8 +1568,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 bf28a55d8185e370fea39de297c37387f852f43fac0a316e5900e633f99b367f 04d4100445a3373986ee962618bc03ec304f6ba2f867c8e9eee415daffb593fc -R 114c4ffb4ff05c31b0d61e7341b119eb -T +closed 04d4100445a3373986ee962618bc03ec304f6ba2f867c8e9eee415daffb593fc +P 476088482024e411e2549b1697cdaf0124294c79d43f508c71c4eb66906a56fc +R 08d6f399deb89f284d166c511d46a6ea U drh -Z 015dcf3dd857377b8513b610e324274e +Z 437a93d0f27334776c018af18840b42a diff --git a/manifest.uuid b/manifest.uuid index 4f00615e01..4ff617a710 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -476088482024e411e2549b1697cdaf0124294c79d43f508c71c4eb66906a56fc \ No newline at end of file +9d5350418b2f6113e0b50c57e8a872006f27753067baf08ffdfa7943c0c9a148 \ No newline at end of file diff --git a/test/json104.test b/test/json104.test index ff17147723..5d93991eb1 100644 --- a/test/json104.test +++ b/test/json104.test @@ -62,5 +62,15 @@ do_execsql_test json104-200 { do_execsql_test json104-210 { SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}'); } {{{"y":1}}} +do_execsql_test json104-220 { + SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}'); +} {{{"a":{"bb":{}}}}} +do_execsql_test json104-221 { + SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,null,3]}}}'); +} {{{"a":{"bb":{"ccc":[1,null,3]}}}}} +do_execsql_test json104-222 { + SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}'); +} {{{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}}} + finish_test From f9e91972c94e198a5c6406eeccb7068c35779211 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Mar 2017 13:31:47 +0000 Subject: [PATCH 51/60] Add the RFC-7396 Appendix A test cases for json_patch(). FossilOrigin-Name: c5441d2df2526723f72610cc14dd243223663979e67ecdd76fe06fcd366f2b29 --- manifest | 12 +++++------ manifest.uuid | 2 +- test/json104.test | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index b1f0b85dcc..cfdc624046 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\serror\sin\sthe\snew\sjson_patch()\sroutine\sdiscovered\sby\sRalf\sJunker. -D 2017-03-24T12:35:17.534 +C Add\sthe\sRFC-7396\sAppendix\sA\stest\scases\sfor\sjson_patch(). +D 2017-03-24T13:31:47.314 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -913,7 +913,7 @@ F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/json101.test c0897616f32d95431f37fd291cb78742181980ac F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0 -F test/json104.test 2966101e14463655546eb8f639db25382957e9b7136de717e17db945a6f539fb +F test/json104.test 877d5845f6303899b7889ea5dd1bea99076e3100574d5c536082245c5805dcaa F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff F test/kvtest.c b9a9822dda05a1aa481215a52e2fc93cd8b22ee5 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 @@ -1568,7 +1568,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 476088482024e411e2549b1697cdaf0124294c79d43f508c71c4eb66906a56fc -R 08d6f399deb89f284d166c511d46a6ea +P 9d5350418b2f6113e0b50c57e8a872006f27753067baf08ffdfa7943c0c9a148 +R f5d3be53ea90768240f7c6616a0ecd20 U drh -Z 437a93d0f27334776c018af18840b42a +Z c6323f1875b7921e440a4d008ab9c650 diff --git a/manifest.uuid b/manifest.uuid index 4ff617a710..40296ca7c1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d5350418b2f6113e0b50c57e8a872006f27753067baf08ffdfa7943c0c9a148 \ No newline at end of file +c5441d2df2526723f72610cc14dd243223663979e67ecdd76fe06fcd366f2b29 \ No newline at end of file diff --git a/test/json104.test b/test/json104.test index 5d93991eb1..b5313f01b5 100644 --- a/test/json104.test +++ b/test/json104.test @@ -72,5 +72,59 @@ do_execsql_test json104-222 { SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}'); } {{{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}}} +# Example test cases at the end of the RFC-7396 document +do_execsql_test json104-300 { + SELECT json_patch('{"a":"b"}','{"a":"c"}'); +} {{{"a":"c"}}} +do_execsql_test json104-300a { + SELECT coalesce(json_patch(null,'{"a":"c"}'), 'real-null'); +} {{real-null}} +do_execsql_test json104-301 { + SELECT json_patch('{"a":"b"}','{"b":"c"}'); +} {{{"a":"b","b":"c"}}} +do_execsql_test json104-302 { + SELECT json_patch('{"a":"b"}','{"a":null}'); +} {{{}}} +do_execsql_test json104-303 { + SELECT json_patch('{"a":"b","b":"c"}','{"a":null}'); +} {{{"b":"c"}}} +do_execsql_test json104-304 { + SELECT json_patch('{"a":["b"]}','{"a":"c"}'); +} {{{"a":"c"}}} +do_execsql_test json104-305 { + SELECT json_patch('{"a":"c"}','{"a":["b"]}'); +} {{{"a":["b"]}}} +do_execsql_test json104-306 { + SELECT json_patch('{"a":{"b":"c"}}','{"a":{"b":"d","c":null}}'); +} {{{"a":{"b":"d"}}}} +do_execsql_test json104-307 { + SELECT json_patch('{"a":[{"b":"c"}]}','{"a":[1]}'); +} {{{"a":[1]}}} +do_execsql_test json104-308 { + SELECT json_patch('["a","b"]','["c","d"]'); +} {{["c","d"]}} +do_execsql_test json104-309 { + SELECT json_patch('{"a":"b"}','["c"]'); +} {{["c"]}} +do_execsql_test json104-310 { + SELECT json_patch('{"a":"foo"}','null'); +} {{null}} +do_execsql_test json104-310a { + SELECT coalesce(json_patch('{"a":"foo"}',null), 'real-null'); +} {{real-null}} +do_execsql_test json104-311 { + SELECT json_patch('{"a":"foo"}','"bar"'); +} {{"bar"}} +do_execsql_test json104-312 { + SELECT json_patch('{"e":null}','{"a":1}'); +} {{{"e":null,"a":1}}} +do_execsql_test json104-313 { + SELECT json_patch('[1,2]','{"a":"b","c":null}'); +} {{{"a":"b"}}} +do_execsql_test json104-314 { + SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}'); +} {{{"a":{"bb":{}}}}} + + finish_test From ab087d4e67077e80b30caa34bae869af55773647 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Mar 2017 17:59:56 +0000 Subject: [PATCH 52/60] Fix the OP_Once opcode so that it works correctly for recursive triggers. Ticket [06796225f59c057cd120f1]. FossilOrigin-Name: 2556014514f36808e6d18b25722eae0daeeb8fbb5d18af13a9698ea6c6db1679 --- manifest | 17 +++++++++-------- manifest.uuid | 2 +- src/vdbe.c | 40 ++++++++++++++++++++++++++++++--------- src/vdbe.h | 1 + src/vdbeInt.h | 1 + test/triggerG.test | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 test/triggerG.test diff --git a/manifest b/manifest index cfdc624046..f9ac9232e6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sRFC-7396\sAppendix\sA\stest\scases\sfor\sjson_patch(). -D 2017-03-24T13:31:47.314 +C Fix\sthe\sOP_Once\sopcode\sso\sthat\sit\sworks\scorrectly\sfor\srecursive\striggers.\nTicket\s[06796225f59c057cd120f1]. +D 2017-03-24T17:59:56.312 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -468,9 +468,9 @@ F src/update.c 456d4a4656f8a03c2abc88a51b19172197400e58 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c ca8440ede81e155d15cff7c101654f60b55a9ae6 F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 -F src/vdbe.c 89a12451405a17c6e8d39b5826acb6999f1283e4e43d2e83a7ac7c9a7094a86a -F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c -F src/vdbeInt.h 4e4b15b2e1330e1636e4e01974eab2b0b985092f +F src/vdbe.c e59bd3416627d11f76da18ed5a85e93b3c6172892a9d44371d05a7c7183d7b94 +F src/vdbe.h caa5346d52bae2a3c8c1dcfa60a7a4dc878a9e3865cb8239da55808b316c8158 +F src/vdbeInt.h 5db089ce18c4feff8820ec6e4cac2d2c82e03d4b1d96f10a6e43832147b8dffe F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 F src/vdbeaux.c ecd0468611925d218e1eb4b3f538907904b136f0e15e333291a232b521bfcef1 F src/vdbeblob.c 359891617358deefc85bef7bcf787fa6b77facb9 @@ -1360,6 +1360,7 @@ F test/triggerC.test 302d8995f5ffe63bbc15053abb3ef7a39cf5a092 F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650 F test/triggerE.test 15fa63f1097db1f83dd62d121616006978063d1f F test/triggerF.test 55b1eb13433997faac3a4948c1d8252f6c8c636b +F test/triggerG.test 6eb0dbb4ce35df990034e54951e882c69ffbc3462e9c33a021edf66464f8b91b F test/tt3_checkpoint.c 9e75cf7c1c364f52e1c47fd0f14c4340a9db0fe1 F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9 @@ -1568,7 +1569,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 9d5350418b2f6113e0b50c57e8a872006f27753067baf08ffdfa7943c0c9a148 -R f5d3be53ea90768240f7c6616a0ecd20 +P c5441d2df2526723f72610cc14dd243223663979e67ecdd76fe06fcd366f2b29 +R 06e33989e2f9f8999f70d02209e735fb U drh -Z c6323f1875b7921e440a4d008ab9c650 +Z d9ba825914c037a52e49ea53bb54865f diff --git a/manifest.uuid b/manifest.uuid index 40296ca7c1..1ba0445ee1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c5441d2df2526723f72610cc14dd243223663979e67ecdd76fe06fcd366f2b29 \ No newline at end of file +2556014514f36808e6d18b25722eae0daeeb8fbb5d18af13a9698ea6c6db1679 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 93c20c0aaa..5e99366b2d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2332,19 +2332,39 @@ case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */ /* Opcode: Once P1 P2 * * * ** -** If the P1 value is equal to the P1 value on the OP_Init opcode at -** instruction 0, then jump to P2. If the two P1 values differ, then -** set the P1 value on this opcode to equal the P1 value on the OP_Init -** and fall through. +** Fall through to the next instruction the first time this opcode is +** encountered on each invocation of the byte-code program. Jump to P2 +** on the second and all subsequent encounters during the same invocation. +** +** Top-level programs determine first invocation by comparing the P1 +** operand against the P1 operand on the OP_Init opcode at the beginning +** of the program. If the P1 values differ, then fall through and make +** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are +** the same then take the jump. +** +** For subprograms, there is a bitmask in the VdbeFrame that determines +** whether or not the jump should be taken. The bitmask is necessary +** because the self-altering code trick does not work for recursive +** triggers. */ case OP_Once: { /* jump */ + u32 iAddr; /* Address of this instruction */ assert( p->aOp[0].opcode==OP_Init ); - VdbeBranchTaken(p->aOp[0].p1==pOp->p1, 2); - if( p->aOp[0].p1==pOp->p1 ){ - goto jump_to_p2; + if( p->pFrame ){ + iAddr = (int)(pOp - p->aOp); + if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){ + VdbeBranchTaken(1, 2); + p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7); + goto jump_to_p2; + } }else{ - pOp->p1 = p->aOp[0].p1; + if( p->aOp[0].p1==pOp->p1 ){ + VdbeBranchTaken(1, 2); + goto jump_to_p2; + } } + VdbeBranchTaken(0, 2); + pOp->p1 = p->aOp[0].p1; break; } @@ -5870,7 +5890,8 @@ case OP_Program: { /* jump */ if( pProgram->nCsr==0 ) nMem++; nByte = ROUND8(sizeof(VdbeFrame)) + nMem * sizeof(Mem) - + pProgram->nCsr * sizeof(VdbeCursor *); + + pProgram->nCsr * sizeof(VdbeCursor*) + + (pProgram->nOp + 7)/8; pFrame = sqlite3DbMallocZero(db, nByte); if( !pFrame ){ goto no_mem; @@ -5921,6 +5942,7 @@ case OP_Program: { /* jump */ p->nMem = pFrame->nChildMem; p->nCursor = (u16)pFrame->nChildCsr; p->apCsr = (VdbeCursor **)&aMem[p->nMem]; + pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr]; p->aOp = aOp = pProgram->aOp; p->nOp = pProgram->nOp; #ifdef SQLITE_ENABLE_STMT_SCANSTATUS diff --git a/src/vdbe.h b/src/vdbe.h index a35f3be344..be19bc5316 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -87,6 +87,7 @@ struct SubProgram { int nOp; /* Elements in aOp[] */ int nMem; /* Number of memory cells required */ int nCsr; /* Number of cursors required */ + u8 *aOnce; /* Array of OP_Once flags */ void *token; /* id that may be used to recursive triggers */ SubProgram *pNext; /* Next sub-program already visited */ }; diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 989cdfd346..c0435a5a79 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -164,6 +164,7 @@ struct VdbeFrame { i64 *anExec; /* Event counters from parent frame */ Mem *aMem; /* Array of memory cells for parent frame */ VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ + u8 *aOnce; /* Bitmask used by OP_Once */ void *token; /* Copy of SubProgram.token */ i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ AuxData *pAuxData; /* Linked list of auxdata allocations */ diff --git a/test/triggerG.test b/test/triggerG.test new file mode 100644 index 0000000000..9faa898dc3 --- /dev/null +++ b/test/triggerG.test @@ -0,0 +1,47 @@ +# 2017-03-24 +# +# 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix triggerG +ifcapable {!trigger} { + finish_test + return +} + +# Test cases for ticket +# https://www.sqlite.org/src/tktview/06796225f59c057cd120f +# +# The OP_Once opcode was not working correctly for recursive triggers. +# +do_execsql_test 100 { + PRAGMA recursive_triggers = 1; + + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1(a) VALUES(0),(2),(3),(8),(9); + CREATE TABLE t2(b); + CREATE TABLE t3(c); + + CREATE TRIGGER tr AFTER INSERT ON t3 BEGIN + INSERT INTO t3 SELECT new.c+1 WHERE new.c<5; + INSERT INTO t2 SELECT new.c*100+a FROM t1 WHERE a IN (1, 2, 3, 4); + END; + + INSERT INTO t3 VALUES(2); + SELECT c FROM t3 ORDER BY c;; +} {2 3 4 5} +do_execsql_test 110 { + SELECT b FROM t2 ORDER BY b; +} {202 203 302 303 402 403 502 503} + +finish_test From 18333efd51814cecb3af5718abfbd867b10cd6a6 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Mar 2017 18:38:41 +0000 Subject: [PATCH 53/60] Previous check-in was not correct. This is a better fix for the OP_Once problem of ticket [06796225f59c057cd120f1]. FossilOrigin-Name: 8194dd2814b0b3f8cffbcb16306f55aabf1c1508b9d27fa806f92f0e6ecd7631 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 3 ++- test/triggerG.test | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index f9ac9232e6..e0db435a03 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sOP_Once\sopcode\sso\sthat\sit\sworks\scorrectly\sfor\srecursive\striggers.\nTicket\s[06796225f59c057cd120f1]. -D 2017-03-24T17:59:56.312 +C Previous\scheck-in\swas\snot\scorrect.\s\sThis\sis\sa\sbetter\sfix\sfor\sthe\sOP_Once\nproblem\sof\sticket\s[06796225f59c057cd120f1]. +D 2017-03-24T18:38:41.822 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -468,7 +468,7 @@ F src/update.c 456d4a4656f8a03c2abc88a51b19172197400e58 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c ca8440ede81e155d15cff7c101654f60b55a9ae6 F src/vacuum.c 1fe4555cd8c9b263afb85b5b4ee3a4a4181ad569 -F src/vdbe.c e59bd3416627d11f76da18ed5a85e93b3c6172892a9d44371d05a7c7183d7b94 +F src/vdbe.c f1acf5744cef62cbfd0b503d84289f840b6cdc980ac47b0d9632dfdb89cc79eb F src/vdbe.h caa5346d52bae2a3c8c1dcfa60a7a4dc878a9e3865cb8239da55808b316c8158 F src/vdbeInt.h 5db089ce18c4feff8820ec6e4cac2d2c82e03d4b1d96f10a6e43832147b8dffe F src/vdbeapi.c 5b08d82592bcff4470601fe78aaabebd50837860 @@ -1360,7 +1360,7 @@ F test/triggerC.test 302d8995f5ffe63bbc15053abb3ef7a39cf5a092 F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650 F test/triggerE.test 15fa63f1097db1f83dd62d121616006978063d1f F test/triggerF.test 55b1eb13433997faac3a4948c1d8252f6c8c636b -F test/triggerG.test 6eb0dbb4ce35df990034e54951e882c69ffbc3462e9c33a021edf66464f8b91b +F test/triggerG.test 175cafdc6399d85231a09e82e051b0e45a2fd1f23dd08ae715bc359716149ab6 F test/tt3_checkpoint.c 9e75cf7c1c364f52e1c47fd0f14c4340a9db0fe1 F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9 @@ -1569,7 +1569,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 c5441d2df2526723f72610cc14dd243223663979e67ecdd76fe06fcd366f2b29 -R 06e33989e2f9f8999f70d02209e735fb +P 2556014514f36808e6d18b25722eae0daeeb8fbb5d18af13a9698ea6c6db1679 +R 0d4df4a8a9e2796f99d4dab5fea97642 U drh -Z d9ba825914c037a52e49ea53bb54865f +Z 19353cf9e153b27d983c51cfd380c21a diff --git a/manifest.uuid b/manifest.uuid index 1ba0445ee1..71e1d00f96 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2556014514f36808e6d18b25722eae0daeeb8fbb5d18af13a9698ea6c6db1679 \ No newline at end of file +8194dd2814b0b3f8cffbcb16306f55aabf1c1508b9d27fa806f92f0e6ecd7631 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 5e99366b2d..406394c5be 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2354,9 +2354,9 @@ case OP_Once: { /* jump */ iAddr = (int)(pOp - p->aOp); if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){ VdbeBranchTaken(1, 2); - p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7); goto jump_to_p2; } + p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7); }else{ if( p->aOp[0].p1==pOp->p1 ){ VdbeBranchTaken(1, 2); @@ -5943,6 +5943,7 @@ case OP_Program: { /* jump */ p->nCursor = (u16)pFrame->nChildCsr; p->apCsr = (VdbeCursor **)&aMem[p->nMem]; pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr]; + memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8); p->aOp = aOp = pProgram->aOp; p->nOp = pProgram->nOp; #ifdef SQLITE_ENABLE_STMT_SCANSTATUS diff --git a/test/triggerG.test b/test/triggerG.test index 9faa898dc3..c770b5bd76 100644 --- a/test/triggerG.test +++ b/test/triggerG.test @@ -44,4 +44,22 @@ do_execsql_test 110 { SELECT b FROM t2 ORDER BY b; } {202 203 302 303 402 403 502 503} +do_execsql_test 200 { + DELETE FROM t1; + INSERT INTO t1(a) VALUES(0),(2),(3),(8),(9); + DELETE FROM t2; + DELETE FROM t3; + DROP TRIGGER tr; + CREATE TRIGGER tr AFTER INSERT ON t3 BEGIN + INSERT INTO t3 SELECT new.c+1 WHERE new.c<5; + INSERT INTO t2 SELECT new.c*10000+xx.a*100+yy.a + FROM t1 AS xx, t1 AS yy + WHERE xx.a IN (1,2,3,4) + AND yy.a IN (2,3,4,5); + END; + + INSERT INTO t3 VALUES(2); + SELECT b FROM t2 ORDER BY b; +} {20202 20203 20302 20303 30202 30203 30302 30303 40202 40203 40302 40303 50202 50203 50302 50303} + finish_test From ba7cce317bd8da97f01096fc3f0993d2f5c577f9 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Mar 2017 19:45:05 +0000 Subject: [PATCH 54/60] Fix a harmless compiler warning in the JSON1 extension. FossilOrigin-Name: c2c3dd84534bb5ea81c974847b74a166c9cba1545fc749ce625929f303bf22e4 --- ext/misc/json1.c | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 2689726302..7563229136 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1397,7 +1397,7 @@ static JsonNode *jsonMergePatch( } iRoot = iTarget; for(i=1; in; i += jsonNodeSize(&pPatch[i+1])+1){ - int nKey; + u32 nKey; const char *zKey; assert( pPatch[i].eType==JSON_STRING ); assert( pPatch[i].jnFlags & JNODE_LABEL ); diff --git a/manifest b/manifest index e0db435a03..909b15bb9f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Previous\scheck-in\swas\snot\scorrect.\s\sThis\sis\sa\sbetter\sfix\sfor\sthe\sOP_Once\nproblem\sof\sticket\s[06796225f59c057cd120f1]. -D 2017-03-24T18:38:41.822 +C Fix\sa\sharmless\scompiler\swarning\sin\sthe\sJSON1\sextension. +D 2017-03-24T19:45:05.590 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c 52f93b91b8bbbfcd84dca34be383974137e83a1673c71d5f728b16b68bb57d9c +F ext/misc/json1.c f963c2b86201c4a91a40b8e1a36e9ae8b9787435be09e0a77f4af3366a21b8e5 F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -1569,7 +1569,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 2556014514f36808e6d18b25722eae0daeeb8fbb5d18af13a9698ea6c6db1679 -R 0d4df4a8a9e2796f99d4dab5fea97642 +P 8194dd2814b0b3f8cffbcb16306f55aabf1c1508b9d27fa806f92f0e6ecd7631 +R 62e08e896f8ca109e8d6d3c509082b9a U drh -Z 19353cf9e153b27d983c51cfd380c21a +Z 05f31e3559927efd389ed5e57c4ee57c diff --git a/manifest.uuid b/manifest.uuid index 71e1d00f96..c8b35554c2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8194dd2814b0b3f8cffbcb16306f55aabf1c1508b9d27fa806f92f0e6ecd7631 \ No newline at end of file +c2c3dd84534bb5ea81c974847b74a166c9cba1545fc749ce625929f303bf22e4 \ No newline at end of file From 2fb79e9b046209dd03530c3729fcc999b0ffd639 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 25 Mar 2017 12:08:11 +0000 Subject: [PATCH 55/60] Fix two harmless compiler warnings. FossilOrigin-Name: 32be9c3faaafd736da3f49d475dc9279af4e4ba38070b60033d898345080acf0 --- ext/misc/json1.c | 1 + manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 7563229136..bad5cd9b53 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1456,6 +1456,7 @@ static void jsonPatchFunc( JsonParse y; /* The patch */ JsonNode *pResult; /* The result of the merge */ + UNUSED_PARAM(argc); if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){ jsonParseReset(&x); diff --git a/manifest b/manifest index 909b15bb9f..2808a2dabb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning\sin\sthe\sJSON1\sextension. -D 2017-03-24T19:45:05.590 +C Fix\stwo\sharmless\scompiler\swarnings. +D 2017-03-25T12:08:11.283 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -218,7 +218,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25 F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c -F ext/misc/json1.c f963c2b86201c4a91a40b8e1a36e9ae8b9787435be09e0a77f4af3366a21b8e5 +F ext/misc/json1.c 92b9e404bd79cc76d3ef2b3a9e37bf775700f7d645466fd41d2e8742e3fa16fb F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e @@ -402,7 +402,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa -F src/shell.c ce39c4bbbaa02484cb45141034fd363c3bac80a6aa22b0bb3cecea1c6a4c0979 +F src/shell.c 042b74d5ad2fd38a7f0c2c0d13f77740f25fba5d33468e75d4648f865ffed4a5 F src/sqlite.h.in 723107d97f2345a7c103632169dc61366121c4ab65d75a7d83c6dc0e5bbe5ca4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1569,7 +1569,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 8194dd2814b0b3f8cffbcb16306f55aabf1c1508b9d27fa806f92f0e6ecd7631 -R 62e08e896f8ca109e8d6d3c509082b9a +P c2c3dd84534bb5ea81c974847b74a166c9cba1545fc749ce625929f303bf22e4 +R 00c481e82c70ac112e4dd5eb0771ef19 U drh -Z 05f31e3559927efd389ed5e57c4ee57c +Z 8a616016b0f4c387418de171c88a7e3f diff --git a/manifest.uuid b/manifest.uuid index c8b35554c2..0fe8e18ce7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c2c3dd84534bb5ea81c974847b74a166c9cba1545fc749ce625929f303bf22e4 \ No newline at end of file +32be9c3faaafd736da3f49d475dc9279af4e4ba38070b60033d898345080acf0 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index e71c34e6df..456fde5fbe 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2085,6 +2085,7 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){ static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){ ShellText *p = (ShellText*)pArg; int i; + UNUSED_PARAMETER(az); if( p->n ) appendText(p, "|", 0); for(i=0; i Date: Sat, 25 Mar 2017 18:03:26 +0000 Subject: [PATCH 56/60] Make the default value for SQLITE_DEFAULT_SYNCHRONOUS a simple integer literal, so that it does not show up goofy in the output of "PRAGMA compile_options;". FossilOrigin-Name: 833ab3212addc340ca8004e8d6a06cc5e51bf256f43dc73d87fbe67518a4891b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqliteInt.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2808a2dabb..67eade98ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stwo\sharmless\scompiler\swarnings. -D 2017-03-25T12:08:11.283 +C Make\sthe\sdefault\svalue\sfor\sSQLITE_DEFAULT_SYNCHRONOUS\sa\ssimple\sinteger\nliteral,\sso\sthat\sit\sdoes\snot\sshow\sup\sgoofy\sin\sthe\soutput\sof\n"PRAGMA\scompile_options;". +D 2017-03-25T18:03:26.758 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -406,7 +406,7 @@ F src/shell.c 042b74d5ad2fd38a7f0c2c0d13f77740f25fba5d33468e75d4648f865ffed4a5 F src/sqlite.h.in 723107d97f2345a7c103632169dc61366121c4ab65d75a7d83c6dc0e5bbe5ca4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae -F src/sqliteInt.h df268ce1d04df042cf43b557d2309eb0b71e86c4 +F src/sqliteInt.h a530e5baf5e559154d5c2e5cc57471bc780a7af4cd0a5d72750b1d850fef1e22 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1569,7 +1569,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 c2c3dd84534bb5ea81c974847b74a166c9cba1545fc749ce625929f303bf22e4 -R 00c481e82c70ac112e4dd5eb0771ef19 +P 32be9c3faaafd736da3f49d475dc9279af4e4ba38070b60033d898345080acf0 +R f2f2293b380c103d1313beba2f4189cc U drh -Z 8a616016b0f4c387418de171c88a7e3f +Z 533fb94c090ecb58ff1b57331e8e6d3d diff --git a/manifest.uuid b/manifest.uuid index 0fe8e18ce7..b258a1fad8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -32be9c3faaafd736da3f49d475dc9279af4e4ba38070b60033d898345080acf0 \ No newline at end of file +833ab3212addc340ca8004e8d6a06cc5e51bf256f43dc73d87fbe67518a4891b \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e95d63ec35..271ea9a3ef 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1127,7 +1127,7 @@ typedef int VList; ** and the one-based values are used internally. */ #ifndef SQLITE_DEFAULT_SYNCHRONOUS -# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1) +# define SQLITE_DEFAULT_SYNCHRONOUS 2 #endif #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS From 34ad36bf81d0eae64891cc57ba6aee669321eb58 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 25 Mar 2017 18:15:05 +0000 Subject: [PATCH 57/60] Disable the new --preserve-rowids option on the CLI ".dump" command if compiled with SQLITE_OMIT_VIRTUALTABLE. FossilOrigin-Name: bd5bbe4eece9051cc8c27d834d22fb243d34f261641984555d02a27b7038d4f6 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 67eade98ba..9626fae018 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\sdefault\svalue\sfor\sSQLITE_DEFAULT_SYNCHRONOUS\sa\ssimple\sinteger\nliteral,\sso\sthat\sit\sdoes\snot\sshow\sup\sgoofy\sin\sthe\soutput\sof\n"PRAGMA\scompile_options;". -D 2017-03-25T18:03:26.758 +C Disable\sthe\snew\s--preserve-rowids\soption\son\sthe\sCLI\s".dump"\scommand\sif\ncompiled\swith\sSQLITE_OMIT_VIRTUALTABLE. +D 2017-03-25T18:15:05.701 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -402,7 +402,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa -F src/shell.c 042b74d5ad2fd38a7f0c2c0d13f77740f25fba5d33468e75d4648f865ffed4a5 +F src/shell.c ceb2b2f1f958ea2c47a7f37972d0f715fbf9dcf6a34a5e98c886b85e3ce6a238 F src/sqlite.h.in 723107d97f2345a7c103632169dc61366121c4ab65d75a7d83c6dc0e5bbe5ca4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1569,7 +1569,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 32be9c3faaafd736da3f49d475dc9279af4e4ba38070b60033d898345080acf0 -R f2f2293b380c103d1313beba2f4189cc +P 833ab3212addc340ca8004e8d6a06cc5e51bf256f43dc73d87fbe67518a4891b +R 5b5c15828c2f2dcb9cc85dadb80ff440 U drh -Z 533fb94c090ecb58ff1b57331e8e6d3d +Z add0f65c09d0d29a2f7424a8d8e55df8 diff --git a/manifest.uuid b/manifest.uuid index b258a1fad8..598099fcb1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -833ab3212addc340ca8004e8d6a06cc5e51bf256f43dc73d87fbe67518a4891b \ No newline at end of file +bd5bbe4eece9051cc8c27d834d22fb243d34f261641984555d02a27b7038d4f6 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 456fde5fbe..1236b12a0e 100644 --- a/src/shell.c +++ b/src/shell.c @@ -4686,7 +4686,14 @@ static int do_meta_command(char *zLine, ShellState *p){ const char *z = azArg[i]+1; if( z[0]=='-' ) z++; if( strcmp(z,"preserve-rowids")==0 ){ +#ifdef SQLITE_OMIT_VIRTUALTABLE + raw_printf(stderr, "The --preserve-rowids option is not compatible" + " with SQLITE_OMIT_VIRTUALTABLE\n"); + rc = 1; + goto meta_command_exit; +#else ShellSetFlag(p, SHFLG_PreserveRowid); +#endif }else { raw_printf(stderr, "Unknown option \"%s\" on \".dump\"\n", azArg[i]); From b9cd86a09140d6c607716dd724721d7dc5b0a218 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 25 Mar 2017 18:31:42 +0000 Subject: [PATCH 58/60] Do not run tests for ".dump --preserve-rowids" when testing SQLITE_OMIT_VIRTUALTABLE builds. FossilOrigin-Name: 55df410b2cd27dc4c7670bcc1196fa3a0e9e601fc24c42e53d6b0a26ee3e4b45 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/shell1.test | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 9626fae018..dbc499389a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\snew\s--preserve-rowids\soption\son\sthe\sCLI\s".dump"\scommand\sif\ncompiled\swith\sSQLITE_OMIT_VIRTUALTABLE. -D 2017-03-25T18:15:05.701 +C Do\snot\srun\stests\sfor\s".dump\s--preserve-rowids"\swhen\stesting\nSQLITE_OMIT_VIRTUALTABLE\sbuilds. +D 2017-03-25T18:31:42.178 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1114,7 +1114,7 @@ F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/shared_err.test 2f2aee20db294b9924e81f6ccbe60f19e21e8506 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test bc1ca4161e1f459c9cd412d3f21f4ee635cf2322 +F test/shell1.test 50226a3a66bbd42a902e9f7698f768927eb33a56e9cfc55b7c157c38eb3e80ac F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b F test/shell3.test 9b95ba643eaa228376f06a898fb410ee9b6e57c1 F test/shell4.test 89ad573879a745974ff2df20ff97c5d6ffffbd5d @@ -1569,7 +1569,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 833ab3212addc340ca8004e8d6a06cc5e51bf256f43dc73d87fbe67518a4891b -R 5b5c15828c2f2dcb9cc85dadb80ff440 -U drh -Z add0f65c09d0d29a2f7424a8d8e55df8 +P bd5bbe4eece9051cc8c27d834d22fb243d34f261641984555d02a27b7038d4f6 +R 3c7487a050e499b6e6904332fc259f35 +U dan +Z 8bd1e4f61c15057f31029e76e86683dd diff --git a/manifest.uuid b/manifest.uuid index 598099fcb1..7b58a3bd78 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bd5bbe4eece9051cc8c27d834d22fb243d34f261641984555d02a27b7038d4f6 \ No newline at end of file +55df410b2cd27dc4c7670bcc1196fa3a0e9e601fc24c42e53d6b0a26ee3e4b45 \ No newline at end of file diff --git a/test/shell1.test b/test/shell1.test index 7f282292c0..ac3403f810 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -755,6 +755,9 @@ INSERT INTO t3 VALUES(5,'hello'); INSERT INTO t3 VALUES(6,X'807f'); COMMIT;}} + +ifcapable vtab { + # The --preserve-rowids option to .dump # do_test shell1-4.1.1 { @@ -868,6 +871,23 @@ INSERT INTO t1 VALUES(12,'',99); INSERT INTO t1 VALUES(23,1,X'b0b1b2'); COMMIT;}} +} else { + +do_test shell1-4.1.6 { + db close + forcedelete test2.db + sqlite3 db test2.db + db eval { + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(1,null), (2,''), (3,1), + (4,2.25), (5,'hello'), (6,x'807f'); + } + catchcmd test2.db {.dump --preserve-rowids} +} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}} + +} + + # Test the output of ".mode insert" # do_test shell1-4.2.1 { From 0d8d9c9effb312c71998446df64bcc133031acde Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 25 Mar 2017 19:16:41 +0000 Subject: [PATCH 59/60] Add the new sqlite3_set_last_insert_rowid() interface to the extension loader thunk. FossilOrigin-Name: 8469fc0d48d6af0accef9b8a84e08ad2ca32351907510d177b4ca4815c1ea7cb --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/loadext.c | 4 +++- src/sqlite3ext.h | 4 ++++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index dbc499389a..65dae1b276 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srun\stests\sfor\s".dump\s--preserve-rowids"\swhen\stesting\nSQLITE_OMIT_VIRTUALTABLE\sbuilds. -D 2017-03-25T18:31:42.178 +C Add\sthe\snew\ssqlite3_set_last_insert_rowid()\sinterface\sto\sthe\sextension\nloader\sthunk. +D 2017-03-25T19:16:41.259 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -365,7 +365,7 @@ F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c d4bb3a135948553d18cf992f76f7ed7b18aa0327f250607b5a6671e55d9947d5 F src/legacy.c e88ed13c2d531decde75d42c2e35623fb9ce3cb0 -F src/loadext.c a68d8d1d14cf7488bb29dc5311cb1ce9a4404258 +F src/loadext.c a72909474dadce771d3669bf84bf689424f6f87d471fee898589c3ef9b2acfd9 F src/main.c 158326243c5ddc8b98a1e983fa488650cf76d760 F src/malloc.c 89c98e3619d362dcffa5c1c639b364b65b474751 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 @@ -405,7 +405,7 @@ F src/select.c 2496d0cc6368dabe7ad2e4c7f5ed3ad9aa3b4d11cd90f33fa1d1ef72493f43aa F src/shell.c ceb2b2f1f958ea2c47a7f37972d0f715fbf9dcf6a34a5e98c886b85e3ce6a238 F src/sqlite.h.in 723107d97f2345a7c103632169dc61366121c4ab65d75a7d83c6dc0e5bbe5ca4 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 -F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae +F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28 F src/sqliteInt.h a530e5baf5e559154d5c2e5cc57471bc780a7af4cd0a5d72750b1d850fef1e22 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1 @@ -1569,7 +1569,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 bd5bbe4eece9051cc8c27d834d22fb243d34f261641984555d02a27b7038d4f6 -R 3c7487a050e499b6e6904332fc259f35 -U dan -Z 8bd1e4f61c15057f31029e76e86683dd +P 55df410b2cd27dc4c7670bcc1196fa3a0e9e601fc24c42e53d6b0a26ee3e4b45 +R e1b145e92e118b2bc2de7100fb7561b5 +U drh +Z e401f4d2ca1590406e5405bb5cd2850e diff --git a/manifest.uuid b/manifest.uuid index 7b58a3bd78..6ed302dbe3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -55df410b2cd27dc4c7670bcc1196fa3a0e9e601fc24c42e53d6b0a26ee3e4b45 \ No newline at end of file +8469fc0d48d6af0accef9b8a84e08ad2ca32351907510d177b4ca4815c1ea7cb \ No newline at end of file diff --git a/src/loadext.c b/src/loadext.c index 3296be60dd..1fee4260ab 100644 --- a/src/loadext.c +++ b/src/loadext.c @@ -421,7 +421,9 @@ static const sqlite3_api_routines sqlite3Apis = { sqlite3_system_errno, /* Version 3.14.0 and later */ sqlite3_trace_v2, - sqlite3_expanded_sql + sqlite3_expanded_sql, + /* Version 3.18.0 and later */ + sqlite3_set_last_insert_rowid }; /* diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h index ce87e74690..f25084a1f5 100644 --- a/src/sqlite3ext.h +++ b/src/sqlite3ext.h @@ -282,6 +282,8 @@ struct sqlite3_api_routines { /* Version 3.14.0 and later */ int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*); char *(*expanded_sql)(sqlite3_stmt*); + /* Version 3.18.0 and later */ + void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64); }; /* @@ -540,6 +542,8 @@ typedef int (*sqlite3_loadext_entry)( /* Version 3.14.0 and later */ #define sqlite3_trace_v2 sqlite3_api->trace_v2 #define sqlite3_expanded_sql sqlite3_api->expanded_sql +/* Version 3.18.0 and later */ +#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) From fe329a737060c6e9aea2e41f6e3661425b75aa35 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 28 Mar 2017 18:48:43 +0000 Subject: [PATCH 60/60] Version 3.18.0 Release Candidate FossilOrigin-Name: 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37 --- manifest | 11 +++++++---- manifest.uuid | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/manifest b/manifest index 65dae1b276..ca56437574 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\snew\ssqlite3_set_last_insert_rowid()\sinterface\sto\sthe\sextension\nloader\sthunk. -D 2017-03-25T19:16:41.259 +C Version\s3.18.0\sRelease\sCandidate +D 2017-03-28T18:48:43.315 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1faf9f06aadc9284c212dea7bbc7c0dea7e8337f0287c81001eff500912c790a @@ -1569,7 +1569,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 55df410b2cd27dc4c7670bcc1196fa3a0e9e601fc24c42e53d6b0a26ee3e4b45 +P 8469fc0d48d6af0accef9b8a84e08ad2ca32351907510d177b4ca4815c1ea7cb R e1b145e92e118b2bc2de7100fb7561b5 +T *branch * version-3.18 +T *sym-version-3.18 * +T -sym-trunk * U drh -Z e401f4d2ca1590406e5405bb5cd2850e +Z 2998f3cf8a15fbd1f3dc49f1b039f0d5 diff --git a/manifest.uuid b/manifest.uuid index 6ed302dbe3..5619e48c7b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8469fc0d48d6af0accef9b8a84e08ad2ca32351907510d177b4ca4815c1ea7cb \ No newline at end of file +424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37 \ No newline at end of file