SQLite

View Ticket
Login
Ticket Hash: 9eda2697f5cc1aba2762a9b0052c96f4271b1af6
Title: Incorrect result for COUNT(), UTF16be encoding and SUBSTR
Status: Fixed Type: Code_Defect
Severity: Minor Priority: Low
Subsystem: Unknown Resolution: Fixed
Last Modified: 2020-01-08 12:17:58
Version Found In: 3.30.0
User Comments:
mrigger added on 2020-01-08 10:37:49:

Consider the following test case:

PRAGMA encoding = 'UTF16be';
CREATE TABLE t0(c0, c1);
INSERT INTO t0(c0) VALUES (x'00');
CREATE INDEX i0 ON t0(c0 COLLATE BINARY);
INSERT INTO t0(c0) VALUES (1);
SELECT COUNT(*) FROM t0 WHERE SUBSTR(t0.c0, ','); -- expected: 1, actual: 2

Unexpectedly, the COUNT returns 2, even though only one row is contained in the result set:

SELECT * FROM t0 WHERE SUBSTR(t0.c0, ','); -- 1|