Top Description Fields Constructors Methods
com.mysql.cj

public Class QueryInfo

extends Object
Class Inheritance
Static Imports
com.mysql.cj.PlaceholderPurpose.GENERIC, .PlaceholderPurpose.INSERT_VALUES, .PlaceholderPurpose.LIMIT_AND_OFFSET

Represents the "parsed" state of a prepared query, with the statement broken up into its static and dynamic (where parameters are bound) parts.

Field Summary

Modifier and TypeField and Description
private static final String
private QueryInfo
private int
private static final String
private boolean
private String
private static final String
private boolean
private static final String
private static final String
private static final String
private int
private int
private static final String[]
private static final String
private static final String
private static final String
private List<PlaceholderPurpose>
private int
private QueryReturnType
private int
private static final String
private static final String
private String
private char
private String
private byte[][]
private static final String
private static final String
private int
private ArrayList<Integer>

Constructor Summary

AccessConstructor and Description
public
QueryInfo(String
the query SQL string to parse and analyze
sql
,
Session
the Session under which the query analysis must be done.
session
,
String
the characters encoding to use when extracting the query static parts as byte arrays.
encoding
)

Constructs a QueryInfo object for the given query or multi-query.

private
QueryInfo(QueryInfo
the QueryInfo instance that provides the query static parts used to create the new instance now augmented to accommodate the extra number of parameters
baseQueryInfo
,
int
the number of batches, i.e., the number of times the VALUES clause needs to be repeated inside the new query
batchCount
)

Constructs a QueryInfo object with a multi-value clause for the specified batch count, that stems from the specified baseQueryInfo.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the query or any of the original queries contain an ON DUPLICATE KEY UPDATE clause.
containsOnDuplicateKeyUpdate
()

Does this query info represent a query that contains an ON DUPLICATE KEY UPDATE clause?

public static boolean

Returns:

true if the query contains an ON DUPLICATE KEY UPDATE clause, false otherwise
containsOnDuplicateKeyUpdateClause
(String
the query to search
sql
,
boolean
whether backslash escapes are disabled or not.
noBackslashEscapes
)

Checks whether the specified SQL contains or not an ON DUPLICATE KEY UPDATE clause.

public static char

Returns:

the first character of the query, in upper case
firstCharOfStatementUc
(String
the query to search
sql
,
boolean
whether backslash escapes are disabled or not
noBackslashEscapes
)

Finds and returns the first non-whitespace character from the specified SQL, skipping comments and quoted text.

private static String

Returns:

the context of the WITH statement or null if failed to find it
getContextForWithStatement
(String
the query to search
sql
,
boolean
whether backslash escapes are disabled or not
noBackslashEscapes
)

Returns the context of the WITH statement.

public char

Returns:

the first character of the statement
getFirstStmtChar
()

Returns the first character of the statement from the query used to build this QueryInfo.

public int

Returns:

the number of placeholders in the query
getNumberOfPlaceholders
()

Returns the number of placeholders found in the query.

public int

Returns:

the number of queries identified in the original SQL string
getNumberOfQueries
()

Returns the number of queries identified in the original SQL string.

public List<PlaceholderPurpose>

Returns:

the list of the placeholders purposes.
getPlaceholderPurposes
()

Returns a list containing the purpose of each one of the placeholders found according to their positional ordering.

public QueryInfo

Returns:

QueryInfo
getQueryInfoForBatch
(int
the number of parameter batches
count
)

Returns a QueryInfo for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.

public QueryReturnType

Returns:

the return type of the parsed query
getQueryReturnType
()

Returns the return type of the parsed query.

public static QueryReturnType

Returns:

the return type that can be expected from the given query, one of the elements of QueryReturnType.
getQueryReturnType
(String
the query to check
sql
,
boolean
whether backslash escapes are disabled or not
noBackslashEscapes
)

Returns the type of return that can be expected from executing the given query.

public String

Returns:

a preparable query string with the appropriate number of placeholders
getSqlForBatch
()

Returns a preparable query for the batch count of this QueryInfo.

public String

Returns:

a preparable query string with the appropriate number of placeholders
getSqlForBatch
(int
number of parameter batches
count
)

Returns a preparable query for the specified batch count.

public String

Returns:

the statement keyword
getStatementKeyword
()

Returns the statement keyword from the query used to build this QueryInfo.

public static String

Returns:

the statement keyword of the query
getStatementKeyword
(String
the query to search
sql
,
boolean
whether backslash escapes are disabled or not
noBackslashEscapes
)

Finds and returns the statement keyword from the specified SQL, skipping comments and quoted text.

public byte[][]

Returns:

the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located
getStaticSqlParts
()

Returns the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located.

public int

Returns:

the length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1
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.

public static int

Returns:

the position of the first character of the query
indexOfStatementKeyword
(String
the query to search
sql
,
boolean
whether backslash escapes are disabled or not
noBackslashEscapes
)

Finds and returns the position of the first non-whitespace character from the specified SQL, skipping comments and quoted text.

public static boolean

Returns:

true if the query is read-only safe, false otherwise.
isReadOnlySafeQuery
(String
the query to check
sql
,
boolean
whether backslash escapes are disabled or not
noBackslashEscapes
)

Checks whether the given query is safe to run in a read-only session.

public boolean

Returns:

true if the query can be rewritten as a multi-values query.
isRewritableWithMultiValuesClause
()

Can this query be rewritten as a multi-values clause?

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AS_CLAUSEback to summary
private static final String AS_CLAUSE
baseQueryInfoback to summary
private QueryInfo baseQueryInfo
batchCountback to summary
private int batchCount
CLOSING_MARKERSback to summary
private static final String CLOSING_MARKERS
containsOnDuplicateKeyUpdateback to summary
private boolean containsOnDuplicateKeyUpdate
encodingback to summary
private String encoding
INSERT_STATEMENTback to summary
private static final String INSERT_STATEMENT
isRewritableWithMultiValuesClauseback to summary
private boolean isRewritableWithMultiValuesClause
LAST_INSERT_ID_FUNCback to summary
private static final String LAST_INSERT_ID_FUNC
LIMIT_CLAUSEback to summary
private static final String LIMIT_CLAUSE
MULTIPLE_QUERIES_TAGback to summary
private static final String MULTIPLE_QUERIES_TAG
numberOfPlaceholdersback to summary
private int numberOfPlaceholders
numberOfQueriesback to summary
private int numberOfQueries
ODKU_CLAUSEback to summary
private static final String[] ODKU_CLAUSE
OFFSET_CLAUSEback to summary
private static final String OFFSET_CLAUSE
OPENING_MARKERSback to summary
private static final String OPENING_MARKERS
OVERRIDING_MARKERSback to summary
private static final String OVERRIDING_MARKERS
placeholderPurposesback to summary
private List<PlaceholderPurpose> placeholderPurposes
queryLengthback to summary
private int queryLength
queryReturnTypeback to summary
private QueryReturnType queryReturnType
queryStartPosback to summary
private int queryStartPos
REPLACE_STATEMENTback to summary
private static final String REPLACE_STATEMENT
SELECT_STATEMENTback to summary
private static final String SELECT_STATEMENT
sqlback to summary
private String sql
statementFirstCharback to summary
private char statementFirstChar
statementKeywordback to summary
private String statementKeyword
staticSqlPartsback to summary
private byte[][] staticSqlParts
TABLE_STATEMENTback to summary
private static final String TABLE_STATEMENT
VALUE_CLAUSEback to summary
private static final String VALUE_CLAUSE
valuesClauseLengthback to summary
private int valuesClauseLength
valuesEndpointsback to summary
private ArrayList<Integer> valuesEndpoints

Constructor Detail

QueryInfoback to summary
public QueryInfo(String sql, Session session, String encoding)

Constructs a 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.

Parameters
sql:String

the query SQL string to parse and analyze

session:Session

the Session under which the query analysis must be done.

encoding:String

the characters encoding to use when extracting the query static parts as byte arrays.

QueryInfoback to summary
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.

Parameters
baseQueryInfo:QueryInfo

the QueryInfo instance that provides the query static parts used to create the new instance now augmented to accommodate the extra number of parameters

batchCount:int

the number of batches, i.e., the number of times the VALUES clause needs to be repeated inside the new query

Method Detail

containsOnDuplicateKeyUpdateback to summary
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'.

Returns:boolean

true if the query or any of the original queries contain an ON DUPLICATE KEY UPDATE clause.

containsOnDuplicateKeyUpdateClauseback to summary
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.

Parameters
sql:String

the query to search

noBackslashEscapes:boolean

whether backslash escapes are disabled or not.

Returns:boolean

true if the query contains an ON DUPLICATE KEY UPDATE clause, false otherwise

firstCharOfStatementUcback to summary
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.

Parameters
sql:String

the query to search

noBackslashEscapes:boolean

whether backslash escapes are disabled or not

Returns:char

the first character of the query, in upper case

getContextForWithStatementback to summary
private static String getContextForWithStatement(String sql, boolean noBackslashEscapes)

Returns the context of the WITH statement. The context can be: SELECT, TABLE, VALUES, UPDATE or DELETE. This operation does not take into consideration the multiplicity of queries in the specified SQL.

Parameters
sql:String

the query to search

noBackslashEscapes:boolean

whether backslash escapes are disabled or not

Returns:String

the context of the WITH statement or null if failed to find it

getFirstStmtCharback to summary
public char getFirstStmtChar()

Returns the first character of the statement from the query used to build this QueryInfo.

Returns:char

the first character of the statement

getNumberOfPlaceholdersback to summary
public int getNumberOfPlaceholders()

Returns the number of placeholders found in the query.

Returns:int

the number of placeholders in the query

getNumberOfQueriesback to summary
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.

Returns:int

the number of queries identified in the original SQL string

getPlaceholderPurposesback to summary
public List<PlaceholderPurpose> getPlaceholderPurposes()

Returns a list containing the purpose of each one of the placeholders found according to their positional ordering.

Returns:List<PlaceholderPurpose>

the list of the placeholders purposes.

getQueryInfoForBatchback to summary
public QueryInfo getQueryInfoForBatch(int count)

Returns a QueryInfo for a multi-values INSERT/REPLACE assembled for the specified batch count, without re-parsing.

Parameters
count:int

the number of parameter batches

Returns:QueryInfo

QueryInfo

getQueryReturnTypeback to summary
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.

Returns:QueryReturnType

the return type of the parsed query

getQueryReturnTypeback to summary
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.

Parameters
sql:String

the query to check

noBackslashEscapes:boolean

whether backslash escapes are disabled or not

Returns:QueryReturnType

the return type that can be expected from the given query, one of the elements of QueryReturnType.

getSqlForBatchback to summary
public String getSqlForBatch()

Returns a preparable query for the batch count of this QueryInfo.

Returns:String

a preparable query string with the appropriate number of placeholders

getSqlForBatchback to summary
public String getSqlForBatch(int count)

Returns a preparable query for the specified batch count.

Parameters
count:int

number of parameter batches

Returns:String

a preparable query string with the appropriate number of placeholders

getStatementKeywordback to summary
public String getStatementKeyword()

Returns the statement keyword from the query used to build this QueryInfo.

Returns:String

the statement keyword

getStatementKeywordback to summary
public static String getStatementKeyword(String sql, boolean noBackslashEscapes)

Finds and returns the statement keyword from the specified SQL, skipping comments and quoted text.

Parameters
sql:String

the query to search

noBackslashEscapes:boolean

whether backslash escapes are disabled or not

Returns:String

the statement keyword of the query

getStaticSqlPartsback to summary
public byte[][] getStaticSqlParts()

Returns the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located.

Returns:byte[][]

the static sections of the parsed query, as byte arrays, split by the places where the placeholders were located

getValuesClauseLengthback to summary
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.

Returns:int

the length of the parsed VALUES clause section, including the placeholder characters themselves, otherwise returns -1

indexOfStatementKeywordback to summary
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.

Parameters
sql:String

the query to search

noBackslashEscapes:boolean

whether backslash escapes are disabled or not

Returns:int

the position of the first character of the query

isReadOnlySafeQueryback to summary
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.

Parameters
sql:String

the query to check

noBackslashEscapes:boolean

whether backslash escapes are disabled or not

Returns:boolean

true if the query is read-only safe, false otherwise.

isRewritableWithMultiValuesClauseback to summary
public boolean isRewritableWithMultiValuesClause()

Can this query be rewritten as a multi-values clause?

Returns:boolean

true if the query can be rewritten as a multi-values query.