execSQL() with UPDATE doesn't update

后端 未结 2 1259
Happy的楠姐
Happy的楠姐 2020-12-21 08:30

I am trying to use rawQuery and execSQL methods for manipulating my database, instead of the .update, .insert, etc. I am

2条回答
  •  执笔经年
    2020-12-21 09:08

    From the Android SQLiteDatabase class documentation:

    Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.

    It has no means to return any data (such as the number of affected rows). Instead, you're encouraged to use insert(String, String, ContentValues), update(String, ContentValues, String, String[]), et al, when possible.

    Then later:

    For UPDATE statements, use any of the following instead.

    update(String, ContentValues, String, String[])

    updateWithOnConflict(String, ContentValues, String, String[], int)

    As far as I can tell, the execSQL method is more for higher level database operations, such as creating tables and changing schema, and the .query, .update, .delete, etc. methods should be used to modify rows. I'm not sure you have another option besides .update to perform this operation.

提交回复
热议问题