Modifier and Type | Class and Description |
---|---|
static class |
DatabaseUtils.InsertHelper
Deprecated.
Use
SQLiteStatement instead. |
Modifier and Type | Field and Description |
---|---|
static int |
STATEMENT_ABORT
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_ATTACH
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_BEGIN
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_COMMIT
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_DDL
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_OTHER
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_PRAGMA
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_SELECT
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_UNPREPARED
One of the values returned by
getSqlStatementType(String) . |
static int |
STATEMENT_UPDATE
One of the values returned by
getSqlStatementType(String) . |
Constructor and Description |
---|
DatabaseUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
appendEscapedSQLString(StringBuilder sb,
String sqlString)
Appends an SQL string to the given StringBuilder, including the opening
and closing single quotes.
|
static String[] |
appendSelectionArgs(String[] originalValues,
String[] newValues)
Appends one set of selection args to another.
|
static void |
appendValueToSql(StringBuilder sql,
Object value)
Appends an Object to an SQL string with the proper escaping, etc.
|
static void |
bindObjectToProgram(SQLiteProgram prog,
int index,
Object value)
Binds the given Object to the given SQLiteProgram using the proper
typing.
|
static ParcelFileDescriptor |
blobFileDescriptorForQuery(SQLiteDatabase db,
String query,
String[] selectionArgs)
Utility method to run the query on the db and return the blob value in the
first column of the first row.
|
static ParcelFileDescriptor |
blobFileDescriptorForQuery(SQLiteStatement prog,
String[] selectionArgs)
Utility method to run the pre-compiled query and return the blob value in the
first column of the first row.
|
static String |
concatenateWhere(String a,
String b)
Concatenates two SQL WHERE clauses, handling empty or null values.
|
static void |
createDbFromSqlStatements(Context context,
String dbName,
int dbVersion,
String sqlStatements)
Creates a db and populates it with the sql statements in sqlStatements.
|
static void |
cursorDoubleToContentValues(Cursor cursor,
String field,
ContentValues values,
String key)
Reads a Double out of a field in a Cursor and writes it to a Map.
|
static void |
cursorDoubleToContentValuesIfPresent(Cursor cursor,
ContentValues values,
String column)
Reads a Double out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorDoubleToCursorValues(Cursor cursor,
String field,
ContentValues values)
Reads a Double out of a field in a Cursor and writes it to a Map.
|
static void |
cursorFillWindow(Cursor cursor,
int position,
CursorWindow window)
Fills the specified cursor window by iterating over the contents of the cursor.
|
static void |
cursorFloatToContentValuesIfPresent(Cursor cursor,
ContentValues values,
String column)
Reads a Float out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorIntToContentValues(Cursor cursor,
String field,
ContentValues values)
Reads an Integer out of a field in a Cursor and writes it to a Map.
|
static void |
cursorIntToContentValues(Cursor cursor,
String field,
ContentValues values,
String key)
Reads a Integer out of a field in a Cursor and writes it to a Map.
|
static void |
cursorIntToContentValuesIfPresent(Cursor cursor,
ContentValues values,
String column)
Reads a Integer out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorLongToContentValues(Cursor cursor,
String field,
ContentValues values)
Reads a Long out of a field in a Cursor and writes it to a Map.
|
static void |
cursorLongToContentValues(Cursor cursor,
String field,
ContentValues values,
String key)
Reads a Long out of a field in a Cursor and writes it to a Map.
|
static void |
cursorLongToContentValuesIfPresent(Cursor cursor,
ContentValues values,
String column)
Reads a Long out of a column in a Cursor and writes it to a ContentValues.
|
static int |
cursorPickFillWindowStartPosition(int cursorPosition,
int cursorWindowCapacity)
Picks a start position for
Cursor#fillWindow such that the
window will contain the requested row and a useful range of rows
around it. |
static void |
cursorRowToContentValues(Cursor cursor,
ContentValues values)
Read the entire contents of a cursor row and store them in a ContentValues.
|
static void |
cursorShortToContentValuesIfPresent(Cursor cursor,
ContentValues values,
String column)
Reads a Short out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorStringToContentValues(Cursor cursor,
String field,
ContentValues values)
Reads a String out of a field in a Cursor and writes it to a Map.
|
static void |
cursorStringToContentValues(Cursor cursor,
String field,
ContentValues values,
String key)
Reads a String out of a field in a Cursor and writes it to a Map.
|
static void |
cursorStringToContentValuesIfPresent(Cursor cursor,
ContentValues values,
String column)
Reads a String out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorStringToInsertHelper(Cursor cursor,
String field,
DatabaseUtils.InsertHelper inserter,
int index)
Reads a String out of a field in a Cursor and writes it to an InsertHelper.
|
static void |
dumpCurrentRow(Cursor cursor)
Prints the contents of a Cursor's current row to System.out.
|
static void |
dumpCurrentRow(Cursor cursor,
PrintStream stream)
Prints the contents of a Cursor's current row to a PrintSteam.
|
static void |
dumpCurrentRow(Cursor cursor,
StringBuilder sb)
Prints the contents of a Cursor's current row to a StringBuilder.
|
static String |
dumpCurrentRowToString(Cursor cursor)
Dump the contents of a Cursor's current row to a String.
|
static void |
dumpCursor(Cursor cursor)
Prints the contents of a Cursor to System.out.
|
static void |
dumpCursor(Cursor cursor,
PrintStream stream)
Prints the contents of a Cursor to a PrintSteam.
|
static void |
dumpCursor(Cursor cursor,
StringBuilder sb)
Prints the contents of a Cursor to a StringBuilder.
|
static String |
dumpCursorToString(Cursor cursor)
Prints the contents of a Cursor to a String.
|
static int |
findRowIdColumnIndex(String[] columnNames)
Returns column index of "_id" column, or -1 if not found.
|
static String |
getCollationKey(String name)
return the collation key
|
static String |
getHexCollationKey(String name)
return the collation key in hex format
|
static int |
getSqlStatementType(String sql)
Returns one of the following which represent the type of the given SQL statement.
|
static int |
getTypeOfObject(Object obj)
Returns data type of the given object's value.
|
static long |
longForQuery(SQLiteDatabase db,
String query,
String[] selectionArgs)
Utility method to run the query on the db and return the value in the
first column of the first row.
|
static long |
longForQuery(SQLiteStatement prog,
String[] selectionArgs)
Utility method to run the pre-compiled query and return the value in the
first column of the first row.
|
static long |
queryNumEntries(SQLiteDatabase db,
String table)
Query the table for the number of rows in the table.
|
static long |
queryNumEntries(SQLiteDatabase db,
String table,
String selection)
Query the table for the number of rows in the table.
|
static long |
queryNumEntries(SQLiteDatabase db,
String table,
String selection,
String[] selectionArgs)
Query the table for the number of rows in the table.
|
static void |
readExceptionFromParcel(Parcel reply)
Special function for reading an exception result from the header of
a parcel, to be used after receiving the result of a transaction.
|
static void |
readExceptionWithFileNotFoundExceptionFromParcel(Parcel reply) |
static void |
readExceptionWithOperationApplicationExceptionFromParcel(Parcel reply) |
static String |
sqlEscapeString(String value)
SQL-escape a string.
|
static String |
stringForQuery(SQLiteDatabase db,
String query,
String[] selectionArgs)
Utility method to run the query on the db and return the value in the
first column of the first row.
|
static String |
stringForQuery(SQLiteStatement prog,
String[] selectionArgs)
Utility method to run the pre-compiled query and return the value in the
first column of the first row.
|
static void |
writeExceptionToParcel(Parcel reply,
Exception e)
Special function for writing an exception result at the header of
a parcel, to be used when returning an exception from a transaction.
|
public static final int STATEMENT_SELECT
getSqlStatementType(String)
.public static final int STATEMENT_UPDATE
getSqlStatementType(String)
.public static final int STATEMENT_ATTACH
getSqlStatementType(String)
.public static final int STATEMENT_BEGIN
getSqlStatementType(String)
.public static final int STATEMENT_COMMIT
getSqlStatementType(String)
.public static final int STATEMENT_ABORT
getSqlStatementType(String)
.public static final int STATEMENT_PRAGMA
getSqlStatementType(String)
.public static final int STATEMENT_DDL
getSqlStatementType(String)
.public static final int STATEMENT_UNPREPARED
getSqlStatementType(String)
.public static final int STATEMENT_OTHER
getSqlStatementType(String)
.public static final void writeExceptionToParcel(Parcel reply, Exception e)
reply
- Parcel to write toe
- The Exception to be written.Parcel.writeNoException()
,
Parcel.writeException(java.lang.Exception)
public static final void readExceptionFromParcel(Parcel reply)
reply
- Parcel to read fromParcel.writeNoException()
,
Parcel.readException()
public static void readExceptionWithFileNotFoundExceptionFromParcel(Parcel reply) throws FileNotFoundException
FileNotFoundException
public static void readExceptionWithOperationApplicationExceptionFromParcel(Parcel reply) throws OperationApplicationException
OperationApplicationException
public static void bindObjectToProgram(SQLiteProgram prog, int index, Object value)
prog
- the program to bind the object toindex
- the 1-based index to bind atvalue
- the value to bindpublic static int getTypeOfObject(Object obj)
Returned values are
obj
- the object whose value type is to be returnedpublic static void cursorFillWindow(Cursor cursor, int position, CursorWindow window)
cursor
- The cursor that contains the data to put in the window.position
- The start position for filling the window.window
- The window to fill.public static void appendEscapedSQLString(StringBuilder sb, String sqlString)
sb
- the StringBuilder that the SQL string will be appended tosqlString
- the raw string to be appended, which may contain single
quotespublic static final void appendValueToSql(StringBuilder sql, Object value)
public static String concatenateWhere(String a, String b)
public static String getCollationKey(String name)
name
- public static String getHexCollationKey(String name)
name
- public static void dumpCursor(Cursor cursor)
cursor
- the cursor to printpublic static void dumpCursor(Cursor cursor, PrintStream stream)
cursor
- the cursor to printstream
- the stream to print topublic static void dumpCursor(Cursor cursor, StringBuilder sb)
cursor
- the cursor to printsb
- the StringBuilder to print topublic static String dumpCursorToString(Cursor cursor)
cursor
- the cursor to printpublic static void dumpCurrentRow(Cursor cursor)
cursor
- the cursor to print frompublic static void dumpCurrentRow(Cursor cursor, PrintStream stream)
cursor
- the cursor to printstream
- the stream to print topublic static void dumpCurrentRow(Cursor cursor, StringBuilder sb)
cursor
- the cursor to printsb
- the StringBuilder to print topublic static String dumpCurrentRowToString(Cursor cursor)
cursor
- the cursor to printpublic static void cursorStringToContentValues(Cursor cursor, String field, ContentValues values)
cursor
- The cursor to read fromfield
- The TEXT field to readvalues
- The ContentValues
to put the value into, with the field as the keypublic static void cursorStringToInsertHelper(Cursor cursor, String field, DatabaseUtils.InsertHelper inserter, int index)
cursor
- The cursor to read fromfield
- The TEXT field to readinserter
- The InsertHelper to bind intoindex
- the index of the bind entry in the InsertHelperpublic static void cursorStringToContentValues(Cursor cursor, String field, ContentValues values, String key)
cursor
- The cursor to read fromfield
- The TEXT field to readvalues
- The ContentValues
to put the value into, with the field as the keykey
- The key to store the value with in the mappublic static void cursorIntToContentValues(Cursor cursor, String field, ContentValues values)
cursor
- The cursor to read fromfield
- The INTEGER field to readvalues
- The ContentValues
to put the value into, with the field as the keypublic static void cursorIntToContentValues(Cursor cursor, String field, ContentValues values, String key)
cursor
- The cursor to read fromfield
- The INTEGER field to readvalues
- The ContentValues
to put the value into, with the field as the keykey
- The key to store the value with in the mappublic static void cursorLongToContentValues(Cursor cursor, String field, ContentValues values)
cursor
- The cursor to read fromfield
- The INTEGER field to readvalues
- The ContentValues
to put the value into, with the field as the keypublic static void cursorLongToContentValues(Cursor cursor, String field, ContentValues values, String key)
cursor
- The cursor to read fromfield
- The INTEGER field to readvalues
- The ContentValues
to put the value intokey
- The key to store the value with in the mappublic static void cursorDoubleToCursorValues(Cursor cursor, String field, ContentValues values)
cursor
- The cursor to read fromfield
- The REAL field to readvalues
- The ContentValues
to put the value intopublic static void cursorDoubleToContentValues(Cursor cursor, String field, ContentValues values, String key)
cursor
- The cursor to read fromfield
- The REAL field to readvalues
- The ContentValues
to put the value intokey
- The key to store the value with in the mappublic static void cursorRowToContentValues(Cursor cursor, ContentValues values)
cursor
- the cursor to read from.values
- the ContentValues
to put the row into.public static int cursorPickFillWindowStartPosition(int cursorPosition, int cursorWindowCapacity)
Cursor#fillWindow
such that the
window will contain the requested row and a useful range of rows
around it.
When the data set is too large to fit in a cursor window, seeking the
cursor can become a very expensive operation since we have to run the
query again when we move outside the bounds of the current window.
We try to choose a start position for the cursor window such that
1/3 of the window's capacity is used to hold rows before the requested
position and 2/3 of the window's capacity is used to hold rows after the
requested position.cursorPosition
- The row index of the row we want to get.cursorWindowCapacity
- The estimated number of rows that can fit in
a cursor window, or 0 if unknown.public static long queryNumEntries(SQLiteDatabase db, String table)
db
- the database the table is intable
- the name of the table to querypublic static long queryNumEntries(SQLiteDatabase db, String table, String selection)
db
- the database the table is intable
- the name of the table to queryselection
- A filter declaring which rows to return,
formatted as an SQL WHERE clause (excluding the WHERE itself).
Passing null will count all rows for the given tablepublic static long queryNumEntries(SQLiteDatabase db, String table, String selection, String[] selectionArgs)
db
- the database the table is intable
- the name of the table to queryselection
- A filter declaring which rows to return,
formatted as an SQL WHERE clause (excluding the WHERE itself).
Passing null will count all rows for the given tableselectionArgs
- You may include ?s in selection,
which will be replaced by the values from selectionArgs,
in order that they appear in the selection.
The values will be bound as Strings.public static long longForQuery(SQLiteDatabase db, String query, String[] selectionArgs)
public static long longForQuery(SQLiteStatement prog, String[] selectionArgs)
public static String stringForQuery(SQLiteDatabase db, String query, String[] selectionArgs)
public static String stringForQuery(SQLiteStatement prog, String[] selectionArgs)
public static ParcelFileDescriptor blobFileDescriptorForQuery(SQLiteDatabase db, String query, String[] selectionArgs)
public static ParcelFileDescriptor blobFileDescriptorForQuery(SQLiteStatement prog, String[] selectionArgs)
public static void cursorStringToContentValuesIfPresent(Cursor cursor, ContentValues values, String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void cursorLongToContentValuesIfPresent(Cursor cursor, ContentValues values, String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void cursorShortToContentValuesIfPresent(Cursor cursor, ContentValues values, String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void cursorIntToContentValuesIfPresent(Cursor cursor, ContentValues values, String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void cursorFloatToContentValuesIfPresent(Cursor cursor, ContentValues values, String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void cursorDoubleToContentValuesIfPresent(Cursor cursor, ContentValues values, String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void createDbFromSqlStatements(Context context, String dbName, int dbVersion, String sqlStatements)
context
- the context to use to create the dbdbName
- the name of the db to createdbVersion
- the version to set on the dbsqlStatements
- the statements to use to populate the db. This should be a single string
of the form returned by sqlite3's .dump command (statements separated by
semicolons)public static int getSqlStatementType(String sql)
sql
- the SQL statement whose type is returned by this methodpublic static String[] appendSelectionArgs(String[] originalValues, String[] newValues)
public static int findRowIdColumnIndex(String[] columnNames)