[fpc-devel] Implementing TFmtBCDField - ftFmtBCD and SQLite

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Apr 2 00:00:52 CEST 2011


LacaK schrieb:

>>  So as long as users
>> can't make tables with numeric fields that support more then 15 numbers,
>> we don't have to support bcd-fields. So map decimal to BCD (not float,
>> it will be invalid for values within the supported precision range). If
>> users want to store numbers with an higher precision, that is simply
>> impossible in sqlite.
> Yes it is impossible in native way ... but we can help him and do 
> necessary conversion in the background ... question is what user expect, 
> when defines column like DECIMAL(15,7) ?

He expects to get/put values of that type, i.e. TFmtBCDField if I 
understand the discussion right.

Question: is it assumed that the concrete DB is accessed only by FPC apps?

If not, the user is lost. So let's assume that the value can be stored 
in any format. Now you're free to use either a BLOB or an fixed-length 
string with the ASCII representation of the number (ToString).

The string representation has the advantage that the format can be 
determined from the stored data, making the whole thing somewhat 
type-safe. The size overhead of such an encoding should be compared to 
the overhead of an blob, in order to find out whether the verbose 
storage is acceptable. If it wastes too much space, the digits may be 
encoded in some way, that e.g. maps 2 digits into 100 distinct character 
codes. The sign can be encoded in the first character, either as its 
ASCII value, or like a digit with '0' for positive and everything else 
for negative values. Such an encoding can be used for every DB, that 
doesn't support BCD numbers natively.

DoDi




More information about the fpc-devel mailing list