|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.jtds.jdbc.SQLParser
Process JDBC escape strings and parameter markers in the SQL string.
This code recognizes the following escapes:
Nested Class Summary | |
private static class |
SQLParser.CachedSQLQuery
Serialized version of a parsed SQL query (the value stored in the cache for a parsed SQL). |
Field Summary | |
private static SimpleLRUCache |
cache
LRU cache of previously parsed SQL |
private ConnectionJDBC2 |
connection
Connection object for server specific parsing. |
private static java.util.HashMap |
cvMap
Map of jdbc to server data types for convert |
private int |
d
Current position in output buffer. |
private static byte[] |
dateMask
Syntax mask for date escape. |
private static java.util.HashMap |
fnMap
Map of jdbc to sybase function names. |
private static boolean[] |
identifierChar
Lookup table to test if character is part of an identifier. |
private char[] |
in
Input buffer with SQL statement. |
private java.lang.String |
keyWord
First SQL keyword or identifier in statement. |
private int |
len
Length of input buffer. |
private static java.util.HashMap |
msFnMap
Map of jdbc to sql server function names. |
private char[] |
out
Output buffer to contain parsed SQL. |
private java.util.ArrayList |
params
Parameter list to be populated or null if no parameters
are expected. |
private java.lang.String |
procName
Procedure name in call escape. |
private int |
s
Current position in input buffer. |
private java.lang.String |
sql
Original SQL string |
private java.lang.String |
tableName
First table name in from clause |
private char |
terminator
Current expected terminator character. |
private static byte[] |
timeMask
Syntax mask for time escape. |
(package private) static byte[] |
timestampMask
Syntax mask for timestamp escape. |
Constructor Summary | |
private |
SQLParser(java.lang.String sqlIn,
java.util.ArrayList paramList,
ConnectionJDBC2 connection)
Constructs a new parser object to process the supplied SQL. |
Method Summary | |
private void |
append(char character)
Adds the given character to out , incrementing d by
and expanding out by a fixed number of characters if
necessary. |
private void |
append(char[] chars)
|
private void |
callEscape()
Processes the JDBC {call procedure [(? |
private java.lang.String |
copyKeyWord()
Copies over possible SQL keyword eg 'SELECT' |
private void |
copyLiteral(java.lang.String txt)
Inserts a String literal in the output buffer. |
private void |
copyParam(java.lang.String name,
int pos)
Builds a new parameter item. |
private java.lang.String |
copyParamName()
Copies an embedded parameter name to the output buffer. |
private java.lang.String |
copyProcName()
Copies an embedded stored procedure identifier over to the output buffer. |
private void |
copyString()
Copies over an embedded string literal unchanged. |
private void |
copyWhiteSpace()
Copies over white space. |
private void |
escape()
Processes the JDBC escape sequences. |
private void |
functionEscape()
Processes the JDBC escape {fn function()}. |
private static SimpleLRUCache |
getCache(ConnectionJDBC2 connection)
Retrieves the statement cache, creating it if required. |
private boolean |
getDateTimeField(byte[] mask)
Utility routine to validate date and time escapes. |
private java.lang.String |
getTableName()
Extracts the first table name following the keyword FROM. |
private static boolean |
isIdentifier(int ch)
Determines if character could be part of an SQL identifier. |
private void |
likeEscape()
Processes the JDBC escape {escape 'X'}. |
private void |
mustbe(char c,
boolean copy)
Checks that the next character is as expected. |
private void |
outerJoinEscape()
Processes the JDBC escape {oj left outer join etc}. |
(package private) java.lang.String[] |
parse(boolean extractTable)
Parses the SQL statement processing JDBC escapes and parameter markers. |
(package private) static java.lang.String[] |
parse(java.lang.String sql,
java.util.ArrayList paramList,
ConnectionJDBC2 connection,
boolean extractTable)
Parse the SQL statement processing JDBC escapes and parameter markers. |
private void |
skipMultiComments()
Skips multi-line comments |
private void |
skipSingleComments()
Skips single-line comments. |
private void |
skipWhiteSpace()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static SimpleLRUCache cache
private final java.lang.String sql
private final char[] in
private int s
private final int len
private char[] out
private int d
private final java.util.ArrayList params
null
if no parameters
are expected.
private char terminator
private java.lang.String procName
private java.lang.String keyWord
private java.lang.String tableName
private final ConnectionJDBC2 connection
private static boolean[] identifierChar
private static final byte[] timeMask
private static final byte[] dateMask
static final byte[] timestampMask
private static java.util.HashMap fnMap
private static java.util.HashMap msFnMap
private static java.util.HashMap cvMap
Constructor Detail |
private SQLParser(java.lang.String sqlIn, java.util.ArrayList paramList, ConnectionJDBC2 connection)
sqlIn
- the SQL statement to parseparamList
- the parameter list array to populate or
null
if no parameters are expectedconnection
- the parent Connection objectMethod Detail |
static java.lang.String[] parse(java.lang.String sql, java.util.ArrayList paramList, ConnectionJDBC2 connection, boolean extractTable) throws java.sql.SQLException
extractTable
- true to return the first table name in the FROM clause of a select
String[]
.
java.sql.SQLException
- if a parse error occursprivate static SimpleLRUCache getCache(ConnectionJDBC2 connection)
SimpleLRUCache
private static boolean isIdentifier(int ch)
ch
- the character to test.
boolean
true if ch in A-Z a-z 0-9 @ $ # _.private void copyLiteral(java.lang.String txt) throws java.sql.SQLException
txt
- The text to insert.
java.sql.SQLException
private void copyString()
private java.lang.String copyKeyWord()
private void copyParam(java.lang.String name, int pos) throws java.sql.SQLException
name
- Optional parameter name or null.pos
- The parameter marker position in the output buffer.
java.sql.SQLException
private java.lang.String copyProcName() throws java.sql.SQLException
String
.
java.sql.SQLException
private java.lang.String copyParamName()
String
.private void copyWhiteSpace()
private void mustbe(char c, boolean copy) throws java.sql.SQLException
c
- The expected character.copy
- True if found character should be copied.
java.sql.SQLException
- if expected characeter not found.private void skipWhiteSpace() throws java.sql.SQLException
java.sql.SQLException
private void skipSingleComments()
private void skipMultiComments() throws java.sql.SQLException
java.sql.SQLException
private void callEscape() throws java.sql.SQLException
java.sql.SQLException
- if an error occursprivate boolean getDateTimeField(byte[] mask) throws java.sql.SQLException
mask
- The validation mask
java.sql.SQLException
private void outerJoinEscape() throws java.sql.SQLException
java.sql.SQLException
private void functionEscape() throws java.sql.SQLException
java.sql.SQLException
private void likeEscape() throws java.sql.SQLException
java.sql.SQLException
private void escape() throws java.sql.SQLException
java.sql.SQLException
private java.lang.String getTableName() throws java.sql.SQLException
String
java.sql.SQLException
private final void append(char[] chars)
private final void append(char character)
Adds the given character to out
, incrementing d
by
and expanding out
by a fixed number of characters if
necessary.
java.lang.String[] parse(boolean extractTable) throws java.sql.SQLException
extractTable
- true to return the first table name in the FROM clause of a select
String[]
.
java.sql.SQLException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |