The field content is truncated when the field is defined as VARCHAR and contains text as long as the field size. And when it contains national characters.
In the attachments: sample code, screenshot of error, screenshot of table contents in DB Manager.
CREATE TABLE public.test1 (
test VARCHAR(20)
)
WITH (oids = false);
insert into test1 (test) values ('12345678901234567890');
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, SQLDB, PQConnection, Forms, Controls, Graphics, Dialogs,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
ButtonUpdate: TButton;
Button2: TButton;
ButtonUpdateUnicode: TButton;
Edit1: TEdit;
PQConnection1: TPQConnection;
SQL1: TSQLQuery;
SQLTransaction1: TSQLTransaction;
procedure ButtonUpdateClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ButtonUpdateUnicodeClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ButtonUpdateClick(Sender: TObject);
begin
PQConnection1.Connected:=True;
SQL1.Active := False;
SQL1.SQL.Clear;
SQL1.SQL.Add('SET CLIENT_ENCODING TO ''UTF8'';');
SQL1.ExecSQL;
SQL1.Active := False;
SQL1.SQL.Clear;
SQL1.SQL.Add('update test1 set test=''12345678901234567890''');
SQL1.ExecSQL;
if SQLTransaction1.Active then SQLTransaction1.CommitRetaining;
SQL1.Active := False;
SQL1.SQL.Clear;
PQConnection1.Connected:=False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
PQConnection1.Connected:=True;
SQL1.Active := False;
SQL1.SQL.Clear;
SQL1.SQL.Add('SET CLIENT_ENCODING TO ''UTF8'';');
SQL1.ExecSQL;
SQL1.Active := False;
SQL1.SQL.Clear;
SQL1.SQL.Add('select test from test1');
SQL1.Active := True;
Edit1.Text:=SQL1['test'];
SQL1.Active := False;
SQL1.SQL.Clear;
PQConnection1.Connected:=False;
end;
procedure TForm1.ButtonUpdateUnicodeClick(Sender: TObject);
begin
PQConnection1.Connected:=True;
SQL1.Active := False;
SQL1.SQL.Clear;
SQL1.SQL.Add('SET CLIENT_ENCODING TO ''UTF8'';');
SQL1.ExecSQL;
SQL1.Active := False;
SQL1.SQL.Clear;
SQL1.SQL.Add('update test1 set test=''ąęć45678901234567890''');
SQL1.ExecSQL;
if SQLTransaction1.Active then SQLTransaction1.CommitRetaining;
SQL1.Active := False;
SQL1.SQL.Clear;
PQConnection1.Connected:=False;
end;
end.