106 lines
2.5 KiB
ObjectPascal
106 lines
2.5 KiB
ObjectPascal
unit uDM;
|
|
|
|
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.Stan.Param,
|
|
FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Phys.PGDef,
|
|
FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Phys.PG, Data.DB,
|
|
FireDAC.Comp.DataSet, FireDAC.Comp.Client;
|
|
|
|
type
|
|
TDM = class(TDataModule)
|
|
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
|
|
FDPhysPgDriverLink1: TFDPhysPgDriverLink;
|
|
FDQuery1: TFDQuery;
|
|
FDConnection1: TFDConnection;
|
|
FDQuery2: TFDQuery;
|
|
procedure DataModuleDestroy(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
PG_DBName : string;
|
|
PG_UserName : string;
|
|
PG_Password : string;
|
|
PG_Host : string;
|
|
PG_Port : string;
|
|
|
|
function DM_Connect:Boolean;
|
|
function DM_Close:Boolean;
|
|
function xAddSqlMark(velStr: String): String;
|
|
function xAddSqlDoubleMark(velStr: String): string;
|
|
end;
|
|
|
|
var
|
|
DM: TDM;
|
|
|
|
implementation
|
|
|
|
{%CLASSGROUP 'Vcl.Controls.TControl'}
|
|
|
|
{$R *.dfm}
|
|
|
|
{ TDM }
|
|
|
|
function TDM.DM_Connect:Boolean;
|
|
begin
|
|
FDPhysPgDriverLink1.VendorLib := '.\libpq-10.dll';
|
|
|
|
FDConnection1.Connected := False;
|
|
|
|
FDConnection1.Params.Clear;
|
|
FDConnection1.Params.DriverID := 'PG';
|
|
FDConnection1.Params.Database := Trim(PG_DBName);
|
|
FDConnection1.Params.UserName := Trim(PG_UserName);
|
|
FDConnection1.Params.Password := Trim(PG_Password);
|
|
FDConnection1.Params.Add('Server=' + Trim(PG_Host));
|
|
FDConnection1.Params.Add('Port=' + Trim(PG_Port));
|
|
FDConnection1.Params.Add('CharacterSet=UTF8');
|
|
|
|
try
|
|
FDConnection1.Connected := True;
|
|
|
|
Result := True;
|
|
// Memo1.Lines.Add('연결 성공');
|
|
// Memo1.Lines.Add('"Q1" 버튼을 누른 후 "쿼리" 버튼을 누르세요!!');
|
|
|
|
except
|
|
on E: Exception do begin
|
|
Result := False;
|
|
// Memo1.Lines.Add('연결 실패: ' + E.Message);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TDM.DataModuleDestroy(Sender: TObject);
|
|
begin
|
|
if FDConnection1.Connected then FDConnection1.Connected := False;
|
|
end;
|
|
|
|
function TDM.DM_Close:Boolean;
|
|
begin
|
|
try
|
|
if FDConnection1.Connected then FDConnection1.Connected := False;
|
|
Result := True;
|
|
except
|
|
Result := False;
|
|
end;
|
|
end;
|
|
|
|
function TDM.xAddSqlDoubleMark(velStr: String): string;
|
|
begin
|
|
Result := '';
|
|
Result := '"' + velStr + '"';
|
|
end;
|
|
|
|
function TDM.xAddSqlMark(velStr: String): String;
|
|
begin
|
|
Result := '';
|
|
Result := '''' + velStr + '''';
|
|
end;
|
|
|
|
end.
|