如何批次的​​ContentProvider更新DATAS,东西搞糊涂了东西、糊涂了、ContentProvider、DATAS

2023-09-06 17:31:25 作者:细腰丰臀摇摆我的欲望ゐ

我如何可以执行内容提供商如下,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).