XData TDBParam can it mimic "OutputParam" type available in Delphi?

In Standard Delphi I can use the following code:

SQLStatement:= 'INSERT INTO Comments ' +
' (ID, Memo) ' +
' VALUES ' +
' (:ID, :Memo) ';
AQuery.SQL.Text:= SQLStatement;
AQuery.Prepare;
AQuery.ParamByName('ID').ParamType:= ptOutput
AQuery.ParamByName('Memo').asString:= 'Test'
AQuery.ExecSQL;
MyID:= AQuery.ParamByName('ID').AsInteger;

I am using XData TDBParam with success:

lParams := TObjectList.Create;
lParams.Add(TDBParam.Create('DS', TFieldType.ftDateTime, SomeValue));
AStatement := Manager.Connection.CreateStatement;
AStatement.SetSQLCommand(sExecSQL);
AStatement.SetParams(lParams);
AStatement.Execute;

However I cannot see any way of returning a value (other than the record count) from an "Execute" statement, as shown with the Delphi Output Param example.

Is this possible with XData?

I'm assuming you are referring to TMS Aurelius, not TMS XData, so I'm changing the topic category.

No, Aurelius doesn't support output parameters, but usually you can return values as fields. For example, Aurelius executes this kind of command to insert and retrieve the inserted ID (for example, for Firebird. It depends on the database):

SQLStatement:= 'INSERT INTO Comments ' +
'(Memo) VALUES (:Memo) RETURNING ID';

Then you can retrieve the ID value reading the first field of the result set:

ResultSet := AStatement.ExecuteQuery;
ResultSet.Next;
ReturnedId := ResultSet.GetFieldValue(0);

Thank you Wagner, This was really helpful.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.