Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-40956: Convert sqlite3.connect and sqlite3.Connection.__init__ to AC#24421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8192606b72a29cd361aeba8613581ccf5e507164cba1e88c94977d781b2720fc7cd9ee39ed36b754fdc6e59af3bad345e0af0fc7e98f1a9d89926afFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,6 +27,7 @@ | ||
| import unittest | ||
| from test.support.os_helper import TESTFN, unlink | ||
| from test.support import threading_helper | ||
| # Helper for tests using TESTFN | ||
| @@ -224,6 +225,10 @@ def test_open_uri(self): | ||
| with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx: | ||
| cx.execute(self._sql) | ||
| def test_database_keyword(self): | ||
| with sqlite.connect(database=":memory:") as cx: | ||
| self.assertEqual(type(cx), sqlite.Connection) | ||
| class CursorTests(unittest.TestCase): | ||
| def setUp(self): | ||
| @@ -724,6 +729,22 @@ def run(cur, errors): | ||
| if len(errors) > 0: | ||
| self.fail("\n".join(errors)) | ||
| @threading_helper.reap_threads | ||
| def test_dont_check_same_thread(self): | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page.
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| def run(con, err): | ||
| try: | ||
| con.execute("select 1") | ||
| except sqlite.Error: | ||
| err.append("multi-threading not allowed") | ||
| con = sqlite.connect(":memory:", check_same_thread=False) | ||
| err = [] | ||
| t = threading.Thread(target=run, kwargs={"con": con, "err": err}) | ||
| t.start() | ||
| t.join() | ||
| self.assertEqual(len(err), 0, "\n".join(err)) | ||
| class ConstructorTests(unittest.TestCase): | ||
| def test_date(self): | ||
| d = sqlite.Date(2004, 10, 28) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Use Argument Clinic in :mod:`sqlite3`. Patches by Erlend E. Aasland. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -79,40 +79,34 @@ new_statement_cache(pysqlite_Connection *self, int maxsize) | ||||||||||
| return res; | ||||||||||
| } | ||||||||||
| /*[clinic input] | ||||||||||
| _sqlite3.Connection.__init__ as pysqlite_connection_init | ||||||||||
| database as database_obj: object(converter='PyUnicode_FSConverter') | ||||||||||
| timeout: double = 5.0 | ||||||||||
| detect_types: int = 0 | ||||||||||
| isolation_level: object = NULL | ||||||||||
| check_same_thread: bool(accept={int}) = True | ||||||||||
| factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType | ||||||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hummmm, i don't fully get how this is preserving the state as before. Seems that the previous code didn't have a default for factory and used NULL as the c default. Could you briefly explain how this default is preserving previous behaviour? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure :) This is the current code: cpython/Modules/_sqlite/module.c Lines 92 to 95 in 1d10bf0
In practice, the Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see. Is other code using this branch in ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not in the stdlib (except for some tests in the test suite), but I guess it's used in the wild. Personally, I would not have added this feature in the first place.
That's kind of what we're doing no with the default AC argument, right? | ||||||||||
| cached_statements: int = 128 | ||||||||||
| uri: bool = False | ||||||||||
| [clinic start generated code]*/ | ||||||||||
| static int | ||||||||||
| pysqlite_connection_init(pysqlite_Connection *self, PyObject *args, | ||||||||||
| PyObject *kwargs) | ||||||||||
| pysqlite_connection_init_impl(pysqlite_Connection *self, | ||||||||||
| PyObject *database_obj, double timeout, | ||||||||||
| int detect_types, PyObject *isolation_level, | ||||||||||
| int check_same_thread, PyObject *factory, | ||||||||||
| int cached_statements, int uri) | ||||||||||
| /*[clinic end generated code: output=dc19df1c0e2b7b77 input=aa1f21bf12fe907a]*/ | ||||||||||
| { | ||||||||||
| static char *kwlist[] ={ | ||||||||||
| "database", "timeout", "detect_types", "isolation_level", | ||||||||||
| "check_same_thread", "factory", "cached_statements", "uri", | ||||||||||
| NULL | ||||||||||
| }; | ||||||||||
| const char* database; | ||||||||||
| PyObject* database_obj; | ||||||||||
| int detect_types = 0; | ||||||||||
| PyObject* isolation_level = NULL; | ||||||||||
| PyObject* factory = NULL; | ||||||||||
| int check_same_thread = 1; | ||||||||||
| int cached_statements = 128; | ||||||||||
| int uri = 0; | ||||||||||
| double timeout = 5.0; | ||||||||||
| int rc; | ||||||||||
| if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|diOiOip", kwlist, | ||||||||||
| PyUnicode_FSConverter, &database_obj, &timeout, &detect_types, | ||||||||||
| &isolation_level, &check_same_thread, | ||||||||||
| &factory, &cached_statements, &uri)) | ||||||||||
| { | ||||||||||
| return -1; | ||||||||||
| } | ||||||||||
| if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0){ | ||||||||||
| return -1; | ||||||||||
| } | ||||||||||
| database = PyBytes_AsString(database_obj); | ||||||||||
| const char *database = PyBytes_AsString(database_obj); | ||||||||||
| self->initialized = 1; | ||||||||||
| @@ -134,7 +128,7 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args, | ||||||||||
| (uri ? SQLITE_OPEN_URI : 0), NULL); | ||||||||||
| Py_END_ALLOW_THREADS | ||||||||||
| Py_DECREF(database_obj); | ||||||||||
| Py_DECREF(database_obj); // needed bco. the AC FSConverter | ||||||||||
| if (rc != SQLITE_OK){ | ||||||||||
| _pysqlite_seterror(self->db); | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.