Zeos Version: SVN/testing
I have a table that contains FLOAT fields. These fields contains values like '4.85'.
The MySQL server returns '4.85' but the result set puts this string into a single precision data type that cannot hold the information. So I get something like 4.84999990463 what is not 4.85 when converted back into a string (with Field.AsString)
I know that the MySQL FLOAT data type represents a Pascal Single, but when using a Double the precession problem doesn't occur.
Would there be any problem with the change from stFloat to stDouble in ZDbcMySqlUtils.ConvertMySQLHandleToSQLType and ZDbcMySqlUtils.ConvertMySQLTypeToSQLType ?
You only get more precision. The dataset's TFloatField class type remains.
[bug_fixed] MySQL and FLOAT fields (precision)
Moderators: EgonHugeist, mdaems
-
- Senior Boarder
- Posts: 50
- Joined: 31.08.2006, 10:41
- Contact:
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Hi,
I received this private message today:
Mark
I received this private message today:
I did this and it works very well (D7 on Mysql5), so I committed this change to SVN Testing branch (Rev 186).The problem reported with MySql was with the "FLOAT" type and not with the "DECIMAL" type. I created a test table with fields
Data1 DECIMAL(5,2),
Data2 DECIMAL(13,2),
Data3 FLOAT,
Data4 DOUBLE,
The problem ocurrs only with "Data3" (FLOAT type) as reported.
In this case I made 2 modifications to make it work, both are in the ZDbcMySqlUtils.pas source file:
function ConvertMySQLHandleToSQLType(PlainDriver: IZMySQLPlainDriver;
FieldHandle: PZMySQLField; FieldFlags: Integer): TZSQLType;
begin
case PlainDriver.GetFieldType(FieldHandle) of
FIELD_TYPE_TINY:
begin
if (UNSIGNED_FLAG and FieldFlags) = 0 then
Result := stByte
else Result := stShort;
end;
FIELD_TYPE_YEAR, FIELD_TYPE_SHORT:
begin
if (UNSIGNED_FLAG and FieldFlags) = 0 then
Result := stShort
else Result := stInteger;
end;
FIELD_TYPE_INT24, FIELD_TYPE_LONG:
begin
if (UNSIGNED_FLAG and FieldFlags) = 0 then
Result := stInteger
else Result := stLong;
end;
FIELD_TYPE_LONGLONG:
begin
if (UNSIGNED_FLAG and FieldFlags) = 0 then
Result := stLong
else Result := stBigDecimal;
end;
FIELD_TYPE_FLOAT:
Result := stFloat; // Line Number 178
Change Line Number 178 to
Result := stDouble;
The second Change is in:
function ConvertMySQLTypeToSQLType(TypeName, TypeNameFull: string): TZSQLType;
else if TypeName = 'FLOAT' then
begin
if IsUnsigned then
Result := stDouble
else Result := stFloat; // Line number 276
end
replace line number 276 with :
else Result := stDouble;
These changes appear to fix the problem. Again, I don't know it these changes break anything else.
Klchin also reports this happening in MSSQL. I don't have MSSQL so I can't check this.
I think that what should be done is to check the source code of ALL drivers (ZDbcXXXXXUtils.pas) looking for any assignment of (stFloat) to a Type and replace them to a (stDouble) Type and that should fix the problem for whatever driver is being used.
I hope you can check these fixes and apply them to the next version.
Please advise me if you have further doubts or comments.
Regards
Jose Ostos
Mark