android query insert update delete的参数意义

来源:互联网 发布:代工 淘宝店 编辑:程序博客网 时间:2024/06/06 01:14

Cursor cursor = resolver.query(_uri, prjs, selections, selectArgs, order);

ContentResolver的query方法接受几个参数,参数意义如下:

Uri:这个Uri代表要查询的数据库名称加上表的名称。这个Uri一般都直接从MediaStore里取得,例如我要取所有歌的信息,就必须利用MediaStore.Audio.Media. EXTERNAL _CONTENT_URI这个Uri。

专辑信息要利用MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI这个Uri来查询,其他查询也都类似。

Prjs:这个参数代表要从表中选择的列,用一个String数组来表示。

Selections:相当于SQL语句中的where子句,就是代表你的查询条件。

selectArgs:这个参数是说你的Selections里有?这个符号是,这里可以以实际值代替这个问号。如果Selections这个没有?的话,那么这个String数组可以为null。

Order:说明查询结果按什么来排序。

上面就是各个参数的意义,它返回的查询结果一个Cursor,这个Cursor就相当于数据库查询的中Result,用法和它差不多

-------------------------------

增加,代码如下所以:

ContentValues values = new ContentValues();

values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER,0);

resolver.insert(_uri, values);

这个insert传递的参数只有两个,一个是Uri(同查询那个Uri),另一个是ContentValues。这个ContentValuses对应于数据库的一行数据,只要用put方法把每个列的设置好之后,直接利用insert方

法去插入就好了。

----------------------------------

更新,代码如下:

ContentResolver resolver = ctx.getContentResolver();

Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

ContentValues values = new ContentValues();

values.put(MediaStore.Audio.Media.DATE_MODIFIED, sid);

resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,values, where, selectionArgs);

上面update方法和查询还有增加里的参数都很类似,这里就不再重复叙述了,大家也可直接参考google的文档,那里也写的很清楚。

--------------------------------

删除,代码如下:

ContentResolver resolver = ctx.getContentResolver();

nbsp;   resolver.delete(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,where, selectionArgs);


原创粉丝点击