程序包 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.
    • 构造器详细资料

      • QueryInfo

        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.
        参数:
        sql - the query SQL string to parse and analyze
        session - 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.
    • 方法详细资料

      • 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 this QueryInfo.
        返回:
        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`.
        返回:
        true if 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?
        返回:
        true if the query can be rewritten as a multi-values query.
      • getQueryInfoForBatch

        public QueryInfo getQueryInfoForBatch​(int count)
        Returns a QueryInfo for 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 this QueryInfo.
        返回:
        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 search
        noBackslashEscapes - 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 search
        noBackslashEscapes - 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 check
        noBackslashEscapes - whether backslash escapes are disabled or not
        返回:
        true if the query is read-only safe, false otherwise.
      • 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 check
        noBackslashEscapes - 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 search
        noBackslashEscapes - whether backslash escapes are disabled or not.
        返回:
        true if the query contains an ON DUPLICATE KEY UPDATE clause, false otherwise