Skip to content

Commit

Permalink
SQL: distinguish user defined PL/SQL inquiry directives (ccflags) and…
Browse files Browse the repository at this point in the history
… PostgreSQL dollar quoted strings

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed May 9, 2021
1 parent 5c2ca01 commit 293050e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ demo_pkg1.test_var1 input-1.sql /^test_var1 varchar2(64) := $$PLSQL_UNIT_OWNER;$
test_var1 input-1.sql /^test_var1 varchar2(64) := $$PLSQL_UNIT_OWNER;$/;" v package:demo_pkg1
demo_pkg1.test_func1 input-1.sql /^function test_func1 return varchar2$/;" f package:demo_pkg1
test_func1 input-1.sql /^function test_func1 return varchar2$/;" f package:demo_pkg1
Some_Flag input-2.sql /^PLSQL_CCFlags = 'Some_Flag:1, PLSQL_CCFlags:99'$/;" C
foo input-2.sql /^CREATE TABLE foo($/;" t
foo.col input-2.sql /^ col text$/;" E table:foo
col input-2.sql /^ col text$/;" E table:foo
11 changes: 11 additions & 0 deletions Units/parser-sql.r/sql-plsql-inquiry-directive.d/input-2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER SESSION SET
PLSQL_CCFlags = 'Some_Flag:1, PLSQL_CCFlags:99'
/
BEGIN
DBMS_OUTPUT.PUT_LINE($$Some_Flag);
END;
/

CREATE TABLE foo(
col text
);
14 changes: 11 additions & 3 deletions parsers/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ static void parseIdentifier (vString *const string, const int firstChar)
ungetcToInputFile (c); /* unget non-identifier character */
}

static bool isCCFlag(const char *str)
{
return (anyKindEntryInScope(CORK_NIL, str, SQLTAG_PLSQL_CCFLAGS) != 0);
}

/* Parse a PostgreSQL: dollar-quoted string
* https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING
*
Expand Down Expand Up @@ -687,8 +692,9 @@ static tokenType parseDollarQuote (vString *const string, const int delimiter)
{
vStringPut (string, c);
if (empty_tag
&& KEYWORD_inquiry_directive == lookupCaseKeyword (vStringValue (string),
Lang_sql))
&& (KEYWORD_inquiry_directive == lookupCaseKeyword (vStringValue (string),
Lang_sql)
|| isCCFlag(vStringValue (string))))
{
/* PL/SQL inquiry directives */
int c0 = getcFromInputFile ();
Expand Down Expand Up @@ -2753,7 +2759,8 @@ static void parseCCFLAGS (tokenInfo *const token)
if (lookupCaseKeyword(vStringValue(ccflag), Lang_sql)
!= KEYWORD_inquiry_directive)
{
makeSimpleTag(ccflag, SQLTAG_PLSQL_CCFLAGS);
int index = makeSimpleTag(ccflag, SQLTAG_PLSQL_CCFLAGS);
registerEntry(index);
vStringClear(ccflag);
in_var = false;
}
Expand Down Expand Up @@ -2857,5 +2864,6 @@ extern parserDefinition* SqlParser (void)
def->initialize = initialize;
def->keywordTable = SqlKeywordTable;
def->keywordCount = ARRAY_SIZE (SqlKeywordTable);
def->useCork = CORK_QUEUE | CORK_SYMTAB;
return def;
}

0 comments on commit 293050e

Please sign in to comment.