Skip to content

Most visited

Recently visited

navigation

SupportSQLiteOpenHelper

public interface SupportSQLiteOpenHelper

android.arch.persistence.db.SupportSQLiteOpenHelper


An interface to map the behavior of SQLiteOpenHelper. Note that since that class requires overriding certain methods, support implementation uses create(Configuration) to create this and SupportSQLiteOpenHelper.Callback to implement the methods that should be overridden.

Summary

Nested classes

class SupportSQLiteOpenHelper.Callback

Matching callback methods from SQLiteOpenHelper

class SupportSQLiteOpenHelper.Configuration

The configuration to create an SQLite open helper object using SupportSQLiteOpenHelper.Factory

interface SupportSQLiteOpenHelper.Factory

Factory class to create instances of SupportSQLiteOpenHelper using SupportSQLiteOpenHelper.Configuration

Public methods

abstract void close()

Close any open database object.

abstract String getDatabaseName()

Return the name of the SQLite database being opened, as given to the constructor.

abstract SupportSQLiteDatabase getReadableDatabase()

Create and/or open a database.

abstract SupportSQLiteDatabase getWritableDatabase()

Create and/or open a database that will be used for reading and writing.

abstract void setWriteAheadLoggingEnabled(boolean enabled)

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

Public methods

close

void close ()

Close any open database object.

getDatabaseName

String getDatabaseName ()

Return the name of the SQLite database being opened, as given to the constructor.

Returns
String

getReadableDatabase

SupportSQLiteDatabase getReadableDatabase ()

Create and/or open a database. This will be the same object returned by getWritableDatabase() 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 getWritableDatabase() 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 getWritableDatabase(), 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 getWritableDatabase() or close() is called.

Throws
SQLiteException if the database cannot be opened

getWritableDatabase

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 onCreate(SupportSQLiteDatabase), onUpgrade(SupportSQLiteDatabase, int, int) and/or onOpen(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 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 close() is called

Throws
SQLiteException if the database cannot be opened for writing

setWriteAheadLoggingEnabled

void setWriteAheadLoggingEnabled (boolean enabled)

Enables or disables the use of write-ahead logging for the database. 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.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.