public class IlvJDBCQueryUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
IlvJDBCQueryUtil.IdentifierChain
This class contains utility functions for manipulating identifier chains
(sequences of identifiers, separated by periods) in SQL syntax.
|
static interface |
IlvJDBCQueryUtil.QueryCharacterHandler
This interface is used to iterate over the characters of a query string,
separating comments from non-comment tokens.
|
Modifier and Type | Method and Description |
---|---|
static String |
combineQueryWithParameters(Connection connection,
String query,
Object[] queryParameters)
Combines a query string with query parameters, forming a query string that
can be used without parameters.
|
static String |
combineQueryWithParameters(String query,
Object[] queryParameters)
Combines a query string with query parameters, forming a query string that
can be used without parameters.
|
static String |
convertToString(Object object)
Converts a query parameter object to a string in SQL syntax that can be
used in an SQL query string.
|
static void |
recognizeComments(CharSequence s,
IlvJDBCQueryUtil.QueryCharacterHandler handler)
Parses a string in SQL syntax by dissecting it into comments and
non-comment characters.
|
static String |
validateColumnName(String columnName)
Validates that a given column name is valid in SQL syntax without needing
escaping.
|
static String |
validateColumnReference(String columnReference)
Validates that a given column reference is valid in SQL syntax without
needing escaping.
|
static String |
validateIdentifier(String identifier)
Validates that a given identifier is valid in SQL syntax without needing
escaping.
|
static String |
validateTableName(String tableName)
Validates that a given table name is valid in SQL syntax without needing
escaping.
|
public static void recognizeComments(CharSequence s, IlvJDBCQueryUtil.QueryCharacterHandler handler) throws SQLException
s
- A piece of query string, in SQL syntax.handler
- An object that receives the comments and non-comment
characters.SQLException
- if the comment syntax is ambiguouspublic static String combineQueryWithParameters(Connection connection, String query, Object[] queryParameters) throws SQLException
connection
- A connection to the database.query
- An SQL query, with question marks as placeholders for the
parameters. Named parameters are not supported.queryParameters
- An array of parameters for the query.SQLException
- if the comment syntax is ambiguousIllegalArgumentException
- if the number of parameters does not match
the number of question marks in the query,
or if some of the parameters do not have a
supported typepublic static String combineQueryWithParameters(String query, Object[] queryParameters) throws SQLException
query
- An SQL query, with question marks as placeholders for the
parameters. Named parameters are not supported.queryParameters
- An array of parameters for the query.SQLException
- if the comment syntax is ambiguousIllegalArgumentException
- if the number of parameters does not match
the number of question marks in the query,
or if some of the parameters do not have a
supported typepublic static String convertToString(Object object)
object
- An object.IllegalArgumentException
- if object
does not have a
supported typepublic static String validateIdentifier(String identifier) throws SQLException
This function accepts regular identifiers and double-quote delimited identifiers. It does not accept Unicode delimited identifiers or syntaxes that depend on the brand of database. It also does not support whitespace or embedded comments.
identifier
- A string.SQLException
- if the given identifier is invalidpublic static String validateTableName(String tableName) throws SQLException
tableName
- A string.SQLException
- if the given table name is invalidIlvJDBCQueryUtil.IdentifierChain
public static String validateColumnName(String columnName) throws SQLException
This function accepts identifiers like validateIdentifier(String)
does.
Note that all column names are column references, but not vice versa.
columnName
- A string.SQLException
- if the given column name is invalidpublic static String validateColumnReference(String columnReference) throws SQLException
columnReference
- A string.SQLException
- if the given column reference is invalidIlvJDBCQueryUtil.IdentifierChain
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.