org.postgresql.core
Class Parser

java.lang.Object
  extended by org.postgresql.core.Parser

public class Parser
extends Object

Basic query parser infrastructure.

Author:
Michael Paesold (mpaesold@gmx.at)

Constructor Summary
Parser()
           
 
Method Summary
static boolean charTerminatesIdentifier(char c)
           
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)
           
static JdbcCallParseInfo modifyJdbcCall(String jdbcSql, boolean stdStrings, int serverVersion, int protocolVersion)
          Converts JDBC-specific callable statement escapes {@code { [?
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 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 List<NativeQuery> parseJdbcSql(String query, boolean standardConformingStrings, boolean withParameters, boolean splitStatements)
          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 int parseSingleQuotes(char[] query, int offset, boolean standardConformingStrings)
          Find the end of the single-quoted string starting at the given offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

public Parser()
Method Detail

parseJdbcSql

public static List<NativeQuery> parseJdbcSql(String query,
                                             boolean standardConformingStrings,
                                             boolean withParameters,
                                             boolean splitStatements)
Parses JDBC query into PostgreSQL's native format. Several queries might be given if separated by semicolon.

Parameters:
query - jdbc query to parse
standardConformingStrings - whether to allow backslashes to be used as escape characters in single quote literals
withParameters - whether to replace ?, ? with $1, $2, etc
splitStatements - whether to split statements by semicolon
Returns:
list of native queries

parseSingleQuotes

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.

Parameters:
query - query
offset - start offset
standardConformingStrings - standard conforming strings
Returns:
position of the end of the single-quoted string

parseDoubleQuotes

public 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.

Parameters:
query - query
offset - start offset
Returns:
position of the end of the double-quoted string

parseDollarQuotes

public 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.

Parameters:
query - query
offset - start offset
Returns:
offset of the ending dollar character

parseLineComment

public 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.

Parameters:
query - query
offset - start offset
Returns:
position of the first \r or \n character

parseBlockComment

public 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.

Parameters:
query - query
offset - start offset
Returns:
position of the last / character

isSpace

public static boolean isSpace(char c)
Parameters:
c - character
Returns:
true if the character is a whitespace character as defined in the backend's parser

isOperatorChar

public static boolean isOperatorChar(char c)
Parameters:
c - character
Returns:
true if the given character is a valid character for an operator in the backend's parser

isIdentifierStartChar

public static boolean isIdentifierStartChar(char c)
Checks if a character is valid as the start of an identifier.

Parameters:
c - the character to check
Returns:
true if valid as first character of an identifier; false if not

isIdentifierContChar

public static boolean isIdentifierContChar(char c)
Checks if a character is valid as the second or later character of an identifier.

Parameters:
c - the character to check
Returns:
true if valid as second or later character of an identifier; false if not

charTerminatesIdentifier

public static boolean charTerminatesIdentifier(char c)
Parameters:
c - character
Returns:
true if the character terminates an identifier

isDollarQuoteStartChar

public static boolean isDollarQuoteStartChar(char c)
Checks if a character is valid as the start of a dollar quoting tag.

Parameters:
c - the character to check
Returns:
true if valid as first character of a dollar quoting tag; false if not

isDollarQuoteContChar

public static boolean isDollarQuoteContChar(char c)
Checks if a character is valid as the second or later character of a dollar quoting tag.

Parameters:
c - the character to check
Returns:
true if valid as second or later character of a dollar quoting tag; false if not

modifyJdbcCall

public static JdbcCallParseInfo modifyJdbcCall(String jdbcSql,
                                               boolean stdStrings,
                                               int serverVersion,
                                               int protocolVersion)
                                        throws SQLException
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)

Parameters:
jdbcSql - sql text with JDBC escapes
stdStrings - if backslash in single quotes should be regular character or escape one
serverVersion - server version
protocolVersion - protocol version
Returns:
SQL in appropriate for given server format
Throws:
SQLException - if given SQL is malformed


Copyright © 2016 PostgreSQL Global Development Group. All rights reserved.