System.Data.SQLite
Check-in [0b4eec86dd]
Not logged in

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

Overview
Comment:SQLite 3.3.10
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 0b4eec86ddaafe92d0cc88940ff7d8d74cfa9989
User & Date: rmsimpson 2007-01-10 14:50:45
Context
2007-01-10
15:50
no message check-in: 2f09f48056 user: rmsimpson tags: sourceforge
14:50
SQLite 3.3.10 check-in: 0b4eec86dd user: rmsimpson tags: sourceforge
14:49
1.0.39.0 check-in: e8355ff70e user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/src/alter.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that used to generate VDBE code
    13     13   ** that implements the ALTER TABLE command.
    14     14   **
    15         -** $Id: alter.c,v 1.24 2006/10/12 21:34:20 rmsimpson Exp $
           15  +** $Id: alter.c,v 1.25 2007/01/10 14:50:45 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** The code in this file only exists if we are not omitting the
    22     22   ** ALTER TABLE logic from the build.

Changes to SQLite.Interop/src/analyze.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code associated with the ANALYZE command.
    13     13   **
    14         -** @(#) $Id: analyze.c,v 1.17 2006/10/12 21:34:20 rmsimpson Exp $
           14  +** @(#) $Id: analyze.c,v 1.18 2007/01/10 14:50:45 rmsimpson Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_ANALYZE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This routine generates code that opens the sqlite_stat1 table on cursor
    21     21   ** iStatCur.

Changes to SQLite.Interop/src/attach.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the ATTACH and DETACH commands.
    13     13   **
    14         -** $Id: attach.c,v 1.23 2006/10/12 21:34:20 rmsimpson Exp $
           14  +** $Id: attach.c,v 1.24 2007/01/10 14:50:45 rmsimpson Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** Resolve an expression that was part of an ATTACH or DETACH statement. This
    20     20   ** is slightly different from resolving a normal SQL expression, because simple
    21     21   ** identifiers are treated as strings, not possible column names or aliases.

Changes to SQLite.Interop/src/auth.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the sqlite3_set_authorizer()
    13     13   ** API.  This facility is an optional feature of the library.  Embedded
    14     14   ** systems that do not need this facility may omit it by recompiling
    15     15   ** the library with -DSQLITE_OMIT_AUTHORIZATION=1
    16     16   **
    17         -** $Id: auth.c,v 1.23 2006/10/12 21:34:20 rmsimpson Exp $
           17  +** $Id: auth.c,v 1.24 2007/01/10 14:50:45 rmsimpson Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   
    21     21   /*
    22     22   ** All of the code in this file may be omitted by defining a single
    23     23   ** macro.
    24     24   */

Changes to SQLite.Interop/src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.26 2006/10/12 21:34:20 rmsimpson Exp $
           12  +** $Id: btree.c,v 1.27 2007/01/10 14:50:45 rmsimpson Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
   417    417   /*
   418    418   ** The TRACE macro will print high-level status information about the
   419    419   ** btree operation when the global variable sqlite3_btree_trace is
   420    420   ** enabled.
   421    421   */
   422    422   #if SQLITE_TEST
   423    423   # define TRACE(X)   if( sqlite3_btree_trace )\
   424         -                        { sqlite3DebugPrintf X; fflush(stdout); }
          424  +/*                        { sqlite3DebugPrintf X; fflush(stdout); } */ \
          425  +{ printf X; fflush(stdout); }
   425    426   int sqlite3_btree_trace=0;  /* True to enable tracing */
   426    427   #else
   427    428   # define TRACE(X)
   428    429   #endif
   429    430   
   430    431   /*
   431    432   ** Forward declaration
................................................................................
  1035   1036     u8 *pCell;
  1036   1037     pCell = findOverflowCell(pPage, iCell);
  1037   1038     return ptrmapPutOvflPtr(pPage, pCell);
  1038   1039   }
  1039   1040   #endif
  1040   1041   
  1041   1042   
  1042         -/*
  1043         -** Do sanity checking on a page.  Throw an exception if anything is
  1044         -** not right.
  1045         -**
  1046         -** This routine is used for internal error checking only.  It is omitted
  1047         -** from most builds.
  1048         -*/
  1049         -#if defined(BTREE_DEBUG) && !defined(NDEBUG) && 0
  1050         -static void _pageIntegrity(MemPage *pPage){
  1051         -  int usableSize;
  1052         -  u8 *data;
  1053         -  int i, j, idx, c, pc, hdr, nFree;
  1054         -  int cellOffset;
  1055         -  int nCell, cellLimit;
  1056         -  u8 *used;
  1057         -
  1058         -  used = sqliteMallocRaw( pPage->pBt->pageSize );
  1059         -  if( used==0 ) return;
  1060         -  usableSize = pPage->pBt->usableSize;
  1061         -  assert( pPage->aData==&((unsigned char*)pPage)[-pPage->pBt->pageSize] );
  1062         -  hdr = pPage->hdrOffset;
  1063         -  assert( hdr==(pPage->pgno==1 ? 100 : 0) );
  1064         -  assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) );
  1065         -  c = pPage->aData[hdr];
  1066         -  if( pPage->isInit ){
  1067         -    assert( pPage->leaf == ((c & PTF_LEAF)!=0) );
  1068         -    assert( pPage->zeroData == ((c & PTF_ZERODATA)!=0) );
  1069         -    assert( pPage->leafData == ((c & PTF_LEAFDATA)!=0) );
  1070         -    assert( pPage->intKey == ((c & (PTF_INTKEY|PTF_LEAFDATA))!=0) );
  1071         -    assert( pPage->hasData ==
  1072         -             !(pPage->zeroData || (!pPage->leaf && pPage->leafData)) );
  1073         -    assert( pPage->cellOffset==pPage->hdrOffset+12-4*pPage->leaf );
  1074         -    assert( pPage->nCell = get2byte(&pPage->aData[hdr+3]) );
  1075         -  }
  1076         -  data = pPage->aData;
  1077         -  memset(used, 0, usableSize);
  1078         -  for(i=0; i<hdr+10-pPage->leaf*4; i++) used[i] = 1;
  1079         -  nFree = 0;
  1080         -  pc = get2byte(&data[hdr+1]);
  1081         -  while( pc ){
  1082         -    int size;
  1083         -    assert( pc>0 && pc<usableSize-4 );
  1084         -    size = get2byte(&data[pc+2]);
  1085         -    assert( pc+size<=usableSize );
  1086         -    nFree += size;
  1087         -    for(i=pc; i<pc+size; i++){
  1088         -      assert( used[i]==0 );
  1089         -      used[i] = 1;
  1090         -    }
  1091         -    pc = get2byte(&data[pc]);
  1092         -  }
  1093         -  idx = 0;
  1094         -  nCell = get2byte(&data[hdr+3]);
  1095         -  cellLimit = get2byte(&data[hdr+5]);
  1096         -  assert( pPage->isInit==0 
  1097         -         || pPage->nFree==nFree+data[hdr+7]+cellLimit-(cellOffset+2*nCell) );
  1098         -  cellOffset = pPage->cellOffset;
  1099         -  for(i=0; i<nCell; i++){
  1100         -    int size;
  1101         -    pc = get2byte(&data[cellOffset+2*i]);
  1102         -    assert( pc>0 && pc<usableSize-4 );
  1103         -    size = cellSize(pPage, &data[pc]);
  1104         -    assert( pc+size<=usableSize );
  1105         -    for(j=pc; j<pc+size; j++){
  1106         -      assert( used[j]==0 );
  1107         -      used[j] = 1;
  1108         -    }
  1109         -  }
  1110         -  for(i=cellOffset+2*nCell; i<cellimit; i++){
  1111         -    assert( used[i]==0 );
  1112         -    used[i] = 1;
  1113         -  }
  1114         -  nFree = 0;
  1115         -  for(i=0; i<usableSize; i++){
  1116         -    assert( used[i]<=1 );
  1117         -    if( used[i]==0 ) nFree++;
  1118         -  }
  1119         -  assert( nFree==data[hdr+7] );
  1120         -  sqliteFree(used);
  1121         -}
  1122         -#define pageIntegrity(X) _pageIntegrity(X)
  1123         -#else
  1124         -# define pageIntegrity(X)
  1125         -#endif
  1126         -
  1127   1043   /* A bunch of assert() statements to check the transaction state variables
  1128   1044   ** of handle p (type Btree*) are internally consistent.
  1129   1045   */
  1130   1046   #define btreeIntegrity(p) \
  1131   1047     assert( p->inTrans!=TRANS_NONE || p->pBt->nTransaction<p->pBt->nRef ); \
  1132   1048     assert( p->pBt->nTransaction<=p->pBt->nRef ); \
  1133   1049     assert( p->pBt->inTransaction!=TRANS_NONE || p->pBt->nTransaction==0 ); \
................................................................................
  1426   1342     pPage->nFree = nFree;
  1427   1343     if( nFree>=usableSize ){
  1428   1344       /* Free space cannot exceed total page size */
  1429   1345       return SQLITE_CORRUPT_BKPT; 
  1430   1346     }
  1431   1347   
  1432   1348     pPage->isInit = 1;
  1433         -  pageIntegrity(pPage);
  1434   1349     return SQLITE_OK;
  1435   1350   }
  1436   1351   
  1437   1352   /*
  1438   1353   ** Set up a raw page so that it looks like a database page holding
  1439   1354   ** no entries.
  1440   1355   */
................................................................................
  1457   1372     decodeFlags(pPage, flags);
  1458   1373     pPage->hdrOffset = hdr;
  1459   1374     pPage->cellOffset = first;
  1460   1375     pPage->nOverflow = 0;
  1461   1376     pPage->idxShift = 0;
  1462   1377     pPage->nCell = 0;
  1463   1378     pPage->isInit = 1;
  1464         -  pageIntegrity(pPage);
  1465   1379   }
  1466   1380   
  1467   1381   /*
  1468   1382   ** Get a page from the pager.  Initialize the MemPage.pBt and
  1469   1383   ** MemPage.aData elements if needed.
  1470   1384   */
  1471   1385   static int getPage(BtShared *pBt, Pgno pgno, MemPage **ppPage){
................................................................................
  1632   1546     pBt = sqliteMalloc( sizeof(*pBt) );
  1633   1547     if( pBt==0 ){
  1634   1548       *ppBtree = 0;
  1635   1549       sqliteFree(p);
  1636   1550       return SQLITE_NOMEM;
  1637   1551     }
  1638   1552     rc = sqlite3pager_open(&pBt->pPager, zFilename, EXTRA_SIZE, flags);
         1553  +  if( rc==SQLITE_OK ){
         1554  +    rc = sqlite3pager_read_fileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
         1555  +  }
  1639   1556     if( rc!=SQLITE_OK ){
  1640         -    if( pBt->pPager ) sqlite3pager_close(pBt->pPager);
         1557  +    if( pBt->pPager ){
         1558  +      sqlite3pager_close(pBt->pPager);
         1559  +    }
  1641   1560       sqliteFree(pBt);
  1642   1561       sqliteFree(p);
  1643   1562       *ppBtree = 0;
  1644   1563       return rc;
  1645   1564     }
  1646   1565     p->pBt = pBt;
  1647   1566   
  1648   1567     sqlite3pager_set_destructor(pBt->pPager, pageDestructor);
  1649   1568     sqlite3pager_set_reiniter(pBt->pPager, pageReinit);
  1650   1569     pBt->pCursor = 0;
  1651   1570     pBt->pPage1 = 0;
  1652   1571     pBt->readOnly = sqlite3pager_isreadonly(pBt->pPager);
  1653         -  sqlite3pager_read_fileheader(pBt->pPager, sizeof(zDbHeader), zDbHeader);
  1654   1572     pBt->pageSize = get2byte(&zDbHeader[16]);
  1655   1573     if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
  1656   1574          || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
  1657   1575       pBt->pageSize = SQLITE_DEFAULT_PAGE_SIZE;
  1658   1576       pBt->maxEmbedFrac = 64;   /* 25% */
  1659   1577       pBt->minEmbedFrac = 32;   /* 12.5% */
  1660   1578       pBt->minLeafFrac = 32;    /* 12.5% */
................................................................................
  2009   1927   **
  2010   1928   ** If there are any outstanding cursors, this routine is a no-op.
  2011   1929   **
  2012   1930   ** If there is a transaction in progress, this routine is a no-op.
  2013   1931   */
  2014   1932   static void unlockBtreeIfUnused(BtShared *pBt){
  2015   1933     if( pBt->inTransaction==TRANS_NONE && pBt->pCursor==0 && pBt->pPage1!=0 ){
  2016         -    if( pBt->pPage1->aData==0 ){
  2017         -      MemPage *pPage = pBt->pPage1;
  2018         -      pPage->aData = &((u8*)pPage)[-pBt->pageSize];
  2019         -      pPage->pBt = pBt;
  2020         -      pPage->pgno = 1;
         1934  +    if( sqlite3pager_refcount(pBt->pPager)>=1 ){
         1935  +      if( pBt->pPage1->aData==0 ){
         1936  +        MemPage *pPage = pBt->pPage1;
         1937  +        pPage->aData = &((u8*)pPage)[-pBt->pageSize];
         1938  +        pPage->pBt = pBt;
         1939  +        pPage->pgno = 1;
         1940  +      }
         1941  +      releasePage(pBt->pPage1);
  2021   1942       }
  2022         -    releasePage(pBt->pPage1);
  2023   1943       pBt->pPage1 = 0;
  2024   1944       pBt->inStmt = 0;
  2025   1945     }
  2026   1946   }
  2027   1947   
  2028   1948   /*
  2029   1949   ** Create a new database by initializing the first page of the
................................................................................
  2967   2887     int ovflSize;
  2968   2888     u32 nKey;
  2969   2889   
  2970   2890     assert( pCur!=0 && pCur->pPage!=0 );
  2971   2891     assert( pCur->eState==CURSOR_VALID );
  2972   2892     pBt = pCur->pBtree->pBt;
  2973   2893     pPage = pCur->pPage;
  2974         -  pageIntegrity(pPage);
  2975   2894     assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
  2976   2895     getCellInfo(pCur);
  2977   2896     aPayload = pCur->info.pCell + pCur->info.nHeader;
  2978   2897     if( pPage->intKey ){
  2979   2898       nKey = 0;
  2980   2899     }else{
  2981   2900       nKey = pCur->info.nKey;
................................................................................
  3105   3024     MemPage *pPage;
  3106   3025     u32 nKey;
  3107   3026     int nLocal;
  3108   3027   
  3109   3028     assert( pCur!=0 && pCur->pPage!=0 );
  3110   3029     assert( pCur->eState==CURSOR_VALID );
  3111   3030     pPage = pCur->pPage;
  3112         -  pageIntegrity(pPage);
  3113   3031     assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
  3114   3032     getCellInfo(pCur);
  3115   3033     aPayload = pCur->info.pCell;
  3116   3034     aPayload += pCur->info.nHeader;
  3117   3035     if( pPage->intKey ){
  3118   3036       nKey = 0;
  3119   3037     }else{
................................................................................
  3167   3085     MemPage *pNewPage;
  3168   3086     MemPage *pOldPage;
  3169   3087     BtShared *pBt = pCur->pBtree->pBt;
  3170   3088   
  3171   3089     assert( pCur->eState==CURSOR_VALID );
  3172   3090     rc = getAndInitPage(pBt, newPgno, &pNewPage, pCur->pPage);
  3173   3091     if( rc ) return rc;
  3174         -  pageIntegrity(pNewPage);
  3175   3092     pNewPage->idxParent = pCur->idx;
  3176   3093     pOldPage = pCur->pPage;
  3177   3094     pOldPage->idxShift = 0;
  3178   3095     releasePage(pOldPage);
  3179   3096     pCur->pPage = pNewPage;
  3180   3097     pCur->idx = 0;
  3181   3098     pCur->info.nSize = 0;
................................................................................
  3215   3132     MemPage *pPage;
  3216   3133     int idxParent;
  3217   3134   
  3218   3135     assert( pCur->eState==CURSOR_VALID );
  3219   3136     pPage = pCur->pPage;
  3220   3137     assert( pPage!=0 );
  3221   3138     assert( !isRootPage(pPage) );
  3222         -  pageIntegrity(pPage);
  3223   3139     pParent = pPage->pParent;
  3224   3140     assert( pParent!=0 );
  3225         -  pageIntegrity(pParent);
  3226   3141     idxParent = pPage->idxParent;
  3227   3142     sqlite3pager_ref(pParent->aData);
  3228   3143     releasePage(pPage);
  3229   3144     pCur->pPage = pParent;
  3230   3145     pCur->info.nSize = 0;
  3231   3146     assert( pParent->idxShift==0 );
  3232   3147     pCur->idx = idxParent;
................................................................................
  3248   3163       if( 
  3249   3164         SQLITE_OK!=(rc = getAndInitPage(pBt, pCur->pgnoRoot, &pRoot, 0))
  3250   3165       ){
  3251   3166         pCur->eState = CURSOR_INVALID;
  3252   3167         return rc;
  3253   3168       }
  3254   3169       releasePage(pCur->pPage);
  3255         -    pageIntegrity(pRoot);
  3256   3170       pCur->pPage = pRoot;
  3257   3171     }
  3258   3172     pCur->idx = 0;
  3259   3173     pCur->info.nSize = 0;
  3260   3174     if( pRoot->nCell==0 && !pRoot->leaf ){
  3261   3175       Pgno subpage;
  3262   3176       assert( pRoot->pgno==1 );
................................................................................
  3392   3306     assert( pCur->pPage->isInit );
  3393   3307     tryRightmost = pCur->pPage->intKey;
  3394   3308     if( pCur->eState==CURSOR_INVALID ){
  3395   3309       *pRes = -1;
  3396   3310       assert( pCur->pPage->nCell==0 );
  3397   3311       return SQLITE_OK;
  3398   3312     }
  3399         -   for(;;){
         3313  +  for(;;){
  3400   3314       int lwr, upr;
  3401   3315       Pgno chldPg;
  3402   3316       MemPage *pPage = pCur->pPage;
  3403   3317       int c = -1;  /* pRes return if table is empty must be -1 */
  3404   3318       lwr = 0;
  3405   3319       upr = pPage->nCell-1;
  3406   3320       if( !pPage->intKey && pKey==0 ){
  3407   3321         return SQLITE_CORRUPT_BKPT;
  3408   3322       }
  3409         -    pageIntegrity(pPage);
  3410   3323       while( lwr<=upr ){
  3411   3324         void *pCellKey;
  3412   3325         i64 nCellKey;
  3413   3326         pCur->idx = (lwr+upr)/2;
  3414   3327         pCur->info.nSize = 0;
  3415   3328         if( pPage->intKey ){
  3416   3329           u8 *pCell;
................................................................................
  3655   3568     Pgno nearby,
  3656   3569     u8 exact
  3657   3570   ){
  3658   3571     MemPage *pPage1;
  3659   3572     int rc;
  3660   3573     int n;     /* Number of pages on the freelist */
  3661   3574     int k;     /* Number of leaves on the trunk of the freelist */
         3575  +  MemPage *pTrunk = 0;
         3576  +  MemPage *pPrevTrunk = 0;
  3662   3577   
  3663   3578     pPage1 = pBt->pPage1;
  3664   3579     n = get4byte(&pPage1->aData[36]);
  3665   3580     if( n>0 ){
  3666   3581       /* There are pages on the freelist.  Reuse one of those pages. */
  3667         -    MemPage *pTrunk = 0;
  3668   3582       Pgno iTrunk;
  3669         -    MemPage *pPrevTrunk = 0;
  3670   3583       u8 searchList = 0; /* If the free-list must be searched for 'nearby' */
  3671   3584       
  3672   3585       /* If the 'exact' parameter was true and a query of the pointer-map
  3673   3586       ** shows that the page 'nearby' is somewhere on the free-list, then
  3674   3587       ** the entire-list will be searched for that page.
  3675   3588       */
  3676   3589   #ifndef SQLITE_OMIT_AUTOVACUUM
................................................................................
  3703   3616         if( pPrevTrunk ){
  3704   3617           iTrunk = get4byte(&pPrevTrunk->aData[0]);
  3705   3618         }else{
  3706   3619           iTrunk = get4byte(&pPage1->aData[32]);
  3707   3620         }
  3708   3621         rc = getPage(pBt, iTrunk, &pTrunk);
  3709   3622         if( rc ){
  3710         -        releasePage(pPrevTrunk);
  3711         -        return rc;
  3712         -      }
  3713         -
  3714         -      /* TODO: This should move to after the loop? */
  3715         -      rc = sqlite3pager_write(pTrunk->aData);
  3716         -      if( rc ){
  3717         -        releasePage(pTrunk);
  3718         -        releasePage(pPrevTrunk);
  3719         -        return rc;
         3623  +        pTrunk = 0;
         3624  +        goto end_allocate_page;
  3720   3625         }
  3721   3626   
  3722   3627         k = get4byte(&pTrunk->aData[4]);
  3723   3628         if( k==0 && !searchList ){
  3724   3629           /* The trunk has no leaves and the list is not being searched. 
  3725   3630           ** So extract the trunk page itself and use it as the newly 
  3726   3631           ** allocated page */
  3727   3632           assert( pPrevTrunk==0 );
         3633  +        rc = sqlite3pager_write(pTrunk->aData);
         3634  +        if( rc ){
         3635  +          goto end_allocate_page;
         3636  +        }
  3728   3637           *pPgno = iTrunk;
  3729   3638           memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
  3730   3639           *ppPage = pTrunk;
  3731   3640           pTrunk = 0;
  3732   3641           TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
  3733   3642         }else if( k>pBt->usableSize/4 - 8 ){
  3734   3643           /* Value of k is out of range.  Database corruption */
  3735         -        return SQLITE_CORRUPT_BKPT;
         3644  +        rc = SQLITE_CORRUPT_BKPT;
         3645  +        goto end_allocate_page;
  3736   3646   #ifndef SQLITE_OMIT_AUTOVACUUM
  3737   3647         }else if( searchList && nearby==iTrunk ){
  3738   3648           /* The list is being searched and this trunk page is the page
  3739   3649           ** to allocate, regardless of whether it has leaves.
  3740   3650           */
  3741   3651           assert( *pPgno==iTrunk );
  3742   3652           *ppPage = pTrunk;
  3743   3653           searchList = 0;
         3654  +        rc = sqlite3pager_write(pTrunk->aData);
         3655  +        if( rc ){
         3656  +          goto end_allocate_page;
         3657  +        }
  3744   3658           if( k==0 ){
  3745   3659             if( !pPrevTrunk ){
  3746   3660               memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
  3747   3661             }else{
  3748   3662               memcpy(&pPrevTrunk->aData[0], &pTrunk->aData[0], 4);
  3749   3663             }
  3750   3664           }else{
................................................................................
  3752   3666             ** pointers to free-list leaves. The first leaf becomes a trunk
  3753   3667             ** page in this case.
  3754   3668             */
  3755   3669             MemPage *pNewTrunk;
  3756   3670             Pgno iNewTrunk = get4byte(&pTrunk->aData[8]);
  3757   3671             rc = getPage(pBt, iNewTrunk, &pNewTrunk);
  3758   3672             if( rc!=SQLITE_OK ){
  3759         -            releasePage(pTrunk);
  3760         -            releasePage(pPrevTrunk);
  3761         -            return rc;
         3673  +            goto end_allocate_page;
  3762   3674             }
  3763   3675             rc = sqlite3pager_write(pNewTrunk->aData);
  3764   3676             if( rc!=SQLITE_OK ){
  3765   3677               releasePage(pNewTrunk);
  3766         -            releasePage(pTrunk);
  3767         -            releasePage(pPrevTrunk);
  3768         -            return rc;
         3678  +            goto end_allocate_page;
  3769   3679             }
  3770   3680             memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4);
  3771   3681             put4byte(&pNewTrunk->aData[4], k-1);
  3772   3682             memcpy(&pNewTrunk->aData[8], &pTrunk->aData[12], (k-1)*4);
         3683  +          releasePage(pNewTrunk);
  3773   3684             if( !pPrevTrunk ){
  3774   3685               put4byte(&pPage1->aData[32], iNewTrunk);
  3775   3686             }else{
         3687  +            rc = sqlite3pager_write(pPrevTrunk->aData);
         3688  +            if( rc ){
         3689  +              goto end_allocate_page;
         3690  +            }
  3776   3691               put4byte(&pPrevTrunk->aData[0], iNewTrunk);
  3777   3692             }
  3778         -          releasePage(pNewTrunk);
  3779   3693           }
  3780   3694           pTrunk = 0;
  3781   3695           TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
  3782   3696   #endif
  3783   3697         }else{
  3784   3698           /* Extract a leaf from the trunk */
  3785   3699           int closest;
  3786   3700           Pgno iPage;
  3787   3701           unsigned char *aData = pTrunk->aData;
         3702  +        rc = sqlite3pager_write(aData);
         3703  +        if( rc ){
         3704  +          goto end_allocate_page;
         3705  +        }
  3788   3706           if( nearby>0 ){
  3789   3707             int i, dist;
  3790   3708             closest = 0;
  3791   3709             dist = get4byte(&aData[8]) - nearby;
  3792   3710             if( dist<0 ) dist = -dist;
  3793   3711             for(i=1; i<k; i++){
  3794   3712               int d2 = get4byte(&aData[8+i*4]) - nearby;
................................................................................
  3824   3742                 releasePage(*ppPage);
  3825   3743               }
  3826   3744             }
  3827   3745             searchList = 0;
  3828   3746           }
  3829   3747         }
  3830   3748         releasePage(pPrevTrunk);
         3749  +      pPrevTrunk = 0;
  3831   3750       }while( searchList );
  3832         -    releasePage(pTrunk);
  3833   3751     }else{
  3834   3752       /* There are no pages on the freelist, so create a new page at the
  3835   3753       ** end of the file */
  3836   3754       *pPgno = sqlite3pager_pagecount(pBt->pPager) + 1;
  3837   3755   
  3838   3756   #ifndef SQLITE_OMIT_AUTOVACUUM
  3839   3757       if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
................................................................................
  3854   3772       if( rc!=SQLITE_OK ){
  3855   3773         releasePage(*ppPage);
  3856   3774       }
  3857   3775       TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
  3858   3776     }
  3859   3777   
  3860   3778     assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
         3779  +
         3780  +end_allocate_page:
         3781  +  releasePage(pTrunk);
         3782  +  releasePage(pPrevTrunk);
  3861   3783     return rc;
  3862   3784   }
  3863   3785   
  3864   3786   /*
  3865   3787   ** Add a page of the database file to the freelist.
  3866   3788   **
  3867   3789   ** sqlite3pager_unref() is NOT called for pPage.
................................................................................
  4254   4176       for(j=end-2, ptr=&data[j]; j>ins; j-=2, ptr-=2){
  4255   4177         ptr[0] = ptr[-2];
  4256   4178         ptr[1] = ptr[-1];
  4257   4179       }
  4258   4180       put2byte(&data[ins], idx);
  4259   4181       put2byte(&data[hdr+3], pPage->nCell);
  4260   4182       pPage->idxShift = 1;
  4261         -    pageIntegrity(pPage);
  4262   4183   #ifndef SQLITE_OMIT_AUTOVACUUM
  4263   4184       if( pPage->pBt->autoVacuum ){
  4264   4185         /* The cell may contain a pointer to an overflow page. If so, write
  4265   4186         ** the entry for the overflow page into the pointer map.
  4266   4187         */
  4267   4188         CellInfo info;
  4268   4189         parseCellPtr(pPage, pCell, &info);
................................................................................
  4994   4915   
  4995   4916     /*
  4996   4917     ** Balance the parent page.  Note that the current page (pPage) might
  4997   4918     ** have been added to the freelist so it might no longer be initialized.
  4998   4919     ** But the parent page will always be initialized.
  4999   4920     */
  5000   4921     assert( pParent->isInit );
  5001         -  /* assert( pPage->isInit ); // No! pPage might have been added to freelist */
  5002         -  /* pageIntegrity(pPage);    // No! pPage might have been added to freelist */ 
  5003   4922     rc = balance(pParent, 0);
  5004   4923     
  5005   4924     /*
  5006   4925     ** Cleanup before returning.
  5007   4926     */
  5008   4927   balance_cleanup:
  5009   4928     sqliteFree(apCell);
................................................................................
  5980   5899     BtCursor tmpCur;
  5981   5900   
  5982   5901     int rc = restoreOrClearCursorPosition(pCur, 1);
  5983   5902     if( rc!=SQLITE_OK ){
  5984   5903       return rc;
  5985   5904     }
  5986   5905   
  5987         -  pageIntegrity(pPage);
  5988   5906     assert( pPage->isInit );
  5989   5907     getTempCursor(pCur, &tmpCur);
  5990   5908     while( upCnt-- ){
  5991   5909       moveToParent(&tmpCur);
  5992   5910     }
  5993   5911     pPage = tmpCur.pPage;
  5994         -  pageIntegrity(pPage);
  5995   5912     aResult[0] = sqlite3pager_pagenumber(pPage->aData);
  5996   5913     assert( aResult[0]==pPage->pgno );
  5997   5914     aResult[1] = tmpCur.idx;
  5998   5915     aResult[2] = pPage->nCell;
  5999   5916     if( tmpCur.idx>=0 && tmpCur.idx<pPage->nCell ){
  6000   5917       getCellInfo(&tmpCur);
  6001   5918       aResult[3] = tmpCur.info.nSize;
................................................................................
  6505   6422     iSkip = PENDING_BYTE_PAGE(pBtTo);
  6506   6423     for(i=1; rc==SQLITE_OK && i<=nPage; i++){
  6507   6424       void *pPage;
  6508   6425       if( i==iSkip ) continue;
  6509   6426       rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage);
  6510   6427       if( rc ) break;
  6511   6428       rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage);
  6512         -    if( rc ) break;
  6513   6429       sqlite3pager_unref(pPage);
  6514   6430     }
  6515   6431     for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){
  6516   6432       void *pPage;
  6517   6433       if( i==iSkip ) continue;
  6518   6434       rc = sqlite3pager_get(pBtTo->pPager, i, &pPage);
  6519   6435       if( rc ) break;

Changes to SQLite.Interop/src/btree.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite B-Tree file
    13     13   ** subsystem.  See comments in the source code for a detailed description
    14     14   ** of what each interface routine does.
    15     15   **
    16         -** @(#) $Id: btree.h,v 1.24 2006/10/12 21:34:21 rmsimpson Exp $
           16  +** @(#) $Id: btree.h,v 1.25 2007/01/10 14:50:45 rmsimpson Exp $
    17     17   */
    18     18   #ifndef _BTREE_H_
    19     19   #define _BTREE_H_
    20     20   
    21     21   /* TODO: This definition is just included so other modules compile. It
    22     22   ** needs to be revisited.
    23     23   */

Changes to SQLite.Interop/src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.24 2006/10/12 21:34:21 rmsimpson Exp $
           25  +** $Id: build.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
  2936   2936         if( pItem->pSelect ){
  2937   2937           sqlite3SrcListAssignCursors(pParse, pItem->pSelect->pSrc);
  2938   2938         }
  2939   2939       }
  2940   2940     }
  2941   2941   }
  2942   2942   
  2943         -/*
  2944         -** Add an alias to the last identifier on the given identifier list.
  2945         -*/
  2946         -void sqlite3SrcListAddAlias(SrcList *pList, Token *pToken){
  2947         -  if( pList && pList->nSrc>0 ){
  2948         -    pList->a[pList->nSrc-1].zAlias = sqlite3NameFromToken(pToken);
  2949         -  }
  2950         -}
  2951         -
  2952   2943   /*
  2953   2944   ** Delete an entire SrcList including all its substructure.
  2954   2945   */
  2955   2946   void sqlite3SrcListDelete(SrcList *pList){
  2956   2947     int i;
  2957   2948     struct SrcList_item *pItem;
  2958   2949     if( pList==0 ) return;
................................................................................
  2963   2954       sqlite3DeleteTable(0, pItem->pTab);
  2964   2955       sqlite3SelectDelete(pItem->pSelect);
  2965   2956       sqlite3ExprDelete(pItem->pOn);
  2966   2957       sqlite3IdListDelete(pItem->pUsing);
  2967   2958     }
  2968   2959     sqliteFree(pList);
  2969   2960   }
         2961  +
         2962  +/*
         2963  +** This routine is called by the parser to add a new term to the
         2964  +** end of a growing FROM clause.  The "p" parameter is the part of
         2965  +** the FROM clause that has already been constructed.  "p" is NULL
         2966  +** if this is the first term of the FROM clause.  pTable and pDatabase
         2967  +** are the name of the table and database named in the FROM clause term.
         2968  +** pDatabase is NULL if the database name qualifier is missing - the
         2969  +** usual case.  If the term has a alias, then pAlias points to the
         2970  +** alias token.  If the term is a subquery, then pSubquery is the
         2971  +** SELECT statement that the subquery encodes.  The pTable and
         2972  +** pDatabase parameters are NULL for subqueries.  The pOn and pUsing
         2973  +** parameters are the content of the ON and USING clauses.
         2974  +**
         2975  +** Return a new SrcList which encodes is the FROM with the new
         2976  +** term added.
         2977  +*/
         2978  +SrcList *sqlite3SrcListAppendFromTerm(
         2979  +  SrcList *p,             /* The left part of the FROM clause already seen */
         2980  +  Token *pTable,          /* Name of the table to add to the FROM clause */
         2981  +  Token *pDatabase,       /* Name of the database containing pTable */
         2982  +  Token *pAlias,          /* The right-hand side of the AS subexpression */
         2983  +  Select *pSubquery,      /* A subquery used in place of a table name */
         2984  +  Expr *pOn,              /* The ON clause of a join */
         2985  +  IdList *pUsing          /* The USING clause of a join */
         2986  +){
         2987  +  struct SrcList_item *pItem;
         2988  +  p = sqlite3SrcListAppend(p, pTable, pDatabase);
         2989  +  if( p==0 || p->nSrc==0 ){
         2990  +    sqlite3ExprDelete(pOn);
         2991  +    sqlite3IdListDelete(pUsing);
         2992  +    sqlite3SelectDelete(pSubquery);
         2993  +    return p;
         2994  +  }
         2995  +  pItem = &p->a[p->nSrc-1];
         2996  +  if( pAlias && pAlias->n ){
         2997  +    pItem->zAlias = sqlite3NameFromToken(pAlias);
         2998  +  }
         2999  +  pItem->pSelect = pSubquery;
         3000  +  pItem->pOn = pOn;
         3001  +  pItem->pUsing = pUsing;
         3002  +  return p;
         3003  +}
         3004  +
         3005  +/*
         3006  +** When building up a FROM clause in the parser, the join operator
         3007  +** is initially attached to the left operand.  But the code generator
         3008  +** expects the join operator to be on the right operand.  This routine
         3009  +** Shifts all join operators from left to right for an entire FROM
         3010  +** clause.
         3011  +**
         3012  +** Example: Suppose the join is like this:
         3013  +**
         3014  +**           A natural cross join B
         3015  +**
         3016  +** The operator is "natural cross join".  The A and B operands are stored
         3017  +** in p->a[0] and p->a[1], respectively.  The parser initially stores the
         3018  +** operator with A.  This routine shifts that operator over to B.
         3019  +*/
         3020  +void sqlite3SrcListShiftJoinType(SrcList *p){
         3021  +  if( p && p->a ){
         3022  +    int i;
         3023  +    for(i=p->nSrc-1; i>0; i--){
         3024  +      p->a[i].jointype = p->a[i-1].jointype;
         3025  +    }
         3026  +    p->a[0].jointype = 0;
         3027  +  }
         3028  +}
  2970   3029   
  2971   3030   /*
  2972   3031   ** Begin a transaction
  2973   3032   */
  2974   3033   void sqlite3BeginTransaction(Parse *pParse, int type){
  2975   3034     sqlite3 *db;
  2976   3035     Vdbe *v;

Changes to SQLite.Interop/src/callback.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains functions used to access the internal hash tables
    14     14   ** of user defined functions and collation sequences.
    15     15   **
    16         -** $Id: callback.c,v 1.19 2006/10/12 21:34:21 rmsimpson Exp $
           16  +** $Id: callback.c,v 1.20 2007/01/10 14:50:46 rmsimpson Exp $
    17     17   */
    18     18   
    19     19   #include "sqliteInt.h"
    20     20   
    21     21   /*
    22     22   ** Invoke the 'collation needed' callback to request a collation sequence
    23     23   ** in the database text encoding of name zName, length nName.

Changes to SQLite.Interop/src/complete.c.

    12     12   ** An tokenizer for SQL
    13     13   **
    14     14   ** This file contains C code that implements the sqlite3_complete() API.
    15     15   ** This code used to be part of the tokenizer.c source file.  But by
    16     16   ** separating it out, the code will be automatically omitted from
    17     17   ** static links that do not use it.
    18     18   **
    19         -** $Id: complete.c,v 1.17 2006/10/12 21:34:21 rmsimpson Exp $
           19  +** $Id: complete.c,v 1.18 2007/01/10 14:50:46 rmsimpson Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   #ifndef SQLITE_OMIT_COMPLETE
    23     23   
    24     24   /*
    25     25   ** This is defined in tokenize.c.  We just have to import the definition.
    26     26   */

Changes to SQLite.Interop/src/date.c.

    12     12   ** This file contains the C functions that implement date and time
    13     13   ** functions for SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: date.c,v 1.25 2006/10/12 21:34:21 rmsimpson Exp $
           19  +** $Id: date.c,v 1.26 2007/01/10 14:50:46 rmsimpson Exp $
    20     20   **
    21     21   ** NOTES:
    22     22   **
    23     23   ** SQLite processes all times and dates as Julian Day numbers.  The
    24     24   ** dates and times are stored as the number of days since noon
    25     25   ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
    26     26   ** calendar system. 
................................................................................
   836    836           case 'j': {
   837    837             int nDay;             /* Number of days since 1st day of year */
   838    838             DateTime y = x;
   839    839             y.validJD = 0;
   840    840             y.M = 1;
   841    841             y.D = 1;
   842    842             computeJD(&y);
   843         -          nDay = x.rJD - y.rJD;
          843  +          nDay = x.rJD - y.rJD + 0.5;
   844    844             if( zFmt[i]=='W' ){
   845    845               int wd;   /* 0=Monday, 1=Tuesday, ... 6=Sunday */
   846    846               wd = ((int)(x.rJD+0.5)) % 7;
   847    847               sprintf(&z[j],"%02d",(nDay+7-wd)/7);
   848    848               j += 2;
   849    849             }else{
   850    850               sprintf(&z[j],"%03d",nDay+1);
................................................................................
   856    856           case 'm':  sprintf(&z[j],"%02d",x.M); j+=2; break;
   857    857           case 'M':  sprintf(&z[j],"%02d",x.m); j+=2; break;
   858    858           case 's': {
   859    859             sprintf(&z[j],"%d",(int)((x.rJD-2440587.5)*86400.0 + 0.5));
   860    860             j += strlen(&z[j]);
   861    861             break;
   862    862           }
   863         -        case 'S':  sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break;
          863  +        case 'S':  sprintf(&z[j],"%02d",(int)x.s); j+=2; break;
   864    864           case 'w':  z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
   865    865           case 'Y':  sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break;
   866    866           case '%':  z[j++] = '%'; break;
   867    867         }
   868    868       }
   869    869     }
   870    870     z[j] = 0;

Changes to SQLite.Interop/src/delete.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** in order to generate code for DELETE FROM statements.
    14     14   **
    15         -** $Id: delete.c,v 1.24 2006/10/12 21:34:21 rmsimpson Exp $
           15  +** $Id: delete.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Look up every table that is named in pSrc.  If any table is not found,
    21     21   ** add an error message to pParse->zErrMsg and return NULL.  If all tables
    22     22   ** are found, return a pointer to the last table.

Changes to SQLite.Interop/src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.31 2006/10/12 21:34:21 rmsimpson Exp $
           15  +** $Id: expr.c,v 1.32 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
   887    887               pExpr->iTable = pItem->iCursor;
   888    888               pMatch = pItem;
   889    889               pExpr->pSchema = pTab->pSchema;
   890    890               /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
   891    891               pExpr->iColumn = j==pTab->iPKey ? -1 : j;
   892    892               pExpr->affinity = pTab->aCol[j].affinity;
   893    893               pExpr->pColl = sqlite3FindCollSeq(db, ENC(db), zColl,-1, 0);
   894         -            if( pItem->jointype & JT_NATURAL ){
   895         -              /* If this match occurred in the left table of a natural join,
   896         -              ** then skip the right table to avoid a duplicate match */
   897         -              pItem++;
   898         -              i++;
   899         -            }
   900         -            if( (pUsing = pItem->pUsing)!=0 ){
   901         -              /* If this match occurs on a column that is in the USING clause
   902         -              ** of a join, skip the search of the right table of the join
   903         -              ** to avoid a duplicate match there. */
   904         -              int k;
   905         -              for(k=0; k<pUsing->nId; k++){
   906         -                if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ){
   907         -                  pItem++;
   908         -                  i++;
   909         -                  break;
          894  +            if( i<pSrcList->nSrc-1 ){
          895  +              if( pItem[1].jointype & JT_NATURAL ){
          896  +                /* If this match occurred in the left table of a natural join,
          897  +                ** then skip the right table to avoid a duplicate match */
          898  +                pItem++;
          899  +                i++;
          900  +              }else if( (pUsing = pItem[1].pUsing)!=0 ){
          901  +                /* If this match occurs on a column that is in the USING clause
          902  +                ** of a join, skip the search of the right table of the join
          903  +                ** to avoid a duplicate match there. */
          904  +                int k;
          905  +                for(k=0; k<pUsing->nId; k++){
          906  +                  if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ){
          907  +                    pItem++;
          908  +                    i++;
          909  +                    break;
          910  +                  }
   910    911                   }
   911    912                 }
   912    913               }
   913    914               break;
   914    915             }
   915    916           }
   916    917         }
................................................................................
  1176   1177             no_such_func = 1;
  1177   1178           }else{
  1178   1179             wrong_num_args = 1;
  1179   1180           }
  1180   1181         }else{
  1181   1182           is_agg = pDef->xFunc==0;
  1182   1183         }
  1183         -#ifndef SQLITE_OMIT_AUTHORIZER
         1184  +#ifndef SQLITE_OMIT_AUTHORIZATION
  1184   1185         if( pDef ){
  1185   1186           auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
  1186   1187           if( auth!=SQLITE_OK ){
  1187   1188             if( auth==SQLITE_DENY ){
  1188   1189               sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
  1189   1190                                       pDef->zName);
  1190   1191               pNC->nErr++;
................................................................................
  2203   2204     NameContext *pNC = (NameContext *)pArg;
  2204   2205     Parse *pParse = pNC->pParse;
  2205   2206     SrcList *pSrcList = pNC->pSrcList;
  2206   2207     AggInfo *pAggInfo = pNC->pAggInfo;
  2207   2208     
  2208   2209   
  2209   2210     switch( pExpr->op ){
         2211  +    case TK_AGG_COLUMN:
  2210   2212       case TK_COLUMN: {
  2211   2213         /* Check to see if the column is in one of the tables in the FROM
  2212   2214         ** clause of the aggregate query */
  2213   2215         if( pSrcList ){
  2214   2216           struct SrcList_item *pItem = pSrcList->a;
  2215   2217           for(i=0; i<pSrcList->nSrc; i++, pItem++){
  2216   2218             struct AggInfo_col *pCol;

Changes to SQLite.Interop/src/fts1.c.

    46     46   
    47     47   typedef struct StringBuffer {
    48     48     int len;      /* length, not including null terminator */
    49     49     int alloced;  /* Space allocated for s[] */ 
    50     50     char *s;      /* Content of the string */
    51     51   } StringBuffer;
    52     52   
    53         -void initStringBuffer(StringBuffer *sb){
           53  +static void initStringBuffer(StringBuffer *sb){
    54     54     sb->len = 0;
    55     55     sb->alloced = 100;
    56     56     sb->s = malloc(100);
    57     57     sb->s[0] = '\0';
    58     58   }
    59     59   
    60         -void nappend(StringBuffer *sb, const char *zFrom, int nFrom){
           60  +static void nappend(StringBuffer *sb, const char *zFrom, int nFrom){
    61     61     if( sb->len + nFrom >= sb->alloced ){
    62     62       sb->alloced = sb->len + nFrom + 100;
    63     63       sb->s = realloc(sb->s, sb->alloced+1);
    64     64       if( sb->s==0 ){
    65     65         initStringBuffer(sb);
    66     66         return;
    67     67       }
    68     68     }
    69     69     memcpy(sb->s + sb->len, zFrom, nFrom);
    70     70     sb->len += nFrom;
    71     71     sb->s[sb->len] = 0;
    72     72   }
    73         -void append(StringBuffer *sb, const char *zFrom){
           73  +static void append(StringBuffer *sb, const char *zFrom){
    74     74     nappend(sb, zFrom, strlen(zFrom));
    75     75   }
    76     76   
    77     77   /* We encode variable-length integers in little-endian order using seven bits
    78     78    * per byte as follows:
    79     79   **
    80     80   ** KEY:
................................................................................
  1238   1238   
  1239   1239     rc = sqlite3_bind_int64(s, 1+v->nColumn, iRowid);
  1240   1240     if( rc!=SQLITE_OK ) return rc;
  1241   1241   
  1242   1242     return sql_single_step_statement(v, CONTENT_UPDATE_STMT, &s);
  1243   1243   }
  1244   1244   
  1245         -void freeStringArray(int nString, const char **pString){
         1245  +static void freeStringArray(int nString, const char **pString){
  1246   1246     int i;
  1247   1247   
  1248   1248     for (i=0 ; i < nString ; ++i) {
  1249   1249       free((void *) pString[i]);
  1250   1250     }
  1251   1251     free((void *) pString);
  1252   1252   }
................................................................................
  1630   1630   ** Examples:
  1631   1631   **
  1632   1632   **     "abc"   becomes   abc
  1633   1633   **     'xyz'   becomes   xyz
  1634   1634   **     [pqr]   becomes   pqr
  1635   1635   **     `mno`   becomes   mno
  1636   1636   */
  1637         -void dequoteString(char *z){
         1637  +static void dequoteString(char *z){
  1638   1638     int quote;
  1639   1639     int i, j;
  1640   1640     if( z==0 ) return;
  1641   1641     quote = z[0];
  1642   1642     switch( quote ){
  1643   1643       case '\'':  break;
  1644   1644       case '"':   break;
................................................................................
  1672   1672   **     output:     chinese simplifed mixed
  1673   1673   **
  1674   1674   ** Another example:
  1675   1675   **
  1676   1676   **     input:      delimiters ( '[' , ']' , '...' )
  1677   1677   **     output:     [ ] ...
  1678   1678   */
  1679         -void tokenListToIdList(char **azIn){
         1679  +static void tokenListToIdList(char **azIn){
  1680   1680     int i, j;
  1681   1681     if( azIn ){
  1682   1682       for(i=0, j=-1; azIn[i]; i++){
  1683   1683         if( isalnum(azIn[i][0]) || azIn[i][1] ){
  1684   1684           dequoteString(azIn[i]);
  1685   1685           if( j>=0 ){
  1686   1686             azIn[j] = azIn[i];
................................................................................
  1695   1695   
  1696   1696   /*
  1697   1697   ** Find the first alphanumeric token in the string zIn.  Null-terminate
  1698   1698   ** this token.  Remove any quotation marks.  And return a pointer to
  1699   1699   ** the result.
  1700   1700   */
  1701   1701   static char *firstToken(char *zIn, char **pzTail){
  1702         -  int i, n, ttype;
  1703         -  i = 0;
         1702  +  int n, ttype;
  1704   1703     while(1){
  1705   1704       n = getToken(zIn, &ttype);
  1706   1705       if( ttype==TOKEN_SPACE ){
  1707   1706         zIn += n;
  1708   1707       }else if( ttype==TOKEN_EOF ){
  1709   1708         *pzTail = zIn;
  1710   1709         return 0;
................................................................................
  1749   1748     char **azContentColumn;  /* Column names for %_content */
  1750   1749     char **azTokenizer;      /* Name of tokenizer and its arguments */
  1751   1750   } TableSpec;
  1752   1751   
  1753   1752   /*
  1754   1753   ** Reclaim all of the memory used by a TableSpec
  1755   1754   */
  1756         -void clearTableSpec(TableSpec *p) {
         1755  +static void clearTableSpec(TableSpec *p) {
  1757   1756     free(p->azColumn);
  1758   1757     free(p->azContentColumn);
  1759   1758     free(p->azTokenizer);
  1760   1759   }
  1761   1760   
  1762   1761   /* Parse a CREATE VIRTUAL TABLE statement, which looks like this:
  1763   1762    *
  1764   1763    * CREATE VIRTUAL TABLE email
  1765   1764    *        USING fts1(subject, body, tokenize mytokenizer(myarg))
  1766   1765    *
  1767   1766    * We return parsed information in a TableSpec structure.
  1768   1767    * 
  1769   1768    */
  1770         -int parseSpec(TableSpec *pSpec, int argc, const char *const*argv, char**pzErr){
  1771         -  int i, j, n;
         1769  +static int parseSpec(TableSpec *pSpec, int argc, const char *const*argv,
         1770  +                     char**pzErr){
         1771  +  int i, n;
  1772   1772     char *z, *zDummy;
  1773   1773     char **azArg;
  1774   1774     const char *zTokenizer = 0;    /* argv[] entry describing the tokenizer */
  1775   1775   
  1776   1776     assert( argc>=3 );
  1777   1777     /* Current interface:
  1778   1778     ** argv[0] - module name
................................................................................
  1804   1804     /* Identify the column names and the tokenizer and delimiter arguments
  1805   1805     ** in the argv[][] array.
  1806   1806     */
  1807   1807     pSpec->zName = azArg[2];
  1808   1808     pSpec->nColumn = 0;
  1809   1809     pSpec->azColumn = azArg;
  1810   1810     zTokenizer = "tokenize simple";
  1811         -  for(i=3, j=0; i<argc; ++i){
         1811  +  for(i=3; i<argc; ++i){
  1812   1812       if( startsWith(azArg[i],"tokenize") ){
  1813   1813         zTokenizer = azArg[i];
  1814   1814       }else{
  1815   1815         z = azArg[pSpec->nColumn] = firstToken(azArg[i], &zDummy);
  1816   1816         pSpec->nColumn++;
  1817   1817       }
  1818   1818     }
................................................................................
  2035   2035     clearTableSpec(&spec);
  2036   2036     return rc;
  2037   2037   }
  2038   2038   
  2039   2039   /* Decide how to handle an SQL query. */
  2040   2040   static int fulltextBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
  2041   2041     int i;
         2042  +  TRACE(("FTS1 BestIndex\n"));
  2042   2043   
  2043   2044     for(i=0; i<pInfo->nConstraint; ++i){
  2044   2045       const struct sqlite3_index_constraint *pConstraint;
  2045   2046       pConstraint = &pInfo->aConstraint[i];
  2046   2047       if( pConstraint->usable ) {
  2047   2048         if( pConstraint->iColumn==-1 &&
  2048   2049             pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
  2049   2050           pInfo->idxNum = QUERY_ROWID;      /* lookup by rowid */
         2051  +        TRACE(("FTS1 QUERY_ROWID\n"));
  2050   2052         } else if( pConstraint->iColumn>=0 &&
  2051   2053                    pConstraint->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
  2052   2054           /* full-text search */
  2053   2055           pInfo->idxNum = QUERY_FULLTEXT + pConstraint->iColumn;
         2056  +        TRACE(("FTS1 QUERY_FULLTEXT %d\n", pConstraint->iColumn));
  2054   2057         } else continue;
  2055   2058   
  2056   2059         pInfo->aConstraintUsage[i].argvIndex = 1;
  2057   2060         pInfo->aConstraintUsage[i].omit = 1;
  2058   2061   
  2059   2062         /* An arbitrary value for now.
  2060   2063          * TODO: Perhaps rowid matches should be considered cheaper than
................................................................................
  2061   2064          * full-text searches. */
  2062   2065         pInfo->estimatedCost = 1.0;   
  2063   2066   
  2064   2067         return SQLITE_OK;
  2065   2068       }
  2066   2069     }
  2067   2070     pInfo->idxNum = QUERY_GENERIC;
  2068         -  TRACE(("FTS1 BestIndex\n"));
  2069   2071     return SQLITE_OK;
  2070   2072   }
  2071   2073   
  2072   2074   static int fulltextDisconnect(sqlite3_vtab *pVTab){
  2073   2075     TRACE(("FTS1 Disconnect %p\n", pVTab));
  2074   2076     fulltext_vtab_destroy((fulltext_vtab *)pVTab);
  2075   2077     return SQLITE_OK;
................................................................................
  2077   2079   
  2078   2080   static int fulltextDestroy(sqlite3_vtab *pVTab){
  2079   2081     fulltext_vtab *v = (fulltext_vtab *)pVTab;
  2080   2082     int rc;
  2081   2083   
  2082   2084     TRACE(("FTS1 Destroy %p\n", pVTab));
  2083   2085     rc = sql_exec(v->db, v->zName,
  2084         -                    "drop table %_content; drop table %_term");
         2086  +                "drop table if exists %_content;"
         2087  +                "drop table if exists %_term;"
         2088  +                );
  2085   2089     if( rc!=SQLITE_OK ) return rc;
  2086   2090   
  2087   2091     fulltext_vtab_destroy((fulltext_vtab *)pVTab);
  2088   2092     return SQLITE_OK;
  2089   2093   }
  2090   2094   
  2091   2095   static int fulltextOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
................................................................................
  2810   2814   ** If idxNum==QUERY_ROWID then do a rowid lookup for a single entry
  2811   2815   ** in the %_content table.
  2812   2816   **
  2813   2817   ** If idxNum>=QUERY_FULLTEXT then use the full text index.  The
  2814   2818   ** column on the left-hand side of the MATCH operator is column
  2815   2819   ** number idxNum-QUERY_FULLTEXT, 0 indexed.  argv[0] is the right-hand
  2816   2820   ** side of the MATCH operator.
         2821  +*/
         2822  +/* TODO(shess) Upgrade the cursor initialization and destruction to
         2823  +** account for fulltextFilter() being called multiple times on the
         2824  +** same cursor.  The current solution is very fragile.  Apply fix to
         2825  +** fts2 as appropriate.
  2817   2826   */
  2818   2827   static int fulltextFilter(
  2819   2828     sqlite3_vtab_cursor *pCursor,     /* The cursor used for this query */
  2820   2829     int idxNum, const char *idxStr,   /* Which indexing scheme to use */
  2821   2830     int argc, sqlite3_value **argv    /* Arguments for the indexing scheme */
  2822   2831   ){
  2823   2832     fulltext_cursor *c = (fulltext_cursor *) pCursor;
................................................................................
  2825   2834     int rc;
  2826   2835     char *zSql;
  2827   2836   
  2828   2837     TRACE(("FTS1 Filter %p\n",pCursor));
  2829   2838   
  2830   2839     zSql = sqlite3_mprintf("select rowid, * from %%_content %s",
  2831   2840                             idxNum==QUERY_GENERIC ? "" : "where rowid=?");
         2841  +  sqlite3_finalize(c->pStmt);
  2832   2842     rc = sql_prepare(v->db, v->zName, &c->pStmt, zSql);
  2833   2843     sqlite3_free(zSql);
  2834         -  if( rc!=SQLITE_OK ) goto out;
         2844  +  if( rc!=SQLITE_OK ) return rc;
  2835   2845   
  2836   2846     c->iCursorType = idxNum;
  2837   2847     switch( idxNum ){
  2838   2848       case QUERY_GENERIC:
  2839   2849         break;
  2840   2850   
  2841   2851       case QUERY_ROWID:
  2842   2852         rc = sqlite3_bind_int64(c->pStmt, 1, sqlite3_value_int64(argv[0]));
  2843         -      if( rc!=SQLITE_OK ) goto out;
         2853  +      if( rc!=SQLITE_OK ) return rc;
  2844   2854         break;
  2845   2855   
  2846   2856       default:   /* full-text search */
  2847   2857       {
  2848   2858         const char *zQuery = (const char *)sqlite3_value_text(argv[0]);
  2849   2859         DocList *pResult;
  2850   2860         assert( idxNum<=QUERY_FULLTEXT+v->nColumn);
  2851   2861         assert( argc==1 );
  2852   2862         queryClear(&c->q);
  2853   2863         rc = fulltextQuery(v, idxNum-QUERY_FULLTEXT, zQuery, -1, &pResult, &c->q);
  2854         -      if( rc!=SQLITE_OK ) goto out;
         2864  +      if( rc!=SQLITE_OK ) return rc;
         2865  +      if( c->result.pDoclist!=NULL ) docListDelete(c->result.pDoclist);
  2855   2866         readerInit(&c->result, pResult);
  2856   2867         break;
  2857   2868       }
  2858   2869     }
  2859   2870   
  2860         -  rc = fulltextNext(pCursor);
  2861         -
  2862         -out:
  2863         -  return rc;
         2871  +  return fulltextNext(pCursor);
  2864   2872   }
  2865   2873   
  2866   2874   /* This is the xEof method of the virtual table.  The SQLite core
  2867   2875   ** calls this routine to find out if it has reached the end of
  2868   2876   ** a query's results set.
  2869   2877   */
  2870   2878   static int fulltextEof(sqlite3_vtab_cursor *pCursor){

Changes to SQLite.Interop/src/fts1_porter.c.

    66     66   ** Create a new tokenizer instance.
    67     67   */
    68     68   static int porterCreate(
    69     69     int argc, const char * const *argv,
    70     70     sqlite3_tokenizer **ppTokenizer
    71     71   ){
    72     72     porter_tokenizer *t;
    73         -  int i;
    74         -
    75         -for(i=0; i<argc; i++) printf("argv[%d] = %s\n", i, argv[i]);
    76     73     t = (porter_tokenizer *) calloc(sizeof(porter_tokenizer), 1);
    77     74     *ppTokenizer = &t->base;
    78     75     return SQLITE_OK;
    79     76   }
    80     77   
    81     78   /*
    82     79   ** Destroy a tokenizer
................................................................................
   559    556   
   560    557   /*
   561    558   ** Characters that can be part of a token.  We assume any character
   562    559   ** whose value is greater than 0x80 (any UTF character) can be
   563    560   ** part of a token.  In other words, delimiters all must have
   564    561   ** values of 0x7f or lower.
   565    562   */
   566         -const char isIdChar[] = {
          563  +static const char isIdChar[] = {
   567    564   /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
   568    565       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,  /* 3x */
   569    566       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 4x */
   570    567       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,  /* 5x */
   571    568       0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 6x */
   572    569       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,  /* 7x */
   573    570   };

Changes to SQLite.Interop/src/func.c.

    12     12   ** This file contains the C functions that implement various SQL
    13     13   ** functions of SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: func.c,v 1.26 2006/10/12 21:34:21 rmsimpson Exp $
           19  +** $Id: func.c,v 1.27 2007/01/10 14:50:46 rmsimpson Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   #include <ctype.h>
    23     23   /* #include <math.h> */
    24     24   #include <stdlib.h>
    25     25   #include <assert.h>
    26     26   #include "vdbeInt.h"

Changes to SQLite.Interop/src/hash.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This is the implementation of generic hash-tables
    13     13   ** used in SQLite.
    14     14   **
    15         -** $Id: hash.c,v 1.23 2006/10/12 21:34:21 rmsimpson Exp $
           15  +** $Id: hash.c,v 1.24 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <assert.h>
    19     19   
    20     20   /* Turn bulk memory into a hash table object by initializing the
    21     21   ** fields of the Hash structure.
    22     22   **

Changes to SQLite.Interop/src/hash.h.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This is the header file for the generic hash-table implemenation
    13     13   ** used in SQLite.
    14     14   **
    15         -** $Id: hash.h,v 1.23 2006/10/12 21:34:21 rmsimpson Exp $
           15  +** $Id: hash.h,v 1.24 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #ifndef _SQLITE_HASH_H_
    18     18   #define _SQLITE_HASH_H_
    19     19   
    20     20   /* Forward declarations of structures. */
    21     21   typedef struct Hash Hash;
    22     22   typedef struct HashElem HashElem;

Changes to SQLite.Interop/src/insert.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle INSERT statements in SQLite.
    14     14   **
    15         -** $Id: insert.c,v 1.24 2006/10/12 21:34:21 rmsimpson Exp $
           15  +** $Id: insert.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Set P3 of the most recently inserted opcode to a column affinity
    21     21   ** string for index pIdx. A column affinity string has one character
    22     22   ** for each column in the table, according to the affinity of the column:

Changes to SQLite.Interop/src/legacy.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: legacy.c,v 1.23 2006/10/12 21:34:21 rmsimpson Exp $
           17  +** $Id: legacy.c,v 1.24 2007/01/10 14:50:46 rmsimpson Exp $
    18     18   */
    19     19   
    20     20   #include "sqliteInt.h"
    21     21   #include "os.h"
    22     22   #include <ctype.h>
    23     23   
    24     24   /*

Changes to SQLite.Interop/src/loadext.c.

   213    213     ** sqlite3_libversion_number() to make sure they are dealing with
   214    214     ** a library that is new enough to support that API.
   215    215     *************************************************************************
   216    216     */
   217    217     sqlite3_overload_function,
   218    218   };
   219    219   
   220         -/*
   221         -** The windows implementation of shared-library loaders
   222         -*/
   223         -#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__BORLANDC__)
   224         -# include <windows.h>
   225         -# define SQLITE_LIBRARY_TYPE     HANDLE
   226         -# define SQLITE_OPEN_LIBRARY(A)  LoadLibrary(A)
   227         -#ifdef _WIN32_WCE
   228         -# define SQLITE_FIND_SYMBOL(A,B) GetProcAddressA(A,B)
   229         -#else
   230         -# define SQLITE_FIND_SYMBOL(A,B) GetProcAddress(A,B)
   231         -#endif
   232         -# define SQLITE_CLOSE_LIBRARY(A) FreeLibrary(A)
   233         -#endif /* windows */
   234         -
   235         -/*
   236         -** The unix implementation of shared-library loaders
   237         -*/
   238         -#if defined(HAVE_DLOPEN) && !defined(SQLITE_LIBRARY_TYPE)
   239         -# include <dlfcn.h>
   240         -# define SQLITE_LIBRARY_TYPE     void*
   241         -# define SQLITE_OPEN_LIBRARY(A)  dlopen(A, RTLD_NOW | RTLD_GLOBAL)
   242         -# define SQLITE_FIND_SYMBOL(A,B) dlsym(A,B)
   243         -# define SQLITE_CLOSE_LIBRARY(A) dlclose(A)
   244         -#endif
   245         -
   246    220   /*
   247    221   ** Attempt to load an SQLite extension library contained in the file
   248    222   ** zFile.  The entry point is zProc.  zProc may be 0 in which case a
   249    223   ** default entry point name (sqlite3_extension_init) is used.  Use
   250    224   ** of the default name is recommended.
   251    225   **
   252    226   ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
................................................................................
   257    231   */
   258    232   int sqlite3_load_extension(
   259    233     sqlite3 *db,          /* Load the extension into this database connection */
   260    234     const char *zFile,    /* Name of the shared library containing extension */
   261    235     const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
   262    236     char **pzErrMsg       /* Put error message here if not 0 */
   263    237   ){
   264         -#ifdef SQLITE_LIBRARY_TYPE
   265         -  SQLITE_LIBRARY_TYPE handle;
          238  +  void *handle;
   266    239     int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
   267    240     char *zErrmsg = 0;
   268         -  SQLITE_LIBRARY_TYPE *aHandle;
   269         -
   270         -#ifdef _WIN32_WCE
   271         -  WCHAR zWideFile[MAX_PATH];
   272         -  MultiByteToWideChar(CP_ACP, 0, zFile, -1, zWideFile, MAX_PATH);
   273         -#endif
          241  +  void **aHandle;
   274    242   
   275    243     /* Ticket #1863.  To avoid a creating security problems for older
   276    244     ** applications that relink against newer versions of SQLite, the
   277    245     ** ability to run load_extension is turned off by default.  One
   278    246     ** must call sqlite3_enable_load_extension() to turn on extension
   279    247     ** loading.  Otherwise you get the following error.
   280    248     */
................................................................................
   285    253       return SQLITE_ERROR;
   286    254     }
   287    255   
   288    256     if( zProc==0 ){
   289    257       zProc = "sqlite3_extension_init";
   290    258     }
   291    259   
   292         -#ifdef _WIN32_WCE
   293         -  handle = SQLITE_OPEN_LIBRARY(zWideFile);
   294         -#else
   295         -  handle = SQLITE_OPEN_LIBRARY(zFile);
   296         -#endif
          260  +  handle = sqlite3OsDlopen(zFile);
   297    261     if( handle==0 ){
   298    262       if( pzErrMsg ){
   299    263         *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile);
   300    264       }
   301    265       return SQLITE_ERROR;
   302    266     }
   303    267     xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
   304         -                   SQLITE_FIND_SYMBOL(handle, zProc);
          268  +                   sqlite3OsDlsym(handle, zProc);
   305    269     if( xInit==0 ){
   306    270       if( pzErrMsg ){
   307    271          *pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]",
   308    272                                      zProc, zFile);
   309    273       }
   310         -    SQLITE_CLOSE_LIBRARY(handle);
          274  +    sqlite3OsDlclose(handle);
   311    275       return SQLITE_ERROR;
   312    276     }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){
   313    277       if( pzErrMsg ){
   314    278         *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
   315    279       }
   316    280       sqlite3_free(zErrmsg);
   317         -    SQLITE_CLOSE_LIBRARY(handle);
          281  +    sqlite3OsDlclose(handle);
   318    282       return SQLITE_ERROR;
   319    283     }
   320    284   
   321    285     /* Append the new shared library handle to the db->aExtension array. */
   322    286     db->nExtension++;
   323    287     aHandle = sqliteMalloc(sizeof(handle)*db->nExtension);
   324    288     if( aHandle==0 ){
................................................................................
   326    290     }
   327    291     if( db->nExtension>0 ){
   328    292       memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1));
   329    293     }
   330    294     sqliteFree(db->aExtension);
   331    295     db->aExtension = aHandle;
   332    296   
   333         -  ((SQLITE_LIBRARY_TYPE*)db->aExtension)[db->nExtension-1] = handle;
          297  +  db->aExtension[db->nExtension-1] = handle;
   334    298     return SQLITE_OK;
   335         -#else
   336         -  if( pzErrMsg ){
   337         -    *pzErrMsg = sqlite3_mprintf("extension loading is disabled");
   338         -  }
   339         -  return SQLITE_ERROR;
   340         -#endif
   341    299   }
   342    300   
   343    301   /*
   344    302   ** Call this routine when the database connection is closing in order
   345    303   ** to clean up loaded extensions
   346    304   */
   347    305   void sqlite3CloseExtensions(sqlite3 *db){
   348         -#ifdef SQLITE_LIBRARY_TYPE
   349    306     int i;
   350    307     for(i=0; i<db->nExtension; i++){
   351         -    SQLITE_CLOSE_LIBRARY(((SQLITE_LIBRARY_TYPE*)db->aExtension)[i]);
          308  +    sqlite3OsDlclose(db->aExtension[i]);
   352    309     }
   353    310     sqliteFree(db->aExtension);
   354         -#endif
   355    311   }
   356    312   
   357    313   /*
   358    314   ** Enable or disable extension loading.  Extension loading is disabled by
   359    315   ** default so as not to open security holes in older applications.
   360    316   */
   361    317   int sqlite3_enable_load_extension(sqlite3 *db, int onoff){

Changes to SQLite.Interop/src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.25 2006/10/12 21:34:21 rmsimpson Exp $
           17  +** $Id: main.c,v 1.26 2007/01/10 14:50:46 rmsimpson Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
   938    938       sqlite3RegisterBuiltinFunctions(db);
   939    939     }
   940    940     db->magic = SQLITE_MAGIC_OPEN;
   941    941   
   942    942     /* Load automatic extensions - extensions that have been registered
   943    943     ** using the sqlite3_automatic_extension() API.
   944    944     */
   945         -  sqlite3AutoLoadExtensions(db);
          945  +  (void)sqlite3AutoLoadExtensions(db);
   946    946   
   947    947   #ifdef SQLITE_ENABLE_FTS1
   948    948     {
   949    949       extern int sqlite3Fts1Init(sqlite3*);
   950    950       sqlite3Fts1Init(db);
   951    951     }
   952    952   #endif
          953  +
          954  +#ifdef SQLITE_ENABLE_FTS2
          955  +  {
          956  +    extern int sqlite3Fts2Init(sqlite3*);
          957  +    sqlite3Fts2Init(db);
          958  +  }
          959  +#endif
   953    960   
   954    961   opendb_out:
   955    962     if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){
   956    963       sqlite3_close(db);
   957    964       db = 0;
   958    965     }
   959    966     *ppDb = db;

Changes to SQLite.Interop/src/opcodes.c.

    30     30    /*  26 */ "String",
    31     31    /*  27 */ "RealAffinity",
    32     32    /*  28 */ "ParseSchema",
    33     33    /*  29 */ "VOpen",
    34     34    /*  30 */ "Close",
    35     35    /*  31 */ "CreateIndex",
    36     36    /*  32 */ "IsUnique",
    37         - /*  33 */ "IdxIsNull",
    38         - /*  34 */ "NotFound",
    39         - /*  35 */ "Int64",
    40         - /*  36 */ "MustBeInt",
    41         - /*  37 */ "Halt",
    42         - /*  38 */ "Rowid",
    43         - /*  39 */ "IdxLT",
    44         - /*  40 */ "AddImm",
    45         - /*  41 */ "Statement",
    46         - /*  42 */ "RowData",
    47         - /*  43 */ "MemMax",
    48         - /*  44 */ "Push",
    49         - /*  45 */ "NotExists",
    50         - /*  46 */ "MemIncr",
    51         - /*  47 */ "Gosub",
    52         - /*  48 */ "Integer",
    53         - /*  49 */ "MemInt",
    54         - /*  50 */ "Prev",
    55         - /*  51 */ "VColumn",
    56         - /*  52 */ "CreateTable",
    57         - /*  53 */ "Last",
    58         - /*  54 */ "IdxRowid",
    59         - /*  55 */ "MakeIdxRec",
    60         - /*  56 */ "ResetCount",
    61         - /*  57 */ "FifoWrite",
    62         - /*  58 */ "Callback",
    63         - /*  59 */ "ContextPush",
    64         - /*  60 */ "DropTrigger",
           37  + /*  33 */ "NotFound",
           38  + /*  34 */ "Int64",
           39  + /*  35 */ "MustBeInt",
           40  + /*  36 */ "Halt",
           41  + /*  37 */ "Rowid",
           42  + /*  38 */ "IdxLT",
           43  + /*  39 */ "AddImm",
           44  + /*  40 */ "Statement",
           45  + /*  41 */ "RowData",
           46  + /*  42 */ "MemMax",
           47  + /*  43 */ "Push",
           48  + /*  44 */ "NotExists",
           49  + /*  45 */ "MemIncr",
           50  + /*  46 */ "Gosub",
           51  + /*  47 */ "Integer",
           52  + /*  48 */ "MemInt",
           53  + /*  49 */ "Prev",
           54  + /*  50 */ "VColumn",
           55  + /*  51 */ "CreateTable",
           56  + /*  52 */ "Last",
           57  + /*  53 */ "IdxRowid",
           58  + /*  54 */ "MakeIdxRec",
           59  + /*  55 */ "ResetCount",
           60  + /*  56 */ "FifoWrite",
           61  + /*  57 */ "Callback",
           62  + /*  58 */ "ContextPush",
           63  + /*  59 */ "DropTrigger",
           64  + /*  60 */ "DropIndex",
    65     65    /*  61 */ "Or",
    66     66    /*  62 */ "And",
    67         - /*  63 */ "DropIndex",
    68         - /*  64 */ "IdxGE",
    69         - /*  65 */ "IdxDelete",
           67  + /*  63 */ "IdxGE",
           68  + /*  64 */ "IdxDelete",
           69  + /*  65 */ "Vacuum",
    70     70    /*  66 */ "IsNull",
    71     71    /*  67 */ "NotNull",
    72     72    /*  68 */ "Ne",
    73     73    /*  69 */ "Eq",
    74     74    /*  70 */ "Gt",
    75     75    /*  71 */ "Le",
    76     76    /*  72 */ "Lt",
    77     77    /*  73 */ "Ge",
    78         - /*  74 */ "Vacuum",
           78  + /*  74 */ "MoveLe",
    79     79    /*  75 */ "BitAnd",
    80     80    /*  76 */ "BitOr",
    81     81    /*  77 */ "ShiftLeft",
    82     82    /*  78 */ "ShiftRight",
    83     83    /*  79 */ "Add",
    84     84    /*  80 */ "Subtract",
    85     85    /*  81 */ "Multiply",
    86     86    /*  82 */ "Divide",
    87     87    /*  83 */ "Remainder",
    88     88    /*  84 */ "Concat",
    89     89    /*  85 */ "Negative",
    90         - /*  86 */ "MoveLe",
           90  + /*  86 */ "IfNot",
    91     91    /*  87 */ "BitNot",
    92     92    /*  88 */ "String8",
    93         - /*  89 */ "IfNot",
    94         - /*  90 */ "DropTable",
    95         - /*  91 */ "MakeRecord",
    96         - /*  92 */ "Delete",
    97         - /*  93 */ "AggFinal",
    98         - /*  94 */ "Dup",
    99         - /*  95 */ "Goto",
   100         - /*  96 */ "TableLock",
   101         - /*  97 */ "FifoRead",
   102         - /*  98 */ "Clear",
   103         - /*  99 */ "IdxGT",
   104         - /* 100 */ "MoveLt",
   105         - /* 101 */ "VerifyCookie",
   106         - /* 102 */ "AggStep",
   107         - /* 103 */ "Pull",
   108         - /* 104 */ "SetNumColumns",
   109         - /* 105 */ "AbsValue",
   110         - /* 106 */ "Transaction",
   111         - /* 107 */ "VFilter",
   112         - /* 108 */ "VDestroy",
   113         - /* 109 */ "ContextPop",
   114         - /* 110 */ "Next",
   115         - /* 111 */ "IdxInsert",
   116         - /* 112 */ "Distinct",
   117         - /* 113 */ "Insert",
   118         - /* 114 */ "Destroy",
   119         - /* 115 */ "ReadCookie",
   120         - /* 116 */ "ForceInt",
   121         - /* 117 */ "LoadAnalysis",
   122         - /* 118 */ "Explain",
   123         - /* 119 */ "IfMemZero",
   124         - /* 120 */ "OpenPseudo",
   125         - /* 121 */ "OpenEphemeral",
   126         - /* 122 */ "Null",
   127         - /* 123 */ "Blob",
   128         - /* 124 */ "MemStore",
   129         - /* 125 */ "Rewind",
           93  + /*  89 */ "DropTable",
           94  + /*  90 */ "MakeRecord",
           95  + /*  91 */ "Delete",
           96  + /*  92 */ "AggFinal",
           97  + /*  93 */ "Dup",
           98  + /*  94 */ "Goto",
           99  + /*  95 */ "TableLock",
          100  + /*  96 */ "FifoRead",
          101  + /*  97 */ "Clear",
          102  + /*  98 */ "IdxGT",
          103  + /*  99 */ "MoveLt",
          104  + /* 100 */ "VerifyCookie",
          105  + /* 101 */ "AggStep",
          106  + /* 102 */ "Pull",
          107  + /* 103 */ "SetNumColumns",
          108  + /* 104 */ "AbsValue",
          109  + /* 105 */ "Transaction",
          110  + /* 106 */ "VFilter",
          111  + /* 107 */ "VDestroy",
          112  + /* 108 */ "ContextPop",
          113  + /* 109 */ "Next",
          114  + /* 110 */ "IdxInsert",
          115  + /* 111 */ "Distinct",
          116  + /* 112 */ "Insert",
          117  + /* 113 */ "Destroy",
          118  + /* 114 */ "ReadCookie",
          119  + /* 115 */ "ForceInt",
          120  + /* 116 */ "LoadAnalysis",
          121  + /* 117 */ "Explain",
          122  + /* 118 */ "IfMemZero",
          123  + /* 119 */ "OpenPseudo",
          124  + /* 120 */ "OpenEphemeral",
          125  + /* 121 */ "Null",
          126  + /* 122 */ "Blob",
          127  + /* 123 */ "MemStore",
          128  + /* 124 */ "Rewind",
          129  + /* 125 */ "MoveGe",
   130    130    /* 126 */ "Real",
   131    131    /* 127 */ "HexBlob",
   132         - /* 128 */ "MoveGe",
   133         - /* 129 */ "VBegin",
   134         - /* 130 */ "VUpdate",
   135         - /* 131 */ "VCreate",
   136         - /* 132 */ "MemMove",
   137         - /* 133 */ "MemNull",
   138         - /* 134 */ "Found",
   139         - /* 135 */ "NullRow",
          132  + /* 128 */ "VBegin",
          133  + /* 129 */ "VUpdate",
          134  + /* 130 */ "VCreate",
          135  + /* 131 */ "MemMove",
          136  + /* 132 */ "MemNull",
          137  + /* 133 */ "Found",
          138  + /* 134 */ "NullRow",
          139  + /* 135 */ "NotUsed_135",
   140    140    /* 136 */ "NotUsed_136",
   141    141    /* 137 */ "NotUsed_137",
   142    142    /* 138 */ "NotUsed_138",
   143    143    /* 139 */ "ToText",
   144    144    /* 140 */ "ToBlob",
   145    145    /* 141 */ "ToNumeric",
   146    146    /* 142 */ "ToInt",
   147    147    /* 143 */ "ToReal",
   148    148   };
   149    149   #endif

Changes to SQLite.Interop/src/opcodes.h.

    39     39   #define OP_String                              26
    40     40   #define OP_RealAffinity                        27
    41     41   #define OP_ParseSchema                         28
    42     42   #define OP_VOpen                               29
    43     43   #define OP_Close                               30
    44     44   #define OP_CreateIndex                         31
    45     45   #define OP_IsUnique                            32
    46         -#define OP_IdxIsNull                           33
    47         -#define OP_NotFound                            34
    48         -#define OP_Int64                               35
    49         -#define OP_MustBeInt                           36
    50         -#define OP_Halt                                37
    51         -#define OP_Rowid                               38
    52         -#define OP_IdxLT                               39
    53         -#define OP_AddImm                              40
    54         -#define OP_Statement                           41
    55         -#define OP_RowData                             42
    56         -#define OP_MemMax                              43
    57         -#define OP_Push                                44
           46  +#define OP_NotFound                            33
           47  +#define OP_Int64                               34
           48  +#define OP_MustBeInt                           35
           49  +#define OP_Halt                                36
           50  +#define OP_Rowid                               37
           51  +#define OP_IdxLT                               38
           52  +#define OP_AddImm                              39
           53  +#define OP_Statement                           40
           54  +#define OP_RowData                             41
           55  +#define OP_MemMax                              42
           56  +#define OP_Push                                43
    58     57   #define OP_Or                                  61   /* same as TK_OR       */
    59         -#define OP_NotExists                           45
    60         -#define OP_MemIncr                             46
    61         -#define OP_Gosub                               47
           58  +#define OP_NotExists                           44
           59  +#define OP_MemIncr                             45
           60  +#define OP_Gosub                               46
    62     61   #define OP_Divide                              82   /* same as TK_SLASH    */
    63         -#define OP_Integer                             48
           62  +#define OP_Integer                             47
    64     63   #define OP_ToNumeric                          141   /* same as TK_TO_NUMERIC*/
    65         -#define OP_MemInt                              49
    66         -#define OP_Prev                                50
           64  +#define OP_MemInt                              48
           65  +#define OP_Prev                                49
    67     66   #define OP_Concat                              84   /* same as TK_CONCAT   */
    68     67   #define OP_BitAnd                              75   /* same as TK_BITAND   */
    69         -#define OP_VColumn                             51
    70         -#define OP_CreateTable                         52
    71         -#define OP_Last                                53
           68  +#define OP_VColumn                             50
           69  +#define OP_CreateTable                         51
           70  +#define OP_Last                                52
    72     71   #define OP_IsNull                              66   /* same as TK_ISNULL   */
    73         -#define OP_IdxRowid                            54
    74         -#define OP_MakeIdxRec                          55
           72  +#define OP_IdxRowid                            53
           73  +#define OP_MakeIdxRec                          54
    75     74   #define OP_ShiftRight                          78   /* same as TK_RSHIFT   */
    76         -#define OP_ResetCount                          56
    77         -#define OP_FifoWrite                           57
    78         -#define OP_Callback                            58
    79         -#define OP_ContextPush                         59
    80         -#define OP_DropTrigger                         60
    81         -#define OP_DropIndex                           63
    82         -#define OP_IdxGE                               64
    83         -#define OP_IdxDelete                           65
    84         -#define OP_Vacuum                              74
    85         -#define OP_MoveLe                              86
    86         -#define OP_IfNot                               89
    87         -#define OP_DropTable                           90
    88         -#define OP_MakeRecord                          91
           75  +#define OP_ResetCount                          55
           76  +#define OP_FifoWrite                           56
           77  +#define OP_Callback                            57
           78  +#define OP_ContextPush                         58
           79  +#define OP_DropTrigger                         59
           80  +#define OP_DropIndex                           60
           81  +#define OP_IdxGE                               63
           82  +#define OP_IdxDelete                           64
           83  +#define OP_Vacuum                              65
           84  +#define OP_MoveLe                              74
           85  +#define OP_IfNot                               86
           86  +#define OP_DropTable                           89
           87  +#define OP_MakeRecord                          90
    89     88   #define OP_ToBlob                             140   /* same as TK_TO_BLOB  */
    90         -#define OP_Delete                              92
    91         -#define OP_AggFinal                            93
           89  +#define OP_Delete                              91
           90  +#define OP_AggFinal                            92
    92     91   #define OP_ShiftLeft                           77   /* same as TK_LSHIFT   */
    93         -#define OP_Dup                                 94
    94         -#define OP_Goto                                95
    95         -#define OP_TableLock                           96
    96         -#define OP_FifoRead                            97
    97         -#define OP_Clear                               98
    98         -#define OP_IdxGT                               99
    99         -#define OP_MoveLt                             100
           92  +#define OP_Dup                                 93
           93  +#define OP_Goto                                94
           94  +#define OP_TableLock                           95
           95  +#define OP_FifoRead                            96
           96  +#define OP_Clear                               97
           97  +#define OP_IdxGT                               98
           98  +#define OP_MoveLt                              99
   100     99   #define OP_Le                                  71   /* same as TK_LE       */
   101         -#define OP_VerifyCookie                       101
   102         -#define OP_AggStep                            102
   103         -#define OP_Pull                               103
          100  +#define OP_VerifyCookie                       100
          101  +#define OP_AggStep                            101
          102  +#define OP_Pull                               102
   104    103   #define OP_ToText                             139   /* same as TK_TO_TEXT  */
   105    104   #define OP_Not                                 16   /* same as TK_NOT      */
   106    105   #define OP_ToReal                             143   /* same as TK_TO_REAL  */
   107         -#define OP_SetNumColumns                      104
   108         -#define OP_AbsValue                           105
   109         -#define OP_Transaction                        106
   110         -#define OP_VFilter                            107
          106  +#define OP_SetNumColumns                      103
          107  +#define OP_AbsValue                           104
          108  +#define OP_Transaction                        105
          109  +#define OP_VFilter                            106
   111    110   #define OP_Negative                            85   /* same as TK_UMINUS   */
   112    111   #define OP_Ne                                  68   /* same as TK_NE       */
   113         -#define OP_VDestroy                           108
   114         -#define OP_ContextPop                         109
          112  +#define OP_VDestroy                           107
          113  +#define OP_ContextPop                         108
   115    114   #define OP_BitOr                               76   /* same as TK_BITOR    */
   116         -#define OP_Next                               110
   117         -#define OP_IdxInsert                          111
   118         -#define OP_Distinct                           112
          115  +#define OP_Next                               109
          116  +#define OP_IdxInsert                          110
          117  +#define OP_Distinct                           111
   119    118   #define OP_Lt                                  72   /* same as TK_LT       */
   120         -#define OP_Insert                             113
   121         -#define OP_Destroy                            114
   122         -#define OP_ReadCookie                         115
   123         -#define OP_ForceInt                           116
   124         -#define OP_LoadAnalysis                       117
   125         -#define OP_Explain                            118
   126         -#define OP_IfMemZero                          119
   127         -#define OP_OpenPseudo                         120
   128         -#define OP_OpenEphemeral                      121
   129         -#define OP_Null                               122
   130         -#define OP_Blob                               123
          119  +#define OP_Insert                             112
          120  +#define OP_Destroy                            113
          121  +#define OP_ReadCookie                         114
          122  +#define OP_ForceInt                           115
          123  +#define OP_LoadAnalysis                       116
          124  +#define OP_Explain                            117
          125  +#define OP_IfMemZero                          118
          126  +#define OP_OpenPseudo                         119
          127  +#define OP_OpenEphemeral                      120
          128  +#define OP_Null                               121
          129  +#define OP_Blob                               122
   131    130   #define OP_Add                                 79   /* same as TK_PLUS     */
   132         -#define OP_MemStore                           124
   133         -#define OP_Rewind                             125
   134         -#define OP_MoveGe                             128
   135         -#define OP_VBegin                             129
   136         -#define OP_VUpdate                            130
          131  +#define OP_MemStore                           123
          132  +#define OP_Rewind                             124
          133  +#define OP_MoveGe                             125
          134  +#define OP_VBegin                             128
          135  +#define OP_VUpdate                            129
   137    136   #define OP_BitNot                              87   /* same as TK_BITNOT   */
   138         -#define OP_VCreate                            131
   139         -#define OP_MemMove                            132
   140         -#define OP_MemNull                            133
   141         -#define OP_Found                              134
   142         -#define OP_NullRow                            135
          137  +#define OP_VCreate                            130
          138  +#define OP_MemMove                            131
          139  +#define OP_MemNull                            132
          140  +#define OP_Found                              133
          141  +#define OP_NullRow                            134
   143    142   
   144    143   /* The following opcode values are never used */
          144  +#define OP_NotUsed_135                        135
   145    145   #define OP_NotUsed_136                        136
   146    146   #define OP_NotUsed_137                        137
   147    147   #define OP_NotUsed_138                        138
   148    148   
   149    149   /* Opcodes that are guaranteed to never push a value onto the stack
   150    150   ** contain a 1 their corresponding position of the following mask
   151    151   ** set.  See the opcodeNoPush() function in vdbeaux.c  */
   152    152   #define NOPUSH_MASK_0 0xeeb4
   153    153   #define NOPUSH_MASK_1 0x796b
   154         -#define NOPUSH_MASK_2 0xfbb7
   155         -#define NOPUSH_MASK_3 0xff24
          154  +#define NOPUSH_MASK_2 0x7ddb
          155  +#define NOPUSH_MASK_3 0xff92
   156    156   #define NOPUSH_MASK_4 0xffff
   157         -#define NOPUSH_MASK_5 0xb6ef
   158         -#define NOPUSH_MASK_6 0xfdfd
   159         -#define NOPUSH_MASK_7 0x33b3
   160         -#define NOPUSH_MASK_8 0xf8cf
          157  +#define NOPUSH_MASK_5 0xdaef
          158  +#define NOPUSH_MASK_6 0xfefe
          159  +#define NOPUSH_MASK_7 0x39d9
          160  +#define NOPUSH_MASK_8 0xf867
   161    161   #define NOPUSH_MASK_9 0x0000

Changes to SQLite.Interop/src/os.h.

    77     77   ** Temporary files are named starting with this prefix followed by 16 random
    78     78   ** alphanumeric characters, and no file extension. They are stored in the
    79     79   ** OS's standard temporary file directory, and are deleted prior to exit.
    80     80   ** If sqlite is being embedded in another program, you may wish to change the
    81     81   ** prefix to reflect your program's name, so that if your program exits
    82     82   ** prematurely, old temporary files can be easily identified. This can be done
    83     83   ** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
           84  +**
           85  +** 2006-10-31:  The default prefix used to be "sqlite_".  But then
           86  +** Mcafee started using SQLite in their anti-virus product and it
           87  +** started putting files with the "sqlite" name in the c:/temp folder.
           88  +** This annoyed many windows users.  Those users would then do a 
           89  +** Google search for "sqlite", find the telephone numbers of the
           90  +** developers and call to wake them up at night and complain.
           91  +** For this reason, the default name prefix is changed to be "sqlite" 
           92  +** spelled backwards.  So the temp files are still identified, but
           93  +** anybody smart enough to figure out the code is also likely smart
           94  +** enough to know that calling the developer will not help get rid
           95  +** of the file.
    84     96   */
    85     97   #ifndef TEMP_FILE_PREFIX
    86         -# define TEMP_FILE_PREFIX "sqlite_"
           98  +# define TEMP_FILE_PREFIX "etilqs_"
    87     99   #endif
    88    100   
    89    101   /*
    90    102   ** Define the interfaces for Unix, Windows, and OS/2.
    91    103   */
    92    104   #if OS_UNIX
    93    105   #define sqlite3OsOpenReadWrite      sqlite3UnixOpenReadWrite
................................................................................
   106    118   #define sqlite3OsLeaveMutex         sqlite3UnixLeaveMutex
   107    119   #define sqlite3OsInMutex            sqlite3UnixInMutex
   108    120   #define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
   109    121   #define sqlite3OsMalloc             sqlite3GenericMalloc
   110    122   #define sqlite3OsRealloc            sqlite3GenericRealloc
   111    123   #define sqlite3OsFree               sqlite3GenericFree
   112    124   #define sqlite3OsAllocationSize     sqlite3GenericAllocationSize
          125  +#define sqlite3OsDlopen             sqlite3UnixDlopen
          126  +#define sqlite3OsDlsym              sqlite3UnixDlsym
          127  +#define sqlite3OsDlclose            sqlite3UnixDlclose
   113    128   #endif
   114    129   #if OS_WIN
   115    130   #define sqlite3OsOpenReadWrite      sqlite3WinOpenReadWrite
   116    131   #define sqlite3OsOpenExclusive      sqlite3WinOpenExclusive
   117    132   #define sqlite3OsOpenReadOnly       sqlite3WinOpenReadOnly
   118    133   #define sqlite3OsDelete             sqlite3WinDelete
   119    134   #define sqlite3OsFileExists         sqlite3WinFileExists
................................................................................
   128    143   #define sqlite3OsLeaveMutex         sqlite3WinLeaveMutex
   129    144   #define sqlite3OsInMutex            sqlite3WinInMutex
   130    145   #define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
   131    146   #define sqlite3OsMalloc             sqlite3GenericMalloc
   132    147   #define sqlite3OsRealloc            sqlite3GenericRealloc
   133    148   #define sqlite3OsFree               sqlite3GenericFree
   134    149   #define sqlite3OsAllocationSize     sqlite3GenericAllocationSize
          150  +#define sqlite3OsDlopen             sqlite3WinDlopen
          151  +#define sqlite3OsDlsym              sqlite3WinDlsym
          152  +#define sqlite3OsDlclose            sqlite3WinDlclose
   135    153   #endif
   136    154   #if OS_OS2
   137    155   #define sqlite3OsOpenReadWrite      sqlite3Os2OpenReadWrite
   138    156   #define sqlite3OsOpenExclusive      sqlite3Os2OpenExclusive
   139    157   #define sqlite3OsOpenReadOnly       sqlite3Os2OpenReadOnly
   140    158   #define sqlite3OsDelete             sqlite3Os2Delete
   141    159   #define sqlite3OsFileExists         sqlite3Os2FileExists
................................................................................
   150    168   #define sqlite3OsLeaveMutex         sqlite3Os2LeaveMutex
   151    169   #define sqlite3OsInMutex            sqlite3Os2InMutex
   152    170   #define sqlite3OsThreadSpecificData sqlite3Os2ThreadSpecificData
   153    171   #define sqlite3OsMalloc             sqlite3GenericMalloc
   154    172   #define sqlite3OsRealloc            sqlite3GenericRealloc
   155    173   #define sqlite3OsFree               sqlite3GenericFree
   156    174   #define sqlite3OsAllocationSize     sqlite3GenericAllocationSize
          175  +#define sqlite3OsDlopen             sqlite3Os2Dlopen
          176  +#define sqlite3OsDlsym              sqlite3Os2Dlsym
          177  +#define sqlite3OsDlclose            sqlite3Os2Dlclose
   157    178   #endif
   158    179   
   159    180   
   160    181   
   161    182   
   162    183   /*
   163    184   ** If using an alternative OS interface, then we must have an "os_other.h"
................................................................................
   333    354   void sqlite3OsLeaveMutex(void);
   334    355   int sqlite3OsInMutex(int);
   335    356   ThreadData *sqlite3OsThreadSpecificData(int);
   336    357   void *sqlite3OsMalloc(int);
   337    358   void *sqlite3OsRealloc(void *, int);
   338    359   void sqlite3OsFree(void *);
   339    360   int sqlite3OsAllocationSize(void *);
          361  +void *sqlite3OsDlopen(const char*);
          362  +void *sqlite3OsDlsym(void*, const char*);
          363  +int sqlite3OsDlclose(void*);
   340    364   
   341    365   /*
   342    366   ** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
   343    367   ** interface routines are not called directly but are invoked using
   344    368   ** pointers to functions.  This allows the implementation of various
   345    369   ** OS-layer interface routines to be modified at run-time.  There are
   346    370   ** obscure but legitimate reasons for wanting to do this.  But for
................................................................................
   377    401     int (*xInMutex)(int);
   378    402     ThreadData *(*xThreadSpecificData)(int);
   379    403   
   380    404     void *(*xMalloc)(int);
   381    405     void *(*xRealloc)(void *, int);
   382    406     void (*xFree)(void *);
   383    407     int (*xAllocationSize)(void *);
          408  +
          409  +  void *(*xDlopen)(const char*);
          410  +  void *(*xDlsym)(void*, const char*);
          411  +  int (*xDlclose)(void*);
   384    412   };
   385    413   
   386    414   /* Macro used to comment out routines that do not exists when there is
   387         -** no disk I/O 
          415  +** no disk I/O or extension loading
   388    416   */
   389    417   #ifdef SQLITE_OMIT_DISKIO
   390    418   # define IF_DISKIO(X)  0
   391    419   #else
   392    420   # define IF_DISKIO(X)  X
   393    421   #endif
          422  +#ifdef SQLITE_OMIT_LOAD_EXTENSION
          423  +# define IF_DLOPEN(X)  0
          424  +#else
          425  +# define IF_DLOPEN(X)  X
          426  +#endif
          427  +
   394    428   
   395    429   #ifdef _SQLITE_OS_C_
   396    430     /*
   397    431     ** The os.c file implements the global virtual function table.
   398    432     */
   399    433     struct sqlite3OsVtbl sqlite3Os = {
   400    434       IF_DISKIO( sqlite3OsOpenReadWrite ),
................................................................................
   412    446       sqlite3OsEnterMutex,
   413    447       sqlite3OsLeaveMutex,
   414    448       sqlite3OsInMutex,
   415    449       sqlite3OsThreadSpecificData,
   416    450       sqlite3OsMalloc,
   417    451       sqlite3OsRealloc,
   418    452       sqlite3OsFree,
   419         -    sqlite3OsAllocationSize
          453  +    sqlite3OsAllocationSize,
          454  +    IF_DLOPEN( sqlite3OsDlopen ),
          455  +    IF_DLOPEN( sqlite3OsDlsym ),
          456  +    IF_DLOPEN( sqlite3OsDlclose ),
   420    457     };
   421    458   #else
   422    459     /*
   423    460     ** Files other than os.c just reference the global virtual function table. 
   424    461     */
   425    462     extern struct sqlite3OsVtbl sqlite3Os;
   426    463   #endif /* _SQLITE_OS_C_ */

Changes to SQLite.Interop/src/os_os2.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains code that is specific to OS/2.
    14     14   */
           15  +
           16  +#if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
           17  +/* os2safe.h has to be included before os2.h, needed for high mem */
           18  +#include <os2safe.h>
           19  +#endif
           20  +
    15     21   #include "sqliteInt.h"
    16     22   #include "os.h"
    17     23   
    18     24   #if OS_OS2
    19     25   
    20     26   /*
    21     27   ** Macros used to determine whether or not to use threads.
................................................................................
   286    292   */
   287    293   int os2Read( OsFile *id, void *pBuf, int amt ){
   288    294     ULONG got;
   289    295     assert( id!=0 );
   290    296     SimulateIOError( return SQLITE_IOERR );
   291    297     TRACE3( "READ %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );
   292    298     DosRead( ((os2File*)id)->h, pBuf, amt, &got );
   293         -  return (got == (ULONG)amt) ? SQLITE_OK : SQLITE_IOERR;
          299  +  return (got == (ULONG)amt) ? SQLITE_OK : SQLITE_IOERR_SHORT_READ;
   294    300   }
   295    301   
   296    302   /*
   297    303   ** Write data from a buffer into a file.  Return SQLITE_OK on success
   298    304   ** or some other error code on failure.
   299    305   */
   300    306   int os2Write( OsFile *id, const void *pBuf, int amt ){
................................................................................
   763    769   }
   764    770   
   765    771   #endif /* SQLITE_OMIT_DISKIO */
   766    772   /***************************************************************************
   767    773   ** Everything above deals with file I/O.  Everything that follows deals
   768    774   ** with other miscellanous aspects of the operating system interface
   769    775   ****************************************************************************/
          776  +
          777  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
          778  +/*
          779  +** Interfaces for opening a shared library, finding entry points
          780  +** within the shared library, and closing the shared library.
          781  +*/
          782  +void *sqlite3Os2Dlopen(const char *zFilename){
          783  +  return 0;
          784  +}
          785  +void *sqlite3Os2Dlsym(void *pHandle, const char *zSymbol){
          786  +  return 0;
          787  +}
          788  +int sqlite3Os2Dlclose(void *pHandle){
          789  +  return 0;
          790  +}
          791  +#endif /* SQLITE_OMIT_LOAD_EXTENSION */
          792  +
   770    793   
   771    794   /*
   772    795   ** Get information to seed the random number generator.  The seed
   773    796   ** is written into the buffer zBuf[256].  The calling function must
   774    797   ** supply a sufficiently large buffer.
   775    798   */
   776    799   int sqlite3Os2RandomSeed( char *zBuf ){

Changes to SQLite.Interop/src/os_unix.c.

  1022   1022     assert( id );
  1023   1023     TIMER_START;
  1024   1024     got = seekAndRead((unixFile*)id, pBuf, amt);
  1025   1025     TIMER_END;
  1026   1026     TRACE5("READ    %-3d %5d %7d %d\n", ((unixFile*)id)->h, got,
  1027   1027             last_page, TIMER_ELAPSED);
  1028   1028     SEEK(0);
  1029         -  SimulateIOError( got=0 );
         1029  +  SimulateIOError( got = -1 );
  1030   1030     if( got==amt ){
  1031   1031       return SQLITE_OK;
  1032   1032     }else if( got<0 ){
  1033   1033       return SQLITE_IOERR_READ;
  1034   1034     }else{
         1035  +    memset(&((char*)pBuf)[got], 0, amt-got);
  1035   1036       return SQLITE_IOERR_SHORT_READ;
  1036   1037     }
  1037   1038   }
  1038   1039   
  1039   1040   /*
  1040   1041   ** Seek to the offset in id->offset then read cnt bytes into pBuf.
  1041   1042   ** Return the number of bytes actually read.  Update the offset.
................................................................................
  2441   2442    */
  2442   2443   static int allocateUnixFile(
  2443   2444     int h,                  /* Open file descriptor of file being opened */
  2444   2445     OsFile **pId,           /* Write completed initialization here */
  2445   2446     const char *zFilename,  /* Name of the file being opened */
  2446   2447     int delFlag             /* Delete-on-or-before-close flag */
  2447   2448   ){
  2448         -  sqlite3LockingStyle lockStyle;
         2449  +  sqlite3LockingStyle lockingStyle;
  2449   2450     unixFile *pNew;
  2450   2451     unixFile f;
  2451   2452     int rc;
  2452   2453   
  2453         -  lockingStyle = sqlite3DetectLockingStyle(zFilename, f.h);
         2454  +  lockingStyle = sqlite3DetectLockingStyle(zFilename, h);
  2454   2455     if ( lockingStyle == posixLockingStyle ) {
  2455   2456       sqlite3OsEnterMutex();
  2456   2457       rc = findLockInfo(h, &f.pLock, &f.pOpen);
  2457   2458       sqlite3OsLeaveMutex();
  2458   2459       if( rc ){
  2459   2460         close(h);
  2460   2461         unlink(zFilename);
................................................................................
  2481   2482       releaseLockInfo(f.pLock);
  2482   2483       releaseOpenCnt(f.pOpen);
  2483   2484       sqlite3OsLeaveMutex();
  2484   2485       *pId = 0;
  2485   2486       return SQLITE_NOMEM;
  2486   2487     }else{
  2487   2488       *pNew = f;
  2488         -    switch(lockStyle) {
         2489  +    switch(lockingStyle) {
  2489   2490         case afpLockingStyle:
  2490   2491           /* afp locking uses the file path so it needs to be included in
  2491   2492           ** the afpLockingContext */
  2492   2493           pNew->pMethod = &sqlite3AFPLockingUnixIoMethod;
  2493   2494           pNew->lockingContext = 
  2494   2495             sqlite3ThreadSafeMalloc(sizeof(afpLockingContext));
  2495   2496           ((afpLockingContext *)pNew->lockingContext)->filePath = 
................................................................................
  2577   2578   #endif /* SQLITE_OMIT_DISKIO */
  2578   2579   /***************************************************************************
  2579   2580   ** Everything above deals with file I/O.  Everything that follows deals
  2580   2581   ** with other miscellanous aspects of the operating system interface
  2581   2582   ****************************************************************************/
  2582   2583   
  2583   2584   
         2585  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
         2586  +/*
         2587  +** Interfaces for opening a shared library, finding entry points
         2588  +** within the shared library, and closing the shared library.
         2589  +*/
         2590  +#include <dlfcn.h>
         2591  +void *sqlite3UnixDlopen(const char *zFilename){
         2592  +  return dlopen(zFilename, RTLD_NOW | RTLD_GLOBAL);
         2593  +}
         2594  +void *sqlite3UnixDlsym(void *pHandle, const char *zSymbol){
         2595  +  return dlsym(pHandle, zSymbol);
         2596  +}
         2597  +int sqlite3UnixDlclose(void *pHandle){
         2598  +  return dlclose(pHandle);
         2599  +}
         2600  +#endif /* SQLITE_OMIT_LOAD_EXTENSION */
         2601  +
  2584   2602   /*
  2585   2603   ** Get information to seed the random number generator.  The seed
  2586   2604   ** is written into the buffer zBuf[256].  The calling function must
  2587   2605   ** supply a sufficiently large buffer.
  2588   2606   */
  2589   2607   int sqlite3UnixRandomSeed(char *zBuf){
  2590   2608     /* We have to initialize zBuf to prevent valgrind from reporting

Changes to SQLite.Interop/src/os_win.c.

   120    120         sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
   121    121       }
   122    122       return sqlite3_os_type==2;
   123    123     }
   124    124   #endif /* OS_WINCE */
   125    125   
   126    126   /*
   127         -** Convert a UTF-8 string to UTF-32.  Space to hold the returned string
   128         -** is obtained from sqliteMalloc.
          127  +** Convert a UTF-8 string to microsoft unicode (UTF-16?). 
          128  +**
          129  +** Space to hold the returned string is obtained from sqliteMalloc.
   129    130   */
   130    131   static WCHAR *utf8ToUnicode(const char *zFilename){
   131    132     int nChar;
   132    133     WCHAR *zWideFilename;
   133    134   
   134         -  if( !isNT() ){
   135         -    return 0;
   136         -  }
   137    135     nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
   138    136     zWideFilename = sqliteMalloc( nChar*sizeof(zWideFilename[0]) );
   139    137     if( zWideFilename==0 ){
   140    138       return 0;
   141    139     }
   142    140     nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nChar);
   143    141     if( nChar==0 ){
................................................................................
   144    142       sqliteFree(zWideFilename);
   145    143       zWideFilename = 0;
   146    144     }
   147    145     return zWideFilename;
   148    146   }
   149    147   
   150    148   /*
   151         -** Convert UTF-32 to UTF-8.  Space to hold the returned string is
          149  +** Convert microsoft unicode to UTF-8.  Space to hold the returned string is
   152    150   ** obtained from sqliteMalloc().
   153    151   */
   154    152   static char *unicodeToUtf8(const WCHAR *zWideFilename){
   155    153     int nByte;
   156    154     char *zFilename;
   157    155   
   158    156     nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
................................................................................
   164    162                                 0, 0);
   165    163     if( nByte == 0 ){
   166    164       sqliteFree(zFilename);
   167    165       zFilename = 0;
   168    166     }
   169    167     return zFilename;
   170    168   }
          169  +
          170  +/*
          171  +** Convert an ansi string to microsoft unicode, based on the
          172  +** current codepage settings for file apis.
          173  +** 
          174  +** Space to hold the returned string is obtained
          175  +** from sqliteMalloc.
          176  +*/
          177  +static WCHAR *mbcsToUnicode(const char *zFilename){
          178  +  int nByte;
          179  +  WCHAR *zMbcsFilename;
          180  +  int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
          181  +
          182  +  nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
          183  +  zMbcsFilename = sqliteMalloc( nByte*sizeof(zMbcsFilename[0]) );
          184  +  if( zMbcsFilename==0 ){
          185  +    return 0;
          186  +  }
          187  +  nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
          188  +  if( nByte==0 ){
          189  +    sqliteFree(zMbcsFilename);
          190  +    zMbcsFilename = 0;
          191  +  }
          192  +  return zMbcsFilename;
          193  +}
          194  +
          195  +/*
          196  +** Convert microsoft unicode to multibyte character string, based on the
          197  +** user's Ansi codepage.
          198  +**
          199  +** Space to hold the returned string is obtained from
          200  +** sqliteMalloc().
          201  +*/
          202  +static char *unicodeToMbcs(const WCHAR *zWideFilename){
          203  +  int nByte;
          204  +  char *zFilename;
          205  +  int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
          206  +
          207  +  nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
          208  +  zFilename = sqliteMalloc( nByte );
          209  +  if( zFilename==0 ){
          210  +    return 0;
          211  +  }
          212  +  nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, nByte,
          213  +                              0, 0);
          214  +  if( nByte == 0 ){
          215  +    sqliteFree(zFilename);
          216  +    zFilename = 0;
          217  +  }
          218  +  return zFilename;
          219  +}
          220  +
          221  +/*
          222  +** Convert multibyte character string to UTF-8.  Space to hold the
          223  +** returned string is obtained from sqliteMalloc().
          224  +*/
          225  +static char *mbcsToUtf8(const char *zFilename){
          226  +  char *zFilenameUtf8;
          227  +  WCHAR *zTmpWide;
          228  +
          229  +  zTmpWide = mbcsToUnicode(zFilename);
          230  +  if( zTmpWide==0 ){
          231  +    return 0;
          232  +  }
          233  +  zFilenameUtf8 = unicodeToUtf8(zTmpWide);
          234  +  sqliteFree(zTmpWide);
          235  +  return zFilenameUtf8;
          236  +}
          237  +
          238  +/*
          239  +** Convert UTF-8 to multibyte character string.  Space to hold the 
          240  +** returned string is obtained from sqliteMalloc().
          241  +*/
          242  +static char *utf8ToMbcs(const char *zFilename){
          243  +  char *zFilenameMbcs;
          244  +  WCHAR *zTmpWide;
          245  +
          246  +  zTmpWide = utf8ToUnicode(zFilename);
          247  +  if( zTmpWide==0 ){
          248  +    return 0;
          249  +  }
          250  +  zFilenameMbcs = unicodeToMbcs(zTmpWide);
          251  +  sqliteFree(zTmpWide);
          252  +  return zFilenameMbcs;
          253  +}
   171    254   
   172    255   #if OS_WINCE
   173    256   /*************************************************************************
   174    257   ** This section contains code for WinCE only.
   175    258   */
   176    259   /*
   177    260   ** WindowsCE does not have a localtime() function.  So create a
................................................................................
   470    553     }
   471    554     return FALSE;
   472    555   }
   473    556   /*
   474    557   ** End of the special code for wince
   475    558   *****************************************************************************/
   476    559   #endif /* OS_WINCE */
          560  +
          561  +/*
          562  +** Convert a UTF-8 filename into whatever form the underlying
          563  +** operating system wants filenames in.  Space to hold the result
          564  +** is obtained from sqliteMalloc and must be freed by the calling
          565  +** function.
          566  +*/
          567  +static void *convertUtf8Filename(const char *zFilename){
          568  +  void *zConverted = 0;
          569  +  if( isNT() ){
          570  +    zConverted = utf8ToUnicode(zFilename);
          571  +  }else{
          572  +    zConverted = utf8ToMbcs(zFilename);
          573  +  }
          574  +  /* caller will handle out of memory */
          575  +  return zConverted;
          576  +}
   477    577   
   478    578   /*
   479    579   ** Delete the named file.
   480    580   **
   481    581   ** Note that windows does not allow a file to be deleted if some other
   482    582   ** process has it open.  Sometimes a virus scanner or indexing program
   483    583   ** will open a journal file shortly after it is created in order to do
................................................................................
   485    585   ** file open, we will be unable to delete it.  To work around this
   486    586   ** problem, we delay 100 milliseconds and try to delete again.  Up
   487    587   ** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
   488    588   ** up and returning an error.
   489    589   */
   490    590   #define MX_DELETION_ATTEMPTS 3
   491    591   int sqlite3WinDelete(const char *zFilename){
   492         -  WCHAR *zWide = utf8ToUnicode(zFilename);
   493    592     int cnt = 0;
   494    593     int rc;
   495         -  if( zWide ){
          594  +  void *zConverted = convertUtf8Filename(zFilename);
          595  +  if( zConverted==0 ){
          596  +    return SQLITE_NOMEM;
          597  +  }
          598  +  if( isNT() ){
   496    599       do{
   497         -      rc = DeleteFileW(zWide);
   498         -    }while( rc==0 && GetFileAttributesW(zWide)!=0xffffffff 
          600  +      rc = DeleteFileW(zConverted);
          601  +    }while( rc==0 && GetFileAttributesW(zConverted)!=0xffffffff 
   499    602               && cnt++ < MX_DELETION_ATTEMPTS && (Sleep(100), 1) );
   500         -    sqliteFree(zWide);
   501    603     }else{
   502    604   #if OS_WINCE
   503    605       return SQLITE_NOMEM;
   504    606   #else
   505    607       do{
   506         -      rc = DeleteFileA(zFilename);
   507         -    }while( rc==0 && GetFileAttributesA(zFilename)!=0xffffffff
          608  +      rc = DeleteFileA(zConverted);
          609  +    }while( rc==0 && GetFileAttributesA(zConverted)!=0xffffffff
   508    610               && cnt++ < MX_DELETION_ATTEMPTS && (Sleep(100), 1) );
   509    611   #endif
   510    612     }
          613  +  sqliteFree(zConverted);
   511    614     TRACE2("DELETE \"%s\"\n", zFilename);
   512    615     return rc!=0 ? SQLITE_OK : SQLITE_IOERR;
   513    616   }
   514    617   
   515    618   /*
   516    619   ** Return TRUE if the named file exists.
   517    620   */
   518    621   int sqlite3WinFileExists(const char *zFilename){
   519    622     int exists = 0;
   520         -  WCHAR *zWide = utf8ToUnicode(zFilename);
   521         -  if( zWide ){
   522         -    exists = GetFileAttributesW(zWide) != 0xffffffff;
   523         -    sqliteFree(zWide);
          623  +  void *zConverted = convertUtf8Filename(zFilename);
          624  +  if( zConverted==0 ){
          625  +    return SQLITE_NOMEM;
          626  +  }
          627  +  if( isNT() ){
          628  +    exists = GetFileAttributesW((WCHAR*)zConverted) != 0xffffffff;
   524    629     }else{
   525    630   #if OS_WINCE
   526    631       return SQLITE_NOMEM;
   527    632   #else
   528         -    exists = GetFileAttributesA(zFilename) != 0xffffffff;
          633  +    exists = GetFileAttributesA((char*)zConverted) != 0xffffffff;
   529    634   #endif
   530    635     }
          636  +  sqliteFree(zConverted);
   531    637     return exists;
   532    638   }
   533    639   
   534    640   /* Forward declaration */
   535    641   static int allocateWinFile(winFile *pInit, OsFile **pId);
   536    642   
   537    643   /*
................................................................................
   550    656   int sqlite3WinOpenReadWrite(
   551    657     const char *zFilename,
   552    658     OsFile **pId,
   553    659     int *pReadonly
   554    660   ){
   555    661     winFile f;
   556    662     HANDLE h;
   557         -  WCHAR *zWide = utf8ToUnicode(zFilename);
          663  +  void *zConverted = convertUtf8Filename(zFilename);
          664  +  if( zConverted==0 ){
          665  +    return SQLITE_NOMEM;
          666  +  }
   558    667     assert( *pId==0 );
   559         -  if( zWide ){
   560         -    h = CreateFileW(zWide,
          668  +
          669  +  if( isNT() ){
          670  +    h = CreateFileW((WCHAR*)zConverted,
   561    671          GENERIC_READ | GENERIC_WRITE,
   562    672          FILE_SHARE_READ | FILE_SHARE_WRITE,
   563    673          NULL,
   564    674          OPEN_ALWAYS,
   565    675          FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
   566    676          NULL
   567    677       );
   568    678       if( h==INVALID_HANDLE_VALUE ){
   569         -      h = CreateFileW(zWide,
          679  +      h = CreateFileW((WCHAR*)zConverted,
   570    680            GENERIC_READ,
   571    681            FILE_SHARE_READ | FILE_SHARE_WRITE,
   572    682            NULL,
   573    683            OPEN_ALWAYS,
   574    684            FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
   575    685            NULL
   576    686         );
   577    687         if( h==INVALID_HANDLE_VALUE ){
   578         -        sqliteFree(zWide);
          688  +        sqliteFree(zConverted);
   579    689           return SQLITE_CANTOPEN;
   580    690         }
   581    691         *pReadonly = 1;
   582    692       }else{
   583    693         *pReadonly = 0;
   584    694       }
   585    695   #if OS_WINCE
   586    696       if (!winceCreateLock(zFilename, &f)){
   587    697         CloseHandle(h);
   588         -      sqliteFree(zWide);
          698  +      sqliteFree(zConverted);
   589    699         return SQLITE_CANTOPEN;
   590    700       }
   591    701   #endif
   592         -    sqliteFree(zWide);
   593    702     }else{
   594    703   #if OS_WINCE
   595    704       return SQLITE_NOMEM;
   596    705   #else
   597         -    h = CreateFileA(zFilename,
          706  +    h = CreateFileA((char*)zConverted,
   598    707          GENERIC_READ | GENERIC_WRITE,
   599    708          FILE_SHARE_READ | FILE_SHARE_WRITE,
   600    709          NULL,
   601    710          OPEN_ALWAYS,
   602    711          FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
   603    712          NULL
   604    713       );
   605    714       if( h==INVALID_HANDLE_VALUE ){
   606         -      h = CreateFileA(zFilename,
          715  +      h = CreateFileA((char*)zConverted,
   607    716            GENERIC_READ,
   608    717            FILE_SHARE_READ | FILE_SHARE_WRITE,
   609    718            NULL,
   610    719            OPEN_ALWAYS,
   611    720            FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
   612    721            NULL
   613    722         );
   614    723         if( h==INVALID_HANDLE_VALUE ){
          724  +        sqliteFree(zConverted);
   615    725           return SQLITE_CANTOPEN;
   616    726         }
   617    727         *pReadonly = 1;
   618    728       }else{
   619    729         *pReadonly = 0;
   620    730       }
   621    731   #endif /* OS_WINCE */
   622    732     }
          733  +
          734  +  sqliteFree(zConverted);
          735  +
   623    736     f.h = h;
   624    737   #if OS_WINCE
   625    738     f.zDeleteOnClose = 0;
   626    739   #endif
   627    740     TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename);
   628    741     return allocateWinFile(&f, pId);
   629    742   }
................................................................................
   648    761   ** To work around this bug, we pause for 100 milliseconds and attempt
   649    762   ** a second open after the first one fails.  The whole operation only
   650    763   ** fails if both open attempts are unsuccessful.
   651    764   */
   652    765   int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
   653    766     winFile f;
   654    767     HANDLE h;
   655         -  int fileflags;
   656         -  WCHAR *zWide = utf8ToUnicode(zFilename);
          768  +  DWORD fileflags;
          769  +  void *zConverted = convertUtf8Filename(zFilename);
          770  +  if( zConverted==0 ){
          771  +    return SQLITE_NOMEM;
          772  +  }
   657    773     assert( *pId == 0 );
   658    774     fileflags = FILE_FLAG_RANDOM_ACCESS;
   659    775   #if !OS_WINCE
   660    776     if( delFlag ){
   661    777       fileflags |= FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;
   662    778     }
   663    779   #endif
   664         -  if( zWide ){
          780  +  if( isNT() ){
   665    781       int cnt = 0;
   666    782       do{
   667         -      h = CreateFileW(zWide,
          783  +      h = CreateFileW((WCHAR*)zConverted,
   668    784            GENERIC_READ | GENERIC_WRITE,
   669    785            0,
   670    786            NULL,
   671    787            CREATE_ALWAYS,
   672    788            fileflags,
   673    789            NULL
   674    790         );
   675    791       }while( h==INVALID_HANDLE_VALUE && cnt++ < 2 && (Sleep(100), 1) );
   676         -    sqliteFree(zWide);
   677    792     }else{
   678    793   #if OS_WINCE
   679    794       return SQLITE_NOMEM;
   680    795   #else
   681    796       int cnt = 0;
   682    797       do{
   683         -      h = CreateFileA(zFilename,
          798  +      h = CreateFileA((char*)zConverted,
   684    799           GENERIC_READ | GENERIC_WRITE,
   685    800           0,
   686    801           NULL,
   687    802           CREATE_ALWAYS,
   688    803           fileflags,
   689    804           NULL
   690    805         );
   691    806       }while( h==INVALID_HANDLE_VALUE && cnt++ < 2 && (Sleep(100), 1) );
   692    807   #endif /* OS_WINCE */
   693    808     }
          809  +#if OS_WINCE
          810  +  if( delFlag && h!=INVALID_HANDLE_VALUE ){
          811  +    f.zDeleteOnClose = zConverted;
          812  +    zConverted = 0;
          813  +  }
          814  +  f.hMutex = NULL;
          815  +#endif
          816  +  sqliteFree(zConverted);
   694    817     if( h==INVALID_HANDLE_VALUE ){
   695    818       return SQLITE_CANTOPEN;
   696    819     }
   697    820     f.h = h;
   698         -#if OS_WINCE
   699         -  f.zDeleteOnClose = delFlag ? utf8ToUnicode(zFilename) : 0;
   700         -  f.hMutex = NULL;
   701         -#endif
   702    821     TRACE3("OPEN EX %d \"%s\"\n", h, zFilename);
   703    822     return allocateWinFile(&f, pId);
   704    823   }
   705    824   
   706    825   /*
   707    826   ** Attempt to open a new file for read-only access.
   708    827   **
................................................................................
   709    828   ** On success, write the file handle into *id and return SQLITE_OK.
   710    829   **
   711    830   ** On failure, return SQLITE_CANTOPEN.
   712    831   */
   713    832   int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
   714    833     winFile f;
   715    834     HANDLE h;
   716         -  WCHAR *zWide = utf8ToUnicode(zFilename);
          835  +  void *zConverted = convertUtf8Filename(zFilename);
          836  +  if( zConverted==0 ){
          837  +    return SQLITE_NOMEM;
          838  +  }
   717    839     assert( *pId==0 );
   718         -  if( zWide ){
   719         -    h = CreateFileW(zWide,
          840  +  if( isNT() ){
          841  +    h = CreateFileW((WCHAR*)zConverted,
   720    842          GENERIC_READ,
   721    843          0,
   722    844          NULL,
   723    845          OPEN_EXISTING,
   724    846          FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
   725    847          NULL
   726    848       );
   727         -    sqliteFree(zWide);
   728    849     }else{
   729    850   #if OS_WINCE
   730    851       return SQLITE_NOMEM;
   731    852   #else
   732         -    h = CreateFileA(zFilename,
          853  +    h = CreateFileA((char*)zConverted,
   733    854          GENERIC_READ,
   734    855          0,
   735    856          NULL,
   736    857          OPEN_EXISTING,
   737    858          FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
   738    859          NULL
   739    860       );
   740    861   #endif
   741    862     }
          863  +  sqliteFree(zConverted);
   742    864     if( h==INVALID_HANDLE_VALUE ){
   743    865       return SQLITE_CANTOPEN;
   744    866     }
   745    867     f.h = h;
   746    868   #if OS_WINCE
   747    869     f.zDeleteOnClose = 0;
   748    870     f.hMutex = NULL;
................................................................................
   800    922       WCHAR zWidePath[SQLITE_TEMPNAME_SIZE];
   801    923       GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath);
   802    924       zMulti = unicodeToUtf8(zWidePath);
   803    925       if( zMulti ){
   804    926         strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30);
   805    927         zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
   806    928         sqliteFree(zMulti);
          929  +    }else{
          930  +      return SQLITE_NOMEM;
   807    931       }
   808    932     }else{
   809         -    GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
          933  +    char *zUtf8;
          934  +    char zMbcsPath[SQLITE_TEMPNAME_SIZE];
          935  +    GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zMbcsPath);
          936  +    zUtf8 = mbcsToUtf8(zMbcsPath);
          937  +    if( zUtf8 ){
          938  +      strncpy(zTempPath, zUtf8, SQLITE_TEMPNAME_SIZE-30);
          939  +      zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
          940  +      sqliteFree(zUtf8);
          941  +    }else{
          942  +      return SQLITE_NOMEM;
          943  +    }
   810    944     }
   811    945     for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
   812    946     zTempPath[i] = 0;
   813    947     for(;;){
   814    948       sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
   815    949       j = strlen(zBuf);
   816    950       sqlite3Randomness(15, &zBuf[j]);
................................................................................
   862    996   ** Read data from a file into a buffer.  Return SQLITE_OK if all
   863    997   ** bytes were read successfully and SQLITE_IOERR if anything goes
   864    998   ** wrong.
   865    999   */
   866   1000   static int winRead(OsFile *id, void *pBuf, int amt){
   867   1001     DWORD got;
   868   1002     assert( id!=0 );
   869         -  SimulateIOError(return SQLITE_IOERR);
         1003  +  SimulateIOError(return SQLITE_IOERR_READ);
   870   1004     TRACE3("READ %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype);
   871   1005     if( !ReadFile(((winFile*)id)->h, pBuf, amt, &got, 0) ){
   872         -    got = 0;
         1006  +    return SQLITE_IOERR_READ;
   873   1007     }
   874   1008     if( got==(DWORD)amt ){
   875   1009       return SQLITE_OK;
   876   1010     }else{
   877         -    return SQLITE_IOERR;
         1011  +    memset(&((char*)pBuf)[got], 0, amt-got);
         1012  +    return SQLITE_IOERR_SHORT_READ;
   878   1013     }
   879   1014   }
   880   1015   
   881   1016   /*
   882   1017   ** Write data from a buffer into a file.  Return SQLITE_OK on success
   883   1018   ** or some other error code on failure.
   884   1019   */
   885   1020   static int winWrite(OsFile *id, const void *pBuf, int amt){
   886   1021     int rc = 0;
   887   1022     DWORD wrote;
   888   1023     assert( id!=0 );
   889         -  SimulateIOError(return SQLITE_IOERR);
         1024  +  SimulateIOError(return SQLITE_IOERR_READ);
   890   1025     SimulateDiskfullError(return SQLITE_FULL);
   891   1026     TRACE3("WRITE %d lock=%d\n", ((winFile*)id)->h, ((winFile*)id)->locktype);
   892   1027     assert( amt>0 );
   893   1028     while( amt>0 && (rc = WriteFile(((winFile*)id)->h, pBuf, amt, &wrote, 0))!=0
   894   1029            && wrote>0 ){
   895   1030       amt -= wrote;
   896   1031       pBuf = &((char*)pBuf)[wrote];
................................................................................
   942   1077   }
   943   1078   
   944   1079   /*
   945   1080   ** Sync the directory zDirname. This is a no-op on operating systems other
   946   1081   ** than UNIX.
   947   1082   */
   948   1083   int sqlite3WinSyncDirectory(const char *zDirname){
   949         -  SimulateIOError(return SQLITE_IOERR);
         1084  +  SimulateIOError(return SQLITE_IOERR_READ);
   950   1085     return SQLITE_OK;
   951   1086   }
   952   1087   
   953   1088   /*
   954   1089   ** Truncate an open file to a specified size
   955   1090   */
   956   1091   static int winTruncate(OsFile *id, i64 nByte){
   957   1092     LONG upperBits = nByte>>32;
   958   1093     assert( id!=0 );
   959   1094     TRACE3("TRUNCATE %d %lld\n", ((winFile*)id)->h, nByte);
   960         -  SimulateIOError(return SQLITE_IOERR);
         1095  +  SimulateIOError(return SQLITE_IOERR_TRUNCATE);
   961   1096     SetFilePointer(((winFile*)id)->h, nByte, &upperBits, FILE_BEGIN);
   962   1097     SetEndOfFile(((winFile*)id)->h);
   963   1098     return SQLITE_OK;
   964   1099   }
   965   1100   
   966   1101   /*
   967   1102   ** Determine the current size of a file in bytes
   968   1103   */
   969   1104   static int winFileSize(OsFile *id, i64 *pSize){
   970   1105     DWORD upperBits, lowerBits;
   971   1106     assert( id!=0 );
   972         -  SimulateIOError(return SQLITE_IOERR);
         1107  +  SimulateIOError(return SQLITE_IOERR_FSTAT);
   973   1108     lowerBits = GetFileSize(((winFile*)id)->h, &upperBits);
   974   1109     *pSize = (((i64)upperBits)<<32) + lowerBits;
   975   1110     return SQLITE_OK;
   976   1111   }
   977   1112   
   978   1113   /*
   979   1114   ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
................................................................................
  1020   1155   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
  1021   1156   /*
  1022   1157   ** Check that a given pathname is a directory and is writable 
  1023   1158   **
  1024   1159   */
  1025   1160   int sqlite3WinIsDirWritable(char *zDirname){
  1026   1161     int fileAttr;
  1027         -  WCHAR *zWide;
         1162  +  void *zConverted;
  1028   1163     if( zDirname==0 ) return 0;
  1029   1164     if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0;
  1030         -  zWide = utf8ToUnicode(zDirname);
  1031         -  if( zWide ){
  1032         -    fileAttr = GetFileAttributesW(zWide);
  1033         -    sqliteFree(zWide);
         1165  +
         1166  +  zConverted = convertUtf8Filename(zDirname);
         1167  +  if( zConverted==0 ){
         1168  +    return SQLITE_NOMEM;
         1169  +  }
         1170  +  if( isNT() ){
         1171  +    fileAttr = GetFileAttributesW((WCHAR*)zConverted);
  1034   1172     }else{
  1035   1173   #if OS_WINCE
  1036   1174       return 0;
  1037   1175   #else
  1038         -    fileAttr = GetFileAttributesA(zDirname);
         1176  +    fileAttr = GetFileAttributesA((char*)zConverted);
  1039   1177   #endif
  1040   1178     }
         1179  +  sqliteFree(zConverted);
  1041   1180     if( fileAttr == 0xffffffff ) return 0;
  1042   1181     if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
  1043   1182       return 0;
  1044   1183     }
  1045   1184     return 1;
  1046   1185   }
  1047   1186   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
................................................................................
  1222   1361             pFile->locktype, pFile->sharedLockByte);
  1223   1362     type = pFile->locktype;
  1224   1363     if( type>=EXCLUSIVE_LOCK ){
  1225   1364       UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1226   1365       if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
  1227   1366         /* This should never happen.  We should always be able to
  1228   1367         ** reacquire the read lock */
  1229         -      rc = SQLITE_IOERR;
         1368  +      rc = SQLITE_IOERR_UNLOCK;
  1230   1369       }
  1231   1370     }
  1232   1371     if( type>=RESERVED_LOCK ){
  1233   1372       UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1234   1373     }
  1235   1374     if( locktype==NO_LOCK && type>=SHARED_LOCK ){
  1236   1375       unlockReadLock(pFile);
................................................................................
  1256   1395     zFull = sqliteMalloc( nByte );
  1257   1396     if( zFull==0 ) return 0;
  1258   1397     if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
  1259   1398   #elif OS_WINCE
  1260   1399     /* WinCE has no concept of a relative pathname, or so I am told. */
  1261   1400     zFull = sqliteStrDup(zRelative);
  1262   1401   #else
  1263         -  char *zNotUsed;
  1264         -  WCHAR *zWide;
  1265   1402     int nByte;
  1266         -  zWide = utf8ToUnicode(zRelative);
  1267         -  if( zWide ){
  1268         -    WCHAR *zTemp, *zNotUsedW;
  1269         -    nByte = GetFullPathNameW(zWide, 0, 0, &zNotUsedW) + 1;
         1403  +  void *zConverted;
         1404  +  zConverted = convertUtf8Filename(zRelative);
         1405  +  if( isNT() ){
         1406  +    WCHAR *zTemp;
         1407  +    nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3;
  1270   1408       zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) );
  1271         -    if( zTemp==0 ) return 0;
  1272         -    GetFullPathNameW(zWide, nByte, zTemp, &zNotUsedW);
  1273         -    sqliteFree(zWide);
         1409  +    if( zTemp==0 ){
         1410  +      sqliteFree(zConverted);
         1411  +      return 0;
         1412  +    }
         1413  +    GetFullPathNameW((WCHAR*)zConverted, nByte, zTemp, 0);
         1414  +    sqliteFree(zConverted);
  1274   1415       zFull = unicodeToUtf8(zTemp);
  1275   1416       sqliteFree(zTemp);
  1276   1417     }else{
  1277         -    nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
  1278         -    zFull = sqliteMalloc( nByte*sizeof(zFull[0]) );
  1279         -    if( zFull==0 ) return 0;
  1280         -    GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
         1418  +    char *zTemp;
         1419  +    nByte = GetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
         1420  +    zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) );
         1421  +    if( zTemp==0 ){
         1422  +      sqliteFree(zConverted);
         1423  +      return 0;
         1424  +    }
         1425  +    GetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
         1426  +    sqliteFree(zConverted);
         1427  +    zFull = mbcsToUtf8(zTemp);
         1428  +    sqliteFree(zTemp);
  1281   1429     }
  1282   1430   #endif
  1283   1431     return zFull;
  1284   1432   }
  1285   1433   
  1286   1434   /*
  1287   1435   ** The fullSync option is meaningless on windows.   This is a no-op.
................................................................................
  1354   1502   
  1355   1503   
  1356   1504   #endif /* SQLITE_OMIT_DISKIO */
  1357   1505   /***************************************************************************
  1358   1506   ** Everything above deals with file I/O.  Everything that follows deals
  1359   1507   ** with other miscellanous aspects of the operating system interface
  1360   1508   ****************************************************************************/
         1509  +
         1510  +#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
         1511  +/*
         1512  +** Interfaces for opening a shared library, finding entry points
         1513  +** within the shared library, and closing the shared library.
         1514  +*/
         1515  +void *sqlite3WinDlopen(const char *zFilename){
         1516  +  HANDLE h;
         1517  +  void *zConverted = convertUtf8Filename(zFilename);
         1518  +  if( zConverted==0 ){
         1519  +    return 0;
         1520  +  }
         1521  +  if( isNT() ){
         1522  +    h = LoadLibraryW((WCHAR*)zConverted);
         1523  +  }else{
         1524  +#if OS_WINCE
         1525  +    return 0;
         1526  +#else
         1527  +    h = LoadLibraryA((char*)zConverted);
         1528  +#endif
         1529  +  }
         1530  +  sqliteFree(zConverted);
         1531  +  return (void*)h;
         1532  +  
         1533  +}
         1534  +void *sqlite3WinDlsym(void *pHandle, const char *zSymbol){
         1535  +#if OS_WINCE
         1536  +  /* The GetProcAddressA() routine is only available on wince. */
         1537  +  return GetProcAddressA((HANDLE)pHandle, zSymbol);
         1538  +#else
         1539  +  /* All other windows platforms expect GetProcAddress() to take
         1540  +  ** an Ansi string regardless of the _UNICODE setting */
         1541  +  return GetProcAddress((HANDLE)pHandle, zSymbol);
         1542  +#endif
         1543  +}
         1544  +int sqlite3WinDlclose(void *pHandle){
         1545  +  return FreeLibrary((HANDLE)pHandle);
         1546  +}
         1547  +#endif /* !SQLITE_OMIT_LOAD_EXTENSION */
  1361   1548   
  1362   1549   /*
  1363   1550   ** Get information to seed the random number generator.  The seed
  1364   1551   ** is written into the buffer zBuf[256].  The calling function must
  1365   1552   ** supply a sufficiently large buffer.
  1366   1553   */
  1367   1554   int sqlite3WinRandomSeed(char *zBuf){

Changes to SQLite.Interop/src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.25 2006/10/12 21:34:21 rmsimpson Exp $
           21  +** @(#) $Id: pager.c,v 1.26 2007/01/10 14:50:46 rmsimpson Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
    29     29   
    30     30   /*
    31     31   ** Macros for troubleshooting.  Normally turned off
    32     32   */
    33     33   #if 0
           34  +#define sqlite3DebugPrintf printf
    34     35   #define TRACE1(X)       sqlite3DebugPrintf(X)
    35     36   #define TRACE2(X,Y)     sqlite3DebugPrintf(X,Y)
    36     37   #define TRACE3(X,Y,Z)   sqlite3DebugPrintf(X,Y,Z)
    37     38   #define TRACE4(X,Y,Z,W) sqlite3DebugPrintf(X,Y,Z,W)
    38     39   #define TRACE5(X,Y,Z,W,V) sqlite3DebugPrintf(X,Y,Z,W,V)
    39     40   #else
    40     41   #define TRACE1(X)
................................................................................
   346    347   #else
   347    348   # define MEMDB pPager->memDb
   348    349   #endif
   349    350   
   350    351   /*
   351    352   ** The default size of a disk sector
   352    353   */
   353         -#define PAGER_SECTOR_SIZE 512
          354  +#ifndef PAGER_SECTOR_SIZE
          355  +# define PAGER_SECTOR_SIZE 512
          356  +#endif
   354    357   
   355    358   /*
   356    359   ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
   357    360   ** reserved for working around a windows/posix incompatibility). It is
   358    361   ** used in the journal to signify that the remainder of the journal file 
   359    362   ** is devoted to storing a master journal name - there are no more pages to
   360    363   ** roll back. See comments for function writeMasterJournal() for details.
................................................................................
   372    375   */
   373    376   #ifdef SQLITE_TEST
   374    377     int pager3_refinfo_enable = 0;
   375    378     static void pager_refinfo(PgHdr *p){
   376    379       static int cnt = 0;
   377    380       if( !pager3_refinfo_enable ) return;
   378    381       sqlite3DebugPrintf(
   379         -       "REFCNT: %4d addr=%p nRef=%d\n",
   380         -       p->pgno, PGHDR_TO_DATA(p), p->nRef
          382  +       "REFCNT: %4d addr=%p nRef=%-3d total=%d\n",
          383  +       p->pgno, PGHDR_TO_DATA(p), p->nRef, p->pPager->nRef
   381    384       );
   382    385       cnt++;   /* Something to set a breakpoint on */
   383    386     }
   384    387   # define REFINFO(X)  pager_refinfo(X)
   385    388   #else
   386    389   # define REFINFO(X)
   387    390   #endif
................................................................................
   842    845     if( pPager->aHash==0 ) return 0;
   843    846     p = pPager->aHash[pgno & (pPager->nHash-1)];
   844    847     while( p && p->pgno!=pgno ){
   845    848       p = p->pNextHash;
   846    849     }
   847    850     return p;
   848    851   }
          852  +
          853  +/*
          854  +** Unlock the database file.
          855  +**
          856  +** Once all locks have been removed from the database file, other
          857  +** processes or threads might change the file.  So make sure all of
          858  +** our internal cache is invalidated.
          859  +*/
          860  +static void pager_unlock(Pager *pPager){
          861  +  if( !MEMDB ){
          862  +    sqlite3OsUnlock(pPager->fd, NO_LOCK);
          863  +    pPager->dbSize = -1;
          864  +  }
          865  +  pPager->state = PAGER_UNLOCK;
          866  +  assert( pPager->pAll==0 );
          867  +}
          868  +
   849    869   
   850    870   /*
   851    871   ** Unlock the database and clear the in-memory cache.  This routine
   852    872   ** sets the state of the pager back to what it was when it was first
   853    873   ** opened.  Any outstanding pages are invalidated and subsequent attempts
   854    874   ** to access those pages will likely result in a coredump.
   855    875   */
................................................................................
   867    887     pPager->nHash = 0;
   868    888     sqliteFree(pPager->aHash);
   869    889     pPager->nPage = 0;
   870    890     pPager->aHash = 0;
   871    891     if( pPager->state>=PAGER_RESERVED ){
   872    892       sqlite3pager_rollback(pPager);
   873    893     }
   874         -  sqlite3OsUnlock(pPager->fd, NO_LOCK);
   875         -  pPager->state = PAGER_UNLOCK;
   876         -  pPager->dbSize = -1;
          894  +  pager_unlock(pPager);
   877    895     pPager->nRef = 0;
   878         -  assert( pPager->journalOpen==0 );
          896  +  assert( pPager->errCode || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
   879    897   }
   880    898   
   881    899   /*
   882    900   ** When this routine is called, the pager has the journal file open and
   883    901   ** a RESERVED or EXCLUSIVE lock on the database.  This routine releases
   884    902   ** the database lock and acquires a SHARED lock in its place.  The journal
   885    903   ** file is deleted and closed.
................................................................................
   923    941     }
   924    942     rc = sqlite3OsUnlock(pPager->fd, SHARED_LOCK);
   925    943     pPager->state = PAGER_SHARED;
   926    944     pPager->origDbSize = 0;
   927    945     pPager->setMaster = 0;
   928    946     pPager->needSync = 0;
   929    947     pPager->pFirstSynced = pPager->pFirst;
          948  +  pPager->dbSize = -1;
   930    949     return rc;
   931    950   }
   932    951   
   933    952   /*
   934    953   ** Compute and return a checksum for the page of data.
   935    954   **
   936    955   ** This is not a real checksum.  It is really just the sum of the 
................................................................................
  1417   1436     }
  1418   1437     
  1419   1438     /* Truncate the database back to its original size.
  1420   1439     */
  1421   1440     if( pPager->state>=PAGER_EXCLUSIVE ){
  1422   1441       rc = pager_truncate(pPager, pPager->stmtSize);
  1423   1442     }
         1443  +  assert( pPager->state>=PAGER_SHARED );
  1424   1444     pPager->dbSize = pPager->stmtSize;
  1425   1445   
  1426   1446     /* Figure out how many records are in the statement journal.
  1427   1447     */
  1428   1448     assert( pPager->stmtInUse && pPager->journalOpen );
  1429   1449     sqlite3OsSeek(pPager->stfd, 0);
  1430   1450     nRec = pPager->stmtNRec;
................................................................................
  1794   1814   **
  1795   1815   ** No error checking is done. The rational for this is that this function 
  1796   1816   ** may be called even if the file does not exist or contain a header. In 
  1797   1817   ** these cases sqlite3OsRead() will return an error, to which the correct 
  1798   1818   ** response is to zero the memory at pDest and continue.  A real IO error 
  1799   1819   ** will presumably recur and be picked up later (Todo: Think about this).
  1800   1820   */
  1801         -void sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
         1821  +int sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
         1822  +  int rc = SQLITE_OK;
  1802   1823     memset(pDest, 0, N);
  1803   1824     if( MEMDB==0 ){
  1804   1825       disable_simulated_io_errors();
  1805   1826       sqlite3OsSeek(pPager->fd, 0);
  1806         -    sqlite3OsRead(pPager->fd, pDest, N);
  1807   1827       enable_simulated_io_errors();
         1828  +    rc = sqlite3OsRead(pPager->fd, pDest, N);
         1829  +    if( rc==SQLITE_IOERR_SHORT_READ ){
         1830  +      rc = SQLITE_OK;
         1831  +    }
  1808   1832     }
         1833  +  return rc;
  1809   1834   }
  1810   1835   
  1811   1836   /*
  1812   1837   ** Return the total number of pages in the disk file associated with
  1813   1838   ** pPager. 
  1814   1839   **
  1815   1840   ** If the PENDING_BYTE lies on the page directly after the end of the
................................................................................
  1961   1986   ** false or until the lock succeeds.
  1962   1987   **
  1963   1988   ** Return SQLITE_OK on success and an error code if we cannot obtain
  1964   1989   ** the lock.
  1965   1990   */
  1966   1991   static int pager_wait_on_lock(Pager *pPager, int locktype){
  1967   1992     int rc;
         1993  +
         1994  +  /* The OS lock values must be the same as the Pager lock values */
  1968   1995     assert( PAGER_SHARED==SHARED_LOCK );
  1969   1996     assert( PAGER_RESERVED==RESERVED_LOCK );
  1970   1997     assert( PAGER_EXCLUSIVE==EXCLUSIVE_LOCK );
         1998  +
         1999  +  /* If the file is currently unlocked then the size must be unknown */
         2000  +  assert( pPager->state>=PAGER_SHARED || pPager->dbSize<0 || MEMDB );
         2001  +
  1971   2002     if( pPager->state>=locktype ){
  1972   2003       rc = SQLITE_OK;
  1973   2004     }else{
  1974   2005       do {
  1975   2006         rc = sqlite3OsLock(pPager->fd, locktype);
  1976   2007       }while( rc==SQLITE_BUSY && sqlite3InvokeBusyHandler(pPager->pBusyHandler) );
  1977   2008       if( rc==SQLITE_OK ){
................................................................................
  1982   2013   }
  1983   2014   
  1984   2015   /*
  1985   2016   ** Truncate the file to the number of pages specified.
  1986   2017   */
  1987   2018   int sqlite3pager_truncate(Pager *pPager, Pgno nPage){
  1988   2019     int rc;
         2020  +  assert( pPager->state>=PAGER_SHARED || MEMDB );
  1989   2021     sqlite3pager_pagecount(pPager);
  1990   2022     if( pPager->errCode ){
  1991   2023       rc = pPager->errCode;
  1992   2024       return rc;
  1993   2025     }
  1994   2026     if( nPage>=(unsigned)pPager->dbSize ){
  1995   2027       return SQLITE_OK;
................................................................................
  2028   2060   **
  2029   2061   ** This function always succeeds. If a transaction is active an attempt
  2030   2062   ** is made to roll it back. If an error occurs during the rollback 
  2031   2063   ** a hot journal may be left in the filesystem but no error is returned
  2032   2064   ** to the caller.
  2033   2065   */
  2034   2066   int sqlite3pager_close(Pager *pPager){
  2035         -  PgHdr *pPg, *pNext;
  2036   2067   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  2037   2068     /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to 
  2038   2069     ** malloc() must have already been made by this thread before it gets
  2039   2070     ** to this point. This means the ThreadData must have been allocated already
  2040   2071     ** so that ThreadData.nAlloc can be set.
  2041   2072     */
  2042   2073     ThreadData *pTsd = sqlite3ThreadData();
  2043   2074     assert( pPager );
  2044   2075     assert( pTsd && pTsd->nAlloc );
  2045   2076   #endif
  2046   2077   
  2047         -  switch( pPager->state ){
  2048         -    case PAGER_RESERVED:
  2049         -    case PAGER_SYNCED: 
  2050         -    case PAGER_EXCLUSIVE: {
  2051         -      /* We ignore any IO errors that occur during the rollback
  2052         -      ** operation. So disable IO error simulation so that testing
  2053         -      ** works more easily.
  2054         -      */
  2055         -      disable_simulated_io_errors();
  2056         -      sqlite3pager_rollback(pPager);
  2057         -      enable_simulated_io_errors();
  2058         -      if( !MEMDB ){
  2059         -        sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2060         -      }
  2061         -      assert( pPager->errCode || pPager->journalOpen==0 );
  2062         -      break;
  2063         -    }
  2064         -    case PAGER_SHARED: {
  2065         -      if( !MEMDB ){
  2066         -        sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2067         -      }
  2068         -      break;
  2069         -    }
  2070         -    default: {
  2071         -      /* Do nothing */
  2072         -      break;
  2073         -    }
  2074         -  }
  2075         -  for(pPg=pPager->pAll; pPg; pPg=pNext){
  2076         -#ifndef NDEBUG
  2077         -    if( MEMDB ){
  2078         -      PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
  2079         -      assert( !pPg->alwaysRollback );
  2080         -      assert( !pHist->pOrig );
  2081         -      assert( !pHist->pStmt );
  2082         -    }
  2083         -#endif
  2084         -    pNext = pPg->pNextAll;
  2085         -    sqliteFree(pPg);
  2086         -  }
         2078  +  disable_simulated_io_errors();
         2079  +  pPager->errCode = 0;
         2080  +  pager_reset(pPager);
         2081  +  enable_simulated_io_errors();
  2087   2082     TRACE2("CLOSE %d\n", PAGERID(pPager));
  2088   2083     assert( pPager->errCode || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
  2089   2084     if( pPager->journalOpen ){
  2090   2085       sqlite3OsClose(&pPager->jfd);
  2091   2086     }
  2092   2087     sqliteFree(pPager->aInJournal);
  2093   2088     if( pPager->stmtOpen ){
................................................................................
  2661   2656          ** 
  2662   2657          ** Because the intermediate RESERVED lock is not requested, the
  2663   2658          ** second process will get to this point in the code and fail to
  2664   2659          ** obtain it's own EXCLUSIVE lock on the database file.
  2665   2660          */
  2666   2661          rc = sqlite3OsLock(pPager->fd, EXCLUSIVE_LOCK);
  2667   2662          if( rc!=SQLITE_OK ){
  2668         -         sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2669         -         pPager->state = PAGER_UNLOCK;
         2663  +         pager_unlock(pPager);
  2670   2664            return pager_error(pPager, rc);
  2671   2665          }
  2672   2666          pPager->state = PAGER_EXCLUSIVE;
  2673   2667   
  2674   2668          /* Open the journal for reading only.  Return SQLITE_BUSY if
  2675   2669          ** we are unable to open the journal file. 
  2676   2670          **
................................................................................
  2677   2671          ** The journal file does not need to be locked itself.  The
  2678   2672          ** journal file is never open unless the main database file holds
  2679   2673          ** a write lock, so there is never any chance of two or more
  2680   2674          ** processes opening the journal at the same time.
  2681   2675          */
  2682   2676          rc = sqlite3OsOpenReadOnly(pPager->zJournal, &pPager->jfd);
  2683   2677          if( rc!=SQLITE_OK ){
  2684         -         sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2685         -         pPager->state = PAGER_UNLOCK;
         2678  +         pager_unlock(pPager);
  2686   2679            return SQLITE_BUSY;
  2687   2680          }
  2688   2681          pPager->journalOpen = 1;
  2689   2682          pPager->journalStarted = 0;
  2690   2683          pPager->journalOff = 0;
  2691   2684          pPager->setMaster = 0;
  2692   2685          pPager->journalHdr = 0;
................................................................................
  2785   2778         rc = sqlite3OsSeek(pPager->fd, (pgno-1)*(i64)pPager->pageSize);
  2786   2779         if( rc==SQLITE_OK ){
  2787   2780           rc = sqlite3OsRead(pPager->fd, PGHDR_TO_DATA(pPg),
  2788   2781                                 pPager->pageSize);
  2789   2782         }
  2790   2783         TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
  2791   2784         CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
  2792         -      if( rc!=SQLITE_OK ){
  2793         -        i64 fileSize;
  2794         -        int rc2 = sqlite3OsFileSize(pPager->fd, &fileSize);
  2795         -        if( rc2!=SQLITE_OK || fileSize>=pgno*pPager->pageSize ){
  2796         -	  /* An IO error occured in one of the the sqlite3OsSeek() or
  2797         -          ** sqlite3OsRead() calls above. */
  2798         -          pPg->pgno = 0;
  2799         -          sqlite3pager_unref(PGHDR_TO_DATA(pPg));
  2800         -          return rc;
  2801         -        }else{
  2802         -          clear_simulated_io_error();
  2803         -          memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
  2804         -        }
         2785  +      if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
         2786  +        pPg->pgno = 0;
         2787  +        sqlite3pager_unref(PGHDR_TO_DATA(pPg));
         2788  +        return rc;
  2805   2789         }else{
  2806   2790           TEST_INCR(pPager->nRead);
  2807   2791         }
  2808   2792       }
  2809   2793   
  2810   2794       /* Link the page into the page hash table */
  2811   2795       h = pgno & (pPager->nHash-1);
................................................................................
  2969   2953       /* If this was a malloc() failure, then we will not be closing the pager
  2970   2954       ** file. So delete any journal file we may have just created. Otherwise,
  2971   2955       ** the system will get confused, we have a read-lock on the file and a
  2972   2956       ** mysterious journal has appeared in the filesystem.
  2973   2957       */
  2974   2958       sqlite3OsDelete(pPager->zJournal);
  2975   2959     }else{
  2976         -    sqlite3OsUnlock(pPager->fd, NO_LOCK);
  2977         -    pPager->state = PAGER_UNLOCK;
         2960  +    pager_reset(pPager);
  2978   2961     }
  2979   2962     return rc;
  2980   2963   }
  2981   2964   
  2982   2965   /*
  2983   2966   ** Acquire a write-lock on the database.  The lock is removed when
  2984   2967   ** the any of the following happen:
................................................................................
  3229   3212         }
  3230   3213         page_add_to_stmt_list(pPg);
  3231   3214       }
  3232   3215     }
  3233   3216   
  3234   3217     /* Update the database size and return.
  3235   3218     */
         3219  +  assert( pPager->state>=PAGER_SHARED );
  3236   3220     if( pPager->dbSize<(int)pPg->pgno ){
  3237   3221       pPager->dbSize = pPg->pgno;
  3238   3222       if( !MEMDB && pPager->dbSize==PENDING_BYTE/pPager->pageSize ){
  3239   3223         pPager->dbSize++;
  3240   3224       }
  3241   3225     }
  3242   3226     return rc;
................................................................................
  3304   3288   
  3305   3289     if( MEMDB ) return;
  3306   3290   
  3307   3291     pPg = pager_lookup(pPager, pgno);
  3308   3292     assert( pPg!=0 );  /* We never call _dont_write unless the page is in mem */
  3309   3293     pPg->alwaysRollback = 1;
  3310   3294     if( pPg->dirty && !pPager->stmtInUse ){
         3295  +    assert( pPager->state>=PAGER_SHARED );
  3311   3296       if( pPager->dbSize==(int)pPg->pgno && pPager->origDbSize<pPager->dbSize ){
  3312   3297         /* If this pages is the last page in the file and the file has grown
  3313   3298         ** during the current transaction, then do NOT mark the page as clean.
  3314   3299         ** When the database file grows, we must make sure that the last page
  3315   3300         ** gets written at least once so that the disk file will be the correct
  3316   3301         ** size. If you do not write this page and the size of the file
  3317   3302         ** on the disk ends up being too small, that can lead to database
................................................................................
  3333   3318   ** means that the pager does not have to record the given page in the
  3334   3319   ** rollback journal.
  3335   3320   */
  3336   3321   void sqlite3pager_dont_rollback(void *pData){
  3337   3322     PgHdr *pPg = DATA_TO_PGHDR(pData);
  3338   3323     Pager *pPager = pPg->pPager;
  3339   3324   
  3340         -  if( pPager->state!=PAGER_EXCLUSIVE || pPager->journalOpen==0 ) return;
         3325  +  assert( pPager->state>=PAGER_RESERVED );
         3326  +  if( pPager->journalOpen==0 ) return;
  3341   3327     if( pPg->alwaysRollback || pPager->alwaysRollback || MEMDB ) return;
  3342   3328     if( !pPg->inJournal && (int)pPg->pgno <= pPager->origDbSize ){
  3343   3329       assert( pPager->aInJournal!=0 );
  3344   3330       pPager->aInJournal[pPg->pgno/8] |= 1<<(pPg->pgno&7);
  3345   3331       pPg->inJournal = 1;
  3346   3332       if( pPager->stmtInUse ){
  3347   3333         pPager->aInStmt[pPg->pgno/8] |= 1<<(pPg->pgno&7);
................................................................................
  3401   3387       return SQLITE_OK;
  3402   3388     }
  3403   3389     if( pPager->dirtyCache==0 ){
  3404   3390       /* Exit early (without doing the time-consuming sqlite3OsSync() calls)
  3405   3391       ** if there have been no changes to the database file. */
  3406   3392       assert( pPager->needSync==0 );
  3407   3393       rc = pager_unwritelock(pPager);
  3408         -    pPager->dbSize = -1;
  3409   3394       return rc;
  3410   3395     }
  3411   3396     assert( pPager->journalOpen );
  3412   3397     rc = sqlite3pager_sync(pPager, 0, 0);
  3413   3398     if( rc==SQLITE_OK ){
  3414   3399       rc = pager_unwritelock(pPager);
  3415         -    pPager->dbSize = -1;
  3416   3400     }
  3417   3401     return rc;
  3418   3402   }
  3419   3403   
  3420   3404   /*
  3421   3405   ** Rollback all changes.  The database falls back to PAGER_SHARED mode.
  3422   3406   ** All in-memory cache pages revert to their original data contents.
................................................................................
  3466   3450       pPager->stmtInUse = 0;
  3467   3451       pPager->state = PAGER_SHARED;
  3468   3452       return SQLITE_OK;
  3469   3453     }
  3470   3454   
  3471   3455     if( !pPager->dirtyCache || !pPager->journalOpen ){
  3472   3456       rc = pager_unwritelock(pPager);
  3473         -    pPager->dbSize = -1;
  3474   3457       return rc;
  3475   3458     }
  3476   3459   
  3477   3460     if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
  3478   3461       if( pPager->state>=PAGER_EXCLUSIVE ){
  3479   3462         pager_playback(pPager);
  3480   3463       }
................................................................................
  3542   3525   ** open.  A new statement journal is created that can be used to rollback
  3543   3526   ** changes of a single SQL command within a larger transaction.
  3544   3527   */
  3545   3528   int sqlite3pager_stmt_begin(Pager *pPager){
  3546   3529     int rc;
  3547   3530     char zTemp[SQLITE_TEMPNAME_SIZE];
  3548   3531     assert( !pPager->stmtInUse );
         3532  +  assert( pPager->state>=PAGER_SHARED );
  3549   3533     assert( pPager->dbSize>=0 );
  3550   3534     TRACE2("STMT-BEGIN %d\n", PAGERID(pPager));
  3551   3535     if( MEMDB ){
  3552   3536       pPager->stmtInUse = 1;
  3553   3537       pPager->stmtSize = pPager->dbSize;
  3554   3538       return SQLITE_OK;
  3555   3539     }

Changes to SQLite.Interop/src/pager.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite page cache
    13     13   ** subsystem.  The page cache subsystem reads and writes a file a page
    14     14   ** at a time and provides a journal for rollback.
    15     15   **
    16         -** @(#) $Id: pager.h,v 1.24 2006/10/12 21:34:21 rmsimpson Exp $
           16  +** @(#) $Id: pager.h,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    17     17   */
    18     18   
    19     19   #ifndef _PAGER_H_
    20     20   #define _PAGER_H_
    21     21   
    22     22   /*
    23     23   ** The default size of a database page.
................................................................................
    71     71   */
    72     72   int sqlite3pager_open(Pager **ppPager, const char *zFilename,
    73     73                        int nExtra, int flags);
    74     74   void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
    75     75   void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
    76     76   void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
    77     77   int sqlite3pager_set_pagesize(Pager*, int);
    78         -void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
           78  +int sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
    79     79   void sqlite3pager_set_cachesize(Pager*, int);
    80     80   int sqlite3pager_close(Pager *pPager);
    81     81   int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage);
    82     82   void *sqlite3pager_lookup(Pager *pPager, Pgno pgno);
    83     83   int sqlite3pager_ref(void*);
    84     84   int sqlite3pager_unref(void*);
    85     85   Pgno sqlite3pager_pagenumber(void*);

Changes to SQLite.Interop/src/parse.c.

   172    172   **  yy_shift_ofst[]    For each state, the offset into yy_action for
   173    173   **                     shifting terminals.
   174    174   **  yy_reduce_ofst[]   For each state, the offset into yy_action for
   175    175   **                     shifting non-terminals after a reduce.
   176    176   **  yy_default[]       Default action for each state.
   177    177   */
   178    178   static const YYACTIONTYPE yy_action[] = {
   179         - /*     0 */   290,   67,  294,   69,  150,  168,  206,  435,   61,   61,
          179  + /*     0 */   290,   67,  300,   69,  150,  168,  205,  420,   61,   61,
   180    180    /*    10 */    61,   61,   66,   63,   63,   63,   63,   64,   64,   65,
   181         - /*    20 */    65,   65,   66,  445,  325,  164,  448,  454,   68,   63,
          181  + /*    20 */    65,   65,   66,  430,  322,  164,  433,  439,   68,   63,
   182    182    /*    30 */    63,   63,   63,   64,   64,   65,   65,   65,   66,   64,
   183         - /*    40 */    64,   65,   65,   65,   66,   60,   58,  298,  458,  459,
   184         - /*    50 */   455,  455,   62,   62,   61,   61,   61,   61,  517,   63,
          183  + /*    40 */    64,   65,   65,   65,   66,   60,   58,  296,  443,  444,
          184  + /*    50 */   440,  440,   62,   62,   61,   61,   61,   61,  487,   63,
   185    185    /*    60 */    63,   63,   63,   64,   64,   65,   65,   65,   66,  290,
   186         - /*    70 */   321,   67,  435,   69,  150,   79,  160,  114,  224,  317,
   187         - /*    80 */   229,  318,  172,  249,  897,  120,  585,  519,  522,    2,
   188         - /*    90 */   250,  571,  426,   35,  223,  448,  454,  532,   20,   57,
          186  + /*    70 */   318,   67,  420,   69,  150,   79,  160,  114,  240,  341,
          187  + /*    80 */   245,  342,  172,  249,  897,  120,  585,  190,  522,    2,
          188  + /*    90 */   250,  571,  411,   35,  223,  433,  439,  532,   20,   57,
   189    189    /*   100 */   388,  385,   63,   63,   63,   63,   64,   64,   65,   65,
   190         - /*   110 */    65,   66,  290,  477,   60,   58,  298,  458,  459,  455,
   191         - /*   120 */   455,   62,   62,   61,   61,   61,   61,  393,   63,   63,
   192         - /*   130 */    63,   63,   64,   64,   65,   65,   65,   66,  448,  454,
   193         - /*   140 */    91,  314,  389,  484,  236,  387,  271,  204,    2,   83,
   194         - /*   150 */   586,  388,  385,  474,  196,  443,  209,   60,   58,  298,
   195         - /*   160 */   458,  459,  455,  455,   62,   62,   61,   61,   61,   61,
          190  + /*   110 */    65,   66,  290,  489,   60,   58,  296,  443,  444,  440,
          191  + /*   120 */   440,   62,   62,   61,   61,   61,   61,  393,   63,   63,
          192  + /*   130 */    63,   63,   64,   64,   65,   65,   65,   66,  433,  439,
          193  + /*   140 */    91,  314,  389,  473,  230,  529,  504,  204,  168,   55,
          194  + /*   150 */   420,  197,  528,  407,  196,  428,  208,   60,   58,  296,
          195  + /*   160 */   443,  444,  440,  440,   62,   62,   61,   61,   61,   61,
   196    196    /*   170 */   170,   63,   63,   63,   63,   64,   64,   65,   65,   65,
   197         - /*   180 */    66,  290,  490,  443,  209,  274,  109,  272,  427,  447,
   198         - /*   190 */   406,  284,  394,  395,  445,  521,  164,  321,  511,   67,
   199         - /*   200 */   530,   69,  150,  567,  427,  143,  520,  448,  454,  145,
   200         - /*   210 */   146,  583,  888,  376,  888,  515,  171,  156,  518,  426,
   201         - /*   220 */    40,  340,  430,   19,  290,  140,   60,   58,  298,  458,
   202         - /*   230 */   459,  455,  455,   62,   62,   61,   61,   61,   61,  384,
          197  + /*   180 */    66,  290,  479,  428,  208,  412,  109,   81,  412,  432,
          198  + /*   190 */   406,  284,  394,  395,  430,  521,  164,  318,  517,   67,
          199  + /*   200 */   530,   69,  150,  567,  412,  492,  493,  433,  439,  145,
          200  + /*   210 */   146,  583,  888,  376,  888,  420,  171,  156,  488,  411,
          201  + /*   220 */    40,  337,  415,   19,  290,  140,   60,   58,  296,  443,
          202  + /*   230 */   444,  440,  440,   62,   62,   61,   61,   61,   61,  384,
   203    203    /*   240 */    63,   63,   63,   63,   64,   64,   65,   65,   65,   66,
   204         - /*   250 */   448,  454,  580,  408,  409,  432,  432,  432,  332,  335,
   205         - /*   260 */   240,  549,   67,  472,   69,  150,  273,  290,  294,   60,
   206         - /*   270 */    58,  298,  458,  459,  455,  455,   62,   62,   61,   61,
   207         - /*   280 */    61,   61,  124,   63,   63,   63,   63,   64,   64,   65,
   208         - /*   290 */    65,   65,   66,  448,  454,  405,  514,  393,  293,  548,
   209         - /*   300 */    65,   65,   65,   66,  511,  393,  546,  409,  447,  297,
   210         - /*   310 */   438,  439,   60,   58,  298,  458,  459,  455,  455,   62,
   211         - /*   320 */    62,   61,   61,   61,   61,  206,   63,   63,   63,   63,
   212         - /*   330 */    64,   64,   65,   65,   65,   66,  523,  518,  369,  290,
   213         - /*   340 */    75,  430,  148,  494,  224,  317,  229,  318,  172,  249,
   214         - /*   350 */   370,  267,  266,    1,  579,  289,  250,  393,  420,  449,
   215         - /*   360 */   450,  206,  394,  395,  177,  448,  454,  343,  346,  347,
   216         - /*   370 */   394,  395,  208,  360,  432,  432,  432,  363,  168,  348,
   217         - /*   380 */   435,  452,  453,   78,   60,   58,  298,  458,  459,  455,
   218         - /*   390 */   455,   62,   62,   61,   61,   61,   61,  480,   63,   63,
   219         - /*   400 */    63,   63,   64,   64,   65,   65,   65,   66,  290,  451,
   220         - /*   410 */   177,  566,  497,  343,  346,  347,   21,  321,  522,  321,
   221         - /*   420 */   435,  321,  394,  395,  321,  348,  479,  404,   20,  568,
   222         - /*   430 */   569,  493,  151,  177,  448,  454,  343,  346,  347,  426,
   223         - /*   440 */    34,  426,   34,  426,   34,  435,  426,   34,  348,  197,
   224         - /*   450 */   237,  147,  531,   60,   58,  298,  458,  459,  455,  455,
   225         - /*   460 */    62,   62,   61,   61,   61,   61,  427,   63,   63,   63,
   226         - /*   470 */    63,   64,   64,   65,   65,   65,   66,  290,  230,  351,
   227         - /*   480 */   412,  516,  301,  427,  337,  435,  321,  155,  321,  299,
   228         - /*   490 */   321,  208,  413,  154,  469,    9,  469,  462,  468,  393,
   229         - /*   500 */    74,  469,   76,  448,  454,  414,  173,  410,  426,   40,
   230         - /*   510 */   426,   48,  426,   48,  324,  438,  439,  411,  327,  479,
   231         - /*   520 */   461,  461,   60,   58,  298,  458,  459,  455,  455,   62,
   232         - /*   530 */    62,   61,   61,   61,   61,  463,   63,   63,   63,   63,
   233         - /*   540 */    64,   64,   65,   65,   65,   66,  290,  321,  503,  238,
   234         - /*   550 */   253,  484,  393,  341,  412,  149,  425,  309,  338,  310,
   235         - /*   560 */   424,  393,  292,  393,  394,  395,  413,  250,  504,  426,
   236         - /*   570 */    27,  241,  448,  454,  435,  426,    3,  208,  543,  414,
   237         - /*   580 */   322,  331,  583,  887,  327,  887,  461,  461,  488,  427,
   238         - /*   590 */   242,   60,   58,  298,  458,  459,  455,  455,   62,   62,
   239         - /*   600 */    61,   61,   61,   61,  255,   63,   63,   63,   63,   64,
   240         - /*   610 */    64,   65,   65,   65,   66,  290,  371,  394,  395,  492,
   241         - /*   620 */    90,  302,  327,  580,  461,  461,  394,  395,  394,  395,
   242         - /*   630 */   321,  529,  498,  321,  396,  397,  398,  522,  528,  435,
   243         - /*   640 */   219,  448,  454,  259,  481,  257,  576,   20,  327,  300,
   244         - /*   650 */   461,  461,  426,   28,  545,  426,   23,  509,  290,  342,
   245         - /*   660 */    60,   58,  298,  458,  459,  455,  455,   62,   62,   61,
   246         - /*   670 */    61,   61,   61,  321,   63,   63,   63,   63,   64,   64,
   247         - /*   680 */    65,   65,   65,   66,  448,  454,  425,  539,  357,  539,
   248         - /*   690 */   424,  261,  303,  509,  822,  426,   32,  436,  509,   22,
   249         - /*   700 */   188,  290,  509,   60,   58,  298,  458,  459,  455,  455,
   250         - /*   710 */    62,   62,   61,   61,   61,   61,  321,   63,   63,   63,
   251         - /*   720 */    63,   64,   64,   65,   65,   65,   66,  448,  454,  174,
   252         - /*   730 */   175,  176,  381,  216,  427,  484,  248,  304,  426,   53,
   253         - /*   740 */   509,  509,  261,  261,  290,  261,   60,   70,  298,  458,
   254         - /*   750 */   459,  455,  455,   62,   62,   61,   61,   61,   61,  368,
          204  + /*   250 */   433,  439,  580,  546,  493,  417,  417,  417,  549,  332,
          205  + /*   260 */   234,   67,  460,   69,  150,  583,  887,  290,  887,   60,
          206  + /*   270 */    58,  296,  443,  444,  440,  440,   62,   62,   61,   61,
          207  + /*   280 */    61,   61,  318,   63,   63,   63,   63,   64,   64,   65,
          208  + /*   290 */    65,   65,   66,  433,  439,  177,  548,  393,  343,  346,
          209  + /*   300 */   347,  515,  490,  271,  411,   40,  580,  473,  432,  224,
          210  + /*   310 */   348,  408,   60,   58,  296,  443,  444,  440,  440,   62,
          211  + /*   320 */    62,   61,   61,   61,   61,  523,   63,   63,   63,   63,
          212  + /*   330 */    64,   64,   65,   65,   65,   66,  303,  488,  300,  290,
          213  + /*   340 */    75,  415,  274,  483,  272,  232,  236,  370,  267,  266,
          214  + /*   350 */   318,   65,   65,   65,   66,  173,  393,  148,  205,  434,
          215  + /*   360 */   435,  231,  394,  395,  177,  433,  439,  343,  346,  347,
          216  + /*   370 */   293,  515,  411,   34,  417,  417,  417,  378,  477,  348,
          217  + /*   380 */   248,  437,  438,   78,   60,   58,  296,  443,  444,  440,
          218  + /*   390 */   440,   62,   62,   61,   61,   61,   61,  205,   63,   63,
          219  + /*   400 */    63,   63,   64,   64,   65,   65,   65,   66,  290,  436,
          220  + /*   410 */   377,  292,  486,  114,  240,  341,  245,  342,  172,  249,
          221  + /*   420 */   318,  394,  395,  273,  318,  177,  250,  456,  343,  346,
          222  + /*   430 */   347,  329,  151,  566,  433,  439,  295,  423,  424,  298,
          223  + /*   440 */   348,  387,  411,   34,    2,  360,  411,   34,  469,  363,
          224  + /*   450 */   247,  568,  569,   60,   58,  296,  443,  444,  440,  440,
          225  + /*   460 */    62,   62,   61,   61,   61,   61,  412,   63,   63,   63,
          226  + /*   470 */    63,   64,   64,   65,   65,   65,   66,  290,  522,  155,
          227  + /*   480 */   515,  503,   21,  452,  318,  299,  420,  404,   20,  297,
          228  + /*   490 */   321,  423,  424,  482,  318,  453,  318,  457,    1,  207,
          229  + /*   500 */   335,  457,  393,  433,  439,    9,  411,   34,  454,  393,
          230  + /*   510 */   494,  147,  531,  207,  543,  216,  411,   48,  411,   48,
          231  + /*   520 */   495,  393,   60,   58,  296,  443,  444,  440,  440,   62,
          232  + /*   530 */    62,   61,   61,   61,   61,  351,   63,   63,   63,   63,
          233  + /*   540 */    64,   64,   65,   65,   65,   66,  290,  318,  447,  334,
          234  + /*   550 */   253,  420,  371,  207,  452,  149,  448,  579,  289,  248,
          235  + /*   560 */   393,  457,  173,  309,  235,  310,  453,  394,  395,  411,
          236  + /*   570 */    27,  420,  433,  439,  394,  395,  405,  520,  367,  454,
          237  + /*   580 */   324,  328,  446,  446,  509,  517,  394,  395,  473,  412,
          238  + /*   590 */   545,   60,   58,  296,  443,  444,  440,  440,   62,   62,
          239  + /*   600 */    61,   61,   61,   61,  510,   63,   63,   63,   63,   64,
          240  + /*   610 */    64,   65,   65,   65,   66,  290,  192,  338,  292,  324,
          241  + /*   620 */    90,  446,  446,  250,  522,  394,  395,  238,  319,  393,
          242  + /*   630 */   822,  477,  318,  576,   20,  324,  420,  446,  446,  411,
          243  + /*   640 */     3,  433,  439,  324,  217,  446,  446,  586,  388,  385,
          244  + /*   650 */   412,  515,  470,  515,  411,   28,  515,  302,  290,  581,
          245  + /*   660 */    60,   58,  296,  443,  444,  440,  440,   62,   62,   61,
          246  + /*   670 */    61,   61,   61,  219,   63,   63,   63,   63,   64,   64,
          247  + /*   680 */    65,   65,   65,   66,  433,  439,  304,  481,  305,  167,
          248  + /*   690 */   156,  307,  358,  392,  394,  395,  396,  397,  398,  582,
          249  + /*   700 */   188,  290,  339,   60,   58,  296,  443,  444,  440,  440,
          250  + /*   710 */    62,   62,   61,   61,   61,   61,  318,   63,   63,   63,
          251  + /*   720 */    63,   64,   64,   65,   65,   65,   66,  433,  439,  410,
          252  + /*   730 */   248,  261,  248,  409,  412,  248,  367,  255,  411,   23,
          253  + /*   740 */   539,  357,  539,  261,  290,  261,   60,   70,  296,  443,
          254  + /*   750 */   444,  440,  440,   62,   62,   61,   61,   61,   61,  368,
   255    255    /*   760 */    63,   63,   63,   63,   64,   64,   65,   65,   65,   66,
   256         - /*   770 */   448,  454,  247,  392,  244,  305,  307,  248,  167,  156,
   257         - /*   780 */   364,  248,  383,  262,  556,  261,  558,  290,  261,  115,
   258         - /*   790 */    58,  298,  458,  459,  455,  455,   62,   62,   61,   61,
   259         - /*   800 */    61,   61,  321,   63,   63,   63,   63,   64,   64,   65,
   260         - /*   810 */    65,   65,   66,  448,  454,  488,  467,  488,   12,  248,
   261         - /*   820 */   248,  207,    5,  367,  426,   24,  559,  367,   54,  560,
   262         - /*   830 */   312,  119,  441,  441,  298,  458,  459,  455,  455,   62,
   263         - /*   840 */    62,   61,   61,   61,   61,  321,   63,   63,   63,   63,
   264         - /*   850 */    64,   64,   65,   65,   65,   66,   71,  328,  321,    4,
   265         - /*   860 */   321,  541,  321,  296,  261,  540,  261,  426,   51,  321,
   266         - /*   870 */   161,  323,   71,  328,  321,    4,  358,  359,  308,  296,
   267         - /*   880 */   426,   96,  426,   93,  426,   98,  225,  323,  330,  217,
   268         - /*   890 */   431,  426,   99,  218,  444,  321,  426,  110,  226,  447,
   269         - /*   900 */   321,  261,  321,  421,  330,  275,  190,  375,  321,  333,
   270         - /*   910 */   422,  321,  417,  418,  470,  447,  321,  426,  111,   73,
   271         - /*   920 */    72,  192,  426,   16,  426,   97,  152,   71,  319,  320,
   272         - /*   930 */   426,   33,  430,  426,   94,   73,   72,  491,  426,   52,
   273         - /*   940 */   321,  478,  277,   71,  319,  320,   71,  328,  430,    4,
   274         - /*   950 */   321,  206,  321,  296,  321,  427,  486,  321,  169,  179,
   275         - /*   960 */   427,  323,  426,  112,  620,  432,  432,  432,  433,  434,
   276         - /*   970 */    11,  378,  426,  113,  426,   25,  426,   36,  330,  426,
   277         - /*   980 */    37,  432,  432,  432,  433,  434,   11,  483,  326,  447,
   278         - /*   990 */   158,  206,  321,  427,  173,  220,  221,  222,  101,  182,
   279         - /*  1000 */   495,  321,   12,  321,  377,  321,   81,  321,  487,   73,
   280         - /*  1010 */    72,  202,  581,  279,  426,   26,  246,   71,  319,  320,
   281         - /*  1020 */   280,  321,  430,  426,   38,  426,   39,  426,   41,  426,
   282         - /*  1030 */    42,  321,  199,  427,  548,  502,  501,  537,  538,  198,
   283         - /*  1040 */   321,  499,  201,  426,   43,  321,  500,  507,  321,  124,
   284         - /*  1050 */   292,  321,  582,  426,   29,  432,  432,  432,  433,  434,
   285         - /*  1060 */    11,  505,  426,   30,  456,  506,  321,  426,   44,  200,
   286         - /*  1070 */   426,   45,  321,  426,   46,  252,  321,  124,  350,  321,
   287         - /*  1080 */   124,  321,  524,  254,  185,  374,  276,  266,  426,   47,
   288         - /*  1090 */   578,  291,  288,  256,  426,   31,  206,  258,  426,   10,
   289         - /*  1100 */   260,  426,   49,  426,   50,  355,  544,  552,  124,  169,
   290         - /*  1110 */   553,  265,   88,  362,  365,  563,  366,   88,  268,   18,
   291         - /*  1120 */   380,  269,  270,  555,  565,  278,  379,  281,  227,  282,
   292         - /*  1130 */   575,  142,  231,  402,  329,  440,  442,  473,  498,  159,
   293         - /*  1140 */   476,  551,  508,  562,  510,  391,  399,  400,  401,    8,
   294         - /*  1150 */   315,  316,  295,   81,  420,  336,  232,   80,  345,  407,
   295         - /*  1160 */   415,  334,  228,   56,   77,  419,  423,  166,  471,  416,
   296         - /*  1170 */   210,  239,  474,  475,  211,  121,   82,  339,  102,  512,
   297         - /*  1180 */   352,  180,  285,  428,  356,  533,  525,  181,  526,  527,
   298         - /*  1190 */   263,  354,  233,  513,  234,  286,  184,  183,   85,  535,
   299         - /*  1200 */   235,  186,  429,  117,  361,  128,  547,  373,  189,  572,
   300         - /*  1210 */   243,  577,  485,  245,  129,  489,  212,  372,  130,  311,
   301         - /*  1220 */   554,  573,  214,  215,  574,   95,  134,  131,  132,  561,
   302         - /*  1230 */   390,  403,  116,  213,  205,  100,   55,  621,  622,  162,
   303         - /*  1240 */   138,  163,   59,  457,  137,  437,  446,  460,  464,  139,
   304         - /*  1250 */   153,  482,  465,    6,  536,  165,  466,   13,    7,  122,
   305         - /*  1260 */    12,  123,  496,  157,  344,  103,  349,  251,  104,   84,
   306         - /*  1270 */   105,  178,  226,  353,  141,  534,  125,  169,  264,  306,
   307         - /*  1280 */   187,  106,  287,  550,   89,   92,  127,   86,   87,  126,
   308         - /*  1290 */   542,   17,  191,  108,   14,  194,  193,  557,  135,  133,
   309         - /*  1300 */   195,  136,   15,  564,  570,  118,  107,  203,  144,  313,
   310         - /*  1310 */   382,  283,  386,  559,  584,
          256  + /*   770 */   433,  439,  381,  541,  115,  261,  259,  540,  257,  261,
          257  + /*   780 */   364,  174,  175,  176,  262,  261,  556,  290,    5,  359,
          258  + /*   790 */    58,  296,  443,  444,  440,  440,   62,   62,   61,   61,
          259  + /*   800 */    61,   61,  218,   63,   63,   63,   63,   64,   64,   65,
          260  + /*   810 */    65,   65,   66,  433,  439,  477,  558,  205,  466,  468,
          261  + /*   820 */   559,  206,  383,  261,  261,  261,  560,  152,   54,  467,
          262  + /*   830 */   369,  312,  119,  124,  296,  443,  444,  440,  440,   62,
          263  + /*   840 */    62,   61,   61,   61,   61,  416,   63,   63,   63,   63,
          264  + /*   850 */    64,   64,   65,   65,   65,   66,   71,  325,  318,    4,
          265  + /*   860 */   318,  412,  318,  294,  275,  375,  277,  318,   74,  318,
          266  + /*   870 */    76,  320,   71,  325,  318,    4,  308,  498,  499,  294,
          267  + /*   880 */   411,   32,  411,   53,  411,   24,  154,  320,  327,  411,
          268  + /*   890 */    51,  411,   96,  161,  410,  318,  411,   93,  409,  432,
          269  + /*   900 */   318,  421,  318,   22,  327,  426,  426,  179,  318,  501,
          270  + /*   910 */   143,  318,  468,  508,  507,  432,  318,  411,   98,   73,
          271  + /*   920 */    72,  182,  411,   99,  411,  110,  323,   71,  316,  317,
          272  + /*   930 */   411,  111,  415,  411,   16,   73,   72,  480,  411,   97,
          273  + /*   940 */   318,  412,  330,   71,  316,  317,   71,  325,  415,    4,
          274  + /*   950 */   318,  205,  318,  294,  318,  412,  455,  318,   12,  537,
          275  + /*   960 */   538,  320,  411,   33,  462,  417,  417,  417,  418,  419,
          276  + /*   970 */    11,  463,  411,   94,  411,   52,  411,  112,  327,  411,
          277  + /*   980 */   113,  417,  417,  417,  418,  419,   11,  620,  241,  432,
          278  + /*   990 */   158,  475,  318,  169,  429,  220,  221,  222,  101,  458,
          279  + /*  1000 */   242,  318,  441,  318,  484,  318,   12,  318,  472,   73,
          280  + /*  1010 */    72,  202,  476,  279,  411,   25,  246,   71,  316,  317,
          281  + /*  1020 */   280,  318,  415,  411,   36,  411,   37,  411,   26,  411,
          282  + /*  1030 */    38,  318,  199,  505,  548,  513,  252,  124,  124,  198,
          283  + /*  1040 */   318,  506,  201,  411,   39,  318,  511,  350,  318,  124,
          284  + /*  1050 */   544,  318,  124,  411,   41,  417,  417,  417,  418,  419,
          285  + /*  1060 */    11,  512,  411,   42,  524,  254,  318,  411,   43,  200,
          286  + /*  1070 */   411,   29,  318,  411,   30,  552,  318,  169,  553,  318,
          287  + /*  1080 */    88,  318,  256,  318,  185,  374,  276,  266,  411,   44,
          288  + /*  1090 */   258,  291,  318,  260,  411,   45,  205,  265,  411,   46,
          289  + /*  1100 */   318,  411,   47,  411,   31,  411,   10,  563,  578,   88,
          290  + /*  1110 */   288,  355,  362,  365,  411,   49,  366,  268,  269,   18,
          291  + /*  1120 */   380,  270,  411,   50,  555,  565,  278,  379,  281,  282,
          292  + /*  1130 */   575,  142,  225,  402,  425,  427,  326,  504,  551,  461,
          293  + /*  1140 */   465,  562,  159,  391,  399,  243,  400,  514,  516,  401,
          294  + /*  1150 */     8,  413,  226,  315,   81,  333,  227,   80,  331,  228,
          295  + /*  1160 */   345,  229,   77,   56,  209,  166,  459,  233,  210,  407,
          296  + /*  1170 */   464,  121,   82,  336,  340,  491,  496,  301,  244,  501,
          297  + /*  1180 */   497,  500,  502,  102,  518,  519,  414,  285,  352,  525,
          298  + /*  1190 */   180,  526,  527,  533,  237,  181,  474,  239,  354,  478,
          299  + /*  1200 */   211,  286,  184,  214,  535,  183,  215,  356,   85,  361,
          300  + /*  1210 */   117,  186,  128,  547,  189,  372,  554,  373,  311,  561,
          301  + /*  1220 */   572,  129,  130,  131,  138,  573,   95,  132,  577,  263,
          302  + /*  1230 */   137,  134,  574,  390,  403,  621,  536,  213,  622,  100,
          303  + /*  1240 */   162,   59,  163,  422,  431,  442,  445,  139,   89,  449,
          304  + /*  1250 */   153,  165,    6,  450,  451,  122,  471,   13,    7,   92,
          305  + /*  1260 */   123,   12,  485,  157,  212,  108,   83,  103,  104,  116,
          306  + /*  1270 */   344,  251,   84,  105,  349,   17,  178,  353,  242,  534,
          307  + /*  1280 */   141,  125,  306,  187,  106,  169,  126,  287,  542,  264,
          308  + /*  1290 */   118,  550,  127,  191,  313,   14,   86,  193,  194,  135,
          309  + /*  1300 */   557,  195,  133,  564,  136,   15,  107,  570,  382,  283,
          310  + /*  1310 */   144,  203,  386,   87,  584,
   311    311   };
   312    312   static const YYCODETYPE yy_lookahead[] = {
   313    313    /*     0 */    16,  218,   16,  220,  221,   21,  111,   23,   70,   71,
   314    314    /*    10 */    72,   73,   84,   75,   76,   77,   78,   79,   80,   81,
   315    315    /*    20 */    82,   83,   84,  162,  163,  164,   42,   43,   74,   75,
   316    316    /*    30 */    76,   77,   78,   79,   80,   81,   82,   83,   84,   79,
   317    317    /*    40 */    80,   81,   82,   83,   84,   61,   62,   63,   64,   65,
   318    318    /*    50 */    66,   67,   68,   69,   70,   71,   72,   73,  170,   75,
   319    319    /*    60 */    76,   77,   78,   79,   80,   81,   82,   83,   84,   16,
   320    320    /*    70 */   148,  218,   88,  220,  221,   22,   90,   91,   92,   93,
   321         - /*    80 */    94,   95,   96,   97,  140,  141,  142,  170,  148,  145,
          321  + /*    80 */    94,   95,   96,   97,  140,  141,  142,   22,  148,  145,
   322    322    /*    90 */   104,  238,  170,  171,  154,   42,   43,  157,  158,   46,
   323    323    /*   100 */     1,    2,   75,   76,   77,   78,   79,   80,   81,   82,
   324         - /*   110 */    83,   84,   16,   22,   61,   62,   63,   64,   65,   66,
          324  + /*   110 */    83,   84,   16,  170,   61,   62,   63,   64,   65,   66,
   325    325    /*   120 */    67,   68,   69,   70,   71,   72,   73,   23,   75,   76,
   326    326    /*   130 */    77,   78,   79,   80,   81,   82,   83,   84,   42,   43,
   327         - /*   140 */    44,  143,  144,  162,  222,  142,   14,  149,  145,   19,
   328         - /*   150 */     0,    1,    2,   23,  156,   79,   80,   61,   62,   63,
          327  + /*   140 */    44,  143,  144,  162,  222,  177,  178,  149,   21,   19,
          328  + /*   150 */    23,  156,  184,   23,  156,   79,   80,   61,   62,   63,
   329    329    /*   160 */    64,   65,   66,   67,   68,   69,   70,   71,   72,   73,
   330    330    /*   170 */   156,   75,   76,   77,   78,   79,   80,   81,   82,   83,
   331         - /*   180 */    84,   16,  201,   79,   80,   53,   21,   55,  190,   59,
          331  + /*   180 */    84,   16,  201,   79,   80,  190,   21,  122,  190,   59,
   332    332    /*   190 */   169,  159,   88,   89,  162,  163,  164,  148,  177,  218,
   333         - /*   200 */   182,  220,  221,   99,  190,  114,  161,   42,   43,   79,
   334         - /*   210 */    80,   19,   20,  215,   22,  170,  202,  203,   88,  170,
          333  + /*   200 */   182,  220,  221,   99,  190,  186,  187,   42,   43,   79,
          334  + /*   210 */    80,   19,   20,  215,   22,   88,  202,  203,   88,  170,
   335    335    /*   220 */   171,  207,   92,   19,   16,   21,   61,   62,   63,   64,
   336    336    /*   230 */    65,   66,   67,   68,   69,   70,   71,   72,   73,  241,
   337    337    /*   240 */    75,   76,   77,   78,   79,   80,   81,   82,   83,   84,
   338         - /*   250 */    42,   43,   60,  186,  187,  125,  126,  127,  187,  210,
   339         - /*   260 */   211,   11,  218,  219,  220,  221,  134,   16,   16,   61,
          338  + /*   250 */    42,   43,   60,  186,  187,  125,  126,  127,   11,  210,
          339  + /*   260 */   211,  218,  219,  220,  221,   19,   20,   16,   22,   61,
   340    340    /*   270 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
   341         - /*   280 */    72,   73,   22,   75,   76,   77,   78,   79,   80,   81,
   342         - /*   290 */    82,   83,   84,   42,   43,  168,  169,   23,  151,   49,
   343         - /*   300 */    81,   82,   83,   84,  177,   23,  186,  187,   59,  165,
   344         - /*   310 */   166,  167,   61,   62,   63,   64,   65,   66,   67,   68,
   345         - /*   320 */    69,   70,   71,   72,   73,  111,   75,   76,   77,   78,
   346         - /*   330 */    79,   80,   81,   82,   83,   84,  182,   88,  124,   16,
   347         - /*   340 */   132,   92,   22,   20,   92,   93,   94,   95,   96,   97,
   348         - /*   350 */   100,  101,  102,   19,  244,  245,  104,   23,   98,   42,
   349         - /*   360 */    43,  111,   88,   89,   90,   42,   43,   93,   94,   95,
   350         - /*   370 */    88,   89,  228,  226,  125,  126,  127,  230,   21,  105,
   351         - /*   380 */    23,   64,   65,  132,   61,   62,   63,   64,   65,   66,
   352         - /*   390 */    67,   68,   69,   70,   71,   72,   73,  115,   75,   76,
          341  + /*   280 */    72,   73,  148,   75,   76,   77,   78,   79,   80,   81,
          342  + /*   290 */    82,   83,   84,   42,   43,   90,   49,   23,   93,   94,
          343  + /*   300 */    95,  148,  161,   14,  170,  171,   60,  162,   59,  191,
          344  + /*   310 */   105,  170,   61,   62,   63,   64,   65,   66,   67,   68,
          345  + /*   320 */    69,   70,   71,   72,   73,  182,   75,   76,   77,   78,
          346  + /*   330 */    79,   80,   81,   82,   83,   84,  183,   88,   16,   16,
          347  + /*   340 */   132,   92,   53,   20,   55,  211,  201,  100,  101,  102,
          348  + /*   350 */   148,   81,   82,   83,   84,   43,   23,   22,  111,   42,
          349  + /*   360 */    43,  148,   88,   89,   90,   42,   43,   93,   94,   95,
          350  + /*   370 */   151,  148,  170,  171,  125,  126,  127,   91,  148,  105,
          351  + /*   380 */   227,   64,   65,  132,   61,   62,   63,   64,   65,   66,
          352  + /*   390 */    67,   68,   69,   70,   71,   72,   73,  111,   75,   76,
   353    353    /*   400 */    77,   78,   79,   80,   81,   82,   83,   84,   16,   92,
   354         - /*   410 */    90,  148,   20,   93,   94,   95,   19,  148,  148,  148,
   355         - /*   420 */    23,  148,   88,   89,  148,  105,   22,  157,  158,  166,
   356         - /*   430 */   167,   20,  156,   90,   42,   43,   93,   94,   95,  170,
   357         - /*   440 */   171,  170,  171,  170,  171,   88,  170,  171,  105,  156,
   358         - /*   450 */   148,  181,  182,   61,   62,   63,   64,   65,   66,   67,
          354  + /*   410 */   124,   99,   20,   91,   92,   93,   94,   95,   96,   97,
          355  + /*   420 */   148,   88,   89,  134,  148,   90,  104,  225,   93,   94,
          356  + /*   430 */    95,  187,  156,  148,   42,   43,  165,  166,  167,  209,
          357  + /*   440 */   105,  142,  170,  171,  145,  226,  170,  171,  115,  230,
          358  + /*   450 */   227,  166,  167,   61,   62,   63,   64,   65,   66,   67,
   359    359    /*   460 */    68,   69,   70,   71,   72,   73,  190,   75,   76,   77,
   360         - /*   470 */    78,   79,   80,   81,   82,   83,   84,   16,  191,   16,
   361         - /*   480 */    12,   20,  213,  190,  213,   88,  148,  148,  148,  213,
   362         - /*   490 */   148,  228,   24,   89,  225,   19,  225,   20,  225,   23,
   363         - /*   500 */   131,  225,  133,   42,   43,   37,   43,   39,  170,  171,
   364         - /*   510 */   170,  171,  170,  171,  165,  166,  167,   49,  107,  115,
   365         - /*   520 */   109,  110,   61,   62,   63,   64,   65,   66,   67,   68,
   366         - /*   530 */    69,   70,   71,   72,   73,   20,   75,   76,   77,   78,
   367         - /*   540 */    79,   80,   81,   82,   83,   84,   16,  148,   30,  211,
   368         - /*   550 */    20,  162,   23,  148,   12,  156,  108,  217,  148,  217,
   369         - /*   560 */   112,   23,   99,   23,   88,   89,   24,  104,   50,  170,
   370         - /*   570 */   171,  148,   42,   43,   23,  170,  171,  228,   18,   37,
   371         - /*   580 */   148,   39,   19,   20,  107,   22,  109,  110,  148,  190,
   372         - /*   590 */   201,   61,   62,   63,   64,   65,   66,   67,   68,   69,
   373         - /*   600 */    70,   71,   72,   73,   14,   75,   76,   77,   78,   79,
   374         - /*   610 */    80,   81,   82,   83,   84,   16,   56,   88,   89,   81,
   375         - /*   620 */    21,  103,  107,   60,  109,  110,   88,   89,   88,   89,
   376         - /*   630 */   148,  177,  178,  148,    7,    8,    9,  148,  184,   88,
   377         - /*   640 */   146,   42,   43,   53,  115,   55,  157,  158,  107,  209,
   378         - /*   650 */   109,  110,  170,  171,   94,  170,  171,  148,   16,   81,
          360  + /*   470 */    78,   79,   80,   81,   82,   83,   84,   16,  148,  148,
          361  + /*   480 */   148,   20,   19,   12,  148,  213,   23,  157,  158,  213,
          362  + /*   490 */   165,  166,  167,   20,  148,   24,  148,  225,   19,  228,
          363  + /*   500 */   148,  225,   23,   42,   43,   19,  170,  171,   37,   23,
          364  + /*   510 */    39,  181,  182,  228,   18,  183,  170,  171,  170,  171,
          365  + /*   520 */    49,   23,   61,   62,   63,   64,   65,   66,   67,   68,
          366  + /*   530 */    69,   70,   71,   72,   73,   16,   75,   76,   77,   78,
          367  + /*   540 */    79,   80,   81,   82,   83,   84,   16,  148,   20,  213,
          368  + /*   550 */    20,   88,   56,  228,   12,  156,   20,  244,  245,  227,
          369  + /*   560 */    23,  225,   43,  217,  148,  217,   24,   88,   89,  170,
          370  + /*   570 */   171,   23,   42,   43,   88,   89,  168,  169,  148,   37,
          371  + /*   580 */   107,   39,  109,  110,   30,  177,   88,   89,  162,  190,
          372  + /*   590 */    94,   61,   62,   63,   64,   65,   66,   67,   68,   69,
          373  + /*   600 */    70,   71,   72,   73,   50,   75,   76,   77,   78,   79,
          374  + /*   610 */    80,   81,   82,   83,   84,   16,  156,  148,   99,  107,
          375  + /*   620 */    21,  109,  110,  104,  148,   88,   89,  201,  148,   23,
          376  + /*   630 */   134,  148,  148,  157,  158,  107,   88,  109,  110,  170,
          377  + /*   640 */   171,   42,   43,  107,  214,  109,  110,    0,    1,    2,
          378  + /*   650 */   190,  148,  115,  148,  170,  171,  148,  103,   16,   20,
   379    379    /*   660 */    61,   62,   63,   64,   65,   66,   67,   68,   69,   70,
   380         - /*   670 */    71,   72,   73,  148,   75,   76,   77,   78,   79,   80,
   381         - /*   680 */    81,   82,   83,   84,   42,   43,  108,  100,  101,  102,
   382         - /*   690 */   112,  148,  183,  148,  134,  170,  171,   20,  148,   22,
   383         - /*   700 */   156,   16,  148,   61,   62,   63,   64,   65,   66,   67,
          380  + /*   670 */    71,   72,   73,  146,   75,   76,   77,   78,   79,   80,
          381  + /*   680 */    81,   82,   83,   84,   42,   43,  183,   81,  183,  202,
          382  + /*   690 */   203,  183,  209,  148,   88,   89,    7,    8,    9,   60,
          383  + /*   700 */   156,   16,   81,   61,   62,   63,   64,   65,   66,   67,
   384    384    /*   710 */    68,   69,   70,   71,   72,   73,  148,   75,   76,   77,
   385         - /*   720 */    78,   79,   80,   81,   82,   83,   84,   42,   43,  100,
   386         - /*   730 */   101,  102,  189,  183,  190,  162,  227,  183,  170,  171,
   387         - /*   740 */   148,  148,  148,  148,   16,  148,   61,   62,   63,   64,
          385  + /*   720 */    78,   79,   80,   81,   82,   83,   84,   42,   43,  108,
          386  + /*   730 */   227,  148,  227,  112,  190,  227,  148,   14,  170,  171,
          387  + /*   740 */   100,  101,  102,  148,   16,  148,   61,   62,   63,   64,
   388    388    /*   750 */    65,   66,   67,   68,   69,   70,   71,   72,   73,  215,
   389    389    /*   760 */    75,   76,   77,   78,   79,   80,   81,   82,   83,   84,
   390         - /*   770 */    42,   43,  227,  148,  201,  183,  183,  227,  202,  203,
   391         - /*   780 */   236,  227,  239,  189,  189,  148,  189,   16,  148,  148,
          390  + /*   770 */    42,   43,  189,   25,  148,  148,   53,   29,   55,  148,
          391  + /*   780 */   236,  100,  101,  102,  189,  148,  189,   16,  192,   41,
   392    392    /*   790 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
   393         - /*   800 */    72,   73,  148,   75,   76,   77,   78,   79,   80,   81,
   394         - /*   810 */    82,   83,   84,   42,   43,  148,   20,  148,   22,  227,
   395         - /*   820 */   227,  193,  192,  148,  170,  171,  189,  148,  200,  189,
   396         - /*   830 */   242,  243,  125,  126,   63,   64,   65,   66,   67,   68,
          393  + /*   800 */    72,   73,  214,   75,   76,   77,   78,   79,   80,   81,
          394  + /*   810 */    82,   83,   84,   42,   43,  148,  189,  111,   22,   22,
          395  + /*   820 */   189,  193,  239,  148,  148,  148,  189,  156,  200,  204,
          396  + /*   830 */   124,  242,  243,   22,   63,   64,   65,   66,   67,   68,
   397    397    /*   840 */    69,   70,   71,   72,   73,  148,   75,   76,   77,   78,
   398    398    /*   850 */    79,   80,   81,   82,   83,   84,   16,   17,  148,   19,
   399         - /*   860 */   148,   25,  148,   23,  148,   29,  148,  170,  171,  148,
   400         - /*   870 */    19,   31,   16,   17,  148,   19,  209,   41,  209,   23,
   401         - /*   880 */   170,  171,  170,  171,  170,  171,   92,   31,   48,  214,
   402         - /*   890 */   148,  170,  171,  214,  162,  148,  170,  171,  104,   59,
   403         - /*   900 */   148,  148,  148,   27,   48,  189,   22,  189,  148,  148,
   404         - /*   910 */    34,  148,    7,    8,  148,   59,  148,  170,  171,   79,
   405         - /*   920 */    80,  156,  170,  171,  170,  171,  156,   87,   88,   89,
          399  + /*   860 */   148,  190,  148,   23,  189,  189,  189,  148,  131,  148,
          400  + /*   870 */   133,   31,   16,   17,  148,   19,  209,    7,    8,   23,
          401  + /*   880 */   170,  171,  170,  171,  170,  171,   89,   31,   48,  170,
          402  + /*   890 */   171,  170,  171,   19,  108,  148,  170,  171,  112,   59,
          403  + /*   900 */   148,   20,  148,   22,   48,  125,  126,  156,  148,   98,
          404  + /*   910 */   114,  148,  115,   91,   92,   59,  148,  170,  171,   79,
          405  + /*   920 */    80,  156,  170,  171,  170,  171,   16,   87,   88,   89,
   406    406    /*   930 */   170,  171,   92,  170,  171,   79,   80,   81,  170,  171,
   407         - /*   940 */   148,  204,  189,   87,   88,   89,   16,   17,   92,   19,
   408         - /*   950 */   148,  111,  148,   23,  148,  190,   20,  148,   22,  156,
   409         - /*   960 */   190,   31,  170,  171,  113,  125,  126,  127,  128,  129,
   410         - /*   970 */   130,   91,  170,  171,  170,  171,  170,  171,   48,  170,
   411         - /*   980 */   171,  125,  126,  127,  128,  129,  130,  148,   16,   59,
   412         - /*   990 */     5,  111,  148,  190,   43,   10,   11,   12,   13,  156,
   413         - /*  1000 */    20,  148,   22,  148,  124,  148,  122,  148,  148,   79,
   414         - /*  1010 */    80,   26,   20,   28,  170,  171,  148,   87,   88,   89,
          407  + /*   940 */   148,  190,  148,   87,   88,   89,   16,   17,   92,   19,
          408  + /*   950 */   148,  111,  148,   23,  148,  190,   20,  148,   22,   51,
          409  + /*   960 */    52,   31,  170,  171,   27,  125,  126,  127,  128,  129,
          410  + /*   970 */   130,   34,  170,  171,  170,  171,  170,  171,   48,  170,
          411  + /*   980 */   171,  125,  126,  127,  128,  129,  130,  113,   92,   59,
          412  + /*   990 */     5,   20,  148,   22,  162,   10,   11,   12,   13,  148,
          413  + /*  1000 */   104,  148,   92,  148,   20,  148,   22,  148,  148,   79,
          414  + /*  1010 */    80,   26,  148,   28,  170,  171,  148,   87,   88,   89,
   415    415    /*  1020 */    35,  148,   92,  170,  171,  170,  171,  170,  171,  170,
   416         - /*  1030 */   171,  148,   47,  190,   49,   91,   92,   51,   52,   54,
   417         - /*  1040 */   148,  148,   57,  170,  171,  148,  179,   20,  148,   22,
   418         - /*  1050 */    99,  148,   60,  170,  171,  125,  126,  127,  128,  129,
   419         - /*  1060 */   130,  179,  170,  171,   92,  179,  148,  170,  171,   19,
          416  + /*  1030 */   171,  148,   47,  148,   49,   20,   20,   22,   22,   54,
          417  + /*  1040 */   148,  179,   57,  170,  171,  148,  179,   20,  148,   22,
          418  + /*  1050 */    20,  148,   22,  170,  171,  125,  126,  127,  128,  129,
          419  + /*  1060 */   130,  179,  170,  171,  148,  148,  148,  170,  171,   19,
   420    420    /*  1070 */   170,  171,  148,  170,  171,   20,  148,   22,   20,  148,
   421    421    /*  1080 */    22,  148,  148,  148,  232,  100,  101,  102,  170,  171,
   422         - /*  1090 */    20,  106,   22,  148,  170,  171,  111,  148,  170,  171,
   423         - /*  1100 */   148,  170,  171,  170,  171,  233,   20,   20,   22,   22,
   424         - /*  1110 */    20,  148,   22,  148,  148,   20,  148,   22,  148,   69,
   425         - /*  1120 */   135,  148,  148,  148,  148,  148,  148,  148,  173,  148,
   426         - /*  1130 */   148,  192,  194,  150,  224,  229,  229,  173,  178,    6,
   427         - /*  1140 */   173,  195,  173,  195,  173,  147,  147,  147,  147,   22,
   428         - /*  1150 */   155,   99,   40,  122,   98,  119,  195,  120,  174,  172,
   429         - /*  1160 */   172,  117,  172,  121,  131,  174,  172,  113,  153,  180,
   430         - /*  1170 */   223,   97,   23,  161,  212,  153,   99,  116,   19,  161,
   431         - /*  1180 */    15,  152,  175,  190,   38,  153,  172,  152,  172,  172,
   432         - /*  1190 */   234,  153,  196,  180,  197,  175,  153,  152,  131,  153,
   433         - /*  1200 */   198,  152,  199,   61,  153,   19,  185,   15,  185,   33,
   434         - /*  1210 */   205,  138,  206,  205,  188,  206,  212,  153,  188,  153,
   435         - /*  1220 */   195,  153,  212,  212,  153,  160,  185,  188,  188,  195,
   436         - /*  1230 */     1,   20,   32,  176,   44,  176,   19,  113,  113,  113,
   437         - /*  1240 */   216,  113,   19,   92,  216,   20,   20,  108,   11,   19,
   438         - /*  1250 */    19,  115,   20,  118,  235,   22,   20,   22,  118,   19,
   439         - /*  1260 */    22,   20,   20,  113,   44,   19,   44,   20,   19,   19,
   440         - /*  1270 */    19,   96,  104,   16,   21,   17,   99,   22,  134,   36,
   441         - /*  1280 */    99,   19,    5,    1,  237,  237,  103,   69,   69,   45,
   442         - /*  1290 */    45,  231,  123,  240,   19,   14,  114,   17,  103,  114,
   443         - /*  1300 */   116,  123,   19,  124,   20,  243,   14,  136,   19,  246,
   444         - /*  1310 */    58,  137,    3,  247,    4,
          422  + /*  1090 */   148,  106,  148,  148,  170,  171,  111,  148,  170,  171,
          423  + /*  1100 */   148,  170,  171,  170,  171,  170,  171,   20,   20,   22,
          424  + /*  1110 */    22,  233,  148,  148,  170,  171,  148,  148,  148,   69,
          425  + /*  1120 */   135,  148,  170,  171,  148,  148,  148,  148,  148,  148,
          426  + /*  1130 */   148,  192,  194,  150,  229,  229,  224,  178,  195,  173,
          427  + /*  1140 */   173,  195,    6,  147,  147,  173,  147,  173,  173,  147,
          428  + /*  1150 */    22,  190,  195,  155,  122,  119,  196,  120,  117,  197,
          429  + /*  1160 */   174,  198,  131,  121,  223,  113,  153,   97,  212,   23,
          430  + /*  1170 */   161,  153,   99,  116,   99,  172,  172,   40,  172,   98,
          431  + /*  1180 */   180,  174,  172,   19,  161,  180,  199,  175,   15,  172,
          432  + /*  1190 */   152,  172,  172,  153,  205,  152,  206,  205,  153,  206,
          433  + /*  1200 */   212,  175,  153,  212,  153,  152,  212,   38,  131,  153,
          434  + /*  1210 */    61,  152,   19,  185,  185,  153,  195,   15,  153,  195,
          435  + /*  1220 */    33,  188,  188,  188,  216,  153,  160,  188,  138,  234,
          436  + /*  1230 */   216,  185,  153,    1,   20,  113,  235,  176,  113,  176,
          437  + /*  1240 */   113,   19,  113,   20,   20,   92,  108,   19,  237,   11,
          438  + /*  1250 */    19,   22,  118,   20,   20,   19,  115,   22,  118,  237,
          439  + /*  1260 */    20,   22,   20,  113,   44,  240,   19,   19,   19,   32,
          440  + /*  1270 */    44,   20,   19,   19,   44,  231,   96,   16,  104,   17,
          441  + /*  1280 */    21,   99,   36,   99,   19,   22,   45,    5,   45,  134,
          442  + /*  1290 */   243,    1,  103,  123,  246,   19,   69,  114,   14,  103,
          443  + /*  1300 */    17,  116,  114,  124,  123,   19,   14,   20,   58,  137,
          444  + /*  1310 */    19,  136,    3,   69,    4,
   445    445   };
   446    446   #define YY_SHIFT_USE_DFLT (-106)
   447    447   #define YY_SHIFT_MAX 386
   448    448   static const short yy_shift_ofst[] = {
   449    449    /*     0 */    99,  840,  985,  -16,  840,  930,  930,  930,  274, -105,
   450         - /*    10 */    96,  930,  930,  930,  930,  930,  -46,  250,  104,  540,
   451         - /*    20 */   551,   76,   76,   53,  165,  208,  251,  323,  392,  461,
          450  + /*    10 */    96,  930,  930,  930,  930,  930,  -46,  247,  104,  498,
          451  + /*    20 */   548,   76,   76,   53,  165,  208,  251,  323,  392,  461,
   452    452    /*    30 */   530,  599,  642,  685,  642,  642,  642,  642,  642,  642,
   453    453    /*    40 */   642,  642,  642,  642,  642,  642,  642,  642,  642,  642,
   454    454    /*    50 */   642,  728,  771,  771,  856,  930,  930,  930,  930,  930,
   455    455    /*    60 */   930,  930,  930,  930,  930,  930,  930,  930,  930,  930,
   456    456    /*    70 */   930,  930,  930,  930,  930,  930,  930,  930,  930,  930,
   457    457    /*    80 */   930,  930,  930,  930,  930,  930,  930,  930,  930,  930,
   458         - /*    90 */   930,  930,  930,  -62,  -62,  -14,   27,   27,  -40,  219,
   459         - /*   100 */   463,  560,  540,  540,  540,  540,  540,  540,  540,  551,
   460         - /*   110 */   -72, -106, -106, -106,  130,  252,  468,  468,  192,  563,
   461         - /*   120 */   150,  357,  540,  357,  540,  540,  540,  540,  540,  540,
   462         - /*   130 */   540,  540,  540,  540,  540,  540,  540,  880,  214, -105,
   463         - /*   140 */  -105, -105, -106, -106, -106,  249,  249,  320,  343,  411,
   464         - /*   150 */   334,  477,  515,  542,  282,  529,  476,  538,  627,  540,
   465         - /*   160 */   540,  578,  540,  540,  397,  540,  540,  404,  540,  540,
   466         - /*   170 */   541,  404,  540,  540,  518,  518,  518,  540,  540,  541,
   467         - /*   180 */   540,  540,  541,  540,  836,  587,  540,  540,  541,  540,
   468         - /*   190 */   540,  540,  541,  540,  540,  540,  541,  541,  540,  540,
   469         - /*   200 */   540,  540,  540,  540,  204,  876,  448,   91,  707,  707,
   470         - /*   210 */   369,  876,  876,  951,  876,  876,  260,  884,  884, 1133,
   471         - /*   220 */  1133, 1133, 1133, 1127, 1052, 1052, 1112, 1052, 1056, 1052,
   472         - /*   230 */  -105, 1031, 1036, 1037, 1044, 1042, 1033, 1054, 1074, 1149,
   473         - /*   240 */  1074, 1054, 1077, 1061, 1077, 1061, 1159, 1074, 1074, 1149,
   474         - /*   250 */  1112, 1052, 1052, 1052, 1159, 1165, 1054, 1165, 1054, 1165,
   475         - /*   260 */  1054, 1054, 1146, 1067, 1165, 1054, 1142, 1142, 1186, 1031,
   476         - /*   270 */  1054, 1192, 1192, 1192, 1192, 1031, 1142, 1186, 1054, 1176,
   477         - /*   280 */  1176, 1054, 1054, 1073, -106, -106, -106, -106, -106, -106,
   478         - /*   290 */   317,  132,  629,  590,  794,  905,  851,  677,  972,  796,
   479         - /*   300 */   936,  980,  944, 1027, 1055, 1058,  986, 1086, 1087, 1090,
   480         - /*   310 */  1095, 1050, 1070,  992, 1229, 1211, 1200, 1190, 1217, 1124,
   481         - /*   320 */  1125, 1126, 1128, 1223, 1225, 1226, 1151, 1139, 1230, 1237,
   482         - /*   330 */  1231, 1232, 1233, 1236, 1135, 1235, 1140, 1238, 1136, 1240,
   483         - /*   340 */  1241, 1150, 1242, 1220, 1246, 1247, 1249, 1250, 1222, 1251,
   484         - /*   350 */  1175, 1168, 1257, 1258, 1253, 1177, 1243, 1244, 1255, 1245,
   485         - /*   360 */  1144, 1181, 1262, 1277, 1282, 1183, 1218, 1219, 1169, 1275,
   486         - /*   370 */  1182, 1281, 1184, 1280, 1185, 1195, 1178, 1283, 1179, 1284,
   487         - /*   380 */  1292, 1252, 1171, 1174, 1289, 1309, 1310,
          458  + /*    90 */   930,  930,  930,  -62,  -62,  -14,   27,   27,  -40,  270,
          459  + /*   100 */   519,  496,  498,  498,  498,  498,  498,  498,  498,  548,
          460  + /*   110 */   -72, -106, -106, -106,  130,  322,  471,  471,  192,  246,
          461  + /*   120 */   647,  127,  498,  127,  498,  498,  498,  498,  498,  498,
          462  + /*   130 */   498,  498,  498,  498,  498,  498,  498,  286,  706, -105,
          463  + /*   140 */  -105, -105, -106, -106, -106,  249,  249,  335,  205,  473,
          464  + /*   150 */   479,  528,  536,  542,  333,  537,  486,  606,  689,  498,
          465  + /*   160 */   498,  621,  498,  498,  463,  498,  498,  797,  498,  498,
          466  + /*   170 */   512,  797,  498,  498,  554,  554,  554,  498,  498,  512,
          467  + /*   180 */   498,  498,  512,  498,  748,  640,  498,  498,  512,  498,
          468  + /*   190 */   498,  498,  512,  498,  498,  498,  512,  512,  498,  498,
          469  + /*   200 */   498,  498,  498,  498,  204,  786,  796,  780,  780,  737,
          470  + /*   210 */   937,  937,  937,  312,  937,  937,  811,   65,   65, 1136,
          471  + /*   220 */  1136, 1136, 1136, 1128, -105, 1032, 1036, 1037, 1041, 1042,
          472  + /*   230 */  1031, 1052, 1070, 1146, 1070, 1052, 1073, 1057, 1073, 1057,
          473  + /*   240 */  1075, 1075, 1137, 1075, 1081, 1075, 1164, 1070, 1070, 1146,
          474  + /*   250 */  1137, 1075, 1075, 1075, 1164, 1173, 1052, 1173, 1052, 1173,
          475  + /*   260 */  1052, 1052, 1169, 1077, 1173, 1052, 1149, 1149, 1193, 1032,
          476  + /*   270 */  1052, 1202, 1202, 1202, 1202, 1032, 1149, 1193, 1052, 1187,
          477  + /*   280 */  1187, 1052, 1052, 1090, -106, -106, -106, -106, -106, -106,
          478  + /*   290 */   317,  289,  681,  723,  874,  881,  910,  936,  971,  984,
          479  + /*   300 */   896,  870,  822, 1015, 1016, 1027,  908, 1030, 1055, 1058,
          480  + /*   310 */  1087, 1050, 1088,  639, 1232, 1214, 1122, 1125, 1127, 1129,
          481  + /*   320 */  1222, 1223, 1224, 1153, 1138, 1228, 1238, 1231, 1233, 1229,
          482  + /*   330 */  1234, 1134, 1235, 1140, 1239, 1141, 1236, 1240, 1150, 1242,
          483  + /*   340 */  1237, 1220, 1247, 1226, 1248, 1251, 1249, 1253, 1230, 1254,
          484  + /*   350 */  1180, 1174, 1261, 1262, 1259, 1182, 1246, 1241, 1263, 1243,
          485  + /*   360 */  1155, 1184, 1265, 1282, 1290, 1189, 1227, 1244, 1170, 1276,
          486  + /*   370 */  1183, 1284, 1185, 1283, 1188, 1196, 1181, 1286, 1179, 1287,
          487  + /*   380 */  1292, 1250, 1175, 1172, 1291, 1309, 1310,
   488    488   };
   489    489   #define YY_REDUCE_USE_DFLT (-218)
   490    490   #define YY_REDUCE_MAX 289
   491    491   static const short yy_reduce_ofst[] = {
   492         - /*     0 */   -56,  276,   -2,  -19,  399,  269,   49,  271,  270,   14,
   493         - /*    10 */  -147,  -78,  273,  338,  340,  342,   44,  544,  263,  -60,
   494         - /*    20 */    32,  144,  349, -217, -217, -217, -217, -217, -217, -217,
          492  + /*     0 */   -56,  276,   -2,  -19,  399,  272,   49,  336,  330,   14,
          493  + /*    10 */  -147,  -78,  202,  134,  346,  348,   43,  544,  285,  -60,
          494  + /*    20 */    32,  271,  325, -217, -217, -217, -217, -217, -217, -217,
   495    495    /*    30 */  -217, -217, -217, -217, -217, -217, -217, -217, -217, -217,
   496    496    /*    40 */  -217, -217, -217, -217, -217, -217, -217, -217, -217, -217,
   497         - /*    50 */  -217, -217, -217, -217,  405,  482,  485,  525,  568,  654,
   498         - /*    60 */   697,  710,  712,  714,  721,  726,  747,  752,  754,  760,
   499         - /*    70 */   763,  768,  792,  802,  804,  806,  809,  844,  853,  855,
   500         - /*    80 */   857,  859,  873,  883,  892,  897,  900,  903,  918,  924,
   501         - /*    90 */   928,  931,  933, -217, -217,  127, -217, -217, -217, -217,
   502         - /*   100 */   454,  147,  509,  550,  554,  592,  593,  543,  489, -139,
   503         - /*   110 */  -217, -217, -217, -217,   45,   21,   67,  120,  110,  110,
   504         - /*   120 */     3,  389,  440,  573,  545,  594,  667,  675,  669,  595,
   505         - /*   130 */   597,  637,  640,  716,  718,  679,  753,  293,  765,  770,
   506         - /*   140 */   803,  843,  628,  576,  588, -112,  -83,   18,  154,  287,
   507         - /*   150 */   302,  287,  287,   71,  339,  410,  423,  432,  494,  625,
   508         - /*   160 */   641,  630,  432,  742,  732,  761,  766,  737,  839,  860,
   509         - /*   170 */   287,  737,  868,  893,  867,  882,  886,  934,  935,  287,
   510         - /*   180 */   945,  949,  287,  952,  852,  872,  963,  965,  287,  966,
   511         - /*   190 */   968,  970,  287,  973,  974,  975,  287,  287,  976,  977,
   512         - /*   200 */   978,  979,  981,  982,  983,  955,  939,  938,  906,  907,
   513         - /*   210 */   910,  964,  967,  960,  969,  971,  984,  946,  948,  998,
   514         - /*   220 */   999, 1000, 1001,  995,  987,  988,  989,  990,  991,  994,
   515         - /*   230 */   993,  961,  996,  997, 1002, 1003,  947, 1015,  962, 1012,
   516         - /*   240 */  1004, 1022, 1005, 1006, 1008, 1009, 1007, 1010, 1011, 1018,
   517         - /*   250 */  1013, 1014, 1016, 1017, 1020, 1029, 1032, 1035, 1038, 1045,
   518         - /*   260 */  1043, 1046,  956, 1019, 1049, 1051, 1021, 1023, 1024, 1025,
   519         - /*   270 */  1064, 1026, 1030, 1039, 1040, 1034, 1041, 1028, 1066, 1047,
   520         - /*   280 */  1048, 1068, 1071, 1053, 1065, 1057, 1059, 1060, 1062, 1063,
          497  + /*    50 */  -217, -217, -217, -217,  469,  484,  568,  710,  712,  714,
          498  + /*    60 */   719,  721,  726,  747,  752,  754,  760,  763,  768,  792,
          499  + /*    70 */   802,  804,  806,  809,  844,  853,  855,  857,  859,  873,
          500  + /*    80 */   883,  892,  897,  900,  903,  918,  924,  928,  931,  933,
          501  + /*    90 */   935,  944,  952, -217, -217,  408, -217, -217, -217, -217,
          502  + /*   100 */   -32,  219,  153,  332,  503,  505,  508,  583,  476, -139,
          503  + /*   110 */  -217, -217, -217, -217,  141,   21,   19,   67,  313,  313,
          504  + /*   120 */   299,  145,  230,  426,  223,  595,  483,  430,  667,  597,
          505  + /*   130 */   627,  631,  637,  675,  676,  588,  677,   -5,  460,  671,
          506  + /*   140 */   751,  765,  628,  487,  589, -112,  -57,   18,  143,  118,
          507  + /*   150 */   213,  118,  118,  244,  331,  352,  416,  480,  527,  545,
          508  + /*   160 */   626,  596,  480,  697,  832,  794,  851,  625,  860,  864,
          509  + /*   170 */   118,  625,  868,  885,  862,  867,  882,  916,  917,  118,
          510  + /*   180 */   934,  942,  118,  945,  852,  878,  949,  964,  118,  965,
          511  + /*   190 */   968,  969,  118,  970,  973,  976,  118,  118,  977,  978,
          512  + /*   200 */   979,  980,  981,  982,  983,  939,  938,  905,  906,  912,
          513  + /*   210 */   966,  967,  972,  959,  974,  975,  986,  943,  946,  996,
          514  + /*   220 */   997,  999, 1002,  998,  961,  957,  960,  962,  963,  987,
          515  + /*   230 */   941, 1013,  956, 1009,  988, 1018,  989,  990,  992,  993,
          516  + /*   240 */  1003, 1004, 1000, 1006, 1007, 1010, 1012,  991,  994, 1023,
          517  + /*   250 */  1005, 1017, 1019, 1020, 1026, 1038, 1040, 1043, 1045, 1053,
          518  + /*   260 */  1049, 1051,  995, 1001, 1059, 1056, 1028, 1029, 1008, 1021,
          519  + /*   270 */  1062, 1033, 1034, 1035, 1039, 1024, 1046, 1014, 1065, 1011,
          520  + /*   280 */  1022, 1072, 1079, 1025, 1066, 1061, 1063, 1044, 1047, 1048,
   521    521   };
   522    522   static const YYACTIONTYPE yy_default[] = {
   523    523    /*     0 */   592,  819,  896,  707,  896,  819,  896,  819,  896,  711,
   524    524    /*    10 */   870,  815,  819,  896,  896,  896,  790,  896,  841,  896,
   525    525    /*    20 */   623,  841,  841,  742,  896,  896,  896,  896,  896,  896,
   526    526    /*    30 */   896,  896,  743,  896,  818,  814,  810,  812,  811,  744,
   527    527    /*    40 */   731,  740,  747,  723,  855,  749,  750,  756,  757,  871,
................................................................................
   536    536    /*   130 */   896,  896,  896,  896,  896,  896,  896,  896,  896,  896,
   537    537    /*   140 */   896,  896,  701,  711,  889,  896,  896,  667,  896,  896,
   538    538    /*   150 */   896,  896,  896,  896,  896,  896,  896,  896,  599,  597,
   539    539    /*   160 */   896,  699,  896,  896,  625,  896,  896,  709,  896,  896,
   540    540    /*   170 */   714,  715,  896,  896,  896,  896,  896,  896,  896,  613,
   541    541    /*   180 */   896,  896,  688,  896,  847,  896,  896,  896,  862,  896,
   542    542    /*   190 */   896,  896,  860,  896,  896,  896,  690,  752,  829,  896,
   543         - /*   200 */   896,  875,  877,  896,  896,  734,  699,  708,  896,  896,
   544         - /*   210 */   813,  734,  734,  646,  734,  734,  649,  746,  746,  596,
   545         - /*   220 */   596,  596,  596,  666,  678,  678,  663,  678,  649,  678,
   546         - /*   230 */   896,  746,  737,  739,  727,  741,  896,  716,  735,  896,
   547         - /*   240 */   735,  716,  724,  726,  724,  726,  823,  735,  735,  896,
          543  + /*   200 */   896,  875,  877,  896,  896,  699,  708,  896,  896,  813,
          544  + /*   210 */   734,  734,  734,  646,  734,  734,  649,  746,  746,  596,
          545  + /*   220 */   596,  596,  596,  666,  896,  746,  737,  739,  727,  741,
          546  + /*   230 */   896,  716,  735,  896,  735,  716,  724,  726,  724,  726,
          547  + /*   240 */   678,  678,  663,  678,  649,  678,  823,  735,  735,  896,
   548    548    /*   250 */   663,  678,  678,  678,  823,  608,  716,  608,  716,  608,
   549    549    /*   260 */   716,  716,  851,  854,  608,  716,  680,  680,  758,  746,
   550    550    /*   270 */   716,  687,  687,  687,  687,  746,  680,  758,  716,  873,
   551    551    /*   280 */   873,  716,  716,  882,  633,  651,  651,  857,  889,  894,
   552         - /*   290 */   896,  896,  896,  896,  896,  896,  765,  896,  896,  896,
          552  + /*   290 */   896,  896,  896,  896,  765,  896,  896,  896,  896,  896,
   553    553    /*   300 */   896,  896,  896,  896,  896,  896,  896,  896,  896,  896,
   554         - /*   310 */   896,  836,  896,  896,  896,  896,  896,  896,  896,  770,
   555         - /*   320 */   766,  896,  767,  896,  896,  896,  896,  693,  896,  896,
   556         - /*   330 */   896,  896,  896,  896,  896,  728,  896,  738,  896,  896,
          554  + /*   310 */   896,  836,  896,  896,  896,  896,  770,  766,  896,  767,
          555  + /*   320 */   896,  896,  896,  896,  693,  896,  896,  896,  896,  896,
          556  + /*   330 */   896,  896,  728,  896,  738,  896,  896,  896,  896,  896,
   557    557    /*   340 */   896,  896,  896,  896,  896,  896,  896,  896,  896,  896,
   558    558    /*   350 */   896,  896,  896,  896,  896,  896,  896,  849,  850,  896,
   559    559    /*   360 */   896,  896,  896,  896,  896,  896,  896,  896,  896,  896,
   560    560    /*   370 */   896,  896,  896,  896,  896,  896,  896,  896,  896,  896,
   561    561    /*   380 */   896,  881,  896,  896,  884,  593,  896,  587,  590,  589,
   562    562    /*   390 */   591,  595,  598,  620,  621,  622,  600,  601,  602,  603,
   563         - /*   400 */   604,  605,  606,  612,  614,  632,  634,  641,  679,  682,
   564         - /*   410 */   683,  684,  865,  866,  867,  642,  661,  664,  665,  643,
   565         - /*   420 */   650,  732,  733,  644,  697,  698,  762,  691,  692,  696,
   566         - /*   430 */   764,  768,  769,  771,  772,  619,  626,  627,  630,  631,
   567         - /*   440 */   837,  839,  838,  840,  629,  628,  773,  776,  785,  786,
   568         - /*   450 */   788,  794,  800,  803,  787,  792,  793,  795,  799,  802,
   569         - /*   460 */   694,  695,  806,  808,  809,  863,  864,  804,  816,  817,
   570         - /*   470 */   717,  807,  791,  729,  618,  736,  730,  700,  710,  719,
   571         - /*   480 */   720,  721,  722,  705,  706,  712,  725,  760,  761,  713,
   572         - /*   490 */   702,  703,  704,  805,  763,  774,  775,  645,  652,  653,
   573         - /*   500 */   654,  657,  658,  659,  660,  655,  656,  824,  825,  827,
   574         - /*   510 */   826,  647,  648,  662,  635,  636,  637,  638,  770,  639,
   575         - /*   520 */   640,  624,  617,  668,  671,  672,  673,  674,  675,  677,
          563  + /*   400 */   604,  605,  606,  612,  614,  632,  634,  618,  636,  697,
          564  + /*   410 */   698,  762,  691,  692,  696,  764,  768,  769,  771,  772,
          565  + /*   420 */   619,  626,  627,  630,  631,  837,  839,  838,  840,  629,
          566  + /*   430 */   628,  773,  776,  785,  786,  788,  794,  800,  803,  787,
          567  + /*   440 */   792,  793,  795,  799,  802,  694,  695,  806,  808,  809,
          568  + /*   450 */   863,  864,  865,  866,  867,  804,  816,  817,  717,  807,
          569  + /*   460 */   791,  729,  732,  733,  736,  730,  700,  710,  719,  720,
          570  + /*   470 */   721,  722,  705,  706,  712,  725,  760,  761,  713,  702,
          571  + /*   480 */   703,  704,  805,  763,  774,  775,  637,  638,  770,  639,
          572  + /*   490 */   640,  641,  679,  682,  683,  684,  642,  661,  664,  665,
          573  + /*   500 */   643,  650,  644,  645,  652,  653,  654,  657,  658,  659,
          574  + /*   510 */   660,  655,  656,  824,  825,  827,  826,  647,  648,  662,
          575  + /*   520 */   635,  624,  617,  668,  671,  672,  673,  674,  675,  677,
   576    576    /*   530 */   669,  670,  615,  607,  609,  718,  843,  852,  853,  848,
   577    577    /*   540 */   844,  845,  846,  610,  820,  821,  681,  754,  755,  842,
   578    578    /*   550 */   856,  858,  759,  859,  861,  886,  685,  686,  689,  828,
   579    579    /*   560 */   868,  745,  748,  751,  753,  830,  831,  832,  833,  834,
   580    580    /*   570 */   835,  869,  872,  876,  878,  879,  880,  883,  885,  890,
   581    581    /*   580 */   891,  892,  895,  893,  594,  588,
   582    582   };
................................................................................
   918    918    /*  43 */ "typename ::= typename ids",
   919    919    /*  44 */ "signed ::= plus_num",
   920    920    /*  45 */ "signed ::= minus_num",
   921    921    /*  46 */ "carglist ::= carglist carg",
   922    922    /*  47 */ "carglist ::=",
   923    923    /*  48 */ "carg ::= CONSTRAINT nm ccons",
   924    924    /*  49 */ "carg ::= ccons",
   925         - /*  50 */ "carg ::= DEFAULT term",
   926         - /*  51 */ "carg ::= DEFAULT LP expr RP",
   927         - /*  52 */ "carg ::= DEFAULT PLUS term",
   928         - /*  53 */ "carg ::= DEFAULT MINUS term",
   929         - /*  54 */ "carg ::= DEFAULT id",
          925  + /*  50 */ "ccons ::= DEFAULT term",
          926  + /*  51 */ "ccons ::= DEFAULT LP expr RP",
          927  + /*  52 */ "ccons ::= DEFAULT PLUS term",
          928  + /*  53 */ "ccons ::= DEFAULT MINUS term",
          929  + /*  54 */ "ccons ::= DEFAULT id",
   930    930    /*  55 */ "ccons ::= NULL onconf",
   931    931    /*  56 */ "ccons ::= NOT NULL onconf",
   932    932    /*  57 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
   933    933    /*  58 */ "ccons ::= UNIQUE onconf",
   934    934    /*  59 */ "ccons ::= CHECK LP expr RP",
   935    935    /*  60 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
   936    936    /*  61 */ "ccons ::= defer_subclause",
................................................................................
  1253   1253       case 205:
  1254   1254       case 211:
  1255   1255       case 219:
  1256   1256       case 222:
  1257   1257       case 224:
  1258   1258       case 225:
  1259   1259       case 235:
  1260         -#line 633 "parse.y"
         1260  +#line 618 "parse.y"
  1261   1261   {sqlite3ExprDelete((yypminor->yy172));}
  1262   1262   #line 1264 "parse.c"
  1263   1263         break;
  1264   1264       case 175:
  1265   1265       case 183:
  1266   1266       case 193:
  1267   1267       case 196:
................................................................................
  1268   1268       case 198:
  1269   1269       case 200:
  1270   1270       case 210:
  1271   1271       case 213:
  1272   1272       case 214:
  1273   1273       case 217:
  1274   1274       case 223:
  1275         -#line 870 "parse.y"
         1275  +#line 855 "parse.y"
  1276   1276   {sqlite3ExprListDelete((yypminor->yy174));}
  1277   1277   #line 1279 "parse.c"
  1278   1278         break;
  1279   1279       case 189:
  1280   1280       case 194:
  1281   1281       case 202:
  1282   1282       case 203:
  1283         -#line 502 "parse.y"
         1283  +#line 487 "parse.y"
  1284   1284   {sqlite3SrcListDelete((yypminor->yy373));}
  1285   1285   #line 1287 "parse.c"
  1286   1286         break;
  1287   1287       case 199:
  1288         -#line 563 "parse.y"
         1288  +#line 548 "parse.y"
  1289   1289   {
  1290   1290     sqlite3ExprDelete((yypminor->yy234).pLimit);
  1291   1291     sqlite3ExprDelete((yypminor->yy234).pOffset);
  1292   1292   }
  1293   1293   #line 1295 "parse.c"
  1294   1294         break;
  1295   1295       case 206:
  1296   1296       case 209:
  1297   1297       case 216:
  1298         -#line 519 "parse.y"
         1298  +#line 504 "parse.y"
  1299   1299   {sqlite3IdListDelete((yypminor->yy432));}
  1300   1300   #line 1302 "parse.c"
  1301   1301         break;
  1302   1302       case 231:
  1303   1303       case 236:
  1304         -#line 966 "parse.y"
         1304  +#line 951 "parse.y"
  1305   1305   {sqlite3DeleteTriggerStep((yypminor->yy243));}
  1306   1306   #line 1308 "parse.c"
  1307   1307         break;
  1308   1308       case 233:
  1309         -#line 950 "parse.y"
         1309  +#line 935 "parse.y"
  1310   1310   {sqlite3IdListDelete((yypminor->yy370).b);}
  1311   1311   #line 1313 "parse.c"
  1312   1312         break;
  1313   1313       case 238:
  1314         -#line 1034 "parse.y"
         1314  +#line 1019 "parse.y"
  1315   1315   {sqlite3ExprDelete((yypminor->yy386));}
  1316   1316   #line 1318 "parse.c"
  1317   1317         break;
  1318   1318       default:  break;   /* If no destructor action specified: do nothing */
  1319   1319     }
  1320   1320   }
  1321   1321   
................................................................................
  1554   1554     { 164, 2 },
  1555   1555     { 165, 1 },
  1556   1556     { 165, 1 },
  1557   1557     { 160, 2 },
  1558   1558     { 160, 0 },
  1559   1559     { 168, 3 },
  1560   1560     { 168, 1 },
  1561         -  { 168, 2 },
  1562         -  { 168, 4 },
  1563         -  { 168, 3 },
  1564         -  { 168, 3 },
  1565         -  { 168, 2 },
         1561  +  { 169, 2 },
         1562  +  { 169, 4 },
         1563  +  { 169, 3 },
         1564  +  { 169, 3 },
         1565  +  { 169, 2 },
  1566   1566     { 169, 2 },
  1567   1567     { 169, 3 },
  1568   1568     { 169, 5 },
  1569   1569     { 169, 2 },
  1570   1570     { 169, 4 },
  1571   1571     { 169, 4 },
  1572   1572     { 169, 1 },
................................................................................
  2316   2316         case 122:
  2317   2317   #line 446 "parse.y"
  2318   2318   {yygotominor.yy373 = sqliteMalloc(sizeof(*yygotominor.yy373));}
  2319   2319   #line 2322 "parse.c"
  2320   2320           break;
  2321   2321         case 123:
  2322   2322   #line 447 "parse.y"
  2323         -{yygotominor.yy373 = yymsp[0].minor.yy373;}
  2324         -#line 2327 "parse.c"
         2323  +{
         2324  +  yygotominor.yy373 = yymsp[0].minor.yy373;
         2325  +  sqlite3SrcListShiftJoinType(yygotominor.yy373);
         2326  +}
         2327  +#line 2330 "parse.c"
  2325   2328           break;
  2326   2329         case 124:
  2327         -#line 452 "parse.y"
         2330  +#line 455 "parse.y"
  2328   2331   {
  2329   2332      yygotominor.yy373 = yymsp[-1].minor.yy373;
  2330   2333      if( yygotominor.yy373 && yygotominor.yy373->nSrc>0 ) yygotominor.yy373->a[yygotominor.yy373->nSrc-1].jointype = yymsp[0].minor.yy46;
  2331   2334   }
  2332         -#line 2335 "parse.c"
         2335  +#line 2338 "parse.c"
  2333   2336           break;
  2334   2337         case 125:
  2335         -#line 456 "parse.y"
         2338  +#line 459 "parse.y"
  2336   2339   {yygotominor.yy373 = 0;}
  2337         -#line 2340 "parse.c"
         2340  +#line 2343 "parse.c"
  2338   2341           break;
  2339   2342         case 126:
  2340         -#line 457 "parse.y"
         2343  +#line 460 "parse.y"
  2341   2344   {
  2342         -  yygotominor.yy373 = sqlite3SrcListAppend(yymsp[-5].minor.yy373,&yymsp[-4].minor.yy410,&yymsp[-3].minor.yy410);
  2343         -  if( yymsp[-2].minor.yy410.n ) sqlite3SrcListAddAlias(yygotominor.yy373,&yymsp[-2].minor.yy410);
  2344         -  if( yymsp[-1].minor.yy172 ){
  2345         -    if( yygotominor.yy373 && yygotominor.yy373->nSrc>1 ){ yygotominor.yy373->a[yygotominor.yy373->nSrc-2].pOn = yymsp[-1].minor.yy172; }
  2346         -    else { sqlite3ExprDelete(yymsp[-1].minor.yy172); }
  2347         -  }
  2348         -  if( yymsp[0].minor.yy432 ){
  2349         -    if( yygotominor.yy373 && yygotominor.yy373->nSrc>1 ){ yygotominor.yy373->a[yygotominor.yy373->nSrc-2].pUsing = yymsp[0].minor.yy432; }
  2350         -    else { sqlite3IdListDelete(yymsp[0].minor.yy432); }
  2351         -  }
         2345  +  yygotominor.yy373 = sqlite3SrcListAppendFromTerm(yymsp[-5].minor.yy373,&yymsp[-4].minor.yy410,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,0,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
  2352   2346   }
  2353         -#line 2356 "parse.c"
         2347  +#line 2350 "parse.c"
  2354   2348           break;
  2355   2349         case 127:
  2356         -#line 471 "parse.y"
         2350  +#line 465 "parse.y"
  2357   2351   {
  2358         -    yygotominor.yy373 = sqlite3SrcListAppend(yymsp[-6].minor.yy373,0,0);
  2359         -    if( yygotominor.yy373 && yygotominor.yy373->nSrc>0 ) yygotominor.yy373->a[yygotominor.yy373->nSrc-1].pSelect = yymsp[-4].minor.yy219;
  2360         -    if( yymsp[-2].minor.yy410.n ) sqlite3SrcListAddAlias(yygotominor.yy373,&yymsp[-2].minor.yy410);
  2361         -    if( yymsp[-1].minor.yy172 ){
  2362         -      if( yygotominor.yy373 && yygotominor.yy373->nSrc>1 ){ yygotominor.yy373->a[yygotominor.yy373->nSrc-2].pOn = yymsp[-1].minor.yy172; }
  2363         -      else { sqlite3ExprDelete(yymsp[-1].minor.yy172); }
  2364         -    }
  2365         -    if( yymsp[0].minor.yy432 ){
  2366         -      if( yygotominor.yy373 && yygotominor.yy373->nSrc>1 ){ yygotominor.yy373->a[yygotominor.yy373->nSrc-2].pUsing = yymsp[0].minor.yy432; }
  2367         -      else { sqlite3IdListDelete(yymsp[0].minor.yy432); }
  2368         -    }
         2352  +    yygotominor.yy373 = sqlite3SrcListAppendFromTerm(yymsp[-6].minor.yy373,0,0,&yymsp[-2].minor.yy410,yymsp[-4].minor.yy219,yymsp[-1].minor.yy172,yymsp[0].minor.yy432);
  2369   2353     }
  2370         -#line 2373 "parse.c"
         2354  +#line 2357 "parse.c"
  2371   2355           break;
  2372   2356         case 129:
  2373         -#line 492 "parse.y"
         2357  +#line 476 "parse.y"
  2374   2358   {
         2359  +     sqlite3SrcListShiftJoinType(yymsp[0].minor.yy373);
  2375   2360        yygotominor.yy219 = sqlite3SelectNew(0,yymsp[0].minor.yy373,0,0,0,0,0,0,0);
  2376   2361     }
         2362  +#line 2365 "parse.c"
         2363  +        break;
         2364  +      case 130:
         2365  +#line 483 "parse.y"
         2366  +{yygotominor.yy410.z=0; yygotominor.yy410.n=0;}
         2367  +#line 2370 "parse.c"
         2368  +        break;
         2369  +      case 132:
         2370  +#line 488 "parse.y"
         2371  +{yygotominor.yy373 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410);}
         2372  +#line 2375 "parse.c"
         2373  +        break;
         2374  +      case 133:
         2375  +#line 492 "parse.y"
         2376  +{ yygotominor.yy46 = JT_INNER; }
  2377   2377   #line 2380 "parse.c"
  2378   2378           break;
  2379         -      case 130:
  2380         -#line 498 "parse.y"
  2381         -{yygotominor.yy410.z=0; yygotominor.yy410.n=0;}
         2379  +      case 134:
         2380  +#line 493 "parse.y"
         2381  +{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
  2382   2382   #line 2385 "parse.c"
  2383   2383           break;
  2384         -      case 132:
  2385         -#line 503 "parse.y"
  2386         -{yygotominor.yy373 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410);}
         2384  +      case 135:
         2385  +#line 494 "parse.y"
         2386  +{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy410,0); }
  2387   2387   #line 2390 "parse.c"
  2388   2388           break;
  2389         -      case 133:
  2390         -#line 507 "parse.y"
  2391         -{ yygotominor.yy46 = JT_INNER; }
  2392         -#line 2395 "parse.c"
  2393         -        break;
  2394         -      case 134:
  2395         -#line 508 "parse.y"
  2396         -{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
  2397         -#line 2400 "parse.c"
  2398         -        break;
  2399         -      case 135:
  2400         -#line 509 "parse.y"
  2401         -{ yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy410,0); }
  2402         -#line 2405 "parse.c"
  2403         -        break;
  2404   2389         case 136:
  2405         -#line 511 "parse.y"
         2390  +#line 496 "parse.y"
  2406   2391   { yygotominor.yy46 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy410,&yymsp[-1].minor.yy410); }
  2407         -#line 2410 "parse.c"
         2392  +#line 2395 "parse.c"
  2408   2393           break;
  2409   2394         case 137:
  2410   2395         case 145:
  2411   2396         case 154:
  2412   2397         case 161:
  2413   2398         case 176:
  2414   2399         case 203:
  2415   2400         case 226:
  2416   2401         case 228:
  2417   2402         case 232:
  2418         -#line 515 "parse.y"
         2403  +#line 500 "parse.y"
  2419   2404   {yygotominor.yy172 = yymsp[0].minor.yy172;}
  2420         -#line 2423 "parse.c"
         2405  +#line 2408 "parse.c"
  2421   2406           break;
  2422   2407         case 138:
  2423   2408         case 153:
  2424   2409         case 160:
  2425   2410         case 204:
  2426   2411         case 227:
  2427   2412         case 229:
  2428   2413         case 233:
  2429         -#line 516 "parse.y"
         2414  +#line 501 "parse.y"
  2430   2415   {yygotominor.yy172 = 0;}
  2431         -#line 2434 "parse.c"
         2416  +#line 2419 "parse.c"
  2432   2417           break;
  2433   2418         case 139:
  2434   2419         case 173:
  2435         -#line 520 "parse.y"
         2420  +#line 505 "parse.y"
  2436   2421   {yygotominor.yy432 = yymsp[-1].minor.yy432;}
  2437         -#line 2440 "parse.c"
         2422  +#line 2425 "parse.c"
  2438   2423           break;
  2439   2424         case 140:
  2440   2425         case 172:
  2441         -#line 521 "parse.y"
         2426  +#line 506 "parse.y"
  2442   2427   {yygotominor.yy432 = 0;}
  2443         -#line 2446 "parse.c"
         2428  +#line 2431 "parse.c"
  2444   2429           break;
  2445   2430         case 142:
  2446   2431         case 152:
  2447         -#line 532 "parse.y"
         2432  +#line 517 "parse.y"
  2448   2433   {yygotominor.yy174 = yymsp[0].minor.yy174;}
  2449         -#line 2452 "parse.c"
         2434  +#line 2437 "parse.c"
  2450   2435           break;
  2451   2436         case 143:
  2452         -#line 533 "parse.y"
         2437  +#line 518 "parse.y"
  2453   2438   {
  2454   2439     yygotominor.yy174 = sqlite3ExprListAppend(yymsp[-4].minor.yy174,yymsp[-2].minor.yy172,yymsp[-1].minor.yy410.n>0?&yymsp[-1].minor.yy410:0);
  2455   2440     if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = yymsp[0].minor.yy46;
  2456   2441   }
  2457         -#line 2460 "parse.c"
         2442  +#line 2445 "parse.c"
  2458   2443           break;
  2459   2444         case 144:
  2460         -#line 537 "parse.y"
         2445  +#line 522 "parse.y"
  2461   2446   {
  2462   2447     yygotominor.yy174 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy172,yymsp[-1].minor.yy410.n>0?&yymsp[-1].minor.yy410:0);
  2463   2448     if( yygotominor.yy174 && yygotominor.yy174->a ) yygotominor.yy174->a[0].sortOrder = yymsp[0].minor.yy46;
  2464   2449   }
  2465         -#line 2468 "parse.c"
         2450  +#line 2453 "parse.c"
  2466   2451           break;
  2467   2452         case 146:
  2468   2453         case 148:
  2469         -#line 546 "parse.y"
         2454  +#line 531 "parse.y"
  2470   2455   {yygotominor.yy46 = SQLITE_SO_ASC;}
  2471         -#line 2474 "parse.c"
         2456  +#line 2459 "parse.c"
  2472   2457           break;
  2473   2458         case 147:
  2474         -#line 547 "parse.y"
         2459  +#line 532 "parse.y"
  2475   2460   {yygotominor.yy46 = SQLITE_SO_DESC;}
  2476         -#line 2479 "parse.c"
         2461  +#line 2464 "parse.c"
  2477   2462           break;
  2478   2463         case 149:
  2479         -#line 549 "parse.y"
         2464  +#line 534 "parse.y"
  2480   2465   {yygotominor.yy410.z = 0; yygotominor.yy410.n = 0;}
  2481         -#line 2484 "parse.c"
         2466  +#line 2469 "parse.c"
  2482   2467           break;
  2483   2468         case 155:
  2484         -#line 567 "parse.y"
         2469  +#line 552 "parse.y"
  2485   2470   {yygotominor.yy234.pLimit = 0; yygotominor.yy234.pOffset = 0;}
  2486         -#line 2489 "parse.c"
         2471  +#line 2474 "parse.c"
  2487   2472           break;
  2488   2473         case 156:
  2489         -#line 568 "parse.y"
         2474  +#line 553 "parse.y"
  2490   2475   {yygotominor.yy234.pLimit = yymsp[0].minor.yy172; yygotominor.yy234.pOffset = 0;}
  2491         -#line 2494 "parse.c"
         2476  +#line 2479 "parse.c"
  2492   2477           break;
  2493   2478         case 157:
  2494         -#line 570 "parse.y"
         2479  +#line 555 "parse.y"
  2495   2480   {yygotominor.yy234.pLimit = yymsp[-2].minor.yy172; yygotominor.yy234.pOffset = yymsp[0].minor.yy172;}
  2496         -#line 2499 "parse.c"
         2481  +#line 2484 "parse.c"
  2497   2482           break;
  2498   2483         case 158:
  2499         -#line 572 "parse.y"
         2484  +#line 557 "parse.y"
  2500   2485   {yygotominor.yy234.pOffset = yymsp[-2].minor.yy172; yygotominor.yy234.pLimit = yymsp[0].minor.yy172;}
  2501         -#line 2504 "parse.c"
         2486  +#line 2489 "parse.c"
  2502   2487           break;
  2503   2488         case 159:
  2504         -#line 576 "parse.y"
         2489  +#line 561 "parse.y"
  2505   2490   {sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy373,yymsp[0].minor.yy172);}
  2506         -#line 2509 "parse.c"
         2491  +#line 2494 "parse.c"
  2507   2492           break;
  2508   2493         case 162:
  2509         -#line 587 "parse.y"
         2494  +#line 572 "parse.y"
  2510   2495   {sqlite3Update(pParse,yymsp[-3].minor.yy373,yymsp[-1].minor.yy174,yymsp[0].minor.yy172,yymsp[-4].minor.yy46);}
  2511         -#line 2514 "parse.c"
         2496  +#line 2499 "parse.c"
  2512   2497           break;
  2513   2498         case 163:
  2514         -#line 593 "parse.y"
         2499  +#line 578 "parse.y"
  2515   2500   {yygotominor.yy174 = sqlite3ExprListAppend(yymsp[-4].minor.yy174,yymsp[0].minor.yy172,&yymsp[-2].minor.yy410);}
  2516         -#line 2519 "parse.c"
         2501  +#line 2504 "parse.c"
  2517   2502           break;
  2518   2503         case 164:
  2519         -#line 594 "parse.y"
         2504  +#line 579 "parse.y"
  2520   2505   {yygotominor.yy174 = sqlite3ExprListAppend(0,yymsp[0].minor.yy172,&yymsp[-2].minor.yy410);}
  2521         -#line 2524 "parse.c"
         2506  +#line 2509 "parse.c"
  2522   2507           break;
  2523   2508         case 165:
  2524         -#line 600 "parse.y"
         2509  +#line 585 "parse.y"
  2525   2510   {sqlite3Insert(pParse, yymsp[-5].minor.yy373, yymsp[-1].minor.yy174, 0, yymsp[-4].minor.yy432, yymsp[-7].minor.yy46);}
  2526         -#line 2529 "parse.c"
         2511  +#line 2514 "parse.c"
  2527   2512           break;
  2528   2513         case 166:
  2529         -#line 602 "parse.y"
         2514  +#line 587 "parse.y"
  2530   2515   {sqlite3Insert(pParse, yymsp[-2].minor.yy373, 0, yymsp[0].minor.yy219, yymsp[-1].minor.yy432, yymsp[-4].minor.yy46);}
  2531         -#line 2534 "parse.c"
         2516  +#line 2519 "parse.c"
  2532   2517           break;
  2533   2518         case 167:
  2534         -#line 604 "parse.y"
         2519  +#line 589 "parse.y"
  2535   2520   {sqlite3Insert(pParse, yymsp[-3].minor.yy373, 0, 0, yymsp[-2].minor.yy432, yymsp[-5].minor.yy46);}
  2536         -#line 2539 "parse.c"
         2521  +#line 2524 "parse.c"
  2537   2522           break;
  2538   2523         case 170:
  2539   2524         case 230:
  2540         -#line 614 "parse.y"
         2525  +#line 599 "parse.y"
  2541   2526   {yygotominor.yy174 = sqlite3ExprListAppend(yymsp[-2].minor.yy174,yymsp[0].minor.yy172,0);}
  2542         -#line 2545 "parse.c"
         2527  +#line 2530 "parse.c"
  2543   2528           break;
  2544   2529         case 171:
  2545   2530         case 231:
  2546         -#line 615 "parse.y"
         2531  +#line 600 "parse.y"
  2547   2532   {yygotominor.yy174 = sqlite3ExprListAppend(0,yymsp[0].minor.yy172,0);}
  2548         -#line 2551 "parse.c"
         2533  +#line 2536 "parse.c"
  2549   2534           break;
  2550   2535         case 174:
  2551         -#line 624 "parse.y"
         2536  +#line 609 "parse.y"
  2552   2537   {yygotominor.yy432 = sqlite3IdListAppend(yymsp[-2].minor.yy432,&yymsp[0].minor.yy410);}
  2553         -#line 2556 "parse.c"
         2538  +#line 2541 "parse.c"
  2554   2539           break;
  2555   2540         case 175:
  2556         -#line 625 "parse.y"
         2541  +#line 610 "parse.y"
  2557   2542   {yygotominor.yy432 = sqlite3IdListAppend(0,&yymsp[0].minor.yy410);}
  2558         -#line 2561 "parse.c"
         2543  +#line 2546 "parse.c"
  2559   2544           break;
  2560   2545         case 177:
  2561         -#line 636 "parse.y"
         2546  +#line 621 "parse.y"
  2562   2547   {yygotominor.yy172 = yymsp[-1].minor.yy172; sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
  2563         -#line 2566 "parse.c"
         2548  +#line 2551 "parse.c"
  2564   2549           break;
  2565   2550         case 178:
  2566   2551         case 183:
  2567   2552         case 184:
  2568         -#line 637 "parse.y"
         2553  +#line 622 "parse.y"
  2569   2554   {yygotominor.yy172 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
  2570         -#line 2573 "parse.c"
         2555  +#line 2558 "parse.c"
  2571   2556           break;
  2572   2557         case 179:
  2573   2558         case 180:
  2574         -#line 638 "parse.y"
         2559  +#line 623 "parse.y"
  2575   2560   {yygotominor.yy172 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);}
  2576         -#line 2579 "parse.c"
         2561  +#line 2564 "parse.c"
  2577   2562           break;
  2578   2563         case 181:
  2579         -#line 640 "parse.y"
         2564  +#line 625 "parse.y"
  2580   2565   {
  2581   2566     Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy410);
  2582   2567     Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy410);
  2583   2568     yygotominor.yy172 = sqlite3Expr(TK_DOT, temp1, temp2, 0);
  2584   2569   }
  2585         -#line 2588 "parse.c"
         2570  +#line 2573 "parse.c"
  2586   2571           break;
  2587   2572         case 182:
  2588         -#line 645 "parse.y"
         2573  +#line 630 "parse.y"
  2589   2574   {
  2590   2575     Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy410);
  2591   2576     Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy410);
  2592   2577     Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy410);
  2593   2578     Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
  2594   2579     yygotominor.yy172 = sqlite3Expr(TK_DOT, temp1, temp4, 0);
  2595   2580   }
  2596         -#line 2599 "parse.c"
         2581  +#line 2584 "parse.c"
  2597   2582           break;
  2598   2583         case 185:
  2599         -#line 654 "parse.y"
         2584  +#line 639 "parse.y"
  2600   2585   {yygotominor.yy172 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
  2601         -#line 2604 "parse.c"
         2586  +#line 2589 "parse.c"
  2602   2587           break;
  2603   2588         case 186:
  2604         -#line 655 "parse.y"
         2589  +#line 640 "parse.y"
  2605   2590   {
  2606   2591     Token *pToken = &yymsp[0].minor.yy0;
  2607   2592     Expr *pExpr = yygotominor.yy172 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
  2608   2593     sqlite3ExprAssignVarNumber(pParse, pExpr);
  2609   2594   }
  2610         -#line 2613 "parse.c"
         2595  +#line 2598 "parse.c"
  2611   2596           break;
  2612   2597         case 187:
  2613         -#line 661 "parse.y"
         2598  +#line 646 "parse.y"
  2614   2599   {
  2615   2600     yygotominor.yy172 = sqlite3Expr(TK_CAST, yymsp[-3].minor.yy172, 0, &yymsp[-1].minor.yy410);
  2616   2601     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
  2617   2602   }
  2618         -#line 2621 "parse.c"
         2603  +#line 2606 "parse.c"
  2619   2604           break;
  2620   2605         case 188:
  2621         -#line 666 "parse.y"
         2606  +#line 651 "parse.y"
  2622   2607   {
  2623   2608     yygotominor.yy172 = sqlite3ExprFunction(yymsp[-1].minor.yy174, &yymsp[-4].minor.yy0);
  2624   2609     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
  2625   2610     if( yymsp[-2].minor.yy46 && yygotominor.yy172 ){
  2626   2611       yygotominor.yy172->flags |= EP_Distinct;
  2627   2612     }
  2628   2613   }
  2629         -#line 2632 "parse.c"
         2614  +#line 2617 "parse.c"
  2630   2615           break;
  2631   2616         case 189:
  2632         -#line 673 "parse.y"
         2617  +#line 658 "parse.y"
  2633   2618   {
  2634   2619     yygotominor.yy172 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0);
  2635   2620     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
  2636   2621   }
  2637         -#line 2640 "parse.c"
         2622  +#line 2625 "parse.c"
  2638   2623           break;
  2639   2624         case 190:
  2640         -#line 677 "parse.y"
         2625  +#line 662 "parse.y"
  2641   2626   {
  2642   2627     /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
  2643   2628     ** treated as functions that return constants */
  2644   2629     yygotominor.yy172 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0);
  2645   2630     if( yygotominor.yy172 ){
  2646   2631       yygotominor.yy172->op = TK_CONST_FUNC;  
  2647   2632       yygotominor.yy172->span = yymsp[0].minor.yy0;
  2648   2633     }
  2649   2634   }
  2650         -#line 2653 "parse.c"
         2635  +#line 2638 "parse.c"
  2651   2636           break;
  2652   2637         case 191:
  2653   2638         case 192:
  2654   2639         case 193:
  2655   2640         case 194:
  2656   2641         case 195:
  2657   2642         case 196:
  2658   2643         case 197:
  2659   2644         case 198:
  2660         -#line 686 "parse.y"
         2645  +#line 671 "parse.y"
  2661   2646   {yygotominor.yy172 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy172, yymsp[0].minor.yy172, 0);}
  2662         -#line 2665 "parse.c"
         2647  +#line 2650 "parse.c"
  2663   2648           break;
  2664   2649         case 199:
  2665   2650         case 201:
  2666         -#line 696 "parse.y"
         2651  +#line 681 "parse.y"
  2667   2652   {yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 0;}
  2668         -#line 2671 "parse.c"
         2653  +#line 2656 "parse.c"
  2669   2654           break;
  2670   2655         case 200:
  2671   2656         case 202:
  2672         -#line 697 "parse.y"
         2657  +#line 682 "parse.y"
  2673   2658   {yygotominor.yy72.eOperator = yymsp[0].minor.yy0; yygotominor.yy72.not = 1;}
  2674         -#line 2677 "parse.c"
         2659  +#line 2662 "parse.c"
  2675   2660           break;
  2676   2661         case 205:
  2677         -#line 704 "parse.y"
         2662  +#line 689 "parse.y"
  2678   2663   {
  2679   2664     ExprList *pList;
  2680   2665     pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy172, 0);
  2681   2666     pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy172, 0);
  2682   2667     if( yymsp[0].minor.yy172 ){
  2683   2668       pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy172, 0);
  2684   2669     }
  2685   2670     yygotominor.yy172 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy72.eOperator);
  2686   2671     if( yymsp[-2].minor.yy72.not ) yygotominor.yy172 = sqlite3Expr(TK_NOT, yygotominor.yy172, 0, 0);
  2687   2672     sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy172->span, &yymsp[-1].minor.yy172->span);
  2688   2673     if( yygotominor.yy172 ) yygotominor.yy172->flags |= EP_InfixFunc;
  2689   2674   }
  2690         -#line 2693 "parse.c"
         2675  +#line 2678 "parse.c"
  2691   2676           break;
  2692   2677         case 206:
  2693         -#line 717 "parse.y"
         2678  +#line 702 "parse.y"
  2694   2679   {
  2695   2680     yygotominor.yy172 = sqlite3Expr(yymsp[0].major, yymsp[-1].minor.yy172, 0, 0);
  2696   2681     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy172->span,&yymsp[0].minor.yy0);
  2697   2682   }
  2698         -#line 2701 "parse.c"
         2683  +#line 2686 "parse.c"
  2699   2684           break;
  2700   2685         case 207:
  2701         -#line 721 "parse.y"
         2686  +#line 706 "parse.y"
  2702   2687   {
  2703   2688     yygotominor.yy172 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy172, 0, 0);
  2704   2689     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0);
  2705   2690   }
  2706         -#line 2709 "parse.c"
         2691  +#line 2694 "parse.c"
  2707   2692           break;
  2708   2693         case 208:
  2709         -#line 725 "parse.y"
         2694  +#line 710 "parse.y"
  2710   2695   {
  2711   2696     yygotominor.yy172 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy172, 0, 0);
  2712   2697     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy172->span,&yymsp[0].minor.yy0);
  2713   2698   }
  2714         -#line 2717 "parse.c"
         2699  +#line 2702 "parse.c"
  2715   2700           break;
  2716   2701         case 209:
  2717         -#line 729 "parse.y"
         2702  +#line 714 "parse.y"
  2718   2703   {
  2719   2704     yygotominor.yy172 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy172, 0, 0);
  2720   2705     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,&yymsp[0].minor.yy0);
  2721   2706   }
  2722         -#line 2725 "parse.c"
         2707  +#line 2710 "parse.c"
  2723   2708           break;
  2724   2709         case 210:
  2725         -#line 733 "parse.y"
         2710  +#line 718 "parse.y"
  2726   2711   {
  2727   2712     yygotominor.yy172 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy172, 0, 0);
  2728   2713     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
  2729   2714   }
  2730         -#line 2733 "parse.c"
         2715  +#line 2718 "parse.c"
  2731   2716           break;
  2732   2717         case 211:
  2733         -#line 737 "parse.y"
         2718  +#line 722 "parse.y"
  2734   2719   {
  2735   2720     yygotominor.yy172 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy172, 0, 0);
  2736   2721     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
  2737   2722   }
  2738         -#line 2741 "parse.c"
         2723  +#line 2726 "parse.c"
  2739   2724           break;
  2740   2725         case 212:
  2741         -#line 741 "parse.y"
         2726  +#line 726 "parse.y"
  2742   2727   {
  2743   2728     yygotominor.yy172 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy172, 0, 0);
  2744   2729     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy172->span);
  2745   2730   }
  2746         -#line 2749 "parse.c"
         2731  +#line 2734 "parse.c"
  2747   2732           break;
  2748   2733         case 215:
  2749         -#line 748 "parse.y"
         2734  +#line 733 "parse.y"
  2750   2735   {
  2751   2736     ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy172, 0);
  2752   2737     pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy172, 0);
  2753   2738     yygotominor.yy172 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy172, 0, 0);
  2754   2739     if( yygotominor.yy172 ){
  2755   2740       yygotominor.yy172->pList = pList;
  2756   2741     }else{
  2757   2742       sqlite3ExprListDelete(pList);
  2758   2743     } 
  2759   2744     if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3Expr(TK_NOT, yygotominor.yy172, 0, 0);
  2760   2745     sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy172->span);
  2761   2746   }
  2762         -#line 2765 "parse.c"
         2747  +#line 2750 "parse.c"
  2763   2748           break;
  2764   2749         case 218:
  2765         -#line 764 "parse.y"
         2750  +#line 749 "parse.y"
  2766   2751   {
  2767   2752       yygotominor.yy172 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy172, 0, 0);
  2768   2753       if( yygotominor.yy172 ){
  2769   2754         yygotominor.yy172->pList = yymsp[-1].minor.yy174;
  2770   2755       }else{
  2771   2756         sqlite3ExprListDelete(yymsp[-1].minor.yy174);
  2772   2757       }
  2773   2758       if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3Expr(TK_NOT, yygotominor.yy172, 0, 0);
  2774   2759       sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0);
  2775   2760     }
  2776         -#line 2779 "parse.c"
         2761  +#line 2764 "parse.c"
  2777   2762           break;
  2778   2763         case 219:
  2779         -#line 774 "parse.y"
         2764  +#line 759 "parse.y"
  2780   2765   {
  2781   2766       yygotominor.yy172 = sqlite3Expr(TK_SELECT, 0, 0, 0);
  2782   2767       if( yygotominor.yy172 ){
  2783   2768         yygotominor.yy172->pSelect = yymsp[-1].minor.yy219;
  2784   2769       }else{
  2785   2770         sqlite3SelectDelete(yymsp[-1].minor.yy219);
  2786   2771       }
  2787   2772       sqlite3ExprSpan(yygotominor.yy172,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
  2788   2773     }
  2789         -#line 2792 "parse.c"
         2774  +#line 2777 "parse.c"
  2790   2775           break;
  2791   2776         case 220:
  2792         -#line 783 "parse.y"
         2777  +#line 768 "parse.y"
  2793   2778   {
  2794   2779       yygotominor.yy172 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy172, 0, 0);
  2795   2780       if( yygotominor.yy172 ){
  2796   2781         yygotominor.yy172->pSelect = yymsp[-1].minor.yy219;
  2797   2782       }else{
  2798   2783         sqlite3SelectDelete(yymsp[-1].minor.yy219);
  2799   2784       }
  2800   2785       if( yymsp[-3].minor.yy46 ) yygotominor.yy172 = sqlite3Expr(TK_NOT, yygotominor.yy172, 0, 0);
  2801   2786       sqlite3ExprSpan(yygotominor.yy172,&yymsp[-4].minor.yy172->span,&yymsp[0].minor.yy0);
  2802   2787     }
  2803         -#line 2806 "parse.c"
         2788  +#line 2791 "parse.c"
  2804   2789           break;
  2805   2790         case 221:
  2806         -#line 793 "parse.y"
         2791  +#line 778 "parse.y"
  2807   2792   {
  2808   2793       SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410);
  2809   2794       yygotominor.yy172 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy172, 0, 0);
  2810   2795       if( yygotominor.yy172 ){
  2811   2796         yygotominor.yy172->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
  2812   2797       }else{
  2813   2798         sqlite3SrcListDelete(pSrc);
  2814   2799       }
  2815   2800       if( yymsp[-2].minor.yy46 ) yygotominor.yy172 = sqlite3Expr(TK_NOT, yygotominor.yy172, 0, 0);
  2816   2801       sqlite3ExprSpan(yygotominor.yy172,&yymsp[-3].minor.yy172->span,yymsp[0].minor.yy410.z?&yymsp[0].minor.yy410:&yymsp[-1].minor.yy410);
  2817   2802     }
  2818         -#line 2821 "parse.c"
         2803  +#line 2806 "parse.c"
  2819   2804           break;
  2820   2805         case 222:
  2821         -#line 804 "parse.y"
         2806  +#line 789 "parse.y"
  2822   2807   {
  2823   2808       Expr *p = yygotominor.yy172 = sqlite3Expr(TK_EXISTS, 0, 0, 0);
  2824   2809       if( p ){
  2825   2810         p->pSelect = yymsp[-1].minor.yy219;
  2826   2811         sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
  2827   2812       }else{
  2828   2813         sqlite3SelectDelete(yymsp[-1].minor.yy219);
  2829   2814       }
  2830   2815     }
  2831         -#line 2834 "parse.c"
         2816  +#line 2819 "parse.c"
  2832   2817           break;
  2833   2818         case 223:
  2834         -#line 816 "parse.y"
         2819  +#line 801 "parse.y"
  2835   2820   {
  2836   2821     yygotominor.yy172 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, 0);
  2837   2822     if( yygotominor.yy172 ){
  2838   2823       yygotominor.yy172->pList = yymsp[-2].minor.yy174;
  2839   2824     }else{
  2840   2825       sqlite3ExprListDelete(yymsp[-2].minor.yy174);
  2841   2826     }
  2842   2827     sqlite3ExprSpan(yygotominor.yy172, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
  2843   2828   }
  2844         -#line 2847 "parse.c"
         2829  +#line 2832 "parse.c"
  2845   2830           break;
  2846   2831         case 224:
  2847         -#line 827 "parse.y"
         2832  +#line 812 "parse.y"
  2848   2833   {
  2849   2834     yygotominor.yy174 = sqlite3ExprListAppend(yymsp[-4].minor.yy174, yymsp[-2].minor.yy172, 0);
  2850   2835     yygotominor.yy174 = sqlite3ExprListAppend(yygotominor.yy174, yymsp[0].minor.yy172, 0);
  2851   2836   }
  2852         -#line 2855 "parse.c"
         2837  +#line 2840 "parse.c"
  2853   2838           break;
  2854   2839         case 225:
  2855         -#line 831 "parse.y"
         2840  +#line 816 "parse.y"
  2856   2841   {
  2857   2842     yygotominor.yy174 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy172, 0);
  2858   2843     yygotominor.yy174 = sqlite3ExprListAppend(yygotominor.yy174, yymsp[0].minor.yy172, 0);
  2859   2844   }
  2860         -#line 2863 "parse.c"
         2845  +#line 2848 "parse.c"
  2861   2846           break;
  2862   2847         case 234:
  2863         -#line 858 "parse.y"
         2848  +#line 843 "parse.y"
  2864   2849   {
  2865   2850     sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy410, &yymsp[-5].minor.yy410, sqlite3SrcListAppend(0,&yymsp[-3].minor.yy410,0), yymsp[-1].minor.yy174, yymsp[-9].minor.yy46,
  2866   2851                         &yymsp[-10].minor.yy0, &yymsp[0].minor.yy0, SQLITE_SO_ASC, yymsp[-7].minor.yy46);
  2867   2852   }
  2868         -#line 2871 "parse.c"
         2853  +#line 2856 "parse.c"
  2869   2854           break;
  2870   2855         case 235:
  2871   2856         case 280:
  2872         -#line 864 "parse.y"
         2857  +#line 849 "parse.y"
  2873   2858   {yygotominor.yy46 = OE_Abort;}
  2874         -#line 2877 "parse.c"
         2859  +#line 2862 "parse.c"
  2875   2860           break;
  2876   2861         case 236:
  2877         -#line 865 "parse.y"
         2862  +#line 850 "parse.y"
  2878   2863   {yygotominor.yy46 = OE_None;}
  2879         -#line 2882 "parse.c"
         2864  +#line 2867 "parse.c"
  2880   2865           break;
  2881   2866         case 239:
  2882         -#line 875 "parse.y"
         2867  +#line 860 "parse.y"
  2883   2868   {
  2884   2869     Expr *p = 0;
  2885   2870     if( yymsp[-1].minor.yy410.n>0 ){
  2886   2871       p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
  2887   2872       if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)yymsp[-1].minor.yy410.z, yymsp[-1].minor.yy410.n);
  2888   2873     }
  2889   2874     yygotominor.yy174 = sqlite3ExprListAppend(yymsp[-4].minor.yy174, p, &yymsp[-2].minor.yy410);
  2890   2875     if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = yymsp[0].minor.yy46;
  2891   2876   }
  2892         -#line 2895 "parse.c"
         2877  +#line 2880 "parse.c"
  2893   2878           break;
  2894   2879         case 240:
  2895         -#line 884 "parse.y"
         2880  +#line 869 "parse.y"
  2896   2881   {
  2897   2882     Expr *p = 0;
  2898   2883     if( yymsp[-1].minor.yy410.n>0 ){
  2899   2884       p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
  2900   2885       if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)yymsp[-1].minor.yy410.z, yymsp[-1].minor.yy410.n);
  2901   2886     }
  2902   2887     yygotominor.yy174 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy410);
  2903   2888     if( yygotominor.yy174 ) yygotominor.yy174->a[yygotominor.yy174->nExpr-1].sortOrder = yymsp[0].minor.yy46;
  2904   2889   }
  2905         -#line 2908 "parse.c"
         2890  +#line 2893 "parse.c"
  2906   2891           break;
  2907   2892         case 242:
  2908         -#line 898 "parse.y"
         2893  +#line 883 "parse.y"
  2909   2894   {sqlite3DropIndex(pParse, yymsp[0].minor.yy373, yymsp[-1].minor.yy46);}
  2910         -#line 2913 "parse.c"
         2895  +#line 2898 "parse.c"
  2911   2896           break;
  2912   2897         case 243:
  2913   2898         case 244:
  2914         -#line 903 "parse.y"
         2899  +#line 888 "parse.y"
  2915   2900   {sqlite3Vacuum(pParse);}
  2916         -#line 2919 "parse.c"
         2901  +#line 2904 "parse.c"
  2917   2902           break;
  2918   2903         case 245:
  2919   2904         case 247:
  2920         -#line 910 "parse.y"
         2905  +#line 895 "parse.y"
  2921   2906   {sqlite3Pragma(pParse,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,&yymsp[0].minor.yy410,0);}
  2922         -#line 2925 "parse.c"
         2907  +#line 2910 "parse.c"
  2923   2908           break;
  2924   2909         case 246:
  2925         -#line 911 "parse.y"
         2910  +#line 896 "parse.y"
  2926   2911   {sqlite3Pragma(pParse,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,&yymsp[0].minor.yy0,0);}
  2927         -#line 2930 "parse.c"
         2912  +#line 2915 "parse.c"
  2928   2913           break;
  2929   2914         case 248:
  2930         -#line 913 "parse.y"
         2915  +#line 898 "parse.y"
  2931   2916   {
  2932   2917     sqlite3Pragma(pParse,&yymsp[-3].minor.yy410,&yymsp[-2].minor.yy410,&yymsp[0].minor.yy410,1);
  2933   2918   }
  2934         -#line 2937 "parse.c"
         2919  +#line 2922 "parse.c"
  2935   2920           break;
  2936   2921         case 249:
  2937         -#line 916 "parse.y"
         2922  +#line 901 "parse.y"
  2938   2923   {sqlite3Pragma(pParse,&yymsp[-4].minor.yy410,&yymsp[-3].minor.yy410,&yymsp[-1].minor.yy410,0);}
  2939         -#line 2942 "parse.c"
         2924  +#line 2927 "parse.c"
  2940   2925           break;
  2941   2926         case 250:
  2942         -#line 917 "parse.y"
         2927  +#line 902 "parse.y"
  2943   2928   {sqlite3Pragma(pParse,&yymsp[-1].minor.yy410,&yymsp[0].minor.yy410,0,0);}
  2944         -#line 2947 "parse.c"
         2929  +#line 2932 "parse.c"
  2945   2930           break;
  2946   2931         case 256:
  2947         -#line 929 "parse.y"
         2932  +#line 914 "parse.y"
  2948   2933   {
  2949   2934     Token all;
  2950   2935     all.z = yymsp[-3].minor.yy410.z;
  2951   2936     all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy410.z) + yymsp[0].minor.yy0.n;
  2952   2937     sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy243, &all);
  2953   2938   }
  2954         -#line 2957 "parse.c"
         2939  +#line 2942 "parse.c"
  2955   2940           break;
  2956   2941         case 257:
  2957         -#line 938 "parse.y"
         2942  +#line 923 "parse.y"
  2958   2943   {
  2959   2944     sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy410, &yymsp[-6].minor.yy410, yymsp[-5].minor.yy46, yymsp[-4].minor.yy370.a, yymsp[-4].minor.yy370.b, yymsp[-2].minor.yy373, yymsp[-1].minor.yy46, yymsp[0].minor.yy172, yymsp[-10].minor.yy46, yymsp[-8].minor.yy46);
  2960   2945     yygotominor.yy410 = (yymsp[-6].minor.yy410.n==0?yymsp[-7].minor.yy410:yymsp[-6].minor.yy410);
  2961   2946   }
  2962         -#line 2965 "parse.c"
         2947  +#line 2950 "parse.c"
  2963   2948           break;
  2964   2949         case 258:
  2965   2950         case 261:
  2966         -#line 944 "parse.y"
         2951  +#line 929 "parse.y"
  2967   2952   { yygotominor.yy46 = TK_BEFORE; }
  2968         -#line 2971 "parse.c"
         2953  +#line 2956 "parse.c"
  2969   2954           break;
  2970   2955         case 259:
  2971         -#line 945 "parse.y"
         2956  +#line 930 "parse.y"
  2972   2957   { yygotominor.yy46 = TK_AFTER;  }
  2973         -#line 2976 "parse.c"
         2958  +#line 2961 "parse.c"
  2974   2959           break;
  2975   2960         case 260:
  2976         -#line 946 "parse.y"
         2961  +#line 931 "parse.y"
  2977   2962   { yygotominor.yy46 = TK_INSTEAD;}
  2978         -#line 2981 "parse.c"
         2963  +#line 2966 "parse.c"
  2979   2964           break;
  2980   2965         case 262:
  2981   2966         case 263:
  2982         -#line 951 "parse.y"
         2967  +#line 936 "parse.y"
  2983   2968   {yygotominor.yy370.a = yymsp[0].major; yygotominor.yy370.b = 0;}
  2984         -#line 2987 "parse.c"
         2969  +#line 2972 "parse.c"
  2985   2970           break;
  2986   2971         case 264:
  2987         -#line 953 "parse.y"
         2972  +#line 938 "parse.y"
  2988   2973   {yygotominor.yy370.a = TK_UPDATE; yygotominor.yy370.b = yymsp[0].minor.yy432;}
  2989         -#line 2992 "parse.c"
         2974  +#line 2977 "parse.c"
  2990   2975           break;
  2991   2976         case 265:
  2992   2977         case 266:
  2993         -#line 956 "parse.y"
         2978  +#line 941 "parse.y"
  2994   2979   { yygotominor.yy46 = TK_ROW; }
  2995         -#line 2998 "parse.c"
         2980  +#line 2983 "parse.c"
  2996   2981           break;
  2997   2982         case 267:
  2998         -#line 958 "parse.y"
         2983  +#line 943 "parse.y"
  2999   2984   { yygotominor.yy46 = TK_STATEMENT; }
  3000         -#line 3003 "parse.c"
         2985  +#line 2988 "parse.c"
  3001   2986           break;
  3002   2987         case 268:
  3003         -#line 962 "parse.y"
         2988  +#line 947 "parse.y"
  3004   2989   { yygotominor.yy172 = 0; }
  3005         -#line 3008 "parse.c"
         2990  +#line 2993 "parse.c"
  3006   2991           break;
  3007   2992         case 269:
  3008         -#line 963 "parse.y"
         2993  +#line 948 "parse.y"
  3009   2994   { yygotominor.yy172 = yymsp[0].minor.yy172; }
  3010         -#line 3013 "parse.c"
         2995  +#line 2998 "parse.c"
  3011   2996           break;
  3012   2997         case 270:
  3013         -#line 967 "parse.y"
         2998  +#line 952 "parse.y"
  3014   2999   {
  3015   3000     if( yymsp[-2].minor.yy243 ){
  3016   3001       yymsp[-2].minor.yy243->pLast->pNext = yymsp[-1].minor.yy243;
  3017   3002     }else{
  3018   3003       yymsp[-2].minor.yy243 = yymsp[-1].minor.yy243;
  3019   3004     }
  3020   3005     yymsp[-2].minor.yy243->pLast = yymsp[-1].minor.yy243;
  3021   3006     yygotominor.yy243 = yymsp[-2].minor.yy243;
  3022   3007   }
  3023         -#line 3026 "parse.c"
         3008  +#line 3011 "parse.c"
  3024   3009           break;
  3025   3010         case 271:
  3026         -#line 976 "parse.y"
         3011  +#line 961 "parse.y"
  3027   3012   { yygotominor.yy243 = 0; }
  3028         -#line 3031 "parse.c"
         3013  +#line 3016 "parse.c"
  3029   3014           break;
  3030   3015         case 272:
  3031         -#line 982 "parse.y"
         3016  +#line 967 "parse.y"
  3032   3017   { yygotominor.yy243 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy410, yymsp[-1].minor.yy174, yymsp[0].minor.yy172, yymsp[-4].minor.yy46); }
  3033         -#line 3036 "parse.c"
         3018  +#line 3021 "parse.c"
  3034   3019           break;
  3035   3020         case 273:
  3036         -#line 987 "parse.y"
         3021  +#line 972 "parse.y"
  3037   3022   {yygotominor.yy243 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy410, yymsp[-4].minor.yy432, yymsp[-1].minor.yy174, 0, yymsp[-7].minor.yy46);}
  3038         -#line 3041 "parse.c"
         3023  +#line 3026 "parse.c"
  3039   3024           break;
  3040   3025         case 274:
  3041         -#line 990 "parse.y"
         3026  +#line 975 "parse.y"
  3042   3027   {yygotominor.yy243 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy410, yymsp[-1].minor.yy432, 0, yymsp[0].minor.yy219, yymsp[-4].minor.yy46);}
  3043         -#line 3046 "parse.c"
         3028  +#line 3031 "parse.c"
  3044   3029           break;
  3045   3030         case 275:
  3046         -#line 994 "parse.y"
         3031  +#line 979 "parse.y"
  3047   3032   {yygotominor.yy243 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy410, yymsp[0].minor.yy172);}
  3048         -#line 3051 "parse.c"
         3033  +#line 3036 "parse.c"
  3049   3034           break;
  3050   3035         case 276:
  3051         -#line 997 "parse.y"
         3036  +#line 982 "parse.y"
  3052   3037   {yygotominor.yy243 = sqlite3TriggerSelectStep(yymsp[0].minor.yy219); }
  3053         -#line 3056 "parse.c"
         3038  +#line 3041 "parse.c"
  3054   3039           break;
  3055   3040         case 277:
  3056         -#line 1000 "parse.y"
         3041  +#line 985 "parse.y"
  3057   3042   {
  3058   3043     yygotominor.yy172 = sqlite3Expr(TK_RAISE, 0, 0, 0); 
  3059   3044     if( yygotominor.yy172 ){
  3060   3045       yygotominor.yy172->iColumn = OE_Ignore;
  3061   3046       sqlite3ExprSpan(yygotominor.yy172, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
  3062   3047     }
  3063   3048   }
  3064         -#line 3067 "parse.c"
         3049  +#line 3052 "parse.c"
  3065   3050           break;
  3066   3051         case 278:
  3067         -#line 1007 "parse.y"
         3052  +#line 992 "parse.y"
  3068   3053   {
  3069   3054     yygotominor.yy172 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy410); 
  3070   3055     if( yygotominor.yy172 ) {
  3071   3056       yygotominor.yy172->iColumn = yymsp[-3].minor.yy46;
  3072   3057       sqlite3ExprSpan(yygotominor.yy172, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
  3073   3058     }
  3074   3059   }
  3075         -#line 3078 "parse.c"
         3060  +#line 3063 "parse.c"
  3076   3061           break;
  3077   3062         case 279:
  3078         -#line 1017 "parse.y"
         3063  +#line 1002 "parse.y"
  3079   3064   {yygotominor.yy46 = OE_Rollback;}
  3080         -#line 3083 "parse.c"
         3065  +#line 3068 "parse.c"
  3081   3066           break;
  3082   3067         case 281:
  3083         -#line 1019 "parse.y"
         3068  +#line 1004 "parse.y"
  3084   3069   {yygotominor.yy46 = OE_Fail;}
  3085         -#line 3088 "parse.c"
         3070  +#line 3073 "parse.c"
  3086   3071           break;
  3087   3072         case 282:
  3088         -#line 1024 "parse.y"
         3073  +#line 1009 "parse.y"
  3089   3074   {
  3090   3075     sqlite3DropTrigger(pParse,yymsp[0].minor.yy373,yymsp[-1].minor.yy46);
  3091   3076   }
  3092         -#line 3095 "parse.c"
         3077  +#line 3080 "parse.c"
  3093   3078           break;
  3094   3079         case 283:
  3095         -#line 1030 "parse.y"
         3080  +#line 1015 "parse.y"
  3096   3081   {
  3097   3082     sqlite3Attach(pParse, yymsp[-3].minor.yy172, yymsp[-1].minor.yy172, yymsp[0].minor.yy386);
  3098   3083   }
  3099         -#line 3102 "parse.c"
         3084  +#line 3087 "parse.c"
  3100   3085           break;
  3101   3086         case 284:
  3102         -#line 1035 "parse.y"
         3087  +#line 1020 "parse.y"
  3103   3088   { yygotominor.yy386 = 0; }
  3104         -#line 3107 "parse.c"
         3089  +#line 3092 "parse.c"
  3105   3090           break;
  3106   3091         case 285:
  3107         -#line 1036 "parse.y"
         3092  +#line 1021 "parse.y"
  3108   3093   { yygotominor.yy386 = yymsp[0].minor.yy172; }
  3109         -#line 3112 "parse.c"
         3094  +#line 3097 "parse.c"
  3110   3095           break;
  3111   3096         case 288:
  3112         -#line 1042 "parse.y"
         3097  +#line 1027 "parse.y"
  3113   3098   {
  3114   3099     sqlite3Detach(pParse, yymsp[0].minor.yy172);
  3115   3100   }
  3116         -#line 3119 "parse.c"
         3101  +#line 3104 "parse.c"
  3117   3102           break;
  3118   3103         case 289:
  3119         -#line 1048 "parse.y"
         3104  +#line 1033 "parse.y"
  3120   3105   {sqlite3Reindex(pParse, 0, 0);}
  3121         -#line 3124 "parse.c"
         3106  +#line 3109 "parse.c"
  3122   3107           break;
  3123   3108         case 290:
  3124         -#line 1049 "parse.y"
         3109  +#line 1034 "parse.y"
  3125   3110   {sqlite3Reindex(pParse, &yymsp[-1].minor.yy410, &yymsp[0].minor.yy410);}
  3126         -#line 3129 "parse.c"
         3111  +#line 3114 "parse.c"
  3127   3112           break;
  3128   3113         case 291:
  3129         -#line 1054 "parse.y"
         3114  +#line 1039 "parse.y"
  3130   3115   {sqlite3Analyze(pParse, 0, 0);}
  3131         -#line 3134 "parse.c"
         3116  +#line 3119 "parse.c"
  3132   3117           break;
  3133   3118         case 292:
  3134         -#line 1055 "parse.y"
         3119  +#line 1040 "parse.y"
  3135   3120   {sqlite3Analyze(pParse, &yymsp[-1].minor.yy410, &yymsp[0].minor.yy410);}
  3136         -#line 3139 "parse.c"
         3121  +#line 3124 "parse.c"
  3137   3122           break;
  3138   3123         case 293:
  3139         -#line 1060 "parse.y"
         3124  +#line 1045 "parse.y"
  3140   3125   {
  3141   3126     sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy373,&yymsp[0].minor.yy410);
  3142   3127   }
  3143         -#line 3146 "parse.c"
         3128  +#line 3131 "parse.c"
  3144   3129           break;
  3145   3130         case 294:
  3146         -#line 1063 "parse.y"
         3131  +#line 1048 "parse.y"
  3147   3132   {
  3148   3133     sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy410);
  3149   3134   }
  3150         -#line 3153 "parse.c"
         3135  +#line 3138 "parse.c"
  3151   3136           break;
  3152   3137         case 295:
  3153         -#line 1066 "parse.y"
         3138  +#line 1051 "parse.y"
  3154   3139   {
  3155   3140     sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy373);
  3156   3141   }
  3157         -#line 3160 "parse.c"
         3142  +#line 3145 "parse.c"
  3158   3143           break;
  3159   3144         case 298:
  3160         -#line 1075 "parse.y"
         3145  +#line 1060 "parse.y"
  3161   3146   {sqlite3VtabFinishParse(pParse,0);}
  3162         -#line 3165 "parse.c"
         3147  +#line 3150 "parse.c"
  3163   3148           break;
  3164   3149         case 299:
  3165         -#line 1076 "parse.y"
         3150  +#line 1061 "parse.y"
  3166   3151   {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
  3167         -#line 3170 "parse.c"
         3152  +#line 3155 "parse.c"
  3168   3153           break;
  3169   3154         case 300:
  3170         -#line 1077 "parse.y"
         3155  +#line 1062 "parse.y"
  3171   3156   {
  3172   3157       sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy410, &yymsp[-2].minor.yy410, &yymsp[0].minor.yy410);
  3173   3158   }
  3174         -#line 3177 "parse.c"
         3159  +#line 3162 "parse.c"
  3175   3160           break;
  3176   3161         case 303:
  3177         -#line 1082 "parse.y"
         3162  +#line 1067 "parse.y"
  3178   3163   {sqlite3VtabArgInit(pParse);}
  3179         -#line 3182 "parse.c"
         3164  +#line 3167 "parse.c"
  3180   3165           break;
  3181   3166         case 305:
  3182   3167         case 306:
  3183   3168         case 307:
  3184   3169         case 309:
  3185         -#line 1084 "parse.y"
         3170  +#line 1069 "parse.y"
  3186   3171   {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
  3187         -#line 3190 "parse.c"
         3172  +#line 3175 "parse.c"
  3188   3173           break;
  3189   3174     };
  3190   3175     yygoto = yyRuleInfo[yyruleno].lhs;
  3191   3176     yysize = yyRuleInfo[yyruleno].nrhs;
  3192   3177     yypParser->yyidx -= yysize;
  3193   3178     yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto);
  3194   3179     if( yyact < YYNSTATE ){
................................................................................
  3247   3232       if( TOKEN.z[0] ){
  3248   3233         sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
  3249   3234       }else{
  3250   3235         sqlite3ErrorMsg(pParse, "incomplete SQL statement");
  3251   3236       }
  3252   3237       pParse->parseError = 1;
  3253   3238     }
  3254         -#line 3258 "parse.c"
         3239  +#line 3243 "parse.c"
  3255   3240     sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
  3256   3241   }
  3257   3242   
  3258   3243   /*
  3259   3244   ** The following is executed when the parser accepts
  3260   3245   */
  3261   3246   static void yy_accept(

Changes to SQLite.Interop/src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           14  +** $Id: pragma.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "os.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /* Ignore this whole file if pragmas are disabled
    21     21   */
................................................................................
   479    479         sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
   480    480         sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
   481    481         sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
   482    482         sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
   483    483         sqlite3ViewGetColumnNames(pParse, pTab);
   484    484         for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
   485    485           const Token *pDflt;
   486         -        static const Token noDflt =  { (unsigned char*)"", 0, 0 };
   487    486           sqlite3VdbeAddOp(v, OP_Integer, i, 0);
   488    487           sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
   489    488           sqlite3VdbeOp3(v, OP_String8, 0, 0,
   490    489              pCol->zType ? pCol->zType : "", 0);
   491    490           sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
   492         -        pDflt = pCol->pDflt ? &pCol->pDflt->span : &noDflt;
   493         -        if( pDflt->z ){
          491  +        if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
   494    492             sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n);
   495    493           }else{
   496    494             sqlite3VdbeAddOp(v, OP_Null, 0, 0);
   497    495           }
   498    496           sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
   499    497           sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
   500    498         }
................................................................................
   892    890           { OP_ReadCookie,      0,  0,  0},    /* 0 */
   893    891           { OP_Callback,        1,  0,  0}
   894    892         };
   895    893         int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
   896    894         sqlite3VdbeChangeP1(v, addr, iDb);
   897    895         sqlite3VdbeChangeP2(v, addr, iCookie);
   898    896         sqlite3VdbeSetNumCols(v, 1);
          897  +      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P3_TRANSIENT);
   899    898       }
   900    899     }
   901    900   #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
   902    901   
   903    902   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
   904    903     /*
   905    904     ** Report the current state of file logs for all databases

Changes to SQLite.Interop/src/prepare.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains the implementation of the sqlite3_prepare()
    13     13   ** interface, and routines that contribute to loading the database schema
    14     14   ** from disk.
    15     15   **
    16         -** $Id: prepare.c,v 1.20 2006/10/12 21:34:22 rmsimpson Exp $
           16  +** $Id: prepare.c,v 1.21 2007/01/10 14:50:46 rmsimpson Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "os.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   /*
    23     23   ** Fill the InitData structure with an error message that indicates
................................................................................
   441    441     }
   442    442     return i;
   443    443   }
   444    444   
   445    445   /*
   446    446   ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
   447    447   */
   448         -int sqlite3_prepare(
          448  +int sqlite3Prepare(
   449    449     sqlite3 *db,              /* Database handle. */
   450    450     const char *zSql,         /* UTF-8 encoded SQL statement. */
   451    451     int nBytes,               /* Length of zSql in bytes. */
          452  +  int saveSqlFlag,          /* True to copy SQL text into the sqlite3_stmt */
   452    453     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
   453         -  const char** pzTail       /* OUT: End of parsed string */
          454  +  const char **pzTail       /* OUT: End of parsed string */
   454    455   ){
   455    456     Parse sParse;
   456    457     char *zErrMsg = 0;
   457    458     int rc = SQLITE_OK;
   458    459     int i;
   459    460   
   460    461     /* Assert that malloc() has not failed */
................................................................................
   499    500     }
   500    501     if( sParse.rc==SQLITE_SCHEMA ){
   501    502       sqlite3ResetInternalSchema(db, 0);
   502    503     }
   503    504     if( sqlite3MallocFailed() ){
   504    505       sParse.rc = SQLITE_NOMEM;
   505    506     }
   506         -  if( pzTail ) *pzTail = sParse.zTail;
          507  +  if( pzTail ){
          508  +    *pzTail = sParse.zTail;
          509  +  }
   507    510     rc = sParse.rc;
   508    511   
   509    512   #ifndef SQLITE_OMIT_EXPLAIN
   510    513     if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
   511    514       if( sParse.explain==2 ){
   512    515         sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
   513    516         sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P3_STATIC);
................................................................................
   517    520         sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
   518    521         sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P3_STATIC);
   519    522         sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P3_STATIC);
   520    523         sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P3_STATIC);
   521    524         sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P3_STATIC);
   522    525         sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P3_STATIC);
   523    526       }
   524         -  } 
          527  +  }
   525    528   #endif
   526    529   
   527    530     if( sqlite3SafetyOff(db) ){
   528    531       rc = SQLITE_MISUSE;
   529    532     }
   530    533     if( rc==SQLITE_OK ){
          534  +    if( saveSqlFlag ){
          535  +      sqlite3VdbeSetSql(sParse.pVdbe, zSql, sParse.zTail - zSql);
          536  +    }
   531    537       *ppStmt = (sqlite3_stmt*)sParse.pVdbe;
   532    538     }else if( sParse.pVdbe ){
   533    539       sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
   534    540     }
   535    541   
   536    542     if( zErrMsg ){
   537    543       sqlite3Error(db, rc, "%s", zErrMsg);
................................................................................
   541    547     }
   542    548   
   543    549     rc = sqlite3ApiExit(db, rc);
   544    550     sqlite3ReleaseThreadData();
   545    551     assert( (rc&db->errMask)==rc );
   546    552     return rc;
   547    553   }
          554  +
          555  +/*
          556  +** Rerun the compilation of a statement after a schema change.
          557  +** Return true if the statement was recompiled successfully.
          558  +** Return false if there is an error of some kind.
          559  +*/
          560  +int sqlite3Reprepare(Vdbe *p){
          561  +  int rc;
          562  +  Vdbe *pNew;
          563  +  const char *zSql;
          564  +  sqlite3 *db;
          565  +  
          566  +  zSql = sqlite3VdbeGetSql(p);
          567  +  if( zSql==0 ){
          568  +    return 0;
          569  +  }
          570  +  db = sqlite3VdbeDb(p);
          571  +  rc = sqlite3Prepare(db, zSql, -1, 0, (sqlite3_stmt**)&pNew, 0);
          572  +  if( rc ){
          573  +    assert( pNew==0 );
          574  +    return 0;
          575  +  }else{
          576  +    assert( pNew!=0 );
          577  +  }
          578  +  sqlite3VdbeSwap(pNew, p);
          579  +  sqlite3_transfer_bindings((sqlite3_stmt*)pNew, (sqlite3_stmt*)p);
          580  +  sqlite3VdbeResetStepResult(pNew);
          581  +  sqlite3VdbeFinalize(pNew);
          582  +  return 1;
          583  +}
          584  +
          585  +
          586  +/*
          587  +** Two versions of the official API.  Legacy and new use.  In the legacy
          588  +** version, the original SQL text is not saved in the prepared statement
          589  +** and so if a schema change occurs, SQLITE_SCHEMA is returned by
          590  +** sqlite3_step().  In the new version, the original SQL text is retained
          591  +** and the statement is automatically recompiled if an schema change
          592  +** occurs.
          593  +*/
          594  +int sqlite3_prepare(
          595  +  sqlite3 *db,              /* Database handle. */
          596  +  const char *zSql,         /* UTF-8 encoded SQL statement. */
          597  +  int nBytes,               /* Length of zSql in bytes. */
          598  +  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
          599  +  const char **pzTail       /* OUT: End of parsed string */
          600  +){
          601  +  return sqlite3Prepare(db,zSql,nBytes,0,ppStmt,pzTail);
          602  +}
          603  +int sqlite3_prepare_v2(
          604  +  sqlite3 *db,              /* Database handle. */
          605  +  const char *zSql,         /* UTF-8 encoded SQL statement. */
          606  +  int nBytes,               /* Length of zSql in bytes. */
          607  +  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
          608  +  const char **pzTail       /* OUT: End of parsed string */
          609  +){
          610  +  return sqlite3Prepare(db,zSql,nBytes,1,ppStmt,pzTail);
          611  +}
          612  +
   548    613   
   549    614   #ifndef SQLITE_OMIT_UTF16
   550    615   /*
   551    616   ** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
   552    617   */
   553         -int sqlite3_prepare16(
          618  +static int sqlite3Prepare16(
   554    619     sqlite3 *db,              /* Database handle. */ 
   555    620     const void *zSql,         /* UTF-8 encoded SQL statement. */
   556    621     int nBytes,               /* Length of zSql in bytes. */
          622  +  int saveSqlFlag,          /* True to save SQL text into the sqlite3_stmt */
   557    623     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
   558    624     const void **pzTail       /* OUT: End of parsed string */
   559    625   ){
   560    626     /* This function currently works by first transforming the UTF-16
   561    627     ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
   562    628     ** tricky bit is figuring out the pointer to return in *pzTail.
   563    629     */
................................................................................
   566    632     int rc = SQLITE_OK;
   567    633   
   568    634     if( sqlite3SafetyCheck(db) ){
   569    635       return SQLITE_MISUSE;
   570    636     }
   571    637     zSql8 = sqlite3utf16to8(zSql, nBytes);
   572    638     if( zSql8 ){
   573         -    rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
          639  +    rc = sqlite3Prepare(db, zSql8, -1, saveSqlFlag, ppStmt, &zTail8);
   574    640     }
   575    641   
   576    642     if( zTail8 && pzTail ){
   577    643       /* If sqlite3_prepare returns a tail pointer, we calculate the
   578    644       ** equivalent pointer into the UTF-16 string by counting the unicode
   579    645       ** characters between zSql8 and zTail8, and then returning a pointer
   580    646       ** the same number of characters into the UTF-16 string.
................................................................................
   581    647       */
   582    648       int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
   583    649       *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
   584    650     }
   585    651     sqliteFree(zSql8); 
   586    652     return sqlite3ApiExit(db, rc);
   587    653   }
          654  +
          655  +/*
          656  +** Two versions of the official API.  Legacy and new use.  In the legacy
          657  +** version, the original SQL text is not saved in the prepared statement
          658  +** and so if a schema change occurs, SQLITE_SCHEMA is returned by
          659  +** sqlite3_step().  In the new version, the original SQL text is retained
          660  +** and the statement is automatically recompiled if an schema change
          661  +** occurs.
          662  +*/
          663  +int sqlite3_prepare16(
          664  +  sqlite3 *db,              /* Database handle. */ 
          665  +  const void *zSql,         /* UTF-8 encoded SQL statement. */
          666  +  int nBytes,               /* Length of zSql in bytes. */
          667  +  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
          668  +  const void **pzTail       /* OUT: End of parsed string */
          669  +){
          670  +  return sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
          671  +}
          672  +int sqlite3_prepare16_v2(
          673  +  sqlite3 *db,              /* Database handle. */ 
          674  +  const void *zSql,         /* UTF-8 encoded SQL statement. */
          675  +  int nBytes,               /* Length of zSql in bytes. */
          676  +  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
          677  +  const void **pzTail       /* OUT: End of parsed string */
          678  +){
          679  +  return sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
          680  +}
          681  +
   588    682   #endif /* SQLITE_OMIT_UTF16 */

Changes to SQLite.Interop/src/random.c.

    11     11   *************************************************************************
    12     12   ** This file contains code to implement a pseudo-random number
    13     13   ** generator (PRNG) for SQLite.
    14     14   **
    15     15   ** Random numbers are used by some of the database backends in order
    16     16   ** to generate random integer keys for tables or random filenames.
    17     17   **
    18         -** $Id: random.c,v 1.23 2006/10/12 21:34:22 rmsimpson Exp $
           18  +** $Id: random.c,v 1.24 2007/01/10 14:50:46 rmsimpson Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include "os.h"
    22     22   
    23     23   
    24     24   /*
    25     25   ** Get a single 8-bit random value from the RC4 PRNG.  The Mutex
................................................................................
    33     33   ** to know.  To minimize the risk of problems due to bad lrand48()
    34     34   ** implementations, SQLite uses this random number generator based
    35     35   ** on RC4, which we know works very well.
    36     36   **
    37     37   ** (Later):  Actually, OP_NewRowid does not depend on a good source of
    38     38   ** randomness any more.  But we will leave this code in all the same.
    39     39   */
    40         -static int randomByte(){
           40  +static int randomByte(void){
    41     41     unsigned char t;
    42     42   
    43     43     /* All threads share a single random number generator.
    44     44     ** This structure is the current state of the generator.
    45     45     */
    46     46     static struct {
    47     47       unsigned char isInit;          /* True if initialized */

Changes to SQLite.Interop/src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.25 2006/10/12 21:34:22 rmsimpson Exp $
           15  +** $Id: select.c,v 1.26 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
   297    297       Table *pRightTab = pRight->pTab;
   298    298   
   299    299       if( pLeftTab==0 || pRightTab==0 ) continue;
   300    300   
   301    301       /* When the NATURAL keyword is present, add WHERE clause terms for
   302    302       ** every column that the two tables have in common.
   303    303       */
   304         -    if( pLeft->jointype & JT_NATURAL ){
   305         -      if( pLeft->pOn || pLeft->pUsing ){
          304  +    if( pRight->jointype & JT_NATURAL ){
          305  +      if( pRight->pOn || pRight->pUsing ){
   306    306           sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
   307    307              "an ON or USING clause", 0);
   308    308           return 1;
   309    309         }
   310    310         for(j=0; j<pLeftTab->nCol; j++){
   311    311           char *zName = pLeftTab->aCol[j].zName;
   312    312           if( columnIndex(pRightTab, zName)>=0 ){
................................................................................
   316    316             
   317    317           }
   318    318         }
   319    319       }
   320    320   
   321    321       /* Disallow both ON and USING clauses in the same join
   322    322       */
   323         -    if( pLeft->pOn && pLeft->pUsing ){
          323  +    if( pRight->pOn && pRight->pUsing ){
   324    324         sqlite3ErrorMsg(pParse, "cannot have both ON and USING "
   325    325           "clauses in the same join");
   326    326         return 1;
   327    327       }
   328    328   
   329    329       /* Add the ON clause to the end of the WHERE clause, connected by
   330    330       ** an AND operator.
   331    331       */
   332         -    if( pLeft->pOn ){
   333         -      setJoinExpr(pLeft->pOn, pRight->iCursor);
   334         -      p->pWhere = sqlite3ExprAnd(p->pWhere, pLeft->pOn);
   335         -      pLeft->pOn = 0;
          332  +    if( pRight->pOn ){
          333  +      setJoinExpr(pRight->pOn, pRight->iCursor);
          334  +      p->pWhere = sqlite3ExprAnd(p->pWhere, pRight->pOn);
          335  +      pRight->pOn = 0;
   336    336       }
   337    337   
   338    338       /* Create extra terms on the WHERE clause for each column named
   339    339       ** in the USING clause.  Example: If the two tables to be joined are 
   340    340       ** A and B and the USING clause names X, Y, and Z, then add this
   341    341       ** to the WHERE clause:    A.X=B.X AND A.Y=B.Y AND A.Z=B.Z
   342    342       ** Report an error if any column mentioned in the USING clause is
   343    343       ** not contained in both tables to be joined.
   344    344       */
   345         -    if( pLeft->pUsing ){
   346         -      IdList *pList = pLeft->pUsing;
          345  +    if( pRight->pUsing ){
          346  +      IdList *pList = pRight->pUsing;
   347    347         for(j=0; j<pList->nId; j++){
   348    348           char *zName = pList->a[j].zName;
   349    349           if( columnIndex(pLeftTab, zName)<0 || columnIndex(pRightTab, zName)<0 ){
   350    350             sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
   351    351               "not present in both tables", zName);
   352    352             return 1;
   353    353           }
................................................................................
  1305   1305             tableSeen = 1;
  1306   1306             for(j=0; j<pTab->nCol; j++){
  1307   1307               Expr *pExpr, *pRight;
  1308   1308               char *zName = pTab->aCol[j].zName;
  1309   1309   
  1310   1310               if( i>0 ){
  1311   1311                 struct SrcList_item *pLeft = &pTabList->a[i-1];
  1312         -              if( (pLeft->jointype & JT_NATURAL)!=0 &&
         1312  +              if( (pLeft[1].jointype & JT_NATURAL)!=0 &&
  1313   1313                           columnIndex(pLeft->pTab, zName)>=0 ){
  1314   1314                   /* In a NATURAL join, omit the join columns from the 
  1315   1315                   ** table on the right */
  1316   1316                   continue;
  1317   1317                 }
  1318         -              if( sqlite3IdListIndex(pLeft->pUsing, zName)>=0 ){
         1318  +              if( sqlite3IdListIndex(pLeft[1].pUsing, zName)>=0 ){
  1319   1319                   /* In a join with a USING clause, omit columns in the
  1320   1320                   ** using clause from the table on the right. */
  1321   1321                   continue;
  1322   1322                 }
  1323   1323               }
  1324   1324               pRight = sqlite3Expr(TK_ID, 0, 0, 0);
  1325   1325               if( pRight==0 ) break;
................................................................................
  2171   2171     **
  2172   2172     ** If we flatten the above, we would get
  2173   2173     **
  2174   2174     **         (t1 LEFT OUTER JOIN t2) JOIN t3
  2175   2175     **
  2176   2176     ** which is not at all the same thing.
  2177   2177     */
  2178         -  if( pSubSrc->nSrc>1 && iFrom>0 && (pSrc->a[iFrom-1].jointype & JT_OUTER)!=0 ){
         2178  +  if( pSubSrc->nSrc>1 && (pSubitem->jointype & JT_OUTER)!=0 ){
  2179   2179       return 0;
  2180   2180     }
  2181   2181   
  2182   2182     /* Restriction 12:  If the subquery is the right operand of a left outer
  2183   2183     ** join, make sure the subquery has no WHERE clause.
  2184   2184     ** An examples of why this is not allowed:
  2185   2185     **
................................................................................
  2188   2188     ** If we flatten the above, we would get
  2189   2189     **
  2190   2190     **         (t1 LEFT OUTER JOIN t2) WHERE t2.x>0
  2191   2191     **
  2192   2192     ** But the t2.x>0 test will always fail on a NULL row of t2, which
  2193   2193     ** effectively converts the OUTER JOIN into an INNER JOIN.
  2194   2194     */
  2195         -  if( iFrom>0 && (pSrc->a[iFrom-1].jointype & JT_OUTER)!=0 
  2196         -      && pSub->pWhere!=0 ){
         2195  +  if( (pSubitem->jointype & JT_OUTER)!=0 && pSub->pWhere!=0 ){
  2197   2196       return 0;
  2198   2197     }
  2199   2198   
  2200   2199     /* If we reach this point, it means flattening is permitted for the
  2201   2200     ** iFrom-th entry of the FROM clause in the outer query.
  2202   2201     */
  2203   2202   
................................................................................
  2228   2227           pSrc->a[i] = pSrc->a[i-extra];
  2229   2228         }
  2230   2229       }
  2231   2230       for(i=0; i<nSubSrc; i++){
  2232   2231         pSrc->a[i+iFrom] = pSubSrc->a[i];
  2233   2232         memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
  2234   2233       }
  2235         -    pSrc->a[iFrom+nSubSrc-1].jointype = jointype;
         2234  +    pSrc->a[iFrom].jointype = jointype;
  2236   2235     }
  2237   2236   
  2238   2237     /* Now begin substituting subquery result set expressions for 
  2239   2238     ** references to the iParent in the outer query.
  2240   2239     ** 
  2241   2240     ** Example:
  2242   2241     **
................................................................................
  2601   2600           sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
  2602   2601               "the GROUP BY clause");
  2603   2602           return SQLITE_ERROR;
  2604   2603         }
  2605   2604       }
  2606   2605     }
  2607   2606   
  2608         -  return SQLITE_OK;
         2607  +  /* If this is one SELECT of a compound, be sure to resolve names
         2608  +  ** in the other SELECTs.
         2609  +  */
         2610  +  if( p->pPrior ){
         2611  +    return sqlite3SelectResolve(pParse, p->pPrior, pOuterNC);
         2612  +  }else{
         2613  +    return SQLITE_OK;
         2614  +  }
  2609   2615   }
  2610   2616   
  2611   2617   /*
  2612   2618   ** Reset the aggregate accumulator.
  2613   2619   **
  2614   2620   ** The aggregate accumulator is a set of memory cells that hold
  2615   2621   ** intermediate results while calculating an aggregate.  This

Changes to SQLite.Interop/src/shell.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code to implement the "sqlite" command line
    13     13   ** utility for accessing SQLite databases.
    14     14   **
    15         -** $Id: shell.c,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           15  +** $Id: shell.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <stdio.h>
    20     20   #include <assert.h>
    21     21   #include "sqlite3.h"
    22     22   #include <ctype.h>
................................................................................
    56     56   # include <io.h>
    57     57   #else
    58     58   /* Make sure isatty() has a prototype.
    59     59   */
    60     60   extern int isatty();
    61     61   #endif
    62     62   
           63  +/*
           64  +** If the following flag is set, then command execution stops
           65  +** at an error if we are not interactive.
           66  +*/
           67  +static int bail_on_error = 0;
           68  +
           69  +/*
           70  +** Threat stdin as an interactive input if the following variable
           71  +** is true.  Otherwise, assume stdin is connected to a file or pipe.
           72  +*/
           73  +static int stdin_is_interactive = 1;
           74  +
    63     75   /*
    64     76   ** The following is the open SQLite database.  We make a pointer
    65     77   ** to this database a static variable so that it can be accessed
    66     78   ** by the SIGINT handler to interrupt database processing.
    67     79   */
    68     80   static sqlite3 *db = 0;
    69     81   
................................................................................
   180    192       }
   181    193     }
   182    194     zLine = realloc( zLine, n+1 );
   183    195     return zLine;
   184    196   }
   185    197   
   186    198   /*
   187         -** Retrieve a single line of input text.  "isatty" is true if text
   188         -** is coming from a terminal.  In that case, we issue a prompt and
   189         -** attempt to use "readline" for command-line editing.  If "isatty"
   190         -** is false, use "local_getline" instead of "readline" and issue no prompt.
          199  +** Retrieve a single line of input text.
   191    200   **
   192    201   ** zPrior is a string of prior text retrieved.  If not the empty
   193    202   ** string, then issue a continuation prompt.
   194    203   */
   195    204   static char *one_input_line(const char *zPrior, FILE *in){
   196    205     char *zPrompt;
   197    206     char *zResult;
................................................................................
   212    221   
   213    222   struct previous_mode_data {
   214    223     int valid;        /* Is there legit data in here? */
   215    224     int mode;
   216    225     int showHeader;
   217    226     int colWidth[100];
   218    227   };
          228  +
   219    229   /*
   220    230   ** An pointer to an instance of this structure is passed from
   221    231   ** the main program to the callback.  This is used to communicate
   222    232   ** state and mode information.
   223    233   */
   224    234   struct callback_data {
   225    235     sqlite3 *db;            /* The database */
   226    236     int echoOn;            /* True to echo input commands */
   227    237     int cnt;               /* Number of records displayed so far */
   228    238     FILE *out;             /* Write results here */
   229    239     int mode;              /* An output mode setting */
          240  +  int writableSchema;    /* True if PRAGMA writable_schema=ON */
   230    241     int showHeader;        /* True to show column names in List or Column mode */
   231    242     char *zDestTable;      /* Name of destination table when MODE_Insert */
   232    243     char separator[20];    /* Separator character for MODE_List */
   233    244     int colWidth[100];     /* Requested width of each column when in column mode*/
   234    245     int actualWidth[100];  /* Actual width of each column */
   235    246     char nullvalue[20];    /* The text to print when a NULL comes back from
   236    247                            ** the database */
................................................................................
   346    357       }else{
   347    358         break;
   348    359       }
   349    360       z += i + 1;
   350    361     }
   351    362   }
   352    363   
          364  +/*
          365  +** If a field contains any character identified by a 1 in the following
          366  +** array, then the string must be quoted for CSV.
          367  +*/
          368  +static const char needCsvQuote[] = {
          369  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          370  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          371  +  1, 0, 1, 0, 0, 0, 0, 1,   0, 0, 0, 0, 0, 0, 0, 0, 
          372  +  0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 
          373  +  0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 
          374  +  0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 
          375  +  0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 
          376  +  0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 1, 
          377  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          378  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          379  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          380  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          381  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          382  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          383  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          384  +  1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   
          385  +};
          386  +
   353    387   /*
   354    388   ** Output a single term of CSV.  Actually, p->separator is used for
   355    389   ** the separator, which may or may not be a comma.  p->nullvalue is
   356    390   ** the null value.  Strings are quoted using ANSI-C rules.  Numbers
   357    391   ** appear outside of quotes.
   358    392   */
   359    393   static void output_csv(struct callback_data *p, const char *z, int bSep){
          394  +  FILE *out = p->out;
   360    395     if( z==0 ){
   361         -    fprintf(p->out,"%s",p->nullvalue);
   362         -  }else if( isNumber(z, 0) ){
   363         -    fprintf(p->out,"%s",z);
          396  +    fprintf(out,"%s",p->nullvalue);
   364    397     }else{
   365         -    output_c_string(p->out, z);
          398  +    int i;
          399  +    for(i=0; z[i]; i++){
          400  +      if( needCsvQuote[((unsigned char*)z)[i]] ){
          401  +        i = 0;
          402  +        break;
          403  +      }
          404  +    }
          405  +    if( i==0 ){
          406  +      putc('"', out);
          407  +      for(i=0; z[i]; i++){
          408  +        if( z[i]=='"' ) putc('"', out);
          409  +        putc(z[i], out);
          410  +      }
          411  +      putc('"', out);
          412  +    }else{
          413  +      fprintf(out, "%s", z);
          414  +    }
   366    415     }
   367    416     if( bSep ){
   368    417       fprintf(p->out, p->separator);
   369    418     }
   370    419   }
   371    420   
   372    421   #ifdef SIGINT
................................................................................
   583    632   ** from malloc(), or a NULL pointer. The string pointed to by zAppend is
   584    633   ** added to zIn, and the result returned in memory obtained from malloc().
   585    634   ** zIn, if it was not NULL, is freed.
   586    635   **
   587    636   ** If the third argument, quote, is not '\0', then it is used as a 
   588    637   ** quote character for zAppend.
   589    638   */
   590         -static char * appendText(char *zIn, char const *zAppend, char quote){
          639  +static char *appendText(char *zIn, char const *zAppend, char quote){
   591    640     int len;
   592    641     int i;
   593    642     int nAppend = strlen(zAppend);
   594    643     int nIn = (zIn?strlen(zIn):0);
   595    644   
   596    645     len = nAppend+nIn+1;
   597    646     if( quote ){
................................................................................
   624    673     return zIn;
   625    674   }
   626    675   
   627    676   
   628    677   /*
   629    678   ** Execute a query statement that has a single result column.  Print
   630    679   ** that result column on a line by itself with a semicolon terminator.
          680  +**
          681  +** This is used, for example, to show the schema of the database by
          682  +** querying the SQLITE_MASTER table.
   631    683   */
   632    684   static int run_table_dump_query(FILE *out, sqlite3 *db, const char *zSelect){
   633    685     sqlite3_stmt *pSelect;
   634    686     int rc;
   635    687     rc = sqlite3_prepare(db, zSelect, -1, &pSelect, 0);
   636    688     if( rc!=SQLITE_OK || !pSelect ){
   637    689       return rc;
................................................................................
   665    717     
   666    718     if( strcmp(zTable, "sqlite_sequence")==0 ){
   667    719       fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
   668    720     }else if( strcmp(zTable, "sqlite_stat1")==0 ){
   669    721       fprintf(p->out, "ANALYZE sqlite_master;\n");
   670    722     }else if( strncmp(zTable, "sqlite_", 7)==0 ){
   671    723       return 0;
          724  +  }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
          725  +    char *zIns;
          726  +    if( !p->writableSchema ){
          727  +      fprintf(p->out, "PRAGMA writable_schema=ON;\n");
          728  +      p->writableSchema = 1;
          729  +    }
          730  +    zIns = sqlite3_mprintf(
          731  +       "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
          732  +       "VALUES('table','%q','%q',0,'%q');",
          733  +       zTable, zTable, zSql);
          734  +    fprintf(p->out, "%s\n", zIns);
          735  +    sqlite3_free(zIns);
          736  +    return 0;
   672    737     }else{
   673    738       fprintf(p->out, "%s;\n", zSql);
   674    739     }
   675    740   
   676    741     if( strcmp(zType, "table")==0 ){
   677    742       sqlite3_stmt *pTableInfo = 0;
   678    743       char *zSelect = 0;
................................................................................
   698    763       rc = sqlite3_step(pTableInfo);
   699    764       while( rc==SQLITE_ROW ){
   700    765         const char *zText = (const char *)sqlite3_column_text(pTableInfo, 1);
   701    766         zSelect = appendText(zSelect, "quote(", 0);
   702    767         zSelect = appendText(zSelect, zText, '"');
   703    768         rc = sqlite3_step(pTableInfo);
   704    769         if( rc==SQLITE_ROW ){
   705         -        zSelect = appendText(zSelect, ") || ', ' || ", 0);
          770  +        zSelect = appendText(zSelect, ") || ',' || ", 0);
   706    771         }else{
   707    772           zSelect = appendText(zSelect, ") ", 0);
   708    773         }
   709    774       }
   710    775       rc = sqlite3_finalize(pTableInfo);
   711    776       if( rc!=SQLITE_OK ){
   712    777         if( zSelect ) free(zSelect);
................................................................................
   717    782   
   718    783       rc = run_table_dump_query(p->out, p->db, zSelect);
   719    784       if( rc==SQLITE_CORRUPT ){
   720    785         zSelect = appendText(zSelect, " ORDER BY rowid DESC", 0);
   721    786         rc = run_table_dump_query(p->out, p->db, zSelect);
   722    787       }
   723    788       if( zSelect ) free(zSelect);
   724         -    if( rc!=SQLITE_OK ){
   725         -      return 1;
   726         -    }
   727    789     }
   728    790     return 0;
   729    791   }
   730    792   
   731    793   /*
   732         -** Run zQuery.  Update dump_callback() as the callback routine.
          794  +** Run zQuery.  Use dump_callback() as the callback routine so that
          795  +** the contents of the query are output as SQL statements.
          796  +**
   733    797   ** If we get a SQLITE_CORRUPT error, rerun the query after appending
   734    798   ** "ORDER BY rowid DESC" to the end.
   735    799   */
   736    800   static int run_schema_dump_query(
   737    801     struct callback_data *p, 
   738    802     const char *zQuery,
   739    803     char **pzErrMsg
................................................................................
   753    817     return rc;
   754    818   }
   755    819   
   756    820   /*
   757    821   ** Text of a help message
   758    822   */
   759    823   static char zHelp[] =
          824  +  ".bail ON|OFF           Stop after hitting an error.  Default OFF\n"
   760    825     ".databases             List names and files of attached databases\n"
   761    826     ".dump ?TABLE? ...      Dump the database in an SQL text format\n"
   762    827     ".echo ON|OFF           Turn command echo on or off\n"
   763    828     ".exit                  Exit this program\n"
   764    829     ".explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.\n"
   765    830     ".header(s) ON|OFF      Turn display of headers on or off\n"
   766    831     ".help                  Show this message\n"
................................................................................
   789    854     ".show                  Show the current values for various settings\n"
   790    855     ".tables ?PATTERN?      List names of tables matching a LIKE pattern\n"
   791    856     ".timeout MS            Try opening locked tables for MS milliseconds\n"
   792    857     ".width NUM NUM ...     Set column widths for \"column\" mode\n"
   793    858   ;
   794    859   
   795    860   /* Forward reference */
   796         -static void process_input(struct callback_data *p, FILE *in);
          861  +static int process_input(struct callback_data *p, FILE *in);
   797    862   
   798    863   /*
   799    864   ** Make sure the database is open.  If it is not, then open it.  If
   800    865   ** the database fails to open, print an error message and exit.
   801    866   */
   802    867   static void open_db(struct callback_data *p){
   803    868     if( p->db==0 ){
................................................................................
   848    913           }
   849    914         }
   850    915       }
   851    916       z[j] = c;
   852    917     }
   853    918     z[j] = 0;
   854    919   }
          920  +
          921  +/*
          922  +** Interpret zArg as a boolean value.  Return either 0 or 1.
          923  +*/
          924  +static int booleanValue(char *zArg){
          925  +  int val = atoi(zArg);
          926  +  int j;
          927  +  for(j=0; zArg[j]; j++){
          928  +    zArg[j] = tolower(zArg[j]);
          929  +  }
          930  +  if( strcmp(zArg,"on")==0 ){
          931  +    val = 1;
          932  +  }else if( strcmp(zArg,"yes")==0 ){
          933  +    val = 1;
          934  +  }
          935  +  return val;
          936  +}
   855    937   
   856    938   /*
   857    939   ** If an input line begins with "." then invoke this routine to
   858    940   ** process that line.
   859    941   **
   860         -** Return 1 to exit and 0 to continue.
          942  +** Return 1 on error, 2 to exit, and 0 otherwise.
   861    943   */
   862    944   static int do_meta_command(char *zLine, struct callback_data *p){
   863    945     int i = 1;
   864    946     int nArg = 0;
   865    947     int n, c;
   866    948     int rc = 0;
   867    949     char *azArg[50];
................................................................................
   888    970     }
   889    971   
   890    972     /* Process the input line.
   891    973     */
   892    974     if( nArg==0 ) return rc;
   893    975     n = strlen(azArg[0]);
   894    976     c = azArg[0][0];
          977  +  if( c=='b' && n>1 && strncmp(azArg[0], "bail", n)==0 && nArg>1 ){
          978  +    bail_on_error = booleanValue(azArg[1]);
          979  +  }else
          980  +
   895    981     if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 ){
   896    982       struct callback_data data;
   897    983       char *zErrMsg = 0;
   898    984       open_db(p);
   899    985       memcpy(&data, p, sizeof(data));
   900    986       data.showHeader = 1;
   901    987       data.mode = MODE_Column;
................................................................................
   910    996       }
   911    997     }else
   912    998   
   913    999     if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
   914   1000       char *zErrMsg = 0;
   915   1001       open_db(p);
   916   1002       fprintf(p->out, "BEGIN TRANSACTION;\n");
         1003  +    p->writableSchema = 0;
   917   1004       if( nArg==1 ){
   918   1005         run_schema_dump_query(p, 
   919   1006           "SELECT name, type, sql FROM sqlite_master "
   920         -        "WHERE sql NOT NULL AND type=='table' AND rootpage!=0", 0
   921         -      );
   922         -      run_schema_dump_query(p, 
   923         -        "SELECT name, type, sql FROM sqlite_master "
   924         -        "WHERE sql NOT NULL AND "
   925         -        "  AND type!='table' AND type!='meta'", 0
         1007  +        "WHERE sql NOT NULL AND type=='table'", 0
   926   1008         );
   927   1009         run_table_dump_query(p->out, p->db,
   928   1010           "SELECT sql FROM sqlite_master "
   929         -        "WHERE sql NOT NULL AND rootpage==0 AND type='table'"
         1011  +        "WHERE sql NOT NULL AND type IN ('index','trigger','view')"
   930   1012         );
   931   1013       }else{
   932   1014         int i;
   933   1015         for(i=1; i<nArg; i++){
   934   1016           zShellStatic = azArg[i];
   935   1017           run_schema_dump_query(p,
   936   1018             "SELECT name, type, sql FROM sqlite_master "
   937   1019             "WHERE tbl_name LIKE shellstatic() AND type=='table'"
   938         -          "  AND rootpage!=0 AND sql NOT NULL", 0);
   939         -        run_schema_dump_query(p,
   940         -          "SELECT name, type, sql FROM sqlite_master "
   941         -          "WHERE tbl_name LIKE shellstatic() AND type!='table'"
   942         -          "  AND type!='meta' AND sql NOT NULL", 0);
         1020  +          "  AND sql NOT NULL", 0);
   943   1021           run_table_dump_query(p->out, p->db,
   944   1022             "SELECT sql FROM sqlite_master "
   945         -          "WHERE sql NOT NULL AND rootpage==0 AND type='table'"
         1023  +          "WHERE sql NOT NULL"
         1024  +          "  AND type IN ('index','trigger','view')"
   946   1025             "  AND tbl_name LIKE shellstatic()"
   947   1026           );
   948   1027           zShellStatic = 0;
   949   1028         }
         1029  +    }
         1030  +    if( p->writableSchema ){
         1031  +      fprintf(p->out, "PRAGMA writable_schema=OFF;\n");
         1032  +      p->writableSchema = 0;
   950   1033       }
   951   1034       if( zErrMsg ){
   952   1035         fprintf(stderr,"Error: %s\n", zErrMsg);
   953   1036         sqlite3_free(zErrMsg);
   954   1037       }else{
   955   1038         fprintf(p->out, "COMMIT;\n");
   956   1039       }
   957   1040     }else
   958   1041   
   959   1042     if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 ){
   960         -    int j;
   961         -    char *z = azArg[1];
   962         -    int val = atoi(azArg[1]);
   963         -    for(j=0; z[j]; j++){
   964         -      z[j] = tolower((unsigned char)z[j]);
   965         -    }
   966         -    if( strcmp(z,"on")==0 ){
   967         -      val = 1;
   968         -    }else if( strcmp(z,"yes")==0 ){
   969         -      val = 1;
   970         -    }
   971         -    p->echoOn = val;
         1043  +    p->echoOn = booleanValue(azArg[1]);
   972   1044     }else
   973   1045   
   974   1046     if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
   975         -    rc = 1;
         1047  +    rc = 2;
   976   1048     }else
   977   1049   
   978   1050     if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
   979         -    int j;
   980         -    static char zOne[] = "1";
   981         -    char *z = nArg>=2 ? azArg[1] : zOne;
   982         -    int val = atoi(z);
   983         -    for(j=0; z[j]; j++){
   984         -      z[j] = tolower((unsigned char)z[j]);
   985         -    }
   986         -    if( strcmp(z,"on")==0 ){
   987         -      val = 1;
   988         -    }else if( strcmp(z,"yes")==0 ){
   989         -      val = 1;
   990         -    }
         1051  +    int val = nArg>=2 ? booleanValue(azArg[1]) : 1;
   991   1052       if(val == 1) {
   992   1053         if(!p->explainPrev.valid) {
   993   1054           p->explainPrev.valid = 1;
   994   1055           p->explainPrev.mode = p->mode;
   995   1056           p->explainPrev.showHeader = p->showHeader;
   996   1057           memcpy(p->explainPrev.colWidth,p->colWidth,sizeof(p->colWidth));
   997   1058         }
................................................................................
  1014   1075         p->explainPrev.valid = 0;
  1015   1076         p->mode = p->explainPrev.mode;
  1016   1077         p->showHeader = p->explainPrev.showHeader;
  1017   1078         memcpy(p->colWidth,p->explainPrev.colWidth,sizeof(p->colWidth));
  1018   1079       }
  1019   1080     }else
  1020   1081   
  1021         -  if( c=='h' && (strncmp(azArg[0], "header", n)==0
  1022         -                 ||
         1082  +  if( c=='h' && (strncmp(azArg[0], "header", n)==0 ||
  1023   1083                    strncmp(azArg[0], "headers", n)==0 )&& nArg>1 ){
  1024         -    int j;
  1025         -    char *z = azArg[1];
  1026         -    int val = atoi(azArg[1]);
  1027         -    for(j=0; z[j]; j++){
  1028         -      z[j] = tolower((unsigned char)z[j]);
  1029         -    }
  1030         -    if( strcmp(z,"on")==0 ){
  1031         -      val = 1;
  1032         -    }else if( strcmp(z,"yes")==0 ){
  1033         -      val = 1;
  1034         -    }
  1035         -    p->showHeader = val;
         1084  +    p->showHeader = booleanValue(azArg[1]);
  1036   1085     }else
  1037   1086   
  1038   1087     if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
  1039   1088       fprintf(stderr,zHelp);
  1040   1089     }else
  1041   1090   
  1042   1091     if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg>=3 ){
................................................................................
  1065   1114       if( zSql==0 ) return 0;
  1066   1115       nByte = strlen(zSql);
  1067   1116       rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
  1068   1117       sqlite3_free(zSql);
  1069   1118       if( rc ){
  1070   1119         fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
  1071   1120         nCol = 0;
         1121  +      rc = 1;
  1072   1122       }else{
  1073   1123         nCol = sqlite3_column_count(pStmt);
  1074   1124       }
  1075   1125       sqlite3_finalize(pStmt);
  1076   1126       if( nCol==0 ) return 0;
  1077   1127       zSql = malloc( nByte + 20 + nCol*2 );
  1078   1128       if( zSql==0 ) return 0;
................................................................................
  1085   1135       zSql[j++] = ')';
  1086   1136       zSql[j] = 0;
  1087   1137       rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
  1088   1138       free(zSql);
  1089   1139       if( rc ){
  1090   1140         fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
  1091   1141         sqlite3_finalize(pStmt);
  1092         -      return 0;
         1142  +      return 1;
  1093   1143       }
  1094   1144       in = fopen(zFile, "rb");
  1095   1145       if( in==0 ){
  1096   1146         fprintf(stderr, "cannot open file: %s\n", zFile);
  1097   1147         sqlite3_finalize(pStmt);
  1098   1148         return 0;
  1099   1149       }
................................................................................
  1131   1181         }
  1132   1182         sqlite3_step(pStmt);
  1133   1183         rc = sqlite3_reset(pStmt);
  1134   1184         free(zLine);
  1135   1185         if( rc!=SQLITE_OK ){
  1136   1186           fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
  1137   1187           zCommit = "ROLLBACK";
         1188  +        rc = 1;
  1138   1189           break;
  1139   1190         }
  1140   1191       }
  1141   1192       free(azCol);
  1142   1193       fclose(in);
  1143   1194       sqlite3_finalize(pStmt);
  1144   1195       sqlite3_exec(p->db, zCommit, 0, 0, 0);
................................................................................
  1176   1227       zFile = azArg[1];
  1177   1228       zProc = nArg>=3 ? azArg[2] : 0;
  1178   1229       open_db(p);
  1179   1230       rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
  1180   1231       if( rc!=SQLITE_OK ){
  1181   1232         fprintf(stderr, "%s\n", zErrMsg);
  1182   1233         sqlite3_free(zErrMsg);
         1234  +      rc = 1;
  1183   1235       }
  1184   1236     }else
  1185   1237   #endif
  1186   1238   
  1187   1239     if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg>=2 ){
  1188   1240       int n2 = strlen(azArg[1]);
  1189   1241       if( strncmp(azArg[1],"line",n2)==0
................................................................................
  1210   1262         p->mode = MODE_Insert;
  1211   1263         if( nArg>=3 ){
  1212   1264           set_table_name(p, azArg[2]);
  1213   1265         }else{
  1214   1266           set_table_name(p, "table");
  1215   1267         }
  1216   1268       }else {
  1217         -      fprintf(stderr,"mode should be on of: "
         1269  +      fprintf(stderr,"mode should be one of: "
  1218   1270            "column csv html insert line list tabs tcl\n");
  1219   1271       }
  1220   1272     }else
  1221   1273   
  1222   1274     if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 && nArg==2 ) {
  1223   1275       sprintf(p->nullvalue, "%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
  1224   1276     }else
................................................................................
  1247   1299       }
  1248   1300       if( nArg >= 3) {
  1249   1301         strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
  1250   1302       }
  1251   1303     }else
  1252   1304   
  1253   1305     if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
  1254         -    rc = 1;
         1306  +    rc = 2;
  1255   1307     }else
  1256   1308   
  1257   1309     if( c=='r' && strncmp(azArg[0], "read", n)==0 && nArg==2 ){
  1258   1310       FILE *alt = fopen(azArg[1], "rb");
  1259   1311       if( alt==0 ){
  1260   1312         fprintf(stderr,"can't open \"%s\"\n", azArg[1]);
  1261   1313       }else{
................................................................................
  1399   1451         for(i=0; i<nPrintRow; i++){
  1400   1452           for(j=i+1; j<=nRow; j+=nPrintRow){
  1401   1453             char *zSp = j<=nPrintRow ? "" : "  ";
  1402   1454             printf("%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
  1403   1455           }
  1404   1456           printf("\n");
  1405   1457         }
         1458  +    }else{
         1459  +      rc = 1;
  1406   1460       }
  1407   1461       sqlite3_free_table(azResult);
  1408   1462     }else
  1409   1463   
  1410   1464     if( c=='t' && n>1 && strncmp(azArg[0], "timeout", n)==0 && nArg>=2 ){
  1411   1465       open_db(p);
  1412   1466       sqlite3_busy_timeout(p->db, atoi(azArg[1]));
................................................................................
  1478   1532   
  1479   1533   /*
  1480   1534   ** Read input from *in and process it.  If *in==0 then input
  1481   1535   ** is interactive - the user is typing it it.  Otherwise, input
  1482   1536   ** is coming from a file or device.  A prompt is issued and history
  1483   1537   ** is saved only if input is interactive.  An interrupt signal will
  1484   1538   ** cause this routine to exit immediately, unless input is interactive.
         1539  +**
         1540  +** Return the number of errors.
  1485   1541   */
  1486         -static void process_input(struct callback_data *p, FILE *in){
         1542  +static int process_input(struct callback_data *p, FILE *in){
  1487   1543     char *zLine;
  1488   1544     char *zSql = 0;
  1489   1545     int nSql = 0;
  1490   1546     char *zErrMsg;
  1491   1547     int rc;
  1492         -  while( fflush(p->out), (zLine = one_input_line(zSql, in))!=0 ){
         1548  +  int errCnt = 0;
         1549  +  int lineno = 0;
         1550  +  int startline = 0;
         1551  +
         1552  +  while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){
         1553  +    fflush(p->out);
         1554  +    zLine = one_input_line(zSql, in);
         1555  +    if( zLine==0 ){
         1556  +      break;  /* We have reached EOF */
         1557  +    }
  1493   1558       if( seenInterrupt ){
  1494   1559         if( in!=0 ) break;
  1495   1560         seenInterrupt = 0;
  1496   1561       }
         1562  +    lineno++;
  1497   1563       if( p->echoOn ) printf("%s\n", zLine);
  1498   1564       if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue;
  1499   1565       if( zLine && zLine[0]=='.' && nSql==0 ){
  1500         -      int rc = do_meta_command(zLine, p);
         1566  +      rc = do_meta_command(zLine, p);
  1501   1567         free(zLine);
  1502         -      if( rc ) break;
         1568  +      if( rc==2 ){
         1569  +        break;
         1570  +      }else if( rc ){
         1571  +        errCnt++;
         1572  +      }
  1503   1573         continue;
  1504   1574       }
  1505   1575       if( _is_command_terminator(zLine) ){
  1506   1576         strcpy(zLine,";");
  1507   1577       }
  1508   1578       if( zSql==0 ){
  1509   1579         int i;
................................................................................
  1512   1582           nSql = strlen(zLine);
  1513   1583           zSql = malloc( nSql+1 );
  1514   1584           if( zSql==0 ){
  1515   1585             fprintf(stderr, "out of memory\n");
  1516   1586             exit(1);
  1517   1587           }
  1518   1588           strcpy(zSql, zLine);
         1589  +        startline = lineno;
  1519   1590         }
  1520   1591       }else{
  1521   1592         int len = strlen(zLine);
  1522   1593         zSql = realloc( zSql, nSql + len + 2 );
  1523   1594         if( zSql==0 ){
  1524   1595           fprintf(stderr,"%s: out of memory!\n", Argv0);
  1525   1596           exit(1);
................................................................................
  1530   1601       }
  1531   1602       free(zLine);
  1532   1603       if( zSql && _ends_with_semicolon(zSql, nSql) && sqlite3_complete(zSql) ){
  1533   1604         p->cnt = 0;
  1534   1605         open_db(p);
  1535   1606         rc = sqlite3_exec(p->db, zSql, callback, p, &zErrMsg);
  1536   1607         if( rc || zErrMsg ){
  1537         -        /* if( in!=0 && !p->echoOn ) printf("%s\n",zSql); */
         1608  +        char zPrefix[100];
         1609  +        if( in!=0 || !stdin_is_interactive ){
         1610  +          sprintf(zPrefix, "SQL error near line %d:", startline);
         1611  +        }else{
         1612  +          sprintf(zPrefix, "SQL error:");
         1613  +        }
  1538   1614           if( zErrMsg!=0 ){
  1539         -          printf("SQL error: %s\n", zErrMsg);
         1615  +          printf("%s %s\n", zPrefix, zErrMsg);
  1540   1616             sqlite3_free(zErrMsg);
  1541   1617             zErrMsg = 0;
  1542   1618           }else{
  1543         -          printf("SQL error: %s\n", sqlite3_errmsg(p->db));
         1619  +          printf("%s %s\n", zPrefix, sqlite3_errmsg(p->db));
  1544   1620           }
         1621  +        errCnt++;
  1545   1622         }
  1546   1623         free(zSql);
  1547   1624         zSql = 0;
  1548   1625         nSql = 0;
  1549   1626       }
  1550   1627     }
  1551   1628     if( zSql ){
  1552   1629       if( !_all_whitespace(zSql) ) printf("Incomplete SQL: %s\n", zSql);
  1553   1630       free(zSql);
  1554   1631     }
         1632  +  return errCnt;
  1555   1633   }
  1556   1634   
  1557   1635   /*
  1558   1636   ** Return a pathname which is the user's home directory.  A
  1559   1637   ** 0 return indicates an error of some kind.  Space to hold the
  1560   1638   ** resulting string is obtained from malloc().  The calling
  1561   1639   ** function should free the result.
................................................................................
  1638   1716       }
  1639   1717       sprintf(zBuf,"%s/.sqliterc",home_dir);
  1640   1718       free(home_dir);
  1641   1719       sqliterc = (const char*)zBuf;
  1642   1720     }
  1643   1721     in = fopen(sqliterc,"rb");
  1644   1722     if( in ){
  1645         -    if( isatty(fileno(stdout)) ){
         1723  +    if( stdin_is_interactive ){
  1646   1724         printf("Loading resources from %s\n",sqliterc);
  1647   1725       }
  1648   1726       process_input(p,in);
  1649   1727       fclose(in);
  1650   1728     }
  1651   1729     free(zBuf);
  1652   1730     return;
................................................................................
  1655   1733   /*
  1656   1734   ** Show available command line options
  1657   1735   */
  1658   1736   static const char zOptions[] = 
  1659   1737     "   -init filename       read/process named file\n"
  1660   1738     "   -echo                print commands before execution\n"
  1661   1739     "   -[no]header          turn headers on or off\n"
         1740  +  "   -bail                stop after hitting an error\n"
         1741  +  "   -interactive         force interactive I/O\n"
         1742  +  "   -batch               force batch I/O\n"
  1662   1743     "   -column              set output mode to 'column'\n"
         1744  +  "   -csv                 set output mode to 'csv'\n"
  1663   1745     "   -html                set output mode to HTML\n"
  1664   1746     "   -line                set output mode to 'line'\n"
  1665   1747     "   -list                set output mode to 'list'\n"
  1666   1748     "   -separator 'x'       set output field separator (|)\n"
  1667   1749     "   -nullvalue 'text'    set text string for NULL values\n"
  1668   1750     "   -version             show SQLite version\n"
  1669   1751   ;
................................................................................
  1694   1776   
  1695   1777   int main(int argc, char **argv){
  1696   1778     char *zErrMsg = 0;
  1697   1779     struct callback_data data;
  1698   1780     const char *zInitFile = 0;
  1699   1781     char *zFirstCmd = 0;
  1700   1782     int i;
         1783  +  int rc = 0;
  1701   1784   
  1702   1785   #ifdef __MACOS__
  1703   1786     argc = ccommand(&argv);
  1704   1787   #endif
  1705   1788   
  1706   1789     Argv0 = argv[0];
  1707   1790     main_init(&data);
         1791  +  stdin_is_interactive = isatty(0);
  1708   1792   
  1709   1793     /* Make sure we have a valid signal handler early, before anything
  1710   1794     ** else is done.
  1711   1795     */
  1712   1796   #ifdef SIGINT
  1713   1797     signal(SIGINT, interrupt_handler);
  1714   1798   #endif
  1715   1799   
  1716   1800     /* Do an initial pass through the command-line argument to locate
  1717   1801     ** the name of the database file, the name of the initialization file,
  1718   1802     ** and the first command to execute.
  1719   1803     */
  1720   1804     for(i=1; i<argc-1; i++){
         1805  +    char *z;
  1721   1806       if( argv[i][0]!='-' ) break;
         1807  +    z = argv[i];
         1808  +    if( z[0]=='-' && z[1]=='-' ) z++;
  1722   1809       if( strcmp(argv[i],"-separator")==0 || strcmp(argv[i],"-nullvalue")==0 ){
  1723   1810         i++;
  1724   1811       }else if( strcmp(argv[i],"-init")==0 ){
  1725   1812         i++;
  1726   1813         zInitFile = argv[i];
  1727   1814       }
  1728   1815     }
................................................................................
  1765   1852     /* Make a second pass through the command-line argument and set
  1766   1853     ** options.  This second pass is delayed until after the initialization
  1767   1854     ** file is processed so that the command-line arguments will override
  1768   1855     ** settings in the initialization file.
  1769   1856     */
  1770   1857     for(i=1; i<argc && argv[i][0]=='-'; i++){
  1771   1858       char *z = argv[i];
         1859  +    if( z[1]=='-' ){ z++; }
  1772   1860       if( strcmp(z,"-init")==0 ){
  1773   1861         i++;
  1774   1862       }else if( strcmp(z,"-html")==0 ){
  1775   1863         data.mode = MODE_Html;
  1776   1864       }else if( strcmp(z,"-list")==0 ){
  1777   1865         data.mode = MODE_List;
  1778   1866       }else if( strcmp(z,"-line")==0 ){
  1779   1867         data.mode = MODE_Line;
  1780   1868       }else if( strcmp(z,"-column")==0 ){
  1781   1869         data.mode = MODE_Column;
         1870  +    }else if( strcmp(z,"-csv")==0 ){
         1871  +      data.mode = MODE_Csv;
         1872  +      strcpy(data.separator,",");
  1782   1873       }else if( strcmp(z,"-separator")==0 ){
  1783   1874         i++;
  1784   1875         sprintf(data.separator,"%.*s",(int)sizeof(data.separator)-1,argv[i]);
  1785   1876       }else if( strcmp(z,"-nullvalue")==0 ){
  1786   1877         i++;
  1787   1878         sprintf(data.nullvalue,"%.*s",(int)sizeof(data.nullvalue)-1,argv[i]);
  1788   1879       }else if( strcmp(z,"-header")==0 ){
  1789   1880         data.showHeader = 1;
  1790   1881       }else if( strcmp(z,"-noheader")==0 ){
  1791   1882         data.showHeader = 0;
  1792   1883       }else if( strcmp(z,"-echo")==0 ){
  1793   1884         data.echoOn = 1;
         1885  +    }else if( strcmp(z,"-bail")==0 ){
         1886  +      bail_on_error = 1;
  1794   1887       }else if( strcmp(z,"-version")==0 ){
  1795   1888         printf("%s\n", sqlite3_libversion());
  1796   1889         return 0;
         1890  +    }else if( strcmp(z,"-interactive")==0 ){
         1891  +      stdin_is_interactive = 1;
         1892  +    }else if( strcmp(z,"-batch")==0 ){
         1893  +      stdin_is_interactive = 0;
  1797   1894       }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
  1798   1895         usage(1);
  1799   1896       }else{
  1800   1897         fprintf(stderr,"%s: unknown option: %s\n", Argv0, z);
  1801   1898         fprintf(stderr,"Use -help for a list of options.\n");
  1802   1899         return 1;
  1803   1900       }
................................................................................
  1817   1914           fprintf(stderr,"SQL error: %s\n", zErrMsg);
  1818   1915           exit(1);
  1819   1916         }
  1820   1917       }
  1821   1918     }else{
  1822   1919       /* Run commands received from standard input
  1823   1920       */
  1824         -    if( isatty(fileno(stdout)) && isatty(fileno(stdin)) ){
         1921  +    if( stdin_is_interactive ){
  1825   1922         char *zHome;
  1826   1923         char *zHistory = 0;
  1827   1924         printf(
  1828   1925           "SQLite version %s\n"
  1829   1926           "Enter \".help\" for instructions\n",
  1830   1927           sqlite3_libversion()
  1831   1928         );
................................................................................
  1832   1929         zHome = find_home_dir();
  1833   1930         if( zHome && (zHistory = malloc(strlen(zHome)+20))!=0 ){
  1834   1931           sprintf(zHistory,"%s/.sqlite_history", zHome);
  1835   1932         }
  1836   1933   #if defined(HAVE_READLINE) && HAVE_READLINE==1
  1837   1934         if( zHistory ) read_history(zHistory);
  1838   1935   #endif
  1839         -      process_input(&data, 0);
         1936  +      rc = process_input(&data, 0);
  1840   1937         if( zHistory ){
  1841   1938           stifle_history(100);
  1842   1939           write_history(zHistory);
  1843   1940           free(zHistory);
  1844   1941         }
  1845   1942         free(zHome);
  1846   1943       }else{
  1847         -      process_input(&data, stdin);
         1944  +      rc = process_input(&data, stdin);
  1848   1945       }
  1849   1946     }
  1850   1947     set_table_name(&data, 0);
  1851   1948     if( db ){
  1852   1949       if( sqlite3_close(db)!=SQLITE_OK ){
  1853   1950         fprintf(stderr,"error closing database: %s\n", sqlite3_errmsg(db));
  1854   1951       }
  1855   1952     }
  1856         -  return 0;
         1953  +  return rc;
  1857   1954   }

Changes to SQLite.Interop/src/sqlite3.h.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the SQLite library
    13     13   ** presents to client programs.
    14     14   **
    15         -** @(#) $Id: sqlite3.h,v 1.25 2006/10/12 21:34:22 rmsimpson Exp $
           15  +** @(#) $Id: sqlite3.h,v 1.26 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #ifndef _SQLITE3_H_
    18     18   #define _SQLITE3_H_
    19     19   #include <stdarg.h>     /* Needed for the definition of va_list */
    20     20   
    21     21   /*
    22     22   ** Make sure we can call this stuff from C++.
................................................................................
    27     27   
    28     28   /*
    29     29   ** The version of the SQLite library.
    30     30   */
    31     31   #ifdef SQLITE_VERSION
    32     32   # undef SQLITE_VERSION
    33     33   #endif
    34         -#define SQLITE_VERSION         "3.3.8"
           34  +#define SQLITE_VERSION         "3.3.10"
    35     35   
    36     36   /*
    37     37   ** The format of the version string is "X.Y.Z<trailing string>", where
    38     38   ** X is the major version number, Y is the minor version number and Z
    39     39   ** is the release number. The trailing string is often "alpha" or "beta".
    40     40   ** For example "3.1.1beta".
    41     41   **
................................................................................
    44     44   ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
    45     45   ** version 3.1.1 or greater at compile time, programs may use the test 
    46     46   ** (SQLITE_VERSION_NUMBER>=3001001).
    47     47   */
    48     48   #ifdef SQLITE_VERSION_NUMBER
    49     49   # undef SQLITE_VERSION_NUMBER
    50     50   #endif
    51         -#define SQLITE_VERSION_NUMBER 3003008
           51  +#define SQLITE_VERSION_NUMBER 3003010
    52     52   
    53     53   /*
    54     54   ** The version string is also compiled into the library so that a program
    55     55   ** can check to make sure that the lib*.a file and the *.h file are from
    56     56   ** the same version.  The sqlite3_libversion() function returns a pointer
    57     57   ** to the sqlite3_version variable - useful in DLLs which cannot access
    58     58   ** global variables.
................................................................................
   121    121   ** If one or more of the SQL statements are queries, then
   122    122   ** the callback function specified by the 3rd parameter is
   123    123   ** invoked once for each row of the query result.  This callback
   124    124   ** should normally return 0.  If the callback returns a non-zero
   125    125   ** value then the query is aborted, all subsequent SQL statements
   126    126   ** are skipped and the sqlite3_exec() function returns the SQLITE_ABORT.
   127    127   **
   128         -** The 4th parameter is an arbitrary pointer that is passed
          128  +** The 1st parameter is an arbitrary pointer that is passed
   129    129   ** to the callback function as its first parameter.
   130    130   **
   131    131   ** The 2nd parameter to the callback function is the number of
   132    132   ** columns in the query result.  The 3rd parameter to the callback
   133    133   ** is an array of strings holding the values for each column.
   134    134   ** The 4th parameter to the callback is an array of strings holding
   135    135   ** the names of each column.
................................................................................
   311    311   
   312    312   /*
   313    313   ** This routine identifies a callback function that is invoked
   314    314   ** whenever an attempt is made to open a database table that is
   315    315   ** currently locked by another process or thread.  If the busy callback
   316    316   ** is NULL, then sqlite3_exec() returns SQLITE_BUSY immediately if
   317    317   ** it finds a locked table.  If the busy callback is not NULL, then
   318         -** sqlite3_exec() invokes the callback with three arguments.  The
   319         -** second argument is the name of the locked table and the third
   320         -** argument is the number of times the table has been busy.  If the
          318  +** sqlite3_exec() invokes the callback with two arguments.  The
          319  +** first argument to the handler is a copy of the void* pointer which
          320  +** is the third argument to this routine.  The second argument to
          321  +** the handler is the number of times that the busy handler has
          322  +** been invoked for this locking event.  If the
   321    323   ** busy callback returns 0, then sqlite3_exec() immediately returns
   322    324   ** SQLITE_BUSY.  If the callback returns non-zero, then sqlite3_exec()
   323    325   ** tries to open the table again and the cycle repeats.
          326  +**
          327  +** The presence of a busy handler does not guarantee that
          328  +** it will be invoked when there is lock contention.
          329  +** If SQLite determines that invoking the busy handler could result in
          330  +** a deadlock, it will return SQLITE_BUSY instead.
          331  +** Consider a scenario where one process is holding a read lock that
          332  +** it is trying to promote to a reserved lock and
          333  +** a second process is holding a reserved lock that it is trying
          334  +** to promote to an exclusive lock.  The first process cannot proceed
          335  +** because it is blocked by the second and the second process cannot
          336  +** proceed because it is blocked by the first.  If both processes
          337  +** invoke the busy handlers, neither will make any progress.  Therefore,
          338  +** SQLite returns SQLITE_BUSY for the first process, hoping that this
          339  +** will induce the first process to release its read lock and allow
          340  +** the second process to proceed.
   324    341   **
   325    342   ** The default busy callback is NULL.
   326    343   **
   327    344   ** Sqlite is re-entrant, so the busy handler may start a new query. 
   328    345   ** (It is not clear why anyone would every want to do this, but it
   329    346   ** is allowed, in theory.)  But the busy handler may not close the
   330    347   ** database.  Closing the database from a busy handler will delete 
................................................................................
   681    698     sqlite3 *db,            /* Database handle */
   682    699     const char *zSql,       /* SQL statement, UTF-8 encoded */
   683    700     int nBytes,             /* Length of zSql in bytes. */
   684    701     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
   685    702     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
   686    703   );
   687    704   int sqlite3_prepare16(
          705  +  sqlite3 *db,            /* Database handle */
          706  +  const void *zSql,       /* SQL statement, UTF-16 encoded */
          707  +  int nBytes,             /* Length of zSql in bytes. */
          708  +  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
          709  +  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
          710  +);
          711  +
          712  +/*
          713  +** Newer versions of the prepare API work just like the legacy versions
          714  +** but with one exception:  The a copy of the SQL text is saved in the
          715  +** sqlite3_stmt structure that is returned.  If this copy exists, it
          716  +** modifieds the behavior of sqlite3_step() slightly.  First, sqlite3_step()
          717  +** will no longer return an SQLITE_SCHEMA error but will instead automatically
          718  +** rerun the compiler to rebuild the prepared statement.  Secondly, 
          719  +** sqlite3_step() now turns a full result code - the result code that
          720  +** use used to have to call sqlite3_reset() to get.
          721  +*/
          722  +int sqlite3_prepare_v2(
          723  +  sqlite3 *db,            /* Database handle */
          724  +  const char *zSql,       /* SQL statement, UTF-8 encoded */
          725  +  int nBytes,             /* Length of zSql in bytes. */
          726  +  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
          727  +  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
          728  +);
          729  +int sqlite3_prepare16_v2(
   688    730     sqlite3 *db,            /* Database handle */
   689    731     const void *zSql,       /* SQL statement, UTF-16 encoded */
   690    732     int nBytes,             /* Length of zSql in bytes. */
   691    733     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
   692    734     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
   693    735   );
   694    736   

Changes to SQLite.Interop/src/sqlite3ext.h.

    11     11   *************************************************************************
    12     12   ** This header file defines the SQLite interface for use by
    13     13   ** shared libraries that want to be imported as extensions into
    14     14   ** an SQLite instance.  Shared libraries that intend to be loaded
    15     15   ** as extensions by SQLite should #include this file instead of 
    16     16   ** sqlite3.h.
    17     17   **
    18         -** @(#) $Id: sqlite3ext.h,v 1.2 2006/10/12 21:34:22 rmsimpson Exp $
           18  +** @(#) $Id: sqlite3ext.h,v 1.3 2007/01/10 14:50:46 rmsimpson Exp $
    19     19   */
    20     20   #ifndef _SQLITE3EXT_H_
    21     21   #define _SQLITE3EXT_H_
    22     22   #include "sqlite3.h"
    23     23   
    24     24   typedef struct sqlite3_api_routines sqlite3_api_routines;
    25     25   
................................................................................
    88     88     int  (*finalize)(sqlite3_stmt*pStmt);
    89     89     void  (*free)(void*);
    90     90     void  (*free_table)(char**result);
    91     91     int  (*get_autocommit)(sqlite3*);
    92     92     void * (*get_auxdata)(sqlite3_context*,int);
    93     93     int  (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
    94     94     int  (*global_recover)(void);
    95         -  void  (*interrupt)(sqlite3*);
           95  +  void  (*interruptx)(sqlite3*);
    96     96     sqlite_int64  (*last_insert_rowid)(sqlite3*);
    97     97     const char * (*libversion)(void);
    98     98     int  (*libversion_number)(void);
    99     99     void *(*malloc)(int);
   100    100     char * (*mprintf)(const char*,...);
   101    101     int  (*open)(const char*,sqlite3**);
   102    102     int  (*open16)(const void*,sqlite3**);
................................................................................
   218    218   #define sqlite3_finalize               sqlite3_api->finalize
   219    219   #define sqlite3_free                   sqlite3_api->free
   220    220   #define sqlite3_free_table             sqlite3_api->free_table
   221    221   #define sqlite3_get_autocommit         sqlite3_api->get_autocommit
   222    222   #define sqlite3_get_auxdata            sqlite3_api->get_auxdata
   223    223   #define sqlite3_get_table              sqlite3_api->get_table
   224    224   #define sqlite3_global_recover         sqlite3_api->global_recover
   225         -#define sqlite3_interrupt              sqlite3_api->interrupt
          225  +#define sqlite3_interrupt              sqlite3_api->interruptx
   226    226   #define sqlite3_last_insert_rowid      sqlite3_api->last_insert_rowid
   227    227   #define sqlite3_libversion             sqlite3_api->libversion
   228    228   #define sqlite3_libversion_number      sqlite3_api->libversion_number
   229    229   #define sqlite3_malloc                 sqlite3_api->malloc
   230    230   #define sqlite3_mprintf                sqlite3_api->mprintf
   231    231   #define sqlite3_open                   sqlite3_api->open
   232    232   #define sqlite3_open16                 sqlite3_api->open16

Changes to SQLite.Interop/src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Extra interface definitions for those who need them
    21     21   */
................................................................................
   459    459     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
   460    460     struct sqlite3InitInfo {      /* Information used during initialization */
   461    461       int iDb;                    /* When back is being initialized */
   462    462       int newTnum;                /* Rootpage of table being initialized */
   463    463       u8 busy;                    /* TRUE if currently initializing */
   464    464     } init;
   465    465     int nExtension;               /* Number of loaded extensions */
   466         -  void *aExtension;             /* Array of shared libraray handles */
          466  +  void **aExtension;            /* Array of shared libraray handles */
   467    467     struct Vdbe *pVdbe;           /* List of active virtual machines */
   468    468     int activeVdbeCnt;            /* Number of vdbes currently executing */
   469    469     void (*xTrace)(void*,const char*);        /* Trace function */
   470    470     void *pTraceArg;                          /* Argument to the trace function */
   471    471     void (*xProfile)(void*,const char*,u64);  /* Profiling function */
   472    472     void *pProfileArg;                        /* Argument to profile function */
   473    473     void *pCommitArg;                 /* Argument to xCommitCallback() */   
................................................................................
  1613   1613   void sqlite3DropTable(Parse*, SrcList*, int, int);
  1614   1614   void sqlite3DeleteTable(sqlite3*, Table*);
  1615   1615   void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  1616   1616   int sqlite3ArrayAllocate(void**,int,int);
  1617   1617   IdList *sqlite3IdListAppend(IdList*, Token*);
  1618   1618   int sqlite3IdListIndex(IdList*,const char*);
  1619   1619   SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
  1620         -void sqlite3SrcListAddAlias(SrcList*, Token*);
         1620  +SrcList *sqlite3SrcListAppendFromTerm(SrcList*, Token*, Token*, Token*,
         1621  +                                      Select*, Expr*, IdList*);
         1622  +void sqlite3SrcListShiftJoinType(SrcList*);
  1621   1623   void sqlite3SrcListAssignCursors(Parse*, SrcList*);
  1622   1624   void sqlite3IdListDelete(IdList*);
  1623   1625   void sqlite3SrcListDelete(SrcList*);
  1624   1626   void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  1625   1627                           Token*, int, int);
  1626   1628   void sqlite3DropIndex(Parse*, SrcList*, int);
  1627   1629   void sqlite3AddKeyType(Vdbe*, ExprList*);
................................................................................
  1872   1874   void sqlite3VtabArgExtend(Parse*, Token*);
  1873   1875   int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
  1874   1876   int sqlite3VtabCallConnect(Parse*, Table*);
  1875   1877   int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
  1876   1878   int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
  1877   1879   FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*);
  1878   1880   void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
         1881  +int sqlite3Reprepare(Vdbe*);
  1879   1882   
  1880   1883   #ifdef SQLITE_SSE
  1881   1884   #include "sseInt.h"
  1882   1885   #endif
  1883   1886   
  1884   1887   #endif

Changes to SQLite.Interop/src/tclsqlite.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** A TCL Interface to SQLite
    13     13   **
    14         -** $Id: tclsqlite.c,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           14  +** $Id: tclsqlite.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    15     15   */
    16     16   #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
    17     17   
    18     18   #include "sqliteInt.h"
    19     19   #include "hash.h"
    20     20   #include "tcl.h"
    21     21   #include <stdlib.h>
................................................................................
  1169   1169     /*
  1170   1170     **    $db enable_load_extension BOOLEAN
  1171   1171     **
  1172   1172     ** Turn the extension loading feature on or off.  It if off by
  1173   1173     ** default.
  1174   1174     */
  1175   1175     case DB_ENABLE_LOAD_EXTENSION: {
         1176  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1176   1177       int onoff;
  1177   1178       if( objc!=3 ){
  1178   1179         Tcl_WrongNumArgs(interp, 2, objv, "BOOLEAN");
  1179   1180         return TCL_ERROR;
  1180   1181       }
  1181   1182       if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){
  1182   1183         return TCL_ERROR;
  1183   1184       }
  1184   1185       sqlite3_enable_load_extension(pDb->db, onoff);
  1185   1186       break;
         1187  +#else
         1188  +    Tcl_AppendResult(interp, "extension loading is turned off at compile-time",
         1189  +                     0);
         1190  +    return TCL_ERROR;
         1191  +#endif
  1186   1192     }
  1187   1193   
  1188   1194     /*
  1189   1195     **    $db errorcode
  1190   1196     **
  1191   1197     ** Return the numeric error code that was returned by the most recent
  1192   1198     ** call to sqlite3_exec().
................................................................................
  2051   2057     }
  2052   2058     memset(p, 0, sizeof(*p));
  2053   2059     zFile = Tcl_GetStringFromObj(objv[2], 0);
  2054   2060     zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename);
  2055   2061     sqlite3_open(zFile, &p->db);
  2056   2062     Tcl_DStringFree(&translatedFilename);
  2057   2063     if( SQLITE_OK!=sqlite3_errcode(p->db) ){
  2058         -    zErrMsg = strdup(sqlite3_errmsg(p->db));
         2064  +    zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
  2059   2065       sqlite3_close(p->db);
  2060   2066       p->db = 0;
  2061   2067     }
  2062   2068   #ifdef SQLITE_HAS_CODEC
  2063   2069     sqlite3_key(p->db, pKey, nKey);
  2064   2070   #endif
  2065   2071     if( p->db==0 ){
  2066   2072       Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
  2067   2073       Tcl_Free((char*)p);
  2068         -    free(zErrMsg);
         2074  +    sqlite3_free(zErrMsg);
  2069   2075       return TCL_ERROR;
  2070   2076     }
  2071   2077     p->maxStmt = NUM_PREPARED_STMTS;
  2072   2078     p->interp = interp;
  2073   2079     zArg = Tcl_GetStringFromObj(objv[1], 0);
  2074   2080     Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd);
  2075   2081   

Changes to SQLite.Interop/src/tokenize.c.

    11     11   *************************************************************************
    12     12   ** An tokenizer for SQL
    13     13   **
    14     14   ** This file contains C code that splits an SQL input string up into
    15     15   ** individual tokens and sends those tokens one-by-one over to the
    16     16   ** parser for analysis.
    17     17   **
    18         -** $Id: tokenize.c,v 1.27 2006/10/12 21:34:22 rmsimpson Exp $
           18  +** $Id: tokenize.c,v 1.28 2007/01/10 14:50:46 rmsimpson Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include "os.h"
    22     22   #include <ctype.h>
    23     23   #include <stdlib.h>
    24     24   
    25     25   /*

Changes to SQLite.Interop/src/trigger.c.

   664    664     sqlite3VdbeAddOp(v, OP_ContextPush, 0, 0);
   665    665     VdbeComment((v, "# begin trigger %s", pStepList->pTrig->name));
   666    666     while( pTriggerStep ){
   667    667       orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
   668    668       pParse->trigStack->orconf = orconf;
   669    669       switch( pTriggerStep->op ){
   670    670         case TK_SELECT: {
   671         -	Select * ss = sqlite3SelectDup(pTriggerStep->pSelect);		  
   672         -	assert(ss);
   673         -	assert(ss->pSrc);
   674         -        sqlite3SelectResolve(pParse, ss, 0);
   675         -	sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
   676         -	sqlite3SelectDelete(ss);
          671  +	Select *ss = sqlite3SelectDup(pTriggerStep->pSelect);
          672  +        if( ss ){
          673  +          sqlite3SelectResolve(pParse, ss, 0);
          674  +          sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
          675  +          sqlite3SelectDelete(ss);
          676  +        }
   677    677   	break;
   678    678         }
   679    679         case TK_UPDATE: {
   680    680           SrcList *pSrc;
   681    681           pSrc = targetSrcList(pParse, pTriggerStep);
   682    682           sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
   683    683           sqlite3Update(pParse, pSrc,

Changes to SQLite.Interop/src/update.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle UPDATE statements.
    14     14   **
    15         -** $Id: update.c,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           15  +** $Id: update.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   #ifndef SQLITE_OMIT_VIRTUALTABLE
    20     20   /* Forward declaration */
    21     21   static void updateVirtualTable(
    22     22     Parse *pParse,       /* The parsing context */

Changes to SQLite.Interop/src/utf.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used to translate between UTF-8, 
    13     13   ** UTF-16, UTF-16BE, and UTF-16LE.
    14     14   **
    15         -** $Id: utf.c,v 1.23 2006/10/12 21:34:22 rmsimpson Exp $
           15  +** $Id: utf.c,v 1.24 2007/01/10 14:50:46 rmsimpson Exp $
    16     16   **
    17     17   ** Notes on UTF-8:
    18     18   **
    19     19   **   Byte-0    Byte-1    Byte-2    Byte-3    Value
    20     20   **  0xxxxxxx                                 00000000 00000000 0xxxxxxx
    21     21   **  110yyyyy  10xxxxxx                       00000000 00000yyy yyxxxxxx
    22     22   **  1110zzzz  10yyyyyy  10xxxxxx             00000000 zzzzyyyy yyxxxxxx
................................................................................
    60     60   */
    61     61   #include "sqliteInt.h"
    62     62   #include <assert.h>
    63     63   #include "vdbeInt.h"
    64     64   
    65     65   /*
    66     66   ** This table maps from the first byte of a UTF-8 character to the number
    67         -** of trailing bytes expected. A value '255' indicates that the table key
           67  +** of trailing bytes expected. A value '4' indicates that the table key
    68     68   ** is not a legal first byte for a UTF-8 character.
    69     69   */
    70     70   static const u8 xtra_utf8_bytes[256]  = {
    71     71   /* 0xxxxxxx */
    72     72   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    73     73   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    74     74   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
................................................................................
    75     75   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    76     76   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    77     77   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    78     78   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    79     79   0, 0, 0, 0, 0, 0, 0, 0,     0, 0, 0, 0, 0, 0, 0, 0,
    80     80   
    81     81   /* 10wwwwww */
    82         -255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    83         -255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    84         -255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    85         -255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
           82  +4, 4, 4, 4, 4, 4, 4, 4,     4, 4, 4, 4, 4, 4, 4, 4,
           83  +4, 4, 4, 4, 4, 4, 4, 4,     4, 4, 4, 4, 4, 4, 4, 4,
           84  +4, 4, 4, 4, 4, 4, 4, 4,     4, 4, 4, 4, 4, 4, 4, 4,
           85  +4, 4, 4, 4, 4, 4, 4, 4,     4, 4, 4, 4, 4, 4, 4, 4,
    86     86   
    87     87   /* 110yyyyy */
    88     88   1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1,
    89     89   1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1,
    90     90   
    91     91   /* 1110zzzz */
    92     92   2, 2, 2, 2, 2, 2, 2, 2,     2, 2, 2, 2, 2, 2, 2, 2,
    93     93   
    94     94   /* 11110yyy */
    95         -3, 3, 3, 3, 3, 3, 3, 3,     255, 255, 255, 255, 255, 255, 255, 255,
           95  +3, 3, 3, 3, 3, 3, 3, 3,     4, 4, 4, 4, 4, 4, 4, 4,
    96     96   };
    97     97   
    98     98   /*
    99     99   ** This table maps from the number of trailing bytes in a UTF-8 character
   100    100   ** to an integer constant that is effectively calculated for each character
   101    101   ** read by a naive implementation of a UTF-8 character reader. The code
   102    102   ** in the READ_UTF8 macro explains things best.
   103    103   */
   104         -static const int xtra_utf8_bits[4] =  {
   105         -0,
   106         -12416,          /* (0xC0 << 6) + (0x80) */
   107         -925824,         /* (0xE0 << 12) + (0x80 << 6) + (0x80) */
   108         -63447168        /* (0xF0 << 18) + (0x80 << 12) + (0x80 << 6) + 0x80 */
          104  +static const int xtra_utf8_bits[] =  {
          105  +  0,
          106  +  12416,          /* (0xC0 << 6) + (0x80) */
          107  +  925824,         /* (0xE0 << 12) + (0x80 << 6) + (0x80) */
          108  +  63447168        /* (0xF0 << 18) + (0x80 << 12) + (0x80 << 6) + 0x80 */
          109  +};
          110  +
          111  +/*
          112  +** If a UTF-8 character contains N bytes extra bytes (N bytes follow
          113  +** the initial byte so that the total character length is N+1) then
          114  +** masking the character with utf8_mask[N] must produce a non-zero
          115  +** result.  Otherwise, we have an (illegal) overlong encoding.
          116  +*/
          117  +static const int utf_mask[] = {
          118  +  0x00000000,
          119  +  0xffffff80,
          120  +  0xfffff800,
          121  +  0xffff0000,
   109    122   };
   110    123   
   111    124   #define READ_UTF8(zIn, c) { \
   112    125     int xtra;                                            \
   113    126     c = *(zIn)++;                                        \
   114    127     xtra = xtra_utf8_bytes[c];                           \
   115    128     switch( xtra ){                                      \
   116         -    case 255: c = (int)0xFFFD; break;                  \
          129  +    case 4: c = (int)0xFFFD; break;                    \
   117    130       case 3: c = (c<<6) + *(zIn)++;                     \
   118    131       case 2: c = (c<<6) + *(zIn)++;                     \
   119    132       case 1: c = (c<<6) + *(zIn)++;                     \
   120    133       c -= xtra_utf8_bits[xtra];                         \
          134  +    if( (utf_mask[xtra]&c)==0                          \
          135  +        || (c&0xFFFFF800)==0xD800                      \
          136  +        || (c&0xFFFFFFFE)==0xFFFE ){  c = 0xFFFD; }    \
   121    137     }                                                    \
   122    138   }
   123    139   int sqlite3ReadUtf8(const unsigned char *z){
   124    140     int c;
   125    141     READ_UTF8(z, c);
   126    142     return c;
   127    143   }
................................................................................
   177    193   #define READ_UTF16LE(zIn, c){                                         \
   178    194     c = (*zIn++);                                                       \
   179    195     c += ((*zIn++)<<8);                                                 \
   180    196     if( c>=0xD800 && c<=0xE000 ){                                       \
   181    197       int c2 = (*zIn++);                                                \
   182    198       c2 += ((*zIn++)<<8);                                              \
   183    199       c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10);   \
          200  +    if( (c & 0xFFFF0000)==0 ) c = 0xFFFD;                             \
   184    201     }                                                                   \
   185    202   }
   186    203   
   187    204   #define READ_UTF16BE(zIn, c){                                         \
   188    205     c = ((*zIn++)<<8);                                                  \
   189    206     c += (*zIn++);                                                      \
   190    207     if( c>=0xD800 && c<=0xE000 ){                                       \
   191    208       int c2 = ((*zIn++)<<8);                                           \
   192    209       c2 += (*zIn++);                                                   \
   193    210       c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10);   \
          211  +    if( (c & 0xFFFF0000)==0 ) c = 0xFFFD;                             \
   194    212     }                                                                   \
   195    213   }
   196    214   
   197    215   #define SKIP_UTF16BE(zIn){                                            \
   198    216     if( *zIn>=0xD8 && (*zIn<0xE0 || (*zIn==0xE0 && *(zIn+1)==0x00)) ){  \
   199    217       zIn += 4;                                                         \
   200    218     }else{                                                              \
................................................................................
   552    570   #if defined(SQLITE_TEST)
   553    571   /*
   554    572   ** This routine is called from the TCL test function "translate_selftest".
   555    573   ** It checks that the primitives for serializing and deserializing
   556    574   ** characters in each encoding are inverses of each other.
   557    575   */
   558    576   void sqlite3utfSelfTest(){
   559         -  unsigned int i;
          577  +  unsigned int i, t;
   560    578     unsigned char zBuf[20];
   561    579     unsigned char *z;
   562    580     int n;
   563    581     unsigned int c;
   564    582   
   565    583     for(i=0; i<0x00110000; i++){
   566    584       z = zBuf;
   567    585       WRITE_UTF8(z, i);
   568    586       n = z-zBuf;
   569    587       z = zBuf;
   570    588       READ_UTF8(z, c);
   571         -    assert( c==i );
          589  +    t = i;
          590  +    if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
          591  +    if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
          592  +    assert( c==t );
   572    593       assert( (z-zBuf)==n );
   573    594     }
   574    595     for(i=0; i<0x00110000; i++){
   575    596       if( i>=0xD800 && i<=0xE000 ) continue;
   576    597       z = zBuf;
   577    598       WRITE_UTF16LE(z, i);
   578    599       n = z-zBuf;

Changes to SQLite.Interop/src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.25 2006/10/12 21:34:22 rmsimpson Exp $
           17  +** $Id: util.c,v 1.26 2007/01/10 14:50:46 rmsimpson Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <stdarg.h>
    22     22   #include <ctype.h>
    23     23   
    24     24   /*

Changes to SQLite.Interop/src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           17  +** $Id: vacuum.c,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "vdbeInt.h"
    21     21   #include "os.h"
    22     22   
    23     23   #ifndef SQLITE_OMIT_VACUUM
    24         -/*
    25         -** Generate a random name of 20 character in length.
    26         -*/
    27         -static void randomName(unsigned char *zBuf){
    28         -  static const unsigned char zChars[] =
    29         -    "abcdefghijklmnopqrstuvwxyz"
    30         -    "0123456789";
    31         -  int i;
    32         -  sqlite3Randomness(20, zBuf);
    33         -  for(i=0; i<20; i++){
    34         -    zBuf[i] = zChars[ zBuf[i]%(sizeof(zChars)-1) ];
    35         -  }
    36         -}
    37         -
    38     24   /*
    39     25   ** Execute zSql on database db. Return an error code.
    40     26   */
    41     27   static int execSql(sqlite3 *db, const char *zSql){
    42     28     sqlite3_stmt *pStmt;
    43     29     if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
    44     30       return sqlite3_errcode(db);
................................................................................
    88     74   }
    89     75   
    90     76   /*
    91     77   ** This routine implements the OP_Vacuum opcode of the VDBE.
    92     78   */
    93     79   int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
    94     80     int rc = SQLITE_OK;     /* Return code from service routines */
    95         -  const char *zFilename;  /* full pathname of the database file */
    96         -  int nFilename;          /* number of characters  in zFilename[] */
    97         -  char *zTemp = 0;        /* a temporary file in same directory as zFilename */
    98     81     Btree *pMain;           /* The database being vacuumed */
    99         -  Btree *pTemp;
   100         -  char *zSql = 0;
   101         -  int saved_flags;       /* Saved value of the db->flags */
   102         -  Db *pDb = 0;           /* Database to detach at end of vacuum */
           82  +  Btree *pTemp;           /* The temporary database we vacuum into */
           83  +  char *zSql = 0;         /* SQL statements */
           84  +  int saved_flags;        /* Saved value of the db->flags */
           85  +  Db *pDb = 0;            /* Database to detach at end of vacuum */
           86  +  char zTemp[SQLITE_TEMPNAME_SIZE+20];  /* Name of the TEMP file */
   103     87   
   104     88     /* Save the current value of the write-schema flag before setting it. */
   105     89     saved_flags = db->flags;
   106     90     db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
   107     91   
           92  +  sqlite3OsTempFileName(zTemp);
   108     93     if( !db->autoCommit ){
   109     94       sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", 
   110     95          (char*)0);
   111     96       rc = SQLITE_ERROR;
   112     97       goto end_of_vacuum;
   113     98     }
   114         -
   115         -  /* Get the full pathname of the database file and create a
   116         -  ** temporary filename in the same directory as the original file.
   117         -  */
   118     99     pMain = db->aDb[0].pBt;
   119         -  zFilename = sqlite3BtreeGetFilename(pMain);
   120         -  assert( zFilename );
   121         -  if( zFilename[0]=='\0' ){
   122         -    /* The in-memory database. Do nothing. Return directly to avoid causing
   123         -    ** an error trying to DETACH the vacuum_db (which never got attached)
   124         -    ** in the exit-handler.
   125         -    */
   126         -    return SQLITE_OK;
   127         -  }
   128         -  nFilename = strlen(zFilename);
   129         -  zTemp = sqliteMalloc( nFilename+100 );
   130         -  if( zTemp==0 ){
   131         -    rc = SQLITE_NOMEM;
   132         -    goto end_of_vacuum;
   133         -  }
   134         -  strcpy(zTemp, zFilename);
   135         -
   136         -  /* The randomName() procedure in the following loop uses an excellent
   137         -  ** source of randomness to generate a name from a space of 1.3e+31 
   138         -  ** possibilities.  So unless the directory already contains on the order
   139         -  ** of 1.3e+31 files, the probability that the following loop will
   140         -  ** run more than once or twice is vanishingly small.  We are certain
   141         -  ** enough that this loop will always terminate (and terminate quickly)
   142         -  ** that we don't even bother to set a maximum loop count.
   143         -  */
   144         -  do {
   145         -    zTemp[nFilename] = '-';
   146         -    randomName((unsigned char*)&zTemp[nFilename+1]);
   147         -  } while( sqlite3OsFileExists(zTemp) );
   148    100   
   149    101     /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
   150    102     ** can be set to 'off' for this file, as it is not recovered if a crash
   151    103     ** occurs anyway. The integrity of the database is maintained by a
   152    104     ** (possibly synchronous) transaction opened on the main database before
   153    105     ** sqlite3BtreeCopyFile() is called.
   154    106     **
................................................................................
   303    255       sqlite3MallocDisallow();
   304    256       sqlite3BtreeClose(pDb->pBt);
   305    257       sqlite3MallocAllow();
   306    258       pDb->pBt = 0;
   307    259       pDb->pSchema = 0;
   308    260     }
   309    261   
   310         -  if( zTemp ){
   311         -    sqlite3OsDelete(zTemp);
   312         -    sqliteFree(zTemp);
   313         -  }
          262  +  sqlite3OsDelete(zTemp);
          263  +  strcat(zTemp, "-journal");
          264  +  sqlite3OsDelete(zTemp);
   314    265     sqliteFree( zSql );
   315    266     sqlite3ResetInternalSchema(db, 0);
   316    267   
   317    268     return rc;
   318    269   }
   319    270   #endif  /* SQLITE_OMIT_VACUUM */

Changes to SQLite.Interop/src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.26 2006/10/12 21:34:22 rmsimpson Exp $
           46  +** $Id: vdbe.c,v 1.27 2007/01/10 14:50:46 rmsimpson Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
   450    450     if( p->popStack ){
   451    451       popStack(&pTos, p->popStack);
   452    452       p->popStack = 0;
   453    453     }
   454    454     p->resOnStack = 0;
   455    455     db->busyHandler.nBusy = 0;
   456    456     CHECK_FOR_INTERRUPT;
          457  +#ifdef SQLITE_DEBUG
          458  +  if( (p->db->flags & SQLITE_VdbeListing)!=0
          459  +    || sqlite3OsFileExists("vdbe_explain")
          460  +  ){
          461  +    int i;
          462  +    printf("VDBE Program Listing:\n");
          463  +    sqlite3VdbePrintSql(p);
          464  +    for(i=0; i<p->nOp; i++){
          465  +      sqlite3VdbePrintOp(stdout, i, &p->aOp[i]);
          466  +    }
          467  +  }
          468  +  if( sqlite3OsFileExists("vdbe_trace") ){
          469  +    p->trace = stdout;
          470  +  }
          471  +#endif
   457    472     for(pc=p->pc; rc==SQLITE_OK; pc++){
   458    473       assert( pc>=0 && pc<p->nOp );
   459    474       assert( pTos<=&p->aStack[pc] );
   460    475       if( sqlite3MallocFailed() ) goto no_mem;
   461    476   #ifdef VDBE_PROFILE
   462    477       origPc = pc;
   463    478       start = hwtime();
................................................................................
  1808   1823     pTos--;
  1809   1824     if( c ) pc = pOp->p2-1;
  1810   1825     break;
  1811   1826   }
  1812   1827   
  1813   1828   /* Opcode: IsNull P1 P2 *
  1814   1829   **
  1815         -** If any of the top abs(P1) values on the stack are NULL, then jump
  1816         -** to P2.  Pop the stack P1 times if P1>0.   If P1<0 leave the stack
  1817         -** unchanged.
         1830  +** Check the top of the stack and jump to P2 if the top of the stack
         1831  +** is NULL.  If P1 is positive, then pop P1 elements from the stack
         1832  +** regardless of whether or not the jump is taken.  If P1 is negative,
         1833  +** pop -P1 elements from the stack only if the jump is taken and leave
         1834  +** the stack unchanged if the jump is not taken.
  1818   1835   */
  1819   1836   case OP_IsNull: {            /* same as TK_ISNULL, no-push */
  1820         -  int i, cnt;
  1821         -  Mem *pTerm;
  1822         -  cnt = pOp->p1;
  1823         -  if( cnt<0 ) cnt = -cnt;
  1824         -  pTerm = &pTos[1-cnt];
  1825         -  assert( pTerm>=p->aStack );
  1826         -  for(i=0; i<cnt; i++, pTerm++){
  1827         -    if( pTerm->flags & MEM_Null ){
  1828         -      pc = pOp->p2-1;
  1829         -      break;
         1837  +  if( pTos->flags & MEM_Null ){
         1838  +    pc = pOp->p2-1;
         1839  +    if( pOp->p1<0 ){
         1840  +      popStack(&pTos, -pOp->p1);
  1830   1841       }
  1831   1842     }
  1832         -  if( pOp->p1>0 ) popStack(&pTos, cnt);
         1843  +  if( pOp->p1>0 ){
         1844  +    popStack(&pTos, pOp->p1);
         1845  +  }
  1833   1846     break;
  1834   1847   }
  1835   1848   
  1836   1849   /* Opcode: NotNull P1 P2 *
  1837   1850   **
  1838         -** Jump to P2 if the top P1 values on the stack are all not NULL.  Pop the
  1839         -** stack if P1 times if P1 is greater than zero.  If P1 is less than
  1840         -** zero then leave the stack unchanged.
         1851  +** Jump to P2 if the top abs(P1) values on the stack are all not NULL.  
         1852  +** Regardless of whether or not the jump is taken, pop the stack
         1853  +** P1 times if P1 is greater than zero.  But if P1 is negative,
         1854  +** leave the stack unchanged.
  1841   1855   */
  1842   1856   case OP_NotNull: {            /* same as TK_NOTNULL, no-push */
  1843   1857     int i, cnt;
  1844   1858     cnt = pOp->p1;
  1845   1859     if( cnt<0 ) cnt = -cnt;
  1846   1860     assert( &pTos[1-cnt] >= p->aStack );
  1847   1861     for(i=0; i<cnt && (pTos[1+i-cnt].flags & MEM_Null)==0; i++){}
................................................................................
  2006   2020         if( avail>=payloadSize ){
  2007   2021           zRec = zData;
  2008   2022           pC->aRow = (u8*)zData;
  2009   2023         }else{
  2010   2024           pC->aRow = 0;
  2011   2025         }
  2012   2026       }
  2013         -    assert( zRec!=0 || avail>=payloadSize || avail>=9 );
         2027  +    /* The following assert is true in all cases accept when
         2028  +    ** the database file has been corrupted externally.
         2029  +    **    assert( zRec!=0 || avail>=payloadSize || avail>=9 ); */
  2014   2030       szHdrSz = GetVarint((u8*)zData, offset);
  2015   2031   
  2016   2032       /* The KeyFetch() or DataFetch() above are fast and will get the entire
  2017   2033       ** record header in most cases.  But they will fail to get the complete
  2018   2034       ** record header if the record header does not fit on a single page
  2019   2035       ** in the B-Tree.  When that happens, use sqlite3VdbeMemFromBtree() to
  2020   2036       ** acquire the complete header text.
................................................................................
  3077   3093       assert( p->apCsr[i]->isTable );
  3078   3094       iKey = intToKey(pTos->i);
  3079   3095       rc = sqlite3BtreeMoveto(pCrsr, 0, iKey, &res);
  3080   3096       pC->lastRowid = pTos->i;
  3081   3097       pC->rowidIsValid = res==0;
  3082   3098       pC->nullRow = 0;
  3083   3099       pC->cacheStatus = CACHE_STALE;
         3100  +    /* res might be uninitialized if rc!=SQLITE_OK.  But if rc!=SQLITE_OK
         3101  +    ** processing is about to abort so we really do not care whether or not
         3102  +    ** the following jump is taken. */
  3084   3103       if( res!=0 ){
  3085   3104         pc = pOp->p2 - 1;
  3086   3105         pC->rowidIsValid = 0;
  3087   3106       }
  3088   3107     }
  3089   3108     Release(pTos);
  3090   3109     pTos--;
................................................................................
  3848   3867       }
  3849   3868     }
  3850   3869     Release(pTos);
  3851   3870     pTos--;
  3852   3871     break;
  3853   3872   }
  3854   3873   
  3855         -/* Opcode: IdxIsNull P1 P2 *
  3856         -**
  3857         -** The top of the stack contains an index entry such as might be generated
  3858         -** by the MakeIdxRec opcode.  This routine looks at the first P1 fields of
  3859         -** that key.  If any of the first P1 fields are NULL, then a jump is made
  3860         -** to address P2.  Otherwise we fall straight through.
  3861         -**
  3862         -** The index entry is always popped from the stack.
  3863         -*/
  3864         -case OP_IdxIsNull: {        /* no-push */
  3865         -  int i = pOp->p1;
  3866         -  int k, n;
  3867         -  const char *z;
  3868         -  u32 serial_type;
  3869         -
  3870         -  assert( pTos>=p->aStack );
  3871         -  assert( pTos->flags & MEM_Blob );
  3872         -  z = pTos->z;
  3873         -  n = pTos->n;
  3874         -  k = sqlite3GetVarint32((u8*)z, &serial_type);
  3875         -  for(; k<n && i>0; i--){
  3876         -    k += sqlite3GetVarint32((u8*)&z[k], &serial_type);
  3877         -    if( serial_type==0 ){   /* Serial type 0 is a NULL */
  3878         -      pc = pOp->p2-1;
  3879         -      break;
  3880         -    }
  3881         -  }
  3882         -  Release(pTos);
  3883         -  pTos--;
  3884         -  break;
  3885         -}
  3886         -
  3887   3874   /* Opcode: Destroy P1 P2 *
  3888   3875   **
  3889   3876   ** Delete an entire database table or index whose root page in the database
  3890   3877   ** file is given by P1.
  3891   3878   **
  3892   3879   ** The table being destroyed is in the main database file if P2==0.  If
  3893   3880   ** P2==1 then the table to be clear is in the auxiliary database file
................................................................................
  3902   3889   ** a zero is pushed onto the stack.  If AUTOVACUUM is disabled
  3903   3890   ** then a zero is pushed onto the stack.
  3904   3891   **
  3905   3892   ** See also: Clear
  3906   3893   */
  3907   3894   case OP_Destroy: {
  3908   3895     int iMoved;
  3909         -  Vdbe *pVdbe;
  3910   3896     int iCnt;
  3911   3897   #ifndef SQLITE_OMIT_VIRTUALTABLE
         3898  +  Vdbe *pVdbe;
  3912   3899     iCnt = 0;
  3913   3900     for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
  3914   3901       if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 ){
  3915   3902         iCnt++;
  3916   3903       }
  3917   3904     }
  3918   3905   #else
................................................................................
  4028   4015       pTos->flags = MEM_Int;
  4029   4016     }else{
  4030   4017       pTos->flags = MEM_Null;
  4031   4018     }
  4032   4019     break;
  4033   4020   }
  4034   4021   
  4035         -/* Opcode: ParseSchema P1 * P3
         4022  +/* Opcode: ParseSchema P1 P2 P3
  4036   4023   **
  4037   4024   ** Read and parse all entries from the SQLITE_MASTER table of database P1
  4038         -** that match the WHERE clause P3.
         4025  +** that match the WHERE clause P3.  P2 is the "force" flag.   Always do
         4026  +** the parsing if P2 is true.  If P2 is false, then this routine is a
         4027  +** no-op if the schema is not currently loaded.  In other words, if P2
         4028  +** is false, the SQLITE_MASTER table is only parsed if the rest of the
         4029  +** schema is already loaded into the symbol table.
  4039   4030   **
  4040   4031   ** This opcode invokes the parser to create a new virtual machine,
  4041   4032   ** then runs the new virtual machine.  It is thus a reentrant opcode.
  4042   4033   */
  4043   4034   case OP_ParseSchema: {        /* no-push */
  4044   4035     char *zSql;
  4045   4036     int iDb = pOp->p1;
  4046   4037     const char *zMaster;
  4047   4038     InitData initData;
  4048   4039   
  4049   4040     assert( iDb>=0 && iDb<db->nDb );
  4050         -  if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
         4041  +  if( !pOp->p2 && !DbHasProperty(db, iDb, DB_SchemaLoaded) ){
         4042  +    break;
         4043  +  }
  4051   4044     zMaster = SCHEMA_TABLE(iDb);
  4052   4045     initData.db = db;
  4053   4046     initData.iDb = pOp->p1;
  4054   4047     initData.pzErrMsg = &p->zErrMsg;
  4055   4048     zSql = sqlite3MPrintf(
  4056   4049        "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s",
  4057   4050        db->aDb[iDb].zName, zMaster, pOp->p3);
................................................................................
  4671   4664     pModule = pCur->pVtabCursor->pVtab->pModule;
  4672   4665   
  4673   4666     /* Grab the index number and argc parameters off the top of the stack. */
  4674   4667     assert( (&pTos[-1])>=p->aStack );
  4675   4668     assert( (pTos[0].flags&MEM_Int)!=0 && pTos[-1].flags==MEM_Int );
  4676   4669     nArg = pTos[-1].i;
  4677   4670   
  4678         -  /* Invoke the xFilter method if one is defined. */
  4679         -  if( pModule->xFilter ){
  4680         -    int res;
         4671  +  /* Invoke the xFilter method */
         4672  +  {
         4673  +    int res = 0;
  4681   4674       int i;
  4682   4675       Mem **apArg = p->apArg;
  4683   4676       for(i = 0; i<nArg; i++){
  4684   4677         apArg[i] = &pTos[i+1-2-nArg];
  4685   4678         storeTypeInfo(apArg[i], 0);
  4686   4679       }
  4687   4680   

Changes to SQLite.Interop/src/vdbe.h.

    11     11   *************************************************************************
    12     12   ** Header file for the Virtual DataBase Engine (VDBE)
    13     13   **
    14     14   ** This header defines the interface to the virtual database engine
    15     15   ** or VDBE.  The VDBE implements an abstract machine that runs a
    16     16   ** simple program to access and modify the underlying database.
    17     17   **
    18         -** $Id: vdbe.h,v 1.24 2006/10/12 21:34:22 rmsimpson Exp $
           18  +** $Id: vdbe.h,v 1.25 2007/01/10 14:50:46 rmsimpson Exp $
    19     19   */
    20     20   #ifndef _SQLITE_VDBE_H_
    21     21   #define _SQLITE_VDBE_H_
    22     22   #include <stdio.h>
    23     23   
    24     24   /*
    25     25   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
................................................................................
   125    125   int sqlite3VdbeMakeLabel(Vdbe*);
   126    126   void sqlite3VdbeDelete(Vdbe*);
   127    127   void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
   128    128   int sqlite3VdbeFinalize(Vdbe*);
   129    129   void sqlite3VdbeResolveLabel(Vdbe*, int);
   130    130   int sqlite3VdbeCurrentAddr(Vdbe*);
   131    131   void sqlite3VdbeTrace(Vdbe*,FILE*);
          132  +void sqlite3VdbeResetStepResult(Vdbe*);
   132    133   int sqlite3VdbeReset(Vdbe*);
   133    134   int sqliteVdbeSetVariables(Vdbe*,int,const char**);
   134    135   void sqlite3VdbeSetNumCols(Vdbe*,int);
   135    136   int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
   136    137   void sqlite3VdbeCountChanges(Vdbe*);
   137    138   sqlite3 *sqlite3VdbeDb(Vdbe*);
          139  +void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
          140  +const char *sqlite3VdbeGetSql(Vdbe*);
          141  +void sqlite3VdbeSwap(Vdbe*,Vdbe*);
   138    142   
   139    143   #ifndef NDEBUG
   140    144     void sqlite3VdbeComment(Vdbe*, const char*, ...);
   141    145   # define VdbeComment(X)  sqlite3VdbeComment X
   142    146   #else
   143    147   # define VdbeComment(X)
   144    148   #endif
   145    149   
   146    150   #endif

Changes to SQLite.Interop/src/vdbeInt.h.

   324    324     u8 changeCntOn;         /* True to update the change-counter */
   325    325     u8 aborted;             /* True if ROLLBACK in another VM causes an abort */
   326    326     u8 expired;             /* True if the VM needs to be recompiled */
   327    327     u8 minWriteFileFormat;  /* Minimum file format for writable database files */
   328    328     u8 inVtabMethod;        /* See comments above */
   329    329     int nChange;            /* Number of db changes made since last reset */
   330    330     i64 startTime;          /* Time when query started - used for profiling */
          331  +  int nSql;             /* Number of bytes in zSql */
          332  +  char *zSql;           /* Text of the SQL statement that generated this */
   331    333   #ifdef SQLITE_SSE
   332    334     int fetchId;          /* Statement number used by sqlite3_fetch_statement */
   333    335     int lru;              /* Counter used for LRU cache replacement */
   334    336   #endif
   335    337   };
   336    338   
   337    339   /*

Changes to SQLite.Interop/src/vdbeapi.c.

   149    149     sqlite3VdbeMemCopy(&pCtx->s, pValue);
   150    150   }
   151    151   
   152    152   
   153    153   /*
   154    154   ** Execute the statement pStmt, either until a row of data is ready, the
   155    155   ** statement is completely executed or an error occurs.
          156  +**
          157  +** This routine implements the bulk of the logic behind the sqlite_step()
          158  +** API.  The only thing omitted is the automatic recompile if a 
          159  +** schema change has occurred.  That detail is handled by the
          160  +** outer sqlite3_step() wrapper procedure.
   156    161   */
   157         -int sqlite3_step(sqlite3_stmt *pStmt){
   158         -  Vdbe *p = (Vdbe*)pStmt;
          162  +static int sqlite3Step(Vdbe *p){
   159    163     sqlite3 *db;
   160    164     int rc;
   161    165   
   162    166     /* Assert that malloc() has not failed */
   163    167     assert( !sqlite3MallocFailed() );
   164    168   
   165    169     if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
................................................................................
   168    172     if( p->aborted ){
   169    173       return SQLITE_ABORT;
   170    174     }
   171    175     if( p->pc<=0 && p->expired ){
   172    176       if( p->rc==SQLITE_OK ){
   173    177         p->rc = SQLITE_SCHEMA;
   174    178       }
   175         -    return SQLITE_ERROR;
          179  +    rc = SQLITE_ERROR;
          180  +    goto end_of_step;
   176    181     }
   177    182     db = p->db;
   178    183     if( sqlite3SafetyOn(db) ){
   179    184       p->rc = SQLITE_MISUSE;
   180    185       return SQLITE_MISUSE;
   181    186     }
   182    187     if( p->pc<0 ){
................................................................................
   250    255       assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
   251    256       db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
   252    257     }
   253    258   #endif
   254    259   
   255    260     sqlite3Error(p->db, rc, 0);
   256    261     p->rc = sqlite3ApiExit(p->db, p->rc);
          262  +end_of_step:
   257    263     assert( (rc&0xff)==rc );
          264  +  if( p->zSql && (rc&0xff)<SQLITE_ROW ){
          265  +    /* This behavior occurs if sqlite3_prepare_v2() was used to build
          266  +    ** the prepared statement.  Return error codes directly */
          267  +    return p->rc;
          268  +  }else{
          269  +    /* This is for legacy sqlite3_prepare() builds and when the code
          270  +    ** is SQLITE_ROW or SQLITE_DONE */
          271  +    return rc;
          272  +  }
          273  +}
          274  +
          275  +/*
          276  +** This is the top-level implementation of sqlite3_step().  Call
          277  +** sqlite3Step() to do most of the work.  If a schema error occurs,
          278  +** call sqlite3Reprepare() and try again.
          279  +*/
          280  +#ifdef SQLITE_OMIT_PARSER
          281  +int sqlite3_step(sqlite3_stmt *pStmt){
          282  +  return sqlite3Step((Vdbe*)pStmt);
          283  +}
          284  +#else
          285  +int sqlite3_step(sqlite3_stmt *pStmt){
          286  +  int cnt = 0;
          287  +  int rc;
          288  +  Vdbe *v = (Vdbe*)pStmt;
          289  +  while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
          290  +         && cnt++ < 5
          291  +         && sqlite3Reprepare(v) ){
          292  +    sqlite3_reset(pStmt);
          293  +    v->expired = 0;
          294  +  }
   258    295     return rc;
   259    296   }
          297  +#endif
   260    298   
   261    299   /*
   262    300   ** Extract the user data from a sqlite3_context structure and return a
   263    301   ** pointer to it.
   264    302   */
   265    303   void *sqlite3_user_data(sqlite3_context *p){
   266    304     assert( p && p->pFunc );

Changes to SQLite.Interop/src/vdbeaux.c.

    43     43     }
    44     44     p->pNext = db->pVdbe;
    45     45     p->pPrev = 0;
    46     46     db->pVdbe = p;
    47     47     p->magic = VDBE_MAGIC_INIT;
    48     48     return p;
    49     49   }
           50  +
           51  +/*
           52  +** Remember the SQL string for a prepared statement.
           53  +*/
           54  +void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n){
           55  +  if( p==0 ) return;
           56  +  assert( p->zSql==0 );
           57  +  p->zSql = sqlite3StrNDup(z, n);
           58  +}
           59  +
           60  +/*
           61  +** Return the SQL associated with a prepared statement
           62  +*/
           63  +const char *sqlite3VdbeGetSql(Vdbe *p){
           64  +  return p->zSql;
           65  +}
           66  +
           67  +/*
           68  +** Swap all content between two VDBE structures.
           69  +*/
           70  +void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
           71  +  Vdbe tmp, *pTmp;
           72  +  char *zTmp;
           73  +  int nTmp;
           74  +  tmp = *pA;
           75  +  *pA = *pB;
           76  +  *pB = tmp;
           77  +  pTmp = pA->pNext;
           78  +  pA->pNext = pB->pNext;
           79  +  pB->pNext = pTmp;
           80  +  pTmp = pA->pPrev;
           81  +  pA->pPrev = pB->pPrev;
           82  +  pB->pPrev = pTmp;
           83  +  zTmp = pA->zSql;
           84  +  pA->zSql = pB->zSql;
           85  +  pB->zSql = zTmp;
           86  +  nTmp = pA->nSql;
           87  +  pA->nSql = pB->nSql;
           88  +  pB->nSql = nTmp;
           89  +}
    50     90   
    51     91   /*
    52     92   ** Turn tracing on or off
    53     93   */
    54     94   void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
    55     95     p->trace = trace;
    56     96   }
................................................................................
   808    848         }
   809    849       }
   810    850     }
   811    851     for(n=0; n<p->nMem; n++){
   812    852       p->aMem[n].flags = MEM_Null;
   813    853     }
   814    854   
   815         -#ifdef SQLITE_DEBUG
   816         -  if( (p->db->flags & SQLITE_VdbeListing)!=0
   817         -    || sqlite3OsFileExists("vdbe_explain")
   818         -  ){
   819         -    int i;
   820         -    printf("VDBE Program Listing:\n");
   821         -    sqlite3VdbePrintSql(p);
   822         -    for(i=0; i<p->nOp; i++){
   823         -      sqlite3VdbePrintOp(stdout, i, &p->aOp[i]);
   824         -    }
   825         -  }
   826         -  if( sqlite3OsFileExists("vdbe_trace") ){
   827         -    p->trace = stdout;
   828         -  }
   829         -#endif
   830    855     p->pTos = &p->aStack[-1];
   831    856     p->pc = -1;
   832    857     p->rc = SQLITE_OK;
   833    858     p->uniqueCnt = 0;
   834    859     p->returnDepth = 0;
   835    860     p->errorAction = OE_Abort;
   836    861     p->popStack =  0;
................................................................................
  1419   1444       db->activeVdbeCnt--;
  1420   1445     }
  1421   1446     p->magic = VDBE_MAGIC_HALT;
  1422   1447     checkActiveVdbeCnt(db);
  1423   1448   
  1424   1449     return SQLITE_OK;
  1425   1450   }
         1451  +
         1452  +/*
         1453  +** Each VDBE holds the result of the most recent sqlite3_step() call
         1454  +** in p->rc.  This routine sets that result back to SQLITE_OK.
         1455  +*/
         1456  +void sqlite3VdbeResetStepResult(Vdbe *p){
         1457  +  p->rc = SQLITE_OK;
         1458  +}
  1426   1459   
  1427   1460   /*
  1428   1461   ** Clean up a VDBE after execution but do not delete the VDBE just yet.
  1429   1462   ** Write any error messages into *pzErrMsg.  Return the result code.
  1430   1463   **
  1431   1464   ** After this routine is run, the VDBE should be ready to be executed
  1432   1465   ** again.
................................................................................
  1570   1603       sqliteFree(p->aOp);
  1571   1604     }
  1572   1605     releaseMemArray(p->aVar, p->nVar);
  1573   1606     sqliteFree(p->aLabel);
  1574   1607     sqliteFree(p->aStack);
  1575   1608     releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
  1576   1609     sqliteFree(p->aColName);
         1610  +  sqliteFree(p->zSql);
  1577   1611     p->magic = VDBE_MAGIC_DEAD;
  1578   1612     sqliteFree(p);
  1579   1613   }
  1580   1614   
  1581   1615   /*
  1582   1616   ** If a MoveTo operation is pending on the given cursor, then do that
  1583   1617   ** MoveTo now.  Return an error code.  If no MoveTo is pending, this
................................................................................
  1888   1922   
  1889   1923       /* Read the serial types for the next element in each key. */
  1890   1924       idx1 += GetVarint( aKey1+idx1, serial_type1 );
  1891   1925       if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
  1892   1926       idx2 += GetVarint( aKey2+idx2, serial_type2 );
  1893   1927       if( d2>=nKey2 && sqlite3VdbeSerialTypeLen(serial_type2)>0 ) break;
  1894   1928   
  1895         -    /* Assert that there is enough space left in each key for the blob of
  1896         -    ** data to go with the serial type just read. This assert may fail if
  1897         -    ** the file is corrupted.  Then read the value from each key into mem1
  1898         -    ** and mem2 respectively.
         1929  +    /* Extract the values to be compared.
  1899   1930       */
  1900   1931       d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
  1901   1932       d2 += sqlite3VdbeSerialGet(&aKey2[d2], serial_type2, &mem2);
  1902   1933   
         1934  +    /* Do the comparison
         1935  +    */
  1903   1936       rc = sqlite3MemCompare(&mem1, &mem2, i<nField ? pKeyInfo->aColl[i] : 0);
  1904   1937       if( mem1.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem1);
  1905   1938       if( mem2.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem2);
  1906   1939       if( rc!=0 ){
  1907   1940         break;
  1908   1941       }
  1909   1942       i++;

Changes to SQLite.Interop/src/vtab.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to help implement virtual tables.
    13     13   **
    14         -** $Id: vtab.c,v 1.2 2006/10/12 21:34:22 rmsimpson Exp $
           14  +** $Id: vtab.c,v 1.3 2007/01/10 14:50:46 rmsimpson Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_VIRTUALTABLE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** External API function used to create a new virtual-table module.
    21     21   */
................................................................................
   226    226       );
   227    227       sqliteFree(zStmt);
   228    228       v = sqlite3GetVdbe(pParse);
   229    229       sqlite3ChangeCookie(db, v, iDb);
   230    230   
   231    231       sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
   232    232       zWhere = sqlite3MPrintf("name='%q'", pTab->zName);
   233         -    sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
          233  +    sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 1, zWhere, P3_DYNAMIC);
   234    234       sqlite3VdbeOp3(v, OP_VCreate, iDb, 0, pTab->zName, strlen(pTab->zName) + 1);
   235    235     }
   236    236   
   237    237     /* If we are rereading the sqlite_master table create the in-memory
   238    238     ** record of the table. If the module has already been registered,
   239    239     ** also call the xConnect method here.
   240    240     */
................................................................................
   336    336   ** of the virtual table pTab. If an error occurs, an error code is returned 
   337    337   ** and an error left in pParse.
   338    338   **
   339    339   ** This call is a no-op if table pTab is not a virtual table.
   340    340   */
   341    341   int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
   342    342     Module *pMod;
   343         -  const char *zModule;
   344    343     int rc = SQLITE_OK;
   345    344   
   346    345     if( !pTab || !pTab->isVirtual || pTab->pVtab ){
   347    346       return SQLITE_OK;
   348    347     }
   349    348   
   350    349     pMod = pTab->pMod;
   351         -  zModule = pTab->azModuleArg[0];
   352    350     if( !pMod ){
   353    351       const char *zModule = pTab->azModuleArg[0];
   354    352       sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
   355    353       rc = SQLITE_ERROR;
   356    354     } else {
   357    355       char *zErr = 0;
   358    356       sqlite3 *db = pParse->db;

Changes to SQLite.Interop/src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is reponsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.26 2006/10/12 21:34:22 rmsimpson Exp $
           19  +** $Id: where.c,v 1.27 2007/01/10 14:50:46 rmsimpson Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
    25     25   */
    26     26   #define BMS  (sizeof(Bitmask)*8)
................................................................................
   153    153   #define WO_IN     1
   154    154   #define WO_EQ     2
   155    155   #define WO_LT     (WO_EQ<<(TK_LT-TK_EQ))
   156    156   #define WO_LE     (WO_EQ<<(TK_LE-TK_EQ))
   157    157   #define WO_GT     (WO_EQ<<(TK_GT-TK_EQ))
   158    158   #define WO_GE     (WO_EQ<<(TK_GE-TK_EQ))
   159    159   #define WO_MATCH  64
          160  +#define WO_ISNULL 128
   160    161   
   161    162   /*
   162    163   ** Value for flags returned by bestIndex()
   163    164   */
   164    165   #define WHERE_ROWID_EQ       0x0001   /* rowid=EXPR or rowid IN (...) */
   165    166   #define WHERE_ROWID_RANGE    0x0002   /* rowid<EXPR and/or rowid>EXPR */
   166    167   #define WHERE_COLUMN_EQ      0x0010   /* x=EXPR or x IN (...) */
................................................................................
   350    351   ** "=", "<", ">", "<=", ">=", and "IN".
   351    352   */
   352    353   static int allowedOp(int op){
   353    354     assert( TK_GT>TK_EQ && TK_GT<TK_GE );
   354    355     assert( TK_LT>TK_EQ && TK_LT<TK_GE );
   355    356     assert( TK_LE>TK_EQ && TK_LE<TK_GE );
   356    357     assert( TK_GE==TK_EQ+4 );
   357         -  return op==TK_IN || (op>=TK_EQ && op<=TK_GE);
          358  +  return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
   358    359   }
   359    360   
   360    361   /*
   361    362   ** Swap two objects of type T.
   362    363   */
   363    364   #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
   364    365   
................................................................................
   384    385   ** Translate from TK_xx operator to WO_xx bitmask.
   385    386   */
   386    387   static int operatorMask(int op){
   387    388     int c;
   388    389     assert( allowedOp(op) );
   389    390     if( op==TK_IN ){
   390    391       c = WO_IN;
          392  +  }else if( op==TK_ISNULL ){
          393  +    c = WO_ISNULL;
   391    394     }else{
   392    395       c = WO_EQ<<(op-TK_EQ);
   393    396     }
          397  +  assert( op!=TK_ISNULL || c==WO_ISNULL );
   394    398     assert( op!=TK_IN || c==WO_IN );
   395    399     assert( op!=TK_EQ || c==WO_EQ );
   396    400     assert( op!=TK_LT || c==WO_LT );
   397    401     assert( op!=TK_LE || c==WO_LE );
   398    402     assert( op!=TK_GT || c==WO_GT );
   399    403     assert( op!=TK_GE || c==WO_GE );
   400    404     return c;
................................................................................
   418    422     int k;
   419    423     for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
   420    424       if( pTerm->leftCursor==iCur
   421    425          && (pTerm->prereqRight & notReady)==0
   422    426          && pTerm->leftColumn==iColumn
   423    427          && (pTerm->eOperator & op)!=0
   424    428       ){
   425         -      if( iCur>=0 && pIdx ){
          429  +      if( iCur>=0 && pIdx && pTerm->eOperator!=WO_ISNULL ){
   426    430           Expr *pX = pTerm->pExpr;
   427    431           CollSeq *pColl;
   428    432           char idxaff;
   429    433           int j;
   430    434           Parse *pParse = pWC->pParse;
   431    435   
   432    436           idxaff = pIdx->pTable->aCol[iColumn].affinity;
................................................................................
   586    590   ){
   587    591     WhereTerm *pTerm = &pWC->a[idxTerm];
   588    592     Expr *pExpr = pTerm->pExpr;
   589    593     Bitmask prereqLeft;
   590    594     Bitmask prereqAll;
   591    595     int nPattern;
   592    596     int isComplete;
          597  +  int op;
   593    598   
   594    599     if( sqlite3MallocFailed() ) return;
   595    600     prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
   596         -  if( pExpr->op==TK_IN ){
          601  +  op = pExpr->op;
          602  +  if( op==TK_IN ){
   597    603       assert( pExpr->pRight==0 );
   598    604       pTerm->prereqRight = exprListTableUsage(pMaskSet, pExpr->pList)
   599    605                             | exprSelectTableUsage(pMaskSet, pExpr->pSelect);
          606  +  }else if( op==TK_ISNULL ){
          607  +    pTerm->prereqRight = 0;
   600    608     }else{
   601    609       pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight);
   602    610     }
   603    611     prereqAll = exprTableUsage(pMaskSet, pExpr);
   604    612     if( ExprHasProperty(pExpr, EP_FromJoin) ){
   605    613       prereqAll |= getMask(pMaskSet, pExpr->iRightJoinTable);
   606    614     }
   607    615     pTerm->prereqAll = prereqAll;
   608    616     pTerm->leftCursor = -1;
   609    617     pTerm->iParent = -1;
   610    618     pTerm->eOperator = 0;
   611         -  if( allowedOp(pExpr->op) && (pTerm->prereqRight & prereqLeft)==0 ){
          619  +  if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){
   612    620       Expr *pLeft = pExpr->pLeft;
   613    621       Expr *pRight = pExpr->pRight;
   614    622       if( pLeft->op==TK_COLUMN ){
   615    623         pTerm->leftCursor = pLeft->iTable;
   616    624         pTerm->leftColumn = pLeft->iColumn;
   617         -      pTerm->eOperator = operatorMask(pExpr->op);
          625  +      pTerm->eOperator = operatorMask(op);
   618    626       }
   619    627       if( pRight && pRight->op==TK_COLUMN ){
   620    628         WhereTerm *pNew;
   621    629         Expr *pDup;
   622    630         if( pTerm->leftCursor>=0 ){
   623    631           int idxNew;
   624    632           pDup = sqlite3ExprDup(pExpr);
          633  +        if( sqlite3MallocFailed() ){
          634  +          sqliteFree(pDup);
          635  +          return;
          636  +        }
   625    637           idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
   626    638           if( idxNew==0 ) return;
   627    639           pNew = &pWC->a[idxNew];
   628    640           pNew->iParent = idxTerm;
   629    641           pTerm = &pWC->a[idxTerm];
   630    642           pTerm->nChild = 1;
   631    643           pTerm->flags |= TERM_COPIED;
................................................................................
   711    723             ok = 0;
   712    724           }
   713    725         }
   714    726       }while( !ok && (sOr.a[j++].flags & TERM_COPIED)!=0 && j<sOr.nTerm );
   715    727       if( ok ){
   716    728         ExprList *pList = 0;
   717    729         Expr *pNew, *pDup;
          730  +      Expr *pLeft = 0;
   718    731         for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){
   719    732           if( (pOrTerm->flags & TERM_OR_OK)==0 ) continue;
   720    733           pDup = sqlite3ExprDup(pOrTerm->pExpr->pRight);
   721    734           pList = sqlite3ExprListAppend(pList, pDup, 0);
          735  +        pLeft = pOrTerm->pExpr->pLeft;
   722    736         }
   723         -      pDup = sqlite3Expr(TK_COLUMN, 0, 0, 0);
   724         -      if( pDup ){
   725         -        pDup->iTable = iCursor;
   726         -        pDup->iColumn = iColumn;
   727         -      }
          737  +      assert( pLeft!=0 );
          738  +      pDup = sqlite3ExprDup(pLeft);
   728    739         pNew = sqlite3Expr(TK_IN, pDup, 0, 0);
   729    740         if( pNew ){
   730    741           int idxNew;
   731    742           transferJoinMarkings(pNew, pExpr);
   732    743           pNew->pList = pList;
   733    744           idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
   734    745           exprAnalyze(pSrc, pMaskSet, pWC, idxNew);
................................................................................
   853    864   
   854    865     assert( pOrderBy!=0 );
   855    866     nTerm = pOrderBy->nExpr;
   856    867     assert( nTerm>0 );
   857    868   
   858    869     /* Match terms of the ORDER BY clause against columns of
   859    870     ** the index.
          871  +  **
          872  +  ** Note that indices have pIdx->nColumn regular columns plus
          873  +  ** one additional column containing the rowid.  The rowid column
          874  +  ** of the index is also allowed to match against the ORDER BY
          875  +  ** clause.
   860    876     */
   861         -  for(i=j=0, pTerm=pOrderBy->a; j<nTerm && i<pIdx->nColumn; i++){
          877  +  for(i=j=0, pTerm=pOrderBy->a; j<nTerm && i<=pIdx->nColumn; i++){
   862    878       Expr *pExpr;       /* The expression of the ORDER BY pTerm */
   863    879       CollSeq *pColl;    /* The collating sequence of pExpr */
   864    880       int termSortOrder; /* Sort order for this term */
          881  +    int iColumn;       /* The i-th column of the index.  -1 for rowid */
          882  +    int iSortOrder;    /* 1 for DESC, 0 for ASC on the i-th index term */
          883  +    const char *zColl; /* Name of the collating sequence for i-th index term */
   865    884   
   866    885       pExpr = pTerm->pExpr;
   867    886       if( pExpr->op!=TK_COLUMN || pExpr->iTable!=base ){
   868    887         /* Can not use an index sort on anything that is not a column in the
   869    888         ** left-most table of the FROM clause */
   870    889         return 0;
   871    890       }
   872    891       pColl = sqlite3ExprCollSeq(pParse, pExpr);
   873         -    if( !pColl ) pColl = db->pDfltColl;
   874         -    if( pExpr->iColumn!=pIdx->aiColumn[i] || 
   875         -        sqlite3StrICmp(pColl->zName, pIdx->azColl[i]) ){
          892  +    if( !pColl ){
          893  +      pColl = db->pDfltColl;
          894  +    }
          895  +    if( i<pIdx->nColumn ){
          896  +      iColumn = pIdx->aiColumn[i];
          897  +      if( iColumn==pIdx->pTable->iPKey ){
          898  +        iColumn = -1;
          899  +      }
          900  +      iSortOrder = pIdx->aSortOrder[i];
          901  +      zColl = pIdx->azColl[i];
          902  +    }else{
          903  +      iColumn = -1;
          904  +      iSortOrder = 0;
          905  +      zColl = pColl->zName;
          906  +    }
          907  +    if( pExpr->iColumn!=iColumn || sqlite3StrICmp(pColl->zName, zColl) ){
   876    908         /* Term j of the ORDER BY clause does not match column i of the index */
   877    909         if( i<nEqCol ){
   878    910           /* If an index column that is constrained by == fails to match an
   879    911           ** ORDER BY term, that is OK.  Just ignore that column of the index
   880    912           */
   881    913           continue;
   882    914         }else{
................................................................................
   884    916           ** then the index cannot satisfy the ORDER BY constraint.
   885    917           */
   886    918           return 0;
   887    919         }
   888    920       }
   889    921       assert( pIdx->aSortOrder!=0 );
   890    922       assert( pTerm->sortOrder==0 || pTerm->sortOrder==1 );
   891         -    assert( pIdx->aSortOrder[i]==0 || pIdx->aSortOrder[i]==1 );
   892         -    termSortOrder = pIdx->aSortOrder[i] ^ pTerm->sortOrder;
          923  +    assert( iSortOrder==0 || iSortOrder==1 );
          924  +    termSortOrder = iSortOrder ^ pTerm->sortOrder;
   893    925       if( i>nEqCol ){
   894    926         if( termSortOrder!=sortOrder ){
   895    927           /* Indices can only be used if all ORDER BY terms past the
   896    928           ** equality constraints are all either DESC or ASC. */
   897    929           return 0;
   898    930         }
   899    931       }else{
   900    932         sortOrder = termSortOrder;
   901    933       }
   902    934       j++;
   903    935       pTerm++;
          936  +    if( iColumn<0 ){
          937  +      /* If the indexed column is the primary key and everything matches
          938  +      ** so far, then we are assured that the index can be used to sort
          939  +      ** because the primary key is unique and so none of the other columns
          940  +      ** will make any difference
          941  +      */
          942  +      j = nTerm;
          943  +    }
   904    944     }
   905    945   
   906         -  /* The index can be used for sorting if all terms of the ORDER BY clause
   907         -  ** are covered.
   908         -  */
          946  +  *pbRev = sortOrder!=0;
   909    947     if( j>=nTerm ){
   910         -    *pbRev = sortOrder!=0;
          948  +    /* All terms of the ORDER BY clause are covered by this index so
          949  +    ** this index can be used for sorting. */
          950  +    return 1;
          951  +  }
          952  +  if( j==pIdx->nColumn && pIdx->onError!=OE_None ){
          953  +    /* All terms of this index match some prefix of the ORDER BY clause
          954  +    ** and this index is UNIQUE, so this index can be used for sorting. */
   911    955       return 1;
   912    956     }
   913    957     return 0;
   914    958   }
   915    959   
   916    960   /*
   917    961   ** Check table to see if the ORDER BY clause in pOrderBy can be satisfied
................................................................................
   924    968     int *pbRev              /* Set to 1 if ORDER BY is DESC */
   925    969   ){
   926    970     Expr *p;
   927    971   
   928    972     assert( pOrderBy!=0 );
   929    973     assert( pOrderBy->nExpr>0 );
   930    974     p = pOrderBy->a[0].pExpr;
   931         -  if( pOrderBy->nExpr==1 && p->op==TK_COLUMN && p->iTable==base
   932         -          && p->iColumn==-1 ){
          975  +  if( p->op==TK_COLUMN && p->iTable==base && p->iColumn==-1 ){
   933    976       *pbRev = pOrderBy->a[0].sortOrder;
   934    977       return 1;
   935    978     }
   936    979     return 0;
   937    980   }
   938    981   
   939    982   /*
................................................................................
  1333   1376   
  1334   1377       /* Count the number of columns in the index that are satisfied
  1335   1378       ** by x=EXPR constraints or x IN (...) constraints.
  1336   1379       */
  1337   1380       flags = 0;
  1338   1381       for(i=0; i<pProbe->nColumn; i++){
  1339   1382         int j = pProbe->aiColumn[i];
  1340         -      pTerm = findTerm(pWC, iCur, j, notReady, WO_EQ|WO_IN, pProbe);
         1383  +      pTerm = findTerm(pWC, iCur, j, notReady, WO_EQ|WO_IN|WO_ISNULL, pProbe);
  1341   1384         if( pTerm==0 ) break;
  1342   1385         flags |= WHERE_COLUMN_EQ;
  1343   1386         if( pTerm->eOperator & WO_IN ){
  1344   1387           Expr *pExpr = pTerm->pExpr;
  1345   1388           flags |= WHERE_COLUMN_IN;
  1346   1389           if( pExpr->pSelect!=0 ){
  1347   1390             inMultiplier *= 25;
................................................................................
  1472   1515           disableTerm(pLevel, pOther);
  1473   1516         }
  1474   1517       }
  1475   1518     }
  1476   1519   }
  1477   1520   
  1478   1521   /*
  1479         -** Generate code that builds a probe for an index.  Details:
         1522  +** Generate code that builds a probe for an index.
  1480   1523   **
  1481         -**    *  Check the top nColumn entries on the stack.  If any
  1482         -**       of those entries are NULL, jump immediately to brk,
  1483         -**       which is the loop exit, since no index entry will match
  1484         -**       if any part of the key is NULL. Pop (nColumn+nExtra) 
  1485         -**       elements from the stack.
  1486         -**
  1487         -**    *  Construct a probe entry from the top nColumn entries in
  1488         -**       the stack with affinities appropriate for index pIdx. 
  1489         -**       Only nColumn elements are popped from the stack in this case
  1490         -**       (by OP_MakeRecord).
  1491         -**
         1524  +** There should be nColumn values on the stack.  The index
         1525  +** to be probed is pIdx.  Pop the values from the stack and
         1526  +** replace them all with a single record that is the index
         1527  +** problem.
  1492   1528   */
  1493   1529   static void buildIndexProbe(
  1494         -  Vdbe *v, 
  1495         -  int nColumn, 
  1496         -  int nExtra, 
  1497         -  int brk, 
  1498         -  Index *pIdx
         1530  +  Vdbe *v,        /* Generate code into this VM */
         1531  +  int nColumn,    /* The number of columns to check for NULL */
         1532  +  Index *pIdx     /* Index that we will be searching */
  1499   1533   ){
  1500         -  sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3);
  1501         -  sqlite3VdbeAddOp(v, OP_Pop, nColumn+nExtra, 0);
  1502         -  sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
  1503   1534     sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
  1504   1535     sqlite3IndexAffinityStr(v, pIdx);
  1505   1536   }
  1506   1537   
  1507   1538   
  1508   1539   /*
  1509   1540   ** Generate code for a single equality term of the WHERE clause.  An equality
................................................................................
  1519   1550   static void codeEqualityTerm(
  1520   1551     Parse *pParse,      /* The parsing context */
  1521   1552     WhereTerm *pTerm,   /* The term of the WHERE clause to be coded */
  1522   1553     int brk,            /* Jump here to abandon the loop */
  1523   1554     WhereLevel *pLevel  /* When level of the FROM clause we are working on */
  1524   1555   ){
  1525   1556     Expr *pX = pTerm->pExpr;
  1526         -  if( pX->op!=TK_IN ){
  1527         -    assert( pX->op==TK_EQ );
         1557  +  Vdbe *v = pParse->pVdbe;
         1558  +  if( pX->op==TK_EQ ){
  1528   1559       sqlite3ExprCode(pParse, pX->pRight);
         1560  +  }else if( pX->op==TK_ISNULL ){
         1561  +    sqlite3VdbeAddOp(v, OP_Null, 0, 0);
  1529   1562   #ifndef SQLITE_OMIT_SUBQUERY
  1530   1563     }else{
  1531   1564       int iTab;
  1532   1565       int *aIn;
  1533         -    Vdbe *v = pParse->pVdbe;
  1534   1566   
         1567  +    assert( pX->op==TK_IN );
  1535   1568       sqlite3CodeSubselect(pParse, pX);
  1536   1569       iTab = pX->iTable;
  1537   1570       sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0);
  1538   1571       VdbeComment((v, "# %.*s", pX->span.n, pX->span.z));
  1539   1572       pLevel->nIn++;
  1540   1573       sqliteReallocOrFree((void**)&pLevel->aInLoop,
  1541   1574                                    sizeof(pLevel->aInLoop[0])*2*pLevel->nIn);
................................................................................
  1601   1634       termsInMem = 1;
  1602   1635     }
  1603   1636   
  1604   1637     /* Evaluate the equality constraints
  1605   1638     */
  1606   1639     for(j=0; j<pIdx->nColumn; j++){
  1607   1640       int k = pIdx->aiColumn[j];
  1608         -    pTerm = findTerm(pWC, iCur, k, notReady, WO_EQ|WO_IN, pIdx);
         1641  +    pTerm = findTerm(pWC, iCur, k, notReady, WO_EQ|WO_IN|WO_ISNULL, pIdx);
  1609   1642       if( pTerm==0 ) break;
  1610   1643       assert( (pTerm->flags & TERM_CODED)==0 );
  1611   1644       codeEqualityTerm(pParse, pTerm, brk, pLevel);
         1645  +    if( (pTerm->eOperator & WO_ISNULL)==0 ){
         1646  +      sqlite3VdbeAddOp(v, OP_IsNull, termsInMem ? -1 : -(j+1), brk);
         1647  +    }
  1612   1648       if( termsInMem ){
  1613   1649         sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem+j+1, 1);
  1614   1650       }
  1615   1651     }
  1616   1652     assert( j==nEq );
  1617   1653   
  1618   1654     /* Make sure all the constraint values are on the top of the stack
................................................................................
  1846   1882       int once = 0;               /* True when first table is seen */
  1847   1883       sqlite3_index_info *pIndex; /* Current virtual index */
  1848   1884   
  1849   1885       lowestCost = SQLITE_BIG_DBL;
  1850   1886       for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
  1851   1887         int doNotReorder;  /* True if this table should not be reordered */
  1852   1888   
  1853         -      doNotReorder =  (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0
  1854         -                   || (j>0 && (pTabItem[-1].jointype & (JT_LEFT|JT_CROSS))!=0);
         1889  +      doNotReorder =  (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0;
  1855   1890         if( once && doNotReorder ) break;
  1856   1891         m = getMask(&maskSet, pTabItem->iCursor);
  1857   1892         if( (m & notReady)==0 ){
  1858   1893           if( j==iFrom ) iFrom++;
  1859   1894           continue;
  1860   1895         }
  1861   1896         assert( pTabItem->pTab );
................................................................................
  1982   2017         KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
  1983   2018         assert( pIx->pSchema==pTab->pSchema );
  1984   2019         sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
  1985   2020         VdbeComment((v, "# %s", pIx->zName));
  1986   2021         sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIx->tnum,
  1987   2022                        (char*)pKey, P3_KEYINFO_HANDOFF);
  1988   2023       }
  1989         -    if( (pLevel->flags & WHERE_IDX_ONLY)!=0 ){
         2024  +    if( (pLevel->flags & (WHERE_IDX_ONLY|WHERE_COLUMN_RANGE))!=0 ){
         2025  +      /* Only call OP_SetNumColumns on the index if we might later use
         2026  +      ** OP_Column on the index. */
  1990   2027         sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, pIx->nColumn+1);
  1991   2028       }
  1992   2029       sqlite3CodeVerifySchema(pParse, iDb);
  1993   2030     }
  1994   2031     pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
  1995   2032   
  1996   2033     /* Generate the code to do the search.  Each iteration of the for
................................................................................
  2021   2058       brk = pLevel->brk = sqlite3VdbeMakeLabel(v);
  2022   2059       cont = pLevel->cont = sqlite3VdbeMakeLabel(v);
  2023   2060   
  2024   2061       /* If this is the right table of a LEFT OUTER JOIN, allocate and
  2025   2062       ** initialize a memory cell that records if this table matches any
  2026   2063       ** row of the left table of the join.
  2027   2064       */
  2028         -    if( pLevel->iFrom>0 && (pTabItem[-1].jointype & JT_LEFT)!=0 ){
         2065  +    if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
  2029   2066         if( !pParse->nMem ) pParse->nMem++;
  2030   2067         pLevel->iLeftJoin = pParse->nMem++;
  2031   2068         sqlite3VdbeAddOp(v, OP_MemInt, 0, pLevel->iLeftJoin);
  2032   2069         VdbeComment((v, "# init LEFT JOIN no-match flag"));
  2033   2070       }
  2034   2071   
  2035   2072   #ifndef SQLITE_OMIT_VIRTUALTABLE
................................................................................
  2155   2192         */
  2156   2193         int start;
  2157   2194         int nEq = pLevel->nEq;
  2158   2195         int topEq=0;        /* True if top limit uses ==. False is strictly < */
  2159   2196         int btmEq=0;        /* True if btm limit uses ==. False if strictly > */
  2160   2197         int topOp, btmOp;   /* Operators for the top and bottom search bounds */
  2161   2198         int testOp;
  2162         -      int nNotNull;       /* Number of rows of index that must be non-NULL */
  2163   2199         int topLimit = (pLevel->flags & WHERE_TOP_LIMIT)!=0;
  2164   2200         int btmLimit = (pLevel->flags & WHERE_BTM_LIMIT)!=0;
  2165   2201   
  2166   2202         /* Generate code to evaluate all constraint terms using == or IN
  2167   2203         ** and level the values of those terms on the stack.
  2168   2204         */
  2169   2205         codeAllEqualityTerms(pParse, pLevel, &wc, notReady, brk);
................................................................................
  2177   2213         }
  2178   2214   
  2179   2215         /* Figure out what comparison operators to use for top and bottom 
  2180   2216         ** search bounds. For an ascending index, the bottom bound is a > or >=
  2181   2217         ** operator and the top bound is a < or <= operator.  For a descending
  2182   2218         ** index the operators are reversed.
  2183   2219         */
  2184         -      nNotNull = nEq + topLimit;
  2185   2220         if( pIdx->aSortOrder[nEq]==SQLITE_SO_ASC ){
  2186   2221           topOp = WO_LT|WO_LE;
  2187   2222           btmOp = WO_GT|WO_GE;
  2188   2223         }else{
  2189   2224           topOp = WO_GT|WO_GE;
  2190   2225           btmOp = WO_LT|WO_LE;
  2191   2226           SWAP(int, topLimit, btmLimit);
................................................................................
  2202   2237           Expr *pX;
  2203   2238           int k = pIdx->aiColumn[j];
  2204   2239           pTerm = findTerm(&wc, iCur, k, notReady, topOp, pIdx);
  2205   2240           assert( pTerm!=0 );
  2206   2241           pX = pTerm->pExpr;
  2207   2242           assert( (pTerm->flags & TERM_CODED)==0 );
  2208   2243           sqlite3ExprCode(pParse, pX->pRight);
         2244  +        sqlite3VdbeAddOp(v, OP_IsNull, -(nEq+1), brk);
  2209   2245           topEq = pTerm->eOperator & (WO_LE|WO_GE);
  2210   2246           disableTerm(pLevel, pTerm);
  2211   2247           testOp = OP_IdxGE;
  2212   2248         }else{
  2213   2249           testOp = nEq>0 ? OP_IdxGE : OP_Noop;
  2214   2250           topEq = 1;
  2215   2251         }
  2216   2252         if( testOp!=OP_Noop ){
  2217   2253           int nCol = nEq + topLimit;
  2218   2254           pLevel->iMem = pParse->nMem++;
  2219         -        buildIndexProbe(v, nCol, nEq, brk, pIdx);
         2255  +        buildIndexProbe(v, nCol, pIdx);
  2220   2256           if( bRev ){
  2221   2257             int op = topEq ? OP_MoveLe : OP_MoveLt;
  2222   2258             sqlite3VdbeAddOp(v, op, iIdxCur, brk);
  2223   2259           }else{
  2224   2260             sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
  2225   2261           }
  2226   2262         }else if( bRev ){
................................................................................
  2240   2276           Expr *pX;
  2241   2277           int k = pIdx->aiColumn[j];
  2242   2278           pTerm = findTerm(&wc, iCur, k, notReady, btmOp, pIdx);
  2243   2279           assert( pTerm!=0 );
  2244   2280           pX = pTerm->pExpr;
  2245   2281           assert( (pTerm->flags & TERM_CODED)==0 );
  2246   2282           sqlite3ExprCode(pParse, pX->pRight);
         2283  +        sqlite3VdbeAddOp(v, OP_IsNull, -(nEq+1), brk);
  2247   2284           btmEq = pTerm->eOperator & (WO_LE|WO_GE);
  2248   2285           disableTerm(pLevel, pTerm);
  2249   2286         }else{
  2250   2287           btmEq = 1;
  2251   2288         }
  2252   2289         if( nEq>0 || btmLimit ){
  2253   2290           int nCol = nEq + btmLimit;
  2254         -        buildIndexProbe(v, nCol, 0, brk, pIdx);
         2291  +        buildIndexProbe(v, nCol, pIdx);
  2255   2292           if( bRev ){
  2256   2293             pLevel->iMem = pParse->nMem++;
  2257   2294             sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1);
  2258   2295             testOp = OP_IdxLT;
  2259   2296           }else{
  2260   2297             int op = btmEq ? OP_MoveGe : OP_MoveGt;
  2261   2298             sqlite3VdbeAddOp(v, op, iIdxCur, brk);
................................................................................
  2274   2311         if( testOp!=OP_Noop ){
  2275   2312           sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
  2276   2313           sqlite3VdbeAddOp(v, testOp, iIdxCur, brk);
  2277   2314           if( (topEq && !bRev) || (!btmEq && bRev) ){
  2278   2315             sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC);
  2279   2316           }
  2280   2317         }
  2281         -      sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0);
  2282         -      sqlite3VdbeAddOp(v, OP_IdxIsNull, nNotNull, cont);
         2318  +      if( topLimit | btmLimit ){
         2319  +        sqlite3VdbeAddOp(v, OP_Column, iIdxCur, nEq);
         2320  +        sqlite3VdbeAddOp(v, OP_IsNull, 1, cont);
         2321  +      }
  2283   2322         if( !omitTable ){
  2284   2323           sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0);
  2285   2324           sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
  2286   2325         }
  2287   2326   
  2288   2327         /* Record the instruction used to terminate the loop.
  2289   2328         */
................................................................................
  2301   2340         ** and leave the values of those terms on the stack.
  2302   2341         */
  2303   2342         codeAllEqualityTerms(pParse, pLevel, &wc, notReady, brk);
  2304   2343   
  2305   2344         /* Generate a single key that will be used to both start and terminate
  2306   2345         ** the search
  2307   2346         */
  2308         -      buildIndexProbe(v, nEq, 0, brk, pIdx);
         2347  +      buildIndexProbe(v, nEq, pIdx);
  2309   2348         sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
  2310   2349   
  2311   2350         /* Generate code (1) to move to the first matching element of the table.
  2312   2351         ** Then generate code (2) that jumps to "brk" after the cursor is past
  2313   2352         ** the last matching element of the table.  The code (1) is executed
  2314   2353         ** once to initialize the search, the code (2) is executed before each
  2315   2354         ** iteration of the scan to see if the scan has finished. */
................................................................................
  2322   2361         }else{
  2323   2362           /* Scan in the forward order */
  2324   2363           sqlite3VdbeAddOp(v, OP_MoveGe, iIdxCur, brk);
  2325   2364           start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
  2326   2365           sqlite3VdbeOp3(v, OP_IdxGE, iIdxCur, brk, "+", P3_STATIC);
  2327   2366           pLevel->op = OP_Next;
  2328   2367         }
  2329         -      sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0);
  2330         -      sqlite3VdbeAddOp(v, OP_IdxIsNull, nEq, cont);
  2331   2368         if( !omitTable ){
  2332   2369           sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0);
  2333   2370           sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
  2334   2371         }
  2335   2372         pLevel->p1 = iIdxCur;
  2336   2373         pLevel->p2 = start;
  2337   2374       }else{