Class SFBaseStatement

  • Direct Known Subclasses:
    SFStatement

    public abstract class SFBaseStatement
    extends Object
    Base abstract class for an SFStatement implementation. Statements are used in executing queries, both in standard and prepared forms. They are accessed by users via the public API class, SnowflakeStatementV(x).
    • Field Detail

      • MAX_STATEMENT_PARAMETERS

        protected static final int MAX_STATEMENT_PARAMETERS
        See Also:
        Constant Field Values
      • statementParametersMap

        protected final Map<String,​Object> statementParametersMap
      • queryTimeout

        protected int queryTimeout
    • Constructor Detail

      • SFBaseStatement

        public SFBaseStatement()
    • Method Detail

      • addProperty

        public void addProperty​(String propertyName,
                                Object propertyValue)
                         throws SFException
        Add a statement parameter

        Make sure a property is not added more than once and the number of properties does not exceed limit.

        Parameters:
        propertyName - property name
        propertyValue - property value
        Throws:
        SFException - if too many parameters for a statement
      • describe

        public abstract SFPreparedStatementMetaData describe​(String sql)
                                                      throws SFException,
                                                             SQLException
        Describe a statement. This is invoked when prepareStatement() occurs. SFStatementMetadata should be returned by this action, which contains metadata such as the schema of the result.
        Parameters:
        sql - The SQL string of the query/statement.
        Returns:
        metadata of statement including resultset metadata and binding information
        Throws:
        SQLException - if connection is already closed
        SFException - if result set is null
      • asyncExecute

        public abstract SFBaseResultSet asyncExecute​(String sql,
                                                     Map<String,​ParameterBindingDTO> parametersBinding,
                                                     SFBaseStatement.CallingMethod caller,
                                                     ExecTimeTelemetryData execTimeData)
                                              throws SQLException,
                                                     SFException
        Execute sql asynchronously. Note that at a minimum, this does not have to be supported; if executeAsyncQuery() is called from SnowflakeStatement and the SFConnectionHandler's supportsAsyncQuery() returns false, an exception is thrown. If this is un-implemented, then supportsAsyncQuery() should return false.
        Parameters:
        sql - sql statement.
        parametersBinding - parameters to bind
        caller - the JDBC interface method that called this method, if any
        Returns:
        whether there is result set or not
        Throws:
        SQLException - if failed to execute sql
        SFException - exception raised from Snowflake components
        SQLException - if SQL error occurs
      • close

        public abstract void close()
        Closes the statement. Open result sets are closed, connections are terminated, state is cleared, etc.
      • executeSetProperty

        public void executeSetProperty​(String sql)
        Sets a property within session properties, i.e., if the sql is using set-sf-property
        Parameters:
        sql - the set property sql
      • isFileTransfer

        public static boolean isFileTransfer​(String sql)
        A method to check if a sql is file upload statement with consideration for potential comments in front of put keyword.

        Parameters:
        sql - sql statement
        Returns:
        true if the command is upload statement
      • hasChildren

        public abstract boolean hasChildren()
        If this is a multi-statement, i.e., has child results.
      • getSFBaseSession

        public abstract SFBaseSession getSFBaseSession()
        Returns the SFBaseSession associated with this SFBaseStatement.
      • getResultSet

        public abstract SFBaseResultSet getResultSet()
        Retrieves the current result as a ResultSet, if any. This is invoked by SnowflakeStatement and should return an SFBaseResultSet, which is then wrapped in a SnowflakeResultSet.
      • getMoreResults

        public abstract boolean getMoreResults​(int current)
                                        throws SQLException
        Sets the result set to the next one, if available.
        Parameters:
        current - What to do with the current result. One of Statement.CLOSE_CURRENT_RESULT, Statement.CLOSE_ALL_RESULTS, or Statement.KEEP_CURRENT_RESULT
        Returns:
        true if there is a next result and it's a result set false if there are no more results, or there is a next result and it's an update count
        Throws:
        SQLException - if something fails while getting the next result
      • getConservativeMemoryLimit

        public abstract long getConservativeMemoryLimit()
      • getConservativePrefetchThreads

        public abstract int getConservativePrefetchThreads()
      • getChildQueryIds

        public abstract String[] getChildQueryIds​(String queryID)
                                           throws SQLException
        Returns:
        the child query IDs for the multiple statements query.
        Throws:
        SQLException