Class SecureDatabaseStore

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final String getAutoEncryptionKeyAlias()
      final Boolean isOpen() Checks if the database exists and has been opened, that is, .
      final Boolean isInTransaction() Checks if a transaction is in progress.
      final SQLiteDatabase getDatabase() Returns the underlying net.sqlcipher.database.SQLiteDatabase instance assuming .
      final String getDatabaseName()
      final Unit open(ByteArray encryptionKey) Opens the encrypted database with the encryption key.
      final Unit changeEncryptionKey(ByteArray newEncryptionKey) Changes the encryption key of the database.
      final Boolean deleteAutoEncryptionKey()
      final Boolean existsAutoEncryptionKey()
      final Unit deleteStore(Context context) Deletes the database file.
      final Unit close() Closes the database.
      final Unit executeUpdate(String sql) Executes a non-SELECT statement that does contain parameters ('?').
      final Unit executeUpdate(String sql, Object values) Executes a non-SELECT statement that contains parameters ('?').
      final Unit executeInsert(String tableName, ContentValues values) Executes an INSERT statement by filling the column names and the associated values in a ContentValues object.
      final Unit executeStatements(String sqlStatements) Executes multiple SQL statements, each SQL statement does not contain parameters ('?').
      final SecureDatabaseResultSet executeQuery(String sql, String values) Executes a SELECT statement that contains parameters ('?').
      final SecureDatabaseResultSet executeQuery(String sql) Executes a SELECT statement that does not contains parameters ('?').
      final Unit beginExclusiveTransaction() Begins a transaction.
      final Unit commit() Commits the transaction, and ends the current transaction.
      final Unit rollback() Rolls back the current open transaction.
      final Boolean storeExists() Checks if the database file exists.
      final static CharArray toChars(ByteArray bytes) Converts a non-null/non-empty byte[] to char[].
      final static ByteArray toBytes(CharArray chars)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SecureDatabaseStore

        SecureDatabaseStore(Context context, String databaseName, Integer databaseVersion, CreateDatabaseCallback callback)
    • Method Detail

      • isOpen

         final Boolean isOpen()

        Checks if the database exists and has been opened, that is, .open )} has been called and .close has not been called.

      • isInTransaction

         final Boolean isInTransaction()

        Checks if a transaction is in progress.

      • getDatabase

         final SQLiteDatabase getDatabase()

        Returns the underlying net.sqlcipher.database.SQLiteDatabase instance assuming .SecureDatabaseStore and .open have been called.

      • open

         final Unit open(ByteArray encryptionKey)

        Opens the encrypted database with the encryption key.

        You must open the store before you can interact with it. The store can fail to open if the encryption key is incorrect. When the store is opened for the first time, the provided key is used to encrypt the database.

        Parameters:
        encryptionKey - the key to encrypt the store.
      • changeEncryptionKey

         final Unit changeEncryptionKey(ByteArray newEncryptionKey)

        Changes the encryption key of the database.

        Database should have been opened with the old encryption key.

        Parameters:
        newEncryptionKey - new encryption key.
      • deleteStore

         final Unit deleteStore(Context context)

        Deletes the database file. Note that this instance is no longer usable after the call, any operation performed on the instance will get FileMissingException.

        Parameters:
        context - Android application context
      • close

         final Unit close()

        Closes the database. Note that once the database is closed, no operations are allowed.

      • executeUpdate

         final Unit executeUpdate(String sql)

        Executes a non-SELECT statement that does contain parameters ('?').

        Any SQL statement that is not a SELECT statement qualifies as an update, including CREATE, UPDATE, INSERT, ALTER, COMMIT, BEGIN, DETACH, DELETE, DROP, END, EXPLAIN, VACUUM, and REPLACE statements and many more. Basically, if your SQL statement does not begin with SELECT, it is an update statement.

        As a good practice, should use .executeUpdate if possible.

        Parameters:
        sql - a SQL statement that does not contains parameters ('?
      • executeUpdate

         final Unit executeUpdate(String sql, Object values)

        Executes a non-SELECT statement that contains parameters ('?').

        Any SQL statement that is not a SELECT statement qualifies as an update, including CREATE, UPDATE, INSERT, ALTER, COMMIT, BEGIN, DETACH, DELETE, DROP, END, EXPLAIN, VACUUM, and REPLACE statements and many more. Basically, if your SQL statement does not begin with SELECT, it is an update statement.

        Parameters:
        sql - a valid SQL statement that does not begin with SELECT and contains '?
        values - array of objects to match the '?
      • executeInsert

         final Unit executeInsert(String tableName, ContentValues values)

        Executes an INSERT statement by filling the column names and the associated values in a ContentValues object.

        Example:

        <pre>`static final String TABLE_NAME = "account_user"; static final String COLUMN_EMAIL = "email"; static final String COLUMN_FULL_NAME = "fullName"; static final String COLUMN_ACCOUNT_NAME = "accountName"; // Fills each column with value. ContentValues cv = new ContentValues(); cv.put(COLUMN_EMAIL, "john.smith@mycompany.com"); cv.put(COLUMN_FULL_NAME, "John Smith"); cv.put(COLUMN_ACCOUNT_NAME, "JSmith032"); // databaseStore was defined, instantiated and opened already. databaseStore.executeInsert(TABLE_NAME, cv); ` * </pre> *
        Parameters:
        tableName - table name
        values - a ContentValues object that contains column names and the associated values
      • executeStatements

         final Unit executeStatements(String sqlStatements)

        Executes multiple SQL statements, each SQL statement does not contain parameters ('?'). The multiple SQL statements will be executed inside a transaction, any SQL statement execution failure will cause the changes to be rolled back.

        Parameters:
        sqlStatements - a vararg (array) of SQL statements
      • executeQuery

         final SecureDatabaseResultSet executeQuery(String sql, String values)

        Executes a SELECT statement that contains parameters ('?').

        Parameters:
        sql - a SELECT statement
        values - one or more String values to match the '?
      • executeQuery

         final SecureDatabaseResultSet executeQuery(String sql)

        Executes a SELECT statement that does not contains parameters ('?').

        As a good practice, use .executeQuery if possible.

        Parameters:
        sql - a SELECT statement
      • commit

         final Unit commit()

        Commits the transaction, and ends the current transaction.

      • rollback

         final Unit rollback()

        Rolls back the current open transaction.

      • storeExists

        @Synchronized() final Boolean storeExists()

        Checks if the database file exists.

      • toChars

         final static CharArray toChars(ByteArray bytes)

        Converts a non-null/non-empty byte[] to char[].

        Parameters:
        bytes - a non-null/non-empty byte[]
      • toBytes

         final static ByteArray toBytes(CharArray chars)