public class AndroidSQLite extends SQLDatabase
CONFLICT_ABORT, CONFLICT_FAIL, CONFLICT_IGNORE, CONFLICT_NONE, CONFLICT_REPLACE, CONFLICT_ROLLBACK, filename
Constructor and Description |
---|
AndroidSQLite(android.database.sqlite.SQLiteDatabase database) |
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction()
Begins a transaction in EXCLUSIVE mode.
|
void |
close()
Close the database
|
void |
compactDatabase()
For SQLite database, this is to call:
this.execSQL("VACUUM");
|
static AndroidSQLite |
createAndroidSQLite(java.lang.String path) |
int |
delete(java.lang.String table,
java.lang.String whereClause,
java.lang.String[] whereArgs)
Convenience method for deleting rows in the database.
|
void |
endTransaction()
End a transaction.
|
void |
execSQL(java.lang.String sql)
Execute a single SQL statement that is NOT a SELECT
or any other SQL statement that returns data.
|
void |
execSQL(java.lang.String sql,
java.lang.Object[] bindArgs)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
|
int |
getVersion()
Gets the database version, and SQLDatabase's version is defined as:
|
long |
insert(java.lang.String table,
ContentValues args)
Convenience method for inserting a row into the database.
|
long |
insertWithOnConflict(java.lang.String table,
ContentValues initialValues,
int conflictAlgorithm) |
boolean |
isOpen() |
void |
open()
Open the database
|
Cursor |
rawQuery(java.lang.String sql,
java.lang.String[] values)
Runs the provided SQL and returns a
Cursor over the result set. |
void |
setTransactionSuccessful()
Marks the current transaction as successful.
|
int |
update(java.lang.String table,
ContentValues args,
java.lang.String whereClause,
java.lang.String[] whereArgs)
Convenience method for updating rows in the database.
|
public AndroidSQLite(android.database.sqlite.SQLiteDatabase database)
public static AndroidSQLite createAndroidSQLite(java.lang.String path)
public void compactDatabase()
SQLDatabase
compactDatabase
in class SQLDatabase
public void open()
SQLDatabase
open
in class SQLDatabase
public void close()
SQLDatabase
close
in class SQLDatabase
public boolean isOpen()
isOpen
in class SQLDatabase
public void beginTransaction()
SQLDatabase
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(); }
beginTransaction
in class SQLDatabase
public void endTransaction()
SQLDatabase
endTransaction
in class SQLDatabase
public void setTransactionSuccessful()
SQLDatabase
setTransactionSuccessful
in class SQLDatabase
public void execSQL(java.lang.String sql) throws java.sql.SQLException
SQLDatabase
execSQL
in class SQLDatabase
sql
- the SQL statement to be executed. Multiple statements separated by semicolons are
not supported.java.sql.SQLException
- if the SQL string is invalidpublic void execSQL(java.lang.String sql, java.lang.Object[] bindArgs) throws java.sql.SQLException
SQLDatabase
execSQL
in class SQLDatabase
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 int getVersion()
SQLDatabase
Gets the database version, and SQLDatabase's version is defined as:
PRAGMA user_version;
getVersion
in class SQLDatabase
public int update(java.lang.String table, ContentValues args, java.lang.String whereClause, java.lang.String[] whereArgs)
SQLDatabase
update
in class SQLDatabase
table
- the table to update inargs
- 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 Cursor rawQuery(java.lang.String sql, java.lang.String[] values)
SQLDatabase
Cursor
over the result set.rawQuery
in class SQLDatabase
sql
- the SQL query. The SQL string must not be ; terminatedvalues
- 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.public int delete(java.lang.String table, java.lang.String whereClause, java.lang.String[] whereArgs)
SQLDatabase
delete
in class SQLDatabase
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 long insert(java.lang.String table, ContentValues args)
SQLDatabase
insert
in class SQLDatabase
table
- the table to insert the row intoargs
- this map contains the initial column values for the
row. The keys should be the column names and the values the
column valuespublic long insertWithOnConflict(java.lang.String table, ContentValues initialValues, int conflictAlgorithm)
insertWithOnConflict
in class SQLDatabase