Code example for SQLiteDatabase

Methods: beginTransactionendTransactionquerysetTransactionSuccessful

0
     * @return a copy of all the MetaData fields. 
     */ 
    public Fields getFields() { 
        Fields fields = new Fields();
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        db.beginTransaction();
        try { 
            // If the fields have not been initialized from the database, 
            // then read the database. 
            if (!mInitialized) {
                readLocked(db);
            } 
            fields.timezone = mFields.timezone;
            fields.minInstance = mFields.minInstance;
            fields.maxInstance = mFields.maxInstance;
            db.setTransactionSuccessful();
        } finally { 
            db.endTransaction();
        } 
        return fields;
    } 
 
    /** 
     * This method must be called only while holding a database lock. 
     * 
     * <p> 
     * Returns a copy of all the MetaData fields.  This method assumes 
     * the database lock has already been acquired. 
     * </p> 
     * 
     * @return a copy of all the MetaData fields. 
     */ 
    public Fields getFieldsLocked() { 
        Fields fields = new Fields();
 
        // If the fields have not been initialized from the database, 
        // then read the database. 
        if (!mInitialized) {
            SQLiteDatabase db = mOpenHelper.getReadableDatabase();
            readLocked(db);
        } 
        fields.timezone = mFields.timezone;
        fields.minInstance = mFields.minInstance;
        fields.maxInstance = mFields.maxInstance;
        return fields;
    } 
 
    /** 
     * Reads the meta-data for the CalendarProvider from the database and 
     * updates the member variables.  This method executes while the database 
     * lock is held.  If there were no exceptions reading the database, 
     * mInitialized is set to true. 
     */ 
    private void readLocked(SQLiteDatabase db) {
        String timezone = null;
        long minInstance = 0, maxInstance = 0;
 
        // Read the database directly.  We only do this once to initialize 
        // the members of this class. 
        Cursor cursor = db.query("CalendarMetaData", sCalendarMetaDataProjection,
                null, null, null, null, null); 
        try { 
            if (cursor.moveToNext()) {
                timezone = cursor.getString(METADATA_INDEX_LOCAL_TIMEZONE);
                minInstance = cursor.getLong(METADATA_INDEX_MIN_INSTANCE);