xref: /sqlite-3.40.0/src/tokenize.c (revision 9cfcf5d4)
175897234Sdrh /*
2b19a2bc6Sdrh ** 2001 September 15
375897234Sdrh **
4b19a2bc6Sdrh ** The author disclaims copyright to this source code.  In place of
5b19a2bc6Sdrh ** a legal notice, here is a blessing:
675897234Sdrh **
7b19a2bc6Sdrh **    May you do good and not evil.
8b19a2bc6Sdrh **    May you find forgiveness for yourself and forgive others.
9b19a2bc6Sdrh **    May you share freely, never taking more than you give.
1075897234Sdrh **
1175897234Sdrh *************************************************************************
1275897234Sdrh ** An tokenizer for SQL
1375897234Sdrh **
1475897234Sdrh ** This file contains C code that splits an SQL input string up into
1575897234Sdrh ** individual tokens and sends those tokens one-by-one over to the
1675897234Sdrh ** parser for analysis.
1775897234Sdrh **
18*9cfcf5d4Sdrh ** $Id: tokenize.c,v 1.33 2002/01/29 18:41:25 drh Exp $
1975897234Sdrh */
2075897234Sdrh #include "sqliteInt.h"
21ad75e987Sdrh #include "os.h"
2275897234Sdrh #include <ctype.h>
23dcc581ccSdrh #include <stdlib.h>
2475897234Sdrh 
2575897234Sdrh /*
2675897234Sdrh ** All the keywords of the SQL language are stored as in a hash
2775897234Sdrh ** table composed of instances of the following structure.
2875897234Sdrh */
2975897234Sdrh typedef struct Keyword Keyword;
3075897234Sdrh struct Keyword {
3175897234Sdrh   char *zName;             /* The keyword name */
3275897234Sdrh   int len;                 /* Number of characters in the keyword */
3375897234Sdrh   int tokenType;           /* The token value for this keyword */
3475897234Sdrh   Keyword *pNext;          /* Next keyword with the same hash */
3575897234Sdrh };
3675897234Sdrh 
3775897234Sdrh /*
3875897234Sdrh ** These are the keywords
3975897234Sdrh */
4075897234Sdrh static Keyword aKeywordTable[] = {
41*9cfcf5d4Sdrh   { "ABORT",             0, TK_ABORT,            0 },
42fef5208cSdrh   { "ALL",               0, TK_ALL,              0 },
4375897234Sdrh   { "AND",               0, TK_AND,              0 },
4475897234Sdrh   { "AS",                0, TK_AS,               0 },
4575897234Sdrh   { "ASC",               0, TK_ASC,              0 },
46c4a3c779Sdrh   { "BEGIN",             0, TK_BEGIN,            0 },
47fef5208cSdrh   { "BETWEEN",           0, TK_BETWEEN,          0 },
4875897234Sdrh   { "BY",                0, TK_BY,               0 },
4975897234Sdrh   { "CHECK",             0, TK_CHECK,            0 },
50f57b14a6Sdrh   { "CLUSTER",           0, TK_CLUSTER,          0 },
51c4a3c779Sdrh   { "COMMIT",            0, TK_COMMIT,           0 },
52*9cfcf5d4Sdrh   { "CONFLICT",          0, TK_CONFLICT,         0 },
5375897234Sdrh   { "CONSTRAINT",        0, TK_CONSTRAINT,       0 },
54982cef7eSdrh   { "COPY",              0, TK_COPY,             0 },
5575897234Sdrh   { "CREATE",            0, TK_CREATE,           0 },
5675897234Sdrh   { "DEFAULT",           0, TK_DEFAULT,          0 },
5775897234Sdrh   { "DELETE",            0, TK_DELETE,           0 },
58982cef7eSdrh   { "DELIMITERS",        0, TK_DELIMITERS,       0 },
5975897234Sdrh   { "DESC",              0, TK_DESC,             0 },
60efb7251dSdrh   { "DISTINCT",          0, TK_DISTINCT,         0 },
6175897234Sdrh   { "DROP",              0, TK_DROP,             0 },
62c4a3c779Sdrh   { "END",               0, TK_END,              0 },
6382c3d636Sdrh   { "EXCEPT",            0, TK_EXCEPT,           0 },
6475897234Sdrh   { "EXPLAIN",           0, TK_EXPLAIN,          0 },
6575897234Sdrh   { "FROM",              0, TK_FROM,             0 },
66dce2cbe6Sdrh   { "GLOB",              0, TK_GLOB,             0 },
672282792aSdrh   { "GROUP",             0, TK_GROUP,            0 },
682282792aSdrh   { "HAVING",            0, TK_HAVING,           0 },
69*9cfcf5d4Sdrh   { "IGNORE",            0, TK_IGNORE,           0 },
70fef5208cSdrh   { "IN",                0, TK_IN,               0 },
7175897234Sdrh   { "INDEX",             0, TK_INDEX,            0 },
7275897234Sdrh   { "INSERT",            0, TK_INSERT,           0 },
7382c3d636Sdrh   { "INTERSECT",         0, TK_INTERSECT,        0 },
7475897234Sdrh   { "INTO",              0, TK_INTO,             0 },
7575897234Sdrh   { "IS",                0, TK_IS,               0 },
7675897234Sdrh   { "ISNULL",            0, TK_ISNULL,           0 },
7775897234Sdrh   { "KEY",               0, TK_KEY,              0 },
78dce2cbe6Sdrh   { "LIKE",              0, TK_LIKE,             0 },
799bbca4c1Sdrh   { "LIMIT",             0, TK_LIMIT,            0 },
8075897234Sdrh   { "NOT",               0, TK_NOT,              0 },
8175897234Sdrh   { "NOTNULL",           0, TK_NOTNULL,          0 },
8275897234Sdrh   { "NULL",              0, TK_NULL,             0 },
839bbca4c1Sdrh   { "OFFSET",            0, TK_OFFSET,           0 },
8475897234Sdrh   { "ON",                0, TK_ON,               0 },
8575897234Sdrh   { "OR",                0, TK_OR,               0 },
8675897234Sdrh   { "ORDER",             0, TK_ORDER,            0 },
87f57b14a6Sdrh   { "PRAGMA",            0, TK_PRAGMA,           0 },
8875897234Sdrh   { "PRIMARY",           0, TK_PRIMARY,          0 },
89*9cfcf5d4Sdrh   { "REPLACE",           0, TK_REPLACE,          0 },
90c4a3c779Sdrh   { "ROLLBACK",          0, TK_ROLLBACK,         0 },
9175897234Sdrh   { "SELECT",            0, TK_SELECT,           0 },
9275897234Sdrh   { "SET",               0, TK_SET,              0 },
9375897234Sdrh   { "TABLE",             0, TK_TABLE,            0 },
94f57b3399Sdrh   { "TEMP",              0, TK_TEMP,             0 },
95f57b3399Sdrh   { "TEMPORARY",         0, TK_TEMP,             0 },
96c4a3c779Sdrh   { "TRANSACTION",       0, TK_TRANSACTION,      0 },
9782c3d636Sdrh   { "UNION",             0, TK_UNION,            0 },
9875897234Sdrh   { "UNIQUE",            0, TK_UNIQUE,           0 },
9975897234Sdrh   { "UPDATE",            0, TK_UPDATE,           0 },
100982cef7eSdrh   { "USING",             0, TK_USING,            0 },
101dce2cbe6Sdrh   { "VACUUM",            0, TK_VACUUM,           0 },
10275897234Sdrh   { "VALUES",            0, TK_VALUES,           0 },
10375897234Sdrh   { "WHERE",             0, TK_WHERE,            0 },
10475897234Sdrh };
10575897234Sdrh 
10675897234Sdrh /*
10775897234Sdrh ** This is the hash table
10875897234Sdrh */
109daffd0e5Sdrh #define KEY_HASH_SIZE 71
11075897234Sdrh static Keyword *apHashTable[KEY_HASH_SIZE];
11175897234Sdrh 
11275897234Sdrh 
11375897234Sdrh /*
11475897234Sdrh ** This function looks up an identifier to determine if it is a
11575897234Sdrh ** keyword.  If it is a keyword, the token code of that keyword is
11675897234Sdrh ** returned.  If the input is not a keyword, TK_ID is returned.
11775897234Sdrh */
11875897234Sdrh static int sqliteKeywordCode(const char *z, int n){
11975897234Sdrh   int h;
12075897234Sdrh   Keyword *p;
12175897234Sdrh   if( aKeywordTable[0].len==0 ){
12275897234Sdrh     /* Initialize the keyword hash table */
123ad75e987Sdrh     sqliteOsEnterMutex();
124ad75e987Sdrh     if( aKeywordTable[0].len==0 ){
12575897234Sdrh       int i;
12675897234Sdrh       int n;
12775897234Sdrh       n = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
12875897234Sdrh       for(i=0; i<n; i++){
12975897234Sdrh         aKeywordTable[i].len = strlen(aKeywordTable[i].zName);
13075897234Sdrh         h = sqliteHashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
13175897234Sdrh         h %= KEY_HASH_SIZE;
13275897234Sdrh         aKeywordTable[i].pNext = apHashTable[h];
13375897234Sdrh         apHashTable[h] = &aKeywordTable[i];
13475897234Sdrh       }
13575897234Sdrh     }
136ad75e987Sdrh     sqliteOsLeaveMutex();
137ad75e987Sdrh   }
13875897234Sdrh   h = sqliteHashNoCase(z, n) % KEY_HASH_SIZE;
13975897234Sdrh   for(p=apHashTable[h]; p; p=p->pNext){
14075897234Sdrh     if( p->len==n && sqliteStrNICmp(p->zName, z, n)==0 ){
14175897234Sdrh       return p->tokenType;
14275897234Sdrh     }
14375897234Sdrh   }
14475897234Sdrh   return TK_ID;
14575897234Sdrh }
14675897234Sdrh 
14798808babSdrh 
14898808babSdrh /*
14998808babSdrh ** If X is a character that can be used in an identifier then
15098808babSdrh ** isIdChar[X] will be 1.  Otherwise isIdChar[X] will be 0.
15198808babSdrh **
15298808babSdrh ** In this implementation, an identifier can be a string of
15398808babSdrh ** alphabetic characters, digits, and "_" plus any character
15498808babSdrh ** with the high-order bit set.  The latter rule means that
15598808babSdrh ** any sequence of UTF-8 characters or characters taken from
15698808babSdrh ** an extended ISO8859 character set can form an identifier.
15798808babSdrh */
15898808babSdrh static const char isIdChar[] = {
15998808babSdrh /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
16098808babSdrh     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 0x */
16198808babSdrh     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 1x */
16298808babSdrh     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */
16398808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,  /* 3x */
16498808babSdrh     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 4x */
16598808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,  /* 5x */
16698808babSdrh     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 6x */
16798808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,  /* 7x */
16898808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 8x */
16998808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 9x */
17098808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Ax */
17198808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Bx */
17298808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Cx */
17398808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Dx */
17498808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Ex */
17598808babSdrh     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Fx */
17698808babSdrh };
17798808babSdrh 
17898808babSdrh 
17975897234Sdrh /*
18075897234Sdrh ** Return the length of the token that begins at z[0].  Return
18175897234Sdrh ** -1 if the token is (or might be) incomplete.  Store the token
18275897234Sdrh ** type in *tokenType before returning.
18375897234Sdrh */
18498808babSdrh static int sqliteGetToken(const unsigned char *z, int *tokenType){
18575897234Sdrh   int i;
18675897234Sdrh   switch( *z ){
18730cab809Sdrh     case ' ': case '\t': case '\n': case '\f': case '\r': {
18875897234Sdrh       for(i=1; z[i] && isspace(z[i]); i++){}
18975897234Sdrh       *tokenType = TK_SPACE;
19075897234Sdrh       return i;
19175897234Sdrh     }
19275897234Sdrh     case '-': {
19375897234Sdrh       if( z[1]==0 ) return -1;
19475897234Sdrh       if( z[1]=='-' ){
19575897234Sdrh         for(i=2; z[i] && z[i]!='\n'; i++){}
19675897234Sdrh         *tokenType = TK_COMMENT;
19775897234Sdrh         return i;
19875897234Sdrh       }
19975897234Sdrh       *tokenType = TK_MINUS;
20075897234Sdrh       return 1;
20175897234Sdrh     }
20275897234Sdrh     case '(': {
20375897234Sdrh       *tokenType = TK_LP;
20475897234Sdrh       return 1;
20575897234Sdrh     }
20675897234Sdrh     case ')': {
20775897234Sdrh       *tokenType = TK_RP;
20875897234Sdrh       return 1;
20975897234Sdrh     }
21075897234Sdrh     case ';': {
21175897234Sdrh       *tokenType = TK_SEMI;
21275897234Sdrh       return 1;
21375897234Sdrh     }
21475897234Sdrh     case '+': {
21575897234Sdrh       *tokenType = TK_PLUS;
21675897234Sdrh       return 1;
21775897234Sdrh     }
21875897234Sdrh     case '*': {
21975897234Sdrh       *tokenType = TK_STAR;
22075897234Sdrh       return 1;
22175897234Sdrh     }
22275897234Sdrh     case '/': {
22375897234Sdrh       *tokenType = TK_SLASH;
22475897234Sdrh       return 1;
22575897234Sdrh     }
226bf4133cbSdrh     case '%': {
227bf4133cbSdrh       *tokenType = TK_REM;
228bf4133cbSdrh       return 1;
229bf4133cbSdrh     }
23075897234Sdrh     case '=': {
23175897234Sdrh       *tokenType = TK_EQ;
23275897234Sdrh       return 1 + (z[1]=='=');
23375897234Sdrh     }
23475897234Sdrh     case '<': {
23575897234Sdrh       if( z[1]=='=' ){
23675897234Sdrh         *tokenType = TK_LE;
23775897234Sdrh         return 2;
23875897234Sdrh       }else if( z[1]=='>' ){
23975897234Sdrh         *tokenType = TK_NE;
24075897234Sdrh         return 2;
241bf4133cbSdrh       }else if( z[1]=='<' ){
242bf4133cbSdrh         *tokenType = TK_LSHIFT;
243bf4133cbSdrh         return 2;
24475897234Sdrh       }else{
24575897234Sdrh         *tokenType = TK_LT;
24675897234Sdrh         return 1;
24775897234Sdrh       }
24875897234Sdrh     }
24975897234Sdrh     case '>': {
25075897234Sdrh       if( z[1]=='=' ){
25175897234Sdrh         *tokenType = TK_GE;
25275897234Sdrh         return 2;
253bf4133cbSdrh       }else if( z[1]=='>' ){
254bf4133cbSdrh         *tokenType = TK_RSHIFT;
255bf4133cbSdrh         return 2;
25675897234Sdrh       }else{
25775897234Sdrh         *tokenType = TK_GT;
25875897234Sdrh         return 1;
25975897234Sdrh       }
26075897234Sdrh     }
26175897234Sdrh     case '!': {
26275897234Sdrh       if( z[1]!='=' ){
26375897234Sdrh         *tokenType = TK_ILLEGAL;
264c837e709Sdrh         return 2;
26575897234Sdrh       }else{
26675897234Sdrh         *tokenType = TK_NE;
26775897234Sdrh         return 2;
26875897234Sdrh       }
26975897234Sdrh     }
2700040077dSdrh     case '|': {
2710040077dSdrh       if( z[1]!='|' ){
272bf4133cbSdrh         *tokenType = TK_BITOR;
2730040077dSdrh         return 1;
2740040077dSdrh       }else{
2750040077dSdrh         *tokenType = TK_CONCAT;
2760040077dSdrh         return 2;
2770040077dSdrh       }
2780040077dSdrh     }
27975897234Sdrh     case ',': {
28075897234Sdrh       *tokenType = TK_COMMA;
28175897234Sdrh       return 1;
28275897234Sdrh     }
283bf4133cbSdrh     case '&': {
284bf4133cbSdrh       *tokenType = TK_BITAND;
285bf4133cbSdrh       return 1;
286bf4133cbSdrh     }
287bf4133cbSdrh     case '~': {
288bf4133cbSdrh       *tokenType = TK_BITNOT;
289bf4133cbSdrh       return 1;
290bf4133cbSdrh     }
29175897234Sdrh     case '\'': case '"': {
29275897234Sdrh       int delim = z[0];
29375897234Sdrh       for(i=1; z[i]; i++){
29475897234Sdrh         if( z[i]==delim ){
29575897234Sdrh           if( z[i+1]==delim ){
29675897234Sdrh             i++;
29775897234Sdrh           }else{
29875897234Sdrh             break;
29975897234Sdrh           }
30075897234Sdrh         }
30175897234Sdrh       }
30275897234Sdrh       if( z[i] ) i++;
30375897234Sdrh       *tokenType = TK_STRING;
30475897234Sdrh       return i;
30575897234Sdrh     }
30675897234Sdrh     case '.': {
30775897234Sdrh       if( !isdigit(z[1]) ){
30875897234Sdrh         *tokenType = TK_DOT;
30975897234Sdrh         return 1;
31075897234Sdrh       }
31175897234Sdrh       /* Fall thru into the next case */
31275897234Sdrh     }
31375897234Sdrh     case '0': case '1': case '2': case '3': case '4':
31475897234Sdrh     case '5': case '6': case '7': case '8': case '9': {
315c837e709Sdrh       *tokenType = TK_INTEGER;
31675897234Sdrh       for(i=1; z[i] && isdigit(z[i]); i++){}
31775897234Sdrh       if( z[i]=='.' ){
31875897234Sdrh         i++;
31975897234Sdrh         while( z[i] && isdigit(z[i]) ){ i++; }
320c837e709Sdrh         *tokenType = TK_FLOAT;
321c837e709Sdrh       }
32275897234Sdrh       if( (z[i]=='e' || z[i]=='E') &&
32375897234Sdrh            ( isdigit(z[i+1])
32475897234Sdrh             || ((z[i+1]=='+' || z[i+1]=='-') && isdigit(z[i+2]))
32575897234Sdrh            )
32675897234Sdrh       ){
32775897234Sdrh         i += 2;
32875897234Sdrh         while( z[i] && isdigit(z[i]) ){ i++; }
32975897234Sdrh         *tokenType = TK_FLOAT;
33075897234Sdrh       }else if( z[0]=='.' ){
33175897234Sdrh         *tokenType = TK_FLOAT;
33275897234Sdrh       }
33375897234Sdrh       return i;
33475897234Sdrh     }
33598808babSdrh     default: {
33698808babSdrh       if( !isIdChar[*z] ){
33798808babSdrh         break;
33898808babSdrh       }
33998808babSdrh       for(i=1; isIdChar[z[i]]; i++){}
3406a535340Sdrh       *tokenType = sqliteKeywordCode((char*)z, i);
34175897234Sdrh       return i;
34275897234Sdrh     }
34375897234Sdrh   }
34475897234Sdrh   *tokenType = TK_ILLEGAL;
34575897234Sdrh   return 1;
34675897234Sdrh }
34775897234Sdrh 
34875897234Sdrh /*
34975897234Sdrh ** Run the parser on the given SQL string.  The parser structure is
350b19a2bc6Sdrh ** passed in.  An SQLITE_ status code is returned.  If an error occurs
351b19a2bc6Sdrh ** and pzErrMsg!=NULL then an error message might be written into
352b19a2bc6Sdrh ** memory obtained from malloc() and *pzErrMsg made to point to that
353b19a2bc6Sdrh ** error message.  Or maybe not.
35475897234Sdrh */
35580ff32f5Sdrh int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
35675897234Sdrh   int nErr = 0;
35775897234Sdrh   int i;
35875897234Sdrh   void *pEngine;
35975897234Sdrh   int once = 1;
3606d4abfbeSdrh   sqlite *db = pParse->db;
36175897234Sdrh   extern void *sqliteParserAlloc(void*(*)(int));
36275897234Sdrh   extern void sqliteParserFree(void*, void(*)(void*));
363338ea13cSdrh   extern int sqliteParser(void*, int, Token, Parse*);
36475897234Sdrh 
3656d4abfbeSdrh   db->flags &= ~SQLITE_Interrupt;
3664c504391Sdrh   pParse->rc = SQLITE_OK;
36775897234Sdrh   i = 0;
3682282792aSdrh   sqliteParseInfoReset(pParse);
369982cef7eSdrh   pEngine = sqliteParserAlloc((void*(*)(int))malloc);
37075897234Sdrh   if( pEngine==0 ){
37175897234Sdrh     sqliteSetString(pzErrMsg, "out of memory", 0);
37275897234Sdrh     return 1;
37375897234Sdrh   }
374daffd0e5Sdrh   while( sqlite_malloc_failed==0 && nErr==0 && i>=0 && zSql[i]!=0 ){
37575897234Sdrh     int tokenType;
37675897234Sdrh 
3776d4abfbeSdrh     if( (db->flags & SQLITE_Interrupt)!=0 ){
3784c504391Sdrh       pParse->rc = SQLITE_INTERRUPT;
3794c504391Sdrh       sqliteSetString(pzErrMsg, "interrupt", 0);
3804c504391Sdrh       break;
3814c504391Sdrh     }
38275897234Sdrh     pParse->sLastToken.z = &zSql[i];
38398808babSdrh     pParse->sLastToken.n = sqliteGetToken((unsigned char*)&zSql[i], &tokenType);
38475897234Sdrh     i += pParse->sLastToken.n;
38575897234Sdrh     if( once ){
38675897234Sdrh       pParse->sFirstToken = pParse->sLastToken;
38775897234Sdrh       once = 0;
38875897234Sdrh     }
38975897234Sdrh     switch( tokenType ){
39075897234Sdrh       case TK_SPACE:
39175897234Sdrh       case TK_COMMENT: {
39275897234Sdrh         break;
39375897234Sdrh       }
39475897234Sdrh       case TK_ILLEGAL:
395c837e709Sdrh         sqliteSetNString(pzErrMsg, "unrecognized token: \"", -1,
396c837e709Sdrh            pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, 0);
39775897234Sdrh         nErr++;
39875897234Sdrh         break;
39975897234Sdrh       default:
40075897234Sdrh         sqliteParser(pEngine, tokenType, pParse->sLastToken, pParse);
4016e142f54Sdrh         if( pParse->zErrMsg && pParse->sErrToken.z ){
40275897234Sdrh           sqliteSetNString(pzErrMsg, "near \"", -1,
40375897234Sdrh              pParse->sErrToken.z, pParse->sErrToken.n,
40475897234Sdrh              "\": ", -1,
40575897234Sdrh              pParse->zErrMsg, -1,
40675897234Sdrh              0);
40775897234Sdrh           nErr++;
4086e142f54Sdrh           sqliteFree(pParse->zErrMsg);
4096e142f54Sdrh           pParse->zErrMsg = 0;
410ecdc7530Sdrh         }else if( pParse->rc!=SQLITE_OK ){
4116d4abfbeSdrh           sqliteSetString(pzErrMsg, sqlite_error_string(pParse->rc), 0);
412ecdc7530Sdrh           nErr++;
41375897234Sdrh         }
41475897234Sdrh         break;
41575897234Sdrh     }
41675897234Sdrh   }
4176d4abfbeSdrh   if( nErr==0 && (db->flags & SQLITE_Interrupt)==0 ){
41875897234Sdrh     sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
4196e142f54Sdrh     if( pParse->zErrMsg && pParse->sErrToken.z ){
42075897234Sdrh        sqliteSetNString(pzErrMsg, "near \"", -1,
42175897234Sdrh           pParse->sErrToken.z, pParse->sErrToken.n,
42275897234Sdrh           "\": ", -1,
42375897234Sdrh           pParse->zErrMsg, -1,
42475897234Sdrh           0);
42575897234Sdrh        nErr++;
4266e142f54Sdrh        sqliteFree(pParse->zErrMsg);
4276e142f54Sdrh        pParse->zErrMsg = 0;
42875897234Sdrh     }
42975897234Sdrh   }
430dcc581ccSdrh   sqliteParserFree(pEngine, free);
43175897234Sdrh   if( pParse->zErrMsg ){
43275897234Sdrh     if( pzErrMsg ){
4336e142f54Sdrh       sqliteFree(*pzErrMsg);
43475897234Sdrh       *pzErrMsg = pParse->zErrMsg;
43575897234Sdrh     }else{
43675897234Sdrh       sqliteFree(pParse->zErrMsg);
43775897234Sdrh     }
43875897234Sdrh     if( !nErr ) nErr++;
43975897234Sdrh   }
44075897234Sdrh   if( pParse->pVdbe ){
44175897234Sdrh     sqliteVdbeDelete(pParse->pVdbe);
44275897234Sdrh     pParse->pVdbe = 0;
44375897234Sdrh   }
44475897234Sdrh   if( pParse->pNewTable ){
44575897234Sdrh     sqliteDeleteTable(pParse->db, pParse->pNewTable);
44675897234Sdrh     pParse->pNewTable = 0;
44775897234Sdrh   }
4482282792aSdrh   sqliteParseInfoReset(pParse);
4494c504391Sdrh   if( nErr>0 && pParse->rc==SQLITE_OK ){
4504c504391Sdrh     pParse->rc = SQLITE_ERROR;
4514c504391Sdrh   }
45275897234Sdrh   return nErr;
45375897234Sdrh }
454