Hi Wagner,
I have created a standard XDataServer with automatic CRUD entities and would like to add some service operations which needs database access.
If I understood correct the following code should provide a database connection which could be used in a service operation.
var
Statement: IDBStatement;
ResultSet: IDBResultSet;
Statement := Manager.Connection.CreateStatement;
Statement.SetSQLCommand(TheSQLStatement);
ResultSet := Statement.ExecuteQuery;
Must the Statement and ResultSet not be freed after use?
A new instance of this data module will be created by this code.
Besides FDConnection there are of course other components on the datatamodule.
Doesn't this give a lot of overhead or other possible issues?
wlandgraf
(Wagner Landgraf)
May 26, 2025, 8:02am
2
That is correct.
No, you don't need to destroy them. As they are reference-counted interfaces, they will be destroyed automatically when they get out of scope.
No.
No, that's the correct way to do so and there are no additional overheads compared to the way CRUD operations are also retrieving connections and executing statements.
Thank you for the explanation.
Statement := Manager.Connection.CreateStatement;
Where can I find Manager?
wlandgraf
(Wagner Landgraf)
May 26, 2025, 5:34pm
4
You can get manager this way:
Manager := TXDataOperationContext.Current.GetManager;
Or you can simply do it this way if you don't use manager:
var
Statement: IDBStatement;
ResultSet: IDBResultSet;
Statement := TXDataOperationContext.Current.Connection.CreateStatement;
Statement.SetSQLCommand(TheSQLStatement);
ResultSet := Statement.ExecuteQuery;
Hi Wagner, thanks again for the great support. That did the trick.
1 Like
system
(system)
Closed
May 28, 2025, 5:32pm
6
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.