delphimvcframework/samples/angular2/dmvcframeworkserver/CustomersTDGU.pas

86 lines
2.0 KiB
ObjectPascal
Raw Normal View History

2016-12-01 15:23:03 +01:00
unit CustomersTDGU;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait,
Data.DB, FireDAC.Comp.Client, FireDAC.Comp.UI, FireDAC.Phys.FBDef,
FireDAC.Phys.IBBase, FireDAC.Phys.FB, FireDAC.DApt;
type
TCustomersTDG = class(TDataModule)
FDConnection1: TFDConnection;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
function GetCustomers: TDataSet;
function GetCustomerById(const ID: UInt64): TDataSet;
end;
procedure SetupFireDACConnection;
implementation
uses
FireDAC.Stan.Param;
const
PRIVATE_CONN_DEF_NAME = 'MYCONNECTION';
{ %CLASSGROUP 'Vcl.Controls.TControl' }
2017-04-30 00:05:21 +02:00
{$R *.dfm}
2016-12-01 15:23:03 +01:00
{ TDataModule1 }
procedure TCustomersTDG.DataModuleCreate(Sender: TObject);
begin
FDConnection1.ConnectionDefName := PRIVATE_CONN_DEF_NAME;
FDConnection1.Connected := True;
end;
function TCustomersTDG.GetCustomerById(const ID: UInt64): TDataSet;
var
lParams: TFDParams;
lParam: TFDParam;
begin
lParams := TFDParams.Create;
try
lParam := lParams.Add;
lParam.AsLargeInt := ID;
lParam.Name := 'ID';
FDConnection1.ExecSQL('SELECT * FROM CUSTOMERS WHERE ID = :ID', lParams, Result);
finally
lParams.Free;
end;
end;
function TCustomersTDG.GetCustomers: TDataSet;
begin
FDConnection1.ExecSQL('SELECT * FROM CUSTOMERS ORDER BY ID', Result);
end;
procedure SetupFireDACConnection;
var
lParams: TStrings;
begin
lParams := TStringList.Create;
try
2017-04-30 00:05:21 +02:00
// Use CUSTOMERS_FB25.FDB is you are using firebird 2.5
lParams.Add('Database=' + ExtractFilePath(GetModuleName(HInstance)) + '\CUSTOMERS_FB30.FDB');
2016-12-01 15:23:03 +01:00
lParams.Add('Protocol=TCPIP');
lParams.Add('Server=localhost');
lParams.Add('User_Name=sysdba');
lParams.Add('Password=masterkey');
lParams.Add('Pooled=true');
2016-12-01 15:23:03 +01:00
FDManager.AddConnectionDef(PRIVATE_CONN_DEF_NAME, 'FB', lParams);
finally
lParams.Free;
end;
end;
end.