org.firebirdsql.jdbc

Class 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

protected static String
CHECK_CALL_1
protected static String
CHECK_CALL_2
protected static String
CHECK_DATE
protected static String
CHECK_ESCAPE
protected static String
CHECK_FUNCTION
protected static String
CHECK_OUTERJOIN
protected static String
CHECK_TIME
protected static String
CHECK_TIMESTAMP
static String
ESCAPE_CALL_KEYWORD
static String
ESCAPE_CALL_KEYWORD3
static String
ESCAPE_DATE_KEYWORD
static String
ESCAPE_ESCAPE_KEYWORD
static String
ESCAPE_FUNCTION_KEYWORD
static String
ESCAPE_OUTERJOIN_KEYWORS
protected static int
ESCAPE_STATE
static String
ESCAPE_TIMESTAMP_KEYWORD
static String
ESCAPE_TIME_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(String sql)
Check if the target SQL contains at least one of the escaped syntax commands.
protected String
convertEscapeString(String escapeString)
Convert the "{escape '...'}" call into the corresponding escape clause for Firebird.
protected String
convertEscapedFunction(String escapedFunction)
This method converts escaped function to a server function call.
protected String
convertOuterJoin(String outerJoin)
This method converts the escaped outer join call syntax into the native outer join.
protected String
convertProcedureCall(String procedureCall)
This methods converts the escaped procedure call syntax into the native procedure call.
protected String
escapeToNative(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.
String
parse(String sql)
Converts escaped parts in the passed SQL to native representation.
protected void
processEscaped(String escaped, StringBuffer keyword, StringBuffer 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 String
toDateString(String dateStr)
This method converts the 'yyyy-mm-dd' date format into the Firebird understandable format.
protected String
toTimeString(String timeStr)
This method converts the 'hh:mm:ss' time format into the Firebird understandable format.
protected String
toTimestampString(String timestampStr)
This method converts the 'yyyy-mm-dd hh:mm:ss' timestamp format into the Firebird understandable format.
protected boolean
wasInState(int state)
Returns if the system was in state state.

Field Details

CHECK_CALL_1

protected static final String CHECK_CALL_1

CHECK_CALL_2

protected static final String CHECK_CALL_2

CHECK_DATE

protected static final String CHECK_DATE

CHECK_ESCAPE

protected static final String CHECK_ESCAPE

CHECK_FUNCTION

protected static final String CHECK_FUNCTION

CHECK_OUTERJOIN

protected static final String CHECK_OUTERJOIN

CHECK_TIME

protected static final String CHECK_TIME

CHECK_TIMESTAMP

protected static final String CHECK_TIMESTAMP

ESCAPE_CALL_KEYWORD

public static final String ESCAPE_CALL_KEYWORD

ESCAPE_CALL_KEYWORD3

public static final String ESCAPE_CALL_KEYWORD3

ESCAPE_DATE_KEYWORD

public static final String ESCAPE_DATE_KEYWORD

ESCAPE_ESCAPE_KEYWORD

public static final String ESCAPE_ESCAPE_KEYWORD

ESCAPE_FUNCTION_KEYWORD

public static final String ESCAPE_FUNCTION_KEYWORD

ESCAPE_OUTERJOIN_KEYWORS

public static final String ESCAPE_OUTERJOIN_KEYWORS

ESCAPE_STATE

protected static final int ESCAPE_STATE
Field Value:
4

ESCAPE_TIMESTAMP_KEYWORD

public static final String ESCAPE_TIMESTAMP_KEYWORD

ESCAPE_TIME_KEYWORD

public static final String ESCAPE_TIME_KEYWORD

LITERAL_STATE

protected static final int LITERAL_STATE
Field Value:
2

NORMAL_STATE

protected static final int NORMAL_STATE
Field Value:
1

UNDEFINED_STATE

protected static final int UNDEFINED_STATE
Field Value:
0

USE_BUILT_IN

public static final int USE_BUILT_IN
Field Value:
0

USE_STANDARD_UDF

public static final int USE_STANDARD_UDF
Field Value:
1

Constructor Details

FBEscapedParser

public FBEscapedParser(int mode)

Method Details

checkForEscapes

protected boolean checkForEscapes(String sql)
Parameters:
sql - to test
Returns:
true if the sql is suspected to contain escaped syntax.

convertEscapeString

protected String convertEscapeString(String escapeString)
Convert the "{escape '...'}" call into the corresponding escape clause for Firebird.
Parameters:
escapeString - escape string to convert
Returns:
converted code.

convertEscapedFunction

protected String convertEscapedFunction(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.

convertOuterJoin

protected String convertOuterJoin(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.

convertProcedureCall

protected String convertProcedureCall(String procedureCall)
            throws FBSQLException
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.

escapeToNative

protected String escapeToNative(String escaped)
            throws FBSQLException
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.

getLastState

protected int getLastState()
Returns the current state.

getState

protected int getState()
Returns the current 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.

parse

public String parse(String sql)
            throws FBSQLException
Converts escaped parts in the passed SQL to native representation.
Parameters:
sql - to parse
Returns:
native form of the sql.

processEscaped

protected void processEscaped(String escaped,
                              StringBuffer keyword,
                              StringBuffer payload)

setState

protected void setState(int state)
            throws IllegalStateException
Sets the current state.
Parameters:
state - to enter.

supportsLikeEscapeClause

public static boolean supportsLikeEscapeClause()

supportsStoredProcedures

public static boolean supportsStoredProcedures()

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

toDateString

protected String toDateString(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.

toTimeString

protected String toTimeString(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.

toTimestampString

protected String toTimestampString(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.

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.

Copyright B) 2001 David Jencks and other authors. All rights reserved.