Just pass it to the factory as is.
with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
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):
with sqlite.connect(database=":memory:") as cx:
self.assertEqual(type(cx), sqlite.Connection)
--- /dev/null
+No longer convert the database argument of :func:`sqlite3.connect` to bytes
+before passing it to the factory.
if (!args) {
goto exit;
}
- if (!PyUnicode_FSConverter(args[0], &database)) {
- goto exit;
- }
+ database = args[0];
if (!noptargs) {
goto skip_optional_pos;
}
exit:
return return_value;
}
-/*[clinic end generated code: output=43aa4f4356f9269d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a7cfa6dc9d54273c input=a9049054013a1b77]*/
/*[clinic input]
_sqlite3.connect as pysqlite_connect
- database: object(converter='PyUnicode_FSConverter')
+ database: object
timeout: double = 5.0
detect_types: int = 0
isolation_level: object = NULL
int detect_types, PyObject *isolation_level,
int check_same_thread, PyObject *factory,
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) {
isolation_level = PyUnicode_FromString("");
timeout, detect_types,
isolation_level, check_same_thread,
factory, cached_statements, uri);
- Py_DECREF(database); // needed bco. the AC FSConverter
Py_DECREF(isolation_level);
return res;
}