Code example for SQLiteDatabase

Methods: endTransactionexecSQLgetVersionsetTransactionSuccessfulsetVersion, beginTransactionNonExclusive

0
            // Not much we can do to recover at this point 
            Log.e(LOGTAG, "Unable to open or create " + databaseFile);
            return; 
        } 
 
        if (mDatabase.getVersion() != DATABASE_VERSION) {
            mDatabase.beginTransactionNonExclusive();
            try { 
                createTable(); 
                mDatabase.setTransactionSuccessful();
            } finally { 
                mDatabase.endTransaction();
            } 
        } 
    } 
 
    private void createTable() { 
        mDatabase.execSQL("CREATE TABLE " + HTTPAUTH_TABLE_NAME
                + " (" + ID_COL + " INTEGER PRIMARY KEY, "
                + HTTPAUTH_HOST_COL + " TEXT, " + HTTPAUTH_REALM_COL
                + " TEXT, " + HTTPAUTH_USERNAME_COL + " TEXT, "
                + HTTPAUTH_PASSWORD_COL + " TEXT," + " UNIQUE ("
                + HTTPAUTH_HOST_COL + ", " + HTTPAUTH_REALM_COL
                + ") ON CONFLICT REPLACE);"); 
 
        mDatabase.setVersion(DATABASE_VERSION);
    } 
 
    /** 
     * Waits for the background initialization thread to complete and check the database creation 
     * status.