jrmarino / AdaBase

Thick database bindings to MySQL, PostgreSQL and SQLite for Ada
ISC License
33 stars 3 forks source link

Mysql decimal(10,2) #4

Closed mcxbain closed 2 years ago

mcxbain commented 2 years ago

I have following issue with an MySQL type decimal(10,2) in the database.

Following types are defined in adabase-results.ads type Real9 is digits 9; type Real18 is digits 18;

But i probably need something like: type Real10 is delta 0.01 digits 10;

I am really happy about any hint or advice how to implement this MySQL decimal type in Adabase.

Great Database !

jrmarino commented 2 years ago

so real9 approximates the 32-bit "float" equivalent and real18 approximates the 64-bit "double" equivalent.
Cannot you create a conversion from Real18 to your proposed Real10 type? I don't see a need to alter AdaBase since Real18 has more resolution than you need.

mcxbain commented 2 years ago

thanks jrmarino, i understand. actually it works when reading the value as string and casting it to Real10.

type Real10 is delta 0.01 digits 10; my_real : Real10:= Real10'Value(row.column(1).as_string);

Its litte bit cheated, but it works.

mcxbain commented 2 years ago

Cannot you create a conversion from Real18 to your proposed Real10 type?

Yes i can do an conversion from Real18 to Real10 but sometimes the result is inaccurate. The last digit for example 100000.01 is changing to 100000.02 sometimes.

With string it actually works without anny error.