# SupportSQLiteOpenHelper.Callback

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.Callback) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

*** ** * ** ***


```
abstract class SupportSQLiteOpenHelper.Callback
```

<br />

*** ** * ** ***

Creates a new Callback to get database lifecycle events.

Handles various lifecycle events for the SQLite connection, similar to room-runtime.SQLiteOpenHelper.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#Callback(kotlin.Int)(version: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onConfigure(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` Called when the database connection is being configured, to enable features such as write-ahead logging or foreign key support. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onCorruption(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` The method invoked when database corruption is detected. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onCreate(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` Called when the database is created for the first time. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onDowngrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase, oldVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, newVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Called when the database needs to be downgraded. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` Called when the database has been opened. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onUpgrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase, oldVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, newVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Called when the database needs to be upgraded. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#version()` Version number of the database (starting at 1); if the database is older, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onUpgrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)` will be used to upgrade the database; if the database is newer, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onDowngrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)` will be used to downgrade the database. |

## Public constructors

### Callback

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

```
Callback(version: Int)
```

## Public functions

### onConfigure

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

```
open fun onConfigure(db: SupportSQLiteDatabase): Unit
```

Called when the database connection is being configured, to enable features such as write-ahead logging or foreign key support.

This method is called before `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onCreate(androidx.sqlite.db.SupportSQLiteDatabase)`, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onUpgrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)`, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onDowngrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)`, or `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` are called. It should not modify the database except to configure the database connection as required.

This method should only call methods that configure the parameters of the database connection, such as `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase#setForeignKeyConstraintsEnabled(kotlin.Boolean)`, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase#setLocale(java.util.Locale)`, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase#setMaximumSize(kotlin.Long)`, or executing PRAGMA statements.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |

### onCorruption

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

```
open fun onCorruption(db: SupportSQLiteDatabase): Unit
```

The method invoked when database corruption is detected. Default implementation will delete the database file.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | the `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` object representing the database on which corruption is detected. |

### onCreate

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

```
abstract fun onCreate(db: SupportSQLiteDatabase): Unit
```

Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |

### onDowngrade

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

```
open fun onDowngrade(db: SupportSQLiteDatabase, oldVersion: Int, newVersion: Int): Unit
```

Called when the database needs to be downgraded. This is strictly similar to `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onUpgrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)` method, but is called whenever current version is newer than requested one. However, this method is not abstract, so it is not mandatory for a customer to implement it. If not overridden, default implementation will reject downgrade and throws SQLiteException

This method executes within a transaction. If an exception is thrown, all changes will automatically be rolled back.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |
| `oldVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The old database version. |
| `newVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new database version. |

### onOpen

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

```
open fun onOpen(db: SupportSQLiteDatabase): Unit
```

Called when the database has been opened. The implementation should check `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase#isReadOnly()` before updating the database.

This method is called after the database connection has been configured and after the database schema has been created, upgraded or downgraded as necessary. If the database connection must be configured in some way before the schema is created, upgraded, or downgraded, do it in `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onConfigure(androidx.sqlite.db.SupportSQLiteDatabase)` instead.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |

### onUpgrade

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

```
abstract fun onUpgrade(db: SupportSQLiteDatabase, oldVersion: Int, newVersion: Int): Unit
```

Called when the database needs to be upgraded. The implementation should use this method to drop tables, add tables, or do anything else it needs to upgrade to the new schema version.

The SQLite ALTER TABLE documentation can be found [here](http://sqlite.org/lang_altertable.html). If you add new columns you can use ALTER TABLE to insert them into a live table. If you rename or remove columns you can use ALTER TABLE to rename the old table, then create the new table and then populate the new table with the contents of the old table.

This method executes within a transaction. If an exception is thrown, all changes will automatically be rolled back.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |
| `oldVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The old database version. |
| `newVersion: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The new database version. |

## Public properties

### version

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

```
val version: Int
```

Version number of the database (starting at 1); if the database is older, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onUpgrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)` will be used to upgrade the database; if the database is newer, `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback#onDowngrade(androidx.sqlite.db.SupportSQLiteDatabase,kotlin.Int,kotlin.Int)` will be used to downgrade the database.