public static class DatabaseUtils.InsertHelper
extends Object
| java.lang.Object | |
| android.database.DatabaseUtils.InsertHelper | |
此类在API级别17中已被弃用。
改为使用SQLiteStatement 。
该类允许用户使用相同的语句对表进行多次插入。
这个类不是线程安全的。
Public constructors |
|
|---|---|
DatabaseUtils.InsertHelper(SQLiteDatabase db, String tableName) |
|
公共方法(Public methods) |
|
|---|---|
void |
bind(int index, float value) 将该值绑定到索引。 |
void |
bind(int index, double value) 将该值绑定到索引。 |
void |
bind(int index, int value) 将该值绑定到索引。 |
void |
bind(int index, String value) 将该值绑定到索引。 |
void |
bind(int index, long value) 将该值绑定到索引。 |
void |
bind(int index, byte[] value) 将该值绑定到索引。 |
void |
bind(int index, boolean value) 将该值绑定到索引。 |
void |
bindNull(int index) 将null绑定到索引。 |
void |
close() 关闭此对象并释放与其关联的所有资源。 |
long |
execute() 执行先前准备好的插入或使用自上次调用prepareForInsert或prepareForReplace以来的绑定值进行替换。 |
int |
getColumnIndex(String key) 返回指定列的索引。 |
long |
insert(ContentValues values) 执行插入操作,添加具有给定值的新行。 |
void |
prepareForInsert() 为插入准备InsertHelper。 |
void |
prepareForReplace() 准备InsertHelper进行替换。 |
long |
replace(ContentValues values) 执行插入操作,添加具有给定值的新行。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
DatabaseUtils.InsertHelper (SQLiteDatabase db, String tableName)
| 参数(Parameters) | |
|---|---|
db |
SQLiteDatabase: the SQLiteDatabase to insert into |
tableName |
String: the name of the table to insert into |
void bind (int index,
float value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
float: the value to bind |
void bind (int index,
double value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
double: the value to bind |
void bind (int index,
int value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
int: the value to bind |
void bind (int index,
String value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
String: the value to bind |
void bind (int index,
long value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
long: the value to bind |
void bind (int index,
byte[] value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
byte: the value to bind |
void bind (int index,
boolean value)
将该值绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
value |
boolean: the value to bind |
void bindNull (int index)
将null绑定到索引。 没有匹配execute()的prepareForInsert()或prepareForReplace()必须已经被调用。
| 参数(Parameters) | |
|---|---|
index |
int: the index of the slot to which to bind |
long execute ()
执行先前准备好的插入或使用自上次调用prepareForInsert或prepareForReplace以来的绑定值进行替换。
请注意,调用bind()然后执行()不是线程安全的。 使用这个类的唯一线程安全的方法是调用insert()或replace()。
| 返回(Returns) | |
|---|---|
long |
the row ID of the newly inserted row, or -1 if an error occurred |
int getColumnIndex (String key)
返回指定列的索引。 这是索引适用于调用bind()。
| 参数(Parameters) | |
|---|---|
key |
String: the column name |
| 返回(Returns) | |
|---|---|
int |
the index of the column |
long insert (ContentValues values)
执行插入操作,添加具有给定值的新行。 如果表中包含冲突的行,则返回错误。
| 参数(Parameters) | |
|---|---|
values |
ContentValues: the set of values with which to populate the new row |
| 返回(Returns) | |
|---|---|
long |
the row ID of the newly inserted row, or -1 if an error occurred |
void prepareForInsert ()
为插入准备InsertHelper。 这种模式是:
void prepareForReplace ()
准备InsertHelper进行替换。 这种模式是:
long replace (ContentValues values)
执行插入操作,添加具有给定值的新行。 如果该表包含冲突的行,则它们将被删除并替换为新行。
| 参数(Parameters) | |
|---|---|
values |
ContentValues: the set of values with which to populate the new row |
| 返回(Returns) | |
|---|---|
long |
the row ID of the newly inserted row, or -1 if an error occurred |