Class AntlrUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringnormalizeWhitespaceUnquoted(org.antlr.v4.runtime.ParserRuleContext ctx, org.antlr.v4.runtime.CommonTokenStream stream) Normalizes whitespace in SQL text while preserving quoted sections.static StringnormalizeWhitespaceUnquoted(org.antlr.v4.runtime.ParserRuleContext ctx, org.antlr.v4.runtime.CommonTokenStream stream, DatabaseType dbType) Normalizes whitespace in SQL text while preserving quoted sections.static voidremoveIntoStatements(org.antlr.v4.runtime.Parser parser) Removes INTO statements from SQL tokens that aren't part of PL/pgSQL INTO clauses.
-
Method Details
-
normalizeWhitespaceUnquoted
public static String normalizeWhitespaceUnquoted(org.antlr.v4.runtime.ParserRuleContext ctx, org.antlr.v4.runtime.CommonTokenStream stream) Normalizes whitespace in SQL text while preserving quoted sections. Uses PostgreSQL rules by default.- Parameters:
ctx- the parser rule context containing the tokensstream- token stream containing the tokens- Returns:
- normalized SQL string with proper whitespace
-
normalizeWhitespaceUnquoted
public static String normalizeWhitespaceUnquoted(org.antlr.v4.runtime.ParserRuleContext ctx, org.antlr.v4.runtime.CommonTokenStream stream, DatabaseType dbType) Normalizes whitespace in SQL text while preserving quoted sections. Applies database-specific formatting rules.- Parameters:
ctx- the parser rule context containing the tokensstream- token stream containing the tokensdbType- database type to determine specific formatting rules- Returns:
- normalized SQL string with proper whitespace
-
removeIntoStatements
public static void removeIntoStatements(org.antlr.v4.runtime.Parser parser) Removes INTO statements from SQL tokens that aren't part of PL/pgSQL INTO clauses. Handles special cases for INSERT INTO and IMPORT FOREIGN SCHEMA INTO.Because INTO is sometimes used in the main SQL grammar, we have to be careful not to take any such usage of INTO as a PL/pgSQL INTO clause. There are currently three such cases:
1. SELECT ... INTO. We don't care, we just override that with the PL/pgSQL definition.
2. INSERT INTO. This is relatively easy to recognize since the words must appear adjacently; but we can't assume INSERT starts the command, because it can appear in CREATE RULE or WITH. Unfortunately, INSERT is *not* fully reserved, so that means there is a chance of a false match, but it's not very likely.
3. IMPORT FOREIGN SCHEMA ... INTO. This is not allowed in CREATE RULE or WITH, so we just check for IMPORT as the command's first token. (If IMPORT FOREIGN SCHEMA returned data someone might wish to capture with an INTO-variables clause, we'd have to work much harder here.)
See pl_gram.y
-