android内容提供商总和查询 [英] android content provider sum query
本文介绍了android内容提供商总和查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要sum(column)
时可以使用getContentResolver().query()
吗?
或
我必须对数据库句柄进行原始查询吗?
Do I have to make raw query to db handle?
推荐答案
好的,看来使用getContentResolver().query()
是不可能的.
我必须建立数据库连接并建立rawQuery
.
OK, it seems that its not possible using getContentResolver().query()
.
I had to get db connection and make rawQuery
.
ContentProviderClient client = getContentResolver().acquireContentProviderClient(AUTHORITY);
SQLiteDatabase dbHandle= ((MyContentProvider)client.getLocalContentProvider()).getDbHandle();
Cursor cursor = dbHandle.rawQuery("SELECT sum("+COLUM_NNAME+") FROM "+TABLE_NAME +" WHERE "+WHERE_CLAUSE , null);
cursor.moveToFirst();
int cnt = cursor.getInt(0);
cursor.close();
cursor.deactivate();
client.release();
这篇关于android内容提供商总和查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文