org.firebirdsql.jdbc
Class FBEscapedParser

java.lang.Object
  extended by org.firebirdsql.jdbc.FBEscapedParser

public class FBEscapedParser
extends java.lang.Object

The class FBEscapedParser parses the SQL and converts escaped syntax to native form.

Version:
1.0
Author:
Roman Rokytskyy

Field Summary
static java.lang.String ESCAPE_CALL_KEYWORD
           
static java.lang.String ESCAPE_CALL_KEYWORD3
           
static java.lang.String ESCAPE_DATE_KEYWORD
           
static java.lang.String ESCAPE_ESCAPE_KEYWORD
           
static java.lang.String ESCAPE_FUNCTION_KEYWORD
           
static java.lang.String ESCAPE_OUTERJOIN_KEYWORS
           
protected static int ESCAPE_STATE
           
static java.lang.String ESCAPE_TIME_KEYWORD
           
static java.lang.String ESCAPE_TIMESTAMP_KEYWORD
           
protected static int LITERAL_STATE
           
protected static int NORMAL_STATE
           
protected static int UNDEFINED_STATE
           
static int USE_BUILT_IN
           
static int USE_STANDARD_UDF
           
 
Constructor Summary
FBEscapedParser(int mode)
           
 
Method Summary
protected  boolean checkForEscapes(java.lang.String sql)
          Check if the target SQL contains at least one of the escaped syntax commands.
protected  java.lang.String convertEscapedFunction(java.lang.String escapedFunction)
          This method converts escaped function to a server function call.
protected  java.lang.String convertEscapeString(java.lang.String escapeString)
          Convert the "{escape '...'}"
protected  java.lang.String convertOuterJoin(java.lang.String outerJoin)
          This method converts the escaped outer join call syntax into the native outer join.
protected  java.lang.String convertProcedureCall(java.lang.String procedureCall)
          This methods converts the escaped procedure call syntax into the native procedure call.
protected  java.lang.String escapeToNative(java.lang.String escaped)
          This method checks the passed parameter to conform the escaped syntax, checks for the unknown keywords and re-formats result according to the Firebird SQL syntax.
protected  int getLastState()
          Returns the current state.
protected  int getState()
          Returns the current state.
protected  boolean isInState(int state)
          Returns if the system is in state state.
 java.lang.String parse(java.lang.String sql)
          Converts escaped parts in the passed SQL to native representation.
protected  void processEscaped(java.lang.String escaped, java.lang.StringBuilder keyword, java.lang.StringBuilder payload)
           
protected  void setState(int state)
          Sets the current state.
static boolean supportsLikeEscapeClause()
           
static boolean supportsStoredProcedures()
           
protected  void switchState(char testChar)
          Test the character to be the state switching character and switches the state if necessary.
protected  java.lang.String toDateString(java.lang.String dateStr)
          This method converts the 'yyyy-mm-dd' date format into the Firebird understandable format.
protected  java.lang.String toTimestampString(java.lang.String timestampStr)
          This method converts the 'yyyy-mm-dd hh:mm:ss' timestamp format into the Firebird understandable format.
protected  java.lang.String toTimeString(java.lang.String timeStr)
          This method converts the 'hh:mm:ss' time format into the Firebird understandable format.
protected  boolean wasInState(int state)
          Returns if the system was in state state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_BUILT_IN

public static final int USE_BUILT_IN
See Also:
Constant Field Values

USE_STANDARD_UDF

public static final int USE_STANDARD_UDF
See Also:
Constant Field Values

UNDEFINED_STATE

protected static final int UNDEFINED_STATE
See Also:
Constant Field Values

NORMAL_STATE

protected static final int NORMAL_STATE
See Also:
Constant Field Values

LITERAL_STATE

protected static final int LITERAL_STATE
See Also:
Constant Field Values

ESCAPE_STATE

protected static final int ESCAPE_STATE
See Also:
Constant Field Values

ESCAPE_CALL_KEYWORD

public static final java.lang.String ESCAPE_CALL_KEYWORD
See Also:
Constant Field Values

ESCAPE_CALL_KEYWORD3

public static final java.lang.String ESCAPE_CALL_KEYWORD3
See Also:
Constant Field Values

ESCAPE_DATE_KEYWORD

public static final java.lang.String ESCAPE_DATE_KEYWORD
See Also:
Constant Field Values

ESCAPE_TIME_KEYWORD

public static final java.lang.String ESCAPE_TIME_KEYWORD
See Also:
Constant Field Values

ESCAPE_TIMESTAMP_KEYWORD

public static final java.lang.String ESCAPE_TIMESTAMP_KEYWORD
See Also:
Constant Field Values

ESCAPE_FUNCTION_KEYWORD

public static final java.lang.String ESCAPE_FUNCTION_KEYWORD
See Also:
Constant Field Values

ESCAPE_ESCAPE_KEYWORD

public static final java.lang.String ESCAPE_ESCAPE_KEYWORD
See Also:
Constant Field Values

ESCAPE_OUTERJOIN_KEYWORS

public static final java.lang.String ESCAPE_OUTERJOIN_KEYWORS
See Also:
Constant Field Values
Constructor Detail

FBEscapedParser

public FBEscapedParser(int mode)
Method Detail

getLastState

protected int getLastState()
Returns the current state.


getState

protected int getState()
Returns the current state.


setState

protected void setState(int state)
                 throws java.lang.IllegalStateException
Sets the current state.

Parameters:
state - to enter.
Throws:
java.lang.IllegalStateException - if the system cannot enter the desired state.

isInState

protected boolean isInState(int state)
Returns if the system is in state state.

Parameters:
state - we're testing
Returns:
true if the system is in state state.

wasInState

protected boolean wasInState(int state)
Returns if the system was in state state.

Parameters:
state - we're testing
Returns:
true if the system was in state state.

switchState

protected void switchState(char testChar)
Test the character to be the state switching character and switches the state if necessary.

Parameters:
testChar - character to test

checkForEscapes

protected boolean checkForEscapes(java.lang.String sql)
Check if the target SQL contains at least one of the escaped syntax commands. This method performs a simple regex match, so it may report that SQL contains escaped syntax when the "{" is followed by the escaped syntax command in regular string constants that are passed as parameters. In this case parse(String) will perform complete SQL parsing.

Parameters:
sql - to test
Returns:
true if the sql is suspected to contain escaped syntax.

parse

public java.lang.String parse(java.lang.String sql)
                       throws java.sql.SQLException
Converts escaped parts in the passed SQL to native representation.

Parameters:
sql - to parse
Returns:
native form of the sql.
Throws:
java.sql.SQLException

processEscaped

protected void processEscaped(java.lang.String escaped,
                              java.lang.StringBuilder keyword,
                              java.lang.StringBuilder payload)

escapeToNative

protected java.lang.String escapeToNative(java.lang.String escaped)
                                   throws java.sql.SQLException
This method checks the passed parameter to conform the escaped syntax, checks for the unknown keywords and re-formats result according to the Firebird SQL syntax.

Parameters:
escaped - the part of escaped SQL between the '{' and '}'.
Returns:
the native representation of the SQL code.
Throws:
java.sql.SQLException

toDateString

protected java.lang.String toDateString(java.lang.String dateStr)
                                 throws FBSQLParseException
This method converts the 'yyyy-mm-dd' date format into the Firebird understandable format.

Parameters:
dateStr - the date in the 'yyyy-mm-dd' format.
Returns:
Firebird understandable date format.
Throws:
FBSQLParseException

toTimeString

protected java.lang.String toTimeString(java.lang.String timeStr)
                                 throws FBSQLParseException
This method converts the 'hh:mm:ss' time format into the Firebird understandable format.

Parameters:
timeStr - the date in the 'hh:mm:ss' format.
Returns:
Firebird understandable date format.
Throws:
FBSQLParseException

toTimestampString

protected java.lang.String toTimestampString(java.lang.String timestampStr)
                                      throws FBSQLParseException
This method converts the 'yyyy-mm-dd hh:mm:ss' timestamp format into the Firebird understandable format.

Parameters:
timestampStr - the date in the 'yyyy-mm-dd hh:mm:ss' format.
Returns:
Firebird understandable date format.
Throws:
FBSQLParseException

convertProcedureCall

protected java.lang.String convertProcedureCall(java.lang.String procedureCall)
                                         throws java.sql.SQLException
This methods converts the escaped procedure call syntax into the native procedure call.

Parameters:
procedureCall - part of {call proc_name(...)} without curly braces and "call" word.
Returns:
native procedure call.
Throws:
java.sql.SQLException

convertOuterJoin

protected java.lang.String convertOuterJoin(java.lang.String outerJoin)
                                     throws FBSQLParseException
This method converts the escaped outer join call syntax into the native outer join. Actually, we do not change anything here, since Firebird's syntax is the same.

Throws:
FBSQLParseException

convertEscapeString

protected java.lang.String convertEscapeString(java.lang.String escapeString)
Convert the "{escape '...'}" call into the corresponding escape clause for Firebird.

Parameters:
escapeString - escape string to convert
Returns:
converted code.

convertEscapedFunction

protected java.lang.String convertEscapedFunction(java.lang.String escapedFunction)
                                           throws FBSQLParseException
This method converts escaped function to a server function call. Actually we do not change anything here, we hope that all UDF are defined.

Parameters:
escapedFunction - escaped function call
Returns:
server-side function call.
Throws:
FBSQLParseException - if something was wrong.

supportsStoredProcedures

public static boolean supportsStoredProcedures()

supportsLikeEscapeClause

public static boolean supportsLikeEscapeClause()


Copyright © 2001-2019 Jaybird (Firebird JDBC/JCA) team. All rights reserved.