Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions Lib/test/test_sqlite3/test_userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,13 @@ def test_aggr_error_on_create(self):
with self.assertRaises(sqlite.OperationalError):
self.con.create_function("bla", -100, AggrSum)

@with_tracebacks(AttributeError, name="AggrNoStep")
def test_aggr_no_step(self):
cur = self.con.cursor()
with self.assertRaises(AttributeError) as cm:
with self.assertRaises(sqlite.OperationalError) as cm:
cur.execute("select nostep(t) from test")
self.assertEqual(str(cm.exception), "'AggrNoStep' object has no attribute 'step'")
self.assertEqual(str(cm.exception),
"user-defined aggregate's 'step' method not defined")

def test_aggr_no_finalize(self):
cur = self.con.cursor()
Expand Down
10 changes: 6 additions & 4 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,11 @@ step_callback(sqlite3_context *context, int argc, sqlite3_value **params)
PyObject** aggregate_instance;
PyObject* stepmethod = NULL;

aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
assert(ctx != NULL);

aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
if (*aggregate_instance == NULL) {
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
assert(ctx != NULL);
*aggregate_instance = PyObject_CallNoArgs(ctx->callable);
if (!*aggregate_instance) {
set_sqlite_error(context,
Expand All @@ -747,8 +747,10 @@ step_callback(sqlite3_context *context, int argc, sqlite3_value **params)
}
}

stepmethod = PyObject_GetAttrString(*aggregate_instance, "step");
stepmethod = PyObject_GetAttr(*aggregate_instance, ctx->state->str_step);
if (!stepmethod) {
set_sqlite_error(context,
"user-defined aggregate's 'step' method not defined");
goto error;
}

Expand Down
2 changes: 2 additions & 0 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ module_clear(PyObject *module)
Py_CLEAR(state->str___conform__);
Py_CLEAR(state->str_executescript);
Py_CLEAR(state->str_finalize);
Py_CLEAR(state->str_step);
Py_CLEAR(state->str_upper);

return 0;
Expand Down Expand Up @@ -720,6 +721,7 @@ module_exec(PyObject *module)
ADD_INTERNED(state, __conform__);
ADD_INTERNED(state, executescript);
ADD_INTERNED(state, finalize);
ADD_INTERNED(state, step);
ADD_INTERNED(state, upper);

/* Set error constants */
Expand Down
1 change: 1 addition & 0 deletions Modules/_sqlite/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct {
PyObject *str___conform__;
PyObject *str_executescript;
PyObject *str_finalize;
PyObject *str_step;
PyObject *str_upper;
} pysqlite_state;

Expand Down