OLD | NEW |
1 /* | 1 /* |
2 ** 2001 September 15 | 2 ** 2001 September 15 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 ** IdChar(X) will be true. Otherwise it is false. | 70 ** IdChar(X) will be true. Otherwise it is false. |
71 ** | 71 ** |
72 ** For ASCII, any character with the high-order bit set is | 72 ** For ASCII, any character with the high-order bit set is |
73 ** allowed in an identifier. For 7-bit characters, | 73 ** allowed in an identifier. For 7-bit characters, |
74 ** sqlite3IsIdChar[X] must be 1. | 74 ** sqlite3IsIdChar[X] must be 1. |
75 ** | 75 ** |
76 ** For EBCDIC, the rules are more complex but have the same | 76 ** For EBCDIC, the rules are more complex but have the same |
77 ** end result. | 77 ** end result. |
78 ** | 78 ** |
79 ** Ticket #1066. the SQL standard does not allow '$' in the | 79 ** Ticket #1066. the SQL standard does not allow '$' in the |
80 ** middle of identfiers. But many SQL implementations do. | 80 ** middle of identifiers. But many SQL implementations do. |
81 ** SQLite will allow '$' in identifiers for compatibility. | 81 ** SQLite will allow '$' in identifiers for compatibility. |
82 ** But the feature is undocumented. | 82 ** But the feature is undocumented. |
83 */ | 83 */ |
84 #ifdef SQLITE_ASCII | 84 #ifdef SQLITE_ASCII |
85 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0) | 85 #define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0) |
86 #endif | 86 #endif |
87 #ifdef SQLITE_EBCDIC | 87 #ifdef SQLITE_EBCDIC |
88 const char sqlite3IsEbcdicIdChar[] = { | 88 const char sqlite3IsEbcdicIdChar[] = { |
89 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ | 89 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ |
90 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */ | 90 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */ |
91 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */ | 91 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */ |
92 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */ | 92 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */ |
93 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */ | 93 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */ |
94 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */ | 94 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */ |
95 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */ | 95 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */ |
96 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */ | 96 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */ |
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */ | 97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */ |
98 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */ | 98 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */ |
99 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */ | 99 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */ |
100 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */ | 100 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */ |
101 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */ | 101 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */ |
102 }; | 102 }; |
103 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40])) | 103 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40])) |
104 #endif | 104 #endif |
| 105 int sqlite3IsIdChar(u8 c){ return IdChar(c); } |
105 | 106 |
106 | 107 |
107 /* | 108 /* |
108 ** Return the length of the token that begins at z[0]. | 109 ** Return the length of the token that begins at z[0]. |
109 ** Store the token type in *tokenType before returning. | 110 ** Store the token type in *tokenType before returning. |
110 */ | 111 */ |
111 int sqlite3GetToken(const unsigned char *z, int *tokenType){ | 112 int sqlite3GetToken(const unsigned char *z, int *tokenType){ |
112 int i, c; | 113 int i, c; |
113 switch( *z ){ | 114 switch( *z ){ |
114 case ' ': case '\t': case '\n': case '\f': case '\r': { | 115 case ' ': case '\t': case '\n': case '\f': case '\r': { |
115 testcase( z[0]==' ' ); | 116 testcase( z[0]==' ' ); |
116 testcase( z[0]=='\t' ); | 117 testcase( z[0]=='\t' ); |
117 testcase( z[0]=='\n' ); | 118 testcase( z[0]=='\n' ); |
118 testcase( z[0]=='\f' ); | 119 testcase( z[0]=='\f' ); |
119 testcase( z[0]=='\r' ); | 120 testcase( z[0]=='\r' ); |
120 for(i=1; sqlite3Isspace(z[i]); i++){} | 121 for(i=1; sqlite3Isspace(z[i]); i++){} |
121 *tokenType = TK_SPACE; | 122 *tokenType = TK_SPACE; |
122 return i; | 123 return i; |
123 } | 124 } |
124 case '-': { | 125 case '-': { |
125 if( z[1]=='-' ){ | 126 if( z[1]=='-' ){ |
126 /* IMP: R-15891-05542 -- syntax diagram for comments */ | |
127 for(i=2; (c=z[i])!=0 && c!='\n'; i++){} | 127 for(i=2; (c=z[i])!=0 && c!='\n'; i++){} |
128 *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ | 128 *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ |
129 return i; | 129 return i; |
130 } | 130 } |
131 *tokenType = TK_MINUS; | 131 *tokenType = TK_MINUS; |
132 return 1; | 132 return 1; |
133 } | 133 } |
134 case '(': { | 134 case '(': { |
135 *tokenType = TK_LP; | 135 *tokenType = TK_LP; |
136 return 1; | 136 return 1; |
(...skipping 12 matching lines...) Expand all Loading... |
149 } | 149 } |
150 case '*': { | 150 case '*': { |
151 *tokenType = TK_STAR; | 151 *tokenType = TK_STAR; |
152 return 1; | 152 return 1; |
153 } | 153 } |
154 case '/': { | 154 case '/': { |
155 if( z[1]!='*' || z[2]==0 ){ | 155 if( z[1]!='*' || z[2]==0 ){ |
156 *tokenType = TK_SLASH; | 156 *tokenType = TK_SLASH; |
157 return 1; | 157 return 1; |
158 } | 158 } |
159 /* IMP: R-15891-05542 -- syntax diagram for comments */ | |
160 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){} | 159 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){} |
161 if( c ) i++; | 160 if( c ) i++; |
162 *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ | 161 *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ |
163 return i; | 162 return i; |
164 } | 163 } |
165 case '%': { | 164 case '%': { |
166 *tokenType = TK_REM; | 165 *tokenType = TK_REM; |
167 return 1; | 166 return 1; |
168 } | 167 } |
169 case '=': { | 168 case '=': { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 /* If the next character is a digit, this is a floating point | 264 /* If the next character is a digit, this is a floating point |
266 ** number that begins with ".". Fall thru into the next case */ | 265 ** number that begins with ".". Fall thru into the next case */ |
267 } | 266 } |
268 case '0': case '1': case '2': case '3': case '4': | 267 case '0': case '1': case '2': case '3': case '4': |
269 case '5': case '6': case '7': case '8': case '9': { | 268 case '5': case '6': case '7': case '8': case '9': { |
270 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' ); | 269 testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' ); |
271 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' ); | 270 testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' ); |
272 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' ); | 271 testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' ); |
273 testcase( z[0]=='9' ); | 272 testcase( z[0]=='9' ); |
274 *tokenType = TK_INTEGER; | 273 *tokenType = TK_INTEGER; |
| 274 #ifndef SQLITE_OMIT_HEX_INTEGER |
| 275 if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){ |
| 276 for(i=3; sqlite3Isxdigit(z[i]); i++){} |
| 277 return i; |
| 278 } |
| 279 #endif |
275 for(i=0; sqlite3Isdigit(z[i]); i++){} | 280 for(i=0; sqlite3Isdigit(z[i]); i++){} |
276 #ifndef SQLITE_OMIT_FLOATING_POINT | 281 #ifndef SQLITE_OMIT_FLOATING_POINT |
277 if( z[i]=='.' ){ | 282 if( z[i]=='.' ){ |
278 i++; | 283 i++; |
279 while( sqlite3Isdigit(z[i]) ){ i++; } | 284 while( sqlite3Isdigit(z[i]) ){ i++; } |
280 *tokenType = TK_FLOAT; | 285 *tokenType = TK_FLOAT; |
281 } | 286 } |
282 if( (z[i]=='e' || z[i]=='E') && | 287 if( (z[i]=='e' || z[i]=='E') && |
283 ( sqlite3Isdigit(z[i+1]) | 288 ( sqlite3Isdigit(z[i+1]) |
284 || ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2])) | 289 || ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2])) |
(...skipping 13 matching lines...) Expand all Loading... |
298 case '[': { | 303 case '[': { |
299 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){} | 304 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){} |
300 *tokenType = c==']' ? TK_ID : TK_ILLEGAL; | 305 *tokenType = c==']' ? TK_ID : TK_ILLEGAL; |
301 return i; | 306 return i; |
302 } | 307 } |
303 case '?': { | 308 case '?': { |
304 *tokenType = TK_VARIABLE; | 309 *tokenType = TK_VARIABLE; |
305 for(i=1; sqlite3Isdigit(z[i]); i++){} | 310 for(i=1; sqlite3Isdigit(z[i]); i++){} |
306 return i; | 311 return i; |
307 } | 312 } |
308 case '#': { | |
309 for(i=1; sqlite3Isdigit(z[i]); i++){} | |
310 if( i>1 ){ | |
311 /* Parameters of the form #NNN (where NNN is a number) are used | |
312 ** internally by sqlite3NestedParse. */ | |
313 *tokenType = TK_REGISTER; | |
314 return i; | |
315 } | |
316 /* Fall through into the next case if the '#' is not followed by | |
317 ** a digit. Try to match #AAAA where AAAA is a parameter name. */ | |
318 } | |
319 #ifndef SQLITE_OMIT_TCL_VARIABLE | 313 #ifndef SQLITE_OMIT_TCL_VARIABLE |
320 case '$': | 314 case '$': |
321 #endif | 315 #endif |
322 case '@': /* For compatibility with MS SQL Server */ | 316 case '@': /* For compatibility with MS SQL Server */ |
| 317 case '#': |
323 case ':': { | 318 case ':': { |
324 int n = 0; | 319 int n = 0; |
325 testcase( z[0]=='$' ); testcase( z[0]=='@' ); testcase( z[0]==':' ); | 320 testcase( z[0]=='$' ); testcase( z[0]=='@' ); |
| 321 testcase( z[0]==':' ); testcase( z[0]=='#' ); |
326 *tokenType = TK_VARIABLE; | 322 *tokenType = TK_VARIABLE; |
327 for(i=1; (c=z[i])!=0; i++){ | 323 for(i=1; (c=z[i])!=0; i++){ |
328 if( IdChar(c) ){ | 324 if( IdChar(c) ){ |
329 n++; | 325 n++; |
330 #ifndef SQLITE_OMIT_TCL_VARIABLE | 326 #ifndef SQLITE_OMIT_TCL_VARIABLE |
331 }else if( c=='(' && n>0 ){ | 327 }else if( c=='(' && n>0 ){ |
332 do{ | 328 do{ |
333 i++; | 329 i++; |
334 }while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' ); | 330 }while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' ); |
335 if( c==')' ){ | 331 if( c==')' ){ |
(...skipping 10 matching lines...) Expand all Loading... |
346 } | 342 } |
347 } | 343 } |
348 if( n==0 ) *tokenType = TK_ILLEGAL; | 344 if( n==0 ) *tokenType = TK_ILLEGAL; |
349 return i; | 345 return i; |
350 } | 346 } |
351 #ifndef SQLITE_OMIT_BLOB_LITERAL | 347 #ifndef SQLITE_OMIT_BLOB_LITERAL |
352 case 'x': case 'X': { | 348 case 'x': case 'X': { |
353 testcase( z[0]=='x' ); testcase( z[0]=='X' ); | 349 testcase( z[0]=='x' ); testcase( z[0]=='X' ); |
354 if( z[1]=='\'' ){ | 350 if( z[1]=='\'' ){ |
355 *tokenType = TK_BLOB; | 351 *tokenType = TK_BLOB; |
356 for(i=2; (c=z[i])!=0 && c!='\''; i++){ | 352 for(i=2; sqlite3Isxdigit(z[i]); i++){} |
357 if( !sqlite3Isxdigit(c) ){ | 353 if( z[i]!='\'' || i%2 ){ |
358 *tokenType = TK_ILLEGAL; | 354 *tokenType = TK_ILLEGAL; |
359 } | 355 while( z[i] && z[i]!='\'' ){ i++; } |
360 } | 356 } |
361 if( i%2 || !c ) *tokenType = TK_ILLEGAL; | 357 if( z[i] ) i++; |
362 if( c ) i++; | |
363 return i; | 358 return i; |
364 } | 359 } |
365 /* Otherwise fall through to the next case */ | 360 /* Otherwise fall through to the next case */ |
366 } | 361 } |
367 #endif | 362 #endif |
368 default: { | 363 default: { |
369 if( !IdChar(*z) ){ | 364 if( !IdChar(*z) ){ |
370 break; | 365 break; |
371 } | 366 } |
372 for(i=1; IdChar(z[i]); i++){} | 367 for(i=1; IdChar(z[i]); i++){} |
(...skipping 17 matching lines...) Expand all Loading... |
390 int i; /* Loop counter */ | 385 int i; /* Loop counter */ |
391 void *pEngine; /* The LEMON-generated LALR(1) parser */ | 386 void *pEngine; /* The LEMON-generated LALR(1) parser */ |
392 int tokenType; /* type of the next token */ | 387 int tokenType; /* type of the next token */ |
393 int lastTokenParsed = -1; /* type of the previous token */ | 388 int lastTokenParsed = -1; /* type of the previous token */ |
394 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */ | 389 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */ |
395 sqlite3 *db = pParse->db; /* The database connection */ | 390 sqlite3 *db = pParse->db; /* The database connection */ |
396 int mxSqlLen; /* Max length of an SQL string */ | 391 int mxSqlLen; /* Max length of an SQL string */ |
397 | 392 |
398 | 393 |
399 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; | 394 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
400 if( db->activeVdbeCnt==0 ){ | 395 if( db->nVdbeActive==0 ){ |
401 db->u1.isInterrupted = 0; | 396 db->u1.isInterrupted = 0; |
402 } | 397 } |
403 pParse->rc = SQLITE_OK; | 398 pParse->rc = SQLITE_OK; |
404 pParse->zTail = zSql; | 399 pParse->zTail = zSql; |
405 i = 0; | 400 i = 0; |
406 assert( pzErrMsg!=0 ); | 401 assert( pzErrMsg!=0 ); |
407 pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc); | 402 pEngine = sqlite3ParserAlloc(sqlite3Malloc); |
408 if( pEngine==0 ){ | 403 if( pEngine==0 ){ |
409 db->mallocFailed = 1; | 404 db->mallocFailed = 1; |
410 return SQLITE_NOMEM; | 405 return SQLITE_NOMEM; |
411 } | 406 } |
412 assert( pParse->pNewTable==0 ); | 407 assert( pParse->pNewTable==0 ); |
413 assert( pParse->pNewTrigger==0 ); | 408 assert( pParse->pNewTrigger==0 ); |
414 assert( pParse->nVar==0 ); | 409 assert( pParse->nVar==0 ); |
415 assert( pParse->nVarExpr==0 ); | 410 assert( pParse->nzVar==0 ); |
416 assert( pParse->nVarExprAlloc==0 ); | 411 assert( pParse->azVar==0 ); |
417 assert( pParse->apVarExpr==0 ); | |
418 enableLookaside = db->lookaside.bEnabled; | 412 enableLookaside = db->lookaside.bEnabled; |
419 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1; | 413 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1; |
420 while( !db->mallocFailed && zSql[i]!=0 ){ | 414 while( !db->mallocFailed && zSql[i]!=0 ){ |
421 assert( i>=0 ); | 415 assert( i>=0 ); |
422 pParse->sLastToken.z = &zSql[i]; | 416 pParse->sLastToken.z = &zSql[i]; |
423 pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType); | 417 pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType); |
424 i += pParse->sLastToken.n; | 418 i += pParse->sLastToken.n; |
425 if( i>mxSqlLen ){ | 419 if( i>mxSqlLen ){ |
426 pParse->rc = SQLITE_TOOBIG; | 420 pParse->rc = SQLITE_TOOBIG; |
427 break; | 421 break; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 #endif | 494 #endif |
501 | 495 |
502 if( !IN_DECLARE_VTAB ){ | 496 if( !IN_DECLARE_VTAB ){ |
503 /* If the pParse->declareVtab flag is set, do not delete any table | 497 /* If the pParse->declareVtab flag is set, do not delete any table |
504 ** structure built up in pParse->pNewTable. The calling code (see vtab.c) | 498 ** structure built up in pParse->pNewTable. The calling code (see vtab.c) |
505 ** will take responsibility for freeing the Table structure. | 499 ** will take responsibility for freeing the Table structure. |
506 */ | 500 */ |
507 sqlite3DeleteTable(db, pParse->pNewTable); | 501 sqlite3DeleteTable(db, pParse->pNewTable); |
508 } | 502 } |
509 | 503 |
| 504 if( pParse->bFreeWith ) sqlite3WithDelete(db, pParse->pWith); |
510 sqlite3DeleteTrigger(db, pParse->pNewTrigger); | 505 sqlite3DeleteTrigger(db, pParse->pNewTrigger); |
511 sqlite3DbFree(db, pParse->apVarExpr); | 506 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]); |
512 sqlite3DbFree(db, pParse->aAlias); | 507 sqlite3DbFree(db, pParse->azVar); |
513 while( pParse->pAinc ){ | 508 while( pParse->pAinc ){ |
514 AutoincInfo *p = pParse->pAinc; | 509 AutoincInfo *p = pParse->pAinc; |
515 pParse->pAinc = p->pNext; | 510 pParse->pAinc = p->pNext; |
516 sqlite3DbFree(db, p); | 511 sqlite3DbFree(db, p); |
517 } | 512 } |
518 while( pParse->pZombieTab ){ | 513 while( pParse->pZombieTab ){ |
519 Table *p = pParse->pZombieTab; | 514 Table *p = pParse->pZombieTab; |
520 pParse->pZombieTab = p->pNextZombie; | 515 pParse->pZombieTab = p->pNextZombie; |
521 sqlite3DeleteTable(db, p); | 516 sqlite3DeleteTable(db, p); |
522 } | 517 } |
523 if( nErr>0 && pParse->rc==SQLITE_OK ){ | 518 if( nErr>0 && pParse->rc==SQLITE_OK ){ |
524 pParse->rc = SQLITE_ERROR; | 519 pParse->rc = SQLITE_ERROR; |
525 } | 520 } |
526 return nErr; | 521 return nErr; |
527 } | 522 } |
OLD | NEW |