public class DatabaseUtils
extends java.lang.Object
Cursor
s.Modifier and Type | Class and Description |
---|---|
static class |
DatabaseUtils.InsertHelper
This class allows users to do multiple inserts into a table but
compile the SQL insert statement only once, which may increase
performance.
|
Constructor and Description |
---|
DatabaseUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
appendEscapedSQLString(java.lang.StringBuilder sb,
java.lang.String sqlString)
Appends an SQL string to the given StringBuilder, including the opening
and closing single quotes.
|
static void |
appendValueToSql(java.lang.StringBuilder sql,
java.lang.Object value)
Appends an Object to an SQL string with the proper escaping, etc.
|
static void |
bindObjectToProgram(SQLiteProgram prog,
int index,
java.lang.Object value)
Binds the given Object to the given SQLiteProgram using the proper
typing.
|
static java.lang.String |
concatenateWhere(java.lang.String a,
java.lang.String b)
Concatenates two SQL WHERE clauses, handling empty or null values.
|
static void |
cursorDoubleToContentValues(Cursor cursor,
java.lang.String field,
ContentValues values,
java.lang.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,
java.lang.String column)
Reads a Double out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorDoubleToCursorValues(Cursor cursor,
java.lang.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,
android.database.CursorWindow window) |
static void |
cursorFloatToContentValuesIfPresent(Cursor cursor,
ContentValues values,
java.lang.String column)
Reads a Float out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorIntToContentValues(Cursor cursor,
java.lang.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,
java.lang.String field,
ContentValues values,
java.lang.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,
java.lang.String column)
Reads a Integer out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorLongToContentValues(Cursor cursor,
java.lang.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,
java.lang.String field,
ContentValues values,
java.lang.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,
java.lang.String column)
Reads a Long out of a column in a Cursor and writes it to a ContentValues.
|
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,
java.lang.String column)
Reads a Short out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorStringToContentValues(Cursor cursor,
java.lang.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,
java.lang.String field,
ContentValues values,
java.lang.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,
java.lang.String column)
Reads a String out of a column in a Cursor and writes it to a ContentValues.
|
static void |
cursorStringToInsertHelper(Cursor cursor,
java.lang.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,
java.io.PrintStream stream)
Prints the contents of a Cursor's current row to a PrintSteam.
|
static void |
dumpCurrentRow(Cursor cursor,
java.lang.StringBuilder sb)
Prints the contents of a Cursor's current row to a StringBuilder.
|
static java.lang.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,
java.io.PrintStream stream)
Prints the contents of a Cursor to a PrintSteam.
|
static void |
dumpCursor(Cursor cursor,
java.lang.StringBuilder sb)
Prints the contents of a Cursor to a StringBuilder.
|
static java.lang.String |
dumpCursorToString(Cursor cursor)
Prints the contents of a Cursor to a String.
|
static java.lang.String |
getCollationKey(java.lang.String name)
return the collation key
|
static java.lang.String |
getHexCollationKey(java.lang.String name)
return the collation key in hex format
|
static int |
getTypeOfObject(java.lang.Object obj)
Returns data type of the given object's value.
|
static long |
longForQuery(SQLiteDatabase db,
java.lang.String query,
java.lang.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,
java.lang.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,
java.lang.String table)
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 java.lang.String |
sqlEscapeString(java.lang.String value)
SQL-escape a string.
|
static java.lang.String |
stringForQuery(SQLiteDatabase db,
java.lang.String query,
java.lang.String[] selectionArgs)
Utility method to run the query on the db and return the value in the
first column of the first row.
|
static java.lang.String |
stringForQuery(SQLiteStatement prog,
java.lang.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,
java.lang.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 void writeExceptionToParcel(Parcel reply, java.lang.Exception e)
reply
- Parcel to write toe
- The Exception to be written.Parcel#writeNoException
,
Parcel#writeException
public static final void readExceptionFromParcel(Parcel reply)
reply
- Parcel to read fromParcel#writeNoException
,
Parcel#readException
public static void readExceptionWithFileNotFoundExceptionFromParcel(Parcel reply) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static void readExceptionWithOperationApplicationExceptionFromParcel(Parcel reply) throws OperationApplicationException
OperationApplicationException
public static void bindObjectToProgram(SQLiteProgram prog, int index, java.lang.Object value)
prog
- the program to bind the object toindex
- the 1-based index to bind atvalue
- the value to bindpublic static int getTypeOfObject(java.lang.Object obj)
Returned values are
obj
- the object whose value type is to be returnedpublic static void appendEscapedSQLString(java.lang.StringBuilder sb, java.lang.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 java.lang.String sqlEscapeString(java.lang.String value)
public static final void appendValueToSql(java.lang.StringBuilder sql, java.lang.Object value)
public static java.lang.String concatenateWhere(java.lang.String a, java.lang.String b)
public static java.lang.String getCollationKey(java.lang.String name)
name
- public static java.lang.String getHexCollationKey(java.lang.String name)
name
- public static void dumpCursor(Cursor cursor)
cursor
- the cursor to printpublic static void dumpCursor(Cursor cursor, java.io.PrintStream stream)
cursor
- the cursor to printstream
- the stream to print topublic static void dumpCursor(Cursor cursor, java.lang.StringBuilder sb)
cursor
- the cursor to printsb
- the StringBuilder to print topublic static java.lang.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, java.io.PrintStream stream)
cursor
- the cursor to printstream
- the stream to print topublic static void dumpCurrentRow(Cursor cursor, java.lang.StringBuilder sb)
cursor
- the cursor to printsb
- the StringBuilder to print topublic static java.lang.String dumpCurrentRowToString(Cursor cursor)
cursor
- the cursor to printpublic static void cursorStringToContentValues(Cursor cursor, java.lang.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, java.lang.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, java.lang.String field, ContentValues values, java.lang.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, java.lang.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, java.lang.String field, ContentValues values, java.lang.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, java.lang.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, java.lang.String field, ContentValues values, java.lang.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, java.lang.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, java.lang.String field, ContentValues values, java.lang.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 long queryNumEntries(SQLiteDatabase db, java.lang.String table)
db
- the database the table is intable
- the name of the table to querypublic static long longForQuery(SQLiteDatabase db, java.lang.String query, java.lang.String[] selectionArgs)
public static long longForQuery(SQLiteStatement prog, java.lang.String[] selectionArgs)
public static java.lang.String stringForQuery(SQLiteDatabase db, java.lang.String query, java.lang.String[] selectionArgs)
public static java.lang.String stringForQuery(SQLiteStatement prog, java.lang.String[] selectionArgs)
public static void cursorStringToContentValuesIfPresent(Cursor cursor, ContentValues values, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.String column)
cursor
- The cursor to read fromcolumn
- The column to readvalues
- The ContentValues
to put the value intopublic static void cursorFillWindow(Cursor cursor, int position, android.database.CursorWindow window)