Modified statement machine in sqlite3_complete() to return 0 on empty string.
Added/updated tests for same. Ticket 356c885b0b. FossilOrigin-Name: 76eca7295cf7df4bef013af6c8c37251300cd383
This commit is contained in:
parent
4e7b32f37f
commit
c7d526e92b
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
|||||||
C Fixed\ssome\sTCL\stest\scases\sto\swork\sif\sSQLITE_OMIT_TRIGGER\sis\sdefined.
|
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:12:52
|
D 2009-12-17T22:17:39
|
||||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||||
F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3
|
F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3
|
||||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||||
@ -113,7 +113,7 @@ F src/btree.h 7944a9dac59eb3e541aad45fd2747f1051e7c63d
|
|||||||
F src/btreeInt.h 54f4245decd0409ea52cf9aee422d3d761d7ac10
|
F src/btreeInt.h 54f4245decd0409ea52cf9aee422d3d761d7ac10
|
||||||
F src/build.c 5a18b6846e99cb923008a8c888d3fd520f0bea52
|
F src/build.c 5a18b6846e99cb923008a8c888d3fd520f0bea52
|
||||||
F src/callback.c 908f3e0172c3d4058f4ca0acd42c637c52e9669f
|
F src/callback.c 908f3e0172c3d4058f4ca0acd42c637c52e9669f
|
||||||
F src/complete.c 417df1ef5ea798532bb6290b0cc4265fef82980a
|
F src/complete.c 4c8a742c4a4a6d9c835912648f5c8f032ea36c7b
|
||||||
F src/date.c a79c0a8f219370b972e320741f995a3bef9df33f
|
F src/date.c a79c0a8f219370b972e320741f995a3bef9df33f
|
||||||
F src/delete.c 8b8afb9cd7783d573eae55a3f4208bc0637a2bb8
|
F src/delete.c 8b8afb9cd7783d573eae55a3f4208bc0637a2bb8
|
||||||
F src/expr.c 50385ed51f1cd7f1ab289629cd0f87d5b2fcca52
|
F src/expr.c 50385ed51f1cd7f1ab289629cd0f87d5b2fcca52
|
||||||
@ -468,7 +468,7 @@ F test/lock5.test 6b1f78f09ad1522843dad571b76b321e6f439bf7
|
|||||||
F test/lock6.test 862aa71e97b288d6b3f92ba3313f51bd0b003776
|
F test/lock6.test 862aa71e97b288d6b3f92ba3313f51bd0b003776
|
||||||
F test/lock7.test 64006c84c1c616657e237c7ad6532b765611cf64
|
F test/lock7.test 64006c84c1c616657e237c7ad6532b765611cf64
|
||||||
F test/lookaside.test 1dd350dc6dff015c47c07fcc5a727a72fc5bae02
|
F test/lookaside.test 1dd350dc6dff015c47c07fcc5a727a72fc5bae02
|
||||||
F test/main.test 347ab987f16167858781383427476b33dc69fdb7
|
F test/main.test 2be2352ac77ac5b238c6337a5469aeeef57677e6
|
||||||
F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9
|
F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9
|
||||||
F test/malloc.test d23580e15c33ee0353717129421b077541e910dc
|
F test/malloc.test d23580e15c33ee0353717129421b077541e910dc
|
||||||
F test/malloc3.test 4bc57f850b212f706f3e1b37c4eced1d5a727cd1
|
F test/malloc3.test 4bc57f850b212f706f3e1b37c4eced1d5a727cd1
|
||||||
@ -781,7 +781,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
P 29e3c8da1bd3971215036e5f5cfa5b25c6caa81f
|
P 85e3c73497d72d09becf728efe81041277ca1730
|
||||||
R 821d3650108711607e08c70b0cbff634
|
R 441a9b5eb3dd9b55570d6d08e1a1ee71
|
||||||
U shaneh
|
U shaneh
|
||||||
Z 39fa2349d7d22ddb3b872ed12521d5b0
|
Z 240b5a79be1f4714cd0b02c34f1cf679
|
||||||
|
@ -1 +1 @@
|
|||||||
85e3c73497d72d09becf728efe81041277ca1730
|
76eca7295cf7df4bef013af6c8c37251300cd383
|
@ -40,11 +40,13 @@ extern const char sqlite3IsEbcdicIdChar[];
|
|||||||
#define tkSEMI 0
|
#define tkSEMI 0
|
||||||
#define tkWS 1
|
#define tkWS 1
|
||||||
#define tkOTHER 2
|
#define tkOTHER 2
|
||||||
|
#ifndef SQLITE_OMIT_TRIGGER
|
||||||
#define tkEXPLAIN 3
|
#define tkEXPLAIN 3
|
||||||
#define tkCREATE 4
|
#define tkCREATE 4
|
||||||
#define tkTEMP 5
|
#define tkTEMP 5
|
||||||
#define tkTRIGGER 6
|
#define tkTRIGGER 6
|
||||||
#define tkEND 7
|
#define tkEND 7
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Return TRUE if the given SQL string ends in a semicolon.
|
** Return TRUE if the given SQL string ends in a semicolon.
|
||||||
@ -53,36 +55,38 @@ extern const char sqlite3IsEbcdicIdChar[];
|
|||||||
** Whenever the CREATE TRIGGER keywords are seen, the statement
|
** Whenever the CREATE TRIGGER keywords are seen, the statement
|
||||||
** must end with ";END;".
|
** 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
|
** returns 1 if it ends in the START state and 0 if it ends
|
||||||
** in any other state.
|
** 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.
|
** 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.
|
** 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
|
** statement, possibly preceeded by EXPLAIN and/or followed by
|
||||||
** TEMP or TEMPORARY
|
** 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.
|
** 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.
|
** 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.
|
** of a trigger difinition.
|
||||||
**
|
**
|
||||||
** Transitions between states above are determined by tokens extracted
|
** Transitions between states above are determined by tokens extracted
|
||||||
** from the input. The following tokens are significant:
|
** from the input. The following tokens are significant:
|
||||||
**
|
**
|
||||||
** (0) tkSEMI A semicolon.
|
** (0) tkSEMI A semicolon.
|
||||||
** (1) tkWS Whitespace
|
** (1) tkWS Whitespace.
|
||||||
** (2) tkOTHER Any other SQL token.
|
** (2) tkOTHER Any other SQL token.
|
||||||
** (3) tkEXPLAIN The "explain" keyword.
|
** (3) tkEXPLAIN The "explain" keyword.
|
||||||
** (4) tkCREATE The "create" keyword.
|
** (4) tkCREATE The "create" keyword.
|
||||||
@ -91,6 +95,7 @@ extern const char sqlite3IsEbcdicIdChar[];
|
|||||||
** (7) tkEND The "end" keyword.
|
** (7) tkEND The "end" keyword.
|
||||||
**
|
**
|
||||||
** Whitespace never causes a state transition and is always ignored.
|
** 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
|
** 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
|
** to recognize the end of a trigger can be omitted. All we have to do
|
||||||
@ -104,26 +109,28 @@ int sqlite3_complete(const char *zSql){
|
|||||||
/* A complex statement machine used to detect the end of a CREATE TRIGGER
|
/* A complex statement machine used to detect the end of a CREATE TRIGGER
|
||||||
** statement. This is the normal case.
|
** statement. This is the normal case.
|
||||||
*/
|
*/
|
||||||
static const u8 trans[7][8] = {
|
static const u8 trans[8][8] = {
|
||||||
/* Token: */
|
/* Token: */
|
||||||
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
|
/* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
|
||||||
/* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
|
/* 0 INVALID: */ { 1, 0, 2, 3, 4, 2, 2, 2, },
|
||||||
/* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
|
/* 1 START: */ { 1, 1, 2, 3, 4, 2, 2, 2, },
|
||||||
/* 2 EXPLAIN: */ { 0, 2, 2, 1, 3, 1, 1, 1, },
|
/* 2 NORMAL: */ { 1, 2, 2, 2, 2, 2, 2, 2, },
|
||||||
/* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
|
/* 3 EXPLAIN: */ { 1, 3, 3, 2, 4, 2, 2, 2, },
|
||||||
/* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
|
/* 4 CREATE: */ { 1, 4, 2, 2, 2, 4, 5, 2, },
|
||||||
/* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
|
/* 5 TRIGGER: */ { 6, 5, 5, 5, 5, 5, 5, 5, },
|
||||||
/* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
|
/* 6 SEMI: */ { 6, 6, 5, 5, 5, 5, 5, 7, },
|
||||||
|
/* 7 END: */ { 1, 7, 5, 5, 5, 5, 5, 5, },
|
||||||
};
|
};
|
||||||
#else
|
#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
|
** used to detect the end of a statement is much simplier
|
||||||
*/
|
*/
|
||||||
static const u8 trans[2][3] = {
|
static const u8 trans[3][3] = {
|
||||||
/* Token: */
|
/* Token: */
|
||||||
/* State: ** SEMI WS OTHER */
|
/* State: ** SEMI WS OTHER */
|
||||||
/* 0 START: */ { 0, 0, 1, },
|
/* 0 INVALID: */ { 1, 0, 2, },
|
||||||
/* 1 NORMAL: */ { 0, 1, 1, },
|
/* 1 START: */ { 1, 1, 2, },
|
||||||
|
/* 2 NORMAL: */ { 1, 2, 2, },
|
||||||
};
|
};
|
||||||
#endif /* SQLITE_OMIT_TRIGGER */
|
#endif /* SQLITE_OMIT_TRIGGER */
|
||||||
|
|
||||||
@ -159,7 +166,7 @@ int sqlite3_complete(const char *zSql){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while( *zSql && *zSql!='\n' ){ zSql++; }
|
while( *zSql && *zSql!='\n' ){ zSql++; }
|
||||||
if( *zSql==0 ) return state==0;
|
if( *zSql==0 ) return state==1;
|
||||||
token = tkWS;
|
token = tkWS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -243,7 +250,7 @@ int sqlite3_complete(const char *zSql){
|
|||||||
state = trans[state][token];
|
state = trans[state][token];
|
||||||
zSql++;
|
zSql++;
|
||||||
}
|
}
|
||||||
return state==0;
|
return state==1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SQLITE_OMIT_UTF16
|
#ifndef SQLITE_OMIT_UTF16
|
||||||
|
@ -25,21 +25,40 @@ ifcapable {complete} {
|
|||||||
do_test main-1.1 {
|
do_test main-1.1 {
|
||||||
db complete {This is a test}
|
db complete {This is a test}
|
||||||
} {0}
|
} {0}
|
||||||
do_test main-1.2 {
|
do_test main-1.2.0 {
|
||||||
db complete {
|
db complete {
|
||||||
}
|
}
|
||||||
} {1}
|
} {0}
|
||||||
do_test main-1.3 {
|
do_test main-1.2.1 {
|
||||||
|
db complete {}
|
||||||
|
} {0}
|
||||||
|
do_test main-1.3.0 {
|
||||||
db complete {
|
db complete {
|
||||||
-- a comment ;
|
-- a comment ;
|
||||||
}
|
}
|
||||||
} {1}
|
} {0}
|
||||||
do_test main-1.4 {
|
do_test main-1.3.1 {
|
||||||
|
db complete {
|
||||||
|
/* a comment ; */
|
||||||
|
}
|
||||||
|
} {0}
|
||||||
|
do_test main-1.4.0 {
|
||||||
db complete {
|
db complete {
|
||||||
-- a comment ;
|
-- a comment ;
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} {1}
|
} {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 {
|
do_test main-1.5 {
|
||||||
db complete {DROP TABLE 'xyz;}
|
db complete {DROP TABLE 'xyz;}
|
||||||
} {0}
|
} {0}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user