# SupportSQLiteOpenHelper

Artifact: [androidx.sqlite:sqlite](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/db/SupportSQLiteOpenHelper.android.kt+class:androidx.sqlite.db.SupportSQLiteOpenHelper) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

*** ** * ** ***


```
public interface SupportSQLiteOpenHelper extends Closeable
```

<br />

*** ** * ** ***

An interface to map the behavior of `https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html`. Note that since that class requires overriding certain methods, support implementation uses `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Factory#create(androidx.sqlite.db.SupportSQLiteOpenHelper.Configuration)` to create this and `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback` to implement the methods that should be overridden.

## Summary

| ### Nested types |
|---|
| `public abstract class https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback` Creates a new Callback to get database lifecycle events. |
| `public final class https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Configuration` The configuration to create an SQLite open helper object using `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Factory`. |
| `public class https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Configuration.Builder` Builder class for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Configuration`. |
| `public fun interface https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Factory` Factory class to create instances of `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper` using `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Configuration`. |

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#close()()` Close any open database object. |
| `abstract https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#getDatabaseName()()` Return the name of the SQLite database being opened, as given to the constructor. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#getReadableDatabase()()` Create and/or open a database. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#getWritableDatabase()()` Create and/or open a database that will be used for reading and writing. |
| `abstract void` | `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#setWriteAheadLoggingEnabled(kotlin.Boolean)(boolean enabled)` Enables or disables the use of write-ahead logging for the database. |

## Public methods

### close

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

```
abstract void close()
```

Close any open database object.

### getDatabaseName

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

```
abstract String getDatabaseName()
```

Return the name of the SQLite database being opened, as given to the constructor. `null` indicates an in-memory database.

### getReadableDatabase

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

```
abstract @NonNull SupportSQLiteDatabase getReadableDatabase()
```

Create and/or open a database. This will be the same object returned by `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#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 `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#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 `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | a database object valid until `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#writableDatabase()` or `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#close()` is called. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/database/sqlite/SQLiteException.html` | if the database cannot be opened |

### getWritableDatabase

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

```
abstract @NonNull SupportSQLiteDatabase getWritableDatabase()
```

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 `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onCreate(androidx.sqlite.db.SupportSQLiteDatabase)`, `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onUpgrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)` and/or `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` 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 `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | a read/write database object valid until `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#close()` is called |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/database/sqlite/SQLiteException.html` | if the database cannot be opened for writing |

### setWriteAheadLoggingEnabled

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

```
abstract void setWriteAheadLoggingEnabled(boolean enabled)
```

Enables or disables the use of write-ahead logging for the database.

See `https://developer.android.com/reference/androidx/sqlite/db/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 |
|---|---|
| `boolean enabled` | True if write-ahead logging should be enabled, false if it should be disabled. |