View Issue Details

IDProjectCategoryView StatusLast Update
0033714FPCDatabasepublic2018-06-28 12:09
ReporterJesus ReyesAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.1.1Product Buildr38319 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033714: PQConnection bytea column detected as ftBlob will store corrupt data under Lazarus if connection.charset is set to UTF8
DescriptionPQConnection 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.
TagsNo tags attached.
Fixed in Revision39326
FPCOldBugId0
FPCTarget
Attached Files
  • 33714.diff (461 bytes)
    Index: pqconnection.pp
    ===================================================================
    --- pqconnection.pp	(revision 38319)
    +++ pqconnection.pp	(working copy)
    @@ -1021,6 +1021,8 @@
                   end;
                 ftFmtBCD:
                   s := BCDToStr(AParams[i].AsFMTBCD, FSQLFormatSettings);
    +            ftBlob, ftGraphic:
    +              s := AParams[i].AsBlob;
                 else
                   s := GetAsString(AParams[i]);
               end; {case}
    
    33714.diff (461 bytes)

Activities

Jesus Reyes

2018-05-09 00:16

developer  

33714.diff (461 bytes)
Index: pqconnection.pp
===================================================================
--- pqconnection.pp	(revision 38319)
+++ pqconnection.pp	(working copy)
@@ -1021,6 +1021,8 @@
               end;
             ftFmtBCD:
               s := BCDToStr(AParams[i].AsFMTBCD, FSQLFormatSettings);
+            ftBlob, ftGraphic:
+              s := AParams[i].AsBlob;
             else
               s := GetAsString(AParams[i]);
           end; {case}
33714.diff (461 bytes)

Michael Van Canneyt

2018-06-28 12:09

administrator   ~0109107

Well. The patch will not make things worse, so I applied it.

But TBlobData is still an ansistring, so conversions will happen.
So, Ideally, TBlobData must however be changed to RawByteString or better yet, TBytes.

But that is for a separate report.

Issue History

Date Modified Username Field Change
2018-05-09 00:12 Jesus Reyes New Issue
2018-05-09 00:16 Jesus Reyes File Added: 33714.diff
2018-05-09 08:41 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-05-09 08:41 Michael Van Canneyt Status new => assigned
2018-06-28 12:09 Michael Van Canneyt Fixed in Revision => 39326
2018-06-28 12:09 Michael Van Canneyt Note Added: 0109107
2018-06-28 12:09 Michael Van Canneyt Status assigned => resolved
2018-06-28 12:09 Michael Van Canneyt Fixed in Version => 3.1.1
2018-06-28 12:09 Michael Van Canneyt Resolution open => fixed
2018-06-28 12:09 Michael Van Canneyt Target Version => 3.2.0