com.almworks.sqlite4java
Class SQLiteStatement

java.lang.Object
  extended by com.almworks.sqlite4java.SQLiteStatement

public final class SQLiteStatement
extends java.lang.Object

SQLiteStatement wraps an instance of compiled SQL statement, represented as sqlite3_stmt* handle in SQLite C Interface.

You get instances of SQLiteStatement via SQLiteConnection.prepare(com.almworks.sqlite4java.SQLParts, boolean) methods. After you've done using the statement, you have to free it using dispose() method. Statements are usually cached, so until you release the statement, prepare calls for the same SQL will result in needless compilation.

Typical use includes binding parameters, then executing steps and reading columns. Most methods directly correspond to the sqlite3 C interface methods.

 SQLiteStatement statement = connection.prepare(".....");
 try {
   statement.bind(....).bind(....);
   while (statement.step()) {
      statement.columnXXX(...);
   }
 } finally {
   statement.dispose();
 }
 

Unless a method is marked as thread-safe, it is confined to the thread that has opened the connection. Calling a confined method from a different thread will result in exception.

Author:
Igor Sereda
See Also:
sqlite3_stmt*

Field Summary
static SQLiteStatement DISPOSED
          Public instance of initially disposed, dummy statement.
 
Method Summary
 SQLiteStatement bind(int index, byte[] value)
          Binds SQL parameter to a BLOB value, represented by a byte array.
 SQLiteStatement bind(int index, byte[] value, int offset, int length)
          Binds SQL parameter to a BLOB value, represented by a range within byte array.
 SQLiteStatement bind(int index, double value)
          Binds SQL parameter to a value of type double.
 SQLiteStatement bind(int index, int value)
          Binds SQL parameter to a value of type int.
 SQLiteStatement bind(int index, long value)
          Binds SQL parameter to a value of type long.
 SQLiteStatement bind(int index, java.lang.String value)
          Binds SQL parameter to a value of type String.
 SQLiteStatement bind(java.lang.String name, byte[] value)
          Binds SQL parameter to a BLOB value, represented by a byte array.
 SQLiteStatement bind(java.lang.String name, byte[] value, int offset, int length)
          Binds SQL parameter to a BLOB value, represented by a range within byte array.
 SQLiteStatement bind(java.lang.String name, double value)
          Binds SQL parameter to a value of type double.
 SQLiteStatement bind(java.lang.String name, int value)
          Binds SQL parameter to a value of type int.
 SQLiteStatement bind(java.lang.String name, long value)
          Binds SQL parameter to a value of type long.
 SQLiteStatement bind(java.lang.String name, java.lang.String value)
          Binds SQL parameter to a value of type String.
 SQLiteStatement bindNull(int index)
          Binds SQL parameter to a NULL value.
 SQLiteStatement bindNull(java.lang.String name)
          Binds SQL parameter to a NULL value.
 java.io.OutputStream bindStream(int index)
          Binds SQL parameter to a BLOB value, represented by a stream.
 java.io.OutputStream bindStream(int index, int bufferSize)
          Binds SQL parameter to a BLOB value, represented by a stream.
 java.io.OutputStream bindStream(java.lang.String name)
          Binds SQL parameter to a BLOB value, represented by a stream.
 java.io.OutputStream bindStream(java.lang.String name, int bufferSize)
          Binds SQL parameter to a BLOB value, represented by a stream.
 SQLiteStatement bindZeroBlob(int index, int length)
          Binds SQL parameter to a BLOB value, consiting of a given number of zero bytes.
 SQLiteStatement bindZeroBlob(java.lang.String name, int length)
          Binds SQL parameter to a BLOB value, consiting of a given number of zero bytes.
 void cancel()
          Cancels the currently running statement.
 SQLiteStatement clearBindings()
          Clears parameter bindings, if there are any.
 byte[] columnBlob(int column)
          Gets a column value after step has returned a row of the result set.
 int columnCount()
          Gets the number of columns in the result set.
 double columnDouble(int column)
          Gets a column value after step has returned a row of the result set.
 int columnInt(int column)
          Gets a column value after step has returned a row of the result set.
 long columnLong(int column)
          Gets a column value after step has returned a row of the result set.
 boolean columnNull(int column)
          Checks if the value returned in the given column is null.
 java.io.InputStream columnStream(int column)
          Gets an InputStream for reading a BLOB column value after step has returned a row of the result set.
 java.lang.String columnString(int column)
          Gets a column value after step has returned a row of the result set.
 int columnType(int column)
          Gets a type of a column after step() has returned a row.
 java.lang.Object columnValue(int column)
          Gets a column value after step has returned a row of the result set.
 void dispose()
          Disposes this statement and frees allocated resources.
 int getBindParameterCount()
          Returns the number of parameters that can be bound.
 int getBindParameterIndex(java.lang.String name)
          Returns the index of a bind parameter with a given name, as defined in the SQL.
 java.lang.String getBindParameterName(int index)
          Returns the name of a given bind parameter, as defined in the SQL.
 java.lang.String getColumnDatabaseName(int column)
          Gets a name of the column's table's database in the result set.
 java.lang.String getColumnName(int column)
          Gets a name of the column in the result set.
 java.lang.String getColumnOriginName(int column)
          Gets the original name of the column that is behind the given column in the result set.
 java.lang.String getColumnTableName(int column)
          Gets a name of the column's table in the result set.
 SQLParts getSqlParts()
          Returns the immutable SQLParts object that was used to create this instance.
 boolean hasBindings()
          Checks if some parameters were bound
 boolean hasRow()
          Checks whether there's data to be read with columnXYZ methods.
 boolean hasStepped()
          Checks if the statement has been evaluated
 boolean isDisposed()
           
 boolean isReadOnly()
          Check if the underlying statement is a SELECT.
 int loadInts(int column, int[] buffer, int offset, int length)
          Loads int values returned from a query into a buffer.
 int loadLongs(int column, long[] buffer, int offset, int length)
          Loads long values returned from a query into a buffer.
 SQLiteStatement reset()
          Convenience method that resets the statement and clears bindings.
 SQLiteStatement reset(boolean clearBindings)
          Resets the statement if it has been stepped, allowing SQL to be run again.
 boolean step()
          Evaluates SQL statement until either there's data to be read, an error occurs, or the statement completes.
 SQLiteStatement stepThrough()
          Convenience method that ignores the available data and steps through the SQL statement until evaluation is completed.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DISPOSED

public static final SQLiteStatement DISPOSED
Public instance of initially disposed, dummy statement. To be used as a guardian object.

Method Detail

isDisposed

public boolean isDisposed()
Returns:
true if the statement is disposed and cannot be used

getSqlParts

public SQLParts getSqlParts()
Returns the immutable SQLParts object that was used to create this instance.

This method is thread-safe.

Returns:
SQL used for this statement

dispose

public void dispose()
Disposes this statement and frees allocated resources. If the statement's handle is cached, it is returned to the connection's cache and can be reused by later calls to prepare

Calling this method on an already disposed instance has no effect.

After SQLiteStatement instance is disposed, it is no longer usable and holds no references to its originating connection or SQLite database.


reset

public SQLiteStatement reset(boolean clearBindings)
                      throws SQLiteException
Resets the statement if it has been stepped, allowing SQL to be run again. Optionally, clears bindings all binding.

If clearBinding parameter is false, then all preceding bindings remain in place. You can change some or none of them and run statement again.

Parameters:
clearBindings - if true, all parameters will be set to NULL
Returns:
this statement
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_reset, sqlite3_clear_bindings

reset

public SQLiteStatement reset()
                      throws SQLiteException
Convenience method that resets the statement and clears bindings. See reset(boolean) for a detailed description.

Returns:
this statement
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class

clearBindings

public SQLiteStatement clearBindings()
                              throws SQLiteException
Clears parameter bindings, if there are any. All parameters are set to NULL.

Returns:
this statement
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_clear_bindings

step

public boolean step()
             throws SQLiteException
Evaluates SQL statement until either there's data to be read, an error occurs, or the statement completes.

An SQL statement is represented as a VM program in SQLite, and a call to step runs that program until there's a "break point".

Note that since SQlite 3.7, reset(boolean) method is called by step() automatically if anything other than SQLITE_ROW is returned.

This method can produce one of the three results:

Returns:
true if there is data (SQLITE_ROW) was returned, false if statement has been completed (SQLITE_DONE)
Throws:
SQLiteException - if result code from sqlite3_step was neither SQLITE_ROW nor SQLITE_DONE, or if any other problem occurs
See Also:
sqlite3_step

stepThrough

public SQLiteStatement stepThrough()
                            throws SQLiteException
Convenience method that ignores the available data and steps through the SQL statement until evaluation is completed. See step() for details.

Most often it's used to chain calls.

Returns:
this statement
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class

cancel

public void cancel()
Cancels the currently running statement. This method has effect only during execution of the step() method, and so it is run from a different thread.

This method works by setting a cancel flag, which is checked by the progress callback. Hence, if the progress callback is disabled, this method will not have effect. Likewise, if stepsPerCallback parameter is set to large values, the reaction to this call may be far from immediate.

If execution is cancelled, the step() method will throw SQLiteInterruptedException, and transaction will be rolled back.

This method is thread-safe.

See Also:
SQLiteConnection.setStepsPerCallback(int), sqlite3_progress_callback

hasRow

public boolean hasRow()
Checks whether there's data to be read with columnXYZ methods.

Returns:
true if last call to step() has returned true

hasBindings

public boolean hasBindings()
Checks if some parameters were bound

Returns:
true if at least one of the statement parameters has been bound to a value

hasStepped

public boolean hasStepped()
Checks if the statement has been evaluated

Returns:
true if the statement has been stepped at least once, and not reset

loadInts

public int loadInts(int column,
                    int[] buffer,
                    int offset,
                    int length)
             throws SQLiteException
Loads int values returned from a query into a buffer.

The purpose of this method is to run a query and load a single-column result in bulk. This could save a lot of time by making a single JNI call instead of 2*N calls to step() and columnInt().

If result set contains NULL value, it's replaced with 0.

This method may be called iteratively with a fixed-size buffer. For example:

   SQLiteStatement st = connection.prepare("SELECT id FROM articles WHERE text LIKE '%whatever%'");
   try {
     int[] buffer = new int[1000];
     while (!st.hasStepped() || st.hasRow()) {
       int loaded = st.loadInts(0, buffer, 0, buffer.length);
       processResult(buffer, 0, loaded);
     }
   } finally {
     st.dispose();
   }
 

After method finishes, the number of rows loaded is returned and statement's hasRow() method indicates whether more rows are available.

Parameters:
column - column index, as used in columnInt(int)
buffer - buffer for accepting loaded integers
offset - offset in the buffer to start writing
length - maximum number of integers to load from the database
Returns:
actual number of integers loaded
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class

loadLongs

public int loadLongs(int column,
                     long[] buffer,
                     int offset,
                     int length)
              throws SQLiteException
Loads long values returned from a query into a buffer.

The purpose of this method is to run a query and load a single-column result in bulk. This could save a lot of time by making a single JNI call instead of 2*N calls to step() and columnLong().

If result set contains NULL value, it's replaced with 0.

This method may be called iteratively with a fixed-size buffer. For example:

   SQLiteStatement st = connection.prepare("SELECT id FROM articles WHERE text LIKE '%whatever%'");
   try {
     long[] buffer = new long[1000];
     while (!st.hasStepped() || st.hasRow()) {
       int loaded = st.loadInts(0, buffer, 0, buffer.length);
       processResult(buffer, 0, loaded);
     }
   } finally {
     st.dispose();
   }
 

After method finishes, the number of rows loaded is returned and statement's hasRow() method indicates whether more rows are available.

Parameters:
column - column index, as used in columnInt(int)
buffer - buffer for accepting loaded longs
offset - offset in the buffer to start writing
length - maximum number of integers to load from the database
Returns:
actual number of integers loaded
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class

getBindParameterCount

public int getBindParameterCount()
                          throws SQLiteException
Returns the number of parameters that can be bound.

Returns:
the number of SQL parameters
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_parameter_count

getBindParameterName

public java.lang.String getBindParameterName(int index)
                                      throws SQLiteException
Returns the name of a given bind parameter, as defined in the SQL.

Parameters:
index - the index of a bindable parameter, starting with 1
Returns:
the name of the parameter, e.g. "?PARAM1", or null if parameter is anonymous (just "?")
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_parameter_name

getBindParameterIndex

public int getBindParameterIndex(java.lang.String name)
                          throws SQLiteException
Returns the index of a bind parameter with a given name, as defined in the SQL.

Parameters:
name - parameter name
Returns:
the index of the parameter in the SQL, or 0 if no such parameter found
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_parameter_index

bind

public SQLiteStatement bind(int index,
                            double value)
                     throws SQLiteException
Binds SQL parameter to a value of type double.

Parameters:
index - the index of the boundable parameter, starting with 1
value - non-null double value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_double

bind

public SQLiteStatement bind(java.lang.String name,
                            double value)
                     throws SQLiteException
Binds SQL parameter to a value of type double.

Parameters:
name - parameter name
value - non-null double value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_double

bind

public SQLiteStatement bind(int index,
                            int value)
                     throws SQLiteException
Binds SQL parameter to a value of type int.

Parameters:
index - the index of the boundable parameter, starting with 1
value - non-null int value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_int

bind

public SQLiteStatement bind(java.lang.String name,
                            int value)
                     throws SQLiteException
Binds SQL parameter to a value of type int.

Parameters:
name - parameter name
value - non-null int value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_int

bind

public SQLiteStatement bind(int index,
                            long value)
                     throws SQLiteException
Binds SQL parameter to a value of type long.

Parameters:
index - the index of the boundable parameter, starting with 1
value - non-null long value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_int64

bind

public SQLiteStatement bind(java.lang.String name,
                            long value)
                     throws SQLiteException
Binds SQL parameter to a value of type long.

Parameters:
name - parameter name
value - non-null long value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_int64

bind

public SQLiteStatement bind(int index,
                            java.lang.String value)
                     throws SQLiteException
Binds SQL parameter to a value of type String.

Parameters:
index - the index of the boundable parameter, starting with 1
value - String value, if null then bindNull(int) will be called
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_text

bind

public SQLiteStatement bind(java.lang.String name,
                            java.lang.String value)
                     throws SQLiteException
Binds SQL parameter to a value of type String.

Parameters:
name - parameter name
value - String value, if null then bindNull(int) will be called
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_text

bind

public SQLiteStatement bind(int index,
                            byte[] value)
                     throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a byte array.

Parameters:
index - the index of the boundable parameter, starting with 1
value - an array of bytes to be used as the blob value; if null, bindNull(int) is called
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bind

public SQLiteStatement bind(java.lang.String name,
                            byte[] value)
                     throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a byte array.

Parameters:
name - parameter name
value - an array of bytes to be used as the blob value; if null, bindNull(int) is called
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bind

public SQLiteStatement bind(int index,
                            byte[] value,
                            int offset,
                            int length)
                     throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a range within byte array.

Parameters:
index - the index of the boundable parameter, starting with 1
value - an array of bytes; if null, bindNull(int) is called
offset - position in the byte array to start reading value from
length - number of bytes to read from value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bind

public SQLiteStatement bind(java.lang.String name,
                            byte[] value,
                            int offset,
                            int length)
                     throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a range within byte array.

Parameters:
name - parameter name
value - an array of bytes; if null, bindNull(int) is called
offset - position in the byte array to start reading value from
length - number of bytes to read from value
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bindZeroBlob

public SQLiteStatement bindZeroBlob(int index,
                                    int length)
                             throws SQLiteException
Binds SQL parameter to a BLOB value, consiting of a given number of zero bytes.

Parameters:
index - the index of the boundable parameter, starting with 1
length - number of zero bytes to use as a parameter
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_zeroblob

bindZeroBlob

public SQLiteStatement bindZeroBlob(java.lang.String name,
                                    int length)
                             throws SQLiteException
Binds SQL parameter to a BLOB value, consiting of a given number of zero bytes.

Parameters:
name - parameter name
length - number of zero bytes to use as a parameter
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_zeroblob

bindNull

public SQLiteStatement bindNull(int index)
                         throws SQLiteException
Binds SQL parameter to a NULL value.

Parameters:
index - the index of the boundable parameter, starting with 1
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_null

bindNull

public SQLiteStatement bindNull(java.lang.String name)
                         throws SQLiteException
Binds SQL parameter to a NULL value.

Parameters:
name - parameter name
Returns:
this object
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_null

bindStream

public java.io.OutputStream bindStream(int index)
                                throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a stream. The stream can further be used to write into, before the first call to step().

After the application is done writing to the parameter stream, it should be closed.

If statement is executed before the stream is closed, the value will not be set for the parameter.

Parameters:
index - the index of the boundable parameter, starting with 1
Returns:
stream to receive data for the BLOB parameter
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bindStream

public java.io.OutputStream bindStream(java.lang.String name)
                                throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a stream. The stream can further be used to write into, before the first call to step().

After the application is done writing to the parameter stream, it should be closed.

If statement is executed before the stream is closed, the value will not be set for the parameter.

Parameters:
name - parameter name
Returns:
stream to receive data for the BLOB parameter
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bindStream

public java.io.OutputStream bindStream(int index,
                                       int bufferSize)
                                throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a stream. The stream can further be used to write into, before the first call to step().

After the application is done writing to the parameter stream, it should be closed.

If statement is executed before the stream is closed, the value will not be set for the parameter.

Parameters:
index - the index of the boundable parameter, starting with 1
bufferSize - the number of bytes to be allocated for the buffer (the buffer will grow as needed)
Returns:
stream to receive data for the BLOB parameter
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

bindStream

public java.io.OutputStream bindStream(java.lang.String name,
                                       int bufferSize)
                                throws SQLiteException
Binds SQL parameter to a BLOB value, represented by a stream. The stream can further be used to write into, before the first call to step().

After the application is done writing to the parameter stream, it should be closed.

If statement is executed before the stream is closed, the value will not be set for the parameter.

Parameters:
name - parameter name
bufferSize - the number of bytes to be allocated for the buffer (the buffer will grow as needed)
Returns:
stream to receive data for the BLOB parameter
Throws:
SQLiteException - if SQLite returns an error, or if parameter with specified name was not found, or if the call violates the contract of this class
See Also:
sqlite3_bind_blob

columnString

public java.lang.String columnString(int column)
                              throws SQLiteException
Gets a column value after step has returned a row of the result set.

Call this method to retrieve data of type String after step() has returned true.

Parameters:
column - the index of the column, starting with 0
Returns:
a String value or null if database value is NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_text16

columnInt

public int columnInt(int column)
              throws SQLiteException
Gets a column value after step has returned a row of the result set.

Call this method to retrieve data of type int after step() has returned true.

Parameters:
column - the index of the column, starting with 0
Returns:
an int value, or value converted to int, or 0 if value is NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_int

columnDouble

public double columnDouble(int column)
                    throws SQLiteException
Gets a column value after step has returned a row of the result set.

Call this method to retrieve data of type double after step() has returned true.

Parameters:
column - the index of the column, starting with 0
Returns:
a double value, or value converted to double, or 0.0 if value is NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_double

columnLong

public long columnLong(int column)
                throws SQLiteException
Gets a column value after step has returned a row of the result set.

Call this method to retrieve data of type long after step() has returned true.

Parameters:
column - the index of the column, starting with 0
Returns:
a long value, or value converted to long, or 0L if the value is NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_int64

columnBlob

public byte[] columnBlob(int column)
                  throws SQLiteException
Gets a column value after step has returned a row of the result set.

Call this method to retrieve data of type BLOB after step() has returned true.

Parameters:
column - the index of the column, starting with 0
Returns:
a byte array with the value, or null if the value is NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_blob

columnStream

public java.io.InputStream columnStream(int column)
                                 throws SQLiteException
Gets an InputStream for reading a BLOB column value after step has returned a row of the result set.

Call this method to retrieve data of type BLOB after step() has returned true.

The stream should be read and closed before next call to step or reset. Otherwise, the stream is automatically closed and disposed, and the following attempts to read from it result in IOException.

Parameters:
column - the index of the column, starting with 0
Returns:
a stream to read value from, or null if the value is NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_blob

columnNull

public boolean columnNull(int column)
                   throws SQLiteException
Checks if the value returned in the given column is null.

Parameters:
column - the index of the column, starting with 0
Returns:
true if the result for the column was NULL
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_type

columnCount

public int columnCount()
                throws SQLiteException
Gets the number of columns in the result set.

This method may be called before statement is executed, during execution or after statement has executed ( step() returned false).

However, for some statements where the number of columns may vary - such as "SELECT * FROM ..." - the correct result is guaranteed only if method is called during statement execution, when step() has returned true. (That is so because sqlite3_column_count function does not force statement recompilation if database schema has changed, but sqlite3_step does.)

Returns:
the number of columns
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_count

columnValue

public java.lang.Object columnValue(int column)
                             throws SQLiteException
Gets a column value after step has returned a row of the result set.

Call this method to retrieve data of any type after step() has returned true.

The class of the object returned depends on the value and the type of value reported by SQLite. It can be:

Parameters:
column - the index of the column, starting with 0
Returns:
an object containing the value
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_blob

columnType

public int columnType(int column)
               throws SQLiteException
Gets a type of a column after step() has returned a row.

Call this method to retrieve data of any type after step() has returned true.

Note that SQLite has dynamic typing, so this method returns the affinity of the specified column. See dynamic typing for details.

This method returns an integer constant, defined in SQLiteConstants: SQLITE_NULL, SQLITE_INTEGER, SQLITE_TEXT, SQLITE_BLOB or SQLITE_FLOAT.

The value returned by this method is only meaningful if no type conversions have occurred as the result of calling columnNNN() methods.

Parameters:
column - the index of the column, starting with 0
Returns:
an integer code, indicating the type affinity of the returned column
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_type

getColumnName

public java.lang.String getColumnName(int column)
                               throws SQLiteException
Gets a name of the column in the result set.

Parameters:
column - the index of the column, starting with 0
Returns:
column name
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_name

getColumnTableName

public java.lang.String getColumnTableName(int column)
                                    throws SQLiteException
Gets a name of the column's table in the result set.

Parameters:
column - the index of the column, starting with 0
Returns:
name of the table that the column belongs to
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_table_name

getColumnDatabaseName

public java.lang.String getColumnDatabaseName(int column)
                                       throws SQLiteException
Gets a name of the column's table's database in the result set.

Parameters:
column - the index of the column, starting with 0
Returns:
name of the database that contains the table that the column belongs to
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_database_name

getColumnOriginName

public java.lang.String getColumnOriginName(int column)
                                     throws SQLiteException
Gets the original name of the column that is behind the given column in the result set. The name is not aliased (not defined in the SQL).

Parameters:
column - the index of the column, starting with 0
Returns:
name of the table column
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_column_database_name

isReadOnly

public boolean isReadOnly()
                   throws SQLiteException
Check if the underlying statement is a SELECT.

Returns:
true if statement is a SELECT; false if it is UPDATE, INSERT or other DML statement. The return value is undefined for some statements - see SQLite docs.
Throws:
SQLiteException - if SQLite returns an error, or if the call violates the contract of this class
See Also:
sqlite3_stmt_readonly

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object