[Lazarus] Losing data when saving Database fileds with "Size" defined and UTF8 chars
DrDiettrich1 at aol.com
Tue Jul 16 17:18:54 CEST 2013
Reinier Olislagers schrieb:
> On 15-7-2013 18:43, Hans-Peter Diettrich wrote:
>> Reinier Olislagers schrieb:
>>> On 14-7-2013 8:00, Daniel Simoes de Ameida wrote:
>>> Workaround: make your field size as large as the maximum number of UTF8
>>> bytes you expect.
>> Another workaround: use the appropriate codepage for storing strings in
>> the database, so that all characters are single bytes. With the new
>> (encoded) AnsiStrings this should be quite easy (automatic conversion).
> Wouldn't you run into trouble if you want to use a character outside the
> codepage? Presumably OP has enabled UTF8 on the db instead of some other
> codepage on purpose.
Then the choice of byte sized characters in the DB field is
inappropriate at all. I wonder how the DB or SQL would sort or compare
(LIKE) such strings?
When the DB doesn't support better string types, like true UTF-8 or
UTF-16 strings, your suggestion is the next best, i.e. abuse fixed size
STRINGs for storing UTF-8 encoded values, and stay away from any string
handling in the DB. This means that e.g. a character limit must be
handled in application code, with either a sufficiently large fixed or a
variable field size in the DB.
More information about the Lazarus