2018-10-23 16:18:34 +02:00
|
|
|
unit FDConnectionConfigU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
const
|
2018-11-02 21:43:09 +01:00
|
|
|
CON_DEF_NAME = 'MyConnX';
|
2018-10-23 16:18:34 +02:00
|
|
|
|
|
|
|
procedure CreateFirebirdPrivateConnDef(AIsPooled: boolean);
|
2020-01-08 15:30:10 +01:00
|
|
|
procedure CreateInterbasePrivateConnDef(AIsPooled: boolean);
|
2018-10-23 16:18:34 +02:00
|
|
|
procedure CreateMySQLPrivateConnDef(AIsPooled: boolean);
|
2020-04-18 15:04:27 +02:00
|
|
|
procedure CreateMSSQLServerPrivateConnDef(AIsPooled: boolean);
|
2019-01-13 18:56:33 +01:00
|
|
|
procedure CreatePostgresqlPrivateConnDef(AIsPooled: boolean);
|
2019-06-24 20:59:33 +02:00
|
|
|
procedure CreateSqlitePrivateConnDef(AIsPooled: boolean);
|
2018-10-23 16:18:34 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.Classes,
|
|
|
|
System.IOUtils,
|
2022-11-10 18:30:11 +01:00
|
|
|
FireDAC.Comp.Client,
|
|
|
|
FireDAC.Moni.Base,
|
|
|
|
FireDAC.Moni.FlatFile, FireDAC.Stan.Intf
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
gFlatFileMonitor: TFDMoniFlatFileClientLink = nil;
|
2018-10-23 16:18:34 +02:00
|
|
|
|
|
|
|
procedure CreateMySQLPrivateConnDef(AIsPooled: boolean);
|
|
|
|
var
|
|
|
|
LParams: TStringList;
|
|
|
|
begin
|
2022-08-09 13:02:29 +02:00
|
|
|
{
|
|
|
|
docker run --detach --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_ROOT_PASSWORD=root -p 3306:3306 mariadb:latest
|
|
|
|
}
|
2021-11-21 19:27:06 +01:00
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
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 }
|
2022-08-09 13:02:29 +02:00
|
|
|
LParams.Add('CharacterSet=utf8mb4'); // not utf8!!
|
2018-10-23 16:18:34 +02:00
|
|
|
if AIsPooled then
|
|
|
|
begin
|
|
|
|
LParams.Add('Pooled=True');
|
|
|
|
LParams.Add('POOL_MaximumItems=100');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
LParams.Add('Pooled=False');
|
|
|
|
end;
|
2018-11-02 21:43:09 +01:00
|
|
|
FDManager.AddConnectionDef(CON_DEF_NAME, 'MySQL', LParams);
|
2018-10-23 16:18:34 +02:00
|
|
|
finally
|
|
|
|
LParams.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-04-18 15:04:27 +02:00
|
|
|
procedure CreateMSSQLServerPrivateConnDef(AIsPooled: boolean);
|
|
|
|
var
|
|
|
|
LParams: TStringList;
|
|
|
|
begin
|
2022-08-09 13:02:29 +02:00
|
|
|
{
|
|
|
|
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=!SA_password!" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
|
|
|
|
}
|
2021-11-21 19:27:06 +01:00
|
|
|
|
2020-04-18 15:04:27 +02:00
|
|
|
// [ACTIVERECORDB_SQLSERVER]
|
|
|
|
// Database=activerecorddb
|
|
|
|
// OSAuthent=Yes
|
|
|
|
// Server=DANIELETETI\SQLEXPRESS
|
|
|
|
// DriverID=MSSQL
|
|
|
|
//
|
|
|
|
|
|
|
|
LParams := TStringList.Create;
|
|
|
|
try
|
|
|
|
LParams.Add('Database=activerecorddb');
|
2022-08-09 13:02:29 +02:00
|
|
|
LParams.Add('OSAuthent=Yes');
|
|
|
|
// LParams.Add('User_Name=sa');
|
|
|
|
// LParams.Add('Password=sa');
|
|
|
|
LParams.Add('Server=DANIELETETI\SQLEXPRESS');
|
2020-04-18 15:04:27 +02:00
|
|
|
// LParams.Add('TinyIntFormat=Boolean'); { it's the default }
|
|
|
|
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;
|
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
procedure CreateFirebirdPrivateConnDef(AIsPooled: boolean);
|
|
|
|
var
|
|
|
|
LParams: TStringList;
|
|
|
|
begin
|
|
|
|
LParams := TStringList.Create;
|
|
|
|
try
|
2022-11-10 18:30:11 +01:00
|
|
|
LParams.Add('Database=' + TPath.GetFullPath(TPath.Combine('..\..',
|
2022-08-09 13:02:29 +02:00
|
|
|
'data\ACTIVERECORDDB.FDB')));
|
2018-10-23 16:18:34 +02:00
|
|
|
LParams.Add('Protocol=TCPIP');
|
|
|
|
LParams.Add('Server=localhost');
|
|
|
|
LParams.Add('User_Name=sysdba');
|
|
|
|
LParams.Add('Password=masterkey');
|
2021-04-05 18:45:55 +02:00
|
|
|
LParams.Add('CharacterSet=UTF8');
|
2018-10-23 16:18:34 +02:00
|
|
|
if AIsPooled then
|
|
|
|
begin
|
|
|
|
LParams.Add('Pooled=True');
|
|
|
|
LParams.Add('POOL_MaximumItems=100');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
LParams.Add('Pooled=False');
|
|
|
|
end;
|
2018-11-02 21:43:09 +01:00
|
|
|
FDManager.AddConnectionDef(CON_DEF_NAME, 'FB', LParams);
|
2018-10-23 16:18:34 +02:00
|
|
|
finally
|
|
|
|
LParams.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-01-08 15:30:10 +01:00
|
|
|
procedure CreateInterbasePrivateConnDef(AIsPooled: boolean);
|
|
|
|
var
|
|
|
|
LParams: TStringList;
|
|
|
|
begin
|
|
|
|
LParams := TStringList.Create;
|
|
|
|
try
|
2022-08-09 13:02:29 +02:00
|
|
|
LParams.Add('Database=' + TPath.GetFullPath(TPath.Combine('..\..',
|
|
|
|
'data\ACTIVERECORDDB.IB')));
|
2020-01-08 15:30:10 +01:00
|
|
|
LParams.Add('Protocol=TCPIP');
|
|
|
|
LParams.Add('Server=localhost');
|
|
|
|
LParams.Add('User_Name=sysdba');
|
|
|
|
LParams.Add('Password=masterkey');
|
2021-04-05 18:45:55 +02:00
|
|
|
LParams.Add('CharacterSet=UTF8');
|
2020-01-08 15:30:10 +01:00
|
|
|
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;
|
|
|
|
|
2019-01-13 18:56:33 +01:00
|
|
|
procedure CreatePostgresqlPrivateConnDef(AIsPooled: boolean);
|
|
|
|
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');
|
2020-04-08 18:04:45 +02:00
|
|
|
LParams.Add('Password=postgres');
|
2022-11-10 18:30:11 +01:00
|
|
|
LParams.Add('MonitorBy=FlatFile');
|
2022-06-16 14:05:01 +02:00
|
|
|
|
|
|
|
// https://quality.embarcadero.com/browse/RSP-19755?jql=text%20~%20%22firedac%20guid%22
|
|
|
|
LParams.Add('GUIDEndian=Big');
|
2019-01-13 18:56:33 +01:00
|
|
|
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, 'PG', LParams);
|
|
|
|
finally
|
|
|
|
LParams.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2019-06-24 20:59:33 +02:00
|
|
|
procedure CreateSqlitePrivateConnDef(AIsPooled: boolean);
|
|
|
|
var
|
|
|
|
LParams: TStringList;
|
2019-09-13 15:17:56 +02:00
|
|
|
lFName: string;
|
2019-06-24 20:59:33 +02:00
|
|
|
begin
|
|
|
|
LParams := TStringList.Create;
|
|
|
|
try
|
2022-08-09 13:02:29 +02:00
|
|
|
lFName := TPath.Combine(TPath.GetDirectoryName(ParamStr(0)),
|
|
|
|
'..\..\data\activerecorddb.db');
|
2019-09-13 15:17:56 +02:00
|
|
|
LParams.Add('Database=' + lFName);
|
2021-04-05 18:45:55 +02:00
|
|
|
LParams.Add('StringFormat=Unicode');
|
2019-06-24 20:59:33 +02:00
|
|
|
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, 'SQLite', LParams);
|
|
|
|
finally
|
|
|
|
LParams.Free;
|
|
|
|
end;
|
|
|
|
end;
|
2019-01-13 18:56:33 +01:00
|
|
|
|
2022-11-10 18:30:11 +01:00
|
|
|
initialization
|
|
|
|
|
|
|
|
gFlatFileMonitor := TFDMoniFlatFileClientLink.Create(nil);
|
|
|
|
gFlatFileMonitor.FileColumns := [tiRefNo, tiTime, tiThreadID, tiClassName, tiObjID, tiMsgText];
|
|
|
|
gFlatFileMonitor.EventKinds := [
|
|
|
|
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;
|
|
|
|
|
2018-10-23 16:18:34 +02:00
|
|
|
end.
|