-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCcDB.pas
More file actions
1528 lines (1341 loc) · 36.8 KB
/
Copy pathCcDB.pas
File metadata and controls
1528 lines (1341 loc) · 36.8 KB
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
unit CcDB;
{$I CC.INC}
interface
uses Classes, Sysutils, CcProviders, DB{$IFNDEF FPC}, CcMemDS{$ENDIF}{$IFDEF CC_D2K12}, System.Generics.Collections{$ENDIF};
type
TCcFieldInfo = class
// private
// FValIsAssigned : Boolean;
// FValue: Variant;
// procedure SetValue(Val: Variant);
public
FieldName: string;
DataType: TFieldType;
Size: Integer;
IsNull: Boolean;
Value: Variant;
// property Value: Variant read FValue write SetValue;
// property ValIsAssigned : Boolean read FValIsAssigned;
// constructor Create;
end;
TCcFieldList = class
private
FList: TStringList;
function GetCount: Integer;
function GetFieldInfo(Index: Integer): TCcFieldInfo;
function GetFieldInfoByName(FieldName: string): TCcFieldInfo;
public
procedure Add(field: TCcFieldInfo);
procedure Clear;
property FieldInfo[index: Integer]: TCcFieldInfo read GetFieldInfo; default;
property FieldInfoByName[FieldName: string]: TCcFieldInfo read GetFieldInfoByName;
property Count: Integer read GetCount;
constructor Create;
destructor Destroy; override;
end;
TCcArray = class;
TCcValueType = (vtField, vtArray, vtNull);
TCcValue = class
private
FType: TCcValueType;
FField: TCcFieldInfo;
FArray: TCcArray;
procedure SetValue(const Val: Variant);
function GetValue: Variant;
function GetAsArray: TCcArray;
function GetAsField: TCcFieldInfo;
procedure SetAsArray(const Value: TCcArray);
procedure SetAsField(const Value: TCcFieldInfo);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Val: TCcValue);
procedure SetValueAsType(Val: Variant; DataType: TFieldType);
property ValueType: TCcValueType read FType;
property Value: Variant read GetValue write SetValue;
property AsField: TCcFieldInfo read GetAsField write SetAsField;
property AsArray: TCcArray read GetAsArray write SetAsArray;
end;
TCcArray = class
private
FValues: TStringList;
function GetCount: Integer;
function GetValue(Index: Integer): TCcValue;
public
procedure Clear;
function Add: TCcValue;
procedure AddValue(Val: TCcValue);
property Value[index: Integer]: TCcValue read GetValue; default;
property Count: Integer read GetCount;
constructor Create;
destructor Destroy; override;
end;
TCcRecord = class
private
FValues: TStringList;
function GetFieldName(Index: Integer): string;
function GetCount: Integer;
function GetValue(FieldName: string): TCcValue;
public
procedure Clear;
function Add(FieldName: string): TCcValue;
property Value[FieldName: string]: TCcValue read GetValue; default;
property Count: Integer read GetCount;
property FieldName[index: Integer]: string read GetFieldName;
function FieldExists(cFieldName: string): Boolean;
constructor Create;
destructor Destroy; override;
end;
TCcMemoryTable = class;
TCcMemoryFields = class;
TCcMemoryField = class
private
FFields: TCcMemoryFields;
FFieldName: string;
FVisible: Boolean;
FIndex: Integer;
FDateType: TFieldType;
FSize: Integer;
FIsNull: Boolean;
function GetValue: Variant;
procedure SetValue(const Value: Variant);
function GetIsNull: Boolean;
function GetAsString: string;
procedure SetAsString(const Val: string);
procedure SetIsNull(const Value: Boolean);
public
property FieldName: string read FFieldName;
property DataType: TFieldType read FDateType write FDateType;
property Size: Integer read FSize write FSize;
property IsNull: Boolean read GetIsNull write SetIsNull;
procedure Clear;
property Value: Variant read GetValue write SetValue;
property AsString: string read GetAsString write SetAsString;
property index: Integer read FIndex;
property Visible: Boolean read FVisible write FVisible;
constructor Create(fields: TCcMemoryFields);
end;
TCcMemoryFields = class
private
FFields: TList{$IFDEF CC_D2K12}<TCcMemoryField>{$ENDIF};
FFieldsByName: TStringList;
FTable: TCcMemoryTable;
function GetFieldByIndex(Index: Integer): TCcMemoryField;
function GetCount: Integer;
public
procedure Clear;
constructor Create(table: TCcMemoryTable);
destructor Destroy; override;
function Add(cFieldName: String): TCcMemoryField;
function FindField(name: string): TCcMemoryField;
function FieldByName(name: string): TCcMemoryField;
property FieldByIndex[index: Integer]: TCcMemoryField read GetFieldByIndex; default;
procedure Delete(Index: Integer);
property Count: Integer read GetCount;
end;
TCcMemoryRow = class
private
FCount: Integer;
FValues: Variant;
FMemoryTable: TCcMemoryTable;
function GetValue(Index: Integer): Variant;
procedure SetValue(Index: Integer; Val: Variant);
public
property Count: Integer read FCount;
property Value[index: Integer]: Variant read GetValue write SetValue;
procedure CopyFrom(row: TCcMemoryRow);
constructor Create(table: TCcMemoryTable);
destructor Destroy; override;
end;
TCcMemoryTable = class(TComponent)
private
FRecords: TList{$IFDEF CC_D2K12}<TCcMemoryRow>{$ENDIF};
FCurrentRecNo: Integer;
FBof: Boolean;
FEof: Boolean;
FFields: TCcMemoryFields;
FActive: Boolean;
FCanCancelEdits: Boolean;
FEditing: Boolean;
FCurrentEditingRow: TCcMemoryRow;
FAppending: Boolean;
procedure SetRecNo(val: Integer);
function GetRecNo: Integer;
function GetRecordCount: Integer;
function GetCurrentRow: TCcMemoryRow;
procedure SetActive(const Value: Boolean);
protected
property CurrentRow: TCcMemoryRow read GetCurrentRow;
public
procedure EditCurrentRecord;
procedure AddNewRecord;
procedure CancelChanges;
procedure PostChanges;
procedure CheckInactive;
procedure CheckActive;
property Eof: Boolean read FEof;
property Bof: Boolean read FBof;
procedure Clear;
procedure Append;
procedure Next;
procedure Prior;
procedure Last;
procedure First;
procedure Delete;
property RecordCount: Integer read GetRecordCount;
property RecNo: Integer read GetRecNo write SetRecNo;
property fields: TCcMemoryFields read FFields;
function FieldByName(cName: string): TCcMemoryField;
function FindField(cName: string): TCcMemoryField;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Active: Boolean read FActive write SetActive;
procedure CopyStructure(Source: TCcMemoryTable);overload;
procedure LoadRow(Source: TCcMemoryTable; lTrimCharFields, lEmptyStringsToNull: Boolean);overload;
procedure CopyStructure(Source: TCcQuery);overload;
procedure LoadRow(Source: TCcQuery; lTrimCharFields, lEmptyStringsToNull: Boolean);overload;
function LoadFromDataSet(Source: TCcQuery; lTrimCharFields, lCopyStructure,
lEmptyStringsToNull: Boolean): Integer;
property CanCancelEdits:Boolean read FCanCancelEdits write FCanCancelEdits;
end;
{$IFNDEF FPC}
{$IFNDEF NEXTGEN}
// TCcDataSet is a TDataset descendant encapsulating several TCcQuery objects
// (SQL, SQLUpdate, SQLInsert, SQLDelete, SQLRefresh) and enabling a read-write access to data
// through a TCcConnection. If you set only the SQL property, the dataset will be read-only.
TCcDataSet = class(TCcMemoryData)
private
FOldConnectLost: TCcExceptionNotifyEvent;
FConnection: TCcConnection;
FSQLUpdate: TStrings;
FSQLDelete: TStrings;
FSQLInsert: TStrings;
FSQLRefresh: TStrings;
FSQL: TStrings;
OldRecord: TCcRecord;
lLoadingData: Boolean;
lRefreshingRow: Boolean;
FRowsAffected: Integer;
procedure ConnectionLost(Sender: TObject; var RaiseException: Boolean);
procedure LoadRow(qry: TCcQuery; lAppend: Boolean);
procedure SetSQLRefresh(const Value: TStrings);
procedure ExecQuery(qry: TCcQuery);
procedure SetConnection(const Value: TCcConnection);
procedure SetSQL(const Value: TStrings);
procedure SetSQLDelete(const Value: TStrings);
procedure SetSQLInsert(const Value: TStrings);
procedure SetSQLUpdate(const Value: TStrings);
function GetSQLDelete: TStrings;
function GetSQLInsert: TStrings;
function GetSQLRefresh: TStrings;
function GetSQLUpdate: TStrings;
function GetSQL: TStrings;
protected
FSelectQuery: TCcQuery;
FInsertQuery: TCcQuery;
FUpdateQuery: TCcQuery;
FDeleteQuery: TCcQuery;
FRefreshQuery: TCcQuery;
procedure InternalInitFieldDefs; override;
procedure OpenCursor(InfoQuery: Boolean); override;
procedure InternalOpen; override;
procedure InternalClose; override;
procedure InternalPost; override;
procedure InternalCancel; override;
procedure InternalDelete; override;
procedure InternalEdit; override;
procedure InternalInsert; override;
procedure DoAfterPost; override;
procedure DoAfterOpen; override;
procedure DoAfterEdit; override;
procedure DoAfterInsert; override;
procedure DoBeforeEdit; override;
procedure DoBeforeInsert; override;
procedure DoBeforePost; override;
procedure DoOnNewRecord; override;
procedure Notification(AComponent: TComponent; AOperation: TOperation); override;
public
property SelectQuery: TCcQuery read FSelectQuery;
property InsertQuery: TCcQuery read FInsertQuery;
property UpdateQuery: TCcQuery read FUpdateQuery;
property DeleteQuery: TCcQuery read FDeleteQuery;
property RefreshQuery: TCcQuery read FRefreshQuery;
property RowsAffected: Integer read FRowsAffected;
procedure CopyCurrentRecord(DestRecord: TCcRecord);
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property SQL: TStrings read GetSQL write SetSQL;
property SQLDelete: TStrings read GetSQLDelete write SetSQLDelete;
property SQLInsert: TStrings read GetSQLInsert write SetSQLInsert;
property SQLRefresh: TStrings read GetSQLRefresh write SetSQLRefresh;
property SQLUpdate: TStrings read GetSQLUpdate write SetSQLUpdate;
property Connection: TCcConnection read FConnection write SetConnection;
property Active;
end;
{$ENDIF}
{$ENDIF FPC}
implementation
uses Math {$IFNDEF NEXTGEN}{$IFDEF CC_D2K14}, VCL.Forms{$ELSE} {$IFNDEF FPC}, Forms{$ENDIF}{$ENDIF}{$ENDIF} {$IFDEF CC_UseVariants} ,Variants{$ENDIF};
{$IFNDEF NEXTGEN}
{$IFNDEF FPC}
type
TCcBookmarkData = Integer;
PCcMemBookmarkInfo = ^TCcMemBookmarkInfo;
TCcMemBookmarkInfo = record
BookmarkData: TCcBookmarkData;
BookmarkFlag: TBookmarkFlag;
end;
{ TCcDataSet }
constructor TCcDataSet.Create(AOwner: TComponent);
begin
inherited;
FRowsAffected := -1;
FSelectQuery := TCcQuery.Create(Self);
FSelectQuery.SelectStatement := True;
FUpdateQuery := TCcQuery.Create(Self);
FInsertQuery := TCcQuery.Create(Self);
FDeleteQuery := TCcQuery.Create(Self);
FRefreshQuery := TCcQuery.Create(Self);
FRefreshQuery.SelectStatement := True;
FSQL := TStringList.Create;
FSQLUpdate := TStringList.Create;
FSQLInsert := TStringList.Create;
FSQLDelete := TStringList.Create;
FSQLRefresh := TStringList.Create;
OldRecord := TCcRecord.Create;
end;
destructor TCcDataSet.Destroy;
begin
FSelectQuery.Free;
FUpdateQuery.Free;
FInsertQuery.Free;
FDeleteQuery.Free;
FRefreshQuery.Free;
FSQL.Free;
FSQLUpdate.Free;
FSQLInsert.Free;
FSQLDelete.Free;
FSQLRefresh.Free;
OldRecord.Free;
inherited;
end;
procedure TCcDataSet.LoadRow(qry: TCcQuery; lAppend: Boolean);
var
I: Integer;
cFieldName: string;
begin
if not qry.Active then
Exit;
DisableControls;
lLoadingData := True;
try
if lAppend then
Append
else
Edit;
for I := 0 to qry.FieldCount - 1 do
begin
cFieldName := qry.FieldByIndex[I].FieldName;
if FindField(cFieldName) <> nil then
begin
// if qry.FieldByIndex[I].DataType = ftString then
// FieldByName(cFieldName).AsString := Trim(qry.FieldByIndex[I].AsString)
// else
FieldByName(cFieldName).Value := qry.FieldByIndex[I].Value;
end;
end;
Post;
finally
if State <> dsBrowse then
Cancel;
EnableControls;
lLoadingData := False;
end;
end;
procedure TCcDataSet.DoAfterOpen;
begin
try
while not FSelectQuery.Eof do
begin
LoadRow(FSelectQuery, True);
FSelectQuery.Next;
end;
finally
First;
end;
inherited;
end;
procedure TCcDataSet.InternalCancel;
begin
inherited;
OldRecord.Clear;
end;
procedure TCcDataSet.InternalClose;
begin
inherited;
FSelectQuery.Close;
end;
procedure TCcDataSet.InternalDelete;
begin
if not lLoadingData then
ExecQuery(FDeleteQuery);
inherited;
end;
procedure TCcDataSet.InternalEdit;
begin
inherited;
if not lLoadingData then
CopyCurrentRecord(OldRecord);
end;
procedure TCcDataSet.InternalInitFieldDefs;
var
lWasConnected: Boolean;
lWasActive: Boolean;
I: Integer;
f: TCcField;
begin
if not Assigned(Connection) then
Exit;
lWasConnected := Connection.Connected;
lWasActive := FSelectQuery.Active;
try
if (csDesigning in ComponentState) then
// Open connection if it's not open
Connection.Connected := True;
// Execute query
if not FSelectQuery.Active then
FSelectQuery.Exec;
FieldDefs.BeginUpdate;
try
FieldDefs.Clear;
for I := 0 to FSelectQuery.FieldCount - 1 do
begin
f := FSelectQuery.FieldByIndex[I];
with TFieldDef.Create(FieldDefs, f.FieldName,
f.DataType, f.Size, False, I + 1) do
InternalCalcField := False;
end;
finally
FieldDefs.EndUpdate;
end
finally
Connection.Connected := lWasConnected;
FSelectQuery.Active := lWasActive;
end;
end;
procedure TCcDataSet.InternalInsert;
begin
inherited;
if not lLoadingData then
CopyCurrentRecord(OldRecord);
end;
procedure TCcDataSet.CopyCurrentRecord(DestRecord: TCcRecord);
var
I: Integer;
begin
if not Assigned(DestRecord) then
raise Exception.Create('Destination record not initialized');
DestRecord.Clear;
for I := 0 to FieldCount - 1 do
DestRecord[fields[I].FieldName].Value := fields[I].Value;
end;
procedure TCcDataSet.OpenCursor(InfoQuery: Boolean);
begin
if not Assigned(Connection) then
raise Exception.Create('Database connection not assigned!');
FSelectQuery.Exec;
InternalInitFieldDefs;
inherited OpenCursor(InfoQuery);
end;
procedure TCcDataSet.InternalOpen;
begin
inherited;
end;
procedure TCcDataSet.InternalPost;
var
qry: TCcQuery;
begin
if not lLoadingData then
begin
if State = dsInsert then
qry := FInsertQuery
else
qry := FUpdateQuery;
if not qry.Connection.InTransaction then
qry.Connection.StartTransaction;
// Load parameters and execute query
ExecQuery(qry);
// Post record to memory table
inherited;
// Clear old record version, so as to avoid possible errors
// if the user puts an 'OLD_' parameter where he shouldn't
OldRecord.Clear;
end
else
inherited;
end;
procedure TCcDataSet.Notification(AComponent: TComponent;
AOperation: TOperation);
begin
if AOperation = opRemove then
begin
if AComponent = Connection then
SetConnection(nil);
end;
inherited;
end;
procedure TCcDataSet.ExecQuery(qry: TCcQuery);
var
I: Integer;
f: TField;
cFieldName: string;
begin
// If the SQL is empty, it means that the operation is not permitted
// Simply abort so that nothing will happen, don't raise any exception
if Trim(qry.SQL.Text) = '' then
Abort;
qry.Close;
for I := 0 to qry.ParamCount - 1 do
begin
cFieldName := UpperCase(Trim(qry.ParamByIndex[I].FieldName));
f := FindField(cFieldName);
if f <> nil then
qry.ParamByIndex[I].Value := f.Value
else if Copy(cFieldName, 1, 4) = 'OLD_' then
begin
cFieldName := Copy(cFieldName, 5, Length(cFieldName));
if OldRecord.FieldExists(cFieldName) then
qry.ParamByIndex[I].Value := OldRecord[cFieldName].Value;
end;
end;
qry.Exec;
if qry <> FRefreshQuery then
FRowsAffected := qry.RowsAffected;
end;
procedure TCcDataSet.SetConnection(const Value: TCcConnection);
begin
if FConnection = Value then
Exit;
if Assigned(FConnection) then
FConnection.OnConnectionLost := FOldConnectLost;
FConnection := Value;
if Assigned(FConnection) then
begin
FOldConnectLost := FConnection.OnConnectionLost;
FConnection.OnConnectionLost := ConnectionLost;
end;
FSelectQuery.Connection := Value;
FUpdateQuery.Connection := Value;
FInsertQuery.Connection := Value;
FDeleteQuery.Connection := Value;
FRefreshQuery.Connection := Value;
end;
procedure TCcDataSet.SetSQL(const Value: TStrings);
begin
Close;
FSelectQuery.SQL.Assign(Value);
// SetQuerySQL(FSelectQuery, FSQL, Value);
end;
procedure TCcDataSet.SetSQLRefresh(const Value: TStrings);
begin
FRefreshQuery.SQL.Assign(Value);
// SetQuerySQL(FRefreshQuery, FSQLRefresh, Value);
end;
procedure TCcDataSet.SetSQLDelete(const Value: TStrings);
begin
FDeleteQuery.SQL.Assign(Value);
// SetQuerySQL(FDeleteQuery, FSQLDelete, Value);
end;
procedure TCcDataSet.SetSQLInsert(const Value: TStrings);
begin
FInsertQuery.SQL.Assign(Value);
// SetQuerySQL(FInsertQuery, FSQLInsert, Value);
end;
procedure TCcDataSet.SetSQLUpdate(const Value: TStrings);
begin
FUpdateQuery.SQL.Assign(Value);
// SetQuerySQL(FUpdateQuery, FSQLUpdate, Value);
end;
function TCcDataSet.GetSQLDelete: TStrings;
begin
Result := FDeleteQuery.SQL;
end;
function TCcDataSet.GetSQLInsert: TStrings;
begin
Result := FInsertQuery.SQL;
end;
function TCcDataSet.GetSQLRefresh: TStrings;
begin
Result := FRefreshQuery.SQL;
end;
function TCcDataSet.GetSQLUpdate: TStrings;
begin
Result := FUpdateQuery.SQL;
end;
function TCcDataSet.GetSQL: TStrings;
begin
Result := FSelectQuery.SQL;
end;
procedure TCcDataSet.DoAfterPost;
begin
// Refresh current row
if not lLoadingData then
begin
if not lRefreshingRow then
begin
lRefreshingRow := True;
try
if Trim(FRefreshQuery.SQL.Text) <> '' then
begin
ExecQuery(FRefreshQuery);
if (FRefreshQuery.RecordCount > 0) then
LoadRow(FRefreshQuery, False);
end;
finally
lRefreshingRow := False;
end;
end;
inherited;
end;
end;
procedure TCcDataSet.DoAfterEdit;
begin
if not lLoadingData then
inherited;
end;
procedure TCcDataSet.DoAfterInsert;
begin
if not lLoadingData then
inherited;
end;
procedure TCcDataSet.DoBeforeEdit;
begin
if not lLoadingData then
inherited;
end;
procedure TCcDataSet.DoBeforeInsert;
begin
if not lLoadingData then
inherited;
end;
procedure TCcDataSet.DoBeforePost;
begin
if not lLoadingData then
inherited;
end;
procedure TCcDataSet.DoOnNewRecord;
begin
if not lLoadingData then
inherited;
end;
procedure TCcDataSet.ConnectionLost(Sender: TObject;
var RaiseException: Boolean);
begin
Close;
if Assigned(FOldConnectLost) then
FOldConnectLost(Sender, RaiseException);
end;
{$ENDIF}
{$ENDIF}
{ TCcValue }
procedure TCcValue.Assign(Val: TCcValue);
var
I: Integer;
begin
if Val.ValueType = vtArray then
begin
AsArray.Clear;
for I := 0 to Val.AsArray.Count - 1 do
AsArray.Add.Assign(Val.AsArray[I]);
end
else if Val.ValueType = vtField then
begin
AsField.FieldName := Val.AsField.FieldName;
AsField.DataType := Val.AsField.DataType;
AsField.Value := Val.AsField.Value;
AsField.IsNull := Val.AsField.IsNull;
AsField.Size := Val.AsField.Size;
end;
end;
procedure TCcValue.Clear;
begin
if FType = vtArray then
FArray.Free
else if FType = vtField then
FField.Free;
FType := vtNull;
end;
constructor TCcValue.Create;
begin
FType := vtNull;
end;
destructor TCcValue.Destroy;
begin
Clear;
if FType = vtArray then
FArray.Free
else if FType = vtField then
FField.Free;
inherited;
end;
function TCcValue.GetAsArray: TCcArray;
begin
// If no type is set, set type to array
if FType = vtNull then
SetAsArray(TCcArray.Create);
if FType = vtArray then
Result := FArray
else
raise EConvertError.Create('Cannot convert variant type to array!');
end;
function TCcValue.GetAsField: TCcFieldInfo;
begin
// If no type is set, set type to variant
if FType = vtNull then
SetAsField(TCcFieldInfo.Create);
if FType = vtField then
Result := FField
else
raise EConvertError.Create('Cannot convert array type to variant!');
end;
function TCcValue.GetValue: Variant;
begin
Result := GetAsField.Value;
end;
procedure TCcValue.SetAsArray(const Value: TCcArray);
begin
FType := vtArray;
FArray := Value;
end;
procedure TCcValue.SetAsField(const Value: TCcFieldInfo);
begin
FType := vtField;
FField := Value;
end;
procedure TCcValue.SetValue(const Val: Variant);
var
vType: Integer;
begin
vType := VarType(Val);
case vType of
varSmallint, varByte, varInteger:
AsField.DataType := ftInteger;
varDouble, varCurrency:
AsField.DataType := ftFloat;
{$IFDEF CC_D6}
varWord: // Added by Kick Martens
AsField.DataType := ftWord;
{$ENDIF}
{$IFDEF CC_D2K9}
varLongWord: // Added by Kick Martens
AsField.DataType := ftLongWord;
{$ENDIF}
varString {$IFDEF CC_D2K9} , varUString {$ENDIF}:
AsField.DataType := ftString;
// varUString:
// AsField.DataType := ftWideString;
varBoolean:
AsField.DataType := ftBoolean;
varDate:
AsField.DataType := ftDateTime;
else
AsField.DataType := ftUnknown;
end;
AsField.IsNull := (VarIsNull(Val) {$IFDEF CC_D6} or VarIsClear(Val){$ENDIF} or VarIsEmpty(Val));
AsField.Value := Val;
end;
procedure TCcValue.SetValueAsType(Val: Variant; DataType: TFieldType);
begin
Value := Val;
AsField.DataType := DataType;
/// / If the value is null, don't change the datatype
// if AsField.DataType <> ftNull then
// AsField.DataType := dataType;
end;
{ TCcFieldList }
procedure TCcFieldList.Add(field: TCcFieldInfo);
begin
FList.AddObject(field.FieldName, field);
end;
procedure TCcFieldList.Clear;
var
I: Integer;
begin
for I := FList.Count - 1 downto 0 do
begin
if Assigned(FList.Objects[I]) then
FList.Objects[I].Free;
FList.Delete(I);
end;
end;
constructor TCcFieldList.Create;
begin
FList := TStringList.Create;
end;
destructor TCcFieldList.Destroy;
begin
FList.Free;
inherited;
end;
function TCcFieldList.GetCount: Integer;
begin
Result := FList.Count;
end;
function TCcFieldList.GetFieldInfo(Index: Integer): TCcFieldInfo;
begin
Result := TCcFieldInfo(FList.Objects[index]);
end;
function TCcFieldList.GetFieldInfoByName(FieldName: string): TCcFieldInfo;
begin
Result := GetFieldInfo(FList.IndexOf(FieldName));
end;
{ TCcArray }
function TCcArray.Add: TCcValue;
begin
Result := TCcValue.Create;
FValues.AddObject(IntToStr(FValues.Count), Result);
end;
procedure TCcArray.AddValue(Val: TCcValue);
begin
if Assigned(Val) and (Val.ValueType <> vtNull) then
Add.Assign(Val);
end;
procedure TCcArray.Clear;
var
I: Integer;
begin
for I := 0 to FValues.Count - 1 do
TCcValue(FValues.Objects[I]).Free;
FValues.Clear;
end;
constructor TCcArray.Create;
begin
FValues := TStringList.Create;
end;
destructor TCcArray.Destroy;
begin
Clear;
FValues.Free;
inherited;
end;
function TCcArray.GetCount: Integer;
begin
Result := FValues.Count;
end;
function TCcArray.GetValue(Index: Integer): TCcValue;
begin
if (index <> -1) and (index < FValues.Count) then
Result := TCcValue(FValues.Objects[index])
else
Result := nil;
end;
{ TCcRecord }
function TCcRecord.Add(FieldName: string): TCcValue;
begin
Result := TCcValue.Create;
Result.AsField.FieldName := FieldName;
FValues.AddObject(FieldName, Result);
end;
procedure TCcRecord.Clear;
var
I: Integer;
begin
for I := 0 to FValues.Count - 1 do
TCcValue(FValues.Objects[I]).Free;
FValues.Clear;
end;
constructor TCcRecord.Create;
begin
FValues := TStringList.Create;
end;
destructor TCcRecord.Destroy;
begin
Clear;
FValues.Free;
inherited;
end;
function TCcRecord.FieldExists(cFieldName: string): Boolean;
begin
Result := (FValues.IndexOf(cFieldName) > -1);
end;
function TCcRecord.GetCount: Integer;
begin
Result := FValues.Count;
end;
function TCcRecord.GetFieldName(Index: Integer): string;
begin
Result := FValues[index];
end;
function TCcRecord.GetValue(FieldName: string): TCcValue;
var
nIndex: Integer;
begin
nIndex := FValues.IndexOf(FieldName);
if nIndex <> -1 then
Result := TCcValue(FValues.Objects[nIndex])
else
Result := Add(FieldName);
end;