SupportSQLiteOpenHelper
interface SupportSQLiteOpenHelper : Closeable
An interface to map the behavior of android.database.sqlite.SQLiteOpenHelper. Note that since that class requires overriding certain methods, support implementation uses Factory.create to create this and Callback to implement the methods that should be overridden.
Summary
Nested types |
|---|
abstract class SupportSQLiteOpenHelper.CallbackCreates a new Callback to get database lifecycle events. |
|
The configuration to create an SQLite open helper object using |
|
Builder class for |
fun interface SupportSQLiteOpenHelper.FactoryFactory class to create instances of |
Public functions |
|
|---|---|
Unit |
close()Close any open database object. |
Unit |
setWriteAheadLoggingEnabled(enabled: Boolean)Enables or disables the use of write-ahead logging for the database. |
Public properties |
|
|---|---|
String? |
Return the name of the SQLite database being opened, as given to the constructor. |
SupportSQLiteDatabase |
Create and/or open a database. |
SupportSQLiteDatabase |
Create and/or open a database that will be used for reading and writing. |
Public functions
setWriteAheadLoggingEnabled
fun setWriteAheadLoggingEnabled(enabled: Boolean): Unit
Enables or disables the use of write-ahead logging for the database.
See SupportSQLiteDatabase.enableWriteAheadLogging for details.
Write-ahead logging cannot be used with read-only databases so the value of this flag is ignored if the database is opened read-only.
| Parameters | |
|---|---|
enabled: Boolean |
True if write-ahead logging should be enabled, false if it should be disabled. |
Public properties
databaseName
val databaseName: String?
Return the name of the SQLite database being opened, as given to the constructor. null indicates an in-memory database.
readableDatabase
val readableDatabase: SupportSQLiteDatabase
Create and/or open a database. This will be the same object returned by writableDatabase unless some problem, such as a full disk, requires the database to be opened read-only. In that case, a read-only database object will be returned. If the problem is fixed, a future call to writableDatabase may succeed, in which case the read-only database object will be closed and the read/write object will be returned in the future.
Like writableDatabase, this method may take a long time to return, so you should not call it from the application main thread, including from ContentProvider.onCreate().
| Returns | |
|---|---|
SupportSQLiteDatabase |
a database object valid until |
| Throws | |
|---|---|
SQLiteException |
if the database cannot be opened |
writableDatabase
val writableDatabase: SupportSQLiteDatabase
Create and/or open a database that will be used for reading and writing. The first time this is called, the database will be opened and Callback.onCreate, Callback.onUpgrade and/or Callback.onOpen will be called.
Once opened successfully, the database is cached, so you can call this method every time you need to write to the database. (Make sure to call close when you no longer need the database.) Errors such as bad permissions or a full disk may cause this method to fail, but future attempts may succeed if the problem is fixed.
Database upgrade may take a long time, you should not call this method from the application main thread, including from ContentProvider.onCreate().
| Returns | |
|---|---|
SupportSQLiteDatabase |
a read/write database object valid until |
| Throws | |
|---|---|
SQLiteException |
if the database cannot be opened for writing |