Page 1 of 1

Missing field

Posted: Mon 09 Jan 2012 14:24
by uberbach
When I fill the CommandText property of a TSqlDataset like this:

Code: Select all

SqlDataset.CommandText := 'select ''''';
and I open it, the dataset has no fields (FieldCount = 0). To correct the problem I have to cast the empty string constant to a varchar, like this:

Code: Select all

SqlDataset.CommandText := 'select cast('''' as varchar(20))';
Now I get one field, as expected.

The problem occurs on a SQL Server 2000 database, not on SQL Server 2008. In both cases I'm using Delphi 7.1, dbexpsda.dll version 4.55.0.19

Posted: Tue 10 Jan 2012 08:46
by AndreyZ
Hello,

The problem is caused by the following code in the TCustomSQLDataSet.AddFieldDesc procedure of the SqlExpr unit:

Code: Select all

fldZSTRING, fldBYTES, fldVARBYTES, fldRef:
  begin
    if iUnits1 = 0 then { Ignore MLSLABEL field type on Oracle }
      FType := ftUnknown else
      FSize := iUnits1;
  end;
This code sets the datatype for the empty column to ftUnknown. In the TDataSet.CreateFields procedure field definitions with the ftUnknown data type are ignored and no fields are created. This problem doesn't depend on SQL Server version, it exists for all versions of SQL Server. To avoid the problem, you can use the approach with casting empty string to varchar.