Skip to content

Commit f41e419

Browse files
author
D. Richard Hipp
committed
The coalesce(), ifnull(), and iif() functions pass through subtype values
from their arguments, and hence need to have the SQLITE_RESULT_SUBTYPE flag set. This fixes an corner-case for the patch at [ba789a7804ab96d8].
1 parent dd5e3d0 commit f41e419

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/func.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,7 @@ void sqlite3RegisterBuiltinFunctions(void){
26432643
FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ),
26442644
FUNCTION(concat_ws, 0, 0, 0, 0 ),
26452645
FUNCTION(concat_ws, 1, 0, 0, 0 ),
2646-
INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
2646+
INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE),
26472647
VFUNCTION(random, 0, 0, 0, randomFunc ),
26482648
VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
26492649
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
@@ -2725,8 +2725,8 @@ void sqlite3RegisterBuiltinFunctions(void){
27252725
FUNCTION(pi, 0, 0, 0, piFunc ),
27262726
#endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
27272727
FUNCTION(sign, 1, 0, 0, signFunc ),
2728-
INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
2729-
INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
2728+
INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_RESULT_SUBTYPE),
2729+
INLINE_FUNC(iif, 3, INLINEFUNC_iif, SQLITE_RESULT_SUBTYPE),
27302730
};
27312731
#ifndef SQLITE_OMIT_ALTERTABLE
27322732
sqlite3AlterFunctions();

test/indexexpr1.test

+28
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,34 @@ do_execsql_test indexexpr1-2200 {
615615
GROUP BY t2.type, t1.tag
616616
) v ON v.type = 0 AND v.tag = u.tag;
617617
} {7 100 8 101}
618+
do_execsql_test indexexpr1-2210 {
619+
DROP TABLE t1;
620+
CREATE TABLE t1(x INT, y TEXT);
621+
INSERT INTO t1(x,y) VALUES(1,'{b:5}');
622+
SELECT json_insert('{}', '$.a', coalesce(null,json(y)))->>'$.a.b' FROM t1;
623+
} {5}
624+
db null NULL
625+
do_execsql_test indexexpr1-2211 {
626+
CREATE INDEX t1j ON t1(coalesce(null,json(y)));
627+
SELECT json_insert('{}', '$.a', coalesce(null,json(y)))->>'$.a.b' FROM t1;
628+
} {5}
629+
do_execsql_test indexexpr1-2220 {
630+
DROP INDEX t1j;
631+
SELECT json_insert('{}', '$.a', iif(1,json(y),123))->>'$.a.b' FROM t1;
632+
} {5}
633+
do_execsql_test indexexpr1-2221 {
634+
CREATE INDEX t1j ON t1(iif(1,json(y),123));
635+
SELECT json_insert('{}', '$.a', iif(1,json(y),123))->>'$.a.b' FROM t1;
636+
} {5}
637+
do_execsql_test indexexpr1-2230 {
638+
DROP INDEX t1j;
639+
SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1;
640+
} {5}
641+
do_execsql_test indexexpr1-2231 {
642+
CREATE INDEX t1j ON t1(ifnull(NULL,json(y)));
643+
SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1;
644+
} {5}
645+
618646

619647
# 2023-11-08 Forum post https://sqlite.org/forum/forumpost/68d284c86b082c3e
620648
#

0 commit comments

Comments
 (0)