public class SafeSQL
extends java.lang.Object
Constructor and Description |
---|
SafeSQL() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addIn(java.util.Collection<java.lang.String> collection)
Adds literals in collection to bind variables in SQL
|
java.lang.String |
addIn(java.lang.String valuelist)
Replace a single literal in SQL and remember the value
|
java.lang.String |
addIn(java.lang.String valuelist,
java.lang.String delimiter)
Replace a single literal in SQL and remember the value
|
java.lang.String |
addVar(java.lang.Object value)
Replace a single literal in SQL and remember the value
|
static java.lang.String |
convertToSQLInClause(java.lang.String input,
java.lang.String delimiter,
boolean isOracle)
Utility method to convert String input of a list of items separated by delimiter to be used as literals with escaped in a SQL in clause
|
static java.lang.String |
encodeForSQL(java.lang.String input,
boolean isOracle)
Utility method to encode String literal when building query where clause for SDIRequest as PreparedStatement cannot be used in this case
|
java.lang.String |
getPreparedSQL() |
java.lang.Object[] |
getValues()
Return all previously added values since instantiation or last reset calle as an object array from calling addValue and addIn calls to be use as bind variable values in the QueryProcessor getPreparedSQLDataSet call
|
static java.lang.Object[] |
joinArrays(java.lang.Object[] array1,
java.lang.Object[] array2)
Utility method to join two object arrays.
|
static java.lang.String |
replaceAllWithInVars(java.lang.String query,
java.lang.String tokenToReplace,
java.lang.String replaceWithvaluelist,
java.lang.String listdelimitor,
SafeSQL safeSQL)
Utility method to allow the passed in SafeSQL to replace any replaced token with ?,?,?,...
|
static java.lang.String |
replaceAllWithVars(java.lang.String query,
java.lang.String tokenToReplace,
java.lang.String replaceWithvalue,
SafeSQL safeSQL)
Utility method to allow the passed in SafeSQL to replace any replaced token with ? and registerd the replace value to be included in the getValues() return.
|
void |
reset()
Reset the bind variable values for building a new SQL.
|
void |
setPreparedSQL(java.lang.String preparedSQL)
Set the preparedSQL string.
|
public java.lang.String addVar(java.lang.Object value)
value
- The value in a sql literal to replace with a ?public java.lang.String addIn(java.lang.String valuelist)
valuelist
- The list of literal values delimited by "','" or "', N'" in a sql in clause to replace with a corresponding number of "?,?,?.." and remember the values
if valuelist start with ' or N' it will be trimmed. if valuelist ends with ', it will be trimmed.public java.lang.String addIn(java.lang.String valuelist, java.lang.String delimiter)
valuelist
- The list of literal values delimited by the delimiter param in a sql in clause to replace with a corresponding number of "?,?,?.." and remember the valuesdelimiter
- public java.lang.String addIn(java.util.Collection<java.lang.String> collection)
collection
- The collection of literal valuespublic java.lang.Object[] getValues()
public void reset()
public java.lang.String getPreparedSQL()
public void setPreparedSQL(java.lang.String preparedSQL)
preparedSQL
- public static java.lang.String replaceAllWithVars(java.lang.String query, java.lang.String tokenToReplace, java.lang.String replaceWithvalue, SafeSQL safeSQL)
query
- the input query stringtokenToReplace
- the string token in the query to replace with the replaceWithvalue.
It's important to include the single quote as part of the token. For example, when replace with a string literal the token is "[sdcid]",
the token should be changed to "'[sdcid]'" when replace it with bind variables. If original token is something like '[sdcid]%', don't use this methodreplaceWithvalue
- safeSQL
- - the safeSQL object to insert ? in place of tokens and remember the replaceWithvalue in bind var values when safeSQL.getValues() is calledpublic static java.lang.String replaceAllWithInVars(java.lang.String query, java.lang.String tokenToReplace, java.lang.String replaceWithvaluelist, java.lang.String listdelimitor, SafeSQL safeSQL)
query
- the input query stringtokenToReplace
- the string token in the query to replace with the replaceWithvalue.
It's important to include the single quote as part of the token. For example, when replace with a string literal the token is "[sdcid]",
the token should be changed to "'[sdcid]'" when replace it with bind variables. If original token is something like '[sdcid]%', don't use this methodreplaceWithvaluelist
- - semicolon separated list values to replace with bind variables in the inclause tokensafeSQL
- - the safeSQL object to insert ? in place of tokens and remember the replaceWithvalue in bind var values when safeSQL.getValues() is calledpublic static java.lang.Object[] joinArrays(java.lang.Object[] array1, java.lang.Object[] array2)
array1
- the first arrayarray2
- the second arraypublic static java.lang.String encodeForSQL(java.lang.String input, boolean isOracle)
input
- the String to be encodedpublic static java.lang.String convertToSQLInClause(java.lang.String input, java.lang.String delimiter, boolean isOracle)
input
- the String to be converted