2000-05-29 18:26:00 +04:00
|
|
|
/*
|
2001-09-16 04:13:26 +04:00
|
|
|
** 2001 September 15
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** The author disclaims copyright to this source code. In place of
|
|
|
|
** a legal notice, here is a blessing:
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** 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.
|
2000-05-29 18:26:00 +04:00
|
|
|
**
|
|
|
|
*************************************************************************
|
|
|
|
** 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.
|
|
|
|
**
|
2001-11-06 07:00:18 +03:00
|
|
|
** $Id: tokenize.c,v 1.32 2001/11/06 04:00:19 drh Exp $
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
|
|
|
#include "sqliteInt.h"
|
2001-10-09 08:19:46 +04:00
|
|
|
#include "os.h"
|
2000-05-29 18:26:00 +04:00
|
|
|
#include <ctype.h>
|
2000-05-30 17:44:19 +04:00
|
|
|
#include <stdlib.h>
|
2000-05-29 18:26:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** All the keywords of the SQL language are stored as in a hash
|
|
|
|
** table composed of instances of the following structure.
|
|
|
|
*/
|
|
|
|
typedef struct Keyword Keyword;
|
|
|
|
struct Keyword {
|
|
|
|
char *zName; /* The keyword name */
|
|
|
|
int len; /* Number of characters in the keyword */
|
|
|
|
int tokenType; /* The token value for this keyword */
|
|
|
|
Keyword *pNext; /* Next keyword with the same hash */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
** These are the keywords
|
|
|
|
*/
|
|
|
|
static Keyword aKeywordTable[] = {
|
2000-06-06 05:50:43 +04:00
|
|
|
{ "ALL", 0, TK_ALL, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "AND", 0, TK_AND, 0 },
|
|
|
|
{ "AS", 0, TK_AS, 0 },
|
|
|
|
{ "ASC", 0, TK_ASC, 0 },
|
2001-04-04 15:48:57 +04:00
|
|
|
{ "BEGIN", 0, TK_BEGIN, 0 },
|
2000-06-06 05:50:43 +04:00
|
|
|
{ "BETWEEN", 0, TK_BETWEEN, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "BY", 0, TK_BY, 0 },
|
|
|
|
{ "CHECK", 0, TK_CHECK, 0 },
|
2001-09-14 22:54:08 +04:00
|
|
|
{ "CLUSTER", 0, TK_CLUSTER, 0 },
|
2001-04-04 15:48:57 +04:00
|
|
|
{ "COMMIT", 0, TK_COMMIT, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "CONSTRAINT", 0, TK_CONSTRAINT, 0 },
|
2000-05-30 20:27:03 +04:00
|
|
|
{ "COPY", 0, TK_COPY, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "CREATE", 0, TK_CREATE, 0 },
|
|
|
|
{ "DEFAULT", 0, TK_DEFAULT, 0 },
|
|
|
|
{ "DELETE", 0, TK_DELETE, 0 },
|
2000-05-30 20:27:03 +04:00
|
|
|
{ "DELIMITERS", 0, TK_DELIMITERS, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "DESC", 0, TK_DESC, 0 },
|
2000-06-01 00:00:52 +04:00
|
|
|
{ "DISTINCT", 0, TK_DISTINCT, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "DROP", 0, TK_DROP, 0 },
|
2001-04-04 15:48:57 +04:00
|
|
|
{ "END", 0, TK_END, 0 },
|
2000-06-07 01:56:07 +04:00
|
|
|
{ "EXCEPT", 0, TK_EXCEPT, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "EXPLAIN", 0, TK_EXPLAIN, 0 },
|
|
|
|
{ "FROM", 0, TK_FROM, 0 },
|
2000-05-31 06:27:49 +04:00
|
|
|
{ "GLOB", 0, TK_GLOB, 0 },
|
2000-06-06 21:27:05 +04:00
|
|
|
{ "GROUP", 0, TK_GROUP, 0 },
|
|
|
|
{ "HAVING", 0, TK_HAVING, 0 },
|
2000-06-06 05:50:43 +04:00
|
|
|
{ "IN", 0, TK_IN, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "INDEX", 0, TK_INDEX, 0 },
|
|
|
|
{ "INSERT", 0, TK_INSERT, 0 },
|
2000-06-07 01:56:07 +04:00
|
|
|
{ "INTERSECT", 0, TK_INTERSECT, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "INTO", 0, TK_INTO, 0 },
|
|
|
|
{ "IS", 0, TK_IS, 0 },
|
|
|
|
{ "ISNULL", 0, TK_ISNULL, 0 },
|
|
|
|
{ "KEY", 0, TK_KEY, 0 },
|
2000-05-31 06:27:49 +04:00
|
|
|
{ "LIKE", 0, TK_LIKE, 0 },
|
2001-11-06 07:00:18 +03:00
|
|
|
{ "LIMIT", 0, TK_LIMIT, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "NOT", 0, TK_NOT, 0 },
|
|
|
|
{ "NOTNULL", 0, TK_NOTNULL, 0 },
|
|
|
|
{ "NULL", 0, TK_NULL, 0 },
|
2001-11-06 07:00:18 +03:00
|
|
|
{ "OFFSET", 0, TK_OFFSET, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "ON", 0, TK_ON, 0 },
|
|
|
|
{ "OR", 0, TK_OR, 0 },
|
|
|
|
{ "ORDER", 0, TK_ORDER, 0 },
|
2001-09-14 22:54:08 +04:00
|
|
|
{ "PRAGMA", 0, TK_PRAGMA, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "PRIMARY", 0, TK_PRIMARY, 0 },
|
2001-04-04 15:48:57 +04:00
|
|
|
{ "ROLLBACK", 0, TK_ROLLBACK, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "SELECT", 0, TK_SELECT, 0 },
|
|
|
|
{ "SET", 0, TK_SET, 0 },
|
|
|
|
{ "TABLE", 0, TK_TABLE, 0 },
|
2001-10-08 17:22:32 +04:00
|
|
|
{ "TEMP", 0, TK_TEMP, 0 },
|
|
|
|
{ "TEMPORARY", 0, TK_TEMP, 0 },
|
2001-04-04 15:48:57 +04:00
|
|
|
{ "TRANSACTION", 0, TK_TRANSACTION, 0 },
|
2000-06-07 01:56:07 +04:00
|
|
|
{ "UNION", 0, TK_UNION, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "UNIQUE", 0, TK_UNIQUE, 0 },
|
|
|
|
{ "UPDATE", 0, TK_UPDATE, 0 },
|
2000-05-30 20:27:03 +04:00
|
|
|
{ "USING", 0, TK_USING, 0 },
|
2000-05-31 06:27:49 +04:00
|
|
|
{ "VACUUM", 0, TK_VACUUM, 0 },
|
2000-05-29 18:26:00 +04:00
|
|
|
{ "VALUES", 0, TK_VALUES, 0 },
|
|
|
|
{ "WHERE", 0, TK_WHERE, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This is the hash table
|
|
|
|
*/
|
2001-04-11 18:28:42 +04:00
|
|
|
#define KEY_HASH_SIZE 71
|
2000-05-29 18:26:00 +04:00
|
|
|
static Keyword *apHashTable[KEY_HASH_SIZE];
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This function looks up an identifier to determine if it is a
|
|
|
|
** keyword. If it is a keyword, the token code of that keyword is
|
|
|
|
** returned. If the input is not a keyword, TK_ID is returned.
|
|
|
|
*/
|
|
|
|
static int sqliteKeywordCode(const char *z, int n){
|
|
|
|
int h;
|
|
|
|
Keyword *p;
|
|
|
|
if( aKeywordTable[0].len==0 ){
|
|
|
|
/* Initialize the keyword hash table */
|
2001-10-09 08:19:46 +04:00
|
|
|
sqliteOsEnterMutex();
|
|
|
|
if( aKeywordTable[0].len==0 ){
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
n = sizeof(aKeywordTable)/sizeof(aKeywordTable[0]);
|
|
|
|
for(i=0; i<n; i++){
|
|
|
|
aKeywordTable[i].len = strlen(aKeywordTable[i].zName);
|
|
|
|
h = sqliteHashNoCase(aKeywordTable[i].zName, aKeywordTable[i].len);
|
|
|
|
h %= KEY_HASH_SIZE;
|
|
|
|
aKeywordTable[i].pNext = apHashTable[h];
|
|
|
|
apHashTable[h] = &aKeywordTable[i];
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
2001-10-09 08:19:46 +04:00
|
|
|
sqliteOsLeaveMutex();
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
|
|
|
h = sqliteHashNoCase(z, n) % KEY_HASH_SIZE;
|
|
|
|
for(p=apHashTable[h]; p; p=p->pNext){
|
|
|
|
if( p->len==n && sqliteStrNICmp(p->zName, z, n)==0 ){
|
|
|
|
return p->tokenType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TK_ID;
|
|
|
|
}
|
|
|
|
|
2001-10-18 16:34:46 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** If X is a character that can be used in an identifier then
|
|
|
|
** isIdChar[X] will be 1. Otherwise isIdChar[X] will be 0.
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
*/
|
|
|
|
static const char isIdChar[] = {
|
|
|
|
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
|
|
|
|
0, 0, 0, 0, 0, 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 */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 8x */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 9x */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Ax */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Bx */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Cx */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Dx */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Ex */
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* Fx */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-05-29 18:26:00 +04:00
|
|
|
/*
|
|
|
|
** Return the length of the token that begins at z[0]. Return
|
|
|
|
** -1 if the token is (or might be) incomplete. Store the token
|
|
|
|
** type in *tokenType before returning.
|
|
|
|
*/
|
2001-10-18 16:34:46 +04:00
|
|
|
static int sqliteGetToken(const unsigned char *z, int *tokenType){
|
2000-05-29 18:26:00 +04:00
|
|
|
int i;
|
|
|
|
switch( *z ){
|
2000-08-09 21:17:25 +04:00
|
|
|
case ' ': case '\t': case '\n': case '\f': case '\r': {
|
2000-05-29 18:26:00 +04:00
|
|
|
for(i=1; z[i] && isspace(z[i]); i++){}
|
|
|
|
*tokenType = TK_SPACE;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
case '-': {
|
|
|
|
if( z[1]==0 ) return -1;
|
|
|
|
if( z[1]=='-' ){
|
|
|
|
for(i=2; z[i] && z[i]!='\n'; i++){}
|
|
|
|
*tokenType = TK_COMMENT;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
*tokenType = TK_MINUS;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case '(': {
|
|
|
|
*tokenType = TK_LP;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case ')': {
|
|
|
|
*tokenType = TK_RP;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case ';': {
|
|
|
|
*tokenType = TK_SEMI;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case '+': {
|
|
|
|
*tokenType = TK_PLUS;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case '*': {
|
|
|
|
*tokenType = TK_STAR;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case '/': {
|
|
|
|
*tokenType = TK_SLASH;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-10-13 06:59:08 +04:00
|
|
|
case '%': {
|
|
|
|
*tokenType = TK_REM;
|
|
|
|
return 1;
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
case '=': {
|
|
|
|
*tokenType = TK_EQ;
|
|
|
|
return 1 + (z[1]=='=');
|
|
|
|
}
|
|
|
|
case '<': {
|
|
|
|
if( z[1]=='=' ){
|
|
|
|
*tokenType = TK_LE;
|
|
|
|
return 2;
|
|
|
|
}else if( z[1]=='>' ){
|
|
|
|
*tokenType = TK_NE;
|
|
|
|
return 2;
|
2001-10-13 06:59:08 +04:00
|
|
|
}else if( z[1]=='<' ){
|
|
|
|
*tokenType = TK_LSHIFT;
|
|
|
|
return 2;
|
2000-05-29 18:26:00 +04:00
|
|
|
}else{
|
|
|
|
*tokenType = TK_LT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case '>': {
|
|
|
|
if( z[1]=='=' ){
|
|
|
|
*tokenType = TK_GE;
|
|
|
|
return 2;
|
2001-10-13 06:59:08 +04:00
|
|
|
}else if( z[1]=='>' ){
|
|
|
|
*tokenType = TK_RSHIFT;
|
|
|
|
return 2;
|
2000-05-29 18:26:00 +04:00
|
|
|
}else{
|
|
|
|
*tokenType = TK_GT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case '!': {
|
|
|
|
if( z[1]!='=' ){
|
|
|
|
*tokenType = TK_ILLEGAL;
|
2000-06-08 20:26:24 +04:00
|
|
|
return 2;
|
2000-05-29 18:26:00 +04:00
|
|
|
}else{
|
|
|
|
*tokenType = TK_NE;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
2000-06-17 00:51:26 +04:00
|
|
|
case '|': {
|
|
|
|
if( z[1]!='|' ){
|
2001-10-13 06:59:08 +04:00
|
|
|
*tokenType = TK_BITOR;
|
2000-06-17 00:51:26 +04:00
|
|
|
return 1;
|
|
|
|
}else{
|
|
|
|
*tokenType = TK_CONCAT;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
case ',': {
|
|
|
|
*tokenType = TK_COMMA;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-10-13 06:59:08 +04:00
|
|
|
case '&': {
|
|
|
|
*tokenType = TK_BITAND;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case '~': {
|
|
|
|
*tokenType = TK_BITNOT;
|
|
|
|
return 1;
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
case '\'': case '"': {
|
|
|
|
int delim = z[0];
|
|
|
|
for(i=1; z[i]; i++){
|
|
|
|
if( z[i]==delim ){
|
|
|
|
if( z[i+1]==delim ){
|
|
|
|
i++;
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( z[i] ) i++;
|
|
|
|
*tokenType = TK_STRING;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
case '.': {
|
|
|
|
if( !isdigit(z[1]) ){
|
|
|
|
*tokenType = TK_DOT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Fall thru into the next case */
|
|
|
|
}
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9': {
|
2000-06-08 20:26:24 +04:00
|
|
|
*tokenType = TK_INTEGER;
|
2000-05-29 18:26:00 +04:00
|
|
|
for(i=1; z[i] && isdigit(z[i]); i++){}
|
|
|
|
if( z[i]=='.' ){
|
|
|
|
i++;
|
|
|
|
while( z[i] && isdigit(z[i]) ){ i++; }
|
2000-06-08 20:26:24 +04:00
|
|
|
*tokenType = TK_FLOAT;
|
|
|
|
}
|
|
|
|
if( (z[i]=='e' || z[i]=='E') &&
|
2000-05-29 18:26:00 +04:00
|
|
|
( isdigit(z[i+1])
|
|
|
|
|| ((z[i+1]=='+' || z[i+1]=='-') && isdigit(z[i+2]))
|
|
|
|
)
|
2000-06-08 20:26:24 +04:00
|
|
|
){
|
|
|
|
i += 2;
|
|
|
|
while( z[i] && isdigit(z[i]) ){ i++; }
|
2000-05-29 18:26:00 +04:00
|
|
|
*tokenType = TK_FLOAT;
|
|
|
|
}else if( z[0]=='.' ){
|
|
|
|
*tokenType = TK_FLOAT;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2001-10-18 16:34:46 +04:00
|
|
|
default: {
|
|
|
|
if( !isIdChar[*z] ){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(i=1; isIdChar[z[i]]; i++){}
|
2001-10-19 20:44:56 +04:00
|
|
|
*tokenType = sqliteKeywordCode((char*)z, i);
|
2000-05-29 18:26:00 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*tokenType = TK_ILLEGAL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Run the parser on the given SQL string. The parser structure is
|
2001-09-16 04:13:26 +04:00
|
|
|
** passed in. An SQLITE_ status code is returned. If an error occurs
|
|
|
|
** and pzErrMsg!=NULL then an error message might be written into
|
|
|
|
** memory obtained from malloc() and *pzErrMsg made to point to that
|
|
|
|
** error message. Or maybe not.
|
2000-05-29 18:26:00 +04:00
|
|
|
*/
|
2001-11-04 21:32:46 +03:00
|
|
|
int sqliteRunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
|
2000-05-29 18:26:00 +04:00
|
|
|
int nErr = 0;
|
|
|
|
int i;
|
|
|
|
void *pEngine;
|
|
|
|
int once = 1;
|
2001-10-22 06:58:08 +04:00
|
|
|
sqlite *db = pParse->db;
|
2000-05-29 18:26:00 +04:00
|
|
|
extern void *sqliteParserAlloc(void*(*)(int));
|
|
|
|
extern void sqliteParserFree(void*, void(*)(void*));
|
2001-02-11 19:56:24 +03:00
|
|
|
extern int sqliteParser(void*, int, Token, Parse*);
|
2000-05-29 18:26:00 +04:00
|
|
|
|
2001-10-22 06:58:08 +04:00
|
|
|
db->flags &= ~SQLITE_Interrupt;
|
2000-10-17 02:06:40 +04:00
|
|
|
pParse->rc = SQLITE_OK;
|
2000-05-29 18:26:00 +04:00
|
|
|
i = 0;
|
2000-06-06 21:27:05 +04:00
|
|
|
sqliteParseInfoReset(pParse);
|
2000-05-30 20:27:03 +04:00
|
|
|
pEngine = sqliteParserAlloc((void*(*)(int))malloc);
|
2000-05-29 18:26:00 +04:00
|
|
|
if( pEngine==0 ){
|
|
|
|
sqliteSetString(pzErrMsg, "out of memory", 0);
|
|
|
|
return 1;
|
|
|
|
}
|
2001-04-11 18:28:42 +04:00
|
|
|
while( sqlite_malloc_failed==0 && nErr==0 && i>=0 && zSql[i]!=0 ){
|
2000-05-29 18:26:00 +04:00
|
|
|
int tokenType;
|
|
|
|
|
2001-10-22 06:58:08 +04:00
|
|
|
if( (db->flags & SQLITE_Interrupt)!=0 ){
|
2000-10-17 02:06:40 +04:00
|
|
|
pParse->rc = SQLITE_INTERRUPT;
|
|
|
|
sqliteSetString(pzErrMsg, "interrupt", 0);
|
|
|
|
break;
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
pParse->sLastToken.z = &zSql[i];
|
2001-10-18 16:34:46 +04:00
|
|
|
pParse->sLastToken.n = sqliteGetToken((unsigned char*)&zSql[i], &tokenType);
|
2000-05-29 18:26:00 +04:00
|
|
|
i += pParse->sLastToken.n;
|
|
|
|
if( once ){
|
|
|
|
pParse->sFirstToken = pParse->sLastToken;
|
|
|
|
once = 0;
|
|
|
|
}
|
|
|
|
switch( tokenType ){
|
|
|
|
case TK_SPACE:
|
|
|
|
case TK_COMMENT: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TK_ILLEGAL:
|
2000-06-08 20:26:24 +04:00
|
|
|
sqliteSetNString(pzErrMsg, "unrecognized token: \"", -1,
|
|
|
|
pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, 0);
|
2000-05-29 18:26:00 +04:00
|
|
|
nErr++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sqliteParser(pEngine, tokenType, pParse->sLastToken, pParse);
|
2000-06-08 17:36:40 +04:00
|
|
|
if( pParse->zErrMsg && pParse->sErrToken.z ){
|
2000-05-29 18:26:00 +04:00
|
|
|
sqliteSetNString(pzErrMsg, "near \"", -1,
|
|
|
|
pParse->sErrToken.z, pParse->sErrToken.n,
|
|
|
|
"\": ", -1,
|
|
|
|
pParse->zErrMsg, -1,
|
|
|
|
0);
|
|
|
|
nErr++;
|
2000-06-08 17:36:40 +04:00
|
|
|
sqliteFree(pParse->zErrMsg);
|
|
|
|
pParse->zErrMsg = 0;
|
2001-09-23 06:35:53 +04:00
|
|
|
}else if( pParse->rc!=SQLITE_OK ){
|
2001-10-22 06:58:08 +04:00
|
|
|
sqliteSetString(pzErrMsg, sqlite_error_string(pParse->rc), 0);
|
2001-09-23 06:35:53 +04:00
|
|
|
nErr++;
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-10-22 06:58:08 +04:00
|
|
|
if( nErr==0 && (db->flags & SQLITE_Interrupt)==0 ){
|
2000-05-29 18:26:00 +04:00
|
|
|
sqliteParser(pEngine, 0, pParse->sLastToken, pParse);
|
2000-06-08 17:36:40 +04:00
|
|
|
if( pParse->zErrMsg && pParse->sErrToken.z ){
|
2000-05-29 18:26:00 +04:00
|
|
|
sqliteSetNString(pzErrMsg, "near \"", -1,
|
|
|
|
pParse->sErrToken.z, pParse->sErrToken.n,
|
|
|
|
"\": ", -1,
|
|
|
|
pParse->zErrMsg, -1,
|
|
|
|
0);
|
|
|
|
nErr++;
|
2000-06-08 17:36:40 +04:00
|
|
|
sqliteFree(pParse->zErrMsg);
|
|
|
|
pParse->zErrMsg = 0;
|
2000-05-29 18:26:00 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-30 17:44:19 +04:00
|
|
|
sqliteParserFree(pEngine, free);
|
2000-05-29 18:26:00 +04:00
|
|
|
if( pParse->zErrMsg ){
|
|
|
|
if( pzErrMsg ){
|
2000-06-08 17:36:40 +04:00
|
|
|
sqliteFree(*pzErrMsg);
|
2000-05-29 18:26:00 +04:00
|
|
|
*pzErrMsg = pParse->zErrMsg;
|
|
|
|
}else{
|
|
|
|
sqliteFree(pParse->zErrMsg);
|
|
|
|
}
|
|
|
|
if( !nErr ) nErr++;
|
|
|
|
}
|
|
|
|
if( pParse->pVdbe ){
|
|
|
|
sqliteVdbeDelete(pParse->pVdbe);
|
|
|
|
pParse->pVdbe = 0;
|
|
|
|
}
|
|
|
|
if( pParse->pNewTable ){
|
|
|
|
sqliteDeleteTable(pParse->db, pParse->pNewTable);
|
|
|
|
pParse->pNewTable = 0;
|
|
|
|
}
|
2000-06-06 21:27:05 +04:00
|
|
|
sqliteParseInfoReset(pParse);
|
2000-10-17 02:06:40 +04:00
|
|
|
if( nErr>0 && pParse->rc==SQLITE_OK ){
|
|
|
|
pParse->rc = SQLITE_ERROR;
|
|
|
|
}
|
2000-05-29 18:26:00 +04:00
|
|
|
return nErr;
|
|
|
|
}
|