简体   繁体   English

使用SQLite(Android)时,更改的行数(受影响的行)始终为1

[英]The number of changed rows (rows affected) is always 1 with SQLite (Android)

I have this SQLite table in my Android application: 我的Android应用程序中有此SQLite表:

CREATE TABLE " + TABLE_NAME + " (" +
        _ID + " INTEGER PRIMARY KEY AUTOINCREMENT" +
        COMMA + COLUMN_NAME_SID + " INTEGER" +
        COMMA + COLUMN_NAME_TITLE + " TEXT NOT NULL" +
        COMMA + COLUMN_NAME_IS_MINE + " BOOLEAN NOT NULL" +
        COMMA + COLUMN_NAME_CREATED_AT + " DATETIME" +
        COMMA + COLUMN_NAME_CODE + " TEXT UNIQUE" +
        COMMA + COLUMN_NAME_MSG + " INTEGER NOT NULL DEFAULT 0" +
        " );";

When I update a record with the same data, the number of changed rows (rows affected) is always 1. 当我使用相同的数据更新记录时,更改的行数(受影响的行)始终为1。

SQLiteDatabase db = m_helper.getWritableDatabase();
String where = COLUMN_NAME_SID + "=" + sid;
ContentValues values = new ContentValues();
values.put(COLUMN_NAME_MSG, msg);
int rowsAffected = db.update(TABLE_NAME, values, where, null);
db.close();
// rowsAffected is always 1!

In other DBMS (like Mysql), when I perform an update with the same data on a specific record, the number of changed rows is 0. In SQLite on Android is different? 在其他DBMS(如Mysql)中,当我使用特定记录上的相同数据执行更新时,已更改的行数为0。Android上的SQLite是否不同?

Maybe it just does not recognize if that data has actually been changed. 也许只是无法识别该数据是否已实际更改。 Any query is counted as a change, even if the data is the same. 即使数据相同,任何查询也算作更改。

Well that's just the way they've implemented it. 嗯,这就是他们实施它的方式。 For instance, if you write something in IntellIJ IDE and delete it, it doesn't show the file as changed, but if you do it in Visual Studio, it does, unless you did CTRL+Z . 例如,如果您在IntellIJ IDE中编写某些内容并将其删除,则该文件不会显示已更改的文件,但是,如果您在Visual Studio中进行此操作,它将显示该文件,除非您执行CTRL+Z It's just a different way of implementation. 这只是一种不同的实现方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM