net.snowflake.client.core

## Class SFStatement

- java.lang.Object
- - net.snowflake.client.core.SFStatement

    public class SFStatement
    extends Object

Snowflake statement

Author:
  jhuang

### Constructor Summary

Constructors
Constructor and Description
`SFStatement(SFSession session)`
`SFStatement(SFSession session, String sql)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addProperty(String propertyName, Object propertyValue)` Add a statement parameter Make sure a property is not added more than once and the number of properties does not exceed limit.
`void` `cancel()`
`protected void` `cancelHelper(String sql, String mediaType)` A helper method to build URL and cancel the SQL for exec
`void` `close()`
`SFStatementMetaData` `describe()` Describe the statement
`SFStatementMetaData` `describe(String sql)` Describe a statement
`SFBaseResultSet` `execute(String sql)` Execute sql
`protected SFBaseResultSet` `executeFileTransfer(String sql)`
`Object` `executeHelper(String sql, String mediaType, Map<String,Map<String,Object>> bindValues, boolean describeOnly)` A helper method to build URL and submit the SQL to snowflake for exec
`protected SFBaseResultSet` `executeQuery(String sql)` Execute SQL query
`protected SFBaseResultSet` `executeQuery(String sql, boolean describeOnly)` Execute SQL query with an option for describe only
`protected SFBaseResultSet` `executeQueryInternal(String sql, Map<String,Map<String,Object>> parameterBindings, boolean describeOnly)` Internal method for executing a query with bindings accepted.
`void` `executeSetProperty(String sql)`
`protected SFSession` `getSession()`
`protected 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.
`protected void` `releaseConnection()`
`void` `setValue(String parameterName, String value, String sqlType)` Bind value with the given type for the parameter with the given index.
`void` `setValues(String parameterName, List<String> values, String sqlType)` Bind the list of values with the given type for the parameter with the given index.

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

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

### Constructor Detail

#### SFStatement

    public SFStatement(SFSession session)

#### SFStatement

    public SFStatement(SFSession session,
                       String sql)

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

#### executeQuery

    protected SFBaseResultSet executeQuery(String sql)
                                    throws SQLException,
                                           SFException

Execute SQL query

Parameters:
  `sql` - sql statement
Returns:
  ResultSet
Throws:
  `SQLException` - if failed to execute the query
  `SFException` - if failed to execute the query

#### executeQuery

    protected SFBaseResultSet executeQuery(String sql,
                                           boolean describeOnly)
                                    throws SQLException,
                                           SFException

Execute SQL query with an option for describe only

Parameters:
  `sql` - sql statement
  `describeOnly` - true if describe only
Returns:
  query result set
Throws:
  `SQLException` - if connection is already closed
  `SFException` - if result set is null

#### describe

    public SFStatementMetaData describe(String sql)
                                 throws SFException,
                                        SQLException

Describe a statement

Parameters:
  `sql` - statement
Returns:
  metadata of statement including result set metadata and binding information
Throws:
  `SQLException` - if connection is already closed
  `SFException` - if result set is null

#### describe

    public SFStatementMetaData describe()
                                 throws SFException,
                                        SQLException

Describe the statement

Returns:
  metadata of statement including result set metadata and binding information
Throws:
  `SQLException` - if connection is already closed
  `SFException` - if result set is null

#### executeQueryInternal

    protected SFBaseResultSet executeQueryInternal(String sql,
                                                   Map<String,Map<String,Object>> parameterBindings,
                                                   boolean describeOnly)
                                            throws SQLException,
                                                   SFException

Internal method for executing a query with bindings accepted.

Parameters:
  `sql` - sql statement
  `parameterBindings` - binding information
  `describeOnly` - true if just showing result set metadata
Returns:
  snowflake query result set
Throws:
  `SQLException` - if connection is already closed
  `SFException` - if result set is null

#### executeHelper

    public Object executeHelper(String sql,
                                String mediaType,
                                Map<String,Map<String,Object>> bindValues,
                                boolean describeOnly)
                         throws SnowflakeSQLException,
                                SFException

A helper method to build URL and submit the SQL to snowflake for exec

Parameters:
  `sql` - sql statement
  `mediaType` - media type
  `bindValues` - map of binding values
  `describeOnly` - whether only show the result set metadata
Returns:
  query result set
Throws:
  `SFException` - if query is canceled
  `SnowflakeSQLException` - if query is already running

#### cancelHelper

    protected void cancelHelper(String sql,
                                String mediaType)
                         throws SnowflakeSQLException,
                                SFException

A helper method to build URL and cancel the SQL for exec

Parameters:
  `sql` - sql statement
  `mediaType` - media type
Throws:
  `SnowflakeSQLException` - if failed to cancel the statement
  `SFException` - if statement is already closed

#### releaseConnection

    protected void releaseConnection()

#### isFileTransfer

    protected 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

#### execute

    public SFBaseResultSet execute(String sql)
                            throws SQLException,
                                   SFException

Execute sql

Parameters:
  `sql` - sql statement
Returns:
  whether there is result set or not
Throws:
  `SQLException` - if failed to execute sql
  `SFException` - exception raised from Snowflake components

#### executeFileTransfer

    protected SFBaseResultSet executeFileTransfer(String sql)
                                           throws SQLException,
                                                  SFException

Throws:
  `SQLException`
  `SFException`

#### close

    public void close()
               throws SQLException

Throws:
  `SQLException`

#### cancel

    public void cancel()
                throws SFException,
                       SQLException

Throws:
  `SFException`
  `SQLException`

#### executeSetProperty

    public void executeSetProperty(String sql)

#### setValues

    public void setValues(String parameterName,
                          List<String> values,
                          String sqlType)

Bind the list of values with the given type for the parameter with the given index.

Parameters:
  `parameterName` - parameter name in the query string
  `values` - list of values bound to the parameter
  `sqlType` - Snowflake SQL type name as defined in SnowflakeType.java

#### setValue

    public void setValue(String parameterName,
                         String value,
                         String sqlType)

Bind value with the given type for the parameter with the given index.

Parameters:
  `parameterName` - parameter name in the query string
  `value` - value bound to the parameter
  `sqlType:` - Snowflake SQL type name as defined in SnowflakeType.java

#### getSession

    protected SFSession getSession()