SQLiteDatabase class

Exposes methods to manage a SQLite database.

SQLiteDatabase has methods to create, delete, execute SQL commands, and perform other common database management tasks.

See the Notepad example application for an example of creating and managing a database.

Database names must be unique within an application, not across all applications.

See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase

Implemented types

Constructors

SQLiteDatabase()

Properties

id int
The internal database identifier.
read-only
inTransaction Future<bool>
Returns true if the current thread has a transaction pending. [...]
read-only
isDatabaseIntegrityOk Future<bool>
Runs PRAGMA integrity_check on the given database (and all the attached databases). [...]
read-only
isDbLockedByCurrentThread Future<bool>
Returns true if the current thread is holding an active connection to the database. [...]
read-only
isOpen Future<bool>
Returns true if the database is currently open. [...]
read-only
isReadOnly Future<bool>
Returns true if the database is opened as read only. [...]
read-only
isWriteAheadLoggingEnabled Future<bool>
Returns true if write-ahead logging has been enabled for this database. [...]
read-only
maximumSize Future<int>
The maximum size, in bytes, that the database may grow to. [...]
read-only
pageSize Future<int>
The current database page size, in bytes. [...]
read-only
path Future<String>
The path to the database file. [...]
read-only
version Future<int>
The database version. [...]
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

beginTransaction() Future<void>
Begins a transaction in EXCLUSIVE mode. [...]
beginTransactionNonExclusive() Future<void>
Begins a transaction in IMMEDIATE mode. [...]
close() Future<void>
Closes this resource, relinquishing any underlying resources. [...]
override
delete({String table, String where, List<String> whereArgs }) Future<int>
Convenience method for deleting rows in the database. [...]
disableWriteAheadLogging() Future<void>
This method disables the features enabled by enableWriteAheadLogging. [...]
enableWriteAheadLogging() Future<bool>
This method enables parallel execution of queries from multiple threads on the same database. [...]
endTransaction() Future<void>
Ends a transaction. [...]
execSQL(String sql, [ List args = const [] ]) Future<void>
Executes a single SQL statement that is not a SELECT or any other SQL statement that returns data. [...]
getAttachedDbs() Future<Map<String, String>>
Returns list of full pathnames of all attached databases including the main database by executing PRAGMA database_list on the database. [...]
getMaximumSize() Future<int>
Returns the maximum size, in bytes, that the database may grow to. [...]
getPageSize() Future<int>
Returns the current database page size, in bytes. [...]
getPath() Future<String>
Gets the path to the database file. [...]
getVersion() Future<int>
Gets the database version. [...]
insert({String table, Map<String, dynamic> values }) Future<int>
Convenience method for inserting a row into the database. [...]
insertOrThrow({String table, Map<String, dynamic> values }) Future<int>
Convenience method for inserting a row into the database. [...]
insertWithOnConflict({String table, Map<String, dynamic> values, int conflictAlgorithm }) Future<int>
General method for inserting a row into the database. [...]
needUpgrade(int newVersion) Future<bool>
Returns true if the new version code is greater than the current database version. [...]
query({bool distinct: false, String table, List<String> columns, String where, List<String> whereArgs, String groupBy, String having, String orderBy, Object limit }) Future<SQLiteCursor>
Query the given table, returning a Cursor over the result set. [...]
rawQuery(String sql, [ List<String> args = const [] ]) Future<SQLiteCursor>
Runs the provided SQL and returns a cursor over the result set. [...]
replace({String table, Map<String, dynamic> values }) Future<int>
Convenience method for replacing a row in the database. [...]
replaceOrThrow({String table, Map<String, dynamic> values }) Future<int>
Convenience method for replacing a row in the database. [...]
setForeignKeyConstraintsEnabled(bool enable) Future<void>
Sets whether foreign key constraints are enabled for the database. [...]
setLocale(Locale locale) Future<void>
Sets the locale for this database. [...]
setMaximumSize(int numBytes) Future<void>
Sets the maximum size the database will grow to. [...]
setMaxSqlCacheSize(int cacheSize) Future<void>
Sets the maximum size of the prepared-statement cache for this database. [...]
setPageSize(int numBytes) Future<void>
Sets the database page size. [...]
setTransactionSuccessful() Future<void>
Marks the current transaction as successful. [...]
setVersion(int version) Future<void>
Sets the database version. [...]
update({String table, Map<String, dynamic> values, String where, List<String> whereArgs }) Future<int>
Convenience method for updating rows in the database. [...]
updateWithOnConflict({String table, Map<String, dynamic> values, String where, List<String> whereArgs, int conflictAlgorithm }) Future<int>
Convenience method for updating rows in the database. [...]
validateSql(String sql) Future<void>
Verifies that a SQL SELECT statement is valid by compiling it. [...]
yieldIfContendedSafely([int sleepAfterYieldDelay = 0 ]) Future<bool>
Temporarily end the transaction to let other threads run. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Methods

create({String password }) Future<SQLiteDatabase>
Create a memory-backed SQLite database. [...]
createInMemory({String password }) Future<SQLiteDatabase>
Create a memory-backed SQLite database. [...]
deleteDatabase(String path) Future<bool>
Deletes a database including its journal file and other auxiliary files that may have been created by the database engine. [...]
openDatabase(String path, { String password, int flags: OPEN_READWRITE }) Future<SQLiteDatabase>
Open the database according to the specified parameters. [...]
openOrCreateDatabase(String path, { String password }) Future<SQLiteDatabase>
Equivalent to openDatabase(path, flags: CREATE_IF_NECESSARY). [...]
releaseMemory() Future<int>
Attempts to release memory that SQLite holds but does not require to operate properly. [...]

Constants

CONFLICT_ABORT → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CONFLICT_ABORT
2
CONFLICT_FAIL → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CONFLICT_FAIL
3
CONFLICT_IGNORE → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CONFLICT_IGNORE
4
CONFLICT_NONE → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CONFLICT_NONE
0
CONFLICT_REPLACE → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CONFLICT_REPLACE
5
CONFLICT_ROLLBACK → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CONFLICT_ROLLBACK
1
CREATE_IF_NECESSARY → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#CREATE_IF_NECESSARY
0x10000000
ENABLE_WRITE_AHEAD_LOGGING → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#ENABLE_WRITE_AHEAD_LOGGING
0x20000000
MAX_SQL_CACHE_SIZE → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#MAX_SQL_CACHE_SIZE
100
NO_LOCALIZED_COLLATORS → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#NO_LOCALIZED_COLLATORS
0x00000010
OPEN_READONLY → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#OPEN_READONLY
0x00000001
OPEN_READWRITE → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#OPEN_READWRITE
0x00000000
SQLITE_MAX_LIKE_PATTERN_LENGTH → const int
See: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#SQLITE_MAX_LIKE_PATTERN_LENGTH
50000