Subject | string right truncation error with LIKE predicate and UTF8 DB |
---|---|
Author | Рустам Муса-Ахунов |
Post date | 2017-11-02T14:12:37Z |
Hi, people!
I know, that same bugs was discussed early in bug tracker, although bug not fixed, I think they not the same.
I got an error executing SELECT query with LIKE predicate in case of UTF8 database,
non-UTF8 connection charset and national characters in LIKE argument without mask symbols '%' and '_'
Error is
"arithmetic exception, numeric overflow, or string truncation
-string right truncation"
Reproduce step by step:
1) Create database with default character set = 'UTF8'
2) Connect to DB with ANSI character set, e.g. 'WIN1251'
isql -ch WIN1251
3) Execute SELECT query on any table with VARCHAR fields of any length
with LIKE predicate on VARCHAR field, that meet following criterias:
- argument not contain mask symbols '%' and '_'
-
argument
length greater then 1 symbol
-
argument
contain national symbols
4) Got an error, e.g. in ISQL:
"
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
"
EXAMPLE:
Start Command Prompt, CD to Firebird's 'bin' folder and execute:
chcp 1251
Change console window font to Lucida Console (to allow cp1251 characters in console)
Start ISQL:
isql -ch WIN1251
Execute following queries in ISQL (change paths and credentials appropriately):
create database 'c:\databases\bug.fdb' user 'SYSDBA' password 'masterkey'
default character set UTF8 collation UNICODE_CI_AI;
(to connect to existing DB use command
connect c:\databases\bug.fdb user SYSDBA password masterkey;
)
create table TABLE1 (
FIELD1 varchar(50)
);
insert into TABLE1 (FIELD1) values ('abcdef');
insert into TABLE1 (FIELD1) values ('123456');
insert into TABLE1 (FIELD1) values ('абвгде');
-- WIN1251 characters string
commit;
This queries work fine:
select * from TABLE1 where FIELD1 like 'abc%';
select * from TABLE1 where FIELD1 like 'abc';
select * from TABLE1 where FIELD1 like 'абв%';
This query fails:
select * from TABLE1 where FIELD1 like 'абв';
In last 2 queries in LIKE argument used string with national characters (in this case - WIN1251)
===============================================
Tested on FB 2.5.2 Win32, and FB 2.5.7 Win64 (Superservers)
Tested in ISQL and some other SQL tools with same conditions - bug reproduced.
Connection character sets other then WIN1251 - not tested
Server platforms other then Windows - not tested
Database default collations other then UNICODE_CI_AI - not tested