Search code examples
delphifiredac

After insert data into pgsql With FireDAC, the data info changed


Develop tool: Delphi 10.1 Berlin

With FireDAC in Delphi: INSERT INTO ttb(x) VALUES(aaa=111&bbb=222&ccc=333);

Before insert: aaa=111&bbb=222&ccc=333

However after insert with FireDAC, the string becomes: aaa=111=222=333

That is to say, the characters "&bbb" and "&ccc" were deleted while using FireDAC.

Could you tell me how to fix it, thanks!


Solution

  • Better get habit to always use parameters in queries (Online documentation), as it allows you to avoid such problems. In your case code should look like:

    FDQuery1.SQL.Text:='insert into ttb (x) values(:TestData)';
    FDQuery1.Params.ParamByName('TestData').AsString:='aaa=111&bbb=222&ccc=333';
    FDQuery1.ExecSQL;
    

    In Addition to benefits mentioned in documentation, you would be safe from SQL injection and various other "nasty" things that might happen to your database if not using parameters.