Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | 3.2.7 codemerge |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sourceforge |
Files: | files | file ages | folders |
SHA1: |
48ac9068b592fe4e47e87c0947d9a46c |
User & Date: | rmsimpson 2005-10-05 19:38:29.000 |
Context
2005-10-19
| ||
17:10 | 1.0.20 check-in: a0d4d0cf1c user: rmsimpson tags: sourceforge | |
2005-10-05
| ||
19:38 | 3.2.7 codemerge check-in: 48ac9068b5 user: rmsimpson tags: sourceforge | |
19:33 | 1.0.19 check-in: 35ace076c2 user: rmsimpson tags: sourceforge | |
Changes
Changes to SQLite.Interop/src/alter.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** ** $Id: alter.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** The code in this file only exists if we are not omitting the ** ALTER TABLE logic from the build. |
︙ | ︙ |
Changes to SQLite.Interop/src/analyze.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2005 July 8 ** ** 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 associated with the ANALYZE command. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2005 July 8 ** ** 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 associated with the ANALYZE command. ** ** @(#) $Id: analyze.c,v 1.3 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef SQLITE_OMIT_ANALYZE #include "sqliteInt.h" /* ** This routine generates code that opens the sqlite_stat1 table on cursor ** iStatCur. |
︙ | ︙ | |||
84 85 86 87 88 89 90 | Vdbe *v; /* The virtual machine being built up */ int i; /* Loop counter */ int topOfLoop; /* The top of the loop */ int endOfLoop; /* The end of the loop */ int addr; /* The address of an instruction */ v = sqlite3GetVdbe(pParse); | | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | Vdbe *v; /* The virtual machine being built up */ int i; /* Loop counter */ int topOfLoop; /* The top of the loop */ int endOfLoop; /* The end of the loop */ int addr; /* The address of an instruction */ v = sqlite3GetVdbe(pParse); if( pTab==0 || pTab->pIndex==0 ){ /* Do no analysis for tables that have no indices */ return; } #ifndef SQLITE_OMIT_AUTHORIZATION if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0, pParse->db->aDb[pTab->iDb].zName ) ){ return; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | ** mem[iMem+nCol+1] Last observed value of column 1 ** ... ** mem[iMem+nCol+nCol]: Last observed value of column N ** ** Cells iMem through iMem+nCol are initialized to 0. The others ** are initialized to NULL. */ | < | < | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | ** mem[iMem+nCol+1] Last observed value of column 1 ** ... ** mem[iMem+nCol+nCol]: Last observed value of column N ** ** Cells iMem through iMem+nCol are initialized to 0. The others ** are initialized to NULL. */ for(i=0; i<=nCol; i++){ sqlite3VdbeAddOp(v, OP_MemInt, 0, iMem+i); } for(i=0; i<nCol; i++){ sqlite3VdbeAddOp(v, OP_MemNull, iMem+nCol+i+1, 0); } /* Do the analysis. */ endOfLoop = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop); topOfLoop = sqlite3VdbeCurrentAddr(v); |
︙ | ︙ | |||
194 195 196 197 198 199 200 | sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0); }else{ sqlite3VdbeAddOp(v, OP_Dup, 1, 0); } } sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0); sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0); | | | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0); }else{ sqlite3VdbeAddOp(v, OP_Dup, 1, 0); } } sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0); sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0); sqlite3VdbeJumpHere(v, addr); } } /* ** Generate code that will cause the most recent index analysis to ** be laoded into internal hash tables where is can be used. */ |
︙ | ︙ | |||
329 330 331 332 333 334 335 | analysisInfo *pInfo = (analysisInfo*)pData; Index *pIndex; int i, c; unsigned int v; const char *z; assert( argc==2 ); | | | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | analysisInfo *pInfo = (analysisInfo*)pData; Index *pIndex; int i, c; unsigned int v; const char *z; assert( argc==2 ); if( argv==0 || argv[0]==0 || argv[1]==0 ){ return 0; } pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase); if( pIndex==0 ){ return 0; } z = argv[1]; |
︙ | ︙ |
Changes to SQLite.Interop/src/attach.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 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 ATTACH and DETACH commands. ** | | | 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 ATTACH and DETACH commands. ** ** $Id: attach.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** This routine is called by the parser to process an ATTACH statement: ** ** ATTACH DATABASE filename AS dbname |
︙ | ︙ |
Changes to SQLite.Interop/src/auth.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** This file contains code used to implement the sqlite3_set_authorizer() ** API. This facility is an optional feature of the library. Embedded ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** This file contains code used to implement the sqlite3_set_authorizer() ** API. This facility is an optional feature of the library. Embedded ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ** ** $Id: auth.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** All of the code in this file may be omitted by defining a single ** macro. */ |
︙ | ︙ |
Changes to SQLite.Interop/src/btree.c.
1 2 3 4 5 6 7 8 9 10 11 | /* ** 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. ** ************************************************************************* | | | 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.11 2005/10/05 19:38:29 rmsimpson Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to ** ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: ** "Sorting And Searching", pages 473-480. Addison-Wesley ** Publishing Company, Reading, Massachusetts. |
︙ | ︙ | |||
490 491 492 493 494 495 496 | 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 ){ | | | 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | 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); |
︙ | ︙ | |||
536 537 538 539 540 541 542 | } offset = PTRMAP_PTROFFSET(pBt->usableSize, key); if( pEType ) *pEType = pPtrmap[offset]; if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); sqlite3pager_unref(pPtrmap); | | | 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | } offset = PTRMAP_PTROFFSET(pBt->usableSize, key); if( pEType ) *pEType = pPtrmap[offset]; if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); sqlite3pager_unref(pPtrmap); if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT; return SQLITE_OK; } #endif /* SQLITE_OMIT_AUTOVACUUM */ /* ** Given a btree page and a cell index (0 means the first cell on |
︙ | ︙ | |||
1026 1027 1028 1029 1030 1031 1032 | pBt = pPage->pBt; assert( pBt!=0 ); assert( pParent==0 || pParent->pBt==pBt ); assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) ); assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] ); if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){ /* The parent page should never change unless the file is corrupt */ | | | | | | | | 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 | pBt = pPage->pBt; assert( pBt!=0 ); assert( pParent==0 || pParent->pBt==pBt ); assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) ); assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] ); if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){ /* The parent page should never change unless the file is corrupt */ return SQLITE_CORRUPT_BKPT; } if( pPage->isInit ) return SQLITE_OK; if( pPage->pParent==0 && pParent!=0 ){ pPage->pParent = pParent; sqlite3pager_ref(pParent->aData); } hdr = pPage->hdrOffset; data = pPage->aData; decodeFlags(pPage, data[hdr]); pPage->nOverflow = 0; pPage->idxShift = 0; usableSize = pBt->usableSize; pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf; top = get2byte(&data[hdr+5]); pPage->nCell = get2byte(&data[hdr+3]); if( pPage->nCell>MX_CELL(pBt) ){ /* To many cells for a single page. The page must be corrupt */ return SQLITE_CORRUPT_BKPT; } if( pPage->nCell==0 && pParent!=0 && pParent->pgno!=1 ){ /* All pages must have at least one cell, except for root pages */ return SQLITE_CORRUPT_BKPT; } /* Compute the total free space on the page */ pc = get2byte(&data[hdr+1]); nFree = data[hdr+7] + top - (cellOffset + 2*pPage->nCell); while( pc>0 ){ int next, size; if( pc>usableSize-4 ){ /* Free block is off the page */ return SQLITE_CORRUPT_BKPT; } next = get2byte(&data[pc]); size = get2byte(&data[pc+2]); if( next>0 && next<=pc+size+3 ){ /* Free blocks must be in accending order */ return SQLITE_CORRUPT_BKPT; } nFree += size; pc = next; } pPage->nFree = nFree; if( nFree>=usableSize ){ /* Free space cannot exceed total page size */ return SQLITE_CORRUPT_BKPT; } pPage->isInit = 1; pageIntegrity(pPage); return SQLITE_OK; } |
︙ | ︙ | |||
1142 1143 1144 1145 1146 1147 1148 | Btree *pBt, /* The database file */ Pgno pgno, /* Number of the page to get */ MemPage **ppPage, /* Write the page pointer here */ MemPage *pParent /* Parent of the page */ ){ int rc; if( pgno==0 ){ | | | 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 | Btree *pBt, /* The database file */ Pgno pgno, /* Number of the page to get */ MemPage **ppPage, /* Write the page pointer here */ MemPage *pParent /* Parent of the page */ ){ int rc; if( pgno==0 ){ return SQLITE_CORRUPT_BKPT; } rc = getPage(pBt, pgno, ppPage); if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){ rc = initPage(*ppPage, pParent); } return rc; } |
︙ | ︙ | |||
1710 1711 1712 1713 1714 1715 1716 | ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next ** overflow page in the list. */ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ if( eType==PTRMAP_OVERFLOW2 ){ /* The pointer is always the first 4 bytes of the page in this case. */ if( get4byte(pPage->aData)!=iFrom ){ | | | 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 | ** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next ** overflow page in the list. */ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ if( eType==PTRMAP_OVERFLOW2 ){ /* The pointer is always the first 4 bytes of the page in this case. */ if( get4byte(pPage->aData)!=iFrom ){ return SQLITE_CORRUPT_BKPT; } put4byte(pPage->aData, iTo); }else{ int isInitOrig = pPage->isInit; int i; int nCell; |
︙ | ︙ | |||
1743 1744 1745 1746 1747 1748 1749 | } } } if( i==nCell ){ if( eType!=PTRMAP_BTREE || get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){ | | | 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 | } } } if( i==nCell ){ if( eType!=PTRMAP_BTREE || get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){ return SQLITE_CORRUPT_BKPT; } put4byte(&pPage->aData[pPage->hdrOffset+8], iTo); } pPage->isInit = isInitOrig; } return SQLITE_OK; |
︙ | ︙ | |||
1856 1857 1858 1859 1860 1861 1862 | #ifndef NDEBUG int nRef = *sqlite3pager_stats(pPager); #endif assert( pBt->autoVacuum ); if( PTRMAP_ISPAGE(pgsz, sqlite3pager_pagecount(pPager)) ){ | | | | 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 | #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)); |
︙ | ︙ | |||
1894 1895 1896 1897 1898 1899 1900 | 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 ){ | | | 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 | if( PTRMAP_ISPAGE(pgsz, iDbPage) || iDbPage==PENDING_BYTE_PAGE(pBt) ){ continue; } rc = ptrmapGet(pBt, iDbPage, &eType, &iPtrPage); if( rc!=SQLITE_OK ) goto autovacuum_out; if( eType==PTRMAP_ROOTPAGE ){ rc = SQLITE_CORRUPT_BKPT; goto autovacuum_out; } /* If iDbPage is free, do not swap it. */ if( eType==PTRMAP_FREEPAGE ){ continue; } |
︙ | ︙ | |||
2410 2411 2412 2413 2414 2415 2416 | offset -= ovflSize; } sqlite3pager_unref(aPayload); } } if( amt>0 ){ | | | | 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 | offset -= ovflSize; } sqlite3pager_unref(aPayload); } } if( amt>0 ){ return SQLITE_CORRUPT_BKPT; } return SQLITE_OK; } /* ** Read part of the key associated with cursor pCur. Exactly ** "amt" bytes will be transfered into pBuf[]. The transfer ** begins at "offset". ** ** Return SQLITE_OK on success or an error code if anything goes ** wrong. An error is returned if "offset+amt" is larger than ** the available payload. */ int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ assert( pCur->isValid ); assert( pCur->pPage!=0 ); if( pCur->pPage->intKey ){ return SQLITE_CORRUPT_BKPT; } assert( pCur->pPage->intKey==0 ); assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell ); return getPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); } /* |
︙ | ︙ | |||
2477 2478 2479 2480 2481 2482 2483 | static const unsigned char *fetchPayload( BtCursor *pCur, /* Cursor pointing to entry to read from */ int *pAmt, /* Write the number of available bytes here */ int skipKey /* read beginning at data if this is true */ ){ unsigned char *aPayload; MemPage *pPage; | < < | 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 | static const unsigned char *fetchPayload( BtCursor *pCur, /* Cursor pointing to entry to read from */ int *pAmt, /* Write the number of available bytes here */ int skipKey /* read beginning at data if this is true */ ){ unsigned char *aPayload; MemPage *pPage; u32 nKey; int nLocal; assert( pCur!=0 && pCur->pPage!=0 ); assert( pCur->isValid ); pPage = pCur->pPage; pageIntegrity(pPage); assert( pCur->idx>=0 && pCur->idx<pPage->nCell ); getCellInfo(pCur); aPayload = pCur->info.pCell; aPayload += pCur->info.nHeader; if( pPage->intKey ){ |
︙ | ︙ | |||
2550 2551 2552 2553 2554 2555 2556 | pOldPage = pCur->pPage; pOldPage->idxShift = 0; releasePage(pOldPage); pCur->pPage = pNewPage; pCur->idx = 0; pCur->info.nSize = 0; if( pNewPage->nCell<1 ){ | | | 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 | pOldPage = pCur->pPage; pOldPage->idxShift = 0; releasePage(pOldPage); pCur->pPage = pNewPage; pCur->idx = 0; pCur->info.nSize = 0; if( pNewPage->nCell<1 ){ return SQLITE_CORRUPT_BKPT; } return SQLITE_OK; } /* ** Return true if the page is the virtual root of its table. ** |
︙ | ︙ | |||
2581 2582 2583 2584 2585 2586 2587 | ** ** pCur->idx is set to the cell index that contains the pointer ** to the page we are coming from. If we are coming from the ** right-most child page then pCur->idx is set to one more than ** the largest cell index. */ static void moveToParent(BtCursor *pCur){ | < < | 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 | ** ** pCur->idx is set to the cell index that contains the pointer ** to the page we are coming from. If we are coming from the ** right-most child page then pCur->idx is set to one more than ** the largest cell index. */ static void moveToParent(BtCursor *pCur){ MemPage *pParent; MemPage *pPage; int idxParent; assert( pCur->isValid ); pPage = pCur->pPage; assert( pPage!=0 ); assert( !isRootPage(pPage) ); pageIntegrity(pPage); pParent = pPage->pParent; assert( pParent!=0 ); pageIntegrity(pParent); idxParent = pPage->idxParent; sqlite3pager_ref(pParent->aData); releasePage(pPage); pCur->pPage = pParent; pCur->info.nSize = 0; assert( pParent->idxShift==0 ); pCur->idx = idxParent; } |
︙ | ︙ | |||
2761 2762 2763 2764 2765 2766 2767 | int lwr, upr; Pgno chldPg; MemPage *pPage = pCur->pPage; int c = -1; /* pRes return if table is empty must be -1 */ lwr = 0; upr = pPage->nCell-1; if( !pPage->intKey && pKey==0 ){ | | | 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 | int lwr, upr; Pgno chldPg; MemPage *pPage = pCur->pPage; int c = -1; /* pRes return if table is empty must be -1 */ lwr = 0; upr = pPage->nCell-1; if( !pPage->intKey && pKey==0 ){ return SQLITE_CORRUPT_BKPT; } pageIntegrity(pPage); while( lwr<=upr ){ void *pCellKey; i64 nCellKey; pCur->idx = (lwr+upr)/2; pCur->info.nSize = 0; |
︙ | ︙ | |||
3046 3047 3048 3049 3050 3051 3052 | *pPgno = iTrunk; memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4); *ppPage = pTrunk; pTrunk = 0; TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1)); }else if( k>pBt->usableSize/4 - 8 ){ /* Value of k is out of range. Database corruption */ | | | 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 | *pPgno = iTrunk; memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4); *ppPage = pTrunk; pTrunk = 0; TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1)); }else if( k>pBt->usableSize/4 - 8 ){ /* Value of k is out of range. Database corruption */ return SQLITE_CORRUPT_BKPT; #ifndef SQLITE_OMIT_AUTOVACUUM }else if( searchList && nearby==iTrunk ){ /* The list is being searched and this trunk page is the page ** to allocate, regardless of whether it has leaves. */ assert( *pPgno==iTrunk ); *ppPage = pTrunk; |
︙ | ︙ | |||
3121 3122 3123 3124 3125 3126 3127 | } iPage = get4byte(&aData[8+closest*4]); if( !searchList || iPage==nearby ){ *pPgno = iPage; if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){ /* Free page off the end of the file */ | | | 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 | } iPage = get4byte(&aData[8+closest*4]); if( !searchList || iPage==nearby ){ *pPgno = iPage; if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){ /* Free page off the end of the file */ return SQLITE_CORRUPT_BKPT; } TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d" ": %d more free pages\n", *pPgno, closest+1, k, pTrunk->pgno, n-1)); if( closest<k-1 ){ memcpy(&aData[8+closest*4], &aData[4+k*4], 4); } |
︙ | ︙ | |||
3262 3263 3264 3265 3266 3267 3268 | if( info.iOverflow==0 ){ return SQLITE_OK; /* No overflow pages. Return without doing anything */ } ovflPgno = get4byte(&pCell[info.iOverflow]); while( ovflPgno!=0 ){ MemPage *pOvfl; if( ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){ | | | 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 | if( info.iOverflow==0 ){ return SQLITE_OK; /* No overflow pages. Return without doing anything */ } ovflPgno = get4byte(&pCell[info.iOverflow]); while( ovflPgno!=0 ){ MemPage *pOvfl; if( ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){ return SQLITE_CORRUPT_BKPT; } rc = getPage(pBt, ovflPgno, &pOvfl); if( rc ) return rc; ovflPgno = get4byte(pOvfl->aData); rc = freePage(pOvfl); sqlite3pager_unref(pOvfl->aData); if( rc ) return rc; |
︙ | ︙ | |||
4668 4669 4670 4671 4672 4673 4674 | int notUsed; unsigned char *tempCell = 0; assert( !pPage->leafData ); getTempCursor(pCur, &leafCur); rc = sqlite3BtreeNext(&leafCur, ¬Used); if( rc!=SQLITE_OK ){ if( rc!=SQLITE_NOMEM ){ | | | 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 | int notUsed; unsigned char *tempCell = 0; assert( !pPage->leafData ); getTempCursor(pCur, &leafCur); rc = sqlite3BtreeNext(&leafCur, ¬Used); if( rc!=SQLITE_OK ){ if( rc!=SQLITE_NOMEM ){ rc = SQLITE_CORRUPT_BKPT; } } if( rc==SQLITE_OK ){ rc = sqlite3pager_write(leafCur.pPage->aData); } if( rc==SQLITE_OK ){ TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n", |
︙ | ︙ | |||
4854 4855 4856 4857 4858 4859 4860 | ){ MemPage *pPage = 0; int rc; unsigned char *pCell; int i; if( pgno>sqlite3pager_pagecount(pBt->pPager) ){ | | | 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 | ){ MemPage *pPage = 0; int rc; unsigned char *pCell; int i; if( pgno>sqlite3pager_pagecount(pBt->pPager) ){ return SQLITE_CORRUPT_BKPT; } rc = getAndInitPage(pBt, pgno, &pPage, pParent); if( rc ) goto cleardatabasepage_out; rc = sqlite3pager_write(pPage->aData); if( rc ) goto cleardatabasepage_out; for(i=0; i<pPage->nCell; i++){ |
︙ | ︙ | |||
5476 5477 5478 5479 5480 5481 5482 | MemPage *pPage; int i, rc, depth, d2, pgno, cnt; int hdr, cellStart; int nCell; u8 *data; BtCursor cur; Btree *pBt; | | < | 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 | MemPage *pPage; int i, rc, depth, d2, pgno, cnt; int hdr, cellStart; int nCell; u8 *data; BtCursor cur; Btree *pBt; int usableSize; char zContext[100]; char *hit; sprintf(zContext, "Page %d: ", iPage); /* Check that the page exists */ cur.pBt = pBt = pCheck->pBt; usableSize = pBt->usableSize; if( iPage==0 ) return 0; if( checkRef(pCheck, iPage, zParentContext) ) return 0; if( (rc = getPage(pBt, (Pgno)iPage, &pPage))!=0 ){ checkAppendMsg(pCheck, zContext, "unable to get the page. error code=%d", rc); return 0; } if( (rc = initPage(pPage, pParent))!=0 ){ checkAppendMsg(pCheck, zContext, "initPage() returns error code %d", rc); releasePage(pPage); return 0; } /* Check out all the cells. |
︙ | ︙ | |||
5740 5741 5742 5743 5744 5745 5746 | ** must be active for both files. ** ** The size of file pBtFrom may be reduced by this operation. ** If anything goes wrong, the transaction on pBtFrom is rolled back. */ int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){ int rc = SQLITE_OK; | | > > > | 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 | ** must be active for both files. ** ** The size of file pBtFrom may be reduced by this operation. ** If anything goes wrong, the transaction on pBtFrom is rolled back. */ int sqlite3BtreeCopyFile(Btree *pBtTo, Btree *pBtFrom){ int rc = SQLITE_OK; Pgno i, nPage, nToPage, iSkip; if( pBtTo->inTrans!=TRANS_WRITE || pBtFrom->inTrans!=TRANS_WRITE ){ return SQLITE_ERROR; } if( pBtTo->pCursor ) return SQLITE_BUSY; nToPage = sqlite3pager_pagecount(pBtTo->pPager); nPage = sqlite3pager_pagecount(pBtFrom->pPager); iSkip = PENDING_BYTE_PAGE(pBtTo); for(i=1; rc==SQLITE_OK && i<=nPage; i++){ void *pPage; if( i==iSkip ) continue; rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage); if( rc ) break; rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage); if( rc ) break; sqlite3pager_unref(pPage); } for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){ void *pPage; if( i==iSkip ) continue; rc = sqlite3pager_get(pBtTo->pPager, i, &pPage); if( rc ) break; rc = sqlite3pager_write(pPage); sqlite3pager_unref(pPage); sqlite3pager_dont_write(pBtTo->pPager, i); } if( !rc && nPage<nToPage ){ |
︙ | ︙ |
Changes to SQLite.Interop/src/btree.h.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite B-Tree file ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite B-Tree file ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** ** @(#) $Id: btree.h,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ /* TODO: This definition is just included so other modules compile. It ** needs to be revisited. */ |
︙ | ︙ |
Changes to SQLite.Interop/src/build.c.
︙ | ︙ | |||
18 19 20 21 22 23 24 | ** CREATE INDEX ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Initialize the pParse structure as needed. |
︙ | ︙ | |||
72 73 74 75 76 77 78 | ** set for each database that is used. Generate code to start a ** transaction on each used database and to verify the schema cookie ** on each used database. */ if( pParse->cookieGoto>0 ){ u32 mask; int iDb; | | > > | | 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 | ** set for each database that is used. Generate code to start a ** transaction on each used database and to verify the schema cookie ** on each used database. */ if( pParse->cookieGoto>0 ){ u32 mask; int iDb; sqlite3VdbeJumpHere(v, pParse->cookieGoto-1); for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ if( (mask & pParse->cookieMask)==0 ) continue; sqlite3VdbeAddOp(v, OP_Transaction, iDb, (mask & pParse->writeMask)!=0); sqlite3VdbeAddOp(v, OP_VerifyCookie, iDb, pParse->cookieValue[iDb]); } sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->cookieGoto); } #ifndef SQLITE_OMIT_TRACE /* Add a No-op that contains the complete text of the compiled SQL ** statement as its P3 argument. This does not change the functionality ** of the program. ** ** This is used to implement sqlite3_trace(). */ sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail-pParse->zSql); #endif /* SQLITE_OMIT_TRACE */ } /* Get the VDBE program ready for execution */ if( v && pParse->nErr==0 ){ FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0; sqlite3VdbeTrace(v, trace); sqlite3VdbeMakeReady(v, pParse->nVar, pParse->nMem+3, pParse->nTab+3, pParse->explain); pParse->rc = SQLITE_DONE; pParse->colNamesSet = 0; }else if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; } pParse->nTab = 0; pParse->nMem = 0; |
︙ | ︙ | |||
126 127 128 129 130 131 132 | ** Not everything is nestable. This facility is designed to permit ** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER. Use ** care if you decide to try to use this routine for some other purposes. */ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ va_list ap; char *zSql; | < | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | ** Not everything is nestable. This facility is designed to permit ** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER. Use ** care if you decide to try to use this routine for some other purposes. */ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ va_list ap; char *zSql; # define SAVE_SZ (sizeof(Parse) - offsetof(Parse,nVar)) char saveBuf[SAVE_SZ]; if( pParse->nErr ) return; assert( pParse->nested<10 ); /* Nesting should only be of limited depth */ va_start(ap, zFormat); zSql = sqlite3VMPrintf(zFormat, ap); va_end(ap); if( zSql==0 ){ return; /* A malloc must have failed */ } pParse->nested++; memcpy(saveBuf, &pParse->nVar, SAVE_SZ); memset(&pParse->nVar, 0, SAVE_SZ); sqlite3RunParser(pParse, zSql, 0); sqliteFree(zSql); memcpy(&pParse->nVar, saveBuf, SAVE_SZ); pParse->nested--; } /* ** Locate the in-memory structure that describes a particular database |
︙ | ︙ | |||
630 631 632 633 634 635 636 | Token *pStart, /* The "CREATE" token */ Token *pName1, /* First part of the name of the table or view */ Token *pName2, /* Second part of the name of the table or view */ int isTemp, /* True if this is a TEMP table */ int isView /* True if this is a VIEW */ ){ Table *pTable; | < | 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | Token *pStart, /* The "CREATE" token */ Token *pName1, /* First part of the name of the table or view */ Token *pName2, /* Second part of the name of the table or view */ int isTemp, /* True if this is a TEMP table */ int isView /* True if this is a VIEW */ ){ Table *pTable; char *zName = 0; /* The name of the new table */ sqlite3 *db = pParse->db; Vdbe *v; int iDb; /* Database number to create the table in */ Token *pName; /* Unqualified name of the table to create */ /* The table or view name to create is passed to this routine via tokens |
︙ | ︙ | |||
709 710 711 712 713 714 715 | goto begin_table_error; } pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName); if( pTable ){ sqlite3ErrorMsg(pParse, "table %T already exists", pName); goto begin_table_error; } | < | | 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | goto begin_table_error; } pTable = sqlite3FindTable(db, zName, db->aDb[iDb].zName); if( pTable ){ sqlite3ErrorMsg(pParse, "table %T already exists", pName); goto begin_table_error; } if( sqlite3FindIndex(db, zName, 0)!=0 && (iDb==0 || !db->init.busy) ){ sqlite3ErrorMsg(pParse, "there is already an index named %s", zName); goto begin_table_error; } pTable = sqliteMalloc( sizeof(Table) ); if( pTable==0 ){ pParse->rc = SQLITE_NOMEM; pParse->nErr++; |
︙ | ︙ | |||
937 938 939 940 941 942 943 | int i; Column *pCol; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; | | | 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | int i; Column *pCol; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; sqliteFree(pCol->zType); pCol->zType = sqlite3NameFromToken(pType); pCol->affinity = sqlite3AffinityType(pType); } /* ** The expression is the default value for the most recently added column ** of the table currently under construction. |
︙ | ︙ | |||
1012 1013 1014 1015 1016 1017 1018 | }else{ for(i=0; i<pList->nExpr; i++){ for(iCol=0; iCol<pTab->nCol; iCol++){ if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){ break; } } | | > > | 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 | }else{ for(i=0; i<pList->nExpr; i++){ for(iCol=0; iCol<pTab->nCol; iCol++){ if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){ break; } } if( iCol<pTab->nCol ){ pTab->aCol[iCol].isPrimKey = 1; } } if( pList->nExpr>1 ) iCol = -1; } if( iCol>=0 && iCol<pTab->nCol ){ zType = pTab->aCol[iCol].zType; } if( zType && sqlite3StrICmp(zType, "INTEGER")==0 ){ |
︙ | ︙ | |||
1997 1998 1999 2000 2001 2002 2003 | sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort, "indexed columns are not unique", P3_STATIC); assert( addr2==sqlite3VdbeCurrentAddr(v) ); } sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0); sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1); | | | 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 | sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort, "indexed columns are not unique", P3_STATIC); assert( addr2==sqlite3VdbeCurrentAddr(v) ); } sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0); sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1); sqlite3VdbeJumpHere(v, addr1); sqlite3VdbeAddOp(v, OP_Close, iTab, 0); sqlite3VdbeAddOp(v, OP_Close, iIdx, 0); } /* ** Create a new index for an SQL table. pName1.pName2 is the name of the index ** and pTblList is the name of the table that is to be indexed. Both will |
︙ | ︙ | |||
2110 2111 2112 2113 2114 2115 2116 | zName = sqlite3NameFromToken(pName); if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index; if( zName==0 ) goto exit_create_index; if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto exit_create_index; } if( !db->init.busy ){ | < < | | | 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 | zName = sqlite3NameFromToken(pName); if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index; if( zName==0 ) goto exit_create_index; if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto exit_create_index; } if( !db->init.busy ){ if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index; if( sqlite3FindIndex(db, zName, db->aDb[iDb].zName)!=0 ){ sqlite3ErrorMsg(pParse, "index %s already exists", zName); goto exit_create_index; } if( sqlite3FindTable(db, zName, 0)!=0 ){ sqlite3ErrorMsg(pParse, "there is already a table named %s", zName); goto exit_create_index; } } }else{ char zBuf[30]; int n; |
︙ | ︙ | |||
2167 2168 2169 2170 2171 2172 2173 | /* ** Allocate the index structure. */ pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 + sizeof(int) + (sizeof(int)*2 + sizeof(CollSeq*))*pList->nExpr ); if( sqlite3_malloc_failed ) goto exit_create_index; pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr]; | | | 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 | /* ** Allocate the index structure. */ pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 + sizeof(int) + (sizeof(int)*2 + sizeof(CollSeq*))*pList->nExpr ); if( sqlite3_malloc_failed ) goto exit_create_index; pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr]; pIndex->aiRowEst = (unsigned*)&pIndex->aiColumn[pList->nExpr]; pIndex->zName = (char*)&pIndex->aiRowEst[pList->nExpr+1]; strcpy(pIndex->zName, zName); pIndex->pTable = pTab; pIndex->nColumn = pList->nExpr; pIndex->onError = onError; pIndex->autoIndex = pName==0; pIndex->iDb = iDb; |
︙ | ︙ | |||
2390 2391 2392 2393 2394 2395 2396 | ** aiRowEst[N]>=1 ** ** Apart from that, we have little to go on besides intuition as to ** how aiRowEst[] should be initialized. The numbers generated here ** are based on typical values found in actual indices. */ void sqlite3DefaultRowEst(Index *pIdx){ | | | 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 | ** aiRowEst[N]>=1 ** ** Apart from that, we have little to go on besides intuition as to ** how aiRowEst[] should be initialized. The numbers generated here ** are based on typical values found in actual indices. */ void sqlite3DefaultRowEst(Index *pIdx){ unsigned *a = pIdx->aiRowEst; int i; assert( a!=0 ); a[0] = 1000000; for(i=pIdx->nColumn; i>=1; i--){ a[i] = 10; } if( pIdx->onError!=OE_None ){ |
︙ | ︙ | |||
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 | destroyRootPage(pParse, pIndex->tnum, iDb); sqlite3VdbeOp3(v, OP_DropIndex, iDb, 0, pIndex->zName, 0); } exit_drop_index: sqlite3SrcListDelete(pName); } /* ** Append a new element to the given IdList. Create a new IdList if ** need be. ** ** A new IdList is returned, or NULL if malloc() fails. */ IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){ if( pList==0 ){ pList = sqliteMalloc( sizeof(IdList) ); if( pList==0 ) return 0; pList->nAlloc = 0; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | | | | | < < < | < | 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 | destroyRootPage(pParse, pIndex->tnum, iDb); sqlite3VdbeOp3(v, OP_DropIndex, iDb, 0, pIndex->zName, 0); } exit_drop_index: sqlite3SrcListDelete(pName); } /* ** ppArray points into a structure where there is an array pointer ** followed by two integers. The first integer is the ** number of elements in the structure array. The second integer ** is the number of allocated slots in the array. ** ** In other words, the structure looks something like this: ** ** struct Example1 { ** struct subElem *aEntry; ** int nEntry; ** int nAlloc; ** } ** ** The pnEntry parameter points to the equivalent of Example1.nEntry. ** ** This routine allocates a new slot in the array, zeros it out, ** and returns its index. If malloc fails a negative number is returned. ** ** szEntry is the sizeof of a single array entry. initSize is the ** number of array entries allocated on the initial allocation. */ int sqlite3ArrayAllocate(void **ppArray, int szEntry, int initSize){ char *p; int *an = (int*)&ppArray[1]; if( an[0]>=an[1] ){ void *pNew; int newSize; newSize = an[1]*2 + initSize; pNew = sqliteRealloc(*ppArray, newSize*szEntry); if( pNew==0 ){ return -1; } an[1] = newSize; *ppArray = pNew; } p = *ppArray; memset(&p[an[0]*szEntry], 0, szEntry); return an[0]++; } /* ** Append a new element to the given IdList. Create a new IdList if ** need be. ** ** A new IdList is returned, or NULL if malloc() fails. */ IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){ int i; if( pList==0 ){ pList = sqliteMalloc( sizeof(IdList) ); if( pList==0 ) return 0; pList->nAlloc = 0; } i = sqlite3ArrayAllocate((void**)&pList->a, sizeof(pList->a[0]), 5); if( i<0 ){ sqlite3IdListDelete(pList); return 0; } pList->a[i].zName = sqlite3NameFromToken(pToken); return pList; } /* ** Delete an IdList. */ void sqlite3IdListDelete(IdList *pList){ |
︙ | ︙ |
Changes to SQLite.Interop/src/callback.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** ** $Id: callback.c,v 1.5 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** Invoke the 'collation needed' callback to request a collation sequence ** in the database text encoding of name zName, length nName. |
︙ | ︙ |
Changes to SQLite.Interop/src/complete.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** An tokenizer for SQL ** ** This file contains C code that implements the sqlite3_complete() API. ** This code used to be part of the tokenizer.c source file. But by ** separating it out, the code will be automatically omitted from ** static links that do not use it. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** An tokenizer for SQL ** ** This file contains C code that implements the sqlite3_complete() API. ** This code used to be part of the tokenizer.c source file. But by ** separating it out, the code will be automatically omitted from ** static links that do not use it. ** ** $Id: complete.c,v 1.3 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #ifndef SQLITE_OMIT_COMPLETE /* ** This is defined in tokenize.c. We just have to import the definition. */ |
︙ | ︙ |
Changes to SQLite.Interop/src/date.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This file contains the C functions that implement date and time ** functions for SQLite. ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This file contains the C functions that implement date and time ** functions for SQLite. ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** ** $Id: date.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ ** ** NOTES: ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon ** in Greenwich on November 24, 4714 B.C. according to the Gregorian ** calendar system. |
︙ | ︙ |
Changes to SQLite.Interop/src/delete.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** Look up every table that is named in pSrc. If any table is not found, ** add an error message to pParse->zErrMsg and return NULL. If all tables ** are found, return a pointer to the last table. |
︙ | ︙ | |||
174 175 176 177 178 179 180 | v = sqlite3GetVdbe(pParse); if( v==0 ){ goto delete_from_cleanup; } if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb); | | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | v = sqlite3GetVdbe(pParse); if( v==0 ){ goto delete_from_cleanup; } if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); sqlite3BeginWriteOperation(pParse, triggers_exist, pTab->iDb); /* If we are trying to delete from a view, realize that view into ** a ephemeral table. */ if( isView ){ Select *pView = sqlite3SelectDup(pTab->pSelect); sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0); sqlite3SelectDelete(pView); } /* Initialize the counter of the number of rows deleted, if ** we are counting rows. */ if( db->flags & SQLITE_CountRows ){ |
︙ | ︙ | |||
376 377 378 379 380 381 382 | int iCur, /* Cursor number for the table */ int count /* Increment the row change counter */ ){ int addr; addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0); sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0); sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0)); | | | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | int iCur, /* Cursor number for the table */ int count /* Increment the row change counter */ ){ int addr; addr = sqlite3VdbeAddOp(v, OP_NotExists, iCur, 0); sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, 0); sqlite3VdbeAddOp(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0)); sqlite3VdbeJumpHere(v, addr); } /* ** This routine generates VDBE code that causes the deletion of all ** index entries associated with a single row of a single table. ** ** The VDBE must be in a particular state when this routine is called. |
︙ | ︙ |
Changes to SQLite.Interop/src/expr.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | 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.16 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** Return the 'affinity' of the expression pExpr if any. ** |
︙ | ︙ | |||
351 352 353 354 355 356 357 | break; } } if( i>=pParse->nVarExpr ){ pExpr->iTable = ++pParse->nVar; if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){ pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10; | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | break; } } if( i>=pParse->nVarExpr ){ pExpr->iTable = ++pParse->nVar; if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){ pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10; sqlite3ReallocOrFree((void**)&pParse->apVarExpr, pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) ); } if( !sqlite3_malloc_failed ){ assert( pParse->apVarExpr!=0 ); pParse->apVarExpr[pParse->nVarExpr++] = pExpr; } } |
︙ | ︙ | |||
542 543 544 545 546 547 548 | pNew->pOrderBy = sqlite3ExprListDup(p->pOrderBy); pNew->op = p->op; pNew->pPrior = sqlite3SelectDup(p->pPrior); pNew->pLimit = sqlite3ExprDup(p->pLimit); pNew->pOffset = sqlite3ExprDup(p->pOffset); pNew->iLimit = -1; pNew->iOffset = -1; | < > > > > > > | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | pNew->pOrderBy = sqlite3ExprListDup(p->pOrderBy); pNew->op = p->op; pNew->pPrior = sqlite3SelectDup(p->pPrior); pNew->pLimit = sqlite3ExprDup(p->pLimit); pNew->pOffset = sqlite3ExprDup(p->pOffset); pNew->iLimit = -1; pNew->iOffset = -1; pNew->isResolved = p->isResolved; pNew->isAgg = p->isAgg; pNew->usesVirt = 0; pNew->disallowOrderBy = 0; pNew->pRightmost = 0; pNew->addrOpenVirt[0] = -1; pNew->addrOpenVirt[1] = -1; pNew->addrOpenVirt[2] = -1; return pNew; } #else Select *sqlite3SelectDup(Select *p){ assert( p==0 ); return 0; } |
︙ | ︙ | |||
688 689 690 691 692 693 694 695 696 697 698 699 700 701 | case TK_FUNCTION: if( *((int*)pArg)==2 ) return 0; /* Fall through */ case TK_ID: case TK_COLUMN: case TK_DOT: case TK_AGG_FUNCTION: #ifndef SQLITE_OMIT_SUBQUERY case TK_SELECT: case TK_EXISTS: #endif *((int*)pArg) = 0; return 2; case TK_IN: | > | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | case TK_FUNCTION: if( *((int*)pArg)==2 ) return 0; /* Fall through */ case TK_ID: case TK_COLUMN: case TK_DOT: case TK_AGG_FUNCTION: case TK_AGG_COLUMN: #ifndef SQLITE_OMIT_SUBQUERY case TK_SELECT: case TK_EXISTS: #endif *((int*)pArg) = 0; return 2; case TK_IN: |
︙ | ︙ | |||
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 | ** If the expression contains aggregate functions then set the EP_Agg ** property on the expression. */ int sqlite3ExprResolveNames( NameContext *pNC, /* Namespace to resolve expressions in. */ Expr *pExpr /* The expression to be analyzed. */ ){ if( pExpr==0 ) return 0; walkExprTree(pExpr, nameResolverStep, pNC); if( pNC->nErr>0 ){ ExprSetProperty(pExpr, EP_Error); } return ExprHasProperty(pExpr, EP_Error); } /* ** A pointer instance of this structure is used to pass information ** through walkExprTree into codeSubqueryStep(). | > > > > > > > > | 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 | ** If the expression contains aggregate functions then set the EP_Agg ** property on the expression. */ int sqlite3ExprResolveNames( NameContext *pNC, /* Namespace to resolve expressions in. */ Expr *pExpr /* The expression to be analyzed. */ ){ int savedHasAgg; if( pExpr==0 ) return 0; savedHasAgg = pNC->hasAgg; pNC->hasAgg = 0; walkExprTree(pExpr, nameResolverStep, pNC); if( pNC->nErr>0 ){ ExprSetProperty(pExpr, EP_Error); } if( pNC->hasAgg ){ ExprSetProperty(pExpr, EP_Agg); }else if( savedHasAgg ){ pNC->hasAgg = 1; } return ExprHasProperty(pExpr, EP_Error); } /* ** A pointer instance of this structure is used to pass information ** through walkExprTree into codeSubqueryStep(). |
︙ | ︙ | |||
1275 1276 1277 1278 1279 1280 1281 | ** If all of the above are false, then we can run this code just once ** save the results, and reuse the same result on subsequent invocations. */ if( !ExprHasAnyProperty(pExpr, EP_VarSelect) && !pParse->trigStack ){ int mem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0); testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0); | | < | < < < < | 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | ** If all of the above are false, then we can run this code just once ** save the results, and reuse the same result on subsequent invocations. */ if( !ExprHasAnyProperty(pExpr, EP_VarSelect) && !pParse->trigStack ){ int mem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0); testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0); assert( testAddr>0 || sqlite3_malloc_failed ); sqlite3VdbeAddOp(v, OP_MemInt, 1, mem); } switch( pExpr->op ){ case TK_IN: { char affinity; KeyInfo keyInfo; int addr; /* Address of OP_OpenVirtual instruction */ |
︙ | ︙ | |||
1355 1356 1357 1358 1359 1360 1361 | ** disable the test that was generated above that makes sure ** this code only executes once. Because for a non-constant ** expression we need to rerun this code each time. */ if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){ VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1); int i; | | | 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 | ** disable the test that was generated above that makes sure ** this code only executes once. Because for a non-constant ** expression we need to rerun this code each time. */ if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){ VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1); int i; for(i=0; i<3; i++){ aOp[i].opcode = OP_Noop; } testAddr = 0; } /* Evaluate the expression and insert it into the temp table */ sqlite3ExprCode(pParse, pE2); |
︙ | ︙ | |||
1396 1397 1398 1399 1400 1401 1402 | sqlite3Expr(TK_INTEGER, 0, 0, &one), 0); } sqlite3Select(pParse, pSel, sop, pExpr->iColumn, 0, 0, 0, 0); break; } } | < < < | | 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 | sqlite3Expr(TK_INTEGER, 0, 0, &one), 0); } sqlite3Select(pParse, pSel, sop, pExpr->iColumn, 0, 0, 0, 0); break; } } if( testAddr ){ sqlite3VdbeJumpHere(v, testAddr); } return; } #endif /* SQLITE_OMIT_SUBQUERY */ /* ** Generate an instruction that will put the integer describe by |
︙ | ︙ | |||
1441 1442 1443 1444 1445 1446 1447 | if( v==0 ) return; if( pExpr==0 ){ sqlite3VdbeAddOp(v, OP_Null, 0, 0); return; } op = pExpr->op; switch( op ){ | | > | > | > > > > > > > > > | | 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 | if( v==0 ) return; if( pExpr==0 ){ sqlite3VdbeAddOp(v, OP_Null, 0, 0); return; } op = pExpr->op; switch( op ){ case TK_AGG_COLUMN: { AggInfo *pAggInfo = pExpr->pAggInfo; struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg]; if( !pAggInfo->directMode ){ sqlite3VdbeAddOp(v, OP_MemLoad, pCol->iMem, 0); break; }else if( pAggInfo->useSortingIdx ){ sqlite3VdbeAddOp(v, OP_Column, pAggInfo->sortingIdx, pCol->iSorterColumn); break; } /* Otherwise, fall thru into the TK_COLUMN case */ } case TK_COLUMN: { if( pExpr->iColumn>=0 ){ sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn); sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn); }else{ sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0); } break; } |
︙ | ︙ | |||
1593 1594 1595 1596 1597 1598 1599 | sqlite3ExprCode(pParse, pExpr->pLeft); dest = sqlite3VdbeCurrentAddr(v) + 2; sqlite3VdbeAddOp(v, op, 1, dest); sqlite3VdbeAddOp(v, OP_AddImm, -1, 0); break; } case TK_AGG_FUNCTION: { | > | | | | | 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 | sqlite3ExprCode(pParse, pExpr->pLeft); dest = sqlite3VdbeCurrentAddr(v) + 2; sqlite3VdbeAddOp(v, op, 1, dest); sqlite3VdbeAddOp(v, OP_AddImm, -1, 0); break; } case TK_AGG_FUNCTION: { AggInfo *pInfo = pExpr->pAggInfo; sqlite3VdbeAddOp(v, OP_MemLoad, pInfo->aFunc[pExpr->iAgg].iMem, 0); break; } case TK_CONST_FUNC: case TK_FUNCTION: { ExprList *pList = pExpr->pList; int nExpr = pList ? pList->nExpr : 0; FuncDef *pDef; int nId; const char *zId; int constMask = 0; int i; u8 enc = pParse->db->enc; CollSeq *pColl = 0; zId = pExpr->token.z; nId = pExpr->token.n; pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0); assert( pDef!=0 ); nExpr = sqlite3ExprCodeExprList(pParse, pList); for(i=0; i<nExpr && i<32; i++){ if( sqlite3ExprIsConstant(pList->a[i].pExpr) ){ constMask |= (1<<i); } if( pDef->needCollSeq && !pColl ){ pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); } } if( pDef->needCollSeq ){ if( !pColl ) pColl = pParse->db->pDfltColl; sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ); } sqlite3VdbeOp3(v, OP_Function, constMask, nExpr, (char*)pDef, P3_FUNCDEF); break; } #ifndef SQLITE_OMIT_SUBQUERY case TK_EXISTS: case TK_SELECT: { sqlite3CodeSubselect(pParse, pExpr); sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iColumn, 0); |
︙ | ︙ | |||
1688 1689 1690 1691 1692 1693 1694 | case TK_AS: { sqlite3ExprCode(pParse, pExpr->pLeft); break; } case TK_CASE: { int expr_end_label; int jumpInst; | < | 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 | case TK_AS: { sqlite3ExprCode(pParse, pExpr->pLeft); break; } case TK_CASE: { int expr_end_label; int jumpInst; int nExpr; int i; ExprList *pEList; struct ExprList_item *aListelem; assert(pExpr->pList); assert((pExpr->pList->nExpr % 2) == 0); |
︙ | ︙ | |||
1716 1717 1718 1719 1720 1721 1722 | OP_Ne, 0, 1); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); }else{ jumpInst = sqlite3VdbeAddOp(v, OP_IfNot, 1, 0); } sqlite3ExprCode(pParse, aListelem[i+1].pExpr); sqlite3VdbeAddOp(v, OP_Goto, 0, expr_end_label); | | < | 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 | OP_Ne, 0, 1); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); }else{ jumpInst = sqlite3VdbeAddOp(v, OP_IfNot, 1, 0); } sqlite3ExprCode(pParse, aListelem[i+1].pExpr); sqlite3VdbeAddOp(v, OP_Goto, 0, expr_end_label); sqlite3VdbeJumpHere(v, jumpInst); } if( pExpr->pLeft ){ sqlite3VdbeAddOp(v, OP_Pop, 1, 0); } if( pExpr->pRight ){ sqlite3ExprCode(pParse, pExpr->pRight); }else{ |
︙ | ︙ | |||
1884 1885 1886 1887 1888 1889 1890 | addr = codeCompare(pParse, pLeft, pRight, OP_Lt, 0, !jumpIfNull); pRight = pExpr->pList->a[1].pExpr; sqlite3ExprCode(pParse, pRight); codeCompare(pParse, pLeft, pRight, OP_Le, dest, jumpIfNull); sqlite3VdbeAddOp(v, OP_Integer, 0, 0); | | | 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 | addr = codeCompare(pParse, pLeft, pRight, OP_Lt, 0, !jumpIfNull); pRight = pExpr->pList->a[1].pExpr; sqlite3ExprCode(pParse, pRight); codeCompare(pParse, pLeft, pRight, OP_Le, dest, jumpIfNull); sqlite3VdbeAddOp(v, OP_Integer, 0, 0); sqlite3VdbeJumpHere(v, addr); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); break; } default: { sqlite3ExprCode(pParse, pExpr); sqlite3VdbeAddOp(v, OP_If, jumpIfNull, dest); break; |
︙ | ︙ | |||
2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 | int i; if( pA==0 ){ return pB==0; }else if( pB==0 ){ return 0; } if( pA->op!=pB->op ) return 0; if( !sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 0; if( !sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 0; if( pA->pList ){ if( pB->pList==0 ) return 0; if( pA->pList->nExpr!=pB->pList->nExpr ) return 0; for(i=0; i<pA->pList->nExpr; i++){ if( !sqlite3ExprCompare(pA->pList->a[i].pExpr, pB->pList->a[i].pExpr) ){ | > | 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 | int i; if( pA==0 ){ return pB==0; }else if( pB==0 ){ return 0; } if( pA->op!=pB->op ) return 0; if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 0; if( !sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 0; if( !sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 0; if( pA->pList ){ if( pB->pList==0 ) return 0; if( pA->pList->nExpr!=pB->pList->nExpr ) return 0; for(i=0; i<pA->pList->nExpr; i++){ if( !sqlite3ExprCompare(pA->pList->a[i].pExpr, pB->pList->a[i].pExpr) ){ |
︙ | ︙ | |||
2040 2041 2042 2043 2044 2045 2046 2047 | if( pB->token.z==0 ) return 0; if( pB->token.n!=pA->token.n ) return 0; if( sqlite3StrNICmp(pA->token.z, pB->token.z, pB->token.n)!=0 ) return 0; } return 1; } /* | > | | < | < | | | | | < > | | > > > > > > > > > > | | < > > > > > > | > | > > > > > > | | < | | | | | | | < > > | > | > > > > > > > > > > > | > > > > > > > > > > > | > | | < > > > > < > > > > | < | | > > | | | | > | | | > > > > | > > > > > > > > > > | 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 | if( pB->token.z==0 ) return 0; if( pB->token.n!=pA->token.n ) return 0; if( sqlite3StrNICmp(pA->token.z, pB->token.z, pB->token.n)!=0 ) return 0; } return 1; } /* ** Add a new element to the pAggInfo->aCol[] array. Return the index of ** the new element. Return a negative number if malloc fails. */ static int addAggInfoColumn(AggInfo *pInfo){ int i; i = sqlite3ArrayAllocate((void**)&pInfo->aCol, sizeof(pInfo->aCol[0]), 3); if( i<0 ){ return -1; } return i; } /* ** Add a new element to the pAggInfo->aFunc[] array. Return the index of ** the new element. Return a negative number if malloc fails. */ static int addAggInfoFunc(AggInfo *pInfo){ int i; i = sqlite3ArrayAllocate((void**)&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2); if( i<0 ){ return -1; } return i; } /* ** This is an xFunc for walkExprTree() used to implement ** sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates ** for additional information. ** ** This routine analyzes the aggregate function at pExpr. */ static int analyzeAggregate(void *pArg, Expr *pExpr){ int i; NameContext *pNC = (NameContext *)pArg; Parse *pParse = pNC->pParse; SrcList *pSrcList = pNC->pSrcList; AggInfo *pAggInfo = pNC->pAggInfo; switch( pExpr->op ){ case TK_COLUMN: { /* Check to see if the column is in one of the tables in the FROM ** clause of the aggregate query */ if( pSrcList ){ struct SrcList_item *pItem = pSrcList->a; for(i=0; i<pSrcList->nSrc; i++, pItem++){ struct AggInfo_col *pCol; if( pExpr->iTable==pItem->iCursor ){ /* If we reach this point, it means that pExpr refers to a table ** that is in the FROM clause of the aggregate query. ** ** Make an entry for the column in pAggInfo->aCol[] if there ** is not an entry there already. */ pCol = pAggInfo->aCol; for(i=0; i<pAggInfo->nColumn; i++, pCol++){ if( pCol->iTable==pExpr->iTable && pCol->iColumn==pExpr->iColumn ){ break; } } if( i>=pAggInfo->nColumn && (i = addAggInfoColumn(pAggInfo))>=0 ){ pCol = &pAggInfo->aCol[i]; pCol->iTable = pExpr->iTable; pCol->iColumn = pExpr->iColumn; pCol->iMem = pParse->nMem++; pCol->iSorterColumn = -1; pCol->pExpr = pExpr; if( pAggInfo->pGroupBy ){ int j, n; ExprList *pGB = pAggInfo->pGroupBy; struct ExprList_item *pTerm = pGB->a; n = pGB->nExpr; for(j=0; j<n; j++, pTerm++){ Expr *pE = pTerm->pExpr; if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable && pE->iColumn==pExpr->iColumn ){ pCol->iSorterColumn = j; break; } } } if( pCol->iSorterColumn<0 ){ pCol->iSorterColumn = pAggInfo->nSortingColumn++; } } /* There is now an entry for pExpr in pAggInfo->aCol[] (either ** because it was there before or because we just created it). ** Convert the pExpr to be a TK_AGG_COLUMN referring to that ** pAggInfo->aCol[] entry. */ pExpr->pAggInfo = pAggInfo; pExpr->op = TK_AGG_COLUMN; pExpr->iAgg = i; break; } /* endif pExpr->iTable==pItem->iCursor */ } /* end loop over pSrcList */ } return 1; } case TK_AGG_FUNCTION: { /* The pNC->nDepth==0 test causes aggregate functions in subqueries ** to be ignored */ if( pNC->nDepth==0 ){ /* Check to see if pExpr is a duplicate of another aggregate ** function that is already in the pAggInfo structure */ struct AggInfo_func *pItem = pAggInfo->aFunc; for(i=0; i<pAggInfo->nFunc; i++, pItem++){ if( sqlite3ExprCompare(pItem->pExpr, pExpr) ){ break; } } if( i>=pAggInfo->nFunc ){ /* pExpr is original. Make a new entry in pAggInfo->aFunc[] */ u8 enc = pParse->db->enc; i = addAggInfoFunc(pAggInfo); if( i>=0 ){ pItem = &pAggInfo->aFunc[i]; pItem->pExpr = pExpr; pItem->iMem = pParse->nMem++; pItem->pFunc = sqlite3FindFunction(pParse->db, pExpr->token.z, pExpr->token.n, pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0); if( pExpr->flags & EP_Distinct ){ pItem->iDistinct = pParse->nTab++; }else{ pItem->iDistinct = -1; } } } /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry */ pExpr->iAgg = i; pExpr->pAggInfo = pAggInfo; return 1; } } } /* Recursively walk subqueries looking for TK_COLUMN nodes that need ** to be changed to TK_AGG_COLUMN. But increment nDepth so that ** TK_AGG_FUNCTION nodes in subqueries will be unchanged. */ if( pExpr->pSelect ){ pNC->nDepth++; walkSelectExpr(pExpr->pSelect, analyzeAggregate, pNC); pNC->nDepth--; } return 0; } |
︙ | ︙ | |||
2145 2146 2147 2148 2149 2150 2151 | ** the number of errors. */ int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ int nErr = pNC->pParse->nErr; walkExprTree(pExpr, analyzeAggregate, pNC); return pNC->pParse->nErr - nErr; } | > > > > > > > > > > > > > > > > > > | 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 | ** the number of errors. */ int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ int nErr = pNC->pParse->nErr; walkExprTree(pExpr, analyzeAggregate, pNC); return pNC->pParse->nErr - nErr; } /* ** Call sqlite3ExprAnalyzeAggregates() for every expression in an ** expression list. Return the number of errors. ** ** If an error is found, the analysis is cut short. */ int sqlite3ExprAnalyzeAggList(NameContext *pNC, ExprList *pList){ struct ExprList_item *pItem; int i; int nErr = 0; if( pList ){ for(pItem=pList->a, i=0; nErr==0 && i<pList->nExpr; i++, pItem++){ nErr += sqlite3ExprAnalyzeAggregates(pNC, pItem->pExpr); } } return nErr; } |
Changes to SQLite.Interop/src/func.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** 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. ** | | | 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.10 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include <ctype.h> #include <math.h> #include <stdlib.h> #include <assert.h> #include "vdbeInt.h" |
︙ | ︙ | |||
815 816 817 818 819 820 821 822 823 824 825 826 827 828 | ** An instance of the following structure holds the context of a ** sum() or avg() aggregate computation. */ typedef struct SumCtx SumCtx; struct SumCtx { double sum; /* Sum of terms */ int cnt; /* Number of elements summed */ }; /* ** Routines used to compute the sum or average. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; | > > | | > > > > | > > | > > > > | | 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 | ** An instance of the following structure holds the context of a ** sum() or avg() aggregate computation. */ typedef struct SumCtx SumCtx; struct SumCtx { double sum; /* Sum of terms */ int cnt; /* Number of elements summed */ u8 seenFloat; /* True if there has been any floating point value */ }; /* ** Routines used to compute the sum or average. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; int type; assert( argc==1 ); p = sqlite3_aggregate_context(context, sizeof(*p)); type = sqlite3_value_type(argv[0]); if( p && type!=SQLITE_NULL ){ p->sum += sqlite3_value_double(argv[0]); p->cnt++; if( type==SQLITE_FLOAT ){ p->seenFloat = 1; } } } static void sumFinalize(sqlite3_context *context){ SumCtx *p; p = sqlite3_aggregate_context(context, 0); if( p && p->cnt>0 ){ if( p->seenFloat ){ sqlite3_result_double(context, p->sum); }else{ sqlite3_result_int64(context, (i64)p->sum); } } } static void avgFinalize(sqlite3_context *context){ SumCtx *p; p = sqlite3_aggregate_context(context, 0); if( p && p->cnt>0 ){ sqlite3_result_double(context, p->sum/(double)p->cnt); } } /* ** An instance of the following structure holds the context of a |
︙ | ︙ | |||
874 875 876 877 878 879 880 | 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; | | | 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | 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){ |
︙ | ︙ | |||
912 913 914 915 916 917 918 | } }else{ sqlite3VdbeMemCopy(pBest, pArg); } } static void minMaxFinalize(sqlite3_context *context){ sqlite3_value *pRes; | | > | | | | > | 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | } }else{ sqlite3VdbeMemCopy(pBest, pArg); } } static void minMaxFinalize(sqlite3_context *context){ sqlite3_value *pRes; pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0); if( pRes ){ if( pRes->flags ){ sqlite3_result_value(context, pRes); } sqlite3VdbeMemRelease(pRes); } } /* ** This function registered all of the above C functions as SQL ** functions. This should be the only routine in this file with ** external linkage. |
︙ | ︙ | |||
1037 1038 1039 1040 1041 1042 1043 | sqlite3RegisterLikeFunctions(db, 0); #endif } /* ** Set the LIKEOPT flag on the 2-argument function with the given name. */ | | | | < | < > | | | | 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 | sqlite3RegisterLikeFunctions(db, 0); #endif } /* ** Set the LIKEOPT flag on the 2-argument function with the given name. */ static void setLikeOptFlag(sqlite3 *db, const char *zName, int flagVal){ FuncDef *pDef; pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0); if( pDef ){ pDef->flags = flagVal; } } /* ** Register the built-in LIKE and GLOB functions. The caseSensitive ** parameter determines whether or not the LIKE operator is case ** sensitive. GLOB is always case sensitive. */ void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){ struct compareInfo *pInfo; if( caseSensitive ){ pInfo = (struct compareInfo*)&likeInfoAlt; }else{ pInfo = (struct compareInfo*)&likeInfoNorm; } sqlite3_create_function(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0); sqlite3_create_function(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0); sqlite3_create_function(db, "glob", 2, SQLITE_UTF8, (struct compareInfo*)&globInfo, likeFunc, 0,0); setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE); setLikeOptFlag(db, "like", caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE); } /* ** pExpr points to an expression which implements a function. If ** it is appropriate to apply the LIKE optimization to that function ** then set aWc[0] through aWc[2] to the wildcard characters and ** return TRUE. If the function is not a LIKE-style function then ** return FALSE. */ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ FuncDef *pDef; if( pExpr->op!=TK_FUNCTION ){ return 0; } if( pExpr->pList->nExpr!=2 ){ return 0; } pDef = sqlite3FindFunction(db, pExpr->token.z, pExpr->token.n, 2, SQLITE_UTF8, 0); if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){ return 0; } /* The memcpy() statement assumes that the wildcard characters are ** the first three statements in the compareInfo structure. The ** asserts() that follow verify that assumption */ memcpy(aWc, pDef->pUserData, 3); assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll ); assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne ); assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet ); *pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0; return 1; } |
Changes to SQLite.Interop/src/hash.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This is the implementation of generic hash-tables ** used in SQLite. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This is the implementation of generic hash-tables ** used in SQLite. ** ** $Id: hash.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include <assert.h> /* Turn bulk memory into a hash table object by initializing the ** fields of the Hash structure. ** |
︙ | ︙ |
Changes to SQLite.Interop/src/hash.h.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This is the header file for the generic hash-table implemenation ** used in SQLite. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This is the header file for the generic hash-table implemenation ** used in SQLite. ** ** $Id: hash.h,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef _SQLITE_HASH_H_ #define _SQLITE_HASH_H_ /* Forward declarations of structures. */ typedef struct Hash Hash; typedef struct HashElem HashElem; |
︙ | ︙ |
Changes to SQLite.Interop/src/insert.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** Set P3 of the most recently inserted opcode to a column affinity ** string for index pIdx. A column affinity string has one character ** for each column in the table, according to the affinity of the column: |
︙ | ︙ | |||
368 369 370 371 372 373 374 | sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0); sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* The following code runs first because the GOTO at the very top ** of the program jumps to it. Create the temporary table, then jump ** back up and execute the SELECT code above. */ | | | | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0); sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* The following code runs first because the GOTO at the very top ** of the program jumps to it. Create the temporary table, then jump ** back up and execute the SELECT code above. */ sqlite3VdbeJumpHere(v, iInitCode); sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn); sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop); sqlite3VdbeResolveLabel(v, iCleanup); }else{ sqlite3VdbeJumpHere(v, iInitCode); } }else{ /* This is the case if the data for the INSERT is coming from a VALUES ** clause */ NameContext sNC; memset(&sNC, 0, sizeof(sNC)); |
︙ | ︙ | |||
466 467 468 469 470 471 472 | sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol); } /* Initialize the count of rows to be inserted */ if( db->flags & SQLITE_CountRows ){ iCntMem = pParse->nMem++; | < | | 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol); } /* Initialize the count of rows to be inserted */ if( db->flags & SQLITE_CountRows ){ iCntMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemInt, 0, iCntMem); } /* Open tables and indices if there are no row triggers */ if( !triggers_exist ){ base = pParse->nTab; sqlite3OpenTableAndIndices(pParse, pTab, base, OP_OpenWrite); } |
︙ | ︙ | |||
813 814 815 816 817 818 819 | int onError; int addr; int extra; int iCur; Index *pIdx; int seenReplace = 0; int jumpInst1=0, jumpInst2; | < | 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | int onError; int addr; int extra; int iCur; Index *pIdx; int seenReplace = 0; int jumpInst1=0, jumpInst2; int hasTwoRowids = (isUpdate && rowidChng); v = sqlite3GetVdbe(pParse); assert( v!=0 ); assert( pTab->pSelect==0 ); /* This table is not a VIEW */ nCol = pTab->nCol; |
︙ | ︙ | |||
863 864 865 866 867 868 869 | } case OE_Replace: { sqlite3ExprCode(pParse, pTab->aCol[i].pDflt); sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0); break; } } | | | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | } case OE_Replace: { sqlite3ExprCode(pParse, pTab->aCol[i].pDflt); sqlite3VdbeAddOp(v, OP_Push, nCol-i, 0); break; } } sqlite3VdbeJumpHere(v, addr); } /* Test all CHECK constraints */ /**** TBD ****/ /* If we have an INTEGER PRIMARY KEY, make sure the primary key |
︙ | ︙ | |||
917 918 919 920 921 922 923 | case OE_Ignore: { assert( seenReplace==0 ); sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest); break; } } | < | | | 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | case OE_Ignore: { assert( seenReplace==0 ); sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest); break; } } sqlite3VdbeJumpHere(v, jumpInst2); if( isUpdate ){ sqlite3VdbeJumpHere(v, jumpInst1); sqlite3VdbeAddOp(v, OP_Dup, nCol+1, 1); sqlite3VdbeAddOp(v, OP_MoveGe, base, 0); } } /* Test all UNIQUE constraints by creating entries for each UNIQUE ** index and making sure that duplicate entries do not already exist. |
︙ | ︙ | |||
1014 1015 1016 1017 1018 1019 1020 | sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1); sqlite3VdbeAddOp(v, OP_MoveGe, base, 0); } seenReplace = 1; break; } } | < | | | 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 | sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1); sqlite3VdbeAddOp(v, OP_MoveGe, base, 0); } seenReplace = 1; break; } } #if NULL_DISTINCT_FOR_UNIQUE sqlite3VdbeJumpHere(v, jumpInst1); #endif sqlite3VdbeJumpHere(v, jumpInst2); } } /* ** This routine generates code to finish the INSERT or UPDATE operation ** that was started by a prior call to sqlite3GenerateConstraintChecks. ** The stack must contain keys for all active indices followed by data |
︙ | ︙ |
Changes to SQLite.Interop/src/keywordhash.h.
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | /* Hash score: 158 */ static int keywordCode(const char *z, int n){ static const char zText[535] = "ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER" "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYANALYZE" "XCLUSIVEXISTSTATEMENTANDEFERRABLEATTACHAVINGLOBEFOREIGNOREINDEX" "AUTOINCREMENTBEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETE" "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS" "CURRENT_DATECURRENT_TIMESTAMPLANDESCDETACHDISTINCTDROPRAGMATCH" "FAILIMITFROMFULLGROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULL" "JOINORDEREPLACEOUTERESTRICTPRIMARYQUERYRIGHTROLLBACKROWHENUNION" "UNIQUEUSINGVACUUMVALUESVIEWHERE"; static const unsigned char aHash[127] = { 91, 80, 106, 90, 0, 4, 0, 0, 113, 0, 83, 0, 0, 94, 44, 76, 92, 0, 105, 108, 96, 0, 0, 10, 0, 0, 112, 0, 109, 102, 0, 28, 48, 0, 41, 0, 0, 65, 71, 0, 63, 19, 0, 104, 36, 103, 0, 107, 74, 0, 0, 33, 0, 61, 37, 0, 8, 0, 114, 38, 12, 0, 77, 40, 25, 66, 0, 0, 31, 81, 53, 30, 50, 20, 88, 0, 34, 0, 75, 26, 0, 72, 0, 0, 0, 64, 47, 67, 22, 87, 29, 69, 86, 0, 1, 0, 9, 100, 58, 18, 0, 111, 82, 98, 54, 6, 85, 0, 0, 49, 93, 0, 101, 0, 70, 0, 0, 15, 0, 115, 51, 56, 0, 2, 55, 0, 110, }; static const unsigned char aNext[115] = { 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 5, 13, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 16, 0, 23, 52, 0, 0, 0, 0, 45, 0, 59, 0, 0, 0, 0, 0, 0, 0, 0, 73, 42, 0, 24, 60, 21, 0, 79, 0, 0, 68, 0, 0, 84, 46, 0, 0, 0, 0, 0, 0, 0, 39, 95, 97, 0, 0, 99, 0, 32, 0, 14, 27, 78, 0, 57, 89, 0, 35, 0, 62, 0, }; static const unsigned char aLen[115] = { 5, 5, 4, 4, 9, 2, 3, 8, 2, 6, 4, 3, 7, 11, 2, 7, 5, 5, 4, 5, 3, 5, 10, 6, 4, 6, 7, 6, 7, 9, 3, 7, 9, 6, 9, 3, 10, 6, 6, 4, 6, 3, 7, 6, 7, 5, 13, 2, 2, 5, 5, 6, 7, 3, 7, 4, 4, 2, 7, 3, 8, 6, 4, 4, 7, 6, 6, 8, 10, 9, 6, 5, 12, 12, 17, 4, 4, 6, 8, 2, 4, 6, 5, 4, 5, 4, 4, 5, 6, 9, 6, 7, 4, 2, 6, 3, 6, 4, 5, 7, 5, 8, 7, 5, 5, 8, 3, 4, 5, 6, 5, 6, 6, 4, 5, }; static const unsigned short int aOffset[115] = { 0, 4, 7, 10, 10, 14, 19, 21, 26, 27, 32, 34, 36, 42, 51, 52, 57, 61, 65, 67, 71, 74, 78, 86, 91, 94, 99, 105, 108, 113, 118, 122, 128, 136, 141, 150, 152, 162, 167, 172, 175, 177, 177, 181, 185, 187, 192, 194, 196, 205, 208, 212, 218, 224, 224, 227, 230, 234, 236, 237, 241, 248, 254, 258, 262, 269, 275, 281, 289, 296, 305, 311, 316, 328, 328, 344, 348, 352, 358, 359, 366, 369, 373, 378, 381, 386, 390, 394, 397, 403, 412, 418, 425, 428, 428, 431, 434, 440, 444, 448, 455, 459, 467, 474, 479, 484, 492, 494, 498, 503, 509, 514, 520, 526, 529, }; static const unsigned char aCode[115] = { TK_ABORT, TK_TABLE, TK_JOIN_KW, TK_TEMP, TK_TEMP, TK_OR, TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_THEN, TK_END, TK_DEFAULT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER, TK_RAISE, TK_EACH, TK_CHECK, TK_KEY, TK_AFTER, TK_REFERENCES, TK_ESCAPE, TK_ELSE, TK_EXCEPT, TK_TRIGGER, TK_LIKE_KW, TK_EXPLAIN, TK_INITIALLY, TK_ALL, TK_ANALYZE, TK_EXCLUSIVE, TK_EXISTS, TK_STATEMENT, TK_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_IMMEDIATE, TK_INSERT, TK_INSTEAD, TK_INTO, TK_OF, TK_OFFSET, TK_SET, TK_ISNULL, TK_JOIN, TK_ORDER, TK_REPLACE, TK_JOIN_KW, TK_RESTRICT, TK_PRIMARY, TK_QUERY, TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_WHEN, TK_UNION, TK_UNIQUE, TK_USING, TK_VACUUM, TK_VALUES, TK_VIEW, TK_WHERE, }; int h, i; if( n<2 ) return TK_ID; h = ((sqlite3UpperToLower[((unsigned char*)z)[0]]*4) ^ (sqlite3UpperToLower[((unsigned char*)z)[n-1]]*3) ^ n) % 127; for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){ |
︙ | ︙ |
Changes to SQLite.Interop/src/legacy.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** 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. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** ** $Id: legacy.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* |
︙ | ︙ |
Changes to SQLite.Interop/src/main.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** The following constant value is used by the SQLITE_BIGENDIAN and |
︙ | ︙ | |||
505 506 507 508 509 510 511 512 513 514 515 516 517 | } rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep, pUserData, xFunc, xStep, xFinal); return rc; } #endif /* ** Register a trace function. The pArg from the previously registered trace ** is returned. ** ** A NULL trace function means that no tracing is executes. A non-NULL ** trace is a pointer to a function that is invoked at the start of each | > | > > > > > > > > > > > > > > > > > > > | 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 | } rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep, pUserData, xFunc, xStep, xFinal); return rc; } #endif #ifndef SQLITE_OMIT_TRACE /* ** Register a trace function. The pArg from the previously registered trace ** is returned. ** ** A NULL trace function means that no tracing is executes. A non-NULL ** trace is a pointer to a function that is invoked at the start of each ** SQL statement. */ void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){ void *pOld = db->pTraceArg; db->xTrace = xTrace; db->pTraceArg = pArg; return pOld; } /* ** Register a profile function. The pArg from the previously registered ** profile function is returned. ** ** A NULL profile function means that no profiling is executes. A non-NULL ** profile is a pointer to a function that is invoked at the conclusion of ** each SQL statement that is run. */ void *sqlite3_profile( sqlite3 *db, void (*xProfile)(void*,const char*,sqlite_uint64), void *pArg ){ void *pOld = db->pProfileArg; db->xProfile = xProfile; db->pProfileArg = pArg; return pOld; } #endif /* SQLITE_OMIT_TRACE */ /*** EXPERIMENTAL *** ** ** Register a function to be invoked when a transaction comments. ** If either function returns non-zero, then the commit becomes a ** rollback. */ |
︙ | ︙ | |||
690 691 692 693 694 695 696 697 698 699 700 701 702 703 | */ static int openDatabase( const char *zFilename, /* Database filename UTF-8 encoded */ sqlite3 **ppDb /* OUT: Returned database handle */ ){ sqlite3 *db; int rc, i; /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; db->priorNewRowid = 0; db->magic = SQLITE_MAGIC_BUSY; db->nDb = 2; | > | 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | */ static int openDatabase( const char *zFilename, /* Database filename UTF-8 encoded */ sqlite3 **ppDb /* OUT: Returned database handle */ ){ sqlite3 *db; int rc, i; CollSeq *pColl; /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; db->priorNewRowid = 0; db->magic = SQLITE_MAGIC_BUSY; db->nDb = 2; |
︙ | ︙ | |||
725 726 727 728 729 730 731 732 733 734 735 736 737 738 | assert( rc!=SQLITE_OK ); db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; } /* Also add a UTF-8 case-insensitive collation sequence. */ sqlite3_create_collation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc); /* Open the backend database driver */ rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ sqlite3Error(db, rc, 0); db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; | > > > > > > > | 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | assert( rc!=SQLITE_OK ); db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; } /* Also add a UTF-8 case-insensitive collation sequence. */ sqlite3_create_collation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc); /* Set flags on the built-in collating sequences */ db->pDfltColl->type = SQLITE_COLL_BINARY; pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 6, 0); if( pColl ){ pColl->type = SQLITE_COLL_NOCASE; } /* Open the backend database driver */ rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ sqlite3Error(db, rc, 0); db->magic = SQLITE_MAGIC_CLOSED; goto opendb_out; |
︙ | ︙ | |||
843 844 845 846 847 848 849 | */ int sqlite3_reset(sqlite3_stmt *pStmt){ int rc; if( pStmt==0 ){ rc = SQLITE_OK; }else{ rc = sqlite3VdbeReset((Vdbe*)pStmt); | | | 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 | */ int sqlite3_reset(sqlite3_stmt *pStmt){ int rc; if( pStmt==0 ){ rc = SQLITE_OK; }else{ rc = sqlite3VdbeReset((Vdbe*)pStmt); sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0, 0, 0); } return rc; } /* ** Register a new collation sequence with the database handle db. */ |
︙ | ︙ | |||
897 898 899 900 901 902 903 | return SQLITE_BUSY; } sqlite3ExpirePreparedStatements(db); } pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1); if( 0==pColl ){ | | | 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | return SQLITE_BUSY; } sqlite3ExpirePreparedStatements(db); } pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1); if( 0==pColl ){ rc = SQLITE_NOMEM; }else{ pColl->xCmp = xCompare; pColl->pUser = pCtx; pColl->enc = enc; } sqlite3Error(db, rc, 0); return rc; |
︙ | ︙ | |||
1015 1016 1017 1018 1019 1020 1021 | ** by the next COMMIT or ROLLBACK. ** ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** */ int sqlite3_get_autocommit(sqlite3 *db){ return db->autoCommit; } | > > > > > > > > > > > | 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 | ** by the next COMMIT or ROLLBACK. ** ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ****** */ int sqlite3_get_autocommit(sqlite3 *db){ return db->autoCommit; } #ifdef SQLITE_DEBUG /* ** The following routine is subtituted for constant SQLITE_CORRUPT in ** debugging builds. This provides a way to set a breakpoint for when ** corruption is first detected. */ int sqlite3Corrupt(void){ return SQLITE_CORRUPT; } #endif |
Changes to SQLite.Interop/src/opcodes.c.
1 2 3 4 5 6 7 8 | /* 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", | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < > > > > > | | | | | | | | | | | | | | | | | | | | | | | | > > > | 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 | /* 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 */ "ToInt", /* 11 */ "Pop", /* 12 */ "CollSeq", /* 13 */ "OpenRead", /* 14 */ "Expire", /* 15 */ "AutoCommit", /* 16 */ "IntegrityCk", /* 17 */ "Sort", /* 18 */ "Function", /* 19 */ "Noop", /* 20 */ "Return", /* 21 */ "NewRowid", /* 22 */ "Variable", /* 23 */ "String", /* 24 */ "ParseSchema", /* 25 */ "Close", /* 26 */ "CreateIndex", /* 27 */ "IsUnique", /* 28 */ "IdxIsNull", /* 29 */ "NotFound", /* 30 */ "Int64", /* 31 */ "MustBeInt", /* 32 */ "Halt", /* 33 */ "Rowid", /* 34 */ "IdxLT", /* 35 */ "AddImm", /* 36 */ "Statement", /* 37 */ "RowData", /* 38 */ "MemMax", /* 39 */ "Push", /* 40 */ "NotExists", /* 41 */ "MemIncr", /* 42 */ "Gosub", /* 43 */ "Integer", /* 44 */ "ToNumeric", /* 45 */ "MemInt", /* 46 */ "Prev", /* 47 */ "CreateTable", /* 48 */ "Last", /* 49 */ "IdxRowid", /* 50 */ "MakeIdxRec", /* 51 */ "ResetCount", /* 52 */ "FifoWrite", /* 53 */ "Callback", /* 54 */ "ContextPush", /* 55 */ "DropTrigger", /* 56 */ "DropIndex", /* 57 */ "IdxGE", /* 58 */ "IdxDelete", /* 59 */ "Vacuum", /* 60 */ "MoveLe", /* 61 */ "IfNot", /* 62 */ "DropTable", /* 63 */ "MakeRecord", /* 64 */ "ToBlob", /* 65 */ "Delete", /* 66 */ "AggFinal", /* 67 */ "Or", /* 68 */ "And", /* 69 */ "Not", /* 70 */ "Dup", /* 71 */ "Goto", /* 72 */ "FifoRead", /* 73 */ "IsNull", /* 74 */ "NotNull", /* 75 */ "Ne", /* 76 */ "Eq", /* 77 */ "Gt", /* 78 */ "Le", /* 79 */ "Lt", /* 80 */ "Ge", /* 81 */ "Clear", /* 82 */ "BitAnd", /* 83 */ "BitOr", /* 84 */ "ShiftLeft", /* 85 */ "ShiftRight", /* 86 */ "Add", /* 87 */ "Subtract", /* 88 */ "Multiply", /* 89 */ "Divide", /* 90 */ "Remainder", /* 91 */ "Concat", /* 92 */ "Negative", /* 93 */ "IdxGT", /* 94 */ "BitNot", /* 95 */ "String8", /* 96 */ "MoveLt", /* 97 */ "VerifyCookie", /* 98 */ "AggStep", /* 99 */ "Pull", /* 100 */ "ToText", /* 101 */ "SetNumColumns", /* 102 */ "AbsValue", /* 103 */ "Transaction", /* 104 */ "ContextPop", /* 105 */ "Next", /* 106 */ "IdxInsert", /* 107 */ "Distinct", /* 108 */ "Insert", /* 109 */ "Destroy", /* 110 */ "ReadCookie", /* 111 */ "ForceInt", /* 112 */ "LoadAnalysis", /* 113 */ "OpenVirtual", /* 114 */ "Explain", /* 115 */ "OpenPseudo", /* 116 */ "Null", /* 117 */ "Blob", /* 118 */ "MemStore", /* 119 */ "Rewind", /* 120 */ "MoveGe", /* 121 */ "MemMove", /* 122 */ "MemNull", /* 123 */ "Found", /* 124 */ "NullRow", /* 125 */ "NotUsed_125", /* 126 */ "NotUsed_126", /* 127 */ "NotUsed_127", /* 128 */ "NotUsed_128", /* 129 */ "NotUsed_129", /* 130 */ "NotUsed_130", /* 131 */ "NotUsed_131", /* 132 */ "NotUsed_132", /* 133 */ "Real", /* 134 */ "HexBlob", }; #endif |
Changes to SQLite.Interop/src/opcodes.h.
1 2 3 | /* Automatically generated. Do not edit */ /* See the mkopcodeh.awk script for details */ #define OP_MemLoad 1 | | | > | | < < | | | | | | | < | | | < | | < | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | < | | | < | | | < | | | | | | > | | | | | | | | > > | | > > > > > > > > > > | | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | /* Automatically generated. Do not edit */ /* See the mkopcodeh.awk script for details */ #define OP_MemLoad 1 #define OP_HexBlob 134 /* same as TK_BLOB */ #define OP_Column 2 #define OP_SetCookie 3 #define OP_IfMemPos 4 #define OP_Real 133 /* same as TK_FLOAT */ #define OP_Sequence 5 #define OP_MoveGt 6 #define OP_Ge 80 /* same as TK_GE */ #define OP_RowKey 7 #define OP_Eq 76 /* same as TK_EQ */ #define OP_OpenWrite 8 #define OP_NotNull 74 /* same as TK_NOTNULL */ #define OP_If 9 #define OP_ToInt 10 #define OP_String8 95 /* same as TK_STRING */ #define OP_Pop 11 #define OP_CollSeq 12 #define OP_OpenRead 13 #define OP_Expire 14 #define OP_AutoCommit 15 #define OP_Gt 77 /* same as TK_GT */ #define OP_IntegrityCk 16 #define OP_Sort 17 #define OP_Function 18 #define OP_And 68 /* same as TK_AND */ #define OP_Subtract 87 /* same as TK_MINUS */ #define OP_Noop 19 #define OP_Return 20 #define OP_Remainder 90 /* same as TK_REM */ #define OP_NewRowid 21 #define OP_Multiply 88 /* same as TK_STAR */ #define OP_Variable 22 #define OP_String 23 #define OP_ParseSchema 24 #define OP_Close 25 #define OP_CreateIndex 26 #define OP_IsUnique 27 #define OP_IdxIsNull 28 #define OP_NotFound 29 #define OP_Int64 30 #define OP_MustBeInt 31 #define OP_Halt 32 #define OP_Rowid 33 #define OP_IdxLT 34 #define OP_AddImm 35 #define OP_Statement 36 #define OP_RowData 37 #define OP_MemMax 38 #define OP_Push 39 #define OP_Or 67 /* same as TK_OR */ #define OP_NotExists 40 #define OP_MemIncr 41 #define OP_Gosub 42 #define OP_Divide 89 /* same as TK_SLASH */ #define OP_Integer 43 #define OP_ToNumeric 44 #define OP_MemInt 45 #define OP_Prev 46 #define OP_Concat 91 /* same as TK_CONCAT */ #define OP_BitAnd 82 /* same as TK_BITAND */ #define OP_CreateTable 47 #define OP_Last 48 #define OP_IsNull 73 /* same as TK_ISNULL */ #define OP_IdxRowid 49 #define OP_MakeIdxRec 50 #define OP_ShiftRight 85 /* same as TK_RSHIFT */ #define OP_ResetCount 51 #define OP_FifoWrite 52 #define OP_Callback 53 #define OP_ContextPush 54 #define OP_DropTrigger 55 #define OP_DropIndex 56 #define OP_IdxGE 57 #define OP_IdxDelete 58 #define OP_Vacuum 59 #define OP_MoveLe 60 #define OP_IfNot 61 #define OP_DropTable 62 #define OP_MakeRecord 63 #define OP_ToBlob 64 #define OP_Delete 65 #define OP_AggFinal 66 #define OP_ShiftLeft 84 /* same as TK_LSHIFT */ #define OP_Dup 70 #define OP_Goto 71 #define OP_FifoRead 72 #define OP_Clear 81 #define OP_IdxGT 93 #define OP_MoveLt 96 #define OP_Le 78 /* same as TK_LE */ #define OP_VerifyCookie 97 #define OP_AggStep 98 #define OP_Pull 99 #define OP_ToText 100 #define OP_Not 69 /* same as TK_NOT */ #define OP_SetNumColumns 101 #define OP_AbsValue 102 #define OP_Transaction 103 #define OP_Negative 92 /* same as TK_UMINUS */ #define OP_Ne 75 /* same as TK_NE */ #define OP_ContextPop 104 #define OP_BitOr 83 /* same as TK_BITOR */ #define OP_Next 105 #define OP_IdxInsert 106 #define OP_Distinct 107 #define OP_Lt 79 /* same as TK_LT */ #define OP_Insert 108 #define OP_Destroy 109 #define OP_ReadCookie 110 #define OP_ForceInt 111 #define OP_LoadAnalysis 112 #define OP_OpenVirtual 113 #define OP_Explain 114 #define OP_OpenPseudo 115 #define OP_Null 116 #define OP_Blob 117 #define OP_Add 86 /* same as TK_PLUS */ #define OP_MemStore 118 #define OP_Rewind 119 #define OP_MoveGe 120 #define OP_BitNot 94 /* same as TK_BITNOT */ #define OP_MemMove 121 #define OP_MemNull 122 #define OP_Found 123 #define OP_NullRow 124 /* The following opcode values are never used */ #define OP_NotUsed_125 125 #define OP_NotUsed_126 126 #define OP_NotUsed_127 127 #define OP_NotUsed_128 128 #define OP_NotUsed_129 129 #define OP_NotUsed_130 130 #define OP_NotUsed_131 131 #define OP_NotUsed_132 132 #define NOPUSH_MASK_0 65368 #define NOPUSH_MASK_1 47898 #define NOPUSH_MASK_2 22493 #define NOPUSH_MASK_3 32761 #define NOPUSH_MASK_4 65215 #define NOPUSH_MASK_5 30719 #define NOPUSH_MASK_6 40895 #define NOPUSH_MASK_7 6603 #define NOPUSH_MASK_8 0 #define NOPUSH_MASK_9 0 |
Changes to SQLite.Interop/src/os.h.
︙ | ︙ | |||
157 158 159 160 161 162 163 164 | ** Changing the value of PENDING_BYTE results in a subtly incompatible ** file format. Depending on how it is changed, you might not notice ** the incompatibility right away, even running a full regression test. ** The default location of PENDING_BYTE is the first byte past the ** 1GB boundary. ** */ #define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */ | > > > | > > | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | ** Changing the value of PENDING_BYTE results in a subtly incompatible ** file format. Depending on how it is changed, you might not notice ** the incompatibility right away, even running a full regression test. ** The default location of PENDING_BYTE is the first byte past the ** 1GB boundary. ** */ #ifndef SQLITE_TEST #define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */ #else extern unsigned int sqlite3_pending_byte; #define PENDING_BYTE sqlite3_pending_byte #endif #define RESERVED_BYTE (PENDING_BYTE+1) #define SHARED_FIRST (PENDING_BYTE+2) #define SHARED_SIZE 510 int sqlite3OsDelete(const char*); int sqlite3OsFileExists(const char*); int sqlite3OsOpenReadWrite(const char*, OsFile*, int*); int sqlite3OsOpenExclusive(const char*, OsFile*, int); int sqlite3OsOpenReadOnly(const char*, OsFile*); int sqlite3OsOpenDirectory(const char*, OsFile*); int sqlite3OsSyncDirectory(const char*); int sqlite3OsTempFileName(char*); int sqlite3OsIsDirWritable(char*); int sqlite3OsClose(OsFile*); int sqlite3OsRead(OsFile*, void*, int amt); int sqlite3OsWrite(OsFile*, const void*, int amt); int sqlite3OsSeek(OsFile*, i64 offset); int sqlite3OsSync(OsFile*, int); int sqlite3OsTruncate(OsFile*, i64 size); int sqlite3OsFileSize(OsFile*, i64 *pSize); char *sqlite3OsFullPathname(const char*); int sqlite3OsLock(OsFile*, int); int sqlite3OsUnlock(OsFile*, int); int sqlite3OsCheckReservedLock(OsFile *id); |
︙ | ︙ |
Changes to SQLite.Interop/src/os_common.h.
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ** switch. The following code should catch this problem at compile-time. */ #ifdef MEMORY_DEBUG # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." #endif #ifdef SQLITE_DEBUG int sqlite3_os_trace = 0; static int last_page = 0; #define SEEK(X) last_page=(X) #define TRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X) #define TRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y) #define TRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z) | > > > > > > > > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ** switch. The following code should catch this problem at compile-time. */ #ifdef MEMORY_DEBUG # error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead." #endif /* * When testing, this global variable stores the location of the * pending-byte in the database file. */ #ifdef SQLITE_TEST unsigned int sqlite3_pending_byte = 0x40000000; #endif #ifdef SQLITE_DEBUG int sqlite3_os_trace = 0; static int last_page = 0; #define SEEK(X) last_page=(X) #define TRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X) #define TRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y) #define TRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z) |
︙ | ︙ | |||
78 79 80 81 82 83 84 85 86 87 88 89 90 91 | ** If we compile with the SQLITE_TEST macro set, then the following block ** of code will give us the ability to simulate a disk I/O error. This ** is used for testing the I/O recovery logic. */ #ifdef SQLITE_TEST int sqlite3_io_error_pending = 0; int sqlite3_diskfull_pending = 0; #define SimulateIOError(A) \ if( sqlite3_io_error_pending ) \ if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; } static void local_ioerr(){ sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */ } #define SimulateDiskfullError \ | > | | > > > > > > > | 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 | ** If we compile with the SQLITE_TEST macro set, then the following block ** of code will give us the ability to simulate a disk I/O error. This ** is used for testing the I/O recovery logic. */ #ifdef SQLITE_TEST int sqlite3_io_error_pending = 0; int sqlite3_diskfull_pending = 0; int sqlite3_diskfull = 0; #define SimulateIOError(A) \ if( sqlite3_io_error_pending ) \ if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; } static void local_ioerr(){ sqlite3_io_error_pending = 0; /* Really just a place to set a breakpoint */ } #define SimulateDiskfullError \ if( sqlite3_diskfull_pending ){ \ if( sqlite3_diskfull_pending == 1 ){ \ local_ioerr(); \ sqlite3_diskfull = 1; \ return SQLITE_FULL; \ }else{ \ sqlite3_diskfull_pending--; \ } \ } #else #define SimulateIOError(A) #define SimulateDiskfullError #endif /* ** When testing, keep a count of the number of open files. |
︙ | ︙ |
Changes to SQLite.Interop/src/os_unix.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | */ #include "sqliteInt.h" #include "os.h" #if OS_UNIX /* This file is used on unix only */ #include <time.h> #include <errno.h> #include <unistd.h> /* ** Do not include any of the File I/O interface procedures if the ** SQLITE_OMIT_DISKIO macro is defined (indicating that there database ** will be in-memory only) | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "sqliteInt.h" #include "os.h" #if OS_UNIX /* This file is used on unix only */ #include <time.h> #include <sys/time.h> #include <errno.h> #include <unistd.h> /* ** Do not include any of the File I/O interface procedures if the ** SQLITE_OMIT_DISKIO macro is defined (indicating that there database ** will be in-memory only) |
︙ | ︙ | |||
767 768 769 770 771 772 773 774 775 776 777 778 779 780 | /* ** Move the read/write pointer in a file. */ int sqlite3OsSeek(OsFile *id, i64 offset){ assert( id->isOpen ); SEEK(offset/1024 + 1); lseek(id->h, offset, SEEK_SET); return SQLITE_OK; } #ifdef SQLITE_TEST /* ** Count the number of fullsyncs and normal syncs. This is used to test | > > > | 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | /* ** Move the read/write pointer in a file. */ int sqlite3OsSeek(OsFile *id, i64 offset){ assert( id->isOpen ); SEEK(offset/1024 + 1); #ifdef SQLITE_TEST if( offset ) SimulateDiskfullError #endif lseek(id->h, offset, SEEK_SET); return SQLITE_OK; } #ifdef SQLITE_TEST /* ** Count the number of fullsyncs and normal syncs. This is used to test |
︙ | ︙ | |||
792 793 794 795 796 797 798 | ** ** The SQLITE_NO_SYNC macro disables all fsync()s. This is useful ** for testing when we want to run through the test suite quickly. ** You are strongly advised *not* to deploy with SQLITE_NO_SYNC ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash ** or power failure will likely corrupt the database file. */ | | | 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | ** ** The SQLITE_NO_SYNC macro disables all fsync()s. This is useful ** for testing when we want to run through the test suite quickly. ** You are strongly advised *not* to deploy with SQLITE_NO_SYNC ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash ** or power failure will likely corrupt the database file. */ static int full_fsync(int fd, int fullSync, int dataOnly){ int rc; /* Record the number of times that we do a normal fsync() and ** FULLSYNC. This is used during testing to verify that this procedure ** gets called with the correct arguments. */ #ifdef SQLITE_TEST |
︙ | ︙ | |||
820 821 822 823 824 825 826 | rc = fcntl(fd, F_FULLFSYNC, 0); }else{ rc = 1; } /* If the FULLSYNC failed, try to do a normal fsync() */ if( rc ) rc = fsync(fd); | > > > > | > > | > > > > > | | | | 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 | rc = fcntl(fd, F_FULLFSYNC, 0); }else{ rc = 1; } /* If the FULLSYNC failed, try to do a normal fsync() */ if( rc ) rc = fsync(fd); #else /* if !defined(F_FULLSYNC) */ #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO>0 if( dataOnly ){ rc = fdatasync(fd); }else #endif /* _POSIX_SYNCHRONIZED_IO > 0 */ { rc = fsync(fd); } #endif /* defined(F_FULLFSYNC) */ #endif /* defined(SQLITE_NO_SYNC) */ return rc; } /* ** Make sure all writes to a particular file are committed to disk. ** ** If dataOnly==0 then both the file itself and its metadata (file ** size, access time, etc) are synced. If dataOnly!=0 then only the ** file data is synced. ** ** Under Unix, also make sure that the directory entry for the file ** has been created by fsync-ing the directory that contains the file. ** If we do not do this and we encounter a power failure, the directory ** entry for the journal might not exist after we reboot. The next ** SQLite to access the file will not know that the journal exists (because ** the directory entry for the journal was never created) and the transaction ** will not roll back - possibly leading to database corruption. */ int sqlite3OsSync(OsFile *id, int dataOnly){ assert( id->isOpen ); SimulateIOError(SQLITE_IOERR); TRACE2("SYNC %-3d\n", id->h); if( full_fsync(id->h, id->fullSync, dataOnly) ){ return SQLITE_IOERR; } if( id->dirfd>=0 ){ TRACE2("DIRSYNC %-3d\n", id->dirfd); full_fsync(id->dirfd, id->fullSync, 0); close(id->dirfd); /* Only need to sync once, so close the directory */ id->dirfd = -1; /* when we are done. */ } return SQLITE_OK; } /* |
︙ | ︙ | |||
1306 1307 1308 1309 1310 1311 1312 | ** is no longer needed. */ char *sqlite3OsFullPathname(const char *zRelative){ char *zFull = 0; if( zRelative[0]=='/' ){ sqlite3SetString(&zFull, zRelative, (char*)0); }else{ | > | > > | > | 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 | ** is no longer needed. */ char *sqlite3OsFullPathname(const char *zRelative){ char *zFull = 0; if( zRelative[0]=='/' ){ sqlite3SetString(&zFull, zRelative, (char*)0); }else{ char *zBuf = sqliteMalloc(5000); if( zBuf==0 ){ return 0; } zBuf[0] = 0; sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative, (char*)0); sqliteFree(zBuf); } return zFull; } #endif /* SQLITE_OMIT_DISKIO */ /*************************************************************************** |
︙ | ︙ | |||
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | /* ** Find the current time (in Universal Coordinated Time). Write the ** current time and date as a Julian Day number into *prNow and ** return 0. Return 1 if the time and date cannot be found. */ int sqlite3OsCurrentTime(double *prNow){ time_t t; time(&t); *prNow = t/86400.0 + 2440587.5; #ifdef SQLITE_TEST if( sqlite3_current_time ){ *prNow = sqlite3_current_time/86400.0 + 2440587.5; } #endif return 0; } #endif /* OS_UNIX */ | > > > > > > > | 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 | /* ** Find the current time (in Universal Coordinated Time). Write the ** current time and date as a Julian Day number into *prNow and ** return 0. Return 1 if the time and date cannot be found. */ int sqlite3OsCurrentTime(double *prNow){ #ifdef NO_GETTOD time_t t; time(&t); *prNow = t/86400.0 + 2440587.5; #else struct timeval sNow; struct timezone sTz; /* Not used */ gettimeofday(&sNow, &sTz); *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0; #endif #ifdef SQLITE_TEST if( sqlite3_current_time ){ *prNow = sqlite3_current_time/86400.0 + 2440587.5; } #endif return 0; } #endif /* OS_UNIX */ |
Changes to SQLite.Interop/src/os_win.c.
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 45 46 47 | /* ** Do not include any of the File I/O interface procedures if the ** SQLITE_OMIT_DISKIO macro is defined (indicating that there database ** will be in-memory only) */ #ifndef SQLITE_OMIT_DISKIO /* ** Delete the named file */ int sqlite3OsDelete(const char *zFilename){ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > | > > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | /* ** Do not include any of the File I/O interface procedures if the ** SQLITE_OMIT_DISKIO macro is defined (indicating that there database ** will be in-memory only) */ #ifndef SQLITE_OMIT_DISKIO /* ** The following variable is (normally) set once and never changes ** thereafter. It records whether the operating system is Win95 ** or WinNT. ** ** 0: Operating system unknown. ** 1: Operating system is Win95. ** 2: Operating system is WinNT. ** ** In order to facilitate testing on a WinNT system, the test fixture ** can manually set this value to 1 to emulate Win98 behavior. */ int sqlite3_os_type = 0; /* ** Return true (non-zero) if we are running under WinNT, Win2K or WinXP. ** Return false (zero) for Win95, Win98, or WinME. ** ** Here is an interesting observation: Win95, Win98, and WinME lack ** the LockFileEx() API. But we can still statically link against that ** API as long as we don't call it win running Win95/98/ME. A call to ** this routine is used to determine if the host is Win95/98/ME or ** WinNT/2K/XP so that we will know whether or not we can safely call ** the LockFileEx() API. */ static int isNT(void){ if( sqlite3_os_type==0 ){ OSVERSIONINFO sInfo; sInfo.dwOSVersionInfoSize = sizeof(sInfo); GetVersionEx(&sInfo); sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1; } return sqlite3_os_type==2; } /* ** Convert a UTF-8 string to UTF-32. Space to hold the returned string ** is obtained from sqliteMalloc. */ static WCHAR *utf8ToUnicode(const char *zFilename){ int nByte; WCHAR *zWideFilename; if( !isNT() ){ return 0; } nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0)*sizeof(WCHAR); zWideFilename = sqliteMalloc( nByte*sizeof(zWideFilename[0]) ); if( zWideFilename==0 ){ return 0; } nByte = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nByte); if( nByte==0 ){ sqliteFree(zWideFilename); zWideFilename = 0; } return zWideFilename; } /* ** Convert UTF-32 to UTF-8. Space to hold the returned string is ** obtained from sqliteMalloc(). */ static char *unicodeToUtf8(const WCHAR *zWideFilename){ int nByte; char *zFilename; nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); zFilename = sqliteMalloc( nByte ); if( zFilename==0 ){ return 0; } nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, 0, 0); if( nByte == 0 ){ sqliteFree(zFilename); zFilename = 0; } return zFilename; } /* ** Delete the named file */ int sqlite3OsDelete(const char *zFilename){ WCHAR *zWide = utf8ToUnicode(zFilename); if( zWide ){ DeleteFileW(zWide); sqliteFree(zWide); }else{ DeleteFileA(zFilename); } TRACE2("DELETE \"%s\"\n", zFilename); return SQLITE_OK; } /* ** Return TRUE if the named file exists. */ int sqlite3OsFileExists(const char *zFilename){ int exists = 0; WCHAR *zWide = utf8ToUnicode(zFilename); if( zWide ){ exists = GetFileAttributesW(zWide) != 0xffffffff; sqliteFree(zWide); }else{ exists = GetFileAttributesA(zFilename) != 0xffffffff; } return exists; } #ifndef _WIN32_WCE /* ** Attempt to open a file for both reading and writing. If that ** fails, try opening it read-only. If the file does not exist, ** try to create it. |
︙ | ︙ | |||
73 74 75 76 77 78 79 80 | */ int sqlite3OsOpenReadWrite( const char *zFilename, OsFile *id, int *pReadonly ){ HANDLE h; assert( !id->isOpen ); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | > > > > < < < | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | */ int sqlite3OsOpenReadWrite( const char *zFilename, OsFile *id, int *pReadonly ){ HANDLE h; WCHAR *zWide = utf8ToUnicode(zFilename); assert( !id->isOpen ); if( zWide ){ h = CreateFileW(zWide, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); if( h==INVALID_HANDLE_VALUE ){ h = CreateFileW(zWide, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); if( h==INVALID_HANDLE_VALUE ){ sqliteFree(zWide); return SQLITE_CANTOPEN; } *pReadonly = 1; }else{ *pReadonly = 0; } sqliteFree(zWide); }else{ h = CreateFileA(zFilename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); if( h==INVALID_HANDLE_VALUE ){ h = CreateFileA(zFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); if( h==INVALID_HANDLE_VALUE ){ return SQLITE_CANTOPEN; } *pReadonly = 1; }else{ *pReadonly = 0; } } id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; OpenCounter(+1); TRACE3("OPEN R/W %d \"%s\"\n", h, zFilename); |
︙ | ︙ | |||
125 126 127 128 129 130 131 132 133 134 135 136 137 138 | ** On success, write the file handle into *id and return SQLITE_OK. ** ** On failure, return SQLITE_CANTOPEN. */ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ HANDLE h; int fileflags; assert( !id->isOpen ); if( delFlag ){ fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_DELETE_ON_CLOSE; }else{ fileflags = FILE_FLAG_RANDOM_ACCESS; } | > > > > > > > > > > > > | | | | | | | | > | 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 | ** On success, write the file handle into *id and return SQLITE_OK. ** ** On failure, return SQLITE_CANTOPEN. */ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ HANDLE h; int fileflags; WCHAR *zWide = utf8ToUnicode(zFilename); assert( !id->isOpen ); if( delFlag ){ fileflags = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_DELETE_ON_CLOSE; }else{ fileflags = FILE_FLAG_RANDOM_ACCESS; } if( zWide ){ h = CreateFileW(zWide, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, fileflags, NULL ); sqliteFree(zWide); }else{ h = CreateFileA(zFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, fileflags, NULL ); } if( h==INVALID_HANDLE_VALUE ){ return SQLITE_CANTOPEN; } id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; |
︙ | ︙ | |||
161 162 163 164 165 166 167 168 | ** ** On success, write the file handle into *id and return SQLITE_OK. ** ** On failure, return SQLITE_CANTOPEN. */ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ HANDLE h; assert( !id->isOpen ); | > > > > > > > > > > > > | | | | | | | | > | | 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 | ** ** On success, write the file handle into *id and return SQLITE_OK. ** ** On failure, return SQLITE_CANTOPEN. */ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ HANDLE h; WCHAR *zWide = utf8ToUnicode(zFilename); assert( !id->isOpen ); if( zWide ){ h = CreateFileW(zWide, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); sqliteFree(zWide); }else{ h = CreateFileA(zFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL ); } if( h==INVALID_HANDLE_VALUE ){ return SQLITE_CANTOPEN; } id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; OpenCounter(+1); TRACE3("OPEN RO %d \"%s\"\n", h, zFilename); return SQLITE_OK; } #endif // _WIN32_WCE /* ** Attempt to open a file descriptor for the directory that contains a ** file. This file descriptor can be used to fsync() the directory ** in order to make sure the creation of a new file is actually written ** to disk. ** |
︙ | ︙ | |||
227 228 229 230 231 232 233 234 235 236 237 238 239 240 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; char zTempPath[SQLITE_TEMPNAME_SIZE]; if( sqlite3_temp_directory ){ strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30); zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0; }else{ GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath); } for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} zTempPath[i] = 0; for(;;){ sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath); | > > > > > > > > > > | 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i, j; char zTempPath[SQLITE_TEMPNAME_SIZE]; if( sqlite3_temp_directory ){ strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30); zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0; }else if( isNT() ){ char *zMulti; WCHAR zWidePath[SQLITE_TEMPNAME_SIZE]; GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath); zMulti = unicodeToUtf8(zWidePath); if( zMulti ){ strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30); zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0; sqliteFree(zMulti); } }else{ GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath); } for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){} zTempPath[i] = 0; for(;;){ sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath); |
︙ | ︙ | |||
259 260 261 262 263 264 265 | TRACE2("CLOSE %d\n", id->h); CloseHandle(id->h); OpenCounter(-1); id->isOpen = 0; } return SQLITE_OK; } | | | 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | TRACE2("CLOSE %d\n", id->h); CloseHandle(id->h); OpenCounter(-1); id->isOpen = 0; } return SQLITE_OK; } #endif // _WIN32_WCE /* ** Read data from a file into a buffer. Return SQLITE_OK if all ** bytes were read successfully and SQLITE_IOERR if anything goes ** wrong. */ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){ |
︙ | ︙ | |||
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | } if( !rc || amt>(int)wrote ){ return SQLITE_FULL; } return SQLITE_OK; } /* ** Move the read/write pointer in a file. */ int sqlite3OsSeek(OsFile *id, i64 offset){ LONG upperBits = offset>>32; LONG lowerBits = offset & 0xffffffff; DWORD rc; assert( id->isOpen ); SEEK(offset/1024 + 1); rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN); TRACE3("SEEK %d %lld\n", id->h, offset); return SQLITE_OK; } /* ** Make sure all writes to a particular file are committed to disk. */ | > > > > > > > > > > > > > | | 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 | } if( !rc || amt>(int)wrote ){ return SQLITE_FULL; } return SQLITE_OK; } /* ** Some microsoft compilers lack this definition. */ #ifndef INVALID_SET_FILE_POINTER # define INVALID_SET_FILE_POINTER ((DWORD)-1) #endif /* ** Move the read/write pointer in a file. */ int sqlite3OsSeek(OsFile *id, i64 offset){ LONG upperBits = offset>>32; LONG lowerBits = offset & 0xffffffff; DWORD rc; assert( id->isOpen ); #ifdef SQLITE_TEST if( offset ) SimulateDiskfullError #endif SEEK(offset/1024 + 1); rc = SetFilePointer(id->h, lowerBits, &upperBits, FILE_BEGIN); TRACE3("SEEK %d %lld\n", id->h, offset); if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){ return SQLITE_FULL; } return SQLITE_OK; } /* ** Make sure all writes to a particular file are committed to disk. */ int sqlite3OsSync(OsFile *id, int dataOnly){ assert( id->isOpen ); TRACE3("SYNC %d lock=%d\n", id->h, id->locktype); if( FlushFileBuffers(id->h) ){ return SQLITE_OK; }else{ return SQLITE_IOERR; } |
︙ | ︙ | |||
365 366 367 368 369 370 371 | SimulateIOError(SQLITE_IOERR); lowerBits = GetFileSize(id->h, &upperBits); *pSize = (((i64)upperBits)<<32) + lowerBits; return SQLITE_OK; } #ifndef _WIN32_WCE | < < < < < < < < < < < < < < < < < < < < < < | 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | SimulateIOError(SQLITE_IOERR); lowerBits = GetFileSize(id->h, &upperBits); *pSize = (((i64)upperBits)<<32) + lowerBits; return SQLITE_OK; } #ifndef _WIN32_WCE /* ** Acquire a reader lock. ** Different API routines are called depending on whether or not this ** is Win95 or WinNT. */ static int getReadLock(OsFile *id){ int res; |
︙ | ︙ | |||
427 428 429 430 431 432 433 | } #ifndef SQLITE_OMIT_PAGER_PRAGMAS /* ** Check that a given pathname is a directory and is writable ** */ | | > | | > > | > > > > | 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 | } #ifndef SQLITE_OMIT_PAGER_PRAGMAS /* ** Check that a given pathname is a directory and is writable ** */ int sqlite3OsIsDirWritable(char *zDirname){ int fileAttr; WCHAR *zWide; if( zDirname==0 ) return 0; if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0; zWide = utf8ToUnicode(zDirname); if( zWide ){ fileAttr = GetFileAttributesW(zWide); sqliteFree(zWide); }else{ fileAttr = GetFileAttributesA(zDirname); } if( fileAttr == 0xffffffff ) return 0; if( (fileAttr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ){ return 0; } return 1; } #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
︙ | ︙ | |||
632 633 634 635 636 637 638 | } if( type>=PENDING_LOCK ){ UnlockFile(id->h, PENDING_BYTE, 0, 1, 0); } id->locktype = locktype; return rc; } | > | > > > > > > > > > > > > | | | | > | 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 | } if( type>=PENDING_LOCK ){ UnlockFile(id->h, PENDING_BYTE, 0, 1, 0); } id->locktype = locktype; return rc; } #endif // _WIN32_WCE /* ** Turn a relative pathname into a full pathname. Return a pointer ** to the full pathname stored in space obtained from sqliteMalloc(). ** The calling function is responsible for freeing this space once it ** is no longer needed. */ char *sqlite3OsFullPathname(const char *zRelative){ char *zNotUsed; char *zFull; WCHAR *zWide; int nByte; #ifdef __CYGWIN__ nByte = strlen(zRelative) + MAX_PATH + 1001; zFull = sqliteMalloc( nByte ); if( zFull==0 ) return 0; if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0; #else zWide = utf8ToUnicode(zRelative); if( zWide ){ WCHAR *zTemp, *zNotUsedW; nByte = GetFullPathNameW(zWide, 0, 0, &zNotUsedW) + 1; zTemp = sqliteMalloc( nByte*sizeof(zTemp[0]) ); if( zTemp==0 ) return 0; GetFullPathNameW(zWide, nByte, zTemp, &zNotUsedW); sqliteFree(zWide); zFull = unicodeToUtf8(zTemp); sqliteFree(zTemp); }else{ nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1; zFull = sqliteMalloc( nByte*sizeof(zFull[0]) ); if( zFull==0 ) return 0; GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed); } #endif return zFull; } #endif /* SQLITE_OMIT_DISKIO */ /*************************************************************************** ** Everything above deals with file I/O. Everything that follows deals |
︙ | ︙ |
Changes to SQLite.Interop/src/os_win.h.
︙ | ︙ | |||
45 46 47 48 49 50 51 | #endif //_WIN32_WCE }; #define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) #define SQLITE_MIN_SLEEP_MS 1 | < | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #endif //_WIN32_WCE }; #define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) #define SQLITE_MIN_SLEEP_MS 1 /* ** This are WIN32 API functions not present in WinCE. ** They are implemented in the "os_wince.c" file. **/ #ifdef _WIN32_WCE # define DeleteFileA sqlitewce_DeleteFileA # define GetFileAttributesA sqlitewce_GetFileAttributesA |
︙ | ︙ | |||
73 74 75 76 77 78 79 | ** To avoid any problems I just use my own implementation. ** It should be safe, as this header is not included by normal ** programs, only by the SQLite library. **/ #if _WIN32_WCE >= 400 # define localtime sqlitewce_localtime #endif | < < | 72 73 74 75 76 77 78 79 | ** To avoid any problems I just use my own implementation. ** It should be safe, as this header is not included by normal ** programs, only by the SQLite library. **/ #if _WIN32_WCE >= 400 # define localtime sqlitewce_localtime #endif #endif /* _SQLITE_OS_WIN_H_ */ |
Changes to SQLite.Interop/src/os_wince.c.
︙ | ︙ | |||
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | ** This is needed for the command line version of sqlite to compile. **/ int isatty( int handle ) { UNREFERENCED_PARAMETER(handle); return 1; } /* ** Converts a relative path to an absolute path. ** There is no current directory concept on Windows CE, so we assume ** we are working always with absolute paths and simply copy ** the given path to the provided buffer. */ | > > > > > > | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | ** This is needed for the command line version of sqlite to compile. **/ int isatty( int handle ) { UNREFERENCED_PARAMETER(handle); return 1; } // Stubbed in WinCE DWORD WINAPI GetFullPathNameW(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart) { return 0; } /* ** Converts a relative path to an absolute path. ** There is no current directory concept on Windows CE, so we assume ** we are working always with absolute paths and simply copy ** the given path to the provided buffer. */ |
︙ | ︙ | |||
216 217 218 219 220 221 222 223 224 225 226 227 228 229 | ** NOTE: I'm not sure in what conditions this can turn into an infinite ** loop. I don't think it is possible without a serious bug in ** sqlite or windows, but i'm not sure of this. */ static void lock_file( OsFile *id ) { DWORD res; while ( 1 ) { res = WaitForSingleObject( id->hMux, INFINITE ); // I don't know very well what I have to do in this case. // The MSDN says that this case is when a thread terminates without // releasing the mutex. So I have to release it and try again if ( res == WAIT_ABANDONED ) | > > | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | ** NOTE: I'm not sure in what conditions this can turn into an infinite ** loop. I don't think it is possible without a serious bug in ** sqlite or windows, but i'm not sure of this. */ static void lock_file( OsFile *id ) { DWORD res; if (id->lockdata == NULL) return; while ( 1 ) { res = WaitForSingleObject( id->hMux, INFINITE ); // I don't know very well what I have to do in this case. // The MSDN says that this case is when a thread terminates without // releasing the mutex. So I have to release it and try again if ( res == WAIT_ABANDONED ) |
︙ | ︙ | |||
241 242 243 244 245 246 247 | /* ** Releases ownership of the file mutex. ** Always success */ static void unlock_file( OsFile *id ) { | > | > > | > | 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 | /* ** Releases ownership of the file mutex. ** Always success */ static void unlock_file( OsFile *id ) { if (id->hMux) ReleaseMutex( id->hMux ); } /* ** Acquire a lock on the file. ** Returns non-zero on success, zero on failure. */ static int getLock( OsFile *id, int locktype ) { int rc = 0; if (id->lockdata == NULL) return 1; lock_file( id ); if ( locktype == SHARED_LOCK ) { assert( id->lockdata->shared >= 0 ); ++id->lockdata->shared; /* Increment number of readers */ id->lockdata->lock |= 1 << SHARED_LOCK; } else |
︙ | ︙ | |||
278 279 280 281 282 283 284 | /* ** Releases lock on the file. ** Always succeeds, so no return value. */ static void unsetLock( OsFile *id, int locktype ) { assert( locktype >= SHARED_LOCK ); | > > | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | /* ** Releases lock on the file. ** Always succeeds, so no return value. */ static void unsetLock( OsFile *id, int locktype ) { assert( locktype >= SHARED_LOCK ); if (id->lockdata == NULL) return; lock_file( id ); if ( locktype == SHARED_LOCK ) { assert( id->lockdata->shared > 0 ); --id->lockdata->shared; /* Decrement number of readers */ if ( id->lockdata->shared == 0 ) /* Last reader? */ id->lockdata->lock &= ~(1 << SHARED_LOCK); } |
︙ | ︙ | |||
487 488 489 490 491 492 493 | id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; id->wFilename = wFilename; id->delOnClose = delFlag; #ifndef SQLITE_WCE_OMIT_FILELOCK | | | | < | 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; id->wFilename = wFilename; id->delOnClose = delFlag; #ifndef SQLITE_WCE_OMIT_FILELOCK id->lockdata = NULL; id->hMux = NULL; id->hMem = NULL; #endif OpenCounter(+1); TRACE3("OPEN EX %d \"%s\"\n", h, zFilename); return SQLITE_OK; } /* |
︙ | ︙ | |||
523 524 525 526 527 528 529 | id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; id->wFilename = wFilename; id->delOnClose = 0; #ifndef SQLITE_WCE_OMIT_FILELOCK | | | | < | 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | id->h = h; id->locktype = NO_LOCK; id->sharedLockByte = 0; id->isOpen = 1; id->wFilename = wFilename; id->delOnClose = 0; #ifndef SQLITE_WCE_OMIT_FILELOCK id->lockdata = NULL; id->hMux = NULL; id->hMem = NULL; #endif OpenCounter(+1); TRACE3("OPEN RO %d \"%s\"\n", h, zFilename); return SQLITE_OK; } /* |
︙ | ︙ |
Changes to SQLite.Interop/src/pager.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** ** @(#) $Id: pager.c,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include "os.h" #include "pager.h" #include <assert.h> #include <string.h> |
︙ | ︙ | |||
653 654 655 656 657 658 659 | rc = write32bits(&pPager->jfd, pPager->sectorSize); } /* The journal header has been written successfully. Seek the journal ** file descriptor to the end of the journal header sector. */ if( rc==SQLITE_OK ){ | | > | > | 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | rc = write32bits(&pPager->jfd, pPager->sectorSize); } /* The journal header has been written successfully. Seek the journal ** file descriptor to the end of the journal header sector. */ if( rc==SQLITE_OK ){ rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1); if( rc==SQLITE_OK ){ rc = sqlite3OsWrite(&pPager->jfd, "\000", 1); } } return rc; } /* ** The journal file must be open when this is called. A journal header file ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal |
︙ | ︙ | |||
1034 1035 1036 1037 1038 1039 1040 | ** page content is in the main journal either because the page is not in ** cache or else it is marked as needSync==0. */ pPg = pager_lookup(pPager, pgno); assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 ); TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno); if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){ | | > | > | 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | ** page content is in the main journal either because the page is not in ** cache or else it is marked as needSync==0. */ pPg = pager_lookup(pPager, pgno); assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 ); TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno); if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){ rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); if( rc==SQLITE_OK ){ rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize); } if( pPg ) pPg->dirty = 0; } if( pPg ){ /* No page should ever be explicitly rolled back that is in use, except ** for page 1 which is held in use in order to keep the lock on the ** database active. However such a page may be rolled back as a result ** of an internal error resulting in an automatic call to |
︙ | ︙ | |||
1164 1165 1166 1167 1168 1169 1170 | static int pager_reload_cache(Pager *pPager){ PgHdr *pPg; int rc = SQLITE_OK; for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){ char zBuf[SQLITE_MAX_PAGE_SIZE]; if( !pPg->dirty ) continue; if( (int)pPg->pgno <= pPager->origDbSize ){ | | > | > | 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 | static int pager_reload_cache(Pager *pPager){ PgHdr *pPg; int rc = SQLITE_OK; for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){ char zBuf[SQLITE_MAX_PAGE_SIZE]; if( !pPg->dirty ) continue; if( (int)pPg->pgno <= pPager->origDbSize ){ rc = sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1)); if( rc==SQLITE_OK ){ rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize); } TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno); if( rc ) break; CODEC(pPager, zBuf, pPg->pgno, 2); }else{ memset(zBuf, 0, pPager->pageSize); } if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){ |
︙ | ︙ | |||
1481 1482 1483 1484 1485 1486 1487 | } pPager->journalOff = szJ; end_stmt_playback: if( rc!=SQLITE_OK ){ pPager->errMask |= PAGER_ERR_CORRUPT; | | | 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 | } pPager->journalOff = szJ; end_stmt_playback: if( rc!=SQLITE_OK ){ pPager->errMask |= PAGER_ERR_CORRUPT; rc = SQLITE_CORRUPT; }else{ pPager->journalOff = szJ; /* pager_reload_cache(pPager); */ } return rc; } |
︙ | ︙ | |||
1742 1743 1744 1745 1746 1747 1748 | sqlite3OsSeek(&pPager->fd, 0); sqlite3OsRead(&pPager->fd, pDest, N); } } /* ** Return the total number of pages in the disk file associated with | | > > > > > | | | | | | | | | | | < < < | | > > > > | 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 | sqlite3OsSeek(&pPager->fd, 0); sqlite3OsRead(&pPager->fd, pDest, N); } } /* ** Return the total number of pages in the disk file associated with ** pPager. ** ** If the PENDING_BYTE lies on the page directly after the end of the ** file, then consider this page part of the file too. For example, if ** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the ** file is 4096 bytes, 5 is returned instead of 4. */ int sqlite3pager_pagecount(Pager *pPager){ i64 n; assert( pPager!=0 ); if( pPager->dbSize>=0 ){ n = pPager->dbSize; } else { if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){ pPager->errMask |= PAGER_ERR_DISK; return 0; } if( n>0 && n<pPager->pageSize ){ n = 1; }else{ n /= pPager->pageSize; } if( pPager->state!=PAGER_UNLOCK ){ pPager->dbSize = n; } } if( n==(PENDING_BYTE/pPager->pageSize) ){ n++; } return n; } /* ** Forward declaration */ |
︙ | ︙ | |||
2117 2118 2119 2120 2121 2122 2123 | /* Write the nRec value into the journal file header. If in ** full-synchronous mode, sync the journal first. This ensures that ** all data has really hit the disk before nRec is updated to mark ** it as a candidate for rollback. */ if( pPager->fullSync ){ TRACE2("SYNC journal of %d\n", PAGERID(pPager)); | | > | > | > | | 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 | /* Write the nRec value into the journal file header. If in ** full-synchronous mode, sync the journal first. This ensures that ** all data has really hit the disk before nRec is updated to mark ** it as a candidate for rollback. */ if( pPager->fullSync ){ TRACE2("SYNC journal of %d\n", PAGERID(pPager)); rc = sqlite3OsSync(&pPager->jfd, 0); if( rc!=0 ) return rc; } rc = sqlite3OsSeek(&pPager->jfd, pPager->journalHdr + sizeof(aJournalMagic)); if( rc ) return rc; rc = write32bits(&pPager->jfd, pPager->nRec); if( rc ) return rc; rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff); if( rc ) return rc; } TRACE2("SYNC journal of %d\n", PAGERID(pPager)); rc = sqlite3OsSync(&pPager->jfd, pPager->fullSync); if( rc!=0 ) return rc; pPager->journalStarted = 1; } pPager->needSync = 0; /* Erase the needSync flag from every page. */ |
︙ | ︙ | |||
2192 2193 2194 2195 2196 2197 2198 | rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK); if( rc!=SQLITE_OK ){ return rc; } while( pList ){ assert( pList->dirty ); | | > | 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 | rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK); if( rc!=SQLITE_OK ){ return rc; } while( pList ){ assert( pList->dirty ); rc = sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize); if( rc ) return rc; /* If there are dirty pages in the page cache with page numbers greater ** than Pager.dbSize, this means sqlite3pager_truncate() was called to ** make the file smaller (presumably by auto-vacuum code). Do not write ** any such pages to the file. */ if( pList->pgno<=pPager->dbSize ){ CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6); |
︙ | ︙ | |||
2287 2288 2289 2290 2291 2292 2293 | int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ PgHdr *pPg; int rc; /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page ** number greater than this, or zero, is requested. */ | | | | 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 | int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ PgHdr *pPg; int rc; /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page ** number greater than this, or zero, is requested. */ if( pgno>PAGER_MAX_PGNO || pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ return SQLITE_CORRUPT_BKPT; } /* Make sure we have not hit any critical errors. */ assert( pPager!=0 ); *ppPage = 0; if( pPager->errMask & ~(PAGER_ERR_FULL) ){ |
︙ | ︙ | |||
2502 2503 2504 2505 2506 2507 2508 | return rc; } if( sqlite3pager_pagecount(pPager)<(int)pgno ){ memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); }else{ int rc; assert( MEMDB==0 ); | | > | > | 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 | return rc; } if( sqlite3pager_pagecount(pPager)<(int)pgno ){ memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); }else{ int rc; assert( MEMDB==0 ); rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize); if( rc==SQLITE_OK ){ rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize); } TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno); CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); if( rc!=SQLITE_OK ){ i64 fileSize; if( sqlite3OsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK || fileSize>=pgno*pPager->pageSize ){ sqlite3pager_unref(PGHDR_TO_DATA(pPg)); |
︙ | ︙ | |||
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 | assert( pHist->pOrig==0 ); pHist->pOrig = sqliteMallocRaw( pPager->pageSize ); if( pHist->pOrig ){ memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize); } }else{ u32 cksum; CODEC(pPager, pData, pPg->pgno, 7); cksum = pager_cksum(pPager, pPg->pgno, pData); saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager); store32bits(cksum, pPg, pPager->pageSize); szPg = pPager->pageSize+8; store32bits(pPg->pgno, pPg, -4); rc = sqlite3OsWrite(&pPager->jfd, &((char*)pData)[-4], szPg); | > > > > | 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 | assert( pHist->pOrig==0 ); pHist->pOrig = sqliteMallocRaw( pPager->pageSize ); if( pHist->pOrig ){ memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize); } }else{ u32 cksum; /* We should never write to the journal file the page that ** contains the database locks. The following assert verifies ** that we do not. */ assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); CODEC(pPager, pData, pPg->pgno, 7); cksum = pager_cksum(pPager, pPg->pgno, pData); saved = *(u32*)PGHDR_TO_EXTRA(pPg, pPager); store32bits(cksum, pPg, pPager->pageSize); szPg = pPager->pageSize+8; store32bits(pPg->pgno, pPg, -4); rc = sqlite3OsWrite(&pPager->jfd, &((char*)pData)[-4], szPg); |
︙ | ︙ | |||
3167 3168 3169 3170 3171 3172 3173 | if( rc==SQLITE_OK ){ rc = rc2; } }else{ rc = pager_playback(pPager); } if( rc!=SQLITE_OK ){ | | | 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 | if( rc==SQLITE_OK ){ rc = rc2; } }else{ rc = pager_playback(pPager); } if( rc!=SQLITE_OK ){ rc = SQLITE_CORRUPT_BKPT; pPager->errMask |= PAGER_ERR_CORRUPT; } pPager->dbSize = -1; return rc; } /* |
︙ | ︙ | |||
3437 3438 3439 3440 3441 3442 3443 3444 | if( nTrunc!=0 ){ /* If this transaction has made the database smaller, then all pages ** being discarded by the truncation must be written to the journal ** file. */ Pgno i; void *pPage; for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ | > | | 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 | if( nTrunc!=0 ){ /* If this transaction has made the database smaller, then all pages ** being discarded by the truncation must be written to the journal ** file. */ Pgno i; void *pPage; int iSkip = PAGER_MJ_PGNO(pPager); for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){ rc = sqlite3pager_get(pPager, i, &pPage); if( rc!=SQLITE_OK ) goto sync_exit; rc = sqlite3pager_write(pPage); sqlite3pager_unref(pPage); if( rc!=SQLITE_OK ) goto sync_exit; } } |
︙ | ︙ | |||
3468 3469 3470 3471 3472 3473 3474 | /* Write all dirty pages to the database file */ pPg = pager_get_all_dirty_pages(pPager); rc = pager_write_pagelist(pPg); if( rc!=SQLITE_OK ) goto sync_exit; /* Sync the database file. */ if( !pPager->noSync ){ | | | 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 | /* Write all dirty pages to the database file */ pPg = pager_get_all_dirty_pages(pPager); rc = pager_write_pagelist(pPg); if( rc!=SQLITE_OK ) goto sync_exit; /* Sync the database file. */ if( !pPager->noSync ){ rc = sqlite3OsSync(&pPager->fd, 0); } pPager->state = PAGER_SYNCED; } sync_exit: return rc; |
︙ | ︙ |
Changes to SQLite.Interop/src/pager.h.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** | | | | 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 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** ** @(#) $Id: pager.h,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $ */ /* ** The default size of a database page. */ #ifndef SQLITE_DEFAULT_PAGE_SIZE # define SQLITE_DEFAULT_PAGE_SIZE 1024 #endif /* Maximum page size. The upper bound on this value is 32768. This a limit ** imposed by necessity of storing the value in a 2-byte unsigned integer ** and the fact that the page size must be a power of 2. ** ** This value is used to initialize certain arrays on the stack at ** various places in the code. On embedded machines where stack space ** is limited and the flexibility of having large pages is not needed, ** it makes good sense to reduce the maximum page size to something more ** reasonable, like 1024. */ #ifndef SQLITE_MAX_PAGE_SIZE # define SQLITE_MAX_PAGE_SIZE 32768 #endif /* ** Maximum number of pages in one database. */ #define SQLITE_MAX_PAGE 1073741823 |
︙ | ︙ |
Changes to SQLite.Interop/src/parse.c.
︙ | ︙ | |||
89 90 91 92 93 94 95 | ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. */ #define YYCODETYPE unsigned char | | | | | | | < < | | > > > | | | < | | | | | | 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 | ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. */ #define YYCODETYPE unsigned char #define YYNOCODE 247 #define YYACTIONTYPE unsigned short int #define sqlite3ParserTOKENTYPE Token typedef union { sqlite3ParserTOKENTYPE yy0; struct TrigEvent yy30; Expr* yy62; SrcList* yy151; Token yy198; struct LimitVal yy220; struct LikeOp yy222; IdList* yy240; int yy280; struct {int value; int mask;} yy359; TriggerStep* yy360; struct AttachKey yy361; Select* yy375; ExprList* yy418; int yy493; } YYMINORTYPE; #define YYSTACKDEPTH 100 #define sqlite3ParserARG_SDECL Parse *pParse; #define sqlite3ParserARG_PDECL ,Parse *pParse #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse #define sqlite3ParserARG_STORE yypParser->pParse = pParse #define YYNSTATE 581 #define YYNRULE 311 #define YYERRORSYMBOL 146 #define YYERRSYMDT yy493 #define YYFALLBACK 1 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) #define YY_ERROR_ACTION (YYNSTATE+YYNRULE) /* Next are that tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement |
︙ | ︙ | |||
171 172 173 174 175 176 177 | ** 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[] = { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < | | | | | | | | | | | > > > > > > > | | < < < < < < < | | > | | | | | > > | | | | | | | | < < < < | | | < < | < | | | > | | | | | | > > > | | | | | | | | < | | > | | | | | | | | | | | | | | | | | | | | | > | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | ** yy_shift_ofst[] For each state, the offset into yy_action for ** shifting terminals. ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. */ static const YYACTIONTYPE yy_action[] = { /* 0 */ 286, 584, 113, 140, 142, 138, 144, 581, 150, 152, /* 10 */ 154, 156, 158, 160, 162, 164, 166, 168, 3, 577, /* 20 */ 740, 170, 178, 150, 152, 154, 156, 158, 160, 162, /* 30 */ 164, 166, 168, 158, 160, 162, 164, 166, 168, 135, /* 40 */ 97, 171, 181, 186, 191, 180, 185, 146, 148, 140, /* 50 */ 142, 138, 144, 51, 150, 152, 154, 156, 158, 160, /* 60 */ 162, 164, 166, 168, 16, 17, 18, 114, 7, 248, /* 70 */ 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, /* 80 */ 13, 37, 362, 40, 59, 67, 69, 326, 357, 170, /* 90 */ 6, 5, 331, 95, 364, 359, 25, 374, 258, 893, /* 100 */ 1, 580, 514, 13, 4, 575, 33, 135, 97, 171, /* 110 */ 181, 186, 191, 180, 185, 146, 148, 140, 142, 138, /* 120 */ 144, 9, 150, 152, 154, 156, 158, 160, 162, 164, /* 130 */ 166, 168, 374, 136, 592, 80, 112, 99, 269, 34, /* 140 */ 32, 33, 132, 373, 115, 14, 15, 378, 333, 99, /* 150 */ 380, 387, 392, 13, 367, 370, 194, 170, 78, 500, /* 160 */ 525, 315, 395, 369, 375, 408, 10, 98, 14, 15, /* 170 */ 78, 200, 286, 864, 113, 135, 97, 171, 181, 186, /* 180 */ 191, 180, 185, 146, 148, 140, 142, 138, 144, 80, /* 190 */ 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, /* 200 */ 104, 105, 106, 661, 496, 376, 374, 170, 467, 13, /* 210 */ 2, 28, 237, 4, 409, 33, 3, 577, 14, 15, /* 220 */ 51, 132, 133, 115, 241, 135, 97, 171, 181, 186, /* 230 */ 191, 180, 185, 146, 148, 140, 142, 138, 144, 114, /* 240 */ 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, /* 250 */ 40, 59, 67, 69, 326, 357, 136, 44, 45, 501, /* 260 */ 473, 463, 359, 36, 361, 130, 128, 660, 275, 31, /* 270 */ 84, 99, 356, 378, 14, 15, 380, 387, 392, 52, /* 280 */ 170, 117, 122, 123, 113, 541, 369, 643, 395, 348, /* 290 */ 98, 54, 78, 200, 302, 57, 58, 819, 135, 97, /* 300 */ 171, 181, 186, 191, 180, 185, 146, 148, 140, 142, /* 310 */ 138, 144, 861, 150, 152, 154, 156, 158, 160, 162, /* 320 */ 164, 166, 168, 104, 105, 106, 817, 80, 48, 316, /* 330 */ 162, 164, 166, 168, 319, 277, 12, 49, 99, 303, /* 340 */ 283, 818, 99, 124, 304, 99, 241, 172, 593, 114, /* 350 */ 50, 193, 46, 378, 170, 13, 380, 387, 392, 78, /* 360 */ 260, 276, 47, 78, 200, 64, 78, 260, 395, 174, /* 370 */ 175, 221, 135, 97, 171, 181, 186, 191, 180, 185, /* 380 */ 146, 148, 140, 142, 138, 144, 199, 150, 152, 154, /* 390 */ 156, 158, 160, 162, 164, 166, 168, 173, 252, 261, /* 400 */ 120, 122, 123, 212, 170, 268, 254, 130, 128, 288, /* 410 */ 590, 176, 246, 187, 192, 414, 195, 241, 197, 198, /* 420 */ 14, 15, 135, 97, 171, 181, 186, 191, 180, 185, /* 430 */ 146, 148, 140, 142, 138, 144, 433, 150, 152, 154, /* 440 */ 156, 158, 160, 162, 164, 166, 168, 311, 99, 707, /* 450 */ 99, 422, 708, 417, 275, 81, 318, 598, 99, 219, /* 460 */ 13, 231, 124, 13, 176, 48, 187, 192, 20, 78, /* 470 */ 317, 78, 214, 195, 49, 197, 198, 462, 170, 78, /* 480 */ 200, 116, 27, 13, 410, 113, 591, 50, 80, 225, /* 490 */ 195, 11, 197, 198, 506, 235, 135, 97, 171, 181, /* 500 */ 186, 191, 180, 185, 146, 148, 140, 142, 138, 144, /* 510 */ 80, 150, 152, 154, 156, 158, 160, 162, 164, 166, /* 520 */ 168, 277, 215, 324, 606, 14, 15, 301, 14, 15, /* 530 */ 512, 13, 508, 240, 196, 486, 195, 685, 197, 198, /* 540 */ 22, 834, 445, 331, 462, 170, 444, 276, 14, 15, /* 550 */ 114, 468, 278, 394, 599, 280, 470, 288, 446, 680, /* 560 */ 13, 321, 404, 135, 97, 171, 181, 186, 191, 180, /* 570 */ 185, 146, 148, 140, 142, 138, 144, 80, 150, 152, /* 580 */ 154, 156, 158, 160, 162, 164, 166, 168, 74, 99, /* 590 */ 540, 366, 73, 99, 352, 289, 14, 15, 176, 333, /* 600 */ 187, 192, 486, 869, 359, 273, 283, 542, 543, 867, /* 610 */ 78, 500, 510, 170, 78, 323, 682, 176, 472, 187, /* 620 */ 192, 746, 118, 470, 119, 14, 15, 195, 346, 197, /* 630 */ 198, 135, 97, 171, 181, 186, 191, 180, 185, 146, /* 640 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, /* 650 */ 158, 160, 162, 164, 166, 168, 532, 334, 341, 343, /* 660 */ 841, 39, 195, 170, 197, 198, 78, 94, 124, 356, /* 670 */ 271, 353, 439, 441, 440, 544, 883, 428, 72, 862, /* 680 */ 288, 135, 97, 171, 181, 186, 191, 180, 185, 146, /* 690 */ 148, 140, 142, 138, 144, 13, 150, 152, 154, 156, /* 700 */ 158, 160, 162, 164, 166, 168, 195, 99, 197, 198, /* 710 */ 406, 330, 195, 170, 197, 198, 568, 405, 306, 195, /* 720 */ 42, 197, 198, 65, 195, 539, 197, 198, 78, 96, /* 730 */ 66, 135, 97, 171, 181, 186, 191, 180, 185, 146, /* 740 */ 148, 140, 142, 138, 144, 885, 150, 152, 154, 156, /* 750 */ 158, 160, 162, 164, 166, 168, 99, 740, 99, 298, /* 760 */ 14, 15, 272, 170, 13, 74, 572, 86, 600, 73, /* 770 */ 126, 127, 614, 709, 309, 478, 24, 78, 247, 78, /* 780 */ 111, 135, 97, 171, 181, 186, 191, 180, 185, 146, /* 790 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, /* 800 */ 158, 160, 162, 164, 166, 168, 99, 238, 113, 239, /* 810 */ 295, 26, 296, 170, 338, 337, 78, 137, 294, 320, /* 820 */ 347, 239, 348, 390, 211, 348, 30, 78, 139, 14, /* 830 */ 15, 135, 189, 171, 181, 186, 191, 180, 185, 146, /* 840 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, /* 850 */ 158, 160, 162, 164, 166, 168, 99, 80, 99, 372, /* 860 */ 399, 442, 348, 170, 298, 243, 78, 141, 363, 601, /* 870 */ 428, 437, 438, 114, 411, 269, 605, 78, 143, 78, /* 880 */ 145, 448, 97, 171, 181, 186, 191, 180, 185, 146, /* 890 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, /* 900 */ 158, 160, 162, 164, 166, 168, 99, 80, 99, 430, /* 910 */ 99, 296, 555, 170, 413, 856, 78, 147, 672, 457, /* 920 */ 352, 348, 298, 443, 465, 45, 35, 78, 149, 78, /* 930 */ 151, 78, 153, 171, 181, 186, 191, 180, 185, 146, /* 940 */ 148, 140, 142, 138, 144, 99, 150, 152, 154, 156, /* 950 */ 158, 160, 162, 164, 166, 168, 99, 459, 99, 29, /* 960 */ 79, 464, 183, 483, 71, 339, 78, 155, 709, 421, /* 970 */ 428, 79, 109, 99, 491, 71, 296, 78, 157, 78, /* 980 */ 159, 490, 243, 109, 99, 340, 99, 449, 857, 223, /* 990 */ 99, 460, 182, 709, 78, 161, 99, 349, 827, 136, /* 1000 */ 223, 99, 80, 201, 99, 78, 163, 78, 165, 507, /* 1010 */ 136, 78, 167, 42, 201, 38, 493, 78, 169, 569, /* 1020 */ 207, 205, 78, 177, 674, 78, 179, 477, 203, 76, /* 1030 */ 77, 207, 205, 98, 99, 84, 99, 42, 336, 203, /* 1040 */ 76, 77, 99, 43, 98, 41, 428, 79, 494, 80, /* 1050 */ 428, 71, 84, 99, 352, 78, 188, 78, 190, 109, /* 1060 */ 499, 428, 497, 78, 202, 60, 104, 105, 106, 107, /* 1070 */ 108, 209, 213, 99, 78, 204, 223, 104, 105, 106, /* 1080 */ 107, 108, 209, 213, 820, 509, 136, 53, 383, 511, /* 1090 */ 201, 99, 56, 61, 78, 206, 55, 428, 428, 889, /* 1100 */ 513, 99, 243, 99, 352, 99, 79, 207, 205, 312, /* 1110 */ 71, 99, 78, 208, 483, 203, 76, 77, 109, 533, /* 1120 */ 98, 497, 78, 220, 78, 222, 78, 232, 84, 99, /* 1130 */ 428, 353, 78, 234, 352, 223, 517, 521, 389, 99, /* 1140 */ 62, 530, 99, 64, 63, 136, 68, 529, 70, 201, /* 1150 */ 78, 236, 352, 104, 105, 106, 107, 108, 209, 213, /* 1160 */ 78, 249, 99, 78, 265, 877, 207, 205, 398, 527, /* 1170 */ 99, 615, 616, 313, 203, 76, 77, 99, 523, 98, /* 1180 */ 80, 353, 8, 78, 270, 99, 456, 19, 21, 23, /* 1190 */ 412, 78, 300, 75, 78, 310, 82, 84, 78, 365, /* 1200 */ 563, 83, 547, 99, 87, 553, 78, 393, 85, 557, /* 1210 */ 99, 353, 104, 105, 106, 107, 108, 209, 213, 99, /* 1220 */ 269, 536, 99, 467, 78, 434, 88, 266, 534, 353, /* 1230 */ 560, 78, 481, 566, 264, 89, 250, 90, 93, 91, /* 1240 */ 78, 485, 101, 78, 498, 92, 100, 102, 103, 110, /* 1250 */ 131, 121, 134, 125, 129, 168, 184, 242, 686, 687, /* 1260 */ 688, 210, 233, 218, 224, 216, 227, 226, 217, 229, /* 1270 */ 228, 230, 243, 251, 515, 519, 463, 245, 253, 244, /* 1280 */ 505, 257, 255, 256, 258, 84, 259, 262, 263, 239, /* 1290 */ 267, 279, 274, 281, 282, 299, 285, 292, 284, 287, /* 1300 */ 290, 293, 297, 305, 314, 291, 307, 322, 308, 325, /* 1310 */ 327, 345, 329, 328, 332, 350, 354, 330, 358, 335, /* 1320 */ 342, 379, 381, 382, 344, 351, 368, 385, 355, 371, /* 1330 */ 388, 360, 396, 397, 400, 401, 415, 54, 416, 386, /* 1340 */ 384, 391, 418, 402, 407, 419, 377, 420, 423, 424, /* 1350 */ 403, 426, 425, 427, 429, 435, 431, 849, 436, 854, /* 1360 */ 432, 855, 450, 447, 451, 452, 454, 453, 825, 455, /* 1370 */ 458, 826, 469, 461, 466, 747, 748, 848, 471, 464, /* 1380 */ 863, 480, 474, 475, 476, 482, 865, 479, 487, 484, /* 1390 */ 489, 488, 492, 866, 495, 868, 504, 679, 502, 681, /* 1400 */ 833, 875, 518, 503, 516, 739, 520, 524, 522, 742, /* 1410 */ 745, 531, 526, 835, 535, 528, 538, 537, 836, 837, /* 1420 */ 838, 839, 545, 546, 840, 550, 876, 556, 551, 878, /* 1430 */ 548, 549, 554, 879, 559, 882, 884, 562, 886, 561, /* 1440 */ 552, 558, 564, 567, 570, 565, 571, 887, 576, 574, /* 1450 */ 573, 888, 578, 559, 559, 579, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 28, 11, 30, 77, 78, 79, 80, 0, 82, 83, /* 10 */ 84, 85, 86, 87, 88, 89, 90, 91, 11, 12, /* 20 */ 11, 49, 81, 82, 83, 84, 85, 86, 87, 88, /* 30 */ 89, 90, 91, 86, 87, 88, 89, 90, 91, 67, /* 40 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, /* 50 */ 78, 79, 80, 69, 82, 83, 84, 85, 86, 87, /* 60 */ 88, 89, 90, 91, 17, 18, 19, 95, 11, 29, /* 70 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, /* 80 */ 30, 97, 98, 99, 100, 101, 102, 103, 104, 49, /* 90 */ 150, 151, 50, 53, 26, 111, 156, 155, 30, 147, /* 100 */ 148, 149, 162, 30, 152, 163, 164, 67, 68, 69, /* 110 */ 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 120 */ 80, 153, 82, 83, 84, 85, 86, 87, 88, 89, /* 130 */ 90, 91, 155, 65, 11, 195, 28, 155, 129, 165, /* 140 */ 163, 164, 168, 169, 170, 95, 96, 97, 106, 155, /* 150 */ 100, 101, 102, 30, 86, 87, 162, 49, 176, 177, /* 160 */ 220, 88, 112, 95, 187, 188, 154, 99, 95, 96, /* 170 */ 176, 177, 28, 21, 30, 67, 68, 69, 70, 71, /* 180 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 195, /* 190 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, /* 200 */ 132, 133, 134, 27, 222, 29, 155, 49, 56, 30, /* 210 */ 149, 160, 218, 152, 163, 164, 11, 12, 95, 96, /* 220 */ 69, 168, 169, 170, 230, 67, 68, 69, 70, 71, /* 230 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 95, /* 240 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, /* 250 */ 99, 100, 101, 102, 103, 104, 65, 192, 193, 107, /* 260 */ 108, 109, 111, 174, 175, 86, 87, 27, 29, 29, /* 270 */ 118, 155, 183, 97, 95, 96, 100, 101, 102, 99, /* 280 */ 49, 171, 172, 173, 30, 106, 95, 27, 112, 29, /* 290 */ 99, 111, 176, 177, 162, 17, 18, 139, 67, 68, /* 300 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, /* 310 */ 79, 80, 15, 82, 83, 84, 85, 86, 87, 88, /* 320 */ 89, 90, 91, 132, 133, 134, 21, 195, 22, 27, /* 330 */ 88, 89, 90, 91, 218, 96, 155, 31, 155, 207, /* 340 */ 208, 21, 155, 233, 212, 155, 230, 49, 11, 95, /* 350 */ 44, 26, 46, 97, 49, 30, 100, 101, 102, 176, /* 360 */ 177, 122, 56, 176, 177, 105, 176, 177, 112, 71, /* 370 */ 72, 140, 67, 68, 69, 70, 71, 72, 73, 74, /* 380 */ 75, 76, 77, 78, 79, 80, 27, 82, 83, 84, /* 390 */ 85, 86, 87, 88, 89, 90, 91, 99, 215, 216, /* 400 */ 171, 172, 173, 27, 49, 218, 216, 86, 87, 168, /* 410 */ 11, 223, 224, 225, 226, 24, 114, 230, 116, 117, /* 420 */ 95, 96, 67, 68, 69, 70, 71, 72, 73, 74, /* 430 */ 75, 76, 77, 78, 79, 80, 139, 82, 83, 84, /* 440 */ 85, 86, 87, 88, 89, 90, 91, 206, 155, 27, /* 450 */ 155, 60, 27, 62, 29, 162, 27, 11, 155, 139, /* 460 */ 30, 141, 233, 30, 223, 22, 225, 226, 154, 176, /* 470 */ 177, 176, 177, 114, 31, 116, 117, 162, 49, 176, /* 480 */ 177, 26, 26, 30, 28, 30, 11, 44, 195, 46, /* 490 */ 114, 16, 116, 117, 24, 140, 67, 68, 69, 70, /* 500 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, /* 510 */ 195, 82, 83, 84, 85, 86, 87, 88, 89, 90, /* 520 */ 91, 96, 227, 27, 11, 95, 96, 26, 95, 96, /* 530 */ 60, 30, 62, 230, 115, 220, 114, 118, 116, 117, /* 540 */ 154, 11, 32, 50, 162, 49, 36, 122, 95, 96, /* 550 */ 95, 236, 122, 178, 11, 122, 241, 168, 48, 11, /* 560 */ 30, 88, 69, 67, 68, 69, 70, 71, 72, 73, /* 570 */ 74, 75, 76, 77, 78, 79, 80, 195, 82, 83, /* 580 */ 84, 85, 86, 87, 88, 89, 90, 91, 115, 155, /* 590 */ 155, 27, 119, 155, 155, 206, 95, 96, 223, 106, /* 600 */ 225, 226, 220, 11, 111, 207, 208, 172, 173, 11, /* 610 */ 176, 177, 142, 49, 176, 177, 11, 223, 236, 225, /* 620 */ 226, 11, 27, 241, 29, 95, 96, 114, 189, 116, /* 630 */ 117, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 640 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, /* 650 */ 86, 87, 88, 89, 90, 91, 222, 107, 108, 109, /* 660 */ 11, 175, 114, 49, 116, 117, 176, 177, 233, 183, /* 670 */ 29, 232, 107, 108, 109, 26, 11, 155, 26, 15, /* 680 */ 168, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 690 */ 76, 77, 78, 79, 80, 30, 82, 83, 84, 85, /* 700 */ 86, 87, 88, 89, 90, 91, 114, 155, 116, 117, /* 710 */ 183, 184, 114, 49, 116, 117, 194, 190, 206, 114, /* 720 */ 106, 116, 117, 34, 114, 76, 116, 117, 176, 177, /* 730 */ 41, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 740 */ 76, 77, 78, 79, 80, 11, 82, 83, 84, 85, /* 750 */ 86, 87, 88, 89, 90, 91, 155, 11, 155, 155, /* 760 */ 95, 96, 121, 49, 30, 115, 244, 198, 11, 119, /* 770 */ 132, 133, 120, 28, 205, 29, 154, 176, 177, 176, /* 780 */ 177, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 790 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, /* 800 */ 86, 87, 88, 89, 90, 91, 155, 27, 30, 29, /* 810 */ 27, 157, 29, 49, 98, 99, 176, 177, 214, 27, /* 820 */ 27, 29, 29, 27, 162, 29, 27, 176, 177, 95, /* 830 */ 96, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 840 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, /* 850 */ 86, 87, 88, 89, 90, 91, 155, 195, 155, 167, /* 860 */ 27, 52, 29, 49, 155, 120, 176, 177, 176, 11, /* 870 */ 155, 58, 59, 95, 162, 129, 11, 176, 177, 176, /* 880 */ 177, 25, 68, 69, 70, 71, 72, 73, 74, 75, /* 890 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, /* 900 */ 86, 87, 88, 89, 90, 91, 155, 195, 155, 194, /* 910 */ 155, 29, 134, 49, 158, 106, 176, 177, 11, 27, /* 920 */ 155, 29, 155, 214, 192, 193, 166, 176, 177, 176, /* 930 */ 177, 176, 177, 69, 70, 71, 72, 73, 74, 75, /* 940 */ 76, 77, 78, 79, 80, 155, 82, 83, 84, 85, /* 950 */ 86, 87, 88, 89, 90, 91, 155, 101, 155, 161, /* 960 */ 26, 67, 69, 155, 30, 37, 176, 177, 106, 162, /* 970 */ 155, 26, 38, 155, 27, 30, 29, 176, 177, 176, /* 980 */ 177, 214, 120, 38, 155, 57, 155, 231, 106, 55, /* 990 */ 155, 235, 99, 11, 176, 177, 155, 232, 142, 65, /* 1000 */ 55, 155, 195, 69, 155, 176, 177, 176, 177, 194, /* 1010 */ 65, 176, 177, 106, 69, 155, 162, 176, 177, 64, /* 1020 */ 86, 87, 176, 177, 130, 176, 177, 219, 94, 95, /* 1030 */ 96, 86, 87, 99, 155, 118, 155, 106, 110, 94, /* 1040 */ 95, 96, 155, 39, 99, 178, 155, 26, 131, 195, /* 1050 */ 155, 30, 118, 155, 155, 176, 177, 176, 177, 38, /* 1060 */ 27, 155, 29, 176, 177, 51, 132, 133, 134, 135, /* 1070 */ 136, 137, 138, 155, 176, 177, 55, 132, 133, 134, /* 1080 */ 135, 136, 137, 138, 139, 194, 65, 178, 189, 194, /* 1090 */ 69, 155, 47, 179, 176, 177, 186, 155, 155, 144, /* 1100 */ 194, 155, 120, 155, 155, 155, 26, 86, 87, 88, /* 1110 */ 30, 155, 176, 177, 155, 94, 95, 96, 38, 27, /* 1120 */ 99, 29, 176, 177, 176, 177, 176, 177, 118, 155, /* 1130 */ 155, 232, 176, 177, 155, 55, 194, 194, 189, 155, /* 1140 */ 178, 131, 155, 105, 180, 65, 178, 162, 26, 69, /* 1150 */ 176, 177, 155, 132, 133, 134, 135, 136, 137, 138, /* 1160 */ 176, 177, 155, 176, 177, 11, 86, 87, 189, 194, /* 1170 */ 155, 120, 120, 155, 94, 95, 96, 155, 219, 99, /* 1180 */ 195, 232, 15, 176, 177, 155, 189, 20, 21, 22, /* 1190 */ 23, 176, 177, 197, 176, 177, 196, 118, 176, 177, /* 1200 */ 33, 195, 35, 155, 199, 51, 176, 177, 197, 42, /* 1210 */ 155, 232, 132, 133, 134, 135, 136, 137, 138, 155, /* 1220 */ 129, 54, 155, 56, 176, 177, 200, 126, 61, 232, /* 1230 */ 63, 176, 177, 66, 127, 201, 124, 202, 128, 203, /* 1240 */ 176, 177, 155, 176, 177, 204, 120, 120, 155, 26, /* 1250 */ 168, 27, 27, 234, 234, 91, 99, 155, 118, 118, /* 1260 */ 118, 26, 139, 21, 26, 228, 193, 27, 229, 155, /* 1270 */ 29, 27, 120, 125, 107, 108, 109, 159, 29, 155, /* 1280 */ 113, 104, 217, 179, 30, 118, 167, 217, 179, 29, /* 1290 */ 125, 155, 209, 155, 122, 106, 159, 123, 155, 155, /* 1300 */ 210, 26, 155, 27, 120, 211, 210, 27, 211, 178, /* 1310 */ 155, 26, 182, 181, 155, 217, 217, 184, 167, 185, /* 1320 */ 185, 155, 51, 26, 185, 179, 176, 27, 179, 176, /* 1330 */ 26, 186, 51, 26, 103, 155, 155, 111, 159, 178, /* 1340 */ 180, 178, 155, 181, 188, 159, 188, 28, 155, 159, /* 1350 */ 182, 238, 237, 106, 159, 45, 239, 15, 43, 106, /* 1360 */ 240, 106, 142, 52, 155, 159, 155, 106, 11, 26, /* 1370 */ 178, 142, 21, 15, 191, 130, 130, 11, 11, 67, /* 1380 */ 21, 76, 191, 155, 110, 200, 11, 155, 130, 76, /* 1390 */ 26, 155, 221, 11, 26, 11, 200, 11, 121, 11, /* 1400 */ 11, 11, 200, 155, 121, 11, 191, 200, 110, 11, /* 1410 */ 11, 26, 130, 11, 155, 221, 159, 155, 11, 11, /* 1420 */ 11, 11, 155, 27, 11, 28, 11, 40, 155, 11, /* 1430 */ 242, 168, 168, 11, 155, 11, 11, 159, 11, 155, /* 1440 */ 243, 242, 155, 24, 143, 159, 155, 11, 145, 245, /* 1450 */ 144, 11, 13, 246, 246, 14, }; #define YY_SHIFT_USE_DFLT (-75) static const short yy_shift_ofst[] = { /* 0 */ 205, 7, -75, -75, 1167, -10, 57, -75, 47, 475, /* 10 */ 399, 123, 337, -75, -75, -75, -75, -75, -75, 475, /* 20 */ 446, 475, 543, 475, 757, 456, 858, 453, 240, 799, /* 30 */ 865, 50, -75, 254, -75, -16, -75, 453, 151, -75, /* 40 */ 931, -75, 1004, 306, -75, -75, -75, -75, -75, -75, /* 50 */ -75, 180, 931, -75, 1045, -75, 278, -75, -75, 1014, /* 60 */ 689, 931, 1038, -75, -75, -75, -75, 931, -75, 1122, /* 70 */ 1080, 652, 473, -75, -75, 1080, 1051, 1052, -75, 934, /* 80 */ -75, 302, 1079, -75, 650, -75, 641, 1091, 1101, 1107, /* 90 */ 1112, 1110, -75, 1080, 40, 1080, 714, 1080, -75, 1126, /* 100 */ 453, 1127, 453, -75, -75, -75, -75, -75, -75, 1223, /* 110 */ 1080, 108, 254, -75, -75, 455, 321, 595, -75, 321, /* 120 */ 1224, -75, -75, -75, 638, -75, -75, -75, 638, -75, /* 130 */ -75, -75, -75, 1225, -75, 1080, -75, 814, 1080, -12, /* 140 */ 1080, -12, 1080, -12, 1080, -12, 1080, -74, 1080, -74, /* 150 */ 1080, -53, 1080, -53, 1080, -53, 1080, -53, 1080, 242, /* 160 */ 1080, 242, 1080, 1164, 1080, 1164, 1080, 1164, 1080, -75, /* 170 */ -75, 298, -75, -75, -75, -75, 1080, -59, 1080, -12, /* 180 */ -75, 893, -75, 1157, -75, -75, -75, 1080, 764, 1080, /* 190 */ -74, -75, 325, 934, 359, 419, 1140, 1141, 1142, -75, /* 200 */ 714, 1080, 864, 1080, -75, 1080, -75, 1080, -75, 1235, /* 210 */ 1079, 376, -75, 945, 158, 1123, 320, 1242, -75, 1080, /* 220 */ 231, 1080, 714, 1238, 443, 1240, -75, 1241, 453, 1244, /* 230 */ -75, 1080, 305, 1080, 355, 1080, 714, 780, -75, 1080, /* 240 */ -75, -75, 1152, 453, -75, -75, -75, 864, 1080, 714, /* 250 */ 1148, 1080, 1249, 1080, 1177, 689, -75, 1254, -75, -75, /* 260 */ 714, 1177, 689, -75, 1080, 714, 1165, 1080, 1260, 1080, /* 270 */ 714, -75, -75, 239, -75, -75, -75, 430, -75, 433, /* 280 */ -75, 1172, -75, 501, 1152, 144, 453, -75, -75, 1189, /* 290 */ 1174, -75, 1275, 453, 783, -75, 453, -75, -75, 1080, /* 300 */ 714, 1079, 422, 425, 1276, 144, 1189, 1174, -75, 1021, /* 310 */ -28, -75, -75, 1184, 73, -75, -75, 429, -75, 792, /* 320 */ -75, 1280, -75, 496, 931, -75, 453, 1285, -75, 42, /* 330 */ -75, 453, -75, 550, 928, -75, 716, -75, -75, -75, /* 340 */ -75, 928, -75, 928, -75, 453, 793, -75, 453, 1177, /* 350 */ 689, -75, -75, 1177, 689, -75, -75, 1254, -75, 1045, /* 360 */ -75, -75, 68, -75, 1080, 564, -75, 191, -75, -75, /* 370 */ 191, -75, -75, -75, -75, 176, 256, -75, 453, -75, /* 380 */ 1271, 1297, 453, 260, 1300, 931, -75, 1304, 453, 796, /* 390 */ 931, -75, 1080, 614, -75, 1281, 1307, 453, 833, 1231, /* 400 */ 453, 1285, -75, 493, 1226, -75, -75, -75, -75, -75, /* 410 */ 1079, 513, 856, 391, 453, 1152, -75, 453, 745, 1319, /* 420 */ 1079, 548, 453, 1152, 510, 565, 1247, 453, 1152, -75, /* 430 */ 1310, 297, 1342, 1080, 664, 1315, 813, -75, -75, 1253, /* 440 */ 1255, 809, 453, 882, -75, -75, 1311, -75, -75, 1220, /* 450 */ 453, 862, 1261, 453, 1343, 453, 892, 907, 1357, 1229, /* 460 */ 1358, 152, 592, 894, 306, -75, 1245, 1246, 1351, 1366, /* 470 */ 1367, 152, 1359, 1312, 453, 1274, 453, 746, 453, 1305, /* 480 */ 1080, 714, 1375, 1313, 1080, 714, 1258, 453, 1364, 453, /* 490 */ 947, -75, 917, 598, 1368, 1080, 1033, 1080, 714, 1382, /* 500 */ 714, 1277, 453, 9, 1384, 470, 453, 1386, 453, 1388, /* 510 */ 453, 1389, 453, 1390, 605, 1283, 453, 9, 1394, 1312, /* 520 */ 453, 1298, 453, 746, 1398, 1282, 453, 1364, 1010, 610, /* 530 */ 1385, 1080, 1092, 1399, 530, 1402, 453, 1152, 649, 179, /* 540 */ 1407, 1408, 1409, 1410, 453, 1396, 1413, 1387, 254, 1397, /* 550 */ 453, 1154, 1415, 778, 1418, 1422, -75, 1387, 453, 1424, /* 560 */ 665, 982, 1425, 734, 982, 1427, 1419, 453, 955, 1301, /* 570 */ 453, 1436, 1306, 1303, 453, 1440, -75, 1439, 1441, -75, /* 580 */ -75, }; #define YY_REDUCE_USE_DFLT (-61) static const short yy_reduce_ofst[] = { /* 0 */ -48, 61, -61, -61, -60, -61, -61, -61, -32, 12, /* 10 */ -61, 181, -61, -61, -61, -61, -61, -61, -61, 314, /* 20 */ -61, 386, -61, 622, -61, 654, -61, 51, 798, -61, /* 30 */ -61, -23, -61, -26, 760, 89, -61, 860, 486, -61, /* 40 */ 867, -61, -61, 65, -61, -61, -61, -61, -61, -61, /* 50 */ -61, -61, 909, -61, 910, -61, -61, -61, -61, -61, /* 60 */ 914, 962, 964, -61, -61, -61, -61, 968, -61, -61, /* 70 */ 438, -61, 996, -61, -61, 116, -61, -61, -61, 293, /* 80 */ -61, 1000, 1006, -61, 1011, 569, 1005, 1026, 1034, 1035, /* 90 */ 1036, 1041, -61, 490, 394, 552, 394, 601, -61, -61, /* 100 */ 1087, -61, 1093, -61, -61, -61, -61, -61, -61, -61, /* 110 */ 603, 394, 53, -61, -61, 1082, 110, -61, -61, 229, /* 120 */ -61, -61, -61, -61, 1019, -61, -61, -61, 1020, -61, /* 130 */ -61, -61, -61, -61, -61, 640, -61, 394, 651, 394, /* 140 */ 690, 394, 701, 394, 703, 394, 740, 394, 751, 394, /* 150 */ 753, 394, 755, 394, 790, 394, 801, 394, 803, 394, /* 160 */ 818, 394, 829, 394, 831, 394, 835, 394, 841, 394, /* 170 */ -61, -61, -61, -61, -61, -61, 846, 188, 849, 394, /* 180 */ -61, -61, -61, -61, -61, -61, -61, 879, 394, 881, /* 190 */ 394, -61, 1102, -6, 1000, -61, -61, -61, -61, -61, /* 200 */ 394, 887, 394, 898, 394, 918, 394, 936, 394, -61, /* 210 */ 662, 1000, -61, 295, 394, 1037, 1039, -61, -61, 946, /* 220 */ 394, 948, 394, -61, 1073, -61, -61, -61, 1114, -61, /* 230 */ -61, 950, 394, 956, 394, 974, 394, -61, -61, 303, /* 240 */ -61, -61, 1118, 1124, -61, -61, -61, 394, 984, 394, /* 250 */ -61, 183, -61, 190, 1065, 1104, -61, 1119, -61, -61, /* 260 */ 394, 1070, 1109, -61, 987, 394, -61, 187, -61, 1007, /* 270 */ 394, -61, 398, 1083, -61, -61, -61, 1136, -61, 1138, /* 280 */ -61, -61, -61, 1143, 1137, 389, 1144, -61, -61, 1090, /* 290 */ 1094, -61, -61, 604, -61, -61, 1147, -61, -61, 1015, /* 300 */ 394, 132, 1000, 1083, -61, 512, 1096, 1097, -61, 1018, /* 310 */ 241, -61, -61, -61, 1087, -61, -61, 394, -61, -61, /* 320 */ -61, -61, -61, 394, 1131, -61, 1155, 1132, 1130, 1133, /* 330 */ -61, 1159, -61, -61, 1134, -61, -61, -61, -61, -61, /* 340 */ -61, 1135, -61, 1139, -61, 439, -61, -61, 765, 1098, /* 350 */ 1146, -61, -61, 1099, 1149, -61, -61, 1151, -61, 1145, /* 360 */ -61, -61, 692, -61, 1022, 394, -61, 1150, -61, -61, /* 370 */ 1153, -61, -61, -61, -61, 1156, 1158, -61, 1166, -61, /* 380 */ -61, -61, 899, 1160, -61, 1161, -61, -61, 949, -61, /* 390 */ 1163, -61, 1030, 375, -61, -61, -61, 979, -61, -61, /* 400 */ 1180, 1162, 1168, 527, -61, -61, -61, -61, -61, -61, /* 410 */ 712, 1000, 756, -61, 1181, 1179, -61, 1187, 1186, -61, /* 420 */ 807, 1000, 1193, 1190, 1115, 1113, -61, 715, 1195, -61, /* 430 */ 1117, 1120, -61, 1048, 394, -61, -61, -61, -61, -61, /* 440 */ -61, -61, 709, -61, -61, -61, -61, -61, -61, -61, /* 450 */ 1209, 1206, -61, 1211, -61, 997, -61, 1192, -61, -61, /* 460 */ -61, 315, 1000, 1183, 732, -61, -61, -61, -61, -61, /* 470 */ -61, 382, -61, 1191, 1228, -61, 808, 1185, 1232, -61, /* 480 */ 1055, 394, -61, -61, 1064, 394, -61, 1236, 1171, 767, /* 490 */ -61, -61, 854, 1000, -61, -18, -61, 1067, 394, -61, /* 500 */ 394, -61, 1248, 1196, -61, -61, 815, -61, 891, -61, /* 510 */ 895, -61, 906, -61, 1000, -61, 942, 1202, -61, 1215, /* 520 */ 943, -61, 959, 1207, -61, -61, 975, 1194, 985, 1000, /* 530 */ -61, 434, -61, -61, 1259, -61, 1262, 1257, -61, 435, /* 540 */ -61, -61, -61, -61, 1267, -61, -61, 1188, 1263, -61, /* 550 */ 1273, 1197, -61, 1264, -61, -61, -61, 1199, 1279, -61, /* 560 */ 1284, 1278, -61, 1287, 1286, -61, -61, 522, -61, -61, /* 570 */ 1291, -61, -61, 1204, -58, -61, -61, -61, -61, -61, /* 580 */ -61, }; static const YYACTIONTYPE yy_default[] = { /* 0 */ 587, 587, 582, 585, 892, 892, 892, 586, 594, 892, /* 10 */ 892, 892, 892, 614, 615, 616, 595, 596, 597, 892, /* 20 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, /* 30 */ 892, 892, 607, 617, 627, 609, 626, 892, 892, 628, /* 40 */ 672, 635, 892, 892, 673, 676, 677, 678, 872, 873, /* 50 */ 874, 892, 672, 636, 657, 655, 892, 658, 659, 892, /* 60 */ 728, 672, 643, 637, 644, 726, 727, 672, 638, 892, /* 70 */ 892, 758, 692, 690, 691, 824, 764, 759, 755, 892, /* 80 */ 683, 892, 892, 684, 692, 694, 701, 740, 731, 733, /* 90 */ 721, 735, 689, 892, 736, 892, 737, 892, 757, 892, /* 100 */ 892, 760, 892, 761, 762, 763, 765, 766, 767, 892, /* 110 */ 892, 892, 892, 612, 613, 619, 847, 892, 620, 847, /* 120 */ 892, 621, 624, 625, 892, 842, 844, 845, 892, 843, /* 130 */ 846, 623, 622, 892, 768, 892, 771, 773, 892, 774, /* 140 */ 892, 775, 892, 776, 892, 777, 892, 778, 892, 779, /* 150 */ 892, 780, 892, 781, 892, 782, 892, 783, 892, 784, /* 160 */ 892, 785, 892, 786, 892, 787, 892, 788, 892, 789, /* 170 */ 790, 892, 791, 798, 805, 808, 892, 793, 892, 792, /* 180 */ 795, 892, 796, 892, 799, 797, 804, 892, 892, 892, /* 190 */ 806, 807, 892, 824, 892, 892, 892, 892, 892, 811, /* 200 */ 823, 892, 800, 892, 801, 892, 802, 892, 803, 892, /* 210 */ 892, 892, 813, 892, 892, 892, 892, 892, 814, 892, /* 220 */ 892, 892, 815, 892, 892, 892, 870, 892, 892, 892, /* 230 */ 871, 892, 892, 892, 892, 892, 816, 892, 809, 824, /* 240 */ 821, 822, 709, 892, 710, 812, 794, 772, 892, 738, /* 250 */ 892, 892, 722, 892, 729, 728, 723, 892, 611, 730, /* 260 */ 725, 729, 728, 724, 892, 734, 892, 824, 732, 892, /* 270 */ 741, 693, 704, 702, 703, 712, 713, 892, 714, 892, /* 280 */ 715, 892, 716, 892, 709, 700, 892, 698, 699, 718, /* 290 */ 720, 705, 892, 892, 892, 719, 892, 753, 754, 892, /* 300 */ 717, 704, 892, 892, 892, 700, 718, 720, 706, 892, /* 310 */ 700, 695, 696, 892, 892, 697, 810, 892, 756, 892, /* 320 */ 769, 892, 770, 892, 672, 639, 892, 828, 645, 640, /* 330 */ 646, 892, 647, 892, 892, 648, 892, 651, 652, 653, /* 340 */ 654, 892, 649, 892, 650, 892, 892, 829, 892, 729, /* 350 */ 728, 830, 832, 729, 728, 831, 641, 892, 642, 657, /* 360 */ 656, 629, 892, 630, 892, 892, 631, 892, 632, 764, /* 370 */ 892, 633, 634, 618, 610, 892, 892, 662, 892, 665, /* 380 */ 892, 892, 892, 892, 892, 672, 666, 892, 892, 892, /* 390 */ 672, 667, 892, 672, 668, 892, 892, 892, 892, 892, /* 400 */ 892, 828, 645, 670, 892, 669, 671, 663, 664, 608, /* 410 */ 892, 892, 604, 892, 892, 709, 602, 892, 892, 892, /* 420 */ 892, 892, 892, 709, 853, 892, 892, 892, 709, 711, /* 430 */ 858, 892, 892, 892, 892, 892, 892, 859, 860, 892, /* 440 */ 892, 892, 892, 892, 850, 851, 892, 852, 603, 892, /* 450 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, /* 460 */ 892, 892, 892, 892, 892, 675, 892, 892, 892, 892, /* 470 */ 892, 892, 892, 674, 892, 892, 892, 892, 892, 892, /* 480 */ 892, 743, 892, 892, 892, 744, 892, 892, 751, 892, /* 490 */ 892, 752, 892, 892, 892, 892, 892, 892, 749, 892, /* 500 */ 750, 892, 892, 892, 892, 892, 892, 892, 892, 892, /* 510 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 674, /* 520 */ 892, 892, 892, 892, 892, 892, 892, 751, 892, 892, /* 530 */ 892, 892, 892, 892, 892, 892, 892, 709, 892, 847, /* 540 */ 892, 892, 892, 892, 892, 892, 892, 881, 892, 892, /* 550 */ 892, 892, 892, 892, 892, 892, 880, 881, 892, 892, /* 560 */ 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, /* 570 */ 892, 892, 892, 890, 892, 892, 891, 588, 892, 589, /* 580 */ 583, }; #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) /* The next table maps tokens into fallback tokens. If a construct ** like the following: ** ** %fallback ID X Y Z. |
︙ | ︙ | |||
675 676 677 678 679 680 681 682 683 | 0, /* ILLEGAL => nothing */ 0, /* SPACE => nothing */ 0, /* UNCLOSED_STRING => nothing */ 0, /* COMMENT => nothing */ 0, /* FUNCTION => nothing */ 0, /* COLUMN => nothing */ 0, /* AGG_FUNCTION => nothing */ 0, /* CONST_FUNC => nothing */ 0, /* SEMI => nothing */ | > | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | 0, /* ILLEGAL => nothing */ 0, /* SPACE => nothing */ 0, /* UNCLOSED_STRING => nothing */ 0, /* COMMENT => nothing */ 0, /* FUNCTION => nothing */ 0, /* COLUMN => nothing */ 0, /* AGG_FUNCTION => nothing */ 0, /* AGG_COLUMN => nothing */ 0, /* CONST_FUNC => nothing */ 0, /* SEMI => nothing */ 30, /* EXPLAIN => ID */ 30, /* QUERY => ID */ 30, /* PLAN => ID */ 30, /* BEGIN => ID */ 0, /* TRANSACTION => nothing */ 30, /* DEFERRED => ID */ 30, /* IMMEDIATE => ID */ 30, /* EXCLUSIVE => ID */ 0, /* COMMIT => nothing */ 30, /* END => ID */ 0, /* ROLLBACK => nothing */ 0, /* CREATE => nothing */ 0, /* TABLE => nothing */ 30, /* TEMP => ID */ 0, /* LP => nothing */ 0, /* RP => nothing */ 0, /* AS => nothing */ 0, /* COMMA => nothing */ 0, /* ID => nothing */ 30, /* ABORT => ID */ 30, /* AFTER => ID */ 30, /* ANALYZE => ID */ 30, /* ASC => ID */ 30, /* ATTACH => ID */ 30, /* BEFORE => ID */ 30, /* CASCADE => ID */ 30, /* CAST => ID */ 30, /* CONFLICT => ID */ 30, /* DATABASE => ID */ 30, /* DESC => ID */ 30, /* DETACH => ID */ 30, /* EACH => ID */ 30, /* FAIL => ID */ 30, /* FOR => ID */ 30, /* IGNORE => ID */ 30, /* INITIALLY => ID */ 30, /* INSTEAD => ID */ 30, /* LIKE_KW => ID */ 30, /* MATCH => ID */ 30, /* KEY => ID */ 30, /* OF => ID */ 30, /* OFFSET => ID */ 30, /* PRAGMA => ID */ 30, /* RAISE => ID */ 30, /* REPLACE => ID */ 30, /* RESTRICT => ID */ 30, /* ROW => ID */ 30, /* STATEMENT => ID */ 30, /* TRIGGER => ID */ 30, /* VACUUM => ID */ 30, /* VIEW => ID */ 30, /* REINDEX => ID */ 30, /* RENAME => ID */ 30, /* CTIME_KW => ID */ 30, /* ALTER => ID */ 0, /* OR => nothing */ 0, /* AND => nothing */ 0, /* NOT => nothing */ 0, /* IS => nothing */ 0, /* BETWEEN => nothing */ 0, /* IN => nothing */ 0, /* ISNULL => nothing */ |
︙ | ︙ | |||
881 882 883 884 885 886 887 | #ifndef NDEBUG /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { "$", "END_OF_FILE", "ILLEGAL", "SPACE", "UNCLOSED_STRING", "COMMENT", "FUNCTION", "COLUMN", | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | < | | | | | | > | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | < | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | | > | | | | | | | | | < | | | | > | | | | | | | | | | | | | | | | | | | | | | | < | > | | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | > | | | | | | | | < | | | | | | | > | | | | | | | | | | | | | | < | | > | | < | | | | | | | | | > | | | | | | 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 | #ifndef NDEBUG /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { "$", "END_OF_FILE", "ILLEGAL", "SPACE", "UNCLOSED_STRING", "COMMENT", "FUNCTION", "COLUMN", "AGG_FUNCTION", "AGG_COLUMN", "CONST_FUNC", "SEMI", "EXPLAIN", "QUERY", "PLAN", "BEGIN", "TRANSACTION", "DEFERRED", "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END", "ROLLBACK", "CREATE", "TABLE", "TEMP", "LP", "RP", "AS", "COMMA", "ID", "ABORT", "AFTER", "ANALYZE", "ASC", "ATTACH", "BEFORE", "CASCADE", "CAST", "CONFLICT", "DATABASE", "DESC", "DETACH", "EACH", "FAIL", "FOR", "IGNORE", "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH", "KEY", "OF", "OFFSET", "PRAGMA", "RAISE", "REPLACE", "RESTRICT", "ROW", "STATEMENT", "TRIGGER", "VACUUM", "VIEW", "REINDEX", "RENAME", "CTIME_KW", "ALTER", "OR", "AND", "NOT", "IS", "BETWEEN", "IN", "ISNULL", "NOTNULL", "NE", "EQ", "GT", "LE", "LT", "GE", "ESCAPE", "BITAND", "BITOR", "LSHIFT", "RSHIFT", "PLUS", "MINUS", "STAR", "SLASH", "REM", "CONCAT", "UMINUS", "UPLUS", "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL", "PRIMARY", "UNIQUE", "CHECK", "REFERENCES", "COLLATE", "AUTOINCR", "ON", "DELETE", "UPDATE", "INSERT", "SET", "DEFERRABLE", "FOREIGN", "DROP", "UNION", "ALL", "INTERSECT", "EXCEPT", "SELECT", "DISTINCT", "DOT", "FROM", "JOIN", "USING", "ORDER", "BY", "GROUP", "HAVING", "LIMIT", "WHERE", "INTO", "VALUES", "INTEGER", "FLOAT", "BLOB", "REGISTER", "VARIABLE", "EXISTS", "CASE", "WHEN", "THEN", "ELSE", "INDEX", "TO", "ADD", "COLUMNKW", "error", "input", "cmdlist", "ecmd", "cmdx", "cmd", "explain", "transtype", "trans_opt", "nm", "create_table", "create_table_args", "temp", "dbnm", "columnlist", "conslist_opt", "select", "column", "columnid", "type", "carglist", "id", "ids", "typetoken", "typename", "signed", "plus_num", "minus_num", "carg", "ccons", "term", "expr", "onconf", "sortorder", "autoinc", "idxlist_opt", "refargs", "defer_subclause", "refarg", "refact", "init_deferred_pred_opt", "conslist", "tcons", "idxlist", "defer_subclause_opt", "orconf", "resolvetype", "raisetype", "fullname", "oneselect", "multiselect_op", "distinct", "selcollist", "from", "where_opt", "groupby_opt", "having_opt", "orderby_opt", "limit_opt", "sclp", "as", "seltablist", "stl_prefix", "joinop", "on_opt", "using_opt", "seltablist_paren", "joinop2", "inscollist", "sortlist", "sortitem", "collate", "exprlist", "setlist", "insert_cmd", "inscollist_opt", "itemlist", "likeop", "escape", "between_op", "in_op", "case_operand", "case_exprlist", "case_else", "expritem", "uniqueflag", "idxitem", "plus_opt", "number", "trigger_decl", "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause", "when_clause", "trigger_cmd", "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt", }; #endif /* NDEBUG */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. */ static const char *const yyRuleName[] = { /* 0 */ "input ::= cmdlist", /* 1 */ "cmdlist ::= cmdlist ecmd", /* 2 */ "cmdlist ::= ecmd", /* 3 */ "cmdx ::= cmd", /* 4 */ "ecmd ::= SEMI", /* 5 */ "ecmd ::= explain cmdx SEMI", /* 6 */ "explain ::=", /* 7 */ "explain ::= EXPLAIN", /* 8 */ "explain ::= EXPLAIN QUERY PLAN", /* 9 */ "cmd ::= BEGIN transtype trans_opt", /* 10 */ "trans_opt ::=", /* 11 */ "trans_opt ::= TRANSACTION", /* 12 */ "trans_opt ::= TRANSACTION nm", /* 13 */ "transtype ::=", /* 14 */ "transtype ::= DEFERRED", /* 15 */ "transtype ::= IMMEDIATE", /* 16 */ "transtype ::= EXCLUSIVE", /* 17 */ "cmd ::= COMMIT trans_opt", /* 18 */ "cmd ::= END trans_opt", /* 19 */ "cmd ::= ROLLBACK trans_opt", /* 20 */ "cmd ::= create_table create_table_args", /* 21 */ "create_table ::= CREATE temp TABLE nm dbnm", /* 22 */ "temp ::= TEMP", /* 23 */ "temp ::=", /* 24 */ "create_table_args ::= LP columnlist conslist_opt RP", /* 25 */ "create_table_args ::= AS select", /* 26 */ "columnlist ::= columnlist COMMA column", /* 27 */ "columnlist ::= column", /* 28 */ "column ::= columnid type carglist", /* 29 */ "columnid ::= nm", /* 30 */ "id ::= ID", /* 31 */ "ids ::= ID", /* 32 */ "ids ::= STRING", /* 33 */ "nm ::= ID", /* 34 */ "nm ::= STRING", /* 35 */ "nm ::= JOIN_KW", /* 36 */ "type ::=", /* 37 */ "type ::= typetoken", /* 38 */ "typetoken ::= typename", /* 39 */ "typetoken ::= typename LP signed RP", /* 40 */ "typetoken ::= typename LP signed COMMA signed RP", /* 41 */ "typename ::= ids", /* 42 */ "typename ::= typename ids", /* 43 */ "signed ::= plus_num", /* 44 */ "signed ::= minus_num", /* 45 */ "carglist ::= carglist carg", /* 46 */ "carglist ::=", /* 47 */ "carg ::= CONSTRAINT nm ccons", /* 48 */ "carg ::= ccons", /* 49 */ "carg ::= DEFAULT term", /* 50 */ "carg ::= DEFAULT LP expr RP", /* 51 */ "carg ::= DEFAULT PLUS term", /* 52 */ "carg ::= DEFAULT MINUS term", /* 53 */ "carg ::= DEFAULT id", /* 54 */ "ccons ::= NULL onconf", /* 55 */ "ccons ::= NOT NULL onconf", /* 56 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", /* 57 */ "ccons ::= UNIQUE onconf", /* 58 */ "ccons ::= CHECK LP expr RP onconf", /* 59 */ "ccons ::= REFERENCES nm idxlist_opt refargs", /* 60 */ "ccons ::= defer_subclause", /* 61 */ "ccons ::= COLLATE id", /* 62 */ "autoinc ::=", /* 63 */ "autoinc ::= AUTOINCR", /* 64 */ "refargs ::=", /* 65 */ "refargs ::= refargs refarg", /* 66 */ "refarg ::= MATCH nm", /* 67 */ "refarg ::= ON DELETE refact", /* 68 */ "refarg ::= ON UPDATE refact", /* 69 */ "refarg ::= ON INSERT refact", /* 70 */ "refact ::= SET NULL", /* 71 */ "refact ::= SET DEFAULT", /* 72 */ "refact ::= CASCADE", /* 73 */ "refact ::= RESTRICT", /* 74 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", /* 75 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", /* 76 */ "init_deferred_pred_opt ::=", /* 77 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", /* 78 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", /* 79 */ "conslist_opt ::=", /* 80 */ "conslist_opt ::= COMMA conslist", /* 81 */ "conslist ::= conslist COMMA tcons", /* 82 */ "conslist ::= conslist tcons", /* 83 */ "conslist ::= tcons", /* 84 */ "tcons ::= CONSTRAINT nm", /* 85 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", /* 86 */ "tcons ::= UNIQUE LP idxlist RP onconf", /* 87 */ "tcons ::= CHECK expr onconf", /* 88 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", /* 89 */ "defer_subclause_opt ::=", /* 90 */ "defer_subclause_opt ::= defer_subclause", /* 91 */ "onconf ::=", /* 92 */ "onconf ::= ON CONFLICT resolvetype", /* 93 */ "orconf ::=", /* 94 */ "orconf ::= OR resolvetype", /* 95 */ "resolvetype ::= raisetype", /* 96 */ "resolvetype ::= IGNORE", /* 97 */ "resolvetype ::= REPLACE", /* 98 */ "cmd ::= DROP TABLE fullname", /* 99 */ "cmd ::= CREATE temp VIEW nm dbnm AS select", /* 100 */ "cmd ::= DROP VIEW fullname", /* 101 */ "cmd ::= select", /* 102 */ "select ::= oneselect", /* 103 */ "select ::= select multiselect_op oneselect", /* 104 */ "multiselect_op ::= UNION", /* 105 */ "multiselect_op ::= UNION ALL", /* 106 */ "multiselect_op ::= INTERSECT", /* 107 */ "multiselect_op ::= EXCEPT", /* 108 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", /* 109 */ "distinct ::= DISTINCT", /* 110 */ "distinct ::= ALL", /* 111 */ "distinct ::=", /* 112 */ "sclp ::= selcollist COMMA", /* 113 */ "sclp ::=", /* 114 */ "selcollist ::= sclp expr as", /* 115 */ "selcollist ::= sclp STAR", /* 116 */ "selcollist ::= sclp nm DOT STAR", /* 117 */ "as ::= AS nm", /* 118 */ "as ::= ids", /* 119 */ "as ::=", /* 120 */ "from ::=", /* 121 */ "from ::= FROM seltablist", /* 122 */ "stl_prefix ::= seltablist joinop", /* 123 */ "stl_prefix ::=", /* 124 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt", /* 125 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt", /* 126 */ "seltablist_paren ::= select", /* 127 */ "seltablist_paren ::= seltablist", /* 128 */ "dbnm ::=", /* 129 */ "dbnm ::= DOT nm", /* 130 */ "fullname ::= nm dbnm", /* 131 */ "joinop ::= COMMA", /* 132 */ "joinop ::= JOIN", /* 133 */ "joinop ::= JOIN_KW JOIN", /* 134 */ "joinop ::= JOIN_KW nm JOIN", /* 135 */ "joinop ::= JOIN_KW nm nm JOIN", /* 136 */ "on_opt ::= ON expr", /* 137 */ "on_opt ::=", /* 138 */ "using_opt ::= USING LP inscollist RP", /* 139 */ "using_opt ::=", /* 140 */ "orderby_opt ::=", /* 141 */ "orderby_opt ::= ORDER BY sortlist", /* 142 */ "sortlist ::= sortlist COMMA sortitem collate sortorder", /* 143 */ "sortlist ::= sortitem collate sortorder", /* 144 */ "sortitem ::= expr", /* 145 */ "sortorder ::= ASC", /* 146 */ "sortorder ::= DESC", /* 147 */ "sortorder ::=", /* 148 */ "collate ::=", /* 149 */ "collate ::= COLLATE id", /* 150 */ "groupby_opt ::=", /* 151 */ "groupby_opt ::= GROUP BY exprlist", /* 152 */ "having_opt ::=", /* 153 */ "having_opt ::= HAVING expr", /* 154 */ "limit_opt ::=", /* 155 */ "limit_opt ::= LIMIT expr", /* 156 */ "limit_opt ::= LIMIT expr OFFSET expr", /* 157 */ "limit_opt ::= LIMIT expr COMMA expr", /* 158 */ "cmd ::= DELETE FROM fullname where_opt", /* 159 */ "where_opt ::=", /* 160 */ "where_opt ::= WHERE expr", /* 161 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt", /* 162 */ "setlist ::= setlist COMMA nm EQ expr", /* 163 */ "setlist ::= nm EQ expr", /* 164 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP", /* 165 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", /* 166 */ "insert_cmd ::= INSERT orconf", /* 167 */ "insert_cmd ::= REPLACE", /* 168 */ "itemlist ::= itemlist COMMA expr", /* 169 */ "itemlist ::= expr", /* 170 */ "inscollist_opt ::=", /* 171 */ "inscollist_opt ::= LP inscollist RP", /* 172 */ "inscollist ::= inscollist COMMA nm", /* 173 */ "inscollist ::= nm", /* 174 */ "expr ::= term", /* 175 */ "expr ::= LP expr RP", /* 176 */ "term ::= NULL", /* 177 */ "expr ::= ID", /* 178 */ "expr ::= JOIN_KW", /* 179 */ "expr ::= nm DOT nm", /* 180 */ "expr ::= nm DOT nm DOT nm", /* 181 */ "term ::= INTEGER", /* 182 */ "term ::= FLOAT", /* 183 */ "term ::= STRING", /* 184 */ "term ::= BLOB", /* 185 */ "expr ::= REGISTER", /* 186 */ "expr ::= VARIABLE", /* 187 */ "expr ::= CAST LP expr AS typetoken RP", /* 188 */ "expr ::= ID LP distinct exprlist RP", /* 189 */ "expr ::= ID LP STAR RP", /* 190 */ "term ::= CTIME_KW", /* 191 */ "expr ::= expr AND expr", /* 192 */ "expr ::= expr OR expr", /* 193 */ "expr ::= expr LT expr", /* 194 */ "expr ::= expr GT expr", /* 195 */ "expr ::= expr LE expr", /* 196 */ "expr ::= expr GE expr", /* 197 */ "expr ::= expr NE expr", /* 198 */ "expr ::= expr EQ expr", /* 199 */ "expr ::= expr BITAND expr", /* 200 */ "expr ::= expr BITOR expr", /* 201 */ "expr ::= expr LSHIFT expr", /* 202 */ "expr ::= expr RSHIFT expr", /* 203 */ "expr ::= expr PLUS expr", /* 204 */ "expr ::= expr MINUS expr", /* 205 */ "expr ::= expr STAR expr", /* 206 */ "expr ::= expr SLASH expr", /* 207 */ "expr ::= expr REM expr", /* 208 */ "expr ::= expr CONCAT expr", /* 209 */ "likeop ::= LIKE_KW", /* 210 */ "likeop ::= NOT LIKE_KW", /* 211 */ "escape ::= ESCAPE expr", /* 212 */ "escape ::=", /* 213 */ "expr ::= expr likeop expr escape", /* 214 */ "expr ::= expr ISNULL", /* 215 */ "expr ::= expr IS NULL", /* 216 */ "expr ::= expr NOTNULL", /* 217 */ "expr ::= expr NOT NULL", /* 218 */ "expr ::= expr IS NOT NULL", /* 219 */ "expr ::= NOT expr", /* 220 */ "expr ::= BITNOT expr", /* 221 */ "expr ::= MINUS expr", /* 222 */ "expr ::= PLUS expr", /* 223 */ "between_op ::= BETWEEN", /* 224 */ "between_op ::= NOT BETWEEN", /* 225 */ "expr ::= expr between_op expr AND expr", /* 226 */ "in_op ::= IN", /* 227 */ "in_op ::= NOT IN", /* 228 */ "expr ::= expr in_op LP exprlist RP", /* 229 */ "expr ::= LP select RP", /* 230 */ "expr ::= expr in_op LP select RP", /* 231 */ "expr ::= expr in_op nm dbnm", /* 232 */ "expr ::= EXISTS LP select RP", /* 233 */ "expr ::= CASE case_operand case_exprlist case_else END", /* 234 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", /* 235 */ "case_exprlist ::= WHEN expr THEN expr", /* 236 */ "case_else ::= ELSE expr", /* 237 */ "case_else ::=", /* 238 */ "case_operand ::= expr", /* 239 */ "case_operand ::=", /* 240 */ "exprlist ::= exprlist COMMA expritem", /* 241 */ "exprlist ::= expritem", /* 242 */ "expritem ::= expr", /* 243 */ "expritem ::=", /* 244 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf", /* 245 */ "uniqueflag ::= UNIQUE", /* 246 */ "uniqueflag ::=", /* 247 */ "idxlist_opt ::=", /* 248 */ "idxlist_opt ::= LP idxlist RP", /* 249 */ "idxlist ::= idxlist COMMA idxitem collate sortorder", /* 250 */ "idxlist ::= idxitem collate sortorder", /* 251 */ "idxitem ::= nm", /* 252 */ "cmd ::= DROP INDEX fullname", /* 253 */ "cmd ::= VACUUM", /* 254 */ "cmd ::= VACUUM nm", /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nm", /* 256 */ "cmd ::= PRAGMA nm dbnm EQ ON", /* 257 */ "cmd ::= PRAGMA nm dbnm EQ plus_num", /* 258 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", /* 259 */ "cmd ::= PRAGMA nm dbnm LP nm RP", /* 260 */ "cmd ::= PRAGMA nm dbnm", /* 261 */ "plus_num ::= plus_opt number", /* 262 */ "minus_num ::= MINUS number", /* 263 */ "number ::= INTEGER", /* 264 */ "number ::= FLOAT", /* 265 */ "plus_opt ::= PLUS", /* 266 */ "plus_opt ::=", /* 267 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", /* 268 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", /* 269 */ "trigger_time ::= BEFORE", /* 270 */ "trigger_time ::= AFTER", /* 271 */ "trigger_time ::= INSTEAD OF", /* 272 */ "trigger_time ::=", /* 273 */ "trigger_event ::= DELETE", /* 274 */ "trigger_event ::= INSERT", /* 275 */ "trigger_event ::= UPDATE", /* 276 */ "trigger_event ::= UPDATE OF inscollist", /* 277 */ "foreach_clause ::=", /* 278 */ "foreach_clause ::= FOR EACH ROW", /* 279 */ "foreach_clause ::= FOR EACH STATEMENT", /* 280 */ "when_clause ::=", /* 281 */ "when_clause ::= WHEN expr", /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list", /* 283 */ "trigger_cmd_list ::=", /* 284 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", /* 285 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", /* 286 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", /* 287 */ "trigger_cmd ::= DELETE FROM nm where_opt", /* 288 */ "trigger_cmd ::= select", /* 289 */ "expr ::= RAISE LP IGNORE RP", /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP", /* 291 */ "raisetype ::= ROLLBACK", /* 292 */ "raisetype ::= ABORT", /* 293 */ "raisetype ::= FAIL", /* 294 */ "cmd ::= DROP TRIGGER fullname", /* 295 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt", /* 296 */ "key_opt ::=", /* 297 */ "key_opt ::= KEY ids", /* 298 */ "key_opt ::= KEY BLOB", /* 299 */ "database_kw_opt ::= DATABASE", /* 300 */ "database_kw_opt ::=", /* 301 */ "cmd ::= DETACH database_kw_opt nm", /* 302 */ "cmd ::= REINDEX", /* 303 */ "cmd ::= REINDEX nm dbnm", /* 304 */ "cmd ::= ANALYZE", /* 305 */ "cmd ::= ANALYZE nm dbnm", /* 306 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", /* 307 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", /* 308 */ "add_column_fullname ::= fullname", /* 309 */ "kwcolumn_opt ::=", /* 310 */ "kwcolumn_opt ::= COLUMNKW", }; #endif /* NDEBUG */ /* ** This function returns the symbolic name associated with a token ** value. */ |
︙ | ︙ | |||
1314 1315 1316 1317 1318 1319 1320 | ** reduce or during error processing or when a parser is ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ | | | | | | | | | | | | | | | | | | | < | | < < < < < < < < < < < < > > > > > | > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 | ** reduce or during error processing or when a parser is ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ case 162: case 195: case 212: #line 370 "parse.y" {sqlite3SelectDelete((yypminor->yy375));} #line 1332 "parse.c" break; case 176: case 177: case 200: case 202: case 210: case 216: case 230: #line 629 "parse.y" {sqlite3ExprDelete((yypminor->yy62));} #line 1343 "parse.c" break; case 181: case 189: case 198: case 201: case 203: case 205: case 215: case 218: case 219: case 222: case 228: #line 876 "parse.y" {sqlite3ExprListDelete((yypminor->yy418));} #line 1358 "parse.c" break; case 194: case 199: case 207: case 208: #line 499 "parse.y" {sqlite3SrcListDelete((yypminor->yy151));} #line 1366 "parse.c" break; case 204: #line 561 "parse.y" { sqlite3ExprDelete((yypminor->yy220).pLimit); sqlite3ExprDelete((yypminor->yy220).pOffset); } #line 1374 "parse.c" break; case 211: case 214: case 221: #line 517 "parse.y" {sqlite3IdListDelete((yypminor->yy240));} #line 1381 "parse.c" break; case 236: case 241: #line 969 "parse.y" {sqlite3DeleteTriggerStep((yypminor->yy360));} #line 1387 "parse.c" break; case 238: #line 953 "parse.y" {sqlite3IdListDelete((yypminor->yy30).b);} #line 1392 "parse.c" break; default: break; /* If no destructor action specified: do nothing */ } } /* ** Pop the parser's stack once. |
︙ | ︙ | |||
1555 1556 1557 1558 1559 1560 1561 | /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { | | | | | | | | | | | > | | | | | | | | | | | | | < < | | | > < < < < < < < < < < < | > > | | | | > | | | | | | | < < < | | | < < < < | | | | > > | | > | > | | | | | | | | < | | | | | | > | > | | > | | < | | | | | | | | | | | > > > | | > | | | | | | < | | < < < < < < | | | | | < < < < < < < < < < < < < < < < < < > | > > > > > | > | > > > | > > | | | | | > | | | > | | > > > > > > > > > > > > > < < < < < | < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | > > | > | | | > > | | | | | | | | > | > > > > > > > > > > > > > > > > > > > > > > | > | | | | | > > > | | > | | | < | | | | | | | | < < < | < | | < < < < < | < < | < > > > > > | > | | | | > > > > > > > > | | | | > | | < < | < | | | | | | | < < < < | < > > > > > > > > > > > > > > > | > | | | | | | | | | | | | | 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 | /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { { 147, 1 }, { 148, 2 }, { 148, 1 }, { 150, 1 }, { 149, 1 }, { 149, 3 }, { 152, 0 }, { 152, 1 }, { 152, 3 }, { 151, 3 }, { 154, 0 }, { 154, 1 }, { 154, 2 }, { 153, 0 }, { 153, 1 }, { 153, 1 }, { 153, 1 }, { 151, 2 }, { 151, 2 }, { 151, 2 }, { 151, 2 }, { 156, 5 }, { 158, 1 }, { 158, 0 }, { 157, 4 }, { 157, 2 }, { 160, 3 }, { 160, 1 }, { 163, 3 }, { 164, 1 }, { 167, 1 }, { 168, 1 }, { 168, 1 }, { 155, 1 }, { 155, 1 }, { 155, 1 }, { 165, 0 }, { 165, 1 }, { 169, 1 }, { 169, 4 }, { 169, 6 }, { 170, 1 }, { 170, 2 }, { 171, 1 }, { 171, 1 }, { 166, 2 }, { 166, 0 }, { 174, 3 }, { 174, 1 }, { 174, 2 }, { 174, 4 }, { 174, 3 }, { 174, 3 }, { 174, 2 }, { 175, 2 }, { 175, 3 }, { 175, 5 }, { 175, 2 }, { 175, 5 }, { 175, 4 }, { 175, 1 }, { 175, 2 }, { 180, 0 }, { 180, 1 }, { 182, 0 }, { 182, 2 }, { 184, 2 }, { 184, 3 }, { 184, 3 }, { 184, 3 }, { 185, 2 }, { 185, 2 }, { 185, 1 }, { 185, 1 }, { 183, 3 }, { 183, 2 }, { 186, 0 }, { 186, 2 }, { 186, 2 }, { 161, 0 }, { 161, 2 }, { 187, 3 }, { 187, 2 }, { 187, 1 }, { 188, 2 }, { 188, 7 }, { 188, 5 }, { 188, 3 }, { 188, 10 }, { 190, 0 }, { 190, 1 }, { 178, 0 }, { 178, 3 }, { 191, 0 }, { 191, 2 }, { 192, 1 }, { 192, 1 }, { 192, 1 }, { 151, 3 }, { 151, 7 }, { 151, 3 }, { 151, 1 }, { 162, 1 }, { 162, 3 }, { 196, 1 }, { 196, 2 }, { 196, 1 }, { 196, 1 }, { 195, 9 }, { 197, 1 }, { 197, 1 }, { 197, 0 }, { 205, 2 }, { 205, 0 }, { 198, 3 }, { 198, 2 }, { 198, 4 }, { 206, 2 }, { 206, 1 }, { 206, 0 }, { 199, 0 }, { 199, 2 }, { 208, 2 }, { 208, 0 }, { 207, 6 }, { 207, 7 }, { 212, 1 }, { 212, 1 }, { 159, 0 }, { 159, 2 }, { 194, 2 }, { 209, 1 }, { 209, 1 }, { 209, 2 }, { 209, 3 }, { 209, 4 }, { 210, 2 }, { 210, 0 }, { 211, 4 }, { 211, 0 }, { 203, 0 }, { 203, 3 }, { 215, 5 }, { 215, 3 }, { 216, 1 }, { 179, 1 }, { 179, 1 }, { 179, 0 }, { 217, 0 }, { 217, 2 }, { 201, 0 }, { 201, 3 }, { 202, 0 }, { 202, 2 }, { 204, 0 }, { 204, 2 }, { 204, 4 }, { 204, 4 }, { 151, 4 }, { 200, 0 }, { 200, 2 }, { 151, 6 }, { 219, 5 }, { 219, 3 }, { 151, 8 }, { 151, 5 }, { 220, 2 }, { 220, 1 }, { 222, 3 }, { 222, 1 }, { 221, 0 }, { 221, 3 }, { 214, 3 }, { 214, 1 }, { 177, 1 }, { 177, 3 }, { 176, 1 }, { 177, 1 }, { 177, 1 }, { 177, 3 }, { 177, 5 }, { 176, 1 }, { 176, 1 }, { 176, 1 }, { 176, 1 }, { 177, 1 }, { 177, 1 }, { 177, 6 }, { 177, 5 }, { 177, 4 }, { 176, 1 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 177, 3 }, { 223, 1 }, { 223, 2 }, { 224, 2 }, { 224, 0 }, { 177, 4 }, { 177, 2 }, { 177, 3 }, { 177, 2 }, { 177, 3 }, { 177, 4 }, { 177, 2 }, { 177, 2 }, { 177, 2 }, { 177, 2 }, { 225, 1 }, { 225, 2 }, { 177, 5 }, { 226, 1 }, { 226, 2 }, { 177, 5 }, { 177, 3 }, { 177, 5 }, { 177, 4 }, { 177, 4 }, { 177, 5 }, { 228, 5 }, { 228, 4 }, { 229, 2 }, { 229, 0 }, { 227, 1 }, { 227, 0 }, { 218, 3 }, { 218, 1 }, { 230, 1 }, { 230, 0 }, { 151, 11 }, { 231, 1 }, { 231, 0 }, { 181, 0 }, { 181, 3 }, { 189, 5 }, { 189, 3 }, { 232, 1 }, { 151, 3 }, { 151, 1 }, { 151, 2 }, { 151, 5 }, { 151, 5 }, { 151, 5 }, { 151, 5 }, { 151, 6 }, { 151, 3 }, { 172, 2 }, { 173, 2 }, { 234, 1 }, { 234, 1 }, { 233, 1 }, { 233, 0 }, { 151, 5 }, { 235, 10 }, { 237, 1 }, { 237, 1 }, { 237, 2 }, { 237, 0 }, { 238, 1 }, { 238, 1 }, { 238, 1 }, { 238, 3 }, { 239, 0 }, { 239, 3 }, { 239, 3 }, { 240, 0 }, { 240, 2 }, { 236, 3 }, { 236, 0 }, { 241, 6 }, { 241, 8 }, { 241, 5 }, { 241, 4 }, { 241, 1 }, { 177, 4 }, { 177, 6 }, { 193, 1 }, { 193, 1 }, { 193, 1 }, { 151, 3 }, { 151, 6 }, { 243, 0 }, { 243, 2 }, { 243, 2 }, { 242, 1 }, { 242, 0 }, { 151, 3 }, { 151, 1 }, { 151, 3 }, { 151, 1 }, { 151, 3 }, { 151, 6 }, { 151, 6 }, { 244, 1 }, { 245, 0 }, { 245, 1 }, }; static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. |
︙ | ︙ | |||
1916 1917 1918 1919 1920 1921 1922 | ** { ... } // User supplied code ** #line <lineno> <thisfile> ** break; */ case 3: #line 102 "parse.y" { sqlite3FinishCoding(pParse); } | | | | | > > > > > | | | | | | < | | > | | | | | | | | | | | | | < < < < < < < < < < | < < < | | | | | > > > > > > > > < | < | | | < | | | | | | | > > > > > > > > | | | < | > | | | | | | | | | < | | | | < < < < | < | < < | | | | | | | > | > > | | | | > > > > > | | | | | | | | | | | | | | | | | | | < < < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > | | | | < < < < | | | | > > > > > | | | | | | | | | | | | | | | | | < < < < < | | | < | | > | < | < | | | | | | | | | < | > > > > > > > | > | | | | | | | | | | | | | | | | | | < < < < < < > > > > > | | > | | | | | | | | | | | | | | | | | < < < < < | | | | | | < | < < | | > | > > | < < < | < < < < < < < < | | | < | | | | | | | | | | | | | > > > > > > > | > > | > | < < < < < | > | > | > > > > | | | | > | | | | | | | | < < < < < < < < | | | | | > > | | | > > > > > | | | | | | | | | | | > < < | < | | | | | | < | > > | > | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | > | | | | | | | | | > > > > | > | | | | | | | | | | | | | | | | | | | | < < < < < | > > > > > | | | | | | | | | | | > > | < < < < < < < | > > > > > > > > | | | < > | | | | | | | | | | | | | | | | | | | < < < < < < < < | | | | | | | | | | | | | | < | | | > | | | | | | | | | < | < < < | | | | > > | | | | | | | | | | | | | > > | > > | | | | | > > | < > | | | < | | | < | < < < < < < < | < > | | | > | | > > > > > | | | | > > > > > > > > > > > > > > | > > | | > > | | | | | | | < < < < < < < < < < < < < < | < < < < < < < < < < | > > > > > > > > > > > > > > > > > > > > | | | | | | | > > | > > > > > | < | | | > < | | | < < < < | < | < | | | < < < < < | | | | < | < < | | > > > > > > > > > > > > | | | < | > > | > | > | | | | | | | > > > > < < < < | | | < | | | > | | | | | | | | | | < | < < | | > > | > | | | | | | | | | | | | | | | | | > > > > > | | | | | | | | | | | | | | | | | | < < < < < < < | | | | > > > > > > > | | | | | | | | | | | | | | < < < < < | | | | > > > > > | | | | | | | | | | | | | | | | | | 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 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 | ** { ... } // User supplied code ** #line <lineno> <thisfile> ** break; */ case 3: #line 102 "parse.y" { sqlite3FinishCoding(pParse); } #line 1930 "parse.c" break; case 6: #line 105 "parse.y" { sqlite3BeginParse(pParse, 0); } #line 1935 "parse.c" break; case 7: #line 107 "parse.y" { sqlite3BeginParse(pParse, 1); } #line 1940 "parse.c" break; case 8: #line 108 "parse.y" { sqlite3BeginParse(pParse, 2); } #line 1945 "parse.c" break; case 9: #line 114 "parse.y" {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy280);} #line 1950 "parse.c" break; case 13: #line 119 "parse.y" {yygotominor.yy280 = TK_DEFERRED;} #line 1955 "parse.c" break; case 14: case 15: case 16: case 104: case 106: case 107: #line 120 "parse.y" {yygotominor.yy280 = yymsp[0].major;} #line 1965 "parse.c" break; case 17: case 18: #line 123 "parse.y" {sqlite3CommitTransaction(pParse);} #line 1971 "parse.c" break; case 19: #line 125 "parse.y" {sqlite3RollbackTransaction(pParse);} #line 1976 "parse.c" break; case 21: #line 130 "parse.y" { sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198,yymsp[-3].minor.yy280,0); } #line 1983 "parse.c" break; case 22: case 63: case 77: case 109: case 224: case 227: #line 135 "parse.y" {yygotominor.yy280 = 1;} #line 1993 "parse.c" break; case 23: case 62: case 76: case 78: case 89: case 110: case 111: case 223: case 226: #line 137 "parse.y" {yygotominor.yy280 = 0;} #line 2006 "parse.c" break; case 24: #line 138 "parse.y" { sqlite3EndTable(pParse,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy0,0); } #line 2013 "parse.c" break; case 25: #line 141 "parse.y" { sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy375); sqlite3SelectDelete(yymsp[0].minor.yy375); } #line 2021 "parse.c" break; case 28: #line 153 "parse.y" { yygotominor.yy198.z = yymsp[-2].minor.yy198.z; yygotominor.yy198.n = (pParse->sLastToken.z-yymsp[-2].minor.yy198.z) + pParse->sLastToken.n; } #line 2029 "parse.c" break; case 29: #line 157 "parse.y" { sqlite3AddColumn(pParse,&yymsp[0].minor.yy198); yygotominor.yy198 = yymsp[0].minor.yy198; } #line 2037 "parse.c" break; case 30: case 31: case 32: case 33: case 34: case 35: case 263: case 264: #line 167 "parse.y" {yygotominor.yy198 = yymsp[0].minor.yy0;} #line 2049 "parse.c" break; case 37: #line 227 "parse.y" {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy198);} #line 2054 "parse.c" break; case 38: case 41: case 117: case 118: case 129: case 149: case 251: case 261: case 262: #line 228 "parse.y" {yygotominor.yy198 = yymsp[0].minor.yy198;} #line 2067 "parse.c" break; case 39: #line 229 "parse.y" { yygotominor.yy198.z = yymsp[-3].minor.yy198.z; yygotominor.yy198.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy198.z; } #line 2075 "parse.c" break; case 40: #line 233 "parse.y" { yygotominor.yy198.z = yymsp[-5].minor.yy198.z; yygotominor.yy198.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy198.z; } #line 2083 "parse.c" break; case 42: #line 239 "parse.y" {yygotominor.yy198.z=yymsp[-1].minor.yy198.z; yygotominor.yy198.n=yymsp[0].minor.yy198.n+(yymsp[0].minor.yy198.z-yymsp[-1].minor.yy198.z);} #line 2088 "parse.c" break; case 43: #line 241 "parse.y" { yygotominor.yy280 = atoi(yymsp[0].minor.yy198.z); } #line 2093 "parse.c" break; case 44: #line 242 "parse.y" { yygotominor.yy280 = -atoi(yymsp[0].minor.yy198.z); } #line 2098 "parse.c" break; case 49: case 51: #line 251 "parse.y" {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy62);} #line 2104 "parse.c" break; case 50: #line 252 "parse.y" {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy62);} #line 2109 "parse.c" break; case 52: #line 254 "parse.y" { Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy62, 0, 0); sqlite3AddDefaultValue(pParse,p); } #line 2117 "parse.c" break; case 53: #line 258 "parse.y" { Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy198); sqlite3AddDefaultValue(pParse,p); } #line 2125 "parse.c" break; case 55: #line 267 "parse.y" {sqlite3AddNotNull(pParse, yymsp[0].minor.yy280);} #line 2130 "parse.c" break; case 56: #line 269 "parse.y" {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy280,yymsp[0].minor.yy280);} #line 2135 "parse.c" break; case 57: #line 270 "parse.y" {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy280,0,0);} #line 2140 "parse.c" break; case 58: #line 271 "parse.y" {sqlite3ExprDelete(yymsp[-2].minor.yy62);} #line 2145 "parse.c" break; case 59: #line 273 "parse.y" {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy198,yymsp[-1].minor.yy418,yymsp[0].minor.yy280);} #line 2150 "parse.c" break; case 60: #line 274 "parse.y" {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy280);} #line 2155 "parse.c" break; case 61: #line 275 "parse.y" {sqlite3AddCollateType(pParse, yymsp[0].minor.yy198.z, yymsp[0].minor.yy198.n);} #line 2160 "parse.c" break; case 64: #line 288 "parse.y" { yygotominor.yy280 = OE_Restrict * 0x010101; } #line 2165 "parse.c" break; case 65: #line 289 "parse.y" { yygotominor.yy280 = (yymsp[-1].minor.yy280 & yymsp[0].minor.yy359.mask) | yymsp[0].minor.yy359.value; } #line 2170 "parse.c" break; case 66: #line 291 "parse.y" { yygotominor.yy359.value = 0; yygotominor.yy359.mask = 0x000000; } #line 2175 "parse.c" break; case 67: #line 292 "parse.y" { yygotominor.yy359.value = yymsp[0].minor.yy280; yygotominor.yy359.mask = 0x0000ff; } #line 2180 "parse.c" break; case 68: #line 293 "parse.y" { yygotominor.yy359.value = yymsp[0].minor.yy280<<8; yygotominor.yy359.mask = 0x00ff00; } #line 2185 "parse.c" break; case 69: #line 294 "parse.y" { yygotominor.yy359.value = yymsp[0].minor.yy280<<16; yygotominor.yy359.mask = 0xff0000; } #line 2190 "parse.c" break; case 70: #line 296 "parse.y" { yygotominor.yy280 = OE_SetNull; } #line 2195 "parse.c" break; case 71: #line 297 "parse.y" { yygotominor.yy280 = OE_SetDflt; } #line 2200 "parse.c" break; case 72: #line 298 "parse.y" { yygotominor.yy280 = OE_Cascade; } #line 2205 "parse.c" break; case 73: #line 299 "parse.y" { yygotominor.yy280 = OE_Restrict; } #line 2210 "parse.c" break; case 74: case 75: case 90: case 92: case 94: case 95: case 166: #line 301 "parse.y" {yygotominor.yy280 = yymsp[0].minor.yy280;} #line 2221 "parse.c" break; case 79: #line 311 "parse.y" {yygotominor.yy198.n = 0; yygotominor.yy198.z = 0;} #line 2226 "parse.c" break; case 80: #line 312 "parse.y" {yygotominor.yy198 = yymsp[-1].minor.yy0;} #line 2231 "parse.c" break; case 85: #line 318 "parse.y" {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy418,yymsp[0].minor.yy280,yymsp[-2].minor.yy280);} #line 2236 "parse.c" break; case 86: #line 320 "parse.y" {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy418,yymsp[0].minor.yy280,0,0);} #line 2241 "parse.c" break; case 88: #line 323 "parse.y" { sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy418, &yymsp[-3].minor.yy198, yymsp[-2].minor.yy418, yymsp[-1].minor.yy280); sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy280); } #line 2249 "parse.c" break; case 91: case 93: #line 337 "parse.y" {yygotominor.yy280 = OE_Default;} #line 2255 "parse.c" break; case 96: #line 342 "parse.y" {yygotominor.yy280 = OE_Ignore;} #line 2260 "parse.c" break; case 97: case 167: #line 343 "parse.y" {yygotominor.yy280 = OE_Replace;} #line 2266 "parse.c" break; case 98: #line 347 "parse.y" { sqlite3DropTable(pParse, yymsp[0].minor.yy151, 0); } #line 2273 "parse.c" break; case 99: #line 354 "parse.y" { sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy198, &yymsp[-2].minor.yy198, yymsp[0].minor.yy375, yymsp[-5].minor.yy280); } #line 2280 "parse.c" break; case 100: #line 357 "parse.y" { sqlite3DropTable(pParse, yymsp[0].minor.yy151, 1); } #line 2287 "parse.c" break; case 101: #line 364 "parse.y" { sqlite3Select(pParse, yymsp[0].minor.yy375, SRT_Callback, 0, 0, 0, 0, 0); sqlite3SelectDelete(yymsp[0].minor.yy375); } #line 2295 "parse.c" break; case 102: case 126: #line 374 "parse.y" {yygotominor.yy375 = yymsp[0].minor.yy375;} #line 2301 "parse.c" break; case 103: #line 376 "parse.y" { if( yymsp[0].minor.yy375 ){ yymsp[0].minor.yy375->op = yymsp[-1].minor.yy280; yymsp[0].minor.yy375->pPrior = yymsp[-2].minor.yy375; } yygotominor.yy375 = yymsp[0].minor.yy375; } #line 2312 "parse.c" break; case 105: #line 385 "parse.y" {yygotominor.yy280 = TK_ALL;} #line 2317 "parse.c" break; case 108: #line 390 "parse.y" { yygotominor.yy375 = sqlite3SelectNew(yymsp[-6].minor.yy418,yymsp[-5].minor.yy151,yymsp[-4].minor.yy62,yymsp[-3].minor.yy418,yymsp[-2].minor.yy62,yymsp[-1].minor.yy418,yymsp[-7].minor.yy280,yymsp[0].minor.yy220.pLimit,yymsp[0].minor.yy220.pOffset); } #line 2324 "parse.c" break; case 112: case 248: #line 411 "parse.y" {yygotominor.yy418 = yymsp[-1].minor.yy418;} #line 2330 "parse.c" break; case 113: case 140: case 150: case 247: #line 412 "parse.y" {yygotominor.yy418 = 0;} #line 2338 "parse.c" break; case 114: #line 413 "parse.y" { yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-2].minor.yy418,yymsp[-1].minor.yy62,yymsp[0].minor.yy198.n?&yymsp[0].minor.yy198:0); } #line 2345 "parse.c" break; case 115: #line 416 "parse.y" { yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-1].minor.yy418, sqlite3Expr(TK_ALL, 0, 0, 0), 0); } #line 2352 "parse.c" break; case 116: #line 419 "parse.y" { Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0); Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198); yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-3].minor.yy418, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0); } #line 2361 "parse.c" break; case 119: #line 431 "parse.y" {yygotominor.yy198.n = 0;} #line 2366 "parse.c" break; case 120: #line 443 "parse.y" {yygotominor.yy151 = sqliteMalloc(sizeof(*yygotominor.yy151));} #line 2371 "parse.c" break; case 121: #line 444 "parse.y" {yygotominor.yy151 = yymsp[0].minor.yy151;} #line 2376 "parse.c" break; case 122: #line 449 "parse.y" { yygotominor.yy151 = yymsp[-1].minor.yy151; if( yygotominor.yy151 && yygotominor.yy151->nSrc>0 ) yygotominor.yy151->a[yygotominor.yy151->nSrc-1].jointype = yymsp[0].minor.yy280; } #line 2384 "parse.c" break; case 123: #line 453 "parse.y" {yygotominor.yy151 = 0;} #line 2389 "parse.c" break; case 124: #line 454 "parse.y" { yygotominor.yy151 = sqlite3SrcListAppend(yymsp[-5].minor.yy151,&yymsp[-4].minor.yy198,&yymsp[-3].minor.yy198); if( yymsp[-2].minor.yy198.n ) sqlite3SrcListAddAlias(yygotominor.yy151,&yymsp[-2].minor.yy198); if( yymsp[-1].minor.yy62 ){ if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pOn = yymsp[-1].minor.yy62; } else { sqlite3ExprDelete(yymsp[-1].minor.yy62); } } if( yymsp[0].minor.yy240 ){ if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pUsing = yymsp[0].minor.yy240; } else { sqlite3IdListDelete(yymsp[0].minor.yy240); } } } #line 2405 "parse.c" break; case 125: #line 468 "parse.y" { yygotominor.yy151 = sqlite3SrcListAppend(yymsp[-6].minor.yy151,0,0); yygotominor.yy151->a[yygotominor.yy151->nSrc-1].pSelect = yymsp[-4].minor.yy375; if( yymsp[-2].minor.yy198.n ) sqlite3SrcListAddAlias(yygotominor.yy151,&yymsp[-2].minor.yy198); if( yymsp[-1].minor.yy62 ){ if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pOn = yymsp[-1].minor.yy62; } else { sqlite3ExprDelete(yymsp[-1].minor.yy62); } } if( yymsp[0].minor.yy240 ){ if( yygotominor.yy151 && yygotominor.yy151->nSrc>1 ){ yygotominor.yy151->a[yygotominor.yy151->nSrc-2].pUsing = yymsp[0].minor.yy240; } else { sqlite3IdListDelete(yymsp[0].minor.yy240); } } } #line 2422 "parse.c" break; case 127: #line 489 "parse.y" { yygotominor.yy375 = sqlite3SelectNew(0,yymsp[0].minor.yy151,0,0,0,0,0,0,0); } #line 2429 "parse.c" break; case 128: #line 495 "parse.y" {yygotominor.yy198.z=0; yygotominor.yy198.n=0;} #line 2434 "parse.c" break; case 130: #line 500 "parse.y" {yygotominor.yy151 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198);} #line 2439 "parse.c" break; case 131: case 132: #line 504 "parse.y" { yygotominor.yy280 = JT_INNER; } #line 2445 "parse.c" break; case 133: #line 506 "parse.y" { yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } #line 2450 "parse.c" break; case 134: #line 507 "parse.y" { yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy198,0); } #line 2455 "parse.c" break; case 135: #line 509 "parse.y" { yygotominor.yy280 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy198,&yymsp[-1].minor.yy198); } #line 2460 "parse.c" break; case 136: case 144: case 153: case 160: case 174: case 211: case 236: case 238: case 242: #line 513 "parse.y" {yygotominor.yy62 = yymsp[0].minor.yy62;} #line 2473 "parse.c" break; case 137: case 152: case 159: case 212: case 237: case 239: case 243: #line 514 "parse.y" {yygotominor.yy62 = 0;} #line 2484 "parse.c" break; case 138: case 171: #line 518 "parse.y" {yygotominor.yy240 = yymsp[-1].minor.yy240;} #line 2490 "parse.c" break; case 139: case 170: #line 519 "parse.y" {yygotominor.yy240 = 0;} #line 2496 "parse.c" break; case 141: case 151: #line 530 "parse.y" {yygotominor.yy418 = yymsp[0].minor.yy418;} #line 2502 "parse.c" break; case 142: #line 531 "parse.y" { yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418,yymsp[-2].minor.yy62,yymsp[-1].minor.yy198.n>0?&yymsp[-1].minor.yy198:0); if( yygotominor.yy418 ) yygotominor.yy418->a[yygotominor.yy418->nExpr-1].sortOrder = yymsp[0].minor.yy280; } #line 2510 "parse.c" break; case 143: #line 535 "parse.y" { yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy62,yymsp[-1].minor.yy198.n>0?&yymsp[-1].minor.yy198:0); if( yygotominor.yy418 && yygotominor.yy418->a ) yygotominor.yy418->a[0].sortOrder = yymsp[0].minor.yy280; } #line 2518 "parse.c" break; case 145: case 147: #line 544 "parse.y" {yygotominor.yy280 = SQLITE_SO_ASC;} #line 2524 "parse.c" break; case 146: #line 545 "parse.y" {yygotominor.yy280 = SQLITE_SO_DESC;} #line 2529 "parse.c" break; case 148: #line 547 "parse.y" {yygotominor.yy198.z = 0; yygotominor.yy198.n = 0;} #line 2534 "parse.c" break; case 154: #line 565 "parse.y" {yygotominor.yy220.pLimit = 0; yygotominor.yy220.pOffset = 0;} #line 2539 "parse.c" break; case 155: #line 566 "parse.y" {yygotominor.yy220.pLimit = yymsp[0].minor.yy62; yygotominor.yy220.pOffset = 0;} #line 2544 "parse.c" break; case 156: #line 568 "parse.y" {yygotominor.yy220.pLimit = yymsp[-2].minor.yy62; yygotominor.yy220.pOffset = yymsp[0].minor.yy62;} #line 2549 "parse.c" break; case 157: #line 570 "parse.y" {yygotominor.yy220.pOffset = yymsp[-2].minor.yy62; yygotominor.yy220.pLimit = yymsp[0].minor.yy62;} #line 2554 "parse.c" break; case 158: #line 574 "parse.y" {sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy151,yymsp[0].minor.yy62);} #line 2559 "parse.c" break; case 161: #line 585 "parse.y" {sqlite3Update(pParse,yymsp[-3].minor.yy151,yymsp[-1].minor.yy418,yymsp[0].minor.yy62,yymsp[-4].minor.yy280);} #line 2564 "parse.c" break; case 162: #line 591 "parse.y" {yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418,yymsp[0].minor.yy62,&yymsp[-2].minor.yy198);} #line 2569 "parse.c" break; case 163: #line 592 "parse.y" {yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[0].minor.yy62,&yymsp[-2].minor.yy198);} #line 2574 "parse.c" break; case 164: #line 598 "parse.y" {sqlite3Insert(pParse, yymsp[-5].minor.yy151, yymsp[-1].minor.yy418, 0, yymsp[-4].minor.yy240, yymsp[-7].minor.yy280);} #line 2579 "parse.c" break; case 165: #line 600 "parse.y" {sqlite3Insert(pParse, yymsp[-2].minor.yy151, 0, yymsp[0].minor.yy375, yymsp[-1].minor.yy240, yymsp[-4].minor.yy280);} #line 2584 "parse.c" break; case 168: case 240: #line 610 "parse.y" {yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-2].minor.yy418,yymsp[0].minor.yy62,0);} #line 2590 "parse.c" break; case 169: case 241: #line 611 "parse.y" {yygotominor.yy418 = sqlite3ExprListAppend(0,yymsp[0].minor.yy62,0);} #line 2596 "parse.c" break; case 172: #line 620 "parse.y" {yygotominor.yy240 = sqlite3IdListAppend(yymsp[-2].minor.yy240,&yymsp[0].minor.yy198);} #line 2601 "parse.c" break; case 173: #line 621 "parse.y" {yygotominor.yy240 = sqlite3IdListAppend(0,&yymsp[0].minor.yy198);} #line 2606 "parse.c" break; case 175: #line 632 "parse.y" {yygotominor.yy62 = yymsp[-1].minor.yy62; sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } #line 2611 "parse.c" break; case 176: case 181: case 182: case 183: case 184: #line 633 "parse.y" {yygotominor.yy62 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} #line 2620 "parse.c" break; case 177: case 178: #line 634 "parse.y" {yygotominor.yy62 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} #line 2626 "parse.c" break; case 179: #line 636 "parse.y" { Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198); Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy198); yygotominor.yy62 = sqlite3Expr(TK_DOT, temp1, temp2, 0); } #line 2635 "parse.c" break; case 180: #line 641 "parse.y" { Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy198); Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy198); Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy198); Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0); yygotominor.yy62 = sqlite3Expr(TK_DOT, temp1, temp4, 0); } #line 2646 "parse.c" break; case 185: #line 652 "parse.y" {yygotominor.yy62 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} #line 2651 "parse.c" break; case 186: #line 653 "parse.y" { Token *pToken = &yymsp[0].minor.yy0; Expr *pExpr = yygotominor.yy62 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); sqlite3ExprAssignVarNumber(pParse, pExpr); } #line 2660 "parse.c" break; case 187: #line 659 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_CAST, yymsp[-3].minor.yy62, 0, &yymsp[-1].minor.yy198); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); } #line 2668 "parse.c" break; case 188: #line 664 "parse.y" { yygotominor.yy62 = sqlite3ExprFunction(yymsp[-1].minor.yy418, &yymsp[-4].minor.yy0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); if( yymsp[-2].minor.yy280 ){ yygotominor.yy62->flags |= EP_Distinct; } } #line 2679 "parse.c" break; case 189: #line 671 "parse.y" { yygotominor.yy62 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } #line 2687 "parse.c" break; case 190: #line 675 "parse.y" { /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are ** treated as functions that return constants */ yygotominor.yy62 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0); if( yygotominor.yy62 ) yygotominor.yy62->op = TK_CONST_FUNC; } #line 2697 "parse.c" break; case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 201: case 202: case 203: case 204: case 205: case 206: case 207: case 208: #line 681 "parse.y" {yygotominor.yy62 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy62, yymsp[0].minor.yy62, 0);} #line 2719 "parse.c" break; case 209: #line 700 "parse.y" {yygotominor.yy222.operator = yymsp[0].minor.yy0; yygotominor.yy222.not = 0;} #line 2724 "parse.c" break; case 210: #line 701 "parse.y" {yygotominor.yy222.operator = yymsp[0].minor.yy0; yygotominor.yy222.not = 1;} #line 2729 "parse.c" break; case 213: #line 705 "parse.y" { ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy62, 0); pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy62, 0); if( yymsp[0].minor.yy62 ){ pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy62, 0); } yygotominor.yy62 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy222.operator); if( yymsp[-2].minor.yy222.not ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62, &yymsp[-3].minor.yy62->span, &yymsp[-1].minor.yy62->span); } #line 2743 "parse.c" break; case 214: #line 716 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2751 "parse.c" break; case 215: #line 720 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2759 "parse.c" break; case 216: #line 724 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2767 "parse.c" break; case 217: #line 728 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2775 "parse.c" break; case 218: #line 732 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2783 "parse.c" break; case 219: case 220: #line 736 "parse.y" { yygotominor.yy62 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span); } #line 2792 "parse.c" break; case 221: #line 744 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span); } #line 2800 "parse.c" break; case 222: #line 748 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy62->span); } #line 2808 "parse.c" break; case 225: #line 755 "parse.y" { ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy62, 0); pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy62, 0); yygotominor.yy62 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy62, 0, 0); if( yygotominor.yy62 ){ yygotominor.yy62->pList = pList; }else{ sqlite3ExprListDelete(pList); } if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy62->span); } #line 2824 "parse.c" break; case 228: #line 771 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy62, 0, 0); if( yygotominor.yy62 ){ yygotominor.yy62->pList = yymsp[-1].minor.yy418; }else{ sqlite3ExprListDelete(yymsp[-1].minor.yy418); } if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2838 "parse.c" break; case 229: #line 781 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_SELECT, 0, 0, 0); if( yygotominor.yy62 ){ yygotominor.yy62->pSelect = yymsp[-1].minor.yy375; }else{ sqlite3SelectDelete(yymsp[-1].minor.yy375); } sqlite3ExprSpan(yygotominor.yy62,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } #line 2851 "parse.c" break; case 230: #line 790 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy62, 0, 0); if( yygotominor.yy62 ){ yygotominor.yy62->pSelect = yymsp[-1].minor.yy375; }else{ sqlite3SelectDelete(yymsp[-1].minor.yy375); } if( yymsp[-3].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-4].minor.yy62->span,&yymsp[0].minor.yy0); } #line 2865 "parse.c" break; case 231: #line 800 "parse.y" { SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198); yygotominor.yy62 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy62, 0, 0); if( yygotominor.yy62 ){ yygotominor.yy62->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0); }else{ sqlite3SrcListDelete(pSrc); } if( yymsp[-2].minor.yy280 ) yygotominor.yy62 = sqlite3Expr(TK_NOT, yygotominor.yy62, 0, 0); sqlite3ExprSpan(yygotominor.yy62,&yymsp[-3].minor.yy62->span,yymsp[0].minor.yy198.z?&yymsp[0].minor.yy198:&yymsp[-1].minor.yy198); } #line 2880 "parse.c" break; case 232: #line 811 "parse.y" { Expr *p = yygotominor.yy62 = sqlite3Expr(TK_EXISTS, 0, 0, 0); if( p ){ p->pSelect = yymsp[-1].minor.yy375; sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); }else{ sqlite3SelectDelete(yymsp[-1].minor.yy375); } } #line 2893 "parse.c" break; case 233: #line 823 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy62, yymsp[-1].minor.yy62, 0); if( yygotominor.yy62 ){ yygotominor.yy62->pList = yymsp[-2].minor.yy418; }else{ sqlite3ExprListDelete(yymsp[-2].minor.yy418); } sqlite3ExprSpan(yygotominor.yy62, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); } #line 2906 "parse.c" break; case 234: #line 834 "parse.y" { yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418, yymsp[-2].minor.yy62, 0); yygotominor.yy418 = sqlite3ExprListAppend(yygotominor.yy418, yymsp[0].minor.yy62, 0); } #line 2914 "parse.c" break; case 235: #line 838 "parse.y" { yygotominor.yy418 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy62, 0); yygotominor.yy418 = sqlite3ExprListAppend(yygotominor.yy418, yymsp[0].minor.yy62, 0); } #line 2922 "parse.c" break; case 244: #line 863 "parse.y" { if( yymsp[-9].minor.yy280!=OE_None ) yymsp[-9].minor.yy280 = yymsp[0].minor.yy280; if( yymsp[-9].minor.yy280==OE_Default) yymsp[-9].minor.yy280 = OE_Abort; sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy198, &yymsp[-6].minor.yy198, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy198,0),yymsp[-2].minor.yy418,yymsp[-9].minor.yy280, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0); } #line 2931 "parse.c" break; case 245: case 292: #line 870 "parse.y" {yygotominor.yy280 = OE_Abort;} #line 2937 "parse.c" break; case 246: #line 871 "parse.y" {yygotominor.yy280 = OE_None;} #line 2942 "parse.c" break; case 249: #line 881 "parse.y" { Expr *p = 0; if( yymsp[-1].minor.yy198.n>0 ){ p = sqlite3Expr(TK_COLUMN, 0, 0, 0); if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy198.z, yymsp[-1].minor.yy198.n); } yygotominor.yy418 = sqlite3ExprListAppend(yymsp[-4].minor.yy418, p, &yymsp[-2].minor.yy198); } #line 2954 "parse.c" break; case 250: #line 889 "parse.y" { Expr *p = 0; if( yymsp[-1].minor.yy198.n>0 ){ p = sqlite3Expr(TK_COLUMN, 0, 0, 0); if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy198.z, yymsp[-1].minor.yy198.n); } yygotominor.yy418 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy198); } #line 2966 "parse.c" break; case 252: #line 902 "parse.y" {sqlite3DropIndex(pParse, yymsp[0].minor.yy151);} #line 2971 "parse.c" break; case 253: case 254: #line 906 "parse.y" {sqlite3Vacuum(pParse,0);} #line 2977 "parse.c" break; case 255: case 257: #line 912 "parse.y" {sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy198,0);} #line 2983 "parse.c" break; case 256: #line 913 "parse.y" {sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy0,0);} #line 2988 "parse.c" break; case 258: #line 915 "parse.y" { sqlite3Pragma(pParse,&yymsp[-3].minor.yy198,&yymsp[-2].minor.yy198,&yymsp[0].minor.yy198,1); } #line 2995 "parse.c" break; case 259: #line 918 "parse.y" {sqlite3Pragma(pParse,&yymsp[-4].minor.yy198,&yymsp[-3].minor.yy198,&yymsp[-1].minor.yy198,0);} #line 3000 "parse.c" break; case 260: #line 919 "parse.y" {sqlite3Pragma(pParse,&yymsp[-1].minor.yy198,&yymsp[0].minor.yy198,0,0);} #line 3005 "parse.c" break; case 267: #line 932 "parse.y" { Token all; all.z = yymsp[-3].minor.yy198.z; all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy198.z) + yymsp[0].minor.yy0.n; sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy360, &all); } #line 3015 "parse.c" break; case 268: #line 941 "parse.y" { sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy198, &yymsp[-6].minor.yy198, yymsp[-5].minor.yy280, yymsp[-4].minor.yy30.a, yymsp[-4].minor.yy30.b, yymsp[-2].minor.yy151, yymsp[-1].minor.yy280, yymsp[0].minor.yy62, yymsp[-9].minor.yy280); yygotominor.yy198 = (yymsp[-6].minor.yy198.n==0?yymsp[-7].minor.yy198:yymsp[-6].minor.yy198); } #line 3023 "parse.c" break; case 269: case 272: #line 947 "parse.y" { yygotominor.yy280 = TK_BEFORE; } #line 3029 "parse.c" break; case 270: #line 948 "parse.y" { yygotominor.yy280 = TK_AFTER; } #line 3034 "parse.c" break; case 271: #line 949 "parse.y" { yygotominor.yy280 = TK_INSTEAD;} #line 3039 "parse.c" break; case 273: case 274: case 275: #line 954 "parse.y" {yygotominor.yy30.a = yymsp[0].major; yygotominor.yy30.b = 0;} #line 3046 "parse.c" break; case 276: #line 957 "parse.y" {yygotominor.yy30.a = TK_UPDATE; yygotominor.yy30.b = yymsp[0].minor.yy240;} #line 3051 "parse.c" break; case 277: case 278: #line 960 "parse.y" { yygotominor.yy280 = TK_ROW; } #line 3057 "parse.c" break; case 279: #line 962 "parse.y" { yygotominor.yy280 = TK_STATEMENT; } #line 3062 "parse.c" break; case 280: #line 965 "parse.y" { yygotominor.yy62 = 0; } #line 3067 "parse.c" break; case 281: #line 966 "parse.y" { yygotominor.yy62 = yymsp[0].minor.yy62; } #line 3072 "parse.c" break; case 282: #line 970 "parse.y" { yymsp[-2].minor.yy360->pNext = yymsp[0].minor.yy360; yygotominor.yy360 = yymsp[-2].minor.yy360; } #line 3080 "parse.c" break; case 283: #line 974 "parse.y" { yygotominor.yy360 = 0; } #line 3085 "parse.c" break; case 284: #line 980 "parse.y" { yygotominor.yy360 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy198, yymsp[-1].minor.yy418, yymsp[0].minor.yy62, yymsp[-4].minor.yy280); } #line 3090 "parse.c" break; case 285: #line 985 "parse.y" {yygotominor.yy360 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy198, yymsp[-4].minor.yy240, yymsp[-1].minor.yy418, 0, yymsp[-7].minor.yy280);} #line 3095 "parse.c" break; case 286: #line 988 "parse.y" {yygotominor.yy360 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy198, yymsp[-1].minor.yy240, 0, yymsp[0].minor.yy375, yymsp[-4].minor.yy280);} #line 3100 "parse.c" break; case 287: #line 992 "parse.y" {yygotominor.yy360 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy198, yymsp[0].minor.yy62);} #line 3105 "parse.c" break; case 288: #line 995 "parse.y" {yygotominor.yy360 = sqlite3TriggerSelectStep(yymsp[0].minor.yy375); } #line 3110 "parse.c" break; case 289: #line 998 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_RAISE, 0, 0, 0); yygotominor.yy62->iColumn = OE_Ignore; sqlite3ExprSpan(yygotominor.yy62, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } #line 3119 "parse.c" break; case 290: #line 1003 "parse.y" { yygotominor.yy62 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy198); yygotominor.yy62->iColumn = yymsp[-3].minor.yy280; sqlite3ExprSpan(yygotominor.yy62, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } #line 3128 "parse.c" break; case 291: #line 1011 "parse.y" {yygotominor.yy280 = OE_Rollback;} #line 3133 "parse.c" break; case 293: #line 1013 "parse.y" {yygotominor.yy280 = OE_Fail;} #line 3138 "parse.c" break; case 294: #line 1018 "parse.y" { sqlite3DropTrigger(pParse,yymsp[0].minor.yy151); } #line 3145 "parse.c" break; case 295: #line 1024 "parse.y" { sqlite3Attach(pParse, &yymsp[-3].minor.yy198, &yymsp[-1].minor.yy198, yymsp[0].minor.yy361.type, &yymsp[0].minor.yy361.key); } #line 3152 "parse.c" break; case 296: #line 1028 "parse.y" { yygotominor.yy361.type = 0; } #line 3157 "parse.c" break; case 297: #line 1029 "parse.y" { yygotominor.yy361.type=1; yygotominor.yy361.key = yymsp[0].minor.yy198; } #line 3162 "parse.c" break; case 298: #line 1030 "parse.y" { yygotominor.yy361.type=2; yygotominor.yy361.key = yymsp[0].minor.yy0; } #line 3167 "parse.c" break; case 301: #line 1036 "parse.y" { sqlite3Detach(pParse, &yymsp[0].minor.yy198); } #line 3174 "parse.c" break; case 302: #line 1042 "parse.y" {sqlite3Reindex(pParse, 0, 0);} #line 3179 "parse.c" break; case 303: #line 1043 "parse.y" {sqlite3Reindex(pParse, &yymsp[-1].minor.yy198, &yymsp[0].minor.yy198);} #line 3184 "parse.c" break; case 304: #line 1048 "parse.y" {sqlite3Analyze(pParse, 0, 0);} #line 3189 "parse.c" break; case 305: #line 1049 "parse.y" {sqlite3Analyze(pParse, &yymsp[-1].minor.yy198, &yymsp[0].minor.yy198);} #line 3194 "parse.c" break; case 306: #line 1054 "parse.y" { sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy151,&yymsp[0].minor.yy198); } #line 3201 "parse.c" break; case 307: #line 1057 "parse.y" { sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy198); } #line 3208 "parse.c" break; case 308: #line 1060 "parse.y" { sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy151); } #line 3215 "parse.c" break; }; yygoto = yyRuleInfo[yyruleno].lhs; yysize = yyRuleInfo[yyruleno].nrhs; yypParser->yyidx -= yysize; yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); if( yyact < YYNSTATE ){ |
︙ | ︙ | |||
3240 3241 3242 3243 3244 3245 3246 | if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); }else{ sqlite3ErrorMsg(pParse, "incomplete SQL statement"); } } | | | 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 | if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); }else{ sqlite3ErrorMsg(pParse, "incomplete SQL statement"); } } #line 3282 "parse.c" sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } /* ** The following is executed when the parser accepts */ static void yy_accept( |
︙ | ︙ |
Changes to SQLite.Interop/src/parse.h.
1 2 3 4 5 6 7 8 | #define TK_END_OF_FILE 1 #define TK_ILLEGAL 2 #define TK_SPACE 3 #define TK_UNCLOSED_STRING 4 #define TK_COMMENT 5 #define TK_FUNCTION 6 #define TK_COLUMN 7 #define TK_AGG_FUNCTION 8 | > | | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 | #define TK_END_OF_FILE 1 #define TK_ILLEGAL 2 #define TK_SPACE 3 #define TK_UNCLOSED_STRING 4 #define TK_COMMENT 5 #define TK_FUNCTION 6 #define TK_COLUMN 7 #define TK_AGG_FUNCTION 8 #define TK_AGG_COLUMN 9 #define TK_CONST_FUNC 10 #define TK_SEMI 11 #define TK_EXPLAIN 12 #define TK_QUERY 13 #define TK_PLAN 14 #define TK_BEGIN 15 #define TK_TRANSACTION 16 #define TK_DEFERRED 17 #define TK_IMMEDIATE 18 #define TK_EXCLUSIVE 19 #define TK_COMMIT 20 #define TK_END 21 #define TK_ROLLBACK 22 #define TK_CREATE 23 #define TK_TABLE 24 #define TK_TEMP 25 #define TK_LP 26 #define TK_RP 27 #define TK_AS 28 #define TK_COMMA 29 #define TK_ID 30 #define TK_ABORT 31 #define TK_AFTER 32 #define TK_ANALYZE 33 #define TK_ASC 34 #define TK_ATTACH 35 #define TK_BEFORE 36 #define TK_CASCADE 37 #define TK_CAST 38 #define TK_CONFLICT 39 #define TK_DATABASE 40 #define TK_DESC 41 #define TK_DETACH 42 #define TK_EACH 43 #define TK_FAIL 44 #define TK_FOR 45 #define TK_IGNORE 46 #define TK_INITIALLY 47 #define TK_INSTEAD 48 #define TK_LIKE_KW 49 #define TK_MATCH 50 #define TK_KEY 51 #define TK_OF 52 #define TK_OFFSET 53 #define TK_PRAGMA 54 #define TK_RAISE 55 #define TK_REPLACE 56 #define TK_RESTRICT 57 #define TK_ROW 58 #define TK_STATEMENT 59 #define TK_TRIGGER 60 #define TK_VACUUM 61 #define TK_VIEW 62 #define TK_REINDEX 63 #define TK_RENAME 64 #define TK_CTIME_KW 65 #define TK_ALTER 66 #define TK_OR 67 #define TK_AND 68 #define TK_NOT 69 #define TK_IS 70 #define TK_BETWEEN 71 #define TK_IN 72 #define TK_ISNULL 73 #define TK_NOTNULL 74 #define TK_NE 75 #define TK_EQ 76 #define TK_GT 77 #define TK_LE 78 #define TK_LT 79 #define TK_GE 80 #define TK_ESCAPE 81 #define TK_BITAND 82 #define TK_BITOR 83 #define TK_LSHIFT 84 #define TK_RSHIFT 85 #define TK_PLUS 86 #define TK_MINUS 87 #define TK_STAR 88 #define TK_SLASH 89 #define TK_REM 90 #define TK_CONCAT 91 #define TK_UMINUS 92 #define TK_UPLUS 93 #define TK_BITNOT 94 #define TK_STRING 95 #define TK_JOIN_KW 96 #define TK_CONSTRAINT 97 #define TK_DEFAULT 98 #define TK_NULL 99 #define TK_PRIMARY 100 #define TK_UNIQUE 101 #define TK_CHECK 102 #define TK_REFERENCES 103 #define TK_COLLATE 104 #define TK_AUTOINCR 105 #define TK_ON 106 #define TK_DELETE 107 #define TK_UPDATE 108 #define TK_INSERT 109 #define TK_SET 110 #define TK_DEFERRABLE 111 #define TK_FOREIGN 112 #define TK_DROP 113 #define TK_UNION 114 #define TK_ALL 115 #define TK_INTERSECT 116 #define TK_EXCEPT 117 #define TK_SELECT 118 #define TK_DISTINCT 119 #define TK_DOT 120 #define TK_FROM 121 #define TK_JOIN 122 #define TK_USING 123 #define TK_ORDER 124 #define TK_BY 125 #define TK_GROUP 126 #define TK_HAVING 127 #define TK_LIMIT 128 #define TK_WHERE 129 #define TK_INTO 130 #define TK_VALUES 131 #define TK_INTEGER 132 #define TK_FLOAT 133 #define TK_BLOB 134 #define TK_REGISTER 135 #define TK_VARIABLE 136 #define TK_EXISTS 137 #define TK_CASE 138 #define TK_WHEN 139 #define TK_THEN 140 #define TK_ELSE 141 #define TK_INDEX 142 #define TK_TO 143 #define TK_ADD 144 #define TK_COLUMNKW 145 |
Changes to SQLite.Interop/src/pragma.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* Ignore this whole file if pragmas are disabled */ |
︙ | ︙ | |||
622 623 624 625 626 627 628 | } }else #ifndef SQLITE_OMIT_INTEGRITY_CHECK if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){ int i, j, addr; | < < < < < < < < | | 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | } }else #ifndef SQLITE_OMIT_INTEGRITY_CHECK if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){ int i, j, addr; /* Code that appears at the end of the integrity check. If no error ** messages have been generated, output OK. Otherwise output the ** error message */ static const VdbeOpList endCode[] = { { OP_MemLoad, 0, 0, 0}, { OP_Integer, 0, 0, 0}, { OP_Ne, 0, 0, 0}, /* 2 */ { 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; int cnt = 0; if( OMIT_TEMPDB && i==1 ) continue; |
︙ | ︙ | |||
692 693 694 695 696 697 698 | for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){ Table *pTab = sqliteHashData(x); Index *pIdx; int loopTop; if( pTab->pIndex==0 ) continue; sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead); | < | | | < | | | | | | | | | | | | | 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | for(x=sqliteHashFirst(&db->aDb[i].tblHash); x; x=sqliteHashNext(x)){ Table *pTab = sqliteHashData(x); Index *pIdx; int loopTop; if( pTab->pIndex==0 ) continue; sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead); sqlite3VdbeAddOp(v, OP_MemInt, 0, 1); loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0); sqlite3VdbeAddOp(v, OP_MemIncr, 1, 0); for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ int jmp2; static const VdbeOpList idxErr[] = { { OP_MemIncr, 0, 0, 0}, { OP_String8, 0, 0, "rowid "}, { OP_Rowid, 1, 0, 0}, { OP_String8, 0, 0, " missing from index "}, { OP_String8, 0, 0, 0}, /* 4 */ { OP_Concat, 2, 0, 0}, { OP_Callback, 1, 0, 0}, }; sqlite3GenerateIndexKey(v, pIdx, 1); jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0); addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr); sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC); sqlite3VdbeJumpHere(v, jmp2); } sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1); sqlite3VdbeJumpHere(v, loopTop); for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ static const VdbeOpList cntIdx[] = { { OP_MemInt, 0, 2, 0}, { OP_Rewind, 0, 0, 0}, /* 1 */ { OP_MemIncr, 2, 0, 0}, { OP_Next, 0, 0, 0}, /* 3 */ { OP_MemLoad, 1, 0, 0}, { OP_MemLoad, 2, 0, 0}, { OP_Eq, 0, 0, 0}, /* 6 */ { OP_MemIncr, 0, 0, 0}, { OP_String8, 0, 0, "wrong # of entries in index "}, { OP_String8, 0, 0, 0}, /* 9 */ { OP_Concat, 0, 0, 0}, { OP_Callback, 1, 0, 0}, }; if( pIdx->tnum==0 ) continue; addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx); sqlite3VdbeChangeP1(v, addr+1, j+2); sqlite3VdbeChangeP2(v, addr+1, addr+4); sqlite3VdbeChangeP1(v, addr+3, j+2); sqlite3VdbeChangeP2(v, addr+3, addr+2); sqlite3VdbeJumpHere(v, addr+6); sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC); } } } addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); sqlite3VdbeJumpHere(v, addr+2); }else #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ #ifndef SQLITE_OMIT_UTF16 /* ** PRAGMA encoding ** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be" |
︙ | ︙ | |||
899 900 901 902 903 904 905 | 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; | | | | | 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | sqlite3VdbeSetNumCols(v, 2); sqlite3VdbeSetColName(v, 0, "database", P3_STATIC); sqlite3VdbeSetColName(v, 1, "status", P3_STATIC); for(i=0; i<db->nDb; i++){ Btree *pBt; Pager *pPager; if( db->aDb[i].zName==0 ) continue; sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC); pBt = db->aDb[i].pBt; if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC); }else{ int j = sqlite3pager_lockstate(pPager); sqlite3VdbeOp3(v, OP_String8, 0, 0, (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC); } sqlite3VdbeAddOp(v, OP_Callback, 2, 0); } }else #endif |
︙ | ︙ |
Changes to SQLite.Interop/src/prepare.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** 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. ** | | | 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.5 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** Fill the InitData structure with an error message that indicates |
︙ | ︙ | |||
454 455 456 457 458 459 460 | sqlite3ResetInternalSchema(db, 0); } if( pzTail ) *pzTail = sParse.zTail; rc = sParse.rc; #ifndef SQLITE_OMIT_EXPLAIN if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){ | > > > > > > | | | | | | > | 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 | sqlite3ResetInternalSchema(db, 0); } if( pzTail ) *pzTail = sParse.zTail; rc = sParse.rc; #ifndef SQLITE_OMIT_EXPLAIN if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){ if( sParse.explain==2 ){ sqlite3VdbeSetNumCols(sParse.pVdbe, 3); sqlite3VdbeSetColName(sParse.pVdbe, 0, "order", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 1, "from", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 2, "detail", P3_STATIC); }else{ sqlite3VdbeSetNumCols(sParse.pVdbe, 5); sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC); } } #endif prepare_out: if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } |
︙ | ︙ |
Changes to SQLite.Interop/src/printf.c.
︙ | ︙ | |||
159 160 161 162 163 164 165 | d = digit; digit += '0'; *val = (*val - d)*10.0; return digit; } #endif | > > > > > > > > | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | d = digit; digit += '0'; *val = (*val - d)*10.0; return digit; } #endif /* ** On machines with a small stack size, you can redefine the ** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for ** smaller values some %f conversions may go into an infinite loop. */ #ifndef SQLITE_PRINT_BUF_SIZE # define SQLITE_PRINT_BUF_SIZE 350 #endif #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */ /* ** The root program. All variations call this core. ** ** INPUTS: ** func This is a pointer to a function taking three arguments ** 1. A pointer to anything. Same as the "arg" parameter. |
︙ | ︙ | |||
436 437 438 439 440 441 442 | /* It makes more sense to use 0.5 */ for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1); #endif if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ exp = 0; if( realvalue>0.0 ){ | | | | | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | /* It makes more sense to use 0.5 */ for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1); #endif if( xtype==etFLOAT ) realvalue += rounder; /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ exp = 0; if( realvalue>0.0 ){ while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; } while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; } while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; } while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; } while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; } if( exp>350 || exp<-350 ){ bufpt = "NaN"; length = 3; break; } |
︙ | ︙ | |||
714 715 716 717 718 719 720 | pM->nAlloc = pM->nChar + nNewChar*2 + 1; if( pM->zText==pM->zBase ){ pM->zText = pM->xRealloc(0, pM->nAlloc); if( pM->zText && pM->nChar ){ memcpy(pM->zText, pM->zBase, pM->nChar); } }else{ | > | > > > | 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | pM->nAlloc = pM->nChar + nNewChar*2 + 1; if( pM->zText==pM->zBase ){ pM->zText = pM->xRealloc(0, pM->nAlloc); if( pM->zText && pM->nChar ){ memcpy(pM->zText, pM->zBase, pM->nChar); } }else{ char *zNew; zNew = pM->xRealloc(pM->zText, pM->nAlloc); if( zNew ){ pM->zText = zNew; } } } } if( pM->zText ){ if( nNewChar>0 ){ memcpy(&pM->zText[pM->nChar], zNewText, nNewChar); pM->nChar += nNewChar; |
︙ | ︙ | |||
752 753 754 755 756 757 758 | if( xRealloc ){ if( sM.zText==sM.zBase ){ sM.zText = xRealloc(0, sM.nChar+1); if( sM.zText ){ memcpy(sM.zText, sM.zBase, sM.nChar+1); } }else if( sM.nAlloc>sM.nChar+10 ){ | | > > > | | | 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 | if( xRealloc ){ if( sM.zText==sM.zBase ){ sM.zText = xRealloc(0, sM.nChar+1); if( sM.zText ){ memcpy(sM.zText, sM.zBase, sM.nChar+1); } }else if( sM.nAlloc>sM.nChar+10 ){ char *zNew = xRealloc(sM.zText, sM.nChar+1); if( zNew ){ sM.zText = zNew; } } } return sM.zText; } /* ** Realloc that is a real function, not a macro. */ static void *printf_realloc(void *old, int size){ return sqliteRealloc(old,size); } /* ** Print into memory obtained from sqliteMalloc(). Use the internal ** %-conversion extensions. */ char *sqlite3VMPrintf(const char *zFormat, va_list ap){ char zBase[SQLITE_PRINT_BUF_SIZE]; return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap); } /* ** Print into memory obtained from sqliteMalloc(). Use the internal ** %-conversion extensions. */ char *sqlite3MPrintf(const char *zFormat, ...){ va_list ap; char *z; char zBase[SQLITE_PRINT_BUF_SIZE]; va_start(ap, zFormat); z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap); va_end(ap); return z; } /* |
︙ | ︙ |
Changes to SQLite.Interop/src/random.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** This file contains code to implement a pseudo-random number ** generator (PRNG) for SQLite. ** ** Random numbers are used by some of the database backends in order ** to generate random integer keys for tables or random filenames. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** This file contains code to implement a pseudo-random number ** generator (PRNG) for SQLite. ** ** Random numbers are used by some of the database backends in order ** to generate random integer keys for tables or random filenames. ** ** $Id: random.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" /* ** Get a single 8-bit random value from the RC4 PRNG. The Mutex |
︙ | ︙ |
Changes to SQLite.Interop/src/select.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "../interop.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. |
︙ | ︙ | |||
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | pNew->pOrderBy = pOrderBy; pNew->isDistinct = isDistinct; pNew->op = TK_SELECT; pNew->pLimit = pLimit; pNew->pOffset = pOffset; pNew->iLimit = -1; pNew->iOffset = -1; } return pNew; } /* ** Given 1 to 3 identifiers preceeding the JOIN keyword, determine the ** type of join. Return an integer constant that expresses that type ** in terms of the following bit values: ** ** JT_INNER ** JT_OUTER ** JT_NATURAL ** JT_LEFT ** JT_RIGHT ** ** A full outer join is the combination of JT_LEFT and JT_RIGHT. ** | > > > > | 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 | pNew->pOrderBy = pOrderBy; pNew->isDistinct = isDistinct; pNew->op = TK_SELECT; pNew->pLimit = pLimit; pNew->pOffset = pOffset; pNew->iLimit = -1; pNew->iOffset = -1; pNew->addrOpenVirt[0] = -1; pNew->addrOpenVirt[1] = -1; pNew->addrOpenVirt[2] = -1; } return pNew; } /* ** Given 1 to 3 identifiers preceeding the JOIN keyword, determine the ** type of join. Return an integer constant that expresses that type ** in terms of the following bit values: ** ** JT_INNER ** JT_CROSS ** JT_OUTER ** JT_NATURAL ** JT_LEFT ** JT_RIGHT ** ** A full outer join is the combination of JT_LEFT and JT_RIGHT. ** |
︙ | ︙ | |||
91 92 93 94 95 96 97 | } keywords[] = { { "natural", 7, JT_NATURAL }, { "left", 4, JT_LEFT|JT_OUTER }, { "right", 5, JT_RIGHT|JT_OUTER }, { "full", 4, JT_LEFT|JT_RIGHT|JT_OUTER }, { "outer", 5, JT_OUTER }, { "inner", 5, JT_INNER }, | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | } keywords[] = { { "natural", 7, JT_NATURAL }, { "left", 4, JT_LEFT|JT_OUTER }, { "right", 5, JT_RIGHT|JT_OUTER }, { "full", 4, JT_LEFT|JT_RIGHT|JT_OUTER }, { "outer", 5, JT_OUTER }, { "inner", 5, JT_INNER }, { "cross", 5, JT_INNER|JT_CROSS }, }; int i, j; apAll[0] = pA; apAll[1] = pB; apAll[2] = pC; for(i=0; i<3 && apAll[i]; i++){ p = apAll[i]; |
︙ | ︙ | |||
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 | */ static void addWhereTerm( const char *zCol, /* Name of the column */ const Table *pTab1, /* First table */ const char *zAlias1, /* Alias for first table. May be NULL */ const Table *pTab2, /* Second table */ const char *zAlias2, /* Alias for second table. May be NULL */ Expr **ppExpr /* Add the equality term to this expression */ ){ Expr *pE1a, *pE1b, *pE1c; Expr *pE2a, *pE2b, *pE2c; Expr *pE; pE1a = createIdExpr(zCol); pE2a = createIdExpr(zCol); if( zAlias1==0 ){ zAlias1 = pTab1->zName; } pE1b = createIdExpr(zAlias1); if( zAlias2==0 ){ zAlias2 = pTab2->zName; } pE2b = createIdExpr(zAlias2); pE1c = sqlite3Expr(TK_DOT, pE1b, pE1a, 0); pE2c = sqlite3Expr(TK_DOT, pE2b, pE2a, 0); pE = sqlite3Expr(TK_EQ, pE1c, pE2c, 0); ExprSetProperty(pE, EP_FromJoin); *ppExpr = sqlite3ExprAnd(*ppExpr, pE); } /* ** Set the EP_FromJoin property on all terms of the given expression. ** ** The EP_FromJoin property is used on terms of an expression to tell ** the LEFT OUTER JOIN processing logic that this term is part of the ** join restriction specified in the ON or USING clause and not a part ** of the more general WHERE clause. These terms are moved over to the ** WHERE clause during join processing but we need to remember that they ** originated in the ON or USING clause. */ | > > > > > > > > > > > > > > > > > > | > | | 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 | */ static void addWhereTerm( const char *zCol, /* Name of the column */ const Table *pTab1, /* First table */ const char *zAlias1, /* Alias for first table. May be NULL */ const Table *pTab2, /* Second table */ const char *zAlias2, /* Alias for second table. May be NULL */ int iRightJoinTable, /* VDBE cursor for the right table */ Expr **ppExpr /* Add the equality term to this expression */ ){ Expr *pE1a, *pE1b, *pE1c; Expr *pE2a, *pE2b, *pE2c; Expr *pE; pE1a = createIdExpr(zCol); pE2a = createIdExpr(zCol); if( zAlias1==0 ){ zAlias1 = pTab1->zName; } pE1b = createIdExpr(zAlias1); if( zAlias2==0 ){ zAlias2 = pTab2->zName; } pE2b = createIdExpr(zAlias2); pE1c = sqlite3Expr(TK_DOT, pE1b, pE1a, 0); pE2c = sqlite3Expr(TK_DOT, pE2b, pE2a, 0); pE = sqlite3Expr(TK_EQ, pE1c, pE2c, 0); ExprSetProperty(pE, EP_FromJoin); pE->iRightJoinTable = iRightJoinTable; *ppExpr = sqlite3ExprAnd(*ppExpr, pE); } /* ** Set the EP_FromJoin property on all terms of the given expression. ** And set the Expr.iRightJoinTable to iTable for every term in the ** expression. ** ** The EP_FromJoin property is used on terms of an expression to tell ** the LEFT OUTER JOIN processing logic that this term is part of the ** join restriction specified in the ON or USING clause and not a part ** of the more general WHERE clause. These terms are moved over to the ** WHERE clause during join processing but we need to remember that they ** originated in the ON or USING clause. ** ** The Expr.iRightJoinTable tells the WHERE clause processing that the ** expression depends on table iRightJoinTable even if that table is not ** explicitly mentioned in the expression. That information is needed ** for cases like this: ** ** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5 ** ** The where clause needs to defer the handling of the t1.x=5 ** term until after the t2 loop of the join. In that way, a ** NULL t2 row will be inserted whenever t1.x!=5. If we do not ** defer the handling of t1.x=5, it will be processed immediately ** after the t1 loop and rows with t1.x!=5 will never appear in ** the output, which is incorrect. */ static void setJoinExpr(Expr *p, int iTable){ while( p ){ ExprSetProperty(p, EP_FromJoin); p->iRightJoinTable = iTable; setJoinExpr(p->pLeft, iTable); p = p->pRight; } } /* ** This routine processes the join information for a SELECT statement. ** ON and USING clauses are converted into extra terms of the WHERE clause. |
︙ | ︙ | |||
254 255 256 257 258 259 260 | "an ON or USING clause", 0); return 1; } for(j=0; j<pLeftTab->nCol; j++){ char *zName = pLeftTab->aCol[j].zName; if( columnIndex(pRightTab, zName)>=0 ){ addWhereTerm(zName, pLeftTab, pLeft->zAlias, | | > > | | 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 | "an ON or USING clause", 0); return 1; } for(j=0; j<pLeftTab->nCol; j++){ char *zName = pLeftTab->aCol[j].zName; if( columnIndex(pRightTab, zName)>=0 ){ addWhereTerm(zName, pLeftTab, pLeft->zAlias, pRightTab, pRight->zAlias, pRight->iCursor, &p->pWhere); } } } /* Disallow both ON and USING clauses in the same join */ if( pLeft->pOn && pLeft->pUsing ){ sqlite3ErrorMsg(pParse, "cannot have both ON and USING " "clauses in the same join"); return 1; } /* Add the ON clause to the end of the WHERE clause, connected by ** an AND operator. */ if( pLeft->pOn ){ setJoinExpr(pLeft->pOn, pRight->iCursor); p->pWhere = sqlite3ExprAnd(p->pWhere, pLeft->pOn); pLeft->pOn = 0; } /* Create extra terms on the WHERE clause for each column named ** in the USING clause. Example: If the two tables to be joined are ** A and B and the USING clause names X, Y, and Z, then add this |
︙ | ︙ | |||
293 294 295 296 297 298 299 | char *zName = pList->a[j].zName; if( columnIndex(pLeftTab, zName)<0 || columnIndex(pRightTab, zName)<0 ){ sqlite3ErrorMsg(pParse, "cannot join using column %s - column " "not present in both tables", zName); return 1; } addWhereTerm(zName, pLeftTab, pLeft->zAlias, | | > | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | char *zName = pList->a[j].zName; if( columnIndex(pLeftTab, zName)<0 || columnIndex(pRightTab, zName)<0 ){ sqlite3ErrorMsg(pParse, "cannot join using column %s - column " "not present in both tables", zName); return 1; } addWhereTerm(zName, pLeftTab, pLeft->zAlias, pRightTab, pRight->zAlias, pRight->iCursor, &p->pWhere); } } } return 0; } /* |
︙ | ︙ | |||
323 324 325 326 327 328 329 | /* ** Insert code into "v" that will push the record on the top of the ** stack into the sorter. */ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){ sqlite3ExprCodeExprList(pParse, pOrderBy); | > > | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* ** Insert code into "v" that will push the record on the top of the ** stack into the sorter. */ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){ sqlite3ExprCodeExprList(pParse, pOrderBy); sqlite3VdbeAddOp(v, OP_Sequence, pOrderBy->iECursor, 0); sqlite3VdbeAddOp(v, OP_Pull, pOrderBy->nExpr + 1, 0); sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr + 2, 0); sqlite3VdbeAddOp(v, OP_IdxInsert, pOrderBy->iECursor, 0); } /* ** Add code to implement the OFFSET and LIMIT */ static void codeLimiter( Vdbe *v, /* Generate code into this VM */ Select *p, /* The SELECT statement being coded */ int iContinue, /* Jump here to skip the current record */ int iBreak, /* Jump here to end the loop */ int nPop /* Number of times to pop stack when jumping */ ){ if( p->iOffset>=0 && iContinue!=0 ){ int addr = sqlite3VdbeCurrentAddr(v) + 3; if( nPop>0 ) addr++; sqlite3VdbeAddOp(v, OP_MemIncr, p->iOffset, 0); sqlite3VdbeAddOp(v, OP_IfMemPos, p->iOffset, addr); if( nPop>0 ){ sqlite3VdbeAddOp(v, OP_Pop, nPop, 0); } sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue); VdbeComment((v, "# skip OFFSET records")); } if( p->iLimit>=0 && iBreak!=0 ){ sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, iBreak); VdbeComment((v, "# exit when LIMIT reached")); } } /* ** Add code that will check to make sure the top N elements of the ** stack are distinct. iTab is a sorting index that holds previously ** seen combinations of the N values. A new entry is made in iTab ** if the current N values are new. ** ** A jump to addrRepeat is made and the K values are popped from the ** stack if the top N elements are not distinct. */ static void codeDistinct( Vdbe *v, /* Generate code into this VM */ int iTab, /* A sorting index used to test for distinctness */ int addrRepeat, /* Jump to here if not distinct */ int N, /* The top N elements of the stack must be distinct */ int K /* Pop K elements from the stack if indistinct */ ){ #if NULL_ALWAYS_DISTINCT sqlite3VdbeAddOp(v, OP_IsNull, -N, sqlite3VdbeCurrentAddr(v)+6); #endif sqlite3VdbeAddOp(v, OP_MakeRecord, -N, 0); sqlite3VdbeAddOp(v, OP_Distinct, iTab, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, K, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, addrRepeat); VdbeComment((v, "# skip indistinct records")); sqlite3VdbeAddOp(v, OP_IdxInsert, iTab, 0); } /* ** This routine generates the code for the inside of the inner loop ** of a SELECT. ** ** If srcTab and nColumn are both zero, then the pEList expressions ** are evaluated in order to get the data for this row. If nColumn>0 |
︙ | ︙ | |||
409 410 411 412 413 414 415 | /* If the DISTINCT keyword was present on the SELECT statement ** and this row has been seen before, then do not make this row ** part of the result. */ if( hasDistinct ){ int n = pEList->nExpr; | < < < < < < < < < < | < > > | > | 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 | /* If the DISTINCT keyword was present on the SELECT statement ** and this row has been seen before, then do not make this row ** part of the result. */ if( hasDistinct ){ int n = pEList->nExpr; codeDistinct(v, distinct, iContinue, n, n+1); if( pOrderBy==0 ){ codeLimiter(v, p, iContinue, iBreak, nColumn); } } switch( eDest ){ /* In this mode, write each query result to the key of the temporary ** table iParm. */ #ifndef SQLITE_OMIT_COMPOUND_SELECT case SRT_Union: { sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, NULL_ALWAYS_DISTINCT); if( aff ){ sqlite3VdbeChangeP3(v, -1, aff, P3_STATIC); } sqlite3VdbeAddOp(v, OP_IdxInsert, iParm, 0); break; } /* Construct a record from the query result, but instead of ** saving that record, use it as a key to delete elements from ** the temporary table iParm. |
︙ | ︙ | |||
454 455 456 457 458 459 460 | break; } #endif /* Store the result as data using a unique key. */ case SRT_Table: | | | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | break; } #endif /* Store the result as data using a unique key. */ case SRT_Table: case SRT_VirtualTab: { sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); if( pOrderBy ){ pushOntoSorter(pParse, v, pOrderBy); }else{ sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_Insert, iParm, 0); |
︙ | ︙ | |||
480 481 482 483 484 485 486 487 488 489 490 491 492 493 | int addr2; assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0); if( pOrderBy ){ pushOntoSorter(pParse, v, pOrderBy); }else{ char aff = (iParm>>16)&0xFF; aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff); sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1); sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0); } | > > > > | | 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 | int addr2; assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0); if( pOrderBy ){ /* At first glance you would think we could optimize out the ** ORDER BY in this case since the order of entries in the set ** does not matter. But there might be a LIMIT clause, in which ** case the order does matter */ pushOntoSorter(pParse, v, pOrderBy); }else{ char aff = (iParm>>16)&0xFF; aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff); sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1); sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0); } sqlite3VdbeJumpHere(v, addr2); break; } /* If this is a scalar select that is part of an expression, then ** store the results in the appropriate memory cell and break out ** of the scan loop. */ |
︙ | ︙ | |||
513 514 515 516 517 518 519 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ /* Send the data to the callback function or to a subroutine. In the ** case of a subroutine, the subroutine itself is responsible for ** popping the data from the stack. */ case SRT_Subroutine: | | < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | < < | < < < | < < < < < < < < < < < < < | | < < | | > | | | 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ /* Send the data to the callback function or to a subroutine. In the ** case of a subroutine, the subroutine itself is responsible for ** popping the data from the stack. */ case SRT_Subroutine: case SRT_Callback: { if( pOrderBy ){ sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); pushOntoSorter(pParse, v, pOrderBy); }else if( eDest==SRT_Subroutine ){ sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm); }else{ sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0); } break; } #if !defined(SQLITE_OMIT_TRIGGER) /* Discard the results. This is used for SELECT statements inside ** the body of a TRIGGER. The purpose of such selects is to call ** user-defined functions that have side effects. We do not care ** about the actual results of the select. */ default: { assert( eDest==SRT_Discard ); sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0); break; } #endif } return 0; } /* ** Given an expression list, generate a KeyInfo structure that records ** the collating sequence for each expression in that expression list. ** ** If the ExprList is an ORDER BY or GROUP BY clause then the resulting ** KeyInfo structure is appropriate for initializing a virtual index to ** implement that clause. If the ExprList is the result set of a SELECT ** then the KeyInfo structure is appropriate for initializing a virtual ** index to implement a DISTINCT test. ** ** Space to hold the KeyInfo structure is obtain from malloc. The calling ** function is responsible for seeing that this structure is eventually ** freed. Add the KeyInfo structure to the P3 field of an opcode using ** P3_KEYINFO_HANDOFF is the usual way of dealing with this. */ static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){ sqlite3 *db = pParse->db; int nExpr; KeyInfo *pInfo; struct ExprList_item *pItem; int i; nExpr = pList->nExpr; pInfo = sqliteMalloc( sizeof(*pInfo) + nExpr*(sizeof(CollSeq*)+1) ); if( pInfo ){ pInfo->aSortOrder = (char*)&pInfo->aColl[nExpr]; pInfo->nField = nExpr; pInfo->enc = db->enc; for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){ CollSeq *pColl; pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr); if( !pColl ){ pColl = db->pDfltColl; } pInfo->aColl[i] = pColl; pInfo->aSortOrder[i] = pItem->sortOrder; } } return pInfo; } /* ** If the inner loop was generated using a non-null pOrderBy argument, ** then the results were placed in a sorter. After the loop is terminated ** we need to run the sorter and output the results. The following ** routine generates the code needed to do that. */ static void generateSortTail( Parse *pParse, /* The parsing context */ Select *p, /* The SELECT statement */ Vdbe *v, /* Generate code into this VDBE */ int nColumn, /* Number of columns of data */ int eDest, /* Write the sorted results here */ int iParm /* Optional parameter associated with eDest */ ){ int brk = sqlite3VdbeMakeLabel(v); int cont = sqlite3VdbeMakeLabel(v); int addr; int iTab; ExprList *pOrderBy = p->pOrderBy; iTab = pOrderBy->iECursor; addr = 1 + sqlite3VdbeAddOp(v, OP_Sort, iTab, brk); codeLimiter(v, p, cont, brk, 0); sqlite3VdbeAddOp(v, OP_Column, iTab, pOrderBy->nExpr + 1); switch( eDest ){ case SRT_Table: case SRT_VirtualTab: { sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_Insert, iParm, 0); break; } #ifndef SQLITE_OMIT_SUBQUERY case SRT_Set: { assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, 1, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, "n", P3_STATIC); sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0); break; } case SRT_Exists: case SRT_Mem: { assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); break; } #endif case SRT_Callback: case SRT_Subroutine: { int i; sqlite3VdbeAddOp(v, OP_Integer, p->pEList->nExpr, 0); |
︙ | ︙ | |||
633 634 635 636 637 638 639 | break; } default: { /* Do nothing */ break; } } | < | | | < | 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | break; } default: { /* Do nothing */ break; } } sqlite3VdbeResolveLabel(v, cont); sqlite3VdbeAddOp(v, OP_Next, iTab, addr); sqlite3VdbeResolveLabel(v, brk); } /* ** Return a pointer to a string containing the 'declaration type' of the ** expression pExpr. The string may be treated as static by the caller. ** ** If the declaration type is the exact datatype definition extracted from |
︙ | ︙ | |||
1301 1302 1303 1304 1305 1306 1307 | sqlite3VdbeAddOp(v, OP_MemStore, iMem, 1); VdbeComment((v, "# OFFSET counter")); p->iOffset = iMem; } } /* | < < < < < < < < < < | | < > | > | > > > > > > | > > > > > > | | | | < < < < < < < < < < < < < < < < | < < < < < < < < < | < < < < | 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | sqlite3VdbeAddOp(v, OP_MemStore, iMem, 1); VdbeComment((v, "# OFFSET counter")); p->iOffset = iMem; } } /* ** Allocate a virtual index to use for sorting. */ static void createSortingIndex(Parse *pParse, Select *p, ExprList *pOrderBy){ if( pOrderBy ){ int addr; assert( pOrderBy->iECursor==0 ); pOrderBy->iECursor = pParse->nTab++; addr = sqlite3VdbeAddOp(pParse->pVdbe, OP_OpenVirtual, pOrderBy->iECursor, pOrderBy->nExpr+1); assert( p->addrOpenVirt[2] == -1 ); p->addrOpenVirt[2] = addr; } } /* ** The opcode at addr is an OP_OpenVirtual that created a sorting ** index tha we ended up not needing. This routine changes that ** opcode to OP_Noop. */ static void uncreateSortingIndex(Parse *pParse, int addr){ Vdbe *v = pParse->pVdbe; VdbeOp *pOp = sqlite3VdbeGetOp(v, addr); sqlite3VdbeChangeP3(v, addr, 0, 0); pOp->opcode = OP_Noop; pOp->p1 = 0; pOp->p2 = 0; } #ifndef SQLITE_OMIT_COMPOUND_SELECT /* ** Return the appropriate collating sequence for the iCol-th column of ** the result set for the compound-select statement "p". Return NULL if ** the column has no default collating sequence. ** |
︙ | ︙ | |||
1419 1420 1421 1422 1423 1424 1425 | int eDest, /* \___ Store query results as specified */ int iParm, /* / by these two parameters. */ char *aff /* If eDest is SRT_Union, the affinity string */ ){ int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ | < < < > > > > > | 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 | int eDest, /* \___ Store query results as specified */ int iParm, /* / by these two parameters. */ char *aff /* If eDest is SRT_Union, the affinity string */ ){ int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ int nCol; /* Number of columns in the result set */ ExprList *pOrderBy; /* The ORDER BY clause on p */ int aSetP2[2]; /* Set P2 value of these op to number of columns */ int nSetP2 = 0; /* Number of slots in aSetP2[] used */ /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT. */ if( p==0 || p->pPrior==0 ){ rc = 1; goto multi_select_end; } pPrior = p->pPrior; assert( pPrior->pRightmost!=pPrior ); assert( pPrior->pRightmost==p->pRightmost ); if( pPrior->pOrderBy ){ sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before", selectOpName(p->op)); rc = 1; goto multi_select_end; } if( pPrior->pLimit ){ |
︙ | ︙ | |||
1453 1454 1455 1456 1457 1458 1459 | */ v = sqlite3GetVdbe(pParse); if( v==0 ){ rc = 1; goto multi_select_end; } | < < < < < < < < < < < | > | < < > | | 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 | */ v = sqlite3GetVdbe(pParse); if( v==0 ){ rc = 1; goto multi_select_end; } /* Create the destination temporary table if necessary */ if( eDest==SRT_VirtualTab ){ assert( p->pEList ); assert( nSetP2<sizeof(aSetP2)/sizeof(aSetP2[0]) ); aSetP2[nSetP2++] = sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0); eDest = SRT_Table; } /* Generate code for the left and right SELECT statements. */ pOrderBy = p->pOrderBy; switch( p->op ){ case TK_ALL: { if( pOrderBy==0 ){ assert( !pPrior->pLimit ); pPrior->pLimit = p->pLimit; pPrior->pOffset = p->pOffset; rc = sqlite3Select(pParse, pPrior, eDest, iParm, 0, 0, 0, aff); if( rc ){ goto multi_select_end; } |
︙ | ︙ | |||
1506 1507 1508 1509 1510 1511 1512 | } case TK_EXCEPT: case TK_UNION: { int unionTab; /* Cursor number of the temporary table holding result */ int op = 0; /* One of the SRT_ operations to apply to self */ int priorOp; /* The SRT_ operation to apply to prior selects */ Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */ | < | < | | | | < | > > > < < > < > | 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 | } case TK_EXCEPT: case TK_UNION: { int unionTab; /* Cursor number of the temporary table holding result */ int op = 0; /* One of the SRT_ operations to apply to self */ int priorOp; /* The SRT_ operation to apply to prior selects */ Expr *pLimit, *pOffset; /* Saved values of p->nLimit and p->nOffset */ int addr; priorOp = p->op==TK_ALL ? SRT_Table : SRT_Union; if( eDest==priorOp && pOrderBy==0 && !p->pLimit && !p->pOffset ){ /* We can reuse a temporary table generated by a SELECT to our ** right. */ unionTab = iParm; }else{ /* We will need to create our own temporary table to hold the ** intermediate results. */ unionTab = pParse->nTab++; if( pOrderBy && matchOrderbyToColumn(pParse, p, pOrderBy, unionTab,1) ){ rc = 1; goto multi_select_end; } addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, unionTab, 0); if( priorOp==SRT_Table ){ assert( nSetP2<sizeof(aSetP2)/sizeof(aSetP2[0]) ); aSetP2[nSetP2++] = addr; }else{ assert( p->addrOpenVirt[0] == -1 ); p->addrOpenVirt[0] = addr; p->pRightmost->usesVirt = 1; } createSortingIndex(pParse, p, pOrderBy); assert( p->pEList ); } /* Code the SELECT statements to our left */ assert( !pPrior->pOrderBy ); rc = sqlite3Select(pParse, pPrior, priorOp, unionTab, 0, 0, 0, aff); if( rc ){ goto multi_select_end; } /* Code the current SELECT statement */ switch( p->op ){ case TK_EXCEPT: op = SRT_Except; break; case TK_UNION: op = SRT_Union; break; case TK_ALL: op = SRT_Table; break; } p->pPrior = 0; p->pOrderBy = 0; p->disallowOrderBy = pOrderBy!=0; pLimit = p->pLimit; p->pLimit = 0; pOffset = p->pOffset; p->pOffset = 0; rc = sqlite3Select(pParse, p, op, unionTab, 0, 0, 0, aff); p->pPrior = pPrior; p->pOrderBy = pOrderBy; |
︙ | ︙ | |||
1587 1588 1589 1590 1591 1592 1593 | } iBreak = sqlite3VdbeMakeLabel(v); iCont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Rewind, unionTab, iBreak); computeLimitRegisters(pParse, p); iStart = sqlite3VdbeCurrentAddr(v); rc = selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr, | | | 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 | } iBreak = sqlite3VdbeMakeLabel(v); iCont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Rewind, unionTab, iBreak); computeLimitRegisters(pParse, p); iStart = sqlite3VdbeCurrentAddr(v); rc = selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr, pOrderBy, -1, eDest, iParm, iCont, iBreak, 0); if( rc ){ rc = 1; goto multi_select_end; } sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp(v, OP_Next, unionTab, iStart); |
︙ | ︙ | |||
1612 1613 1614 1615 1616 1617 1618 | /* INTERSECT is different from the others since it requires ** two temporary tables. Hence it has its own case. Begin ** by allocating the tables we will need. */ tab1 = pParse->nTab++; tab2 = pParse->nTab++; | | > | < | < < < > | | < < < < | 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 | /* INTERSECT is different from the others since it requires ** two temporary tables. Hence it has its own case. Begin ** by allocating the tables we will need. */ tab1 = pParse->nTab++; tab2 = pParse->nTab++; if( pOrderBy && matchOrderbyToColumn(pParse,p,pOrderBy,tab1,1) ){ rc = 1; goto multi_select_end; } createSortingIndex(pParse, p, pOrderBy); addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab1, 0); assert( p->addrOpenVirt[0] == -1 ); p->addrOpenVirt[0] = addr; p->pRightmost->usesVirt = 1; assert( p->pEList ); /* Code the SELECTs to our left into temporary table "tab1". */ rc = sqlite3Select(pParse, pPrior, SRT_Union, tab1, 0, 0, 0, aff); if( rc ){ goto multi_select_end; } /* Code the current SELECT into temporary table "tab2" */ addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab2, 0); assert( p->addrOpenVirt[1] == -1 ); p->addrOpenVirt[1] = addr; p->pPrior = 0; pLimit = p->pLimit; p->pLimit = 0; pOffset = p->pOffset; p->pOffset = 0; rc = sqlite3Select(pParse, p, SRT_Union, tab2, 0, 0, 0, aff); p->pPrior = pPrior; |
︙ | ︙ | |||
1670 1671 1672 1673 1674 1675 1676 | iBreak = sqlite3VdbeMakeLabel(v); iCont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Rewind, tab1, iBreak); computeLimitRegisters(pParse, p); iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0); sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont); rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr, | | | 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 | iBreak = sqlite3VdbeMakeLabel(v); iCont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Rewind, tab1, iBreak); computeLimitRegisters(pParse, p); iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0); sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont); rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr, pOrderBy, -1, eDest, iParm, iCont, iBreak, 0); if( rc ){ rc = 1; goto multi_select_end; } sqlite3VdbeResolveLabel(v, iCont); sqlite3VdbeAddOp(v, OP_Next, tab1, iStart); |
︙ | ︙ | |||
1699 1700 1701 1702 1703 1704 1705 | rc = 1; goto multi_select_end; } /* Set the number of columns in temporary tables */ nCol = p->pEList->nExpr; | | < | | > > > | | | | | | > | < | > > > > > > > | | | > | | > > > > > > > > | | | < | | > > > > > > > > < < | | | < < < < < | 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 | rc = 1; goto multi_select_end; } /* Set the number of columns in temporary tables */ nCol = p->pEList->nExpr; while( nSetP2 ){ sqlite3VdbeChangeP2(v, aSetP2[--nSetP2], nCol); } /* Compute collating sequences used by either the ORDER BY clause or ** by any temporary tables needed to implement the compound select. ** Attach the KeyInfo structure to all temporary tables. Invoke the ** ORDER BY processing if there is an ORDER BY clause. ** ** This section is run by the right-most SELECT statement only. ** SELECT statements to the left always skip this part. The right-most ** SELECT might also skip this part if it has no ORDER BY clause and ** no temp tables are required. */ if( pOrderBy || p->usesVirt ){ int i; /* Loop counter */ KeyInfo *pKeyInfo; /* Collating sequence for the result set */ Select *pLoop; /* For looping through SELECT statements */ CollSeq **apColl; CollSeq **aCopy; assert( p->pRightmost==p ); pKeyInfo = sqliteMalloc(sizeof(*pKeyInfo)+nCol*2*sizeof(CollSeq*) + nCol); if( !pKeyInfo ){ rc = SQLITE_NOMEM; goto multi_select_end; } pKeyInfo->enc = pParse->db->enc; pKeyInfo->nField = nCol; for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){ *apColl = multiSelectCollSeq(pParse, p, i); if( 0==*apColl ){ *apColl = pParse->db->pDfltColl; } } for(pLoop=p; pLoop; pLoop=pLoop->pPrior){ for(i=0; i<2; i++){ int addr = pLoop->addrOpenVirt[i]; if( addr<0 ){ /* If [0] is unused then [1] is also unused. So we can ** always safely abort as soon as the first unused slot is found */ assert( pLoop->addrOpenVirt[1]<0 ); break; } sqlite3VdbeChangeP2(v, addr, nCol); sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO); } } if( pOrderBy ){ struct ExprList_item *pOTerm = pOrderBy->a; int nExpr = pOrderBy->nExpr; int addr; u8 *pSortOrder; aCopy = (CollSeq**)&pKeyInfo[1]; pSortOrder = pKeyInfo->aSortOrder = (u8*)&aCopy[nExpr]; memcpy(aCopy, pKeyInfo->aColl, nCol*sizeof(CollSeq*)); apColl = pKeyInfo->aColl; for(i=0; i<pOrderBy->nExpr; i++, pOTerm++, apColl++, pSortOrder++){ Expr *pExpr = pOTerm->pExpr; char *zName = pOTerm->zName; assert( pExpr->op==TK_COLUMN && pExpr->iColumn<nCol ); if( zName ){ *apColl = sqlite3LocateCollSeq(pParse, zName, -1); }else{ *apColl = aCopy[pExpr->iColumn]; } *pSortOrder = pOTerm->sortOrder; } assert( p->pRightmost==p ); assert( p->addrOpenVirt[2]>=0 ); addr = p->addrOpenVirt[2]; sqlite3VdbeChangeP2(v, addr, p->pEList->nExpr+2); pKeyInfo->nField = pOrderBy->nExpr; sqlite3VdbeChangeP3(v, addr, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); pKeyInfo = 0; generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm); } sqliteFree(pKeyInfo); } multi_select_end: return rc; } #endif /* SQLITE_OMIT_COMPOUND_SELECT */ #ifndef SQLITE_OMIT_VIEW /* ** Scan through the expression pExpr. Replace every reference to |
︙ | ︙ | |||
1943 1944 1945 1946 1947 1948 1949 | if( (pSub->pLimit && p->pLimit) || pSub->pOffset || (pSub->pLimit && isAgg) ) return 0; if( pSubSrc->nSrc==0 ) return 0; if( pSub->isDistinct && (pSrc->nSrc>1 || isAgg) ){ return 0; } if( p->isDistinct && subqueryIsAgg ) return 0; | | | 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 | if( (pSub->pLimit && p->pLimit) || pSub->pOffset || (pSub->pLimit && isAgg) ) return 0; if( pSubSrc->nSrc==0 ) return 0; if( pSub->isDistinct && (pSrc->nSrc>1 || isAgg) ){ return 0; } if( p->isDistinct && subqueryIsAgg ) return 0; if( (p->disallowOrderBy || p->pOrderBy) && pSub->pOrderBy ) return 0; /* Restriction 3: If the subquery is a join, make sure the subquery is ** not used as the right operand of an outer join. Examples of why this ** is not allowed: ** ** t1 LEFT OUTER JOIN (t2 JOIN t3) ** |
︙ | ︙ | |||
2171 2172 2173 2174 2175 2176 2177 | ** The column names have already been generated in the calling function. */ v = sqlite3GetVdbe(pParse); if( v==0 ) return 0; /* If the output is destined for a temporary table, open that table. */ | | | < | 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 | ** The column names have already been generated in the calling function. */ v = sqlite3GetVdbe(pParse); if( v==0 ) return 0; /* If the output is destined for a temporary table, open that table. */ if( eDest==SRT_VirtualTab ){ sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 1); } /* Generating code to find the min or the max. Basically all we have ** to do is find the first or the last entry in the chosen index. If ** the min() or max() is on the INTEGER PRIMARY KEY, then find the first ** or last entry in the main table. */ |
︙ | ︙ | |||
2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 | Parse *pParse, /* The parser context */ Select *p, /* The SELECT statement being coded. */ NameContext *pOuterNC /* The outer name context. May be NULL. */ ){ ExprList *pEList; /* Result set. */ int i; /* For-loop variable used in multiple places */ NameContext sNC; /* Local name-context */ /* If this routine has run before, return immediately. */ if( p->isResolved ){ assert( !pOuterNC ); return SQLITE_OK; } p->isResolved = 1; | > | 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 | Parse *pParse, /* The parser context */ Select *p, /* The SELECT statement being coded. */ NameContext *pOuterNC /* The outer name context. May be NULL. */ ){ ExprList *pEList; /* Result set. */ int i; /* For-loop variable used in multiple places */ NameContext sNC; /* Local name-context */ ExprList *pGroupBy; /* The group by clause */ /* If this routine has run before, return immediately. */ if( p->isResolved ){ assert( !pOuterNC ); return SQLITE_OK; } p->isResolved = 1; |
︙ | ︙ | |||
2325 2326 2327 2328 2329 2330 2331 | /* Set up the local name-context to pass to ExprResolveNames() to ** resolve the expression-list. */ sNC.allowAgg = 1; sNC.pSrcList = p->pSrc; sNC.pNext = pOuterNC; | < < < < < < < < < < < < > | | | > > > > > > > > > > > > > > < | < > | > > | | > | > > > > > > > > > > | > > > > | | > > | > > > > | | | < | | > | < < > > > > | > > > | < < < | | | > > > | > > > > > > > > > > > > > > > > > > > > > > > > | | > | > > > > > > > > > > > > > | 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 | /* Set up the local name-context to pass to ExprResolveNames() to ** resolve the expression-list. */ sNC.allowAgg = 1; sNC.pSrcList = p->pSrc; sNC.pNext = pOuterNC; /* Resolve names in the result set. */ pEList = p->pEList; if( !pEList ) return SQLITE_ERROR; for(i=0; i<pEList->nExpr; i++){ Expr *pX = pEList->a[i].pExpr; if( sqlite3ExprResolveNames(&sNC, pX) ){ return SQLITE_ERROR; } } /* If there are no aggregate functions in the result-set, and no GROUP BY ** expression, do not allow aggregates in any of the other expressions. */ assert( !p->isAgg ); pGroupBy = p->pGroupBy; if( pGroupBy || sNC.hasAgg ){ p->isAgg = 1; }else{ sNC.allowAgg = 0; } /* If a HAVING clause is present, then there must be a GROUP BY clause. */ if( p->pHaving && !pGroupBy ){ sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); return SQLITE_ERROR; } /* Add the expression list to the name-context before parsing the ** other expressions in the SELECT statement. This is so that ** expressions in the WHERE clause (etc.) can refer to expressions by ** aliases in the result set. ** ** Minor point: If this is the case, then the expression will be ** re-evaluated for each reference to it. */ sNC.pEList = p->pEList; if( sqlite3ExprResolveNames(&sNC, p->pWhere) || sqlite3ExprResolveNames(&sNC, p->pHaving) || processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") || processOrderGroupBy(&sNC, pGroupBy, "GROUP") ){ return SQLITE_ERROR; } /* Make sure the GROUP BY clause does not contain aggregate functions. */ if( pGroupBy ){ struct ExprList_item *pItem; for(i=0, pItem=pGroupBy->a; i<pGroupBy->nExpr; i++, pItem++){ if( ExprHasProperty(pItem->pExpr, EP_Agg) ){ sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in " "the GROUP BY clause"); return SQLITE_ERROR; } } } return SQLITE_OK; } /* ** Reset the aggregate accumulator. ** ** The aggregate accumulator is a set of memory cells that hold ** intermediate results while calculating an aggregate. This ** routine simply stores NULLs in all of those memory cells. */ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ Vdbe *v = pParse->pVdbe; int i; struct AggInfo_func *pFunc; if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){ return; } for(i=0; i<pAggInfo->nColumn; i++){ sqlite3VdbeAddOp(v, OP_MemNull, pAggInfo->aCol[i].iMem, 0); } for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ sqlite3VdbeAddOp(v, OP_MemNull, pFunc->iMem, 0); if( pFunc->iDistinct>=0 ){ Expr *pE = pFunc->pExpr; if( pE->pList==0 || pE->pList->nExpr!=1 ){ sqlite3ErrorMsg(pParse, "DISTINCT in aggregate must be followed " "by an expression"); pFunc->iDistinct = -1; }else{ KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->pList); sqlite3VdbeOp3(v, OP_OpenVirtual, pFunc->iDistinct, 0, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); } } } } /* ** Invoke the OP_AggFinalize opcode for every aggregate function ** in the AggInfo structure. */ static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){ Vdbe *v = pParse->pVdbe; int i; struct AggInfo_func *pF; for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ ExprList *pList = pF->pExpr->pList; sqlite3VdbeOp3(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0, (void*)pF->pFunc, P3_FUNCDEF); } } /* ** Update the accumulator memory cells for an aggregate based on ** the current cursor position. */ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){ Vdbe *v = pParse->pVdbe; int i; struct AggInfo_func *pF; struct AggInfo_col *pC; pAggInfo->directMode = 1; for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ int nArg; int addrNext = 0; ExprList *pList = pF->pExpr->pList; if( pList ){ nArg = pList->nExpr; sqlite3ExprCodeExprList(pParse, pList); }else{ nArg = 0; } if( pF->iDistinct>=0 ){ addrNext = sqlite3VdbeMakeLabel(v); assert( nArg==1 ); codeDistinct(v, pF->iDistinct, addrNext, 1, 2); } if( pF->pFunc->needCollSeq ){ CollSeq *pColl = 0; struct ExprList_item *pItem; int j; for(j=0, pItem=pList->a; !pColl && j<pList->nExpr; j++, pItem++){ pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr); } if( !pColl ){ pColl = pParse->db->pDfltColl; } sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ); } sqlite3VdbeOp3(v, OP_AggStep, pF->iMem, nArg, (void*)pF->pFunc, P3_FUNCDEF); if( addrNext ){ sqlite3VdbeResolveLabel(v, addrNext); } } for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){ sqlite3ExprCode(pParse, pC->pExpr); sqlite3VdbeAddOp(v, OP_MemStore, pC->iMem, 1); } pAggInfo->directMode = 0; } /* ** Generate code for the given SELECT statement. ** ** The results are distributed in various ways depending on the ** value of eDest and iParm. ** ** eDest Value Result |
︙ | ︙ | |||
2481 2482 2483 2484 2485 2486 2487 | int eDest, /* How to dispose of the results */ int iParm, /* A parameter used by the eDest disposal method */ Select *pParent, /* Another SELECT for which this is a sub-query */ int parentTab, /* Index in pParent->pSrc of this query */ int *pParentAgg, /* True if pParent uses aggregate functions */ char *aff /* If eDest is SRT_Union, the affinity string */ ){ | | | | > | > > > > > > > < < > | 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 | int eDest, /* How to dispose of the results */ int iParm, /* A parameter used by the eDest disposal method */ Select *pParent, /* Another SELECT for which this is a sub-query */ int parentTab, /* Index in pParent->pSrc of this query */ int *pParentAgg, /* True if pParent uses aggregate functions */ char *aff /* If eDest is SRT_Union, the affinity string */ ){ int i, j; /* Loop counters */ WhereInfo *pWInfo; /* Return from sqlite3WhereBegin() */ Vdbe *v; /* The virtual machine under construction */ int isAgg; /* True for select lists like "count(*)" */ ExprList *pEList; /* List of columns to extract. */ SrcList *pTabList; /* List of tables to select from */ Expr *pWhere; /* The WHERE clause. May be NULL */ ExprList *pOrderBy; /* The ORDER BY clause. May be NULL */ ExprList *pGroupBy; /* The GROUP BY clause. May be NULL */ Expr *pHaving; /* The HAVING clause. May be NULL */ int isDistinct; /* True if the DISTINCT keyword is present */ int distinct; /* Table to use for the distinct set */ int rc = 1; /* Value to return from this function */ int addrSortIndex; /* Address of an OP_OpenVirtual instruction */ AggInfo sAggInfo; /* Information used by aggregate queries */ if( sqlite3_malloc_failed || pParse->nErr || p==0 ) return 1; if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; memset(&sAggInfo, 0, sizeof(sAggInfo)); #ifndef SQLITE_OMIT_COMPOUND_SELECT /* If there is are a sequence of queries, do the earlier ones first. */ if( p->pPrior ){ if( p->pRightmost==0 ){ Select *pLoop; for(pLoop=p; pLoop; pLoop=pLoop->pPrior){ pLoop->pRightmost = p; } } return multiSelect(pParse, p, eDest, iParm, aff); } #endif pOrderBy = p->pOrderBy; if( IgnorableOrderby(eDest) ){ p->pOrderBy = 0; } if( sqlite3SelectResolve(pParse, p, 0) ){ goto select_end; } p->pOrderBy = pOrderBy; |
︙ | ︙ | |||
2548 2549 2550 2551 2552 2553 2554 | "a SELECT that is part of an expression"); goto select_end; } #endif /* ORDER BY is ignored for some destinations. */ | | < < < | < < < > | | | | | | | 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 | "a SELECT that is part of an expression"); goto select_end; } #endif /* ORDER BY is ignored for some destinations. */ if( IgnorableOrderby(eDest) ){ pOrderBy = 0; } /* Begin generating code. */ v = sqlite3GetVdbe(pParse); if( v==0 ) goto select_end; /* 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; } sqlite3Select(pParse, pItem->pSelect, SRT_VirtualTab, pItem->iCursor, p, i, &isAgg, 0); if( needRestoreContext ){ pParse->zAuthContext = zSavedAuthContext; } pTabList = p->pSrc; pWhere = p->pWhere; if( !IgnorableOrderby(eDest) ){ pOrderBy = p->pOrderBy; } pGroupBy = p->pGroupBy; pHaving = p->pHaving; isDistinct = p->isDistinct; } #endif |
︙ | ︙ | |||
2621 2622 2623 2624 2625 2626 2627 | flattenSubquery(pParse, pParent, parentTab, *pParentAgg, isAgg) ){ if( isAgg ) *pParentAgg = 1; goto select_end; } #endif /* If there is an ORDER BY clause, resolve any collation sequences | | > > > > > > > > | | < | > > > > > > > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | > | | > > | > > > > | | | < | > > > > > > > > > | < | < | | < < | > | > | | | > > | < < | | < < | < < < < | > > > > > > | | | < < < | < < < < < > < < < < < < < < < < | < | | < < < | < > > | > > > > > > | > | < < < < | | < < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 | flattenSubquery(pParse, pParent, parentTab, *pParentAgg, isAgg) ){ if( isAgg ) *pParentAgg = 1; goto select_end; } #endif /* If there is an ORDER BY clause, resolve any collation sequences ** names that have been explicitly specified and create a sorting index. ** ** This sorting index might end up being unused if the data can be ** extracted in pre-sorted order. If that is the case, then the ** OP_OpenVirtual instruction will be changed to an OP_Noop once ** we figure out that the sorting index is not needed. The addrSortIndex ** variable is used to facilitate that change. */ if( pOrderBy ){ struct ExprList_item *pTerm; KeyInfo *pKeyInfo; for(i=0, pTerm=pOrderBy->a; i<pOrderBy->nExpr; i++, pTerm++){ if( pTerm->zName ){ pTerm->pExpr->pColl = sqlite3LocateCollSeq(pParse, pTerm->zName, -1); } } if( pParse->nErr ){ goto select_end; } pKeyInfo = keyInfoFromExprList(pParse, pOrderBy); pOrderBy->iECursor = pParse->nTab++; p->addrOpenVirt[2] = addrSortIndex = sqlite3VdbeOp3(v, OP_OpenVirtual, pOrderBy->iECursor, pOrderBy->nExpr+2, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); }else{ addrSortIndex = -1; } /* Set the limiter. */ computeLimitRegisters(pParse, p); /* If the output is destined for a temporary table, open that table. */ if( eDest==SRT_VirtualTab ){ sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, pEList->nExpr); } /* Initialize the memory cell to NULL for SRT_Mem or 0 for SRT_Exists */ if( eDest==SRT_Mem ){ sqlite3VdbeAddOp(v, OP_MemNull, iParm, 0); }else if( eDest==SRT_Exists ){ sqlite3VdbeAddOp(v, OP_MemInt, 0, iParm); } /* Open a virtual index to use for the distinct set. */ if( isDistinct ){ KeyInfo *pKeyInfo; distinct = pParse->nTab++; pKeyInfo = keyInfoFromExprList(pParse, p->pEList); sqlite3VdbeOp3(v, OP_OpenVirtual, distinct, 0, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); }else{ distinct = -1; } /* Aggregate and non-aggregate queries are handled differently */ if( !isAgg && pGroupBy==0 ){ /* This case is for non-aggregate queries ** Begin the database scan */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy); if( pWInfo==0 ) goto select_end; /* If sorting index that was created by a prior OP_OpenVirtual ** instruction ended up not being needed, then change the OP_OpenVirtual ** into an OP_Noop. */ if( addrSortIndex>=0 && pOrderBy==0 ){ uncreateSortingIndex(pParse, addrSortIndex); p->addrOpenVirt[2] = -1; } /* Use the standard inner loop */ if( selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, distinct, eDest, iParm, pWInfo->iContinue, pWInfo->iBreak, aff) ){ goto select_end; } /* End the database scan loop. */ sqlite3WhereEnd(pWInfo); }else{ /* This is the processing for aggregate queries */ NameContext sNC; /* Name context for processing aggregate information */ int iAMem; /* First Mem address for storing current GROUP BY */ int iBMem; /* First Mem address for previous GROUP BY */ int iUseFlag; /* Mem address holding flag indicating that at least ** one row of the input to the aggregator has been ** processed */ int iAbortFlag; /* Mem address which causes query abort if positive */ int groupBySort; /* Rows come from source in GROUP BY order */ /* The following variables hold addresses or labels for parts of the ** virtual machine program we are putting together */ int addrOutputRow; /* Start of subroutine that outputs a result row */ int addrSetAbort; /* Set the abort flag and return */ int addrInitializeLoop; /* Start of code that initializes the input loop */ int addrTopOfLoop; /* Top of the input loop */ int addrGroupByChange; /* Code that runs when any GROUP BY term changes */ int addrProcessRow; /* Code to process a single input row */ int addrEnd; /* End of all processing */ int addrSortingIdx; /* The OP_OpenVirtual for the sorting index */ int addrReset; /* Subroutine for resetting the accumulator */ addrEnd = sqlite3VdbeMakeLabel(v); /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the ** SELECT statement. */ memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pParse; sNC.pSrcList = pTabList; sNC.pAggInfo = &sAggInfo; sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0; sAggInfo.pGroupBy = pGroupBy; if( sqlite3ExprAnalyzeAggList(&sNC, pEList) ){ goto select_end; } if( sqlite3ExprAnalyzeAggList(&sNC, pOrderBy) ){ goto select_end; } if( pHaving && sqlite3ExprAnalyzeAggregates(&sNC, pHaving) ){ goto select_end; } sAggInfo.nAccumulator = sAggInfo.nColumn; for(i=0; i<sAggInfo.nFunc; i++){ if( sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->pList) ){ goto select_end; } } if( sqlite3_malloc_failed ) goto select_end; /* Processing for aggregates with GROUP BY is very different and ** much more complex tha aggregates without a GROUP BY. */ if( pGroupBy ){ KeyInfo *pKeyInfo; /* Keying information for the group by clause */ /* Create labels that we will be needing */ addrInitializeLoop = sqlite3VdbeMakeLabel(v); addrGroupByChange = sqlite3VdbeMakeLabel(v); addrProcessRow = sqlite3VdbeMakeLabel(v); /* If there is a GROUP BY clause we might need a sorting index to ** implement it. Allocate that sorting index now. If it turns out ** that we do not need it after all, the OpenVirtual instruction ** will be converted into a Noop. */ sAggInfo.sortingIdx = pParse->nTab++; pKeyInfo = keyInfoFromExprList(pParse, pGroupBy); addrSortingIdx = sqlite3VdbeOp3(v, OP_OpenVirtual, sAggInfo.sortingIdx, sAggInfo.nSortingColumn, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); /* Initialize memory locations used by GROUP BY aggregate processing */ iUseFlag = pParse->nMem++; iAbortFlag = pParse->nMem++; iAMem = pParse->nMem; pParse->nMem += pGroupBy->nExpr; iBMem = pParse->nMem; pParse->nMem += pGroupBy->nExpr; sqlite3VdbeAddOp(v, OP_MemInt, 0, iAbortFlag); VdbeComment((v, "# clear abort flag")); sqlite3VdbeAddOp(v, OP_MemInt, 0, iUseFlag); VdbeComment((v, "# indicate accumulator empty")); sqlite3VdbeAddOp(v, OP_Goto, 0, addrInitializeLoop); /* Generate a subroutine that outputs a single row of the result ** set. This subroutine first looks at the iUseFlag. If iUseFlag ** is less than or equal to zero, the subroutine is a no-op. If ** the processing calls for the query to abort, this subroutine ** increments the iAbortFlag memory location before returning in ** order to signal the caller to abort. */ addrSetAbort = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp(v, OP_MemInt, 1, iAbortFlag); VdbeComment((v, "# set abort flag")); sqlite3VdbeAddOp(v, OP_Return, 0, 0); addrOutputRow = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp(v, OP_IfMemPos, iUseFlag, addrOutputRow+2); VdbeComment((v, "# Groupby result generator entry point")); sqlite3VdbeAddOp(v, OP_Return, 0, 0); finalizeAggFunctions(pParse, &sAggInfo); if( pHaving ){ sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, 1); } rc = selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy, distinct, eDest, iParm, addrOutputRow+1, addrSetAbort, aff); if( rc ){ goto select_end; } sqlite3VdbeAddOp(v, OP_Return, 0, 0); VdbeComment((v, "# end groupby result generator")); /* Generate a subroutine that will reset the group-by accumulator */ addrReset = sqlite3VdbeCurrentAddr(v); resetAccumulator(pParse, &sAggInfo); sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* Begin a loop that will extract all source rows in GROUP BY order. ** This might involve two separate loops with an OP_Sort in between, or ** it might be a single loop that uses an index to extract information ** in the right order to begin with. */ sqlite3VdbeResolveLabel(v, addrInitializeLoop); sqlite3VdbeAddOp(v, OP_Gosub, 0, addrReset); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy); if( pWInfo==0 ) goto select_end; if( pGroupBy==0 ){ /* The optimizer is able to deliver rows in group by order so ** we do not have to sort. The OP_OpenVirtual table will be ** cancelled later because we still need to use the pKeyInfo */ pGroupBy = p->pGroupBy; groupBySort = 0; }else{ /* Rows are coming out in undetermined order. We have to push ** each row into a sorting index, terminate the first loop, ** then loop over the sorting index in order to get the output ** in sorted order */ groupBySort = 1; sqlite3ExprCodeExprList(pParse, pGroupBy); sqlite3VdbeAddOp(v, OP_Sequence, sAggInfo.sortingIdx, 0); j = pGroupBy->nExpr+1; for(i=0; i<sAggInfo.nColumn; i++){ struct AggInfo_col *pCol = &sAggInfo.aCol[i]; if( pCol->iSorterColumn<j ) continue; if( pCol->iColumn<0 ){ sqlite3VdbeAddOp(v, OP_Rowid, pCol->iTable, 0); }else{ sqlite3VdbeAddOp(v, OP_Column, pCol->iTable, pCol->iColumn); } j++; } sqlite3VdbeAddOp(v, OP_MakeRecord, j, 0); sqlite3VdbeAddOp(v, OP_IdxInsert, sAggInfo.sortingIdx, 0); sqlite3WhereEnd(pWInfo); sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, addrEnd); VdbeComment((v, "# GROUP BY sort")); sAggInfo.useSortingIdx = 1; } /* Evaluate the current GROUP BY terms and store in b0, b1, b2... ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth) ** Then compare the current GROUP BY terms against the GROUP BY terms ** from the previous row currently stored in a0, a1, a2... */ addrTopOfLoop = sqlite3VdbeCurrentAddr(v); for(j=0; j<pGroupBy->nExpr; j++){ if( groupBySort ){ sqlite3VdbeAddOp(v, OP_Column, sAggInfo.sortingIdx, j); }else{ sAggInfo.directMode = 1; sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr); } sqlite3VdbeAddOp(v, OP_MemStore, iBMem+j, j<pGroupBy->nExpr-1); } for(j=pGroupBy->nExpr-1; j>=0; j--){ if( j<pGroupBy->nExpr-1 ){ sqlite3VdbeAddOp(v, OP_MemLoad, iBMem+j, 0); } sqlite3VdbeAddOp(v, OP_MemLoad, iAMem+j, 0); if( j==0 ){ sqlite3VdbeAddOp(v, OP_Eq, 0x200, addrProcessRow); }else{ sqlite3VdbeAddOp(v, OP_Ne, 0x200, addrGroupByChange); } sqlite3VdbeChangeP3(v, -1, (void*)pKeyInfo->aColl[j], P3_COLLSEQ); } /* Generate code that runs whenever the GROUP BY changes. ** Change in the GROUP BY are detected by the previous code ** block. If there were no changes, this block is skipped. ** ** This code copies current group by terms in b0,b1,b2,... ** over to a0,a1,a2. It then calls the output subroutine ** and resets the aggregate accumulator registers in preparation ** for the next GROUP BY batch. */ sqlite3VdbeResolveLabel(v, addrGroupByChange); for(j=0; j<pGroupBy->nExpr; j++){ sqlite3VdbeAddOp(v, OP_MemMove, iAMem+j, iBMem+j); } sqlite3VdbeAddOp(v, OP_Gosub, 0, addrOutputRow); VdbeComment((v, "# output one row")); sqlite3VdbeAddOp(v, OP_IfMemPos, iAbortFlag, addrEnd); VdbeComment((v, "# check abort flag")); sqlite3VdbeAddOp(v, OP_Gosub, 0, addrReset); VdbeComment((v, "# reset accumulator")); /* Update the aggregate accumulators based on the content of ** the current row */ sqlite3VdbeResolveLabel(v, addrProcessRow); updateAccumulator(pParse, &sAggInfo); sqlite3VdbeAddOp(v, OP_MemInt, 1, iUseFlag); VdbeComment((v, "# indicate data in accumulator")); /* End of the loop */ if( groupBySort ){ sqlite3VdbeAddOp(v, OP_Next, sAggInfo.sortingIdx, addrTopOfLoop); }else{ sqlite3WhereEnd(pWInfo); uncreateSortingIndex(pParse, addrSortingIdx); } /* Output the final row of result */ sqlite3VdbeAddOp(v, OP_Gosub, 0, addrOutputRow); VdbeComment((v, "# output final row")); } /* endif pGroupBy */ else { /* This case runs if the aggregate has no GROUP BY clause. The ** processing is much simpler since there is only a single row ** of output. */ resetAccumulator(pParse, &sAggInfo); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); if( pWInfo==0 ) goto select_end; updateAccumulator(pParse, &sAggInfo); sqlite3WhereEnd(pWInfo); finalizeAggFunctions(pParse, &sAggInfo); pOrderBy = 0; if( pHaving ){ sqlite3ExprIfFalse(pParse, pHaving, addrEnd, 1); } selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, -1, eDest, iParm, addrEnd, addrEnd, aff); } sqlite3VdbeResolveLabel(v, addrEnd); } /* endif aggregate query */ /* If there is an ORDER BY clause, then we need to sort the results ** and send them to the callback one by one. */ if( pOrderBy ){ generateSortTail(pParse, p, v, pEList->nExpr, eDest, iParm); } |
︙ | ︙ | |||
2850 2851 2852 2853 2854 2855 2856 | */ rc = 0; /* Control jumps to here if an error is encountered above, or upon ** successful coding of the SELECT. */ select_end: | | > | 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 | */ rc = 0; /* Control jumps to here if an error is encountered above, or upon ** successful coding of the SELECT. */ select_end: sqliteFree(sAggInfo.aCol); sqliteFree(sAggInfo.aFunc); return rc; } |
Changes to SQLite.Interop/src/shell.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** | | | 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 code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** ** $Id: shell.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <assert.h> #include "sqlite3.h" #include <ctype.h> |
︙ | ︙ | |||
309 310 311 312 313 314 315 | }else if( c=='\n' ){ fputc('\\', out); fputc('n', out); }else if( c=='\r' ){ fputc('\\', out); fputc('r', out); }else if( !isprint(c) ){ | | | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | }else if( c=='\n' ){ fputc('\\', out); fputc('n', out); }else if( c=='\r' ){ fputc('\\', out); fputc('r', out); }else if( !isprint(c) ){ fprintf(out, "\\%03o", c&0xff); }else{ fputc(c, out); } } fputc('"', out); } |
︙ | ︙ | |||
652 653 654 655 656 657 658 | struct callback_data *p = (struct callback_data *)pArg; if( nArg!=3 ) return 1; zTable = azArg[0]; zType = azArg[1]; zSql = azArg[2]; | | > > | > > | | 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | struct callback_data *p = (struct callback_data *)pArg; if( nArg!=3 ) return 1; zTable = azArg[0]; zType = azArg[1]; zSql = azArg[2]; if( strcmp(zTable, "sqlite_sequence")==0 ){ fprintf(p->out, "DELETE FROM sqlite_sequence;\n"); }else if( strcmp(zTable, "sqlite_stat1")==0 ){ fprintf(p->out, "ANALYZE sqlite_master;\n"); }else if( strncmp(zTable, "sqlite_", 7)==0 ){ return 0; }else{ fprintf(p->out, "%s;\n", zSql); } if( strcmp(zType, "table")==0 ){ sqlite3_stmt *pTableInfo = 0; char *zSelect = 0; char *zTableInfo = 0; char *zTmp = 0; |
︙ | ︙ | |||
1286 1287 1288 1289 1290 1291 1292 | zShellStatic = 0; } }else{ sqlite3_exec(p->db, "SELECT sql FROM " " (SELECT * FROM sqlite_master UNION ALL" " SELECT * FROM sqlite_temp_master) " | | | 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | zShellStatic = 0; } }else{ sqlite3_exec(p->db, "SELECT sql FROM " " (SELECT * FROM sqlite_master UNION ALL" " SELECT * FROM sqlite_temp_master) " "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'" "ORDER BY substr(type,2,1), name", callback, &data, &zErrMsg ); } if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); sqlite3_free(zErrMsg); |
︙ | ︙ | |||
1330 1331 1332 1333 1334 1335 1336 | char **azResult; int nRow, rc; char *zErrMsg; open_db(p); if( nArg==1 ){ rc = sqlite3_get_table(p->db, "SELECT name FROM sqlite_master " | | | 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 | char **azResult; int nRow, rc; char *zErrMsg; open_db(p); if( nArg==1 ){ rc = sqlite3_get_table(p->db, "SELECT name FROM sqlite_master " "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'" "UNION ALL " "SELECT name FROM sqlite_temp_master " "WHERE type IN ('table','view') " "ORDER BY 1", &azResult, &nRow, 0, &zErrMsg ); }else{ |
︙ | ︙ | |||
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 | data.zDbFilename = 0; #endif } if( i<argc ){ zFirstCmd = argv[i++]; } data.out = stdout; /* Go ahead and open the database file if it already exists. If the ** file does not exist, delay opening it. This prevents empty database ** files from being created if a user mistypes the database name argument ** to the sqlite command-line tool. */ if( access(data.zDbFilename, 0)==0 ){ | > > > > > > > | 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 | data.zDbFilename = 0; #endif } if( i<argc ){ zFirstCmd = argv[i++]; } data.out = stdout; #ifdef SQLITE_OMIT_MEMORYDB if( data.zDbFilename==0 ){ fprintf(stderr,"%s: no database filename specified\n", argv[0]); exit(1); } #endif /* Go ahead and open the database file if it already exists. If the ** file does not exist, delay opening it. This prevents empty database ** files from being created if a user mistypes the database name argument ** to the sqlite command-line tool. */ if( access(data.zDbFilename, 0)==0 ){ |
︙ | ︙ |
Changes to SQLite.Interop/src/sqlite3.h.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | | | 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 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the SQLite library ** presents to client programs. ** ** @(#) $Id: sqlite3.h,v 1.10 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ #include <stdarg.h> /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. */ #ifdef __cplusplus extern "C" { #endif /* ** The version of the SQLite library. */ #ifdef SQLITE_VERSION # undef SQLITE_VERSION #endif #define SQLITE_VERSION "3.2.7" /* ** The format of the version string is "X.Y.Z<trailing string>", where ** X is the major version number, Y is the minor version number and Z ** is the release number. The trailing string is often "alpha" or "beta". ** For example "3.1.1beta". ** ** The SQLITE_VERSION_NUMBER is an integer with the value ** (X*100000 + Y*1000 + Z). For example, for version "3.1.1beta", ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using ** version 3.1.1 or greater at compile time, programs may use the test ** (SQLITE_VERSION_NUMBER>=3001001). */ #ifdef SQLITE_VERSION_NUMBER # undef SQLITE_VERSION_NUMBER #endif #define SQLITE_VERSION_NUMBER 3002007 /* ** The version string is also compiled into the library so that a program ** can check to make sure that the lib*.a file and the *.h file are from ** the same version. The sqlite3_libversion() function returns a pointer ** to the sqlite3_version variable - useful in DLLs which cannot access ** global variables. |
︙ | ︙ | |||
369 370 371 372 373 374 375 | ** ** For example, so some string variable contains text as follows: ** ** char *zText = "It's a happy day!"; ** ** We can use this text in an SQL statement as follows: ** | > | | | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | ** ** For example, so some string variable contains text as follows: ** ** char *zText = "It's a happy day!"; ** ** We can use this text in an SQL statement as follows: ** ** char *z = sqlite3_mprintf("INSERT INTO TABLES('%q')", zText); ** sqlite3_exec(db, z, callback1, 0, 0); ** sqlite3_free(z); ** ** Because the %q format string is used, the '\'' character in zText ** is escaped and the SQL generated is as follows: ** ** INSERT INTO table1 VALUES('It''s a happy day!') ** ** This is correct. Had we used %s instead of %q, the generated SQL |
︙ | ︙ | |||
460 461 462 463 464 465 466 | ** following constants: */ /* #define SQLITE_OK 0 // Allow access (This is actually defined above) */ #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ /* | | | | > > > > > > > | 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 | ** following constants: */ /* #define SQLITE_OK 0 // Allow access (This is actually defined above) */ #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ /* ** Register a function for tracing SQL command evaluation. The function ** registered by sqlite3_trace() is invoked at the first sqlite3_step() ** for the evaluation of an SQL statement. The function registered by ** sqlite3_profile() runs at the end of each SQL statement and includes ** information on how long that statement ran. ** ** The sqlite3_profile() API is currently considered experimental and ** is subject to change. */ void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); void *sqlite3_profile(sqlite3*, void(*xProfile)(void*,const char*,sqlite_uint64), void*); /* ** This routine configures a callback function - the progress callback - that ** is invoked periodically during long running calls to sqlite3_exec(), ** sqlite3_step() and sqlite3_get_table(). An example use for this API is to ** keep a GUI updated during a large query. ** |
︙ | ︙ |
Changes to SQLite.Interop/src/sqliteInt.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 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. ** | | > > > > > > > > > > > | 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 | /* ** 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. ** Setting NDEBUG makes the code smaller and run faster. So the following ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out ** feature. */ #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) # define NDEBUG 1 #endif /* ** These #defines should enable >2GB file support on Posix if the ** underlying operating system supports it. If the OS lacks ** large file support, or if the OS is windows, these should be no-ops. ** ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch ** on the compiler command line. This is necessary if you are compiling |
︙ | ︙ | |||
294 295 296 297 298 299 300 | ** an array. */ #define ArraySize(X) (sizeof(X)/sizeof(X[0])) /* ** Forward references to structures */ | | | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | ** an array. */ #define ArraySize(X) (sizeof(X)/sizeof(X[0])) /* ** Forward references to structures */ typedef struct AggInfo AggInfo; typedef struct AuthContext AuthContext; typedef struct CollSeq CollSeq; typedef struct Column Column; typedef struct Db Db; typedef struct Expr Expr; typedef struct ExprList ExprList; typedef struct FKey FKey; |
︙ | ︙ | |||
416 417 418 419 420 421 422 | struct sqlite3InitInfo { /* Information used during initialization */ int iDb; /* When back is being initialized */ int newTnum; /* Rootpage of table being initialized */ u8 busy; /* TRUE if currently initializing */ } init; struct Vdbe *pVdbe; /* List of active virtual machines */ int activeVdbeCnt; /* Number of vdbes currently executing */ | | | > > | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | struct sqlite3InitInfo { /* Information used during initialization */ int iDb; /* When back is being initialized */ int newTnum; /* Rootpage of table being initialized */ u8 busy; /* TRUE if currently initializing */ } init; struct Vdbe *pVdbe; /* List of active virtual machines */ int activeVdbeCnt; /* Number of vdbes currently executing */ void (*xTrace)(void*,const char*); /* Trace function */ void *pTraceArg; /* Argument to the trace function */ void (*xProfile)(void*,const char*,u64); /* Profiling function */ void *pProfileArg; /* Argument to profile function */ void *pCommitArg; /* Argument to xCommitCallback() */ int (*xCommitCallback)(void*);/* Invoked at every commit. */ void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); void *pCollNeededArg; sqlite3_value *pValue; /* Value used for transient conversions */ sqlite3_value *pErr; /* Most recent error message */ |
︙ | ︙ | |||
507 508 509 510 511 512 513 | void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ char zName[1]; /* SQL name of the function. MUST BE LAST */ }; /* ** Possible values for FuncDef.flags */ | | > | 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ char zName[1]; /* SQL name of the function. MUST BE LAST */ }; /* ** Possible values for FuncDef.flags */ #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */ #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ /* ** information about each column of an SQL table is held in an instance ** of this structure. */ struct Column { char *zName; /* Name of this column */ |
︙ | ︙ | |||
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the ** collating sequence is undefined. Indices built on an undefined ** collating sequence may not be read or written. */ struct CollSeq { char *zName; /* Name of the collating sequence, UTF-8 encoded */ u8 enc; /* Text encoding handled by xCmp() */ void *pUser; /* First argument to xCmp() */ int (*xCmp)(void*,int, const void*, int, const void*); }; /* ** A sort order can be either ASC or DESC. */ #define SQLITE_SO_ASC 0 /* Sort in ascending order */ #define SQLITE_SO_DESC 1 /* Sort in ascending order */ /* | > > > > > > > > > | 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 | ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the ** collating sequence is undefined. Indices built on an undefined ** collating sequence may not be read or written. */ struct CollSeq { char *zName; /* Name of the collating sequence, UTF-8 encoded */ u8 enc; /* Text encoding handled by xCmp() */ u8 type; /* One of the SQLITE_COLL_... values below */ void *pUser; /* First argument to xCmp() */ int (*xCmp)(void*,int, const void*, int, const void*); }; /* ** Allowed values of CollSeq flags: */ #define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ #define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ #define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ #define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ /* ** A sort order can be either ASC or DESC. */ #define SQLITE_SO_ASC 0 /* Sort in ascending order */ #define SQLITE_SO_DESC 1 /* Sort in ascending order */ /* |
︙ | ︙ | |||
772 773 774 775 776 777 778 779 780 781 782 783 784 785 | */ struct Token { const unsigned char *z; /* Text of the token. Not NULL-terminated! */ unsigned dyn : 1; /* True for malloced memory, false for static */ unsigned n : 31; /* Number of characters in this token */ }; /* ** Each node of an expression in the parse tree is an instance ** of this structure. ** ** Expr.op is the opcode. The integer parser token codes are reused ** as opcodes here. For example, the parser defines TK_GE to be an integer ** code representing the ">=" operator. This same integer code is reused | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | */ struct Token { const unsigned char *z; /* Text of the token. Not NULL-terminated! */ unsigned dyn : 1; /* True for malloced memory, false for static */ unsigned n : 31; /* Number of characters in this token */ }; /* ** An instance of this structure contains information needed to generate ** code for a SELECT that contains aggregate functions. ** ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a ** pointer to this structure. The Expr.iColumn field is the index in ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate ** code for that node. ** ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the ** original Select structure that describes the SELECT statement. These ** fields do not need to be freed when deallocating the AggInfo structure. */ struct AggInfo { u8 directMode; /* Direct rendering mode means take data directly ** from source tables rather than from accumulators */ u8 useSortingIdx; /* In direct mode, reference the sorting index rather ** than the source table */ int sortingIdx; /* Cursor number of the sorting index */ ExprList *pGroupBy; /* The group by clause */ int nSortingColumn; /* Number of columns in the sorting index */ struct AggInfo_col { /* For each column used in source tables */ int iTable; /* Cursor number of the source table */ int iColumn; /* Column number within the source table */ int iSorterColumn; /* Column number in the sorting index */ int iMem; /* Memory location that acts as accumulator */ Expr *pExpr; /* The original expression */ } *aCol; int nColumn; /* Number of used entries in aCol[] */ int nColumnAlloc; /* Number of slots allocated for aCol[] */ int nAccumulator; /* Number of columns that show through to the output. ** Additional columns are used only as parameters to ** aggregate functions */ struct AggInfo_func { /* For each aggregate function */ Expr *pExpr; /* Expression encoding the function */ FuncDef *pFunc; /* The aggregate function implementation */ int iMem; /* Memory location that acts as accumulator */ int iDistinct; /* Virtual table used to enforce DISTINCT */ } *aFunc; int nFunc; /* Number of entries in aFunc[] */ int nFuncAlloc; /* Number of slots allocated for aFunc[] */ }; /* ** Each node of an expression in the parse tree is an instance ** of this structure. ** ** Expr.op is the opcode. The integer parser token codes are reused ** as opcodes here. For example, the parser defines TK_GE to be an integer ** code representing the ">=" operator. This same integer code is reused |
︙ | ︙ | |||
831 832 833 834 835 836 837 | Expr *pLeft, *pRight; /* Left and right subnodes */ ExprList *pList; /* A list of expressions used as function arguments ** or in "<expr> IN (<expr-list)" */ Token token; /* An operand token */ Token span; /* Complete text of the expression */ int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the ** iColumn-th field of the iTable-th table. */ | > | < | | | 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 | Expr *pLeft, *pRight; /* Left and right subnodes */ ExprList *pList; /* A list of expressions used as function arguments ** or in "<expr> IN (<expr-list)" */ Token token; /* An operand token */ Token span; /* Complete text of the expression */ int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the ** iColumn-th field of the iTable-th table. */ AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ Select *pSelect; /* When the expression is a sub-select. Also the ** right side of "<expr> IN (<select>)" */ Table *pTab; /* Table for OP_Column expressions. */ }; /* ** The following are the meanings of bits in the Expr.flags field. */ #define EP_FromJoin 0x01 /* Originated in ON or USING clause of a join */ #define EP_Agg 0x02 /* Contains one or more aggregate functions */ #define EP_Resolved 0x04 /* IDs have been resolved to COLUMNs */ #define EP_Error 0x08 /* Expression contains one or more errors */ #define EP_Distinct 0x10 /* Aggregate function with DISTINCT keyword */ #define EP_VarSelect 0x20 /* pSelect is correlated, not constant */ #define EP_Dequoted 0x40 /* True if the string has been dequoted */ /* ** These macros can be used to test, set, or clear bits in the ** Expr.flags field. */ |
︙ | ︙ | |||
870 871 872 873 874 875 876 877 878 879 880 881 882 883 | ** list of "ID = expr" items in an UPDATE. A list of expressions can ** also be used as the argument to a function, in which case the a.zName ** field is not used. */ struct ExprList { int nExpr; /* Number of expressions on the list */ int nAlloc; /* Number of entries allocated below */ struct ExprList_item { Expr *pExpr; /* The list of expressions */ char *zName; /* Token associated with this expression */ u8 sortOrder; /* 1 for DESC or 0 for ASC */ u8 isAgg; /* True if this is an aggregate like count(*) */ u8 done; /* A flag to indicate when processing is finished */ } *a; /* One entry for each expression */ | > | 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | ** list of "ID = expr" items in an UPDATE. A list of expressions can ** also be used as the argument to a function, in which case the a.zName ** field is not used. */ struct ExprList { int nExpr; /* Number of expressions on the list */ int nAlloc; /* Number of entries allocated below */ int iECursor; /* VDBE Cursor associated with this ExprList */ struct ExprList_item { Expr *pExpr; /* The list of expressions */ char *zName; /* Token associated with this expression */ u8 sortOrder; /* 1 for DESC or 0 for ASC */ u8 isAgg; /* True if this is an aggregate like count(*) */ u8 done; /* A flag to indicate when processing is finished */ } *a; /* One entry for each expression */ |
︙ | ︙ | |||
895 896 897 898 899 900 901 | ** column names after a table name in an INSERT statement. In the statement ** ** INSERT INTO t(a,b,c) ... ** ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. */ struct IdList { | < < > > | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 | ** column names after a table name in an INSERT statement. In the statement ** ** INSERT INTO t(a,b,c) ... ** ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. */ struct IdList { struct IdList_item { char *zName; /* Name of the identifier */ int idx; /* Index in some Table.aCol[] of a column named zName */ } *a; int nId; /* Number of identifiers on the list */ int nAlloc; /* Number of entries allocated for a[] below */ }; /* ** The bitmask datatype defined below is used for various optimizations. */ typedef unsigned int Bitmask; |
︙ | ︙ | |||
940 941 942 943 944 945 946 | } a[1]; /* One entry for each identifier on the list */ }; /* ** Permitted values of the SrcList.a.jointype field */ #define JT_INNER 0x0001 /* Any kind of inner or cross join */ | > | | | | | | 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | } a[1]; /* One entry for each identifier on the list */ }; /* ** Permitted values of the SrcList.a.jointype field */ #define JT_INNER 0x0001 /* Any kind of inner or cross join */ #define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */ #define JT_NATURAL 0x0004 /* True for a "natural" join */ #define JT_LEFT 0x0008 /* Left outer join */ #define JT_RIGHT 0x0010 /* Right outer join */ #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */ #define JT_ERROR 0x0040 /* unknown or unsupported join type */ /* ** For each nested loop in a WHERE clause implementation, the WhereInfo ** structure contains a single instance of this structure. This structure ** is intended to be private the the where.c module and should not be ** access or modified by other modules. */ |
︙ | ︙ | |||
1014 1015 1016 1017 1018 1019 1020 | struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ ExprList *pEList; /* Optional list of named expressions */ int nRef; /* Number of names resolved by this context */ int nErr; /* Number of errors encountered while resolving names */ u8 allowAgg; /* Aggregate functions allowed here */ | | > > > > > > > > > > > > > > > > | < < > > > > > > > | | | < < | < < | | | < < < < < < < < < < < < < < < < < < < < < < < < < < | 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 | struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ ExprList *pEList; /* Optional list of named expressions */ int nRef; /* Number of names resolved by this context */ int nErr; /* Number of errors encountered while resolving names */ u8 allowAgg; /* Aggregate functions allowed here */ u8 hasAgg; /* True if aggregates are seen */ int nDepth; /* Depth of subquery recursion. 1 for no recursion */ AggInfo *pAggInfo; /* Information about aggregates at this level */ NameContext *pNext; /* Next outer name context. NULL for outermost */ }; /* ** An instance of the following structure contains all information ** needed to generate code for a single SELECT statement. ** ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. ** If there is a LIMIT clause, the parser sets nLimit to the value of the ** limit and nOffset to the value of the offset (or 0 if there is not ** offset). But later on, nLimit and nOffset become the memory locations ** in the VDBE that record the limit and offset counters. ** ** addrOpenVirt[] entries contain the address of OP_OpenVirtual opcodes. ** These addresses must be stored so that we can go back and fill in ** the P3_KEYINFO and P2 parameters later. Neither the KeyInfo nor ** the number of columns in P2 can be computed at the same time ** as the OP_OpenVirtual instruction is coded because not ** enough information about the compound query is known at that point. ** The KeyInfo for addrOpenVirt[0] and [1] contains collating sequences ** for the result set. The KeyInfo for addrOpenVirt[2] contains collating ** sequences for the ORDER BY clause. */ struct Select { ExprList *pEList; /* The fields of the result */ u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ u8 isDistinct; /* True if the DISTINCT keyword is present */ u8 isResolved; /* True once sqlite3SelectResolve() has run. */ u8 isAgg; /* True if this is an aggregate query */ u8 usesVirt; /* True if uses an OpenVirtual opcode */ u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */ SrcList *pSrc; /* The FROM clause */ Expr *pWhere; /* The WHERE clause */ ExprList *pGroupBy; /* The GROUP BY clause */ Expr *pHaving; /* The HAVING clause */ ExprList *pOrderBy; /* The ORDER BY clause */ Select *pPrior; /* Prior select in a compound select statement */ Select *pRightmost; /* Right-most select in a compound select statement */ Expr *pLimit; /* LIMIT expression. NULL means not used. */ Expr *pOffset; /* OFFSET expression. NULL means not used. */ int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ int addrOpenVirt[3]; /* OP_OpenVirtual opcodes related to this select */ }; /* ** The results of a select can be distributed in several ways. */ #define SRT_Union 1 /* Store result as keys in an index */ #define SRT_Except 2 /* Remove result from a UNION index */ #define SRT_Discard 3 /* Do not save the results anywhere */ /* The ORDER BY clause is ignored for all of the above */ #define IgnorableOrderby(X) (X<=SRT_Discard) #define SRT_Callback 4 /* Invoke a callback with each row of result */ #define SRT_Mem 5 /* Store result in a memory cell */ #define SRT_Set 6 /* Store non-null results as keys in an index */ #define SRT_Table 7 /* Store result as data with an automatic rowid */ #define SRT_VirtualTab 8 /* Create virtual table and store like SRT_Table */ #define SRT_Subroutine 9 /* Call a subroutine to handle results */ #define SRT_Exists 10 /* Put 0 or 1 in a memory cell */ /* ** An SQL parser context. A copy of this structure is passed through ** the parser and down into all the parser action routine in order to ** carry around information that is global to the entire parse. ** ** The structure is divided into two parts. When the parser and code ** generate call themselves recursively, the first part of the structure ** is constant but the second part is reset at the beginning and end of ** each recursion. */ struct Parse { sqlite3 *db; /* The main database structure */ int rc; /* Return code from execution */ char *zErrMsg; /* An error message */ Vdbe *pVdbe; /* An engine for executing database bytecode */ u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ u8 nameClash; /* A permanent table name clashes with temp table name */ u8 checkSchema; /* Causes schema cookie check after an error */ u8 nested; /* Number of nested calls to the parser/code generator */ int nErr; /* Number of errors seen */ int nTab; /* Number of previously allocated VDBE cursors */ int nMem; /* Number of memory cells used so far */ int nSet; /* Number of sets used so far */ u32 writeMask; /* Start a write transaction on these databases */ u32 cookieMask; /* Bitmask of schema verified databases */ int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
︙ | ︙ | |||
1133 1134 1135 1136 1137 1138 1139 | Token sLastToken; /* The last token parsed */ const char *zSql; /* All SQL text */ const char *zTail; /* All SQL text past the last semicolon parsed */ Table *pNewTable; /* A table being constructed by CREATE TABLE */ Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ TriggerStack *trigStack; /* Trigger actions being coded */ const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ | < < < | 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 | Token sLastToken; /* The last token parsed */ const char *zSql; /* All SQL text */ const char *zTail; /* All SQL text past the last semicolon parsed */ Table *pNewTable; /* A table being constructed by CREATE TABLE */ Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ TriggerStack *trigStack; /* Trigger actions being coded */ const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ }; /* ** An instance of the following structure can be declared on a stack and used ** to save the Parse.zAuthContext value so that it can be restored later. */ struct AuthContext { |
︙ | ︙ | |||
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 | /* * This global flag is set for performance testing of triggers. When it is set * SQLite will perform the overhead of building new and old trigger references * even when no triggers exist */ extern int sqlite3_always_code_trigger_setup; /* ** Internal function prototypes */ int sqlite3StrICmp(const char *, const char *); int sqlite3StrNICmp(const char *, const char *, int); int sqlite3HashNoCase(const char *, int); int sqlite3IsNumber(const char*, int*, u8); | > > > > > > > > > > > > > | 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 | /* * This global flag is set for performance testing of triggers. When it is set * SQLite will perform the overhead of building new and old trigger references * even when no triggers exist */ extern int sqlite3_always_code_trigger_setup; /* ** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production ** builds) or a function call (for debugging). If it is a function call, ** it allows the operator to set a breakpoint at the spot where database ** corruption is first detected. */ #ifdef SQLITE_DEBUG extern int sqlite3Corrupt(void); # define SQLITE_CORRUPT_BKPT sqlite3Corrupt() #else # define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT #endif /* ** Internal function prototypes */ int sqlite3StrICmp(const char *, const char *); int sqlite3StrNICmp(const char *, const char *, int); int sqlite3HashNoCase(const char *, int); int sqlite3IsNumber(const char*, int*, u8); |
︙ | ︙ | |||
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 | void sqlite3Free(void*); void *sqlite3Realloc(void*,int); char *sqlite3StrDup(const char*); char *sqlite3StrNDup(const char*, int); # define sqlite3CheckMemory(a,b) # define sqlite3MallocX sqlite3Malloc #endif void sqlite3FreeX(void*); void *sqlite3MallocX(int); char *sqlite3MPrintf(const char*, ...); char *sqlite3VMPrintf(const char*, va_list); void sqlite3DebugPrintf(const char*, ...); void *sqlite3TextToPtr(const char*); void sqlite3SetString(char **, ...); | > | 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 | void sqlite3Free(void*); void *sqlite3Realloc(void*,int); char *sqlite3StrDup(const char*); char *sqlite3StrNDup(const char*, int); # define sqlite3CheckMemory(a,b) # define sqlite3MallocX sqlite3Malloc #endif void sqlite3ReallocOrFree(void**,int); void sqlite3FreeX(void*); void *sqlite3MallocX(int); char *sqlite3MPrintf(const char*, ...); char *sqlite3VMPrintf(const char*, va_list); void sqlite3DebugPrintf(const char*, ...); void *sqlite3TextToPtr(const char*); void sqlite3SetString(char **, ...); |
︙ | ︙ | |||
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 | #else # define sqlite3ViewGetColumnNames(A,B) 0 #endif void sqlite3DropTable(Parse*, SrcList*, int); void sqlite3DeleteTable(sqlite3*, Table*); void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); IdList *sqlite3IdListAppend(IdList*, Token*); int sqlite3IdListIndex(IdList*,const char*); SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*); void sqlite3SrcListAddAlias(SrcList*, Token*); void sqlite3SrcListAssignCursors(Parse*, SrcList*); void sqlite3IdListDelete(IdList*); void sqlite3SrcListDelete(SrcList*); | > | 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 | #else # define sqlite3ViewGetColumnNames(A,B) 0 #endif void sqlite3DropTable(Parse*, SrcList*, int); void sqlite3DeleteTable(sqlite3*, Table*); void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); int sqlite3ArrayAllocate(void**,int,int); IdList *sqlite3IdListAppend(IdList*, Token*); int sqlite3IdListIndex(IdList*,const char*); SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*); void sqlite3SrcListAddAlias(SrcList*, Token*); void sqlite3SrcListAssignCursors(Parse*, SrcList*); void sqlite3IdListDelete(IdList*); void sqlite3SrcListDelete(SrcList*); |
︙ | ︙ | |||
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 | int sqlite3RunVacuum(char**, sqlite3*); char *sqlite3NameFromToken(Token*); int sqlite3ExprCheck(Parse*, Expr*, int, int*); int sqlite3ExprCompare(Expr*, Expr*); int sqliteFuncId(Token*); int sqlite3ExprResolveNames(NameContext *, Expr *); int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); Vdbe *sqlite3GetVdbe(Parse*); void sqlite3Randomness(int, void*); void sqlite3RollbackAll(sqlite3*); void sqlite3CodeVerifySchema(Parse*, int); void sqlite3BeginTransaction(Parse*, int); void sqlite3CommitTransaction(Parse*); void sqlite3RollbackTransaction(Parse*); | > | 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 | int sqlite3RunVacuum(char**, sqlite3*); char *sqlite3NameFromToken(Token*); int sqlite3ExprCheck(Parse*, Expr*, int, int*); int sqlite3ExprCompare(Expr*, Expr*); int sqliteFuncId(Token*); int sqlite3ExprResolveNames(NameContext *, Expr *); int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); Vdbe *sqlite3GetVdbe(Parse*); void sqlite3Randomness(int, void*); void sqlite3RollbackAll(sqlite3*); void sqlite3CodeVerifySchema(Parse*, int); void sqlite3BeginTransaction(Parse*, int); void sqlite3CommitTransaction(Parse*); void sqlite3RollbackTransaction(Parse*); |
︙ | ︙ | |||
1553 1554 1555 1556 1557 1558 1559 | void sqlite3VdbeSetChanges(sqlite3 *, int); void sqlite3utf16Substr(sqlite3_context *,int,sqlite3_value **); const void *sqlite3ValueText(sqlite3_value*, u8); int sqlite3ValueBytes(sqlite3_value*, u8); void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*)); void sqlite3ValueFree(sqlite3_value*); | | | 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 | void sqlite3VdbeSetChanges(sqlite3 *, int); void sqlite3utf16Substr(sqlite3_context *,int,sqlite3_value **); const void *sqlite3ValueText(sqlite3_value*, u8); int sqlite3ValueBytes(sqlite3_value*, u8); void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*)); void sqlite3ValueFree(sqlite3_value*); sqlite3_value *sqlite3ValueNew(void); sqlite3_value *sqlite3GetTransientValue(sqlite3*db); int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **); void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); extern const unsigned char sqlite3UpperToLower[]; void sqlite3RootPageMoved(Db*, int, int); void sqlite3Reindex(Parse*, Token*, Token*); void sqlite3AlterFunctions(sqlite3*); |
︙ | ︙ | |||
1579 1580 1581 1582 1583 1584 1585 | char sqlite3AffinityType(const Token*); void sqlite3Analyze(Parse*, Token*, Token*); int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); void sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); | | | 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 | char sqlite3AffinityType(const Token*); void sqlite3Analyze(Parse*, Token*, Token*); int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); void sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); #ifdef SQLITE_SSE #include "sseInt.h" #endif #endif |
Changes to SQLite.Interop/src/tclsqlite.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 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 ** | | | 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.9 2005/10/05 19:38:29 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> |
︙ | ︙ | |||
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | typedef struct SqliteDb SqliteDb; struct SqliteDb { sqlite3 *db; /* The "real" database structure */ Tcl_Interp *interp; /* The interpreter used for this database */ char *zBusy; /* The busy callback routine */ char *zCommit; /* The commit hook callback routine */ char *zTrace; /* The trace callback routine */ char *zProgress; /* The progress callback routine */ char *zAuth; /* The authorization callback routine */ char *zNull; /* Text to substitute for an SQL NULL value */ SqlFunc *pFunc; /* List of SQL functions */ SqlCollate *pCollate; /* List of SQL collation functions */ int rc; /* Return code of most recent sqlite3_exec() */ Tcl_Obj *pCollateNeeded; /* Collation needed script */ | > | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | typedef struct SqliteDb SqliteDb; struct SqliteDb { sqlite3 *db; /* The "real" database structure */ Tcl_Interp *interp; /* The interpreter used for this database */ char *zBusy; /* The busy callback routine */ char *zCommit; /* The commit hook callback routine */ char *zTrace; /* The trace callback routine */ char *zProfile; /* The profile callback routine */ char *zProgress; /* The progress callback routine */ char *zAuth; /* The authorization callback routine */ char *zNull; /* Text to substitute for an SQL NULL value */ SqlFunc *pFunc; /* List of SQL functions */ SqlCollate *pCollate; /* List of SQL collation functions */ int rc; /* Return code of most recent sqlite3_exec() */ Tcl_Obj *pCollateNeeded; /* Collation needed script */ |
︙ | ︙ | |||
186 187 188 189 190 191 192 193 194 195 196 197 198 199 | } if( pDb->zBusy ){ Tcl_Free(pDb->zBusy); } if( pDb->zTrace ){ Tcl_Free(pDb->zTrace); } if( pDb->zAuth ){ Tcl_Free(pDb->zAuth); } if( pDb->zNull ){ Tcl_Free(pDb->zNull); } Tcl_Free((char*)pDb); | > > > | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | } if( pDb->zBusy ){ Tcl_Free(pDb->zBusy); } if( pDb->zTrace ){ Tcl_Free(pDb->zTrace); } if( pDb->zProfile ){ Tcl_Free(pDb->zProfile); } if( pDb->zAuth ){ Tcl_Free(pDb->zAuth); } if( pDb->zNull ){ Tcl_Free(pDb->zNull); } Tcl_Free((char*)pDb); |
︙ | ︙ | |||
242 243 244 245 246 247 248 249 250 251 252 253 254 255 | Tcl_DStringInit(&str); Tcl_DStringAppend(&str, pDb->zTrace, -1); Tcl_DStringAppendElement(&str, zSql); Tcl_Eval(pDb->interp, Tcl_DStringValue(&str)); Tcl_DStringFree(&str); Tcl_ResetResult(pDb->interp); } /* ** This routine is called when a transaction is committed. The ** TCL script in pDb->zCommit is executed. If it returns non-zero or ** if it throws an exception, the transaction is rolled back instead ** of being committed. */ | > > > > > > > > > > > > > > > > > > > | 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 | Tcl_DStringInit(&str); Tcl_DStringAppend(&str, pDb->zTrace, -1); Tcl_DStringAppendElement(&str, zSql); Tcl_Eval(pDb->interp, Tcl_DStringValue(&str)); Tcl_DStringFree(&str); Tcl_ResetResult(pDb->interp); } /* ** This routine is called by the SQLite profile handler after a statement ** SQL has executed. The TCL script in pDb->zProfile is evaluated. */ static void DbProfileHandler(void *cd, const char *zSql, sqlite_uint64 tm){ SqliteDb *pDb = (SqliteDb*)cd; Tcl_DString str; char zTm[100]; sqlite3_snprintf(sizeof(zTm)-1, zTm, "%lld", tm); Tcl_DStringInit(&str); Tcl_DStringAppend(&str, pDb->zProfile, -1); Tcl_DStringAppendElement(&str, zSql); Tcl_DStringAppendElement(&str, zTm); Tcl_Eval(pDb->interp, Tcl_DStringValue(&str)); Tcl_DStringFree(&str); Tcl_ResetResult(pDb->interp); } /* ** This routine is called when a transaction is committed. The ** TCL script in pDb->zCommit is executed. If it returns non-zero or ** if it throws an exception, the transaction is rolled back instead ** of being committed. */ |
︙ | ︙ | |||
585 586 587 588 589 590 591 | int rc = TCL_OK; static const char *DB_strs[] = { "authorizer", "busy", "cache", "changes", "close", "collate", "collation_needed", "commit_hook", "complete", "copy", "errorcode", "eval", "function", "last_insert_rowid", "nullvalue", | | | | > | | | | 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 | int rc = TCL_OK; static const char *DB_strs[] = { "authorizer", "busy", "cache", "changes", "close", "collate", "collation_needed", "commit_hook", "complete", "copy", "errorcode", "eval", "function", "last_insert_rowid", "nullvalue", "onecolumn", "profile", "progress", "rekey", "timeout", "total_changes", "trace", "transaction", "version", 0 }; enum DB_enum { DB_AUTHORIZER, DB_BUSY, DB_CACHE, DB_CHANGES, DB_CLOSE, DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK, DB_COMPLETE, DB_COPY, DB_ERRORCODE, DB_EVAL, DB_FUNCTION, DB_LAST_INSERT_ROWID,DB_NULLVALUE, DB_ONECOLUMN, DB_PROFILE, DB_PROGRESS, DB_REKEY, DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE, DB_TRANSACTION, DB_VERSION }; /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ if( objc<2 ){ Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ..."); return TCL_ERROR; } |
︙ | ︙ | |||
776 777 778 779 780 781 782 | ** Shutdown the database */ case DB_CLOSE: { Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0)); break; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | ** Shutdown the database */ case DB_CLOSE: { Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0)); break; } /* ** $db collate NAME SCRIPT ** ** Create a new SQL collation function called NAME. Whenever ** that function is called, invoke SCRIPT to evaluate the function. */ case DB_COLLATE: { |
︙ | ︙ | |||
865 866 867 868 869 870 871 872 873 874 875 876 877 878 | Tcl_DecrRefCount(pDb->pCollateNeeded); } pDb->pCollateNeeded = Tcl_DuplicateObj(objv[2]); Tcl_IncrRefCount(pDb->pCollateNeeded); sqlite3_collation_needed(pDb->db, pDb, tclCollateNeeded); break; } /* $db complete SQL ** ** Return TRUE if SQL is a complete SQL statement. Return FALSE if ** additional lines of input are needed. This is similar to the ** built-in "info complete" command of Tcl. */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | Tcl_DecrRefCount(pDb->pCollateNeeded); } pDb->pCollateNeeded = Tcl_DuplicateObj(objv[2]); Tcl_IncrRefCount(pDb->pCollateNeeded); sqlite3_collation_needed(pDb->db, pDb, tclCollateNeeded); break; } /* $db commit_hook ?CALLBACK? ** ** Invoke the given callback just before committing every SQL transaction. ** If the callback throws an exception or returns non-zero, then the ** transaction is aborted. If CALLBACK is an empty string, the callback ** is disabled. */ case DB_COMMIT_HOOK: { if( objc>3 ){ Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?"); return TCL_ERROR; }else if( objc==2 ){ if( pDb->zCommit ){ Tcl_AppendResult(interp, pDb->zCommit, 0); } }else{ char *zCommit; int len; if( pDb->zCommit ){ Tcl_Free(pDb->zCommit); } zCommit = Tcl_GetStringFromObj(objv[2], &len); if( zCommit && len>0 ){ pDb->zCommit = Tcl_Alloc( len + 1 ); strcpy(pDb->zCommit, zCommit); }else{ pDb->zCommit = 0; } if( pDb->zCommit ){ pDb->interp = interp; sqlite3_commit_hook(pDb->db, DbCommitHandler, pDb); }else{ sqlite3_commit_hook(pDb->db, 0, 0); } } break; } /* $db complete SQL ** ** Return TRUE if SQL is a complete SQL statement. Return FALSE if ** additional lines of input are needed. This is similar to the ** built-in "info complete" command of Tcl. */ |
︙ | ︙ | |||
886 887 888 889 890 891 892 893 894 895 896 897 898 899 | } isComplete = sqlite3_complete( Tcl_GetStringFromObj(objv[2], 0) ); pResult = Tcl_GetObjResult(interp); Tcl_SetBooleanObj(pResult, isComplete); #endif break; } /* ** $db errorcode ** ** Return the numeric error code that was returned by the most recent ** call to sqlite3_exec(). */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 | } isComplete = sqlite3_complete( Tcl_GetStringFromObj(objv[2], 0) ); pResult = Tcl_GetObjResult(interp); Tcl_SetBooleanObj(pResult, isComplete); #endif break; } /* $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR? ** ** Copy data into table from filename, optionally using SEPARATOR ** as column separators. If a column contains a null string, or the ** value of NULLINDICATOR, a NULL is inserted for the column. ** conflict-algorithm is one of the sqlite conflict algorithms: ** rollback, abort, fail, ignore, replace ** On success, return the number of lines processed, not necessarily same ** as 'db changes' due to conflict-algorithm selected. ** ** This code is basically an implementation/enhancement of ** the sqlite3 shell.c ".import" command. ** ** This command usage is equivalent to the sqlite2.x COPY statement, ** which imports file data into a table using the PostgreSQL COPY file format: ** $db copy $conflit_algo $table_name $filename \t \\N */ case DB_COPY: { char *zTable; /* Insert data into this table */ char *zFile; /* The file from which to extract data */ char *zConflict; /* The conflict algorithm to use */ sqlite3_stmt *pStmt; /* A statement */ int rc; /* Result code */ int nCol; /* Number of columns in the table */ int nByte; /* Number of bytes in an SQL string */ int i, j; /* Loop counters */ int nSep; /* Number of bytes in zSep[] */ int nNull; /* Number of bytes in zNull[] */ char *zSql; /* An SQL statement */ char *zLine; /* A single line of input from the file */ char **azCol; /* zLine[] broken up into columns */ char *zCommit; /* How to commit changes */ FILE *in; /* The input file */ int lineno = 0; /* Line number of input file */ char zLineNum[80]; /* Line number print buffer */ Tcl_Obj *pResult; /* interp result */ char *zSep; char *zNull; if( objc<5 || objc>7 ){ Tcl_WrongNumArgs(interp, 2, objv, "CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"); return TCL_ERROR; } if( objc>=6 ){ zSep = Tcl_GetStringFromObj(objv[5], 0); }else{ zSep = "\t"; } if( objc>=7 ){ zNull = Tcl_GetStringFromObj(objv[6], 0); }else{ zNull = ""; } zConflict = Tcl_GetStringFromObj(objv[2], 0); zTable = Tcl_GetStringFromObj(objv[3], 0); zFile = Tcl_GetStringFromObj(objv[4], 0); nSep = strlen(zSep); nNull = strlen(zNull); if( nSep==0 ){ Tcl_AppendResult(interp, "Error: non-null separator required for copy", 0); return TCL_ERROR; } if(sqlite3StrICmp(zConflict, "rollback") != 0 && sqlite3StrICmp(zConflict, "abort" ) != 0 && sqlite3StrICmp(zConflict, "fail" ) != 0 && sqlite3StrICmp(zConflict, "ignore" ) != 0 && sqlite3StrICmp(zConflict, "replace" ) != 0 ) { Tcl_AppendResult(interp, "Error: \"", zConflict, "\", conflict-algorithm must be one of: rollback, " "abort, fail, ignore, or replace", 0); return TCL_ERROR; } zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable); if( zSql==0 ){ Tcl_AppendResult(interp, "Error: no such table: ", zTable, 0); return TCL_ERROR; } nByte = strlen(zSql); rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0); sqlite3_free(zSql); if( rc ){ Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0); nCol = 0; }else{ nCol = sqlite3_column_count(pStmt); } sqlite3_finalize(pStmt); if( nCol==0 ) { return TCL_ERROR; } zSql = malloc( nByte + 50 + nCol*2 ); if( zSql==0 ) { Tcl_AppendResult(interp, "Error: can't malloc()", 0); return TCL_ERROR; } sqlite3_snprintf(nByte+50, zSql, "INSERT OR %q INTO '%q' VALUES(?", zConflict, zTable); j = strlen(zSql); for(i=1; i<nCol; i++){ zSql[j++] = ','; zSql[j++] = '?'; } zSql[j++] = ')'; zSql[j] = 0; rc = sqlite3_prepare(pDb->db, zSql, 0, &pStmt, 0); free(zSql); if( rc ){ Tcl_AppendResult(interp, "Error: ", sqlite3_errmsg(pDb->db), 0); sqlite3_finalize(pStmt); return TCL_ERROR; } in = fopen(zFile, "rb"); if( in==0 ){ Tcl_AppendResult(interp, "Error: cannot open file: ", zFile, NULL); sqlite3_finalize(pStmt); return TCL_ERROR; } azCol = malloc( sizeof(azCol[0])*(nCol+1) ); if( azCol==0 ) { Tcl_AppendResult(interp, "Error: can't malloc()", 0); return TCL_ERROR; } sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0); zCommit = "COMMIT"; while( (zLine = local_getline(0, in))!=0 ){ char *z; i = 0; lineno++; azCol[0] = zLine; for(i=0, z=zLine; *z; z++){ if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){ *z = 0; i++; if( i<nCol ){ azCol[i] = &z[nSep]; z += nSep-1; } } } if( i+1!=nCol ){ char *zErr; zErr = malloc(200 + strlen(zFile)); sprintf(zErr,"Error: %s line %d: expected %d columns of data but found %d", zFile, lineno, nCol, i+1); Tcl_AppendResult(interp, zErr, 0); free(zErr); zCommit = "ROLLBACK"; break; } for(i=0; i<nCol; i++){ /* check for null data, if so, bind as null */ if ((nNull>0 && strcmp(azCol[i], zNull)==0) || strlen(azCol[i])==0) { sqlite3_bind_null(pStmt, i+1); }else{ sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC); } } sqlite3_step(pStmt); rc = sqlite3_reset(pStmt); free(zLine); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp,"Error: ", sqlite3_errmsg(pDb->db), 0); zCommit = "ROLLBACK"; break; } } free(azCol); fclose(in); sqlite3_finalize(pStmt); sqlite3_exec(pDb->db, zCommit, 0, 0, 0); if( zCommit[0] == 'C' ){ /* success, set result as number of lines processed */ pResult = Tcl_GetObjResult(interp); Tcl_SetIntObj(pResult, lineno); rc = TCL_OK; }else{ /* failure, append lineno where failed */ sprintf(zLineNum,"%d",lineno); Tcl_AppendResult(interp,", failed while processing line: ",zLineNum,0); rc = TCL_ERROR; } break; } /* ** $db errorcode ** ** Return the numeric error code that was returned by the most recent ** call to sqlite3_exec(). */ |
︙ | ︙ | |||
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 | Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE); }else{ /* Must flush any cached statements */ flushStmtCache( pDb ); } break; } /* ** $db last_insert_rowid ** ** Return an integer which is the ROWID for the most recent insert. */ case DB_LAST_INSERT_ROWID: { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 | Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE); }else{ /* Must flush any cached statements */ flushStmtCache( pDb ); } break; } /* ** $db nullvalue ?STRING? ** ** Change text used when a NULL comes back from the database. If ?STRING? ** is not present, then the current string used for NULL is returned. ** If STRING is present, then STRING is returned. ** */ case DB_NULLVALUE: { if( objc!=2 && objc!=3 ){ Tcl_WrongNumArgs(interp, 2, objv, "NULLVALUE"); return TCL_ERROR; } if( objc==3 ){ int len; char *zNull = Tcl_GetStringFromObj(objv[2], &len); if( pDb->zNull ){ Tcl_Free(pDb->zNull); } if( zNull && len>0 ){ pDb->zNull = Tcl_Alloc( len + 1 ); strncpy(pDb->zNull, zNull, len); pDb->zNull[len] = '\0'; }else{ pDb->zNull = 0; } } Tcl_SetObjResult(interp, dbTextToObj(pDb->zNull)); break; } /* ** $db last_insert_rowid ** ** Return an integer which is the ROWID for the most recent insert. */ case DB_LAST_INSERT_ROWID: { |
︙ | ︙ | |||
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 | #endif }else{ Tcl_WrongNumArgs(interp, 2, objv, "N CALLBACK"); return TCL_ERROR; } break; } /* ** $db rekey KEY ** ** Change the encryption key on the currently open database. */ case DB_REKEY: { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 | #endif }else{ Tcl_WrongNumArgs(interp, 2, objv, "N CALLBACK"); return TCL_ERROR; } break; } /* $db profile ?CALLBACK? ** ** Make arrangements to invoke the CALLBACK routine after each SQL statement ** that has run. The text of the SQL and the amount of elapse time are ** appended to CALLBACK before the script is run. */ case DB_PROFILE: { if( objc>3 ){ Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?"); return TCL_ERROR; }else if( objc==2 ){ if( pDb->zProfile ){ Tcl_AppendResult(interp, pDb->zProfile, 0); } }else{ char *zProfile; int len; if( pDb->zProfile ){ Tcl_Free(pDb->zProfile); } zProfile = Tcl_GetStringFromObj(objv[2], &len); if( zProfile && len>0 ){ pDb->zProfile = Tcl_Alloc( len + 1 ); strcpy(pDb->zProfile, zProfile); }else{ pDb->zProfile = 0; } #ifndef SQLITE_OMIT_TRACE if( pDb->zProfile ){ pDb->interp = interp; sqlite3_profile(pDb->db, DbProfileHandler, pDb); }else{ sqlite3_profile(pDb->db, 0, 0); } #endif } break; } /* ** $db rekey KEY ** ** Change the encryption key on the currently open database. */ case DB_REKEY: { |
︙ | ︙ | |||
1399 1400 1401 1402 1403 1404 1405 | Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS"); return TCL_ERROR; } if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR; sqlite3_busy_timeout(pDb->db, ms); break; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 | Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS"); return TCL_ERROR; } if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR; sqlite3_busy_timeout(pDb->db, ms); break; } /* ** $db total_changes ** ** Return the number of rows that were modified, inserted, or deleted ** since the database handle was created. */ |
︙ | ︙ | |||
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 | zTrace = Tcl_GetStringFromObj(objv[2], &len); if( zTrace && len>0 ){ pDb->zTrace = Tcl_Alloc( len + 1 ); strcpy(pDb->zTrace, zTrace); }else{ pDb->zTrace = 0; } if( pDb->zTrace ){ pDb->interp = interp; sqlite3_trace(pDb->db, DbTraceHandler, pDb); }else{ sqlite3_trace(pDb->db, 0, 0); } } break; } /* $db transaction [-deferred|-immediate|-exclusive] SCRIPT ** ** Start a new transaction (if we are not already in the midst of a | > > | 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 | zTrace = Tcl_GetStringFromObj(objv[2], &len); if( zTrace && len>0 ){ pDb->zTrace = Tcl_Alloc( len + 1 ); strcpy(pDb->zTrace, zTrace); }else{ pDb->zTrace = 0; } #ifndef SQLITE_OMIT_TRACE if( pDb->zTrace ){ pDb->interp = interp; sqlite3_trace(pDb->db, DbTraceHandler, pDb); }else{ sqlite3_trace(pDb->db, 0, 0); } #endif } break; } /* $db transaction [-deferred|-immediate|-exclusive] SCRIPT ** ** Start a new transaction (if we are not already in the midst of a |
︙ | ︙ | |||
1539 1540 1541 1542 1543 1544 1545 | if( rc==TCL_ERROR ){ zEnd = "ROLLBACK"; } else { zEnd = "COMMIT"; } sqlite3_exec(pDb->db, zEnd, 0, 0, 0); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 | if( rc==TCL_ERROR ){ zEnd = "ROLLBACK"; } else { zEnd = "COMMIT"; } sqlite3_exec(pDb->db, zEnd, 0, 0, 0); } break; } /* $db version ** ** Return the version string for this database. */ |
︙ | ︙ |
Changes to SQLite.Interop/src/tokenize.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** ** $Id: tokenize.c,v 1.11 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include <stdlib.h> /* |
︙ | ︙ |
Changes to SQLite.Interop/src/update.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** The most recently coded instruction was an OP_Column to retrieve column ** 'i' of table pTab. This routine sets the P3 parameter of the ** OP_Column to the default value, if any. |
︙ | ︙ | |||
255 256 257 258 259 260 261 | /* Begin generating code. */ v = sqlite3GetVdbe(pParse); if( v==0 ) goto update_cleanup; if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); sqlite3BeginWriteOperation(pParse, 1, pTab->iDb); | | | | | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | /* Begin generating code. */ v = sqlite3GetVdbe(pParse); if( v==0 ) goto update_cleanup; if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); sqlite3BeginWriteOperation(pParse, 1, pTab->iDb); /* If we are trying to update a view, realize that view into ** a ephemeral table. */ if( isView ){ Select *pView; pView = sqlite3SelectDup(pTab->pSelect); sqlite3Select(pParse, pView, SRT_VirtualTab, iCur, 0, 0, 0, 0); sqlite3SelectDelete(pView); } /* Begin the database scan */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); if( pWInfo==0 ) goto update_cleanup; |
︙ | ︙ | |||
465 466 467 468 469 470 471 | } } /* Repeat the above with the next record to be updated, until ** all record selected by the WHERE clause have been updated. */ sqlite3VdbeAddOp(v, OP_Goto, 0, addr); | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | } } /* Repeat the above with the next record to be updated, until ** all record selected by the WHERE clause have been updated. */ sqlite3VdbeAddOp(v, OP_Goto, 0, addr); sqlite3VdbeJumpHere(v, addr); /* Close all tables if there were no FOR EACH ROW triggers */ if( !triggers_exist ){ for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ if( openAll || aIdxUsed[i] ){ sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0); } |
︙ | ︙ |
Changes to SQLite.Interop/src/utf.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains routines used to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** | | | 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 to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** ** $Id: utf.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ ** ** Notes on UTF-8: ** ** Byte-0 Byte-1 Byte-2 Byte-3 Value ** 0xxxxxxx 00000000 00000000 0xxxxxxx ** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx ** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx |
︙ | ︙ |
Changes to SQLite.Interop/src/util.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | | 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.10 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> #if SQLITE_MEMDEBUG>2 && defined(__GLIBC__) #include <execinfo.h> |
︙ | ︙ | |||
361 362 363 364 365 366 367 368 369 370 371 372 373 374 | if( zNew ){ memcpy(zNew, z, n); zNew[n] = 0; } return zNew; } #endif /* !defined(SQLITE_MEMDEBUG) */ /* ** Create a string from the 2nd and subsequent arguments (up to the ** first NULL argument), store the string in memory obtained from ** sqliteMalloc() and make the pointer indicated by the 1st argument ** point to that string. The 1st argument must either be NULL or ** point to memory obtained from sqliteMalloc(). | > > > > > > > > > > > > > | 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 | if( zNew ){ memcpy(zNew, z, n); zNew[n] = 0; } return zNew; } #endif /* !defined(SQLITE_MEMDEBUG) */ /* ** Reallocate a buffer to a different size. This is similar to ** sqliteRealloc() except that if the allocation fails the buffer ** is freed. */ void sqlite3ReallocOrFree(void **ppBuf, int newSize){ void *pNew = sqliteRealloc(*ppBuf, newSize); if( pNew==0 ){ sqliteFree(*ppBuf); } *ppBuf = pNew; } /* ** Create a string from the 2nd and subsequent arguments (up to the ** first NULL argument), store the string in memory obtained from ** sqliteMalloc() and make the pointer indicated by the 1st argument ** point to that string. The 1st argument must either be NULL or ** point to memory obtained from sqliteMalloc(). |
︙ | ︙ |
Changes to SQLite.Interop/src/vacuum.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** This file contains code used to implement the VACUUM command. ** ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** This file contains code used to implement the VACUUM command. ** ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** ** $Id: vacuum.c,v 1.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #ifndef SQLITE_OMIT_VACUUM /* ** Generate a random name of 20 character in length. |
︙ | ︙ |
Changes to SQLite.Interop/src/vdbe.c.
︙ | ︙ | |||
39 40 41 42 43 44 45 | ** ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
156 157 158 159 160 161 162 | else if( flags & MEM_Str ){ pMem->type = SQLITE_TEXT; }else{ pMem->type = SQLITE_BLOB; } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | else if( flags & MEM_Str ){ pMem->type = SQLITE_TEXT; }else{ pMem->type = SQLITE_BLOB; } } /* ** Pop the stack N times. */ static void popStack(Mem **ppTos, int N){ Mem *pTos = *ppTos; while( N>0 ){ N--; Release(pTos); pTos--; } *ppTos = pTos; } /* ** Allocate cursor number iCur. Return a pointer to it. Return NULL ** if we run out of memory. */ static Cursor *allocateCursor(Vdbe *p, int iCur){ Cursor *pCx; assert( iCur<p->nCursor ); |
︙ | ︙ | |||
631 632 633 634 635 636 637 | p->returnDepth--; pc = p->returnStack[p->returnDepth] - 1; break; } /* Opcode: Halt P1 P2 P3 ** | | | 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | p->returnDepth--; pc = p->returnStack[p->returnDepth] - 1; break; } /* Opcode: Halt P1 P2 P3 ** ** Exit immediately. All open cursors, Fifos, etc are closed ** automatically. ** ** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(), ** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0). ** For errors, it can be some other value. If P1!=0 then P2 will determine ** whether or not to rollback the current transaction. Do not rollback ** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort, |
︙ | ︙ | |||
769 770 771 772 773 774 775 776 777 778 779 780 781 782 | /* Opcode: Null * * * ** ** Push a NULL onto the stack. */ case OP_Null: { pTos++; pTos->flags = MEM_Null; break; } #ifndef SQLITE_OMIT_BLOB_LITERAL /* Opcode: HexBlob * * P3 ** | > | 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | /* Opcode: Null * * * ** ** Push a NULL onto the stack. */ case OP_Null: { pTos++; pTos->flags = MEM_Null; pTos->n = 0; break; } #ifndef SQLITE_OMIT_BLOB_LITERAL /* Opcode: HexBlob * * P3 ** |
︙ | ︙ | |||
1160 1161 1162 1163 1164 1165 1166 | assert( pOp->p3type==P3_COLLSEQ ); break; } /* Opcode: Function P1 P2 P3 ** ** Invoke a user function (P3 is a pointer to a Function structure that | | | | | | < | 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | assert( pOp->p3type==P3_COLLSEQ ); break; } /* Opcode: Function P1 P2 P3 ** ** Invoke a user function (P3 is a pointer to a Function structure that ** defines the function) with P2 arguments taken from the stack. Pop all ** arguments from the stack and push back the result. ** ** P1 is a 32-bit bitmask indicating whether or not each argument to the ** function was determined to be constant at compile time. If the first ** argument was constant then bit 0 of P1 is set. This is used to determine ** whether meta data associated with a user function argument using the ** sqlite3_set_auxdata() API may be safely retained until the next ** invocation of this opcode. ** ** See also: AggStep and AggFinal */ case OP_Function: { int i; Mem *pArg; sqlite3_context ctx; sqlite3_value **apVal; int n = pOp->p2; apVal = p->apArg; assert( apVal || n==0 ); pArg = &pTos[1-n]; for(i=0; i<n; i++, pArg++){ apVal[i] = pArg; storeTypeInfo(pArg, db->enc); |
︙ | ︙ | |||
1218 1219 1220 1221 1222 1223 1224 | if( sqlite3_malloc_failed ) goto no_mem; popStack(&pTos, n); /* If any auxilary data functions have been called by this user function, ** immediately call the destructor for any non-static values. */ if( ctx.pVdbeFunc ){ | | | 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | if( sqlite3_malloc_failed ) goto no_mem; popStack(&pTos, n); /* If any auxilary data functions have been called by this user function, ** immediately call the destructor for any non-static values. */ if( ctx.pVdbeFunc ){ sqlite3VdbeDeleteAuxData(ctx.pVdbeFunc, pOp->p1); pOp->p3 = (char *)ctx.pVdbeFunc; pOp->p3type = P3_VDBEFUNC; } /* Copy the result of the function to the top of the stack */ sqlite3VdbeChangeEncoding(&ctx.s, db->enc); pTos++; |
︙ | ︙ | |||
1472 1473 1474 1475 1476 1477 1478 | /* Opcode: Eq P1 P2 P3 ** ** Pop the top two elements from the stack. If they are equal, then ** jump to instruction P2. Otherwise, continue to the next instruction. ** ** If the 0x100 bit of P1 is true and either operand is NULL then take the | | > > > > > > > | 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 | /* Opcode: Eq P1 P2 P3 ** ** Pop the top two elements from the stack. If they are equal, then ** jump to instruction P2. Otherwise, continue to the next instruction. ** ** If the 0x100 bit of P1 is true and either operand is NULL then take the ** jump. If the 0x100 bit of P1 is clear then fall thru if either operand ** is NULL. ** ** If the 0x200 bit of P1 is set and either operand is NULL then ** both operands are converted to integers prior to comparison. ** NULL operands are converted to zero and non-NULL operands are ** converted to 1. Thus, for example, with 0x200 set, NULL==NULL is true ** whereas it would normally be NULL. Similarly, NULL==123 is false when ** 0x200 is set but is NULL when the 0x200 bit of P1 is clear. ** ** The least significant byte of P1 (mask 0xff) must be an affinity character - ** 'n', 't', 'i' or 'o' - or 0x00. An attempt is made to coerce both values ** according to the affinity before the comparison is made. If the byte is ** 0x00, then numeric affinity is used. ** ** Once any conversions have taken place, and neither value is NULL, |
︙ | ︙ | |||
1542 1543 1544 1545 1546 1547 1548 | flags = pTos->flags|pNos->flags; /* If either value is a NULL P2 is not zero, take the jump if the least ** significant byte of P1 is true. If P2 is zero, then push a NULL onto ** the stack. */ if( flags&MEM_Null ){ | > > > > > > > > > > > > > > > > > > > | | | > > | | | | | > | 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 | flags = pTos->flags|pNos->flags; /* If either value is a NULL P2 is not zero, take the jump if the least ** significant byte of P1 is true. If P2 is zero, then push a NULL onto ** the stack. */ if( flags&MEM_Null ){ if( (pOp->p1 & 0x200)!=0 ){ /* The 0x200 bit of P1 means, roughly "do not treat NULL as the ** magic SQL value it normally is - treat it as if it were another ** integer". ** ** With 0x200 set, if either operand is NULL then both operands ** are converted to integers prior to being passed down into the ** normal comparison logic below. NULL operands are converted to ** zero and non-NULL operands are converted to 1. Thus, for example, ** with 0x200 set, NULL==NULL is true whereas it would normally ** be NULL. Similarly, NULL!=123 is true. */ sqlite3VdbeMemSetInt64(pTos, (pTos->flags & MEM_Null)==0); sqlite3VdbeMemSetInt64(pNos, (pNos->flags & MEM_Null)==0); }else{ /* If the 0x200 bit of P1 is clear and either operand is NULL then ** the result is always NULL. The jump is taken if the 0x100 bit ** of P1 is set. */ popStack(&pTos, 2); if( pOp->p2 ){ if( pOp->p1 & 0x100 ){ pc = pOp->p2-1; } }else{ pTos++; pTos->flags = MEM_Null; } break; } } affinity = pOp->p1 & 0xFF; if( affinity ){ applyAffinity(pNos, affinity, db->enc); applyAffinity(pTos, affinity, db->enc); } |
︙ | ︙ | |||
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 | } /* Opcode: Noop * * * ** ** Do nothing. This instruction is often useful as a jump ** destination. */ case OP_Noop: { /* no-push */ break; } /* Opcode: If P1 P2 * ** ** Pop a single boolean from the stack. If the boolean popped is | > > > > > > > | 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 | } /* Opcode: Noop * * * ** ** Do nothing. This instruction is often useful as a jump ** destination. */ /* ** The magic Explain opcode are only inserted when explain==2 (which ** is to say when the EXPLAIN QUERY PLAN syntax is used.) ** This opcode records information from the optimizer. It is the ** the same as a no-op. This opcodesnever appears in a real VM program. */ case OP_Explain: case OP_Noop: { /* no-push */ break; } /* Opcode: If P1 P2 * ** ** Pop a single boolean from the stack. If the boolean popped is |
︙ | ︙ | |||
2016 2017 2018 2019 2020 2021 2022 | } /* The header should end at the start of data and the data should ** end at last byte of the record. If this is not the case then ** we are dealing with a malformed record. */ if( idx!=szHdr || offset!=payloadSize ){ | | | 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 | } /* The header should end at the start of data and the data should ** end at last byte of the record. If this is not the case then ** we are dealing with a malformed record. */ if( idx!=szHdr || offset!=payloadSize ){ rc = SQLITE_CORRUPT_BKPT; goto op_column_out; } /* Remember all aType and aColumn information if we have a cursor ** to remember it in. */ if( pC ){ pC->payloadSize = payloadSize; |
︙ | ︙ | |||
2570 2571 2572 2573 2574 2575 2576 | /* Sanity checking. Only the lower four bits of the flags byte should ** be used. Bit 3 (mask 0x08) is unpreditable. The lower 3 bits ** (mask 0x07) should be either 5 (intkey+leafdata for tables) or ** 2 (zerodata for indices). If these conditions are not met it can ** only mean that we are dealing with a corrupt database file */ if( (flags & 0xf0)!=0 || ((flags & 0x07)!=5 && (flags & 0x07)!=2) ){ | | | | | > | 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 | /* Sanity checking. Only the lower four bits of the flags byte should ** be used. Bit 3 (mask 0x08) is unpreditable. The lower 3 bits ** (mask 0x07) should be either 5 (intkey+leafdata for tables) or ** 2 (zerodata for indices). If these conditions are not met it can ** only mean that we are dealing with a corrupt database file */ if( (flags & 0xf0)!=0 || ((flags & 0x07)!=5 && (flags & 0x07)!=2) ){ rc = SQLITE_CORRUPT_BKPT; goto abort_due_to_error; } pCur->isTable = (flags & BTREE_INTKEY)!=0; pCur->isIndex = (flags & BTREE_ZERODATA)!=0; /* If P3==0 it means we are expected to open a table. If P3!=0 then ** we expect to be opening an index. If this is not what happened, ** then the database is corrupt */ if( (pCur->isTable && pOp->p3type==P3_KEYINFO) || (pCur->isIndex && pOp->p3type!=P3_KEYINFO) ){ rc = SQLITE_CORRUPT_BKPT; goto abort_due_to_error; } break; } case SQLITE_EMPTY: { pCur->isTable = pOp->p3type!=P3_KEYINFO; pCur->isIndex = !pCur->isTable; rc = SQLITE_OK; break; } default: { goto abort_due_to_error; } } break; } /* Opcode: OpenVirtual P1 P2 P3 ** ** Open a new cursor P1 to a transient or virtual table. ** The cursor is always opened read/write even if ** the main database is read-only. The transient or virtual ** table is deleted automatically when the cursor is closed. ** ** P2 is the number of columns in the virtual table. ** The cursor points to a BTree table if P3==0 and to a BTree index ** if P3 is not 0. If P3 is not NULL, it points to a KeyInfo structure ** that defines the format of keys in the index. */ case OP_OpenVirtual: { /* no-push */ int i = pOp->p1; Cursor *pCx; |
︙ | ︙ | |||
2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 | pCx->isTable = 0; }else{ rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, 0, &pCx->pCursor); pCx->isTable = 1; pCx->pIncrKey = &pCx->bogusIncrKey; } } pCx->isIndex = !pCx->isTable; break; } #ifndef SQLITE_OMIT_TRIGGER /* Opcode: OpenPseudo P1 * * ** | > | 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 | pCx->isTable = 0; }else{ rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, 0, &pCx->pCursor); pCx->isTable = 1; pCx->pIncrKey = &pCx->bogusIncrKey; } } pCx->nField = pOp->p2; pCx->isIndex = !pCx->isTable; break; } #ifndef SQLITE_OMIT_TRIGGER /* Opcode: OpenPseudo P1 * * ** |
︙ | ︙ | |||
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 | pC->rowidIsValid = 0; } } Release(pTos); pTos--; break; } /* Opcode: NewRowid P1 P2 * ** ** Get a new integer record number (a.k.a "rowid") used as the key to a table. ** The record number is not previously used as a key in the database ** table that cursor P1 points to. The new record number is pushed ** onto the stack. | > > > > > > > > > > > > > > > > > > | 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 | pC->rowidIsValid = 0; } } Release(pTos); pTos--; break; } /* Opcode: Sequence P1 * * ** ** Push an integer onto the stack which is the next available ** sequence number for cursor P1. The sequence number on the ** cursor is incremented after the push. */ case OP_Sequence: { int i = pOp->p1; assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); assert( p->apCsr[i]!=0 ); pTos++; pTos->i = p->apCsr[i]->seqCount++; pTos->flags = MEM_Int; break; } /* Opcode: NewRowid P1 P2 * ** ** Get a new integer record number (a.k.a "rowid") used as the key to a table. ** The record number is not previously used as a key in the database ** table that cursor P1 points to. The new record number is pushed ** onto the stack. |
︙ | ︙ | |||
3090 3091 3092 3093 3094 3095 3096 | ** to double the speed of the COPY operation. */ int res, rx=SQLITE_OK, cnt; i64 x; cnt = 0; if( (sqlite3BtreeFlags(pC->pCursor)&(BTREE_INTKEY|BTREE_ZERODATA)) != BTREE_INTKEY ){ | | | 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 | ** to double the speed of the COPY operation. */ int res, rx=SQLITE_OK, cnt; i64 x; cnt = 0; if( (sqlite3BtreeFlags(pC->pCursor)&(BTREE_INTKEY|BTREE_ZERODATA)) != BTREE_INTKEY ){ rc = SQLITE_CORRUPT_BKPT; goto abort_due_to_error; } assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_INTKEY)!=0 ); assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_ZERODATA)==0 ); #ifdef SQLITE_32BIT_ROWID # define MAX_ROWID 0x7fffffff |
︙ | ︙ | |||
3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 | } }else{ pC->nullRow = 0; } break; } /* Opcode: Rewind P1 P2 * ** ** The next use of the Rowid or Column or Next instruction for P1 ** will refer to the first entry in the database table or index. ** If the table or index is empty and P2>0, then jump immediately to P2. ** If P2 is 0 or if the table or index is not empty, fall through ** to the following instruction. | > > > > > > > > > > > > > > > > > > | 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 | } }else{ pC->nullRow = 0; } break; } /* Opcode: Sort P1 P2 * ** ** This opcode does exactly the same thing as OP_Rewind except that ** it increments an undocumented global variable used for testing. ** ** Sorting is accomplished by writing records into a sorting index, ** then rewinding that index and playing it back from beginning to ** end. We use the OP_Sort opcode instead of OP_Rewind to do the ** rewinding so that the global variable will be incremented and ** regression tests can determine whether or not the optimizer is ** correctly optimizing out sorts. */ case OP_Sort: { /* no-push */ sqlite3_sort_count++; sqlite3_search_count--; /* Fall through into OP_Rewind */ } /* Opcode: Rewind P1 P2 * ** ** The next use of the Rowid or Column or Next instruction for P1 ** will refer to the first entry in the database table or index. ** If the table or index is empty and P2>0, then jump immediately to P2. ** If P2 is 0 or if the table or index is not empty, fall through ** to the following instruction. |
︙ | ︙ | |||
3681 3682 3683 3684 3685 3686 3687 | ** an epsilon prior to the comparison. This makes the opcode work ** like IdxLE. */ case OP_IdxLT: /* no-push */ case OP_IdxGT: /* no-push */ case OP_IdxGE: { /* no-push */ int i= pOp->p1; | < | | 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 | ** an epsilon prior to the comparison. This makes the opcode work ** like IdxLE. */ case OP_IdxLT: /* no-push */ case OP_IdxGT: /* no-push */ case OP_IdxGE: { /* no-push */ int i= pOp->p1; Cursor *pC; assert( i>=0 && i<p->nCursor ); assert( p->apCsr[i]!=0 ); assert( pTos>=p->aStack ); if( (pC = p->apCsr[i])->pCursor!=0 ){ int res, rc; assert( pTos->flags & MEM_Blob ); /* Created using OP_Make*Key */ Stringify(pTos, db->enc); assert( pC->deferredMoveto==0 ); *pC->pIncrKey = pOp->p3!=0; assert( pOp->p3==0 || pOp->opcode!=OP_IdxGT ); |
︙ | ︙ | |||
4019 4020 4021 4022 4023 4024 4025 | pTos++; pTos->i = v; pTos->flags = MEM_Int; } break; } | < < < < < < < < < < < < < < < < < < < < < < < < < | | 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 | pTos++; pTos->i = v; pTos->flags = MEM_Int; } break; } #ifndef SQLITE_OMIT_TRIGGER /* Opcode: ContextPush * * * ** ** Save the current Vdbe context such that it can be restored by a ContextPop ** opcode. The context stores the last insert row id, the last statement change ** count, and the current statement change count. */ case OP_ContextPush: { /* no-push */ int i = p->contextStackTop++; Context *pContext; assert( i>=0 ); /* FIX ME: This should be allocated as part of the vdbe at compile-time */ if( i>=p->contextStackDepth ){ p->contextStackDepth = i+1; sqlite3ReallocOrFree((void**)&p->contextStack, sizeof(Context)*(i+1)); if( p->contextStack==0 ) goto no_mem; } pContext = &p->contextStack[i]; pContext->lastRowid = db->lastRowid; pContext->nChange = p->nChange; pContext->sFifo = p->sFifo; sqlite3VdbeFifoInit(&p->sFifo); |
︙ | ︙ | |||
4087 4088 4089 4090 4091 4092 4093 | p->nChange = pContext->nChange; sqlite3VdbeFifoClear(&p->sFifo); p->sFifo = pContext->sFifo; break; } #endif /* #ifndef SQLITE_OMIT_TRIGGER */ | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 | p->nChange = pContext->nChange; sqlite3VdbeFifoClear(&p->sFifo); p->sFifo = pContext->sFifo; break; } #endif /* #ifndef SQLITE_OMIT_TRIGGER */ /* Opcode: MemStore P1 P2 * ** ** Write the top of the stack into memory location P1. ** P1 should be a small integer since space is allocated ** for all memory locations between 0 and P1 inclusive. ** ** After the data is stored in the memory location, the |
︙ | ︙ | |||
4292 4293 4294 4295 4296 4297 4298 | assert( pMem->flags==MEM_Int ); if( pMem->i>0 ){ pc = pOp->p2 - 1; } break; } | | < < < | < < < | < | | < < | < < | < < | > > > > > > | < | | | < | < < < < | | | | | | > < < < | | < | < < < < | < | | < < | | | | < < < > | > > | | < < | | < < | < | < < | < < < < < < < | < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 | assert( pMem->flags==MEM_Int ); if( pMem->i>0 ){ pc = pOp->p2 - 1; } break; } /* Opcode: MemNull P1 * * ** ** Store a NULL in memory cell P1 */ case OP_MemNull: { assert( pOp->p1>=0 && pOp->p1<p->nMem ); sqlite3VdbeMemSetNull(&p->aMem[pOp->p1]); break; } /* Opcode: MemInt P1 P2 * ** ** Store the integer value P1 in memory cell P2. */ case OP_MemInt: { assert( pOp->p2>=0 && pOp->p2<p->nMem ); sqlite3VdbeMemSetInt64(&p->aMem[pOp->p2], pOp->p1); break; } /* Opcode: MemMove P1 P2 * ** ** Move the content of memory cell P2 over to memory cell P1. ** Any prior content of P1 is erased. Memory cell P2 is left ** containing a NULL. */ case OP_MemMove: { assert( pOp->p1>=0 && pOp->p1<p->nMem ); assert( pOp->p2>=0 && pOp->p2<p->nMem ); rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], &p->aMem[pOp->p2]); break; } /* Opcode: AggStep P1 P2 P3 ** ** Execute the step function for an aggregate. The ** function has P2 arguments. P3 is a pointer to the FuncDef ** structure that specifies the function. Use memory location ** P1 as the accumulator. ** ** The P2 arguments are popped from the stack. */ case OP_AggStep: { /* no-push */ int n = pOp->p2; int i; Mem *pMem, *pRec; sqlite3_context ctx; sqlite3_value **apVal; assert( n>=0 ); pRec = &pTos[1-n]; assert( pRec>=p->aStack ); apVal = p->apArg; assert( apVal || n==0 ); for(i=0; i<n; i++, pRec++){ apVal[i] = pRec; storeTypeInfo(pRec, db->enc); } ctx.pFunc = (FuncDef*)pOp->p3; assert( pOp->p1>=0 && pOp->p1<p->nMem ); ctx.pMem = pMem = &p->aMem[pOp->p1]; pMem->n++; ctx.isError = 0; ctx.pColl = 0; if( ctx.pFunc->needCollSeq ){ assert( pOp>p->aOp ); assert( pOp[-1].p3type==P3_COLLSEQ ); assert( pOp[-1].opcode==OP_CollSeq ); ctx.pColl = (CollSeq *)pOp[-1].p3; } (ctx.pFunc->xStep)(&ctx, n, apVal); popStack(&pTos, n); if( ctx.isError ){ rc = SQLITE_ERROR; } break; } /* Opcode: AggFinal P1 P2 P3 ** ** Execute the finalizer function for an aggregate. P1 is ** the memory location that is the accumulator for the aggregate. ** ** P2 is the number of arguments that the step function takes and ** P3 is a pointer to the FuncDef for this function. The P2 ** argument is not used by this opcode. It is only there to disambiguate ** functions that can take varying numbers of arguments. The ** P3 argument is only needed for the degenerate case where ** the step function was not previously called. */ case OP_AggFinal: { /* no-push */ Mem *pMem; assert( pOp->p1>=0 && pOp->p1<p->nMem ); pMem = &p->aMem[pOp->p1]; assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); sqlite3VdbeMemFinalize(pMem, (FuncDef*)pOp->p3); break; } /* Opcode: Vacuum * * * ** ** Vacuum the entire database. This opcode will cause other virtual ** machines to be created and run. It may not be called from within ** a transaction. */ |
︙ | ︙ |
Changes to SQLite.Interop/src/vdbe.h.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** 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. ** | | | 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.9 2005/10/05 19:38:29 rmsimpson Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ #include <stdio.h> /* ** A single VDBE is an opaque structure named "Vdbe". Only routines |
︙ | ︙ | |||
100 101 102 103 104 105 106 107 108 109 110 | Vdbe *sqlite3VdbeCreate(sqlite3*); void sqlite3VdbeCreateCallback(Vdbe*, int*); int sqlite3VdbeAddOp(Vdbe*,int,int,int); int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int); int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N); VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); int sqlite3VdbeMakeLabel(Vdbe*); void sqlite3VdbeDelete(Vdbe*); | > | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | Vdbe *sqlite3VdbeCreate(sqlite3*); void sqlite3VdbeCreateCallback(Vdbe*, int*); int sqlite3VdbeAddOp(Vdbe*,int,int,int); int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int); int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); void sqlite3VdbeJumpHere(Vdbe*, int addr); void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N); VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); int sqlite3VdbeMakeLabel(Vdbe*); void sqlite3VdbeDelete(Vdbe*); void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int); 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); |
︙ | ︙ |
Changes to SQLite.Interop/src/vdbeInt.h.
︙ | ︙ | |||
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | Btree *pBt; /* Separate file holding temporary table */ int nData; /* Number of bytes in pData */ char *pData; /* Data for a NEW or OLD pseudo-table */ i64 iKey; /* Key for the NEW or OLD pseudo-table row */ u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */ KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ int nField; /* Number of fields in the header */ /* Cached information about the header for the data record that the ** cursor is currently pointing to. Only valid if cacheValid is true. ** zRow might point to (ephemeral) data for the current row, or it might ** be NULL. */ Bool cacheValid; /* True if the cache is valid */ int payloadSize; /* Total number of bytes in the record */ | > | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | Btree *pBt; /* Separate file holding temporary table */ int nData; /* Number of bytes in pData */ char *pData; /* Data for a NEW or OLD pseudo-table */ i64 iKey; /* Key for the NEW or OLD pseudo-table row */ u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */ KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ int nField; /* Number of fields in the header */ i64 seqCount; /* Sequence counter */ /* Cached information about the header for the data record that the ** cursor is currently pointing to. Only valid if cacheValid is true. ** zRow might point to (ephemeral) data for the current row, or it might ** be NULL. */ Bool cacheValid; /* True if the cache is valid */ int payloadSize; /* Total number of bytes in the record */ |
︙ | ︙ | |||
109 110 111 112 113 114 115 | ** ** Each value has a manifest type. The manifest type of the value stored ** in a Mem struct is returned by the MemType(Mem*) macro. The type is ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or ** SQLITE_BLOB. */ struct Mem { | | > > < < < < < < < < < < < < < < < < < < < | 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 | ** ** Each value has a manifest type. The manifest type of the value stored ** in a Mem struct is returned by the MemType(Mem*) macro. The type is ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or ** SQLITE_BLOB. */ struct Mem { i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */ double r; /* Real value */ char *z; /* String or BLOB value */ int n; /* Number of characters in string value, including '\0' */ u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ u8 type; /* One of MEM_Null, MEM_Str, etc. */ u8 enc; /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */ void (*xDel)(void *); /* If not null, call this function to delete Mem.z */ char zShort[NBFS]; /* Space for short strings */ }; typedef struct Mem Mem; /* One or more of the following flags are set to indicate the validOK ** representations of the value stored in the Mem struct. ** ** If the MEM_Null flag is set, then the value is an SQL NULL value. ** No other flags may be set in this case. ** ** If the MEM_Str flag is set then Mem.z points at a string representation. |
︙ | ︙ | |||
169 170 171 172 173 174 175 | ** string is \000 or \u0000 terminated */ #define MEM_Term 0x0020 /* String rep is nul terminated */ #define MEM_Dyn 0x0040 /* Need to call sqliteFree() on Mem.z */ #define MEM_Static 0x0080 /* Mem.z points to a static string */ #define MEM_Ephem 0x0100 /* Mem.z points to an ephemeral string */ #define MEM_Short 0x0200 /* Mem.z points to Mem.zShort */ | < < < < < | | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | ** string is \000 or \u0000 terminated */ #define MEM_Term 0x0020 /* String rep is nul terminated */ #define MEM_Dyn 0x0040 /* Need to call sqliteFree() on Mem.z */ #define MEM_Static 0x0080 /* Mem.z points to a static string */ #define MEM_Ephem 0x0100 /* Mem.z points to an ephemeral string */ #define MEM_Short 0x0200 /* Mem.z points to Mem.zShort */ #define MEM_Agg 0x0400 /* Mem.z points to an agg function context */ /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains ** additional information about auxiliary information bound to arguments ** of the function. This is used to implement the sqlite3_get_auxdata() ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data ** that can be associated with a constant argument to a function. This |
︙ | ︙ | |||
206 207 208 209 210 211 212 | ** implement the SQL functions. ** ** There is a typedef for this structure in sqlite.h. So all routines, ** even the public interface to SQLite, can use a pointer to this structure. ** But this file is the only place where the internal details of this ** structure are known. ** | | | | | | < | < < < < < < < < < < < < < < < < < < < < < < < < | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | ** implement the SQL functions. ** ** There is a typedef for this structure in sqlite.h. So all routines, ** even the public interface to SQLite, can use a pointer to this structure. ** But this file is the only place where the internal details of this ** structure are known. ** ** This structure is defined inside of vdbeInt.h because it uses substructures ** (Mem) which are only defined there. */ struct sqlite3_context { FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ Mem s; /* The return value is stored here */ Mem *pMem; /* Memory cell used to store aggregate context */ u8 isError; /* Set to true for an error */ CollSeq *pColl; /* Collating sequence */ }; /* ** A Set structure is used for quick testing to see if a value ** is part of a small set. Sets are used to implement code like ** this: ** x.y IN ('hi','hoo','hum') |
︙ | ︙ | |||
320 321 322 323 324 325 326 | int *aLabel; /* Space to hold the labels */ Mem *aStack; /* The operand stack, except string values */ Mem *pTos; /* Top entry in the operand stack */ Mem **apArg; /* Arguments to currently executing user function */ Mem *aColName; /* Column names to return */ int nCursor; /* Number of slots in apCsr[] */ Cursor **apCsr; /* One element of this array for each open cursor */ | < < < < < | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | int *aLabel; /* Space to hold the labels */ Mem *aStack; /* The operand stack, except string values */ Mem *pTos; /* Top entry in the operand stack */ Mem **apArg; /* Arguments to currently executing user function */ Mem *aColName; /* Column names to return */ int nCursor; /* Number of slots in apCsr[] */ Cursor **apCsr; /* One element of this array for each open cursor */ int nVar; /* Number of entries in aVar[] */ Mem *aVar; /* Values for the OP_Variable opcode. */ char **azVar; /* Name of variables */ int okVar; /* True if azVar[] has been initialized */ int magic; /* Magic number for sanity checking */ int nMem; /* Number of memory locations currently allocated */ Mem *aMem; /* The memory locations */ int nCallback; /* Number of callbacks invoked so far */ Fifo sFifo; /* A list of ROWIDs */ int contextStackTop; /* Index of top element in the context stack */ int contextStackDepth; /* The size of the "context" stack */ Context *contextStack; /* Stack used by opcodes ContextPush & ContextPop*/ int pc; /* The program counter */ int rc; /* Value to return */ |
︙ | ︙ | |||
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | char *zErrMsg; /* Error message written here */ u8 resOnStack; /* True if there are result values on the stack */ u8 explain; /* True if EXPLAIN present on SQL command */ u8 changeCntOn; /* True to update the change-counter */ u8 aborted; /* True if ROLLBACK in another VM causes an abort */ u8 expired; /* True if the VM needs to be recompiled */ int nChange; /* Number of db changes made since last reset */ }; /* ** The following are allowed values for Vdbe.magic */ #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ #define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */ #define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */ /* ** Function prototypes */ void sqlite3VdbeFreeCursor(Cursor*); | > < < | 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 | char *zErrMsg; /* Error message written here */ u8 resOnStack; /* True if there are result values on the stack */ u8 explain; /* True if EXPLAIN present on SQL command */ u8 changeCntOn; /* True to update the change-counter */ u8 aborted; /* True if ROLLBACK in another VM causes an abort */ u8 expired; /* True if the VM needs to be recompiled */ int nChange; /* Number of db changes made since last reset */ i64 startTime; /* Time when query started - used for profiling */ }; /* ** The following are allowed values for Vdbe.magic */ #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ #define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */ #define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */ /* ** Function prototypes */ void sqlite3VdbeFreeCursor(Cursor*); void sqliteVdbePopStack(Vdbe*,int); int sqlite3VdbeCursorMoveto(Cursor*); #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) void sqlite3VdbePrintOp(FILE*, int, Op*); #endif #ifdef SQLITE_DEBUG void sqlite3VdbePrintSql(Vdbe*); |
︙ | ︙ | |||
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | int sqlite3VdbeMemStringify(Mem*, int); i64 sqlite3VdbeIntValue(Mem*); int sqlite3VdbeMemIntegerify(Mem*); double sqlite3VdbeRealValue(Mem*); int sqlite3VdbeMemRealify(Mem*); int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); void sqlite3VdbeMemRelease(Mem *p); #ifndef NDEBUG void sqlite3VdbeMemSanity(Mem*, u8); int sqlite3VdbeOpcodeNoPush(u8); #endif int sqlite3VdbeMemTranslate(Mem*, u8); void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf); int sqlite3VdbeMemHandleBom(Mem *pMem); void sqlite3VdbeFifoInit(Fifo*); int sqlite3VdbeFifoPush(Fifo*, i64); int sqlite3VdbeFifoPop(Fifo*, i64*); void sqlite3VdbeFifoClear(Fifo*); | > | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | int sqlite3VdbeMemStringify(Mem*, int); i64 sqlite3VdbeIntValue(Mem*); int sqlite3VdbeMemIntegerify(Mem*); double sqlite3VdbeRealValue(Mem*); int sqlite3VdbeMemRealify(Mem*); int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); void sqlite3VdbeMemRelease(Mem *p); void sqlite3VdbeMemFinalize(Mem*, FuncDef*); #ifndef NDEBUG void sqlite3VdbeMemSanity(Mem*, u8); int sqlite3VdbeOpcodeNoPush(u8); #endif int sqlite3VdbeMemTranslate(Mem*, u8); void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf); int sqlite3VdbeMemHandleBom(Mem *pMem); void sqlite3VdbeFifoInit(Fifo*); int sqlite3VdbeFifoPush(Fifo*, i64); int sqlite3VdbeFifoPop(Fifo*, i64*); void sqlite3VdbeFifoClear(Fifo*); |
Changes to SQLite.Interop/src/vdbeapi.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ************************************************************************* ** ** This file contains code use to implement APIs that are part of the ** VDBE. */ #include "sqliteInt.h" #include "vdbeInt.h" /* ** Return TRUE (non-zero) of the statement supplied as an argument needs ** to be recompiled. A statement needs to be recompiled whenever the ** execution environment changes in a way that would alter the program ** that sqlite3_prepare() generates. For example, if new functions or ** collating sequences are registered or if an authorizer function is | > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** ** This file contains code use to implement APIs that are part of the ** VDBE. */ #include "sqliteInt.h" #include "vdbeInt.h" #include "os.h" /* ** Return TRUE (non-zero) of the statement supplied as an argument needs ** to be recompiled. A statement needs to be recompiled whenever the ** execution environment changes in a way that would alter the program ** that sqlite3_prepare() generates. For example, if new functions or ** collating sequences are registered or if an authorizer function is |
︙ | ︙ | |||
169 170 171 172 173 174 175 176 177 | } db = p->db; if( sqlite3SafetyOn(db) ){ p->rc = SQLITE_MISUSE; return SQLITE_MISUSE; } if( p->pc<0 ){ /* Invoke the trace callback if there is one */ | > | > > > > > > | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | } db = p->db; if( sqlite3SafetyOn(db) ){ p->rc = SQLITE_MISUSE; return SQLITE_MISUSE; } if( p->pc<0 ){ #ifndef SQLITE_OMIT_TRACE /* Invoke the trace callback if there is one */ if( db->xTrace && !db->init.busy ){ assert( p->nOp>0 ); assert( p->aOp[p->nOp-1].opcode==OP_Noop ); assert( p->aOp[p->nOp-1].p3!=0 ); assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC ); sqlite3SafetyOff(db); db->xTrace(db->pTraceArg, p->aOp[p->nOp-1].p3); if( sqlite3SafetyOn(db) ){ p->rc = SQLITE_MISUSE; return SQLITE_MISUSE; } } if( db->xProfile && !db->init.busy ){ double rNow; sqlite3OsCurrentTime(&rNow); p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0; } #endif /* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned ** on in debugging mode. */ #ifdef SQLITE_DEBUG if( (db->flags & SQLITE_SqlTrace)!=0 ){ sqlite3DebugPrintf("SQL-trace: %s\n", p->aOp[p->nOp-1].p3); |
︙ | ︙ | |||
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 | { rc = sqlite3VdbeExec(p); } if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); return rc; } /* ** Extract the user data from a sqlite3_context structure and return a ** pointer to it. */ void *sqlite3_user_data(sqlite3_context *p){ assert( p && p->pFunc ); return p->pFunc->pUserData; } /* ** Allocate or return the aggregate context for a user function. A new ** context is allocated on the first call. Subsequent calls return the ** same context that was returned on prior calls. */ void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){ assert( p && p->pFunc && p->pFunc->xStep ); | > > > > > > > > > > > > > > > > > > > | > > > > > > | | | | | | | > | | 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 | { rc = sqlite3VdbeExec(p); } if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } #ifndef SQLITE_OMIT_TRACE /* Invoke the profile callback if there is one */ if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){ double rNow; u64 elapseTime; sqlite3OsCurrentTime(&rNow); elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime; assert( p->nOp>0 ); assert( p->aOp[p->nOp-1].opcode==OP_Noop ); assert( p->aOp[p->nOp-1].p3!=0 ); assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC ); db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime); } #endif sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); return rc; } /* ** Extract the user data from a sqlite3_context structure and return a ** pointer to it. */ void *sqlite3_user_data(sqlite3_context *p){ assert( p && p->pFunc ); return p->pFunc->pUserData; } /* ** Allocate or return the aggregate context for a user function. A new ** context is allocated on the first call. Subsequent calls return the ** same context that was returned on prior calls. */ void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){ Mem *pMem = p->pMem; assert( p && p->pFunc && p->pFunc->xStep ); if( (pMem->flags & MEM_Agg)==0 ){ if( nByte==0 ){ assert( pMem->flags==MEM_Null ); pMem->z = 0; }else{ pMem->flags = MEM_Agg; pMem->xDel = sqlite3FreeX; *(FuncDef**)&pMem->i = p->pFunc; if( nByte<=NBFS ){ pMem->z = pMem->zShort; memset(pMem->z, 0, nByte); }else{ pMem->z = sqliteMalloc( nByte ); } } } return (void*)pMem->z; } /* ** Return the auxilary data pointer, if any, for the iArg'th argument to ** the user-function defined by pCtx. */ void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
︙ | ︙ | |||
270 271 272 273 274 275 276 | struct AuxData *pAuxData; VdbeFunc *pVdbeFunc; if( iArg<0 ) return; pVdbeFunc = pCtx->pVdbeFunc; if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){ int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg; | | > | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | struct AuxData *pAuxData; VdbeFunc *pVdbeFunc; if( iArg<0 ) return; pVdbeFunc = pCtx->pVdbeFunc; if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){ int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg; pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc); if( !pVdbeFunc ) return; pCtx->pVdbeFunc = pVdbeFunc; memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0, sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux)); pVdbeFunc->nAux = iArg+1; pVdbeFunc->pFunc = pCtx->pFunc; } pAuxData = &pVdbeFunc->apAux[iArg]; |
︙ | ︙ | |||
296 297 298 299 300 301 302 | ** ** 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 ); | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | ** ** 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; } /* ** Return the number of columns in the result set for the statement pStmt. */ int sqlite3_column_count(sqlite3_stmt *pStmt){ Vdbe *pVm = (Vdbe *)pStmt; |
︙ | ︙ |
Changes to SQLite.Interop/src/vdbeaux.c.
︙ | ︙ | |||
58 59 60 61 62 63 64 | /* ** Resize the Vdbe.aOp array so that it contains at least N ** elements. If the Vdbe is in VDBE_MAGIC_RUN state, then ** the Vdbe.aOp array will be sized to contain exactly N ** elements. */ static void resizeOpArray(Vdbe *p, int N){ | | < | | < > > > | | | | > | 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 | /* ** Resize the Vdbe.aOp array so that it contains at least N ** elements. If the Vdbe is in VDBE_MAGIC_RUN state, then ** the Vdbe.aOp array will be sized to contain exactly N ** elements. */ static void resizeOpArray(Vdbe *p, int N){ int runMode = p->magic==VDBE_MAGIC_RUN; if( runMode || p->nOpAlloc<N ){ VdbeOp *pNew; int nNew = N + 100*(!runMode); int oldSize = p->nOpAlloc; pNew = sqliteRealloc(p->aOp, nNew*sizeof(Op)); if( pNew ){ p->nOpAlloc = nNew; p->aOp = pNew; if( nNew>oldSize ){ memset(&p->aOp[oldSize], 0, (nNew-oldSize)*sizeof(Op)); } } } } /* ** Add a new instruction to the list of instructions current in the ** VDBE. Return the address of the new instruction. |
︙ | ︙ | |||
96 97 98 99 100 101 102 | int i; VdbeOp *pOp; i = p->nOp; p->nOp++; assert( p->magic==VDBE_MAGIC_INIT ); resizeOpArray(p, i+1); | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | int i; VdbeOp *pOp; i = p->nOp; p->nOp++; assert( p->magic==VDBE_MAGIC_INIT ); resizeOpArray(p, i+1); if( sqlite3_malloc_failed ){ return 0; } pOp = &p->aOp[i]; pOp->opcode = op; pOp->p1 = p1; pOp->p2 = p2; pOp->p3 = 0; |
︙ | ︙ | |||
141 142 143 144 145 146 147 | */ int sqlite3VdbeMakeLabel(Vdbe *p){ int i; i = p->nLabel++; assert( p->magic==VDBE_MAGIC_INIT ); if( i>=p->nLabelAlloc ){ p->nLabelAlloc = p->nLabelAlloc*2 + 10; | > | | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | */ int sqlite3VdbeMakeLabel(Vdbe *p){ int i; i = p->nLabel++; assert( p->magic==VDBE_MAGIC_INIT ); if( i>=p->nLabelAlloc ){ p->nLabelAlloc = p->nLabelAlloc*2 + 10; sqlite3ReallocOrFree((void**)&p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0])); } if( p->aLabel ){ p->aLabel[i] = -1; } return -1-i; } |
︙ | ︙ | |||
211 212 213 214 215 216 217 | /* ** Loop through the program looking for P2 values that are negative. ** Each such value is a label. Resolve the label by setting the P2 ** value to its correct non-zero value. ** ** This routine is called once after all opcodes have been inserted. ** | | | | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | /* ** Loop through the program looking for P2 values that are negative. ** Each such value is a label. Resolve the label by setting the P2 ** value to its correct non-zero value. ** ** This routine is called once after all opcodes have been inserted. ** ** Variable *pMaxFuncArgs is set to the maximum value of any P2 argument ** to an OP_Function or OP_AggStep opcode. This is used by ** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array. ** ** The integer *pMaxStack is set to the maximum number of vdbe stack ** entries that static analysis reveals this program might need. ** ** This routine also does the following optimization: It scans for ** Halt instructions where P1==SQLITE_CONSTRAINT or P2==OE_Abort or for |
︙ | ︙ | |||
235 236 237 238 239 240 241 | Op *pOp; int *aLabel = p->aLabel; int doesStatementRollback = 0; int hasStatementBegin = 0; for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ u8 opcode = pOp->opcode; | < < < | < < | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | Op *pOp; int *aLabel = p->aLabel; int doesStatementRollback = 0; int hasStatementBegin = 0; for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ u8 opcode = pOp->opcode; if( opcode==OP_Function || opcode==OP_AggStep ){ if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; }else if( opcode==OP_Halt ){ if( pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort ){ doesStatementRollback = 1; } }else if( opcode==OP_IdxInsert ){ if( pOp->p2 ){ |
︙ | ︙ | |||
298 299 300 301 302 303 304 | ** Add a whole list of operations to the operation stack. Return the ** address of the first operation added. */ int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ int addr; assert( p->magic==VDBE_MAGIC_INIT ); resizeOpArray(p, p->nOp + nOp); | | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | ** Add a whole list of operations to the operation stack. Return the ** address of the first operation added. */ int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ int addr; assert( p->magic==VDBE_MAGIC_INIT ); resizeOpArray(p, p->nOp + nOp); if( sqlite3_malloc_failed ){ return 0; } addr = p->nOp; if( nOp>0 ){ int i; VdbeOpList const *pIn = aOp; for(i=0; i<nOp; i++, pIn++){ |
︙ | ︙ | |||
348 349 350 351 352 353 354 355 356 357 358 359 360 361 | void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){ assert( val>=0 ); assert( p->magic==VDBE_MAGIC_INIT ); if( p && addr>=0 && p->nOp>addr && p->aOp ){ p->aOp[addr].p2 = val; } } /* ** Change the value of the P3 operand for a specific instruction. ** This routine is useful when a large program is loaded from a ** static array using sqlite3VdbeAddOpList but we want to make a ** few minor changes to the program. ** | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){ assert( val>=0 ); assert( p->magic==VDBE_MAGIC_INIT ); if( p && addr>=0 && p->nOp>addr && p->aOp ){ p->aOp[addr].p2 = val; } } /* ** Change teh P2 operand of instruction addr so that it points to ** the address of the next instruction to be coded. */ void sqlite3VdbeJumpHere(Vdbe *p, int addr){ sqlite3VdbeChangeP2(p, addr, p->nOp); } /* ** Delete a P3 value if necessary. */ static void freeP3(int p3type, void *p3){ if( p3 ){ switch( p3type ){ case P3_DYNAMIC: case P3_KEYINFO: case P3_KEYINFO_HANDOFF: { sqliteFree(p3); break; } case P3_VDBEFUNC: { VdbeFunc *pVdbeFunc = (VdbeFunc *)p3; sqlite3VdbeDeleteAuxData(pVdbeFunc, 0); sqliteFree(pVdbeFunc); break; } case P3_MEM: { sqlite3ValueFree((sqlite3_value*)p3); break; } } } } /* ** Change the value of the P3 operand for a specific instruction. ** This routine is useful when a large program is loaded from a ** static array using sqlite3VdbeAddOpList but we want to make a ** few minor changes to the program. ** |
︙ | ︙ | |||
378 379 380 381 382 383 384 | ** ** If addr<0 then change P3 on the most recently inserted instruction. */ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ Op *pOp; assert( p->magic==VDBE_MAGIC_INIT ); if( p==0 || p->aOp==0 ){ | < | < < < < < | | < > > > > > | 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 | ** ** If addr<0 then change P3 on the most recently inserted instruction. */ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){ Op *pOp; assert( p->magic==VDBE_MAGIC_INIT ); if( p==0 || p->aOp==0 ){ freeP3(n, (void*)*(char**)&zP3); return; } if( addr<0 || addr>=p->nOp ){ addr = p->nOp - 1; if( addr<0 ) return; } pOp = &p->aOp[addr]; freeP3(pOp->p3type, pOp->p3); pOp->p3 = 0; if( zP3==0 ){ pOp->p3 = 0; pOp->p3type = P3_NOTUSED; }else if( n==P3_KEYINFO ){ KeyInfo *pKeyInfo; int nField, nByte; /* KeyInfo structures that include an KeyInfo.aSortOrder are always ** sent in using P3_KEYINFO_HANDOFF. The KeyInfo.aSortOrder array ** is not duplicated when P3_KEYINFO is used. */ /* assert( pKeyInfo->aSortOrder==0 ); */ nField = ((KeyInfo*)zP3)->nField; nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]); pKeyInfo = sqliteMallocRaw( nByte ); pOp->p3 = (char*)pKeyInfo; if( pKeyInfo ){ memcpy(pKeyInfo, zP3, nByte); pOp->p3type = P3_KEYINFO; |
︙ | ︙ | |||
573 574 575 576 577 578 579 | ** sqlite3_column_text16(), causing a translation to UTF-16 encoding. */ if( p->pTos==&p->aStack[4] ){ releaseMemArray(p->aStack, 5); } p->resOnStack = 0; | | | > | 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | ** sqlite3_column_text16(), causing a translation to UTF-16 encoding. */ if( p->pTos==&p->aStack[4] ){ releaseMemArray(p->aStack, 5); } p->resOnStack = 0; do{ i = p->pc++; }while( i<p->nOp && p->explain==2 && p->aOp[i].opcode!=OP_Explain ); if( i>=p->nOp ){ p->rc = SQLITE_OK; rc = SQLITE_DONE; }else if( db->flags & SQLITE_Interrupt ){ db->flags &= ~SQLITE_Interrupt; p->rc = SQLITE_INTERRUPT; rc = SQLITE_ERROR; |
︙ | ︙ | |||
613 614 615 616 617 618 619 | pMem++; pMem->flags = MEM_Short|MEM_Str|MEM_Term; /* P3 */ pMem->z = displayP3(pOp, pMem->zShort, sizeof(pMem->zShort)); pMem->type = SQLITE_TEXT; pMem->enc = SQLITE_UTF8; | | | 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | pMem++; pMem->flags = MEM_Short|MEM_Str|MEM_Term; /* P3 */ pMem->z = displayP3(pOp, pMem->zShort, sizeof(pMem->zShort)); pMem->type = SQLITE_TEXT; pMem->enc = SQLITE_UTF8; p->nResColumn = 5 - 2*(p->explain-1); p->pTos = pMem; p->rc = SQLITE_OK; p->resOnStack = 1; rc = SQLITE_ROW; } return rc; } |
︙ | ︙ | |||
654 655 656 657 658 659 660 | ** VDBE_MAGIC_RUN. */ void sqlite3VdbeMakeReady( Vdbe *p, /* The VDBE */ int nVar, /* Number of '?' see in the SQL statement */ int nMem, /* Number of memory cells to allocate */ int nCursor, /* Number of cursors to allocate */ | < | 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | ** VDBE_MAGIC_RUN. */ void sqlite3VdbeMakeReady( Vdbe *p, /* The VDBE */ int nVar, /* Number of '?' see in the SQL statement */ int nMem, /* Number of memory cells to allocate */ int nCursor, /* Number of cursors to allocate */ int isExplain /* True if the EXPLAIN keywords is present */ ){ int n; assert( p!=0 ); assert( p->magic==VDBE_MAGIC_INIT ); |
︙ | ︙ | |||
697 698 699 700 701 702 703 | p->aStack = sqliteMalloc( nStack*sizeof(p->aStack[0]) /* aStack */ + nArg*sizeof(Mem*) /* apArg */ + nVar*sizeof(Mem) /* aVar */ + nVar*sizeof(char*) /* azVar */ + nMem*sizeof(Mem) /* aMem */ + nCursor*sizeof(Cursor*) /* apCsr */ | < < < < < < | 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 | p->aStack = sqliteMalloc( nStack*sizeof(p->aStack[0]) /* aStack */ + nArg*sizeof(Mem*) /* apArg */ + nVar*sizeof(Mem) /* aVar */ + nVar*sizeof(char*) /* azVar */ + nMem*sizeof(Mem) /* aMem */ + nCursor*sizeof(Cursor*) /* apCsr */ ); if( !sqlite3_malloc_failed ){ p->aMem = &p->aStack[nStack]; p->nMem = nMem; p->aVar = &p->aMem[nMem]; p->nVar = nVar; p->okVar = 0; p->apArg = (Mem**)&p->aVar[nVar]; p->azVar = (char**)&p->apArg[nArg]; p->apCsr = (Cursor**)&p->azVar[nVar]; p->nCursor = nCursor; for(n=0; n<nVar; n++){ p->aVar[n].flags = MEM_Null; } } } for(n=0; n<p->nMem; n++){ p->aMem[n].flags = MEM_Null; } #ifdef SQLITE_DEBUG if( (p->db->flags & SQLITE_VdbeListing)!=0 || sqlite3OsFileExists("vdbe_explain") |
︙ | ︙ | |||
759 760 761 762 763 764 765 | p->aOp[i].cnt = 0; p->aOp[i].cycles = 0; } } #endif } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | p->aOp[i].cnt = 0; p->aOp[i].cycles = 0; } } #endif } /* ** Close a cursor and release all the resources that cursor happens ** to hold. */ void sqlite3VdbeFreeCursor(Cursor *pCx){ if( pCx==0 ){ return; |
︙ | ︙ | |||
961 962 963 964 965 966 967 | sqlite3VdbeFifoClear(&p->sFifo); if( p->contextStack ){ for(i=0; i<p->contextStackTop; i++){ sqlite3VdbeFifoClear(&p->contextStack[i].sFifo); } sqliteFree(p->contextStack); } | < < < < | 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | sqlite3VdbeFifoClear(&p->sFifo); if( p->contextStack ){ for(i=0; i<p->contextStackTop; i++){ sqlite3VdbeFifoClear(&p->contextStack[i].sFifo); } sqliteFree(p->contextStack); } p->contextStack = 0; p->contextStackDepth = 0; p->contextStackTop = 0; sqliteFree(p->zErrMsg); p->zErrMsg = 0; } |
︙ | ︙ | |||
1141 1142 1143 1144 1145 1146 1147 | /* Sync the master journal file. Before doing this, open the directory ** the master journal file is store in so that it gets synced too. */ zMainFile = sqlite3BtreeGetDirname(db->aDb[0].pBt); rc = sqlite3OsOpenDirectory(zMainFile, &master); | | > | 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 | /* Sync the master journal file. Before doing this, open the directory ** the master journal file is store in so that it gets synced too. */ zMainFile = sqlite3BtreeGetDirname(db->aDb[0].pBt); rc = sqlite3OsOpenDirectory(zMainFile, &master); if( rc!=SQLITE_OK || (needSync && (rc=sqlite3OsSync(&master,0))!=SQLITE_OK) ){ sqlite3OsClose(&master); sqlite3OsDelete(zMaster); sqliteFree(zMaster); return rc; } /* Sync all the db files involved in the transaction. The same call |
︙ | ︙ | |||
1485 1486 1487 1488 1489 1490 1491 | } if( p->pNext ){ p->pNext->pPrev = p->pPrev; } if( p->aOp ){ for(i=0; i<p->nOp; i++){ Op *pOp = &p->aOp[i]; | < < < < < < < < | < < | 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 | } if( p->pNext ){ p->pNext->pPrev = p->pPrev; } if( p->aOp ){ for(i=0; i<p->nOp; i++){ Op *pOp = &p->aOp[i]; 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); |
︙ | ︙ | |||
1710 1711 1712 1713 1714 1715 1716 | x = (x<<32) | y; pMem->i = *(i64*)&x; pMem->flags = MEM_Int; return 6; } case 6: /* 8-byte signed integer */ case 7: { /* IEEE floating point */ | > > > > > > > > > > | | | 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 | x = (x<<32) | y; pMem->i = *(i64*)&x; pMem->flags = MEM_Int; return 6; } case 6: /* 8-byte signed integer */ case 7: { /* IEEE floating point */ u64 x; u32 y; #ifndef NDEBUG /* Verify that integers and floating point values use the same ** byte order. The byte order differs on some (broken) architectures. */ static const u64 t1 = ((u64)0x3ff00000)<<32; assert( 1.0==*(double*)&t1 ); #endif x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3]; y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7]; x = (x<<32) | y; if( serial_type==6 ){ pMem->i = *(i64*)&x; pMem->flags = MEM_Int; }else{ pMem->r = *(double*)&x; pMem->flags = MEM_Real; |
︙ | ︙ | |||
1849 1850 1851 1852 1853 1854 1855 | u32 szHdr; /* Size of the header */ u32 typeRowid; /* Serial type of the rowid */ u32 lenRowid; /* Size of the rowid */ Mem m, v; sqlite3BtreeKeySize(pCur, &nCellKey); if( nCellKey<=0 ){ | | | 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 | u32 szHdr; /* Size of the header */ u32 typeRowid; /* Serial type of the rowid */ u32 lenRowid; /* Size of the rowid */ Mem m, v; sqlite3BtreeKeySize(pCur, &nCellKey); if( nCellKey<=0 ){ return SQLITE_CORRUPT_BKPT; } rc = sqlite3VdbeMemFromBtree(pCur, 0, nCellKey, 1, &m); if( rc ){ return rc; } sqlite3GetVarint32(m.z, &szHdr); sqlite3GetVarint32(&m.z[szHdr-1], &typeRowid); |
︙ | ︙ |
Changes to SQLite.Interop/src/vdbemem.c.
︙ | ︙ | |||
182 183 184 185 186 187 188 189 190 191 192 193 194 195 | pMem->n = strlen(z); pMem->z = z; pMem->enc = SQLITE_UTF8; pMem->flags |= MEM_Str | MEM_Short | MEM_Term; sqlite3VdbeChangeEncoding(pMem, enc); return rc; } /* ** Release any memory held by the Mem. This may leave the Mem in an ** inconsistent state, for example with (Mem.z==0) and ** (Mem.type==SQLITE_TEXT). */ void sqlite3VdbeMemRelease(Mem *p){ | > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > | > | 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 | pMem->n = strlen(z); pMem->z = z; pMem->enc = SQLITE_UTF8; pMem->flags |= MEM_Str | MEM_Short | MEM_Term; sqlite3VdbeChangeEncoding(pMem, enc); return rc; } /* ** Memory cell pMem contains the context of an aggregate function. ** This routine calls the finalize method for that function. The ** result of the aggregate is stored back into pMem. */ void sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){ if( pFunc && pFunc->xFinalize ){ sqlite3_context ctx; assert( (pMem->flags & MEM_Null)!=0 || pFunc==*(FuncDef**)&pMem->i ); ctx.s.flags = MEM_Null; ctx.s.z = pMem->zShort; ctx.pMem = pMem; ctx.pFunc = pFunc; pFunc->xFinalize(&ctx); if( pMem->z && pMem->z!=pMem->zShort ){ sqliteFree( pMem->z ); } *pMem = ctx.s; if( pMem->flags & MEM_Short ){ pMem->z = pMem->zShort; } } } /* ** Release any memory held by the Mem. This may leave the Mem in an ** inconsistent state, for example with (Mem.z==0) and ** (Mem.type==SQLITE_TEXT). */ void sqlite3VdbeMemRelease(Mem *p){ if( p->flags & (MEM_Dyn|MEM_Agg) ){ if( p->xDel ){ if( p->flags & MEM_Agg ){ sqlite3VdbeMemFinalize(p, *(FuncDef**)&p->i); assert( (p->flags & MEM_Agg)==0 ); sqlite3VdbeMemRelease(p); }else{ p->xDel((void *)p->z); } }else{ sqliteFree(p->z); } p->z = 0; p->xDel = 0; } } |
︙ | ︙ | |||
283 284 285 286 287 288 289 290 291 292 293 294 295 296 | /* ** Delete any previous value and set the value stored in *pMem to NULL. */ void sqlite3VdbeMemSetNull(Mem *pMem){ sqlite3VdbeMemRelease(pMem); pMem->flags = MEM_Null; pMem->type = SQLITE_NULL; } /* ** Delete any previous value and set the value stored in *pMem to val, ** manifest type INTEGER. */ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){ | > | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | /* ** Delete any previous value and set the value stored in *pMem to NULL. */ void sqlite3VdbeMemSetNull(Mem *pMem){ sqlite3VdbeMemRelease(pMem); pMem->flags = MEM_Null; pMem->type = SQLITE_NULL; pMem->n = 0; } /* ** Delete any previous value and set the value stored in *pMem to val, ** manifest type INTEGER. */ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){ |
︙ | ︙ | |||
695 696 697 698 699 700 701 | } return (const void *)(pVal->z); } /* ** Create a new sqlite3_value object. */ | | | 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | } return (const void *)(pVal->z); } /* ** Create a new sqlite3_value object. */ sqlite3_value* sqlite3ValueNew(void){ Mem *p = sqliteMalloc(sizeof(*p)); if( p ){ p->flags = MEM_Null; p->type = SQLITE_NULL; } return p; } |
︙ | ︙ |
Changes to SQLite.Interop/src/where.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is reponsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is reponsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** ** $Id: where.c,v 1.11 2005/10/05 19:38:29 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** The number of bits in a Bitmask. "BMS" means "BitMask Size". */ #define BMS (sizeof(Bitmask)*8) |
︙ | ︙ | |||
228 229 230 231 232 233 234 | pTerm->pWC = pWC; pTerm->iParent = -1; return idx; } /* ** This routine identifies subexpressions in the WHERE clause where | | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | pTerm->pWC = pWC; pTerm->iParent = -1; return idx; } /* ** This routine identifies subexpressions in the WHERE clause where ** each subexpression is separated by the AND operator or some other ** operator specified in the op parameter. The WhereClause structure ** is filled with pointers to subexpressions. For example: ** ** WHERE a=='hello' AND coalesce(b,11)<10 AND (c+12!=d OR c==22) ** \________/ \_______________/ \________________/ ** slot[0] slot[1] slot[2] ** |
︙ | ︙ | |||
277 278 279 280 281 282 283 | } /* ** Create a new mask for cursor iCursor. ** ** There is one cursor per table in the FROM clause. The number of ** tables in the FROM clause is limited by a test early in the | | | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | } /* ** Create a new mask for cursor iCursor. ** ** There is one cursor per table in the FROM clause. The number of ** tables in the FROM clause is limited by a test early in the ** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[] ** array will never overflow. */ static void createMask(ExprMaskSet *pMaskSet, int iCursor){ assert( pMaskSet->n < ARRAYSIZE(pMaskSet->ix) ); pMaskSet->ix[pMaskSet->n++] = iCursor; } |
︙ | ︙ | |||
299 300 301 302 303 304 305 | ** the header comment on that routine for additional information. ** The sqlite3ExprResolveNames() routines looks for column names and ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to ** the VDBE cursor number of the table. This routine just has to ** translate the cursor numbers into bitmask values and OR all ** the bitmasks together. */ | | > < < | < < < < < > > > > > > > > > > > > > | 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 | ** the header comment on that routine for additional information. ** The sqlite3ExprResolveNames() routines looks for column names and ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to ** the VDBE cursor number of the table. This routine just has to ** translate the cursor numbers into bitmask values and OR all ** the bitmasks together. */ static Bitmask exprListTableUsage(ExprMaskSet*, ExprList*); static Bitmask exprSelectTableUsage(ExprMaskSet*, Select*); static Bitmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){ Bitmask mask = 0; if( p==0 ) return 0; if( p->op==TK_COLUMN ){ mask = getMask(pMaskSet, p->iTable); return mask; } mask = exprTableUsage(pMaskSet, p->pRight); mask |= exprTableUsage(pMaskSet, p->pLeft); mask |= exprListTableUsage(pMaskSet, p->pList); mask |= exprSelectTableUsage(pMaskSet, p->pSelect); return mask; } static Bitmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){ int i; Bitmask mask = 0; if( pList ){ for(i=0; i<pList->nExpr; i++){ mask |= exprTableUsage(pMaskSet, pList->a[i].pExpr); } } return mask; } static Bitmask exprSelectTableUsage(ExprMaskSet *pMaskSet, Select *pS){ Bitmask mask; if( pS==0 ){ mask = 0; }else{ mask = exprListTableUsage(pMaskSet, pS->pEList); mask |= exprListTableUsage(pMaskSet, pS->pGroupBy); mask |= exprListTableUsage(pMaskSet, pS->pOrderBy); mask |= exprTableUsage(pMaskSet, pS->pWhere); mask |= exprTableUsage(pMaskSet, pS->pHaving); } return mask; } /* ** Return TRUE if the given operator is one of the operators that is ** allowed for an indexable WHERE clause term. The allowed operators are ** "=", "<", ">", "<=", ">=", and "IN". */ |
︙ | ︙ | |||
475 476 477 478 479 480 481 482 | int *pnPattern, /* Number of non-wildcard prefix characters */ int *pisComplete /* True if the only wildcard is % in the last character */ ){ const char *z; Expr *pRight, *pLeft; ExprList *pList; int c, cnt; char wc[3]; | > > > | > > > > > > > > | 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 | int *pnPattern, /* Number of non-wildcard prefix characters */ int *pisComplete /* True if the only wildcard is % in the last character */ ){ const char *z; Expr *pRight, *pLeft; ExprList *pList; int c, cnt; int noCase; char wc[3]; CollSeq *pColl; if( !sqlite3IsLikeFunction(db, pExpr, &noCase, wc) ){ return 0; } pList = pExpr->pList; pRight = pList->a[0].pExpr; if( pRight->op!=TK_STRING ){ return 0; } pLeft = pList->a[1].pExpr; if( pLeft->op!=TK_COLUMN ){ return 0; } pColl = pLeft->pColl; if( pColl==0 ){ pColl = db->pDfltColl; } if( (pColl->type!=SQLITE_COLL_BINARY || noCase) && (pColl->type!=SQLITE_COLL_NOCASE || !noCase) ){ return 0; } sqlite3DequoteExpr(pRight); z = pRight->token.z; for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){} if( cnt==0 || 255==(u8)z[cnt] ){ return 0; } |
︙ | ︙ | |||
510 511 512 513 514 515 516 | ** subexpression and populate all the other fields of the WhereTerm ** structure. ** ** If the expression is of the form "<expr> <op> X" it gets commuted ** to the standard form of "X <op> <expr>". If the expression is of ** the form "X <op> Y" where both X and Y are columns, then the original ** expression is unchanged and a new virtual expression of the form | | < > > > > > | > > > > > | < | 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 | ** subexpression and populate all the other fields of the WhereTerm ** structure. ** ** If the expression is of the form "<expr> <op> X" it gets commuted ** to the standard form of "X <op> <expr>". If the expression is of ** the form "X <op> Y" where both X and Y are columns, then the original ** expression is unchanged and a new virtual expression of the form ** "Y <op> X" is added to the WHERE clause and analyzed separately. */ static void exprAnalyze( SrcList *pSrc, /* the FROM clause */ ExprMaskSet *pMaskSet, /* table masks */ WhereClause *pWC, /* the WHERE clause */ int idxTerm /* Index of the term to be analyzed */ ){ WhereTerm *pTerm = &pWC->a[idxTerm]; Expr *pExpr = pTerm->pExpr; Bitmask prereqLeft; Bitmask prereqAll; int nPattern; int isComplete; if( sqlite3_malloc_failed ) return; prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); if( pExpr->op==TK_IN ){ assert( pExpr->pRight==0 ); pTerm->prereqRight = exprListTableUsage(pMaskSet, pExpr->pList) | exprSelectTableUsage(pMaskSet, pExpr->pSelect); }else{ pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight); } prereqAll = exprTableUsage(pMaskSet, pExpr); if( ExprHasProperty(pExpr, EP_FromJoin) ){ prereqAll |= getMask(pMaskSet, pExpr->iRightJoinTable); } pTerm->prereqAll = prereqAll; pTerm->leftCursor = -1; pTerm->iParent = -1; pTerm->operator = 0; if( allowedOp(pExpr->op) && (pTerm->prereqRight & prereqLeft)==0 ){ Expr *pLeft = pExpr->pLeft; Expr *pRight = pExpr->pRight; if( pLeft->op==TK_COLUMN ){ pTerm->leftCursor = pLeft->iTable; pTerm->leftColumn = pLeft->iColumn; pTerm->operator = operatorMask(pExpr->op); |
︙ | ︙ | |||
595 596 597 598 599 600 601 | } pTerm->nChild = 2; } #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ #ifndef SQLITE_OMIT_OR_OPTIMIZATION /* Attempt to convert OR-connected terms into an IN operator so that | | > > > > > > | 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | } pTerm->nChild = 2; } #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ #ifndef SQLITE_OMIT_OR_OPTIMIZATION /* Attempt to convert OR-connected terms into an IN operator so that ** they can make use of indices. Example: ** ** x = expr1 OR expr2 = x OR x = expr3 ** ** is converted into ** ** x IN (expr1,expr2,expr3) */ else if( pExpr->op==TK_OR ){ int ok; int i, j; int iColumn, iCursor; WhereClause sOr; WhereTerm *pOrTerm; |
︙ | ︙ | |||
643 644 645 646 647 648 649 | } pDup = sqlite3Expr(TK_COLUMN, 0, 0, 0); if( pDup ){ pDup->iTable = iCursor; pDup->iColumn = iColumn; } pNew = sqlite3Expr(TK_IN, pDup, 0, 0); | > | > > > | 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 | } pDup = sqlite3Expr(TK_COLUMN, 0, 0, 0); if( pDup ){ pDup->iTable = iCursor; pDup->iColumn = iColumn; } pNew = sqlite3Expr(TK_IN, pDup, 0, 0); if( pNew ){ pNew->pList = pList; }else{ sqlite3ExprListDelete(pList); } pTerm->pExpr = pNew; pTerm->flags |= TERM_DYNAMIC; exprAnalyze(pSrc, pMaskSet, pWC, idxTerm); pTerm = &pWC->a[idxTerm]; } or_not_possible: whereClauseClear(&sOr); |
︙ | ︙ | |||
721 722 723 724 725 726 727 | Index *pIdx, /* The index we are testing */ Table *pTab, /* The table to be sorted */ int base, /* Cursor number for pTab */ ExprList *pOrderBy, /* The ORDER BY clause */ int nEqCol, /* Number of index columns with == constraints */ int *pbRev /* Set to 1 if ORDER BY is DESC */ ){ | | | | | | 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | Index *pIdx, /* The index we are testing */ Table *pTab, /* The table to be sorted */ int base, /* Cursor number for pTab */ ExprList *pOrderBy, /* The ORDER BY clause */ int nEqCol, /* Number of index columns with == constraints */ int *pbRev /* Set to 1 if ORDER BY is DESC */ ){ int i, j; /* Loop counters */ int sortOrder = SQLITE_SO_ASC; /* Which direction we are sorting */ int nTerm; /* Number of ORDER BY terms */ struct ExprList_item *pTerm; /* A term of the ORDER BY clause */ sqlite3 *db = pParse->db; assert( pOrderBy!=0 ); nTerm = pOrderBy->nExpr; assert( nTerm>0 ); /* Match terms of the ORDER BY clause against columns of |
︙ | ︙ | |||
798 799 800 801 802 803 804 | int *pbRev /* Set to 1 if ORDER BY is DESC */ ){ Expr *p; assert( pOrderBy!=0 ); assert( pOrderBy->nExpr>0 ); p = pOrderBy->a[0].pExpr; | | > | | 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | int *pbRev /* Set to 1 if ORDER BY is DESC */ ){ Expr *p; assert( pOrderBy!=0 ); assert( pOrderBy->nExpr>0 ); p = pOrderBy->a[0].pExpr; if( pOrderBy->nExpr==1 && p->op==TK_COLUMN && p->iTable==base && p->iColumn==-1 ){ *pbRev = pOrderBy->a[0].sortOrder; return 1; } return 0; } /* ** Prepare a crude estimate of the logarithm of the input value. ** The results need not be exact. This is only used for estimating ** the total cost of performing operatings with O(logN) or O(NlogN) ** complexity. Because N is just a guess, it is no great tragedy if ** logN is a little off. */ static double estLog(double N){ double logN = 1.0; |
︙ | ︙ | |||
1065 1066 1067 1068 1069 1070 1071 | ** (3) SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok' ** ** The t2.z='ok' is disabled in the in (2) because it originates ** in the ON clause. The term is disabled in (3) because it is not part ** of a LEFT OUTER JOIN. In (1), the term is not disabled. ** ** Disabling a term causes that term to not be tested in the inner loop | | > | | | | | 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | ** (3) SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok' ** ** The t2.z='ok' is disabled in the in (2) because it originates ** in the ON clause. The term is disabled in (3) because it is not part ** of a LEFT OUTER JOIN. In (1), the term is not disabled. ** ** Disabling a term causes that term to not be tested in the inner loop ** of the join. Disabling is an optimization. When terms are satisfied ** by indices, we disable them to prevent redundant tests in the inner ** loop. We would get the correct results if nothing were ever disabled, ** but joins might run a little slower. The trick is to disable as much ** as we can without disabling too much. If we disabled in (1), we'd get ** the wrong answer. See ticket #813. */ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){ if( pTerm && (pTerm->flags & TERM_CODED)==0 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin)) ){ pTerm->flags |= TERM_CODED; |
︙ | ︙ | |||
1138 1139 1140 1141 1142 1143 1144 | Vdbe *v = pParse->pVdbe; sqlite3CodeSubselect(pParse, pX); iTab = pX->iTable; sqlite3VdbeAddOp(v, OP_Rewind, iTab, brk); VdbeComment((v, "# %.*s", pX->span.n, pX->span.z)); pLevel->nIn++; | | > | 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 | Vdbe *v = pParse->pVdbe; sqlite3CodeSubselect(pParse, pX); iTab = pX->iTable; sqlite3VdbeAddOp(v, OP_Rewind, iTab, brk); VdbeComment((v, "# %.*s", pX->span.n, pX->span.z)); pLevel->nIn++; sqlite3ReallocOrFree((void**)&pLevel->aInLoop, sizeof(pLevel->aInLoop[0])*3*pLevel->nIn); aIn = pLevel->aInLoop; if( aIn ){ aIn += pLevel->nIn*3 - 3; aIn[0] = OP_Next; aIn[1] = iTab; aIn[2] = sqlite3VdbeAddOp(v, OP_Column, iTab, 0); }else{ pLevel->nIn = 0; |
︙ | ︙ | |||
1225 1226 1227 1228 1229 1230 1231 | if( termsInMem ){ for(j=0; j<nEq; j++){ sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem+j+1, 0); } } } | | | 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | if( termsInMem ){ for(j=0; j<nEq; j++){ sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem+j+1, 0); } } } #if defined(SQLITE_TEST) /* ** The following variable holds a text description of query plan generated ** by the most recent call to sqlite3WhereBegin(). Each call to WhereBegin ** overwrites the previous. This information is used for testing and ** analysis only. */ char sqlite3_query_plan[BMS*2*40]; /* Text of the join */ |
︙ | ︙ | |||
1383 1384 1385 1386 1387 1388 1389 | sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, 1); pWhere = 0; } /* Analyze all of the subexpressions. Note that exprAnalyze() might ** add new virtual terms onto the end of the WHERE clause. We do not ** want to analyze these virtual terms, so start analyzing at the end | | | 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 | sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, 1); pWhere = 0; } /* Analyze all of the subexpressions. Note that exprAnalyze() might ** add new virtual terms onto the end of the WHERE clause. We do not ** want to analyze these virtual terms, so start analyzing at the end ** and work forward so that the added virtual terms are never processed. */ for(i=0; i<pTabList->nSrc; i++){ createMask(&maskSet, pTabList->a[i].iCursor); } exprAnalyzeAll(pTabList, &maskSet, &wc); if( sqlite3_malloc_failed ){ goto whereBeginNoMem; |
︙ | ︙ | |||
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 | ** This loop also figures out the nesting order of tables in the FROM ** clause. */ notReady = ~(Bitmask)0; pTabItem = pTabList->a; pLevel = pWInfo->a; andFlags = ~0; for(i=iFrom=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ Index *pIdx; /* Index for FROM table at pTabItem */ int flags; /* Flags asssociated with pIdx */ int nEq; /* Number of == or IN constraints */ double cost; /* The cost for pIdx */ int j; /* For looping over FROM tables */ Index *pBest = 0; /* The best index seen so far */ int bestFlags = 0; /* Flags associated with pBest */ int bestNEq = 0; /* nEq associated with pBest */ double lowestCost = 1.0e99; /* Cost of the pBest */ int bestJ; /* The value of j */ Bitmask m; /* Bitmask value for j or bestJ */ for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){ m = getMask(&maskSet, pTabItem->iCursor); if( (m & notReady)==0 ){ if( j==iFrom ) iFrom++; continue; } cost = bestIndex(pParse, &wc, pTabItem, notReady, | > | | | > > > > > > > > > > > > > > > > > | 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 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 | ** This loop also figures out the nesting order of tables in the FROM ** clause. */ notReady = ~(Bitmask)0; pTabItem = pTabList->a; pLevel = pWInfo->a; andFlags = ~0; TRACE(("*** Optimizer Start ***\n")); for(i=iFrom=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ Index *pIdx; /* Index for FROM table at pTabItem */ int flags; /* Flags asssociated with pIdx */ int nEq; /* Number of == or IN constraints */ double cost; /* The cost for pIdx */ int j; /* For looping over FROM tables */ Index *pBest = 0; /* The best index seen so far */ int bestFlags = 0; /* Flags associated with pBest */ int bestNEq = 0; /* nEq associated with pBest */ double lowestCost = 1.0e99; /* Cost of the pBest */ int bestJ; /* The value of j */ Bitmask m; /* Bitmask value for j or bestJ */ for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){ m = getMask(&maskSet, pTabItem->iCursor); if( (m & notReady)==0 ){ if( j==iFrom ) iFrom++; continue; } cost = bestIndex(pParse, &wc, pTabItem, notReady, (i==0 && ppOrderBy) ? *ppOrderBy : 0, &pIdx, &flags, &nEq); if( cost<lowestCost ){ lowestCost = cost; pBest = pIdx; bestFlags = flags; bestNEq = nEq; bestJ = j; } if( (pTabItem->jointype & (JT_LEFT|JT_CROSS))!=0 || (j>0 && (pTabItem[-1].jointype & (JT_LEFT|JT_CROSS))!=0) ){ break; } } TRACE(("*** Optimizer choose table %d for loop %d\n", bestJ, pLevel-pWInfo->a)); if( (bestFlags & WHERE_ORDERBY)!=0 ){ *ppOrderBy = 0; } andFlags &= bestFlags; pLevel->flags = bestFlags; pLevel->pIdx = pBest; pLevel->nEq = bestNEq; pLevel->aInLoop = 0; pLevel->nIn = 0; if( pBest ){ pLevel->iIdxCur = pParse->nTab++; }else{ pLevel->iIdxCur = -1; } notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor); pLevel->iFrom = bestJ; } TRACE(("*** Optimizer Finished ***\n")); /* If the total query only selects a single row, then the ORDER BY ** clause is irrelevant. */ if( (andFlags & WHERE_UNIQUE)!=0 && ppOrderBy ){ *ppOrderBy = 0; } /* Open all tables in the pTabList and any indices selected for ** searching those tables. */ sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ pLevel = pWInfo->a; for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ Table *pTab; Index *pIx; int iIdxCur = pLevel->iIdxCur; #ifndef SQLITE_OMIT_EXPLAIN if( pParse->explain==2 ){ char *zMsg; struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom]; zMsg = sqlite3MPrintf("TABLE %s", pItem->zName); if( pItem->zAlias ){ zMsg = sqlite3MPrintf("%z AS %s", zMsg, pItem->zAlias); } if( (pIx = pLevel->pIdx)!=0 ){ zMsg = sqlite3MPrintf("%z WITH INDEX %s", zMsg, pIx->zName); } sqlite3VdbeOp3(v, OP_Explain, i, pLevel->iFrom, zMsg, P3_DYNAMIC); } #endif /* SQLITE_OMIT_EXPLAIN */ pTabItem = &pTabList->a[pLevel->iFrom]; pTab = pTabItem->pTab; if( pTab->isTransient || pTab->pSelect ) continue; if( (pLevel->flags & WHERE_IDX_ONLY)==0 ){ sqlite3OpenTableForReading(v, pTabItem->iCursor, pTab); } pLevel->iTabCur = pTabItem->iCursor; |
︙ | ︙ | |||
1536 1537 1538 1539 1540 1541 1542 | /* If this is the right table of a LEFT OUTER JOIN, allocate and ** initialize a memory cell that records if this table matches any ** row of the left table of the join. */ if( pLevel->iFrom>0 && (pTabItem[-1].jointype & JT_LEFT)!=0 ){ if( !pParse->nMem ) pParse->nMem++; pLevel->iLeftJoin = pParse->nMem++; | | < | 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 | /* If this is the right table of a LEFT OUTER JOIN, allocate and ** initialize a memory cell that records if this table matches any ** row of the left table of the join. */ if( pLevel->iFrom>0 && (pTabItem[-1].jointype & JT_LEFT)!=0 ){ if( !pParse->nMem ) pParse->nMem++; pLevel->iLeftJoin = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemInt, 0, pLevel->iLeftJoin); VdbeComment((v, "# init LEFT JOIN no-match flag")); } if( pLevel->flags & WHERE_ROWID_EQ ){ /* Case 1: We can directly reference a single row using an ** equality comparison against the ROWID field. Or ** we reference multiple rows using a "rowid IN (...)" |
︙ | ︙ | |||
1817 1818 1819 1820 1821 1822 1823 | } /* For a LEFT OUTER JOIN, generate code that will record the fact that ** at least one row of the right table has matched the left table. */ if( pLevel->iLeftJoin ){ pLevel->top = sqlite3VdbeCurrentAddr(v); | | < | 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 | } /* For a LEFT OUTER JOIN, generate code that will record the fact that ** at least one row of the right table has matched the left table. */ if( pLevel->iLeftJoin ){ pLevel->top = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp(v, OP_MemInt, 1, pLevel->iLeftJoin); VdbeComment((v, "# record LEFT JOIN hit")); for(pTerm=wc.a, j=0; j<wc.nTerm; j++, pTerm++){ if( pTerm->flags & (TERM_VIRTUAL|TERM_CODED) ) continue; if( (pTerm->prereqAll & notReady)!=0 ) continue; assert( pTerm->pExpr ); sqlite3ExprIfFalse(pParse, pTerm->pExpr, cont, 1); pTerm->flags |= TERM_CODED; |
︙ | ︙ | |||
1920 1921 1922 1923 1924 1925 1926 | for(j=pLevel->nIn, a=&pLevel->aInLoop[j*3-3]; j>0; j--, a-=3){ sqlite3VdbeAddOp(v, a[0], a[1], a[2]); } sqliteFree(pLevel->aInLoop); } if( pLevel->iLeftJoin ){ int addr; | | < > | 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 | for(j=pLevel->nIn, a=&pLevel->aInLoop[j*3-3]; j>0; j--, a-=3){ sqlite3VdbeAddOp(v, a[0], a[1], a[2]); } sqliteFree(pLevel->aInLoop); } if( pLevel->iLeftJoin ){ int addr; addr = sqlite3VdbeAddOp(v, OP_IfMemPos, pLevel->iLeftJoin, 0); sqlite3VdbeAddOp(v, OP_NullRow, pTabList->a[i].iCursor, 0); if( pLevel->iIdxCur>=0 ){ sqlite3VdbeAddOp(v, OP_NullRow, pLevel->iIdxCur, 0); } sqlite3VdbeAddOp(v, OP_Goto, 0, pLevel->top); sqlite3VdbeJumpHere(v, addr); } } /* The "break" point is here, just past the end of the outer loop. ** Set it. */ sqlite3VdbeResolveLabel(v, pWInfo->iBreak); |
︙ | ︙ |