mirror of https://github.com/python/cpython
[3.11] gh-93044: No longer convert the database argument of sqlite3.connect() to bytes (GH-93046) (GH-93048)
Just pass it to the factory as is.
(cherry picked from commit 14c0d33016
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
f2aeb3f6f7
commit
d9a48d2b41
|
@ -685,6 +685,19 @@ class OpenTests(unittest.TestCase):
|
||||||
with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
|
with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
|
||||||
cx.execute(self._sql)
|
cx.execute(self._sql)
|
||||||
|
|
||||||
|
def test_factory_database_arg(self):
|
||||||
|
def factory(database, *args, **kwargs):
|
||||||
|
nonlocal database_arg
|
||||||
|
database_arg = database
|
||||||
|
return sqlite.Connection(":memory:", *args, **kwargs)
|
||||||
|
|
||||||
|
for database in (TESTFN, os.fsencode(TESTFN),
|
||||||
|
FakePath(TESTFN), FakePath(os.fsencode(TESTFN))):
|
||||||
|
database_arg = None
|
||||||
|
with sqlite.connect(database, factory=factory):
|
||||||
|
pass
|
||||||
|
self.assertEqual(database_arg, database)
|
||||||
|
|
||||||
def test_database_keyword(self):
|
def test_database_keyword(self):
|
||||||
with sqlite.connect(database=":memory:") as cx:
|
with sqlite.connect(database=":memory:") as cx:
|
||||||
self.assertEqual(type(cx), sqlite.Connection)
|
self.assertEqual(type(cx), sqlite.Connection)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
No longer convert the database argument of :func:`sqlite3.connect` to bytes
|
||||||
|
before passing it to the factory.
|
|
@ -43,9 +43,7 @@ pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
|
||||||
if (!args) {
|
if (!args) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!PyUnicode_FSConverter(args[0], &database)) {
|
database = args[0];
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if (!noptargs) {
|
if (!noptargs) {
|
||||||
goto skip_optional_pos;
|
goto skip_optional_pos;
|
||||||
}
|
}
|
||||||
|
@ -334,4 +332,4 @@ skip_optional:
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=d846459943008a9c input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=10c4f942dc9f0c79 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -46,7 +46,7 @@ module _sqlite3
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
_sqlite3.connect as pysqlite_connect
|
_sqlite3.connect as pysqlite_connect
|
||||||
|
|
||||||
database: object(converter='PyUnicode_FSConverter')
|
database: object
|
||||||
timeout: double = 5.0
|
timeout: double = 5.0
|
||||||
detect_types: int = 0
|
detect_types: int = 0
|
||||||
isolation_level: object = NULL
|
isolation_level: object = NULL
|
||||||
|
@ -66,7 +66,7 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
|
||||||
int detect_types, PyObject *isolation_level,
|
int detect_types, PyObject *isolation_level,
|
||||||
int check_same_thread, PyObject *factory,
|
int check_same_thread, PyObject *factory,
|
||||||
int cached_statements, int uri)
|
int cached_statements, int uri)
|
||||||
/*[clinic end generated code: output=450ac9078b4868bb input=ea6355ba55a78e12]*/
|
/*[clinic end generated code: output=450ac9078b4868bb input=e16914663ddf93ce]*/
|
||||||
{
|
{
|
||||||
if (isolation_level == NULL) {
|
if (isolation_level == NULL) {
|
||||||
isolation_level = PyUnicode_FromString("");
|
isolation_level = PyUnicode_FromString("");
|
||||||
|
@ -81,7 +81,6 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
|
||||||
timeout, detect_types,
|
timeout, detect_types,
|
||||||
isolation_level, check_same_thread,
|
isolation_level, check_same_thread,
|
||||||
factory, cached_statements, uri);
|
factory, cached_statements, uri);
|
||||||
Py_DECREF(database); // needed bco. the AC FSConverter
|
|
||||||
Py_DECREF(isolation_level);
|
Py_DECREF(isolation_level);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue