System.Data.SQLite

Check-in [e3ded2c8dc]
Login

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

Overview
Comment:Pre 3.3.4 interim updates
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: e3ded2c8dc20ee5a1518021b152b32108ccc5b8d
User & Date: rmsimpson 2006-02-10 19:45:44.000
Context
2006-02-10
19:51
Pre 3.3.4 interim updates check-in: ced943931d user: rmsimpson tags: sourceforge
19:45
Pre 3.3.4 interim updates check-in: e3ded2c8dc user: rmsimpson tags: sourceforge
19:44
Changes due to 3.3.4 check-in: 917fbb8c4d user: rmsimpson tags: sourceforge
Changes
Unified Diff 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.17 2006/01/31 19:16:13 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.18 2006/02/10 19:45:44 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.
537
538
539
540
541
542
543

544
545
546
547
548
549
550
  if( !pNew->aCol || !pNew->zName ){
    goto exit_begin_add_column;
  }
  memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
  for(i=0; i<pNew->nCol; i++){
    Column *pCol = &pNew->aCol[i];
    pCol->zName = sqliteStrDup(pCol->zName);

    pCol->zType = 0;
    pCol->pDflt = 0;
  }
  pNew->pSchema = pParse->db->aDb[iDb].pSchema;
  pNew->addColOffset = pTab->addColOffset;
  pNew->nRef = 1;








>







537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
  if( !pNew->aCol || !pNew->zName ){
    goto exit_begin_add_column;
  }
  memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
  for(i=0; i<pNew->nCol; i++){
    Column *pCol = &pNew->aCol[i];
    pCol->zName = sqliteStrDup(pCol->zName);
    pCol->zColl = 0;
    pCol->zType = 0;
    pCol->pDflt = 0;
  }
  pNew->pSchema = pParse->db->aDb[iDb].pSchema;
  pNew->addColOffset = pTab->addColOffset;
  pNew->nRef = 1;

Changes to SQLite.Interop/src/btree.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
** 2004 April 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.19 2006/01/31 19:16:13 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.











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
** 2004 April 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.20 2006/02/10 19:45:44 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.
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
**   because the table is empty or because BtreeCursorFirst() has not been
**   called.
**
** CURSOR_REQUIRESEEK:
**   The table that this cursor was opened on still exists, but has been 
**   modified since the cursor was last used. The cursor position is saved
**   in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in 
**   this state, restoreOrClearCursorPosition() can be called to attempt to seek 
**   the cursor to the saved position.
*/
#define CURSOR_INVALID           0
#define CURSOR_VALID             1
#define CURSOR_REQUIRESEEK       2

/*
** The TRACE macro will print high-level status information about the







|
|







407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
**   because the table is empty or because BtreeCursorFirst() has not been
**   called.
**
** CURSOR_REQUIRESEEK:
**   The table that this cursor was opened on still exists, but has been 
**   modified since the cursor was last used. The cursor position is saved
**   in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in 
**   this state, restoreOrClearCursorPosition() can be called to attempt to
**   seek the cursor to the saved position.
*/
#define CURSOR_INVALID           0
#define CURSOR_VALID             1
#define CURSOR_REQUIRESEEK       2

/*
** The TRACE macro will print high-level status information about the
752
753
754
755
756
757
758
759
760
761










762
763
764
765
766
767
768
** the offset of the requested map entry.
**
** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
** then pgno is returned. So (pgno==PTRMAP_PAGENO(pgsz, pgno)) can be
** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
** this test.
*/
#define PTRMAP_PAGENO(pgsz, pgno) (((pgno-2)/(pgsz/5+1))*(pgsz/5+1)+2)
#define PTRMAP_PTROFFSET(pgsz, pgno) (((pgno-2)%(pgsz/5+1)-1)*5)
#define PTRMAP_ISPAGE(pgsz, pgno) (PTRMAP_PAGENO(pgsz,pgno)==pgno)











/*
** The pointer map is a lookup table that identifies the parent page for
** each child page in the database file.  The parent page is the page that
** contains a pointer to the child.  Every page in the database contains
** 0 or 1 parent pages.  (In this context 'database page' refers
** to any page that is not part of the pointer map itself.)  Each pointer map







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







752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
** the offset of the requested map entry.
**
** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
** then pgno is returned. So (pgno==PTRMAP_PAGENO(pgsz, pgno)) can be
** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
** this test.
*/
#define PTRMAP_PAGENO(pBt, pgno) ptrmapPageno(pBt, pgno)
#define PTRMAP_PTROFFSET(pBt, pgno) (5*(pgno-ptrmapPageno(pBt, pgno)-1))
#define PTRMAP_ISPAGE(pBt, pgno) (PTRMAP_PAGENO((pBt),(pgno))==(pgno))

static Pgno ptrmapPageno(BtShared *pBt, Pgno pgno){
  int nPagesPerMapPage = (pBt->usableSize/5)+1;
  int iPtrMap = (pgno-2)/nPagesPerMapPage;
  int ret = (iPtrMap*nPagesPerMapPage) + 2; 
  if( ret==PENDING_BYTE_PAGE(pBt) ){
    ret++;
  }
  return ret;
}

/*
** The pointer map is a lookup table that identifies the parent page for
** each child page in the database file.  The parent page is the page that
** contains a pointer to the child.  Every page in the database contains
** 0 or 1 parent pages.  (In this context 'database page' refers
** to any page that is not part of the pointer map itself.)  Each pointer map
806
807
808
809
810
811
812



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
*/
static int ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent){
  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);

  if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
    TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
    rc = sqlite3pager_write(pPtrmap);
    if( rc==SQLITE_OK ){
      pPtrmap[offset] = eType;
      put4byte(&pPtrmap[offset+1], parent);







>
>
>




|




|







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
*/
static int ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent){
  u8 *pPtrmap;    /* The pointer map page */
  Pgno iPtrmap;   /* The pointer map page number */
  int offset;     /* Offset in pointer map page */
  int rc;

  /* The master-journal page number must never be used as a pointer map page */
  assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );

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

  if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
    TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
    rc = sqlite3pager_write(pPtrmap);
    if( rc==SQLITE_OK ){
      pPtrmap[offset] = eType;
      put4byte(&pPtrmap[offset+1], parent);
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
*/
static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
  int iPtrmap;       /* Pointer map page index */
  u8 *pPtrmap;       /* Pointer map page data */
  int offset;        /* Offset of entry in pointer map */
  int rc;

  iPtrmap = PTRMAP_PAGENO(pBt->usableSize, key);
  rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
  if( rc!=0 ){
    return rc;
  }

  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;
}







|





|







856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
*/
static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
  int iPtrmap;       /* Pointer map page index */
  u8 *pPtrmap;       /* Pointer map page data */
  int offset;        /* Offset of entry in pointer map */
  int rc;

  iPtrmap = PTRMAP_PAGENO(pBt, key);
  rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
  if( rc!=0 ){
    return rc;
  }

  offset = PTRMAP_PTROFFSET(pBt, 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;
}
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
  MemPage *pFreeMemPage = 0; /* "" */

#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));

  /* Variable 'finSize' will be the size of the file in pages after
  ** the auto-vacuum has completed (the current file size minus the number
  ** of pages on the free list). Loop through the pages that lie beyond
  ** this mark, and if they are not already on the free list, move them
  ** to a free page earlier in the file (somewhere before finSize).
  */
  for( iDbPage=finSize+1; iDbPage<=origSize; iDbPage++ ){
    /* If iDbPage is a pointer map page, or the pending-byte page, skip it. */
    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;







|












>
>
>
>
>
>
>
>
>

>
>
>
|

|

>
|
|
<











|







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
  MemPage *pFreeMemPage = 0; /* "" */

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

  assert( pBt->autoVacuum );
  if( PTRMAP_ISPAGE(pBt, 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;
  }

  /* This block figures out how many pages there are in the database
  ** now (variable origSize), and how many there will be after the
  ** truncation (variable finSize).
  **
  ** The final size is the original size, less the number of free pages
  ** in the database, less any pointer-map pages that will no longer
  ** be required, less 1 if the pending-byte page was part of the database
  ** but is not after the truncation.
  **/
  origSize = sqlite3pager_pagecount(pPager);
  if( origSize==PENDING_BYTE_PAGE(pBt) ){
    origSize--;
  }
  nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pBt, origSize)+pgsz/5)/(pgsz/5);
  finSize = origSize - nFreeList - nPtrMap;
  if( origSize>PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){
    finSize--;
  }
  while( PTRMAP_ISPAGE(pBt, finSize) || finSize==PENDING_BYTE_PAGE(pBt) ){
    finSize--;

  }
  TRACE(("AUTOVACUUM: Begin (db size %d->%d)\n", origSize, finSize));

  /* Variable 'finSize' will be the size of the file in pages after
  ** the auto-vacuum has completed (the current file size minus the number
  ** of pages on the free list). Loop through the pages that lie beyond
  ** this mark, and if they are not already on the free list, move them
  ** to a free page earlier in the file (somewhere before finSize).
  */
  for( iDbPage=finSize+1; iDbPage<=origSize; iDbPage++ ){
    /* If iDbPage is a pointer map page, or the pending-byte page, skip it. */
    if( PTRMAP_ISPAGE(pBt, 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;
2430
2431
2432
2433
2434
2435
2436

2437
2438
2439
2440
2441
2442
2443
  */
  rc = sqlite3pager_write(pBt->pPage1->aData);
  if( rc!=SQLITE_OK ) goto autovacuum_out;
  put4byte(&pBt->pPage1->aData[32], 0);
  put4byte(&pBt->pPage1->aData[36], 0);
  if( rc!=SQLITE_OK ) goto autovacuum_out;
  *nTrunc = finSize;


autovacuum_out:
  assert( nRef==*sqlite3pager_stats(pPager) );
  if( rc!=SQLITE_OK ){
    sqlite3pager_rollback(pPager);
  }
  return rc;







>







2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
  */
  rc = sqlite3pager_write(pBt->pPage1->aData);
  if( rc!=SQLITE_OK ) goto autovacuum_out;
  put4byte(&pBt->pPage1->aData[32], 0);
  put4byte(&pBt->pPage1->aData[36], 0);
  if( rc!=SQLITE_OK ) goto autovacuum_out;
  *nTrunc = finSize;
  assert( finSize!=PENDING_BYTE_PAGE(pBt) );

autovacuum_out:
  assert( nRef==*sqlite3pager_stats(pPager) );
  if( rc!=SQLITE_OK ){
    sqlite3pager_rollback(pPager);
  }
  return rc;
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
    releasePage(pTrunk);
  }else{
    /* There are no pages on the freelist, so create a new page at the
    ** end of the file */
    *pPgno = sqlite3pager_pagecount(pBt->pPager) + 1;

#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt->usableSize, *pPgno) ){
      /* If *pPgno refers to a pointer-map page, allocate two new pages
      ** at the end of the file instead of one. The first allocated page
      ** becomes a new pointer-map page, the second is used by the caller.
      */
      TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
      assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
      (*pPgno)++;







|







3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
    releasePage(pTrunk);
  }else{
    /* There are no pages on the freelist, so create a new page at the
    ** end of the file */
    *pPgno = sqlite3pager_pagecount(pBt->pPager) + 1;

#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
      /* If *pPgno refers to a pointer-map page, allocate two new pages
      ** at the end of the file instead of one. The first allocated page
      ** becomes a new pointer-map page, the second is used by the caller.
      */
      TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
      assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
      (*pPgno)++;
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
    rc = sqlite3BtreeGetMeta(p, 4, &pgnoRoot);
    if( rc!=SQLITE_OK ) return rc;
    pgnoRoot++;

    /* The new root-page may not be allocated on a pointer-map page, or the
    ** PENDING_BYTE page.
    */
    if( pgnoRoot==PTRMAP_PAGENO(pBt->usableSize, pgnoRoot) ||
        pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
      pgnoRoot++;
    }
    assert( pgnoRoot>=3 );

    /* Allocate a page. The page that currently resides at pgnoRoot will
    ** be moved to the allocated page (unless the allocated page happens







|







5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
    rc = sqlite3BtreeGetMeta(p, 4, &pgnoRoot);
    if( rc!=SQLITE_OK ) return rc;
    pgnoRoot++;

    /* The new root-page may not be allocated on a pointer-map page, or the
    ** PENDING_BYTE page.
    */
    if( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
        pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
      pgnoRoot++;
    }
    assert( pgnoRoot>=3 );

    /* Allocate a page. The page that currently resides at pgnoRoot will
    ** be moved to the allocated page (unless the allocated page happens
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
      ** be a root-page number, less one again if that is the
      ** PENDING_BYTE_PAGE.
      */
      maxRootPgno--;
      if( maxRootPgno==PENDING_BYTE_PAGE(pBt) ){
        maxRootPgno--;
      }
      if( maxRootPgno==PTRMAP_PAGENO(pBt->usableSize, maxRootPgno) ){
        maxRootPgno--;
      }
      assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) );

      rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno);
    }else{
      rc = freePage(pPage);







|







5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
      ** be a root-page number, less one again if that is the
      ** PENDING_BYTE_PAGE.
      */
      maxRootPgno--;
      if( maxRootPgno==PENDING_BYTE_PAGE(pBt) ){
        maxRootPgno--;
      }
      if( maxRootPgno==PTRMAP_PAGENO(pBt, maxRootPgno) ){
        maxRootPgno--;
      }
      assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) );

      rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno);
    }else{
      rc = freePage(pPage);
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
      checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
    }
#else
    /* If the database supports auto-vacuum, make sure no tables contain
    ** references to pointer-map pages.
    */
    if( sCheck.anRef[i]==0 && 
       (PTRMAP_PAGENO(pBt->usableSize, i)!=i || !pBt->autoVacuum) ){
      checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
    }
    if( sCheck.anRef[i]!=0 && 
       (PTRMAP_PAGENO(pBt->usableSize, i)==i && pBt->autoVacuum) ){
      checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
    }
#endif
  }

  /* Make sure this analysis did not leave any unref() pages
  */







|



|







6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
      checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
    }
#else
    /* If the database supports auto-vacuum, make sure no tables contain
    ** references to pointer-map pages.
    */
    if( sCheck.anRef[i]==0 && 
       (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
      checkAppendMsg(&sCheck, 0, "Page %d is never used", i);
    }
    if( sCheck.anRef[i]!=0 && 
       (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
      checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
    }
#endif
  }

  /* Make sure this analysis did not leave any unref() pages
  */
6518
6519
6520
6521
6522
6523
6524

6525
6526
6527
6528

6529
6530
6531

6532
6533

6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
** When this is called, the master journal should already have been
** created, populated with this journal pointer and synced to disk.
**
** Once this is routine has returned, the only thing required to commit
** the write-transaction for this database file is to delete the journal.
*/
int sqlite3BtreeSync(Btree *p, const char *zMaster){

  if( p->inTrans==TRANS_WRITE ){
    BtShared *pBt = p->pBt;
#ifndef SQLITE_OMIT_AUTOVACUUM
    Pgno nTrunc = 0;

    if( pBt->autoVacuum ){
      int rc = autoVacuumCommit(pBt, &nTrunc); 
      if( rc!=SQLITE_OK ) return rc;

    }
    return sqlite3pager_sync(pBt->pPager, zMaster, nTrunc);

#endif
    return sqlite3pager_sync(pBt->pPager, zMaster, 0);
  }
  return SQLITE_OK;
}

/*
** This function returns a pointer to a blob of memory associated with
** a single shared-btree. The memory is used by client code for it's own
** purposes (for example, to store a high-level schema associated with 
** the shared-btree). The btree layer manages reference counting issues.







>


<

>

|
|
>
|
<
>

|

|







6544
6545
6546
6547
6548
6549
6550
6551
6552
6553

6554
6555
6556
6557
6558
6559
6560

6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
** When this is called, the master journal should already have been
** created, populated with this journal pointer and synced to disk.
**
** Once this is routine has returned, the only thing required to commit
** the write-transaction for this database file is to delete the journal.
*/
int sqlite3BtreeSync(Btree *p, const char *zMaster){
  int rc = SQLITE_OK;
  if( p->inTrans==TRANS_WRITE ){
    BtShared *pBt = p->pBt;

    Pgno nTrunc = 0;
#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pBt->autoVacuum ){
      rc = autoVacuumCommit(pBt, &nTrunc); 
      if( rc!=SQLITE_OK ){
        return rc;
      }

    }
#endif
    rc = sqlite3pager_sync(pBt->pPager, zMaster, nTrunc);
  }
  return rc;
}

/*
** This function returns a pointer to a blob of memory associated with
** a single shared-btree. The memory is used by client code for it's own
** purposes (for example, to store a high-level schema associated with 
** the shared-btree). The btree layer manages reference counting issues.
Changes to SQLite.Interop/src/build.c.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.17 2006/01/31 19:16:13 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.







|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.18 2006/02/10 19:45:44 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.
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
  **
  **     CREATE VIEW one AS SELECT * FROM two;
  **     CREATE VIEW two AS SELECT * FROM one;
  **
  ** Actually, this error is caught previously and so the following test
  ** should always fail.  But we will leave it in place just to be safe.
  */
#if 0
  if( pTable->nCol<0 ){
    sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName);
    return 1;
  }
#endif
  assert( pTable->nCol>=0 );

  /* If we get this far, it means we need to compute the table names.
  ** Note that the call to sqlite3ResultSetOfSelect() will expand any
  ** "*" elements in the results set of the view and will assign cursors
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT







<




<







1658
1659
1660
1661
1662
1663
1664

1665
1666
1667
1668

1669
1670
1671
1672
1673
1674
1675
  **
  **     CREATE VIEW one AS SELECT * FROM two;
  **     CREATE VIEW two AS SELECT * FROM one;
  **
  ** Actually, this error is caught previously and so the following test
  ** should always fail.  But we will leave it in place just to be safe.
  */

  if( pTable->nCol<0 ){
    sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName);
    return 1;
  }

  assert( pTable->nCol>=0 );

  /* If we get this far, it means we need to compute the table names.
  ** Note that the call to sqlite3ResultSetOfSelect() will expand any
  ** "*" elements in the results set of the view and will assign cursors
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT
2845
2846
2847
2848
2849
2850
2851

2852
2853
2854
2855
2856
2857
2858
    Token *pTemp = pDatabase;
    pDatabase = pTable;
    pTable = pTemp;
  }
  pItem->zName = sqlite3NameFromToken(pTable);
  pItem->zDatabase = sqlite3NameFromToken(pDatabase);
  pItem->iCursor = -1;

  pList->nSrc++;
  return pList;
}

/*
** Assign cursors to all tables in a SrcList
*/







>







2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
    Token *pTemp = pDatabase;
    pDatabase = pTable;
    pTable = pTemp;
  }
  pItem->zName = sqlite3NameFromToken(pTable);
  pItem->zDatabase = sqlite3NameFromToken(pDatabase);
  pItem->iCursor = -1;
  pItem->isPopulated = 0;
  pList->nSrc++;
  return pList;
}

/*
** Assign cursors to all tables in a SrcList
*/
Changes to SQLite.Interop/src/delete.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 are called by the parser
** in order to generate code for DELETE FROM statements.
**
** $Id: delete.c,v 1.17 2006/01/31 19:16:13 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.







|







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 are called by the parser
** in order to generate code for DELETE FROM statements.
**
** $Id: delete.c,v 1.18 2006/02/10 19:45:44 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.
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  ** Return the number of rows that were deleted. If this routine is 
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, "rows deleted", P3_STATIC);
  }

delete_from_cleanup:
  sqlite3AuthContextPop(&sContext);
  sqlite3SrcListDelete(pTabList);
  sqlite3ExprDelete(pWhere);
  return;







|







339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  ** Return the number of rows that were deleted. If this routine is 
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", P3_STATIC);
  }

delete_from_cleanup:
  sqlite3AuthContextPop(&sContext);
  sqlite3SrcListDelete(pTabList);
  sqlite3ExprDelete(pWhere);
  return;
Changes to SQLite.Interop/src/expr.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 routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.24 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**







|







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 routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.25 2006/02/10 19:45:44 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
491
492
493
494
495
496
497

498
499
500
501
502
503
504
    struct SrcList_item *pOldItem = &p->a[i];
    Table *pTab;
    pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase);
    pNewItem->zName = sqliteStrDup(pOldItem->zName);
    pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias);
    pNewItem->jointype = pOldItem->jointype;
    pNewItem->iCursor = pOldItem->iCursor;

    pTab = pNewItem->pTab = pOldItem->pTab;
    if( pTab ){
      pTab->nRef++;
    }
    pNewItem->pSelect = sqlite3SelectDup(pOldItem->pSelect);
    pNewItem->pOn = sqlite3ExprDup(pOldItem->pOn);
    pNewItem->pUsing = sqlite3IdListDup(pOldItem->pUsing);







>







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
    struct SrcList_item *pOldItem = &p->a[i];
    Table *pTab;
    pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase);
    pNewItem->zName = sqliteStrDup(pOldItem->zName);
    pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias);
    pNewItem->jointype = pOldItem->jointype;
    pNewItem->iCursor = pOldItem->iCursor;
    pNewItem->isPopulated = pOldItem->isPopulated;
    pTab = pNewItem->pTab = pOldItem->pTab;
    if( pTab ){
      pTab->nRef++;
    }
    pNewItem->pSelect = sqlite3SelectDup(pOldItem->pSelect);
    pNewItem->pOn = sqlite3ExprDup(pOldItem->pOn);
    pNewItem->pUsing = sqlite3IdListDup(pOldItem->pUsing);
Changes to SQLite.Interop/src/func.c.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** 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.19 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/* #include <math.h> */
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** 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.20 2006/02/10 19:45:44 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/* #include <math.h> */
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"
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
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
878
879
880
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

/*
** 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, average, and total.
**
** The SUM() function follows the (broken) SQL standard which means
** that it returns NULL if it sums over no inputs.  TOTAL returns
** 0.0 in that case.  In addition, TOTAL always returns a float where
** SUM might return an integer if it never encounters a floating point
** value.









*/
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);
  }
}
static void totalFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  sqlite3_result_double(context, p ? p->sum : 0.0);
}

/*
** An instance of the following structure holds the context of a
** variance or standard deviation computation.
*/
typedef struct StdDevCtx StdDevCtx;
struct StdDevCtx {
  double sum;     /* Sum of terms */
  double sum2;    /* Sum of the squares of terms */
  int cnt;        /* Number of terms counted */
};

/*
** The following structure keeps track of state information for the
** count() aggregate function.
*/
typedef struct CountCtx CountCtx;
struct CountCtx {
  int n;
};

/*
** Routines to implement the count() aggregate function.
*/
static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
  CountCtx *p;
  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){
  Mem *pArg  = (Mem *)argv[0];







|
|
|










>
>
>
>
>
>
>
>
>






|

<

|
>
>
>
>
>
>
>
|







|



















<
<
<
<
<
<
<
<
<
<
<






|















|







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
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
878
879
880
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

/*
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
*/
typedef struct SumCtx SumCtx;
struct SumCtx {
  LONGDOUBLE_TYPE sum;    /* Sum of terms */
  i64 cnt;                /* Number of elements summed */
  u8 approx;              /* True if sum is approximate */
};

/*
** Routines used to compute the sum, average, and total.
**
** The SUM() function follows the (broken) SQL standard which means
** that it returns NULL if it sums over no inputs.  TOTAL returns
** 0.0 in that case.  In addition, TOTAL always returns a float where
** SUM might return an integer if it never encounters a floating point
** value.
**
** I am told that SUM() should raise an exception if it encounters
** a integer overflow.  But after pondering this, I decided that 
** behavior leads to brittle programs.  So instead, I have coded
** SUM() to revert to using floating point if it encounters an
** integer overflow.  The answer may not be exact, but it will be
** close.  If the SUM() function returns an integer, the value is
** exact.  If SUM() returns a floating point value, it means the
** value might be approximated.
*/
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_numeric_type(argv[0]);
  if( p && type!=SQLITE_NULL ){

    p->cnt++;
    if( type==SQLITE_INTEGER ){
      p->sum += sqlite3_value_int64(argv[0]);
      if( !p->approx ){
        i64 iVal;
        p->approx = p->sum!=(LONGDOUBLE_TYPE)(iVal = (i64)p->sum);
      }
    }else{
      p->sum += sqlite3_value_double(argv[0]);
      p->approx = 1;
    }
  }
}
static void sumFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  if( p && p->cnt>0 ){
    if( p->approx ){
      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);
  }
}
static void totalFinalize(sqlite3_context *context){
  SumCtx *p;
  p = sqlite3_aggregate_context(context, 0);
  sqlite3_result_double(context, p ? p->sum : 0.0);
}












/*
** The following structure keeps track of state information for the
** count() aggregate function.
*/
typedef struct CountCtx CountCtx;
struct CountCtx {
  i64 n;
};

/*
** Routines to implement the count() aggregate function.
*/
static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
  CountCtx *p;
  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_int64(context, p ? p->n : 0);
}

/*
** Routines to implement min() and max() aggregate functions.
*/
static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){
  Mem *pArg  = (Mem *)argv[0];
Changes to SQLite.Interop/src/insert.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 are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.17 2006/01/31 19:16:13 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:







|







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 are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.18 2006/02/10 19:45:44 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:
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
    sqlite3VdbeAddOp(v, OP_MemLoad, iCntMem, 0);
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, "rows inserted", P3_STATIC);
  }

insert_cleanup:
  sqlite3SrcListDelete(pTabList);
  sqlite3ExprListDelete(pList);
  sqlite3SelectDelete(pSelect);
  sqlite3IdListDelete(pColumn);







|







699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
    sqlite3VdbeAddOp(v, OP_MemLoad, iCntMem, 0);
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", P3_STATIC);
  }

insert_cleanup:
  sqlite3SrcListDelete(pTabList);
  sqlite3ExprListDelete(pList);
  sqlite3SelectDelete(pSelect);
  sqlite3IdListDelete(pColumn);
Changes to SQLite.Interop/src/keywordhash.h.
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
    "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS"
    "CURRENT_DATECURRENT_TIMESTAMPLANDESCDETACHDISTINCTDROPRAGMATCH"
    "FAILIMITFROMFULLGROUPDATEIFIMMEDIATEINSERTINSTEADINTOFFSETISNULL"
    "JOINORDEREPLACEOUTERESTRICTPRIMARYQUERYRIGHTROLLBACKROWHENUNION"
    "UNIQUEUSINGVACUUMVALUESVIEWHERE";
  static const unsigned char aHash[127] = {
      92,  80, 107,  91,   0,   4,   0,   0, 114,   0,  83,   0,   0,
      95,  44,  76,  93,   0, 106, 109,  97,  90,   0,  10,   0,   0,
     113,   0, 110, 103,   0,  28,  48,   0,  41,   0,   0,  65,  71,
       0,  63,  19,   0, 105,  36, 104,   0, 108,  74,   0,   0,  33,
       0,  61,  37,   0,   8,   0, 115,  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, 101,  58,  18,   0, 112,  82,  99,
      54,   6,  85,   0,   0,  49,  94,   0, 102,   0,  70,   0,   0,
      15,   0, 116,  51,  56,   0,   2,  55,   0, 111,
  };
  static const unsigned char aNext[116] = {
       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,   0,  39,  96,  98,   0,   0, 100,   0,  32,
       0,  14,  27,  78,   0,  57,  89,   0,  35,   0,  62,   0,
  };
  static const unsigned char aLen[116] = {
       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,   2,   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[116] = {
       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,







|

|


|

|
|





|
|
|

|






|
|
|

|







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
    "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS"
    "CURRENT_DATECURRENT_TIMESTAMPLANDESCDETACHDISTINCTDROPRAGMATCH"
    "FAILIMITFROMFULLGROUPDATEIFIMMEDIATEINSERTINSTEADINTOFFSETISNULL"
    "JOINORDEREPLACEOUTERESTRICTPRIMARYQUERYRIGHTROLLBACKROWHENUNION"
    "UNIQUEUSINGVACUUMVALUESVIEWHERE";
  static const unsigned char aHash[127] = {
      92,  80, 107,  91,   0,   4,   0,   0, 114,   0,  83,   0,   0,
      96,  44,  76,  93,   0, 106, 109,  97,  90,   0,  10,   0,   0,
     113,   0, 110, 103,   0,  28,  48,   0,  41,   0,   0,  65,  71,
       0,  63,  19,   0, 105,  36, 104,   0, 108,  75,   0,   0,  33,
       0,  61,  37,   0,   8,   0, 115,  38,  12,   0,  77,  40,  25,
      66,   0,   0,  31,  81,  53,  30,  50,  20,  88,   0,  34,   0,
      74,  26,   0,  72,   0,   0,   0,  64,  47,  67,  22,  87,  29,
      69,  86,   0,   1,   0,   9, 101,  58,  18,   0, 112,  82,  99,
      55,   6,  85,   0,   0,  49,  94,   0, 102,   0,  70,   0,   0,
      15,   0, 116,  51,  56,   0,   2,  54,   0, 111,
  };
  static const unsigned char aNext[116] = {
       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,  42,   0,   0,   0,   0,   0,
       0,  16,   0,   0,  23,  52,   0,   0,   0,   0,  45,   0,  59,
       0,   0,   0,   0,   0,   0,   0,   0,  43,  73,   0,  24,  60,
      21,   0,  79,   0,   0,  68,   0,   0,  84,  46,   0,   0,   0,
       0,   0,   0,   0,   0,  39,  95,  98,   0,   0, 100,   0,  32,
       0,  14,  27,  78,   0,  57,  89,   0,  35,   0,  62,   0,
  };
  static const unsigned char aLen[116] = {
       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,   7,   3,   6,   7,   5,  13,   2,   2,   5,   5,   6,
       7,   7,   3,   4,   4,   2,   7,   3,   8,   6,   4,   4,   7,
       6,   6,   8,  10,   9,   6,   5,  12,  17,  12,   4,   4,   6,
       8,   2,   4,   6,   5,   4,   5,   4,   4,   5,   6,   2,   9,
       6,   7,   4,   6,   2,   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[116] = {
       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,
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
    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_AND,        TK_DEFERRABLE, TK_ATTACH,     TK_HAVING,     TK_LIKE_KW,    
    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_IF,         
    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;







|

|







|
|







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
    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_AND,        TK_DEFERRABLE, TK_ATTACH,     TK_HAVING,     TK_LIKE_KW,    
    TK_BEFORE,     TK_FOREIGN,    TK_FOR,        TK_IGNORE,     TK_REINDEX,    
    TK_INDEX,      TK_AUTOINCR,   TK_TO,         TK_IN,         TK_BEGIN,      
    TK_JOIN_KW,    TK_RENAME,     TK_BETWEEN,    TK_NOTNULL,    TK_NOT,        
    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_IF,         
    TK_IMMEDIATE,  TK_INSERT,     TK_INSTEAD,    TK_INTO,       TK_OFFSET,     
    TK_OF,         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;
Changes to SQLite.Interop/src/main.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: main.c,v 1.18 2006/02/02 22:45:10 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The following constant value is used by the SQLITE_BIGENDIAN and







|







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: main.c,v 1.19 2006/02/10 19:45:44 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The following constant value is used by the SQLITE_BIGENDIAN and
1113
1114
1115
1116
1117
1118
1119


















































































































void sqlite3_thread_cleanup(void){
  ThreadData *pTd = sqlite3OsThreadSpecificData(0);
  if( pTd ){
    memset(pTd, 0, sizeof(*pTd));
    sqlite3OsThreadSpecificData(-1);
  }
}

























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
void sqlite3_thread_cleanup(void){
  ThreadData *pTd = sqlite3OsThreadSpecificData(0);
  if( pTd ){
    memset(pTd, 0, sizeof(*pTd));
    sqlite3OsThreadSpecificData(-1);
  }
}

/*
** Return meta information about a specific column of a database table.
** See comment in sqlite3.h (sqlite.h.in) for details.
*/
#ifdef SQLITE_ENABLE_COLUMN_METADATA
int sqlite3_table_column_metadata(
  sqlite3 *db,                /* Connection handle */
  const char *zDbName,        /* Database name or NULL */
  const char *zTableName,     /* Table name */
  const char *zColumnName,    /* Column name */
  char const **pzDataType,    /* OUTPUT: Declared data type */
  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
  int *pAutoinc               /* OUTPUT: True if colums is auto-increment */
){
  int rc;
  char *zErrMsg = 0;
  Table *pTab = 0;
  Column *pCol = 0;
  int iCol;

  char const *zDataType = 0;
  char const *zCollSeq = 0;
  int notnull = 0;
  int primarykey = 0;
  int autoinc = 0;

  /* Ensure the database schema has been loaded */
  if( sqlite3SafetyOn(db) ){
    return SQLITE_MISUSE;
  }
  rc = sqlite3Init(db, &zErrMsg);
  if( SQLITE_OK!=rc ){
    goto error_out;
  }

  /* Locate the table in question */
  pTab = sqlite3FindTable(db, zTableName, zDbName);
  if( !pTab || pTab->pSelect ){
    pTab = 0;
    goto error_out;
  }

  /* Find the column for which info is requested */
  if( sqlite3IsRowid(zColumnName) ){
    iCol = pTab->iPKey;
    if( iCol>=0 ){
      pCol = &pTab->aCol[iCol];
    }
  }else{
    for(iCol=0; iCol<pTab->nCol; iCol++){
      pCol = &pTab->aCol[iCol];
      if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
        break;
      }
    }
    if( iCol==pTab->nCol ){
      pTab = 0;
      goto error_out;
    }
  }

  /* The following block stores the meta information that will be returned
  ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
  ** and autoinc. At this point there are two possibilities:
  ** 
  **     1. The specified column name was rowid", "oid" or "_rowid_" 
  **        and there is no explicitly declared IPK column. 
  **
  **     2. The table is not a view and the column name identified an 
  **        explicitly declared column. Copy meta information from *pCol.
  */ 
  if( pCol ){
    zDataType = pCol->zType;
    zCollSeq = pCol->zColl;
    notnull = (pCol->notNull?1:0);
    primarykey  = (pCol->isPrimKey?1:0);
    autoinc = ((pTab->iPKey==iCol && pTab->autoInc)?1:0);
  }else{
    zDataType = "INTEGER";
    primarykey = 1;
  }
  if( !zCollSeq ){
    zCollSeq = "BINARY";
  }

error_out:
  if( sqlite3SafetyOff(db) ){
    rc = SQLITE_MISUSE;
  }

  /* Whether the function call succeeded or failed, set the output parameters
  ** to whatever their local counterparts contain. If an error did occur,
  ** this has the effect of zeroing all output parameters.
  */
  if( pzDataType ) *pzDataType = zDataType;
  if( pzCollSeq ) *pzCollSeq = zCollSeq;
  if( pNotNull ) *pNotNull = notnull;
  if( pPrimaryKey ) *pPrimaryKey = primarykey;
  if( pAutoinc ) *pAutoinc = autoinc;

  if( SQLITE_OK==rc && !pTab ){
    sqlite3SetString(&zErrMsg, "no such table column: ", zTableName, ".", 
        zColumnName, 0);
    rc = SQLITE_ERROR;
  }
  sqlite3Error(db, rc, (zErrMsg?"%s":0), zErrMsg);
  sqliteFree(zErrMsg);
  return sqlite3ApiExit(db, rc);
}
#endif

Changes to SQLite.Interop/src/opcodes.c.
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
/* Automatically generated.  Do not edit */
/* 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 */ "Pop",
 /*  11 */ "CollSeq",
 /*  12 */ "OpenRead",
 /*  13 */ "Expire",
 /*  14 */ "AutoCommit",

 /*  15 */ "IntegrityCk",
 /*  16 */ "Not",
 /*  17 */ "Sort",
 /*  18 */ "Function",


 /*  19 */ "Noop",
 /*  20 */ "Return",

 /*  21 */ "NewRowid",

 /*  22 */ "IfMemNeg",
 /*  23 */ "Variable",
 /*  24 */ "String",
 /*  25 */ "RealAffinity",
 /*  26 */ "ParseSchema",
 /*  27 */ "Close",
 /*  28 */ "CreateIndex",
 /*  29 */ "IsUnique",
 /*  30 */ "IdxIsNull",
 /*  31 */ "NotFound",
 /*  32 */ "Int64",
 /*  33 */ "MustBeInt",
 /*  34 */ "Halt",
 /*  35 */ "Rowid",
 /*  36 */ "IdxLT",
 /*  37 */ "AddImm",
 /*  38 */ "Statement",
 /*  39 */ "RowData",
 /*  40 */ "MemMax",
 /*  41 */ "Push",

 /*  42 */ "NotExists",
 /*  43 */ "MemIncr",
 /*  44 */ "Gosub",

 /*  45 */ "Integer",

 /*  46 */ "MemInt",
 /*  47 */ "Prev",


 /*  48 */ "CreateTable",
 /*  49 */ "Last",

 /*  50 */ "IdxRowid",
 /*  51 */ "MakeIdxRec",

 /*  52 */ "ResetCount",
 /*  53 */ "FifoWrite",
 /*  54 */ "Callback",
 /*  55 */ "ContextPush",
 /*  56 */ "DropTrigger",
 /*  57 */ "DropIndex",
 /*  58 */ "IdxGE",
 /*  59 */ "Or",
 /*  60 */ "And",
 /*  61 */ "IdxDelete",
 /*  62 */ "Vacuum",
 /*  63 */ "MoveLe",
 /*  64 */ "IsNull",
 /*  65 */ "NotNull",
 /*  66 */ "Ne",
 /*  67 */ "Eq",
 /*  68 */ "Gt",
 /*  69 */ "Le",
 /*  70 */ "Lt",
 /*  71 */ "Ge",
 /*  72 */ "IfNot",
 /*  73 */ "BitAnd",
 /*  74 */ "BitOr",
 /*  75 */ "ShiftLeft",
 /*  76 */ "ShiftRight",
 /*  77 */ "Add",
 /*  78 */ "Subtract",
 /*  79 */ "Multiply",
 /*  80 */ "Divide",
 /*  81 */ "Remainder",
 /*  82 */ "Concat",
 /*  83 */ "Negative",
 /*  84 */ "DropTable",
 /*  85 */ "BitNot",
 /*  86 */ "String8",
 /*  87 */ "MakeRecord",

 /*  88 */ "Delete",
 /*  89 */ "AggFinal",

 /*  90 */ "Dup",
 /*  91 */ "Goto",
 /*  92 */ "TableLock",
 /*  93 */ "FifoRead",
 /*  94 */ "Clear",
 /*  95 */ "IdxGT",
 /*  96 */ "MoveLt",

 /*  97 */ "VerifyCookie",
 /*  98 */ "AggStep",
 /*  99 */ "Pull",



 /* 100 */ "SetNumColumns",
 /* 101 */ "AbsValue",
 /* 102 */ "Transaction",


 /* 103 */ "ContextPop",

 /* 104 */ "Next",
 /* 105 */ "IdxInsert",
 /* 106 */ "Distinct",

 /* 107 */ "Insert",
 /* 108 */ "Destroy",
 /* 109 */ "ReadCookie",
 /* 110 */ "ForceInt",
 /* 111 */ "LoadAnalysis",
 /* 112 */ "OpenVirtual",
 /* 113 */ "Explain",
 /* 114 */ "IfMemZero",
 /* 115 */ "OpenPseudo",
 /* 116 */ "Null",
 /* 117 */ "Blob",

 /* 118 */ "MemStore",
 /* 119 */ "Rewind",
 /* 120 */ "MoveGe",

 /* 121 */ "MemMove",
 /* 122 */ "MemNull",
 /* 123 */ "Found",
 /* 124 */ "Real",
 /* 125 */ "HexBlob",
 /* 126 */ "NullRow",
 /* 127 */ "NotUsed_127",
 /* 128 */ "NotUsed_128",
 /* 129 */ "NotUsed_129",
 /* 130 */ "NotUsed_130",
 /* 131 */ "NotUsed_131",
 /* 132 */ "NotUsed_132",
 /* 133 */ "NotUsed_133",
 /* 134 */ "NotUsed_134",
 /* 135 */ "NotUsed_135",
 /* 136 */ "NotUsed_136",
 /* 137 */ "ToText",
 /* 138 */ "ToBlob",
 /* 139 */ "ToNumeric",
 /* 140 */ "ToInt",
 /* 141 */ "ToReal",
};
#endif





>



>


>

>

>

>
>





>

<


>
>


>

>




















>



>

>


>
>


>


>







<
<



<
<
<
<
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<

<
<

>


>







>



>
>
>



>
>

>



>











>



>



<
<











<
<
<
<
<


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
/* Automatically generated.  Do not edit */
/* 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",
 /* 125 */ "HexBlob",
 /*   2 */ "Column",
 /*   3 */ "SetCookie",
 /*   4 */ "IfMemPos",
 /* 124 */ "Real",
 /*   5 */ "Sequence",
 /*   6 */ "MoveGt",
 /*  71 */ "Ge",
 /*   7 */ "RowKey",
 /*  67 */ "Eq",
 /*   8 */ "OpenWrite",
 /*  65 */ "NotNull",
 /*   9 */ "If",
 /* 140 */ "ToInt",
 /*  86 */ "String8",
 /*  10 */ "Pop",
 /*  11 */ "CollSeq",
 /*  12 */ "OpenRead",
 /*  13 */ "Expire",
 /*  14 */ "AutoCommit",
 /*  68 */ "Gt",
 /*  15 */ "IntegrityCk",

 /*  17 */ "Sort",
 /*  18 */ "Function",
 /*  60 */ "And",
 /*  78 */ "Subtract",
 /*  19 */ "Noop",
 /*  20 */ "Return",
 /*  81 */ "Remainder",
 /*  21 */ "NewRowid",
 /*  79 */ "Multiply",
 /*  22 */ "IfMemNeg",
 /*  23 */ "Variable",
 /*  24 */ "String",
 /*  25 */ "RealAffinity",
 /*  26 */ "ParseSchema",
 /*  27 */ "Close",
 /*  28 */ "CreateIndex",
 /*  29 */ "IsUnique",
 /*  30 */ "IdxIsNull",
 /*  31 */ "NotFound",
 /*  32 */ "Int64",
 /*  33 */ "MustBeInt",
 /*  34 */ "Halt",
 /*  35 */ "Rowid",
 /*  36 */ "IdxLT",
 /*  37 */ "AddImm",
 /*  38 */ "Statement",
 /*  39 */ "RowData",
 /*  40 */ "MemMax",
 /*  41 */ "Push",
 /*  59 */ "Or",
 /*  42 */ "NotExists",
 /*  43 */ "MemIncr",
 /*  44 */ "Gosub",
 /*  80 */ "Divide",
 /*  45 */ "Integer",
 /* 139 */ "ToNumeric",
 /*  46 */ "MemInt",
 /*  47 */ "Prev",
 /*  82 */ "Concat",
 /*  73 */ "BitAnd",
 /*  48 */ "CreateTable",
 /*  49 */ "Last",
 /*  64 */ "IsNull",
 /*  50 */ "IdxRowid",
 /*  51 */ "MakeIdxRec",
 /*  76 */ "ShiftRight",
 /*  52 */ "ResetCount",
 /*  53 */ "FifoWrite",
 /*  54 */ "Callback",
 /*  55 */ "ContextPush",
 /*  56 */ "DropTrigger",
 /*  57 */ "DropIndex",
 /*  58 */ "IdxGE",


 /*  61 */ "IdxDelete",
 /*  62 */ "Vacuum",
 /*  63 */ "MoveLe",








 /*  72 */ "IfNot",











 /*  84 */ "DropTable",


 /*  87 */ "MakeRecord",
 /* 138 */ "ToBlob",
 /*  88 */ "Delete",
 /*  89 */ "AggFinal",
 /*  75 */ "ShiftLeft",
 /*  90 */ "Dup",
 /*  91 */ "Goto",
 /*  92 */ "TableLock",
 /*  93 */ "FifoRead",
 /*  94 */ "Clear",
 /*  95 */ "IdxGT",
 /*  96 */ "MoveLt",
 /*  69 */ "Le",
 /*  97 */ "VerifyCookie",
 /*  98 */ "AggStep",
 /*  99 */ "Pull",
 /* 137 */ "ToText",
 /*  16 */ "Not",
 /* 141 */ "ToReal",
 /* 100 */ "SetNumColumns",
 /* 101 */ "AbsValue",
 /* 102 */ "Transaction",
 /*  83 */ "Negative",
 /*  66 */ "Ne",
 /* 103 */ "ContextPop",
 /*  74 */ "BitOr",
 /* 104 */ "Next",
 /* 105 */ "IdxInsert",
 /* 106 */ "Distinct",
 /*  70 */ "Lt",
 /* 107 */ "Insert",
 /* 108 */ "Destroy",
 /* 109 */ "ReadCookie",
 /* 110 */ "ForceInt",
 /* 111 */ "LoadAnalysis",
 /* 112 */ "OpenVirtual",
 /* 113 */ "Explain",
 /* 114 */ "IfMemZero",
 /* 115 */ "OpenPseudo",
 /* 116 */ "Null",
 /* 117 */ "Blob",
 /*  77 */ "Add",
 /* 118 */ "MemStore",
 /* 119 */ "Rewind",
 /* 120 */ "MoveGe",
 /*  85 */ "BitNot",
 /* 121 */ "MemMove",
 /* 122 */ "MemNull",
 /* 123 */ "Found",


 /* 126 */ "NullRow",
 /* 127 */ "NotUsed_127",
 /* 128 */ "NotUsed_128",
 /* 129 */ "NotUsed_129",
 /* 130 */ "NotUsed_130",
 /* 131 */ "NotUsed_131",
 /* 132 */ "NotUsed_132",
 /* 133 */ "NotUsed_133",
 /* 134 */ "NotUsed_134",
 /* 135 */ "NotUsed_135",
 /* 136 */ "NotUsed_136",





};
#endif
Changes to SQLite.Interop/src/os_unix.c.
1056
1057
1058
1059
1060
1061
1062





1063
1064
1065
1066
1067
1068
1069
1070
  if( full_fsync(pFile->h, pFile->fullSync, dataOnly) ){
    return SQLITE_IOERR;
  }
  if( pFile->dirfd>=0 ){
    TRACE2("DIRSYNC %-3d\n", pFile->dirfd);
#ifndef SQLITE_DISABLE_DIRSYNC
    if( full_fsync(pFile->dirfd, pFile->fullSync, 0) ){





        return SQLITE_IOERR;
    }
#endif
    close(pFile->dirfd);  /* Only need to sync once, so close the directory */
    pFile->dirfd = -1;    /* when we are done. */
  }
  return SQLITE_OK;
}







>
>
>
>
>
|







1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
  if( full_fsync(pFile->h, pFile->fullSync, dataOnly) ){
    return SQLITE_IOERR;
  }
  if( pFile->dirfd>=0 ){
    TRACE2("DIRSYNC %-3d\n", pFile->dirfd);
#ifndef SQLITE_DISABLE_DIRSYNC
    if( full_fsync(pFile->dirfd, pFile->fullSync, 0) ){
       /* We have received multiple reports of fsync() returning
       ** errors when applied to directories on certain file systems.
       ** A failed directory sync is not a big deal.  So it seems
       ** better to ignore the error.  Ticket #1657
       */
       /* return SQLITE_IOERR; */
    }
#endif
    close(pFile->dirfd);  /* Only need to sync once, so close the directory */
    pFile->dirfd = -1;    /* when we are done. */
  }
  return SQLITE_OK;
}
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
#else
  sleep((ms+999)/1000);
  return 1000*((ms+999)/1000);
#endif
}

/*
** Static variables used for thread synchronization




























*/
static int inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
static pthread_t mutexOwner;

static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
#endif

/*
** The following pair of routine implement mutual exclusion for
** multi-threaded processes.  Only a single thread is allowed to
** executed code that is surrounded by EnterMutex() and LeaveMutex().
**
** SQLite uses only a single Mutex.  There is not much critical
** code and what little there is executes quickly and without blocking.
**
** As of version 3.3.2, this mutex must be recursive.
*/
void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS
  pthread_mutex_lock(&mutex1);



  if( inMutex==0 ){

    pthread_mutex_lock(&mutex2);
    mutexOwner = pthread_self();

  }

  pthread_mutex_unlock(&mutex1);
#endif
  inMutex++;

}
void sqlite3UnixLeaveMutex(){
  assert( inMutex>0 );
#ifdef SQLITE_UNIX_THREADS
  assert( pthread_equal(mutexOwner, pthread_self()) );
  pthread_mutex_lock(&mutex1);
  inMutex--;

  if( inMutex==0 ){


    pthread_mutex_unlock(&mutex2);
  }
  pthread_mutex_unlock(&mutex1);
#else
  inMutex--;
#endif
}

/*
** Return TRUE if the mutex is currently held.
**
** If the thisThreadOnly parameter is true, return true only if the
** calling thread holds the mutex.  If the parameter is false, return
** true if any thread holds the mutex.
*/
int sqlite3UnixInMutex(int thisThreadOnly){
#ifdef SQLITE_UNIX_THREADS




  return inMutex>0 && 
           (thisThreadOnly==0 || pthread_equal(mutexOwner, pthread_self()));
#else
  return inMutex>0;
#endif
}

/*
** Remember the number of thread-specific-data blocks allocated.







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



|
>
|
|














|
>
>
>
|
>
|

>

>
|
|
|
>




<
|

>

>
>
|

|








|



|

>
>
>
>
|
<







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
#else
  sleep((ms+999)/1000);
  return 1000*((ms+999)/1000);
#endif
}

/*
** Static variables used for thread synchronization.
**
** inMutex      the nesting depth of the recursive mutex.  The thread
**              holding mutexMain can read this variable at any time.
**              But is must hold mutexAux to change this variable.  Other
**              threads must hold mutexAux to read the variable and can
**              never write.
**
** mutexOwner   The thread id of the thread holding mutexMain.  Same
**              access rules as for inMutex.
**
** mutexOwnerValid   True if the value in mutexOwner is valid.  The same
**                   access rules apply as for inMutex.
**
** mutexMain    The main mutex.  Hold this mutex in order to get exclusive
**              access to SQLite data structures.
**
** mutexAux     An auxiliary mutex needed to access variables defined above.
**
** Mutexes are always acquired in this order: mutexMain mutexAux.   It
** is not necessary to acquire mutexMain in order to get mutexAux - just
** do not attempt to acquire them in the reverse order: mutexAux mutexMain.
** Either get the mutexes with mutexMain first or get mutexAux only.
**
** When running on a platform where the three variables inMutex, mutexOwner,
** and mutexOwnerValid can be set atomically, the mutexAux is not required.
** On many systems, all three are 32-bit integers and writing to a 32-bit
** integer is atomic.  I think.  But there are no guarantees.  So it seems
** safer to protect them using mutexAux.
*/
static int inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
static pthread_t mutexOwner;          /* Thread holding mutexMain */
static int mutexOwnerValid = 0;       /* True if mutexOwner is valid */
static pthread_mutex_t mutexMain = PTHREAD_MUTEX_INITIALIZER; /* The mutex */
static pthread_mutex_t mutexAux = PTHREAD_MUTEX_INITIALIZER;  /* Aux mutex */
#endif

/*
** The following pair of routine implement mutual exclusion for
** multi-threaded processes.  Only a single thread is allowed to
** executed code that is surrounded by EnterMutex() and LeaveMutex().
**
** SQLite uses only a single Mutex.  There is not much critical
** code and what little there is executes quickly and without blocking.
**
** As of version 3.3.2, this mutex must be recursive.
*/
void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS
  pthread_mutex_lock(&mutexAux);
  if( !mutexOwnerValid || !pthread_equal(mutexOwner, pthread_self()) ){
    pthread_mutex_unlock(&mutexAux);
    pthread_mutex_lock(&mutexMain);
    assert( inMutex==0 );
    assert( !mutexOwnerValid );
    pthread_mutex_lock(&mutexAux);
    mutexOwner = pthread_self();
    mutexOwnerValid = 1;
  }
  inMutex++;
  pthread_mutex_unlock(&mutexAux);
#else
  inMutex++
#endif
}
void sqlite3UnixLeaveMutex(){
  assert( inMutex>0 );
#ifdef SQLITE_UNIX_THREADS

  pthread_mutex_lock(&mutexAux);
  inMutex--;
  assert( pthread_equal(mutexOwner, pthread_self()) );
  if( inMutex==0 ){
    assert( mutexOwnerValid );
    mutexOwnerValid = 0;
    pthread_mutex_unlock(&mutexMain);
  }
  pthread_mutex_unlock(&mutexAux);
#else
  inMutex--;
#endif
}

/*
** Return TRUE if the mutex is currently held.
**
** If the thisThrd parameter is true, return true only if the
** calling thread holds the mutex.  If the parameter is false, return
** true if any thread holds the mutex.
*/
int sqlite3UnixInMutex(int thisThrd){
#ifdef SQLITE_UNIX_THREADS
  int rc;
  pthread_mutex_lock(&mutexAux);
  rc = inMutex>0 && (thisThrd==0 || pthread_equal(mutexOwner,pthread_self()));
  pthread_mutex_unlock(&mutexAux);
  return rc;

#else
  return inMutex>0;
#endif
}

/*
** Remember the number of thread-specific-data blocks allocated.
Changes to SQLite.Interop/src/parse.c.
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
**  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 */   279,   68,  283,   70,  148,  166,  546,  419,   62,   62,
 /*    10 */    62,   62,  202,   64,   64,   64,   64,   65,   65,   66,
 /*    20 */    66,   66,   67,   67,  548,  549,  432,   69,   64,   64,
 /*    30 */    64,   64,   65,   65,   66,   66,   66,   67,   68,  454,
 /*    40 */    70,  148,  499,   61,   59,  287,  440,  441,  437,  437,
 /*    50 */    63,   63,   62,   62,   62,   62,  501,   64,   64,   64,
 /*    60 */    64,   65,   65,   66,   66,   66,   67,  279,  371,  283,
 /*    70 */   419,    2,  377,   80,  158,  115,  220,  304,  225,  305,
 /*    80 */   170,  245,  856,  119,  559,  504,  204,    2,  246,  389,
 /*    90 */   496,  219,   22,  432,  514,   21,  419,   58,  493,  171,
 /*   100 */    64,   64,   64,   64,   65,   65,   66,   66,   66,   67,
 /*   110 */    61,   59,  287,  440,  441,  437,  437,   63,   63,   62,
 /*   120 */    62,   62,   62,  512,   64,   64,   64,   64,   65,   65,
 /*   130 */    66,   66,   66,   67,  279,  378,  379,  175,  202,  377,
 /*   140 */   330,  333,  334,  220,  304,  225,  305,  170,  245,  203,
 /*   150 */   146,  357,  335,  281,  377,  246,   55,  301,  373,  419,
 /*   160 */   432,  505,   92,  200,  530,   66,   66,   66,   67,  525,
 /*   170 */   192,   65,   65,   66,   66,   66,   67,   61,   59,  287,
 /*   180 */   440,  441,  437,  437,   63,   63,   62,   62,   62,   62,
 /*   190 */   433,   64,   64,   64,   64,   65,   65,   66,   66,   66,
 /*   200 */    67,  279,  378,  379,  411,  431,  110,  226,  427,  205,
 /*   210 */   435,  436,  308,  358,  261,  260,  175,  378,  379,  330,
 /*   220 */   333,  334,  372,  369,  202,  511,  480,  432,  547,  362,
 /*   230 */   466,  335,  510,  500,  410,   41,  276,  414,  434,  429,
 /*   240 */   503,  162,  233,  527,   61,   59,  287,  440,  441,  437,
 /*   250 */   437,   63,   63,   62,   62,   62,   62,  319,   64,   64,
 /*   260 */    64,   64,   65,   65,   66,   66,   66,   67,  279,  472,
 /*   270 */   416,  416,  416,  308,  322,  236,  308,   68,  308,   70,
 /*   280 */   148,    1,  308,  793,  308,  377,   68,  153,   70,  148,
 /*   290 */   149,  377,  325,  282,  432,  410,   35,  551,  410,   35,
 /*   300 */   410,   36,  427,  205,  410,   35,  410,   35,  286,  422,
 /*   310 */   423,   61,   59,  287,  440,  441,  437,  437,   63,   63,
 /*   320 */    62,   62,   62,   62,  411,   64,   64,   64,   64,   65,
 /*   330 */    65,   66,   66,   66,   67,  308,  504,  466,  290,  255,
 /*   340 */   279,  324,  485,  147,  237,  388,   21,  288,  378,  379,
 /*   350 */   451,  419,  232,  451,  378,  379,  308,  410,   28,  451,
 /*   360 */   175,  450,  486,  330,  333,  334,  432,  215,  347,  145,
 /*   370 */   513,  204,  350,  186,  168,  335,  238,  411,  410,   41,
 /*   380 */   256,  462,   76,   61,   59,  287,  440,  441,  437,  437,
 /*   390 */    63,   63,   62,   62,   62,   62,  309,   64,   64,   64,
 /*   400 */    64,   65,   65,   66,   66,   66,   67,  411,  411,  186,
 /*   410 */   396,  308,  279,  291,  419,  338,  476,  308,  390,  234,
 /*   420 */   169,  154,  397,  475,  396,  327,  493,  311,  422,  423,
 /*   430 */   444,  377,  356,  410,   49,  398,  397,  394,  432,  410,
 /*   440 */    49,  502,  171,  411,  429,  312,  162,  395,  351,  398,
 /*   450 */   497,  318,  470,  352,   79,   61,   59,  287,  440,  441,
 /*   460 */   437,  437,   63,   63,   62,   62,   62,   62,  356,   64,
 /*   470 */    64,   64,   64,   65,   65,   66,   66,   66,   67,  279,
 /*   480 */   298,  445,  376,  479,  532,  405,  299,   11,  504,  352,
 /*   490 */   204,  377,  406,  377,  378,  379,  281,  556,   21,  491,
 /*   500 */   491,  246,  560,  372,  369,  432,  392,  393,  314,  123,
 /*   510 */   443,  443,  166,  289,  419,  314,  116,  443,  443,  251,
 /*   520 */   264,  463,   61,   59,  287,  440,  441,  437,  437,   63,
 /*   530 */    63,   62,   62,   62,   62,  292,   64,   64,   64,   64,
 /*   540 */    65,   65,   66,   66,   66,   67,  279,  459,  328,  474,
 /*   550 */   498,  308,  202,  308,  378,  379,  378,  379,  181,  131,
 /*   560 */   179,  265,  308,    5,  308,  363,  314,  355,  443,  443,
 /*   570 */   410,    3,  432,  410,   29,  410,   24,  419,  243,  244,
 /*   580 */   380,  381,  382,  404,  410,   33,  410,   54,  466,   61,
 /*   590 */    59,  287,  440,  441,  437,  437,   63,   63,   62,   62,
 /*   600 */    62,   62,  308,   64,   64,   64,   64,   65,   65,   66,
 /*   610 */    66,   66,   67,  279,  521,  344,  521,  249,  308,  491,
 /*   620 */   308,  470,  308,  470,  410,   25,  308,  240,  308,  314,
 /*   630 */   308,  443,  443,  213,  172,  173,  174,  142,  266,  432,
 /*   640 */   410,   52,  410,   97,  410,   94,  528,  393,  410,   99,
 /*   650 */   410,  100,  410,  111,  212,  255,   61,   59,  287,  440,
 /*   660 */   441,  437,  437,   63,   63,   62,   62,   62,   62,  308,
 /*   670 */    64,   64,   64,   64,   65,   65,   66,   66,   66,   67,
 /*   680 */   279,  308,  345,  188,  297,   91,  308,  491,  308,  415,
 /*   690 */   308,  410,  112,  308,  428,  308,  537,  308,  244,  165,
 /*   700 */   154,  409,  355,  410,   18,  408,  432,  320,  410,   98,
 /*   710 */   410,   34,  410,   95,  313,  410,   53,  410,  113,  410,
 /*   720 */   114,  255,  293,   61,   59,  287,  440,  441,  437,  437,
 /*   730 */    63,   63,   62,   62,   62,   62,  308,   64,   64,   64,
 /*   740 */    64,   65,   65,   66,   66,   66,   67,  279,  308,  491,
 /*   750 */   491,  523,  308,  452,  308,  522,  308,  461,  410,   26,
 /*   760 */   308,   75,  539,   77,  308,  460,  244,  346,  214,  465,
 /*   770 */   410,   37,  469,  432,  410,   38,  410,   27,  410,   39,
 /*   780 */   242,   82,  410,   40,  294,  296,  410,   42,  438,  329,
 /*   790 */    61,   59,  287,  440,  441,  437,  437,   63,   63,   62,
 /*   800 */    62,   62,   62,  308,   64,   64,   64,   64,   65,   65,
 /*   810 */    66,   66,   66,   67,  279,  308,  409,  190,  221,  308,
 /*   820 */   408,  308,  152,  308,  159,  410,   43,  308,  244,  244,
 /*   830 */   222,   20,  308,  139,  425,  425,  481,  410,   44,  482,
 /*   840 */   432,  410,   30,  410,   31,  410,   45,  487,  461,  410,
 /*   850 */    46,  411,  506,  255,  410,   47,  488,   61,   71,  287,
 /*   860 */   440,  441,  437,  437,   63,   63,   62,   62,   62,   62,
 /*   870 */   308,   64,   64,   64,   64,   65,   65,   66,   66,   66,
 /*   880 */    67,  279,  308,  401,  402,  250,  308,  193,  308,  420,
 /*   890 */   308,   23,  410,   48,  540,  449,  255,   14,  468,  477,
 /*   900 */   167,   14,  484,  483,  410,   32,  252,  432,  410,   12,
 /*   910 */   410,   50,  410,   51,  255,  255,  594,  255,  255,  150,
 /*   920 */   489,  411,  123,  253,  279,   59,  287,  440,  441,  437,
 /*   930 */   437,   63,   63,   62,   62,   62,   62,  541,   64,   64,
 /*   940 */    64,   64,   65,   65,   66,   66,   66,   67,  254,  248,
 /*   950 */   432,  123,  337,  411,  123,  267,  269,  196,  361,  366,
 /*   960 */   183,  177,  180,  519,  520,  526,  534,  123,  167,  287,
 /*   970 */   440,  441,  437,  437,   63,   63,   62,   62,   62,   62,
 /*   980 */   342,   64,   64,   64,   64,   65,   65,   66,   66,   66,
 /*   990 */    67,   72,  315,  259,    4,  411,  411,  535,  285,   89,
 /*  1000 */   544,  349,   89,  353,  354,   19,  310,   72,  315,  368,
 /*  1010 */     4,  386,  262,  263,  285,  223,  545,  270,  364,  273,
 /*  1020 */   274,  141,  310,  317,  227,  316,  555,  424,  426,  480,
 /*  1030 */   455,  458,  490,  431,  332,  492,  533,  157,  543,  317,
 /*  1040 */   375,  383,  384,  385,    8,  302,  303,  391,  284,  431,
 /*  1050 */   404,  399,   74,   73,  224,  403,  407,   82,  323,  321,
 /*  1060 */    72,  306,  307,  400,  231,  414,   81,  206,   74,   73,
 /*  1070 */   473,   57,   78,  164,  453,  412,   72,  306,  307,   72,
 /*  1080 */   315,  414,    4,  228,  202,  229,  285,  235,  230,  456,
 /*  1090 */   457,  413,  207,  120,  310,   83,  326,  102,  416,  416,
 /*  1100 */   416,  417,  418,   13,  239,  495,  467,  241,  277,  208,
 /*  1110 */   471,  317,  494,  210,  416,  416,  416,  417,  418,   13,
 /*  1120 */   211,  431,  156,  278,  339,  507,  508,  216,  217,  218,
 /*  1130 */   106,  509,  515,  178,  343,   84,  341,  182,  517,  456,
 /*  1140 */    74,   73,   86,  198,  518,  271,  257,  184,   72,  306,
 /*  1150 */   307,  348,  272,  414,  118,  529,  187,  127,  536,  359,
 /*  1160 */   128,  136,  129,  542,  195,  130,  530,  133,  300,  552,
 /*  1170 */   553,  194,  137,  197,  431,   90,  554,  557,   96,  209,
 /*  1180 */   101,  374,  387,  117,  201,   56,  416,  416,  416,  417,
 /*  1190 */   418,   13,   93,  143,  144,  595,  596,  109,  160,  161,
 /*  1200 */    60,  439,  500,  421,  430,  442,  414,  138,  446,  151,
 /*  1210 */     6,  447,  155,  448,  163,  360,  268,  260,   15,    7,
 /*  1220 */    14,  280,  121,  464,  122,  478,  202,  103,  104,  331,
 /*  1230 */   247,   85,  105,  336,  222,  176,  340,  140,  516,  416,
 /*  1240 */   416,  416,  124,  295,  125,  167,  524,  258,  107,  185,
 /*  1250 */   365,    9,  531,   10,  126,  189,   16,  538,  191,  132,
 /*  1260 */   134,   87,   88,  135,   17,  108,  275,  550,  367,  199,
 /*  1270 */   370,  536,  558,
};
static const YYCODETYPE yy_lookahead[] = {
 /*     0 */    16,  216,   16,  218,  219,   21,  146,   23,   68,   69,
 /*    10 */    70,   71,  109,   73,   74,   75,   76,   77,   78,   79,
 /*    20 */    80,   81,   82,   82,  164,  165,   42,   72,   73,   74,
 /*    30 */    75,   76,   77,   78,   79,   80,   81,   82,  216,  217,
 /*    40 */   218,  219,  168,   59,   60,   61,   62,   63,   64,   65,
 /*    50 */    66,   67,   68,   69,   70,   71,  168,   73,   74,   75,
 /*    60 */    76,   77,   78,   79,   80,   81,   82,   16,  140,   16,

 /*    70 */    86,  143,   23,   22,   88,   89,   90,   91,   92,   93,
 /*    80 */    94,   95,  138,  139,  140,  146,  226,  143,  102,  166,
 /*    90 */   167,  152,   19,   42,  155,  156,   23,   46,  175,   43,
 /*   100 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
 /*   110 */    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,
 /*   120 */    69,   70,   71,  180,   73,   74,   75,   76,   77,   78,
 /*   130 */    79,   80,   81,   82,   16,   86,   87,   88,  109,   23,
 /*   140 */    91,   92,   93,   90,   91,   92,   93,   94,   95,  191,
 /*   150 */    22,  122,  103,   97,   23,  102,  198,  141,  142,   86,
 /*   160 */    42,  180,   44,  147,   49,   79,   80,   81,   82,   18,
 /*   170 */   154,   77,   78,   79,   80,   81,   82,   59,   60,   61,
 /*   180 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   190 */    42,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   200 */    82,   16,   86,   87,  188,   58,   21,  189,   77,   78,
 /*   210 */    62,   63,  146,   98,   99,  100,   88,   86,   87,   91,
 /*   220 */    92,   93,    1,    2,  109,  175,  176,   42,   97,  213,
 /*   230 */   160,  103,  182,   86,  168,  169,  157,   90,   90,  160,
 /*   240 */   161,  162,  146,   92,   59,   60,   61,   62,   63,   64,
 /*   250 */    65,   66,   67,   68,   69,   70,   71,  185,   73,   74,
 /*   260 */    75,   76,   77,   78,   79,   80,   81,   82,   16,  199,
 /*   270 */   123,  124,  125,  146,  208,  209,  146,  216,  146,  218,
 /*   280 */   219,   19,  146,  132,  146,   23,  216,  146,  218,  219,
 /*   290 */   154,   23,  146,  149,   42,  168,  169,  236,  168,  169,
 /*   300 */   168,  169,   77,   78,  168,  169,  168,  169,  163,  164,
 /*   310 */   165,   59,   60,   61,   62,   63,   64,   65,   66,   67,
 /*   320 */    68,   69,   70,   71,  188,   73,   74,   75,   76,   77,
 /*   330 */    78,   79,   80,   81,   82,  146,  146,  160,  211,  146,
 /*   340 */    16,  211,   30,  154,  146,  155,  156,  211,   86,   87,
 /*   350 */   223,   23,  220,  223,   86,   87,  146,  168,  169,  223,
 /*   360 */    88,  223,   50,   91,   92,   93,   42,  144,  224,  179,
 /*   370 */   180,  226,  228,  154,  154,  103,  199,  188,  168,  169,
 /*   380 */   187,  113,  130,   59,   60,   61,   62,   63,   64,   65,
 /*   390 */    66,   67,   68,   69,   70,   71,  146,   73,   74,   75,
 /*   400 */    76,   77,   78,   79,   80,   81,   82,  188,  188,  154,
 /*   410 */    12,  146,   16,  101,   86,   16,   20,  146,  167,  209,
 /*   420 */   200,  201,   24,   20,   12,  205,  175,  163,  164,  165,
 /*   430 */    20,   23,  213,  168,  169,   37,   24,   39,   42,  168,
 /*   440 */   169,  159,   43,  188,  160,  161,  162,   49,  229,   37,
 /*   450 */   168,   39,  146,  234,  130,   59,   60,   61,   62,   63,
 /*   460 */    64,   65,   66,   67,   68,   69,   70,   71,  213,   73,
 /*   470 */    74,   75,   76,   77,   78,   79,   80,   81,   82,   16,
 /*   480 */   215,   20,  146,   20,  229,   27,  215,   19,  146,  234,
 /*   490 */   226,   23,   34,   23,   86,   87,   97,  155,  156,  146,
 /*   500 */   146,  102,    0,    1,    2,   42,  184,  185,  105,   22,
 /*   510 */   107,  108,   21,  207,   23,  105,  146,  107,  108,   14,
 /*   520 */    14,  113,   59,   60,   61,   62,   63,   64,   65,   66,
 /*   530 */    67,   68,   69,   70,   71,  181,   73,   74,   75,   76,
 /*   540 */    77,   78,   79,   80,   81,   82,   16,   22,  146,   79,
 /*   550 */    20,  146,  109,  146,   86,   87,   86,   87,   53,   53,
 /*   560 */    55,   55,  146,  190,  146,  122,  105,  146,  107,  108,
 /*   570 */   168,  169,   42,  168,  169,  168,  169,   86,  225,  225,
 /*   580 */     7,    8,    9,   96,  168,  169,  168,  169,  160,   59,
 /*   590 */    60,   61,   62,   63,   64,   65,   66,   67,   68,   69,
 /*   600 */    70,   71,  146,   73,   74,   75,   76,   77,   78,   79,
 /*   610 */    80,   81,   82,   16,   98,   99,  100,   20,  146,  146,
 /*   620 */   146,  146,  146,  146,  168,  169,  146,  199,  146,  105,
 /*   630 */   146,  107,  108,  212,   98,   99,  100,  112,  132,   42,
 /*   640 */   168,  169,  168,  169,  168,  169,  184,  185,  168,  169,
 /*   650 */   168,  169,  168,  169,  181,  146,   59,   60,   61,   62,
 /*   660 */    63,   64,   65,   66,   67,   68,   69,   70,   71,  146,
 /*   670 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
 /*   680 */    16,  146,  207,   22,  207,   21,  146,  146,  146,  146,
 /*   690 */   146,  168,  169,  146,  160,  146,  187,  146,  225,  200,
 /*   700 */   201,  106,  146,  168,  169,  110,   42,  146,  168,  169,
 /*   710 */   168,  169,  168,  169,   16,  168,  169,  168,  169,  168,
 /*   720 */   169,  146,  181,   59,   60,   61,   62,   63,   64,   65,
 /*   730 */    66,   67,   68,   69,   70,   71,  146,   73,   74,   75,
 /*   740 */    76,   77,   78,   79,   80,   81,   82,   16,  146,  146,
 /*   750 */   146,   25,  146,  146,  146,   29,  146,   22,  168,  169,
 /*   760 */   146,  129,  187,  131,  146,  202,  225,   41,  212,  146,
 /*   770 */   168,  169,  146,   42,  168,  169,  168,  169,  168,  169,
 /*   780 */   146,  120,  168,  169,  181,  181,  168,  169,   90,   79,
 /*   790 */    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,
 /*   800 */    69,   70,   71,  146,   73,   74,   75,   76,   77,   78,
 /*   810 */    79,   80,   81,   82,   16,  146,  106,  154,   90,  146,
 /*   820 */   110,  146,   87,  146,   19,  168,  169,  146,  225,  225,
 /*   830 */   102,   19,  146,   21,  123,  124,  146,  168,  169,  177,
 /*   840 */    42,  168,  169,  168,  169,  168,  169,  177,  113,  168,
 /*   850 */   169,  188,  146,  146,  168,  169,  177,   59,   60,   61,
 /*   860 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   870 */   146,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   880 */    82,   16,  146,    7,    8,  146,  146,  154,  146,   20,
 /*   890 */   146,   22,  168,  169,  187,   20,  146,   22,   20,   20,
 /*   900 */    22,   22,   89,   90,  168,  169,  146,   42,  168,  169,
 /*   910 */   168,  169,  168,  169,  146,  146,  111,  146,  146,  154,
 /*   920 */    20,  188,   22,  146,   16,   60,   61,   62,   63,   64,
 /*   930 */    65,   66,   67,   68,   69,   70,   71,  187,   73,   74,
 /*   940 */    75,   76,   77,   78,   79,   80,   81,   82,  146,   20,
 /*   950 */    42,   22,   20,  188,   22,  187,  187,   19,  187,  187,
 /*   960 */   230,  154,  154,   51,   52,   20,   20,   22,   22,   61,
 /*   970 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   980 */   231,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   990 */    82,   16,   17,  146,   19,  188,  188,   20,   23,   22,
 /*  1000 */    20,  146,   22,  146,  146,   67,   31,   16,   17,  237,
 /*  1010 */    19,  148,  146,  146,   23,  171,  146,  146,  146,  146,
 /*  1020 */   146,  190,   31,   48,  192,  222,  146,  227,  227,  176,
 /*  1030 */   171,  171,  171,   58,  172,  171,  193,    6,  193,   48,
 /*  1040 */   145,  145,  145,  145,   22,  153,   97,  170,   40,   58,
 /*  1050 */    96,  170,   77,   78,  170,  172,  170,  120,  117,  115,
 /*  1060 */    85,   86,   87,  178,  196,   90,  118,  221,   77,   78,
 /*  1070 */    79,  119,  129,  111,  151,  188,   85,   86,   87,   16,
 /*  1080 */    17,   90,   19,  193,  109,  194,   23,   95,  195,   23,
 /*  1090 */   159,  197,  210,  151,   31,   97,  114,   19,  123,  124,
 /*  1100 */   125,  126,  127,  128,  203,  178,  204,  203,  173,  210,
 /*  1110 */   204,   48,  159,  210,  123,  124,  125,  126,  127,  128,
 /*  1120 */   210,   58,    5,  173,   15,  170,  170,   10,   11,   12,
 /*  1130 */    13,  170,  151,  150,   38,   19,  151,  151,  151,   23,
 /*  1140 */    77,   78,  129,   26,  233,   28,  232,  150,   85,   86,
 /*  1150 */    87,  151,   35,   90,   59,  183,  183,   19,  193,   15,
 /*  1160 */   186,  214,  186,  193,   47,  186,   49,  183,  151,   33,
 /*  1170 */   151,   54,  214,   56,   58,  235,  151,  136,  158,  174,
 /*  1180 */   174,    1,   20,   32,   44,   19,  123,  124,  125,  126,
 /*  1190 */   127,  128,  235,   77,   78,  111,  111,  238,  111,  111,
 /*  1200 */    19,   90,   86,   20,   20,  106,   90,   19,   11,   19,
 /*  1210 */   116,   20,  111,   20,   22,   98,   99,  100,   22,  116,
 /*  1220 */    22,  104,   19,  113,   20,   20,  109,   19,   19,   44,
 /*  1230 */    20,   19,   19,   44,  102,   94,   16,   21,   17,  123,
 /*  1240 */   124,  125,   97,   36,   45,   22,   45,  132,   19,   97,
 /*  1250 */   133,    5,   11,    1,  101,  121,   19,   17,  112,  112,
 /*  1260 */   101,   67,   67,  121,   19,   14,  135,   20,   57,  134,
 /*  1270 */     3,  239,    4,
};
#define YY_SHIFT_USE_DFLT (-98)
#define YY_SHIFT_MAX 370
static const short yy_shift_ofst[] = {
 /*     0 */   221,  975, 1117,  -16,  975, 1063, 1063, 1063,   49,  115,
 /*    10 */   115,  -97,  118, 1063, 1063, 1063, 1063, 1063,  -45,  131,
 /*    20 */   116,  328,  225,  225,   51,  185,  252,  324,  396,  463,
 /*    30 */   530,  597,  664,  731,  798,  731,  731,  731,  731,  731,
 /*    40 */   731,  731,  731,  731,  731,  731,  731,  731,  731,  731,
 /*    50 */   731,  731,  865,  908,  908,  991, 1063, 1063, 1063, 1063,
 /*    60 */  1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
 /*    70 */  1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
 /*    80 */  1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
 /*    90 */  1063, 1063, 1063, 1063,  -60,  -60,  -14,   27,   27,   94,
 /*   100 */    86,  399,  116,  116,  116,  116,  151,  116,  116,  116,
 /*   110 */   328,  -59,  -98,  -98,  -98, 1116,   53,  398,  398,  502,
 /*   120 */   491,  116,  491,  116,  116,  116,  116,  116,  116,  116,
 /*   130 */   116,  116,  116,  116,  116,  116,   29,  443,  -97,  -97,
 /*   140 */   -97,  -98,  -98,  147,  147,  128,  272,  403,  262,  410,
 /*   150 */   461,  412,  268,  408,  468,  470,  573,  116,  116,  710,
 /*   160 */   116,  116,   73,  116,  116,  735,  116,  116,  524,  735,
 /*   170 */   116,  116,  312,  312,  312,  116,  116,  524,  116,  116,
 /*   180 */   524,  116,  726,  516,  116,  116,  524,  116,  116,  116,
 /*   190 */   524,  116,  524,  524,  116,  116,  116,  116,  116,  116,
 /*   200 */   812,  458,  595,  525,  711,  711,  632,  458,  458,   56,
 /*   210 */   458,  458,  487,  661,  661, 1031, 1031, 1031, 1031, 1022,
 /*   220 */   949,  949, 1008,  949,  954,  949,  -97,  937,  941,  948,
 /*   230 */   944,  952,  943,  962,  992, 1066,  992,  962,  998,  982,
 /*   240 */   998,  982, 1078,  992,  992, 1066, 1008,  949,  949,  949,
 /*   250 */  1078, 1109,  962,  962,  962,  962, 1096, 1013, 1109,  962,
 /*   260 */  1095, 1095, 1138,  937, 1144, 1144, 1144,  937, 1095, 1138,
 /*   270 */   962, 1136, 1136,  962,  962, 1041,  -98,  -98,  -98,  148,
 /*   280 */   506,  536,  505,  728,  876,  805,  869,  698,  875,  878,
 /*   290 */   879,  813,  900,  929,  932,  912,  945,  946,  977,  980,
 /*   300 */   938, 1180, 1162, 1151, 1140, 1166, 1084, 1085, 1087, 1088,
 /*   310 */  1181, 1183, 1184, 1111, 1099, 1188, 1197, 1190, 1191, 1192,
 /*   320 */  1193, 1094, 1196, 1103, 1198, 1110, 1203, 1204, 1101, 1205,
 /*   330 */  1185, 1208, 1210, 1209, 1212, 1189, 1213, 1141, 1132, 1220,
 /*   340 */  1221, 1216, 1145, 1207, 1199, 1223, 1201, 1115, 1152, 1229,
 /*   350 */  1246, 1241, 1252, 1153, 1194, 1195, 1134, 1237, 1146, 1240,
 /*   360 */  1147, 1159, 1142, 1245, 1247, 1251, 1211, 1135, 1131, 1267,
 /*   370 */  1268,
};
#define YY_REDUCE_USE_DFLT (-216)
#define YY_REDUCE_MAX 278
static const short yy_reduce_ofst[] = {
 /*     0 */   -56,  136,   16,   70,  189,  127,   66,  130,  190,  219,
 /*    10 */   255,  220,   61,  132,  138,  210,  265,  271, -178, -140,
 /*    20 */   -61,   79,  145,  264, -215, -215, -215, -215, -215, -215,
 /*    30 */  -215, -215, -215, -215, -215, -215, -215, -215, -215, -215,
 /*    40 */  -215, -215, -215, -215, -215, -215, -215, -215, -215, -215,
 /*    50 */  -215, -215, -215, -215, -215,  402,  405,  407,  416,  418,
 /*    60 */   456,  472,  474,  476,  480,  482,  484,  523,  535,  540,
 /*    70 */   542,  544,  547,  549,  551,  590,  602,  606,  608,  610,
 /*    80 */   614,  618,  657,  669,  673,  675,  677,  681,  686,  724,
 /*    90 */   736,  740,  742,  744, -215, -215,  -77, -215, -215, -215,
 /*   100 */  -215,   50,  354,  473,  541,  603,  144,  604,  772,  342,
 /*   110 */   284, -215, -215, -215, -215,  282,  251,  322,  462,  -72,
 /*   120 */   177,  306,  428,  353,  193,  475,  421,  477,  509,  575,
 /*   130 */   707,  750,  768,  771,  556,  769,  663,  733,  765,  807,
 /*   140 */   808,  -42,  499, -126, -112,  -57,  -19,   18,   96,   18,
 /*   150 */    18,   72,  141,  146,  198,  250,  223,  336,  370,  373,
 /*   160 */   250,  543,  534,  561,  607,  563,  623,  626,   18,  563,
 /*   170 */   634,  690,  662,  670,  679,  706,  739,   18,  760,  777,
 /*   180 */    18,  802,  730,  749,  847,  855,   18,  857,  858,  866,
 /*   190 */    18,  867,   18,   18,  870,  871,  872,  873,  874,  880,
 /*   200 */   863,  844,  831,  832,  800,  801,  803,  859,  860,  853,
 /*   210 */   861,  864,  862,  843,  845,  895,  896,  897,  898,  892,
 /*   220 */   877,  881,  885,  884,  883,  886,  887,  890,  891,  893,
 /*   230 */   868,  894,  846,  923,  882,  931,  899,  942,  901,  902,
 /*   240 */   904,  906,  935,  903,  910,  953,  927,  955,  956,  961,
 /*   250 */   950,  983,  981,  985,  986,  987,  914,  911,  997, 1000,
 /*   260 */   972,  973,  947,  965,  974,  976,  979,  970,  984,  958,
 /*   270 */  1017,  940,  957, 1019, 1025,  959, 1020, 1005, 1006,
};
static const YYACTIONTYPE yy_default[] = {
 /*     0 */   566,  790,  855,  681,  855,  790,  855,  790,  855,  828,
 /*    10 */   828,  685,  841,  786,  790,  855,  855,  855,  761,  812,
 /*    20 */   855,  597,  812,  812,  716,  855,  855,  855,  855,  855,
 /*    30 */   855,  855,  855,  717,  855,  789,  785,  781,  783,  782,
 /*    40 */   718,  705,  714,  721,  697,  826,  723,  724,  729,  730,
 /*    50 */   842,  845,  751,  767,  750,  855,  855,  855,  855,  855,
 /*    60 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*    70 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*    80 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*    90 */   855,  855,  855,  855,  753,  772,  590,  752,  760,  754,
 /*   100 */   755,  650,  855,  855,  855,  855,  585,  855,  855,  855,
 /*   110 */   855,  756,  757,  768,  769,  855,  855,  855,  855,  566,
 /*   120 */   681,  855,  681,  855,  855,  855,  855,  855,  855,  855,
 /*   130 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*   140 */   855,  675,  685,  855,  855,  641,  855,  855,  855,  855,
 /*   150 */   855,  855,  855,  855,  855,  855,  573,  571,  855,  673,
 /*   160 */   855,  855,  599,  855,  855,  683,  855,  855,  688,  689,

 /*   170 */   855,  855,  855,  855,  855,  855,  855,  587,  855,  855,
 /*   180 */   662,  855,  818,  855,  855,  855,  833,  855,  855,  855,
 /*   190 */   831,  855,  664,  726,  800,  855,  855,  846,  848,  855,
 /*   200 */   855,  708,  673,  682,  855,  855,  784,  708,  708,  620,
 /*   210 */   708,  708,  623,  720,  720,  570,  570,  570,  570,  640,
 /*   220 */   652,  652,  637,  652,  623,  652,  855,  720,  711,  713,
 /*   230 */   701,  715,  855,  690,  709,  855,  709,  690,  698,  700,
 /*   240 */   698,  700,  794,  709,  709,  855,  637,  652,  652,  652,
 /*   250 */   794,  582,  690,  690,  690,  690,  822,  825,  582,  690,
 /*   260 */   654,  654,  731,  720,  661,  661,  661,  720,  654,  731,
 /*   270 */   690,  844,  844,  690,  690,  853,  607,  625,  625,  855,
 /*   280 */   855,  855,  855,  855,  855,  738,  855,  855,  855,  855,

 /*   290 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*   300 */   807,  855,  855,  855,  855,  855,  743,  739,  855,  740,
 /*   310 */   855,  855,  855,  855,  667,  855,  855,  855,  855,  855,
 /*   320 */   855,  855,  702,  855,  712,  855,  855,  855,  855,  855,
 /*   330 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*   340 */   855,  855,  855,  855,  820,  821,  855,  855,  855,  855,
 /*   350 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*   360 */   855,  855,  855,  855,  855,  855,  852,  855,  855,  567,
 /*   370 */   855,  561,  564,  563,  565,  569,  572,  594,  595,  596,
 /*   380 */   574,  575,  576,  577,  578,  579,  580,  586,  588,  606,
 /*   390 */   608,  615,  653,  656,  657,  658,  836,  837,  838,  616,
 /*   400 */   635,  638,  639,  617,  624,  706,  707,  618,  671,  672,
 /*   410 */   735,  665,  666,  670,  737,  741,  742,  744,  745,  593,
 /*   420 */   600,  601,  604,  605,  808,  810,  809,  811,  603,  602,
 /*   430 */   746,  749,  758,  759,  765,  771,  774,  763,  764,  766,
 /*   440 */   770,  773,  668,  669,  777,  779,  780,  834,  835,  775,
 /*   450 */   787,  788,  691,  778,  762,  703,  592,  710,  704,  674,
 /*   460 */   684,  693,  694,  695,  696,  679,  680,  686,  699,  733,
 /*   470 */   734,  687,  676,  677,  678,  776,  736,  747,  748,  619,
 /*   480 */   626,  627,  628,  631,  632,  633,  634,  629,  630,  795,
 /*   490 */   796,  798,  797,  621,  622,  636,  609,  610,  611,  612,
 /*   500 */   743,  613,  614,  598,  591,  642,  645,  646,  647,  648,
 /*   510 */   649,  651,  643,  644,  589,  581,  583,  692,  814,  823,
 /*   520 */   824,  819,  815,  816,  817,  584,  791,  792,  655,  727,
 /*   530 */   728,  813,  827,  829,  732,  830,  832,  659,  660,  663,
 /*   540 */   799,  839,  719,  722,  725,  801,  802,  803,  804,  805,
 /*   550 */   806,  840,  843,  847,  849,  850,  851,  854,  568,  562,
};
#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.







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


|
|
|

|
|
|
>
|
|
<
|

|
|
|
|
|
|

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

|
|
|
|
|
|


|
|
|
|
|
|
|
|
|

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

|


|
|
|
|
|




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




|
|
|


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



|
|
|
|
|



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







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
**  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 */   279,   77,  343,   65,  150,  178,  221,  516,   67,   67,
 /*    10 */    67,   67,  299,   82,   82,   82,   82,   80,   80,   79,
 /*    20 */    79,   79,   78,  345,  477,   41,  543,   69,   82,   82,
 /*    30 */    82,   82,   80,   80,   79,   79,   79,   78,   77,  480,
 /*    40 */    65,  150,  167,   84,   61,  294,  524,  517,  529,  529,
 /*    50 */    86,   86,   67,   67,   67,   67,  244,   82,   82,   82,
 /*    60 */    82,   80,   80,   79,   79,   79,   78,  279,  275,  299,
 /*    70 */   516,  283,  519,   81,   82,   82,   82,   82,   80,   80,
 /*    80 */    79,   79,   79,   78,  190,  115,  235,  302,  264,  323,
 /*    90 */   176,  232,  182,  543,  378,  427,  282,   68,  225,   57,
 /*   100 */   178,  377,  516,  475,   80,   80,   79,   79,   79,   78,
 /*   110 */    84,   61,  294,  524,  517,  529,  529,   86,   86,   67,
 /*   120 */    67,   67,   67,  252,   82,   82,   82,   82,   80,   80,
 /*   130 */    79,   79,   79,   78,  279,  511,  506,  198,  385,   90,
 /*   140 */   350,  357,  362,  235,  302,  264,  323,  176,  232,  146,
 /*   150 */   452,   77,  367,   65,  150,  225,  216,  144,  145,  519,
 /*   160 */   543,  318,  359,  538,  270,  516,  391,  492,  211,   15,
 /*   170 */   499,  532,  219,  455,  385,  194,  187,   84,   61,  294,
 /*   180 */   524,  517,  529,  529,   86,   86,   67,   67,   67,   67,
 /*   190 */    71,   82,   82,   82,   82,   80,   80,   79,   79,   79,
 /*   200 */    78,  279,  391,  507,  507,  507,  499,  451,  397,  478,
 /*   210 */   478,  356,  438,  549,  202,  198,  400,  418,  350,  357,
 /*   220 */   362,  198,  511,  506,  350,  357,  362,  543,  228,   77,
 /*   230 */   367,   65,  150,  521,  346,  192,  367,  417,  167,  507,
 /*   240 */   507,  507,  421,  424,   84,   61,  294,  524,  517,  529,
 /*   250 */   529,   86,   86,   67,   67,   67,   67,  316,   82,   82,
 /*   260 */    82,   82,   80,   80,   79,   79,   79,   78,  343,  478,
 /*   270 */   513,  343,   76,  279,  552,  365,  165,  274,  343,  147,
 /*   280 */   343,  196,  148,  343,  510,  343,  314,  343,  284,  343,
 /*   290 */   477,   38,  282,  477,   29,  149,  358,  225,  442,  543,
 /*   300 */   477,   50,  477,   50,  450,  477,   37,  477,   50,  477,
 /*   310 */    50,  477,   96,  478,  450,   85,   84,   61,  294,  524,
 /*   320 */   517,  529,  529,   86,   86,   67,   67,   67,   67,  478,
 /*   330 */    82,   82,   82,   82,   80,   80,   79,   79,   79,   78,
 /*   340 */   279,  416,  222,  324,  386,  330,  233,  328,  271,  241,
 /*   350 */   290,  343,  286,  456,   22,  486,  550,  487,  208,  343,
 /*   360 */   505,  520,  486,   11,  486,  296,  543,  519,   92,  352,
 /*   370 */   527,  512,  512,  477,   37,  309,  519,  143,  380,  522,
 /*   380 */   523,  477,   41,   84,   61,  294,  524,  517,  529,  529,
 /*   390 */    86,   86,   67,   67,   67,   67,  375,   82,   82,   82,
 /*   400 */    82,   80,   80,   79,   79,   79,   78,  279,  371,  386,
 /*   410 */   375,  116,  110,  420,  226,  247,  435,  419,  381,   22,
 /*   420 */   503,  373,  371,  337,  291,  533,  536,  281,  288,  308,
 /*   430 */   511,  506,  436,  543,  519,  373,  217,  403,  162,  511,
 /*   440 */   506,  204,   79,   79,   79,   78,  352,  384,  512,  512,
 /*   450 */    84,   61,  294,  524,  517,  529,  529,   86,   86,   67,
 /*   460 */    67,   67,   67,  458,   82,   82,   82,   82,   80,   80,
 /*   470 */    79,   79,   79,   78,  279,  127,  277,  223,  432,  552,
 /*   480 */   387,  165,  484,  353,  533,  536,  519,  204,  519,    1,
 /*   490 */   856,  128,  559,  519,  542,    2,  553,  511,  506,    2,
 /*   500 */   543,  352,  307,  512,  512,  352,  305,  512,  512,  560,
 /*   510 */   546,  366,   21,  266,  539,  537,  516,   84,   61,  294,
 /*   520 */   524,  517,  529,  529,   86,   86,   67,   67,   67,   67,
 /*   530 */   594,   82,   82,   82,   82,   80,   80,   79,   79,   79,
 /*   540 */    78,  279,  540,  343,  166,  428,  204,  343,  448,  511,
 /*   550 */   506,  511,  506,  386,  231,  449,  511,  506,  412,  343,
 /*   560 */   406,  411,  554,   22,  268,  477,   97,  543,  465,  477,
 /*   570 */    30,  415,  312,  415,  546,  366,  462,  224,  463,  516,
 /*   580 */   450,  477,   39,  303,   84,   61,  294,  524,  517,  529,
 /*   590 */   529,   86,   86,   67,   67,   67,   67,  343,   82,   82,
 /*   600 */    82,   82,   80,   80,   79,   79,   79,   78,  279,  433,
 /*   610 */   469,  126,  394,  343,  468,  343,  181,  343,  195,  477,
 /*   620 */    36,  343,  272,  343,  430,  343,   15,  343,  502,  500,
 /*   630 */   496,  164,  180,  193,  543,  477,   42,  477,   51,  477,
 /*   640 */    94,  298,  423,  477,   33,  477,   44,  477,   34,  477,
 /*   650 */   113,   84,   61,  294,  524,  517,  529,  529,   86,   86,
 /*   660 */    67,   67,   67,   67,  343,   82,   82,   82,   82,   80,
 /*   670 */    80,   79,   79,   79,   78,  279,  343,   93,  515,   89,
 /*   680 */   343,  383,  343,  177,  343,  464,  477,   35,  343,  200,
 /*   690 */   343,  518,  343,   23,  158,  148,   55,  257,  477,   53,
 /*   700 */   333,  543,  477,   40,  477,   28,  477,   18,  440,  409,
 /*   710 */   477,   25,  477,  114,  477,  112,  434,  478,   84,   61,
 /*   720 */   294,  524,  517,  529,  529,   86,   86,   67,   67,   67,
 /*   730 */    67,  343,   82,   82,   82,   82,   80,   80,   79,   79,
 /*   740 */    79,   78,  370,  343,  177,  343,  388,  279,  343,  369,
 /*   750 */   155,  126,  343,  477,  111,  396,  793,  343,  311,  306,
 /*   760 */   547,  547,  343,  313,  343,  477,   31,  477,  100,  161,
 /*   770 */   477,   54,  254,  543,  477,   43,  464,  238,  478,  477,
 /*   780 */    45,  477,    3,  240,  477,   99,  477,   24,  457,   91,
 /*   790 */    84,   61,  294,  524,  517,  529,  529,   86,   86,   67,
 /*   800 */    67,   67,   67,  370,   82,   82,   82,   82,   80,   80,
 /*   810 */    79,   79,   79,   78,  279,  343,   20,   19,  139,  447,
 /*   820 */   343,  469,  343,  126,  313,  468,  259,  343,  126,  343,
 /*   830 */   319,  343,  467,  343,  208,  208,  319,  477,   52,  453,
 /*   840 */   543,  183,  477,   46,  477,   95,  252,  349,  326,  477,
 /*   850 */    27,  477,   26,  477,   47,  477,   12,   84,   64,  294,
 /*   860 */   524,  517,  529,  529,   86,   86,   67,   67,   67,   67,
 /*   870 */   343,   82,   82,   82,   82,   80,   80,   79,   79,   79,
 /*   880 */    78,  279,  343,  402,  402,  402,  343,  361,  402,  402,
 /*   890 */   410,  409,  477,   48,  426,  439,  213,  446,  407,  466,
 /*   900 */   126,  183,  201,  400,  477,   49,  548,  543,  477,   32,
 /*   910 */   549,  202,  252,  455,  402,  455,  252,  173,  297,  289,
 /*   920 */   206,  154,  141,  295,  279,   61,  294,  524,  517,  529,
 /*   930 */   529,   86,   86,   67,   67,   67,   67,  364,   82,   82,
 /*   940 */    82,   82,   80,   80,   79,   79,   79,   78,  516,  292,
 /*   950 */   543,  478,  260,  340,  269,  478,  474,  237,   76,  252,
 /*   960 */   252,  175,  242,  242,  242,  172,  322,  242,  258,  294,
 /*   970 */   524,  517,  529,  529,   86,   86,   67,   67,   67,   67,
 /*   980 */   252,   82,   82,   82,   82,   80,   80,   79,   79,   79,
 /*   990 */    78,   56,  344,  242,    4,  478,  252,  252,  287,  478,
 /*  1000 */   493,  491,  413,  414,  551,  545,  348,   56,  344,  404,
 /*  1010 */     4,  516,  425,  401,  287,  304,    7,  354,  246,  355,
 /*  1020 */   142,  262,  348,  338,  427,  248,  249,  471,  476,  218,
 /*  1030 */   470,  528,  504,  385,  153,  118,  130,  488,  483,  338,
 /*  1040 */   342,  191,  389,  332,  121,  301,  208,  489,  481,  385,
 /*  1050 */    87,   71,   62,   58,  479,  341,  123,  214,  285,  186,
 /*  1060 */    56,  327,  329,  229,  398,  499,  156,  482,   62,   58,
 /*  1070 */   437,  174,  212,  475,  472,  125,   56,  327,  329,   56,
 /*  1080 */   344,  499,    4,  473,  208,  399,  287,  210,  490,  310,
 /*  1090 */   157,  498,  293,  431,  348,  251,   83,  497,  507,  507,
 /*  1100 */   507,  508,  509,   17,  376,  205,  535,  441,    8,  382,
 /*  1110 */    88,  338,  253,  320,  507,  507,  507,  508,  509,   17,
 /*  1120 */   120,  385,  159,  530,  136,   72,  325,  234,  227,  230,
 /*  1130 */   102,  405,  446,  445,  541,  135,  544,   74,  256,  203,
 /*  1140 */    62,   58,  267,  170,  374,  245,   66,  317,   56,  327,
 /*  1150 */   329,  261,  250,  499,  454,   63,  315,  460,  443,  263,
 /*  1160 */   103,  408,  278,  331,  168,  239,  442,  334,  265,  137,
 /*  1170 */   276,  171,  372,  169,  555,  197,  188,  395,  101,  109,
 /*  1180 */    98,  368,  209,  106,  347,  321,  507,  507,  507,  508,
 /*  1190 */   509,   17,  556,  273,   60,  335,  189,  220,  255,  363,
 /*  1200 */   105,  534,  525,  557,  108,  390,  275,  379,  526,  393,
 /*  1210 */   243,  531,  514,  107,  351,  336,  215,  241,   13,  558,
 /*  1220 */    59,  280,  179,  132,  138,  185,  208,  501,   78,  339,
 /*  1230 */   131,  163,  429,  207,  392,  129,    9,  151,  152,  495,
 /*  1240 */   104,  236,  199,  140,  494,  485,    6,  422,  183,   16,
 /*  1250 */   360,  444,  122,   10,  596,  117,  184,  133,  595,  119,
 /*  1260 */    14,  300,   73,  134,    5,   15,   70,  461,  124,  459,
 /*  1270 */    75,  160,
};
static const YYCODETYPE yy_lookahead[] = {
 /*     0 */    16,  216,  146,  218,  219,   21,  146,   23,   68,   69,
 /*    10 */    70,   71,   16,   73,   74,   75,   76,   77,   78,   79,
 /*    20 */    80,   81,   82,  146,  168,  169,   42,   72,   73,   74,
 /*    30 */    75,   76,   77,   78,   79,   80,   81,   82,  216,  217,
 /*    40 */   218,  219,   43,   59,   60,   61,   62,   63,   64,   65,
 /*    50 */    66,   67,   68,   69,   70,   71,   90,   73,   74,   75,
 /*    60 */    76,   77,   78,   79,   80,   81,   82,   16,  102,   16,
 /*    70 */    86,  215,   23,   22,   73,   74,   75,   76,   77,   78,
 /*    80 */    79,   80,   81,   82,   88,   89,   90,   91,   92,   93,
 /*    90 */    94,   95,   22,   42,  175,  176,   97,   46,  102,   19,

 /*   100 */    21,  182,   23,   23,   77,   78,   79,   80,   81,   82,
 /*   110 */    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,
 /*   120 */    69,   70,   71,  146,   73,   74,   75,   76,   77,   78,
 /*   130 */    79,   80,   81,   82,   16,   86,   87,   88,   58,   21,
 /*   140 */    91,   92,   93,   90,   91,   92,   93,   94,   95,   22,
 /*   150 */   146,  216,  103,  218,  219,  102,  146,   77,   78,   23,
 /*   160 */    42,  146,  141,  142,  187,   86,   86,   20,  147,   22,
 /*   170 */    90,  236,  189,  160,   58,  154,  154,   59,   60,   61,
 /*   180 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   190 */   120,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   200 */    82,   16,   86,  123,  124,  125,   90,  166,  167,  188,
 /*   210 */   188,   16,  199,   77,   78,   88,  175,   30,   91,   92,
 /*   220 */    93,   88,   86,   87,   91,   92,   93,   42,  146,  216,
 /*   230 */   103,  218,  219,   97,  213,  154,  103,   50,   43,  123,
 /*   240 */   124,  125,   89,   90,   59,   60,   61,   62,   63,   64,
 /*   250 */    65,   66,   67,   68,   69,   70,   71,  146,   73,   74,
 /*   260 */    75,   76,   77,   78,   79,   80,   81,   82,  146,  188,
 /*   270 */    20,  146,   22,   16,  160,  161,  162,   20,  146,  154,
 /*   280 */   146,  200,  201,  146,   20,  146,  205,  146,  101,  146,
 /*   290 */   168,  169,   97,  168,  169,  154,   16,  102,   49,   42,
 /*   300 */   168,  169,  168,  169,  146,  168,  169,  168,  169,  168,
 /*   310 */   169,  168,  169,  188,  146,  130,   59,   60,   61,   62,
 /*   320 */    63,   64,   65,   66,   67,   68,   69,   70,   71,  188,
 /*   330 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
 /*   340 */    16,  177,  220,  211,  146,  208,  209,   98,   99,  100,
 /*   350 */   211,  146,  211,  155,  156,  223,  146,  223,  109,  146,
 /*   360 */   146,  146,  223,   19,  223,  207,   42,   23,   44,  105,
 /*   370 */    90,  107,  108,  168,  169,  207,   23,  179,  180,  164,
 /*   380 */   165,  168,  169,   59,   60,   61,   62,   63,   64,   65,
 /*   390 */    66,   67,   68,   69,   70,   71,   12,   73,   74,   75,
 /*   400 */    76,   77,   78,   79,   80,   81,   82,   16,   24,  146,
 /*   410 */    12,  146,   21,   25,  209,  152,   20,   29,  155,  156,
 /*   420 */    20,   37,   24,   39,  163,  164,  165,  149,  215,   41,
 /*   430 */    86,   87,   79,   42,   23,   37,   14,   39,   19,   86,
 /*   440 */    87,  226,   79,   80,   81,   82,  105,   49,  107,  108,
 /*   450 */    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,
 /*   460 */    69,   70,   71,  146,   73,   74,   75,   76,   77,   78,
 /*   470 */    79,   80,   81,   82,   16,   53,  157,   55,   20,  160,
 /*   480 */   161,  162,  146,  163,  164,  165,   23,  226,   23,   19,
 /*   490 */   138,  139,  140,   23,   42,  143,  140,   86,   87,  143,
 /*   500 */    42,  105,  224,  107,  108,  105,  228,  107,  108,    0,
 /*   510 */     1,    2,   19,  146,   62,   63,   23,   59,   60,   61,
 /*   520 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   530 */   111,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   540 */    82,   16,   90,  146,  230,   20,  226,  146,   27,   86,
 /*   550 */    87,   86,   87,  146,  132,   34,   86,   87,  177,  146,
 /*   560 */     7,    8,  155,  156,  146,  168,  169,   42,  202,  168,
 /*   570 */   169,   98,   99,  100,    1,    2,  113,   14,  113,   86,
 /*   580 */   146,  168,  169,   79,   59,   60,   61,   62,   63,   64,
 /*   590 */    65,   66,   67,   68,   69,   70,   71,  146,   73,   74,
 /*   600 */    75,   76,   77,   78,   79,   80,   81,   82,   16,   20,
 /*   610 */   106,   22,   20,  146,  110,  146,   53,  146,   55,  168,
 /*   620 */   169,  146,  146,  146,   20,  146,   22,  146,    7,    8,
 /*   630 */     9,   98,   99,  100,   42,  168,  169,  168,  169,  168,
 /*   640 */   169,  207,   18,  168,  169,  168,  169,  168,  169,  168,
 /*   650 */   169,   59,   60,   61,   62,   63,   64,   65,   66,   67,
 /*   660 */    68,   69,   70,   71,  146,   73,   74,   75,   76,   77,
 /*   670 */    78,   79,   80,   81,   82,   16,  146,  129,  146,  131,
 /*   680 */   146,  146,  146,  154,  146,   22,  168,  169,  146,  191,
 /*   690 */   146,   20,  146,   22,  200,  201,  198,  146,  168,  169,
 /*   700 */   146,   42,  168,  169,  168,  169,  168,  169,  184,  185,
 /*   710 */   168,  169,  168,  169,  168,  169,   92,  188,   59,   60,
 /*   720 */    61,   62,   63,   64,   65,   66,   67,   68,   69,   70,
 /*   730 */    71,  146,   73,   74,   75,   76,   77,   78,   79,   80,
 /*   740 */    81,   82,  213,  146,  154,  146,  159,   16,  146,   20,
 /*   750 */    87,   22,  146,  168,  169,  168,  132,  146,  229,  146,
 /*   760 */   123,  124,  146,  234,  146,  168,  169,  168,  169,   19,
 /*   770 */   168,  169,  146,   42,  168,  169,  113,  146,  188,  168,
 /*   780 */   169,  168,  169,  192,  168,  169,  168,  169,  193,  130,
 /*   790 */    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,
 /*   800 */    69,   70,   71,  213,   73,   74,   75,   76,   77,   78,
 /*   810 */    79,   80,   81,   82,   16,  146,   19,   67,   21,  229,
 /*   820 */   146,  106,  146,   22,  234,  110,   20,  146,   22,  146,
 /*   830 */   146,  146,   22,  146,  109,  109,  146,  168,  169,   20,
 /*   840 */    42,   22,  168,  169,  168,  169,  146,  122,  122,  168,
 /*   850 */   169,  168,  169,  168,  169,  168,  169,   59,   60,   61,
 /*   860 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   870 */   146,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   880 */    82,   16,  146,  146,  146,  146,  146,  187,  146,  146,
 /*   890 */   184,  185,  168,  169,  146,  167,  212,   96,   20,   20,
 /*   900 */    22,   22,  212,  175,  168,  169,  227,   42,  168,  169,
 /*   910 */    77,   78,  146,  160,  146,  160,  146,  154,  181,  181,
 /*   920 */   181,  154,  112,  181,   16,   60,   61,   62,   63,   64,
 /*   930 */    65,   66,   67,   68,   69,   70,   71,  237,   73,   74,
 /*   940 */    75,   76,   77,   78,   79,   80,   81,   82,   23,  181,
 /*   950 */    42,  188,  199,  187,  199,  188,   20,  187,   22,  146,
 /*   960 */   146,  154,  225,  225,  225,  154,  231,  225,  225,   61,
 /*   970 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
 /*   980 */   146,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   990 */    82,   16,   17,  225,   19,  188,  146,  146,   23,  188,
 /*  1000 */   187,  187,   51,   52,  160,  227,   31,   16,   17,  171,
 /*  1010 */    19,   86,  177,  171,   23,  146,  190,  172,  171,  146,
 /*  1020 */   190,  187,   31,   48,  176,  144,  146,  171,  171,  146,
 /*  1030 */   148,  146,  193,   58,  146,   59,  183,  187,  187,   48,
 /*  1040 */   222,  111,  151,   15,  186,  151,  109,  188,  151,   58,
 /*  1050 */   129,  120,   77,   78,  193,   15,  186,  221,   40,  150,
 /*  1060 */    85,   86,   87,   95,  178,   90,    6,  145,   77,   78,
 /*  1070 */    79,  151,  210,   23,  159,  186,   85,   86,   87,   16,
 /*  1080 */    17,   90,   19,  145,  109,  159,   23,  210,  145,   97,
 /*  1090 */   150,  193,  151,  170,   31,  193,  119,  197,  123,  124,
 /*  1100 */   125,  126,  127,  128,  170,  210,   33,  183,   22,  170,
 /*  1110 */   235,   48,  170,  153,  123,  124,  125,  126,  127,  128,
 /*  1120 */    19,   58,    5,  145,  214,  235,  117,   10,   11,   12,
 /*  1130 */    13,  151,   96,  172,  151,  151,  151,  118,  194,  210,
 /*  1140 */    77,   78,  195,   26,  170,   28,   97,  114,   85,   86,
 /*  1150 */    87,  203,   35,   90,  204,  129,   38,  170,  204,  232,
 /*  1160 */    19,  233,  173,  115,   47,  196,   49,  151,  203,  214,
 /*  1170 */   173,   54,  170,   56,  136,   94,  183,  178,  174,   19,
 /*  1180 */   158,   44,  174,  238,    3,  146,  123,  124,  125,  126,
 /*  1190 */   127,  128,   20,  135,   19,  185,  134,  146,  146,   57,
 /*  1200 */    14,    1,   90,  180,   19,  168,  102,  180,   20,  168,
 /*  1210 */    20,   20,  106,   19,   44,   98,   99,  100,   19,    4,
 /*  1220 */    19,  104,  111,  121,   19,  111,  109,   11,   82,   16,
 /*  1230 */   101,   97,   20,   44,   17,  112,    5,   19,  111,   20,
 /*  1240 */    19,  132,   22,   21,   20,   17,  116,   45,   22,   22,
 /*  1250 */   133,   11,   45,    1,  111,   32,  112,   20,  111,  101,
 /*  1260 */    19,   36,   67,   19,  116,   22,   19,  113,   97,   20,
 /*  1270 */    67,  121,
};
#define YY_SHIFT_USE_DFLT (-61)
#define YY_SHIFT_MAX 370
static const short yy_shift_ofst[] = {
 /*     0 */   573,  975, 1117,  -16,  975, 1063, 1063, 1063,   49,  249,
 /*    10 */   249,  937,  324, 1063, 1063, 1063, 1063, 1063,  -45,  136,
 /*    20 */   411,  833,  925,  833,   51,  391,  118,  185,  257,  458,
 /*    30 */   525,  592,  659,  731,  731,  731,  731,  731,  731,  731,
 /*    40 */   731,  731,  798,  731,  731,  731,  731,  731,  731,  731,
 /*    50 */   731,  731,  865,  908,  908,  991, 1063, 1063, 1063, 1063,
 /*    60 */  1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
 /*    70 */  1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
 /*    80 */  1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
 /*    90 */  1063, 1063, 1063, 1063,  -60,  -60,    1,    1,   -4,   27,
 /*   100 */   363,  195,  624,  411,  411,  411,  411,  411,  411,  411,
 /*   110 */   925, 1146,  -61,  -61,  -61,   80,   53,  398,  398,  411,
 /*   120 */   411,  411,  411,  411,  411,  411,  411,  411,  509,  411,
 /*   130 */   411,  411,  411,   79,  411,   79,  726,  725,  937,  937,
 /*   140 */   937,  -61,  -61,  127,  116,  116,  133,  396,  344,  264,
 /*   150 */   470,  384,  353,  463,  400,  465,  411,  411,  663,  621,
 /*   160 */   411,  411,  504,  411,  187,  493,  473,  411,  411,  411,
 /*   170 */   411,  411,  341,  341,  388,  341,  411,  341,  411,  411,
 /*   180 */   187,  411,  411,  411,  411,  411,  411,  341,  411,  411,
 /*   190 */   411,  411,  341,  187,  341,  411,  663,  411,  411,  411,
 /*   200 */   810,   70,  637,  521,  637,  521,  801,  521,  715,   -1,
 /*   210 */   521,  797,  521,   70,  548,  976,  930, 1028,  930,  937,
 /*   220 */   930,  931,  921, 1028, 1040, 1018,  968, 1060,  930, 1050,
 /*   230 */  1060, 1028, 1050,  968, 1060,  992, 1040,  931,  930,  977,
 /*   240 */   931,  976,  968,  992,  992, 1073,  992, 1086, 1060, 1101,
 /*   250 */  1073, 1009,  930, 1036,  930,  930, 1019,  930,  968,  992,
 /*   260 */  1049, 1033, 1118, 1026,  992, 1033, 1141, 1048,  930, 1049,
 /*   270 */  1101,  976, 1141, 1038,  992, 1018,  -61,  -61,  -61,  452,
 /*   280 */   422,  563,  533,  936,  153,  553,  147,  419,  250,  589,
 /*   290 */   604,  671,  729,  750,  280,  806,  819,  878,  879,  -34,
 /*   300 */   951, 1134, 1189, 1212, 1221, 1231, 1127, 1109, 1202, 1226,
 /*   310 */  1223, 1240, 1207, 1252, 1237, 1225, 1158, 1244, 1195, 1203,
 /*   320 */  1249, 1154, 1171, 1247, 1243, 1148, 1241, 1147, 1144, 1143,
 /*   330 */  1227, 1130, 1228, 1224, 1222, 1220, 1123, 1219, 1218, 1217,
 /*   340 */  1129, 1213, 1216, 1114, 1205, 1111, 1102, 1215, 1201, 1199,
 /*   350 */  1170, 1194, 1106, 1191, 1190, 1188, 1104, 1185, 1112, 1200,
 /*   360 */  1186, 1142, 1175, 1062, 1058, 1172, 1181, 1137, 1160, 1081,
 /*   370 */  1150,
};
#define YY_REDUCE_USE_DFLT (-216)
#define YY_REDUCE_MAX 278
static const short yy_reduce_ofst[] = {
 /*     0 */   352,  141,   21,   13,  125,  132,  137,  139,  198,  529,
 /*    10 */   590,   81,  -65,  213, -144,  134,  205,  122, -178,  215,
 /*    20 */   263,  261,  319,  320, -215, -215, -215, -215, -215, -215,
 /*    30 */  -215, -215, -215, -215, -215, -215, -215, -215, -215, -215,
 /*    40 */  -215, -215, -215, -215, -215, -215, -215, -215, -215, -215,
 /*    50 */  -215, -215, -215, -215, -215,  613,  602,  597,  546,  542,
 /*    60 */   536,  530,  481,  477,  471,  467,  413,  397,  611,  143,
 /*    70 */   401,  451,  469,  475,  479,  518,  534,  538,  544,  585,
 /*    80 */   599,  606,  616,  618,  669,  674,  676,  681,  683,  685,
 /*    90 */   687,  724,  736,  740, -215, -215, -215, -215,   41, -215,
 /*   100 */  -215,  -81,  278,  737,  738,  700,  407,  739,  742,  768,
 /*   110 */   114, -215, -215, -215, -215,  587,  728,  706,  524,  690,
 /*   120 */   434,  851,  168,  850,  834,  814,  743,  813,  356,  770,
 /*   130 */   766,  684,  -23,  755,  158,  753,  811,  807,  767,  763,
 /*   140 */    22,  494,  498, 1027, 1041, 1037, 1023,  -17, 1052,  -17,
 /*   150 */  1051, 1010, -123, 1039,  -17,  888,  885,  883,  366,  881,
 /*   160 */   880,  873,  826,  869,  835,  844,  735,  748,  631,  626,
 /*   170 */   551,  532,  -17,  -17,  314,  -17,  367,  -17,  317,  214,
 /*   180 */   164,   82,   15,    4, -140, -123,   10,  -17,  111,  210,
 /*   190 */   265,  336,  -17,  381,  -17,  418,  366,  476,  535,  554,
 /*   200 */   591,  595,  679,  838,  778,  842,  845,  847,  830,  848,
 /*   210 */   856,  882,  857,  839,  818,  853,  891,  858,  894,  859,
 /*   220 */   897,  861,  836,  870,  909,  886,  862,  922,  920,  915,
 /*   230 */   938,  889,  926,  877,  943,  923,  940,  898,  941,  900,
 /*   240 */   902,  924,  895,  934,  939,  875,  942,  960,  978,  910,
 /*   250 */   890,  944,  980,  961,  983,  984,  947,  985,  929,  974,
 /*   260 */   948,  950,  927,  928,  987,  954,  989,  969, 1016,  965,
 /*   270 */   955,  993,  997,  945, 1002,  999, 1004, 1022, 1008,
};
static const YYACTIONTYPE yy_default[] = {
 /*     0 */   566,  790,  855,  681,  855,  790,  855,  790,  855,  828,
 /*    10 */   828,  685,  841,  855,  855,  790,  855,  786,  761,  812,
 /*    20 */   855,  812,  597,  812,  716,  855,  855,  855,  855,  855,
 /*    30 */   855,  855,  855,  723,  714,  724,  721,  705,  785,  697,
 /*    40 */   729,  730,  855,  718,  826,  717,  782,  783,  781,  842,
 /*    50 */   789,  845,  751,  750,  767,  855,  855,  855,  855,  855,
 /*    60 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*    70 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*    80 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*    90 */   855,  855,  855,  855,  772,  753,  760,  752,  590,  754,
 /*   100 */   755,  650,  585,  855,  855,  855,  855,  855,  855,  855,
 /*   110 */   855,  756,  768,  769,  757,  855,  855,  855,  855,  855,
 /*   120 */   855,  855,  855,  855,  855,  855,  855,  855,  566,  855,
 /*   130 */   855,  855,  855,  681,  855,  681,  855,  855,  855,  855,
 /*   140 */   855,  685,  675,  641,  855,  855,  855,  855,  855,  855,
 /*   150 */   855,  855,  855,  855,  855,  855,  571,  855,  683,  573,
 /*   160 */   855,  855,  673,  855,  855,  599,  855,  855,  855,  846,
 /*   170 */   848,  800,  831,  587,  818,  726,  855,  833,  855,  855,
 /*   180 */   855,  855,  855,  855,  855,  855,  855,  662,  855,  855,

 /*   190 */   855,  855,  688,  855,  664,  855,  689,  855,  855,  855,
 /*   200 */   682,  720,  855,  708,  855,  708,  623,  708,  673,  620,
 /*   210 */   708,  855,  708,  720,  784,  654,  690,  661,  690,  855,
 /*   220 */   690,  720,  855,  661,  582,  637,  709,  570,  690,  855,
 /*   230 */   570,  661,  855,  709,  570,  652,  582,  720,  690,  715,
 /*   240 */   720,  654,  709,  652,  652,  844,  652,  640,  570,  731,
 /*   250 */   844,  711,  690,  623,  690,  690,  713,  690,  709,  652,
 /*   260 */   698,  700,  822,  825,  652,  700,  794,  701,  690,  698,
 /*   270 */   731,  654,  794,  853,  652,  637,  625,  607,  625,  855,
 /*   280 */   855,  855,  855,  855,  855,  855,  855,  738,  855,  855,
 /*   290 */   855,  855,  855,  807,  855,  855,  855,  855,  855,  855,
 /*   300 */   855,  855,  855,  855,  855,  855,  855,  855,  855,  821,
 /*   310 */   855,  855,  820,  855,  855,  855,  855,  855,  855,  855,
 /*   320 */   855,  855,  855,  855,  712,  855,  855,  743,  855,  739,

 /*   330 */   702,  855,  855,  855,  855,  855,  855,  855,  855,  855,
 /*   340 */   855,  855,  855,  855,  855,  740,  855,  855,  855,  855,
 /*   350 */   855,  855,  667,  855,  855,  855,  855,  855,  855,  855,
 /*   360 */   855,  852,  855,  855,  855,  855,  567,  855,  855,  855,
 /*   370 */   855,  837,  648,  838,  647,  836,  646,  649,  651,  643,
 /*   380 */   644,  589,  616,  645,  658,  749,  591,  598,  614,  581,
 /*   390 */   613,  743,  583,  612,  611,  635,  610,  609,  636,  622,
 /*   400 */   621,  797,  798,  657,  796,  692,  638,  795,  814,  656,
 /*   410 */   653,  639,  630,  823,  824,  819,  629,  634,  633,  815,
 /*   420 */   816,  632,  817,  584,  631,  628,  627,  626,  619,  748,
 /*   430 */   747,  615,  736,  791,  792,  776,  678,  677,  676,  608,
 /*   440 */   655,  727,  728,  687,  813,  617,  624,  827,  706,  707,
 /*   450 */   734,  606,  733,  699,  686,  680,  588,  829,  679,  586,
 /*   460 */   618,  696,  695,  694,  693,  684,  732,  674,  671,  672,
 /*   470 */   580,  704,  710,  579,  830,  592,  703,  735,  665,  832,
 /*   480 */   762,  778,  578,  659,  691,  660,  788,  787,  663,  666,
 /*   490 */   577,  799,  775,  839,  835,  834,  576,  670,  719,  737,
 /*   500 */   575,  780,  574,  779,  722,  741,  596,  742,  744,  745,
 /*   510 */   777,  595,  669,  725,  668,  801,  593,  773,  600,  594,
 /*   520 */   802,  803,  804,  805,  770,  766,  806,  764,  572,  763,
 /*   530 */   569,  601,  840,  604,  565,  843,  605,  774,  563,  771,
 /*   540 */   765,  847,  759,  758,  849,  808,  564,  810,  809,  811,
 /*   550 */   850,  603,  602,  561,  851,  854,  746,  642,  568,  562,
};
#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.
Changes to SQLite.Interop/src/pragma.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2003 April 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.17 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/* Ignore this whole file if pragmas are disabled
*/













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2003 April 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.18 2006/02/10 19:45:45 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/* Ignore this whole file if pragmas are disabled
*/
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
** Generate code to return a single integer value.
*/
static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
  Vdbe *v = sqlite3GetVdbe(pParse);
  sqlite3VdbeAddOp(v, OP_Integer, value, 0);
  if( pParse->explain==0 ){
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, zLabel, P3_STATIC);
  }
  sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
}

#ifndef SQLITE_OMIT_FLAG_PRAGMAS
/*
** Check to see if zRight and zLeft refer to a pragma that queries







|







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
** Generate code to return a single integer value.
*/
static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
  Vdbe *v = sqlite3GetVdbe(pParse);
  sqlite3VdbeAddOp(v, OP_Integer, value, 0);
  if( pParse->explain==0 ){
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC);
  }
  sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
}

#ifndef SQLITE_OMIT_FLAG_PRAGMAS
/*
** Check to see if zRight and zLeft refer to a pragma that queries
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
      { OP_Integer,     0, 0,        0},  /* 5 */
      { OP_Callback,    1, 0,        0},
    };
    int addr;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    if( !zRight ){
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, "cache_size", P3_STATIC);
      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
      sqlite3VdbeChangeP1(v, addr, iDb);
      sqlite3VdbeChangeP1(v, addr+5, MAX_PAGES);
    }else{
      int size = atoi(zRight);
      if( size<0 ) size = -size;
      sqlite3BeginWriteOperation(pParse, 0, iDb);







|







270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
      { OP_Integer,     0, 0,        0},  /* 5 */
      { OP_Callback,    1, 0,        0},
    };
    int addr;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    if( !zRight ){
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC);
      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
      sqlite3VdbeChangeP1(v, addr, iDb);
      sqlite3VdbeChangeP1(v, addr+5, MAX_PAGES);
    }else{
      int size = atoi(zRight);
      if( size<0 ) size = -size;
      sqlite3BeginWriteOperation(pParse, 0, iDb);
388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
  ** If temporary directory is changed, then invalidateTempStorage.
  **
  */
  if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
    if( !zRight ){
      if( sqlite3_temp_directory ){
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, "temp_store_directory", P3_STATIC);

        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
      }
    }else{
      if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
        sqlite3ErrorMsg(pParse, "not a writable directory");
        goto pragma_out;







|
>







388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
  ** If temporary directory is changed, then invalidateTempStorage.
  **
  */
  if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
    if( !zRight ){
      if( sqlite3_temp_directory ){
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
            "temp_store_directory", P3_STATIC);
        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
      }
    }else{
      if( zRight[0] && !sqlite3OsIsDirWritable(zRight) ){
        sqlite3ErrorMsg(pParse, "not a writable directory");
        goto pragma_out;
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
  */
  if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
    Table *pTab;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      int i;

      sqlite3VdbeSetNumCols(v, 6);
      sqlite3VdbeSetColName(v, 0, "cid", P3_STATIC);
      sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
      sqlite3VdbeSetColName(v, 2, "type", P3_STATIC);
      sqlite3VdbeSetColName(v, 3, "notnull", P3_STATIC);
      sqlite3VdbeSetColName(v, 4, "dflt_value", P3_STATIC);
      sqlite3VdbeSetColName(v, 5, "pk", P3_STATIC);
      sqlite3ViewGetColumnNames(pParse, pTab);
      for(i=0; i<pTab->nCol; i++){
        sqlite3VdbeAddOp(v, OP_Integer, i, 0);
        sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[i].zName, 0);
        sqlite3VdbeOp3(v, OP_String8, 0, 0,
           pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", 0);
        sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0);
        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
        sqlite3VdbeAddOp(v, OP_Integer, pTab->aCol[i].isPrimKey, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
      }
    }
  }else

  if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
    Index *pIdx;
    Table *pTab;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    pIdx = sqlite3FindIndex(db, zRight, zDb);
    if( pIdx ){
      int i;
      pTab = pIdx->pTable;
      sqlite3VdbeSetNumCols(v, 3);
      sqlite3VdbeSetColName(v, 0, "seqno", P3_STATIC);
      sqlite3VdbeSetColName(v, 1, "cid", P3_STATIC);
      sqlite3VdbeSetColName(v, 2, "name", P3_STATIC);
      for(i=0; i<pIdx->nColumn; i++){
        int cnum = pIdx->aiColumn[i];
        sqlite3VdbeAddOp(v, OP_Integer, i, 0);
        sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
        assert( pTab->nCol>cnum );
        sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 3, 0);







>

|
|
|
|
|
|

|

|

|
|
|
|














|
|
|







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
  */
  if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
    Table *pTab;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      int i;
      Column *pCol;
      sqlite3VdbeSetNumCols(v, 6);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
      sqlite3ViewGetColumnNames(pParse, pTab);
      for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
        sqlite3VdbeAddOp(v, OP_Integer, i, 0);
        sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
        sqlite3VdbeOp3(v, OP_String8, 0, 0,
           pCol->zType ? pCol->zType : "numeric", 0);
        sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
        sqlite3ExprCode(pParse, pCol->pDflt);
        sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
      }
    }
  }else

  if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
    Index *pIdx;
    Table *pTab;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    pIdx = sqlite3FindIndex(db, zRight, zDb);
    if( pIdx ){
      int i;
      pTab = pIdx->pTable;
      sqlite3VdbeSetNumCols(v, 3);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);
      for(i=0; i<pIdx->nColumn; i++){
        int cnum = pIdx->aiColumn[i];
        sqlite3VdbeAddOp(v, OP_Integer, i, 0);
        sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
        assert( pTab->nCol>cnum );
        sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
        sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
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
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      v = sqlite3GetVdbe(pParse);
      pIdx = pTab->pIndex;
      if( pIdx ){
        int i = 0; 
        sqlite3VdbeSetNumCols(v, 3);
        sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
        sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
        sqlite3VdbeSetColName(v, 2, "unique", P3_STATIC);
        while(pIdx){
          sqlite3VdbeAddOp(v, OP_Integer, i, 0);
          sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
          sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
          sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
          ++i;
          pIdx = pIdx->pNext;
        }
      }
    }
  }else

  if( sqlite3StrICmp(zLeft, "database_list")==0 ){
    int i;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    sqlite3VdbeSetNumCols(v, 3);
    sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
    sqlite3VdbeSetColName(v, 2, "file", P3_STATIC);
    for(i=0; i<db->nDb; i++){
      if( db->aDb[i].pBt==0 ) continue;
      assert( db->aDb[i].zName!=0 );
      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
      sqlite3VdbeOp3(v, OP_String8, 0, 0,
           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
      sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
    }
  }else

  if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
    int i = 0;
    HashElem *p;
    sqlite3VdbeSetNumCols(v, 2);
    sqlite3VdbeSetColName(v, 0, "seq", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, "name", P3_STATIC);
    for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
      CollSeq *pColl = (CollSeq *)sqliteHashData(p);
      sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
      sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
    }
  }else







|
|
|
















|
|
|















|
|







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
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      v = sqlite3GetVdbe(pParse);
      pIdx = pTab->pIndex;
      if( pIdx ){
        int i = 0; 
        sqlite3VdbeSetNumCols(v, 3);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);
        while(pIdx){
          sqlite3VdbeAddOp(v, OP_Integer, i, 0);
          sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
          sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
          sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
          ++i;
          pIdx = pIdx->pNext;
        }
      }
    }
  }else

  if( sqlite3StrICmp(zLeft, "database_list")==0 ){
    int i;
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    sqlite3VdbeSetNumCols(v, 3);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);
    for(i=0; i<db->nDb; i++){
      if( db->aDb[i].pBt==0 ) continue;
      assert( db->aDb[i].zName!=0 );
      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
      sqlite3VdbeOp3(v, OP_String8, 0, 0,
           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
      sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
    }
  }else

  if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
    int i = 0;
    HashElem *p;
    sqlite3VdbeSetNumCols(v, 2);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
    for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
      CollSeq *pColl = (CollSeq *)sqliteHashData(p);
      sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
      sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
    }
  }else
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      v = sqlite3GetVdbe(pParse);
      pFK = pTab->pFKey;
      if( pFK ){
        int i = 0; 
        sqlite3VdbeSetNumCols(v, 5);
        sqlite3VdbeSetColName(v, 0, "id", P3_STATIC);
        sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC);
        sqlite3VdbeSetColName(v, 2, "table", P3_STATIC);
        sqlite3VdbeSetColName(v, 3, "from", P3_STATIC);
        sqlite3VdbeSetColName(v, 4, "to", P3_STATIC);
        while(pFK){
          int j;
          for(j=0; j<pFK->nCol; j++){
            char *zCol = pFK->aCol[j].zCol;
            sqlite3VdbeAddOp(v, OP_Integer, i, 0);
            sqlite3VdbeAddOp(v, OP_Integer, j, 0);
            sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);







|
|
|
|
|







581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      v = sqlite3GetVdbe(pParse);
      pFK = pTab->pFKey;
      if( pFK ){
        int i = 0; 
        sqlite3VdbeSetNumCols(v, 5);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);
        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);
        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);
        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);
        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);
        while(pFK){
          int j;
          for(j=0; j<pFK->nCol; j++){
            char *zCol = pFK->aCol[j].zCol;
            sqlite3VdbeAddOp(v, OP_Integer, i, 0);
            sqlite3VdbeAddOp(v, OP_Integer, j, 0);
            sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
      { OP_String8,     0, 0,        "ok"},
      { 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;
      Hash *pTbls;
      int cnt = 0;







|







647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
      { OP_String8,     0, 0,        "ok"},
      { OP_Callback,    1, 0,        0},
    };

    /* Initialize the VDBE program */
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "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;
      Hash *pTbls;
      int cnt = 0;
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
      { 0, 0 }
    };
    struct EncName *pEnc;
    encnames[6].enc = encnames[7].enc = SQLITE_UTF16NATIVE;
    if( !zRight ){    /* "PRAGMA encoding" */
      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, "encoding", P3_STATIC);
      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
      for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
        if( pEnc->enc==ENC(pParse->db) ){
          sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
          break;
        }
      }







|







792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
      { 0, 0 }
    };
    struct EncName *pEnc;
    encnames[6].enc = encnames[7].enc = SQLITE_UTF16NATIVE;
    if( !zRight ){    /* "PRAGMA encoding" */
      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC);
      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
      for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
        if( pEnc->enc==ENC(pParse->db) ){
          sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
          break;
        }
      }
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
  if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
    static const char *const azLockName[] = {
      "unlocked", "shared", "reserved", "pending", "exclusive"
    };
    int i;
    Vdbe *v = sqlite3GetVdbe(pParse);
    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 ){







|
|







898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
  if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
    static const char *const azLockName[] = {
      "unlocked", "shared", "reserved", "pending", "exclusive"
    };
    int i;
    Vdbe *v = sqlite3GetVdbe(pParse);
    sqlite3VdbeSetNumCols(v, 2);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "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 ){
Changes to SQLite.Interop/src/prepare.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 the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.13 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** Fill the InitData structure with an error message that indicates







|







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 the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.14 2006/02/10 19:45:45 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** Fill the InitData structure with an error message that indicates
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
  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

  if( sqlite3SafetyOff(db) ){
    rc = SQLITE_MISUSE;
  }







|
|
|


|
|
|
|
|







552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
  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, COLNAME_NAME, "order", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P3_STATIC);
    }else{
      sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P3_STATIC);
      sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P3_STATIC);
    }
  } 
#endif

  if( sqlite3SafetyOff(db) ){
    rc = SQLITE_MISUSE;
  }
Changes to SQLite.Interop/src/select.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 are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.18 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.







|







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 are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.19 2006/02/10 19:45:45 rmsimpson Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
758
759
760
761
762
763
764
765
766




767
768





769
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
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
852
853

854
855
856



857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
  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
** the original CREATE TABLE statement if the expression is a column.




** 
** The declaration type for an expression is either TEXT, NUMERIC or ANY.





** The declaration type for a ROWID field is INTEGER.
*/
static const char *columnType(NameContext *pNC, Expr *pExpr){






  char const *zType;



  int j;
  if( pExpr==0 || pNC->pSrcList==0 ) return 0;

  /* The TK_AS operator can only occur in ORDER BY, GROUP BY, HAVING,
  ** and LIMIT clauses.  But pExpr originates in the result set of a
  ** SELECT.  So pExpr can never contain an AS operator.
  */
  assert( pExpr->op!=TK_AS );

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




      Table *pTab = 0;

      int iCol = pExpr->iColumn;
      while( pNC && !pTab ){
        SrcList *pTabList = pNC->pSrcList;
        for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
        if( j<pTabList->nSrc ){
          pTab = pTabList->a[j].pTab;

        }else{
          pNC = pNC->pNext;
        }
      }

      if( pTab==0 ){
        /* FIX ME:
        ** This can occurs if you have something like "SELECT new.x;" inside
        ** a trigger.  In other words, if you reference the special "new"
        ** table in the result set of a select.  We do not have a good way
        ** to find the actual table type, so call it "TEXT".  This is really
        ** something of a bug, but I do not know how to fix it.
        **
        ** This code does not produce the correct answer - it just prevents
        ** a segfault.  See ticket #1229.
        */
        zType = "TEXT";
        break;
      }

      assert( pTab );























      if( iCol<0 ) iCol = pTab->iPKey;
      assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
      if( iCol<0 ){
        zType = "INTEGER";

      }else{
        zType = pTab->aCol[iCol].zType;

      }






      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_SELECT: {




      NameContext sNC;
      Select *pS = pExpr->pSelect;

      sNC.pSrcList = pExpr->pSelect->pSrc;
      sNC.pNext = pNC;

      zType = columnType(&sNC, pS->pEList->a[0].pExpr); 
      break;
    }
#endif
    default:
      zType = 0;
  }
  






  return zType;
}

/*
** Generate code that will tell the VDBE the declaration types of columns
** in the result set.
*/
static void generateColumnTypes(
  Parse *pParse,      /* Parser context */
  SrcList *pTabList,  /* List of tables */
  ExprList *pEList    /* Expressions defining the result set */
){
  Vdbe *v = pParse->pVdbe;
  int i;
  NameContext sNC;
  sNC.pSrcList = pTabList;

  for(i=0; i<pEList->nExpr; i++){
    Expr *p = pEList->a[i].pExpr;



    const char *zType = columnType(&sNC, p);
    if( zType==0 ) continue;
    /* The vdbe must make it's own copy of the column-type, in case the 

    ** schema is reset before this virtual machine is deleted.
    */
    sqlite3VdbeSetColName(v, i+pEList->nExpr, zType, strlen(zType));



  }
}

/*
** Generate code that will tell the VDBE the names of columns
** in the result set.  This information is used to provide the
** azCol[] values in the callback.
*/
static void _generateColumnNames(
  Parse *pParse,      /* Parser context */
  SrcList *pTabList,  /* List of tables */
  ExprList *pEList    /* Expressions defining the result set */
){
  Vdbe *v = pParse->pVdbe;
  int i, j;
  sqlite3 *db = pParse->db;







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

|
>
>
>
>
>
>
|
>
>
>











>
>
>
>
|
>
|





>




>














>

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




>
>
>
>


>
|

>
|



<
<


>
>
>
>
>
>
















>


>
>
>
|
|
|
>
|

|
>
>
>








|







758
759
760
761
762
763
764
765
766
767
768
769
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
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
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
878
879
880
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
  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.
**
** The declaration type is the exact datatype definition extracted from the
** original CREATE TABLE statement if the expression is a column. The
** declaration type for a ROWID field is INTEGER. Exactly when an expression
** is considered a column can be complex in the presence of subqueries. The
** result-set expression in all of the following SELECT statements is 
** considered a column by this function.
**

**   SELECT col FROM tbl;
**   SELECT (SELECT col FROM tbl;
**   SELECT (SELECT col FROM tbl);
**   SELECT abc FROM (SELECT col AS abc FROM tbl);
** 
** The declaration type for any expression other than a column is NULL.
*/
static const char *columnType(
  NameContext *pNC, 
  Expr *pExpr,
  const char **pzOriginDb,
  const char **pzOriginTab,
  const char **pzOriginCol
){
  char const *zType = 0;
  char const *zOriginDb = 0;
  char const *zOriginTab = 0;
  char const *zOriginCol = 0;
  int j;
  if( pExpr==0 || pNC->pSrcList==0 ) return 0;

  /* The TK_AS operator can only occur in ORDER BY, GROUP BY, HAVING,
  ** and LIMIT clauses.  But pExpr originates in the result set of a
  ** SELECT.  So pExpr can never contain an AS operator.
  */
  assert( pExpr->op!=TK_AS );

  switch( pExpr->op ){
    case TK_COLUMN: {
      /* The expression is a column. Locate the table the column is being
      ** extracted from in NameContext.pSrcList. This table may be real
      ** database table or a subquery.
      */
      Table *pTab = 0;            /* Table structure column is extracted from */
      Select *pS = 0;             /* Select the column is extracted from */
      int iCol = pExpr->iColumn;  /* Index of column in pTab */
      while( pNC && !pTab ){
        SrcList *pTabList = pNC->pSrcList;
        for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
        if( j<pTabList->nSrc ){
          pTab = pTabList->a[j].pTab;
          pS = pTabList->a[j].pSelect;
        }else{
          pNC = pNC->pNext;
        }
      }

      if( pTab==0 ){
        /* FIX ME:
        ** This can occurs if you have something like "SELECT new.x;" inside
        ** a trigger.  In other words, if you reference the special "new"
        ** table in the result set of a select.  We do not have a good way
        ** to find the actual table type, so call it "TEXT".  This is really
        ** something of a bug, but I do not know how to fix it.
        **
        ** This code does not produce the correct answer - it just prevents
        ** a segfault.  See ticket #1229.
        */
        zType = "TEXT";
        break;
      }

      assert( pTab );
#ifndef SQLITE_OMIT_SUBQUERY
      if( pS ){
        /* The "table" is actually a sub-select or a view in the FROM clause
        ** of the SELECT statement. Return the declaration type and origin
        ** data for the result-set column of the sub-select.
        */
        if( iCol>=0 && iCol<pS->pEList->nExpr ){
          /* If iCol is less than zero, then the expression requests the
          ** rowid of the sub-select or view. This expression is legal (see 
          ** test case misc2.2.2) - it always evaluates to NULL.
          */
          NameContext sNC;
          Expr *p = pS->pEList->a[iCol].pExpr;
          sNC.pSrcList = pS->pSrc;
          sNC.pNext = 0;
          sNC.pParse = pNC->pParse;
          zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); 
        }
      }else
#endif
      if( pTab->pSchema ){
        /* A real table */
        assert( !pS );
        if( iCol<0 ) iCol = pTab->iPKey;
        assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
        if( iCol<0 ){
          zType = "INTEGER";
          zOriginCol = "rowid";
        }else{
          zType = pTab->aCol[iCol].zType;
          zOriginCol = pTab->aCol[iCol].zName;
        }
        zOriginTab = pTab->zName;
        if( pNC->pParse ){
          int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
          zOriginDb = pNC->pParse->db->aDb[iDb].zName;
        }
      }
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_SELECT: {
      /* The expression is a sub-select. Return the declaration type and
      ** origin info for the single column in the result set of the SELECT
      ** statement.
      */
      NameContext sNC;
      Select *pS = pExpr->pSelect;
      Expr *p = pS->pEList->a[0].pExpr;
      sNC.pSrcList = pS->pSrc;
      sNC.pNext = pNC;
      sNC.pParse = pNC->pParse;
      zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); 
      break;
    }
#endif


  }
  
  if( pzOriginDb ){
    assert( pzOriginTab && pzOriginCol );
    *pzOriginDb = zOriginDb;
    *pzOriginTab = zOriginTab;
    *pzOriginCol = zOriginCol;
  }
  return zType;
}

/*
** Generate code that will tell the VDBE the declaration types of columns
** in the result set.
*/
static void generateColumnTypes(
  Parse *pParse,      /* Parser context */
  SrcList *pTabList,  /* List of tables */
  ExprList *pEList    /* Expressions defining the result set */
){
  Vdbe *v = pParse->pVdbe;
  int i;
  NameContext sNC;
  sNC.pSrcList = pTabList;
  sNC.pParse = pParse;
  for(i=0; i<pEList->nExpr; i++){
    Expr *p = pEList->a[i].pExpr;
    const char *zOrigDb = 0;
    const char *zOrigTab = 0;
    const char *zOrigCol = 0;
    const char *zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);

    /* The vdbe must make it's own copy of the column-type and other 
    ** column specific strings, in case the schema is reset before this
    ** virtual machine is deleted.
    */
    sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, P3_TRANSIENT);
    sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, P3_TRANSIENT);
    sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, P3_TRANSIENT);
    sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, P3_TRANSIENT);
  }
}

/*
** Generate code that will tell the VDBE the names of columns
** in the result set.  This information is used to provide the
** azCol[] values in the callback.
*/
static void generateColumnNames(
  Parse *pParse,      /* Parser context */
  SrcList *pTabList,  /* List of tables */
  ExprList *pEList    /* Expressions defining the result set */
){
  Vdbe *v = pParse->pVdbe;
  int i, j;
  sqlite3 *db = pParse->db;
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
  sqlite3VdbeSetNumCols(v, pEList->nExpr);
  for(i=0; i<pEList->nExpr; i++){
    Expr *p;
    p = pEList->a[i].pExpr;
    if( p==0 ) continue;
    if( pEList->a[i].zName ){
      char *zName = pEList->a[i].zName;
      sqlite3VdbeSetColName(v, i, zName, strlen(zName));
      continue;
    }
    if( p->op==TK_COLUMN && pTabList ){
      Table *pTab;
      char *zCol;
      int iCol = p->iColumn;
      for(j=0; j<pTabList->nSrc && pTabList->a[j].iCursor!=p->iTable; j++){}
      assert( j<pTabList->nSrc );
      pTab = pTabList->a[j].pTab;
      if( iCol<0 ) iCol = pTab->iPKey;
      assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
      if( iCol<0 ){
        zCol = "rowid";
      }else{
        zCol = pTab->aCol[iCol].zName;
      }
      if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){
        sqlite3VdbeSetColName(v, i, (char*)p->span.z, p->span.n);
      }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
        char *zName = 0;
        char *zTab;
 
        zTab = pTabList->a[j].zAlias;
        if( fullNames || zTab==0 ) zTab = pTab->zName;
        sqlite3SetString(&zName, zTab, ".", zCol, (char*)0);
        sqlite3VdbeSetColName(v, i, zName, P3_DYNAMIC);
      }else{
        sqlite3VdbeSetColName(v, i, zCol, strlen(zCol));
      }
    }else if( p->span.z && p->span.z[0] ){
      sqlite3VdbeSetColName(v, i, (char*)p->span.z, p->span.n);
      /* sqlite3VdbeCompressSpace(v, addr); */
    }else{
      char zName[30];
      assert( p->op!=TK_COLUMN || pTabList==0 );
      sprintf(zName, "column%d", i+1);
      sqlite3VdbeSetColName(v, i, zName, 0);
    }
  }
  generateColumnTypes(pParse, pTabList, pEList);
}

#ifndef SQLITE_OMIT_COMPOUND_SELECT
/*







|

















|







|

|


|





|







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
  sqlite3VdbeSetNumCols(v, pEList->nExpr);
  for(i=0; i<pEList->nExpr; i++){
    Expr *p;
    p = pEList->a[i].pExpr;
    if( p==0 ) continue;
    if( pEList->a[i].zName ){
      char *zName = pEList->a[i].zName;
      sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, strlen(zName));
      continue;
    }
    if( p->op==TK_COLUMN && pTabList ){
      Table *pTab;
      char *zCol;
      int iCol = p->iColumn;
      for(j=0; j<pTabList->nSrc && pTabList->a[j].iCursor!=p->iTable; j++){}
      assert( j<pTabList->nSrc );
      pTab = pTabList->a[j].pTab;
      if( iCol<0 ) iCol = pTab->iPKey;
      assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
      if( iCol<0 ){
        zCol = "rowid";
      }else{
        zCol = pTab->aCol[iCol].zName;
      }
      if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){
        sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
      }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
        char *zName = 0;
        char *zTab;
 
        zTab = pTabList->a[j].zAlias;
        if( fullNames || zTab==0 ) zTab = pTab->zName;
        sqlite3SetString(&zName, zTab, ".", zCol, (char*)0);
        sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, P3_DYNAMIC);
      }else{
        sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol));
      }
    }else if( p->span.z && p->span.z[0] ){
      sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
      /* sqlite3VdbeCompressSpace(v, addr); */
    }else{
      char zName[30];
      assert( p->op!=TK_COLUMN || pTabList==0 );
      sprintf(zName, "column%d", i+1);
      sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, 0);
    }
  }
  generateColumnTypes(pParse, pTabList, pEList);
}

#ifndef SQLITE_OMIT_COMPOUND_SELECT
/*
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
    pCol->zName = zName;

    /* Get the typename, type affinity, and collating sequence for the
    ** column.
    */
    memset(&sNC, 0, sizeof(sNC));
    sNC.pSrcList = pSelect->pSrc;
    zType = sqliteStrDup(columnType(&sNC, p));
    pCol->zType = zType;
    pCol->affinity = sqlite3ExprAffinity(p);
    pColl = sqlite3ExprCollSeq(pParse, p);
    if( pColl ){
      pCol->zColl = sqliteStrDup(pColl->zName);
    }
  }







|







1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
    pCol->zName = zName;

    /* Get the typename, type affinity, and collating sequence for the
    ** column.
    */
    memset(&sNC, 0, sizeof(sNC));
    sNC.pSrcList = pSelect->pSrc;
    zType = sqliteStrDup(columnType(&sNC, p, 0, 0, 0));
    pCol->zType = zType;
    pCol->affinity = sqlite3ExprAffinity(p);
    pColl = sqlite3ExprCollSeq(pParse, p);
    if( pColl ){
      pCol->zColl = sqliteStrDup(pColl->zName);
    }
  }
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
  }

  /* Begin generating code.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ) goto select_end;

  /* Identify column names if we will be using them in a callback.  This
  ** step is skipped if the output is going to some other destination.
  */
  if( eDest==SRT_Callback ){
    generateColumnNames(pParse, pTabList, pEList);
  }

  /* 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;
    }







<
<
<
<
<
<
<








|







2853
2854
2855
2856
2857
2858
2859







2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
  }

  /* 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 || pItem->isPopulated ) continue;
    if( pItem->zName!=0 ){
      zSavedAuthContext = pParse->zAuthContext;
      pParse->zAuthContext = pItem->zName;
      needRestoreContext = 1;
    }else{
      needRestoreContext = 0;
    }
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
3221
3222
3223
  */
  if( pOrderBy ){
    generateSortTail(pParse, p, v, pEList->nExpr, eDest, iParm);
  }

#ifndef SQLITE_OMIT_SUBQUERY
  /* If this was a subquery, we have now converted the subquery into a
  ** temporary table.  So delete the subquery structure from the parent
  ** to prevent this subquery from being evaluated again and to force the
  ** the use of the temporary table.
  */
  if( pParent ){
    assert( pParent->pSrc->nSrc>parentTab );
    assert( pParent->pSrc->a[parentTab].pSelect==p );
    sqlite3SelectDelete(p);
    pParent->pSrc->a[parentTab].pSelect = 0;
  }
#endif

  /* Jump here to skip this query
  */
  sqlite3VdbeResolveLabel(v, iEnd);

  /* The SELECT was successfully coded.   Set the return code to 0
  ** to indicate no errors.
  */
  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;
}







|
|
|




<
|
















>
>
>
>
>
>
>
>




3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268

3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
  */
  if( pOrderBy ){
    generateSortTail(pParse, p, v, pEList->nExpr, eDest, iParm);
  }

#ifndef SQLITE_OMIT_SUBQUERY
  /* If this was a subquery, we have now converted the subquery into a
  ** temporary table.  So set the SrcList_item.isPopulated flag to prevent
  ** this subquery from being evaluated again and to force the use of
  ** the temporary table.
  */
  if( pParent ){
    assert( pParent->pSrc->nSrc>parentTab );
    assert( pParent->pSrc->a[parentTab].pSelect==p );

    pParent->pSrc->a[parentTab].isPopulated = 1;
  }
#endif

  /* Jump here to skip this query
  */
  sqlite3VdbeResolveLabel(v, iEnd);

  /* The SELECT was successfully coded.   Set the return code to 0
  ** to indicate no errors.
  */
  rc = 0;

  /* Control jumps to here if an error is encountered above, or upon
  ** successful coding of the SELECT.
  */
select_end:

  /* Identify column names if we will be using them in a callback.  This
  ** step is skipped if the output is going to some other destination.
  */
  if( rc==SQLITE_OK && eDest==SRT_Callback ){
    generateColumnNames(pParse, pTabList, pEList);
  }

  sqliteFree(sAggInfo.aCol);
  sqliteFree(sAggInfo.aFunc);
  return rc;
}
Changes to SQLite.Interop/src/sqlite3.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 header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite3.h,v 1.18 2006/01/31 19:16:13 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++.







|







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 header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite3.h,v 1.19 2006/02/10 19:45:45 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++.
160
161
162
163
164
165
166

167
168
169
170
171
172
173
  char **errmsg                 /* Error msg written here */
);

/*
** Return values for sqlite3_exec() and sqlite3_step()
*/
#define SQLITE_OK           0   /* Successful result */

#define SQLITE_ERROR        1   /* SQL error or missing database */
#define SQLITE_INTERNAL     2   /* NOT USED. Internal logic error in SQLite */
#define SQLITE_PERM         3   /* Access permission denied */
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
#define SQLITE_BUSY         5   /* The database file is locked */
#define SQLITE_LOCKED       6   /* A table in the database is locked */
#define SQLITE_NOMEM        7   /* A malloc() failed */







>







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  char **errmsg                 /* Error msg written here */
);

/*
** Return values for sqlite3_exec() and sqlite3_step()
*/
#define SQLITE_OK           0   /* Successful result */
/* beginning-of-error-codes */
#define SQLITE_ERROR        1   /* SQL error or missing database */
#define SQLITE_INTERNAL     2   /* NOT USED. Internal logic error in SQLite */
#define SQLITE_PERM         3   /* Access permission denied */
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
#define SQLITE_BUSY         5   /* The database file is locked */
#define SQLITE_LOCKED       6   /* A table in the database is locked */
#define SQLITE_NOMEM        7   /* A malloc() failed */
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
#define SQLITE_AUTH        23   /* Authorization denied */
#define SQLITE_FORMAT      24   /* Auxiliary database format error */
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
/* end-of-return-codes */

/*
** Each entry in an SQLite table has a unique integer key.  (The key is
** the value of the INTEGER PRIMARY KEY column if there is such a column,
** otherwise the key is generated at random.  The unique key is always
** available as the ROWID, OID, or _ROWID_ column.)  The following routine
** returns the integer key of the most recent insert in the database.







|







189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
#define SQLITE_AUTH        23   /* Authorization denied */
#define SQLITE_FORMAT      24   /* Auxiliary database format error */
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
/* end-of-error-codes */

/*
** Each entry in an SQLite table has a unique integer key.  (The key is
** the value of the INTEGER PRIMARY KEY column if there is such a column,
** otherwise the key is generated at random.  The unique key is always
** available as the ROWID, OID, or _ROWID_ column.)  The following routine
** returns the integer key of the most recent insert in the database.
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
758
759
760
761
762
763
764
765
766
** the column heading for the Nth column of that statement, where N is the
** second function parameter.  The string returned is UTF-8 for
** sqlite3_column_name() and UTF-16 for sqlite3_column_name16().
*/
const char *sqlite3_column_name(sqlite3_stmt*,int);
const void *sqlite3_column_name16(sqlite3_stmt*,int);

























/*
** The first parameter is a compiled SQL statement. If this statement
** is a SELECT statement, the Nth column of the returned result set 
** of the SELECT is a table column then the declared type of the table
** column is returned. If the Nth column of the result set is not at table
** column, then a NULL pointer is returned. The returned string is always
** UTF-8 encoded. For example, in the database schema:
**
** CREATE TABLE t1(c1 VARIANT);
**
** And the following statement compiled:
**
** SELECT c1 + 1, 0 FROM t1;
**
** Then this routine would return the string "VARIANT" for the second
** result column (i==1), and a NULL pointer for the first result column
** (i==0).
*/
const char *sqlite3_column_decltype(sqlite3_stmt *, int i);

/*
** The first parameter is a compiled SQL statement. If this statement
** is a SELECT statement, the Nth column of the returned result set 
** of the SELECT is a table column then the declared type of the table
** column is returned. If the Nth column of the result set is not at table
** column, then a NULL pointer is returned. The returned string is always
** UTF-16 encoded. For example, in the database schema:
**
** CREATE TABLE t1(c1 INTEGER);
**
** And the following statement compiled:
**
** SELECT c1 + 1, 0 FROM t1;
**
** Then this routine would return the string "INTEGER" for the second
** result column (i==1), and a NULL pointer for the first result column
** (i==0).
*/
const void *sqlite3_column_decltype16(sqlite3_stmt*,int);








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












|



















|







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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
** the column heading for the Nth column of that statement, where N is the
** second function parameter.  The string returned is UTF-8 for
** sqlite3_column_name() and UTF-16 for sqlite3_column_name16().
*/
const char *sqlite3_column_name(sqlite3_stmt*,int);
const void *sqlite3_column_name16(sqlite3_stmt*,int);

/*
** The first parameter to the following calls is a compiled SQL statement.
** These functions return information about the Nth column returned by 
** the statement, where N is the second function argument.
**
** If the Nth column returned by the statement is not a column value,
** then all of the functions return NULL. Otherwise, the return the 
** name of the attached database, table and column that the expression
** extracts a value from.
**
** As with all other SQLite APIs, those postfixed with "16" return UTF-16
** encoded strings, the other functions return UTF-8. The memory containing
** the returned strings is valid until the statement handle is finalized().
**
** These APIs are only available if the library was compiled with the 
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
*/
const char *sqlite3_column_database_name(sqlite3_stmt*,int);
const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
const char *sqlite3_column_table_name(sqlite3_stmt*,int);
const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);

/*
** The first parameter is a compiled SQL statement. If this statement
** is a SELECT statement, the Nth column of the returned result set 
** of the SELECT is a table column then the declared type of the table
** column is returned. If the Nth column of the result set is not at table
** column, then a NULL pointer is returned. The returned string is always
** UTF-8 encoded. For example, in the database schema:
**
** CREATE TABLE t1(c1 VARIANT);
**
** And the following statement compiled:
**
** SELECT c1 + 1, c1 FROM t1;
**
** Then this routine would return the string "VARIANT" for the second
** result column (i==1), and a NULL pointer for the first result column
** (i==0).
*/
const char *sqlite3_column_decltype(sqlite3_stmt *, int i);

/*
** The first parameter is a compiled SQL statement. If this statement
** is a SELECT statement, the Nth column of the returned result set 
** of the SELECT is a table column then the declared type of the table
** column is returned. If the Nth column of the result set is not at table
** column, then a NULL pointer is returned. The returned string is always
** UTF-16 encoded. For example, in the database schema:
**
** CREATE TABLE t1(c1 INTEGER);
**
** And the following statement compiled:
**
** SELECT c1 + 1, c1 FROM t1;
**
** Then this routine would return the string "INTEGER" for the second
** result column (i==1), and a NULL pointer for the first result column
** (i==0).
*/
const void *sqlite3_column_decltype16(sqlite3_stmt*,int);

893
894
895
896
897
898
899

900
901
902
903
904
905
906
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
double sqlite3_column_double(sqlite3_stmt*, int iCol);
int sqlite3_column_int(sqlite3_stmt*, int iCol);
sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
int sqlite3_column_type(sqlite3_stmt*, int iCol);


/*
** The sqlite3_finalize() function is called to delete a compiled
** SQL statement obtained by a previous call to sqlite3_prepare()
** or sqlite3_prepare16(). If the statement was executed successfully, or
** not executed at all, then SQLITE_OK is returned. If execution of the
** statement failed then an error code is returned. 







>







918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
double sqlite3_column_double(sqlite3_stmt*, int iCol);
int sqlite3_column_int(sqlite3_stmt*, int iCol);
sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
int sqlite3_column_type(sqlite3_stmt*, int iCol);
int sqlite3_column_numeric_type(sqlite3_stmt*, int iCol);

/*
** The sqlite3_finalize() function is called to delete a compiled
** SQL statement obtained by a previous call to sqlite3_prepare()
** or sqlite3_prepare16(). If the statement was executed successfully, or
** not executed at all, then SQLITE_OK is returned. If execution of the
** statement failed then an error code is returned. 
976
977
978
979
980
981
982
983
984
985

986
987
988
989
990
991
992
  void*,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);

/*
** The next routine returns the number of calls to xStep for a particular
** aggregate function instance.  The current call to xStep counts so this
** routine always returns at least 1.

*/
int sqlite3_aggregate_count(sqlite3_context*);

/*
** The next group of routines returns information about parameters to
** a user-defined function.  Function implementations use these routines
** to access their parameters.  These routines are the same as the







<
|
<
>







1002
1003
1004
1005
1006
1007
1008

1009

1010
1011
1012
1013
1014
1015
1016
1017
  void*,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  void (*xFinal)(sqlite3_context*)
);

/*

** This function is deprecated.  Do not use it.  It continues to exist

** so as not to break legacy code.  But new code should avoid using it.
*/
int sqlite3_aggregate_count(sqlite3_context*);

/*
** The next group of routines returns information about parameters to
** a user-defined function.  Function implementations use these routines
** to access their parameters.  These routines are the same as the
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
int sqlite3_value_int(sqlite3_value*);
sqlite_int64 sqlite3_value_int64(sqlite3_value*);
const unsigned char *sqlite3_value_text(sqlite3_value*);
const void *sqlite3_value_text16(sqlite3_value*);
const void *sqlite3_value_text16le(sqlite3_value*);
const void *sqlite3_value_text16be(sqlite3_value*);
int sqlite3_value_type(sqlite3_value*);


/*
** Aggregate functions use the following routine to allocate
** a structure for storing their state.  The first time this routine
** is called for a particular aggregate, a new structure of size nBytes
** is allocated, zeroed, and returned.  On subsequent calls (for the
** same aggregate instance) the same buffer is returned.  The implementation







>







1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
int sqlite3_value_int(sqlite3_value*);
sqlite_int64 sqlite3_value_int64(sqlite3_value*);
const unsigned char *sqlite3_value_text(sqlite3_value*);
const void *sqlite3_value_text16(sqlite3_value*);
const void *sqlite3_value_text16le(sqlite3_value*);
const void *sqlite3_value_text16be(sqlite3_value*);
int sqlite3_value_type(sqlite3_value*);
int sqlite3_value_numeric_type(sqlite3_value*);

/*
** Aggregate functions use the following routine to allocate
** a structure for storing their state.  The first time this routine
** is called for a particular aggregate, a new structure of size nBytes
** is allocated, zeroed, and returned.  On subsequent calls (for the
** same aggregate instance) the same buffer is returned.  The implementation
1364
1365
1366
1367
1368
1369
1370





































































1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
** will be automatically deallocated once memory-management and
** shared-cache are disabled and the soft heap limit has been set
** to zero.  This routine is provided as a convenience for users who
** want to make absolutely sure they have not forgotten something
** prior to killing off a thread.
*/
void sqlite3_thread_cleanup(void);






































































/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
#ifdef SQLITE_OMIT_FLOATING_POINT
# undef double
#endif

#ifdef __cplusplus
}  /* End of the 'extern "C"' block */
#endif
#endif







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













1390
1391
1392
1393
1394
1395
1396
1397
1398
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
1444
1445
1446
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
1476
1477
1478
** will be automatically deallocated once memory-management and
** shared-cache are disabled and the soft heap limit has been set
** to zero.  This routine is provided as a convenience for users who
** want to make absolutely sure they have not forgotten something
** prior to killing off a thread.
*/
void sqlite3_thread_cleanup(void);

/*
** Return meta information about a specific column of a specific database
** table accessible using the connection handle passed as the first function 
** argument.
**
** The column is identified by the second, third and fourth parameters to 
** this function. The second parameter is either the name of the database
** (i.e. "main", "temp" or an attached database) containing the specified
** table or NULL. If it is NULL, then all attached databases are searched
** for the table using the same algorithm as the database engine uses to 
** resolve unqualified table references.
**
** The third and fourth parameters to this function are the table and column 
** name of the desired column, respectively. Neither of these parameters 
** may be NULL.
**
** Meta information is returned by writing to the memory locations passed as
** the 5th and subsequent parameters to this function. Any of these 
** arguments may be NULL, in which case the corresponding element of meta 
** information is ommitted.
**
** Parameter     Output Type      Description
** -----------------------------------
**
**   5th         const char*      Data type
**   6th         const char*      Name of the default collation sequence 
**   7th         int              True if the column has a NOT NULL constraint
**   8th         int              True if the column is part of the PRIMARY KEY
**   9th         int              True if the column is AUTOINCREMENT
**
**
** The memory pointed to by the character pointers returned for the 
** declaration type and collation sequence is valid only until the next 
** call to any sqlite API function.
**
** If the specified table is actually a view, then an error is returned.
**
** If the specified column is "rowid", "oid" or "_rowid_" and an 
** INTEGER PRIMARY KEY column has been explicitly declared, then the output 
** parameters are set for the explicitly declared column. If there is no
** explicitly declared IPK column, then the output parameters are set as 
** follows:
**
**     data type: "INTEGER"
**     collation sequence: "BINARY"
**     not null: 0
**     primary key: 1
**     auto increment: 0
**
** This function may load one or more schemas from database files. If an
** error occurs during this process, or if the requested table or column
** cannot be found, an SQLITE error code is returned and an error message
** left in the database handle (to be retrieved using sqlite3_errmsg()).
**
** This API is only available if the library was compiled with the
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
*/
int sqlite3_table_column_metadata(
  sqlite3 *db,                /* Connection handle */
  const char *zDbName,        /* Database name or NULL */
  const char *zTableName,     /* Table name */
  const char *zColumnName,    /* Column name */
  char const **pzDataType,    /* OUTPUT: Declared data type */
  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
  int *pAutoinc               /* OUTPUT: True if colums is auto-increment */
);

/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
#ifdef SQLITE_OMIT_FLOATING_POINT
# undef double
#endif

#ifdef __cplusplus
}  /* End of the 'extern "C"' block */
#endif
#endif
Changes to SQLite.Interop/src/sqliteInt.h.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.17 2006/01/31 19:16:13 rmsimpson Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_

/*
** Extra interface definitions for those who need them
*/













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.18 2006/02/10 19:45:45 rmsimpson Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_

/*
** Extra interface definitions for those who need them
*/
1065
1066
1067
1068
1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
  i16 nAlloc;      /* Number of entries allocated in a[] below */
  struct SrcList_item {
    char *zDatabase;  /* Name of database holding this table */
    char *zName;      /* Name of the table */
    char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
    Table *pTab;      /* An SQL table corresponding to zName */
    Select *pSelect;  /* A SELECT statement used in place of a table name */

    u8 jointype;      /* Type of join between this table and the next */
    i16 iCursor;      /* The VDBE cursor number used to access this table */
    Expr *pOn;        /* The ON clause of a join */
    IdList *pUsing;   /* The USING clause of a join */
    Bitmask colUsed;  /* Bit N (1<<N) set if column N or pTab is used */
  } a[1];             /* One entry for each identifier on the list */
};







>







1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
  i16 nAlloc;      /* Number of entries allocated in a[] below */
  struct SrcList_item {
    char *zDatabase;  /* Name of database holding this table */
    char *zName;      /* Name of the table */
    char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
    Table *pTab;      /* An SQL table corresponding to zName */
    Select *pSelect;  /* A SELECT statement used in place of a table name */
    u8 isPopulated;   /* Temporary table associated with SELECT is populated */
    u8 jointype;      /* Type of join between this table and the next */
    i16 iCursor;      /* The VDBE cursor number used to access this table */
    Expr *pOn;        /* The ON clause of a join */
    IdList *pUsing;   /* The USING clause of a join */
    Bitmask colUsed;  /* Bit N (1<<N) set if column N or pTab is used */
  } a[1];             /* One entry for each identifier on the list */
};
Changes to SQLite.Interop/src/tclsqlite.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.17 2006/01/31 19:16:13 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>













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.18 2006/02/10 19:45:46 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>
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1126
            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++){







>
|







1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
            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++){
Changes to SQLite.Interop/src/update.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 are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.17 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** The most recently coded instruction was an OP_Column to retrieve the
** i-th column of table pTab. This routine sets the P3 parameter of the 
** OP_Column to the default value, if any.







|







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 are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.18 2006/02/10 19:45:46 rmsimpson Exp $
*/
#include "sqliteInt.h"

/*
** The most recently coded instruction was an OP_Column to retrieve the
** i-th column of table pTab. This routine sets the P3 parameter of the 
** OP_Column to the default value, if any.
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  ** Return the number of rows that were changed. If this routine is 
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, "rows updated", P3_STATIC);
  }

update_cleanup:
  sqlite3AuthContextPop(&sContext);
  sqliteFree(apIdx);
  sqliteFree(aXRef);
  sqlite3SrcListDelete(pTabList);
  sqlite3ExprListDelete(pChanges);
  sqlite3ExprDelete(pWhere);
  return;
}







|











490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  ** Return the number of rows that were changed. If this routine is 
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", P3_STATIC);
  }

update_cleanup:
  sqlite3AuthContextPop(&sContext);
  sqliteFree(apIdx);
  sqliteFree(aXRef);
  sqlite3SrcListDelete(pTabList);
  sqlite3ExprListDelete(pChanges);
  sqlite3ExprDelete(pWhere);
  return;
}
Changes to SQLite.Interop/src/util.c.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.18 2006/01/31 19:16:13 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>

/*







|







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

/*
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

#endif  /* SQLITE_MEMDEBUG */
/*
** End code for memory allocation system test layer.
**--------------------------------------------------------------------------*/

/*
** The handleSoftLimit() function is called before each call to 
** sqlite3OsMalloc() or xRealloc(). The parameter 'n' is the number of
** extra bytes about to be allocated (for Realloc() this means the size of the
** new allocation less the size of the old allocation). If the extra allocation
** means that the total memory allocated to SQLite in this thread would exceed
** the limit set by sqlite3_soft_heap_limit(), then sqlite3_release_memory() is



** called to try to avoid this. No indication of whether or not this is

** successful is returned to the caller.
**
** If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, this routine is
** a no-op
*/
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
static int handleSoftLimit(int n){
























  ThreadData *pTsd = sqlite3ThreadData();
  if( pTsd ){
    pTsd->nAlloc += n;
    assert( pTsd->nAlloc>=0 );
    if( n>0 && pTsd->nSoftHeapLimit>0 ){
      while( pTsd->nAlloc>pTsd->nSoftHeapLimit && sqlite3_release_memory(n) );
    }else if( pTsd->nAlloc==0 && pTsd->nSoftHeapLimit==0 ){
      sqlite3ReleaseThreadData();
    }
  }
  return (pTsd ? 0 : 1);
}
#else
#define handleSoftLimit(x) 0
#endif

/*
** Allocate and return N bytes of uninitialised memory by calling
** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory 
** by calling sqlite3_release_memory().
*/
void *sqlite3MallocRaw(int n){
  void *p = 0;
  if( n>0 && !sqlite3MallocFailed() && !handleSoftLimit(n) ){
    while( (p = OSMALLOC(n))==0 && sqlite3_release_memory(n) );
    if( !p ){
      /* If the allocation failed, call handleSoftLimit() again, this time
      ** with the additive inverse of the argument passed to 
      ** handleSoftLimit() above. This is so the ThreadData.nAlloc variable is
      ** still correct after a malloc() failure. 
      */
      (void)handleSoftLimit(n * -1);
      sqlite3FailedMalloc();
      OSMALLOC_FAILED();


    }
  }
  return p;
}

/*
** Resize the allocation at p to n bytes by calling sqlite3OsRealloc(). The
** pointer to the new allocation is returned.  If the Realloc() call fails,
** attempt to free memory by calling sqlite3_release_memory().
*/
void *sqlite3Realloc(void *p, int n){
  if( sqlite3MallocFailed() ){
    return 0;
  }

  if( !p ){
    return sqlite3Malloc(n);
  }else{
    void *np = 0;

    if( !handleSoftLimit(n - OSSIZEOF(p)) ){


      while( (np = OSREALLOC(p, n))==0 && sqlite3_release_memory(n) );
      if( !np ){
        /* If the allocation failed, call handleSoftLimit() again, this time
        ** with the additive inverse of the argument passed to 
        ** handleSoftLimit() above. This is so the ThreadData.nAlloc variable is
        ** still correct after a malloc() failure. 
        */
        (void)handleSoftLimit(OSSIZEOF(p) - n);
        sqlite3FailedMalloc();
        OSMALLOC_FAILED();


      }
    }
    return np;
  }
}

/*
** Free the memory pointed to by p. p must be either a NULL pointer or a 
** value returned by a previous call to sqlite3Malloc() or sqlite3Realloc().
*/
void sqlite3FreeX(void *p){
  (void)handleSoftLimit(0 - OSSIZEOF(p));
  if( p ){

    OSFREE(p);
  }
}

/*
** A version of sqliteMalloc() that is always a function, not a macro.
** Currently, this is used only to alloc to allocate the parser engine.







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



|

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




<
<
|



<


|









|


<
<
<
<
<
<


>
>



















>
|
>
>


<
<
<
<
<
<


>
>











<

>







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

#endif  /* SQLITE_MEMDEBUG */
/*
** End code for memory allocation system test layer.
**--------------------------------------------------------------------------*/

/*
** This routine is called when we are about to allocate n additional bytes


** of memory.  If the new allocation will put is over the soft allocation

** limit, then invoke sqlite3_release_memory() to try to release some
** memory before continuing with the allocation.
**
** This routine also makes sure that the thread-specific-data (TSD) has
** be allocated.  If it has not and can not be allocated, then return
** false.  The updateMemoryUsedCount() routine below will deallocate
** the TSD if it ought to be.
**
** If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, this routine is
** a no-op
*/ 
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
static int enforceSoftLimit(int n){
  ThreadData *pTsd = sqlite3ThreadData();
  if( pTsd==0 ){
    return 0;
  }
  assert( pTsd->nAlloc>=0 );
  if( n>0 && pTsd->nSoftHeapLimit>0 ){
    while( pTsd->nAlloc+n>pTsd->nSoftHeapLimit && sqlite3_release_memory(n) );
  }
  return 1;
}
#else
# define enforceSoftLimit(X)  1
#endif

/*
** Update the count of total outstanding memory that is held in
** thread-specific-data (TSD).  If after this update the TSD is
** no longer being used, then deallocate it.
**
** If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, this routine is
** a no-op
*/
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
static void updateMemoryUsedCount(int n){
  ThreadData *pTsd = sqlite3ThreadData();
  if( pTsd ){
    pTsd->nAlloc += n;
    assert( pTsd->nAlloc>=0 );


    if( pTsd->nAlloc==0 && pTsd->nSoftHeapLimit==0 ){
      sqlite3ReleaseThreadData();
    }
  }

}
#else
#define updateMemoryUsedCount(x)  /* no-op */
#endif

/*
** Allocate and return N bytes of uninitialised memory by calling
** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory 
** by calling sqlite3_release_memory().
*/
void *sqlite3MallocRaw(int n){
  void *p = 0;
  if( n>0 && !sqlite3MallocFailed() && enforceSoftLimit(n) ){
    while( (p = OSMALLOC(n))==0 && sqlite3_release_memory(n) );
    if( !p ){






      sqlite3FailedMalloc();
      OSMALLOC_FAILED();
    }else{
      updateMemoryUsedCount(OSSIZEOF(p));
    }
  }
  return p;
}

/*
** Resize the allocation at p to n bytes by calling sqlite3OsRealloc(). The
** pointer to the new allocation is returned.  If the Realloc() call fails,
** attempt to free memory by calling sqlite3_release_memory().
*/
void *sqlite3Realloc(void *p, int n){
  if( sqlite3MallocFailed() ){
    return 0;
  }

  if( !p ){
    return sqlite3Malloc(n);
  }else{
    void *np = 0;
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
    int origSize = OSSIZEOF(p);
#endif
    if( enforceSoftLimit(n - origSize) ){
      while( (np = OSREALLOC(p, n))==0 && sqlite3_release_memory(n) );
      if( !np ){






        sqlite3FailedMalloc();
        OSMALLOC_FAILED();
      }else{
        updateMemoryUsedCount(OSSIZEOF(np) - origSize);
      }
    }
    return np;
  }
}

/*
** Free the memory pointed to by p. p must be either a NULL pointer or a 
** value returned by a previous call to sqlite3Malloc() or sqlite3Realloc().
*/
void sqlite3FreeX(void *p){

  if( p ){
    updateMemoryUsedCount(0 - OSSIZEOF(p));
    OSFREE(p);
  }
}

/*
** A version of sqliteMalloc() that is always a function, not a macro.
** Currently, this is used only to alloc to allocate the parser engine.
Changes to SQLite.Interop/src/vdbe.c.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.19 2006/02/02 22:45:10 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*







|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** in this file for details.  If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.20 2006/02/10 19:45:46 rmsimpson Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
184
185
186
187
188
189
190

























191
192
193
194
195
196
197
  }
  p->apCsr[iCur] = pCx = sqliteMalloc( sizeof(Cursor) );
  if( pCx ){
    pCx->iDb = iDb;
  }
  return pCx;
}


























/*
** Processing is determine by the affinity parameter:
**
** SQLITE_AFF_INTEGER:
** SQLITE_AFF_REAL:
** SQLITE_AFF_NUMERIC:







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







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
  }
  p->apCsr[iCur] = pCx = sqliteMalloc( sizeof(Cursor) );
  if( pCx ){
    pCx->iDb = iDb;
  }
  return pCx;
}

/*
** Try to convert a value into a numeric representation if we can
** do so without loss of information.  In other words, if the string
** looks like a number, convert it into a number.  If it does not
** look like a number, leave it alone.
*/
static void applyNumericAffinity(Mem *pRec){
  if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
    int realnum;
    sqlite3VdbeMemNulTerminate(pRec);
    if( (pRec->flags&MEM_Str)
         && sqlite3IsNumber(pRec->z, &realnum, pRec->enc) ){
      i64 value;
      sqlite3VdbeChangeEncoding(pRec, SQLITE_UTF8);
      if( !realnum && sqlite3atoi64(pRec->z, &value) ){
        sqlite3VdbeMemRelease(pRec);
        pRec->i = value;
        pRec->flags = MEM_Int;
      }else{
        sqlite3VdbeMemRealify(pRec);
      }
    }
  }
}

/*
** Processing is determine by the affinity parameter:
**
** SQLITE_AFF_INTEGER:
** SQLITE_AFF_REAL:
** SQLITE_AFF_NUMERIC:
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
    if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
      sqlite3VdbeMemStringify(pRec, enc);
    }
    pRec->flags &= ~(MEM_Real|MEM_Int);
  }else if( affinity!=SQLITE_AFF_NONE ){
    assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
             || affinity==SQLITE_AFF_NUMERIC );
    if( 0==(pRec->flags&(MEM_Real|MEM_Int)) ){
      /* pRec does not have a valid integer or real representation. 
      ** Attempt a conversion if pRec has a string representation and
      ** it looks like a number.
      */
      int realnum;
      sqlite3VdbeMemNulTerminate(pRec);
      if( (pRec->flags&MEM_Str)
           && sqlite3IsNumber(pRec->z, &realnum, pRec->enc) ){
        i64 value;
        sqlite3VdbeChangeEncoding(pRec, SQLITE_UTF8);
        if( !realnum && sqlite3atoi64(pRec->z, &value) ){
          sqlite3VdbeMemRelease(pRec);
          pRec->i = value;
          pRec->flags = MEM_Int;
        }else{
          sqlite3VdbeMemNumerify(pRec);
        }
      }
    }else if( pRec->flags & MEM_Real ){
      sqlite3VdbeIntegerAffinity(pRec);
    }
  }













}

/*
** Exported version of applyAffinity(). This one works on sqlite3_value*, 
** not the internal Mem* type.
*/
void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){
  applyAffinity((Mem *)pVal, affinity, enc);







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








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
    if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
      sqlite3VdbeMemStringify(pRec, enc);
    }
    pRec->flags &= ~(MEM_Real|MEM_Int);
  }else if( affinity!=SQLITE_AFF_NONE ){
    assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
             || affinity==SQLITE_AFF_NUMERIC );












    applyNumericAffinity(pRec);

    if( pRec->flags & MEM_Real ){

      sqlite3VdbeIntegerAffinity(pRec);
    }
  }


}

/*
** Try to convert the type of a function argument or a result column
** into a numeric representation.  Use either INTEGER or REAL whichever
** is appropriate.  But only do the conversion if it is possible without
** loss of information and return the revised type of the argument.
**
** This is an EXPERIMENTAL api and is subject to change or removal.
*/
int sqlite3_value_numeric_type(sqlite3_value *pVal){
  Mem *pMem = (Mem*)pVal;
  applyNumericAffinity(pMem);
  storeTypeInfo(pMem, 0);
  return pMem->type;
}

/*
** Exported version of applyAffinity(). This one works on sqlite3_value*, 
** not the internal Mem* type.
*/
void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){
  applyAffinity((Mem *)pVal, affinity, enc);
1961
1962
1963
1964
1965
1966
1967

1968
1969
1970
1971
1972
1973
1974
  if( pC && pC->cacheStatus==p->cacheCtr ){
    aType = pC->aType;
    aOffset = pC->aOffset;
  }else{
    u8 *zIdx;        /* Index into header */
    u8 *zEndHdr;     /* Pointer to first byte after the header */
    u32 offset;      /* Offset into the data */

    int avail;       /* Number of bytes of available data */
    if( pC && pC->aType ){
      aType = pC->aType;
    }else{
      aType = sqliteMallocRaw( 2*nField*sizeof(aType) );
    }
    aOffset = &aType[nField];







>







1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
  if( pC && pC->cacheStatus==p->cacheCtr ){
    aType = pC->aType;
    aOffset = pC->aOffset;
  }else{
    u8 *zIdx;        /* Index into header */
    u8 *zEndHdr;     /* Pointer to first byte after the header */
    u32 offset;      /* Offset into the data */
    int szHdrSz;     /* Size of the header size field at start of record */
    int avail;       /* Number of bytes of available data */
    if( pC && pC->aType ){
      aType = pC->aType;
    }else{
      aType = sqliteMallocRaw( 2*nField*sizeof(aType) );
    }
    aOffset = &aType[nField];
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
      if( avail>=payloadSize ){
        zRec = zData;
        pC->aRow = (u8*)zData;
      }else{
        pC->aRow = 0;
      }
    }

    zIdx = (u8 *)GetVarint((u8*)zData, offset);

    /* The KeyFetch() or DataFetch() above are fast and will get the entire
    ** record header in most cases.  But they will fail to get the complete
    ** record header if the record header does not fit on a single page
    ** in the B-Tree.  When that happens, use sqlite3VdbeMemFromBtree() to
    ** acquire the complete header text.
    */
    if( !zRec && avail<offset ){
      rc = sqlite3VdbeMemFromBtree(pCrsr, 0, offset, pC->isIndex, &sMem);
      if( rc!=SQLITE_OK ){
        goto op_column_out;
      }
      zData = sMem.z;
    }
    zEndHdr = (u8 *)zData + offset;
    zIdx = (u8 *)zData + (int)zIdx;

    /* Scan the header and use it to fill in the aType[] and aOffset[]
    ** arrays.  aType[i] will contain the type integer for the i-th
    ** column and aOffset[i] will contain the offset from the beginning
    ** of the record to the start of the data for the i-th column
    */
    for(i=0; i<nField; i++){







>
|














|
|







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
      if( avail>=payloadSize ){
        zRec = zData;
        pC->aRow = (u8*)zData;
      }else{
        pC->aRow = 0;
      }
    }
    assert( zRec!=0 || avail>=payloadSize || avail>=9 );
    szHdrSz = GetVarint((u8*)zData, offset);

    /* The KeyFetch() or DataFetch() above are fast and will get the entire
    ** record header in most cases.  But they will fail to get the complete
    ** record header if the record header does not fit on a single page
    ** in the B-Tree.  When that happens, use sqlite3VdbeMemFromBtree() to
    ** acquire the complete header text.
    */
    if( !zRec && avail<offset ){
      rc = sqlite3VdbeMemFromBtree(pCrsr, 0, offset, pC->isIndex, &sMem);
      if( rc!=SQLITE_OK ){
        goto op_column_out;
      }
      zData = sMem.z;
    }
    zEndHdr = (u8 *)&zData[offset];
    zIdx = (u8 *)&zData[szHdrSz];

    /* Scan the header and use it to fill in the aType[] and aOffset[]
    ** arrays.  aType[i] will contain the type integer for the i-th
    ** column and aOffset[i] will contain the offset from the beginning
    ** of the record to the start of the data for the i-th column
    */
    for(i=0; i<nField; i++){
Changes to SQLite.Interop/src/vdbe.h.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************************************************************
** Header file for the Virtual DataBase Engine (VDBE)
**
** This header defines the interface to the virtual database engine
** or VDBE.  The VDBE implements an abstract machine that runs a
** simple program to access and modify the underlying database.
**
** $Id: vdbe.h,v 1.17 2006/01/31 19:16:13 rmsimpson Exp $
*/
#ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_
#include <stdio.h>

/*
** A single VDBE is an opaque structure named "Vdbe".  Only routines







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************************************************************
** Header file for the Virtual DataBase Engine (VDBE)
**
** This header defines the interface to the virtual database engine
** or VDBE.  The VDBE implements an abstract machine that runs a
** simple program to access and modify the underlying database.
**
** $Id: vdbe.h,v 1.18 2006/02/10 19:45:46 rmsimpson Exp $
*/
#ifndef _SQLITE_VDBE_H_
#define _SQLITE_VDBE_H_
#include <stdio.h>

/*
** A single VDBE is an opaque structure named "Vdbe".  Only routines
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
80
81











82
83
84
85
86
87
88
#define P3_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
#define P3_STATIC   (-2)  /* Pointer to a static string */
#define P3_COLLSEQ  (-4)  /* P3 is a pointer to a CollSeq structure */
#define P3_FUNCDEF  (-5)  /* P3 is a pointer to a FuncDef structure */
#define P3_KEYINFO  (-6)  /* P3 is a pointer to a KeyInfo structure */
#define P3_VDBEFUNC (-7)  /* P3 is a pointer to a VdbeFunc structure */
#define P3_MEM      (-8)  /* P3 is a pointer to a Mem*    structure */


/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
** is made.  That copy is freed when the Vdbe is finalized.  But if the
** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used.  It still
** gets freed when the Vdbe is finalized so it still should be obtained
** from a single sqliteMalloc().  But no copy is made and the calling
** function should *not* try to free the KeyInfo.
*/
#define P3_KEYINFO_HANDOFF (-9)












/*
** The following macro converts a relative address in the p2 field
** of a VdbeOp structure into a negative number so that 
** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
** the macro again restores the address.
*/
#define ADDR(X)  (-1-(X))







>










>
>
>
>
>
>
>
>
>
>
>







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
#define P3_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
#define P3_STATIC   (-2)  /* Pointer to a static string */
#define P3_COLLSEQ  (-4)  /* P3 is a pointer to a CollSeq structure */
#define P3_FUNCDEF  (-5)  /* P3 is a pointer to a FuncDef structure */
#define P3_KEYINFO  (-6)  /* P3 is a pointer to a KeyInfo structure */
#define P3_VDBEFUNC (-7)  /* P3 is a pointer to a VdbeFunc structure */
#define P3_MEM      (-8)  /* P3 is a pointer to a Mem*    structure */
#define P3_TRANSIENT (-9)  /* P3 is a pointer to a transient string */

/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
** is made.  That copy is freed when the Vdbe is finalized.  But if the
** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used.  It still
** gets freed when the Vdbe is finalized so it still should be obtained
** from a single sqliteMalloc().  But no copy is made and the calling
** function should *not* try to free the KeyInfo.
*/
#define P3_KEYINFO_HANDOFF (-9)

/*
** The Vdbe.aColName array contains 5n Mem structures, where n is the 
** number of columns of data returned by the statement.
*/
#define COLNAME_NAME     0
#define COLNAME_DECLTYPE 1
#define COLNAME_DATABASE 2
#define COLNAME_TABLE    3
#define COLNAME_COLUMN   4
#define COLNAME_N        5      /* Number of COLNAME_xxx symbols */

/*
** The following macro converts a relative address in the p2 field
** of a VdbeOp structure into a negative number so that 
** sqlite3VdbeAddOpList() knows that the address is relative.  Calling
** the macro again restores the address.
*/
#define ADDR(X)  (-1-(X))
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
int sqlite3VdbeFinalize(Vdbe*);
void sqlite3VdbeResolveLabel(Vdbe*, int);
int sqlite3VdbeCurrentAddr(Vdbe*);
void sqlite3VdbeTrace(Vdbe*,FILE*);
int sqlite3VdbeReset(Vdbe*);
int sqliteVdbeSetVariables(Vdbe*,int,const char**);
void sqlite3VdbeSetNumCols(Vdbe*,int);
int sqlite3VdbeSetColName(Vdbe*, int, const char *, int);
void sqlite3VdbeCountChanges(Vdbe*);
sqlite3 *sqlite3VdbeDb(Vdbe*);

#ifndef NDEBUG
  void sqlite3VdbeComment(Vdbe*, const char*, ...);
# define VdbeComment(X)  sqlite3VdbeComment X
#else
# define VdbeComment(X)
#endif

#endif







|











125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
int sqlite3VdbeFinalize(Vdbe*);
void sqlite3VdbeResolveLabel(Vdbe*, int);
int sqlite3VdbeCurrentAddr(Vdbe*);
void sqlite3VdbeTrace(Vdbe*,FILE*);
int sqlite3VdbeReset(Vdbe*);
int sqliteVdbeSetVariables(Vdbe*,int,const char**);
void sqlite3VdbeSetNumCols(Vdbe*,int);
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
void sqlite3VdbeCountChanges(Vdbe*);
sqlite3 *sqlite3VdbeDb(Vdbe*);

#ifndef NDEBUG
  void sqlite3VdbeComment(Vdbe*, const char*, ...);
# define VdbeComment(X)  sqlite3VdbeComment X
#else
# define VdbeComment(X)
#endif

#endif
Changes to SQLite.Interop/src/vdbeapi.c.
70
71
72
73
74
75
76

77
78
79
80
81
82
83
const void *sqlite3_value_text16le(sqlite3_value *pVal){
  return sqlite3ValueText(pVal, SQLITE_UTF16LE);
}
#endif /* SQLITE_OMIT_UTF16 */
int sqlite3_value_type(sqlite3_value* pVal){
  return pVal->type;
}


/**************************** sqlite3_result_  *******************************
** The following routines are used by user-defined functions to specify
** the function result.
*/
void sqlite3_result_blob(
  sqlite3_context *pCtx, 







>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const void *sqlite3_value_text16le(sqlite3_value *pVal){
  return sqlite3ValueText(pVal, SQLITE_UTF16LE);
}
#endif /* SQLITE_OMIT_UTF16 */
int sqlite3_value_type(sqlite3_value* pVal){
  return pVal->type;
}
/* sqlite3_value_numeric_type() defined in vdbe.c */

/**************************** sqlite3_result_  *******************************
** The following routines are used by user-defined functions to specify
** the function result.
*/
void sqlite3_result_blob(
  sqlite3_context *pCtx, 
331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347
  pAuxData->xDelete = xDelete;
}

/*
** Return the number of times the Step function of a aggregate has been 
** called.
**
** This routine is defined here in vdbe.c because it depends on knowing
** the internals of the sqlite3_context structure which is only defined in

** this source file.
*/
int sqlite3_aggregate_count(sqlite3_context *p){
  assert( p && p->pFunc && p->pFunc->xStep );
  return p->pMem->n;
}

/*







|
|
>
|







332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
  pAuxData->xDelete = xDelete;
}

/*
** Return the number of times the Step function of a aggregate has been 
** called.
**
** This function is deprecated.  Do not use it for new code.  It is
** provide only to avoid breaking legacy code.  New aggregate function
** implementations should keep their own counts within their aggregate
** context.
*/
int sqlite3_aggregate_count(sqlite3_context *p){
  assert( p && p->pFunc && p->pFunc->xStep );
  return p->pMem->n;
}

/*
464
465
466
467
468
469
470







471
472
473
474
475
476
477
  return val;
}
#endif /* SQLITE_OMIT_UTF16 */
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
  return sqlite3_value_type( columnMem(pStmt,i) );
}








/*
** Convert the N-th element of pStmt->pColName[] into a string using
** xFunc() then return that string.  If N is out of range, return 0.
**
** There are up to 5 names for each column.  useType determines which
** name is returned.  Here are the names:
**







>
>
>
>
>
>
>







466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
  return val;
}
#endif /* SQLITE_OMIT_UTF16 */
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
  return sqlite3_value_type( columnMem(pStmt,i) );
}

/* The following function is experimental and subject to change or
** removal */
/*int sqlite3_column_numeric_type(sqlite3_stmt *pStmt, int i){
**  return sqlite3_value_numeric_type( columnMem(pStmt,i) );
**}
*/

/*
** Convert the N-th element of pStmt->pColName[] into a string using
** xFunc() then return that string.  If N is out of range, return 0.
**
** There are up to 5 names for each column.  useType determines which
** name is returned.  Here are the names:
**
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
}

/*
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
*/
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
}
#endif

/*
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt.
*/
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
}
#endif /* SQLITE_OMIT_UTF16 */

#if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0
/*
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 2);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2);
}
#endif /* SQLITE_OMIT_UTF16 */

/*
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 3);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3);
}
#endif /* SQLITE_OMIT_UTF16 */

/*
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 4);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){

  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4);
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_OMIT_ORIGIN_NAMES */




/******************************* sqlite3_bind_  ***************************
** 
** Routines used to attach values to wildcards in a compiled SQL statement.
*/
/*







>
|



>
|








>
|



>
|



|






>
|



>
|









>
|



>
|









>
|



>
|


|
<
<







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
}

/*
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
*/
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
}
#endif

/*
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt.
*/
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
}
#endif /* SQLITE_OMIT_UTF16 */

#ifdef SQLITE_ENABLE_COLUMN_METADATA
/*
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
}
#endif /* SQLITE_OMIT_UTF16 */

/*
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
}
#endif /* SQLITE_OMIT_UTF16 */

/*
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
}
#ifndef SQLITE_OMIT_UTF16
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
}
#endif /* SQLITE_OMIT_UTF16 */
#endif /* SQLITE_ENABLE_COLUMN_METADATA */




/******************************* sqlite3_bind_  ***************************
** 
** Routines used to attach values to wildcards in a compiled SQL statement.
*/
/*
Changes to SQLite.Interop/src/vdbeaux.c.
867
868
869
870
871
872
873
874
875
876
877
878
879
880
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
** statement. This is now set at compile time, rather than during
** execution of the vdbe program so that sqlite3_column_count() can
** be called on an SQL statement before sqlite3_step().
*/
void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
  Mem *pColName;
  int n;
  releaseMemArray(p->aColName, p->nResColumn*2);
  sqliteFree(p->aColName);
  n = nResColumn*2;
  p->nResColumn = nResColumn;
  p->aColName = pColName = (Mem*)sqliteMalloc( sizeof(Mem)*n );
  if( p->aColName==0 ) return;
  while( n-- > 0 ){
    (pColName++)->flags = MEM_Null;
  }
}

/*
** Set the name of the idx'th column to be returned by the SQL statement.
** zName must be a pointer to a nul terminated string.
**
** This call must be made after a call to sqlite3VdbeSetNumCols().
**
** If N==P3_STATIC  it means that zName is a pointer to a constant static
** string and we can just copy the pointer. If it is P3_DYNAMIC, then 
** the string is freed using sqliteFree() when the vdbe is finished with
** it. Otherwise, N bytes of zName are copied.
*/
int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){
  int rc;
  Mem *pColName;
  assert( idx<(2*p->nResColumn) );

  if( sqlite3MallocFailed() ) return SQLITE_NOMEM;
  assert( p->aColName!=0 );
  pColName = &(p->aColName[idx]);
  if( N==P3_DYNAMIC || N==P3_STATIC ){
    rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC);
  }else{
    rc = sqlite3VdbeMemSetStr(pColName, zName, N, SQLITE_UTF8,SQLITE_TRANSIENT);
  }
  if( rc==SQLITE_OK && N==P3_DYNAMIC ){
    pColName->flags = (pColName->flags&(~MEM_Static))|MEM_Dyn;







|

|



















|


|
>


|







867
868
869
870
871
872
873
874
875
876
877
878
879
880
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
** statement. This is now set at compile time, rather than during
** execution of the vdbe program so that sqlite3_column_count() can
** be called on an SQL statement before sqlite3_step().
*/
void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
  Mem *pColName;
  int n;
  releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
  sqliteFree(p->aColName);
  n = nResColumn*COLNAME_N;
  p->nResColumn = nResColumn;
  p->aColName = pColName = (Mem*)sqliteMalloc( sizeof(Mem)*n );
  if( p->aColName==0 ) return;
  while( n-- > 0 ){
    (pColName++)->flags = MEM_Null;
  }
}

/*
** Set the name of the idx'th column to be returned by the SQL statement.
** zName must be a pointer to a nul terminated string.
**
** This call must be made after a call to sqlite3VdbeSetNumCols().
**
** If N==P3_STATIC  it means that zName is a pointer to a constant static
** string and we can just copy the pointer. If it is P3_DYNAMIC, then 
** the string is freed using sqliteFree() when the vdbe is finished with
** it. Otherwise, N bytes of zName are copied.
*/
int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
  int rc;
  Mem *pColName;
  assert( idx<p->nResColumn );
  assert( var<COLNAME_N );
  if( sqlite3MallocFailed() ) return SQLITE_NOMEM;
  assert( p->aColName!=0 );
  pColName = &(p->aColName[idx+var*p->nResColumn]);
  if( N==P3_DYNAMIC || N==P3_STATIC ){
    rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC);
  }else{
    rc = sqlite3VdbeMemSetStr(pColName, zName, N, SQLITE_UTF8,SQLITE_TRANSIENT);
  }
  if( rc==SQLITE_OK && N==P3_DYNAMIC ){
    pColName->flags = (pColName->flags&(~MEM_Static))|MEM_Dyn;
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
      freeP3(pOp->p3type, pOp->p3);
    }
    sqliteFree(p->aOp);
  }
  releaseMemArray(p->aVar, p->nVar);
  sqliteFree(p->aLabel);
  sqliteFree(p->aStack);
  releaseMemArray(p->aColName, p->nResColumn*2);
  sqliteFree(p->aColName);
  p->magic = VDBE_MAGIC_DEAD;
  sqliteFree(p);
}

/*
** If a MoveTo operation is pending on the given cursor, then do that







|







1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
      freeP3(pOp->p3type, pOp->p3);
    }
    sqliteFree(p->aOp);
  }
  releaseMemArray(p->aVar, p->nVar);
  sqliteFree(p->aLabel);
  sqliteFree(p->aStack);
  releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
  sqliteFree(p->aColName);
  p->magic = VDBE_MAGIC_DEAD;
  sqliteFree(p);
}

/*
** If a MoveTo operation is pending on the given cursor, then do that