DatabaseConnection

A database connection, opened through ksqlite.kapi.SQLite.open.

Unless documented otherwise, every member throws IllegalStateException once this connection is closed.

Properties

Link copied to clipboard
abstract val changes: Long

Number of rows modified, inserted or deleted by the most recently completed INSERT, UPDATE or DELETE statement.

Link copied to clipboard

Cipher configuration operating on this connection.

Link copied to clipboard
abstract val cipherData: CipherData

Cipher data for this connection.

Link copied to clipboard

Configuration of the connection.

Link copied to clipboard
abstract val fileControl: FileControl

Low-level file control operations on the underlying VFS.

Link copied to clipboard
abstract val isAutocommit: Boolean

Whether the connection is in autocommit mode.

Link copied to clipboard
abstract val isInterrupted: Boolean

Whether an interrupt is currently in effect.

Link copied to clipboard
abstract val lastError: LastError

Most recent error information.

Link copied to clipboard
abstract var lastInsertRowid: Long

Rowid of the most recent successful INSERT into a rowid table or virtual table on this connection.

Link copied to clipboard
abstract val totalChanges: Long

Total number of rows inserted, modified or deleted by all INSERT, UPDATE or DELETE statements completed since the database connection was opened, including those executed as part of trigger programs.

Link copied to clipboard
abstract val wal: WriteAheadLog

Write-Ahead Log operating on this connection.

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard

Creates the collation name, or replaces it if one was already created with that name and encoding, backed by collation.

Link copied to clipboard

Convenience overload of createCollation using UTF-8 encoding, the only one currently supported.

Link copied to clipboard

Creates the aggregate function name(argumentCount), or replaces it if one was already created with the same name, argument count and encoding, and returns a handle that removes it again once closed.

abstract fun createFunction(name: String, argumentCount: Int, encoding: SqliteFunctionTextEncoding, function: ScalarFunction): Registration

Creates the scalar function name(argumentCount), or replaces it if one was already created with the same name, argument count and encoding, and returns a handle that removes it again once closed.

abstract fun createFunction(name: String, argumentCount: Int, encoding: SqliteFunctionTextEncoding, function: WindowFunction): Registration

Creates the window function name(argumentCount), or replaces it if one was already created with the same name, argument count and encoding, and returns a handle that removes it again once closed.

Link copied to clipboard

Convenience overload of createFunction using UTF-8 encoding, the only one currently supported.

Link copied to clipboard
abstract fun createModule(name: String, version: SqliteModuleVersion = SqliteModuleVersion.VERSION_4, module: VirtualTableModule.Eponymous): Registration

Creates the virtual table module name, or replaces it if one was already created with that name, and returns a handle that removes it again once closed. The table module connects to can either be referenced directly by name in SQL, with no CREATE VIRTUAL TABLE needed, or explicitly created like a VirtualTableModule.Regular one.

abstract fun createModule(name: String, version: SqliteModuleVersion = SqliteModuleVersion.VERSION_4, module: VirtualTableModule.EponymousOnly): Registration

Creates the virtual table module name, or replaces it if one was already created with that name, and returns a handle that removes it again once closed. The table module connects to can only be referenced directly by name in SQL, CREATE VIRTUAL TABLE is not supported for it.

abstract fun createModule(name: String, version: SqliteModuleVersion = SqliteModuleVersion.VERSION_4, module: VirtualTableModule.Regular): Registration

Creates the virtual table module name, or replaces it if one was already created with that name, and returns a handle that removes it again once closed. module must implement its create and connect functions differently, since SQLite only creates the backing table once but connects to it every time it is referenced.

Link copied to clipboard
abstract fun createSnapshot(database: String = SQLITE_MAIN_DB_NAME): Snapshot

Records the current state of the given database and returns a Snapshot.

Link copied to clipboard
abstract fun deserialize(serializedDatabase: Buffer, database: String = SQLITE_MAIN_DB_NAME, databaseSize: Long = serializedDatabase.byteSize, bufferSize: Long = databaseSize, flags: SqliteDeserializeFlag? = null)

Disconnects from database and then reopens database as an in-memory database based on the serialization contained in serializedDatabase. The serializedDatabase is databaseSize bytes in size. bufferSize is the size of the buffer serializedDatabase, which might be larger than databaseSize. If bufferSize is larger than databaseSize, and the SqliteDeserializeFlag.READONLY bit is not set in flags, then SQLite is permitted to add content to the in-memory database as long as the total size does not exceed bufferSize bytes.

Link copied to clipboard
abstract fun execute(sql: String, callback: Exec? = null)

Runs zero or more UTF-8 encoded, semicolon-separated SQL statements from sql. If callback is not null then it is invoked for each result row coming out of the evaluated SQL statements.

Link copied to clipboard
abstract fun flushCache()

Writes any dirty pages in the pager cache that are not currently in use. The operation only takes place if there is a write transaction open at the time this function is called.

Link copied to clipboard
abstract fun getFileName(database: String = SQLITE_MAIN_DB_NAME): FileName?

Returns the absolute pathname of database, or null for a temporary or in-memory database.

Link copied to clipboard
abstract fun getLimit(limit: SqliteRuntimeLimit): Int

Returns the current value of the given limit category.

Link copied to clipboard
abstract fun getName(index: Int): String?

Returns the schema name of the database at the 0-based index, main being 0, or null if there is no database at that index.

Link copied to clipboard
abstract fun getStatus(option: SqliteDbStatusOption, reset: Boolean = false): Status

Returns the current value and high-water mark for option, resetting the high-water mark afterward if reset is true.

Link copied to clipboard
abstract fun getTransactionState(database: String? = null): SqliteTransactionState

Returns the current transaction state of database.

Link copied to clipboard
abstract fun interrupt()

Causes any pending database operation to abort and return at its earliest opportunity.

Link copied to clipboard
abstract fun isReadOnly(database: String): Boolean

Returns true if the database database is read-only, or false If it is read/write.

Link copied to clipboard
abstract fun openBlob(tableName: String, columnName: String, rowid: Long, database: String = SQLITE_MAIN_DB_NAME, flags: SqliteBlobOpenFlag = SqliteBlobOpenFlag.READWRITE): Blob

Opens the Blob for incremental I/O on column columnName of the row rowid in table tableName, in database. flags controls whether the blob is opened for writing.

Link copied to clipboard
abstract fun openSnapshot(snapshot: Snapshot, database: String = SQLITE_MAIN_DB_NAME)

Starts a new read transaction or upgrades an existing one for database of this database such that the read transaction refers to historical snapshot, rather than the most recent change to the database.

Link copied to clipboard
abstract fun prepare(sql: String, flags: SqlitePrepareFlag? = null): PreparedStatement

Creates and returns a PreparedStatement.

Link copied to clipboard
abstract fun recoverSnapshots(database: String = SQLITE_MAIN_DB_NAME)

Attempts to scan the WAL file associated with database of this connection and make all valid snapshots available to openSnapshot.

Link copied to clipboard
abstract fun releaseMemory()

Attempts to free as much heap memory as possible from this connection.

Link copied to clipboard
abstract fun serialize(flags: SqliteSerializeFlag? = null, database: String = SQLITE_MAIN_DB_NAME): SerializeResult

Serializes database into a SerializeResult. Whether the returned buffer is owned by SQLite or by the caller depends on flags, see SerializeResult.Immutable and SerializeResult.Mutable.

Link copied to clipboard
abstract fun setAuthorizer(handler: Authorizer?)

Sets the callback invoked while an SQL statement is being compiled by prepare, once per action it would perform, to allow or deny each one.

Link copied to clipboard
abstract fun setAutovacuumPages(handler: AutovacuumPages?)

Sets the callback that is invoked prior to each autovacuum of the database file.

Link copied to clipboard
abstract fun setBusyHandler(handler: BusyHandler?)

Sets the callback that might be invoked whenever an attempt is made to access a database table associated with this connection when another thread or process has the table locked.

Link copied to clipboard
abstract fun setBusyTimeout(millis: Int)

Sets a BusyHandler that sleeps for a specified amount of time when a table is locked. Any BusyHandler previously passed to setBusyHandler is replaced.

Link copied to clipboard

Sets a BusyHandler that sleeps for a specified amount of time when a table is locked. Any BusyHandler previously passed to DatabaseConnection.setBusyHandler is replaced.

Link copied to clipboard
abstract fun setCollationNeeded(handler: CollationNeeded?)

Sets the callback invoked whenever an undefined collation sequence is required.

Link copied to clipboard
abstract fun setCommitHook(handler: CommitHook?)

Sets the callback invoked right before a transaction commits.

Link copied to clipboard
abstract fun setExtendedResultCodesEnabled(enabled: Boolean)

Enables or disables extended result codes, which report failures in more detail than the primary ksqlite.types.SqliteResultCode alone.

Link copied to clipboard
abstract fun setKey(key: ByteArray, size: Int = key.size, database: String = SQLITE_MAIN_DB_NAME)

Sets the key used to access an encrypted database.

Link copied to clipboard
abstract fun setLimit(limit: SqliteRuntimeLimit, value: Int)

Sets the value of the given limit category.

Link copied to clipboard
abstract fun setPreupdateHook(handler: PreupdateHook?)

Sets the callback that is invoked prior to each INSERT, UPDATE, and DELETE operation.

Link copied to clipboard
abstract fun setProgressHandler(operationCount: Int, handler: ProgressHandler?)

Sets handler to be invoked every operationCount internal VM instructions during long-running calls, or clears it if operationCount is not positive.

Link copied to clipboard
abstract fun setReKey(key: ByteArray, size: Int = key.size, database: String = SQLITE_MAIN_DB_NAME)

Changes the database encryption key.

Link copied to clipboard
abstract fun setRollbackHook(handler: RollbackHook?)

Sets the callback invoked whenever a transaction is rolled back.

Link copied to clipboard
abstract fun setTrace(eventCodes: SqliteTraceEventCode?, handler: Trace?)

Sets the callback invoked whenever any of the events identified by eventCodes occur, or clears it if eventCodes is null.

Link copied to clipboard
abstract fun setUpdateHook(handler: UpdateHook?)

Sets the callback that is invoked whenever a row is updated, inserted or deleted in a rowid table.

Link copied to clipboard
abstract fun tableColumnMetadata(table: String, column: String, database: String? = null): TableColumnMetadata

Returns information about the column column of table table in database database.