CC: | support [...] sqlite.org, Sean Black <sblack [...] actualmetrics.com> |
Subject: | Finalizer() not called in sqlite_create_aggregate() when there are no rows |
Date: | Mon, 18 Mar 2013 13:29:33 -0400 |
To: | Bugs in DBD-SQLite via RT <bug-DBD-SQLite [...] rt.cpan.org> |
From: | Richard Hipp <drh [...] sqlite.org> |
The documentation says:
finalize()
This method will be called once all rows in the aggregate were processed
and it should return the aggregate function's result. *When there is no
rows in the aggregate, finalize() will be called right after new().*
But that does not appear to be what happens. In fact, when there are no
rows in the aggregate, neither the new() nor the finalize() methods are
invoked.
We believe that the following patch to dbdimp.c fixes the problem:
--- dbdimp.c-orig 2013-03-18 12:51:31.322372116 -0400
+++ dbdimp.c 2013-03-18 12:57:26.374371658 -0400
@@ -1534,7 +1534,7 @@
aggrInfo *aggr, myAggr;
int count = 0;
- aggr = sqlite3_aggregate_context(context, sizeof (aggrInfo));
+ aggr = sqlite3_aggregate_context(context, 0);
ENTER;
SAVETMPS;
The problem above likely originates from ambiguities in the SQLite
documentation. I have attempted to clarify the SQLite APIs with the
checkin at http://www.sqlite.org/src/info/4fe2db1d86 and those changes
have be folded into the SQLite website.
--
D. Richard Hipp
drh@sqlite.org