1. Falguni Patel
  2. PowerBuilder
  3. Wednesday, 11 May 2022 06:51 AM UTC

Hi,

 

I wish to add two transaction objects in single application. Appreciate some blogs and example.

 

Thanks,

Falguni

René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 11 May 2022 07:25 AM UTC
  2. PowerBuilder
  3. # 1

Hi Fakguni,

It is no complicated. SQLCA is the default transaction object. It is created automatically as a global variable.

But you can create more instances of the transaction class, e.g. as a global variable.

 

example:

// global variable
transaction gtr_mytrans

// application open event (for example)
gtr_mytrans = CREATE transaction

gtr_mytrans.DBMS = ...
...

CONNECT USING gtr_mytrans;
...


// application close event (for example)
DISCONNECT USING gtr_mytrans;
DESTROY gtr_mytrans


// using (examples)
dw_1.SetTransObject(gtr_mytrans)

SELECT ...
USING gtr_mytrans;

 

You can also find information in the help file: Look for "Transaction management with a separate transaction object" in https://docs.appeon.com/pb2019/datawindow_programmers_guide/ch02s03.html

 

HTH,

René

 

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Wednesday, 11 May 2022 07:20 AM UTC
  2. PowerBuilder
  3. # 2

If you want your second transaction to be global you have to declare it as a global variable. This is done like this:

// Global Variables

Transaction gnv_sqlca // or whatever name you want. This will be the equivallent of sqlca for the second transaction...

If you want it as an instance (or shared - static) in a specific object then you have to declare it to the appropriate variables declaration of your object. Or if you want it available to a specific script, the above declaration should be done to that script.

For Global Declaration:

In you application's open object:

gnv_sqlca = create transaction

gnv_sqlca.DBMS = "Your DBMS"
gnv_sqlca.LogPass = "Password" // should be provided by user...
gnv_sqlca.ServerName = "Server Name"
gnv_sqlca.LogId = "username" // should be provided by user...
gnv_sqlca.AutoCommit = False // or true depending of what you want to do.
gnv_sqlca.DBParm = "" // Additional params if needed.

connect using gnv_sqlca;

if gnv_sqlca.sqlcode <> 0 then // Connection failed!
	messagebox("Error:", gnv_sqlca.sqlerrtext) // See why...
	halt close
end if

Attention: in any sql command that should not execute to sqlca, you should state what transaction it has to use. Example:

select count(*)
into :ll_counter
from dummy
using gnv_sqlca;

Also for datawindows:

dw_1.settransobject(gnv_sqlca) // or dw_1.settrans(gnv_sqlca) depending of what you want.

When the application ends you should disconnect and destroy your object:

// Probably your application's close event.

disconnect using gnv_sqlca;
if isvalid(gnv_sqlca) then destroy gnv_sqlca

In case your didn't create your object as a global object then you should disconnect and destroy your object from the appropriate object - script.

Andreas.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.