firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Too long updates to a UNICODE_FSS column silently truncated with connection character set UNICODE_FSS

Open mrotteveel opened this issue 3 years ago • 0 comments

When inserting or updating a too long value of a UNICODE_FSS column while connecting with connection character set UNICODE_FSS, the insert succeeds without error, but the value is truncated. When connecting with NONE, a string right truncation error is returned (*).

The silent truncation only happens if the string literal has the exact length in bytes of the column. For too short or too long literals, the truncation error is returned.

[redacted]\Firebird-4.0.2.2816-0-x64>isql -user sysdba -ch none e:\db\fb4\FB4TESTDATABASE.FDB
Database: e:\db\fb4\FB4TESTDATABASE.FDB, User: SYSDBA
SQL> create table with_unicode_fss (id integer, val char(5) character set unicode_fss);
SQL> commit;
SQL> insert into with_unicode_fss (id, val) values (1, '12345');
SQL> insert into with_unicode_fss (id, val) values (2, '123456789012345');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 5, actual 15
SQL> exit;

[redacted]\Firebird-4.0.2.2816-0-x64>isql -user sysdba -ch unicode_fss e:\db\fb4\FB4TESTDATABASE.FDB
Database: e:\db\fb4\FB4TESTDATABASE.FDB, User: SYSDBA
SQL> insert into with_unicode_fss (id, val) values (2, '123456789012345');
SQL> select cast(val as varchar(50)) from with_unicode_fss;

CAST
==================================================
12345
12345

SQL> insert into with_unicode_fss (id, val) values (3, '12345678901234');
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 5, actual 14
SQL>

*: This last behaviour is an undocumented change in Firebird 4.0, because in previous versions, the character length of UNICODE_FSS was not checked, only byte-length mattered.

mrotteveel avatar Oct 07 '22 11:10 mrotteveel