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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When Does REPLACE Change Field?

Status
Not open for further replies.

Shanachie

Programmer
Jun 18, 2000
92
US
When is a REPLACEd value reflected in the table? I have a situation in which two similar routines are opening tables (different tables) and REPLACE-ing a value but when I BROWSE the tables (during execution), one of them does not reflect the change. Later on, I can BROWSE and find the change. The only thing that I can see that is different is that in the one that does reflect the change, another SELECT has been executed. Does that cause the value to be actually written to the table? At exactly what point is the value written to the table? Is there another way to force the writing of that changed value?

TIA,
Shanachie
 
Are your tables buffered using Cursorsetprop() and set to five?

If so , you need to do TableUpdate(.t.) to commit the changes to the buffered table! Please let me know if this helped you :)

Tekno
Wireless Toyz
Ypsilanti, Michigan
 
<Are your tables buffered using Cursorsetprop() and set to five?>

No, they are not. Data buffering is not enabled. These tables are accessed in random order; buffering would not help, as far as I can see.

If it's any help, here's the code fragment. The context is a purchase order system, here accessing the table to track po status. The mem var poslockflg is also used to enable/disable the Save button. The field ps_wholock keeps track of who locked the record:

use (postatusDB)in 0
select po_status
set order to ps_ponum
seek poid
poslockflg = lock()
if poslockflg then
replace ps_wholock with signonname
else
errmsg0 = &quot;Hmmmm....&quot;
errmsg1 = &quot;The status record for that PO&quot;
errmsg2 = &quot;is locked by another user! (&quot;+;
alltrim(po_status.ps_wholock)+&quot;)&quot;
errmsg3 = &quot;You have read-only access.&quot;
do form ErrMsg
endif
scatter memvar memo


The code is intended to prevent more than one user from accessing the record as read/write and to tell that user who is locking the record. (Occasionally, someone will lock a record, then go to a meeting or lunch, tying the record up indefinitely.) The problem is that the second user gets a message that has a blank for ps_wholock. If I BROWSE the table at that point, the record is indeed blank, despite the first user's REPLACE. How come?

TIA,
Shanachie
 
OK, I've found a solution but I don't like it. After the REPLACE, I SEEK the same record again. That seems to force the table to update. Seems like there should be a better way to do that. Ah, well.

If anyone has any better ideas, I'd love to hear them. This just doesn't seem, well, quite right.

Shanachie

New code fragment:

use (postatusDB)in 0
select po_status
set order to ps_ponum
seek poid
poslockflg = lock()
if poslockflg then
replace ps_wholock with signonname
seek poid && seek same record to force update
else
errmsg0 = &quot;Hmmmm....&quot;
errmsg1 = &quot;The status record for that PO&quot;
errmsg2 = &quot;is locked by another user! (&quot;+;
alltrim(po_status.ps_wholock)+&quot;)&quot;
errmsg3 = &quot;You have read-only access.&quot;
do form ErrMsg
endif
scatter memvar memo

 
OK, I've found a solution but I don't like it. After the REPLACE, I SEEK the same record again. That seems to force the table to update. Seems like there should be a better way to do that. Ah, well.

In order to save a record in a non-buffered table, all that is required is to move the record pointer (which is what you are doing), so to answer, no, there isn't any other way.

Mike Gagnon

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

Have you tried just simply

FLUSH

after REPLACE?

Another choice would be to try SYS(1104) function.

Essentially, both of them force writing onto disk and free the memory variables/buffers. Even if you do not enable buffering, the later is still present, so issuing FLUSH would not hurt.

IHTH

Regards,

Ilya
 
FLUSH seems to do the trick!

Thanks, that just feels better.

Shanachie
 
Even though you seem to be happy, I'm just curious about the two things I highlighted below:
use (postatusDB)in 0 ALIAS po_status
select po_status
set order to ps_ponum
seek poid
poslockflg = lock()
if poslockflg then
replace ps_wholock with signonname
FLUSH
UNLOCK
else

1) Are you missing this optional ALIAS clause?
2) Are you unlocking this record somewhere?

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top