RETURNING Value not set with design time editor

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
HelgeLange
Posts: 17
Joined: Wed 13 Jun 2007 16:40
Location: Caracas

RETURNING Value not set with design time editor

Post by HelgeLange » Tue 05 Dec 2017 18:35

Hi Devart,

I came across a curious behaviour today.
I use auto inc fields (with generator) in a firebird database and use the sql

Code: Select all

INSERT INTO (MyValue) VALUES (:Valor) RETURNING DocId
On an old form I'm currently updating I had the SQl saved in the SQL property at design time (normally I load them dynamically into the UniQuery1.SQL.Text property) and I left it there and added only the "RETURNING DocID" to the SQL.

But I get the "RET_DocId" not found error when I try to read the Out-Param. When I switched to my dynamically loaded SQL. it works as expected.

BTW: I use a standard function I wrote to run these inserts with returning id as optional parameter and it works fine with all other forms (which load dynamically SQL at run time. :

Code: Select all

function TDMWXSI.DoTrySave_Document(DS: TDataSet; Q: TUniQuery; const Return_FieldName: String = ''): Int64;
var bAgain: Boolean;
    AField : TField;
    Numero : Integer;
begin
  Result := -1;
  AField := DMWXSI.FindField(DS, 8004);  // looking for field 'Numero'

  If Assigned(AField) Then
    Numero := AField.AsInteger                      // If we have a dataset to get the initial number from...
  Else
    Numero := Q.ParamByName('Numero').AsInteger;    // if no we get the initial number from the param Numero

  bAgain := True;
  While bAgain Do begin
    Try
      Q.ParamByName('Numero').AsInteger := Numero;
      Q.ExecSQL;
      If Assigned(AField) Then
        If AField.AsInteger <> Numero Then begin
          DS.Edit;
          AField.AsInteger := Numero;
          DS.Post;
        end;
      bAgain := False;
      If Return_FieldName <> '' Then
        Result := Q.ParamByName('RET_' + Return_FieldName).AsLargeInt;
    Except on E: Exception Do
      If Pos('PRIMARY or UNIQUE KEY', E.Message) <> 0 Then
        Inc(Numero)
      Else
        Raise Exception.Create(E.Message);
    end;
  end;  //  --  While bAgain Do
end;
Just to let you know. It drove me crazy all morning.
Helge

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: RETURNING Value not set with design time editor

Post by ViktorV » Wed 06 Dec 2017 14:39

Unfortunately we could not reproduce the issue on the latest UniDAC 7.1.4 version.
Please check whether the problem occurs on the latest version UniDAC 7.1.4 and inform us about the result. It it is, please compose a full sample demonstrating the described behavior and send it to us via e-support form: https://www.devart.com/company/contactform.html, including scripts for creating database objects.

Post Reply