PQConnection bytea column detected as ftBlob will store corrupt data under Lazarus if connection.charset is set to UTF8
Original Reporter info from Mantis: Jesus @jramx
-
Reporter name: Jesus Reyes
Original Reporter info from Mantis: Jesus @jramx
- Reporter name: Jesus Reyes
Description:
PQConnection treat bytea columns as ftBlob fields and they are internally stored as ansistrings. On updating a field with Query.CreateBlobStream, using Field.AsBytes or directly with a 'Update' query and params, the stored binary data is corrupted.
The problems seems to be the default handling of such columns, in TPQConnection.Execute its data is retrieved from the corresponding parameter using GetAsString(AParams[i]) which in turn uses parameter.AsUTF8String Parameter.AsAnsiString depending on the the CodePage set by Charset connection property. If the charset is not UTF8 but is not empty such fields may get converted to the specified charset.
I think blob fields should be treated as binary data and should not be exposed to internal string conversions, please see the attached patch for the case on ftBlob and ftGraphic fields, other blob fields should be analyzed and fixed too if needed.
Mantis conversion info:
- Mantis ID: 33714
- Build: r38319
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 39326 (#6b775a20)
- Target version: 3.2.0