java.lang.Object | |
↳ | android.database.DatabaseUtils |
Static utility methods for dealing with databases and Cursor
s.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DatabaseUtils.InsertHelper |
This class was deprecated
in API level 17.
Use SQLiteStatement instead.
|
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | STATEMENT_ABORT | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_ATTACH | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_BEGIN | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_COMMIT | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_DDL | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_OTHER | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_PRAGMA | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_SELECT | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_UNPREPARED | One of the values returned by getSqlStatementType(String) . |
|||||||||
int | STATEMENT_UPDATE | One of the values returned by getSqlStatementType(String) . |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends an SQL string to the given StringBuilder, including the opening
and closing single quotes.
| |||||||||||
Appends one set of selection args to another.
| |||||||||||
Appends an Object to an SQL string with the proper escaping, etc.
| |||||||||||
Binds the given Object to the given SQLiteProgram using the proper
typing.
| |||||||||||
Utility method to run the pre-compiled query and return the blob value in the
first column of the first row.
| |||||||||||
Utility method to run the query on the db and return the blob value in the
first column of the first row.
| |||||||||||
Concatenates two SQL WHERE clauses, handling empty or null values.
| |||||||||||
Creates a db and populates it with the sql statements in sqlStatements.
| |||||||||||
Reads a Double out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a Double out of a column in a Cursor and writes it to a ContentValues.
| |||||||||||
Reads a Double out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a Float out of a column in a Cursor and writes it to a ContentValues.
| |||||||||||
Reads a Integer out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads an Integer out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a Integer out of a column in a Cursor and writes it to a ContentValues.
| |||||||||||
Reads a Long out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a Long out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a Long out of a column in a Cursor and writes it to a ContentValues.
| |||||||||||
Read the entire contents of a cursor row and store them in a ContentValues.
| |||||||||||
Reads a Short out of a column in a Cursor and writes it to a ContentValues.
| |||||||||||
Reads a String out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a String out of a field in a Cursor and writes it to a Map.
| |||||||||||
Reads a String out of a column in a Cursor and writes it to a ContentValues.
| |||||||||||
Reads a String out of a field in a Cursor and writes it to an InsertHelper.
| |||||||||||
Prints the contents of a Cursor's current row to a PrintSteam.
| |||||||||||
Prints the contents of a Cursor's current row to a StringBuilder.
| |||||||||||
Prints the contents of a Cursor's current row to System.out.
| |||||||||||
Dump the contents of a Cursor's current row to a String.
| |||||||||||
Prints the contents of a Cursor to a PrintSteam.
| |||||||||||
Prints the contents of a Cursor to a StringBuilder.
| |||||||||||
Prints the contents of a Cursor to System.out.
| |||||||||||
Prints the contents of a Cursor to a String.
| |||||||||||
return the collation key
| |||||||||||
return the collation key in hex format
| |||||||||||
Returns one of the following which represent the type of the given SQL statement.
| |||||||||||
Utility method to run the query on the db and return the value in the
first column of the first row.
| |||||||||||
Utility method to run the pre-compiled query and return the value in the
first column of the first row.
| |||||||||||
Query the table for the number of rows in the table.
| |||||||||||
Query the table for the number of rows in the table.
| |||||||||||
Query the table for the number of rows in the table.
| |||||||||||
Special function for reading an exception result from the header of
a parcel, to be used after receiving the result of a transaction.
| |||||||||||
SQL-escape a string.
| |||||||||||
Utility method to run the query on the db and return the value in the
first column of the first row.
| |||||||||||
Utility method to run the pre-compiled query and return the value in the
first column of the first row.
| |||||||||||
Special function for writing an exception result at the header of
a parcel, to be used when returning an exception from a transaction.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
One of the values returned by getSqlStatementType(String)
.
Appends an SQL string to the given StringBuilder, including the opening and closing single quotes. Any single quotes internal to sqlString will be escaped. This method is deprecated because we want to encourage everyone to use the "?" binding form. However, when implementing a ContentProvider, one may want to add WHERE clauses that were not provided by the caller. Since "?" is a positional form, using it in this case could break the caller because the indexes would be shifted to accomodate the ContentProvider's internal bindings. In that case, it may be necessary to construct a WHERE clause manually. This method is useful for those cases.
sb | the StringBuilder that the SQL string will be appended to |
---|---|
sqlString | the raw string to be appended, which may contain single quotes |
Appends one set of selection args to another. This is useful when adding a selection argument to a user provided set.
Appends an Object to an SQL string with the proper escaping, etc.
Binds the given Object to the given SQLiteProgram using the proper typing. For example, bind numbers as longs/doubles, and everything else as a string by call toString() on it.
prog | the program to bind the object to |
---|---|
index | the 1-based index to bind at |
value | the value to bind |
Utility method to run the pre-compiled query and return the blob value in the first column of the first row.
Utility method to run the query on the db and return the blob value in the first column of the first row.
Concatenates two SQL WHERE clauses, handling empty or null values.
Creates a db and populates it with the sql statements in sqlStatements.
context | the context to use to create the db |
---|---|
dbName | the name of the db to create |
dbVersion | the version to set on the db |
sqlStatements | 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) |
Reads a Double out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The REAL field to read |
values | The ContentValues to put the value into |
key | The key to store the value with in the map |
Reads a Double out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the ContentValues if the column isn't present or if its value is null.
cursor | The cursor to read from |
---|---|
values | The ContentValues to put the value into
|
column | The column to read |
Reads a Double out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The REAL field to read |
values | The ContentValues to put the value into
|
Reads a Float out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the ContentValues if the column isn't present or if its value is null.
cursor | The cursor to read from |
---|---|
values | The ContentValues to put the value into
|
column | The column to read |
Reads a Integer out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The INTEGER field to read |
values | The ContentValues to put the value into, with the field as the key |
key | The key to store the value with in the map |
Reads an Integer out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The INTEGER field to read |
values | The ContentValues to put the value into, with the field as the key
|
Reads a Integer out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the ContentValues if the column isn't present or if its value is null.
cursor | The cursor to read from |
---|---|
values | The ContentValues to put the value into
|
column | The column to read |
Reads a Long out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The INTEGER field to read |
values | The ContentValues to put the value into |
key | The key to store the value with in the map |
Reads a Long out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The INTEGER field to read |
values | The ContentValues to put the value into, with the field as the key
|
Reads a Long out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the ContentValues if the column isn't present or if its value is null.
cursor | The cursor to read from |
---|---|
values | The ContentValues to put the value into
|
column | The column to read |
Read the entire contents of a cursor row and store them in a ContentValues.
cursor | the cursor to read from. |
---|---|
values | the ContentValues to put the row into.
|
Reads a Short out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the ContentValues if the column isn't present or if its value is null.
cursor | The cursor to read from |
---|---|
values | The ContentValues to put the value into
|
column | The column to read |
Reads a String out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The TEXT field to read |
values | The ContentValues to put the value into, with the field as the key |
key | The key to store the value with in the map |
Reads a String out of a field in a Cursor and writes it to a Map.
cursor | The cursor to read from |
---|---|
field | The TEXT field to read |
values | The ContentValues to put the value into, with the field as the key
|
Reads a String out of a column in a Cursor and writes it to a ContentValues. Adds nothing to the ContentValues if the column isn't present or if its value is null.
cursor | The cursor to read from |
---|---|
values | The ContentValues to put the value into
|
column | The column to read |
Reads a String out of a field in a Cursor and writes it to an InsertHelper.
cursor | The cursor to read from |
---|---|
field | The TEXT field to read |
inserter | The InsertHelper to bind into |
index | the index of the bind entry in the InsertHelper |
Prints the contents of a Cursor's current row to a PrintSteam.
cursor | the cursor to print |
---|---|
stream | the stream to print to |
Prints the contents of a Cursor's current row to a StringBuilder.
cursor | the cursor to print |
---|---|
sb | the StringBuilder to print to |
Prints the contents of a Cursor's current row to System.out.
cursor | the cursor to print from |
---|
Dump the contents of a Cursor's current row to a String.
cursor | the cursor to print |
---|
Prints the contents of a Cursor to a PrintSteam. The position is restored after printing.
cursor | the cursor to print |
---|---|
stream | the stream to print to |
Prints the contents of a Cursor to a StringBuilder. The position is restored after printing.
cursor | the cursor to print |
---|---|
sb | the StringBuilder to print to |
Prints the contents of a Cursor to System.out. The position is restored after printing.
cursor | the cursor to print |
---|
Prints the contents of a Cursor to a String. The position is restored after printing.
cursor | the cursor to print |
---|
return the collation key
return the collation key in hex format
Returns one of the following which represent the type of the given SQL statement.
sql | the SQL statement whose type is returned by this method |
---|
Utility method to run the query on the db and return the value in the first column of the first row.
Utility method to run the pre-compiled query and return the value in the first column of the first row.
Query the table for the number of rows in the table.
db | the database the table is in |
---|---|
table | the name of the table to query |
Query the table for the number of rows in the table.
db | the database the table is in |
---|---|
table | the name of the table to query |
selection | 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 table |
Query the table for the number of rows in the table.
db | the database the table is in |
---|---|
table | the name of the table to query |
selection | 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 table |
selectionArgs | 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. |
Special function for reading an exception result from the header of a parcel, to be used after receiving the result of a transaction. This will throw the exception for you if it had been written to the Parcel, otherwise return and let you read the normal result data from the Parcel.
reply | Parcel to read from |
---|
FileNotFoundException |
---|
Utility method to run the query on the db and return the value in the first column of the first row.
Utility method to run the pre-compiled query and return the value in the first column of the first row.
Special function for writing an exception result at the header of a parcel, to be used when returning an exception from a transaction. exception will be re-thrown by the function in another process
reply | Parcel to write to |
---|---|
e | The Exception to be written. |