程序包 com.mysql.cj
类 QueryInfo
- java.lang.Object
-
- com.mysql.cj.QueryInfo
-
public class QueryInfo extends Object
Represents the "parsed" state of a prepared query, with the statement broken up into its static and dynamic (where parameters are bound) parts.
-
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 booleancontainsOnDuplicateKeyUpdate()Does this query info represent a query that contains an ON DUPLICATE KEY UPDATE clause?static booleancontainsOnDuplicateKeyUpdateClause(String sql, boolean noBackslashEscapes)Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause.static charfirstCharOfStatementUc(String sql, boolean noBackslashEscapes)Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.chargetFirstStmtChar()Returns the first character of the statement from the query used to build thisQueryInfo.intgetNumberOfQueries()Returns the number of queries identified in the original SQL string.QueryInfogetQueryInfoForBatch(int count)Returns aQueryInfofor a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.QueryReturnTypegetQueryReturnType()Returns the return type of the parsed query.static QueryReturnTypegetQueryReturnType(String sql, boolean noBackslashEscapes)Returns the type of return that can be expected from executing the given query.StringgetSqlForBatch()Returns a preparable query for the batch count of thisQueryInfo.StringgetSqlForBatch(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.intgetValuesClauseLength()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 intindexOfStatementKeyword(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 booleanisReadOnlySafeQuery(String sql, boolean noBackslashEscapes)Checks whether the given query is safe to run in a read-only session.booleanisRewritableWithMultiValuesClause()Can this query be rewritten as a multi-values clause?
-
-
-
构造器详细资料
-
QueryInfo
public QueryInfo(String sql, Session session, String encoding)
Constructs aQueryInfoobject 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- theSessionunder which the query analysis must be done.encoding- the characters encoding to use when extracting the query static parts as byte arrays.
-
-
方法详细资料
-
getNumberOfQueries
public int getNumberOfQueries()
Returns the number of queries identified in the original SQL string. Different queries are identified by the presence of the query delimiter character, i.e., a semicolon.- 返回:
- the number of queries identified in the original SQL string
-
getQueryReturnType
public QueryReturnType getQueryReturnType()
Returns the return type of the parsed query. This operation does not take into consideration the multiplicity of queries in the specified SQL.- 返回:
- the return type of the parsed query
-
getFirstStmtChar
public char getFirstStmtChar()
Returns the first character of the statement from the query used to build thisQueryInfo.- 返回:
- the first character of the statement
-
getValuesClauseLength
public 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.- 返回:
- the length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1
-
containsOnDuplicateKeyUpdate
public 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. Checking whether the original query contains an ON DUPLICATE KEY UPDATE clause is conditional to how the connection properties `dontCheckOnDuplicateKeyUpdateInSQL` and `rewriteBatchedStatements` are set, with `rewriteBatchedStatements=true` implicitly disabling `dontCheckOnDuplicateKeyUpdateInSQL`.- 返回:
trueif the query or any of the original queries contain an ON DUPLICATE KEY UPDATE clause.
-
getStaticSqlParts
public byte[][] getStaticSqlParts()
Returns the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located.- 返回:
- the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located
-
isRewritableWithMultiValuesClause
public boolean isRewritableWithMultiValuesClause()
Can this query be rewritten as a multi-values clause?- 返回:
trueif the query can be rewritten as a multi-values query.
-
getQueryInfoForBatch
public QueryInfo getQueryInfoForBatch(int count)
Returns aQueryInfofor a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.- 参数:
count- the number of parameter batches- 返回:
QueryInfo
-
getSqlForBatch
public String getSqlForBatch()
Returns a preparable query for the batch count of thisQueryInfo.- 返回:
- a preparable query string with the appropriate number of placeholders
-
getSqlForBatch
public String getSqlForBatch(int count)
Returns a preparable query for the specified batch count.- 参数:
count- number of parameter batches- 返回:
- a preparable query string with the appropriate number of placeholders
-
indexOfStatementKeyword
public 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.- 参数:
sql- the query to searchnoBackslashEscapes- whether backslash escapes are disabled or not- 返回:
- the position of the first character of the query
-
firstCharOfStatementUc
public static char firstCharOfStatementUc(String sql, boolean noBackslashEscapes)
Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.- 参数:
sql- the query to searchnoBackslashEscapes- whether backslash escapes are disabled or not- 返回:
- the first character of the query, in upper case
-
isReadOnlySafeQuery
public static boolean isReadOnlySafeQuery(String sql, boolean noBackslashEscapes)
Checks whether the given query is safe to run in a read-only session. In case of doubt it is assumed to be safe. This operation does not take into consideration the multiplicity of queries in the specified SQL.- 参数:
sql- the query to checknoBackslashEscapes- whether backslash escapes are disabled or not- 返回:
trueif the query is read-only safe,falseotherwise.
-
getQueryReturnType
public static QueryReturnType getQueryReturnType(String sql, boolean noBackslashEscapes)
Returns the type of return that can be expected from executing the given query. This operation does not take into consideration the multiplicity of queries in the specified SQL.- 参数:
sql- the query to checknoBackslashEscapes- whether backslash escapes are disabled or not- 返回:
- the return type that can be expected from the given query, one of the elements of
QueryReturnType.
-
containsOnDuplicateKeyUpdateClause
public static boolean containsOnDuplicateKeyUpdateClause(String sql, boolean noBackslashEscapes)
Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause. This operation does not take into consideration the multiplicity of queries in the specified SQL.- 参数:
sql- the query to searchnoBackslashEscapes- whether backslash escapes are disabled or not.- 返回:
trueif the query contains an ON DUPLICATE KEY UPDATE clause,falseotherwise
-
-