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: 56
Committed: Mon Mar 6 10:20:02 2017 UTC (7 years, 8 months ago) by tony
Content type: text/x-pascal
File size: 7184 byte(s)
Log Message:
Committing updates for Trunk

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     protected
86     function GetActivityIntf(att: IAttachment): IActivityMonitor; override;
87     public
88     property Handle: TISC_TR_HANDLE read FHandle;
89    
90     public
91     {ITransaction}
92     function GetInTransaction: boolean; override;
93     procedure PrepareForCommit; override;
94     procedure Commit(Force: boolean=false); override;
95     procedure CommitRetaining; override;
96     procedure Start(DefaultCompletion: TTransactionCompletion=taCommit); overload; override;
97     procedure Rollback(Force: boolean=false); override;
98     procedure RollbackRetaining; override;
99     end;
100    
101     implementation
102    
103     uses FBMessages, FBParamBlock;
104    
105     { TFB25Transaction }
106    
107     function TFB25Transaction.GetActivityIntf(att: IAttachment): IActivityMonitor;
108     begin
109     Result := (att as TFB25Attachment);
110     end;
111    
112     function TFB25Transaction.GetInTransaction: boolean;
113     begin
114     Result := FHandle <> nil;
115     end;
116    
117     procedure TFB25Transaction.PrepareForCommit;
118     begin
119     if Length(FAttachments) < 2 then
120     IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
121     if FHandle = nil then
122     Exit;
123     with Firebird25ClientAPI do
124     Call(isc_prepare_transaction(StatusVector, @FHandle));
125     end;
126    
127     procedure TFB25Transaction.Commit(Force: boolean);
128     begin
129     if FHandle = nil then
130     Exit;
131     with Firebird25ClientAPI do
132     Call(isc_commit_transaction(StatusVector, @FHandle),not Force);
133     FHandle := nil;
134     end;
135    
136     procedure TFB25Transaction.CommitRetaining;
137     begin
138     if FHandle = nil then
139     Exit;
140     with Firebird25ClientAPI do
141     Call(isc_commit_retaining(StatusVector, @FHandle));
142     end;
143    
144     procedure TFB25Transaction.Start(DefaultCompletion: TTransactionCompletion);
145     var pteb: PISC_TEB_ARRAY;
146     i: integer;
147     db_handle: TISC_DB_HANDLE;
148     begin
149     if FHandle <> nil then
150     Exit;
151     pteb := nil;
152     FDefaultCompletion := DefaultCompletion;
153     with Firebird25ClientAPI do
154     if (Length(FAttachments) = 1) then
155     try
156     db_handle := (FAttachments[0] as TFB25Attachment).Handle;
157     Call(isc_start_transaction(StatusVector, @FHandle,1,
158     @db_handle,(FTPB as TTPB).getDataLength,(FTPB as TTPB).getBuffer));
159     except
160     FHandle := nil;
161     raise;
162     end
163     else
164     begin
165     IBAlloc(pteb, 0, Length(FAttachments) * SizeOf(TISC_TEB));
166     try
167     for i := 0 to Length(FAttachments) - 1 do
168     if (FAttachments[i] <> nil) then
169     begin
170     pteb^[i].db_handle := @((FAttachments[i] as TFB25Attachment).Handle);
171     pteb^[i].tpb_length := (FTPB as TTPB).getDataLength;
172     pteb^[i].tpb_address := (FTPB as TTPB).getBuffer;
173     end;
174     try
175     Call(isc_start_multiple(StatusVector, @FHandle,
176     Length(FAttachments), PISC_TEB(pteb)));
177     except
178     FHandle := nil;
179     raise;
180     end;
181     finally
182     FreeMem(pteb);
183     end;
184     end;
185     Inc(FSeqNo);
186     end;
187    
188     procedure TFB25Transaction.Rollback(Force: boolean);
189     begin
190     if FHandle = nil then
191     Exit;
192     with Firebird25ClientAPI do
193     Call(isc_rollback_transaction(StatusVector, @FHandle),not Force);
194     FHandle := nil;
195     end;
196    
197     procedure TFB25Transaction.RollbackRetaining;
198     begin
199     if FHandle = nil then
200     Exit;
201     with Firebird25ClientAPI do
202     Call(isc_rollback_retaining(StatusVector, @FHandle));
203     end;
204    
205     end.
206