]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Modified statement machine in sqlite3_complete() to return 0 on empty string.
authorshaneh <shaneh@noemail.net>
Thu, 17 Dec 2009 22:17:38 +0000 (22:17 +0000)
committershaneh <shaneh@noemail.net>
Thu, 17 Dec 2009 22:17:38 +0000 (22:17 +0000)
Added/updated tests for same.  Ticket 356c885b0b.

FossilOrigin-Name: 76eca7295cf7df4bef013af6c8c37251300cd383

manifest
manifest.uuid
src/complete.c
test/main.test

index 717f10828b4e23232055518f5914c9de29631f77..3866dd541de3874f49e1ae18051f1466a85f6d3b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fixed\ssome\sTCL\stest\scases\sto\swork\sif\sSQLITE_OMIT_TRIGGER\sis\sdefined.
-D 2009-12-17T22:12:52
+C Modified\sstatement\smachine\sin\ssqlite3_complete()\sto\sreturn\s0\son\sempty\sstring.\s\s\nAdded/updated\stests\sfor\ssame.\s\sTicket\s356c885b0b.
+D 2009-12-17T22:17:39
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -113,7 +113,7 @@ F src/btree.h 7944a9dac59eb3e541aad45fd2747f1051e7c63d
 F src/btreeInt.h 54f4245decd0409ea52cf9aee422d3d761d7ac10
 F src/build.c 5a18b6846e99cb923008a8c888d3fd520f0bea52
 F src/callback.c 908f3e0172c3d4058f4ca0acd42c637c52e9669f
-F src/complete.c 417df1ef5ea798532bb6290b0cc4265fef82980a
+F src/complete.c 4c8a742c4a4a6d9c835912648f5c8f032ea36c7b
 F src/date.c a79c0a8f219370b972e320741f995a3bef9df33f
 F src/delete.c 8b8afb9cd7783d573eae55a3f4208bc0637a2bb8
 F src/expr.c 50385ed51f1cd7f1ab289629cd0f87d5b2fcca52
@@ -468,7 +468,7 @@ F test/lock5.test 6b1f78f09ad1522843dad571b76b321e6f439bf7
 F test/lock6.test 862aa71e97b288d6b3f92ba3313f51bd0b003776
 F test/lock7.test 64006c84c1c616657e237c7ad6532b765611cf64
 F test/lookaside.test 1dd350dc6dff015c47c07fcc5a727a72fc5bae02
-F test/main.test 347ab987f16167858781383427476b33dc69fdb7
+F test/main.test 2be2352ac77ac5b238c6337a5469aeeef57677e6
 F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9
 F test/malloc.test d23580e15c33ee0353717129421b077541e910dc
 F test/malloc3.test 4bc57f850b212f706f3e1b37c4eced1d5a727cd1
@@ -781,7 +781,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 29e3c8da1bd3971215036e5f5cfa5b25c6caa81f
-R 821d3650108711607e08c70b0cbff634
+P 85e3c73497d72d09becf728efe81041277ca1730
+R 441a9b5eb3dd9b55570d6d08e1a1ee71
 U shaneh
-Z 39fa2349d7d22ddb3b872ed12521d5b0
+Z 240b5a79be1f4714cd0b02c34f1cf679
index 0a06b84e1a502ce1fe7c86a0001360344d6d534b..437f90dc71ea51690a721175f6d1b10afee6c119 100644 (file)
@@ -1 +1 @@
-85e3c73497d72d09becf728efe81041277ca1730
\ No newline at end of file
+76eca7295cf7df4bef013af6c8c37251300cd383
\ No newline at end of file
index 0f7b1879e2d69c8f842e6695019b40974a68f9d4..9799a6ae3079abe941cc95110e9e5fdcd5afdc58 100644 (file)
-/*
-** 2001 September 15
-**
-** The author disclaims copyright to this source code.  In place of
-** a legal notice, here is a blessing:
-**
-**    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.
-**
-*************************************************************************
-** An tokenizer for SQL
-**
-** This file contains C code that implements the sqlite3_complete() API.
-** 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.
-*/
-#include "sqliteInt.h"
-#ifndef SQLITE_OMIT_COMPLETE
-
-/*
-** This is defined in tokenize.c.  We just have to import the definition.
-*/
-#ifndef SQLITE_AMALGAMATION
-#ifdef SQLITE_ASCII
-#define IdChar(C)  ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
-#endif
-#ifdef SQLITE_EBCDIC
-extern const char sqlite3IsEbcdicIdChar[];
-#define IdChar(C)  (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
-#endif
-#endif /* SQLITE_AMALGAMATION */
-
-
-/*
-** Token types used by the sqlite3_complete() routine.  See the header
-** comments on that procedure for additional information.
-*/
-#define tkSEMI    0
-#define tkWS      1
-#define tkOTHER   2
-#define tkEXPLAIN 3
-#define tkCREATE  4
-#define tkTEMP    5
-#define tkTRIGGER 6
-#define tkEND     7
-
-/*
-** Return TRUE if the given SQL string ends in a semicolon.
-**
-** Special handling is require for CREATE TRIGGER statements.
-** Whenever the CREATE TRIGGER keywords are seen, the statement
-** must end with ";END;".
-**
-** This implementation uses a state machine with 7 states:
-**
-**   (0) 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
-**                 semicolon.
-**
-**   (2) 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
-**                 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
-**                 ended by a semicolon, the keyword END, and another semicolon.
-**
-**   (5) 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
-**                 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
-**   (2) tkOTHER     Any other SQL token.
-**   (3) tkEXPLAIN   The "explain" keyword.
-**   (4) tkCREATE    The "create" keyword.
-**   (5) tkTEMP      The "temp" or "temporary" keyword.
-**   (6) tkTRIGGER   The "trigger" keyword.
-**   (7) tkEND       The "end" keyword.
-**
-** Whitespace never causes a state transition and is always ignored.
-**
-** 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
-** is look for a semicolon that is not part of an string or comment.
-*/
-int sqlite3_complete(const char *zSql){
-  u8 state = 0;   /* Current state, using numbers defined in header comment */
-  u8 token;       /* Value of the next token */
-
-#ifndef SQLITE_OMIT_TRIGGER
-  /* 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] = {
-                     /* 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,  },
-  };
-#else
-  /* If triggers are not suppored by this compile then the statement machine
-  ** used to detect the end of a statement is much simplier
-  */
-  static const u8 trans[2][3] = {
-                     /* Token:           */
-     /* State:       **  SEMI  WS  OTHER */
-     /* 0   START: */ {    0,  0,     1, },
-     /* 1  NORMAL: */ {    0,  1,     1, },
-  };
-#endif /* SQLITE_OMIT_TRIGGER */
-
-  while( *zSql ){
-    switch( *zSql ){
-      case ';': {  /* A semicolon */
-        token = tkSEMI;
-        break;
-      }
-      case ' ':
-      case '\r':
-      case '\t':
-      case '\n':
-      case '\f': {  /* White space is ignored */
-        token = tkWS;
-        break;
-      }
-      case '/': {   /* C-style comments */
-        if( zSql[1]!='*' ){
-          token = tkOTHER;
-          break;
-        }
-        zSql += 2;
-        while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
-        if( zSql[0]==0 ) return 0;
-        zSql++;
-        token = tkWS;
-        break;
-      }
-      case '-': {   /* SQL-style comments from "--" to end of line */
-        if( zSql[1]!='-' ){
-          token = tkOTHER;
-          break;
-        }
-        while( *zSql && *zSql!='\n' ){ zSql++; }
-        if( *zSql==0 ) return state==0;
-        token = tkWS;
-        break;
-      }
-      case '[': {   /* Microsoft-style identifiers in [...] */
-        zSql++;
-        while( *zSql && *zSql!=']' ){ zSql++; }
-        if( *zSql==0 ) return 0;
-        token = tkOTHER;
-        break;
-      }
-      case '`':     /* Grave-accent quoted symbols used by MySQL */
-      case '"':     /* single- and double-quoted strings */
-      case '\'': {
-        int c = *zSql;
-        zSql++;
-        while( *zSql && *zSql!=c ){ zSql++; }
-        if( *zSql==0 ) return 0;
-        token = tkOTHER;
-        break;
-      }
-      default: {
-#ifdef SQLITE_EBCDIC
-        unsigned char c;
-#endif
-        if( IdChar((u8)*zSql) ){
-          /* Keywords and unquoted identifiers */
-          int nId;
-          for(nId=1; IdChar(zSql[nId]); nId++){}
-#ifdef SQLITE_OMIT_TRIGGER
-          token = tkOTHER;
-#else
-          switch( *zSql ){
-            case 'c': case 'C': {
-              if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
-                token = tkCREATE;
-              }else{
-                token = tkOTHER;
-              }
-              break;
-            }
-            case 't': case 'T': {
-              if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
-                token = tkTRIGGER;
-              }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
-                token = tkTEMP;
-              }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
-                token = tkTEMP;
-              }else{
-                token = tkOTHER;
-              }
-              break;
-            }
-            case 'e':  case 'E': {
-              if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
-                token = tkEND;
-              }else
-#ifndef SQLITE_OMIT_EXPLAIN
-              if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
-                token = tkEXPLAIN;
-              }else
-#endif
-              {
-                token = tkOTHER;
-              }
-              break;
-            }
-            default: {
-              token = tkOTHER;
-              break;
-            }
-          }
-#endif /* SQLITE_OMIT_TRIGGER */
-          zSql += nId-1;
-        }else{
-          /* Operators and special symbols */
-          token = tkOTHER;
-        }
-        break;
-      }
-    }
-    state = trans[state][token];
-    zSql++;
-  }
-  return state==0;
-}
-
-#ifndef SQLITE_OMIT_UTF16
-/*
-** This routine is the same as the sqlite3_complete() routine described
-** above, except that the parameter is required to be UTF-16 encoded, not
-** UTF-8.
-*/
-int sqlite3_complete16(const void *zSql){
-  sqlite3_value *pVal;
-  char const *zSql8;
-  int rc = SQLITE_NOMEM;
-
-#ifndef SQLITE_OMIT_AUTOINIT
-  rc = sqlite3_initialize();
-  if( rc ) return rc;
-#endif
-  pVal = sqlite3ValueNew(0);
-  sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
-  zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
-  if( zSql8 ){
-    rc = sqlite3_complete(zSql8);
-  }else{
-    rc = SQLITE_NOMEM;
-  }
-  sqlite3ValueFree(pVal);
-  return sqlite3ApiExit(0, rc);
-}
-#endif /* SQLITE_OMIT_UTF16 */
-#endif /* SQLITE_OMIT_COMPLETE */
+/*\r
+** 2001 September 15\r
+**\r
+** The author disclaims copyright to this source code.  In place of\r
+** a legal notice, here is a blessing:\r
+**\r
+**    May you do good and not evil.\r
+**    May you find forgiveness for yourself and forgive others.\r
+**    May you share freely, never taking more than you give.\r
+**\r
+*************************************************************************\r
+** An tokenizer for SQL\r
+**\r
+** This file contains C code that implements the sqlite3_complete() API.\r
+** This code used to be part of the tokenizer.c source file.  But by\r
+** separating it out, the code will be automatically omitted from\r
+** static links that do not use it.\r
+*/\r
+#include "sqliteInt.h"\r
+#ifndef SQLITE_OMIT_COMPLETE\r
+\r
+/*\r
+** This is defined in tokenize.c.  We just have to import the definition.\r
+*/\r
+#ifndef SQLITE_AMALGAMATION\r
+#ifdef SQLITE_ASCII\r
+#define IdChar(C)  ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)\r
+#endif\r
+#ifdef SQLITE_EBCDIC\r
+extern const char sqlite3IsEbcdicIdChar[];\r
+#define IdChar(C)  (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))\r
+#endif\r
+#endif /* SQLITE_AMALGAMATION */\r
+\r
+\r
+/*\r
+** Token types used by the sqlite3_complete() routine.  See the header\r
+** comments on that procedure for additional information.\r
+*/\r
+#define tkSEMI    0\r
+#define tkWS      1\r
+#define tkOTHER   2\r
+#ifndef SQLITE_OMIT_TRIGGER\r
+#define tkEXPLAIN 3\r
+#define tkCREATE  4\r
+#define tkTEMP    5\r
+#define tkTRIGGER 6\r
+#define tkEND     7\r
+#endif\r
+\r
+/*\r
+** Return TRUE if the given SQL string ends in a semicolon.\r
+**\r
+** Special handling is require for CREATE TRIGGER statements.\r
+** Whenever the CREATE TRIGGER keywords are seen, the statement\r
+** must end with ";END;".\r
+**\r
+** This implementation uses a state machine with 8 states:\r
+**\r
+**   (0) INVALID   We have not yet seen a non-whitespace character.\r
+**\r
+**   (1) START     At the beginning or end of an SQL statement.  This routine\r
+**                 returns 1 if it ends in the START state and 0 if it ends\r
+**                 in any other state.\r
+**\r
+**   (2) NORMAL    We are in the middle of statement which ends with a single\r
+**                 semicolon.\r
+**\r
+**   (3) EXPLAIN   The keyword EXPLAIN has been seen at the beginning of \r
+**                 a statement.\r
+**\r
+**   (4) CREATE    The keyword CREATE has been seen at the beginning of a\r
+**                 statement, possibly preceeded by EXPLAIN and/or followed by\r
+**                 TEMP or TEMPORARY\r
+**\r
+**   (5) TRIGGER   We are in the middle of a trigger definition that must be\r
+**                 ended by a semicolon, the keyword END, and another semicolon.\r
+**\r
+**   (6) SEMI      We've seen the first semicolon in the ";END;" that occurs at\r
+**                 the end of a trigger definition.\r
+**\r
+**   (7) END       We've seen the ";END" of the ";END;" that occurs at the end\r
+**                 of a trigger difinition.\r
+**\r
+** Transitions between states above are determined by tokens extracted\r
+** from the input.  The following tokens are significant:\r
+**\r
+**   (0) tkSEMI      A semicolon.\r
+**   (1) tkWS        Whitespace.\r
+**   (2) tkOTHER     Any other SQL token.\r
+**   (3) tkEXPLAIN   The "explain" keyword.\r
+**   (4) tkCREATE    The "create" keyword.\r
+**   (5) tkTEMP      The "temp" or "temporary" keyword.\r
+**   (6) tkTRIGGER   The "trigger" keyword.\r
+**   (7) tkEND       The "end" keyword.\r
+**\r
+** Whitespace never causes a state transition and is always ignored.\r
+** This means that a SQL string of all whitespace is invalid.\r
+**\r
+** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed\r
+** to recognize the end of a trigger can be omitted.  All we have to do\r
+** is look for a semicolon that is not part of an string or comment.\r
+*/\r
+int sqlite3_complete(const char *zSql){\r
+  u8 state = 0;   /* Current state, using numbers defined in header comment */\r
+  u8 token;       /* Value of the next token */\r
+\r
+#ifndef SQLITE_OMIT_TRIGGER\r
+  /* A complex statement machine used to detect the end of a CREATE TRIGGER\r
+  ** statement.  This is the normal case.\r
+  */\r
+  static const u8 trans[8][8] = {\r
+                     /* Token:                                                */\r
+     /* State:       **  SEMI  WS  OTHER  EXPLAIN  CREATE  TEMP  TRIGGER  END */\r
+     /* 0 INVALID: */ {    1,  0,     2,       3,      4,    2,       2,   2, },\r
+     /* 1   START: */ {    1,  1,     2,       3,      4,    2,       2,   2, },\r
+     /* 2  NORMAL: */ {    1,  2,     2,       2,      2,    2,       2,   2, },\r
+     /* 3 EXPLAIN: */ {    1,  3,     3,       2,      4,    2,       2,   2, },\r
+     /* 4  CREATE: */ {    1,  4,     2,       2,      2,    4,       5,   2, },\r
+     /* 5 TRIGGER: */ {    6,  5,     5,       5,      5,    5,       5,   5, },\r
+     /* 6    SEMI: */ {    6,  6,     5,       5,      5,    5,       5,   7, },\r
+     /* 7     END: */ {    1,  7,     5,       5,      5,    5,       5,   5, },\r
+  };\r
+#else\r
+  /* If triggers are not supported by this compile then the statement machine\r
+  ** used to detect the end of a statement is much simplier\r
+  */\r
+  static const u8 trans[3][3] = {\r
+                     /* Token:           */\r
+     /* State:       **  SEMI  WS  OTHER */\r
+     /* 0 INVALID: */ {    1,  0,     2, },\r
+     /* 1   START: */ {    1,  1,     2, },\r
+     /* 2  NORMAL: */ {    1,  2,     2, },\r
+  };\r
+#endif /* SQLITE_OMIT_TRIGGER */\r
+\r
+  while( *zSql ){\r
+    switch( *zSql ){\r
+      case ';': {  /* A semicolon */\r
+        token = tkSEMI;\r
+        break;\r
+      }\r
+      case ' ':\r
+      case '\r':\r
+      case '\t':\r
+      case '\n':\r
+      case '\f': {  /* White space is ignored */\r
+        token = tkWS;\r
+        break;\r
+      }\r
+      case '/': {   /* C-style comments */\r
+        if( zSql[1]!='*' ){\r
+          token = tkOTHER;\r
+          break;\r
+        }\r
+        zSql += 2;\r
+        while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }\r
+        if( zSql[0]==0 ) return 0;\r
+        zSql++;\r
+        token = tkWS;\r
+        break;\r
+      }\r
+      case '-': {   /* SQL-style comments from "--" to end of line */\r
+        if( zSql[1]!='-' ){\r
+          token = tkOTHER;\r
+          break;\r
+        }\r
+        while( *zSql && *zSql!='\n' ){ zSql++; }\r
+        if( *zSql==0 ) return state==1;\r
+        token = tkWS;\r
+        break;\r
+      }\r
+      case '[': {   /* Microsoft-style identifiers in [...] */\r
+        zSql++;\r
+        while( *zSql && *zSql!=']' ){ zSql++; }\r
+        if( *zSql==0 ) return 0;\r
+        token = tkOTHER;\r
+        break;\r
+      }\r
+      case '`':     /* Grave-accent quoted symbols used by MySQL */\r
+      case '"':     /* single- and double-quoted strings */\r
+      case '\'': {\r
+        int c = *zSql;\r
+        zSql++;\r
+        while( *zSql && *zSql!=c ){ zSql++; }\r
+        if( *zSql==0 ) return 0;\r
+        token = tkOTHER;\r
+        break;\r
+      }\r
+      default: {\r
+#ifdef SQLITE_EBCDIC\r
+        unsigned char c;\r
+#endif\r
+        if( IdChar((u8)*zSql) ){\r
+          /* Keywords and unquoted identifiers */\r
+          int nId;\r
+          for(nId=1; IdChar(zSql[nId]); nId++){}\r
+#ifdef SQLITE_OMIT_TRIGGER\r
+          token = tkOTHER;\r
+#else\r
+          switch( *zSql ){\r
+            case 'c': case 'C': {\r
+              if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){\r
+                token = tkCREATE;\r
+              }else{\r
+                token = tkOTHER;\r
+              }\r
+              break;\r
+            }\r
+            case 't': case 'T': {\r
+              if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){\r
+                token = tkTRIGGER;\r
+              }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){\r
+                token = tkTEMP;\r
+              }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){\r
+                token = tkTEMP;\r
+              }else{\r
+                token = tkOTHER;\r
+              }\r
+              break;\r
+            }\r
+            case 'e':  case 'E': {\r
+              if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){\r
+                token = tkEND;\r
+              }else\r
+#ifndef SQLITE_OMIT_EXPLAIN\r
+              if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){\r
+                token = tkEXPLAIN;\r
+              }else\r
+#endif\r
+              {\r
+                token = tkOTHER;\r
+              }\r
+              break;\r
+            }\r
+            default: {\r
+              token = tkOTHER;\r
+              break;\r
+            }\r
+          }\r
+#endif /* SQLITE_OMIT_TRIGGER */\r
+          zSql += nId-1;\r
+        }else{\r
+          /* Operators and special symbols */\r
+          token = tkOTHER;\r
+        }\r
+        break;\r
+      }\r
+    }\r
+    state = trans[state][token];\r
+    zSql++;\r
+  }\r
+  return state==1;\r
+}\r
+\r
+#ifndef SQLITE_OMIT_UTF16\r
+/*\r
+** This routine is the same as the sqlite3_complete() routine described\r
+** above, except that the parameter is required to be UTF-16 encoded, not\r
+** UTF-8.\r
+*/\r
+int sqlite3_complete16(const void *zSql){\r
+  sqlite3_value *pVal;\r
+  char const *zSql8;\r
+  int rc = SQLITE_NOMEM;\r
+\r
+#ifndef SQLITE_OMIT_AUTOINIT\r
+  rc = sqlite3_initialize();\r
+  if( rc ) return rc;\r
+#endif\r
+  pVal = sqlite3ValueNew(0);\r
+  sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);\r
+  zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);\r
+  if( zSql8 ){\r
+    rc = sqlite3_complete(zSql8);\r
+  }else{\r
+    rc = SQLITE_NOMEM;\r
+  }\r
+  sqlite3ValueFree(pVal);\r
+  return sqlite3ApiExit(0, rc);\r
+}\r
+#endif /* SQLITE_OMIT_UTF16 */\r
+#endif /* SQLITE_OMIT_COMPLETE */\r
index 12262c1c5132555b22d34b9affc4dc058a5d35b9..6248e11bb2dbfff3308db40cbb72a3f3ff428d8b 100644 (file)
@@ -25,21 +25,40 @@ ifcapable {complete} {
 do_test main-1.1 {
   db complete {This is a test}
 } {0}
-do_test main-1.2 {
+do_test main-1.2.0 {
   db complete {
   }
-} {1}
-do_test main-1.3 {
+} {0}
+do_test main-1.2.1 {
+  db complete {}
+} {0}
+do_test main-1.3.0 {
   db complete {
      -- a comment ;
   }
-} {1}
-do_test main-1.4 {
+} {0}
+do_test main-1.3.1 {
+  db complete {
+     /* a comment ; */
+  }
+} {0}
+do_test main-1.4.0 {
   db complete {
      -- a comment ;
      ;
   }
 } {1}
+do_test main-1.4.1 {
+  db complete {
+     /* a comment ; */
+     ;
+  }
+} {1}
+do_test main-1.4.2 {
+  db complete {
+     /* a comment ; */ ;
+  }
+} {1}
 do_test main-1.5 {
   db complete {DROP TABLE 'xyz;}
 } {0}