Search in sources :

Example 1 with SQLiteException

use of net.sqlcipher.database.SQLiteException in project requery by requery.

the class SqlCipherMetaData method queryMemory.

@Override
protected <R> R queryMemory(Function<Cursor, R> function, String query) throws SQLException {
    try {
        final SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(":memory:", "", null);
        Cursor cursor = database.rawQuery(query, null);
        return function.apply(closeWithCursor(new Closeable() {

            @Override
            public void close() throws IOException {
                database.close();
            }
        }, cursor));
    } catch (SQLiteException e) {
        throw new SQLException(e);
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SQLException(java.sql.SQLException) Closeable(java.io.Closeable) Cursor(android.database.Cursor) SQLiteException(net.sqlcipher.database.SQLiteException)

Example 2 with SQLiteException

use of net.sqlcipher.database.SQLiteException in project requery by requery.

the class SqlCipherPreparedStatement method executeUpdate.

@Override
public int executeUpdate() throws SQLException {
    if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
        try {
            long rowId = statement.executeInsert();
            insertResult = new SingleResultSet(this, rowId);
            updateCount = 1;
        } catch (SQLiteException e) {
            SqlCipherConnection.throwSQLException(e);
        }
    } else {
        try {
            updateCount = statement.executeUpdateDelete();
        } catch (SQLiteException e) {
            SqlCipherConnection.throwSQLException(e);
        }
    }
    return updateCount;
}
Also used : SingleResultSet(io.requery.android.sqlite.SingleResultSet) SQLiteException(net.sqlcipher.database.SQLiteException)

Example 3 with SQLiteException

use of net.sqlcipher.database.SQLiteException in project requery by requery.

the class SqlCipherStatement method execute.

@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
    SQLiteStatement statement = null;
    try {
        statement = connection.getDatabase().compileStatement(sql);
        if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
            long rowId = statement.executeInsert();
            insertResult = new SingleResultSet(this, rowId);
            return true;
        } else {
            statement.execute();
        }
    } catch (SQLiteException e) {
        SqlCipherConnection.throwSQLException(e);
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
    return false;
}
Also used : SQLiteStatement(net.sqlcipher.database.SQLiteStatement) SingleResultSet(io.requery.android.sqlite.SingleResultSet) SQLiteException(net.sqlcipher.database.SQLiteException)

Example 4 with SQLiteException

use of net.sqlcipher.database.SQLiteException in project requery by requery.

the class SqlCipherPreparedStatement method executeQuery.

@Override
public ResultSet executeQuery() throws SQLException {
    try {
        String[] args = bindingsToArray();
        cursor = connection.getDatabase().rawQuery(getSql(), args);
        return queryResult = new CursorResultSet(this, cursor, false);
    } catch (SQLiteException e) {
        SqlCipherConnection.throwSQLException(e);
    }
    return null;
}
Also used : CursorResultSet(io.requery.android.sqlite.CursorResultSet) SQLiteException(net.sqlcipher.database.SQLiteException)

Example 5 with SQLiteException

use of net.sqlcipher.database.SQLiteException in project requery by requery.

the class SqlCipherStatement method executeUpdate.

@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
    SQLiteStatement statement = null;
    try {
        statement = connection.getDatabase().compileStatement(sql);
        if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
            long rowId = statement.executeInsert();
            insertResult = new SingleResultSet(this, rowId);
            return 1;
        } else {
            return updateCount = statement.executeUpdateDelete();
        }
    } catch (SQLiteException e) {
        SqlCipherConnection.throwSQLException(e);
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
    return 0;
}
Also used : SQLiteStatement(net.sqlcipher.database.SQLiteStatement) SingleResultSet(io.requery.android.sqlite.SingleResultSet) SQLiteException(net.sqlcipher.database.SQLiteException)

Aggregations

SQLiteException (net.sqlcipher.database.SQLiteException)5 SingleResultSet (io.requery.android.sqlite.SingleResultSet)3 SQLiteStatement (net.sqlcipher.database.SQLiteStatement)2 Cursor (android.database.Cursor)1 CursorResultSet (io.requery.android.sqlite.CursorResultSet)1 Closeable (java.io.Closeable)1 SQLException (java.sql.SQLException)1 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)1