28 |
|
* |
29 |
|
*) |
30 |
|
unit FBBlob; |
31 |
+ |
{$IFDEF MSWINDOWS} |
32 |
+ |
{$DEFINE WINDOWS} |
33 |
+ |
{$ENDIF} |
34 |
|
|
35 |
|
{$IFDEF FPC} |
36 |
< |
{$mode objfpc}{$H+} |
36 |
> |
{$mode delphi} |
37 |
|
{$interfaces COM} |
38 |
|
{$ENDIF} |
39 |
|
|
40 |
|
interface |
41 |
|
|
42 |
|
uses |
43 |
< |
Classes, SysUtils, IB, FBActivityMonitor, FBTransaction, FBClientAPI; |
43 |
> |
Classes, SysUtils, IB, FBActivityMonitor, FBTransaction, FBClientAPI, |
44 |
> |
FBOutputBlock; |
45 |
|
|
46 |
|
type |
47 |
|
|
49 |
|
|
50 |
|
TFBBlobMetaData = class(TActivityReporter) |
51 |
|
private |
52 |
< |
FRelationName: string; |
53 |
< |
FColumnName: string; |
52 |
> |
FRelationName: AnsiString; |
53 |
> |
FColumnName: AnsiString; |
54 |
|
protected |
55 |
|
FUnconfirmedCharacterSet: boolean; |
56 |
|
FHasSubType: boolean; |
57 |
|
FSubType: integer; |
58 |
|
FCharSetID: cardinal; |
59 |
|
FSegmentSize: cardinal; |
60 |
+ |
function Attachment: IAttachment; virtual; abstract; |
61 |
+ |
function CanFetchMetaData: boolean; |
62 |
|
procedure NeedFullMetadata; virtual; abstract; |
63 |
|
procedure NeedSubType; |
64 |
|
public |
65 |
< |
constructor Create(Transaction: TFBTransaction; RelationName, ColumnName: string |
65 |
> |
constructor Create(Transaction: TFBTransaction; RelationName, ColumnName: AnsiString |
66 |
|
); |
67 |
+ |
procedure SetCharSetID(aValue: integer); |
68 |
|
|
69 |
|
public |
70 |
|
{IBlobMetaData} |
72 |
|
function GetCharSetID: cardinal; |
73 |
|
function GetCodePage: TSystemCodePage; |
74 |
|
function GetSegmentSize: cardinal; |
75 |
< |
function GetRelationName: string; |
76 |
< |
function GetColumnName: string; |
75 |
> |
function GetRelationName: AnsiString; |
76 |
> |
function GetColumnName: AnsiString; |
77 |
|
function GetUnconfirmedCharacterSet: boolean; |
78 |
|
end; |
79 |
|
|
80 |
< |
TFBBlob = class(TActivityReporter) |
80 |
> |
TFBBlob = class(TActivityReporter,ITransactionUser) |
81 |
|
private |
82 |
|
FMetaData: IBlobMetaData; |
83 |
|
FAttachment: IAttachment; |
92 |
|
procedure CheckWritable; virtual; abstract; |
93 |
|
procedure ClearStringCache; |
94 |
|
function GetIntf: IBlob; virtual; abstract; |
95 |
+ |
procedure GetInfo(Request: array of byte; Response: IBlobInfo); overload; virtual; abstract; |
96 |
|
procedure InternalClose(Force: boolean); virtual; abstract; |
97 |
|
procedure InternalCancel(Force: boolean); virtual; abstract; |
98 |
|
public |
101 |
|
constructor Create(Attachment: IAttachment; Transaction: TFBTransaction; |
102 |
|
MetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB); overload; |
103 |
|
destructor Destroy; override; |
104 |
< |
procedure TransactionEnding(aTransaction: TFBTransaction; Force: boolean); |
104 |
> |
|
105 |
> |
public |
106 |
> |
{ITransactionUser} |
107 |
> |
procedure TransactionEnding(aTransaction: ITransaction; Force: boolean); |
108 |
|
|
109 |
|
public |
110 |
|
{IBlobMetaData} |
112 |
|
function GetCharSetID: cardinal; |
113 |
|
function GetCodePage: TSystemCodePage; |
114 |
|
function GetSegmentSize: cardinal; |
115 |
< |
function GetRelationName: string; |
116 |
< |
function GetColumnName: string; |
115 |
> |
function GetRelationName: AnsiString; |
116 |
> |
function GetColumnName: AnsiString; |
117 |
|
function GetUnconfirmedCharacterSet: boolean; |
118 |
|
|
119 |
|
{IBlob} |
122 |
|
procedure Close; |
123 |
|
function GetBlobSize: Int64; |
124 |
|
procedure GetInfo(var NumSegments: Int64; var MaxSegmentSize, TotalSize: Int64; |
125 |
< |
var BlobType: TBlobType); virtual; abstract; |
125 |
> |
var BlobType: TBlobType); overload; |
126 |
|
function GetBlobID: TISC_QUAD; |
127 |
|
function GetBlobMode: TFBBlobMode; |
128 |
|
function Read(var Buffer; Count: Longint): Longint; virtual; abstract; |
129 |
|
function Write(const Buffer; Count: Longint): Longint; virtual; abstract; |
130 |
< |
function LoadFromFile(Filename: string): IBlob; |
130 |
> |
function LoadFromFile(Filename: AnsiString): IBlob; |
131 |
|
function LoadFromStream(S: TStream) : IBlob; |
132 |
< |
function SaveToFile(Filename: string): IBlob; |
132 |
> |
function SaveToFile(Filename: AnsiString): IBlob; |
133 |
|
function SaveToStream(S: TStream): IBlob; |
134 |
|
function GetAttachment: IAttachment; |
135 |
|
function GetTransaction: ITransaction; |
142 |
|
|
143 |
|
implementation |
144 |
|
|
134 |
– |
uses FBMessages; |
135 |
– |
|
145 |
|
{ TFBBlob } |
146 |
|
|
147 |
|
procedure TFBBlob.ClearStringCache; |
178 |
|
inherited Destroy; |
179 |
|
end; |
180 |
|
|
181 |
< |
procedure TFBBlob.TransactionEnding(aTransaction: TFBTransaction; |
173 |
< |
Force: boolean); |
181 |
> |
procedure TFBBlob.TransactionEnding(aTransaction: ITransaction; Force: boolean); |
182 |
|
begin |
183 |
< |
if aTransaction <> FTransaction then |
183 |
> |
if (aTransaction as TObject) <> (FTransaction as TObject) then |
184 |
|
Exit; |
185 |
|
if FCreating then |
186 |
|
InternalCancel(Force) |
208 |
|
Result := FMetaData.GetSegmentSize; |
209 |
|
end; |
210 |
|
|
211 |
< |
function TFBBlob.GetRelationName: string; |
211 |
> |
function TFBBlob.GetRelationName: AnsiString; |
212 |
|
begin |
213 |
|
Result := FMetaData.GetRelationName; |
214 |
|
end; |
215 |
|
|
216 |
< |
function TFBBlob.GetColumnName: string; |
216 |
> |
function TFBBlob.GetColumnName: AnsiString; |
217 |
|
begin |
218 |
|
Result := FMetaData.GetColumnName; |
219 |
|
end; |
246 |
|
GetInfo(NumSegments,MaxSegmentSize,Result,BlobType); |
247 |
|
end; |
248 |
|
|
249 |
+ |
procedure TFBBlob.GetInfo(var NumSegments: Int64; var MaxSegmentSize, |
250 |
+ |
TotalSize: Int64; var BlobType: TBlobType); |
251 |
+ |
var BlobInfo: IBlobInfo; |
252 |
+ |
i: integer; |
253 |
+ |
begin |
254 |
+ |
NumSegments := 0; |
255 |
+ |
MaxSegmentSize := 0; |
256 |
+ |
TotalSize := 0; |
257 |
+ |
BlobType := btSegmented; |
258 |
+ |
|
259 |
+ |
BlobInfo := TBlobInfo.Create(FAttachment.getFirebirdAPI as TFBClientAPI); |
260 |
+ |
GetInfo([isc_info_blob_num_segments, |
261 |
+ |
isc_info_blob_max_segment, |
262 |
+ |
isc_info_blob_total_length, |
263 |
+ |
isc_info_blob_type],BlobInfo); |
264 |
+ |
|
265 |
+ |
for i := 0 to BlobInfo.Count - 1 do |
266 |
+ |
with BlobInfo[i] do |
267 |
+ |
case getItemType of |
268 |
+ |
isc_info_blob_num_segments: |
269 |
+ |
NumSegments := GetAsInteger; |
270 |
+ |
isc_info_blob_max_segment: |
271 |
+ |
MaxSegmentSize := GetAsInteger; |
272 |
+ |
isc_info_blob_total_length: |
273 |
+ |
TotalSize := GetAsInteger; |
274 |
+ |
isc_info_blob_type: |
275 |
+ |
if GetAsInteger = 0 then |
276 |
+ |
BlobType := btSegmented |
277 |
+ |
else |
278 |
+ |
BlobType := btStream; |
279 |
+ |
end; |
280 |
+ |
end; |
281 |
+ |
|
282 |
|
function TFBBlob.GetBlobID: TISC_QUAD; |
283 |
|
begin |
284 |
|
Result := FBlobID; |
292 |
|
Result := fbmRead; |
293 |
|
end; |
294 |
|
|
295 |
< |
function TFBBlob.LoadFromFile(Filename: string): IBlob; |
295 |
> |
function TFBBlob.LoadFromFile(Filename: AnsiString): IBlob; |
296 |
|
var |
297 |
|
Stream: TStream; |
298 |
|
begin |
320 |
|
Result := GetIntf; |
321 |
|
end; |
322 |
|
|
323 |
< |
function TFBBlob.SaveToFile(Filename: string): IBlob; |
323 |
> |
function TFBBlob.SaveToFile(Filename: AnsiString): IBlob; |
324 |
|
var |
325 |
|
Stream: TStream; |
326 |
|
begin |
405 |
|
|
406 |
|
{TFBBlobMetaData} |
407 |
|
|
408 |
+ |
function TFBBlobMetaData.CanFetchMetaData: boolean; |
409 |
+ |
begin |
410 |
+ |
Result := (FRelationName <> '') and (FColumnName <> ''); |
411 |
+ |
end; |
412 |
+ |
|
413 |
|
procedure TFBBlobMetaData.NeedSubType; |
414 |
|
begin |
415 |
|
if not FHasSubType then |
420 |
|
end; |
421 |
|
|
422 |
|
constructor TFBBlobMetaData.Create(Transaction: TFBTransaction; RelationName, |
423 |
< |
ColumnName: string); |
423 |
> |
ColumnName: AnsiString); |
424 |
|
begin |
425 |
|
inherited Create(Transaction); |
426 |
|
// if (RelationName = '') or (ColumnName = '') then |
428 |
|
FRelationName := RelationName; |
429 |
|
FColumnName := ColumnName; |
430 |
|
FSegmentSize := 80; |
431 |
+ |
FUnconfirmedCharacterSet := true; |
432 |
+ |
FCharSetID := 0; |
433 |
+ |
end; |
434 |
+ |
|
435 |
+ |
procedure TFBBlobMetaData.SetCharSetID(aValue: integer); |
436 |
+ |
begin |
437 |
+ |
FCharSetID := aValue; |
438 |
+ |
FUnconfirmedCharacterSet := false; |
439 |
|
end; |
440 |
|
|
441 |
|
function TFBBlobMetaData.GetSubType: integer; |
446 |
|
|
447 |
|
function TFBBlobMetaData.GetCharSetID: cardinal; |
448 |
|
begin |
449 |
< |
NeedFullMetadata; |
449 |
> |
if FUnconfirmedCharacterSet and CanFetchMetaData then |
450 |
> |
NeedFullMetadata; |
451 |
|
Result := FCharSetID; |
452 |
|
end; |
453 |
|
|
454 |
|
function TFBBlobMetaData.GetCodePage: TSystemCodePage; |
455 |
|
begin |
456 |
< |
FirebirdClientAPI.CharSetID2CodePage(GetCharSetID,Result); |
456 |
> |
Attachment.CharSetID2CodePage(GetCharSetID,Result); |
457 |
|
end; |
458 |
|
|
459 |
|
function TFBBlobMetaData.GetSegmentSize: cardinal; |
462 |
|
Result := FSegmentSize; |
463 |
|
end; |
464 |
|
|
465 |
< |
function TFBBlobMetaData.GetRelationName: string; |
465 |
> |
function TFBBlobMetaData.GetRelationName: AnsiString; |
466 |
|
begin |
467 |
|
Result := FRelationName; |
468 |
|
end; |
469 |
|
|
470 |
< |
function TFBBlobMetaData.GetColumnName: string; |
470 |
> |
function TFBBlobMetaData.GetColumnName: AnsiString; |
471 |
|
begin |
472 |
|
Result := FColumnName; |
473 |
|
end; |