Package net.snowflake.client.core

## Class SFBaseStatement

- java.lang.Object
- - net.snowflake.client.core.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).

### Nested Class Summary

Nested Classes
`static class` `SFBaseStatement.CallingMethod` The type of query that is being executed.

### Field Summary

Fields
`protected static int` `MAX_STATEMENT_PARAMETERS`
`protected int` `queryTimeout`
`protected Map<String,​Object>` `statementParametersMap`

### Constructor Summary

Constructors
`SFBaseStatement()`

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`void` `addProperty​(String propertyName, Object propertyValue)` Add a statement parameter
`abstract SFBaseResultSet` `asyncExecute​(String sql, Map<String,​ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData)` Execute sql asynchronously.
`abstract void` `cancel()` Aborts the statement.
`abstract void` `close()` Closes the statement.
`abstract SFPreparedStatementMetaData` `describe​(String sql)` Describe a statement.
`abstract SFBaseResultSet` `execute​(String sql, Map<String,​ParameterBindingDTO> parametersBinding, SFBaseStatement.CallingMethod caller, ExecTimeTelemetryData execTimeData)` Executes the given SQL string.
`void` `executeSetProperty​(String sql)` Sets a property within session properties, i.e., if the sql is using set-sf-property
`abstract String[]` `getChildQueryIds​(String queryID)`
`abstract long` `getConservativeMemoryLimit()`
`abstract int` `getConservativePrefetchThreads()`
`abstract boolean` `getMoreResults​(int current)` Sets the result set to the next one, if available.
`abstract SFBaseResultSet` `getResultSet()` Retrieves the current result as a ResultSet, if any.
`abstract SFBaseSession` `getSFBaseSession()` Returns the SFBaseSession associated with this SFBaseStatement.
`Map<String,​Object>` `getStatementParameters()`
`abstract boolean` `hasChildren()` If this is a multi-statement, i.e., has child results.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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

#### getStatementParameters

    public Map<String,​Object> getStatementParameters()

#### 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

#### execute

    public abstract SFBaseResultSet execute​(String sql,
                                            Map<String,​ParameterBindingDTO> parametersBinding,
                                            SFBaseStatement.CallingMethod caller,
                                            ExecTimeTelemetryData execTimeData)
                                     throws SQLException,
                                            SFException

Executes the given SQL string.

Parameters:
  `sql` - The SQL string to execute, synchronously.
  `parametersBinding` - parameters to bind
  `caller` - the JDBC interface method that called this method, if any
  `execTimeData` - OOB telemetry object to record timings
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

#### 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.

#### cancel

    public abstract void cancel()
                         throws SFException,
                                SQLException

Aborts the statement.

Throws:
  `SFException` - if the statement is already closed.
  `SQLException` - if there are server-side errors from trying to abort.

#### 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`