ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/2.5/FB25Transaction.pas
Revision: 421
Committed: Sat Oct 21 14:22:28 2023 UTC (13 months ago) by tony
Content type: text/x-pascal
File size: 8320 byte(s)
Log Message:
Release 2.6.3 Merged

File Contents

# User Rev Content
1 tony 45 (*
2     * Firebird Interface (fbintf). The fbintf components provide a set of
3     * Pascal language bindings for the Firebird API. Although predominantly
4     * a new development they include source code taken from IBX and may be
5     * considered a derived product. This software thus also includes the copyright
6     * notice and license conditions from IBX.
7     *
8     * Except for those parts dervied from IBX, contents of this file are subject
9     * to the Initial Developer's Public License Version 1.0 (the "License"); you
10     * may not use this file except in compliance with the License. You may obtain a
11     * copy of the License here:
12     *
13     * http://www.firebirdsql.org/index.php?op=doc&id=idpl
14     *
15     * Software distributed under the License is distributed on an "AS
16     * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17     * implied. See the License for the specific language governing rights
18     * and limitations under the License.
19     *
20     * The Initial Developer of the Original Code is Tony Whyman.
21     *
22     * The Original Code is (C) 2016 Tony Whyman, MWA Software
23     * (http://www.mwasoftware.co.uk).
24     *
25     * All Rights Reserved.
26     *
27     * Contributor(s): ______________________________________.
28     *
29     *)
30     {************************************************************************}
31     { }
32     { Borland Delphi Visual Component Library }
33     { InterBase Express core components }
34     { }
35     { Copyright (c) 1998-2000 Inprise Corporation }
36     { }
37     { InterBase Express is based in part on the product }
38     { Free IB Components, written by Gregory H. Deatz for }
39     { Hoagland, Longo, Moran, Dunst & Doukas Company. }
40     { Free IB Components is used under license. }
41     { }
42     { The contents of this file are subject to the InterBase }
43     { Public License Version 1.0 (the "License"); you may not }
44     { use this file except in compliance with the License. You }
45     { may obtain a copy of the License at http://www.Inprise.com/IPL.html }
46     { Software distributed under the License is distributed on }
47     { an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
48     { express or implied. See the License for the specific language }
49     { governing rights and limitations under the License. }
50     { The Original Code was created by InterBase Software Corporation }
51     { and its successors. }
52     { Portions created by Inprise Corporation are Copyright (C) Inprise }
53     { Corporation. All Rights Reserved. }
54     { Contributor(s): Jeff Overcash }
55     { }
56     { IBX For Lazarus (Firebird Express) }
57     { Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
58     { Portions created by MWA Software are copyright McCallum Whyman }
59     { Associates Ltd 2011 - 2015 }
60     { }
61     {************************************************************************}
62     unit FB25Transaction;
63 tony 56 {$IFDEF MSWINDOWS}
64     {$DEFINE WINDOWS}
65     {$ENDIF}
66 tony 45
67     {$IFDEF FPC}
68 tony 56 {$mode delphi}
69 tony 45 {$interfaces COM}
70     {$ENDIF}
71     {$R-}
72    
73     interface
74    
75     uses
76     Classes, SysUtils, IB, FBClientAPI, FB25ClientAPI, IBHeader,
77     FB25Attachment, FBActivityMonitor, FBTransaction;
78    
79     type
80     { TFB25Transaction }
81    
82     TFB25Transaction = class(TFBTransaction,ITransaction, IActivityMonitor)
83     private
84     FHandle: TISC_TR_HANDLE;
85 tony 263 FFirebird25ClientAPI: TFB25ClientAPI;
86 tony 45 protected
87     function GetActivityIntf(att: IAttachment): IActivityMonitor; override;
88 tony 359 function GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer): ITrInformation; override;
89 tony 263 procedure SetInterface(api: TFBClientAPI); override;
90 tony 421 procedure SetErrorHandler(Attachment: IAttachment); override;
91 tony 402 procedure InternalStartSingle(attachment: IAttachment); override;
92     procedure InternalStartMultiple; override;
93     function InternalCommit(Force: boolean): TTrCompletionState; override;
94     function InternalRollback(Force: boolean): TTrCompletionState; override;
95     procedure InternalCommitRetaining; override;
96     procedure InternalRollbackRetaining; override;
97 tony 45 public
98     property Handle: TISC_TR_HANDLE read FHandle;
99    
100     public
101     {ITransaction}
102     function GetInTransaction: boolean; override;
103     procedure PrepareForCommit; override;
104     end;
105    
106     implementation
107    
108     uses FBMessages, FBParamBlock;
109    
110     { TFB25Transaction }
111    
112     function TFB25Transaction.GetActivityIntf(att: IAttachment): IActivityMonitor;
113     begin
114     Result := (att as TFB25Attachment);
115     end;
116    
117 tony 359 function TFB25Transaction.GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer
118     ): ITrInformation;
119     begin
120     Result := TTrInformation.Create(FFirebird25ClientAPI);
121     with FFirebird25ClientAPI, Result as TTrInformation do
122 tony 421 begin
123 tony 359 if isc_transaction_info(StatusVector, @(FHandle), ReqBufLen, ReqBuffer,
124     getBufSize, Buffer) > 0 then
125 tony 421 raise EIBInterBaseError.Create(GetStatus,ConnectionCodePage);
126     end;
127 tony 359 end;
128    
129 tony 263 procedure TFB25Transaction.SetInterface(api: TFBClientAPI);
130     begin
131     inherited SetInterface(api);
132     FFirebird25ClientAPI := api as TFB25ClientAPI;
133     end;
134    
135 tony 421 procedure TFB25Transaction.SetErrorHandler(Attachment: IAttachment);
136     begin
137     if Attachment <> nil then
138     OnDatabaseError := (Attachment as TFB25Attachment).IBDataBaseError;
139     end;
140    
141 tony 402 procedure TFB25Transaction.InternalStartSingle(attachment: IAttachment);
142     var db_handle: TISC_DB_HANDLE;
143 tony 45 begin
144 tony 263 with FFirebird25ClientAPI do
145 tony 402 try
146     db_handle := (attachment as TFB25Attachment).Handle;
147     Call(isc_start_transaction(StatusVector, @FHandle,1,
148     @db_handle,(FTPB as TTPB).getDataLength,(FTPB as TTPB).getBuffer));
149     except
150     FHandle := nil;
151     raise;
152     end
153 tony 45 end;
154    
155 tony 402 procedure TFB25Transaction.InternalStartMultiple;
156 tony 45 var pteb: PISC_TEB_ARRAY;
157     i: integer;
158     begin
159     pteb := nil;
160 tony 263 with FFirebird25ClientAPI do
161 tony 45 begin
162     IBAlloc(pteb, 0, Length(FAttachments) * SizeOf(TISC_TEB));
163     try
164     for i := 0 to Length(FAttachments) - 1 do
165     if (FAttachments[i] <> nil) then
166     begin
167     pteb^[i].db_handle := @((FAttachments[i] as TFB25Attachment).Handle);
168     pteb^[i].tpb_length := (FTPB as TTPB).getDataLength;
169     pteb^[i].tpb_address := (FTPB as TTPB).getBuffer;
170     end;
171 tony 402
172 tony 45 try
173     Call(isc_start_multiple(StatusVector, @FHandle,
174     Length(FAttachments), PISC_TEB(pteb)));
175     except
176     FHandle := nil;
177     raise;
178     end;
179     finally
180     FreeMem(pteb);
181     end;
182     end;
183     end;
184    
185 tony 402 function TFB25Transaction.InternalCommit(Force: boolean): TTrCompletionState;
186 tony 45 begin
187 tony 402 Result := trCommitted;
188 tony 263 with FFirebird25ClientAPI do
189 tony 402 if Call(isc_commit_transaction(StatusVector, @FHandle),not Force) > 0 then
190     Result := trCommitFailed;
191 tony 45 FHandle := nil;
192     end;
193    
194 tony 402 function TFB25Transaction.InternalRollback(Force: boolean): TTrCompletionState;
195 tony 45 begin
196 tony 402 Result := trRolledback;
197     with FFirebird25ClientAPI do
198     if Call(isc_rollback_transaction(StatusVector, @FHandle),not Force) > 0 then
199     Result := trRollbackFailed;
200     FHandle := nil;
201     end;
202    
203     procedure TFB25Transaction.InternalCommitRetaining;
204     begin
205     with FFirebird25ClientAPI do
206     Call(isc_commit_retaining(StatusVector, @FHandle));
207     end;
208    
209     procedure TFB25Transaction.InternalRollbackRetaining;
210     begin
211     with FFirebird25ClientAPI do
212     Call(isc_rollback_retaining(StatusVector, @FHandle));
213     end;
214    
215     function TFB25Transaction.GetInTransaction: boolean;
216     begin
217     Result := FHandle <> nil;
218     end;
219    
220     procedure TFB25Transaction.PrepareForCommit;
221     begin
222     if Length(FAttachments) < 2 then
223     IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
224 tony 45 if FHandle = nil then
225     Exit;
226 tony 263 with FFirebird25ClientAPI do
227 tony 402 Call(isc_prepare_transaction(StatusVector, @FHandle));
228 tony 45 end;
229    
230     end.
231    

Properties

Name Value
svn:eol-style native