Index: third_party/sqlite/src/src/complete.c |
diff --git a/third_party/sqlite/src/src/complete.c b/third_party/sqlite/src/src/complete.c |
index 8993cfd455410a74c27b025c0474a3cda7ebf845..9e9140085c0046ed3bf6f4485220692dca1743c5 100644 |
--- a/third_party/sqlite/src/src/complete.c |
+++ b/third_party/sqlite/src/src/complete.c |
@@ -15,8 +15,6 @@ |
** 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.8 2009/04/28 04:46:42 drh Exp $ |
*/ |
#include "sqliteInt.h" |
#ifndef SQLITE_OMIT_COMPLETE |
@@ -26,8 +24,7 @@ |
*/ |
#ifndef SQLITE_AMALGAMATION |
#ifdef SQLITE_ASCII |
-extern const char sqlite3IsAsciiIdChar[]; |
-#define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsAsciiIdChar[c-0x20])) |
+#define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0) |
#endif |
#ifdef SQLITE_EBCDIC |
extern const char sqlite3IsEbcdicIdChar[]; |
@@ -43,11 +40,13 @@ extern const char sqlite3IsEbcdicIdChar[]; |
#define tkSEMI 0 |
#define tkWS 1 |
#define tkOTHER 2 |
+#ifndef SQLITE_OMIT_TRIGGER |
#define tkEXPLAIN 3 |
#define tkCREATE 4 |
#define tkTEMP 5 |
#define tkTRIGGER 6 |
#define tkEND 7 |
+#endif |
/* |
** Return TRUE if the given SQL string ends in a semicolon. |
@@ -56,36 +55,38 @@ extern const char sqlite3IsEbcdicIdChar[]; |
** Whenever the CREATE TRIGGER keywords are seen, the statement |
** must end with ";END;". |
** |
-** This implementation uses a state machine with 7 states: |
+** This implementation uses a state machine with 8 states: |
** |
-** (0) START At the beginning or end of an SQL statement. This routine |
+** (0) INVALID We have not yet seen a non-whitespace character. |
+** |
+** (1) 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 |
+** (2) 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 |
+** (3) 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 |
+** (4) 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 |
+** (5) 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 |
+** (6) 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 |
+** (7) 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 |
+** (1) tkWS Whitespace. |
** (2) tkOTHER Any other SQL token. |
** (3) tkEXPLAIN The "explain" keyword. |
** (4) tkCREATE The "create" keyword. |
@@ -94,6 +95,7 @@ extern const char sqlite3IsEbcdicIdChar[]; |
** (7) tkEND The "end" keyword. |
** |
** Whitespace never causes a state transition and is always ignored. |
+** This means that a SQL string of all whitespace is invalid. |
** |
** 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 |
@@ -107,26 +109,28 @@ int sqlite3_complete(const char *zSql){ |
/* 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] = { |
+ static const u8 trans[8][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, 2, 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, }, |
+ /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */ |
+ /* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, }, |
+ /* 1 START: */ { 1, 1, 2, 3, 4, 2, 2, 2, }, |
+ /* 2 NORMAL: */ { 1, 2, 2, 2, 2, 2, 2, 2, }, |
+ /* 3 EXPLAIN: */ { 1, 3, 3, 2, 4, 2, 2, 2, }, |
+ /* 4 CREATE: */ { 1, 4, 2, 2, 2, 4, 5, 2, }, |
+ /* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, }, |
+ /* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, }, |
+ /* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, }, |
}; |
#else |
- /* If triggers are not suppored by this compile then the statement machine |
+ /* If triggers are not supported by this compile then the statement machine |
** used to detect the end of a statement is much simplier |
*/ |
- static const u8 trans[2][3] = { |
+ static const u8 trans[3][3] = { |
/* Token: */ |
/* State: ** SEMI WS OTHER */ |
- /* 0 START: */ { 0, 0, 1, }, |
- /* 1 NORMAL: */ { 0, 1, 1, }, |
+ /* 0 INVALID: */ { 1, 0, 2, }, |
+ /* 1 START: */ { 1, 1, 2, }, |
+ /* 2 NORMAL: */ { 1, 2, 2, }, |
}; |
#endif /* SQLITE_OMIT_TRIGGER */ |
@@ -162,7 +166,7 @@ int sqlite3_complete(const char *zSql){ |
break; |
} |
while( *zSql && *zSql!='\n' ){ zSql++; } |
- if( *zSql==0 ) return state==0; |
+ if( *zSql==0 ) return state==1; |
token = tkWS; |
break; |
} |
@@ -184,7 +188,9 @@ int sqlite3_complete(const char *zSql){ |
break; |
} |
default: { |
- int c; |
+#ifdef SQLITE_EBCDIC |
+ unsigned char c; |
+#endif |
if( IdChar((u8)*zSql) ){ |
/* Keywords and unquoted identifiers */ |
int nId; |
@@ -244,7 +250,7 @@ int sqlite3_complete(const char *zSql){ |
state = trans[state][token]; |
zSql++; |
} |
- return state==0; |
+ return state==1; |
} |
#ifndef SQLITE_OMIT_UTF16 |