SQLiteStatement


public interface 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 methods

abstract void
bindBlob(int index, @NonNull byte[] value)

Binds a ByteArray value to this statement at an index.

default void
bindBoolean(int index, boolean value)

Binds a Boolean value to this statement at an index.

abstract void
bindDouble(int index, double value)

Binds a Double value to this statement at an index.

default void
bindFloat(int index, float value)

Binds a Float value to this statement at an index.

default void
bindInt(int index, int value)

Binds a Int value to this statement at an index.

abstract void
bindLong(int index, long value)

Binds a Long value to this statement at an index.

abstract void
bindNull(int index)

Binds a NULL value to this statement at an index.

abstract void
bindText(int index, @NonNull String value)

Binds a String value to this statement at an index.

abstract void

Clears all parameter bindings.

abstract void

Closes the statement.

abstract @NonNull byte[]
getBlob(int index)

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

default boolean
getBoolean(int index)

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

abstract int

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

abstract @NonNull String
getColumnName(int index)

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

default @NonNull List<@NonNull String>

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

abstract double
getDouble(int index)

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

default float
getFloat(int index)

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

default int
getInt(int index)

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

abstract long
getLong(int index)

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

abstract @NonNull String
getText(int index)

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

abstract boolean
isNull(int index)

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

abstract void

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

abstract boolean

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

Extension functions

default final @NonNull R
<R extends Object> SQLiteKt.use(
    @NonNull SQLiteStatement receiver,
    @NonNull Function1<@NonNull SQLiteStatement, @NonNull R> block
)

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

Public methods

bindBlob

Added in 2.5.0-alpha02
abstract void bindBlob(int index, @NonNull byte[] value)

Binds a ByteArray value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

@NonNull byte[] value

the value to bind

bindBoolean

Added in 2.5.0-alpha02
default void bindBoolean(int index, boolean value)

Binds a Boolean value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

boolean value

the value to bind

bindDouble

Added in 2.5.0-alpha02
abstract void bindDouble(int index, double value)

Binds a Double value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

double value

the value to bind

bindFloat

Added in 2.5.0-alpha02
default void bindFloat(int index, float value)

Binds a Float value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

float value

the value to bind

bindInt

Added in 2.5.0-alpha02
default void bindInt(int index, int value)

Binds a Int value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

int value

the value to bind

bindLong

Added in 2.5.0-alpha02
abstract void bindLong(int index, long value)

Binds a Long value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

long value

the value to bind

bindNull

Added in 2.5.0-alpha02
abstract void bindNull(int index)

Binds a NULL value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

bindText

Added in 2.5.0-alpha02
abstract void bindText(int index, @NonNull String value)

Binds a String value to this statement at an index.

Parameters
int index

the 1-based index of the parameter to bind

@NonNull String value

the value to bind

clearBindings

Added in 2.5.0-alpha02
abstract void clearBindings()

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

close

Added in 2.5.0-alpha02
abstract void close()

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

Added in 2.5.0-alpha02
abstract @NonNull byte[] getBlob(int index)

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

Parameters
int index

the 0-based index of the column

Returns
@NonNull byte[]

the value of the column

getBoolean

Added in 2.5.0-alpha02
default boolean getBoolean(int index)

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

Parameters
int index

the 0-based index of the column

Returns
boolean

the value of the column

getColumnCount

Added in 2.5.0-alpha02
abstract int getColumnCount()

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

Returns
int

the number of columns

getColumnName

Added in 2.5.0-alpha02
abstract @NonNull String getColumnName(int index)

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

Parameters
int index

the 0-based index of the column

Returns
@NonNull String

the name of the column

getColumnNames

Added in 2.5.0-alpha02
default @NonNull List<@NonNull StringgetColumnNames()

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

Returns
@NonNull List<@NonNull String>

the names of the columns

getDouble

Added in 2.5.0-alpha02
abstract double getDouble(int index)

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

Parameters
int index

the 0-based index of the column

Returns
double

the value of the column

getFloat

Added in 2.5.0-alpha02
default float getFloat(int index)

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

Parameters
int index

the 0-based index of the column

Returns
float

the value of the column

getInt

Added in 2.5.0-alpha02
default int getInt(int index)

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

Parameters
int index

the 0-based index of the column

Returns
int

the value of the column

getLong

Added in 2.5.0-alpha02
abstract long getLong(int index)

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

Parameters
int index

the 0-based index of the column

Returns
long

the value of the column

getText

Added in 2.5.0-alpha02
abstract @NonNull String getText(int index)

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

Parameters
int index

the 0-based index of the column

Returns
@NonNull String

the value of the column

isNull

Added in 2.5.0-alpha02
abstract boolean isNull(int index)

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

Parameters
int index

the 0-based index of the column

Returns
boolean

true if the column value is NULL, false otherwise

reset

Added in 2.5.0-alpha02
abstract void reset()

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

Added in 2.5.0-alpha02
abstract boolean step()

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

SQLiteKt.use

default final @NonNull R <R extends Object> SQLiteKt.use(
    @NonNull SQLiteStatement receiver,
    @NonNull Function1<@NonNull SQLiteStatement, @NonNull R> block
)

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