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

INSERT INTO not update table within transaction

Status
Not open for further replies.

worky24

Programmer
Aug 20, 2003
13
RO
Hello all!

I have the following situation:

I'm using 3 tables with buffering mode 5. I'm collecting the data to update the tables using a form with an empty data environment (using variables as ControlSources for form's controls). Finally, I'm saving the values using the following code (simplified):

BEGIN TRANSACTION
INSERT INTO table1 (fields from table1) VALUES (some values)
INSERT INTO table2 (fields from table2) VALUES (some values)

SELECT table3
LOCATE FOR some_condition
IF FOUND()
some code
ELSE
INSERT INTO table3 (fields from table3) VALUES (some values)
ENDIF

llUpdt=TABLEUPDATE(.T.,.F.,table1)
IF llUpdt
llUpdt=TABLEUPDATE(.T.,.F.,table2)
ENDIF
IF llUpdt
llUpdt=TABLEUPDATE(.T.,.F.,table3)
ENDIF

IF llUpdt
END TRANSACTION
ELSE
ROLLBACK
TABLEREVERT(.....)
......
ENDIF

Problem: The first two tables are updated but not the third! When I issue the third TABLEUPDATE (for table3), apparently the table is updated (I see in status bar that the number of records is incremented by 1) but when is executed 'END TRANSACTION' number of records are decremented by 1 and the new record disappear!!!

Have anyone some suggestions?

Thanks!
 
That is weird! It seems like it should work.

I'd reiterate DSummZZZ's question.

Also, are you sure your not getting an error in the line:
llUpdt=TABLEUPDATE(.T.,.F.,table3), that's somehow not
getting trapped? (possibly caused by an error method in
force that's not trapping for the condition)

Darrell
 
worky24,

I agree with the others. Your code should work (except I disagree about SET MULTILOCKS. You wouldn't have been able to set the buffer mode in the first place if that had not been ON.)

You need to do some detailed debugging here. Check the value of llUpdt at every stage, and make sure it really is doing an End Transaction rather than a Rollback.

Also, do you have any triggers in force? If a trigger returns .F., it would explain why the record is apparently being inserted and subsequently "un-inserted". (But, in that case, I would expect the entire transaction to be rolled back.)

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top