您的位置:首页 > 产品设计 > UI/UE

withValueBackReference简介

2011-12-16 11:07 183 查看
ContentProviderOperation.Builder的withValueBackReference函数定义如下:

ContentProviderOperation.BuilderwithValueBackReference(String key,
int previousResult)
Add a ContentValues back reference.

第一个参数key对应于数据库中的列名,第二个参数previousResult代表着:回引数据库批量操作中的第previousResult个数据库操作的返回值。

总的来说就是说把批量数据库操作中的第previousResult个数据库操作的返回值作为列名为key的记录的值

ContentProviderOperation.BuilderwithValueBackReferences(ContentValues backReferences)
Add a 
ContentValues
 of
back references.

同上,只是把2个参数封装成一个参数。
示例1:
来源http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html

 ArrayList<ContentProviderOperation> ops =
          new ArrayList<ContentProviderOperation>();
 ...
 int rawContactInsertIndex = ops.size();
 ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
          .withValue(RawContacts.ACCOUNT_TYPE, accountType)
          .withValue(RawContacts.ACCOUNT_NAME, accountName)
          .build());

 ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
          .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
          .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")
          .build());

 getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
 


Note the use of 
withValueBackReference(String,
int)
 to refer to the as-yet-unknown index value of the raw contact inserted in the first operation.

结束!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库 string
相关文章推荐