public class DatabaseUtils
extends java.lang.Object
Cursors.| 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(java.lang.StringBuilder sb,
java.lang.String sqlString)
Appends an SQL string to the given StringBuilder, including the opening
and closing single quotes.
|
static java.lang.String[] |
appendSelectionArgs(java.lang.String[] originalValues,
java.lang.String[] newValues)
Appends one set of selection args to another.
|
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 |
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 |
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 |
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 |
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 |
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 |
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 int |
findRowIdColumnIndex(java.lang.String[] columnNames)
Returns column index of "_id" column, or -1 if not found.
|
static int |
getSqlStatementType(java.lang.String sql)
Returns one of the following which represent the type of the given SQL statement.
|
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 boolean |
queryIsEmpty(SQLiteDatabase db,
java.lang.String table)
Query the table to check whether a table is empty or not
|
static long |
queryNumEntries(SQLiteDatabase db,
java.lang.String table)
Query the table for the number of rows in the table.
|
static long |
queryNumEntries(SQLiteDatabase db,
java.lang.String table,
java.lang.String selection)
Query the table for the number of rows in the table.
|
static long |
queryNumEntries(SQLiteDatabase db,
java.lang.String table,
java.lang.String selection,
java.lang.String[] selectionArgs)
Query the table for the number of rows in the table.
|
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.
|
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 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 long queryNumEntries(SQLiteDatabase db, java.lang.String table)
db - the database the table is intable - the name of the table to querypublic static long queryNumEntries(SQLiteDatabase db, java.lang.String table, java.lang.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, java.lang.String table, java.lang.String selection, java.lang.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 boolean queryIsEmpty(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 int getSqlStatementType(java.lang.String sql)
sql - the SQL statement whose type is returned by this methodpublic static java.lang.String[] appendSelectionArgs(java.lang.String[] originalValues,
java.lang.String[] newValues)
public static int findRowIdColumnIndex(java.lang.String[] columnNames)