-
@Deprecated() public class DatabaseUtils.InsertHelper
This class allows users to do multiple inserts into a table usingthe same statement.
This class is not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description public final static int
TABLE_INFO_PRAGMA_COLUMNNAME_INDEX
public final static int
TABLE_INFO_PRAGMA_DEFAULT_INDEX
-
Constructor Summary
Constructors Constructor Description DatabaseUtils.InsertHelper(SQLiteDatabase db, String tableName)
-
Method Summary
Modifier and Type Method Description int
getColumnIndex(String key)
Returns the index of the specified column. 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, int 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
bind(int index, Array<byte> value)
Bind the value to an index. void
bind(int index, String value)
Bind the value to an index. long
insert(ContentValues values)
Performs an insert, adding a new row with the given values.If the table contains conflicting rows, an error isreturned. long
execute()
Execute the previously prepared insert or replace using the bound valuessince the last call to prepareForInsert or prepareForReplace. 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.If the table contains conflicting rows, they are deletedand replaced with the new row. void
close()
Close this object and release any resources associated withit. -
-
Constructor Detail
-
DatabaseUtils.InsertHelper
DatabaseUtils.InsertHelper(SQLiteDatabase db, String tableName)
- Parameters:
db
- the SQLiteDatabase to insert intotableName
- the name of the table to insert into
-
-
Method Detail
-
getColumnIndex
int getColumnIndex(String key)
Returns the index of the specified column. This is index is suitagble for usein calls to bind().
- Parameters:
key
- the column name
-
bind
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 bindvalue
- the value to bind
-
bind
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 bindvalue
- the value to bind
-
bind
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 bindvalue
- the value to bind
-
bind
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 bindvalue
- the value to bind
-
bind
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 bindvalue
- the value to bind
-
bindNull
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
-
bind
void bind(int index, Array<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 bindvalue
- the value to bind
-
bind
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 bindvalue
- the value to bind
-
insert
long insert(ContentValues values)
Performs an insert, adding a new row with the given values.If the table contains conflicting rows, an error isreturned.
- Parameters:
values
- the set of values with which to populate thenew row
-
execute
long execute()
Execute the previously prepared insert or replace using the bound valuessince the last call to prepareForInsert or prepareForReplace.
Note that calling bind() and then execute() is not thread-safe. The only thread-safeway to use this class is to call insert() or replace().
-
prepareForInsert
void prepareForInsert()
Prepare the InsertHelper for an insert. The pattern for this is:
- prepareForInsert()
- bind(index, value);
- bind(index, value);
- ...
- bind(index, value);
- execute();
-
prepareForReplace
void prepareForReplace()
Prepare the InsertHelper for a replace. The pattern for this is:
- prepareForReplace()
- bind(index, value);
- bind(index, value);
- ...
- bind(index, value);
- execute();
-
replace
long replace(ContentValues values)
Performs an insert, adding a new row with the given values.If the table contains conflicting rows, they are deletedand replaced with the new row.
- Parameters:
values
- the set of values with which to populate thenew row
-
close
void close()
Close this object and release any resources associated withit. The behavior of calling
insert()
aftercalling this method is undefined.
-
-
-
-