TUniParam.Assign get a "Parameter not found" Exception

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Jeweller
Posts: 13
Joined: Thu 18 Jun 2015 16:37

TUniParam.Assign get a "Parameter not found" Exception

Post by Jeweller » Thu 02 Jul 2015 08:32

Hello,
I have another strange behavior that worked with ADO before... If you assign a parameter, this one seems to not exist any more after (or we loose his name?):

Code: Select all

 UniConnection.open;

//Param DT_ECH was created by design in the DFM and the SQL too
 UniQuery.ParamByName('DT_ECH').value := now;  // no pb

 UniQuery.ParamByName('DT_ECH').assign(  AnOtherActiveUniQuery.FieldByName('DT_ECH') );  //no pb

//an UniQuery.open here would work!

//but now We cannot access to this parameter but get an exception "Parameter DT_ECH not found"
if UniQuery.ParamByName('DT_ECH').value <=0  //HERE WE GET THE EXCEPTION
then ...

Any advise ?
regards
Michael

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: TUniParam.Assign get a "Parameter not found" Exception

Post by AlexP » Thu 02 Jul 2015 10:17

Hello,

Please specify the versions of UniDAC and IDE you are using.

Jeweller
Posts: 13
Joined: Thu 18 Jun 2015 16:37

Re: TUniParam.Assign get a "Parameter not found" Exception

Post by Jeweller » Fri 03 Jul 2015 08:10

Yes Sorry, UniDac 6.1.3 (SQLServer provider or Oracle) and Delphi 2007.
Michael

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: TUniParam.Assign get a "Parameter not found" Exception

Post by AlexP » Fri 03 Jul 2015 09:25

We can't reproduce the problem on the latest UniDAC version 6.1.5. Please modify the following code, so that the problem is reproduced and send it back to us.

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Uni, OracleUniProvider;

var
  UniConnection: TUniConnection;
  UniQuery1, UniQuery2: TUniQuery;

begin
  UniConnection := TUniConnection.Create(nil);
  try
    UniConnection.ConnectString := 'ProviderName=Oracle;Server=Orcl1120;UID=alexp;PWD=11111';
    UniConnection.Connect;
    UniQuery1 := TUniQuery.Create(nil);
    try
      UniQuery1.Connection := UniConnection;
      UniQuery1.SQL.Text := 'SELECT DEPTNO FROM DEPT';
      UniQuery1.Open;
      UniQuery2 := TUniQuery.Create(nil);
      try
        UniQuery2.Connection := UniConnection;
        UniQuery2.SQL.Text := 'SELECT DEPTNO FROM DEPT WHERE DEPTNO = :DEPTNO';
        UniQuery2.ParamByName('DEPTNO').Value := 50;
        UniQuery2.ParamByName('DEPTNO').Assign(UniQuery1.FieldByName('DEPTNO'));
        if UniQuery2.ParamByName('DEPTNO').Value <= 0 then
          WriteLn('OK');
      finally
        UniQuery2.Free;
      end;
    finally
      UniQuery1.Free;
    end;
  finally
    UniConnection.Free;
    readln;
  end;
end.

Jeweller
Posts: 13
Joined: Thu 18 Jun 2015 16:37

Re: TUniParam.Assign get a "Parameter not found" Exception

Post by Jeweller » Fri 03 Jul 2015 09:52

I do not know about the structure of the dabatase you are using, but if you do not use the same column name when assigning you will reproduced (your sample works for me too with the same name). So something like this:

Code: Select all

    try
      UniQuery1.Connection := UniConnection;
      UniQuery1.SQL.Text := 'SELECT SAL FROM EMP';
      UniQuery1.Open;
      UniQuery2 := TUniQuery.Create(nil);
      try
        UniQuery2.Connection := UniConnection;
        UniQuery2.SQL.Text := 'SELECT * FROM EMP WHERE COMM = :COMM';
        UniQuery2.ParamByName('COMM').Value := 50;
        UniQuery2.ParamByName('COMM').Assign(UniQuery1.FieldByName('SAL')); //same db type of course but different name between parameter and fieldname
        if UniQuery2.ParamByName('COMM').Value <= 0 then
          WriteLn('OK');
      finally
        UniQuery2.Free;
      end;
    finally
      UniQuery1.Free;
    end;
By doing this I understand one thing: With ADO, parameter are not named, so when I assign maybe it didnt care about the name (but the position), but now with undac, you take care of the name of the parameter (a good thing!) (and the assign will change the name)... The thing is that it was working before (I dont know extactly how!), I would not do my code like this but I have to manage the existing code!
So is there something to do for you here (preserve the name of the param?), or should I find a work arround and what it could be (change back the name - how?)? What happens here if the param SAL already exist in the query2 (dangerous!)?

Of course I would like your assign keep the original name! ;)
Thanks for your advises

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: TUniParam.Assign get a "Parameter not found" Exception

Post by AlexP » Fri 03 Jul 2015 11:23

Yes, if names don't match, you will get an error. this behavior is similar to BDE and ClientDataSet, and it is changed only in ADO. To get the behavior similar to ADO, you should assign the following field values to the corresponding parameter instead of the Assign method:

Code: Select all

    DataType := Field.DataType;
    Size := Field.Size;
    Value := Field.Value;

Post Reply