java.lang.Object | |
↳ | com.neomades.database.Database |
Exposes methods to manage a SQL database.
Database has methods to create, delete, execute SQL commands, and perform other common database management tasks.
Database names must be unique within an application, but not necessarily across all applications.
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Database()
Default constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract void |
beginTransaction()
Begins a transaction in EXCLUSIVE mode.
| ||||||||||
abstract void |
close()
Releases a reference to the object, closing the object if the last reference
was released.
| ||||||||||
abstract void |
commitTransaction()
Commits a transaction.
| ||||||||||
static String[] |
databaseList()
Returns an array of strings naming the private databases of the application.
| ||||||||||
static void |
deleteDatabase(String databaseName)
Deletes an existing private Database.
| ||||||||||
abstract Cursor |
execQuery(String sql)
Runs the provided SQL and returns a Cursor over the result set.
| ||||||||||
abstract Cursor |
execQuery(String sql, String[] params)
Runs the provided SQL and returns a Cursor over the result set.
| ||||||||||
abstract void |
execSQL(String sql, String[] params)
Executes a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
| ||||||||||
abstract void |
execSQL(String sql)
Executes a single SQL statement that is NOT a SELECT or any other SQL
statement that returns data.
| ||||||||||
abstract void |
execSQL(String sql, Object[] params)
Executes a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
| ||||||||||
static boolean |
exists(String databaseName)
Checks if a Database exists.
| ||||||||||
static File |
getDatabasePath(String databaseName)
Returns the absolute path on the file system where the database with the
given name is stored.
| ||||||||||
abstract String |
getName()
Returns the unique name (in the application) of the database.
| ||||||||||
abstract int |
getVersion()
Returns the version of the Database.
| ||||||||||
static Database |
openOrCreateDatabase(String databaseName)
Opens a new private Database.
| ||||||||||
static Database |
openOrCreateDatabase(String databaseName, int version, DatabaseOpenHelper helper)
Opens a new private Database using a helper object to create, open, and/or
manage a database.
| ||||||||||
abstract void |
rollbackTransaction()
Rollbacks (cancels) the current transaction.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Default constructor.
Begins a transaction in EXCLUSIVE mode. It means that no other database
connection (except for read_uncommitted
connections) will be
able to read the database and no other connection without exception will be
able to write the database until the transaction is complete
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 committed (using commitTransaction()
).
Releases a reference to the object, closing the object if the last reference was released.
Returns an array of strings naming the private databases of the application.
Deletes an existing private Database.
databaseName | the name (unique) of the database |
---|
Runs the provided SQL and returns a Cursor over the result set.
Note: the returned Cursor will be empty if the query is not a SELECT.
Moreover in that case, the query will not be immediately run. To execute the
request, call moveToFirst()
. Even after the query execution,
the Cursor will remain empty.
sql | the SQL query. The SQL string must not be ; terminated |
---|
Cursor
object, which is positioned before the first entry.
Note that Cursors are not synchronized.
Runs the provided SQL and returns a Cursor over the result set.
Note: the returned Cursor will be empty if the query is not a SELECT.
Moreover in that case, the query will not be immediately run. To execute the
request, call moveToFirst()
. Even after the query execution,
the Cursor will remain empty.
sql | the SQL query. The SQL string must not be ; terminated |
---|---|
params | You may include ? in where clause in the query, which
will be replaced by the values from params . The
values will be bound as Strings. |
Cursor
object, which is positioned before the first entry.
Note that Cursors are not synchronized.
Executes a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
For INSERT, UPDATE and DELETE statements, use execSQL(String)
instead.
For example, the following are good candidates for using this method:
sql | the SQL statement to be executed. Multiple statements separated by semicolons are not supported |
---|---|
params | only String is supported |
Executes a single SQL statement that is NOT a SELECT or any other SQL statement that returns data. It has no means to return any data (such as the number of affected rows).
sql | the SQL statement to be executed. Multiple statements separated by semicolons are not supported. |
---|
Executes a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
For INSERT, UPDATE and DELETE statements, use execSQL(String)
instead.
For example, the following are good candidates for using this method:
sql | the SQL statement to be executed. Multiple statements separated by semicolons are not supported |
---|---|
params | only byte[], String, Long and Double are supported |
Checks if a Database exists.
databaseName | the name (unique) of the database |
---|
Returns the absolute path on the file system where the database with the given name is stored.
databaseName | name of the database for which you would like to get the path. |
---|
Returns the unique name (in the application) of the database.
Returns the version of the Database.
Opens a new private Database. Create the database file if it doesn't exist.
databaseName | the name (unique) of the database |
---|
Opens a new private Database using a helper object to create, open, and/or manage a database. Create the database file if it doesn't exist.
databaseName | the name (unique) of the database |
---|---|
version | the version of the database |
helper | a helper object to create, open, and/or manage a database |
Rollbacks (cancels) the current transaction.