|
2 | 2 | preserve |
3 | 3 | [clinic start generated code]*/ |
4 | 4 |
|
| 5 | +PyDoc_STRVAR(pysqlite_connect__doc__, |
| 6 | +"connect($module, /, database, timeout=5.0, detect_types=0,\n" |
| 7 | +" isolation_level=<unrepresentable>, check_same_thread=True,\n" |
| 8 | +" factory=ConnectionType, cached_statements=128, uri=False)\n" |
| 9 | +"--\n" |
| 10 | +"\n" |
| 11 | +"Opens a connection to the SQLite database file database.\n" |
| 12 | +"\n" |
| 13 | +"You can use \":memory:\" to open a database connection to a database that resides\n" |
| 14 | +"in RAM instead of on disk."); |
| 15 | + |
| 16 | +#define PYSQLITE_CONNECT_METHODDEF \ |
| 17 | + {"connect", (PyCFunction)(void(*)(void))pysqlite_connect, METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__}, |
| 18 | + |
| 19 | +static PyObject * |
| 20 | +pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout, |
| 21 | + int detect_types, PyObject *isolation_level, |
| 22 | + int check_same_thread, PyObject *factory, |
| 23 | + int cached_statements, int uri); |
| 24 | + |
| 25 | +static PyObject * |
| 26 | +pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 27 | +{ |
| 28 | + PyObject *return_value = NULL; |
| 29 | + static const char * const _keywords[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", "uri", NULL}; |
| 30 | + static _PyArg_Parser _parser = {NULL, _keywords, "connect", 0}; |
| 31 | + PyObject *argsbuf[8]; |
| 32 | + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 33 | + PyObject *database; |
| 34 | + double timeout = 5.0; |
| 35 | + int detect_types = 0; |
| 36 | + PyObject *isolation_level = NULL; |
| 37 | + int check_same_thread = 1; |
| 38 | + PyObject *factory = (PyObject*)clinic_state()->ConnectionType; |
| 39 | + int cached_statements = 128; |
| 40 | + int uri = 0; |
| 41 | + |
| 42 | + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 8, 0, argsbuf); |
| 43 | + if (!args) { |
| 44 | + goto exit; |
| 45 | + } |
| 46 | + if (!PyUnicode_FSConverter(args[0], &database)) { |
| 47 | + goto exit; |
| 48 | + } |
| 49 | + if (!noptargs) { |
| 50 | + goto skip_optional_pos; |
| 51 | + } |
| 52 | + if (args[1]) { |
| 53 | + if (PyFloat_CheckExact(args[1])) { |
| 54 | + timeout = PyFloat_AS_DOUBLE(args[1]); |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + timeout = PyFloat_AsDouble(args[1]); |
| 59 | + if (timeout == -1.0 && PyErr_Occurred()) { |
| 60 | + goto exit; |
| 61 | + } |
| 62 | + } |
| 63 | + if (!--noptargs) { |
| 64 | + goto skip_optional_pos; |
| 65 | + } |
| 66 | + } |
| 67 | + if (args[2]) { |
| 68 | + detect_types = _PyLong_AsInt(args[2]); |
| 69 | + if (detect_types == -1 && PyErr_Occurred()) { |
| 70 | + goto exit; |
| 71 | + } |
| 72 | + if (!--noptargs) { |
| 73 | + goto skip_optional_pos; |
| 74 | + } |
| 75 | + } |
| 76 | + if (args[3]) { |
| 77 | + isolation_level = args[3]; |
| 78 | + if (!--noptargs) { |
| 79 | + goto skip_optional_pos; |
| 80 | + } |
| 81 | + } |
| 82 | + if (args[4]) { |
| 83 | + check_same_thread = _PyLong_AsInt(args[4]); |
| 84 | + if (check_same_thread == -1 && PyErr_Occurred()) { |
| 85 | + goto exit; |
| 86 | + } |
| 87 | + if (!--noptargs) { |
| 88 | + goto skip_optional_pos; |
| 89 | + } |
| 90 | + } |
| 91 | + if (args[5]) { |
| 92 | + factory = args[5]; |
| 93 | + if (!--noptargs) { |
| 94 | + goto skip_optional_pos; |
| 95 | + } |
| 96 | + } |
| 97 | + if (args[6]) { |
| 98 | + cached_statements = _PyLong_AsInt(args[6]); |
| 99 | + if (cached_statements == -1 && PyErr_Occurred()) { |
| 100 | + goto exit; |
| 101 | + } |
| 102 | + if (!--noptargs) { |
| 103 | + goto skip_optional_pos; |
| 104 | + } |
| 105 | + } |
| 106 | + uri = PyObject_IsTrue(args[7]); |
| 107 | + if (uri < 0) { |
| 108 | + goto exit; |
| 109 | + } |
| 110 | +skip_optional_pos: |
| 111 | + return_value = pysqlite_connect_impl(module, database, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements, uri); |
| 112 | + |
| 113 | +exit: |
| 114 | + return return_value; |
| 115 | +} |
| 116 | + |
5 | 117 | PyDoc_STRVAR(pysqlite_complete_statement__doc__, |
6 | 118 | "complete_statement($module, /, statement)\n" |
7 | 119 | "--\n" |
@@ -219,4 +331,4 @@ pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
219 | 331 | exit: |
220 | 332 | return return_value; |
221 | 333 | } |
222 | | -/*[clinic end generated code: output=e9c2442673289cab input=a9049054013a1b77]*/ |
| 334 | +/*[clinic end generated code: output=ef03fdbf018d3391 input=a9049054013a1b77]*/ |
0 commit comments