IT. Expert System.

Android Reference

SQLiteOpenHelper


android.database.sqlite

Class SQLiteOpenHelper



  • public abstract class SQLiteOpenHelper
    extends Object
    A helper class to manage database creation and version management.

    You create a subclass implementing onCreate(android.database.sqlite.SQLiteDatabase), onUpgrade(android.database.sqlite.SQLiteDatabase, int, int) and optionally onOpen(android.database.sqlite.SQLiteDatabase), and this class takes care of opening the database if it exists, creating it if it does not, and upgrading it as necessary. Transactions are used to make sure the database is always in a sensible state.

    This class makes it easy for ContentProvider implementations to defer opening and upgrading the database until first use, to avoid blocking application startup with long-running database upgrades.

    For an example, see the NotePadProvider class in the NotePad sample application, in the samples/ directory of the SDK.

    Note: this class assumes monotonically increasing version numbers for upgrades.

    • Method Detail

      • getDatabaseName

        public String getDatabaseName()
        Return the name of the SQLite database being opened, as given to the constructor.
      • setWriteAheadLoggingEnabled

        public 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 - True if write-ahead logging should be enabled, false if it should be disabled.
        See Also:
        SQLiteDatabase.enableWriteAheadLogging()
      • getReadableDatabase

        public SQLiteDatabase 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:
        a database object valid until getWritableDatabase() or close() is called.
        Throws:
        SQLiteException - if the database cannot be opened
      • close

        public void close()
        Close any open database object.
      • onCreate

        public abstract void onCreate(SQLiteDatabase 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.
        Parameters:
        db - The database.
      • onUpgrade

        public abstract void onUpgrade(SQLiteDatabase 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. 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 - The database.
        oldVersion - The old database version.
        newVersion - The new database version.
      • onDowngrade

        public void onDowngrade(SQLiteDatabase db,
                       int oldVersion,
                       int newVersion)
        Called when the database needs to be downgraded. This is strictly similar to onUpgrade(android.database.sqlite.SQLiteDatabase, 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.

        Parameters:
        db - The database.
        oldVersion - The old database version.
        newVersion - The new database version.
      • onOpen

        public void onOpen(SQLiteDatabase db)
        Called when the database has been opened. The implementation should check SQLiteDatabase.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(android.database.sqlite.SQLiteDatabase) instead.

        Parameters:
        db - The database.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 29 / 158748741. Delta: 0.03483 с