Figure it, I have connection properties like this:
Code: Select all
compress=yes
dbless=no
useresult=no
timeout=30
arg1=--basedir=./mysql
arg2=--datadir=./mysql/data
arg3=--character-sets-dir=./mysql/share/charsets
arg4=--language=./mysql/share/english
arg5=--skip-innodb
arg6=--key_buffer_size=32M
So I have modify MySQL library of ZEOSLIB.
1. ZPlainMySQLDriver.pas
a. Add uses clause of Classes
Before
Code: Select all
uses ZClasses, ...
Code: Select all
uses Classes, ZClasses, ...
Code: Select all
function GetFieldData(Row: PZMySQLRow; Offset: Cardinal): PChar;
procedure BuildOptions(Options: TStrings);
Code: Select all
TZMySQL5PlainDriver = class (TZAbstractObject, IZPlainDriver,
IZMySQLPlainDriver)
....
public
...
procedure BuildOptions(Options: TStrings); virtual;
end;
TZMySQLD5PlainDriver = class (TZMySQL5PlainDriver)
public
...
procedure BuildOptions(Options: TStrings); override;
end;
Code: Select all
uses SysUtils, ZMessages;
var
ServerArgs: array of PChar;
ServerArgsLen: Integer;
const
ServerArgsKeyPrefix = 'arg';
procedure BuildServerArguments(Options: TStrings);
var
Tmp: TStringList;
i: Integer;
begin
Tmp := TStringList.Create;
try
Tmp.Add(ParamStr(0));
for i := 0 to Options.Count - 1 do
if SameText(ServerArgsKeyPrefix, Copy(Options.Names[i], 1, Length(ServerArgsKeyPrefix))) then
Tmp.Add(Options.ValueFromIndex[i]);
ServerArgsLen := Tmp.Count;
SetLength(ServerArgs, ServerArgsLen);
for i := 0 to ServerArgsLen - 1 do
ServerArgs[i] := StrNew(PChar(Tmp[i]));
finally
Tmp.Free;
end;
end;
Code: Select all
procedure TZMySQL5PlainDriver.BuildArguments(Options: TStrings);
begin
// leave blank for non embedded
end;
procedure TZMySQLD5PlainDriver.BuildArguments(Options: TStrings);
begin
BuildServerArguments(Options);
end;
Code: Select all
function TZMySQLD5PlainDriver.Init(var Handle: PZMySQLConnect): PZMySQLConnect;
begin
if @MYSQL_API.mysql_server_init <> nil then
MYSQL_API.mysql_server_init(ServerArgsLen, ServerArgs, @SERVER_GROUPS);
// MYSQL_API.mysql_server_init(3, @DEFAULT_PARAMS, @SERVER_GROUPS);
Handle := MYSQL_API.mysql_init(nil);
Result := Handle;
end;
Insert code commented below to the existing code:
Code: Select all
function TZMySQLDriver.Connect(const Url: string; Info: TStrings): IZConnection;
var
TempInfo: TStrings;
HostName, Database, UserName, Password: string;
Port: Integer;
PlainDriver: IZMySQLPlainDriver;
begin
TempInfo := TStringList.Create;
try
PlainDriver := GetPlainDriver(Url);
ResolveDatabaseUrl(Url, Info, HostName, Port, Database,
UserName, Password, TempInfo);
// insert this line
if PlainDriver <> nil then
PlainDriver.BuildArguments(TempInfo);
// end of insert line
Result := TZMySQLConnection.Create(Self, Url, PlainDriver, HostName, Port,
Database, UserName, Password, TempInfo);
finally
TempInfo.Free;
end;
end;