{ **************************************************************************** }
{ * LOAD_SQL - Initialisieren der DLL * }
{ **************************************************************************** }
function LOAD_SQL: Boolean;
stdcall;
begin
try
ConnectionList := TObjectlist.Create(True);
QueryList := TObjectlist.Create(True);
DataSourceList := TObjectList.Create(True);
Result := True;
except
Result := False;
end;
DBConnection := TZConnection.Create(DBConnection);
DBConnection.HostName := '
localhost';
DBConnection.User := '
root';
DBConnection.Protocol := '
mysql';
DBConnection.Database := '
kleiderverwaltung';
DBConnection.Connect;
end;
{ **************************************************************************** }
{ * UNLOAD_SQL - Entlädt die DLL * }
{ **************************************************************************** }
function UNLOAD_SQL: Boolean;
stdcall;
var
I: Integer;
AConnection: TZConnection;
begin
try
for I := 0
to ConnectionList.Count -1
do begin
AConnection := (ConnectionList.Items[I])
as TZConnection;
AConnection.Disconnect;
FreeandNil(AConnection);
ConnectionList.Delete(I);
end;
ConnectionList.Clear;
QueryList.Clear;
DataSourceList.Clear;
if (ConnectionList.Count <> 0)
or (QueryList.Count <> 0)
or (DataSourceList.Count <> 0)
then begin
Result := False;
Exit;
end;
ConnectionList.Free;
QueryList.Free;
DataSourceList.Free;
Result := True;
except
Result := False;
end;
end;
{ **************************************************************************** }
{ * CONNECTION_ADD - Erstellt eine neue Verbindung * }
{ **************************************************************************** }
function CONNECTION_ADD(Protocol: PChar; Host: PChar; Port: Integer; User: PChar; Password: PChar; Database: PChar): Integer;
stdcall;
var
AConnection: TZConnection;
ConnectionIndex: Integer;
begin
AConnection := TZConnection.Create(
nil);
if Protocol = '
mysql'
then begin
AConnection.Protocol := '
mysql';
AConnection.HostName := Host;
AConnection.Port := Port;
AConnection.User := User;
AConnection.Password := Password;
AConnection.Database := Database;
AConnection.Catalog := DataBase;
end;
if Protocol = '
sqlite'
then begin
AConnection.Protocol := '
sqlite-3';
AConnection.HostName := Host;
AConnection.Port := Port;
AConnection.User := User;
AConnection.Password := Password;
AConnection.Database := Database;
AConnection.Catalog := DataBase;
end;
if Protocol = '
mssql'
then begin
AConnection.Protocol := '
ado';
AConnection.HostName := Host;
AConnection.Port := Port;
AConnection.User := User;
AConnection.Password := Password;
AConnection.Database := Database;
AConnection.Catalog := DataBase;
end;
if Protocol = '
mdb'
then begin
AConnection.Protocol := '
ado';
AConnection.HostName := Host;
AConnection.Port := Port;
AConnection.User := User;
AConnection.Password := Password;
AConnection.Database := Database;
AConnection.Catalog := DataBase;
end;
try
AConnection.Connect;
AConnection.Disconnect;
ConnectionList.Add(AConnection);
ConnectionIndex := ConnectionList.IndexOf(AConnection);
AConnection.
Name := Format('
connection_%d', [ConnectionIndex]);
AConnection.Tag := ConnectionIndex;
Result := ConnectionIndex;
except
FreeandNil(AConnection);
Result := -1;
end;
end;
{ **************************************************************************** }
{ * QUERY_ADD - Fügt ein neues Query Hinzu * }
{ **************************************************************************** }
function QUERY_ADD(Connection_ID: Integer): Integer;
stdcall;
var
AConnection: TZConnection;
AQuery: TZQuery;
ADataSource: TDataSource;
I: Integer;
QueryIndex: Integer;
//DataSourceIndex: Integer;
begin
for I := 0
to ConnectionList.Count -1
do begin
AConnection := (ConnectionList.Items[Connection_ID])
as TZConnection;
if (AConnection.Tag = Connection_ID)
and (AConnection.
Name = Format('
connection_%d', [Connection_ID]))
then begin
AQuery := TZQuery.Create(
nil);
AQuery.Connection := AConnection;
ADataSource := TDataSource.Create(
nil);
ADataSource.DataSet := AQuery;
QueryList.Add(AQuery);
QueryIndex := QueryList.IndexOf(AQuery);
AQuery.
Name := Format('
query_%d', [QueryIndex]);
AQuery.Tag := QueryIndex;
DataSourceList.Add(ADataSource);
//DataSourceIndex := DataSourceList.IndexOf(ADataSource);
ADataSource.
Name := Format('
datasource_%d', [QueryIndex]);
ADataSource.Tag := QueryIndex;
Result := QueryIndex;
Exit;
end;
end;
Result := -1;
end;