Delphi+Linux+Charsets+insert = crazy result

223 views
Skip to first unread message

Lucas Schatz

unread,
Sep 20, 2022, 10:18:20 PM9/20/22
to firebird-support
Hello, not sure if this can be answered here or at Embarcadero, anyway I'm hoping someone can help me:

Simple program build with Delphi 11.2 compiled with Ubuntu WSL2 are inserting a string 'AÇÃO' at an UTF8 Fb 4.0 database, but inserts as 'AÇÃO' instead of 'AÇÃO'.
Same program when build/run with Windows binary correctly insert as 'AÇÃO'
If I try to insert as a encoded string, it inserts as 'A%C3%87%C3%83O', both Windows and Linux builds.
Tested connecting in a Firebird 4.0.2 server running under both Win11 and a jacobalberty/firebird:v4.0 image.

Here is my code:

```
program DelphiFBEncoding;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  uoFIrebirdFD,
  FireDAC.Phys.FB,
  FireDAC.Comp.Client,
  FireDAC.ConsoleUI.Wait,
  NetEncoding;

begin
  try
    writeln('init');
    IsConsole := false;
    ReportMemoryLeaksOnShutdown := true;

    var FDPhysFBDriverLink1 := TFDPhysFBDriverLink.Create(nil);
    var lBanco := TFDConnection.Create(nil);
    var lTr    := TFDTransaction.Create(lBanco);
    lTr.Connection := lBanco;
    var lQuery := TFDQuery.Create(lTr);
    lQuery.Connection := lBanco;
    lQuery.Transaction := lTr;



    lBanco.Params.Values['Database']:='d:\u\banco\logutf8.fdb';
    lBanco.Params.Values['Server']:='192.168.15.140';
    lBanco.Params.Values['User_Name']:='SYSDBA';
    lBanco.Params.Values['Password']:='masterkey';
    lBanco.Params.Values['RoleName']:='';
    lBanco.Params.Values['Protocol']:='TCPIP';
    lBanco.Params.Values['CharacterSet']:='UTF8';
    lBanco.Params.Values['DriverID']:='FB';
    lBanco.Params.Values['Pooled']  := 'false';
    try
      lBanco.connected := true;
      lTr.Options.AutoCommit := false;
      lTr.StartTransaction;

      lQuery.SQL.Clear;
      lQuery.SQL.Add('insert into log$api (ROTA, BODY, BODYENCODED) values(:ROTA, :BODY, :BODYENCODED)');
      lQuery.ParamByName('ROTA').AsString        := {$IFDEF LINUX}'LINUX'{$ELSE}'WINDOWS'{$ENDIF};
      lQuery.ParamByName('BODY').AsString        :=  'AÇÃO';
      lQuery.ParamByName('BODYENCODED').AsString := TNetEncoding.URL.EncodeForm( 'AÇÃO' , [], TEncoding.UTF8);
      lQuery.ExecSQL;
      lTr.Commit;

    finally
      lBanco.Free;
      FDPhysFBDriverLink1.Free;
      writeln('finish');
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
```
Thanks!

Ertan Küçükoglu

unread,
Sep 21, 2022, 1:08:26 AM9/21/22
to firebird...@googlegroups.com
Hello,

You would probably want to use AsWideString while assigning values to fields or parameters since you are using UTF8 connection.

Sent from my iPhone

On 21 Sep 2022, at 05:18, Lucas Schatz <lucas...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/a966b60f-2b83-48e9-ac84-a6cc2b2311ean%40googlegroups.com.

P-Soft - Fabio Codebue

unread,
Sep 21, 2022, 4:28:13 AM9/21/22
to firebird...@googlegroups.com
I'm just installed latest firebird 4 from yum on a centOS 7.9 server
service was installed and work correctly
using isql I can connect to my database as well
I can't find some script to change sysdba password......
I looked into /var/log/messages if during installation process password was writing there, like mySQL server do, but nothing found

so how I can change default sysdba password to create one more secure?

perhaps it's better to install firebird manually?


Fabio Codebue

P-SOFT di Codebue Fabio

Via Nuova n. 9 - 24060 Tavernola B.sca (BG)

P.I. 03624950162

C.F. CDBFBA72A11C618T

Mobile: +39.348.3515786

Fax: +39.030.5100306

Web: http://www.p-soft.biz

 

pec: amminis...@pec.p-soft.biz
cod.intermediario SDI: KRRH6B9
 

Dimitry Sibiryakov

unread,
Sep 21, 2022, 5:33:51 AM9/21/22
to firebird...@googlegroups.com
'P-Soft - Fabio Codebue' via firebird-support wrote 21.09.2022 10:28:
> so how I can change default sysdba password to create one more secure?


https://firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref40/fblangref40-security-user.html

--
WBR, SD.

AlexPeshkoff

unread,
Sep 21, 2022, 5:42:59 AM9/21/22
to firebird-support
Fabio, I do not know in details what does yum install in Fedora contain. But the following method:

$ isql -user sysdba -pas oldBadPasswd localhost:employee
SQL> alter user sysdba password 'NewNicePass';

should always work. (Certainly you may connect remotely using your favorite tool instead isql on localhost.)

среда, 21 сентября 2022 г. в 11:28:13 UTC+3, P-Soft - Fabio Codebue:

Mark Rotteveel

unread,
Sep 21, 2022, 6:23:21 AM9/21/22
to firebird...@googlegroups.com
On 21-09-2022 11:42, AlexPeshkoff wrote:
> Fabio, I do not know in details what does yum install in Fedora contain.
> But the following method:
>
> $ isql -user sysdba -pas oldBadPasswd localhost:employee
> SQL> alter user sysdba password 'NewNicePass';
>
> should always work. (Certainly you may connect remotely using your
> favorite tool instead isql on localhost.)

If you use both Srp and Legacy_Auth, please make sure you alter the
password in **both** user managers, using the `USING PLUGIN` clause:

alter user sysdba password 'NewNicePass' using plugin srp;
alter user sysdba password 'NewNicePass' using plugin legacy_usermanager;

(although if possible, just stop using Legacy_Auth)
--
Mark Rotteveel

Lucas Schatz

unread,
Sep 21, 2022, 8:07:02 AM9/21/22
to firebird-support
Hello, using asWideString worked.
The strange part is, I always used asString in Windows, and even with an ISO8859-1 db asString it didn't worked (in Linux)
Thank you for your help

Dimitry Sibiryakov

unread,
Sep 21, 2022, 8:10:22 AM9/21/22
to firebird...@googlegroups.com
Lucas Schatz wrote 21.09.2022 14:07:
> The strange part is, I always used asString in Windows, and even with an
> ISO8859-1 db asString it didn't worked (in Linux)

In Delphi type String is a WideString. In FPC the String is an AnsiString.

--
WBR, SD.

Lucas Schatz

unread,
Sep 21, 2022, 8:20:06 AM9/21/22
to firebird...@googlegroups.com
Looks like Embarcadero forgot to update its Firedac source to include Linux in the options:

procedure TFDParam.SetAsStrings(AIndex: Integer; const AValue: String);
begin
  if not (FDataType in [ftString, ftFixedChar, ftWideString, ftFixedWideChar]) then
    FDataType := {$IF DEFINED(IOS) OR DEFINED(ANDROID)} ftWideString {$ELSE} ftString {$ENDIF};
  Values[AIndex] := AValue;
end;


--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.

Ertan Küçükoglu

unread,
Sep 21, 2022, 11:17:37 AM9/21/22
to firebird...@googlegroups.com
Hello,

You can define parameter datatype as WideString and then use to assign value AsString like you used to do.

Otherwise, you need AsWideString like you did.

Sent from my iPhone

On 21 Sep 2022, at 15:20, Lucas Schatz <lucas...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages