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

Comparing ibx/trunk/fbintf/client/FBAttachment.pas (file contents):
Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 109 by tony, Thu Jan 18 14:37:48 2018 UTC

# Line 25 | Line 25
25   *
26   *)
27   unit FBAttachment;
28 + {$IFDEF MSWINDOWS}
29 + {$DEFINE WINDOWS}
30 + {$ENDIF}
31  
32   {$IFDEF FPC}
33 < {$mode objfpc}{$H+}
33 > {$mode delphi}
34   {$interfaces COM}
35   {$ENDIF}
36  
37   interface
38  
39   uses
40 <  Classes, SysUtils, IB,  FBParamBlock, FBActivityMonitor;
40 >  Classes, SysUtils, {$IFDEF WINDOWS} windows, {$ENDIF} IB,  FBParamBlock, FBActivityMonitor;
41  
42   type
43 +  TCharsetMap = record
44 +    CharsetID: integer;
45 +    CharSetName: AnsiString;
46 +    CharSetWidth: integer;
47 +    CodePage: TSystemCodePage;
48 +    AllowReverseLookup: boolean; {used to ensure that lookup of CP_UTF* does not return UNICODE_FSS}
49 +  end;
50  
51    { TFBAttachment }
52  
# Line 44 | Line 54 | type
54    private
55      FDPB: IDPB;
56      FFirebirdAPI: IFirebirdAPI;
57 +    FUserCharSetMap: array of TCharSetMap;
58    protected
59 <    FDatabaseName: string;
59 >    FDatabaseName: AnsiString;
60      FRaiseExceptionOnConnectError: boolean;
61      FSQLDialect: integer;
62      FHasDefaultCharSet: boolean;
63      FCharSetID: integer;
64      FCodePage: TSystemCodePage;
65 <    constructor Create(DatabaseName: string; DPB: IDPB;
65 >    constructor Create(DatabaseName: AnsiString; DPB: IDPB;
66        RaiseExceptionOnConnectError: boolean);
67      procedure CheckHandle; virtual; abstract;
68 <    function GenerateCreateDatabaseSQL(DatabaseName: string; aDPB: IDPB): string;
68 >    function GenerateCreateDatabaseSQL(DatabaseName: AnsiString; aDPB: IDPB): AnsiString;
69      procedure EndAllTransactions;
70      procedure SetParameters(SQLParams: ISQLParams; params: array of const);
71    public
# Line 64 | Line 75 | type
75      function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; overload; virtual; abstract;
76      function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; overload; virtual; abstract;
77      procedure Disconnect(Force: boolean=false); virtual; abstract;
78 <    procedure ExecImmediate(transaction: ITransaction; sql: string; aSQLDialect: integer); overload; virtual; abstract;
79 <    procedure ExecImmediate(TPB: array of byte; sql: string; aSQLDialect: integer); overload;
80 <    procedure ExecImmediate(transaction: ITransaction; sql: string); overload;
81 <    procedure ExecImmediate(TPB: array of byte; sql: string); overload;
82 <    function ExecuteSQL(TPB: array of byte; sql: string; SQLDialect: integer; params: array of const): IResults; overload;
83 <    function ExecuteSQL(transaction: ITransaction; sql: string; SQLDialect: integer; params: array of const): IResults; overload;
84 <    function ExecuteSQL(TPB: array of byte; sql: string; params: array of const): IResults; overload;
85 <    function ExecuteSQL(transaction: ITransaction; sql: string; params: array of const): IResults; overload;
86 <    function OpenCursor(transaction: ITransaction; sql: string; aSQLDialect: integer): IResultSet; overload;
87 <    function OpenCursor(transaction: ITransaction; sql: string; aSQLDialect: integer;
78 >    procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); overload; virtual; abstract;
79 >    procedure ExecImmediate(TPB: array of byte; sql: AnsiString; aSQLDialect: integer); overload;
80 >    procedure ExecImmediate(transaction: ITransaction; sql: AnsiString); overload;
81 >    procedure ExecImmediate(TPB: array of byte; sql: AnsiString); overload;
82 >    function ExecuteSQL(TPB: array of byte; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
83 >    function ExecuteSQL(transaction: ITransaction; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
84 >    function ExecuteSQL(TPB: array of byte; sql: AnsiString; params: array of const): IResults; overload;
85 >    function ExecuteSQL(transaction: ITransaction; sql: AnsiString; params: array of const): IResults; overload;
86 >    function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
87 >    function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
88                               params: array of const): IResultSet; overload;
89 <    function OpenCursor(transaction: ITransaction; sql: string): IResultSet; overload;
90 <    function OpenCursor(transaction: ITransaction; sql: string;
89 >    function OpenCursor(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
90 >    function OpenCursor(transaction: ITransaction; sql: AnsiString;
91                               params: array of const): IResultSet; overload;
92 <    function OpenCursorAtStart(transaction: ITransaction; sql: string; aSQLDialect: integer): IResultSet; overload;
93 <    function OpenCursorAtStart(transaction: ITransaction; sql: string; aSQLDialect: integer;
92 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
93 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
94                               params: array of const): IResultSet; overload;
95 <    function OpenCursorAtStart(transaction: ITransaction; sql: string): IResultSet; overload;
96 <    function OpenCursorAtStart(transaction: ITransaction; sql: string;
95 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
96 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString;
97                               params: array of const): IResultSet; overload;
98 <    function OpenCursorAtStart(sql: string): IResultSet; overload;
99 <    function OpenCursorAtStart(sql: string;
98 >    function OpenCursorAtStart(sql: AnsiString): IResultSet; overload;
99 >    function OpenCursorAtStart(sql: AnsiString;
100                               params: array of const): IResultSet; overload;
101 <    function Prepare(transaction: ITransaction; sql: string; aSQLDialect: integer): IStatement; overload; virtual; abstract;
102 <    function Prepare(transaction: ITransaction; sql: string): IStatement; overload;
103 <    function PrepareWithNamedParameters(transaction: ITransaction; sql: string;
101 >    function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload; virtual; abstract;
102 >    function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
103 >    function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
104                         aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload; virtual; abstract;
105 <    function PrepareWithNamedParameters(transaction: ITransaction; sql: string;
105 >    function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
106                         GenerateParamNames: boolean=false): IStatement; overload;
107      function GetEventHandler(Events: TStrings): IEvents; overload; virtual; abstract;
108 <    function GetEventHandler(Event: string): IEvents; overload;
108 >    function GetEventHandler(Event: AnsiString): IEvents; overload;
109  
110      function GetSQLDialect: integer;
111 <    function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; virtual; abstract; overload;
111 >    function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; virtual; abstract;
112      function OpenBlob(transaction: ITransaction; Field: ISQLData; BPB: IBPB=nil): IBlob; overload;
113      property SQLDialect: integer read FSQLDialect;
103    property HasDefaultCharSet: boolean read FHasDefaultCharSet;
104    property CharSetID: integer read FCharSetID;
105    property CodePage: TSystemCodePage read FCodePage;
114      property DPB: IDPB read FDPB;
115 + public
116 +    {Character Sets}
117 +  function HasDefaultCharSet: boolean;
118 +  function GetDefaultCharSetID: integer;
119 +  function GetCharsetName(CharSetID: integer): AnsiString;
120 +  function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
121 +  function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
122 +  function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
123 +  function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
124 +  procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage;
125 +    AllowReverseLookup:boolean; out CharSetID: integer);
126 +  property CharSetID: integer read FCharSetID;
127 +  property CodePage: TSystemCodePage read FCodePage;
128    end;
129  
130   implementation
131  
132   uses FBMessages, FBTransaction;
133  
134 + const
135 +  CharSetMap: array [0..69] of TCharsetMap = (
136 +  (CharsetID: 0; CharSetName: 'NONE'; CharSetWidth: 1; CodePage: CP_ACP; AllowReverseLookup: true),
137 +  (CharsetID: 1; CharSetName: 'OCTETS'; CharSetWidth: 1; CodePage: CP_NONE; AllowReverseLookup: true),
138 +  (CharsetID: 2; CharSetName: 'ASCII'; CharSetWidth: 1; CodePage: CP_ASCII; AllowReverseLookup: true),
139 +  (CharsetID: 3; CharSetName: 'UNICODE_FSS'; CharSetWidth: 3; CodePage: CP_UTF8; AllowReverseLookup: false),
140 +  (CharsetID: 4; CharSetName: 'UTF8'; CharSetWidth: 4; CodePage: CP_UTF8; AllowReverseLookup: true),
141 +  (CharsetID: 5; CharSetName: 'SJIS_0208'; CharSetWidth: 2; CodePage: 20932; AllowReverseLookup: true),
142 +  (CharsetID: 6; CharSetName: 'EUCJ_0208'; CharSetWidth: 2; CodePage: 20932; AllowReverseLookup: true),
143 +  (CharsetID: 7; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: true),
144 +  (CharsetID: 8; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: true),
145 +  (CharsetID: 9; CharSetName: 'DOS737'; CharSetWidth: 1; CodePage: 737; AllowReverseLookup: true),
146 +  (CharsetID: 10; CharSetName: 'DOS437'; CharSetWidth: 1; CodePage: 437; AllowReverseLookup: true),
147 +  (CharsetID: 11; CharSetName: 'DOS850'; CharSetWidth: 1; CodePage: 850; AllowReverseLookup: true),
148 +  (CharsetID: 12; CharSetName: 'DOS865'; CharSetWidth: 1; CodePage: 865; AllowReverseLookup: true),
149 +  (CharsetID: 13; CharSetName: 'DOS860'; CharSetWidth: 1; CodePage: 860; AllowReverseLookup: true),
150 +  (CharsetID: 14; CharSetName: 'DOS863'; CharSetWidth: 1; CodePage: 863; AllowReverseLookup: true),
151 +  (CharsetID: 15; CharSetName: 'DOS775'; CharSetWidth: 1; CodePage: 775; AllowReverseLookup: true),
152 +  (CharsetID: 16; CharSetName: 'DOS858'; CharSetWidth: 1; CodePage: 858; AllowReverseLookup: true),
153 +  (CharsetID: 17; CharSetName: 'DOS862'; CharSetWidth: 1; CodePage: 862; AllowReverseLookup: true),
154 +  (CharsetID: 18; CharSetName: 'DOS864'; CharSetWidth: 1; CodePage: 864; AllowReverseLookup: true),
155 +  (CharsetID: 19; CharSetName: 'NEXT'; CharSetWidth: 1; CodePage: CP_NONE; AllowReverseLookup: true),
156 +  (CharsetID: 20; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: true),
157 +  (CharsetID: 21; CharSetName: 'ISO8859_1'; CharSetWidth: 1; CodePage: 28591; AllowReverseLookup: true),
158 +  (CharsetID: 22; CharSetName: 'ISO8859_2'; CharSetWidth: 1; CodePage: 28592; AllowReverseLookup: true),
159 +  (CharsetID: 23; CharSetName: 'ISO8859_3'; CharSetWidth: 1; CodePage: 28593; AllowReverseLookup: true),
160 +  (CharsetID: 24; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
161 +  (CharsetID: 25; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
162 +  (CharsetID: 26; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
163 +  (CharsetID: 27; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
164 +  (CharsetID: 28; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
165 +  (CharsetID: 29; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
166 +  (CharsetID: 30; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
167 +  (CharsetID: 31; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
168 +  (CharsetID: 32; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
169 +  (CharsetID: 33; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
170 +  (CharsetID: 34; CharSetName: 'ISO8859_4'; CharSetWidth: 1; CodePage: 28594; AllowReverseLookup: true),
171 +  (CharsetID: 35; CharSetName: 'ISO8859_5'; CharSetWidth: 1; CodePage: 28595; AllowReverseLookup: true),
172 +  (CharsetID: 36; CharSetName: 'ISO8859_6'; CharSetWidth: 1; CodePage: 28596; AllowReverseLookup: true),
173 +  (CharsetID: 37; CharSetName: 'ISO8859_7'; CharSetWidth: 1; CodePage: 28597; AllowReverseLookup: true),
174 +  (CharsetID: 38; CharSetName: 'ISO8859_8'; CharSetWidth: 1; CodePage: 28598; AllowReverseLookup: true),
175 +  (CharsetID: 39; CharSetName: 'ISO8859_9'; CharSetWidth: 1; CodePage: 28599; AllowReverseLookup: true),
176 +  (CharsetID: 40; CharSetName: 'ISO8859_13'; CharSetWidth: 1; CodePage: 28603; AllowReverseLookup: true),
177 +  (CharsetID: 41; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
178 +  (CharsetID: 42; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
179 +  (CharsetID: 43; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
180 +  (CharsetID: 44; CharSetName: 'KSC_5601'; CharSetWidth: 2; CodePage: 949; AllowReverseLookup: true),
181 +  (CharsetID: 45; CharSetName: 'DOS852'; CharSetWidth: 1; CodePage: 852; AllowReverseLookup: true),
182 +  (CharsetID: 46; CharSetName: 'DOS857'; CharSetWidth: 1; CodePage: 857; AllowReverseLookup: true),
183 +  (CharsetID: 47; CharSetName: 'DOS861'; CharSetWidth: 1; CodePage: 861; AllowReverseLookup: true),
184 +  (CharsetID: 48; CharSetName: 'DOS866'; CharSetWidth: 1; CodePage: 866; AllowReverseLookup: true),
185 +  (CharsetID: 49; CharSetName: 'DOS869'; CharSetWidth: 1; CodePage: 869; AllowReverseLookup: true),
186 +  (CharsetID: 50; CharSetName: 'CYRL'; CharSetWidth: 1; CodePage: 1251; AllowReverseLookup: true),
187 +  (CharsetID: 51; CharSetName: 'WIN1250'; CharSetWidth: 1; CodePage: 1250; AllowReverseLookup: true),
188 +  (CharsetID: 52; CharSetName: 'WIN1251'; CharSetWidth: 1; CodePage: 1251; AllowReverseLookup: true),
189 +  (CharsetID: 53; CharSetName: 'WIN1252'; CharSetWidth: 1; CodePage: 1252; AllowReverseLookup: true),
190 +  (CharsetID: 54; CharSetName: 'WIN1253'; CharSetWidth: 1; CodePage: 1253; AllowReverseLookup: true),
191 +  (CharsetID: 55; CharSetName: 'WIN1254'; CharSetWidth: 1; CodePage: 1254; AllowReverseLookup: true),
192 +  (CharsetID: 56; CharSetName: 'BIG_5'; CharSetWidth: 2; CodePage: 950; AllowReverseLookup: true),
193 +  (CharsetID: 57; CharSetName: 'GB_2312'; CharSetWidth: 2; CodePage: 936; AllowReverseLookup: true),
194 +  (CharsetID: 58; CharSetName: 'WIN1255'; CharSetWidth: 1; CodePage: 1255; AllowReverseLookup: true),
195 +  (CharsetID: 59; CharSetName: 'WIN1256'; CharSetWidth: 1; CodePage: 1256; AllowReverseLookup: true),
196 +  (CharsetID: 60; CharSetName: 'WIN1257'; CharSetWidth: 1; CodePage: 1257; AllowReverseLookup: true),
197 +  (CharsetID: 61; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
198 +  (CharsetID: 62; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE; AllowReverseLookup: false),
199 +  (CharsetID: 63; CharSetName: 'KOI8R'; CharSetWidth: 1; CodePage: 20866; AllowReverseLookup: true),
200 +  (CharsetID: 64; CharSetName: 'KOI8U'; CharSetWidth: 1; CodePage: 21866; AllowReverseLookup: true),
201 +  (CharsetID: 65; CharSetName: 'WIN1258'; CharSetWidth: 1; CodePage: 1258; AllowReverseLookup: true),
202 +  (CharsetID: 66; CharSetName: 'TIS620'; CharSetWidth: 1; CodePage: 874; AllowReverseLookup: true),
203 +  (CharsetID: 67; CharSetName: 'GBK'; CharSetWidth: 2; CodePage: 936; AllowReverseLookup: true),
204 +  (CharsetID: 68; CharSetName: 'CP943C'; CharSetWidth: 2; CodePage: 943; AllowReverseLookup: true),
205 +  (CharsetID: 69; CharSetName: 'GB18030'; CharSetWidth: 4; CodePage: 54936; AllowReverseLookup: true)
206 + );
207 +
208 +
209 +
210 +
211   { TFBAttachment }
212  
213 < constructor TFBAttachment.Create(DatabaseName: string; DPB: IDPB;
213 > constructor TFBAttachment.Create(DatabaseName: AnsiString; DPB: IDPB;
214    RaiseExceptionOnConnectError: boolean);
215   begin
216    inherited Create;
# Line 120 | Line 218 | begin
218    FSQLDialect := 3;
219    FDatabaseName := DatabaseName;
220    FDPB := DPB;
221 +  SetLength(FUserCharSetMap,0);
222    FRaiseExceptionOnConnectError := RaiseExceptionOnConnectError;
223   end;
224  
225 < function TFBAttachment.GenerateCreateDatabaseSQL(DatabaseName: string;  aDPB: IDPB): string;
226 < var CreateParams: string;
225 > function TFBAttachment.GenerateCreateDatabaseSQL(DatabaseName: AnsiString;  aDPB: IDPB): AnsiString;
226 > var CreateParams: AnsiString;
227      DPBItem: IDPBItem;
228   begin
229    CreateParams := '';
# Line 133 | Line 232 | begin
232    begin
233      DPBItem :=  aDPB.Find(isc_dpb_user_name);
234      if DPBItem <> nil then
235 <      CreateParams += ' USER ''' + DPBItem.AsString + '''';
235 >      CreateParams := CreateParams + ' USER ''' + DPBItem.AsString + '''';
236  
237      DPBItem :=  aDPB.Find(isc_dpb_password);
238      if DPBItem <> nil then
239 <      CreateParams += ' Password ''' + DPBItem.AsString + '''';
239 >      CreateParams := CreateParams + ' Password ''' + DPBItem.AsString + '''';
240  
241      DPBItem :=  aDPB.Find(isc_dpb_page_size);
242      if DPBItem <> nil then
243 <      CreateParams += ' PAGE_SIZE ' + DPBItem.AsString;
243 >      CreateParams := CreateParams + ' PAGE_SIZE ' + DPBItem.AsString;
244  
245      DPBItem :=  aDPB.Find(isc_dpb_lc_ctype);
246      if DPBItem <> nil then
247 <      CreateParams += ' DEFAULT CHARACTER SET ' + DPBItem.AsString;
247 >      CreateParams := CreateParams + ' DEFAULT CHARACTER SET ' + DPBItem.AsString;
248  
249      DPBItem :=  aDPB.Find(isc_dpb_sql_dialect);
250      if DPBItem <> nil then
# Line 179 | Line 278 | begin
278      case params[i].vtype of
279        vtinteger    :
280          SQLParams[i].AsInteger := params[i].vinteger;
281 +      vtInt64:
282 +        SQLParams[i].AsInt64 := params[i].VInt64^;
283 +      {$IF declared (vtQWord)}
284 +      vtQWord:
285 +        SQLParams[i].AsInt64 := params[i].VQWord^;
286 +      {$IFEND}
287        vtboolean    :
288          SQLParams[i].AsBoolean :=  params[i].vboolean;
289        vtchar       :
# Line 188 | Line 293 | begin
293        vtCurrency:
294          SQLParams[i].AsDouble := params[i].VCurrency^;
295        vtString     :
296 <        SQLParams[i].AsString := params[i].VString^;
296 >        SQLParams[i].AsString := strpas(PChar(params[i].VString));
297        vtPChar      :
298          SQLParams[i].AsString := strpas(params[i].VPChar);
299        vtAnsiString :
300 <        SQLParams[i].AsString := AnsiString(params[i].VAnsiString^);
300 >        SQLParams[i].AsString := strpas(PAnsiChar(params[i].VAnsiString));
301        vtVariant:
302          SQLParams[i].AsVariant := params[i].VVariant^;
303 +      vtWideChar:
304 +        SQLParams[i].AsString := UTF8Encode(WideCharLenToString(@params[i].VWideChar,1));
305 +      vtPWideChar:
306 +        SQLParams[i].AsString := UTF8Encode(strpas(PWideChar(params[i].VPWideChar)));
307 +      vtWideString:
308 +        SQLParams[i].AsString := UTF8Encode(strpas(PWideChar(params[i].VWideString)));
309 +      vtUnicodeString:
310 +        SQLParams[i].AsString := UTF8Encode(strpas(PWideChar(params[i].VUnicodeString)));
311      else
312          IBError(ibxeInvalidVariantType,[nil]);
313      end;
# Line 217 | Line 330 | begin
330    Result := TBPB.Create;
331   end;
332  
333 < procedure TFBAttachment.ExecImmediate(TPB: array of byte; sql: string;
333 > procedure TFBAttachment.ExecImmediate(TPB: array of byte; sql: AnsiString;
334    aSQLDialect: integer);
335   begin
336    ExecImmediate(StartTransaction(TPB,taCommit),sql,aSQLDialect);
337   end;
338  
339 < procedure TFBAttachment.ExecImmediate(transaction: ITransaction; sql: string);
339 > procedure TFBAttachment.ExecImmediate(transaction: ITransaction; sql: AnsiString);
340   begin
341    ExecImmediate(transaction,sql,FSQLDialect);
342   end;
343  
344 < procedure TFBAttachment.ExecImmediate(TPB: array of byte; sql: string);
344 > procedure TFBAttachment.ExecImmediate(TPB: array of byte; sql: AnsiString);
345   begin
346    ExecImmediate(StartTransaction(TPB,taCommit),sql,FSQLDialect);
347   end;
348  
349 < function TFBAttachment.ExecuteSQL(TPB: array of byte; sql: string;
349 > function TFBAttachment.ExecuteSQL(TPB: array of byte; sql: AnsiString;
350    SQLDialect: integer; params: array of const): IResults;
351   begin
352    Result := ExecuteSQL(StartTransaction(TPB,taCommit),sql,FSQLDialect,params);
353   end;
354  
355 < function TFBAttachment.ExecuteSQL(transaction: ITransaction; sql: string;
355 > function TFBAttachment.ExecuteSQL(transaction: ITransaction; sql: AnsiString;
356    SQLDialect: integer; params: array of const): IResults;
357   begin
358    with Prepare(transaction,sql,SQLDialect) do
# Line 249 | Line 362 | begin
362    end;
363   end;
364  
365 < function TFBAttachment.ExecuteSQL(TPB: array of byte; sql: string;
365 > function TFBAttachment.ExecuteSQL(TPB: array of byte; sql: AnsiString;
366    params: array of const): IResults;
367   begin
368     Result := ExecuteSQL(StartTransaction(TPB,taCommit),sql,params);
369   end;
370  
371 < function TFBAttachment.ExecuteSQL(transaction: ITransaction; sql: string;
371 > function TFBAttachment.ExecuteSQL(transaction: ITransaction; sql: AnsiString;
372    params: array of const): IResults;
373   begin
374    with Prepare(transaction,sql,FSQLDialect) do
# Line 265 | Line 378 | begin
378    end;
379   end;
380  
381 < function TFBAttachment.OpenCursor(transaction: ITransaction; sql: string;
381 > function TFBAttachment.OpenCursor(transaction: ITransaction; sql: AnsiString;
382    aSQLDialect: integer): IResultSet;
383   begin
384    Result := OpenCursor(transaction,sql,aSQLDialect,[]);
385   end;
386  
387 < function TFBAttachment.OpenCursor(transaction: ITransaction; sql: string;
387 > function TFBAttachment.OpenCursor(transaction: ITransaction; sql: AnsiString;
388    aSQLDialect: integer; params: array of const): IResultSet;
389   var Statement: IStatement;
390   begin
# Line 281 | Line 394 | begin
394    Result := Statement.OpenCursor;
395   end;
396  
397 < function TFBAttachment.OpenCursor(transaction: ITransaction; sql: string
397 > function TFBAttachment.OpenCursor(transaction: ITransaction; sql: AnsiString
398    ): IResultSet;
399   begin
400    Result := OpenCursor(transaction,sql,FSQLDialect,[]);
401   end;
402  
403 < function TFBAttachment.OpenCursor(transaction: ITransaction; sql: string;
403 > function TFBAttachment.OpenCursor(transaction: ITransaction; sql: AnsiString;
404    params: array of const): IResultSet;
405   begin
406    Result := OpenCursor(transaction,sql,FSQLDialect,params);
407   end;
408  
409   function TFBAttachment.OpenCursorAtStart(transaction: ITransaction;
410 <  sql: string; aSQLDialect: integer): IResultSet;
410 >  sql: AnsiString; aSQLDialect: integer): IResultSet;
411   begin
412    Result := OpenCursor(transaction,sql,aSQLDialect,[]);
413    Result.FetchNext;
414   end;
415  
416   function TFBAttachment.OpenCursorAtStart(transaction: ITransaction;
417 <  sql: string; aSQLDialect: integer; params: array of const): IResultSet;
417 >  sql: AnsiString; aSQLDialect: integer; params: array of const): IResultSet;
418   begin
419    Result := OpenCursor(transaction,sql,aSQLDialect,params);
420    Result.FetchNext;
421   end;
422  
423 < function TFBAttachment.OpenCursorAtStart(transaction: ITransaction; sql: string
423 > function TFBAttachment.OpenCursorAtStart(transaction: ITransaction; sql: AnsiString
424    ): IResultSet;
425   begin
426    Result := OpenCursorAtStart(transaction,sql,FSQLDialect,[]);
427   end;
428  
429   function TFBAttachment.OpenCursorAtStart(transaction: ITransaction;
430 <  sql: string; params: array of const): IResultSet;
430 >  sql: AnsiString; params: array of const): IResultSet;
431   begin
432    Result := OpenCursorAtStart(transaction,sql,FSQLDialect,params);
433   end;
434  
435 < function TFBAttachment.OpenCursorAtStart(sql: string): IResultSet;
435 > function TFBAttachment.OpenCursorAtStart(sql: AnsiString): IResultSet;
436   begin
437    Result := OpenCursorAtStart(sql,[]);
438   end;
439  
440 < function TFBAttachment.OpenCursorAtStart(sql: string;
440 > function TFBAttachment.OpenCursorAtStart(sql: AnsiString;
441    params: array of const): IResultSet;
442   begin
443    Result := OpenCursorAtStart(StartTransaction([isc_tpb_read,isc_tpb_wait,isc_tpb_concurrency],taCommit),sql,FSQLDialect,params);
444   end;
445  
446 < function TFBAttachment.Prepare(transaction: ITransaction; sql: string
446 > function TFBAttachment.Prepare(transaction: ITransaction; sql: AnsiString
447    ): IStatement;
448   begin
449    Result := Prepare(transaction,sql,FSQLDialect);
450   end;
451  
452   function TFBAttachment.PrepareWithNamedParameters(transaction: ITransaction;
453 <  sql: string; GenerateParamNames: boolean): IStatement;
453 >  sql: AnsiString; GenerateParamNames: boolean): IStatement;
454   begin
455    Result := PrepareWithNamedParameters(transaction,sql,FSQLDialect,GenerateParamNames);
456   end;
457  
458 < function TFBAttachment.GetEventHandler(Event: string): IEvents;
458 > function TFBAttachment.GetEventHandler(Event: AnsiString): IEvents;
459   var S: TStringList;
460   begin
461    S := TStringList.Create;
# Line 365 | Line 478 | begin
478    Result := OpenBlob(Transaction,Field.GetBlobMetadata, Field.AsQuad,BPB);
479   end;
480  
481 + function TFBAttachment.HasDefaultCharSet: boolean;
482 + begin
483 +  Result := FHasDefaultCharSet
484 + end;
485 +
486 + function TFBAttachment.GetDefaultCharSetID: integer;
487 + begin
488 +  Result := FCharsetID;
489 + end;
490 +
491 + function TFBAttachment.GetCharsetName(CharSetID: integer): AnsiString;
492 + var i: integer;
493 + begin
494 +  Result := '';
495 +  if (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap)) and
496 +                                  (CharSetMap[CharSetID].CharSetID = CharSetID) then
497 +    begin
498 +      Result := CharSetMap[CharSetID].CharSetName;
499 +      Exit;
500 +    end;
501 +
502 +  for i := 0 to Length(FUserCharSetMap) - 1 do
503 +    if FUserCharSetMap[i].CharSetID = CharSetID then
504 +    begin
505 +      Result := FUserCharSetMap[i].CharSetName;
506 +      Exit;
507 +    end;
508 + end;
509 +
510 + function TFBAttachment.CharSetID2CodePage(CharSetID: integer;
511 +  var CodePage: TSystemCodePage): boolean;
512 + var i: integer;
513 + begin
514 +  Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap))
515 +               and (CharSetMap[CharSetID].CharSetID = CharSetID);
516 +  if Result then
517 +    begin
518 +      CodePage := CharSetMap[CharSetID].CodePage;
519 +      Result := true;
520 +      Exit;
521 +    end;
522 +
523 +  for i := 0 to Length(FUserCharSetMap) - 1 do
524 +    if FUserCharSetMap[i].CharSetID = CharSetID then
525 +    begin
526 +      CodePage := FUserCharSetMap[i].CodePage;
527 +      Result := true;
528 +      Exit;
529 +    end;
530 + end;
531 +
532 + function TFBAttachment.CodePage2CharSetID(CodePage: TSystemCodePage;
533 +  var CharSetID: integer): boolean;
534 + var i: integer;
535 + begin
536 +  Result := false;
537 +  for i := Low(CharSetMap) to High(CharSetMap) do
538 +    if (CharSetMap[i].AllowReverseLookup) and (CharSetMap[i].CodePage = CodePage) then
539 +    begin
540 +      CharSetID := CharSetMap[i].CharSetID;
541 +      Result := true;
542 +      Exit;
543 +    end;
544 +
545 +  for i := 0 to Length(FUserCharSetMap) - 1 do
546 +    if (FUserCharSetMap[i].AllowReverseLookup) and (FUserCharSetMap[i].CodePage = CodePage) then
547 +    begin
548 +      CharSetID := FUserCharSetMap[i].CharSetID;
549 +      Result := true;
550 +      Exit;
551 +    end;
552 + end;
553 +
554 + function TFBAttachment.CharSetName2CharSetID(CharSetName: AnsiString;
555 +  var CharSetID: integer): boolean;
556 + var i: integer;
557 + begin
558 +  Result := false;
559 +  for i := Low(CharSetMap) to High(CharSetMap) do
560 +    if AnsiCompareStr(CharSetMap[i].CharSetName, CharSetName) = 0 then
561 +    begin
562 +      CharSetID := CharSetMap[i].CharSetID;
563 +      Result := true;
564 +      Exit;
565 +    end;
566 +
567 +    for i := 0 to Length(FUserCharSetMap) - 1 do
568 +      if AnsiCompareStr(FUserCharSetMap[i].CharSetName, CharSetName) = 0 then
569 +      begin
570 +        CharSetID := FUserCharSetMap[i].CharSetID;
571 +        Result := true;
572 +        Exit;
573 +      end;
574 + end;
575 +
576 + function TFBAttachment.CharSetWidth(CharSetID: integer; var Width: integer
577 +  ): boolean;
578 + var i: integer;
579 + begin
580 +  Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap))
581 +               and (CharSetMap[CharSetID].CharSetID = CharSetID);
582 +  if Result then
583 +    begin
584 +      Width := CharSetMap[CharSetID].CharSetWidth;
585 +      Result := true;
586 +      Exit;
587 +    end;
588 +
589 +  for i := 0 to Length(FUserCharSetMap) - 1 do
590 +    if FUserCharSetMap[i].CharSetID = CharSetID then
591 +    begin
592 +      Width := FUserCharSetMap[i].CharSetWidth;
593 +      Result := true;
594 +      Exit;
595 +    end;
596 + end;
597 +
598 + const
599 +  sqlLookupCharSet = 'Select RDB$CHARACTER_SET_ID, RDB$BYTES_PER_CHARACTER From RDB$CHARACTER_SETS '+
600 +                     'Where RDB$SYSTEM_FLAG = 0 and RDB$CHARACTER_SET_NAME = UPPER(?)';
601 +
602 + procedure TFBAttachment.RegisterCharSet(CharSetName: AnsiString;
603 +  CodePage: TSystemCodePage; AllowReverseLookup: boolean; out CharSetID: integer
604 +  );
605 + var CharSets: IResultSet;
606 +    idx: integer;
607 + begin
608 +  if CharSetName2CharSetID(CharSetName,CharSetID) then
609 +    IBError(ibxeCharacterSetExists,[CharSetName]);
610 +
611 +  CharSets := OpenCursorAtStart(sqlLookupCharSet,[CharSetName]);
612 +  if CharSets.IsEof then
613 +    IBError(ibxeUnknownUserCharSet,[CharSetName]);
614 +
615 +  idx := Length(FUserCharSetMap);
616 +  SetLength(FUserCharSetMap,idx+1);
617 +  FUserCharSetMap[idx].AllowReverseLookup := AllowReverseLookup;
618 +  FUserCharSetMap[idx].CharSetID := CharSets[0].AsInteger;
619 +  FUserCharSetMap[idx].CharSetName := AnsiUpperCase(CharSetName);
620 +  FUserCharSetMap[idx].CharSetWidth := CharSets[1].AsInteger;
621 +  FUserCharSetMap[idx].CodePage := CodePage;
622 +  CharSetID := CharSets[0].AsInteger;
623 + end;
624 +
625   end.
626  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines