[fpc-pascal] code example where AnsiString used in FCL (SqlDB) causes data loss

Michael Van Canneyt michael at freepascal.org
Wed May 11 19:58:35 CEST 2016



On Wed, 11 May 2016, Santiago A. wrote:

> El 11/05/2016 a las 16:38, Michael Van Canneyt escribió:
>>
>>> FPC 3.0 adds unsafe auto-conversions
>>
>> Why do you think it is unsafe ?
>>
> I have an answer for this.
>
> In short:
> Different codepage strings and raw strings should be considered
> different incompatible types. Pascal is a hardtyped language, and I love
> that, and codepages are prone to errors (all these threads prove it).

They are only prone to errors if you don't understand what is happening.

That is so for any feature.

> Something about codpages needs a second thought.
>
> a) There shouldn't be automatic conversion at all.

This is simply not debatable, it is Delphi compatibility that requires this.


To be clear: I think all the problems are hugely exaggerated and blown out
of proportion.

For 99,99% of cases, no changes to your code are required. 
If it worked in 2.6.4, it will work in 3.0.0

Only if somewhere explicitly different codepages are used will you have
problems, or if the characters are a different codepage than what is said 
in the string codepage setting. 
(which is what is happening in TStringField.AsString)

In those cases, you would have problems anyway, no matter what the solution.

I have a huge codebase dealing with databases and lots of string manipulation. 
It uses 2.6.4. It converts data from a database with cp1251 data to UTF8, 
in 2.6.4.

I have recompiled the code, I am running this since 3.0 came out, and have yet 
to encounter the first problem in the applications.

Michael.


More information about the fpc-pascal mailing list