O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

SupportSQLiteDatabase

interface SupportSQLiteDatabase : Closeable
androidx.sqlite.db.SupportSQLiteDatabase

A database abstraction which removes the framework dependency and allows swapping underlying sql versions. It mimics the behavior of android.database.sqlite.SQLiteDatabase

Summary

Public methods
abstract Unit

Begins a transaction in EXCLUSIVE mode.

abstract Unit

Begins a transaction in IMMEDIATE mode.

abstract Unit

Begins a transaction in EXCLUSIVE mode.

abstract Unit

Begins a transaction in IMMEDIATE mode.

abstract SupportSQLiteStatement!

Compiles the given SQL statement.

abstract Int
delete(table: String!, whereClause: String!, whereArgs: Array<Any!>!)

Convenience method for deleting rows in the database.

abstract Unit

This method disables the features enabled by enableWriteAheadLogging().

abstract Boolean

This method enables parallel execution of queries from multiple threads on the same database.

abstract Unit

End a transaction.

abstract Unit
execSQL(sql: String!)

Execute a single SQL statement that does not return any data.

abstract Unit
execSQL(sql: String!, bindArgs: Array<Any!>!)

Execute a single SQL statement that does not return any data.

abstract MutableList<Pair<String!, String!>!>!

Returns list of full path names of all attached databases including the main database by executing 'pragma database_list' on the database.

abstract Long

Returns the maximum size the database may grow to.

abstract Long

Returns the current database page size, in bytes.

abstract String!

Gets the path to the database file.

abstract Int

Gets the database version.

abstract Boolean

Returns true if the current thread has a transaction pending.

abstract Long
insert(table: String!, conflictAlgorithm: Int, values: ContentValues!)

Convenience method for inserting a row into the database.

abstract Boolean

Runs 'pragma integrity_check' on the given database (and all the attached databases) and returns true if the given database (and all its attached databases) pass integrity_check, false otherwise.

abstract Boolean

Returns true if the current thread is holding an active connection to the database.

abstract Boolean

Returns true if the database is currently open.

abstract Boolean

Returns true if the database is opened as read only.

abstract Boolean

Returns true if write-ahead logging has been enabled for this database.

abstract Boolean
needUpgrade(newVersion: Int)

Returns true if the new version code is greater than the current database version.

abstract Cursor!
query(query: String!)

Runs the given query on the database.

abstract Cursor!
query(query: String!, bindArgs: Array<Any!>!)

Runs the given query on the database.

abstract Cursor!

Runs the given query on the database.

abstract Cursor!
query(query: SupportSQLiteQuery!, cancellationSignal: CancellationSignal!)

Runs the given query on the database.

abstract Unit

Sets whether foreign key constraints are enabled for the database.

abstract Unit
setLocale(locale: Locale!)

Sets the locale for this database.

abstract Unit
setMaxSqlCacheSize(cacheSize: Int)

Sets the maximum size of the prepared-statement cache for this database.

abstract Long
setMaximumSize(numBytes: Long)

Sets the maximum size the database will grow to.

abstract Unit
setPageSize(numBytes: Long)

Sets the database page size.

abstract Unit

Marks the current transaction as successful.

abstract Unit
setVersion(version: Int)

Sets the database version.

abstract Int
update(table: String!, conflictAlgorithm: Int, values: ContentValues!, whereClause: String!, whereArgs: Array<Any!>!)

Convenience method for updating rows in the database.

abstract Boolean

Temporarily end the transaction to let other threads run.

abstract Boolean
yieldIfContendedSafely(sleepAfterYieldDelay: Long)

Temporarily end the transaction to let other threads run.

Extension functions
From androidx.sqlite.db
T
SupportSQLiteDatabase.transaction(exclusive: Boolean = true, body: SupportSQLiteDatabase.() -> T)

Run body in a transaction marking it as successful if it completes without exception.

Public methods

beginTransaction

abstract fun beginTransaction(): Unit

Begins a transaction in EXCLUSIVE mode.

Transactions can be nested. When the outer transaction is ended all of the work done in that transaction and all of the nested transactions will be committed or rolled back. The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful). Otherwise they will be committed.

Here is the standard idiom for transactions:

db.beginTransaction();
        try {
          ...
          db.setTransactionSuccessful();
        } finally {
          db.endTransaction();
        }
      

beginTransactionNonExclusive

abstract fun beginTransactionNonExclusive(): Unit

Begins a transaction in IMMEDIATE mode. Transactions can be nested. When the outer transaction is ended all of the work done in that transaction and all of the nested transactions will be committed or rolled back. The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful). Otherwise they will be committed.

Here is the standard idiom for transactions:

db.beginTransactionNonExclusive();
        try {
          ...
          db.setTransactionSuccessful();
        } finally {
          db.endTransaction();
        }
      

beginTransactionWithListener

abstract fun beginTransactionWithListener(transactionListener: SQLiteTransactionListener!): Unit

Begins a transaction in EXCLUSIVE mode.

Transactions can be nested. When the outer transaction is ended all of the work done in that transaction and all of the nested transactions will be committed or rolled back. The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful). Otherwise they will be committed.

Here is the standard idiom for transactions:

db.beginTransactionWithListener(listener);
        try {
          ...
          db.setTransactionSuccessful();
        } finally {
          db.endTransaction();
        }
      
Parameters
transactionListener SQLiteTransactionListener!: listener that should be notified when the transaction begins, commits, or is rolled back, either explicitly or by a call to #yieldIfContendedSafely.

beginTransactionWithListenerNonExclusive

abstract fun beginTransactionWithListenerNonExclusive(transactionListener: SQLiteTransactionListener!): Unit

Begins a transaction in IMMEDIATE mode. Transactions can be nested. When the outer transaction is ended all of the work done in that transaction and all of the nested transactions will be committed or rolled back. The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful). Otherwise they will be committed.

Here is the standard idiom for transactions:

db.beginTransactionWithListenerNonExclusive(listener);
        try {
          ...
          db.setTransactionSuccessful();
        } finally {
          db.endTransaction();
        }
      
Parameters
transactionListener SQLiteTransactionListener!: listener that should be notified when the transaction begins, commits, or is rolled back, either explicitly or by a call to #yieldIfContendedSafely.

compileStatement

abstract fun compileStatement(sql: String!): SupportSQLiteStatement!

Compiles the given SQL statement.

Parameters
sql String!: The sql query.
Return
SupportSQLiteStatement! Compiled statement.

delete

abstract fun delete(
    table: String!,
    whereClause: String!,
    whereArgs: Array<Any!>!
): Int

Convenience method for deleting rows in the database.

Parameters
table String!: the table to delete from
whereClause String!: the optional WHERE clause to apply when deleting. Passing null will delete all rows.
whereArgs Array<Any!>!: You may include ?s in the where clause, which will be replaced by the values from whereArgs. The values will be bound as Strings.
Return
Int the number of rows affected if a whereClause is passed in, 0 otherwise. To remove all rows and get a count pass "1" as the whereClause.

disableWriteAheadLogging

@RequiresApi(16) abstract fun disableWriteAheadLogging(): Unit

This method disables the features enabled by enableWriteAheadLogging().

Exceptions
IllegalStateException if there are transactions in progress at the time this method is called. WAL mode can only be changed when there are no transactions in progress.

enableWriteAheadLogging

abstract fun enableWriteAheadLogging(): Boolean

This method enables parallel execution of queries from multiple threads on the same database. It does this by opening multiple connections to the database and using a different database connection for each query. The database journal mode is also changed to enable writes to proceed concurrently with reads.

When write-ahead logging is not enabled (the default), it is not possible for reads and writes to occur on the database at the same time. Before modifying the database, the writer implicitly acquires an exclusive lock on the database which prevents readers from accessing the database until the write is completed.

In contrast, when write-ahead logging is enabled (by calling this method), write operations occur in a separate log file which allows reads to proceed concurrently. While a write is in progress, readers on other threads will perceive the state of the database as it was before the write began. When the write completes, readers on other threads will then perceive the new state of the database.

It is a good idea to enable write-ahead logging whenever a database will be concurrently accessed and modified by multiple threads at the same time. However, write-ahead logging uses significantly more memory than ordinary journaling because there are multiple connections to the same database. So if a database will only be used by a single thread, or if optimizing concurrency is not very important, then write-ahead logging should be disabled.

After calling this method, execution of queries in parallel is enabled as long as the database remains open. To disable execution of queries in parallel, either call disableWriteAheadLogging or close the database and reopen it.

The maximum number of connections used to execute queries in parallel is dependent upon the device memory and possibly other properties.

If a query is part of a transaction, then it is executed on the same database handle the transaction was begun.

Writers should use beginTransactionNonExclusive() or beginTransactionWithListenerNonExclusive(SQLiteTransactionListener) to start a transaction. Non-exclusive mode allows database file to be in readable by other threads executing queries.

If the database has any attached databases, then execution of queries in parallel is NOT possible. Likewise, write-ahead logging is not supported for read-only databases or memory databases. In such cases, enableWriteAheadLogging returns false.

The best way to enable write-ahead logging is to pass the SQLiteDatabase#ENABLE_WRITE_AHEAD_LOGGING flag to SQLiteDatabase#openDatabase. This is more efficient than calling

<code>
          SQLiteDatabase db = SQLiteDatabase.openDatabase("db_filename", cursorFactory,
                  SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING,
                  myDatabaseErrorHandler);
          db.enableWriteAheadLogging();
      </code>

Another way to enable write-ahead logging is to call enableWriteAheadLogging after opening the database.

<code>
          SQLiteDatabase db = SQLiteDatabase.openDatabase("db_filename", cursorFactory,
                  SQLiteDatabase.CREATE_IF_NECESSARY, myDatabaseErrorHandler);
          db.enableWriteAheadLogging();
      </code>

See also SQLite Write-Ahead Logging for more details about how write-ahead logging works.

Return
Boolean True if write-ahead logging is enabled.
Exceptions
IllegalStateException if there are transactions in progress at the time this method is called. WAL mode can only be changed when there are no transactions in progress.

endTransaction

abstract fun endTransaction(): Unit

End a transaction. See beginTransaction for notes about how to use this and when transactions are committed and rolled back.

execSQL

abstract fun execSQL(sql: String!): Unit

Execute a single SQL statement that does not return any data.

When using enableWriteAheadLogging(), journal_mode is automatically managed by this class. So, do not set journal_mode using "PRAGMA journal_mode'" statement if your app is using enableWriteAheadLogging()

Parameters
sql String!: the SQL statement to be executed. Multiple statements separated by semicolons are not supported.
Exceptions
SQLException if the SQL string is invalid

execSQL

abstract fun execSQL(
    sql: String!,
    bindArgs: Array<Any!>!
): Unit

Execute a single SQL statement that does not return any data.

When using enableWriteAheadLogging(), journal_mode is automatically managed by this class. So, do not set journal_mode using "PRAGMA journal_mode'" statement if your app is using enableWriteAheadLogging()

Parameters
sql String!: the SQL statement to be executed. Multiple statements separated by semicolons are not supported.
bindArgs Array<Any!>!: only byte[], String, Long and Double are supported in selectionArgs.
Exceptions
SQLException if the SQL string is invalid

getAttachedDbs

abstract fun getAttachedDbs(): MutableList<Pair<String!, String!>!>!

Returns list of full path names of all attached databases including the main database by executing 'pragma database_list' on the database.

Return
MutableList<Pair<String!, String!>!>! ArrayList of pairs of (database name, database file path) or null if the database is not open.

getMaximumSize

abstract fun getMaximumSize(): Long

Returns the maximum size the database may grow to.

Return
Long the new maximum database size

getPageSize

abstract fun getPageSize(): Long

Returns the current database page size, in bytes.

Return
Long the database page size, in bytes

getPath

abstract fun getPath(): String!

Gets the path to the database file.

Return
String! The path to the database file.

getVersion

abstract fun getVersion(): Int

Gets the database version.

Return
Int the database version

inTransaction

abstract fun inTransaction(): Boolean

Returns true if the current thread has a transaction pending.

Return
Boolean True if the current thread is in a transaction.

insert

abstract fun insert(
    table: String!,
    conflictAlgorithm: Int,
    values: ContentValues!
): Long

Convenience method for inserting a row into the database.

Parameters
table String!: the table to insert the row into
values ContentValues!: this map contains the initial column values for the row. The keys should be the column names and the values the column values
conflictAlgorithm Int: for insert conflict resolver. One of SQLiteDatabase#CONFLICT_NONE, SQLiteDatabase#CONFLICT_ROLLBACK,