25 |
|
* |
26 |
|
*) |
27 |
|
unit FBArray; |
28 |
+ |
{$IFDEF MSWINDOWS} |
29 |
+ |
{$DEFINE WINDOWS} |
30 |
+ |
{$ENDIF} |
31 |
|
|
32 |
|
{$IFDEF FPC} |
33 |
< |
{$mode objfpc}{$H+} |
33 |
> |
{$mode delphi} |
34 |
|
{$codepage UTF8} |
35 |
|
{$interfaces COM} |
36 |
|
{$ENDIF} |
38 |
|
interface |
39 |
|
|
40 |
|
uses |
41 |
< |
Classes, SysUtils, IB, IBHeader, FBTransaction, |
42 |
< |
FBSQLData, FBClientAPI, IBExternals, FBActivityMonitor; |
41 |
> |
Classes, SysUtils, IBHeader, IB, FBTransaction, |
42 |
> |
FBSQLData, FBClientAPI, IBExternals, FBActivityMonitor, FmtBCD; |
43 |
|
|
44 |
|
(* |
45 |
|
|
72 |
|
|
73 |
|
TFBArrayElement = class(TSQLDataItem) |
74 |
|
private |
75 |
< |
FBufPtr: PChar; |
75 |
> |
FBufPtr: PByte; |
76 |
|
FArray: TFBArray; |
77 |
|
protected |
78 |
+ |
function GetAttachment: IAttachment; override; |
79 |
|
function GetSQLDialect: integer; override; |
80 |
|
procedure Changing; override; |
81 |
|
procedure Changed; override; |
82 |
< |
function SQLData: PChar; override; |
82 |
> |
function SQLData: PByte; override; |
83 |
|
function GetDataLength: cardinal; override; |
84 |
|
function GetCodePage: TSystemCodePage; override; |
85 |
+ |
function getCharSetID: cardinal; override; |
86 |
|
procedure SetDataLength(len: cardinal); override; |
87 |
|
procedure SetSQLType(aValue: cardinal); override; |
88 |
|
public |
89 |
< |
constructor Create(anArray: TFBArray; P: PChar); |
89 |
> |
constructor Create(anArray: TFBArray; P: PByte); |
90 |
|
function GetSQLType: cardinal; override; |
91 |
< |
function GetName: string; override; |
91 |
> |
function GetName: AnsiString; override; |
92 |
|
function GetScale: integer; override; |
93 |
|
function GetSize: integer; |
94 |
< |
function GetAsString: string; override; |
94 |
> |
function GetCharSetWidth: integer; override; |
95 |
> |
function GetAsString: AnsiString; override; |
96 |
|
procedure SetAsLong(Value: Long); override; |
97 |
|
procedure SetAsShort(Value: Short); override; |
98 |
|
procedure SetAsInt64(Value: Int64); override; |
99 |
< |
procedure SetAsString(Value: String); override; |
99 |
> |
procedure SetAsString(Value: AnsiString); override; |
100 |
|
procedure SetAsDouble(Value: Double); override; |
101 |
|
procedure SetAsFloat(Value: Float); override; |
102 |
|
procedure SetAsCurrency(Value: Currency); override; |
103 |
+ |
procedure SetAsBcd(aValue: tBCD); override; |
104 |
+ |
procedure SetAsNumeric(Value: IFBNumeric); override; |
105 |
|
end; |
106 |
|
|
107 |
|
{ TFBArrayMetaData } |
108 |
|
|
109 |
|
TFBArrayMetaData = class(TFBInterfacedObject,IArrayMetaData) |
110 |
+ |
private |
111 |
+ |
function GetDType(SQLType: cardinal): UChar; |
112 |
|
protected |
113 |
|
FArrayDesc: TISC_ARRAY_DESC; |
114 |
+ |
FCharSetID: integer; |
115 |
+ |
FAttachment: IAttachment; |
116 |
|
procedure LoadMetaData(aAttachment: IAttachment; aTransaction: ITransaction; |
117 |
< |
relationName, columnName: string); virtual; abstract; |
117 |
> |
relationName, columnName: AnsiString); virtual; abstract; |
118 |
|
function NumOfElements: integer; |
119 |
|
public |
120 |
|
constructor Create(aAttachment: IAttachment; aTransaction: ITransaction; |
121 |
< |
relationName, columnName: string); |
121 |
> |
relationName, columnName: AnsiString); overload; |
122 |
> |
constructor Create(aAttachment: IAttachment;SQLType: cardinal; tableName: AnsiString; columnName: AnsiString; |
123 |
> |
Scale: integer; size: cardinal; charSetID: cardinal; |
124 |
> |
dimensions: cardinal; bounds: TArrayBounds); overload; |
125 |
|
function GetCodePage: TSystemCodePage; virtual; abstract; |
126 |
|
|
127 |
|
public |
128 |
|
{IArrayMetaData} |
129 |
|
function GetSQLType: cardinal; |
130 |
< |
function GetSQLTypeName: string; |
130 |
> |
function GetSQLTypeName: AnsiString; |
131 |
|
function GetScale: integer; |
132 |
|
function GetSize: cardinal; |
133 |
|
function GetCharSetID: cardinal; virtual; abstract; |
134 |
< |
function GetTableName: string; |
135 |
< |
function GetColumnName: string; |
134 |
> |
function GetCharSetWidth: integer; virtual; abstract; |
135 |
> |
function GetTableName: AnsiString; |
136 |
> |
function GetColumnName: AnsiString; |
137 |
|
function GetDimensions: integer; |
138 |
|
function GetBounds: TArrayBounds; |
139 |
|
end; |
141 |
|
|
142 |
|
{ TFBArray } |
143 |
|
|
144 |
< |
TFBArray = class(TActivityReporter,IArray) |
144 |
> |
TFBArray = class(TActivityReporter,IArray,ITransactionUser) |
145 |
|
private |
146 |
+ |
FFirebirdClientAPI: TFBClientAPI; |
147 |
|
FMetaData: IArrayMetaData; |
148 |
|
FIsNew: boolean; |
149 |
|
FLoaded: boolean; |
159 |
|
FEventHandlers: array of TArrayEventHandler; |
160 |
|
procedure GetArraySlice; |
161 |
|
procedure PutArraySlice(Force: boolean=false); |
162 |
< |
function GetOffset(index: array of integer): PChar; |
162 |
> |
function GetOffset(index: array of integer): PByte; |
163 |
|
function GetDataLength: short; |
164 |
|
protected |
165 |
< |
FBuffer: PChar; |
165 |
> |
FBuffer: PByte; |
166 |
|
FBufSize: ISC_LONG; |
167 |
|
FArrayID: TISC_QUAD; |
168 |
|
procedure AllocateBuffer; virtual; |
169 |
< |
procedure Changing; |
170 |
< |
procedure Changed; |
169 |
> |
procedure Changing; virtual; |
170 |
> |
procedure Changed; virtual; |
171 |
|
function GetArrayDesc: PISC_ARRAY_DESC; |
172 |
|
procedure InternalGetSlice; virtual; abstract; |
173 |
|
procedure InternalPutSlice(Force: boolean); virtual; abstract; |
178 |
|
aField: IArrayMetaData; ArrayID: TISC_QUAD); overload; |
179 |
|
destructor Destroy; override; |
180 |
|
function GetSQLDialect: integer; |
181 |
+ |
|
182 |
+ |
public |
183 |
+ |
{ITransactionUser} |
184 |
|
procedure TransactionEnding(aTransaction: ITransaction; Force: boolean); |
185 |
|
|
186 |
|
public |
187 |
|
{IArrayMetaData} |
188 |
|
function GetSQLType: cardinal; |
189 |
< |
function GetSQLTypeName: string; |
189 |
> |
function GetSQLTypeName: AnsiString; |
190 |
|
function GetScale: integer; |
191 |
|
function GetSize: cardinal; |
192 |
|
function GetCharSetID: cardinal; |
193 |
< |
function GetTableName: string; |
194 |
< |
function GetColumnName: string; |
193 |
> |
function GetCharSetWidth: integer; |
194 |
> |
function GetTableName: AnsiString; |
195 |
> |
function GetColumnName: AnsiString; |
196 |
|
function GetDimensions: integer; |
197 |
|
function GetBounds: TArrayBounds; |
198 |
|
{IArray} |
206 |
|
function GetAsBoolean(index: array of integer): boolean; |
207 |
|
function GetAsCurrency(index: array of integer): Currency; |
208 |
|
function GetAsInt64(index: array of integer): Int64; |
209 |
< |
function GetAsDateTime(index: array of integer): TDateTime; |
209 |
> |
function GetAsDateTime(index: array of integer): TDateTime; overload; |
210 |
> |
procedure GetAsDateTime(index: array of integer; var aDateTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload; |
211 |
> |
procedure GetAsDateTime(index: array of integer; var aDateTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload; |
212 |
> |
procedure GetAsTime(index: array of integer; var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime); overload; |
213 |
> |
procedure GetAsTime(index: array of integer; var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString; OnDate: TDateTime); overload; |
214 |
> |
function GetAsUTCDateTime(index: array of integer): TDateTime; |
215 |
|
function GetAsDouble(index: array of integer): Double; |
216 |
|
function GetAsFloat(index: array of integer): Float; |
217 |
|
function GetAsLong(index: array of integer): Long; |
218 |
|
function GetAsShort(index: array of integer): Short; |
219 |
< |
function GetAsString(index: array of integer): String; |
219 |
> |
function GetAsString(index: array of integer): AnsiString; |
220 |
|
function GetAsVariant(index: array of integer): Variant; |
221 |
+ |
function GetAsBCD(index: array of integer): tBCD; |
222 |
|
procedure SetAsInteger(index: array of integer; AValue: integer); |
223 |
|
procedure SetAsBoolean(index: array of integer; AValue: boolean); |
224 |
|
procedure SetAsCurrency(index: array of integer; Value: Currency); |
225 |
|
procedure SetAsInt64(index: array of integer; Value: Int64); |
226 |
|
procedure SetAsDate(index: array of integer; Value: TDateTime); |
227 |
|
procedure SetAsLong(index: array of integer; Value: Long); |
228 |
< |
procedure SetAsTime(index: array of integer; Value: TDateTime); |
229 |
< |
procedure SetAsDateTime(index: array of integer; Value: TDateTime); |
228 |
> |
procedure SetAsTime(index: array of integer; Value: TDateTime); overload; |
229 |
> |
procedure SetAsTime(index: array of integer; aValue: TDateTime; OnDate: TDateTime; aTimeZoneID: TFBTimeZoneID); overload; |
230 |
> |
procedure SetAsTime(index: array of integer; aValue: TDateTime; OnDate: TDateTime; aTimeZone: AnsiString); overload; |
231 |
> |
procedure SetAsDateTime(index: array of integer; Value: TDateTime); overload; |
232 |
> |
procedure SetAsDateTime(index: array of integer; aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload; |
233 |
> |
procedure SetAsDateTime(index: array of integer; aValue: TDateTime; aTimeZone: AnsiString); overload; |
234 |
> |
procedure SetAsUTCDateTime(index: array of integer; aUTCTime: TDateTime); |
235 |
|
procedure SetAsDouble(index: array of integer; Value: Double); |
236 |
|
procedure SetAsFloat(index: array of integer; Value: Float); |
237 |
|
procedure SetAsShort(index: array of integer; Value: Short); |
238 |
< |
procedure SetAsString(index: array of integer; Value: String); |
238 |
> |
procedure SetAsString(index: array of integer; Value: AnsiString); |
239 |
|
procedure SetAsVariant(index: array of integer; Value: Variant); |
240 |
+ |
procedure SetAsBcd(index: array of integer; aValue: tBCD); |
241 |
|
procedure SetBounds(dim, UpperBound, LowerBound: integer); |
242 |
|
function GetAttachment: IAttachment; |
243 |
|
function GetTransaction: ITransaction; |
247 |
|
|
248 |
|
implementation |
249 |
|
|
250 |
< |
uses FBMessages; |
250 |
> |
uses FBMessages, IBUtils, FBNumeric; |
251 |
|
|
252 |
|
{ TFBArrayElement } |
253 |
|
|
254 |
+ |
function TFBArrayElement.GetAttachment: IAttachment; |
255 |
+ |
begin |
256 |
+ |
Result := FArray.GetAttachment; |
257 |
+ |
end; |
258 |
+ |
|
259 |
|
function TFBArrayElement.GetSQLDialect: integer; |
260 |
|
begin |
261 |
|
Result := FArray.GetSQLDialect; |
273 |
|
FArray.Changed; |
274 |
|
end; |
275 |
|
|
276 |
< |
function TFBArrayElement.SQLData: PChar; |
276 |
> |
function TFBArrayElement.SQLData: PByte; |
277 |
|
begin |
278 |
|
Result := FBufPtr; |
279 |
|
end; |
288 |
|
Result := (FArray.FMetaData as TFBArrayMetaData).GetCodePage; |
289 |
|
end; |
290 |
|
|
291 |
+ |
function TFBArrayElement.getCharSetID: cardinal; |
292 |
+ |
begin |
293 |
+ |
Result := (FArray.FMetaData as TFBArrayMetaData).GetCharSetID; |
294 |
+ |
end; |
295 |
+ |
|
296 |
|
procedure TFBArrayElement.SetDataLength(len: cardinal); |
297 |
|
begin |
298 |
|
if len > GetDataLength then |
299 |
|
IBError(ibxeArrayElementOverFlow,[nil]); |
300 |
|
end; |
301 |
|
|
302 |
< |
constructor TFBArrayElement.Create(anArray: TFBArray; P: PChar); |
302 |
> |
constructor TFBArrayElement.Create(anArray: TFBArray; P: PByte); |
303 |
|
begin |
304 |
< |
inherited Create; |
304 |
> |
inherited Create(anArray.FFirebirdClientAPI); |
305 |
|
FArray := anArray; |
306 |
|
FBufPtr := P; |
307 |
|
end; |
311 |
|
Result := FArray.FMetaData.GetSQLType; |
312 |
|
end; |
313 |
|
|
314 |
< |
function TFBArrayElement.GetName: string; |
314 |
> |
function TFBArrayElement.GetName: AnsiString; |
315 |
|
begin |
316 |
|
Result := FArray.FMetaData.GetColumnName; |
317 |
|
end; |
326 |
|
Result := GetDataLength; |
327 |
|
end; |
328 |
|
|
329 |
< |
function TFBArrayElement.GetAsString: string; |
329 |
> |
function TFBArrayElement.GetCharSetWidth: integer; |
330 |
> |
begin |
331 |
> |
Result := FArray.FMetaData.GetCharSetWidth; |
332 |
> |
end; |
333 |
> |
|
334 |
> |
function TFBArrayElement.GetAsString: AnsiString; |
335 |
|
var rs: RawByteString; |
336 |
|
begin |
337 |
|
case GetSQLType of |
338 |
|
SQL_VARYING: |
339 |
|
begin |
340 |
< |
rs := strpas(FBufPtr); |
340 |
> |
rs := strpas(PAnsiChar(FBufPtr)); |
341 |
|
SetCodePage(rs,GetCodePage,false); |
342 |
|
Result := rs; |
343 |
|
end; |
344 |
|
SQL_TEXT: |
345 |
|
begin |
346 |
< |
SetString(rs,FBufPtr,GetDataLength); |
346 |
> |
SetString(rs,PAnsiChar(FBufPtr),GetDataLength); |
347 |
|
SetCodePage(rs,GetCodePage,false); |
348 |
|
Result := rs; |
349 |
|
end |
367 |
|
CheckActive; |
368 |
|
case GetSQLType of |
369 |
|
SQL_LONG: |
370 |
< |
PLong(SQLData)^ := Value; |
370 |
> |
PLong(SQLData)^ := NumericFromRawValues(Value,getScale).getRawValue; |
371 |
|
SQL_SHORT: |
372 |
< |
PShort(SQLData)^ := Value; |
372 |
> |
PShort(SQLData)^ := NumericFromRawValues(Value,getScale).getRawValue; |
373 |
|
SQL_INT64: |
374 |
< |
PInt64(SQLData)^ := Value; |
374 |
> |
PInt64(SQLData)^ := NumericFromRawValues(Value,getScale).getRawValue; |
375 |
|
SQL_TEXT, SQL_VARYING: |
376 |
|
SetAsString(IntToStr(Value)); |
377 |
|
SQL_D_FLOAT, |
385 |
|
Changed; |
386 |
|
end; |
387 |
|
|
388 |
< |
procedure TFBArrayElement.SetAsString(Value: String); |
388 |
> |
procedure TFBArrayElement.SetAsString(Value: AnsiString); |
389 |
|
var len: integer; |
390 |
|
ElementSize: integer; |
391 |
+ |
Int64Value: Int64; |
392 |
+ |
aScale: integer; |
393 |
|
begin |
394 |
|
CheckActive; |
395 |
|
case GetSQLType of |
396 |
|
SQL_BOOLEAN: |
397 |
< |
if CompareText(Value,STrue) = 0 then |
397 |
> |
if AnsiCompareText(Value,STrue) = 0 then |
398 |
|
AsBoolean := true |
399 |
|
else |
400 |
< |
if CompareText(Value,SFalse) = 0 then |
400 |
> |
if AnsiCompareText(Value,SFalse) = 0 then |
401 |
|
AsBoolean := false |
402 |
|
else |
403 |
|
IBError(ibxeInvalidDataConversion,[nil]); |
412 |
|
if Len > 0 then |
413 |
|
Move(Value[1],FBufPtr^,len); |
414 |
|
if Len < ElementSize - 2 then |
415 |
< |
(FBufPtr+len)^ := #0; |
415 |
> |
(FBufPtr+len)^ := 0; |
416 |
|
Changed; |
417 |
|
end; |
418 |
|
|
430 |
|
SQL_SHORT, |
431 |
|
SQL_LONG, |
432 |
|
SQL_INT64: |
433 |
< |
if trim(Value) = '' then |
434 |
< |
SetAsInt64(0) |
433 |
> |
if TryStrToNumeric(Value,Int64Value,aScale) then |
434 |
> |
SetAsNumeric(NumericFromRawValues(Int64Value,aScale)) |
435 |
|
else |
436 |
< |
SetAsInt64(StrToInt(Value)); |
436 |
> |
SetAsCurrency(StrToCurr(Value)); |
437 |
|
|
438 |
|
SQL_D_FLOAT, |
439 |
|
SQL_DOUBLE, |
440 |
|
SQL_FLOAT: |
441 |
< |
if trim(Value) = '' then |
442 |
< |
SetAsDouble(0) |
443 |
< |
else |
444 |
< |
SetAsDouble(StrToFloat(Value)); |
441 |
> |
if TryStrToNumeric(Value,Int64Value,aScale) then |
442 |
> |
SetAsDouble(NumericToDouble(Int64Value,AScale)) |
443 |
> |
else |
444 |
> |
IBError(ibxeInvalidDataConversion,[nil]); |
445 |
> |
|
446 |
> |
SQL_DEC_FIXED, |
447 |
> |
SQL_DEC16, |
448 |
> |
SQL_DEC34, |
449 |
> |
SQL_INT128: |
450 |
> |
SetAsBCD(StrToBCD(Value)); |
451 |
|
|
452 |
|
SQL_TIMESTAMP: |
453 |
|
SetAsDateTime(StrToDateTime(Value)); |
474 |
|
PSingle(SQLData)^ := Value; |
475 |
|
SQL_SHORT: |
476 |
|
if Scale < 0 then |
477 |
< |
PShort(SQLData)^ := AdjustScaleFromDouble(Value,Scale) |
477 |
> |
PShort(SQLData)^ := SafeSmallInt(DoubleToNumeric(Value).AdjustScaleTo(Scale).getRawValue) |
478 |
|
else |
479 |
|
IBError(ibxeInvalidDataConversion, [nil]); |
480 |
|
SQL_LONG: |
481 |
|
if Scale < 0 then |
482 |
< |
PLong(SQLData)^ := AdjustScaleFromDouble(Value,Scale) |
482 |
> |
PLong(SQLData)^ := SafeInteger(DoubleToNumeric(Value).AdjustScaleTo(Scale).getRawValue) |
483 |
|
else |
484 |
|
IBError(ibxeInvalidDataConversion, [nil]); |
485 |
|
SQL_INT64: |
486 |
|
if Scale < 0 then |
487 |
< |
PInt64(SQLData)^ := AdjustScaleFromDouble(Value,Scale) |
487 |
> |
PInt64(SQLData)^ := DoubleToNumeric(Value).AdjustScaleTo(Scale).getRawValue |
488 |
|
else |
489 |
|
IBError(ibxeInvalidDataConversion, [nil]); |
490 |
|
SQL_TEXT, SQL_VARYING: |
510 |
|
if Scale = -4 then |
511 |
|
PCurrency(SQLData)^ := Value |
512 |
|
else |
513 |
< |
PInt64(SQLData)^ := AdjustScaleFromCurrency(Value,Scale); |
513 |
> |
PInt64(SQLData)^ := CurrToNumeric(Value).AdjustScaleTo(Scale).getRawValue; |
514 |
|
Changed; |
515 |
|
end |
516 |
|
end; |
517 |
|
|
518 |
+ |
procedure TFBArrayElement.SetAsBcd(aValue: tBCD); |
519 |
+ |
var C: Currency; |
520 |
+ |
begin |
521 |
+ |
CheckActive; |
522 |
+ |
with FirebirdClientAPI do |
523 |
+ |
case SQLType of |
524 |
+ |
SQL_DEC_FIXED, |
525 |
+ |
SQL_DEC16, |
526 |
+ |
SQL_DEC34: |
527 |
+ |
SQLDecFloatEncode(aValue,SQLType,SQLData); |
528 |
+ |
|
529 |
+ |
SQL_INT128: |
530 |
+ |
StrToInt128(Scale,BcdToStr(aValue),SQLData); |
531 |
+ |
|
532 |
+ |
else |
533 |
+ |
begin |
534 |
+ |
BCDToCurr(aValue,C); |
535 |
+ |
SetAsCurrency(C); |
536 |
+ |
end; |
537 |
+ |
end; |
538 |
+ |
Changed; |
539 |
+ |
end; |
540 |
+ |
|
541 |
+ |
procedure TFBArrayElement.SetAsNumeric(Value: IFBNumeric); |
542 |
+ |
begin |
543 |
+ |
CheckActive; |
544 |
+ |
case GetSQLType of |
545 |
+ |
SQL_LONG: |
546 |
+ |
PLong(SQLData)^ := SafeInteger(Value.AdjustScaleTo(Scale).getRawValue); |
547 |
+ |
SQL_SHORT: |
548 |
+ |
PShort(SQLData)^ := SafeSmallInt(Value.AdjustScaleTo(Scale).getRawValue); |
549 |
+ |
SQL_INT64: |
550 |
+ |
PInt64(SQLData)^ := Value.AdjustScaleTo(Scale).getRawValue; |
551 |
+ |
SQL_TEXT, SQL_VARYING: |
552 |
+ |
SetAsString(Value.getAsString); |
553 |
+ |
SQL_D_FLOAT, |
554 |
+ |
SQL_DOUBLE: |
555 |
+ |
PDouble(SQLData)^ := Value.getAsDouble; |
556 |
+ |
SQL_FLOAT: |
557 |
+ |
PSingle(SQLData)^ := Value.getAsDouble; |
558 |
+ |
else |
559 |
+ |
IBError(ibxeInvalidDataConversion, [nil]); |
560 |
+ |
end; |
561 |
+ |
Changed; |
562 |
+ |
end; |
563 |
+ |
|
564 |
|
procedure TFBArrayElement.SetSQLType(aValue: cardinal); |
565 |
|
begin |
566 |
< |
if aValue = GetSQLType then |
566 |
> |
if aValue <> GetSQLType then |
567 |
|
IBError(ibxeInvalidDataConversion, [nil]); |
568 |
|
end; |
569 |
|
|
570 |
|
{TFBArrayMetaData} |
571 |
|
|
572 |
|
constructor TFBArrayMetaData.Create(aAttachment: IAttachment; |
573 |
< |
aTransaction: ITransaction; relationName, columnName: string); |
573 |
> |
aTransaction: ITransaction; relationName, columnName: AnsiString); |
574 |
|
begin |
575 |
|
inherited Create; |
576 |
+ |
FAttachment := aAttachment; |
577 |
|
LoadMetaData(aAttachment,aTransaction,relationName, columnName); |
578 |
|
end; |
579 |
|
|
580 |
+ |
constructor TFBArrayMetaData.Create(aAttachment: IAttachment; |
581 |
+ |
SQLType: cardinal; tableName: AnsiString; columnName: AnsiString; |
582 |
+ |
Scale: integer; size: cardinal; charSetID: cardinal; dimensions: cardinal; |
583 |
+ |
bounds: TArrayBounds); |
584 |
+ |
var i: integer; |
585 |
+ |
begin |
586 |
+ |
inherited Create; |
587 |
+ |
FAttachment := aAttachment; |
588 |
+ |
with FArrayDesc do |
589 |
+ |
begin |
590 |
+ |
array_desc_dtype := GetDType(SQLType); |
591 |
+ |
array_desc_scale := Scale; |
592 |
+ |
array_desc_length := UShort(size); |
593 |
+ |
StrPLCopy(array_desc_field_name,columnName,sizeof(array_desc_field_name)); |
594 |
+ |
StrPLCopy(array_desc_relation_name,tableName,sizeof(array_desc_relation_name)); |
595 |
+ |
array_desc_dimensions := dimensions; |
596 |
+ |
array_desc_flags := 0; |
597 |
+ |
FCharSetID := charSetID; |
598 |
+ |
for i := 0 to Length(bounds) - 1 do |
599 |
+ |
begin |
600 |
+ |
array_desc_bounds[i].array_bound_lower := bounds[i].LowerBound; |
601 |
+ |
array_desc_bounds[i].array_bound_upper := bounds[i].UpperBound; |
602 |
+ |
end; |
603 |
+ |
end; |
604 |
+ |
end; |
605 |
+ |
|
606 |
|
function TFBArrayMetaData.GetSQLType: cardinal; |
607 |
|
begin |
608 |
|
case FArrayDesc.array_desc_dtype of |
630 |
|
Result := SQL_TYPE_TIME; |
631 |
|
blr_int64: |
632 |
|
Result := SQL_INT64; |
633 |
+ |
blr_sql_time_tz: |
634 |
+ |
Result := SQL_TIME_TZ; |
635 |
+ |
blr_timestamp_tz: |
636 |
+ |
Result := SQL_TIMESTAMP_TZ; |
637 |
+ |
blr_ex_time_tz: |
638 |
+ |
Result := SQL_TIME_TZ_EX; |
639 |
+ |
blr_ex_timestamp_tz: |
640 |
+ |
Result := SQL_TIMESTAMP_TZ_EX; |
641 |
+ |
blr_dec64: |
642 |
+ |
Result := SQL_DEC16; |
643 |
+ |
blr_dec128: |
644 |
+ |
Result := SQL_DEC34; |
645 |
+ |
blr_int128: |
646 |
+ |
Result := SQL_INT128; |
647 |
|
end; |
648 |
|
end; |
649 |
|
|
650 |
< |
function TFBArrayMetaData.GetSQLTypeName: string; |
650 |
> |
function TFBArrayMetaData.GetSQLTypeName: AnsiString; |
651 |
|
begin |
652 |
|
Result := TSQLDataItem.GetSQLTypeName(GetSQLType); |
653 |
|
end; |
654 |
|
|
655 |
|
function TFBArrayMetaData.GetScale: integer; |
656 |
|
begin |
657 |
< |
Result := byte(FArrayDesc.array_desc_scale); |
657 |
> |
Result := FArrayDesc.array_desc_scale; |
658 |
|
end; |
659 |
|
|
660 |
|
function TFBArrayMetaData.GetSize: cardinal; |
662 |
|
Result := FArrayDesc.array_desc_length; |
663 |
|
end; |
664 |
|
|
665 |
< |
function TFBArrayMetaData.GetTableName: string; |
665 |
> |
function TFBArrayMetaData.GetTableName: AnsiString; |
666 |
|
begin |
667 |
|
with FArrayDesc do |
668 |
< |
SetString(Result,PChar(@array_desc_relation_name),sizeof(array_desc_relation_name)); |
668 |
> |
SetString(Result,PAnsiChar(@array_desc_relation_name),sizeof(array_desc_relation_name)); |
669 |
|
Result := trim(Result); |
670 |
|
end; |
671 |
|
|
672 |
< |
function TFBArrayMetaData.GetColumnName: string; |
672 |
> |
function TFBArrayMetaData.GetColumnName: AnsiString; |
673 |
|
begin |
674 |
|
with FArrayDesc do |
675 |
< |
SetString(Result,PChar(@FArrayDesc.array_desc_field_name),sizeof(array_desc_field_name)); |
675 |
> |
SetString(Result,PAnsiChar(@FArrayDesc.array_desc_field_name),sizeof(array_desc_field_name)); |
676 |
|
Result := trim(Result); |
677 |
|
end; |
678 |
|
|
692 |
|
end; |
693 |
|
end; |
694 |
|
|
695 |
+ |
function TFBArrayMetaData.GetDType(SQLType: cardinal): UChar; |
696 |
+ |
begin |
697 |
+ |
case SQLType of |
698 |
+ |
SQL_TEXT: |
699 |
+ |
Result := blr_text; |
700 |
+ |
SQL_SHORT: |
701 |
+ |
Result := blr_short; |
702 |
+ |
SQL_LONG: |
703 |
+ |
Result := blr_long; |
704 |
+ |
SQL_QUAD: |
705 |
+ |
Result := blr_quad; |
706 |
+ |
SQL_FLOAT: |
707 |
+ |
Result := blr_float; |
708 |
+ |
SQL_D_FLOAT: |
709 |
+ |
Result := blr_double; |
710 |
+ |
SQL_TIMESTAMP: |
711 |
+ |
Result := blr_timestamp; |
712 |
+ |
SQL_VARYING: |
713 |
+ |
Result := blr_varying; |
714 |
+ |
SQL_TYPE_DATE: |
715 |
+ |
Result := blr_sql_date; |
716 |
+ |
SQL_TYPE_TIME: |
717 |
+ |
Result := blr_sql_time; |
718 |
+ |
SQL_INT64: |
719 |
+ |
Result := blr_int64; |
720 |
+ |
SQL_TIME_TZ: |
721 |
+ |
Result := blr_sql_time_tz; |
722 |
+ |
SQL_TIMESTAMP_TZ: |
723 |
+ |
Result := blr_timestamp_tz; |
724 |
+ |
SQL_TIME_TZ_EX: |
725 |
+ |
Result := blr_ex_time_tz; |
726 |
+ |
SQL_TIMESTAMP_TZ_EX: |
727 |
+ |
Result := blr_ex_timestamp_tz; |
728 |
+ |
SQL_DEC16: |
729 |
+ |
Result := blr_dec64; |
730 |
+ |
SQL_DEC34: |
731 |
+ |
Result := blr_dec128; |
732 |
+ |
SQL_INT128: |
733 |
+ |
Result := blr_int128; |
734 |
+ |
end; |
735 |
+ |
end; |
736 |
+ |
|
737 |
|
function TFBArrayMetaData.NumOfElements: integer; |
738 |
|
var i: integer; |
739 |
|
Bounds: TArrayBounds; |
741 |
|
Result := 1; |
742 |
|
Bounds := GetBounds; |
743 |
|
for i := 0 to Length(Bounds) - 1 do |
744 |
< |
Result *= (Bounds[i].UpperBound - Bounds[i].LowerBound + 1); |
744 |
> |
Result := Result * (Bounds[i].UpperBound - Bounds[i].LowerBound + 1); |
745 |
|
end; |
746 |
|
|
747 |
|
|
764 |
|
FElementSize := FArrayDesc.array_desc_length; |
765 |
|
case GetSQLType of |
766 |
|
SQL_VARYING: |
767 |
< |
FElementSize += 2; |
767 |
> |
FElementSize := FElementSize + 2; |
768 |
|
SQL_TEXT: |
769 |
< |
FElementSize += 1; |
769 |
> |
FElementSize := FElementSize + 1; |
770 |
|
end; |
771 |
|
FBufSize := FElementSize * l; |
772 |
|
|
773 |
< |
with FirebirdClientAPI do |
773 |
> |
with FFirebirdClientAPI do |
774 |
|
IBAlloc(FBuffer,0,FBufSize); |
775 |
|
|
776 |
|
Dims := GetDimensions; |
822 |
|
InternalPutSlice(Force); |
823 |
|
FModified := false; |
824 |
|
FIsNew := false; |
825 |
+ |
FLoaded := true; |
826 |
|
end; |
827 |
|
|
828 |
< |
function TFBArray.GetOffset(index: array of integer): PChar; |
828 |
> |
function TFBArray.GetOffset(index: array of integer): PByte; |
829 |
|
var i: integer; |
830 |
|
Bounds: TArrayBounds; |
831 |
|
FlatIndex: integer; |
840 |
|
if (index[i] < Bounds[i].LowerBound) or (index[i] > Bounds[i].UpperBound) then |
841 |
|
IBError(ibxeInvalidSubscript,[index[i],i]); |
842 |
|
|
843 |
< |
FlatIndex += FOffsets[i]*(index[i] - Bounds[i].LowerBound); |
843 |
> |
FlatIndex := FlatIndex + FOffsets[i]*(index[i] - Bounds[i].LowerBound); |
844 |
|
end; |
845 |
|
Result := FBuffer + FlatIndex*FElementSize; |
846 |
|
end; |
860 |
|
inherited Create(aTransaction); |
861 |
|
FMetaData := aField; |
862 |
|
FAttachment := aAttachment; |
863 |
+ |
FFirebirdClientAPI := aTransaction.FirebirdAPI; |
864 |
|
FTransactionIntf := aTransaction; |
865 |
|
FTransactionSeqNo := aTransaction.TransactionSeqNo; |
866 |
|
FIsNew := true; |
879 |
|
FMetaData := aField; |
880 |
|
FArrayID := ArrayID; |
881 |
|
FAttachment := aAttachment; |
882 |
+ |
FFirebirdClientAPI := aTransaction.FirebirdAPI; |
883 |
|
FTransactionIntf := aTransaction; |
884 |
|
FTransactionSeqNo := aTransaction.TransactionSeqNo; |
885 |
|
FIsNew := false; |
941 |
|
procedure TFBArray.TransactionEnding(aTransaction: ITransaction; Force: boolean |
942 |
|
); |
943 |
|
begin |
944 |
< |
if (aTransaction = FTransactionIntf) and FModified and not FIsNew then |
944 |
> |
if ((aTransaction as TObject) = (FTransactionIntf as TObject)) and FModified and not FIsNew then |
945 |
|
PutArraySlice(Force); |
946 |
|
end; |
947 |
|
|
950 |
|
Result := FMetaData.GetSQLType; |
951 |
|
end; |
952 |
|
|
953 |
< |
function TFBArray.GetSQLTypeName: string; |
953 |
> |
function TFBArray.GetSQLTypeName: AnsiString; |
954 |
|
begin |
955 |
|
Result := FMetaData.GetSQLTypeName; |
956 |
|
end; |
970 |
|
Result := FMetaData.GetCharSetID; |
971 |
|
end; |
972 |
|
|
973 |
< |
function TFBArray.GetTableName: string; |
973 |
> |
function TFBArray.GetCharSetWidth: integer; |
974 |
> |
begin |
975 |
> |
Result := FMetaData.GetCharSetWidth; |
976 |
> |
end; |
977 |
> |
|
978 |
> |
function TFBArray.GetTableName: AnsiString; |
979 |
|
begin |
980 |
|
Result := FMetaData.GetTableName; |
981 |
|
end; |
982 |
|
|
983 |
< |
function TFBArray.GetColumnName: string; |
983 |
> |
function TFBArray.GetColumnName: AnsiString; |
984 |
|
begin |
985 |
|
Result := FMetaData.GetColumnName; |
986 |
|
end; |
1030 |
|
Result := FElement.GetAsDateTime; |
1031 |
|
end; |
1032 |
|
|
1033 |
+ |
procedure TFBArray.GetAsDateTime(index: array of integer; |
1034 |
+ |
var aDateTime: TDateTime; var dstOffset: smallint; |
1035 |
+ |
var aTimezoneID: TFBTimeZoneID); |
1036 |
+ |
begin |
1037 |
+ |
GetArraySlice; |
1038 |
+ |
FElement.FBufPtr := GetOffset(index); |
1039 |
+ |
FElement.GetAsDateTime(aDateTime,dstOffset,aTimezoneID); |
1040 |
+ |
end; |
1041 |
+ |
|
1042 |
+ |
procedure TFBArray.GetAsDateTime(index: array of integer; |
1043 |
+ |
var aDateTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); |
1044 |
+ |
begin |
1045 |
+ |
GetArraySlice; |
1046 |
+ |
FElement.FBufPtr := GetOffset(index); |
1047 |
+ |
FElement.GetAsDateTime(aDateTime,dstOffset,aTimezone); |
1048 |
+ |
end; |
1049 |
+ |
|
1050 |
+ |
procedure TFBArray.GetAsTime(index: array of integer; var aTime: TDateTime; |
1051 |
+ |
var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime); |
1052 |
+ |
begin |
1053 |
+ |
GetArraySlice; |
1054 |
+ |
FElement.FBufPtr := GetOffset(index); |
1055 |
+ |
FElement.GetAsTime(aTime,dstOffset,aTimezoneID,OnDate); |
1056 |
+ |
end; |
1057 |
+ |
|
1058 |
+ |
procedure TFBArray.GetAsTime(index: array of integer; var aTime: TDateTime; |
1059 |
+ |
var dstOffset: smallint; var aTimezone: AnsiString; OnDate: TDateTime); |
1060 |
+ |
begin |
1061 |
+ |
GetArraySlice; |
1062 |
+ |
FElement.FBufPtr := GetOffset(index); |
1063 |
+ |
FElement.GetAsTime(aTime,dstOffset,aTimezone,OnDate); |
1064 |
+ |
end; |
1065 |
+ |
|
1066 |
+ |
function TFBArray.GetAsUTCDateTime(index: array of integer): TDateTime; |
1067 |
+ |
begin |
1068 |
+ |
GetArraySlice; |
1069 |
+ |
FElement.FBufPtr := GetOffset(index); |
1070 |
+ |
Result := FElement.GetAsUTCDateTime; |
1071 |
+ |
end; |
1072 |
+ |
|
1073 |
|
function TFBArray.GetAsDouble(index: array of integer): Double; |
1074 |
|
begin |
1075 |
|
GetArraySlice; |
1098 |
|
Result := FElement.GetAsShort; |
1099 |
|
end; |
1100 |
|
|
1101 |
< |
function TFBArray.GetAsString(index: array of integer): String; |
1101 |
> |
function TFBArray.GetAsString(index: array of integer): AnsiString; |
1102 |
|
begin |
1103 |
|
GetArraySlice; |
1104 |
|
FElement.FBufPtr := GetOffset(index); |
1112 |
|
Result := FElement.GetAsVariant; |
1113 |
|
end; |
1114 |
|
|
1115 |
+ |
function TFBArray.GetAsBCD(index: array of integer): tBCD; |
1116 |
+ |
begin |
1117 |
+ |
GetArraySlice; |
1118 |
+ |
FElement.FBufPtr := GetOffset(index); |
1119 |
+ |
Result := FElement.GetAsBCD; |
1120 |
+ |
end; |
1121 |
+ |
|
1122 |
|
procedure TFBArray.SetAsInteger(index: array of integer; AValue: integer); |
1123 |
|
begin |
1124 |
|
FElement.FBufPtr := GetOffset(index); |
1161 |
|
FElement.SetAsTime(Value); |
1162 |
|
end; |
1163 |
|
|
1164 |
+ |
procedure TFBArray.SetAsTime(index: array of integer; aValue: TDateTime; OnDate: TDateTime; |
1165 |
+ |
aTimeZoneID: TFBTimeZoneID); |
1166 |
+ |
begin |
1167 |
+ |
FElement.FBufPtr := GetOffset(index); |
1168 |
+ |
FElement.SetAsTime(aValue,OnDate,aTimeZoneID); |
1169 |
+ |
end; |
1170 |
+ |
|
1171 |
+ |
procedure TFBArray.SetAsTime(index: array of integer; aValue: TDateTime; OnDate: TDateTime; |
1172 |
+ |
aTimeZone: AnsiString); |
1173 |
+ |
begin |
1174 |
+ |
FElement.FBufPtr := GetOffset(index); |
1175 |
+ |
FElement.SetAsTime(aValue,OnDate, aTimeZone); |
1176 |
+ |
end; |
1177 |
+ |
|
1178 |
|
procedure TFBArray.SetAsDateTime(index: array of integer; Value: TDateTime); |
1179 |
|
begin |
1180 |
|
FElement.FBufPtr := GetOffset(index); |
1181 |
|
FElement.SetAsDateTime(Value); |
1182 |
|
end; |
1183 |
|
|
1184 |
+ |
procedure TFBArray.SetAsDateTime(index: array of integer; aValue: TDateTime; |
1185 |
+ |
aTimeZoneID: TFBTimeZoneID); |
1186 |
+ |
begin |
1187 |
+ |
FElement.FBufPtr := GetOffset(index); |
1188 |
+ |
FElement.SetAsDateTime(aValue,aTimeZoneID); |
1189 |
+ |
end; |
1190 |
+ |
|
1191 |
+ |
procedure TFBArray.SetAsDateTime(index: array of integer; aValue: TDateTime; |
1192 |
+ |
aTimeZone: AnsiString); |
1193 |
+ |
begin |
1194 |
+ |
FElement.FBufPtr := GetOffset(index); |
1195 |
+ |
FElement.SetAsDateTime(aValue,aTimeZone); |
1196 |
+ |
end; |
1197 |
+ |
|
1198 |
+ |
procedure TFBArray.SetAsUTCDateTime(index: array of integer; |
1199 |
+ |
aUTCTime: TDateTime); |
1200 |
+ |
begin |
1201 |
+ |
FElement.FBufPtr := GetOffset(index); |
1202 |
+ |
FElement.SetAsUTCDateTime(aUTCTime); |
1203 |
+ |
end; |
1204 |
+ |
|
1205 |
|
procedure TFBArray.SetAsDouble(index: array of integer; Value: Double); |
1206 |
|
begin |
1207 |
|
FElement.FBufPtr := GetOffset(index); |
1220 |
|
FElement.SetAsShort(Value); |
1221 |
|
end; |
1222 |
|
|
1223 |
< |
procedure TFBArray.SetAsString(index: array of integer; Value: String); |
1223 |
> |
procedure TFBArray.SetAsString(index: array of integer; Value: AnsiString); |
1224 |
|
begin |
1225 |
|
FElement.FBufPtr := GetOffset(index); |
1226 |
|
FElement.SetAsString(Value); |
1232 |
|
FElement.SetAsVariant(Value); |
1233 |
|
end; |
1234 |
|
|
1235 |
+ |
procedure TFBArray.SetAsBcd(index: array of integer; aValue: tBCD); |
1236 |
+ |
begin |
1237 |
+ |
FElement.FBufPtr := GetOffset(index); |
1238 |
+ |
FElement.SetAsBcd(aValue); |
1239 |
+ |
end; |
1240 |
+ |
|
1241 |
|
procedure TFBArray.SetBounds(dim, UpperBound, LowerBound: integer); |
1242 |
|
begin |
1243 |
|
with (FMetaData as TFBArrayMetaData) do |
1279 |
|
var i,j : integer; |
1280 |
|
begin |
1281 |
|
for i := Length(FEventHandlers) - 1 downto 0 do |
1282 |
< |
if FEventHandlers[i] = Handler then |
1282 |
> |
if (TMethod(FEventHandlers[i]).Code = TMethod(Handler).Code) and |
1283 |
> |
(TMethod(FEventHandlers[i]).Data = TMethod(Handler).Data) then |
1284 |
|
begin |
1285 |
|
for j := i to Length(FEventHandlers) - 2 do |
1286 |
|
FEventHandlers[i] := FEventHandlers[i+1]; |