ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/2.5/FB25Transaction.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/2.5/FB25Transaction.pas (file contents):
Revision 380 by tony, Mon Jan 10 10:13:17 2022 UTC vs.
Revision 402 by tony, Mon Aug 1 10:07:24 2022 UTC

# Line 87 | Line 87 | type
87      function GetActivityIntf(att: IAttachment): IActivityMonitor; override;
88      function GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer): ITrInformation; override;
89      procedure SetInterface(api: TFBClientAPI); override;
90 +    procedure InternalStartSingle(attachment: IAttachment); override;
91 +    procedure InternalStartMultiple; override;
92 +    function InternalCommit(Force: boolean): TTrCompletionState; override;
93 +    function InternalRollback(Force: boolean): TTrCompletionState; override;
94 +    procedure InternalCommitRetaining; override;
95 +    procedure InternalRollbackRetaining; override;
96    public
97      property Handle: TISC_TR_HANDLE read FHandle;
98  
# Line 94 | Line 100 | type
100      {ITransaction}
101      function GetInTransaction: boolean; override;
102      procedure PrepareForCommit; override;
97    procedure Commit(Force: boolean=false); override;
98    procedure CommitRetaining; override;
99    procedure Start(DefaultCompletion: TTransactionCompletion=taCommit); overload; override;
100    procedure Rollback(Force: boolean=false); override;
101    procedure RollbackRetaining; override;
103   end;
104  
105   implementation
# Line 129 | Line 130 | begin
130    OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError;
131   end;
132  
133 < function TFB25Transaction.GetInTransaction: boolean;
134 < begin
134 <  Result := FHandle <> nil;
135 < end;
136 <
137 < procedure TFB25Transaction.PrepareForCommit;
138 < begin
139 <  if Length(FAttachments) < 2 then
140 <    IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
141 <  if FHandle = nil then
142 <    Exit;
143 <  with FFirebird25ClientAPI do
144 <    Call(isc_prepare_transaction(StatusVector, @FHandle));
145 < end;
146 <
147 < procedure TFB25Transaction.Commit(Force: boolean);
148 < begin
149 <  if FHandle = nil then
150 <    Exit;
151 <  with FFirebird25ClientAPI do
152 <    Call(isc_commit_transaction(StatusVector, @FHandle),not Force);
153 <  FHandle := nil;
154 < end;
155 <
156 < procedure TFB25Transaction.CommitRetaining;
133 > procedure TFB25Transaction.InternalStartSingle(attachment: IAttachment);
134 > var db_handle: TISC_DB_HANDLE;
135   begin
158  if FHandle = nil then
159    Exit;
136    with FFirebird25ClientAPI do
161    Call(isc_commit_retaining(StatusVector, @FHandle));
162 end;
163
164 procedure TFB25Transaction.Start(DefaultCompletion: TTransactionCompletion);
165 var pteb: PISC_TEB_ARRAY;
166    i: integer;
167    db_handle: TISC_DB_HANDLE;
168 begin
169  if FHandle <> nil then
170    Exit;
171  pteb := nil;
172  FDefaultCompletion := DefaultCompletion;
173  with FFirebird25ClientAPI do
174  if (Length(FAttachments) = 1)  then
137    try
138 <    db_handle := (FAttachments[0] as TFB25Attachment).Handle;
138 >    db_handle := (attachment as TFB25Attachment).Handle;
139      Call(isc_start_transaction(StatusVector, @FHandle,1,
140                @db_handle,(FTPB as TTPB).getDataLength,(FTPB as TTPB).getBuffer));
141    except
142      FHandle := nil;
143      raise;
144    end
145 <  else
145 > end;
146 >
147 > procedure TFB25Transaction.InternalStartMultiple;
148 > var pteb: PISC_TEB_ARRAY;
149 >    i: integer;
150 > begin
151 >  pteb := nil;
152 >  with FFirebird25ClientAPI do
153    begin
154      IBAlloc(pteb, 0, Length(FAttachments) * SizeOf(TISC_TEB));
155       try
# Line 191 | Line 160 | begin
160            pteb^[i].tpb_length := (FTPB as TTPB).getDataLength;
161            pteb^[i].tpb_address := (FTPB as TTPB).getBuffer;
162          end;
163 +
164          try
165            Call(isc_start_multiple(StatusVector, @FHandle,
166                                     Length(FAttachments), PISC_TEB(pteb)));
# Line 202 | Line 172 | begin
172          FreeMem(pteb);
173       end;
174    end;
205  Inc(FSeqNo);
175   end;
176  
177 < procedure TFB25Transaction.Rollback(Force: boolean);
177 > function TFB25Transaction.InternalCommit(Force: boolean): TTrCompletionState;
178   begin
179 <  if FHandle = nil then
211 <    Exit;
179 >  Result := trCommitted;
180    with FFirebird25ClientAPI do
181 <    Call(isc_rollback_transaction(StatusVector, @FHandle),not Force);
181 >    if Call(isc_commit_transaction(StatusVector, @FHandle),not Force) > 0 then
182 >      Result := trCommitFailed;
183    FHandle := nil;
184   end;
185  
186 < procedure TFB25Transaction.RollbackRetaining;
186 > function TFB25Transaction.InternalRollback(Force: boolean): TTrCompletionState;
187 > begin
188 >  Result := trRolledback;
189 >  with FFirebird25ClientAPI do
190 >    if Call(isc_rollback_transaction(StatusVector, @FHandle),not Force) > 0 then
191 >      Result := trRollbackFailed;
192 >  FHandle := nil;
193 > end;
194 >
195 > procedure TFB25Transaction.InternalCommitRetaining;
196 > begin
197 >  with FFirebird25ClientAPI do
198 >    Call(isc_commit_retaining(StatusVector, @FHandle));
199 > end;
200 >
201 > procedure TFB25Transaction.InternalRollbackRetaining;
202   begin
203 +  with FFirebird25ClientAPI do
204 +    Call(isc_rollback_retaining(StatusVector, @FHandle));
205 + end;
206 +
207 + function TFB25Transaction.GetInTransaction: boolean;
208 + begin
209 +  Result := FHandle <> nil;
210 + end;
211 +
212 + procedure TFB25Transaction.PrepareForCommit;
213 + begin
214 +  if Length(FAttachments) < 2 then
215 +    IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
216    if FHandle = nil then
217      Exit;
218    with FFirebird25ClientAPI do
219 <    Call(isc_rollback_retaining(StatusVector, @FHandle));
219 >    Call(isc_prepare_transaction(StatusVector, @FHandle));
220   end;
221  
222   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines