unit MaxMySqlQuery;
interface
uses
SysUtils, Classes,
mysql,MaxMySqlCon, Dialogs;
type
TMaxMySqlQuery =
class(TComponent)
//(TMaxMySqlCon) //Vererbt von TMaxMySqlCon
private
{ Private-Deklarationen }
TSource : TMaxMySqlCon;
SQL_Text : PChar;
SQL_Result : PMYSQL_RES;
// SQL_Row : PMYSQL_ROW;
protected
{ Protected-Deklarationen }
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
public
{ Public-Deklarationen }
procedure Clear();
procedure Add(SQL_String:
String);
function Open(): PMYSQL_RES;
procedure ExecSQL();
function RowCount():Integer;
published
{ Published-Deklarationen }
property Datasource : TMaxMySqlCon
read TSource
write TSource;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
MaxMySql', [TMaxMySqlQuery]);
end;
{******************************************************************************
Notification überschreiben
*******************************************************************************}
procedure TMaxMySqlQuery.Notification(Acomponent : TComponent; Operation: TOperation);
begin
if (Operation = opRemove)
and (AComponent
is TMaxMySqlCon)
then
TSource :=
nil;
end;
{******************************************************************************
Sql Clear
*******************************************************************************}
procedure TMaxMySqlQuery.Clear();
begin
mysql_free_result(SQL_Result);
end;
{******************************************************************************
Sql Add
*******************************************************************************}
procedure TMaxMySqlQuery.Add(SQL_String:
String);
begin
SQL_Text:=PChar(SQL_String);
end;
{******************************************************************************
Sql Open
*******************************************************************************}
function TMaxMySqlQuery.Open(): PMYSQL_RES;
//var x : Integer;
begin
if TSource.Connected
then
begin
mysql_real_query(TSource._MySql,SQL_Text,length(SQL_Text));
SQL_Result := mysql_store_result(TSource._MySql);
//alle Datensätze vom Server anfordern
if TSource._MySql =
nil then
begin
ShowMessage('
Es konnten keine Datensätze zurückgebenen werden. Ursache: ' + mysql_error(TSource._MySql));
result:=
nil;
Exit;
end;
end
else
ShowMessage('
Kann Abfrage nicht durchführen da keine Verbindung zum Server besteht');
// x:= mysql_num_rows(Sql_Result);
result:= SQL_Result;
end;
{******************************************************************************
Sql ExecSQL
*******************************************************************************}
procedure TMaxMySqlQuery.ExecSQL();
begin
end;
{******************************************************************************
Row Count -1 wenn nicht verbunden
*******************************************************************************}
function TMaxMySqlQuery.RowCount():Integer;
begin
if TSource.Connected
then
result:= mysql_num_rows(SQL_Result)
else
result:= -1;
end;
end.