public class QueryInfo
extends java.lang.Object
Constructor and Description |
---|
QueryInfo(java.lang.String sql,
Session session,
java.lang.String encoding)
Constructs a
QueryInfo object for the given query or multi-query. |
Modifier and Type | Method and Description |
---|---|
boolean |
containsOnDuplicateKeyUpdate()
Does this query info represent a query that contains an ON DUPLICATE KEY UPDATE clause? This operation does not take into consideration the multiplicity
of queries in the original SQL.
|
static boolean |
containsOnDuplicateKeyUpdateClause(java.lang.String sql,
boolean noBackslashEscapes)
Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause.
|
static char |
firstCharOfStatementUc(java.lang.String sql,
boolean noBackslashEscapes)
Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
char |
getFirstStmtChar()
Returns the first character of the statement from the query used to build this
QueryInfo . |
int |
getNumberOfQueries()
Returns the number of queries identified in the original SQL string.
|
QueryInfo |
getQueryInfoForBatch(int count)
Returns a
QueryInfo for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing. |
QueryReturnType |
getQueryReturnType()
Returns the return type of the parsed query.
|
static QueryReturnType |
getQueryReturnType(java.lang.String sql,
boolean noBackslashEscapes)
Returns the type of return that can be expected from executing the given query.
|
java.lang.String |
getSqlForBatch()
Returns a preparable query for the batch count of this
QueryInfo . |
java.lang.String |
getSqlForBatch(int count)
Returns a preparable query for the specified batch count.
|
byte[][] |
getStaticSqlParts()
Returns the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located.
|
int |
getValuesClauseLength()
If this object represents a query that is re-writable as a multi-values statement and if rewriting batched statements is enabled, then returns the
length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1.
|
static int |
indexOfStatementKeyword(java.lang.String sql,
boolean noBackslashEscapes)
Finds and returns the position of the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
static boolean |
isReadOnlySafeQuery(java.lang.String sql,
boolean noBackslashEscapes)
Checks whether the given query is safe to run in a read-only session.
|
boolean |
isRewritableWithMultiValuesClause()
Can this query be rewritten as a multi-values clause?
|
public QueryInfo(java.lang.String sql, Session session, java.lang.String encoding)
QueryInfo
object for the given query or multi-query. The parsed result of this query allows to determine the location of the
placeholders, the query static parts and whether this query can be rewritten as a multi-values clause query.sql
- the query SQL string to parse and analyzesession
- the Session
under which the query analysis must be done.encoding
- the characters encoding to use when extracting the query static parts as byte arrays.public int getNumberOfQueries()
public QueryReturnType getQueryReturnType()
public char getFirstStmtChar()
QueryInfo
.public int getValuesClauseLength()
public boolean containsOnDuplicateKeyUpdate()
true
if the query or any of the original queries contain an ON DUPLICATE KEY UPDATE clause.public byte[][] getStaticSqlParts()
public boolean isRewritableWithMultiValuesClause()
true
if the query can be rewritten as a multi-values query.public QueryInfo getQueryInfoForBatch(int count)
QueryInfo
for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.count
- the number of parameter batchesQueryInfo
public java.lang.String getSqlForBatch()
QueryInfo
.public java.lang.String getSqlForBatch(int count)
count
- number of parameter batchespublic static int indexOfStatementKeyword(java.lang.String sql, boolean noBackslashEscapes)
sql
- the query to searchnoBackslashEscapes
- whether backslash escapes are disabled or notpublic static char firstCharOfStatementUc(java.lang.String sql, boolean noBackslashEscapes)
sql
- the query to searchnoBackslashEscapes
- whether backslash escapes are disabled or notpublic static boolean isReadOnlySafeQuery(java.lang.String sql, boolean noBackslashEscapes)
sql
- the query to checknoBackslashEscapes
- whether backslash escapes are disabled or nottrue
if the query is read-only safe, false
otherwise.public static QueryReturnType getQueryReturnType(java.lang.String sql, boolean noBackslashEscapes)
sql
- the query to checknoBackslashEscapes
- whether backslash escapes are disabled or notQueryReturnType
.public static boolean containsOnDuplicateKeyUpdateClause(java.lang.String sql, boolean noBackslashEscapes)
sql
- the query to searchnoBackslashEscapes
- whether backslash escapes are disabled or not.true
if the query contains an ON DUPLICATE KEY UPDATE clause, false
otherwise