public abstract class SQLDatabase
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
CONFLICT_ABORT
When a constraint violation occurs,no ROLLBACK is executed
so changes from prior commands within the same transaction
are preserved.
|
static int |
CONFLICT_FAIL
When a constraint violation occurs, the command aborts with a return
code SQLITE_CONSTRAINT.
|
static int |
CONFLICT_IGNORE
When a constraint violation occurs, the one row that contains
the constraint violation is not inserted or changed.
|
static int |
CONFLICT_NONE
Use the following when no conflict action is specified.
|
static int |
CONFLICT_REPLACE
When a UNIQUE constraint violation occurs, the pre-existing rows that
are causing the constraint violation are removed prior to inserting
or updating the current row.
|
static int |
CONFLICT_ROLLBACK
When a constraint violation occurs, an immediate ROLLBACK occurs,
thus ending the current transaction, and the command aborts with a
return code of SQLITE_CONSTRAINT.
|
java.lang.String |
filename |
Constructor and Description |
---|
SQLDatabase() |
Modifier and Type | Method and Description |
---|---|
abstract void |
beginTransaction()
Begins a transaction in EXCLUSIVE mode.
|
abstract void |
close()
Close the database
|
abstract void |
compactDatabase()
For SQLite database, this is to call:
this.execSQL("VACUUM");
|
abstract int |
delete(java.lang.String table,
java.lang.String whereClause,
java.lang.String[] whereArgs)
Convenience method for deleting rows in the database.
|
abstract void |
endTransaction()
End a transaction.
|
abstract void |
execSQL(java.lang.String sql)
Execute a single SQL statement that is NOT a SELECT
or any other SQL statement that returns data.
|
abstract void |
execSQL(java.lang.String sql,
java.lang.Object[] bindArgs)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
|
abstract int |
getVersion()
Gets the database version, and SQLDatabase's version is defined as:
|
abstract long |
insert(java.lang.String table,
ContentValues values)
Convenience method for inserting a row into the database.
|
abstract long |
insertWithOnConflict(java.lang.String table,
ContentValues initialValues,
int conflictAlgorithm) |
abstract boolean |
isOpen() |
abstract void |
open()
Open the database
|
abstract Cursor |
rawQuery(java.lang.String sql,
java.lang.String[] selectionArgs)
Runs the provided SQL and returns a
Cursor over the result set. |
abstract void |
setTransactionSuccessful()
Marks the current transaction as successful.
|
abstract int |
update(java.lang.String table,
ContentValues values,
java.lang.String whereClause,
java.lang.String[] whereArgs)
Convenience method for updating rows in the database.
|
public java.lang.String filename
public static final int CONFLICT_ROLLBACK
public static final int CONFLICT_ABORT
public static final int CONFLICT_FAIL
public static final int CONFLICT_IGNORE
public static final int CONFLICT_REPLACE
public static final int CONFLICT_NONE
public abstract void execSQL(java.lang.String sql, java.lang.Object[] bindArgs) throws java.sql.SQLException
sql
- the SQL statement to be executed. Multiple statements separated by semicolons are
not supported.bindArgs
- only byte[], String, Long and Double are supported in bindArgs.java.sql.SQLException
- if the SQL string is invalidpublic abstract void execSQL(java.lang.String sql) throws java.sql.SQLException
sql
- the SQL statement to be executed. Multiple statements separated by semicolons are
not supported.java.sql.SQLException
- if the SQL string is invalidpublic abstract void compactDatabase()
public abstract int getVersion()
Gets the database version, and SQLDatabase's version is defined as:
PRAGMA user_version;
public abstract void open()
public abstract void close()
public abstract boolean isOpen()
public abstract void beginTransaction()
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(); }
public abstract void endTransaction()
public abstract void setTransactionSuccessful()
java.lang.IllegalStateException
- if the current thread is not in a transaction or the
transaction is already marked as successful.public abstract int update(java.lang.String table, ContentValues values, java.lang.String whereClause, java.lang.String[] whereArgs)
table
- the table to update invalues
- a map from column names to new column values. null is a
valid value that will be translated to NULL.whereClause
- the optional WHERE clause to apply when updating.
Passing null will update all rows.public abstract Cursor rawQuery(java.lang.String sql, java.lang.String[] selectionArgs) throws java.sql.SQLException
Cursor
over the result set.sql
- the SQL query. The SQL string must not be ; terminatedselectionArgs
- You may include ?s in where clause in the query,
which will be replaced by the values from selectionArgs. The
values will be bound as Strings.Cursor
object, which is positioned before the first entry. Note that
Cursor
s are not synchronized, see the documentation for more details.java.sql.SQLException
public abstract int delete(java.lang.String table, java.lang.String whereClause, java.lang.String[] whereArgs)
table
- the table to delete fromwhereClause
- the optional WHERE clause to apply when deleting.
Passing null will delete all rows. And, do not include
"where" in the clause.public abstract long insert(java.lang.String table, ContentValues values)
table
- the table to insert the row intovalues
- this map contains the initial column values for the
row. The keys should be the column names and the values the
column valuespublic abstract long insertWithOnConflict(java.lang.String table, ContentValues initialValues, int conflictAlgorithm)
table
- initialValues
- conflictAlgorithm
-