Forum > Database

SQLDB problem with truncated field content

(1/1)

mmelwin:
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.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---CREATE TABLE public.test1 (  test VARCHAR(20)) WITH (oids = false);insert into test1 (test) values ('12345678901234567890'); 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1;{$mode objfpc}{$H+}interfaceuses  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.            

Zvoni:
What encoding did you use when you created the Database?
https://www.sqlite.org/pragma.html#pragma_encoding

--- Quote ---Once an encoding has been set for a database, it cannot be changed.
--- End quote ---

mmelwin:
This is PostgreSQL, not SQLite.
Database encoding is WIN1250.

Navigation

[0] Message Index

Go to full version