/ Check-in [ba8294e2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge the latest trunk fixes and enhancements into the apple-osx branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1:ba8294e2f76a0cfcf48200634e6076a8995024f0
User & Date: drh 2015-02-25 14:09:23
Context
2015-03-09
13:18
Merge recent trunk enhancements into the apple-osx branch. check-in: 5e04eec8 user: drh tags: apple-osx
2015-02-25
14:09
Merge the latest trunk fixes and enhancements into the apple-osx branch. check-in: ba8294e2 user: drh tags: apple-osx
13:48
Add support for the linenoise command-line editing library in shell.c. check-in: 03bbb947 user: drh tags: trunk
2015-02-21
01:03
Merge trunk changes into the apple-osx branch. check-in: 3896e233 user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.msc.

  1532   1532   		$(TOP)\test\wordcount.c $(SQLITE3C)
  1533   1533   
  1534   1534   speedtest1.exe:	$(TOP)\test\speedtest1.c $(SQLITE3C)
  1535   1535   	$(LTLINK) -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \
  1536   1536   		$(TOP)\test\speedtest1.c $(SQLITE3C)
  1537   1537   
  1538   1538   clean:
  1539         -	del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib
  1540         -	del /Q *.cod *.da *.bb *.bbg gmon.out
  1541         -	del /Q sqlite3.h opcodes.c opcodes.h
  1542         -	del /Q lemon.* lempar.c parse.*
  1543         -	del /Q mkkeywordhash.* keywordhash.h
  1544         -	del /Q notasharedlib.*
  1545         -	-rmdir /Q/S .deps
  1546         -	-rmdir /Q/S .libs
  1547         -	-rmdir /Q/S quota2a
  1548         -	-rmdir /Q/S quota2b
  1549         -	-rmdir /Q/S quota2c
  1550         -	-rmdir /Q/S tsrc
  1551         -	del /Q .target_source
  1552         -	del /Q tclsqlite3.exe tclsqlite3.exp
  1553         -	del /Q testloadext.dll testloadext.exp
  1554         -	del /Q testfixture.exe testfixture.exp test.db
  1555         -	del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe
  1556         -	del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe
  1557         -	del /Q wordcount.exe
  1558         -	del /Q sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def
  1559         -	del /Q sqlite3.c sqlite3-*.c
  1560         -	del /Q sqlite3rc.h
  1561         -	del /Q shell.c sqlite3ext.h
  1562         -	del /Q sqlite3_analyzer.exe sqlite3_analyzer.exp sqlite3_analyzer.c
  1563         -	del /Q sqlite-*-output.vsix
  1564         -	del /Q mptester.exe
         1539  +	del /Q *.lo *.ilk *.lib *.obj *.pdb sqlite3.exe libsqlite3.lib 2>NUL
         1540  +	del /Q *.cod *.da *.bb *.bbg gmon.out 2>NUL
         1541  +	del /Q sqlite3.h opcodes.c opcodes.h 2>NUL
         1542  +	del /Q lemon.* lempar.c parse.* 2>NUL
         1543  +	del /Q mkkeywordhash.* keywordhash.h 2>NUL
         1544  +	del /Q notasharedlib.* 2>NUL
         1545  +	-rmdir /Q/S .deps 2>NUL
         1546  +	-rmdir /Q/S .libs 2>NUL
         1547  +	-rmdir /Q/S quota2a 2>NUL
         1548  +	-rmdir /Q/S quota2b 2>NUL
         1549  +	-rmdir /Q/S quota2c 2>NUL
         1550  +	-rmdir /Q/S tsrc 2>NUL
         1551  +	del /Q .target_source 2>NUL
         1552  +	del /Q tclsqlite3.exe tclsqlite3.exp 2>NUL
         1553  +	del /Q testloadext.dll testloadext.exp 2>NUL
         1554  +	del /Q testfixture.exe testfixture.exp test.db 2>NUL
         1555  +	del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe 2>NUL
         1556  +	del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL
         1557  +	del /Q wordcount.exe 2>NUL
         1558  +	del /Q sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def 2>NUL
         1559  +	del /Q sqlite3.c sqlite3-*.c 2>NUL
         1560  +	del /Q sqlite3rc.h 2>NUL
         1561  +	del /Q shell.c sqlite3ext.h 2>NUL
         1562  +	del /Q sqlite3_analyzer.exe sqlite3_analyzer.exp sqlite3_analyzer.c 2>NUL
         1563  +	del /Q sqlite-*-output.vsix 2>NUL
         1564  +	del /Q mptester.exe 2>NUL
  1565   1565   
  1566   1566   # Dynamic link library section.
  1567   1567   #
  1568   1568   dll: sqlite3.dll
  1569   1569   
  1570   1570   sqlite3.def: libsqlite3.lib
  1571   1571   	echo EXPORTS > sqlite3.def
  1572   1572   	dumpbin /all libsqlite3.lib \
  1573   1573   		| $(NAWK) "/ 1 _?sqlite3_/ { sub(/^.* _?/,\"\");print }" \
  1574   1574   		| sort >> sqlite3.def
  1575   1575   
  1576   1576   sqlite3.dll: $(LIBOBJ) $(LIBRESOBJS) sqlite3.def
  1577   1577   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /DEF:sqlite3.def /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)

Changes to src/shell.c.

    55     55   # include <sys/types.h>
    56     56   #endif
    57     57   
    58     58   #if HAVE_READLINE
    59     59   # include <readline/readline.h>
    60     60   # include <readline/history.h>
    61     61   #endif
           62  +
    62     63   #if HAVE_EDITLINE
    63         -# undef HAVE_READLINE
    64         -# define HAVE_READLINE 1
    65     64   # include <editline/readline.h>
    66     65   #endif
    67         -#if !HAVE_READLINE
    68         -# define add_history(X)
    69         -# define read_history(X)
    70         -# define write_history(X)
    71         -# define stifle_history(X)
           66  +
           67  +#if HAVE_EDITLINE || HAVE_READLINE
           68  +
           69  +# define shell_add_history(X) add_history(X)
           70  +# define shell_read_history(X) read_history(X)
           71  +# define shell_write_history(X) write_history(X)
           72  +# define shell_stifle_history(X) stifle_history(X)
           73  +# define shell_readline(X) readline(X)
           74  +
           75  +#elif HAVE_LINENOISE
           76  +
           77  +# include "linenoise.h"
           78  +# define shell_add_history(X) linenoiseHistoryAdd(X)
           79  +# define shell_read_history(X) linenoiseHistoryLoad(X)
           80  +# define shell_write_history(X) linenoiseHistorySave(X)
           81  +# define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
           82  +# define shell_readline(X) linenoise(X)
           83  +
           84  +#else
           85  +
           86  +# define shell_read_history(X) 
           87  +# define shell_write_history(X)
           88  +# define shell_stifle_history(X)
           89  +
           90  +# define SHELL_USE_LOCAL_GETLINE 1
    72     91   #endif
           92  +
    73     93   
    74     94   #if defined(_WIN32) || defined(WIN32)
    75     95   # include <io.h>
    76     96   # include <fcntl.h>
    77     97   #define isatty(h) _isatty(h)
    78     98   #ifndef access
    79     99   # define access(f,m) _access((f),(m))
................................................................................
   447    467   static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
   448    468     char *zPrompt;
   449    469     char *zResult;
   450    470     if( in!=0 ){
   451    471       zResult = local_getline(zPrior, in);
   452    472     }else{
   453    473       zPrompt = isContinuation ? continuePrompt : mainPrompt;
   454         -#if HAVE_READLINE
   455         -    free(zPrior);
   456         -    zResult = readline(zPrompt);
   457         -    if( zResult && *zResult ) add_history(zResult);
   458         -#else
          474  +#if SHELL_USE_LOCAL_GETLINE
   459    475       printf("%s", zPrompt);
   460    476       fflush(stdout);
   461    477       zResult = local_getline(zPrior, stdin);
          478  +#else
          479  +    free(zPrior);
          480  +    zResult = shell_readline(zPrompt);
          481  +    if( zResult && *zResult ) shell_add_history(zResult);
   462    482   #endif
   463    483     }
   464    484     return zResult;
   465    485   }
   466    486   
   467    487   /*
   468    488   ** Shell output mode information from before ".explain on", 
................................................................................
  4632   4652         zHome = find_home_dir();
  4633   4653         if( zHome ){
  4634   4654           nHistory = strlen30(zHome) + 20;
  4635   4655           if( (zHistory = malloc(nHistory))!=0 ){
  4636   4656             sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
  4637   4657           }
  4638   4658         }
  4639         -#if HAVE_READLINE
  4640         -      if( zHistory ) read_history(zHistory);
  4641         -#endif
         4659  +      if( zHistory ) shell_read_history(zHistory);
  4642   4660         rc = process_input(&data, 0);
  4643   4661         if( zHistory ){
  4644         -        stifle_history(100);
  4645         -        write_history(zHistory);
         4662  +        shell_stifle_history(100);
         4663  +        shell_write_history(zHistory);
  4646   4664           free(zHistory);
  4647   4665         }
  4648   4666       }else{
  4649   4667         rc = process_input(&data, stdin);
  4650   4668       }
  4651   4669     }
  4652   4670     set_table_name(&data, 0);
  4653   4671     if( data.db ){
  4654   4672       sqlite3_close(data.db);
  4655   4673     }
  4656   4674     sqlite3_free(data.zFreeOnClose); 
  4657   4675     return rc;
  4658   4676   }

Changes to src/sqlite.h.in.

  2229   2229   void sqlite3_free_table(char **result);
  2230   2230   
  2231   2231   /*
  2232   2232   ** CAPI3REF: Formatted String Printing Functions
  2233   2233   **
  2234   2234   ** These routines are work-alikes of the "printf()" family of functions
  2235   2235   ** from the standard C library.
         2236  +** These routines understand most of the common K&R formatting options,
         2237  +** plus some additional non-standard formats, detailed below.
         2238  +** Note that some of the more obscure formatting options from recent
         2239  +** C-library standards are omitted from this implementation.
  2236   2240   **
  2237   2241   ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2238   2242   ** results into memory obtained from [sqlite3_malloc()].
  2239   2243   ** The strings returned by these two routines should be
  2240   2244   ** released by [sqlite3_free()].  ^Both routines return a
  2241   2245   ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  2242   2246   ** memory to hold the resulting string.
................................................................................
  2261   2265   ** written will be n-1 characters.
  2262   2266   **
  2263   2267   ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2264   2268   **
  2265   2269   ** These routines all implement some additional formatting
  2266   2270   ** options that are useful for constructing SQL statements.
  2267   2271   ** All of the usual printf() formatting options apply.  In addition, there
  2268         -** is are "%q", "%Q", and "%z" options.
         2272  +** is are "%q", "%Q", "%w" and "%z" options.
  2269   2273   **
  2270   2274   ** ^(The %q option works like %s in that it substitutes a nul-terminated
  2271   2275   ** string from the argument list.  But %q also doubles every '\'' character.
  2272   2276   ** %q is designed for use inside a string literal.)^  By doubling each '\''
  2273   2277   ** character it escapes that character and allows it to be inserted into
  2274   2278   ** the string.
  2275   2279   **
................................................................................
  2313   2317   **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  2314   2318   **  sqlite3_exec(db, zSQL, 0, 0, 0);
  2315   2319   **  sqlite3_free(zSQL);
  2316   2320   ** </pre></blockquote>
  2317   2321   **
  2318   2322   ** The code above will render a correct SQL statement in the zSQL
  2319   2323   ** variable even if the zText variable is a NULL pointer.
         2324  +**
         2325  +** ^(The "%w" formatting option is like "%q" except that it expects to
         2326  +** be contained within double-quotes instead of single quotes, and it
         2327  +** escapes the double-quote character instead of the single-quote
         2328  +** character.)^  The "%w" formatting option is intended for safely inserting
         2329  +** table and column names into a constructed SQL statement.
  2320   2330   **
  2321   2331   ** ^(The "%z" formatting option works like "%s" but with the
  2322   2332   ** addition that after the string has been read and copied into
  2323   2333   ** the result, [sqlite3_free()] is called on the input string.)^
  2324   2334   */
  2325   2335   char *sqlite3_mprintf(const char*,...);
  2326   2336   char *sqlite3_vmprintf(const char*, va_list);

Changes to src/where.c.

  1608   1608     ** and used to match WHERE clause constraints */
  1609   1609     nKeyCol = 0;
  1610   1610     pTable = pSrc->pTab;
  1611   1611     pWCEnd = &pWC->a[pWC->nTerm];
  1612   1612     pLoop = pLevel->pWLoop;
  1613   1613     idxCols = 0;
  1614   1614     for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
         1615  +    Expr *pExpr = pTerm->pExpr;
         1616  +    assert( !ExprHasProperty(pExpr, EP_FromJoin)    /* prereq always non-zero */
         1617  +         || pExpr->iRightJoinTable!=pSrc->iCursor   /*   for the right-hand   */
         1618  +         || pLoop->prereq!=0 );                     /*   table of a LEFT JOIN */
  1615   1619       if( pLoop->prereq==0
  1616   1620        && (pTerm->wtFlags & TERM_VIRTUAL)==0
  1617         -     && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
         1621  +     && !ExprHasProperty(pExpr, EP_FromJoin)
         1622  +     && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
  1618   1623         pPartial = sqlite3ExprAnd(pParse->db, pPartial,
  1619         -                                sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
         1624  +                                sqlite3ExprDup(pParse->db, pExpr, 0));
  1620   1625       }
  1621   1626       if( termCanDriveIndex(pTerm, pSrc, notReady) ){
  1622   1627         int iCol = pTerm->u.leftColumn;
  1623   1628         Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
  1624   1629         testcase( iCol==BMS );
  1625   1630         testcase( iCol==BMS-1 );
  1626   1631         if( !sentWarning ){
................................................................................
  4690   4695   /* Check to see if a partial index with pPartIndexWhere can be used
  4691   4696   ** in the current query.  Return true if it can be and false if not.
  4692   4697   */
  4693   4698   static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
  4694   4699     int i;
  4695   4700     WhereTerm *pTerm;
  4696   4701     for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
  4697         -    if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab) ) return 1;
         4702  +    Expr *pExpr = pTerm->pExpr;
         4703  +    if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab) 
         4704  +     && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
         4705  +    ){
         4706  +      return 1;
         4707  +    }
  4698   4708     }
  4699   4709     return 0;
  4700   4710   }
  4701   4711   
  4702   4712   /*
  4703   4713   ** Add all WhereLoop objects for a single table of the join where the table
  4704   4714   ** is idenfied by pBuilder->pNew->iTab.  That table is guaranteed to be

Changes to test/autoindex4.test.

    44     44     CREATE TABLE t3(e,f);
    45     45     INSERT INTO t3 VALUES(123,654),(555,444),(234,987);
    46     46   
    47     47     SELECT (SELECT count(*) FROM t1, t2 WHERE a=e AND x=f), e, f, '|'
    48     48       FROM t3
    49     49      ORDER BY rowid;
    50     50   } {1 123 654 | 0 555 444 | 4 234 987 |}
           51  +
           52  +# Ticket [2326c258d02ead33d]
           53  +# Two joins, one with and the other without an ORDER BY clause.
           54  +# The one without ORDER BY correctly returns two rows of result.
           55  +# The one with ORDER BY returns no rows. 
           56  +#
           57  +do_execsql_test autoindex4-3.0 {
           58  +  CREATE TABLE A(Name text);
           59  +  CREATE TABLE Items(ItemName text , Name text);
           60  +  INSERT INTO Items VALUES('Item1','Parent');
           61  +  INSERT INTO Items VALUES('Item2','Parent');
           62  +  CREATE TABLE B(Name text);
           63  +  
           64  +  SELECT Items.ItemName
           65  +    FROM Items
           66  +      LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy')
           67  +      LEFT JOIN B ON (B.Name = Items.ItemName)
           68  +    WHERE Items.Name = 'Parent'
           69  +    ORDER BY Items.ItemName;
           70  +} {Item1 Item2}
           71  +do_execsql_test autoindex4-3.1 {
           72  +  CREATE INDEX Items_x1 ON Items(ItemName,Name) WHERE ItemName = 'dummy';
           73  +  
           74  +  SELECT Items.ItemName
           75  +    FROM Items
           76  +      LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy')
           77  +      LEFT JOIN B ON (B.Name = Items.ItemName)
           78  +    WHERE Items.Name = 'Parent'
           79  +    ORDER BY Items.ItemName;
           80  +} {Item1 Item2}
           81  +
    51     82   
    52     83   finish_test

Changes to test/index6.test.

   263    263     UPDATE OR REPLACE t6 SET b=789;
   264    264     SELECT * FROM t6;
   265    265   } {123 789}
   266    266   do_execsql_test index6-6.2 {
   267    267     PRAGMA integrity_check;
   268    268   } {ok}
   269    269   
          270  +# Test case for ticket [2326c258d02ead33d69faa63de8f4686b9b1b9d9] on
          271  +# 2015-02-24.  Any use of a partial index qualifying constraint inside
          272  +# the ON clause of a LEFT JOIN was causing incorrect results for all
          273  +# versions of SQLite 3.8.0 through 3.8.8.
          274  +#
          275  +do_execsql_test index6-7.0 {
          276  +  CREATE TABLE t7a(x);
          277  +  CREATE TABLE t7b(y);
          278  +  INSERT INTO t7a(x) VALUES(1);
          279  +  CREATE INDEX t7ax ON t7a(x) WHERE x=99;
          280  +  PRAGMA automatic_index=OFF;
          281  +  SELECT * FROM t7a LEFT JOIN t7b ON (x=99) ORDER BY x;
          282  +} {1 {}}
          283  +do_execsql_test index6-7.1 {
          284  +  INSERT INTO t7b(y) VALUES(2);
          285  +  SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x;
          286  +} {}
          287  +do_execsql_test index6-7.2 {
          288  +  INSERT INTO t7a(x) VALUES(99);
          289  +  SELECT * FROM t7a LEFT JOIN t7b ON (x=99) ORDER BY x;
          290  +} {1 {} 99 2}
          291  +do_execsql_test index6-7.3 {
          292  +  SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x;
          293  +} {99 2}
          294  +do_execsql_test index6-7.4 {
          295  +  EXPLAIN QUERY PLAN
          296  +  SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x;
          297  +} {/USING COVERING INDEX t7ax/}
          298  +
          299  +
          300  +do_execsql_test index6-8.0 {
          301  +  CREATE TABLE t8a(a,b);
          302  +  CREATE TABLE t8b(x,y);
          303  +  CREATE INDEX i8c ON t8b(y) WHERE x = 'value';
          304  +
          305  +  INSERT INTO t8a VALUES(1, 'one');
          306  +  INSERT INTO t8a VALUES(2, 'two');
          307  +  INSERT INTO t8a VALUES(3, 'three');
          308  +
          309  +  INSERT INTO t8b VALUES('value', 1);
          310  +  INSERT INTO t8b VALUES('dummy', 2);
          311  +  INSERT INTO t8b VALUES('value', 3);
          312  +  INSERT INTO t8b VALUES('dummy', 4);
          313  +} {}
          314  +
          315  +do_eqp_test index6-8.1 {
          316  +  SELECT * FROM t8a LEFT JOIN t8b ON (x = 'value' AND y = a)
          317  +} {
          318  +  0 0 0 {SCAN TABLE t8a} 
          319  +  0 1 1 {SEARCH TABLE t8b USING INDEX i8c (y=?)}
          320  +}
          321  +
          322  +do_execsql_test index6-8.2 {
          323  +  SELECT * FROM t8a LEFT JOIN t8b ON (x = 'value' AND y = a)
          324  +} {
          325  +  1 one value 1 
          326  +  2 two {} {} 
          327  +  3 three value 3
          328  +}
   270    329   
   271    330   finish_test