module.c.h 6.2 KB

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