Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: handle "DATABASE" and "SCHEMA" keywords specially only when they come after "CREATE" #3674

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tmain/sql-null-tag-warning-2.d/input.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER DATABASE :"datname" REFRESH COLLATION VERSION;
12 changes: 12 additions & 0 deletions Tmain/sql-null-tag-warning-2.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright: 2023 Masatake YAMATO
# License: GPL-2

. ../utils.sh

CTAGS=$1

V=
# V=valgrind

echo '# no warning should be printed' 1>&2
$CTAGS --quiet --options=NONE -o - input.sql
1 change: 1 addition & 0 deletions Tmain/sql-null-tag-warning-2.d/stderr-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no warning should be printed
Empty file.
19 changes: 13 additions & 6 deletions parsers/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static struct SqlReservedWord SqlReservedWord [SQLKEYWORD_COUNT] = {
static void parseBlock (tokenInfo *const token, const bool local);
static void parseBlockFull (tokenInfo *const token, const bool local, langType lang);
static void parseDeclare (tokenInfo *const token, const bool local);
static void parseKeywords (tokenInfo *const token);
static void parseKeywords (tokenInfo *const token, enum eKeywordId precedingKeyword);
static tokenType parseSqlFile (tokenInfo *const token);

/*
Expand Down Expand Up @@ -1914,7 +1914,7 @@ static void parseStatements (tokenInfo *const token, const bool exit_on_endif )

case KEYWORD_create:
readToken (token);
parseKeywords(token);
parseKeywords(token, KEYWORD_create);
break;

case KEYWORD_declare:
Expand Down Expand Up @@ -3095,7 +3095,7 @@ static void parseDatabase (tokenInfo *const token, enum eKeywordId keyword)
findCmdTerm (token, true);
}

static void parseKeywords (tokenInfo *const token)
static void parseKeywords (tokenInfo *const token, enum eKeywordId precedingKeyword)
{
switch (token->keyword)
{
Expand All @@ -3106,7 +3106,10 @@ static void parseKeywords (tokenInfo *const token)
break;
case KEYWORD_comment: parseComment (token); break;
case KEYWORD_cursor: parseSimple (token, SQLTAG_CURSOR); break;
case KEYWORD_database: parseDatabase (token, KEYWORD_database); break;
case KEYWORD_database:
if (precedingKeyword == KEYWORD_create)
parseDatabase (token, KEYWORD_database);
break;
case KEYWORD_datatype: parseDomain (token); break;
case KEYWORD_declare: parseBlock (token, false); break;
case KEYWORD_domain: parseDomain (token); break;
Expand All @@ -3130,7 +3133,10 @@ static void parseKeywords (tokenInfo *const token)
case KEYWORD_package: parsePackage (token); break;
case KEYWORD_procedure: parseSubProgram (token); break;
case KEYWORD_publication: parsePublication (token); break;
case KEYWORD_schema: parseDatabase (token, KEYWORD_schema); break;
case KEYWORD_schema:
if (precedingKeyword == KEYWORD_create)
parseDatabase (token, KEYWORD_schema);
break;
case KEYWORD_service: parseService (token); break;
case KEYWORD_subtype: parseSimple (token, SQLTAG_SUBTYPE); break;
case KEYWORD_synonym: parseSynonym (token); break;
Expand All @@ -3149,12 +3155,13 @@ static tokenType parseSqlFile (tokenInfo *const token)
{
do
{
enum eKeywordId k = token->keyword;
readToken (token);

if (isType (token, TOKEN_BLOCK_LABEL_BEGIN))
parseLabel (token);
else
parseKeywords (token);
parseKeywords (token, k);
} while (! isKeyword (token, KEYWORD_end) &&
! isType (token, TOKEN_EOF));

Expand Down