summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r--Modules/_sqlite/module.c82
1 files changed, 40 insertions, 42 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 9587cbd..6adadf6 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -60,50 +60,49 @@ int pysqlite_BaseTypeAdapted = 0;
pysqlite_state pysqlite_global_state;
-static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
- kwargs)
-{
- /* Python seems to have no way of extracting a single keyword-arg at
- * C-level, so this code is redundant with the one in connection_init in
- * connection.c and must always be copied from there ... */
+// NOTE: This must equal sqlite3.Connection.__init__ argument spec!
+/*[clinic input]
+_sqlite3.connect as pysqlite_connect
- static char *kwlist[] = {
- "database", "timeout", "detect_types", "isolation_level",
- "check_same_thread", "factory", "cached_statements", "uri",
- NULL
- };
- PyObject* database;
- int detect_types = 0;
- PyObject* isolation_level;
- PyObject* factory = NULL;
- int check_same_thread = 1;
- int cached_statements;
- int uri = 0;
- double timeout = 5.0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
- &database, &timeout, &detect_types,
- &isolation_level, &check_same_thread,
- &factory, &cached_statements, &uri))
- {
- return NULL;
- }
+ database: 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
+ cached_statements: int = 128
+ uri: bool = False
- if (factory == NULL) {
- pysqlite_state *state = pysqlite_get_state(self);
- factory = (PyObject *)state->ConnectionType;
- }
+Opens a connection to the SQLite database file database.
- return PyObject_Call(factory, args, kwargs);
-}
+You can use ":memory:" to open a database connection to a database that resides
+in RAM instead of on disk.
+[clinic start generated code]*/
-PyDoc_STRVAR(module_connect_doc,
-"connect(database[, timeout, detect_types, isolation_level,\n\
- check_same_thread, factory, cached_statements, uri])\n\
-\n\
-Opens a connection to the SQLite database file *database*. You can use\n\
-\":memory:\" to open a database connection to a database that resides in\n\
-RAM instead of on disk.");
+static PyObject *
+pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
+ 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]*/
+{
+ if (isolation_level == NULL) {
+ isolation_level = PyUnicode_FromString("");
+ if (isolation_level == NULL) {
+ return NULL;
+ }
+ }
+ else {
+ Py_INCREF(isolation_level);
+ }
+ PyObject *res = PyObject_CallFunction(factory, "OdiOiOii", database,
+ 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;
+}
/*[clinic input]
_sqlite3.complete_statement as pysqlite_complete_statement
@@ -287,10 +286,9 @@ load_functools_lru_cache(PyObject *module)
}
static PyMethodDef module_methods[] = {
- {"connect", (PyCFunction)(void(*)(void))module_connect,
- METH_VARARGS | METH_KEYWORDS, module_connect_doc},
PYSQLITE_ADAPT_METHODDEF
PYSQLITE_COMPLETE_STATEMENT_METHODDEF
+ PYSQLITE_CONNECT_METHODDEF
PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF
PYSQLITE_REGISTER_ADAPTER_METHODDEF