You have three options.
- Use the connection pool normally, and execute queries using the Aurelius interfaces, this way:
For UPDATE/INSERT/DELETE:
uses {...}, Aurelius.Drivers.Interfaces;
var
Statement: IDBStatement;
Statement := Manager.Connection.CreateStatement;
Statement.SetSQLCommand(TheSQLStatement);
Statement.Execute;
for SELECT:
var
Statement: IDBStatement;
ResultSet: IDBResultSet;
Statement := Manager.Connection.CreateStatement;
Statement.SetSQLCommand(TheSQLStatement);
ResultSet := Statement.ExecuteQuery;
while ResultSet.Next do
Value := ResultSet.GetFieldValue(SomeFieldName);
Finally, for both types of commands you can set parameter values:
{...}
Params := TObjectList<TDBParam>.Create;
try
Statement := Manager.Connection.CreateStatement;
Params.Add(TDBParam.Create('id', ftInteger, 15));
Statement.SetSQLCommand('Delete from Customer Where Id = :id');
Statement.SetParams(Params);
Statement.Execute;
finally
Params.Free;
end;
- Use the connection pool normally, then get the underlying TFDConnection component:
var
MyConnection: IDBConnection;
FDConnection: TFDConnection;
{...}
FDConnection := (MyConnection as IDBConnectionAdapter).AdaptedConnection as TFDConnection;
With the TFDConnection
in hands, create a new TFDQuery in each request, associated with the TFDConnection
- Enable FireDac pooling and simply create a new
TFDConnection
andTFDQuery
in each request.
Do not reuse global connections or queries as it's not thread-safe.