Page 1 of 1

UniDAC/Oracle - Byte parameter passed as 0 ?

Posted: Sun 13 Apr 2014 17:10
by Anachronox
Hello.

I found some strange behaviour with UniDAC.

I have a TCustomUniDataSet query on Oracle with parameters.

I used, let say, parameter P0, which was defined as a Delphi constant 191.
Thus Delphi assigned the Byte type for this constant since it's lower than 256.

Code: Select all

MyConstantByte = 191; // Delphi type Byte
MyConstantInteger : Integer = 191; // Delphi type Integer
So, when I used MyConstantByte as a parameter, the query result was wrong, since its internal value somewhere in UniDac (or Oracle) core was evidently evaluated wrong (I suppose as "0").
But when I used MyConstantInteger, the query was done right.

My original code for my query :

Code: Select all

function MyUniQuery(UniTable : TCustomUniDataSet; QueryText : String; 
  Values : Array of Variant; RunQuery : Boolean = True) : Boolean;
var I : Integer;
begin
  Result := False;
  UniTable.Params.Clear;
  UniTable.SQL.Text := QueryText;
  for I := 0 to UniTable.Params.Count - 1 do
  begin
    UniTable.Params[I].Value := Values[I];
  end;
  if RunQuery then
  begin
    UniTable.Open;
    UniTable.First;
    if not UniTable.Eof then Result := True;
  end;
end;
My patched code for my query :

Code: Select all

function MyUniQuery(UniTable : TCustomUniDataSet; QueryText : String; 
  Values : Array of Variant; RunQuery : Boolean = True) : Boolean;
var I : Integer;
begin
  Result := False;
  UniTable.Params.Clear;
  UniTable.SQL.Text := QueryText;
  for I := 0 to UniTable.Params.Count - 1 do
  begin
    if VarType(Values[I]) = varByte
    then Values[I] := Integer(Values[I]);
    UniTable.Params[I].Value := Values[I];
  end;
  if RunQuery then
  begin
    UniTable.Open;
    UniTable.First;
    if not UniTable.Eof then Result := True;
  end;
end;
So - isn't it a bug ? I suppose there should be no difference between Byte or Integer type in a query parameter and the real parameter value should be the same.

Thank you for your response.

Re: UniDAC/Oracle - Byte parameter passed as 0 ?

Posted: Mon 14 Apr 2014 12:41
by AlexP
Hello,

We cannot reproduce the problem. Please try running the following code and let us know the results.

Re: UniDAC/Oracle - Byte parameter passed as 0 ?

Posted: Thu 17 Apr 2014 22:45
by Anachronox
AlexP wrote: Please try running the following code and let us know the results.
Hello, I am missing the "following code" 8)

Re: UniDAC/Oracle - Byte parameter passed as 0 ?

Posted: Fri 18 Apr 2014 07:29
by AlexP
Hello,

Code: Select all

program Project11;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Uni,
  DB,
  OracleUniProvider;

var
  UniConnection: TUniConnection;
  UniQuery: TUniQuery;
  MyConstantByte: byte;
  MyConstantInteger : Integer;
  Arr: array of Variant;
begin
  UniConnection := TUniConnection.Create(nil);
  try
    UniConnection.ConnectString := 'ProviderName=Oracle;Data Source=orcl1120;UID=scott;PWD=tiger';
    UniConnection.Connect;
    UniQuery := TUniQuery.Create(nil);
    try
      UniQuery.Connection := UniConnection;
      UniQuery.SQL.Text := 'select * from dual where 191 = :p1';
      MyConstantByte := 191;
      MyConstantInteger := 191;
      SetLength(Arr, 1);
      Arr[0] := MyConstantByte;
      UniQuery.ParamByName('p1').DataType := ftInteger;
      UniQuery.ParamByName('p1').Value := Arr[0];
      UniQuery.Open;
      Writeln(IntToStr(UniQuery.RecordCount));
      UniQuery.Close;
      Arr[0] := MyConstantInteger;
      UniQuery.ParamByName('p1').DataType := ftInteger;
      UniQuery.ParamByName('p1').Value := Arr[0];
      UniQuery.Open;
      Writeln(IntToStr(UniQuery.RecordCount));

    finally
      UniQuery.Free;
    end;
  finally
    UniConnection.Free;
    Readln;
  end;
end.