diff --git a/samples/activerecord_showcase/MainFormU.dfm b/samples/activerecord_showcase/MainFormU.dfm index 99dab8c1..bcdb5d9a 100644 --- a/samples/activerecord_showcase/MainFormU.dfm +++ b/samples/activerecord_showcase/MainFormU.dfm @@ -328,8 +328,4 @@ object MainForm: TMainForm TabOrder = 32 OnClick = btnTransactionClick end - object FDConnection1: TFDConnection - Left = 312 - Top = 40 - end end diff --git a/samples/activerecord_showcase/MainFormU.pas b/samples/activerecord_showcase/MainFormU.pas index bbe5b125..5926003b 100644 --- a/samples/activerecord_showcase/MainFormU.pas +++ b/samples/activerecord_showcase/MainFormU.pas @@ -42,7 +42,6 @@ type btnMultiThreading: TButton; btnRQL: TButton; btnReadOnlyFields: TButton; - FDConnection1: TFDConnection; btnNullTest: TButton; btnCRUDNoAutoInc: TButton; btnCRUDWithStringPKs: TButton; @@ -839,13 +838,11 @@ procedure TMainForm.btnMultiThreadingClick(Sender: TObject); var lTasks: TArray; lProc: TProc; - lConnParams: string; begin Log('** Multithreading test'); TMVCActiveRecord.DeleteRQL(TCustomer, 'in(City,["Rome","New York","London","Melbourne","Berlin"])'); - lConnParams := FDConnection1.Params.Text; lProc := procedure var lCustomer: TCustomer; @@ -2335,7 +2332,7 @@ end; procedure TMainForm.FormDestroy(Sender: TObject); begin - ActiveRecordConnectionsRegistry.RemoveDefaultConnection(False); + ActiveRecordConnectionsRegistry.RemoveDefaultConnection(); end; procedure TMainForm.FormShow(Sender: TObject); @@ -2380,11 +2377,7 @@ begin raise Exception.Create('Unknown RDBMS'); end; - FDConnection1.Params.Clear; - FDConnection1.ConnectionDefName := FDConnectionConfigU.CON_DEF_NAME; - FDConnection1.Connected := True; - - ActiveRecordConnectionsRegistry.AddDefaultConnection(FDConnection1); + ActiveRecordConnectionsRegistry.AddDefaultConnection(FDConnectionConfigU.CON_DEF_NAME); Caption := Caption + ' (Curr Backend: ' + ActiveRecordConnectionsRegistry.GetCurrentBackend + ')'; {$IFDEF USE_SEQUENCES} Caption := Caption + ' USE_SEQUENCES'; diff --git a/samples/data/activerecorddb_postgresql_script.sql b/samples/data/activerecorddb_postgresql_script.sql index f9c12569..0bf9c2bd 100644 --- a/samples/data/activerecorddb_postgresql_script.sql +++ b/samples/data/activerecorddb_postgresql_script.sql @@ -128,7 +128,8 @@ CREATE TABLE public.customers2 ( description character varying(200), city character varying(200), note text, - rating integer + rating integer, + last_contact_timestamp timestamptz NULL ); ALTER TABLE public.customers2 OWNER TO postgres; diff --git a/samples/datapump/CustomerEntityU.pas b/samples/datapump/CustomerEntityU.pas new file mode 100644 index 00000000..2da20251 --- /dev/null +++ b/samples/datapump/CustomerEntityU.pas @@ -0,0 +1,39 @@ +unit CustomerEntityU; + +interface + +uses + MVCFramework.ActiveRecord, MVCFramework.Nullables; + +type + [MVCTable('customers')] + TCustomer = class(TMVCActiveRecord) + private + [MVCTableField('id', [foPrimaryKey, foAutoGenerated])] + fID: NullableInt64; + [MVCTableField('code')] + fCode: NullableString; + [MVCTableField('description')] + fCompanyName: NullableString; + [MVCTableField('city')] + fCity: string; + [MVCTableField('last_contact_timestamp')] + fLastContact: NullableTDateTime; + [MVCTableField('rating')] + fRating: NullableInt32; + [MVCTableField('note')] + fNote: string; + public + property ID: NullableInt64 read fID write fID; + property Code: NullableString read fCode write fCode; + property CompanyName: NullableString read fCompanyName write fCompanyName; + property City: string read fCity write fCity; + property LastContact: NullableTDateTime read fLastContact write fLastContact; + property Rating: NullableInt32 read fRating write fRating; + property Note: string read fNote write fNote; + end; + + +implementation + +end. diff --git a/samples/datapump/DataPumpSample.dpr b/samples/datapump/DataPumpSample.dpr new file mode 100644 index 00000000..f8cf260f --- /dev/null +++ b/samples/datapump/DataPumpSample.dpr @@ -0,0 +1,16 @@ +program DataPumpSample; + +uses + Vcl.Forms, + MainFormU in 'MainFormU.pas' {MainForm}, + FDConnectionConfigU in 'FDConnectionConfigU.pas', + CustomerEntityU in 'CustomerEntityU.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TMainForm, MainForm); + Application.Run; +end. diff --git a/samples/datapump/DataPumpSample.dproj b/samples/datapump/DataPumpSample.dproj new file mode 100644 index 00000000..dd3a81d3 --- /dev/null +++ b/samples/datapump/DataPumpSample.dproj @@ -0,0 +1,1131 @@ + + + {CD63040E-EDF2-44BA-81C1-A83514949757} + 20.1 + VCL + True + Debug + Win32 + DataPumpSample + 3 + Application + DataPumpSample.dpr + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + true + Cfg_2 + true + true + + + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + $(BDS)\bin\delphi_PROJECTICON.ico + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + DataPumpSample + + + vclwinx;DataSnapServer;fmx;emshosting;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;DBXMSSQLDriver;FireDACCommonODBC;emsclient;FireDACCommonDriver;Twitter;appanalytics;IndyProtocols;vclx;Skia.Package.RTL;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;emsedge;bindcompfmx;DBXFirebirdDriver;inetdb;FireDACSqliteDriver;DbxClientDriver;FireDACASADriver;soapmidas;vclactnband;fmxFireDAC;dbexpress;FireDACInfxDriver;DBXMySQLDriver;VclSmp;inet;DataSnapCommon;vcltouch;fmxase;DBXOdbcDriver;dbrtl;FireDACDBXDriver;Skia.Package.FMX;FireDACOracleDriver;fmxdae;FireDACMSAccDriver;CustomIPTransport;FireDACMSSQLDriver;DataSnapIndy10ServerTransport;DataSnapConnectors;vcldsnap;DBXInterBaseDriver;FireDACMongoDBDriver;IndySystem;FireDACTDataDriver;Skia.Package.VCL;vcldb;StyledComponents;vclFireDAC;bindcomp;FireDACCommon;DataSnapServerMidas;FireDACODBCDriver;emsserverresource;IndyCore;RESTBackendComponents;dmvcframeworkDT;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;StyledAnimatedComponents;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;DataSnapClient;DataSnapProviderClient;adortl;DBXSybaseASEDriver;DBXDb2Driver;vclimg;DataSnapFireDAC;emsclientfiredac;FireDACPgDriver;FireDAC;FireDACDSDriver;inetdbxpress;xmlrtl;tethering;dmvcframeworkRT;bindcompvcl;dsnap;CloudService;DBXSybaseASADriver;DBXOracleDriver;FireDACDb2Driver;DBXInformixDriver;fmxobj;bindcompvclsmp;DataSnapNativeClient;DatasnapConnectorsFreePascal;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage) + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + $(BDS)\bin\default_app.manifest + .\bin + none + + + vclwinx;DataSnapServer;fmx;emshosting;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;DBXMSSQLDriver;FireDACCommonODBC;emsclient;FireDACCommonDriver;Twitter;appanalytics;IndyProtocols;vclx;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;emsedge;bindcompfmx;DBXFirebirdDriver;inetdb;FireDACSqliteDriver;DbxClientDriver;FireDACASADriver;soapmidas;vclactnband;fmxFireDAC;dbexpress;FireDACInfxDriver;DBXMySQLDriver;VclSmp;inet;DataSnapCommon;vcltouch;fmxase;DBXOdbcDriver;dbrtl;FireDACDBXDriver;FireDACOracleDriver;fmxdae;FireDACMSAccDriver;CustomIPTransport;FireDACMSSQLDriver;DataSnapIndy10ServerTransport;DataSnapConnectors;vcldsnap;DBXInterBaseDriver;FireDACMongoDBDriver;IndySystem;FireDACTDataDriver;Skia.Package.VCL;vcldb;StyledComponents;vclFireDAC;bindcomp;FireDACCommon;DataSnapServerMidas;FireDACODBCDriver;emsserverresource;IndyCore;RESTBackendComponents;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;StyledAnimatedComponents;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;DataSnapClient;DataSnapProviderClient;adortl;DBXSybaseASEDriver;DBXDb2Driver;vclimg;DataSnapFireDAC;emsclientfiredac;FireDACPgDriver;FireDAC;FireDACDSDriver;inetdbxpress;xmlrtl;tethering;bindcompvcl;dsnap;CloudService;DBXSybaseASADriver;DBXOracleDriver;FireDACDb2Driver;DBXInformixDriver;fmxobj;bindcompvclsmp;DataSnapNativeClient;DatasnapConnectorsFreePascal;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage) + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + $(BDS)\bin\default_app.manifest + + + DEBUG;$(DCC_Define) + true + false + true + true + true + true + true + + + false + PerMonitorV2 + true + 1033 + + + PerMonitorV2 + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + PerMonitorV2 + + + PerMonitorV2 + + + + MainSource + + +
MainForm
+ dfm +
+ + + + Base + + + Cfg_1 + Base + + + Cfg_2 + Base + +
+ + Delphi.Personality.12 + Application + + + + DataPumpSample.dpr + + + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + Embarcadero C++Builder Office 2000 Servers Package + Embarcadero C++Builder Office XP Servers Package + + + + + + DataPumpSample.exe + true + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + classes + 64 + + + classes + 64 + + + + + res\xml + 1 + + + res\xml + 1 + + + + + library\lib\armeabi + 1 + + + library\lib\armeabi + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\mips + 1 + + + library\lib\mips + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-anydpi-v21 + 1 + + + res\drawable-anydpi-v21 + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\values-v21 + 1 + + + res\values-v21 + 1 + + + + + res\values-v31 + 1 + + + res\values-v31 + 1 + + + + + res\drawable-anydpi-v26 + 1 + + + res\drawable-anydpi-v26 + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-anydpi-v33 + 1 + + + res\drawable-anydpi-v33 + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\values-night-v21 + 1 + + + res\values-night-v21 + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-small + 1 + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + res\drawable-xlarge + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\drawable-anydpi-v24 + 1 + + + res\drawable-anydpi-v24 + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-night-anydpi-v21 + 1 + + + res\drawable-night-anydpi-v21 + 1 + + + + + res\drawable-anydpi-v31 + 1 + + + res\drawable-anydpi-v31 + 1 + + + + + res\drawable-night-anydpi-v31 + 1 + + + res\drawable-night-anydpi-v31 + 1 + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + Contents\MacOS + 1 + .framework + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + Contents\Resources\StartUp\ + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + ..\ + 1 + + + + + Contents + 1 + + + Contents + 1 + + + Contents + 1 + + + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + library\lib\armeabi-v7a + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + ..\ + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen + 64 + + + ..\$(PROJECTNAME).launchscreen + 64 + + + + + 1 + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + + + + + + + + + + + + + True + True + + + 12 + + + + +
diff --git a/samples/datapump/FDConnectionConfigU.pas b/samples/datapump/FDConnectionConfigU.pas new file mode 100644 index 00000000..09acaa8b --- /dev/null +++ b/samples/datapump/FDConnectionConfigU.pas @@ -0,0 +1,226 @@ +unit FDConnectionConfigU; + +interface + +const + CON_DEF_NAME = 'MyConnX'; + +procedure CreateFirebirdPrivateConnDef(AIsPooled: boolean); +procedure CreateInterbasePrivateConnDef(AIsPooled: boolean); +procedure CreateMySQLPrivateConnDef(AIsPooled: boolean); +procedure CreateMSSQLServerPrivateConnDef(AIsPooled: boolean); +procedure CreatePostgresqlPrivateConnDef(AIsPooled: boolean; ConDefName: String = CON_DEF_NAME); +procedure CreateSqlitePrivateConnDef(AIsPooled: boolean; ConDefName: String = CON_DEF_NAME); + +implementation + +uses + System.Classes, + System.IOUtils, + FireDAC.Comp.Client, + FireDAC.Moni.Base, + FireDAC.Moni.FlatFile, + FireDAC.Stan.Intf + ; + + +var + gFlatFileMonitor: TFDMoniFlatFileClientLink = nil; + +procedure CreateMySQLPrivateConnDef(AIsPooled: boolean); +var + LParams: TStringList; +begin + { + docker run --detach --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_ROOT_PASSWORD=root -p 3306:3306 mariadb:latest + } + + LParams := TStringList.Create; + try + LParams.Add('Database=activerecorddb'); + LParams.Add('Protocol=TCPIP'); + LParams.Add('Server=localhost'); + LParams.Add('User_Name=root'); + LParams.Add('Password=root'); + LParams.Add('TinyIntFormat=Boolean'); { it's the default } + LParams.Add('CharacterSet=utf8mb4'); // not utf8!! + LParams.Add('MonitorBy=FlatFile'); + if AIsPooled then + begin + LParams.Add('Pooled=True'); + LParams.Add('POOL_MaximumItems=100'); + end + else + begin + LParams.Add('Pooled=False'); + end; + FDManager.AddConnectionDef(CON_DEF_NAME, 'MySQL', LParams); + finally + LParams.Free; + end; +end; + +procedure CreateMSSQLServerPrivateConnDef(AIsPooled: boolean); +var + LParams: TStringList; +begin + { + docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=!SA_password!" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest + } + + // [ACTIVERECORDB_SQLSERVER] + // Database=activerecorddb + // OSAuthent=Yes + // Server=DANIELETETI\SQLEXPRESS + // DriverID=MSSQL + // + + LParams := TStringList.Create; + try + LParams.Add('Database=activerecorddb'); + LParams.Add('OSAuthent=Yes'); + LParams.Add('Server=DANIELETETI\SQLEXPRESS'); + if AIsPooled then + begin + LParams.Add('Pooled=True'); + LParams.Add('POOL_MaximumItems=100'); + end + else + begin + LParams.Add('Pooled=False'); + end; + FDManager.AddConnectionDef(CON_DEF_NAME, 'MSSQL', LParams); + finally + LParams.Free; + end; +end; + +procedure CreateFirebirdPrivateConnDef(AIsPooled: boolean); +var + LParams: TStringList; +begin + LParams := TStringList.Create; + try + LParams.Add('Database=' + TPath.GetFullPath(TPath.Combine('..\..', + 'data\ACTIVERECORDDB.FDB'))); + LParams.Add('Protocol=TCPIP'); + LParams.Add('Server=localhost'); + LParams.Add('User_Name=sysdba'); + LParams.Add('Password=masterkey'); + LParams.Add('CharacterSet=UTF8'); + if AIsPooled then + begin + LParams.Add('Pooled=True'); + LParams.Add('POOL_MaximumItems=100'); + end + else + begin + LParams.Add('Pooled=False'); + end; + FDManager.AddConnectionDef(CON_DEF_NAME, 'FB', LParams); + finally + LParams.Free; + end; +end; + +procedure CreateInterbasePrivateConnDef(AIsPooled: boolean); +var + LParams: TStringList; +begin + LParams := TStringList.Create; + try + LParams.Add('Database=' + TPath.GetFullPath(TPath.Combine('..\..', + 'data\ACTIVERECORDDB.IB'))); + LParams.Add('Protocol=TCPIP'); + LParams.Add('Server=localhost'); + LParams.Add('User_Name=sysdba'); + LParams.Add('Password=masterkey'); + LParams.Add('CharacterSet=UTF8'); + if AIsPooled then + begin + LParams.Add('Pooled=True'); + LParams.Add('POOL_MaximumItems=100'); + end + else + begin + LParams.Add('Pooled=False'); + end; + FDManager.AddConnectionDef(CON_DEF_NAME, 'IB', LParams); + finally + LParams.Free; + end; +end; + +procedure CreatePostgresqlPrivateConnDef(AIsPooled: boolean; ConDefName: String); +var + LParams: TStringList; +begin + LParams := TStringList.Create; + try + LParams.Add('Database=activerecorddb'); + LParams.Add('Protocol=TCPIP'); + LParams.Add('Server=localhost'); + LParams.Add('User_Name=postgres'); + LParams.Add('Password=postgres'); + LParams.Add('MonitorBy=FlatFile'); + + // https://quality.embarcadero.com/browse/RSP-19755?jql=text%20~%20%22firedac%20guid%22 + LParams.Add('GUIDEndian=Big'); + if AIsPooled then + begin + LParams.Add('Pooled=True'); + LParams.Add('POOL_MaximumItems=100'); + end + else + begin + LParams.Add('Pooled=False'); + end; + FDManager.AddConnectionDef(ConDefName, 'PG', LParams); + finally + LParams.Free; + end; +end; + +procedure CreateSqlitePrivateConnDef(AIsPooled: Boolean; ConDefName: String); +var + LParams: TStringList; + lFName: string; +begin + LParams := TStringList.Create; + try + lFName := TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), + '..\..\data\activerecorddb.db'); + LParams.Add('Database=' + lFName); + LParams.Add('StringFormat=Unicode'); + if AIsPooled then + begin + LParams.Add('Pooled=True'); + LParams.Add('POOL_MaximumItems=100'); + end + else + begin + LParams.Add('Pooled=False'); + end; + FDManager.AddConnectionDef(ConDefName, 'SQLite', LParams); + finally + LParams.Free; + end; +end; + +initialization + +gFlatFileMonitor := TFDMoniFlatFileClientLink.Create(nil); +gFlatFileMonitor.FileColumns := [tiRefNo, tiTime, tiThreadID, tiClassName, tiObjID, tiMsgText]; +gFlatFileMonitor.EventKinds := [ + ekVendor, ekConnConnect, ekLiveCycle, ekError, ekConnTransact, + ekCmdPrepare, ekCmdExecute, ekCmdDataIn, ekCmdDataOut]; +gFlatFileMonitor.ShowTraces := False; +gFlatFileMonitor.FileAppend := False; +gFlatFileMonitor.FileName := TPath.ChangeExtension(ParamStr(0), '.trace.log'); +gFlatFileMonitor.Tracing := True; + +finalization + +gFlatFileMonitor.Free; + +end. diff --git a/samples/datapump/MainFormU.dfm b/samples/datapump/MainFormU.dfm new file mode 100644 index 00000000..53fbd129 --- /dev/null +++ b/samples/datapump/MainFormU.dfm @@ -0,0 +1,31 @@ +object MainForm: TMainForm + Left = 0 + Top = 0 + Caption = 'Data Pump With MVCActiveRecord Sample' + ClientHeight = 64 + ClientWidth = 425 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -12 + Font.Name = 'Segoe UI' + Font.Style = [] + OnCreate = FormCreate + TextHeight = 15 + object Label1: TLabel + Left = 16 + Top = 24 + Width = 211 + Height = 15 + Caption = 'Migrate data from SQLite to PostgreSQL' + end + object btnDataPump: TButton + Left = 336 + Top = 20 + Width = 81 + Height = 25 + Caption = 'Data Pump' + TabOrder = 0 + OnClick = btnDataPumpClick + end +end diff --git a/samples/datapump/MainFormU.pas b/samples/datapump/MainFormU.pas new file mode 100644 index 00000000..59eb65a6 --- /dev/null +++ b/samples/datapump/MainFormU.pas @@ -0,0 +1,73 @@ +unit MainFormU; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, FireDAC.UI.Intf, + FireDAC.VCLUI.Wait, FireDAC.Stan.Intf, FireDAC.Comp.UI; + +type + TMainForm = class(TForm) + btnDataPump: TButton; + Label1: TLabel; + procedure FormCreate(Sender: TObject); + procedure btnDataPumpClick(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + MainForm: TMainForm; + +implementation + +{$R *.dfm} + +uses + FDConnectionConfigU, MVCFramework.ActiveRecord, CustomerEntityU, + MVCFramework.SQLGenerators.PostgreSQL, MVCFramework.SQLGenerators.Sqlite; + +procedure TMainForm.btnDataPumpClick(Sender: TObject); +begin + // let's prepare connections giving them a name + ActiveRecordConnectionsRegistry.AddConnection('source', 'sqlitecon'); + try + ActiveRecordConnectionsRegistry.AddConnection('destination', 'pgcon'); + try + + // from now on, in this thread, current connection is "source" + ActiveRecordConnectionsRegistry.SetCurrent('source'); + var lCustomers := TMVCActiveRecord.All; + try + + // from now on, in this thread, current connection is "destination" + ActiveRecordConnectionsRegistry.SetCurrent('destination'); + begin var lTx := TMVCActiveRecord.UseTransactionContext; //use TransactionContext + for var lCustomer in lCustomers do + begin + lCustomer.InvalidateConnection; //set connection to the current one + lCustomer.Insert; + end; + end; + + finally + lCustomers.Free; + end; + finally + ActiveRecordConnectionsRegistry.RemoveConnection('destination'); + end; + finally + ActiveRecordConnectionsRegistry.RemoveConnection('source'); + end; +end; + +procedure TMainForm.FormCreate(Sender: TObject); +begin + CreateSqlitePrivateConnDef(False, 'sqlitecon'); + CreatePostgresqlPrivateConnDef(False, 'pgcon'); +end; + +end.