System.Data.SQLite
Check-in [48ac9068b5]
Not logged in

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

Overview
Comment:3.2.7 codemerge
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 48ac9068b592fe4e47e87c0947d9a46cff884505
User & Date: rmsimpson 2005-10-05 19:38:29
Context
2005-10-19
17:10
1.0.20 check-in: a0d4d0cf1c user: rmsimpson tags: sourceforge
2005-10-05
19:38
3.2.7 codemerge check-in: 48ac9068b5 user: rmsimpson tags: sourceforge
19:33
1.0.19 check-in: 35ace076c2 user: rmsimpson tags: sourceforge
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
** $Id: alter.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
**
** $Id: alter.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.

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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** @(#) $Id: analyze.c,v 1.2 2005/09/01 06:07:55 rmsimpson Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"

/*
** This routine generates code that opens the sqlite_stat1 table on cursor
** iStatCur.
................................................................................
  Vdbe *v;         /* The virtual machine being built up */
  int i;           /* Loop counter */
  int topOfLoop;   /* The top of the loop */
  int endOfLoop;   /* The end of the loop */
  int addr;        /* The address of an instruction */

  v = sqlite3GetVdbe(pParse);
  if( pTab==0 || pTab->pIndex==0 || pTab->pIndex->pNext==0 ){
    /* Do no analysis for tables with fewer than 2 indices */
    return;
  }

#ifndef SQLITE_OMIT_AUTHORIZATION
  if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
      pParse->db->aDb[pTab->iDb].zName ) ){
    return;
................................................................................
    **    mem[iMem+nCol+1]       Last observed value of column 1
    **    ...
    **    mem[iMem+nCol+nCol]:   Last observed value of column N
    **
    ** Cells iMem through iMem+nCol are initialized to 0.  The others
    ** are initialized to NULL.
    */
    sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
    for(i=0; i<=nCol; i++){
      sqlite3VdbeAddOp(v, OP_MemStore, iMem+i, i==nCol);
    }
    sqlite3VdbeAddOp(v, OP_Null, 0, 0);
    for(i=0; i<nCol; i++){
      sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, i==nCol-1);
    }

    /* Do the analysis.
    */
    endOfLoop = sqlite3VdbeMakeLabel(v);
    sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
    topOfLoop = sqlite3VdbeCurrentAddr(v);
................................................................................
        sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0);
      }else{
        sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
      }
    }
    sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0);
    sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
    sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
  }
}

/*
** Generate code that will cause the most recent index analysis to
** be laoded into internal hash tables where is can be used.
*/
................................................................................
  analysisInfo *pInfo = (analysisInfo*)pData;
  Index *pIndex;
  int i, c;
  unsigned int v;
  const char *z;

  assert( argc==2 );
  if( argv[0]==0 || argv[1]==0 ){
    return 0;
  }
  pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
  if( pIndex==0 ){
    return 0;
  }
  z = argv[1];







|







 







|
|







 







<

|

<

|







 







|







 







|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
123
124
125
126
127
128
129

130
131
132

133
134
135
136
137
138
139
140
141
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** @(#) $Id: analyze.c,v 1.3 2005/10/05 19:38:29 rmsimpson Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"

/*
** This routine generates code that opens the sqlite_stat1 table on cursor
** iStatCur.
................................................................................
  Vdbe *v;         /* The virtual machine being built up */
  int i;           /* Loop counter */
  int topOfLoop;   /* The top of the loop */
  int endOfLoop;   /* The end of the loop */
  int addr;        /* The address of an instruction */

  v = sqlite3GetVdbe(pParse);
  if( pTab==0 || pTab->pIndex==0 ){
    /* Do no analysis for tables that have no indices */
    return;
  }

#ifndef SQLITE_OMIT_AUTHORIZATION
  if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
      pParse->db->aDb[pTab->iDb].zName ) ){
    return;
................................................................................
    **    mem[iMem+nCol+1]       Last observed value of column 1
    **    ...
    **    mem[iMem+nCol+nCol]:   Last observed value of column N
    **
    ** Cells iMem through iMem+nCol are initialized to 0.  The others
    ** are initialized to NULL.
    */

    for(i=0; i<=nCol; i++){
      sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i);
    }

    for(i=0; i<nCol; i++){
      sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0);
    }

    /* Do the analysis.
    */
    endOfLoop = sqlite3VdbeMakeLabel(v);
    sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
    topOfLoop = sqlite3VdbeCurrentAddr(v);
................................................................................
        sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0);
      }else{
        sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
      }
    }
    sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0);
    sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0);
    sqlite3VdbeJumpHere(v, addr);
  }
}

/*
** Generate code that will cause the most recent index analysis to
** be laoded into internal hash tables where is can be used.
*/
................................................................................
  analysisInfo *pInfo = (analysisInfo*)pData;
  Index *pIndex;
  int i, c;
  unsigned int v;
  const char *z;

  assert( argc==2 );
  if( argv==0 || argv[0]==0 || argv[1]==0 ){
    return 0;
  }
  pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
  if( pIndex==0 ){
    return 0;
  }
  z = argv[1];

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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** This routine is called by the parser to process an ATTACH statement:
**
**     ATTACH DATABASE filename AS dbname







|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** This routine is called by the parser to process an ATTACH statement:
**
**     ATTACH DATABASE filename AS dbname

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

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** This file contains code used to implement the sqlite3_set_authorizer()
** API.  This facility is an optional feature of the library.  Embedded
** systems that do not need this facility may omit it by recompiling
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
**
** $Id: auth.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** All of the code in this file may be omitted by defining a single
** macro.
*/







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** This file contains code used to implement the sqlite3_set_authorizer()
** API.  This facility is an optional feature of the library.  Embedded
** systems that do not need this facility may omit it by recompiling
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
**
** $Id: auth.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** All of the code in this file may be omitted by defining a single
** macro.
*/

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

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
....
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
....
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
....
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
....
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
....
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
....
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
....
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
....
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
....
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
....
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
....
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
....
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
....
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
....
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
....
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
....
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
....
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
....
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
....
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
....
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
....
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
....
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
....
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754

5755
5756

5757
5758
5759
5760
5761
5762
5763
5764

5765
5766
5767
5768
5769
5770
5771
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.10 2005/09/01 06:07:55 rmsimpson Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.
................................................................................
  u8 *pPtrmap;    /* The pointer map page */
  Pgno iPtrmap;   /* The pointer map page number */
  int offset;     /* Offset in pointer map page */
  int rc;

  assert( pBt->autoVacuum );
  if( key==0 ){
    return SQLITE_CORRUPT;
  }
  iPtrmap = PTRMAP_PAGENO(pBt->usableSize, key);
  rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
  if( rc!=SQLITE_OK ){
    return rc;
  }
  offset = PTRMAP_PTROFFSET(pBt->usableSize, key);
................................................................................
  }

  offset = PTRMAP_PTROFFSET(pBt->usableSize, key);
  if( pEType ) *pEType = pPtrmap[offset];
  if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);

  sqlite3pager_unref(pPtrmap);
  if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT;
  return SQLITE_OK;
}

#endif /* SQLITE_OMIT_AUTOVACUUM */

/*
** Given a btree page and a cell index (0 means the first cell on
................................................................................
  pBt = pPage->pBt;
  assert( pBt!=0 );
  assert( pParent==0 || pParent->pBt==pBt );
  assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) );
  assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] );
  if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){
    /* The parent page should never change unless the file is corrupt */
    return SQLITE_CORRUPT; /* bkpt-CORRUPT */
  }
  if( pPage->isInit ) return SQLITE_OK;
  if( pPage->pParent==0 && pParent!=0 ){
    pPage->pParent = pParent;
    sqlite3pager_ref(pParent->aData);
  }
  hdr = pPage->hdrOffset;
................................................................................
  pPage->idxShift = 0;
  usableSize = pBt->usableSize;
  pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf;
  top = get2byte(&data[hdr+5]);
  pPage->nCell = get2byte(&data[hdr+3]);
  if( pPage->nCell>MX_CELL(pBt) ){
    /* To many cells for a single page.  The page must be corrupt */
    return SQLITE_CORRUPT; /* bkpt-CORRUPT */
  }
  if( pPage->nCell==0 && pParent!=0 && pParent->pgno!=1 ){
    /* All pages must have at least one cell, except for root pages */
    return SQLITE_CORRUPT; /* bkpt-CORRUPT */
  }

  /* Compute the total free space on the page */
  pc = get2byte(&data[hdr+1]);
  nFree = data[hdr+7] + top - (cellOffset + 2*pPage->nCell);
  while( pc>0 ){
    int next, size;
    if( pc>usableSize-4 ){
      /* Free block is off the page */
      return SQLITE_CORRUPT;  /* bkpt-CORRUPT */
    }
    next = get2byte(&data[pc]);
    size = get2byte(&data[pc+2]);
    if( next>0 && next<=pc+size+3 ){
      /* Free blocks must be in accending order */
      return SQLITE_CORRUPT;  /* bkpt-CORRUPT */
    }
    nFree += size;
    pc = next;
  }
  pPage->nFree = nFree;
  if( nFree>=usableSize ){
    /* Free space cannot exceed total page size */
    return SQLITE_CORRUPT;  /* bkpt-CORRUPT */
  }

  pPage->isInit = 1;
  pageIntegrity(pPage);
  return SQLITE_OK;
}

................................................................................
  Btree *pBt,          /* The database file */
  Pgno pgno,           /* Number of the page to get */
  MemPage **ppPage,    /* Write the page pointer here */
  MemPage *pParent     /* Parent of the page */
){
  int rc;
  if( pgno==0 ){
    return SQLITE_CORRUPT;  /* bkpt-CORRUPT */
  }
  rc = getPage(pBt, pgno, ppPage);
  if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
    rc = initPage(*ppPage, pParent);
  }
  return rc;
}
................................................................................
** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
**                   overflow page in the list.
*/
static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
  if( eType==PTRMAP_OVERFLOW2 ){
    /* The pointer is always the first 4 bytes of the page in this case.  */
    if( get4byte(pPage->aData)!=iFrom ){
      return SQLITE_CORRUPT;
    }
    put4byte(pPage->aData, iTo);
  }else{
    int isInitOrig = pPage->isInit;
    int i;
    int nCell;

................................................................................
        }
      }
    }
  
    if( i==nCell ){
      if( eType!=PTRMAP_BTREE || 
          get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
        return SQLITE_CORRUPT;
      }
      put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
    }

    pPage->isInit = isInitOrig;
  }
  return SQLITE_OK;
................................................................................

#ifndef NDEBUG
  int nRef = *sqlite3pager_stats(pPager);
#endif

  assert( pBt->autoVacuum );
  if( PTRMAP_ISPAGE(pgsz, sqlite3pager_pagecount(pPager)) ){
    return SQLITE_CORRUPT;
  }

  /* Figure out how many free-pages are in the database. If there are no
  ** free pages, then auto-vacuum is a no-op.
  */
  nFreeList = get4byte(&pBt->pPage1->aData[36]);
  if( nFreeList==0 ){
................................................................................
    *nTrunc = 0;
    return SQLITE_OK;
  }

  origSize = sqlite3pager_pagecount(pPager);
  nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pgsz, origSize)+pgsz/5)/(pgsz/5);
  finSize = origSize - nFreeList - nPtrMap;
  if( origSize>PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){
    finSize--;
    if( PTRMAP_ISPAGE(pBt->usableSize, finSize) ){
      finSize--;
    }
  }
  TRACE(("AUTOVACUUM: Begin (db size %d->%d)\n", origSize, finSize));

................................................................................
    if( PTRMAP_ISPAGE(pgsz, iDbPage) || iDbPage==PENDING_BYTE_PAGE(pBt) ){
      continue;
    }

    rc = ptrmapGet(pBt, iDbPage, &eType, &iPtrPage);
    if( rc!=SQLITE_OK ) goto autovacuum_out;
    if( eType==PTRMAP_ROOTPAGE ){
      rc = SQLITE_CORRUPT;
      goto autovacuum_out;
    }

    /* If iDbPage is free, do not swap it.  */
    if( eType==PTRMAP_FREEPAGE ){
      continue;
    }
................................................................................
        offset -= ovflSize;
      }
      sqlite3pager_unref(aPayload);
    }
  }

  if( amt>0 ){
    return SQLITE_CORRUPT; /* bkpt-CORRUPT */
  }
  return SQLITE_OK;
}

/*
** Read part of the key associated with cursor pCur.  Exactly
** "amt" bytes will be transfered into pBuf[].  The transfer
................................................................................
** wrong.  An error is returned if "offset+amt" is larger than
** the available payload.
*/
int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
  assert( pCur->isValid );
  assert( pCur->pPage!=0 );
  if( pCur->pPage->intKey ){
    return SQLITE_CORRUPT;
  }
  assert( pCur->pPage->intKey==0 );
  assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
  return getPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
}

/*
................................................................................
static const unsigned char *fetchPayload(
  BtCursor *pCur,      /* Cursor pointing to entry to read from */
  int *pAmt,           /* Write the number of available bytes here */
  int skipKey          /* read beginning at data if this is true */
){
  unsigned char *aPayload;
  MemPage *pPage;
  Btree *pBt;
  u32 nKey;
  int nLocal;

  assert( pCur!=0 && pCur->pPage!=0 );
  assert( pCur->isValid );
  pBt = pCur->pBt;
  pPage = pCur->pPage;
  pageIntegrity(pPage);
  assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
  getCellInfo(pCur);
  aPayload = pCur->info.pCell;
  aPayload += pCur->info.nHeader;
  if( pPage->intKey ){
................................................................................
  pOldPage = pCur->pPage;
  pOldPage->idxShift = 0;
  releasePage(pOldPage);
  pCur->pPage = pNewPage;
  pCur->idx = 0;
  pCur->info.nSize = 0;
  if( pNewPage->nCell<1 ){
    return SQLITE_CORRUPT; /* bkpt-CORRUPT */
  }
  return SQLITE_OK;
}

/*
** Return true if the page is the virtual root of its table.
**
................................................................................
**
** pCur->idx is set to the cell index that contains the pointer
** to the page we are coming from.  If we are coming from the
** right-most child page then pCur->idx is set to one more than
** the largest cell index.
*/
static void moveToParent(BtCursor *pCur){
  Pgno oldPgno;
  MemPage *pParent;
  MemPage *pPage;
  int idxParent;

  assert( pCur->isValid );
  pPage = pCur->pPage;
  assert( pPage!=0 );
................................................................................
  assert( !isRootPage(pPage) );
  pageIntegrity(pPage);
  pParent = pPage->pParent;
  assert( pParent!=0 );
  pageIntegrity(pParent);
  idxParent = pPage->idxParent;
  sqlite3pager_ref(pParent->aData);
  oldPgno = pPage->pgno;
  releasePage(pPage);
  pCur->pPage = pParent;
  pCur->info.nSize = 0;
  assert( pParent->idxShift==0 );
  pCur->idx = idxParent;
}

................................................................................
    int lwr, upr;
    Pgno chldPg;
    MemPage *pPage = pCur->pPage;
    int c = -1;  /* pRes return if table is empty must be -1 */
    lwr = 0;
    upr = pPage->nCell-1;
    if( !pPage->intKey && pKey==0 ){
      return SQLITE_CORRUPT;
    }
    pageIntegrity(pPage);
    while( lwr<=upr ){
      void *pCellKey;
      i64 nCellKey;
      pCur->idx = (lwr+upr)/2;
      pCur->info.nSize = 0;
................................................................................
        *pPgno = iTrunk;
        memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
        *ppPage = pTrunk;
        pTrunk = 0;
        TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
      }else if( k>pBt->usableSize/4 - 8 ){
        /* Value of k is out of range.  Database corruption */
        return SQLITE_CORRUPT; /* bkpt-CORRUPT */
#ifndef SQLITE_OMIT_AUTOVACUUM
      }else if( searchList && nearby==iTrunk ){
        /* The list is being searched and this trunk page is the page
        ** to allocate, regardless of whether it has leaves.
        */
        assert( *pPgno==iTrunk );
        *ppPage = pTrunk;
................................................................................
        }

        iPage = get4byte(&aData[8+closest*4]);
        if( !searchList || iPage==nearby ){
          *pPgno = iPage;
          if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){
            /* Free page off the end of the file */
            return SQLITE_CORRUPT; /* bkpt-CORRUPT */
          }
          TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d"
                 ": %d more free pages\n",
                 *pPgno, closest+1, k, pTrunk->pgno, n-1));
          if( closest<k-1 ){
            memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
          }
................................................................................
  if( info.iOverflow==0 ){
    return SQLITE_OK;  /* No overflow pages. Return without doing anything */
  }
  ovflPgno = get4byte(&pCell[info.iOverflow]);
  while( ovflPgno!=0 ){
    MemPage *pOvfl;
    if( ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){
      return SQLITE_CORRUPT;
    }
    rc = getPage(pBt, ovflPgno, &pOvfl);
    if( rc ) return rc;
    ovflPgno = get4byte(pOvfl->aData);
    rc = freePage(pOvfl);
    sqlite3pager_unref(pOvfl->aData);
    if( rc ) return rc;
................................................................................
    int notUsed;
    unsigned char *tempCell = 0;
    assert( !pPage->leafData );
    getTempCursor(pCur, &leafCur);
    rc = sqlite3BtreeNext(&leafCur, &notUsed);
    if( rc!=SQLITE_OK ){
      if( rc!=SQLITE_NOMEM ){
        rc = SQLITE_CORRUPT;  /* bkpt-CORRUPT */
      }
    }
    if( rc==SQLITE_OK ){
      rc = sqlite3pager_write(leafCur.pPage->aData);
    }
    if( rc==SQLITE_OK ){
      TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
................................................................................
){
  MemPage *pPage = 0;
  int rc;
  unsigned char *pCell;
  int i;

  if( pgno>sqlite3pager_pagecount(pBt->pPager) ){
    return SQLITE_CORRUPT;
  }

  rc = getAndInitPage(pBt, pgno, &pPage, pParent);
  if( rc ) goto cleardatabasepage_out;
  rc = sqlite3pager_write(pPage->aData);
  if( rc ) goto cleardatabasepage_out;
  for(i=0; i<pPage->nCell; i++){
................................................................................
  MemPage *pPage;
  int i, rc, depth, d2, pgno, cnt;
  int hdr, cellStart;
  int nCell;
  u8 *data;
  BtCursor cur;
  Btree *pBt;
  int maxLocal, usableSize;
  char zContext[100];
  char *hit;

  sprintf(zContext, "Page %d: ", iPage);

  /* Check that the page exists
  */
................................................................................
  if( iPage==0 ) return 0;
  if( checkRef(pCheck, iPage, zParentContext) ) return 0;
  if( (rc = getPage(pBt, (Pgno)iPage, &pPage))!=0 ){
    checkAppendMsg(pCheck, zContext,
       "unable to get the page. error code=%d", rc);
    return 0;
  }
  maxLocal = pPage->leafData ? pBt->maxLeaf : pBt->maxLocal;
  if( (rc = initPage(pPage, pParent))!=0 ){
    checkAppendMsg(pCheck, zContext, "initPage() returns error code %d", rc);
    releasePage(pPage);
    return 0;
  }

  /* Check out all the cells.
................................................................................
** must be active for both files.
**
** The size of file pBtFrom may be reduced by this operation.
** If anything goes wrong, the transaction on pBtFrom is rolled back.
*/
int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
  int rc = SQLITE_OK;
  Pgno i, nPage, nToPage;

  if( pBtTo->inTrans!=TRANS_WRITE || pBtFrom->inTrans!=TRANS_WRITE ){
    return SQLITE_ERROR;
  }
  if( pBtTo->pCursor ) return SQLITE_BUSY;
  nToPage = sqlite3pager_pagecount(pBtTo->pPager);
  nPage = sqlite3pager_pagecount(pBtFrom->pPager);

  for(i=1; rc==SQLITE_OK && i<=nPage; i++){
    void *pPage;

    rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage);
    if( rc ) break;
    rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage);
    if( rc ) break;
    sqlite3pager_unref(pPage);
  }
  for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){
    void *pPage;

    rc = sqlite3pager_get(pBtTo->pPager, i, &pPage);
    if( rc ) break;
    rc = sqlite3pager_write(pPage);
    sqlite3pager_unref(pPage);
    sqlite3pager_dont_write(pBtTo->pPager, i);
  }
  if( !rc && nPage<nToPage ){







|







 







|







 







|







 







|







 







|



|









|





|







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







<





<







 







|







 







<







 







<







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







<







 







|







>


>








>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
....
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
....
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
....
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
....
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
....
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
....
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
....
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
....
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
....
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
....
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
....
2477
2478
2479
2480
2481
2482
2483

2484
2485
2486
2487
2488

2489
2490
2491
2492
2493
2494
2495
....
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
....
2579
2580
2581
2582
2583
2584
2585

2586
2587
2588
2589
2590
2591
2592
....
2593
2594
2595
2596
2597
2598
2599

2600
2601
2602
2603
2604
2605
2606
....
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
....
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
....
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
....
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
....
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
....
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
....
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
....
5489
5490
5491
5492
5493
5494
5495

5496
5497
5498
5499
5500
5501
5502
....
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.11 2005/10/05 19:38:29 rmsimpson Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
**     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
**     "Sorting And Searching", pages 473-480. Addison-Wesley
**     Publishing Company, Reading, Massachusetts.
................................................................................
  u8 *pPtrmap;    /* The pointer map page */
  Pgno iPtrmap;   /* The pointer map page number */
  int offset;     /* Offset in pointer map page */
  int rc;

  assert( pBt->autoVacuum );
  if( key==0 ){
    return SQLITE_CORRUPT_BKPT;
  }
  iPtrmap = PTRMAP_PAGENO(pBt->usableSize, key);
  rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
  if( rc!=SQLITE_OK ){
    return rc;
  }
  offset = PTRMAP_PTROFFSET(pBt->usableSize, key);
................................................................................
  }

  offset = PTRMAP_PTROFFSET(pBt->usableSize, key);
  if( pEType ) *pEType = pPtrmap[offset];
  if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);

  sqlite3pager_unref(pPtrmap);
  if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT;
  return SQLITE_OK;
}

#endif /* SQLITE_OMIT_AUTOVACUUM */

/*
** Given a btree page and a cell index (0 means the first cell on
................................................................................
  pBt = pPage->pBt;
  assert( pBt!=0 );
  assert( pParent==0 || pParent->pBt==pBt );
  assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) );
  assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] );
  if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){
    /* The parent page should never change unless the file is corrupt */
    return SQLITE_CORRUPT_BKPT;
  }
  if( pPage->isInit ) return SQLITE_OK;
  if( pPage->pParent==0 && pParent!=0 ){
    pPage->pParent = pParent;
    sqlite3pager_ref(pParent->aData);
  }
  hdr = pPage->hdrOffset;
................................................................................
  pPage->idxShift = 0;
  usableSize = pBt->usableSize;
  pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf;
  top = get2byte(&data[hdr+5]);
  pPage->nCell = get2byte(&data[hdr+3]);
  if( pPage->nCell>MX_CELL(pBt) ){
    /* To many cells for a single page.  The page must be corrupt */
    return SQLITE_CORRUPT_BKPT;
  }
  if( pPage->nCell==0 && pParent!=0 && pParent->pgno!=1 ){
    /* All pages must have at least one cell, except for root pages */
    return SQLITE_CORRUPT_BKPT;
  }

  /* Compute the total free space on the page */
  pc = get2byte(&data[hdr+1]);
  nFree = data[hdr+7] + top - (cellOffset + 2*pPage->nCell);
  while( pc>0 ){
    int next, size;
    if( pc>usableSize-4 ){
      /* Free block is off the page */
      return SQLITE_CORRUPT_BKPT; 
    }
    next = get2byte(&data[pc]);
    size = get2byte(&data[pc+2]);
    if( next>0 && next<=pc+size+3 ){
      /* Free blocks must be in accending order */
      return SQLITE_CORRUPT_BKPT; 
    }
    nFree += size;
    pc = next;
  }
  pPage->nFree = nFree;
  if( nFree>=usableSize ){
    /* Free space cannot exceed total page size */
    return SQLITE_CORRUPT_BKPT; 
  }

  pPage->isInit = 1;
  pageIntegrity(pPage);
  return SQLITE_OK;
}

................................................................................
  Btree *pBt,          /* The database file */
  Pgno pgno,           /* Number of the page to get */
  MemPage **ppPage,    /* Write the page pointer here */
  MemPage *pParent     /* Parent of the page */
){
  int rc;
  if( pgno==0 ){
    return SQLITE_CORRUPT_BKPT; 
  }
  rc = getPage(pBt, pgno, ppPage);
  if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
    rc = initPage(*ppPage, pParent);
  }
  return rc;
}
................................................................................
** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
**                   overflow page in the list.
*/
static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
  if( eType==PTRMAP_OVERFLOW2 ){
    /* The pointer is always the first 4 bytes of the page in this case.  */
    if( get4byte(pPage->aData)!=iFrom ){
      return SQLITE_CORRUPT_BKPT;
    }
    put4byte(pPage->aData, iTo);
  }else{
    int isInitOrig = pPage->isInit;
    int i;
    int nCell;

................................................................................
        }
      }
    }
  
    if( i==nCell ){
      if( eType!=PTRMAP_BTREE || 
          get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
        return SQLITE_CORRUPT_BKPT;
      }
      put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
    }

    pPage->isInit = isInitOrig;
  }
  return SQLITE_OK;
................................................................................

#ifndef NDEBUG
  int nRef = *sqlite3pager_stats(pPager);
#endif

  assert( pBt->autoVacuum );
  if( PTRMAP_ISPAGE(pgsz, sqlite3pager_pagecount(pPager)) ){
    return SQLITE_CORRUPT_BKPT;
  }

  /* Figure out how many free-pages are in the database. If there are no
  ** free pages, then auto-vacuum is a no-op.
  */
  nFreeList = get4byte(&pBt->pPage1->aData[36]);
  if( nFreeList==0 ){
................................................................................
    *nTrunc = 0;
    return SQLITE_OK;
  }

  origSize = sqlite3pager_pagecount(pPager);
  nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pgsz, origSize)+pgsz/5)/(pgsz/5);
  finSize = origSize - nFreeList - nPtrMap;
  if( origSize>=PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){
    finSize--;
    if( PTRMAP_ISPAGE(pBt->usableSize, finSize) ){
      finSize--;
    }
  }
  TRACE(("AUTOVACUUM: Begin (db size %d->%d)\n", origSize, finSize));

................................................................................
    if( PTRMAP_ISPAGE(pgsz, iDbPage) || iDbPage==PENDING_BYTE_PAGE(pBt) ){
      continue;
    }

    rc = ptrmapGet(pBt, iDbPage, &eType, &iPtrPage);
    if( rc!=SQLITE_OK ) goto autovacuum_out;
    if( eType==PTRMAP_ROOTPAGE ){
      rc = SQLITE_CORRUPT_BKPT;
      goto autovacuum_out;
    }

    /* If iDbPage is free, do not swap it.  */
    if( eType==PTRMAP_FREEPAGE ){
      continue;
    }
................................................................................
        offset -= ovflSize;
      }
      sqlite3pager_unref(aPayload);
    }
  }

  if( amt>0 ){
    return SQLITE_CORRUPT_BKPT;
  }
  return SQLITE_OK;
}

/*
** Read part of the key associated with cursor pCur.  Exactly
** "amt" bytes will be transfered into pBuf[].  The transfer
................................................................................
** wrong.  An error is returned if "offset+amt" is larger than
** the available payload.
*/
int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
  assert( pCur->isValid );
  assert( pCur->pPage!=0 );
  if( pCur->pPage->intKey ){
    return SQLITE_CORRUPT_BKPT;
  }
  assert( pCur->pPage->intKey==0 );
  assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
  return getPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
}

/*
................................................................................
static const unsigned char *fetchPayload(
  BtCursor *pCur,      /* Cursor pointing to entry to read from */
  int *pAmt,           /* Write the number of available bytes here */
  int skipKey          /* read beginning at data if this is true */
){
  unsigned char *aPayload;
  MemPage *pPage;

  u32 nKey;
  int nLocal;

  assert( pCur!=0 && pCur->pPage!=0 );
  assert( pCur->isValid );

  pPage = pCur->pPage;
  pageIntegrity(pPage);
  assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
  getCellInfo(pCur);
  aPayload = pCur->info.pCell;
  aPayload += pCur->info.nHeader;
  if( pPage->intKey ){
................................................................................
  pOldPage = pCur->pPage;
  pOldPage->idxShift = 0;
  releasePage(pOldPage);
  pCur->pPage = pNewPage;
  pCur->idx = 0;
  pCur->info.nSize = 0;
  if( pNewPage->nCell<1 ){
    return SQLITE_CORRUPT_BKPT;
  }
  return SQLITE_OK;
}

/*
** Return true if the page is the virtual root of its table.
**
................................................................................
**
** pCur->idx is set to the cell index that contains the pointer
** to the page we are coming from.  If we are coming from the
** right-most child page then pCur->idx is set to one more than
** the largest cell index.
*/
static void moveToParent(BtCursor *pCur){

  MemPage *pParent;
  MemPage *pPage;
  int idxParent;

  assert( pCur->isValid );
  pPage = pCur->pPage;
  assert( pPage!=0 );
................................................................................
  assert( !isRootPage(pPage) );
  pageIntegrity(pPage);
  pParent = pPage->pParent;
  assert( pParent!=0 );
  pageIntegrity(pParent);
  idxParent = pPage->idxParent;
  sqlite3pager_ref(pParent->aData);

  releasePage(pPage);
  pCur->pPage = pParent;
  pCur->info.nSize = 0;
  assert( pParent->idxShift==0 );
  pCur->idx = idxParent;
}

................................................................................
    int lwr, upr;
    Pgno chldPg;
    MemPage *pPage = pCur->pPage;
    int c = -1;  /* pRes return if table is empty must be -1 */
    lwr = 0;
    upr = pPage->nCell-1;
    if( !pPage->intKey && pKey==0 ){
      return SQLITE_CORRUPT_BKPT;
    }
    pageIntegrity(pPage);
    while( lwr<=upr ){
      void *pCellKey;
      i64 nCellKey;
      pCur->idx = (lwr+upr)/2;
      pCur->info.nSize = 0;
................................................................................
        *pPgno = iTrunk;
        memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
        *ppPage = pTrunk;
        pTrunk = 0;
        TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
      }else if( k>pBt->usableSize/4 - 8 ){
        /* Value of k is out of range.  Database corruption */
        return SQLITE_CORRUPT_BKPT;
#ifndef SQLITE_OMIT_AUTOVACUUM
      }else if( searchList && nearby==iTrunk ){
        /* The list is being searched and this trunk page is the page
        ** to allocate, regardless of whether it has leaves.
        */
        assert( *pPgno==iTrunk );
        *ppPage = pTrunk;
................................................................................
        }

        iPage = get4byte(&aData[8+closest*4]);
        if( !searchList || iPage==nearby ){
          *pPgno = iPage;
          if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){
            /* Free page off the end of the file */
            return SQLITE_CORRUPT_BKPT;
          }
          TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d"
                 ": %d more free pages\n",
                 *pPgno, closest+1, k, pTrunk->pgno, n-1));
          if( closest<k-1 ){
            memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
          }
................................................................................
  if( info.iOverflow==0 ){
    return SQLITE_OK;  /* No overflow pages. Return without doing anything */
  }
  ovflPgno = get4byte(&pCell[info.iOverflow]);
  while( ovflPgno!=0 ){
    MemPage *pOvfl;
    if( ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){
      return SQLITE_CORRUPT_BKPT;
    }
    rc = getPage(pBt, ovflPgno, &pOvfl);
    if( rc ) return rc;
    ovflPgno = get4byte(pOvfl->aData);
    rc = freePage(pOvfl);
    sqlite3pager_unref(pOvfl->aData);
    if( rc ) return rc;
................................................................................
    int notUsed;
    unsigned char *tempCell = 0;
    assert( !pPage->leafData );
    getTempCursor(pCur, &leafCur);
    rc = sqlite3BtreeNext(&leafCur, &notUsed);
    if( rc!=SQLITE_OK ){
      if( rc!=SQLITE_NOMEM ){
        rc = SQLITE_CORRUPT_BKPT; 
      }
    }
    if( rc==SQLITE_OK ){
      rc = sqlite3pager_write(leafCur.pPage->aData);
    }
    if( rc==SQLITE_OK ){
      TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
................................................................................
){
  MemPage *pPage = 0;
  int rc;
  unsigned char *pCell;
  int i;

  if( pgno>sqlite3pager_pagecount(pBt->pPager) ){
    return SQLITE_CORRUPT_BKPT;
  }

  rc = getAndInitPage(pBt, pgno, &pPage, pParent);
  if( rc ) goto cleardatabasepage_out;
  rc = sqlite3pager_write(pPage->aData);
  if( rc ) goto cleardatabasepage_out;
  for(i=0; i<pPage->nCell; i++){
................................................................................
  MemPage *pPage;
  int i, rc, depth, d2, pgno, cnt;
  int hdr, cellStart;
  int nCell;
  u8 *data;
  BtCursor cur;
  Btree *pBt;
  int usableSize;
  char zContext[100];
  char *hit;

  sprintf(zContext, "Page %d: ", iPage);

  /* Check that the page exists
  */
................................................................................
  if( iPage==0 ) return 0;
  if( checkRef(pCheck, iPage, zParentContext) ) return 0;
  if( (rc = getPage(pBt, (Pgno)iPage, &pPage))!=0 ){
    checkAppendMsg(pCheck, zContext,
       "unable to get the page. error code=%d", rc);
    return 0;
  }

  if( (rc = initPage(pPage, pParent))!=0 ){
    checkAppendMsg(pCheck, zContext, "initPage() returns error code %d", rc);
    releasePage(pPage);
    return 0;
  }

  /* Check out all the cells.
................................................................................
** must be active for both files.
**
** The size of file pBtFrom may be reduced by this operation.
** If anything goes wrong, the transaction on pBtFrom is rolled back.
*/
int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){
  int rc = SQLITE_OK;
  Pgno i, nPage, nToPage, iSkip;

  if( pBtTo->inTrans!=TRANS_WRITE || pBtFrom->inTrans!=TRANS_WRITE ){
    return SQLITE_ERROR;
  }
  if( pBtTo->pCursor ) return SQLITE_BUSY;
  nToPage = sqlite3pager_pagecount(pBtTo->pPager);
  nPage = sqlite3pager_pagecount(pBtFrom->pPager);
  iSkip = PENDING_BYTE_PAGE(pBtTo);
  for(i=1; rc==SQLITE_OK && i<=nPage; i++){
    void *pPage;
    if( i==iSkip ) continue;
    rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage);
    if( rc ) break;
    rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage);
    if( rc ) break;
    sqlite3pager_unref(pPage);
  }
  for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){
    void *pPage;
    if( i==iSkip ) continue;
    rc = sqlite3pager_get(pBtTo->pPager, i, &pPage);
    if( rc ) break;
    rc = sqlite3pager_write(pPage);
    sqlite3pager_unref(pPage);
    sqlite3pager_dont_write(pBtTo->pPager, i);
  }
  if( !rc && nPage<nToPage ){

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

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite B-Tree file
** subsystem.  See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.9 2005/09/01 06:07:55 rmsimpson Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_

/* TODO: This definition is just included so other modules compile. It
** needs to be revisited.
*/







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite B-Tree file
** subsystem.  See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_

/* TODO: This definition is just included so other modules compile. It
** needs to be revisited.
*/

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

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
...
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
....
1012
1013
1014
1015
1016
1017
1018

1019

1020
1021
1022
1023
1024
1025
1026
....
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
....
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
....
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
....
2462
2463
2464
2465
2466
2467
2468









































2469
2470
2471
2472
2473
2474
2475
2476

2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
................................................................................
    ** set for each database that is used.  Generate code to start a
    ** transaction on each used database and to verify the schema cookie
    ** on each used database.
    */
    if( pParse->cookieGoto>0 ){
      u32 mask;
      int iDb;
      sqlite3VdbeChangeP2(v, pParse->cookieGoto-1, sqlite3VdbeCurrentAddr(v));
      for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
        if( (mask & pParse->cookieMask)==0 ) continue;
        sqlite3VdbeAddOp(v, OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
        sqlite3VdbeAddOp(v, OP_VerifyCookie, iDb, pParse->cookieValue[iDb]);
      }
      sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->cookieGoto);
    }


    /* Add a No-op that contains the complete text of the compiled SQL
    ** statement as its P3 argument.  This does not change the functionality
    ** of the program. 
    **
    ** This is used to implement sqlite3_trace().
    */
    sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail-pParse->zSql);

  }


  /* Get the VDBE program ready for execution
  */
  if( v && pParse->nErr==0 ){
    FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
    sqlite3VdbeTrace(v, trace);
    sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem+3,
                         pParse->nTab+3, pParse->nMaxDepth+1, pParse->explain);
    pParse->rc = SQLITE_DONE;
    pParse->colNamesSet = 0;
  }else if( pParse->rc==SQLITE_OK ){
    pParse->rc = SQLITE_ERROR;
  }
  pParse->nTab = 0;
  pParse->nMem = 0;
................................................................................
** Not everything is nestable.  This facility is designed to permit
** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER.  Use
** care if you decide to try to use this routine for some other purposes.
*/
void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
  va_list ap;
  char *zSql;
  int rc;
# define SAVE_SZ  (sizeof(Parse) - offsetof(Parse,nVar))
  char saveBuf[SAVE_SZ];

  if( pParse->nErr ) return;
  assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
  va_start(ap, zFormat);
  zSql = sqlite3VMPrintf(zFormat, ap);
................................................................................
  va_end(ap);
  if( zSql==0 ){
    return;   /* A malloc must have failed */
  }
  pParse->nested++;
  memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
  memset(&pParse->nVar, 0, SAVE_SZ);
  rc = sqlite3RunParser(pParse, zSql, 0);
  sqliteFree(zSql);
  memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
  pParse->nested--;
}

/*
** Locate the in-memory structure that describes a particular database
................................................................................
  Token *pStart,   /* The "CREATE" token */
  Token *pName1,   /* First part of the name of the table or view */
  Token *pName2,   /* Second part of the name of the table or view */
  int isTemp,      /* True if this is a TEMP table */
  int isView       /* True if this is a VIEW */
){
  Table *pTable;
  Index *pIdx;
  char *zName = 0; /* The name of the new table */
  sqlite3 *db = pParse->db;
  Vdbe *v;
  int iDb;         /* Database number to create the table in */
  Token *pName;    /* Unqualified name of the table to create */

  /* The table or view name to create is passed to this routine via tokens
................................................................................
    goto begin_table_error;
  }
  pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName);
  if( pTable ){
    sqlite3ErrorMsg(pParse, "table %T already exists", pName);
    goto begin_table_error;
  }
  if( (pIdx = sqlite3FindIndex(db, zName, 0))!=0 && 
      ( iDb==0 || !db->init.busy) ){
    sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
    goto begin_table_error;
  }
  pTable = sqliteMalloc( sizeof(Table) );
  if( pTable==0 ){
    pParse->rc = SQLITE_NOMEM;
    pParse->nErr++;
................................................................................
  int i;
  Column *pCol;

  if( (p = pParse->pNewTable)==0 ) return;
  i = p->nCol-1;
  if( i<0 ) return;
  pCol = &p->aCol[i];
  assert( pCol->zType==0 );
  pCol->zType = sqlite3NameFromToken(pType);
  pCol->affinity = sqlite3AffinityType(pType);
}

/*
** The expression is the default value for the most recently added column
** of the table currently under construction.
................................................................................
  }else{
    for(i=0; i<pList->nExpr; i++){
      for(iCol=0; iCol<pTab->nCol; iCol++){
        if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
          break;
        }
      }

      if( iCol<pTab->nCol ) pTab->aCol[iCol].isPrimKey = 1;

    }
    if( pList->nExpr>1 ) iCol = -1;
  }
  if( iCol>=0 && iCol<pTab->nCol ){
    zType = pTab->aCol[iCol].zType;
  }
  if( zType && sqlite3StrICmp(zType, "INTEGER")==0 ){
................................................................................
    sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2);
    sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort,
                    "indexed columns are not unique", P3_STATIC);
    assert( addr2==sqlite3VdbeCurrentAddr(v) );
  }
  sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0);
  sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1);
  sqlite3VdbeChangeP2(v, addr1, sqlite3VdbeCurrentAddr(v));
  sqlite3VdbeAddOp(v, OP_Close, iTab, 0);
  sqlite3VdbeAddOp(v, OP_Close, iIdx, 0);
}

/*
** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
** and pTblList is the name of the table that is to be indexed.  Both will 
................................................................................
    zName = sqlite3NameFromToken(pName);
    if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
    if( zName==0 ) goto exit_create_index;
    if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
      goto exit_create_index;
    }
    if( !db->init.busy ){
      Index *pISameName;    /* Another index with the same name */
      Table *pTSameName;    /* A table with same name as the index */
      if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
      if( (pISameName = sqlite3FindIndex(db, zName, db->aDb[iDb].zName))!=0 ){
        sqlite3ErrorMsg(pParse, "index %s already exists", zName);
        goto exit_create_index;
      }
      if( (pTSameName = sqlite3FindTable(db, zName, 0))!=0 ){
        sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
        goto exit_create_index;
      }
    }
  }else{
    char zBuf[30];
    int n;
................................................................................
  /* 
  ** Allocate the index structure. 
  */
  pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 + sizeof(int) +
                        (sizeof(int)*2 + sizeof(CollSeq*))*pList->nExpr );
  if( sqlite3_malloc_failed ) goto exit_create_index;
  pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr];
  pIndex->aiRowEst = &pIndex->aiColumn[pList->nExpr];
  pIndex->zName = (char*)&pIndex->aiRowEst[pList->nExpr+1];
  strcpy(pIndex->zName, zName);
  pIndex->pTable = pTab;
  pIndex->nColumn = pList->nExpr;
  pIndex->onError = onError;
  pIndex->autoIndex = pName==0;
  pIndex->iDb = iDb;
................................................................................
**           aiRowEst[N]>=1
**
** Apart from that, we have little to go on besides intuition as to
** how aiRowEst[] should be initialized.  The numbers generated here
** are based on typical values found in actual indices.
*/
void sqlite3DefaultRowEst(Index *pIdx){
  int *a = pIdx->aiRowEst;
  int i;
  assert( a!=0 );
  a[0] = 1000000;
  for(i=pIdx->nColumn; i>=1; i--){
    a[i] = 10;
  }
  if( pIdx->onError!=OE_None ){
................................................................................
    destroyRootPage(pParse, pIndex->tnum, iDb);
    sqlite3VdbeOp3(v, OP_DropIndex, iDb, 0, pIndex->zName, 0);
  }

exit_drop_index:
  sqlite3SrcListDelete(pName);
}










































/*
** Append a new element to the given IdList.  Create a new IdList if
** need be.
**
** A new IdList is returned, or NULL if malloc() fails.
*/
IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){

  if( pList==0 ){
    pList = sqliteMalloc( sizeof(IdList) );
    if( pList==0 ) return 0;
    pList->nAlloc = 0;
  }
  if( pList->nId>=pList->nAlloc ){
    struct IdList_item *a;
    pList->nAlloc = pList->nAlloc*2 + 5;
    a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]) );
    if( a==0 ){
      sqlite3IdListDelete(pList);
      return 0;
    }
    pList->a = a;
  }
  memset(&pList->a[pList->nId], 0, sizeof(pList->a[0]));
  pList->a[pList->nId].zName = sqlite3NameFromToken(pToken);
  pList->nId++;
  return pList;
}

/*
** Delete an IdList.
*/
void sqlite3IdListDelete(IdList *pList){







|







 







|








>







>









|







 







<







 







|







 







<







 







<
|







 







|







 







>
|
>







 







|







 







<
<

|



|







 







|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>





|
<
<
<
|
|
|
|
<
<
<
|
<







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
128
129
130
131
132
133
134

135
136
137
138
139
140
141
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
631
632
633
634
635
636
637

638
639
640
641
642
643
644
...
709
710
711
712
713
714
715

716
717
718
719
720
721
722
723
...
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
....
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
....
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
....
2111
2112
2113
2114
2115
2116
2117


2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
....
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
....
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
....
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523



2524
2525
2526
2527



2528

2529
2530
2531
2532
2533
2534
2535
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
................................................................................
    ** set for each database that is used.  Generate code to start a
    ** transaction on each used database and to verify the schema cookie
    ** on each used database.
    */
    if( pParse->cookieGoto>0 ){
      u32 mask;
      int iDb;
      sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
      for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
        if( (mask & pParse->cookieMask)==0 ) continue;
        sqlite3VdbeAddOp(v, OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
        sqlite3VdbeAddOp(v, OP_VerifyCookie, iDb, pParse->cookieValue[iDb]);
      }
      sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->cookieGoto);
    }

#ifndef SQLITE_OMIT_TRACE
    /* Add a No-op that contains the complete text of the compiled SQL
    ** statement as its P3 argument.  This does not change the functionality
    ** of the program. 
    **
    ** This is used to implement sqlite3_trace().
    */
    sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail-pParse->zSql);
#endif /* SQLITE_OMIT_TRACE */
  }


  /* Get the VDBE program ready for execution
  */
  if( v && pParse->nErr==0 ){
    FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
    sqlite3VdbeTrace(v, trace);
    sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem+3,
                         pParse->nTab+3, pParse->explain);
    pParse->rc = SQLITE_DONE;
    pParse->colNamesSet = 0;
  }else if( pParse->rc==SQLITE_OK ){
    pParse->rc = SQLITE_ERROR;
  }
  pParse->nTab = 0;
  pParse->nMem = 0;
................................................................................
** Not everything is nestable.  This facility is designed to permit
** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER.  Use
** care if you decide to try to use this routine for some other purposes.
*/
void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
  va_list ap;
  char *zSql;

# define SAVE_SZ  (sizeof(Parse) - offsetof(Parse,nVar))
  char saveBuf[SAVE_SZ];

  if( pParse->nErr ) return;
  assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
  va_start(ap, zFormat);
  zSql = sqlite3VMPrintf(zFormat, ap);
................................................................................
  va_end(ap);
  if( zSql==0 ){
    return;   /* A malloc must have failed */
  }
  pParse->nested++;
  memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
  memset(&pParse->nVar, 0, SAVE_SZ);
  sqlite3RunParser(pParse, zSql, 0);
  sqliteFree(zSql);
  memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
  pParse->nested--;
}

/*
** Locate the in-memory structure that describes a particular database
................................................................................
  Token *pStart,   /* The "CREATE" token */
  Token *pName1,   /* First part of the name of the table or view */
  Token *pName2,   /* Second part of the name of the table or view */
  int isTemp,      /* True if this is a TEMP table */
  int isView       /* True if this is a VIEW */
){
  Table *pTable;

  char *zName = 0; /* The name of the new table */
  sqlite3 *db = pParse->db;
  Vdbe *v;
  int iDb;         /* Database number to create the table in */
  Token *pName;    /* Unqualified name of the table to create */

  /* The table or view name to create is passed to this routine via tokens
................................................................................
    goto begin_table_error;
  }
  pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName);
  if( pTable ){
    sqlite3ErrorMsg(pParse, "table %T already exists", pName);
    goto begin_table_error;
  }

  if( sqlite3FindIndex(db, zName, 0)!=0 && (iDb==0 || !db->init.busy) ){
    sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
    goto begin_table_error;
  }
  pTable = sqliteMalloc( sizeof(Table) );
  if( pTable==0 ){
    pParse->rc = SQLITE_NOMEM;
    pParse->nErr++;
................................................................................
  int i;
  Column *pCol;

  if( (p = pParse->pNewTable)==0 ) return;
  i = p->nCol-1;
  if( i<0 ) return;
  pCol = &p->aCol[i];
  sqliteFree(pCol->zType);
  pCol->zType = sqlite3NameFromToken(pType);
  pCol->affinity = sqlite3AffinityType(pType);
}

/*
** The expression is the default value for the most recently added column
** of the table currently under construction.
................................................................................
  }else{
    for(i=0; i<pList->nExpr; i++){
      for(iCol=0; iCol<pTab->nCol; iCol++){
        if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
          break;
        }
      }
      if( iCol<pTab->nCol ){
        pTab->aCol[iCol].isPrimKey = 1;
      }
    }
    if( pList->nExpr>1 ) iCol = -1;
  }
  if( iCol>=0 && iCol<pTab->nCol ){
    zType = pTab->aCol[iCol].zType;
  }
  if( zType && sqlite3StrICmp(zType, "INTEGER")==0 ){
................................................................................
    sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2);
    sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort,
                    "indexed columns are not unique", P3_STATIC);
    assert( addr2==sqlite3VdbeCurrentAddr(v) );
  }
  sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0);
  sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1);
  sqlite3VdbeJumpHere(v, addr1);
  sqlite3VdbeAddOp(v, OP_Close, iTab, 0);
  sqlite3VdbeAddOp(v, OP_Close, iIdx, 0);
}

/*
** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
** and pTblList is the name of the table that is to be indexed.  Both will 
................................................................................
    zName = sqlite3NameFromToken(pName);
    if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
    if( zName==0 ) goto exit_create_index;
    if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
      goto exit_create_index;
    }
    if( !db->init.busy ){


      if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
      if( sqlite3FindIndex(db, zName, db->aDb[iDb].zName)!=0 ){
        sqlite3ErrorMsg(pParse, "index %s already exists", zName);
        goto exit_create_index;
      }
      if( sqlite3FindTable(db, zName, 0)!=0 ){
        sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
        goto exit_create_index;
      }
    }
  }else{
    char zBuf[30];
    int n;
................................................................................
  /* 
  ** Allocate the index structure. 
  */
  pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 + sizeof(int) +
                        (sizeof(int)*2 + sizeof(CollSeq*))*pList->nExpr );
  if( sqlite3_malloc_failed ) goto exit_create_index;
  pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr];
  pIndex->aiRowEst = (unsigned*)&pIndex->aiColumn[pList->nExpr];
  pIndex->zName = (char*)&pIndex->aiRowEst[pList->nExpr+1];
  strcpy(pIndex->zName, zName);
  pIndex->pTable = pTab;
  pIndex->nColumn = pList->nExpr;
  pIndex->onError = onError;
  pIndex->autoIndex = pName==0;
  pIndex->iDb = iDb;
................................................................................
**           aiRowEst[N]>=1
**
** Apart from that, we have little to go on besides intuition as to
** how aiRowEst[] should be initialized.  The numbers generated here
** are based on typical values found in actual indices.
*/
void sqlite3DefaultRowEst(Index *pIdx){
  unsigned *a = pIdx->aiRowEst;
  int i;
  assert( a!=0 );
  a[0] = 1000000;
  for(i=pIdx->nColumn; i>=1; i--){
    a[i] = 10;
  }
  if( pIdx->onError!=OE_None ){
................................................................................
    destroyRootPage(pParse, pIndex->tnum, iDb);
    sqlite3VdbeOp3(v, OP_DropIndex, iDb, 0, pIndex->zName, 0);
  }

exit_drop_index:
  sqlite3SrcListDelete(pName);
}

/*
** ppArray points into a structure where there is an array pointer
** followed by two integers. The first integer is the
** number of elements in the structure array.  The second integer
** is the number of allocated slots in the array.
**
** In other words, the structure looks something like this:
**
**        struct Example1 {
**          struct subElem *aEntry;
**          int nEntry;
**          int nAlloc;
**        }
**
** The pnEntry parameter points to the equivalent of Example1.nEntry.
**
** This routine allocates a new slot in the array, zeros it out,
** and returns its index.  If malloc fails a negative number is returned.
**
** szEntry is the sizeof of a single array entry.  initSize is the 
** number of array entries allocated on the initial allocation.
*/
int sqlite3ArrayAllocate(void **ppArray, int szEntry, int initSize){
  char *p;
  int *an = (int*)&ppArray[1];
  if( an[0]>=an[1] ){
    void *pNew;
    int newSize;
    newSize = an[1]*2 + initSize;
    pNew = sqliteRealloc(*ppArray, newSize*szEntry);
    if( pNew==0 ){
      return -1;
    }
    an[1] = newSize;
    *ppArray = pNew;
  }
  p = *ppArray;
  memset(&p[an[0]*szEntry], 0, szEntry);
  return an[0]++;
}

/*
** Append a new element to the given IdList.  Create a new IdList if
** need be.
**
** A new IdList is returned, or NULL if malloc() fails.
*/
IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){
  int i;
  if( pList==0 ){
    pList = sqliteMalloc( sizeof(IdList) );
    if( pList==0 ) return 0;
    pList->nAlloc = 0;
  }
  i = sqlite3ArrayAllocate((void**)&pList->a, sizeof(pList->a[0]), 5);



  if( i<0 ){
    sqlite3IdListDelete(pList);
    return 0;
  }



  pList->a[i].zName = sqlite3NameFromToken(pToken);

  return pList;
}

/*
** Delete an IdList.
*/
void sqlite3IdListDelete(IdList *pList){

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

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
** $Id: callback.c,v 1.4 2005/09/01 06:07:55 rmsimpson Exp $
*/

#include "sqliteInt.h"

/*
** Invoke the 'collation needed' callback to request a collation sequence
** in the database text encoding of name zName, length nName.







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
** $Id: callback.c,v 1.5 2005/10/05 19:38:29 rmsimpson Exp $
*/

#include "sqliteInt.h"

/*
** Invoke the 'collation needed' callback to request a collation sequence
** in the database text encoding of name zName, length nName.

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

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** An tokenizer for SQL
**
** This file contains C code that implements the sqlite3_complete() API.
** This code used to be part of the tokenizer.c source file.  But by
** separating it out, the code will be automatically omitted from
** static links that do not use it.
**
** $Id: complete.c,v 1.2 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#ifndef SQLITE_OMIT_COMPLETE

/*
** This is defined in tokenize.c.  We just have to import the definition.
*/







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** An tokenizer for SQL
**
** This file contains C code that implements the sqlite3_complete() API.
** This code used to be part of the tokenizer.c source file.  But by
** separating it out, the code will be automatically omitted from
** static links that do not use it.
**
** $Id: complete.c,v 1.3 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#ifndef SQLITE_OMIT_COMPLETE

/*
** This is defined in tokenize.c.  We just have to import the definition.
*/

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

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement date and time
** functions for SQLite.  
**
** There is only one exported symbol in this file - the function
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
**
** NOTES:
**
** SQLite processes all times and dates as Julian Day numbers.  The
** dates and times are stored as the number of days since noon
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
** calendar system.







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement date and time
** functions for SQLite.  
**
** There is only one exported symbol in this file - the function
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
**
** NOTES:
**
** SQLite processes all times and dates as Julian Day numbers.  The
** dates and times are stored as the number of days since noon
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
** calendar system.

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
**
** $Id: delete.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** Look up every table that is named in pSrc.  If any table is not found,
** add an error message to pParse->zErrMsg and return NULL.  If all tables
** are found, return a pointer to the last table.
................................................................................
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    goto delete_from_cleanup;
  }
  if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
  sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb);

  /* If we are trying to delete from a view, construct that view into
  ** a temporary table.
  */
  if( isView ){
    Select *pView = sqlite3SelectDup(pTab->pSelect);
    sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0);
    sqlite3SelectDelete(pView);
  }

  /* Initialize the counter of the number of rows deleted, if
  ** we are counting rows.
  */
  if( db->flags & SQLITE_CountRows ){
................................................................................
  int iCur,          /* Cursor number for the table */
  int count          /* Increment the row change counter */
){
  int addr;
  addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
  sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
  sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
  sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
}

/*
** This routine generates VDBE code that causes the deletion of all
** index entries associated with a single row of a single table.
**
** The VDBE must be in a particular state when this routine is called.







|







 







|
|



|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
**
** $Id: delete.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** Look up every table that is named in pSrc.  If any table is not found,
** add an error message to pParse->zErrMsg and return NULL.  If all tables
** are found, return a pointer to the last table.
................................................................................
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    goto delete_from_cleanup;
  }
  if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
  sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb);

  /* If we are trying to delete from a view, realize that view into
  ** a ephemeral table.
  */
  if( isView ){
    Select *pView = sqlite3SelectDup(pTab->pSelect);
    sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0);
    sqlite3SelectDelete(pView);
  }

  /* Initialize the counter of the number of rows deleted, if
  ** we are counting rows.
  */
  if( db->flags & SQLITE_CountRows ){
................................................................................
  int iCur,          /* Cursor number for the table */
  int count          /* Increment the row change counter */
){
  int addr;
  addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0);
  sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0);
  sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
  sqlite3VdbeJumpHere(v, addr);
}

/*
** This routine generates VDBE code that causes the deletion of all
** index entries associated with a single row of a single table.
**
** The VDBE must be in a particular state when this routine is called.

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
...
542
543
544
545
546
547
548
549
550
551






552
553
554
555
556
557
558
...
688
689
690
691
692
693
694

695
696
697
698
699
700
701
....
1223
1224
1225
1226
1227
1228
1229

1230


1231
1232
1233





1234
1235
1236
1237
1238
1239
1240
....
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
....
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
....
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
....
1441
1442
1443
1444
1445
1446
1447
1448
1449


1450









1451
1452
1453
1454
1455
1456
1457
1458
....
1593
1594
1595
1596
1597
1598
1599

1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
....
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
....
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
....
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
....
2017
2018
2019
2020
2021
2022
2023

2024
2025
2026
2027
2028
2029
2030
....
2040
2041
2042
2043
2044
2045
2046

2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059

2060
2061











2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077

2078

2079
2080




2081

2082
2083
2084
2085








2086
2087
2088
2089
2090
2091
2092
2093
2094






2095











2096
2097
2098
2099
2100
















2101
2102
2103
2104


2105
2106
2107
2108




2109
2110
2111
2112
2113


2114
2115
2116
2117


2118

2119
2120
2121




2122




2123

2124
2125
2126
2127





2128
2129
2130
2131
2132
2133
2134
....
2145
2146
2147
2148
2149
2150
2151


















**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.15 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
        break;
      }
    }
    if( i>=pParse->nVarExpr ){
      pExpr->iTable = ++pParse->nVar;
      if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
        pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
        pParse->apVarExpr = sqliteRealloc(pParse->apVarExpr,
                       pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
      }
      if( !sqlite3_malloc_failed ){
        assert( pParse->apVarExpr!=0 );
        pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
      }
    }
................................................................................
  pNew->pOrderBy = sqlite3ExprListDup(p->pOrderBy);
  pNew->op = p->op;
  pNew->pPrior = sqlite3SelectDup(p->pPrior);
  pNew->pLimit = sqlite3ExprDup(p->pLimit);
  pNew->pOffset = sqlite3ExprDup(p->pOffset);
  pNew->iLimit = -1;
  pNew->iOffset = -1;
  pNew->ppOpenVirtual = 0;
  pNew->isResolved = p->isResolved;
  pNew->isAgg = p->isAgg;






  return pNew;
}
#else
Select *sqlite3SelectDup(Select *p){
  assert( p==0 );
  return 0;
}
................................................................................
    case TK_FUNCTION:
      if( *((int*)pArg)==2 ) return 0;
      /* Fall through */
    case TK_ID:
    case TK_COLUMN:
    case TK_DOT:
    case TK_AGG_FUNCTION:

#ifndef SQLITE_OMIT_SUBQUERY
    case TK_SELECT:
    case TK_EXISTS:
#endif
      *((int*)pArg) = 0;
      return 2;
    case TK_IN:
................................................................................
** If the expression contains aggregate functions then set the EP_Agg
** property on the expression.
*/
int sqlite3ExprResolveNames(
  NameContext *pNC,       /* Namespace to resolve expressions in. */
  Expr *pExpr             /* The expression to be analyzed. */
){

  if( pExpr==0 ) return 0;


  walkExprTree(pExpr, nameResolverStep, pNC);
  if( pNC->nErr>0 ){
    ExprSetProperty(pExpr, EP_Error);





  }
  return ExprHasProperty(pExpr, EP_Error);
}

/*
** A pointer instance of this structure is used to pass information
** through walkExprTree into codeSubqueryStep().
................................................................................
  ** If all of the above are false, then we can run this code just once
  ** save the results, and reuse the same result on subsequent invocations.
  */
  if( !ExprHasAnyProperty(pExpr, EP_VarSelect) && !pParse->trigStack ){
    int mem = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0);
    testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0);
    assert( testAddr>0 );
    sqlite3VdbeAddOp(v, OP_Integer, 1, 0);
    sqlite3VdbeAddOp(v, OP_MemStore, mem, 1);
  }

  if( pExpr->pSelect ){
    sqlite3VdbeAddOp(v, OP_AggContextPush, 0, 0);
  }

  switch( pExpr->op ){
    case TK_IN: {
      char affinity;
      KeyInfo keyInfo;
      int addr;        /* Address of OP_OpenVirtual instruction */
................................................................................
          ** disable the test that was generated above that makes sure
          ** this code only executes once.  Because for a non-constant
          ** expression we need to rerun this code each time.
          */
          if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){
            VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1);
            int i;
            for(i=0; i<4; i++){
              aOp[i].opcode = OP_Noop;
            }
            testAddr = 0;
          }

          /* Evaluate the expression and insert it into the temp table */
          sqlite3ExprCode(pParse, pE2);
................................................................................
                          sqlite3Expr(TK_INTEGER, 0, 0, &one), 0);
      }
      sqlite3Select(pParse, pSel, sop, pExpr->iColumn, 0, 0, 0, 0);
      break;
    }
  }

  if( pExpr->pSelect ){
    sqlite3VdbeAddOp(v, OP_AggContextPop, 0, 0);
  }
  if( testAddr ){
    sqlite3VdbeChangeP2(v, testAddr, sqlite3VdbeCurrentAddr(v));

  }
  return;
}
#endif /* SQLITE_OMIT_SUBQUERY */

/*
** Generate an instruction that will put the integer describe by
................................................................................
  if( v==0 ) return;
  if( pExpr==0 ){
    sqlite3VdbeAddOp(v, OP_Null, 0, 0);
    return;
  }
  op = pExpr->op;
  switch( op ){
    case TK_COLUMN: {
      if( !pParse->fillAgg && pExpr->iAgg>=0 ){


        sqlite3VdbeAddOp(v, OP_AggGet, pExpr->iAggCtx, pExpr->iAgg);









      }else if( pExpr->iColumn>=0 ){
        sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn);
        sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn);
      }else{
        sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0);
      }
      break;
    }
................................................................................
      sqlite3ExprCode(pParse, pExpr->pLeft);
      dest = sqlite3VdbeCurrentAddr(v) + 2;
      sqlite3VdbeAddOp(v, op, 1, dest);
      sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
      break;
    }
    case TK_AGG_FUNCTION: {

      sqlite3VdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg);
      break;
    }
    case TK_CONST_FUNC:
    case TK_FUNCTION: {
      ExprList *pList = pExpr->pList;
      int nExpr = pList ? pList->nExpr : 0;
      FuncDef *pDef;
      int nId;
      const char *zId;
      int p2 = 0;
      int i;
      u8 enc = pParse->db->enc;
      CollSeq *pColl = 0;
      zId = pExpr->token.z;
      nId = pExpr->token.n;
      pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0);
      assert( pDef!=0 );
      nExpr = sqlite3ExprCodeExprList(pParse, pList);
      for(i=0; i<nExpr && i<32; i++){
        if( sqlite3ExprIsConstant(pList->a[i].pExpr) ){
          p2 |= (1<<i);
        }
        if( pDef->needCollSeq && !pColl ){
          pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
        }
      }
      if( pDef->needCollSeq ){
        if( !pColl ) pColl = pParse->db->pDfltColl; 
        sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);
      }
      sqlite3VdbeOp3(v, OP_Function, nExpr, p2, (char*)pDef, P3_FUNCDEF);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_EXISTS:
    case TK_SELECT: {
      sqlite3CodeSubselect(pParse, pExpr);
      sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iColumn, 0);
................................................................................
    case TK_AS: {
      sqlite3ExprCode(pParse, pExpr->pLeft);
      break;
    }
    case TK_CASE: {
      int expr_end_label;
      int jumpInst;
      int addr;
      int nExpr;
      int i;
      ExprList *pEList;
      struct ExprList_item *aListelem;

      assert(pExpr->pList);
      assert((pExpr->pList->nExpr % 2) == 0);
................................................................................
                                 OP_Ne, 0, 1);
          sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
        }else{
          jumpInst = sqlite3VdbeAddOp(v, OP_IfNot, 1, 0);
        }
        sqlite3ExprCode(pParse, aListelem[i+1].pExpr);
        sqlite3VdbeAddOp(v, OP_Goto, 0, expr_end_label);
        addr = sqlite3VdbeCurrentAddr(v);
        sqlite3VdbeChangeP2(v, jumpInst, addr);
      }
      if( pExpr->pLeft ){
        sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
      }
      if( pExpr->pRight ){
        sqlite3ExprCode(pParse, pExpr->pRight);
      }else{
................................................................................
      addr = codeCompare(pParse, pLeft, pRight, OP_Lt, 0, !jumpIfNull);

      pRight = pExpr->pList->a[1].pExpr;
      sqlite3ExprCode(pParse, pRight);
      codeCompare(pParse, pLeft, pRight, OP_Le, dest, jumpIfNull);

      sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
      sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
      sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
      break;
    }
    default: {
      sqlite3ExprCode(pParse, pExpr);
      sqlite3VdbeAddOp(v, OP_If, jumpIfNull, dest);
      break;
................................................................................
  int i;
  if( pA==0 ){
    return pB==0;
  }else if( pB==0 ){
    return 0;
  }
  if( pA->op!=pB->op ) return 0;

  if( !sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 0;
  if( !sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 0;
  if( pA->pList ){
    if( pB->pList==0 ) return 0;
    if( pA->pList->nExpr!=pB->pList->nExpr ) return 0;
    for(i=0; i<pA->pList->nExpr; i++){
      if( !sqlite3ExprCompare(pA->pList->a[i].pExpr, pB->pList->a[i].pExpr) ){
................................................................................
    if( pB->token.z==0 ) return 0;
    if( pB->token.n!=pA->token.n ) return 0;
    if( sqlite3StrNICmp(pA->token.z, pB->token.z, pB->token.n)!=0 ) return 0;
  }
  return 1;
}


/*
** Add a new element to the pParse->aAgg[] array and return its index.
** The new element is initialized to zero.  The calling function is
** expected to fill it in.
*/
static int appendAggInfo(Parse *pParse){
  if( (pParse->nAgg & 0x7)==0 ){
    int amt = pParse->nAgg + 8;
    AggExpr *aAgg = sqliteRealloc(pParse->aAgg, amt*sizeof(pParse->aAgg[0]));
    if( aAgg==0 ){
      return -1;
    }
    pParse->aAgg = aAgg;

  }
  memset(&pParse->aAgg[pParse->nAgg], 0, sizeof(pParse->aAgg[0]));











  return pParse->nAgg++;
}

/*
** This is an xFunc for walkExprTree() used to implement 
** sqlite3ExprAnalyzeAggregates().  See sqlite3ExprAnalyzeAggregates
** for additional information.
**
** This routine analyzes the aggregate function at pExpr.
*/
static int analyzeAggregate(void *pArg, Expr *pExpr){
  int i;
  AggExpr *aAgg;
  NameContext *pNC = (NameContext *)pArg;
  Parse *pParse = pNC->pParse;
  SrcList *pSrcList = pNC->pSrcList;



  switch( pExpr->op ){
    case TK_COLUMN: {




      for(i=0; pSrcList && i<pSrcList->nSrc; i++){

        if( pExpr->iTable==pSrcList->a[i].iCursor ){
          aAgg = pParse->aAgg;
          for(i=0; i<pParse->nAgg; i++){
            if( aAgg[i].isAgg ) continue;








            if( aAgg[i].pExpr->iTable==pExpr->iTable
             && aAgg[i].pExpr->iColumn==pExpr->iColumn ){
              break;
            }
          }
          if( i>=pParse->nAgg ){
            i = appendAggInfo(pParse);
            if( i<0 ) return 1;
            pParse->aAgg[i].isAgg = 0;






            pParse->aAgg[i].pExpr = pExpr;











          }
          pExpr->iAgg = i;
          pExpr->iAggCtx = pNC->nDepth;
          return 1;
        }
















      }
      return 1;
    }
    case TK_AGG_FUNCTION: {


      if( pNC->nDepth==0 ){
        aAgg = pParse->aAgg;
        for(i=0; i<pParse->nAgg; i++){
          if( !aAgg[i].isAgg ) continue;




          if( sqlite3ExprCompare(aAgg[i].pExpr, pExpr) ){
            break;
          }
        }
        if( i>=pParse->nAgg ){


          u8 enc = pParse->db->enc;
          i = appendAggInfo(pParse);
          if( i<0 ) return 1;
          pParse->aAgg[i].isAgg = 1;


          pParse->aAgg[i].pExpr = pExpr;

          pParse->aAgg[i].pFunc = sqlite3FindFunction(pParse->db,
               pExpr->token.z, pExpr->token.n,
               pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0);




        }




        pExpr->iAgg = i;

        return 1;
      }
    }
  }





  if( pExpr->pSelect ){
    pNC->nDepth++;
    walkSelectExpr(pExpr->pSelect, analyzeAggregate, pNC);
    pNC->nDepth--;
  }
  return 0;
}
................................................................................
** the number of errors.
*/
int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
  int nErr = pNC->pParse->nErr;
  walkExprTree(pExpr, analyzeAggregate, pNC);
  return pNC->pParse->nErr - nErr;
}

























|







 







|







 







<


>
>
>
>
>
>







 







>







 







>

>
>



>
>
>
>
>







 







|
<
|
<
<
<
<







 







|







 







<
<
<

<
>







 







|
|
>
>
|
>
>
>
>
>
>
>
>
>
|







 







>
|









|










|









|







 







<







 







|
<







 







|







 







>







 







>

|
<
|

|
|
|
|
<
|
|
<
>
|
<
>
>
>
>
>
>
>
>
>
>
>
|
|










<



>
|
>


>
>
>
>
|
>
|
<
<
<
>
>
>
>
>
>
>
>
|
|
|
|
|
<
<
<
<
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>

<
<
|
>
>
>
>
|



|
>
>

<
<
|
>
>
|
>
|
|
|
>
>
>
>
|
>
>
>
>

>




>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
...
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
....
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
....
1289
1290
1291
1292
1293
1294
1295
1296

1297




1298
1299
1300
1301
1302
1303
1304
....
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
....
1405
1406
1407
1408
1409
1410
1411



1412

1413
1414
1415
1416
1417
1418
1419
1420
....
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
....
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
....
1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717
1718
1719
....
1733
1734
1735
1736
1737
1738
1739
1740

1741
1742
1743
1744
1745
1746
1747
....
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
....
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
....
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066

2067
2068
2069
2070
2071
2072

2073
2074

2075
2076

2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099

2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114



2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127




2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146



2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170


2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183


2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
....
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.16 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
        break;
      }
    }
    if( i>=pParse->nVarExpr ){
      pExpr->iTable = ++pParse->nVar;
      if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
        pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
        sqlite3ReallocOrFree((void**)&pParse->apVarExpr,
                       pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
      }
      if( !sqlite3_malloc_failed ){
        assert( pParse->apVarExpr!=0 );
        pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
      }
    }
................................................................................
  pNew->pOrderBy = sqlite3ExprListDup(p->pOrderBy);
  pNew->op = p->op;
  pNew->pPrior = sqlite3SelectDup(p->pPrior);
  pNew->pLimit = sqlite3ExprDup(p->pLimit);
  pNew->pOffset = sqlite3ExprDup(p->pOffset);
  pNew->iLimit = -1;
  pNew->iOffset = -1;

  pNew->isResolved = p->isResolved;
  pNew->isAgg = p->isAgg;
  pNew->usesVirt = 0;
  pNew->disallowOrderBy = 0;
  pNew->pRightmost = 0;
  pNew->addrOpenVirt[0] = -1;
  pNew->addrOpenVirt[1] = -1;
  pNew->addrOpenVirt[2] = -1;
  return pNew;
}
#else
Select *sqlite3SelectDup(Select *p){
  assert( p==0 );
  return 0;
}
................................................................................
    case TK_FUNCTION:
      if( *((int*)pArg)==2 ) return 0;
      /* Fall through */
    case TK_ID:
    case TK_COLUMN:
    case TK_DOT:
    case TK_AGG_FUNCTION:
    case TK_AGG_COLUMN:
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_SELECT:
    case TK_EXISTS:
#endif
      *((int*)pArg) = 0;
      return 2;
    case TK_IN:
................................................................................
** If the expression contains aggregate functions then set the EP_Agg
** property on the expression.
*/
int sqlite3ExprResolveNames(
  NameContext *pNC,       /* Namespace to resolve expressions in. */
  Expr *pExpr             /* The expression to be analyzed. */
){
  int savedHasAgg;
  if( pExpr==0 ) return 0;
  savedHasAgg = pNC->hasAgg;
  pNC->hasAgg = 0;
  walkExprTree(pExpr, nameResolverStep, pNC);
  if( pNC->nErr>0 ){
    ExprSetProperty(pExpr, EP_Error);
  }
  if( pNC->hasAgg ){
    ExprSetProperty(pExpr, EP_Agg);
  }else if( savedHasAgg ){
    pNC->hasAgg = 1;
  }
  return ExprHasProperty(pExpr, EP_Error);
}

/*
** A pointer instance of this structure is used to pass information
** through walkExprTree into codeSubqueryStep().
................................................................................
  ** If all of the above are false, then we can run this code just once
  ** save the results, and reuse the same result on subsequent invocations.
  */
  if( !ExprHasAnyProperty(pExpr, EP_VarSelect) && !pParse->trigStack ){
    int mem = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0);
    testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0);
    assert( testAddr>0 || sqlite3_malloc_failed );

    sqlite3VdbeAddOp(v, OP_MemInt, 1, mem);




  }

  switch( pExpr->op ){
    case TK_IN: {
      char affinity;
      KeyInfo keyInfo;
      int addr;        /* Address of OP_OpenVirtual instruction */
................................................................................
          ** disable the test that was generated above that makes sure
          ** this code only executes once.  Because for a non-constant
          ** expression we need to rerun this code each time.
          */
          if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){
            VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1);
            int i;
            for(i=0; i<3; i++){
              aOp[i].opcode = OP_Noop;
            }
            testAddr = 0;
          }

          /* Evaluate the expression and insert it into the temp table */
          sqlite3ExprCode(pParse, pE2);
................................................................................
                          sqlite3Expr(TK_INTEGER, 0, 0, &one), 0);
      }
      sqlite3Select(pParse, pSel, sop, pExpr->iColumn, 0, 0, 0, 0);
      break;
    }
  }




  if( testAddr ){

    sqlite3VdbeJumpHere(v, testAddr);
  }
  return;
}
#endif /* SQLITE_OMIT_SUBQUERY */

/*
** Generate an instruction that will put the integer describe by
................................................................................
  if( v==0 ) return;
  if( pExpr==0 ){
    sqlite3VdbeAddOp(v, OP_Null, 0, 0);
    return;
  }
  op = pExpr->op;
  switch( op ){
    case TK_AGG_COLUMN: {
      AggInfo *pAggInfo = pExpr->pAggInfo;
      struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg];
      if( !pAggInfo->directMode ){
        sqlite3VdbeAddOp(v, OP_MemLoad, pCol->iMem, 0);
        break;
      }else if( pAggInfo->useSortingIdx ){
        sqlite3VdbeAddOp(v, OP_Column, pAggInfo->sortingIdx,
                              pCol->iSorterColumn);
        break;
      }
      /* Otherwise, fall thru into the TK_COLUMN case */
    }
    case TK_COLUMN: {
      if( pExpr->iColumn>=0 ){
        sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn);
        sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn);
      }else{
        sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0);
      }
      break;
    }
................................................................................
      sqlite3ExprCode(pParse, pExpr->pLeft);
      dest = sqlite3VdbeCurrentAddr(v) + 2;
      sqlite3VdbeAddOp(v, op, 1, dest);
      sqlite3VdbeAddOp(v, OP_AddImm, -1, 0);
      break;
    }
    case TK_AGG_FUNCTION: {
      AggInfo *pInfo = pExpr->pAggInfo;
      sqlite3VdbeAddOp(v, OP_MemLoad, pInfo->aFunc[pExpr->iAgg].iMem, 0);
      break;
    }
    case TK_CONST_FUNC:
    case TK_FUNCTION: {
      ExprList *pList = pExpr->pList;
      int nExpr = pList ? pList->nExpr : 0;
      FuncDef *pDef;
      int nId;
      const char *zId;
      int constMask = 0;
      int i;
      u8 enc = pParse->db->enc;
      CollSeq *pColl = 0;
      zId = pExpr->token.z;
      nId = pExpr->token.n;
      pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0);
      assert( pDef!=0 );
      nExpr = sqlite3ExprCodeExprList(pParse, pList);
      for(i=0; i<nExpr && i<32; i++){
        if( sqlite3ExprIsConstant(pList->a[i].pExpr) ){
          constMask |= (1<<i);
        }
        if( pDef->needCollSeq && !pColl ){
          pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr);
        }
      }
      if( pDef->needCollSeq ){
        if( !pColl ) pColl = pParse->db->pDfltColl; 
        sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);
      }
      sqlite3VdbeOp3(v, OP_Function, constMask, nExpr, (char*)pDef, P3_FUNCDEF);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_EXISTS:
    case TK_SELECT: {
      sqlite3CodeSubselect(pParse, pExpr);
      sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iColumn, 0);
................................................................................
    case TK_AS: {
      sqlite3ExprCode(pParse, pExpr->pLeft);
      break;
    }
    case TK_CASE: {
      int expr_end_label;
      int jumpInst;

      int nExpr;
      int i;
      ExprList *pEList;
      struct ExprList_item *aListelem;

      assert(pExpr->pList);
      assert((pExpr->pList->nExpr % 2) == 0);
................................................................................
                                 OP_Ne, 0, 1);
          sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
        }else{
          jumpInst = sqlite3VdbeAddOp(v, OP_IfNot, 1, 0);
        }
        sqlite3ExprCode(pParse, aListelem[i+1].pExpr);
        sqlite3VdbeAddOp(v, OP_Goto, 0, expr_end_label);
        sqlite3VdbeJumpHere(v, jumpInst);

      }
      if( pExpr->pLeft ){
        sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
      }
      if( pExpr->pRight ){
        sqlite3ExprCode(pParse, pExpr->pRight);
      }else{
................................................................................
      addr = codeCompare(pParse, pLeft, pRight, OP_Lt, 0, !jumpIfNull);

      pRight = pExpr->pList->a[1].pExpr;
      sqlite3ExprCode(pParse, pRight);
      codeCompare(pParse, pLeft, pRight, OP_Le, dest, jumpIfNull);

      sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
      sqlite3VdbeJumpHere(v, addr);
      sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
      break;
    }
    default: {
      sqlite3ExprCode(pParse, pExpr);
      sqlite3VdbeAddOp(v, OP_If, jumpIfNull, dest);
      break;
................................................................................
  int i;
  if( pA==0 ){
    return pB==0;
  }else if( pB==0 ){
    return 0;
  }
  if( pA->op!=pB->op ) return 0;
  if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 0;
  if( !sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 0;
  if( !sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 0;
  if( pA->pList ){
    if( pB->pList==0 ) return 0;
    if( pA->pList->nExpr!=pB->pList->nExpr ) return 0;
    for(i=0; i<pA->pList->nExpr; i++){
      if( !sqlite3ExprCompare(pA->pList->a[i].pExpr, pB->pList->a[i].pExpr) ){
................................................................................
    if( pB->token.z==0 ) return 0;
    if( pB->token.n!=pA->token.n ) return 0;
    if( sqlite3StrNICmp(pA->token.z, pB->token.z, pB->token.n)!=0 ) return 0;
  }
  return 1;
}


/*
** Add a new element to the pAggInfo->aCol[] array.  Return the index of

** the new element.  Return a negative number if malloc fails.
*/
static int addAggInfoColumn(AggInfo *pInfo){
  int i;
  i = sqlite3ArrayAllocate((void**)&pInfo->aCol, sizeof(pInfo->aCol[0]), 3);
  if( i<0 ){

    return -1;
  }

  return i;
}    


/*
** Add a new element to the pAggInfo->aFunc[] array.  Return the index of
** the new element.  Return a negative number if malloc fails.
*/
static int addAggInfoFunc(AggInfo *pInfo){
  int i;
  i = sqlite3ArrayAllocate((void**)&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2);
  if( i<0 ){
    return -1;
  }
  return i;
}    

/*
** This is an xFunc for walkExprTree() used to implement 
** sqlite3ExprAnalyzeAggregates().  See sqlite3ExprAnalyzeAggregates
** for additional information.
**
** This routine analyzes the aggregate function at pExpr.
*/
static int analyzeAggregate(void *pArg, Expr *pExpr){
  int i;

  NameContext *pNC = (NameContext *)pArg;
  Parse *pParse = pNC->pParse;
  SrcList *pSrcList = pNC->pSrcList;
  AggInfo *pAggInfo = pNC->pAggInfo;
  

  switch( pExpr->op ){
    case TK_COLUMN: {
      /* Check to see if the column is in one of the tables in the FROM
      ** clause of the aggregate query */
      if( pSrcList ){
        struct SrcList_item *pItem = pSrcList->a;
        for(i=0; i<pSrcList->nSrc; i++, pItem++){
          struct AggInfo_col *pCol;
          if( pExpr->iTable==pItem->iCursor ){



            /* If we reach this point, it means that pExpr refers to a table
            ** that is in the FROM clause of the aggregate query.  
            **
            ** Make an entry for the column in pAggInfo->aCol[] if there
            ** is not an entry there already.
            */
            pCol = pAggInfo->aCol;
            for(i=0; i<pAggInfo->nColumn; i++, pCol++){
              if( pCol->iTable==pExpr->iTable &&
                  pCol->iColumn==pExpr->iColumn ){
                break;
              }
            }




            if( i>=pAggInfo->nColumn && (i = addAggInfoColumn(pAggInfo))>=0 ){
              pCol = &pAggInfo->aCol[i];
              pCol->iTable = pExpr->iTable;
              pCol->iColumn = pExpr->iColumn;
              pCol->iMem = pParse->nMem++;
              pCol->iSorterColumn = -1;
              pCol->pExpr = pExpr;
              if( pAggInfo->pGroupBy ){
                int j, n;
                ExprList *pGB = pAggInfo->pGroupBy;
                struct ExprList_item *pTerm = pGB->a;
                n = pGB->nExpr;
                for(j=0; j<n; j++, pTerm++){
                  Expr *pE = pTerm->pExpr;
                  if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
                      pE->iColumn==pExpr->iColumn ){
                    pCol->iSorterColumn = j;
                    break;
                  }



                }
              }
              if( pCol->iSorterColumn<0 ){
                pCol->iSorterColumn = pAggInfo->nSortingColumn++;
              }
            }
            /* There is now an entry for pExpr in pAggInfo->aCol[] (either
            ** because it was there before or because we just created it).
            ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
            ** pAggInfo->aCol[] entry.
            */
            pExpr->pAggInfo = pAggInfo;
            pExpr->op = TK_AGG_COLUMN;
            pExpr->iAgg = i;
            break;
          } /* endif pExpr->iTable==pItem->iCursor */
        } /* end loop over pSrcList */
      }
      return 1;
    }
    case TK_AGG_FUNCTION: {
      /* The pNC->nDepth==0 test causes aggregate functions in subqueries
      ** to be ignored */
      if( pNC->nDepth==0 ){


        /* Check to see if pExpr is a duplicate of another aggregate 
        ** function that is already in the pAggInfo structure
        */
        struct AggInfo_func *pItem = pAggInfo->aFunc;
        for(i=0; i<pAggInfo->nFunc; i++, pItem++){
          if( sqlite3ExprCompare(pItem->pExpr, pExpr) ){
            break;
          }
        }
        if( i>=pAggInfo->nFunc ){
          /* pExpr is original.  Make a new entry in pAggInfo->aFunc[]
          */
          u8 enc = pParse->db->enc;


          i = addAggInfoFunc(pAggInfo);
          if( i>=0 ){
            pItem = &pAggInfo->aFunc[i];
            pItem->pExpr = pExpr;
            pItem->iMem = pParse->nMem++;
            pItem->pFunc = sqlite3FindFunction(pParse->db,
                   pExpr->token.z, pExpr->token.n,
                   pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0);
            if( pExpr->flags & EP_Distinct ){
              pItem->iDistinct = pParse->nTab++;
            }else{
              pItem->iDistinct = -1;
            }
          }
        }
        /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
        */
        pExpr->iAgg = i;
        pExpr->pAggInfo = pAggInfo;
        return 1;
      }
    }
  }

  /* Recursively walk subqueries looking for TK_COLUMN nodes that need
  ** to be changed to TK_AGG_COLUMN.  But increment nDepth so that
  ** TK_AGG_FUNCTION nodes in subqueries will be unchanged.
  */
  if( pExpr->pSelect ){
    pNC->nDepth++;
    walkSelectExpr(pExpr->pSelect, analyzeAggregate, pNC);
    pNC->nDepth--;
  }
  return 0;
}
................................................................................
** the number of errors.
*/
int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
  int nErr = pNC->pParse->nErr;
  walkExprTree(pExpr, analyzeAggregate, pNC);
  return pNC->pParse->nErr - nErr;
}

/*
** Call sqlite3ExprAnalyzeAggregates() for every expression in an
** expression list.  Return the number of errors.
**
** If an error is found, the analysis is cut short.
*/
int sqlite3ExprAnalyzeAggList(NameContext *pNC, ExprList *pList){
  struct ExprList_item *pItem;
  int i;
  int nErr = 0;
  if( pList ){
    for(pItem=pList->a, i=0; nErr==0 && i<pList->nExpr; i++, pItem++){
      nErr += sqlite3ExprAnalyzeAggregates(pNC, pItem->pExpr);
    }
  }
  return nErr;
}

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

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
815
816
817
818
819
820
821

822
823
824
825
826
827
828
829

830
831

832
833



834
835
836
837
838


839




840
841
842
843
844
845
846
847
848
849
850
...
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
...
912
913
914
915
916
917
918
919

920
921
922
923

924
925
926
927
928
929
930
....
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
....
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.9 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"
................................................................................
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
*/
typedef struct SumCtx SumCtx;
struct SumCtx {
  double sum;     /* Sum of terms */
  int cnt;        /* Number of elements summed */

};

/*
** Routines used to compute the sum or average.
*/
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
  SumCtx *p;
  if( argc<1 ) return;

  p = sqlite3_aggregate_context(context, sizeof(*p));
  if( p && SQLITE_NULL!=sqlite3_value_type(argv[0]) ){

    p->sum += sqlite3_value_double(argv[0]);
    p->cnt++;



  }
}
static void sumFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, sizeof(*p));


  sqlite3_result_double(context, p ? p->sum : 0.0);




}
static void avgFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, sizeof(*p));
  if( p && p->cnt>0 ){
    sqlite3_result_double(context, p->sum/(double)p->cnt);
  }
}

/*
** An instance of the following structure holds the context of a
................................................................................
  p = sqlite3_aggregate_context(context, sizeof(*p));
  if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
    p->n++;
  }
}   
static void countFinalize(sqlite3_context *context){
  CountCtx *p;
  p = sqlite3_aggregate_context(context, sizeof(*p));
  sqlite3_result_int(context, p ? p->n : 0);
}

/*
** Routines to implement min() and max() aggregate functions.
*/
static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){
................................................................................
    }
  }else{
    sqlite3VdbeMemCopy(pBest, pArg);
  }
}
static void minMaxFinalize(sqlite3_context *context){
  sqlite3_value *pRes;
  pRes = (sqlite3_value *)sqlite3_aggregate_context(context, sizeof(Mem));

  if( pRes->flags ){
    sqlite3_result_value(context, pRes);
  }
  sqlite3VdbeMemRelease(pRes);

}


/*
** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
................................................................................
  sqlite3RegisterLikeFunctions(db, 0);
#endif
}

/*
** Set the LIKEOPT flag on the 2-argument function with the given name.
*/
static void setLikeOptFlag(sqlite3 *db, const char *zName){
  FuncDef *pDef;
  pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0);
  if( pDef ){
    pDef->flags = SQLITE_FUNC_LIKEOPT;
  }
}

/*
** Register the built-in LIKE and GLOB functions.  The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive.  GLOB is always case sensitive.
................................................................................
  }else{
    pInfo = (struct compareInfo*)&likeInfoNorm;
  }
  sqlite3_create_function(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
  sqlite3_create_function(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
  sqlite3_create_function(db, "glob", 2, SQLITE_UTF8, 
      (struct compareInfo*)&globInfo, likeFunc, 0,0);
  setLikeOptFlag(db, "glob");
  if( caseSensitive ){
    setLikeOptFlag(db, "like");
  }

}

/*
** pExpr points to an expression which implements a function.  If
** it is appropriate to apply the LIKE optimization to that function
** then set aWc[0] through aWc[2] to the wildcard characters and
** return TRUE.  If the function is not a LIKE-style function then
** return FALSE.
*/
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, char *aWc){
  FuncDef *pDef;
  if( pExpr->op!=TK_FUNCTION ){
    return 0;
  }
  if( pExpr->pList->nExpr!=2 ){
    return 0;
  }
  pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2,
                             SQLITE_UTF8, 0);
  if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKEOPT)==0 ){
    return 0;
  }

  /* The memcpy() statement assumes that the wildcard characters are
  ** the first three statements in the compareInfo structure.  The
  ** asserts() that follow verify that assumption
  */
  memcpy(aWc, pDef->pUserData, 3);
  assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
  assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
  assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );


  return 1;
}







|







 







>







|
>

|
>


>
>
>




|
>
>
|
>
>
>
>



|







 







|







 







|
>
|
|
|
|
>







 







|



|







 







|
<
|
<
>









|









|











<
>


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
...
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
...
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
....
1075
1076
1077
1078
1079
1080
1081
1082

1083

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115

1116
1117
1118
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"
................................................................................
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
*/
typedef struct SumCtx SumCtx;
struct SumCtx {
  double sum;     /* Sum of terms */
  int cnt;        /* Number of elements summed */
  u8 seenFloat;   /* True if there has been any floating point value */
};

/*
** Routines used to compute the sum or average.
*/
static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
  SumCtx *p;
  int type;
  assert( argc==1 );
  p = sqlite3_aggregate_context(context, sizeof(*p));
  type = sqlite3_value_type(argv[0]);
  if( p && type!=SQLITE_NULL ){
    p->sum += sqlite3_value_double(argv[0]);
    p->cnt++;
    if( type==SQLITE_FLOAT ){
      p->seenFloat = 1;
    }
  }
}
static void sumFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  if( p && p->cnt>0 ){
    if( p->seenFloat ){
      sqlite3_result_double(context, p->sum);
    }else{
      sqlite3_result_int64(context, (i64)p->sum);
    }
  }
}
static void avgFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  if( p && p->cnt>0 ){
    sqlite3_result_double(context, p->sum/(double)p->cnt);
  }
}

/*
** An instance of the following structure holds the context of a
................................................................................
  p = sqlite3_aggregate_context(context, sizeof(*p));
  if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
    p->n++;
  }
}   
static void countFinalize(sqlite3_context *context){
  CountCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  sqlite3_result_int(context, p ? p->n : 0);
}

/*
** Routines to implement min() and max() aggregate functions.
*/
static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){
................................................................................
    }
  }else{
    sqlite3VdbeMemCopy(pBest, pArg);
  }
}
static void minMaxFinalize(sqlite3_context *context){
  sqlite3_value *pRes;
  pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
  if( pRes ){
    if( pRes->flags ){
      sqlite3_result_value(context, pRes);
    }
    sqlite3VdbeMemRelease(pRes);
  }
}


/*
** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
................................................................................
  sqlite3RegisterLikeFunctions(db, 0);
#endif
}

/*
** Set the LIKEOPT flag on the 2-argument function with the given name.
*/
static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){
  FuncDef *pDef;
  pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0);
  if( pDef ){
    pDef->flags = flagVal;
  }
}

/*
** Register the built-in LIKE and GLOB functions.  The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive.  GLOB is always case sensitive.
................................................................................
  }else{
    pInfo = (struct compareInfo*)&likeInfoNorm;
  }
  sqlite3_create_function(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
  sqlite3_create_function(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0);
  sqlite3_create_function(db, "glob", 2, SQLITE_UTF8, 
      (struct compareInfo*)&globInfo, likeFunc, 0,0);
  setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);

  setLikeOptFlag(db, "like", 

      caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
}

/*
** pExpr points to an expression which implements a function.  If
** it is appropriate to apply the LIKE optimization to that function
** then set aWc[0] through aWc[2] to the wildcard characters and
** return TRUE.  If the function is not a LIKE-style function then
** return FALSE.
*/
int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
  FuncDef *pDef;
  if( pExpr->op!=TK_FUNCTION ){
    return 0;
  }
  if( pExpr->pList->nExpr!=2 ){
    return 0;
  }
  pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2,
                             SQLITE_UTF8, 0);
  if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
    return 0;
  }

  /* The memcpy() statement assumes that the wildcard characters are
  ** the first three statements in the compareInfo structure.  The
  ** asserts() that follow verify that assumption
  */
  memcpy(aWc, pDef->pUserData, 3);
  assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
  assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
  assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );

  *pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
  return 1;
}

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This is the implementation of generic hash-tables
** used in SQLite.
**
** $Id: hash.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <assert.h>

/* Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This is the implementation of generic hash-tables
** used in SQLite.
**
** $Id: hash.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <assert.h>

/* Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for the generic hash-table implemenation
** used in SQLite.
**
** $Id: hash.h,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#ifndef _SQLITE_HASH_H_
#define _SQLITE_HASH_H_

/* Forward declarations of structures. */
typedef struct Hash Hash;
typedef struct HashElem HashElem;







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for the generic hash-table implemenation
** used in SQLite.
**
** $Id: hash.h,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#ifndef _SQLITE_HASH_H_
#define _SQLITE_HASH_H_

/* Forward declarations of structures. */
typedef struct Hash Hash;
typedef struct HashElem HashElem;

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
...
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
...
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
...
917
918
919
920
921
922
923
924
925
926
927

928
929
930
931
932
933
934
....
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023

1024
1025

1026
1027
1028
1029
1030
1031
1032
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................
      sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
      sqlite3VdbeAddOp(v, OP_Return, 0, 0);

      /* The following code runs first because the GOTO at the very top
      ** of the program jumps to it.  Create the temporary table, then jump
      ** back up and execute the SELECT code above.
      */
      sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
      sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0);
      sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
      sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
      sqlite3VdbeResolveLabel(v, iCleanup);
    }else{
      sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
    }
  }else{
    /* This is the case if the data for the INSERT is coming from a VALUES
    ** clause
    */
    NameContext sNC;
    memset(&sNC, 0, sizeof(sNC));
................................................................................
    sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol);
  }
    
  /* Initialize the count of rows to be inserted
  */
  if( db->flags & SQLITE_CountRows ){
    iCntMem = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
    sqlite3VdbeAddOp(v, OP_MemStore, iCntMem, 1);
  }

  /* Open tables and indices if there are no row triggers */
  if( !triggers_exist ){
    base = pParse->nTab;
    sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite);
  }
................................................................................
  int onError;
  int addr;
  int extra;
  int iCur;
  Index *pIdx;
  int seenReplace = 0;
  int jumpInst1=0, jumpInst2;
  int contAddr;
  int hasTwoRowids = (isUpdate && rowidChng);

  v = sqlite3GetVdbe(pParse);
  assert( v!=0 );
  assert( pTab->pSelect==0 );  /* This table is not a VIEW */
  nCol = pTab->nCol;

................................................................................
      }
      case OE_Replace: {
        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
        sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0);
        break;
      }
    }
    sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v));
  }

  /* Test all CHECK constraints
  */
  /**** TBD ****/

  /* If we have an INTEGER PRIMARY KEY, make sure the primary key
................................................................................
      case OE_Ignore: {
        assert( seenReplace==0 );
        sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
        sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
        break;
      }
    }
    contAddr = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeChangeP2(v, jumpInst2, contAddr);
    if( isUpdate ){
      sqlite3VdbeChangeP2(v, jumpInst1, contAddr);

      sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
      sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
    }
  }

  /* Test all UNIQUE constraints by creating entries for each UNIQUE
  ** index and making sure that duplicate entries do not already exist.
................................................................................
          sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1);
          sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
        }
        seenReplace = 1;
        break;
      }
    }
    contAddr = sqlite3VdbeCurrentAddr(v);
#if NULL_DISTINCT_FOR_UNIQUE
    sqlite3VdbeChangeP2(v, jumpInst1, contAddr);

#endif
    sqlite3VdbeChangeP2(v, jumpInst2, contAddr);

  }
}

/*
** This routine generates code to finish the INSERT or UPDATE operation
** that was started by a prior call to sqlite3GenerateConstraintChecks.
** The stack must contain keys for all active indices followed by data







|







 







|





|







 







<
|







 







<







 







|







 







|
<

<
>







 







<

<
>

<
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
...
466
467
468
469
470
471
472

473
474
475
476
477
478
479
480
...
812
813
814
815
816
817
818

819
820
821
822
823
824
825
...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
...
915
916
917
918
919
920
921
922

923

924
925
926
927
928
929
930
931
....
1011
1012
1013
1014
1015
1016
1017

1018

1019
1020

1021
1022
1023
1024
1025
1026
1027
1028
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................
      sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
      sqlite3VdbeAddOp(v, OP_Return, 0, 0);

      /* The following code runs first because the GOTO at the very top
      ** of the program jumps to it.  Create the temporary table, then jump
      ** back up and execute the SELECT code above.
      */
      sqlite3VdbeJumpHere(v, iInitCode);
      sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0);
      sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
      sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
      sqlite3VdbeResolveLabel(v, iCleanup);
    }else{
      sqlite3VdbeJumpHere(v, iInitCode);
    }
  }else{
    /* This is the case if the data for the INSERT is coming from a VALUES
    ** clause
    */
    NameContext sNC;
    memset(&sNC, 0, sizeof(sNC));
................................................................................
    sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol);
  }
    
  /* Initialize the count of rows to be inserted
  */
  if( db->flags & SQLITE_CountRows ){
    iCntMem = pParse->nMem++;

    sqlite3VdbeAddOp(v, OP_MemInt, 0, iCntMem);
  }

  /* Open tables and indices if there are no row triggers */
  if( !triggers_exist ){
    base = pParse->nTab;
    sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite);
  }
................................................................................
  int onError;
  int addr;
  int extra;
  int iCur;
  Index *pIdx;
  int seenReplace = 0;
  int jumpInst1=0, jumpInst2;

  int hasTwoRowids = (isUpdate && rowidChng);

  v = sqlite3GetVdbe(pParse);
  assert( v!=0 );
  assert( pTab->pSelect==0 );  /* This table is not a VIEW */
  nCol = pTab->nCol;

................................................................................
      }
      case OE_Replace: {
        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
        sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0);
        break;
      }
    }
    sqlite3VdbeJumpHere(v, addr);
  }

  /* Test all CHECK constraints
  */
  /**** TBD ****/

  /* If we have an INTEGER PRIMARY KEY, make sure the primary key
................................................................................
      case OE_Ignore: {
        assert( seenReplace==0 );
        sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
        sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
        break;
      }
    }
    sqlite3VdbeJumpHere(v, jumpInst2);

    if( isUpdate ){

      sqlite3VdbeJumpHere(v, jumpInst1);
      sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1);
      sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
    }
  }

  /* Test all UNIQUE constraints by creating entries for each UNIQUE
  ** index and making sure that duplicate entries do not already exist.
................................................................................
          sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1);
          sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
        }
        seenReplace = 1;
        break;
      }
    }

#if NULL_DISTINCT_FOR_UNIQUE

    sqlite3VdbeJumpHere(v, jumpInst1);
#endif

    sqlite3VdbeJumpHere(v, jumpInst2);
  }
}

/*
** This routine generates code to finish the INSERT or UPDATE operation
** that was started by a prior call to sqlite3GenerateConstraintChecks.
** The stack must contain keys for all active indices followed by data

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Hash score: 156 */
static int keywordCode(const char *z, int n){
  static const char zText[526] =
    "ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER"
    "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYANALYZE"
    "XCLUSIVEXISTSTATEMENTANDEFERRABLEATTACHAVINGLOBEFOREIGNOREINDEX"
    "AUTOINCREMENTBEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETE"
    "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS"
    "CURRENT_DATECURRENT_TIMESTAMPRAGMATCHDESCDETACHDISTINCTDROPRIMARY"
    "FAILIMITFROMFULLGROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULL"
    "JOINORDEREPLACEOUTERESTRICTRIGHTROLLBACKROWHENUNIONUNIQUEUSING"
    "VACUUMVALUESVIEWHERE";
  static const unsigned char aHash[127] = {
      91,  81, 104,  90,   0,   4,   0,   0, 111,   0,  77,   0,   0,
      94,  44,   0,  92,   0, 103, 106,  96,   0,   0,  10,   0,   0,
     110,   0, 107, 102,   0,  28,  48,   0,  41,   0,   0,  65,  71,
       0,  63,  19,   0,   0,  36,  83,   0, 105,  74,   0,   0,  33,
       0,  61,  37,   0,   8,   0, 112,  38,  12,   0,  78,  40,  25,
      66,   0,   0,  31,  82,  53,  30,  50,  20,  88,   0,  34,   0,
      75,  26,   0,  72,   0,   0,   0,  64,  47,  67,  22,  87,  29,
      69,  86,   0,   1,   0,   9, 100,  58,  18,   0, 109,  76,  98,
      54,   6,  85,   0,   0,  49,  93,   0, 101,   0,  70,   0,   0,
      15,   0, 113,  51,  56,   0,   2,  55,   0, 108,
  };
  static const unsigned char aNext[113] = {
       0,   0,   0,   0,   0,   3,   0,   0,   0,   0,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,  17,   0,   0,   0,   0,
       0,  11,   0,   0,   0,   0,   5,  13,   0,   7,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,  43,   0,   0,   0,   0,   0,
       0,   0,  16,   0,  23,  52,   0,   0,   0,   0,  45,   0,  59,
       0,   0,   0,   0,   0,   0,   0,   0,  73,  42,   0,   0,  24,
      60,  21,   0,  80,  32,  68,   0,   0,  84,  46,   0,   0,   0,
       0,   0,   0,   0,  39,  95,  97,   0,   0,  99,   0,  14,  27,
      79,   0,  57,  89,   0,  35,   0,  62,   0,
  };
  static const unsigned char aLen[113] = {
       5,   5,   4,   4,   9,   2,   3,   8,   2,   6,   4,   3,   7,
      11,   2,   7,   5,   5,   4,   5,   3,   5,  10,   6,   4,   6,
       7,   6,   7,   9,   3,   7,   9,   6,   9,   3,  10,   6,   6,
       4,   6,   3,   7,   6,   7,   5,  13,   2,   2,   5,   5,   6,
       7,   3,   7,   4,   4,   2,   7,   3,   8,   6,   4,   4,   7,
       6,   6,   8,  10,   9,   6,   5,  12,  12,  17,   6,   5,   4,
       6,   8,   2,   4,   7,   4,   5,   4,   4,   5,   6,   9,   6,
       7,   4,   2,   6,   3,   6,   4,   5,   7,   5,   8,   5,   8,
       3,   4,   5,   6,   5,   6,   6,   4,   5,
  };
  static const unsigned short int aOffset[113] = {
       0,   4,   7,  10,  10,  14,  19,  21,  26,  27,  32,  34,  36,
      42,  51,  52,  57,  61,  65,  67,  71,  74,  78,  86,  91,  94,
      99, 105, 108, 113, 118, 122, 128, 136, 141, 150, 152, 162, 167,
     172, 175, 177, 177, 181, 185, 187, 192, 194, 196, 205, 208, 212,
     218, 224, 224, 227, 230, 234, 236, 237, 241, 248, 254, 258, 262,
     269, 275, 281, 289, 296, 305, 311, 316, 328, 328, 344, 348, 353,
     357, 363, 364, 371, 374, 381, 384, 389, 393, 397, 400, 406, 415,
     421, 428, 431, 431, 434, 437, 443, 447, 451, 458, 462, 470, 475,
     483, 485, 489, 494, 500, 505, 511, 517, 520,
  };
  static const unsigned char aCode[113] = {
    TK_ABORT,      TK_TABLE,      TK_JOIN_KW,    TK_TEMP,       TK_TEMP,       
    TK_OR,         TK_ADD,        TK_DATABASE,   TK_AS,         TK_SELECT,     
    TK_THEN,       TK_END,        TK_DEFAULT,    TK_TRANSACTION,TK_ON,         
    TK_JOIN_KW,    TK_ALTER,      TK_RAISE,      TK_EACH,       TK_CHECK,      
    TK_KEY,        TK_AFTER,      TK_REFERENCES, TK_ESCAPE,     TK_ELSE,       
    TK_EXCEPT,     TK_TRIGGER,    TK_LIKE_KW,    TK_EXPLAIN,    TK_INITIALLY,  
    TK_ALL,        TK_ANALYZE,    TK_EXCLUSIVE,  TK_EXISTS,     TK_STATEMENT,  
................................................................................
    TK_BEFORE,     TK_FOR,        TK_FOREIGN,    TK_IGNORE,     TK_REINDEX,    
    TK_INDEX,      TK_AUTOINCR,   TK_TO,         TK_IN,         TK_BEGIN,      
    TK_JOIN_KW,    TK_RENAME,     TK_BETWEEN,    TK_NOT,        TK_NOTNULL,    
    TK_NULL,       TK_LIKE_KW,    TK_BY,         TK_CASCADE,    TK_ASC,        
    TK_DEFERRED,   TK_DELETE,     TK_CASE,       TK_CAST,       TK_COLLATE,    
    TK_COLUMNKW,   TK_COMMIT,     TK_CONFLICT,   TK_CONSTRAINT, TK_INTERSECT,  
    TK_CREATE,     TK_JOIN_KW,    TK_CTIME_KW,   TK_CTIME_KW,   TK_CTIME_KW,   
    TK_PRAGMA,     TK_MATCH,      TK_DESC,       TK_DETACH,     TK_DISTINCT,   
    TK_IS,         TK_DROP,       TK_PRIMARY,    TK_FAIL,       TK_LIMIT,      
    TK_FROM,       TK_JOIN_KW,    TK_GROUP,      TK_UPDATE,     TK_IMMEDIATE,  
    TK_INSERT,     TK_INSTEAD,    TK_INTO,       TK_OF,         TK_OFFSET,     
    TK_SET,        TK_ISNULL,     TK_JOIN,       TK_ORDER,      TK_REPLACE,    
    TK_JOIN_KW,    TK_RESTRICT,   TK_JOIN_KW,    TK_ROLLBACK,   TK_ROW,        
    TK_WHEN,       TK_UNION,      TK_UNIQUE,     TK_USING,      TK_VACUUM,     
    TK_VALUES,     TK_VIEW,       TK_WHERE,      
  };
  int h, i;
  if( n<2 ) return TK_ID;
  h = ((sqlite3UpperToLower[((unsigned char*)z)[0]]*4) ^
      (sqlite3UpperToLower[((unsigned char*)z)[n-1]]*3) ^
      n) % 127;
  for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
|

|





|

|
|

|
|
|
|
|
|

|

|

|





|
|
|
|

|





|
|
|
|

|





|
|
|
|

|







 







|
|



|
|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Hash score: 158 */
static int keywordCode(const char *z, int n){
  static const char zText[535] =
    "ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER"
    "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYANALYZE"
    "XCLUSIVEXISTSTATEMENTANDEFERRABLEATTACHAVINGLOBEFOREIGNOREINDEX"
    "AUTOINCREMENTBEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETE"
    "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS"
    "CURRENT_DATECURRENT_TIMESTAMPLANDESCDETACHDISTINCTDROPRAGMATCH"
    "FAILIMITFROMFULLGROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULL"
    "JOINORDEREPLACEOUTERESTRICTPRIMARYQUERYRIGHTROLLBACKROWHENUNION"
    "UNIQUEUSINGVACUUMVALUESVIEWHERE";
  static const unsigned char aHash[127] = {
      91,  80, 106,  90,   0,   4,   0,   0, 113,   0,  83,   0,   0,
      94,  44,  76,  92,   0, 105, 108,  96,   0,   0,  10,   0,   0,
     112,   0, 109, 102,   0,  28,  48,   0,  41,   0,   0,  65,  71,
       0,  63,  19,   0, 104,  36, 103,   0, 107,  74,   0,   0,  33,
       0,  61,  37,   0,   8,   0, 114,  38,  12,   0,  77,  40,  25,
      66,   0,   0,  31,  81,  53,  30,  50,  20,  88,   0,  34,   0,
      75,  26,   0,  72,   0,   0,   0,  64,  47,  67,  22,  87,  29,
      69,  86,   0,   1,   0,   9, 100,  58,  18,   0, 111,  82,  98,
      54,   6,  85,   0,   0,  49,  93,   0, 101,   0,  70,   0,   0,
      15,   0, 115,  51,  56,   0,   2,  55,   0, 110,
  };
  static const unsigned char aNext[115] = {
       0,   0,   0,   0,   0,   3,   0,   0,   0,   0,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,   0,  17,   0,   0,   0,   0,
       0,  11,   0,   0,   0,   0,   5,  13,   0,   7,   0,   0,   0,
       0,   0,   0,   0,   0,   0,   0,  43,   0,   0,   0,   0,   0,
       0,   0,  16,   0,  23,  52,   0,   0,   0,   0,  45,   0,  59,
       0,   0,   0,   0,   0,   0,   0,   0,  73,  42,   0,  24,  60,
      21,   0,  79,   0,   0,  68,   0,   0,  84,  46,   0,   0,   0,
       0,   0,   0,   0,  39,  95,  97,   0,   0,  99,   0,  32,   0,
      14,  27,  78,   0,  57,  89,   0,  35,   0,  62,   0,
  };
  static const unsigned char aLen[115] = {
       5,   5,   4,   4,   9,   2,   3,   8,   2,   6,   4,   3,   7,
      11,   2,   7,   5,   5,   4,   5,   3,   5,  10,   6,   4,   6,
       7,   6,   7,   9,   3,   7,   9,   6,   9,   3,  10,   6,   6,
       4,   6,   3,   7,   6,   7,   5,  13,   2,   2,   5,   5,   6,
       7,   3,   7,   4,   4,   2,   7,   3,   8,   6,   4,   4,   7,
       6,   6,   8,  10,   9,   6,   5,  12,  12,  17,   4,   4,   6,
       8,   2,   4,   6,   5,   4,   5,   4,   4,   5,   6,   9,   6,
       7,   4,   2,   6,   3,   6,   4,   5,   7,   5,   8,   7,   5,
       5,   8,   3,   4,   5,   6,   5,   6,   6,   4,   5,
  };
  static const unsigned short int aOffset[115] = {
       0,   4,   7,  10,  10,  14,  19,  21,  26,  27,  32,  34,  36,
      42,  51,  52,  57,  61,  65,  67,  71,  74,  78,  86,  91,  94,
      99, 105, 108, 113, 118, 122, 128, 136, 141, 150, 152, 162, 167,
     172, 175, 177, 177, 181, 185, 187, 192, 194, 196, 205, 208, 212,
     218, 224, 224, 227, 230, 234, 236, 237, 241, 248, 254, 258, 262,
     269, 275, 281, 289, 296, 305, 311, 316, 328, 328, 344, 348, 352,
     358, 359, 366, 369, 373, 378, 381, 386, 390, 394, 397, 403, 412,
     418, 425, 428, 428, 431, 434, 440, 444, 448, 455, 459, 467, 474,
     479, 484, 492, 494, 498, 503, 509, 514, 520, 526, 529,
  };
  static const unsigned char aCode[115] = {
    TK_ABORT,      TK_TABLE,      TK_JOIN_KW,    TK_TEMP,       TK_TEMP,       
    TK_OR,         TK_ADD,        TK_DATABASE,   TK_AS,         TK_SELECT,     
    TK_THEN,       TK_END,        TK_DEFAULT,    TK_TRANSACTION,TK_ON,         
    TK_JOIN_KW,    TK_ALTER,      TK_RAISE,      TK_EACH,       TK_CHECK,      
    TK_KEY,        TK_AFTER,      TK_REFERENCES, TK_ESCAPE,     TK_ELSE,       
    TK_EXCEPT,     TK_TRIGGER,    TK_LIKE_KW,    TK_EXPLAIN,    TK_INITIALLY,  
    TK_ALL,        TK_ANALYZE,    TK_EXCLUSIVE,  TK_EXISTS,     TK_STATEMENT,  
................................................................................
    TK_BEFORE,     TK_FOR,        TK_FOREIGN,    TK_IGNORE,     TK_REINDEX,    
    TK_INDEX,      TK_AUTOINCR,   TK_TO,         TK_IN,         TK_BEGIN,      
    TK_JOIN_KW,    TK_RENAME,     TK_BETWEEN,    TK_NOT,        TK_NOTNULL,    
    TK_NULL,       TK_LIKE_KW,    TK_BY,         TK_CASCADE,    TK_ASC,        
    TK_DEFERRED,   TK_DELETE,     TK_CASE,       TK_CAST,       TK_COLLATE,    
    TK_COLUMNKW,   TK_COMMIT,     TK_CONFLICT,   TK_CONSTRAINT, TK_INTERSECT,  
    TK_CREATE,     TK_JOIN_KW,    TK_CTIME_KW,   TK_CTIME_KW,   TK_CTIME_KW,   
    TK_PLAN,       TK_DESC,       TK_DETACH,     TK_DISTINCT,   TK_IS,         
    TK_DROP,       TK_PRAGMA,     TK_MATCH,      TK_FAIL,       TK_LIMIT,      
    TK_FROM,       TK_JOIN_KW,    TK_GROUP,      TK_UPDATE,     TK_IMMEDIATE,  
    TK_INSERT,     TK_INSTEAD,    TK_INTO,       TK_OF,         TK_OFFSET,     
    TK_SET,        TK_ISNULL,     TK_JOIN,       TK_ORDER,      TK_REPLACE,    
    TK_JOIN_KW,    TK_RESTRICT,   TK_PRIMARY,    TK_QUERY,      TK_JOIN_KW,    
    TK_ROLLBACK,   TK_ROW,        TK_WHEN,       TK_UNION,      TK_UNIQUE,     
    TK_USING,      TK_VACUUM,     TK_VALUES,     TK_VIEW,       TK_WHERE,      
  };
  int h, i;
  if( n<2 ) return TK_ID;
  h = ((sqlite3UpperToLower[((unsigned char*)z)[0]]*4) ^
      (sqlite3UpperToLower[((unsigned char*)z)[n-1]]*3) ^
      n) % 127;
  for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){

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

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: legacy.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/

#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: legacy.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/

#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*

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

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519
520
521
522
523
524
525



















526
527
528
529
530
531
532
...
690
691
692
693
694
695
696

697
698
699
700
701
702
703
...
725
726
727
728
729
730
731







732
733
734
735
736
737
738
...
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
...
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
....
1015
1016
1017
1018
1019
1020
1021











**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.8 2005/09/01 06:07:55 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
  }
  rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep, 
      pUserData, xFunc, xStep, xFinal);
  return rc;
}
#endif


/*
** Register a trace function.  The pArg from the previously registered trace
** is returned.  
**
** A NULL trace function means that no tracing is executes.  A non-NULL
** trace is a pointer to a function that is invoked at the start of each
** sqlite3_exec().
*/
void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
  void *pOld = db->pTraceArg;
  db->xTrace = xTrace;
  db->pTraceArg = pArg;
  return pOld;
}




















/*** EXPERIMENTAL ***
**
** Register a function to be invoked when a transaction comments.
** If either function returns non-zero, then the commit becomes a
** rollback.
*/
................................................................................
*/
static int openDatabase(
  const char *zFilename, /* Database filename UTF-8 encoded */
  sqlite3 **ppDb         /* OUT: Returned database handle */
){
  sqlite3 *db;
  int rc, i;


  /* Allocate the sqlite data structure */
  db = sqliteMalloc( sizeof(sqlite3) );
  if( db==0 ) goto opendb_out;
  db->priorNewRowid = 0;
  db->magic = SQLITE_MAGIC_BUSY;
  db->nDb = 2;
................................................................................
    assert( rc!=SQLITE_OK );
    db->magic = SQLITE_MAGIC_CLOSED;
    goto opendb_out;
  }

  /* Also add a UTF-8 case-insensitive collation sequence. */
  sqlite3_create_collation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc);








  /* Open the backend database driver */
  rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
  if( rc!=SQLITE_OK ){
    sqlite3Error(db, rc, 0);
    db->magic = SQLITE_MAGIC_CLOSED;
    goto opendb_out;
................................................................................
*/
int sqlite3_reset(sqlite3_stmt *pStmt){
  int rc;
  if( pStmt==0 ){
    rc = SQLITE_OK;
  }else{
    rc = sqlite3VdbeReset((Vdbe*)pStmt);
    sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0, 0);
  }
  return rc;
}

/*
** Register a new collation sequence with the database handle db.
*/
................................................................................
      return SQLITE_BUSY;
    }
    sqlite3ExpirePreparedStatements(db);
  }

  pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1);
  if( 0==pColl ){
   rc = SQLITE_NOMEM;
  }else{
    pColl->xCmp = xCompare;
    pColl->pUser = pCtx;
    pColl->enc = enc;
  }
  sqlite3Error(db, rc, 0);
  return rc;
................................................................................
** by the next COMMIT or ROLLBACK.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite3_get_autocommit(sqlite3 *db){
  return db->autoCommit;
}


















|







 







>






|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







>
>
>
>
>
>
>







 







|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
...
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
...
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
...
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
....
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
  }
  rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep, 
      pUserData, xFunc, xStep, xFinal);
  return rc;
}
#endif

#ifndef SQLITE_OMIT_TRACE
/*
** Register a trace function.  The pArg from the previously registered trace
** is returned.  
**
** A NULL trace function means that no tracing is executes.  A non-NULL
** trace is a pointer to a function that is invoked at the start of each
** SQL statement.
*/
void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
  void *pOld = db->pTraceArg;
  db->xTrace = xTrace;
  db->pTraceArg = pArg;
  return pOld;
}
/*
** Register a profile function.  The pArg from the previously registered 
** profile function is returned.  
**
** A NULL profile function means that no profiling is executes.  A non-NULL
** profile is a pointer to a function that is invoked at the conclusion of
** each SQL statement that is run.
*/
void *sqlite3_profile(
  sqlite3 *db,
  void (*xProfile)(void*,const char*,sqlite_uint64),
  void *pArg
){
  void *pOld = db->pProfileArg;
  db->xProfile = xProfile;
  db->pProfileArg = pArg;
  return pOld;
}
#endif /* SQLITE_OMIT_TRACE */

/*** EXPERIMENTAL ***
**
** Register a function to be invoked when a transaction comments.
** If either function returns non-zero, then the commit becomes a
** rollback.
*/
................................................................................
*/
static int openDatabase(
  const char *zFilename, /* Database filename UTF-8 encoded */
  sqlite3 **ppDb         /* OUT: Returned database handle */
){
  sqlite3 *db;
  int rc, i;
  CollSeq *pColl;

  /* Allocate the sqlite data structure */
  db = sqliteMalloc( sizeof(sqlite3) );
  if( db==0 ) goto opendb_out;
  db->priorNewRowid = 0;
  db->magic = SQLITE_MAGIC_BUSY;
  db->nDb = 2;
................................................................................
    assert( rc!=SQLITE_OK );
    db->magic = SQLITE_MAGIC_CLOSED;
    goto opendb_out;
  }

  /* Also add a UTF-8 case-insensitive collation sequence. */
  sqlite3_create_collation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc);

  /* Set flags on the built-in collating sequences */
  db->pDfltColl->type = SQLITE_COLL_BINARY;
  pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 6, 0);
  if( pColl ){
    pColl->type = SQLITE_COLL_NOCASE;
  }

  /* Open the backend database driver */
  rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
  if( rc!=SQLITE_OK ){
    sqlite3Error(db, rc, 0);
    db->magic = SQLITE_MAGIC_CLOSED;
    goto opendb_out;
................................................................................
*/
int sqlite3_reset(sqlite3_stmt *pStmt){
  int rc;
  if( pStmt==0 ){
    rc = SQLITE_OK;
  }else{
    rc = sqlite3VdbeReset((Vdbe*)pStmt);
    sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0);
  }
  return rc;
}

/*
** Register a new collation sequence with the database handle db.
*/
................................................................................
      return SQLITE_BUSY;
    }
    sqlite3ExpirePreparedStatements(db);
  }

  pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1);
  if( 0==pColl ){
    rc = SQLITE_NOMEM;
  }else{
    pColl->xCmp = xCompare;
    pColl->pUser = pCtx;
    pColl->enc = enc;
  }
  sqlite3Error(db, rc, 0);
  return rc;
................................................................................
** by the next COMMIT or ROLLBACK.
**
******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
*/
int sqlite3_get_autocommit(sqlite3 *db){
  return db->autoCommit;
}

#ifdef SQLITE_DEBUG
/*
** The following routine is subtituted for constant SQLITE_CORRUPT in
** debugging builds.  This provides a way to set a breakpoint for when
** corruption is first detected.
*/
int sqlite3Corrupt(void){
  return SQLITE_CORRUPT;
}
#endif

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

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135



136
137
/* See the mkopcodec.awk script for details. */
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
const char *const sqlite3OpcodeNames[] = { "?",
 /*   1 */ "MemLoad",
 /*   2 */ "Column",
 /*   3 */ "SetCookie",
 /*   4 */ "IfMemPos",
 /*   5 */ "MoveGt",
 /*   6 */ "AggFocus",
 /*   7 */ "RowKey",
 /*   8 */ "AggNext",
 /*   9 */ "OpenWrite",
 /*  10 */ "If",
 /*  11 */ "ToInt",
 /*  12 */ "Pop",
 /*  13 */ "AggContextPush",
 /*  14 */ "CollSeq",
 /*  15 */ "OpenRead",
 /*  16 */ "Expire",
 /*  17 */ "SortReset",
 /*  18 */ "AutoCommit",
 /*  19 */ "Sort",
 /*  20 */ "IntegrityCk",
 /*  21 */ "SortInsert",
 /*  22 */ "Function",
 /*  23 */ "Noop",
 /*  24 */ "Return",
 /*  25 */ "NewRowid",
 /*  26 */ "Variable",
 /*  27 */ "String",
 /*  28 */ "ParseSchema",
 /*  29 */ "AggFunc",
 /*  30 */ "Close",
 /*  31 */ "CreateIndex",
 /*  32 */ "IsUnique",
 /*  33 */ "IdxIsNull",
 /*  34 */ "NotFound",
 /*  35 */ "Int64",
 /*  36 */ "MustBeInt",
 /*  37 */ "Halt",
 /*  38 */ "Rowid",
 /*  39 */ "IdxLT",
 /*  40 */ "AddImm",
 /*  41 */ "Statement",
 /*  42 */ "RowData",
 /*  43 */ "MemMax",
 /*  44 */ "Push",
 /*  45 */ "NotExists",
 /*  46 */ "MemIncr",
 /*  47 */ "Gosub",
 /*  48 */ "AggSet",
 /*  49 */ "Integer",
 /*  50 */ "ToNumeric",
 /*  51 */ "SortNext",
 /*  52 */ "Prev",
 /*  53 */ "CreateTable",
 /*  54 */ "Last",
 /*  55 */ "IdxRowid",
 /*  56 */ "MakeIdxRec",
 /*  57 */ "ResetCount",
 /*  58 */ "FifoWrite",
 /*  59 */ "Callback",
 /*  60 */ "ContextPush",
 /*  61 */ "DropTrigger",
 /*  62 */ "DropIndex",
 /*  63 */ "IdxGE",
 /*  64 */ "Or",
 /*  65 */ "And",
 /*  66 */ "Not",
 /*  67 */ "IdxDelete",
 /*  68 */ "Vacuum",
 /*  69 */ "MoveLe",
 /*  70 */ "IsNull",
 /*  71 */ "NotNull",
 /*  72 */ "Ne",
 /*  73 */ "Eq",
 /*  74 */ "Gt",
 /*  75 */ "Le",
 /*  76 */ "Lt",
 /*  77 */ "Ge",
 /*  78 */ "IfNot",
 /*  79 */ "BitAnd",
 /*  80 */ "BitOr",
 /*  81 */ "ShiftLeft",
 /*  82 */ "ShiftRight",
 /*  83 */ "Add",
 /*  84 */ "Subtract",
 /*  85 */ "Multiply",
 /*  86 */ "Divide",
 /*  87 */ "Remainder",
 /*  88 */ "Concat",
 /*  89 */ "Negative",
 /*  90 */ "DropTable",
 /*  91 */ "BitNot",
 /*  92 */ "String8",
 /*  93 */ "MakeRecord",
 /*  94 */ "ToBlob",
 /*  95 */ "Delete",
 /*  96 */ "AggContextPop",
 /*  97 */ "Dup",
 /*  98 */ "Goto",
 /*  99 */ "FifoRead",
 /* 100 */ "Clear",
 /* 101 */ "IdxGT",
 /* 102 */ "MoveLt",
 /* 103 */ "VerifyCookie",
 /* 104 */ "Pull",
 /* 105 */ "ToText",
 /* 106 */ "SetNumColumns",
 /* 107 */ "AbsValue",
 /* 108 */ "Transaction",
 /* 109 */ "AggGet",
 /* 110 */ "ContextPop",
 /* 111 */ "Next",
 /* 112 */ "AggInit",
 /* 113 */ "IdxInsert",
 /* 114 */ "Distinct",
 /* 115 */ "AggReset",
 /* 116 */ "Insert",
 /* 117 */ "Destroy",
 /* 118 */ "ReadCookie",
 /* 119 */ "ForceInt",
 /* 120 */ "LoadAnalysis",
 /* 121 */ "OpenVirtual",
 /* 122 */ "OpenPseudo",
 /* 123 */ "Null",
 /* 124 */ "Blob",
 /* 125 */ "MemStore",
 /* 126 */ "Rewind",
 /* 127 */ "MoveGe",
 /* 128 */ "Found",
 /* 129 */ "NullRow",
 /* 130 */ "Real",
 /* 131 */ "HexBlob",



};
#endif







|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* See the mkopcodec.awk script for details. */
#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
const char *const sqlite3OpcodeNames[] = { "?",
 /*   1 */ "MemLoad",
 /*   2 */ "Column",
 /*   3 */ "SetCookie",
 /*   4 */ "IfMemPos",
 /*   5 */ "Sequence",
 /*   6 */ "MoveGt",
 /*   7 */ "RowKey",
 /*   8 */ "OpenWrite",
 /*   9 */ "If",
 /*  10 */ "ToInt",
 /*  11 */ "Pop",
 /*  12 */ "CollSeq",
 /*  13 */ "OpenRead",
 /*  14 */ "Expire",
 /*  15 */ "AutoCommit",
 /*  16 */ "IntegrityCk",
 /*  17 */ "Sort",
 /*  18 */ "Function",
 /*  19 */ "Noop",
 /*  20 */ "Return",
 /*  21 */ "NewRowid",
 /*  22 */ "Variable",
 /*  23 */ "String",
 /*  24 */ "ParseSchema",
 /*  25 */ "Close",
 /*  26 */ "CreateIndex",
 /*  27 */ "IsUnique",
 /*  28 */ "IdxIsNull",
 /*  29 */ "NotFound",
 /*  30 */ "Int64",
 /*  31 */ "MustBeInt",
 /*  32 */ "Halt",
 /*  33 */ "Rowid",
 /*  34 */ "IdxLT",
 /*  35 */ "AddImm",
 /*  36 */ "Statement",
 /*  37 */ "RowData",
 /*  38 */ "MemMax",
 /*  39 */ "Push",
 /*  40 */ "NotExists",
 /*  41 */ "MemIncr",
 /*  42 */ "Gosub",
 /*  43 */ "Integer",
 /*  44 */ "ToNumeric",
 /*  45 */ "MemInt",
 /*  46 */ "Prev",
 /*  47 */ "CreateTable",
 /*  48 */ "Last",
 /*  49 */ "IdxRowid",
 /*  50 */ "MakeIdxRec",
 /*  51 */ "ResetCount",
 /*  52 */ "FifoWrite",
 /*  53 */ "Callback",
 /*  54 */ "ContextPush",
 /*  55 */ "DropTrigger",
 /*  56 */ "DropIndex",
 /*  57 */ "IdxGE",
 /*  58 */ "IdxDelete",
 /*  59 */ "Vacuum",
 /*  60 */ "MoveLe",
 /*  61 */ "IfNot",
 /*  62 */ "DropTable",
 /*  63 */ "MakeRecord",
 /*  64 */ "ToBlob",
 /*  65 */ "Delete",
 /*  66 */ "AggFinal",
 /*  67 */ "Or",
 /*  68 */ "And",
 /*  69 */ "Not",
 /*  70 */ "Dup",
 /*  71 */ "Goto",
 /*  72 */ "FifoRead",
 /*  73 */ "IsNull",
 /*  74 */ "NotNull",
 /*  75 */ "Ne",
 /*  76 */ "Eq",
 /*  77 */ "Gt",
 /*  78 */ "Le",
 /*  79 */ "Lt",
 /*  80 */ "Ge",
 /*  81 */ "Clear",
 /*  82 */ "BitAnd",
 /*  83 */ "BitOr",
 /*  84 */ "ShiftLeft",
 /*  85 */ "ShiftRight",
 /*  86 */ "Add",
 /*  87 */ "Subtract",
 /*  88 */ "Multiply",
 /*  89 */ "Divide",
 /*  90 */ "Remainder",
 /*  91 */ "Concat",
 /*  92 */ "Negative",
 /*  93 */ "IdxGT",
 /*  94 */ "BitNot",
 /*  95 */ "String8",
 /*  96 */ "MoveLt",
 /*  97 */ "VerifyCookie",
 /*  98 */ "AggStep",
 /*  99 */ "Pull",
 /* 100 */ "ToText",
 /* 101 */ "SetNumColumns",
 /* 102 */ "AbsValue",
 /* 103 */ "Transaction",
 /* 104 */ "ContextPop",
 /* 105 */ "Next",
 /* 106 */ "IdxInsert",
 /* 107 */ "Distinct",
 /* 108 */ "Insert",
 /* 109 */ "Destroy",
 /* 110 */ "ReadCookie",
 /* 111 */ "ForceInt",
 /* 112 */ "LoadAnalysis",
 /* 113 */ "OpenVirtual",
 /* 114 */ "Explain",
 /* 115 */ "OpenPseudo",
 /* 116 */ "Null",
 /* 117 */ "Blob",
 /* 118 */ "MemStore",
 /* 119 */ "Rewind",
 /* 120 */ "MoveGe",
 /* 121 */ "MemMove",
 /* 122 */ "MemNull",
 /* 123 */ "Found",
 /* 124 */ "NullRow",
 /* 125 */ "NotUsed_125",
 /* 126 */ "NotUsed_126",
 /* 127 */ "NotUsed_127",
 /* 128 */ "NotUsed_128",
 /* 129 */ "NotUsed_129",
 /* 130 */ "NotUsed_130",
 /* 131 */ "NotUsed_131",
 /* 132 */ "NotUsed_132",
 /* 133 */ "Real",
 /* 134 */ "HexBlob",
};
#endif

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

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130
131


132
133
134










135
136
137
138
139
140
141
142
143
144
/* Automatically generated.  Do not edit */
/* See the mkopcodeh.awk script for details */
#define OP_MemLoad                              1
#define OP_HexBlob                            131   /* same as TK_BLOB     */
#define OP_Column                               2
#define OP_SetCookie                            3
#define OP_IfMemPos                             4
#define OP_Real                               130   /* same as TK_FLOAT    */

#define OP_MoveGt                               5
#define OP_Ge                                  77   /* same as TK_GE       */
#define OP_AggFocus                             6
#define OP_RowKey                               7
#define OP_AggNext                              8
#define OP_Eq                                  73   /* same as TK_EQ       */
#define OP_OpenWrite                            9
#define OP_NotNull                             71   /* same as TK_NOTNULL  */
#define OP_If                                  10
#define OP_ToInt                               11
#define OP_String8                             92   /* same as TK_STRING   */
#define OP_Pop                                 12
#define OP_AggContextPush                      13
#define OP_CollSeq                             14
#define OP_OpenRead                            15
#define OP_Expire                              16
#define OP_SortReset                           17
#define OP_AutoCommit                          18
#define OP_Gt                                  74   /* same as TK_GT       */
#define OP_Sort                                19
#define OP_IntegrityCk                         20
#define OP_SortInsert                          21
#define OP_Function                            22
#define OP_And                                 65   /* same as TK_AND      */
#define OP_Subtract                            84   /* same as TK_MINUS    */
#define OP_Noop                                23
#define OP_Return                              24
#define OP_Remainder                           87   /* same as TK_REM      */
#define OP_NewRowid                            25
#define OP_Multiply                            85   /* same as TK_STAR     */
#define OP_Variable                            26
#define OP_String                              27
#define OP_ParseSchema                         28
#define OP_AggFunc                             29
#define OP_Close                               30
#define OP_CreateIndex                         31
#define OP_IsUnique                            32
#define OP_IdxIsNull                           33
#define OP_NotFound                            34
#define OP_Int64                               35
#define OP_MustBeInt                           36
#define OP_Halt                                37
#define OP_Rowid                               38
#define OP_IdxLT                               39
#define OP_AddImm                              40
#define OP_Statement                           41
#define OP_RowData                             42
#define OP_MemMax                              43
#define OP_Push                                44
#define OP_Or                                  64   /* same as TK_OR       */
#define OP_NotExists                           45
#define OP_MemIncr                             46
#define OP_Gosub                               47
#define OP_Divide                              86   /* same as TK_SLASH    */
#define OP_AggSet                              48
#define OP_Integer                             49
#define OP_ToNumeric                           50
#define OP_SortNext                            51
#define OP_Prev                                52
#define OP_Concat                              88   /* same as TK_CONCAT   */
#define OP_BitAnd                              79   /* same as TK_BITAND   */
#define OP_CreateTable                         53
#define OP_Last                                54
#define OP_IsNull                              70   /* same as TK_ISNULL   */
#define OP_IdxRowid                            55
#define OP_MakeIdxRec                          56
#define OP_ShiftRight                          82   /* same as TK_RSHIFT   */
#define OP_ResetCount                          57
#define OP_FifoWrite                           58
#define OP_Callback                            59
#define OP_ContextPush                         60
#define OP_DropTrigger                         61
#define OP_DropIndex                           62
#define OP_IdxGE                               63
#define OP_IdxDelete                           67
#define OP_Vacuum                              68
#define OP_MoveLe                              69
#define OP_IfNot                               78
#define OP_DropTable                           90
#define OP_MakeRecord                          93
#define OP_ToBlob                              94
#define OP_Delete                              95
#define OP_AggContextPop                       96

#define OP_ShiftLeft                           81   /* same as TK_LSHIFT   */
#define OP_Dup                                 97
#define OP_Goto                                98
#define OP_FifoRead                            99
#define OP_Clear                              100
#define OP_IdxGT                              101
#define OP_MoveLt                             102
#define OP_Le                                  75   /* same as TK_LE       */
#define OP_VerifyCookie                       103

#define OP_Pull                               104
#define OP_ToText                             105
#define OP_Not                                 66   /* same as TK_NOT      */
#define OP_SetNumColumns                      106
#define OP_AbsValue                           107
#define OP_Transaction                        108
#define OP_Negative                            89   /* same as TK_UMINUS   */
#define OP_Ne                                  72   /* same as TK_NE       */
#define OP_AggGet                             109
#define OP_ContextPop                         110
#define OP_BitOr                               80   /* same as TK_BITOR    */
#define OP_Next                               111
#define OP_AggInit                            112
#define OP_IdxInsert                          113
#define OP_Distinct                           114
#define OP_Lt                                  76   /* same as TK_LT       */
#define OP_AggReset                           115
#define OP_Insert                             116
#define OP_Destroy                            117
#define OP_ReadCookie                         118
#define OP_ForceInt                           119
#define OP_LoadAnalysis                       120
#define OP_OpenVirtual                        121

#define OP_OpenPseudo                         122
#define OP_Null                               123
#define OP_Blob                               124
#define OP_Add                                 83   /* same as TK_PLUS     */
#define OP_MemStore                           125
#define OP_Rewind                             126
#define OP_MoveGe                             127
#define OP_BitNot                              91   /* same as TK_BITNOT   */


#define OP_Found                              128
#define OP_NullRow                            129











#define NOPUSH_MASK_0 65400
#define NOPUSH_MASK_1 29103
#define NOPUSH_MASK_2 64439
#define NOPUSH_MASK_3 65109
#define NOPUSH_MASK_4 65535
#define NOPUSH_MASK_5 52991
#define NOPUSH_MASK_6 55285
#define NOPUSH_MASK_7 59295
#define NOPUSH_MASK_8 3
#define NOPUSH_MASK_9 0



|



|
>
|
|
<

<
|
|
|
|
|
|
|
<
|
|
|
<
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<
|
|
|
<
|
|
|
<
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
>
>
|
|

>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|

1
2
3
4
5
6
7
8
9
10
11

12

13
14
15
16
17
18
19

20
21
22

23
24

25
26
27
28
29
30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

104
105
106

107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Automatically generated.  Do not edit */
/* See the mkopcodeh.awk script for details */
#define OP_MemLoad                              1
#define OP_HexBlob                            134   /* same as TK_BLOB     */
#define OP_Column                               2
#define OP_SetCookie                            3
#define OP_IfMemPos                             4
#define OP_Real                               133   /* same as TK_FLOAT    */
#define OP_Sequence                             5
#define OP_MoveGt                               6
#define OP_Ge                                  80   /* same as TK_GE       */

#define OP_RowKey                               7

#define OP_Eq                                  76   /* same as TK_EQ       */
#define OP_OpenWrite                            8
#define OP_NotNull                             74   /* same as TK_NOTNULL  */
#define OP_If                                   9
#define OP_ToInt                               10
#define OP_String8                             95   /* same as TK_STRING   */
#define OP_Pop                                 11

#define OP_CollSeq                             12
#define OP_OpenRead                            13
#define OP_Expire                              14

#define OP_AutoCommit                          15
#define OP_Gt                                  77   /* same as TK_GT       */

#define OP_IntegrityCk                         16
#define OP_Sort                                17
#define OP_Function                            18
#define OP_And                                 68   /* same as TK_AND      */
#define OP_Subtract                            87   /* same as TK_MINUS    */
#define OP_Noop                                19
#define OP_Return                              20
#define OP_Remainder                           90   /* same as TK_REM      */
#define OP_NewRowid                            21
#define OP_Multiply                            88   /* same as TK_STAR     */
#define OP_Variable                            22
#define OP_String                              23
#define OP_ParseSchema                         24

#define OP_Close                               25
#define OP_CreateIndex                         26
#define OP_IsUnique                            27
#define OP_IdxIsNull                           28
#define OP_NotFound                            29
#define OP_Int64                               30
#define OP_MustBeInt                           31
#define OP_Halt                                32
#define OP_Rowid                               33
#define OP_IdxLT                               34
#define OP_AddImm                              35
#define OP_Statement                           36
#define OP_RowData                             37
#define OP_MemMax                              38
#define OP_Push                                39
#define OP_Or                                  67   /* same as TK_OR       */
#define OP_NotExists                           40
#define OP_MemIncr                             41
#define OP_Gosub                               42
#define OP_Divide                              89   /* same as TK_SLASH    */

#define OP_Integer                             43
#define OP_ToNumeric                           44
#define OP_MemInt                              45
#define OP_Prev                                46
#define OP_Concat                              91   /* same as TK_CONCAT   */
#define OP_BitAnd                              82   /* same as TK_BITAND   */
#define OP_CreateTable                         47
#define OP_Last                                48
#define OP_IsNull                              73   /* same as TK_ISNULL   */
#define OP_IdxRowid                            49
#define OP_MakeIdxRec                          50
#define OP_ShiftRight                          85   /* same as TK_RSHIFT   */
#define OP_ResetCount                          51
#define OP_FifoWrite                           52
#define OP_Callback                            53
#define OP_ContextPush                         54
#define OP_DropTrigger                         55
#define OP_DropIndex                           56
#define OP_IdxGE                               57
#define OP_IdxDelete                           58
#define OP_Vacuum                              59
#define OP_MoveLe                              60
#define OP_IfNot                               61
#define OP_DropTable                           62
#define OP_MakeRecord                          63
#define OP_ToBlob                              64
#define OP_Delete                              65

#define OP_AggFinal                            66
#define OP_ShiftLeft                           84   /* same as TK_LSHIFT   */
#define OP_Dup                                 70
#define OP_Goto                                71
#define OP_FifoRead                            72
#define OP_Clear                               81
#define OP_IdxGT                               93
#define OP_MoveLt                              96
#define OP_Le                                  78   /* same as TK_LE       */
#define OP_VerifyCookie                        97
#define OP_AggStep                             98
#define OP_Pull                                99
#define OP_ToText                             100
#define OP_Not                                 69   /* same as TK_NOT      */
#define OP_SetNumColumns                      101
#define OP_AbsValue                           102
#define OP_Transaction                        103
#define OP_Negative                            92   /* same as TK_UMINUS   */
#define OP_Ne                                  75   /* same as TK_NE       */

#define OP_ContextPop                         104
#define OP_BitOr                               83   /* same as TK_BITOR    */
#define OP_Next                               105

#define OP_IdxInsert                          106
#define OP_Distinct                           107
#define OP_Lt                                  79   /* same as TK_LT       */

#define OP_Insert                             108
#define OP_Destroy                            109
#define OP_ReadCookie                         110
#define OP_ForceInt                           111
#define OP_LoadAnalysis                       112
#define OP_OpenVirtual                        113
#define OP_Explain                            114
#define OP_OpenPseudo                         115
#define OP_Null                               116
#define OP_Blob                               117
#define OP_Add                                 86   /* same as TK_PLUS     */
#define OP_MemStore                           118
#define OP_Rewind                             119
#define OP_MoveGe                             120
#define OP_BitNot                              94   /* same as TK_BITNOT   */
#define OP_MemMove                            121
#define OP_MemNull                            122
#define OP_Found                              123
#define OP_NullRow                            124

/* The following opcode values are never used */
#define OP_NotUsed_125                        125
#define OP_NotUsed_126                        126
#define OP_NotUsed_127                        127
#define OP_NotUsed_128                        128
#define OP_NotUsed_129                        129
#define OP_NotUsed_130                        130
#define OP_NotUsed_131                        131
#define OP_NotUsed_132                        132

#define NOPUSH_MASK_0 65368
#define NOPUSH_MASK_1 47898
#define NOPUSH_MASK_2 22493
#define NOPUSH_MASK_3 32761
#define NOPUSH_MASK_4 65215
#define NOPUSH_MASK_5 30719
#define NOPUSH_MASK_6 40895
#define NOPUSH_MASK_7 6603
#define NOPUSH_MASK_8 0
#define NOPUSH_MASK_9 0

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

157
158
159
160
161
162
163

164


165


166
167
168
169
170
171
172
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
** Changing the value of PENDING_BYTE results in a subtly incompatible
** file format.  Depending on how it is changed, you might not notice
** the incompatibility right away, even running a full regression test.
** The default location of PENDING_BYTE is the first byte past the
** 1GB boundary.
**
*/

#define PENDING_BYTE      0x40000000  /* First byte past the 1GB boundary */


/* #define PENDING_BYTE     0x5400   // Page 22 - for testing */


#define RESERVED_BYTE     (PENDING_BYTE+1)
#define SHARED_FIRST      (PENDING_BYTE+2)
#define SHARED_SIZE       510


int sqlite3OsDelete(const char*);
int sqlite3OsFileExists(const char*);
................................................................................
int sqlite3OsSyncDirectory(const char*);
int sqlite3OsTempFileName(char*);
int sqlite3OsIsDirWritable(char*);
int sqlite3OsClose(OsFile*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);
int sqlite3OsSeek(OsFile*, i64 offset);
int sqlite3OsSync(OsFile*);
int sqlite3OsTruncate(OsFile*, i64 size);
int sqlite3OsFileSize(OsFile*, i64 *pSize);
char *sqlite3OsFullPathname(const char*);
int sqlite3OsLock(OsFile*, int);
int sqlite3OsUnlock(OsFile*, int);
int sqlite3OsCheckReservedLock(OsFile *id);








>

>
>
|
>
>







 







|







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
** Changing the value of PENDING_BYTE results in a subtly incompatible
** file format.  Depending on how it is changed, you might not notice
** the incompatibility right away, even running a full regression test.
** The default location of PENDING_BYTE is the first byte past the
** 1GB boundary.
**
*/
#ifndef SQLITE_TEST
#define PENDING_BYTE      0x40000000  /* First byte past the 1GB boundary */
#else
extern unsigned int sqlite3_pending_byte;
#define PENDING_BYTE sqlite3_pending_byte
#endif

#define RESERVED_BYTE     (PENDING_BYTE+1)
#define SHARED_FIRST      (PENDING_BYTE+2)
#define SHARED_SIZE       510


int sqlite3OsDelete(const char*);
int sqlite3OsFileExists(const char*);
................................................................................
int sqlite3OsSyncDirectory(const char*);
int sqlite3OsTempFileName(char*);
int sqlite3OsIsDirWritable(char*);
int sqlite3OsClose(OsFile*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);
int sqlite3OsSeek(OsFile*, i64 offset);
int sqlite3OsSync(OsFile*, int);
int sqlite3OsTruncate(OsFile*, i64 size);
int sqlite3OsFileSize(OsFile*, i64 *pSize);
char *sqlite3OsFullPathname(const char*);
int sqlite3OsLock(OsFile*, int);
int sqlite3OsUnlock(OsFile*, int);
int sqlite3OsCheckReservedLock(OsFile *id);

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

24
25
26
27
28
29
30








31
32
33
34
35
36
37
..
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93







94
95
96
97
98
99
100
** switch.  The following code should catch this problem at compile-time.
*/
#ifdef MEMORY_DEBUG
# error "The MEMORY_DEBUG macro is obsolete.  Use SQLITE_DEBUG instead."
#endif










#ifdef SQLITE_DEBUG
int sqlite3_os_trace = 0;
static int last_page = 0;
#define SEEK(X)           last_page=(X)
#define TRACE1(X)         if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
#define TRACE2(X,Y)       if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
#define TRACE3(X,Y,Z)     if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
................................................................................
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error.  This
** is used for testing the I/O recovery logic.
*/
#ifdef SQLITE_TEST
int sqlite3_io_error_pending = 0;
int sqlite3_diskfull_pending = 0;

#define SimulateIOError(A)  \
   if( sqlite3_io_error_pending ) \
     if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
static void local_ioerr(){
  sqlite3_io_error_pending = 0;  /* Really just a place to set a breakpoint */
}
#define SimulateDiskfullError \
   if( sqlite3_diskfull_pending ) \
     if( sqlite3_diskfull_pending-- == 1 ){ local_ioerr(); return SQLITE_FULL; }







#else
#define SimulateIOError(A)
#define SimulateDiskfullError
#endif

/*
** When testing, keep a count of the number of open files.







>
>
>
>
>
>
>
>







 







>







|
|
>
>
>
>
>
>
>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
** switch.  The following code should catch this problem at compile-time.
*/
#ifdef MEMORY_DEBUG
# error "The MEMORY_DEBUG macro is obsolete.  Use SQLITE_DEBUG instead."
#endif


/*
 * When testing, this global variable stores the location of the
 * pending-byte in the database file.
 */
#ifdef SQLITE_TEST
unsigned int sqlite3_pending_byte = 0x40000000;
#endif

#ifdef SQLITE_DEBUG
int sqlite3_os_trace = 0;
static int last_page = 0;
#define SEEK(X)           last_page=(X)
#define TRACE1(X)         if( sqlite3_os_trace ) sqlite3DebugPrintf(X)
#define TRACE2(X,Y)       if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y)
#define TRACE3(X,Y,Z)     if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z)
................................................................................
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error.  This
** is used for testing the I/O recovery logic.
*/
#ifdef SQLITE_TEST
int sqlite3_io_error_pending = 0;
int sqlite3_diskfull_pending = 0;
int sqlite3_diskfull = 0;
#define SimulateIOError(A)  \
   if( sqlite3_io_error_pending ) \
     if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
static void local_ioerr(){
  sqlite3_io_error_pending = 0;  /* Really just a place to set a breakpoint */
}
#define SimulateDiskfullError \
   if( sqlite3_diskfull_pending ){ \
     if( sqlite3_diskfull_pending == 1 ){ \
       local_ioerr(); \
       sqlite3_diskfull = 1; \
       return SQLITE_FULL; \
     }else{ \
       sqlite3_diskfull_pending--; \
     } \
   }
#else
#define SimulateIOError(A)
#define SimulateDiskfullError
#endif

/*
** When testing, keep a count of the number of open files.

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

14
15
16
17
18
19
20

21
22
23
24
25
26
27
...
767
768
769
770
771
772
773



774
775
776
777
778
779
780
...
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
...
820
821
822
823
824
825
826




827


828

829
830
831
832
833
834
835
836




837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
....
1306
1307
1308
1309
1310
1311
1312
1313



1314
1315
1316

1317
1318
1319
1320
1321
1322
1323
....
1416
1417
1418
1419
1420
1421
1422

1423
1424
1425






1426
1427
1428
1429
1430
1431
1432
1433
1434
*/
#include "sqliteInt.h"
#include "os.h"
#if OS_UNIX              /* This file is used on unix only */


#include <time.h>

#include <errno.h>
#include <unistd.h>

/*
** Do not include any of the File I/O interface procedures if the
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
** will be in-memory only)
................................................................................

/*
** Move the read/write pointer in a file.
*/
int sqlite3OsSeek(OsFile *id, i64 offset){
  assert( id->isOpen );
  SEEK(offset/1024 + 1);



  lseek(id->h, offset, SEEK_SET);
  return SQLITE_OK;
}

#ifdef SQLITE_TEST
/*
** Count the number of fullsyncs and normal syncs.  This is used to test
................................................................................
**
** The SQLITE_NO_SYNC macro disables all fsync()s.  This is useful
** for testing when we want to run through the test suite quickly.
** You are strongly advised *not* to deploy with SQLITE_NO_SYNC
** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
** or power failure will likely corrupt the database file.
*/
static int full_fsync(int fd, int fullSync){
  int rc;

  /* Record the number of times that we do a normal fsync() and 
  ** FULLSYNC.  This is used during testing to verify that this procedure
  ** gets called with the correct arguments.
  */
#ifdef SQLITE_TEST
................................................................................
    rc = fcntl(fd, F_FULLFSYNC, 0);
  }else{
    rc = 1;
  }
  /* If the FULLSYNC failed, try to do a normal fsync() */
  if( rc ) rc = fsync(fd);





#else


  rc = fsync(fd);

#endif /* defined(F_FULLFSYNC) */
#endif /* defined(SQLITE_NO_SYNC) */

  return rc;
}

/*
** Make sure all writes to a particular file are committed to disk.




**
** Under Unix, also make sure that the directory entry for the file
** has been created by fsync-ing the directory that contains the file.
** If we do not do this and we encounter a power failure, the directory
** entry for the journal might not exist after we reboot.  The next
** SQLite to access the file will not know that the journal exists (because
** the directory entry for the journal was never created) and the transaction
** will not roll back - possibly leading to database corruption.
*/
int sqlite3OsSync(OsFile *id){
  assert( id->isOpen );
  SimulateIOError(SQLITE_IOERR);
  TRACE2("SYNC    %-3d\n", id->h);
  if( full_fsync(id->h, id->fullSync) ){
    return SQLITE_IOERR;
  }
  if( id->dirfd>=0 ){
    TRACE2("DIRSYNC %-3d\n", id->dirfd);
    full_fsync(id->dirfd, id->fullSync);
    close(id->dirfd);  /* Only need to sync once, so close the directory */
    id->dirfd = -1;    /* when we are done. */
  }
  return SQLITE_OK;
}

/*
................................................................................
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
  char *zFull = 0;
  if( zRelative[0]=='/' ){
    sqlite3SetString(&zFull, zRelative, (char*)0);
  }else{
    char zBuf[5000];



    zBuf[0] = 0;
    sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative,
                    (char*)0);

  }
  return zFull;
}


#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
................................................................................

/*
** Find the current time (in Universal Coordinated Time).  Write the
** current time and date as a Julian Day number into *prNow and
** return 0.  Return 1 if the time and date cannot be found.
*/
int sqlite3OsCurrentTime(double *prNow){

  time_t t;
  time(&t);
  *prNow = t/86400.0 + 2440587.5;






#ifdef SQLITE_TEST
  if( sqlite3_current_time ){
    *prNow = sqlite3_current_time/86400.0 + 2440587.5;
  }
#endif
  return 0;
}

#endif /* OS_UNIX */







>







 







>
>
>







 







|







 







>
>
>
>
|
>
>
|
>








>
>
>
>









|



|




|







 







|
>
>
>

|

>







 







>



>
>
>
>
>
>









14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
...
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
...
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
....
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
....
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
*/
#include "sqliteInt.h"
#include "os.h"
#if OS_UNIX              /* This file is used on unix only */


#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <unistd.h>

/*
** Do not include any of the File I/O interface procedures if the
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
** will be in-memory only)
................................................................................

/*
** Move the read/write pointer in a file.
*/
int sqlite3OsSeek(OsFile *id, i64 offset){
  assert( id->isOpen );
  SEEK(offset/1024 + 1);
#ifdef SQLITE_TEST
  if( offset ) SimulateDiskfullError
#endif
  lseek(id->h, offset, SEEK_SET);
  return SQLITE_OK;
}

#ifdef SQLITE_TEST
/*
** Count the number of fullsyncs and normal syncs.  This is used to test
................................................................................
**
** The SQLITE_NO_SYNC macro disables all fsync()s.  This is useful
** for testing when we want to run through the test suite quickly.
** You are strongly advised *not* to deploy with SQLITE_NO_SYNC
** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
** or power failure will likely corrupt the database file.
*/
static int full_fsync(int fd, int fullSync, int dataOnly){
  int rc;

  /* Record the number of times that we do a normal fsync() and 
  ** FULLSYNC.  This is used during testing to verify that this procedure
  ** gets called with the correct arguments.
  */
#ifdef SQLITE_TEST
................................................................................
    rc = fcntl(fd, F_FULLFSYNC, 0);
  }else{
    rc = 1;
  }
  /* If the FULLSYNC failed, try to do a normal fsync() */
  if( rc ) rc = fsync(fd);

#else /* if !defined(F_FULLSYNC) */
#if  defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO>0
  if( dataOnly ){
    rc = fdatasync(fd);
  }else
#endif /* _POSIX_SYNCHRONIZED_IO > 0 */
  {
    rc = fsync(fd);
  }
#endif /* defined(F_FULLFSYNC) */
#endif /* defined(SQLITE_NO_SYNC) */

  return rc;
}

/*
** Make sure all writes to a particular file are committed to disk.
**
** If dataOnly==0 then both the file itself and its metadata (file
** size, access time, etc) are synced.  If dataOnly!=0 then only the
** file data is synced.
**
** Under Unix, also make sure that the directory entry for the file
** has been created by fsync-ing the directory that contains the file.
** If we do not do this and we encounter a power failure, the directory
** entry for the journal might not exist after we reboot.  The next
** SQLite to access the file will not know that the journal exists (because
** the directory entry for the journal was never created) and the transaction
** will not roll back - possibly leading to database corruption.
*/
int sqlite3OsSync(OsFile *id, int dataOnly){
  assert( id->isOpen );
  SimulateIOError(SQLITE_IOERR);
  TRACE2("SYNC    %-3d\n", id->h);
  if( full_fsync(id->h, id->fullSync, dataOnly) ){
    return SQLITE_IOERR;
  }
  if( id->dirfd>=0 ){
    TRACE2("DIRSYNC %-3d\n", id->dirfd);
    full_fsync(id->dirfd, id->fullSync, 0);
    close(id->dirfd);  /* Only need to sync once, so close the directory */
    id->dirfd = -1;    /* when we are done. */
  }
  return SQLITE_OK;
}

/*
................................................................................
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
  char *zFull = 0;
  if( zRelative[0]=='/' ){
    sqlite3SetString(&zFull, zRelative, (char*)0);
  }else{
    char *zBuf = sqliteMalloc(5000);
    if( zBuf==0 ){
      return 0;
    }
    zBuf[0] = 0;
    sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative,
                    (char*)0);
    sqliteFree(zBuf);
  }
  return zFull;
}


#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
................................................................................

/*
** Find the current time (in Universal Coordinated Time).  Write the
** current time and date as a Julian Day number into *prNow and
** return 0.  Return 1 if the time and date cannot be found.
*/
int sqlite3OsCurrentTime(double *prNow){
#ifdef NO_GETTOD
  time_t t;
  time(&t);
  *prNow = t/86400.0 + 2440587.5;
#else
  struct timeval sNow;
  struct timezone sTz;  /* Not used */
  gettimeofday(&sNow, &sTz);
  *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0;
#endif
#ifdef SQLITE_TEST
  if( sqlite3_current_time ){
    *prNow = sqlite3_current_time/86400.0 + 2440587.5;
  }
#endif
  return 0;
}

#endif /* OS_UNIX */

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

36
37
38
39
40
41
42
43
44


















































































45
46
47





48

49
50
51
52
53
54
55
56






57


58
59
60
61
62
63
64
..
73
74
75
76
77
78
79

80

81
82
83
84
85
86
87
88
89
90
91
92


















93
94
95
96
97
98









99
100
101
102
103

104
105
106
107
108
109
110
...
125
126
127
128
129
130
131

132
133
134
135
136
137
138











139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
...
161
162
163
164
165
166
167

168











169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
227
228
229
230
231
232
233










234
235
236
237
238
239
240
...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
...
303
304
305
306
307
308
309







310
311
312
313
314
315
316
317



318
319
320



321
322
323
324
325
326
327
328
329
330
331
332
333
334
...
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
...
427
428
429
430
431
432
433
434
435

436
437





438

439
440
441
442
443
444
445
...
632
633
634
635
636
637
638

639
640
641
642
643
644
645
646
647
648
649

650
651
652
653
654
655
656











657
658
659
660

661
662
663
664
665
666
667

/*
** Do not include any of the File I/O interface procedures if the
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
** will be in-memory only)
*/
#ifndef SQLITE_OMIT_DISKIO

/*


















































































** Delete the named file
*/
int sqlite3OsDelete(const char *zFilename){





  DeleteFileA(zFilename);

  TRACE2("DELETE \"%s\"\n", zFilename);
  return SQLITE_OK;
}

/*
** Return TRUE if the named file exists.
*/
int sqlite3OsFileExists(const char *zFilename){






  return GetFileAttributesA(zFilename) != 0xffffffff;


}

#ifndef _WIN32_WCE
/*
** Attempt to open a file for both reading and writing.  If that
** fails, try opening it read-only.  If the file does not exist,
** try to create it.
................................................................................
*/
int sqlite3OsOpenReadWrite(
  const char *zFilename,
  OsFile *id,
  int *pReadonly
){
  HANDLE h;

  assert( !id->isOpen );

  h = CreateFileA(zFilename,
     GENERIC_READ | GENERIC_WRITE,
     FILE_SHARE_READ | FILE_SHARE_WRITE,
     NULL,
     OPEN_ALWAYS,
     FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
     NULL
  );
  if( h==INVALID_HANDLE_VALUE ){
    h = CreateFileA(zFilename,
       GENERIC_READ,
       FILE_SHARE_READ,


















       NULL,
       OPEN_ALWAYS,
       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
       NULL
    );
    if( h==INVALID_HANDLE_VALUE ){









      return SQLITE_CANTOPEN;
    }
    *pReadonly = 1;
  }else{
    *pReadonly = 0;

  }
  id->h = h;
  id->locktype = NO_LOCK;
  id->sharedLockByte = 0;
  id->isOpen = 1;
  OpenCounter(+1);
  TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename);
................................................................................
** On success, write the file handle into *id and return SQLITE_OK.
**
** On failure, return SQLITE_CANTOPEN.
*/
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
  HANDLE h;
  int fileflags;

  assert( !id->isOpen );
  if( delFlag ){
    fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS 
                     | FILE_FLAG_DELETE_ON_CLOSE;
  }else{
    fileflags = FILE_FLAG_RANDOM_ACCESS;
  }











  h = CreateFileA(zFilename,
     GENERIC_READ | GENERIC_WRITE,
     0,
     NULL,
     CREATE_ALWAYS,
     fileflags,
     NULL
  );

  if( h==INVALID_HANDLE_VALUE ){
    return SQLITE_CANTOPEN;
  }
  id->h = h;
  id->locktype = NO_LOCK;
  id->sharedLockByte = 0;
  id->isOpen = 1;
................................................................................
**
** On success, write the file handle into *id and return SQLITE_OK.
**
** On failure, return SQLITE_CANTOPEN.
*/
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
  HANDLE h;

  assert( !id->isOpen );











  h = CreateFileA(zFilename,
     GENERIC_READ,
     0,
     NULL,
     OPEN_EXISTING,
     FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
     NULL
  );

  if( h==INVALID_HANDLE_VALUE ){
    return SQLITE_CANTOPEN;
  }
  id->h = h;
  id->locktype = NO_LOCK;
  id->sharedLockByte = 0;
  id->isOpen = 1;
  OpenCounter(+1);
  TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
  return SQLITE_OK;
}
#endif /* !defined(_WIN32_WCE) */

/*
** Attempt to open a file descriptor for the directory that contains a
** file.  This file descriptor can be used to fsync() the directory
** in order to make sure the creation of a new file is actually written
** to disk.
**
................................................................................
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  char zTempPath[SQLITE_TEMPNAME_SIZE];
  if( sqlite3_temp_directory ){
    strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
    zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;










  }else{
    GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
  }
  for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
  zTempPath[i] = 0;
  for(;;){
    sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
................................................................................
    TRACE2("CLOSE %d\n", id->h);
    CloseHandle(id->h);
    OpenCounter(-1);
    id->isOpen = 0;
  }
  return SQLITE_OK;
}
#endif

/*
** Read data from a file into a buffer.  Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
................................................................................
  }
  if( !rc || amt>(int)wrote ){
    return SQLITE_FULL;
  }
  return SQLITE_OK;
}








/*
** Move the read/write pointer in a file.
*/
int sqlite3OsSeek(OsFile *id, i64 offset){
  LONG upperBits = offset>>32;
  LONG lowerBits = offset & 0xffffffff;
  DWORD rc;
  assert( id->isOpen );



  SEEK(offset/1024 + 1);
  rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN);
  TRACE3("SEEK %d %lld\n", id->h, offset);



  return SQLITE_OK;
}

/*
** Make sure all writes to a particular file are committed to disk.
*/
int sqlite3OsSync(OsFile *id){
  assert( id->isOpen );
  TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
  if( FlushFileBuffers(id->h) ){
    return SQLITE_OK;
  }else{
    return SQLITE_IOERR;
  }
................................................................................
  SimulateIOError(SQLITE_IOERR);
  lowerBits = GetFileSize(id->h, &upperBits);
  *pSize = (((i64)upperBits)<<32) + lowerBits;
  return SQLITE_OK;
}

#ifndef _WIN32_WCE
/*
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
** Return false (zero) for Win95, Win98, or WinME.
**
** Here is an interesting observation:  Win95, Win98, and WinME lack
** the LockFileEx() API.  But we can still statically link against that
** API as long as we don't call it win running Win95/98/ME.  A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
*/
static int isNT(void){
  static int osType = 0;   /* 0=unknown 1=win95 2=winNT */
  if( osType==0 ){
    OSVERSIONINFO sInfo;
    sInfo.dwOSVersionInfoSize = sizeof(sInfo);
    GetVersionEx(&sInfo);
    osType = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
  }
  return osType==2;
}

/*
** Acquire a reader lock.
** Different API routines are called depending on whether or not this
** is Win95 or WinNT.
*/
static int getReadLock(OsFile *id){
  int res;
................................................................................
}

#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/*
** Check that a given pathname is a directory and is writable 
**
*/
int sqlite3OsIsDirWritable(char *zBuf){
  int fileAttr;

  if(! zBuf ) return 0;
  if(! isNT() && strlen(zBuf) > MAX_PATH ) return 0;





  fileAttr = GetFileAttributesA(zBuf);

  if( fileAttr == 0xffffffff ) return 0;
  if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
    return 0;
  }
  return 1;
}
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
................................................................................
  }
  if( type>=PENDING_LOCK ){
    UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
  }
  id->locktype = locktype;
  return rc;
}

#endif /* !defined(_WIN32_WCE) */

/*
** Turn a relative pathname into a full pathname.  Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
  char *zNotUsed;
  char *zFull;

  int nByte;
#ifdef __CYGWIN__
  nByte = strlen(zRelative) + MAX_PATH + 1001;
  zFull = sqliteMalloc( nByte );
  if( zFull==0 ) return 0;
  if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
#else











  nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
  zFull = (char *)sqliteMalloc( nByte );
  if( zFull==0 ) return 0;
  GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);

#endif
  return zFull;
}

#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O.  Everything that follows deals









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
|
>








>
>
>
>
>
>
|
>
>







 







>

>
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
>
>
|
|
|
|
|
>







 







>







>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
>







 







>

>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
>











|







 







>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>








>
>
>



>
>
>






|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|

>
|
|
>
>
>
>
>
|
>







 







>
|










>







>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
>







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
...
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
...
540
541
542
543
544
545
546






















547
548
549
550
551
552
553
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
...
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841

/*
** Do not include any of the File I/O interface procedures if the
** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
** will be in-memory only)
*/
#ifndef SQLITE_OMIT_DISKIO

/*
** The following variable is (normally) set once and never changes
** thereafter.  It records whether the operating system is Win95
** or WinNT.
**
** 0:   Operating system unknown.
** 1:   Operating system is Win95.
** 2:   Operating system is WinNT.
**
** In order to facilitate testing on a WinNT system, the test fixture
** can manually set this value to 1 to emulate Win98 behavior.
*/
int sqlite3_os_type = 0;

/*
** Return true (non-zero) if we are running under WinNT, Win2K or WinXP.
** Return false (zero) for Win95, Win98, or WinME.
**
** Here is an interesting observation:  Win95, Win98, and WinME lack
** the LockFileEx() API.  But we can still statically link against that
** API as long as we don't call it win running Win95/98/ME.  A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
*/
static int isNT(void){
  if( sqlite3_os_type==0 ){
    OSVERSIONINFO sInfo;
    sInfo.dwOSVersionInfoSize = sizeof(sInfo);
    GetVersionEx(&sInfo);
    sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
  }
  return sqlite3_os_type==2;
}

/*
** Convert a UTF-8 string to UTF-32.  Space to hold the returned string
** is obtained from sqliteMalloc.
*/
static WCHAR *utf8ToUnicode(const char *zFilename){
  int nByte;
  WCHAR *zWideFilename;

  if( !isNT() ){
    return 0;
  }
  nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0)*sizeof(WCHAR);
  zWideFilename = sqliteMalloc( nByte*sizeof(zWideFilename[0]) );
  if( zWideFilename==0 ){
    return 0;
  }
  nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nByte);
  if( nByte==0 ){
    sqliteFree(zWideFilename);
    zWideFilename = 0;
  }
  return zWideFilename;
}

/*
** Convert UTF-32 to UTF-8.  Space to hold the returned string is
** obtained from sqliteMalloc().
*/
static char *unicodeToUtf8(const WCHAR *zWideFilename){
  int nByte;
  char *zFilename;

  nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
  zFilename = sqliteMalloc( nByte );
  if( zFilename==0 ){
    return 0;
  }
  nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
                              0, 0);
  if( nByte == 0 ){
    sqliteFree(zFilename);
    zFilename = 0;
  }
  return zFilename;
}


/*
** Delete the named file
*/
int sqlite3OsDelete(const char *zFilename){
  WCHAR *zWide = utf8ToUnicode(zFilename);
  if( zWide ){
    DeleteFileW(zWide);
    sqliteFree(zWide);
  }else{
    DeleteFileA(zFilename);
  }
  TRACE2("DELETE \"%s\"\n", zFilename);
  return SQLITE_OK;
}

/*
** Return TRUE if the named file exists.
*/
int sqlite3OsFileExists(const char *zFilename){
  int exists = 0;
  WCHAR *zWide = utf8ToUnicode(zFilename);
  if( zWide ){
    exists = GetFileAttributesW(zWide) != 0xffffffff;
    sqliteFree(zWide);
  }else{
    exists = GetFileAttributesA(zFilename) != 0xffffffff;
  }
  return exists;
}

#ifndef _WIN32_WCE
/*
** Attempt to open a file for both reading and writing.  If that
** fails, try opening it read-only.  If the file does not exist,
** try to create it.
................................................................................
*/
int sqlite3OsOpenReadWrite(
  const char *zFilename,
  OsFile *id,
  int *pReadonly
){
  HANDLE h;
  WCHAR *zWide = utf8ToUnicode(zFilename);
  assert( !id->isOpen );
  if( zWide ){
    h = CreateFileW(zWide,
       GENERIC_READ | GENERIC_WRITE,
       FILE_SHARE_READ | FILE_SHARE_WRITE,
       NULL,
       OPEN_ALWAYS,
       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
       NULL
    );
    if( h==INVALID_HANDLE_VALUE ){
      h = CreateFileW(zWide,
         GENERIC_READ,
         FILE_SHARE_READ,
         NULL,
         OPEN_ALWAYS,
         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
         NULL
      );
      if( h==INVALID_HANDLE_VALUE ){
        sqliteFree(zWide);
        return SQLITE_CANTOPEN;
      }
      *pReadonly = 1;
    }else{
      *pReadonly = 0;
    }
    sqliteFree(zWide);
  }else{
    h = CreateFileA(zFilename,
       GENERIC_READ | GENERIC_WRITE,
       FILE_SHARE_READ | FILE_SHARE_WRITE,
       NULL,
       OPEN_ALWAYS,
       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
       NULL
    );
    if( h==INVALID_HANDLE_VALUE ){
      h = CreateFileA(zFilename,
         GENERIC_READ,
         FILE_SHARE_READ,
         NULL,
         OPEN_ALWAYS,
         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
         NULL
      );
      if( h==INVALID_HANDLE_VALUE ){
        return SQLITE_CANTOPEN;
      }
      *pReadonly = 1;
    }else{
      *pReadonly = 0;
    }
  }
  id->h = h;
  id->locktype = NO_LOCK;
  id->sharedLockByte = 0;
  id->isOpen = 1;
  OpenCounter(+1);
  TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename);
................................................................................
** On success, write the file handle into *id and return SQLITE_OK.
**
** On failure, return SQLITE_CANTOPEN.
*/
int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
  HANDLE h;
  int fileflags;
  WCHAR *zWide = utf8ToUnicode(zFilename);
  assert( !id->isOpen );
  if( delFlag ){
    fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS 
                     | FILE_FLAG_DELETE_ON_CLOSE;
  }else{
    fileflags = FILE_FLAG_RANDOM_ACCESS;
  }
  if( zWide ){
    h = CreateFileW(zWide,
       GENERIC_READ | GENERIC_WRITE,
       0,
       NULL,
       CREATE_ALWAYS,
       fileflags,
       NULL
    );
    sqliteFree(zWide);
  }else{
    h = CreateFileA(zFilename,
       GENERIC_READ | GENERIC_WRITE,
       0,
       NULL,
       CREATE_ALWAYS,
       fileflags,
       NULL
    );
  }
  if( h==INVALID_HANDLE_VALUE ){
    return SQLITE_CANTOPEN;
  }
  id->h = h;
  id->locktype = NO_LOCK;
  id->sharedLockByte = 0;
  id->isOpen = 1;
................................................................................
**
** On success, write the file handle into *id and return SQLITE_OK.
**
** On failure, return SQLITE_CANTOPEN.
*/
int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
  HANDLE h;
  WCHAR *zWide = utf8ToUnicode(zFilename);
  assert( !id->isOpen );
  if( zWide ){
    h = CreateFileW(zWide,
       GENERIC_READ,
       0,
       NULL,
       OPEN_EXISTING,
       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
       NULL
    );
    sqliteFree(zWide);
  }else{
    h = CreateFileA(zFilename,
       GENERIC_READ,
       0,
       NULL,
       OPEN_EXISTING,
       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
       NULL
    );
  }
  if( h==INVALID_HANDLE_VALUE ){
    return SQLITE_CANTOPEN;
  }
  id->h = h;
  id->locktype = NO_LOCK;
  id->sharedLockByte = 0;
  id->isOpen = 1;
  OpenCounter(+1);
  TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
  return SQLITE_OK;
}
#endif // _WIN32_WCE

/*
** Attempt to open a file descriptor for the directory that contains a
** file.  This file descriptor can be used to fsync() the directory
** in order to make sure the creation of a new file is actually written
** to disk.
**
................................................................................
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  char zTempPath[SQLITE_TEMPNAME_SIZE];
  if( sqlite3_temp_directory ){
    strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
    zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
  }else if( isNT() ){
    char *zMulti;
    WCHAR zWidePath[SQLITE_TEMPNAME_SIZE];
    GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath);
    zMulti = unicodeToUtf8(zWidePath);
    if( zMulti ){
      strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30);
      zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
      sqliteFree(zMulti);
    }
  }else{
    GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
  }
  for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
  zTempPath[i] = 0;
  for(;;){
    sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
................................................................................
    TRACE2("CLOSE %d\n", id->h);
    CloseHandle(id->h);
    OpenCounter(-1);
    id->isOpen = 0;
  }
  return SQLITE_OK;
}
#endif // _WIN32_WCE

/*
** Read data from a file into a buffer.  Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
*/
int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
................................................................................
  }
  if( !rc || amt>(int)wrote ){
    return SQLITE_FULL;
  }
  return SQLITE_OK;
}

/*
** Some microsoft compilers lack this definition.
*/
#ifndef INVALID_SET_FILE_POINTER
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
#endif

/*
** Move the read/write pointer in a file.
*/
int sqlite3OsSeek(OsFile *id, i64 offset){
  LONG upperBits = offset>>32;
  LONG lowerBits = offset & 0xffffffff;
  DWORD rc;
  assert( id->isOpen );
#ifdef SQLITE_TEST
  if( offset ) SimulateDiskfullError
#endif
  SEEK(offset/1024 + 1);
  rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN);
  TRACE3("SEEK %d %lld\n", id->h, offset);
  if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){
    return SQLITE_FULL;
  }
  return SQLITE_OK;
}

/*
** Make sure all writes to a particular file are committed to disk.
*/
int sqlite3OsSync(OsFile *id, int dataOnly){
  assert( id->isOpen );
  TRACE3("SYNC %d lock=%d\n", id->h, id->locktype);
  if( FlushFileBuffers(id->h) ){
    return SQLITE_OK;
  }else{
    return SQLITE_IOERR;
  }
................................................................................
  SimulateIOError(SQLITE_IOERR);
  lowerBits = GetFileSize(id->h, &upperBits);
  *pSize = (((i64)upperBits)<<32) + lowerBits;
  return SQLITE_OK;
}

#ifndef _WIN32_WCE






















/*
** Acquire a reader lock.
** Different API routines are called depending on whether or not this
** is Win95 or WinNT.
*/
static int getReadLock(OsFile *id){
  int res;
................................................................................
}

#ifndef SQLITE_OMIT_PAGER_PRAGMAS
/*
** Check that a given pathname is a directory and is writable 
**
*/
int sqlite3OsIsDirWritable(char *zDirname){
  int fileAttr;
  WCHAR *zWide;
  if( zDirname==0 ) return 0;
  if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0;
  zWide = utf8ToUnicode(zDirname);
  if( zWide ){
    fileAttr = GetFileAttributesW(zWide);
    sqliteFree(zWide);
  }else{
    fileAttr = GetFileAttributesA(zDirname);
  }
  if( fileAttr == 0xffffffff ) return 0;
  if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){
    return 0;
  }
  return 1;
}
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
................................................................................
  }
  if( type>=PENDING_LOCK ){
    UnlockFile(id->h, PENDING_BYTE, 0, 1, 0);
  }
  id->locktype = locktype;
  return rc;
}

#endif // _WIN32_WCE

/*
** Turn a relative pathname into a full pathname.  Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqlite3OsFullPathname(const char *zRelative){
  char *zNotUsed;
  char *zFull;
  WCHAR *zWide;
  int nByte;
#ifdef __CYGWIN__
  nByte = strlen(zRelative) + MAX_PATH + 1001;
  zFull = sqliteMalloc( nByte );
  if( zFull==0 ) return 0;
  if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
#else
  zWide = utf8ToUnicode(zRelative);
  if( zWide ){
    WCHAR *zTemp, *zNotUsedW;
    nByte = GetFullPathNameW(zWide, 0, 0, &zNotUsedW) + 1;
    zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) );
    if( zTemp==0 ) return 0;
    GetFullPathNameW(zWide, nByte, zTemp, &zNotUsedW);
    sqliteFree(zWide);
    zFull = unicodeToUtf8(zTemp);
    sqliteFree(zTemp);
  }else{
    nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
    zFull = sqliteMalloc( nByte*sizeof(zFull[0]) );
    if( zFull==0 ) return 0;
    GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
  }
#endif
  return zFull;
}

#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O.  Everything that follows deals

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

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
73
74
75
76
77
78
79
80
81
82
#endif //_WIN32_WCE
};


#define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
#define SQLITE_MIN_SLEEP_MS 1


/*
** This are WIN32 API functions not present in WinCE.
** They are implemented in the "os_wince.c" file.
**/
#ifdef _WIN32_WCE
# define DeleteFileA				sqlitewce_DeleteFileA
# define GetFileAttributesA			sqlitewce_GetFileAttributesA
................................................................................
** To avoid any problems I just use my own implementation.
** It should be safe, as this header is not included by normal
** programs, only by the SQLite library.
**/
#if _WIN32_WCE >= 400
# define localtime					sqlitewce_localtime
#endif


#endif /* _SQLITE_OS_WIN_H_ */







<







 







<
<

45
46
47
48
49
50
51

52
53
54
55
56
57
58
..
72
73
74
75
76
77
78


79
#endif //_WIN32_WCE
};


#define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
#define SQLITE_MIN_SLEEP_MS 1


/*
** This are WIN32 API functions not present in WinCE.
** They are implemented in the "os_wince.c" file.
**/
#ifdef _WIN32_WCE
# define DeleteFileA				sqlitewce_DeleteFileA
# define GetFileAttributesA			sqlitewce_GetFileAttributesA
................................................................................
** To avoid any problems I just use my own implementation.
** It should be safe, as this header is not included by normal
** programs, only by the SQLite library.
**/
#if _WIN32_WCE >= 400
# define localtime					sqlitewce_localtime
#endif


#endif /* _SQLITE_OS_WIN_H_ */

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

102
103
104
105
106
107
108






109
110
111
112
113
114
115
...
216
217
218
219
220
221
222


223
224
225
226
227
228
229
...
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257


258

259
260
261
262
263
264
265
...
278
279
280
281
282
283
284


285
286
287
288
289
290
291
292
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
** This is needed for the command line version of sqlite to compile.
**/
int isatty( int handle )
{
	UNREFERENCED_PARAMETER(handle);
	return 1;
}







/*
** Converts a relative path to an absolute path.
** There is no current directory concept on Windows CE, so we assume
** we are working always with absolute paths and simply copy
** the given path to the provided buffer.
*/
................................................................................
** NOTE: I'm not sure in what conditions this can turn into an infinite
**       loop. I don't think it is possible without a serious bug in
**       sqlite or windows, but i'm not sure of this.
*/
static void lock_file( OsFile *id )
{
	DWORD res;


	while ( 1 )
	{
		res = WaitForSingleObject( id->hMux, INFINITE );
		// I don't know very well what I have to do in this case.
		// The MSDN says that this case is when a thread terminates without
		// releasing the mutex. So I have to release it and try again
		if ( res == WAIT_ABANDONED )
................................................................................

/*
** Releases ownership of the file mutex.
** Always success
*/
static void unlock_file( OsFile *id )
{

	ReleaseMutex( id->hMux );
}

/*
** Acquire a lock on the file.
** Returns non-zero on success, zero on failure.
*/
static int getLock( OsFile *id, int locktype )
{
	int rc = 0;


	lock_file( id );

	if ( locktype == SHARED_LOCK )
	{
		assert( id->lockdata->shared >= 0 );
		++id->lockdata->shared;	/* Increment number of readers */
		id->lockdata->lock |= 1 << SHARED_LOCK;
	}
	else
................................................................................
/*
** Releases lock on the file.
** Always succeeds, so no return value.
*/
static void unsetLock( OsFile *id, int locktype )
{
	assert( locktype >= SHARED_LOCK );


	lock_file( id );
	if ( locktype == SHARED_LOCK )
	{
		assert( id->lockdata->shared > 0 );
		--id->lockdata->shared;	/* Decrement number of readers */
		if ( id->lockdata->shared == 0 )	/* Last reader? */
			id->lockdata->lock &= ~(1 << SHARED_LOCK);
	}
................................................................................
	id->h = h;
	id->locktype = NO_LOCK;
	id->sharedLockByte = 0;
	id->isOpen = 1;
	id->wFilename = wFilename;
	id->delOnClose = delFlag;
#ifndef SQLITE_WCE_OMIT_FILELOCK
	// Not shared, so no need to lock file (it would fail to open)
	id->hMux = NULL;
	id->hMem = NULL;
	id->lockdata = NULL;
#endif
	OpenCounter(+1);
	TRACE3("OPEN EX %d \"%s\"\n", h, zFilename);
	return SQLITE_OK;
}

/*
................................................................................
	id->h = h;
	id->locktype = NO_LOCK;
	id->sharedLockByte = 0;
	id->isOpen = 1;
	id->wFilename = wFilename;
	id->delOnClose = 0;
#ifndef SQLITE_WCE_OMIT_FILELOCK
	// Not shared, so no need to lock file
	id->hMux = NULL;
	id->hMem = NULL;
	id->lockdata = NULL;
#endif
	OpenCounter(+1);
	TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
	return SQLITE_OK;
}

/*







>
>
>
>
>
>







 







>
>







 







>
|









>
>
|
>







 







>
>
|







 







|
|
|
<







 







|
|
|
<







102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
...
501
502
503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
...
536
537
538
539
540
541
542
543
544
545

546
547
548
549
550
551
552
** This is needed for the command line version of sqlite to compile.
**/
int isatty( int handle )
{
	UNREFERENCED_PARAMETER(handle);
	return 1;
}

// Stubbed in WinCE
DWORD WINAPI GetFullPathNameW(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart)
{
  return 0;
}

/*
** Converts a relative path to an absolute path.
** There is no current directory concept on Windows CE, so we assume
** we are working always with absolute paths and simply copy
** the given path to the provided buffer.
*/
................................................................................
** NOTE: I'm not sure in what conditions this can turn into an infinite
**       loop. I don't think it is possible without a serious bug in
**       sqlite or windows, but i'm not sure of this.
*/
static void lock_file( OsFile *id )
{
	DWORD res;
  if (id->lockdata == NULL) return;

	while ( 1 )
	{
		res = WaitForSingleObject( id->hMux, INFINITE );
		// I don't know very well what I have to do in this case.
		// The MSDN says that this case is when a thread terminates without
		// releasing the mutex. So I have to release it and try again
		if ( res == WAIT_ABANDONED )
................................................................................

/*
** Releases ownership of the file mutex.
** Always success
*/
static void unlock_file( OsFile *id )
{
  if (id->hMux)
    ReleaseMutex( id->hMux );
}

/*
** Acquire a lock on the file.
** Returns non-zero on success, zero on failure.
*/
static int getLock( OsFile *id, int locktype )
{
	int rc = 0;
  if (id->lockdata == NULL) return 1;

  lock_file( id );
  
	if ( locktype == SHARED_LOCK )
	{
		assert( id->lockdata->shared >= 0 );
		++id->lockdata->shared;	/* Increment number of readers */
		id->lockdata->lock |= 1 << SHARED_LOCK;
	}
	else
................................................................................
/*
** Releases lock on the file.
** Always succeeds, so no return value.
*/
static void unsetLock( OsFile *id, int locktype )
{
	assert( locktype >= SHARED_LOCK );
  if (id->lockdata == NULL) return;

  lock_file( id );
	if ( locktype == SHARED_LOCK )
	{
		assert( id->lockdata->shared > 0 );
		--id->lockdata->shared;	/* Decrement number of readers */
		if ( id->lockdata->shared == 0 )	/* Last reader? */
			id->lockdata->lock &= ~(1 << SHARED_LOCK);
	}
................................................................................
	id->h = h;
	id->locktype = NO_LOCK;
	id->sharedLockByte = 0;
	id->isOpen = 1;
	id->wFilename = wFilename;
	id->delOnClose = delFlag;
#ifndef SQLITE_WCE_OMIT_FILELOCK
  id->lockdata = NULL;
  id->hMux = NULL;
  id->hMem = NULL;

#endif
	OpenCounter(+1);
	TRACE3("OPEN EX %d \"%s\"\n", h, zFilename);
	return SQLITE_OK;
}

/*
................................................................................
	id->h = h;
	id->locktype = NO_LOCK;
	id->sharedLockByte = 0;
	id->isOpen = 1;
	id->wFilename = wFilename;
	id->delOnClose = 0;
#ifndef SQLITE_WCE_OMIT_FILELOCK
  id->lockdata = NULL;
  id->hMux = NULL;
  id->hMem = NULL;

#endif
	OpenCounter(+1);
	TRACE3("OPEN RO %d \"%s\"\n", h, zFilename);
	return SQLITE_OK;
}

/*

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

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
653
654
655
656
657
658
659
660

661

662
663
664
665
666
667
668
....
1034
1035
1036
1037
1038
1039
1040
1041

1042

1043
1044
1045
1046
1047
1048
1049
....
1164
1165
1166
1167
1168
1169
1170
1171

1172

1173
1174
1175
1176
1177
1178
1179
....
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
....
1742
1743
1744
1745
1746
1747
1748
1749





1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771




1772
1773
1774
1775
1776
1777
1778
....
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126

2127

2128
2129
2130
2131

2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
....
2192
2193
2194
2195
2196
2197
2198
2199

2200
2201
2202
2203
2204
2205
2206
....
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
....
2502
2503
2504
2505
2506
2507
2508
2509

2510

2511
2512
2513
2514
2515
2516
2517
....
2811
2812
2813
2814
2815
2816
2817




2818
2819
2820
2821
2822
2823
2824
....
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
....
3437
3438
3439
3440
3441
3442
3443

3444
3445
3446
3447
3448
3449
3450
3451
3452
....
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.9 2005/09/01 06:07:55 rmsimpson Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
................................................................................
    rc = write32bits(&pPager->jfd, pPager->sectorSize);
  }

  /* The journal header has been written successfully. Seek the journal
  ** file descriptor to the end of the journal header sector.
  */
  if( rc==SQLITE_OK ){
    sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1);

    rc = sqlite3OsWrite(&pPager->jfd, "\000", 1);

  }
  return rc;
}

/*
** The journal file must be open when this is called. A journal header file
** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
................................................................................
  ** page content is in the main journal either because the page is not in
  ** cache or else it is marked as needSync==0.
  */
  pPg = pager_lookup(pPager, pgno);
  assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 );
  TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno);
  if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){
    sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);

    rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);

    if( pPg ) pPg->dirty = 0;
  }
  if( pPg ){
    /* No page should ever be explicitly rolled back that is in use, except
    ** for page 1 which is held in use in order to keep the lock on the
    ** database active. However such a page may be rolled back as a result
    ** of an internal error resulting in an automatic call to
................................................................................
static int pager_reload_cache(Pager *pPager){
  PgHdr *pPg;
  int rc = SQLITE_OK;
  for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
    char zBuf[SQLITE_MAX_PAGE_SIZE];
    if( !pPg->dirty ) continue;
    if( (int)pPg->pgno <= pPager->origDbSize ){
      sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));

      rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize);

      TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
      if( rc ) break;
      CODEC(pPager, zBuf, pPg->pgno, 2);
    }else{
      memset(zBuf, 0, pPager->pageSize);
    }
    if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){
................................................................................
  }

  pPager->journalOff = szJ;
  
end_stmt_playback:
  if( rc!=SQLITE_OK ){
    pPager->errMask |= PAGER_ERR_CORRUPT;
    rc = SQLITE_CORRUPT;  /* bkpt-CORRUPT */
  }else{
    pPager->journalOff = szJ;
    /* pager_reload_cache(pPager); */
  }
  return rc;
}

................................................................................
    sqlite3OsSeek(&pPager->fd, 0);
    sqlite3OsRead(&pPager->fd, pDest, N);
  }
}

/*
** Return the total number of pages in the disk file associated with
** pPager.





*/
int sqlite3pager_pagecount(Pager *pPager){
  i64 n;
  assert( pPager!=0 );
  if( pPager->dbSize>=0 ){
    return pPager->dbSize;
  }
  if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
    pPager->errMask |= PAGER_ERR_DISK;
    return 0;
  }
  if( n>0 && n<pPager->pageSize ){
    n = 1;
  }else{
    n /= pPager->pageSize;
  }
  if( !MEMDB && n==PENDING_BYTE/pPager->pageSize ){
    n++;
  }
  if( pPager->state!=PAGER_UNLOCK ){
    pPager->dbSize = n;
  }




  return n;
}

/*
** Forward declaration
*/
static int syncJournal(Pager*);
................................................................................
        /* Write the nRec value into the journal file header. If in
        ** full-synchronous mode, sync the journal first. This ensures that
        ** all data has really hit the disk before nRec is updated to mark
        ** it as a candidate for rollback. 
        */
        if( pPager->fullSync ){
          TRACE2("SYNC journal of %d\n", PAGERID(pPager));
          rc = sqlite3OsSync(&pPager->jfd);
          if( rc!=0 ) return rc;
        }

        sqlite3OsSeek(&pPager->jfd, pPager->journalHdr + sizeof(aJournalMagic));

        rc = write32bits(&pPager->jfd, pPager->nRec);
        if( rc ) return rc;

        sqlite3OsSeek(&pPager->jfd, pPager->journalOff);

      }
      TRACE2("SYNC journal of %d\n", PAGERID(pPager));
      rc = sqlite3OsSync(&pPager->jfd);
      if( rc!=0 ) return rc;
      pPager->journalStarted = 1;
    }
    pPager->needSync = 0;

    /* Erase the needSync flag from every page.
    */
................................................................................
  rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  while( pList ){
    assert( pList->dirty );
    sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);

    /* If there are dirty pages in the page cache with page numbers greater
    ** than Pager.dbSize, this means sqlite3pager_truncate() was called to
    ** make the file smaller (presumably by auto-vacuum code). Do not write
    ** any such pages to the file.
    */
    if( pList->pgno<=pPager->dbSize ){
      CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
................................................................................
int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
  PgHdr *pPg;
  int rc;

  /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
  ** number greater than this, or zero, is requested.
  */
  if( pgno>PAGER_MAX_PGNO || pgno==0 ){
    return SQLITE_CORRUPT;
  }

  /* Make sure we have not hit any critical errors.
  */ 
  assert( pPager!=0 );
  *ppPage = 0;
  if( pPager->errMask & ~(PAGER_ERR_FULL) ){
................................................................................
      return rc;
    }
    if( sqlite3pager_pagecount(pPager)<(int)pgno ){
      memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
    }else{
      int rc;
      assert( MEMDB==0 );
      sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);

      rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize);

      TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
      CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
      if( rc!=SQLITE_OK ){
        i64 fileSize;
        if( sqlite3OsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
               || fileSize>=pgno*pPager->pageSize ){
          sqlite3pager_unref(PGHDR_TO_DATA(pPg));
................................................................................
          assert( pHist->pOrig==0 );
          pHist->pOrig = sqliteMallocRaw( pPager->pageSize );
          if( pHist->pOrig ){
            memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize);
          }
        }else{
          u32 cksum;




          CODEC(pPager, pData, pPg->pgno, 7);
          cksum = pager_cksum(pPager, pPg->pgno, pData);
          saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager);
          store32bits(cksum, pPg, pPager->pageSize);
          szPg = pPager->pageSize+8;
          store32bits(pPg->pgno, pPg, -4);
          rc = sqlite3OsWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
................................................................................
    if( rc==SQLITE_OK ){
      rc = rc2;
    }
  }else{
    rc = pager_playback(pPager);
  }
  if( rc!=SQLITE_OK ){
    rc = SQLITE_CORRUPT;  /* bkpt-CORRUPT */
    pPager->errMask |= PAGER_ERR_CORRUPT;
  }
  pPager->dbSize = -1;
  return rc;
}

/*
................................................................................
      if( nTrunc!=0 ){
        /* If this transaction has made the database smaller, then all pages
        ** being discarded by the truncation must be written to the journal
        ** file.
        */
        Pgno i;
        void *pPage;

        for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
          if( !(pPager->aInJournal[i/8] & (1<<(i&7))) ){
            rc = sqlite3pager_get(pPager, i, &pPage);
            if( rc!=SQLITE_OK ) goto sync_exit;
            rc = sqlite3pager_write(pPage);
            sqlite3pager_unref(pPage);
            if( rc!=SQLITE_OK ) goto sync_exit;
          }
        } 
................................................................................
    /* Write all dirty pages to the database file */
    pPg = pager_get_all_dirty_pages(pPager);
    rc = pager_write_pagelist(pPg);
    if( rc!=SQLITE_OK ) goto sync_exit;

    /* Sync the database file. */
    if( !pPager->noSync ){
      rc = sqlite3OsSync(&pPager->fd);
    }

    pPager->state = PAGER_SYNCED;
  }

sync_exit:
  return rc;







|







 







|
>
|
>







 







|
>
|
>







 







|
>
|
>







 







|







 







|
>
>
>
>
>





|
|
|
|
|
|
|
|
|
|
|
<
<
<
|
|
|
>
>
>
>







 







|


>
|
>



|
>


|







 







|
>







 







|
|







 







|
>
|
>







 







>
>
>
>







 







|







 







>

|







 







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
....
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
....
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
....
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
....
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776



1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
....
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
....
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
....
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
....
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
....
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
....
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
....
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
....
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
................................................................................
    rc = write32bits(&pPager->jfd, pPager->sectorSize);
  }

  /* The journal header has been written successfully. Seek the journal
  ** file descriptor to the end of the journal header sector.
  */
  if( rc==SQLITE_OK ){
    rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1);
    if( rc==SQLITE_OK ){
      rc = sqlite3OsWrite(&pPager->jfd, "\000", 1);
    }
  }
  return rc;
}

/*
** The journal file must be open when this is called. A journal header file
** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
................................................................................
  ** page content is in the main journal either because the page is not in
  ** cache or else it is marked as needSync==0.
  */
  pPg = pager_lookup(pPager, pgno);
  assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 );
  TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno);
  if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){
    rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
    if( rc==SQLITE_OK ){
      rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);
    }
    if( pPg ) pPg->dirty = 0;
  }
  if( pPg ){
    /* No page should ever be explicitly rolled back that is in use, except
    ** for page 1 which is held in use in order to keep the lock on the
    ** database active. However such a page may be rolled back as a result
    ** of an internal error resulting in an automatic call to
................................................................................
static int pager_reload_cache(Pager *pPager){
  PgHdr *pPg;
  int rc = SQLITE_OK;
  for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
    char zBuf[SQLITE_MAX_PAGE_SIZE];
    if( !pPg->dirty ) continue;
    if( (int)pPg->pgno <= pPager->origDbSize ){
      rc = sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));
      if( rc==SQLITE_OK ){
        rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize);
      }
      TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
      if( rc ) break;
      CODEC(pPager, zBuf, pPg->pgno, 2);
    }else{
      memset(zBuf, 0, pPager->pageSize);
    }
    if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){
................................................................................
  }

  pPager->journalOff = szJ;
  
end_stmt_playback:
  if( rc!=SQLITE_OK ){
    pPager->errMask |= PAGER_ERR_CORRUPT;
    rc = SQLITE_CORRUPT;
  }else{
    pPager->journalOff = szJ;
    /* pager_reload_cache(pPager); */
  }
  return rc;
}

................................................................................
    sqlite3OsSeek(&pPager->fd, 0);
    sqlite3OsRead(&pPager->fd, pDest, N);
  }
}

/*
** Return the total number of pages in the disk file associated with
** pPager. 
**
** If the PENDING_BYTE lies on the page directly after the end of the
** file, then consider this page part of the file too. For example, if
** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
** file is 4096 bytes, 5 is returned instead of 4.
*/
int sqlite3pager_pagecount(Pager *pPager){
  i64 n;
  assert( pPager!=0 );
  if( pPager->dbSize>=0 ){
    n = pPager->dbSize;
  } else {
    if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
      pPager->errMask |= PAGER_ERR_DISK;
      return 0;
    }
    if( n>0 && n<pPager->pageSize ){
      n = 1;
    }else{
      n /= pPager->pageSize;
    }



    if( pPager->state!=PAGER_UNLOCK ){
      pPager->dbSize = n;
    }
  }
  if( n==(PENDING_BYTE/pPager->pageSize) ){
    n++;
  }
  return n;
}

/*
** Forward declaration
*/
static int syncJournal(Pager*);
................................................................................
        /* Write the nRec value into the journal file header. If in
        ** full-synchronous mode, sync the journal first. This ensures that
        ** all data has really hit the disk before nRec is updated to mark
        ** it as a candidate for rollback. 
        */
        if( pPager->fullSync ){
          TRACE2("SYNC journal of %d\n", PAGERID(pPager));
          rc = sqlite3OsSync(&pPager->jfd, 0);
          if( rc!=0 ) return rc;
        }
        rc = sqlite3OsSeek(&pPager->jfd,
                           pPager->journalHdr + sizeof(aJournalMagic));
        if( rc ) return rc;
        rc = write32bits(&pPager->jfd, pPager->nRec);
        if( rc ) return rc;

        rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff);
        if( rc ) return rc;
      }
      TRACE2("SYNC journal of %d\n", PAGERID(pPager));
      rc = sqlite3OsSync(&pPager->jfd, pPager->fullSync);
      if( rc!=0 ) return rc;
      pPager->journalStarted = 1;
    }
    pPager->needSync = 0;

    /* Erase the needSync flag from every page.
    */
................................................................................
  rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  while( pList ){
    assert( pList->dirty );
    rc = sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
    if( rc ) return rc;
    /* If there are dirty pages in the page cache with page numbers greater
    ** than Pager.dbSize, this means sqlite3pager_truncate() was called to
    ** make the file smaller (presumably by auto-vacuum code). Do not write
    ** any such pages to the file.
    */
    if( pList->pgno<=pPager->dbSize ){
      CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
................................................................................
int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
  PgHdr *pPg;
  int rc;

  /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
  ** number greater than this, or zero, is requested.
  */
  if( pgno>PAGER_MAX_PGNO || pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
    return SQLITE_CORRUPT_BKPT;
  }

  /* Make sure we have not hit any critical errors.
  */ 
  assert( pPager!=0 );
  *ppPage = 0;
  if( pPager->errMask & ~(PAGER_ERR_FULL) ){
................................................................................
      return rc;
    }
    if( sqlite3pager_pagecount(pPager)<(int)pgno ){
      memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
    }else{
      int rc;
      assert( MEMDB==0 );
      rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
      if( rc==SQLITE_OK ){
        rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize);
      }
      TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
      CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
      if( rc!=SQLITE_OK ){
        i64 fileSize;
        if( sqlite3OsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
               || fileSize>=pgno*pPager->pageSize ){
          sqlite3pager_unref(PGHDR_TO_DATA(pPg));
................................................................................
          assert( pHist->pOrig==0 );
          pHist->pOrig = sqliteMallocRaw( pPager->pageSize );
          if( pHist->pOrig ){
            memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize);
          }
        }else{
          u32 cksum;
          /* We should never write to the journal file the page that
          ** contains the database locks.  The following assert verifies
          ** that we do not. */
          assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
          CODEC(pPager, pData, pPg->pgno, 7);
          cksum = pager_cksum(pPager, pPg->pgno, pData);
          saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager);
          store32bits(cksum, pPg, pPager->pageSize);
          szPg = pPager->pageSize+8;
          store32bits(pPg->pgno, pPg, -4);
          rc = sqlite3OsWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
................................................................................
    if( rc==SQLITE_OK ){
      rc = rc2;
    }
  }else{
    rc = pager_playback(pPager);
  }
  if( rc!=SQLITE_OK ){
    rc = SQLITE_CORRUPT_BKPT;
    pPager->errMask |= PAGER_ERR_CORRUPT;
  }
  pPager->dbSize = -1;
  return rc;
}

/*
................................................................................
      if( nTrunc!=0 ){
        /* If this transaction has made the database smaller, then all pages
        ** being discarded by the truncation must be written to the journal
        ** file.
        */
        Pgno i;
        void *pPage;
        int iSkip = PAGER_MJ_PGNO(pPager);
        for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
          if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){
            rc = sqlite3pager_get(pPager, i, &pPage);
            if( rc!=SQLITE_OK ) goto sync_exit;
            rc = sqlite3pager_write(pPage);
            sqlite3pager_unref(pPage);
            if( rc!=SQLITE_OK ) goto sync_exit;
          }
        } 
................................................................................
    /* Write all dirty pages to the database file */
    pPg = pager_get_all_dirty_pages(pPager);
    rc = pager_write_pagelist(pPg);
    if( rc!=SQLITE_OK ) goto sync_exit;

    /* Sync the database file. */
    if( !pPager->noSync ){
      rc = sqlite3OsSync(&pPager->fd, 0);
    }

    pPager->state = PAGER_SYNCED;
  }

sync_exit:
  return rc;

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

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem.  The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.9 2005/09/01 06:07:56 rmsimpson Exp $
*/

/*
** The default size of a database page.
*/
#ifndef SQLITE_DEFAULT_PAGE_SIZE
# define SQLITE_DEFAULT_PAGE_SIZE 1024
................................................................................
** This value is used to initialize certain arrays on the stack at
** various places in the code.  On embedded machines where stack space
** is limited and the flexibility of having large pages is not needed,
** it makes good sense to reduce the maximum page size to something more
** reasonable, like 1024.
*/
#ifndef SQLITE_MAX_PAGE_SIZE
# define SQLITE_MAX_PAGE_SIZE 8192
#endif

/*
** Maximum number of pages in one database.
*/
#define SQLITE_MAX_PAGE 1073741823








|







 







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem.  The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
** @(#) $Id: pager.h,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $
*/

/*
** The default size of a database page.
*/
#ifndef SQLITE_DEFAULT_PAGE_SIZE
# define SQLITE_DEFAULT_PAGE_SIZE 1024
................................................................................
** This value is used to initialize certain arrays on the stack at
** various places in the code.  On embedded machines where stack space
** is limited and the flexibility of having large pages is not needed,
** it makes good sense to reduce the maximum page size to something more
** reasonable, like 1024.
*/
#ifndef SQLITE_MAX_PAGE_SIZE
# define SQLITE_MAX_PAGE_SIZE 32768
#endif

/*
** Maximum number of pages in one database.
*/
#define SQLITE_MAX_PAGE 1073741823

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

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
...
675
676
677
678
679
680
681

682
683
684


685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
...
881
882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
...
955
956
957
958
959
960
961

962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
....
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
....
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
....
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936





1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985









1986
1987
1988
1989

1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034

2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080

2081
2082
2083
2084





2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200




2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217





2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310

2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331

2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362





2363
2364
2365
2366
2367
2368
2369
2370

2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385

2386
2387
2388
2389

2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402

2403
2404
2405
2406

2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460

2461
2462
2463
2464
2465


2466
2467
2468
2469
2470
2471
2472
2473
2474
2475





2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492

2493





2494
2495
2496


2497
2498
2499
2500
2501
2502
2503
2504

2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531

2532
2533
2534
2535
2536

2537
2538
2539
2540
2541

2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577

2578
2579
2580
2581
2582
2583
2584
2585
2586

2587
2588

2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601




2602
2603
2604
2605

2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642





2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662


2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676








2677
2678
2679
2680

2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
....
2695
2696
2697
2698
2699
2700
2701

2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726

2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770







2771

2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801




2802
2803

2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824

2825

2826

2827
2828
2829
2830
2831
2832
2833
2834

2835

2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
































3182
3183
3184
3185
3186
3187
3188
....
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
**    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
**    YYNSTATE           the combined number of states.
**    YYNRULE            the number of rules in the grammar
**    YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
*/
#define YYCODETYPE unsigned char
#define YYNOCODE 244
#define YYACTIONTYPE unsigned short int
#define sqlite3ParserTOKENTYPE Token
typedef union {
  sqlite3ParserTOKENTYPE yy0;
  struct {int value; int mask;} yy35;
  Expr* yy44;
  int yy58;
  Select* yy99;
  struct LimitVal yy112;
  Token yy144;
  TriggerStep* yy203;
  struct TrigEvent yy234;
  IdList* yy258;



  struct AttachKey yy300;
  SrcList* yy367;
  ExprList* yy412;
  struct LikeOp yy432;
  int yy487;
} YYMINORTYPE;
#define YYSTACKDEPTH 100
#define sqlite3ParserARG_SDECL Parse *pParse;
#define sqlite3ParserARG_PDECL ,Parse *pParse
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
#define YYNSTATE 578
#define YYNRULE 310
#define YYERRORSYMBOL 143
#define YYERRSYMDT yy487
#define YYFALLBACK 1
#define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
#define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
#define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)

/* Next are that tables used to determine what action to take based on the
** current state and lookahead token.  These tables are used to implement
................................................................................
**  yy_shift_ofst[]    For each state, the offset into yy_action for
**                     shifting terminals.
**  yy_reduce_ofst[]   For each state, the offset into yy_action for
**                     shifting non-terminals after a reduce.
**  yy_default[]       Default action for each state.
*/
static const YYACTIONTYPE yy_action[] = {
 /*     0 */   283,  581,  110,  137,  139,  135,  141,  268,  147,  149,
 /*    10 */   151,  153,  155,  157,  159,  161,  163,  165,  114,  119,
 /*    20 */   120,  167,  175,  147,  149,  151,  153,  155,  157,  159,
 /*    30 */   161,  163,  165,  155,  157,  159,  161,  163,  165,  132,
 /*    40 */    94,  168,  178,  183,  188,  177,  182,  143,  145,  137,
 /*    50 */   139,  135,  141,   72,  147,  149,  151,  153,  155,  157,
 /*    60 */   159,  161,  163,  165,   44,   45,  245,  111,  147,  149,
 /*    70 */   151,  153,  155,  157,  159,  161,  163,  165,   13,  427,
 /*    80 */   121,  578,  657,  639,  375,  347,  167,   39,    6,    5,
 /*    90 */    92,    3,  576,  363,   25,  355,  299,  255,   34,  269,
 /*   100 */   513,  129,  372,  112,  132,   94,  168,  178,  183,  188,
 /*   110 */   177,  182,  143,  145,  137,  139,  135,  141,  567,  147,
 /*   120 */   149,  151,  153,  155,  157,  159,  161,  163,  165,   77,
 /*   130 */   109,  373,  133,   77,  117,  119,  120,    7,   13,   32,
 /*   140 */    33,  300,  280,   14,   15,  377,  301,  610,  379,  386,
 /*   150 */   391,  167,  377,  366,  369,  379,  386,  391,  524,  330,
 /*   160 */   394,   64,  368,  374,  407,  705,   95,  394,  571,  132,
 /*   170 */    94,  168,  178,  183,  188,  177,  182,  143,  145,  137,
 /*   180 */   139,  135,  141,    9,  147,  149,  151,  153,  155,  157,
 /*   190 */   159,  161,  163,  165,  127,  125,  121,  373,  167,  101,
 /*   200 */   102,  103,   28,   14,   15,  408,   33,  860,  889,    1,
 /*   210 */   577,    3,  576,    4,  540,  332,  132,   94,  168,  178,
 /*   220 */   183,  188,  177,  182,  143,  145,  137,  139,  135,  141,
 /*   230 */   295,  147,  149,  151,  153,  155,  157,  159,  161,  163,
 /*   240 */   165,    2,  466,  377,    4,  167,  379,  386,  391,   16,
 /*   250 */    17,   18,  285,  159,  161,  163,  165,  240,  394,  173,
 /*   260 */   243,  184,  189,  132,   94,  168,  178,  183,  188,  177,
 /*   270 */   182,  143,  145,  137,  139,  135,  141,   96,  147,  149,
 /*   280 */   151,  153,  155,  157,  159,  161,  163,  165,  815,  291,
 /*   290 */   308,  813,   51,  500,  472,  462,  588,  539,   75,  322,
 /*   300 */    27,  133,  409,  704,   81,  272,   10,  173,   96,  184,
 /*   310 */   189,   96,  190,   13,  541,  542,   13,  393,   78,  167,
 /*   320 */    37,  361,   40,   59,   67,   69,  325,  356,  586,   75,
 /*   330 */   197,  368,   75,  316,  358,   95,  218,  132,   94,  168,
 /*   340 */   178,  183,  188,  177,  182,  143,  145,  137,  139,  135,
 /*   350 */   141,   77,  147,  149,  151,  153,  155,  157,  159,  161,
 /*   360 */   163,  165,  173,  113,  184,  189,  167,  110,  101,  102,
 /*   370 */   103,  318,  274,  405,  329,  121,   12,  461,   14,   15,
 /*   380 */   404,   14,   15,  238,  132,   94,  168,  178,  183,  188,
 /*   390 */   177,  182,  143,  145,  137,  139,  135,  141,  273,  147,
 /*   400 */   149,  151,  153,  155,  157,  159,  161,  163,  165,   96,
 /*   410 */    77,   51,  315,  427,   48,   36,  360,  196,  317,  129,
 /*   420 */   130,  112,  314,   49,  355,  209,  313,   13,   96,  110,
 /*   430 */    75,  197,  111,   96,  814,  485,   50,  589,   46,  461,
 /*   440 */   167,   40,   59,   67,   69,  325,  356,  482,   47,   75,
 /*   450 */   257,  467,  429,  358,   75,  197,  469,  232,  132,   94,
 /*   460 */   168,  178,  183,  188,  177,  182,  143,  145,  137,  139,
 /*   470 */   135,  141,   77,  147,  149,  151,  153,  155,  157,  159,
 /*   480 */   161,  163,  165,  323,  237,   13,  830,  169,  249,  258,
 /*   490 */    13,  703,   14,   15,  111,   96,  265,  485,   96,  192,
 /*   500 */    96,  194,  195,   13,  192,  167,  194,  195,  238,  171,
 /*   510 */   172,  476,  192,  471,  194,  195,   75,  211,  469,   75,
 /*   520 */   257,   75,   91,  132,   94,  168,  178,  183,  188,  177,
 /*   530 */   182,  143,  145,  137,  139,  135,  141,  170,  147,  149,
 /*   540 */   151,  153,  155,  157,  159,  161,  163,  165,  365,   48,
 /*   550 */    14,   15,  216,   65,  228,   14,   15,  298,   49,  251,
 /*   560 */    66,   13,  602,   13,  330,   96,  676,  212,   14,   15,
 /*   570 */   167,   50,  865,  222,   57,   58,  678,  275,  192,   20,
 /*   580 */   194,  195,  277,  403,   26,  351,   75,  499,  132,   94,
 /*   590 */   168,  178,  183,  188,  177,  182,  143,  145,  137,  139,
 /*   600 */   135,  141,   96,  147,  149,  151,  153,  155,  157,  159,
 /*   610 */   161,  163,  165,  587,  863,   83,   11,  167,  742,  345,
 /*   620 */   332,  312,  306,   75,   93,  358,   14,   15,   14,   15,
 /*   630 */   858,  173,  495,  184,  189,  132,   94,  168,  178,  183,
 /*   640 */   188,  177,  182,  143,  145,  137,  139,  135,  141,  594,
 /*   650 */   147,  149,  151,  153,  155,  157,  159,  161,  163,  165,
 /*   660 */    22,  272,  352,  192,  167,  194,  195,  192,  295,  194,
 /*   670 */   195,  285,  505,  192,   42,  194,  195,  192,  351,  194,
 /*   680 */   195,  595,  132,   94,  168,  178,  183,  188,  177,  182,
 /*   690 */   143,  145,  137,  139,  135,  141,  338,  147,  149,  151,
 /*   700 */   153,  155,  157,  159,  161,  163,  165,  837,  511,  286,
 /*   710 */   507,  167,  382,  127,  125,  192,  339,  194,  195,  192,
 /*   720 */   543,  194,  195,  333,  340,  342,  351,  442,  274,  132,
 /*   730 */    94,  168,  178,  183,  188,  177,  182,  143,  145,  137,
 /*   740 */   139,  135,  141,   96,  147,  149,  151,  153,  155,  157,
 /*   750 */   159,  161,  163,  165,  273,  352,  110,  371,  167,  373,
 /*   760 */   388,  438,  440,  439,   75,  499,  362,  574,   33,  335,
 /*   770 */   538,  668,  656,  351,   31,  413,  132,  186,  168,  178,
 /*   780 */   183,  188,  177,  182,  143,  145,  137,  139,  135,  141,
 /*   790 */   509,  147,  149,  151,  153,  155,  157,  159,  161,  163,
 /*   800 */   165,   96,  736,  352,  283,  167,  110,  397,  123,  124,
 /*   810 */   531,  421,  193,  416,  115,  681,  116,  235,  477,  236,
 /*   820 */   351,  111,   75,  244,   94,  168,  178,  183,  188,  177,
 /*   830 */   182,  143,  145,  137,  139,  135,  141,   96,  147,  149,
 /*   840 */   151,  153,  155,  157,  159,  161,  163,  165,   96,  879,
 /*   850 */   352,  881,  167,  292,  455,  293,  270,  280,   75,  108,
 /*   860 */   554,  319,  857,  236,   42,  447,   13,  351,   13,   75,
 /*   870 */   134,  111,  168,  178,  183,  188,  177,  182,  143,  145,
 /*   880 */   137,  139,  135,  141,   96,  147,  149,  151,  153,  155,
 /*   890 */   157,  159,  161,  163,  165,   96,   76,  352,  444,   96,
 /*   900 */    71,   96,  443,   52,  208,   75,  136,   76,  106,   24,
 /*   910 */   412,   71,  180,  596,  445,   54,   75,  138,  266,  106,
 /*   920 */    75,  140,   75,  142,  441,  220,   96,  337,  336,   29,
 /*   930 */    96,   14,   15,   14,   15,  133,  220,   77,   96,  198,
 /*   940 */    96,  458,  179,  346,  348,  347,  133,   75,  433,   96,
 /*   950 */   198,   75,  144,  389,  285,  347,  204,  202,  320,   75,
 /*   960 */   146,   75,  148,  410,  200,   73,   74,  204,  202,   95,
 /*   970 */    75,  150,  398,   96,  347,  200,   73,   74,  852,   96,
 /*   980 */    95,   76,  823,  448,  597,   71,  432,  459,  293,  420,
 /*   990 */    96,  705,  303,  106,   75,  480,   77,  436,  437,   81,
 /*  1000 */    75,  152,  101,  102,  103,  104,  105,  206,  210,  705,
 /*  1010 */   220,   75,  154,  101,  102,  103,  104,  105,  206,  210,
 /*  1020 */   133,   30,   77,  240,  198,  456,   96,  347,   35,  464,
 /*  1030 */    45,  490,  463,  293,   96,  873,  498,   96,  496,   96,
 /*  1040 */    76,  204,  202,  736,   71,   96,  601,   75,  156,  200,
 /*  1050 */    73,   74,  106,   96,   95,   75,  158,  295,   75,  160,
 /*  1060 */    75,  162,   38,  492,   96,  853,   75,  164,   76,  220,
 /*  1070 */    41,  191,   71,  552,   75,  166,  482,   43,  427,  133,
 /*  1080 */   106,  528,  568,  198,   96,   75,  197,  101,  102,  103,
 /*  1090 */   104,  105,  206,  210,  816,  670,   77,  220,  240,   81,
 /*  1100 */   204,  202,  309,   96,   77,   75,  174,  133,  200,   73,
 /*  1110 */    74,  198,  493,   95,   77,    8,  489,  506,  427,  427,
 /*  1120 */    19,   21,   23,  411,   75,  176,   42,  234,  204,  202,
 /*  1130 */   427,   81,  427,  562,  427,  546,  200,   73,   74,  238,
 /*  1140 */   522,   95,  556,   96,  529,  427,  101,  102,  103,  104,
 /*  1150 */   105,  206,  210,  532,  535,  496,  466,  508,  510,  266,
 /*  1160 */    96,  533,  885,  559,   75,  185,  565,   96,   56,  512,
 /*  1170 */    96,  516,   96,  520,  101,  102,  103,  104,  105,  206,
 /*  1180 */   210,   75,  187,   55,  526,   53,   60,   61,   75,  199,
 /*  1190 */    96,   75,  201,   75,  203,   96,   64,   62,   96,   70,
 /*  1200 */    96,   63,   96,   68,   96,  611,   96,  514,  518,  462,
 /*  1210 */    84,   75,  205,  504,   96,  612,   75,  217,   81,   75,
 /*  1220 */   219,   75,  229,   75,  231,   75,  233,   75,  246,   81,
 /*  1230 */    79,   80,   96,  266,   82,   75,  262,   96,  263,  310,
 /*  1240 */    86,   96,  261,   96,   85,   96,  247,   96,   87,   97,
 /*  1250 */    99,   88,   90,   75,  267,  107,   89,   98,   75,  297,
 /*  1260 */    75,  307,   75,  364,   75,  392,   75,  484,   75,  497,
 /*  1270 */   118,  100,  131,  128,  165,  122,  181,  682,  239,  683,
 /*  1280 */   684,  207,  230,  213,  126,  214,  215,  221,  225,  224,
 /*  1290 */   223,  226,  240,  227,  241,  248,  242,  250,  254,  253,
 /*  1300 */   252,  255,  236,  264,  259,  256,  260,  271,  276,  278,
 /*  1310 */   279,  281,  284,  296,  282,  289,  287,  290,  288,  294,
 /*  1320 */   302,  305,  311,  304,  321,  324,  326,  344,  328,  327,
 /*  1330 */   331,  349,  357,  329,  353,  334,  341,  343,  380,  350,
 /*  1340 */   378,  381,  354,  367,  359,  370,  384,  387,  396,  395,
 /*  1350 */   399,  400,  385,   54,  406,  414,  376,  401,  390,  383,
 /*  1360 */   415,  417,  418,  402,  419,  422,  425,  423,  424,  434,
 /*  1370 */   426,  428,  430,  845,  431,  435,  850,  446,  851,  449,
 /*  1380 */   450,  451,  452,  453,  821,  454,  822,  457,  460,  465,
 /*  1390 */   743,  468,  744,  844,  470,  859,  463,  481,  475,  479,
 /*  1400 */   861,  474,  473,  478,  483,  486,  487,  491,  488,  494,
 /*  1410 */   862,  501,  502,  503,  864,  675,  677,  829,  871,  517,
 /*  1420 */   515,  735,  519,  521,  523,  738,  525,  741,  831,  534,
 /*  1430 */   832,  833,  530,  536,  834,  527,  537,  835,  544,  836,
 /*  1440 */   545,  547,  872,  874,  549,  875,  557,  555,  548,  550,
 /*  1450 */   553,  878,  880,  882,  561,  558,  883,  560,  551,  563,
 /*  1460 */   566,  569,  564,  570,  572,  573,  884,  555,  555,  555,
 /*  1470 */   555,  575,
};
static const YYCODETYPE yy_lookahead[] = {
 /*     0 */    25,   10,   27,   74,   75,   76,   77,   26,   79,   80,
 /*    10 */    81,   82,   83,   84,   85,   86,   87,   88,  168,  169,
 /*    20 */   170,   46,   78,   79,   80,   81,   82,   83,   84,   85,
 /*    30 */    86,   87,   88,   83,   84,   85,   86,   87,   88,   64,
 /*    40 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
 /*    50 */    75,   76,   77,   23,   79,   80,   81,   82,   83,   84,
 /*    60 */    85,   86,   87,   88,  189,  190,   26,   92,   79,   80,
 /*    70 */    81,   82,   83,   84,   85,   86,   87,   88,   27,  152,
 /*    80 */   230,    0,   24,   24,   26,   26,   46,  172,  147,  148,
 /*    90 */    50,   10,   11,   23,  153,  180,  159,   27,  162,  118,
 /*   100 */   159,  165,  166,  167,   64,   65,   66,   67,   68,   69,
 /*   110 */    70,   71,   72,   73,   74,   75,   76,   77,  191,   79,
 /*   120 */    80,   81,   82,   83,   84,   85,   86,   87,   88,  192,
 /*   130 */    25,  152,   62,  192,  168,  169,  170,   10,   27,  160,
 /*   140 */   161,  204,  205,   92,   93,   94,  209,  117,   97,   98,
 /*   150 */    99,   46,   94,   83,   84,   97,   98,   99,  217,   47,
 /*   160 */   109,  102,   92,  184,  185,   25,   96,  109,  241,   64,
 /*   170 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
 /*   180 */    75,   76,   77,  150,   79,   80,   81,   82,   83,   84,
 /*   190 */    85,   86,   87,   88,   83,   84,  230,  152,   46,  129,
 /*   200 */   130,  131,  157,   92,   93,  160,  161,   18,  144,  145,
 /*   210 */   146,   10,   11,  149,  103,  103,   64,   65,   66,   67,
 /*   220 */    68,   69,   70,   71,   72,   73,   74,   75,   76,   77,
 /*   230 */   152,   79,   80,   81,   82,   83,   84,   85,   86,   87,
 /*   240 */    88,  146,   53,   94,  149,   46,   97,   98,   99,   14,
 /*   250 */    15,   16,  165,   85,   86,   87,   88,  117,  109,  220,
 /*   260 */   221,  222,  223,   64,   65,   66,   67,   68,   69,   70,
 /*   270 */    71,   72,   73,   74,   75,   76,   77,  152,   79,   80,
 /*   280 */    81,   82,   83,   84,   85,   86,   87,   88,  136,  211,
 /*   290 */   203,   18,   66,  104,  105,  106,   10,  152,  173,  174,
 /*   300 */    23,   62,   25,   24,  115,   26,  151,  220,  152,  222,
 /*   310 */   223,  152,   23,   27,  169,  170,   27,  175,  159,   46,
 /*   320 */    94,   95,   96,   97,   98,   99,  100,  101,   10,  173,
 /*   330 */   174,   92,  173,  174,  108,   96,  137,   64,   65,   66,
 /*   340 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
 /*   350 */    77,  192,   79,   80,   81,   82,   83,   84,   85,   86,
 /*   360 */    87,   88,  220,   23,  222,  223,   46,   27,  129,  130,
 /*   370 */   131,  215,   93,  180,  181,  230,  152,  159,   92,   93,
 /*   380 */   187,   92,   93,  227,   64,   65,   66,   67,   68,   69,
 /*   390 */    70,   71,   72,   73,   74,   75,   76,   77,  119,   79,
 /*   400 */    80,   81,   82,   83,   84,   85,   86,   87,   88,  152,
 /*   410 */   192,   66,   24,  152,   19,  171,  172,   24,   24,  165,
 /*   420 */   166,  167,  112,   28,  180,   24,  116,   27,  152,   27,
 /*   430 */   173,  174,   92,  152,   18,  217,   41,   10,   43,  159,
 /*   440 */    46,   96,   97,   98,   99,  100,  101,  152,   53,  173,
 /*   450 */   174,  233,  191,  108,  173,  174,  238,  137,   64,   65,
 /*   460 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   470 */    76,   77,  192,   79,   80,   81,   82,   83,   84,   85,
 /*   480 */    86,   87,   88,   24,  227,   27,   10,   46,  212,  213,
 /*   490 */    27,   24,   92,   93,   92,  152,  215,  217,  152,  111,
 /*   500 */   152,  113,  114,   27,  111,   46,  113,  114,  227,   68,
 /*   510 */    69,  216,  111,  233,  113,  114,  173,  174,  238,  173,
 /*   520 */   174,  173,  174,   64,   65,   66,   67,   68,   69,   70,
 /*   530 */    71,   72,   73,   74,   75,   76,   77,   96,   79,   80,
 /*   540 */    81,   82,   83,   84,   85,   86,   87,   88,   24,   19,
 /*   550 */    92,   93,  136,   31,  138,   92,   93,   23,   28,  213,
 /*   560 */    38,   27,   10,   27,   47,  152,   10,  224,   92,   93,
 /*   570 */    46,   41,   10,   43,   14,   15,   10,  119,  111,  151,
 /*   580 */   113,  114,  119,   66,  154,  152,  173,  174,   64,   65,
 /*   590 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   600 */    76,   77,  152,   79,   80,   81,   82,   83,   84,   85,
 /*   610 */    86,   87,   88,   10,   10,  195,   13,   46,   10,  186,
 /*   620 */   103,   85,  202,  173,  174,  108,   92,   93,   92,   93,
 /*   630 */    12,  220,  219,  222,  223,   64,   65,   66,   67,   68,
 /*   640 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   10,
 /*   650 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
 /*   660 */   151,   26,  229,  111,   46,  113,  114,  111,  152,  113,
 /*   670 */   114,  165,   21,  111,  103,  113,  114,  111,  152,  113,
 /*   680 */   114,   10,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   690 */    72,   73,   74,   75,   76,   77,   34,   79,   80,   81,
 /*   700 */    82,   83,   84,   85,   86,   87,   88,   10,   57,  203,
 /*   710 */    59,   46,  186,   83,   84,  111,   54,  113,  114,  111,
 /*   720 */    23,  113,  114,  104,  105,  106,  152,  211,   93,   64,
 /*   730 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
 /*   740 */    75,   76,   77,  152,   79,   80,   81,   82,   83,   84,
 /*   750 */    85,   86,   87,   88,  119,  229,   27,  164,   46,  152,
 /*   760 */   186,  104,  105,  106,  173,  174,  173,  160,  161,  107,
 /*   770 */    73,   10,   24,  152,   26,   21,   64,   65,   66,   67,
 /*   780 */    68,   69,   70,   71,   72,   73,   74,   75,   76,   77,
 /*   790 */   139,   79,   80,   81,   82,   83,   84,   85,   86,   87,
 /*   800 */    88,  152,   10,  229,   25,   46,   27,  186,  129,  130,
 /*   810 */   219,   57,  112,   59,   24,  115,   26,   24,   26,   26,
 /*   820 */   152,   92,  173,  174,   65,   66,   67,   68,   69,   70,
 /*   830 */    71,   72,   73,   74,   75,   76,   77,  152,   79,   80,
 /*   840 */    81,   82,   83,   84,   85,   86,   87,   88,  152,   10,
 /*   850 */   229,   10,   46,   24,  186,   26,  204,  205,  173,  174,
 /*   860 */   131,   24,   12,   26,  103,   22,   27,  152,   27,  173,
 /*   870 */   174,   92,   66,   67,   68,   69,   70,   71,   72,   73,
 /*   880 */    74,   75,   76,   77,  152,   79,   80,   81,   82,   83,
 /*   890 */    84,   85,   86,   87,   88,  152,   23,  229,   29,  152,
 /*   900 */    27,  152,   33,   96,  159,  173,  174,   23,   35,  151,
 /*   910 */   155,   27,   66,   10,   45,  108,  173,  174,  126,   35,
 /*   920 */   173,  174,  173,  174,   49,   52,  152,   95,   96,  158,
 /*   930 */   152,   92,   93,   92,   93,   62,   52,  192,  152,   66,
 /*   940 */   152,   98,   96,   24,  229,   26,   62,  173,  174,  152,
 /*   950 */    66,  173,  174,   24,  165,   26,   83,   84,   85,  173,
 /*   960 */   174,  173,  174,  159,   91,   92,   93,   83,   84,   96,
 /*   970 */   173,  174,   24,  152,   26,   91,   92,   93,  103,  152,
 /*   980 */    96,   23,  139,  228,   10,   27,  136,  232,   26,  159,
 /*   990 */   152,   10,  203,   35,  173,  174,  192,   55,   56,  115,
 /*  1000 */   173,  174,  129,  130,  131,  132,  133,  134,  135,  103,
 /*  1010 */    52,  173,  174,  129,  130,  131,  132,  133,  134,  135,
 /*  1020 */    62,   24,  192,  117,   66,   24,  152,   26,  163,  189,
 /*  1030 */   190,   24,   64,   26,  152,   10,   24,  152,   26,  152,
 /*  1040 */    23,   83,   84,   10,   27,  152,   10,  173,  174,   91,
 /*  1050 */    92,   93,   35,  152,   96,  173,  174,  152,  173,  174,
 /*  1060 */   173,  174,  152,  159,  152,  103,  173,  174,   23,   52,
 /*  1070 */   175,  159,   27,   48,  173,  174,  152,   36,  152,   62,
 /*  1080 */    35,  159,   61,   66,  152,  173,  174,  129,  130,  131,
 /*  1090 */   132,  133,  134,  135,  136,  127,  192,   52,  117,  115,
 /*  1100 */    83,   84,   85,  152,  192,  173,  174,   62,   91,   92,
 /*  1110 */    93,   66,  128,   96,  192,   12,  211,  191,  152,  152,
 /*  1120 */    17,   18,   19,   20,  173,  174,  103,  215,   83,   84,
 /*  1130 */   152,  115,  152,   30,  152,   32,   91,   92,   93,  227,
 /*  1140 */   216,   96,   39,  152,  128,  152,  129,  130,  131,  132,
 /*  1150 */   133,  134,  135,   24,   51,   26,   53,  191,  191,  126,
 /*  1160 */   152,   58,  141,   60,  173,  174,   63,  152,   44,  191,
 /*  1170 */   152,  191,  152,  191,  129,  130,  131,  132,  133,  134,
 /*  1180 */   135,  173,  174,  183,  191,  175,   48,  176,  173,  174,
 /*  1190 */   152,  173,  174,  173,  174,  152,  102,  175,  152,   23,
 /*  1200 */   152,  177,  152,  175,  152,  117,  152,  104,  105,  106,
 /*  1210 */   196,  173,  174,  110,  152,  117,  173,  174,  115,  173,
 /*  1220 */   174,  173,  174,  173,  174,  173,  174,  173,  174,  115,
 /*  1230 */   193,  192,  152,  126,  194,  173,  174,  152,  123,  152,
 /*  1240 */   198,  152,  124,  152,  197,  152,  121,  152,  199,  117,
 /*  1250 */   117,  200,  125,  173,  174,   23,  201,  152,  173,  174,
 /*  1260 */   173,  174,  173,  174,  173,  174,  173,  174,  173,  174,
 /*  1270 */    24,  152,   24,  165,   88,  231,   96,  115,  152,  115,
 /*  1280 */   115,   23,  136,  225,  231,  226,   18,   23,   26,  190,
 /*  1290 */    24,  152,  117,   24,  152,  122,  156,   26,  101,  176,
 /*  1300 */   214,   27,   26,  122,  214,  164,  176,  206,  152,  152,
 /*  1310 */   119,  152,  152,  103,  156,  120,  207,   23,  208,  152,
 /*  1320 */    24,  208,  117,  207,   24,  175,  152,   23,  179,  178,
 /*  1330 */   152,  214,  164,  181,  214,  182,  182,  182,   48,  176,
 /*  1340 */   152,   23,  176,  173,  183,  173,   24,   23,   23,   48,
 /*  1350 */   100,  152,  175,  108,  185,  152,  185,  178,  175,  177,
 /*  1360 */   156,  152,  156,  179,   25,  152,  235,  156,  234,   42,
 /*  1370 */   103,  156,  236,   12,  237,   40,  103,   49,  103,  139,
 /*  1380 */   152,  156,  103,  152,   10,   23,  139,  175,   12,  188,
 /*  1390 */   127,   18,  127,   10,   10,   18,   64,  197,  107,   73,
 /*  1400 */    10,  152,  188,  152,   73,  127,  152,  218,   23,   23,
 /*  1410 */    10,  118,  152,  197,   10,   10,   10,   10,   10,  197,
 /*  1420 */   118,   10,  188,  107,  197,   10,  127,   10,   10,  152,
 /*  1430 */    10,   10,   23,  152,   10,  218,  156,   10,  152,   10,
 /*  1440 */    24,  239,   10,   10,   25,   10,  239,   37,  165,  152,
 /*  1450 */   165,   10,   10,   10,  156,  152,   10,  152,  240,  152,
 /*  1460 */    21,  140,  156,  152,  141,  242,   10,  243,  243,  243,
 /*  1470 */   243,  142,
};
#define YY_SHIFT_USE_DFLT (-72)
static const short yy_shift_ofst[] = {
 /*     0 */   201,   81,  -72,  -72, 1103,   -9,  127,  -72,  235,  603,
 /*    10 */   318,  286,  427,  -72,  -72,  -72,  -72,  -72,  -72,  603,
 /*    20 */   639,  603,  671,  603,  903,  277,  974,  400,  748,  997,
 /*    30 */  1036,   51,  -72,  402,  -72,  226,  -72,  400,  345,  -72,
 /*    40 */  1023,  -72, 1041,  395,  -72,  -72,  -72,  -72,  -72,  -72,
 /*    50 */   -72,  807, 1023,  -72, 1124,  -72,  560,  -72,  -72, 1138,
 /*    60 */   522, 1023, 1094,  -72,  -72,  -72,  -72, 1023,  -72, 1176,
 /*    70 */  1045,   30,  873, 1088, 1098,  -72,  884,  -72,  388, 1114,
 /*    80 */   -72,  310,  -72,  -19, 1107, 1115, 1118, 1125, 1127,  -72,
 /*    90 */  1045,   40, 1045,  665, 1045,  -72, 1132,  400, 1133,  400,
 /*   100 */   -72,  -72,  -72,  -72,  -72,  -72, 1232, 1045,  105,  402,
 /*   110 */   -72,  -72,  340,  630,  790,  -72,  630, 1246,  -72,  -72,
 /*   120 */   -72,  679,  -72,  -72,  -72,  679,  -72,  -72,  -72,  -72,
 /*   130 */  1248,  -72, 1045,  -72,  759, 1045,  -11, 1045,  -11, 1045,
 /*   140 */   -11, 1045,  -11, 1045,  -71, 1045,  -71, 1045,  -50, 1045,
 /*   150 */   -50, 1045,  -50, 1045,  -50, 1045,  168, 1045,  168, 1045,
 /*   160 */  1186, 1045, 1186, 1045, 1186, 1045,  -72,  -72,  441,  -72,
 /*   170 */   -72,  -72,  -72, 1045,  -56, 1045,  -11,  -72,  846,  -72,
 /*   180 */  1180,  -72,  -72,  -72, 1045,  712, 1045,  -71,  -72,  289,
 /*   190 */   884,  393,  700, 1162, 1164, 1165,  -72,  665, 1045,  806,
 /*   200 */  1045,  -72, 1045,  -72, 1045,  -72, 1258, 1114,  401,  -72,
 /*   210 */   958,  152, 1146,  416, 1268,  -72, 1045,  199, 1045,  665,
 /*   220 */  1264,  530, 1266,  -72, 1262,  400, 1269,  -72, 1045,  273,
 /*   230 */  1045,  320, 1045,  665,  793,  -72, 1045,  -72,  -72, 1175,
 /*   240 */   400,  -72,  -72,  -72,  806, 1045,  665, 1173, 1045, 1271,
 /*   250 */  1045, 1197,  522,  -72, 1274,  -72,  -72,  665, 1197,  522,
 /*   260 */   -72, 1045,  665, 1181, 1045, 1276, 1045,  665,  -72,  -72,
 /*   270 */   635,  -72,  -72,  -72,  458,  -72,  463,  -72, 1191,  -72,
 /*   280 */   534, 1175,  779,  400,  -72,  -72, 1210, 1195,  -72, 1294,
 /*   290 */   400,  829,  -72,  400,  -72,  -72, 1045,  665, 1114,  467,
 /*   300 */   279, 1296,  779, 1210, 1195,  -72, 1017,  -25,  -72,  -72,
 /*   310 */  1205,  536,  -72,  -72,  -72,  -72,  394,  -72,  837,  -72,
 /*   320 */  1300,  -72,  459, 1023,  -72,  400, 1304,  -72,  112,  -72,
 /*   330 */   400,  -72,  619,  662,  -72,  832,  -72,  -72,  -72,  -72,
 /*   340 */   662,  -72,  662,  -72,  400,  919,  -72,  400, 1197,  522,
 /*   350 */   -72,  -72, 1197,  522,  -72,  -72, 1274,  -72, 1124,  -72,
 /*   360 */   -72,   70,  -72, 1045,  524,  -72,  239,  -72,  -72,  239,
 /*   370 */   -72,  -72,  -72,  -72,   58,  149,  -72,  400,  -72, 1290,
 /*   380 */  1318,  400,   59, 1322, 1023,  -72, 1324,  400,  929, 1023,
 /*   390 */   -72, 1045,  571,  -72, 1301, 1325,  400,  948, 1250,  400,
 /*   400 */  1304,  -72,  517, 1245,  -72,  -72,  -72,  -72,  -72, 1114,
 /*   410 */   552,  843,  754,  400, 1175,  -72,  400,  140, 1339, 1114,
 /*   420 */   556,  400, 1175,  869,  657, 1267,  400, 1175,  -72, 1327,
 /*   430 */   850, 1361, 1045,  618, 1335,  942,  -72,  -72, 1273, 1275,
 /*   440 */   875,  400,  962,  -72,  -72, 1328,  -72,  -72, 1240,  400,
 /*   450 */   906, 1279,  400, 1362,  400, 1001,  761, 1374, 1247, 1376,
 /*   460 */   189,  562,  968,  395,  -72, 1263, 1265, 1373, 1383, 1384,
 /*   470 */   189, 1377, 1332,  400, 1291,  400,  792,  400, 1326, 1045,
 /*   480 */   665, 1390, 1331, 1045,  665, 1278,  400, 1385,  400, 1007,
 /*   490 */   -72,  984,  604, 1386, 1045, 1012, 1045,  665, 1400,  665,
 /*   500 */  1293,  400, 1033, 1404,  651,  400, 1405,  400, 1406,  400,
 /*   510 */  1407,  400, 1408,  566, 1302,  400, 1033, 1411, 1332,  400,
 /*   520 */  1316,  400,  792, 1415, 1299,  400, 1385, 1016,  608, 1409,
 /*   530 */  1045, 1129, 1417,  476, 1418,  400, 1175,  697,  111, 1420,
 /*   540 */  1421, 1424, 1427,  400, 1416, 1429, 1410,  402, 1419,  400,
 /*   550 */  1025, 1432,  729, 1433, 1435,  -72, 1410,  400, 1441,  839,
 /*   560 */   981, 1442,  841,  981, 1443, 1439,  400, 1021, 1321,  400,
 /*   570 */  1446, 1323, 1329,  400, 1456,  -72,  -72,  -72,
};
#define YY_REDUCE_USE_DFLT (-151)
static const short yy_reduce_ofst[] = {
 /*     0 */    64,   95, -151, -151,  -59, -151, -151, -151,   33,  155,
 /*    10 */  -151,  224, -151, -151, -151, -151, -151, -151, -151,  428,
 /*    20 */  -151,  509, -151,  758, -151,  430, -151,   45,  771, -151,
 /*    30 */  -151,  -21, -151,  -64,  865,  244, -151,  910,  -85, -151,
 /*    40 */   895, -151, -151, -125, -151, -151, -151, -151, -151, -151,
 /*    50 */  -151, -151, 1010, -151, 1000, -151, -151, -151, -151, -151,
 /*    60 */  1011, 1022, 1024, -151, -151, -151, -151, 1028, -151, -151,
 /*    70 */   125, -151,  156, -151, -151, -151,  159, -151, 1037, 1039,
 /*    80 */  -151, 1040,  420, 1014, 1047, 1042, 1049, 1051, 1055, -151,
 /*    90 */   348,  411,  450,  411,  649, -151, -151, 1105, -151, 1119,
 /*   100 */  -151, -151, -151, -151, -151, -151, -151,  685,  411,  254,
 /*   110 */  -151, -151, 1108, -150, -151, -151,  -34, -151, -151, -151,
 /*   120 */  -151, 1044, -151, -151, -151, 1053, -151, -151, -151, -151,
 /*   130 */  -151, -151,  696, -151,  411,  732,  411,  743,  411,  747,
 /*   140 */   411,  749,  411,  778,  411,  786,  411,  788,  411,  797,
 /*   150 */   411,  827,  411,  838,  411,  874,  411,  882,  411,  885,
 /*   160 */   411,  887,  411,  893,  411,  901,  411, -151, -151, -151,
 /*   170 */  -151, -151, -151,  932,   39,  951,  411, -151, -151, -151,
 /*   180 */  -151, -151, -151, -151,  991,  411, 1008,  411, -151, 1126,
 /*   190 */   912, 1037, -151, -151, -151, -151, -151,  411, 1015,  411,
 /*   200 */  1018,  411, 1020,  411, 1038,  411, -151,  745, 1037, -151,
 /*   210 */   343,  411, 1058, 1059, -151, -151, 1043,  411, 1046,  411,
 /*   220 */  -151, 1099, -151, -151, -151, 1139, -151, -151, 1048,  411,
 /*   230 */  1050,  411, 1052,  411, -151, -151,  257, -151, -151, 1140,
 /*   240 */  1142, -151, -151, -151,  411, 1054,  411, -151,  276, -151,
 /*   250 */   346, 1086, 1123, -151, 1141, -151, -151,  411, 1090, 1130,
 /*   260 */  -151, 1062,  411, -151,  281, -151, 1080,  411, -151,  652,
 /*   270 */  1101, -151, -151, -151, 1156, -151, 1157, -151, -151, -151,
 /*   280 */  1159, 1158,  506, 1160, -151, -151, 1109, 1110, -151, -151,
 /*   290 */    78, -151, -151, 1167, -151, -151, 1085,  411,  -63, 1037,
 /*   300 */  1101, -151,  789, 1116, 1113, -151, 1087,   87, -151, -151,
 /*   310 */  -151, 1105, -151, -151, -151, -151,  411, -151, -151, -151,
 /*   320 */  -151, -151,  411, 1150, -151, 1174, 1151, 1149, 1152, -151,
 /*   330 */  1178, -151, -151, 1153, -151, -151, -151, -151, -151, -151,
 /*   340 */  1154, -151, 1155, -151,  433, -151, -151,  715, 1117, 1163,
 /*   350 */  -151, -151, 1120, 1166, -151, -151, 1168, -151, 1161, -151,
 /*   360 */  -151,  593, -151, 1089,  411, -151, 1170, -151, -151, 1172,
 /*   370 */  -151, -151, -151, -151, 1169, 1171, -151, 1188, -151, -151,
 /*   380 */  -151,  526, 1182, -151, 1177, -151, -151,  574, -151, 1183,
 /*   390 */  -151, 1091,  142, -151, -151, -151,  621, -151, -151, 1199,
 /*   400 */  1179, 1184,  193, -151, -151, -151, -151, -151, -151,  804,
 /*   410 */  1037,  755, -151, 1203, 1204, -151, 1209, 1206, -151,  830,
 /*   420 */  1037, 1213, 1211, 1134, 1131, -151,  261, 1215, -151, 1136,
 /*   430 */  1137, -151,  774,  411, -151, -151, -151, -151, -151, -151,
 /*   440 */  -151,  516, -151, -151, -151, -151, -151, -151, -151, 1228,
 /*   450 */  1225, -151, 1231, -151,  668, -151, 1212, -151, -151, -151,
 /*   460 */   218, 1037, 1201,  840, -151, -151, -151, -151, -151, -151,
 /*   470 */   280, -151, 1214, 1249, -151,  295, 1200, 1251, -151,  821,
 /*   480 */   411, -151, -151, 1093,  411, -151, 1254, 1189,  905, -151,
 /*   490 */  -151,  904, 1037, -151,  413, -151, 1095,  411, -151,  411,
 /*   500 */  -151, 1260, 1216, -151, -151,  926, -151,  966, -151,  967,
 /*   510 */  -151,  978, -151, 1037, -151,  980, 1222, -151, 1234,  982,
 /*   520 */  -151,  924, 1227, -151, -151,  993, 1217,  922, 1037, -151,
 /*   530 */   591, -151, -151, 1277, -151, 1281, 1280, -151,  145, -151,
 /*   540 */  -151, -151, -151, 1286, -151, -151, 1202, 1283, -151, 1297,
 /*   550 */  1218, -151, 1285, -151, -151, -151, 1207, 1303, -151, 1305,
 /*   560 */  1298, -151, 1307, 1306, -151, -151,  -73, -151, -151, 1311,
 /*   570 */  -151, -151, 1223,  607, -151, -151, -151, -151,
};
static const YYACTIONTYPE yy_default[] = {
 /*     0 */   584,  584,  579,  582,  888,  888,  888,  583,  590,  888,
 /*    10 */   888,  888,  888,  610,  611,  612,  591,  592,  593,  888,
 /*    20 */   888,  888,  888,  888,  888,  888,  888,  888,  888,  888,
 /*    30 */   888,  888,  603,  613,  623,  605,  622,  888,  888,  624,
 /*    40 */   668,  631,  888,  888,  669,  672,  673,  674,  868,  869,
 /*    50 */   870,  888,  668,  632,  653,  651,  888,  654,  655,  888,
 /*    60 */   724,  668,  639,  633,  640,  722,  723,  668,  634,  888,
 /*    70 */   888,  754,  820,  760,  755,  751,  888,  679,  888,  888,
 /*    80 */   680,  688,  690,  697,  736,  727,  729,  717,  731,  685,
 /*    90 */   888,  732,  888,  733,  888,  753,  888,  888,  756,  888,
 /*   100 */   757,  758,  759,  761,  762,  763,  888,  888,  888,  888,
 /*   110 */   608,  609,  615,  843,  888,  616,  843,  888,  617,  620,
 /*   120 */   621,  888,  838,  840,  841,  888,  839,  842,  619,  618,
 /*   130 */   888,  764,  888,  767,  769,  888,  770,  888,  771,  888,
 /*   140 */   772,  888,  773,  888,  774,  888,  775,  888,  776,  888,
 /*   150 */   777,  888,  778,  888,  779,  888,  780,  888,  781,  888,
 /*   160 */   782,  888,  783,  888,  784,  888,  785,  786,  888,  787,
 /*   170 */   794,  801,  804,  888,  789,  888,  788,  791,  888,  792,
 /*   180 */   888,  795,  793,  800,  888,  888,  888,  802,  803,  888,
 /*   190 */   820,  888,  888,  888,  888,  888,  807,  819,  888,  796,
 /*   200 */   888,  797,  888,  798,  888,  799,  888,  888,  888,  809,
 /*   210 */   888,  888,  888,  888,  888,  810,  888,  888,  888,  811,
 /*   220 */   888,  888,  888,  866,  888,  888,  888,  867,  888,  888,
 /*   230 */   888,  888,  888,  812,  888,  805,  820,  817,  818,  705,
 /*   240 */   888,  706,  808,  790,  768,  888,  734,  888,  888,  718,
 /*   250 */   888,  725,  724,  719,  888,  607,  726,  721,  725,  724,
 /*   260 */   720,  888,  730,  888,  820,  728,  888,  737,  689,  700,
 /*   270 */   698,  699,  708,  709,  888,  710,  888,  711,  888,  712,
 /*   280 */   888,  705,  696,  888,  694,  695,  714,  716,  701,  888,
 /*   290 */   888,  888,  715,  888,  749,  750,  888,  713,  700,  888,
 /*   300 */   888,  888,  696,  714,  716,  702,  888,  696,  691,  692,
 /*   310 */   888,  888,  693,  686,  687,  806,  888,  752,  888,  765,
 /*   320 */   888,  766,  888,  668,  635,  888,  824,  641,  636,  642,
 /*   330 */   888,  643,  888,  888,  644,  888,  647,  648,  649,  650,
 /*   340 */   888,  645,  888,  646,  888,  888,  825,  888,  725,  724,
 /*   350 */   826,  828,  725,  724,  827,  637,  888,  638,  653,  652,
 /*   360 */   625,  888,  626,  888,  888,  627,  888,  628,  760,  888,
 /*   370 */   629,  630,  614,  606,  888,  888,  658,  888,  661,  888,
 /*   380 */   888,  888,  888,  888,  668,  662,  888,  888,  888,  668,
 /*   390 */   663,  888,  668,  664,  888,  888,  888,  888,  888,  888,
 /*   400 */   824,  641,  666,  888,  665,  667,  659,  660,  604,  888,
 /*   410 */   888,  600,  888,  888,  705,  598,  888,  888,  888,  888,
 /*   420 */   888,  888,  705,  849,  888,  888,  888,  705,  707,  854,
 /*   430 */   888,  888,  888,  888,  888,  888,  855,  856,  888,  888,
 /*   440 */   888,  888,  888,  846,  847,  888,  848,  599,  888,  888,
 /*   450 */   888,  888,  888,  888,  888,  888,  888,  888,  888,  888,
 /*   460 */   888,  888,  888,  888,  671,  888,  888,  888,  888,  888,
 /*   470 */   888,  888,  670,  888,  888,  888,  888,  888,  888,  888,
 /*   480 */   739,  888,  888,  888,  740,  888,  888,  747,  888,  888,
 /*   490 */   748,  888,  888,  888,  888,  888,  888,  745,  888,  746,
 /*   500 */   888,  888,  888,  888,  888,  888,  888,  888,  888,  888,
 /*   510 */   888,  888,  888,  888,  888,  888,  888,  888,  670,  888,
 /*   520 */   888,  888,  888,  888,  888,  888,  747,  888,  888,  888,
 /*   530 */   888,  888,  888,  888,  888,  888,  705,  888,  843,  888,
 /*   540 */   888,  888,  888,  888,  888,  888,  877,  888,  888,  888,
 /*   550 */   888,  888,  888,  888,  888,  876,  877,  888,  888,  888,
 /*   560 */   888,  888,  888,  888,  888,  888,  888,  888,  888,  888,
 /*   570 */   888,  888,  886,  888,  888,  887,  585,  580,
};
#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))

/* The next table maps tokens into fallback tokens.  If a construct
** like the following:
** 
**      %fallback ID X Y Z.
................................................................................
    0,  /*    ILLEGAL => nothing */
    0,  /*      SPACE => nothing */
    0,  /* UNCLOSED_STRING => nothing */
    0,  /*    COMMENT => nothing */
    0,  /*   FUNCTION => nothing */
    0,  /*     COLUMN => nothing */
    0,  /* AGG_FUNCTION => nothing */

    0,  /* CONST_FUNC => nothing */
    0,  /*       SEMI => nothing */
   27,  /*    EXPLAIN => ID */


   27,  /*      BEGIN => ID */
    0,  /* TRANSACTION => nothing */
   27,  /*   DEFERRED => ID */
   27,  /*  IMMEDIATE => ID */
   27,  /*  EXCLUSIVE => ID */
    0,  /*     COMMIT => nothing */
   27,  /*        END => ID */
    0,  /*   ROLLBACK => nothing */
    0,  /*     CREATE => nothing */
    0,  /*      TABLE => nothing */
   27,  /*       TEMP => ID */
    0,  /*         LP => nothing */
    0,  /*         RP => nothing */
    0,  /*         AS => nothing */
    0,  /*      COMMA => nothing */
    0,  /*         ID => nothing */
   27,  /*      ABORT => ID */
   27,  /*      AFTER => ID */
   27,  /*    ANALYZE => ID */
   27,  /*        ASC => ID */
   27,  /*     ATTACH => ID */
   27,  /*     BEFORE => ID */
   27,  /*    CASCADE => ID */
   27,  /*       CAST => ID */
   27,  /*   CONFLICT => ID */
   27,  /*   DATABASE => ID */
   27,  /*       DESC => ID */
   27,  /*     DETACH => ID */
   27,  /*       EACH => ID */
   27,  /*       FAIL => ID */
   27,  /*        FOR => ID */
   27,  /*     IGNORE => ID */
   27,  /*  INITIALLY => ID */
   27,  /*    INSTEAD => ID */
   27,  /*    LIKE_KW => ID */
   27,  /*      MATCH => ID */
   27,  /*        KEY => ID */
   27,  /*         OF => ID */
   27,  /*     OFFSET => ID */
   27,  /*     PRAGMA => ID */
   27,  /*      RAISE => ID */
   27,  /*    REPLACE => ID */
   27,  /*   RESTRICT => ID */
   27,  /*        ROW => ID */
   27,  /*  STATEMENT => ID */
   27,  /*    TRIGGER => ID */
   27,  /*     VACUUM => ID */
   27,  /*       VIEW => ID */
   27,  /*    REINDEX => ID */
   27,  /*     RENAME => ID */
   27,  /*   CTIME_KW => ID */
   27,  /*      ALTER => ID */
    0,  /*         OR => nothing */
    0,  /*        AND => nothing */
    0,  /*        NOT => nothing */
    0,  /*         IS => nothing */
    0,  /*    BETWEEN => nothing */
    0,  /*         IN => nothing */
    0,  /*     ISNULL => nothing */
................................................................................

#ifndef NDEBUG
/* For tracing shifts, the names of all terminals and nonterminals
** are required.  The following table supplies these names */
static const char *const yyTokenName[] = { 
  "$",             "END_OF_FILE",   "ILLEGAL",       "SPACE",       
  "UNCLOSED_STRING",  "COMMENT",       "FUNCTION",      "COLUMN",      
  "AGG_FUNCTION",  "CONST_FUNC",    "SEMI",          "EXPLAIN",     

  "BEGIN",         "TRANSACTION",   "DEFERRED",      "IMMEDIATE",   
  "EXCLUSIVE",     "COMMIT",        "END",           "ROLLBACK",    
  "CREATE",        "TABLE",         "TEMP",          "LP",          
  "RP",            "AS",            "COMMA",         "ID",          
  "ABORT",         "AFTER",         "ANALYZE",       "ASC",         
  "ATTACH",        "BEFORE",        "CASCADE",       "CAST",        
  "CONFLICT",      "DATABASE",      "DESC",          "DETACH",      
  "EACH",          "FAIL",          "FOR",           "IGNORE",      
  "INITIALLY",     "INSTEAD",       "LIKE_KW",       "MATCH",       
  "KEY",           "OF",            "OFFSET",        "PRAGMA",      
  "RAISE",         "REPLACE",       "RESTRICT",      "ROW",         
  "STATEMENT",     "TRIGGER",       "VACUUM",        "VIEW",        
  "REINDEX",       "RENAME",        "CTIME_KW",      "ALTER",       
  "OR",            "AND",           "NOT",           "IS",          
  "BETWEEN",       "IN",            "ISNULL",        "NOTNULL",     
  "NE",            "EQ",            "GT",            "LE",          
  "LT",            "GE",            "ESCAPE",        "BITAND",      
  "BITOR",         "LSHIFT",        "RSHIFT",        "PLUS",        
  "MINUS",         "STAR",          "SLASH",         "REM",         
  "CONCAT",        "UMINUS",        "UPLUS",         "BITNOT",      
  "STRING",        "JOIN_KW",       "CONSTRAINT",    "DEFAULT",     
  "NULL",          "PRIMARY",       "UNIQUE",        "CHECK",       
  "REFERENCES",    "COLLATE",       "AUTOINCR",      "ON",          
  "DELETE",        "UPDATE",        "INSERT",        "SET",         
  "DEFERRABLE",    "FOREIGN",       "DROP",          "UNION",       
  "ALL",           "INTERSECT",     "EXCEPT",        "SELECT",      
  "DISTINCT",      "DOT",           "FROM",          "JOIN",        
  "USING",         "ORDER",         "BY",            "GROUP",       
  "HAVING",        "LIMIT",         "WHERE",         "INTO",        
  "VALUES",        "INTEGER",       "FLOAT",         "BLOB",        
  "REGISTER",      "VARIABLE",      "EXISTS",        "CASE",        
  "WHEN",          "THEN",          "ELSE",          "INDEX",       
  "TO",            "ADD",           "COLUMNKW",      "error",       
  "input",         "cmdlist",       "ecmd",          "cmdx",        
  "cmd",           "explain",       "transtype",     "trans_opt",   
  "nm",            "create_table",  "create_table_args",  "temp",        
  "dbnm",          "columnlist",    "conslist_opt",  "select",      
  "column",        "columnid",      "type",          "carglist",    
  "id",            "ids",           "typetoken",     "typename",    
  "signed",        "plus_num",      "minus_num",     "carg",        
  "ccons",         "term",          "expr",          "onconf",      
  "sortorder",     "autoinc",       "idxlist_opt",   "refargs",     
  "defer_subclause",  "refarg",        "refact",        "init_deferred_pred_opt",
  "conslist",      "tcons",         "idxlist",       "defer_subclause_opt",
  "orconf",        "resolvetype",   "raisetype",     "fullname",    
  "oneselect",     "multiselect_op",  "distinct",      "selcollist",  
  "from",          "where_opt",     "groupby_opt",   "having_opt",  
  "orderby_opt",   "limit_opt",     "sclp",          "as",          
  "seltablist",    "stl_prefix",    "joinop",        "on_opt",      
  "using_opt",     "seltablist_paren",  "joinop2",       "inscollist",  
  "sortlist",      "sortitem",      "collate",       "exprlist",    
  "setlist",       "insert_cmd",    "inscollist_opt",  "itemlist",    
  "likeop",        "escape",        "between_op",    "in_op",       
  "case_operand",  "case_exprlist",  "case_else",     "expritem",    
  "uniqueflag",    "idxitem",       "plus_opt",      "number",      
  "trigger_decl",  "trigger_cmd_list",  "trigger_time",  "trigger_event",
  "foreach_clause",  "when_clause",   "trigger_cmd",   "database_kw_opt",
  "key_opt",       "add_column_fullname",  "kwcolumn_opt",
};
#endif /* NDEBUG */

#ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *const yyRuleName[] = {
................................................................................
 /*   1 */ "cmdlist ::= cmdlist ecmd",
 /*   2 */ "cmdlist ::= ecmd",
 /*   3 */ "cmdx ::= cmd",
 /*   4 */ "ecmd ::= SEMI",
 /*   5 */ "ecmd ::= explain cmdx SEMI",
 /*   6 */ "explain ::=",
 /*   7 */ "explain ::= EXPLAIN",

 /*   8 */ "cmd ::= BEGIN transtype trans_opt",
 /*   9 */ "trans_opt ::=",
 /*  10 */ "trans_opt ::= TRANSACTION",
 /*  11 */ "trans_opt ::= TRANSACTION nm",
 /*  12 */ "transtype ::=",
 /*  13 */ "transtype ::= DEFERRED",
 /*  14 */ "transtype ::= IMMEDIATE",
 /*  15 */ "transtype ::= EXCLUSIVE",
 /*  16 */ "cmd ::= COMMIT trans_opt",
 /*  17 */ "cmd ::= END trans_opt",
 /*  18 */ "cmd ::= ROLLBACK trans_opt",
 /*  19 */ "cmd ::= create_table create_table_args",
 /*  20 */ "create_table ::= CREATE temp TABLE nm dbnm",
 /*  21 */ "temp ::= TEMP",
 /*  22 */ "temp ::=",
 /*  23 */ "create_table_args ::= LP columnlist conslist_opt RP",
 /*  24 */ "create_table_args ::= AS select",
 /*  25 */ "columnlist ::= columnlist COMMA column",
 /*  26 */ "columnlist ::= column",
 /*  27 */ "column ::= columnid type carglist",
 /*  28 */ "columnid ::= nm",
 /*  29 */ "id ::= ID",
 /*  30 */ "ids ::= ID",
 /*  31 */ "ids ::= STRING",
 /*  32 */ "nm ::= ID",
 /*  33 */ "nm ::= STRING",
 /*  34 */ "nm ::= JOIN_KW",
 /*  35 */ "type ::=",
 /*  36 */ "type ::= typetoken",
 /*  37 */ "typetoken ::= typename",
 /*  38 */ "typetoken ::= typename LP signed RP",
 /*  39 */ "typetoken ::= typename LP signed COMMA signed RP",
 /*  40 */ "typename ::= ids",
 /*  41 */ "typename ::= typename ids",
 /*  42 */ "signed ::= plus_num",
 /*  43 */ "signed ::= minus_num",
 /*  44 */ "carglist ::= carglist carg",
 /*  45 */ "carglist ::=",
 /*  46 */ "carg ::= CONSTRAINT nm ccons",
 /*  47 */ "carg ::= ccons",
 /*  48 */ "carg ::= DEFAULT term",
 /*  49 */ "carg ::= DEFAULT LP expr RP",
 /*  50 */ "carg ::= DEFAULT PLUS term",
 /*  51 */ "carg ::= DEFAULT MINUS term",
 /*  52 */ "carg ::= DEFAULT id",
 /*  53 */ "ccons ::= NULL onconf",
 /*  54 */ "ccons ::= NOT NULL onconf",
 /*  55 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
 /*  56 */ "ccons ::= UNIQUE onconf",
 /*  57 */ "ccons ::= CHECK LP expr RP onconf",
 /*  58 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
 /*  59 */ "ccons ::= defer_subclause",
 /*  60 */ "ccons ::= COLLATE id",
 /*  61 */ "autoinc ::=",
 /*  62 */ "autoinc ::= AUTOINCR",
 /*  63 */ "refargs ::=",
 /*  64 */ "refargs ::= refargs refarg",
 /*  65 */ "refarg ::= MATCH nm",
 /*  66 */ "refarg ::= ON DELETE refact",
 /*  67 */ "refarg ::= ON UPDATE refact",
 /*  68 */ "refarg ::= ON INSERT refact",
 /*  69 */ "refact ::= SET NULL",
 /*  70 */ "refact ::= SET DEFAULT",
 /*  71 */ "refact ::= CASCADE",
 /*  72 */ "refact ::= RESTRICT",
 /*  73 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
 /*  74 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
 /*  75 */ "init_deferred_pred_opt ::=",
 /*  76 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
 /*  77 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
 /*  78 */ "conslist_opt ::=",
 /*  79 */ "conslist_opt ::= COMMA conslist",
 /*  80 */ "conslist ::= conslist COMMA tcons",
 /*  81 */ "conslist ::= conslist tcons",
 /*  82 */ "conslist ::= tcons",
 /*  83 */ "tcons ::= CONSTRAINT nm",
 /*  84 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
 /*  85 */ "tcons ::= UNIQUE LP idxlist RP onconf",
 /*  86 */ "tcons ::= CHECK expr onconf",
 /*  87 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
 /*  88 */ "defer_subclause_opt ::=",
 /*  89 */ "defer_subclause_opt ::= defer_subclause",
 /*  90 */ "onconf ::=",
 /*  91 */ "onconf ::= ON CONFLICT resolvetype",
 /*  92 */ "orconf ::=",
 /*  93 */ "orconf ::= OR resolvetype",
 /*  94 */ "resolvetype ::= raisetype",
 /*  95 */ "resolvetype ::= IGNORE",
 /*  96 */ "resolvetype ::= REPLACE",
 /*  97 */ "cmd ::= DROP TABLE fullname",
 /*  98 */ "cmd ::= CREATE temp VIEW nm dbnm AS select",
 /*  99 */ "cmd ::= DROP VIEW fullname",
 /* 100 */ "cmd ::= select",
 /* 101 */ "select ::= oneselect",
 /* 102 */ "select ::= select multiselect_op oneselect",
 /* 103 */ "multiselect_op ::= UNION",
 /* 104 */ "multiselect_op ::= UNION ALL",
 /* 105 */ "multiselect_op ::= INTERSECT",
 /* 106 */ "multiselect_op ::= EXCEPT",
 /* 107 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
 /* 108 */ "distinct ::= DISTINCT",
 /* 109 */ "distinct ::= ALL",
 /* 110 */ "distinct ::=",
 /* 111 */ "sclp ::= selcollist COMMA",
 /* 112 */ "sclp ::=",
 /* 113 */ "selcollist ::= sclp expr as",
 /* 114 */ "selcollist ::= sclp STAR",
 /* 115 */ "selcollist ::= sclp nm DOT STAR",
 /* 116 */ "as ::= AS nm",
 /* 117 */ "as ::= ids",
 /* 118 */ "as ::=",
 /* 119 */ "from ::=",
 /* 120 */ "from ::= FROM seltablist",
 /* 121 */ "stl_prefix ::= seltablist joinop",
 /* 122 */ "stl_prefix ::=",
 /* 123 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt",
 /* 124 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt",
 /* 125 */ "seltablist_paren ::= select",
 /* 126 */ "seltablist_paren ::= seltablist",
 /* 127 */ "dbnm ::=",
 /* 128 */ "dbnm ::= DOT nm",
 /* 129 */ "fullname ::= nm dbnm",
 /* 130 */ "joinop ::= COMMA",
 /* 131 */ "joinop ::= JOIN",
 /* 132 */ "joinop ::= JOIN_KW JOIN",
 /* 133 */ "joinop ::= JOIN_KW nm JOIN",
 /* 134 */ "joinop ::= JOIN_KW nm nm JOIN",
 /* 135 */ "on_opt ::= ON expr",
 /* 136 */ "on_opt ::=",
 /* 137 */ "using_opt ::= USING LP inscollist RP",
 /* 138 */ "using_opt ::=",
 /* 139 */ "orderby_opt ::=",
 /* 140 */ "orderby_opt ::= ORDER BY sortlist",
 /* 141 */ "sortlist ::= sortlist COMMA sortitem collate sortorder",
 /* 142 */ "sortlist ::= sortitem collate sortorder",
 /* 143 */ "sortitem ::= expr",
 /* 144 */ "sortorder ::= ASC",
 /* 145 */ "sortorder ::= DESC",
 /* 146 */ "sortorder ::=",
 /* 147 */ "collate ::=",
 /* 148 */ "collate ::= COLLATE id",
 /* 149 */ "groupby_opt ::=",
 /* 150 */ "groupby_opt ::= GROUP BY exprlist",
 /* 151 */ "having_opt ::=",
 /* 152 */ "having_opt ::= HAVING expr",
 /* 153 */ "limit_opt ::=",
 /* 154 */ "limit_opt ::= LIMIT expr",
 /* 155 */ "limit_opt ::= LIMIT expr OFFSET expr",
 /* 156 */ "limit_opt ::= LIMIT expr COMMA expr",
 /* 157 */ "cmd ::= DELETE FROM fullname where_opt",
 /* 158 */ "where_opt ::=",
 /* 159 */ "where_opt ::= WHERE expr",
 /* 160 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt",
 /* 161 */ "setlist ::= setlist COMMA nm EQ expr",
 /* 162 */ "setlist ::= nm EQ expr",
 /* 163 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
 /* 164 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
 /* 165 */ "insert_cmd ::= INSERT orconf",
 /* 166 */ "insert_cmd ::= REPLACE",
 /* 167 */ "itemlist ::= itemlist COMMA expr",
 /* 168 */ "itemlist ::= expr",
 /* 169 */ "inscollist_opt ::=",
 /* 170 */ "inscollist_opt ::= LP inscollist RP",
 /* 171 */ "inscollist ::= inscollist COMMA nm",
 /* 172 */ "inscollist ::= nm",
 /* 173 */ "expr ::= term",
 /* 174 */ "expr ::= LP expr RP",
 /* 175 */ "term ::= NULL",
 /* 176 */ "expr ::= ID",
 /* 177 */ "expr ::= JOIN_KW",
 /* 178 */ "expr ::= nm DOT nm",
 /* 179 */ "expr ::= nm DOT nm DOT nm",
 /* 180 */ "term ::= INTEGER",
 /* 181 */ "term ::= FLOAT",
 /* 182 */ "term ::= STRING",
 /* 183 */ "term ::= BLOB",
 /* 184 */ "expr ::= REGISTER",
 /* 185 */ "expr ::= VARIABLE",
 /* 186 */ "expr ::= CAST LP expr AS typetoken RP",
 /* 187 */ "expr ::= ID LP exprlist RP",
 /* 188 */ "expr ::= ID LP STAR RP",
 /* 189 */ "term ::= CTIME_KW",
 /* 190 */ "expr ::= expr AND expr",
 /* 191 */ "expr ::= expr OR expr",
 /* 192 */ "expr ::= expr LT expr",
 /* 193 */ "expr ::= expr GT expr",
 /* 194 */ "expr ::= expr LE expr",
 /* 195 */ "expr ::= expr GE expr",
 /* 196 */ "expr ::= expr NE expr",
 /* 197 */ "expr ::= expr EQ expr",
 /* 198 */ "expr ::= expr BITAND expr",
 /* 199 */ "expr ::= expr BITOR expr",
 /* 200 */ "expr ::= expr LSHIFT expr",
 /* 201 */ "expr ::= expr RSHIFT expr",
 /* 202 */ "expr ::= expr PLUS expr",
 /* 203 */ "expr ::= expr MINUS expr",
 /* 204 */ "expr ::= expr STAR expr",
 /* 205 */ "expr ::= expr SLASH expr",
 /* 206 */ "expr ::= expr REM expr",
 /* 207 */ "expr ::= expr CONCAT expr",
 /* 208 */ "likeop ::= LIKE_KW",
 /* 209 */ "likeop ::= NOT LIKE_KW",
 /* 210 */ "escape ::= ESCAPE expr",
 /* 211 */ "escape ::=",
 /* 212 */ "expr ::= expr likeop expr escape",
 /* 213 */ "expr ::= expr ISNULL",
 /* 214 */ "expr ::= expr IS NULL",
 /* 215 */ "expr ::= expr NOTNULL",
 /* 216 */ "expr ::= expr NOT NULL",
 /* 217 */ "expr ::= expr IS NOT NULL",
 /* 218 */ "expr ::= NOT expr",
 /* 219 */ "expr ::= BITNOT expr",
 /* 220 */ "expr ::= MINUS expr",
 /* 221 */ "expr ::= PLUS expr",
 /* 222 */ "between_op ::= BETWEEN",
 /* 223 */ "between_op ::= NOT BETWEEN",
 /* 224 */ "expr ::= expr between_op expr AND expr",
 /* 225 */ "in_op ::= IN",
 /* 226 */ "in_op ::= NOT IN",
 /* 227 */ "expr ::= expr in_op LP exprlist RP",
 /* 228 */ "expr ::= LP select RP",
 /* 229 */ "expr ::= expr in_op LP select RP",
 /* 230 */ "expr ::= expr in_op nm dbnm",
 /* 231 */ "expr ::= EXISTS LP select RP",
 /* 232 */ "expr ::= CASE case_operand case_exprlist case_else END",
 /* 233 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
 /* 234 */ "case_exprlist ::= WHEN expr THEN expr",
 /* 235 */ "case_else ::= ELSE expr",
 /* 236 */ "case_else ::=",
 /* 237 */ "case_operand ::= expr",
 /* 238 */ "case_operand ::=",
 /* 239 */ "exprlist ::= exprlist COMMA expritem",
 /* 240 */ "exprlist ::= expritem",
 /* 241 */ "expritem ::= expr",
 /* 242 */ "expritem ::=",
 /* 243 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf",
 /* 244 */ "uniqueflag ::= UNIQUE",
 /* 245 */ "uniqueflag ::=",
 /* 246 */ "idxlist_opt ::=",
 /* 247 */ "idxlist_opt ::= LP idxlist RP",
 /* 248 */ "idxlist ::= idxlist COMMA idxitem collate sortorder",
 /* 249 */ "idxlist ::= idxitem collate sortorder",
 /* 250 */ "idxitem ::= nm",
 /* 251 */ "cmd ::= DROP INDEX fullname",
 /* 252 */ "cmd ::= VACUUM",
 /* 253 */ "cmd ::= VACUUM nm",
 /* 254 */ "cmd ::= PRAGMA nm dbnm EQ nm",
 /* 255 */ "cmd ::= PRAGMA nm dbnm EQ ON",
 /* 256 */ "cmd ::= PRAGMA nm dbnm EQ plus_num",
 /* 257 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
 /* 258 */ "cmd ::= PRAGMA nm dbnm LP nm RP",
 /* 259 */ "cmd ::= PRAGMA nm dbnm",
 /* 260 */ "plus_num ::= plus_opt number",
 /* 261 */ "minus_num ::= MINUS number",
 /* 262 */ "number ::= INTEGER",
 /* 263 */ "number ::= FLOAT",
 /* 264 */ "plus_opt ::= PLUS",
 /* 265 */ "plus_opt ::=",
 /* 266 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
 /* 267 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
 /* 268 */ "trigger_time ::= BEFORE",
 /* 269 */ "trigger_time ::= AFTER",
 /* 270 */ "trigger_time ::= INSTEAD OF",
 /* 271 */ "trigger_time ::=",
 /* 272 */ "trigger_event ::= DELETE",
 /* 273 */ "trigger_event ::= INSERT",
 /* 274 */ "trigger_event ::= UPDATE",
 /* 275 */ "trigger_event ::= UPDATE OF inscollist",
 /* 276 */ "foreach_clause ::=",
 /* 277 */ "foreach_clause ::= FOR EACH ROW",
 /* 278 */ "foreach_clause ::= FOR EACH STATEMENT",
 /* 279 */ "when_clause ::=",
 /* 280 */ "when_clause ::= WHEN expr",
 /* 281 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list",
 /* 282 */ "trigger_cmd_list ::=",
 /* 283 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
 /* 284 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
 /* 285 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
 /* 286 */ "trigger_cmd ::= DELETE FROM nm where_opt",
 /* 287 */ "trigger_cmd ::= select",
 /* 288 */ "expr ::= RAISE LP IGNORE RP",
 /* 289 */ "expr ::= RAISE LP raisetype COMMA nm RP",
 /* 290 */ "raisetype ::= ROLLBACK",
 /* 291 */ "raisetype ::= ABORT",
 /* 292 */ "raisetype ::= FAIL",
 /* 293 */ "cmd ::= DROP TRIGGER fullname",
 /* 294 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt",
 /* 295 */ "key_opt ::=",
 /* 296 */ "key_opt ::= KEY ids",
 /* 297 */ "key_opt ::= KEY BLOB",
 /* 298 */ "database_kw_opt ::= DATABASE",
 /* 299 */ "database_kw_opt ::=",
 /* 300 */ "cmd ::= DETACH database_kw_opt nm",
 /* 301 */ "cmd ::= REINDEX",
 /* 302 */ "cmd ::= REINDEX nm dbnm",
 /* 303 */ "cmd ::= ANALYZE",
 /* 304 */ "cmd ::= ANALYZE nm dbnm",
 /* 305 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
 /* 306 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
 /* 307 */ "add_column_fullname ::= fullname",
 /* 308 */ "kwcolumn_opt ::=",
 /* 309 */ "kwcolumn_opt ::= COLUMNKW",
};
#endif /* NDEBUG */

/*
** This function returns the symbolic name associated with a token
** value.
*/
................................................................................
    ** reduce or during error processing or when a parser is 
    ** being destroyed before it is finished parsing.
    **
    ** Note: during a reduce, the only symbols destroyed are those
    ** which appear on the RHS of the rule, but which are not used
    ** inside the C code.
    */
    case 159:
    case 192:
    case 209:
#line 369 "parse.y"
{sqlite3SelectDelete((yypminor->yy99));}
#line 1328 "parse.c"
      break;
    case 173:
    case 174:
    case 197:
    case 199:
    case 207:
    case 213:
    case 227:
#line 628 "parse.y"
{sqlite3ExprDelete((yypminor->yy44));}
#line 1339 "parse.c"
      break;
    case 178:
    case 186:
    case 195:
    case 198:
    case 200:
    case 202:
    case 212:
    case 215:
    case 216:
    case 219:
    case 225:

#line 853 "parse.y"
{sqlite3ExprListDelete((yypminor->yy412));}
#line 1354 "parse.c"
      break;
    case 191:
    case 196:
    case 204:
    case 205:
#line 498 "parse.y"
{sqlite3SrcListDelete((yypminor->yy367));}
#line 1362 "parse.c"
      break;
    case 201:
#line 560 "parse.y"
{
  sqlite3ExprDelete((yypminor->yy112).pLimit);
  sqlite3ExprDelete((yypminor->yy112).pOffset);
}
#line 1370 "parse.c"
      break;
    case 208:
    case 211:
    case 218:
#line 516 "parse.y"
{sqlite3IdListDelete((yypminor->yy258));}
#line 1377 "parse.c"
      break;
    case 233:
    case 238:
#line 946 "parse.y"
{sqlite3DeleteTriggerStep((yypminor->yy203));}
#line 1383 "parse.c"
      break;
    case 235:
#line 930 "parse.y"
{sqlite3IdListDelete((yypminor->yy234).b);}
#line 1388 "parse.c"
      break;
    default:  break;   /* If no destructor action specified: do nothing */
  }
}

/*
** Pop the parser's stack once.
................................................................................
/* The following table contains information about every rule that
** is used during the reduce.
*/
static const struct {
  YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
  unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
} yyRuleInfo[] = {
  { 144, 1 },
  { 145, 2 },
  { 145, 1 },
  { 147, 1 },
  { 146, 1 },
  { 146, 3 },
  { 149, 0 },
  { 149, 1 },
  { 148, 3 },
  { 151, 0 },

  { 151, 1 },
  { 151, 2 },
  { 150, 0 },
  { 150, 1 },
  { 150, 1 },
  { 150, 1 },
  { 148, 2 },
  { 148, 2 },
  { 148, 2 },
  { 148, 2 },
  { 153, 5 },
  { 155, 1 },
  { 155, 0 },
  { 154, 4 },
  { 154, 2 },
  { 157, 3 },
  { 157, 1 },
  { 160, 3 },
  { 161, 1 },
  { 164, 1 },
  { 165, 1 },
  { 165, 1 },
  { 152, 1 },
  { 152, 1 },
  { 152, 1 },
  { 162, 0 },
  { 162, 1 },
  { 166, 1 },
  { 166, 4 },
  { 166, 6 },
  { 167, 1 },
  { 167, 2 },
  { 168, 1 },
  { 168, 1 },
  { 163, 2 },
  { 163, 0 },
  { 171, 3 },
  { 171, 1 },
  { 171, 2 },
  { 171, 4 },
  { 171, 3 },
  { 171, 3 },
  { 171, 2 },
  { 172, 2 },
  { 172, 3 },
  { 172, 5 },
  { 172, 2 },
  { 172, 5 },
  { 172, 4 },
  { 172, 1 },
  { 172, 2 },
  { 177, 0 },
  { 177, 1 },
  { 179, 0 },
  { 179, 2 },
  { 181, 2 },
  { 181, 3 },
  { 181, 3 },
  { 181, 3 },
  { 182, 2 },
  { 182, 2 },
  { 182, 1 },
  { 182, 1 },
  { 180, 3 },
  { 180, 2 },
  { 183, 0 },
  { 183, 2 },
  { 183, 2 },
  { 158, 0 },
  { 158, 2 },
  { 184, 3 },
  { 184, 2 },
  { 184, 1 },
  { 185, 2 },
  { 185, 7 },
  { 185, 5 },
  { 185, 3 },
  { 185, 10 },
  { 187, 0 },
  { 187, 1 },
  { 175, 0 },
  { 175, 3 },
  { 188, 0 },
  { 188, 2 },
  { 189, 1 },
  { 189, 1 },
  { 189, 1 },
  { 148, 3 },
  { 148, 7 },
  { 148, 3 },
  { 148, 1 },
  { 159, 1 },
  { 159, 3 },
  { 193, 1 },
  { 193, 2 },
  { 193, 1 },
  { 193, 1 },
  { 192, 9 },
  { 194, 1 },
  { 194, 1 },
  { 194, 0 },
  { 202, 2 },
  { 202, 0 },
  { 195, 3 },
  { 195, 2 },
  { 195, 4 },
  { 203, 2 },
  { 203, 1 },
  { 203, 0 },
  { 196, 0 },
  { 196, 2 },
  { 205, 2 },
  { 205, 0 },
  { 204, 6 },
  { 204, 7 },
  { 209, 1 },
  { 209, 1 },
  { 156, 0 },
  { 156, 2 },
  { 191, 2 },
  { 206, 1 },
  { 206, 1 },
  { 206, 2 },
  { 206, 3 },
  { 206, 4 },
  { 207, 2 },
  { 207, 0 },
  { 208, 4 },
  { 208, 0 },
  { 200, 0 },
  { 200, 3 },
  { 212, 5 },
  { 212, 3 },
  { 213, 1 },
  { 176, 1 },
  { 176, 1 },
  { 176, 0 },
  { 214, 0 },
  { 214, 2 },
  { 198, 0 },
  { 198, 3 },
  { 199, 0 },
  { 199, 2 },
  { 201, 0 },
  { 201, 2 },
  { 201, 4 },
  { 201, 4 },
  { 148, 4 },
  { 197, 0 },
  { 197, 2 },
  { 148, 6 },
  { 216, 5 },
  { 216, 3 },
  { 148, 8 },
  { 148, 5 },
  { 217, 2 },
  { 217, 1 },
  { 219, 3 },
  { 219, 1 },
  { 218, 0 },
  { 218, 3 },
  { 211, 3 },
  { 211, 1 },
  { 174, 1 },
  { 174, 3 },
  { 173, 1 },
  { 174, 1 },
  { 174, 1 },
  { 174, 3 },
  { 174, 5 },
  { 173, 1 },
  { 173, 1 },
  { 173, 1 },
  { 173, 1 },
  { 174, 1 },
  { 174, 1 },
  { 174, 6 },
  { 174, 4 },
  { 174, 4 },
  { 173, 1 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 174, 3 },
  { 220, 1 },
  { 220, 2 },
  { 221, 2 },
  { 221, 0 },
  { 174, 4 },
  { 174, 2 },
  { 174, 3 },
  { 174, 2 },
  { 174, 3 },
  { 174, 4 },
  { 174, 2 },
  { 174, 2 },
  { 174, 2 },
  { 174, 2 },
  { 222, 1 },
  { 222, 2 },
  { 174, 5 },
  { 223, 1 },
  { 223, 2 },
  { 174, 5 },
  { 174, 3 },
  { 174, 5 },
  { 174, 4 },
  { 174, 4 },
  { 174, 5 },
  { 225, 5 },
  { 225, 4 },
  { 226, 2 },
  { 226, 0 },
  { 224, 1 },
  { 224, 0 },
  { 215, 3 },
  { 215, 1 },
  { 227, 1 },
  { 227, 0 },
  { 148, 11 },
  { 228, 1 },
  { 228, 0 },
  { 178, 0 },
  { 178, 3 },
  { 186, 5 },
  { 186, 3 },
  { 229, 1 },
  { 148, 3 },
  { 148, 1 },
  { 148, 2 },
  { 148, 5 },
  { 148, 5 },
  { 148, 5 },
  { 148, 5 },
  { 148, 6 },
  { 148, 3 },
  { 169, 2 },
  { 170, 2 },
  { 231, 1 },
  { 231, 1 },
  { 230, 1 },
  { 230, 0 },
  { 148, 5 },
  { 232, 10 },
  { 234, 1 },
  { 234, 1 },
  { 234, 2 },
  { 234, 0 },
  { 235, 1 },
  { 235, 1 },
  { 235, 1 },
  { 235, 3 },
  { 236, 0 },
  { 236, 3 },
  { 236, 3 },
  { 237, 0 },
  { 237, 2 },
  { 233, 3 },
  { 233, 0 },
  { 238, 6 },
  { 238, 8 },
  { 238, 5 },
  { 238, 4 },
  { 238, 1 },
  { 174, 4 },
  { 174, 6 },
  { 190, 1 },
  { 190, 1 },
  { 190, 1 },
  { 148, 3 },
  { 148, 6 },
  { 240, 0 },
  { 240, 2 },
  { 240, 2 },
  { 239, 1 },
  { 239, 0 },
  { 148, 3 },
  { 148, 1 },
  { 148, 3 },
  { 148, 1 },
  { 148, 3 },
  { 148, 6 },
  { 148, 6 },
  { 241, 1 },
  { 242, 0 },
  { 242, 1 },
};

static void yy_accept(yyParser*);  /* Forward Declaration */

/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
................................................................................
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
      case 3:
#line 102 "parse.y"
{ sqlite3FinishCoding(pParse); }
#line 1925 "parse.c"
        break;
      case 6:
#line 105 "parse.y"
{ sqlite3BeginParse(pParse, 0); }
#line 1930 "parse.c"
        break;
      case 7:
#line 107 "parse.y"
{ sqlite3BeginParse(pParse, 1); }
#line 1935 "parse.c"
        break;
      case 8:
#line 113 "parse.y"





{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy58);}
#line 1940 "parse.c"
        break;
      case 12:
#line 118 "parse.y"
{yygotominor.yy58 = TK_DEFERRED;}
#line 1945 "parse.c"
        break;
      case 13:
      case 14:
      case 15:
      case 103:
      case 105:
      case 106:
#line 119 "parse.y"
{yygotominor.yy58 = yymsp[0].major;}
#line 1955 "parse.c"
        break;
      case 16:
      case 17:
#line 122 "parse.y"
{sqlite3CommitTransaction(pParse);}
#line 1961 "parse.c"
        break;
      case 18:
#line 124 "parse.y"
{sqlite3RollbackTransaction(pParse);}
#line 1966 "parse.c"
        break;
      case 20:
#line 129 "parse.y"
{
   sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144,yymsp[-3].minor.yy58,0);
}
#line 1973 "parse.c"
        break;
      case 21:
      case 62:
      case 76:
      case 108:
      case 223:
      case 226:
#line 134 "parse.y"
{yygotominor.yy58 = 1;}
#line 1983 "parse.c"
        break;
      case 22:
      case 61:
      case 75:









      case 77:
      case 88:
      case 109:
      case 110:

      case 222:
      case 225:
#line 136 "parse.y"
{yygotominor.yy58 = 0;}
#line 1996 "parse.c"
        break;
      case 23:
#line 137 "parse.y"
{
  sqlite3EndTable(pParse,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy0,0);
}
#line 2003 "parse.c"
        break;
      case 24:
#line 140 "parse.y"
{
  sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy99);
  sqlite3SelectDelete(yymsp[0].minor.yy99);
}
#line 2011 "parse.c"
        break;
      case 27:
#line 152 "parse.y"
{
  yygotominor.yy144.z = yymsp[-2].minor.yy144.z;
  yygotominor.yy144.n = (pParse->sLastToken.z-yymsp[-2].minor.yy144.z) + pParse->sLastToken.n;
}
#line 2019 "parse.c"
        break;
      case 28:
#line 156 "parse.y"
{
  sqlite3AddColumn(pParse,&yymsp[0].minor.yy144);
  yygotominor.yy144 = yymsp[0].minor.yy144;
}
#line 2027 "parse.c"
        break;
      case 29:
      case 30:
      case 31:
      case 32:
      case 33:
      case 34:
      case 262:
      case 263:

#line 166 "parse.y"
{yygotominor.yy144 = yymsp[0].minor.yy0;}
#line 2039 "parse.c"
        break;
      case 36:
#line 226 "parse.y"
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy144);}
#line 2044 "parse.c"
        break;
      case 37:
      case 40:
      case 116:
      case 117:
      case 128:
      case 148:
      case 250:
      case 260:
      case 261:
#line 227 "parse.y"
{yygotominor.yy144 = yymsp[0].minor.yy144;}
#line 2057 "parse.c"
        break;
      case 38:
#line 228 "parse.y"
{
  yygotominor.yy144.z = yymsp[-3].minor.yy144.z;
  yygotominor.yy144.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy144.z;
}
#line 2065 "parse.c"
        break;
      case 39:
#line 232 "parse.y"
{
  yygotominor.yy144.z = yymsp[-5].minor.yy144.z;
  yygotominor.yy144.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy144.z;
}
#line 2073 "parse.c"
        break;
      case 41:
#line 238 "parse.y"
{yygotominor.yy144.z=yymsp[-1].minor.yy144.z; yygotominor.yy144.n=yymsp[0].minor.yy144.n+(yymsp[0].minor.yy144.z-yymsp[-1].minor.yy144.z);}
#line 2078 "parse.c"
        break;
      case 42:
#line 240 "parse.y"
{ yygotominor.yy58 = atoi(yymsp[0].minor.yy144.z); }

#line 2083 "parse.c"
        break;
      case 43:
#line 241 "parse.y"





{ yygotominor.yy58 = -atoi(yymsp[0].minor.yy144.z); }
#line 2088 "parse.c"
        break;
      case 48:
      case 50:
#line 250 "parse.y"
{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy44);}
#line 2094 "parse.c"
        break;
      case 49:
#line 251 "parse.y"
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy44);}
#line 2099 "parse.c"
        break;
      case 51:
#line 253 "parse.y"
{
  Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy44, 0, 0);
  sqlite3AddDefaultValue(pParse,p);
}
#line 2107 "parse.c"
        break;
      case 52:
#line 257 "parse.y"
{
  Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy144);
  sqlite3AddDefaultValue(pParse,p);
}
#line 2115 "parse.c"
        break;
      case 54:
#line 266 "parse.y"
{sqlite3AddNotNull(pParse, yymsp[0].minor.yy58);}
#line 2120 "parse.c"
        break;
      case 55:
#line 268 "parse.y"
{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy58,yymsp[0].minor.yy58);}
#line 2125 "parse.c"
        break;
      case 56:
#line 269 "parse.y"
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy58,0,0);}
#line 2130 "parse.c"
        break;
      case 57:
#line 270 "parse.y"
{sqlite3ExprDelete(yymsp[-2].minor.yy44);}
#line 2135 "parse.c"
        break;
      case 58:
#line 272 "parse.y"
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy144,yymsp[-1].minor.yy412,yymsp[0].minor.yy58);}
#line 2140 "parse.c"
        break;
      case 59:
#line 273 "parse.y"
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy58);}
#line 2145 "parse.c"
        break;
      case 60:
#line 274 "parse.y"
{sqlite3AddCollateType(pParse, yymsp[0].minor.yy144.z, yymsp[0].minor.yy144.n);}
#line 2150 "parse.c"
        break;
      case 63:
#line 287 "parse.y"
{ yygotominor.yy58 = OE_Restrict * 0x010101; }
#line 2155 "parse.c"
        break;
      case 64:
#line 288 "parse.y"
{ yygotominor.yy58 = (yymsp[-1].minor.yy58 & yymsp[0].minor.yy35.mask) | yymsp[0].minor.yy35.value; }
#line 2160 "parse.c"
        break;
      case 65:
#line 290 "parse.y"
{ yygotominor.yy35.value = 0;     yygotominor.yy35.mask = 0x000000; }
#line 2165 "parse.c"
        break;
      case 66:
#line 291 "parse.y"
{ yygotominor.yy35.value = yymsp[0].minor.yy58;     yygotominor.yy35.mask = 0x0000ff; }
#line 2170 "parse.c"
        break;
      case 67:
#line 292 "parse.y"
{ yygotominor.yy35.value = yymsp[0].minor.yy58<<8;  yygotominor.yy35.mask = 0x00ff00; }
#line 2175 "parse.c"
        break;
      case 68:
#line 293 "parse.y"
{ yygotominor.yy35.value = yymsp[0].minor.yy58<<16; yygotominor.yy35.mask = 0xff0000; }
#line 2180 "parse.c"
        break;
      case 69:
#line 295 "parse.y"
{ yygotominor.yy58 = OE_SetNull; }
#line 2185 "parse.c"
        break;
      case 70:
#line 296 "parse.y"
{ yygotominor.yy58 = OE_SetDflt; }
#line 2190 "parse.c"
        break;
      case 71:
#line 297 "parse.y"
{ yygotominor.yy58 = OE_Cascade; }
#line 2195 "parse.c"
        break;
      case 72:
#line 298 "parse.y"
{ yygotominor.yy58 = OE_Restrict; }
#line 2200 "parse.c"
        break;
      case 73:




      case 74:
      case 89:
      case 91:
      case 93:
      case 94:
      case 165:
#line 300 "parse.y"
{yygotominor.yy58 = yymsp[0].minor.yy58;}
#line 2211 "parse.c"
        break;
      case 78:
#line 310 "parse.y"
{yygotominor.yy144.n = 0; yygotominor.yy144.z = 0;}
#line 2216 "parse.c"
        break;
      case 79:
#line 311 "parse.y"





{yygotominor.yy144 = yymsp[-1].minor.yy0;}
#line 2221 "parse.c"
        break;
      case 84:
#line 317 "parse.y"
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy412,yymsp[0].minor.yy58,yymsp[-2].minor.yy58);}
#line 2226 "parse.c"
        break;
      case 85:
#line 319 "parse.y"
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy412,yymsp[0].minor.yy58,0,0);}
#line 2231 "parse.c"
        break;
      case 87:
#line 322 "parse.y"
{
    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy412, &yymsp[-3].minor.yy144, yymsp[-2].minor.yy412, yymsp[-1].minor.yy58);
    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy58);
}
#line 2239 "parse.c"
        break;
      case 90:
      case 92:
#line 336 "parse.y"
{yygotominor.yy58 = OE_Default;}
#line 2245 "parse.c"
        break;
      case 95:
#line 341 "parse.y"
{yygotominor.yy58 = OE_Ignore;}
#line 2250 "parse.c"
        break;
      case 96:
      case 166:
#line 342 "parse.y"
{yygotominor.yy58 = OE_Replace;}
#line 2256 "parse.c"
        break;
      case 97:
#line 346 "parse.y"
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy367, 0);
}
#line 2263 "parse.c"
        break;
      case 98:
#line 353 "parse.y"
{
  sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy144, &yymsp[-2].minor.yy144, yymsp[0].minor.yy99, yymsp[-5].minor.yy58);
}
#line 2270 "parse.c"
        break;
      case 99:
#line 356 "parse.y"
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy367, 1);
}
#line 2277 "parse.c"
        break;
      case 100:
#line 363 "parse.y"
{
  sqlite3Select(pParse, yymsp[0].minor.yy99, SRT_Callback, 0, 0, 0, 0, 0);
  sqlite3SelectDelete(yymsp[0].minor.yy99);
}
#line 2285 "parse.c"
        break;
      case 101:
      case 125:
#line 373 "parse.y"
{yygotominor.yy99 = yymsp[0].minor.yy99;}
#line 2291 "parse.c"
        break;
      case 102:
#line 375 "parse.y"
{
  if( yymsp[0].minor.yy99 ){
    yymsp[0].minor.yy99->op = yymsp[-1].minor.yy58;
    yymsp[0].minor.yy99->pPrior = yymsp[-2].minor.yy99;
  }
  yygotominor.yy99 = yymsp[0].minor.yy99;
}
#line 2302 "parse.c"
        break;
      case 104:
#line 384 "parse.y"
{yygotominor.yy58 = TK_ALL;}
#line 2307 "parse.c"
        break;
      case 107:
#line 389 "parse.y"
{
  yygotominor.yy99 = sqlite3SelectNew(yymsp[-6].minor.yy412,yymsp[-5].minor.yy367,yymsp[-4].minor.yy44,yymsp[-3].minor.yy412,yymsp[-2].minor.yy44,yymsp[-1].minor.yy412,yymsp[-7].minor.yy58,yymsp[0].minor.yy112.pLimit,yymsp[0].minor.yy112.pOffset);

}
#line 2314 "parse.c"
        break;
      case 111:
      case 247:
#line 410 "parse.y"
{yygotominor.yy412 = yymsp[-1].minor.yy412;}
#line 2320 "parse.c"
        break;
      case 112:
      case 139:
      case 149:
      case 246:
#line 411 "parse.y"
{yygotominor.yy412 = 0;}
#line 2328 "parse.c"
        break;
      case 113:
#line 412 "parse.y"
{
   yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-2].minor.yy412,yymsp[-1].minor.yy44,yymsp[0].minor.yy144.n?&yymsp[0].minor.yy144:0);

}
#line 2335 "parse.c"
        break;
      case 114:
#line 415 "parse.y"
{
  yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-1].minor.yy412, sqlite3Expr(TK_ALL, 0, 0, 0), 0);
}
#line 2342 "parse.c"
        break;
      case 115:
#line 418 "parse.y"
{
  Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0);
  Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy144);
  yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-3].minor.yy412, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0);
}
#line 2351 "parse.c"
        break;
      case 118:
#line 430 "parse.y"
{yygotominor.yy144.n = 0;}
#line 2356 "parse.c"
        break;
      case 119:
#line 442 "parse.y"
{yygotominor.yy367 = sqliteMalloc(sizeof(*yygotominor.yy367));}
#line 2361 "parse.c"
        break;
      case 120:
#line 443 "parse.y"





{yygotominor.yy367 = yymsp[0].minor.yy367;}
#line 2366 "parse.c"
        break;
      case 121:
#line 448 "parse.y"
{
   yygotominor.yy367 = yymsp[-1].minor.yy367;
   if( yygotominor.yy367 && yygotominor.yy367->nSrc>0 ) yygotominor.yy367->a[yygotominor.yy367->nSrc-1].jointype = yymsp[0].minor.yy58;

}
#line 2374 "parse.c"
        break;
      case 122:
#line 452 "parse.y"
{yygotominor.yy367 = 0;}
#line 2379 "parse.c"
        break;
      case 123:
#line 453 "parse.y"
{
  yygotominor.yy367 = sqlite3SrcListAppend(yymsp[-5].minor.yy367,&yymsp[-4].minor.yy144,&yymsp[-3].minor.yy144);
  if( yymsp[-2].minor.yy144.n ) sqlite3SrcListAddAlias(yygotominor.yy367,&yymsp[-2].minor.yy144);
  if( yymsp[-1].minor.yy44 ){
    if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pOn = yymsp[-1].minor.yy44; }

    else { sqlite3ExprDelete(yymsp[-1].minor.yy44); }
  }
  if( yymsp[0].minor.yy258 ){
    if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pUsing = yymsp[0].minor.yy258; }

    else { sqlite3IdListDelete(yymsp[0].minor.yy258); }
  }
}
#line 2395 "parse.c"
        break;
      case 124:
#line 467 "parse.y"
{
    yygotominor.yy367 = sqlite3SrcListAppend(yymsp[-6].minor.yy367,0,0);
    yygotominor.yy367->a[yygotominor.yy367->nSrc-1].pSelect = yymsp[-4].minor.yy99;
    if( yymsp[-2].minor.yy144.n ) sqlite3SrcListAddAlias(yygotominor.yy367,&yymsp[-2].minor.yy144);
    if( yymsp[-1].minor.yy44 ){
      if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pOn = yymsp[-1].minor.yy44; }

      else { sqlite3ExprDelete(yymsp[-1].minor.yy44); }
    }
    if( yymsp[0].minor.yy258 ){
      if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pUsing = yymsp[0].minor.yy258; }

      else { sqlite3IdListDelete(yymsp[0].minor.yy258); }
    }
  }
#line 2412 "parse.c"
        break;
      case 126:
#line 488 "parse.y"
{
     yygotominor.yy99 = sqlite3SelectNew(0,yymsp[0].minor.yy367,0,0,0,0,0,0,0);
  }
#line 2419 "parse.c"
        break;
      case 127:
#line 494 "parse.y"
{yygotominor.yy144.z=0; yygotominor.yy144.n=0;}
#line 2424 "parse.c"
        break;
      case 129:
#line 499 "parse.y"
{yygotominor.yy367 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144);}
#line 2429 "parse.c"
        break;
      case 130:
      case 131:
#line 503 "parse.y"
{ yygotominor.yy58 = JT_INNER; }
#line 2435 "parse.c"
        break;
      case 132:
#line 505 "parse.y"
{ yygotominor.yy58 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
#line 2440 "parse.c"
        break;
      case 133:
#line 506 "parse.y"
{ yygotominor.yy58 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy144,0); }
#line 2445 "parse.c"
        break;
      case 134:
#line 508 "parse.y"
{ yygotominor.yy58 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy144,&yymsp[-1].minor.yy144); }
#line 2450 "parse.c"
        break;
      case 135:
      case 143:
      case 152:
      case 159:
      case 173:
      case 210:
      case 235:
      case 237:
      case 241:
#line 512 "parse.y"
{yygotominor.yy44 = yymsp[0].minor.yy44;}

#line 2463 "parse.c"
        break;
      case 136:
      case 151:
      case 158:


      case 211:
      case 236:
      case 238:
      case 242:
#line 513 "parse.y"
{yygotominor.yy44 = 0;}
#line 2474 "parse.c"
        break;
      case 137:
      case 170:





#line 517 "parse.y"
{yygotominor.yy258 = yymsp[-1].minor.yy258;}
#line 2480 "parse.c"
        break;
      case 138:
      case 169:
#line 518 "parse.y"
{yygotominor.yy258 = 0;}
#line 2486 "parse.c"
        break;
      case 140:
      case 150:
#line 529 "parse.y"
{yygotominor.yy412 = yymsp[0].minor.yy412;}
#line 2492 "parse.c"
        break;
      case 141:

#line 530 "parse.y"





{
  yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412,yymsp[-2].minor.yy44,yymsp[-1].minor.yy144.n>0?&yymsp[-1].minor.yy144:0);
  if( yygotominor.yy412 ) yygotominor.yy412->a[yygotominor.yy412->nExpr-1].sortOrder = yymsp[0].minor.yy58;


}
#line 2500 "parse.c"
        break;
      case 142:
#line 534 "parse.y"
{
  yygotominor.yy412 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy44,yymsp[-1].minor.yy144.n>0?&yymsp[-1].minor.yy144:0);
  if( yygotominor.yy412 && yygotominor.yy412->a ) yygotominor.yy412->a[0].sortOrder = yymsp[0].minor.yy58;

}
#line 2508 "parse.c"
        break;
      case 144:
      case 146:
#line 543 "parse.y"
{yygotominor.yy58 = SQLITE_SO_ASC;}
#line 2514 "parse.c"
        break;
      case 145:
#line 544 "parse.y"
{yygotominor.yy58 = SQLITE_SO_DESC;}
#line 2519 "parse.c"
        break;
      case 147:
#line 546 "parse.y"
{yygotominor.yy144.z = 0; yygotominor.yy144.n = 0;}
#line 2524 "parse.c"
        break;
      case 153:
#line 564 "parse.y"
{yygotominor.yy112.pLimit = 0; yygotominor.yy112.pOffset = 0;}
#line 2529 "parse.c"
        break;
      case 154:
#line 565 "parse.y"
{yygotominor.yy112.pLimit = yymsp[0].minor.yy44; yygotominor.yy112.pOffset = 0;}

#line 2534 "parse.c"
        break;
      case 155:
#line 567 "parse.y"
{yygotominor.yy112.pLimit = yymsp[-2].minor.yy44; yygotominor.yy112.pOffset = yymsp[0].minor.yy44;}

#line 2539 "parse.c"
        break;
      case 156:
#line 569 "parse.y"
{yygotominor.yy112.pOffset = yymsp[-2].minor.yy44; yygotominor.yy112.pLimit = yymsp[0].minor.yy44;}

#line 2544 "parse.c"
        break;
      case 157:
#line 573 "parse.y"
{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy367,yymsp[0].minor.yy44);}
#line 2549 "parse.c"
        break;
      case 160:
#line 584 "parse.y"
{sqlite3Update(pParse,yymsp[-3].minor.yy367,yymsp[-1].minor.yy412,yymsp[0].minor.yy44,yymsp[-4].minor.yy58);}
#line 2554 "parse.c"
        break;
      case 161:
#line 590 "parse.y"
{yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412,yymsp[0].minor.yy44,&yymsp[-2].minor.yy144);}
#line 2559 "parse.c"
        break;
      case 162:
#line 591 "parse.y"
{yygotominor.yy412 = sqlite3ExprListAppend(0,yymsp[0].minor.yy44,&yymsp[-2].minor.yy144);}
#line 2564 "parse.c"
        break;
      case 163:
#line 597 "parse.y"
{sqlite3Insert(pParse, yymsp[-5].minor.yy367, yymsp[-1].minor.yy412, 0, yymsp[-4].minor.yy258, yymsp[-7].minor.yy58);}
#line 2569 "parse.c"
        break;
      case 164:
#line 599 "parse.y"
{sqlite3Insert(pParse, yymsp[-2].minor.yy367, 0, yymsp[0].minor.yy99, yymsp[-1].minor.yy258, yymsp[-4].minor.yy58);}
#line 2574 "parse.c"
        break;
      case 167:
      case 239:
#line 609 "parse.y"
{yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-2].minor.yy412,yymsp[0].minor.yy44,0);}

#line 2580 "parse.c"
        break;
      case 168:
      case 240:
#line 610 "parse.y"
{yygotominor.yy412 = sqlite3ExprListAppend(0,yymsp[0].minor.yy44,0);}
#line 2586 "parse.c"
        break;
      case 171:

#line 619 "parse.y"
{yygotominor.yy258 = sqlite3IdListAppend(yymsp[-2].minor.yy258,&yymsp[0].minor.yy144);}

#line 2591 "parse.c"
        break;
      case 172:
#line 620 "parse.y"
{yygotominor.yy258 = sqlite3IdListAppend(0,&yymsp[0].minor.yy144);}
#line 2596 "parse.c"
        break;
      case 174:
#line 631 "parse.y"
{yygotominor.yy44 = yymsp[-1].minor.yy44; sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
#line 2601 "parse.c"
        break;
      case 175:




      case 180:
      case 181:
      case 182:
      case 183:

#line 632 "parse.y"
{yygotominor.yy44 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
#line 2610 "parse.c"
        break;
      case 176:
      case 177:
#line 633 "parse.y"
{yygotominor.yy44 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);}
#line 2616 "parse.c"
        break;
      case 178:
#line 635 "parse.y"
{
  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy144);
  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy144);
  yygotominor.yy44 = sqlite3Expr(TK_DOT, temp1, temp2, 0);
}
#line 2625 "parse.c"
        break;
      case 179:
#line 640 "parse.y"
{
  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy144);
  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy144);
  Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy144);
  Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
  yygotominor.yy44 = sqlite3Expr(TK_DOT, temp1, temp4, 0);
}
#line 2636 "parse.c"
        break;
      case 184:
#line 651 "parse.y"
{yygotominor.yy44 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
#line 2641 "parse.c"
        break;
      case 185:
#line 652 "parse.y"





{
  Token *pToken = &yymsp[0].minor.yy0;
  Expr *pExpr = yygotominor.yy44 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
  sqlite3ExprAssignVarNumber(pParse, pExpr);
}
#line 2650 "parse.c"
        break;
      case 186:
#line 658 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_CAST, yymsp[-3].minor.yy44, 0, &yymsp[-1].minor.yy144);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
}
#line 2658 "parse.c"
        break;
      case 187:
#line 663 "parse.y"
{
  yygotominor.yy44 = sqlite3ExprFunction(yymsp[-1].minor.yy412, &yymsp[-3].minor.yy0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);


}
#line 2666 "parse.c"
        break;
      case 188:
#line 667 "parse.y"
{
  yygotominor.yy44 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
}
#line 2674 "parse.c"
        break;
      case 189:
#line 671 "parse.y"
{








  /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
  ** treated as functions that return constants */
  yygotominor.yy44 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0);
  if( yygotominor.yy44 ) yygotominor.yy44->op = TK_CONST_FUNC;  

}
#line 2684 "parse.c"
        break;
      case 190:
      case 191:
      case 192:
      case 193:
      case 194:
      case 195:
      case 196:
      case 197:
................................................................................
      case 201:
      case 202:
      case 203:
      case 204:
      case 205:
      case 206:
      case 207:

#line 677 "parse.y"
{yygotominor.yy44 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy44, yymsp[0].minor.yy44, 0);}
#line 2706 "parse.c"
        break;
      case 208:
#line 696 "parse.y"
{yygotominor.yy432.operator = yymsp[0].minor.yy0; yygotominor.yy432.not = 0;}
#line 2711 "parse.c"
        break;
      case 209:
#line 697 "parse.y"
{yygotominor.yy432.operator = yymsp[0].minor.yy0; yygotominor.yy432.not = 1;}
#line 2716 "parse.c"
        break;
      case 212:
#line 701 "parse.y"
{
  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy44, 0);
  pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy44, 0);
  if( yymsp[0].minor.yy44 ){
    pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy44, 0);
  }
  yygotominor.yy44 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy432.operator);
  if( yymsp[-2].minor.yy432.not ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44, &yymsp[-3].minor.yy44->span, &yymsp[-1].minor.yy44->span);

}
#line 2730 "parse.c"
        break;
      case 213:
#line 712 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy44->span,&yymsp[0].minor.yy0);
}
#line 2738 "parse.c"
        break;
      case 214:
#line 716 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy44->span,&yymsp[0].minor.yy0);
}
#line 2746 "parse.c"
        break;
      case 215:
#line 720 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy44->span,&yymsp[0].minor.yy0);
}
#line 2754 "parse.c"
        break;
      case 216:
#line 724 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy44->span,&yymsp[0].minor.yy0);
}
#line 2762 "parse.c"
        break;
      case 217:
#line 728 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy44->span,&yymsp[0].minor.yy0);
}
#line 2770 "parse.c"
        break;
      case 218:







      case 219:

#line 732 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy44->span);
}
#line 2779 "parse.c"
        break;
      case 220:
#line 740 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy44->span);
}
#line 2787 "parse.c"
        break;
      case 221:
#line 744 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy44->span);
}
#line 2795 "parse.c"
        break;
      case 224:
#line 751 "parse.y"
{
  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy44, 0);
  pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy44, 0);
  yygotominor.yy44 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy44, 0, 0);
  if( yygotominor.yy44 ) yygotominor.yy44->pList = pList;




  if( yymsp[-3].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0);
  sqlite3ExprSpan(yygotominor.yy44,&yymsp[-4].minor.yy44->span,&yymsp[0].minor.yy44->span);

}
#line 2807 "parse.c"
        break;
      case 227:
#line 763 "parse.y"
{
    yygotominor.yy44 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy44, 0, 0);
    if( yygotominor.yy44 ){
      yygotominor.yy44->pList = yymsp[-1].minor.yy412;
    }else{
      sqlite3ExprListDelete(yymsp[-1].minor.yy412);
    }
    if( yymsp[-3].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0);
    sqlite3ExprSpan(yygotominor.yy44,&yymsp[-4].minor.yy44->span,&yymsp[0].minor.yy0);
  }
#line 2821 "parse.c"
        break;
      case 228:
#line 773 "parse.y"
{
    yygotominor.yy44 = sqlite3Expr(TK_SELECT, 0, 0, 0);

    if( yygotominor.yy44 ) yygotominor.yy44->pSelect = yymsp[-1].minor.yy99;

    if( !yygotominor.yy44 ) sqlite3SelectDelete(yymsp[-1].minor.yy99);

    sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
  }
#line 2831 "parse.c"
        break;
      case 229:
#line 779 "parse.y"
{
    yygotominor.yy44 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy44, 0, 0);

    if( yygotominor.yy44 ) yygotominor.yy44->pSelect = yymsp[-1].minor.yy99;

    if( !yygotominor.yy44 ) sqlite3SelectDelete(yymsp[-1].minor.yy99);
    if( yymsp[-3].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0);
    sqlite3ExprSpan(yygotominor.yy44,&yymsp[-4].minor.yy44->span,&yymsp[0].minor.yy0);
  }
#line 2842 "parse.c"
        break;
      case 230:
#line 786 "parse.y"
{
    SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144);
    yygotominor.yy44 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy44, 0, 0);
    if( yygotominor.yy44 ) yygotominor.yy44->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
    if( yymsp[-2].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0);
    sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy44->span,yymsp[0].minor.yy144.z?&yymsp[0].minor.yy144:&yymsp[-1].minor.yy144);
  }
#line 2853 "parse.c"
        break;
      case 231:
#line 793 "parse.y"
{
    Expr *p = yygotominor.yy44 = sqlite3Expr(TK_EXISTS, 0, 0, 0);
    if( p ){
      p->pSelect = yymsp[-1].minor.yy99;
      sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
    }
    if( !p ) sqlite3SelectDelete(yymsp[-1].minor.yy99);
  }
#line 2865 "parse.c"
        break;
      case 232:
#line 804 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy44, yymsp[-1].minor.yy44, 0);
  if( yygotominor.yy44 ) yygotominor.yy44->pList = yymsp[-2].minor.yy412;
  sqlite3ExprSpan(yygotominor.yy44, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
}
#line 2874 "parse.c"
        break;
      case 233:
#line 811 "parse.y"
{
  yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412, yymsp[-2].minor.yy44, 0);
  yygotominor.yy412 = sqlite3ExprListAppend(yygotominor.yy412, yymsp[0].minor.yy44, 0);
}
#line 2882 "parse.c"
        break;
      case 234:
#line 815 "parse.y"
{
  yygotominor.yy412 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy44, 0);
  yygotominor.yy412 = sqlite3ExprListAppend(yygotominor.yy412, yymsp[0].minor.yy44, 0);
}
#line 2890 "parse.c"
        break;
      case 243:
#line 840 "parse.y"
{
  if( yymsp[-9].minor.yy58!=OE_None ) yymsp[-9].minor.yy58 = yymsp[0].minor.yy58;
  if( yymsp[-9].minor.yy58==OE_Default) yymsp[-9].minor.yy58 = OE_Abort;
  sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy144, &yymsp[-6].minor.yy144, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy144,0),yymsp[-2].minor.yy412,yymsp[-9].minor.yy58, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0);
}
#line 2899 "parse.c"
        break;
      case 244:
      case 291:
#line 847 "parse.y"
{yygotominor.yy58 = OE_Abort;}
#line 2905 "parse.c"
        break;
      case 245:
#line 848 "parse.y"
{yygotominor.yy58 = OE_None;}
#line 2910 "parse.c"
        break;
      case 248:
#line 858 "parse.y"
{
  Expr *p = 0;
  if( yymsp[-1].minor.yy144.n>0 ){
    p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy144.z, yymsp[-1].minor.yy144.n);
  }
  yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412, p, &yymsp[-2].minor.yy144);
}
#line 2922 "parse.c"
        break;
      case 249:
#line 866 "parse.y"
{
  Expr *p = 0;
  if( yymsp[-1].minor.yy144.n>0 ){
    p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy144.z, yymsp[-1].minor.yy144.n);
  }
  yygotominor.yy412 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy144);
}
#line 2934 "parse.c"
        break;
      case 251:
#line 879 "parse.y"
{sqlite3DropIndex(pParse, yymsp[0].minor.yy367);}
#line 2939 "parse.c"
        break;
      case 252:
      case 253:
#line 883 "parse.y"
{sqlite3Vacuum(pParse,0);}
#line 2945 "parse.c"
        break;
      case 254:
      case 256:
#line 889 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy144,&yymsp[-2].minor.yy144,&yymsp[0].minor.yy144,0);}
#line 2951 "parse.c"
        break;
      case 255:
#line 890 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy144,&yymsp[-2].minor.yy144,&yymsp[0].minor.yy0,0);}
#line 2956 "parse.c"
        break;
      case 257:
#line 892 "parse.y"
{
  sqlite3Pragma(pParse,&yymsp[-3].minor.yy144,&yymsp[-2].minor.yy144,&yymsp[0].minor.yy144,1);
}
#line 2963 "parse.c"
        break;
      case 258:
#line 895 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy144,&yymsp[-3].minor.yy144,&yymsp[-1].minor.yy144,0);}
#line 2968 "parse.c"
        break;
      case 259:
#line 896 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144,0,0);}
#line 2973 "parse.c"
        break;
      case 266:
#line 909 "parse.y"
{
  Token all;
  all.z = yymsp[-3].minor.yy144.z;
  all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy144.z) + yymsp[0].minor.yy0.n;
  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all);
}
#line 2983 "parse.c"
        break;
      case 267:
#line 918 "parse.y"
{
  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy144, &yymsp[-6].minor.yy144, yymsp[-5].minor.yy58, yymsp[-4].minor.yy234.a, yymsp[-4].minor.yy234.b, yymsp[-2].minor.yy367, yymsp[-1].minor.yy58, yymsp[0].minor.yy44, yymsp[-9].minor.yy58);
  yygotominor.yy144 = (yymsp[-6].minor.yy144.n==0?yymsp[-7].minor.yy144:yymsp[-6].minor.yy144);
}
#line 2991 "parse.c"
        break;
      case 268:
      case 271:
#line 924 "parse.y"
{ yygotominor.yy58 = TK_BEFORE; }
#line 2997 "parse.c"
        break;
      case 269:
#line 925 "parse.y"
{ yygotominor.yy58 = TK_AFTER;  }
#line 3002 "parse.c"
        break;
      case 270:
#line 926 "parse.y"
{ yygotominor.yy58 = TK_INSTEAD;}
#line 3007 "parse.c"
        break;
      case 272:
      case 273:
      case 274:
#line 931 "parse.y"
{yygotominor.yy234.a = yymsp[0].major; yygotominor.yy234.b = 0;}
#line 3014 "parse.c"
        break;
      case 275:
#line 934 "parse.y"
{yygotominor.yy234.a = TK_UPDATE; yygotominor.yy234.b = yymsp[0].minor.yy258;}
#line 3019 "parse.c"
        break;
      case 276:
      case 277:
#line 937 "parse.y"
{ yygotominor.yy58 = TK_ROW; }
#line 3025 "parse.c"
        break;
      case 278:
#line 939 "parse.y"
{ yygotominor.yy58 = TK_STATEMENT; }
#line 3030 "parse.c"
        break;
      case 279:
#line 942 "parse.y"
{ yygotominor.yy44 = 0; }
#line 3035 "parse.c"
        break;
      case 280:
#line 943 "parse.y"
{ yygotominor.yy44 = yymsp[0].minor.yy44; }
#line 3040 "parse.c"
        break;
      case 281:
#line 947 "parse.y"
{
  yymsp[-2].minor.yy203->pNext = yymsp[0].minor.yy203;
  yygotominor.yy203 = yymsp[-2].minor.yy203;
}
#line 3048 "parse.c"
        break;
      case 282:
#line 951 "parse.y"
{ yygotominor.yy203 = 0; }
#line 3053 "parse.c"
        break;
      case 283:
#line 957 "parse.y"
{ yygotominor.yy203 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy144, yymsp[-1].minor.yy412, yymsp[0].minor.yy44, yymsp[-4].minor.yy58); }
#line 3058 "parse.c"
        break;
      case 284:
#line 962 "parse.y"
{yygotominor.yy203 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy144, yymsp[-4].minor.yy258, yymsp[-1].minor.yy412, 0, yymsp[-7].minor.yy58);}
#line 3063 "parse.c"
        break;
      case 285:
#line 965 "parse.y"
{yygotominor.yy203 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy144, yymsp[-1].minor.yy258, 0, yymsp[0].minor.yy99, yymsp[-4].minor.yy58);}
#line 3068 "parse.c"
        break;
      case 286:
#line 969 "parse.y"
{yygotominor.yy203 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy144, yymsp[0].minor.yy44);}
#line 3073 "parse.c"
        break;
      case 287:
#line 972 "parse.y"
{yygotominor.yy203 = sqlite3TriggerSelectStep(yymsp[0].minor.yy99); }
#line 3078 "parse.c"
        break;
      case 288:
#line 975 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_RAISE, 0, 0, 0); 
  yygotominor.yy44->iColumn = OE_Ignore;
  sqlite3ExprSpan(yygotominor.yy44, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
}
#line 3087 "parse.c"
        break;
      case 289:
#line 980 "parse.y"
{
  yygotominor.yy44 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy144); 
  yygotominor.yy44->iColumn = yymsp[-3].minor.yy58;
  sqlite3ExprSpan(yygotominor.yy44, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
}
#line 3096 "parse.c"
        break;
      case 290:
#line 988 "parse.y"
{yygotominor.yy58 = OE_Rollback;}
#line 3101 "parse.c"
        break;
      case 292:
#line 990 "parse.y"
{yygotominor.yy58 = OE_Fail;}
#line 3106 "parse.c"
        break;
      case 293:
#line 995 "parse.y"
{
  sqlite3DropTrigger(pParse,yymsp[0].minor.yy367);
}
#line 3113 "parse.c"
        break;
      case 294:
#line 1001 "parse.y"
{
  sqlite3Attach(pParse, &yymsp[-3].minor.yy144, &yymsp[-1].minor.yy144, yymsp[0].minor.yy300.type, &yymsp[0].minor.yy300.key);
}
#line 3120 "parse.c"
        break;
      case 295:
#line 1005 "parse.y"
{ yygotominor.yy300.type = 0; }
#line 3125 "parse.c"
        break;
      case 296:
#line 1006 "parse.y"
{ yygotominor.yy300.type=1; yygotominor.yy300.key = yymsp[0].minor.yy144; }
#line 3130 "parse.c"
        break;
      case 297:
#line 1007 "parse.y"
{ yygotominor.yy300.type=2; yygotominor.yy300.key = yymsp[0].minor.yy0; }
#line 3135 "parse.c"
        break;
      case 300:
#line 1013 "parse.y"
{
  sqlite3Detach(pParse, &yymsp[0].minor.yy144);
}
#line 3142 "parse.c"
        break;
      case 301:
#line 1019 "parse.y"
{sqlite3Reindex(pParse, 0, 0);}
#line 3147 "parse.c"
        break;
      case 302:
#line 1020 "parse.y"
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy144, &yymsp[0].minor.yy144);}
#line 3152 "parse.c"
        break;
      case 303:
#line 1025 "parse.y"
{sqlite3Analyze(pParse, 0, 0);}
#line 3157 "parse.c"
        break;
      case 304:
#line 1026 "parse.y"
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy144, &yymsp[0].minor.yy144);}
#line 3162 "parse.c"
        break;
      case 305:
#line 1031 "parse.y"
{
  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy367,&yymsp[0].minor.yy144);
}
#line 3169 "parse.c"
        break;
      case 306:
#line 1034 "parse.y"
{
  sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy144);
}
#line 3176 "parse.c"
        break;
      case 307:
#line 1037 "parse.y"
{
  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy367);
}
#line 3183 "parse.c"
































        break;
  };
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->yyidx -= yysize;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto);
  if( yyact < YYNSTATE ){
................................................................................
  if( pParse->zErrMsg==0 ){
    if( TOKEN.z[0] ){
      sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
    }else{
      sqlite3ErrorMsg(pParse, "incomplete SQL statement");
    }
  }
#line 3250 "parse.c"
  sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}

/*
** The following is executed when the parser accepts
*/
static void yy_accept(







|




|
|
|
|
|
|
<
<
|
>
>
>
|
|
|
<
|






|
|
|
|







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<







 







>


|
>
>
|

|
|
|

|



|





|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|
|
<

|
|
|

|

|
>
|
|
|

|
|
|
|
|
|
|

|
|

|
|

|

|
|
|
|
|
|

|
|
|
|
|

|
|
|
|







 







|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







|




|




|


|
>
>
>
>
>
|
|

|
|
|
|

|
|
|
|
|
|
|
|
|

|
|
|

|

|
|

|

|
|

|

<
<
<
<
<
<
<
<
<
<



|
|
>
>
>
>
>
>
>
>
>
|
|
|

>
|
|
|
|
|

|
|

|

|

|
|

|
|

|

|
|

|
|

|

|
|

|
|

|

<





|

>
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|

|
|

|
|

|

|
|

|
|

|

<
<
<
<
<

|
<
>
|



>
>
>
>
>
|
|

|
|
|
|
|

|
|
|
|

|
|

|


|

|
|

|


|

|
|
|
|
<
<
<
<
<



|
|



|
|


|
|
|



|
|



|
|

|
|
|
|



|
|


|
|
|



|
|



|
|



|
|


|
|
|



|
|



|
|



|
|


>
>
>
>

|
|
|

|
<
<
<
<
|
|
|
|



>
>
>
>
>
|
|

|
|
|
|

|
|
|
|

|
|

|
|

|

|
|
|
|
|

|
|
|
|

|
|
|
|
|

|
|

|

|

|
|

|

|

|
|

|

|

|
|

|
|

|

|
|
|
|
|

|
|

|
|
|

|

|

|
|
|
|

|
|

<
>

|

|
|
|
|
|

|
|
|
|
|
|
|

|
|

<
>

|

|
|

|

|

|
|


|
|

|

|
|
|
<
<
<
<
<
|



>
>
>
>
>
|
|

|
|

|
<
>

|

|
|
|
|

|
|

|
|
|
<
>
|

|
<
>
|


|

|
|

|
|
|
|
<
>
|

|
<
>
|


|

|
|

|

|

|
|
|
|

|
|
|
|

<

<
<
<
<

|
|
|



|
|


|
|
|


<
<
<
<
<
<
<
<
|
<
>
|


|
|
>
>





|
|


|
>
>
>
>
>
|
|
|


|

|
|

|
|
|
|
|


>

>
>
>
>
>

<
<
>
>

|

|
|

|
<
>

|

|
|
|
|
|

|
|
|
|

|
|
|
|

|
|
|
|

|
|
<
>
|

|
|
<
>
|

|
|
<
>
|

|
|
|
|

|
|
|
|
<
<
<
<
<



|
|


|
|
|


|
|
|

|
<
|
<
>
|




|
|

|
>
|
<
>
|



|
|

|
|
|
|


>
>
>
>
|



>
|
|
|

|
|
|
|
|

|
|

|
|
|

|

|
|

|
|
|

|

<
<
<
<
<
|



>
>
>
>
>


|


|

|
|

|
|

|

|
|

|
|
>
>
|
<
<
<
<
<
<
<

|




>
>
>
>
>
>
>
>


|
<
>

|

<







 







>
|
|
|

|
|
|
|

|
|
|
|

|
|

|
|
|
|

|
|
<
>

|
<
<
<
<
<
<
<
<




|
|

|




|
|

|




|
|

|




|
|

|


>
>
>
>
>
>
>

>
|

|
|

|

|
|

|
|

|

|
|

|
|

|

|
|

|
|
|
|
>
>
>
>
|
<
>

|

|
|

|
|
|

|

|
|

|

|
|

|
>
|
>
|
>
|

|

|
|

|
>
|
>
|
<
<
|
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
|
<
<
<
<
<



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106


107
108
109
110
111
112
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
...
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
...
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
...
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
....
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344

1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
....
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
....
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980










1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036

2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082





2083
2084

2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128





2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215




2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319

2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340

2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363





2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379

2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394

2395
2396
2397
2398

2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411

2412
2413
2414
2415

2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438

2439




2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455








2456

2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504


2505
2506
2507
2508
2509
2510
2511
2512
2513

2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540

2541
2542
2543
2544
2545

2546
2547
2548
2549
2550

2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562





2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579

2580

2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592

2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643





2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675







2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692

2693
2694
2695
2696

2697
2698
2699
2700
2701
2702
2703
....
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738

2739
2740
2741








2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819

2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858


2859








2860







2861





2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
....
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
**    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
**    YYNSTATE           the combined number of states.
**    YYNRULE            the number of rules in the grammar
**    YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
*/
#define YYCODETYPE unsigned char
#define YYNOCODE 247
#define YYACTIONTYPE unsigned short int
#define sqlite3ParserTOKENTYPE Token
typedef union {
  sqlite3ParserTOKENTYPE yy0;
  struct TrigEvent yy30;
  Expr* yy62;
  SrcList* yy151;
  Token yy198;
  struct LimitVal yy220;
  struct LikeOp yy222;


  IdList* yy240;
  int yy280;
  struct {int value; int mask;} yy359;
  TriggerStep* yy360;
  struct AttachKey yy361;
  Select* yy375;
  ExprList* yy418;

  int yy493;
} YYMINORTYPE;
#define YYSTACKDEPTH 100
#define sqlite3ParserARG_SDECL Parse *pParse;
#define sqlite3ParserARG_PDECL ,Parse *pParse
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
#define YYNSTATE 581
#define YYNRULE 311
#define YYERRORSYMBOL 146
#define YYERRSYMDT yy493
#define YYFALLBACK 1
#define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
#define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
#define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)

/* Next are that tables used to determine what action to take based on the
** current state and lookahead token.  These tables are used to implement
................................................................................
**  yy_shift_ofst[]    For each state, the offset into yy_action for
**                     shifting terminals.
**  yy_reduce_ofst[]   For each state, the offset into yy_action for
**                     shifting non-terminals after a reduce.
**  yy_default[]       Default action for each state.
*/
static const YYACTIONTYPE yy_action[] = {
 /*     0 */   286,  584,  113,  140,  142,  138,  144,  581,  150,  152,
 /*    10 */   154,  156,  158,  160,  162,  164,  166,  168,    3,  577,
 /*    20 */   740,  170,  178,  150,  152,  154,  156,  158,  160,  162,
 /*    30 */   164,  166,  168,  158,  160,  162,  164,  166,  168,  135,
 /*    40 */    97,  171,  181,  186,  191,  180,  185,  146,  148,  140,
 /*    50 */   142,  138,  144,   51,  150,  152,  154,  156,  158,  160,
 /*    60 */   162,  164,  166,  168,   16,   17,   18,  114,    7,  248,
 /*    70 */   150,  152,  154,  156,  158,  160,  162,  164,  166,  168,
 /*    80 */    13,   37,  362,   40,   59,   67,   69,  326,  357,  170,
 /*    90 */     6,    5,  331,   95,  364,  359,   25,  374,  258,  893,
 /*   100 */     1,  580,  514,   13,    4,  575,   33,  135,   97,  171,
 /*   110 */   181,  186,  191,  180,  185,  146,  148,  140,  142,  138,
 /*   120 */   144,    9,  150,  152,  154,  156,  158,  160,  162,  164,
 /*   130 */   166,  168,  374,  136,  592,   80,  112,   99,  269,   34,
 /*   140 */    32,   33,  132,  373,  115,   14,   15,  378,  333,   99,
 /*   150 */   380,  387,  392,   13,  367,  370,  194,  170,   78,  500,
 /*   160 */   525,  315,  395,  369,  375,  408,   10,   98,   14,   15,
 /*   170 */    78,  200,  286,  864,  113,  135,   97,  171,  181,  186,
 /*   180 */   191,  180,  185,  146,  148,  140,  142,  138,  144,   80,
 /*   190 */   150,  152,  154,  156,  158,  160,  162,  164,  166,  168,
 /*   200 */   104,  105,  106,  661,  496,  376,  374,  170,  467,   13,
 /*   210 */     2,   28,  237,    4,  409,   33,    3,  577,   14,   15,
 /*   220 */    51,  132,  133,  115,  241,  135,   97,  171,  181,  186,
 /*   230 */   191,  180,  185,  146,  148,  140,  142,  138,  144,  114,
 /*   240 */   150,  152,  154,  156,  158,  160,  162,  164,  166,  168,
 /*   250 */    40,   59,   67,   69,  326,  357,  136,   44,   45,  501,
 /*   260 */   473,  463,  359,   36,  361,  130,  128,  660,  275,   31,
 /*   270 */    84,   99,  356,  378,   14,   15,  380,  387,  392,   52,
 /*   280 */   170,  117,  122,  123,  113,  541,  369,  643,  395,  348,
 /*   290 */    98,   54,   78,  200,  302,   57,   58,  819,  135,   97,
 /*   300 */   171,  181,  186,  191,  180,  185,  146,  148,  140,  142,
 /*   310 */   138,  144,  861,  150,  152,  154,  156,  158,  160,  162,
 /*   320 */   164,  166,  168,  104,  105,  106,  817,   80,   48,  316,
 /*   330 */   162,  164,  166,  168,  319,  277,   12,   49,   99,  303,
 /*   340 */   283,  818,   99,  124,  304,   99,  241,  172,  593,  114,
 /*   350 */    50,  193,   46,  378,  170,   13,  380,  387,  392,   78,
 /*   360 */   260,  276,   47,   78,  200,   64,   78,  260,  395,  174,
 /*   370 */   175,  221,  135,   97,  171,  181,  186,  191,  180,  185,
 /*   380 */   146,  148,  140,  142,  138,  144,  199,  150,  152,  154,
 /*   390 */   156,  158,  160,  162,  164,  166,  168,  173,  252,  261,
 /*   400 */   120,  122,  123,  212,  170,  268,  254,  130,  128,  288,
 /*   410 */   590,  176,  246,  187,  192,  414,  195,  241,  197,  198,
 /*   420 */    14,   15,  135,   97,  171,  181,  186,  191,  180,  185,
 /*   430 */   146,  148,  140,  142,  138,  144,  433,  150,  152,  154,
 /*   440 */   156,  158,  160,  162,  164,  166,  168,  311,   99,  707,
 /*   450 */    99,  422,  708,  417,  275,   81,  318,  598,   99,  219,
 /*   460 */    13,  231,  124,   13,  176,   48,  187,  192,   20,   78,
 /*   470 */   317,   78,  214,  195,   49,  197,  198,  462,  170,   78,
 /*   480 */   200,  116,   27,   13,  410,  113,  591,   50,   80,  225,
 /*   490 */   195,   11,  197,  198,  506,  235,  135,   97,  171,  181,
 /*   500 */   186,  191,  180,  185,  146,  148,  140,  142,  138,  144,
 /*   510 */    80,  150,  152,  154,  156,  158,  160,  162,  164,  166,
 /*   520 */   168,  277,  215,  324,  606,   14,   15,  301,   14,   15,
 /*   530 */   512,   13,  508,  240,  196,  486,  195,  685,  197,  198,
 /*   540 */    22,  834,  445,  331,  462,  170,  444,  276,   14,   15,
 /*   550 */   114,  468,  278,  394,  599,  280,  470,  288,  446,  680,
 /*   560 */    13,  321,  404,  135,   97,  171,  181,  186,  191,  180,
 /*   570 */   185,  146,  148,  140,  142,  138,  144,   80,  150,  152,
 /*   580 */   154,  156,  158,  160,  162,  164,  166,  168,   74,   99,
 /*   590 */   540,  366,   73,   99,  352,  289,   14,   15,  176,  333,
 /*   600 */   187,  192,  486,  869,  359,  273,  283,  542,  543,  867,
 /*   610 */    78,  500,  510,  170,   78,  323,  682,  176,  472,  187,
 /*   620 */   192,  746,  118,  470,  119,   14,   15,  195,  346,  197,
 /*   630 */   198,  135,   97,  171,  181,  186,  191,  180,  185,  146,
 /*   640 */   148,  140,  142,  138,  144,   99,  150,  152,  154,  156,
 /*   650 */   158,  160,  162,  164,  166,  168,  532,  334,  341,  343,
 /*   660 */   841,   39,  195,  170,  197,  198,   78,   94,  124,  356,
 /*   670 */   271,  353,  439,  441,  440,  544,  883,  428,   72,  862,
 /*   680 */   288,  135,   97,  171,  181,  186,  191,  180,  185,  146,
 /*   690 */   148,  140,  142,  138,  144,   13,  150,  152,  154,  156,
 /*   700 */   158,  160,  162,  164,  166,  168,  195,   99,  197,  198,
 /*   710 */   406,  330,  195,  170,  197,  198,  568,  405,  306,  195,
 /*   720 */    42,  197,  198,   65,  195,  539,  197,  198,   78,   96,
 /*   730 */    66,  135,   97,  171,  181,  186,  191,  180,  185,  146,
 /*   740 */   148,  140,  142,  138,  144,  885,  150,  152,  154,  156,
 /*   750 */   158,  160,  162,  164,  166,  168,   99,  740,   99,  298,
 /*   760 */    14,   15,  272,  170,   13,   74,  572,   86,  600,   73,
 /*   770 */   126,  127,  614,  709,  309,  478,   24,   78,  247,   78,
 /*   780 */   111,  135,   97,  171,  181,  186,  191,  180,  185,  146,
 /*   790 */   148,  140,  142,  138,  144,   99,  150,  152,  154,  156,
 /*   800 */   158,  160,  162,  164,  166,  168,   99,  238,  113,  239,
 /*   810 */   295,   26,  296,  170,  338,  337,   78,  137,  294,  320,
 /*   820 */   347,  239,  348,  390,  211,  348,   30,   78,  139,   14,
 /*   830 */    15,  135,  189,  171,  181,  186,  191,  180,  185,  146,
 /*   840 */   148,  140,  142,  138,  144,   99,  150,  152,  154,  156,
 /*   850 */   158,  160,  162,  164,  166,  168,   99,   80,   99,  372,
 /*   860 */   399,  442,  348,  170,  298,  243,   78,  141,  363,  601,
 /*   870 */   428,  437,  438,  114,  411,  269,  605,   78,  143,   78,
 /*   880 */   145,  448,   97,  171,  181,  186,  191,  180,  185,  146,
 /*   890 */   148,  140,  142,  138,  144,   99,  150,  152,  154,  156,
 /*   900 */   158,  160,  162,  164,  166,  168,   99,   80,   99,  430,
 /*   910 */    99,  296,  555,  170,  413,  856,   78,  147,  672,  457,
 /*   920 */   352,  348,  298,  443,  465,   45,   35,   78,  149,   78,
 /*   930 */   151,   78,  153,  171,  181,  186,  191,  180,  185,  146,
 /*   940 */   148,  140,  142,  138,  144,   99,  150,  152,  154,  156,
 /*   950 */   158,  160,  162,  164,  166,  168,   99,  459,   99,   29,
 /*   960 */    79,  464,  183,  483,   71,  339,   78,  155,  709,  421,
 /*   970 */   428,   79,  109,   99,  491,   71,  296,   78,  157,   78,
 /*   980 */   159,  490,  243,  109,   99,  340,   99,  449,  857,  223,
 /*   990 */    99,  460,  182,  709,   78,  161,   99,  349,  827,  136,
 /*  1000 */   223,   99,   80,  201,   99,   78,  163,   78,  165,  507,
 /*  1010 */   136,   78,  167,   42,  201,   38,  493,   78,  169,  569,
 /*  1020 */   207,  205,   78,  177,  674,   78,  179,  477,  203,   76,
 /*  1030 */    77,  207,  205,   98,   99,   84,   99,   42,  336,  203,
 /*  1040 */    76,   77,   99,   43,   98,   41,  428,   79,  494,   80,
 /*  1050 */   428,   71,   84,   99,  352,   78,  188,   78,  190,  109,
 /*  1060 */   499,  428,  497,   78,  202,   60,  104,  105,  106,  107,
 /*  1070 */   108,  209,  213,   99,   78,  204,  223,  104,  105,  106,
 /*  1080 */   107,  108,  209,  213,  820,  509,  136,   53,  383,  511,
 /*  1090 */   201,   99,   56,   61,   78,  206,   55,  428,  428,  889,
 /*  1100 */   513,   99,  243,   99,  352,   99,   79,  207,  205,  312,
 /*  1110 */    71,   99,   78,  208,  483,  203,   76,   77,  109,  533,
 /*  1120 */    98,  497,   78,  220,   78,  222,   78,  232,   84,   99,
 /*  1130 */   428,  353,   78,  234,  352,  223,  517,  521,  389,   99,
 /*  1140 */    62,  530,   99,   64,   63,  136,   68,  529,   70,  201,
 /*  1150 */    78,  236,  352,  104,  105,  106,  107,  108,  209,  213,
 /*  1160 */    78,  249,   99,   78,  265,  877,  207,  205,  398,  527,
 /*  1170 */    99,  615,  616,  313,  203,   76,   77,   99,  523,   98,
 /*  1180 */    80,  353,    8,   78,  270,   99,  456,   19,   21,   23,
 /*  1190 */   412,   78,  300,   75,   78,  310,   82,   84,   78,  365,
 /*  1200 */   563,   83,  547,   99,   87,  553,   78,  393,   85,  557,
 /*  1210 */    99,  353,  104,  105,  106,  107,  108,  209,  213,   99,
 /*  1220 */   269,  536,   99,  467,   78,  434,   88,  266,  534,  353,
 /*  1230 */   560,   78,  481,  566,  264,   89,  250,   90,   93,   91,
 /*  1240 */    78,  485,  101,   78,  498,   92,  100,  102,  103,  110,
 /*  1250 */   131,  121,  134,  125,  129,  168,  184,  242,  686,  687,
 /*  1260 */   688,  210,  233,  218,  224,  216,  227,  226,  217,  229,
 /*  1270 */   228,  230,  243,  251,  515,  519,  463,  245,  253,  244,
 /*  1280 */   505,  257,  255,  256,  258,   84,  259,  262,  263,  239,
 /*  1290 */   267,  279,  274,  281,  282,  299,  285,  292,  284,  287,
 /*  1300 */   290,  293,  297,  305,  314,  291,  307,  322,  308,  325,
 /*  1310 */   327,  345,  329,  328,  332,  350,  354,  330,  358,  335,
 /*  1320 */   342,  379,  381,  382,  344,  351,  368,  385,  355,  371,
 /*  1330 */   388,  360,  396,  397,  400,  401,  415,   54,  416,  386,
 /*  1340 */   384,  391,  418,  402,  407,  419,  377,  420,  423,  424,
 /*  1350 */   403,  426,  425,  427,  429,  435,  431,  849,  436,  854,
 /*  1360 */   432,  855,  450,  447,  451,  452,  454,  453,  825,  455,
 /*  1370 */   458,  826,  469,  461,  466,  747,  748,  848,  471,  464,
 /*  1380 */   863,  480,  474,  475,  476,  482,  865,  479,  487,  484,
 /*  1390 */   489,  488,  492,  866,  495,  868,  504,  679,  502,  681,
 /*  1400 */   833,  875,  518,  503,  516,  739,  520,  524,  522,  742,
 /*  1410 */   745,  531,  526,  835,  535,  528,  538,  537,  836,  837,
 /*  1420 */   838,  839,  545,  546,  840,  550,  876,  556,  551,  878,
 /*  1430 */   548,  549,  554,  879,  559,  882,  884,  562,  886,  561,
 /*  1440 */   552,  558,  564,  567,  570,  565,  571,  887,  576,  574,
 /*  1450 */   573,  888,  578,  559,  559,  579,
};
static const YYCODETYPE yy_lookahead[] = {
 /*     0 */    28,   11,   30,   77,   78,   79,   80,    0,   82,   83,
 /*    10 */    84,   85,   86,   87,   88,   89,   90,   91,   11,   12,
 /*    20 */    11,   49,   81,   82,   83,   84,   85,   86,   87,   88,
 /*    30 */    89,   90,   91,   86,   87,   88,   89,   90,   91,   67,
 /*    40 */    68,   69,   70,   71,   72,   73,   74,   75,   76,   77,
 /*    50 */    78,   79,   80,   69,   82,   83,   84,   85,   86,   87,
 /*    60 */    88,   89,   90,   91,   17,   18,   19,   95,   11,   29,
 /*    70 */    82,   83,   84,   85,   86,   87,   88,   89,   90,   91,
 /*    80 */    30,   97,   98,   99,  100,  101,  102,  103,  104,   49,
 /*    90 */   150,  151,   50,   53,   26,  111,  156,  155,   30,  147,
 /*   100 */   148,  149,  162,   30,  152,  163,  164,   67,   68,   69,
 /*   110 */    70,   71,   72,   73,   74,   75,   76,   77,   78,   79,
 /*   120 */    80,  153,   82,   83,   84,   85,   86,   87,   88,   89,
 /*   130 */    90,   91,  155,   65,   11,  195,   28,  155,  129,  165,
 /*   140 */   163,  164,  168,  169,  170,   95,   96,   97,  106,  155,
 /*   150 */   100,  101,  102,   30,   86,   87,  162,   49,  176,  177,
 /*   160 */   220,   88,  112,   95,  187,  188,  154,   99,   95,   96,
 /*   170 */   176,  177,   28,   21,   30,   67,   68,   69,   70,   71,
 /*   180 */    72,   73,   74,   75,   76,   77,   78,   79,   80,  195,
 /*   190 */    82,   83,   84,   85,   86,   87,   88,   89,   90,   91,
 /*   200 */   132,  133,  134,   27,  222,   29,  155,   49,   56,   30,
 /*   210 */   149,  160,  218,  152,  163,  164,   11,   12,   95,   96,
 /*   220 */    69,  168,  169,  170,  230,   67,   68,   69,   70,   71,
 /*   230 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   95,
 /*   240 */    82,   83,   84,   85,   86,   87,   88,   89,   90,   91,
 /*   250 */    99,  100,  101,  102,  103,  104,   65,  192,  193,  107,
 /*   260 */   108,  109,  111,  174,  175,   86,   87,   27,   29,   29,
 /*   270 */   118,  155,  183,   97,   95,   96,  100,  101,  102,   99,
 /*   280 */    49,  171,  172,  173,   30,  106,   95,   27,  112,   29,
 /*   290 */    99,  111,  176,  177,  162,   17,   18,  139,   67,   68,
 /*   300 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   78,
 /*   310 */    79,   80,   15,   82,   83,   84,   85,   86,   87,   88,
 /*   320 */    89,   90,   91,  132,  133,  134,   21,  195,   22,   27,
 /*   330 */    88,   89,   90,   91,  218,   96,  155,   31,  155,  207,
 /*   340 */   208,   21,  155,  233,  212,  155,  230,   49,   11,   95,
 /*   350 */    44,   26,   46,   97,   49,   30,  100,  101,  102,  176,
 /*   360 */   177,  122,   56,  176,  177,  105,  176,  177,  112,   71,
 /*   370 */    72,  140,   67,   68,   69,   70,   71,   72,   73,   74,
 /*   380 */    75,   76,   77,   78,   79,   80,   27,   82,   83,   84,
 /*   390 */    85,   86,   87,   88,   89,   90,   91,   99,  215,  216,
 /*   400 */   171,  172,  173,   27,   49,  218,  216,   86,   87,  168,
 /*   410 */    11,  223,  224,  225,  226,   24,  114,  230,  116,  117,
 /*   420 */    95,   96,   67,   68,   69,   70,   71,   72,   73,   74,
 /*   430 */    75,   76,   77,   78,   79,   80,  139,   82,   83,   84,
 /*   440 */    85,   86,   87,   88,   89,   90,   91,  206,  155,   27,
 /*   450 */   155,   60,   27,   62,   29,  162,   27,   11,  155,  139,
 /*   460 */    30,  141,  233,   30,  223,   22,  225,  226,  154,  176,
 /*   470 */   177,  176,  177,  114,   31,  116,  117,  162,   49,  176,
 /*   480 */   177,   26,   26,   30,   28,   30,   11,   44,  195,   46,
 /*   490 */   114,   16,  116,  117,   24,  140,   67,   68,   69,   70,
 /*   500 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
 /*   510 */   195,   82,   83,   84,   85,   86,   87,   88,   89,   90,
 /*   520 */    91,   96,  227,   27,   11,   95,   96,   26,   95,   96,
 /*   530 */    60,   30,   62,  230,  115,  220,  114,  118,  116,  117,
 /*   540 */   154,   11,   32,   50,  162,   49,   36,  122,   95,   96,
 /*   550 */    95,  236,  122,  178,   11,  122,  241,  168,   48,   11,
 /*   560 */    30,   88,   69,   67,   68,   69,   70,   71,   72,   73,
 /*   570 */    74,   75,   76,   77,   78,   79,   80,  195,   82,   83,
 /*   580 */    84,   85,   86,   87,   88,   89,   90,   91,  115,  155,
 /*   590 */   155,   27,  119,  155,  155,  206,   95,   96,  223,  106,
 /*   600 */   225,  226,  220,   11,  111,  207,  208,  172,  173,   11,
 /*   610 */   176,  177,  142,   49,  176,  177,   11,  223,  236,  225,
 /*   620 */   226,   11,   27,  241,   29,   95,   96,  114,  189,  116,
 /*   630 */   117,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   640 */    76,   77,   78,   79,   80,  155,   82,   83,   84,   85,
 /*   650 */    86,   87,   88,   89,   90,   91,  222,  107,  108,  109,
 /*   660 */    11,  175,  114,   49,  116,  117,  176,  177,  233,  183,
 /*   670 */    29,  232,  107,  108,  109,   26,   11,  155,   26,   15,
 /*   680 */   168,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   690 */    76,   77,   78,   79,   80,   30,   82,   83,   84,   85,
 /*   700 */    86,   87,   88,   89,   90,   91,  114,  155,  116,  117,
 /*   710 */   183,  184,  114,   49,  116,  117,  194,  190,  206,  114,
 /*   720 */   106,  116,  117,   34,  114,   76,  116,  117,  176,  177,
 /*   730 */    41,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   740 */    76,   77,   78,   79,   80,   11,   82,   83,   84,   85,
 /*   750 */    86,   87,   88,   89,   90,   91,  155,   11,  155,  155,
 /*   760 */    95,   96,  121,   49,   30,  115,  244,  198,   11,  119,
 /*   770 */   132,  133,  120,   28,  205,   29,  154,  176,  177,  176,
 /*   780 */   177,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   790 */    76,   77,   78,   79,   80,  155,   82,   83,   84,   85,
 /*   800 */    86,   87,   88,   89,   90,   91,  155,   27,   30,   29,
 /*   810 */    27,  157,   29,   49,   98,   99,  176,  177,  214,   27,
 /*   820 */    27,   29,   29,   27,  162,   29,   27,  176,  177,   95,
 /*   830 */    96,   67,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   840 */    76,   77,   78,   79,   80,  155,   82,   83,   84,   85,
 /*   850 */    86,   87,   88,   89,   90,   91,  155,  195,  155,  167,
 /*   860 */    27,   52,   29,   49,  155,  120,  176,  177,  176,   11,
 /*   870 */   155,   58,   59,   95,  162,  129,   11,  176,  177,  176,
 /*   880 */   177,   25,   68,   69,   70,   71,   72,   73,   74,   75,
 /*   890 */    76,   77,   78,   79,   80,  155,   82,   83,   84,   85,
 /*   900 */    86,   87,   88,   89,   90,   91,  155,  195,  155,  194,
 /*   910 */   155,   29,  134,   49,  158,  106,  176,  177,   11,   27,
 /*   920 */   155,   29,  155,  214,  192,  193,  166,  176,  177,  176,
 /*   930 */   177,  176,  177,   69,   70,   71,   72,   73,   74,   75,
 /*   940 */    76,   77,   78,   79,   80,  155,   82,   83,   84,   85,
 /*   950 */    86,   87,   88,   89,   90,   91,  155,  101,  155,  161,
 /*   960 */    26,   67,   69,  155,   30,   37,  176,  177,  106,  162,
 /*   970 */   155,   26,   38,  155,   27,   30,   29,  176,  177,  176,
 /*   980 */   177,  214,  120,   38,  155,   57,  155,  231,  106,   55,
 /*   990 */   155,  235,   99,   11,  176,  177,  155,  232,  142,   65,
 /*  1000 */    55,  155,  195,   69,  155,  176,  177,  176,  177,  194,
 /*  1010 */    65,  176,  177,  106,   69,  155,  162,  176,  177,   64,
 /*  1020 */    86,   87,  176,  177,  130,  176,  177,  219,   94,   95,
 /*  1030 */    96,   86,   87,   99,  155,  118,  155,  106,  110,   94,
 /*  1040 */    95,   96,  155,   39,   99,  178,  155,   26,  131,  195,
 /*  1050 */   155,   30,  118,  155,  155,  176,  177,  176,  177,   38,
 /*  1060 */    27,  155,   29,  176,  177,   51,  132,  133,  134,  135,
 /*  1070 */   136,  137,  138,  155,  176,  177,   55,  132,  133,  134,
 /*  1080 */   135,  136,  137,  138,  139,  194,   65,  178,  189,  194,
 /*  1090 */    69,  155,   47,  179,  176,  177,  186,  155,  155,  144,
 /*  1100 */   194,  155,  120,  155,  155,  155,   26,   86,   87,   88,
 /*  1110 */    30,  155,  176,  177,  155,   94,   95,   96,   38,   27,
 /*  1120 */    99,   29,  176,  177,  176,  177,  176,  177,  118,  155,
 /*  1130 */   155,  232,  176,  177,  155,   55,  194,  194,  189,  155,
 /*  1140 */   178,  131,  155,  105,  180,   65,  178,  162,   26,   69,
 /*  1150 */   176,  177,  155,  132,  133,  134,  135,  136,  137,  138,
 /*  1160 */   176,  177,  155,  176,  177,   11,   86,   87,  189,  194,
 /*  1170 */   155,  120,  120,  155,   94,   95,   96,  155,  219,   99,
 /*  1180 */   195,  232,   15,  176,  177,  155,  189,   20,   21,   22,
 /*  1190 */    23,  176,  177,  197,  176,  177,  196,  118,  176,  177,
 /*  1200 */    33,  195,   35,  155,  199,   51,  176,  177,  197,   42,
 /*  1210 */   155,  232,  132,  133,  134,  135,  136,  137,  138,  155,
 /*  1220 */   129,   54,  155,   56,  176,  177,  200,  126,   61,  232,
 /*  1230 */    63,  176,  177,   66,  127,  201,  124,  202,  128,  203,
 /*  1240 */   176,  177,  155,  176,  177,  204,  120,  120,  155,   26,
 /*  1250 */   168,   27,   27,  234,  234,   91,   99,  155,  118,  118,
 /*  1260 */   118,   26,  139,   21,   26,  228,  193,   27,  229,  155,
 /*  1270 */    29,   27,  120,  125,  107,  108,  109,  159,   29,  155,
 /*  1280 */   113,  104,  217,  179,   30,  118,  167,  217,  179,   29,
 /*  1290 */   125,  155,  209,  155,  122,  106,  159,  123,  155,  155,
 /*  1300 */   210,   26,  155,   27,  120,  211,  210,   27,  211,  178,
 /*  1310 */   155,   26,  182,  181,  155,  217,  217,  184,  167,  185,
 /*  1320 */   185,  155,   51,   26,  185,  179,  176,   27,  179,  176,
 /*  1330 */    26,  186,   51,   26,  103,  155,  155,  111,  159,  178,
 /*  1340 */   180,  178,  155,  181,  188,  159,  188,   28,  155,  159,
 /*  1350 */   182,  238,  237,  106,  159,   45,  239,   15,   43,  106,
 /*  1360 */   240,  106,  142,   52,  155,  159,  155,  106,   11,   26,
 /*  1370 */   178,  142,   21,   15,  191,  130,  130,   11,   11,   67,
 /*  1380 */    21,   76,  191,  155,  110,  200,   11,  155,  130,   76,
 /*  1390 */    26,  155,  221,   11,   26,   11,  200,   11,  121,   11,
 /*  1400 */    11,   11,  200,  155,  121,   11,  191,  200,  110,   11,
 /*  1410 */    11,   26,  130,   11,  155,  221,  159,  155,   11,   11,
 /*  1420 */    11,   11,  155,   27,   11,   28,   11,   40,  155,   11,
 /*  1430 */   242,  168,  168,   11,  155,   11,   11,  159,   11,  155,
 /*  1440 */   243,  242,  155,   24,  143,  159,  155,   11,  145,  245,
 /*  1450 */   144,   11,   13,  246,  246,   14,
};
#define YY_SHIFT_USE_DFLT (-75)
static const short yy_shift_ofst[] = {
 /*     0 */   205,    7,  -75,  -75, 1167,  -10,   57,  -75,   47,  475,
 /*    10 */   399,  123,  337,  -75,  -75,  -75,  -75,  -75,  -75,  475,
 /*    20 */   446,  475,  543,  475,  757,  456,  858,  453,  240,  799,
 /*    30 */   865,   50,  -75,  254,  -75,  -16,  -75,  453,  151,  -75,
 /*    40 */   931,  -75, 1004,  306,  -75,  -75,  -75,  -75,  -75,  -75,
 /*    50 */   -75,  180,  931,  -75, 1045,  -75,  278,  -75,  -75, 1014,
 /*    60 */   689,  931, 1038,  -75,  -75,  -75,  -75,  931,  -75, 1122,
 /*    70 */  1080,  652,  473,  -75,  -75, 1080, 1051, 1052,  -75,  934,
 /*    80 */   -75,  302, 1079,  -75,  650,  -75,  641, 1091, 1101, 1107,
 /*    90 */  1112, 1110,  -75, 1080,   40, 1080,  714, 1080,  -75, 1126,
 /*   100 */   453, 1127,  453,  -75,  -75,  -75,  -75,  -75,  -75, 1223,
 /*   110 */  1080,  108,  254,  -75,  -75,  455,  321,  595,  -75,  321,
 /*   120 */  1224,  -75,  -75,  -75,  638,  -75,  -75,  -75,  638,  -75,
 /*   130 */   -75,  -75,  -75, 1225,  -75, 1080,  -75,  814, 1080,  -12,
 /*   140 */  1080,  -12, 1080,  -12, 1080,  -12, 1080,  -74, 1080,  -74,
 /*   150 */  1080,  -53, 1080,  -53, 1080,  -53, 1080,  -53, 1080,  242,
 /*   160 */  1080,  242, 1080, 1164, 1080, 1164, 1080, 1164, 1080,  -75,
 /*   170 */   -75,  298,  -75,  -75,  -75,  -75, 1080,  -59, 1080,  -12,
 /*   180 */   -75,  893,  -75, 1157,  -75,  -75,  -75, 1080,  764, 1080,
 /*   190 */   -74,  -75,  325,  934,  359,  419, 1140, 1141, 1142,  -75,
 /*   200 */   714, 1080,  864, 1080,  -75, 1080,  -75, 1080,  -75, 1235,
 /*   210 */  1079,  376,  -75,  945,  158, 1123,  320, 1242,  -75, 1080,
 /*   220 */   231, 1080,  714, 1238,  443, 1240,  -75, 1241,  453, 1244,
 /*   230 */   -75, 1080,  305, 1080,  355, 1080,  714,  780,  -75, 1080,
 /*   240 */   -75,  -75, 1152,  453,  -75,  -75,  -75,  864, 1080,  714,
 /*   250 */  1148, 1080, 1249, 1080, 1177,  689,  -75, 1254,  -75,  -75,
 /*   260 */   714, 1177,  689,  -75, 1080,  714, 1165, 1080, 1260, 1080,
 /*   270 */   714,  -75,  -75,  239,  -75,  -75,  -75,  430,  -75,  433,
 /*   280 */   -75, 1172,  -75,  501, 1152,  144,  453,  -75,  -75, 1189,
 /*   290 */  1174,  -75, 1275,  453,  783,  -75,  453,  -75,  -75, 1080,
 /*   300 */   714, 1079,  422,  425, 1276,  144, 1189, 1174,  -75, 1021,
 /*   310 */   -28,  -75,  -75, 1184,   73,  -75,  -75,  429,  -75,  792,
 /*   320 */   -75, 1280,  -75,  496,  931,  -75,  453, 1285,  -75,   42,
 /*   330 */   -75,  453,  -75,  550,  928,  -75,  716,  -75,  -75,  -75,
 /*   340 */   -75,  928,  -75,  928,  -75,  453,  793,  -75,  453, 1177,
 /*   350 */   689,  -75,  -75, 1177,  689,  -75,  -75, 1254,  -75, 1045,
 /*   360 */   -75,  -75,   68,  -75, 1080,  564,  -75,  191,  -75,  -75,
 /*   370 */   191,  -75,  -75,  -75,  -75,  176,  256,  -75,  453,  -75,
 /*   380 */  1271, 1297,  453,  260, 1300,  931,  -75, 1304,  453,  796,
 /*   390 */   931,  -75, 1080,  614,  -75, 1281, 1307,  453,  833, 1231,
 /*   400 */   453, 1285,  -75,  493, 1226,  -75,  -75,  -75,  -75,  -75,
 /*   410 */  1079,  513,  856,  391,  453, 1152,  -75,  453,  745, 1319,
 /*   420 */  1079,  548,  453, 1152,  510,  565, 1247,  453, 1152,  -75,
 /*   430 */  1310,  297, 1342, 1080,  664, 1315,  813,  -75,  -75, 1253,
 /*   440 */  1255,  809,  453,  882,  -75,  -75, 1311,  -75,  -75, 1220,
 /*   450 */   453,  862, 1261,  453, 1343,  453,  892,  907, 1357, 1229,
 /*   460 */  1358,  152,  592,  894,  306,  -75, 1245, 1246, 1351, 1366,
 /*   470 */  1367,  152, 1359, 1312,  453, 1274,  453,  746,  453, 1305,
 /*   480 */  1080,  714, 1375, 1313, 1080,  714, 1258,  453, 1364,  453,
 /*   490 */   947,  -75,  917,  598, 1368, 1080, 1033, 1080,  714, 1382,
 /*   500 */   714, 1277,  453,    9, 1384,  470,  453, 1386,  453, 1388,
 /*   510 */   453, 1389,  453, 1390,  605, 1283,  453,    9, 1394, 1312,
 /*   520 */   453, 1298,  453,  746, 1398, 1282,  453, 1364, 1010,  610,
 /*   530 */  1385, 1080, 1092, 1399,  530, 1402,  453, 1152,  649,  179,
 /*   540 */  1407, 1408, 1409, 1410,  453, 1396, 1413, 1387,  254, 1397,
 /*   550 */   453, 1154, 1415,  778, 1418, 1422,  -75, 1387,  453, 1424,
 /*   560 */   665,  982, 1425,  734,  982, 1427, 1419,  453,  955, 1301,
 /*   570 */   453, 1436, 1306, 1303,  453, 1440,  -75, 1439, 1441,  -75,
 /*   580 */   -75,
};
#define YY_REDUCE_USE_DFLT (-61)
static const short yy_reduce_ofst[] = {
 /*     0 */   -48,   61,  -61,  -61,  -60,  -61,  -61,  -61,  -32,   12,
 /*    10 */   -61,  181,  -61,  -61,  -61,  -61,  -61,  -61,  -61,  314,
 /*    20 */   -61,  386,  -61,  622,  -61,  654,  -61,   51,  798,  -61,
 /*    30 */   -61,  -23,  -61,  -26,  760,   89,  -61,  860,  486,  -61,
 /*    40 */   867,  -61,  -61,   65,  -61,  -61,  -61,  -61,  -61,  -61,
 /*    50 */   -61,  -61,  909,  -61,  910,  -61,  -61,  -61,  -61,  -61,
 /*    60 */   914,  962,  964,  -61,  -61,  -61,  -61,  968,  -61,  -61,
 /*    70 */   438,  -61,  996,  -61,  -61,  116,  -61,  -61,  -61,  293,
 /*    80 */   -61, 1000, 1006,  -61, 1011,  569, 1005, 1026, 1034, 1035,
 /*    90 */  1036, 1041,  -61,  490,  394,  552,  394,  601,  -61,  -61,
 /*   100 */  1087,  -61, 1093,  -61,  -61,  -61,  -61,  -61,  -61,  -61,
 /*   110 */   603,  394,   53,  -61,  -61, 1082,  110,  -61,  -61,  229,
 /*   120 */   -61,  -61,  -61,  -61, 1019,  -61,  -61,  -61, 1020,  -61,
 /*   130 */   -61,  -61,  -61,  -61,  -61,  640,  -61,  394,  651,  394,
 /*   140 */   690,  394,  701,  394,  703,  394,  740,  394,  751,  394,
 /*   150 */   753,  394,  755,  394,  790,  394,  801,  394,  803,  394,
 /*   160 */   818,  394,  829,  394,  831,  394,  835,  394,  841,  394,
 /*   170 */   -61,  -61,  -61,  -61,  -61,  -61,  846,  188,  849,  394,
 /*   180 */   -61,  -61,  -61,  -61,  -61,  -61,  -61,  879,  394,  881,
 /*   190 */   394,  -61, 1102,   -6, 1000,  -61,  -61,  -61,  -61,  -61,
 /*   200 */   394,  887,  394,  898,  394,  918,  394,  936,  394,  -61,
 /*   210 */   662, 1000,  -61,  295,  394, 1037, 1039,  -61,  -61,  946,
 /*   220 */   394,  948,  394,  -61, 1073,  -61,  -61,  -61, 1114,  -61,
 /*   230 */   -61,  950,  394,  956,  394,  974,  394,  -61,  -61,  303,
 /*   240 */   -61,  -61, 1118, 1124,  -61,  -61,  -61,  394,  984,  394,
 /*   250 */   -61,  183,  -61,  190, 1065, 1104,  -61, 1119,  -61,  -61,
 /*   260 */   394, 1070, 1109,  -61,  987,  394,  -61,  187,  -61, 1007,
 /*   270 */   394,  -61,  398, 1083,  -61,  -61,  -61, 1136,  -61, 1138,
 /*   280 */   -61,  -61,  -61, 1143, 1137,  389, 1144,  -61,  -61, 1090,
 /*   290 */  1094,  -61,  -61,  604,  -61,  -61, 1147,  -61,  -61, 1015,
 /*   300 */   394,  132, 1000, 1083,  -61,  512, 1096, 1097,  -61, 1018,
 /*   310 */   241,  -61,  -61,  -61, 1087,  -61,  -61,  394,  -61,  -61,
 /*   320 */   -61,  -61,  -61,  394, 1131,  -61, 1155, 1132, 1130, 1133,
 /*   330 */   -61, 1159,  -61,  -61, 1134,  -61,  -61,  -61,  -61,  -61,
 /*   340 */   -61, 1135,  -61, 1139,  -61,  439,  -61,  -61,  765, 1098,
 /*   350 */  1146,  -61,  -61, 1099, 1149,  -61,  -61, 1151,  -61, 1145,
 /*   360 */   -61,  -61,  692,  -61, 1022,  394,  -61, 1150,  -61,  -61,
 /*   370 */  1153,  -61,  -61,  -61,  -61, 1156, 1158,  -61, 1166,  -61,
 /*   380 */   -61,  -61,  899, 1160,  -61, 1161,  -61,  -61,  949,  -61,
 /*   390 */  1163,  -61, 1030,  375,  -61,  -61,  -61,  979,  -61,  -61,
 /*   400 */  1180, 1162, 1168,  527,  -61,  -61,  -61,  -61,  -61,  -61,
 /*   410 */   712, 1000,  756,  -61, 1181, 1179,  -61, 1187, 1186,  -61,
 /*   420 */   807, 1000, 1193, 1190, 1115, 1113,  -61,  715, 1195,  -61,
 /*   430 */  1117, 1120,  -61, 1048,  394,  -61,  -61,  -61,  -61,  -61,
 /*   440 */   -61,  -61,  709,  -61,  -61,  -61,  -61,  -61,  -61,  -61,
 /*   450 */  1209, 1206,  -61, 1211,  -61,  997,  -61, 1192,  -61,  -61,
 /*   460 */   -61,  315, 1000, 1183,  732,  -61,  -61,  -61,  -61,  -61,
 /*   470 */   -61,  382,  -61, 1191, 1228,  -61,  808, 1185, 1232,  -61,
 /*   480 */  1055,  394,  -61,  -61, 1064,  394,  -61, 1236, 1171,  767,
 /*   490 */   -61,  -61,  854, 1000,  -61,  -18,  -61, 1067,  394,  -61,
 /*   500 */   394,  -61, 1248, 1196,  -61,  -61,  815,  -61,  891,  -61,
 /*   510 */   895,  -61,  906,  -61, 1000,  -61,  942, 1202,  -61, 1215,
 /*   520 */   943,  -61,  959, 1207,  -61,  -61,  975, 1194,  985, 1000,
 /*   530 */   -61,  434,  -61,  -61, 1259,  -61, 1262, 1257,  -61,  435,
 /*   540 */   -61,  -61,  -61,  -61, 1267,  -61,  -61, 1188, 1263,  -61,
 /*   550 */  1273, 1197,  -61, 1264,  -61,  -61,  -61, 1199, 1279,  -61,
 /*   560 */  1284, 1278,  -61, 1287, 1286,  -61,  -61,  522,  -61,  -61,
 /*   570 */  1291,  -61,  -61, 1204,  -58,  -61,  -61,  -61,  -61,  -61,
 /*   580 */   -61,
};
static const YYACTIONTYPE yy_default[] = {
 /*     0 */   587,  587,  582,  585,  892,  892,  892,  586,  594,  892,
 /*    10 */   892,  892,  892,  614,  615,  616,  595,  596,  597,  892,
 /*    20 */   892,  892,  892,  892,  892,  892,  892,  892,  892,  892,
 /*    30 */   892,  892,  607,  617,  627,  609,  626,  892,  892,  628,
 /*    40 */   672,  635,  892,  892,  673,  676,  677,  678,  872,  873,
 /*    50 */   874,  892,  672,  636,  657,  655,  892,  658,  659,  892,
 /*    60 */   728,  672,  643,  637,  644,  726,  727,  672,  638,  892,
 /*    70 */   892,  758,  692,  690,  691,  824,  764,  759,  755,  892,
 /*    80 */   683,  892,  892,  684,  692,  694,  701,  740,  731,  733,
 /*    90 */   721,  735,  689,  892,  736,  892,  737,  892,  757,  892,
 /*   100 */   892,  760,  892,  761,  762,  763,  765,  766,  767,  892,
 /*   110 */   892,  892,  892,  612,  613,  619,  847,  892,  620,  847,
 /*   120 */   892,  621,  624,  625,  892,  842,  844,  845,  892,  843,
 /*   130 */   846,  623,  622,  892,  768,  892,  771,  773,  892,  774,
 /*   140 */   892,  775,  892,  776,  892,  777,  892,  778,  892,  779,
 /*   150 */   892,  780,  892,  781,  892,  782,  892,  783,  892,  784,
 /*   160 */   892,  785,  892,  786,  892,  787,  892,  788,  892,  789,
 /*   170 */   790,  892,  791,  798,  805,  808,  892,  793,  892,  792,
 /*   180 */   795,  892,  796,  892,  799,  797,  804,  892,  892,  892,
 /*   190 */   806,  807,  892,  824,  892,  892,  892,  892,  892,  811,
 /*   200 */   823,  892,  800,  892,  801,  892,  802,  892,  803,  892,
 /*   210 */   892,  892,  813,  892,  892,  892,  892,  892,  814,  892,
 /*   220 */   892,  892,  815,  892,  892,  892,  870,  892,  892,  892,
 /*   230 */   871,  892,  892,  892,  892,  892,  816,  892,  809,  824,
 /*   240 */   821,  822,  709,  892,  710,  812,  794,  772,  892,  738,
 /*   250 */   892,  892,  722,  892,  729,  728,  723,  892,  611,  730,
 /*   260 */   725,  729,  728,  724,  892,  734,  892,  824,  732,  892,
 /*   270 */   741,  693,  704,  702,  703,  712,  713,  892,  714,  892,
 /*   280 */   715,  892,  716,  892,  709,  700,  892,  698,  699,  718,
 /*   290 */   720,  705,  892,  892,  892,  719,  892,  753,  754,  892,
 /*   300 */   717,  704,  892,  892,  892,  700,  718,  720,  706,  892,
 /*   310 */   700,  695,  696,  892,  892,  697,  810,  892,  756,  892,
 /*   320 */   769,  892,  770,  892,  672,  639,  892,  828,  645,  640,
 /*   330 */   646,  892,  647,  892,  892,  648,  892,  651,  652,  653,
 /*   340 */   654,  892,  649,  892,  650,  892,  892,  829,  892,  729,
 /*   350 */   728,  830,  832,  729,  728,  831,  641,  892,  642,  657,
 /*   360 */   656,  629,  892,  630,  892,  892,  631,  892,  632,  764,
 /*   370 */   892,  633,  634,  618,  610,  892,  892,  662,  892,  665,
 /*   380 */   892,  892,  892,  892,  892,  672,  666,  892,  892,  892,
 /*   390 */   672,  667,  892,  672,  668,  892,  892,  892,  892,  892,
 /*   400 */   892,  828,  645,  670,  892,  669,  671,  663,  664,  608,
 /*   410 */   892,  892,  604,  892,  892,  709,  602,  892,  892,  892,
 /*   420 */   892,  892,  892,  709,  853,  892,  892,  892,  709,  711,
 /*   430 */   858,  892,  892,  892,  892,  892,  892,  859,  860,  892,
 /*   440 */   892,  892,  892,  892,  850,  851,  892,  852,  603,  892,
 /*   450 */   892,  892,  892,  892,  892,  892,  892,  892,  892,  892,
 /*   460 */   892,  892,  892,  892,  892,  675,  892,  892,  892,  892,
 /*   470 */   892,  892,  892,  674,  892,  892,  892,  892,  892,  892,
 /*   480 */   892,  743,  892,  892,  892,  744,  892,  892,  751,  892,
 /*   490 */   892,  752,  892,  892,  892,  892,  892,  892,  749,  892,
 /*   500 */   750,  892,  892,  892,  892,  892,  892,  892,  892,  892,
 /*   510 */   892,  892,  892,  892,  892,  892,  892,  892,  892,  674,
 /*   520 */   892,  892,  892,  892,  892,  892,  892,  751,  892,  892,
 /*   530 */   892,  892,  892,  892,  892,  892,  892,  709,  892,  847,
 /*   540 */   892,  892,  892,  892,  892,  892,  892,  881,  892,  892,
 /*   550 */   892,  892,  892,  892,  892,  892,  880,  881,  892,  892,
 /*   560 */   892,  892,  892,  892,  892,  892,  892,  892,  892,  892,
 /*   570 */   892,  892,  892,  890,  892,  892,  891,  588,  892,  589,
 /*   580 */   583,

};
#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))

/* The next table maps tokens into fallback tokens.  If a construct
** like the following:
** 
**      %fallback ID X Y Z.
................................................................................
    0,  /*    ILLEGAL => nothing */
    0,  /*      SPACE => nothing */
    0,  /* UNCLOSED_STRING => nothing */
    0,  /*    COMMENT => nothing */
    0,  /*   FUNCTION => nothing */
    0,  /*     COLUMN => nothing */
    0,  /* AGG_FUNCTION => nothing */
    0,  /* AGG_COLUMN => nothing */
    0,  /* CONST_FUNC => nothing */
    0,  /*       SEMI => nothing */
   30,  /*    EXPLAIN => ID */
   30,  /*      QUERY => ID */
   30,  /*       PLAN => ID */
   30,  /*      BEGIN => ID */
    0,  /* TRANSACTION => nothing */
   30,  /*   DEFERRED => ID */
   30,  /*  IMMEDIATE => ID */
   30,  /*  EXCLUSIVE => ID */
    0,  /*     COMMIT => nothing */
   30,  /*        END => ID */
    0,  /*   ROLLBACK => nothing */
    0,  /*     CREATE => nothing */
    0,  /*      TABLE => nothing */
   30,  /*       TEMP => ID */
    0,  /*         LP => nothing */
    0,  /*         RP => nothing */
    0,  /*         AS => nothing */
    0,  /*      COMMA => nothing */
    0,  /*         ID => nothing */
   30,  /*      ABORT => ID */
   30,  /*      AFTER => ID */
   30,  /*    ANALYZE => ID */
   30,  /*        ASC => ID */
   30,  /*     ATTACH => ID */
   30,  /*     BEFORE => ID */
   30,  /*    CASCADE => ID */
   30,  /*       CAST => ID */
   30,  /*   CONFLICT => ID */
   30,  /*   DATABASE => ID */
   30,  /*       DESC => ID */
   30,  /*     DETACH => ID */
   30,  /*       EACH => ID */
   30,  /*       FAIL => ID */
   30,  /*        FOR => ID */
   30,  /*     IGNORE => ID */
   30,  /*  INITIALLY => ID */
   30,  /*    INSTEAD => ID */
   30,  /*    LIKE_KW => ID */
   30,  /*      MATCH => ID */
   30,  /*        KEY => ID */
   30,  /*         OF => ID */
   30,  /*     OFFSET => ID */
   30,  /*     PRAGMA => ID */
   30,  /*      RAISE => ID */
   30,  /*    REPLACE => ID */
   30,  /*   RESTRICT => ID */
   30,  /*        ROW => ID */
   30,  /*  STATEMENT => ID */
   30,  /*    TRIGGER => ID */
   30,  /*     VACUUM => ID */
   30,  /*       VIEW => ID */
   30,  /*    REINDEX => ID */
   30,  /*     RENAME => ID */
   30,  /*   CTIME_KW => ID */
   30,  /*      ALTER => ID */
    0,  /*         OR => nothing */
    0,  /*        AND => nothing */
    0,  /*        NOT => nothing */
    0,  /*         IS => nothing */
    0,  /*    BETWEEN => nothing */
    0,  /*         IN => nothing */
    0,  /*     ISNULL => nothing */
................................................................................

#ifndef NDEBUG
/* For tracing shifts, the names of all terminals and nonterminals
** are required.  The following table supplies these names */
static const char *const yyTokenName[] = { 
  "$",             "END_OF_FILE",   "ILLEGAL",       "SPACE",       
  "UNCLOSED_STRING",  "COMMENT",       "FUNCTION",      "COLUMN",      
  "AGG_FUNCTION",  "AGG_COLUMN",    "CONST_FUNC",    "SEMI",        
  "EXPLAIN",       "QUERY",         "PLAN",          "BEGIN",       
  "TRANSACTION",   "DEFERRED",      "IMMEDIATE",     "EXCLUSIVE",   
  "COMMIT",        "END",           "ROLLBACK",      "CREATE",      
  "TABLE",         "TEMP",          "LP",            "RP",          
  "AS",            "COMMA",         "ID",            "ABORT",       
  "AFTER",         "ANALYZE",       "ASC",           "ATTACH",      
  "BEFORE",        "CASCADE",       "CAST",          "CONFLICT",    
  "DATABASE",      "DESC",          "DETACH",        "EACH",        
  "FAIL",          "FOR",           "IGNORE",        "INITIALLY",   
  "INSTEAD",       "LIKE_KW",       "MATCH",         "KEY",         
  "OF",            "OFFSET",        "PRAGMA",        "RAISE",       
  "REPLACE",       "RESTRICT",      "ROW",           "STATEMENT",   
  "TRIGGER",       "VACUUM",        "VIEW",          "REINDEX",     
  "RENAME",        "CTIME_KW",      "ALTER",         "OR",          
  "AND",           "NOT",           "IS",            "BETWEEN",     
  "IN",            "ISNULL",        "NOTNULL",       "NE",          
  "EQ",            "GT",            "LE",            "LT",          
  "GE",            "ESCAPE",        "BITAND",        "BITOR",       
  "LSHIFT",        "RSHIFT",        "PLUS",          "MINUS",       
  "STAR",          "SLASH",         "REM",           "CONCAT",      
  "UMINUS",        "UPLUS",         "BITNOT",        "STRING",      
  "JOIN_KW",       "CONSTRAINT",    "DEFAULT",       "NULL",        
  "PRIMARY",       "UNIQUE",        "CHECK",         "REFERENCES",  
  "COLLATE",       "AUTOINCR",      "ON",            "DELETE",      
  "UPDATE",        "INSERT",        "SET",           "DEFERRABLE",  
  "FOREIGN",       "DROP",          "UNION",         "ALL",         
  "INTERSECT",     "EXCEPT",        "SELECT",        "DISTINCT",    
  "DOT",           "FROM",          "JOIN",          "USING",       
  "ORDER",         "BY",            "GROUP",         "HAVING",      
  "LIMIT",         "WHERE",         "INTO",          "VALUES",      
  "INTEGER",       "FLOAT",         "BLOB",          "REGISTER",    
  "VARIABLE",      "EXISTS",        "CASE",          "WHEN",        
  "THEN",          "ELSE",          "INDEX",         "TO",          
  "ADD",           "COLUMNKW",      "error",         "input",       
  "cmdlist",       "ecmd",          "cmdx",          "cmd",         
  "explain",       "transtype",     "trans_opt",     "nm",          
  "create_table",  "create_table_args",  "temp",          "dbnm",        
  "columnlist",    "conslist_opt",  "select",        "column",      
  "columnid",      "type",          "carglist",      "id",          
  "ids",           "typetoken",     "typename",      "signed",      
  "plus_num",      "minus_num",     "carg",          "ccons",       
  "term",          "expr",          "onconf",        "sortorder",   
  "autoinc",       "idxlist_opt",   "refargs",       "defer_subclause",
  "refarg",        "refact",        "init_deferred_pred_opt",  "conslist",    
  "tcons",         "idxlist",       "defer_subclause_opt",  "orconf",      
  "resolvetype",   "raisetype",     "fullname",      "oneselect",   
  "multiselect_op",  "distinct",      "selcollist",    "from",        
  "where_opt",     "groupby_opt",   "having_opt",    "orderby_opt", 
  "limit_opt",     "sclp",          "as",            "seltablist",  
  "stl_prefix",    "joinop",        "on_opt",        "using_opt",   
  "seltablist_paren",  "joinop2",       "inscollist",    "sortlist",    
  "sortitem",      "collate",       "exprlist",      "setlist",     
  "insert_cmd",    "inscollist_opt",  "itemlist",      "likeop",      
  "escape",        "between_op",    "in_op",         "case_operand",
  "case_exprlist",  "case_else",     "expritem",      "uniqueflag",  
  "idxitem",       "plus_opt",      "number",        "trigger_decl",
  "trigger_cmd_list",  "trigger_time",  "trigger_event",  "foreach_clause",
  "when_clause",   "trigger_cmd",   "database_kw_opt",  "key_opt",     
  "add_column_fullname",  "kwcolumn_opt",
};
#endif /* NDEBUG */

#ifndef NDEBUG
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *const yyRuleName[] = {
................................................................................
 /*   1 */ "cmdlist ::= cmdlist ecmd",
 /*   2 */ "cmdlist ::= ecmd",
 /*   3 */ "cmdx ::= cmd",
 /*   4 */ "ecmd ::= SEMI",
 /*   5 */ "ecmd ::= explain cmdx SEMI",
 /*   6 */ "explain ::=",
 /*   7 */ "explain ::= EXPLAIN",
 /*   8 */ "explain ::= EXPLAIN QUERY PLAN",
 /*   9 */ "cmd ::= BEGIN transtype trans_opt",
 /*  10 */ "trans_opt ::=",
 /*  11 */ "trans_opt ::= TRANSACTION",
 /*  12 */ "trans_opt ::= TRANSACTION nm",
 /*  13 */ "transtype ::=",
 /*  14 */ "transtype ::= DEFERRED",
 /*  15 */ "transtype ::= IMMEDIATE",
 /*  16 */ "transtype ::= EXCLUSIVE",
 /*  17 */ "cmd ::= COMMIT trans_opt",
 /*  18 */ "cmd ::= END trans_opt",
 /*  19 */ "cmd ::= ROLLBACK trans_opt",
 /*  20 */ "cmd ::= create_table create_table_args",
 /*  21 */ "create_table ::= CREATE temp TABLE nm dbnm",
 /*  22 */ "temp ::= TEMP",
 /*  23 */ "temp ::=",
 /*  24 */ "create_table_args ::= LP columnlist conslist_opt RP",
 /*  25 */ "create_table_args ::= AS select",
 /*  26 */ "columnlist ::= columnlist COMMA column",
 /*  27 */ "columnlist ::= column",
 /*  28 */ "column ::= columnid type carglist",
 /*  29 */ "columnid ::= nm",
 /*  30 */ "id ::= ID",
 /*  31 */ "ids ::= ID",
 /*  32 */ "ids ::= STRING",
 /*  33 */ "nm ::= ID",
 /*  34 */ "nm ::= STRING",
 /*  35 */ "nm ::= JOIN_KW",
 /*  36 */ "type ::=",
 /*  37 */ "type ::= typetoken",
 /*  38 */ "typetoken ::= typename",
 /*  39 */ "typetoken ::= typename LP signed RP",
 /*  40 */ "typetoken ::= typename LP signed COMMA signed RP",
 /*  41 */ "typename ::= ids",
 /*  42 */ "typename ::= typename ids",
 /*  43 */ "signed ::= plus_num",
 /*  44 */ "signed ::= minus_num",
 /*  45 */ "carglist ::= carglist carg",
 /*  46 */ "carglist ::=",
 /*  47 */ "carg ::= CONSTRAINT nm ccons",
 /*  48 */ "carg ::= ccons",
 /*  49 */ "carg ::= DEFAULT term",
 /*  50 */ "carg ::= DEFAULT LP expr RP",
 /*  51 */ "carg ::= DEFAULT PLUS term",
 /*  52 */ "carg ::= DEFAULT MINUS term",
 /*  53 */ "carg ::= DEFAULT id",
 /*  54 */ "ccons ::= NULL onconf",
 /*  55 */ "ccons ::= NOT NULL onconf",
 /*  56 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
 /*  57 */ "ccons ::= UNIQUE onconf",
 /*  58 */ "ccons ::= CHECK LP expr RP onconf",
 /*  59 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
 /*  60 */ "ccons ::= defer_subclause",
 /*  61 */ "ccons ::= COLLATE id",
 /*  62 */ "autoinc ::=",
 /*  63 */ "autoinc ::= AUTOINCR",
 /*  64 */ "refargs ::=",
 /*  65 */ "refargs ::= refargs refarg",
 /*  66 */ "refarg ::= MATCH nm",
 /*  67 */ "refarg ::= ON DELETE refact",
 /*  68 */ "refarg ::= ON UPDATE refact",
 /*  69 */ "refarg ::= ON INSERT refact",
 /*  70 */ "refact ::= SET NULL",
 /*  71 */ "refact ::= SET DEFAULT",
 /*  72 */ "refact ::= CASCADE",
 /*  73 */ "refact ::= RESTRICT",
 /*  74 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt",
 /*  75 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt",
 /*  76 */ "init_deferred_pred_opt ::=",
 /*  77 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED",
 /*  78 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE",
 /*  79 */ "conslist_opt ::=",
 /*  80 */ "conslist_opt ::= COMMA conslist",
 /*  81 */ "conslist ::= conslist COMMA tcons",
 /*  82 */ "conslist ::= conslist tcons",
 /*  83 */ "conslist ::= tcons",
 /*  84 */ "tcons ::= CONSTRAINT nm",
 /*  85 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
 /*  86 */ "tcons ::= UNIQUE LP idxlist RP onconf",
 /*  87 */ "tcons ::= CHECK expr onconf",
 /*  88 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
 /*  89 */ "defer_subclause_opt ::=",
 /*  90 */ "defer_subclause_opt ::= defer_subclause",
 /*  91 */ "onconf ::=",
 /*  92 */ "onconf ::= ON CONFLICT resolvetype",
 /*  93 */ "orconf ::=",
 /*  94 */ "orconf ::= OR resolvetype",
 /*  95 */ "resolvetype ::= raisetype",
 /*  96 */ "resolvetype ::= IGNORE",
 /*  97 */ "resolvetype ::= REPLACE",
 /*  98 */ "cmd ::= DROP TABLE fullname",
 /*  99 */ "cmd ::= CREATE temp VIEW nm dbnm AS select",
 /* 100 */ "cmd ::= DROP VIEW fullname",
 /* 101 */ "cmd ::= select",
 /* 102 */ "select ::= oneselect",
 /* 103 */ "select ::= select multiselect_op oneselect",
 /* 104 */ "multiselect_op ::= UNION",
 /* 105 */ "multiselect_op ::= UNION ALL",
 /* 106 */ "multiselect_op ::= INTERSECT",
 /* 107 */ "multiselect_op ::= EXCEPT",
 /* 108 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt",
 /* 109 */ "distinct ::= DISTINCT",
 /* 110 */ "distinct ::= ALL",
 /* 111 */ "distinct ::=",
 /* 112 */ "sclp ::= selcollist COMMA",
 /* 113 */ "sclp ::=",
 /* 114 */ "selcollist ::= sclp expr as",
 /* 115 */ "selcollist ::= sclp STAR",
 /* 116 */ "selcollist ::= sclp nm DOT STAR",
 /* 117 */ "as ::= AS nm",
 /* 118 */ "as ::= ids",
 /* 119 */ "as ::=",
 /* 120 */ "from ::=",
 /* 121 */ "from ::= FROM seltablist",
 /* 122 */ "stl_prefix ::= seltablist joinop",
 /* 123 */ "stl_prefix ::=",
 /* 124 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt",
 /* 125 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt",
 /* 126 */ "seltablist_paren ::= select",
 /* 127 */ "seltablist_paren ::= seltablist",
 /* 128 */ "dbnm ::=",
 /* 129 */ "dbnm ::= DOT nm",
 /* 130 */ "fullname ::= nm dbnm",
 /* 131 */ "joinop ::= COMMA",
 /* 132 */ "joinop ::= JOIN",
 /* 133 */ "joinop ::= JOIN_KW JOIN",
 /* 134 */ "joinop ::= JOIN_KW nm JOIN",
 /* 135 */ "joinop ::= JOIN_KW nm nm JOIN",
 /* 136 */ "on_opt ::= ON expr",
 /* 137 */ "on_opt ::=",
 /* 138 */ "using_opt ::= USING LP inscollist RP",
 /* 139 */ "using_opt ::=",
 /* 140 */ "orderby_opt ::=",
 /* 141 */ "orderby_opt ::= ORDER BY sortlist",
 /* 142 */ "sortlist ::= sortlist COMMA sortitem collate sortorder",
 /* 143 */ "sortlist ::= sortitem collate sortorder",
 /* 144 */ "sortitem ::= expr",
 /* 145 */ "sortorder ::= ASC",
 /* 146 */ "sortorder ::= DESC",
 /* 147 */ "sortorder ::=",
 /* 148 */ "collate ::=",
 /* 149 */ "collate ::= COLLATE id",
 /* 150 */ "groupby_opt ::=",
 /* 151 */ "groupby_opt ::= GROUP BY exprlist",
 /* 152 */ "having_opt ::=",
 /* 153 */ "having_opt ::= HAVING expr",
 /* 154 */ "limit_opt ::=",
 /* 155 */ "limit_opt ::= LIMIT expr",
 /* 156 */ "limit_opt ::= LIMIT expr OFFSET expr",
 /* 157 */ "limit_opt ::= LIMIT expr COMMA expr",
 /* 158 */ "cmd ::= DELETE FROM fullname where_opt",
 /* 159 */ "where_opt ::=",
 /* 160 */ "where_opt ::= WHERE expr",
 /* 161 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt",
 /* 162 */ "setlist ::= setlist COMMA nm EQ expr",
 /* 163 */ "setlist ::= nm EQ expr",
 /* 164 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP",
 /* 165 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select",
 /* 166 */ "insert_cmd ::= INSERT orconf",
 /* 167 */ "insert_cmd ::= REPLACE",
 /* 168 */ "itemlist ::= itemlist COMMA expr",
 /* 169 */ "itemlist ::= expr",
 /* 170 */ "inscollist_opt ::=",
 /* 171 */ "inscollist_opt ::= LP inscollist RP",
 /* 172 */ "inscollist ::= inscollist COMMA nm",
 /* 173 */ "inscollist ::= nm",
 /* 174 */ "expr ::= term",
 /* 175 */ "expr ::= LP expr RP",
 /* 176 */ "term ::= NULL",
 /* 177 */ "expr ::= ID",
 /* 178 */ "expr ::= JOIN_KW",
 /* 179 */ "expr ::= nm DOT nm",
 /* 180 */ "expr ::= nm DOT nm DOT nm",
 /* 181 */ "term ::= INTEGER",
 /* 182 */ "term ::= FLOAT",
 /* 183 */ "term ::= STRING",
 /* 184 */ "term ::= BLOB",
 /* 185 */ "expr ::= REGISTER",
 /* 186 */ "expr ::= VARIABLE",
 /* 187 */ "expr ::= CAST LP expr AS typetoken RP",
 /* 188 */ "expr ::= ID LP distinct exprlist RP",
 /* 189 */ "expr ::= ID LP STAR RP",
 /* 190 */ "term ::= CTIME_KW",
 /* 191 */ "expr ::= expr AND expr",
 /* 192 */ "expr ::= expr OR expr",
 /* 193 */ "expr ::= expr LT expr",
 /* 194 */ "expr ::= expr GT expr",
 /* 195 */ "expr ::= expr LE expr",
 /* 196 */ "expr ::= expr GE expr",
 /* 197 */ "expr ::= expr NE expr",
 /* 198 */ "expr ::= expr EQ expr",
 /* 199 */ "expr ::= expr BITAND expr",
 /* 200 */ "expr ::= expr BITOR expr",
 /* 201 */ "expr ::= expr LSHIFT expr",
 /* 202 */ "expr ::= expr RSHIFT expr",
 /* 203 */ "expr ::= expr PLUS expr",
 /* 204 */ "expr ::= expr MINUS expr",
 /* 205 */ "expr ::= expr STAR expr",
 /* 206 */ "expr ::= expr SLASH expr",
 /* 207 */ "expr ::= expr REM expr",
 /* 208 */ "expr ::= expr CONCAT expr",
 /* 209 */ "likeop ::= LIKE_KW",
 /* 210 */ "likeop ::= NOT LIKE_KW",
 /* 211 */ "escape ::= ESCAPE expr",
 /* 212 */ "escape ::=",
 /* 213 */ "expr ::= expr likeop expr escape",
 /* 214 */ "expr ::= expr ISNULL",
 /* 215 */ "expr ::= expr IS NULL",
 /* 216 */ "expr ::= expr NOTNULL",
 /* 217 */ "expr ::= expr NOT NULL",
 /* 218 */ "expr ::= expr IS NOT NULL",
 /* 219 */ "expr ::= NOT expr",
 /* 220 */ "expr ::= BITNOT expr",
 /* 221 */ "expr ::= MINUS expr",
 /* 222 */ "expr ::= PLUS expr",
 /* 223 */ "between_op ::= BETWEEN",
 /* 224 */ "between_op ::= NOT BETWEEN",
 /* 225 */ "expr ::= expr between_op expr AND expr",
 /* 226 */ "in_op ::= IN",
 /* 227 */ "in_op ::= NOT IN",
 /* 228 */ "expr ::= expr in_op LP exprlist RP",
 /* 229 */ "expr ::= LP select RP",
 /* 230 */ "expr ::= expr in_op LP select RP",
 /* 231 */ "expr ::= expr in_op nm dbnm",
 /* 232 */ "expr ::= EXISTS LP select RP",
 /* 233 */ "expr ::= CASE case_operand case_exprlist case_else END",
 /* 234 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
 /* 235 */ "case_exprlist ::= WHEN expr THEN expr",
 /* 236 */ "case_else ::= ELSE expr",
 /* 237 */ "case_else ::=",
 /* 238 */ "case_operand ::= expr",
 /* 239 */ "case_operand ::=",
 /* 240 */ "exprlist ::= exprlist COMMA expritem",
 /* 241 */ "exprlist ::= expritem",
 /* 242 */ "expritem ::= expr",
 /* 243 */ "expritem ::=",
 /* 244 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf",
 /* 245 */ "uniqueflag ::= UNIQUE",
 /* 246 */ "uniqueflag ::=",
 /* 247 */ "idxlist_opt ::=",
 /* 248 */ "idxlist_opt ::= LP idxlist RP",
 /* 249 */ "idxlist ::= idxlist COMMA idxitem collate sortorder",
 /* 250 */ "idxlist ::= idxitem collate sortorder",
 /* 251 */ "idxitem ::= nm",
 /* 252 */ "cmd ::= DROP INDEX fullname",
 /* 253 */ "cmd ::= VACUUM",
 /* 254 */ "cmd ::= VACUUM nm",
 /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nm",
 /* 256 */ "cmd ::= PRAGMA nm dbnm EQ ON",
 /* 257 */ "cmd ::= PRAGMA nm dbnm EQ plus_num",
 /* 258 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
 /* 259 */ "cmd ::= PRAGMA nm dbnm LP nm RP",
 /* 260 */ "cmd ::= PRAGMA nm dbnm",
 /* 261 */ "plus_num ::= plus_opt number",
 /* 262 */ "minus_num ::= MINUS number",
 /* 263 */ "number ::= INTEGER",
 /* 264 */ "number ::= FLOAT",
 /* 265 */ "plus_opt ::= PLUS",
 /* 266 */ "plus_opt ::=",
 /* 267 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
 /* 268 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
 /* 269 */ "trigger_time ::= BEFORE",
 /* 270 */ "trigger_time ::= AFTER",
 /* 271 */ "trigger_time ::= INSTEAD OF",
 /* 272 */ "trigger_time ::=",
 /* 273 */ "trigger_event ::= DELETE",
 /* 274 */ "trigger_event ::= INSERT",
 /* 275 */ "trigger_event ::= UPDATE",
 /* 276 */ "trigger_event ::= UPDATE OF inscollist",
 /* 277 */ "foreach_clause ::=",
 /* 278 */ "foreach_clause ::= FOR EACH ROW",
 /* 279 */ "foreach_clause ::= FOR EACH STATEMENT",
 /* 280 */ "when_clause ::=",
 /* 281 */ "when_clause ::= WHEN expr",
 /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list",
 /* 283 */ "trigger_cmd_list ::=",
 /* 284 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
 /* 285 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
 /* 286 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
 /* 287 */ "trigger_cmd ::= DELETE FROM nm where_opt",
 /* 288 */ "trigger_cmd ::= select",
 /* 289 */ "expr ::= RAISE LP IGNORE RP",
 /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP",
 /* 291 */ "raisetype ::= ROLLBACK",
 /* 292 */ "raisetype ::= ABORT",
 /* 293 */ "raisetype ::= FAIL",
 /* 294 */ "cmd ::= DROP TRIGGER fullname",
 /* 295 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt",
 /* 296 */ "key_opt ::=",
 /* 297 */ "key_opt ::= KEY ids",
 /* 298 */ "key_opt ::= KEY BLOB",
 /* 299 */ "database_kw_opt ::= DATABASE",
 /* 300 */ "database_kw_opt ::=",
 /* 301 */ "cmd ::= DETACH database_kw_opt nm",
 /* 302 */ "cmd ::= REINDEX",
 /* 303 */ "cmd ::= REINDEX nm dbnm",
 /* 304 */ "cmd ::= ANALYZE",
 /* 305 */ "cmd ::= ANALYZE nm dbnm",
 /* 306 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
 /* 307 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
 /* 308 */ "add_column_fullname ::= fullname",
 /* 309 */ "kwcolumn_opt ::=",
 /* 310 */ "kwcolumn_opt ::= COLUMNKW",
};
#endif /* NDEBUG */

/*
** This function returns the symbolic name associated with a token
** value.
*/
................................................................................
    ** reduce or during error processing or when a parser is 
    ** being destroyed before it is finished parsing.
    **
    ** Note: during a reduce, the only symbols destroyed are those
    ** which appear on the RHS of the rule, but which are not used
    ** inside the C code.
    */
    case 162:
    case 195:
    case 212:
#line 370 "parse.y"
{sqlite3SelectDelete((yypminor->yy375));}
#line 1332 "parse.c"
      break;
    case 176:
    case 177:
    case 200:
    case 202:
    case 210:
    case 216:
    case 230:
#line 629 "parse.y"
{sqlite3ExprDelete((yypminor->yy62));}
#line 1343 "parse.c"
      break;
    case 181:
    case 189:

    case 198:
    case 201:
    case 203:
    case 205:
    case 215:
    case 218:
    case 219:
    case 222:
    case 228:
#line 876 "parse.y"
{sqlite3ExprListDelete((yypminor->yy418));}
#line 1358 "parse.c"
      break;
    case 194:
    case 199:
    case 207:
    case 208:
#line 499 "parse.y"
{sqlite3SrcListDelete((yypminor->yy151));}
#line 1366 "parse.c"
      break;
    case 204:
#line 561 "parse.y"
{
  sqlite3ExprDelete((yypminor->yy220).pLimit);
  sqlite3ExprDelete((yypminor->yy220).pOffset);
}
#line 1374 "parse.c"
      break;
    case 211:
    case 214:
    case 221:
#line 517 "parse.y"
{sqlite3IdListDelete((yypminor->yy240));}
#line 1381 "parse.c"
      break;
    case 236:
    case 241:
#line 969 "parse.y"
{sqlite3DeleteTriggerStep((yypminor->yy360));}
#line 1387 "parse.c"
      break;
    case 238:
#line 953 "parse.y"
{sqlite3IdListDelete((yypminor->yy30).b);}
#line 1392 "parse.c"
      break;
    default:  break;   /* If no destructor action specified: do nothing */
  }
}

/*
** Pop the parser's stack once.
................................................................................
/* The following table contains information about every rule that
** is used during the reduce.
*/
static const struct {
  YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
  unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
} yyRuleInfo[] = {
  { 147, 1 },
  { 148, 2 },
  { 148, 1 },
  { 150, 1 },
  { 149, 1 },
  { 149, 3 },
  { 152, 0 },
  { 152, 1 },
  { 152, 3 },
  { 151, 3 },
  { 154, 0 },
  { 154, 1 },
  { 154, 2 },
  { 153, 0 },
  { 153, 1 },
  { 153, 1 },
  { 153, 1 },
  { 151, 2 },
  { 151, 2 },
  { 151, 2 },
  { 151, 2 },
  { 156, 5 },
  { 158, 1 },
  { 158, 0 },
  { 157, 4 },
  { 157, 2 },
  { 160, 3 },
  { 160, 1 },
  { 163, 3 },
  { 164, 1 },
  { 167, 1 },
  { 168, 1 },
  { 168, 1 },
  { 155, 1 },
  { 155, 1 },
  { 155, 1 },
  { 165, 0 },
  { 165, 1 },
  { 169, 1 },
  { 169, 4 },
  { 169, 6 },
  { 170, 1 },
  { 170, 2 },
  { 171, 1 },
  { 171, 1 },
  { 166, 2 },
  { 166, 0 },
  { 174, 3 },
  { 174, 1 },
  { 174, 2 },
  { 174, 4 },
  { 174, 3 },
  { 174, 3 },
  { 174, 2 },
  { 175, 2 },
  { 175, 3 },
  { 175, 5 },
  { 175, 2 },
  { 175, 5 },
  { 175, 4 },
  { 175, 1 },
  { 175, 2 },
  { 180, 0 },
  { 180, 1 },
  { 182, 0 },
  { 182, 2 },
  { 184, 2 },
  { 184, 3 },
  { 184, 3 },
  { 184, 3 },
  { 185, 2 },
  { 185, 2 },
  { 185, 1 },
  { 185, 1 },
  { 183, 3 },
  { 183, 2 },
  { 186, 0 },
  { 186, 2 },
  { 186, 2 },
  { 161, 0 },
  { 161, 2 },
  { 187, 3 },
  { 187, 2 },
  { 187, 1 },
  { 188, 2 },
  { 188, 7 },
  { 188, 5 },
  { 188, 3 },
  { 188, 10 },
  { 190, 0 },
  { 190, 1 },
  { 178, 0 },
  { 178, 3 },
  { 191, 0 },
  { 191, 2 },
  { 192, 1 },
  { 192, 1 },
  { 192, 1 },
  { 151, 3 },
  { 151, 7 },
  { 151, 3 },
  { 151, 1 },
  { 162, 1 },
  { 162, 3 },
  { 196, 1 },
  { 196, 2 },
  { 196, 1 },
  { 196, 1 },
  { 195, 9 },
  { 197, 1 },
  { 197, 1 },
  { 197, 0 },
  { 205, 2 },
  { 205, 0 },
  { 198, 3 },
  { 198, 2 },
  { 198, 4 },
  { 206, 2 },
  { 206, 1 },
  { 206, 0 },
  { 199, 0 },
  { 199, 2 },
  { 208, 2 },
  { 208, 0 },
  { 207, 6 },
  { 207, 7 },
  { 212, 1 },
  { 212, 1 },
  { 159, 0 },
  { 159, 2 },
  { 194, 2 },
  { 209, 1 },
  { 209, 1 },
  { 209, 2 },
  { 209, 3 },
  { 209, 4 },
  { 210, 2 },
  { 210, 0 },
  { 211, 4 },
  { 211, 0 },
  { 203, 0 },
  { 203, 3 },
  { 215, 5 },
  { 215, 3 },
  { 216, 1 },
  { 179, 1 },
  { 179, 1 },
  { 179, 0 },
  { 217, 0 },
  { 217, 2 },
  { 201, 0 },
  { 201, 3 },
  { 202, 0 },
  { 202, 2 },
  { 204, 0 },
  { 204, 2 },
  { 204, 4 },
  { 204, 4 },
  { 151, 4 },
  { 200, 0 },
  { 200, 2 },
  { 151, 6 },
  { 219, 5 },
  { 219, 3 },
  { 151, 8 },
  { 151, 5 },
  { 220, 2 },
  { 220, 1 },
  { 222, 3 },
  { 222, 1 },
  { 221, 0 },
  { 221, 3 },
  { 214, 3 },
  { 214, 1 },
  { 177, 1 },
  { 177, 3 },
  { 176, 1 },
  { 177, 1 },
  { 177, 1 },
  { 177, 3 },
  { 177, 5 },
  { 176, 1 },
  { 176, 1 },
  { 176, 1 },
  { 176, 1 },
  { 177, 1 },
  { 177, 1 },
  { 177, 6 },
  { 177, 5 },
  { 177, 4 },
  { 176, 1 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 177, 3 },
  { 223, 1 },
  { 223, 2 },
  { 224, 2 },
  { 224, 0 },
  { 177, 4 },
  { 177, 2 },
  { 177, 3 },
  { 177, 2 },
  { 177, 3 },
  { 177, 4 },
  { 177, 2 },
  { 177, 2 },
  { 177, 2 },
  { 177, 2 },
  { 225, 1 },
  { 225, 2 },
  { 177, 5 },
  { 226, 1 },
  { 226, 2 },
  { 177, 5 },
  { 177, 3 },
  { 177, 5 },
  { 177, 4 },
  { 177, 4 },
  { 177, 5 },
  { 228, 5 },
  { 228, 4 },
  { 229, 2 },
  { 229, 0 },
  { 227, 1 },
  { 227, 0 },
  { 218, 3 },
  { 218, 1 },
  { 230, 1 },
  { 230, 0 },
  { 151, 11 },
  { 231, 1 },
  { 231, 0 },
  { 181, 0 },
  { 181, 3 },
  { 189, 5 },
  { 189, 3 },
  { 232, 1 },
  { 151, 3 },
  { 151, 1 },
  { 151, 2 },
  { 151, 5 },
  { 151, 5 },
  { 151, 5 },
  { 151, 5 },
  { 151, 6 },
  { 151, 3 },
  { 172, 2 },
  { 173, 2 },
  { 234, 1 },
  { 234, 1 },
  { 233, 1 },
  { 233, 0 },
  { 151, 5 },
  { 235, 10 },
  { 237, 1 },
  { 237, 1 },
  { 237, 2 },
  { 237, 0 },
  { 238, 1 },
  { 238, 1 },
  { 238, 1 },
  { 238, 3 },
  { 239, 0 },
  { 239, 3 },
  { 239, 3 },
  { 240, 0 },
  { 240, 2 },
  { 236, 3 },
  { 236, 0 },
  { 241, 6 },
  { 241, 8 },
  { 241, 5 },
  { 241, 4 },
  { 241, 1 },
  { 177, 4 },
  { 177, 6 },
  { 193, 1 },
  { 193, 1 },
  { 193, 1 },
  { 151, 3 },
  { 151, 6 },
  { 243, 0 },
  { 243, 2 },
  { 243, 2 },
  { 242, 1 },
  { 242, 0 },
  { 151, 3 },
  { 151, 1 },
  { 151, 3 },
  { 151, 1 },
  { 151, 3 },
  { 151, 6 },
  { 151, 6 },
  { 244, 1 },
  { 245, 0 },
  { 245, 1 },
};

static void yy_accept(yyParser*);  /* Forward Declaration */

/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
................................................................................
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
      case 3:
#line 102 "parse.y"
{ sqlite3FinishCoding(pParse); }
#line 1930 "parse.c"
        break;
      case 6:
#line 105 "parse.y"
{ sqlite3BeginParse(pParse, 0); }
#line 1935 "parse.c"
        break;
      case 7:
#line 107 "parse.y"
{ sqlite3BeginParse(pParse, 1); }
#line 1940 "parse.c"
        break;
      case 8:
#line 108 "parse.y"
{ sqlite3BeginParse(pParse, 2); }
#line 1945 "parse.c"
        break;
      case 9:
#line 114 "parse.y"
{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy280);}
#line 1950 "parse.c"
        break;
      case 13:
#line 119 "parse.y"
{yygotominor.yy280 = TK_DEFERRED;}
#line 1955 "parse.c"
        break;
      case 14:
      case 15:
      case 16:
      case 104:
      case 106:
      case 107:
#line 120 "parse.y"
{yygotominor.yy280 = yymsp[0].major;}
#line 1965 "parse.c"
        break;
      case 17:
      case 18:
#line 123 "parse.y"
{sqlite3CommitTransaction(pParse);}
#line 1971 "parse.c"
        break;
      case 19:
#line 125 "parse.y"
{sqlite3RollbackTransaction(pParse);}
#line 1976 "parse.c"
        break;
      case 21:
#line 130 "parse.y"
{
   sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198,yymsp[-3].minor.yy280,0);
}










#line 1983 "parse.c"
        break;
      case 22:
      case 63:
      case 77:
      case 109:
      case 224:
      case 227:
#line 135 "parse.y"
{yygotominor.yy280 = 1;}
#line 1993 "parse.c"
        break;
      case 23:
      case 62:
      case 76:
      case 78:
      case 89:
      case 110:
      case 111:
      case 223:
      case 226:
#line 137 "parse.y"
{yygotominor.yy280 = 0;}
#line 2006 "parse.c"
        break;
      case 24:
#line 138 "parse.y"
{
  sqlite3EndTable(pParse,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy0,0);
}
#line 2013 "parse.c"
        break;
      case 25:
#line 141 "parse.y"
{
  sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy375);
  sqlite3SelectDelete(yymsp[0].minor.yy375);
}
#line 2021 "parse.c"
        break;
      case 28:
#line 153 "parse.y"
{
  yygotominor.yy198.z = yymsp[-2].minor.yy198.z;
  yygotominor.yy198.n = (pParse->sLastToken.z-yymsp[-2].minor.yy198.z) + pParse->sLastToken.n;
}
#line 2029 "parse.c"
        break;
      case 29:
#line 157 "parse.y"
{
  sqlite3AddColumn(pParse,&yymsp[0].minor.yy198);
  yygotominor.yy198 = yymsp[0].minor.yy198;
}
#line 2037 "parse.c"
        break;

      case 30:
      case 31:
      case 32:
      case 33:
      case 34:
      case 35:
      case 263:
      case 264:
#line 167 "parse.y"
{yygotominor.yy198 = yymsp[0].minor.yy0;}
#line 2049 "parse.c"
        break;
      case 37:
#line 227 "parse.y"
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy198);}
#line 2054 "parse.c"
        break;
      case 38:
      case 41:
      case 117:
      case 118:
      case 129:
      case 149:
      case 251:
      case 261:
      case 262:
#line 228 "parse.y"
{yygotominor.yy198 = yymsp[0].minor.yy198;}
#line 2067 "parse.c"
        break;
      case 39:
#line 229 "parse.y"
{
  yygotominor.yy198.z = yymsp[-3].minor.yy198.z;
  yygotominor.yy198.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy198.z;
}
#line 2075 "parse.c"
        break;
      case 40:
#line 233 "parse.y"
{
  yygotominor.yy198.z = yymsp[-5].minor.yy198.z;
  yygotominor.yy198.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy198.z;
}
#line 2083 "parse.c"
        break;





      case 42:
#line 239 "parse.y"

{yygotominor.yy198.z=yymsp[-1].minor.yy198.z; yygotominor.yy198.n=yymsp[0].minor.yy198.n+(yymsp[0].minor.yy198.z-yymsp[-1].minor.yy198.z);}
#line 2088 "parse.c"
        break;
      case 43:
#line 241 "parse.y"
{ yygotominor.yy280 = atoi(yymsp[0].minor.yy198.z); }
#line 2093 "parse.c"
        break;
      case 44:
#line 242 "parse.y"
{ yygotominor.yy280 = -atoi(yymsp[0].minor.yy198.z); }
#line 2098 "parse.c"
        break;
      case 49:
      case 51:
#line 251 "parse.y"
{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy62);}
#line 2104 "parse.c"
        break;
      case 50:
#line 252 "parse.y"
{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy62);}
#line 2109 "parse.c"
        break;
      case 52:
#line 254 "parse.y"
{
  Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy62, 0, 0);
  sqlite3AddDefaultValue(pParse,p);
}
#line 2117 "parse.c"
        break;
      case 53:
#line 258 "parse.y"
{
  Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy198);
  sqlite3AddDefaultValue(pParse,p);
}
#line 2125 "parse.c"
        break;
      case 55:
#line 267 "parse.y"
{sqlite3AddNotNull(pParse, yymsp[0].minor.yy280);}
#line 2130 "parse.c"





        break;
      case 56:
#line 269 "parse.y"
{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy280,yymsp[0].minor.yy280);}
#line 2135 "parse.c"
        break;
      case 57:
#line 270 "parse.y"
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy280,0,0);}
#line 2140 "parse.c"
        break;
      case 58:
#line 271 "parse.y"
{sqlite3ExprDelete(yymsp[-2].minor.yy62);}
#line 2145 "parse.c"
        break;
      case 59:
#line 273 "parse.y"
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy198,yymsp[-1].minor.yy418,yymsp[0].minor.yy280);}
#line 2150 "parse.c"
        break;
      case 60:
#line 274 "parse.y"
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy280);}
#line 2155 "parse.c"
        break;
      case 61:
#line 275 "parse.y"
{sqlite3AddCollateType(pParse, yymsp[0].minor.yy198.z, yymsp[0].minor.yy198.n);}
#line 2160 "parse.c"
        break;
      case 64:
#line 288 "parse.y"
{ yygotominor.yy280 = OE_Restrict * 0x010101; }
#line 2165 "parse.c"
        break;
      case 65:
#line 289 "parse.y"
{ yygotominor.yy280 = (yymsp[-1].minor.yy280 & yymsp[0].minor.yy359.mask) | yymsp[0].minor.yy359.value; }
#line 2170 "parse.c"
        break;
      case 66:
#line 291 "parse.y"
{ yygotominor.yy359.value = 0;     yygotominor.yy359.mask = 0x000000; }
#line 2175 "parse.c"
        break;
      case 67:
#line 292 "parse.y"
{ yygotominor.yy359.value = yymsp[0].minor.yy280;     yygotominor.yy359.mask = 0x0000ff; }
#line 2180 "parse.c"
        break;
      case 68:
#line 293 "parse.y"
{ yygotominor.yy359.value = yymsp[0].minor.yy280<<8;  yygotominor.yy359.mask = 0x00ff00; }
#line 2185 "parse.c"
        break;
      case 69:
#line 294 "parse.y"
{ yygotominor.yy359.value = yymsp[0].minor.yy280<<16; yygotominor.yy359.mask = 0xff0000; }
#line 2190 "parse.c"
        break;
      case 70:
#line 296 "parse.y"
{ yygotominor.yy280 = OE_SetNull; }
#line 2195 "parse.c"
        break;
      case 71:
#line 297 "parse.y"
{ yygotominor.yy280 = OE_SetDflt; }
#line 2200 "parse.c"
        break;
      case 72:
#line 298 "parse.y"
{ yygotominor.yy280 = OE_Cascade; }
#line 2205 "parse.c"
        break;
      case 73:
#line 299 "parse.y"
{ yygotominor.yy280 = OE_Restrict; }
#line 2210 "parse.c"
        break;
      case 74:
      case 75:
      case 90:
      case 92:
      case 94:
      case 95:




      case 166:
#line 301 "parse.y"
{yygotominor.yy280 = yymsp[0].minor.yy280;}
#line 2221 "parse.c"
        break;
      case 79:
#line 311 "parse.y"
{yygotominor.yy198.n = 0; yygotominor.yy198.z = 0;}
#line 2226 "parse.c"
        break;
      case 80:
#line 312 "parse.y"
{yygotominor.yy198 = yymsp[-1].minor.yy0;}
#line 2231 "parse.c"
        break;
      case 85:
#line 318 "parse.y"
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy418,yymsp[0].minor.yy280,yymsp[-2].minor.yy280);}
#line 2236 "parse.c"
        break;
      case 86:
#line 320 "parse.y"
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy418,yymsp[0].minor.yy280,0,0);}
#line 2241 "parse.c"
        break;
      case 88:
#line 323 "parse.y"
{
    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy418, &yymsp[-3].minor.yy198, yymsp[-2].minor.yy418, yymsp[-1].minor.yy280);
    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy280);
}
#line 2249 "parse.c"
        break;
      case 91:
      case 93:
#line 337 "parse.y"
{yygotominor.yy280 = OE_Default;}
#line 2255 "parse.c"
        break;
      case 96:
#line 342 "parse.y"
{yygotominor.yy280 = OE_Ignore;}
#line 2260 "parse.c"
        break;
      case 97:
      case 167:
#line 343 "parse.y"
{yygotominor.yy280 = OE_Replace;}
#line 2266 "parse.c"
        break;
      case 98:
#line 347 "parse.y"
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy151, 0);
}
#line 2273 "parse.c"
        break;
      case 99:
#line 354 "parse.y"
{
  sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy198, &yymsp[-2].minor.yy198, yymsp[0].minor.yy375, yymsp[-5].minor.yy280);
}
#line 2280 "parse.c"
        break;
      case 100:
#line 357 "parse.y"
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy151, 1);
}
#line 2287 "parse.c"
        break;
      case 101:
#line 364 "parse.y"
{
  sqlite3Select(pParse, yymsp[0].minor.yy375, SRT_Callback, 0, 0, 0, 0, 0);
  sqlite3SelectDelete(yymsp[0].minor.yy375);
}
#line 2295 "parse.c"
        break;
      case 102:
      case 126:
#line 374 "parse.y"
{yygotominor.yy375 = yymsp[0].minor.yy375;}
#line 2301 "parse.c"
        break;
      case 103:
#line 376 "parse.y"
{
  if( yymsp[0].minor.yy375 ){
    yymsp[0].minor.yy375->op = yymsp[-1].minor.yy280;
    yymsp[0].minor.yy375->pPrior = yymsp[-2].minor.yy375;
  }
  yygotominor.yy375 = yymsp[0].minor.yy375;
}
#line 2312 "parse.c"
        break;
      case 105:
#line 385 "parse.y"
{yygotominor.yy280 = TK_ALL;}
#line 2317 "parse.c"
        break;
      case 108:
#line 390 "parse.y"
{

  yygotominor.yy375 = sqlite3SelectNew(yymsp[-6].minor.yy418,yymsp[-5].minor.yy151,yymsp[-4].minor.yy62,yymsp[-3].minor.yy418,yymsp[-2].minor.yy62,yymsp[-1].minor.yy418,yymsp[-7].minor.yy280,yymsp[0].minor.yy220.pLimit,yymsp[0].minor.yy220.pOffset);
}
#line 2324 "parse.c"
        break;
      case 112:
      case 248:
#line 411 "parse.y"
{yygotominor.yy418 = yymsp[-1].minor.yy418;}
#line 2330 "parse.c"
        break;
      case 113:
      case 140:
      case 150:
      case 247:
#line 412 "parse.y"
{yygotominor.yy418 = 0;}
#line 2338 "parse.c"
        break;
      case 114:
#line 413 "parse.y"
{

   yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-2].minor.yy418,yymsp[-1].minor.yy62,yymsp[0].minor.yy198.n?&yymsp[0].minor.yy198:0);
}
#line 2345 "parse.c"
        break;
      case 115:
#line 416 "parse.y"
{
  yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-1].minor.yy418, sqlite3Expr(TK_ALL, 0, 0, 0), 0);
}
#line 2352 "parse.c"
        break;
      case 116:
#line 419 "parse.y"
{
  Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0);
  Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198);
  yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-3].minor.yy418, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0);
}
#line 2361 "parse.c"
        break;
      case 119:
#line 431 "parse.y"
{yygotominor.yy198.n = 0;}





#line 2366 "parse.c"
        break;
      case 120:
#line 443 "parse.y"
{yygotominor.yy151 = sqliteMalloc(sizeof(*yygotominor.yy151));}
#line 2371 "parse.c"
        break;
      case 121:
#line 444 "parse.y"
{yygotominor.yy151 = yymsp[0].minor.yy151;}
#line 2376 "parse.c"
        break;
      case 122:
#line 449 "parse.y"
{
   yygotominor.yy151 = yymsp[-1].minor.yy151;

   if( yygotominor.yy151 && yygotominor.yy151->nSrc>0 ) yygotominor.yy151->a[yygotominor.yy151->nSrc-1].jointype = yymsp[0].minor.yy280;
}
#line 2384 "parse.c"
        break;
      case 123:
#line 453 "parse.y"
{yygotominor.yy151 = 0;}
#line 2389 "parse.c"
        break;
      case 124:
#line 454 "parse.y"
{
  yygotominor.yy151 = sqlite3SrcListAppend(yymsp[-5].minor.yy151,&yymsp[-4].minor.yy198,&yymsp[-3].minor.yy198);
  if( yymsp[-2].minor.yy198.n ) sqlite3SrcListAddAlias(yygotominor.yy151,&yymsp[-2].minor.yy198);
  if( yymsp[-1].minor.yy62 ){

    if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pOn = yymsp[-1].minor.yy62; }
    else { sqlite3ExprDelete(yymsp[-1].minor.yy62); }
  }
  if( yymsp[0].minor.yy240 ){

    if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pUsing = yymsp[0].minor.yy240; }
    else { sqlite3IdListDelete(yymsp[0].minor.yy240); }
  }
}
#line 2405 "parse.c"
        break;
      case 125:
#line 468 "parse.y"
{
    yygotominor.yy151 = sqlite3SrcListAppend(yymsp[-6].minor.yy151,0,0);
    yygotominor.yy151->a[yygotominor.yy151->nSrc-1].pSelect = yymsp[-4].minor.yy375;
    if( yymsp[-2].minor.yy198.n ) sqlite3SrcListAddAlias(yygotominor.yy151,&yymsp[-2].minor.yy198);
    if( yymsp[-1].minor.yy62 ){

      if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pOn = yymsp[-1].minor.yy62; }
      else { sqlite3ExprDelete(yymsp[-1].minor.yy62); }
    }
    if( yymsp[0].minor.yy240 ){

      if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pUsing = yymsp[0].minor.yy240; }
      else { sqlite3IdListDelete(yymsp[0].minor.yy240); }
    }
  }
#line 2422 "parse.c"
        break;
      case 127:
#line 489 "parse.y"
{
     yygotominor.yy375 = sqlite3SelectNew(0,yymsp[0].minor.yy151,0,0,0,0,0,0,0);
  }
#line 2429 "parse.c"
        break;
      case 128:
#line 495 "parse.y"
{yygotominor.yy198.z=0; yygotominor.yy198.n=0;}
#line 2434 "parse.c"
        break;
      case 130:
#line 500 "parse.y"
{yygotominor.yy151 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198);}
#line 2439 "parse.c"
        break;

      case 131:




      case 132:
#line 504 "parse.y"
{ yygotominor.yy280 = JT_INNER; }
#line 2445 "parse.c"
        break;
      case 133:
#line 506 "parse.y"
{ yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
#line 2450 "parse.c"
        break;
      case 134:
#line 507 "parse.y"
{ yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy198,0); }
#line 2455 "parse.c"
        break;
      case 135:








#line 509 "parse.y"

{ yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy198,&yymsp[-1].minor.yy198); }
#line 2460 "parse.c"
        break;
      case 136:
      case 144:
      case 153:
      case 160:
      case 174:
      case 211:
      case 236:
      case 238:
      case 242:
#line 513 "parse.y"
{yygotominor.yy62 = yymsp[0].minor.yy62;}
#line 2473 "parse.c"
        break;
      case 137:
      case 152:
      case 159:
      case 212:
      case 237:
      case 239:
      case 243:
#line 514 "parse.y"
{yygotominor.yy62 = 0;}
#line 2484 "parse.c"
        break;
      case 138:
      case 171:
#line 518 "parse.y"
{yygotominor.yy240 = yymsp[-1].minor.yy240;}
#line 2490 "parse.c"
        break;
      case 139:
      case 170:
#line 519 "parse.y"
{yygotominor.yy240 = 0;}
#line 2496 "parse.c"
        break;
      case 141:
      case 151:
#line 530 "parse.y"
{yygotominor.yy418 = yymsp[0].minor.yy418;}
#line 2502 "parse.c"
        break;
      case 142:
#line 531 "parse.y"
{


  yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418,yymsp[-2].minor.yy62,yymsp[-1].minor.yy198.n>0?&yymsp[-1].minor.yy198:0);
  if( yygotominor.yy418 ) yygotominor.yy418->a[yygotominor.yy418->nExpr-1].sortOrder = yymsp[0].minor.yy280;
}
#line 2510 "parse.c"
        break;
      case 143:
#line 535 "parse.y"
{
  yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy62,yymsp[-1].minor.yy198.n>0?&yymsp[-1].minor.yy198:0);

  if( yygotominor.yy418 && yygotominor.yy418->a ) yygotominor.yy418->a[0].sortOrder = yymsp[0].minor.yy280;
}
#line 2518 "parse.c"
        break;
      case 145:
      case 147:
#line 544 "parse.y"
{yygotominor.yy280 = SQLITE_SO_ASC;}
#line 2524 "parse.c"
        break;
      case 146:
#line 545 "parse.y"
{yygotominor.yy280 = SQLITE_SO_DESC;}
#line 2529 "parse.c"
        break;
      case 148:
#line 547 "parse.y"
{yygotominor.yy198.z = 0; yygotominor.yy198.n = 0;}
#line 2534 "parse.c"
        break;
      case 154:
#line 565 "parse.y"
{yygotominor.yy220.pLimit = 0; yygotominor.yy220.pOffset = 0;}
#line 2539 "parse.c"
        break;
      case 155:
#line 566 "parse.y"

{yygotominor.yy220.pLimit = yymsp[0].minor.yy62; yygotominor.yy220.pOffset = 0;}
#line 2544 "parse.c"
        break;
      case 156:
#line 568 "parse.y"

{yygotominor.yy220.pLimit = yymsp[-2].minor.yy62; yygotominor.yy220.pOffset = yymsp[0].minor.yy62;}
#line 2549 "parse.c"
        break;
      case 157:
#line 570 "parse.y"

{yygotominor.yy220.pOffset = yymsp[-2].minor.yy62; yygotominor.yy220.pLimit = yymsp[0].minor.yy62;}
#line 2554 "parse.c"
        break;
      case 158:
#line 574 "parse.y"
{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy151,yymsp[0].minor.yy62);}
#line 2559 "parse.c"
        break;
      case 161:
#line 585 "parse.y"
{sqlite3Update(pParse,yymsp[-3].minor.yy151,yymsp[-1].minor.yy418,yymsp[0].minor.yy62,yymsp[-4].minor.yy280);}
#line 2564 "parse.c"





        break;
      case 162:
#line 591 "parse.y"
{yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418,yymsp[0].minor.yy62,&yymsp[-2].minor.yy198);}
#line 2569 "parse.c"
        break;
      case 163:
#line 592 "parse.y"
{yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[0].minor.yy62,&yymsp[-2].minor.yy198);}
#line 2574 "parse.c"
        break;
      case 164:
#line 598 "parse.y"
{sqlite3Insert(pParse, yymsp[-5].minor.yy151, yymsp[-1].minor.yy418, 0, yymsp[-4].minor.yy240, yymsp[-7].minor.yy280);}
#line 2579 "parse.c"
        break;
      case 165:

#line 600 "parse.y"

{sqlite3Insert(pParse, yymsp[-2].minor.yy151, 0, yymsp[0].minor.yy375, yymsp[-1].minor.yy240, yymsp[-4].minor.yy280);}
#line 2584 "parse.c"
        break;
      case 168:
      case 240:
#line 610 "parse.y"
{yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-2].minor.yy418,yymsp[0].minor.yy62,0);}
#line 2590 "parse.c"
        break;
      case 169:
      case 241:
#line 611 "parse.y"

{yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[0].minor.yy62,0);}
#line 2596 "parse.c"
        break;
      case 172:
#line 620 "parse.y"
{yygotominor.yy240 = sqlite3IdListAppend(yymsp[-2].minor.yy240,&yymsp[0].minor.yy198);}
#line 2601 "parse.c"
        break;
      case 173:
#line 621 "parse.y"
{yygotominor.yy240 = sqlite3IdListAppend(0,&yymsp[0].minor.yy198);}
#line 2606 "parse.c"
        break;
      case 175:
#line 632 "parse.y"
{yygotominor.yy62 = yymsp[-1].minor.yy62; sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
#line 2611 "parse.c"
        break;
      case 176:
      case 181:
      case 182:
      case 183:
      case 184:
#line 633 "parse.y"
{yygotominor.yy62 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
#line 2620 "parse.c"
        break;
      case 177:
      case 178:
#line 634 "parse.y"
{yygotominor.yy62 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);}
#line 2626 "parse.c"
        break;
      case 179:
#line 636 "parse.y"
{
  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198);
  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy198);
  yygotominor.yy62 = sqlite3Expr(TK_DOT, temp1, temp2, 0);
}
#line 2635 "parse.c"
        break;
      case 180:
#line 641 "parse.y"
{
  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy198);
  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198);
  Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy198);
  Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
  yygotominor.yy62 = sqlite3Expr(TK_DOT, temp1, temp4, 0);
}





#line 2646 "parse.c"
        break;
      case 185:
#line 652 "parse.y"
{yygotominor.yy62 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
#line 2651 "parse.c"
        break;
      case 186:
#line 653 "parse.y"
{
  Token *pToken = &yymsp[0].minor.yy0;
  Expr *pExpr = yygotominor.yy62 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
  sqlite3ExprAssignVarNumber(pParse, pExpr);
}
#line 2660 "parse.c"
        break;
      case 187:
#line 659 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_CAST, yymsp[-3].minor.yy62, 0, &yymsp[-1].minor.yy198);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
}
#line 2668 "parse.c"
        break;
      case 188:
#line 664 "parse.y"
{
  yygotominor.yy62 = sqlite3ExprFunction(yymsp[-1].minor.yy418, &yymsp[-4].minor.yy0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
  if( yymsp[-2].minor.yy280 ){
    yygotominor.yy62->flags |= EP_Distinct;
  }







}
#line 2679 "parse.c"
        break;
      case 189:
#line 671 "parse.y"
{
  yygotominor.yy62 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
}
#line 2687 "parse.c"
        break;
      case 190:
#line 675 "parse.y"
{
  /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
  ** treated as functions that return constants */
  yygotominor.yy62 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0);

  if( yygotominor.yy62 ) yygotominor.yy62->op = TK_CONST_FUNC;  
}
#line 2697 "parse.c"
        break;

      case 191:
      case 192:
      case 193:
      case 194:
      case 195:
      case 196:
      case 197:
................................................................................
      case 201:
      case 202:
      case 203:
      case 204:
      case 205:
      case 206:
      case 207:
      case 208:
#line 681 "parse.y"
{yygotominor.yy62 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy62, yymsp[0].minor.yy62, 0);}
#line 2719 "parse.c"
        break;
      case 209:
#line 700 "parse.y"
{yygotominor.yy222.operator = yymsp[0].minor.yy0; yygotominor.yy222.not = 0;}
#line 2724 "parse.c"
        break;
      case 210:
#line 701 "parse.y"
{yygotominor.yy222.operator = yymsp[0].minor.yy0; yygotominor.yy222.not = 1;}
#line 2729 "parse.c"
        break;
      case 213:
#line 705 "parse.y"
{
  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy62, 0);
  pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy62, 0);
  if( yymsp[0].minor.yy62 ){
    pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy62, 0);
  }
  yygotominor.yy62 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy222.operator);
  if( yymsp[-2].minor.yy222.not ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0);

  sqlite3ExprSpan(yygotominor.yy62, &yymsp[-3].minor.yy62->span, &yymsp[-1].minor.yy62->span);
}
#line 2743 "parse.c"








        break;
      case 214:
#line 716 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy62->span,&yymsp[0].minor.yy0);
}
#line 2751 "parse.c"
        break;
      case 215:
#line 720 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy62->span,&yymsp[0].minor.yy0);
}
#line 2759 "parse.c"
        break;
      case 216:
#line 724 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy62->span,&yymsp[0].minor.yy0);
}
#line 2767 "parse.c"
        break;
      case 217:
#line 728 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy62->span,&yymsp[0].minor.yy0);
}
#line 2775 "parse.c"
        break;
      case 218:
#line 732 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy62->span,&yymsp[0].minor.yy0);
}
#line 2783 "parse.c"
        break;
      case 219:
      case 220:
#line 736 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span);
}
#line 2792 "parse.c"
        break;
      case 221:
#line 744 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span);
}
#line 2800 "parse.c"
        break;
      case 222:
#line 748 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy62, 0, 0);
  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span);
}
#line 2808 "parse.c"
        break;
      case 225:
#line 755 "parse.y"
{
  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy62, 0);
  pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy62, 0);
  yygotominor.yy62 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy62, 0, 0);
  if( yygotominor.yy62 ){
    yygotominor.yy62->pList = pList;
  }else{
    sqlite3ExprListDelete(pList);
  } 
  if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0);

  sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy62->span);
}
#line 2824 "parse.c"
        break;
      case 228:
#line 771 "parse.y"
{
    yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy62, 0, 0);
    if( yygotominor.yy62 ){
      yygotominor.yy62->pList = yymsp[-1].minor.yy418;
    }else{
      sqlite3ExprListDelete(yymsp[-1].minor.yy418);
    }
    if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0);
    sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy0);
  }
#line 2838 "parse.c"
        break;
      case 229:
#line 781 "parse.y"
{
    yygotominor.yy62 = sqlite3Expr(TK_SELECT, 0, 0, 0);
    if( yygotominor.yy62 ){
      yygotominor.yy62->pSelect = yymsp[-1].minor.yy375;
    }else{
      sqlite3SelectDelete(yymsp[-1].minor.yy375);
    }
    sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
  }
#line 2851 "parse.c"
        break;
      case 230:
#line 790 "parse.y"
{
    yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy62, 0, 0);
    if( yygotominor.yy62 ){
      yygotominor.yy62->pSelect = yymsp[-1].minor.yy375;
    }else{
      sqlite3SelectDelete(yymsp[-1].minor.yy375);


    }








    if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0);







    sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy0);





  }
#line 2865 "parse.c"
        break;
      case 231:
#line 800 "parse.y"
{
    SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198);
    yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy62, 0, 0);
    if( yygotominor.yy62 ){
      yygotominor.yy62->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
    }else{
      sqlite3SrcListDelete(pSrc);
    }
    if( yymsp[-2].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0);
    sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy62->span,yymsp[0].minor.yy198.z?&yymsp[0].minor.yy198:&yymsp[-1].minor.yy198);
  }
#line 2880 "parse.c"
        break;
      case 232:
#line 811 "parse.y"
{
    Expr *p = yygotominor.yy62 = sqlite3Expr(TK_EXISTS, 0, 0, 0);
    if( p ){
      p->pSelect = yymsp[-1].minor.yy375;
      sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
    }else{
      sqlite3SelectDelete(yymsp[-1].minor.yy375);
    }
  }
#line 2893 "parse.c"
        break;
      case 233:
#line 823 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy62, yymsp[-1].minor.yy62, 0);
  if( yygotominor.yy62 ){
    yygotominor.yy62->pList = yymsp[-2].minor.yy418;
  }else{
    sqlite3ExprListDelete(yymsp[-2].minor.yy418);
  }
  sqlite3ExprSpan(yygotominor.yy62, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
}
#line 2906 "parse.c"
        break;
      case 234:
#line 834 "parse.y"
{
  yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418, yymsp[-2].minor.yy62, 0);
  yygotominor.yy418 = sqlite3ExprListAppend(yygotominor.yy418, yymsp[0].minor.yy62, 0);
}
#line 2914 "parse.c"
        break;
      case 235:
#line 838 "parse.y"
{
  yygotominor.yy418 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy62, 0);
  yygotominor.yy418 = sqlite3ExprListAppend(yygotominor.yy418, yymsp[0].minor.yy62, 0);
}
#line 2922 "parse.c"
        break;
      case 244:
#line 863 "parse.y"
{
  if( yymsp[-9].minor.yy280!=OE_None ) yymsp[-9].minor.yy280 = yymsp[0].minor.yy280;
  if( yymsp[-9].minor.yy280==OE_Default) yymsp[-9].minor.yy280 = OE_Abort;
  sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy198, &yymsp[-6].minor.yy198, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy198,0),yymsp[-2].minor.yy418,yymsp[-9].minor.yy280, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0);
}
#line 2931 "parse.c"
        break;
      case 245:
      case 292:
#line 870 "parse.y"
{yygotominor.yy280 = OE_Abort;}
#line 2937 "parse.c"
        break;
      case 246:
#line 871 "parse.y"
{yygotominor.yy280 = OE_None;}
#line 2942 "parse.c"
        break;
      case 249:
#line 881 "parse.y"
{
  Expr *p = 0;
  if( yymsp[-1].minor.yy198.n>0 ){
    p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy198.z, yymsp[-1].minor.yy198.n);
  }
  yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418, p, &yymsp[-2].minor.yy198);
}
#line 2954 "parse.c"
        break;
      case 250:
#line 889 "parse.y"
{
  Expr *p = 0;
  if( yymsp[-1].minor.yy198.n>0 ){
    p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy198.z, yymsp[-1].minor.yy198.n);
  }
  yygotominor.yy418 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy198);
}
#line 2966 "parse.c"
        break;
      case 252:
#line 902 "parse.y"
{sqlite3DropIndex(pParse, yymsp[0].minor.yy151);}
#line 2971 "parse.c"
        break;
      case 253:
      case 254:
#line 906 "parse.y"
{sqlite3Vacuum(pParse,0);}
#line 2977 "parse.c"
        break;
      case 255:
      case 257:
#line 912 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy198,0);}
#line 2983 "parse.c"
        break;
      case 256:
#line 913 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy0,0);}
#line 2988 "parse.c"
        break;
      case 258:
#line 915 "parse.y"
{
  sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy198,1);
}
#line 2995 "parse.c"
        break;
      case 259:
#line 918 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy198,&yymsp[-3].minor.yy198,&yymsp[-1].minor.yy198,0);}
#line 3000 "parse.c"
        break;
      case 260:
#line 919 "parse.y"
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198,0,0);}
#line 3005 "parse.c"
        break;
      case 267:
#line 932 "parse.y"
{
  Token all;
  all.z = yymsp[-3].minor.yy198.z;
  all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy198.z) + yymsp[0].minor.yy0.n;
  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy360, &all);
}
#line 3015 "parse.c"
        break;
      case 268:
#line 941 "parse.y"
{
  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy198, &yymsp[-6].minor.yy198, yymsp[-5].minor.yy280, yymsp[-4].minor.yy30.a, yymsp[-4].minor.yy30.b, yymsp[-2].minor.yy151, yymsp[-1].minor.yy280, yymsp[0].minor.yy62, yymsp[-9].minor.yy280);
  yygotominor.yy198 = (yymsp[-6].minor.yy198.n==0?yymsp[-7].minor.yy198:yymsp[-6].minor.yy198);
}
#line 3023 "parse.c"
        break;
      case 269:
      case 272:
#line 947 "parse.y"
{ yygotominor.yy280 = TK_BEFORE; }
#line 3029 "parse.c"
        break;
      case 270:
#line 948 "parse.y"
{ yygotominor.yy280 = TK_AFTER;  }
#line 3034 "parse.c"
        break;
      case 271:
#line 949 "parse.y"
{ yygotominor.yy280 = TK_INSTEAD;}
#line 3039 "parse.c"
        break;
      case 273:
      case 274:
      case 275:
#line 954 "parse.y"
{yygotominor.yy30.a = yymsp[0].major; yygotominor.yy30.b = 0;}
#line 3046 "parse.c"
        break;
      case 276:
#line 957 "parse.y"
{yygotominor.yy30.a = TK_UPDATE; yygotominor.yy30.b = yymsp[0].minor.yy240;}
#line 3051 "parse.c"
        break;
      case 277:
      case 278:
#line 960 "parse.y"
{ yygotominor.yy280 = TK_ROW; }
#line 3057 "parse.c"
        break;
      case 279:
#line 962 "parse.y"
{ yygotominor.yy280 = TK_STATEMENT; }
#line 3062 "parse.c"
        break;
      case 280:
#line 965 "parse.y"
{ yygotominor.yy62 = 0; }
#line 3067 "parse.c"
        break;
      case 281:
#line 966 "parse.y"
{ yygotominor.yy62 = yymsp[0].minor.yy62; }
#line 3072 "parse.c"
        break;
      case 282:
#line 970 "parse.y"
{
  yymsp[-2].minor.yy360->pNext = yymsp[0].minor.yy360;
  yygotominor.yy360 = yymsp[-2].minor.yy360;
}
#line 3080 "parse.c"
        break;
      case 283:
#line 974 "parse.y"
{ yygotominor.yy360 = 0; }
#line 3085 "parse.c"
        break;
      case 284:
#line 980 "parse.y"
{ yygotominor.yy360 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy198, yymsp[-1].minor.yy418, yymsp[0].minor.yy62, yymsp[-4].minor.yy280); }
#line 3090 "parse.c"
        break;
      case 285:
#line 985 "parse.y"
{yygotominor.yy360 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy198, yymsp[-4].minor.yy240, yymsp[-1].minor.yy418, 0, yymsp[-7].minor.yy280);}
#line 3095 "parse.c"
        break;
      case 286:
#line 988 "parse.y"
{yygotominor.yy360 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy198, yymsp[-1].minor.yy240, 0, yymsp[0].minor.yy375, yymsp[-4].minor.yy280);}
#line 3100 "parse.c"
        break;
      case 287:
#line 992 "parse.y"
{yygotominor.yy360 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy198, yymsp[0].minor.yy62);}
#line 3105 "parse.c"
        break;
      case 288:
#line 995 "parse.y"
{yygotominor.yy360 = sqlite3TriggerSelectStep(yymsp[0].minor.yy375); }
#line 3110 "parse.c"
        break;
      case 289:
#line 998 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_RAISE, 0, 0, 0); 
  yygotominor.yy62->iColumn = OE_Ignore;
  sqlite3ExprSpan(yygotominor.yy62, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
}
#line 3119 "parse.c"
        break;
      case 290:
#line 1003 "parse.y"
{
  yygotominor.yy62 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy198); 
  yygotominor.yy62->iColumn = yymsp[-3].minor.yy280;
  sqlite3ExprSpan(yygotominor.yy62, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
}
#line 3128 "parse.c"
        break;
      case 291:
#line 1011 "parse.y"
{yygotominor.yy280 = OE_Rollback;}
#line 3133 "parse.c"
        break;
      case 293:
#line 1013 "parse.y"
{yygotominor.yy280 = OE_Fail;}
#line 3138 "parse.c"
        break;
      case 294:
#line 1018 "parse.y"
{
  sqlite3DropTrigger(pParse,yymsp[0].minor.yy151);
}
#line 3145 "parse.c"
        break;
      case 295:
#line 1024 "parse.y"
{
  sqlite3Attach(pParse, &yymsp[-3].minor.yy198, &yymsp[-1].minor.yy198, yymsp[0].minor.yy361.type, &yymsp[0].minor.yy361.key);
}
#line 3152 "parse.c"
        break;
      case 296:
#line 1028 "parse.y"
{ yygotominor.yy361.type = 0; }
#line 3157 "parse.c"
        break;
      case 297:
#line 1029 "parse.y"
{ yygotominor.yy361.type=1; yygotominor.yy361.key = yymsp[0].minor.yy198; }
#line 3162 "parse.c"
        break;
      case 298:
#line 1030 "parse.y"
{ yygotominor.yy361.type=2; yygotominor.yy361.key = yymsp[0].minor.yy0; }
#line 3167 "parse.c"
        break;
      case 301:
#line 1036 "parse.y"
{
  sqlite3Detach(pParse, &yymsp[0].minor.yy198);
}
#line 3174 "parse.c"
        break;
      case 302:
#line 1042 "parse.y"
{sqlite3Reindex(pParse, 0, 0);}
#line 3179 "parse.c"
        break;
      case 303:
#line 1043 "parse.y"
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy198, &yymsp[0].minor.yy198);}
#line 3184 "parse.c"
        break;
      case 304:
#line 1048 "parse.y"
{sqlite3Analyze(pParse, 0, 0);}
#line 3189 "parse.c"
        break;
      case 305:
#line 1049 "parse.y"
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy198, &yymsp[0].minor.yy198);}
#line 3194 "parse.c"
        break;
      case 306:
#line 1054 "parse.y"
{
  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy151,&yymsp[0].minor.yy198);
}
#line 3201 "parse.c"
        break;
      case 307:
#line 1057 "parse.y"
{
  sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy198);
}
#line 3208 "parse.c"
        break;
      case 308:
#line 1060 "parse.y"
{
  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy151);
}
#line 3215 "parse.c"
        break;
  };
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->yyidx -= yysize;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto);
  if( yyact < YYNSTATE ){
................................................................................
  if( pParse->zErrMsg==0 ){
    if( TOKEN.z[0] ){
      sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
    }else{
      sqlite3ErrorMsg(pParse, "incomplete SQL statement");
    }
  }
#line 3282 "parse.c"
  sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}

/*
** The following is executed when the parser accepts
*/
static void yy_accept(

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

2
3
4
5
6
7
8

9
10
11


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#define TK_ILLEGAL                         2
#define TK_SPACE                           3
#define TK_UNCLOSED_STRING                 4
#define TK_COMMENT                         5
#define TK_FUNCTION                        6
#define TK_COLUMN                          7
#define TK_AGG_FUNCTION                    8

#define TK_CONST_FUNC                      9
#define TK_SEMI                           10
#define TK_EXPLAIN                        11


#define TK_BEGIN                          12
#define TK_TRANSACTION                    13
#define TK_DEFERRED                       14
#define TK_IMMEDIATE                      15
#define TK_EXCLUSIVE                      16
#define TK_COMMIT                         17
#define TK_END                            18
#define TK_ROLLBACK                       19
#define TK_CREATE                         20
#define TK_TABLE                          21
#define TK_TEMP                           22
#define TK_LP                             23
#define TK_RP                             24
#define TK_AS                             25
#define TK_COMMA                          26
#define TK_ID                             27
#define TK_ABORT                          28
#define TK_AFTER                          29
#define TK_ANALYZE                        30
#define TK_ASC                            31
#define TK_ATTACH                         32
#define TK_BEFORE                         33
#define TK_CASCADE                        34
#define TK_CAST                           35
#define TK_CONFLICT                       36
#define TK_DATABASE                       37
#define TK_DESC                           38
#define TK_DETACH                         39
#define TK_EACH                           40
#define TK_FAIL                           41
#define TK_FOR                            42
#define TK_IGNORE                         43
#define TK_INITIALLY                      44
#define TK_INSTEAD                        45
#define TK_LIKE_KW                        46
#define TK_MATCH                          47
#define TK_KEY                            48
#define TK_OF                             49
#define TK_OFFSET                         50
#define TK_PRAGMA                         51
#define TK_RAISE                          52
#define TK_REPLACE                        53
#define TK_RESTRICT                       54
#define TK_ROW                            55
#define TK_STATEMENT                      56
#define TK_TRIGGER                        57
#define TK_VACUUM                         58
#define TK_VIEW                           59
#define TK_REINDEX                        60
#define TK_RENAME                         61
#define TK_CTIME_KW                       62
#define TK_ALTER                          63
#define TK_OR                             64
#define TK_AND                            65
#define TK_NOT                            66
#define TK_IS                             67
#define TK_BETWEEN                        68
#define TK_IN                             69
#define TK_ISNULL                         70
#define TK_NOTNULL                        71
#define TK_NE                             72
#define TK_EQ                             73
#define TK_GT                             74
#define TK_LE                             75
#define TK_LT                             76
#define TK_GE                             77
#define TK_ESCAPE                         78
#define TK_BITAND                         79
#define TK_BITOR                          80
#define TK_LSHIFT                         81
#define TK_RSHIFT                         82
#define TK_PLUS                           83
#define TK_MINUS                          84
#define TK_STAR                           85
#define TK_SLASH                          86
#define TK_REM                            87
#define TK_CONCAT                         88
#define TK_UMINUS                         89
#define TK_UPLUS                          90
#define TK_BITNOT                         91
#define TK_STRING                         92
#define TK_JOIN_KW                        93
#define TK_CONSTRAINT                     94
#define TK_DEFAULT                        95
#define TK_NULL                           96
#define TK_PRIMARY                        97
#define TK_UNIQUE                         98
#define TK_CHECK                          99
#define TK_REFERENCES                     100
#define TK_COLLATE                        101
#define TK_AUTOINCR                       102
#define TK_ON                             103
#define TK_DELETE                         104
#define TK_UPDATE                         105
#define TK_INSERT                         106
#define TK_SET                            107
#define TK_DEFERRABLE                     108
#define TK_FOREIGN                        109
#define TK_DROP                           110
#define TK_UNION                          111
#define TK_ALL                            112
#define TK_INTERSECT                      113
#define TK_EXCEPT                         114
#define TK_SELECT                         115
#define TK_DISTINCT                       116
#define TK_DOT                            117
#define TK_FROM                           118
#define TK_JOIN                           119
#define TK_USING                          120
#define TK_ORDER                          121
#define TK_BY                             122
#define TK_GROUP                          123
#define TK_HAVING                         124
#define TK_LIMIT                          125
#define TK_WHERE                          126
#define TK_INTO                           127
#define TK_VALUES                         128
#define TK_INTEGER                        129
#define TK_FLOAT                          130
#define TK_BLOB                           131
#define TK_REGISTER                       132
#define TK_VARIABLE                       133
#define TK_EXISTS                         134
#define TK_CASE                           135
#define TK_WHEN                           136
#define TK_THEN                           137
#define TK_ELSE                           138
#define TK_INDEX                          139
#define TK_TO                             140
#define TK_ADD                            141
#define TK_COLUMNKW                       142







>
|
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#define TK_ILLEGAL                         2
#define TK_SPACE                           3
#define TK_UNCLOSED_STRING                 4
#define TK_COMMENT                         5
#define TK_FUNCTION                        6
#define TK_COLUMN                          7
#define TK_AGG_FUNCTION                    8
#define TK_AGG_COLUMN                      9
#define TK_CONST_FUNC                     10
#define TK_SEMI                           11
#define TK_EXPLAIN                        12
#define TK_QUERY                          13
#define TK_PLAN                           14
#define TK_BEGIN                          15
#define TK_TRANSACTION                    16
#define TK_DEFERRED                       17
#define TK_IMMEDIATE                      18
#define TK_EXCLUSIVE                      19
#define TK_COMMIT                         20
#define TK_END                            21
#define TK_ROLLBACK                       22
#define TK_CREATE                         23
#define TK_TABLE                          24
#define TK_TEMP                           25
#define TK_LP                             26
#define TK_RP                             27
#define TK_AS                             28
#define TK_COMMA                          29
#define TK_ID                             30
#define TK_ABORT                          31
#define TK_AFTER                          32
#define TK_ANALYZE                        33
#define TK_ASC                            34
#define TK_ATTACH                         35
#define TK_BEFORE                         36
#define TK_CASCADE                        37
#define TK_CAST                           38
#define TK_CONFLICT                       39
#define TK_DATABASE                       40
#define TK_DESC                           41
#define TK_DETACH                         42
#define TK_EACH                           43
#define TK_FAIL                           44
#define TK_FOR                            45
#define TK_IGNORE                         46
#define TK_INITIALLY                      47
#define TK_INSTEAD                        48
#define TK_LIKE_KW                        49
#define TK_MATCH                          50
#define TK_KEY                            51
#define TK_OF                             52
#define TK_OFFSET                         53
#define TK_PRAGMA                         54
#define TK_RAISE                          55
#define TK_REPLACE                        56
#define TK_RESTRICT                       57
#define TK_ROW                            58
#define TK_STATEMENT                      59
#define TK_TRIGGER                        60
#define TK_VACUUM                         61
#define TK_VIEW                           62
#define TK_REINDEX                        63
#define TK_RENAME                         64
#define TK_CTIME_KW                       65
#define TK_ALTER                          66
#define TK_OR                             67
#define TK_AND                            68
#define TK_NOT                            69
#define TK_IS                             70
#define TK_BETWEEN                        71
#define TK_IN                             72
#define TK_ISNULL                         73
#define TK_NOTNULL                        74
#define TK_NE                             75
#define TK_EQ                             76
#define TK_GT                             77
#define TK_LE                             78
#define TK_LT                             79
#define TK_GE                             80
#define TK_ESCAPE                         81
#define TK_BITAND                         82
#define TK_BITOR                          83
#define TK_LSHIFT                         84
#define TK_RSHIFT                         85
#define TK_PLUS                           86
#define TK_MINUS                          87
#define TK_STAR                           88
#define TK_SLASH                          89
#define TK_REM                            90
#define TK_CONCAT                         91
#define TK_UMINUS                         92
#define TK_UPLUS                          93
#define TK_BITNOT                         94
#define TK_STRING                         95
#define TK_JOIN_KW                        96
#define TK_CONSTRAINT                     97
#define TK_DEFAULT                        98
#define TK_NULL                           99
#define TK_PRIMARY                        100
#define TK_UNIQUE                         101
#define TK_CHECK                          102
#define TK_REFERENCES                     103
#define TK_COLLATE                        104
#define TK_AUTOINCR                       105
#define TK_ON                             106
#define TK_DELETE                         107
#define TK_UPDATE                         108
#define TK_INSERT                         109
#define TK_SET                            110
#define TK_DEFERRABLE                     111
#define TK_FOREIGN                        112
#define TK_DROP                           113
#define TK_UNION                          114
#define TK_ALL                            115
#define TK_INTERSECT                      116
#define TK_EXCEPT                         117
#define TK_SELECT                         118
#define TK_DISTINCT                       119
#define TK_DOT                            120
#define TK_FROM                           121
#define TK_JOIN                           122
#define TK_USING                          123
#define TK_ORDER                          124
#define TK_BY                             125
#define TK_GROUP                          126
#define TK_HAVING                         127
#define TK_LIMIT                          128
#define TK_WHERE                          129
#define TK_INTO                           130
#define TK_VALUES                         131
#define TK_INTEGER                        132
#define TK_FLOAT                          133
#define TK_BLOB                           134
#define TK_REGISTER                       135
#define TK_VARIABLE                       136
#define TK_EXISTS                         137
#define TK_CASE                           138
#define TK_WHEN                           139
#define TK_THEN                           140
#define TK_ELSE                           141
#define TK_INDEX                          142
#define TK_TO                             143
#define TK_ADD                            144
#define TK_COLUMNKW                       145

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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
...
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
...
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.8 2005/09/01 06:07:56 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/* Ignore this whole file if pragmas are disabled
*/
................................................................................
    }
  }else

#ifndef SQLITE_OMIT_INTEGRITY_CHECK
  if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
    int i, j, addr;

    /* Code that initializes the integrity check program.  Set the
    ** error count 0
    */
    static const VdbeOpList initCode[] = {
      { OP_Integer,     0, 0,        0},
      { OP_MemStore,    0, 1,        0},
    };

    /* Code that appears at the end of the integrity check.  If no error
    ** messages have been generated, output OK.  Otherwise output the
    ** error message
    */
    static const VdbeOpList endCode[] = {
      { OP_MemLoad,     0, 0,        0},
      { OP_Integer,     0, 0,        0},
................................................................................
      { OP_Callback,    1, 0,        0},
    };

    /* Initialize the VDBE program */
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
    sqlite3VdbeAddOpList(v, ArraySize(initCode), initCode);

    /* Do an integrity check on each database file */
    for(i=0; i<db->nDb; i++){
      HashElem *x;
      int cnt = 0;

      if( OMIT_TEMPDB && i==1 ) continue;
................................................................................
      for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
        Table *pTab = sqliteHashData(x);
        Index *pIdx;
        int loopTop;

        if( pTab->pIndex==0 ) continue;
        sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
        sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
        sqlite3VdbeAddOp(v, OP_MemStore, 1, 1);
        loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
        sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
          int jmp2;
          static const VdbeOpList idxErr[] = {
            { OP_MemIncr,     0,  0,  0},
            { OP_String8,     0,  0,  "rowid "},
................................................................................
            { OP_Concat,      2,  0,  0},
            { OP_Callback,    1,  0,  0},
          };
          sqlite3GenerateIndexKey(v, pIdx, 1);
          jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
          addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
          sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
          sqlite3VdbeChangeP2(v, jmp2, sqlite3VdbeCurrentAddr(v));
        }
        sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
        sqlite3VdbeChangeP2(v, loopTop, sqlite3VdbeCurrentAddr(v));
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
          static const VdbeOpList cntIdx[] = {
             { OP_Integer,      0,  0,  0},
             { OP_MemStore,     2,  1,  0},
             { OP_Rewind,       0,  0,  0},  /* 2 */
             { OP_MemIncr,      2,  0,  0},
             { OP_Next,         0,  0,  0},  /* 4 */
             { OP_MemLoad,      1,  0,  0},
             { OP_MemLoad,      2,  0,  0},
             { OP_Eq,           0,  0,  0},  /* 7 */
             { OP_MemIncr,      0,  0,  0},
             { OP_String8,      0,  0,  "wrong # of entries in index "},
             { OP_String8,      0,  0,  0},  /* 10 */
             { OP_Concat,       0,  0,  0},
             { OP_Callback,     1,  0,  0},
          };
          if( pIdx->tnum==0 ) continue;
          addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
          sqlite3VdbeChangeP1(v, addr+2, j+2);
          sqlite3VdbeChangeP2(v, addr+2, addr+5);
          sqlite3VdbeChangeP1(v, addr+4, j+2);
          sqlite3VdbeChangeP2(v, addr+4, addr+3);
          sqlite3VdbeChangeP2(v, addr+7, addr+ArraySize(cntIdx));
          sqlite3VdbeChangeP3(v, addr+10, pIdx->zName, P3_STATIC);
        }
      } 
    }
    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
    sqlite3VdbeChangeP2(v, addr+2, addr+ArraySize(endCode));
  }else
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */

#ifndef SQLITE_OMIT_UTF16
  /*
  **   PRAGMA encoding
  **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
................................................................................
    sqlite3VdbeSetNumCols(v, 2);
    sqlite3VdbeSetColName(v, 0, "database", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, "status", P3_STATIC);
    for(i=0; i<db->nDb; i++){
      Btree *pBt;
      Pager *pPager;
      if( db->aDb[i].zName==0 ) continue;
      sqlite3VdbeOp3(v, OP_String, 0, 0, db->aDb[i].zName, P3_STATIC);
      pBt = db->aDb[i].pBt;
      if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
        sqlite3VdbeOp3(v, OP_String, 0, 0, "closed", P3_STATIC);
      }else{
        int j = sqlite3pager_lockstate(pPager);
        sqlite3VdbeOp3(v, OP_String, 0, 0, 
            (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
      }
      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
    }
  }else
#endif








|







 







<
<
<
<
<
<
<
<







 







|







 







<
|







 







|


|


|
<
|

|


|


|





|
|
|
|
|
|




|







 







|


|


|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
622
623
624
625
626
627
628








629
630
631
632
633
634
635
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
...
684
685
686
687
688
689
690

691
692
693
694
695
696
697
698
...
702
703
704
705
706
707
708
709
710
711
712
713
714
715

716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/* Ignore this whole file if pragmas are disabled
*/
................................................................................
    }
  }else

#ifndef SQLITE_OMIT_INTEGRITY_CHECK
  if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
    int i, j, addr;









    /* Code that appears at the end of the integrity check.  If no error
    ** messages have been generated, output OK.  Otherwise output the
    ** error message
    */
    static const VdbeOpList endCode[] = {
      { OP_MemLoad,     0, 0,        0},
      { OP_Integer,     0, 0,        0},
................................................................................
      { OP_Callback,    1, 0,        0},
    };

    /* Initialize the VDBE program */
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, "integrity_check", P3_STATIC);
    sqlite3VdbeAddOp(v, OP_MemInt, 0, 0);  /* Initialize error count to 0 */

    /* Do an integrity check on each database file */
    for(i=0; i<db->nDb; i++){
      HashElem *x;
      int cnt = 0;

      if( OMIT_TEMPDB && i==1 ) continue;
................................................................................
      for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){
        Table *pTab = sqliteHashData(x);
        Index *pIdx;
        int loopTop;

        if( pTab->pIndex==0 ) continue;
        sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);

        sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
        loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
        sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0);
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
          int jmp2;
          static const VdbeOpList idxErr[] = {
            { OP_MemIncr,     0,  0,  0},
            { OP_String8,     0,  0,  "rowid "},
................................................................................
            { OP_Concat,      2,  0,  0},
            { OP_Callback,    1,  0,  0},
          };
          sqlite3GenerateIndexKey(v, pIdx, 1);
          jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
          addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
          sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
          sqlite3VdbeJumpHere(v, jmp2);
        }
        sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
        sqlite3VdbeJumpHere(v, loopTop);
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
          static const VdbeOpList cntIdx[] = {
             { OP_MemInt,       0,  2,  0},

             { OP_Rewind,       0,  0,  0},  /* 1 */
             { OP_MemIncr,      2,  0,  0},
             { OP_Next,         0,  0,  0},  /* 3 */
             { OP_MemLoad,      1,  0,  0},
             { OP_MemLoad,      2,  0,  0},
             { OP_Eq,           0,  0,  0},  /* 6 */
             { OP_MemIncr,      0,  0,  0},
             { OP_String8,      0,  0,  "wrong # of entries in index "},
             { OP_String8,      0,  0,  0},  /* 9 */
             { OP_Concat,       0,  0,  0},
             { OP_Callback,     1,  0,  0},
          };
          if( pIdx->tnum==0 ) continue;
          addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
          sqlite3VdbeChangeP1(v, addr+1, j+2);
          sqlite3VdbeChangeP2(v, addr+1, addr+4);
          sqlite3VdbeChangeP1(v, addr+3, j+2);
          sqlite3VdbeChangeP2(v, addr+3, addr+2);
          sqlite3VdbeJumpHere(v, addr+6);
          sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
        }
      } 
    }
    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
    sqlite3VdbeJumpHere(v, addr+2);
  }else
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */

#ifndef SQLITE_OMIT_UTF16
  /*
  **   PRAGMA encoding
  **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
................................................................................
    sqlite3VdbeSetNumCols(v, 2);
    sqlite3VdbeSetColName(v, 0, "database", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, "status", P3_STATIC);
    for(i=0; i<db->nDb; i++){
      Btree *pBt;
      Pager *pPager;
      if( db->aDb[i].zName==0 ) continue;
      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
      pBt = db->aDb[i].pBt;
      if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
        sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
      }else{
        int j = sqlite3pager_lockstate(pPager);
        sqlite3VdbeOp3(v, OP_String8, 0, 0, 
            (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
      }
      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
    }
  }else
#endif

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

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
454
455
456
457
458
459
460






461
462
463
464
465
466

467
468
469
470
471
472
473
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.4 2005/09/01 06:07:56 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** Fill the InitData structure with an error message that indicates
................................................................................
    sqlite3ResetInternalSchema(db, 0);
  }
  if( pzTail ) *pzTail = sParse.zTail;
  rc = sParse.rc;

#ifndef SQLITE_OMIT_EXPLAIN
  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){






    sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
    sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
    sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
    sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
    sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
    sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);

  } 
#endif

prepare_out:
  if( sqlite3SafetyOff(db) ){
    rc = SQLITE_MISUSE;
  }







|







 







>
>
>
>
>
>
|
|
|
|
|
|
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.5 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** Fill the InitData structure with an error message that indicates
................................................................................
    sqlite3ResetInternalSchema(db, 0);
  }
  if( pzTail ) *pzTail = sParse.zTail;
  rc = sParse.rc;

#ifndef SQLITE_OMIT_EXPLAIN
  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
    if( sParse.explain==2 ){
      sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
      sqlite3VdbeSetColName(sParse.pVdbe, 0, "order", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 1, "from", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 2, "detail", P3_STATIC);
    }else{
      sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
      sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);
    }
  } 
#endif

prepare_out:
  if( sqlite3SafetyOff(db) ){
    rc = SQLITE_MISUSE;
  }

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

159
160
161
162
163
164
165








166
167
168
169
170
171
172
173
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
...
714
715
716
717
718
719
720

721



722
723
724
725
726
727
728
...
752
753
754
755
756
757
758
759



760
761
762
763
764
765
766
...
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
  d = digit;
  digit += '0';
  *val = (*val - d)*10.0;
  return digit;
}
#endif









#define etBUFSIZE 1000  /* Size of the output buffer */

/*
** The root program.  All variations call this core.
**
** INPUTS:
**   func   This is a pointer to a function taking three arguments
**            1. A pointer to anything.  Same as the "arg" parameter.
................................................................................
        /* It makes more sense to use 0.5 */
        for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
#endif
        if( xtype==etFLOAT ) realvalue += rounder;
        /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
        exp = 0;
        if( realvalue>0.0 ){
          while( realvalue>1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
          while( realvalue>1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
          while( realvalue>10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
          while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
          while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
          if( exp>350 || exp<-350 ){
            bufpt = "NaN";
            length = 3;
            break;
          }
................................................................................
      pM->nAlloc = pM->nChar + nNewChar*2 + 1;
      if( pM->zText==pM->zBase ){
        pM->zText = pM->xRealloc(0, pM->nAlloc);
        if( pM->zText && pM->nChar ){
          memcpy(pM->zText, pM->zBase, pM->nChar);
        }
      }else{

        pM->zText = pM->xRealloc(pM->zText, pM->nAlloc);



      }
    }
  }
  if( pM->zText ){
    if( nNewChar>0 ){
      memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
      pM->nChar += nNewChar;
................................................................................
  if( xRealloc ){
    if( sM.zText==sM.zBase ){
      sM.zText = xRealloc(0, sM.nChar+1);
      if( sM.zText ){
        memcpy(sM.zText, sM.zBase, sM.nChar+1);
      }
    }else if( sM.nAlloc>sM.nChar+10 ){
      sM.zText = xRealloc(sM.zText, sM.nChar+1);



    }
  }
  return sM.zText;
}

/*
** Realloc that is a real function, not a macro.
................................................................................
}

/*
** Print into memory obtained from sqliteMalloc().  Use the internal
** %-conversion extensions.
*/
char *sqlite3VMPrintf(const char *zFormat, va_list ap){
  char zBase[1000];
  return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
}

/*
** Print into memory obtained from sqliteMalloc().  Use the internal
** %-conversion extensions.
*/
char *sqlite3MPrintf(const char *zFormat, ...){
  va_list ap;
  char *z;
  char zBase[1000];
  va_start(ap, zFormat);
  z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
  va_end(ap);
  return z;
}

/*







>
>
>
>
>
>
>
>
|







 







|
|
|







 







>
|
>
>
>







 







|
>
>
>







 







|










|







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
...
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
...
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
...
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
  d = digit;
  digit += '0';
  *val = (*val - d)*10.0;
  return digit;
}
#endif

/*
** On machines with a small stack size, you can redefine the
** SQLITE_PRINT_BUF_SIZE to be less than 350.  But beware - for
** smaller values some %f conversions may go into an infinite loop.
*/
#ifndef SQLITE_PRINT_BUF_SIZE
# define SQLITE_PRINT_BUF_SIZE 350
#endif
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE  /* Size of the output buffer */

/*
** The root program.  All variations call this core.
**
** INPUTS:
**   func   This is a pointer to a function taking three arguments
**            1. A pointer to anything.  Same as the "arg" parameter.
................................................................................
        /* It makes more sense to use 0.5 */
        for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
#endif
        if( xtype==etFLOAT ) realvalue += rounder;
        /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
        exp = 0;
        if( realvalue>0.0 ){
          while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
          while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
          while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
          while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
          while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
          if( exp>350 || exp<-350 ){
            bufpt = "NaN";
            length = 3;
            break;
          }
................................................................................
      pM->nAlloc = pM->nChar + nNewChar*2 + 1;
      if( pM->zText==pM->zBase ){
        pM->zText = pM->xRealloc(0, pM->nAlloc);
        if( pM->zText && pM->nChar ){
          memcpy(pM->zText, pM->zBase, pM->nChar);
        }
      }else{
        char *zNew;
        zNew = pM->xRealloc(pM->zText, pM->nAlloc);
        if( zNew ){
          pM->zText = zNew;
        }
      }
    }
  }
  if( pM->zText ){
    if( nNewChar>0 ){
      memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
      pM->nChar += nNewChar;
................................................................................
  if( xRealloc ){
    if( sM.zText==sM.zBase ){
      sM.zText = xRealloc(0, sM.nChar+1);
      if( sM.zText ){
        memcpy(sM.zText, sM.zBase, sM.nChar+1);
      }
    }else if( sM.nAlloc>sM.nChar+10 ){
      char *zNew = xRealloc(sM.zText, sM.nChar+1);
      if( zNew ){
        sM.zText = zNew;
      }
    }
  }
  return sM.zText;
}

/*
** Realloc that is a real function, not a macro.
................................................................................
}

/*
** Print into memory obtained from sqliteMalloc().  Use the internal
** %-conversion extensions.
*/
char *sqlite3VMPrintf(const char *zFormat, va_list ap){
  char zBase[SQLITE_PRINT_BUF_SIZE];
  return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
}

/*
** Print into memory obtained from sqliteMalloc().  Use the internal
** %-conversion extensions.
*/
char *sqlite3MPrintf(const char *zFormat, ...){
  va_list ap;
  char *z;
  char zBase[SQLITE_PRINT_BUF_SIZE];
  va_start(ap, zFormat);
  z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
  va_end(ap);
  return z;
}

/*

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

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************************************************************
** This file contains code to implement a pseudo-random number
** generator (PRNG) for SQLite.
**
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
** $Id: random.c,v 1.8 2005/09/01 06:07:56 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"


/*
** Get a single 8-bit random value from the RC4 PRNG.  The Mutex







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************************************************************
** This file contains code to implement a pseudo-random number
** generator (PRNG) for SQLite.
**
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
**
** $Id: random.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"


/*
** Get a single 8-bit random value from the RC4 PRNG.  The Mutex

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
56
57
58
59
60
61
62



63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
171
172
173
174
175
176
177

178
179
180
181
182
183
184
...
191
192
193
194
195
196
197

198
199
200
201
202


203
204
205
206
207
208
209














210
211
212
213

214
215
216
217
218
219
220
221
...
254
255
256
257
258
259
260
261


262
263
264
265
266
267
268
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
...
293
294
295
296
297
298
299
300

301
302
303
304
305
306
307
...
323
324
325
326
327
328
329


330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359




























360
361
362
363
364
365
366
...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

437
438

439

440
441
442
443
444
445
446
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
...
480
481
482
483
484
485
486




487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
...
542
543
544
545
546
547
548










































549
550
551
552
553
554
555
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601
602
...
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
...
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
....
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325

1326






1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350



1351
1352
1353
1354
1355







1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
....
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429



1430
1431
1432
1433
1434
1435
1436
1437
1438


1439
1440
1441
1442
1443
1444
1445
....
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1482

1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
....
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540

1541
1542
1543
1544
1545
1546
1547
....
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
....
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
....
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622

1623
1624
1625
1626
1627
1628
1629
1630

1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
....
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
....
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723



1724
1725

1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744







1745
1746
1747

1748
1749








1750
1751
1752
1753
1754
1755
1756
1757
1758
1759

1760







1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
....
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
....
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
....
2282
2283
2284
2285
2286
2287
2288

2289
2290
2291
2292
2293
2294
2295
....
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
....
2351
2352
2353
2354
2355
2356
2357

2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
....
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387














2388
2389
2390
2391
2392
2393
2394
2395





2396
2397


2398
2399
2400
2401



2402




















2403
2404
2405
2406


2407
2408

2409
2410
2411
2412







2413
2414
2415
2416
2417
2418
2419

2420
2421
2422
2423
2424










2425






























2426
2427
2428
2429
2430
2431
2432
....
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501

2502
2503
2504

2505
2506
2507
2508
2509






2510
2511
2512
2513
2514
2515
2516

2517
2518
2519
2520
2521
2522
2523
....
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
....
2576
2577
2578
2579
2580
2581
2582

2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
....
2621
2622
2623
2624
2625
2626
2627
2628






2629
2630


2631
2632
2633

2634
2635
2636
2637
2638
2639







2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725

2726
2727
2728
2729
2730
2731

2732
2733



2734
2735
2736
2737



2738
2739
2740
2741
2742
2743









2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755

2756

2757
2758
2759
2760























































2761















2762
2763
2764





























2765
2766


2767



2768
2769
2770
2771






2772

2773
2774
2775
2776





2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788























2789












2790
2791
2792
2793













2794
2795





2796
2797
2798

2799
2800



2801





2802

2803
2804









2805
























2806

2807
2808
2809


2810
2811
2812
2813
2814















2815
2816
2817
2818
2819
2820

2821
2822
2823
2824
2825

2826
2827
2828
2829
2830
2831
2832
....
2850
2851
2852
2853
2854
2855
2856
2857

2858
2859
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.8 2005/09/01 06:07:56 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "../interop.h"

/*
** Allocate a new Select structure and return a pointer to that
** structure.
................................................................................
    pNew->pOrderBy = pOrderBy;
    pNew->isDistinct = isDistinct;
    pNew->op = TK_SELECT;
    pNew->pLimit = pLimit;
    pNew->pOffset = pOffset;
    pNew->iLimit = -1;
    pNew->iOffset = -1;



  }
  return pNew;
}

/*
** Given 1 to 3 identifiers preceeding the JOIN keyword, determine the
** type of join.  Return an integer constant that expresses that type
** in terms of the following bit values:
**
**     JT_INNER

**     JT_OUTER
**     JT_NATURAL
**     JT_LEFT
**     JT_RIGHT
**
** A full outer join is the combination of JT_LEFT and JT_RIGHT.
**
................................................................................
  } keywords[] = {
    { "natural", 7, JT_NATURAL },
    { "left",    4, JT_LEFT|JT_OUTER },
    { "right",   5, JT_RIGHT|JT_OUTER },
    { "full",    4, JT_LEFT|JT_RIGHT|JT_OUTER },
    { "outer",   5, JT_OUTER },
    { "inner",   5, JT_INNER },
    { "cross",   5, JT_INNER },
  };
  int i, j;
  apAll[0] = pA;
  apAll[1] = pB;
  apAll[2] = pC;
  for(i=0; i<3 && apAll[i]; i++){
    p = apAll[i];
................................................................................
*/
static void addWhereTerm(
  const char *zCol,        /* Name of the column */
  const Table *pTab1,      /* First table */
  const char *zAlias1,     /* Alias for first table.  May be NULL */
  const Table *pTab2,      /* Second table */
  const char *zAlias2,     /* Alias for second table.  May be NULL */

  Expr **ppExpr            /* Add the equality term to this expression */
){
  Expr *pE1a, *pE1b, *pE1c;
  Expr *pE2a, *pE2b, *pE2c;
  Expr *pE;

  pE1a = createIdExpr(zCol);
................................................................................
    zAlias2 = pTab2->zName;
  }
  pE2b = createIdExpr(zAlias2);
  pE1c = sqlite3Expr(TK_DOT, pE1b, pE1a, 0);
  pE2c = sqlite3Expr(TK_DOT, pE2b, pE2a, 0);
  pE = sqlite3Expr(TK_EQ, pE1c, pE2c, 0);
  ExprSetProperty(pE, EP_FromJoin);

  *ppExpr = sqlite3ExprAnd(*ppExpr, pE);
}

/*
** Set the EP_FromJoin property on all terms of the given expression.


**
** The EP_FromJoin property is used on terms of an expression to tell
** the LEFT OUTER JOIN processing logic that this term is part of the
** join restriction specified in the ON or USING clause and not a part
** of the more general WHERE clause.  These terms are moved over to the
** WHERE clause during join processing but we need to remember that they
** originated in the ON or USING clause.














*/
static void setJoinExpr(Expr *p){
  while( p ){
    ExprSetProperty(p, EP_FromJoin);

    setJoinExpr(p->pLeft);
    p = p->pRight;
  } 
}

/*
** This routine processes the join information for a SELECT statement.
** ON and USING clauses are converted into extra terms of the WHERE clause.
................................................................................
           "an ON or USING clause", 0);
        return 1;
      }
      for(j=0; j<pLeftTab->nCol; j++){
        char *zName = pLeftTab->aCol[j].zName;
        if( columnIndex(pRightTab, zName)>=0 ){
          addWhereTerm(zName, pLeftTab, pLeft->zAlias, 
                              pRightTab, pRight->zAlias, &p->pWhere);


        }
      }
    }

    /* Disallow both ON and USING clauses in the same join
    */
    if( pLeft->pOn && pLeft->pUsing ){
................................................................................
      return 1;
    }

    /* Add the ON clause to the end of the WHERE clause, connected by
    ** an AND operator.
    */
    if( pLeft->pOn ){
      setJoinExpr(pLeft->pOn);
      p->pWhere = sqlite3ExprAnd(p->pWhere, pLeft->pOn);
      pLeft->pOn = 0;
    }

    /* Create extra terms on the WHERE clause for each column named
    ** in the USING clause.  Example: If the two tables to be joined are 
    ** A and B and the USING clause names X, Y, and Z, then add this
................................................................................
        char *zName = pList->a[j].zName;
        if( columnIndex(pLeftTab, zName)<0 || columnIndex(pRightTab, zName)<0 ){
          sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
            "not present in both tables", zName);
          return 1;
        }
        addWhereTerm(zName, pLeftTab, pLeft->zAlias, 
                            pRightTab, pRight->zAlias, &p->pWhere);

      }
    }
  }
  return 0;
}

/*
................................................................................

/*
** Insert code into "v" that will push the record on the top of the
** stack into the sorter.
*/
static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){
  sqlite3ExprCodeExprList(pParse, pOrderBy);


  sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr, 0);
  sqlite3VdbeAddOp(v, OP_SortInsert, 0, 0);
}

/*
** Add code to implement the OFFSET and LIMIT
*/
static void codeLimiter(
  Vdbe *v,          /* Generate code into this VM */
  Select *p,        /* The SELECT statement being coded */
  int iContinue,    /* Jump here to skip the current record */
  int iBreak,       /* Jump here to end the loop */
  int nPop          /* Number of times to pop stack when jumping */
){
  if( p->iOffset>=0 ){
    int addr = sqlite3VdbeCurrentAddr(v) + 3;
    if( nPop>0 ) addr++;
    sqlite3VdbeAddOp(v, OP_MemIncr, p->iOffset, 0);
    sqlite3VdbeAddOp(v, OP_IfMemPos, p->iOffset, addr);
    if( nPop>0 ){
      sqlite3VdbeAddOp(v, OP_Pop, nPop, 0);
    }
    sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue);
    VdbeComment((v, "# skip OFFSET records"));
  }
  if( p->iLimit>=0 ){
    sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, iBreak);
    VdbeComment((v, "# exit when LIMIT reached"));
  }
}





























/*
** This routine generates the code for the inside of the inner loop
** of a SELECT.
**
** If srcTab and nColumn are both zero, then the pEList expressions
** are evaluated in order to get the data for this row.  If nColumn>0
................................................................................

  /* If the DISTINCT keyword was present on the SELECT statement
  ** and this row has been seen before, then do not make this row
  ** part of the result.
  */
  if( hasDistinct ){
    int n = pEList->nExpr;
#if NULL_ALWAYS_DISTINCT
    sqlite3VdbeAddOp(v, OP_IsNull, -pEList->nExpr, sqlite3VdbeCurrentAddr(v)+7);
#endif
    /* Deliberately leave the affinity string off of the following
    ** OP_MakeRecord */
    sqlite3VdbeAddOp(v, OP_MakeRecord, -n, 0);
    sqlite3VdbeAddOp(v, OP_Distinct, distinct, sqlite3VdbeCurrentAddr(v)+3);
    sqlite3VdbeAddOp(v, OP_Pop, n+1, 0);
    sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue);
    VdbeComment((v, "# skip indistinct records"));
    sqlite3VdbeAddOp(v, OP_IdxInsert, distinct, 0);
    if( pOrderBy==0 ){
      codeLimiter(v, p, iContinue, iBreak, nColumn);
    }
  }

  switch( eDest ){
#ifndef SQLITE_OMIT_COMPOUND_SELECT
    /* In this mode, write each query result to the key of the temporary
    ** table iParm.
    */

    case SRT_Union: {
      sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, NULL_ALWAYS_DISTINCT);

      sqlite3VdbeChangeP3(v, -1, aff, P3_STATIC);

      sqlite3VdbeAddOp(v, OP_IdxInsert, iParm, 0);
      break;
    }

    /* Construct a record from the query result, but instead of
    ** saving that record, use it as a key to delete elements from
    ** the temporary table iParm.
................................................................................
      break;
    }
#endif

    /* Store the result as data using a unique key.
    */
    case SRT_Table:
    case SRT_TempTable: {
      sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
      if( pOrderBy ){
        pushOntoSorter(pParse, v, pOrderBy);
      }else{
        sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
        sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
        sqlite3VdbeAddOp(v, OP_Insert, iParm, 0);
................................................................................
      int addr2;

      assert( nColumn==1 );
      sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3);
      sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
      addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
      if( pOrderBy ){




        pushOntoSorter(pParse, v, pOrderBy);
      }else{
        char aff = (iParm>>16)&0xFF;
        aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff);
        sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1);
        sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
      }
      sqlite3VdbeChangeP2(v, addr2, sqlite3VdbeCurrentAddr(v));
      break;
    }

    /* If this is a scalar select that is part of an expression, then
    ** store the results in the appropriate memory cell and break out
    ** of the scan loop.
    */
................................................................................
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */

    /* Send the data to the callback function or to a subroutine.  In the
    ** case of a subroutine, the subroutine itself is responsible for
    ** popping the data from the stack.
    */
    case SRT_Subroutine:
    case SRT_Callback:
    case SRT_Sorter: {
      if( pOrderBy ){
        sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
        pushOntoSorter(pParse, v, pOrderBy);
      }else if( eDest==SRT_Subroutine ){
        sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
      }else{
        assert( eDest!=SRT_Sorter );
        sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0);
      }
      break;
    }

#if !defined(SQLITE_OMIT_TRIGGER)
    /* Discard the results.  This is used for SELECT statements inside
................................................................................
      sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0);
      break;
    }
#endif
  }
  return 0;
}











































/*
** If the inner loop was generated using a non-null pOrderBy argument,
** then the results were placed in a sorter.  After the loop is terminated
** we need to run the sorter and output the results.  The following
** routine generates the code needed to do that.
*/
................................................................................
  Parse *pParse,   /* The parsing context */
  Select *p,       /* The SELECT statement */
  Vdbe *v,         /* Generate code into this VDBE */
  int nColumn,     /* Number of columns of data */
  int eDest,       /* Write the sorted results here */
  int iParm        /* Optional parameter associated with eDest */
){
  int end1 = sqlite3VdbeMakeLabel(v);
  int end2 = sqlite3VdbeMakeLabel(v);
  int addr;
  KeyInfo *pInfo;
  ExprList *pOrderBy;
  int nCol, i;
  sqlite3 *db = pParse->db;

  if( eDest==SRT_Sorter ) return;
  pOrderBy = p->pOrderBy;
  nCol = pOrderBy->nExpr;
  pInfo = sqliteMalloc( sizeof(*pInfo) + nCol*(sizeof(CollSeq*)+1) );
  if( pInfo==0 ) return;
  pInfo->aSortOrder = (char*)&pInfo->aColl[nCol];
  pInfo->nField = nCol;
  for(i=0; i<nCol; i++){
    /* If a collation sequence was specified explicity, then it
    ** is stored in pOrderBy->a[i].zName. Otherwise, use the default
    ** collation type for the expression.
    */
    pInfo->aColl[i] = sqlite3ExprCollSeq(pParse, pOrderBy->a[i].pExpr);
    if( !pInfo->aColl[i] ){
      pInfo->aColl[i] = db->pDfltColl;
    }
    pInfo->aSortOrder[i] = pOrderBy->a[i].sortOrder;
  }
  sqlite3VdbeOp3(v, OP_Sort, 0, 0, (char*)pInfo, P3_KEYINFO_HANDOFF);
  addr = sqlite3VdbeAddOp(v, OP_SortNext, 0, end1);
  codeLimiter(v, p, addr, end2, 1);

  switch( eDest ){
    case SRT_Table:
    case SRT_TempTable: {
      sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
      sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
      sqlite3VdbeAddOp(v, OP_Insert, iParm, 0);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case SRT_Set: {
................................................................................
      sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
      break;
    }
    case SRT_Exists:
    case SRT_Mem: {
      assert( nColumn==1 );
      sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1);
      sqlite3VdbeAddOp(v, OP_Goto, 0, end1);
      break;
    }
#endif
    case SRT_Callback:
    case SRT_Subroutine: {
      int i;
      sqlite3VdbeAddOp(v, OP_Integer, p->pEList->nExpr, 0);
................................................................................
      break;
    }
    default: {
      /* Do nothing */
      break;
    }
  }
  sqlite3VdbeAddOp(v, OP_Goto, 0, addr);
  sqlite3VdbeResolveLabel(v, end2);
  sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
  sqlite3VdbeResolveLabel(v, end1);
  sqlite3VdbeAddOp(v, OP_SortReset, 0, 0);
}

/*
** Return a pointer to a string containing the 'declaration type' of the
** expression pExpr. The string may be treated as static by the caller.
**
** If the declaration type is the exact datatype definition extracted from
................................................................................
    sqlite3VdbeAddOp(v, OP_MemStore, iMem, 1);
    VdbeComment((v, "# OFFSET counter"));
    p->iOffset = iMem;
  }
}

/*
** Generate VDBE instructions that will open a transient table that
** will be used for an index or to store keyed results for a compound
** select.  In other words, open a transient table that needs a
** KeyInfo structure.  The number of columns in the KeyInfo is determined
** by the result set of the SELECT statement in the second argument.
**
** Specifically, this routine is called to open an index table for
** DISTINCT, UNION, INTERSECT and EXCEPT select statements (but not 
** UNION ALL).
**
** The value returned is the address of the OP_OpenVirtual instruction.
*/
static int openVirtualIndex(Parse *pParse, Select *p, int iTab){
  KeyInfo *pKeyInfo;
  int nColumn;
  sqlite3 *db = pParse->db;
  int i;
  Vdbe *v = pParse->pVdbe;

  int addr;







  if( prepSelectStmt(pParse, p) ){
    return 0;
  }
  nColumn = p->pEList->nExpr;
  pKeyInfo = sqliteMalloc( sizeof(*pKeyInfo)+nColumn*sizeof(CollSeq*) );
  if( pKeyInfo==0 ) return 0;
  pKeyInfo->enc = db->enc;
  pKeyInfo->nField = nColumn;
  for(i=0; i<nColumn; i++){
    pKeyInfo->aColl[i] = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
    if( !pKeyInfo->aColl[i] ){
      pKeyInfo->aColl[i] = db->pDfltColl;
    }
  }
  addr = sqlite3VdbeOp3(v, OP_OpenVirtual, iTab, 0, 
      (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
  return addr;
}

#ifndef SQLITE_OMIT_COMPOUND_SELECT
/*
** Add the address "addr" to the set of all OpenVirtual opcode addresses
** that are being accumulated in p->ppOpenVirtual.



*/
static int multiSelectOpenVirtualAddr(Select *p, int addr){
  IdList *pList = *p->ppOpenVirtual = sqlite3IdListAppend(*p->ppOpenVirtual, 0);
  if( pList==0 ){
    return SQLITE_NOMEM;







  }
  pList->a[pList->nId-1].idx = addr;
  return SQLITE_OK;
}
#endif /* SQLITE_OMIT_COMPOUND_SELECT */

#ifndef SQLITE_OMIT_COMPOUND_SELECT
/*
** Return the appropriate collating sequence for the iCol-th column of
** the result set for the compound-select statement "p".  Return NULL if
** the column has no default collating sequence.
**
** The collating sequence for the compound select is taken from the
................................................................................
  int eDest,            /* \___  Store query results as specified */
  int iParm,            /* /     by these two parameters.         */
  char *aff             /* If eDest is SRT_Union, the affinity string */
){
  int rc = SQLITE_OK;   /* Success code from a subroutine */
  Select *pPrior;       /* Another SELECT immediately to our left */
  Vdbe *v;              /* Generate code to this VDBE */
  IdList *pOpenVirtual = 0;/* OP_OpenVirtual opcodes that need a KeyInfo */
  int aAddr[5];         /* Addresses of SetNumColumns operators */
  int nAddr = 0;        /* Number used */
  int nCol;             /* Number of columns in the result set */




  /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs.  Only
  ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
  */
  if( p==0 || p->pPrior==0 ){
    rc = 1;
    goto multi_select_end;
  }
  pPrior = p->pPrior;


  if( pPrior->pOrderBy ){
    sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
      selectOpName(p->op));
    rc = 1;
    goto multi_select_end;
  }
  if( pPrior->pLimit ){
................................................................................
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    rc = 1;
    goto multi_select_end;
  }

  /* If *p this is the right-most select statement, then initialize
  ** p->ppOpenVirtual to point to pOpenVirtual.  If *p is not the right most
  ** statement then p->ppOpenVirtual will have already been initialized
  ** by a prior call to this same procedure.  Pass along the pOpenVirtual
  ** pointer to pPrior, the next statement to our left.
  */
  if( p->ppOpenVirtual==0 ){
    p->ppOpenVirtual = &pOpenVirtual;
  }
  pPrior->ppOpenVirtual = p->ppOpenVirtual;

  /* Create the destination temporary table if necessary
  */
  if( eDest==SRT_TempTable ){
    assert( p->pEList );

    sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0);
    assert( nAddr==0 );
    aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 0);
    eDest = SRT_Table;
  }

  /* Generate code for the left and right SELECT statements.
  */

  switch( p->op ){
    case TK_ALL: {
      if( p->pOrderBy==0 ){
        assert( !pPrior->pLimit );
        pPrior->pLimit = p->pLimit;
        pPrior->pOffset = p->pOffset;
        rc = sqlite3Select(pParse, pPrior, eDest, iParm, 0, 0, 0, aff);
        if( rc ){
          goto multi_select_end;
        }
................................................................................
    }
    case TK_EXCEPT:
    case TK_UNION: {
      int unionTab;    /* Cursor number of the temporary table holding result */
      int op = 0;      /* One of the SRT_ operations to apply to self */
      int priorOp;     /* The SRT_ operation to apply to prior selects */
      Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */
      ExprList *pOrderBy;     /* The ORDER BY clause for the right SELECT */
      int addr;

      priorOp = p->op==TK_ALL ? SRT_Table : SRT_Union;
      if( eDest==priorOp && p->pOrderBy==0 && !p->pLimit && !p->pOffset ){
        /* We can reuse a temporary table generated by a SELECT to our
        ** right.
        */
        unionTab = iParm;
      }else{
        /* We will need to create our own temporary table to hold the
        ** intermediate results.
        */
        unionTab = pParse->nTab++;
        if( p->pOrderBy 
        && matchOrderbyToColumn(pParse, p, p->pOrderBy, unionTab, 1) ){
          rc = 1;
          goto multi_select_end;
        }
        addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, unionTab, 0);
        if( p->op!=TK_ALL ){
          rc = multiSelectOpenVirtualAddr(p, addr);
          if( rc!=SQLITE_OK ){
            goto multi_select_end;
          }
        }
	assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) );
        aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, unionTab, 0);

        assert( p->pEList );
      }

      /* Code the SELECT statements to our left
      */
      assert( !pPrior->pOrderBy );
      rc = sqlite3Select(pParse, pPrior, priorOp, unionTab, 0, 0, 0, aff);
................................................................................
      */
      switch( p->op ){
         case TK_EXCEPT:  op = SRT_Except;   break;
         case TK_UNION:   op = SRT_Union;    break;
         case TK_ALL:     op = SRT_Table;    break;
      }
      p->pPrior = 0;
      pOrderBy = p->pOrderBy;
      p->pOrderBy = 0;

      pLimit = p->pLimit;
      p->pLimit = 0;
      pOffset = p->pOffset;
      p->pOffset = 0;
      rc = sqlite3Select(pParse, p, op, unionTab, 0, 0, 0, aff);
      p->pPrior = pPrior;
      p->pOrderBy = pOrderBy;
................................................................................
        }
        iBreak = sqlite3VdbeMakeLabel(v);
        iCont = sqlite3VdbeMakeLabel(v);
        sqlite3VdbeAddOp(v, OP_Rewind, unionTab, iBreak);
        computeLimitRegisters(pParse, p);
        iStart = sqlite3VdbeCurrentAddr(v);
        rc = selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr,
                             p->pOrderBy, -1, eDest, iParm, 
                             iCont, iBreak, 0);
        if( rc ){
          rc = 1;
          goto multi_select_end;
        }
        sqlite3VdbeResolveLabel(v, iCont);
        sqlite3VdbeAddOp(v, OP_Next, unionTab, iStart);
................................................................................

      /* INTERSECT is different from the others since it requires
      ** two temporary tables.  Hence it has its own case.  Begin
      ** by allocating the tables we will need.
      */
      tab1 = pParse->nTab++;
      tab2 = pParse->nTab++;
      if( p->pOrderBy && matchOrderbyToColumn(pParse,p,p->pOrderBy,tab1,1) ){
        rc = 1;
        goto multi_select_end;
      }


      addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab1, 0);
      rc = multiSelectOpenVirtualAddr(p, addr);
      if( rc!=SQLITE_OK ){
        goto multi_select_end;
      }
      assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) );
      aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, tab1, 0);

      assert( p->pEList );

      /* Code the SELECTs to our left into temporary table "tab1".
      */
      rc = sqlite3Select(pParse, pPrior, SRT_Union, tab1, 0, 0, 0, aff);
      if( rc ){
        goto multi_select_end;
      }

      /* Code the current SELECT into temporary table "tab2"
      */
      addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab2, 0);
      rc = multiSelectOpenVirtualAddr(p, addr);
      if( rc!=SQLITE_OK ){
        goto multi_select_end;
      }
      assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) );
      aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, tab2, 0);
      p->pPrior = 0;
      pLimit = p->pLimit;
      p->pLimit = 0;
      pOffset = p->pOffset;
      p->pOffset = 0;
      rc = sqlite3Select(pParse, p, SRT_Union, tab2, 0, 0, 0, aff);
      p->pPrior = pPrior;
................................................................................
      iBreak = sqlite3VdbeMakeLabel(v);
      iCont = sqlite3VdbeMakeLabel(v);
      sqlite3VdbeAddOp(v, OP_Rewind, tab1, iBreak);
      computeLimitRegisters(pParse, p);
      iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0);
      sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont);
      rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr,
                             p->pOrderBy, -1, eDest, iParm, 
                             iCont, iBreak, 0);
      if( rc ){
        rc = 1;
        goto multi_select_end;
      }
      sqlite3VdbeResolveLabel(v, iCont);
      sqlite3VdbeAddOp(v, OP_Next, tab1, iStart);
................................................................................
    rc = 1;
    goto multi_select_end;
  }

  /* Set the number of columns in temporary tables
  */
  nCol = p->pEList->nExpr;
  while( nAddr>0 ){
    nAddr--;
    sqlite3VdbeChangeP2(v, aAddr[nAddr], nCol);
  }

  /* Compute collating sequences used by either the ORDER BY clause or
  ** by any temporary tables needed to implement the compound select.
  ** Attach the KeyInfo structure to all temporary tables.  Invoke the
  ** ORDER BY processing if there is an ORDER BY clause.
  **
  ** This section is run by the right-most SELECT statement only.
  ** SELECT statements to the left always skip this part.  The right-most
  ** SELECT might also skip this part if it has no ORDER BY clause and
  ** no temp tables are required.
  */
  if( p->pOrderBy || (pOpenVirtual && pOpenVirtual->nId>0) ){
    int i;                        /* Loop counter */
    KeyInfo *pKeyInfo;            /* Collating sequence for the result set */




    assert( p->ppOpenVirtual == &pOpenVirtual );

    pKeyInfo = sqliteMalloc(sizeof(*pKeyInfo)+nCol*sizeof(CollSeq*));
    if( !pKeyInfo ){
      rc = SQLITE_NOMEM;
      goto multi_select_end;
    }

    pKeyInfo->enc = pParse->db->enc;
    pKeyInfo->nField = nCol;

    for(i=0; i<nCol; i++){
      pKeyInfo->aColl[i] = multiSelectCollSeq(pParse, p, i);
      if( !pKeyInfo->aColl[i] ){
        pKeyInfo->aColl[i] = pParse->db->pDfltColl;
      }
    }

    for(i=0; pOpenVirtual && i<pOpenVirtual->nId; i++){
      int p3type = (i==0?P3_KEYINFO_HANDOFF:P3_KEYINFO);
      int addr = pOpenVirtual->a[i].idx;







      sqlite3VdbeChangeP3(v, addr, (char *)pKeyInfo, p3type);
    }


    if( p->pOrderBy ){
      struct ExprList_item *pOrderByTerm = p->pOrderBy->a;








      for(i=0; i<p->pOrderBy->nExpr; i++, pOrderByTerm++){
        Expr *pExpr = pOrderByTerm->pExpr;
        char *zName = pOrderByTerm->zName;
        assert( pExpr->op==TK_COLUMN && pExpr->iColumn<nCol );
        /* assert( !pExpr->pColl ); */
        if( zName ){
          pExpr->pColl = sqlite3LocateCollSeq(pParse, zName, -1);
        }else{
          pExpr->pColl = pKeyInfo->aColl[pExpr->iColumn];
        }

      }







      generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm);
    }

    if( !pOpenVirtual ){
      /* This happens for UNION ALL ... ORDER BY */
      sqliteFree(pKeyInfo);
    }
  }

multi_select_end:
  if( pOpenVirtual ){
    sqlite3IdListDelete(pOpenVirtual);
  }
  p->ppOpenVirtual = 0;
  return rc;
}
#endif /* SQLITE_OMIT_COMPOUND_SELECT */

#ifndef SQLITE_OMIT_VIEW
/*
** Scan through the expression pExpr.  Replace every reference to
................................................................................
  if( (pSub->pLimit && p->pLimit) || pSub->pOffset || 
      (pSub->pLimit && isAgg) ) return 0;
  if( pSubSrc->nSrc==0 ) return 0;
  if( pSub->isDistinct && (pSrc->nSrc>1 || isAgg) ){
     return 0;
  }
  if( p->isDistinct && subqueryIsAgg ) return 0;
  if( p->pOrderBy && pSub->pOrderBy ) return 0;

  /* Restriction 3:  If the subquery is a join, make sure the subquery is 
  ** not used as the right operand of an outer join.  Examples of why this
  ** is not allowed:
  **
  **         t1 LEFT OUTER JOIN (t2 JOIN t3)
  **
................................................................................
  ** The column names have already been generated in the calling function.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ) return 0;

  /* If the output is destined for a temporary table, open that table.
  */
  if( eDest==SRT_TempTable ){
    sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0);
    sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 1);
  }

  /* Generating code to find the min or the max.  Basically all we have
  ** to do is find the first or the last entry in the chosen index.  If
  ** the min() or max() is on the INTEGER PRIMARY KEY, then find the first
  ** or last entry in the main table.
  */
................................................................................
  Parse *pParse,         /* The parser context */
  Select *p,             /* The SELECT statement being coded. */
  NameContext *pOuterNC  /* The outer name context. May be NULL. */
){
  ExprList *pEList;          /* Result set. */
  int i;                     /* For-loop variable used in multiple places */
  NameContext sNC;           /* Local name-context */


  /* If this routine has run before, return immediately. */
  if( p->isResolved ){
    assert( !pOuterNC );
    return SQLITE_OK;
  }
  p->isResolved = 1;
................................................................................
  /* Set up the local name-context to pass to ExprResolveNames() to
  ** resolve the expression-list.
  */
  sNC.allowAgg = 1;
  sNC.pSrcList = p->pSrc;
  sNC.pNext = pOuterNC;

  /* NameContext.nDepth stores the depth of recursion for this query. For
  ** an outer query (e.g. SELECT * FROM sqlite_master) this is 1. For
  ** a subquery it is 2. For a subquery of a subquery, 3. And so on. 
  ** Parse.nMaxDepth is the maximum depth for any subquery resolved so
  ** far. This is used to determine the number of aggregate contexts
  ** required at runtime.
  */
  sNC.nDepth = (pOuterNC?pOuterNC->nDepth+1:1);
  if( sNC.nDepth>pParse->nMaxDepth ){
    pParse->nMaxDepth = sNC.nDepth;
  }

  /* Resolve names in the result set. */
  pEList = p->pEList;
  if( !pEList ) return SQLITE_ERROR;
  for(i=0; i<pEList->nExpr; i++){
    Expr *pX = pEList->a[i].pExpr;
    if( sqlite3ExprResolveNames(&sNC, pX) ){
      return SQLITE_ERROR;
................................................................................
    }
  }

  /* If there are no aggregate functions in the result-set, and no GROUP BY 
  ** expression, do not allow aggregates in any of the other expressions.
  */
  assert( !p->isAgg );

  if( p->pGroupBy || sNC.hasAgg ){
    p->isAgg = 1;
  }else{
    sNC.allowAgg = 0;
  }

  /* If a HAVING clause is present, then there must be a GROUP BY clause.
  */
  if( p->pHaving && !p->pGroupBy ){
    sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
    return SQLITE_ERROR;
  }

  /* Add the expression list to the name-context before parsing the
  ** other expressions in the SELECT statement. This is so that
  ** expressions in the WHERE clause (etc.) can refer to expressions by
................................................................................
  ** Minor point: If this is the case, then the expression will be
  ** re-evaluated for each reference to it.
  */
  sNC.pEList = p->pEList;
  if( sqlite3ExprResolveNames(&sNC, p->pWhere) ||
      sqlite3ExprResolveNames(&sNC, p->pHaving) ||
      processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") ||
      processOrderGroupBy(&sNC, p->pGroupBy, "GROUP")
  ){
    return SQLITE_ERROR;
  }















  return SQLITE_OK;
}

/*
** An instance of the following struct is used by sqlite3Select()
** to save aggregate related information from the Parse object
** at the start of each call and to restore it at the end. See
** saveAggregateInfo() and restoreAggregateInfo().





*/ 
struct AggregateInfo {


  int nAgg;
  AggExpr *aAgg;
};
typedef struct AggregateInfo AggregateInfo;
























/* 
** Copy aggregate related information from the Parse structure
** into the AggregateInfo structure. Zero the aggregate related
** values in the Parse struct.


*/
static void saveAggregateInfo(Parse *pParse, AggregateInfo *pInfo){

  pInfo->aAgg = pParse->aAgg;
  pInfo->nAgg = pParse->nAgg;
  pParse->aAgg = 0;
  pParse->nAgg = 0;







}

/*
** Copy aggregate related information from the AggregateInfo struct
** back into the Parse structure. The aggregate related information
** currently stored in the Parse structure is deleted.
*/

static void restoreAggregateInfo(Parse *pParse, AggregateInfo *pInfo){
  sqliteFree(pParse->aAgg);
  pParse->aAgg = pInfo->aAgg;
  pParse->nAgg = pInfo->nAgg;
}










  






























/*
** Generate code for the given SELECT statement.
**
** The results are distributed in various ways depending on the
** value of eDest and iParm.
**
**     eDest Value       Result
................................................................................
  int eDest,             /* How to dispose of the results */
  int iParm,             /* A parameter used by the eDest disposal method */
  Select *pParent,       /* Another SELECT for which this is a sub-query */
  int parentTab,         /* Index in pParent->pSrc of this query */
  int *pParentAgg,       /* True if pParent uses aggregate functions */
  char *aff              /* If eDest is SRT_Union, the affinity string */
){
  int i;
  WhereInfo *pWInfo;
  Vdbe *v;
  int isAgg;             /* True for select lists like "count(*)" */
  ExprList *pEList;      /* List of columns to extract. */
  SrcList *pTabList;     /* List of tables to select from */
  Expr *pWhere;          /* The WHERE clause.  May be NULL */
  ExprList *pOrderBy;    /* The ORDER BY clause.  May be NULL */
  ExprList *pGroupBy;    /* The GROUP BY clause.  May be NULL */
  Expr *pHaving;         /* The HAVING clause.  May be NULL */
  int isDistinct;        /* True if the DISTINCT keyword is present */
  int distinct;          /* Table to use for the distinct set */
  int rc = 1;            /* Value to return from this function */
  AggregateInfo sAggInfo;


  if( sqlite3_malloc_failed || pParse->nErr || p==0 ) return 1;
  if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;


#ifndef SQLITE_OMIT_COMPOUND_SELECT
  /* If there is are a sequence of queries, do the earlier ones first.
  */
  if( p->pPrior ){






    return multiSelect(pParse, p, eDest, iParm, aff);
  }
#endif

  saveAggregateInfo(pParse, &sAggInfo);
  pOrderBy = p->pOrderBy;
  if( eDest==SRT_Union || eDest==SRT_Except || eDest==SRT_Discard ){

    p->pOrderBy = 0;
  }
  if( sqlite3SelectResolve(pParse, p, 0) ){
    goto select_end;
  }
  p->pOrderBy = pOrderBy;

................................................................................
       "a SELECT that is part of an expression");
    goto select_end;
  }
#endif

  /* ORDER BY is ignored for some destinations.
  */
  switch( eDest ){
    case SRT_Union:
    case SRT_Except:
    case SRT_Discard:
      pOrderBy = 0;
      break;
    default:
      break;
  }

  /* Begin generating code.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ) goto select_end;

................................................................................

  /* Generate code for all sub-queries in the FROM clause
  */
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
  for(i=0; i<pTabList->nSrc; i++){
    const char *zSavedAuthContext = 0;
    int needRestoreContext;


    if( pTabList->a[i].pSelect==0 ) continue;
    if( pTabList->a[i].zName!=0 ){
      zSavedAuthContext = pParse->zAuthContext;
      pParse->zAuthContext = pTabList->a[i].zName;
      needRestoreContext = 1;
    }else{
      needRestoreContext = 0;
    }
    sqlite3Select(pParse, pTabList->a[i].pSelect, SRT_TempTable, 
                 pTabList->a[i].iCursor, p, i, &isAgg, 0);
    if( needRestoreContext ){
      pParse->zAuthContext = zSavedAuthContext;
    }
    pTabList = p->pSrc;
    pWhere = p->pWhere;
    if( eDest!=SRT_Union && eDest!=SRT_Except && eDest!=SRT_Discard ){
      pOrderBy = p->pOrderBy;
    }
    pGroupBy = p->pGroupBy;
    pHaving = p->pHaving;
    isDistinct = p->isDistinct;
  }
#endif
................................................................................
      flattenSubquery(pParse, pParent, parentTab, *pParentAgg, isAgg) ){
    if( isAgg ) *pParentAgg = 1;
    goto select_end;
  }
#endif

  /* If there is an ORDER BY clause, resolve any collation sequences
  ** names that have been explicitly specified.






  */
  if( pOrderBy ){


    for(i=0; i<pOrderBy->nExpr; i++){
      if( pOrderBy->a[i].zName ){
        pOrderBy->a[i].pExpr->pColl = 

            sqlite3LocateCollSeq(pParse, pOrderBy->a[i].zName, -1);
      }
    }
    if( pParse->nErr ){
      goto select_end;
    }







  }

  /* Set the limiter.
  */
  computeLimitRegisters(pParse, p);

  /* If the output is destined for a temporary table, open that table.
  */
  if( eDest==SRT_TempTable ){
    sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0);
    sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, pEList->nExpr);
  }

  /* Do an analysis of aggregate expressions.
  */
  if( isAgg || pGroupBy ){
    NameContext sNC;
    memset(&sNC, 0, sizeof(sNC));
    sNC.pParse = pParse;
    sNC.pSrcList = pTabList;

    assert( pParse->nAgg==0 );
    isAgg = 1;
    for(i=0; i<pEList->nExpr; i++){
      if( sqlite3ExprAnalyzeAggregates(&sNC, pEList->a[i].pExpr) ){
        goto select_end;
      }
    }
    if( pGroupBy ){
      for(i=0; i<pGroupBy->nExpr; i++){
        if( sqlite3ExprAnalyzeAggregates(&sNC, pGroupBy->a[i].pExpr) ){
          goto select_end;
        }
      }
    }
    if( pHaving && sqlite3ExprAnalyzeAggregates(&sNC, pHaving) ){
      goto select_end;
    }
    if( pOrderBy ){
      for(i=0; i<pOrderBy->nExpr; i++){
        if( sqlite3ExprAnalyzeAggregates(&sNC, pOrderBy->a[i].pExpr) ){
          goto select_end;
        }
      }
    }
  }

  /* Reset the aggregator
  */
  if( isAgg ){
    int addr = sqlite3VdbeAddOp(v, OP_AggReset, (pGroupBy?0:1), pParse->nAgg);
    for(i=0; i<pParse->nAgg; i++){
      FuncDef *pFunc;
      if( (pFunc = pParse->aAgg[i].pFunc)!=0 && pFunc->xFinalize!=0 ){
        int nExpr = 0;
#ifdef SQLITE_SSE
        Expr *pAggExpr = pParse->aAgg[i].pExpr;
        if( pAggExpr && pAggExpr->pList ){
          nExpr = pAggExpr->pList->nExpr;
        }
#endif
        sqlite3VdbeOp3(v, OP_AggInit, nExpr, i, (char*)pFunc, P3_FUNCDEF);
      }
    }
    if( pGroupBy ){
      int sz = sizeof(KeyInfo) + pGroupBy->nExpr*sizeof(CollSeq*);
      KeyInfo *pKey = (KeyInfo *)sqliteMalloc(sz);
      if( 0==pKey ){
        goto select_end;
      }
      pKey->enc = pParse->db->enc;
      pKey->nField = pGroupBy->nExpr;
      for(i=0; i<pGroupBy->nExpr; i++){
        pKey->aColl[i] = sqlite3ExprCollSeq(pParse, pGroupBy->a[i].pExpr);
        if( !pKey->aColl[i] ){
          pKey->aColl[i] = pParse->db->pDfltColl;
        }
      }
      sqlite3VdbeChangeP3(v, addr, (char *)pKey, P3_KEYINFO_HANDOFF);
    }
  }

  /* Initialize the memory cell to NULL for SRT_Mem or 0 for SRT_Exists
  */
  if( eDest==SRT_Mem || eDest==SRT_Exists ){
    sqlite3VdbeAddOp(v, eDest==SRT_Mem ? OP_Null : OP_Integer, 0, 0);

    sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1);
  }

  /* Open a temporary table to use for the distinct set.
  */
  if( isDistinct ){

    distinct = pParse->nTab++;
    openVirtualIndex(pParse, p, distinct);



  }else{
    distinct = -1;
  }




  /* Begin the database scan
  */
  pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,
                             pGroupBy ? 0 : &pOrderBy);
  if( pWInfo==0 ) goto select_end;










  /* Use the standard inner loop if we are not dealing with
  ** aggregates
  */
  if( !isAgg ){
    if( selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, eDest,
                    iParm, pWInfo->iContinue, pWInfo->iBreak, aff) ){
       goto select_end;
    }
  }

  /* If we are dealing with aggregates, then do the special aggregate
  ** processing.  

  */

  else{
    AggExpr *pAgg;
    int lbl1 = 0;
    pParse->fillAgg = 1;























































    if( pGroupBy ){















      sqlite3ExprCodeExprList(pParse, pGroupBy);
      /* No affinity string is attached to the following OP_MakeRecord 
      ** because we do not need to do any coercion of datatypes. */





























      sqlite3VdbeAddOp(v, OP_MakeRecord, pGroupBy->nExpr, 0);
      lbl1 = sqlite3VdbeMakeLabel(v);


      sqlite3VdbeAddOp(v, OP_AggFocus, 0, lbl1);



    }
    for(i=0, pAgg=pParse->aAgg; i<pParse->nAgg; i++, pAgg++){
      if( pAgg->isAgg ) continue;
      sqlite3ExprCode(pParse, pAgg->pExpr);






      sqlite3VdbeAddOp(v, OP_AggSet, 0, i);

    }
    pParse->fillAgg = 0;
    if( lbl1<0 ){
      sqlite3VdbeResolveLabel(v, lbl1);





    }
    for(i=0, pAgg=pParse->aAgg; i<pParse->nAgg; i++, pAgg++){
      Expr *pE;
      int nExpr;
      FuncDef *pDef;
      if( !pAgg->isAgg ) continue;
      assert( pAgg->pFunc!=0 );
      assert( pAgg->pFunc->xStep!=0 );
      pDef = pAgg->pFunc;
      pE = pAgg->pExpr;
      assert( pE!=0 );
      assert( pE->op==TK_AGG_FUNCTION );























      nExpr = sqlite3ExprCodeExprList(pParse, pE->pList);












      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
      if( pDef->needCollSeq ){
        CollSeq *pColl = 0;
        int j;













        for(j=0; !pColl && j<nExpr; j++){
          pColl = sqlite3ExprCollSeq(pParse, pE->pList->a[j].pExpr);





        }
        if( !pColl ) pColl = pParse->db->pDfltColl;
        sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);

      }
      sqlite3VdbeOp3(v, OP_AggFunc, 0, nExpr, (char*)pDef, P3_FUNCDEF);



    }





  }


  /* End the database scan loop.









  */
























  sqlite3WhereEnd(pWInfo);


  /* If we are processing aggregates, we need to set up a second loop
  ** over all of the aggregate values and process them.


  */
  if( isAgg ){
    int endagg = sqlite3VdbeMakeLabel(v);
    int startagg;
    startagg = sqlite3VdbeAddOp(v, OP_AggNext, 0, endagg);















    if( pHaving ){
      sqlite3ExprIfFalse(pParse, pHaving, startagg, 1);
    }
    if( selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, eDest,
                    iParm, startagg, endagg, aff) ){
      goto select_end;

    }
    sqlite3VdbeAddOp(v, OP_Goto, 0, startagg);
    sqlite3VdbeResolveLabel(v, endagg);
    sqlite3VdbeAddOp(v, OP_Noop, 0, 0);
  }


  /* If there is an ORDER BY clause, then we need to sort the results
  ** and send them to the callback one by one.
  */
  if( pOrderBy ){
    generateSortTail(pParse, p, v, pEList->nExpr, eDest, iParm);
  }
................................................................................
  */
  rc = 0;

  /* Control jumps to here if an error is encountered above, or upon
  ** successful coding of the SELECT.
  */
select_end:
  restoreAggregateInfo(pParse, &sAggInfo);

  return rc;
}







|







 







>
>
>










>







 







|







 







>







 







>





>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>

|


>
|







 







|
>
>







 







|







 







|
>







 







>
>
|
|












|










|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
<
<
<
<
<
<
<
<
<
<






<



>


>
|
>







 







|







 







>
>
>
>







|







 







|
<






<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|

|
|
<
<

<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
>


|







 







|







 







<
|
|
|
<







 







|
<
<
<
<
<
<
<
<
<
<

|
<
<
<
<
<
>
|
>
>
>
>
>
>
|
<
<
|
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<

<
<
>
>
>

<
<
<
<
>
>
>
>
>
>
>
|
<
<
|
<
<







 







<
<
<

>
>
>









>
>







 







<
<
<
<
<
<
<
<
<
<
<


|

>
|
<
<





>


|







 







<



|









<
|




|
|
|
|
|
|
|
|
>







 







<

>







 







|







 







|



>


<
|
|
<
<
<
>












|
|
<
<
<
<







 







|







 







|
<
|












|


>
>
>

<
>
|








|
|
|
|



|
|
|
>
>
>
>
>
>
>
|
|
|
>
|
|
>
>
>
>
>
>
>
>
|
|
|

<

|

|

>

>
>
>
>
>
>
>



<
<
|
<



<
<
<
<







 







|







 







|
|
<







 







>







 







<
<
<
<
<
<
<
<
<
<
<
<







 







>
|







|







 







|




>
>
>
>
>
>
>
>
>
>
>
>
>
>




<
<
<
<
>
>
>
>
>
|
<
>
>
|
<
<
<
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
>
>

<
>
|
<
<
<
>
>
>
>
>
>
>



|
|
<

>
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|










|
>



>





>
>
>
>
>
>




<

<
>







 







|
<
<
<
|
<
<
<







 







>

|
|

|




|
|





|







 







|
>
>
>
>
>
>


>
>
|
<
<
>
|





>
>
>
>
>
>
>








|
|
<


<
<
<
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|
|
>
|


|


>

<
>
>
>




>
>
>
|
|
|
<
|

>
>
>
>
>
>
>
>
>
|
<
|
<




|
<
<
<
>
|
>
|
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
|
>
>
>
|
<
<
<
>
>
>
>
>
>
|
>
|
<
<
<
>
>
>
>
>
|
<
<
<
<
<
<
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
>

<
<
>

<
>
>
>
|
>
>
>
>
>
|
>
|
<
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
<
<
>
>
|
<
<
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
<
<
>

<
|
<
|
>







 







|
>


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
...
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
...
465
466
467
468
469
470
471
472










473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
...
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
...
565
566
567
568
569
570
571
572

573
574
575
576
577
578

579
580
581
582
583
584
585
...
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
649
650
651
652
653
654
655
656
657
658
659
660


661


662
















663
664
665
666
667
668
669
670
671
672
673
674
675
...
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
...
706
707
708
709
710
711
712

713
714
715

716
717
718
719
720
721
722
....
1372
1373
1374
1375
1376
1377
1378
1379










1380
1381





1382
1383
1384
1385
1386
1387
1388
1389
1390


1391









1392







1393


1394
1395
1396
1397




1398
1399
1400
1401
1402
1403
1404
1405


1406


1407
1408
1409
1410
1411
1412
1413
....
1464
1465
1466
1467
1468
1469
1470



1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
....
1500
1501
1502
1503
1504
1505
1506











1507
1508
1509
1510
1511
1512


1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
....
1542
1543
1544
1545
1546
1547
1548

1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
....
1588
1589
1590
1591
1592
1593
1594

1595
1596
1597
1598
1599
1600
1601
1602
1603
....
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
....
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660

1661
1662



1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677




1678
1679
1680
1681
1682
1683
1684
....
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
....
1728
1729
1730
1731
1732
1733
1734
1735

1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755

1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800

1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817


1818

1819
1820
1821




1822
1823
1824
1825
1826
1827
1828
....
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
....
2218
2219
2220
2221
2222
2223
2224
2225
2226

2227
2228
2229
2230
2231
2232
2233
....
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
....
2372
2373
2374
2375
2376
2377
2378












2379
2380
2381
2382
2383
2384
2385
....
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
....
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441




2442
2443
2444
2445
2446
2447

2448
2449
2450



2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475



2476
2477
2478

2479
2480



2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492

2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
....
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636

2637

2638
2639
2640
2641
2642
2643
2644
2645
....
2670
2671
2672
2673
2674
2675
2676
2677



2678



2679
2680
2681
2682
2683
2684
2685
....
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
....
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756


2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780

2781
2782







2783





























































2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796

2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809

2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821

2822

2823
2824
2825
2826
2827



2828
2829
2830
2831



2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903


2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941



2942
2943
2944
2945
2946
2947
2948
2949
2950



2951
2952
2953
2954
2955
2956











2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993



2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007

3008
3009
3010
3011
3012
3013


3014
3015

3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027

3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064


3065
3066
3067



3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087


3088
3089

3090

3091
3092
3093
3094
3095
3096
3097
3098
3099
....
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "../interop.h"

/*
** Allocate a new Select structure and return a pointer to that
** structure.
................................................................................
    pNew->pOrderBy = pOrderBy;
    pNew->isDistinct = isDistinct;
    pNew->op = TK_SELECT;
    pNew->pLimit = pLimit;
    pNew->pOffset = pOffset;
    pNew->iLimit = -1;
    pNew->iOffset = -1;
    pNew->addrOpenVirt[0] = -1;
    pNew->addrOpenVirt[1] = -1;
    pNew->addrOpenVirt[2] = -1;
  }
  return pNew;
}

/*
** Given 1 to 3 identifiers preceeding the JOIN keyword, determine the
** type of join.  Return an integer constant that expresses that type
** in terms of the following bit values:
**
**     JT_INNER
**     JT_CROSS
**     JT_OUTER
**     JT_NATURAL
**     JT_LEFT
**     JT_RIGHT
**
** A full outer join is the combination of JT_LEFT and JT_RIGHT.
**
................................................................................
  } keywords[] = {
    { "natural", 7, JT_NATURAL },
    { "left",    4, JT_LEFT|JT_OUTER },
    { "right",   5, JT_RIGHT|JT_OUTER },
    { "full",    4, JT_LEFT|JT_RIGHT|JT_OUTER },
    { "outer",   5, JT_OUTER },
    { "inner",   5, JT_INNER },
    { "cross",   5, JT_INNER|JT_CROSS },
  };
  int i, j;
  apAll[0] = pA;
  apAll[1] = pB;
  apAll[2] = pC;
  for(i=0; i<3 && apAll[i]; i++){
    p = apAll[i];
................................................................................
*/
static void addWhereTerm(
  const char *zCol,        /* Name of the column */
  const Table *pTab1,      /* First table */
  const char *zAlias1,     /* Alias for first table.  May be NULL */
  const Table *pTab2,      /* Second table */
  const char *zAlias2,     /* Alias for second table.  May be NULL */
  int iRightJoinTable,     /* VDBE cursor for the right table */
  Expr **ppExpr            /* Add the equality term to this expression */
){
  Expr *pE1a, *pE1b, *pE1c;
  Expr *pE2a, *pE2b, *pE2c;
  Expr *pE;

  pE1a = createIdExpr(zCol);
................................................................................
    zAlias2 = pTab2->zName;
  }
  pE2b = createIdExpr(zAlias2);
  pE1c = sqlite3Expr(TK_DOT, pE1b, pE1a, 0);
  pE2c = sqlite3Expr(TK_DOT, pE2b, pE2a, 0);
  pE = sqlite3Expr(TK_EQ, pE1c, pE2c, 0);
  ExprSetProperty(pE, EP_FromJoin);
  pE->iRightJoinTable = iRightJoinTable;
  *ppExpr = sqlite3ExprAnd(*ppExpr, pE);
}

/*
** Set the EP_FromJoin property on all terms of the given expression.
** And set the Expr.iRightJoinTable to iTable for every term in the
** expression.
**
** The EP_FromJoin property is used on terms of an expression to tell
** the LEFT OUTER JOIN processing logic that this term is part of the
** join restriction specified in the ON or USING clause and not a part
** of the more general WHERE clause.  These terms are moved over to the
** WHERE clause during join processing but we need to remember that they
** originated in the ON or USING clause.
**
** The Expr.iRightJoinTable tells the WHERE clause processing that the
** expression depends on table iRightJoinTable even if that table is not
** explicitly mentioned in the expression.  That information is needed
** for cases like this:
**
**    SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
**
** The where clause needs to defer the handling of the t1.x=5
** term until after the t2 loop of the join.  In that way, a
** NULL t2 row will be inserted whenever t1.x!=5.  If we do not
** defer the handling of t1.x=5, it will be processed immediately
** after the t1 loop and rows with t1.x!=5 will never appear in
** the output, which is incorrect.
*/
static void setJoinExpr(Expr *p, int iTable){
  while( p ){
    ExprSetProperty(p, EP_FromJoin);
    p->iRightJoinTable = iTable;
    setJoinExpr(p->pLeft, iTable);
    p = p->pRight;
  } 
}

/*
** This routine processes the join information for a SELECT statement.
** ON and USING clauses are converted into extra terms of the WHERE clause.
................................................................................
           "an ON or USING clause", 0);
        return 1;
      }
      for(j=0; j<pLeftTab->nCol; j++){
        char *zName = pLeftTab->aCol[j].zName;
        if( columnIndex(pRightTab, zName)>=0 ){
          addWhereTerm(zName, pLeftTab, pLeft->zAlias, 
                              pRightTab, pRight->zAlias,
                              pRight->iCursor, &p->pWhere);
          
        }
      }
    }

    /* Disallow both ON and USING clauses in the same join
    */
    if( pLeft->pOn && pLeft->pUsing ){
................................................................................
      return 1;
    }

    /* Add the ON clause to the end of the WHERE clause, connected by
    ** an AND operator.
    */
    if( pLeft->pOn ){
      setJoinExpr(pLeft->pOn, pRight->iCursor);
      p->pWhere = sqlite3ExprAnd(p->pWhere, pLeft->pOn);
      pLeft->pOn = 0;
    }

    /* Create extra terms on the WHERE clause for each column named
    ** in the USING clause.  Example: If the two tables to be joined are 
    ** A and B and the USING clause names X, Y, and Z, then add this
................................................................................
        char *zName = pList->a[j].zName;
        if( columnIndex(pLeftTab, zName)<0 || columnIndex(pRightTab, zName)<0 ){
          sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
            "not present in both tables", zName);
          return 1;
        }
        addWhereTerm(zName, pLeftTab, pLeft->zAlias, 
                            pRightTab, pRight->zAlias,
                            pRight->iCursor, &p->pWhere);
      }
    }
  }
  return 0;
}

/*
................................................................................

/*
** Insert code into "v" that will push the record on the top of the
** stack into the sorter.
*/
static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){
  sqlite3ExprCodeExprList(pParse, pOrderBy);
  sqlite3VdbeAddOp(v, OP_Sequence, pOrderBy->iECursor, 0);
  sqlite3VdbeAddOp(v, OP_Pull, pOrderBy->nExpr + 1, 0);
  sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr + 2, 0);
  sqlite3VdbeAddOp(v, OP_IdxInsert, pOrderBy->iECursor, 0);
}

/*
** Add code to implement the OFFSET and LIMIT
*/
static void codeLimiter(
  Vdbe *v,          /* Generate code into this VM */
  Select *p,        /* The SELECT statement being coded */
  int iContinue,    /* Jump here to skip the current record */
  int iBreak,       /* Jump here to end the loop */
  int nPop          /* Number of times to pop stack when jumping */
){
  if( p->iOffset>=0 && iContinue!=0 ){
    int addr = sqlite3VdbeCurrentAddr(v) + 3;
    if( nPop>0 ) addr++;
    sqlite3VdbeAddOp(v, OP_MemIncr, p->iOffset, 0);
    sqlite3VdbeAddOp(v, OP_IfMemPos, p->iOffset, addr);
    if( nPop>0 ){
      sqlite3VdbeAddOp(v, OP_Pop, nPop, 0);
    }
    sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue);
    VdbeComment((v, "# skip OFFSET records"));
  }
  if( p->iLimit>=0 && iBreak!=0 ){
    sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, iBreak);
    VdbeComment((v, "# exit when LIMIT reached"));
  }
}

/*
** Add code that will check to make sure the top N elements of the
** stack are distinct.  iTab is a sorting index that holds previously
** seen combinations of the N values.  A new entry is made in iTab
** if the current N values are new.
**
** A jump to addrRepeat is made and the K values are popped from the
** stack if the top N elements are not distinct.
*/
static void codeDistinct(
  Vdbe *v,           /* Generate code into this VM */
  int iTab,          /* A sorting index used to test for distinctness */
  int addrRepeat,    /* Jump to here if not distinct */
  int N,             /* The top N elements of the stack must be distinct */
  int K              /* Pop K elements from the stack if indistinct */
){
#if NULL_ALWAYS_DISTINCT
  sqlite3VdbeAddOp(v, OP_IsNull, -N, sqlite3VdbeCurrentAddr(v)+6);
#endif
  sqlite3VdbeAddOp(v, OP_MakeRecord, -N, 0);
  sqlite3VdbeAddOp(v, OP_Distinct, iTab, sqlite3VdbeCurrentAddr(v)+3);
  sqlite3VdbeAddOp(v, OP_Pop, K, 0);
  sqlite3VdbeAddOp(v, OP_Goto, 0, addrRepeat);
  VdbeComment((v, "# skip indistinct records"));
  sqlite3VdbeAddOp(v, OP_IdxInsert, iTab, 0);
}


/*
** This routine generates the code for the inside of the inner loop
** of a SELECT.
**
** If srcTab and nColumn are both zero, then the pEList expressions
** are evaluated in order to get the data for this row.  If nColumn>0
................................................................................

  /* If the DISTINCT keyword was present on the SELECT statement
  ** and this row has been seen before, then do not make this row
  ** part of the result.
  */
  if( hasDistinct ){
    int n = pEList->nExpr;
    codeDistinct(v, distinct, iContinue, n, n+1);










    if( pOrderBy==0 ){
      codeLimiter(v, p, iContinue, iBreak, nColumn);
    }
  }

  switch( eDest ){

    /* In this mode, write each query result to the key of the temporary
    ** table iParm.
    */
#ifndef SQLITE_OMIT_COMPOUND_SELECT
    case SRT_Union: {
      sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, NULL_ALWAYS_DISTINCT);
      if( aff ){
        sqlite3VdbeChangeP3(v, -1, aff, P3_STATIC);
      }
      sqlite3VdbeAddOp(v, OP_IdxInsert, iParm, 0);
      break;
    }

    /* Construct a record from the query result, but instead of
    ** saving that record, use it as a key to delete elements from
    ** the temporary table iParm.
................................................................................
      break;
    }
#endif

    /* Store the result as data using a unique key.
    */
    case SRT_Table:
    case SRT_VirtualTab: {
      sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
      if( pOrderBy ){
        pushOntoSorter(pParse, v, pOrderBy);
      }else{
        sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
        sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
        sqlite3VdbeAddOp(v, OP_Insert, iParm, 0);
................................................................................
      int addr2;

      assert( nColumn==1 );
      sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3);
      sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
      addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
      if( pOrderBy ){
        /* At first glance you would think we could optimize out the
        ** ORDER BY in this case since the order of entries in the set
        ** does not matter.  But there might be a LIMIT clause, in which
        ** case the order does matter */
        pushOntoSorter(pParse, v, pOrderBy);
      }else{
        char aff = (iParm>>16)&0xFF;
        aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff);
        sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1);
        sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
      }
      sqlite3VdbeJumpHere(v, addr2);
      break;
    }

    /* If this is a scalar select that is part of an expression, then
    ** store the results in the appropriate memory cell and break out
    ** of the scan loop.
    */
................................................................................
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */

    /* Send the data to the callback function or to a subroutine.  In the
    ** case of a subroutine, the subroutine itself is responsible for
    ** popping the data from the stack.
    */
    case SRT_Subroutine:
    case SRT_Callback: {

      if( pOrderBy ){
        sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
        pushOntoSorter(pParse, v, pOrderBy);
      }else if( eDest==SRT_Subroutine ){
        sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
      }else{

        sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0);
      }
      break;
    }

#if !defined(SQLITE_OMIT_TRIGGER)
    /* Discard the results.  This is used for SELECT statements inside
................................................................................
      sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0);
      break;
    }
#endif
  }
  return 0;
}

/*
** Given an expression list, generate a KeyInfo structure that records
** the collating sequence for each expression in that expression list.
**
** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
** KeyInfo structure is appropriate for initializing a virtual index to
** implement that clause.  If the ExprList is the result set of a SELECT
** then the KeyInfo structure is appropriate for initializing a virtual
** index to implement a DISTINCT test.
**
** Space to hold the KeyInfo structure is obtain from malloc.  The calling
** function is responsible for seeing that this structure is eventually
** freed.  Add the KeyInfo structure to the P3 field of an opcode using
** P3_KEYINFO_HANDOFF is the usual way of dealing with this.
*/
static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
  sqlite3 *db = pParse->db;
  int nExpr;
  KeyInfo *pInfo;
  struct ExprList_item *pItem;
  int i;

  nExpr = pList->nExpr;
  pInfo = sqliteMalloc( sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) );
  if( pInfo ){
    pInfo->aSortOrder = (char*)&pInfo->aColl[nExpr];
    pInfo->nField = nExpr;
    pInfo->enc = db->enc;
    for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
      CollSeq *pColl;
      pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
      if( !pColl ){
        pColl = db->pDfltColl;
      }
      pInfo->aColl[i] = pColl;
      pInfo->aSortOrder[i] = pItem->sortOrder;
    }
  }
  return pInfo;
}


/*
** If the inner loop was generated using a non-null pOrderBy argument,
** then the results were placed in a sorter.  After the loop is terminated
** we need to run the sorter and output the results.  The following
** routine generates the code needed to do that.
*/
................................................................................
  Parse *pParse,   /* The parsing context */
  Select *p,       /* The SELECT statement */
  Vdbe *v,         /* Generate code into this VDBE */
  int nColumn,     /* Number of columns of data */
  int eDest,       /* Write the sorted results here */
  int iParm        /* Optional parameter associated with eDest */
){
  int brk = sqlite3VdbeMakeLabel(v);
  int cont = sqlite3VdbeMakeLabel(v);
  int addr;
  int iTab;
  ExprList *pOrderBy = p->pOrderBy;





  iTab = pOrderBy->iECursor;
















  addr = 1 + sqlite3VdbeAddOp(v, OP_Sort, iTab, brk);
  codeLimiter(v, p, cont, brk, 0);
  sqlite3VdbeAddOp(v, OP_Column, iTab, pOrderBy->nExpr + 1);
  switch( eDest ){
    case SRT_Table:
    case SRT_VirtualTab: {
      sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
      sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
      sqlite3VdbeAddOp(v, OP_Insert, iParm, 0);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case SRT_Set: {
................................................................................
      sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
      break;
    }
    case SRT_Exists:
    case SRT_Mem: {
      assert( nColumn==1 );
      sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1);
      sqlite3VdbeAddOp(v, OP_Goto, 0, brk);
      break;
    }
#endif
    case SRT_Callback:
    case SRT_Subroutine: {
      int i;
      sqlite3VdbeAddOp(v, OP_Integer, p->pEList->nExpr, 0);
................................................................................
      break;
    }
    default: {
      /* Do nothing */
      break;
    }
  }

  sqlite3VdbeResolveLabel(v, cont);
  sqlite3VdbeAddOp(v, OP_Next, iTab, addr);
  sqlite3VdbeResolveLabel(v, brk);

}

/*
** Return a pointer to a string containing the 'declaration type' of the
** expression pExpr. The string may be treated as static by the caller.
**
** If the declaration type is the exact datatype definition extracted from
................................................................................
    sqlite3VdbeAddOp(v, OP_MemStore, iMem, 1);
    VdbeComment((v, "# OFFSET counter"));
    p->iOffset = iMem;
  }
}

/*
** Allocate a virtual index to use for sorting.










*/
static void createSortingIndex(Parse *pParse, Select *p, ExprList *pOrderBy){





  if( pOrderBy ){
    int addr;
    assert( pOrderBy->iECursor==0 );
    pOrderBy->iECursor = pParse->nTab++;
    addr = sqlite3VdbeAddOp(pParse->pVdbe, OP_OpenVirtual,
                            pOrderBy->iECursor, pOrderBy->nExpr+1);
    assert( p->addrOpenVirt[2] == -1 );
    p->addrOpenVirt[2] = addr;
  }


}

















/*


** The opcode at addr is an OP_OpenVirtual that created a sorting
** index tha we ended up not needing.  This routine changes that
** opcode to OP_Noop.
*/




static void uncreateSortingIndex(Parse *pParse, int addr){
  Vdbe *v = pParse->pVdbe;
  VdbeOp *pOp = sqlite3VdbeGetOp(v, addr);
  sqlite3VdbeChangeP3(v, addr, 0, 0);
  pOp->opcode = OP_Noop;
  pOp->p1 = 0;
  pOp->p2 = 0;
}





#ifndef SQLITE_OMIT_COMPOUND_SELECT
/*
** Return the appropriate collating sequence for the iCol-th column of
** the result set for the compound-select statement "p".  Return NULL if
** the column has no default collating sequence.
**
** The collating sequence for the compound select is taken from the
................................................................................
  int eDest,            /* \___  Store query results as specified */
  int iParm,            /* /     by these two parameters.         */
  char *aff             /* If eDest is SRT_Union, the affinity string */
){
  int rc = SQLITE_OK;   /* Success code from a subroutine */
  Select *pPrior;       /* Another SELECT immediately to our left */
  Vdbe *v;              /* Generate code to this VDBE */



  int nCol;             /* Number of columns in the result set */
  ExprList *pOrderBy;   /* The ORDER BY clause on p */
  int aSetP2[2];        /* Set P2 value of these op to number of columns */
  int nSetP2 = 0;       /* Number of slots in aSetP2[] used */

  /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs.  Only
  ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
  */
  if( p==0 || p->pPrior==0 ){
    rc = 1;
    goto multi_select_end;
  }
  pPrior = p->pPrior;
  assert( pPrior->pRightmost!=pPrior );
  assert( pPrior->pRightmost==p->pRightmost );
  if( pPrior->pOrderBy ){
    sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
      selectOpName(p->op));
    rc = 1;
    goto multi_select_end;
  }
  if( pPrior->pLimit ){
................................................................................
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    rc = 1;
    goto multi_select_end;
  }












  /* Create the destination temporary table if necessary
  */
  if( eDest==SRT_VirtualTab ){
    assert( p->pEList );
    assert( nSetP2<sizeof(aSetP2)/sizeof(aSetP2[0]) );
    aSetP2[nSetP2++] = sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0);


    eDest = SRT_Table;
  }

  /* Generate code for the left and right SELECT statements.
  */
  pOrderBy = p->pOrderBy;
  switch( p->op ){
    case TK_ALL: {
      if( pOrderBy==0 ){
        assert( !pPrior->pLimit );
        pPrior->pLimit = p->pLimit;
        pPrior->pOffset = p->pOffset;
        rc = sqlite3Select(pParse, pPrior, eDest, iParm, 0, 0, 0, aff);
        if( rc ){
          goto multi_select_end;
        }
................................................................................
    }
    case TK_EXCEPT:
    case TK_UNION: {
      int unionTab;    /* Cursor number of the temporary table holding result */
      int op = 0;      /* One of the SRT_ operations to apply to self */
      int priorOp;     /* The SRT_ operation to apply to prior selects */
      Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */

      int addr;

      priorOp = p->op==TK_ALL ? SRT_Table : SRT_Union;
      if( eDest==priorOp && pOrderBy==0 && !p->pLimit && !p->pOffset ){
        /* We can reuse a temporary table generated by a SELECT to our
        ** right.
        */
        unionTab = iParm;
      }else{
        /* We will need to create our own temporary table to hold the
        ** intermediate results.
        */
        unionTab = pParse->nTab++;

        if( pOrderBy && matchOrderbyToColumn(pParse, p, pOrderBy, unionTab,1) ){
          rc = 1;
          goto multi_select_end;
        }
        addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, unionTab, 0);
        if( priorOp==SRT_Table ){
          assert( nSetP2<sizeof(aSetP2)/sizeof(aSetP2[0]) );
          aSetP2[nSetP2++] = addr;
        }else{
          assert( p->addrOpenVirt[0] == -1 );
          p->addrOpenVirt[0] = addr;
          p->pRightmost->usesVirt = 1;
        }
        createSortingIndex(pParse, p, pOrderBy);
        assert( p->pEList );
      }

      /* Code the SELECT statements to our left
      */
      assert( !pPrior->pOrderBy );
      rc = sqlite3Select(pParse, pPrior, priorOp, unionTab, 0, 0, 0, aff);
................................................................................
      */
      switch( p->op ){
         case TK_EXCEPT:  op = SRT_Except;   break;
         case TK_UNION:   op = SRT_Union;    break;
         case TK_ALL:     op = SRT_Table;    break;
      }
      p->pPrior = 0;

      p->pOrderBy = 0;
      p->disallowOrderBy = pOrderBy!=0;
      pLimit = p->pLimit;
      p->pLimit = 0;
      pOffset = p->pOffset;
      p->pOffset = 0;
      rc = sqlite3Select(pParse, p, op, unionTab, 0, 0, 0, aff);
      p->pPrior = pPrior;
      p->pOrderBy = pOrderBy;
................................................................................
        }
        iBreak = sqlite3VdbeMakeLabel(v);
        iCont = sqlite3VdbeMakeLabel(v);
        sqlite3VdbeAddOp(v, OP_Rewind, unionTab, iBreak);
        computeLimitRegisters(pParse, p);
        iStart = sqlite3VdbeCurrentAddr(v);
        rc = selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr,
                             pOrderBy, -1, eDest, iParm, 
                             iCont, iBreak, 0);
        if( rc ){
          rc = 1;
          goto multi_select_end;
        }
        sqlite3VdbeResolveLabel(v, iCont);
        sqlite3VdbeAddOp(v, OP_Next, unionTab, iStart);
................................................................................

      /* INTERSECT is different from the others since it requires
      ** two temporary tables.  Hence it has its own case.  Begin
      ** by allocating the tables we will need.
      */
      tab1 = pParse->nTab++;
      tab2 = pParse->nTab++;
      if( pOrderBy && matchOrderbyToColumn(pParse,p,pOrderBy,tab1,1) ){
        rc = 1;
        goto multi_select_end;
      }
      createSortingIndex(pParse, p, pOrderBy);

      addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab1, 0);

      assert( p->addrOpenVirt[0] == -1 );
      p->addrOpenVirt[0] = addr;



      p->pRightmost->usesVirt = 1;
      assert( p->pEList );

      /* Code the SELECTs to our left into temporary table "tab1".
      */
      rc = sqlite3Select(pParse, pPrior, SRT_Union, tab1, 0, 0, 0, aff);
      if( rc ){
        goto multi_select_end;
      }

      /* Code the current SELECT into temporary table "tab2"
      */
      addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab2, 0);
      assert( p->addrOpenVirt[1] == -1 );
      p->addrOpenVirt[1] = addr;




      p->pPrior = 0;
      pLimit = p->pLimit;
      p->pLimit = 0;
      pOffset = p->pOffset;
      p->pOffset = 0;
      rc = sqlite3Select(pParse, p, SRT_Union, tab2, 0, 0, 0, aff);
      p->pPrior = pPrior;
................................................................................
      iBreak = sqlite3VdbeMakeLabel(v);
      iCont = sqlite3VdbeMakeLabel(v);
      sqlite3VdbeAddOp(v, OP_Rewind, tab1, iBreak);
      computeLimitRegisters(pParse, p);
      iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0);
      sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont);
      rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr,
                             pOrderBy, -1, eDest, iParm, 
                             iCont, iBreak, 0);
      if( rc ){
        rc = 1;
        goto multi_select_end;
      }
      sqlite3VdbeResolveLabel(v, iCont);
      sqlite3VdbeAddOp(v, OP_Next, tab1, iStart);
................................................................................
    rc = 1;
    goto multi_select_end;
  }

  /* Set the number of columns in temporary tables
  */
  nCol = p->pEList->nExpr;
  while( nSetP2 ){

    sqlite3VdbeChangeP2(v, aSetP2[--nSetP2], nCol);
  }

  /* Compute collating sequences used by either the ORDER BY clause or
  ** by any temporary tables needed to implement the compound select.
  ** Attach the KeyInfo structure to all temporary tables.  Invoke the
  ** ORDER BY processing if there is an ORDER BY clause.
  **
  ** This section is run by the right-most SELECT statement only.
  ** SELECT statements to the left always skip this part.  The right-most
  ** SELECT might also skip this part if it has no ORDER BY clause and
  ** no temp tables are required.
  */
  if( pOrderBy || p->usesVirt ){
    int i;                        /* Loop counter */
    KeyInfo *pKeyInfo;            /* Collating sequence for the result set */
    Select *pLoop;                /* For looping through SELECT statements */
    CollSeq **apColl;
    CollSeq **aCopy;


    assert( p->pRightmost==p );
    pKeyInfo = sqliteMalloc(sizeof(*pKeyInfo)+nCol*2*sizeof(CollSeq*) + nCol);
    if( !pKeyInfo ){
      rc = SQLITE_NOMEM;
      goto multi_select_end;
    }

    pKeyInfo->enc = pParse->db->enc;
    pKeyInfo->nField = nCol;

    for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
      *apColl = multiSelectCollSeq(pParse, p, i);
      if( 0==*apColl ){
        *apColl = pParse->db->pDfltColl;
      }
    }

    for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
      for(i=0; i<2; i++){
        int addr = pLoop->addrOpenVirt[i];
        if( addr<0 ){
          /* If [0] is unused then [1] is also unused.  So we can
          ** always safely abort as soon as the first unused slot is found */
          assert( pLoop->addrOpenVirt[1]<0 );
          break;
        }
        sqlite3VdbeChangeP2(v, addr, nCol);
        sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO);
      }
    }

    if( pOrderBy ){
      struct ExprList_item *pOTerm = pOrderBy->a;
      int nExpr = pOrderBy->nExpr;
      int addr;
      u8 *pSortOrder;

      aCopy = (CollSeq**)&pKeyInfo[1];
      pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nExpr];
      memcpy(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*));
      apColl = pKeyInfo->aColl;
      for(i=0; i<pOrderBy->nExpr; i++, pOTerm++, apColl++, pSortOrder++){
        Expr *pExpr = pOTerm->pExpr;
        char *zName = pOTerm->zName;
        assert( pExpr->op==TK_COLUMN && pExpr->iColumn<nCol );

        if( zName ){
          *apColl = sqlite3LocateCollSeq(pParse, zName, -1);
        }else{
          *apColl = aCopy[pExpr->iColumn];
        }
        *pSortOrder = pOTerm->sortOrder;
      }
      assert( p->pRightmost==p );
      assert( p->addrOpenVirt[2]>=0 );
      addr = p->addrOpenVirt[2];
      sqlite3VdbeChangeP2(v, addr, p->pEList->nExpr+2);
      pKeyInfo->nField = pOrderBy->nExpr;
      sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
      pKeyInfo = 0;
      generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm);
    }



    sqliteFree(pKeyInfo);

  }

multi_select_end:




  return rc;
}
#endif /* SQLITE_OMIT_COMPOUND_SELECT */

#ifndef SQLITE_OMIT_VIEW
/*
** Scan through the expression pExpr.  Replace every reference to
................................................................................
  if( (pSub->pLimit && p->pLimit) || pSub->pOffset || 
      (pSub->pLimit && isAgg) ) return 0;
  if( pSubSrc->nSrc==0 ) return 0;
  if( pSub->isDistinct && (pSrc->nSrc>1 || isAgg) ){
     return 0;
  }
  if( p->isDistinct && subqueryIsAgg ) return 0;
  if( (p->disallowOrderBy || p->pOrderBy) && pSub->pOrderBy ) return 0;

  /* Restriction 3:  If the subquery is a join, make sure the subquery is 
  ** not used as the right operand of an outer join.  Examples of why this
  ** is not allowed:
  **
  **         t1 LEFT OUTER JOIN (t2 JOIN t3)
  **
................................................................................
  ** The column names have already been generated in the calling function.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ) return 0;

  /* If the output is destined for a temporary table, open that table.
  */
  if( eDest==SRT_VirtualTab ){
    sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 1);

  }

  /* Generating code to find the min or the max.  Basically all we have
  ** to do is find the first or the last entry in the chosen index.  If
  ** the min() or max() is on the INTEGER PRIMARY KEY, then find the first
  ** or last entry in the main table.
  */
................................................................................
  Parse *pParse,         /* The parser context */
  Select *p,             /* The SELECT statement being coded. */
  NameContext *pOuterNC  /* The outer name context. May be NULL. */
){
  ExprList *pEList;          /* Result set. */
  int i;                     /* For-loop variable used in multiple places */
  NameContext sNC;           /* Local name-context */
  ExprList *pGroupBy;        /* The group by clause */

  /* If this routine has run before, return immediately. */
  if( p->isResolved ){
    assert( !pOuterNC );
    return SQLITE_OK;
  }
  p->isResolved = 1;
................................................................................
  /* Set up the local name-context to pass to ExprResolveNames() to
  ** resolve the expression-list.
  */
  sNC.allowAgg = 1;
  sNC.pSrcList = p->pSrc;
  sNC.pNext = pOuterNC;













  /* Resolve names in the result set. */
  pEList = p->pEList;
  if( !pEList ) return SQLITE_ERROR;
  for(i=0; i<pEList->nExpr; i++){
    Expr *pX = pEList->a[i].pExpr;
    if( sqlite3ExprResolveNames(&sNC, pX) ){
      return SQLITE_ERROR;
................................................................................
    }
  }

  /* If there are no aggregate functions in the result-set, and no GROUP BY 
  ** expression, do not allow aggregates in any of the other expressions.
  */
  assert( !p->isAgg );
  pGroupBy = p->pGroupBy;
  if( pGroupBy || sNC.hasAgg ){
    p->isAgg = 1;
  }else{
    sNC.allowAgg = 0;
  }

  /* If a HAVING clause is present, then there must be a GROUP BY clause.
  */
  if( p->pHaving && !pGroupBy ){
    sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
    return SQLITE_ERROR;
  }

  /* Add the expression list to the name-context before parsing the
  ** other expressions in the SELECT statement. This is so that
  ** expressions in the WHERE clause (etc.) can refer to expressions by
................................................................................
  ** Minor point: If this is the case, then the expression will be
  ** re-evaluated for each reference to it.
  */
  sNC.pEList = p->pEList;
  if( sqlite3ExprResolveNames(&sNC, p->pWhere) ||
      sqlite3ExprResolveNames(&sNC, p->pHaving) ||
      processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") ||
      processOrderGroupBy(&sNC, pGroupBy, "GROUP")
  ){
    return SQLITE_ERROR;
  }

  /* Make sure the GROUP BY clause does not contain aggregate functions.
  */
  if( pGroupBy ){
    struct ExprList_item *pItem;
  
    for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){
      if( ExprHasProperty(pItem->pExpr, EP_Agg) ){
        sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
            "the GROUP BY clause");
        return SQLITE_ERROR;
      }
    }
  }

  return SQLITE_OK;
}

/*




** Reset the aggregate accumulator.
**
** The aggregate accumulator is a set of memory cells that hold
** intermediate results while calculating an aggregate.  This
** routine simply stores NULLs in all of those memory cells.
*/

static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
  Vdbe *v = pParse->pVdbe;
  int i;



  struct AggInfo_func *pFunc;
  if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){
    return;
  }
  for(i=0; i<pAggInfo->nColumn; i++){
    sqlite3VdbeAddOp(v, OP_MemNull, pAggInfo->aCol[i].iMem, 0);
  }
  for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
    sqlite3VdbeAddOp(v, OP_MemNull, pFunc->iMem, 0);
    if( pFunc->iDistinct>=0 ){
      Expr *pE = pFunc->pExpr;
      if( pE->pList==0 || pE->pList->nExpr!=1 ){
        sqlite3ErrorMsg(pParse, "DISTINCT in aggregate must be followed "
           "by an expression");
        pFunc->iDistinct = -1;
      }else{
        KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->pList);
        sqlite3VdbeOp3(v, OP_OpenVirtual, pFunc->iDistinct, 0, 
                          (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
      }
    }
  }
}

/*



** Invoke the OP_AggFinalize opcode for every aggregate function
** in the AggInfo structure.
*/

static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
  Vdbe *v = pParse->pVdbe;



  int i;
  struct AggInfo_func *pF;
  for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
    ExprList *pList = pF->pExpr->pList;
    sqlite3VdbeOp3(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0,
                      (void*)pF->pFunc, P3_FUNCDEF);
  }
}

/*
** Update the accumulator memory cells for an aggregate based on
** the current cursor position.

*/
static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
  Vdbe *v = pParse->pVdbe;
  int i;
  struct AggInfo_func *pF;
  struct AggInfo_col *pC;

  pAggInfo->directMode = 1;
  for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
    int nArg;
    int addrNext = 0;
    ExprList *pList = pF->pExpr->pList;
    if( pList ){
      nArg = pList->nExpr;
      sqlite3ExprCodeExprList(pParse, pList);
    }else{
      nArg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      assert( nArg==1 );
      codeDistinct(v, pF->iDistinct, addrNext, 1, 2);
    }
    if( pF->pFunc->needCollSeq ){
      CollSeq *pColl = 0;
      struct ExprList_item *pItem;
      int j;
      for(j=0, pItem=pList->a; !pColl && j<pList->nExpr; j++, pItem++){
        pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
      }
      if( !pColl ){
        pColl = pParse->db->pDfltColl;
      }
      sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);
    }
    sqlite3VdbeOp3(v, OP_AggStep, pF->iMem, nArg, (void*)pF->pFunc, P3_FUNCDEF);
    if( addrNext ){
      sqlite3VdbeResolveLabel(v, addrNext);
    }
  }
  for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
    sqlite3ExprCode(pParse, pC->pExpr);
    sqlite3VdbeAddOp(v, OP_MemStore, pC->iMem, 1);
  }
  pAggInfo->directMode = 0;
}


/*
** Generate code for the given SELECT statement.
**
** The results are distributed in various ways depending on the
** value of eDest and iParm.
**
**     eDest Value       Result
................................................................................
  int eDest,             /* How to dispose of the results */
  int iParm,             /* A parameter used by the eDest disposal method */
  Select *pParent,       /* Another SELECT for which this is a sub-query */
  int parentTab,         /* Index in pParent->pSrc of this query */
  int *pParentAgg,       /* True if pParent uses aggregate functions */
  char *aff              /* If eDest is SRT_Union, the affinity string */
){
  int i, j;              /* Loop counters */
  WhereInfo *pWInfo;     /* Return from sqlite3WhereBegin() */
  Vdbe *v;               /* The virtual machine under construction */
  int isAgg;             /* True for select lists like "count(*)" */
  ExprList *pEList;      /* List of columns to extract. */
  SrcList *pTabList;     /* List of tables to select from */
  Expr *pWhere;          /* The WHERE clause.  May be NULL */
  ExprList *pOrderBy;    /* The ORDER BY clause.  May be NULL */
  ExprList *pGroupBy;    /* The GROUP BY clause.  May be NULL */
  Expr *pHaving;         /* The HAVING clause.  May be NULL */
  int isDistinct;        /* True if the DISTINCT keyword is present */
  int distinct;          /* Table to use for the distinct set */
  int rc = 1;            /* Value to return from this function */
  int addrSortIndex;     /* Address of an OP_OpenVirtual instruction */
  AggInfo sAggInfo;      /* Information used by aggregate queries */

  if( sqlite3_malloc_failed || pParse->nErr || p==0 ) return 1;
  if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
  memset(&sAggInfo, 0, sizeof(sAggInfo));

#ifndef SQLITE_OMIT_COMPOUND_SELECT
  /* If there is are a sequence of queries, do the earlier ones first.
  */
  if( p->pPrior ){
    if( p->pRightmost==0 ){
      Select *pLoop;
      for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
        pLoop->pRightmost = p;
      }
    }
    return multiSelect(pParse, p, eDest, iParm, aff);
  }
#endif


  pOrderBy = p->pOrderBy;

  if( IgnorableOrderby(eDest) ){
    p->pOrderBy = 0;
  }
  if( sqlite3SelectResolve(pParse, p, 0) ){
    goto select_end;
  }
  p->pOrderBy = pOrderBy;

................................................................................
       "a SELECT that is part of an expression");
    goto select_end;
  }
#endif

  /* ORDER BY is ignored for some destinations.
  */
  if( IgnorableOrderby(eDest) ){



    pOrderBy = 0;



  }

  /* Begin generating code.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ) goto select_end;

................................................................................

  /* Generate code for all sub-queries in the FROM clause
  */
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
  for(i=0; i<pTabList->nSrc; i++){
    const char *zSavedAuthContext = 0;
    int needRestoreContext;
    struct SrcList_item *pItem = &pTabList->a[i];

    if( pItem->pSelect==0 ) continue;
    if( pItem->zName!=0 ){
      zSavedAuthContext = pParse->zAuthContext;
      pParse->zAuthContext = pItem->zName;
      needRestoreContext = 1;
    }else{
      needRestoreContext = 0;
    }
    sqlite3Select(pParse, pItem->pSelect, SRT_VirtualTab, 
                 pItem->iCursor, p, i, &isAgg, 0);
    if( needRestoreContext ){
      pParse->zAuthContext = zSavedAuthContext;
    }
    pTabList = p->pSrc;
    pWhere = p->pWhere;
    if( !IgnorableOrderby(eDest) ){
      pOrderBy = p->pOrderBy;
    }
    pGroupBy = p->pGroupBy;
    pHaving = p->pHaving;
    isDistinct = p->isDistinct;
  }
#endif
................................................................................
      flattenSubquery(pParse, pParent, parentTab, *pParentAgg, isAgg) ){
    if( isAgg ) *pParentAgg = 1;
    goto select_end;
  }
#endif

  /* If there is an ORDER BY clause, resolve any collation sequences
  ** names that have been explicitly specified and create a sorting index.
  **
  ** This sorting index might end up being unused if the data can be 
  ** extracted in pre-sorted order.  If that is the case, then the
  ** OP_OpenVirtual instruction will be changed to an OP_Noop once
  ** we figure out that the sorting index is not needed.  The addrSortIndex
  ** variable is used to facilitate that change.
  */
  if( pOrderBy ){
    struct ExprList_item *pTerm;
    KeyInfo *pKeyInfo;
    for(i=0, pTerm=pOrderBy->a; i<pOrderBy->nExpr; i++, pTerm++){


      if( pTerm->zName ){
        pTerm->pExpr->pColl = sqlite3LocateCollSeq(pParse, pTerm->zName, -1);
      }
    }
    if( pParse->nErr ){
      goto select_end;
    }
    pKeyInfo = keyInfoFromExprList(pParse, pOrderBy);
    pOrderBy->iECursor = pParse->nTab++;
    p->addrOpenVirt[2] = addrSortIndex =
       sqlite3VdbeOp3(v, OP_OpenVirtual, pOrderBy->iECursor, pOrderBy->nExpr+2, 
                        (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
  }else{
    addrSortIndex = -1;
  }

  /* Set the limiter.
  */
  computeLimitRegisters(pParse, p);

  /* If the output is destined for a temporary table, open that table.
  */
  if( eDest==SRT_VirtualTab ){
    sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, pEList->nExpr);

  }






































































  /* Initialize the memory cell to NULL for SRT_Mem or 0 for SRT_Exists
  */
  if( eDest==SRT_Mem ){
    sqlite3VdbeAddOp(v, OP_MemNull, iParm, 0);
  }else if( eDest==SRT_Exists ){
    sqlite3VdbeAddOp(v, OP_MemInt, 0, iParm);
  }

  /* Open a virtual index to use for the distinct set.
  */
  if( isDistinct ){
    KeyInfo *pKeyInfo;
    distinct = pParse->nTab++;

    pKeyInfo = keyInfoFromExprList(pParse, p->pEList);
    sqlite3VdbeOp3(v, OP_OpenVirtual, distinct, 0, 
                        (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
  }else{
    distinct = -1;
  }

  /* Aggregate and non-aggregate queries are handled differently */
  if( !isAgg && pGroupBy==0 ){
    /* This case is for non-aggregate queries
    ** Begin the database scan
    */
    pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy);

    if( pWInfo==0 ) goto select_end;

    /* If sorting index that was created by a prior OP_OpenVirtual 
    ** instruction ended up not being needed, then change the OP_OpenVirtual
    ** into an OP_Noop.
    */
    if( addrSortIndex>=0 && pOrderBy==0 ){
      uncreateSortingIndex(pParse, addrSortIndex);
      p->addrOpenVirt[2] = -1;
    }

    /* Use the standard inner loop

    */

    if( selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, eDest,
                    iParm, pWInfo->iContinue, pWInfo->iBreak, aff) ){
       goto select_end;
    }




    /* End the database scan loop.
    */
    sqlite3WhereEnd(pWInfo);
  }else{



    /* This is the processing for aggregate queries */
    NameContext sNC;    /* Name context for processing aggregate information */
    int iAMem;          /* First Mem address for storing current GROUP BY */
    int iBMem;          /* First Mem address for previous GROUP BY */
    int iUseFlag;       /* Mem address holding flag indicating that at least
                        ** one row of the input to the aggregator has been
                        ** processed */
    int iAbortFlag;     /* Mem address which causes query abort if positive */
    int groupBySort;    /* Rows come from source in GROUP BY order */


    /* The following variables hold addresses or labels for parts of the
    ** virtual machine program we are putting together */
    int addrOutputRow;      /* Start of subroutine that outputs a result row */
    int addrSetAbort;       /* Set the abort flag and return */
    int addrInitializeLoop; /* Start of code that initializes the input loop */
    int addrTopOfLoop;      /* Top of the input loop */
    int addrGroupByChange;  /* Code that runs when any GROUP BY term changes */
    int addrProcessRow;     /* Code to process a single input row */
    int addrEnd;            /* End of all processing */
    int addrSortingIdx;     /* The OP_OpenVirtual for the sorting index */
    int addrReset;          /* Subroutine for resetting the accumulator */

    addrEnd = sqlite3VdbeMakeLabel(v);

    /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
    ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
    ** SELECT statement.
    */
    memset(&sNC, 0, sizeof(sNC));
    sNC.pParse = pParse;
    sNC.pSrcList = pTabList;
    sNC.pAggInfo = &sAggInfo;
    sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0;
    sAggInfo.pGroupBy = pGroupBy;
    if( sqlite3ExprAnalyzeAggList(&sNC, pEList) ){
      goto select_end;
    }
    if( sqlite3ExprAnalyzeAggList(&sNC, pOrderBy) ){
      goto select_end;
    }
    if( pHaving && sqlite3ExprAnalyzeAggregates(&sNC, pHaving) ){
      goto select_end;
    }
    sAggInfo.nAccumulator = sAggInfo.nColumn;
    for(i=0; i<sAggInfo.nFunc; i++){
      if( sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->pList) ){
        goto select_end;
      }
    }
    if( sqlite3_malloc_failed ) goto select_end;

    /* Processing for aggregates with GROUP BY is very different and
    ** much more complex tha aggregates without a GROUP BY.
    */
    if( pGroupBy ){
      KeyInfo *pKeyInfo;  /* Keying information for the group by clause */

      /* Create labels that we will be needing
      */
     
      addrInitializeLoop = sqlite3VdbeMakeLabel(v);
      addrGroupByChange = sqlite3VdbeMakeLabel(v);
      addrProcessRow = sqlite3VdbeMakeLabel(v);

      /* If there is a GROUP BY clause we might need a sorting index to
      ** implement it.  Allocate that sorting index now.  If it turns out
      ** that we do not need it after all, the OpenVirtual instruction
      ** will be converted into a Noop.  
      */
      sAggInfo.sortingIdx = pParse->nTab++;
      pKeyInfo = keyInfoFromExprList(pParse, pGroupBy);


      addrSortingIdx =
          sqlite3VdbeOp3(v, OP_OpenVirtual, sAggInfo.sortingIdx,
                         sAggInfo.nSortingColumn,
                         (char*)pKeyInfo, P3_KEYINFO_HANDOFF);

      /* Initialize memory locations used by GROUP BY aggregate processing
      */
      iUseFlag = pParse->nMem++;
      iAbortFlag = pParse->nMem++;
      iAMem = pParse->nMem;
      pParse->nMem += pGroupBy->nExpr;
      iBMem = pParse->nMem;
      pParse->nMem += pGroupBy->nExpr;
      sqlite3VdbeAddOp(v, OP_MemInt, 0, iAbortFlag);
      VdbeComment((v, "# clear abort flag"));
      sqlite3VdbeAddOp(v, OP_MemInt, 0, iUseFlag);
      VdbeComment((v, "# indicate accumulator empty"));
      sqlite3VdbeAddOp(v, OP_Goto, 0, addrInitializeLoop);

      /* Generate a subroutine that outputs a single row of the result
      ** set.  This subroutine first looks at the iUseFlag.  If iUseFlag
      ** is less than or equal to zero, the subroutine is a no-op.  If
      ** the processing calls for the query to abort, this subroutine
      ** increments the iAbortFlag memory location before returning in
      ** order to signal the caller to abort.
      */
      addrSetAbort = sqlite3VdbeCurrentAddr(v);
      sqlite3VdbeAddOp(v, OP_MemInt, 1, iAbortFlag);
      VdbeComment((v, "# set abort flag"));
      sqlite3VdbeAddOp(v, OP_Return, 0, 0);
      addrOutputRow = sqlite3VdbeCurrentAddr(v);
      sqlite3VdbeAddOp(v, OP_IfMemPos, iUseFlag, addrOutputRow+2);
      VdbeComment((v, "# Groupby result generator entry point"));
      sqlite3VdbeAddOp(v, OP_Return, 0, 0);
      finalizeAggFunctions(pParse, &sAggInfo);
      if( pHaving ){
        sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, 1);
      }



      rc = selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy,
                           distinct, eDest, iParm, 
                           addrOutputRow+1, addrSetAbort, aff);
      if( rc ){
        goto select_end;
      }
      sqlite3VdbeAddOp(v, OP_Return, 0, 0);
      VdbeComment((v, "# end groupby result generator"));




      /* Generate a subroutine that will reset the group-by accumulator
      */
      addrReset = sqlite3VdbeCurrentAddr(v);
      resetAccumulator(pParse, &sAggInfo);
      sqlite3VdbeAddOp(v, OP_Return, 0, 0);












      /* Begin a loop that will extract all source rows in GROUP BY order.
      ** This might involve two separate loops with an OP_Sort in between, or
      ** it might be a single loop that uses an index to extract information
      ** in the right order to begin with.
      */
      sqlite3VdbeResolveLabel(v, addrInitializeLoop);
      sqlite3VdbeAddOp(v, OP_Gosub, 0, addrReset);
      pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy);
      if( pWInfo==0 ) goto select_end;
      if( pGroupBy==0 ){
        /* The optimizer is able to deliver rows in group by order so
        ** we do not have to sort.  The OP_OpenVirtual table will be
        ** cancelled later because we still need to use the pKeyInfo
        */
        pGroupBy = p->pGroupBy;
        groupBySort = 0;
      }else{
        /* Rows are coming out in undetermined order.  We have to push
        ** each row into a sorting index, terminate the first loop,
        ** then loop over the sorting index in order to get the output
        ** in sorted order
        */
        groupBySort = 1;
        sqlite3ExprCodeExprList(pParse, pGroupBy);
        sqlite3VdbeAddOp(v, OP_Sequence, sAggInfo.sortingIdx, 0);
        j = pGroupBy->nExpr+1;
        for(i=0; i<sAggInfo.nColumn; i++){
          struct AggInfo_col *pCol = &sAggInfo.aCol[i];
          if( pCol->iSorterColumn<j ) continue;
          if( pCol->iColumn<0 ){
            sqlite3VdbeAddOp(v, OP_Rowid, pCol->iTable, 0);
          }else{
            sqlite3VdbeAddOp(v, OP_Column, pCol->iTable, pCol->iColumn);
          }
          j++;
        }
        sqlite3VdbeAddOp(v, OP_MakeRecord, j, 0);



        sqlite3VdbeAddOp(v, OP_IdxInsert, sAggInfo.sortingIdx, 0);
        sqlite3WhereEnd(pWInfo);
        sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, addrEnd);
        VdbeComment((v, "# GROUP BY sort"));
        sAggInfo.useSortingIdx = 1;
      }

      /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
      ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
      ** Then compare the current GROUP BY terms against the GROUP BY terms
      ** from the previous row currently stored in a0, a1, a2...
      */
      addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
      for(j=0; j<pGroupBy->nExpr; j++){

        if( groupBySort ){
          sqlite3VdbeAddOp(v, OP_Column, sAggInfo.sortingIdx, j);
        }else{
          sAggInfo.directMode = 1;
          sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr);
        }


        sqlite3VdbeAddOp(v, OP_MemStore, iBMem+j, j<pGroupBy->nExpr-1);
      }

      for(j=pGroupBy->nExpr-1; j>=0; j--){
        if( j<pGroupBy->nExpr-1 ){
          sqlite3VdbeAddOp(v, OP_MemLoad, iBMem+j, 0);
        }
        sqlite3VdbeAddOp(v, OP_MemLoad, iAMem+j, 0);
        if( j==0 ){
          sqlite3VdbeAddOp(v, OP_Eq, 0x200, addrProcessRow);
        }else{
          sqlite3VdbeAddOp(v, OP_Ne, 0x200, addrGroupByChange);
        }
        sqlite3VdbeChangeP3(v, -1, (void*)pKeyInfo->aColl[j], P3_COLLSEQ);
      }


      /* Generate code that runs whenever the GROUP BY changes.
      ** Change in the GROUP BY are detected by the previous code
      ** block.  If there were no changes, this block is skipped.
      **
      ** This code copies current group by terms in b0,b1,b2,...
      ** over to a0,a1,a2.  It then calls the output subroutine
      ** and resets the aggregate accumulator registers in preparation
      ** for the next GROUP BY batch.
      */
      sqlite3VdbeResolveLabel(v, addrGroupByChange);
      for(j=0; j<pGroupBy->nExpr; j++){
        sqlite3VdbeAddOp(v, OP_MemMove, iAMem+j, iBMem+j);
      }
      sqlite3VdbeAddOp(v, OP_Gosub, 0, addrOutputRow);
      VdbeComment((v, "# output one row"));
      sqlite3VdbeAddOp(v, OP_IfMemPos, iAbortFlag, addrEnd);
      VdbeComment((v, "# check abort flag"));
      sqlite3VdbeAddOp(v, OP_Gosub, 0, addrReset);
      VdbeComment((v, "# reset accumulator"));

      /* Update the aggregate accumulators based on the content of
      ** the current row
      */
      sqlite3VdbeResolveLabel(v, addrProcessRow);
      updateAccumulator(pParse, &sAggInfo);
      sqlite3VdbeAddOp(v, OP_MemInt, 1, iUseFlag);
      VdbeComment((v, "# indicate data in accumulator"));

      /* End of the loop
      */
      if( groupBySort ){
        sqlite3VdbeAddOp(v, OP_Next, sAggInfo.sortingIdx, addrTopOfLoop);
      }else{
        sqlite3WhereEnd(pWInfo);
        uncreateSortingIndex(pParse, addrSortingIdx);
      }



      /* Output the final row of result
      */



      sqlite3VdbeAddOp(v, OP_Gosub, 0, addrOutputRow);
      VdbeComment((v, "# output final row"));
      
    } /* endif pGroupBy */
    else {
      /* This case runs if the aggregate has no GROUP BY clause.  The
      ** processing is much simpler since there is only a single row
      ** of output.
      */
      resetAccumulator(pParse, &sAggInfo);
      pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
      if( pWInfo==0 ) goto select_end;
      updateAccumulator(pParse, &sAggInfo);
      sqlite3WhereEnd(pWInfo);
      finalizeAggFunctions(pParse, &sAggInfo);
      pOrderBy = 0;
      if( pHaving ){
        sqlite3ExprIfFalse(pParse, pHaving, addrEnd, 1);
      }
      selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, -1, 


                      eDest, iParm, addrEnd, addrEnd, aff);
    }

    sqlite3VdbeResolveLabel(v, addrEnd);

    
  } /* endif aggregate query */

  /* If there is an ORDER BY clause, then we need to sort the results
  ** and send them to the callback one by one.
  */
  if( pOrderBy ){
    generateSortTail(pParse, p, v, pEList->nExpr, eDest, iParm);
  }
................................................................................
  */
  rc = 0;

  /* Control jumps to here if an error is encountered above, or upon
  ** successful coding of the SELECT.
  */
select_end:
  sqliteFree(sAggInfo.aCol);
  sqliteFree(sAggInfo.aFunc);
  return rc;
}

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
652
653
654
655
656
657
658
659


660


661
662
663
664
665
666
667
668
669
....
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
....
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
....
1693
1694
1695
1696
1697
1698
1699







1700
1701
1702
1703
1704
1705
1706
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.8 2005/09/01 06:07:56 rmsimpson Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "sqlite3.h"
#include <ctype.h>
................................................................................
    }else if( c=='\n' ){
      fputc('\\', out);
      fputc('n', out);
    }else if( c=='\r' ){
      fputc('\\', out);
      fputc('r', out);
    }else if( !isprint(c) ){
      fprintf(out, "\\%03o", c);
    }else{
      fputc(c, out);
    }
  }
  fputc('"', out);
}

................................................................................
  struct callback_data *p = (struct callback_data *)pArg;

  if( nArg!=3 ) return 1;
  zTable = azArg[0];
  zType = azArg[1];
  zSql = azArg[2];
  
  if( strcmp(zTable,"sqlite_sequence")!=0 ){


    fprintf(p->out, "%s;\n", zSql);


  }else{
    fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
  }

  if( strcmp(zType, "table")==0 ){
    sqlite3_stmt *pTableInfo = 0;
    char *zSelect = 0;
    char *zTableInfo = 0;
    char *zTmp = 0;
................................................................................
        zShellStatic = 0;
      }
    }else{
      sqlite3_exec(p->db,
         "SELECT sql FROM "
         "  (SELECT * FROM sqlite_master UNION ALL"
         "   SELECT * FROM sqlite_temp_master) "
         "WHERE type!='meta' AND sql NOTNULL "
         "ORDER BY substr(type,2,1), name",
         callback, &data, &zErrMsg
      );
    }
    if( zErrMsg ){
      fprintf(stderr,"Error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
................................................................................
    char **azResult;
    int nRow, rc;
    char *zErrMsg;
    open_db(p);
    if( nArg==1 ){
      rc = sqlite3_get_table(p->db,
        "SELECT name FROM sqlite_master "
        "WHERE type IN ('table','view') "
        "UNION ALL "
        "SELECT name FROM sqlite_temp_master "
        "WHERE type IN ('table','view') "
        "ORDER BY 1",
        &azResult, &nRow, 0, &zErrMsg
      );
    }else{
................................................................................
    data.zDbFilename = 0;
#endif
  }
  if( i<argc ){
    zFirstCmd = argv[i++];
  }
  data.out = stdout;








  /* Go ahead and open the database file if it already exists.  If the
  ** file does not exist, delay opening it.  This prevents empty database
  ** files from being created if a user mistypes the database name argument
  ** to the sqlite command-line tool.
  */
  if( access(data.zDbFilename, 0)==0 ){







|







 







|







 







|
>
>
|
>
>

|







 







|







 







|







 







>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
....
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
....
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
....
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "sqlite3.h"
#include <ctype.h>
................................................................................
    }else if( c=='\n' ){
      fputc('\\', out);
      fputc('n', out);
    }else if( c=='\r' ){
      fputc('\\', out);
      fputc('r', out);
    }else if( !isprint(c) ){
      fprintf(out, "\\%03o", c&0xff);
    }else{
      fputc(c, out);
    }
  }
  fputc('"', out);
}

................................................................................
  struct callback_data *p = (struct callback_data *)pArg;

  if( nArg!=3 ) return 1;
  zTable = azArg[0];
  zType = azArg[1];
  zSql = azArg[2];
  
  if( strcmp(zTable, "sqlite_sequence")==0 ){
    fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
  }else if( strcmp(zTable, "sqlite_stat1")==0 ){
    fprintf(p->out, "ANALYZE sqlite_master;\n");
  }else if( strncmp(zTable, "sqlite_", 7)==0 ){
    return 0;
  }else{
    fprintf(p->out, "%s;\n", zSql);
  }

  if( strcmp(zType, "table")==0 ){
    sqlite3_stmt *pTableInfo = 0;
    char *zSelect = 0;
    char *zTableInfo = 0;
    char *zTmp = 0;
................................................................................
        zShellStatic = 0;
      }
    }else{
      sqlite3_exec(p->db,
         "SELECT sql FROM "
         "  (SELECT * FROM sqlite_master UNION ALL"
         "   SELECT * FROM sqlite_temp_master) "
         "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'"
         "ORDER BY substr(type,2,1), name",
         callback, &data, &zErrMsg
      );
    }
    if( zErrMsg ){
      fprintf(stderr,"Error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
................................................................................
    char **azResult;
    int nRow, rc;
    char *zErrMsg;
    open_db(p);
    if( nArg==1 ){
      rc = sqlite3_get_table(p->db,
        "SELECT name FROM sqlite_master "
        "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'"
        "UNION ALL "
        "SELECT name FROM sqlite_temp_master "
        "WHERE type IN ('table','view') "
        "ORDER BY 1",
        &azResult, &nRow, 0, &zErrMsg
      );
    }else{
................................................................................
    data.zDbFilename = 0;
#endif
  }
  if( i<argc ){
    zFirstCmd = argv[i++];
  }
  data.out = stdout;

#ifdef SQLITE_OMIT_MEMORYDB
  if( data.zDbFilename==0 ){
    fprintf(stderr,"%s: no database filename specified\n", argv[0]);
    exit(1);
  }
#endif

  /* Go ahead and open the database file if it already exists.  If the
  ** file does not exist, delay opening it.  This prevents empty database
  ** files from being created if a user mistypes the database name argument
  ** to the sqlite command-line tool.
  */
  if( access(data.zDbFilename, 0)==0 ){

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

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
369
370
371
372
373
374
375
376
377

378
379
380
381
382
383
384
...
460
461
462
463
464
465
466
467
468
469





470
471


472
473
474
475
476
477
478
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite3.h,v 1.9 2005/09/01 06:07:56 rmsimpson Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................

/*
** The version of the SQLite library.
*/
#ifdef SQLITE_VERSION
# undef SQLITE_VERSION
#endif
#define SQLITE_VERSION         "3.2.5"

/*
** The format of the version string is "X.Y.Z<trailing string>", where
** X is the major version number, Y is the minor version number and Z
** is the release number. The trailing string is often "alpha" or "beta".
** For example "3.1.1beta".
**
................................................................................
** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
** version 3.1.1 or greater at compile time, programs may use the test 
** (SQLITE_VERSION_NUMBER>=3001001).
*/
#ifdef SQLITE_VERSION_NUMBER
# undef SQLITE_VERSION_NUMBER
#endif
#define SQLITE_VERSION_NUMBER 3002005

/*
** The version string is also compiled into the library so that a program
** can check to make sure that the lib*.a file and the *.h file are from
** the same version.  The sqlite3_libversion() function returns a pointer
** to the sqlite3_version variable - useful in DLLs which cannot access
** global variables.
................................................................................
**
** For example, so some string variable contains text as follows:
**
**      char *zText = "It's a happy day!";
**
** We can use this text in an SQL statement as follows:
**
**      sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')",
**          callback1, 0, 0, zText);

**
** Because the %q format string is used, the '\'' character in zText
** is escaped and the SQL generated is as follows:
**
**      INSERT INTO table1 VALUES('It''s a happy day!')
**
** This is correct.  Had we used %s instead of %q, the generated SQL
................................................................................
** following constants:
*/
/* #define SQLITE_OK  0   // Allow access (This is actually defined above) */
#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */

/*
** Register a function that is called at every invocation of sqlite3_exec()
** or sqlite3_prepare().  This function can be used (for example) to generate
** a log file of all SQL executed against a database.





*/
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);



/*
** This routine configures a callback function - the progress callback - that
** is invoked periodically during long running calls to sqlite3_exec(),
** sqlite3_step() and sqlite3_get_table(). An example use for this API is to 
** keep a GUI updated during a large query.
**







|







 







|







 







|







 







|
|
>







 







|
|
|
>
>
>
>
>


>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite3.h,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................

/*
** The version of the SQLite library.
*/
#ifdef SQLITE_VERSION
# undef SQLITE_VERSION
#endif
#define SQLITE_VERSION         "3.2.7"

/*
** The format of the version string is "X.Y.Z<trailing string>", where
** X is the major version number, Y is the minor version number and Z
** is the release number. The trailing string is often "alpha" or "beta".
** For example "3.1.1beta".
**
................................................................................
** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
** version 3.1.1 or greater at compile time, programs may use the test 
** (SQLITE_VERSION_NUMBER>=3001001).
*/
#ifdef SQLITE_VERSION_NUMBER
# undef SQLITE_VERSION_NUMBER
#endif
#define SQLITE_VERSION_NUMBER 3002007

/*
** The version string is also compiled into the library so that a program
** can check to make sure that the lib*.a file and the *.h file are from
** the same version.  The sqlite3_libversion() function returns a pointer
** to the sqlite3_version variable - useful in DLLs which cannot access
** global variables.
................................................................................
**
** For example, so some string variable contains text as follows:
**
**      char *zText = "It's a happy day!";
**
** We can use this text in an SQL statement as follows:
**
**      char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText);
**      sqlite3_exec(db, z, callback1, 0, 0);
**      sqlite3_free(z);
**
** Because the %q format string is used, the '\'' character in zText
** is escaped and the SQL generated is as follows:
**
**      INSERT INTO table1 VALUES('It''s a happy day!')
**
** This is correct.  Had we used %s instead of %q, the generated SQL
................................................................................
** following constants:
*/
/* #define SQLITE_OK  0   // Allow access (This is actually defined above) */
#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */

/*
** Register a function for tracing SQL command evaluation.  The function
** registered by sqlite3_trace() is invoked at the first sqlite3_step()
** for the evaluation of an SQL statement.  The function registered by
** sqlite3_profile() runs at the end of each SQL statement and includes
** information on how long that statement ran.
**
** The sqlite3_profile() API is currently considered experimental and
** is subject to change.
*/
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
void *sqlite3_profile(sqlite3*,
   void(*xProfile)(void*,const char*,sqlite_uint64), void*);

/*
** This routine configures a callback function - the progress callback - that
** is invoked periodically during long running calls to sqlite3_exec(),
** sqlite3_step() and sqlite3_get_table(). An example use for this API is to 
** keep a GUI updated during a large query.
**

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

7
8
9
10
11
12
13
14
15
16
17
18











19
20
21
22
23
24
25
...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
...
416
417
418
419
420
421
422
423
424


425
426
427
428
429
430
431
...
507
508
509
510
511
512
513
514

515
516
517
518
519
520
521
...
547
548
549
550
551
552
553

554
555
556
557








558
559
560
561
562
563
564
...
772
773
774
775
776
777
778











































779
780
781
782
783
784
785
...
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
...
870
871
872
873
874
875
876

877
878
879
880
881
882
883
...
895
896
897
898
899
900
901
902
903
904
905
906
907


908
909
910
911
912
913
914
...
940
941
942
943
944
945
946

947
948
949
950
951
952
953
954
955
956
957
958
....
1014
1015
1016
1017
1018
1019
1020
1021
1022

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034










1035
1036
1037
1038
1039




1040
1041
1042
1043
1044
1045

1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056







1057
1058
1059
1060
1061

1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
....
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
....
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
....
1315
1316
1317
1318
1319
1320
1321













1322
1323
1324
1325
1326
1327
1328
....
1342
1343
1344
1345
1346
1347
1348

1349
1350
1351
1352
1353
1354
1355
....
1392
1393
1394
1395
1396
1397
1398

1399
1400
1401
1402
1403
1404
1405
....
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
....
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
....
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.8 2005/09/01 06:07:56 rmsimpson Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_












/*
** These #defines should enable >2GB file support on Posix if the
** underlying operating system supports it.  If the OS lacks
** large file support, or if the OS is windows, these should be no-ops.
**
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
** on the compiler command line.  This is necessary if you are compiling
................................................................................
** an array.
*/
#define ArraySize(X)    (sizeof(X)/sizeof(X[0]))

/*
** Forward references to structures
*/
typedef struct AggExpr AggExpr;
typedef struct AuthContext AuthContext;
typedef struct CollSeq CollSeq;
typedef struct Column Column;
typedef struct Db Db;
typedef struct Expr Expr;
typedef struct ExprList ExprList;
typedef struct FKey FKey;
................................................................................
  struct sqlite3InitInfo {      /* Information used during initialization */
    int iDb;                    /* When back is being initialized */
    int newTnum;                /* Rootpage of table being initialized */
    u8 busy;                    /* TRUE if currently initializing */
  } init;
  struct Vdbe *pVdbe;           /* List of active virtual machines */
  int activeVdbeCnt;            /* Number of vdbes currently executing */
  void (*xTrace)(void*,const char*);     /* Trace function */
  void *pTraceArg;                       /* Argument to the trace function */


  void *pCommitArg;             /* Argument to xCommitCallback() */   
  int (*xCommitCallback)(void*);/* Invoked at every commit. */
  void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
  void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
  void *pCollNeededArg;
  sqlite3_value *pValue;        /* Value used for transient conversions */
  sqlite3_value *pErr;          /* Most recent error message */
................................................................................
  void (*xFinalize)(sqlite3_context*);                /* Aggregate finializer */
  char zName[1];       /* SQL name of the function.  MUST BE LAST */
};

/*
** Possible values for FuncDef.flags
*/
#define SQLITE_FUNC_LIKEOPT  0x01    /* Candidate for the LIKE optimization */


/*
** information about each column of an SQL table is held in an instance
** of this structure.
*/
struct Column {
  char *zName;     /* Name of this column */
................................................................................
** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
** collating sequence is undefined.  Indices built on an undefined
** collating sequence may not be read or written.
*/
struct CollSeq {
  char *zName;         /* Name of the collating sequence, UTF-8 encoded */
  u8 enc;              /* Text encoding handled by xCmp() */

  void *pUser;         /* First argument to xCmp() */
  int (*xCmp)(void*,int, const void*, int, const void*);
};









/*
** A sort order can be either ASC or DESC.
*/
#define SQLITE_SO_ASC       0  /* Sort in ascending order */
#define SQLITE_SO_DESC      1  /* Sort in ascending order */

/*
................................................................................
*/
struct Token {
  const unsigned char *z; /* Text of the token.  Not NULL-terminated! */
  unsigned dyn  : 1;      /* True for malloced memory, false for static */
  unsigned n    : 31;     /* Number of characters in this token */
};












































/*
** Each node of an expression in the parse tree is an instance
** of this structure.
**
** Expr.op is the opcode.  The integer parser token codes are reused
** as opcodes here.  For example, the parser defines TK_GE to be an integer
** code representing the ">=" operator.  This same integer code is reused
................................................................................
  Expr *pLeft, *pRight;  /* Left and right subnodes */
  ExprList *pList;       /* A list of expressions used as function arguments
                         ** or in "<expr> IN (<expr-list)" */
  Token token;           /* An operand token */
  Token span;            /* Complete text of the expression */
  int iTable, iColumn;   /* When op==TK_COLUMN, then this expr node means the
                         ** iColumn-th field of the iTable-th table. */
  int iAgg;              /* When op==TK_COLUMN and pParse->fillAgg==FALSE, pull
                         ** result from the iAgg-th element of the aggregator */
  int iAggCtx;           /* The value to pass as P1 of OP_AggGet. */
  Select *pSelect;       /* When the expression is a sub-select.  Also the
                         ** right side of "<expr> IN (<select>)" */
  Table *pTab;           /* Table for OP_Column expressions. */
};

/*
** The following are the meanings of bits in the Expr.flags field.
*/
#define EP_FromJoin     0x01  /* Originated in ON or USING clause of a join */
#define EP_Agg          0x02  /* Contains one or more aggregate functions */
#define EP_Resolved     0x04  /* IDs have been resolved to COLUMNs */
#define EP_Error        0x08  /* Expression contains one or more errors */
#define EP_Not          0x10  /* Operator preceeded by NOT */
#define EP_VarSelect    0x20  /* pSelect is correlated, not constant */
#define EP_Dequoted     0x40  /* True if the string has been dequoted */

/*
** These macros can be used to test, set, or clear bits in the 
** Expr.flags field.
*/
................................................................................
** list of "ID = expr" items in an UPDATE.  A list of expressions can
** also be used as the argument to a function, in which case the a.zName
** field is not used.
*/
struct ExprList {
  int nExpr;             /* Number of expressions on the list */
  int nAlloc;            /* Number of entries allocated below */

  struct ExprList_item {
    Expr *pExpr;           /* The list of expressions */
    char *zName;           /* Token associated with this expression */
    u8 sortOrder;          /* 1 for DESC or 0 for ASC */
    u8 isAgg;              /* True if this is an aggregate like count(*) */
    u8 done;               /* A flag to indicate when processing is finished */
  } *a;                  /* One entry for each expression */
................................................................................
** column names after a table name in an INSERT statement.  In the statement
**
**     INSERT INTO t(a,b,c) ...
**
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
*/
struct IdList {
  int nId;         /* Number of identifiers on the list */
  int nAlloc;      /* Number of entries allocated for a[] below */
  struct IdList_item {
    char *zName;      /* Name of the identifier */
    int idx;          /* Index in some Table.aCol[] of a column named zName */
  } *a;


};

/*
** The bitmask datatype defined below is used for various optimizations.
*/
typedef unsigned int Bitmask;

................................................................................
  } a[1];             /* One entry for each identifier on the list */
};

/*
** Permitted values of the SrcList.a.jointype field
*/
#define JT_INNER     0x0001    /* Any kind of inner or cross join */

#define JT_NATURAL   0x0002    /* True for a "natural" join */
#define JT_LEFT      0x0004    /* Left outer join */
#define JT_RIGHT     0x0008    /* Right outer join */
#define JT_OUTER     0x0010    /* The "OUTER" keyword is present */
#define JT_ERROR     0x0020    /* unknown or unsupported join type */

/*
** For each nested loop in a WHERE clause implementation, the WhereInfo
** structure contains a single instance of this structure.  This structure
** is intended to be private the the where.c module and should not be
** access or modified by other modules.
*/
................................................................................
struct NameContext {
  Parse *pParse;       /* The parser */
  SrcList *pSrcList;   /* One or more tables used to resolve names */
  ExprList *pEList;    /* Optional list of named expressions */
  int nRef;            /* Number of names resolved by this context */
  int nErr;            /* Number of errors encountered while resolving names */
  u8 allowAgg;         /* Aggregate functions allowed here */
  u8 hasAgg;
  int nDepth;          /* Depth of subquery recursion. 1 for no recursion */

  NameContext *pNext;  /* Next outer name context.  NULL for outermost */
};

/*
** An instance of the following structure contains all information
** needed to generate code for a single SELECT statement.
**
** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
** If there is a LIMIT clause, the parser sets nLimit to the value of the
** limit and nOffset to the value of the offset (or 0 if there is not
** offset).  But later on, nLimit and nOffset become the memory locations
** in the VDBE that record the limit and offset counters.










*/
struct Select {
  ExprList *pEList;      /* The fields of the result */
  u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  u8 isDistinct;         /* True if the DISTINCT keyword is present */




  SrcList *pSrc;         /* The FROM clause */
  Expr *pWhere;          /* The WHERE clause */
  ExprList *pGroupBy;    /* The GROUP BY clause */
  Expr *pHaving;         /* The HAVING clause */
  ExprList *pOrderBy;    /* The ORDER BY clause */
  Select *pPrior;        /* Prior select in a compound select statement */

  Expr *pLimit;          /* LIMIT expression. NULL means not used. */
  Expr *pOffset;         /* OFFSET expression. NULL means not used. */
  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
  IdList **ppOpenVirtual;/* OP_OpenVirtual addresses used by multi-selects */
  u8 isResolved;         /* True once sqlite3SelectResolve() has run. */
  u8 isAgg;              /* True if this is an aggregate query */
};

/*
** The results of a select can be distributed in several ways.
*/







#define SRT_Callback     1  /* Invoke a callback with each row of result */
#define SRT_Mem          2  /* Store result in a memory cell */
#define SRT_Set          3  /* Store result as unique keys in a table */
#define SRT_Union        5  /* Store result as keys in a table */
#define SRT_Except       6  /* Remove result from a UNION table */

#define SRT_Table        7  /* Store result as data with a unique key */
#define SRT_TempTable    8  /* Store result in a trasient table */
#define SRT_Discard      9  /* Do not save the results anywhere */
#define SRT_Sorter      10  /* Store results in the sorter */

#define SRT_Subroutine  11  /* Call a subroutine to handle results */
#define SRT_Exists      12  /* Put 0 or 1 in a memory cell */

/*
** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")
** we have to do some additional analysis of expressions.  An instance
** of the following structure holds information about a single subexpression
** somewhere in the SELECT statement.  An array of these structures holds
** all the information we need to generate code for aggregate
** expressions.
**
** Note that when analyzing a SELECT containing aggregates, both
** non-aggregate field variables and aggregate functions are stored
** in the AggExpr array of the Parser structure.
**
** The pExpr field points to an expression that is part of either the
** field list, the GROUP BY clause, the HAVING clause or the ORDER BY
** clause.  The expression will be freed when those clauses are cleaned
** up.  Do not try to delete the expression attached to AggExpr.pExpr.
**
** If AggExpr.pExpr==0, that means the expression is "count(*)".
*/
struct AggExpr {
  int isAgg;        /* if TRUE contains an aggregate function */
  Expr *pExpr;      /* The expression */
  FuncDef *pFunc;   /* Information about the aggregate function */
};

/*
** An SQL parser context.  A copy of this structure is passed through
** the parser and down into all the parser action routine in order to
** carry around information that is global to the entire parse.
**
** The structure is divided into two parts.  When the parser and code
................................................................................
  int rc;              /* Return code from execution */
  char *zErrMsg;       /* An error message */
  Vdbe *pVdbe;         /* An engine for executing database bytecode */
  u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */
  u8 nameClash;        /* A permanent table name clashes with temp table name */
  u8 checkSchema;      /* Causes schema cookie check after an error */
  u8 nested;           /* Number of nested calls to the parser/code generator */
  u8 fillAgg;          /* If true, ignore the Expr.iAgg field. Normally false */
  int nErr;            /* Number of errors seen */
  int nTab;            /* Number of previously allocated VDBE cursors */
  int nMem;            /* Number of memory cells used so far */
  int nSet;            /* Number of sets used so far */
  u32 writeMask;       /* Start a write transaction on these databases */
  u32 cookieMask;      /* Bitmask of schema verified databases */
  int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
................................................................................
  Token sLastToken;    /* The last token parsed */
  const char *zSql;    /* All SQL text */
  const char *zTail;   /* All SQL text past the last semicolon parsed */
  Table *pNewTable;    /* A table being constructed by CREATE TABLE */
  Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
  TriggerStack *trigStack;  /* Trigger actions being coded */
  const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
  int nAgg;            /* Number of aggregate expressions */
  AggExpr *aAgg;       /* An array of aggregate expressions */
  int nMaxDepth;       /* Maximum depth of subquery recursion */
};

/*
** An instance of the following structure can be declared on a stack and used
** to save the Parse.zAuthContext value so that it can be restored later.
*/
struct AuthContext {
................................................................................
/*
 * This global flag is set for performance testing of triggers. When it is set
 * SQLite will perform the overhead of building new and old trigger references 
 * even when no triggers exist
 */
extern int sqlite3_always_code_trigger_setup;














/*
** Internal function prototypes
*/
int sqlite3StrICmp(const char *, const char *);
int sqlite3StrNICmp(const char *, const char *, int);
int sqlite3HashNoCase(const char *, int);
int sqlite3IsNumber(const char*, int*, u8);
................................................................................
  void sqlite3Free(void*);
  void *sqlite3Realloc(void*,int);
  char *sqlite3StrDup(const char*);
  char *sqlite3StrNDup(const char*, int);
# define sqlite3CheckMemory(a,b)
# define sqlite3MallocX sqlite3Malloc
#endif

void sqlite3FreeX(void*);
void *sqlite3MallocX(int);
char *sqlite3MPrintf(const char*, ...);
char *sqlite3VMPrintf(const char*, va_list);
void sqlite3DebugPrintf(const char*, ...);
void *sqlite3TextToPtr(const char*);
void sqlite3SetString(char **, ...);
................................................................................
#else
# define sqlite3ViewGetColumnNames(A,B) 0
#endif

void sqlite3DropTable(Parse*, SrcList*, int);
void sqlite3DeleteTable(sqlite3*, Table*);
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);

IdList *sqlite3IdListAppend(IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*);
SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
void sqlite3SrcListAddAlias(SrcList*, Token*);
void sqlite3SrcListAssignCursors(Parse*, SrcList*);
void sqlite3IdListDelete(IdList*);
void sqlite3SrcListDelete(SrcList*);
................................................................................
int sqlite3RunVacuum(char**, sqlite3*);
char *sqlite3NameFromToken(Token*);
int sqlite3ExprCheck(Parse*, Expr*, int, int*);
int sqlite3ExprCompare(Expr*, Expr*);
int sqliteFuncId(Token*);
int sqlite3ExprResolveNames(NameContext *, Expr *);
int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);

Vdbe *sqlite3GetVdbe(Parse*);
void sqlite3Randomness(int, void*);
void sqlite3RollbackAll(sqlite3*);
void sqlite3CodeVerifySchema(Parse*, int);
void sqlite3BeginTransaction(Parse*, int);
void sqlite3CommitTransaction(Parse*);
void sqlite3RollbackTransaction(Parse*);
................................................................................
void sqlite3VdbeSetChanges(sqlite3 *, int);
void sqlite3utf16Substr(sqlite3_context *,int,sqlite3_value **);

const void *sqlite3ValueText(sqlite3_value*, u8);
int sqlite3ValueBytes(sqlite3_value*, u8);
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
void sqlite3ValueFree(sqlite3_value*);
sqlite3_value *sqlite3ValueNew();
sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
extern const unsigned char sqlite3UpperToLower[];
void sqlite3RootPageMoved(Db*, int, int);
void sqlite3Reindex(Parse*, Token*, Token*);
void sqlite3AlterFunctions(sqlite3*);
................................................................................
char sqlite3AffinityType(const Token*);
void sqlite3Analyze(Parse*, Token*, Token*);
int sqlite3InvokeBusyHandler(BusyHandler*);
int sqlite3FindDb(sqlite3*, Token*);
void sqlite3AnalysisLoad(sqlite3*,int iDB);
void sqlite3DefaultRowEst(Index*);
void sqlite3RegisterLikeFunctions(sqlite3*, int);
int sqlite3IsLikeFunction(sqlite3*,Expr*,char*);

#ifdef SQLITE_SSE
#include "sseInt.h"
#endif

#endif







|




>
>
>
>
>
>
>
>
>
>
>







 







|







 







|
|
>
>







 







|
>







 







>




>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|












|







 







>







 







<
<




>
>







 







>
|
|
|
|
|







 







|

>












>
>
>
>
>
>
>
>
>
>





>
>
>
>






>



|
<
<





>
>
>
>
>
>
>
|
|
<
<
<
>
|
<
<
<
>
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<







 







<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







>







 







>







 







|







 







|






7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
...
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
...
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
...
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
...
962
963
964
965
966
967
968


969
970
971
972
973
974
975
976
977
978
979
980
981
....
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
....
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133


1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147



1148
1149



1150
1151
1152

























1153
1154
1155
1156
1157
1158
1159
....
1166
1167
1168
1169
1170
1171
1172

1173
1174
1175
1176
1177
1178
1179
....
1192
1193
1194
1195
1196
1197
1198



1199
1200
1201
1202
1203
1204
1205
....
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
....
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
....
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
....
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
....
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
....
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_

/*
** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
** Setting NDEBUG makes the code smaller and run faster.  So the following
** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
** option is set.  Thus NDEBUG becomes an opt-in rather than an opt-out
** feature.
*/
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
# define NDEBUG 1
#endif

/*
** These #defines should enable >2GB file support on Posix if the
** underlying operating system supports it.  If the OS lacks
** large file support, or if the OS is windows, these should be no-ops.
**
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
** on the compiler command line.  This is necessary if you are compiling
................................................................................
** an array.
*/
#define ArraySize(X)    (sizeof(X)/sizeof(X[0]))

/*
** Forward references to structures
*/
typedef struct AggInfo AggInfo;
typedef struct AuthContext AuthContext;
typedef struct CollSeq CollSeq;
typedef struct Column Column;
typedef struct Db Db;
typedef struct Expr Expr;
typedef struct ExprList ExprList;
typedef struct FKey FKey;
................................................................................
  struct sqlite3InitInfo {      /* Information used during initialization */
    int iDb;                    /* When back is being initialized */
    int newTnum;                /* Rootpage of table being initialized */
    u8 busy;                    /* TRUE if currently initializing */
  } init;
  struct Vdbe *pVdbe;           /* List of active virtual machines */
  int activeVdbeCnt;            /* Number of vdbes currently executing */
  void (*xTrace)(void*,const char*);        /* Trace function */
  void *pTraceArg;                          /* Argument to the trace function */
  void (*xProfile)(void*,const char*,u64);  /* Profiling function */
  void *pProfileArg;                        /* Argument to profile function */
  void *pCommitArg;             /* Argument to xCommitCallback() */   
  int (*xCommitCallback)(void*);/* Invoked at every commit. */
  void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
  void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
  void *pCollNeededArg;
  sqlite3_value *pValue;        /* Value used for transient conversions */
  sqlite3_value *pErr;          /* Most recent error message */
................................................................................
  void (*xFinalize)(sqlite3_context*);                /* Aggregate finializer */
  char zName[1];       /* SQL name of the function.  MUST BE LAST */
};

/*
** Possible values for FuncDef.flags
*/
#define SQLITE_FUNC_LIKE   0x01  /* Candidate for the LIKE optimization */
#define SQLITE_FUNC_CASE   0x02  /* Case-sensitive LIKE-type function */

/*
** information about each column of an SQL table is held in an instance
** of this structure.
*/
struct Column {
  char *zName;     /* Name of this column */
................................................................................
** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
** collating sequence is undefined.  Indices built on an undefined
** collating sequence may not be read or written.
*/
struct CollSeq {
  char *zName;         /* Name of the collating sequence, UTF-8 encoded */
  u8 enc;              /* Text encoding handled by xCmp() */
  u8 type;             /* One of the SQLITE_COLL_... values below */
  void *pUser;         /* First argument to xCmp() */
  int (*xCmp)(void*,int, const void*, int, const void*);
};

/*
** Allowed values of CollSeq flags:
*/
#define SQLITE_COLL_BINARY  1  /* The default memcmp() collating sequence */
#define SQLITE_COLL_NOCASE  2  /* The built-in NOCASE collating sequence */
#define SQLITE_COLL_REVERSE 3  /* The built-in REVERSE collating sequence */
#define SQLITE_COLL_USER    0  /* Any other user-defined collating sequence */

/*
** A sort order can be either ASC or DESC.
*/
#define SQLITE_SO_ASC       0  /* Sort in ascending order */
#define SQLITE_SO_DESC      1  /* Sort in ascending order */

/*
................................................................................
*/
struct Token {
  const unsigned char *z; /* Text of the token.  Not NULL-terminated! */
  unsigned dyn  : 1;      /* True for malloced memory, false for static */
  unsigned n    : 31;     /* Number of characters in this token */
};

/*
** An instance of this structure contains information needed to generate
** code for a SELECT that contains aggregate functions.
**
** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
** pointer to this structure.  The Expr.iColumn field is the index in
** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
** code for that node.
**
** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
** original Select structure that describes the SELECT statement.  These
** fields do not need to be freed when deallocating the AggInfo structure.
*/
struct AggInfo {
  u8 directMode;          /* Direct rendering mode means take data directly
                          ** from source tables rather than from accumulators */
  u8 useSortingIdx;       /* In direct mode, reference the sorting index rather
                          ** than the source table */
  int sortingIdx;         /* Cursor number of the sorting index */
  ExprList *pGroupBy;     /* The group by clause */
  int nSortingColumn;     /* Number of columns in the sorting index */
  struct AggInfo_col {    /* For each column used in source tables */
    int iTable;              /* Cursor number of the source table */
    int iColumn;             /* Column number within the source table */
    int iSorterColumn;       /* Column number in the sorting index */
    int iMem;                /* Memory location that acts as accumulator */
    Expr *pExpr;             /* The original expression */
  } *aCol;
  int nColumn;            /* Number of used entries in aCol[] */
  int nColumnAlloc;       /* Number of slots allocated for aCol[] */
  int nAccumulator;       /* Number of columns that show through to the output.
                          ** Additional columns are used only as parameters to
                          ** aggregate functions */
  struct AggInfo_func {   /* For each aggregate function */
    Expr *pExpr;             /* Expression encoding the function */
    FuncDef *pFunc;          /* The aggregate function implementation */
    int iMem;                /* Memory location that acts as accumulator */
    int iDistinct;           /* Virtual table used to enforce DISTINCT */
  } *aFunc;
  int nFunc;              /* Number of entries in aFunc[] */
  int nFuncAlloc;         /* Number of slots allocated for aFunc[] */
};

/*
** Each node of an expression in the parse tree is an instance
** of this structure.
**
** Expr.op is the opcode.  The integer parser token codes are reused
** as opcodes here.  For example, the parser defines TK_GE to be an integer
** code representing the ">=" operator.  This same integer code is reused
................................................................................
  Expr *pLeft, *pRight;  /* Left and right subnodes */
  ExprList *pList;       /* A list of expressions used as function arguments
                         ** or in "<expr> IN (<expr-list)" */
  Token token;           /* An operand token */
  Token span;            /* Complete text of the expression */
  int iTable, iColumn;   /* When op==TK_COLUMN, then this expr node means the
                         ** iColumn-th field of the iTable-th table. */
  AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  int iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  int iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  Select *pSelect;       /* When the expression is a sub-select.  Also the
                         ** right side of "<expr> IN (<select>)" */
  Table *pTab;           /* Table for OP_Column expressions. */
};

/*
** The following are the meanings of bits in the Expr.flags field.
*/
#define EP_FromJoin     0x01  /* Originated in ON or USING clause of a join */
#define EP_Agg          0x02  /* Contains one or more aggregate functions */
#define EP_Resolved     0x04  /* IDs have been resolved to COLUMNs */
#define EP_Error        0x08  /* Expression contains one or more errors */
#define EP_Distinct     0x10  /* Aggregate function with DISTINCT keyword */
#define EP_VarSelect    0x20  /* pSelect is correlated, not constant */
#define EP_Dequoted     0x40  /* True if the string has been dequoted */

/*
** These macros can be used to test, set, or clear bits in the 
** Expr.flags field.
*/
................................................................................
** list of "ID = expr" items in an UPDATE.  A list of expressions can
** also be used as the argument to a function, in which case the a.zName
** field is not used.
*/
struct ExprList {
  int nExpr;             /* Number of expressions on the list */
  int nAlloc;            /* Number of entries allocated below */
  int iECursor;          /* VDBE Cursor associated with this ExprList */
  struct ExprList_item {
    Expr *pExpr;           /* The list of expressions */
    char *zName;           /* Token associated with this expression */
    u8 sortOrder;          /* 1 for DESC or 0 for ASC */
    u8 isAgg;              /* True if this is an aggregate like count(*) */
    u8 done;               /* A flag to indicate when processing is finished */
  } *a;                  /* One entry for each expression */
................................................................................
** column names after a table name in an INSERT statement.  In the statement
**
**     INSERT INTO t(a,b,c) ...
**
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
*/
struct IdList {


  struct IdList_item {
    char *zName;      /* Name of the identifier */
    int idx;          /* Index in some Table.aCol[] of a column named zName */
  } *a;
  int nId;         /* Number of identifiers on the list */
  int nAlloc;      /* Number of entries allocated for a[] below */
};

/*
** The bitmask datatype defined below is used for various optimizations.
*/
typedef unsigned int Bitmask;

................................................................................
  } a[1];             /* One entry for each identifier on the list */
};

/*
** Permitted values of the SrcList.a.jointype field
*/
#define JT_INNER     0x0001    /* Any kind of inner or cross join */
#define JT_CROSS     0x0002    /* Explicit use of the CROSS keyword */
#define JT_NATURAL   0x0004    /* True for a "natural" join */
#define JT_LEFT      0x0008    /* Left outer join */
#define JT_RIGHT     0x0010    /* Right outer join */
#define JT_OUTER     0x0020    /* The "OUTER" keyword is present */
#define JT_ERROR     0x0040    /* unknown or unsupported join type */

/*
** For each nested loop in a WHERE clause implementation, the WhereInfo
** structure contains a single instance of this structure.  This structure
** is intended to be private the the where.c module and should not be
** access or modified by other modules.
*/
................................................................................
struct NameContext {
  Parse *pParse;       /* The parser */
  SrcList *pSrcList;   /* One or more tables used to resolve names */
  ExprList *pEList;    /* Optional list of named expressions */
  int nRef;            /* Number of names resolved by this context */
  int nErr;            /* Number of errors encountered while resolving names */
  u8 allowAgg;         /* Aggregate functions allowed here */
  u8 hasAgg;           /* True if aggregates are seen */
  int nDepth;          /* Depth of subquery recursion. 1 for no recursion */
  AggInfo *pAggInfo;   /* Information about aggregates at this level */
  NameContext *pNext;  /* Next outer name context.  NULL for outermost */
};

/*
** An instance of the following structure contains all information
** needed to generate code for a single SELECT statement.
**
** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
** If there is a LIMIT clause, the parser sets nLimit to the value of the
** limit and nOffset to the value of the offset (or 0 if there is not
** offset).  But later on, nLimit and nOffset become the memory locations
** in the VDBE that record the limit and offset counters.
**
** addrOpenVirt[] entries contain the address of OP_OpenVirtual opcodes.
** These addresses must be stored so that we can go back and fill in
** the P3_KEYINFO and P2 parameters later.  Neither the KeyInfo nor
** the number of columns in P2 can be computed at the same time
** as the OP_OpenVirtual instruction is coded because not
** enough information about the compound query is known at that point.
** The KeyInfo for addrOpenVirt[0] and [1] contains collating sequences
** for the result set.  The KeyInfo for addrOpenVirt[2] contains collating
** sequences for the ORDER BY clause.
*/
struct Select {
  ExprList *pEList;      /* The fields of the result */
  u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  u8 isDistinct;         /* True if the DISTINCT keyword is present */
  u8 isResolved;         /* True once sqlite3SelectResolve() has run. */
  u8 isAgg;              /* True if this is an aggregate query */
  u8 usesVirt;           /* True if uses an OpenVirtual opcode */
  u8 disallowOrderBy;    /* Do not allow an ORDER BY to be attached if TRUE */
  SrcList *pSrc;         /* The FROM clause */
  Expr *pWhere;          /* The WHERE clause */
  ExprList *pGroupBy;    /* The GROUP BY clause */
  Expr *pHaving;         /* The HAVING clause */
  ExprList *pOrderBy;    /* The ORDER BY clause */
  Select *pPrior;        /* Prior select in a compound select statement */
  Select *pRightmost;    /* Right-most select in a compound select statement */
  Expr *pLimit;          /* LIMIT expression. NULL means not used. */
  Expr *pOffset;         /* OFFSET expression. NULL means not used. */
  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
  int addrOpenVirt[3];   /* OP_OpenVirtual opcodes related to this select */


};

/*
** The results of a select can be distributed in several ways.
*/
#define SRT_Union        1  /* Store result as keys in an index */
#define SRT_Except       2  /* Remove result from a UNION index */
#define SRT_Discard      3  /* Do not save the results anywhere */

/* The ORDER BY clause is ignored for all of the above */
#define IgnorableOrderby(X) (X<=SRT_Discard)

#define SRT_Callback     4  /* Invoke a callback with each row of result */
#define SRT_Mem          5  /* Store result in a memory cell */



#define SRT_Set          6  /* Store non-null results as keys in an index */
#define SRT_Table        7  /* Store result as data with an automatic rowid */



#define SRT_VirtualTab   8  /* Create virtual table and store like SRT_Table */
#define SRT_Subroutine   9  /* Call a subroutine to handle results */
#define SRT_Exists      10  /* Put 0 or 1 in a memory cell */


























/*
** An SQL parser context.  A copy of this structure is passed through
** the parser and down into all the parser action routine in order to
** carry around information that is global to the entire parse.
**
** The structure is divided into two parts.  When the parser and code
................................................................................
  int rc;              /* Return code from execution */
  char *zErrMsg;       /* An error message */
  Vdbe *pVdbe;         /* An engine for executing database bytecode */
  u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */
  u8 nameClash;        /* A permanent table name clashes with temp table name */
  u8 checkSchema;      /* Causes schema cookie check after an error */
  u8 nested;           /* Number of nested calls to the parser/code generator */

  int nErr;            /* Number of errors seen */
  int nTab;            /* Number of previously allocated VDBE cursors */
  int nMem;            /* Number of memory cells used so far */
  int nSet;            /* Number of sets used so far */
  u32 writeMask;       /* Start a write transaction on these databases */
  u32 cookieMask;      /* Bitmask of schema verified databases */
  int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
................................................................................
  Token sLastToken;    /* The last token parsed */
  const char *zSql;    /* All SQL text */
  const char *zTail;   /* All SQL text past the last semicolon parsed */
  Table *pNewTable;    /* A table being constructed by CREATE TABLE */
  Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
  TriggerStack *trigStack;  /* Trigger actions being coded */
  const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */



};

/*
** An instance of the following structure can be declared on a stack and used
** to save the Parse.zAuthContext value so that it can be restored later.
*/
struct AuthContext {
................................................................................
/*
 * This global flag is set for performance testing of triggers. When it is set
 * SQLite will perform the overhead of building new and old trigger references 
 * even when no triggers exist
 */
extern int sqlite3_always_code_trigger_setup;

/*
** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
** builds) or a function call (for debugging).  If it is a function call,
** it allows the operator to set a breakpoint at the spot where database
** corruption is first detected.
*/
#ifdef SQLITE_DEBUG
  extern int sqlite3Corrupt(void);
# define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
#else
# define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
#endif

/*
** Internal function prototypes
*/
int sqlite3StrICmp(const char *, const char *);
int sqlite3StrNICmp(const char *, const char *, int);
int sqlite3HashNoCase(const char *, int);
int sqlite3IsNumber(const char*, int*, u8);
................................................................................
  void sqlite3Free(void*);
  void *sqlite3Realloc(void*,int);
  char *sqlite3StrDup(const char*);
  char *sqlite3StrNDup(const char*, int);
# define sqlite3CheckMemory(a,b)
# define sqlite3MallocX sqlite3Malloc
#endif
void sqlite3ReallocOrFree(void**,int);
void sqlite3FreeX(void*);
void *sqlite3MallocX(int);
char *sqlite3MPrintf(const char*, ...);
char *sqlite3VMPrintf(const char*, va_list);
void sqlite3DebugPrintf(const char*, ...);
void *sqlite3TextToPtr(const char*);
void sqlite3SetString(char **, ...);
................................................................................
#else
# define sqlite3ViewGetColumnNames(A,B) 0
#endif

void sqlite3DropTable(Parse*, SrcList*, int);
void sqlite3DeleteTable(sqlite3*, Table*);
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
int sqlite3ArrayAllocate(void**,int,int);
IdList *sqlite3IdListAppend(IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*);
SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
void sqlite3SrcListAddAlias(SrcList*, Token*);
void sqlite3SrcListAssignCursors(Parse*, SrcList*);
void sqlite3IdListDelete(IdList*);
void sqlite3SrcListDelete(SrcList*);
................................................................................
int sqlite3RunVacuum(char**, sqlite3*);
char *sqlite3NameFromToken(Token*);
int sqlite3ExprCheck(Parse*, Expr*, int, int*);
int sqlite3ExprCompare(Expr*, Expr*);
int sqliteFuncId(Token*);
int sqlite3ExprResolveNames(NameContext *, Expr *);
int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
Vdbe *sqlite3GetVdbe(Parse*);
void sqlite3Randomness(int, void*);
void sqlite3RollbackAll(sqlite3*);
void sqlite3CodeVerifySchema(Parse*, int);
void sqlite3BeginTransaction(Parse*, int);
void sqlite3CommitTransaction(Parse*);
void sqlite3RollbackTransaction(Parse*);
................................................................................
void sqlite3VdbeSetChanges(sqlite3 *, int);
void sqlite3utf16Substr(sqlite3_context *,int,sqlite3_value **);

const void *sqlite3ValueText(sqlite3_value*, u8);
int sqlite3ValueBytes(sqlite3_value*, u8);
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
void sqlite3ValueFree(sqlite3_value*);
sqlite3_value *sqlite3ValueNew(void);
sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
extern const unsigned char sqlite3UpperToLower[];
void sqlite3RootPageMoved(Db*, int, int);
void sqlite3Reindex(Parse*, Token*, Token*);
void sqlite3AlterFunctions(sqlite3*);
................................................................................
char sqlite3AffinityType(const Token*);
void sqlite3Analyze(Parse*, Token*, Token*);
int sqlite3InvokeBusyHandler(BusyHandler*);
int sqlite3FindDb(sqlite3*, Token*);
void sqlite3AnalysisLoad(sqlite3*,int iDB);
void sqlite3DefaultRowEst(Index*);
void sqlite3RegisterLikeFunctions(sqlite3*, int);
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);

#ifdef SQLITE_SSE
#include "sseInt.h"
#endif

#endif

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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
80
81
82
83
84
85
86

87
88
89
90
91
92
93
...
186
187
188
189
190
191
192



193
194
195
196
197
198
199
...
242
243
244
245
246
247
248



















249
250
251
252
253
254
255
...
585
586
587
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
...
865
866
867
868
869
870
871






































872
873
874
875
876
877
878
...
886
887
888
889
890
891
892


























































































































































































893
894
895
896
897
898
899
....
1296
1297
1298
1299
1300
1301
1302































1303
1304
1305
1306
1307
1308
1309
....
1360
1361
1362
1363
1364
1365
1366







































1367
1368
1369
1370
1371
1372
1373
....
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
....
1475
1476
1477
1478
1479
1480
1481

1482
1483
1484
1485
1486
1487

1488
1489
1490
1491
1492
1493
1494
....
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.8 2005/09/01 06:07:56 rmsimpson Exp $
*/
#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */

#include "sqliteInt.h"
#include "hash.h"
#include "tcl.h"
#include <stdlib.h>
................................................................................
typedef struct SqliteDb SqliteDb;
struct SqliteDb {
  sqlite3 *db;               /* The "real" database structure */
  Tcl_Interp *interp;        /* The interpreter used for this database */
  char *zBusy;               /* The busy callback routine */
  char *zCommit;             /* The commit hook callback routine */
  char *zTrace;              /* The trace callback routine */

  char *zProgress;           /* The progress callback routine */
  char *zAuth;               /* The authorization callback routine */
  char *zNull;               /* Text to substitute for an SQL NULL value */
  SqlFunc *pFunc;            /* List of SQL functions */
  SqlCollate *pCollate;      /* List of SQL collation functions */
  int rc;                    /* Return code of most recent sqlite3_exec() */
  Tcl_Obj *pCollateNeeded;   /* Collation needed script */
................................................................................
  }
  if( pDb->zBusy ){
    Tcl_Free(pDb->zBusy);
  }
  if( pDb->zTrace ){
    Tcl_Free(pDb->zTrace);
  }



  if( pDb->zAuth ){
    Tcl_Free(pDb->zAuth);
  }
  if( pDb->zNull ){
    Tcl_Free(pDb->zNull);
  }
  Tcl_Free((char*)pDb);
................................................................................
  Tcl_DStringInit(&str);
  Tcl_DStringAppend(&str, pDb->zTrace, -1);
  Tcl_DStringAppendElement(&str, zSql);
  Tcl_Eval(pDb->interp, Tcl_DStringValue(&str));
  Tcl_DStringFree(&str);
  Tcl_ResetResult(pDb->interp);
}




















/*
** This routine is called when a transaction is committed.  The
** TCL script in pDb->zCommit is executed.  If it returns non-zero or
** if it throws an exception, the transaction is rolled back instead
** of being committed.
*/
................................................................................
  int rc = TCL_OK;
  static const char *DB_strs[] = {
    "authorizer",         "busy",              "cache",
    "changes",            "close",             "collate",
    "collation_needed",   "commit_hook",       "complete",
    "copy",               "errorcode",         "eval",
    "function",           "last_insert_rowid", "nullvalue",
    "onecolumn",          "progress",          "rekey",
    "timeout",            "total_changes",     "trace",
    "transaction",        "version",           0

  };
  enum DB_enum {
    DB_AUTHORIZER,        DB_BUSY,             DB_CACHE,
    DB_CHANGES,           DB_CLOSE,            DB_COLLATE,
    DB_COLLATION_NEEDED,  DB_COMMIT_HOOK,      DB_COMPLETE,
    DB_COPY,              DB_ERRORCODE,        DB_EVAL,
    DB_FUNCTION,          DB_LAST_INSERT_ROWID,DB_NULLVALUE,
    DB_ONECOLUMN,         DB_PROGRESS,         DB_REKEY,
    DB_TIMEOUT,           DB_TOTAL_CHANGES,    DB_TRACE,
    DB_TRANSACTION,       DB_VERSION,          
  };
  /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */

  if( objc<2 ){
    Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
    return TCL_ERROR;
  }
................................................................................
  ** Shutdown the database
  */
  case DB_CLOSE: {
    Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0));
    break;
  }

  /*    $db commit_hook ?CALLBACK?
  **
  ** Invoke the given callback just before committing every SQL transaction.
  ** If the callback throws an exception or returns non-zero, then the
  ** transaction is aborted.  If CALLBACK is an empty string, the callback
  ** is disabled.
  */
  case DB_COMMIT_HOOK: {
    if( objc>3 ){
      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
      return TCL_ERROR;
    }else if( objc==2 ){
      if( pDb->zCommit ){
        Tcl_AppendResult(interp, pDb->zCommit, 0);
      }
    }else{
      char *zCommit;
      int len;
      if( pDb->zCommit ){
        Tcl_Free(pDb->zCommit);
      }
      zCommit = Tcl_GetStringFromObj(objv[2], &len);
      if( zCommit && len>0 ){
        pDb->zCommit = Tcl_Alloc( len + 1 );
        strcpy(pDb->zCommit, zCommit);
      }else{
        pDb->zCommit = 0;
      }
      if( pDb->zCommit ){
        pDb->interp = interp;
        sqlite3_commit_hook(pDb->db, DbCommitHandler, pDb);
      }else{
        sqlite3_commit_hook(pDb->db, 0, 0);
      }
    }
    break;
  }

  /*
  **     $db collate NAME SCRIPT
  **
  ** Create a new SQL collation function called NAME.  Whenever
  ** that function is called, invoke SCRIPT to evaluate the function.
  */
  case DB_COLLATE: {
................................................................................
      Tcl_DecrRefCount(pDb->pCollateNeeded);
    }
    pDb->pCollateNeeded = Tcl_DuplicateObj(objv[2]);
    Tcl_IncrRefCount(pDb->pCollateNeeded);
    sqlite3_collation_needed(pDb->db, pDb, tclCollateNeeded);
    break;
  }







































  /*    $db complete SQL
  **
  ** Return TRUE if SQL is a complete SQL statement.  Return FALSE if
  ** additional lines of input are needed.  This is similar to the
  ** built-in "info complete" command of Tcl.
  */
................................................................................
    }
    isComplete = sqlite3_complete( Tcl_GetStringFromObj(objv[2], 0) );
    pResult = Tcl_GetObjResult(interp);
    Tcl_SetBooleanObj(pResult, isComplete);
#endif
    break;
  }



























































































































































































  /*
  **    $db errorcode
  **
  ** Return the numeric error code that was returned by the most recent
  ** call to sqlite3_exec().
  */
................................................................................
      Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE);
    }else{
      /* Must flush any cached statements */
      flushStmtCache( pDb );
    }
    break;
  }
































  /*
  **     $db last_insert_rowid 
  **
  ** Return an integer which is the ROWID for the most recent insert.
  */
  case DB_LAST_INSERT_ROWID: {
................................................................................
#endif
    }else{
      Tcl_WrongNumArgs(interp, 2, objv, "N CALLBACK");
      return TCL_ERROR;
    }
    break;
  }








































  /*
  **     $db rekey KEY
  **
  ** Change the encryption key on the currently open database.
  */
  case DB_REKEY: {
................................................................................
      Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS");
      return TCL_ERROR;
    }
    if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR;
    sqlite3_busy_timeout(pDb->db, ms);
    break;
  }

  /*
  **     $db nullvalue ?STRING?
  **
  ** Change text used when a NULL comes back from the database. If ?STRING?
  ** is not present, then the current string used for NULL is returned.
  ** If STRING is present, then STRING is returned.
  **
  */
  case DB_NULLVALUE: {
    if( objc!=2 && objc!=3 ){
      Tcl_WrongNumArgs(interp, 2, objv, "NULLVALUE");
      return TCL_ERROR;
    }
    if( objc==3 ){
      int len;
      char *zNull = Tcl_GetStringFromObj(objv[2], &len);
      if( pDb->zNull ){
        Tcl_Free(pDb->zNull);
      }
      if( zNull && len>0 ){
        pDb->zNull = Tcl_Alloc( len + 1 );
        strncpy(pDb->zNull, zNull, len);
        pDb->zNull[len] = '\0';
      }else{
        pDb->zNull = 0;
      }
    }
    Tcl_SetObjResult(interp, dbTextToObj(pDb->zNull));
    break;
  }
  
  /*
  **     $db total_changes
  **
  ** Return the number of rows that were modified, inserted, or deleted 
  ** since the database handle was created.
  */
................................................................................
      zTrace = Tcl_GetStringFromObj(objv[2], &len);
      if( zTrace && len>0 ){
        pDb->zTrace = Tcl_Alloc( len + 1 );
        strcpy(pDb->zTrace, zTrace);
      }else{
        pDb->zTrace = 0;
      }

      if( pDb->zTrace ){
        pDb->interp = interp;
        sqlite3_trace(pDb->db, DbTraceHandler, pDb);
      }else{
        sqlite3_trace(pDb->db, 0, 0);
      }

    }
    break;
  }

  /*    $db transaction [-deferred|-immediate|-exclusive] SCRIPT
  **
  ** Start a new transaction (if we are not already in the midst of a
................................................................................
      if( rc==TCL_ERROR ){
        zEnd = "ROLLBACK";
      } else {
        zEnd = "COMMIT";
      }
      sqlite3_exec(pDb->db, zEnd, 0, 0, 0);
    }
    break;
  }

  /*    $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR?
  **
  ** Copy data into table from filename, optionally using SEPARATOR
  ** as column separators.  If a column contains a null string, or the
  ** value of NULLINDICATOR, a NULL is inserted for the column.
  ** conflict-algorithm is one of the sqlite conflict algorithms:
  **    rollback, abort, fail, ignore, replace
  ** On success, return the number of lines processed, not necessarily same
  ** as 'db changes' due to conflict-algorithm selected.
  **
  ** This code is basically an implementation/enhancement of
  ** the sqlite3 shell.c ".import" command.
  **
  ** This command usage is equivalent to the sqlite2.x COPY statement,
  ** which imports file data into a table using the PostgreSQL COPY file format:
  **   $db copy $conflit_algo $table_name $filename \t \\N
  */
  case DB_COPY: {
    char *zTable;               /* Insert data into this table */
    char *zFile;                /* The file from which to extract data */
    char *zConflict;            /* The conflict algorithm to use */
    sqlite3_stmt *pStmt;        /* A statement */
    int rc;                     /* Result code */
    int nCol;                   /* Number of columns in the table */
    int nByte;                  /* Number of bytes in an SQL string */
    int i, j;                   /* Loop counters */
    int nSep;                   /* Number of bytes in zSep[] */
    int nNull;                  /* Number of bytes in zNull[] */
    char *zSql;                 /* An SQL statement */
    char *zLine;                /* A single line of input from the file */
    char **azCol;               /* zLine[] broken up into columns */
    char *zCommit;              /* How to commit changes */
    FILE *in;                   /* The input file */
    int lineno = 0;             /* Line number of input file */
    char zLineNum[80];          /* Line number print buffer */
    Tcl_Obj *pResult;           /* interp result */

    char *zSep;
    char *zNull;
    if( objc<5 || objc>7 ){
      Tcl_WrongNumArgs(interp, 2, objv, 
         "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?");
      return TCL_ERROR;
    }
    if( objc>=6 ){
      zSep = Tcl_GetStringFromObj(objv[5], 0);
    }else{
      zSep = "\t";
    }
    if( objc>=7 ){
      zNull = Tcl_GetStringFromObj(objv[6], 0);
    }else{
      zNull = "";
    }
    zConflict = Tcl_GetStringFromObj(objv[2], 0);
    zTable = Tcl_GetStringFromObj(objv[3], 0);
    zFile = Tcl_GetStringFromObj(objv[4], 0);
    nSep = strlen(zSep);
    nNull = strlen(zNull);
    if( nSep==0 ){
      Tcl_AppendResult(interp, "Error: non-null separator required for copy", 0);
      return TCL_ERROR;
    }
    if(sqlite3StrICmp(zConflict, "rollback") != 0 &&
       sqlite3StrICmp(zConflict, "abort"   ) != 0 &&
       sqlite3StrICmp(zConflict, "fail"    ) != 0 &&
       sqlite3StrICmp(zConflict, "ignore"  ) != 0 &&
       sqlite3StrICmp(zConflict, "replace" ) != 0 ) {
      Tcl_AppendResult(interp, "Error: \"", zConflict, 
            "\", conflict-algorithm must be one of: rollback, "
            "abort, fail, ignore, or replace", 0);
      return TCL_ERROR;
    }
    zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
    if( zSql==0 ){
      Tcl_AppendResult(interp, "Error: no such table: ", zTable, 0);
      return TCL_ERROR;
    }
    nByte = strlen(zSql);
    rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0);
    sqlite3_free(zSql);
    if( rc ){
      Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0);
      nCol = 0;
    }else{
      nCol = sqlite3_column_count(pStmt);
    }
    sqlite3_finalize(pStmt);
    if( nCol==0 ) {
      return TCL_ERROR;
    }
    zSql = malloc( nByte + 50 + nCol*2 );
    if( zSql==0 ) {
      Tcl_AppendResult(interp, "Error: can't malloc()", 0);
      return TCL_ERROR;
    }
    sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?",
         zConflict, zTable);
    j = strlen(zSql);
    for(i=1; i<nCol; i++){
      zSql[j++] = ',';
      zSql[j++] = '?';
    }
    zSql[j++] = ')';
    zSql[j] = 0;
    rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0);
    free(zSql);
    if( rc ){
      Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0);
      sqlite3_finalize(pStmt);
      return TCL_ERROR;
    }
    in = fopen(zFile, "rb");
    if( in==0 ){
      Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, NULL);
      sqlite3_finalize(pStmt);
      return TCL_ERROR;
    }
    azCol = malloc( sizeof(azCol[0])*(nCol+1) );
    if( azCol==0 ) {
      Tcl_AppendResult(interp, "Error: can't malloc()", 0);
      return TCL_ERROR;
    }
    sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0);
    zCommit = "COMMIT";
    while( (zLine = local_getline(0, in))!=0 ){
      char *z;
      i = 0;
      lineno++;
      azCol[0] = zLine;
      for(i=0, z=zLine; *z; z++){
        if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
          *z = 0;
          i++;
          if( i<nCol ){
            azCol[i] = &z[nSep];
            z += nSep-1;
          }
        }
      }
      if( i+1!=nCol ){
        char *zErr;
        zErr = malloc(200 + strlen(zFile));
        sprintf(zErr,"Error: %s line %d: expected %d columns of data but found %d",
           zFile, lineno, nCol, i+1);
        Tcl_AppendResult(interp, zErr, 0);
        free(zErr);
        zCommit = "ROLLBACK";
        break;
      }
      for(i=0; i<nCol; i++){
        /* check for null data, if so, bind as null */
        if ((nNull>0 && strcmp(azCol[i], zNull)==0) || strlen(azCol[i])==0) {
          sqlite3_bind_null(pStmt, i+1);
        }else{
          sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
        }
      }
      sqlite3_step(pStmt);
      rc = sqlite3_reset(pStmt);
      free(zLine);
      if( rc!=SQLITE_OK ){
        Tcl_AppendResult(interp,"Error: ", sqlite3_errmsg(pDb->db), 0);
        zCommit = "ROLLBACK";
        break;
      }
    }
    free(azCol);
    fclose(in);
    sqlite3_finalize(pStmt);
    sqlite3_exec(pDb->db, zCommit, 0, 0, 0);

    if( zCommit[0] == 'C' ){
      /* success, set result as number of lines processed */
      pResult = Tcl_GetObjResult(interp);
      Tcl_SetIntObj(pResult, lineno);
      rc = TCL_OK;
    }else{
      /* failure, append lineno where failed */
      sprintf(zLineNum,"%d",lineno);
      Tcl_AppendResult(interp,", failed while processing line: ",zLineNum,0);
      rc = TCL_ERROR;
    }
    break;
  }

  /*    $db version
  **
  ** Return the version string for this database.
  */







|







 







>







 







>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
>







|
|
|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
&g