public class SQLiteWrapper extends SQLDatabase
CONFLICT_ABORT, CONFLICT_FAIL, CONFLICT_IGNORE, CONFLICT_NONE, CONFLICT_REPLACE, CONFLICT_ROLLBACK, filename
Constructor and Description |
---|
SQLiteWrapper(java.lang.String databaseFilePath) |
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");
|
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.
|
java.lang.String |
getDatabaseFile() |
int |
getVersion()
Gets the database version, and SQLDatabase's version is defined as:
|
long |
insert(java.lang.String table,
ContentValues initialValues)
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
|
static SQLiteWrapper |
openSQLiteWrapper(java.lang.String databaseFilePath) |
SQLiteCursor |
rawQuery(java.lang.String sql,
java.lang.String[] bindArgs)
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 values,
java.lang.String whereClause,
java.lang.String[] whereArgs)
Convenience method for updating rows in the database.
|
public static SQLiteWrapper openSQLiteWrapper(java.lang.String databaseFilePath)
public java.lang.String getDatabaseFile()
public void open()
SQLDatabase
open
in class SQLDatabase
public void compactDatabase()
SQLDatabase
compactDatabase
in class SQLDatabase
public int getVersion()
SQLDatabase
Gets the database version, and SQLDatabase's version is defined as:
PRAGMA user_version;
getVersion
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 close()
SQLDatabase
close
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 update(java.lang.String table, ContentValues values, java.lang.String whereClause, java.lang.String[] whereArgs)
SQLDatabase
update
in class SQLDatabase
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 SQLiteCursor rawQuery(java.lang.String sql, java.lang.String[] bindArgs) throws java.sql.SQLException
SQLDatabase
Cursor
over the result set.rawQuery
in class SQLDatabase
sql
- the SQL query. The SQL string must not be ; terminatedbindArgs
- 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 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 insertWithOnConflict(java.lang.String table, ContentValues initialValues, int conflictAlgorithm)
insertWithOnConflict
in class SQLDatabase
public long insert(java.lang.String table, ContentValues initialValues)
SQLDatabase
insert
in class SQLDatabase
table
- the table to insert the row intoinitialValues
- this map contains the initial column values for the
row. The keys should be the column names and the values the
column values