|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.database.DatabaseUtils
public class DatabaseUtils
Static utility methods for dealing with databases and Cursors.
| Nested Class Summary | |
|---|---|
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 Summary | |
|---|---|
DatabaseUtils()
|
|
| Method Summary | |
|---|---|
static void |
appendEscapedSQLString(StringBuilder sb,
String sqlString)
Appends an SQL string to the given StringBuilder, including the opening and closing single quotes. |
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 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 |
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 |
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 |
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 |
cursorRowToContentValues(Cursor cursor,
ContentValues values)
Read the entire contents of a cursor row and store them in 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 |
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 String |
getCollationKey(String name)
return the collation key |
static String |
getHexCollationKey(String name)
return the collation key in hex format |
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 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 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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DatabaseUtils()
| Method Detail |
|---|
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 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 bind
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 String sqlEscapeString(String value)
public static final void appendValueToSql(StringBuilder sql,
Object value)
public static String getCollationKey(String name)
name -
public static String getHexCollationKey(String name)
name -
public static void dumpCursor(Cursor cursor)
cursor - the cursor to print
public static void dumpCursor(Cursor cursor,
PrintStream stream)
cursor - the cursor to printstream - the stream to print to
public 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 print
public static void dumpCurrentRow(Cursor cursor)
cursor - the cursor to print from
public static void dumpCurrentRow(Cursor cursor,
PrintStream stream)
cursor - the cursor to printstream - the stream to print to
public 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 print
public 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 key
public 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 InsertHelper
public 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 map
public 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 key
public 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 map
public 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 key
public 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 map
public 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 into
public 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 map
public 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,
String table)
db - the database the table is intable - the name of the table to query
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 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)
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||