[fpc-devel] TMySQLConnection.LoadField field length

Joost van der Sluis joost at cnoc.nl
Wed May 18 17:31:00 CEST 2005


> The TMySQLConnection.LoadField method from sqldb/mysql does not fetch the field lengths properly. It uses mysql_fetch_field_direct, but this only returns data about an entire column in your result set. It does not give valid field lengths for fields of variable length. Is should use mysql_fetch_lengths I think (http://dev.mysql.com/doc/mysql/en/mysql-fetch-lengths.html).

I don't know how the MySQLConnection works internally. But the LoadField
method should load the data from the underlying DB in it's native
format, and convert that to the format expected by the fieldtype, and
place that value in the buffer.

So I think this should be adjusted. But take care for the convertion to
the right data-type.

> The MySQLDataType method also uses length information from mysql_fetch_field_direct and pumps this into TFieldDef.Create.
> I'm not sure about the meaning of the ASize parameter for TFieldDef.Create. What if a string can have arbitrary length?

Look in the Delphi-help for the meaning of TField.Size. It's different
for all sort of fields. For string-fields, it's the maximum amount of
characters in a string. For ftBCD it's the amount of digits after the
decimal place...

The size of the buffer associated with the field, is given in
field.datasize. 

If a string-field is created, aSize is used to set the datasize. But a
ftInteger-field doesn't do anything with it. It's datasize is always set
to 4.

> I need answers to these questions if I want to make a (good) patch I think.

If you need more help, let me know. (Or else, send in the patch!)

-- 
Met vriendelijke groeten,

  Joost van der Sluis
  CNOC Informatiesystemen en Netwerken
  http://www.cnoc.nl





More information about the fpc-devel mailing list