Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_sqlite/clinic/module.c.h
12 views
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
# include "pycore_gc.h" // PyGC_Head
7
# include "pycore_runtime.h" // _Py_ID()
8
#endif
9
10
11
PyDoc_STRVAR(pysqlite_complete_statement__doc__,
12
"complete_statement($module, /, statement)\n"
13
"--\n"
14
"\n"
15
"Checks if a string contains a complete SQL statement.");
16
17
#define PYSQLITE_COMPLETE_STATEMENT_METHODDEF \
18
{"complete_statement", _PyCFunction_CAST(pysqlite_complete_statement), METH_FASTCALL|METH_KEYWORDS, pysqlite_complete_statement__doc__},
19
20
static PyObject *
21
pysqlite_complete_statement_impl(PyObject *module, const char *statement);
22
23
static PyObject *
24
pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
25
{
26
PyObject *return_value = NULL;
27
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
28
29
#define NUM_KEYWORDS 1
30
static struct {
31
PyGC_Head _this_is_not_used;
32
PyObject_VAR_HEAD
33
PyObject *ob_item[NUM_KEYWORDS];
34
} _kwtuple = {
35
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36
.ob_item = { &_Py_ID(statement), },
37
};
38
#undef NUM_KEYWORDS
39
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
40
41
#else // !Py_BUILD_CORE
42
# define KWTUPLE NULL
43
#endif // !Py_BUILD_CORE
44
45
static const char * const _keywords[] = {"statement", NULL};
46
static _PyArg_Parser _parser = {
47
.keywords = _keywords,
48
.fname = "complete_statement",
49
.kwtuple = KWTUPLE,
50
};
51
#undef KWTUPLE
52
PyObject *argsbuf[1];
53
const char *statement;
54
55
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
56
if (!args) {
57
goto exit;
58
}
59
if (!PyUnicode_Check(args[0])) {
60
_PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]);
61
goto exit;
62
}
63
Py_ssize_t statement_length;
64
statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length);
65
if (statement == NULL) {
66
goto exit;
67
}
68
if (strlen(statement) != (size_t)statement_length) {
69
PyErr_SetString(PyExc_ValueError, "embedded null character");
70
goto exit;
71
}
72
return_value = pysqlite_complete_statement_impl(module, statement);
73
74
exit:
75
return return_value;
76
}
77
78
PyDoc_STRVAR(pysqlite_register_adapter__doc__,
79
"register_adapter($module, type, adapter, /)\n"
80
"--\n"
81
"\n"
82
"Register a function to adapt Python objects to SQLite values.");
83
84
#define PYSQLITE_REGISTER_ADAPTER_METHODDEF \
85
{"register_adapter", _PyCFunction_CAST(pysqlite_register_adapter), METH_FASTCALL, pysqlite_register_adapter__doc__},
86
87
static PyObject *
88
pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
89
PyObject *caster);
90
91
static PyObject *
92
pysqlite_register_adapter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
93
{
94
PyObject *return_value = NULL;
95
PyTypeObject *type;
96
PyObject *caster;
97
98
if (!_PyArg_CheckPositional("register_adapter", nargs, 2, 2)) {
99
goto exit;
100
}
101
type = (PyTypeObject *)args[0];
102
caster = args[1];
103
return_value = pysqlite_register_adapter_impl(module, type, caster);
104
105
exit:
106
return return_value;
107
}
108
109
PyDoc_STRVAR(pysqlite_register_converter__doc__,
110
"register_converter($module, typename, converter, /)\n"
111
"--\n"
112
"\n"
113
"Register a function to convert SQLite values to Python objects.");
114
115
#define PYSQLITE_REGISTER_CONVERTER_METHODDEF \
116
{"register_converter", _PyCFunction_CAST(pysqlite_register_converter), METH_FASTCALL, pysqlite_register_converter__doc__},
117
118
static PyObject *
119
pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
120
PyObject *callable);
121
122
static PyObject *
123
pysqlite_register_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
124
{
125
PyObject *return_value = NULL;
126
PyObject *orig_name;
127
PyObject *callable;
128
129
if (!_PyArg_CheckPositional("register_converter", nargs, 2, 2)) {
130
goto exit;
131
}
132
if (!PyUnicode_Check(args[0])) {
133
_PyArg_BadArgument("register_converter", "argument 1", "str", args[0]);
134
goto exit;
135
}
136
orig_name = args[0];
137
callable = args[1];
138
return_value = pysqlite_register_converter_impl(module, orig_name, callable);
139
140
exit:
141
return return_value;
142
}
143
144
PyDoc_STRVAR(pysqlite_enable_callback_trace__doc__,
145
"enable_callback_tracebacks($module, enable, /)\n"
146
"--\n"
147
"\n"
148
"Enable or disable callback functions throwing errors to stderr.");
149
150
#define PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF \
151
{"enable_callback_tracebacks", (PyCFunction)pysqlite_enable_callback_trace, METH_O, pysqlite_enable_callback_trace__doc__},
152
153
static PyObject *
154
pysqlite_enable_callback_trace_impl(PyObject *module, int enable);
155
156
static PyObject *
157
pysqlite_enable_callback_trace(PyObject *module, PyObject *arg)
158
{
159
PyObject *return_value = NULL;
160
int enable;
161
162
enable = _PyLong_AsInt(arg);
163
if (enable == -1 && PyErr_Occurred()) {
164
goto exit;
165
}
166
return_value = pysqlite_enable_callback_trace_impl(module, enable);
167
168
exit:
169
return return_value;
170
}
171
172
PyDoc_STRVAR(pysqlite_adapt__doc__,
173
"adapt($module, obj, proto=PrepareProtocolType, alt=<unrepresentable>, /)\n"
174
"--\n"
175
"\n"
176
"Adapt given object to given protocol.");
177
178
#define PYSQLITE_ADAPT_METHODDEF \
179
{"adapt", _PyCFunction_CAST(pysqlite_adapt), METH_FASTCALL, pysqlite_adapt__doc__},
180
181
static PyObject *
182
pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
183
PyObject *alt);
184
185
static PyObject *
186
pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
187
{
188
PyObject *return_value = NULL;
189
PyObject *obj;
190
PyObject *proto = (PyObject *)clinic_state()->PrepareProtocolType;
191
PyObject *alt = NULL;
192
193
if (!_PyArg_CheckPositional("adapt", nargs, 1, 3)) {
194
goto exit;
195
}
196
obj = args[0];
197
if (nargs < 2) {
198
goto skip_optional;
199
}
200
proto = args[1];
201
if (nargs < 3) {
202
goto skip_optional;
203
}
204
alt = args[2];
205
skip_optional:
206
return_value = pysqlite_adapt_impl(module, obj, proto, alt);
207
208
exit:
209
return return_value;
210
}
211
/*[clinic end generated code: output=e08e6856ae546e7b input=a9049054013a1b77]*/
212
213