/ Check-in [aa72ea8a]
Login

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

Overview
Comment:Merge all trunk changes since 3.8.1 into the sessions branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: aa72ea8a004de7fe744fc13baef19d05aea607d5
User & Date: drh 2013-10-28 22:47:24
Context
2013-11-11
22:55
Merge in the WITHOUT ROWID changes. A few tests are failing now. They will be fixed in a follow-on check-in. check-in: 5addd123 user: drh tags: sessions
2013-10-28
22:47
Merge all trunk changes since 3.8.1 into the sessions branch. check-in: aa72ea8a user: drh tags: sessions
22:33
Formatting improvements to the WHERE-clause constraint display in the wheretrace debugging logic. check-in: 3a9e3ed9 user: drh tags: trunk
2013-10-16
14:32
Merge the latest trunk changes. check-in: 58065468 user: drh tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/vfslog.c.

    12     12   **
    13     13   ** This file contains the implementation of an SQLite vfs wrapper for
    14     14   ** unix that generates per-database log files of all disk activity.
    15     15   */
    16     16   
    17     17   /*
    18     18   ** This module contains code for a wrapper VFS that causes a log of
    19         -** most VFS calls to be written into a file on disk. The log 
    20         -** is stored as comma-separated variables.
           19  +** most VFS calls to be written into a file on disk.
           20  +**
           21  +** Each database connection creates a separate log file in the same
           22  +** directory as the original database and named after the original
           23  +** database.  A unique suffix is added to avoid name collisions.  
           24  +** Separate log files are used so that concurrent processes do not
           25  +** try to write log operations to the same file at the same instant, 
           26  +** resulting in overwritten or comingled log text.
           27  +**
           28  +** Each individual log file records operations by a single database
           29  +** connection on both the original database and its associated rollback
           30  +** journal.
           31  +**
           32  +** The log files are in the comma-separated-value (CSV) format.  The
           33  +** log files can be imported into an SQLite database using the ".import"
           34  +** command of the SQLite command-line shell for analysis.
           35  +**
           36  +** One technique for using this module is to append the text of this
           37  +** module to the end of a standard "sqlite3.c" amalgamation file then
           38  +** add the following compile-time options:
           39  +**
           40  +**     -DSQLITE_EXTRA_INIT=sqlite3_register_vfslog
           41  +**     -DSQLITE_USE_FCNTL_TRACE
    21     42   **
    22         -** All calls on sqlite3_file objects are logged.
    23         -** Additionally, calls to the xAccess(), xOpen(), and xDelete()
    24         -** methods are logged. The other sqlite3_vfs object methods (xDlXXX,
    25         -** xRandomness, xSleep, xCurrentTime, xGetLastError and xCurrentTimeInt64) 
    26         -** are not logged.
           43  +** The first compile-time option causes the sqlite3_register_vfslog()
           44  +** function, defined below, to be invoked when SQLite is initialized.
           45  +** That causes this custom VFS to become the default VFS for all
           46  +** subsequent connections.  The SQLITE_USE_FCNTL_TRACE option causes
           47  +** the SQLite core to issue extra sqlite3_file_control() operations
           48  +** with SQLITE_FCNTL_TRACE to give some indication of what is going
           49  +** on in the core.
    27     50   */
    28     51   
    29     52   #include "sqlite3.h"
    30     53   #include <string.h>
    31     54   #include <assert.h>
    32     55   #include <stdio.h>
    33     56   #if SQLITE_OS_UNIX
................................................................................
   186    209     sqlite3_int64 tElapse,           /* Elapse time of system call */
   187    210     const char *zOp,                 /* Type of system call */
   188    211     sqlite3_int64 iArg1,             /* First argument */
   189    212     sqlite3_int64 iArg2,             /* Second argument */
   190    213     const char *zArg3,               /* Third argument */
   191    214     int iRes                         /* Result */
   192    215   ){
   193         -  char z1[40], z2[40], z3[70];
          216  +  char z1[40], z2[40], z3[2000];
   194    217     if( pLog==0 ) return;
   195    218     if( iArg1>=0 ){
   196    219       sqlite3_snprintf(sizeof(z1), z1, "%lld", iArg1);
   197    220     }else{
   198    221       z1[0] = 0;
   199    222     }
   200    223     if( iArg2>=0 ){
   201    224       sqlite3_snprintf(sizeof(z2), z2, "%lld", iArg2);
   202    225     }else{
   203    226       z2[0] = 0;
   204    227     }
   205    228     if( zArg3 ){
   206         -    sqlite3_snprintf(sizeof(z3), z3, "\"%s\"", zArg3);
          229  +    sqlite3_snprintf(sizeof(z3), z3, "\"%.*w\"", sizeof(z3)-4, zArg3);
   207    230     }else{
   208    231       z3[0] = 0;
   209    232     }
   210    233     fprintf(pLog->out,"%lld,%lld,%s,%d,%s,%s,%s,%d\n",
   211    234         tStart, tElapse, zOp, pLog->zFilename==0, z1, z2, z3, iRes);
   212    235   }
   213    236   
................................................................................
   341    364         s1 += pI[1] + s0;
   342    365         pI += 2;
   343    366       }
   344    367       for(i=0; i<8; i++) sqlite3_snprintf(3, zCksum+i*2, "%02x", p[i]);
   345    368       sqlite3_snprintf(18, zCksum+i*2, "-%08x%08x", s0, s1);
   346    369     }
   347    370   }
          371  +
          372  +/*
          373  +** Convert a big-endian 32-bit integer into a native integer
          374  +*/
          375  +static int bigToNative(const unsigned char *x){
          376  +  return (x[0]<<24) + (x[1]<<16) + (x[2]<<8) + x[3];
          377  +}
   348    378   
   349    379   /*
   350    380   ** Read data from an vlog-file.
   351    381   */
   352    382   static int vlogRead(
   353    383     sqlite3_file *pFile, 
   354    384     void *zBuf, 
................................................................................
   372    402     if( rc==SQLITE_OK
   373    403      && p->pLog
   374    404      && p->pLog->zFilename
   375    405      && iOfst<=24
   376    406      && iOfst+iAmt>=28
   377    407     ){
   378    408       unsigned char *x = ((unsigned char*)zBuf)+(24-iOfst);
   379         -    unsigned iCtr;
   380         -    iCtr = (x[0]<<24) + (x[1]<<16) + (x[2]<<8) + x[3];
   381         -    vlogLogPrint(p->pLog, tStart, 0, "CHNGCTR-READ", iCtr, -1, 0, 0);
          409  +    unsigned iCtr, nFree = -1;
          410  +    char *zFree = 0;
          411  +    char zStr[12];
          412  +    iCtr = bigToNative(x);
          413  +    if( iOfst+iAmt>=40 ){
          414  +      zFree = zStr;
          415  +      sqlite3_snprintf(sizeof(zStr), zStr, "%d", bigToNative(x+8));
          416  +      nFree = bigToNative(x+12);
          417  +    }
          418  +    vlogLogPrint(p->pLog, tStart, 0, "CHNGCTR-READ", iCtr, nFree, zFree, 0);
   382    419     }
   383    420     return rc;
   384    421   }
   385    422   
   386    423   /*
   387    424   ** Write data to an vlog-file.
   388    425   */
................................................................................
   405    442     if( rc==SQLITE_OK
   406    443      && p->pLog
   407    444      && p->pLog->zFilename
   408    445      && iOfst<=24
   409    446      && iOfst+iAmt>=28
   410    447     ){
   411    448       unsigned char *x = ((unsigned char*)z)+(24-iOfst);
   412         -    unsigned iCtr;
   413         -    iCtr = (x[0]<<24) + (x[1]<<16) + (x[2]<<8) + x[3];
   414         -    vlogLogPrint(p->pLog, tStart, 0, "CHNGCTR-WRITE", iCtr, -1, 0, 0);
          449  +    unsigned iCtr, nFree = -1;
          450  +    char *zFree = 0;
          451  +    char zStr[12];
          452  +    iCtr = bigToNative(x);
          453  +    if( iOfst+iAmt>=40 ){
          454  +      zFree = zStr;
          455  +      sqlite3_snprintf(sizeof(zStr), zStr, "%d", bigToNative(x+8));
          456  +      nFree = bigToNative(x+12);
          457  +    }
          458  +    vlogLogPrint(p->pLog, tStart, 0, "CHNGCTR-WRITE", iCtr, nFree, zFree, 0);
   415    459     }
   416    460     return rc;
   417    461   }
   418    462   
   419    463   /*
   420    464   ** Truncate an vlog-file.
   421    465   */
................................................................................
   473    517   }
   474    518   
   475    519   /*
   476    520   ** Unlock an vlog-file.
   477    521   */
   478    522   static int vlogUnlock(sqlite3_file *pFile, int eLock){
   479    523     int rc;
   480         -  sqlite3_uint64 tStart, tElapse;
          524  +  sqlite3_uint64 tStart;
   481    525     VLogFile *p = (VLogFile *)pFile;
   482    526     tStart = vlog_time();
          527  +  vlogLogPrint(p->pLog, tStart, 0, "UNLOCK", eLock, -1, 0, 0);
   483    528     rc = p->pReal->pMethods->xUnlock(p->pReal, eLock);
   484         -  tElapse = vlog_time() - tStart;
   485         -  vlogLogPrint(p->pLog, tStart, tElapse, "UNLOCK", eLock, -1, 0, rc);
   486    529     return rc;
   487    530   }
   488    531   
   489    532   /*
   490    533   ** Check if another file-handle holds a RESERVED lock on an vlog-file.
   491    534   */
   492    535   static int vlogCheckReservedLock(sqlite3_file *pFile, int *pResOut){
................................................................................
   510    553     int rc;
   511    554     tStart = vlog_time();
   512    555     rc = p->pReal->pMethods->xFileControl(p->pReal, op, pArg);
   513    556     if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){
   514    557       *(char**)pArg = sqlite3_mprintf("vlog/%z", *(char**)pArg);
   515    558     }
   516    559     tElapse = vlog_time() - tStart;
   517         -  vlogLogPrint(p->pLog, tStart, tElapse, "FILECONTROL", op, -1, 0, rc);
          560  +  if( op==SQLITE_FCNTL_TRACE ){
          561  +    vlogLogPrint(p->pLog, tStart, tElapse, "TRACE", op, -1, pArg, rc);
          562  +  }else if( op==SQLITE_FCNTL_PRAGMA ){
          563  +    const char **azArg = (const char **)pArg;
          564  +    vlogLogPrint(p->pLog, tStart, tElapse, "FILECONTROL", op, -1, azArg[1], rc);
          565  +  }else if( op==SQLITE_FCNTL_SIZE_HINT ){
          566  +    sqlite3_int64 sz = *(sqlite3_int64*)pArg;
          567  +    vlogLogPrint(p->pLog, tStart, tElapse, "FILECONTROL", op, sz, 0, rc);
          568  +  }else{
          569  +    vlogLogPrint(p->pLog, tStart, tElapse, "FILECONTROL", op, -1, 0, rc);
          570  +  }
   518    571     return rc;
   519    572   }
   520    573   
   521    574   /*
   522    575   ** Return the sector-size in bytes for an vlog-file.
   523    576   */
   524    577   static int vlogSectorSize(sqlite3_file *pFile){

Changes to src/build.c.

  1710   1710           );
  1711   1711         }
  1712   1712       }
  1713   1713   #endif
  1714   1714   
  1715   1715       /* Reparse everything to update our internal data structures */
  1716   1716       sqlite3VdbeAddParseSchemaOp(v, iDb,
  1717         -               sqlite3MPrintf(db, "tbl_name='%q'", p->zName));
         1717  +           sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
  1718   1718     }
  1719   1719   
  1720   1720   
  1721   1721     /* Add the table to the in-memory representation of the database.
  1722   1722     */
  1723   1723     if( db->init.busy ){
  1724   1724       Table *pOld;

Changes to src/pragma.c.

    90     90   #endif
    91     91   #if !defined(SQLITE_OMIT_AUTOVACUUM)
    92     92     { /* zName:     */ "auto_vacuum",
    93     93       /* ePragTyp:  */ PragTyp_AUTO_VACUUM,
    94     94       /* ePragFlag: */ PragFlag_NeedSchema,
    95     95       /* iArg:      */ 0 },
    96     96   #endif
           97  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    97     98   #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
    98     99     { /* zName:     */ "automatic_index",
    99    100       /* ePragTyp:  */ PragTyp_FLAG,
   100    101       /* ePragFlag: */ 0,
   101    102       /* iArg:      */ SQLITE_AutoIndex },
          103  +#endif
   102    104   #endif
   103    105     { /* zName:     */ "busy_timeout",
   104    106       /* ePragTyp:  */ PragTyp_BUSY_TIMEOUT,
   105    107       /* ePragFlag: */ 0,
   106    108       /* iArg:      */ 0 },
   107    109   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   108    110     { /* zName:     */ "cache_size",
   109    111       /* ePragTyp:  */ PragTyp_CACHE_SIZE,
   110    112       /* ePragFlag: */ PragFlag_NeedSchema,
   111    113       /* iArg:      */ 0 },
   112    114   #endif
          115  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   113    116     { /* zName:     */ "cache_spill",
   114    117       /* ePragTyp:  */ PragTyp_FLAG,
   115    118       /* ePragFlag: */ 0,
   116    119       /* iArg:      */ SQLITE_CacheSpill },
          120  +#endif
   117    121     { /* zName:     */ "case_sensitive_like",
   118    122       /* ePragTyp:  */ PragTyp_CASE_SENSITIVE_LIKE,
   119    123       /* ePragFlag: */ 0,
   120    124       /* iArg:      */ 0 },
          125  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   121    126     { /* zName:     */ "checkpoint_fullfsync",
   122    127       /* ePragTyp:  */ PragTyp_FLAG,
   123    128       /* ePragFlag: */ 0,
   124    129       /* iArg:      */ SQLITE_CkptFullFSync },
          130  +#endif
   125    131   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   126    132     { /* zName:     */ "collation_list",
   127    133       /* ePragTyp:  */ PragTyp_COLLATION_LIST,
   128    134       /* ePragFlag: */ 0,
   129    135       /* iArg:      */ 0 },
   130    136   #endif
   131    137   #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
   132    138     { /* zName:     */ "compile_options",
   133    139       /* ePragTyp:  */ PragTyp_COMPILE_OPTIONS,
   134    140       /* ePragFlag: */ 0,
   135    141       /* iArg:      */ 0 },
   136    142   #endif
          143  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   137    144     { /* zName:     */ "count_changes",
   138    145       /* ePragTyp:  */ PragTyp_FLAG,
   139    146       /* ePragFlag: */ 0,
   140    147       /* iArg:      */ SQLITE_CountRows },
          148  +#endif
   141    149   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
   142    150     { /* zName:     */ "data_store_directory",
   143    151       /* ePragTyp:  */ PragTyp_DATA_STORE_DIRECTORY,
   144    152       /* ePragFlag: */ 0,
   145    153       /* iArg:      */ 0 },
   146    154   #endif
   147    155   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
................................................................................
   152    160   #endif
   153    161   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   154    162     { /* zName:     */ "default_cache_size",
   155    163       /* ePragTyp:  */ PragTyp_DEFAULT_CACHE_SIZE,
   156    164       /* ePragFlag: */ PragFlag_NeedSchema,
   157    165       /* iArg:      */ 0 },
   158    166   #endif
          167  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   159    168   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   160    169     { /* zName:     */ "defer_foreign_keys",
   161    170       /* ePragTyp:  */ PragTyp_FLAG,
   162    171       /* ePragFlag: */ 0,
   163    172       /* iArg:      */ SQLITE_DeferFKs },
   164    173   #endif
          174  +#endif
          175  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   165    176     { /* zName:     */ "empty_result_callbacks",
   166    177       /* ePragTyp:  */ PragTyp_FLAG,
   167    178       /* ePragFlag: */ 0,
   168    179       /* iArg:      */ SQLITE_NullCallback },
          180  +#endif
   169    181   #if !defined(SQLITE_OMIT_UTF16)
   170    182     { /* zName:     */ "encoding",
   171    183       /* ePragTyp:  */ PragTyp_ENCODING,
   172    184       /* ePragFlag: */ 0,
   173    185       /* iArg:      */ 0 },
   174    186   #endif
   175    187   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
................................................................................
   180    192   #endif
   181    193   #if !defined(SQLITE_OMIT_FOREIGN_KEY)
   182    194     { /* zName:     */ "foreign_key_list",
   183    195       /* ePragTyp:  */ PragTyp_FOREIGN_KEY_LIST,
   184    196       /* ePragFlag: */ PragFlag_NeedSchema,
   185    197       /* iArg:      */ 0 },
   186    198   #endif
          199  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   187    200   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   188    201     { /* zName:     */ "foreign_keys",
   189    202       /* ePragTyp:  */ PragTyp_FLAG,
   190    203       /* ePragFlag: */ 0,
   191    204       /* iArg:      */ SQLITE_ForeignKeys },
          205  +#endif
   192    206   #endif
   193    207   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   194    208     { /* zName:     */ "freelist_count",
   195    209       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   196    210       /* ePragFlag: */ 0,
   197    211       /* iArg:      */ 0 },
   198    212   #endif
          213  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   199    214     { /* zName:     */ "full_column_names",
   200    215       /* ePragTyp:  */ PragTyp_FLAG,
   201    216       /* ePragFlag: */ 0,
   202    217       /* iArg:      */ SQLITE_FullColNames },
   203    218     { /* zName:     */ "fullfsync",
   204    219       /* ePragTyp:  */ PragTyp_FLAG,
   205    220       /* ePragFlag: */ 0,
   206    221       /* iArg:      */ SQLITE_FullFSync },
          222  +#endif
   207    223   #if defined(SQLITE_HAS_CODEC)
   208    224     { /* zName:     */ "hexkey",
   209    225       /* ePragTyp:  */ PragTyp_HEXKEY,
   210    226       /* ePragFlag: */ 0,
   211    227       /* iArg:      */ 0 },
   212    228     { /* zName:     */ "hexrekey",
   213    229       /* ePragTyp:  */ PragTyp_HEXKEY,
   214    230       /* ePragFlag: */ 0,
   215    231       /* iArg:      */ 0 },
   216    232   #endif
          233  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   217    234   #if !defined(SQLITE_OMIT_CHECK)
   218    235     { /* zName:     */ "ignore_check_constraints",
   219    236       /* ePragTyp:  */ PragTyp_FLAG,
   220    237       /* ePragFlag: */ 0,
   221    238       /* iArg:      */ SQLITE_IgnoreChecks },
          239  +#endif
   222    240   #endif
   223    241   #if !defined(SQLITE_OMIT_AUTOVACUUM)
   224    242     { /* zName:     */ "incremental_vacuum",
   225    243       /* ePragTyp:  */ PragTyp_INCREMENTAL_VACUUM,
   226    244       /* ePragFlag: */ PragFlag_NeedSchema,
   227    245       /* iArg:      */ 0 },
   228    246   #endif
................................................................................
   254    272   #endif
   255    273   #if defined(SQLITE_HAS_CODEC)
   256    274     { /* zName:     */ "key",
   257    275       /* ePragTyp:  */ PragTyp_KEY,
   258    276       /* ePragFlag: */ 0,
   259    277       /* iArg:      */ 0 },
   260    278   #endif
          279  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   261    280     { /* zName:     */ "legacy_file_format",
   262    281       /* ePragTyp:  */ PragTyp_FLAG,
   263    282       /* ePragFlag: */ 0,
   264    283       /* iArg:      */ SQLITE_LegacyFileFmt },
          284  +#endif
   265    285   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
   266    286     { /* zName:     */ "lock_proxy_file",
   267    287       /* ePragTyp:  */ PragTyp_LOCK_PROXY_FILE,
   268    288       /* ePragFlag: */ 0,
   269    289       /* iArg:      */ 0 },
   270    290   #endif
   271    291   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
................................................................................
   298    318   #endif
   299    319   #if defined(SQLITE_DEBUG)
   300    320     { /* zName:     */ "parser_trace",
   301    321       /* ePragTyp:  */ PragTyp_PARSER_TRACE,
   302    322       /* ePragFlag: */ 0,
   303    323       /* iArg:      */ 0 },
   304    324   #endif
          325  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   305    326     { /* zName:     */ "query_only",
   306    327       /* ePragTyp:  */ PragTyp_FLAG,
   307    328       /* ePragFlag: */ 0,
   308    329       /* iArg:      */ SQLITE_QueryOnly },
          330  +#endif
   309    331   #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
   310    332     { /* zName:     */ "quick_check",
   311    333       /* ePragTyp:  */ PragTyp_INTEGRITY_CHECK,
   312    334       /* ePragFlag: */ PragFlag_NeedSchema,
   313    335       /* iArg:      */ 0 },
   314    336   #endif
          337  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   315    338     { /* zName:     */ "read_uncommitted",
   316    339       /* ePragTyp:  */ PragTyp_FLAG,
   317    340       /* ePragFlag: */ 0,
   318    341       /* iArg:      */ SQLITE_ReadUncommitted },
   319    342     { /* zName:     */ "recursive_triggers",
   320    343       /* ePragTyp:  */ PragTyp_FLAG,
   321    344       /* ePragFlag: */ 0,
   322    345       /* iArg:      */ SQLITE_RecTriggers },
          346  +#endif
   323    347   #if defined(SQLITE_HAS_CODEC)
   324    348     { /* zName:     */ "rekey",
   325    349       /* ePragTyp:  */ PragTyp_REKEY,
   326    350       /* ePragFlag: */ 0,
   327    351       /* iArg:      */ 0 },
   328    352   #endif
          353  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   329    354     { /* zName:     */ "reverse_unordered_selects",
   330    355       /* ePragTyp:  */ PragTyp_FLAG,
   331    356       /* ePragFlag: */ 0,
   332    357       /* iArg:      */ SQLITE_ReverseOrder },
          358  +#endif
   333    359   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   334    360     { /* zName:     */ "schema_version",
   335    361       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   336    362       /* ePragFlag: */ 0,
   337    363       /* iArg:      */ 0 },
   338    364   #endif
   339    365   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   340    366     { /* zName:     */ "secure_delete",
   341    367       /* ePragTyp:  */ PragTyp_SECURE_DELETE,
   342    368       /* ePragFlag: */ 0,
   343    369       /* iArg:      */ 0 },
   344    370   #endif
          371  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   345    372     { /* zName:     */ "short_column_names",
   346    373       /* ePragTyp:  */ PragTyp_FLAG,
   347    374       /* ePragFlag: */ 0,
   348    375       /* iArg:      */ SQLITE_ShortColNames },
          376  +#endif
   349    377     { /* zName:     */ "shrink_memory",
   350    378       /* ePragTyp:  */ PragTyp_SHRINK_MEMORY,
   351    379       /* ePragFlag: */ 0,
   352    380       /* iArg:      */ 0 },
   353    381     { /* zName:     */ "soft_heap_limit",
   354    382       /* ePragTyp:  */ PragTyp_SOFT_HEAP_LIMIT,
   355    383       /* ePragFlag: */ 0,
   356    384       /* iArg:      */ 0 },
          385  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   357    386   #if defined(SQLITE_DEBUG)
   358    387     { /* zName:     */ "sql_trace",
   359    388       /* ePragTyp:  */ PragTyp_FLAG,
   360    389       /* ePragFlag: */ 0,
   361    390       /* iArg:      */ SQLITE_SqlTrace },
          391  +#endif
   362    392   #endif
   363    393   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   364    394     { /* zName:     */ "stats",
   365    395       /* ePragTyp:  */ PragTyp_STATS,
   366    396       /* ePragFlag: */ PragFlag_NeedSchema,
   367    397       /* iArg:      */ 0 },
   368    398   #endif
................................................................................
   390    420   #endif
   391    421   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   392    422     { /* zName:     */ "user_version",
   393    423       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   394    424       /* ePragFlag: */ 0,
   395    425       /* iArg:      */ 0 },
   396    426   #endif
          427  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   397    428   #if defined(SQLITE_DEBUG)
   398    429     { /* zName:     */ "vdbe_addoptrace",
   399    430       /* ePragTyp:  */ PragTyp_FLAG,
   400    431       /* ePragFlag: */ 0,
   401    432       /* iArg:      */ SQLITE_VdbeAddopTrace },
   402    433     { /* zName:     */ "vdbe_debug",
   403    434       /* ePragTyp:  */ PragTyp_FLAG,
................................................................................
   407    438       /* ePragTyp:  */ PragTyp_FLAG,
   408    439       /* ePragFlag: */ 0,
   409    440       /* iArg:      */ SQLITE_VdbeListing },
   410    441     { /* zName:     */ "vdbe_trace",
   411    442       /* ePragTyp:  */ PragTyp_FLAG,
   412    443       /* ePragFlag: */ 0,
   413    444       /* iArg:      */ SQLITE_VdbeTrace },
          445  +#endif
   414    446   #endif
   415    447   #if !defined(SQLITE_OMIT_WAL)
   416    448     { /* zName:     */ "wal_autocheckpoint",
   417    449       /* ePragTyp:  */ PragTyp_WAL_AUTOCHECKPOINT,
   418    450       /* ePragFlag: */ 0,
   419    451       /* iArg:      */ 0 },
   420    452     { /* zName:     */ "wal_checkpoint",
   421    453       /* ePragTyp:  */ PragTyp_WAL_CHECKPOINT,
   422    454       /* ePragFlag: */ PragFlag_NeedSchema,
   423    455       /* iArg:      */ 0 },
   424    456   #endif
          457  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   425    458     { /* zName:     */ "writable_schema",
   426    459       /* ePragTyp:  */ PragTyp_FLAG,
   427    460       /* ePragFlag: */ 0,
   428    461       /* iArg:      */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
          462  +#endif
   429    463   };
   430    464   /* Number of pragmas: 56 on by default, 68 total. */
   431    465   /* End of the automatically generated pragma table.
   432    466   ***************************************************************************/
   433    467   
   434    468   /*
   435    469   ** Interpret the given string as a safety level.  Return 0 for OFF,

Changes to src/resolve.c.

   705    705                 sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a "
   706    706                                         "constant between 0.0 and 1.0");
   707    707                 pNC->nErr++;
   708    708               }
   709    709             }else{
   710    710               /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to
   711    711               ** likelihood(X, 0.0625).
   712         -            ** EVIDENCE-OF: R-35738-39582 The unlikely(X) fucntion is short-hand for
          712  +            ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is short-hand for
   713    713               ** likelihood(X,0.0625). */
   714    714               pExpr->iTable = 62;  /* TUNING:  Default 2nd arg to unlikely() is 0.0625 */
   715    715             }             
   716    716           }
   717    717         }
   718    718   #ifndef SQLITE_OMIT_AUTHORIZATION
   719    719         if( pDef ){

Changes to src/shell.c.

   432    432     char nullvalue[20];    /* The text to print when a NULL comes back from
   433    433                            ** the database */
   434    434     struct previous_mode_data explainPrev;
   435    435                            /* Holds the mode information just before
   436    436                            ** .explain ON */
   437    437     char outfile[FILENAME_MAX]; /* Filename for *out */
   438    438     const char *zDbFilename;    /* name of the database file */
          439  +  char *zFreeOnClose;         /* Filename to free when closing */
   439    440     const char *zVfs;           /* Name of VFS to use */
   440    441     sqlite3_stmt *pStmt;   /* Current statement if any. */
   441    442     FILE *pLog;            /* Write log output here */
   442    443   };
   443    444   
   444    445   /*
   445    446   ** These are the allowed modes.
................................................................................
  1433   1434     "                         html     HTML <table> code\n"
  1434   1435     "                         insert   SQL insert statements for TABLE\n"
  1435   1436     "                         line     One value per line\n"
  1436   1437     "                         list     Values delimited by .separator string\n"
  1437   1438     "                         tabs     Tab-separated values\n"
  1438   1439     "                         tcl      TCL list elements\n"
  1439   1440     ".nullvalue STRING      Use STRING in place of NULL values\n"
         1441  +  ".open ?FILENAME?       Close existing database and reopen FILENAME\n"
  1440   1442     ".output FILENAME       Send output to FILENAME\n"
  1441   1443     ".output stdout         Send output to the screen\n"
  1442   1444     ".print STRING...       Print literal STRING\n"
  1443   1445     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  1444   1446     ".quit                  Exit this program\n"
  1445   1447     ".read FILENAME         Execute SQL in FILENAME\n"
  1446   1448     ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
................................................................................
  1466   1468   /* Forward reference */
  1467   1469   static int process_input(struct callback_data *p, FILE *in);
  1468   1470   
  1469   1471   /*
  1470   1472   ** Make sure the database is open.  If it is not, then open it.  If
  1471   1473   ** the database fails to open, print an error message and exit.
  1472   1474   */
  1473         -static void open_db(struct callback_data *p){
         1475  +static void open_db(struct callback_data *p, int keepAlive){
  1474   1476     if( p->db==0 ){
  1475   1477       sqlite3_initialize();
  1476   1478       sqlite3_open(p->zDbFilename, &p->db);
  1477   1479       db = p->db;
  1478   1480       if( db && sqlite3_errcode(db)==SQLITE_OK ){
  1479   1481         sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
  1480   1482             shellstaticFunc, 0, 0);
  1481   1483       }
  1482   1484       if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
  1483   1485         fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 
  1484   1486             p->zDbFilename, sqlite3_errmsg(db));
         1487  +      if( keepAlive ) return;
  1485   1488         exit(1);
  1486   1489       }
  1487   1490   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  1488   1491       sqlite3_enable_load_extension(p->db, 1);
  1489   1492   #endif
  1490   1493     }
  1491   1494   }
................................................................................
  1830   1833       if( zDb==0 ) zDb = "main";
  1831   1834       rc = sqlite3_open(zDestFile, &pDest);
  1832   1835       if( rc!=SQLITE_OK ){
  1833   1836         fprintf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
  1834   1837         sqlite3_close(pDest);
  1835   1838         return 1;
  1836   1839       }
  1837         -    open_db(p);
         1840  +    open_db(p, 0);
  1838   1841       pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
  1839   1842       if( pBackup==0 ){
  1840   1843         fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
  1841   1844         sqlite3_close(pDest);
  1842   1845         return 1;
  1843   1846       }
  1844   1847       while(  (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
................................................................................
  1862   1865     if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
  1863   1866       test_breakpoint();
  1864   1867     }else
  1865   1868   
  1866   1869     if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
  1867   1870       struct callback_data data;
  1868   1871       char *zErrMsg = 0;
  1869         -    open_db(p);
         1872  +    open_db(p, 0);
  1870   1873       memcpy(&data, p, sizeof(data));
  1871   1874       data.showHeader = 1;
  1872   1875       data.mode = MODE_Column;
  1873   1876       data.colWidth[0] = 3;
  1874   1877       data.colWidth[1] = 15;
  1875   1878       data.colWidth[2] = 58;
  1876   1879       data.cnt = 0;
................................................................................
  1879   1882         fprintf(stderr,"Error: %s\n", zErrMsg);
  1880   1883         sqlite3_free(zErrMsg);
  1881   1884         rc = 1;
  1882   1885       }
  1883   1886     }else
  1884   1887   
  1885   1888     if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
  1886         -    open_db(p);
         1889  +    open_db(p, 0);
  1887   1890       /* When playing back a "dump", the content might appear in an order
  1888   1891       ** which causes immediate foreign key constraints to be violated.
  1889   1892       ** So disable foreign-key constraint enforcement to prevent problems. */
  1890   1893       fprintf(p->out, "PRAGMA foreign_keys=OFF;\n");
  1891   1894       fprintf(p->out, "BEGIN TRANSACTION;\n");
  1892   1895       p->writableSchema = 0;
  1893   1896       sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
................................................................................
  1998   2001       int nSep;                   /* Number of bytes in p->separator[] */
  1999   2002       char *zSql;                 /* An SQL statement */
  2000   2003       CSVReader sCsv;             /* Reader context */
  2001   2004       int (*xCloser)(FILE*);      /* Procedure to close th3 connection */
  2002   2005   
  2003   2006       seenInterrupt = 0;
  2004   2007       memset(&sCsv, 0, sizeof(sCsv));
  2005         -    open_db(p);
         2008  +    open_db(p, 0);
  2006   2009       nSep = strlen30(p->separator);
  2007   2010       if( nSep==0 ){
  2008   2011         fprintf(stderr, "Error: non-null separator required for import\n");
  2009   2012         return 1;
  2010   2013       }
  2011   2014       if( nSep>1 ){
  2012   2015         fprintf(stderr, "Error: multi-character separators not allowed"
................................................................................
  2136   2139       sqlite3_finalize(pStmt);
  2137   2140       if( needCommit ) sqlite3_exec(db, "COMMIT", 0, 0, 0);
  2138   2141     }else
  2139   2142   
  2140   2143     if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
  2141   2144       struct callback_data data;
  2142   2145       char *zErrMsg = 0;
  2143         -    open_db(p);
         2146  +    open_db(p, 0);
  2144   2147       memcpy(&data, p, sizeof(data));
  2145   2148       data.showHeader = 0;
  2146   2149       data.mode = MODE_List;
  2147   2150       if( nArg==1 ){
  2148   2151         rc = sqlite3_exec(p->db,
  2149   2152           "SELECT name FROM sqlite_master "
  2150   2153           "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
................................................................................
  2202   2205   
  2203   2206   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  2204   2207     if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){
  2205   2208       const char *zFile, *zProc;
  2206   2209       char *zErrMsg = 0;
  2207   2210       zFile = azArg[1];
  2208   2211       zProc = nArg>=3 ? azArg[2] : 0;
  2209         -    open_db(p);
         2212  +    open_db(p, 0);
  2210   2213       rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
  2211   2214       if( rc!=SQLITE_OK ){
  2212   2215         fprintf(stderr, "Error: %s\n", zErrMsg);
  2213   2216         sqlite3_free(zErrMsg);
  2214   2217         rc = 1;
  2215   2218       }
  2216   2219     }else
................................................................................
  2267   2270       }
  2268   2271     }else
  2269   2272   
  2270   2273     if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
  2271   2274       sqlite3_snprintf(sizeof(p->nullvalue), p->nullvalue,
  2272   2275                        "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
  2273   2276     }else
         2277  +
         2278  +  if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
         2279  +    sqlite3 *savedDb = p->db;
         2280  +    const char *zSavedFilename = p->zDbFilename;
         2281  +    char *zNewFilename = 0;
         2282  +    p->db = 0;
         2283  +    if( nArg>=2 ){
         2284  +      p->zDbFilename = zNewFilename = sqlite3_mprintf("%s", azArg[1]);
         2285  +    }
         2286  +    open_db(p, 1);
         2287  +    if( p->db!=0 ){
         2288  +      sqlite3_close(savedDb);
         2289  +      sqlite3_free(p->zFreeOnClose);
         2290  +      p->zFreeOnClose = zNewFilename;
         2291  +    }else{
         2292  +      sqlite3_free(zNewFilename);
         2293  +      p->db = savedDb;
         2294  +      p->zDbFilename = zSavedFilename;
         2295  +    }
         2296  +  }else
  2274   2297   
  2275   2298     if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
  2276   2299       if( p->outfile[0]=='|' ){
  2277   2300         pclose(p->out);
  2278   2301       }else{
  2279   2302         output_file_close(p->out);
  2280   2303       }
................................................................................
  2351   2374       }
  2352   2375       rc = sqlite3_open(zSrcFile, &pSrc);
  2353   2376       if( rc!=SQLITE_OK ){
  2354   2377         fprintf(stderr, "Error: cannot open \"%s\"\n", zSrcFile);
  2355   2378         sqlite3_close(pSrc);
  2356   2379         return 1;
  2357   2380       }
  2358         -    open_db(p);
         2381  +    open_db(p, 0);
  2359   2382       pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
  2360   2383       if( pBackup==0 ){
  2361   2384         fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
  2362   2385         sqlite3_close(pSrc);
  2363   2386         return 1;
  2364   2387       }
  2365   2388       while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
................................................................................
  2381   2404       }
  2382   2405       sqlite3_close(pSrc);
  2383   2406     }else
  2384   2407   
  2385   2408     if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
  2386   2409       struct callback_data data;
  2387   2410       char *zErrMsg = 0;
  2388         -    open_db(p);
         2411  +    open_db(p, 0);
  2389   2412       memcpy(&data, p, sizeof(data));
  2390   2413       data.showHeader = 0;
  2391   2414       data.mode = MODE_Semi;
  2392   2415       if( nArg>1 ){
  2393   2416         int i;
  2394   2417         for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
  2395   2418         if( strcmp(azArg[1],"sqlite_master")==0 ){
................................................................................
  2512   2535   
  2513   2536     if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 && nArg<3 ){
  2514   2537       sqlite3_stmt *pStmt;
  2515   2538       char **azResult;
  2516   2539       int nRow, nAlloc;
  2517   2540       char *zSql = 0;
  2518   2541       int ii;
  2519         -    open_db(p);
         2542  +    open_db(p, 0);
  2520   2543       rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
  2521   2544       if( rc ) return rc;
  2522   2545       zSql = sqlite3_mprintf(
  2523   2546           "SELECT name FROM sqlite_master"
  2524   2547           " WHERE type IN ('table','view')"
  2525   2548           "   AND name NOT LIKE 'sqlite_%%'"
  2526   2549           "   AND name LIKE ?1");
................................................................................
  2612   2635         { "optimizations",         SQLITE_TESTCTRL_OPTIMIZATIONS          },
  2613   2636         { "iskeyword",             SQLITE_TESTCTRL_ISKEYWORD              },
  2614   2637         { "scratchmalloc",         SQLITE_TESTCTRL_SCRATCHMALLOC          },
  2615   2638       };
  2616   2639       int testctrl = -1;
  2617   2640       int rc = 0;
  2618   2641       int i, n;
  2619         -    open_db(p);
         2642  +    open_db(p, 0);
  2620   2643   
  2621   2644       /* convert testctrl text option to value. allow any unique prefix
  2622   2645       ** of the option name, or a numerical value. */
  2623   2646       n = strlen30(azArg[1]);
  2624   2647       for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
  2625   2648         if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
  2626   2649           if( testctrl<0 ){
................................................................................
  2711   2734                     azArg[1]);
  2712   2735             break;
  2713   2736         }
  2714   2737       }
  2715   2738     }else
  2716   2739   
  2717   2740     if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
  2718         -    open_db(p);
         2741  +    open_db(p, 0);
  2719   2742       sqlite3_busy_timeout(p->db, (int)integerValue(azArg[1]));
  2720   2743     }else
  2721   2744       
  2722   2745     if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
  2723   2746      && nArg==2
  2724   2747     ){
  2725   2748       enableTimer = booleanValue(azArg[1]);
  2726   2749     }else
  2727   2750     
  2728   2751     if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
  2729         -    open_db(p);
         2752  +    open_db(p, 0);
  2730   2753       output_file_close(p->traceOut);
  2731   2754       p->traceOut = output_file_open(azArg[1]);
  2732   2755   #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
  2733   2756       if( p->traceOut==0 ){
  2734   2757         sqlite3_trace(p->db, 0, 0);
  2735   2758       }else{
  2736   2759         sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
................................................................................
  2914   2937         zSql[nSql++] = '\n';
  2915   2938         memcpy(zSql+nSql, zLine, nLine+1);
  2916   2939         nSql += nLine;
  2917   2940       }
  2918   2941       if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
  2919   2942                   && sqlite3_complete(zSql) ){
  2920   2943         p->cnt = 0;
  2921         -      open_db(p);
         2944  +      open_db(p, 0);
  2922   2945         BEGIN_TIMER;
  2923   2946         rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
  2924   2947         END_TIMER;
  2925   2948         if( rc || zErrMsg ){
  2926   2949           char zPrefix[100];
  2927   2950           if( in!=0 || !stdin_is_interactive ){
  2928   2951             sqlite3_snprintf(sizeof(zPrefix), zPrefix, 
................................................................................
  3241   3264   
  3242   3265     /* Go ahead and open the database file if it already exists.  If the
  3243   3266     ** file does not exist, delay opening it.  This prevents empty database
  3244   3267     ** files from being created if a user mistypes the database name argument
  3245   3268     ** to the sqlite command-line tool.
  3246   3269     */
  3247   3270     if( access(data.zDbFilename, 0)==0 ){
  3248         -    open_db(&data);
         3271  +    open_db(&data, 0);
  3249   3272     }
  3250   3273   
  3251   3274     /* Process the initialization file if there is one.  If no -init option
  3252   3275     ** is given on the command line, look for a file named ~/.sqliterc and
  3253   3276     ** try to process it.
  3254   3277     */
  3255   3278     rc = process_sqliterc(&data,zInitFile);
................................................................................
  3321   3344       }else if( strcmp(z,"-cmd")==0 ){
  3322   3345         if( i==argc-1 ) break;
  3323   3346         z = cmdline_option_value(argc,argv,++i);
  3324   3347         if( z[0]=='.' ){
  3325   3348           rc = do_meta_command(z, &data);
  3326   3349           if( rc && bail_on_error ) return rc==2 ? 0 : rc;
  3327   3350         }else{
  3328         -        open_db(&data);
         3351  +        open_db(&data, 0);
  3329   3352           rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
  3330   3353           if( zErrMsg!=0 ){
  3331   3354             fprintf(stderr,"Error: %s\n", zErrMsg);
  3332   3355             if( bail_on_error ) return rc!=0 ? rc : 1;
  3333   3356           }else if( rc!=0 ){
  3334   3357             fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z);
  3335   3358             if( bail_on_error ) return rc;
................................................................................
  3345   3368     if( zFirstCmd ){
  3346   3369       /* Run just the command that follows the database name
  3347   3370       */
  3348   3371       if( zFirstCmd[0]=='.' ){
  3349   3372         rc = do_meta_command(zFirstCmd, &data);
  3350   3373         if( rc==2 ) rc = 0;
  3351   3374       }else{
  3352         -      open_db(&data);
         3375  +      open_db(&data, 0);
  3353   3376         rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
  3354   3377         if( zErrMsg!=0 ){
  3355   3378           fprintf(stderr,"Error: %s\n", zErrMsg);
  3356   3379           return rc!=0 ? rc : 1;
  3357   3380         }else if( rc!=0 ){
  3358   3381           fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
  3359   3382           return rc;
................................................................................
  3392   3415         rc = process_input(&data, stdin);
  3393   3416       }
  3394   3417     }
  3395   3418     set_table_name(&data, 0);
  3396   3419     if( data.db ){
  3397   3420       sqlite3_close(data.db);
  3398   3421     }
         3422  +  sqlite3_free(data.zFreeOnClose); 
  3399   3423     return rc;
  3400   3424   }

Changes to src/sqlite.h.in.

   903    903   ** The argument is a pointer to a value of type sqlite3_int64 that
   904    904   ** is an advisory maximum number of bytes in the file to memory map.  The
   905    905   ** pointer is overwritten with the old value.  The limit is not changed if
   906    906   ** the value originally pointed to is negative, and so the current limit 
   907    907   ** can be queried by passing in a pointer to a negative number.  This
   908    908   ** file-control is used internally to implement [PRAGMA mmap_size].
   909    909   **
          910  +** <li>[[SQLITE_FCNTL_TRACE]]
          911  +** The [SQLITE_FCNTL_TRACE] file control provides advisory information
          912  +** to the VFS about what the higher layers of the SQLite stack are doing.
          913  +** This file control is used by some VFS activity tracing [shims].
          914  +** The argument is a zero-terminated string.  Higher layers in the
          915  +** SQLite stack may generate instances of this file control if
          916  +** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
          917  +**
   910    918   ** </ul>
   911    919   */
   912    920   #define SQLITE_FCNTL_LOCKSTATE               1
   913    921   #define SQLITE_GET_LOCKPROXYFILE             2
   914    922   #define SQLITE_SET_LOCKPROXYFILE             3
   915    923   #define SQLITE_LAST_ERRNO                    4
   916    924   #define SQLITE_FCNTL_SIZE_HINT               5
................................................................................
   922    930   #define SQLITE_FCNTL_OVERWRITE              11
   923    931   #define SQLITE_FCNTL_VFSNAME                12
   924    932   #define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
   925    933   #define SQLITE_FCNTL_PRAGMA                 14
   926    934   #define SQLITE_FCNTL_BUSYHANDLER            15
   927    935   #define SQLITE_FCNTL_TEMPFILENAME           16
   928    936   #define SQLITE_FCNTL_MMAP_SIZE              18
          937  +#define SQLITE_FCNTL_TRACE                  19
   929    938   
   930    939   /*
   931    940   ** CAPI3REF: Mutex Handle
   932    941   **
   933    942   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
   934    943   ** abstract type for a mutex object.  The SQLite core never looks
   935    944   ** at the internal representation of an [sqlite3_mutex].  It only

Changes to src/vdbe.c.

  6186   6186      && !p->doingRerun
  6187   6187      && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
  6188   6188     ){
  6189   6189       z = sqlite3VdbeExpandSql(p, zTrace);
  6190   6190       db->xTrace(db->pTraceArg, z);
  6191   6191       sqlite3DbFree(db, z);
  6192   6192     }
         6193  +#ifdef SQLITE_USE_FCNTL_TRACE
         6194  +  zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
         6195  +  if( zTrace ){
         6196  +    int i;
         6197  +    for(i=0; i<db->nDb; i++){
         6198  +      if( ((1<<i) & p->btreeMask)==0 ) continue;
         6199  +      sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
         6200  +    }
         6201  +  }
         6202  +#endif /* SQLITE_USE_FCNTL_TRACE */
  6193   6203   #ifdef SQLITE_DEBUG
  6194   6204     if( (db->flags & SQLITE_SqlTrace)!=0
  6195   6205      && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
  6196   6206     ){
  6197   6207       sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
  6198   6208     }
  6199   6209   #endif /* SQLITE_DEBUG */

Changes to src/where.c.

   874    874     int k = pScan->k;    /* Where to start scanning */
   875    875   
   876    876     while( pScan->iEquiv<=pScan->nEquiv ){
   877    877       iCur = pScan->aEquiv[pScan->iEquiv-2];
   878    878       iColumn = pScan->aEquiv[pScan->iEquiv-1];
   879    879       while( (pWC = pScan->pWC)!=0 ){
   880    880         for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
   881         -        if( pTerm->leftCursor==iCur && pTerm->u.leftColumn==iColumn ){
          881  +        if( pTerm->leftCursor==iCur
          882  +         && pTerm->u.leftColumn==iColumn
          883  +         && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
          884  +        ){
   882    885             if( (pTerm->eOperator & WO_EQUIV)!=0
   883    886              && pScan->nEquiv<ArraySize(pScan->aEquiv)
   884    887             ){
   885    888               int j;
   886    889               pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
   887    890               assert( pX->op==TK_COLUMN );
   888    891               for(j=0; j<pScan->nEquiv; j+=2){
................................................................................
  2546   2549         }else{
  2547   2550           nNew = 10;        assert( 10==sqlite3LogEst(2) );
  2548   2551         }
  2549   2552         if( nNew<nOut ){
  2550   2553           nOut = nNew;
  2551   2554         }
  2552   2555         pLoop->nOut = (LogEst)nOut;
  2553         -      WHERETRACE(0x100, ("range scan regions: %u..%u  est=%d\n",
         2556  +      WHERETRACE(0x10, ("range scan regions: %u..%u  est=%d\n",
  2554   2557                            (u32)iLower, (u32)iUpper, nOut));
  2555   2558         return SQLITE_OK;
  2556   2559       }
  2557   2560     }
  2558   2561   #else
  2559   2562     UNUSED_PARAMETER(pParse);
  2560   2563     UNUSED_PARAMETER(pBuilder);
................................................................................
  2632   2635     rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk);
  2633   2636     pBuilder->pRec = pRec;
  2634   2637     if( rc!=SQLITE_OK ) return rc;
  2635   2638     if( bOk==0 ) return SQLITE_NOTFOUND;
  2636   2639     pBuilder->nRecValid = nEq;
  2637   2640   
  2638   2641     whereKeyStats(pParse, p, pRec, 0, a);
  2639         -  WHERETRACE(0x100,("equality scan regions: %d\n", (int)a[1]));
         2642  +  WHERETRACE(0x10,("equality scan regions: %d\n", (int)a[1]));
  2640   2643     *pnRow = a[1];
  2641   2644     
  2642   2645     return rc;
  2643   2646   }
  2644   2647   #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
  2645   2648   
  2646   2649   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
................................................................................
  2680   2683       nRowEst += nEst;
  2681   2684       pBuilder->nRecValid = nRecValid;
  2682   2685     }
  2683   2686   
  2684   2687     if( rc==SQLITE_OK ){
  2685   2688       if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
  2686   2689       *pnRow = nRowEst;
  2687         -    WHERETRACE(0x100,("IN row estimate: est=%g\n", nRowEst));
         2690  +    WHERETRACE(0x10,("IN row estimate: est=%g\n", nRowEst));
  2688   2691     }
  2689   2692     assert( pBuilder->nRecValid==nRecValid );
  2690   2693     return rc;
  2691   2694   }
  2692   2695   #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
  2693   2696   
  2694   2697   /*
................................................................................
  3884   3887         pTerm->wtFlags |= TERM_CODED;
  3885   3888       }
  3886   3889     }
  3887   3890     sqlite3ReleaseTempReg(pParse, iReleaseReg);
  3888   3891   
  3889   3892     return pLevel->notReady;
  3890   3893   }
         3894  +
         3895  +#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
         3896  +/*
         3897  +** Generate "Explanation" text for a WhereTerm.
         3898  +*/
         3899  +static void whereExplainTerm(Vdbe *v, WhereTerm *pTerm){
         3900  +  char zType[4];
         3901  +  memcpy(zType, "...", 4);
         3902  +  if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
         3903  +  if( pTerm->eOperator & WO_EQUIV  ) zType[1] = 'E';
         3904  +  if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
         3905  +  sqlite3ExplainPrintf(v, "%s ", zType);
         3906  +  sqlite3ExplainExpr(v, pTerm->pExpr);
         3907  +}
         3908  +#endif /* WHERETRACE_ENABLED && SQLITE_ENABLE_TREE_EXPLAIN */
         3909  +
  3891   3910   
  3892   3911   #ifdef WHERETRACE_ENABLED
  3893   3912   /*
  3894   3913   ** Print a WhereLoop object for debugging purposes
  3895   3914   */
  3896         -static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
  3897         -  int nb = 1+(pTabList->nSrc+7)/8;
  3898         -  struct SrcList_item *pItem = pTabList->a + p->iTab;
         3915  +static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
         3916  +  WhereInfo *pWInfo = pWC->pWInfo;
         3917  +  int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
         3918  +  struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
  3899   3919     Table *pTab = pItem->pTab;
  3900   3920     sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
  3901   3921                        p->iTab, nb, p->maskSelf, nb, p->prereq);
  3902   3922     sqlite3DebugPrintf(" %12s",
  3903   3923                        pItem->zAlias ? pItem->zAlias : pTab->zName);
  3904   3924     if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
  3905         -    if( p->u.btree.pIndex ){
  3906         -      const char *zName = p->u.btree.pIndex->zName;
  3907         -      if( zName==0 ) zName = "ipk";
         3925  +     const char *zName;
         3926  +     if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
  3908   3927         if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
  3909   3928           int i = sqlite3Strlen30(zName) - 1;
  3910   3929           while( zName[i]!='_' ) i--;
  3911   3930           zName += i;
  3912   3931         }
  3913   3932         sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
  3914   3933       }else{
................................................................................
  3923   3942         z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
  3924   3943       }
  3925   3944       sqlite3DebugPrintf(" %-19s", z);
  3926   3945       sqlite3_free(z);
  3927   3946     }
  3928   3947     sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
  3929   3948     sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
         3949  +#ifdef SQLITE_ENABLE_TREE_EXPLAIN
         3950  +  /* If the 0x100 bit of wheretracing is set, then show all of the constraint
         3951  +  ** expressions in the WhereLoop.aLTerm[] array.
         3952  +  */
         3953  +  if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){  /* WHERETRACE 0x100 */
         3954  +    int i;
         3955  +    Vdbe *v = pWInfo->pParse->pVdbe;
         3956  +    sqlite3ExplainBegin(v);
         3957  +    for(i=0; i<p->nLTerm; i++){
         3958  +      WhereTerm *pTerm = p->aLTerm[i];
         3959  +      sqlite3ExplainPrintf(v, "  (%d) #%-2d ", i+1, (int)(pTerm-pWC->a));
         3960  +      sqlite3ExplainPush(v);
         3961  +      whereExplainTerm(v, pTerm);
         3962  +      sqlite3ExplainPop(v);
         3963  +      sqlite3ExplainNL(v);
         3964  +    }
         3965  +    sqlite3ExplainFinish(v);
         3966  +    sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
         3967  +  }
         3968  +#endif
  3930   3969   }
  3931   3970   #endif
  3932   3971   
  3933   3972   /*
  3934   3973   ** Convert bulk memory into a valid WhereLoop that can be passed
  3935   3974   ** to whereLoopClear harmlessly.
  3936   3975   */
................................................................................
  4062   4101     if( pBuilder->pOrSet!=0 ){
  4063   4102   #if WHERETRACE_ENABLED
  4064   4103       u16 n = pBuilder->pOrSet->n;
  4065   4104       int x =
  4066   4105   #endif
  4067   4106       whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
  4068   4107                                       pTemplate->nOut);
  4069         -#if WHERETRACE_ENABLED
         4108  +#if WHERETRACE_ENABLED /* 0x8 */
  4070   4109       if( sqlite3WhereTrace & 0x8 ){
  4071   4110         sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
  4072         -      whereLoopPrint(pTemplate, pWInfo->pTabList);
         4111  +      whereLoopPrint(pTemplate, pBuilder->pWC);
  4073   4112       }
  4074   4113   #endif
  4075   4114       return SQLITE_OK;
  4076   4115     }
  4077   4116   
  4078   4117     /* Search for an existing WhereLoop to overwrite, or which takes
  4079   4118     ** priority over pTemplate.
................................................................................
  4135   4174       }
  4136   4175     }
  4137   4176   
  4138   4177     /* If we reach this point it means that either p[] should be overwritten
  4139   4178     ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
  4140   4179     ** WhereLoop and insert it.
  4141   4180     */
  4142         -#if WHERETRACE_ENABLED
         4181  +#if WHERETRACE_ENABLED /* 0x8 */
  4143   4182     if( sqlite3WhereTrace & 0x8 ){
  4144   4183       if( p!=0 ){
  4145   4184         sqlite3DebugPrintf("ins-del:  ");
  4146         -      whereLoopPrint(p, pWInfo->pTabList);
         4185  +      whereLoopPrint(p, pBuilder->pWC);
  4147   4186       }
  4148   4187       sqlite3DebugPrintf("ins-new:  ");
  4149         -    whereLoopPrint(pTemplate, pWInfo->pTabList);
         4188  +    whereLoopPrint(pTemplate, pBuilder->pWC);
  4150   4189     }
  4151   4190   #endif
  4152   4191     if( p==0 ){
  4153   4192       p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
  4154   4193       if( p==0 ) return SQLITE_NOMEM;
  4155   4194       whereLoopInit(p);
  4156   4195     }
................................................................................
  4163   4202         p->u.btree.pIndex = 0;
  4164   4203       }
  4165   4204     }
  4166   4205     return SQLITE_OK;
  4167   4206   
  4168   4207     /* Jump here if the insert is a no-op */
  4169   4208   whereLoopInsert_noop:
  4170         -#if WHERETRACE_ENABLED
         4209  +#if WHERETRACE_ENABLED /* 0x8 */
  4171   4210     if( sqlite3WhereTrace & 0x8 ){
  4172   4211       sqlite3DebugPrintf("ins-noop: ");
  4173         -    whereLoopPrint(pTemplate, pWInfo->pTabList);
         4212  +    whereLoopPrint(pTemplate, pBuilder->pWC);
  4174   4213     }
  4175   4214   #endif
  4176   4215     return SQLITE_OK;  
  4177   4216   }
  4178   4217   
  4179   4218   /*
  4180   4219   ** Adjust the WhereLoop.nOut value downward to account for terms of the
................................................................................
  5324   5363             ){
  5325   5364               testcase( jj==nTo-1 );
  5326   5365               break;
  5327   5366             }
  5328   5367           }
  5329   5368           if( jj>=nTo ){
  5330   5369             if( nTo>=mxChoice && rCost>=mxCost ){
  5331         -#ifdef WHERETRACE_ENABLED
         5370  +#ifdef WHERETRACE_ENABLED /* 0x4 */
  5332   5371               if( sqlite3WhereTrace&0x4 ){
  5333   5372                 sqlite3DebugPrintf("Skip   %s cost=%-3d,%3d order=%c\n",
  5334   5373                     wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
  5335   5374                     isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
  5336   5375               }
  5337   5376   #endif
  5338   5377               continue;
................................................................................
  5342   5381               /* Increase the size of the aTo set by one */
  5343   5382               jj = nTo++;
  5344   5383             }else{
  5345   5384               /* New path replaces the prior worst to keep count below mxChoice */
  5346   5385               jj = mxI;
  5347   5386             }
  5348   5387             pTo = &aTo[jj];
  5349         -#ifdef WHERETRACE_ENABLED
         5388  +#ifdef WHERETRACE_ENABLED /* 0x4 */
  5350   5389             if( sqlite3WhereTrace&0x4 ){
  5351   5390               sqlite3DebugPrintf("New    %s cost=%-3d,%3d order=%c\n",
  5352   5391                   wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
  5353   5392                   isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
  5354   5393             }
  5355   5394   #endif
  5356   5395           }else{
  5357   5396             if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
  5358         -#ifdef WHERETRACE_ENABLED
         5397  +#ifdef WHERETRACE_ENABLED /* 0x4 */
  5359   5398               if( sqlite3WhereTrace&0x4 ){
  5360   5399                 sqlite3DebugPrintf(
  5361   5400                     "Skip   %s cost=%-3d,%3d order=%c",
  5362   5401                     wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
  5363   5402                     isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
  5364   5403                 sqlite3DebugPrintf("   vs %s cost=%-3d,%d order=%c\n",
  5365   5404                     wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
................................................................................
  5367   5406               }
  5368   5407   #endif
  5369   5408               testcase( pTo->rCost==rCost );
  5370   5409               continue;
  5371   5410             }
  5372   5411             testcase( pTo->rCost==rCost+1 );
  5373   5412             /* A new and better score for a previously created equivalent path */
  5374         -#ifdef WHERETRACE_ENABLED
         5413  +#ifdef WHERETRACE_ENABLED /* 0x4 */
  5375   5414             if( sqlite3WhereTrace&0x4 ){
  5376   5415               sqlite3DebugPrintf(
  5377   5416                   "Update %s cost=%-3d,%3d order=%c",
  5378   5417                   wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
  5379   5418                   isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
  5380   5419               sqlite3DebugPrintf("  was %s cost=%-3d,%3d order=%c\n",
  5381   5420                   wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
................................................................................
  5403   5442                 mxI = jj;
  5404   5443               }
  5405   5444             }
  5406   5445           }
  5407   5446         }
  5408   5447       }
  5409   5448   
  5410         -#ifdef WHERETRACE_ENABLED
         5449  +#ifdef WHERETRACE_ENABLED  /* >=2 */
  5411   5450       if( sqlite3WhereTrace>=2 ){
  5412   5451         sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
  5413   5452         for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
  5414   5453           sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
  5415   5454              wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
  5416   5455              pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
  5417   5456           if( pTo->isOrderedValid && pTo->isOrdered ){
................................................................................
  5812   5851         pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
  5813   5852         pWInfo->pOrderBy = pResultSet;
  5814   5853       }
  5815   5854     }
  5816   5855   
  5817   5856     /* Construct the WhereLoop objects */
  5818   5857     WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
         5858  +  /* Display all terms of the WHERE clause */
         5859  +#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
         5860  +  if( sqlite3WhereTrace & 0x100 ){
         5861  +    int i;
         5862  +    Vdbe *v = pParse->pVdbe;
         5863  +    sqlite3ExplainBegin(v);
         5864  +    for(i=0; i<sWLB.pWC->nTerm; i++){
         5865  +      sqlite3ExplainPrintf(v, "#%-2d ", i);
         5866  +      sqlite3ExplainPush(v);
         5867  +      whereExplainTerm(v, &sWLB.pWC->a[i]);
         5868  +      sqlite3ExplainPop(v);
         5869  +      sqlite3ExplainNL(v);
         5870  +    }
         5871  +    sqlite3ExplainFinish(v);
         5872  +    sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
         5873  +  }
         5874  +#endif
  5819   5875     if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
  5820   5876       rc = whereLoopAddAll(&sWLB);
  5821   5877       if( rc ) goto whereBeginError;
  5822   5878     
  5823   5879       /* Display all of the WhereLoop objects if wheretrace is enabled */
  5824         -#ifdef WHERETRACE_ENABLED
         5880  +#ifdef WHERETRACE_ENABLED /* !=0 */
  5825   5881       if( sqlite3WhereTrace ){
  5826   5882         WhereLoop *p;
  5827   5883         int i;
  5828   5884         static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
  5829   5885                                          "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
  5830   5886         for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
  5831   5887           p->cId = zLabel[i%sizeof(zLabel)];
  5832         -        whereLoopPrint(p, pTabList);
         5888  +        whereLoopPrint(p, sWLB.pWC);
  5833   5889         }
  5834   5890       }
  5835   5891   #endif
  5836   5892     
  5837   5893       wherePathSolver(pWInfo, 0);
  5838   5894       if( db->mallocFailed ) goto whereBeginError;
  5839   5895       if( pWInfo->pOrderBy ){
................................................................................
  5843   5899     }
  5844   5900     if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
  5845   5901        pWInfo->revMask = (Bitmask)(-1);
  5846   5902     }
  5847   5903     if( pParse->nErr || NEVER(db->mallocFailed) ){
  5848   5904       goto whereBeginError;
  5849   5905     }
  5850         -#ifdef WHERETRACE_ENABLED
         5906  +#ifdef WHERETRACE_ENABLED /* !=0 */
  5851   5907     if( sqlite3WhereTrace ){
  5852   5908       int ii;
  5853   5909       sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
  5854   5910       if( pWInfo->bOBSat ){
  5855   5911         sqlite3DebugPrintf(" ORDERBY=0x%llx", pWInfo->revMask);
  5856   5912       }
  5857   5913       switch( pWInfo->eDistinct ){
................................................................................
  5866   5922         case WHERE_DISTINCT_UNORDERED: {
  5867   5923           sqlite3DebugPrintf("  DISTINCT=unordered");
  5868   5924           break;
  5869   5925         }
  5870   5926       }
  5871   5927       sqlite3DebugPrintf("\n");
  5872   5928       for(ii=0; ii<pWInfo->nLevel; ii++){
  5873         -      whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
         5929  +      whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
  5874   5930       }
  5875   5931     }
  5876   5932   #endif
  5877   5933     /* Attempt to omit tables from the join that do not effect the result */
  5878   5934     if( pWInfo->nLevel>=2
  5879   5935      && pResultSet!=0
  5880   5936      && OptimizationEnabled(db, SQLITE_OmitNoopJoin)

Changes to test/auth2.test.

    98     98   SQLITE_UPDATE sqlite_master rootpage main {}
    99     99   SQLITE_UPDATE sqlite_master sql main {}
   100    100   SQLITE_READ sqlite_master ROWID main {}
   101    101   SQLITE_READ sqlite_master name main {}
   102    102   SQLITE_READ sqlite_master rootpage main {}
   103    103   SQLITE_READ sqlite_master sql main {}
   104    104   SQLITE_READ sqlite_master tbl_name main {}
          105  +SQLITE_READ sqlite_master type main {}
   105    106   SQLITE_READ sqlite_master ROWID main {}
   106    107   }
   107    108   do_test auth2-2.2 {
   108    109     set ::authargs {}
   109    110     db eval {
   110    111       CREATE VIEW v2 AS SELECT x+y AS a, y+z AS b from t2;
   111    112     }
................................................................................
   118    119   SQLITE_UPDATE sqlite_master rootpage main {}
   119    120   SQLITE_UPDATE sqlite_master sql main {}
   120    121   SQLITE_READ sqlite_master ROWID main {}
   121    122   SQLITE_READ sqlite_master name main {}
   122    123   SQLITE_READ sqlite_master rootpage main {}
   123    124   SQLITE_READ sqlite_master sql main {}
   124    125   SQLITE_READ sqlite_master tbl_name main {}
          126  +SQLITE_READ sqlite_master type main {}
   125    127   SQLITE_READ sqlite_master ROWID main {}
   126    128   }
   127    129   do_test auth2-2.3 {
   128    130     set ::authargs {}
   129    131     db eval {
   130    132       SELECT a, b FROM v2;
   131    133     }

Changes to test/temptrigger.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   # $Id: temptrigger.test,v 1.3 2009/04/15 13:07:19 drh Exp $
    13     13   
    14     14   set testdir [file dirname $argv0]
    15     15   source $testdir/tester.tcl
           16  +set testprefix temptrigger
    16     17   
    17     18   ifcapable {!trigger || !shared_cache} { finish_test ; return }
    18     19   
    19     20   # Test cases:
    20     21   #
    21     22   #   temptrigger-1.*: Shared cache problem.
    22     23   #   temptrigger-2.*: A similar shared cache problem.
................................................................................
   197    198     # assert if executed.
   198    199     #execsql { DROP TRIGGER tr2 }
   199    200   } {}
   200    201   
   201    202   catch { db close }
   202    203   catch { db2 close }
   203    204   
          205  +
          206  +#-------------------------------------------------------------------------
          207  +# Test that creating a temp table after a temp trigger on the same name
          208  +# has been created is an error.
          209  +#
          210  +reset_db
          211  +do_execsql_test 4.0 {
          212  +  CREATE TABLE t1(x);
          213  +  CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN
          214  +    SELECT 1,2,3;
          215  +  END;
          216  +}
          217  +
          218  +do_execsql_test 4.1 {
          219  +  CREATE TEMP TABLE t1(x);
          220  +}
          221  +
          222  +#-------------------------------------------------------------------------
          223  +# Test that no harm is done if the table a temp trigger is attached to is
          224  +# deleted by an external connection.
          225  +#
          226  +reset_db
          227  +do_execsql_test 5.0 {
          228  +  CREATE TABLE t1(x);
          229  +  CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN SELECT 1,2,3; END;
          230  +}
          231  +
          232  +do_test 5.1 {
          233  +  sqlite3 db2 test.db
          234  +  execsql { DROP TABLE t1 } db2
          235  +} {}
          236  +
          237  +do_execsql_test 5.2 {
          238  +  SELECT * FROM sqlite_master;
          239  +  SELECT * FROM sqlite_temp_master;
          240  +} {
          241  +  trigger tr1 t1 0 
          242  +  {CREATE TRIGGER tr1 BEFORE INSERT ON t1 BEGIN SELECT 1,2,3; END}
          243  +}
          244  +db2 close
          245  +
          246  +#-------------------------------------------------------------------------
          247  +# Check that if a second connection creates a table in an attached database
          248  +# with the same name as a table in the main database that has a temp
          249  +# trigger attached to it nothing goes awry.
          250  +#
          251  +reset_db
          252  +forcedelete test.db2
          253  +
          254  +do_execsql_test 6.0 {
          255  +  CREATE TABLE t1(x);
          256  +  CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN 
          257  +    SELECT raise(ABORT, 'error'); 
          258  +  END;
          259  +  ATTACH 'test.db2' AS aux;
          260  +}
          261  +
          262  +do_test 6.1 {
          263  +  sqlite3 db2 test.db2
          264  +  execsql { CREATE TABLE t1(a, b, c); } db2
          265  +} {}
          266  +
          267  +do_execsql_test 6.2 {
          268  +  SELECT * FROM aux.sqlite_master;
          269  +  INSERT INTO aux.t1 VALUES(1,2,3);
          270  +} {
          271  +  table t1 t1 2 {CREATE TABLE t1(a, b, c)}
          272  +}
          273  +
          274  +do_catchsql_test 6.3 {
          275  +  INSERT INTO main.t1 VALUES(1);
          276  +} {1 error}
          277  +db2 close
          278  +
   204    279   finish_test

Changes to test/transitive1.test.

    97     97   } {1 2 1 3 3 4 3 6}
    98     98   do_execsql_test transitive1-332 {
    99     99     SELECT *
   100    100       FROM t301 CROSS JOIN t302 ON w=y
   101    101      WHERE y BETWEEN 1 AND 4
   102    102      ORDER BY w DESC;
   103    103   } {3 4 3 6 1 2 1 3}
          104  +
          105  +# Ticket [c620261b5b5dc] circa 2013-10-28.
          106  +# Make sureconstraints are not used with LEFT JOINs.
          107  +#
          108  +# The next case is from the ticket report.  It outputs no rows in 3.8.1
          109  +# prior to the bug-fix.
          110  +#
          111  +do_execsql_test transitive1-400 {
          112  +  CREATE TABLE t401(a);
          113  +  CREATE TABLE t402(b);
          114  +  CREATE TABLE t403(c INTEGER PRIMARY KEY);
          115  +  INSERT INTO t401 VALUES(1);
          116  +  INSERT INTO t403 VALUES(1);
          117  +  SELECT '1-row' FROM t401 LEFT JOIN t402 ON b=a JOIN t403 ON c=a;
          118  +} {1-row}
          119  +
          120  +# The following is a script distilled from the XBMC project where the
          121  +# bug was originally encountered.  The correct answer is a single row
          122  +# of output.  Before the bug was fixed, zero rows were generated.
          123  +#
          124  +do_execsql_test transitive1-410 {
          125  +  CREATE TABLE bookmark ( idBookmark integer primary key, idFile integer, timeInSeconds double, totalTimeInSeconds double, thumbNailImage text, player text, playerState text, type integer);
          126  +  CREATE TABLE path ( idPath integer primary key, strPath text, strContent text, strScraper text, strHash text, scanRecursive integer, useFolderNames bool, strSettings text, noUpdate bool, exclude bool, dateAdded text);
          127  +  INSERT INTO "path" VALUES(1,'/tmp/tvshows/','tvshows','metadata.tvdb.com','989B1CE5680A14F5F86123F751169B49',0,0,'<settings><setting id="absolutenumber" value="false" /><setting id="dvdorder" value="false" /><setting id="fanart" value="true" /><setting id="language" value="en" /></settings>',0,0,NULL);
          128  +  INSERT INTO "path" VALUES(2,'/tmp/tvshows/The.Big.Bang.Theory/','','','85E1DAAB2F5FF6EAE8AEDF1B5C882D1E',NULL,NULL,NULL,NULL,NULL,'2013-10-23 18:58:43');
          129  +  CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename text, playCount integer, lastPlayed text, dateAdded text);
          130  +  INSERT INTO "files" VALUES(1,2,'The.Big.Bang.Theory.S01E01.WEB-DL.AAC2.0.H264.mkv',NULL,NULL,'2013-10-23 18:57:36');
          131  +  CREATE TABLE tvshow ( idShow integer primary key,c00 text,c01 text,c02 text,c03 text,c04 text,c05 text,c06 text,c07 text,c08 text,c09 text,c10 text,c11 text,c12 text,c13 text,c14 text,c15 text,c16 text,c17 text,c18 text,c19 text,c20 text,c21 text,c22 text,c23 text);
          132  +  INSERT INTO "tvshow" VALUES(1,'The Big Bang Theory','Leonard Hofstadter and Sheldon Cooper are brilliant physicists, the kind of "beautiful minds" that understand how the universe works. But none of that genius helps them interact with people, especially women. All this begins to change when a free-spirited beauty named Penny moves in next door. Sheldon, Leonard''s roommate, is quite content spending his nights playing Klingon Boggle with their socially dysfunctional friends, fellow CalTech scientists Howard Wolowitz and Raj Koothrappali. However, Leonard sees in Penny a whole new universe of possibilities... including love.','','','9.200000','2007-09-24','<thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g13.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g23.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g18.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g17.jpg</thumb><thumb aspect="banner">http://
          133  +  thetvdb.com/banners/graphical/80379-g6.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g5.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g2.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g11.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g12.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g19.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g3.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g4.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g15.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g22.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g7.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g10.jpg</thumb><thumb
          134  +  aspect="banner">http://thetvdb.com/banners/graphical/80379-g24.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g8.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g9.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g14.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g16.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g21.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-4.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-2.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-3.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-5.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-8.jpg</thumb><thumb aspect="poster" type="season" season="0">http://thetvdb.com/banners/seasons/80379-0-4.jpg</thumb><thumb aspect="poster" type="season"
          135  +  season="1">http://thetvdb.com/banners/seasons/80379-1-12.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-9.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-11.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-9.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-8.jpg</thumb><thumb aspect="poster" type="season" season="7">http://thetvdb.com/banners/seasons/80379-7-3.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-4.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-5.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-9.jpg</thumb><thumb aspect="poster" type="season" season="0">http://thetvdb.com/banners/seasons/80379-0-2.jpg</thumb><thumb aspect="
          136  +  poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-6.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-4.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-2.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-9.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-4.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-2.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-7.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-10.jpg</
          137  +  thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-5.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-5.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-4.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-3.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-6.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2.jpg</thumb><thumb aspect="poster" type="season" season="7">http://thetvdb.com/banners/seasons/80379-7.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-
          138  +  1-7.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-2.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-3.jpg</thumb><thumb aspect="poster" type="season" season="7">http://thetvdb.com/banners/seasons/80379-7-2.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-2.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-5.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-3.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-5.jpg</thumb><thumb aspect="poster" type="season" season="0">http://thetvdb.com/banners/seasons/80379-0.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-5.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/
          139  +  seasons/80379-1-6.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-3.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-8.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-7.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-8.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-7.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-6.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-8.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-11.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-10.jpg</thumb><thumb aspect="poster" type="season" season="1">http://
          140  +  thetvdb.com/banners/seasons/80379-1-8.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-7.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-4.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-3.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-4.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-3.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-7.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-2.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-6.jpg</thumb><thumb aspect="poster" type="season"
          141  +  season="3">http://thetvdb.com/banners/seasons/80379-3-2.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-6.jpg</thumb><thumb aspect="banner" type="season" season="5">http://thetvdb.com/banners/seasonswide/80379-5.jpg</thumb><thumb aspect="banner" type="season" season="3">http://thetvdb.com/banners/seasonswide/80379-3-2.jpg</thumb><thumb aspect="banner" type="season" season="1">http://thetvdb.com/banners/seasonswide/80379-1-2.jpg</thumb><thumb aspect="banner" type="season" season="2">http://thetvdb.com/banners/seasonswide/80379-2-2.jpg</thumb><thumb aspect="banner" type="season" season="4">http://thetvdb.com/banners/seasonswide/80379-4-2.jpg</thumb><thumb aspect="banner" type="season" season="0">http://thetvdb.com/banners/seasonswide/80379-0.jpg</thumb><thumb aspect="banner" type="season" season="0">http://thetvdb.com/banners/seasonswide/80379-0-2.jpg</thumb><thumb aspect="banner" type="season" season="1">http://thetvdb.com/banners/seasonswide/80379-1.jpg</
          142  +  thumb><thumb aspect="banner" type="season" season="2">http://thetvdb.com/banners/seasonswide/80379-2.jpg</thumb><thumb aspect="banner" type="season" season="4">http://thetvdb.com/banners/seasonswide/80379-4.jpg</thumb><thumb aspect="banner" type="season" season="3">http://thetvdb.com/banners/seasonswide/80379-3.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-22.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-18.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-13.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-10.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-16.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-1.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-9.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-2.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-19.jpg</
          143  +  thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-8.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-4.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-20.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-23.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-7.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-3.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-12.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-11.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-15.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-21.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-14.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-17.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-6.jpg</thumb><thumb
          144  +  aspect="poster">http://thetvdb.com/banners/posters/80379-5.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-22.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-18.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-13.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-10.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-16.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-1.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-9.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-2.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-19.jpg</thumb><thumb aspect="
          145  +  poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-8.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-4.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-20.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-23.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-7.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-3.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-12.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-11.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-15.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-21.jpg</
          146  +  thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-14.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-17.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-6.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-5.jpg</thumb>','','Comedy','','<episodeguide><url cache="80379-en.xml">http://thetvdb.com/api/1D62F2F90030C444/series/80379/all/en.zip</url></episodeguide>','<fanart url="http://thetvdb.com/banners/"><thumb dim="1920x1080" colors="|192,185,169|19,20,25|57,70,89|" preview="_cache/fanart/original/80379-2.jpg">fanart/original/80379-2.jpg</thumb><thumb dim="1920x1080" colors="|94,28,16|194,18,38|0,0,8|" preview="_cache/fanart/original/80379-34.jpg">fanart/original/80379-34.jpg</thumb><thumb dim="1280x720" colors="|254,157,210|11,12,7|191,152,111|" preview="_cache/fanart/original/80379-4.jpg">fanart/original/80379-
          147  +  4.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-42.jpg">fanart/original/80379-42.jpg</thumb><thumb dim="1920x1080" colors="|236,187,155|136,136,128|254,254,252|" preview="_cache/fanart/original/80379-37.jpg">fanart/original/80379-37.jpg</thumb><thumb dim="1920x1080" colors="|112,102,152|116,109,116|235,152,146|" preview="_cache/fanart/original/80379-14.jpg">fanart/original/80379-14.jpg</thumb><thumb dim="1920x1080" colors="|150,158,161|174,75,121|150,98,58|" preview="_cache/fanart/original/80379-16.jpg">fanart/original/80379-16.jpg</thumb><thumb dim="1280x720" colors="|224,200,176|11,1,28|164,96,0|" preview="_cache/fanart/original/80379-1.jpg">fanart/original/80379-1.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-35.jpg">fanart/original/80379-35.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-40.jpg">fanart/original/80379-40.jpg</thumb><thumb dim="1920x1080" colors="|255,255,255|30,19,13|155,112,70|"
          148  +  preview="_cache/fanart/original/80379-31.jpg">fanart/original/80379-31.jpg</thumb><thumb dim="1920x1080" colors="|241,195,172|84,54,106|254,221,206|" preview="_cache/fanart/original/80379-29.jpg">fanart/original/80379-29.jpg</thumb><thumb dim="1280x720" colors="|197,167,175|219,29,39|244,208,192|" preview="_cache/fanart/original/80379-11.jpg">fanart/original/80379-11.jpg</thumb><thumb dim="1280x720" colors="|195,129,97|244,192,168|219,148,118|" preview="_cache/fanart/original/80379-24.jpg">fanart/original/80379-24.jpg</thumb><thumb dim="1920x1080" colors="|14,10,11|255,255,255|175,167,164|" preview="_cache/fanart/original/80379-30.jpg">fanart/original/80379-30.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-19.jpg">fanart/original/80379-19.jpg</thumb><thumb dim="1920x1080" colors="|246,199,69|98,55,38|161,127,82|" preview="_cache/fanart/original/80379-9.jpg">fanart/original/80379-9.jpg</thumb><thumb dim="1280x720" colors="|129,22,14|48,50,39|223,182,64|" preview="_cache/
          149  +  fanart/original/80379-13.jpg">fanart/original/80379-13.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-45.jpg">fanart/original/80379-45.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-33.jpg">fanart/original/80379-33.jpg</thumb><thumb dim="1280x720" colors="|103,77,60|224,180,153|129,100,84|" preview="_cache/fanart/original/80379-10.jpg">fanart/original/80379-10.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-23.jpg">fanart/original/80379-23.jpg</thumb><thumb dim="1280x720" colors="|219,29,39|0,4,10|88,117,135|" preview="_cache/fanart/original/80379-12.jpg">fanart/original/80379-12.jpg</thumb><thumb dim="1920x1080" colors="|226,209,165|51,18,9|89,54,24|" preview="_cache/fanart/original/80379-5.jpg">fanart/original/80379-5.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-26.jpg">fanart/original/80379-26.jpg</thumb><thumb dim="1280x720" colors="|249,251,229|126,47,53|251,226,
          150  +  107|" preview="_cache/fanart/original/80379-27.jpg">fanart/original/80379-27.jpg</thumb><thumb dim="1920x1080" colors="|233,218,65|30,27,46|173,53,18|" preview="_cache/fanart/original/80379-32.jpg">fanart/original/80379-32.jpg</thumb><thumb dim="1280x720" colors="|248,248,248|64,54,78|188,193,196|" preview="_cache/fanart/original/80379-3.jpg">fanart/original/80379-3.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-25.jpg">fanart/original/80379-25.jpg</thumb><thumb dim="1280x720" colors="|159,150,133|59,39,32|168,147,104|" preview="_cache/fanart/original/80379-7.jpg">fanart/original/80379-7.jpg</thumb><thumb dim="1920x1080" colors="|221,191,157|11,7,6|237,146,102|" preview="_cache/fanart/original/80379-21.jpg">fanart/original/80379-21.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-28.jpg">fanart/original/80379-28.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-36.jpg">fanart/original/80379-36.jpg</thumb><thumb
          151  +  dim="1920x1080" colors="|253,237,186|33,25,22|245,144,38|" preview="_cache/fanart/original/80379-38.jpg">fanart/original/80379-38.jpg</thumb><thumb dim="1920x1080" colors="|174,111,68|243,115,50|252,226,45|" preview="_cache/fanart/original/80379-20.jpg">fanart/original/80379-20.jpg</thumb><thumb dim="1920x1080" colors="|63,56,123|87,59,47|63,56,123|" preview="_cache/fanart/original/80379-17.jpg">fanart/original/80379-17.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-43.jpg">fanart/original/80379-43.jpg</thumb><thumb dim="1280x720" colors="|69,68,161|142,118,142|222,191,137|" preview="_cache/fanart/original/80379-22.jpg">fanart/original/80379-22.jpg</thumb><thumb dim="1280x720" colors="|1,108,206|242,209,192|250,197,163|" preview="_cache/fanart/original/80379-15.jpg">fanart/original/80379-15.jpg</thumb><thumb dim="1280x720" colors="|239,229,237|0,0,0|167,136,115|" preview="_cache/fanart/original/80379-18.jpg">fanart/original/80379-18.jpg</thumb><thumb dim="1280x720" colors=""
          152  +  preview="_cache/fanart/original/80379-6.jpg">fanart/original/80379-6.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-8.jpg">fanart/original/80379-8.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-41.jpg">fanart/original/80379-41.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-44.jpg">fanart/original/80379-44.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-39.jpg">fanart/original/80379-39.jpg</thumb></fanart>','80379','TV-PG','CBS','','/tmp/tvshows/The.Big.Bang.Theory/','1',NULL,NULL,NULL,NULL,NULL,NULL);
          153  +  CREATE TABLE episode ( idEpisode integer primary key, idFile integer,c00 text,c01 text,c02 text,c03 text,c04 text,c05 text,c06 text,c07 text,c08 text,c09 text,c10 text,c11 text,c12 varchar(24),c13 varchar(24),c14 text,c15 text,c16 text,c17 varchar(24),c18 text,c19 text,c20 text,c21 text,c22 text,c23 text, idShow integer);
          154  +  INSERT INTO "episode" VALUES(1,1,'Pilot','Brilliant physicist roommates Leonard and Sheldon meet their new neighbor Penny, who begins showing them that as much as they know about science, they know little about actual living.','','7.700000','Chuck Lorre / Bill Prady','2007-09-24','<thumb>http://thetvdb.com/banners/episodes/80379/332484.jpg</thumb>','',NULL,'1800','James Burrows','','1','1','','-1','-1','-1','/tmp/tvshows/The.Big.Bang.Theory/The.Big.Bang.Theory.S01E01.WEB-DL.AAC2.0.H264.mkv','2','332484',NULL,NULL,NULL,1);
          155  +  CREATE TABLE tvshowlinkpath (idShow integer, idPath integer);
          156  +  INSERT INTO "tvshowlinkpath" VALUES(1,2);
          157  +  CREATE TABLE seasons ( idSeason integer primary key, idShow integer, season integer);
          158  +  INSERT INTO "seasons" VALUES(1,1,-1);
          159  +  INSERT INTO "seasons" VALUES(2,1,0);
          160  +  INSERT INTO "seasons" VALUES(3,1,1);
          161  +  INSERT INTO "seasons" VALUES(4,1,2);
          162  +  INSERT INTO "seasons" VALUES(5,1,3);
          163  +  INSERT INTO "seasons" VALUES(6,1,4);
          164  +  INSERT INTO "seasons" VALUES(7,1,5);
          165  +  INSERT INTO "seasons" VALUES(8,1,6);
          166  +  INSERT INTO "seasons" VALUES(9,1,7);
          167  +  CREATE TABLE art(art_id INTEGER PRIMARY KEY, media_id INTEGER, media_type TEXT, type TEXT, url TEXT);
          168  +  INSERT INTO "art" VALUES(1,1,'actor','thumb','http://thetvdb.com/banners/actors/73597.jpg');
          169  +  INSERT INTO "art" VALUES(2,2,'actor','thumb','http://thetvdb.com/banners/actors/73596.jpg');
          170  +  INSERT INTO "art" VALUES(3,3,'actor','thumb','http://thetvdb.com/banners/actors/73595.jpg');
          171  +  INSERT INTO "art" VALUES(4,4,'actor','thumb','http://thetvdb.com/banners/actors/73599.jpg');
          172  +  INSERT INTO "art" VALUES(5,5,'actor','thumb','http://thetvdb.com/banners/actors/73598.jpg');
          173  +  INSERT INTO "art" VALUES(6,6,'actor','thumb','http://thetvdb.com/banners/actors/283158.jpg');
          174  +  INSERT INTO "art" VALUES(7,7,'actor','thumb','http://thetvdb.com/banners/actors/283157.jpg');
          175  +  INSERT INTO "art" VALUES(8,8,'actor','thumb','http://thetvdb.com/banners/actors/91271.jpg');
          176  +  INSERT INTO "art" VALUES(9,9,'actor','thumb','http://thetvdb.com/banners/actors/294178.jpg');
          177  +  INSERT INTO "art" VALUES(10,10,'actor','thumb','http://thetvdb.com/banners/actors/283159.jpg');
          178  +  INSERT INTO "art" VALUES(11,1,'tvshow','banner','http://thetvdb.com/banners/graphical/80379-g13.jpg');
          179  +  INSERT INTO "art" VALUES(12,1,'tvshow','fanart','http://thetvdb.com/banners/fanart/original/80379-2.jpg');
          180  +  INSERT INTO "art" VALUES(13,1,'tvshow','poster','http://thetvdb.com/banners/posters/80379-22.jpg');
          181  +  INSERT INTO "art" VALUES(14,1,'season','poster','http://thetvdb.com/banners/posters/80379-22.jpg');
          182  +  INSERT INTO "art" VALUES(15,2,'season','banner','http://thetvdb.com/banners/seasonswide/80379-0.jpg');
          183  +  INSERT INTO "art" VALUES(16,2,'season','poster','http://thetvdb.com/banners/seasons/80379-0-4.jpg');
          184  +  INSERT INTO "art" VALUES(17,3,'season','banner','http://thetvdb.com/banners/seasonswide/80379-1-2.jpg');
          185  +  INSERT INTO "art" VALUES(18,3,'season','poster','http://thetvdb.com/banners/seasons/80379-1-12.jpg');
          186  +  INSERT INTO "art" VALUES(19,4,'season','banner','http://thetvdb.com/banners/seasonswide/80379-2-2.jpg');
          187  +  INSERT INTO "art" VALUES(20,4,'season','poster','http://thetvdb.com/banners/seasons/80379-2-11.jpg');
          188  +  INSERT INTO "art" VALUES(21,5,'season','banner','http://thetvdb.com/banners/seasonswide/80379-3-2.jpg');
          189  +  INSERT INTO "art" VALUES(22,5,'season','poster','http://thetvdb.com/banners/seasons/80379-3-9.jpg');
          190  +  INSERT INTO "art" VALUES(23,6,'season','banner','http://thetvdb.com/banners/seasonswide/80379-4-2.jpg');
          191  +  INSERT INTO "art" VALUES(24,6,'season','poster','http://thetvdb.com/banners/seasons/80379-4-8.jpg');
          192  +  INSERT INTO "art" VALUES(25,7,'season','banner','http://thetvdb.com/banners/seasonswide/80379-5.jpg');
          193  +  INSERT INTO "art" VALUES(26,7,'season','poster','http://thetvdb.com/banners/seasons/80379-5-9.jpg');
          194  +  INSERT INTO "art" VALUES(27,8,'season','poster','http://thetvdb.com/banners/seasons/80379-6-8.jpg');
          195  +  INSERT INTO "art" VALUES(28,9,'season','poster','http://thetvdb.com/banners/seasons/80379-7-3.jpg');
          196  +  INSERT INTO "art" VALUES(29,1,'episode','thumb','http://thetvdb.com/banners/episodes/80379/332484.jpg');
          197  +  CREATE INDEX ix_bookmark ON bookmark (idFile, type);
          198  +  CREATE INDEX ix_path ON path ( strPath );
          199  +  CREATE INDEX ix_files ON files ( idPath, strFilename );
          200  +  CREATE UNIQUE INDEX ix_episode_file_1 on episode (idEpisode, idFile);
          201  +  CREATE UNIQUE INDEX id_episode_file_2 on episode (idFile, idEpisode);
          202  +  CREATE INDEX ix_episode_season_episode on episode (c12, c13);
          203  +  CREATE INDEX ix_episode_bookmark on episode (c17);
          204  +  CREATE INDEX ix_episode_show1 on episode(idEpisode,idShow);
          205  +  CREATE INDEX ix_episode_show2 on episode(idShow,idEpisode);
          206  +  CREATE UNIQUE INDEX ix_tvshowlinkpath_1 ON tvshowlinkpath ( idShow, idPath );
          207  +  CREATE UNIQUE INDEX ix_tvshowlinkpath_2 ON tvshowlinkpath ( idPath, idShow );
          208  +  CREATE INDEX ixEpisodeBasePath ON episode ( c19 );
          209  +  CREATE INDEX ixTVShowBasePath on tvshow ( c17 );
          210  +  CREATE INDEX ix_seasons ON seasons (idShow, season);
          211  +  CREATE INDEX ix_art ON art(media_id, media_type, type);
          212  +  CREATE VIEW episodeview
          213  +  AS
          214  +    SELECT episode.*,
          215  +           files.strfilename           AS strFileName,
          216  +           path.strpath                AS strPath,
          217  +           files.playcount             AS playCount,
          218  +           files.lastplayed            AS lastPlayed,
          219  +           files.dateadded             AS dateAdded,
          220  +           tvshow.c00                  AS strTitle,
          221  +           tvshow.c14                  AS strStudio,
          222  +           tvshow.c05                  AS premiered,
          223  +           tvshow.c13                  AS mpaa,
          224  +           tvshow.c16                  AS strShowPath,
          225  +           bookmark.timeinseconds      AS resumeTimeInSeconds,
          226  +           bookmark.totaltimeinseconds AS totalTimeInSeconds,
          227  +           seasons.idseason            AS idSeason
          228  +    FROM   episode
          229  +           JOIN files
          230  +             ON files.idfile = episode.idfile
          231  +           JOIN tvshow
          232  +             ON tvshow.idshow = episode.idshow
          233  +           LEFT JOIN seasons
          234  +                  ON seasons.idshow = episode.idshow
          235  +                     AND seasons.season = episode.c12
          236  +           JOIN path
          237  +             ON files.idpath = path.idpath
          238  +           LEFT JOIN bookmark
          239  +                  ON bookmark.idfile = episode.idfile
          240  +                     AND bookmark.type = 1; 
          241  +  CREATE VIEW tvshowview
          242  +  AS
          243  +    SELECT tvshow.*,
          244  +           path.strpath                              AS strPath,
          245  +           path.dateadded                            AS dateAdded,
          246  +           Max(files.lastplayed)                     AS lastPlayed,
          247  +           NULLIF(Count(episode.c12), 0)             AS totalCount,
          248  +           Count(files.playcount)                    AS watchedcount,
          249  +           NULLIF(Count(DISTINCT( episode.c12 )), 0) AS totalSeasons
          250  +    FROM   tvshow
          251  +           LEFT JOIN tvshowlinkpath
          252  +                  ON tvshowlinkpath.idshow = tvshow.idshow
          253  +           LEFT JOIN path
          254  +                  ON path.idpath = tvshowlinkpath.idpath
          255  +           LEFT JOIN episode
          256  +                  ON episode.idshow = tvshow.idshow
          257  +           LEFT JOIN files
          258  +                  ON files.idfile = episode.idfile
          259  +    GROUP  BY tvshow.idshow; 
          260  +  SELECT
          261  +    episodeview.c12,
          262  +    path.strPath,
          263  +    tvshowview.c00,
          264  +    tvshowview.c01,
          265  +    tvshowview.c05,
          266  +    tvshowview.c08,
          267  +    tvshowview.c14,
          268  +    tvshowview.c13,
          269  +    seasons.idSeason,
          270  +    count(1),
          271  +    count(files.playCount)
          272  +  FROM episodeview
          273  +      JOIN tvshowview ON tvshowview.idShow = episodeview.idShow
          274  +      JOIN seasons ON (seasons.idShow = tvshowview.idShow
          275  +                       AND seasons.season = episodeview.c12)
          276  +      JOIN files ON files.idFile = episodeview.idFile
          277  +      JOIN tvshowlinkpath ON tvshowlinkpath.idShow = tvshowview.idShow
          278  +      JOIN path ON path.idPath = tvshowlinkpath.idPath
          279  +  WHERE tvshowview.idShow = 1
          280  +  GROUP BY episodeview.c12;
          281  +} {1 /tmp/tvshows/The.Big.Bang.Theory/ {The Big Bang Theory} {Leonard Hofstadter and Sheldon Cooper are brilliant physicists, the kind of "beautiful minds" that understand how the universe works. But none of that genius helps them interact with people, especially women. All this begins to change when a free-spirited beauty named Penny moves in next door. Sheldon, Leonard's roommate, is quite content spending his nights playing Klingon Boggle with their socially dysfunctional friends, fellow CalTech scientists Howard Wolowitz and Raj Koothrappali. However, Leonard sees in Penny a whole new universe of possibilities... including love.} 2007-09-24 Comedy CBS TV-PG 3 1 0}
          282  +
   104    283   
   105    284   finish_test

Changes to tool/mkpragmatab.tcl.

    10     10   # new pragma.
    11     11   #
    12     12   
    13     13   set pragma_def {
    14     14     NAME: full_column_names
    15     15     TYPE: FLAG
    16     16     ARG:  SQLITE_FullColNames
           17  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    17     18   
    18     19     NAME: short_column_names
    19     20     TYPE: FLAG
    20     21     ARG:  SQLITE_ShortColNames
           22  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    21     23   
    22     24     NAME: count_changes
    23     25     TYPE: FLAG
    24     26     ARG:  SQLITE_CountRows
           27  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    25     28   
    26     29     NAME: empty_result_callbacks
    27     30     TYPE: FLAG
    28     31     ARG:  SQLITE_NullCallback
           32  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    29     33   
    30     34     NAME: legacy_file_format
    31     35     TYPE: FLAG
    32     36     ARG:  SQLITE_LegacyFileFmt
           37  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    33     38   
    34     39     NAME: fullfsync
    35     40     TYPE: FLAG
    36     41     ARG:  SQLITE_FullFSync
           42  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    37     43   
    38     44     NAME: checkpoint_fullfsync
    39     45     TYPE: FLAG
    40     46     ARG:  SQLITE_CkptFullFSync
           47  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    41     48   
    42     49     NAME: cache_spill
    43     50     TYPE: FLAG
    44     51     ARG:  SQLITE_CacheSpill
           52  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    45     53   
    46     54     NAME: reverse_unordered_selects
    47     55     TYPE: FLAG
    48     56     ARG:  SQLITE_ReverseOrder
           57  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    49     58   
    50     59     NAME: query_only
    51     60     TYPE: FLAG
    52     61     ARG:  SQLITE_QueryOnly
           62  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    53     63   
    54     64     NAME: automatic_index
    55     65     TYPE: FLAG
    56     66     ARG:  SQLITE_AutoIndex
           67  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    57     68     IF:   !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
    58     69   
    59     70     NAME: sql_trace
    60     71     TYPE: FLAG
    61     72     ARG:  SQLITE_SqlTrace
           73  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    62     74     IF:   defined(SQLITE_DEBUG)
    63     75   
    64     76     NAME: vdbe_listing
    65     77     TYPE: FLAG
    66     78     ARG:  SQLITE_VdbeListing
           79  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    67     80     IF:   defined(SQLITE_DEBUG)
    68     81   
    69     82     NAME: vdbe_trace
    70     83     TYPE: FLAG
    71     84     ARG:  SQLITE_VdbeTrace
           85  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    72     86     IF:   defined(SQLITE_DEBUG)
    73     87   
    74     88     NAME: vdbe_addoptrace
    75     89     TYPE: FLAG
    76     90     ARG:  SQLITE_VdbeAddopTrace
           91  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    77     92     IF:   defined(SQLITE_DEBUG)
    78     93   
    79     94     NAME: vdbe_debug
    80     95     TYPE: FLAG
    81     96     ARG:  SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
           97  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    82     98     IF:   defined(SQLITE_DEBUG)
    83     99   
    84    100     NAME: ignore_check_constraints
    85    101     TYPE: FLAG
    86    102     ARG:  SQLITE_IgnoreChecks
          103  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    87    104     IF:   !defined(SQLITE_OMIT_CHECK)
    88    105   
    89    106     NAME: writable_schema
    90    107     TYPE: FLAG
    91    108     ARG:  SQLITE_WriteSchema|SQLITE_RecoveryMode
          109  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    92    110   
    93    111     NAME: read_uncommitted
    94    112     TYPE: FLAG
    95    113     ARG:  SQLITE_ReadUncommitted
          114  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
    96    115   
    97    116     NAME: recursive_triggers
    98    117     TYPE: FLAG
    99    118     ARG:  SQLITE_RecTriggers
          119  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   100    120   
   101    121     NAME: foreign_keys
   102    122     TYPE: FLAG
   103    123     ARG:  SQLITE_ForeignKeys
          124  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   104    125     IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   105    126   
   106    127     NAME: defer_foreign_keys
   107    128     TYPE: FLAG
   108    129     ARG:  SQLITE_DeferFKs
          130  +  IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   109    131     IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   110    132   
   111    133     NAME: default_cache_size
   112    134     FLAG: NeedSchema
   113    135     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   114    136   
   115    137     NAME: page_size
................................................................................
   263    285     IF:   defined(SQLITE_HAS_CODEC)
   264    286   
   265    287     NAME: activate_extensions
   266    288     IF:   defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
   267    289   
   268    290     NAME: soft_heap_limit
   269    291   }
          292  +fconfigure stdout -translation lf
   270    293   set name {}
   271    294   set type {}
   272    295   set if {}
   273    296   set flags {}
   274    297   set arg 0
   275    298   proc record_one {} {
   276    299     global name type if arg allbyname typebyif flags
................................................................................
   292    315       set name $val
   293    316       set type [string toupper $val]
   294    317     } elseif {$id=="TYPE"} {
   295    318       set type $val
   296    319     } elseif {$id=="ARG"} {
   297    320       set arg $val
   298    321     } elseif {$id=="IF"} {
   299         -    set if $val
          322  +    lappend if $val
   300    323     } elseif {$id=="FLAG"} {
   301    324       foreach term [split $val] {
   302    325         lappend flags $term
   303    326         set allflags($term) 1
   304    327       }
   305    328     } else {
   306    329       error "bad pragma_def line: $line"
................................................................................
   358    381   puts "\175 aPragmaNames\[\] = \173"
   359    382   
   360    383   set current_if {}
   361    384   set spacer [format {    %26s } {}]
   362    385   foreach name $allnames {
   363    386     foreach {type arg if flag} $allbyname($name) break
   364    387     if {$if!=$current_if} {
   365         -    if {$current_if!=""} {puts "#endif"}
          388  +    if {$current_if!=""} {
          389  +      foreach this_if $current_if {
          390  +        puts "#endif"
          391  +      }
          392  +    }
   366    393       set current_if $if
   367         -    if {$current_if!=""} {puts "#if $current_if"}
          394  +    if {$current_if!=""} {
          395  +      foreach this_if $current_if {
          396  +        puts "#if $this_if"
          397  +      }
          398  +    }
   368    399     }
   369    400     set typex [format PragTyp_%-23s $type,]
   370    401     if {$flag==""} {
   371    402       set flagx "0"
   372    403     } else {
   373    404       set flagx PragFlag_[join $flag {|PragFlag_}]
   374    405     }
   375    406     puts "  \173 /* zName:     */ \"$name\","
   376    407     puts "    /* ePragTyp:  */ PragTyp_$type,"
   377    408     puts "    /* ePragFlag: */ $flagx,"
   378    409     puts "    /* iArg:      */ $arg \175,"
   379    410   }
   380         -if {$current_if!=""} {puts "#endif"}
          411  +if {$current_if!=""} {
          412  +  foreach this_if $current_if {
          413  +    puts "#endif"
          414  +  }
          415  +}
   381    416   puts "\175;"
   382    417   
   383    418   # count the number of pragmas, for information purposes
   384    419   #
   385    420   set allcnt 0
   386    421   set dfltcnt 0
   387    422   foreach name $allnames {
   388    423     incr allcnt
   389    424     set if [lindex $allbyname($name) 2]
   390    425     if {[regexp {^defined} $if] || [regexp {[^!]defined} $if]} continue
   391    426     incr dfltcnt
   392    427   }
   393    428   puts "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"