com.jdbwc.core.util
Class SQLParamParser

java.lang.Object
  extended by com.jdbwc.core.util.SQLParamParser

public class SQLParamParser
extends java.lang.Object

This class is designed to parse a variety of SQL Strings into table and parameter variables suitable for building ParameterMetaData from.
At the moment its a bit limited but should be ok for most traditional sql.
Some SQL99 is also translated correctly.
If we cant produce accurate metadata here we usually throw an exception to ParameterMetaData.

This class can handle table JOINS.
Nested functions will result in the first valid String parameter of a multi-parameter function being used as the actual column name. This will be improved later or replaced with something more efficient.

Version:
1.0.0.2
Author:
Tim Gall (Oz-DevWorX)

Field Summary
static java.lang.String MY_MODE_IN
           
static java.lang.String MY_MODE_INOUT
           
static java.lang.String MY_MODE_OUT
           
static char OUR_PARAM_MARKER
          deals with the field portion of a select statement
 
Constructor Summary
SQLParamParser(WCConnection connection, com.ozdevworx.dtype.DataHandler prepStatement)
          Constructs a new SQLParamParser ready to return PreparedStatement ParameterMetaData for the sqlString parameter.
SQLParamParser(WCConnection connection, com.ozdevworx.dtype.DataHandler callableStatement, boolean isCallable)
          Constructs a new SQLParamParser ready to return CallableStatement ParameterMetaData for the sqlString parameter.
 
Method Summary
static int countParams(java.lang.String input)
           
static int countParams(java.lang.String input, char delimiter)
           
 SQLField[] getFields()
           
static java.lang.String populateParams(com.ozdevworx.dtype.DataHandler prepStatement)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MY_MODE_IN

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

MY_MODE_OUT

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

MY_MODE_INOUT

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

OUR_PARAM_MARKER

public static final char OUR_PARAM_MARKER
deals with the field portion of a select statement

See Also:
Constant Field Values
Constructor Detail

SQLParamParser

public SQLParamParser(WCConnection connection,
                      com.ozdevworx.dtype.DataHandler prepStatement)
               throws java.sql.SQLException
Constructs a new SQLParamParser ready to return PreparedStatement ParameterMetaData for the sqlString parameter.

Parameters:
connection - Database Connection
prepStatement - A DataHandler containing a valid SQL String at the first index, parameters in the remaining indexes.
Throws:
java.sql.SQLException - if the connection or sqlString are not valid for this Constructor.

SQLParamParser

public SQLParamParser(WCConnection connection,
                      com.ozdevworx.dtype.DataHandler callableStatement,
                      boolean isCallable)
               throws java.sql.SQLException
Constructs a new SQLParamParser ready to return CallableStatement ParameterMetaData for the sqlString parameter.

Parameters:
connection - Database Connection
callableStatement - A DataHandler containing a valid SQL CALL String at the first index, parameters in the remaining indexes.
isCallable - boolean to signify the fieldSet should be built for a CallableStatement.
Throws:
java.sql.SQLException - if the connection or sqlString are not valid for this Constructor.
Method Detail

countParams

public static int countParams(java.lang.String input)

countParams

public static int countParams(java.lang.String input,
                              char delimiter)

populateParams

public static java.lang.String populateParams(com.ozdevworx.dtype.DataHandler prepStatement)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getFields

public SQLField[] getFields()