Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/tokenize.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
106 /* Make the IdChar function accessible from ctime.c */
107 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
105 int sqlite3IsIdChar(u8 c){ return IdChar(c); } 108 int sqlite3IsIdChar(u8 c){ return IdChar(c); }
109 #endif
106 110
107 111
108 /* 112 /*
109 ** Return the length of the token that begins at z[0]. 113 ** Return the length of the token that begins at z[0].
110 ** Store the token type in *tokenType before returning. 114 ** Store the token type in *tokenType before returning.
111 */ 115 */
112 int sqlite3GetToken(const unsigned char *z, int *tokenType){ 116 int sqlite3GetToken(const unsigned char *z, int *tokenType){
113 int i, c; 117 int i, c;
114 switch( *z ){ 118 switch( *z ){
115 case ' ': case '\t': case '\n': case '\f': case '\r': { 119 case ' ': case '\t': case '\n': case '\f': case '\r': {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return i; 362 return i;
359 } 363 }
360 /* Otherwise fall through to the next case */ 364 /* Otherwise fall through to the next case */
361 } 365 }
362 #endif 366 #endif
363 default: { 367 default: {
364 if( !IdChar(*z) ){ 368 if( !IdChar(*z) ){
365 break; 369 break;
366 } 370 }
367 for(i=1; IdChar(z[i]); i++){} 371 for(i=1; IdChar(z[i]); i++){}
368 *tokenType = keywordCode((char*)z, i); 372 *tokenType = TK_ID;
369 return i; 373 return keywordCode((char*)z, i, tokenType);
370 } 374 }
371 } 375 }
372 *tokenType = TK_ILLEGAL; 376 *tokenType = TK_ILLEGAL;
373 return 1; 377 return 1;
374 } 378 }
375 379
376 /* 380 /*
377 ** Run the parser on the given SQL string. The parser structure is 381 ** Run the parser on the given SQL string. The parser structure is
378 ** passed in. An SQLITE_ status code is returned. If an error occurs 382 ** passed in. An SQLITE_ status code is returned. If an error occurs
379 ** then an and attempt is made to write an error message into 383 ** then an and attempt is made to write an error message into
380 ** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that 384 ** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that
381 ** error message. 385 ** error message.
382 */ 386 */
383 int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ 387 int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
384 int nErr = 0; /* Number of errors encountered */ 388 int nErr = 0; /* Number of errors encountered */
385 int i; /* Loop counter */ 389 int i; /* Loop counter */
386 void *pEngine; /* The LEMON-generated LALR(1) parser */ 390 void *pEngine; /* The LEMON-generated LALR(1) parser */
387 int tokenType; /* type of the next token */ 391 int tokenType; /* type of the next token */
388 int lastTokenParsed = -1; /* type of the previous token */ 392 int lastTokenParsed = -1; /* type of the previous token */
389 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */ 393 u8 enableLookaside; /* Saved value of db->lookaside.bEnabled */
390 sqlite3 *db = pParse->db; /* The database connection */ 394 sqlite3 *db = pParse->db; /* The database connection */
391 int mxSqlLen; /* Max length of an SQL string */ 395 int mxSqlLen; /* Max length of an SQL string */
392 396
393 397 assert( zSql!=0 );
394 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; 398 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
395 if( db->nVdbeActive==0 ){ 399 if( db->nVdbeActive==0 ){
396 db->u1.isInterrupted = 0; 400 db->u1.isInterrupted = 0;
397 } 401 }
398 pParse->rc = SQLITE_OK; 402 pParse->rc = SQLITE_OK;
399 pParse->zTail = zSql; 403 pParse->zTail = zSql;
400 i = 0; 404 i = 0;
401 assert( pzErrMsg!=0 ); 405 assert( pzErrMsg!=0 );
406 /* sqlite3ParserTrace(stdout, "parser: "); */
402 pEngine = sqlite3ParserAlloc(sqlite3Malloc); 407 pEngine = sqlite3ParserAlloc(sqlite3Malloc);
403 if( pEngine==0 ){ 408 if( pEngine==0 ){
404 db->mallocFailed = 1; 409 db->mallocFailed = 1;
405 return SQLITE_NOMEM; 410 return SQLITE_NOMEM;
406 } 411 }
407 assert( pParse->pNewTable==0 ); 412 assert( pParse->pNewTable==0 );
408 assert( pParse->pNewTrigger==0 ); 413 assert( pParse->pNewTrigger==0 );
409 assert( pParse->nVar==0 ); 414 assert( pParse->nVar==0 );
410 assert( pParse->nzVar==0 ); 415 assert( pParse->nzVar==0 );
411 assert( pParse->azVar==0 ); 416 assert( pParse->azVar==0 );
412 enableLookaside = db->lookaside.bEnabled; 417 enableLookaside = db->lookaside.bEnabled;
413 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1; 418 if( db->lookaside.pStart ) db->lookaside.bEnabled = 1;
414 while( !db->mallocFailed && zSql[i]!=0 ){ 419 while( zSql[i]!=0 ){
415 assert( i>=0 ); 420 assert( i>=0 );
416 pParse->sLastToken.z = &zSql[i]; 421 pParse->sLastToken.z = &zSql[i];
417 pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType); 422 pParse->sLastToken.n = sqlite3GetToken((unsigned char*)&zSql[i],&tokenType);
418 i += pParse->sLastToken.n; 423 i += pParse->sLastToken.n;
419 if( i>mxSqlLen ){ 424 if( i>mxSqlLen ){
420 pParse->rc = SQLITE_TOOBIG; 425 pParse->rc = SQLITE_TOOBIG;
421 break; 426 break;
422 } 427 }
423 switch( tokenType ){ 428 if( tokenType>=TK_SPACE ){
424 case TK_SPACE: { 429 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
425 if( db->u1.isInterrupted ){ 430 if( db->u1.isInterrupted ){
426 sqlite3ErrorMsg(pParse, "interrupt"); 431 sqlite3ErrorMsg(pParse, "interrupt");
427 pParse->rc = SQLITE_INTERRUPT; 432 pParse->rc = SQLITE_INTERRUPT;
428 goto abort_parse;
429 }
430 break; 433 break;
431 } 434 }
432 case TK_ILLEGAL: { 435 if( tokenType==TK_ILLEGAL ){
433 sqlite3DbFree(db, *pzErrMsg); 436 sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
434 *pzErrMsg = sqlite3MPrintf(db, "unrecognized token: \"%T\"",
435 &pParse->sLastToken); 437 &pParse->sLastToken);
436 nErr++;
437 goto abort_parse;
438 }
439 case TK_SEMI: {
440 pParse->zTail = &zSql[i];
441 /* Fall thru into the default case */
442 }
443 default: {
444 sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
445 lastTokenParsed = tokenType;
446 if( pParse->rc!=SQLITE_OK ){
447 goto abort_parse;
448 }
449 break; 438 break;
450 } 439 }
440 }else{
441 if( tokenType==TK_SEMI ) pParse->zTail = &zSql[i];
442 sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
443 lastTokenParsed = tokenType;
444 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
451 } 445 }
452 } 446 }
453 abort_parse: 447 assert( nErr==0 );
454 if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){ 448 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
449 assert( zSql[i]==0 );
455 if( lastTokenParsed!=TK_SEMI ){ 450 if( lastTokenParsed!=TK_SEMI ){
456 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse); 451 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
457 pParse->zTail = &zSql[i]; 452 pParse->zTail = &zSql[i];
458 } 453 }
459 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse); 454 if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
455 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
456 }
460 } 457 }
461 #ifdef YYTRACKMAXSTACKDEPTH 458 #ifdef YYTRACKMAXSTACKDEPTH
462 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK, 459 sqlite3_mutex_enter(sqlite3MallocMutex());
460 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
463 sqlite3ParserStackPeak(pEngine) 461 sqlite3ParserStackPeak(pEngine)
464 ); 462 );
463 sqlite3_mutex_leave(sqlite3MallocMutex());
465 #endif /* YYDEBUG */ 464 #endif /* YYDEBUG */
466 sqlite3ParserFree(pEngine, sqlite3_free); 465 sqlite3ParserFree(pEngine, sqlite3_free);
467 db->lookaside.bEnabled = enableLookaside; 466 db->lookaside.bEnabled = enableLookaside;
468 if( db->mallocFailed ){ 467 if( db->mallocFailed ){
469 pParse->rc = SQLITE_NOMEM; 468 pParse->rc = SQLITE_NOMEM;
470 } 469 }
471 if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ 470 if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
472 sqlite3SetString(&pParse->zErrMsg, db, "%s", sqlite3ErrStr(pParse->rc)); 471 pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
473 } 472 }
474 assert( pzErrMsg!=0 ); 473 assert( pzErrMsg!=0 );
475 if( pParse->zErrMsg ){ 474 if( pParse->zErrMsg ){
476 *pzErrMsg = pParse->zErrMsg; 475 *pzErrMsg = pParse->zErrMsg;
477 sqlite3_log(pParse->rc, "%s", *pzErrMsg); 476 sqlite3_log(pParse->rc, "%s", *pzErrMsg);
478 pParse->zErrMsg = 0; 477 pParse->zErrMsg = 0;
479 nErr++; 478 nErr++;
480 } 479 }
481 if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){ 480 if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){
482 sqlite3VdbeDelete(pParse->pVdbe); 481 sqlite3VdbeDelete(pParse->pVdbe);
(...skipping 11 matching lines...) Expand all
494 #endif 493 #endif
495 494
496 if( !IN_DECLARE_VTAB ){ 495 if( !IN_DECLARE_VTAB ){
497 /* If the pParse->declareVtab flag is set, do not delete any table 496 /* If the pParse->declareVtab flag is set, do not delete any table
498 ** structure built up in pParse->pNewTable. The calling code (see vtab.c) 497 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
499 ** will take responsibility for freeing the Table structure. 498 ** will take responsibility for freeing the Table structure.
500 */ 499 */
501 sqlite3DeleteTable(db, pParse->pNewTable); 500 sqlite3DeleteTable(db, pParse->pNewTable);
502 } 501 }
503 502
504 if( pParse->bFreeWith ) sqlite3WithDelete(db, pParse->pWith); 503 sqlite3WithDelete(db, pParse->pWithToFree);
505 sqlite3DeleteTrigger(db, pParse->pNewTrigger); 504 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
506 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]); 505 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
507 sqlite3DbFree(db, pParse->azVar); 506 sqlite3DbFree(db, pParse->azVar);
508 while( pParse->pAinc ){ 507 while( pParse->pAinc ){
509 AutoincInfo *p = pParse->pAinc; 508 AutoincInfo *p = pParse->pAinc;
510 pParse->pAinc = p->pNext; 509 pParse->pAinc = p->pNext;
511 sqlite3DbFree(db, p); 510 sqlite3DbFree(db, p);
512 } 511 }
513 while( pParse->pZombieTab ){ 512 while( pParse->pZombieTab ){
514 Table *p = pParse->pZombieTab; 513 Table *p = pParse->pZombieTab;
515 pParse->pZombieTab = p->pNextZombie; 514 pParse->pZombieTab = p->pNextZombie;
516 sqlite3DeleteTable(db, p); 515 sqlite3DeleteTable(db, p);
517 } 516 }
518 if( nErr>0 && pParse->rc==SQLITE_OK ){ 517 assert( nErr==0 || pParse->rc!=SQLITE_OK );
519 pParse->rc = SQLITE_ERROR;
520 }
521 return nErr; 518 return nErr;
522 } 519 }
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/threads.c ('k') | third_party/sqlite/sqlite-src-3100200/src/treeview.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698