SQLiteStatement
public interface SQLiteStatement extends AutoCloseable
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 |
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 |
Binds a Float value to this statement at an index. |
default void |
Binds a Int value to this statement at an index. |
abstract void |
Binds a Long value to this statement at an index. |
abstract void |
Binds a NULL value to this statement at an index. |
abstract void |
Binds a String value to this statement at an index. |
abstract void |
Clears all parameter bindings. |
abstract void |
close()Closes the statement. |
abstract @NonNull byte[] |
Returns the value of the column at |
default boolean |
getBoolean(@IntRange(from = 0) int index)Returns the value of the column at |
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 |
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 |
abstract double |
Returns the value of the column at |
default float |
Returns the value of the column at |
default int |
Returns the value of the column at |
abstract long |
Returns the value of the column at |
abstract @NonNull String |
Returns the value of the column at |
abstract boolean |
Returns true if the value of the column at |
abstract void |
reset()Resets the prepared statement back to initial state so that it can be re-executed via |
abstract boolean |
step()Executes the statement and evaluates the next result row if available. |
Extension functions |
|
|---|---|
default final boolean |
SQLiteAsync.step(@NonNull SQLiteStatement receiver)Executes the statement and evaluates the next result row if available. |
Public methods
bindBlob
abstract void bindBlob(@IntRange(from = 1) int index, @NonNull byte[] value)
Binds a ByteArray value to this statement at an index.
bindBoolean
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
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
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
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
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
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
abstract void bindText(@IntRange(from = 1) int index, @NonNull String value)
Binds a String value to this statement at an index.
clearBindings
abstract void clearBindings()
Clears all parameter bindings. Unset bindings are treated as NULL.
close
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
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
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
abstract int getColumnCount()
Returns the number of columns in the result of the statement.
| Returns | |
|---|---|
int |
the number of columns |
getColumnName
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 |
getColumnNames
default @NonNull List<@NonNull String> getColumnNames()
Returns the name of the columns in the result of the statement ordered by their index.
getColumnType
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
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
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
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
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
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 |
isNull
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
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
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
SQLiteAsync.step
default final boolean SQLiteAsync.step(@NonNull SQLiteStatement receiver)
Executes the statement and evaluates the next result row if available.
On web targets this function is asynchronous while for non-web it is synchronous.