Skip to content

Commit 10665ac

Browse files
author
Erlend Egeberg Aasland
authored
bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__init__ (pythonGH-25818)
(cherry picked from commit c96cc08) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
1 parent db3ce79 commit 10665ac

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Creating a :class:`sqlite3.Connection` object now also produces
2+
a ``sqlite3.connect`` :ref:`auditing event <auditing>`.
3+
Previously this event was only produced by :func:`sqlite3.connect`
4+
calls. Patch by Erlend E. Aasland.

Modules/_sqlite/connection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
9898
return -1;
9999
}
100100

101+
if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0) {
102+
return -1;
103+
}
104+
101105
database = PyBytes_AsString(database_obj);
102106

103107
self->initialized = 1;

Modules/_sqlite/module.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
7171
int uri = 0;
7272
double timeout = 5.0;
7373

74-
PyObject* result;
75-
7674
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
7775
&database, &timeout, &detect_types,
7876
&isolation_level, &check_same_thread,
@@ -85,13 +83,7 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
8583
factory = (PyObject*)&pysqlite_ConnectionType;
8684
}
8785

88-
if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
89-
return NULL;
90-
}
91-
92-
result = PyObject_Call(factory, args, kwargs);
93-
94-
return result;
86+
return PyObject_Call(factory, args, kwargs);
9587
}
9688

9789
PyDoc_STRVAR(module_connect_doc,

0 commit comments

Comments
 (0)