-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrpdatainfo.pas
5206 lines (4990 loc) · 137 KB
/
rpdatainfo.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
{*******************************************************}
{ }
{ Report Manager }
{ }
{ rpdatainfo }
{ }
{ }
{ A collection of information for opening datasets}
{ }
{ }
{ Copyright (c) 1994-2019 Toni Martir }
{ }
{ This file is under the MPL license }
{ If you enhace this file you must provide }
{ source code }
{ }
{ }
{*******************************************************}
unit rpdatainfo;
interface
{$I rpconf.inc}
{$IFDEF MSWINDOWS}
{$R dbxdrivers.res}
{$ENDIF}
uses Classes,SysUtils,
{$IFDEF DELPHI2007UP}
{$IFDEF USESQLEXPRESS}
{$IFDEF REPMANRELEASE}
DBXCLient,DBXDynaLink,
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$IFDEF MSWINDOWS}
{$IFNDEF DELPHI2007UP}
registry,
{$ENDIF}
windows,shlobj,ActiveX,
{$ENDIF}
{$IFDEF DELPHI2009UP}
// WinApi.KnownFolders,
{$ENDIF}
{$IFDEF LINUX}
{$IFNDEF FPC}
// Libc,
{$ENDIF}
{$ENDIF}
{$IFDEF USESQLEXPRESS}
{$DEFINE USENEWLINK}
SqlExpr,SqlConst,
//DBExpMYSQL,DbExpMyS,dbExpDB2,dbExpORA,dbExpINT
{$IFDEF DELPHI2009UP}
DBXInterbase,
DBXMySQL,
{$IFDEF DELPHIENTERPRISEDBSTATIC}
DBXOracle,DBXInformix,DBXFirebird,DBXSyBaseASA,
DBXSyBaseASE,DBXMSSQL,DBXCommon,DBXDb2,DBXOdbc,
{$ENDIF}
{$ENDIF}
{$IFNDEF DELPHI2009UP}
DBXpress,
{$ENDIF}
{$ENDIF}
rpmdconsts,rpmdshfolder,
DB,rpparams,Inifiles,rptypes,
{$IFDEF USEIBX}
{$IFNDEF DELPHIXE2UP}
IBQuery,IBDatabase,
{$ENDIF}
{$IFDEF DELPHIXE2UP}
IBX.IBQuery,IBX.IBDatabase,
{$ENDIF}
{$ENDIF}
{$IFDEF USEZEOS}
{$DEFINE USENEWLINK}
ZDbcIntfs,ZAbstractRODataset, ZDataset, ZConnection,
{$ENDIF}
{$IFDEF FIREDAC}
FireDAC.Phys, FireDAC.Stan.Intf, FireDAC.Comp.Client,FireDAC.Stan.Def,FireDAC.DApt,FireDAC.Stan.Option,
FireDAC.Stan.Async, FireDac.ConsoleUI.Wait,
FireDAC.Phys.ADS, FireDAC.Phys.ODBCBase,FireDAC.Phys.ODBCWrapper,
FireDAC.Phys.FB,FireDAC.Phys.IB,FireDAC.Phys.IBBase,
FireDAC.Phys.PG,FireDAC.Phys.SQLite,FireDAC.Phys.SQLiteVDataset,
FireDAC.Phys.Intf,
{$IFNDEF LINUX}
FireDAC.Phys.MSAcc,
FireDAC.Phys.DS,
{$ENDIF}
FireDAC.Phys.MySQL,
{$IFDEF DELPHIENTERPRISEDBSTATIC}
FireDAC.Phys.MSSQL,
FireDAC.Phys.ASA,FireDAC.Phys.DB2, FireDAC.Phys.Infx,
FireDAC.Phys.TData,
{$IFNDEF LINUX}
FireDAC.Phys.TDBX,
FireDAC.Phys.TDBXBase,
{$ENDIF}
FireDAC.Phys.Oracle,
FireDAC.Phys.ODBCDef,
FireDAC.Phys.ODBC,
{$ENDIF}
{$ENDIF}
{$IFDEF USEBDE}
dbtables,
{$ENDIF}
{$IFDEF USEADO}
{$IFNDEF DOTNETD}
{$IFDEF DELPHIXE2UP}
Data.Win.ADODB,
{$ELSE}
adodb,//oleauto,
{$ENDIF}
{$ENDIF}
{$IFDEF DOTNETD}
ADONetDb,
{$ENDIF}
{$ENDIF}
{$IFDEF USEIBO}
IB_Components,IBODataset,
{$ENDIF}
{$IFDEF USEVARIANTS}
Variants,Types,
{$ENDIF}
{$IFNDEF FPC}
DBClient,
{$ENDIF}
{$IFDEF USERPDATASET}
rpdataset,
{$IFDEF FPC}
Memds,
{$ENDIF}
{$ENDIF}
rpdatatext;
{$IFDEF LINUX}
const
DBXDRIVERFILENAME='dbxdrivers';
DBXCONFIGFILENAME='dbxconnections';
{$ENDIF}
type
TRpDbDriver=(rpdatadbexpress=0,rpdatamybase=1,rpdataibx=2,
rpdatabde=3,rpdataado=4,rpdataibo=5,rpdatazeos=6,rpdatadriver=7,rpdotnet2driver=8,rpfiredac=9);
TRpConnAdmin=class(TObject)
private
public
DBXConnectionsOverride:String;
DBXDriversOverride:String;
driverfilename:string;
configfilename:string;
config:TMemInifile;
drivers:TMemInifile;
constructor Create;
destructor Destroy;override;
procedure LoadConfig;
procedure GetDriverNames(alist:TStrings);
procedure GetConnectionParams(conname:string;params:TStrings);
procedure GetDriverLibNames(const drivername:string;var LibraryName,VendorLib:string);
procedure GetConnectionNames(alist:TStrings;drivername:String);
procedure AddConnection(newname:string;drivername:string);
procedure DeleteConnection(conname:string);
end;
IRpDatabaseDriver=interface
['{B3BA37D5-5401-4B9E-8804-698C214F8B0C}']
procedure Connect;
procedure AssignParams(params:TStrings);
procedure GetParams(params:TStrings);
function GetStreamFromSQL(sqlsentence:String;params:TStringList;paramlist:TRpParamList):TStream;
procedure GetTableNames(Alist:TStrings;params:TRpParamList);
procedure GetFieldNames(atable:String;fieldlist,fieldtypes,fieldsizes:TStrings;params:TRpParamList);
function OpenDatasetFromSQL(sqlsentence:String;params:TStringList;onlyexec:Boolean;paramlist:TRpParamList):TDataset;
end;
IRpDataDriver=interface
['{5094336F-C953-4108-94E3-1EC0E3D3D94C}']
function Open:TDataset;
procedure Close;
procedure SetDatabase(IDatabase:IRpDatabaseDriver);
procedure AssignParams(params:TStrings);
procedure GetParams(params:TStrings);
end;
TRpDatabaseInfoItem=class(TCollectionItem)
private
FAlias:string;
FMyBasePath:String;
{$IFDEF USESQLEXPRESS}
FSQLConnection:TSQLConnection;
FSQLInternalConnection:TSQLConnection;
{$ENDIF}
ConAdmin:TRpConnAdmin;
FConfigFile:string;
FLoadParams:boolean;
FReportTable,FReportGroupsTable,FReportSearchField,FReportField:String;
FLoadDriverParams:boolean;
FLoginPrompt:boolean;
FADOConnectionString:widestring;
{$IFDEF USEIBX}
FIBInternalDatabase:TIBDatabase;
FIBDatabase:TIBDatabase;
FIBTransaction:TIBTransaction;
FIBInternalTransaction:TIBTransaction;
{$ENDIF}
{$IFDEF FIREDAC}
FFDInternalConnection:TFDConnection;
FFDConnection:TFDConnection;
FFDTransaction:TFDTransaction;
FFDInternalTransaction:TFDTransaction;
{$ENDIF}
{$IFDEF USEZEOS}
FZInternalDatabase:TZConnection;
FZConnection:TZConnection;
{$ENDIF}
{$IFDEF USEADO}
FADOConnection:TADOConnection;
FProvidedADOConnection:TADOConnection;
{$ENDIF}
{$IFDEF USEBDE}
FBDEDatabase:TDatabase;
FBDEAlias:string;
CreatedBDE:Boolean;
{$ENDIF}
{$IFDEF USEIBO}
FIBODatabase: TIB_Database;
{$ENDIF}
FDriver:TRpDbDriver;
procedure SetAlias(Value:string);
procedure SetConfigFile(Value:string);
procedure SetLoadParams(Value:boolean);
procedure SetLoadDriverParams(Value:boolean);
procedure SetLoginPrompt(Value:boolean);
{$IFDEF USEADO}
procedure SetADOConnection(Value:TADOConnection);
function GetADOConnection:TADOConnection;
{$ENDIF}
procedure ReadAdoConnectionString(Reader:TReader);
procedure WriteAdoConnectionString(Writer:TWriter);
protected
procedure DefineProperties(Filer:TFiler);override;
public
DotNetDriver:integer;
ProviderFactory:string;
procedure UpdateConAdmin;
procedure Assign(Source:TPersistent);override;
destructor Destroy;override;
procedure Connect(params:TRpParamList);
procedure DisConnect;
constructor Create(Collection:TCollection);override;
{$IFDEF USESQLEXPRESS}
property SQLConnection:TSQLConnection read FSQLConnection write FSQLConnection;
{$ENDIF}
{$IFDEF USEIBX}
property IBDatabase:TIBDatabase read FIBDatabase
write FIBDatabase;
property IBTransaction:TIBTransaction read FIBTransaction
write FIBTransaction;
{$ENDIF}
{$IFDEF FIREDAC}
property FDConnection:TFDConnection read FFDConnection
write FFDConnection;
property FDTransaction:TFDTransaction read FFDTransaction
write FFDTransaction;
{$ENDIF}
{$IFDEF USEZEOS}
property ZConnection:TZConnection read FZConnection
write FZConnection;
{$ENDIF}
function GetStreamFromSQL(sqlsentence:String;params:TStringList;paramlist:TRpParamList):TStream;
procedure GetTableNames(Alist:TStrings;params:TRpParamList);
procedure GetFieldNames(atable:String;fieldlist,fieldtypes,fieldsizes:TStrings;params:TRpParamList);
function OpenDatasetFromSQL(sqlsentence:String;params:TStringList;onlyexec:Boolean;paramlist:TRpParamList):TDataset;
procedure CreateLibrary(reporttable,reportfield,reportsearchfield,groupstable:String;paramlist:TRpParamList);
function GetReportStream(ReportName:WideString;paramlist:TRpParamList):TStream;
procedure SaveReportStream(ReportName:WideString;astream:TStream;paramlist:TRpParamList);
{$IFDEF USEADO}
property ADOConnection:TADOConnection read GetADOConnection write SetADOConnection;
{$ENDIF}
property MyBasePath:String read FMyBasePath;
property ADOConnectionString:widestring read FADOConnectionString write FADOConnectionString;
procedure DoCommit;
published
property Alias:string read FAlias write SetAlias;
property ConfigFile:string read FConfigFile write SetConfigFile;
property LoadParams:boolean read FLoadParams write SetLoadParams;
property LoadDriverParams:boolean read FLoadDriverParams write SetLoadDriverParams;
property LoginPrompt:boolean read FLoginPrompt write SetLoginPrompt;
property Driver:TRpDbDriver read FDriver write FDriver default rpdatadbexpress;
property ReportTable:String read FReportTable write FReportTable;
property ReportSearchField:String read FReportSearchField write FReportSearchField;
property ReportField:String read FReportField write FReportField;
property ReportGroupsTable:String read FReportGroupsTable write FReportGroupsTable;
end;
TRpDatabaseInfoList=class(TCollection)
private
FReport:TComponent;
{$IFDEF USEBDE}
FBDESession:TSession;
{$ENDIF}
function GetItem(Index:Integer):TRpDatabaseInfoItem;
procedure SetItem(index:integer;Value:TRpDatabaseInfoItem);
public
{$IFDEF USEBDE}
property BDESession:TSession read FBDESession write FBDESession;
{$ENDIF}
function Add(alias:string):TRpDatabaseInfoItem;
function IndexOf(Value:string):integer;
function ItemByName(AName:string):TRpDatabaseInfoItem;
function GetReportStream(ConnectionName:String;ReportName:WideString;paramlist:TRpParamList):TStream;
procedure SaveReportStream(ConnectionName:String;ReportName:WideString;astream:TStream;paramlist:TRpParamList);
procedure SaveToFile(ainifile:String);
procedure LoadFromFile(ainifile:String);
procedure FillTreeDir(ConnectionName:String;alist:TStrings);
property Items[index:integer]:TRpDatabaseInfoItem read GetItem write SetItem;default;
constructor Create(rep:TComponent);
destructor Destroy;override;
end;
TRpDatasetType=(rpdquery,rpdtable);
TRpDataLink=class;
TRpDataInfoItem=class(TCollectionItem)
private
FDatabaseAlias:string;
FSQL:widestring;
FDataSource:string;
FAlias:string;
FDataset:TDataset;
FDataLink:TRpDatalink;
{$IFDEF USERPDATASET}
FCachedDataset:TRpDataset;
{$ENDIF}
FSQLInternalQuery:TDataset;
FMyBaseFilename:string;
FMyBaseFields:String;
FMyBaseIndexFields:string;
FMyBaseMasterFields:string;
FBDEIndexFields:string;
FBDEIndexName:string;
FBDETable:string;
FBDEType:TRpDatasetType;
FBDEMasterFields:string;
FBDEFilter:string;
FBDEFirstRange,FBDELastRange:string;
connecting:boolean;
FCached:Boolean;
FMasterSource:TDataSource;
FDataUnions:TStrings;
FGroupUnion:Boolean;
FDBInfoList:TRpDatabaseInfoList;
FParamsList:TRpParamList;
FOpenOnStart:Boolean;
{$IFDEF USEADO}
FexternalDataSet: Pointer;
{$ENDIF}
FOnConnect:TDatasetNotifyEvent;
FOnDisConnect:TDatasetNotifyEvent;
FParallelUnion:Boolean;
procedure SetDataUnions(Value:TStrings);
procedure SetDatabaseAlias(Value:string);
procedure SetAlias(Value:string);
procedure SetDataSource(Value:string);
procedure SetSQL(Value:widestring);
{$IFDEF USEBDE}
procedure SetRangeForTable(lastrange:boolean);
{$ENDIF}
public
SQLOverride:widestring;
procedure GetFieldNames(fieldlist,fieldtypes,fieldsizes:TStrings);
property OnConnect:TDatasetNotifyEvent read FOnConnect write FOnConnect;
property OnDisConnect:TDatasetNotifyEvent read FOnDisConnect write FOnDisConnect;
procedure Assign(Source:TPersistent);override;
procedure Connect(databaseinfo:TRpDatabaseInfoList;params:TRpParamList);
procedure Disconnect;
destructor Destroy;override;
constructor Create(Collection:TCollection);override;
property Dataset:TDataset read FDataset write FDataset;
{$IFDEF USERPDATASET}
property CachedDataset:TRpDataset read FCachedDataset;
{$ENDIF}
property Cached:Boolean read FCached write FCached;
{$IFDEF USEADO}
property externalDataset: Pointer read FexternalDataSet write FexternalDataSet;
{$ENDIF}
published
property Alias:string read FAlias write SetAlias;
property DatabaseAlias:string read FDatabaseAlias write SetDatabaseAlias;
property SQL:widestring read FSQL write SetSQL;
property DataSource:string read FDatasource write SetDataSource;
property MyBaseFilename:string read FMyBaseFilename write FMyBaseFilename;
property MyBaseFields:string read FMyBaseFields write FMyBaseFields;
property MyBaseIndexFields:string read FMyBaseIndexFields write FMyBaseIndexFields;
property MyBaseMasterFields:string read FMyBaseMasterFields write FMyBaseMasterFields;
property BDEIndexFields:string read FBDEIndexFields write FBDEIndexFields;
property BDEIndexName:string read FBDEIndexName write FBDEIndexName;
property BDETable:string read FBDETable write FBDETable;
property BDEType:TRpDatasetType read FBDEType write FBDEType
default rpdquery;
property BDEFilter:string read FBDEFilter write FBDEFilter;
property BDEMasterFields:string read FBDEMasterFields write FBDEMasterFields;
property BDEFirstRange:string read FBDEFirstRange write FBDEFirstRange;
property BDELastRange:string read FBDELastRange write FBDELastRange;
property DataUnions:TStrings read FDataUnions write SetDataUnions;
property GroupUnion:Boolean read FGroupUnion write FGroupUnion default false;
property OpenOnStart:Boolean read FOpenOnStart write FOpenOnStart default true;
property ParallelUnion:Boolean read FParallelUnion write FParallelUnion default false;
end;
TRpDataInfoList=class(TCollection)
private
FReport:TComponent;
function GetItem(Index:Integer):TRpDataInfoItem;
procedure SetItem(index:integer;Value:TRpDataInfoItem);
procedure IntEnableLink(alist:TStringList;i:integer);
procedure IntDisableLink(alist:TStringList;i:integer);
public
procedure DisableLinks;
procedure EnableLinks;
function Add(alias:string):TRpDataInfoItem;
procedure Swap(index1, index2: integer);
function IndexOf(Value:string):integer;
function ItemByName(AName:string):TRpDataInfoItem;
property Items[index:integer]:TRpDataInfoItem read GetItem write SetItem;default;
property Report:TComponent read FReport;
constructor Create(rep:TComponent);
end;
TRpDataLink=class(TDataLink)
protected
procedure RecordChanged(Field:TField);override;
public
databaseinfo:TRpDatabaseInfoList;
datainfo:TRpDataInfoList;
datainfoitem:TRpDataInfoItem;
dbinfoitem:TRpDatabaseInfoItem;
procedure DoRecordChange;
constructor Create;
end;
procedure GetRpDatabaseDrivers(alist:TStrings);
{$IFDEF USERPDATASET}
{$IFDEF FPC}
procedure CombineAddDataset(client:TMemDataset;data:TDataset;group:boolean);
function CombineParallel(data1:TMemDataset;data2:TDataset;prefix:string;commonfields:TStrings;originalfields:TStrings):TMemDataset;
{$ENDIF}
{$IFNDEF FPC}
procedure CombineAddDataset(client:TClientDataset;data:TDataset;group:boolean);
function CombineParallel(data1:TClientDataset;data2:TDataset;prefix:string;commonfields:TStrings;originalfields:TStrings):TClientDataset;
{$IFDEF USEIBX}
procedure ConvertParamsFromDBXToIBX(base:TIBDatabase);
{$ENDIF}
{$ENDIF}
{$ENDIF}
procedure FillFieldsInfo(adata:TDataset;fieldnames,fieldtypes,fieldsizes:TStrings);
function ExtractFieldNameEx(astring:String):string;
function EncodeADOPassword(astring:String):String;
procedure GetDotNetDrivers(alist:TStrings);
procedure GetDotNet2Drivers(alist:TStrings);
procedure ExtractUnionFields(var datasetname:string;alist:TStrings);
{$IFDEF FIREDAC}
procedure ConvertParamsFromDBXToFDac(base:TFDConnection);
{$ENDIF}
implementation
uses
{$IFDEF USEBDE}
rpeval,
{$ENDIF}
rpreport,rpbasereport;
const
SDRIVERREG_SETTING = 'Driver Registry File'; { Do not localize }
SCONNECTIONREG_SETTING = 'Connection Registry File'; { Do not localize }
VENDORLIB_KEY = 'VendorLib'; { Do not localize }
DLLLIB_KEY = 'LibraryName'; { Do not localize }
{$IFDEF MSWINDOWS}
SDriverConfigFile = 'dbxdrivers.ini'; { Do not localize }
SConnectionConfigFile = 'dbxconnections.ini'; { Do not localize }
SDBEXPRESSREG_SETTING = '\Software\Borland\DBExpress'; { Do not localize }
{$ENDIF}
{$IFDEF LINUX}
SDBEXPRESSREG_USERPATH = '/.borland/'; { Do not localize }
SDBEXPRESSREG_GLOBALPATH = '/usr/local/etc/'; { Do not localize }
SDriverConfigFile = 'dbxdrivers'; { Do not localize }
SConnectionConfigFile = 'dbxconnections'; { Do not localize }
SConfExtension = '.conf'; { Do not localize }
{$ENDIF}
{$IFDEF MSWINDOWS}
type
lpfn_SHGetKnownFolderPath = function(const rfid: TIID; dwFlags: DWORD;
hToken: THandle; var ppszPath: LPWSTR): HRESULT; stdcall;
var
SHGetKnownFolderPath: lpfn_SHGetKnownFolderPath = nil;
{$ENDIF}
const FOLDERID_Public: TGUID = '{DFDF76A2-C82A-4D63-906A-5644AC457385}';
{$IFDEF MSWINDOWS}
function GetPublicPathSlash: string;
var
pszPath: LPWSTR;
szPath: array[0..MAX_PATH] of Char;
begin
Result := '';
if Assigned(SHGetKnownFolderPath) then
begin
if SHGetKnownFolderPath(FOLDERID_Public, 0, 0, pszPath) = S_OK then
try
Result := IncludeTrailingPathDelimiter(pszPath);
finally
CoTaskMemFree(pszPath);
end;
end else begin
if SHGetSpecialFolderPath(0, szPath, CSIDL_COMMON_APPDATA, FALSE) then
begin
Result := IncludeTrailingPathDelimiter(szPath);
end;
end;
end;
{$ENDIF}
{$IFDEF USEZEOS}
procedure AssignParamValuesZ(ZQuery:TZReadOnlyQuery;Dataset:TDataset);
var
i:integer;
afield:TField;
begin
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
ZQuery.Params.Items[i].Clear;
ZQuery.Params.Items[i].DataType:=afield.DataType;
if Not afield.IsNull then
ZQuery.Params.Items[i].Value:=afield.Value;
end;
end;
end;
function EqualParamValuesZ(ZQuery:TZReadOnlyQuery;Dataset:TDataset):Boolean;
var
i:integer;
afield:TField;
qvalue:Variant;
begin
Result:=true;
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
qvalue:=ZQuery.Params.Items[i].Value;
if VarType(qvalue)=varEmpty then
begin
Result:=false;
break;
end;
if Not (qvalue=afield.AsVariant) then
begin
Result:=false;
break;
end;
end;
end;
end;
{$ENDIF}
{$IFDEF USEIBX}
procedure AssignParamValuesIBX(ZQuery:TIBQuery;Dataset:TDataset);
var
i:integer;
afield:TField;
begin
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
ZQuery.Params.Items[i].Clear;
ZQuery.Params.Items[i].DataType:=afield.DataType;
if Not afield.IsNull then
ZQuery.Params.Items[i].Value:=afield.Value;
end;
end;
end;
{$ENDIF}
{$IFDEF FIREDAC}
procedure AssignParamValuesFiredac(ZQuery:TFDQuery;Dataset:TDataset);
var
i:integer;
afield:TField;
begin
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
ZQuery.Params.Items[i].Clear;
ZQuery.Params.Items[i].DataType:=afield.DataType;
if Not afield.IsNull then
ZQuery.Params.Items[i].Value:=afield.Value;
end;
end;
end;
{$ENDIF}
{$IFDEF USESQLEXPRESS}
procedure AssignParamValuesS(ZQuery:TSQLQuery;Dataset:TDataset);
var
i:integer;
afield:TField;
begin
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
ZQuery.Params.Items[i].Clear;
ZQuery.Params.Items[i].DataType:=afield.DataType;
if Not afield.IsNull then
ZQuery.Params.Items[i].Value:=afield.Value;
end
end;
end;
function EqualParamValuesS(ZQuery:TSQLQuery;Dataset:TDataset):Boolean;
var
i:integer;
afield:TField;
qvalue:Variant;
begin
Result:=true;
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
qvalue:=ZQuery.Params.Items[i].Value;
if VarType(qvalue)=varEmpty then
begin
Result:=false;
break;
end;
if Not (qvalue=afield.AsVariant) then
begin
Result:=false;
break;
end;
end;
end;
end;
{$ENDIF}
{$IFDEF USEIBX}
function EqualParamValuesIBX(ZQuery:TIBQuery;Dataset:TDataset):Boolean;
var
i:integer;
afield:TField;
qvalue:Variant;
begin
Result:=true;
for i:=0 to ZQuery.Params.Count-1 do
begin
afield:=Dataset.FindField(ZQuery.Params.Items[i].Name);
if Assigned(afield) then
begin
qvalue:=ZQuery.Params.Items[i].Value;
if VarType(qvalue)=varEmpty then
begin
Result:=false;
break;
end;
if Not (qvalue=afield.AsVariant) then
begin
Result:=false;
break;
end;
end;
end;
end;
{$ENDIF}
{$IFDEF USEBDE}
procedure AddParamsFromDBXToBDE(paramssource,params:TStrings);
var
index:integer;
begin
index:=paramssource.IndexOfName('Password');
if index>=0 then
params.Add(paramssource.Strings[index]);
end;
{$ENDIF}
{$IFDEF USEIBX}
procedure ConvertParamsFromDBXToIBX(base:TIBDatabase);
var
index:integer;
params:TStrings;
drivername:string;
begin
params:=base.Params;
index:=params.IndexOfName('DriverName');
if index>=0 then
begin
drivername:= UpperCase(params.Values['DriverName']);
if ((drivername<>'INTERBASE') AND (drivername<>'FIREBIRD')) then
Raise Exception.Create(SRpDriverAliasIsNotInterbase);
params.Delete(index);
end;
index:=params.IndexOfName('Database');
if index<0 then
Raise Exception.Create(SRpNoDatabase);
base.DatabaseName:=params.Values['Database'];
params.Delete(index);
index:=params.IndexOfName('BlobSize');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('CommitRetain');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('Trim Char');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('ErrorResourceFile');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('LocaleCode');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('Interbase TransIsolation');
if index>=0 then
params.Delete(index);
// D2007 DBX4 params
index:=params.IndexOfName('DriverUnit');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('DriverPackageLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('DriverAssemblyLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('MetaDataPackageLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('MetaDataAssemblyLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('IsolationLevel');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('SEP');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('DisplayDriverName');
if index>=0 then
params.Delete(index);
// End D2007 DBX4 params
// Delphi XE2 params
index:=params.IndexOfName('LibraryNameOsx');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('VendorLibWin64');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('VendorLibOsx');
if index>=0 then
params.Delete(index);
// End DelphiXE2 params
index:=params.IndexOfName('WaitOnLocks');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('SQLDialect');
if index>=0 then
begin
base.SQLDialect:=StrToInt(params.Values['SQLDialect']);
params.Delete(index);
end;
index:=params.IndexOfName('RoleName');
if index>=0 then
begin
params.Add('sql_role_name='+params.Values['RoleName']);
params.Delete(index);
end;
index:=params.IndexOfName('ServerCharSet');
if index>=0 then
begin
params.Add('lc_ctype='+params.Values['ServerCharSet']);
params.Delete(index);
end;
end;
{$ENDIF}
{$IFDEF FIREDAC}
procedure ConvertParamsFromDBXToFDac(base:TFDConnection);
var
index:integer;
params:TStringList;
valor: string;
begin
params:=TStringList.Create;
params.Assign(base.Params);
index:=params.IndexOfName('DriverName');
if index<0 then
Raise Exception.Create(SRpNoDriverName);
base.DriverName := params.Values['DriverName'];
if (base.DriverName = 'Firebird') then
begin
base.DriverName:='FB';
params.Delete(index);
params.Values['DriverID']:='FB';
index:=params.IndexOfName('Database');
if index<0 then
Raise Exception.Create(SRpNoDatabase);
//params.Delete(index);
end
else
begin
if (UpperCase(base.DriverName) = 'ODBC') then
begin
params.Values['DriverID']:='ODBC';
index:=params.IndexOfName('ConnectionString');
if index<0 then
Raise Exception.Create(SRpNoDatabase + ' No connectionstring supplied set DSN in connection string');
valor:=params.Values['ConnectionString'];
params.Delete(index);
params.Values['DataSource'] := valor;
end;
end;
index:=params.IndexOfName('BlobSize');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('CommitRetain');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('Trim Char');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('ErrorResourceFile');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('LocaleCode');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('Interbase TransIsolation');
if index>=0 then
params.Delete(index);
// D2007 DBX4 params
index:=params.IndexOfName('DriverUnit');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('DriverPackageLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('DriverAssemblyLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('MetaDataPackageLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('MetaDataAssemblyLoader');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('IsolationLevel');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('SEP');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('DisplayDriverName');
if index>=0 then
params.Delete(index);
// End D2007 DBX4 params
// Delphi XE2 params
index:=params.IndexOfName('LibraryNameOsx');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('VendorLibWin64');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('VendorLibOsx');
if index>=0 then
params.Delete(index);
// End DelphiXE2 params
index:=params.IndexOfName('WaitOnLocks');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('SQLDialect');
if index>=0 then
begin
//params.Delete(index);
end;
index:=params.IndexOfName('RoleName');
if index>=0 then
begin
params.Add('RoleName='+params.Values['RoleName']);
params.Delete(index);
end;
index:=params.IndexOfName('ServerCharSet');
if index>=0 then
begin
params.Add('CharacterSet='+params.Values['ServerCharSet']);
params.Delete(index);
end;
base.Params.Assign(params);
end;
{$ENDIF}
{$IFDEF USEIBO}
procedure ConvertParamsFromDBXToIBO(base:TIB_Database);
var
index:integer;
params:TStrings;
begin
params:=base.Params;
index:=params.IndexOfName('DriverName');
if index>=0 then
begin
if UpperCase(params.Values['DriverName'])<>'INTERBASE' then
Raise Exception.Create(SRpDriverAliasIsNotInterbase);
params.Delete(index);
end;
index:=params.IndexOfName('Database');
if index<0 then
Raise Exception.Create(SRpNoDatabase);
base.DatabaseName:=params.Values['Database'];
params.Delete(index);
index:=params.IndexOfName('BlobSize');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('CommitRetain');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('ErrorResourceFile');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('LocaleCode');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('Interbase TransIsolation');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('WaitOnLocks');
if index>=0 then
params.Delete(index);
index:=params.IndexOfName('SQLDialect');
if index>=0 then
begin
base.SQLDialect:=StrToInt(params.Values['SQLDialect']);
params.Delete(index);
end;
index:=params.IndexOfName('RoleName');
if index>=0 then
begin
base.SQLRole:=params.Values['RoleName'];
params.Delete(index);
end;
index:=params.IndexOfName('user_name');
if index>=0 then
begin
params.Add('USER NAME='+params.Values['user_name']);
params.Delete(index);
end;
index:=params.IndexOfName('ServerCharSet');