public class Parser extends Object
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
static boolean |
charTerminatesIdentifier(char c) |
static int |
digitAt(String s,
int pos)
Converts digit at position
pos in string s to integer or throws. |
static boolean |
isArrayWhiteSpace(char c)
Identifies white space characters which the backend uses to determine if a
String value needs to be quoted in array representation. |
static boolean |
isDigitAt(String s,
int pos)
Returns true if a given string
s has digit at position pos . |
static boolean |
isDollarQuoteContChar(char c)
Checks if a character is valid as the second or later character of a dollar quoting tag.
|
static boolean |
isDollarQuoteStartChar(char c)
Checks if a character is valid as the start of a dollar quoting tag.
|
static boolean |
isIdentifierContChar(char c)
Checks if a character is valid as the second or later character of an identifier.
|
static boolean |
isIdentifierStartChar(char c)
Checks if a character is valid as the start of an identifier.
|
static boolean |
isOperatorChar(char c) |
static boolean |
isSpace(char c)
Identifies characters which the backend scanner considers to be whitespace.
|
static JdbcCallParseInfo |
modifyJdbcCall(String jdbcSql,
boolean stdStrings,
int serverVersion,
int protocolVersion,
EscapeSyntaxCallMode escapeSyntaxCallMode)
Converts JDBC-specific callable statement escapes
{ [? =] call <some_function> [(?,
[?,..])] } into the PostgreSQL format which is select <some_function> (?, [?, ...]) as
result or select * from <some_function> (?, [?, ...]) as result (7.3) |
static boolean |
parseAlterKeyword(char[] query,
int offset)
Parse string to check presence of CREATE keyword regardless of case.
|
static boolean |
parseAsKeyword(char[] query,
int offset)
Parse string to check presence of AS keyword regardless of case.
|
static int |
parseBlockComment(char[] query,
int offset)
Test if the
/ character at offset starts a block comment, and return the
position of the last / character. |
static boolean |
parseCreateKeyword(char[] query,
int offset)
Parse string to check presence of CREATE keyword regardless of case.
|
static boolean |
parseDeleteKeyword(char[] query,
int offset)
Parse string to check presence of DELETE keyword regardless of case.
|
static int |
parseDollarQuotes(char[] query,
int offset)
Test if the dollar character (
$ ) at the given offset starts a dollar-quoted string and
return the offset of the ending dollar character. |
static int |
parseDoubleQuotes(char[] query,
int offset)
Find the end of the double-quoted string starting at the given offset.
|
static boolean |
parseInsertKeyword(char[] query,
int offset)
Parse string to check presence of INSERT keyword regardless of case.
|
static List<NativeQuery> |
parseJdbcSql(String query,
boolean standardConformingStrings,
boolean withParameters,
boolean splitStatements,
boolean isBatchedReWriteConfigured,
boolean quoteReturningIdentifiers,
String... returningColumnNames)
Parses JDBC query into PostgreSQL's native format.
|
static int |
parseLineComment(char[] query,
int offset)
Test if the
- character at offset starts a -- style line comment,
and return the position of the first \r or \n character. |
static long |
parseLong(String s,
int beginIndex,
int endIndex)
Faster version of
Long.parseLong(String) when parsing a substring is required |
static boolean |
parseMoveKeyword(char[] query,
int offset)
Parse string to check presence of MOVE keyword regardless of case.
|
static boolean |
parseReturningKeyword(char[] query,
int offset)
Parse string to check presence of RETURNING keyword regardless of case.
|
static boolean |
parseSelectKeyword(char[] query,
int offset)
Parse string to check presence of SELECT keyword regardless of case.
|
static int |
parseSingleQuotes(char[] query,
int offset,
boolean standardConformingStrings)
Find the end of the single-quoted string starting at the given offset.
|
static boolean |
parseUpdateKeyword(char[] query,
int offset)
Parse string to check presence of UPDATE keyword regardless of case.
|
static boolean |
parseValuesKeyword(char[] query,
int offset)
Parse string to check presence of VALUES keyword regardless of case.
|
static boolean |
parseWithKeyword(char[] query,
int offset)
Parse string to check presence of WITH keyword regardless of case.
|
static String |
replaceProcessing(String sql,
boolean replaceProcessingEnabled,
boolean standardConformingStrings)
Filter the SQL string of Java SQL Escape clauses.
|
public static List<NativeQuery> parseJdbcSql(String query, boolean standardConformingStrings, boolean withParameters, boolean splitStatements, boolean isBatchedReWriteConfigured, boolean quoteReturningIdentifiers, String... returningColumnNames) throws SQLException
query
- jdbc query to parsestandardConformingStrings
- whether to allow backslashes to be used as escape characters
in single quote literalswithParameters
- whether to replace ?, ? with $1, $2, etcsplitStatements
- whether to split statements by semicolonisBatchedReWriteConfigured
- whether re-write optimization is enabledquoteReturningIdentifiers
- whether to quote identifiers returned using returning clausereturningColumnNames
- for simple insert, update, delete add returning with given column namesSQLException
- if unable to add returning clause (invalid column names)public static int parseSingleQuotes(char[] query, int offset, boolean standardConformingStrings)
Find the end of the single-quoted string starting at the given offset.
Note: for 'single '' quote in string'
, this method currently returns the offset of
first '
character after the initial one. The caller must call the method a second time
for the second part of the quoted string.
query
- queryoffset
- start offsetstandardConformingStrings
- standard conforming stringspublic static int parseDoubleQuotes(char[] query, int offset)
Find the end of the double-quoted string starting at the given offset.
Note: for "double "" quote in string"
, this method currently
returns the offset of first "
character after the initial one. The caller must
call the method a second time for the second part of the quoted string.
query
- queryoffset
- start offsetpublic static int parseDollarQuotes(char[] query, int offset)
$
) at the given offset starts a dollar-quoted string and
return the offset of the ending dollar character.query
- queryoffset
- start offsetpublic static int parseLineComment(char[] query, int offset)
-
character at offset
starts a --
style line comment,
and return the position of the first \r
or \n
character.query
- queryoffset
- start offset\r
or \n
characterpublic static int parseBlockComment(char[] query, int offset)
/
character at offset
starts a block comment, and return the
position of the last /
character.query
- queryoffset
- start offset/
characterpublic static boolean parseDeleteKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseInsertKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseMoveKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseReturningKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseSelectKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseAlterKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseCreateKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseUpdateKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseValuesKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static long parseLong(String s, int beginIndex, int endIndex)
Long.parseLong(String)
when parsing a substring is requireds
- string to parsebeginIndex
- begin indexendIndex
- end indexpublic static boolean parseWithKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean parseAsKeyword(char[] query, int offset)
query
- char[] of the query statementoffset
- position of query to start checkingpublic static boolean isDigitAt(String s, int pos)
s
has digit at position pos
.s
- input stringpos
- position (0-based)public static int digitAt(String s, int pos)
pos
in string s
to integer or throws.s
- input stringpos
- position (0-based)NumberFormatException
- if character at position pos is not an integerpublic static boolean isSpace(char c)
https://github.com/postgres/postgres/blob/17bb62501787c56e0518e61db13a523d47afd724/src/backend/parser/scan.l#L194-L198
c
- characterpublic static boolean isArrayWhiteSpace(char c)
String
value needs to be quoted in array representation.
https://github.com/postgres/postgres/blob/f2c587067a8eb9cf1c8f009262381a6576ba3dd0/src/backend/utils/adt/arrayfuncs.c#L421-L438
c
- Character to examine.public static boolean isOperatorChar(char c)
c
- characterpublic static boolean isIdentifierStartChar(char c)
c
- the character to checkpublic static boolean isIdentifierContChar(char c)
c
- the character to checkpublic static boolean charTerminatesIdentifier(char c)
c
- characterpublic static boolean isDollarQuoteStartChar(char c)
c
- the character to checkpublic static boolean isDollarQuoteContChar(char c)
c
- the character to checkpublic static JdbcCallParseInfo modifyJdbcCall(String jdbcSql, boolean stdStrings, int serverVersion, int protocolVersion, EscapeSyntaxCallMode escapeSyntaxCallMode) throws SQLException
{ [? =] call <some_function> [(?,
[?,..])] }
into the PostgreSQL format which is select <some_function> (?, [?, ...]) as
result
or select * from <some_function> (?, [?, ...]) as result
(7.3)jdbcSql
- sql text with JDBC escapesstdStrings
- if backslash in single quotes should be regular character or escape oneserverVersion
- server versionprotocolVersion
- protocol versionescapeSyntaxCallMode
- mode specifying whether JDBC escape call syntax is transformed into a CALL/SELECT statementSQLException
- if given SQL is malformedpublic static String replaceProcessing(String sql, boolean replaceProcessingEnabled, boolean standardConformingStrings) throws SQLException
Filter the SQL string of Java SQL Escape clauses.
Currently implemented Escape clauses are those mentioned in 11.3 in the specification. Basically we look through the sql string for {d xxx}, {t xxx}, {ts xxx}, {oj xxx} or {fn xxx} in non-string sql code. When we find them, we just strip the escape part leaving only the xxx part. So, something like "select * from x where d={d '2001-10-09'}" would return "select * from x where d= '2001-10-09'".
sql
- the original query textreplaceProcessingEnabled
- whether replace_processing_enabled is onstandardConformingStrings
- whether standard_conforming_strings is onSQLException
- if given SQL is wrongCopyright © 1997-2020 PostgreSQL Global Development Group. All Rights Reserved.