Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a DatabaseAdapter class which contains two databases which are opened together.</p> <pre><code>public class DatabaseAdapter { /** Identifier for the internal database */ public static final int INTERNAL = 0; /** Identifier for the external database */ public static final int EXTERNAL = 1; private final SQLiteOpenHelper[] mDatabaseManager = new SQLiteOpenHelper[2]; private final SQLiteDatabase[] mDatabases = new SQLiteDatabase[2]; /** * Constructs the database and open it. */ public DatabaseAdapter() { // Open the internal_db mDatabaseManager[INTERNAL] = new InternalDatabaseManager(MyApplication.getInstance()); mDatabases[INTERNAL] = mDatabaseManager[INTERNAL].getWritableDatabase(); } /** * Checks the database state and throws an {@link IllegalStateException} if database isn't open. * Should always be used before starting to access the database. * * @param type Type of the database. Can be INTERNAL or EXTERNAL. */ public void checkDbState(int type) { if (mDatabases[type] == null || !mDatabases[type].isOpen()) { throw new IllegalStateException("The database has not been opened"); } } /** * Closes the database of the given type. * * @param type Type of the database. Can be INTERNAL or EXTERNAL. */ public void close(int type) { if (mDatabases[type].isOpen()) { mDatabases[type].close(); mDatabases[type] = null; if (mDatabaseManager[type] != null) { mDatabaseManager[type].close(); mDatabaseManager[type] = null; } } } /** * @param type Type of the database. Can be INTERNAL or EXTERNAL. * @return true if the database is open, false otherwise. */ public boolean isOpen(int type) { return mDatabases[type] != null &amp;&amp; mDatabases[type].isOpen(); } /** * Opens the default database. * * @param type Type of the database. Can be INTERNAL or EXTERNAL. */ public void open(int type) { switch (type) { case INTERNAL: mDatabaseManager[INTERNAL] = new InternalDatabaseManager(MyApplication.getInstance()); if (!isOpen(INTERNAL)) { mDatabases[INTERNAL] = mDatabaseManager[INTERNAL].getWritableDatabase(); } break; case EXTERNAL: mDatabaseManager[EXTERNAL] = new ExternalDatabaseManager(MyApplication.getInstance(), Constants.EXTERNAL_DB_PATH, 1); if (!isOpen(EXTERNAL)) { mDatabases[EXTERNAL] = mDatabaseManager[EXTERNAL].getWritableDatabase(); } break; } } } </code></pre> <p>to add a third one should be easy :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload