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: @IntRange(from = 1) Int, value: ByteArray)

Binds a ByteArray value to this statement at an index.

Cmn
open Unit
bindBoolean(index: @IntRange(from = 1) Int, value: Boolean)

Binds a Boolean value to this statement at an index.

Cmn
Unit
bindDouble(index: @IntRange(from = 1) Int, value: Double)

Binds a Double value to this statement at an index.

Cmn
open Unit
bindFloat(index: @IntRange(from = 1) Int, value: Float)

Binds a Float value to this statement at an index.

Cmn
open Unit
bindInt(index: @IntRange(from = 1) Int, value: Int)

Binds a Int value to this statement at an index.

Cmn
Unit
bindLong(index: @IntRange(from = 1) Int, value: Long)

Binds a Long value to this statement at an index.

Cmn
Unit
bindNull(index: @IntRange(from = 1) Int)

Binds a NULL value to this statement at an index.

Cmn
Unit
bindText(index: @IntRange(from = 1) 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: @IntRange(from = 0) Int)

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

Cmn
open Boolean
getBoolean(index: @IntRange(from = 0) 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
getColumnName(index: @IntRange(from = 0) Int)

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
Int
getColumnType(index: @IntRange(from = 0) Int)

Returns the data type of a column at index in the result of the statement.

Cmn
Double
getDouble(index: @IntRange(from = 0) Int)

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

Cmn
open Float
getFloat(index: @IntRange(from = 0) Int)

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

Cmn
open Int
getInt(index: @IntRange(from = 0) Int)

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

Cmn
Long
getLong(index: @IntRange(from = 0) Int)

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

Cmn
String
getText(index: @IntRange(from = 0) Int)

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

Cmn
Boolean
isNull(index: @IntRange(from = 0) 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: @IntRange(from = 1) Int, value: ByteArray): Unit

Binds a ByteArray value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

value: ByteArray

the value to bind

bindBoolean

open fun bindBoolean(index: @IntRange(from = 1) Int, value: Boolean): Unit

Binds a Boolean value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

value: Boolean

the value to bind

bindDouble

fun bindDouble(index: @IntRange(from = 1) Int, value: Double): Unit

Binds a Double value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

value: Double

the value to bind

bindFloat

open fun bindFloat(index: @IntRange(from = 1) Int, value: Float): Unit

Binds a Float value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

value: Float

the value to bind

bindInt

open fun bindInt(index: @IntRange(from = 1) Int, value: Int): Unit

Binds a Int value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

value: Int

the value to bind

bindLong

fun bindLong(index: @IntRange(from = 1) Int, value: Long): Unit

Binds a Long value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

value: Long

the value to bind

bindNull

fun bindNull(index: @IntRange(from = 1) Int): Unit

Binds a NULL value to this statement at an index.

Parameters
index: @IntRange(from = 1) Int

the 1-based index of the parameter to bind

bindText

fun bindText(index: @IntRange(from = 1) Int, value: String): Unit

Binds a String value to this statement at an index.

Parameters
index: @IntRange(from = 1) 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: @IntRange(from = 0) Int): ByteArray

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

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
ByteArray

the value of the column

getBoolean

open fun getBoolean(index: @IntRange(from = 0) Int): Boolean

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

Parameters
index: @IntRange(from = 0) 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: @IntRange(from = 0) Int): String

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

Parameters
index: @IntRange(from = 0) 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

getColumnType

fun getColumnType(index: @IntRange(from = 0) Int): Int

Returns the data type of a column at index in the result of the statement.

The data type can be used to determine the preferred get*() function to be used for the column but other getters may perform data type conversion.

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
Int

the data type of the column

getDouble

fun getDouble(index: @IntRange(from = 0) Int): Double

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

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
Double

the value of the column

getFloat

open fun getFloat(index: @IntRange(from = 0) Int): Float

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

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
Float

the value of the column

getInt

open fun getInt(index: @IntRange(from = 0) Int): Int

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

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
Int

the value of the column

getLong

fun getLong(index: @IntRange(from = 0) Int): Long

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

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
Long

the value of the column

getText

fun getText(index: @IntRange(from = 0) Int): String

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

Parameters
index: @IntRange(from = 0) Int

the 0-based index of the column

Returns
String

the value of the column

isNull

fun isNull(index: @IntRange(from = 0) Int): Boolean

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

Parameters
index: @IntRange(from = 0) 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.