English | Site Directory

Android - An Open Handset Alliance Project

android.database
public class

android.database.DatabaseUtils

java.lang.Object
android.database.DatabaseUtils

Static utility methods for dealing with databases and Cursors.

Summary

Public Constructors

          DatabaseUtils()

Public Methods

      static  void  appendEscapedSQLString(StringBuilder sb, String sqlString)
Appends an SQL string to the given StringBuilder, including the opening and closing single quotes.
    final  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  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, String key)
Reads a Integer 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  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  dumpCurrentRow(Cursor cursor, PrintStream stream)
Prints the contents of a Cursor's current row to a PrintSteam.
      static  void  dumpCurrentRow(Cursor cursor)
Prints the contents of a Cursor's current row to System.out.
      static  void  dumpCurrentRow(Cursor cursor, StringBuilder sb)
Prints the contents of a Cursor's current row to a StringBuilder.
      static  void  dumpCursor(Cursor cursor)
Prints the contents of a Cursor to System.out.
      static  void  dumpCursor(Cursor cursor, StringBuilder sb)
Prints the contents of a Cursor to a StringBuilder.
      static  void  dumpCursor(Cursor cursor, PrintStream stream)
Prints the contents of a Cursor to a PrintSteam.
      static  String  dumpCursorToString(Cursor cursor)
Prints the contents of a Cursor to a String.
      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  queryNumEntries(SQLiteDatabase db, String table)
Query the table for the number of rows in the table.
Methods inherited from class java.lang.Object

Details

Public Constructors

public DatabaseUtils()

Public Methods

public static void appendEscapedSQLString(StringBuilder sb, String sqlString)

Appends an SQL string to the given StringBuilder, including the opening and closing single quotes. Any single quotes internal to sqlString will be escaped.

Parameters

sb the StringBuilder that the SQL string will be appended to
sqlString the raw string to be appended, which may contain single quotes

public static final void appendValueToSql(StringBuilder sql, Object value)

Appends an Object to an SQL string with the proper escaping, etc.

public static void bindObjectToProgram(SQLiteProgram prog, int index, Object value)

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.

Parameters

prog the program to bind the object to
index the 1-based index to bind at
value the value to bind

public 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.

Parameters

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

public 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.

Parameters

cursor The cursor to read from
field The REAL field to read
values The ContentValues to put the value into

public 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.

Parameters

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

public 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.

Parameters

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

public 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.

Parameters

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

public 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.

Parameters

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

public static void cursorRowToContentValues(Cursor cursor, ContentValues values)

Read the entire contents of a cursor row and store them in a ContentValues.

Parameters

cursor the cursor to read from.
values the ContentValues to put the row into.

public 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.

Parameters

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

public 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.

Parameters

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

public static void dumpCurrentRow(Cursor cursor, PrintStream stream)

Prints the contents of a Cursor's current row to a PrintSteam.

Parameters

cursor the cursor to print
stream the stream to print to

public static void dumpCurrentRow(Cursor cursor)

Prints the contents of a Cursor's current row to System.out.

Parameters

cursor the cursor to print from

public static void dumpCurrentRow(Cursor cursor, StringBuilder sb)

Prints the contents of a Cursor's current row to a StringBuilder.

Parameters

cursor the cursor to print
sb the StringBuilder to print to

public static void dumpCursor(Cursor cursor)

Prints the contents of a Cursor to System.out. The position is restored after printing.

Parameters

cursor the cursor to print

public static void dumpCursor(Cursor cursor, StringBuilder sb)

Prints the contents of a Cursor to a StringBuilder. The position is restored after printing.

Parameters

cursor the cursor to print
sb the StringBuilder to print to

public static void dumpCursor(Cursor cursor, PrintStream stream)

Prints the contents of a Cursor to a PrintSteam. The position is restored after printing.

Parameters

cursor the cursor to print
stream the stream to print to

public static String dumpCursorToString(Cursor cursor)

Prints the contents of a Cursor to a String. The position is restored after printing.

Parameters

cursor the cursor to print

Returns

  • a String that contains the dumped cursor

public 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.

public static long queryNumEntries(SQLiteDatabase db, String table)

Query the table for the number of rows in the table.

Parameters

db the database the table is in
table the name of the table to query

Returns

  • the number of rows in the table
Build m5-rc15g - 14 May 2008 12:50