Subject Re: [IBO] Cursors losing buffer after insert
Author Helen Borrie
At 01:01 AM 27-10-02 +0000, Paul Filmer wrote:

>For INSERTING a record:
>
>C_Cursor.ParamByName('pPRIMARY_FIELD').AsInteger := 0;
>C_Cursor.Open;
>C_Cursor.Edit;
>C_Cursor.FieldByName('PRIMARY_FIELD').AsInteger := 123;
>... + other fields assigned here.
>C_Cursor.Post;
>
>And after the post we find that:
>C_Cursor.FieldByName('PRIMARY_FIELD').AsInteger = 0
>
>Because the data has been committed to the server and the local
>buffer emptied. This I can understand.

In fact, IB_Cursor doesn't have a local buffer. You are looking at THE row
buffer (the buffer for the current row). Always, for an IB_Cursor, the row
buffer contains the latest row fetched from the database. Because you
called Open instead of First -
if FetchAll is true you are looking at the last row of the set
if FetchAll is False you are looking at the row...or, if you
subsequently called Next, then it will be the second row from the
server...and so on

However, your SQL happens to be a singleton select, so it happens to be
both the first and the last row.


>However, EDITING a record:
>
>C_Cursor.ParamByName('pPRIMARY_FIELD').AsInteger := 123;
>C_Cursor.Open;
>C_Cursor.Edit;
>C_Cursor.FieldByName('PRIMARY_FIELD').AsInteger := 124;
>C_Cursor.Post;
>
>And we see that the updated data is still available to us:
>C_Cursor.FieldByName('PRIMARY_FIELD').AsInteger = 124

That is because you changed the data in the row buffer. If you commit this
and afterwards perform a refresh of the original statement, you will get an
empty row buffer, because there is no longer a row in the table that
matches the criteria of your SQL.


>So my confusion is: why does the buffer do things differently for an
>edit operation. And if we CAN keep the buffer after an edit, is it
>possible to do the same after an insertion.

Not without a buffer to store it in. If you do this edit and then commit
it, you can only retrieve the edited row into the row buffer by changing
the parameter of your SQL to be the new PK you entered. There is no
dataset buffer in which to hold both the old (now non-existent) row and the
changed row.

>Hope this makes a little more sense!

Well....I think you need to understand the use of an unbuffered dataset and
cut your cloth accordingly. If you need buffering, don't use IB_Cursor.

Helen