public class QueryInfo extends Object
| Modifier | Constructor | Description |
|---|---|---|
private |
QueryInfo(QueryInfo baseQueryInfo,
int batchCount) |
Constructs a
QueryInfo object with a multi-value clause for the specified batch count, that stems from the specified baseQueryInfo. |
|
QueryInfo(String sql,
Session session,
String encoding) |
Constructs a
QueryInfo object for the given query or multi-query. |
| Modifier and Type | Method | Description |
|---|---|---|
private static boolean |
containsIntoClause(int startingPosition,
String searchIn,
boolean noBackslashEscapes) |
Checks whether the given input string contains an "INTO" clause, starting from the specified position, while optionally considering MySQL's
NO_BACKSLASH_ESCAPES SQL mode for escape sequence handling.
|
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(String sql,
boolean noBackslashEscapes) |
Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause.
|
static char |
firstCharOfStatementUc(String sql,
boolean noBackslashEscapes) |
Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.
|
private static String |
getContextForWithStatement(String sql,
boolean noBackslashEscapes) |
Returns the context of the WITH statement.
|
char |
getFirstStmtChar() |
Returns the first character of the statement from the query used to build this
QueryInfo. |
int |
getNumberOfPlaceholders() |
Returns the number of placeholders found in the query.
|
int |
getNumberOfQueries() |
Returns the number of queries identified in the original SQL string.
|
List<PlaceholderPurpose> |
getPlaceholderPurposes() |
Returns a list containing the purpose of each one of the placeholders found according to their positional ordering.
|
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(String sql,
boolean noBackslashEscapes) |
Returns the type of return that can be expected from executing the given query.
|
String |
getSqlForBatch() |
Returns a preparable query for the batch count of this
QueryInfo. |
String |
getSqlForBatch(int count) |
Returns a preparable query for the specified batch count.
|
String |
getStatementKeyword() |
Returns the statement keyword from the query used to build this
QueryInfo. |
static String |
getStatementKeyword(String sql,
boolean noBackslashEscapes) |
Finds and returns the statement keyword from the specified SQL, skipping comments and quoted text.
|
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(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(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?
|
private static final String OPENING_MARKERS
private static final String OPENING_MARKERS_WITH_PARENS
private static final String CLOSING_MARKERS
private static final String CLOSING_MARKERS_WITH_PARENS
private static final String OVERRIDING_MARKERS
private static final String SELECT_STATEMENT
private static final String TABLE_STATEMENT
private static final String INSERT_STATEMENT
private static final String REPLACE_STATEMENT
private static final String MULTIPLE_QUERIES_TAG
private static final String LIMIT_CLAUSE
private static final String OFFSET_CLAUSE
private static final String VALUE_CLAUSE
private static final String AS_CLAUSE
private static final String[] ODKU_CLAUSE
private static final String LAST_INSERT_ID_FUNC
private static final String INTO_CLAUSE
private QueryInfo baseQueryInfo
private String sql
private String encoding
private QueryReturnType queryReturnType
private int queryLength
private int queryStartPos
private char statementFirstChar
private String statementKeyword
private int batchCount
private int numberOfPlaceholders
private int numberOfQueries
private boolean containsOnDuplicateKeyUpdate
private boolean isRewritableWithMultiValuesClause
private int valuesClauseLength
private byte[][] staticSqlParts
private List<PlaceholderPurpose> placeholderPurposes
public QueryInfo(String sql, Session session, 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.private QueryInfo(QueryInfo baseQueryInfo, int batchCount)
QueryInfo object with a multi-value clause for the specified batch count, that stems from the specified baseQueryInfo.baseQueryInfo - the QueryInfo instance that provides the query static parts used to create the new instance now augmented to accommodate the extra
number of parametersbatchCount - the number of batches, i.e., the number of times the VALUES clause needs to be repeated inside the new querypublic int getNumberOfQueries()
public int getNumberOfPlaceholders()
public QueryReturnType getQueryReturnType()
public char getFirstStmtChar()
QueryInfo.public String getStatementKeyword()
QueryInfo.public int getValuesClauseLength()
public List<PlaceholderPurpose> getPlaceholderPurposes()
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 batchesQueryInfopublic String getSqlForBatch()
QueryInfo.public String getSqlForBatch(int count)
count - number of parameter batchespublic static int indexOfStatementKeyword(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static char firstCharOfStatementUc(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static String getStatementKeyword(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static boolean isReadOnlySafeQuery(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(String sql, boolean noBackslashEscapes)
sql - the query to checknoBackslashEscapes - whether backslash escapes are disabled or notQueryReturnType.private static boolean containsIntoClause(int startingPosition,
String searchIn,
boolean noBackslashEscapes)
startingPosition - the position in the string to begin the searchsearchIn - the string to search for the "INTO" clausenoBackslashEscapes - whether backslash escapes should be ignored (true for NO_BACKSLASH_ESCAPES mode)true if the "INTO" clause is found in the input string from the given position, false otherwiseprivate static String getContextForWithStatement(String sql, boolean noBackslashEscapes)
sql - the query to searchnoBackslashEscapes - whether backslash escapes are disabled or notpublic static boolean containsOnDuplicateKeyUpdateClause(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