Page 1 of 1

SQLServer default fieldlength incorrect

Posted: 24.03.2009, 12:08
by JWBokx
Hello all,

I'm using the Zeos 6.6.4 stable and Delphi 2007.
To connect to MSSql I used the ADO setting of the connection component.
My query is generated at runtime.
In a query is an uniqieuidentifier field.
This field is created as a stringfield with a lentgh of 16 characters.
So the field is to short to get all the data, it should be 40 characters long.
All other stringfields do have the correct length.

What can be the cause of this?

Posted: 25.03.2009, 21:49
by mdaems
Sorry, I know almost nothing about ADO. Never even tried to use it. :oops:

But you may try to find out what's going wrong by debugging TZAdoResultSet.Open in ZDbcADOResultset.pas . Maybe the length is got from the wrong place in the ADO structures.

Mark

Posted: 26.03.2009, 09:43
by JWBokx
Well Ado was new for me too.
But MSSQL from 2005 on does not standard use the dblib anymore.
For 2005 it can be done by manually copy the dll, but it's not recomended.

So the only option left is ADO I think.

I'll try to debug it and see what is happening.

Jan

Posted: 26.03.2009, 13:56
by JWBokx
After some debugging and google-ing I have discoverd some strange things.

The ADO struct indeed gives a length of 16.
I did not found another property with the correct length.

I found this site: http://doc.ddart.net/mssql/sql70/impt_bcp_14.htm
The length depends on the storage kind, char or native. I have no idea what this means....

In the Delphi library source for ADO I found this code:

Code: Select all

        case FieldType of
          ftString, ftWideString, ftBytes, ftVarBytes, ftFixedChar, ftFixedWideChar:
            FSize := F.DefinedSize;
          ftBCD:
            begin
              FPrecision := F.Precision;
              FSize := ShortInt(F.NumericScale);
              if FSize < 0 then FSize := 4;
            end;
          ftInteger:
            if HasAutoIncProp and (F.Properties[SIsAutoInc].Value = True) then
              FieldType := ftAutoInc;
          ftGuid:
            FSize := 38;
        end;
So it seems the same problem is corrected hardcoded... :shock:

I have hardcoded this too, and it works ok now. :roll:

Just changed the

Code: Select all

      FieldSize := F.DefinedSize;
into

Code: Select all

    if F.Type_ = adGuid then
      FieldSize := 38
    else
      FieldSize := F.DefinedSize;
in the TZAdoResultSet.Open method

Posted: 27.03.2009, 08:30
by JWBokx
I have also tried to add the TGuidField type to the source.
This does work, but another bug in the delphi library gives an error :shock:

An error Incorrect field length comes up.
Searching internet I found the same error as a bug in Delphi 8 :shock:
( I'm using delphi 2007)

This bug prevents adding a TGuidField to any dataset.
Just try to add a TGuidField in the IDE to a dataset.
The fieldlength is disabled, and set to 0. :zip:
Then the incorrect field length error is raised....

Posted: 02.04.2009, 22:28
by mdaems
Hoi Jan,

I don't really understand what the last message in the thread means, but I just committed your patch to SVN (Rev. 616). Let me know if there's some reason why I should NOT merge this patch to 6.6-patches branch later on.

Groetjes,

Mark

Posted: 03.04.2009, 08:03
by JWBokx
The patch is ok.
CodeGear did the same thing.
But I did try to add the TGuidField to the source.
This would be a better solution, because this field type is for this kind of field.
But then a very very old bug in delphi makes it useless. :roll:

It is just impossible to use a TGuidField.
So the only solution is use a stringfield, and set the length hardcoded.

The bug was reported in Delphi 8, and I'm using Dlephi 2007.
The bug should be very easy to correct, just initialise the fieldlength properly.
But instead of fixing the bug, they hardcode the length in the datset source... :wallb:

That was my last message about.
So the patch is a good patch.

It seems the TGuidField is not used very often.
But I have to read from a database from another party (Exact).
It is full with these guidfields...


Groetjes, :blink2: