ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/FBAttachment.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/FBAttachment.pas (file contents):
Revision 56 by tony, Mon Mar 6 10:20:02 2017 UTC vs.
Revision 143 by tony, Fri Feb 23 12:11:21 2018 UTC

# Line 32 | Line 32 | unit FBAttachment;
32   {$IFDEF FPC}
33   {$mode delphi}
34   {$interfaces COM}
35 + {$define HASREQEX}
36   {$ENDIF}
37  
38   interface
39  
40   uses
41 <  Classes, SysUtils, IB,  FBParamBlock, FBActivityMonitor;
41 >  Classes, SysUtils, {$IFDEF WINDOWS} windows, {$ENDIF} IB,  FBParamBlock, FBActivityMonitor;
42  
43   type
44 +  TCharsetMap = record
45 +    CharsetID: integer;
46 +    CharSetName: AnsiString;
47 +    CharSetWidth: integer;
48 +    CodePage: TSystemCodePage;
49 +    AllowReverseLookup: boolean; {used to ensure that lookup of CP_UTF* does not return UNICODE_FSS}
50 +  end;
51  
52    { TFBAttachment }
53  
# Line 47 | Line 55 | type
55    private
56      FDPB: IDPB;
57      FFirebirdAPI: IFirebirdAPI;
58 +    FODSMajorVersion: integer;
59 +    FODSMinorVersion: integer;
60 +    FUserCharSetMap: array of TCharSetMap;
61    protected
62      FDatabaseName: AnsiString;
63      FRaiseExceptionOnConnectError: boolean;
# Line 54 | Line 65 | type
65      FHasDefaultCharSet: boolean;
66      FCharSetID: integer;
67      FCodePage: TSystemCodePage;
68 +    FRemoteProtocol: AnsiString;
69 +    FAuthMethod: AnsiString;
70      constructor Create(DatabaseName: AnsiString; DPB: IDPB;
71        RaiseExceptionOnConnectError: boolean);
72      procedure CheckHandle; virtual; abstract;
73      function GenerateCreateDatabaseSQL(DatabaseName: AnsiString; aDPB: IDPB): AnsiString;
74 +    procedure GetODSAndConnectionInfo;
75 +    function GetDBInfo(ReqBuffer: PByte; ReqBufLen: integer): IDBInformation; virtual; abstract;
76 +    function IsConnected: boolean; virtual; abstract;
77      procedure EndAllTransactions;
78 +    procedure DPBFromCreateSQL(CreateSQL: AnsiString);
79      procedure SetParameters(SQLParams: ISQLParams; params: array of const);
80    public
81      destructor Destroy; override;
82      function getDPB: IDPB;
83      function AllocateBPB: IBPB;
84 +    function AllocateDIRB: IDIRB;
85      function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; overload; virtual; abstract;
86      function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; overload; virtual; abstract;
87      procedure Disconnect(Force: boolean=false); virtual; abstract;
# Line 103 | Line 121 | type
121      function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; virtual; abstract;
122      function OpenBlob(transaction: ITransaction; Field: ISQLData; BPB: IBPB=nil): IBlob; overload;
123      property SQLDialect: integer read FSQLDialect;
106    property HasDefaultCharSet: boolean read FHasDefaultCharSet;
107    property CharSetID: integer read FCharSetID;
108    property CodePage: TSystemCodePage read FCodePage;
124      property DPB: IDPB read FDPB;
125 + public
126 +  function GetDBInformation(Requests: array of byte): IDBInformation; overload;
127 +  function GetDBInformation(Request: byte): IDBInformation; overload;
128 +  function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
129 +  function GetConnectString: AnsiString;
130 +  function GetRemoteProtocol: AnsiString;
131 +  function GetAuthenticationMethod: AnsiString;
132 +  function GetODSMajorVersion: integer;
133 +  function GetODSMinorVersion: integer;
134 +  {Character Sets}
135 +  function HasDefaultCharSet: boolean;
136 +  function GetDefaultCharSetID: integer;
137 +  function GetCharsetName(CharSetID: integer): AnsiString;
138 +  function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
139 +  function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
140 +  function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
141 +  function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
142 +  procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage;
143 +    AllowReverseLookup:boolean; out CharSetID: integer);
144 +  property CharSetID: integer read FCharSetID;
145 +  property CodePage: TSystemCodePage read FCodePage;
146    end;
147  
148   implementation
149  
150 < uses FBMessages, FBTransaction;
150 > uses FBMessages, IBUtils, FBTransaction {$IFDEF HASREQEX}, RegExpr{$ENDIF};
151 >
152 > const
153 >  CharSetMap: array [0..69] of TCharsetMap = (
154 >  (CharsetID: 0; CharSetName: 'NONE'; CharSetWidth: 1; CodePage: CP_ACP; AllowReverseLookup: true),
155 >  (CharsetID: 1; CharSetName: 'OCTETS'; CharSetWidth: 1; CodePage: CP_NONE; AllowReverseLookup: true),
156 >  (CharsetID: 2; CharSetName: 'ASCII'; CharSetWidth: 1; CodePage: CP_ASCII; AllowReverseLookup: true),
157 >  (CharsetID: 3; CharSetName: 'UNICODE_FSS'; CharSetWidth: 3; CodePage: CP_UTF8; AllowReverseLookup: false),
158 >  (CharsetID: 4; CharSetName: 'UTF8'; CharSetWidth: 4; CodePage: CP_UTF8; AllowReverseLookup: true),
159 >  (CharsetID: 5; CharSetName: 'SJIS_0208'; CharSetWidth: 2; CodePage: 20932; AllowReverseLookup: true),
160 >  (CharsetID: 6; CharSetName: 'EUCJ_0208'; CharSetWidth: 2; CodePage: 20932; AllowReverseLookup: true),
161 >  (CharsetID: 7; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: true),
162 >  (CharsetID: 8; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: true),
163 >  (CharsetID: 9; CharSetName: 'DOS737'; CharSetWidth: 1; CodePage: 737; AllowReverseLookup: true),
164 >  (CharsetID: 10; CharSetName: 'DOS437'; CharSetWidth: 1; CodePage: 437; AllowReverseLookup: true),
165 >  (CharsetID: 11; CharSetName: 'DOS850'; CharSetWidth: 1; CodePage: 850; AllowReverseLookup: true),
166 >  (CharsetID: 12; CharSetName: 'DOS865'; CharSetWidth: 1; CodePage: 865; AllowReverseLookup: true),
167 >  (CharsetID: 13; CharSetName: 'DOS860'; CharSetWidth: 1; CodePage: 860; AllowReverseLookup: true),
168 >  (CharsetID: 14; CharSetName: 'DOS863'; CharSetWidth: 1; CodePage: 863; AllowReverseLookup: true),
169 >  (CharsetID: 15; CharSetName: 'DOS775'; CharSetWidth: 1; CodePage: 775; AllowReverseLookup: true),
170 >  (CharsetID: 16; CharSetName: 'DOS858'; CharSetWidth: 1; CodePage: 858; AllowReverseLookup: true),
171 >  (CharsetID: 17; CharSetName: 'DOS862'; CharSetWidth: 1; CodePage: 862; AllowReverseLookup: true),
172 >  (CharsetID: 18; CharSetName: 'DOS864'; CharSetWidth: 1; CodePage: 864; AllowReverseLookup: true),
173 >  (CharsetID: 19; CharSetName: 'NEXT'; CharSetWidth: 1; CodePage: CP_NONE; AllowReverseLookup: true),
174 >  (CharsetID: 20; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: true),
175 >  (CharsetID: 21; CharSetName: 'ISO8859_1'; CharSetWidth: 1; CodePage: 28591; AllowReverseLookup: true),
176 >  (CharsetID: 22; CharSetName: 'ISO8859_2'; CharSetWidth: 1; CodePage: 28592; AllowReverseLookup: true),
177 >  (CharsetID: 23; CharSetName: 'ISO8859_3'; CharSetWidth: 1; CodePage: 28593; AllowReverseLookup: true),
178 >  (CharsetID: 24; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
179 >  (CharsetID: 25; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
180 >  (CharsetID: 26; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
181 >  (CharsetID: 27; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
182 >  (CharsetID: 28; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
183 >  (CharsetID: 29; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
184 >  (CharsetID: 30; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
185 >  (CharsetID: 31; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
186 >  (CharsetID: 32; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
187 >  (CharsetID: 33; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
188 >  (CharsetID: 34; CharSetName: 'ISO8859_4'; CharSetWidth: 1; CodePage: 28594; AllowReverseLookup: true),
189 >  (CharsetID: 35; CharSetName: 'ISO8859_5'; CharSetWidth: 1; CodePage: 28595; AllowReverseLookup: true),
190 >  (CharsetID: 36; CharSetName: 'ISO8859_6'; CharSetWidth: 1; CodePage: 28596; AllowReverseLookup: true),
191 >  (CharsetID: 37; CharSetName: 'ISO8859_7'; CharSetWidth: 1; CodePage: 28597; AllowReverseLookup: true),
192 >  (CharsetID: 38; CharSetName: 'ISO8859_8'; CharSetWidth: 1; CodePage: 28598; AllowReverseLookup: true),
193 >  (CharsetID: 39; CharSetName: 'ISO8859_9'; CharSetWidth: 1; CodePage: 28599; AllowReverseLookup: true),
194 >  (CharsetID: 40; CharSetName: 'ISO8859_13'; CharSetWidth: 1; CodePage: 28603; AllowReverseLookup: true),
195 >  (CharsetID: 41; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
196 >  (CharsetID: 42; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
197 >  (CharsetID: 43; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
198 >  (CharsetID: 44; CharSetName: 'KSC_5601'; CharSetWidth: 2; CodePage: 949; AllowReverseLookup: true),
199 >  (CharsetID: 45; CharSetName: 'DOS852'; CharSetWidth: 1; CodePage: 852; AllowReverseLookup: true),
200 >  (CharsetID: 46; CharSetName: 'DOS857'; CharSetWidth: 1; CodePage: 857; AllowReverseLookup: true),
201 >  (CharsetID: 47; CharSetName: 'DOS861'; CharSetWidth: 1; CodePage: 861; AllowReverseLookup: true),
202 >  (CharsetID: 48; CharSetName: 'DOS866'; CharSetWidth: 1; CodePage: 866; AllowReverseLookup: true),
203 >  (CharsetID: 49; CharSetName: 'DOS869'; CharSetWidth: 1; CodePage: 869; AllowReverseLookup: true),
204 >  (CharsetID: 50; CharSetName: 'CYRL'; CharSetWidth: 1; CodePage: 1251; AllowReverseLookup: true),
205 >  (CharsetID: 51; CharSetName: 'WIN1250'; CharSetWidth: 1; CodePage: 1250; AllowReverseLookup: true),
206 >  (CharsetID: 52; CharSetName: 'WIN1251'; CharSetWidth: 1; CodePage: 1251; AllowReverseLookup: true),
207 >  (CharsetID: 53; CharSetName: 'WIN1252'; CharSetWidth: 1; CodePage: 1252; AllowReverseLookup: true),
208 >  (CharsetID: 54; CharSetName: 'WIN1253'; CharSetWidth: 1; CodePage: 1253; AllowReverseLookup: true),
209 >  (CharsetID: 55; CharSetName: 'WIN1254'; CharSetWidth: 1; CodePage: 1254; AllowReverseLookup: true),
210 >  (CharsetID: 56; CharSetName: 'BIG_5'; CharSetWidth: 2; CodePage: 950; AllowReverseLookup: true),
211 >  (CharsetID: 57; CharSetName: 'GB_2312'; CharSetWidth: 2; CodePage: 936; AllowReverseLookup: true),
212 >  (CharsetID: 58; CharSetName: 'WIN1255'; CharSetWidth: 1; CodePage: 1255; AllowReverseLookup: true),
213 >  (CharsetID: 59; CharSetName: 'WIN1256'; CharSetWidth: 1; CodePage: 1256; AllowReverseLookup: true),
214 >  (CharsetID: 60; CharSetName: 'WIN1257'; CharSetWidth: 1; CodePage: 1257; AllowReverseLookup: true),
215 >  (CharsetID: 61; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
216 >  (CharsetID: 62; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
217 >  (CharsetID: 63; CharSetName: 'KOI8R'; CharSetWidth: 1; CodePage: 20866; AllowReverseLookup: true),
218 >  (CharsetID: 64; CharSetName: 'KOI8U'; CharSetWidth: 1; CodePage: 21866; AllowReverseLookup: true),
219 >  (CharsetID: 65; CharSetName: 'WIN1258'; CharSetWidth: 1; CodePage: 1258; AllowReverseLookup: true),
220 >  (CharsetID: 66; CharSetName: 'TIS620'; CharSetWidth: 1; CodePage: 874; AllowReverseLookup: true),
221 >  (CharsetID: 67; CharSetName: 'GBK'; CharSetWidth: 2; CodePage: 936; AllowReverseLookup: true),
222 >  (CharsetID: 68; CharSetName: 'CP943C'; CharSetWidth: 2; CodePage: 943; AllowReverseLookup: true),
223 >  (CharsetID: 69; CharSetName: 'GB18030'; CharSetWidth: 4; CodePage: 54936; AllowReverseLookup: true)
224 > );
225 >
226 >
227 >
228  
229   { TFBAttachment }
230  
231 + procedure TFBAttachment.GetODSAndConnectionInfo;
232 + var DBInfo: IDBInformation;
233 +    i: integer;
234 +    Stmt: IStatement;
235 +    ResultSet: IResultSet;
236 +    Param: IDPBItem;
237 + begin
238 +  if not IsConnected then Exit;
239 +  DBInfo := GetDBInformation([isc_info_db_id,isc_info_ods_version,isc_info_ods_minor_version,
240 +                               isc_info_db_SQL_Dialect]);
241 +  for i := 0 to DBInfo.GetCount - 1 do
242 +    with DBInfo[i] do
243 +      case getItemType of
244 +      isc_info_ods_minor_version:
245 +        FODSMinorVersion := getAsInteger;
246 +      isc_info_ods_version:
247 +        FODSMajorVersion := getAsInteger;
248 +      isc_info_db_SQL_Dialect:
249 +        FSQLDialect := getAsInteger;
250 +      end;
251 +
252 +  FCharSetID := 0;
253 +  FRemoteProtocol := '';
254 +  FAuthMethod := 'Legacy_Auth';
255 +  if FODSMajorVersion > 11 then
256 +  begin
257 +    Stmt := Prepare(StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit),
258 +                    'Select MON$CHARACTER_SET_ID, MON$REMOTE_PROTOCOL, MON$AUTH_METHOD From MON$ATTACHMENTS '+
259 +                    'Where MON$ATTACHMENT_ID = CURRENT_CONNECTION');
260 +    ResultSet := Stmt.OpenCursor;
261 +    if ResultSet.FetchNext then
262 +    begin
263 +      FCharSetID := ResultSet[0].AsInteger;
264 +      FRemoteProtocol := ResultSet[1].AsString;
265 +      FAuthMethod := ResultSet[2].AsString;
266 +    end
267 +  end
268 +  else
269 +  if (FODSMajorVersion = 11) and (FODSMinorVersion >= 1) then
270 +  begin
271 +    Stmt := Prepare(StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit),
272 +                    'Select MON$CHARACTER_SET_ID, MON$REMOTE_PROTOCOL From MON$ATTACHMENTS '+
273 +                    'Where MON$ATTACHMENT_ID = CURRENT_CONNECTION');
274 +    ResultSet := Stmt.OpenCursor;
275 +    if ResultSet.FetchNext then
276 +    begin
277 +      FCharSetID := ResultSet[0].AsInteger;
278 +      FRemoteProtocol := ResultSet[1].AsString;
279 +    end
280 +  end
281 +  else
282 +  if DPB <> nil then
283 +  begin
284 +    Param :=  DPB.Find(isc_dpb_lc_ctype);
285 +    if (Param = nil) or not CharSetName2CharSetID(Param.AsString,FCharSetID) then
286 +      FCharSetID := 0;
287 +    case GetProtocol(FDatabaseName) of
288 +    TCP:       FRemoteProtocol := 'TCPv4';
289 +    Local:     FRemoteProtocol := '';
290 +    NamedPipe: FRemoteProtocol := 'Netbui';
291 +    SPX:       FRemoteProtocol := 'SPX'
292 +    end;
293 +  end;
294 +  FHasDefaultCharSet := CharSetID2CodePage(FCharSetID,FCodePage) and (FCharSetID > 1);
295 + end;
296 +
297   constructor TFBAttachment.Create(DatabaseName: AnsiString; DPB: IDPB;
298    RaiseExceptionOnConnectError: boolean);
299   begin
# Line 123 | Line 302 | begin
302    FSQLDialect := 3;
303    FDatabaseName := DatabaseName;
304    FDPB := DPB;
305 +  SetLength(FUserCharSetMap,0);
306    FRaiseExceptionOnConnectError := RaiseExceptionOnConnectError;
307 +  FODSMajorVersion := 0;
308 +  FODSMinorVersion := 0;
309   end;
310  
311   function TFBAttachment.GenerateCreateDatabaseSQL(DatabaseName: AnsiString;  aDPB: IDPB): AnsiString;
# Line 170 | Line 352 | begin
352    end;
353   end;
354  
355 + {$IFDEF HASREQEX}
356 + procedure TFBAttachment.DPBFromCreateSQL(CreateSQL: AnsiString);
357 + var RegexObj: TRegExpr;
358 + begin
359 +  FDPB := FFirebirdAPI.AllocateDPB;
360 +  RegexObj := TRegExpr.Create;
361 +  try
362 +    {extact database file spec}
363 +    RegexObj.ModifierG := false; {turn off greedy matches}
364 +    RegexObj.ModifierI := true; {case insensitive match}
365 +    RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +''.*'' +USER +''(.+)'' PASSWORD +''(.+)''';
366 +    if RegexObj.Exec(CreateSQL) then
367 +    begin
368 +      DPB.Add(isc_dpb_user_name).AsString := system.copy(CreateSQL,RegexObj.MatchPos[2],RegexObj.MatchLen[2]);
369 +      DPB.Add(isc_dpb_password).AsString := system.copy(CreateSQL,RegexObj.MatchPos[3],RegexObj.MatchLen[3]);
370 +    end
371 +    else
372 +    begin
373 +      RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +(''.*'') +USER +''(.+)''';
374 +      if RegexObj.Exec(CreateSQL) then
375 +        DPB.Add(isc_dpb_user_name).AsString := system.copy(CreateSQL,RegexObj.MatchPos[2],RegexObj.MatchLen[2]);
376 +    end;
377 +  finally
378 +    RegexObj.Free;
379 +  end;
380 +  if FCharSetID > 0 then
381 +    DPB.Add(isc_dpb_lc_ctype).AsString := GetCharSetName(FCharSetID);
382 +  DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(FSQLDialect);
383 + end;
384 + {$ELSE}
385 + procedure TFBAttachment.DPBFromCreateSQL(CreateSQL: AnsiString);
386 + begin
387 +  FDPB := FFirebirdAPI.AllocateDPB;
388 +  if FCharSetID > 0 then
389 +    DPB.Add(isc_dpb_lc_ctype).AsString := GetCharSetName(FCharSetID);
390 +  DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(FSQLDialect);
391 + end;
392 + {$ENDIF}
393 +
394   procedure TFBAttachment.SetParameters(SQLParams: ISQLParams;
395    params: array of const);
396   var i: integer;
# Line 182 | Line 403 | begin
403      case params[i].vtype of
404        vtinteger    :
405          SQLParams[i].AsInteger := params[i].vinteger;
406 +      vtInt64:
407 +        SQLParams[i].AsInt64 := params[i].VInt64^;
408 +      {$IF declared (vtQWord)}
409 +      vtQWord:
410 +        SQLParams[i].AsInt64 := params[i].VQWord^;
411 +      {$IFEND}
412        vtboolean    :
413          SQLParams[i].AsBoolean :=  params[i].vboolean;
414        vtchar       :
# Line 191 | Line 418 | begin
418        vtCurrency:
419          SQLParams[i].AsDouble := params[i].VCurrency^;
420        vtString     :
421 <        SQLParams[i].AsString := params[i].VString^;
421 >        SQLParams[i].AsString := strpas(PChar(params[i].VString));
422        vtPChar      :
423          SQLParams[i].AsString := strpas(params[i].VPChar);
424        vtAnsiString :
425 <        SQLParams[i].AsString := AnsiString(params[i].VAnsiString^);
425 >        SQLParams[i].AsString := strpas(PAnsiChar(params[i].VAnsiString));
426        vtVariant:
427          SQLParams[i].AsVariant := params[i].VVariant^;
428 +      vtWideChar:
429 +        SQLParams[i].AsString := UTF8Encode(WideCharLenToString(@params[i].VWideChar,1));
430 +      vtPWideChar:
431 +        SQLParams[i].AsString := UTF8Encode(strpas(PWideChar(params[i].VPWideChar)));
432 +      vtWideString:
433 +        SQLParams[i].AsString := UTF8Encode(strpas(PWideChar(params[i].VWideString)));
434 +      vtUnicodeString:
435 +        SQLParams[i].AsString := UTF8Encode(strpas(PWideChar(params[i].VUnicodeString)));
436      else
437          IBError(ibxeInvalidVariantType,[nil]);
438      end;
# Line 220 | Line 455 | begin
455    Result := TBPB.Create;
456   end;
457  
458 + function TFBAttachment.AllocateDIRB: IDIRB;
459 + begin
460 +  Result := TDIRB.Create;
461 + end;
462 +
463   procedure TFBAttachment.ExecImmediate(TPB: array of byte; sql: AnsiString;
464    aSQLDialect: integer);
465   begin
# Line 239 | Line 479 | end;
479   function TFBAttachment.ExecuteSQL(TPB: array of byte; sql: AnsiString;
480    SQLDialect: integer; params: array of const): IResults;
481   begin
482 <  Result := ExecuteSQL(StartTransaction(TPB,taCommit),sql,FSQLDialect,params);
482 >  Result := ExecuteSQL(StartTransaction(TPB,taCommit),sql,SQLDialect,params);
483   end;
484  
485   function TFBAttachment.ExecuteSQL(transaction: ITransaction; sql: AnsiString;
# Line 368 | Line 608 | begin
608    Result := OpenBlob(Transaction,Field.GetBlobMetadata, Field.AsQuad,BPB);
609   end;
610  
611 + function TFBAttachment.GetDBInformation(Requests: array of byte
612 +  ): IDBInformation;
613 + var ReqBuffer: PByte;
614 +    i: integer;
615 + begin
616 +  CheckHandle;
617 +  if Length(Requests) = 1 then
618 +    Result := GetDBInformation(Requests[0])
619 +  else
620 +  begin
621 +    GetMem(ReqBuffer,Length(Requests));
622 +    try
623 +      for i := 0 to Length(Requests) - 1 do
624 +        ReqBuffer[i] := Requests[i];
625 +
626 +      Result := GetDBInfo(ReqBuffer,Length(Requests));
627 +
628 +    finally
629 +      FreeMem(ReqBuffer);
630 +    end;
631 +  end;
632 + end;
633 +
634 + function TFBAttachment.GetDBInformation(Request: byte): IDBInformation;
635 + begin
636 +  CheckHandle;
637 +  Result := GetDBInfo(@Request,1);
638 + end;
639 +
640 + function TFBAttachment.GetDBInformation(Requests: IDIRB): IDBInformation;
641 + begin
642 +  CheckHandle;
643 +  with Requests as TDIRB do
644 +    Result := GetDBInfo(getBuffer,getDataLength);
645 + end;
646 +
647 + function TFBAttachment.GetConnectString: AnsiString;
648 + begin
649 +  Result := FDatabaseName;
650 + end;
651 +
652 + function TFBAttachment.GetRemoteProtocol: AnsiString;
653 + begin
654 +  Result := FRemoteProtocol;
655 + end;
656 +
657 + function TFBAttachment.GetAuthenticationMethod: AnsiString;
658 + begin
659 +  Result := FAuthMethod;
660 + end;
661 +
662 + function TFBAttachment.GetODSMajorVersion: integer;
663 + begin
664 +  Result := FODSMajorVersion;
665 + end;
666 +
667 + function TFBAttachment.GetODSMinorVersion: integer;
668 + begin
669 +  Result := FODSMinorVersion;
670 + end;
671 +
672 + function TFBAttachment.HasDefaultCharSet: boolean;
673 + begin
674 +  Result := FHasDefaultCharSet
675 + end;
676 +
677 + function TFBAttachment.GetDefaultCharSetID: integer;
678 + begin
679 +  Result := FCharsetID;
680 + end;
681 +
682 + function TFBAttachment.GetCharsetName(CharSetID: integer): AnsiString;
683 + var i: integer;
684 + begin
685 +  Result := '';
686 +  if (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap)) and
687 +                                  (CharSetMap[CharSetID].CharSetID = CharSetID) then
688 +    begin
689 +      Result := CharSetMap[CharSetID].CharSetName;
690 +      Exit;
691 +    end;
692 +
693 +  for i := 0 to Length(FUserCharSetMap) - 1 do
694 +    if FUserCharSetMap[i].CharSetID = CharSetID then
695 +    begin
696 +      Result := FUserCharSetMap[i].CharSetName;
697 +      Exit;
698 +    end;
699 + end;
700 +
701 + function TFBAttachment.CharSetID2CodePage(CharSetID: integer;
702 +  var CodePage: TSystemCodePage): boolean;
703 + var i: integer;
704 + begin
705 +  Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap))
706 +               and (CharSetMap[CharSetID].CharSetID = CharSetID);
707 +  if Result then
708 +    begin
709 +      CodePage := CharSetMap[CharSetID].CodePage;
710 +      Result := true;
711 +      Exit;
712 +    end;
713 +
714 +  for i := 0 to Length(FUserCharSetMap) - 1 do
715 +    if FUserCharSetMap[i].CharSetID = CharSetID then
716 +    begin
717 +      CodePage := FUserCharSetMap[i].CodePage;
718 +      Result := true;
719 +      Exit;
720 +    end;
721 + end;
722 +
723 + function TFBAttachment.CodePage2CharSetID(CodePage: TSystemCodePage;
724 +  var CharSetID: integer): boolean;
725 + var i: integer;
726 + begin
727 +  Result := false;
728 +  for i := Low(CharSetMap) to High(CharSetMap) do
729 +    if (CharSetMap[i].AllowReverseLookup) and (CharSetMap[i].CodePage = CodePage) then
730 +    begin
731 +      CharSetID := CharSetMap[i].CharSetID;
732 +      Result := true;
733 +      Exit;
734 +    end;
735 +
736 +  for i := 0 to Length(FUserCharSetMap) - 1 do
737 +    if (FUserCharSetMap[i].AllowReverseLookup) and (FUserCharSetMap[i].CodePage = CodePage) then
738 +    begin
739 +      CharSetID := FUserCharSetMap[i].CharSetID;
740 +      Result := true;
741 +      Exit;
742 +    end;
743 + end;
744 +
745 + function TFBAttachment.CharSetName2CharSetID(CharSetName: AnsiString;
746 +  var CharSetID: integer): boolean;
747 + var i: integer;
748 + begin
749 +  Result := false;
750 +  for i := Low(CharSetMap) to High(CharSetMap) do
751 +    if AnsiCompareStr(CharSetMap[i].CharSetName, CharSetName) = 0 then
752 +    begin
753 +      CharSetID := CharSetMap[i].CharSetID;
754 +      Result := true;
755 +      Exit;
756 +    end;
757 +
758 +    for i := 0 to Length(FUserCharSetMap) - 1 do
759 +      if AnsiCompareStr(FUserCharSetMap[i].CharSetName, CharSetName) = 0 then
760 +      begin
761 +        CharSetID := FUserCharSetMap[i].CharSetID;
762 +        Result := true;
763 +        Exit;
764 +      end;
765 + end;
766 +
767 + function TFBAttachment.CharSetWidth(CharSetID: integer; var Width: integer
768 +  ): boolean;
769 + var i: integer;
770 + begin
771 +  Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap))
772 +               and (CharSetMap[CharSetID].CharSetID = CharSetID);
773 +  if Result then
774 +    begin
775 +      Width := CharSetMap[CharSetID].CharSetWidth;
776 +      Result := true;
777 +      Exit;
778 +    end;
779 +
780 +  for i := 0 to Length(FUserCharSetMap) - 1 do
781 +    if FUserCharSetMap[i].CharSetID = CharSetID then
782 +    begin
783 +      Width := FUserCharSetMap[i].CharSetWidth;
784 +      Result := true;
785 +      Exit;
786 +    end;
787 + end;
788 +
789 + const
790 +  sqlLookupCharSet = 'Select RDB$CHARACTER_SET_ID, RDB$BYTES_PER_CHARACTER From RDB$CHARACTER_SETS '+
791 +                     'Where RDB$SYSTEM_FLAG = 0 and RDB$CHARACTER_SET_NAME = UPPER(?)';
792 +
793 + procedure TFBAttachment.RegisterCharSet(CharSetName: AnsiString;
794 +  CodePage: TSystemCodePage; AllowReverseLookup: boolean; out CharSetID: integer
795 +  );
796 + var CharSets: IResultSet;
797 +    idx: integer;
798 + begin
799 +  if CharSetName2CharSetID(CharSetName,CharSetID) then
800 +    IBError(ibxeCharacterSetExists,[CharSetName]);
801 +
802 +  CharSets := OpenCursorAtStart(sqlLookupCharSet,[CharSetName]);
803 +  if CharSets.IsEof then
804 +    IBError(ibxeUnknownUserCharSet,[CharSetName]);
805 +
806 +  idx := Length(FUserCharSetMap);
807 +  SetLength(FUserCharSetMap,idx+1);
808 +  FUserCharSetMap[idx].AllowReverseLookup := AllowReverseLookup;
809 +  FUserCharSetMap[idx].CharSetID := CharSets[0].AsInteger;
810 +  FUserCharSetMap[idx].CharSetName := AnsiUpperCase(CharSetName);
811 +  FUserCharSetMap[idx].CharSetWidth := CharSets[1].AsInteger;
812 +  FUserCharSetMap[idx].CodePage := CodePage;
813 +  CharSetID := CharSets[0].AsInteger;
814 + end;
815 +
816   end.
817  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines