Here is my Code for XData + Apache + MySQL(UniDac)
The module runs on the linux server but there is no open connection to the db I can not get any data.
library mod_stdb;
uses
{$IFDEF MSWINDOWS}
Winapi.ActiveX,
{$ENDIF }
Web.WebBroker,
Web.ApacheApp,
Web.HTTPD24Impl,
WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule},
ConnectionModule in 'ConnectionModule.pas' {UniDacMySqlConnection: TDataModule};
{$R .res}
// httpd.conf entries:
//
(
LoadModule stdb_module modules/mod_stdb.dll
<Location /xyz>
SetHandler mod_stdb-handler
</Location>
*)
//
// These entries assume that the output directory for this project is the apache/modules directory.
//
// httpd.conf entries should be different if the project is changed in these ways:
// 1. The TApacheModuleData variable name is changed.
// 2. The project is renamed.
// 3. The output directory is not the apache/modules directory.
// 4. The dynamic library extension depends on a platform. Use .dll on Windows and .so on Linux.
//
// Declare exported variable so that Apache can access this module.
var
GModuleData: TApacheModuleData;
exports
GModuleData name 'stdb_module';
begin
{$IFDEF MSWINDOWS}
CoInitFlags := COINIT_MULTITHREADED;
{$ENDIF}
Web.ApacheApp.InitApplication(@GModuleData);
Application.Initialize;
Application.WebModuleClass := WebModuleClass;
//Application.CreateForm(TUniDacMySqlConnection, UniDacMySqlConnection);
Application.Run;
end.
unit WebModuleUnit1;
interface
uses
System.SysUtils, System.Classes, Web.HTTPApp,
Sparkle.WebBroker.Server,
Sparkle.WebBroker.Adapter,
Sparkle.HttpServer.Module,
Sparkle.HttpServer.Context,
XData.Server.Module,
ConnectionModule,
Aurelius.Engine.DatabaseManager,
XData.OpenApi.Service,
XData.SwaggerUI.Service,
XData.Aurelius.ConnectionPool;
type
TWebModule1 = class(TWebModule)
procedure WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure WebModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
WebModuleClass: TComponentClass = TWebModule1;
Server : TWebBrokerServer;
Module : TXDataServerModule;
implementation
{%CLASSGROUP 'System.Classes.TPersistent'}
{$R *.dfm}
procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
Adapter: IWebBrokerAdapter;
begin
Adapter := TWebBrokerAdapter.Create(Request, Response);
Server.DispatchRequest(Adapter);
end;
procedure TWebModule1.WebModuleCreate(Sender: TObject);
begin
TDatabaseManager.Update(TUniDacMySqlConnection.CreateConnection);
end;
initialization
RegisterSwaggerUIService;
RegisterOpenApiService;
UniDacMySqlConnection := TUniDacMySqlConnection.Create(nil);
Server := TWebBrokerServer.Create;
//TDatabaseManager.Update(TUniDacMySqlConnection.CreateConnection);
Module := TXDataServerModule.Create(
TDBConnectionPool.Create(20, TUniDacMySqlConnection.CreateFactory));
Server.Dispatcher.AddModule(Module);
Server.Dispatcher.AddModule(TAnonymousServerModule.Create(
procedure(const C: THttpServerContext)
begin
C.Response.StatusCode := 200;
C.Response.ContentType := 'text/plain';
C.Response.Close(TEncoding.UTF8.GetBytes('Hello from Sparkle!'));
end
));
finalization
Server.Free;
UniDacMySqlConnection.Free;
end.
unit ConnectionModule;
interface
uses
Aurelius.Drivers.Interfaces,
Aurelius.Drivers.UniDac,
System.SysUtils, System.Classes, Aurelius.Sql.MySQL, Aurelius.Schema.MySQL,
Aurelius.Comp.Connection, Data.DB, DBAccess, Uni, UniProvider,
MySQLUniProvider, MemDS;
type
TUniDacMySqlConnection = class(TDataModule)
Connection: TUniConnection;
AureliusConnection1: TAureliusConnection;
MySQLUniProvider1: TMySQLUniProvider;
UniSQL1: TUniSQL;
UniQuery1: TUniQuery;
procedure DataModuleCreate(Sender: TObject);
private
public
class function CreateConnection: IDBConnection;
class function CreateFactory: IDBConnectionFactory;
end;
var
UniDacMySqlConnection: TUniDacMySqlConnection;
implementation
{%CLASSGROUP 'System.Classes.TPersistent'}
uses
Aurelius.Drivers.Base;
{$R *.dfm}
{ TMyConnectionModule }
class function TUniDacMySqlConnection.CreateConnection: IDBConnection;
begin
Result := UniDacMySqlConnection.AureliusConnection1.CreateConnection;
end;
class function TUniDacMySqlConnection.CreateFactory: IDBConnectionFactory;
begin
Result := TDBConnectionFactory.Create(
function: IDBConnection
begin
Result := CreateConnection;
end
);
end;
end.