Skip to content

Commit 479959f

Browse files
[alt 1] pythongh-95132: partially revert 185ecdc
1 parent 2c9e96f commit 479959f

File tree

2 files changed

+42
-147
lines changed

2 files changed

+42
-147
lines changed

Modules/_sqlite/clinic/module.c.h

Lines changed: 1 addition & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/module.c

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,52 @@ module _sqlite3
4242
[clinic start generated code]*/
4343
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
4444

45-
// NOTE: This must equal sqlite3.Connection.__init__ argument spec!
46-
/*[clinic input]
47-
_sqlite3.connect as pysqlite_connect
48-
49-
database: object
50-
timeout: double = 5.0
51-
detect_types: int = 0
52-
isolation_level: object = NULL
53-
check_same_thread: bool(accept={int}) = True
54-
factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType
55-
cached_statements: int = 128
56-
uri: bool = False
57-
58-
Opens a connection to the SQLite database file database.
59-
60-
You can use ":memory:" to open a database connection to a database that resides
61-
in RAM instead of on disk.
62-
[clinic start generated code]*/
45+
PyDoc_STRVAR(pysqlite_connect__doc__,
46+
"connect($module, /, database, timeout=5.0, detect_types=0,\n"
47+
" isolation_level=<unrepresentable>, check_same_thread=True,\n"
48+
" factory=ConnectionType, cached_statements=128, uri=False)\n"
49+
"--\n"
50+
"\n"
51+
"Opens a connection to the SQLite database file database.\n"
52+
"\n"
53+
"You can use \":memory:\" to open a database connection to a database that resides\n"
54+
"in RAM instead of on disk.");
55+
56+
#define PYSQLITE_CONNECT_METHODDEF \
57+
{"connect", _PyCFunction_CAST(module_connect), METH_VARARGS|METH_KEYWORDS, pysqlite_connect__doc__},
6358

6459
static PyObject *
65-
pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
66-
int detect_types, PyObject *isolation_level,
67-
int check_same_thread, PyObject *factory,
68-
int cached_statements, int uri)
69-
/*[clinic end generated code: output=450ac9078b4868bb input=e16914663ddf93ce]*/
60+
module_connect(PyObject *self, PyObject *args, PyObject *kwargs)
7061
{
71-
if (isolation_level == NULL) {
72-
isolation_level = PyUnicode_FromString("");
73-
if (isolation_level == NULL) {
74-
return NULL;
75-
}
62+
/* Python seems to have no way of extracting a single keyword-arg at
63+
* C-level, so this code is redundant with the one in connection_init in
64+
* connection.c and must always be copied from there ... */
65+
static char *kwlist[] = {
66+
"database", "timeout", "detect_types", "isolation_level",
67+
"check_same_thread", "factory", "cached_statements", "uri",
68+
NULL
69+
};
70+
PyObject *database;
71+
int detect_types = 0;
72+
PyObject *isolation_level;
73+
PyObject *factory = NULL;
74+
int check_same_thread = 1;
75+
int cached_statements;
76+
int uri = 0;
77+
double timeout = 5.0;
78+
79+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
80+
&database, &timeout, &detect_types,
81+
&isolation_level, &check_same_thread,
82+
&factory, &cached_statements, &uri))
83+
{
84+
return NULL;
7685
}
77-
else {
78-
Py_INCREF(isolation_level);
86+
if (factory == NULL) {
87+
pysqlite_state *state = pysqlite_get_state(self);
88+
factory = (PyObject *)state->ConnectionType;
7989
}
80-
PyObject *res = PyObject_CallFunction(factory, "OdiOiOii", database,
81-
timeout, detect_types,
82-
isolation_level, check_same_thread,
83-
factory, cached_statements, uri);
84-
Py_DECREF(isolation_level);
85-
return res;
90+
return PyObject_Call(factory, args, kwargs);
8691
}
8792

8893
/*[clinic input]

0 commit comments

Comments
 (0)