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(@IntRange(from = 1) int index, @NonNull byte[] value)

Binds a ByteArray value to this statement at an index.

default void
bindBoolean(@IntRange(from = 1) int index, boolean value)

Binds a Boolean value to this statement at an index.

abstract void
bindDouble(@IntRange(from = 1) int index, double value)

Binds a Double value to this statement at an index.

default void
bindFloat(@IntRange(from = 1) int index, float value)

Binds a Float value to this statement at an index.

default void
bindInt(@IntRange(from = 1) int index, int value)

Binds a Int value to this statement at an index.

abstract void
bindLong(@IntRange(from = 1) int index, long value)

Binds a Long value to this statement at an index.

abstract void
bindNull(@IntRange(from = 1) int index)

Binds a NULL value to this statement at an index.

abstract void
bindText(@IntRange(from = 1) 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(@IntRange(from = 0) int index)

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

default boolean
getBoolean(@IntRange(from = 0) 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(@IntRange(from = 0) 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 int
getColumnType(@IntRange(from = 0) int index)

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

abstract double
getDouble(@IntRange(from = 0) int index)

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

default float
getFloat(@IntRange(from = 0) int index)

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

default int
getInt(@IntRange(from = 0) int index)

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

abstract long
getLong(@IntRange(from = 0) int index)

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

abstract @NonNull String
getText(@IntRange(from = 0) int index)

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

abstract boolean
isNull(@IntRange(from = 0) 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> SQLite.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-alpha11
abstract void bindBlob(@IntRange(from = 1) int index, @NonNull byte[] value)

Binds a ByteArray value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

@NonNull byte[] value

the value to bind

bindBoolean

Added in 2.5.0-alpha11
default void bindBoolean(@IntRange(from = 1) int index, boolean value)

Binds a Boolean value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

boolean value

the value to bind

bindDouble

Added in 2.5.0-alpha11
abstract void bindDouble(@IntRange(from = 1) int index, double value)

Binds a Double value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

double value

the value to bind

bindFloat

Added in 2.5.0-alpha11
default void bindFloat(@IntRange(from = 1) int index, float value)

Binds a Float value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

float value

the value to bind

bindInt

Added in 2.5.0-alpha11
default void bindInt(@IntRange(from = 1) int index, int value)

Binds a Int value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

int value

the value to bind

bindLong

Added in 2.5.0-alpha11
abstract void bindLong(@IntRange(from = 1) int index, long value)

Binds a Long value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

long value

the value to bind

bindNull

Added in 2.5.0-alpha11
abstract void bindNull(@IntRange(from = 1) int index)

Binds a NULL value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

bindText

Added in 2.5.0-alpha11
abstract void bindText(@IntRange(from = 1) int index, @NonNull String value)

Binds a String value to this statement at an index.

Parameters
@IntRange(from = 1) int index

the 1-based index of the parameter to bind

@NonNull String value

the value to bind

clearBindings

Added in 2.5.0-alpha11
abstract void clearBindings()

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

close

Added in 2.5.0-alpha11
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-alpha11
abstract @NonNull byte[] getBlob(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
@NonNull byte[]

the value of the column

getBoolean

Added in 2.5.0-alpha11
default boolean getBoolean(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
boolean

the value of the column

getColumnCount

Added in 2.5.0-alpha11
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-alpha11
abstract @NonNull String getColumnName(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
@NonNull String

the name of the column

getColumnNames

Added in 2.5.0-alpha11
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

getColumnType

Added in 2.5.0-alpha11
abstract int getColumnType(@IntRange(from = 0) int index)

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

the 0-based index of the column

Returns
int

the data type of the column

getDouble

Added in 2.5.0-alpha11
abstract double getDouble(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
double

the value of the column

getFloat

Added in 2.5.0-alpha11
default float getFloat(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
float

the value of the column

getInt

Added in 2.5.0-alpha11
default int getInt(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
int

the value of the column

getLong

Added in 2.5.0-alpha11
abstract long getLong(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
long

the value of the column

getText

Added in 2.5.0-alpha11
abstract @NonNull String getText(@IntRange(from = 0) int index)

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

Parameters
@IntRange(from = 0) int index

the 0-based index of the column

Returns
@NonNull String

the value of the column

isNull

Added in 2.5.0-alpha11
abstract boolean isNull(@IntRange(from = 0) int index)

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

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

SQLite.use

default final @NonNull R <R extends Object> SQLite.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.