Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Curval(), oldVal() with Cursoradapters

Status
Not open for further replies.

mHeit

Programmer
Dec 6, 2004
14
US
Can Curval() and OldVal() be used with cursoradapter cursors?

I get an error 1585 (update conflict) when I save changes to 1st cursor after saving changes to 2nd cursor. But when I try to resolve the conflict, the changes from the 2nd cursor (which are now in the underlying table don't show up in the CurVal() function. It still shows the Oldval()

I use it the following way:

First fill CAcursor1 with values from Table1.
Next fill CAcursor2 with same values from Table1.
Edit CAcursor2
TableUpdate()
select CAcursor1
Edit CACursor1 &&same fields
Begin Transaction
TablUpdate && Get error 1585
Rollback && because of error
END Transaction

? oldVal('somefield')
? CurVal('somefield') &&same as oldval

What am I missing?

Thanks
 
mHeit;

I'm not going to pretend I know a lot about the cursoradapter class but try the following:

Make sure that MULTILOCKS is set to "ON" and that you have enabled either Optimistic Table or Row buffering.

HTH

Ed

Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 

Curval() and oldVal work when the tables have the buffering enabled.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
mHeit,

Yes, CURVAL() and OLDVAL() will work pretty much the same with cursoradapters as they do otherwise. The cursoradapter is simply a wrapper for accessing the table data. The actual table is the same, and all commands and functions that work with tables will work the same with cursoradapters (with one or two very minor exceptions).

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Thanks for the response.

Buffering is automatically enabled with cursor adapter to optimistic row buffering. I also enabled multilocks. These settings aren't having any effect on my updates.

What kind of effect does a transaction and rollback have on Curval() and OldVal()? I don't perform a tablerevert() on the cursors before handling the conflict.

Thanks.
 
I looked at it again. In the command window I instantiated the same cursor adapter twice. They each contain name_l = 'Johnson'. Then I do the following:

Select CA1
REPLACE name_l WITH 'blah'
? CURVAL('adjuster') &&Johnson
? OLDVAL('adjuster') &&Johnson
TABLEUPDATE()
? OLDVAL('adjuster') &&blah
? CURVAL('adjuster') &&blah -- Table has been updated

SELECT CA2
? OLDVAL('adjuster') &&Johnson
? CURVAL('adjuster') &&Johnson -- PROBLEM, SHOULD BE blah

It doesn't reflect new value in table on disk. In a cursor adapter do I need to set buffering also on the actual underlying datasource or just on the cursors?
 
Sorry I messed up the code is as follows:

Select CA1
REPLACE name_l WITH 'blah'
? CURVAL('name_l') &&Johnson
? OLDVAL('name_l') &&Johnson
TABLEUPDATE()
? OLDVAL('name_l') &&blah
? CURVAL('name_l') &&blah -- Table has been updated

SELECT CA2
? OLDVAL('name_l') &&Johnson
? CURVAL('name_l') &&Johnson -- PROBLEM, SHOULD BE blah

It doesn't reflect new value in table on disk. In a cursor adapter do I need to set buffering also on the actual underlying datasource or just on the cursors?
 
mHeit;

Is name_l a key? or is name_l part of a relation into the child table?? If so, that's your problem - you're changing a key value.

Just a guess.

Ed



Please let me know if the suggestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.
smallbug.gif
 
No name_l is not a key. I have two key values. ins_dat_key and order_key. (Just noticed ins_dat_key is really too long). Anyway, name_l is just a last name value for an insurance adjuster.

The table is part of a database container. I don't know if that should have an effect on it.

I'm gonna start from scratch and try some experiments on a table, to see where it all goes wrong.
 
OK. Many hours later and I'm still stuck. AARGH!!!
I decided to open up two VFP 8.0 sessions. In each I create the same cursor by instantiating a cursoradapter.

I make changes in one, Tableupdate(), and changes go through. Underlying table is modified, which shows up in both sessions.

Change the same value in second cursor. Do TableUpdate(), and get error 1585 (update conflict) through AError. I do a TableRevert() and value in cursor 2 reverts to original values (not updated value in underlying table). The CurVal() NEVER shows value saved by Cursor1. CURVAl() just doesn't want to work.
Anyone know why? Can anyone produce a programatic example that shows how it works, preferrably with a cursoradapter? Or am I expecting the wrong thing with CurVal() and OldVal(). Am I testing it wrong? How do you test to see if it works?

Thanks for any help you can provide.

Sincerely,

Frustrated and hairless
 
OK me again (warning long message).

Did some more troubleshooting. I was able to get the proper values from OldVal() CurVal() by opening the same buffered cursor using two sessions with a simple Use() commands.

However, it doesn't look that CurVal() works with a Cursoradapter using a native datasource. When you load the data using a cursor adapter, it seems to produce 2 cursors. One with the table name, and one with the Alias the CA creates using the SQL-Select statement, which seems to work like a view.

If I instantiate 2 CA's and change buffering to 5 on the 1st cursor for each CA, I can get a CurVal() from them. But the CurVal() function, doesn't work with the cursors containing the SQL query results. Helpfile says that CurVal() doesn't work with Views unless they are refreshed. The CurValu() values don't update automatically. Apparently CA cursors seem to act exactly the same way, which is a problem because you need to use CurVal() after you get the update conflict after which .cursorrefresh() would return an error.

So my solution after a conflict occurs is store all user edited values in the cursor to an object (SCATTER()). Store oldval() values to collection object. Then do a .cursorfill() to update cursor with CurVal() data. Finally replace every field (equal to oldval() collection values) in updated cursor with edited values. And do some custom stuff to Current values that are both different from old values and edited values.

If you're still with me, is that pretty much the only solution or am I seriously missing something?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top