25 |
|
* |
26 |
|
*) |
27 |
|
unit FB25Attachment; |
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 |
|
|
49 |
|
protected |
50 |
|
procedure CheckHandle; override; |
51 |
|
public |
52 |
< |
constructor Create(DatabaseName: string; aDPB: IDPB; |
52 |
> |
constructor Create(DatabaseName: AnsiString; aDPB: IDPB; |
53 |
|
RaiseExceptionOnConnectError: boolean); |
54 |
< |
constructor CreateDatabase(DatabaseName: string; aDPB: IDPB; RaiseExceptionOnError: boolean); |
54 |
> |
constructor CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; RaiseExceptionOnError: boolean); overload; |
55 |
> |
constructor CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
56 |
> |
RaiseExceptionOnError: boolean); overload; |
57 |
|
property Handle: TISC_DB_HANDLE read FHandle; |
58 |
|
|
59 |
|
public |
60 |
|
{IAttachment} |
61 |
|
procedure Connect; |
62 |
|
procedure Disconnect(Force: boolean=false); override; |
63 |
< |
function IsConnected: boolean; |
63 |
> |
function IsConnected: boolean; override; |
64 |
|
procedure DropDatabase; |
65 |
|
function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
66 |
|
function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction; override; |
67 |
< |
procedure ExecImmediate(transaction: ITransaction; sql: string; aSQLDialect: integer); override; |
68 |
< |
function Prepare(transaction: ITransaction; sql: string; aSQLDialect: integer): IStatement; override; |
69 |
< |
function PrepareWithNamedParameters(transaction: ITransaction; sql: string; |
67 |
> |
procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer); override; |
68 |
> |
function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; override; |
69 |
> |
function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString; |
70 |
|
aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; override; |
71 |
|
function GetEventHandler(Events: TStrings): IEvents; override; |
72 |
< |
function CreateBlob(transaction: ITransaction; RelationName, ColumnName: string; BPB: IBPB=nil): IBlob; overload; |
72 |
> |
function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload; |
73 |
|
function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload; |
74 |
|
function CreateBlob(transaction: ITransaction; SubType: integer; aCharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload; |
75 |
< |
function OpenBlob(transaction: ITransaction; RelationName, ColumnName: string; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; |
76 |
< |
function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; override; overload; |
75 |
> |
function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; |
76 |
> |
function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload; override; |
77 |
|
|
78 |
< |
function OpenArray(transaction: ITransaction; RelationName, ColumnName: string; |
78 |
> |
function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; |
79 |
|
ArrayID: TISC_QUAD): IArray; |
80 |
< |
function CreateArray(transaction: ITransaction; RelationName, ColumnName: string |
80 |
> |
function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString |
81 |
|
): IArray; overload; |
82 |
|
function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload; |
83 |
+ |
function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString; |
84 |
+ |
Scale: integer; size: cardinal; |
85 |
+ |
acharSetID: cardinal; dimensions: cardinal; bounds: TArrayBounds |
86 |
+ |
): IArrayMetaData; |
87 |
|
|
88 |
|
{Database Information} |
89 |
|
|
90 |
< |
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: string): IBlobMetaData; |
91 |
< |
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: string): IArrayMetaData; |
92 |
< |
function GetDBInformation(Requests: array of byte): IDBInformation; overload; |
93 |
< |
function GetDBInformation(Request: byte): IDBInformation; overload; |
90 |
> |
function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData; |
91 |
> |
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
92 |
> |
function GetDBInformation(Requests: array of byte): IDBInformation; overload; override; |
93 |
> |
function GetDBInformation(Request: byte): IDBInformation; overload; override; |
94 |
|
end; |
95 |
|
|
96 |
|
implementation |
97 |
|
|
98 |
|
uses FB25Events,FB25Transaction, FBMessages, FB25Blob, |
99 |
< |
FB25Statement, FB25Array; |
99 |
> |
FB25Statement, FB25Array, IBUtils; |
100 |
|
|
101 |
|
{ TFB25Attachment } |
102 |
|
|
106 |
|
IBError(ibxeDatabaseClosed,[nil]); |
107 |
|
end; |
108 |
|
|
109 |
< |
constructor TFB25Attachment.Create(DatabaseName: string; aDPB: IDPB; |
109 |
> |
constructor TFB25Attachment.Create(DatabaseName: AnsiString; aDPB: IDPB; |
110 |
|
RaiseExceptionOnConnectError: boolean); |
111 |
|
begin |
112 |
|
if aDPB = nil then |
119 |
|
Connect; |
120 |
|
end; |
121 |
|
|
122 |
< |
constructor TFB25Attachment.CreateDatabase(DatabaseName: string; aDPB: IDPB; |
122 |
> |
constructor TFB25Attachment.CreateDatabase(DatabaseName: AnsiString; aDPB: IDPB; |
123 |
|
RaiseExceptionOnError: boolean); |
124 |
< |
var sql: string; |
124 |
> |
var sql: AnsiString; |
125 |
|
tr_handle: TISC_TR_HANDLE; |
126 |
|
begin |
127 |
|
inherited Create(DatabaseName,aDPB,RaiseExceptionOnError); |
128 |
|
sql := GenerateCreateDatabaseSQL(DatabaseName,aDPB); |
129 |
|
tr_handle := nil; |
130 |
|
with Firebird25ClientAPI do |
131 |
< |
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PChar(sql), |
131 |
> |
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
132 |
|
SQLDialect, nil) > 0) and RaiseExceptionOnError then |
133 |
|
IBDataBaseError; |
134 |
|
if DPB <> nil then |
136 |
|
begin |
137 |
|
Disconnect; |
138 |
|
Connect; |
139 |
+ |
end |
140 |
+ |
else |
141 |
+ |
GetODSAndConnectionInfo; |
142 |
+ |
end; |
143 |
+ |
|
144 |
+ |
constructor TFB25Attachment.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
145 |
+ |
RaiseExceptionOnError: boolean); |
146 |
+ |
var tr_handle: TISC_TR_HANDLE; |
147 |
+ |
begin |
148 |
+ |
inherited Create('',nil,RaiseExceptionOnError); |
149 |
+ |
FSQLDialect := aSQLDialect; |
150 |
+ |
tr_handle := nil; |
151 |
+ |
with Firebird25ClientAPI do |
152 |
+ |
begin |
153 |
+ |
if (isc_dsql_execute_immediate(StatusVector, @FHandle, @tr_handle, 0, PAnsiChar(sql), |
154 |
+ |
aSQLDialect, nil) > 0) and RaiseExceptionOnError then |
155 |
+ |
IBDataBaseError; |
156 |
+ |
|
157 |
|
end; |
158 |
+ |
GetODSAndConnectionInfo; |
159 |
+ |
ExtractConnectString(sql,FDatabaseName); |
160 |
+ |
DPBFromCreateSQL(sql); |
161 |
|
end; |
162 |
|
|
163 |
|
procedure TFB25Attachment.Connect; |
134 |
– |
var Param: IDPBItem; |
164 |
|
begin |
165 |
|
FSQLDialect := 3; |
166 |
|
|
168 |
|
if DPB = nil then |
169 |
|
begin |
170 |
|
if (isc_attach_database(StatusVector, Length(FDatabaseName), |
171 |
< |
PChar(FDatabaseName), @FHandle, 0, nil) > 0) and FRaiseExceptionOnConnectError then |
171 |
> |
PAnsiChar(FDatabaseName), @FHandle, 0, nil) > 0) and FRaiseExceptionOnConnectError then |
172 |
|
IBDatabaseError; |
173 |
|
end |
174 |
|
else |
175 |
|
begin |
176 |
|
if (isc_attach_database(StatusVector, Length(FDatabaseName), |
177 |
< |
PChar(FDatabaseName), @FHandle, |
177 |
> |
PAnsiChar(FDatabaseName), @FHandle, |
178 |
|
(DPB as TDPB).getDataLength, |
179 |
|
(DPB as TDPB).getBuffer) > 0 ) and FRaiseExceptionOnConnectError then |
180 |
|
IBDatabaseError; |
181 |
|
|
153 |
– |
if IsConnected then |
154 |
– |
begin |
155 |
– |
Param := DPB.Find(isc_dpb_set_db_SQL_dialect); |
156 |
– |
if Param <> nil then |
157 |
– |
FSQLDialect := Param.AsByte; |
158 |
– |
Param := DPB.Find(isc_dpb_lc_ctype); |
159 |
– |
FHasDefaultCharSet := (Param <> nil) and |
160 |
– |
CharSetName2CharSetID(Param.AsString,FCharSetID) and |
161 |
– |
CharSetID2CodePage(FCharSetID,FCodePage) and |
162 |
– |
(FCharSetID > 1); |
163 |
– |
end; |
182 |
|
end; |
183 |
+ |
GetODSAndConnectionInfo; |
184 |
|
end; |
185 |
|
|
186 |
|
procedure TFB25Attachment.Disconnect(Force: boolean); |
229 |
|
end; |
230 |
|
|
231 |
|
function TFB25Attachment.CreateBlob(transaction: ITransaction; RelationName, |
232 |
< |
ColumnName: string; BPB: IBPB): IBlob; |
232 |
> |
ColumnName: AnsiString; BPB: IBPB): IBlob; |
233 |
|
begin |
234 |
|
CheckHandle; |
235 |
|
Result := TFB25Blob.Create(self,transaction as TFB25transaction, |
251 |
|
end; |
252 |
|
|
253 |
|
function TFB25Attachment.OpenBlob(transaction: ITransaction; RelationName, |
254 |
< |
ColumnName: string; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; |
254 |
> |
ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; |
255 |
|
begin |
256 |
|
CheckHandle; |
257 |
|
Result := TFB25Blob.Create(self,transaction as TFB25transaction, |
266 |
|
Result := TFB25Blob.Create(self,transaction as TFB25transaction,BlobMetaData,BlobID,BPB); |
267 |
|
end; |
268 |
|
|
269 |
< |
procedure TFB25Attachment.ExecImmediate(transaction: ITransaction; sql: string; |
269 |
> |
procedure TFB25Attachment.ExecImmediate(transaction: ITransaction; sql: AnsiString; |
270 |
|
aSQLDialect: integer); |
271 |
|
var TRHandle: TISC_TR_HANDLE; |
272 |
|
begin |
273 |
|
CheckHandle; |
274 |
|
TRHandle := (Transaction as TFB25Transaction).Handle; |
275 |
|
with Firebird25ClientAPI do |
276 |
< |
if isc_dsql_execute_immediate(StatusVector, @fHandle, @TRHandle, 0,PChar(sql), aSQLDialect, nil) > 0 then |
276 |
> |
if isc_dsql_execute_immediate(StatusVector, @fHandle, @TRHandle, 0,PAnsiChar(sql), aSQLDialect, nil) > 0 then |
277 |
|
IBDatabaseError; |
278 |
|
SignalActivity; |
279 |
|
end; |
280 |
|
|
281 |
< |
function TFB25Attachment.Prepare(transaction: ITransaction; sql: string; |
281 |
> |
function TFB25Attachment.Prepare(transaction: ITransaction; sql: AnsiString; |
282 |
|
aSQLDialect: integer): IStatement; |
283 |
|
begin |
284 |
|
CheckHandle; |
286 |
|
end; |
287 |
|
|
288 |
|
function TFB25Attachment.PrepareWithNamedParameters(transaction: ITransaction; |
289 |
< |
sql: string; aSQLDialect: integer; GenerateParamNames: boolean): IStatement; |
289 |
> |
sql: AnsiString; aSQLDialect: integer; GenerateParamNames: boolean): IStatement; |
290 |
|
begin |
291 |
|
CheckHandle; |
292 |
|
Result := TFB25Statement.CreateWithParameterNames(self,transaction,sql,aSQLDialect, |
299 |
|
Result := TFB25Events.Create(self,Events); |
300 |
|
end; |
301 |
|
|
302 |
< |
function TFB25Attachment.OpenArray(transaction: ITransaction; RelationName, ColumnName: string; |
302 |
> |
function TFB25Attachment.OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; |
303 |
|
ArrayID: TISC_QUAD): IArray; |
304 |
|
begin |
305 |
|
CheckHandle; |
307 |
|
GetArrayMetaData(transaction,RelationName,ColumnName),ArrayID); |
308 |
|
end; |
309 |
|
|
310 |
< |
function TFB25Attachment.CreateArray(transaction: ITransaction; RelationName, ColumnName: string): IArray; |
310 |
> |
function TFB25Attachment.CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; |
311 |
|
begin |
312 |
|
CheckHandle; |
313 |
|
Result := TFB25Array.Create(self,transaction as TFB25Transaction, |
321 |
|
Result := TFB25Array.Create(self,transaction as TFB25Transaction,ArrayMetaData); |
322 |
|
end; |
323 |
|
|
324 |
+ |
function TFB25Attachment.CreateArrayMetaData(SQLType: cardinal; |
325 |
+ |
tableName: AnsiString; columnName: AnsiString; Scale: integer; size: cardinal; |
326 |
+ |
acharSetID: cardinal; dimensions: cardinal; bounds: TArrayBounds |
327 |
+ |
): IArrayMetaData; |
328 |
+ |
begin |
329 |
+ |
Result := TFB25ArrayMetaData.Create(self,SQLType,tableName,ColumnName,Scale,size,acharSetID,dimensions,bounds); |
330 |
+ |
end; |
331 |
+ |
|
332 |
|
function TFB25Attachment.GetBlobMetaData(Transaction: ITransaction; tableName, |
333 |
< |
columnName: string): IBlobMetaData; |
333 |
> |
columnName: AnsiString): IBlobMetaData; |
334 |
|
begin |
335 |
|
CheckHandle; |
336 |
|
Result := TFB25BlobMetaData.Create(self,Transaction as TFB25Transaction,tableName,columnName); |
337 |
|
end; |
338 |
|
|
339 |
|
function TFB25Attachment.GetArrayMetaData(Transaction: ITransaction; tableName, |
340 |
< |
columnName: string): IArrayMetaData; |
340 |
> |
columnName: AnsiString): IArrayMetaData; |
341 |
|
begin |
342 |
|
CheckHandle; |
343 |
|
Result := TFB25ArrayMetaData.Create(self,Transaction as TFB25Transaction,tableName,columnName); |
360 |
|
ReqBuffer[i] := Requests[i]; |
361 |
|
|
362 |
|
with Firebird25ClientAPI, Result as TDBInformation do |
363 |
< |
if isc_database_info(StatusVector, @(FHandle), Length(Requests), PChar(ReqBuffer), |
363 |
> |
if isc_database_info(StatusVector, @(FHandle), Length(Requests), ReqBuffer, |
364 |
|
getBufSize, Buffer) > 0 then |
365 |
|
IBDataBaseError; |
366 |
|
|