Home > database >  Function in the transaction issues - for advice
Function in the transaction issues - for advice

Time:10-10

Question is like this,,

Insert into a (id) values (1) using the sqlca.
Wf_test ()
The rollback using sqlca;

Like this, the window function wf_Test a commit statement is in the ();
After such execution wf_test, the above statement that has been submitted, the back of the rollback doesn't work,,
If can let the commit outside does not affect the function of SQL statements?

CodePudding user response:

You write code, are indeed have personality,
I generally is

Insert into a (id) values (1) using the sqlca.
If the sqlca. Sqlcode=0 then
commit;
The else
rollback;
Messagebox (" ", "the corresponding error message")
end if

CodePudding user response:

You understand the thinking of wrong friends, your window function cf_Test () in the commit operation is also the sqlca this transaction object, the same transaction has been submitted successfully, you go to rollback certainly didn't

CodePudding user response:

The code inside the wf_test?

CodePudding user response:

Alternatively:
A, don't have a commit or rollback function;
Second, function returns a value, 1 said SQL execution fails, said 1 SQL execution success
Three, after the function call, according to the return value to determine whether a SQL execution is successful, and then make a decision whether to commit or rollback;

CodePudding user response:

Wf_Test () a Transaction is separated from the outside, inside is not affected

CodePudding user response:

Wf_Test () can be in a new transaction, separated from the original transaction, can also,
The Transaction trans;
Trans=new Transaction;

.
Commit the using trans;

Destroy trans;

CodePudding user response:

The same transaction must be submitted together with a rollback, if want to submit with the outside, the function of the inside not to commit and rollback returns sqlca. Only sqlcode, execution function to judge the outside return values, if is 0 will submit the commit, if it's not just the rollback together,

CodePudding user response:

reference 1st floor ZHGWBZHD response:
write code, like you do more personality,
I generally is

Insert into a (id) values (1) using the sqlca.
If the sqlca. Sqlcode=0 then
commit;
The else
rollback;
Messagebox (" ", "the corresponding error message")
End the if
I usually write it
  • Related