Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | 3.2.3 code merge |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sourceforge |
Files: | files | file ages | folders |
SHA1: |
79fe5ae73a51272c9eb1cbf530999c98 |
User & Date: | rmsimpson 2005-08-22 18:22:12.000 |
Context
2005-08-23
| ||
22:11 | added new schemas IndexColumns, ViewColumns, ForeignKeys check-in: 91fab4183e user: rmsimpson tags: sourceforge | |
2005-08-22
| ||
18:22 | 3.2.3 code merge check-in: 79fe5ae73a user: rmsimpson tags: sourceforge | |
18:20 | 1.0.15 check-in: 36c2575662 user: rmsimpson tags: sourceforge | |
Changes
Changes to SQLite.Interop/src/alter.c.
1 2 3 | #pragma unmanaged extern "C" { | < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #pragma unmanaged extern "C" { /* ** 2005 February 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. ** ************************************************************************* ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. ** ** $Id: alter.c,v 1.7 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
258 259 260 261 262 263 264 265 266 267 268 269 270 271 | char *zName = 0; /* NULL-terminated version of pName */ sqlite3 *db = pParse->db; /* Database connection */ Vdbe *v; #ifndef SQLITE_OMIT_TRIGGER char *zWhere = 0; /* Where clause to locate temp triggers */ #endif assert( pSrc->nSrc==1 ); pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); if( !pTab ) goto exit_rename_table; iDb = pTab->iDb; zDb = db->aDb[iDb].zName; | > | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | char *zName = 0; /* NULL-terminated version of pName */ sqlite3 *db = pParse->db; /* Database connection */ Vdbe *v; #ifndef SQLITE_OMIT_TRIGGER char *zWhere = 0; /* Where clause to locate temp triggers */ #endif if( sqlite3_malloc_failed ) goto exit_rename_table; assert( pSrc->nSrc==1 ); pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); if( !pTab ) goto exit_rename_table; iDb = pTab->iDb; zDb = db->aDb[iDb].zName; |
︙ | ︙ | |||
499 500 501 502 503 504 505 506 507 | void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ Table *pNew; Table *pTab; Vdbe *v; int iDb; int i; int nAlloc; /* Look up the table being altered. */ | > | > > | 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 | void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ Table *pNew; Table *pTab; Vdbe *v; int iDb; int i; int nAlloc; /* Look up the table being altered. */ assert( pParse->pNewTable==0 ); if( sqlite3_malloc_failed ) goto exit_begin_add_column; pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase); if( !pTab ) goto exit_begin_add_column; /* Make sure this is not an attempt to ALTER a view. */ if( pTab->pSelect ){ sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); goto exit_begin_add_column; } assert( pTab->addColOffset>0 ); iDb = pTab->iDb; /* Put a copy of the Table struct in Parse.pNewTable for the ** sqlite3AddColumn() function and friends to modify. */ pNew = (Table *)sqliteMalloc(sizeof(Table)); if( !pNew ) goto exit_begin_add_column; pParse->pNewTable = pNew; pNew->nRef = 1; pNew->nCol = pTab->nCol; assert( pNew->nCol>0 ); nAlloc = (((pNew->nCol-1)/8)*8)+8; assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 ); pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc); pNew->zName = sqliteStrDup(pTab->zName); if( !pNew->aCol || !pNew->zName ){ |
︙ | ︙ | |||
551 552 553 554 555 556 557 | sqlite3ChangeCookie(pParse->db, v, iDb); exit_begin_add_column: sqlite3SrcListDelete(pSrc); return; } #endif /* SQLITE_ALTER_TABLE */ | | < | 554 555 556 557 558 559 560 561 | sqlite3ChangeCookie(pParse->db, v, iDb); exit_begin_add_column: sqlite3SrcListDelete(pSrc); return; } #endif /* SQLITE_ALTER_TABLE */ } |
Added SQLite.Interop/src/analyze.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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 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 | #pragma unmanaged extern "C" { /* ** 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.1 2005/08/22 18:22:12 rmsimpson Exp $ */ #ifndef SQLITE_OMIT_ANALYZE #include "sqliteInt.h" /* ** This routine generates code that opens the sqlite_stat1 table on cursor ** iStatCur. ** ** If the sqlite_stat1 tables does not previously exist, it is created. ** If it does previously exist, all entires associated with table zWhere ** are removed. If zWhere==0 then all entries are removed. */ static void openStatTable( Parse *pParse, /* Parsing context */ int iDb, /* The database we are looking in */ int iStatCur, /* Open the sqlite_stat1 table on this cursor */ const char *zWhere /* Delete entries associated with this table */ ){ sqlite3 *db = pParse->db; Db *pDb; int iRootPage; Table *pStat; Vdbe *v = sqlite3GetVdbe(pParse); pDb = &db->aDb[iDb]; if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){ /* The sqlite_stat1 tables does not exist. Create it. ** Note that a side-effect of the CREATE TABLE statement is to leave ** the rootpage of the new table on the top of the stack. This is ** important because the OpenWrite opcode below will be needing it. */ sqlite3NestedParse(pParse, "CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)", pDb->zName ); iRootPage = 0; /* Cause rootpage to be taken from top of stack */ }else if( zWhere ){ /* The sqlite_stat1 table exists. Delete all entries associated with ** the table zWhere. */ sqlite3NestedParse(pParse, "DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q", pDb->zName, zWhere ); iRootPage = pStat->tnum; }else{ /* The sqlite_stat1 table already exists. Delete all rows. */ iRootPage = pStat->tnum; sqlite3VdbeAddOp(v, OP_Clear, pStat->tnum, iDb); } /* Open the sqlite_stat1 table for writing. */ sqlite3VdbeAddOp(v, OP_Integer, iDb, 0); sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage); sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3); } /* ** Generate code to do an analysis of all indices associated with ** a single table. */ static void analyzeOneTable( Parse *pParse, /* Parser context */ Table *pTab, /* Table whose indices are to be analyzed */ int iStatCur, /* Cursor that writes to the sqlite_stat1 table */ int iMem /* Available memory locations begin here */ ){ Index *pIdx; /* An index to being analyzed */ int iIdxCur; /* Cursor number for index being analyzed */ int nCol; /* Number of columns in the index */ Vdbe *v; /* The virtual machine being built up */ int i; /* Loop counter */ int topOfLoop; /* The top of the loop */ int endOfLoop; /* The end of the loop */ int addr; /* The address of an instruction */ v = sqlite3GetVdbe(pParse); if( pTab==0 || pTab->pIndex==0 || pTab->pIndex->pNext==0 ){ /* Do no analysis for tables with fewer than 2 indices */ return; } #ifndef SQLITE_OMIT_AUTHORIZATION if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0, pParse->db->aDb[pTab->iDb].zName ) ){ return; } #endif iIdxCur = pParse->nTab; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ /* Open a cursor to the index to be analyzed */ sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0); VdbeComment((v, "# %s", pIdx->zName)); sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, (char*)&pIdx->keyInfo, P3_KEYINFO); nCol = pIdx->nColumn; if( iMem+nCol*2>=pParse->nMem ){ pParse->nMem = iMem+nCol*2+1; } sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, nCol+1); /* Memory cells are used as follows: ** ** mem[iMem]: The total number of rows in the table. ** mem[iMem+1]: Number of distinct values in column 1 ** ... ** mem[iMem+nCol]: Number of distinct values in column N ** mem[iMem+nCol+1] Last observed value of column 1 ** ... ** mem[iMem+nCol+nCol]: Last observed value of column N ** ** Cells iMem through iMem+nCol are initialized to 0. The others ** are initialized to NULL. */ sqlite3VdbeAddOp(v, OP_Integer, 0, 0); for(i=0; i<=nCol; i++){ sqlite3VdbeAddOp(v, OP_MemStore, iMem+i, i==nCol); } sqlite3VdbeAddOp(v, OP_Null, 0, 0); for(i=0; i<nCol; i++){ sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, i==nCol-1); } /* Do the analysis. */ endOfLoop = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop); topOfLoop = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp(v, OP_MemIncr, iMem, 0); for(i=0; i<nCol; i++){ sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i); sqlite3VdbeAddOp(v, OP_MemLoad, iMem+nCol+i+1, 0); sqlite3VdbeAddOp(v, OP_Ne, 0x100, 0); } sqlite3VdbeAddOp(v, OP_Goto, 0, endOfLoop); for(i=0; i<nCol; i++){ addr = sqlite3VdbeAddOp(v, OP_MemIncr, iMem+i+1, 0); sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr); sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i); sqlite3VdbeAddOp(v, OP_MemStore, iMem+nCol+i+1, 1); } sqlite3VdbeResolveLabel(v, endOfLoop); sqlite3VdbeAddOp(v, OP_Next, iIdxCur, topOfLoop); sqlite3VdbeAddOp(v, OP_Close, iIdxCur, 0); /* Store the results. ** ** The result is a single row of the sqlite_stmt1 table. The first ** two columns are the names of the table and index. The third column ** is a string composed of a list of integer statistics about the ** index. The first integer in the list is the total number of entires ** in the index. There is one additional integer in the list for each ** column of the table. This additional integer is a guess of how many ** rows of the table the index will select. If D is the count of distinct ** values and K is the total number of rows, then the integer is computed ** as: ** ** I = (K+D-1)/D ** ** If K==0 then no entry is made into the sqlite_stat1 table. ** If K>0 then it is always the case the D>0 so division by zero ** is never possible. */ sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0); addr = sqlite3VdbeAddOp(v, OP_IfNot, 0, 0); sqlite3VdbeAddOp(v, OP_NewRowid, iStatCur, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0); sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, " ", 0); for(i=0; i<nCol; i++){ sqlite3VdbeAddOp(v, OP_MemLoad, iMem, 0); sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0); sqlite3VdbeAddOp(v, OP_Add, 0, 0); sqlite3VdbeAddOp(v, OP_AddImm, -1, 0); sqlite3VdbeAddOp(v, OP_MemLoad, iMem+i+1, 0); sqlite3VdbeAddOp(v, OP_Divide, 0, 0); if( i==nCol-1 ){ sqlite3VdbeAddOp(v, OP_Concat, nCol*2-1, 0); }else{ sqlite3VdbeAddOp(v, OP_Dup, 1, 0); } } sqlite3VdbeOp3(v, OP_MakeRecord, 3, 0, "ttt", 0); sqlite3VdbeAddOp(v, OP_Insert, iStatCur, 0); sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v)); } } /* ** Generate code that will cause the most recent index analysis to ** be laoded into internal hash tables where is can be used. */ static void loadAnalysis(Parse *pParse, int iDb){ Vdbe *v = sqlite3GetVdbe(pParse); sqlite3VdbeAddOp(v, OP_LoadAnalysis, iDb, 0); } /* ** Generate code that will do an analysis of an entire database */ static void analyzeDatabase(Parse *pParse, int iDb){ sqlite3 *db = pParse->db; HashElem *k; int iStatCur; int iMem; sqlite3BeginWriteOperation(pParse, 0, iDb); iStatCur = pParse->nTab++; openStatTable(pParse, iDb, iStatCur, 0); iMem = pParse->nMem; for(k=sqliteHashFirst(&db->aDb[iDb].tblHash); k; k=sqliteHashNext(k)){ Table *pTab = (Table*)sqliteHashData(k); analyzeOneTable(pParse, pTab, iStatCur, iMem); } loadAnalysis(pParse, iDb); } /* ** Generate code that will do an analysis of a single table in ** a database. */ static void analyzeTable(Parse *pParse, Table *pTab){ int iDb; int iStatCur; assert( pTab!=0 ); iDb = pTab->iDb; sqlite3BeginWriteOperation(pParse, 0, iDb); iStatCur = pParse->nTab++; openStatTable(pParse, iDb, iStatCur, pTab->zName); analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem); loadAnalysis(pParse, iDb); } /* ** Generate code for the ANALYZE command. The parser calls this routine ** when it recognizes an ANALYZE command. ** ** ANALYZE -- 1 ** ANALYZE <database> -- 2 ** ANALYZE ?<database>.?<tablename> -- 3 ** ** Form 1 causes all indices in all attached databases to be analyzed. ** Form 2 analyzes all indices the single database named. ** Form 3 analyzes all indices associated with the named table. */ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){ sqlite3 *db = pParse->db; int iDb; int i; char *z, *zDb; Table *pTab; Token *pTableName; /* Read the database schema. If an error occurs, leave an error message ** and code in pParse and return NULL. */ if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ return; } if( pName1==0 ){ /* Form 1: Analyze everything */ for(i=0; i<db->nDb; i++){ if( i==1 ) continue; /* Do not analyze the TEMP database */ analyzeDatabase(pParse, i); } }else if( pName2==0 || pName2->n==0 ){ /* Form 2: Analyze the database or table named */ iDb = sqlite3FindDb(db, pName1); if( iDb>=0 ){ analyzeDatabase(pParse, iDb); }else{ z = sqlite3NameFromToken(pName1); pTab = sqlite3LocateTable(pParse, z, 0); sqliteFree(z); if( pTab ){ analyzeTable(pParse, pTab); } } }else{ /* Form 3: Analyze the fully qualified table name */ iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName); if( iDb>=0 ){ zDb = db->aDb[iDb].zName; z = sqlite3NameFromToken(pTableName); pTab = sqlite3LocateTable(pParse, z, zDb); sqliteFree(z); if( pTab ){ analyzeTable(pParse, pTab); } } } } /* ** Used to pass information from the analyzer reader through to the ** callback routine. */ typedef struct analysisInfo analysisInfo; struct analysisInfo { sqlite3 *db; const char *zDatabase; }; /* ** This callback is invoked once for each index when reading the ** sqlite_stat1 table. ** ** argv[0] = name of the index ** argv[1] = results of analysis - on integer for each column */ static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){ analysisInfo *pInfo = (analysisInfo*)pData; Index *pIndex; int i, c; unsigned int v; const char *z; assert( argc==2 ); if( argv[0]==0 || argv[1]==0 ){ return 0; } pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase); if( pIndex==0 ){ return 0; } z = argv[1]; for(i=0; *z && i<=pIndex->nColumn; i++){ v = 0; while( (c=z[0])>='0' && c<='9' ){ v = v*10 + c - '0'; z++; } pIndex->aiRowEst[i] = v; if( *z==' ' ) z++; } return 0; } /* ** Load the content of the sqlite_stat1 table into the index hash tables. */ void sqlite3AnalysisLoad(sqlite3 *db, int iDb){ analysisInfo sInfo; HashElem *i; char *zSql; /* Clear any prior statistics */ for(i=sqliteHashFirst(&db->aDb[iDb].idxHash); i; i=sqliteHashNext(i)){ Index *pIdx = (Index *)sqliteHashData(i); sqlite3DefaultRowEst(pIdx); } /* Check to make sure the sqlite_stat1 table existss */ sInfo.db = db; sInfo.zDatabase = db->aDb[iDb].zName; if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){ return; } /* Load new statistics out of the sqlite_stat1 table */ zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1", sInfo.zDatabase); sqlite3SafetyOff(db); sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0); sqlite3SafetyOn(db); sqliteFree(zSql); } #endif /* SQLITE_OMIT_ANALYZE */ } |
Changes to SQLite.Interop/src/attach.c.
1 2 3 | #pragma unmanaged extern "C" { | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #pragma unmanaged extern "C" { /* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** This routine is called by the parser to process an ATTACH statement: ** ** ATTACH DATABASE filename AS dbname |
︙ | ︙ | |||
145 146 147 148 149 150 151 | int i = db->nDb - 1; assert( i>=2 ); if( db->aDb[i].pBt ){ sqlite3BtreeClose(db->aDb[i].pBt); db->aDb[i].pBt = 0; } sqlite3ResetInternalSchema(db, 0); | | | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | int i = db->nDb - 1; assert( i>=2 ); if( db->aDb[i].pBt ){ sqlite3BtreeClose(db->aDb[i].pBt); db->aDb[i].pBt = 0; } sqlite3ResetInternalSchema(db, 0); assert( pParse->nErr>0 ); /* Always set by sqlite3ReadSchema() */ if( pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; } } attach_end: sqliteFree(zFile); sqliteFree(zName); |
︙ | ︙ | |||
349 350 351 352 353 354 355 | return 1; } pStep = pStep->pNext; } return 0; } #endif | | < | 349 350 351 352 353 354 355 356 | return 1; } pStep = pStep->pNext; } return 0; } #endif } |
Changes to SQLite.Interop/src/auth.c.
1 2 3 | #pragma unmanaged extern "C" { | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #pragma unmanaged extern "C" { /* ** 2003 January 11 ** ** 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 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** All of the code in this file may be omitted by defining a single ** macro. */ |
︙ | ︙ | |||
113 114 115 116 117 118 119 120 121 122 123 124 125 126 | Table *pTab; /* The table being read */ const char *zCol; /* Name of the column of the table */ int iSrc; /* Index in pTabList->a[] of table being read */ const char *zDBase; /* Name of database being accessed */ TriggerStack *pStack; /* The stack of current triggers */ if( db->xAuth==0 ) return; assert( pExpr->op==TK_COLUMN ); for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){ if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break; } if( iSrc>=0 && pTabList && iSrc<pTabList->nSrc ){ pTab = pTabList->a[iSrc].pTab; }else if( (pStack = pParse->trigStack)!=0 ){ | > | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | Table *pTab; /* The table being read */ const char *zCol; /* Name of the column of the table */ int iSrc; /* Index in pTabList->a[] of table being read */ const char *zDBase; /* Name of database being accessed */ TriggerStack *pStack; /* The stack of current triggers */ if( db->xAuth==0 ) return; if( pExpr->op==TK_AS ) return; assert( pExpr->op==TK_COLUMN ); for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){ if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break; } if( iSrc>=0 && pTabList && iSrc<pTabList->nSrc ){ pTab = pTabList->a[iSrc].pTab; }else if( (pStack = pParse->trigStack)!=0 ){ |
︙ | ︙ | |||
221 222 223 224 225 226 227 | if( pContext->pParse ){ pContext->pParse->zAuthContext = pContext->zAuthContext; pContext->pParse = 0; } } #endif /* SQLITE_OMIT_AUTHORIZATION */ | | < | 222 223 224 225 226 227 228 229 | if( pContext->pParse ){ pContext->pParse->zAuthContext = pContext->zAuthContext; pContext->pParse = 0; } } #endif /* SQLITE_OMIT_AUTHORIZATION */ } |
Changes to SQLite.Interop/src/btree.c.
1 2 3 | #pragma unmanaged extern "C" { | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #pragma unmanaged extern "C" { /* ** 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.8 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
233 234 235 236 237 238 239 | /* Forward declarations */ typedef struct MemPage MemPage; /* ** This is a magic string that appears at the beginning of every ** SQLite database in order to identify the file as a real database. | > > > > > > > > > | > > | | 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 | /* Forward declarations */ typedef struct MemPage MemPage; /* ** This is a magic string that appears at the beginning of every ** SQLite database in order to identify the file as a real database. ** ** You can change this value at compile-time by specifying a ** -DSQLITE_FILE_HEADER="..." on the compiler command-line. The ** header must be exactly 16 bytes including the zero-terminator so ** the string itself should be 15 characters long. If you change ** the header, then your custom library will not be able to read ** databases generated by the standard tools and the standard tools ** will not be able to read databases created by your custom library. */ #ifndef SQLITE_FILE_HEADER /* 123456789 123456 */ # define SQLITE_FILE_HEADER "SQLite format 3" #endif static const char zMagicHeader[] = SQLITE_FILE_HEADER; /* ** Page type flags. An ORed combination of these flags appear as the ** first byte of every BTree page. */ #define PTF_INTKEY 0x01 #define PTF_ZERODATA 0x02 |
︙ | ︙ | |||
556 557 558 559 560 561 562 | ** This a more complex version of findCell() that works for ** pages that do contain overflow cells. See insert */ static u8 *findOverflowCell(MemPage *pPage, int iCell){ int i; for(i=pPage->nOverflow-1; i>=0; i--){ int k; | | | 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | ** This a more complex version of findCell() that works for ** pages that do contain overflow cells. See insert */ static u8 *findOverflowCell(MemPage *pPage, int iCell){ int i; for(i=pPage->nOverflow-1; i>=0; i--){ int k; struct MemPage::_OvflCell *pOvfl; pOvfl = &pPage->aOvfl[i]; k = pOvfl->idx; if( k<=iCell ){ if( k==iCell ){ return pOvfl->pCell; } iCell--; |
︙ | ︙ | |||
1594 1595 1596 1597 1598 1599 1600 | ** One or the other of the two processes must give way or there can be ** no progress. By returning SQLITE_BUSY and not invoking the busy callback ** when A already has a read lock, we encourage A to give up and let B ** proceed. */ int sqlite3BtreeBeginTrans(Btree *pBt, int wrflag){ int rc = SQLITE_OK; | < < | 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 | ** One or the other of the two processes must give way or there can be ** no progress. By returning SQLITE_BUSY and not invoking the busy callback ** when A already has a read lock, we encourage A to give up and let B ** proceed. */ int sqlite3BtreeBeginTrans(Btree *pBt, int wrflag){ int rc = SQLITE_OK; /* If the btree is already in a write-transaction, or it ** is already in a read-transaction and a read-transaction ** is requested, this is a no-op. */ if( pBt->inTrans==TRANS_WRITE || (pBt->inTrans==TRANS_READ && !wrflag) ){ return SQLITE_OK; |
︙ | ︙ | |||
1629 1630 1631 1632 1633 1634 1635 | if( rc==SQLITE_OK ){ pBt->inTrans = (wrflag?TRANS_WRITE:TRANS_READ); if( wrflag ) pBt->inStmt = 0; }else{ unlockBtreeIfUnused(pBt); } }while( rc==SQLITE_BUSY && pBt->inTrans==TRANS_NONE && | | < < | 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 | if( rc==SQLITE_OK ){ pBt->inTrans = (wrflag?TRANS_WRITE:TRANS_READ); if( wrflag ) pBt->inStmt = 0; }else{ unlockBtreeIfUnused(pBt); } }while( rc==SQLITE_BUSY && pBt->inTrans==TRANS_NONE && sqlite3InvokeBusyHandler(pBt->pBusyHandler) ); return rc; } #ifndef SQLITE_OMIT_AUTOVACUUM /* ** Set the pointer-map entries for all children of page pPage. Also, if |
︙ | ︙ | |||
3594 3595 3596 3597 3598 3599 3600 | } assert( totalSize+2*nCell<=pPage->nFree ); assert( pPage->nCell==0 ); cellptr = pPage->cellOffset; data = pPage->aData; hdr = pPage->hdrOffset; put2byte(&data[hdr+3], nCell); | > | | | | | | | | | | | > | 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 | } assert( totalSize+2*nCell<=pPage->nFree ); assert( pPage->nCell==0 ); cellptr = pPage->cellOffset; data = pPage->aData; hdr = pPage->hdrOffset; put2byte(&data[hdr+3], nCell); if( nCell ){ cellbody = allocateSpace(pPage, totalSize); assert( cellbody>0 ); assert( pPage->nFree >= 2*nCell ); pPage->nFree -= 2*nCell; for(i=0; i<nCell; i++){ put2byte(&data[cellptr], cellbody); memcpy(&data[cellbody], apCell[i], aSize[i]); cellptr += 2; cellbody += aSize[i]; } assert( cellbody==pPage->pBt->usableSize ); } pPage->nCell = nCell; } /* ** The following parameters determine how many adjacent pages get involved ** in a balancing operation. NN is the number of neighbors on either side ** of the page that participate in the balancing operation. NB is the |
︙ | ︙ | |||
3808 3809 3810 3811 3812 3813 3814 | assert( pParent ); TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno)); #ifndef SQLITE_OMIT_QUICKBALANCE /* ** A special case: If a new entry has just been inserted into a ** table (that is, a btree with integer keys and all data at the leaves) | | | 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 | assert( pParent ); TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno)); #ifndef SQLITE_OMIT_QUICKBALANCE /* ** A special case: If a new entry has just been inserted into a ** table (that is, a btree with integer keys and all data at the leaves) ** and the new entry is the right-most entry in the tree (it has the ** largest key) then use the special balance_quick() routine for ** balancing. balance_quick() is much faster and results in a tighter ** packing of data in the common case. */ if( pPage->leaf && pPage->intKey && pPage->leafData && |
︙ | ︙ | |||
4081 4082 4083 4084 4085 4086 4087 | cntNew[i-1]--; r = cntNew[i-1] - 1; d = r + 1 - leafData; } szNew[i] = szRight; szNew[i-1] = szLeft; } | > > > > > | | 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 | cntNew[i-1]--; r = cntNew[i-1] - 1; d = r + 1 - leafData; } szNew[i] = szRight; szNew[i-1] = szLeft; } /* Either we found one or more cells (cntnew[0])>0) or we are the ** a virtual root page. A virtual root page is when the real root ** page is page 1 and we are the only child of that page. */ assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) ); /* ** Allocate k new pages. Reuse old pages where possible. */ assert( pPage->pgno>1 ); pageFlags = pPage->aData[0]; for(i=0; i<k; i++){ |
︙ | ︙ | |||
4170 4171 4172 4173 4174 4175 4176 | j = 0; for(i=0; i<nNew; i++){ /* Assemble the new sibling page. */ MemPage *pNew = apNew[i]; assert( j<nMaxCells ); assert( pNew->pgno==pgnoNew[i] ); assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]); | | | 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 | j = 0; for(i=0; i<nNew; i++){ /* Assemble the new sibling page. */ MemPage *pNew = apNew[i]; assert( j<nMaxCells ); assert( pNew->pgno==pgnoNew[i] ); assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]); assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) ); assert( pNew->nOverflow==0 ); #ifndef SQLITE_OMIT_AUTOVACUUM /* If this is an auto-vacuum database, update the pointer map entries ** that point to the siblings that were rearranged. These can be: left ** children of cells, the right-child of the page, or overflow pages ** pointed to by cells. |
︙ | ︙ | |||
4882 4883 4884 4885 4886 4887 4888 | int rc; BtCursor *pCur; if( pBt->inTrans!=TRANS_WRITE ){ return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; } for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ if( pCur->pgnoRoot==(Pgno)iTable ){ | | < | 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 | int rc; BtCursor *pCur; if( pBt->inTrans!=TRANS_WRITE ){ return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; } for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ if( pCur->pgnoRoot==(Pgno)iTable ){ if( pCur->wrFlag==0 ) return SQLITE_LOCKED; moveToRoot(pCur); } } rc = clearDatabasePage(pBt, (Pgno)iTable, 0, 0); if( rc ){ sqlite3BtreeRollback(pBt); } |
︙ | ︙ | |||
5810 5811 5812 5813 5814 5815 5816 | int sqlite3BtreeReset(Btree *pBt){ if( pBt->pCursor ) return SQLITE_BUSY; pBt->inTrans = TRANS_NONE; unlockBtreeIfUnused(pBt); return sqlite3pager_reset(pBt->pPager); } #endif | | < | 5823 5824 5825 5826 5827 5828 5829 5830 | int sqlite3BtreeReset(Btree *pBt){ if( pBt->pCursor ) return SQLITE_BUSY; pBt->inTrans = TRANS_NONE; unlockBtreeIfUnused(pBt); return sqlite3pager_reset(pBt->pPager); } #endif } |
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.7 2005/08/22 18:22:12 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.
1 2 3 | #pragma unmanaged extern "C" { | | | 1 2 3 4 5 6 7 8 9 10 11 | #pragma unmanaged extern "C" { /* ** 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. |
︙ | ︙ | |||
21 22 23 24 25 26 27 | ** CREATE INDEX ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ** CREATE INDEX ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** ** $Id: build.c,v 1.7 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
199 200 201 202 203 204 205 | return 0; } p = sqlite3FindTable(pParse->db, zName, zDbase); if( p==0 ){ if( zDbase ){ sqlite3ErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); | < < < | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | return 0; } p = sqlite3FindTable(pParse->db, zName, zDbase); if( p==0 ){ if( zDbase ){ sqlite3ErrorMsg(pParse, "no such table: %s.%s", zDbase, zName); }else{ sqlite3ErrorMsg(pParse, "no such table: %s", zName); } pParse->checkSchema = 1; } return p; } |
︙ | ︙ | |||
257 258 259 260 261 262 263 | */ static void sqliteDeleteIndex(sqlite3 *db, Index *p){ Index *pOld; assert( db!=0 && p->zName!=0 ); pOld = (Index *)sqlite3HashInsert(&db->aDb[p->iDb].idxHash, p->zName, strlen(p->zName)+1, 0); | | < < < | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | */ static void sqliteDeleteIndex(sqlite3 *db, Index *p){ Index *pOld; assert( db!=0 && p->zName!=0 ); pOld = (Index *)sqlite3HashInsert(&db->aDb[p->iDb].idxHash, p->zName, strlen(p->zName)+1, 0); assert( pOld==0 || pOld==p ); freeIndex(p); } /* ** For the index called zIdxName which is found in the database iDb, ** unlike that index from its Table then remove the index from ** the index hash table and free all memory structures associated |
︙ | ︙ | |||
534 535 536 537 538 539 540 | /* ** The token *pName contains the name of a database (either "main" or ** "temp" or the name of an attached db). This routine returns the ** index of the named database in db->aDb[], or -1 if the named db ** does not exist. */ | | | 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | /* ** The token *pName contains the name of a database (either "main" or ** "temp" or the name of an attached db). This routine returns the ** index of the named database in db->aDb[], or -1 if the named db ** does not exist. */ int sqlite3FindDb(sqlite3 *db, Token *pName){ int i = -1; /* Database number */ int n; /* Number of characters in the name */ Db *pDb; /* A database whose name space is being searched */ char *zName; /* Name we are searching for */ zName = sqlite3NameFromToken(pName); if( zName ){ |
︙ | ︙ | |||
582 583 584 585 586 587 588 | ){ int iDb; /* Database holding the object */ sqlite3 *db = pParse->db; if( pName2 && pName2->n>0 ){ assert( !db->init.busy ); *pUnqual = pName2; | | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | ){ int iDb; /* Database holding the object */ sqlite3 *db = pParse->db; if( pName2 && pName2->n>0 ){ assert( !db->init.busy ); *pUnqual = pName2; iDb = sqlite3FindDb(db, pName1); if( iDb<0 ){ sqlite3ErrorMsg(pParse, "unknown database %T", pName1); pParse->nErr++; return -1; } }else{ assert( db->init.iDb==0 || db->init.busy ); |
︙ | ︙ | |||
744 745 746 747 748 749 750 | pParse->pNewTable = pTable; /* If this is the magic sqlite_sequence table used by autoincrement, ** then record a pointer to this table in the main database structure ** so that INSERT can find the table easily. */ #ifndef SQLITE_OMIT_AUTOINCREMENT | | | 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | pParse->pNewTable = pTable; /* If this is the magic sqlite_sequence table used by autoincrement, ** then record a pointer to this table in the main database structure ** so that INSERT can find the table easily. */ #ifndef SQLITE_OMIT_AUTOINCREMENT if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){ db->aDb[iDb].pSeqTab = pTable; } #endif /* Begin generating the code that will insert the table record into ** the SQLITE_MASTER table. Note in particular that we must go ahead ** and allocate the record number for the table entry now. Before any |
︙ | ︙ | |||
901 902 903 904 905 906 907 | ** 'CLOB' | SQLITE_AFF_TEXT ** 'TEXT' | SQLITE_AFF_TEXT ** 'BLOB' | SQLITE_AFF_NONE ** ** If none of the substrings in the above table are found, ** SQLITE_AFF_NUMERIC is returned. */ | | | | | 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 | ** 'CLOB' | SQLITE_AFF_TEXT ** 'TEXT' | SQLITE_AFF_TEXT ** 'BLOB' | SQLITE_AFF_NONE ** ** If none of the substrings in the above table are found, ** SQLITE_AFF_NUMERIC is returned. */ char sqlite3AffinityType(const Token *pType){ u32 h = 0; char aff = SQLITE_AFF_NUMERIC; const unsigned char *zIn = pType->z; const unsigned char *zEnd = &pType->z[pType->n]; while( zIn!=zEnd ){ h = (h<<8) + sqlite3UpperToLower[*zIn]; zIn++; if( h==(('c'<<24)+('h'<<16)+('a'<<8)+'r') ){ /* CHAR */ aff = SQLITE_AFF_TEXT; }else if( h==(('c'<<24)+('l'<<16)+('o'<<8)+'b') ){ /* CLOB */ |
︙ | ︙ | |||
937 938 939 940 941 942 943 | ** parsing a CREATE TABLE statement. The pFirst token is the first ** token in the sequence of tokens that describe the type of the ** column currently under construction. pLast is the last token ** in the sequence. Use this information to construct a string ** that contains the typename of the column and store that string ** in zType. */ | | | < | < < < < | < < < < < < < | | | | | | | | | > | 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 | ** parsing a CREATE TABLE statement. The pFirst token is the first ** token in the sequence of tokens that describe the type of the ** column currently under construction. pLast is the last token ** in the sequence. Use this information to construct a string ** that contains the typename of the column and store that string ** in zType. */ void sqlite3AddColumnType(Parse *pParse, Token *pType){ Table *p; int i; Column *pCol; if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( i<0 ) return; pCol = &p->aCol[i]; assert( pCol->zType==0 ); pCol->zType = sqlite3NameFromToken(pType); pCol->affinity = sqlite3AffinityType(pType); } /* ** The expression is the default value for the most recently added column ** of the table currently under construction. ** ** Default value expressions must be constant. Raise an exception if this ** is not the case. ** ** This routine is called by the parser while in the middle of ** parsing a CREATE TABLE statement. */ void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){ Table *p; Column *pCol; if( (p = pParse->pNewTable)!=0 ){ pCol = &(p->aCol[p->nCol-1]); if( !sqlite3ExprIsConstantOrFunction(pExpr) ){ sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", pCol->zName); }else{ sqlite3ExprDelete(pCol->pDflt); pCol->pDflt = sqlite3ExprDup(pExpr); } } sqlite3ExprDelete(pExpr); } /* ** Designate the PRIMARY KEY for the table. pList is a list of names ** of columns that form the primary key. If pList is NULL, then the |
︙ | ︙ | |||
1316 1317 1318 1319 1320 1321 1322 | /* Create the rootpage for the new table and push it onto the stack. ** A view has no rootpage, so just push a zero onto the stack for ** views. Initialize zType at the same time. */ if( p->pSelect==0 ){ /* A regular table */ | < < | 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 | /* Create the rootpage for the new table and push it onto the stack. ** A view has no rootpage, so just push a zero onto the stack for ** views. Initialize zType at the same time. */ if( p->pSelect==0 ){ /* A regular table */ zType = "table"; zType2 = "TABLE"; #ifndef SQLITE_OMIT_VIEW }else{ /* A view */ zType = "view"; zType2 = "VIEW"; #endif } /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT ** statement to populate the new table. The root-page number for the |
︙ | ︙ | |||
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 | ** ** CREATE VIEW one AS SELECT * FROM two; ** CREATE VIEW two AS SELECT * FROM one; ** ** Actually, this error is caught previously and so the following test ** should always fail. But we will leave it in place just to be safe. */ if( pTable->nCol<0 ){ sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } /* If we get this far, it means we need to compute the table names. ** Note that the call to sqlite3ResultSetOfSelect() will expand any ** "*" elements in the results set of the view and will assign cursors ** to the elements of the FROM clause. But we do not want these changes ** to be permanent. So the computation is done on a copy of the SELECT ** statement that defines the view. | > > > | 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 | ** ** CREATE VIEW one AS SELECT * FROM two; ** CREATE VIEW two AS SELECT * FROM one; ** ** Actually, this error is caught previously and so the following test ** should always fail. But we will leave it in place just to be safe. */ #if 0 if( pTable->nCol<0 ){ sqlite3ErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } #endif assert( pTable->nCol>=0 ); /* If we get this far, it means we need to compute the table names. ** Note that the call to sqlite3ResultSetOfSelect() will expand any ** "*" elements in the results set of the view and will assign cursors ** to the elements of the FROM clause. But we do not want these changes ** to be permanent. So the computation is done on a copy of the SELECT ** statement that defines the view. |
︙ | ︙ | |||
1972 1973 1974 1975 1976 1977 1978 | static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){ Table *pTab = pIndex->pTable; /* The table that is indexed */ int iTab = pParse->nTab; /* Btree cursor used for pTab */ int iIdx = pParse->nTab+1; /* Btree cursor used for pIndex */ int addr1; /* Address of top of loop */ int tnum; /* Root page of index */ Vdbe *v; /* Generate code into this virtual machine */ | < | 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 | static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){ Table *pTab = pIndex->pTable; /* The table that is indexed */ int iTab = pParse->nTab; /* Btree cursor used for pTab */ int iIdx = pParse->nTab+1; /* Btree cursor used for pIndex */ int addr1; /* Address of top of loop */ int tnum; /* Root page of index */ Vdbe *v; /* Generate code into this virtual machine */ #ifndef SQLITE_OMIT_AUTHORIZATION if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0, pParse->db->aDb[pIndex->iDb].zName ) ){ return; } #endif |
︙ | ︙ | |||
2001 2002 2003 2004 2005 2006 2007 | }else{ tnum = pIndex->tnum; sqlite3VdbeAddOp(v, OP_Clear, tnum, pIndex->iDb); } sqlite3VdbeAddOp(v, OP_Integer, pIndex->iDb, 0); sqlite3VdbeOp3(v, OP_OpenWrite, iIdx, tnum, (char*)&pIndex->keyInfo, P3_KEYINFO); | < | < | > > > > | | > | > > | 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 | }else{ tnum = pIndex->tnum; sqlite3VdbeAddOp(v, OP_Clear, tnum, pIndex->iDb); } sqlite3VdbeAddOp(v, OP_Integer, pIndex->iDb, 0); sqlite3VdbeOp3(v, OP_OpenWrite, iIdx, tnum, (char*)&pIndex->keyInfo, P3_KEYINFO); sqlite3OpenTableForReading(v, iTab, pTab); addr1 = sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0); sqlite3GenerateIndexKey(v, pIndex, iTab); if( pIndex->onError!=OE_None ){ int curaddr = sqlite3VdbeCurrentAddr(v); int addr2 = curaddr+4; sqlite3VdbeChangeP2(v, curaddr-1, addr2); sqlite3VdbeAddOp(v, OP_Rowid, iTab, 0); sqlite3VdbeAddOp(v, OP_AddImm, 1, 0); sqlite3VdbeAddOp(v, OP_IsUnique, iIdx, addr2); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort, "indexed columns are not unique", P3_STATIC); assert( addr2==sqlite3VdbeCurrentAddr(v) ); } sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, 0); sqlite3VdbeAddOp(v, OP_Next, iTab, addr1+1); sqlite3VdbeChangeP2(v, addr1, sqlite3VdbeCurrentAddr(v)); sqlite3VdbeAddOp(v, OP_Close, iTab, 0); sqlite3VdbeAddOp(v, OP_Close, iIdx, 0); } /* |
︙ | ︙ | |||
2078 2079 2080 2081 2082 2083 2084 | iDb = 1; } #endif if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) ){ | | > > | 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 | iDb = 1; } #endif if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && sqlite3FixSrcList(&sFix, pTblName) ){ /* Because the parser constructs pTblName from a single identifier, ** sqlite3FixSrcList can never fail. */ assert(0); } pTab = sqlite3LocateTable(pParse, pTblName->a[0].zName, pTblName->a[0].zDatabase); if( !pTab ) goto exit_create_index; assert( iDb==pTab->iDb ); }else{ assert( pName==0 ); |
︙ | ︙ | |||
2167 2168 2169 2170 2171 2172 2173 | #endif /* If pList==0, it means this routine was called to make a primary ** key out of the last column added to the table under construction. ** So create a fake list to simulate this. */ if( pList==0 ){ | | | | > | | 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 | #endif /* If pList==0, it means this routine was called to make a primary ** key out of the last column added to the table under construction. ** So create a fake list to simulate this. */ if( pList==0 ){ nullId.z = (unsigned char *)pTab->aCol[pTab->nCol-1].zName; nullId.n = strlen((const char *)nullId.z); pList = sqlite3ExprListAppend(0, 0, &nullId); if( pList==0 ) goto exit_create_index; } /* ** Allocate the index structure. */ pIndex = (Index *)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 int *)&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; |
︙ | ︙ | |||
2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 | if( !db->init.busy && sqlite3CheckCollSeq(pParse, pIndex->keyInfo.aColl[i]) ){ goto exit_create_index; } } pIndex->keyInfo.nField = pList->nExpr; if( pTab==pParse->pNewTable ){ /* This routine has been called to create an automatic index as a ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or ** a PRIMARY KEY or UNIQUE clause following the column definitions. ** i.e. one of: ** | > | 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 | if( !db->init.busy && sqlite3CheckCollSeq(pParse, pIndex->keyInfo.aColl[i]) ){ goto exit_create_index; } } pIndex->keyInfo.nField = pList->nExpr; sqlite3DefaultRowEst(pIndex); if( pTab==pParse->pNewTable ){ /* This routine has been called to create an automatic index as a ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or ** a PRIMARY KEY or UNIQUE clause following the column definitions. ** i.e. one of: ** |
︙ | ︙ | |||
2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 | freeIndex(pIndex); } sqlite3ExprListDelete(pList); sqlite3SrcListDelete(pTblName); sqliteFree(zName); return; } /* ** This routine will drop an existing named index. This routine ** implements the DROP INDEX statement. */ void sqlite3DropIndex(Parse *pParse, SrcList *pName){ Index *pIndex; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | freeIndex(pIndex); } sqlite3ExprListDelete(pList); sqlite3SrcListDelete(pTblName); sqliteFree(zName); return; } /* ** Fill the Index.aiRowEst[] array with default information - information ** to be used when we have not run the ANALYZE command. ** ** aiRowEst[0] is suppose to contain the number of elements in the index. ** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the ** number of rows in the table that match any particular value of the ** first column of the index. aiRowEst[2] is an estimate of the number ** of rows that match any particular combiniation of the first 2 columns ** of the index. And so forth. It must always be the case that * ** aiRowEst[N]<=aiRowEst[N-1] ** aiRowEst[N]>=1 ** ** Apart from that, we have little to go on besides intuition as to ** how aiRowEst[] should be initialized. The numbers generated here ** are based on typical values found in actual indices. */ void sqlite3DefaultRowEst(Index *pIdx){ int *a = (int *)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 ){ a[pIdx->nColumn] = 1; } } /* ** This routine will drop an existing named index. This routine ** implements the DROP INDEX statement. */ void sqlite3DropIndex(Parse *pParse, SrcList *pName){ Index *pIndex; |
︙ | ︙ | |||
2456 2457 2458 2459 2460 2461 2462 | IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){ if( pList==0 ){ pList = (IdList *)sqliteMalloc( sizeof(IdList) ); if( pList==0 ) return 0; pList->nAlloc = 0; } if( pList->nId>=pList->nAlloc ){ | | | > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){ if( pList==0 ){ pList = (IdList *)sqliteMalloc( sizeof(IdList) ); if( pList==0 ) return 0; pList->nAlloc = 0; } if( pList->nId>=pList->nAlloc ){ struct IdList::IdList_item *a; pList->nAlloc = pList->nAlloc*2 + 5; a = (IdList::IdList_item *)sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]) ); if( a==0 ){ sqlite3IdListDelete(pList); return 0; } pList->a = a; } memset(&pList->a[pList->nId], 0, sizeof(pList->a[0])); pList->a[pList->nId].zName = sqlite3NameFromToken(pToken); pList->nId++; return pList; } /* ** Delete an IdList. */ void sqlite3IdListDelete(IdList *pList){ int i; if( pList==0 ) return; for(i=0; i<pList->nId; i++){ sqliteFree(pList->a[i].zName); } sqliteFree(pList->a); sqliteFree(pList); } /* ** Return the index in pList of the identifier named zId. Return -1 ** if not found. */ int sqlite3IdListIndex(IdList *pList, const char *zName){ int i; if( pList==0 ) return -1; for(i=0; i<pList->nId; i++){ if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i; } return -1; } /* ** Append a new table name to the given SrcList. Create a new SrcList if ** need be. A new entry is created in the SrcList even if pToken is NULL. ** ** A new SrcList is returned, or NULL if malloc() fails. ** |
︙ | ︙ | |||
2497 2498 2499 2500 2501 2502 2503 | ** like this: ** ** sqlite3SrcListAppend(A,B,C); ** ** Then C is the table name and B is the database name. */ SrcList *sqlite3SrcListAppend(SrcList *pList, Token *pTable, Token *pDatabase){ | | | | 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 | ** like this: ** ** sqlite3SrcListAppend(A,B,C); ** ** Then C is the table name and B is the database name. */ SrcList *sqlite3SrcListAppend(SrcList *pList, Token *pTable, Token *pDatabase){ struct SrcList::SrcList_item *pItem; if( pList==0 ){ pList = (SrcList *)sqliteMalloc( sizeof(SrcList) ); if( pList==0 ) return 0; pList->nAlloc = 1; } if( pList->nSrc>=pList->nAlloc ){ SrcList *pNew; pList->nAlloc *= 2; pNew = (SrcList *)sqliteRealloc(pList, sizeof(*pList) + (pList->nAlloc-1)*sizeof(pList->a[0]) ); if( pNew==0 ){ sqlite3SrcListDelete(pList); return 0; } pList = pNew; } pItem = (SrcList::SrcList_item *)&pList->a[pList->nSrc]; memset(pItem, 0, sizeof(pList->a[0])); if( pDatabase && pDatabase->z==0 ){ pDatabase = 0; } if( pDatabase && pTable ){ Token *pTemp = pDatabase; pDatabase = pTable; |
︙ | ︙ | |||
2555 2556 2557 2558 2559 2560 2561 | */ void sqlite3SrcListAddAlias(SrcList *pList, Token *pToken){ if( pList && pList->nSrc>0 ){ pList->a[pList->nSrc-1].zAlias = sqlite3NameFromToken(pToken); } } | < < < < < < < < < < < < < < < < < < < < < < < < < < | 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 | */ void sqlite3SrcListAddAlias(SrcList *pList, Token *pToken){ if( pList && pList->nSrc>0 ){ pList->a[pList->nSrc-1].zAlias = sqlite3NameFromToken(pToken); } } /* ** Delete an entire SrcList including all its substructure. */ void sqlite3SrcListDelete(SrcList *pList){ int i; struct SrcList::SrcList_item *pItem; if( pList==0 ) return; |
︙ | ︙ | |||
2783 2784 2785 2786 2787 2788 2789 | #endif /* ** Recompute all indices of pTab that use the collating sequence pColl. ** If pColl==0 then recompute all indices of pTab. */ #ifndef SQLITE_OMIT_REINDEX | | | | | 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 | #endif /* ** Recompute all indices of pTab that use the collating sequence pColl. ** If pColl==0 then recompute all indices of pTab. */ #ifndef SQLITE_OMIT_REINDEX static void reindexTable(Parse *pParse, Table *pTab, CollSeq *pColl){ Index *pIndex; /* An index associated with pTab */ for(pIndex=pTab->pIndex; pIndex; pIndex=pIndex->pNext){ if( pColl==0 || collationMatch(pColl,pIndex) ){ sqlite3BeginWriteOperation(pParse, 0, pTab->iDb); sqlite3RefillIndex(pParse, pIndex, -1); } } } #endif /* ** Recompute all indices of all tables in all databases where the ** indices use the collating sequence pColl. If pColl==0 then recompute ** all indices everywhere. */ #ifndef SQLITE_OMIT_REINDEX static void reindexDatabases(Parse *pParse, CollSeq *pColl){ Db *pDb; /* A single database */ int iDb; /* The database index number */ sqlite3 *db = pParse->db; /* The database connection */ HashElem *k; /* For looping over tables in pDb */ Table *pTab; /* A table in the database */ for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){ if( pDb==0 ) continue; for(k=sqliteHashFirst(&pDb->tblHash); k; k=sqliteHashNext(k)){ pTab = (Table*)sqliteHashData(k); reindexTable(pParse, pTab, pColl); } } } #endif |
︙ | ︙ | |||
2878 2879 2880 2881 2882 2883 2884 | sqlite3BeginWriteOperation(pParse, 0, iDb); sqlite3RefillIndex(pParse, pIndex, -1); return; } sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed"); } #endif | | < | 2901 2902 2903 2904 2905 2906 2907 2908 | sqlite3BeginWriteOperation(pParse, 0, iDb); sqlite3RefillIndex(pParse, pIndex, -1); return; } sqlite3ErrorMsg(pParse, "unable to identify the object to be reindexed"); } #endif } |
Changes to SQLite.Interop/src/callback.c.
1 2 3 | #pragma unmanaged extern "C" { | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #pragma unmanaged extern "C" { /* ** 2005 May 23 ** ** 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 functions used to access the internal hash tables ** of user defined functions and collation sequences. ** ** $Id: callback.c,v 1.3 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
146 147 148 149 150 151 152 | ** array of three CollSeq structures. The first is the collation sequence ** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be. ** ** Stored immediately after the three collation sequences is a copy of ** the collation sequence name. A pointer to this string is stored in ** each collation sequence structure. */ | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | ** array of three CollSeq structures. The first is the collation sequence ** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be. ** ** Stored immediately after the three collation sequences is a copy of ** the collation sequence name. A pointer to this string is stored in ** each collation sequence structure. */ static CollSeq *findCollSeqEntry( sqlite3 *db, const char *zName, int nName, int create ){ CollSeq *pColl; if( nName<0 ) nName = strlen(zName); |
︙ | ︙ | |||
285 286 287 288 289 290 291 | } /* If the createFlag parameter is true, and the seach did not reveal an ** exact match for the name, number of arguments and encoding, then add a ** new entry to the hash table and return it. */ if( createFlag && bestmatch<6 && | | < | < | 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 | } /* If the createFlag parameter is true, and the seach did not reveal an ** exact match for the name, number of arguments and encoding, then add a ** new entry to the hash table and return it. */ if( createFlag && bestmatch<6 && (pBest = (FuncDef *)sqliteMalloc(sizeof(*pBest)+nName)) ){ pBest->nArg = nArg; pBest->pNext = pFirst; pBest->iPrefEnc = enc; memcpy(pBest->zName, zName, nName); pBest->zName[nName] = 0; if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){ sqliteFree(pBest); return 0; } } if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){ return pBest; } return 0; } } |
Added SQLite.Interop/src/complete.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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 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 | #pragma unmanaged extern "C" { /* ** 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. ** ************************************************************************* ** 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.1 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #ifndef SQLITE_OMIT_COMPLETE /* ** This is defined in tokenize.c. We just have to import the definition. */ extern const char sqlite3IsIdChar[]; #define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20])) /* ** Token types used by the sqlite3_complete() routine. See the header ** comments on that procedure for additional information. */ #define tkSEMI 0 #define tkWS 1 #define tkOTHER 2 #define tkEXPLAIN 3 #define tkCREATE 4 #define tkTEMP 5 #define tkTRIGGER 6 #define tkEND 7 /* ** Return TRUE if the given SQL string ends in a semicolon. ** ** Special handling is require for CREATE TRIGGER statements. ** Whenever the CREATE TRIGGER keywords are seen, the statement ** must end with ";END;". ** ** This implementation uses a state machine with 7 states: ** ** (0) START At the beginning or end of an SQL statement. This routine ** returns 1 if it ends in the START state and 0 if it ends ** in any other state. ** ** (1) NORMAL We are in the middle of statement which ends with a single ** semicolon. ** ** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of ** a statement. ** ** (3) CREATE The keyword CREATE has been seen at the beginning of a ** statement, possibly preceeded by EXPLAIN and/or followed by ** TEMP or TEMPORARY ** ** (4) TRIGGER We are in the middle of a trigger definition that must be ** ended by a semicolon, the keyword END, and another semicolon. ** ** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at ** the end of a trigger definition. ** ** (6) END We've seen the ";END" of the ";END;" that occurs at the end ** of a trigger difinition. ** ** Transitions between states above are determined by tokens extracted ** from the input. The following tokens are significant: ** ** (0) tkSEMI A semicolon. ** (1) tkWS Whitespace ** (2) tkOTHER Any other SQL token. ** (3) tkEXPLAIN The "explain" keyword. ** (4) tkCREATE The "create" keyword. ** (5) tkTEMP The "temp" or "temporary" keyword. ** (6) tkTRIGGER The "trigger" keyword. ** (7) tkEND The "end" keyword. ** ** Whitespace never causes a state transition and is always ignored. ** ** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed ** to recognize the end of a trigger can be omitted. All we have to do ** is look for a semicolon that is not part of an string or comment. */ int sqlite3_complete(const char *zSql){ u8 state = 0; /* Current state, using numbers defined in header comment */ u8 token; /* Value of the next token */ #ifndef SQLITE_OMIT_TRIGGER /* A complex statement machine used to detect the end of a CREATE TRIGGER ** statement. This is the normal case. */ static const u8 trans[7][8] = { /* Token: */ /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */ /* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, }, /* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, }, /* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, }, /* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, }, /* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, }, /* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, }, /* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, }, }; #else /* If triggers are not suppored by this compile then the statement machine ** used to detect the end of a statement is much simplier */ static const u8 trans[2][3] = { /* Token: */ /* State: ** SEMI WS OTHER */ /* 0 START: */ { 0, 0, 1, }, /* 1 NORMAL: */ { 0, 1, 1, }, }; #endif /* SQLITE_OMIT_TRIGGER */ while( *zSql ){ switch( *zSql ){ case ';': { /* A semicolon */ token = tkSEMI; break; } case ' ': case '\r': case '\t': case '\n': case '\f': { /* White space is ignored */ token = tkWS; break; } case '/': { /* C-style comments */ if( zSql[1]!='*' ){ token = tkOTHER; break; } zSql += 2; while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; } if( zSql[0]==0 ) return 0; zSql++; token = tkWS; break; } case '-': { /* SQL-style comments from "--" to end of line */ if( zSql[1]!='-' ){ token = tkOTHER; break; } while( *zSql && *zSql!='\n' ){ zSql++; } if( *zSql==0 ) return state==0; token = tkWS; break; } case '[': { /* Microsoft-style identifiers in [...] */ zSql++; while( *zSql && *zSql!=']' ){ zSql++; } if( *zSql==0 ) return 0; token = tkOTHER; break; } case '`': /* Grave-accent quoted symbols used by MySQL */ case '"': /* single- and double-quoted strings */ case '\'': { int c = *zSql; zSql++; while( *zSql && *zSql!=c ){ zSql++; } if( *zSql==0 ) return 0; token = tkOTHER; break; } default: { int c; if( IdChar((u8)*zSql) ){ /* Keywords and unquoted identifiers */ int nId; for(nId=1; IdChar(zSql[nId]); nId++){} #ifdef SQLITE_OMIT_TRIGGER token = tkOTHER; #else switch( *zSql ){ case 'c': case 'C': { if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){ token = tkCREATE; }else{ token = tkOTHER; } break; } case 't': case 'T': { if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){ token = tkTRIGGER; }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){ token = tkTEMP; }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){ token = tkTEMP; }else{ token = tkOTHER; } break; } case 'e': case 'E': { if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){ token = tkEND; }else #ifndef SQLITE_OMIT_EXPLAIN if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){ token = tkEXPLAIN; }else #endif { token = tkOTHER; } break; } default: { token = tkOTHER; break; } } #endif /* SQLITE_OMIT_TRIGGER */ zSql += nId-1; }else{ /* Operators and special symbols */ token = tkOTHER; } break; } } state = trans[state][token]; zSql++; } return state==0; } #ifndef SQLITE_OMIT_UTF16 /* ** This routine is the same as the sqlite3_complete() routine described ** above, except that the parameter is required to be UTF-16 encoded, not ** UTF-8. */ int sqlite3_complete16(const void *zSql){ sqlite3_value *pVal; char const *zSql8; int rc = 0; pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC); zSql8 = (const char *)sqlite3ValueText(pVal, SQLITE_UTF8); if( zSql8 ){ rc = sqlite3_complete(zSql8); } sqlite3ValueFree(pVal); return rc; } #endif /* SQLITE_OMIT_UTF16 */ #endif /* SQLITE_OMIT_COMPLETE */ } |
Changes to SQLite.Interop/src/date.c.
︙ | ︙ | |||
15 16 17 18 19 20 21 | ** 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. ** | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ** 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.7 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
123 124 125 126 127 128 129 | return cnt; } /* ** Read text from z[] and convert into a floating point number. Return ** the number of digits converted. */ | < < | < < | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | return cnt; } /* ** Read text from z[] and convert into a floating point number. Return ** the number of digits converted. */ #define getValue sqlite3AtoF /* ** Parse a timezone extension on the end of a date-time. ** The extension is of the form: ** ** (+/-)HH:MM ** |
︙ | ︙ | |||
319 320 321 322 323 324 325 | }else if( sqlite3StrICmp(zDate,"now")==0){ double r; sqlite3OsCurrentTime(&r); p->rJD = r; p->validJD = 1; return 0; }else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){ | | | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | }else if( sqlite3StrICmp(zDate,"now")==0){ double r; sqlite3OsCurrentTime(&r); p->rJD = r; p->validJD = 1; return 0; }else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){ getValue(zDate, &p->rJD); p->validJD = 1; return 0; } return 1; } /* |
︙ | ︙ | |||
997 998 999 1000 1001 1002 1003 | for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){ sqlite3_create_function(db, aFuncs[i].zName, 0, SQLITE_UTF8, aFuncs[i].zFormat, currentTimeFunc, 0, 0); } #endif } | | < | 993 994 995 996 997 998 999 1000 | for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){ sqlite3_create_function(db, aFuncs[i].zName, 0, SQLITE_UTF8, aFuncs[i].zFormat, currentTimeFunc, 0, 0); } #endif } } |
Changes to SQLite.Interop/src/delete.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ** 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.7 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
64 65 66 67 68 69 70 | */ void sqlite3OpenTableForReading( Vdbe *v, /* Generate code into this VDBE */ int iCur, /* The cursor number of the table */ Table *pTab /* The table to be opened */ ){ sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); | < > | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | */ void sqlite3OpenTableForReading( Vdbe *v, /* Generate code into this VDBE */ int iCur, /* The cursor number of the table */ Table *pTab /* The table to be opened */ ){ sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); VdbeComment((v, "# %s", pTab->zName)); sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum); sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol); } /* ** Generate code for a DELETE FROM statement. ** |
︙ | ︙ | |||
239 240 241 242 243 244 245 | */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); if( pWInfo==0 ) goto delete_from_cleanup; /* Remember the rowid of every item to be deleted. */ sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); | | < | | | | 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 | */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); if( pWInfo==0 ) goto delete_from_cleanup; /* Remember the rowid of every item to be deleted. */ sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0); if( db->flags & SQLITE_CountRows ){ sqlite3VdbeAddOp(v, OP_AddImm, 1, 0); } /* End the database scan loop. */ sqlite3WhereEnd(pWInfo); /* Open the pseudo-table used to store OLD if there are triggers. */ if( triggers_exist ){ sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol); } /* Delete every item whose key was written to the list during the ** database scan. We have to delete items after the scan is complete ** because deleting an item can change the scan order. */ end = sqlite3VdbeMakeLabel(v); /* This is the beginning of the delete loop when there are ** row triggers. */ if( triggers_exist ){ addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end); if( !isView ){ sqlite3VdbeAddOp(v, OP_Dup, 0, 0); sqlite3OpenTableForReading(v, iCur, pTab); } sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0); sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); sqlite3VdbeAddOp(v, OP_RowData, iCur, 0); sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0); if( !isView ){ sqlite3VdbeAddOp(v, OP_Close, iCur, 0); } (void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_BEFORE, pTab, -1, oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default, addr); } if( !isView ){ /* Open cursors for the table we are deleting from and all its ** indices. If there are row triggers, this happens inside the ** OP_FifoRead loop because the cursor have to all be closed ** before the trigger fires. If there are no row triggers, the ** cursors are opened only once on the outside the loop. */ sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite); /* This is the beginning of the delete loop when there are no ** row triggers */ if( !triggers_exist ){ addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, end); } /* Delete the row */ sqlite3GenerateRowDelete(db, v, pTab, iCur, pParse->nested==0); } /* If there are row triggers, close all cursors then invoke |
︙ | ︙ | |||
321 322 323 324 325 326 327 | oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default, addr); } /* End of the delete loop */ sqlite3VdbeAddOp(v, OP_Goto, 0, addr); sqlite3VdbeResolveLabel(v, end); | < | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default, addr); } /* End of the delete loop */ sqlite3VdbeAddOp(v, OP_Goto, 0, addr); sqlite3VdbeResolveLabel(v, end); /* Close the cursors after the loop if there are no row triggers */ if( !triggers_exist ){ for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){ sqlite3VdbeAddOp(v, OP_Close, iCur + i, pIdx->tnum); } sqlite3VdbeAddOp(v, OP_Close, iCur, 0); |
︙ | ︙ | |||
441 442 443 444 445 446 447 | if( idx==pTab->iPKey ){ sqlite3VdbeAddOp(v, OP_Dup, j, 0); }else{ sqlite3VdbeAddOp(v, OP_Column, iCur, idx); sqlite3ColumnDefault(v, pTab, idx); } } | | | < | 439 440 441 442 443 444 445 446 447 448 449 | if( idx==pTab->iPKey ){ sqlite3VdbeAddOp(v, OP_Dup, j, 0); }else{ sqlite3VdbeAddOp(v, OP_Column, iCur, idx); sqlite3ColumnDefault(v, pTab, idx); } } sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); } } |
Changes to SQLite.Interop/src/expr.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** Return the 'affinity' of the expression pExpr if any. ** |
︙ | ︙ | |||
33 34 35 36 37 38 39 | ** ** CREATE TABLE t1(a); ** SELECT * FROM t1 WHERE a; ** SELECT a AS b FROM t1 WHERE b; ** SELECT * FROM t1 WHERE (select a from t1); */ char sqlite3ExprAffinity(Expr *pExpr){ | > | | > > > > > | | 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 | ** ** CREATE TABLE t1(a); ** SELECT * FROM t1 WHERE a; ** SELECT a AS b FROM t1 WHERE b; ** SELECT * FROM t1 WHERE (select a from t1); */ char sqlite3ExprAffinity(Expr *pExpr){ int op = pExpr->op; if( op==TK_AS ){ return sqlite3ExprAffinity(pExpr->pLeft); } if( op==TK_SELECT ){ return sqlite3ExprAffinity(pExpr->pSelect->pEList->a[0].pExpr); } #ifndef SQLITE_OMIT_CAST if( op==TK_CAST ){ return sqlite3AffinityType(&pExpr->token); } #endif return pExpr->affinity; } /* ** Return the default collation sequence for the expression pExpr. If ** there is no default collation type, return 0. */ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ CollSeq *pColl = 0; if( pExpr ){ pColl = pExpr->pColl; if( (pExpr->op==TK_AS || pExpr->op==TK_CAST) && !pColl ){ return sqlite3ExprCollSeq(pParse, pExpr->pLeft); } } if( sqlite3CheckCollSeq(pParse, pColl) ){ pColl = 0; } return pColl; |
︙ | ︙ | |||
86 87 88 89 90 91 92 93 94 95 96 97 98 99 | /* Neither side of the comparison is a column. Compare the ** results directly. */ /* return SQLITE_AFF_NUMERIC; // Ticket #805 */ return SQLITE_AFF_NONE; }else{ /* One side is a column, the other is not. Use the columns affinity. */ return (aff1 + aff2); } } /* ** pExpr is a comparison operator. Return the type affinity that should ** be applied to both operands prior to doing the comparison. | > | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | /* Neither side of the comparison is a column. Compare the ** results directly. */ /* return SQLITE_AFF_NUMERIC; // Ticket #805 */ return SQLITE_AFF_NONE; }else{ /* One side is a column, the other is not. Use the columns affinity. */ assert( aff1==0 || aff2==0 ); return (aff1 + aff2); } } /* ** pExpr is a comparison operator. Return the type affinity that should ** be applied to both operands prior to doing the comparison. |
︙ | ︙ | |||
206 207 208 209 210 211 212 | } return pNew; } /* ** When doing a nested parse, you can include terms in an expression ** that look like this: #0 #1 #2 ... These terms refer to elements | | | < < > | < | | | < < < | 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 | } return pNew; } /* ** When doing a nested parse, you can include terms in an expression ** that look like this: #0 #1 #2 ... These terms refer to elements ** on the stack. "#0" means the top of the stack. ** "#1" means the next down on the stack. And so forth. ** ** This routine is called by the parser to deal with on of those terms. ** It immediately generates code to store the value in a memory location. ** The returns an expression that will code to extract the value from ** that memory location as needed. */ Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){ Vdbe *v = pParse->pVdbe; Expr *p; int depth; if( pParse->nested==0 ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken); return 0; } if( v==0 ) return 0; p = sqlite3Expr(TK_REGISTER, 0, 0, pToken); if( p==0 ){ return 0; /* Malloc failed */ } depth = atoi((const char *)&pToken->z[1]); p->iTable = pParse->nMem++; sqlite3VdbeAddOp(v, OP_Dup, depth, 0); sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1); return p; } /* ** Join two expressions using an AND operator. If either expression is ** NULL, then just return the other expression. */ |
︙ | ︙ | |||
324 325 326 327 328 329 330 | if( pToken->n==1 ){ /* Wildcard of the form "?". Assign the next variable number */ pExpr->iTable = ++pParse->nVar; }else if( pToken->z[0]=='?' ){ /* Wildcard of the form "?nnn". Convert "nnn" to an integer and ** use it as the variable number */ int i; | | | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | if( pToken->n==1 ){ /* Wildcard of the form "?". Assign the next variable number */ pExpr->iTable = ++pParse->nVar; }else if( pToken->z[0]=='?' ){ /* Wildcard of the form "?nnn". Convert "nnn" to an integer and ** use it as the variable number */ int i; pExpr->iTable = i = atoi((const char *)&pToken->z[1]); if( i<1 || i>SQLITE_MAX_VARIABLE_NUMBER ){ sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", SQLITE_MAX_VARIABLE_NUMBER); } if( i>pParse->nVar ){ pParse->nVar = i; } |
︙ | ︙ | |||
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 | sqlite3ExprDelete(p->pLeft); sqlite3ExprDelete(p->pRight); sqlite3ExprListDelete(p->pList); sqlite3SelectDelete(p->pSelect); sqliteFree(p); } /* ** The following group of routines make deep copies of expressions, ** expression lists, ID lists, and select statements. The copies can ** be deleted (by being passed to their respective ...Delete() routines) ** without effecting the originals. ** ** The expression list, ID, and source lists return by sqlite3ExprListDup(), ** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded ** by subsequent calls to sqlite*ListAppend() routines. ** ** Any tables that the SrcList might point to are not duplicated. */ Expr *sqlite3ExprDup(Expr *p){ Expr *pNew; if( p==0 ) return 0; pNew = (Expr *)sqliteMallocRaw( sizeof(*p) ); if( pNew==0 ) return 0; memcpy(pNew, p, sizeof(*pNew)); if( p->token.z!=0 ){ | > > > > > > > > > > > > > > > | | | 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 | sqlite3ExprDelete(p->pLeft); sqlite3ExprDelete(p->pRight); sqlite3ExprListDelete(p->pList); sqlite3SelectDelete(p->pSelect); sqliteFree(p); } /* ** The Expr.token field might be a string literal that is quoted. ** If so, remove the quotation marks. */ void sqlite3DequoteExpr(Expr *p){ if( ExprHasAnyProperty(p, EP_Dequoted) ){ return; } ExprSetProperty(p, EP_Dequoted); if( p->token.dyn==0 ){ sqlite3TokenCopy(&p->token, &p->token); } sqlite3Dequote((char*)p->token.z); } /* ** The following group of routines make deep copies of expressions, ** expression lists, ID lists, and select statements. The copies can ** be deleted (by being passed to their respective ...Delete() routines) ** without effecting the originals. ** ** The expression list, ID, and source lists return by sqlite3ExprListDup(), ** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded ** by subsequent calls to sqlite*ListAppend() routines. ** ** Any tables that the SrcList might point to are not duplicated. */ Expr *sqlite3ExprDup(Expr *p){ Expr *pNew; if( p==0 ) return 0; pNew = (Expr *)sqliteMallocRaw( sizeof(*p) ); if( pNew==0 ) return 0; memcpy(pNew, p, sizeof(*pNew)); if( p->token.z!=0 ){ pNew->token.z = (const unsigned char *)sqliteStrNDup((const char *)p->token.z, p->token.n); pNew->token.dyn = 1; }else{ assert( pNew->token.z==0 ); } pNew->span.z = 0; pNew->pLeft = sqlite3ExprDup(p->pLeft); pNew->pRight = sqlite3ExprDup(p->pRight); pNew->pList = sqlite3ExprListDup(p->pList); pNew->pSelect = sqlite3SelectDup(p->pSelect); pNew->pTab = p->pTab; return pNew; } void sqlite3TokenCopy(Token *pTo, Token *pFrom){ if( pTo->dyn ) sqliteFree((char*)pTo->z); if( pFrom->z ){ pTo->n = pFrom->n; pTo->z = (const unsigned char *)sqliteStrNDup((const char *)pFrom->z, pFrom->n); pTo->dyn = 1; }else{ pTo->z = 0; } } ExprList *sqlite3ExprListDup(ExprList *p){ ExprList *pNew; |
︙ | ︙ | |||
471 472 473 474 475 476 477 | int nByte; if( p==0 ) return 0; nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0); pNew = (SrcList *)sqliteMallocRaw( nByte ); if( pNew==0 ) return 0; pNew->nSrc = pNew->nAlloc = p->nSrc; for(i=0; i<p->nSrc; i++){ | | | | 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | int nByte; if( p==0 ) return 0; nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0); pNew = (SrcList *)sqliteMallocRaw( nByte ); if( pNew==0 ) return 0; pNew->nSrc = pNew->nAlloc = p->nSrc; for(i=0; i<p->nSrc; i++){ struct SrcList::SrcList_item *pNewItem = &pNew->a[i]; struct SrcList::SrcList_item *pOldItem = &p->a[i]; Table *pTab; pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase); pNewItem->zName = sqliteStrDup(pOldItem->zName); pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias); pNewItem->jointype = pOldItem->jointype; pNewItem->iCursor = pOldItem->iCursor; pTab = pNewItem->pTab = pOldItem->pTab; |
︙ | ︙ | |||
503 504 505 506 507 508 509 | pNew->nId = pNew->nAlloc = p->nId; pNew->a = (IdList::IdList_item *)sqliteMallocRaw( p->nId*sizeof(p->a[0]) ); if( pNew->a==0 ){ sqliteFree(pNew); return 0; } for(i=0; i<p->nId; i++){ | | | | 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | pNew->nId = pNew->nAlloc = p->nId; pNew->a = (IdList::IdList_item *)sqliteMallocRaw( p->nId*sizeof(p->a[0]) ); if( pNew->a==0 ){ sqliteFree(pNew); return 0; } for(i=0; i<p->nId; i++){ struct IdList::IdList_item *pNewItem = &pNew->a[i]; struct IdList::IdList_item *pOldItem = &p->a[i]; pNewItem->zName = sqliteStrDup(pOldItem->zName); pNewItem->idx = pOldItem->idx; } return pNew; } Select *sqlite3SelectDup(Select *p){ Select *pNew; |
︙ | ︙ | |||
528 529 530 531 532 533 534 | 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; | | | 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | pNew->pOrderBy = sqlite3ExprListDup(p->pOrderBy); pNew->op = p->op; pNew->pPrior = sqlite3SelectDup(p->pPrior); pNew->pLimit = sqlite3ExprDup(p->pLimit); pNew->pOffset = sqlite3ExprDup(p->pOffset); pNew->iLimit = -1; pNew->iOffset = -1; pNew->ppOpenVirtual = 0; pNew->isResolved = p->isResolved; pNew->isAgg = p->isAgg; return pNew; } #else Select *sqlite3SelectDup(Select *p){ assert( p==0 ); |
︙ | ︙ | |||
554 555 556 557 558 559 560 | pList = (ExprList *)sqliteMalloc( sizeof(ExprList) ); if( pList==0 ){ goto no_mem; } assert( pList->nAlloc==0 ); } if( pList->nAlloc<=pList->nExpr ){ | | | | | 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 | pList = (ExprList *)sqliteMalloc( sizeof(ExprList) ); if( pList==0 ){ goto no_mem; } assert( pList->nAlloc==0 ); } if( pList->nAlloc<=pList->nExpr ){ struct ExprList::ExprList_item *a; int n = pList->nAlloc*2 + 4; a = (ExprList::ExprList_item *)sqliteRealloc(pList->a, n*sizeof(pList->a[0])); if( a==0 ){ goto no_mem; } pList->a = a; pList->nAlloc = n; } assert( pList->a!=0 ); if( pExpr || pName ){ struct ExprList::ExprList_item *pItem = &pList->a[pList->nExpr++]; memset(pItem, 0, sizeof(*pItem)); pItem->zName = sqlite3NameFromToken(pName); pItem->pExpr = pExpr; } return pList; no_mem: |
︙ | ︙ | |||
663 664 665 666 667 668 669 670 671 672 673 | ** ** After walking the whole tree, if no nodes are found that disqualify ** the expression as constant, then we assume the whole expression ** is constant. See sqlite3ExprIsConstant() for additional information. */ static int exprNodeIsConstant(void *pArg, Expr *pExpr){ switch( pExpr->op ){ case TK_ID: case TK_COLUMN: case TK_DOT: case TK_AGG_FUNCTION: | > > > > > < | > > > > > > > > > > > > > > > | | 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 746 747 748 749 750 751 752 | ** ** After walking the whole tree, if no nodes are found that disqualify ** the expression as constant, then we assume the whole expression ** is constant. See sqlite3ExprIsConstant() for additional information. */ static int exprNodeIsConstant(void *pArg, Expr *pExpr){ switch( pExpr->op ){ /* Consider functions to be constant if all their arguments are constant ** and *pArg==2 */ 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; default: return 0; } } /* ** Walk an expression tree. Return 1 if the expression is constant ** and 0 if it involves variables or function calls. ** ** For the purposes of this function, a double-quoted string (ex: "abc") ** is considered a variable but a single-quoted string (ex: 'abc') is ** a constant. */ int sqlite3ExprIsConstant(Expr *p){ int isConst = 1; walkExprTree(p, exprNodeIsConstant, &isConst); return isConst; } /* ** Walk an expression tree. Return 1 if the expression is constant ** or a function call with constant arguments. Return and 0 if there ** are any variables. ** ** For the purposes of this function, a double-quoted string (ex: "abc") ** is considered a variable but a single-quoted string (ex: 'abc') is ** a constant. */ int sqlite3ExprIsConstantOrFunction(Expr *p){ int isConst = 2; walkExprTree(p, exprNodeIsConstant, &isConst); return isConst!=0; } /* ** If the expression p codes a constant integer that is small enough ** to fit in a 32-bit integer, return 1 and put the value of the integer ** in *pValue. If the expression is not an integer or if it is too big ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged. */ int sqlite3ExprIsInteger(Expr *p, int *pValue){ switch( p->op ){ case TK_INTEGER: { if( sqlite3GetInt32((const char *)p->token.z, pValue) ){ return 1; } break; } case TK_UPLUS: { return sqlite3ExprIsInteger(p->pLeft, pValue); } |
︙ | ︙ | |||
1217 1218 1219 1220 1221 1222 1223 | ** ** The first form is handled by creating a set holding the list ** of allowed values. The second form causes the SELECT to generate ** a temporary table. */ #ifndef SQLITE_OMIT_SUBQUERY void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ | | > > > | > | < > > > < | > | | | | 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 | ** ** The first form is handled by creating a set holding the list ** of allowed values. The second form causes the SELECT to generate ** a temporary table. */ #ifndef SQLITE_OMIT_SUBQUERY void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ int testAddr = 0; /* One-time test address */ Vdbe *v = sqlite3GetVdbe(pParse); if( v==0 ) return; /* This code must be run in its entirety every time it is encountered ** if any of the following is true: ** ** * The right-hand side is a correlated subquery ** * The right-hand side is an expression list containing variables ** * We are inside a trigger ** ** If all of the above are false, then we can run this code just once ** save the results, and reuse the same result on subsequent invocations. */ if( !ExprHasAnyProperty(pExpr, EP_VarSelect) && !pParse->trigStack ){ int mem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemLoad, mem, 0); testAddr = sqlite3VdbeAddOp(v, OP_If, 0, 0); assert( testAddr>0 ); sqlite3VdbeAddOp(v, OP_Integer, 1, 0); sqlite3VdbeAddOp(v, OP_MemStore, mem, 1); } if( pExpr->pSelect ){ sqlite3VdbeAddOp(v, OP_AggContextPush, 0, 0); } switch( pExpr->op ){ case TK_IN: { char affinity; KeyInfo keyInfo; int addr; /* Address of OP_OpenVirtual instruction */ affinity = sqlite3ExprAffinity(pExpr->pLeft); /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)' ** expression it is handled the same way. A virtual table is ** filled with single-field index keys representing the results ** from the SELECT or the <exprlist>. ** ** If the 'x' expression is a column value, or the SELECT... ** statement returns a column value, then the affinity of that ** column is used to build the index keys. If both 'x' and the ** SELECT... statement are columns, then numeric affinity is used ** if either column has NUMERIC or INTEGER affinity. If neither ** 'x' nor the SELECT... statement are columns, then numeric affinity ** is used. */ pExpr->iTable = pParse->nTab++; addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, pExpr->iTable, 0); memset(&keyInfo, 0, sizeof(keyInfo)); keyInfo.nField = 1; sqlite3VdbeAddOp(v, OP_SetNumColumns, pExpr->iTable, 1); if( pExpr->pSelect ){ /* Case 1: expr IN (SELECT ...) ** |
︙ | ︙ | |||
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 | ** ** For each expression, build an index key from the evaluation and ** store it in the temporary table. If <expr> is a column, then use ** that columns affinity when building index keys. If <expr> is not ** a column, use numeric affinity. */ int i; if( !affinity ){ affinity = SQLITE_AFF_NUMERIC; } keyInfo.aColl[0] = pExpr->pLeft->pColl; /* Loop through each expression in <exprlist>. */ | > > > | | | > > > > | | < | > > > > | | | | | | 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 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 | ** ** For each expression, build an index key from the evaluation and ** store it in the temporary table. If <expr> is a column, then use ** that columns affinity when building index keys. If <expr> is not ** a column, use numeric affinity. */ int i; ExprList *pList = pExpr->pList; struct ExprList::ExprList_item *pItem; if( !affinity ){ affinity = SQLITE_AFF_NUMERIC; } keyInfo.aColl[0] = pExpr->pLeft->pColl; /* Loop through each expression in <exprlist>. */ for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){ Expr *pE2 = pItem->pExpr; /* If the expression is not constant then we will need to ** disable the test that was generated above that makes sure ** this code only executes once. Because for a non-constant ** expression we need to rerun this code each time. */ if( testAddr>0 && !sqlite3ExprIsConstant(pE2) ){ VdbeOp *aOp = sqlite3VdbeGetOp(v, testAddr-1); int i; for(i=0; i<4; i++){ aOp[i].opcode = OP_Noop; } testAddr = 0; } /* Evaluate the expression and insert it into the temp table */ sqlite3ExprCode(pParse, pE2); sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &affinity, 1); sqlite3VdbeAddOp(v, OP_IdxInsert, pExpr->iTable, 0); } } sqlite3VdbeChangeP3(v, addr, (const char *)(void *)&keyInfo, P3_KEYINFO); break; } case TK_EXISTS: case TK_SELECT: { /* This has to be a scalar SELECT. Generate code to put the ** value of this select in a memory cell and record the number ** of the memory cell in iColumn. */ int sop; Select *pSel; pExpr->iColumn = pParse->nMem++; pSel = pExpr->pSelect; if( pExpr->op==TK_SELECT ){ sop = SRT_Mem; }else{ static const Token one = { (unsigned char *)"1", 0, 1 }; sop = SRT_Exists; sqlite3ExprListDelete(pSel->pEList); pSel->pEList = sqlite3ExprListAppend(0, sqlite3Expr(TK_INTEGER, 0, 0, &one), 0); } sqlite3Select(pParse, pSel, sop, pExpr->iColumn, 0, 0, 0, 0); break; } } if( pExpr->pSelect ){ sqlite3VdbeAddOp(v, OP_AggContextPop, 0, 0); } if( testAddr ){ sqlite3VdbeChangeP2(v, testAddr, sqlite3VdbeCurrentAddr(v)); } return; } #endif /* SQLITE_OMIT_SUBQUERY */ /* ** Generate an instruction that will put the integer describe by ** text z[0..n-1] on the stack. */ static void codeInteger(Vdbe *v, const char *z, int n){ int i; if( sqlite3GetInt32(z, &i) ){ sqlite3VdbeAddOp(v, OP_Integer, i, 0); }else if( sqlite3FitsIn64Bits(z) ){ sqlite3VdbeOp3(v, OP_Int64, 0, 0, z, n); }else{ sqlite3VdbeOp3(v, OP_Real, 0, 0, z, n); } } /* ** Generate code into the current Vdbe to evaluate the given |
︙ | ︙ | |||
1397 1398 1399 1400 1401 1402 1403 | sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn); }else{ sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0); } break; } case TK_INTEGER: { | | > | < | < | > > > > > > > > > > > > > > > > | 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 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 | sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn); }else{ sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0); } break; } case TK_INTEGER: { codeInteger(v, (const char *)pExpr->token.z, pExpr->token.n); break; } case TK_FLOAT: case TK_STRING: { assert( TK_FLOAT==OP_Real ); assert( TK_STRING==OP_String8 ); sqlite3DequoteExpr(pExpr); sqlite3VdbeOp3(v, op, 0, 0, (const char *)pExpr->token.z, pExpr->token.n); break; } case TK_NULL: { sqlite3VdbeAddOp(v, OP_Null, 0, 0); break; } #ifndef SQLITE_OMIT_BLOB_LITERAL case TK_BLOB: { assert( TK_BLOB==OP_HexBlob ); sqlite3VdbeOp3(v, op, 0, 0, (const char *)pExpr->token.z+2, pExpr->token.n-3); break; } #endif case TK_VARIABLE: { sqlite3VdbeAddOp(v, OP_Variable, pExpr->iTable, 0); if( pExpr->token.n>1 ){ sqlite3VdbeChangeP3(v, -1, (const char *)pExpr->token.z, pExpr->token.n); } break; } case TK_REGISTER: { sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iTable, 0); break; } #ifndef SQLITE_OMIT_CAST case TK_CAST: { /* Expressions of the form: CAST(pLeft AS token) */ int aff, op; sqlite3ExprCode(pParse, pExpr->pLeft); aff = sqlite3AffinityType(&pExpr->token); switch( aff ){ case SQLITE_AFF_INTEGER: op = OP_ToInt; break; case SQLITE_AFF_NUMERIC: op = OP_ToNumeric; break; case SQLITE_AFF_TEXT: op = OP_ToText; break; case SQLITE_AFF_NONE: op = OP_ToBlob; break; } sqlite3VdbeAddOp(v, op, 0, 0); break; } #endif /* SQLITE_OMIT_CAST */ case TK_LT: case TK_LE: case TK_GT: case TK_GE: case TK_NE: case TK_EQ: { assert( TK_LT==OP_Lt ); |
︙ | ︙ | |||
1662 1663 1664 1665 1666 1667 1668 1669 | "RAISE() may only be used within a trigger-program"); return; } if( pExpr->iColumn!=OE_Ignore ){ assert( pExpr->iColumn==OE_Rollback || pExpr->iColumn == OE_Abort || pExpr->iColumn == OE_Fail ); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn, | > | | | 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 | "RAISE() may only be used within a trigger-program"); return; } if( pExpr->iColumn!=OE_Ignore ){ assert( pExpr->iColumn==OE_Rollback || pExpr->iColumn == OE_Abort || pExpr->iColumn == OE_Fail ); sqlite3DequoteExpr(pExpr); sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, pExpr->iColumn, (const char *)pExpr->token.z, pExpr->token.n); // sqlite3VdbeDequoteP3(v, -1); } else { assert( pExpr->iColumn == OE_Ignore ); sqlite3VdbeAddOp(v, OP_ContextPop, 0, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, pParse->trigStack->ignoreJump); VdbeComment((v, "# raise(IGNORE)")); } } |
︙ | ︙ | |||
1716 1717 1718 1719 1720 1721 1722 | */ int sqlite3ExprCodeExprList( Parse *pParse, /* Parsing context */ ExprList *pList /* The expression list to be coded */ ){ struct ExprList::ExprList_item *pItem; int i, n; | < < | | 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 | */ int sqlite3ExprCodeExprList( Parse *pParse, /* Parsing context */ ExprList *pList /* The expression list to be coded */ ){ struct ExprList::ExprList_item *pItem; int i, n; if( pList==0 ) return 0; n = pList->nExpr; for(pItem=pList->a, i=n; i>0; i--, pItem++){ sqlite3ExprCode(pParse, pItem->pExpr); } return n; } /* ** Generate code for a boolean expression such that a jump is made |
︙ | ︙ | |||
1958 1959 1960 1961 1962 1963 1964 | return 0; } if( pA->pSelect || pB->pSelect ) return 0; if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 0; if( pA->token.z ){ if( pB->token.z==0 ) return 0; if( pB->token.n!=pA->token.n ) return 0; | | | 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 | return 0; } if( pA->pSelect || pB->pSelect ) return 0; if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 0; if( pA->token.z ){ if( pB->token.z==0 ) return 0; if( pB->token.n!=pA->token.n ) return 0; if( sqlite3StrNICmp((const char *)pA->token.z, (const char *)pB->token.z, pB->token.n)!=0 ) return 0; } return 1; } /* ** Add a new element to the pParse->aAgg[] array and return its index. ** The new element is initialized to zero. The calling function is |
︙ | ︙ | |||
2036 2037 2038 2039 2040 2041 2042 | if( i>=pParse->nAgg ){ u8 enc = pParse->db->enc; i = appendAggInfo(pParse); if( i<0 ) return 1; pParse->aAgg[i].isAgg = 1; pParse->aAgg[i].pExpr = pExpr; pParse->aAgg[i].pFunc = sqlite3FindFunction(pParse->db, | | | 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 | if( i>=pParse->nAgg ){ u8 enc = pParse->db->enc; i = appendAggInfo(pParse); if( i<0 ) return 1; pParse->aAgg[i].isAgg = 1; pParse->aAgg[i].pExpr = pExpr; pParse->aAgg[i].pFunc = sqlite3FindFunction(pParse->db, (const char *)pExpr->token.z, pExpr->token.n, pExpr->pList ? pExpr->pList->nExpr : 0, enc, 0); } pExpr->iAgg = i; return 1; } } } |
︙ | ︙ | |||
2068 2069 2070 2071 2072 2073 2074 | ** the number of errors. */ int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ int nErr = pNC->pParse->nErr; walkExprTree(pExpr, analyzeAggregate, pNC); return pNC->pParse->nErr - nErr; } | | < | 2134 2135 2136 2137 2138 2139 2140 2141 | ** the number of errors. */ int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){ int nErr = pNC->pParse->nErr; walkExprTree(pExpr, analyzeAggregate, pNC); return pNC->pParse->nErr - nErr; } } |
Changes to SQLite.Interop/src/func.c.
︙ | ︙ | |||
15 16 17 18 19 20 21 | ** 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. ** | | > > > | 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 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include <ctype.h> #include <math.h> #include <stdlib.h> #include <assert.h> #include "vdbeInt.h" #include "os.h" /* ** Return the collating function associated with a function. */ static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){ return context->pColl; } /* ** Implementation of the non-aggregate min() and max() functions */ |
︙ | ︙ | |||
76 77 78 79 80 81 82 83 84 85 86 87 88 89 | case SQLITE_INTEGER: z = "integer"; break; case SQLITE_TEXT: z = "text"; break; case SQLITE_FLOAT: z = "real"; break; case SQLITE_BLOB: z = "blob"; break; } sqlite3_result_text(context, z, -1, SQLITE_STATIC); } /* ** Implementation of the length() function */ static void lengthFunc( sqlite3_context *context, int argc, | > | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | case SQLITE_INTEGER: z = "integer"; break; case SQLITE_TEXT: z = "text"; break; case SQLITE_FLOAT: z = "real"; break; case SQLITE_BLOB: z = "blob"; break; } sqlite3_result_text(context, z, -1, SQLITE_STATIC); } /* ** Implementation of the length() function */ static void lengthFunc( sqlite3_context *context, int argc, |
︙ | ︙ | |||
182 183 184 185 186 187 188 | /* ** Implementation of the round() function */ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; | | | | | | | | 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 | /* ** Implementation of the round() function */ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; char zBuf[500]; /* larger than the %f representation of the largest double */ assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; n = sqlite3_value_int(argv[1]); if( n>30 ) n = 30; if( n<0 ) n = 0; } if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; r = sqlite3_value_double(argv[0]); sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r); sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } /* ** Implementation of the upper() and lower() SQL functions. */ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ unsigned char *z; int i; if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; z = (unsigned char *)sqliteMalloc(sqlite3_value_bytes(argv[0])+1); if( z==0 ) return; strcpy((char *)z, (const char *)sqlite3_value_text(argv[0])); for(i=0; z[i]; i++){ z[i] = toupper(z[i]); } sqlite3_result_text(context, (const char *)z, -1, SQLITE_TRANSIENT); sqliteFree(z); } static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ unsigned char *z; int i; if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; z = (unsigned char *)sqliteMalloc(sqlite3_value_bytes(argv[0])+1); if( z==0 ) return; strcpy((char *)z, (const char *)sqlite3_value_text(argv[0])); for(i=0; z[i]; i++){ z[i] = tolower(z[i]); } sqlite3_result_text(context, (const char *)z, -1, SQLITE_TRANSIENT); sqliteFree(z); } /* ** Implementation of the IFNULL(), NVL(), and COALESCE() functions. ** All three do the same thing. They return the first non-NULL ** argument. |
︙ | ︙ | |||
306 307 308 309 310 311 312 313 | */ struct compareInfo { u8 matchAll; u8 matchOne; u8 matchSet; u8 noCase; }; static const struct compareInfo globInfo = { '*', '?', '[', 0 }; | > > > > > > | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | */ struct compareInfo { u8 matchAll; u8 matchOne; u8 matchSet; u8 noCase; }; static const struct compareInfo globInfo = { '*', '?', '[', 0 }; /* The correct SQL-92 behavior is for the LIKE operator to ignore ** case. Thus 'a' LIKE 'A' would be true. */ static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 }; /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator ** is case sensitive causing 'a' LIKE 'A' to be false */ static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }; /* ** X is a pointer to the first byte of a UTF-8 character. Increment ** X so that it points to the next character. This only works right ** if X points to a well-formed UTF-8 string. */ #define sqliteNextChar(X) while( (0xc0&*++(X))==0x80 ){} |
︙ | ︙ | |||
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | zString++; prevEscape = 0; } } return *zString==0; } /* ** Implementation of the like() SQL function. This function implements ** the build-in LIKE operator. The first argument to the function is the ** pattern and the second argument is the string. So, the SQL statements: ** ** A LIKE B ** ** is implemented as like(B,A). ** | > > > > > > > > > | | | | < < | < < < < < < < < < < | < | | | 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 | zString++; prevEscape = 0; } } return *zString==0; } /* ** Count the number of times that the LIKE operator (or GLOB which is ** just a variation of LIKE) gets called. This is used for testing ** only. */ #ifdef SQLITE_TEST int sqlite3_like_count = 0; #endif /* ** Implementation of the like() SQL function. This function implements ** the build-in LIKE operator. The first argument to the function is the ** pattern and the second argument is the string. So, the SQL statements: ** ** A LIKE B ** ** is implemented as like(B,A). ** ** This same function (with a different compareInfo structure) computes ** the GLOB operator. */ static void likeFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ const unsigned char *zA = sqlite3_value_text(argv[0]); const unsigned char *zB = sqlite3_value_text(argv[1]); int escape = 0; if( argc==3 ){ /* The escape character string must consist of a single UTF-8 character. ** Otherwise, return an error. */ const unsigned char *zEsc = sqlite3_value_text(argv[2]); if( sqlite3utf8CharLen((const char *)zEsc, -1)!=1 ){ sqlite3_result_error(context, "ESCAPE expression must be a single character", -1); return; } escape = sqlite3ReadUtf8(zEsc); } if( zA && zB ){ struct compareInfo *pInfo = (compareInfo *)sqlite3_user_data(context); #ifdef SQLITE_TEST sqlite3_like_count++; #endif sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape)); } } /* ** Implementation of the NULLIF(x,y) function. The result is the first ** argument if the arguments are different. The result is NULL if the ** arguments are equal to each other. |
︙ | ︙ | |||
961 962 963 964 965 966 967 | { "upper", 1, 0, SQLITE_UTF8, 0, upperFunc }, { "lower", 1, 0, SQLITE_UTF8, 0, lowerFunc }, { "coalesce", -1, 0, SQLITE_UTF8, 0, ifnullFunc }, { "coalesce", 0, 0, SQLITE_UTF8, 0, 0 }, { "coalesce", 1, 0, SQLITE_UTF8, 0, 0 }, { "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc }, { "random", -1, 0, SQLITE_UTF8, 0, randomFunc }, | < < < | 967 968 969 970 971 972 973 974 975 976 977 978 979 980 | { "upper", 1, 0, SQLITE_UTF8, 0, upperFunc }, { "lower", 1, 0, SQLITE_UTF8, 0, lowerFunc }, { "coalesce", -1, 0, SQLITE_UTF8, 0, ifnullFunc }, { "coalesce", 0, 0, SQLITE_UTF8, 0, 0 }, { "coalesce", 1, 0, SQLITE_UTF8, 0, 0 }, { "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc }, { "random", -1, 0, SQLITE_UTF8, 0, randomFunc }, { "nullif", 2, 0, SQLITE_UTF8, 1, nullifFunc }, { "sqlite_version", 0, 0, SQLITE_UTF8, 0, versionFunc}, { "quote", 1, 0, SQLITE_UTF8, 0, quoteFunc }, { "last_insert_rowid", 0, 1, SQLITE_UTF8, 0, last_insert_rowid }, { "changes", 0, 1, SQLITE_UTF8, 0, changes }, { "total_changes", 0, 1, SQLITE_UTF8, 0, total_changes }, #ifdef SQLITE_SOUNDEX |
︙ | ︙ | |||
1035 1036 1037 1038 1039 1040 1041 | if( pFunc && aAggs[i].needCollSeq ){ pFunc->needCollSeq = 1; } } } sqlite3RegisterDateTimeFunctions(db); #ifdef SQLITE_SSE | > > > > > > > > | > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > | > > | > > > > | > > > > > > > > > > > > > | 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 | if( pFunc && aAggs[i].needCollSeq ){ pFunc->needCollSeq = 1; } } } sqlite3RegisterDateTimeFunctions(db); #ifdef SQLITE_SSE sqlite3SseFunctions(db); #endif #ifdef SQLITE_CASE_SENSITIVE_LIKE sqlite3RegisterLikeFunctions(db, 1); #else sqlite3RegisterLikeFunctions(db, 0); #endif } /* ** Set the LIKEOPT flag on the 2-argument function with the given name. */ static void setLikeOptFlag(sqlite3 *db, const char *zName){ FuncDef *pDef; pDef = sqlite3FindFunction(db, zName, strlen(zName), 2, SQLITE_UTF8, 0); if( pDef ){ pDef->flags = SQLITE_FUNC_LIKEOPT; } } /* ** Register the built-in LIKE and GLOB functions. The caseSensitive ** parameter determines whether or not the LIKE operator is case ** sensitive. GLOB is always case sensitive. */ 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"); if( caseSensitive ){ setLikeOptFlag(db, "like"); } } /* ** pExpr points to an expression which implements a function. If ** it is appropriate to apply the LIKE optimization to that function ** then set aWc[0] through aWc[2] to the wildcard characters and ** return TRUE. If the function is not a LIKE-style function then ** return FALSE. */ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, char *aWc){ FuncDef *pDef; if( pExpr->op!=TK_FUNCTION ){ return 0; } if( pExpr->pList->nExpr!=2 ){ return 0; } pDef = sqlite3FindFunction(db, (const char *)pExpr->token.z, pExpr->token.n, 2, SQLITE_UTF8, 0); if( pDef==0 || (pDef->flags & SQLITE_FUNC_LIKEOPT)==0 ){ return 0; } /* The memcpy() statement assumes that the wildcard characters are ** the first three statements in the compareInfo structure. The ** asserts() that follow verify that assumption */ memcpy(aWc, pDef->pUserData, 3); assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll ); assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne ); assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet ); return 1; } } |
Changes to SQLite.Interop/src/hash.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include <assert.h> /* Turn bulk memory into a hash table object by initializing the ** fields of the Hash structure. ** |
︙ | ︙ | |||
384 385 386 387 388 389 390 | assert( pH->htsize>0 ); assert( (pH->htsize & (pH->htsize-1))==0 ); h = hraw & (pH->htsize-1); insertElement(pH, &pH->ht[h], new_elem); new_elem->data = data; return 0; } | | < | 384 385 386 387 388 389 390 391 | assert( pH->htsize>0 ); assert( (pH->htsize & (pH->htsize-1))==0 ); h = hraw & (pH->htsize-1); insertElement(pH, &pH->ht[h], new_elem); new_elem->data = data; return 0; } } |
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.7 2005/08/22 18:22:12 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.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ** 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.7 2005/08/22 18:22:12 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: |
︙ | ︙ | |||
372 373 374 375 376 377 378 | sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* The following code runs first because the GOTO at the very top ** of the program jumps to it. Create the temporary table, then jump ** back up and execute the SELECT code above. */ sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v)); | | | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | sqlite3VdbeAddOp(v, OP_Return, 0, 0); /* The following code runs first because the GOTO at the very top ** of the program jumps to it. Create the temporary table, then jump ** back up and execute the SELECT code above. */ sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v)); sqlite3VdbeAddOp(v, OP_OpenVirtual, srcTab, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn); sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop); sqlite3VdbeResolveLabel(v, iCleanup); }else{ sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v)); } }else{ |
︙ | ︙ | |||
948 949 950 951 952 953 954 | int idx = pIdx->aiColumn[i]; if( idx==pTab->iPKey ){ sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol+1, 1); }else{ sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1); } } | | | 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | int idx = pIdx->aiColumn[i]; if( idx==pTab->iPKey ){ sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol+1, 1); }else{ sqlite3VdbeAddOp(v, OP_Dup, i+extra+nCol-idx, 1); } } jumpInst1 = sqlite3VdbeAddOp(v, OP_MakeIdxRec, pIdx->nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); /* Find out what action to take in case there is an indexing conflict */ onError = pIdx->onError; if( onError==OE_None ) continue; /* pIdx is not a UNIQUE index */ if( overrideError!=OE_Default ){ onError = overrideError; |
︙ | ︙ | |||
1018 1019 1020 1021 1022 1023 1024 | sqlite3VdbeAddOp(v, OP_MoveGe, base, 0); } seenReplace = 1; break; } } contAddr = sqlite3VdbeCurrentAddr(v); | < | | 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | sqlite3VdbeAddOp(v, OP_MoveGe, base, 0); } seenReplace = 1; break; } } contAddr = sqlite3VdbeCurrentAddr(v); #if NULL_DISTINCT_FOR_UNIQUE sqlite3VdbeChangeP2(v, jumpInst1, contAddr); #endif sqlite3VdbeChangeP2(v, jumpInst2, contAddr); } } /* ** This routine generates code to finish the INSERT or UPDATE operation |
︙ | ︙ | |||
1096 1097 1098 1099 1100 1101 1102 | int op /* OP_OpenRead or OP_OpenWrite */ ){ int i; Index *pIdx; Vdbe *v = sqlite3GetVdbe(pParse); assert( v!=0 ); sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); | < > > | < | 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | int op /* OP_OpenRead or OP_OpenWrite */ ){ int i; Index *pIdx; Vdbe *v = sqlite3GetVdbe(pParse); assert( v!=0 ); sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); VdbeComment((v, "# %s", pTab->zName)); sqlite3VdbeAddOp(v, op, base, pTab->tnum); sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol); for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0); VdbeComment((v, "# %s", pIdx->zName)); sqlite3VdbeOp3(v, op, i+base, pIdx->tnum, (char*)&pIdx->keyInfo, P3_KEYINFO); } if( pParse->nTab<=base+i ){ pParse->nTab = base+i; } } } |
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: 156 */ static int keywordCode(const char *z, int n){ static const char zText[526] = "ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER" "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYANALYZE" "XCLUSIVEXISTSTATEMENTANDEFERRABLEATTACHAVINGLOBEFOREIGNOREINDEX" "AUTOINCREMENTBEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETE" "CASECASTCOLLATECOLUMNCOMMITCONFLICTCONSTRAINTERSECTCREATECROSS" "CURRENT_DATECURRENT_TIMESTAMPRAGMATCHDESCDETACHDISTINCTDROPRIMARY" "FAILIMITFROMFULLGROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULL" "JOINORDEREPLACEOUTERESTRICTRIGHTROLLBACKROWHENUNIONUNIQUEUSING" "VACUUMVALUESVIEWHERE"; static const unsigned char aHash[127] = { 91, 81, 104, 90, 0, 4, 0, 0, 111, 0, 77, 0, 0, 94, 44, 0, 92, 0, 103, 106, 96, 0, 0, 10, 0, 0, 110, 0, 107, 102, 0, 28, 48, 0, 41, 0, 0, 65, 71, 0, 63, 19, 0, 0, 36, 83, 0, 105, 74, 0, 0, 33, 0, 61, 37, 0, 8, 0, 112, 38, 12, 0, 78, 40, 25, 66, 0, 0, 31, 82, 53, 30, 50, 20, 88, 0, 34, 0, 75, 26, 0, 72, 0, 0, 0, 64, 47, 67, 22, 87, 29, 69, 86, 0, 1, 0, 9, 100, 58, 18, 0, 109, 76, 98, 54, 6, 85, 0, 0, 49, 93, 0, 101, 0, 70, 0, 0, 15, 0, 113, 51, 56, 0, 2, 55, 0, 108, }; static const unsigned char aNext[113] = { 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 5, 13, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 16, 0, 23, 52, 0, 0, 0, 0, 45, 0, 59, 0, 0, 0, 0, 0, 0, 0, 0, 73, 42, 0, 0, 24, 60, 21, 0, 80, 32, 68, 0, 0, 84, 46, 0, 0, 0, 0, 0, 0, 0, 39, 95, 97, 0, 0, 99, 0, 14, 27, 79, 0, 57, 89, 0, 35, 0, 62, 0, }; static const unsigned char aLen[113] = { 5, 5, 4, 4, 9, 2, 3, 8, 2, 6, 4, 3, 7, 11, 2, 7, 5, 5, 4, 5, 3, 5, 10, 6, 4, 6, 7, 6, 7, 9, 3, 7, 9, 6, 9, 3, 10, 6, 6, 4, 6, 3, 7, 6, 7, 5, 13, 2, 2, 5, 5, 6, 7, 3, 7, 4, 4, 2, 7, 3, 8, 6, 4, 4, 7, 6, 6, 8, 10, 9, 6, 5, 12, 12, 17, 6, 5, 4, 6, 8, 2, 4, 7, 4, 5, 4, 4, 5, 6, 9, 6, 7, 4, 2, 6, 3, 6, 4, 5, 7, 5, 8, 5, 8, 3, 4, 5, 6, 5, 6, 6, 4, 5, }; static const unsigned short int aOffset[113] = { 0, 4, 7, 10, 10, 14, 19, 21, 26, 27, 32, 34, 36, 42, 51, 52, 57, 61, 65, 67, 71, 74, 78, 86, 91, 94, 99, 105, 108, 113, 118, 122, 128, 136, 141, 150, 152, 162, 167, 172, 175, 177, 177, 181, 185, 187, 192, 194, 196, 205, 208, 212, 218, 224, 224, 227, 230, 234, 236, 237, 241, 248, 254, 258, 262, 269, 275, 281, 289, 296, 305, 311, 316, 328, 328, 344, 348, 353, 357, 363, 364, 371, 374, 381, 384, 389, 393, 397, 400, 406, 415, 421, 428, 431, 431, 434, 437, 443, 447, 451, 458, 462, 470, 475, 483, 485, 489, 494, 500, 505, 511, 517, 520, }; static const unsigned char aCode[113] = { TK_ABORT, TK_TABLE, TK_JOIN_KW, TK_TEMP, TK_TEMP, TK_OR, TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_THEN, TK_END, TK_DEFAULT, TK_TRANSACTION,TK_ON, TK_JOIN_KW, TK_ALTER, TK_RAISE, TK_EACH, TK_CHECK, TK_KEY, TK_AFTER, TK_REFERENCES, TK_ESCAPE, TK_ELSE, TK_EXCEPT, TK_TRIGGER, TK_LIKE_KW, TK_EXPLAIN, TK_INITIALLY, TK_ALL, TK_ANALYZE, TK_EXCLUSIVE, TK_EXISTS, TK_STATEMENT, TK_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_PRAGMA, TK_MATCH, TK_DESC, TK_DETACH, TK_DISTINCT, TK_IS, TK_DROP, TK_PRIMARY, TK_FAIL, TK_LIMIT, TK_FROM, TK_JOIN_KW, TK_GROUP, TK_UPDATE, TK_IMMEDIATE, TK_INSERT, TK_INSTEAD, TK_INTO, TK_OF, TK_OFFSET, TK_SET, TK_ISNULL, TK_JOIN, TK_ORDER, TK_REPLACE, TK_JOIN_KW, TK_RESTRICT, TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_WHEN, TK_UNION, TK_UNIQUE, TK_USING, TK_VACUUM, TK_VALUES, TK_VIEW, TK_WHERE, }; int h, i; if( n<2 ) return TK_ID; h = ((sqlite3UpperToLower[((unsigned char*)z)[0]]*4) ^ (sqlite3UpperToLower[((unsigned char*)z)[n-1]]*3) ^ n) % 127; for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){ |
︙ | ︙ |
Changes to SQLite.Interop/src/legacy.c.
︙ | ︙ | |||
13 14 15 16 17 18 19 | ** ************************************************************************* ** 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. ** | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ** ************************************************************************* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* |
︙ | ︙ | |||
135 136 137 138 139 140 141 | } }else if( pzErrMsg ){ *pzErrMsg = 0; } return rc; } | | < | 135 136 137 138 139 140 141 142 | } }else if( pzErrMsg ){ *pzErrMsg = 0; } return rc; } } |
Changes to SQLite.Interop/src/main.c.
︙ | ︙ | |||
13 14 15 16 17 18 19 | ** ************************************************************************* ** 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. ** | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ** ************************************************************************* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** The following constant value is used by the SQLITE_BIGENDIAN and |
︙ | ︙ | |||
233 234 235 236 237 238 239 | const char *sqlite3ErrStr(int rc){ const char *z; switch( rc ){ case SQLITE_ROW: case SQLITE_DONE: case SQLITE_OK: z = "not an error"; break; case SQLITE_ERROR: z = "SQL logic error or missing database"; break; | < < | < | 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 | const char *sqlite3ErrStr(int rc){ const char *z; switch( rc ){ case SQLITE_ROW: case SQLITE_DONE: case SQLITE_OK: z = "not an error"; break; case SQLITE_ERROR: z = "SQL logic error or missing database"; break; case SQLITE_PERM: z = "access permission denied"; break; case SQLITE_ABORT: z = "callback requested query abort"; break; case SQLITE_BUSY: z = "database is locked"; break; case SQLITE_LOCKED: z = "database table is locked"; break; case SQLITE_NOMEM: z = "out of memory"; break; case SQLITE_READONLY: z = "attempt to write a readonly database"; break; case SQLITE_INTERRUPT: z = "interrupted"; break; case SQLITE_IOERR: z = "disk I/O error"; break; case SQLITE_CORRUPT: z = "database disk image is malformed"; break; case SQLITE_FULL: z = "database or disk is full"; break; case SQLITE_CANTOPEN: z = "unable to open database file"; break; case SQLITE_PROTOCOL: z = "database locking protocol failure"; break; case SQLITE_EMPTY: z = "table contains no data"; break; case SQLITE_SCHEMA: z = "database schema has changed"; break; case SQLITE_CONSTRAINT: z = "constraint failed"; break; case SQLITE_MISMATCH: z = "datatype mismatch"; break; case SQLITE_MISUSE: z = "library routine called out of sequence";break; case SQLITE_NOLFS: z = "kernel lacks large file support"; break; case SQLITE_AUTH: z = "authorization denied"; break; case SQLITE_FORMAT: z = "auxiliary database format error"; break; case SQLITE_RANGE: z = "bind or column index out of range"; break; |
︙ | ︙ | |||
297 298 299 300 301 302 303 | if( prior + delay > timeout ){ delay = timeout - prior; if( delay<=0 ) return 0; } sqlite3OsSleep(delay); return 1; #else | | > > > > > > > > > > > > > > > > > > > > | 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 | if( prior + delay > timeout ){ delay = timeout - prior; if( delay<=0 ) return 0; } sqlite3OsSleep(delay); return 1; #else int timeout = ((sqlite3 *)ptr)->busyTimeout; if( (count+1)*1000 > timeout ){ return 0; } sqlite3OsSleep(1000); return 1; #endif } /* ** Invoke the given busy handler. ** ** This routine is called when an operation failed with a lock. ** If this routine returns non-zero, the lock is retried. If it ** returns 0, the operation aborts with an SQLITE_BUSY error. */ int sqlite3InvokeBusyHandler(BusyHandler *p){ int rc; if( p==0 || p->xFunc==0 || p->nBusy<0 ) return 0; rc = p->xFunc(p->pArg, p->nBusy); if( rc==0 ){ p->nBusy = -1; }else{ p->nBusy++; } return rc; } /* ** This routine sets the busy callback for an Sqlite database to the ** given callback function with the given argument. */ int sqlite3_busy_handler( sqlite3 *db, int (*xBusy)(void*,int), void *pArg ){ if( sqlite3SafetyCheck(db) ){ return SQLITE_MISUSE; } db->busyHandler.xFunc = xBusy; db->busyHandler.pArg = pArg; db->busyHandler.nBusy = 0; return SQLITE_OK; } #ifndef SQLITE_OMIT_PROGRESS_CALLBACK /* ** This routine sets the progress callback for an Sqlite database to the ** given callback function with the given argument. The progress callback will |
︙ | ︙ | |||
453 454 455 456 457 458 459 460 461 462 463 464 465 466 | }else{ sqlite3ExpirePreparedStatements(db); } } p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1); if( p==0 ) return SQLITE_NOMEM; p->xFunc = xFunc; p->xStep = xStep; p->xFinalize = xFinal; p->pUserData = pUserData; return SQLITE_OK; } #ifndef SQLITE_OMIT_UTF16 | > | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | }else{ sqlite3ExpirePreparedStatements(db); } } p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1); if( p==0 ) return SQLITE_NOMEM; p->flags = 0; p->xFunc = xFunc; p->xStep = xStep; p->xFinalize = xFinal; p->pUserData = pUserData; return SQLITE_OK; } #ifndef SQLITE_OMIT_UTF16 |
︙ | ︙ | |||
529 530 531 532 533 534 535 | /* ** This routine is called to create a connection to a database BTree ** driver. If zFilename is the name of a file, then that file is ** opened and used. If zFilename is the magic name ":memory:" then ** the database is stored in memory (and is thus forgotten as soon as ** the connection is closed.) If zFilename is NULL then the database | | | | | | 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | /* ** This routine is called to create a connection to a database BTree ** driver. If zFilename is the name of a file, then that file is ** opened and used. If zFilename is the magic name ":memory:" then ** the database is stored in memory (and is thus forgotten as soon as ** the connection is closed.) If zFilename is NULL then the database ** is a "virtual" database for transient use only and is deleted as ** soon as the connection is closed. ** ** A virtual database can be either a disk file (that is automatically ** deleted when the file is closed) or it an be held entirely in memory, ** depending on the values of the TEMP_STORE compile-time macro and the ** db->temp_store variable, according to the following chart: ** ** TEMP_STORE db->temp_store Location of temporary database ** ---------- -------------- ------------------------------ ** 0 any file ** 1 1 file |
︙ | ︙ | |||
1000 1001 1002 1003 1004 1005 1006 | ** 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; } | | < | 1018 1019 1020 1021 1022 1023 1024 1025 | ** 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; } } |
Changes to SQLite.Interop/src/opcodes.c.
1 2 3 4 5 6 | #pragma unmanaged extern "C" { /* 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) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > < | 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 | #pragma unmanaged extern "C" { /* 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) extern const char * sqlite3OpcodeNames[] = { "?", /* 1 */ "MemLoad", /* 2 */ "Column", /* 3 */ "SetCookie", /* 4 */ "IfMemPos", /* 5 */ "MoveGt", /* 6 */ "AggFocus", /* 7 */ "RowKey", /* 8 */ "AggNext", /* 9 */ "OpenWrite", /* 10 */ "If", /* 11 */ "ToInt", /* 12 */ "Pop", /* 13 */ "AggContextPush", /* 14 */ "CollSeq", /* 15 */ "OpenRead", /* 16 */ "Expire", /* 17 */ "SortReset", /* 18 */ "AutoCommit", /* 19 */ "Sort", /* 20 */ "IntegrityCk", /* 21 */ "SortInsert", /* 22 */ "Function", /* 23 */ "Noop", /* 24 */ "Return", /* 25 */ "NewRowid", /* 26 */ "Variable", /* 27 */ "String", /* 28 */ "ParseSchema", /* 29 */ "AggFunc", /* 30 */ "Close", /* 31 */ "CreateIndex", /* 32 */ "IsUnique", /* 33 */ "IdxIsNull", /* 34 */ "NotFound", /* 35 */ "Int64", /* 36 */ "MustBeInt", /* 37 */ "Halt", /* 38 */ "Rowid", /* 39 */ "IdxLT", /* 40 */ "AddImm", /* 41 */ "Statement", /* 42 */ "RowData", /* 43 */ "MemMax", /* 44 */ "Push", /* 45 */ "NotExists", /* 46 */ "MemIncr", /* 47 */ "Gosub", /* 48 */ "AggSet", /* 49 */ "Integer", /* 50 */ "ToNumeric", /* 51 */ "SortNext", /* 52 */ "Prev", /* 53 */ "CreateTable", /* 54 */ "Last", /* 55 */ "IdxRowid", /* 56 */ "MakeIdxRec", /* 57 */ "ResetCount", /* 58 */ "FifoWrite", /* 59 */ "Callback", /* 60 */ "ContextPush", /* 61 */ "DropTrigger", /* 62 */ "DropIndex", /* 63 */ "IdxGE", /* 64 */ "Or", /* 65 */ "And", /* 66 */ "Not", /* 67 */ "IdxDelete", /* 68 */ "Vacuum", /* 69 */ "MoveLe", /* 70 */ "IsNull", /* 71 */ "NotNull", /* 72 */ "Ne", /* 73 */ "Eq", /* 74 */ "Gt", /* 75 */ "Le", /* 76 */ "Lt", /* 77 */ "Ge", /* 78 */ "IfNot", /* 79 */ "BitAnd", /* 80 */ "BitOr", /* 81 */ "ShiftLeft", /* 82 */ "ShiftRight", /* 83 */ "Add", /* 84 */ "Subtract", /* 85 */ "Multiply", /* 86 */ "Divide", /* 87 */ "Remainder", /* 88 */ "Concat", /* 89 */ "Negative", /* 90 */ "DropTable", /* 91 */ "BitNot", /* 92 */ "String8", /* 93 */ "MakeRecord", /* 94 */ "ToBlob", /* 95 */ "Delete", /* 96 */ "AggContextPop", /* 97 */ "Dup", /* 98 */ "Goto", /* 99 */ "FifoRead", /* 100 */ "Clear", /* 101 */ "IdxGT", /* 102 */ "MoveLt", /* 103 */ "VerifyCookie", /* 104 */ "Pull", /* 105 */ "ToText", /* 106 */ "SetNumColumns", /* 107 */ "AbsValue", /* 108 */ "Transaction", /* 109 */ "AggGet", /* 110 */ "ContextPop", /* 111 */ "Next", /* 112 */ "AggInit", /* 113 */ "IdxInsert", /* 114 */ "Distinct", /* 115 */ "AggReset", /* 116 */ "Insert", /* 117 */ "Destroy", /* 118 */ "ReadCookie", /* 119 */ "ForceInt", /* 120 */ "LoadAnalysis", /* 121 */ "OpenVirtual", /* 122 */ "OpenPseudo", /* 123 */ "Null", /* 124 */ "Blob", /* 125 */ "MemStore", /* 126 */ "Rewind", /* 127 */ "MoveGe", /* 128 */ "Found", /* 129 */ "NullRow", /* 130 */ "Real", /* 131 */ "HexBlob", }; #endif } |
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 | /* Automatically generated. Do not edit */ /* See the mkopcodeh.awk script for details */ #define OP_MemLoad 1 #define OP_HexBlob 131 /* same as TK_BLOB */ #define OP_Column 2 #define OP_SetCookie 3 #define OP_IfMemPos 4 #define OP_Real 130 /* same as TK_FLOAT */ #define OP_MoveGt 5 #define OP_Ge 77 /* same as TK_GE */ #define OP_AggFocus 6 #define OP_RowKey 7 #define OP_AggNext 8 #define OP_Eq 73 /* same as TK_EQ */ #define OP_OpenWrite 9 #define OP_NotNull 71 /* same as TK_NOTNULL */ #define OP_If 10 #define OP_ToInt 11 #define OP_String8 92 /* same as TK_STRING */ #define OP_Pop 12 #define OP_AggContextPush 13 #define OP_CollSeq 14 #define OP_OpenRead 15 #define OP_Expire 16 #define OP_SortReset 17 #define OP_AutoCommit 18 #define OP_Gt 74 /* same as TK_GT */ #define OP_Sort 19 #define OP_IntegrityCk 20 #define OP_SortInsert 21 #define OP_Function 22 #define OP_And 65 /* same as TK_AND */ #define OP_Subtract 84 /* same as TK_MINUS */ #define OP_Noop 23 #define OP_Return 24 #define OP_Remainder 87 /* same as TK_REM */ #define OP_NewRowid 25 #define OP_Multiply 85 /* same as TK_STAR */ #define OP_Variable 26 #define OP_String 27 #define OP_ParseSchema 28 #define OP_AggFunc 29 #define OP_Close 30 #define OP_CreateIndex 31 #define OP_IsUnique 32 #define OP_IdxIsNull 33 #define OP_NotFound 34 #define OP_Int64 35 #define OP_MustBeInt 36 #define OP_Halt 37 #define OP_Rowid 38 #define OP_IdxLT 39 #define OP_AddImm 40 #define OP_Statement 41 #define OP_RowData 42 #define OP_MemMax 43 #define OP_Push 44 #define OP_Or 64 /* same as TK_OR */ #define OP_NotExists 45 #define OP_MemIncr 46 #define OP_Gosub 47 #define OP_Divide 86 /* same as TK_SLASH */ #define OP_AggSet 48 #define OP_Integer 49 #define OP_ToNumeric 50 #define OP_SortNext 51 #define OP_Prev 52 #define OP_Concat 88 /* same as TK_CONCAT */ #define OP_BitAnd 79 /* same as TK_BITAND */ #define OP_CreateTable 53 #define OP_Last 54 #define OP_IsNull 70 /* same as TK_ISNULL */ #define OP_IdxRowid 55 #define OP_MakeIdxRec 56 #define OP_ShiftRight 82 /* same as TK_RSHIFT */ #define OP_ResetCount 57 #define OP_FifoWrite 58 #define OP_Callback 59 #define OP_ContextPush 60 #define OP_DropTrigger 61 #define OP_DropIndex 62 #define OP_IdxGE 63 #define OP_IdxDelete 67 #define OP_Vacuum 68 #define OP_MoveLe 69 #define OP_IfNot 78 #define OP_DropTable 90 #define OP_MakeRecord 93 #define OP_ToBlob 94 #define OP_Delete 95 #define OP_AggContextPop 96 #define OP_ShiftLeft 81 /* same as TK_LSHIFT */ #define OP_Dup 97 #define OP_Goto 98 #define OP_FifoRead 99 #define OP_Clear 100 #define OP_IdxGT 101 #define OP_MoveLt 102 #define OP_Le 75 /* same as TK_LE */ #define OP_VerifyCookie 103 #define OP_Pull 104 #define OP_ToText 105 #define OP_Not 66 /* same as TK_NOT */ #define OP_SetNumColumns 106 #define OP_AbsValue 107 #define OP_Transaction 108 #define OP_Negative 89 /* same as TK_UMINUS */ #define OP_Ne 72 /* same as TK_NE */ #define OP_AggGet 109 #define OP_ContextPop 110 #define OP_BitOr 80 /* same as TK_BITOR */ #define OP_Next 111 #define OP_AggInit 112 #define OP_IdxInsert 113 #define OP_Distinct 114 #define OP_Lt 76 /* same as TK_LT */ #define OP_AggReset 115 #define OP_Insert 116 #define OP_Destroy 117 #define OP_ReadCookie 118 #define OP_ForceInt 119 #define OP_LoadAnalysis 120 #define OP_OpenVirtual 121 #define OP_OpenPseudo 122 #define OP_Null 123 #define OP_Blob 124 #define OP_Add 83 /* same as TK_PLUS */ #define OP_MemStore 125 #define OP_Rewind 126 #define OP_MoveGe 127 #define OP_BitNot 91 /* same as TK_BITNOT */ #define OP_Found 128 #define OP_NullRow 129 #define NOPUSH_MASK_0 65400 #define NOPUSH_MASK_1 29103 #define NOPUSH_MASK_2 64439 #define NOPUSH_MASK_3 65109 #define NOPUSH_MASK_4 65535 #define NOPUSH_MASK_5 52991 #define NOPUSH_MASK_6 55285 #define NOPUSH_MASK_7 59295 #define NOPUSH_MASK_8 3 #define NOPUSH_MASK_9 0 |
Changes to SQLite.Interop/src/os_unix.c.
︙ | ︙ | |||
51 52 53 54 55 56 57 | ** lacks the fcntl() system call. So redefine fcntl() to be something ** that always succeeds. This means that locking does not occur under ** DJGPP. But its DOS - what did you expect? */ #ifdef __DJGPP__ # define fcntl(A,B,C) 0 #endif | < < < < < < < < < < < < > > > > > > > > > | > > > > > > > > > > | > > > > | 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 | ** lacks the fcntl() system call. So redefine fcntl() to be something ** that always succeeds. This means that locking does not occur under ** DJGPP. But its DOS - what did you expect? */ #ifdef __DJGPP__ # define fcntl(A,B,C) 0 #endif /* ** Include code that is common to all os_*.c files */ #include "os_common.h" /* ** The threadid macro resolves to the thread-id or to 0. Used for ** testing and debugging only. */ #ifdef SQLITE_UNIX_THREADS #define threadid pthread_self() #else #define threadid 0 #endif /* ** Set or check the OsFile.tid field. This field is set when an OsFile ** is first opened. All subsequent uses of the OsFile verify that the ** same thread is operating on the OsFile. Some operating systems do ** not allow locks to be overridden by other threads and that restriction ** means that sqlite3* database handles cannot be moved from one thread ** to another. This logic makes sure a user does not try to do that ** by mistake. */ #ifdef SQLITE_UNIX_THREADS # define SET_THREADID(X) X->tid = pthread_self() # define CHECK_THREADID(X) (!pthread_equal(X->tid, pthread_self())) #else # define SET_THREADID(X) # define CHECK_THREADID(X) 0 #endif /* ** Here is the dirt on POSIX advisory locks: ANSI STD 1003.1 (1996) ** section 6.5.2.2 lines 483 through 490 specify that when a process ** sets or clears a lock, that operation overrides any prior locks set ** by the same process. It does not explicitly say so, but this implies |
︙ | ︙ | |||
260 261 262 263 264 265 266 267 268 269 270 271 272 273 | */ struct threadTestData { int fd; /* File to be locked */ struct flock lock; /* The locking operation */ int result; /* Result of the locking operation */ }; /* ** The testThreadLockingBehavior() routine launches two separate ** threads on this routine. This routine attempts to lock a file ** descriptor then returns. The success or failure of that attempt ** allows the testThreadLockingBehavior() procedure to determine ** whether or not threads can override each others locks. */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | */ struct threadTestData { int fd; /* File to be locked */ struct flock lock; /* The locking operation */ int result; /* Result of the locking operation */ }; #ifdef SQLITE_LOCK_TRACE /* ** Print out information about all locking operations. ** ** This routine is used for troubleshooting locks on multithreaded ** platforms. Enable by compiling with the -DSQLITE_LOCK_TRACE ** command-line option on the compiler. This code is normally ** turnned off. */ static int lockTrace(int fd, int op, struct flock *p){ char *zOpName, *zType; int s; int savedErrno; if( op==F_GETLK ){ zOpName = "GETLK"; }else if( op==F_SETLK ){ zOpName = "SETLK"; }else{ s = fcntl(fd, op, p); sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s); return s; } if( p->l_type==F_RDLCK ){ zType = "RDLCK"; }else if( p->l_type==F_WRLCK ){ zType = "WRLCK"; }else if( p->l_type==F_UNLCK ){ zType = "UNLCK"; }else{ assert( 0 ); } assert( p->l_whence==SEEK_SET ); s = fcntl(fd, op, p); savedErrno = errno; sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n", threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len, (int)p->l_pid, s); if( s && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){ struct flock l2; l2 = *p; fcntl(fd, F_GETLK, &l2); if( l2.l_type==F_RDLCK ){ zType = "RDLCK"; }else if( l2.l_type==F_WRLCK ){ zType = "WRLCK"; }else if( l2.l_type==F_UNLCK ){ zType = "UNLCK"; }else{ assert( 0 ); } sqlite3DebugPrintf("fcntl-failure-reason: %s %d %d %d\n", zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid); } errno = savedErrno; return s; } #define fcntl lockTrace #endif /* SQLITE_LOCK_TRACE */ /* ** The testThreadLockingBehavior() routine launches two separate ** threads on this routine. This routine attempts to lock a file ** descriptor then returns. The success or failure of that attempt ** allows the testThreadLockingBehavior() procedure to determine ** whether or not threads can override each others locks. */ |
︙ | ︙ | |||
439 440 441 442 443 444 445 446 447 448 449 450 451 452 | const char *zFilename, OsFile *id, int *pReadonly ){ int rc; assert( !id->isOpen ); id->dirfd = -1; id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, SQLITE_DEFAULT_FILE_PERMISSIONS); if( id->h<0 ){ #ifdef EISDIR if( errno==EISDIR ){ return SQLITE_CANTOPEN; } | > | 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | const char *zFilename, OsFile *id, int *pReadonly ){ int rc; assert( !id->isOpen ); id->dirfd = -1; SET_THREADID(id); id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, SQLITE_DEFAULT_FILE_PERMISSIONS); if( id->h<0 ){ #ifdef EISDIR if( errno==EISDIR ){ return SQLITE_CANTOPEN; } |
︙ | ︙ | |||
490 491 492 493 494 495 496 497 498 | */ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ int rc; assert( !id->isOpen ); if( access(zFilename, 0)==0 ){ return SQLITE_CANTOPEN; } id->dirfd = -1; id->h = open(zFilename, | > | > | 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | */ int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){ int rc; assert( !id->isOpen ); if( access(zFilename, 0)==0 ){ return SQLITE_CANTOPEN; } SET_THREADID(id); id->dirfd = -1; id->h = open(zFilename, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY, SQLITE_DEFAULT_FILE_PERMISSIONS); if( id->h<0 ){ return SQLITE_CANTOPEN; } sqlite3OsEnterMutex(); rc = findLockInfo(id->h, &id->pLock, &id->pOpen); sqlite3OsLeaveMutex(); if( rc ){ |
︙ | ︙ | |||
524 525 526 527 528 529 530 531 532 533 534 535 536 537 | ** On success, write the file handle into *id and return SQLITE_OK. ** ** On failure, return SQLITE_CANTOPEN. */ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ int rc; assert( !id->isOpen ); id->dirfd = -1; id->h = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY); if( id->h<0 ){ return SQLITE_CANTOPEN; } sqlite3OsEnterMutex(); rc = findLockInfo(id->h, &id->pLock, &id->pOpen); | > | 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | ** On success, write the file handle into *id and return SQLITE_OK. ** ** On failure, return SQLITE_CANTOPEN. */ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){ int rc; assert( !id->isOpen ); SET_THREADID(id); id->dirfd = -1; id->h = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY); if( id->h<0 ){ return SQLITE_CANTOPEN; } sqlite3OsEnterMutex(); rc = findLockInfo(id->h, &id->pLock, &id->pOpen); |
︙ | ︙ | |||
568 569 570 571 572 573 574 575 576 577 578 579 580 581 | OsFile *id ){ if( !id->isOpen ){ /* Do not open the directory if the corresponding file is not already ** open. */ return SQLITE_CANTOPEN; } assert( id->dirfd<0 ); id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0); if( id->dirfd<0 ){ return SQLITE_CANTOPEN; } TRACE3("OPENDIR %-3d %s\n", id->dirfd, zDirname); return SQLITE_OK; | > | 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | OsFile *id ){ if( !id->isOpen ){ /* Do not open the directory if the corresponding file is not already ** open. */ return SQLITE_CANTOPEN; } SET_THREADID(id); assert( id->dirfd<0 ); id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0); if( id->dirfd<0 ){ return SQLITE_CANTOPEN; } TRACE3("OPENDIR %-3d %s\n", id->dirfd, zDirname); return SQLITE_OK; |
︙ | ︙ | |||
835 836 837 838 839 840 841 842 843 844 845 846 847 848 | ** non-zero. If the file is unlocked or holds only SHARED locks, then ** return zero. */ int sqlite3OsCheckReservedLock(OsFile *id){ int r = 0; assert( id->isOpen ); sqlite3OsEnterMutex(); /* Needed because id->pLock is shared across threads */ /* Check if a thread in this process holds such a lock */ if( id->pLock->locktype>SHARED_LOCK ){ r = 1; } | > | 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 | ** non-zero. If the file is unlocked or holds only SHARED locks, then ** return zero. */ int sqlite3OsCheckReservedLock(OsFile *id){ int r = 0; assert( id->isOpen ); if( CHECK_THREADID(id) ) return SQLITE_MISUSE; sqlite3OsEnterMutex(); /* Needed because id->pLock is shared across threads */ /* Check if a thread in this process holds such a lock */ if( id->pLock->locktype>SHARED_LOCK ){ r = 1; } |
︙ | ︙ | |||
952 953 954 955 956 957 958 959 960 961 962 963 964 965 | struct flock lock; int s; assert( id->isOpen ); TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype), locktypeName(id->locktype), locktypeName(pLock->locktype), pLock->cnt ,getpid() ); /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. */ if( id->locktype>=locktype ){ TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype)); | > | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 | struct flock lock; int s; assert( id->isOpen ); TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype), locktypeName(id->locktype), locktypeName(pLock->locktype), pLock->cnt ,getpid() ); if( CHECK_THREADID(id) ) return SQLITE_MISUSE; /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. */ if( id->locktype>=locktype ){ TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype)); |
︙ | ︙ | |||
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | id->locktype = SHARED_LOCK; pLock->cnt++; id->pOpen->nLock++; goto end_lock; } lock.l_len = 1L; lock.l_whence = SEEK_SET; /* A PENDING lock is needed before acquiring a SHARED lock and before ** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will ** be released. */ if( locktype==SHARED_LOCK | > | 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | id->locktype = SHARED_LOCK; pLock->cnt++; id->pOpen->nLock++; goto end_lock; } lock.l_len = 1L; lock.l_whence = SEEK_SET; /* A PENDING lock is needed before acquiring a SHARED lock and before ** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will ** be released. */ if( locktype==SHARED_LOCK |
︙ | ︙ | |||
1033 1034 1035 1036 1037 1038 1039 | lock.l_len = SHARED_SIZE; s = fcntl(id->h, F_SETLK, &lock); /* Drop the temporary PENDING lock */ lock.l_start = PENDING_BYTE; lock.l_len = 1L; lock.l_type = F_UNLCK; | | > > > | 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | lock.l_len = SHARED_SIZE; s = fcntl(id->h, F_SETLK, &lock); /* Drop the temporary PENDING lock */ lock.l_start = PENDING_BYTE; lock.l_len = 1L; lock.l_type = F_UNLCK; if( fcntl(id->h, F_SETLK, &lock)!=0 ){ rc = SQLITE_IOERR; /* This should never happen */ goto end_lock; } if( s ){ rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY; }else{ id->locktype = SHARED_LOCK; id->pOpen->nLock++; pLock->cnt = 1; } |
︙ | ︙ | |||
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 | struct lockInfo *pLock; struct flock lock; int rc = SQLITE_OK; assert( id->isOpen ); TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype, id->pLock->locktype, id->pLock->cnt, getpid()); assert( locktype<=SHARED_LOCK ); if( id->locktype<=locktype ){ return SQLITE_OK; } sqlite3OsEnterMutex(); pLock = id->pLock; | > | 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 | struct lockInfo *pLock; struct flock lock; int rc = SQLITE_OK; assert( id->isOpen ); TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype, id->pLock->locktype, id->pLock->cnt, getpid()); if( CHECK_THREADID(id) ) return SQLITE_MISUSE; assert( locktype<=SHARED_LOCK ); if( id->locktype<=locktype ){ return SQLITE_OK; } sqlite3OsEnterMutex(); pLock = id->pLock; |
︙ | ︙ | |||
1127 1128 1129 1130 1131 1132 1133 | rc = SQLITE_IOERR; } } lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; lock.l_start = PENDING_BYTE; lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); | | | > > > | | > > > | 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 | rc = SQLITE_IOERR; } } lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; lock.l_start = PENDING_BYTE; lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); if( fcntl(id->h, F_SETLK, &lock)==0 ){ pLock->locktype = SHARED_LOCK; }else{ rc = SQLITE_IOERR; /* This should never happen */ } } if( locktype==NO_LOCK ){ struct openCnt *pOpen; /* Decrement the shared lock counter. Release the lock using an ** OS call only when all threads in this same process have released ** the lock. */ pLock->cnt--; if( pLock->cnt==0 ){ lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; lock.l_start = lock.l_len = 0L; if( fcntl(id->h, F_SETLK, &lock)==0 ){ pLock->locktype = NO_LOCK; }else{ rc = SQLITE_IOERR; /* This should never happen */ } } /* Decrement the count of locks against this same file. When the ** count reaches zero, close any other file descriptors whose close ** was deferred because of outstanding locks. */ pOpen = id->pOpen; |
︙ | ︙ | |||
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | } /* ** Close a file. */ int sqlite3OsClose(OsFile *id){ if( !id->isOpen ) return SQLITE_OK; sqlite3OsUnlock(id, NO_LOCK); if( id->dirfd>=0 ) close(id->dirfd); id->dirfd = -1; sqlite3OsEnterMutex(); if( id->pOpen->nLock ){ /* If there are outstanding locks, do not actually close the file just ** yet because that would clear those locks. Instead, add the file | > | 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 | } /* ** Close a file. */ int sqlite3OsClose(OsFile *id){ if( !id->isOpen ) return SQLITE_OK; if( CHECK_THREADID(id) ) return SQLITE_MISUSE; sqlite3OsUnlock(id, NO_LOCK); if( id->dirfd>=0 ) close(id->dirfd); id->dirfd = -1; sqlite3OsEnterMutex(); if( id->pOpen->nLock ){ /* If there are outstanding locks, do not actually close the file just ** yet because that would clear those locks. Instead, add the file |
︙ | ︙ |
Changes to SQLite.Interop/src/os_unix.h.
︙ | ︙ | |||
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 | ** standard include files. */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> /* ** The OsFile structure is a operating-system independing representation ** of an open file handle. It is defined differently for each architecture. ** ** This is the definition for Unix. ** ** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK, ** PENDING_LOCK or EXCLUSIVE_LOCK. */ typedef struct OsFile OsFile; struct OsFile { struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */ struct openCnt *pOpen; /* Info about all open fd's on this inode */ struct lockInfo *pLock; /* Info about locks on this inode */ int h; /* The file descriptor */ unsigned char locktype; /* The type of lock held on this fd */ unsigned char isOpen; /* True if needs to be closed */ unsigned char fullSync; /* Use F_FULLSYNC if available */ int dirfd; /* File descriptor for the directory */ }; /* ** A macro to set the OsFile.fullSync flag, if it exists. */ #define SET_FULLSYNC(x,y) ((x).fullSync = (y)) | > > > > > > > > > > > > > > | 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 | ** standard include files. */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> /* ** Macros used to determine whether or not to use threads. The ** SQLITE_UNIX_THREADS macro is defined if we are synchronizing for ** Posix threads and SQLITE_W32_THREADS is defined if we are ** synchronizing using Win32 threads. */ #if defined(THREADSAFE) && THREADSAFE # include <pthread.h> # define SQLITE_UNIX_THREADS 1 #endif /* ** The OsFile structure is a operating-system independing representation ** of an open file handle. It is defined differently for each architecture. ** ** This is the definition for Unix. ** ** OsFile.locktype takes one of the values SHARED_LOCK, RESERVED_LOCK, ** PENDING_LOCK or EXCLUSIVE_LOCK. */ typedef struct OsFile OsFile; struct OsFile { struct Pager *pPager; /* The pager that owns this OsFile. Might be 0 */ struct openCnt *pOpen; /* Info about all open fd's on this inode */ struct lockInfo *pLock; /* Info about locks on this inode */ int h; /* The file descriptor */ unsigned char locktype; /* The type of lock held on this fd */ unsigned char isOpen; /* True if needs to be closed */ unsigned char fullSync; /* Use F_FULLSYNC if available */ int dirfd; /* File descriptor for the directory */ #ifdef SQLITE_UNIX_THREADS pthread_t tid; /* The thread authorized to use this OsFile */ #endif }; /* ** A macro to set the OsFile.fullSync flag, if it exists. */ #define SET_FULLSYNC(x,y) ((x).fullSync = (y)) |
︙ | ︙ |
Changes to SQLite.Interop/src/os_win.c.
1 2 3 4 5 6 7 | extern "C" { /* ** 2004 May 22 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: | > | 1 2 3 4 5 6 7 8 | #pragma unmanaged extern "C" { /* ** 2004 May 22 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: |
︙ | ︙ | |||
769 770 771 772 773 774 775 | *prNow = sqlite3_current_time/86400.0 + 2440587.5; } #endif return 0; } #endif /* OS_WIN */ | | < | 770 771 772 773 774 775 776 777 | *prNow = sqlite3_current_time/86400.0 + 2440587.5; } #endif return 0; } #endif /* OS_WIN */ } |
Changes to SQLite.Interop/src/os_wince.c.
1 2 3 4 5 6 7 | extern "C" { /* ** 2005 April 1 - Nuno Lucas ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: | > | 1 2 3 4 5 6 7 8 | #pragma unmanaged extern "C" { /* ** 2005 April 1 - Nuno Lucas ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: |
︙ | ︙ |
Changes to SQLite.Interop/src/pager.c.
︙ | ︙ | |||
17 18 19 20 21 22 23 | ** 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. ** | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include "os.h" #include "pager.h" #include <assert.h> #include <string.h> |
︙ | ︙ | |||
1006 1007 1008 1009 1010 1011 1012 | if( pgno>(unsigned)pPager->dbSize ){ return SQLITE_OK; } if( useCksum ){ rc = read32bits(jfd, &cksum); if( rc ) return rc; pPager->journalOff += 4; | | | 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 | if( pgno>(unsigned)pPager->dbSize ){ return SQLITE_OK; } if( useCksum ){ rc = read32bits(jfd, &cksum); if( rc ) return rc; pPager->journalOff += 4; if( pager_cksum(pPager, pgno, (const char *)aData)!=cksum ){ return SQLITE_DONE; } } assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE ); /* If the pager is in RESERVED state, then there must be a copy of this |
︙ | ︙ | |||
1757 1758 1759 1760 1761 1762 1763 | if( pPager->dbSize>=0 ){ return pPager->dbSize; } if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){ pPager->errMask |= PAGER_ERR_DISK; return 0; } | > > > | > | 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 | if( pPager->dbSize>=0 ){ return pPager->dbSize; } if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){ pPager->errMask |= PAGER_ERR_DISK; return 0; } if( n>0 && n<pPager->pageSize ){ n = 1; }else{ n /= pPager->pageSize; } if( !MEMDB && n==PENDING_BYTE/pPager->pageSize ){ n++; } if( pPager->state!=PAGER_UNLOCK ){ pPager->dbSize = n; } return n; |
︙ | ︙ | |||
1865 1866 1867 1868 1869 1870 1871 | } #else #define memoryTruncate(p) #endif /* ** Try to obtain a lock on a file. Invoke the busy callback if the lock | | < < | < < < | 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 | } #else #define memoryTruncate(p) #endif /* ** Try to obtain a lock on a file. Invoke the busy callback if the lock ** is currently not available. Repeat until the busy callback returns ** false or until the lock succeeds. ** ** Return SQLITE_OK on success and an error code if we cannot obtain ** the lock. */ static int pager_wait_on_lock(Pager *pPager, int locktype){ int rc; assert( PAGER_SHARED==SHARED_LOCK ); assert( PAGER_RESERVED==RESERVED_LOCK ); assert( PAGER_EXCLUSIVE==EXCLUSIVE_LOCK ); if( pPager->state>=locktype ){ rc = SQLITE_OK; }else{ do { rc = sqlite3OsLock(&pPager->fd, locktype); }while( rc==SQLITE_BUSY && sqlite3InvokeBusyHandler(pPager->pBusyHandler) ); if( rc==SQLITE_OK ){ pPager->state = locktype; } } return rc; } |
︙ | ︙ | |||
2816 2817 2818 2819 2820 2821 2822 | pHist->pOrig = (u8 *)sqliteMallocRaw( pPager->pageSize ); if( pHist->pOrig ){ memcpy(pHist->pOrig, PGHDR_TO_DATA(pPg), pPager->pageSize); } }else{ u32 cksum; CODEC(pPager, pData, pPg->pgno, 7); | | | 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 | pHist->pOrig = (u8 *)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, (const char *)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); pPager->journalOff += szPg; TRACE4("JOURNAL %d page %d needSync=%d\n", |
︙ | ︙ | |||
3601 3602 3603 3604 3605 3606 3607 | sqlite3DebugPrintf("PAGE %3d addr=%p nRef=%d\n", pPg->pgno, PGHDR_TO_DATA(pPg), pPg->nRef); } } #endif #endif /* SQLITE_OMIT_DISKIO */ | | < | 3600 3601 3602 3603 3604 3605 3606 3607 | sqlite3DebugPrintf("PAGE %3d addr=%p nRef=%d\n", pPg->pgno, PGHDR_TO_DATA(pPg), pPg->nRef); } } #endif #endif /* SQLITE_OMIT_DISKIO */ } |
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 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ /* ** The default size of a database page. */ #ifndef SQLITE_DEFAULT_PAGE_SIZE # define SQLITE_DEFAULT_PAGE_SIZE 1024 |
︙ | ︙ |
Changes to SQLite.Interop/src/parse.c.
1 2 3 4 5 6 7 8 9 | #pragma unmanaged extern "C" { /* Driver template for the LEMON parser generator. ** The author disclaims copyright to this source code. */ /* First off, code is include which follows the "include" declaration ** in the input file. */ #include <stdio.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 | #pragma unmanaged extern "C" { /* Driver template for the LEMON parser generator. ** The author disclaims copyright to this source code. */ /* First off, code is include which follows the "include" declaration ** in the input file. */ #include <stdio.h> //#line 51 "parse.y" #include "sqliteInt.h" #include "parse.h" /* ** An instance of this structure holds information about the ** LIMIT clause of a SELECT statement. */ struct LimitVal { Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */ Expr *pOffset; /* The OFFSET expression. NULL if there is none */ }; /* ** An instance of this structure is used to store the LIKE, ** GLOB, NOT LIKE, and NOT GLOB operators. */ struct LikeOp { Token _operator; /* "like" or "glob" or "regexp" */ int not; /* True if the NOT keyword is present */ }; /* ** An instance of the following structure describes the event of a ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, ** TK_DELETE, or TK_INSTEAD. If the event is of the form |
︙ | ︙ | |||
92 93 94 95 96 97 98 | ** 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 | | < | | < < | | | | | > > > > | | < | | | | | | 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 | ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. */ #define YYCODETYPE unsigned char #define YYNOCODE 244 #define YYACTIONTYPE unsigned short int #define sqlite3ParserTOKENTYPE Token typedef union { sqlite3ParserTOKENTYPE yy0; struct {int value; int mask;} yy35; Expr* yy44; int yy58; Select* yy99; struct LimitVal yy112; Token yy144; TriggerStep* yy203; struct TrigEvent yy234; IdList* yy258; struct AttachKey yy300; SrcList* yy367; ExprList* yy412; struct LikeOp yy432; int yy487; } YYMINORTYPE; #define YYSTACKDEPTH 100 #define sqlite3ParserARG_SDECL Parse *pParse; #define sqlite3ParserARG_PDECL ,Parse *pParse #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse #define sqlite3ParserARG_STORE yypParser->pParse = pParse #define YYNSTATE 578 #define YYNRULE 310 #define YYERRORSYMBOL 143 #define YYERRSYMDT yy487 #define YYFALLBACK 1 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) #define YY_ERROR_ACTION (YYNSTATE+YYNRULE) /* Next are that tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement |
︙ | ︙ | |||
174 175 176 177 178 179 180 | ** 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[] = { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > | | | | | | | | | | | | | | > > | | < < | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | > > | | | < < < | | | | | | | | > | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | > > > | | > > > > > > > > > > | < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | ** yy_shift_ofst[] For each state, the offset into yy_action for ** shifting terminals. ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. */ static const YYACTIONTYPE yy_action[] = { /* 0 */ 283, 581, 110, 137, 139, 135, 141, 268, 147, 149, /* 10 */ 151, 153, 155, 157, 159, 161, 163, 165, 114, 119, /* 20 */ 120, 167, 175, 147, 149, 151, 153, 155, 157, 159, /* 30 */ 161, 163, 165, 155, 157, 159, 161, 163, 165, 132, /* 40 */ 94, 168, 178, 183, 188, 177, 182, 143, 145, 137, /* 50 */ 139, 135, 141, 72, 147, 149, 151, 153, 155, 157, /* 60 */ 159, 161, 163, 165, 44, 45, 245, 111, 147, 149, /* 70 */ 151, 153, 155, 157, 159, 161, 163, 165, 13, 427, /* 80 */ 121, 578, 657, 639, 375, 347, 167, 39, 6, 5, /* 90 */ 92, 3, 576, 363, 25, 355, 299, 255, 34, 269, /* 100 */ 513, 129, 372, 112, 132, 94, 168, 178, 183, 188, /* 110 */ 177, 182, 143, 145, 137, 139, 135, 141, 567, 147, /* 120 */ 149, 151, 153, 155, 157, 159, 161, 163, 165, 77, /* 130 */ 109, 373, 133, 77, 117, 119, 120, 7, 13, 32, /* 140 */ 33, 300, 280, 14, 15, 377, 301, 610, 379, 386, /* 150 */ 391, 167, 377, 366, 369, 379, 386, 391, 524, 330, /* 160 */ 394, 64, 368, 374, 407, 705, 95, 394, 571, 132, /* 170 */ 94, 168, 178, 183, 188, 177, 182, 143, 145, 137, /* 180 */ 139, 135, 141, 9, 147, 149, 151, 153, 155, 157, /* 190 */ 159, 161, 163, 165, 127, 125, 121, 373, 167, 101, /* 200 */ 102, 103, 28, 14, 15, 408, 33, 860, 889, 1, /* 210 */ 577, 3, 576, 4, 540, 332, 132, 94, 168, 178, /* 220 */ 183, 188, 177, 182, 143, 145, 137, 139, 135, 141, /* 230 */ 295, 147, 149, 151, 153, 155, 157, 159, 161, 163, /* 240 */ 165, 2, 466, 377, 4, 167, 379, 386, 391, 16, /* 250 */ 17, 18, 285, 159, 161, 163, 165, 240, 394, 173, /* 260 */ 243, 184, 189, 132, 94, 168, 178, 183, 188, 177, /* 270 */ 182, 143, 145, 137, 139, 135, 141, 96, 147, 149, /* 280 */ 151, 153, 155, 157, 159, 161, 163, 165, 815, 291, /* 290 */ 308, 813, 51, 500, 472, 462, 588, 539, 75, 322, /* 300 */ 27, 133, 409, 704, 81, 272, 10, 173, 96, 184, /* 310 */ 189, 96, 190, 13, 541, 542, 13, 393, 78, 167, /* 320 */ 37, 361, 40, 59, 67, 69, 325, 356, 586, 75, /* 330 */ 197, 368, 75, 316, 358, 95, 218, 132, 94, 168, /* 340 */ 178, 183, 188, 177, 182, 143, 145, 137, 139, 135, /* 350 */ 141, 77, 147, 149, 151, 153, 155, 157, 159, 161, /* 360 */ 163, 165, 173, 113, 184, 189, 167, 110, 101, 102, /* 370 */ 103, 318, 274, 405, 329, 121, 12, 461, 14, 15, /* 380 */ 404, 14, 15, 238, 132, 94, 168, 178, 183, 188, /* 390 */ 177, 182, 143, 145, 137, 139, 135, 141, 273, 147, /* 400 */ 149, 151, 153, 155, 157, 159, 161, 163, 165, 96, /* 410 */ 77, 51, 315, 427, 48, 36, 360, 196, 317, 129, /* 420 */ 130, 112, 314, 49, 355, 209, 313, 13, 96, 110, /* 430 */ 75, 197, 111, 96, 814, 485, 50, 589, 46, 461, /* 440 */ 167, 40, 59, 67, 69, 325, 356, 482, 47, 75, /* 450 */ 257, 467, 429, 358, 75, 197, 469, 232, 132, 94, /* 460 */ 168, 178, 183, 188, 177, 182, 143, 145, 137, 139, /* 470 */ 135, 141, 77, 147, 149, 151, 153, 155, 157, 159, /* 480 */ 161, 163, 165, 323, 237, 13, 830, 169, 249, 258, /* 490 */ 13, 703, 14, 15, 111, 96, 265, 485, 96, 192, /* 500 */ 96, 194, 195, 13, 192, 167, 194, 195, 238, 171, /* 510 */ 172, 476, 192, 471, 194, 195, 75, 211, 469, 75, /* 520 */ 257, 75, 91, 132, 94, 168, 178, 183, 188, 177, /* 530 */ 182, 143, 145, 137, 139, 135, 141, 170, 147, 149, /* 540 */ 151, 153, 155, 157, 159, 161, 163, 165, 365, 48, /* 550 */ 14, 15, 216, 65, 228, 14, 15, 298, 49, 251, /* 560 */ 66, 13, 602, 13, 330, 96, 676, 212, 14, 15, /* 570 */ 167, 50, 865, 222, 57, 58, 678, 275, 192, 20, /* 580 */ 194, 195, 277, 403, 26, 351, 75, 499, 132, 94, /* 590 */ 168, 178, 183, 188, 177, 182, 143, 145, 137, 139, /* 600 */ 135, 141, 96, 147, 149, 151, 153, 155, 157, 159, /* 610 */ 161, 163, 165, 587, 863, 83, 11, 167, 742, 345, /* 620 */ 332, 312, 306, 75, 93, 358, 14, 15, 14, 15, /* 630 */ 858, 173, 495, 184, 189, 132, 94, 168, 178, 183, /* 640 */ 188, 177, 182, 143, 145, 137, 139, 135, 141, 594, /* 650 */ 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, /* 660 */ 22, 272, 352, 192, 167, 194, 195, 192, 295, 194, /* 670 */ 195, 285, 505, 192, 42, 194, 195, 192, 351, 194, /* 680 */ 195, 595, 132, 94, 168, 178, 183, 188, 177, 182, /* 690 */ 143, 145, 137, 139, 135, 141, 338, 147, 149, 151, /* 700 */ 153, 155, 157, 159, 161, 163, 165, 837, 511, 286, /* 710 */ 507, 167, 382, 127, 125, 192, 339, 194, 195, 192, /* 720 */ 543, 194, 195, 333, 340, 342, 351, 442, 274, 132, /* 730 */ 94, 168, 178, 183, 188, 177, 182, 143, 145, 137, /* 740 */ 139, 135, 141, 96, 147, 149, 151, 153, 155, 157, /* 750 */ 159, 161, 163, 165, 273, 352, 110, 371, 167, 373, /* 760 */ 388, 438, 440, 439, 75, 499, 362, 574, 33, 335, /* 770 */ 538, 668, 656, 351, 31, 413, 132, 186, 168, 178, /* 780 */ 183, 188, 177, 182, 143, 145, 137, 139, 135, 141, /* 790 */ 509, 147, 149, 151, 153, 155, 157, 159, 161, 163, /* 800 */ 165, 96, 736, 352, 283, 167, 110, 397, 123, 124, /* 810 */ 531, 421, 193, 416, 115, 681, 116, 235, 477, 236, /* 820 */ 351, 111, 75, 244, 94, 168, 178, 183, 188, 177, /* 830 */ 182, 143, 145, 137, 139, 135, 141, 96, 147, 149, /* 840 */ 151, 153, 155, 157, 159, 161, 163, 165, 96, 879, /* 850 */ 352, 881, 167, 292, 455, 293, 270, 280, 75, 108, /* 860 */ 554, 319, 857, 236, 42, 447, 13, 351, 13, 75, /* 870 */ 134, 111, 168, 178, 183, 188, 177, 182, 143, 145, /* 880 */ 137, 139, 135, 141, 96, 147, 149, 151, 153, 155, /* 890 */ 157, 159, 161, 163, 165, 96, 76, 352, 444, 96, /* 900 */ 71, 96, 443, 52, 208, 75, 136, 76, 106, 24, /* 910 */ 412, 71, 180, 596, 445, 54, 75, 138, 266, 106, /* 920 */ 75, 140, 75, 142, 441, 220, 96, 337, 336, 29, /* 930 */ 96, 14, 15, 14, 15, 133, 220, 77, 96, 198, /* 940 */ 96, 458, 179, 346, 348, 347, 133, 75, 433, 96, /* 950 */ 198, 75, 144, 389, 285, 347, 204, 202, 320, 75, /* 960 */ 146, 75, 148, 410, 200, 73, 74, 204, 202, 95, /* 970 */ 75, 150, 398, 96, 347, 200, 73, 74, 852, 96, /* 980 */ 95, 76, 823, 448, 597, 71, 432, 459, 293, 420, /* 990 */ 96, 705, 303, 106, 75, 480, 77, 436, 437, 81, /* 1000 */ 75, 152, 101, 102, 103, 104, 105, 206, 210, 705, /* 1010 */ 220, 75, 154, 101, 102, 103, 104, 105, 206, 210, /* 1020 */ 133, 30, 77, 240, 198, 456, 96, 347, 35, 464, /* 1030 */ 45, 490, 463, 293, 96, 873, 498, 96, 496, 96, /* 1040 */ 76, 204, 202, 736, 71, 96, 601, 75, 156, 200, /* 1050 */ 73, 74, 106, 96, 95, 75, 158, 295, 75, 160, /* 1060 */ 75, 162, 38, 492, 96, 853, 75, 164, 76, 220, /* 1070 */ 41, 191, 71, 552, 75, 166, 482, 43, 427, 133, /* 1080 */ 106, 528, 568, 198, 96, 75, 197, 101, 102, 103, /* 1090 */ 104, 105, 206, 210, 816, 670, 77, 220, 240, 81, /* 1100 */ 204, 202, 309, 96, 77, 75, 174, 133, 200, 73, /* 1110 */ 74, 198, 493, 95, 77, 8, 489, 506, 427, 427, /* 1120 */ 19, 21, 23, 411, 75, 176, 42, 234, 204, 202, /* 1130 */ 427, 81, 427, 562, 427, 546, 200, 73, 74, 238, /* 1140 */ 522, 95, 556, 96, 529, 427, 101, 102, 103, 104, /* 1150 */ 105, 206, 210, 532, 535, 496, 466, 508, 510, 266, /* 1160 */ 96, 533, 885, 559, 75, 185, 565, 96, 56, 512, /* 1170 */ 96, 516, 96, 520, 101, 102, 103, 104, 105, 206, /* 1180 */ 210, 75, 187, 55, 526, 53, 60, 61, 75, 199, /* 1190 */ 96, 75, 201, 75, 203, 96, 64, 62, 96, 70, /* 1200 */ 96, 63, 96, 68, 96, 611, 96, 514, 518, 462, /* 1210 */ 84, 75, 205, 504, 96, 612, 75, 217, 81, 75, /* 1220 */ 219, 75, 229, 75, 231, 75, 233, 75, 246, 81, /* 1230 */ 79, 80, 96, 266, 82, 75, 262, 96, 263, 310, /* 1240 */ 86, 96, 261, 96, 85, 96, 247, 96, 87, 97, /* 1250 */ 99, 88, 90, 75, 267, 107, 89, 98, 75, 297, /* 1260 */ 75, 307, 75, 364, 75, 392, 75, 484, 75, 497, /* 1270 */ 118, 100, 131, 128, 165, 122, 181, 682, 239, 683, /* 1280 */ 684, 207, 230, 213, 126, 214, 215, 221, 225, 224, /* 1290 */ 223, 226, 240, 227, 241, 248, 242, 250, 254, 253, /* 1300 */ 252, 255, 236, 264, 259, 256, 260, 271, 276, 278, /* 1310 */ 279, 281, 284, 296, 282, 289, 287, 290, 288, 294, /* 1320 */ 302, 305, 311, 304, 321, 324, 326, 344, 328, 327, /* 1330 */ 331, 349, 357, 329, 353, 334, 341, 343, 380, 350, /* 1340 */ 378, 381, 354, 367, 359, 370, 384, 387, 396, 395, /* 1350 */ 399, 400, 385, 54, 406, 414, 376, 401, 390, 383, /* 1360 */ 415, 417, 418, 402, 419, 422, 425, 423, 424, 434, /* 1370 */ 426, 428, 430, 845, 431, 435, 850, 446, 851, 449, /* 1380 */ 450, 451, 452, 453, 821, 454, 822, 457, 460, 465, /* 1390 */ 743, 468, 744, 844, 470, 859, 463, 481, 475, 479, /* 1400 */ 861, 474, 473, 478, 483, 486, 487, 491, 488, 494, /* 1410 */ 862, 501, 502, 503, 864, 675, 677, 829, 871, 517, /* 1420 */ 515, 735, 519, 521, 523, 738, 525, 741, 831, 534, /* 1430 */ 832, 833, 530, 536, 834, 527, 537, 835, 544, 836, /* 1440 */ 545, 547, 872, 874, 549, 875, 557, 555, 548, 550, /* 1450 */ 553, 878, 880, 882, 561, 558, 883, 560, 551, 563, /* 1460 */ 566, 569, 564, 570, 572, 573, 884, 555, 555, 555, /* 1470 */ 555, 575, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 25, 10, 27, 74, 75, 76, 77, 26, 79, 80, /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 168, 169, /* 20 */ 170, 46, 78, 79, 80, 81, 82, 83, 84, 85, /* 30 */ 86, 87, 88, 83, 84, 85, 86, 87, 88, 64, /* 40 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, /* 50 */ 75, 76, 77, 23, 79, 80, 81, 82, 83, 84, /* 60 */ 85, 86, 87, 88, 189, 190, 26, 92, 79, 80, /* 70 */ 81, 82, 83, 84, 85, 86, 87, 88, 27, 152, /* 80 */ 230, 0, 24, 24, 26, 26, 46, 172, 147, 148, /* 90 */ 50, 10, 11, 23, 153, 180, 159, 27, 162, 118, /* 100 */ 159, 165, 166, 167, 64, 65, 66, 67, 68, 69, /* 110 */ 70, 71, 72, 73, 74, 75, 76, 77, 191, 79, /* 120 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 192, /* 130 */ 25, 152, 62, 192, 168, 169, 170, 10, 27, 160, /* 140 */ 161, 204, 205, 92, 93, 94, 209, 117, 97, 98, /* 150 */ 99, 46, 94, 83, 84, 97, 98, 99, 217, 47, /* 160 */ 109, 102, 92, 184, 185, 25, 96, 109, 241, 64, /* 170 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, /* 180 */ 75, 76, 77, 150, 79, 80, 81, 82, 83, 84, /* 190 */ 85, 86, 87, 88, 83, 84, 230, 152, 46, 129, /* 200 */ 130, 131, 157, 92, 93, 160, 161, 18, 144, 145, /* 210 */ 146, 10, 11, 149, 103, 103, 64, 65, 66, 67, /* 220 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, /* 230 */ 152, 79, 80, 81, 82, 83, 84, 85, 86, 87, /* 240 */ 88, 146, 53, 94, 149, 46, 97, 98, 99, 14, /* 250 */ 15, 16, 165, 85, 86, 87, 88, 117, 109, 220, /* 260 */ 221, 222, 223, 64, 65, 66, 67, 68, 69, 70, /* 270 */ 71, 72, 73, 74, 75, 76, 77, 152, 79, 80, /* 280 */ 81, 82, 83, 84, 85, 86, 87, 88, 136, 211, /* 290 */ 203, 18, 66, 104, 105, 106, 10, 152, 173, 174, /* 300 */ 23, 62, 25, 24, 115, 26, 151, 220, 152, 222, /* 310 */ 223, 152, 23, 27, 169, 170, 27, 175, 159, 46, /* 320 */ 94, 95, 96, 97, 98, 99, 100, 101, 10, 173, /* 330 */ 174, 92, 173, 174, 108, 96, 137, 64, 65, 66, /* 340 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, /* 350 */ 77, 192, 79, 80, 81, 82, 83, 84, 85, 86, /* 360 */ 87, 88, 220, 23, 222, 223, 46, 27, 129, 130, /* 370 */ 131, 215, 93, 180, 181, 230, 152, 159, 92, 93, /* 380 */ 187, 92, 93, 227, 64, 65, 66, 67, 68, 69, /* 390 */ 70, 71, 72, 73, 74, 75, 76, 77, 119, 79, /* 400 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 152, /* 410 */ 192, 66, 24, 152, 19, 171, 172, 24, 24, 165, /* 420 */ 166, 167, 112, 28, 180, 24, 116, 27, 152, 27, /* 430 */ 173, 174, 92, 152, 18, 217, 41, 10, 43, 159, /* 440 */ 46, 96, 97, 98, 99, 100, 101, 152, 53, 173, /* 450 */ 174, 233, 191, 108, 173, 174, 238, 137, 64, 65, /* 460 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 470 */ 76, 77, 192, 79, 80, 81, 82, 83, 84, 85, /* 480 */ 86, 87, 88, 24, 227, 27, 10, 46, 212, 213, /* 490 */ 27, 24, 92, 93, 92, 152, 215, 217, 152, 111, /* 500 */ 152, 113, 114, 27, 111, 46, 113, 114, 227, 68, /* 510 */ 69, 216, 111, 233, 113, 114, 173, 174, 238, 173, /* 520 */ 174, 173, 174, 64, 65, 66, 67, 68, 69, 70, /* 530 */ 71, 72, 73, 74, 75, 76, 77, 96, 79, 80, /* 540 */ 81, 82, 83, 84, 85, 86, 87, 88, 24, 19, /* 550 */ 92, 93, 136, 31, 138, 92, 93, 23, 28, 213, /* 560 */ 38, 27, 10, 27, 47, 152, 10, 224, 92, 93, /* 570 */ 46, 41, 10, 43, 14, 15, 10, 119, 111, 151, /* 580 */ 113, 114, 119, 66, 154, 152, 173, 174, 64, 65, /* 590 */ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, /* 600 */ 76, 77, 152, 79, 80, 81, 82, 83, 84, 85, /* 610 */ 86, 87, 88, 10, 10, 195, 13, 46, 10, 186, /* 620 */ 103, 85, 202, 173, 174, 108, 92, 93, 92, 93, /* 630 */ 12, 220, 219, 222, 223, 64, 65, 66, 67, 68, /* 640 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 10, /* 650 */ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, /* 660 */ 151, 26, 229, 111, 46, 113, 114, 111, 152, 113, /* 670 */ 114, 165, 21, 111, 103, 113, 114, 111, 152, 113, /* 680 */ 114, 10, 64, 65, 66, 67, 68, 69, 70, 71, /* 690 */ 72, 73, 74, 75, 76, 77, 34, 79, 80, 81, /* 700 */ 82, 83, 84, 85, 86, 87, 88, 10, 57, 203, /* 710 */ 59, 46, 186, 83, 84, 111, 54, 113, 114, 111, /* 720 */ 23, 113, 114, 104, 105, 106, 152, 211, 93, 64, /* 730 */ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, /* 740 */ 75, 76, 77, 152, 79, 80, 81, 82, 83, 84, /* 750 */ 85, 86, 87, 88, 119, 229, 27, 164, 46, 152, /* 760 */ 186, 104, 105, 106, 173, 174, 173, 160, 161, 107, /* 770 */ 73, 10, 24, 152, 26, 21, 64, 65, 66, 67, /* 780 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, /* 790 */ 139, 79, 80, 81, 82, 83, 84, 85, 86, 87, /* 800 */ 88, 152, 10, 229, 25, 46, 27, 186, 129, 130, /* 810 */ 219, 57, 112, 59, 24, 115, 26, 24, 26, 26, /* 820 */ 152, 92, 173, 174, 65, 66, 67, 68, 69, 70, /* 830 */ 71, 72, 73, 74, 75, 76, 77, 152, 79, 80, /* 840 */ 81, 82, 83, 84, 85, 86, 87, 88, 152, 10, /* 850 */ 229, 10, 46, 24, 186, 26, 204, 205, 173, 174, /* 860 */ 131, 24, 12, 26, 103, 22, 27, 152, 27, 173, /* 870 */ 174, 92, 66, 67, 68, 69, 70, 71, 72, 73, /* 880 */ 74, 75, 76, 77, 152, 79, 80, 81, 82, 83, /* 890 */ 84, 85, 86, 87, 88, 152, 23, 229, 29, 152, /* 900 */ 27, 152, 33, 96, 159, 173, 174, 23, 35, 151, /* 910 */ 155, 27, 66, 10, 45, 108, 173, 174, 126, 35, /* 920 */ 173, 174, 173, 174, 49, 52, 152, 95, 96, 158, /* 930 */ 152, 92, 93, 92, 93, 62, 52, 192, 152, 66, /* 940 */ 152, 98, 96, 24, 229, 26, 62, 173, 174, 152, /* 950 */ 66, 173, 174, 24, 165, 26, 83, 84, 85, 173, /* 960 */ 174, 173, 174, 159, 91, 92, 93, 83, 84, 96, /* 970 */ 173, 174, 24, 152, 26, 91, 92, 93, 103, 152, /* 980 */ 96, 23, 139, 228, 10, 27, 136, 232, 26, 159, /* 990 */ 152, 10, 203, 35, 173, 174, 192, 55, 56, 115, /* 1000 */ 173, 174, 129, 130, 131, 132, 133, 134, 135, 103, /* 1010 */ 52, 173, 174, 129, 130, 131, 132, 133, 134, 135, /* 1020 */ 62, 24, 192, 117, 66, 24, 152, 26, 163, 189, /* 1030 */ 190, 24, 64, 26, 152, 10, 24, 152, 26, 152, /* 1040 */ 23, 83, 84, 10, 27, 152, 10, 173, 174, 91, /* 1050 */ 92, 93, 35, 152, 96, 173, 174, 152, 173, 174, /* 1060 */ 173, 174, 152, 159, 152, 103, 173, 174, 23, 52, /* 1070 */ 175, 159, 27, 48, 173, 174, 152, 36, 152, 62, /* 1080 */ 35, 159, 61, 66, 152, 173, 174, 129, 130, 131, /* 1090 */ 132, 133, 134, 135, 136, 127, 192, 52, 117, 115, /* 1100 */ 83, 84, 85, 152, 192, 173, 174, 62, 91, 92, /* 1110 */ 93, 66, 128, 96, 192, 12, 211, 191, 152, 152, /* 1120 */ 17, 18, 19, 20, 173, 174, 103, 215, 83, 84, /* 1130 */ 152, 115, 152, 30, 152, 32, 91, 92, 93, 227, /* 1140 */ 216, 96, 39, 152, 128, 152, 129, 130, 131, 132, /* 1150 */ 133, 134, 135, 24, 51, 26, 53, 191, 191, 126, /* 1160 */ 152, 58, 141, 60, 173, 174, 63, 152, 44, 191, /* 1170 */ 152, 191, 152, 191, 129, 130, 131, 132, 133, 134, /* 1180 */ 135, 173, 174, 183, 191, 175, 48, 176, 173, 174, /* 1190 */ 152, 173, 174, 173, 174, 152, 102, 175, 152, 23, /* 1200 */ 152, 177, 152, 175, 152, 117, 152, 104, 105, 106, /* 1210 */ 196, 173, 174, 110, 152, 117, 173, 174, 115, 173, /* 1220 */ 174, 173, 174, 173, 174, 173, 174, 173, 174, 115, /* 1230 */ 193, 192, 152, 126, 194, 173, 174, 152, 123, 152, /* 1240 */ 198, 152, 124, 152, 197, 152, 121, 152, 199, 117, /* 1250 */ 117, 200, 125, 173, 174, 23, 201, 152, 173, 174, /* 1260 */ 173, 174, 173, 174, 173, 174, 173, 174, 173, 174, /* 1270 */ 24, 152, 24, 165, 88, 231, 96, 115, 152, 115, /* 1280 */ 115, 23, 136, 225, 231, 226, 18, 23, 26, 190, /* 1290 */ 24, 152, 117, 24, 152, 122, 156, 26, 101, 176, /* 1300 */ 214, 27, 26, 122, 214, 164, 176, 206, 152, 152, /* 1310 */ 119, 152, 152, 103, 156, 120, 207, 23, 208, 152, /* 1320 */ 24, 208, 117, 207, 24, 175, 152, 23, 179, 178, /* 1330 */ 152, 214, 164, 181, 214, 182, 182, 182, 48, 176, /* 1340 */ 152, 23, 176, 173, 183, 173, 24, 23, 23, 48, /* 1350 */ 100, 152, 175, 108, 185, 152, 185, 178, 175, 177, /* 1360 */ 156, 152, 156, 179, 25, 152, 235, 156, 234, 42, /* 1370 */ 103, 156, 236, 12, 237, 40, 103, 49, 103, 139, /* 1380 */ 152, 156, 103, 152, 10, 23, 139, 175, 12, 188, /* 1390 */ 127, 18, 127, 10, 10, 18, 64, 197, 107, 73, /* 1400 */ 10, 152, 188, 152, 73, 127, 152, 218, 23, 23, /* 1410 */ 10, 118, 152, 197, 10, 10, 10, 10, 10, 197, /* 1420 */ 118, 10, 188, 107, 197, 10, 127, 10, 10, 152, /* 1430 */ 10, 10, 23, 152, 10, 218, 156, 10, 152, 10, /* 1440 */ 24, 239, 10, 10, 25, 10, 239, 37, 165, 152, /* 1450 */ 165, 10, 10, 10, 156, 152, 10, 152, 240, 152, /* 1460 */ 21, 140, 156, 152, 141, 242, 10, 243, 243, 243, /* 1470 */ 243, 142, }; #define YY_SHIFT_USE_DFLT (-72) static const short yy_shift_ofst[] = { /* 0 */ 201, 81, -72, -72, 1103, -9, 127, -72, 235, 603, /* 10 */ 318, 286, 427, -72, -72, -72, -72, -72, -72, 603, /* 20 */ 639, 603, 671, 603, 903, 277, 974, 400, 748, 997, /* 30 */ 1036, 51, -72, 402, -72, 226, -72, 400, 345, -72, /* 40 */ 1023, -72, 1041, 395, -72, -72, -72, -72, -72, -72, /* 50 */ -72, 807, 1023, -72, 1124, -72, 560, -72, -72, 1138, /* 60 */ 522, 1023, 1094, -72, -72, -72, -72, 1023, -72, 1176, /* 70 */ 1045, 30, 873, 1088, 1098, -72, 884, -72, 388, 1114, /* 80 */ -72, 310, -72, -19, 1107, 1115, 1118, 1125, 1127, -72, /* 90 */ 1045, 40, 1045, 665, 1045, -72, 1132, 400, 1133, 400, /* 100 */ -72, -72, -72, -72, -72, -72, 1232, 1045, 105, 402, /* 110 */ -72, -72, 340, 630, 790, -72, 630, 1246, -72, -72, /* 120 */ -72, 679, -72, -72, -72, 679, -72, -72, -72, -72, /* 130 */ 1248, -72, 1045, -72, 759, 1045, -11, 1045, -11, 1045, /* 140 */ -11, 1045, -11, 1045, -71, 1045, -71, 1045, -50, 1045, /* 150 */ -50, 1045, -50, 1045, -50, 1045, 168, 1045, 168, 1045, /* 160 */ 1186, 1045, 1186, 1045, 1186, 1045, -72, -72, 441, -72, /* 170 */ -72, -72, -72, 1045, -56, 1045, -11, -72, 846, -72, /* 180 */ 1180, -72, -72, -72, 1045, 712, 1045, -71, -72, 289, /* 190 */ 884, 393, 700, 1162, 1164, 1165, -72, 665, 1045, 806, /* 200 */ 1045, -72, 1045, -72, 1045, -72, 1258, 1114, 401, -72, /* 210 */ 958, 152, 1146, 416, 1268, -72, 1045, 199, 1045, 665, /* 220 */ 1264, 530, 1266, -72, 1262, 400, 1269, -72, 1045, 273, /* 230 */ 1045, 320, 1045, 665, 793, -72, 1045, -72, -72, 1175, /* 240 */ 400, -72, -72, -72, 806, 1045, 665, 1173, 1045, 1271, /* 250 */ 1045, 1197, 522, -72, 1274, -72, -72, 665, 1197, 522, /* 260 */ -72, 1045, 665, 1181, 1045, 1276, 1045, 665, -72, -72, /* 270 */ 635, -72, -72, -72, 458, -72, 463, -72, 1191, -72, /* 280 */ 534, 1175, 779, 400, -72, -72, 1210, 1195, -72, 1294, /* 290 */ 400, 829, -72, 400, -72, -72, 1045, 665, 1114, 467, /* 300 */ 279, 1296, 779, 1210, 1195, -72, 1017, -25, -72, -72, /* 310 */ 1205, 536, -72, -72, -72, -72, 394, -72, 837, -72, /* 320 */ 1300, -72, 459, 1023, -72, 400, 1304, -72, 112, -72, /* 330 */ 400, -72, 619, 662, -72, 832, -72, -72, -72, -72, /* 340 */ 662, -72, 662, -72, 400, 919, -72, 400, 1197, 522, /* 350 */ -72, -72, 1197, 522, -72, -72, 1274, -72, 1124, -72, /* 360 */ -72, 70, -72, 1045, 524, -72, 239, -72, -72, 239, /* 370 */ -72, -72, -72, -72, 58, 149, -72, 400, -72, 1290, /* 380 */ 1318, 400, 59, 1322, 1023, -72, 1324, 400, 929, 1023, /* 390 */ -72, 1045, 571, -72, 1301, 1325, 400, 948, 1250, 400, /* 400 */ 1304, -72, 517, 1245, -72, -72, -72, -72, -72, 1114, /* 410 */ 552, 843, 754, 400, 1175, -72, 400, 140, 1339, 1114, /* 420 */ 556, 400, 1175, 869, 657, 1267, 400, 1175, -72, 1327, /* 430 */ 850, 1361, 1045, 618, 1335, 942, -72, -72, 1273, 1275, /* 440 */ 875, 400, 962, -72, -72, 1328, -72, -72, 1240, 400, /* 450 */ 906, 1279, 400, 1362, 400, 1001, 761, 1374, 1247, 1376, /* 460 */ 189, 562, 968, 395, -72, 1263, 1265, 1373, 1383, 1384, /* 470 */ 189, 1377, 1332, 400, 1291, 400, 792, 400, 1326, 1045, /* 480 */ 665, 1390, 1331, 1045, 665, 1278, 400, 1385, 400, 1007, /* 490 */ -72, 984, 604, 1386, 1045, 1012, 1045, 665, 1400, 665, /* 500 */ 1293, 400, 1033, 1404, 651, 400, 1405, 400, 1406, 400, /* 510 */ 1407, 400, 1408, 566, 1302, 400, 1033, 1411, 1332, 400, /* 520 */ 1316, 400, 792, 1415, 1299, 400, 1385, 1016, 608, 1409, /* 530 */ 1045, 1129, 1417, 476, 1418, 400, 1175, 697, 111, 1420, /* 540 */ 1421, 1424, 1427, 400, 1416, 1429, 1410, 402, 1419, 400, /* 550 */ 1025, 1432, 729, 1433, 1435, -72, 1410, 400, 1441, 839, /* 560 */ 981, 1442, 841, 981, 1443, 1439, 400, 1021, 1321, 400, /* 570 */ 1446, 1323, 1329, 400, 1456, -72, -72, -72, }; #define YY_REDUCE_USE_DFLT (-151) static const short yy_reduce_ofst[] = { /* 0 */ 64, 95, -151, -151, -59, -151, -151, -151, 33, 155, /* 10 */ -151, 224, -151, -151, -151, -151, -151, -151, -151, 428, /* 20 */ -151, 509, -151, 758, -151, 430, -151, 45, 771, -151, /* 30 */ -151, -21, -151, -64, 865, 244, -151, 910, -85, -151, /* 40 */ 895, -151, -151, -125, -151, -151, -151, -151, -151, -151, /* 50 */ -151, -151, 1010, -151, 1000, -151, -151, -151, -151, -151, /* 60 */ 1011, 1022, 1024, -151, -151, -151, -151, 1028, -151, -151, /* 70 */ 125, -151, 156, -151, -151, -151, 159, -151, 1037, 1039, /* 80 */ -151, 1040, 420, 1014, 1047, 1042, 1049, 1051, 1055, -151, /* 90 */ 348, 411, 450, 411, 649, -151, -151, 1105, -151, 1119, /* 100 */ -151, -151, -151, -151, -151, -151, -151, 685, 411, 254, /* 110 */ -151, -151, 1108, -150, -151, -151, -34, -151, -151, -151, /* 120 */ -151, 1044, -151, -151, -151, 1053, -151, -151, -151, -151, /* 130 */ -151, -151, 696, -151, 411, 732, 411, 743, 411, 747, /* 140 */ 411, 749, 411, 778, 411, 786, 411, 788, 411, 797, /* 150 */ 411, 827, 411, 838, 411, 874, 411, 882, 411, 885, /* 160 */ 411, 887, 411, 893, 411, 901, 411, -151, -151, -151, /* 170 */ -151, -151, -151, 932, 39, 951, 411, -151, -151, -151, /* 180 */ -151, -151, -151, -151, 991, 411, 1008, 411, -151, 1126, /* 190 */ 912, 1037, -151, -151, -151, -151, -151, 411, 1015, 411, /* 200 */ 1018, 411, 1020, 411, 1038, 411, -151, 745, 1037, -151, /* 210 */ 343, 411, 1058, 1059, -151, -151, 1043, 411, 1046, 411, /* 220 */ -151, 1099, -151, -151, -151, 1139, -151, -151, 1048, 411, /* 230 */ 1050, 411, 1052, 411, -151, -151, 257, -151, -151, 1140, /* 240 */ 1142, -151, -151, -151, 411, 1054, 411, -151, 276, -151, /* 250 */ 346, 1086, 1123, -151, 1141, -151, -151, 411, 1090, 1130, /* 260 */ -151, 1062, 411, -151, 281, -151, 1080, 411, -151, 652, /* 270 */ 1101, -151, -151, -151, 1156, -151, 1157, -151, -151, -151, /* 280 */ 1159, 1158, 506, 1160, -151, -151, 1109, 1110, -151, -151, /* 290 */ 78, -151, -151, 1167, -151, -151, 1085, 411, -63, 1037, /* 300 */ 1101, -151, 789, 1116, 1113, -151, 1087, 87, -151, -151, /* 310 */ -151, 1105, -151, -151, -151, -151, 411, -151, -151, -151, /* 320 */ -151, -151, 411, 1150, -151, 1174, 1151, 1149, 1152, -151, /* 330 */ 1178, -151, -151, 1153, -151, -151, -151, -151, -151, -151, /* 340 */ 1154, -151, 1155, -151, 433, -151, -151, 715, 1117, 1163, /* 350 */ -151, -151, 1120, 1166, -151, -151, 1168, -151, 1161, -151, /* 360 */ -151, 593, -151, 1089, 411, -151, 1170, -151, -151, 1172, /* 370 */ -151, -151, -151, -151, 1169, 1171, -151, 1188, -151, -151, /* 380 */ -151, 526, 1182, -151, 1177, -151, -151, 574, -151, 1183, /* 390 */ -151, 1091, 142, -151, -151, -151, 621, -151, -151, 1199, /* 400 */ 1179, 1184, 193, -151, -151, -151, -151, -151, -151, 804, /* 410 */ 1037, 755, -151, 1203, 1204, -151, 1209, 1206, -151, 830, /* 420 */ 1037, 1213, 1211, 1134, 1131, -151, 261, 1215, -151, 1136, /* 430 */ 1137, -151, 774, 411, -151, -151, -151, -151, -151, -151, /* 440 */ -151, 516, -151, -151, -151, -151, -151, -151, -151, 1228, /* 450 */ 1225, -151, 1231, -151, 668, -151, 1212, -151, -151, -151, /* 460 */ 218, 1037, 1201, 840, -151, -151, -151, -151, -151, -151, /* 470 */ 280, -151, 1214, 1249, -151, 295, 1200, 1251, -151, 821, /* 480 */ 411, -151, -151, 1093, 411, -151, 1254, 1189, 905, -151, /* 490 */ -151, 904, 1037, -151, 413, -151, 1095, 411, -151, 411, /* 500 */ -151, 1260, 1216, -151, -151, 926, -151, 966, -151, 967, /* 510 */ -151, 978, -151, 1037, -151, 980, 1222, -151, 1234, 982, /* 520 */ -151, 924, 1227, -151, -151, 993, 1217, 922, 1037, -151, /* 530 */ 591, -151, -151, 1277, -151, 1281, 1280, -151, 145, -151, /* 540 */ -151, -151, -151, 1286, -151, -151, 1202, 1283, -151, 1297, /* 550 */ 1218, -151, 1285, -151, -151, -151, 1207, 1303, -151, 1305, /* 560 */ 1298, -151, 1307, 1306, -151, -151, -73, -151, -151, 1311, /* 570 */ -151, -151, 1223, 607, -151, -151, -151, -151, }; static const YYACTIONTYPE yy_default[] = { /* 0 */ 584, 584, 579, 582, 888, 888, 888, 583, 590, 888, /* 10 */ 888, 888, 888, 610, 611, 612, 591, 592, 593, 888, /* 20 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, /* 30 */ 888, 888, 603, 613, 623, 605, 622, 888, 888, 624, /* 40 */ 668, 631, 888, 888, 669, 672, 673, 674, 868, 869, /* 50 */ 870, 888, 668, 632, 653, 651, 888, 654, 655, 888, /* 60 */ 724, 668, 639, 633, 640, 722, 723, 668, 634, 888, /* 70 */ 888, 754, 820, 760, 755, 751, 888, 679, 888, 888, /* 80 */ 680, 688, 690, 697, 736, 727, 729, 717, 731, 685, /* 90 */ 888, 732, 888, 733, 888, 753, 888, 888, 756, 888, /* 100 */ 757, 758, 759, 761, 762, 763, 888, 888, 888, 888, /* 110 */ 608, 609, 615, 843, 888, 616, 843, 888, 617, 620, /* 120 */ 621, 888, 838, 840, 841, 888, 839, 842, 619, 618, /* 130 */ 888, 764, 888, 767, 769, 888, 770, 888, 771, 888, /* 140 */ 772, 888, 773, 888, 774, 888, 775, 888, 776, 888, /* 150 */ 777, 888, 778, 888, 779, 888, 780, 888, 781, 888, /* 160 */ 782, 888, 783, 888, 784, 888, 785, 786, 888, 787, /* 170 */ 794, 801, 804, 888, 789, 888, 788, 791, 888, 792, /* 180 */ 888, 795, 793, 800, 888, 888, 888, 802, 803, 888, /* 190 */ 820, 888, 888, 888, 888, 888, 807, 819, 888, 796, /* 200 */ 888, 797, 888, 798, 888, 799, 888, 888, 888, 809, /* 210 */ 888, 888, 888, 888, 888, 810, 888, 888, 888, 811, /* 220 */ 888, 888, 888, 866, 888, 888, 888, 867, 888, 888, /* 230 */ 888, 888, 888, 812, 888, 805, 820, 817, 818, 705, /* 240 */ 888, 706, 808, 790, 768, 888, 734, 888, 888, 718, /* 250 */ 888, 725, 724, 719, 888, 607, 726, 721, 725, 724, /* 260 */ 720, 888, 730, 888, 820, 728, 888, 737, 689, 700, /* 270 */ 698, 699, 708, 709, 888, 710, 888, 711, 888, 712, /* 280 */ 888, 705, 696, 888, 694, 695, 714, 716, 701, 888, /* 290 */ 888, 888, 715, 888, 749, 750, 888, 713, 700, 888, /* 300 */ 888, 888, 696, 714, 716, 702, 888, 696, 691, 692, /* 310 */ 888, 888, 693, 686, 687, 806, 888, 752, 888, 765, /* 320 */ 888, 766, 888, 668, 635, 888, 824, 641, 636, 642, /* 330 */ 888, 643, 888, 888, 644, 888, 647, 648, 649, 650, /* 340 */ 888, 645, 888, 646, 888, 888, 825, 888, 725, 724, /* 350 */ 826, 828, 725, 724, 827, 637, 888, 638, 653, 652, /* 360 */ 625, 888, 626, 888, 888, 627, 888, 628, 760, 888, /* 370 */ 629, 630, 614, 606, 888, 888, 658, 888, 661, 888, /* 380 */ 888, 888, 888, 888, 668, 662, 888, 888, 888, 668, /* 390 */ 663, 888, 668, 664, 888, 888, 888, 888, 888, 888, /* 400 */ 824, 641, 666, 888, 665, 667, 659, 660, 604, 888, /* 410 */ 888, 600, 888, 888, 705, 598, 888, 888, 888, 888, /* 420 */ 888, 888, 705, 849, 888, 888, 888, 705, 707, 854, /* 430 */ 888, 888, 888, 888, 888, 888, 855, 856, 888, 888, /* 440 */ 888, 888, 888, 846, 847, 888, 848, 599, 888, 888, /* 450 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, /* 460 */ 888, 888, 888, 888, 671, 888, 888, 888, 888, 888, /* 470 */ 888, 888, 670, 888, 888, 888, 888, 888, 888, 888, /* 480 */ 739, 888, 888, 888, 740, 888, 888, 747, 888, 888, /* 490 */ 748, 888, 888, 888, 888, 888, 888, 745, 888, 746, /* 500 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, /* 510 */ 888, 888, 888, 888, 888, 888, 888, 888, 670, 888, /* 520 */ 888, 888, 888, 888, 888, 888, 747, 888, 888, 888, /* 530 */ 888, 888, 888, 888, 888, 888, 705, 888, 843, 888, /* 540 */ 888, 888, 888, 888, 888, 888, 877, 888, 888, 888, /* 550 */ 888, 888, 888, 888, 888, 876, 877, 888, 888, 888, /* 560 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, /* 570 */ 888, 888, 886, 888, 888, 887, 585, 580, }; #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) /* The next table maps tokens into fallback tokens. If a construct ** like the following: ** ** %fallback ID X Y Z. |
︙ | ︙ | |||
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | 0, /* LP => nothing */ 0, /* RP => nothing */ 0, /* AS => nothing */ 0, /* COMMA => nothing */ 0, /* ID => nothing */ 27, /* ABORT => ID */ 27, /* AFTER => ID */ 27, /* ASC => ID */ 27, /* ATTACH => ID */ 27, /* BEFORE => ID */ 27, /* CASCADE => ID */ 27, /* CONFLICT => ID */ 27, /* DATABASE => ID */ 27, /* DESC => ID */ 27, /* DETACH => ID */ 27, /* EACH => ID */ 27, /* FAIL => ID */ 27, /* FOR => ID */ | > > | 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | 0, /* LP => nothing */ 0, /* RP => nothing */ 0, /* AS => nothing */ 0, /* COMMA => nothing */ 0, /* ID => nothing */ 27, /* ABORT => ID */ 27, /* AFTER => ID */ 27, /* ANALYZE => ID */ 27, /* ASC => ID */ 27, /* ATTACH => ID */ 27, /* BEFORE => ID */ 27, /* CASCADE => ID */ 27, /* CAST => ID */ 27, /* CONFLICT => ID */ 27, /* DATABASE => ID */ 27, /* DESC => ID */ 27, /* DETACH => ID */ 27, /* EACH => ID */ 27, /* FAIL => ID */ 27, /* FOR => ID */ |
︙ | ︙ | |||
868 869 870 871 872 873 874 | "$", "END_OF_FILE", "ILLEGAL", "SPACE", "UNCLOSED_STRING", "COMMENT", "FUNCTION", "COLUMN", "AGG_FUNCTION", "CONST_FUNC", "SEMI", "EXPLAIN", "BEGIN", "TRANSACTION", "DEFERRED", "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END", "ROLLBACK", "CREATE", "TABLE", "TEMP", "LP", "RP", "AS", "COMMA", "ID", | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 | "$", "END_OF_FILE", "ILLEGAL", "SPACE", "UNCLOSED_STRING", "COMMENT", "FUNCTION", "COLUMN", "AGG_FUNCTION", "CONST_FUNC", "SEMI", "EXPLAIN", "BEGIN", "TRANSACTION", "DEFERRED", "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END", "ROLLBACK", "CREATE", "TABLE", "TEMP", "LP", "RP", "AS", "COMMA", "ID", "ABORT", "AFTER", "ANALYZE", "ASC", "ATTACH", "BEFORE", "CASCADE", "CAST", "CONFLICT", "DATABASE", "DESC", "DETACH", "EACH", "FAIL", "FOR", "IGNORE", "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH", "KEY", "OF", "OFFSET", "PRAGMA", "RAISE", "REPLACE", "RESTRICT", "ROW", "STATEMENT", "TRIGGER", "VACUUM", "VIEW", "REINDEX", "RENAME", "CTIME_KW", "ALTER", "OR", "AND", "NOT", "IS", "BETWEEN", "IN", "ISNULL", "NOTNULL", "NE", "EQ", "GT", "LE", "LT", "GE", "ESCAPE", "BITAND", "BITOR", "LSHIFT", "RSHIFT", "PLUS", "MINUS", "STAR", "SLASH", "REM", "CONCAT", "UMINUS", "UPLUS", "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT", "DEFAULT", "NULL", "PRIMARY", "UNIQUE", "CHECK", "REFERENCES", "COLLATE", "AUTOINCR", "ON", "DELETE", "UPDATE", "INSERT", "SET", "DEFERRABLE", "FOREIGN", "DROP", "UNION", "ALL", "INTERSECT", "EXCEPT", "SELECT", "DISTINCT", "DOT", "FROM", "JOIN", "USING", "ORDER", "BY", "GROUP", "HAVING", "LIMIT", "WHERE", "INTO", "VALUES", "INTEGER", "FLOAT", "BLOB", "REGISTER", "VARIABLE", "EXISTS", "CASE", "WHEN", "THEN", "ELSE", "INDEX", "TO", "ADD", "COLUMNKW", "error", "input", "cmdlist", "ecmd", "cmdx", "cmd", "explain", "transtype", "trans_opt", "nm", "create_table", "create_table_args", "temp", "dbnm", "columnlist", "conslist_opt", "select", "column", "columnid", "type", "carglist", "id", "ids", "typetoken", "typename", "signed", "plus_num", "minus_num", "carg", "ccons", "term", "expr", "onconf", "sortorder", "autoinc", "idxlist_opt", "refargs", "defer_subclause", "refarg", "refact", "init_deferred_pred_opt", "conslist", "tcons", "idxlist", "defer_subclause_opt", "orconf", "resolvetype", "raisetype", "fullname", "oneselect", "multiselect_op", "distinct", "selcollist", "from", "where_opt", "groupby_opt", "having_opt", "orderby_opt", "limit_opt", "sclp", "as", "seltablist", "stl_prefix", "joinop", "on_opt", "using_opt", "seltablist_paren", "joinop2", "inscollist", "sortlist", "sortitem", "collate", "exprlist", "setlist", "insert_cmd", "inscollist_opt", "itemlist", "likeop", "escape", "between_op", "in_op", "case_operand", "case_exprlist", "case_else", "expritem", "uniqueflag", "idxitem", "plus_opt", "number", "trigger_decl", "trigger_cmd_list", "trigger_time", "trigger_event", "foreach_clause", "when_clause", "trigger_cmd", "database_kw_opt", "key_opt", "add_column_fullname", "kwcolumn_opt", }; #endif /* NDEBUG */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. */ static const char *const yyRuleName[] = { |
︙ | ︙ | |||
964 965 966 967 968 969 970 | /* 29 */ "id ::= ID", /* 30 */ "ids ::= ID", /* 31 */ "ids ::= STRING", /* 32 */ "nm ::= ID", /* 33 */ "nm ::= STRING", /* 34 */ "nm ::= JOIN_KW", /* 35 */ "type ::=", | | > | | | | | | < | | | | | | | > > | | | | | | | | | | | | | | | | < < | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < | | | | | | | | | | | | | | | | | | | | | | | | > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > | | | | | | 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 | /* 29 */ "id ::= ID", /* 30 */ "ids ::= ID", /* 31 */ "ids ::= STRING", /* 32 */ "nm ::= ID", /* 33 */ "nm ::= STRING", /* 34 */ "nm ::= JOIN_KW", /* 35 */ "type ::=", /* 36 */ "type ::= typetoken", /* 37 */ "typetoken ::= typename", /* 38 */ "typetoken ::= typename LP signed RP", /* 39 */ "typetoken ::= typename LP signed COMMA signed RP", /* 40 */ "typename ::= ids", /* 41 */ "typename ::= typename ids", /* 42 */ "signed ::= plus_num", /* 43 */ "signed ::= minus_num", /* 44 */ "carglist ::= carglist carg", /* 45 */ "carglist ::=", /* 46 */ "carg ::= CONSTRAINT nm ccons", /* 47 */ "carg ::= ccons", /* 48 */ "carg ::= DEFAULT term", /* 49 */ "carg ::= DEFAULT LP expr RP", /* 50 */ "carg ::= DEFAULT PLUS term", /* 51 */ "carg ::= DEFAULT MINUS term", /* 52 */ "carg ::= DEFAULT id", /* 53 */ "ccons ::= NULL onconf", /* 54 */ "ccons ::= NOT NULL onconf", /* 55 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc", /* 56 */ "ccons ::= UNIQUE onconf", /* 57 */ "ccons ::= CHECK LP expr RP onconf", /* 58 */ "ccons ::= REFERENCES nm idxlist_opt refargs", /* 59 */ "ccons ::= defer_subclause", /* 60 */ "ccons ::= COLLATE id", /* 61 */ "autoinc ::=", /* 62 */ "autoinc ::= AUTOINCR", /* 63 */ "refargs ::=", /* 64 */ "refargs ::= refargs refarg", /* 65 */ "refarg ::= MATCH nm", /* 66 */ "refarg ::= ON DELETE refact", /* 67 */ "refarg ::= ON UPDATE refact", /* 68 */ "refarg ::= ON INSERT refact", /* 69 */ "refact ::= SET NULL", /* 70 */ "refact ::= SET DEFAULT", /* 71 */ "refact ::= CASCADE", /* 72 */ "refact ::= RESTRICT", /* 73 */ "defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt", /* 74 */ "defer_subclause ::= DEFERRABLE init_deferred_pred_opt", /* 75 */ "init_deferred_pred_opt ::=", /* 76 */ "init_deferred_pred_opt ::= INITIALLY DEFERRED", /* 77 */ "init_deferred_pred_opt ::= INITIALLY IMMEDIATE", /* 78 */ "conslist_opt ::=", /* 79 */ "conslist_opt ::= COMMA conslist", /* 80 */ "conslist ::= conslist COMMA tcons", /* 81 */ "conslist ::= conslist tcons", /* 82 */ "conslist ::= tcons", /* 83 */ "tcons ::= CONSTRAINT nm", /* 84 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf", /* 85 */ "tcons ::= UNIQUE LP idxlist RP onconf", /* 86 */ "tcons ::= CHECK expr onconf", /* 87 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt", /* 88 */ "defer_subclause_opt ::=", /* 89 */ "defer_subclause_opt ::= defer_subclause", /* 90 */ "onconf ::=", /* 91 */ "onconf ::= ON CONFLICT resolvetype", /* 92 */ "orconf ::=", /* 93 */ "orconf ::= OR resolvetype", /* 94 */ "resolvetype ::= raisetype", /* 95 */ "resolvetype ::= IGNORE", /* 96 */ "resolvetype ::= REPLACE", /* 97 */ "cmd ::= DROP TABLE fullname", /* 98 */ "cmd ::= CREATE temp VIEW nm dbnm AS select", /* 99 */ "cmd ::= DROP VIEW fullname", /* 100 */ "cmd ::= select", /* 101 */ "select ::= oneselect", /* 102 */ "select ::= select multiselect_op oneselect", /* 103 */ "multiselect_op ::= UNION", /* 104 */ "multiselect_op ::= UNION ALL", /* 105 */ "multiselect_op ::= INTERSECT", /* 106 */ "multiselect_op ::= EXCEPT", /* 107 */ "oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt", /* 108 */ "distinct ::= DISTINCT", /* 109 */ "distinct ::= ALL", /* 110 */ "distinct ::=", /* 111 */ "sclp ::= selcollist COMMA", /* 112 */ "sclp ::=", /* 113 */ "selcollist ::= sclp expr as", /* 114 */ "selcollist ::= sclp STAR", /* 115 */ "selcollist ::= sclp nm DOT STAR", /* 116 */ "as ::= AS nm", /* 117 */ "as ::= ids", /* 118 */ "as ::=", /* 119 */ "from ::=", /* 120 */ "from ::= FROM seltablist", /* 121 */ "stl_prefix ::= seltablist joinop", /* 122 */ "stl_prefix ::=", /* 123 */ "seltablist ::= stl_prefix nm dbnm as on_opt using_opt", /* 124 */ "seltablist ::= stl_prefix LP seltablist_paren RP as on_opt using_opt", /* 125 */ "seltablist_paren ::= select", /* 126 */ "seltablist_paren ::= seltablist", /* 127 */ "dbnm ::=", /* 128 */ "dbnm ::= DOT nm", /* 129 */ "fullname ::= nm dbnm", /* 130 */ "joinop ::= COMMA", /* 131 */ "joinop ::= JOIN", /* 132 */ "joinop ::= JOIN_KW JOIN", /* 133 */ "joinop ::= JOIN_KW nm JOIN", /* 134 */ "joinop ::= JOIN_KW nm nm JOIN", /* 135 */ "on_opt ::= ON expr", /* 136 */ "on_opt ::=", /* 137 */ "using_opt ::= USING LP inscollist RP", /* 138 */ "using_opt ::=", /* 139 */ "orderby_opt ::=", /* 140 */ "orderby_opt ::= ORDER BY sortlist", /* 141 */ "sortlist ::= sortlist COMMA sortitem collate sortorder", /* 142 */ "sortlist ::= sortitem collate sortorder", /* 143 */ "sortitem ::= expr", /* 144 */ "sortorder ::= ASC", /* 145 */ "sortorder ::= DESC", /* 146 */ "sortorder ::=", /* 147 */ "collate ::=", /* 148 */ "collate ::= COLLATE id", /* 149 */ "groupby_opt ::=", /* 150 */ "groupby_opt ::= GROUP BY exprlist", /* 151 */ "having_opt ::=", /* 152 */ "having_opt ::= HAVING expr", /* 153 */ "limit_opt ::=", /* 154 */ "limit_opt ::= LIMIT expr", /* 155 */ "limit_opt ::= LIMIT expr OFFSET expr", /* 156 */ "limit_opt ::= LIMIT expr COMMA expr", /* 157 */ "cmd ::= DELETE FROM fullname where_opt", /* 158 */ "where_opt ::=", /* 159 */ "where_opt ::= WHERE expr", /* 160 */ "cmd ::= UPDATE orconf fullname SET setlist where_opt", /* 161 */ "setlist ::= setlist COMMA nm EQ expr", /* 162 */ "setlist ::= nm EQ expr", /* 163 */ "cmd ::= insert_cmd INTO fullname inscollist_opt VALUES LP itemlist RP", /* 164 */ "cmd ::= insert_cmd INTO fullname inscollist_opt select", /* 165 */ "insert_cmd ::= INSERT orconf", /* 166 */ "insert_cmd ::= REPLACE", /* 167 */ "itemlist ::= itemlist COMMA expr", /* 168 */ "itemlist ::= expr", /* 169 */ "inscollist_opt ::=", /* 170 */ "inscollist_opt ::= LP inscollist RP", /* 171 */ "inscollist ::= inscollist COMMA nm", /* 172 */ "inscollist ::= nm", /* 173 */ "expr ::= term", /* 174 */ "expr ::= LP expr RP", /* 175 */ "term ::= NULL", /* 176 */ "expr ::= ID", /* 177 */ "expr ::= JOIN_KW", /* 178 */ "expr ::= nm DOT nm", /* 179 */ "expr ::= nm DOT nm DOT nm", /* 180 */ "term ::= INTEGER", /* 181 */ "term ::= FLOAT", /* 182 */ "term ::= STRING", /* 183 */ "term ::= BLOB", /* 184 */ "expr ::= REGISTER", /* 185 */ "expr ::= VARIABLE", /* 186 */ "expr ::= CAST LP expr AS typetoken RP", /* 187 */ "expr ::= ID LP exprlist RP", /* 188 */ "expr ::= ID LP STAR RP", /* 189 */ "term ::= CTIME_KW", /* 190 */ "expr ::= expr AND expr", /* 191 */ "expr ::= expr OR expr", /* 192 */ "expr ::= expr LT expr", /* 193 */ "expr ::= expr GT expr", /* 194 */ "expr ::= expr LE expr", /* 195 */ "expr ::= expr GE expr", /* 196 */ "expr ::= expr NE expr", /* 197 */ "expr ::= expr EQ expr", /* 198 */ "expr ::= expr BITAND expr", /* 199 */ "expr ::= expr BITOR expr", /* 200 */ "expr ::= expr LSHIFT expr", /* 201 */ "expr ::= expr RSHIFT expr", /* 202 */ "expr ::= expr PLUS expr", /* 203 */ "expr ::= expr MINUS expr", /* 204 */ "expr ::= expr STAR expr", /* 205 */ "expr ::= expr SLASH expr", /* 206 */ "expr ::= expr REM expr", /* 207 */ "expr ::= expr CONCAT expr", /* 208 */ "likeop ::= LIKE_KW", /* 209 */ "likeop ::= NOT LIKE_KW", /* 210 */ "escape ::= ESCAPE expr", /* 211 */ "escape ::=", /* 212 */ "expr ::= expr likeop expr escape", /* 213 */ "expr ::= expr ISNULL", /* 214 */ "expr ::= expr IS NULL", /* 215 */ "expr ::= expr NOTNULL", /* 216 */ "expr ::= expr NOT NULL", /* 217 */ "expr ::= expr IS NOT NULL", /* 218 */ "expr ::= NOT expr", /* 219 */ "expr ::= BITNOT expr", /* 220 */ "expr ::= MINUS expr", /* 221 */ "expr ::= PLUS expr", /* 222 */ "between_op ::= BETWEEN", /* 223 */ "between_op ::= NOT BETWEEN", /* 224 */ "expr ::= expr between_op expr AND expr", /* 225 */ "in_op ::= IN", /* 226 */ "in_op ::= NOT IN", /* 227 */ "expr ::= expr in_op LP exprlist RP", /* 228 */ "expr ::= LP select RP", /* 229 */ "expr ::= expr in_op LP select RP", /* 230 */ "expr ::= expr in_op nm dbnm", /* 231 */ "expr ::= EXISTS LP select RP", /* 232 */ "expr ::= CASE case_operand case_exprlist case_else END", /* 233 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", /* 234 */ "case_exprlist ::= WHEN expr THEN expr", /* 235 */ "case_else ::= ELSE expr", /* 236 */ "case_else ::=", /* 237 */ "case_operand ::= expr", /* 238 */ "case_operand ::=", /* 239 */ "exprlist ::= exprlist COMMA expritem", /* 240 */ "exprlist ::= expritem", /* 241 */ "expritem ::= expr", /* 242 */ "expritem ::=", /* 243 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf", /* 244 */ "uniqueflag ::= UNIQUE", /* 245 */ "uniqueflag ::=", /* 246 */ "idxlist_opt ::=", /* 247 */ "idxlist_opt ::= LP idxlist RP", /* 248 */ "idxlist ::= idxlist COMMA idxitem collate sortorder", /* 249 */ "idxlist ::= idxitem collate sortorder", /* 250 */ "idxitem ::= nm", /* 251 */ "cmd ::= DROP INDEX fullname", /* 252 */ "cmd ::= VACUUM", /* 253 */ "cmd ::= VACUUM nm", /* 254 */ "cmd ::= PRAGMA nm dbnm EQ nm", /* 255 */ "cmd ::= PRAGMA nm dbnm EQ ON", /* 256 */ "cmd ::= PRAGMA nm dbnm EQ plus_num", /* 257 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", /* 258 */ "cmd ::= PRAGMA nm dbnm LP nm RP", /* 259 */ "cmd ::= PRAGMA nm dbnm", /* 260 */ "plus_num ::= plus_opt number", /* 261 */ "minus_num ::= MINUS number", /* 262 */ "number ::= INTEGER", /* 263 */ "number ::= FLOAT", /* 264 */ "plus_opt ::= PLUS", /* 265 */ "plus_opt ::=", /* 266 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END", /* 267 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", /* 268 */ "trigger_time ::= BEFORE", /* 269 */ "trigger_time ::= AFTER", /* 270 */ "trigger_time ::= INSTEAD OF", /* 271 */ "trigger_time ::=", /* 272 */ "trigger_event ::= DELETE", /* 273 */ "trigger_event ::= INSERT", /* 274 */ "trigger_event ::= UPDATE", /* 275 */ "trigger_event ::= UPDATE OF inscollist", /* 276 */ "foreach_clause ::=", /* 277 */ "foreach_clause ::= FOR EACH ROW", /* 278 */ "foreach_clause ::= FOR EACH STATEMENT", /* 279 */ "when_clause ::=", /* 280 */ "when_clause ::= WHEN expr", /* 281 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list", /* 282 */ "trigger_cmd_list ::=", /* 283 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt", /* 284 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP", /* 285 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select", /* 286 */ "trigger_cmd ::= DELETE FROM nm where_opt", /* 287 */ "trigger_cmd ::= select", /* 288 */ "expr ::= RAISE LP IGNORE RP", /* 289 */ "expr ::= RAISE LP raisetype COMMA nm RP", /* 290 */ "raisetype ::= ROLLBACK", /* 291 */ "raisetype ::= ABORT", /* 292 */ "raisetype ::= FAIL", /* 293 */ "cmd ::= DROP TRIGGER fullname", /* 294 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt", /* 295 */ "key_opt ::=", /* 296 */ "key_opt ::= KEY ids", /* 297 */ "key_opt ::= KEY BLOB", /* 298 */ "database_kw_opt ::= DATABASE", /* 299 */ "database_kw_opt ::=", /* 300 */ "cmd ::= DETACH database_kw_opt nm", /* 301 */ "cmd ::= REINDEX", /* 302 */ "cmd ::= REINDEX nm dbnm", /* 303 */ "cmd ::= ANALYZE", /* 304 */ "cmd ::= ANALYZE nm dbnm", /* 305 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", /* 306 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column", /* 307 */ "add_column_fullname ::= fullname", /* 308 */ "kwcolumn_opt ::=", /* 309 */ "kwcolumn_opt ::= COLUMNKW", }; #endif /* NDEBUG */ /* ** This function returns the symbolic name associated with a token ** value. */ |
︙ | ︙ | |||
1290 1291 1292 1293 1294 1295 1296 | ** 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. */ | | | | | | | | | | | | | | | | | | < | < | < < < < < < < < < < < > > > > > | > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 | ** reduce or during error processing or when a parser is ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those ** which appear on the RHS of the rule, but which are not used ** inside the C code. */ case 159: case 192: case 209: //#line 369 "parse.y" {sqlite3SelectDelete((yypminor->yy99));} //#line 1328 "parse.c" break; case 173: case 174: case 197: case 199: case 207: case 213: case 227: //#line 628 "parse.y" {sqlite3ExprDelete((yypminor->yy44));} //#line 1339 "parse.c" break; case 178: case 186: case 195: case 198: case 200: case 202: case 212: case 215: case 216: case 219: case 225: //#line 853 "parse.y" {sqlite3ExprListDelete((yypminor->yy412));} //#line 1354 "parse.c" break; case 191: case 196: case 204: case 205: //#line 498 "parse.y" {sqlite3SrcListDelete((yypminor->yy367));} //#line 1362 "parse.c" break; case 201: //#line 560 "parse.y" { sqlite3ExprDelete((yypminor->yy112).pLimit); sqlite3ExprDelete((yypminor->yy112).pOffset); } //#line 1370 "parse.c" break; case 208: case 211: case 218: //#line 516 "parse.y" {sqlite3IdListDelete((yypminor->yy258));} //#line 1377 "parse.c" break; case 233: case 238: //#line 946 "parse.y" {sqlite3DeleteTriggerStep((yypminor->yy203));} //#line 1383 "parse.c" break; case 235: //#line 930 "parse.y" {sqlite3IdListDelete((yypminor->yy234).b);} //#line 1388 "parse.c" break; default: break; /* If no destructor action specified: do nothing */ } } /* ** Pop the parser's stack once. |
︙ | ︙ | |||
1531 1532 1533 1534 1535 1536 1537 | /* 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[] = { | | | < < < | | > > > | | | | | | | | | < | < < < | | | | < < < | | < | | < < < | | < | | | | | | | < | | < | | | | | | | > | | > | | | | > | > | | | | | < < | | > | | | | | | > | > | | > | | < | | | | | | | | | | | | | < < < | | < < | | | | | | < | | | | < | < < | < | < | | < < < < | < < | < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < | | > | | | > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | > > | | | | | | 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 | /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ unsigned char nrhs; /* Number of right-hand side symbols in the rule */ } yyRuleInfo[] = { { 144, 1 }, { 145, 2 }, { 145, 1 }, { 147, 1 }, { 146, 1 }, { 146, 3 }, { 149, 0 }, { 149, 1 }, { 148, 3 }, { 151, 0 }, { 151, 1 }, { 151, 2 }, { 150, 0 }, { 150, 1 }, { 150, 1 }, { 150, 1 }, { 148, 2 }, { 148, 2 }, { 148, 2 }, { 148, 2 }, { 153, 5 }, { 155, 1 }, { 155, 0 }, { 154, 4 }, { 154, 2 }, { 157, 3 }, { 157, 1 }, { 160, 3 }, { 161, 1 }, { 164, 1 }, { 165, 1 }, { 165, 1 }, { 152, 1 }, { 152, 1 }, { 152, 1 }, { 162, 0 }, { 162, 1 }, { 166, 1 }, { 166, 4 }, { 166, 6 }, { 167, 1 }, { 167, 2 }, { 168, 1 }, { 168, 1 }, { 163, 2 }, { 163, 0 }, { 171, 3 }, { 171, 1 }, { 171, 2 }, { 171, 4 }, { 171, 3 }, { 171, 3 }, { 171, 2 }, { 172, 2 }, { 172, 3 }, { 172, 5 }, { 172, 2 }, { 172, 5 }, { 172, 4 }, { 172, 1 }, { 172, 2 }, { 177, 0 }, { 177, 1 }, { 179, 0 }, { 179, 2 }, { 181, 2 }, { 181, 3 }, { 181, 3 }, { 181, 3 }, { 182, 2 }, { 182, 2 }, { 182, 1 }, { 182, 1 }, { 180, 3 }, { 180, 2 }, { 183, 0 }, { 183, 2 }, { 183, 2 }, { 158, 0 }, { 158, 2 }, { 184, 3 }, { 184, 2 }, { 184, 1 }, { 185, 2 }, { 185, 7 }, { 185, 5 }, { 185, 3 }, { 185, 10 }, { 187, 0 }, { 187, 1 }, { 175, 0 }, { 175, 3 }, { 188, 0 }, { 188, 2 }, { 189, 1 }, { 189, 1 }, { 189, 1 }, { 148, 3 }, { 148, 7 }, { 148, 3 }, { 148, 1 }, { 159, 1 }, { 159, 3 }, { 193, 1 }, { 193, 2 }, { 193, 1 }, { 193, 1 }, { 192, 9 }, { 194, 1 }, { 194, 1 }, { 194, 0 }, { 202, 2 }, { 202, 0 }, { 195, 3 }, { 195, 2 }, { 195, 4 }, { 203, 2 }, { 203, 1 }, { 203, 0 }, { 196, 0 }, { 196, 2 }, { 205, 2 }, { 205, 0 }, { 204, 6 }, { 204, 7 }, { 209, 1 }, { 209, 1 }, { 156, 0 }, { 156, 2 }, { 191, 2 }, { 206, 1 }, { 206, 1 }, { 206, 2 }, { 206, 3 }, { 206, 4 }, { 207, 2 }, { 207, 0 }, { 208, 4 }, { 208, 0 }, { 200, 0 }, { 200, 3 }, { 212, 5 }, { 212, 3 }, { 213, 1 }, { 176, 1 }, { 176, 1 }, { 176, 0 }, { 214, 0 }, { 214, 2 }, { 198, 0 }, { 198, 3 }, { 199, 0 }, { 199, 2 }, { 201, 0 }, { 201, 2 }, { 201, 4 }, { 201, 4 }, { 148, 4 }, { 197, 0 }, { 197, 2 }, { 148, 6 }, { 216, 5 }, { 216, 3 }, { 148, 8 }, { 148, 5 }, { 217, 2 }, { 217, 1 }, { 219, 3 }, { 219, 1 }, { 218, 0 }, { 218, 3 }, { 211, 3 }, { 211, 1 }, { 174, 1 }, { 174, 3 }, { 173, 1 }, { 174, 1 }, { 174, 1 }, { 174, 3 }, { 174, 5 }, { 173, 1 }, { 173, 1 }, { 173, 1 }, { 173, 1 }, { 174, 1 }, { 174, 1 }, { 174, 6 }, { 174, 4 }, { 174, 4 }, { 173, 1 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 174, 3 }, { 220, 1 }, { 220, 2 }, { 221, 2 }, { 221, 0 }, { 174, 4 }, { 174, 2 }, { 174, 3 }, { 174, 2 }, { 174, 3 }, { 174, 4 }, { 174, 2 }, { 174, 2 }, { 174, 2 }, { 174, 2 }, { 222, 1 }, { 222, 2 }, { 174, 5 }, { 223, 1 }, { 223, 2 }, { 174, 5 }, { 174, 3 }, { 174, 5 }, { 174, 4 }, { 174, 4 }, { 174, 5 }, { 225, 5 }, { 225, 4 }, { 226, 2 }, { 226, 0 }, { 224, 1 }, { 224, 0 }, { 215, 3 }, { 215, 1 }, { 227, 1 }, { 227, 0 }, { 148, 11 }, { 228, 1 }, { 228, 0 }, { 178, 0 }, { 178, 3 }, { 186, 5 }, { 186, 3 }, { 229, 1 }, { 148, 3 }, { 148, 1 }, { 148, 2 }, { 148, 5 }, { 148, 5 }, { 148, 5 }, { 148, 5 }, { 148, 6 }, { 148, 3 }, { 169, 2 }, { 170, 2 }, { 231, 1 }, { 231, 1 }, { 230, 1 }, { 230, 0 }, { 148, 5 }, { 232, 10 }, { 234, 1 }, { 234, 1 }, { 234, 2 }, { 234, 0 }, { 235, 1 }, { 235, 1 }, { 235, 1 }, { 235, 3 }, { 236, 0 }, { 236, 3 }, { 236, 3 }, { 237, 0 }, { 237, 2 }, { 233, 3 }, { 233, 0 }, { 238, 6 }, { 238, 8 }, { 238, 5 }, { 238, 4 }, { 238, 1 }, { 174, 4 }, { 174, 6 }, { 190, 1 }, { 190, 1 }, { 190, 1 }, { 148, 3 }, { 148, 6 }, { 240, 0 }, { 240, 2 }, { 240, 2 }, { 239, 1 }, { 239, 0 }, { 148, 3 }, { 148, 1 }, { 148, 3 }, { 148, 1 }, { 148, 3 }, { 148, 6 }, { 148, 6 }, { 241, 1 }, { 242, 0 }, { 242, 1 }, }; static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. |
︙ | ︙ | |||
1885 1886 1887 1888 1889 1890 1891 | ** case 0: ** //#line <lineno> <grammarfile> ** { ... } // User supplied code ** //#line <lineno> <thisfile> ** break; */ case 3: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < > | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > | | | | > > | > | < < < < < < < | > | < < < < | > | | | | | | | | > > > > > | | | | > > > > > | | | | | < < < | < < < < < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > | > | > | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < | | | | | < | | | | < < < < < < | | < < < > | | | | | < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < | < | > | > | | < < < | > > | > | | > | < | < | | > > > > | | | | < < < | < | | > | > | | > | | | | > > > | | | | | | < | | | > | > | | < < < < | < | < | | < | > > > > > | > > > > > > > > > > < < < | | < | > > > > | < < < < | | > > | > > < < < < < < < < < | < < < < < | < < < < | > > | | | > > > > | < < > | < > > > | > > | | < < < < < < < < | > | > | > > > > | > > > > | | > > > > | > > > > | > > > > | | | | | > > > > > > > | | | | < < < < | | < < | < | < < < < < < < | | < < | < | | | | | | | < < < < | | | | | > | | | > > > > > > > > > > > > > > > > > | | > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > | | | | | | | | | | > | | | | | | | | | | | > > > > | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < | < < | | | > > > > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < | | < < < | < < < < < < | | | < | < < | | | < | < < | | | > > > > > > | | | | | | | | | | > > > > > > > | | | | | | | | > | | | | | | < | < | > > > > > > | | | | > > | | < < < < | | | | | | | | | < | < < < < < < < | < < | < < < < < < < < | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < < < < < < < < < | < < < < < | < < < < < < < < < < < | | | > | < < < < < | > | | < | > | > > > | < < < < | | < | < | | | | | | | > > > > > > | > | | | < > | > | > | | | | < < | < | | | | > | < > | | | | | | < < | > | > | | | | | | < | | > > > > > > > > > > | > > > > > > > > > | | | | | > > > | > > > > > > > > > > > > > > > | | | | < < | < | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < | < < | | > > | > | | | | | | | < > | < > > > > | | | < | < | | | | | | | | > > | > > | | | > > | | | | > > > > > > > > > > > | > > > > > > > > > > > > > | | | | | > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 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 | ** case 0: ** //#line <lineno> <grammarfile> ** { ... } // User supplied code ** //#line <lineno> <thisfile> ** break; */ case 3: //#line 102 "parse.y" { sqlite3FinishCoding(pParse); } //#line 1925 "parse.c" break; case 6: //#line 105 "parse.y" { sqlite3BeginParse(pParse, 0); } //#line 1930 "parse.c" break; case 7: //#line 107 "parse.y" { sqlite3BeginParse(pParse, 1); } //#line 1935 "parse.c" break; case 8: //#line 113 "parse.y" {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy58);} //#line 1940 "parse.c" break; case 12: //#line 118 "parse.y" {yygotominor.yy58 = TK_DEFERRED;} //#line 1945 "parse.c" break; case 13: case 14: case 15: case 103: case 105: case 106: //#line 119 "parse.y" {yygotominor.yy58 = yymsp[0].major;} //#line 1955 "parse.c" break; case 16: case 17: //#line 122 "parse.y" {sqlite3CommitTransaction(pParse);} //#line 1961 "parse.c" break; case 18: //#line 124 "parse.y" {sqlite3RollbackTransaction(pParse);} //#line 1966 "parse.c" break; case 20: //#line 129 "parse.y" { sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144,yymsp[-3].minor.yy58,0); } //#line 1973 "parse.c" break; case 21: case 62: case 76: case 108: case 223: case 226: //#line 134 "parse.y" {yygotominor.yy58 = 1;} //#line 1983 "parse.c" break; case 22: case 61: case 75: case 77: case 88: case 109: case 110: case 222: case 225: //#line 136 "parse.y" {yygotominor.yy58 = 0;} //#line 1996 "parse.c" break; case 23: //#line 137 "parse.y" { sqlite3EndTable(pParse,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy0,0); } //#line 2003 "parse.c" break; case 24: //#line 140 "parse.y" { sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy99); sqlite3SelectDelete(yymsp[0].minor.yy99); } //#line 2011 "parse.c" break; case 27: //#line 152 "parse.y" { yygotominor.yy144.z = yymsp[-2].minor.yy144.z; yygotominor.yy144.n = (pParse->sLastToken.z-yymsp[-2].minor.yy144.z) + pParse->sLastToken.n; } //#line 2019 "parse.c" break; case 28: //#line 156 "parse.y" { sqlite3AddColumn(pParse,&yymsp[0].minor.yy144); yygotominor.yy144 = yymsp[0].minor.yy144; } //#line 2027 "parse.c" break; case 29: case 30: case 31: case 32: case 33: case 34: case 262: case 263: //#line 166 "parse.y" {yygotominor.yy144 = yymsp[0].minor.yy0;} //#line 2039 "parse.c" break; case 36: //#line 226 "parse.y" {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy144);} //#line 2044 "parse.c" break; case 37: case 40: case 116: case 117: case 128: case 148: case 250: case 260: case 261: //#line 227 "parse.y" {yygotominor.yy144 = yymsp[0].minor.yy144;} //#line 2057 "parse.c" break; case 38: //#line 228 "parse.y" { yygotominor.yy144.z = yymsp[-3].minor.yy144.z; yygotominor.yy144.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-3].minor.yy144.z; } //#line 2065 "parse.c" break; case 39: //#line 232 "parse.y" { yygotominor.yy144.z = yymsp[-5].minor.yy144.z; yygotominor.yy144.n = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] - yymsp[-5].minor.yy144.z; } //#line 2073 "parse.c" break; case 41: //#line 238 "parse.y" {yygotominor.yy144.z=yymsp[-1].minor.yy144.z; yygotominor.yy144.n=yymsp[0].minor.yy144.n+(yymsp[0].minor.yy144.z-yymsp[-1].minor.yy144.z);} //#line 2078 "parse.c" break; case 42: //#line 240 "parse.y" { yygotominor.yy58 = atoi((const char *)yymsp[0].minor.yy144.z); } //#line 2083 "parse.c" break; case 43: //#line 241 "parse.y" { yygotominor.yy58 = -atoi((const char *)yymsp[0].minor.yy144.z); } //#line 2088 "parse.c" break; case 48: case 50: //#line 250 "parse.y" {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy44);} //#line 2094 "parse.c" break; case 49: //#line 251 "parse.y" {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy44);} //#line 2099 "parse.c" break; case 51: //#line 253 "parse.y" { Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy44, 0, 0); sqlite3AddDefaultValue(pParse,p); } //#line 2107 "parse.c" break; case 52: //#line 257 "parse.y" { Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy144); sqlite3AddDefaultValue(pParse,p); } //#line 2115 "parse.c" break; case 54: //#line 266 "parse.y" {sqlite3AddNotNull(pParse, yymsp[0].minor.yy58);} //#line 2120 "parse.c" break; case 55: //#line 268 "parse.y" {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy58,yymsp[0].minor.yy58);} //#line 2125 "parse.c" break; case 56: //#line 269 "parse.y" {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy58,0,0);} //#line 2130 "parse.c" break; case 57: //#line 270 "parse.y" {sqlite3ExprDelete(yymsp[-2].minor.yy44);} //#line 2135 "parse.c" break; case 58: //#line 272 "parse.y" {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy144,yymsp[-1].minor.yy412,yymsp[0].minor.yy58);} //#line 2140 "parse.c" break; case 59: //#line 273 "parse.y" {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy58);} //#line 2145 "parse.c" break; case 60: //#line 274 "parse.y" {sqlite3AddCollateType(pParse, (const char *)yymsp[0].minor.yy144.z, yymsp[0].minor.yy144.n);} //#line 2150 "parse.c" break; case 63: //#line 287 "parse.y" { yygotominor.yy58 = OE_Restrict * 0x010101; } //#line 2155 "parse.c" break; case 64: //#line 288 "parse.y" { yygotominor.yy58 = (yymsp[-1].minor.yy58 & yymsp[0].minor.yy35.mask) | yymsp[0].minor.yy35.value; } //#line 2160 "parse.c" break; case 65: //#line 290 "parse.y" { yygotominor.yy35.value = 0; yygotominor.yy35.mask = 0x000000; } //#line 2165 "parse.c" break; case 66: //#line 291 "parse.y" { yygotominor.yy35.value = yymsp[0].minor.yy58; yygotominor.yy35.mask = 0x0000ff; } //#line 2170 "parse.c" break; case 67: //#line 292 "parse.y" { yygotominor.yy35.value = yymsp[0].minor.yy58<<8; yygotominor.yy35.mask = 0x00ff00; } //#line 2175 "parse.c" break; case 68: //#line 293 "parse.y" { yygotominor.yy35.value = yymsp[0].minor.yy58<<16; yygotominor.yy35.mask = 0xff0000; } //#line 2180 "parse.c" break; case 69: //#line 295 "parse.y" { yygotominor.yy58 = OE_SetNull; } //#line 2185 "parse.c" break; case 70: //#line 296 "parse.y" { yygotominor.yy58 = OE_SetDflt; } //#line 2190 "parse.c" break; case 71: //#line 297 "parse.y" { yygotominor.yy58 = OE_Cascade; } //#line 2195 "parse.c" break; case 72: //#line 298 "parse.y" { yygotominor.yy58 = OE_Restrict; } //#line 2200 "parse.c" break; case 73: case 74: case 89: case 91: case 93: case 94: case 165: //#line 300 "parse.y" {yygotominor.yy58 = yymsp[0].minor.yy58;} //#line 2211 "parse.c" break; case 78: //#line 310 "parse.y" {yygotominor.yy144.n = 0; yygotominor.yy144.z = 0;} //#line 2216 "parse.c" break; case 79: //#line 311 "parse.y" {yygotominor.yy144 = yymsp[-1].minor.yy0;} //#line 2221 "parse.c" break; case 84: //#line 317 "parse.y" {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy412,yymsp[0].minor.yy58,yymsp[-2].minor.yy58);} //#line 2226 "parse.c" break; case 85: //#line 319 "parse.y" {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy412,yymsp[0].minor.yy58,0,0);} //#line 2231 "parse.c" break; case 87: //#line 322 "parse.y" { sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy412, &yymsp[-3].minor.yy144, yymsp[-2].minor.yy412, yymsp[-1].minor.yy58); sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy58); } //#line 2239 "parse.c" break; case 90: case 92: //#line 336 "parse.y" {yygotominor.yy58 = OE_Default;} //#line 2245 "parse.c" break; case 95: //#line 341 "parse.y" {yygotominor.yy58 = OE_Ignore;} //#line 2250 "parse.c" break; case 96: case 166: //#line 342 "parse.y" {yygotominor.yy58 = OE_Replace;} //#line 2256 "parse.c" break; case 97: //#line 346 "parse.y" { sqlite3DropTable(pParse, yymsp[0].minor.yy367, 0); } //#line 2263 "parse.c" break; case 98: //#line 353 "parse.y" { sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy144, &yymsp[-2].minor.yy144, yymsp[0].minor.yy99, yymsp[-5].minor.yy58); } //#line 2270 "parse.c" break; case 99: //#line 356 "parse.y" { sqlite3DropTable(pParse, yymsp[0].minor.yy367, 1); } //#line 2277 "parse.c" break; case 100: //#line 363 "parse.y" { sqlite3Select(pParse, yymsp[0].minor.yy99, SRT_Callback, 0, 0, 0, 0, 0); sqlite3SelectDelete(yymsp[0].minor.yy99); } //#line 2285 "parse.c" break; case 101: case 125: //#line 373 "parse.y" {yygotominor.yy99 = yymsp[0].minor.yy99;} //#line 2291 "parse.c" break; case 102: //#line 375 "parse.y" { if( yymsp[0].minor.yy99 ){ yymsp[0].minor.yy99->op = yymsp[-1].minor.yy58; yymsp[0].minor.yy99->pPrior = yymsp[-2].minor.yy99; } yygotominor.yy99 = yymsp[0].minor.yy99; } //#line 2302 "parse.c" break; case 104: //#line 384 "parse.y" {yygotominor.yy58 = TK_ALL;} //#line 2307 "parse.c" break; case 107: //#line 389 "parse.y" { yygotominor.yy99 = sqlite3SelectNew(yymsp[-6].minor.yy412,yymsp[-5].minor.yy367,yymsp[-4].minor.yy44,yymsp[-3].minor.yy412,yymsp[-2].minor.yy44,yymsp[-1].minor.yy412,yymsp[-7].minor.yy58,yymsp[0].minor.yy112.pLimit,yymsp[0].minor.yy112.pOffset); } //#line 2314 "parse.c" break; case 111: case 247: //#line 410 "parse.y" {yygotominor.yy412 = yymsp[-1].minor.yy412;} //#line 2320 "parse.c" break; case 112: case 139: case 149: case 246: //#line 411 "parse.y" {yygotominor.yy412 = 0;} //#line 2328 "parse.c" break; case 113: //#line 412 "parse.y" { yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-2].minor.yy412,yymsp[-1].minor.yy44,yymsp[0].minor.yy144.n?&yymsp[0].minor.yy144:0); } //#line 2335 "parse.c" break; case 114: //#line 415 "parse.y" { yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-1].minor.yy412, sqlite3Expr(TK_ALL, 0, 0, 0), 0); } //#line 2342 "parse.c" break; case 115: //#line 418 "parse.y" { Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0); Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy144); yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-3].minor.yy412, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0); } //#line 2351 "parse.c" break; case 118: //#line 430 "parse.y" {yygotominor.yy144.n = 0;} //#line 2356 "parse.c" break; case 119: //#line 442 "parse.y" {yygotominor.yy367 = (SrcList *)sqliteMalloc(sizeof(*yygotominor.yy367));} //#line 2361 "parse.c" break; case 120: //#line 443 "parse.y" {yygotominor.yy367 = yymsp[0].minor.yy367;} //#line 2366 "parse.c" break; case 121: //#line 448 "parse.y" { yygotominor.yy367 = yymsp[-1].minor.yy367; if( yygotominor.yy367 && yygotominor.yy367->nSrc>0 ) yygotominor.yy367->a[yygotominor.yy367->nSrc-1].jointype = yymsp[0].minor.yy58; } //#line 2374 "parse.c" break; case 122: //#line 452 "parse.y" {yygotominor.yy367 = 0;} //#line 2379 "parse.c" break; case 123: //#line 453 "parse.y" { yygotominor.yy367 = sqlite3SrcListAppend(yymsp[-5].minor.yy367,&yymsp[-4].minor.yy144,&yymsp[-3].minor.yy144); if( yymsp[-2].minor.yy144.n ) sqlite3SrcListAddAlias(yygotominor.yy367,&yymsp[-2].minor.yy144); if( yymsp[-1].minor.yy44 ){ if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pOn = yymsp[-1].minor.yy44; } else { sqlite3ExprDelete(yymsp[-1].minor.yy44); } } if( yymsp[0].minor.yy258 ){ if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pUsing = yymsp[0].minor.yy258; } else { sqlite3IdListDelete(yymsp[0].minor.yy258); } } } //#line 2395 "parse.c" break; case 124: //#line 467 "parse.y" { yygotominor.yy367 = sqlite3SrcListAppend(yymsp[-6].minor.yy367,0,0); yygotominor.yy367->a[yygotominor.yy367->nSrc-1].pSelect = yymsp[-4].minor.yy99; if( yymsp[-2].minor.yy144.n ) sqlite3SrcListAddAlias(yygotominor.yy367,&yymsp[-2].minor.yy144); if( yymsp[-1].minor.yy44 ){ if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pOn = yymsp[-1].minor.yy44; } else { sqlite3ExprDelete(yymsp[-1].minor.yy44); } } if( yymsp[0].minor.yy258 ){ if( yygotominor.yy367 && yygotominor.yy367->nSrc>1 ){ yygotominor.yy367->a[yygotominor.yy367->nSrc-2].pUsing = yymsp[0].minor.yy258; } else { sqlite3IdListDelete(yymsp[0].minor.yy258); } } } //#line 2412 "parse.c" break; case 126: //#line 488 "parse.y" { yygotominor.yy99 = sqlite3SelectNew(0,yymsp[0].minor.yy367,0,0,0,0,0,0,0); } //#line 2419 "parse.c" break; case 127: //#line 494 "parse.y" {yygotominor.yy144.z=0; yygotominor.yy144.n=0;} //#line 2424 "parse.c" break; case 129: //#line 499 "parse.y" {yygotominor.yy367 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144);} //#line 2429 "parse.c" break; case 130: case 131: //#line 503 "parse.y" { yygotominor.yy58 = JT_INNER; } //#line 2435 "parse.c" break; case 132: //#line 505 "parse.y" { yygotominor.yy58 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); } //#line 2440 "parse.c" break; case 133: //#line 506 "parse.y" { yygotominor.yy58 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy144,0); } //#line 2445 "parse.c" break; case 134: //#line 508 "parse.y" { yygotominor.yy58 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy144,&yymsp[-1].minor.yy144); } //#line 2450 "parse.c" break; case 135: case 143: case 152: case 159: case 173: case 210: case 235: case 237: case 241: //#line 512 "parse.y" {yygotominor.yy44 = yymsp[0].minor.yy44;} //#line 2463 "parse.c" break; case 136: case 151: case 158: case 211: case 236: case 238: case 242: //#line 513 "parse.y" {yygotominor.yy44 = 0;} //#line 2474 "parse.c" break; case 137: case 170: //#line 517 "parse.y" {yygotominor.yy258 = yymsp[-1].minor.yy258;} //#line 2480 "parse.c" break; case 138: case 169: //#line 518 "parse.y" {yygotominor.yy258 = 0;} //#line 2486 "parse.c" break; case 140: case 150: //#line 529 "parse.y" {yygotominor.yy412 = yymsp[0].minor.yy412;} //#line 2492 "parse.c" break; case 141: //#line 530 "parse.y" { yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412,yymsp[-2].minor.yy44,yymsp[-1].minor.yy144.n>0?&yymsp[-1].minor.yy144:0); if( yygotominor.yy412 ) yygotominor.yy412->a[yygotominor.yy412->nExpr-1].sortOrder = yymsp[0].minor.yy58; } //#line 2500 "parse.c" break; case 142: //#line 534 "parse.y" { yygotominor.yy412 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy44,yymsp[-1].minor.yy144.n>0?&yymsp[-1].minor.yy144:0); if( yygotominor.yy412 && yygotominor.yy412->a ) yygotominor.yy412->a[0].sortOrder = yymsp[0].minor.yy58; } //#line 2508 "parse.c" break; case 144: case 146: //#line 543 "parse.y" {yygotominor.yy58 = SQLITE_SO_ASC;} //#line 2514 "parse.c" break; case 145: //#line 544 "parse.y" {yygotominor.yy58 = SQLITE_SO_DESC;} //#line 2519 "parse.c" break; case 147: //#line 546 "parse.y" {yygotominor.yy144.z = 0; yygotominor.yy144.n = 0;} //#line 2524 "parse.c" break; case 153: //#line 564 "parse.y" {yygotominor.yy112.pLimit = 0; yygotominor.yy112.pOffset = 0;} //#line 2529 "parse.c" break; case 154: //#line 565 "parse.y" {yygotominor.yy112.pLimit = yymsp[0].minor.yy44; yygotominor.yy112.pOffset = 0;} //#line 2534 "parse.c" break; case 155: //#line 567 "parse.y" {yygotominor.yy112.pLimit = yymsp[-2].minor.yy44; yygotominor.yy112.pOffset = yymsp[0].minor.yy44;} //#line 2539 "parse.c" break; case 156: //#line 569 "parse.y" {yygotominor.yy112.pOffset = yymsp[-2].minor.yy44; yygotominor.yy112.pLimit = yymsp[0].minor.yy44;} //#line 2544 "parse.c" break; case 157: //#line 573 "parse.y" {sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy367,yymsp[0].minor.yy44);} //#line 2549 "parse.c" break; case 160: //#line 584 "parse.y" {sqlite3Update(pParse,yymsp[-3].minor.yy367,yymsp[-1].minor.yy412,yymsp[0].minor.yy44,yymsp[-4].minor.yy58);} //#line 2554 "parse.c" break; case 161: //#line 590 "parse.y" {yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412,yymsp[0].minor.yy44,&yymsp[-2].minor.yy144);} //#line 2559 "parse.c" break; case 162: //#line 591 "parse.y" {yygotominor.yy412 = sqlite3ExprListAppend(0,yymsp[0].minor.yy44,&yymsp[-2].minor.yy144);} //#line 2564 "parse.c" break; case 163: //#line 597 "parse.y" {sqlite3Insert(pParse, yymsp[-5].minor.yy367, yymsp[-1].minor.yy412, 0, yymsp[-4].minor.yy258, yymsp[-7].minor.yy58);} //#line 2569 "parse.c" break; case 164: //#line 599 "parse.y" {sqlite3Insert(pParse, yymsp[-2].minor.yy367, 0, yymsp[0].minor.yy99, yymsp[-1].minor.yy258, yymsp[-4].minor.yy58);} //#line 2574 "parse.c" break; case 167: case 239: //#line 609 "parse.y" {yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-2].minor.yy412,yymsp[0].minor.yy44,0);} //#line 2580 "parse.c" break; case 168: case 240: //#line 610 "parse.y" {yygotominor.yy412 = sqlite3ExprListAppend(0,yymsp[0].minor.yy44,0);} //#line 2586 "parse.c" break; case 171: //#line 619 "parse.y" {yygotominor.yy258 = sqlite3IdListAppend(yymsp[-2].minor.yy258,&yymsp[0].minor.yy144);} //#line 2591 "parse.c" break; case 172: //#line 620 "parse.y" {yygotominor.yy258 = sqlite3IdListAppend(0,&yymsp[0].minor.yy144);} //#line 2596 "parse.c" break; case 174: //#line 631 "parse.y" {yygotominor.yy44 = yymsp[-1].minor.yy44; sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } //#line 2601 "parse.c" break; case 175: case 180: case 181: case 182: case 183: //#line 632 "parse.y" {yygotominor.yy44 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);} //#line 2610 "parse.c" break; case 176: case 177: //#line 633 "parse.y" {yygotominor.yy44 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);} //#line 2616 "parse.c" break; case 178: //#line 635 "parse.y" { Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy144); Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy144); yygotominor.yy44 = sqlite3Expr(TK_DOT, temp1, temp2, 0); } //#line 2625 "parse.c" break; case 179: //#line 640 "parse.y" { Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy144); Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy144); Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy144); Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0); yygotominor.yy44 = sqlite3Expr(TK_DOT, temp1, temp4, 0); } //#line 2636 "parse.c" break; case 184: //#line 651 "parse.y" {yygotominor.yy44 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);} //#line 2641 "parse.c" break; case 185: //#line 652 "parse.y" { Token *pToken = &yymsp[0].minor.yy0; Expr *pExpr = yygotominor.yy44 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); sqlite3ExprAssignVarNumber(pParse, pExpr); } //#line 2650 "parse.c" break; case 186: //#line 658 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_CAST, yymsp[-3].minor.yy44, 0, &yymsp[-1].minor.yy144); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); } //#line 2658 "parse.c" break; case 187: //#line 663 "parse.y" { yygotominor.yy44 = sqlite3ExprFunction(yymsp[-1].minor.yy412, &yymsp[-3].minor.yy0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } //#line 2666 "parse.c" break; case 188: //#line 667 "parse.y" { yygotominor.yy44 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } //#line 2674 "parse.c" break; case 189: //#line 671 "parse.y" { /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are ** treated as functions that return constants */ yygotominor.yy44 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0); if( yygotominor.yy44 ) yygotominor.yy44->op = TK_CONST_FUNC; } //#line 2684 "parse.c" break; case 190: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 201: case 202: case 203: case 204: case 205: case 206: case 207: //#line 677 "parse.y" {yygotominor.yy44 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy44, yymsp[0].minor.yy44, 0);} //#line 2706 "parse.c" break; case 208: //#line 696 "parse.y" {yygotominor.yy432._operator = yymsp[0].minor.yy0; yygotominor.yy432.not = 0;} //#line 2711 "parse.c" break; case 209: //#line 697 "parse.y" {yygotominor.yy432._operator = yymsp[0].minor.yy0; yygotominor.yy432.not = 1;} //#line 2716 "parse.c" break; case 212: //#line 701 "parse.y" { ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy44, 0); pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy44, 0); if( yymsp[0].minor.yy44 ){ pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy44, 0); } yygotominor.yy44 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy432._operator); if( yymsp[-2].minor.yy432.not ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44, &yymsp[-3].minor.yy44->span, &yymsp[-1].minor.yy44->span); } //#line 2730 "parse.c" break; case 213: //#line 712 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2738 "parse.c" break; case 214: //#line 716 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2746 "parse.c" break; case 215: //#line 720 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2754 "parse.c" break; case 216: //#line 724 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2762 "parse.c" break; case 217: //#line 728 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2770 "parse.c" break; case 218: case 219: //#line 732 "parse.y" { yygotominor.yy44 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy44->span); } //#line 2779 "parse.c" break; case 220: //#line 740 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy44->span); } //#line 2787 "parse.c" break; case 221: //#line 744 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy44->span); } //#line 2795 "parse.c" break; case 224: //#line 751 "parse.y" { ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy44, 0); pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy44, 0); yygotominor.yy44 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy44, 0, 0); if( yygotominor.yy44 ) yygotominor.yy44->pList = pList; if( yymsp[-3].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-4].minor.yy44->span,&yymsp[0].minor.yy44->span); } //#line 2807 "parse.c" break; case 227: //#line 763 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy44, 0, 0); if( yygotominor.yy44 ){ yygotominor.yy44->pList = yymsp[-1].minor.yy412; }else{ sqlite3ExprListDelete(yymsp[-1].minor.yy412); } if( yymsp[-3].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-4].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2821 "parse.c" break; case 228: //#line 773 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_SELECT, 0, 0, 0); if( yygotominor.yy44 ) yygotominor.yy44->pSelect = yymsp[-1].minor.yy99; if( !yygotominor.yy44 ) sqlite3SelectDelete(yymsp[-1].minor.yy99); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); } //#line 2831 "parse.c" break; case 229: //#line 779 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy44, 0, 0); if( yygotominor.yy44 ) yygotominor.yy44->pSelect = yymsp[-1].minor.yy99; if( !yygotominor.yy44 ) sqlite3SelectDelete(yymsp[-1].minor.yy99); if( yymsp[-3].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-4].minor.yy44->span,&yymsp[0].minor.yy0); } //#line 2842 "parse.c" break; case 230: //#line 786 "parse.y" { SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144); yygotominor.yy44 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy44, 0, 0); if( yygotominor.yy44 ) yygotominor.yy44->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0); if( yymsp[-2].minor.yy58 ) yygotominor.yy44 = sqlite3Expr(TK_NOT, yygotominor.yy44, 0, 0); sqlite3ExprSpan(yygotominor.yy44,&yymsp[-3].minor.yy44->span,yymsp[0].minor.yy144.z?&yymsp[0].minor.yy144:&yymsp[-1].minor.yy144); } //#line 2853 "parse.c" break; case 231: //#line 793 "parse.y" { Expr *p = yygotominor.yy44 = sqlite3Expr(TK_EXISTS, 0, 0, 0); if( p ){ p->pSelect = yymsp[-1].minor.yy99; sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); } if( !p ) sqlite3SelectDelete(yymsp[-1].minor.yy99); } //#line 2865 "parse.c" break; case 232: //#line 804 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy44, yymsp[-1].minor.yy44, 0); if( yygotominor.yy44 ) yygotominor.yy44->pList = yymsp[-2].minor.yy412; sqlite3ExprSpan(yygotominor.yy44, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); } //#line 2874 "parse.c" break; case 233: //#line 811 "parse.y" { yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412, yymsp[-2].minor.yy44, 0); yygotominor.yy412 = sqlite3ExprListAppend(yygotominor.yy412, yymsp[0].minor.yy44, 0); } //#line 2882 "parse.c" break; case 234: //#line 815 "parse.y" { yygotominor.yy412 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy44, 0); yygotominor.yy412 = sqlite3ExprListAppend(yygotominor.yy412, yymsp[0].minor.yy44, 0); } //#line 2890 "parse.c" break; case 243: //#line 840 "parse.y" { if( yymsp[-9].minor.yy58!=OE_None ) yymsp[-9].minor.yy58 = yymsp[0].minor.yy58; if( yymsp[-9].minor.yy58==OE_Default) yymsp[-9].minor.yy58 = OE_Abort; sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy144, &yymsp[-6].minor.yy144, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy144,0),yymsp[-2].minor.yy412,yymsp[-9].minor.yy58, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0); } //#line 2899 "parse.c" break; case 244: case 291: //#line 847 "parse.y" {yygotominor.yy58 = OE_Abort;} //#line 2905 "parse.c" break; case 245: //#line 848 "parse.y" {yygotominor.yy58 = OE_None;} //#line 2910 "parse.c" break; case 248: //#line 858 "parse.y" { Expr *p = 0; if( yymsp[-1].minor.yy144.n>0 ){ p = sqlite3Expr(TK_COLUMN, 0, 0, 0); if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (const char *)yymsp[-1].minor.yy144.z, yymsp[-1].minor.yy144.n); } yygotominor.yy412 = sqlite3ExprListAppend(yymsp[-4].minor.yy412, p, &yymsp[-2].minor.yy144); } //#line 2922 "parse.c" break; case 249: //#line 866 "parse.y" { Expr *p = 0; if( yymsp[-1].minor.yy144.n>0 ){ p = sqlite3Expr(TK_COLUMN, 0, 0, 0); if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (const char *)yymsp[-1].minor.yy144.z, yymsp[-1].minor.yy144.n); } yygotominor.yy412 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy144); } //#line 2934 "parse.c" break; case 251: //#line 879 "parse.y" {sqlite3DropIndex(pParse, yymsp[0].minor.yy367);} //#line 2939 "parse.c" break; case 252: case 253: //#line 883 "parse.y" {sqlite3Vacuum(pParse,0);} //#line 2945 "parse.c" break; case 254: case 256: //#line 889 "parse.y" {sqlite3Pragma(pParse,&yymsp[-3].minor.yy144,&yymsp[-2].minor.yy144,&yymsp[0].minor.yy144,0);} //#line 2951 "parse.c" break; case 255: //#line 890 "parse.y" {sqlite3Pragma(pParse,&yymsp[-3].minor.yy144,&yymsp[-2].minor.yy144,&yymsp[0].minor.yy0,0);} //#line 2956 "parse.c" break; case 257: //#line 892 "parse.y" { sqlite3Pragma(pParse,&yymsp[-3].minor.yy144,&yymsp[-2].minor.yy144,&yymsp[0].minor.yy144,1); } //#line 2963 "parse.c" break; case 258: //#line 895 "parse.y" {sqlite3Pragma(pParse,&yymsp[-4].minor.yy144,&yymsp[-3].minor.yy144,&yymsp[-1].minor.yy144,0);} //#line 2968 "parse.c" break; case 259: //#line 896 "parse.y" {sqlite3Pragma(pParse,&yymsp[-1].minor.yy144,&yymsp[0].minor.yy144,0,0);} //#line 2973 "parse.c" break; case 266: //#line 909 "parse.y" { Token all; all.z = yymsp[-3].minor.yy144.z; all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy144.z) + yymsp[0].minor.yy0.n; sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy203, &all); } //#line 2983 "parse.c" break; case 267: //#line 918 "parse.y" { sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy144, &yymsp[-6].minor.yy144, yymsp[-5].minor.yy58, yymsp[-4].minor.yy234.a, yymsp[-4].minor.yy234.b, yymsp[-2].minor.yy367, yymsp[-1].minor.yy58, yymsp[0].minor.yy44, yymsp[-9].minor.yy58); yygotominor.yy144 = (yymsp[-6].minor.yy144.n==0?yymsp[-7].minor.yy144:yymsp[-6].minor.yy144); } //#line 2991 "parse.c" break; case 268: case 271: //#line 924 "parse.y" { yygotominor.yy58 = TK_BEFORE; } //#line 2997 "parse.c" break; case 269: //#line 925 "parse.y" { yygotominor.yy58 = TK_AFTER; } //#line 3002 "parse.c" break; case 270: //#line 926 "parse.y" { yygotominor.yy58 = TK_INSTEAD;} //#line 3007 "parse.c" break; case 272: case 273: case 274: //#line 931 "parse.y" {yygotominor.yy234.a = yymsp[0].major; yygotominor.yy234.b = 0;} //#line 3014 "parse.c" break; case 275: //#line 934 "parse.y" {yygotominor.yy234.a = TK_UPDATE; yygotominor.yy234.b = yymsp[0].minor.yy258;} //#line 3019 "parse.c" break; case 276: case 277: //#line 937 "parse.y" { yygotominor.yy58 = TK_ROW; } //#line 3025 "parse.c" break; case 278: //#line 939 "parse.y" { yygotominor.yy58 = TK_STATEMENT; } //#line 3030 "parse.c" break; case 279: //#line 942 "parse.y" { yygotominor.yy44 = 0; } //#line 3035 "parse.c" break; case 280: //#line 943 "parse.y" { yygotominor.yy44 = yymsp[0].minor.yy44; } //#line 3040 "parse.c" break; case 281: //#line 947 "parse.y" { yymsp[-2].minor.yy203->pNext = yymsp[0].minor.yy203; yygotominor.yy203 = yymsp[-2].minor.yy203; } //#line 3048 "parse.c" break; case 282: //#line 951 "parse.y" { yygotominor.yy203 = 0; } //#line 3053 "parse.c" break; case 283: //#line 957 "parse.y" { yygotominor.yy203 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy144, yymsp[-1].minor.yy412, yymsp[0].minor.yy44, yymsp[-4].minor.yy58); } //#line 3058 "parse.c" break; case 284: //#line 962 "parse.y" {yygotominor.yy203 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy144, yymsp[-4].minor.yy258, yymsp[-1].minor.yy412, 0, yymsp[-7].minor.yy58);} //#line 3063 "parse.c" break; case 285: //#line 965 "parse.y" {yygotominor.yy203 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy144, yymsp[-1].minor.yy258, 0, yymsp[0].minor.yy99, yymsp[-4].minor.yy58);} //#line 3068 "parse.c" break; case 286: //#line 969 "parse.y" {yygotominor.yy203 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy144, yymsp[0].minor.yy44);} //#line 3073 "parse.c" break; case 287: //#line 972 "parse.y" {yygotominor.yy203 = sqlite3TriggerSelectStep(yymsp[0].minor.yy99); } //#line 3078 "parse.c" break; case 288: //#line 975 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_RAISE, 0, 0, 0); yygotominor.yy44->iColumn = OE_Ignore; sqlite3ExprSpan(yygotominor.yy44, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } //#line 3087 "parse.c" break; case 289: //#line 980 "parse.y" { yygotominor.yy44 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy144); yygotominor.yy44->iColumn = yymsp[-3].minor.yy58; sqlite3ExprSpan(yygotominor.yy44, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0); } //#line 3096 "parse.c" break; case 290: //#line 988 "parse.y" {yygotominor.yy58 = OE_Rollback;} //#line 3101 "parse.c" break; case 292: //#line 990 "parse.y" {yygotominor.yy58 = OE_Fail;} //#line 3106 "parse.c" break; case 293: //#line 995 "parse.y" { sqlite3DropTrigger(pParse,yymsp[0].minor.yy367); } //#line 3113 "parse.c" break; case 294: //#line 1001 "parse.y" { sqlite3Attach(pParse, &yymsp[-3].minor.yy144, &yymsp[-1].minor.yy144, yymsp[0].minor.yy300.type, &yymsp[0].minor.yy300.key); } //#line 3120 "parse.c" break; case 295: //#line 1005 "parse.y" { yygotominor.yy300.type = 0; } //#line 3125 "parse.c" break; case 296: //#line 1006 "parse.y" { yygotominor.yy300.type=1; yygotominor.yy300.key = yymsp[0].minor.yy144; } //#line 3130 "parse.c" break; case 297: //#line 1007 "parse.y" { yygotominor.yy300.type=2; yygotominor.yy300.key = yymsp[0].minor.yy0; } //#line 3135 "parse.c" break; case 300: //#line 1013 "parse.y" { sqlite3Detach(pParse, &yymsp[0].minor.yy144); } //#line 3142 "parse.c" break; case 301: //#line 1019 "parse.y" {sqlite3Reindex(pParse, 0, 0);} //#line 3147 "parse.c" break; case 302: //#line 1020 "parse.y" {sqlite3Reindex(pParse, &yymsp[-1].minor.yy144, &yymsp[0].minor.yy144);} //#line 3152 "parse.c" break; case 303: //#line 1025 "parse.y" {sqlite3Analyze(pParse, 0, 0);} //#line 3157 "parse.c" break; case 304: //#line 1026 "parse.y" {sqlite3Analyze(pParse, &yymsp[-1].minor.yy144, &yymsp[0].minor.yy144);} //#line 3162 "parse.c" break; case 305: //#line 1031 "parse.y" { sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy367,&yymsp[0].minor.yy144); } //#line 3169 "parse.c" break; case 306: //#line 1034 "parse.y" { sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy144); } //#line 3176 "parse.c" break; case 307: //#line 1037 "parse.y" { sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy367); } //#line 3183 "parse.c" break; }; yygoto = yyRuleInfo[yyruleno].lhs; yysize = yyRuleInfo[yyruleno].nrhs; yypParser->yyidx -= yysize; yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); if( yyact < YYNSTATE ){ |
︙ | ︙ | |||
3172 3173 3174 3175 3176 3177 3178 | static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ YYMINORTYPE yyminor /* The minor type of the error token */ ){ sqlite3ParserARG_FETCH; #define TOKEN (yyminor.yy0) | | | | 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 | static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ YYMINORTYPE yyminor /* The minor type of the error token */ ){ sqlite3ParserARG_FETCH; #define TOKEN (yyminor.yy0) //#line 34 "parse.y" if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); }else{ sqlite3ErrorMsg(pParse, "incomplete SQL statement"); } } //#line 3250 "parse.c" sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } /* ** The following is executed when the parser accepts */ static void yy_accept( |
︙ | ︙ | |||
3352 3353 3354 3355 3356 3357 3358 | }else{ yy_accept(yypParser); yymajor = YYNOCODE; } }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); return; } | | < | 3414 3415 3416 3417 3418 3419 3420 3421 | }else{ yy_accept(yypParser); yymajor = YYNOCODE; } }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); return; } } |
Changes to SQLite.Interop/src/parse.h.
︙ | ︙ | |||
23 24 25 26 27 28 29 | #define TK_LP 23 #define TK_RP 24 #define TK_AS 25 #define TK_COMMA 26 #define TK_ID 27 #define TK_ABORT 28 #define TK_AFTER 29 | > | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #define TK_LP 23 #define TK_RP 24 #define TK_AS 25 #define TK_COMMA 26 #define TK_ID 27 #define TK_ABORT 28 #define TK_AFTER 29 #define TK_ANALYZE 30 #define TK_ASC 31 #define TK_ATTACH 32 #define TK_BEFORE 33 #define TK_CASCADE 34 #define TK_CAST 35 #define TK_CONFLICT 36 #define TK_DATABASE 37 #define TK_DESC 38 #define TK_DETACH 39 #define TK_EACH 40 #define TK_FAIL 41 #define TK_FOR 42 #define TK_IGNORE 43 #define TK_INITIALLY 44 #define TK_INSTEAD 45 #define TK_LIKE_KW 46 #define TK_MATCH 47 #define TK_KEY 48 #define TK_OF 49 #define TK_OFFSET 50 #define TK_PRAGMA 51 #define TK_RAISE 52 #define TK_REPLACE 53 #define TK_RESTRICT 54 #define TK_ROW 55 #define TK_STATEMENT 56 #define TK_TRIGGER 57 #define TK_VACUUM 58 #define TK_VIEW 59 #define TK_REINDEX 60 #define TK_RENAME 61 #define TK_CTIME_KW 62 #define TK_ALTER 63 #define TK_OR 64 #define TK_AND 65 #define TK_NOT 66 #define TK_IS 67 #define TK_BETWEEN 68 #define TK_IN 69 #define TK_ISNULL 70 #define TK_NOTNULL 71 #define TK_NE 72 #define TK_EQ 73 #define TK_GT 74 #define TK_LE 75 #define TK_LT 76 #define TK_GE 77 #define TK_ESCAPE 78 #define TK_BITAND 79 #define TK_BITOR 80 #define TK_LSHIFT 81 #define TK_RSHIFT 82 #define TK_PLUS 83 #define TK_MINUS 84 #define TK_STAR 85 #define TK_SLASH 86 #define TK_REM 87 #define TK_CONCAT 88 #define TK_UMINUS 89 #define TK_UPLUS 90 #define TK_BITNOT 91 #define TK_STRING 92 #define TK_JOIN_KW 93 #define TK_CONSTRAINT 94 #define TK_DEFAULT 95 #define TK_NULL 96 #define TK_PRIMARY 97 #define TK_UNIQUE 98 #define TK_CHECK 99 #define TK_REFERENCES 100 #define TK_COLLATE 101 #define TK_AUTOINCR 102 #define TK_ON 103 #define TK_DELETE 104 #define TK_UPDATE 105 #define TK_INSERT 106 #define TK_SET 107 #define TK_DEFERRABLE 108 #define TK_FOREIGN 109 #define TK_DROP 110 #define TK_UNION 111 #define TK_ALL 112 #define TK_INTERSECT 113 #define TK_EXCEPT 114 #define TK_SELECT 115 #define TK_DISTINCT 116 #define TK_DOT 117 #define TK_FROM 118 #define TK_JOIN 119 #define TK_USING 120 #define TK_ORDER 121 #define TK_BY 122 #define TK_GROUP 123 #define TK_HAVING 124 #define TK_LIMIT 125 #define TK_WHERE 126 #define TK_INTO 127 #define TK_VALUES 128 #define TK_INTEGER 129 #define TK_FLOAT 130 #define TK_BLOB 131 #define TK_REGISTER 132 #define TK_VARIABLE 133 #define TK_EXISTS 134 #define TK_CASE 135 #define TK_WHEN 136 #define TK_THEN 137 #define TK_ELSE 138 #define TK_INDEX 139 #define TK_TO 140 #define TK_ADD 141 #define TK_COLUMNKW 142 |
Changes to SQLite.Interop/src/pragma.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** 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. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* Ignore this whole file if pragmas are disabled */ |
︙ | ︙ | |||
43 44 45 46 47 48 49 | /* 123456789 123456789 */ static const char zText[] = "onoffalseyestruefull"; static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; int i, n; if( isdigit(*z) ){ | | | | | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | /* 123456789 123456789 */ static const char zText[] = "onoffalseyestruefull"; static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16}; static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4}; static const u8 iValue[] = {1, 0, 0, 0, 1, 1, 2}; int i, n; if( isdigit(*z) ){ return atoi((const char *)z); } n = strlen((const char *)z); for(i=0; i<sizeof(iLength); i++){ if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],(const char *)z,n)==0 ){ return iValue[i]; } } return 1; } /* |
︙ | ︙ | |||
165 166 167 168 169 170 171 | sqlite3 *db = pParse->db; Vdbe *v; v = sqlite3GetVdbe(pParse); if( v ){ if( zRight==0 ){ returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 ); }else{ | | | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | sqlite3 *db = pParse->db; Vdbe *v; v = sqlite3GetVdbe(pParse); if( v ){ if( zRight==0 ){ returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 ); }else{ if( getBoolean((const u8 *)zRight) ){ db->flags |= p->mask; }else{ db->flags &= ~p->mask; } } /* If one of these pragmas is executed, any prepared statements ** need to be recompiled. |
︙ | ︙ | |||
318 319 320 321 322 323 324 | if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){ Btree *pBt = pDb->pBt; if( !zRight ){ int auto_vacuum = pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM; returnSingleInt(pParse, "auto_vacuum", auto_vacuum); }else{ | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){ Btree *pBt = pDb->pBt; if( !zRight ){ int auto_vacuum = pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM; returnSingleInt(pParse, "auto_vacuum", auto_vacuum); }else{ sqlite3BtreeSetAutoVacuum(pBt, getBoolean((const u8 *)zRight)); } }else #endif #ifndef SQLITE_OMIT_PAGER_PRAGMAS /* ** PRAGMA [database.]cache_size |
︙ | ︙ | |||
426 427 428 429 430 431 432 | if( !zRight ){ returnSingleInt(pParse, "synchronous", pDb->safety_level-1); }else{ if( !db->autoCommit ){ sqlite3ErrorMsg(pParse, "Safety level may not be changed inside a transaction"); }else{ | | | 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | if( !zRight ){ returnSingleInt(pParse, "synchronous", pDb->safety_level-1); }else{ if( !db->autoCommit ){ sqlite3ErrorMsg(pParse, "Safety level may not be changed inside a transaction"); }else{ pDb->safety_level = getSafetyLevel((const u8 *)zRight)+1; sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level); } } }else #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
︙ | ︙ | |||
582 583 584 585 586 587 588 589 590 591 592 593 | sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC); sqlite3VdbeSetColName(v, 2, "table", P3_STATIC); sqlite3VdbeSetColName(v, 3, "from", P3_STATIC); sqlite3VdbeSetColName(v, 4, "to", P3_STATIC); while(pFK){ int j; for(j=0; j<pFK->nCol; j++){ sqlite3VdbeAddOp(v, OP_Integer, i, 0); sqlite3VdbeAddOp(v, OP_Integer, j, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[pFK->aCol[j].iFrom].zName, 0); | > | > | | | | > > > > > > > > > > | 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 | sqlite3VdbeSetColName(v, 1, "seq", P3_STATIC); sqlite3VdbeSetColName(v, 2, "table", P3_STATIC); sqlite3VdbeSetColName(v, 3, "from", P3_STATIC); sqlite3VdbeSetColName(v, 4, "to", P3_STATIC); while(pFK){ int j; for(j=0; j<pFK->nCol; j++){ char *zCol = pFK->aCol[j].zCol; sqlite3VdbeAddOp(v, OP_Integer, i, 0); sqlite3VdbeAddOp(v, OP_Integer, j, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0); sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[pFK->aCol[j].iFrom].zName, 0); sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0); sqlite3VdbeAddOp(v, OP_Callback, 5, 0); } ++i; pFK = pFK->pNextFrom; } } } }else #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ #ifndef NDEBUG if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ extern void sqlite3ParserTrace(FILE*, char *); if( zRight ){ if( getBoolean(zRight) ){ sqlite3ParserTrace(stderr, "parser: "); }else{ sqlite3ParserTrace(0, 0); } } }else #endif /* Reinstall the LIKE and GLOB functions. The variant of LIKE ** used will be case sensitive or not depending on the RHS. */ if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){ if( zRight ){ sqlite3RegisterLikeFunctions(db, getBoolean((const u8 *)zRight)); } }else #ifndef SQLITE_OMIT_INTEGRITY_CHECK if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){ int i, j, addr; /* Code that initializes the integrity check program. Set the ** error count 0 |
︙ | ︙ | |||
930 931 932 933 934 935 936 | } pragma_out: sqliteFree(zLeft); sqliteFree(zRight); } #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ | | < | 942 943 944 945 946 947 948 949 | } pragma_out: sqliteFree(zLeft); sqliteFree(zRight); } #endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */ } |
Changes to SQLite.Interop/src/prepare.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** 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. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** 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.3 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** Fill the InitData structure with an error message that indicates |
︙ | ︙ | |||
293 294 295 296 297 298 299 300 301 302 303 304 305 306 | zSql = sqlite3MPrintf( "SELECT name, rootpage, sql, '%s' FROM '%q'.%s", zDbNum, db->aDb[iDb].zName, zMasterName); sqlite3SafetyOff(db); rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); sqlite3SafetyOn(db); sqliteFree(zSql); sqlite3BtreeCloseCursor(curMain); } if( sqlite3_malloc_failed ){ sqlite3SetString(pzErrMsg, "out of memory", (char*)0); rc = SQLITE_NOMEM; sqlite3ResetInternalSchema(db, 0); } | > > > > > | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | zSql = sqlite3MPrintf( "SELECT name, rootpage, sql, '%s' FROM '%q'.%s", zDbNum, db->aDb[iDb].zName, zMasterName); sqlite3SafetyOff(db); rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); sqlite3SafetyOn(db); sqliteFree(zSql); #ifndef SQLITE_OMIT_ANALYZE if( rc==SQLITE_OK ){ sqlite3AnalysisLoad(db, iDb); } #endif sqlite3BtreeCloseCursor(curMain); } if( sqlite3_malloc_failed ){ sqlite3SetString(pzErrMsg, "out of memory", (char*)0); rc = SQLITE_NOMEM; sqlite3ResetInternalSchema(db, 0); } |
︙ | ︙ | |||
369 370 371 372 373 374 375 | int rc = SQLITE_OK; sqlite3 *db = pParse->db; if( !db->init.busy ){ if( (db->flags & SQLITE_Initialized)==0 ){ rc = sqlite3Init(db, &pParse->zErrMsg); } } | | | 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | int rc = SQLITE_OK; sqlite3 *db = pParse->db; if( !db->init.busy ){ if( (db->flags & SQLITE_Initialized)==0 ){ rc = sqlite3Init(db, &pParse->zErrMsg); } } assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy ); if( rc!=SQLITE_OK ){ pParse->rc = rc; pParse->nErr++; } return rc; } |
︙ | ︙ | |||
525 526 527 528 529 530 531 | int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8); *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed); } return rc; } #endif /* SQLITE_OMIT_UTF16 */ | | < | 530 531 532 533 534 535 536 537 | int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8); *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed); } return rc; } #endif /* SQLITE_OMIT_UTF16 */ } |
Changes to SQLite.Interop/src/printf.c.
︙ | ︙ | |||
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | ** most frequently used conversion types first. */ static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; static const char aPrefix[] = "-x0\000X0"; static const et_info fmtinfo[] = { { 'd', 10, 1, etRADIX, 0, 0 }, { 's', 0, 4, etSTRING, 0, 0 }, { 'z', 0, 6, etDYNSTRING, 0, 0 }, { 'q', 0, 4, etSQLESCAPE, 0, 0 }, { 'Q', 0, 4, etSQLESCAPE2, 0, 0 }, { 'c', 0, 0, etCHARX, 0, 0 }, { 'o', 8, 0, etRADIX, 0, 2 }, { 'u', 10, 0, etRADIX, 0, 0 }, { 'x', 16, 0, etRADIX, 16, 1 }, { 'X', 16, 0, etRADIX, 0, 4 }, { 'f', 0, 1, etFLOAT, 0, 0 }, { 'e', 0, 1, etEXP, 30, 0 }, { 'E', 0, 1, etEXP, 14, 0 }, | > < | 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 | ** most frequently used conversion types first. */ static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; static const char aPrefix[] = "-x0\000X0"; static const et_info fmtinfo[] = { { 'd', 10, 1, etRADIX, 0, 0 }, { 's', 0, 4, etSTRING, 0, 0 }, { 'g', 0, 1, etGENERIC, 30, 0 }, { 'z', 0, 6, etDYNSTRING, 0, 0 }, { 'q', 0, 4, etSQLESCAPE, 0, 0 }, { 'Q', 0, 4, etSQLESCAPE2, 0, 0 }, { 'c', 0, 0, etCHARX, 0, 0 }, { 'o', 8, 0, etRADIX, 0, 2 }, { 'u', 10, 0, etRADIX, 0, 0 }, { 'x', 16, 0, etRADIX, 16, 1 }, { 'X', 16, 0, etRADIX, 0, 4 }, { 'f', 0, 1, etFLOAT, 0, 0 }, { 'e', 0, 1, etEXP, 30, 0 }, { 'E', 0, 1, etEXP, 14, 0 }, { 'G', 0, 1, etGENERIC, 14, 0 }, { 'i', 10, 1, etRADIX, 0, 0 }, { 'n', 0, 0, etSIZE, 0, 0 }, { '%', 0, 0, etPERCENT, 0, 0 }, { 'p', 16, 0, etPOINTER, 0, 1 }, { 'T', 0, 2, etTOKEN, 0, 0 }, { 'S', 0, 2, etSRCLIST, 0, 0 }, |
︙ | ︙ | |||
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | int idx; /* A general purpose loop counter */ int count; /* Total number of characters output */ int width; /* Width of the current field */ etByte flag_leftjustify; /* True if "-" flag is present */ etByte flag_plussign; /* True if "+" flag is present */ etByte flag_blanksign; /* True if " " flag is present */ etByte flag_alternateform; /* True if "#" flag is present */ etByte flag_zeropad; /* True if field width constant starts with zero */ etByte flag_long; /* True if "l" flag is present */ etByte flag_longlong; /* True if the "ll" flag is present */ UINT64_TYPE longvalue; /* Value for integer types */ LONGDOUBLE_TYPE realvalue; /* Value for real types */ const et_info *infop; /* Pointer to the appropriate info structure */ char buf[etBUFSIZE]; /* Conversion buffer */ char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ etByte errorflag = 0; /* True if an error is encountered */ etByte xtype; /* Conversion paradigm */ char *zExtra; /* Extra memory used for etTCLESCAPE conversions */ static const char spaces[] = " "; #define etSPACESIZE (sizeof(spaces)-1) #ifndef etNOFLOATINGPOINT | > > | | 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 | int idx; /* A general purpose loop counter */ int count; /* Total number of characters output */ int width; /* Width of the current field */ etByte flag_leftjustify; /* True if "-" flag is present */ etByte flag_plussign; /* True if "+" flag is present */ etByte flag_blanksign; /* True if " " flag is present */ etByte flag_alternateform; /* True if "#" flag is present */ etByte flag_altform2; /* True if "!" flag is present */ etByte flag_zeropad; /* True if field width constant starts with zero */ etByte flag_long; /* True if "l" flag is present */ etByte flag_longlong; /* True if the "ll" flag is present */ etByte done; /* Loop termination flag */ UINT64_TYPE longvalue; /* Value for integer types */ LONGDOUBLE_TYPE realvalue; /* Value for real types */ const et_info *infop; /* Pointer to the appropriate info structure */ char buf[etBUFSIZE]; /* Conversion buffer */ char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ etByte errorflag = 0; /* True if an error is encountered */ etByte xtype; /* Conversion paradigm */ char *zExtra; /* Extra memory used for etTCLESCAPE conversions */ static const char spaces[] = " "; #define etSPACESIZE (sizeof(spaces)-1) #ifndef etNOFLOATINGPOINT int exp, e2; /* exponent of real numbers */ double rounder; /* Used for rounding floating point values */ etByte flag_dp; /* True if decimal point should be shown */ etByte flag_rtz; /* True if trailing zeros should be removed */ etByte flag_exp; /* True to force display of the exponent */ int nsd; /* Number of significant digits returned */ #endif |
︙ | ︙ | |||
253 254 255 256 257 258 259 | errorflag = 1; (*func)(arg,"%",1); count++; break; } /* Find out what flags are present */ flag_leftjustify = flag_plussign = flag_blanksign = | | > | | | | > | | | | 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 | errorflag = 1; (*func)(arg,"%",1); count++; break; } /* Find out what flags are present */ flag_leftjustify = flag_plussign = flag_blanksign = flag_alternateform = flag_altform2 = flag_zeropad = 0; done = 0; do{ switch( c ){ case '-': flag_leftjustify = 1; break; case '+': flag_plussign = 1; break; case ' ': flag_blanksign = 1; break; case '#': flag_alternateform = 1; break; case '!': flag_altform2 = 1; break; case '0': flag_zeropad = 1; break; default: done = 1; break; } }while( !done && (c=(*++fmt))!=0 ); /* Get the field width */ width = 0; if( c=='*' ){ width = va_arg(ap,int); if( width<0 ){ flag_leftjustify = 1; width = -width; |
︙ | ︙ | |||
335 336 337 338 339 340 341 342 343 344 345 346 347 348 | precision = etBUFSIZE-40; } /* ** At this point, variables are initialized as follows: ** ** flag_alternateform TRUE if a '#' is present. ** flag_plussign TRUE if a '+' is present. ** flag_leftjustify TRUE if a '-' is present or if the ** field width was negative. ** flag_zeropad TRUE if the width began with 0. ** flag_long TRUE if the letter 'l' (ell) prefixed ** the conversion character. ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed | > | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | precision = etBUFSIZE-40; } /* ** At this point, variables are initialized as follows: ** ** flag_alternateform TRUE if a '#' is present. ** flag_altform2 TRUE if a '!' is present. ** flag_plussign TRUE if a '+' is present. ** flag_leftjustify TRUE if a '-' is present or if the ** field width was negative. ** flag_zeropad TRUE if the width began with 0. ** flag_long TRUE if the letter 'l' (ell) prefixed ** the conversion character. ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed |
︙ | ︙ | |||
413 414 415 416 417 418 419 | break; case etFLOAT: case etEXP: case etGENERIC: realvalue = va_arg(ap,double); #ifndef etNOFLOATINGPOINT if( precision<0 ) precision = 6; /* Set default precision */ | | | < | > | | | 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 | break; case etFLOAT: case etEXP: case etGENERIC: realvalue = va_arg(ap,double); #ifndef etNOFLOATINGPOINT if( precision<0 ) precision = 6; /* Set default precision */ if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10; if( realvalue<0.0 ){ realvalue = -realvalue; prefix = '-'; }else{ if( flag_plussign ) prefix = '+'; else if( flag_blanksign ) prefix = ' '; else prefix = 0; } if( xtype==etGENERIC && precision>0 ) precision--; #if 0 /* Rounding works like BSD when the constant 0.4999 is used. Wierd! */ for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1); #else /* 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; } |
︙ | ︙ | |||
466 467 468 469 470 471 472 | }else{ precision = precision - exp; xtype = etFLOAT; } }else{ flag_rtz = 0; } | < | > | < > > < | > | | < > | | | | > | < > > > | | < | | < > | < | > | | | > > | | > | > > > > | < > > > | | > | > | > | | | | | | | > | | 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 | }else{ precision = precision - exp; xtype = etFLOAT; } }else{ flag_rtz = 0; } if( xtype==etEXP ){ e2 = 0; }else{ e2 = exp; } nsd = 0; flag_dp = (precision>0) | flag_alternateform | flag_altform2; /* The sign in front of the number */ if( prefix ){ *(bufpt++) = prefix; } /* Digits prior to the decimal point */ if( e2<0 ){ *(bufpt++) = '0'; }else{ for(; e2>=0; e2--){ *(bufpt++) = et_getdigit(&realvalue,&nsd); } } /* The decimal point */ if( flag_dp ){ *(bufpt++) = '.'; } /* "0" digits after the decimal point but before the first ** significant digit of the number */ for(e2++; e2<0 && precision>0; precision--, e2++){ *(bufpt++) = '0'; } /* Significant digits after the decimal point */ while( (precision--)>0 ){ *(bufpt++) = et_getdigit(&realvalue,&nsd); } /* Remove trailing zeros and the "." if no digits follow the "." */ if( flag_rtz && flag_dp ){ while( bufpt[-1]=='0' ) *(--bufpt) = 0; assert( bufpt>buf ); if( bufpt[-1]=='.' ){ if( flag_altform2 ){ *(bufpt++) = '0'; }else{ *(--bufpt) = 0; } } } /* Add the "eNNN" suffix */ if( flag_exp || (xtype==etEXP && exp) ){ *(bufpt++) = aDigits[infop->charset]; if( exp<0 ){ *(bufpt++) = '-'; exp = -exp; }else{ *(bufpt++) = '+'; } if( exp>=100 ){ *(bufpt++) = (exp/100)+'0'; /* 100's digit */ exp %= 100; } *(bufpt++) = exp/10+'0'; /* 10's digit */ *(bufpt++) = exp%10+'0'; /* 1's digit */ } *bufpt = 0; /* The converted number is in buf[] and zero terminated. Output it. ** Note that the number is in the usual order, not reversed as with ** integer conversions. */ length = bufpt-buf; bufpt = buf; /* Special case: Add leading zeros if the flag_zeropad flag is |
︙ | ︙ | |||
563 564 565 566 567 568 569 | }else if( xtype==etDYNSTRING ){ zExtra = bufpt; } length = strlen(bufpt); if( precision>=0 && precision<length ) length = precision; break; case etSQLESCAPE: | | < | | | | | | | | | | | | | | | | | | | | | | | | | | < > | | | 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 | }else if( xtype==etDYNSTRING ){ zExtra = bufpt; } length = strlen(bufpt); if( precision>=0 && precision<length ) length = precision; break; case etSQLESCAPE: case etSQLESCAPE2: { int i, j, n, c, isnull; int needQuote; char *arg = va_arg(ap,char*); isnull = arg==0; if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); for(i=n=0; (c=arg[i])!=0; i++){ if( c=='\'' ) n++; } needQuote = !isnull && xtype==etSQLESCAPE2; n += i + 1 + needQuote*2; if( n>etBUFSIZE ){ bufpt = zExtra = (char *)sqliteMalloc( n ); if( bufpt==0 ) return -1; }else{ bufpt = buf; } j = 0; if( needQuote ) bufpt[j++] = '\''; for(i=0; (c=arg[i])!=0; i++){ bufpt[j++] = c; if( c=='\'' ) bufpt[j++] = c; } if( needQuote ) bufpt[j++] = '\''; bufpt[j] = 0; length = j; if( precision>=0 && precision<length ) length = precision; break; } case etTOKEN: { Token *pToken = va_arg(ap, Token*); if( pToken && pToken->z ){ (*func)(arg, (const char *)pToken->z, pToken->n); } length = width = 0; break; } case etSRCLIST: { SrcList *pSrc = va_arg(ap, SrcList*); int k = va_arg(ap, int); struct SrcList::SrcList_item *pItem = &pSrc->a[k]; assert( k>=0 && k<pSrc->nSrc ); if( pItem->zDatabase && pItem->zDatabase[0] ){ (*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase)); (*func)(arg, ".", 1); } (*func)(arg, pItem->zName, strlen(pItem->zName)); length = width = 0; |
︙ | ︙ | |||
828 829 830 831 832 833 834 | va_start(ap, zFormat); base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap); va_end(ap); fprintf(stdout,"%d: %s", getpid(), zBuf); fflush(stdout); } #endif | | < | 848 849 850 851 852 853 854 855 | va_start(ap, zFormat); base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap); va_end(ap); fprintf(stdout,"%d: %s", getpid(), zBuf); fflush(stdout); } #endif } |
Changes to SQLite.Interop/src/random.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ************************************************************************* ** 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. ** | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ************************************************************************* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" /* ** Get a single 8-bit random value from the RC4 PRNG. The Mutex |
︙ | ︙ | |||
97 98 99 100 101 102 103 | unsigned char *zBuf = (unsigned char *)pBuf; sqlite3OsEnterMutex(); while( N-- ){ *(zBuf++) = randomByte(); } sqlite3OsLeaveMutex(); } | | < | 97 98 99 100 101 102 103 104 | unsigned char *zBuf = (unsigned char *)pBuf; sqlite3OsEnterMutex(); while( N-- ){ *(zBuf++) = randomByte(); } sqlite3OsLeaveMutex(); } } |
Changes to SQLite.Interop/src/select.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "../interop.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. */ Select *sqlite3SelectNew( ExprList *pEList, /* which columns to include in the result */ |
︙ | ︙ | |||
84 85 86 87 88 89 90 | ** a join type, but put an error in the pParse structure. */ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){ int jointype = 0; Token *apAll[3]; Token *p; static const struct { | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | ** a join type, but put an error in the pParse structure. */ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){ int jointype = 0; Token *apAll[3]; Token *p; static const struct { const char zKeyword[8]; u8 nChar; u8 code; } 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 }, |
︙ | ︙ | |||
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | */ static void setToken(Token *p, const char *z){ p->z = (const unsigned char *)z; p->n = strlen(z); p->dyn = 0; } /* ** Add a term to the WHERE expression in *ppExpr that requires the ** zCol column to be equal in the two tables pTab1 and pTab2. */ 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 */ ){ | > > > > > > > > > < | < | | < | < | 154 155 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | */ static void setToken(Token *p, const char *z){ p->z = (const unsigned char *)z; p->n = strlen(z); p->dyn = 0; } /* ** Create an expression node for an identifier with the name of zName */ static Expr *createIdExpr(const char *zName){ Token dummy; setToken(&dummy, zName); return sqlite3Expr(TK_ID, 0, 0, &dummy); } /* ** Add a term to the WHERE expression in *ppExpr that requires the ** zCol column to be equal in the two tables pTab1 and pTab2. */ 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); } |
︙ | ︙ | |||
320 321 322 323 324 325 326 | } /* ** 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){ | < < | < | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | } /* ** Insert code into "v" that will push the record on the top of the ** stack into the sorter. */ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){ sqlite3ExprCodeExprList(pParse, pOrderBy); sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr, 0); sqlite3VdbeAddOp(v, OP_SortInsert, 0, 0); } /* ** Add code to implement the OFFSET and LIMIT */ |
︙ | ︙ | |||
401 402 403 404 405 406 407 | */ if( nColumn>0 ){ for(i=0; i<nColumn; i++){ sqlite3VdbeAddOp(v, OP_Column, srcTab, i); } }else{ nColumn = pEList->nExpr; | < | < > | | | 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 | */ if( nColumn>0 ){ for(i=0; i<nColumn; i++){ sqlite3VdbeAddOp(v, OP_Column, srcTab, i); } }else{ nColumn = pEList->nExpr; sqlite3ExprCodeExprList(pParse, pEList); } /* If the DISTINCT keyword was present on the SELECT statement ** and this row has been seen before, then do not make this row ** part of the result. */ if( hasDistinct ){ int n = pEList->nExpr; #if NULL_ALWAYS_DISTINCT sqlite3VdbeAddOp(v, OP_IsNull, -pEList->nExpr, sqlite3VdbeCurrentAddr(v)+7); #endif /* Deliberately leave the affinity string off of the following ** OP_MakeRecord */ sqlite3VdbeAddOp(v, OP_MakeRecord, -n, 0); sqlite3VdbeAddOp(v, OP_Distinct, distinct, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, n+1, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue); VdbeComment((v, "# skip indistinct records")); sqlite3VdbeAddOp(v, OP_IdxInsert, distinct, 0); if( pOrderBy==0 ){ codeLimiter(v, p, iContinue, iBreak, nColumn); } } |
︙ | ︙ | |||
510 511 512 513 514 515 516 | sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); sqlite3VdbeAddOp(v, OP_Goto, 0, iBreak); } break; } #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ | | > > > < < < < < < < < < < | < | < > | | 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 | sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); sqlite3VdbeAddOp(v, OP_Goto, 0, iBreak); } break; } #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ /* Send the data to the callback function or to a subroutine. In the ** case of a subroutine, the subroutine itself is responsible for ** popping the data from the stack. */ case SRT_Subroutine: case SRT_Callback: case SRT_Sorter: { if( pOrderBy ){ sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); pushOntoSorter(pParse, v, pOrderBy); }else if( eDest==SRT_Subroutine ){ sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm); }else{ assert( eDest!=SRT_Sorter ); sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0); } break; } #if !defined(SQLITE_OMIT_TRIGGER) /* Discard the results. This is used for SELECT statements inside ** the body of a TRIGGER. The purpose of such selects is to call |
︙ | ︙ | |||
801 802 803 804 805 806 807 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); if( iCol<0 ){ zCol = "rowid"; }else{ zCol = pTab->aCol[iCol].zName; } if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){ | | | | 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 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); if( iCol<0 ){ zCol = "rowid"; }else{ zCol = pTab->aCol[iCol].zName; } if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){ sqlite3VdbeSetColName(v, i, (const char *)p->span.z, p->span.n); }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){ char *zName = 0; char *zTab; zTab = pTabList->a[j].zAlias; if( fullNames || zTab==0 ) zTab = pTab->zName; sqlite3SetString(&zName, zTab, ".", zCol, 0); sqlite3VdbeSetColName(v, i, zName, P3_DYNAMIC); }else{ sqlite3VdbeSetColName(v, i, zCol, strlen(zCol)); } }else if( p->span.z && p->span.z[0] ){ sqlite3VdbeSetColName(v, i, (const char *)p->span.z, p->span.n); /* sqlite3VdbeCompressSpace(v, addr); */ }else{ char zName[30]; assert( p->op!=TK_COLUMN || pTabList==0 ); sprintf(zName, "column%d", i+1); sqlite3VdbeSetColName(v, i, zName, 0); } |
︙ | ︙ | |||
1321 1322 1323 1324 1325 1326 1327 | ** KeyInfo structure. The number of columns in the KeyInfo is determined ** by the result set of the SELECT statement in the second argument. ** ** Specifically, this routine is called to open an index table for ** DISTINCT, UNION, INTERSECT and EXCEPT select statements (but not ** UNION ALL). ** | | | | 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 | ** KeyInfo structure. The number of columns in the KeyInfo is determined ** by the result set of the SELECT statement in the second argument. ** ** Specifically, this routine is called to open an index table for ** DISTINCT, UNION, INTERSECT and EXCEPT select statements (but not ** UNION ALL). ** ** The value returned is the address of the OP_OpenVirtual instruction. */ static int openVirtualIndex(Parse *pParse, Select *p, int iTab){ KeyInfo *pKeyInfo; int nColumn; sqlite3 *db = pParse->db; int i; Vdbe *v = pParse->pVdbe; int addr; |
︙ | ︙ | |||
1345 1346 1347 1348 1349 1350 1351 | pKeyInfo->nField = nColumn; for(i=0; i<nColumn; i++){ pKeyInfo->aColl[i] = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr); if( !pKeyInfo->aColl[i] ){ pKeyInfo->aColl[i] = db->pDfltColl; } } | | | | | | | 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 | pKeyInfo->nField = nColumn; for(i=0; i<nColumn; i++){ pKeyInfo->aColl[i] = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr); if( !pKeyInfo->aColl[i] ){ pKeyInfo->aColl[i] = db->pDfltColl; } } addr = sqlite3VdbeOp3(v, OP_OpenVirtual, iTab, 0, (char*)pKeyInfo, P3_KEYINFO_HANDOFF); return addr; } #ifndef SQLITE_OMIT_COMPOUND_SELECT /* ** Add the address "addr" to the set of all OpenVirtual opcode addresses ** that are being accumulated in p->ppOpenVirtual. */ static int multiSelectOpenVirtualAddr(Select *p, int addr){ IdList *pList = *p->ppOpenVirtual = sqlite3IdListAppend(*p->ppOpenVirtual, 0); if( pList==0 ){ return SQLITE_NOMEM; } pList->a[pList->nId-1].idx = addr; return SQLITE_OK; } #endif /* SQLITE_OMIT_COMPOUND_SELECT */ |
︙ | ︙ | |||
1429 1430 1431 1432 1433 1434 1435 | 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 */ | | | 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 | int eDest, /* \___ Store query results as specified */ int iParm, /* / by these two parameters. */ char *aff /* If eDest is SRT_Union, the affinity string */ ){ int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ IdList *pOpenVirtual = 0;/* OP_OpenVirtual opcodes that need a KeyInfo */ int aAddr[5]; /* Addresses of SetNumColumns operators */ int nAddr = 0; /* Number used */ int nCol; /* Number of columns in the result set */ /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT. */ |
︙ | ︙ | |||
1464 1465 1466 1467 1468 1469 1470 | v = sqlite3GetVdbe(pParse); if( v==0 ){ rc = 1; goto multi_select_end; } /* If *p this is the right-most select statement, then initialize | | | | | | | | | 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 | v = sqlite3GetVdbe(pParse); if( v==0 ){ rc = 1; goto multi_select_end; } /* If *p this is the right-most select statement, then initialize ** p->ppOpenVirtual to point to pOpenVirtual. If *p is not the right most ** statement then p->ppOpenVirtual will have already been initialized ** by a prior call to this same procedure. Pass along the pOpenVirtual ** pointer to pPrior, the next statement to our left. */ if( p->ppOpenVirtual==0 ){ p->ppOpenVirtual = &pOpenVirtual; } pPrior->ppOpenVirtual = p->ppOpenVirtual; /* Create the destination temporary table if necessary */ if( eDest==SRT_TempTable ){ assert( p->pEList ); sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0); assert( nAddr==0 ); aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 0); eDest = SRT_Table; } /* Generate code for the left and right SELECT statements. */ |
︙ | ︙ | |||
1535 1536 1537 1538 1539 1540 1541 | */ unionTab = pParse->nTab++; if( p->pOrderBy && matchOrderbyToColumn(pParse, p, p->pOrderBy, unionTab, 1) ){ rc = 1; goto multi_select_end; } | | | | 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 | */ unionTab = pParse->nTab++; if( p->pOrderBy && matchOrderbyToColumn(pParse, p, p->pOrderBy, unionTab, 1) ){ rc = 1; goto multi_select_end; } addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, unionTab, 0); if( p->op!=TK_ALL ){ rc = multiSelectOpenVirtualAddr(p, addr); if( rc!=SQLITE_OK ){ goto multi_select_end; } } assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) ); aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, unionTab, 0); assert( p->pEList ); |
︙ | ︙ | |||
1627 1628 1629 1630 1631 1632 1633 | tab1 = pParse->nTab++; tab2 = pParse->nTab++; if( p->pOrderBy && matchOrderbyToColumn(pParse,p,p->pOrderBy,tab1,1) ){ rc = 1; goto multi_select_end; } | | | | | | 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 | tab1 = pParse->nTab++; tab2 = pParse->nTab++; if( p->pOrderBy && matchOrderbyToColumn(pParse,p,p->pOrderBy,tab1,1) ){ rc = 1; goto multi_select_end; } addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab1, 0); rc = multiSelectOpenVirtualAddr(p, addr); if( rc!=SQLITE_OK ){ goto multi_select_end; } assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) ); aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, tab1, 0); assert( p->pEList ); /* Code the SELECTs to our left into temporary table "tab1". */ rc = sqlite3Select(pParse, pPrior, SRT_Union, tab1, 0, 0, 0, aff); if( rc ){ goto multi_select_end; } /* Code the current SELECT into temporary table "tab2" */ addr = sqlite3VdbeAddOp(v, OP_OpenVirtual, tab2, 0); rc = multiSelectOpenVirtualAddr(p, addr); if( rc!=SQLITE_OK ){ goto multi_select_end; } assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) ); aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, tab2, 0); p->pPrior = 0; pLimit = p->pLimit; |
︙ | ︙ | |||
1724 1725 1726 1727 1728 1729 1730 | ** 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. */ | | | | | | | | | | 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 | ** ORDER BY processing if there is an ORDER BY clause. ** ** This section is run by the right-most SELECT statement only. ** SELECT statements to the left always skip this part. The right-most ** SELECT might also skip this part if it has no ORDER BY clause and ** no temp tables are required. */ if( p->pOrderBy || (pOpenVirtual && pOpenVirtual->nId>0) ){ int i; /* Loop counter */ KeyInfo *pKeyInfo; /* Collating sequence for the result set */ assert( p->ppOpenVirtual == &pOpenVirtual ); pKeyInfo = (KeyInfo *)sqliteMalloc(sizeof(*pKeyInfo)+nCol*sizeof(CollSeq*)); if( !pKeyInfo ){ rc = SQLITE_NOMEM; goto multi_select_end; } pKeyInfo->enc = pParse->db->enc; pKeyInfo->nField = nCol; for(i=0; i<nCol; i++){ pKeyInfo->aColl[i] = multiSelectCollSeq(pParse, p, i); if( !pKeyInfo->aColl[i] ){ pKeyInfo->aColl[i] = pParse->db->pDfltColl; } } for(i=0; pOpenVirtual && i<pOpenVirtual->nId; i++){ int p3type = (i==0?P3_KEYINFO_HANDOFF:P3_KEYINFO); int addr = pOpenVirtual->a[i].idx; sqlite3VdbeChangeP3(v, addr, (char *)pKeyInfo, p3type); } if( p->pOrderBy ){ struct ExprList::ExprList_item *pOrderByTerm = p->pOrderBy->a; for(i=0; i<p->pOrderBy->nExpr; i++, pOrderByTerm++){ Expr *pExpr = pOrderByTerm->pExpr; char *zName = pOrderByTerm->zName; assert( pExpr->op==TK_COLUMN && pExpr->iColumn<nCol ); /* assert( !pExpr->pColl ); */ if( zName ){ pExpr->pColl = sqlite3LocateCollSeq(pParse, zName, -1); }else{ pExpr->pColl = pKeyInfo->aColl[pExpr->iColumn]; } } generateSortTail(pParse, p, v, p->pEList->nExpr, eDest, iParm); } if( !pOpenVirtual ){ /* This happens for UNION ALL ... ORDER BY */ sqliteFree(pKeyInfo); } } multi_select_end: if( pOpenVirtual ){ sqlite3IdListDelete(pOpenVirtual); } p->ppOpenVirtual = 0; return rc; } #endif /* SQLITE_OMIT_COMPOUND_SELECT */ #ifndef SQLITE_OMIT_VIEW /* ** Scan through the expression pExpr. Replace every reference to |
︙ | ︙ | |||
2044 2045 2046 2047 2048 2049 2050 | ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10". */ substExprList(p->pEList, iParent, pSub->pEList); pList = p->pEList; for(i=0; i<pList->nExpr; i++){ Expr *pExpr; if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){ | | | 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 | ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10". */ substExprList(p->pEList, iParent, pSub->pEList); pList = p->pEList; for(i=0; i<pList->nExpr; i++){ Expr *pExpr; if( pList->a[i].zName==0 && (pExpr = pList->a[i].pExpr)->span.z!=0 ){ pList->a[i].zName = sqliteStrNDup((const char *)pExpr->span.z, pExpr->span.n); } } if( isAgg ){ substExprList(p->pGroupBy, iParent, pSub->pEList); substExpr(p->pHaving, iParent, pSub->pEList); } if( pSub->pOrderBy ){ |
︙ | ︙ | |||
2143 2144 2145 2146 2147 2148 2149 | pEList = p->pEList; if( pEList->nExpr!=1 ) return 0; pExpr = pEList->a[0].pExpr; if( pExpr->op!=TK_AGG_FUNCTION ) return 0; pList = pExpr->pList; if( pList==0 || pList->nExpr!=1 ) return 0; if( pExpr->token.n!=3 ) return 0; | | | | 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 | pEList = p->pEList; if( pEList->nExpr!=1 ) return 0; pExpr = pEList->a[0].pExpr; if( pExpr->op!=TK_AGG_FUNCTION ) return 0; pList = pExpr->pList; if( pList==0 || pList->nExpr!=1 ) return 0; if( pExpr->token.n!=3 ) return 0; if( sqlite3StrNICmp((const char *)pExpr->token.z,"min",3)==0 ){ seekOp = OP_Rewind; }else if( sqlite3StrNICmp((const char *)pExpr->token.z,"max",3)==0 ){ seekOp = OP_Last; }else{ return 0; } pExpr = pList->a[0].pExpr; if( pExpr->op!=TK_COLUMN ) return 0; iCol = pExpr->iColumn; |
︙ | ︙ | |||
2182 2183 2184 2185 2186 2187 2188 | */ v = sqlite3GetVdbe(pParse); if( v==0 ) return 0; /* If the output is destined for a temporary table, open that table. */ if( eDest==SRT_TempTable ){ | | | 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 | */ v = sqlite3GetVdbe(pParse); if( v==0 ) return 0; /* If the output is destined for a temporary table, open that table. */ if( eDest==SRT_TempTable ){ sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 1); } /* Generating code to find the min or the max. Basically all we have ** to do is find the first or the last entry in the chosen index. If ** the min() or max() is on the INTEGER PRIMARY KEY, then find the first ** or last entry in the main table. |
︙ | ︙ | |||
2652 2653 2654 2655 2656 2657 2658 | /* Set the limiter. */ computeLimitRegisters(pParse, p); /* If the output is destined for a temporary table, open that table. */ if( eDest==SRT_TempTable ){ | | | 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 | /* Set the limiter. */ computeLimitRegisters(pParse, p); /* If the output is destined for a temporary table, open that table. */ if( eDest==SRT_TempTable ){ sqlite3VdbeAddOp(v, OP_OpenVirtual, iParm, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, pEList->nExpr); } /* Do an analysis of aggregate expressions. */ if( isAgg || pGroupBy ){ NameContext sNC; |
︙ | ︙ | |||
2736 2737 2738 2739 2740 2741 2742 | sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); } /* Open a temporary table to use for the distinct set. */ if( isDistinct ){ distinct = pParse->nTab++; | | | 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 | sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); } /* Open a temporary table to use for the distinct set. */ if( isDistinct ){ distinct = pParse->nTab++; openVirtualIndex(pParse, p, distinct); }else{ distinct = -1; } /* Begin the database scan */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, |
︙ | ︙ | |||
2765 2766 2767 2768 2769 2770 2771 | ** processing. */ else{ AggExpr *pAgg; int lbl1 = 0; pParse->fillAgg = 1; if( pGroupBy ){ | < | < | 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 | ** processing. */ else{ AggExpr *pAgg; int lbl1 = 0; pParse->fillAgg = 1; if( pGroupBy ){ sqlite3ExprCodeExprList(pParse, pGroupBy); /* No affinity string is attached to the following OP_MakeRecord ** because we do not need to do any coercion of datatypes. */ sqlite3VdbeAddOp(v, OP_MakeRecord, pGroupBy->nExpr, 0); lbl1 = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_AggFocus, 0, lbl1); } for(i=0, pAgg=pParse->aAgg; i<pParse->nAgg; i++, pAgg++){ |
︙ | ︙ | |||
2865 2866 2867 2868 2869 2870 2871 | /* Control jumps to here if an error is encountered above, or upon ** successful coding of the SELECT. */ select_end: restoreAggregateInfo(pParse, &sAggInfo); return rc; } | | < | 2856 2857 2858 2859 2860 2861 2862 2863 | /* Control jumps to here if an error is encountered above, or upon ** successful coding of the SELECT. */ select_end: restoreAggregateInfo(pParse, &sAggInfo); 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <assert.h> #include "sqlite3.h" #include <ctype.h> |
︙ | ︙ | |||
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | i++; if( i<nCol ){ azCol[i] = &z[nSep]; z += nSep-1; } } } if( i+1!=nCol ){ fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n", zFile, lineno, nCol, i+1); zCommit = "ROLLBACK"; break; } for(i=0; i<nCol; i++){ | > | 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | i++; if( i<nCol ){ azCol[i] = &z[nSep]; z += nSep-1; } } } *z = 0; if( i+1!=nCol ){ fprintf(stderr,"%s line %d: expected %d columns of data but found %d\n", zFile, lineno, nCol, i+1); zCommit = "ROLLBACK"; break; } for(i=0; i<nCol; i++){ |
︙ | ︙ |
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.7 2005/08/22 18:22:12 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.3" /* ** 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 3002003 /* ** 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. |
︙ | ︙ | |||
154 155 156 157 158 159 160 | ); /* ** Return values for sqlite3_exec() and sqlite3_step() */ #define SQLITE_OK 0 /* Successful result */ #define SQLITE_ERROR 1 /* SQL error or missing database */ | | | | | 154 155 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 183 184 | ); /* ** Return values for sqlite3_exec() and sqlite3_step() */ #define SQLITE_OK 0 /* Successful result */ #define SQLITE_ERROR 1 /* SQL error or missing database */ #define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */ #define SQLITE_PERM 3 /* Access permission denied */ #define SQLITE_ABORT 4 /* Callback routine requested an abort */ #define SQLITE_BUSY 5 /* The database file is locked */ #define SQLITE_LOCKED 6 /* A table in the database is locked */ #define SQLITE_NOMEM 7 /* A malloc() failed */ #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ #define SQLITE_FULL 13 /* Insertion failed because database is full */ #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ #define SQLITE_EMPTY 16 /* Database is empty */ #define SQLITE_SCHEMA 17 /* The database schema changed */ #define SQLITE_TOOBIG 18 /* NOT USED. Too much data for one row */ #define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */ #define SQLITE_MISMATCH 20 /* Data type mismatch */ #define SQLITE_MISUSE 21 /* Library used incorrectly */ #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ #define SQLITE_AUTH 23 /* Authorization denied */ #define SQLITE_FORMAT 24 /* Auxiliary database format error */ #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ |
︙ | ︙ | |||
448 449 450 451 452 453 454 455 456 457 458 459 460 461 | #define SQLITE_SELECT 21 /* NULL NULL */ #define SQLITE_TRANSACTION 22 /* NULL NULL */ #define SQLITE_UPDATE 23 /* Table Name Column Name */ #define SQLITE_ATTACH 24 /* Filename NULL */ #define SQLITE_DETACH 25 /* Database Name NULL */ #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ #define SQLITE_REINDEX 27 /* Index Name NULL */ /* ** The return value of the authorization function should be one of the ** following constants: */ /* #define SQLITE_OK 0 // Allow access (This is actually defined above) */ | > | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | #define SQLITE_SELECT 21 /* NULL NULL */ #define SQLITE_TRANSACTION 22 /* NULL NULL */ #define SQLITE_UPDATE 23 /* Table Name Column Name */ #define SQLITE_ATTACH 24 /* Filename NULL */ #define SQLITE_DETACH 25 /* Database Name NULL */ #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ #define SQLITE_REINDEX 27 /* Index Name NULL */ #define SQLITE_ANALYZE 28 /* Table Name NULL */ /* ** The return value of the authorization function should be one of the ** following constants: */ /* #define SQLITE_OK 0 // Allow access (This is actually defined above) */ |
︙ | ︙ | |||
998 999 1000 1001 1002 1003 1004 | ** of the aggregate can use the returned buffer to accumulate data. ** ** The buffer allocated is freed automatically by SQLite. */ void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); /* | | | | < | 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | ** of the aggregate can use the returned buffer to accumulate data. ** ** The buffer allocated is freed automatically by SQLite. */ void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); /* ** The pUserData parameter to the sqlite3_create_function() ** routine used to register user functions is available to ** the implementation of the function using this call. */ void *sqlite3_user_data(sqlite3_context*); /* ** The following two functions may be used by scalar user functions to ** associate meta-data with argument values. If the same value is passed to ** multiple invocations of the user-function during query execution, under |
︙ | ︙ |
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 | /* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* ** These #defines should enable >2GB file support on Posix if the ** underlying operating system supports it. If the OS lacks |
︙ | ︙ | |||
204 205 206 207 208 209 210 211 212 213 214 215 216 217 | ** handle is passed a pointer to sqlite.busyHandler. The busy-handler ** callback is currently invoked only from within pager.c. */ typedef struct BusyHandler BusyHandler; struct BusyHandler { int (*xFunc)(void *,int); /* The busy callback */ void *pArg; /* First arg to busy callback */ }; /* ** Defer sourcing vdbe.h and btree.h until after the "u8" and ** "BusyHandler typedefs. */ #include "vdbe.h" | > | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | ** handle is passed a pointer to sqlite.busyHandler. The busy-handler ** callback is currently invoked only from within pager.c. */ typedef struct BusyHandler BusyHandler; struct BusyHandler { int (*xFunc)(void *,int); /* The busy callback */ void *pArg; /* First arg to busy callback */ int nBusy; /* Incremented with each busy call */ }; /* ** Defer sourcing vdbe.h and btree.h until after the "u8" and ** "BusyHandler typedefs. */ #include "vdbe.h" |
︙ | ︙ | |||
293 294 295 296 297 298 299 | ** an array. */ #define ArraySize(X) (sizeof(X)/sizeof(X[0])) /* ** Forward references to structures */ | > > | | | | | | > | > | > | | | | | | < < < < < | 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 | ** an array. */ #define ArraySize(X) (sizeof(X)/sizeof(X[0])) /* ** Forward references to structures */ typedef struct AggExpr AggExpr; typedef struct AuthContext AuthContext; typedef struct CollSeq CollSeq; typedef struct Column Column; typedef struct Db Db; typedef struct Expr Expr; typedef struct ExprList ExprList; typedef struct FKey FKey; typedef struct FuncDef FuncDef; typedef struct IdList IdList; typedef struct Index Index; typedef struct KeyClass KeyClass; typedef struct KeyInfo KeyInfo; typedef struct NameContext NameContext; typedef struct Parse Parse; typedef struct Select Select; typedef struct SrcList SrcList; typedef struct Table Table; typedef struct Token Token; typedef struct TriggerStack TriggerStack; typedef struct TriggerStep TriggerStep; typedef struct Trigger Trigger; typedef struct WhereInfo WhereInfo; typedef struct WhereLevel WhereLevel; /* ** Each database file to be accessed by the system is an instance ** of the following structure. There are normally two of these structures ** in the sqlite.aDb[] array. aDb[0] is the main database file and ** aDb[1] is the database file used to hold temporary tables. Additional ** databases may be attached. |
︙ | ︙ | |||
491 492 493 494 495 496 497 | /* ** Each SQL function is defined by an instance of the following ** structure. A pointer to this structure is stored in the sqlite.aFunc ** hash table. When multiple functions have the same name, the hash table ** points to a linked list of these structures. */ struct FuncDef { | < | > > | > > > > > | 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 | /* ** Each SQL function is defined by an instance of the following ** structure. A pointer to this structure is stored in the sqlite.aFunc ** hash table. When multiple functions have the same name, the hash table ** points to a linked list of these structures. */ struct FuncDef { i16 nArg; /* Number of arguments. -1 means unlimited */ u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ u8 needCollSeq; /* True if sqlite3GetFuncCollSeq() might be called */ u8 flags; /* Some combination of SQLITE_FUNC_* */ void *pUserData; /* User data parameter */ FuncDef *pNext; /* Next function with same name */ void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */ void (*xFinalize)(sqlite3_context*); /* Aggregate finializer */ char zName[1]; /* SQL name of the function. MUST BE LAST */ }; /* ** Possible values for FuncDef.flags */ #define SQLITE_FUNC_LIKEOPT 0x01 /* Candidate for the LIKE optimization */ /* ** information about each column of an SQL table is held in an instance ** of this structure. */ struct Column { char *zName; /* Name of this column */ Expr *pDflt; /* Default value of this column */ |
︙ | ︙ | |||
740 741 742 743 744 745 746 747 748 749 750 751 752 753 | ** algorithm to employ whenever an attempt is made to insert a non-unique ** element. */ struct Index { char *zName; /* Name of this index */ int nColumn; /* Number of columns in the table used by this index */ int *aiColumn; /* Which columns are used by this index. 1st is 0 */ Table *pTable; /* The SQL table being indexed */ int tnum; /* Page containing root of this index in database file */ u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */ char *zColAff; /* String defining the affinity of each column */ Index *pNext; /* The next index associated with the same table */ | > | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | ** algorithm to employ whenever an attempt is made to insert a non-unique ** element. */ struct Index { char *zName; /* Name of this index */ int nColumn; /* Number of columns in the table used by this index */ int *aiColumn; /* Which columns are used by this index. 1st is 0 */ unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ Table *pTable; /* The SQL table being indexed */ int tnum; /* Page containing root of this index in database file */ u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ u8 iDb; /* Index in sqlite.aDb[] of where this index is stored */ char *zColAff; /* String defining the affinity of each column */ Index *pNext; /* The next index associated with the same table */ |
︙ | ︙ | |||
834 835 836 837 838 839 840 | ** 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. */ | | | | | | | > | 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 | ** right side of "<expr> IN (<select>)" */ Table *pTab; /* Table for OP_Column expressions. */ }; /* ** The following are the meanings of bits in the Expr.flags field. */ #define EP_FromJoin 0x01 /* Originated in ON or USING clause of a join */ #define EP_Agg 0x02 /* Contains one or more aggregate functions */ #define EP_Resolved 0x04 /* IDs have been resolved to COLUMNs */ #define EP_Error 0x08 /* Expression contains one or more errors */ #define EP_Not 0x10 /* Operator preceeded by NOT */ #define EP_VarSelect 0x20 /* pSelect is correlated, not constant */ #define EP_Dequoted 0x40 /* True if the string has been dequoted */ /* ** These macros can be used to test, set, or clear bits in the ** Expr.flags field. */ #define ExprHasProperty(E,P) (((E)->flags&(P))==(P)) #define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0) |
︙ | ︙ | |||
919 920 921 922 923 924 925 | i16 nAlloc; /* Number of entries allocated in a[] below */ struct SrcList_item { char *zDatabase; /* Name of database holding this table */ char *zName; /* Name of the table */ char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ Table *pTab; /* An SQL table corresponding to zName */ Select *pSelect; /* A SELECT statement used in place of a table name */ | | | | 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | i16 nAlloc; /* Number of entries allocated in a[] below */ struct SrcList_item { char *zDatabase; /* Name of database holding this table */ char *zName; /* Name of the table */ char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ Table *pTab; /* An SQL table corresponding to zName */ Select *pSelect; /* A SELECT statement used in place of a table name */ u8 jointype; /* Type of join between this table and the next */ i16 iCursor; /* The VDBE cursor number used to access this table */ Expr *pOn; /* The ON clause of a join */ IdList *pUsing; /* The USING clause of a join */ Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */ } a[1]; /* One entry for each identifier on the list */ }; /* |
︙ | ︙ | |||
944 945 946 947 948 949 950 | /* ** For each nested loop in a WHERE clause implementation, the WhereInfo ** structure contains a single instance of this structure. This structure ** is intended to be private the the where.c module and should not be ** access or modified by other modules. */ struct WhereLevel { | > > | > | | | < | | < < | | | > > | 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 | /* ** For each nested loop in a WHERE clause implementation, the WhereInfo ** structure contains a single instance of this structure. This structure ** is intended to be private the the where.c module and should not be ** access or modified by other modules. */ struct WhereLevel { int iFrom; /* Which entry in the FROM clause */ int flags; /* Flags associated with this level */ int iMem; /* First memory cell used by this level */ int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */ Index *pIdx; /* Index used. NULL if no index */ int iTabCur; /* The VDBE cursor used to access the table */ int iIdxCur; /* The VDBE cursor used to acesss pIdx */ int brk; /* Jump here to break out of the loop */ int cont; /* Jump here to continue with the next loop cycle */ int top; /* First instruction of interior of the loop */ int op, p1, p2; /* Opcode used to terminate the loop */ int nEq; /* Number of == or IN constraints on this loop */ int nIn; /* Number of IN operators constraining this loop */ int *aInLoop; /* Loop terminators for IN operators */ }; /* ** The WHERE clause processing routine has two halves. The ** first part does the start of the WHERE loop and the second ** half does the tail of the WHERE loop. An instance of ** this structure is returned by the first half and passed |
︙ | ︙ | |||
1031 1032 1033 1034 1035 1036 1037 | ExprList *pGroupBy; /* The GROUP BY clause */ Expr *pHaving; /* The HAVING clause */ ExprList *pOrderBy; /* The ORDER BY clause */ Select *pPrior; /* Prior select in a compound select statement */ Expr *pLimit; /* LIMIT expression. NULL means not used. */ Expr *pOffset; /* OFFSET expression. NULL means not used. */ int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ | | | 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | ExprList *pGroupBy; /* The GROUP BY clause */ Expr *pHaving; /* The HAVING clause */ ExprList *pOrderBy; /* The ORDER BY clause */ Select *pPrior; /* Prior select in a compound select statement */ Expr *pLimit; /* LIMIT expression. NULL means not used. */ Expr *pOffset; /* OFFSET expression. NULL means not used. */ int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ IdList **ppOpenVirtual;/* OP_OpenVirtual addresses used by multi-selects */ u8 isResolved; /* True once sqlite3SelectResolve() has run. */ u8 isAgg; /* True if this is an aggregate query */ }; /* ** The results of a select can be distributed in several ways. */ |
︙ | ︙ | |||
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 | char *sqlite3MPrintf(const char*, ...); char *sqlite3VMPrintf(const char*, va_list); void sqlite3DebugPrintf(const char*, ...); void *sqlite3TextToPtr(const char*); void sqlite3SetString(char **, ...); void sqlite3ErrorMsg(Parse*, const char*, ...); void sqlite3Dequote(char*); int sqlite3KeywordCode(const char*, int); int sqlite3RunParser(Parse*, const char*, char **); void sqlite3FinishCoding(Parse*); Expr *sqlite3Expr(int, Expr*, Expr*, const Token*); Expr *sqlite3RegisterExpr(Parse*,Token*); Expr *sqlite3ExprAnd(Expr*, Expr*); void sqlite3ExprSpan(Expr*,Token*,Token*); | > | 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | char *sqlite3MPrintf(const char*, ...); char *sqlite3VMPrintf(const char*, va_list); void sqlite3DebugPrintf(const char*, ...); void *sqlite3TextToPtr(const char*); void sqlite3SetString(char **, ...); void sqlite3ErrorMsg(Parse*, const char*, ...); void sqlite3Dequote(char*); void sqlite3DequoteExpr(Expr*); int sqlite3KeywordCode(const char*, int); int sqlite3RunParser(Parse*, const char*, char **); void sqlite3FinishCoding(Parse*); Expr *sqlite3Expr(int, Expr*, Expr*, const Token*); Expr *sqlite3RegisterExpr(Parse*,Token*); Expr *sqlite3ExprAnd(Expr*, Expr*); void sqlite3ExprSpan(Expr*,Token*,Token*); |
︙ | ︙ | |||
1365 1366 1367 1368 1369 1370 1371 | void sqlite3CommitInternalChanges(sqlite3*); Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*); void sqlite3OpenMasterTable(Vdbe *v, int); void sqlite3StartTable(Parse*,Token*,Token*,Token*,int,int); void sqlite3AddColumn(Parse*,Token*); void sqlite3AddNotNull(Parse*, int); void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int); | | | 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 | void sqlite3CommitInternalChanges(sqlite3*); Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*); void sqlite3OpenMasterTable(Vdbe *v, int); void sqlite3StartTable(Parse*,Token*,Token*,Token*,int,int); void sqlite3AddColumn(Parse*,Token*); void sqlite3AddNotNull(Parse*, int); void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int); void sqlite3AddColumnType(Parse*,Token*); void sqlite3AddDefaultValue(Parse*,Expr*); void sqlite3AddCollateType(Parse*, const char*, int); void sqlite3EndTable(Parse*,Token*,Token*,Select*); #ifndef SQLITE_OMIT_VIEW void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int); int sqlite3ViewGetColumnNames(Parse*,Table*); |
︙ | ︙ | |||
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 | void sqlite3Randomness(int, void*); void sqlite3RollbackAll(sqlite3*); void sqlite3CodeVerifySchema(Parse*, int); void sqlite3BeginTransaction(Parse*, int); void sqlite3CommitTransaction(Parse*); void sqlite3RollbackTransaction(Parse*); int sqlite3ExprIsConstant(Expr*); int sqlite3ExprIsInteger(Expr*, int*); int sqlite3IsRowid(const char*); void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int); void sqlite3GenerateRowIndexDelete(sqlite3*, Vdbe*, Table*, int, char*); void sqlite3GenerateIndexKey(Vdbe*, Index*, int); void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int); void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int); | > | 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 | void sqlite3Randomness(int, void*); void sqlite3RollbackAll(sqlite3*); void sqlite3CodeVerifySchema(Parse*, int); void sqlite3BeginTransaction(Parse*, int); void sqlite3CommitTransaction(Parse*); void sqlite3RollbackTransaction(Parse*); int sqlite3ExprIsConstant(Expr*); int sqlite3ExprIsConstantOrFunction(Expr*); int sqlite3ExprIsInteger(Expr*, int*); int sqlite3IsRowid(const char*); void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int); void sqlite3GenerateRowIndexDelete(sqlite3*, Vdbe*, Table*, int, char*); void sqlite3GenerateIndexKey(Vdbe*, Index*, int); void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int); void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int); |
︙ | ︙ | |||
1504 1505 1506 1507 1508 1509 1510 | int omitJournal, int nCache, Btree **ppBtree); int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); int sqlite3FixSrcList(DbFixer*, SrcList*); int sqlite3FixSelect(DbFixer*, Select*); int sqlite3FixExpr(DbFixer*, Expr*); int sqlite3FixExprList(DbFixer*, ExprList*); int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); | | | 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 | int omitJournal, int nCache, Btree **ppBtree); int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); int sqlite3FixSrcList(DbFixer*, SrcList*); int sqlite3FixSelect(DbFixer*, Select*); int sqlite3FixExpr(DbFixer*, Expr*); int sqlite3FixExprList(DbFixer*, ExprList*); int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); int sqlite3AtoF(const char *z, double*); char *sqlite3_snprintf(int,char*,const char*,...); int sqlite3GetInt32(const char *, int*); int sqlite3FitsIn64Bits(const char *); int sqlite3utf16ByteLen(const void *pData, int nChar); int sqlite3utf8CharLen(const char *pData, int nByte); int sqlite3ReadUtf8(const unsigned char *); int sqlite3PutVarint(unsigned char *, u64); |
︙ | ︙ | |||
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | void sqlite3CodeSubselect(Parse *, Expr *); int sqlite3SelectResolve(Parse *, Select *, NameContext *); void sqlite3ColumnDefault(Vdbe *, Table *, int); void sqlite3AlterFinishAddColumn(Parse *, Token *); void sqlite3AlterBeginAddColumn(Parse *, SrcList *); const char *sqlite3TestErrorName(int); CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int); #ifdef SQLITE_SSE #include "sseInt.h" #endif #endif | > > > > > > > > | 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 | void sqlite3CodeSubselect(Parse *, Expr *); int sqlite3SelectResolve(Parse *, Select *, NameContext *); void sqlite3ColumnDefault(Vdbe *, Table *, int); void sqlite3AlterFinishAddColumn(Parse *, Token *); void sqlite3AlterBeginAddColumn(Parse *, SrcList *); const char *sqlite3TestErrorName(int); CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int); char sqlite3AffinityType(const Token*); void sqlite3Analyze(Parse*, Token*, Token*); int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); void sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); int sqlite3IsLikeFunction(sqlite3*,Expr*,char*); #ifdef SQLITE_SSE #include "sseInt.h" #endif #endif |
Changes to SQLite.Interop/src/table.c.
︙ | ︙ | |||
192 193 194 195 196 197 198 | azResult--; if( azResult==0 ) return; n = (int)azResult[0]; for(i=1; i<n; i++){ if( azResult[i] ) free(azResult[i]); } free(azResult); } } | < | 192 193 194 195 196 197 198 199 | azResult--; if( azResult==0 ) return; n = (int)azResult[0]; for(i=1; i<n; i++){ if( azResult[i] ) free(azResult[i]); } free(azResult); } } } |
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 22 23 24 25 26 27 28 29 30 31 | /* ** 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.7 2005/08/22 18:22:12 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> #include <string.h> #include <assert.h> #include <ctype.h> #define NUM_PREPARED_STMTS 10 #define MAX_PREPARED_STMTS 100 /* ** If TCL uses UTF-8 and SQLite is configured to use iso8859, then we ** have to do a translation when going between the two. Set the |
︙ | ︙ | |||
38 39 40 41 42 43 44 | /* ** New SQL functions can be created as TCL scripts. Each such function ** is described by an instance of the following structure. */ typedef struct SqlFunc SqlFunc; struct SqlFunc { Tcl_Interp *interp; /* The TCL interpret to execute the function */ | | > > | | 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 | /* ** New SQL functions can be created as TCL scripts. Each such function ** is described by an instance of the following structure. */ typedef struct SqlFunc SqlFunc; struct SqlFunc { Tcl_Interp *interp; /* The TCL interpret to execute the function */ Tcl_Obj *pScript; /* The Tcl_Obj representation of the script */ int useEvalObjv; /* True if it is safe to use Tcl_EvalObjv */ char *zName; /* Name of this function */ SqlFunc *pNext; /* Next function on the list of them all */ }; /* ** New collation sequences function can be created as TCL scripts. Each such ** function is described by an instance of the following structure. */ typedef struct SqlCollate SqlCollate; struct SqlCollate { Tcl_Interp *interp; /* The TCL interpret to execute the function */ char *zScript; /* The script to be run */ SqlCollate *pNext; /* Next function on the list of them all */ }; /* ** Prepared statements are cached for faster execution. Each prepared ** statement is described by an instance of the following structure. */ typedef struct SqlPreparedStmt SqlPreparedStmt; |
︙ | ︙ | |||
72 73 74 75 76 77 78 | /* ** There is one instance of this structure for each SQLite database ** that has been opened by the SQLite TCL interface. */ typedef struct SqliteDb SqliteDb; struct SqliteDb { | | | | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* ** There is one instance of this structure for each SQLite database ** that has been opened by the SQLite TCL interface. */ 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 */ SqlPreparedStmt *stmtList; /* List of prepared statements*/ SqlPreparedStmt *stmtLast; /* Last statement in the list */ int maxStmt; /* The next maximum number of stmtList */ int nStmt; /* Number of statements in stmtList */ }; /* ** Look at the script prefix in pCmd. We will be executing this script ** after first appending one or more arguments. This routine analyzes ** the script to see if it is safe to use Tcl_EvalObjv() on the script ** rather than the more general Tcl_EvalEx(). Tcl_EvalObjv() is much ** faster. ** ** Scripts that are safe to use with Tcl_EvalObjv() consists of a ** command name followed by zero or more arguments with no [...] or $ ** or {...} or ; to be seen anywhere. Most callback scripts consist ** of just a single procedure name and they meet this requirement. */ static int safeToUseEvalObjv(Tcl_Interp *interp, Tcl_Obj *pCmd){ /* We could try to do something with Tcl_Parse(). But we will instead ** just do a search for forbidden characters. If any of the forbidden ** characters appear in pCmd, we will report the string as unsafe. */ const char *z; int n; z = Tcl_GetStringFromObj(pCmd, &n); while( n-- > 0 ){ int c = *(z++); if( c=='$' || c=='[' || c==';' ) return 0; } return 1; } /* ** Find an SqlFunc structure with the given name. Or create a new ** one if an existing one cannot be found. Return a pointer to the ** structure. */ static SqlFunc *findSqlFunc(SqliteDb *pDb, const char *zName){ SqlFunc *p, *pNew; int i; pNew = (SqlFunc*)Tcl_Alloc( sizeof(*pNew) + strlen(zName) + 1 ); pNew->zName = (char*)&pNew[1]; for(i=0; zName[i]; i++){ pNew->zName[i] = tolower(zName[i]); } pNew->zName[i] = 0; for(p=pDb->pFunc; p; p=p->pNext){ if( strcmp(p->zName, pNew->zName)==0 ){ Tcl_Free((char*)pNew); return p; } } pNew->interp = pDb->interp; pNew->pScript = 0; pNew->pNext = pDb->pFunc; pDb->pFunc = pNew; return pNew; } /* ** Finalize and free a list of prepared statements */ static void flushStmtCache( SqliteDb *pDb ){ SqlPreparedStmt *pPreStmt; |
︙ | ︙ | |||
117 118 119 120 121 122 123 124 125 126 127 128 129 130 | static void DbDeleteCmd(void *db){ SqliteDb *pDb = (SqliteDb*)db; flushStmtCache(pDb); sqlite3_close(pDb->db); while( pDb->pFunc ){ SqlFunc *pFunc = pDb->pFunc; pDb->pFunc = pFunc->pNext; Tcl_Free((char*)pFunc); } while( pDb->pCollate ){ SqlCollate *pCollate = pDb->pCollate; pDb->pCollate = pCollate->pNext; Tcl_Free((char*)pCollate); } | > | 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | static void DbDeleteCmd(void *db){ SqliteDb *pDb = (SqliteDb*)db; flushStmtCache(pDb); sqlite3_close(pDb->db); while( pDb->pFunc ){ SqlFunc *pFunc = pDb->pFunc; pDb->pFunc = pFunc->pNext; Tcl_DecrRefCount(pFunc->pScript); Tcl_Free((char*)pFunc); } while( pDb->pCollate ){ SqlCollate *pCollate = pDb->pCollate; pDb->pCollate = pCollate->pNext; Tcl_Free((char*)pCollate); } |
︙ | ︙ | |||
147 148 149 150 151 152 153 | ** This routine is called when a database file is locked while trying ** to execute SQL. */ static int DbBusyHandler(void *cd, int nTries){ SqliteDb *pDb = (SqliteDb*)cd; int rc; char zVal[30]; | < < < < < < | < | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | ** This routine is called when a database file is locked while trying ** to execute SQL. */ static int DbBusyHandler(void *cd, int nTries){ SqliteDb *pDb = (SqliteDb*)cd; int rc; char zVal[30]; sprintf(zVal, "%d", nTries); rc = Tcl_VarEval(pDb->interp, pDb->zBusy, " ", zVal, (char*)0); if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){ return 0; } return 1; } /* |
︙ | ︙ | |||
243 244 245 246 247 248 249 | SqlCollate *p = (SqlCollate *)pCtx; Tcl_Obj *pCmd; pCmd = Tcl_NewStringObj(p->zScript, -1); Tcl_IncrRefCount(pCmd); Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zA, nA)); Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zB, nB)); | | | > > > > > > > > | > > > > > > > > > > | > > > > > > > | | > | > > > > > > > > > > > | > > > > > > > > > > > > > > > | > | | | > > > > > > > > > > > > | | > | > > > > > > | 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 | SqlCollate *p = (SqlCollate *)pCtx; Tcl_Obj *pCmd; pCmd = Tcl_NewStringObj(p->zScript, -1); Tcl_IncrRefCount(pCmd); Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zA, nA)); Tcl_ListObjAppendElement(p->interp, pCmd, Tcl_NewStringObj(zB, nB)); Tcl_EvalObjEx(p->interp, pCmd, TCL_EVAL_DIRECT); Tcl_DecrRefCount(pCmd); return (atoi(Tcl_GetStringResult(p->interp))); } /* ** This routine is called to evaluate an SQL function implemented ** using TCL script. */ static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv){ SqlFunc *p = sqlite3_user_data(context); Tcl_Obj *pCmd; int i; int rc; if( argc==0 ){ /* If there are no arguments to the function, call Tcl_EvalObjEx on the ** script object directly. This allows the TCL compiler to generate ** bytecode for the command on the first invocation and thus make ** subsequent invocations much faster. */ pCmd = p->pScript; Tcl_IncrRefCount(pCmd); rc = Tcl_EvalObjEx(p->interp, pCmd, 0); Tcl_DecrRefCount(pCmd); }else{ /* If there are arguments to the function, make a shallow copy of the ** script object, lappend the arguments, then evaluate the copy. ** ** By "shallow" copy, we mean a only the outer list Tcl_Obj is duplicated. ** The new Tcl_Obj contains pointers to the original list elements. ** That way, when Tcl_EvalObjv() is run and shimmers the first element ** of the list to tclCmdNameType, that alternate representation will ** be preserved and reused on the next invocation. */ Tcl_Obj **aArg; int nArg; if( Tcl_ListObjGetElements(p->interp, p->pScript, &nArg, &aArg) ){ sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); return; } pCmd = Tcl_NewListObj(nArg, aArg); Tcl_IncrRefCount(pCmd); for(i=0; i<argc; i++){ sqlite3_value *pIn = argv[i]; Tcl_Obj *pVal; /* Set pVal to contain the i'th column of this row. */ switch( sqlite3_value_type(pIn) ){ case SQLITE_BLOB: { int bytes = sqlite3_value_bytes(pIn); pVal = Tcl_NewByteArrayObj(sqlite3_value_blob(pIn), bytes); break; } case SQLITE_INTEGER: { sqlite_int64 v = sqlite3_value_int64(pIn); if( v>=-2147483647 && v<=2147483647 ){ pVal = Tcl_NewIntObj(v); }else{ pVal = Tcl_NewWideIntObj(v); } break; } case SQLITE_FLOAT: { double r = sqlite3_value_double(pIn); pVal = Tcl_NewDoubleObj(r); break; } case SQLITE_NULL: { pVal = Tcl_NewStringObj("", 0); break; } default: { int bytes = sqlite3_value_bytes(pIn); pVal = Tcl_NewStringObj(sqlite3_value_text(pIn), bytes); break; } } rc = Tcl_ListObjAppendElement(p->interp, pCmd, pVal); if( rc ){ Tcl_DecrRefCount(pCmd); sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); return; } } if( !p->useEvalObjv ){ /* Tcl_EvalObjEx() will automatically call Tcl_EvalObjv() if pCmd ** is a list without a string representation. To prevent this from ** happening, make sure pCmd has a valid string representation */ Tcl_GetString(pCmd); } rc = Tcl_EvalObjEx(p->interp, pCmd, TCL_EVAL_DIRECT); Tcl_DecrRefCount(pCmd); } if( rc && rc!=TCL_RETURN ){ sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); }else{ Tcl_Obj *pVar = Tcl_GetObjResult(p->interp); int n; u8 *data; char *zType = pVar->typePtr ? pVar->typePtr->name : ""; char c = zType[0]; if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){ /* Only return a BLOB type if the Tcl variable is a bytearray and ** has no string representation. */ data = Tcl_GetByteArrayFromObj(pVar, &n); sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT); }else if( (c=='b' && strcmp(zType,"boolean")==0) || (c=='i' && strcmp(zType,"int")==0) ){ Tcl_GetIntFromObj(0, pVar, &n); sqlite3_result_int(context, n); }else if( c=='d' && strcmp(zType,"double")==0 ){ double r; Tcl_GetDoubleFromObj(0, pVar, &r); sqlite3_result_double(context, r); }else if( c=='w' && strcmp(zType,"wideInt")==0 ){ Tcl_WideInt v; Tcl_GetWideIntFromObj(0, pVar, &v); sqlite3_result_int64(context, v); }else{ data = Tcl_GetStringFromObj(pVar, &n); sqlite3_result_text(context, data, n, SQLITE_TRANSIENT); } } } |
︙ | ︙ | |||
347 348 349 350 351 352 353 354 355 356 357 358 359 360 | case SQLITE_SELECT : zCode="SQLITE_SELECT"; break; case SQLITE_TRANSACTION : zCode="SQLITE_TRANSACTION"; break; case SQLITE_UPDATE : zCode="SQLITE_UPDATE"; break; case SQLITE_ATTACH : zCode="SQLITE_ATTACH"; break; case SQLITE_DETACH : zCode="SQLITE_DETACH"; break; case SQLITE_ALTER_TABLE : zCode="SQLITE_ALTER_TABLE"; break; case SQLITE_REINDEX : zCode="SQLITE_REINDEX"; break; default : zCode="????"; break; } Tcl_DStringInit(&str); Tcl_DStringAppend(&str, pDb->zAuth, -1); Tcl_DStringAppendElement(&str, zCode); Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : ""); Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : ""); | > | 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | case SQLITE_SELECT : zCode="SQLITE_SELECT"; break; case SQLITE_TRANSACTION : zCode="SQLITE_TRANSACTION"; break; case SQLITE_UPDATE : zCode="SQLITE_UPDATE"; break; case SQLITE_ATTACH : zCode="SQLITE_ATTACH"; break; case SQLITE_DETACH : zCode="SQLITE_DETACH"; break; case SQLITE_ALTER_TABLE : zCode="SQLITE_ALTER_TABLE"; break; case SQLITE_REINDEX : zCode="SQLITE_REINDEX"; break; case SQLITE_ANALYZE : zCode="SQLITE_ANALYZE"; break; default : zCode="????"; break; } Tcl_DStringInit(&str); Tcl_DStringAppend(&str, pDb->zAuth, -1); Tcl_DStringAppendElement(&str, zCode); Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : ""); Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : ""); |
︙ | ︙ | |||
465 466 467 468 469 470 471 | "authorizer", "busy", "cache", "changes", "close", "collate", "collation_needed", "commit_hook", "complete", "copy", "errorcode", "eval", "function", "last_insert_rowid", "nullvalue", "onecolumn", "progress", "rekey", "timeout", "total_changes", "trace", | | < | | 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 | "authorizer", "busy", "cache", "changes", "close", "collate", "collation_needed", "commit_hook", "complete", "copy", "errorcode", "eval", "function", "last_insert_rowid", "nullvalue", "onecolumn", "progress", "rekey", "timeout", "total_changes", "trace", "transaction", "version", 0 }; enum DB_enum { DB_AUTHORIZER, DB_BUSY, DB_CACHE, DB_CHANGES, DB_CLOSE, DB_COLLATE, DB_COLLATION_NEEDED, DB_COMMIT_HOOK, DB_COMPLETE, DB_COPY, DB_ERRORCODE, DB_EVAL, DB_FUNCTION, DB_LAST_INSERT_ROWID,DB_NULLVALUE, DB_ONECOLUMN, DB_PROGRESS, DB_REKEY, DB_TIMEOUT, DB_TOTAL_CHANGES, DB_TRACE, DB_TRANSACTION, DB_VERSION, }; /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ if( objc<2 ){ Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ..."); return TCL_ERROR; } |
︙ | ︙ | |||
920 921 922 923 924 925 926 | if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':') ){ Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0); if( pVar ){ int n; u8 *data; char *zType = pVar->typePtr ? pVar->typePtr->name : ""; char c = zType[0]; | | > > > > > > | 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 | if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':') ){ Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0); if( pVar ){ int n; u8 *data; char *zType = pVar->typePtr ? pVar->typePtr->name : ""; char c = zType[0]; if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){ /* Only load a BLOB type if the Tcl variable is a bytearray and ** has no string representation. */ data = Tcl_GetByteArrayFromObj(pVar, &n); sqlite3_bind_blob(pStmt, i, data, n, SQLITE_STATIC); Tcl_IncrRefCount(pVar); apParm[nParm++] = pVar; }else if( (c=='b' && strcmp(zType,"boolean")==0) || (c=='i' && strcmp(zType,"int")==0) ){ Tcl_GetIntFromObj(interp, pVar, &n); sqlite3_bind_int(pStmt, i, n); }else if( c=='d' && strcmp(zType,"double")==0 ){ double r; Tcl_GetDoubleFromObj(interp, pVar, &r); sqlite3_bind_double(pStmt, i, r); }else if( c=='w' && strcmp(zType,"wideInt")==0 ){ Tcl_WideInt v; Tcl_GetWideIntFromObj(interp, pVar, &v); sqlite3_bind_int64(pStmt, i, v); }else{ data = Tcl_GetStringFromObj(pVar, &n); sqlite3_bind_text(pStmt, i, data, n, SQLITE_STATIC); Tcl_IncrRefCount(pVar); apParm[nParm++] = pVar; } }else{ |
︙ | ︙ | |||
1142 1143 1144 1145 1146 1147 1148 1149 | ** $db function NAME SCRIPT ** ** Create a new SQL function called NAME. Whenever that function is ** called, invoke SCRIPT to evaluate the function. */ case DB_FUNCTION: { SqlFunc *pFunc; char *zName; | > < < | | | | > | < | > | 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 | ** $db function NAME SCRIPT ** ** Create a new SQL function called NAME. Whenever that function is ** called, invoke SCRIPT to evaluate the function. */ case DB_FUNCTION: { SqlFunc *pFunc; Tcl_Obj *pScript; char *zName; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 2, objv, "NAME SCRIPT"); return TCL_ERROR; } zName = Tcl_GetStringFromObj(objv[2], 0); pScript = objv[3]; pFunc = findSqlFunc(pDb, zName); if( pFunc==0 ) return TCL_ERROR; if( pFunc->pScript ){ Tcl_DecrRefCount(pFunc->pScript); } pFunc->pScript = pScript; Tcl_IncrRefCount(pScript); pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript); rc = sqlite3_create_function(pDb->db, zName, -1, SQLITE_UTF8, pFunc, tclSqlFunc, 0, 0); if( rc!=SQLITE_OK ){ rc = TCL_ERROR; Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE); }else{ /* Must flush any cached statements */ |
︙ | ︙ | |||
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 | sqlite3_trace(pDb->db, DbTraceHandler, pDb); }else{ sqlite3_trace(pDb->db, 0, 0); } } break; } /* $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR? ** ** Copy data into table from filename, optionally using SEPARATOR ** as column separators. If a column contains a null string, or the ** value of NULLINDICATOR, a NULL is inserted for the column. ** conflict-algorithm is one of the sqlite conflict algorithms: | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 1552 1553 1554 | 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 ** transaction) and execute the TCL script SCRIPT. After SCRIPT ** completes, either commit the transaction or roll it back if SCRIPT ** throws an exception. Or if no new transation was started, do nothing. ** pass the exception on up the stack. ** ** This command was inspired by Dave Thomas's talk on Ruby at the ** 2005 O'Reilly Open Source Convention (OSCON). */ case DB_TRANSACTION: { int inTrans; Tcl_Obj *pScript; const char *zBegin = "BEGIN"; if( objc!=3 && objc!=4 ){ Tcl_WrongNumArgs(interp, 2, objv, "[TYPE] SCRIPT"); return TCL_ERROR; } if( objc==3 ){ pScript = objv[2]; } else { static const char *TTYPE_strs[] = { "deferred", "exclusive", "immediate", 0 }; enum TTYPE_enum { TTYPE_DEFERRED, TTYPE_EXCLUSIVE, TTYPE_IMMEDIATE }; int ttype; if( Tcl_GetIndexFromObj(interp, objv[2], TTYPE_strs, "transaction type", 0, &ttype) ){ return TCL_ERROR; } switch( (enum TTYPE_enum)ttype ){ case TTYPE_DEFERRED: /* no-op */; break; case TTYPE_EXCLUSIVE: zBegin = "BEGIN EXCLUSIVE"; break; case TTYPE_IMMEDIATE: zBegin = "BEGIN IMMEDIATE"; break; } pScript = objv[3]; } inTrans = !sqlite3_get_autocommit(pDb->db); if( !inTrans ){ sqlite3_exec(pDb->db, zBegin, 0, 0, 0); } rc = Tcl_EvalObjEx(interp, pScript, 0); if( !inTrans ){ const char *zEnd; if( rc==TCL_ERROR ){ zEnd = "ROLLBACK"; } else { zEnd = "COMMIT"; } sqlite3_exec(pDb->db, zEnd, 0, 0, 0); } break; } /* $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR? ** ** Copy data into table from filename, optionally using SEPARATOR ** as column separators. If a column contains a null string, or the ** value of NULLINDICATOR, a NULL is inserted for the column. ** conflict-algorithm is one of the sqlite conflict algorithms: |
︙ | ︙ |
Changes to SQLite.Interop/src/tokenize.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ************************************************************************* ** 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. ** | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ************************************************************************* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include <stdlib.h> /* |
︙ | ︙ | |||
37 38 39 40 41 42 43 | ** the #include below. */ #include "keywordhash.h" /* ** If X is a character that can be used in an identifier and | | | | | | 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 | ** the #include below. */ #include "keywordhash.h" /* ** If X is a character that can be used in an identifier and ** X&0x80==0 then sqlite3IsIdChar[X] will be 1. If X&0x80==0x80 then ** X is always an identifier character. (Hence all UTF-8 ** characters can be part of an identifier). sqlite3IsIdChar[X] will ** be 0 for every character in the lower 128 ASCII characters ** that cannot be used as part of an identifier. ** ** In this implementation, an identifier can be a string of ** alphabetic characters, digits, and "_" plus any character ** with the high-order bit set. The latter rule means that ** any sequence of UTF-8 characters or characters taken from ** an extended ISO8859 character set can form an identifier. ** ** Ticket #1066. the SQL standard does not allow '$' in the ** middle of identfiers. But many SQL implementations do. ** SQLite will allow '$' in identifiers for compatibility. ** But the feature is undocumented. */ extern const char sqlite3IsIdChar[] = { /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */ }; #define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20])) /* ** Return the length of the token that begins at z[0]. ** Store the token type in *tokenType before returning. */ static int getToken(const unsigned char *z, int *tokenType){ int i, c; |
︙ | ︙ | |||
182 183 184 185 186 187 188 | *tokenType = TK_BITAND; return 1; } case '~': { *tokenType = TK_BITNOT; return 1; } | | < < < < | > | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | *tokenType = TK_BITAND; return 1; } case '~': { *tokenType = TK_BITNOT; return 1; } case '`': case '\'': case '"': { int delim = z[0]; for(i=1; (c=z[i])!=0; i++){ if( c==delim ){ if( z[i+1]==delim ){ i++; }else{ break; |
︙ | ︙ | |||
238 239 240 241 242 243 244 | return i; } case '?': { *tokenType = TK_VARIABLE; for(i=1; isdigit(z[i]); i++){} return i; } | | | > > > | | | > > > | < < < < | < < < < < < | | > | | | > | | | | | | | | | | | | > | | | | | < < | 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 | return i; } case '?': { *tokenType = TK_VARIABLE; for(i=1; isdigit(z[i]); i++){} return i; } case '#': { for(i=1; isdigit(z[i]); i++){} if( i>1 ){ /* Parameters of the form #NNN (where NNN is a number) are used ** internally by sqlite3NestedParse. */ *tokenType = TK_REGISTER; return i; } /* Fall through into the next case if the '#' is not followed by ** a digit. Try to match #AAAA where AAAA is a parameter name. */ } #ifndef SQLITE_OMIT_TCL_VARIABLE case '$': #endif case ':': { int n = 0; *tokenType = TK_VARIABLE; for(i=1; (c=z[i])!=0; i++){ if( IdChar(c) ){ n++; #ifndef SQLITE_OMIT_TCL_VARIABLE }else if( c=='(' && n>0 ){ do{ i++; }while( (c=z[i])!=0 && !isspace(c) && c!=')' ); if( c==')' ){ i++; }else{ *tokenType = TK_ILLEGAL; } break; }else if( c==':' && z[i+1]==':' ){ i++; #endif }else{ break; } } if( n==0 ) *tokenType = TK_ILLEGAL; return i; } #ifndef SQLITE_OMIT_BLOB_LITERAL case 'x': case 'X': { if( (c=z[1])=='\'' || c=='"' ){ int delim = c; *tokenType = TK_BLOB; for(i=2; (c=z[i])!=0; i++){ if( c==delim ){ |
︙ | ︙ | |||
429 430 431 432 433 434 435 | sqlite3DeleteTrigger(pParse->pNewTrigger); sqliteFree(pParse->apVarExpr); if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){ pParse->rc = SQLITE_ERROR; } return nErr; } | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 423 424 425 426 427 428 429 430 | sqlite3DeleteTrigger(pParse->pNewTrigger); sqliteFree(pParse->apVarExpr); if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){ pParse->rc = SQLITE_ERROR; } return nErr; } } |
Changes to SQLite.Interop/src/trigger.c.
︙ | ︙ | |||
236 237 238 239 240 241 242 | v = sqlite3GetVdbe(pParse); if( v==0 ) goto triggerfinish_cleanup; sqlite3BeginWriteOperation(pParse, 0, pTrig->iDb); sqlite3OpenMasterTable(v, pTrig->iDb); addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig); sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0); sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0); | | | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | v = sqlite3GetVdbe(pParse); if( v==0 ) goto triggerfinish_cleanup; sqlite3BeginWriteOperation(pParse, 0, pTrig->iDb); sqlite3OpenMasterTable(v, pTrig->iDb); addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig); sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0); sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0); sqlite3VdbeChangeP3(v, addr+6, (const char *)pAll->z, pAll->n); sqlite3ChangeCookie(db, v, pTrig->iDb); sqlite3VdbeAddOp(v, OP_Close, 0, 0); sqlite3VdbeOp3(v, OP_ParseSchema, pTrig->iDb, 0, sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC); } if( db->init.busy ){ |
︙ | ︙ | |||
277 278 279 280 281 282 283 | ** string is ephemeral - it will go away as soon as the sqlite3_exec() ** call that started the parser exits. This routine makes a persistent ** copy of all the Expr.token.z strings so that the TriggerStep structure ** will be valid even after the sqlite3_exec() call returns. */ static void sqlitePersistTriggerStep(TriggerStep *p){ if( p->target.z ){ | | | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | ** string is ephemeral - it will go away as soon as the sqlite3_exec() ** call that started the parser exits. This routine makes a persistent ** copy of all the Expr.token.z strings so that the TriggerStep structure ** will be valid even after the sqlite3_exec() call returns. */ static void sqlitePersistTriggerStep(TriggerStep *p){ if( p->target.z ){ p->target.z = (const unsigned char *)sqliteStrNDup((const char *)p->target.z, p->target.n); p->target.dyn = 1; } if( p->pSelect ){ Select *pNew = sqlite3SelectDup(p->pSelect); sqlite3SelectDelete(p->pSelect); p->pSelect = pNew; } |
︙ | ︙ | |||
620 621 622 623 624 625 626 | int iDb; /* Index of the database to use */ SrcList *pSrc; /* SrcList to be returned */ iDb = pStep->pTrig->iDb; if( iDb==0 || iDb>=2 ){ assert( iDb<pParse->db->nDb ); sDb.z = (const unsigned char *)pParse->db->aDb[iDb].zName; | | | 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | int iDb; /* Index of the database to use */ SrcList *pSrc; /* SrcList to be returned */ iDb = pStep->pTrig->iDb; if( iDb==0 || iDb>=2 ){ assert( iDb<pParse->db->nDb ); sDb.z = (const unsigned char *)pParse->db->aDb[iDb].zName; sDb.n = strlen((const char *)sDb.z); pSrc = sqlite3SrcListAppend(0, &sDb, &pStep->target); } else { pSrc = sqlite3SrcListAppend(0, &pStep->target, 0); } return pSrc; } |
︙ | ︙ | |||
799 800 801 802 803 804 805 | sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger); } pTrigger = pTrigger->pNext; } return 0; } #endif /* !defined(SQLITE_OMIT_TRIGGER) */ | | < | 799 800 801 802 803 804 805 806 | sqlite3VdbeResolveLabel(pParse->pVdbe, endTrigger); } pTrigger = pTrigger->pNext; } return 0; } #endif /* !defined(SQLITE_OMIT_TRIGGER) */ } |
Changes to SQLite.Interop/src/update.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ** 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.7 2005/08/22 18:22:12 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. |
︙ | ︙ | |||
46 47 48 49 50 51 52 | */ void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){ if( pTab && !pTab->pSelect ){ sqlite3_value *pValue; u8 enc = sqlite3VdbeDb(v)->enc; Column *pCol = &pTab->aCol[i]; sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue); | > | > > > | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | */ void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){ if( pTab && !pTab->pSelect ){ sqlite3_value *pValue; u8 enc = sqlite3VdbeDb(v)->enc; Column *pCol = &pTab->aCol[i]; sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue); if( pValue ){ sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM); }else{ VdbeComment((v, "# %s.%s", pTab->zName, pCol->zName)); } } } /* ** Process an UPDATE statement. ** ** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL; |
︙ | ︙ | |||
272 273 274 275 276 277 278 | */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); if( pWInfo==0 ) goto update_cleanup; /* Remember the index of every item to be updated. */ sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); | | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | */ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0); if( pWInfo==0 ) goto update_cleanup; /* Remember the index of every item to be updated. */ sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); sqlite3VdbeAddOp(v, OP_FifoWrite, 0, 0); /* End the database scan loop. */ sqlite3WhereEnd(pWInfo); /* Initialize the count of updated rows */ |
︙ | ︙ | |||
294 295 296 297 298 299 300 | sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol); sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol); /* The top of the update loop for when there are triggers. */ | < | | 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol); sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0); sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol); /* The top of the update loop for when there are triggers. */ addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0); if( !isView ){ sqlite3VdbeAddOp(v, OP_Dup, 0, 0); sqlite3VdbeAddOp(v, OP_Dup, 0, 0); /* Open a cursor and make it point to the record that is ** being updated. */ |
︙ | ︙ | |||
388 389 390 391 392 393 394 | /* Loop over every record that needs updating. We have to load ** the old data for each record to be updated because some columns ** might not change and we will need to copy the old value. ** Also, the old data is needed to delete the old index entires. ** So make the cursor point at the old record. */ if( !triggers_exist ){ | < | | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | /* Loop over every record that needs updating. We have to load ** the old data for each record to be updated because some columns ** might not change and we will need to copy the old value. ** Also, the old data is needed to delete the old index entires. ** So make the cursor point at the old record. */ if( !triggers_exist ){ addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0); sqlite3VdbeAddOp(v, OP_Dup, 0, 0); } sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr); /* If the record number will change, push the record number as it ** will be after the update. (The old record number is currently ** on top of the stack.) |
︙ | ︙ | |||
467 468 469 470 471 472 473 | } /* 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); sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v)); | < | 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | } /* 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); sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v)); /* 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); } |
︙ | ︙ | |||
502 503 504 505 506 507 508 | sqliteFree(apIdx); sqliteFree(aXRef); sqlite3SrcListDelete(pTabList); sqlite3ExprListDelete(pChanges); sqlite3ExprDelete(pWhere); return; } | | < | 503 504 505 506 507 508 509 510 | sqliteFree(apIdx); sqliteFree(aXRef); sqlite3SrcListDelete(pTabList); sqlite3ExprListDelete(pChanges); sqlite3ExprDelete(pWhere); return; } } |
Changes to SQLite.Interop/src/utf.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ** 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. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ** 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.7 2005/08/22 18:22:12 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 |
︙ | ︙ | |||
567 568 569 570 571 572 573 | READ_UTF16BE(z, c); assert( c==i ); assert( (z-zBuf)==n ); } } #endif /* SQLITE_TEST */ #endif /* SQLITE_OMIT_UTF16 */ | | < | 567 568 569 570 571 572 573 574 | READ_UTF16BE(z, c); assert( c==i ); assert( (z-zBuf)==n ); } } #endif /* SQLITE_TEST */ #endif /* SQLITE_OMIT_UTF16 */ } |
Changes to SQLite.Interop/src/util.c.
︙ | ︙ | |||
13 14 15 16 17 18 19 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ** ************************************************************************* ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** ** $Id: util.c,v 1.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include <stdarg.h> #include <ctype.h> #if SQLITE_MEMDEBUG>2 && defined(__GLIBC__) #include <execinfo.h> |
︙ | ︙ | |||
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | ** is used to check for memory leaks. The iMallocFail and iMallocReset ** values are used to simulate malloc() failures during testing in ** order to verify that the library correctly handles an out-of-memory ** condition. */ int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */ int sqlite3_nFree; /* Number of sqliteFree() calls */ int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */ int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */ #if SQLITE_MEMDEBUG>1 static int memcnt = 0; #endif /* ** Number of 32-bit guard words. This should probably be a multiple of ** 2 since on 64-bit machines we want the value returned by sqliteMalloc() ** to be 8-byte aligned. */ #define N_GUARD 2 /* | > > | | | < < < > > > | | | > > > > > > > > | > > > > > > > | 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 | ** is used to check for memory leaks. The iMallocFail and iMallocReset ** values are used to simulate malloc() failures during testing in ** order to verify that the library correctly handles an out-of-memory ** condition. */ int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */ int sqlite3_nFree; /* Number of sqliteFree() calls */ int sqlite3_memUsed; /* Total memory obtained from malloc */ int sqlite3_memMax; /* Mem usage high-water mark */ int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */ int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */ #if SQLITE_MEMDEBUG>1 static int memcnt = 0; #endif /* ** Number of 32-bit guard words. This should probably be a multiple of ** 2 since on 64-bit machines we want the value returned by sqliteMalloc() ** to be 8-byte aligned. */ #define N_GUARD 2 /* ** Check for a simulated memory allocation failure. Return true if ** the failure should be simulated. Return false to proceed as normal. */ static int simulatedMallocFailure(int n, char *zFile, int line){ if( sqlite3_iMallocFail>=0 ){ sqlite3_iMallocFail--; if( sqlite3_iMallocFail==0 ){ sqlite3_malloc_failed++; #if SQLITE_MEMDEBUG>1 fprintf(stderr,"**** failed to allocate %d bytes at %s:%d\n", n, zFile,line); #endif sqlite3_iMallocFail = sqlite3_iMallocReset; return 1; } } return 0; } /* ** Allocate new memory and set it to zero. Return NULL if ** no memory is available. */ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){ void *p; int *pi; int i, k; if( n==0 ){ return 0; } if( simulatedMallocFailure(n, zFile, line) ){ return 0; } sqlite3_memUsed += n; if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed; k = (n+sizeof(int)-1)/sizeof(int); pi = malloc( (N_GUARD*2+1+k)*sizeof(int)); if( pi==0 ){ if( n>0 ) sqlite3_malloc_failed++; return 0; } sqlite3_nMalloc++; |
︙ | ︙ | |||
156 157 158 159 160 161 162 163 164 165 166 167 168 169 | for(i=0; i<N_GUARD; i++){ if( pi[i]!=0xdead1122 ){ fprintf(stderr,"Low-end memory corruption at 0x%x\n", (int)p); return; } } n = pi[N_GUARD]; k = (n+sizeof(int)-1)/sizeof(int); for(i=0; i<N_GUARD; i++){ if( pi[k+N_GUARD+1+i]!=0xdead3344 ){ fprintf(stderr,"High-end memory corruption at 0x%x\n", (int)p); return; } } | > | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | for(i=0; i<N_GUARD; i++){ if( pi[i]!=0xdead1122 ){ fprintf(stderr,"Low-end memory corruption at 0x%x\n", (int)p); return; } } n = pi[N_GUARD]; sqlite3_memUsed -= n; k = (n+sizeof(int)-1)/sizeof(int); for(i=0; i<N_GUARD; i++){ if( pi[k+N_GUARD+1+i]!=0xdead3344 ){ fprintf(stderr,"High-end memory corruption at 0x%x\n", (int)p); return; } } |
︙ | ︙ | |||
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 | void *p; if( oldP==0 ){ return sqlite3Malloc_(n,1,zFile,line); } if( n==0 ){ sqlite3Free_(oldP,zFile,line); return 0; } oldPi = oldP; oldPi -= N_GUARD+1; if( oldPi[0]!=0xdead1122 ){ fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)oldP); return 0; } oldN = oldPi[N_GUARD]; oldK = (oldN+sizeof(int)-1)/sizeof(int); for(i=0; i<N_GUARD; i++){ if( oldPi[oldK+N_GUARD+1+i]!=0xdead3344 ){ fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n", (int)oldP); return 0; } } k = (n + sizeof(int) - 1)/sizeof(int); pi = malloc( (k+N_GUARD*2+1)*sizeof(int) ); if( pi==0 ){ if( n>0 ) sqlite3_malloc_failed++; return 0; } for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122; pi[N_GUARD] = n; for(i=0; i<N_GUARD; i++) pi[k+N_GUARD+1+i] = 0xdead3344; p = &pi[N_GUARD+1]; memcpy(p, oldP, n>oldN ? oldN : n); if( n>oldN ){ memset(&((char*)p)[oldN], 0x55, n-oldN); } memset(oldPi, 0xab, (oldK+N_GUARD+2)*sizeof(int)); | > > > > > > | 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 | void *p; if( oldP==0 ){ return sqlite3Malloc_(n,1,zFile,line); } if( n==0 ){ sqlite3Free_(oldP,zFile,line); return 0; } if( simulatedMallocFailure(n, zFile, line) ){ return 0; } oldPi = oldP; oldPi -= N_GUARD+1; if( oldPi[0]!=0xdead1122 ){ fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)oldP); return 0; } oldN = oldPi[N_GUARD]; sqlite3_memUsed -= oldN; oldK = (oldN+sizeof(int)-1)/sizeof(int); for(i=0; i<N_GUARD; i++){ if( oldPi[oldK+N_GUARD+1+i]!=0xdead3344 ){ fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n", (int)oldP); return 0; } } k = (n + sizeof(int) - 1)/sizeof(int); pi = malloc( (k+N_GUARD*2+1)*sizeof(int) ); if( pi==0 ){ if( n>0 ) sqlite3_malloc_failed++; return 0; } for(i=0; i<N_GUARD; i++) pi[i] = 0xdead1122; pi[N_GUARD] = n; sqlite3_memUsed += n; if( sqlite3_memMax<sqlite3_memUsed ) sqlite3_memMax = sqlite3_memUsed; for(i=0; i<N_GUARD; i++) pi[k+N_GUARD+1+i] = 0xdead3344; p = &pi[N_GUARD+1]; memcpy(p, oldP, n>oldN ? oldN : n); if( n>oldN ){ memset(&((char*)p)[oldN], 0x55, n-oldN); } memset(oldPi, 0xab, (oldK+N_GUARD+2)*sizeof(int)); |
︙ | ︙ | |||
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 | /* ** Allocate new memory and set it to zero. Return NULL if ** no memory is available. See also sqliteMallocRaw(). */ void *sqlite3Malloc(int n){ void *p; if( (p = malloc(n))==0 ){ if( n>0 ) sqlite3_malloc_failed++; }else{ memset(p, 0, n); } return p; } /* ** Allocate new memory but do not set it to zero. Return NULL if ** no memory is available. See also sqliteMalloc(). */ void *sqlite3MallocRaw(int n){ void *p; if( (p = malloc(n))==0 ){ if( n>0 ) sqlite3_malloc_failed++; } return p; } /* | > > | 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 | /* ** Allocate new memory and set it to zero. Return NULL if ** no memory is available. See also sqliteMallocRaw(). */ void *sqlite3Malloc(int n){ void *p; if( n==0 ) return 0; if( (p = malloc(n))==0 ){ if( n>0 ) sqlite3_malloc_failed++; }else{ memset(p, 0, n); } return p; } /* ** Allocate new memory but do not set it to zero. Return NULL if ** no memory is available. See also sqliteMalloc(). */ void *sqlite3MallocRaw(int n){ void *p; if( n==0 ) return 0; if( (p = malloc(n))==0 ){ if( n>0 ) sqlite3_malloc_failed++; } return p; } /* |
︙ | ︙ | |||
371 372 373 374 375 376 377 | *zResult = 0; va_start(ap, pz); while( (z = va_arg(ap, const char*))!=0 ){ strcpy(zResult, z); zResult += strlen(zResult); } va_end(ap); | | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | *zResult = 0; va_start(ap, pz); while( (z = va_arg(ap, const char*))!=0 ){ strcpy(zResult, z); zResult += strlen(zResult); } va_end(ap); #ifdef SQLITE_MEMDEBUG #if SQLITE_MEMDEBUG>1 fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz); #endif #endif } /* ** Set the most recent error code and error string for the sqlite |
︙ | ︙ | |||
459 460 461 462 463 464 465 | int quote; int i, j; if( z==0 ) return; quote = z[0]; switch( quote ){ case '\'': break; case '"': break; | > | | 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | int quote; int i, j; if( z==0 ) return; quote = z[0]; switch( quote ){ case '\'': break; case '"': break; case '`': break; /* For MySQL compatibility */ case '[': quote = ']'; break; /* For MS SqlServer compatibility */ default: return; } for(i=1, j=0; z[i]; i++){ if( z[i]==quote ){ if( z[i+1]==quote ){ z[j++] = quote; i++; |
︙ | ︙ | |||
564 565 566 567 568 569 570 | ** is not, the result is undefined. ** ** This routine is used instead of the library atof() function because ** the library atof() might want to use "," as the decimal point instead ** of "." depending on how locale is set. But that would cause problems ** for SQL. So this routine always uses "." regardless of locale. */ | | > | 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | ** is not, the result is undefined. ** ** This routine is used instead of the library atof() function because ** the library atof() might want to use "," as the decimal point instead ** of "." depending on how locale is set. But that would cause problems ** for SQL. So this routine always uses "." regardless of locale. */ int sqlite3AtoF(const char *z, double *pResult){ int sign = 1; const char *zBegin = z; LONGDOUBLE_TYPE v1 = 0.0; if( *z=='-' ){ sign = -1; z++; }else if( *z=='+' ){ z++; } |
︙ | ︙ | |||
612 613 614 615 616 617 618 | while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; } if( esign<0 ){ v1 /= scale; }else{ v1 *= scale; } } | < | > | 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | while( eval>=1 ){ scale *= 1.0e+1; eval -= 1; } if( esign<0 ){ v1 /= scale; }else{ v1 *= scale; } } *pResult = sign<0 ? -v1 : v1; return z - zBegin; } /* ** Return TRUE if zNum is a 64-bit signed integer and write ** the value of the integer into *pNum. If zNum is not an integer ** or is an integer that is too large to be expressed with 64 bits, ** then return false. If n>0 and the integer is string is not |
︙ | ︙ | |||
961 962 963 964 965 966 967 | assert( sizeof(p)==sizeof(v2) ); v2 = (u32)v; p = *(void**)&v2; } return p; } #endif | | < | 989 990 991 992 993 994 995 996 | assert( sizeof(p)==sizeof(v2) ); v2 = (u32)v; p = *(void**)&v2; } return p; } #endif } |
Changes to SQLite.Interop/src/vacuum.c.
︙ | ︙ | |||
13 14 15 16 17 18 19 | ** ************************************************************************* ** 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. ** | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ** ************************************************************************* ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #ifndef SQLITE_OMIT_VACUUM /* ** Generate a random name of 20 character in length. |
︙ | ︙ | |||
307 308 309 310 311 312 313 | } if( zSql ) sqliteFree( zSql ); sqlite3ResetInternalSchema(db, 0); #endif return rc; } | | < | 307 308 309 310 311 312 313 314 | } if( zSql ) sqliteFree( zSql ); sqlite3ResetInternalSchema(db, 0); #endif return rc; } } |
Changes to SQLite.Interop/src/vdbe.c.
︙ | ︙ | |||
42 43 44 45 46 47 48 | ** ** 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. ** | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | ** ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
453 454 455 456 457 458 459 | Vdbe *p /* The VDBE */ ){ int pc; /* The program counter */ Op *pOp; /* Current operation */ int rc = SQLITE_OK; /* Value to return */ sqlite3 *db = p->db; /* The database */ Mem *pTos; /* Top entry in the operand stack */ | < | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | Vdbe *p /* The VDBE */ ){ int pc; /* The program counter */ Op *pOp; /* Current operation */ int rc = SQLITE_OK; /* Value to return */ sqlite3 *db = p->db; /* The database */ Mem *pTos; /* Top entry in the operand stack */ #ifdef VDBE_PROFILE unsigned long long start; /* CPU clock count at start of opcode */ int origPc; /* Program counter at start of opcode */ #endif #ifndef SQLITE_OMIT_PROGRESS_CALLBACK int nProgressOps = 0; /* Opcodes executed since progress callback. */ #endif |
︙ | ︙ | |||
477 478 479 480 481 482 483 484 485 486 487 488 489 490 | pTos = p->pTos; if( sqlite3_malloc_failed ) goto no_mem; if( p->popStack ){ popStack(&pTos, p->popStack); p->popStack = 0; } p->resOnStack = 0; CHECK_FOR_INTERRUPT; for(pc=p->pc; rc==SQLITE_OK; pc++){ assert( pc>=0 && pc<p->nOp ); assert( pTos<=&p->aStack[pc] ); if( sqlite3_malloc_failed ) goto no_mem; #ifdef VDBE_PROFILE origPc = pc; | > | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | pTos = p->pTos; if( sqlite3_malloc_failed ) goto no_mem; if( p->popStack ){ popStack(&pTos, p->popStack); p->popStack = 0; } p->resOnStack = 0; db->busyHandler.nBusy = 0; CHECK_FOR_INTERRUPT; for(pc=p->pc; rc==SQLITE_OK; pc++){ assert( pc>=0 && pc<p->nOp ); assert( pTos<=&p->aStack[pc] ); if( sqlite3_malloc_failed ) goto no_mem; #ifdef VDBE_PROFILE origPc = pc; |
︙ | ︙ | |||
632 633 634 635 636 637 638 | case OP_Return: { /* no-push */ assert( p->returnDepth>0 ); p->returnDepth--; pc = p->returnStack[p->returnDepth] - 1; break; } | | > > | 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 | case OP_Return: { /* no-push */ assert( p->returnDepth>0 ); p->returnDepth--; pc = p->returnStack[p->returnDepth] - 1; break; } /* Opcode: Halt P1 P2 P3 ** ** Exit immediately. All open cursors, Lists, Sorts, 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, ** then back out all changes that have occurred during this execution of the ** VDBE, but do not rollback the transaction. ** ** If P3 is not null then it is an error message string. ** ** There is an implied "Halt 0 0 0" instruction inserted at the very end of ** every program. So a jump past the last instruction of the program ** is the same as executing Halt. */ case OP_Halt: { /* no-push */ p->pTos = pTos; |
︙ | ︙ | |||
666 667 668 669 670 671 672 | if( rc==SQLITE_BUSY ){ p->rc = SQLITE_BUSY; return SQLITE_BUSY; } return p->rc ? SQLITE_ERROR : SQLITE_DONE; } | | | < < < < < < | | > > | > > > > > > > > | | | | | | < | 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 696 697 698 699 700 701 702 703 704 705 706 | if( rc==SQLITE_BUSY ){ p->rc = SQLITE_BUSY; return SQLITE_BUSY; } return p->rc ? SQLITE_ERROR : SQLITE_DONE; } /* Opcode: Integer P1 * * ** ** The 32-bit integer value P1 is pushed onto the stack. */ case OP_Integer: { pTos++; pTos->flags = MEM_Int; pTos->i = pOp->p1; break; } /* Opcode: Int64 * * P3 ** ** P3 is a string representation of an integer. Convert that integer ** to a 64-bit value and push it onto the stack. */ case OP_Int64: { pTos++; assert( pOp->p3!=0 ); pTos->flags = MEM_Str|MEM_Static|MEM_Term; pTos->z = pOp->p3; pTos->n = strlen(pTos->z); pTos->enc = SQLITE_UTF8; pTos->i = sqlite3VdbeIntValue(pTos); pTos->flags |= MEM_Int; break; } /* Opcode: Real * * P3 ** ** The string value P3 is converted to a real and pushed on to the stack. */ |
︙ | ︙ | |||
999 1000 1001 1002 1003 1004 1005 | */ zNew = (char *)sqliteMallocRaw( nByte+2 ); if( zNew==0 ) goto no_mem; j = 0; pTerm = &pTos[1-nField]; for(i=j=0; i<nField; i++, pTerm++){ int n = pTerm->n; | | | 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | */ zNew = (char *)sqliteMallocRaw( nByte+2 ); if( zNew==0 ) goto no_mem; j = 0; pTerm = &pTos[1-nField]; for(i=j=0; i<nField; i++, pTerm++){ int n = pTerm->n; assert( pTerm->flags & (MEM_Str|MEM_Blob) ); memcpy(&zNew[j], pTerm->z, n); j += n; } zNew[j] = 0; zNew[j+1] = 0; assert( j==nByte ); |
︙ | ︙ | |||
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 | }else{ Release(pTos); pTos->flags = MEM_Int; } break; } /* 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 false then fall thru if either operand | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | }else{ Release(pTos); pTos->flags = MEM_Int; } break; } #ifndef SQLITE_OMIT_CAST /* Opcode: ToInt * * * ** ** Force the value on the top of the stack to be an integer. If ** The value is currently a real number, drop its fractional part. ** If the value is text or blob, try to convert it to an integer using the ** equivalent of atoi() and store 0 if no such conversion is possible. ** ** A NULL value is not changed by this routine. It remains NULL. */ case OP_ToInt: { /* no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; assert( MEM_Str==(MEM_Blob>>3) ); pTos->flags |= (pTos->flags&MEM_Blob)>>3; applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc); sqlite3VdbeMemIntegerify(pTos); break; } /* Opcode: ToNumeric * * * ** ** Force the value on the top of the stack to be numeric (either an ** integer or a floating-point number. ** If the value is text or blob, try to convert it to an using the ** equivalent of atoi() or atof() and store 0 if no such conversion ** is possible. ** ** A NULL value is not changed by this routine. It remains NULL. */ case OP_ToNumeric: { /* no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; assert( MEM_Str==(MEM_Blob>>3) ); pTos->flags |= (pTos->flags&MEM_Blob)>>3; applyAffinity(pTos, SQLITE_AFF_NUMERIC, db->enc); if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){ sqlite3VdbeMemRealify(pTos); }else{ sqlite3VdbeMemRelease(pTos); } assert( (pTos->flags & MEM_Dyn)==0 ); pTos->flags &= (MEM_Int|MEM_Real); break; } /* Opcode: ToText * * * ** ** Force the value on the top of the stack to be text. ** If the value is numeric, convert it to an using the ** equivalent of printf(). Blob values are unchanged and ** are afterwards simply interpreted as text. ** ** A NULL value is not changed by this routine. It remains NULL. */ case OP_ToText: { /* no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; assert( MEM_Str==(MEM_Blob>>3) ); pTos->flags |= (pTos->flags&MEM_Blob)>>3; applyAffinity(pTos, SQLITE_AFF_TEXT, db->enc); assert( pTos->flags & MEM_Str ); pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob); break; } /* Opcode: ToBlob * * * ** ** Force the value on the top of the stack to be a BLOB. ** If the value is numeric, convert it to a string first. ** Strings are simply reinterpreted as blobs with no change ** to the underlying data. ** ** A NULL value is not changed by this routine. It remains NULL. */ case OP_ToBlob: { /* no-push */ assert( pTos>=p->aStack ); if( pTos->flags & MEM_Null ) break; if( (pTos->flags & MEM_Blob)==0 ){ applyAffinity(pTos, SQLITE_AFF_TEXT, db->enc); assert( pTos->flags & MEM_Str ); pTos->flags |= MEM_Blob; } pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Str); break; } #endif /* SQLITE_OMIT_CAST */ /* 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 false then fall thru if either operand |
︙ | ︙ | |||
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 | ** ** If P1 is negative, then the record is stored on the stack rather than in ** a table. For P1==-1, the top of the stack is used. For P1==-2, the ** next on the stack is used. And so forth. The value pushed is always ** just a pointer into the record which is stored further down on the ** stack. The column value is not copied. The number of columns in the ** record is stored on the stack just above the record itself. */ case OP_Column: { u32 payloadSize; /* Number of bytes in the record */ int p1 = pOp->p1; /* P1 value of the opcode */ int p2 = pOp->p2; /* column number to retrieve */ Cursor *pC = 0; /* The VDBE cursor */ char *zRec; /* Pointer to complete record-data */ | > > > > > > > | 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 | ** ** If P1 is negative, then the record is stored on the stack rather than in ** a table. For P1==-1, the top of the stack is used. For P1==-2, the ** next on the stack is used. And so forth. The value pushed is always ** just a pointer into the record which is stored further down on the ** stack. The column value is not copied. The number of columns in the ** record is stored on the stack just above the record itself. ** ** If the column contains fewer than P2 fields, then push a NULL. Or ** if P3 is of type P3_MEM, then push the P3 value. The P3 value will ** be default value for a column that has been added using the ALTER TABLE ** ADD COLUMN command. If P3 is an ordinary string, just push a NULL. ** When P3 is a string it is really just a comment describing the value ** to be pushed, not a default value. */ case OP_Column: { u32 payloadSize; /* Number of bytes in the record */ int p1 = pOp->p1; /* P1 value of the opcode */ int p2 = pOp->p2; /* column number to retrieve */ Cursor *pC = 0; /* The VDBE cursor */ char *zRec; /* Pointer to complete record-data */ |
︙ | ︙ | |||
1936 1937 1938 1939 1940 1941 1942 | pC->cacheValid = 1; } } /* Get the column information. If aOffset[p2] is non-zero, then ** deserialize the value from the record. If aOffset[p2] is zero, ** then there are not enough fields in the record to satisfy the | | > | | 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 | pC->cacheValid = 1; } } /* Get the column information. If aOffset[p2] is non-zero, then ** deserialize the value from the record. If aOffset[p2] is zero, ** then there are not enough fields in the record to satisfy the ** request. In this case, set the value NULL or to P3 if P3 is ** a pointer to a Mem object. */ if( aOffset[p2] ){ assert( rc==SQLITE_OK ); if( zRec ){ zData = &zRec[aOffset[p2]]; }else{ len = sqlite3VdbeSerialTypeLen(aType[p2]); rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, pC->isIndex,&sMem); if( rc!=SQLITE_OK ){ goto op_column_out; } zData = sMem.z; } sqlite3VdbeSerialGet((const unsigned char *)zData, aType[p2], pTos); pTos->enc = db->enc; }else{ if( pOp->p3type==P3_MEM ){ sqlite3VdbeMemShallowCopy(pTos, (Mem *)(pOp->p3), MEM_Static); }else{ pTos->flags = MEM_Null; } } /* If we dynamically allocated space to hold the data (in the |
︙ | ︙ | |||
1999 2000 2001 2002 2003 2004 2005 | ** sqlite3VdbeRecordCompare function will correctly compare two encoded ** records. Refer to source code comments for the details of the record ** format. ** ** The original stack entries are popped from the stack if P1>0 but ** remain on the stack if P1<0. ** | < < < | | | > > > > > > > > > > | 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 | ** sqlite3VdbeRecordCompare function will correctly compare two encoded ** records. Refer to source code comments for the details of the record ** format. ** ** The original stack entries are popped from the stack if P1>0 but ** remain on the stack if P1<0. ** ** If P2 is not zero and one or more of the entries are NULL, then jump ** to the address given by P2. This feature can be used to skip a ** uniqueness test on indices. ** ** P3 may be a string that is P1 characters long. The nth character of the ** string indicates the column affinity that should be used for the nth ** field of the index key (i.e. the first character of P3 corresponds to the ** lowest element on the stack). ** ** The mapping from character to affinity is as follows: ** 'n' = NUMERIC. ** 'i' = INTEGER. ** 't' = TEXT. ** 'o' = NONE. ** ** If P3 is NULL then all index fields have the affinity NONE. ** ** See also OP_MakeIdxRec */ /* Opcode: MakeRecordI P1 P2 P3 ** ** This opcode works just OP_MakeRecord except that it reads an extra ** integer from the stack (thus reading a total of abs(P1+1) entries) ** and appends that extra integer to the end of the record as a varint. ** This results in an index key. */ case OP_MakeIdxRec: case OP_MakeRecord: { /* Assuming the record contains N fields, the record format looks ** like this: ** ** ------------------------------------------------------------------------ ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | ** ------------------------------------------------------------------------ |
︙ | ︙ | |||
2056 2057 2058 2059 2060 2061 2062 | int nField; /* Number of fields in the record */ int jumpIfNull; /* Jump here if non-zero and any entries are NULL. */ int addRowid; /* True to append a rowid column at the end */ char *zAffinity; /* The affinity string for the record */ leaveOnStack = ((pOp->p1<0)?1:0); nField = pOp->p1 * (leaveOnStack?-1:1); | | | | 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 | int nField; /* Number of fields in the record */ int jumpIfNull; /* Jump here if non-zero and any entries are NULL. */ int addRowid; /* True to append a rowid column at the end */ char *zAffinity; /* The affinity string for the record */ leaveOnStack = ((pOp->p1<0)?1:0); nField = pOp->p1 * (leaveOnStack?-1:1); jumpIfNull = pOp->p2; addRowid = pOp->opcode==OP_MakeIdxRec; zAffinity = pOp->p3; pData0 = &pTos[1-nField]; assert( pData0>=p->aStack ); containsNull = 0; /* Loop through the elements that will make up the record to figure |
︙ | ︙ | |||
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 | pTos->flags = MEM_Blob | MEM_Short; }else{ assert( zNewRecord!=(unsigned char *)zTemp ); pTos->z = (char *)zNewRecord; pTos->flags = MEM_Blob | MEM_Dyn; pTos->xDel = 0; } /* If a NULL was encountered and jumpIfNull is non-zero, take the jump. */ if( jumpIfNull && containsNull ){ pc = jumpIfNull - 1; } break; } | > | 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 | pTos->flags = MEM_Blob | MEM_Short; }else{ assert( zNewRecord!=(unsigned char *)zTemp ); pTos->z = (char *)zNewRecord; pTos->flags = MEM_Blob | MEM_Dyn; pTos->xDel = 0; } pTos->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ /* If a NULL was encountered and jumpIfNull is non-zero, take the jump. */ if( jumpIfNull && containsNull ){ pc = jumpIfNull - 1; } break; } |
︙ | ︙ | |||
2428 2429 2430 2431 2432 2433 2434 | wrFlag = pOp->opcode==OP_OpenWrite; if( p2<=0 ){ assert( pTos>=p->aStack ); Integerify(pTos); p2 = pTos->i; assert( (pTos->flags & MEM_Dyn)==0 ); pTos--; | | < < < < | 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 | wrFlag = pOp->opcode==OP_OpenWrite; if( p2<=0 ){ assert( pTos>=p->aStack ); Integerify(pTos); p2 = pTos->i; assert( (pTos->flags & MEM_Dyn)==0 ); pTos--; assert( p2>=2 ); } assert( i>=0 ); pCur = allocateCursor(p, i); if( pCur==0 ) goto no_mem; pCur->nullRow = 1; if( pX==0 ) break; /* We always provide a key comparison function. If the table being |
︙ | ︙ | |||
2497 2498 2499 2500 2501 2502 2503 | default: { goto abort_due_to_error; } } break; } | | | | | | < < < < < < < | | 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 | default: { goto abort_due_to_error; } } break; } /* Opcode: OpenVirtual P1 * P3 ** ** Open a new cursor 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. ** ** 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; assert( i>=0 ); pCx = allocateCursor(p, i); if( pCx==0 ) goto no_mem; pCx->nullRow = 1; rc = sqlite3BtreeFactory(db, 0, 1, TEMP_PAGES, &pCx->pBt); |
︙ | ︙ | |||
3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 | pTos->n = pC->nData; pTos->z = pC->pData; pTos->flags = MEM_Blob|MEM_Ephem; #endif }else{ pTos->flags = MEM_Null; } break; } /* Opcode: Rowid P1 * * ** ** Push onto the stack an integer which is the key of the table entry that ** P1 is currently point to. | > | 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 | pTos->n = pC->nData; pTos->z = pC->pData; pTos->flags = MEM_Blob|MEM_Ephem; #endif }else{ pTos->flags = MEM_Null; } pTos->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ break; } /* Opcode: Rowid P1 * * ** ** Push onto the stack an integer which is the key of the table entry that ** P1 is currently point to. |
︙ | ︙ | |||
3443 3444 3445 3446 3447 3448 3449 | }else{ pC->nullRow = 1; } pC->rowidIsValid = 0; break; } | | < < < < < > < < < < < < < < < < < < < < < < < < < < < < < < < < | 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 | }else{ pC->nullRow = 1; } pC->rowidIsValid = 0; break; } /* Opcode: IdxInsert P1 * * ** ** The top of the stack holds a SQL index key made using the ** MakeIdxKey instruction. This opcode writes that key into the ** index P1. Data for the entry is nil. ** ** This instruction only works for indices. The equivalent instruction ** for tables is OP_Insert. */ case OP_IdxInsert: { /* no-push */ int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); assert( p->apCsr[i]!=0 ); assert( pTos->flags & MEM_Blob ); assert( pOp->p2==0 ); if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){ int nKey = pTos->n; const char *zKey = pTos->z; assert( pC->isTable==0 ); rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0); assert( pC->deferredMoveto==0 ); pC->cacheValid = 0; } Release(pTos); pTos--; |
︙ | ︙ | |||
3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 | rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); db->init.busy = 0; sqlite3SafetyOn(db); sqliteFree(zSql); break; } /* Opcode: DropTable P1 * P3 ** ** Remove the internal (in-memory) data structures that describe ** the table named P3 in database P1. This is called after a table ** is dropped in order to keep the internal representation of the ** schema consistent with what is on disk. */ | > > > > > > > > > > > > > > > | 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 | rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); db->init.busy = 0; sqlite3SafetyOn(db); sqliteFree(zSql); break; } #ifndef SQLITE_OMIT_ANALYZE /* Opcode: LoadAnalysis P1 * * ** ** Read the sqlite_stat1 table for database P1 and load the content ** of that table into the internal index hash table. This will cause ** the analysis to be used when preparing all subsequent queries. */ case OP_LoadAnalysis: { /* no-push */ int iDb = pOp->p1; assert( iDb>=0 && iDb<db->nDb ); sqlite3AnalysisLoad(db, iDb); break; } #endif /* SQLITE_OMIT_ANALYZE */ /* Opcode: DropTable P1 * P3 ** ** Remove the internal (in-memory) data structures that describe ** the table named P3 in database P1. This is called after a table ** is dropped in order to keep the internal representation of the ** schema consistent with what is on disk. */ |
︙ | ︙ | |||
3905 3906 3907 3908 3909 3910 3911 | pTos->enc = SQLITE_UTF8; sqlite3VdbeChangeEncoding(pTos, db->enc); sqliteFree(aRoot); break; } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ | | | | < < < < < < < < < < < | | < < < < < < < < < < < < < < < < < < < < | | | < > > | < | < < | < < < < < < < < < < < < < < < < < < | 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 | pTos->enc = SQLITE_UTF8; sqlite3VdbeChangeEncoding(pTos, db->enc); sqliteFree(aRoot); break; } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ /* Opcode: FifoWrite * * * ** ** Write the integer on the top of the stack ** into the Fifo. */ case OP_FifoWrite: { /* no-push */ assert( pTos>=p->aStack ); Integerify(pTos); sqlite3VdbeFifoPush(&p->sFifo, pTos->i); assert( (pTos->flags & MEM_Dyn)==0 ); pTos--; break; } /* Opcode: FifoRead * P2 * ** ** Attempt to read a single integer from the Fifo ** and push it onto the stack. If the Fifo is empty ** push nothing but instead jump to P2. */ case OP_FifoRead: { i64 v; CHECK_FOR_INTERRUPT; if( sqlite3VdbeFifoPop(&p->sFifo, &v)==SQLITE_DONE ){ pc = pOp->p2 - 1; }else{ pTos++; pTos->i = v; pTos->flags = MEM_Int; } break; } #ifndef SQLITE_OMIT_SUBQUERY /* Opcode: AggContextPush * * * ** |
︙ | ︙ | |||
4035 4036 4037 4038 4039 4040 4041 | p->contextStackDepth = i+1; p->contextStack = (Context *)sqliteRealloc(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; | | | | | | 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 | p->contextStackDepth = i+1; p->contextStack = (Context *)sqliteRealloc(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); break; } /* Opcode: ContextPop * * * ** ** Restore the Vdbe context to the state it was in when contextPush was last ** executed. The context stores the last insert row id, the last statement ** change count, and the current statement change count. */ case OP_ContextPop: { /* no-push */ Context *pContext = &p->contextStack[--p->contextStackTop]; assert( p->contextStackTop>=0 ); db->lastRowid = pContext->lastRowid; p->nChange = pContext->nChange; sqlite3VdbeFifoClear(&p->sFifo); p->sFifo = pContext->sFifo; break; } #endif /* #ifndef SQLITE_OMIT_TRIGGER */ /* Opcode: SortInsert * * * ** ** The TOS is the key and the NOS is the data. Pop both from the stack |
︙ | ︙ | |||
4566 4567 4568 4569 4570 4571 4572 | break; } /* An other opcode is illegal... */ default: { | | < < | 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 | break; } /* An other opcode is illegal... */ default: { assert( 0 ); break; } /***************************************************************************** ** The cases of the switch statement above this line should all be indented ** by 6 spaces. But the left-most 6 spaces have been removed to improve the ** readability. From this point on down, the normal indentation rules are |
︙ | ︙ | |||
4605 4606 4607 4608 4609 4610 4611 | ** the evaluator loop. So we can leave it out when NDEBUG is defined. */ #ifndef NDEBUG /* Sanity checking on the top element of the stack */ if( pTos>=p->aStack ){ sqlite3VdbeMemSanity(pTos, db->enc); } | | < < < | 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 | ** the evaluator loop. So we can leave it out when NDEBUG is defined. */ #ifndef NDEBUG /* Sanity checking on the top element of the stack */ if( pTos>=p->aStack ){ sqlite3VdbeMemSanity(pTos, db->enc); } assert( pc>=-1 && pc<p->nOp ); #ifdef SQLITE_DEBUG /* Code for tracing the vdbe stack. */ if( p->trace && pTos>=p->aStack ){ int i; fprintf(p->trace, "Stack:"); for(i=0; i>-5 && &pTos[i]>=p->aStack; i--){ if( pTos[i].flags & MEM_Null ){ |
︙ | ︙ | |||
4689 4690 4691 4692 4693 4694 4695 | }else{ rc = SQLITE_INTERRUPT; } p->rc = rc; sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0); goto vdbe_halt; } | | < | 4717 4718 4719 4720 4721 4722 4723 4724 | }else{ rc = SQLITE_INTERRUPT; } p->rc = rc; sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(rc), (char*)0); goto vdbe_halt; } } |
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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ #include <stdio.h> /* ** A single VDBE is an opaque structure named "Vdbe". Only routines |
︙ | ︙ | |||
101 102 103 104 105 106 107 | 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); | < < | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | 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*); void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int); int sqlite3VdbeFinalize(Vdbe*); void sqlite3VdbeResolveLabel(Vdbe*, int); int sqlite3VdbeCurrentAddr(Vdbe*); |
︙ | ︙ |
Changes to SQLite.Interop/src/vdbeInt.h.
︙ | ︙ | |||
25 26 27 28 29 30 31 | /* ** The makefile scans the vdbe.c source file and creates the following ** array of string constants which are the names of all VDBE opcodes. This ** array is defined in a separate source code file named opcode.c which is ** automatically generated by the makefile. */ | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* ** The makefile scans the vdbe.c source file and creates the following ** array of string constants which are the names of all VDBE opcodes. This ** array is defined in a separate source code file named opcode.c which is ** automatically generated by the makefile. */ extern const char *sqlite3OpcodeNames[]; /* ** SQL is translated into a sequence of instructions to be ** executed by a virtual machine. Each instruction is an instance ** of the following structure. */ typedef struct VdbeOp Op; |
︙ | ︙ | |||
256 257 258 259 260 261 262 | typedef struct Set Set; struct Set { Hash hash; /* A set is just a hash table */ HashElem *prev; /* Previously accessed hash elemen */ }; /* | | | < | | | | | | | > > > > > > > > > > > > > | | 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 | typedef struct Set Set; struct Set { Hash hash; /* A set is just a hash table */ HashElem *prev; /* Previously accessed hash elemen */ }; /* ** A FifoPage structure holds a single page of valves. Pages are arranged ** in a list. */ typedef struct FifoPage FifoPage; struct FifoPage { u16 nSlot; /* Number of entries aSlot[] */ u16 iWrite; /* Push the next value into this entry in aSlot[] */ i16 iRead; /* Read the next value from this entry in aSlot[] */ FifoPage *pNext; /* Next page in the fifo */ i64 aSlot[1]; /* One or more slots for rowid values */ }; /* ** The Fifo structure is typedef-ed in vdbeInt.h. But the implementation ** of that structure is private to this file. ** ** The Fifo structure describes the entire fifo. */ typedef struct Fifo Fifo; struct Fifo { int nEntry; /* Total number of entries */ FifoPage *pFirst; /* First page on the list */ FifoPage *pLast; /* Last page on the list */ }; /* ** A Context stores the last insert rowid, the last statement change count, ** and the current statement change count (i.e. changes since last statement). ** The current keylist is also stored in the context. ** Elements of Context structure type make up the ContextStack, which is ** updated by the ContextPush and ContextPop opcodes (used by triggers). ** The context is pushed before executing a trigger a popped when the ** trigger finishes. */ typedef struct Context Context; struct Context { int lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ int nChange; /* Statement changes (Vdbe.nChanges) */ Fifo sFifo; /* Records that will participate in a DELETE or UPDATE */ }; /* ** An instance of the virtual machine. This structure contains the complete ** state of the virtual machine. ** ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile() |
︙ | ︙ | |||
321 322 323 324 325 326 327 | int magic; /* Magic number for sanity checking */ int nMem; /* Number of memory locations currently allocated */ Mem *aMem; /* The memory locations */ int nAgg; /* Number of elements in apAgg */ Agg *apAgg; /* Array of aggregate contexts */ Agg *pAgg; /* Current aggregate context */ int nCallback; /* Number of callbacks invoked so far */ | | | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | int magic; /* Magic number for sanity checking */ int nMem; /* Number of memory locations currently allocated */ Mem *aMem; /* The memory locations */ int nAgg; /* Number of elements in apAgg */ Agg *apAgg; /* Array of aggregate contexts */ Agg *pAgg; /* Current aggregate context */ 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 */ unsigned uniqueCnt; /* Used by OP_MakeRecord when P2!=0 */ int errorAction; /* Recovery action to do in case of an error */ |
︙ | ︙ | |||
358 359 360 361 362 363 364 | /* ** Function prototypes */ void sqlite3VdbeFreeCursor(Cursor*); void sqlite3VdbeSorterReset(Vdbe*); int sqlite3VdbeAggReset(sqlite3*, Agg *, KeyInfo *); | < | 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | /* ** Function prototypes */ void sqlite3VdbeFreeCursor(Cursor*); void sqlite3VdbeSorterReset(Vdbe*); int sqlite3VdbeAggReset(sqlite3*, Agg *, KeyInfo *); 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*); |
︙ | ︙ | |||
407 408 409 410 411 412 413 | #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); | > > > > | 418 419 420 421 422 423 424 425 426 427 428 | #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.
︙ | ︙ | |||
83 84 85 86 87 88 89 | */ void sqlite3_result_blob( sqlite3_context *pCtx, const void *z, int n, void (*xDel)(void *) ){ | | | | | 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 | */ void sqlite3_result_blob( sqlite3_context *pCtx, const void *z, int n, void (*xDel)(void *) ){ assert( n>=0 ); sqlite3VdbeMemSetStr(&pCtx->s, (const char *)z, n, 0, xDel); } void sqlite3_result_double(sqlite3_context *pCtx, double rVal){ sqlite3VdbeMemSetDouble(&pCtx->s, rVal); } void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ pCtx->isError = 1; sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); } void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ pCtx->isError = 1; sqlite3VdbeMemSetStr(&pCtx->s, (const char *)z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); } void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal); } void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){ sqlite3VdbeMemSetInt64(&pCtx->s, iVal); } |
︙ | ︙ | |||
121 122 123 124 125 126 127 | #ifndef SQLITE_OMIT_UTF16 void sqlite3_result_text16( sqlite3_context *pCtx, const void *z, int n, void (*xDel)(void *) ){ | | | | | 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 | #ifndef SQLITE_OMIT_UTF16 void sqlite3_result_text16( sqlite3_context *pCtx, const void *z, int n, void (*xDel)(void *) ){ sqlite3VdbeMemSetStr(&pCtx->s, (const char *)z, n, SQLITE_UTF16NATIVE, xDel); } void sqlite3_result_text16be( sqlite3_context *pCtx, const void *z, int n, void (*xDel)(void *) ){ sqlite3VdbeMemSetStr(&pCtx->s, (const char *)z, n, SQLITE_UTF16BE, xDel); } void sqlite3_result_text16le( sqlite3_context *pCtx, const void *z, int n, void (*xDel)(void *) ){ sqlite3VdbeMemSetStr(&pCtx->s, (const char *)z, n, SQLITE_UTF16LE, xDel); } #endif /* SQLITE_OMIT_UTF16 */ void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ sqlite3VdbeMemCopy(&pCtx->s, pValue); } |
︙ | ︙ | |||
212 213 214 215 216 217 218 | rc = sqlite3VdbeExec(p); } if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } | | | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | 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. */ |
︙ | ︙ | |||
368 369 370 371 372 373 374 375 376 377 378 379 380 381 | } sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){ return sqlite3_value_int64( columnMem(pStmt,i) ); } const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){ return sqlite3_value_text( columnMem(pStmt,i) ); } #ifndef SQLITE_OMIT_UTF16 const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){ return sqlite3_value_text16( columnMem(pStmt,i) ); } #endif /* SQLITE_OMIT_UTF16 */ int sqlite3_column_type(sqlite3_stmt *pStmt, int i){ return sqlite3_value_type( columnMem(pStmt,i) ); | > > > > > | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | } sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){ return sqlite3_value_int64( columnMem(pStmt,i) ); } const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){ return sqlite3_value_text( columnMem(pStmt,i) ); } #if 0 sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){ return columnMem(pStmt, i); } #endif #ifndef SQLITE_OMIT_UTF16 const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){ return sqlite3_value_text16( columnMem(pStmt,i) ); } #endif /* SQLITE_OMIT_UTF16 */ int sqlite3_column_type(sqlite3_stmt *pStmt, int i){ return sqlite3_value_type( columnMem(pStmt,i) ); |
︙ | ︙ | |||
533 534 535 536 537 538 539 | int rc; rc = vdbeUnbind(p, i); if( rc || zData==0 ){ return rc; } pVar = &p->aVar[i-1]; | | | 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | int rc; rc = vdbeUnbind(p, i); if( rc || zData==0 ){ return rc; } pVar = &p->aVar[i-1]; rc = sqlite3VdbeMemSetStr(pVar, (const char *)zData, nData, encoding, xDel); if( rc ){ return rc; } if( rc==SQLITE_OK && encoding!=0 ){ rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc); } return rc; |
︙ | ︙ | |||
698 699 700 701 702 703 704 | ** in the argument belongs. This is the same database handle that was ** the first argument to the sqlite3_prepare() that was used to create ** the statement in the first place. */ sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){ return pStmt ? ((Vdbe*)pStmt)->db : 0; } | | < | 703 704 705 706 707 708 709 710 | ** in the argument belongs. This is the same database handle that was ** the first argument to the sqlite3_prepare() that was used to create ** the statement in the first place. */ sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){ return pStmt ? ((Vdbe*)pStmt)->db : 0; } } |
Changes to SQLite.Interop/src/vdbeaux.c.
︙ | ︙ | |||
17 18 19 20 21 22 23 | ** to version 2.8.7, all this code was combined into the vdbe.c source file. ** But that file was getting too big so this subroutines were split out. */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ** to version 2.8.7, all this code was combined into the vdbe.c source file. ** But that file was getting too big so this subroutines were split out. */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* ** When debugging the code generator in a symbolic debugger, one can ** set the sqlite3_vdbe_addop_trace to 1 and all opcodes will be printed ** as they are added to the instruction stream. */ #ifdef SQLITE_DEBUG int sqlite3_vdbe_addop_trace = 0; #endif /* ** Create a new virtual database engine. */ |
︙ | ︙ | |||
108 109 110 111 112 113 114 115 116 117 118 119 120 121 | } pOp = &p->aOp[i]; pOp->opcode = op; pOp->p1 = p1; pOp->p2 = p2; pOp->p3 = 0; pOp->p3type = P3_NOTUSED; #ifdef SQLITE_DEBUG if( sqlite3_vdbe_addop_trace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]); #endif return i; } /* | > | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | } pOp = &p->aOp[i]; pOp->opcode = op; pOp->p1 = p1; pOp->p2 = p2; pOp->p3 = 0; pOp->p3type = P3_NOTUSED; p->expired = 0; #ifdef SQLITE_DEBUG if( sqlite3_vdbe_addop_trace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]); #endif return i; } /* |
︙ | ︙ | |||
441 442 443 444 445 446 447 | assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 ); va_start(ap, zFormat); sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC); va_end(ap); } #endif | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 ); va_start(ap, zFormat); sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC); va_end(ap); } #endif /* ** Return the opcode for a given address. */ VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ assert( p->magic==VDBE_MAGIC_INIT ); assert( addr>=0 && addr<p->nOp ); return &p->aOp[addr]; |
︙ | ︙ | |||
951 952 953 954 955 956 957 | } pAgg->pCurrent = 0; pAgg->nMem = 0; pAgg->searching = 0; return SQLITE_OK; } | < < < < < < < < < < < < | 911 912 913 914 915 916 917 918 919 920 921 922 923 924 | } pAgg->pCurrent = 0; pAgg->nMem = 0; pAgg->searching = 0; return SQLITE_OK; } /* ** Close a cursor and release all the resources that cursor happens ** to hold. */ void sqlite3VdbeFreeCursor(Cursor *pCx){ if( pCx==0 ){ return; |
︙ | ︙ | |||
1009 1010 1011 1012 1013 1014 1015 | int i; if( p->aStack ){ releaseMemArray(p->aStack, 1 + (p->pTos - p->aStack)); p->pTos = &p->aStack[-1]; } closeAllCursors(p); releaseMemArray(p->aMem, p->nMem); | < | < < | | 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | int i; if( p->aStack ){ releaseMemArray(p->aStack, 1 + (p->pTos - p->aStack)); p->pTos = &p->aStack[-1]; } closeAllCursors(p); releaseMemArray(p->aMem, p->nMem); sqlite3VdbeFifoClear(&p->sFifo); if( p->contextStack ){ for(i=0; i<p->contextStackTop; i++){ sqlite3VdbeFifoClear(&p->contextStack[i].sFifo); } sqliteFree(p->contextStack); } sqlite3VdbeSorterReset(p); for(i=0; i<p->nAgg; i++){ sqlite3VdbeAggReset(0, &p->apAgg[i], 0); } |
︙ | ︙ | |||
1762 1763 1764 1765 1766 1767 1768 | u64 x = (((signed char)buf[0])<<8) | buf[1]; u32 y = (buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5]; x = (x<<32) | y; pMem->i = *(i64*)&x; pMem->flags = MEM_Int; return 6; } | | | 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 | u64 x = (((signed char)buf[0])<<8) | buf[1]; u32 y = (buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5]; 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 = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3]; u32 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; |
︙ | ︙ | |||
1994 1995 1996 1997 1998 1999 2000 | /* ** Return the database associated with the Vdbe. */ sqlite3 *sqlite3VdbeDb(Vdbe *v){ return v->db; } | | < | 1939 1940 1941 1942 1943 1944 1945 1946 | /* ** Return the database associated with the Vdbe. */ sqlite3 *sqlite3VdbeDb(Vdbe *v){ return v->db; } } |
Added SQLite.Interop/src/vdbefifo.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #pragma unmanaged extern "C" { /* ** 2005 June 16 ** ** 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 implements a FIFO queue of rowids used for processing ** UPDATE and DELETE statements. */ #include "sqliteInt.h" #include "vdbeInt.h" /* ** Allocate a new FifoPage and return a pointer to it. Return NULL if ** we run out of memory. Leave space on the page for nEntry entries. */ static FifoPage *allocatePage(int nEntry){ FifoPage *pPage; pPage = (FifoPage *)sqliteMallocRaw( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) ); if( pPage ){ pPage->nSlot = nEntry; pPage->iWrite = 0; pPage->iRead = 0; pPage->pNext = 0; } return pPage; } /* ** Initialize a Fifo structure. */ void sqlite3VdbeFifoInit(Fifo *pFifo){ memset(pFifo, 0, sizeof(*pFifo)); } /* ** Push a single 64-bit integer value into the Fifo. Return SQLITE_OK ** normally. SQLITE_NOMEM is returned if we are unable to allocate ** memory. */ int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){ FifoPage *pPage; pPage = pFifo->pLast; if( pPage==0 ){ pPage = pFifo->pLast = pFifo->pFirst = allocatePage(20); if( pPage==0 ){ return SQLITE_NOMEM; } }else if( pPage->iWrite>=pPage->nSlot ){ pPage->pNext = allocatePage(pFifo->nEntry); if( pPage->pNext==0 ){ return SQLITE_NOMEM; } pPage = pFifo->pLast = pPage->pNext; } pPage->aSlot[pPage->iWrite++] = val; pFifo->nEntry++; return SQLITE_OK; } /* ** Extract a single 64-bit integer value from the Fifo. The integer ** extracted is the one least recently inserted. If the Fifo is empty ** return SQLITE_DONE. */ int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){ FifoPage *pPage; if( pFifo->nEntry==0 ){ return SQLITE_DONE; } assert( pFifo->nEntry>0 ); pPage = pFifo->pFirst; assert( pPage!=0 ); assert( pPage->iWrite>pPage->iRead ); assert( pPage->iRead<pPage->nSlot ); *pVal = pPage->aSlot[pPage->iRead++]; pFifo->nEntry--; if( pPage->iRead>=pPage->iWrite ){ pFifo->pFirst = pPage->pNext; sqliteFree(pPage); if( pFifo->nEntry==0 ){ assert( pFifo->pLast==pPage ); pFifo->pLast = 0; }else{ assert( pFifo->pFirst!=0 ); } }else{ assert( pFifo->nEntry>0 ); } return SQLITE_OK; } /* ** Delete all information from a Fifo object. Free all memory held ** by the Fifo. */ void sqlite3VdbeFifoClear(Fifo *pFifo){ FifoPage *pPage, *pNextPage; for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){ pNextPage = pPage->pNext; sqliteFree(pPage); } sqlite3VdbeFifoInit(pFifo); } } |
Changes to SQLite.Interop/src/vdbemem.c.
︙ | ︙ | |||
173 174 175 176 177 178 179 | /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8 ** string representation of the value. Then, if the required encoding ** is UTF-16le or UTF-16be do a translation. ** ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16. */ if( fg & MEM_Real ){ | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8 ** string representation of the value. Then, if the required encoding ** is UTF-16le or UTF-16be do a translation. ** ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16. */ if( fg & MEM_Real ){ sqlite3_snprintf(NBFS, (char *)z, "%!.15g", pMem->r); }else{ assert( fg & MEM_Int ); sqlite3_snprintf(NBFS, (char *)z, "%lld", pMem->i); } pMem->n = strlen((const char *)z); pMem->z = (char *)z; pMem->enc = SQLITE_UTF8; pMem->flags |= MEM_Str | MEM_Short | MEM_Term; sqlite3VdbeChangeEncoding(pMem, enc); return rc; } |
︙ | ︙ | |||
255 256 257 258 259 260 261 262 263 264 265 266 | */ double sqlite3VdbeRealValue(Mem *pMem){ if( pMem->flags & MEM_Real ){ return pMem->r; }else if( pMem->flags & MEM_Int ){ return (double)pMem->i; }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8) || sqlite3VdbeMemNulTerminate(pMem) ){ return SQLITE_NOMEM; } assert( pMem->z ); | > | > | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | */ double sqlite3VdbeRealValue(Mem *pMem){ if( pMem->flags & MEM_Real ){ return pMem->r; }else if( pMem->flags & MEM_Int ){ return (double)pMem->i; }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ double val = 0.0; if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8) || sqlite3VdbeMemNulTerminate(pMem) ){ return SQLITE_NOMEM; } assert( pMem->z ); sqlite3AtoF(pMem->z, &val); return val; }else{ return 0.0; } } /* ** Convert pMem so that it is of type MEM_Real. Invalidate any |
︙ | ︙ | |||
405 406 407 408 409 410 411 412 413 414 415 416 417 418 | pMem->n = n; assert( enc==0 || enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); switch( enc ){ case 0: pMem->flags |= MEM_Blob; break; case SQLITE_UTF8: pMem->flags |= MEM_Str; if( n<0 ){ pMem->n = strlen(z); pMem->flags |= MEM_Term; | > | 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | pMem->n = n; assert( enc==0 || enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); switch( enc ){ case 0: pMem->flags |= MEM_Blob; pMem->enc = SQLITE_UTF8; break; case SQLITE_UTF8: pMem->flags |= MEM_Str; if( n<0 ){ pMem->n = strlen(z); pMem->flags |= MEM_Term; |
︙ | ︙ | |||
665 666 667 668 669 670 671 | /* Cannot define a string subtype for non-string objects */ assert( (pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 ); assert( pMem->xDel==0 ); } /* MEM_Null excludes all other types */ assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0 || (pMem->flags&MEM_Null)==0 ); | > | | < | 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | /* Cannot define a string subtype for non-string objects */ assert( (pMem->flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 ); assert( pMem->xDel==0 ); } /* MEM_Null excludes all other types */ assert( (pMem->flags&(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0 || (pMem->flags&MEM_Null)==0 ); /* If the MEM is both real and integer, the values are equal */ assert( (pMem->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) || pMem->r==pMem->i ); } #endif /* This function is only available internally, it is not part of the ** external API. It works in a similar way to sqlite3_value_text(), ** except the data returned is in the encoding specified by the second ** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or |
︙ | ︙ | |||
731 732 733 734 735 736 737 | if( !pExpr ){ *ppVal = 0; return SQLITE_OK; } op = pExpr->op; if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){ | | | | | 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | if( !pExpr ){ *ppVal = 0; return SQLITE_OK; } op = pExpr->op; if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){ zVal = sqliteStrNDup((const char *)pExpr->token.z, pExpr->token.n); pVal = sqlite3ValueNew(); if( !zVal || !pVal ) goto no_mem; sqlite3Dequote(zVal); sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX); if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){ sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc); }else{ sqlite3ValueApplyAffinity(pVal, affinity, enc); } }else if( op==TK_UMINUS ) { if( SQLITE_OK==sqlite3ValueFromExpr(pExpr->pLeft, enc, affinity, &pVal) ){ pVal->i = -1 * pVal->i; pVal->r = -1.0 * pVal->r; } } #ifndef SQLITE_OMIT_BLOB_LITERAL else if( op==TK_BLOB ){ int nVal; pVal = sqlite3ValueNew(); zVal = sqliteStrNDup((const char *)pExpr->token.z+1, pExpr->token.n-1); if( !zVal || !pVal ) goto no_mem; sqlite3Dequote(zVal); nVal = strlen(zVal)/2; sqlite3VdbeMemSetStr(pVal, (const char *)sqlite3HexToBlob(zVal), nVal, 0, sqlite3FreeX); sqliteFree(zVal); } #endif *ppVal = pVal; return SQLITE_OK; |
︙ | ︙ | |||
780 781 782 783 784 785 786 | void sqlite3ValueSetStr( sqlite3_value *v, int n, const void *z, u8 enc, void (*xDel)(void*) ){ | | | 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | void sqlite3ValueSetStr( sqlite3_value *v, int n, const void *z, u8 enc, void (*xDel)(void*) ){ if( v ) sqlite3VdbeMemSetStr((Mem *)v, (const char *)z, n, enc, xDel); } /* ** Free an sqlite3_value object */ void sqlite3ValueFree(sqlite3_value *v){ if( !v ) return; |
︙ | ︙ | |||
803 804 805 806 807 808 809 | int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){ Mem *p = (Mem*)pVal; if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){ return p->n; } return 0; } | | < | 806 807 808 809 810 811 812 813 | int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){ Mem *p = (Mem*)pVal; if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){ return p->n; } return 0; } } |
Changes to SQLite.Interop/src/where.c.
︙ | ︙ | |||
15 16 17 18 19 20 21 | ** 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". ** | | > > > > > > > > > > > > > > > > > > > > > > > > > | < < < | > > > > > > > | < > > > | < < < < < < < < < < < < < < < < | | | | | > | > | < < > > | > > > > > > > > > > > > > > > > > > > > > | | | 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 | ** 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.7 2005/08/22 18:22:12 rmsimpson Exp $ */ #include "sqliteInt.h" /* ** The number of bits in a Bitmask. "BMS" means "BitMask Size". */ #define BMS (sizeof(Bitmask)*8) /* ** Determine the number of elements in an array. */ #define ARRAYSIZE(X) (sizeof(X)/sizeof(X[0])) /* ** Trace output macros */ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) int sqlite3_where_trace = 0; # define TRACE(X) if(sqlite3_where_trace) sqlite3DebugPrintf X #else # define TRACE(X) #endif /* Forward reference */ typedef struct WhereClause WhereClause; /* ** The query generator uses an array of instances of this structure to ** help it analyze the subexpressions of the WHERE clause. Each WHERE ** clause subexpression is separated from the others by an AND operator. ** ** All WhereTerms are collected into a single WhereClause structure. ** The following identity holds: ** ** WhereTerm.pWC->a[WhereTerm.idx] == WhereTerm ** ** When a term is of the form: ** ** X <op> <expr> ** ** where X is a column name and <op> is one of certain operators, ** then WhereTerm.leftCursor and WhereTerm.leftColumn record the ** cursor number and column number for X. WhereTerm.operator records ** the <op> using a bitmask encoding defined by WO_xxx below. The ** use of a bitmask encoding for the operator allows us to search ** quickly for terms that match any of several different operators. ** ** prereqRight and prereqAll record sets of cursor numbers, ** but they do so indirectly. A single ExprMaskSet structure translates ** cursor number into bits and the translated bit is stored in the prereq ** fields. The translation is used in order to maximize the number of ** bits that will fit in a Bitmask. The VDBE cursor numbers might be ** spread out over the non-negative integers. For example, the cursor ** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The ExprMaskSet ** translates these sparse cursor numbers into consecutive integers ** beginning with 0 in order to make the best possible use of the available ** bits in the Bitmask. So, in the example above, the cursor numbers ** would be mapped into integers 0 through 7. */ typedef struct WhereTerm WhereTerm; struct WhereTerm { Expr *pExpr; /* Pointer to the subexpression */ u16 idx; /* Index of this term in pWC->a[] */ i16 iParent; /* Disable pWC->a[iParent] when this term disabled */ i16 leftCursor; /* Cursor number of X in "X <op> <expr>" */ i16 leftColumn; /* Column number of X in "X <op> <expr>" */ u16 _operator; /* A WO_xx value describing <op> */ u8 flags; /* Bit flags. See below */ u8 nChild; /* Number of children that must disable us */ WhereClause *pWC; /* The clause this term is part of */ Bitmask prereqRight; /* Bitmask of tables used by pRight */ Bitmask prereqAll; /* Bitmask of tables referenced by p */ }; /* ** Allowed values of WhereTerm.flags */ #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(pExpr) */ #define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */ #define TERM_CODED 0x04 /* This term is already coded */ #define TERM_COPIED 0x08 /* Has a child */ #define TERM_OR_OK 0x10 /* Used during OR-clause processing */ /* ** An instance of the following structure holds all information about a ** WHERE clause. Mostly this is a container for one or more WhereTerms. */ struct WhereClause { Parse *pParse; /* The parser context */ int nTerm; /* Number of terms */ int nSlot; /* Number of entries in a[] */ WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */ WhereTerm aStatic[10]; /* Initial static space for a[] */ }; /* ** An instance of the following structure keeps track of a mapping ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm. ** ** The VDBE cursor numbers are small integers contained in ** SrcList::SrcList_item.iCursor and Expr.iTable fields. For any given WHERE ** clause, the cursor numbers might not begin with 0 and they might ** contain gaps in the numbering sequence. But we want to make maximum ** use of the bits in our bitmasks. This structure provides a mapping ** from the sparse cursor numbers into consecutive integers beginning ** with 0. ** ** If ExprMaskSet.ix[A]==B it means that The A-th bit of a Bitmask |
︙ | ︙ | |||
106 107 108 109 110 111 112 113 | */ typedef struct ExprMaskSet ExprMaskSet; struct ExprMaskSet { int n; /* Number of assigned cursor values */ int ix[sizeof(Bitmask)*8]; /* Cursor assigned to each bit */ }; /* | > > > > > > > > > > > | > > > > > > > > > > > > > | > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | | | | | < | < | < < < < | | < | | < | 144 145 146 147 148 149 150 151 152 153 154 155 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 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 | */ typedef struct ExprMaskSet ExprMaskSet; struct ExprMaskSet { int n; /* Number of assigned cursor values */ int ix[sizeof(Bitmask)*8]; /* Cursor assigned to each bit */ }; /* ** Bitmasks for the operators that indices are able to exploit. An ** OR-ed combination of these values can be used when searching for ** terms in the where clause. */ #define WO_IN 1 #define WO_EQ 2 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ)) #define WO_LE (WO_EQ<<(TK_LE-TK_EQ)) #define WO_GT (WO_EQ<<(TK_GT-TK_EQ)) #define WO_GE (WO_EQ<<(TK_GE-TK_EQ)) /* ** Value for flags returned by bestIndex() */ #define WHERE_ROWID_EQ 0x0001 /* rowid=EXPR or rowid IN (...) */ #define WHERE_ROWID_RANGE 0x0002 /* rowid<EXPR and/or rowid>EXPR */ #define WHERE_COLUMN_EQ 0x0010 /* x=EXPR or x IN (...) */ #define WHERE_COLUMN_RANGE 0x0020 /* x<EXPR and/or x>EXPR */ #define WHERE_COLUMN_IN 0x0040 /* x IN (...) */ #define WHERE_TOP_LIMIT 0x0100 /* x<EXPR or x<=EXPR constraint */ #define WHERE_BTM_LIMIT 0x0200 /* x>EXPR or x>=EXPR constraint */ #define WHERE_IDX_ONLY 0x0800 /* Use index only - omit table */ #define WHERE_ORDERBY 0x1000 /* Output will appear in correct order */ #define WHERE_REVERSE 0x2000 /* Scan in reverse order */ #define WHERE_UNIQUE 0x4000 /* Selects no more than one row */ /* ** Initialize a preallocated WhereClause structure. */ static void whereClauseInit(WhereClause *pWC, Parse *pParse){ pWC->pParse = pParse; pWC->nTerm = 0; pWC->nSlot = ARRAYSIZE(pWC->aStatic); pWC->a = pWC->aStatic; } /* ** Deallocate a WhereClause structure. The WhereClause structure ** itself is not freed. This routine is the inverse of whereClauseInit(). */ static void whereClauseClear(WhereClause *pWC){ int i; WhereTerm *a; for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){ if( a->flags & TERM_DYNAMIC ){ sqlite3ExprDelete(a->pExpr); } } if( pWC->a!=pWC->aStatic ){ sqliteFree(pWC->a); } } /* ** Add a new entries to the WhereClause structure. Increase the allocated ** space as necessary. */ static WhereTerm *whereClauseInsert(WhereClause *pWC, Expr *p, int flags){ WhereTerm *pTerm; if( pWC->nTerm>=pWC->nSlot ){ WhereTerm *pOld = pWC->a; pWC->a = (WhereTerm *)sqliteMalloc( sizeof(pWC->a[0])*pWC->nSlot*2 ); if( pWC->a==0 ) return 0; memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); if( pOld!=pWC->aStatic ){ sqliteFree(pOld); } pWC->nSlot *= 2; } pTerm = &pWC->a[pWC->nTerm]; pTerm->idx = pWC->nTerm; pWC->nTerm++; pTerm->pExpr = p; pTerm->flags = flags; pTerm->pWC = pWC; pTerm->iParent = -1; return pTerm; } /* ** This routine identifies subexpressions in the WHERE clause where ** each subexpression is separate 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] ** ** The original WHERE clause in pExpr is unaltered. All this routine ** does is make slot[] entries point to substructure within pExpr. ** ** In the previous sentence and in the diagram, "slot[]" refers to ** the WhereClause.a[] array. This array grows as needed to contain ** all terms of the WHERE clause. */ static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){ if( pExpr==0 ) return; if( pExpr->op!=op ){ whereClauseInsert(pWC, pExpr, 0); }else{ whereSplit(pWC, pExpr->pLeft, op); whereSplit(pWC, pExpr->pRight, op); } } /* ** Initialize an expression mask set */ #define initMaskSet(P) memset(P, 0, sizeof(*P)) |
︙ | ︙ | |||
166 167 168 169 170 171 172 173 174 | } } return 0; } /* ** Create a new mask for cursor iCursor. */ static void createMask(ExprMaskSet *pMaskSet, int iCursor){ | > > > > > | | | < < < < < < | > > | 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 | } } return 0; } /* ** 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() routien. 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; } /* ** This routine walks (recursively) an expression tree and generates ** a bitmask indicating which tables are used in that expression ** tree. ** ** In order for this routine to work, the calling function must have ** previously invoked sqlite3ExprResolveNames() on the expression. See ** 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 exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){ Bitmask mask = 0; if( p==0 ) return 0; if( p->op==TK_COLUMN ){ mask = getMask(pMaskSet, p->iTable); |
︙ | ︙ | |||
228 229 230 231 232 233 234 | /* ** 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". */ static int allowedOp(int op){ | > > > | > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > | > | > > > > > | > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > | > > | > > > > > | > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > > > | | > > > | > > | | | > > > > > > | > > > > | > > > > > > > | | | | | > | | | | > > > > > > > > > > > > > > > > | > | > | | > > | > | > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > < < < < < < < < | < < > | > | > > > > > | | > > > > > > > > | < | | < > > > > > > > | > | > > > > | > > > > > | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < | 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 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 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | /* ** 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". */ static int allowedOp(int op){ assert( TK_GT>TK_EQ && TK_GT<TK_GE ); assert( TK_LT>TK_EQ && TK_LT<TK_GE ); assert( TK_LE>TK_EQ && TK_LE<TK_GE ); assert( TK_GE==TK_EQ+4 ); return op==TK_IN || (op>=TK_EQ && op<=TK_GE); } /* ** Swap two objects of type T. */ #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} /* ** Commute a comparision operator. Expressions of the form "X op Y" ** are converted into "Y op X". */ static void exprCommute(Expr *pExpr){ assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); SWAP(Expr*,pExpr->pRight,pExpr->pLeft); if( pExpr->op>=TK_GT ){ assert( TK_LT==TK_GT+2 ); assert( TK_GE==TK_LE+2 ); assert( TK_GT>TK_EQ ); assert( TK_GT<TK_LE ); assert( pExpr->op>=TK_GT && pExpr->op<=TK_GE ); pExpr->op = ((pExpr->op-TK_GT)^2)+TK_GT; } } /* ** Translate from TK_xx operator to WO_xx bitmask. */ static int operatorMask(int op){ int c; assert( allowedOp(op) ); if( op==TK_IN ){ c = WO_IN; }else{ c = WO_EQ<<(op-TK_EQ); } assert( op!=TK_IN || c==WO_IN ); assert( op!=TK_EQ || c==WO_EQ ); assert( op!=TK_LT || c==WO_LT ); assert( op!=TK_LE || c==WO_LE ); assert( op!=TK_GT || c==WO_GT ); assert( op!=TK_GE || c==WO_GE ); return c; } /* ** Search for a term in the WHERE clause that is of the form "X <op> <expr>" ** where X is a reference to the iColumn of table iCur and <op> is one of ** the WO_xx operator codes specified by the op parameter. ** Return a pointer to the term. Return 0 if not found. */ static WhereTerm *findTerm( WhereClause *pWC, /* The WHERE clause to be searched */ int iCur, /* Cursor number of LHS */ int iColumn, /* Column number of LHS */ Bitmask notReady, /* RHS must not overlap with this mask */ u16 op, /* Mask of WO_xx values describing operator */ Index *pIdx /* Must be compatible with this index, if not NULL */ ){ WhereTerm *pTerm; int k; for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){ if( pTerm->leftCursor==iCur && (pTerm->prereqRight & notReady)==0 && pTerm->leftColumn==iColumn && (pTerm->_operator & op)!=0 ){ if( iCur>=0 && pIdx ){ Expr *pX = pTerm->pExpr; CollSeq *pColl; char idxaff; int k; Parse *pParse = pWC->pParse; idxaff = pIdx->pTable->aCol[iColumn].affinity; if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue; pColl = sqlite3ExprCollSeq(pParse, pX->pLeft); if( !pColl ){ if( pX->pRight ){ pColl = sqlite3ExprCollSeq(pParse, pX->pRight); } if( !pColl ){ pColl = pParse->db->pDfltColl; } } for(k=0; k<pIdx->nColumn && pIdx->aiColumn[k]!=iColumn; k++){} assert( k<pIdx->nColumn ); if( pColl!=pIdx->keyInfo.aColl[k] ) continue; } return pTerm; } } return 0; } /* Forward reference */ static void exprAnalyze(SrcList*, ExprMaskSet*, WhereTerm*); /* ** Call exprAnalyze on all terms in a WHERE clause. ** ** */ static void exprAnalyzeAll( SrcList *pTabList, /* the FROM clause */ ExprMaskSet *pMaskSet, /* table masks */ WhereClause *pWC /* the WHERE clause to be analyzed */ ){ WhereTerm *pTerm; int i; for(i=pWC->nTerm-1, pTerm=pWC->a; i>=0; i--, pTerm++){ exprAnalyze(pTabList, pMaskSet, pTerm); } } #ifndef SQLITE_OMIT_LIKE_OPTIMIZATION /* ** Check to see if the given expression is a LIKE or GLOB operator that ** can be optimized using inequality constraints. Return TRUE if it is ** so and false if not. ** ** In order for the operator to be optimizible, the RHS must be a string ** literal that does not begin with a wildcard. */ static int isLikeOrGlob( sqlite3 *db, /* The database */ Expr *pExpr, /* Test this expression */ 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]; if( !sqlite3IsLikeFunction(db, pExpr, 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; } sqlite3DequoteExpr(pRight); z = (const char *)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; } *pisComplete = z[cnt]==wc[0] && z[cnt+1]==0; *pnPattern = cnt; return 1; } #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ /* ** The input to this routine is an WhereTerm structure with only the ** "pExpr" field filled in. The job of this routine is to analyze the ** 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. */ static void exprAnalyze( SrcList *pSrc, /* the FROM clause */ ExprMaskSet *pMaskSet, /* table masks */ WhereTerm *pTerm /* the WHERE clause term to be analyzed */ ){ Expr *pExpr = pTerm->pExpr; Bitmask prereqLeft; Bitmask prereqAll; int idxRight; int nPattern; int isComplete; if( sqlite3_malloc_failed ) return; prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight); pTerm->prereqAll = prereqAll = exprTableUsage(pMaskSet, pExpr); pTerm->leftCursor = -1; pTerm->iParent = -1; pTerm->_operator = 0; idxRight = -1; 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); } if( pRight && pRight->op==TK_COLUMN ){ WhereTerm *pNew; Expr *pDup; if( pTerm->leftCursor>=0 ){ pDup = sqlite3ExprDup(pExpr); pNew = whereClauseInsert(pTerm->pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC); if( pNew==0 ) return; pNew->iParent = pTerm->idx; pTerm->nChild = 1; pTerm->flags |= TERM_COPIED; }else{ pDup = pExpr; pNew = pTerm; } exprCommute(pDup); pLeft = pDup->pLeft; pNew->leftCursor = pLeft->iTable; pNew->leftColumn = pLeft->iColumn; pNew->prereqRight = prereqLeft; pNew->prereqAll = prereqAll; pNew->_operator = operatorMask(pDup->op); } } #ifndef SQLITE_OMIT_BETWEEN_OPTIMIZATION /* If a term is the BETWEEN operator, create two new virtual terms ** that define the range that the BETWEEN implements. */ else if( pExpr->op==TK_BETWEEN ){ ExprList *pList = pExpr->pList; int i; static const u8 ops[] = {TK_GE, TK_LE}; assert( pList!=0 ); assert( pList->nExpr==2 ); for(i=0; i<2; i++){ Expr *pNewExpr; WhereTerm *pNewTerm; pNewExpr = sqlite3Expr(ops[i], sqlite3ExprDup(pExpr->pLeft), sqlite3ExprDup(pList->a[i].pExpr), 0); pNewTerm = whereClauseInsert(pTerm->pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); exprAnalyze(pSrc, pMaskSet, pNewTerm); pNewTerm->iParent = pTerm->idx; } 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. */ else if( pExpr->op==TK_OR ){ int ok; int i, j; int iColumn, iCursor; WhereClause sOr; WhereTerm *pOrTerm; assert( (pTerm->flags & TERM_DYNAMIC)==0 ); whereClauseInit(&sOr, pTerm->pWC->pParse); whereSplit(&sOr, pExpr, TK_OR); exprAnalyzeAll(pSrc, pMaskSet, &sOr); assert( sOr.nTerm>0 ); j = 0; do{ iColumn = sOr.a[j].leftColumn; iCursor = sOr.a[j].leftCursor; ok = iCursor>=0; for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){ if( pOrTerm->_operator!=WO_EQ ){ goto or_not_possible; } if( pOrTerm->leftCursor==iCursor && pOrTerm->leftColumn==iColumn ){ pOrTerm->flags |= TERM_OR_OK; }else if( (pOrTerm->flags & TERM_COPIED)!=0 || ((pOrTerm->flags & TERM_VIRTUAL)!=0 && (sOr.a[pOrTerm->iParent].flags & TERM_OR_OK)!=0) ){ pOrTerm->flags &= ~TERM_OR_OK; }else{ ok = 0; } } }while( !ok && (sOr.a[j++].flags & TERM_COPIED)!=0 && j<sOr.nTerm ); if( ok ){ ExprList *pList = 0; Expr *pNew, *pDup; for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){ if( (pOrTerm->flags & TERM_OR_OK)==0 ) continue; pDup = sqlite3ExprDup(pOrTerm->pExpr->pRight); pList = sqlite3ExprListAppend(pList, pDup, 0); } 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; pTerm->pExpr = pNew; pTerm->flags |= TERM_DYNAMIC; exprAnalyze(pSrc, pMaskSet, pTerm); } or_not_possible: whereClauseClear(&sOr); } #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ #ifndef SQLITE_OMIT_LIKE_OPTIMIZATION /* Add constraints to reduce the search space on a LIKE or GLOB ** operator. */ if( isLikeOrGlob(pTerm->pWC->pParse->db, pExpr, &nPattern, &isComplete) ){ Expr *pLeft, *pRight; Expr *pStr1, *pStr2; Expr *pNewExpr1, *pNewExpr2; WhereTerm *pNewTerm1, *pNewTerm2; pLeft = pExpr->pList->a[1].pExpr; pRight = pExpr->pList->a[0].pExpr; pStr1 = sqlite3Expr(TK_STRING, 0, 0, 0); if( pStr1 ){ sqlite3TokenCopy(&pStr1->token, &pRight->token); pStr1->token.n = nPattern; } pStr2 = sqlite3ExprDup(pStr1); if( pStr2 ){ assert( pStr2->token.dyn ); ++*(u8*)&pStr2->token.z[nPattern-1]; } pNewExpr1 = sqlite3Expr(TK_GE, sqlite3ExprDup(pLeft), pStr1, 0); pNewTerm1 = whereClauseInsert(pTerm->pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); exprAnalyze(pSrc, pMaskSet, pNewTerm1); pNewExpr2 = sqlite3Expr(TK_LT, sqlite3ExprDup(pLeft), pStr2, 0); pNewTerm2 = whereClauseInsert(pTerm->pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); exprAnalyze(pSrc, pMaskSet, pNewTerm2); if( isComplete ){ pNewTerm2->iParent = pTerm->idx; pNewTerm1->iParent = pTerm->idx; pTerm->nChild = 2; } } #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */ } /* ** This routine decides if pIdx can be used to satisfy the ORDER BY ** clause. If it can, it returns 1. If pIdx cannot satisfy the ** ORDER BY clause, this routine returns 0. ** ** pOrderBy is an ORDER BY clause from a SELECT statement. pTab is the ** left-most table in the FROM clause of that same SELECT statement and ** the table has a cursor number of "base". pIdx is an index on pTab. ** ** nEqCol is the number of columns of pIdx that are used as equality ** constraints. Any of these columns may be missing from the ORDER BY ** clause and the match can still be a success. ** ** All terms of the ORDER BY that match against the index must be either ** ASC or DESC. (Terms of the ORDER BY clause past the end of a UNIQUE ** index do not need to satisfy this constraint.) The *pbRev value is ** set to 1 if the ORDER BY clause is all DESC and it is set to 0 if ** the ORDER BY clause is all ASC. */ static int isSortingIndex( |
︙ | ︙ | |||
393 394 395 396 397 398 399 | sortOrder = pTerm->sortOrder; } j++; pTerm++; } /* The index can be used for sorting if all terms of the ORDER BY clause | < | | | 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | sortOrder = pTerm->sortOrder; } j++; pTerm++; } /* The index can be used for sorting if all terms of the ORDER BY clause ** are covered. */ if( j>=nTerm ){ *pbRev = sortOrder==SQLITE_SO_DESC; return 1; } return 0; } /* |
︙ | ︙ | |||
425 426 427 428 429 430 431 432 433 434 435 436 437 438 | if( p->op==TK_COLUMN && p->iTable==base && p->iColumn==-1 ){ *pbRev = pOrderBy->a[0].sortOrder; return 1; } return 0; } /* ** Disable a term in the WHERE clause. Except, do not disable the term ** if it controls a LEFT OUTER JOIN and it did not originate in the ON ** or USING clause of that join. ** ** Consider the term t2.z='ok' in the following queries: | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 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 | if( 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 logorithm 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; double x = 10.0; while( N>x ){ logN += 1.0; x *= 10; } return logN; } /* ** Find the best index for accessing a particular table. Return a pointer ** to the index, flags that describe how the index should be used, the ** number of equality constraints, and the "cost" for this index. ** ** The lowest cost index wins. The cost is an estimate of the amount of ** CPU and disk I/O need to process the request using the selected index. ** Factors that influence cost include: ** ** * The estimated number of rows that will be retrieved. (The ** fewer the better.) ** ** * Whether or not sorting must occur. ** ** * Whether or not there must be separate lookups in the ** index and in the main table. ** */ static double bestIndex( Parse *pParse, /* The parsing context */ WhereClause *pWC, /* The WHERE clause */ struct SrcList::SrcList_item *pSrc, /* The FROM clause term to search */ Bitmask notReady, /* Mask of cursors that are not available */ ExprList *pOrderBy, /* The order by clause */ Index **ppIndex, /* Make *ppIndex point to the best index */ int *pFlags, /* Put flags describing this choice in *pFlags */ int *pnEq /* Put the number of == or IN constraints here */ ){ WhereTerm *pTerm; Index *bestIdx = 0; /* Index that gives the lowest cost */ double lowestCost = 1.0e99; /* The cost of using bestIdx */ int bestFlags = 0; /* Flags associated with bestIdx */ int bestNEq = 0; /* Best value for nEq */ int iCur = pSrc->iCursor; /* The cursor of the table to be accessed */ Index *pProbe; /* An index we are evaluating */ int rev; /* True to scan in reverse order */ int flags; /* Flags associated with pProbe */ int nEq; /* Number of == or IN constraints */ double cost; /* Cost of using pProbe */ TRACE(("bestIndex: tbl=%s notReady=%x\n", pSrc->pTab->zName, notReady)); /* Check for a rowid=EXPR or rowid IN (...) constraints */ pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0); if( pTerm ){ Expr *pExpr; *ppIndex = 0; bestFlags = WHERE_ROWID_EQ; if( pTerm->_operator & WO_EQ ){ /* Rowid== is always the best pick. Look no further. Because only ** a single row is generated, output is always in sorted order */ *pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE; *pnEq = 1; TRACE(("... best is rowid\n")); return 0.0; }else if( (pExpr = pTerm->pExpr)->pList!=0 ){ /* Rowid IN (LIST): cost is NlogN where N is the number of list ** elements. */ lowestCost = pExpr->pList->nExpr; lowestCost *= estLog(lowestCost); }else{ /* Rowid IN (SELECT): cost is NlogN where N is the number of rows ** in the result of the inner select. We have no way to estimate ** that value so make a wild guess. */ lowestCost = 200.0; } TRACE(("... rowid IN cost: %.9g\n", lowestCost)); } /* Estimate the cost of a table scan. If we do not know how many ** entries are in the table, use 1 million as a guess. */ pProbe = pSrc->pTab->pIndex; cost = pProbe ? pProbe->aiRowEst[0] : 1000000.0; TRACE(("... table scan base cost: %.9g\n", cost)); flags = WHERE_ROWID_RANGE; /* Check for constraints on a range of rowids in a table scan. */ pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0); if( pTerm ){ if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){ flags |= WHERE_TOP_LIMIT; cost *= 0.333; /* Guess that rowid<EXPR eliminates two-thirds or rows */ } if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){ flags |= WHERE_BTM_LIMIT; cost *= 0.333; /* Guess that rowid>EXPR eliminates two-thirds of rows */ } TRACE(("... rowid range reduces cost to %.9g\n", cost)); }else{ flags = 0; } /* If the table scan does not satisfy the ORDER BY clause, increase ** the cost by NlogN to cover the expense of sorting. */ if( pOrderBy ){ if( sortableByRowid(iCur, pOrderBy, &rev) ){ flags |= WHERE_ORDERBY|WHERE_ROWID_RANGE; if( rev ){ flags |= WHERE_REVERSE; } }else{ cost += cost*estLog(cost); TRACE(("... sorting increases cost to %.9g\n", cost)); } } if( cost<lowestCost ){ lowestCost = cost; bestFlags = flags; } /* Look at each index. */ for(; pProbe; pProbe=pProbe->pNext){ int i; /* Loop counter */ double inMultiplier = 1.0; TRACE(("... index %s:\n", pProbe->zName)); /* Count the number of columns in the index that are satisfied ** by x=EXPR constraints or x IN (...) constraints. */ flags = 0; for(i=0; i<pProbe->nColumn; i++){ int j = pProbe->aiColumn[i]; pTerm = findTerm(pWC, iCur, j, notReady, WO_EQ|WO_IN, pProbe); if( pTerm==0 ) break; flags |= WHERE_COLUMN_EQ; if( pTerm->_operator & WO_IN ){ Expr *pExpr = pTerm->pExpr; flags |= WHERE_COLUMN_IN; if( pExpr->pSelect!=0 ){ inMultiplier *= 100.0; }else if( pExpr->pList!=0 ){ inMultiplier *= pExpr->pList->nExpr + 1.0; } } } cost = pProbe->aiRowEst[i] * inMultiplier * estLog(inMultiplier); nEq = i; if( pProbe->onError!=OE_None && (flags & WHERE_COLUMN_IN)==0 && nEq==pProbe->nColumn ){ flags |= WHERE_UNIQUE; } TRACE(("...... nEq=%d inMult=%.9g cost=%.9g\n", nEq, inMultiplier, cost)); /* Look for range constraints */ if( nEq<pProbe->nColumn ){ int j = pProbe->aiColumn[nEq]; pTerm = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pProbe); if( pTerm ){ flags |= WHERE_COLUMN_RANGE; if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pProbe) ){ flags |= WHERE_TOP_LIMIT; cost *= 0.333; } if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){ flags |= WHERE_BTM_LIMIT; cost *= 0.333; } TRACE(("...... range reduces cost to %.9g\n", cost)); } } /* Add the additional cost of sorting if that is a factor. */ if( pOrderBy ){ if( (flags & WHERE_COLUMN_IN)==0 && isSortingIndex(pParse,pProbe,pSrc->pTab,iCur,pOrderBy,nEq,&rev) ){ if( flags==0 ){ flags = WHERE_COLUMN_RANGE; } flags |= WHERE_ORDERBY; if( rev ){ flags |= WHERE_REVERSE; } }else{ cost += cost*estLog(cost); TRACE(("...... orderby increases cost to %.9g\n", cost)); } } /* Check to see if we can get away with using just the index without ** ever reading the table. If that is the case, then halve the ** cost of this index. */ if( flags && pSrc->colUsed < (((Bitmask)1)<<(BMS-1)) ){ Bitmask m = pSrc->colUsed; int j; for(j=0; j<pProbe->nColumn; j++){ int x = pProbe->aiColumn[j]; if( x<BMS-1 ){ m &= ~(((Bitmask)1)<<x); } } if( m==0 ){ flags |= WHERE_IDX_ONLY; cost *= 0.5; TRACE(("...... idx-only reduces cost to %.9g\n", cost)); } } /* If this index has achieved the lowest cost so far, then use it. */ if( cost < lowestCost ){ bestIdx = pProbe; lowestCost = cost; assert( flags!=0 ); bestFlags = flags; bestNEq = nEq; } } /* Report the best result */ *ppIndex = bestIdx; TRACE(("best index is %s, cost=%.9g, flags=%x, nEq=%d\n", bestIdx ? bestIdx->zName : "(none)", lowestCost, bestFlags, bestNEq)); *pFlags = bestFlags; *pnEq = bestNEq; return lowestCost; } /* ** Disable a term in the WHERE clause. Except, do not disable the term ** if it controls a LEFT OUTER JOIN and it did not originate in the ON ** or USING clause of that join. ** ** Consider the term t2.z='ok' in the following queries: |
︙ | ︙ | |||
448 449 450 451 452 453 454 | ** Disabling a term causes that term to not be tested in the inner loop ** of the join. Disabling is an optimization. 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. */ | | | > | > | > > > > > > | 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 | ** Disabling a term causes that term to not be tested in the inner loop ** of the join. Disabling is an optimization. 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; if( pTerm->iParent>=0 ){ WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent]; if( (--pOther->nChild)==0 ){ disableTerm(pLevel, pOther); } } } } /* ** Generate code that builds a probe for an index. Details: ** ** * Check the top nColumn entries on the stack. If any |
︙ | ︙ | |||
473 474 475 476 477 478 479 480 481 | static void buildIndexProbe(Vdbe *v, int nColumn, int brk, Index *pIdx){ sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); } /* | > | | > > > > > > > | | > > > > > > > > | | | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | static void buildIndexProbe(Vdbe *v, int nColumn, int brk, Index *pIdx){ sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); } /* ** Generate code for a single equality term of the WHERE clause. An equality ** term can be either X=expr or X IN (...). pTerm is the term to be ** coded. ** ** The current value for the constraint is left on the top of the stack. ** ** For a constraint of the form X=expr, the expression is evaluated and its ** result is left on the stack. For constraints of the form X IN (...) ** this routine sets up a loop that will iterate over all values of X. */ static void codeEqualityTerm( Parse *pParse, /* The parsing context */ WhereTerm *pTerm, /* The term of the WHERE clause to be coded */ int brk, /* Jump here to abandon the loop */ WhereLevel *pLevel /* When level of the FROM clause we are working on */ ){ Expr *pX = pTerm->pExpr; if( pX->op!=TK_IN ){ assert( pX->op==TK_EQ ); sqlite3ExprCode(pParse, pX->pRight); #ifndef SQLITE_OMIT_SUBQUERY }else{ int iTab; int *aIn; 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++; pLevel->aInLoop = aIn = (int *)sqliteRealloc(pLevel->aInLoop, sizeof(pLevel->aInLoop[0])*3*pLevel->nIn); 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; } #endif } disableTerm(pLevel, pTerm); } /* ** Generate code that will evaluate all == and IN constraints for an ** index. The values for all constraints are left on the stack. ** ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c). ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10 ** The index has as many as three equality constraints, but in this ** example, the third "c" value is an inequality. So only two ** constraints are coded. This routine will generate code to evaluate ** a==5 and b IN (1,2,3). The current values for a and b will be left ** on the stack - a is the deepest and b the shallowest. ** ** In the example above nEq==2. But this subroutine works for any value ** of nEq including 0. If nEq==0, this routine is nearly a no-op. ** The only thing it does is allocate the pLevel->iMem memory cell. ** ** This routine always allocates at least one memory cell and puts ** the address of that memory cell in pLevel->iMem. The code that ** calls this routine will use pLevel->iMem to store the termination ** key value of the loop. If one or more IN operators appear, then ** this routine allocates an additional nEq memory cells for internal ** use. */ static void codeAllEqualityTerms( Parse *pParse, /* Parsing context */ WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */ WhereClause *pWC, /* The WHERE clause */ Bitmask notReady, /* Which parts of FROM have not yet been coded */ int brk /* Jump here to end the loop */ ){ int nEq = pLevel->nEq; /* The number of == or IN constraints to code */ int termsInMem = 0; /* If true, store value in mem[] cells */ Vdbe *v = pParse->pVdbe; /* The virtual machine under construction */ Index *pIdx = pLevel->pIdx; /* The index being used for this loop */ int iCur = pLevel->iTabCur; /* The cursor of the table */ WhereTerm *pTerm; /* A single constraint term */ int j; /* Loop counter */ /* Figure out how many memory cells we will need then allocate them. ** We always need at least one used to store the loop terminator ** value. If there are IN operators we'll need one for each == or ** IN constraint. */ pLevel->iMem = pParse->nMem++; if( pLevel->flags & WHERE_COLUMN_IN ){ pParse->nMem += pLevel->nEq; termsInMem = 1; } /* Evaluate the equality constraints */ for(j=0; j<pIdx->nColumn; j++){ int k = pIdx->aiColumn[j]; pTerm = findTerm(pWC, iCur, k, notReady, WO_EQ|WO_IN, pIdx); if( pTerm==0 ) break; assert( (pTerm->flags & TERM_CODED)==0 ); codeEqualityTerm(pParse, pTerm, brk, pLevel); if( termsInMem ){ sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem+j+1, 1); } } assert( j==nEq ); /* Make sure all the constraint values are on the top of the stack */ if( termsInMem ){ for(j=0; j<nEq; j++){ sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem+j+1, 0); } } } #ifdef 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 */ static int nQPlan = 0; /* Next free slow in _query_plan[] */ #endif /* SQLITE_TEST */ /* ** Generate the beginning of the loop used for WHERE clause processing. ** The return value is a pointer to an opaque structure that contains ** information needed to terminate the loop. Later, the calling routine ** should invoke sqlite3WhereEnd() with the return value of this function |
︙ | ︙ | |||
536 537 538 539 540 541 542 543 544 545 546 547 548 549 | ** foreach row1 in t1 do \ Code generated ** foreach row2 in t2 do |-- by sqlite3WhereBegin() ** foreach row3 in t3 do / ** ... ** end \ Code generated ** end |-- by sqlite3WhereEnd() ** end / ** ** There are Btree cursors associated with each table. t1 uses cursor ** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor. ** And so forth. This routine generates code to open those VDBE cursors ** and sqlite3WhereEnd() generates the code to close them. ** ** The code that sqlite3WhereBegin() generates leaves the cursors named | > > > > > > | 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 | ** foreach row1 in t1 do \ Code generated ** foreach row2 in t2 do |-- by sqlite3WhereBegin() ** foreach row3 in t3 do / ** ... ** end \ Code generated ** end |-- by sqlite3WhereEnd() ** end / ** ** Note that the loops might not be nested in the order in which they ** appear in the FROM clause if a different order is better able to make ** use of indices. Note also that when the IN operator appears in ** the WHERE clause, it might result in additional nested loops for ** scanning through all values on the right-hand side of the IN. ** ** There are Btree cursors associated with each table. t1 uses cursor ** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor. ** And so forth. This routine generates code to open those VDBE cursors ** and sqlite3WhereEnd() generates the code to close them. ** ** The code that sqlite3WhereBegin() generates leaves the cursors named |
︙ | ︙ | |||
603 604 605 606 607 608 609 | Expr *pWhere, /* The WHERE clause */ ExprList **ppOrderBy /* An ORDER BY clause, or NULL */ ){ int i; /* Loop counter */ WhereInfo *pWInfo; /* Will become the return value of this function */ Vdbe *v = pParse->pVdbe; /* The virtual database engine */ int brk, cont = 0; /* Addresses used during code generation */ | | < | | < < < | > > | | | < | < < < < < | < | < < | | > > > < | > > < | < | > < < | < | > > | > | < | | > | < < < < | > > > > | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > | > | < < | | < < > | < < < < < | < < < < < < | < < | | < < < | | | < < < < < < < < < < < > | | | | < < < < < | < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < | < < < < < < | < < | | | | | | > | > > | < < < < < < < < < < < < < | | | | < < < < < < < < < < < < < < < | < | > | > | | > > | < < | | > > > | > < > > > | | > | | < | | | > < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | < | < | | < < < < < < < < < < < > | < | < < < > | < > | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | | > | | > > | | | < | | | > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | < | > > > | > > | | | < | | | 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 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 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 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 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 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 | Expr *pWhere, /* The WHERE clause */ ExprList **ppOrderBy /* An ORDER BY clause, or NULL */ ){ int i; /* Loop counter */ WhereInfo *pWInfo; /* Will become the return value of this function */ Vdbe *v = pParse->pVdbe; /* The virtual database engine */ int brk, cont = 0; /* Addresses used during code generation */ Bitmask notReady; /* Cursors that are not yet positioned */ WhereTerm *pTerm; /* A single term in the WHERE clause */ ExprMaskSet maskSet; /* The expression mask set */ WhereClause wc; /* The WHERE clause is divided into these terms */ struct SrcList::SrcList_item *pTabItem; /* A single entry from pTabList */ WhereLevel *pLevel; /* A single level in the pWInfo list */ int iFrom; /* First unused FROM clause element */ int andFlags; /* AND-ed combination of all wc.a[].flags */ /* The number of tables in the FROM clause is limited by the number of ** bits in a Bitmask */ if( pTabList->nSrc>BMS ){ sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS); return 0; } /* Split the WHERE clause into separate subexpressions where each ** subexpression is separated by an AND operator. */ initMaskSet(&maskSet); whereClauseInit(&wc, pParse); whereSplit(&wc, pWhere, TK_AND); /* Allocate and initialize the WhereInfo structure that will become the ** return value. */ pWInfo = (WhereInfo *)sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel)); if( sqlite3_malloc_failed ){ goto whereBeginNoMem; } pWInfo->pParse = pParse; pWInfo->pTabList = pTabList; pWInfo->iBreak = sqlite3VdbeMakeLabel(v); /* Special case: a WHERE clause that is constant. Evaluate the ** expression and either jump over all of the code or fall thru. */ if( pWhere && (pTabList->nSrc==0 || sqlite3ExprIsConstant(pWhere)) ){ 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 they 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; } /* Chose the best index to use for each table in the FROM clause. ** ** This loop fills in the following fields: ** ** pWInfo->a[].pIdx The index to use for this level of the loop. ** pWInfo->a[].flags WHERE_xxx flags associated with pIdx ** pWInfo->a[].nEq The number of == and IN constraints ** pWInfo->a[].iFrom When term of the FROM clause is being coded ** pWInfo->a[].iTabCur The VDBE cursor for the database table ** pWInfo->a[].iIdxCur The VDBE cursor for the index ** ** 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, (j==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)!=0 || (j>0 && (pTabItem[-1].jointype & JT_LEFT)!=0) ){ break; } } 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; } /* 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; 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; if( (pIx = pLevel->pIdx)!=0 ){ sqlite3VdbeAddOp(v, OP_Integer, pIx->iDb, 0); VdbeComment((v, "# %s", pIx->zName)); sqlite3VdbeOp3(v, OP_OpenRead, iIdxCur, pIx->tnum, (char*)&pIx->keyInfo, P3_KEYINFO); } if( (pLevel->flags & WHERE_IDX_ONLY)!=0 ){ sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, pIx->nColumn+1); } sqlite3CodeVerifySchema(pParse, pTab->iDb); } pWInfo->iTop = sqlite3VdbeCurrentAddr(v); /* Generate the code to do the search. Each iteration of the for ** loop below generates code for a single nested loop of the VM ** program. */ notReady = ~(Bitmask)0; for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ int j; int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */ Index *pIdx; /* The index we will be using */ int iIdxCur; /* The VDBE cursor for the index */ int omitTable; /* True if we use the index only */ int bRev; /* True if we need to scan in reverse order */ pTabItem = &pTabList->a[pLevel->iFrom]; iCur = pTabItem->iCursor; pIdx = pLevel->pIdx; iIdxCur = pLevel->iIdxCur; bRev = (pLevel->flags & WHERE_REVERSE)!=0; omitTable = (pLevel->flags & WHERE_IDX_ONLY)!=0; /* Create labels for the "break" and "continue" instructions ** for the current loop. Jump to brk to break out of a loop. ** Jump to cont to go immediately to the next iteration of the ** loop. */ brk = pLevel->brk = sqlite3VdbeMakeLabel(v); cont = pLevel->cont = sqlite3VdbeMakeLabel(v); /* 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_Null, 0, 0); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1); 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 (...)" ** construct. */ pTerm = findTerm(&wc, iCur, -1, notReady, WO_EQ|WO_IN, 0); assert( pTerm!=0 ); assert( pTerm->pExpr!=0 ); assert( pTerm->leftCursor==iCur ); assert( omitTable==0 ); codeEqualityTerm(pParse, pTerm, brk, pLevel); sqlite3VdbeAddOp(v, OP_MustBeInt, 1, brk); sqlite3VdbeAddOp(v, OP_NotExists, iCur, brk); VdbeComment((v, "pk")); pLevel->op = OP_Noop; }else if( pLevel->flags & WHERE_ROWID_RANGE ){ /* Case 2: We have an inequality comparison against the ROWID field. */ int testOp = OP_Noop; int start; WhereTerm *pStart, *pEnd; assert( omitTable==0 ); pStart = findTerm(&wc, iCur, -1, notReady, WO_GT|WO_GE, 0); pEnd = findTerm(&wc, iCur, -1, notReady, WO_LT|WO_LE, 0); if( bRev ){ pTerm = pStart; pStart = pEnd; pEnd = pTerm; } if( pStart ){ Expr *pX; pX = pStart->pExpr; assert( pX!=0 ); assert( pStart->leftCursor==iCur ); sqlite3ExprCode(pParse, pX->pRight); sqlite3VdbeAddOp(v, OP_ForceInt, pX->op==TK_LE || pX->op==TK_GT, brk); sqlite3VdbeAddOp(v, bRev ? OP_MoveLt : OP_MoveGe, iCur, brk); VdbeComment((v, "pk")); disableTerm(pLevel, pStart); }else{ sqlite3VdbeAddOp(v, bRev ? OP_Last : OP_Rewind, iCur, brk); } if( pEnd ){ Expr *pX; pX = pEnd->pExpr; assert( pX!=0 ); assert( pEnd->leftCursor==iCur ); sqlite3ExprCode(pParse, pX->pRight); pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); if( pX->op==TK_LT || pX->op==TK_GT ){ testOp = bRev ? OP_Le : OP_Ge; }else{ testOp = bRev ? OP_Lt : OP_Gt; } disableTerm(pLevel, pEnd); } start = sqlite3VdbeCurrentAddr(v); pLevel->op = bRev ? OP_Prev : OP_Next; pLevel->p1 = iCur; pLevel->p2 = start; if( testOp!=OP_Noop ){ sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0); sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, testOp, 'n', brk); } }else if( pLevel->flags & WHERE_COLUMN_RANGE ){ /* Case 3: The WHERE clause term that refers to the right-most ** column of the index is an inequality. For example, if ** the index is on (x,y,z) and the WHERE clause is of the ** form "x=5 AND y<10" then this case is used. Only the ** right-most column can be an inequality - the rest must ** use the "==" and "IN" operators. ** ** This case is also used when there are no WHERE clause ** constraints but an index is selected anyway, in order ** to force the output order to conform to an ORDER BY. */ int start; int nEq = pLevel->nEq; int leFlag=0, geFlag=0; int testOp; int topLimit = (pLevel->flags & WHERE_TOP_LIMIT)!=0; int btmLimit = (pLevel->flags & WHERE_BTM_LIMIT)!=0; /* Generate code to evaluate all constraint terms using == or IN ** and level the values of those terms on the stack. */ codeAllEqualityTerms(pParse, pLevel, &wc, notReady, brk); /* Duplicate the equality term values because they will all be ** used twice: once to make the termination key and once to make the ** start key. */ for(j=0; j<nEq; j++){ sqlite3VdbeAddOp(v, OP_Dup, nEq-1, 0); } /* Generate the termination key. This is the key value that ** will end the search. There is no termination key if there ** are no equality terms and no "X<..." term. ** ** 2002-Dec-04: On a reverse-order scan, the so-called "termination" ** key computed here really ends up being the start key. */ if( topLimit ){ Expr *pX; int k = pIdx->aiColumn[j]; pTerm = findTerm(&wc, iCur, k, notReady, WO_LT|WO_LE, pIdx); assert( pTerm!=0 ); pX = pTerm->pExpr; assert( (pTerm->flags & TERM_CODED)==0 ); sqlite3ExprCode(pParse, pX->pRight); leFlag = pX->op==TK_LE; disableTerm(pLevel, pTerm); testOp = OP_IdxGE; }else{ testOp = nEq>0 ? OP_IdxGE : OP_Noop; leFlag = 1; } if( testOp!=OP_Noop ){ int nCol = nEq + topLimit; pLevel->iMem = pParse->nMem++; buildIndexProbe(v, nCol, brk, pIdx); if( bRev ){ int op = leFlag ? OP_MoveLe : OP_MoveLt; sqlite3VdbeAddOp(v, op, iIdxCur, brk); }else{ sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); } }else if( bRev ){ sqlite3VdbeAddOp(v, OP_Last, iIdxCur, brk); } /* Generate the start key. This is the key that defines the lower ** bound on the search. There is no start key if there are no ** equality terms and if there is no "X>..." term. In ** that case, generate a "Rewind" instruction in place of the ** start key search. ** ** 2002-Dec-04: In the case of a reverse-order search, the so-called ** "start" key really ends up being used as the termination key. */ if( btmLimit ){ Expr *pX; int k = pIdx->aiColumn[j]; pTerm = findTerm(&wc, iCur, k, notReady, WO_GT|WO_GE, pIdx); assert( pTerm!=0 ); pX = pTerm->pExpr; assert( (pTerm->flags & TERM_CODED)==0 ); sqlite3ExprCode(pParse, pX->pRight); geFlag = pX->op==TK_GE; disableTerm(pLevel, pTerm); }else{ geFlag = 1; } if( nEq>0 || btmLimit ){ int nCol = nEq + btmLimit; buildIndexProbe(v, nCol, brk, pIdx); if( bRev ){ pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); testOp = OP_IdxLT; }else{ int op = geFlag ? OP_MoveGe : OP_MoveGt; sqlite3VdbeAddOp(v, op, iIdxCur, brk); } }else if( bRev ){ testOp = OP_Noop; }else{ sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, brk); } /* Generate the the top of the loop. If there is a termination ** key we have to test for that key and abort at the top of the ** loop. */ start = sqlite3VdbeCurrentAddr(v); if( testOp!=OP_Noop ){ sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, testOp, iIdxCur, brk); if( (leFlag && !bRev) || (!geFlag && bRev) ){ sqlite3VdbeChangeP3(v, -1, "+", P3_STATIC); } } sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0); sqlite3VdbeAddOp(v, OP_IdxIsNull, nEq + topLimit, cont); if( !omitTable ){ sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0); sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0); } /* Record the instruction used to terminate the loop. */ pLevel->op = bRev ? OP_Prev : OP_Next; pLevel->p1 = iIdxCur; pLevel->p2 = start; }else if( pLevel->flags & WHERE_COLUMN_EQ ){ /* Case 4: There is an index and all terms of the WHERE clause that ** refer to the index using the "==" or "IN" operators. */ int start; int nEq = pLevel->nEq; /* Generate code to evaluate all constraint terms using == or IN ** and leave the values of those terms on the stack. */ codeAllEqualityTerms(pParse, pLevel, &wc, notReady, brk); /* Generate a single key that will be used to both start and terminate ** the search */ buildIndexProbe(v, nEq, brk, pIdx); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 0); /* Generate code (1) to move to the first matching element of the table. ** Then generate code (2) that jumps to "brk" after the cursor is past ** the last matching element of the table. The code (1) is executed ** once to initialize the search, the code (2) is executed before each ** iteration of the scan to see if the scan has finished. */ if( bRev ){ /* Scan in reverse order */ sqlite3VdbeAddOp(v, OP_MoveLe, iIdxCur, brk); start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeAddOp(v, OP_IdxLT, iIdxCur, brk); pLevel->op = OP_Prev; }else{ /* Scan in the forward order */ sqlite3VdbeAddOp(v, OP_MoveGe, iIdxCur, brk); start = sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0); sqlite3VdbeOp3(v, OP_IdxGE, iIdxCur, brk, "+", P3_STATIC); pLevel->op = OP_Next; } sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0); sqlite3VdbeAddOp(v, OP_IdxIsNull, nEq, cont); if( !omitTable ){ sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0); sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0); } pLevel->p1 = iIdxCur; pLevel->p2 = start; }else{ /* Case 5: There is no usable index. We must do a complete ** scan of the entire table. */ assert( omitTable==0 ); assert( bRev==0 ); pLevel->op = OP_Next; pLevel->p1 = iCur; pLevel->p2 = 1 + sqlite3VdbeAddOp(v, OP_Rewind, iCur, brk); } notReady &= ~getMask(&maskSet, iCur); /* Insert code to test every subexpression that can be completely ** computed using the current set of tables. */ for(pTerm=wc.a, j=wc.nTerm; j>0; j--, pTerm++){ Expr *pE; if( pTerm->flags & (TERM_VIRTUAL|TERM_CODED) ) continue; if( (pTerm->prereqAll & notReady)!=0 ) continue; pE = pTerm->pExpr; assert( pE!=0 ); if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){ continue; } sqlite3ExprIfFalse(pParse, pE, cont, 1); pTerm->flags |= TERM_CODED; } /* 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_Integer, 1, 0); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1); 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; } } } #ifdef SQLITE_TEST /* For testing and debugging use only */ /* Record in the query plan information about the current table ** and the index used to access it (if any). If the table itself ** is not used, its name is just '{}'. If no index is used ** the index is listed as "{}". If the primary key is used the ** index name is '*'. */ for(i=0; i<pTabList->nSrc; i++){ char *z; int n; pLevel = &pWInfo->a[i]; pTabItem = &pTabList->a[pLevel->iFrom]; z = pTabItem->zAlias; if( z==0 ) z = pTabItem->pTab->zName; n = strlen(z); if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){ if( pLevel->flags & WHERE_IDX_ONLY ){ strcpy(&sqlite3_query_plan[nQPlan], "{}"); nQPlan += 2; }else{ strcpy(&sqlite3_query_plan[nQPlan], z); nQPlan += n; } sqlite3_query_plan[nQPlan++] = ' '; } if( pLevel->flags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){ strcpy(&sqlite3_query_plan[nQPlan], "* "); nQPlan += 2; }else if( pLevel->pIdx==0 ){ strcpy(&sqlite3_query_plan[nQPlan], "{} "); nQPlan += 3; }else{ n = strlen(pLevel->pIdx->zName); if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){ strcpy(&sqlite3_query_plan[nQPlan], pLevel->pIdx->zName); nQPlan += n; sqlite3_query_plan[nQPlan++] = ' '; } } } while( nQPlan>0 && sqlite3_query_plan[nQPlan-1]==' ' ){ sqlite3_query_plan[--nQPlan] = 0; } sqlite3_query_plan[nQPlan] = 0; nQPlan = 0; #endif /* SQLITE_TEST // Testing and debugging use only */ /* Record the continuation address in the WhereInfo structure. Then ** clean up and return. */ pWInfo->iContinue = cont; whereClauseClear(&wc); return pWInfo; /* Jump here if malloc fails */ whereBeginNoMem: whereClauseClear(&wc); sqliteFree(pWInfo); return 0; } /* ** Generate the end of the WHERE loop. See comments on ** sqlite3WhereBegin() for additional information. */ void sqlite3WhereEnd(WhereInfo *pWInfo){ Vdbe *v = pWInfo->pParse->pVdbe; int i; WhereLevel *pLevel; SrcList *pTabList = pWInfo->pTabList; /* Generate loop termination code. */ for(i=pTabList->nSrc-1; i>=0; i--){ pLevel = &pWInfo->a[i]; sqlite3VdbeResolveLabel(v, pLevel->cont); if( pLevel->op!=OP_Noop ){ sqlite3VdbeAddOp(v, pLevel->op, pLevel->p1, pLevel->p2); } sqlite3VdbeResolveLabel(v, pLevel->brk); if( pLevel->nIn ){ int *a; int j; 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_MemLoad, pLevel->iLeftJoin, 0); sqlite3VdbeAddOp(v, OP_NotNull, 1, addr+4 + (pLevel->iIdxCur>=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); } } /* The "break" point is here, just past the end of the outer loop. ** Set it. */ sqlite3VdbeResolveLabel(v, pWInfo->iBreak); /* Close all of the cursors that were opened by sqlite3WhereBegin. */ for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ struct SrcList::SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom]; Table *pTab = pTabItem->pTab; assert( pTab!=0 ); if( pTab->isTransient || pTab->pSelect ) continue; if( (pLevel->flags & WHERE_IDX_ONLY)==0 ){ sqlite3VdbeAddOp(v, OP_Close, pTabItem->iCursor, 0); } if( pLevel->pIdx!=0 ){ sqlite3VdbeAddOp(v, OP_Close, pLevel->iIdxCur, 0); } /* Make cursor substitutions for cases where we want to use ** just the index and never reference the table. ** ** Calls to the code generator in between sqlite3WhereBegin and ** sqlite3WhereEnd will have created code that references the table ** directly. This loop scans all that code looking for opcodes ** that reference the table and converts them into opcodes that ** reference the index. */ if( pLevel->flags & WHERE_IDX_ONLY ){ int i, j, last; VdbeOp *pOp; Index *pIdx = pLevel->pIdx; assert( pIdx!=0 ); pOp = sqlite3VdbeGetOp(v, pWInfo->iTop); last = sqlite3VdbeCurrentAddr(v); |
︙ | ︙ | |||
1436 1437 1438 1439 1440 1441 1442 | } /* Final cleanup */ sqliteFree(pWInfo); return; } | | < | 1985 1986 1987 1988 1989 1990 1991 1992 | } /* Final cleanup */ sqliteFree(pWInfo); return; } } |