-
Notifications
You must be signed in to change notification settings - Fork 58
/
FIBDataSet.pas
12756 lines (11575 loc) · 335 KB
/
FIBDataSet.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{***************************************************************}
{ FIBPlus - component library for direct access to Firebird and }
{ InterBase databases }
{ }
{ FIBPlus is based in part on the product }
{ Free IB Components, written by Gregory H. Deatz for }
{ Hoagland, Longo, Moran, Dunst & Doukas Company. }
{ mailto:[email protected] }
{ }
{ Copyright (c) 1998-2012 Devrace Ltd. }
{ Written by Serge Buzadzhy ([email protected]) }
{ }
{ ------------------------------------------------------------- }
{ FIBPlus home page: http://www.fibplus.com/ }
{ FIBPlus support : http://www.devrace.com/support/ }
{ ------------------------------------------------------------- }
{ }
{ Please see the file License.txt for full license information }
{***************************************************************}
unit FIBDataSet;
interface
{$I FIBPlus.inc}
uses
SysUtils, ibase,IB_Intf, ib_externals, fib,
FIBPlatforms,
pFIBProps,pFIBFieldsDescr, DB,FIBCacheManage,
DBCommon,DbConsts,DBParsers,
FIBDatabase, FIBQuery, FIBMiscellaneous,SqlTxtRtns,pFIBLists,FIBCloneComponents ,
pFIBInterfaces,pFIBEventLists,
Classes,StdFuncs
{$IFNDEF NO_GUI}
{$IFDEF D_XE2}
,System.UITypes
{$ELSE}
,Forms,Controls // IS GUI units
{$ENDIF}
{$ENDIF}
{$IFDEF D6+},FMTBcd, Variants{$ENDIF}
;
const
vBufferCacheSize = 32; // Allocate cache in this many record chunks
vMinBufferChunksForLimCache=100;
type
{$IFNDEF D_XE4}
{$IFDEF D2009+}
TRecordBuffer=PByte;
{$ELSE}
TRecordBuffer=PChar ;
{$ENDIF}
{$ENDIF}
TFIBCustomDataSet = class;
TFIBDataSet = class;
TBlobDataArray =array[0..0] of TFIBBlobStream;
PBlobDataArray = ^TBlobDataArray;
TFieldData =record
fdIsNull: Boolean;
end;
PFieldData = ^TFieldData;
TCachedUpdateStatus =
(cusUnmodified, cusModified, cusInserted,cusDeleted, cusUninserted,cusDeletedApplied);
TRecordData =packed record
rdRecordNumber: Long;
rdBookmarkFlag: TBookmarkFlag;
rdFlags : Byte; // 3 bit - TCachedUpdateStatus
// rdCachedUpdateStatus: TCachedUpdateStatus;// Bit 7 is Calcs
rdFields: array[1..1] of TFieldData;
end;
PRecordData = ^TRecordData;
TSavedRecordData =packed record
rdFlags : Byte;
rdFields: array[1..1] of TFieldData;
end;
PSavedRecordData = ^TSavedRecordData;
TFIBStringField = class(TStringField)
private
FPrepared:Boolean;
vInSetAsString :boolean;
FEmptyStrToNull :boolean;
FDefaultValueEmptyString:boolean;
FValueLength :integer;
FCollateNumber :Byte;
FCharacterSetName :string;
FNeedUnicodeConvert:boolean;
FIsDBKey :boolean;
FReservedBuffer :TDataBuffer;
// FStringBuffer :FIBByteString;
FDataSet :TDataSet;
function GetAsDB_KEY:string;
procedure Prepare;
procedure UnPrepare(Sender:TObject);
function GetDataToReserveBuffer:boolean;
function InternalGetAsString(var IsNull:boolean):string;
protected
class procedure CheckTypeSize(Value: Integer); override;
procedure SetDataSet(ADataSet: TDataSet); override;
function GetAsString: string; override;
function GetAsNativeData: FIBByteString;
procedure SetAsNativeData(const Value: FIBByteString);
function GetAsVariant: Variant; override;
procedure SetAsString(const Value: string); override;
procedure SetSize(Value: Integer); override;
{$IFDEF UNICODE_TO_STRING_FIELDS}
function GetDataSize: Integer; override;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
function IsDBKey:boolean;
function SqlSubType:integer;
function CharacterSet :string;
procedure Clear; override;
property DefaultValueEmptyString:boolean read FDefaultValueEmptyString write FDefaultValueEmptyString;
property AsNativeData:FIBByteString read GetAsNativeData;
property AsOctetsData:FIBByteString read GetAsNativeData write SetAsNativeData;
published
property EmptyStrToNull:boolean read FEmptyStrToNull write FEmptyStrToNull default false;
end;
TFIBWideStringField = class(TWideStringField)
protected
FPrepared:Boolean;
FSqlSubType :Integer;
FDataSize :Integer;
FCollateNumber :Byte;
FCharacterSetName :string;
FDataSet:TDataSet;
FEmptyStrToNull :boolean;
FCreated:boolean;
function GetDataSize: Integer; override;
procedure SetSize(Value: Integer); override;
procedure Prepare;
procedure UnPrepare(Sender:TObject);
procedure SetDataSet(ADataSet: TDataSet); override;
{$IFDEF D2006+}
procedure CopyData(Source, Dest: Pointer); override;
{$ENDIF}
protected
FReservedBuffer :TDataBuffer;
FStringBuffer :FIBByteString;
FNeedUnicodeConvert:boolean;
FValueLength:Integer;
function GetBytesValue(var Value: FIBByteString): Boolean;
function GetDataToReserveBuffer:boolean;
function GetAsNativeData: FIBByteString ;
procedure SetAsNativeData(const Value: FIBByteString);
function GetAsString: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Clear; override;
function CharacterSet :string;
function SqlSubType:Integer;
function CollateNumber :Byte;
property AsNativeData:FIBByteString read GetAsNativeData write SetAsNativeData;
published
property EmptyStrToNull:boolean read FEmptyStrToNull write FEmptyStrToNull default false;
end;
TFIBLargeIntField = class(TLargeIntField)
private
function GetOldAsInt64:Int64;
protected
procedure SetVarValue(const Value: Variant); override;
public
property OldValue:Int64 read GetOldAsInt64;
end;
TFIBIntegerField = class(TIntegerField)
protected
function GetAsBoolean: Boolean; override;
procedure SetAsBoolean(Value: Boolean); override;
public
procedure Clear; override;
constructor Create(AOwner: TComponent); override;
end;
TFIBDateField = class(TDateField)
protected
{$IFDEF D_XE3}
procedure SetAsDateTime(Value: TDateTime); override;
{$ENDIF}
public
end;
TFIBTimeField = class(TTimeField)
private
FShowMsec:boolean;
protected
procedure GetText(var Text: string; DisplayText: Boolean); override;
{$IFDEF D_XE3}
procedure SetAsDateTime(Value: TDateTime); override;
{$ENDIF}
public
published
property ShowMsec:boolean read FShowMsec write FShowMsec default False;
end;
TFIBDateTimeField = class(TDateTimeField)
private
FShowMsec:boolean;
function GetAsTimeStamp:TTimeStamp;
procedure SetAsTimeStamp(const Value:TTimeStamp);
protected
procedure GetText(var Text: string; DisplayText: Boolean); override;
{$IFDEF D_XE3}
procedure SetAsDateTime(Value: TDateTime); override;
{$ENDIF}
public
property AsTimeStamp:TTimeStamp read GetAsTimeStamp write SetAsTimeStamp;
published
property ShowMsec:boolean read FShowMsec write FShowMsec default False;
end;
TFIBBlobField = class(TBlobField)
private
FSubType:SmallInt;
FIsClientCalcField:boolean;
protected
function GetAsVariant: Variant; override;
function GetBlobId:TISC_QUAD;
function GetIsNull:boolean; override;
public
function GetBlobInfo:TBlobInfo;
property SubType:SmallInt read FSubType;
property Blob_ID:TISC_QUAD read GetBlobId;
published
property IsClientField:boolean read FIsClientCalcField write FIsClientCalcField default False;
end;
//TNT Controls Interface
IWideStringField = interface
['{679C5F1A-4356-4696-A8F3-9C7C6970A9F6}']
function GetAsWideString: {$IFDEF D2009+}UnicodeString; {$ELSE} WideString; {$ENDIF}
procedure SetAsWideString(const Value: {$IFDEF D2009+}UnicodeString {$ELSE} WideString {$ENDIF});
function GetWideDisplayText: WideString;
function GetWideEditText: WideString;
procedure SetWideEditText(const Value: WideString);
//--
property AsWideString: {$IFDEF D2009+}UnicodeString {$ELSE} WideString {$ENDIF} read GetAsWideString write SetAsWideString{inherited};
property WideDisplayText: WideString read GetWideDisplayText;
property WideText: WideString read GetWideEditText write SetWideEditText;
end;
TFIBMemoField = class(TMemoField,IWideStringField)
private
FCharSetID:integer;
FSubType:SmallInt;
function GetWideDisplayText: WideString;
function GetWideEditText: WideString;
procedure SetWideEditText(const Value: WideString);
protected
procedure SetAsVariant(const Value: Variant); override;
{$IFDEF D2009+}
function GetAsAnsiString: AnsiString; override;
{$ENDIF}
{$IFDEF D_XE3+}
procedure SetAsAnsiString(const Value: AnsiString); override;
{$ENDIF}
public
function GetAsWideString: {$IFDEF D2009+}UnicodeString; {$ELSE} WideString; {$ENDIF} {$IFDEF D2006+} override;{$ENDIF}
procedure SetAsWideString(const aValue:{$IFDEF D2009+} UnicodeString{$ELSE} WideString {$ENDIF});{$IFDEF D2006+} override; {$ENDIF}
function GetAsVariant: Variant; override;
function GetAsString: string; override;
procedure SetAsString(const Value: string); override;
function GetBlobId:TISC_QUAD;
public
function GetBlobInfo:TBlobInfo;
property SubType:SmallInt read FSubType;
procedure InternalSetCharSet(aValue:integer); // Internal use
property Blob_ID:TISC_QUAD read GetBlobId;
end;
TFIBSmallIntField =class(TSmallintField)
protected
function GetAsBoolean: Boolean; override;
procedure SetAsBoolean(Value: Boolean); override;
end;
TFIBFloatField =class(TFloatField)
private
FRoundByScale:boolean;
function GetScale:integer;
protected
procedure SetAsFloat(Value: Double); override;
procedure GetText(var Text: string; DisplayText: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
property Scale:integer read GetScale;
published
property RoundByScale:boolean read FRoundByScale write FRoundByScale default True;
end;
TFIBBCDField = class(TBCDField)
private
FDataAsComp :boolean;
FDataSet :TDataSet;
function ServerType:integer;
protected
procedure LoadRoundByScale(Reader: TReader);
procedure DefineProperties(Filer: TFiler); override;
procedure SetDataSet(ADataSet: TDataSet); override;
class procedure CheckTypeSize(Value: Integer); override;
function GetAsCurrency: Currency; override;
function GetAsString: string; override;
function GetAsVariant: Variant; override;
function GetDataSize: Integer; override;
procedure GetText(var Text: string; DisplayText: Boolean); override;
function GetValue(var Value: Currency): Boolean;
procedure SetAsString(const Value: string); override;
procedure SetAsCurrency(Value: Currency); override;
{$IFNDEF NO_USE_COMP}
function GetAsComp: comp;
procedure SetAsComp(Value: comp);
{$ENDIF}
function GetAsExtended: Extended; {$IFDEF D2009+} override; {$ENDIF}
procedure SetAsExtended(Value: Extended); {$IFDEF D2009+} override; {$ENDIF}
function GetAsInt64: Int64;
procedure SetAsInt64(const Value: Int64);
function GetAsBCD: TBcd;{$IFDEF D6+} override;{$ENDIF}
procedure SetAsBCD(const Value: TBcd);{$IFDEF D6+} override;{$ENDIF}
procedure SetVarValue(const Value: Variant); override;
function GetInternalData(var ValueIsNull:boolean):Int64;
function GetInternalOldData(var OldIsNull:boolean):Int64;
function GetData(Buffer: Pointer): Boolean;
public
constructor Create(AOwner: TComponent); override;
{$IFDEF D6+}
procedure AddExtended(const Value:Extended);
procedure SubtractExtended(const Value:Extended);
procedure MultiplyExtended(const Value:Extended);
procedure DivideExtended(const Value:Extended);
procedure AddBCD(const Value:TBCD);
procedure SubtractBCD(const Value:TBCD);
procedure MultiplyBCD(const Value:TBCD);
procedure DivideBCD(const Value:TBCD);
{$ENDIF}
property AsInt64:Int64 read GetAsInt64 write SetAsInt64;
procedure Assign(Source: TPersistent); override;
function FieldModified:boolean;
property AsBcd: TBcd read GetAsBcd write SetAsBcd;
{$IFNDEF NO_USE_COMP}
property AsComp: Comp read GetAsComp write SetAsComp;
{$ENDIF}
property AsExtended: Extended read GetAsExtended write SetAsExtended;
property Value : Variant read GetAsVariant write SetVarValue;
published
property Size default 8;
end;
TFIBGuidField= class (TGuidField)
private
FBuffer:FIBByteString;
pBuffer:Pointer;
protected
class procedure CheckTypeSize(Value: Integer); override;
procedure SetAsString(const Value: string); override;
{$IFDEF D_25}
function GetAsGuid: TGUID; override;
procedure SetAsGuid(const Value: TGUID); override;
{$ELSE}
function GetAsGuid: TGUID;
procedure SetAsGuid(const Value: TGUID);
{$ENDIF}
function GetAsVariant: variant; override;
procedure SetAsVariant(const Value: Variant); override;
public
constructor Create(AOwner: TComponent); override;
property AsGuid: TGUID read GetAsGuid write SetAsGuid;
end;
TFIBBooleanField= class (TBooleanField)
private
FStringFalse:string;
FStringTrue :string;
protected
function StoreStrFalse:boolean;
function StoreStrTrue :boolean;
function GetAsInteger: Longint; override;
procedure SetAsString(const Value: string);override;
procedure SetVarValue(const Value: Variant); override;
procedure SetAsInteger(Value: Longint);override;
procedure SetAsBoolean(Value: Boolean); override;
function GetDataSize: Integer; override;
function GetAsString: string; override;
function GetAsBoolean: Boolean; override;
function GetAsVariant: Variant; override;
public
constructor Create(AOwner: TComponent); override;
published
property StringFalse:string read FStringFalse write FStringFalse
stored StoreStrFalse
;
property StringTrue :string read FStringTrue write FStringTrue
stored StoreStrTrue
;
end;
{$IFDEF SUPPORT_ARRAY_FIELD}
TFIBArrayField=class(TBytesField)
private
FOldValueBuffer:PAnsiChar;
function GetFIBXSQLVAR:TFIBXSQLVAR;
protected
procedure GetText(var Text: string; DisplayText: Boolean); override;
function GetDimCount:integer;
function GetElementType:TFieldType;
function GetDimension(Index:integer):TISC_ARRAY_BOUND;
function GetArraySize:integer;
procedure SaveOldBuffer ;
procedure RestoreOldBuffer;
function GetArrayId:TISC_QUAD;
function GetAsVariant: Variant; override;
procedure SetAsVariant(const Value: Variant); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property DimensionCount:integer read GetDimCount;
property ElementType:TFieldType read GetElementType;
property Dimension[Index: Integer]: TISC_ARRAY_BOUND read GetDimension;
property ArraySize:Integer read GetArraySize;
property ArrayID:TISC_QUAD read GetArrayId;
end;
{$ENDIF}
TUpdateKinds = set of TUpdateKind;
TFIBUpdateAction = (uaFail, uaAbort, uaSkip, uaRetry, uaApply, uaApplied);
TFIBUpdateErrorEvent = procedure(DataSet: TDataSet; E: EFIBError;
UpdateKind: TUpdateKind; var UpdateAction: TFIBUpdateAction) of object;
TFIBUpdateRecordEvent = procedure(DataSet: TDataSet; UpdateKind: TUpdateKind;
var UpdateAction: TFIBUpdateAction) of object;
TFIBAfterUpdateRecordEvent = procedure(DataSet: TDataSet; UpdateKind: TUpdateKind;
var Resume:boolean) of object;
TFIBUpdateRecordTypes = set of TCachedUpdateStatus;
TOnFetchRecord =procedure (FromQuery: TFIBQuery;RecordNumber:integer;
var StopFetching:boolean
) of object;
TpSQLKind = (skModify, skInsert, skDelete, skRefresh,
skMerge
);
TDispositionFieldType= (dfNormal,dfRRecNumber);
TExtLocateOption =(eloCaseInsensitive, eloPartialKey,eloWildCards,
eloInSortedDS,eloNearest,eloInFetchedRecords
);
TExtLocateOptions=set of TExtLocateOption;
TLocateKind =(lkStandard,lkNext,lkPrior);
TSortFieldInfo=record
FieldName:string;
InDataSetIndex:integer;
InOrderIndex:integer;
Asc :boolean;
NullsFirst:boolean;
end;
TFIBDataLink = class(TDetailDataLink)
protected
FDataSet: TFIBCustomDataSet;
protected
procedure ActiveChanged; override;
procedure RecordChanged(Field: TField); override;
procedure CheckBrowseMode; override;
procedure DataSetChanged; override;
function GetDetailDataSet: TDataSet; override;
public
constructor Create(ADataSet: TFIBCustomDataSet);
destructor Destroy; override;
end;
TFIBBookmark = packed record
bRecordNumber:integer;
bActiveRecord:integer;
end;
PFIBBookMark=^TFIBBookmark;
(*
* TFIBCustomDataSet - declaration
*)
TTransactionKind=(tkReadTransaction,tkUpdateTransaction);
TCompareFieldValues= function (Field:TField;const S1,S2:variant):integer of object;
TRecordsPartition = record
BeginPartRecordNo: Integer;
EndPartRecordNo : Integer;
IncludeBof : boolean;
IncludeEof : boolean;
end;
PRecordsPartition=^TRecordsPartition;
TCacheModelKind=(cmkStandard,cmkLimitedBufferSize);
TCacheModelOptions = class(TPersistent)
private
vOwner:TFIBCustomDataSet;
FCacheModelKind:TCacheModelKind;
FBufferChunks :Integer;
FPlanForDescSQLs:string;
FBlobCacheLimit :integer;
procedure SetBufferChunks(Value: Integer);
procedure SetCacheModelKind(Value:TCacheModelKind);
public
constructor Create(Owner:TFIBCustomDataSet);
published
property CacheModelKind:TCacheModelKind read FCacheModelKind write SetCacheModelKind default cmkStandard;
property BufferChunks: Integer read FBufferChunks write SetBufferChunks default vBufferCacheSize;
property PlanForDescSQLs:string read FPlanForDescSQLs write FPlanForDescSQLs;
property BlobCacheLimit :integer read FBlobCacheLimit write FBlobCacheLimit default 0;
end;
TUpdateBlobInfo=(ubiCheckIsNull,ubiPost,ubiCancel,ubiClearOldValue,ubiRefresh);
TOnFillClientBlob=procedure(DataSet:TFIBCustomDataSet;Field:TFIBBlobField;Stream:TFIBBlobStream) of object;
TOnBlobFieldProcessing=procedure(Field:TBlobField;BlobSize:integer;Progress:integer;var Stop:boolean) of object;
TDataSetRunStateValue=(drsInCacheRefresh,drsInSort,drsInOpenByTimer,
drsInFilterProc,drsInGetRecordProc,drsInGotoBookMark, drsInClone,
drsInApplyUpdates,drsInRefreshClientFields,drsDontCheckInactive,
drsForceCreateCalcFields,drsInRefreshRow,drsInMoveRecord,drsInCacheDelete,
drsInFetchingAll,drsInLoaded,
drsGetBlobStream,drsInLoadFromStream,drsInFieldValidate ,drsInFieldAsData,drsInPost
);
TDataSetRunState=set of TDataSetRunStateValue; //InternalUse
TFilteredCacheInfo =
record
AllRecords: integer;
FilteredRecords: integer;
NonVisibleRecords: TSortedList;
end;
{$IFDEF D_XE2}
EventInfo =NativeInt;
{$ELSE}
EventInfo =Longint;
{$ENDIF}
TFIBCustomDataSet = class({$IFDEF TWideDataSet}TWideDataset{$ELSE}TDataset{$ENDIF},ISQLObject,IFIBDataSet)
protected
(*
* Fields, and internal objects
*)
FBase: TFIBBase; (* Manages database and transaction *)
FBlobCacheBufferOffset: Integer;
FBlobCacheOffset: Integer;
FBlobStreamList: TList;
FOpenedBlobStreams: TList;
FRecordsCache:TRecordsCache;
FBufferChunkSize,
FBPos,
FOBPos,
FBEnd,
FOBEnd: DWORD;
FCachedUpdates: Boolean;
FCalcFieldsOffset: Integer;
FCurrentRecord: Long;
FDeletedRecords: Long; (* How many records have been deleted? *)
FSourceLink: TFIBDataLink;
FOpen: Boolean; (* Is the dataset open? *)
FPrepared: Boolean;
FQDelete,
FQInsert,
FQRefresh,
FQSelect,
FQUpdate: TFIBQuery; (* Dataset management queries *)
FRecordBufferSize: Integer;
FBlockReadSize : Integer;
FRecordCount: Integer;
FAllRecordCount:integer;
FRecordSize: Integer;
vDisableScrollCount:integer;
FDatabaseDisconnecting,
FDatabaseDisconnected,
FDatabaseFree : TNotifyEvent;
FOnUpdateError : TFIBUpdateErrorEvent;
FOnUpdateRecord: TFIBUpdateRecordEvent;
FAfterUpdateRecord: TFIBAfterUpdateRecordEvent;
FTransactionEnding: TNotifyEvent;
FTransactionEnded : TNotifyEvent;
FTransactionFree : TNotifyEvent;
FBeforeStartTr:TNotifyEvent ;
FAfterStartTr :TNotifyEvent ;
FBeforeEndTr :TEndTrEvent ;
FAfterEndTr :TEndTrEvent ;
FBeforeStartUpdTr:TNotifyEvent ;
FAfterStartUpdTr :TNotifyEvent ;
FBeforeEndUpdTr :TEndTrEvent ;
FAfterEndUpdTr :TEndTrEvent ;
FUpdatesPending: Boolean;
FUpdateRecordTypes: TFIBUpdateRecordTypes;
FUniDirectional: Boolean;
FOnGetRecordError: TDataSetErrorEvent;
FOptions:TpFIBDsOptions;
FDetailConditions:TDetailConditions;
vInspectRecno:integer;
vTypeDispositionField:TDispositionFieldType;
vTimerForDetail:TFIBTimer;
vScrollTimer :TFIBTimer;
FDisableCOCount:integer;
FDisableCalcFieldsCount:integer;
FPrepareOptions:TpPrepareOptions;
vSelectSQLTextChanged:boolean;
FRefreshTransactionKind:TTransactionKind;
FAutoCommit:boolean;
FWaitEndMasterInterval:integer;
FOnFieldChange:TFieldNotifyEvent;
FOnFillClientBlob:TOnFillClientBlob;
FOnBlobFieldRead :TOnBlobFieldProcessing;
FOnBlobFieldWrite:TOnBlobFieldProcessing;
FWritingBlob:TField;
vPredState : TDataSetState;
vrdFieldCount :integer;
FStringFieldCount :integer;
FFilterParser : TExpressionParser;
FAllowedUpdateKinds: TUpdateKinds;
FRunState:TDataSetRunState;
vSimpleBookMark:Integer;
vCalcFieldsSavedCache:boolean;
FFieldOriginRule:TFieldOriginRule;
FFilteredCacheInfo: TFilteredCacheInfo;
protected
FAutoUpdateOptions: TAutoUpdateOptions;
{$IFDEF CSMonitor}
FCSMonitorSupport: TCSMonitorSupport;
procedure SetCSMonitorSupport(Value:TCSMonitorSupport);
{$ENDIF}
function IsDBKeyField(Field:TObject):boolean;
// GB
procedure CheckDataFields(FieldList:TList; const CallerProc:string);
procedure PrepareAdditionalSelects;
function CompareBookMarkAndRecno(BookMark:TBookMark; Rno:integer;OnlyFields:boolean=False ):boolean;
function RefreshAround(BaseQuery: TFIBQuery; var BaseRecNum:integer;
IgnoreEmptyBaseQuery:boolean = True;ReopenBaseQuery:boolean = True
):boolean;
//End GB
private
// GB
FCacheModelOptions:TCacheModelOptions;
vPartition :PRecordsPartition;
FQCurrentSelect :TFIBQuery;
FQSelectPart :TFIBQuery;
FQSelectDescPart:TFIBQuery;
FQSelectDesc :TFIBQuery;
FQBookMark :TFIBQuery;
FKeyFieldsForBookMark :TStrings;
FSortFields:variant;
function CanHaveLimitedCache:boolean;
procedure SetCacheModelOptions(aCacheModelOptions:TCacheModelOptions);
function GetBufferChunks:Integer;
procedure SetBufferChunks(Value:integer);
procedure ShiftCurRec;
//End GB
function StoreUpdTransaction: Boolean;
procedure SetOnEndScroll(Event:TDataSetNotifyEvent);
function GetDefaultFields:boolean;
procedure ClearBlobStreamList;
function CreateInternalQuery(const QName:string):TFIBQuery;
function GetGroupByString: string;
function GetMainWhereClause: string;
procedure SetGroupByString(const Value: string);
procedure SetMainWhereClause(const Value: string);
function GetPlanClause: string;
procedure SetPlanClause(const Value: string);
protected
FOnCompareFieldValues:TCompareFieldValues;
function CompareFieldValues(Field:TField;const S1,S2:variant):integer; virtual;
public
function AnsiCompareString(Field:TField;const val1, val2: variant): Integer;
function StdAnsiCompareString(Field:TField;const S1, S2: variant): Integer;
function StdCompareValues(Field:TField;const S1, S2: variant): Integer;
published
property OnCompareFieldValues:TCompareFieldValues read FOnCompareFieldValues
write FOnCompareFieldValues;
protected
{$DEFINE FIB_INTERFACE}
{$I FIBDataSetPT.inc}
{$UNDEF FIB_INTERFACE}
protected
function GetXSQLVAR(Fld:TField):TXSQLVAR;
function GetFieldScale(Fld:TNumericField):Short;
function GetUpdateTransaction:TFIBTransaction;
(*
* Routines for managing access to the database, etc... They have
* nothing to do with TDataset.
*)
function AdjustCurrentRecord(Buffer: Pointer; GetMode: TGetMode): TGetResult;
function CanEdit: Boolean; virtual;
function CanInsert: Boolean; virtual;
function CanDelete: Boolean; virtual;
procedure CheckFieldCompatibility(Field: TField; FieldDef: TFieldDef); override;
procedure CheckInactive; override;
procedure CheckEditState;
procedure UpdateBlobInfo(Buff: Pointer;Operation:TUpdateBlobInfo;ClearModified,ForceWrite:boolean
; Field:TField=nil
);
procedure CallBackBlobWrite(BlobSize:integer; BytesProcessing:integer; var Stop:boolean);
(*
* When copying a given record buffer, should we overwrite
* the pointers to "memory" or should we just copy the
* contents?
*)
procedure CopyRecordBuffer(Source, Dest: Pointer);
procedure DoDatabaseDisconnecting(Sender: TObject);
procedure DoDatabaseDisconnected(Sender: TObject);
procedure DoDatabaseFree(Sender: TObject);
procedure DoTransactionEnding(Sender: TObject); virtual;
procedure DoTransactionEnded(Sender: TObject); virtual;
procedure DoTransactionFree(Sender: TObject);
procedure DoBeforeStartTransaction(Sender: TObject);
procedure DoAfterStartTransaction(Sender: TObject);
procedure DoBeforeEndTransaction(EndingTR:TFIBTransaction;Action: TTransactionAction;
Force: Boolean);
procedure DoAfterEndTransaction(EndingTR:TFIBTransaction;Action: TTransactionAction;
Force: Boolean);
procedure DoBeforeStartUpdateTransaction(Sender: TObject);
procedure DoAfterStartUpdateTransaction(Sender: TObject);
procedure DoBeforeEndUpdateTransaction(EndingTR:TFIBTransaction;Action: TTransactionAction;
Force: Boolean);
procedure DoAfterEndUpdateTransaction(EndingTR:TFIBTransaction;Action: TTransactionAction;
Force: Boolean); virtual;
procedure FetchCurrentRecordToBuffer(
Qry: TFIBQuery; RecordNumber: Integer;Buffer: TRecordBuffer
);
procedure FetchRecordToCache(Qry: TFIBQuery; RecordNumber: Integer);
procedure InitDataSetSchema;
function GetActiveBuf: TRecordBuffer;
function GetDatabase: TFIBDatabase;
function GetDBHandle: PISC_DB_HANDLE;
function GetDeleteSQL: TStrings;
function GetInsertSQL: TStrings;
function GetParams: TFIBXSQLDA;
function GetRefreshSQL: TStrings;
function GetSelectSQL: TStrings;
function GetStatementType: TFIBSQLTypes;
function GetUpdateSQL: TStrings;
function GetTransaction: TFIBTransaction;
function GetTRHandle: PISC_TR_HANDLE;
procedure InternalDeleteRecord(Qry: TFIBQuery; Buff: Pointer);virtual;
{$DEFINE FIB_INTERFACE}
{$I FIBDataSetLocate.inc}
{$UNDEF FIB_INTERFACE}
function InternalLocate(const KeyFields: string; KeyValues:array of Variant;
Options: TExtLocateOptions ;FromBegin:boolean = False;LocateKind:TLocateKind = lkStandard;
ResyncToCenter:boolean=False
): Boolean; virtual;
function InternalLocateForLimCache(
const KeyFields: string; const KeyValues:array of Variant;
Options: TExtLocateOptions; LocateKind:TLocateKind = lkStandard;aQLocate:TFIBQuery=nil
): Boolean;
function InternalExtLocate(const KeyFields: string; const KeyValues:Variant;
Options: TExtLocateOptions;LocateKind:TLocateKind):Boolean;
procedure InternalPostRecord(Qry: TFIBQuery; Buff: Pointer); virtual;
function InternalRefreshRow(Qry: TFIBQuery; Buff:TRecordBuffer) :boolean;
procedure InternalRevertRecord(RecordNumber: Integer;WithUnInserted:boolean);
function IsVisibleStat(Buffer: TRecordBuffer): Boolean;
function IsVisible(Buffer: TRecordBuffer): Boolean; virtual;
procedure SaveOldBuffer(Buffer: TRecordBuffer);
procedure SetDatabase(Value: TFIBDatabase);
procedure LiveChangeDatabase(Value: TFIBDatabase); // internal use
procedure SetDeleteSQL(Value: TStrings);
procedure SetInsertSQL(Value: TStrings);
procedure SetQueryParams(Qry: TFIBQuery; Buffer: Pointer);
procedure SetRefreshSQL(Value: TStrings);
procedure SetSelectSQL(Value: TStrings);
procedure SetUpdateSQL(Value: TStrings);
procedure SetTransaction(Value: TFIBTransaction);
procedure LiveChangeTransaction(Value: TFIBTransaction); // internal use
procedure SetUpdateTransaction(Value:TFIBTransaction) ; virtual;
procedure SetUpdateRecordTypes(Value: TFIBUpdateRecordTypes);
procedure SetUniDirectional(Value: Boolean);
procedure SetPrepareOptions(Value:TpPrepareOptions); virtual;
procedure SetRefreshTransactionKind(const Value: TTransactionKind);
procedure SourceChanged;
procedure SourceDisabled;
protected
FParams: TParams;
procedure SQLChanging(Sender: TObject); virtual;
procedure ReadRecordCache(RecordNumber: Integer; Buffer: TRecordBuffer;
ReadOldBuffer: Boolean; Shift:integer=0);
procedure WriteRecordCache(RecordNumber: Integer; Buffer: TRecordBuffer);
function GetNewBuffer:TRecordBuffer;
function GetOldBuffer(aRecordNo:integer =-1):TRecordBuffer;
procedure CheckUpdateTransaction;
protected
FValidatingFieldBuffer:TDataBuffer;
FValidatedField:TField;
FValidatedRec:Integer;
vFieldDescrList:TFIBFieldDescrList;
FFNFields: TStringList;
(*
* Routines from TDataset that need to be overridden to use the IB API
* directly.
*)
vIgnoreLocRecno:integer;
vControlsEnabled:boolean;
FOnEnableControls:TDataSetNotifyEvent;
FOnDisableControls:TDataSetNotifyEvent;
FOnEndScroll:TDataSetNotifyEvent;
FCachedActive :boolean;
vNeedReloadClientBlobs:boolean;
vBeforeCloseEvents : TNotifyEventList;
vAfterOpenEvents : TNotifyEventList;
vBeforeOpenEvents : TNotifyEventList;
procedure SetActive(Value: Boolean); override;
procedure DataEvent(Event: TDataEvent; Info: EventInfo); override;
procedure SetStateFieldValue(State: TDataSetState; Field: TField; const Value: Variant); override;
procedure DoOnDisableControls(DataSet:TDataSet);
procedure DoOnEnableControls(DataSet:TDataSet);
function AllocRecordBuffer: TRecordBuffer; override; (* abstract *)
procedure InternalDoBeforeOpen; virtual;
procedure DoBeforeOpen; override;
procedure DoAfterOpen; override;
procedure DoBeforeClose; override;
procedure DoAfterClose; override;
procedure DoBeforeCancel; override;
procedure DoAfterCancel; override;
procedure DoBeforeDelete; override;
procedure DoBeforeEdit; override;
procedure DoBeforeInsert; override;
procedure DoBeforeScroll; override;
procedure DoAfterScroll; override;
procedure DoBeforePost; override;
procedure DoAfterInsert; override;
procedure DoAfterPost; override;
procedure DoAfterDelete; override;
procedure DoOnEndScroll(Sender:TObject);
procedure DoOnPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); virtual;
procedure FreeRecordBuffer(var Buffer: TRecordBuffer); override; (* abstract *)
procedure GetBookmarkData(Buffer: TRecordBuffer; Data: Pointer); override; (* abstract *)
function GetBookmarkFlag(Buffer: TRecordBuffer): TBookmarkFlag; override; (* abstract *)
function GetCanModify: Boolean; override;
function GetDataSource: TDataSource; override;
function GetFieldClass(FieldType: TFieldType): TFieldClass; override;
function GetRecNo: Integer; override;
function GetRealRecNo: Integer;
procedure TryDesignPrepare;
{$IFDEF D_XE4}
procedure GetBookmarkData(Buffer: TRecordBuffer; Data: TBookmark); override;
procedure DataConvert(Field: TField; Source:TValueBuffer; var Dest: TValueBuffer; ToNative: Boolean); override;
{$ELSE}
{$IFDEF D_XE3}
procedure GetBookmarkData(Buffer: TRecordBuffer; Data: TBookmark); override;
procedure DataConvert(Field: TField; Source, Dest: TValueBuffer; ToNative: Boolean); override;
{$ENDIF}
{$ENDIF}
protected
procedure PrepareQuery(KindQuery: TpSQLKind);
procedure PrepareBookMarkSize;
procedure ClearCalcFields(Buffer: TRecordBuffer); override;
procedure GetCalcFields(Buffer: TRecordBuffer); override;
function GetRecord(Buffer: TRecordBuffer; GetMode: TGetMode;
DoCheck: Boolean): TGetResult; override; (* abstract *)
function GetRecordCount: Integer; override;
function GetRecordSize: Word; override; (* abstract *)
procedure InternalAddRecord(Buffer: Pointer; Append: Boolean); override; (* abstract *)
procedure InternalCancel; override;
procedure InternalClose; override; (* abstract *)
procedure CloseCursor; override;
procedure InternalDelete; override; (* abstract *)
procedure InternalFirst; override; (* abstract *)
procedure InternalHandleException; override; (* abstract *)
procedure InternalInitFieldDefs; override; (* abstract *)
procedure InternalInitRecord(Buffer: TRecordBuffer); override; (* abstract *)
procedure InternalLast; override; (* abstract *)
procedure InternalOpen; override; (* abstract *)
procedure InternalPost; override; (* abstract *)
procedure DoInternalRefresh(Qry: TFIBQuery; Buff:Pointer;ForceFullRefresh:boolean); virtual;
procedure InternalRefresh; override;
procedure InternalSetToRecord(Buffer: TRecordBuffer); override; (* abstract *)
function IsCursorOpen: Boolean; override; (* abstract *)
procedure SetBookmarkFlag(Buffer: TRecordBuffer; Value: TBookmarkFlag); override;
{$IFDEF D_23}
procedure InternalGotoBookmark(Bookmark: TBookmark); override;
procedure SetBookmarkData(Buffer: TRecBuf; Data: TBookmark); override;
{$ELSE}
procedure InternalGotoBookmark(Bookmark: Pointer); override;
procedure SetBookmarkData(Buffer: TRecordBuffer; Data: Pointer); override;
{$ENDIF}
procedure SetCachedUpdates(Value: Boolean);
procedure SetDataSource(Value: TDataSource);
procedure SetOptions(Value:TpFIBDsOptions);
procedure SetFieldData(Field: TField; Buffer: Pointer); override; (* abstract *)
procedure SetRealRecNo(Value: Integer;ToCenter:boolean =False);
procedure SetRecNo(Value: Integer); override;
function MasterFieldsChanged :boolean; virtual;
procedure SetParamsFromMaster ;
procedure ForceEndWaitMaster;
// Filter works
procedure SetFiltered(Value: Boolean); override;
procedure ExprParserCreate(const Text: string; Options: TFilterOptions);
procedure SetFilterData(const Text: string; Options: TFilterOptions);
procedure SetFilterOptions(Value: TFilterOptions); override;
procedure SetFilterText(const Value: string); override;
//
protected
FIsClientSorting:boolean;
FBeforeFetchRecord: TOnFetchRecord;
FAfterFetchRecord : TOnFetchRecord;
FRelationTables : TStringList;
FCountUpdatesPending:integer;
{$IFNDEF NO_GUI}
FSQLScreenCursor :TCursor;
{$ENDIF}
FSQLs :TSQLs;
procedure SetBeforeFetchRecord(Value:TOnFetchRecord);
function IsValidBuffer(FCache: PAnsiChar):boolean;