mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00

* Replace the pulldown by a list to get a better overview * Display last connected and created date in details * Prompt user on form closing if modifications should be saved * Remove moreorless useless image * Remove options "timeout" and "sort database" TODO: Display some help text on the right side when no session at all is existant to help new users.
118 lines
2.6 KiB
ObjectPascal
118 lines
2.6 KiB
ObjectPascal
unit MysqlConn;
|
|
|
|
interface
|
|
|
|
uses ZConnection, ExtCtrls, MysqlQueryThread;
|
|
|
|
const
|
|
// connection attemp result codes
|
|
MCR_SUCCESS = 0;
|
|
MCR_FAILED = 1;
|
|
|
|
{$I const.inc}
|
|
|
|
type
|
|
|
|
|
|
TMysqlConn = class
|
|
private
|
|
FConn : TZConnection;
|
|
FOpenConn : TOpenConnProf;
|
|
FLastError : String;
|
|
function GetIsAlive: Boolean;
|
|
function GetIsConnected: Boolean;
|
|
//FTimer : TTimer;
|
|
public
|
|
constructor Create(AConn : POpenConnProf);
|
|
destructor Destroy(); override;
|
|
function Connect() : Integer;
|
|
procedure Disconnect();
|
|
property IsConnected : Boolean read GetIsConnected;
|
|
property IsAlive : Boolean read GetIsAlive;
|
|
property Connection : TZConnection read FConn;
|
|
property LastError : String read FLastError;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses SysUtils;
|
|
|
|
{ TMysqlConn }
|
|
|
|
constructor TMysqlConn.Create;
|
|
begin
|
|
FConn := TZConnection.Create(nil);
|
|
FOpenConn := AConn^;
|
|
FLastError := '';
|
|
end;
|
|
|
|
function TMysqlConn.Connect(): Integer;
|
|
begin
|
|
FLastError := '';
|
|
|
|
if FConn.Connected then FConn.Disconnect;
|
|
with FOpenConn.MysqlParams do
|
|
begin
|
|
FConn.Protocol := 'mysql';
|
|
if FOpenConn.MysqlParams.NetType = NETTYPE_TCPIP then begin
|
|
FConn.Hostname := Host;
|
|
FConn.SocketName := '';
|
|
end else begin
|
|
FConn.Hostname := '.';
|
|
FConn.SocketName := Host;
|
|
end;
|
|
FConn.User := User;
|
|
FConn.Password := Pass;
|
|
FConn.Port := Port;
|
|
|
|
FConn.Properties.Values['compress'] := PrpCompress;
|
|
FConn.Properties.Values['dbless'] := PrpDbless;
|
|
FConn.Properties.Values['CLIENT_LOCAL_FILES'] := PrpClientLocalFiles;
|
|
FConn.Properties.Values['CLIENT_INTERACTIVE'] := PrpClientInteractive;
|
|
// ZConn.Properties.Values['USE_RESULT'] := 'true'; // doesn't work
|
|
// ZConn.Properties.Values['CLIENT_SSL'] := 'true'; // from an mdaems's example
|
|
FConn.Properties.Values['CLIENT_MULTI_RESULTS'] := '1';
|
|
end;
|
|
|
|
try
|
|
FConn.Connect();
|
|
Result := MCR_SUCCESS;
|
|
except
|
|
// todo: handle exception
|
|
on E : Exception do
|
|
begin
|
|
FLastError := E.Message;
|
|
Result := MCR_FAILED;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TMysqlConn.Disconnect;
|
|
begin
|
|
if FConn.Connected then FConn.Disconnect;
|
|
end;
|
|
|
|
|
|
destructor TMysqlConn.Destroy;
|
|
begin
|
|
if FConn.Connected then FConn.Disconnect;
|
|
FreeAndNil (FConn);
|
|
inherited;
|
|
end;
|
|
|
|
function TMysqlConn.GetIsAlive: Boolean;
|
|
begin
|
|
Result := False;
|
|
if IsConnected then Result := FConn.Ping();
|
|
end;
|
|
|
|
function TMysqlConn.GetIsConnected: Boolean;
|
|
begin
|
|
Result := FConn.Connected;
|
|
end;
|
|
|
|
|
|
|
|
end.
|