FieldByName('fieldname').AsString not Returning entire field

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gymwalker
Posts: 9
Joined: Wed 09 May 2007 23:53
Location: San Diego, CA
Contact:

FieldByName('fieldname').AsString not Returning entire field

Post by gymwalker » Tue 28 Oct 2008 20:21

I have a field in an SQL DB that is defined as CHAR(100)...I am using the SDAC components (still on trial)...and I am performing the following:

TempStr := datamodule.tablename.fieldbyname('fieldname').asstring;

As I said this field is defined as CHAR(100)...however, its only returning data up to the first NULL it finds in the field...not the entire 100 bytes. How do I get this to function to return all 100 bytes of the field and not stop at the first NULL value in the field that it runs into?

I know...this is not good database management...however, this DB came from an old COBOL system where they did a lot of large fields with several sub-fields in them so they didn't have to keep expanding the DB.

In COBOL this is pretty easy to diffine in a buffer...but I'm struggling with accessing all 100 bytes of data in Delphi 6.

Any recomomendation?

Thanks,
Jim

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 29 Oct 2008 11:18

To keep any bytes (including NULL) in a field you should use the BINARY field type instead of CHAR.

gymwalker
Posts: 9
Joined: Wed 09 May 2007 23:53
Location: San Diego, CA
Contact:

FieldByName('fieldname').AsString not Returning entire field

Post by gymwalker » Wed 29 Oct 2008 16:23

I don't have any control over the database definition...I'm stuck with the CHAR(100)...can I define a binary field (target) in Delphi and manipulate the data there? If so, how would I define a 100 byte binary data field?

Thanks in advance!
Jim

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 30 Oct 2008 12:20

You can change the field type with ALTER TABLE ... ALTER COLUMN statement.
In other way you can change your SELECT query using CAST statement for change of field type, like this:

Code: Select all

  SELECT CAST(FieldName AS BINARY(100)) FieldAlias, ...

Post Reply