Android
android.database
public static class

android.database.DatabaseUtils.InsertHelper

java.lang.Object
android.database.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.

Summary

Constants

      Value  
int  TABLE_INFO_PRAGMA_DEFAULT_INDEX    0x00000004 

Public Constructors

            DatabaseUtils.InsertHelper(SQLiteDatabase db, String tableName)

Public Methods

          void  bind(int index, byte[] value)
Bind the value to an index.
          void  bind(int index, int value)
Bind the value to an index.
          void  bind(int index, String value)
Bind the value to an index.
          void  bind(int index, double value)
Bind the value to an index.
          void  bind(int index, float value)
Bind the value to an index.
          void  bind(int index, long value)
Bind the value to an index.
          void  bind(int index, boolean value)
Bind the value to an index.
          void  bindNull(int index)
Bind null to an index.
          void  close()
Close this object and release any resources associated with it.
          long  execute()
Execute the previously prepared insert or replace using the bound values since the last call to prepareForInsert or prepareForReplace.
          int  getColumnIndex(String key)
Returns the index of the specified column.
          long  insert(ContentValues values)
Performs an insert, adding a new row with the given values.
          void  prepareForInsert()
Prepare the InsertHelper for an insert.
          void  prepareForReplace()
Prepare the InsertHelper for a replace.
          long  replace(ContentValues values)
Performs an insert, adding a new row with the given values.
Methods inherited from class java.lang.Object

Details

Constants

public static final int TABLE_INFO_PRAGMA_DEFAULT_INDEX

Constant Value: 4 (0x00000004)

Public Constructors

public DatabaseUtils.InsertHelper(SQLiteDatabase db, String tableName)

Parameters

db the SQLiteDatabase to insert into
tableName the name of the table to insert into

Public Methods

public void bind(int index, byte[] value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bind(int index, int value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bind(int index, String value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bind(int index, double value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bind(int index, float value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bind(int index, long value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bind(int index, boolean value)

Bind the value to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind
value the value to bind

public void bindNull(int index)

Bind null to an index. A prepareForInsert() or prepareForReplace() without a matching execute() must have already have been called.

Parameters

index the index of the slot to which to bind

public void close()

Close this object and release any resources associated with it. The behavior of calling insert() after calling this method is undefined.

public long execute()

Execute the previously prepared insert or replace using the bound values since the last call to prepareForInsert or prepareForReplace.

Returns

  • the row ID of the newly inserted row, or -1 if an error occurred

public int getColumnIndex(String key)

Returns the index of the specified column. This is index is suitagble for use in calls to bind().

Parameters

key the column name

Returns

  • the index of the column

public long insert(ContentValues values)

Performs an insert, adding a new row with the given values. If the table contains conflicting rows, an error is returned.

Parameters

values the set of values with which to populate the new row

Returns

  • the row ID of the newly inserted row, or -1 if an error occurred

public void prepareForInsert()

Prepare the InsertHelper for an insert. The pattern for this is:
  • prepareForInsert()
  • bind(index, value);
  • bind(index, value);
  • ...
  • bind(index, value);
  • execute();

public void prepareForReplace()

Prepare the InsertHelper for a replace. The pattern for this is:
  • prepareForReplace()
  • bind(index, value);
  • bind(index, value);
  • ...
  • bind(index, value);
  • execute();

public long replace(ContentValues values)

Performs an insert, adding a new row with the given values. If the table contains conflicting rows, they are deleted and replaced with the new row.

Parameters

values the set of values with which to populate the new row

Returns

  • the row ID of the newly inserted row, or -1 if an error occurred
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48