简体   繁体   中英

Is it possible to compare two cursors?

I need to check if two cursors pointing at the same rows with the same values. Is it possible?

More details:

  1. I'm loading data from my own ContentProvider
  2. I'm sending request to server and then updating my data inside ContentProvider with new values.
  3. If values is changed - I need to notify user that he can update data.

As per CommonsWare's deleted answer:

Iterate over the relevant columns in the Cursor, retrieve the values, and compare each.

Although you may not know in advance the type of each column, you can find out with Cursor.getType() . You can also use Cursor.getColumnNames() to get the name of each column, and the number of columns.

This information will allow you to then use the correct accessor method to obtain each value and compare.

In SQLite, rows do not have an identity separate from their column values (but the ROWID is one of these values).

What you want requires that your data has some unique column(s) as part of the cursor, either the ROWID , or some other key value that is guaranteed to have no duplicates.

Otherwise, you can never know if what you see is just two records that happen to have the same values in those columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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