Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compare two cursors?

Tags:

android

sqlite

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.
like image 853
Dmitry Zaytsev Avatar asked Feb 11 '13 12:02

Dmitry Zaytsev


People also ask

How to compare two cursors in Oracle?

Below is my code: CREATE OR REPLACE PROCEDURE CHECK_STUDENT AS CURSOR SCHOOL_REG IS SELECT STUDENT_ID FROM SCHOOL WHERE CLASSROOM IN (1,2,3,4,5); CURSOR CLASS_REG IS SELECT STUDENT_ID, STUDENT_NAME FROM REGISTER WHERE CLASSROOM = 1; FOR X IN CLASS_REG LOOP IF X. STUDENT_ID <> SCHOOL_REG. STUDENT_ID THEN DBMS_OUTPUT.

Can we have two cursors in a procedure Oracle?

The trick to declaring a cursor within a cursor is that you need to continue to open and close the second cursor each time a new record is retrieved from the first cursor. That way, the second cursor will use the new variable values from the first cursor.

Can cursors operate on multiple rows?

Can cursor operate multiple rows? The multiple-row FETCH statement can be used with both serial and scrollable cursors. The operations used to define, open, and close a cursor for a multiple-row FETCH remain the same.


2 Answers

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.

like image 183
Graham Borland Avatar answered Oct 10 '22 07:10

Graham Borland


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.

like image 41
CL. Avatar answered Oct 10 '22 07:10

CL.