SqlCeResultSet - Problem After Deleting First Record

Hi,

I've noticed that after the first record from a ResultSet is deleted, HasRows property throws an exception like "The current row was deleted." Method ReadFirst() throws similar exception as well.

More details:

1. Create a ResultSet:ExecuteResultSet(ResultSetOptions.Updatable |ResultSetOptions.Scrollable |ResultSetOptions.Sensitive)

2. Let's say, there is no records in the resultset. Insert two new ones. Then call:ReadAbsolute(0); Delete(); HasRows; and the exception is thrown.

3. Then you can call ReadFirst() or Read with the same result.

4. Now call ReadAbsolute(0). It returns true. Call HasRows, ReadFirst() or Read() and you will get the exception each time.

I tried to explain this with the fact thatDelete() doesn't change the current position of the ResultSet. But I don't see why that would mess the HasRows property or why after ReadAbsolute(0) retuns true, HasRows or ReadFirst() doesn't work.

Could anybody tell me what the problem is?

Thank you.

[1730 byte] By [arturm] at [2007-12-25]
# 1

As you have mentioned Delete() dowsn't change the current position of the resultset and that explains why HasRows doesn't work.

In SSEv, HasRows has been implemented little differently (one may say that this is not the best way to do this). To evaluate HasRows and return boolean, we do it by calling Move() function which moves to the first row and then comes back to the start. This is the reason why SSEv HasRows requires cursor to be scrollable (which is not the case for other providers' implementation of HasRows). Since we do not change the position of the result set, HasRows fails as it tries to move to the first row as part of evaluating the value of boolean.

Thanks

Sachin

SachinSinha at 2007-9-3 > top of Msdn Tech,SQL Server,SQL Server Compact Edition...
# 2

Sachin,

Thanks for your answear. However, I think that there is more to that. The ResultSet is scrolable, and there are issues not only with HasRows.

1. After the row is deleted, ReadFirst() and Read() don't work either.

2. Why after ReadAbsolute(0) returns true, ReadFirst(), Read() and HasRows throw an exception?

3. And there is one more issue I run into which I didn't mention in the original post. This one has nothing to do with deleting, but with using combination of ReadAbsolute(0) and ReadRelative(1).

After two Insert()s with PositionOnInsertedRow option, the code below doesn't find the first record.

if (rsItems.ReadAbsolute(0))

{

do

{...

}

while (rsItems.ReadRelative(1));

}

Artur

PS. As far as HasRows is concerned, I think the problem can be worked around with ReadAbsolute(0).

arturm at 2007-9-3 > top of Msdn Tech,SQL Server,SQL Server Compact Edition...
# 3

When we call ReadAbsolute(), then we access the particular row using BookMark. Something like

GotoRow(bookmarks[position]);

After deleteing the record (after calling ReadAbsolute()), we make sure to delete the bookmark from the cache

But again as in the case of HasRows, we implement ReadFirst() using Move() .Same with Read() and ReadRelative().

Ideally, we should have the engine wrapper position us on the correct row, however there are semantic differences between QP/SE cursors wrt MOVE_PREVIOUS, MOVE_FIRST etc...Move() works on these items.

I would agree the third item you have mentioned should behave correctly, but i reckon it has to do with the way we move from one row to another. And this is different from how we go to a row by calling ReadAbsolute(), where we use GotoRow().

We will look into the issues.

Thanks

SachinSinhaMSFT at 2007-9-3 > top of Msdn Tech,SQL Server,SQL Server Compact Edition...

SQL Server

Site Classified