Skip to content

Commit 1231d26

Browse files
committed
Fixed call to final aggregate function when no step function was called
1 parent 6569f1b commit 1231d26

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Fixed missing GC registration of init values in aggregate functions.
44

5+
* Fixed call to final aggregate function when no step function was called.
6+
57
* Fixed incorrect required minimum OCaml version (now 4.12).
68

79

src/sqlite3_stubs.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,14 @@ static void caml_sqlite3_user_function_##NAME(sqlite3_context *ctx) \
14571457
agg_ctx *agg_ctx = sqlite3_aggregate_context(ctx, sizeof(agg_ctx)); \
14581458
value v_res; \
14591459
caml_leave_blocking_section(); \
1460-
v_res = caml_callback_exn(GET_FUN, agg_ctx->v_acc); \
1461-
set_sqlite3_result(ctx, v_res); \
1462-
REMOVE_ROOT; \
1460+
if (!agg_ctx->initialized) { \
1461+
v_res = caml_callback_exn(GET_FUN, Field(data->v_fun, 1)); \
1462+
set_sqlite3_result(ctx, v_res); \
1463+
} else { \
1464+
v_res = caml_callback_exn(GET_FUN, agg_ctx->v_acc); \
1465+
set_sqlite3_result(ctx, v_res); \
1466+
REMOVE_ROOT; \
1467+
} \
14631468
caml_enter_blocking_section(); \
14641469
}
14651470

0 commit comments

Comments
 (0)