# SupportSQLiteOpenHelper.Callback

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)   
belongs to Maven artifact android.arch.persistence:db:1.1.0-beta2  
Summary: [Fields](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#lfields) \| [Ctors](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#pubctors) \| [Methods](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#inhmethods)  

# SupportSQLiteOpenHelper.Callback

| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\*](https://developer.android.com/jetpack/androidx/migrate) packages. See [androidx.sqlite.db.SupportSQLiteOpenHelper.Callback](https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Callback) instead.


`
public
static

abstract
class
SupportSQLiteOpenHelper.Callback
`


`

extends Object


`

`


`

|---|--------------------------------------------------------------|
| java.lang.Object                                                ||
| ↳ | android.arch.persistence.db.SupportSQLiteOpenHelper.Callback |

<br />

*** ** * ** ***

Handles various lifecycle events for the SQLite connection, similar to
[SQLiteOpenHelper](https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                       ### Fields                                                                                                                                                                                                                                                                                                                                                                                       ||
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public final int` | [version](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#version) Version number of the database (starting at 1); if the database is older, [onUpgrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onUpgrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int)) will be used to upgrade the database; if the database is newer, [onDowngrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onDowngrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int)) will be used to downgrade the database. |

|                                                                                                                    ### Public constructors                                                                                                                    ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[SupportSQLiteOpenHelper.Callback](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#SupportSQLiteOpenHelper.Callback(int))`(int version) ` Creates a new Callback to get database lifecycle events. |

|                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                          ||
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`          | ` `[onConfigure](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onConfigure(android.arch.persistence.db.SupportSQLiteDatabase))`(`[SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)` db) ` Called when the database connection is being configured, to enable features such as write-ahead logging or foreign key support. |
| ` void`          | ` `[onCorruption](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onCorruption(android.arch.persistence.db.SupportSQLiteDatabase))`(`[SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)` db) ` The method invoked when database corruption is detected.                                                                      |
| ` abstract void` | ` `[onCreate](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onCreate(android.arch.persistence.db.SupportSQLiteDatabase))`(`[SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)` db) ` Called when the database is created for the first time.                                                                               |
| ` void`          | ` `[onDowngrade](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onDowngrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int))`(`[SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)` db, int oldVersion, int newVersion) ` Called when the database needs to be downgraded.                                      |
| ` void`          | ` `[onOpen](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onOpen(android.arch.persistence.db.SupportSQLiteDatabase))`(`[SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)` db) ` Called when the database has been opened.                                                                                                 |
| ` abstract void` | ` `[onUpgrade](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onUpgrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int))`(`[SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)` db, int oldVersion, int newVersion) ` Called when the database needs to be upgraded.                                            |

| ### Inherited methods |
|-----------------------|---|
| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Fields

### version

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int version
```

Version number of the database (starting at 1); if the database is older,
[onUpgrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onUpgrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int))
will be used to upgrade the database; if the database is newer,
[onDowngrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onDowngrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int))
will be used to downgrade the database.

<br />

## Public constructors

### SupportSQLiteOpenHelper.Callback

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
SupportSQLiteOpenHelper.Callback (int version)
```

Creates a new Callback to get database lifecycle events.

<br />

|                                                                                          Parameters                                                                                          ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `version` | `int`: The version for the database instance. See [version](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#version). <br /> |

## Public methods

### onConfigure

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onConfigure (SupportSQLiteDatabase db)
```

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 [onCreate(SupportSQLiteDatabase)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onCreate(android.arch.persistence.db.SupportSQLiteDatabase)), [onUpgrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onUpgrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int)), [onDowngrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onDowngrade(android.arch.persistence.db.SupportSQLiteDatabase, int, int)),
or [onOpen(SupportSQLiteDatabase)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onOpen(android.arch.persistence.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 [enableWriteAheadLogging()](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase#enableWriteAheadLogging())
[setForeignKeyConstraintsEnabled(boolean)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase#setForeignKeyConstraintsEnabled(boolean)),
[setLocale(Locale)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase#setLocale(java.util.Locale)),
[setMaximumSize(long)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase#setMaximumSize(long)), or executing PRAGMA statements.

<br />

<br />

|                     Parameters                      ||
|------|-----------------------------------------------|
| `db` | `SupportSQLiteDatabase`: The database. <br /> |

### onCorruption

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onCorruption (SupportSQLiteDatabase db)
```

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

<br />

|                                                                                                           Parameters                                                                                                           ||
|------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `db` | `SupportSQLiteDatabase`: the [SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase) object representing the database on which corruption is detected. <br /> |

### onCreate

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onCreate (SupportSQLiteDatabase db)
```

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.

<br />

|                     Parameters                      ||
|------|-----------------------------------------------|
| `db` | `SupportSQLiteDatabase`: The database. <br /> |

### onDowngrade

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onDowngrade (SupportSQLiteDatabase db, 
                int oldVersion, 
                int newVersion)
```

Called when the database needs to be downgraded. This is strictly similar to
[onUpgrade(SupportSQLiteDatabase, int, int)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onUpgrade(android.arch.persistence.db.SupportSQLiteDatabase, int, 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.

<br />

<br />

|                         Parameters                          ||
|--------------|-----------------------------------------------|
| `db`         | `SupportSQLiteDatabase`: The database. <br /> |
| `oldVersion` | `int`: The old database version. <br />       |
| `newVersion` | `int`: The new database version. <br />       |

### onOpen

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onOpen (SupportSQLiteDatabase db)
```

Called when the database has been opened. The implementation
should check [isReadOnly()](https://developer.android.com/reference/android/arch/persistence/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 [onConfigure(SupportSQLiteDatabase)](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback#onConfigure(android.arch.persistence.db.SupportSQLiteDatabase)) instead.

<br />

<br />

|                     Parameters                      ||
|------|-----------------------------------------------|
| `db` | `SupportSQLiteDatabase`: The database. <br /> |

### onUpgrade

added in [version 1.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void onUpgrade (SupportSQLiteDatabase db, 
                int oldVersion, 
                int newVersion)
```

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.

<br />

<br />

|                         Parameters                          ||
|--------------|-----------------------------------------------|
| `db`         | `SupportSQLiteDatabase`: The database. <br /> |
| `oldVersion` | `int`: The old database version. <br />       |
| `newVersion` | `int`: The new database version. <br />       |

-

  ## Interfaces

  - [SupportSQLiteDatabase](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteDatabase)
  - [SupportSQLiteOpenHelper](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper)
  - [SupportSQLiteOpenHelper.Factory](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Factory)
  - [SupportSQLiteProgram](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteProgram)
  - [SupportSQLiteQuery](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteQuery)
  - [SupportSQLiteStatement](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteStatement)
-

  ## Classes

  - [SimpleSQLiteQuery](https://developer.android.com/reference/android/arch/persistence/db/SimpleSQLiteQuery)
  - [SupportSQLiteOpenHelper.Callback](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Callback)
  - [SupportSQLiteOpenHelper.Configuration](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Configuration)
  - [SupportSQLiteOpenHelper.Configuration.Builder](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteOpenHelper.Configuration.Builder)
  - [SupportSQLiteQueryBuilder](https://developer.android.com/reference/android/arch/persistence/db/SupportSQLiteQueryBuilder)