SQLiteStatement



SQLite statement definition.

A prepared statement is a resource that must be released once it is no longer needed via its close function.

See also Prepared Statement

Summary

Public functions

Unit
bindBlob(index: Int, value: ByteArray)

Binds a ByteArray value to this statement at an index.

Cmn
open Unit
bindBoolean(index: Int, value: Boolean)

Binds a Boolean value to this statement at an index.

Cmn
Unit
bindDouble(index: Int, value: Double)

Binds a Double value to this statement at an index.

Cmn
open Unit
bindFloat(index: Int, value: Float)

Binds a Float value to this statement at an index.

Cmn
open Unit
bindInt(index: Int, value: Int)

Binds a Int value to this statement at an index.

Cmn
Unit
bindLong(index: Int, value: Long)

Binds a Long value to this statement at an index.

Cmn
Unit
bindNull(index: Int)

Binds a NULL value to this statement at an index.

Cmn
Unit
bindText(index: Int, value: String)

Binds a String value to this statement at an index.

Cmn
Unit

Clears all parameter bindings.

Cmn
Unit

Closes the statement.

Cmn
ByteArray
getBlob(index: Int)

Returns the value of the column at index as a ByteArray.

Cmn
open Boolean
getBoolean(index: Int)

Returns the value of the column at index as a Boolean.

Cmn
Int

Returns the number of columns in the result of the statement.

Cmn
String

Returns the name of a column at index in the result of the statement.

Cmn
open List<String>

Returns the name of the columns in the result of the statement ordered by their index.

Cmn
Double
getDouble(index: Int)

Returns the value of the column at index as a Double.

Cmn
open Float
getFloat(index: Int)

Returns the value of the column at index as a Float.

Cmn
open Int
getInt(index: Int)

Returns the value of the column at index as a Int.

Cmn
Long
getLong(index: Int)

Returns the value of the column at index as a Long.

Cmn
String
getText(index: Int)

Returns the value of the column at index as a String.

Cmn
Boolean
isNull(index: Int)

Returns true if the value of the column at index is NULL.

Cmn
Unit

Resets the prepared statement back to initial state so that it can be re-executed via step.

Cmn
Boolean

Executes the statement and evaluates the next result row if available.

Cmn

Extension functions

inline R
<R : Any?> SQLiteStatement.use(block: (SQLiteStatement) -> R)

Use the receiver statement within the block and closes it once it is done.

Cmn

Public functions

bindBlob

fun bindBlob(index: Int, value: ByteArray): Unit

Binds a ByteArray value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: ByteArray

the value to bind

bindBoolean

open fun bindBoolean(index: Int, value: Boolean): Unit

Binds a Boolean value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: Boolean

the value to bind

bindDouble

fun bindDouble(index: Int, value: Double): Unit

Binds a Double value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: Double

the value to bind

bindFloat

open fun bindFloat(index: Int, value: Float): Unit

Binds a Float value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: Float

the value to bind

bindInt

open fun bindInt(index: Int, value: Int): Unit

Binds a Int value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: Int

the value to bind

bindLong

fun bindLong(index: Int, value: Long): Unit

Binds a Long value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: Long

the value to bind

bindNull

fun bindNull(index: Int): Unit

Binds a NULL value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

bindText

fun bindText(index: Int, value: String): Unit

Binds a String value to this statement at an index.

Parameters
index: Int

the 1-based index of the parameter to bind

value: String

the value to bind

clearBindings

fun clearBindings(): Unit

Clears all parameter bindings. Unset bindings are treated as NULL.

close

fun close(): Unit

Closes the statement.

Once a statement is closed it should no longer be used. Calling this function on an already closed statement is a no-op.

getBlob

fun getBlob(index: Int): ByteArray

Returns the value of the column at index as a ByteArray.

Parameters
index: Int

the 0-based index of the column

Returns
ByteArray

the value of the column

getBoolean

open fun getBoolean(index: Int): Boolean

Returns the value of the column at index as a Boolean.

Parameters
index: Int

the 0-based index of the column

Returns
Boolean

the value of the column

getColumnCount

fun getColumnCount(): Int

Returns the number of columns in the result of the statement.

Returns
Int

the number of columns

getColumnName

fun getColumnName(index: Int): String

Returns the name of a column at index in the result of the statement.

Parameters
index: Int

the 0-based index of the column

Returns
String

the name of the column

getColumnNames

open fun getColumnNames(): List<String>

Returns the name of the columns in the result of the statement ordered by their index.

Returns
List<String>

the names of the columns

getDouble

fun getDouble(index: Int): Double

Returns the value of the column at index as a Double.

Parameters
index: Int

the 0-based index of the column

Returns
Double

the value of the column

getFloat

open fun getFloat(index: Int): Float

Returns the value of the column at index as a Float.

Parameters
index: Int

the 0-based index of the column

Returns
Float

the value of the column

getInt

open fun getInt(index: Int): Int

Returns the value of the column at index as a Int.

Parameters
index: Int

the 0-based index of the column

Returns
Int

the value of the column

getLong

fun getLong(index: Int): Long

Returns the value of the column at index as a Long.

Parameters
index: Int

the 0-based index of the column

Returns
Long

the value of the column

getText

fun getText(index: Int): String

Returns the value of the column at index as a String.

Parameters
index: Int

the 0-based index of the column

Returns
String

the value of the column

isNull

fun isNull(index: Int): Boolean

Returns true if the value of the column at index is NULL.

Parameters
index: Int

the 0-based index of the column

Returns
Boolean

true if the column value is NULL, false otherwise

reset

fun reset(): Unit

Resets the prepared statement back to initial state so that it can be re-executed via step. Any parameter bound via the bind*() APIs will retain their value.

step

fun step(): Boolean

Executes the statement and evaluates the next result row if available.

A statement is initially prepared and compiled but is not executed until one or more calls to this function. If the statement execution produces result rows then this function will return true indicating there is a new row of data ready to be read.

Returns
Boolean

true if there are more rows to evaluate or false if the statement is done executing

Extension functions

inline fun <R : Any?> SQLiteStatement.use(block: (SQLiteStatement) -> R): R

Use the receiver statement within the block and closes it once it is done.