如何批次的​​ContentProvider更新DATAS,东西搞糊涂了 [英] How to batch update datas in ContentProvider,something confused me

查看:109
本文介绍了如何批次的​​ContentProvider更新DATAS,东西搞糊涂了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以执行内容提供商如下,SQL:

How can i execute this sql in content Provider as below:

update dtrips set dtp_day_idx=dtp_day_idx+2 where tp_id=1

谁能帮我解决了code

Can anyone help me fix the code

    DTrip dTrip = new DTrip();
    ContentValues values = createContentValues(dTrip);
    values.put("dtp_day_idx" ,...);
    String select ="tp_id="+tripId;
    mContentResolver.update(UsersColumns.CONTENT_URI, values, select, null);

感谢。

推荐答案

我认为你可以做到这一点只是一个SQL语句(不通过 ContentResolver的),请尝试code:

I think you could achieve that just with a SQL statement (not via ContentResolver), please try the code:

String sql = "UPDATE " + TABLE_NAME
    + " SET " + COLUMN_DAY_IDX + "=" + COLUMN_DAY_IDX + "+2" 
    + " WHERE " + COLUMN_ID  + "=1";

// open a database and execute the sql statement
DatebaseHelper dbHelper = new DatebaseHelper(mContext);
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.execSQL(sql);
dbHelper.close();

和做的更好的工作线程(避免阻塞UI线程)。

And better do it in a worker thread (avoid blocking the UI thread).

这篇关于如何批次的​​ContentProvider更新DATAS,东西搞糊涂了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆