public class DBHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXPLAIN_ARGS |
static java.lang.String |
EXPLAIN_ROWS |
static java.lang.String |
EXPLAIN_SQL |
static java.lang.String |
EXPLAIN_TAG |
Constructor and Description |
---|
DBHelper() |
Modifier and Type | Method and Description |
---|---|
void |
cacheHasSoup(java.lang.String soupName,
boolean hasSoup) |
void |
cacheIndexSpecs(java.lang.String soupName,
IndexSpec[] indexSpecs) |
void |
cacheTableName(java.lang.String soupName,
java.lang.String tableName) |
void |
clearMemoryCache()
Resets all cached data from memory.
|
Cursor |
countQuery(SQLiteDatabase db,
java.lang.String table,
java.lang.String whereClause,
java.lang.String... whereArgs)
Does a count query
|
int |
countRawCountQuery(SQLiteDatabase db,
java.lang.String countSql,
java.lang.String... whereArgs)
Does a count for a raw count query
|
int |
countRawQuery(SQLiteDatabase db,
java.lang.String sql,
java.lang.String... whereArgs)
Does a count for a raw query
|
void |
delete(SQLiteDatabase db,
java.lang.String table,
java.lang.String whereClause,
java.lang.String... whereArgs)
Does a delete (after first logging the delete statement)
|
java.lang.Boolean |
getCachedHasFTS(java.lang.String soupName) |
IndexSpec[] |
getCachedIndexSpecs(java.lang.String soupName) |
java.lang.String |
getCachedTableName(java.lang.String soupName) |
java.lang.String |
getColumnNameForPath(SQLiteDatabase db,
java.lang.String soupName,
java.lang.String path)
Return column name in soup table that holds the soup projection for path
|
IndexSpec[] |
getIndexSpecs(SQLiteDatabase db,
java.lang.String soupName)
Read index specs back from the soup index map table
|
protected IndexSpec[] |
getIndexSpecsFromDb(SQLiteDatabase db,
java.lang.String soupName) |
InsertHelper |
getInsertHelper(SQLiteDatabase db,
java.lang.String table)
Get insert helper for a table
|
static DBHelper |
getInstance(SQLiteDatabase db)
Returns the instance of this class associated with the database specified.
|
JSONObject |
getLastExplainQueryPlan() |
long |
getNextId(SQLiteDatabase db,
java.lang.String tableName)
Get next id for a table
|
java.lang.String |
getSoupTableName(SQLiteDatabase db,
java.lang.String soupName)
Return table name for a given soup or null if the soup doesn't exist
|
protected java.lang.String |
getSoupTableNameFromDb(SQLiteDatabase db,
java.lang.String soupName) |
boolean |
hasFTS(SQLiteDatabase db,
java.lang.String soupName) |
boolean |
hasIndexForPath(SQLiteDatabase db,
java.lang.String soupName,
java.lang.String path)
Return true if the given path is indexed on the given soup
|
boolean |
hasSoup(SQLiteDatabase db,
java.lang.String soupName)
Return true if given soup exists
|
long |
insert(SQLiteDatabase db,
java.lang.String table,
ContentValues contentValues)
Does an insert
|
Cursor |
limitRawQuery(SQLiteDatabase db,
java.lang.String sql,
java.lang.String limit,
java.lang.String... whereArgs)
Does a limit for a raw query
|
Cursor |
query(SQLiteDatabase db,
java.lang.String table,
java.lang.String[] columns,
java.lang.String orderBy,
java.lang.String limit,
java.lang.String whereClause,
java.lang.String... whereArgs)
Runs a query
|
void |
removeFromCache(java.lang.String soupName) |
void |
reset(Context ctx)
Resets all cached data and deletes the database for all users.
|
void |
reset(Context ctx,
UserAccount account)
Resets all cached data and deletes the database for the specified user.
|
protected void |
safeClose(Cursor cursor) |
void |
setCaptureExplainQueryPlan(boolean captureExplainQueryPlan)
If turned on, explain query plan is run before executing a query and stored in lastExplainQueryPlan
and also get logged
|
int |
update(SQLiteDatabase db,
java.lang.String table,
ContentValues contentValues,
java.lang.String whereClause,
java.lang.String... whereArgs)
Does an update
|
public static final java.lang.String EXPLAIN_SQL
public static final java.lang.String EXPLAIN_ARGS
public static final java.lang.String EXPLAIN_ROWS
public static final java.lang.String EXPLAIN_TAG
public static DBHelper getInstance(SQLiteDatabase db)
db
- Database.public void cacheTableName(java.lang.String soupName, java.lang.String tableName)
soupName
- tableName
- public void cacheHasSoup(java.lang.String soupName, boolean hasSoup)
soupName
- hasSoup
- public java.lang.String getCachedTableName(java.lang.String soupName)
soupName
- public void cacheIndexSpecs(java.lang.String soupName, IndexSpec[] indexSpecs)
soupName
- indexSpecs
- public IndexSpec[] getCachedIndexSpecs(java.lang.String soupName)
soupName
- public java.lang.Boolean getCachedHasFTS(java.lang.String soupName)
soupName
- public void removeFromCache(java.lang.String soupName)
soupName
- public long getNextId(SQLiteDatabase db, java.lang.String tableName)
db
- tableName
- public InsertHelper getInsertHelper(SQLiteDatabase db, java.lang.String table)
table
- public Cursor countQuery(SQLiteDatabase db, java.lang.String table, java.lang.String whereClause, java.lang.String... whereArgs)
db
- table
- whereClause
- whereArgs
- public Cursor limitRawQuery(SQLiteDatabase db, java.lang.String sql, java.lang.String limit, java.lang.String... whereArgs)
db
- sql
- limit
- whereArgs
- public int countRawCountQuery(SQLiteDatabase db, java.lang.String countSql, java.lang.String... whereArgs)
db
- countSql
- whereArgs
- public int countRawQuery(SQLiteDatabase db, java.lang.String sql, java.lang.String... whereArgs)
db
- sql
- whereArgs
- public Cursor query(SQLiteDatabase db, java.lang.String table, java.lang.String[] columns, java.lang.String orderBy, java.lang.String limit, java.lang.String whereClause, java.lang.String... whereArgs)
db
- table
- columns
- orderBy
- limit
- whereClause
- whereArgs
- public long insert(SQLiteDatabase db, java.lang.String table, ContentValues contentValues)
db
- table
- contentValues
- public int update(SQLiteDatabase db, java.lang.String table, ContentValues contentValues, java.lang.String whereClause, java.lang.String... whereArgs)
db
- table
- contentValues
- whereClause
- whereArgs
- public void delete(SQLiteDatabase db, java.lang.String table, java.lang.String whereClause, java.lang.String... whereArgs)
db
- table
- whereClause
- whereArgs
- public void reset(Context ctx)
ctx
- Context.public void reset(Context ctx, UserAccount account)
ctx
- Context.account
- User account.public void clearMemoryCache()
public java.lang.String getColumnNameForPath(SQLiteDatabase db, java.lang.String soupName, java.lang.String path)
db
- soupName
- path
- public boolean hasIndexForPath(SQLiteDatabase db, java.lang.String soupName, java.lang.String path)
db
- soupName
- path
- public IndexSpec[] getIndexSpecs(SQLiteDatabase db, java.lang.String soupName)
db
- soupName
- protected IndexSpec[] getIndexSpecsFromDb(SQLiteDatabase db, java.lang.String soupName)
public boolean hasFTS(SQLiteDatabase db, java.lang.String soupName)
db
- soupName
- public java.lang.String getSoupTableName(SQLiteDatabase db, java.lang.String soupName)
db
- soupName
- public boolean hasSoup(SQLiteDatabase db, java.lang.String soupName)
db
- soupName
- public void setCaptureExplainQueryPlan(boolean captureExplainQueryPlan)
captureExplainQueryPlan
- true to turn capture on and false to turn offpublic JSONObject getLastExplainQueryPlan()
protected java.lang.String getSoupTableNameFromDb(SQLiteDatabase db, java.lang.String soupName)
protected void safeClose(Cursor cursor)
cursor
-