Java Code Examples for net.sqlcipher.database.SQLiteDatabase#isOpen()

The following examples show how to use net.sqlcipher.database.SQLiteDatabase#isOpen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public final int update(final Uri url, final ContentValues values, final String selection,
        final String[] selectionArgs) {

    DatabaseHelper dbHelper = getDBHelper();


    int result = 0;

    if (dbHelper != null)
    {
        SQLiteDatabase db = dbHelper.getWritableDatabase();

        if (db.isOpen())
        {
            try {
                db.beginTransaction();

                result = updateInternal(url, values, selection, selectionArgs);
                db.setTransactionSuccessful();
                db.endTransaction();
            }
            catch (Exception e){

                if (db.isOpen() && db.inTransaction())
                    db.endTransaction();
            }


            if (result > 0) {
                getContext().getContentResolver()
                        .notifyChange(url, null /* observer */, false /* sync */);
            }
        }

    }

    return result;
}
 
Example 2
@Override
public final int delete(final Uri url, final String selection, final String[] selectionArgs) {

    int result = -1;

    if (getDBHelper() != null)
    {
        SQLiteDatabase db = getDBHelper().getWritableDatabase();

        if (db.isOpen()) //db can be closed if service sign out takes longer than app/cacheword lock
        {
            try {
                db.beginTransaction();
                result = deleteInternal(url, selection, selectionArgs);
                db.setTransactionSuccessful();
                db.endTransaction();
            }
            catch (Exception e)
            {
                //could not delete
            }

            if (result > 0) {
                getContext().getContentResolver()
                        .notifyChange(url, null /* observer */, false /* sync */);
            }
        }
    }

    return result;
}
 
Example 3
@Override
public final Uri insert(final Uri url, final ContentValues values) {
    Uri result = null;

    if (getDBHelper() != null)
    {
        try
        {
            SQLiteDatabase db = getDBHelper().getWritableDatabase();

            if (db.isOpen())
            {
                db.beginTransaction();
                try {
                    result = insertInternal(url, values);
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                }
                if (result != null) {
                    getContext().getContentResolver()
                            .notifyChange(url, null /* observer */, false /* sync */);
                }
            }

        }
        catch (IllegalStateException ise)
        {
            log("database closed when insert attempted: " + url.toString());
        }
    }
    return result;
}