Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle aggregate queries with no hits
  • Loading branch information
Erlend E. Aasland committed Feb 18, 2021
commit b7dd8c226a54ad93993396e3718fa9368e0fdc21
5 changes: 5 additions & 0 deletions Lib/sqlite3/test/userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ def test_aggr_check_aggr_sum(self):
val = cur.fetchone()[0]
self.assertEqual(val, 60)

def test_aggr_no_match(self):
cur = self.con.execute("select mysum(i) from (select 1 as i) where i == 0")
val = cur.fetchone()[0]
self.assertIsNone(val)

class AuthorizerTests(unittest.TestCase):
@staticmethod
def authorizer_cb(action, arg1, arg2, dbname, source):
Expand Down
6 changes: 5 additions & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,11 @@ void _pysqlite_final_callback(sqlite3_context* context)
threadstate = PyGILState_Ensure();

aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, 0);
if (!*aggregate_instance) {
if (aggregate_instance == NULL) {
/* No rows matched the query; the step handler was never called. */
goto error;
}
else if (!*aggregate_instance) {
/* this branch is executed if there was an exception in the aggregate's
* __init__ */

Expand Down