Skip to content

Commit

Permalink
Compute the correct column name even if the column identifier is the
Browse files Browse the repository at this point in the history
very last token in the SQL statement.  This fixes a problem introduced
by check-in [0fdf97efe5df745510c6b] and reported by the community during
beta-testing.
  • Loading branch information
D. Richard Hipp committed Jan 10, 2018
1 parent 505cfdd commit 65479e8
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ void sqlite3CreateView(
** the end.
*/
sEnd = pParse->sLastToken;
assert( sEnd.z[0]!=0 );
assert( sEnd.z[0]!=0 || sEnd.n==0 );
if( sEnd.z[0]!=';' ){
sEnd.z += sEnd.n;
}
Expand Down
7 changes: 5 additions & 2 deletions src/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
//
%syntax_error {
UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */
assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
if( TOKEN.z[0] ){
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
}else{
sqlite3ErrorMsg(pParse, "incomplete input");
}
}
%stack_overflow {
sqlite3ErrorMsg(pParse, "parser stack overflow");
Expand Down
2 changes: 1 addition & 1 deletion src/tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
}else{
tokenType = TK_SEMI;
}
zSql -= n;
n = 0;
}
if( tokenType>=TK_SPACE ){
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
Expand Down
2 changes: 1 addition & 1 deletion test/capi2.test
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ do_test capi2-3.2 {
sqlite3_prepare $DB {select bogus from } -1 TAIL
} msg]
lappend rc $msg $TAIL
} {1 {(1) near " ": syntax error} {}}
} {1 {(1) incomplete input} {}}
do_test capi2-3.3 {
set rc [catch {
sqlite3_prepare $DB {;;;;select bogus from sqlite_master} -1 TAIL
Expand Down
12 changes: 12 additions & 0 deletions test/capi3.test
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,18 @@ do_test capi3-5.33 {
sqlite3_finalize $STMT
} SQLITE_OK

# 2018-01-09: If a column is the last token if a string, the column name
# was not being set correctly, due to changes in check-in
# https://sqlite.org/src/info/0fdf97efe5df7455
#
# This problem was detected by the community during beta-testing.
#
do_test capi3-5.34 {
set STMT [sqlite3_prepare $DB {SELECT :a, :b} -1 TAIL]
sqlite3_column_count $STMT
} 2
check_header $STMT capi-5.35 {:a :b} {{} {}}
sqlite3_finalize $STMT

set ::ENC [execsql {pragma encoding}]
db close
Expand Down
4 changes: 2 additions & 2 deletions test/icu.test
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ ifcapable icu {
do_catchsql_test icu-5.4 {
SELECT 'abc' REGEXP 'a[abc]c.*'
} {0 1}
do_catchsql_test icu-5.4 {SELECT 'abc' REGEXP } {1 {near " ": syntax error}}
do_catchsql_test icu-5.5 {SELECT 'abc' REGEXP, 1} {1 {near ",": syntax error}}
do_catchsql_test icu-5.5 {SELECT 'abc' REGEXP } {1 {incomplete input}}
do_catchsql_test icu-5.6 {SELECT 'abc' REGEXP, 1} {1 {near ",": syntax error}}

do_malloc_test icu-6.10 -sqlbody {
SELECT upper(char(0xfb04,0xdf,0xfb04,0xe8,0xfb04));
Expand Down
4 changes: 2 additions & 2 deletions test/main.test
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ do_test main-3.2.28 {
} {0 246}
do_test main-3.2.29 {
catchsql {select 123/}
} {1 {near "/": syntax error}}
} {1 {incomplete input}}
do_test main-3.2.30 {
catchsql {select 123--5}
} {0 123}
Expand Down Expand Up @@ -467,7 +467,7 @@ do_test main-3.4 {
do_test main-3.5 {
set v [catch {execsql {create}} msg]
lappend v $msg
} {1 {near "create": syntax error}}
} {1 {incomplete input}}
do_test main-3.6 {
catchsql {SELECT 'abc' + #9}
} {1 {near "#9": syntax error}}
Expand Down
2 changes: 1 addition & 1 deletion test/select1.test
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ do_test select1-7.2 {
do_test select1-7.3 {
set v [catch {execsql {SELECT f1 FROM test1 as 'hi', test2 as}} msg]
lappend v $msg
} {1 {near "as": syntax error}}
} {1 {incomplete input}}
do_test select1-7.4 {
set v [catch {execsql {
SELECT f1 FROM test1 ORDER BY;
Expand Down
4 changes: 2 additions & 2 deletions test/shell3.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ do_test shell3-1.6 {
} {0 {}}
do_test shell3-1.7 {
catchcmd "foo.db \"CREATE TABLE\""
} {1 {Error: near "TABLE": syntax error}}
} {1 {Error: incomplete input}}

#----------------------------------------------------------------------------
# shell3-2.*: Basic tests for running SQL file from command line.
Expand Down Expand Up @@ -96,6 +96,6 @@ do_test shell3-2.6 {
} {0 {}}
do_test shell3-2.7 {
catchcmd "foo.db" "CREATE TABLE"
} {1 {Error: near line 1: near "TABLE": syntax error}}
} {1 {Error: near line 1: incomplete input}}

finish_test
2 changes: 1 addition & 1 deletion test/with2.test
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ do_catchsql_test 6.5 {

do_catchsql_test 6.6 {
WITH x AS (SELECT * FROM t1) DELETE FROM t2 WHERE
} {/1 {near .* syntax error}/}
} {1 {incomplete input}}

do_catchsql_test 6.7 {
WITH x AS (SELECT * FROM t1) DELETE FROM t2 WHRE 1;
Expand Down

0 comments on commit 65479e8

Please sign in to comment.