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

Comparing ibx/trunk/fbintf/client/3.0/FB30Attachment.pas (file contents):
Revision 60 by tony, Mon Mar 27 15:21:02 2017 UTC vs.
Revision 270 by tony, Fri Jan 18 11:10:37 2019 UTC

# Line 46 | Line 46 | type
46    TFB30Attachment = class(TFBAttachment,IAttachment, IActivityMonitor)
47    private
48      FAttachmentIntf: Firebird.IAttachment;
49 +    FFirebird30ClientAPI: TFB30ClientAPI;
50    protected
51      procedure CheckHandle; override;
52    public
53 <    constructor Create(DatabaseName: AnsiString; aDPB: IDPB;
53 >    constructor Create(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB;
54            RaiseExceptionOnConnectError: boolean);
55 <    constructor CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean);  overload;
56 <    constructor CreateDatabase(sql: AnsiString; aSQLDialect: integer;
55 >    constructor CreateDatabase(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean);  overload;
56 >    constructor CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer;
57        RaiseExceptionOnError: boolean); overload;
58      destructor Destroy; override;
59 +    function GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation;
60 +      override;
61      property AttachmentIntf: Firebird.IAttachment read FAttachmentIntf;
62 +    property Firebird30ClientAPI: TFB30ClientAPI read FFirebird30ClientAPI;
63  
64    public
65      {IAttachment}
66      procedure Connect;
67      procedure Disconnect(Force: boolean=false); override;
68 <    function IsConnected: boolean;
68 >    function IsConnected: boolean; override;
69      procedure DropDatabase;
70      function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; override;
71      function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; override;
72      procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); override;
73      function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; override;
74      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
75 <                       aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; override;
75 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
76 >                       CaseSensitiveParams: boolean=false): IStatement; override;
77  
78      {Events}
79      function GetEventHandler(Events: TStrings): IEvents; override;
# Line 87 | Line 92 | type
92      function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
93      function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString;
94        columnName: AnsiString; Scale: integer; size: cardinal; aCharSetID: cardinal;
95 <  dimensions: cardinal; bounds: TArrayBounds): IArrayMetaData;
95 >      dimensions: cardinal; bounds: TArrayBounds): IArrayMetaData;
96  
97  
98      {Database Information}
99      function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData;
100      function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
101 <    function GetDBInformation(Requests: array of byte): IDBInformation; overload;
97 <    function GetDBInformation(Request: byte): IDBInformation; overload;
101 >    procedure getFBVersion(version: TStrings);
102    end;
103  
104   implementation
105  
106   uses FB30Transaction, FB30Statement, FB30Array, FB30Blob, FBMessages,
107 <  FBOutputBlock, FB30Events;
107 >  FBOutputBlock, FB30Events, IBUtils;
108 >
109 > type
110 >  { TVersionCallback }
111 >
112 >  TVersionCallback = class(Firebird.IVersionCallbackImpl)
113 >  private
114 >    FOutput: TStrings;
115 >  public
116 >    constructor Create(output: TStrings);
117 >    procedure callback(status: Firebird.IStatus; text: PAnsiChar); override;
118 >  end;
119 >
120 > { TVersionCallback }
121 >
122 > constructor TVersionCallback.Create(output: TStrings);
123 > begin
124 >  inherited Create;
125 >  FOutput := output;
126 > end;
127 >
128 > procedure TVersionCallback.callback(status: Firebird.IStatus; text: PAnsiChar);
129 > begin
130 >  FOutput.Add(text);
131 > end;
132 >
133  
134   { TFB30Attachment }
135  
# Line 110 | Line 139 | begin
139      IBError(ibxeDatabaseClosed,[nil]);
140   end;
141  
142 < constructor TFB30Attachment.Create(DatabaseName: AnsiString; aDPB: IDPB;
142 > constructor TFB30Attachment.Create(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB;
143    RaiseExceptionOnConnectError: boolean);
144   begin
145 +  FFirebird30ClientAPI := api;
146    if aDPB = nil then
147    begin
148      if RaiseExceptionOnConnectError then
149         IBError(ibxeNoDPB,[nil]);
150      Exit;
151    end;
152 <  inherited Create(DatabaseName,aDPB,RaiseExceptionOnConnectError);
152 >  inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnConnectError);
153    Connect;
154   end;
155  
156 < constructor TFB30Attachment.CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB;
156 > constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; DatabaseName: AnsiString; aDPB: IDPB;
157    RaiseExceptionOnError: boolean);
158   var Param: IDPBItem;
159      sql: AnsiString;
160      IsCreateDB: boolean;
161   begin
162 <  inherited Create(DatabaseName,aDPB,RaiseExceptionOnError);
162 >  inherited Create(api,DatabaseName,aDPB,RaiseExceptionOnError);
163 >  FFirebird30ClientAPI := api;
164    IsCreateDB := true;
165    if aDPB <> nil then
166    begin
# Line 138 | Line 169 | begin
169        FSQLDialect := Param.AsByte;
170    end;
171    sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB);
172 <  with Firebird30ClientAPI do
172 >  with FFirebird30ClientAPI do
173    begin
174      FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql),
175                                         PAnsiChar(sql),FSQLDialect,@IsCreateDB);
# Line 151 | Line 182 | begin
182      begin
183        Disconnect;
184        Connect;
185 <    end;
185 >    end
186 >    else
187 >      GetODSAndConnectionInfo;
188    end;
189   end;
190  
191 < constructor TFB30Attachment.CreateDatabase(sql: AnsiString; aSQLDialect: integer;
191 > constructor TFB30Attachment.CreateDatabase(api: TFB30ClientAPI; sql: AnsiString; aSQLDialect: integer;
192    RaiseExceptionOnError: boolean);
193   var IsCreateDB: boolean;
161    info: IDBInformation;
162    ConnectionType: integer;
163    SiteName: AnsiString;
194   begin
195 <  inherited Create('',nil,RaiseExceptionOnError);
195 >  inherited Create(api,'',nil,RaiseExceptionOnError);
196 >  FFirebird30ClientAPI := api;
197    FSQLDialect := aSQLDialect;
198 <  with Firebird30ClientAPI do
198 >  with FFirebird30ClientAPI do
199    begin
200      FAttachmentIntf := UtilIntf.executeCreateDatabase(StatusIntf,Length(sql),
201                                         PAnsiChar(sql),aSQLDialect,@IsCreateDB);
202      if FRaiseExceptionOnConnectError then Check4DataBaseError;
203      if InErrorState then
204        FAttachmentIntf := nil;
174    FCharSetID := 0;
175    FCodePage := CP_NONE;
176    FHasDefaultCharSet := false;
177    info := GetDBInformation(isc_info_db_id);
178    info[0].DecodeIDCluster(ConnectionType,FDatabaseName,SiteName);
205    end;
206 +  GetODSAndConnectionInfo;
207 +  ExtractConnectString(sql,FDatabaseName);
208 +  DPBFromCreateSQL(sql);
209   end;
210  
211   destructor TFB30Attachment.Destroy;
# Line 186 | Line 215 | begin
215      FAttachmentIntf.release;
216   end;
217  
218 + function TFB30Attachment.GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation;
219 + begin
220 +  Result := TDBInformation.Create(Firebird30ClientAPI);
221 +  with FFirebird30ClientAPI, Result as TDBInformation do
222 +  begin
223 +    FAttachmentIntf.getInfo(StatusIntf, ReqBufLen, BytePtr(ReqBuffer),
224 +                               getBufSize, BytePtr(Buffer));
225 +      Check4DataBaseError;
226 +  end
227 + end;
228 +
229   procedure TFB30Attachment.Connect;
190 var Param: IDPBItem;
230   begin
231 <  with Firebird30ClientAPI do
231 >  with FFirebird30ClientAPI do
232    begin
233      FAttachmentIntf := ProviderIntf.attachDatabase(StatusIntf,PAnsiChar(FDatabaseName),
234                           (DPB as TDPB).getDataLength,
# Line 198 | Line 237 | begin
237      if InErrorState then
238        FAttachmentIntf := nil
239      else
240 <    begin
202 <      Param := DPB.Find(isc_dpb_set_db_SQL_dialect);
203 <      if Param <> nil then
204 <        FSQLDialect := Param.AsByte;
205 <      Param :=  DPB.Find(isc_dpb_lc_ctype);
206 <      FHasDefaultCharSet :=  (Param <> nil) and
207 <                             CharSetName2CharSetID(Param.AsString,FCharSetID) and
208 <                             CharSetID2CodePage(FCharSetID,FCodePage) and
209 <                             (FCharSetID > 1);
210 <    end;
240 >      GetODSAndConnectionInfo;
241    end;
242   end;
243  
244   procedure TFB30Attachment.Disconnect(Force: boolean);
245   begin
246    if IsConnected then
247 <    with Firebird30ClientAPI do
247 >    with FFirebird30ClientAPI do
248      begin
249        EndAllTransactions;
250        FAttachmentIntf.Detach(StatusIntf);
# Line 235 | Line 265 | end;
265   procedure TFB30Attachment.DropDatabase;
266   begin
267    if IsConnected then
268 <    with Firebird30ClientAPI do
268 >    with FFirebird30ClientAPI do
269      begin
270        EndAllTransactions;
271        FAttachmentIntf.dropDatabase(StatusIntf);
# Line 248 | Line 278 | function TFB30Attachment.StartTransactio
278    DefaultCompletion: TTransactionCompletion): ITransaction;
279   begin
280    CheckHandle;
281 <  Result := TFB30Transaction.Create(self,TPB,DefaultCompletion);
281 >  Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion);
282   end;
283  
284   function TFB30Attachment.StartTransaction(TPB: ITPB;
285    DefaultCompletion: TTransactionCompletion): ITransaction;
286   begin
287    CheckHandle;
288 <  Result := TFB30Transaction.Create(self,TPB,DefaultCompletion);
288 >  Result := TFB30Transaction.Create(FFirebird30ClientAPI,self,TPB,DefaultCompletion);
289   end;
290  
291   procedure TFB30Attachment.ExecImmediate(transaction: ITransaction; sql: AnsiString;
292    aSQLDialect: integer);
293   begin
294    CheckHandle;
295 <  with Firebird30ClientAPI do
295 >  with FFirebird30ClientAPI do
296    begin
297      FAttachmentIntf.execute(StatusIntf,(transaction as TFB30Transaction).TransactionIntf,
298                      Length(sql),PAnsiChar(sql),aSQLDialect,nil,nil,nil,nil);
# Line 278 | Line 308 | begin
308   end;
309  
310   function TFB30Attachment.PrepareWithNamedParameters(transaction: ITransaction;
311 <  sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean): IStatement;
311 >  sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean;
312 >  CaseSensitiveParams: boolean): IStatement;
313   begin
314    CheckHandle;
315    Result := TFB30Statement.CreateWithParameterNames(self,transaction,sql,aSQLDialect,
316 <         GenerateParamNames);
316 >         GenerateParamNames,CaseSensitiveParams);
317   end;
318  
319   function TFB30Attachment.GetEventHandler(Events: TStrings): IEvents;
# Line 373 | Line 404 | begin
404    Result := TFB30ArrayMetaData.Create(self,Transaction as TFB30Transaction,tableName,columnName);
405   end;
406  
407 < function TFB30Attachment.GetDBInformation(Requests: array of byte
408 <  ): IDBInformation;
378 < var ReqBuffer: PByte;
379 <    i: integer;
407 > procedure TFB30Attachment.getFBVersion(version: TStrings);
408 > var bufferObj: TVersionCallback;
409   begin
410 <  CheckHandle;
411 <  if Length(Requests) = 1 then
412 <    Result := GetDBInformation(Requests[0])
413 <  else
414 <  begin
415 <    Result := TDBInformation.Create;
416 <    GetMem(ReqBuffer,Length(Requests));
388 <    try
389 <      for i := 0 to Length(Requests) - 1 do
390 <        ReqBuffer[i] := Requests[i];
391 <
392 <      with Firebird30ClientAPI, Result as TDBInformation do
393 <      begin
394 <        FAttachmentIntf.getInfo(StatusIntf, Length(Requests), BytePtr(ReqBuffer),
395 <                                 getBufSize, BytePtr(Buffer));
396 <          Check4DataBaseError;
397 <      end
398 <
399 <    finally
400 <      FreeMem(ReqBuffer);
410 >  version.Clear;
411 >  bufferObj := TVersionCallback.Create(version);
412 >  try
413 >    with FFirebird30ClientAPI do
414 >    begin
415 >       UtilIntf.getFbVersion(StatusIntf,FAttachmentIntf,bufferObj);
416 >       Check4DataBaseError;
417      end;
418 <  end;
419 < end;
404 <
405 < function TFB30Attachment.GetDBInformation(Request: byte): IDBInformation;
406 < begin
407 <  CheckHandle;
408 <  Result := TDBInformation.Create;
409 <  with Firebird30ClientAPI, Result as TDBInformation do
410 <  begin
411 <    FAttachmentIntf.getInfo(StatusIntf, 1, BytePtr(@Request),
412 <                           getBufSize, BytePtr(Buffer));
413 <      Check4DataBaseError;
418 >  finally
419 >    bufferObj.Free;
420    end;
421   end;
422  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines