SQLDatabase

@ThreadSafe
class SQLDatabase(val path: String, sqlite: SQLite, configuration: DatabaseConfiguration, key: ByteArray?, random: IRandom = CommonThreadLocalRandom) : IDatabase, SharedCloseable(source)

The use of ThreadLocal underpins SQLDatabase's thread-safety.

A thread can acquire at most one connection session per database instance. Sessions hold at most one connection at any given time, and exclusively. Sessions control all access to a database's connections and each session is thread-bound. This prevents two threads from ever sharing a single connection.

This is the same strategy Google employs in the Android SDK.

See also

Constructors

Link copied to clipboard
constructor(path: String, sqlite: SQLite, configuration: DatabaseConfiguration, key: ByteArray?, random: IRandom = CommonThreadLocalRandom)

Properties

Link copied to clipboard
open override val inTransaction: Boolean
Link copied to clipboard

Returns true if any database connection managed by this database has been interrupted and has not yet completed. This method is safe to call from any thread.

Link copied to clipboard
Link copied to clipboard
open override var version: Int

Functions

Link copied to clipboard
fun batch(sql: String, bindArgs: Stream<Array<out Any?>>): Int
fun batch(sql: String, bindArgs: Iterable<Array<out Any?>>): Int
fun batch(sql: String, bindArgs: List<Array<out Any?>>): Int
fun batch(sql: String, bindArgs: Sequence<Array<out Any?>>): Int
fun batch(sql: String, bindArgs: Array<out Array<out Any?>>, fromIndex: Int = 0, toIndex: Int = bindArgs.size): Int
Link copied to clipboard
open override fun beginExclusiveTransaction()
Link copied to clipboard
open override fun beginImmediateTransaction()
Link copied to clipboard
fun close()
Link copied to clipboard
open override fun compileStatement(sql: String, bindArgs: Array<out Any?>? = null): ISQLStatement
Link copied to clipboard
fun databaseConfig(op: Int, value: Int)
Link copied to clipboard
open override fun delete(table: String, whereClause: String, whereArgs: Array<out Any?>): Int
Link copied to clipboard
open override fun endTransaction()
Link copied to clipboard
open override fun exec(sql: String, bindArgs: Array<out Any?>? = null)
Link copied to clipboard
fun <T> execute(readOnly: Boolean, block: SQLDatabase.() -> T): T
Link copied to clipboard
open override fun insert(table: String, values: IContentValues, conflictAlgorithm: IConflictAlgorithm): Long
Link copied to clipboard
fun interrupt()

Interrupts all database connections managed by this database. This causes any pending database operations on those connections to abort and return at the earliest opportunity. This method is safe to call from any thread.

Link copied to clipboard
Link copied to clipboard
fun pragma(pragma: SQLitePragma): String
fun pragma(key: String): String
fun pragma(pragma: SQLitePragma, value: Any): String?
fun pragma(key: String, value: Any): String?
Link copied to clipboard
open override fun query(query: ISQLQuery): ICursor
open override fun query(sql: String, selectionArgs: Array<out Any?>): ICursor
open override fun query(distinct: Boolean, table: String, columns: Array<out String>, selection: String, selectionArgs: Array<out Any?>, groupBy: String?, having: String?, orderBy: String?, limit: Int?): ICursor

fun query(query: ISQLQuery, cancellationSignal: CancellationSignal): ICursor
fun query(sql: String, selectionArgs: Array<out Any?>, cancellationSignal: CancellationSignal): ICursor
fun query(distinct: Boolean, table: String, columns: Array<out String>, selection: String, selectionArgs: Array<out Any?>, groupBy: String?, having: String?, orderBy: String?, limit: Int?, cancellationSignal: CancellationSignal): ICursor

Executes a cancellable query. If the cancellationSignal is cancelled from another thread, the query will be aborted at the earliest opportunity and an OperationCancelledException will be thrown.

Link copied to clipboard
fun queryForwardOnly(sql: String, selectionArgs: Array<out Any?>): ICursor

Returns a forward-only streaming ICursor backed by a ForwardCursor. The caller must close the returned cursor to release the underlying prepared statement back to the connection's cache and to release the session's connection back to the pool.

Link copied to clipboard
fun readFromBlob(name: String, table: String, column: String, row: Long, offset: Int, limit: Int, stream: OutputStream)
Link copied to clipboard
fun release()
Link copied to clipboard
fun releaseMemory(priority: Priority)
Link copied to clipboard
Link copied to clipboard
fun retain()
Link copied to clipboard
Link copied to clipboard
fun setProgressHandler(instructionCount: Int, handler: SQLProgressHandler?)

Registers a progress handler that is invoked periodically during long-running SQL statements on all database connections managed by this database. If the handler returns non-zero, the operation is interrupted.

Link copied to clipboard
fun setSavepoint(name: String? = null): String
Link copied to clipboard
open override fun setTransactionSuccessful()
Link copied to clipboard
fun sizeOfBlob(name: String, table: String, column: String, row: Long): Int
Link copied to clipboard
fun <T> transact(transactionMode: SQLiteTransactionMode = SQLiteTransactionMode.EXCLUSIVE, block: SQLDatabase.() -> T): T
fun <D, T> transact(database: D, transactionMode: SQLiteTransactionMode, block: D.() -> T): T
fun <T> transact(listener: SQLTransactionListener, transactionMode: SQLiteTransactionMode = SQLiteTransactionMode.EXCLUSIVE, block: SQLDatabase.() -> T): T
Link copied to clipboard
open override fun update(table: String, values: IContentValues, whereClause: String, whereArgs: Array<out Any?>, conflictAlgorithm: IConflictAlgorithm): Int
Link copied to clipboard
open override fun upsert(table: String, values: IContentValues, columns: Array<out String>, update: String): Long
Link copied to clipboard
fun writeToBlob(name: String, table: String, column: String, row: Long, offset: Int, stream: InputStream)
Link copied to clipboard
open override fun yieldTransaction(): Boolean
open override fun yieldTransaction(pauseMillis: Long): Boolean