Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1052

How to load a TStringStream from database with DBConnection set to UTF-8 charset?

$
0
0

We are changing the database connection settings for our project from WIN1252 to UTF8. (FireDAC).It is a PostgreSQL database created with UTF-8 encoding.

There are some text fields that we load from stream due to their size. This was working before, but now only the first char of the text is loaded.

Here is the code we had before changing the database connection's charset:

procedure TfrmTeste.LoadSqlScript_old;var  _Stream: TStream;begin  _Stream := qry1.CreateBlobStream(                  qry1.FieldByName('Script'),                  bmRead              );  try    FReportQry.Sql.LoadFromStream(_Stream);  finally    _Stream.Free;  end;end;

As I mentioned, the text loaded only contains the first character of the original text. I tried to load the text to a TStringStream in order to understand what's going on:

procedure TfrmTeste.LoadSqlScript_new;var  _StringStream: TStringStream;  _Stream: TStream;begin  _StringStream := TStringStream.Create;  try    _Stream := qry1.CreateBlobStream(                    qry1.FieldByName('Script'),                    bmRead                );    try      _StringStream.LoadFromStream(_Stream);      _StringStream.SaveToFile('c:\tmp\test.sql');      FReportQry.Sql.LoadFromStream(_StringStream);    finally      _Stream.Free;    end;  finally    _StringStream.Free;  end;end;

Interestingly enough, the text file saved to disk has the full text. But the text loaded to TQuery.SQL only has the first character.

Delphi Rio 10.3.3 with FireDAC.


Viewing all articles
Browse latest Browse all 1052

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>