connection.c.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  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. static int
  9. pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
  10. double timeout, int detect_types,
  11. const char *isolation_level,
  12. int check_same_thread, PyObject *factory,
  13. int cache_size, int uri,
  14. enum autocommit_mode autocommit);
  15. static int
  16. pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
  17. {
  18. int return_value = -1;
  19. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  20. #define NUM_KEYWORDS 9
  21. static struct {
  22. PyGC_Head _this_is_not_used;
  23. PyObject_VAR_HEAD
  24. PyObject *ob_item[NUM_KEYWORDS];
  25. } _kwtuple = {
  26. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  27. .ob_item = { &_Py_ID(database), &_Py_ID(timeout), &_Py_ID(detect_types), &_Py_ID(isolation_level), &_Py_ID(check_same_thread), &_Py_ID(factory), &_Py_ID(cached_statements), &_Py_ID(uri), &_Py_ID(autocommit), },
  28. };
  29. #undef NUM_KEYWORDS
  30. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  31. #else // !Py_BUILD_CORE
  32. # define KWTUPLE NULL
  33. #endif // !Py_BUILD_CORE
  34. static const char * const _keywords[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", "uri", "autocommit", NULL};
  35. static _PyArg_Parser _parser = {
  36. .keywords = _keywords,
  37. .fname = "Connection",
  38. .kwtuple = KWTUPLE,
  39. };
  40. #undef KWTUPLE
  41. PyObject *argsbuf[9];
  42. PyObject * const *fastargs;
  43. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  44. Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
  45. PyObject *database;
  46. double timeout = 5.0;
  47. int detect_types = 0;
  48. const char *isolation_level = "";
  49. int check_same_thread = 1;
  50. PyObject *factory = (PyObject*)clinic_state()->ConnectionType;
  51. int cache_size = 128;
  52. int uri = 0;
  53. enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
  54. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
  55. if (!fastargs) {
  56. goto exit;
  57. }
  58. database = fastargs[0];
  59. if (!noptargs) {
  60. goto skip_optional_pos;
  61. }
  62. if (fastargs[1]) {
  63. if (PyFloat_CheckExact(fastargs[1])) {
  64. timeout = PyFloat_AS_DOUBLE(fastargs[1]);
  65. }
  66. else
  67. {
  68. timeout = PyFloat_AsDouble(fastargs[1]);
  69. if (timeout == -1.0 && PyErr_Occurred()) {
  70. goto exit;
  71. }
  72. }
  73. if (!--noptargs) {
  74. goto skip_optional_pos;
  75. }
  76. }
  77. if (fastargs[2]) {
  78. detect_types = _PyLong_AsInt(fastargs[2]);
  79. if (detect_types == -1 && PyErr_Occurred()) {
  80. goto exit;
  81. }
  82. if (!--noptargs) {
  83. goto skip_optional_pos;
  84. }
  85. }
  86. if (fastargs[3]) {
  87. if (!isolation_level_converter(fastargs[3], &isolation_level)) {
  88. goto exit;
  89. }
  90. if (!--noptargs) {
  91. goto skip_optional_pos;
  92. }
  93. }
  94. if (fastargs[4]) {
  95. check_same_thread = PyObject_IsTrue(fastargs[4]);
  96. if (check_same_thread < 0) {
  97. goto exit;
  98. }
  99. if (!--noptargs) {
  100. goto skip_optional_pos;
  101. }
  102. }
  103. if (fastargs[5]) {
  104. factory = fastargs[5];
  105. if (!--noptargs) {
  106. goto skip_optional_pos;
  107. }
  108. }
  109. if (fastargs[6]) {
  110. cache_size = _PyLong_AsInt(fastargs[6]);
  111. if (cache_size == -1 && PyErr_Occurred()) {
  112. goto exit;
  113. }
  114. if (!--noptargs) {
  115. goto skip_optional_pos;
  116. }
  117. }
  118. if (fastargs[7]) {
  119. uri = PyObject_IsTrue(fastargs[7]);
  120. if (uri < 0) {
  121. goto exit;
  122. }
  123. if (!--noptargs) {
  124. goto skip_optional_pos;
  125. }
  126. }
  127. skip_optional_pos:
  128. if (!noptargs) {
  129. goto skip_optional_kwonly;
  130. }
  131. if (!autocommit_converter(fastargs[8], &autocommit)) {
  132. goto exit;
  133. }
  134. skip_optional_kwonly:
  135. return_value = pysqlite_connection_init_impl((pysqlite_Connection *)self, database, timeout, detect_types, isolation_level, check_same_thread, factory, cache_size, uri, autocommit);
  136. exit:
  137. return return_value;
  138. }
  139. PyDoc_STRVAR(pysqlite_connection_cursor__doc__,
  140. "cursor($self, /, factory=<unrepresentable>)\n"
  141. "--\n"
  142. "\n"
  143. "Return a cursor for the connection.");
  144. #define PYSQLITE_CONNECTION_CURSOR_METHODDEF \
  145. {"cursor", _PyCFunction_CAST(pysqlite_connection_cursor), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_cursor__doc__},
  146. static PyObject *
  147. pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory);
  148. static PyObject *
  149. pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  150. {
  151. PyObject *return_value = NULL;
  152. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  153. #define NUM_KEYWORDS 1
  154. static struct {
  155. PyGC_Head _this_is_not_used;
  156. PyObject_VAR_HEAD
  157. PyObject *ob_item[NUM_KEYWORDS];
  158. } _kwtuple = {
  159. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  160. .ob_item = { &_Py_ID(factory), },
  161. };
  162. #undef NUM_KEYWORDS
  163. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  164. #else // !Py_BUILD_CORE
  165. # define KWTUPLE NULL
  166. #endif // !Py_BUILD_CORE
  167. static const char * const _keywords[] = {"factory", NULL};
  168. static _PyArg_Parser _parser = {
  169. .keywords = _keywords,
  170. .fname = "cursor",
  171. .kwtuple = KWTUPLE,
  172. };
  173. #undef KWTUPLE
  174. PyObject *argsbuf[1];
  175. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  176. PyObject *factory = NULL;
  177. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  178. if (!args) {
  179. goto exit;
  180. }
  181. if (!noptargs) {
  182. goto skip_optional_pos;
  183. }
  184. factory = args[0];
  185. skip_optional_pos:
  186. return_value = pysqlite_connection_cursor_impl(self, factory);
  187. exit:
  188. return return_value;
  189. }
  190. PyDoc_STRVAR(blobopen__doc__,
  191. "blobopen($self, table, column, row, /, *, readonly=False, name=\'main\')\n"
  192. "--\n"
  193. "\n"
  194. "Open and return a BLOB object.\n"
  195. "\n"
  196. " table\n"
  197. " Table name.\n"
  198. " column\n"
  199. " Column name.\n"
  200. " row\n"
  201. " Row index.\n"
  202. " readonly\n"
  203. " Open the BLOB without write permissions.\n"
  204. " name\n"
  205. " Database name.");
  206. #define BLOBOPEN_METHODDEF \
  207. {"blobopen", _PyCFunction_CAST(blobopen), METH_FASTCALL|METH_KEYWORDS, blobopen__doc__},
  208. static PyObject *
  209. blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
  210. sqlite3_int64 row, int readonly, const char *name);
  211. static PyObject *
  212. blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  213. {
  214. PyObject *return_value = NULL;
  215. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  216. #define NUM_KEYWORDS 2
  217. static struct {
  218. PyGC_Head _this_is_not_used;
  219. PyObject_VAR_HEAD
  220. PyObject *ob_item[NUM_KEYWORDS];
  221. } _kwtuple = {
  222. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  223. .ob_item = { &_Py_ID(readonly), &_Py_ID(name), },
  224. };
  225. #undef NUM_KEYWORDS
  226. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  227. #else // !Py_BUILD_CORE
  228. # define KWTUPLE NULL
  229. #endif // !Py_BUILD_CORE
  230. static const char * const _keywords[] = {"", "", "", "readonly", "name", NULL};
  231. static _PyArg_Parser _parser = {
  232. .keywords = _keywords,
  233. .fname = "blobopen",
  234. .kwtuple = KWTUPLE,
  235. };
  236. #undef KWTUPLE
  237. PyObject *argsbuf[5];
  238. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  239. const char *table;
  240. const char *col;
  241. sqlite3_int64 row;
  242. int readonly = 0;
  243. const char *name = "main";
  244. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  245. if (!args) {
  246. goto exit;
  247. }
  248. if (!PyUnicode_Check(args[0])) {
  249. _PyArg_BadArgument("blobopen", "argument 1", "str", args[0]);
  250. goto exit;
  251. }
  252. Py_ssize_t table_length;
  253. table = PyUnicode_AsUTF8AndSize(args[0], &table_length);
  254. if (table == NULL) {
  255. goto exit;
  256. }
  257. if (strlen(table) != (size_t)table_length) {
  258. PyErr_SetString(PyExc_ValueError, "embedded null character");
  259. goto exit;
  260. }
  261. if (!PyUnicode_Check(args[1])) {
  262. _PyArg_BadArgument("blobopen", "argument 2", "str", args[1]);
  263. goto exit;
  264. }
  265. Py_ssize_t col_length;
  266. col = PyUnicode_AsUTF8AndSize(args[1], &col_length);
  267. if (col == NULL) {
  268. goto exit;
  269. }
  270. if (strlen(col) != (size_t)col_length) {
  271. PyErr_SetString(PyExc_ValueError, "embedded null character");
  272. goto exit;
  273. }
  274. if (!sqlite3_int64_converter(args[2], &row)) {
  275. goto exit;
  276. }
  277. if (!noptargs) {
  278. goto skip_optional_kwonly;
  279. }
  280. if (args[3]) {
  281. readonly = PyObject_IsTrue(args[3]);
  282. if (readonly < 0) {
  283. goto exit;
  284. }
  285. if (!--noptargs) {
  286. goto skip_optional_kwonly;
  287. }
  288. }
  289. if (!PyUnicode_Check(args[4])) {
  290. _PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]);
  291. goto exit;
  292. }
  293. Py_ssize_t name_length;
  294. name = PyUnicode_AsUTF8AndSize(args[4], &name_length);
  295. if (name == NULL) {
  296. goto exit;
  297. }
  298. if (strlen(name) != (size_t)name_length) {
  299. PyErr_SetString(PyExc_ValueError, "embedded null character");
  300. goto exit;
  301. }
  302. skip_optional_kwonly:
  303. return_value = blobopen_impl(self, table, col, row, readonly, name);
  304. exit:
  305. return return_value;
  306. }
  307. PyDoc_STRVAR(pysqlite_connection_close__doc__,
  308. "close($self, /)\n"
  309. "--\n"
  310. "\n"
  311. "Close the database connection.\n"
  312. "\n"
  313. "Any pending transaction is not committed implicitly.");
  314. #define PYSQLITE_CONNECTION_CLOSE_METHODDEF \
  315. {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, pysqlite_connection_close__doc__},
  316. static PyObject *
  317. pysqlite_connection_close_impl(pysqlite_Connection *self);
  318. static PyObject *
  319. pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
  320. {
  321. return pysqlite_connection_close_impl(self);
  322. }
  323. PyDoc_STRVAR(pysqlite_connection_commit__doc__,
  324. "commit($self, /)\n"
  325. "--\n"
  326. "\n"
  327. "Commit any pending transaction to the database.\n"
  328. "\n"
  329. "If there is no open transaction, this method is a no-op.");
  330. #define PYSQLITE_CONNECTION_COMMIT_METHODDEF \
  331. {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__},
  332. static PyObject *
  333. pysqlite_connection_commit_impl(pysqlite_Connection *self);
  334. static PyObject *
  335. pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
  336. {
  337. return pysqlite_connection_commit_impl(self);
  338. }
  339. PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
  340. "rollback($self, /)\n"
  341. "--\n"
  342. "\n"
  343. "Roll back to the start of any pending transaction.\n"
  344. "\n"
  345. "If there is no open transaction, this method is a no-op.");
  346. #define PYSQLITE_CONNECTION_ROLLBACK_METHODDEF \
  347. {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, pysqlite_connection_rollback__doc__},
  348. static PyObject *
  349. pysqlite_connection_rollback_impl(pysqlite_Connection *self);
  350. static PyObject *
  351. pysqlite_connection_rollback(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
  352. {
  353. return pysqlite_connection_rollback_impl(self);
  354. }
  355. PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
  356. "create_function($self, /, name, narg, func, *, deterministic=False)\n"
  357. "--\n"
  358. "\n"
  359. "Creates a new function.");
  360. #define PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF \
  361. {"create_function", _PyCFunction_CAST(pysqlite_connection_create_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_function__doc__},
  362. static PyObject *
  363. pysqlite_connection_create_function_impl(pysqlite_Connection *self,
  364. PyTypeObject *cls, const char *name,
  365. int narg, PyObject *func,
  366. int deterministic);
  367. static PyObject *
  368. pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  369. {
  370. PyObject *return_value = NULL;
  371. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  372. #define NUM_KEYWORDS 4
  373. static struct {
  374. PyGC_Head _this_is_not_used;
  375. PyObject_VAR_HEAD
  376. PyObject *ob_item[NUM_KEYWORDS];
  377. } _kwtuple = {
  378. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  379. .ob_item = { &_Py_ID(name), &_Py_ID(narg), &_Py_ID(func), &_Py_ID(deterministic), },
  380. };
  381. #undef NUM_KEYWORDS
  382. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  383. #else // !Py_BUILD_CORE
  384. # define KWTUPLE NULL
  385. #endif // !Py_BUILD_CORE
  386. static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL};
  387. static _PyArg_Parser _parser = {
  388. .keywords = _keywords,
  389. .fname = "create_function",
  390. .kwtuple = KWTUPLE,
  391. };
  392. #undef KWTUPLE
  393. PyObject *argsbuf[4];
  394. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  395. const char *name;
  396. int narg;
  397. PyObject *func;
  398. int deterministic = 0;
  399. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  400. if (!args) {
  401. goto exit;
  402. }
  403. if (!PyUnicode_Check(args[0])) {
  404. _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
  405. goto exit;
  406. }
  407. Py_ssize_t name_length;
  408. name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
  409. if (name == NULL) {
  410. goto exit;
  411. }
  412. if (strlen(name) != (size_t)name_length) {
  413. PyErr_SetString(PyExc_ValueError, "embedded null character");
  414. goto exit;
  415. }
  416. narg = _PyLong_AsInt(args[1]);
  417. if (narg == -1 && PyErr_Occurred()) {
  418. goto exit;
  419. }
  420. func = args[2];
  421. if (!noptargs) {
  422. goto skip_optional_kwonly;
  423. }
  424. deterministic = PyObject_IsTrue(args[3]);
  425. if (deterministic < 0) {
  426. goto exit;
  427. }
  428. skip_optional_kwonly:
  429. return_value = pysqlite_connection_create_function_impl(self, cls, name, narg, func, deterministic);
  430. exit:
  431. return return_value;
  432. }
  433. #if defined(HAVE_WINDOW_FUNCTIONS)
  434. PyDoc_STRVAR(create_window_function__doc__,
  435. "create_window_function($self, name, num_params, aggregate_class, /)\n"
  436. "--\n"
  437. "\n"
  438. "Creates or redefines an aggregate window function. Non-standard.\n"
  439. "\n"
  440. " name\n"
  441. " The name of the SQL aggregate window function to be created or\n"
  442. " redefined.\n"
  443. " num_params\n"
  444. " The number of arguments the step and inverse methods takes.\n"
  445. " aggregate_class\n"
  446. " A class with step(), finalize(), value(), and inverse() methods.\n"
  447. " Set to None to clear the window function.");
  448. #define CREATE_WINDOW_FUNCTION_METHODDEF \
  449. {"create_window_function", _PyCFunction_CAST(create_window_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, create_window_function__doc__},
  450. static PyObject *
  451. create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
  452. const char *name, int num_params,
  453. PyObject *aggregate_class);
  454. static PyObject *
  455. create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  456. {
  457. PyObject *return_value = NULL;
  458. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  459. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  460. #else
  461. # define KWTUPLE NULL
  462. #endif
  463. static const char * const _keywords[] = {"", "", "", NULL};
  464. static _PyArg_Parser _parser = {
  465. .keywords = _keywords,
  466. .fname = "create_window_function",
  467. .kwtuple = KWTUPLE,
  468. };
  469. #undef KWTUPLE
  470. PyObject *argsbuf[3];
  471. const char *name;
  472. int num_params;
  473. PyObject *aggregate_class;
  474. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  475. if (!args) {
  476. goto exit;
  477. }
  478. if (!PyUnicode_Check(args[0])) {
  479. _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]);
  480. goto exit;
  481. }
  482. Py_ssize_t name_length;
  483. name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
  484. if (name == NULL) {
  485. goto exit;
  486. }
  487. if (strlen(name) != (size_t)name_length) {
  488. PyErr_SetString(PyExc_ValueError, "embedded null character");
  489. goto exit;
  490. }
  491. num_params = _PyLong_AsInt(args[1]);
  492. if (num_params == -1 && PyErr_Occurred()) {
  493. goto exit;
  494. }
  495. aggregate_class = args[2];
  496. return_value = create_window_function_impl(self, cls, name, num_params, aggregate_class);
  497. exit:
  498. return return_value;
  499. }
  500. #endif /* defined(HAVE_WINDOW_FUNCTIONS) */
  501. PyDoc_STRVAR(pysqlite_connection_create_aggregate__doc__,
  502. "create_aggregate($self, /, name, n_arg, aggregate_class)\n"
  503. "--\n"
  504. "\n"
  505. "Creates a new aggregate.");
  506. #define PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF \
  507. {"create_aggregate", _PyCFunction_CAST(pysqlite_connection_create_aggregate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_aggregate__doc__},
  508. static PyObject *
  509. pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
  510. PyTypeObject *cls,
  511. const char *name, int n_arg,
  512. PyObject *aggregate_class);
  513. static PyObject *
  514. pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  515. {
  516. PyObject *return_value = NULL;
  517. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  518. #define NUM_KEYWORDS 3
  519. static struct {
  520. PyGC_Head _this_is_not_used;
  521. PyObject_VAR_HEAD
  522. PyObject *ob_item[NUM_KEYWORDS];
  523. } _kwtuple = {
  524. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  525. .ob_item = { &_Py_ID(name), &_Py_ID(n_arg), &_Py_ID(aggregate_class), },
  526. };
  527. #undef NUM_KEYWORDS
  528. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  529. #else // !Py_BUILD_CORE
  530. # define KWTUPLE NULL
  531. #endif // !Py_BUILD_CORE
  532. static const char * const _keywords[] = {"name", "n_arg", "aggregate_class", NULL};
  533. static _PyArg_Parser _parser = {
  534. .keywords = _keywords,
  535. .fname = "create_aggregate",
  536. .kwtuple = KWTUPLE,
  537. };
  538. #undef KWTUPLE
  539. PyObject *argsbuf[3];
  540. const char *name;
  541. int n_arg;
  542. PyObject *aggregate_class;
  543. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  544. if (!args) {
  545. goto exit;
  546. }
  547. if (!PyUnicode_Check(args[0])) {
  548. _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
  549. goto exit;
  550. }
  551. Py_ssize_t name_length;
  552. name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
  553. if (name == NULL) {
  554. goto exit;
  555. }
  556. if (strlen(name) != (size_t)name_length) {
  557. PyErr_SetString(PyExc_ValueError, "embedded null character");
  558. goto exit;
  559. }
  560. n_arg = _PyLong_AsInt(args[1]);
  561. if (n_arg == -1 && PyErr_Occurred()) {
  562. goto exit;
  563. }
  564. aggregate_class = args[2];
  565. return_value = pysqlite_connection_create_aggregate_impl(self, cls, name, n_arg, aggregate_class);
  566. exit:
  567. return return_value;
  568. }
  569. PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
  570. "set_authorizer($self, /, authorizer_callback)\n"
  571. "--\n"
  572. "\n"
  573. "Sets authorizer callback.");
  574. #define PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF \
  575. {"set_authorizer", _PyCFunction_CAST(pysqlite_connection_set_authorizer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_authorizer__doc__},
  576. static PyObject *
  577. pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
  578. PyTypeObject *cls,
  579. PyObject *callable);
  580. static PyObject *
  581. pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  582. {
  583. PyObject *return_value = NULL;
  584. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  585. #define NUM_KEYWORDS 1
  586. static struct {
  587. PyGC_Head _this_is_not_used;
  588. PyObject_VAR_HEAD
  589. PyObject *ob_item[NUM_KEYWORDS];
  590. } _kwtuple = {
  591. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  592. .ob_item = { &_Py_ID(authorizer_callback), },
  593. };
  594. #undef NUM_KEYWORDS
  595. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  596. #else // !Py_BUILD_CORE
  597. # define KWTUPLE NULL
  598. #endif // !Py_BUILD_CORE
  599. static const char * const _keywords[] = {"authorizer_callback", NULL};
  600. static _PyArg_Parser _parser = {
  601. .keywords = _keywords,
  602. .fname = "set_authorizer",
  603. .kwtuple = KWTUPLE,
  604. };
  605. #undef KWTUPLE
  606. PyObject *argsbuf[1];
  607. PyObject *callable;
  608. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  609. if (!args) {
  610. goto exit;
  611. }
  612. callable = args[0];
  613. return_value = pysqlite_connection_set_authorizer_impl(self, cls, callable);
  614. exit:
  615. return return_value;
  616. }
  617. PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
  618. "set_progress_handler($self, /, progress_handler, n)\n"
  619. "--\n"
  620. "\n"
  621. "Sets progress handler callback.");
  622. #define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF \
  623. {"set_progress_handler", _PyCFunction_CAST(pysqlite_connection_set_progress_handler), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
  624. static PyObject *
  625. pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
  626. PyTypeObject *cls,
  627. PyObject *callable, int n);
  628. static PyObject *
  629. pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  630. {
  631. PyObject *return_value = NULL;
  632. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  633. #define NUM_KEYWORDS 2
  634. static struct {
  635. PyGC_Head _this_is_not_used;
  636. PyObject_VAR_HEAD
  637. PyObject *ob_item[NUM_KEYWORDS];
  638. } _kwtuple = {
  639. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  640. .ob_item = { &_Py_ID(progress_handler), _Py_LATIN1_CHR('n'), },
  641. };
  642. #undef NUM_KEYWORDS
  643. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  644. #else // !Py_BUILD_CORE
  645. # define KWTUPLE NULL
  646. #endif // !Py_BUILD_CORE
  647. static const char * const _keywords[] = {"progress_handler", "n", NULL};
  648. static _PyArg_Parser _parser = {
  649. .keywords = _keywords,
  650. .fname = "set_progress_handler",
  651. .kwtuple = KWTUPLE,
  652. };
  653. #undef KWTUPLE
  654. PyObject *argsbuf[2];
  655. PyObject *callable;
  656. int n;
  657. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  658. if (!args) {
  659. goto exit;
  660. }
  661. callable = args[0];
  662. n = _PyLong_AsInt(args[1]);
  663. if (n == -1 && PyErr_Occurred()) {
  664. goto exit;
  665. }
  666. return_value = pysqlite_connection_set_progress_handler_impl(self, cls, callable, n);
  667. exit:
  668. return return_value;
  669. }
  670. PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
  671. "set_trace_callback($self, /, trace_callback)\n"
  672. "--\n"
  673. "\n"
  674. "Sets a trace callback called for each SQL statement (passed as unicode).");
  675. #define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF \
  676. {"set_trace_callback", _PyCFunction_CAST(pysqlite_connection_set_trace_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_trace_callback__doc__},
  677. static PyObject *
  678. pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
  679. PyTypeObject *cls,
  680. PyObject *callable);
  681. static PyObject *
  682. pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  683. {
  684. PyObject *return_value = NULL;
  685. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  686. #define NUM_KEYWORDS 1
  687. static struct {
  688. PyGC_Head _this_is_not_used;
  689. PyObject_VAR_HEAD
  690. PyObject *ob_item[NUM_KEYWORDS];
  691. } _kwtuple = {
  692. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  693. .ob_item = { &_Py_ID(trace_callback), },
  694. };
  695. #undef NUM_KEYWORDS
  696. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  697. #else // !Py_BUILD_CORE
  698. # define KWTUPLE NULL
  699. #endif // !Py_BUILD_CORE
  700. static const char * const _keywords[] = {"trace_callback", NULL};
  701. static _PyArg_Parser _parser = {
  702. .keywords = _keywords,
  703. .fname = "set_trace_callback",
  704. .kwtuple = KWTUPLE,
  705. };
  706. #undef KWTUPLE
  707. PyObject *argsbuf[1];
  708. PyObject *callable;
  709. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  710. if (!args) {
  711. goto exit;
  712. }
  713. callable = args[0];
  714. return_value = pysqlite_connection_set_trace_callback_impl(self, cls, callable);
  715. exit:
  716. return return_value;
  717. }
  718. #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
  719. PyDoc_STRVAR(pysqlite_connection_enable_load_extension__doc__,
  720. "enable_load_extension($self, enable, /)\n"
  721. "--\n"
  722. "\n"
  723. "Enable dynamic loading of SQLite extension modules.");
  724. #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF \
  725. {"enable_load_extension", (PyCFunction)pysqlite_connection_enable_load_extension, METH_O, pysqlite_connection_enable_load_extension__doc__},
  726. static PyObject *
  727. pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
  728. int onoff);
  729. static PyObject *
  730. pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *arg)
  731. {
  732. PyObject *return_value = NULL;
  733. int onoff;
  734. onoff = PyObject_IsTrue(arg);
  735. if (onoff < 0) {
  736. goto exit;
  737. }
  738. return_value = pysqlite_connection_enable_load_extension_impl(self, onoff);
  739. exit:
  740. return return_value;
  741. }
  742. #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
  743. #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
  744. PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
  745. "load_extension($self, name, /, *, entrypoint=None)\n"
  746. "--\n"
  747. "\n"
  748. "Load SQLite extension module.");
  749. #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF \
  750. {"load_extension", _PyCFunction_CAST(pysqlite_connection_load_extension), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_load_extension__doc__},
  751. static PyObject *
  752. pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
  753. const char *extension_name,
  754. const char *entrypoint);
  755. static PyObject *
  756. pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  757. {
  758. PyObject *return_value = NULL;
  759. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  760. #define NUM_KEYWORDS 1
  761. static struct {
  762. PyGC_Head _this_is_not_used;
  763. PyObject_VAR_HEAD
  764. PyObject *ob_item[NUM_KEYWORDS];
  765. } _kwtuple = {
  766. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  767. .ob_item = { &_Py_ID(entrypoint), },
  768. };
  769. #undef NUM_KEYWORDS
  770. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  771. #else // !Py_BUILD_CORE
  772. # define KWTUPLE NULL
  773. #endif // !Py_BUILD_CORE
  774. static const char * const _keywords[] = {"", "entrypoint", NULL};
  775. static _PyArg_Parser _parser = {
  776. .keywords = _keywords,
  777. .fname = "load_extension",
  778. .kwtuple = KWTUPLE,
  779. };
  780. #undef KWTUPLE
  781. PyObject *argsbuf[2];
  782. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  783. const char *extension_name;
  784. const char *entrypoint = NULL;
  785. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  786. if (!args) {
  787. goto exit;
  788. }
  789. if (!PyUnicode_Check(args[0])) {
  790. _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
  791. goto exit;
  792. }
  793. Py_ssize_t extension_name_length;
  794. extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
  795. if (extension_name == NULL) {
  796. goto exit;
  797. }
  798. if (strlen(extension_name) != (size_t)extension_name_length) {
  799. PyErr_SetString(PyExc_ValueError, "embedded null character");
  800. goto exit;
  801. }
  802. if (!noptargs) {
  803. goto skip_optional_kwonly;
  804. }
  805. if (args[1] == Py_None) {
  806. entrypoint = NULL;
  807. }
  808. else if (PyUnicode_Check(args[1])) {
  809. Py_ssize_t entrypoint_length;
  810. entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length);
  811. if (entrypoint == NULL) {
  812. goto exit;
  813. }
  814. if (strlen(entrypoint) != (size_t)entrypoint_length) {
  815. PyErr_SetString(PyExc_ValueError, "embedded null character");
  816. goto exit;
  817. }
  818. }
  819. else {
  820. _PyArg_BadArgument("load_extension", "argument 'entrypoint'", "str or None", args[1]);
  821. goto exit;
  822. }
  823. skip_optional_kwonly:
  824. return_value = pysqlite_connection_load_extension_impl(self, extension_name, entrypoint);
  825. exit:
  826. return return_value;
  827. }
  828. #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
  829. PyDoc_STRVAR(pysqlite_connection_execute__doc__,
  830. "execute($self, sql, parameters=<unrepresentable>, /)\n"
  831. "--\n"
  832. "\n"
  833. "Executes an SQL statement.");
  834. #define PYSQLITE_CONNECTION_EXECUTE_METHODDEF \
  835. {"execute", _PyCFunction_CAST(pysqlite_connection_execute), METH_FASTCALL, pysqlite_connection_execute__doc__},
  836. static PyObject *
  837. pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
  838. PyObject *parameters);
  839. static PyObject *
  840. pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
  841. {
  842. PyObject *return_value = NULL;
  843. PyObject *sql;
  844. PyObject *parameters = NULL;
  845. if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
  846. goto exit;
  847. }
  848. if (!PyUnicode_Check(args[0])) {
  849. _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
  850. goto exit;
  851. }
  852. if (PyUnicode_READY(args[0]) == -1) {
  853. goto exit;
  854. }
  855. sql = args[0];
  856. if (nargs < 2) {
  857. goto skip_optional;
  858. }
  859. parameters = args[1];
  860. skip_optional:
  861. return_value = pysqlite_connection_execute_impl(self, sql, parameters);
  862. exit:
  863. return return_value;
  864. }
  865. PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
  866. "executemany($self, sql, parameters, /)\n"
  867. "--\n"
  868. "\n"
  869. "Repeatedly executes an SQL statement.");
  870. #define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF \
  871. {"executemany", _PyCFunction_CAST(pysqlite_connection_executemany), METH_FASTCALL, pysqlite_connection_executemany__doc__},
  872. static PyObject *
  873. pysqlite_connection_executemany_impl(pysqlite_Connection *self,
  874. PyObject *sql, PyObject *parameters);
  875. static PyObject *
  876. pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
  877. {
  878. PyObject *return_value = NULL;
  879. PyObject *sql;
  880. PyObject *parameters;
  881. if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
  882. goto exit;
  883. }
  884. if (!PyUnicode_Check(args[0])) {
  885. _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
  886. goto exit;
  887. }
  888. if (PyUnicode_READY(args[0]) == -1) {
  889. goto exit;
  890. }
  891. sql = args[0];
  892. parameters = args[1];
  893. return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
  894. exit:
  895. return return_value;
  896. }
  897. PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
  898. "executescript($self, sql_script, /)\n"
  899. "--\n"
  900. "\n"
  901. "Executes multiple SQL statements at once.");
  902. #define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF \
  903. {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
  904. PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
  905. "interrupt($self, /)\n"
  906. "--\n"
  907. "\n"
  908. "Abort any pending database operation.");
  909. #define PYSQLITE_CONNECTION_INTERRUPT_METHODDEF \
  910. {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, pysqlite_connection_interrupt__doc__},
  911. static PyObject *
  912. pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
  913. static PyObject *
  914. pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
  915. {
  916. return pysqlite_connection_interrupt_impl(self);
  917. }
  918. PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
  919. "iterdump($self, /)\n"
  920. "--\n"
  921. "\n"
  922. "Returns iterator to the dump of the database in an SQL text format.");
  923. #define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF \
  924. {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS, pysqlite_connection_iterdump__doc__},
  925. static PyObject *
  926. pysqlite_connection_iterdump_impl(pysqlite_Connection *self);
  927. static PyObject *
  928. pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
  929. {
  930. return pysqlite_connection_iterdump_impl(self);
  931. }
  932. PyDoc_STRVAR(pysqlite_connection_backup__doc__,
  933. "backup($self, /, target, *, pages=-1, progress=None, name=\'main\',\n"
  934. " sleep=0.25)\n"
  935. "--\n"
  936. "\n"
  937. "Makes a backup of the database.");
  938. #define PYSQLITE_CONNECTION_BACKUP_METHODDEF \
  939. {"backup", _PyCFunction_CAST(pysqlite_connection_backup), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
  940. static PyObject *
  941. pysqlite_connection_backup_impl(pysqlite_Connection *self,
  942. pysqlite_Connection *target, int pages,
  943. PyObject *progress, const char *name,
  944. double sleep);
  945. static PyObject *
  946. pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  947. {
  948. PyObject *return_value = NULL;
  949. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  950. #define NUM_KEYWORDS 5
  951. static struct {
  952. PyGC_Head _this_is_not_used;
  953. PyObject_VAR_HEAD
  954. PyObject *ob_item[NUM_KEYWORDS];
  955. } _kwtuple = {
  956. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  957. .ob_item = { &_Py_ID(target), &_Py_ID(pages), &_Py_ID(progress), &_Py_ID(name), &_Py_ID(sleep), },
  958. };
  959. #undef NUM_KEYWORDS
  960. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  961. #else // !Py_BUILD_CORE
  962. # define KWTUPLE NULL
  963. #endif // !Py_BUILD_CORE
  964. static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
  965. static _PyArg_Parser _parser = {
  966. .keywords = _keywords,
  967. .fname = "backup",
  968. .kwtuple = KWTUPLE,
  969. };
  970. #undef KWTUPLE
  971. PyObject *argsbuf[5];
  972. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  973. pysqlite_Connection *target;
  974. int pages = -1;
  975. PyObject *progress = Py_None;
  976. const char *name = "main";
  977. double sleep = 0.25;
  978. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  979. if (!args) {
  980. goto exit;
  981. }
  982. if (!PyObject_TypeCheck(args[0], clinic_state()->ConnectionType)) {
  983. _PyArg_BadArgument("backup", "argument 'target'", (clinic_state()->ConnectionType)->tp_name, args[0]);
  984. goto exit;
  985. }
  986. target = (pysqlite_Connection *)args[0];
  987. if (!noptargs) {
  988. goto skip_optional_kwonly;
  989. }
  990. if (args[1]) {
  991. pages = _PyLong_AsInt(args[1]);
  992. if (pages == -1 && PyErr_Occurred()) {
  993. goto exit;
  994. }
  995. if (!--noptargs) {
  996. goto skip_optional_kwonly;
  997. }
  998. }
  999. if (args[2]) {
  1000. progress = args[2];
  1001. if (!--noptargs) {
  1002. goto skip_optional_kwonly;
  1003. }
  1004. }
  1005. if (args[3]) {
  1006. if (!PyUnicode_Check(args[3])) {
  1007. _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
  1008. goto exit;
  1009. }
  1010. Py_ssize_t name_length;
  1011. name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
  1012. if (name == NULL) {
  1013. goto exit;
  1014. }
  1015. if (strlen(name) != (size_t)name_length) {
  1016. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1017. goto exit;
  1018. }
  1019. if (!--noptargs) {
  1020. goto skip_optional_kwonly;
  1021. }
  1022. }
  1023. if (PyFloat_CheckExact(args[4])) {
  1024. sleep = PyFloat_AS_DOUBLE(args[4]);
  1025. }
  1026. else
  1027. {
  1028. sleep = PyFloat_AsDouble(args[4]);
  1029. if (sleep == -1.0 && PyErr_Occurred()) {
  1030. goto exit;
  1031. }
  1032. }
  1033. skip_optional_kwonly:
  1034. return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
  1035. exit:
  1036. return return_value;
  1037. }
  1038. PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
  1039. "create_collation($self, name, callback, /)\n"
  1040. "--\n"
  1041. "\n"
  1042. "Creates a collation function.");
  1043. #define PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF \
  1044. {"create_collation", _PyCFunction_CAST(pysqlite_connection_create_collation), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_collation__doc__},
  1045. static PyObject *
  1046. pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
  1047. PyTypeObject *cls,
  1048. const char *name,
  1049. PyObject *callable);
  1050. static PyObject *
  1051. pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1052. {
  1053. PyObject *return_value = NULL;
  1054. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1055. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  1056. #else
  1057. # define KWTUPLE NULL
  1058. #endif
  1059. static const char * const _keywords[] = {"", "", NULL};
  1060. static _PyArg_Parser _parser = {
  1061. .keywords = _keywords,
  1062. .fname = "create_collation",
  1063. .kwtuple = KWTUPLE,
  1064. };
  1065. #undef KWTUPLE
  1066. PyObject *argsbuf[2];
  1067. const char *name;
  1068. PyObject *callable;
  1069. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  1070. if (!args) {
  1071. goto exit;
  1072. }
  1073. if (!PyUnicode_Check(args[0])) {
  1074. _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
  1075. goto exit;
  1076. }
  1077. Py_ssize_t name_length;
  1078. name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
  1079. if (name == NULL) {
  1080. goto exit;
  1081. }
  1082. if (strlen(name) != (size_t)name_length) {
  1083. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1084. goto exit;
  1085. }
  1086. callable = args[1];
  1087. return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable);
  1088. exit:
  1089. return return_value;
  1090. }
  1091. #if defined(PY_SQLITE_HAVE_SERIALIZE)
  1092. PyDoc_STRVAR(serialize__doc__,
  1093. "serialize($self, /, *, name=\'main\')\n"
  1094. "--\n"
  1095. "\n"
  1096. "Serialize a database into a byte string.\n"
  1097. "\n"
  1098. " name\n"
  1099. " Which database to serialize.\n"
  1100. "\n"
  1101. "For an ordinary on-disk database file, the serialization is just a copy of the\n"
  1102. "disk file. For an in-memory database or a \"temp\" database, the serialization is\n"
  1103. "the same sequence of bytes which would be written to disk if that database\n"
  1104. "were backed up to disk.");
  1105. #define SERIALIZE_METHODDEF \
  1106. {"serialize", _PyCFunction_CAST(serialize), METH_FASTCALL|METH_KEYWORDS, serialize__doc__},
  1107. static PyObject *
  1108. serialize_impl(pysqlite_Connection *self, const char *name);
  1109. static PyObject *
  1110. serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1111. {
  1112. PyObject *return_value = NULL;
  1113. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1114. #define NUM_KEYWORDS 1
  1115. static struct {
  1116. PyGC_Head _this_is_not_used;
  1117. PyObject_VAR_HEAD
  1118. PyObject *ob_item[NUM_KEYWORDS];
  1119. } _kwtuple = {
  1120. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1121. .ob_item = { &_Py_ID(name), },
  1122. };
  1123. #undef NUM_KEYWORDS
  1124. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1125. #else // !Py_BUILD_CORE
  1126. # define KWTUPLE NULL
  1127. #endif // !Py_BUILD_CORE
  1128. static const char * const _keywords[] = {"name", NULL};
  1129. static _PyArg_Parser _parser = {
  1130. .keywords = _keywords,
  1131. .fname = "serialize",
  1132. .kwtuple = KWTUPLE,
  1133. };
  1134. #undef KWTUPLE
  1135. PyObject *argsbuf[1];
  1136. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  1137. const char *name = "main";
  1138. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
  1139. if (!args) {
  1140. goto exit;
  1141. }
  1142. if (!noptargs) {
  1143. goto skip_optional_kwonly;
  1144. }
  1145. if (!PyUnicode_Check(args[0])) {
  1146. _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
  1147. goto exit;
  1148. }
  1149. Py_ssize_t name_length;
  1150. name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
  1151. if (name == NULL) {
  1152. goto exit;
  1153. }
  1154. if (strlen(name) != (size_t)name_length) {
  1155. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1156. goto exit;
  1157. }
  1158. skip_optional_kwonly:
  1159. return_value = serialize_impl(self, name);
  1160. exit:
  1161. return return_value;
  1162. }
  1163. #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
  1164. #if defined(PY_SQLITE_HAVE_SERIALIZE)
  1165. PyDoc_STRVAR(deserialize__doc__,
  1166. "deserialize($self, data, /, *, name=\'main\')\n"
  1167. "--\n"
  1168. "\n"
  1169. "Load a serialized database.\n"
  1170. "\n"
  1171. " data\n"
  1172. " The serialized database content.\n"
  1173. " name\n"
  1174. " Which database to reopen with the deserialization.\n"
  1175. "\n"
  1176. "The deserialize interface causes the database connection to disconnect from the\n"
  1177. "target database, and then reopen it as an in-memory database based on the given\n"
  1178. "serialized data.\n"
  1179. "\n"
  1180. "The deserialize interface will fail with SQLITE_BUSY if the database is\n"
  1181. "currently in a read transaction or is involved in a backup operation.");
  1182. #define DESERIALIZE_METHODDEF \
  1183. {"deserialize", _PyCFunction_CAST(deserialize), METH_FASTCALL|METH_KEYWORDS, deserialize__doc__},
  1184. static PyObject *
  1185. deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
  1186. const char *name);
  1187. static PyObject *
  1188. deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1189. {
  1190. PyObject *return_value = NULL;
  1191. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1192. #define NUM_KEYWORDS 1
  1193. static struct {
  1194. PyGC_Head _this_is_not_used;
  1195. PyObject_VAR_HEAD
  1196. PyObject *ob_item[NUM_KEYWORDS];
  1197. } _kwtuple = {
  1198. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1199. .ob_item = { &_Py_ID(name), },
  1200. };
  1201. #undef NUM_KEYWORDS
  1202. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1203. #else // !Py_BUILD_CORE
  1204. # define KWTUPLE NULL
  1205. #endif // !Py_BUILD_CORE
  1206. static const char * const _keywords[] = {"", "name", NULL};
  1207. static _PyArg_Parser _parser = {
  1208. .keywords = _keywords,
  1209. .fname = "deserialize",
  1210. .kwtuple = KWTUPLE,
  1211. };
  1212. #undef KWTUPLE
  1213. PyObject *argsbuf[2];
  1214. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  1215. Py_buffer data = {NULL, NULL};
  1216. const char *name = "main";
  1217. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1218. if (!args) {
  1219. goto exit;
  1220. }
  1221. if (PyUnicode_Check(args[0])) {
  1222. Py_ssize_t len;
  1223. const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
  1224. if (ptr == NULL) {
  1225. goto exit;
  1226. }
  1227. PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
  1228. }
  1229. else { /* any bytes-like object */
  1230. if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
  1231. goto exit;
  1232. }
  1233. if (!PyBuffer_IsContiguous(&data, 'C')) {
  1234. _PyArg_BadArgument("deserialize", "argument 1", "contiguous buffer", args[0]);
  1235. goto exit;
  1236. }
  1237. }
  1238. if (!noptargs) {
  1239. goto skip_optional_kwonly;
  1240. }
  1241. if (!PyUnicode_Check(args[1])) {
  1242. _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
  1243. goto exit;
  1244. }
  1245. Py_ssize_t name_length;
  1246. name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
  1247. if (name == NULL) {
  1248. goto exit;
  1249. }
  1250. if (strlen(name) != (size_t)name_length) {
  1251. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1252. goto exit;
  1253. }
  1254. skip_optional_kwonly:
  1255. return_value = deserialize_impl(self, &data, name);
  1256. exit:
  1257. /* Cleanup for data */
  1258. if (data.obj) {
  1259. PyBuffer_Release(&data);
  1260. }
  1261. return return_value;
  1262. }
  1263. #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
  1264. PyDoc_STRVAR(pysqlite_connection_enter__doc__,
  1265. "__enter__($self, /)\n"
  1266. "--\n"
  1267. "\n"
  1268. "Called when the connection is used as a context manager.\n"
  1269. "\n"
  1270. "Returns itself as a convenience to the caller.");
  1271. #define PYSQLITE_CONNECTION_ENTER_METHODDEF \
  1272. {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, pysqlite_connection_enter__doc__},
  1273. static PyObject *
  1274. pysqlite_connection_enter_impl(pysqlite_Connection *self);
  1275. static PyObject *
  1276. pysqlite_connection_enter(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
  1277. {
  1278. return pysqlite_connection_enter_impl(self);
  1279. }
  1280. PyDoc_STRVAR(pysqlite_connection_exit__doc__,
  1281. "__exit__($self, type, value, traceback, /)\n"
  1282. "--\n"
  1283. "\n"
  1284. "Called when the connection is used as a context manager.\n"
  1285. "\n"
  1286. "If there was any exception, a rollback takes place; otherwise we commit.");
  1287. #define PYSQLITE_CONNECTION_EXIT_METHODDEF \
  1288. {"__exit__", _PyCFunction_CAST(pysqlite_connection_exit), METH_FASTCALL, pysqlite_connection_exit__doc__},
  1289. static PyObject *
  1290. pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
  1291. PyObject *exc_value, PyObject *exc_tb);
  1292. static PyObject *
  1293. pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
  1294. {
  1295. PyObject *return_value = NULL;
  1296. PyObject *exc_type;
  1297. PyObject *exc_value;
  1298. PyObject *exc_tb;
  1299. if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
  1300. goto exit;
  1301. }
  1302. exc_type = args[0];
  1303. exc_value = args[1];
  1304. exc_tb = args[2];
  1305. return_value = pysqlite_connection_exit_impl(self, exc_type, exc_value, exc_tb);
  1306. exit:
  1307. return return_value;
  1308. }
  1309. PyDoc_STRVAR(setlimit__doc__,
  1310. "setlimit($self, category, limit, /)\n"
  1311. "--\n"
  1312. "\n"
  1313. "Set connection run-time limits.\n"
  1314. "\n"
  1315. " category\n"
  1316. " The limit category to be set.\n"
  1317. " limit\n"
  1318. " The new limit. If the new limit is a negative number, the limit is\n"
  1319. " unchanged.\n"
  1320. "\n"
  1321. "Attempts to increase a limit above its hard upper bound are silently truncated\n"
  1322. "to the hard upper bound. Regardless of whether or not the limit was changed,\n"
  1323. "the prior value of the limit is returned.");
  1324. #define SETLIMIT_METHODDEF \
  1325. {"setlimit", _PyCFunction_CAST(setlimit), METH_FASTCALL, setlimit__doc__},
  1326. static PyObject *
  1327. setlimit_impl(pysqlite_Connection *self, int category, int limit);
  1328. static PyObject *
  1329. setlimit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
  1330. {
  1331. PyObject *return_value = NULL;
  1332. int category;
  1333. int limit;
  1334. if (!_PyArg_CheckPositional("setlimit", nargs, 2, 2)) {
  1335. goto exit;
  1336. }
  1337. category = _PyLong_AsInt(args[0]);
  1338. if (category == -1 && PyErr_Occurred()) {
  1339. goto exit;
  1340. }
  1341. limit = _PyLong_AsInt(args[1]);
  1342. if (limit == -1 && PyErr_Occurred()) {
  1343. goto exit;
  1344. }
  1345. return_value = setlimit_impl(self, category, limit);
  1346. exit:
  1347. return return_value;
  1348. }
  1349. PyDoc_STRVAR(getlimit__doc__,
  1350. "getlimit($self, category, /)\n"
  1351. "--\n"
  1352. "\n"
  1353. "Get connection run-time limits.\n"
  1354. "\n"
  1355. " category\n"
  1356. " The limit category to be queried.");
  1357. #define GETLIMIT_METHODDEF \
  1358. {"getlimit", (PyCFunction)getlimit, METH_O, getlimit__doc__},
  1359. static PyObject *
  1360. getlimit_impl(pysqlite_Connection *self, int category);
  1361. static PyObject *
  1362. getlimit(pysqlite_Connection *self, PyObject *arg)
  1363. {
  1364. PyObject *return_value = NULL;
  1365. int category;
  1366. category = _PyLong_AsInt(arg);
  1367. if (category == -1 && PyErr_Occurred()) {
  1368. goto exit;
  1369. }
  1370. return_value = getlimit_impl(self, category);
  1371. exit:
  1372. return return_value;
  1373. }
  1374. PyDoc_STRVAR(setconfig__doc__,
  1375. "setconfig($self, op, enable=True, /)\n"
  1376. "--\n"
  1377. "\n"
  1378. "Set a boolean connection configuration option.\n"
  1379. "\n"
  1380. " op\n"
  1381. " The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes.");
  1382. #define SETCONFIG_METHODDEF \
  1383. {"setconfig", _PyCFunction_CAST(setconfig), METH_FASTCALL, setconfig__doc__},
  1384. static PyObject *
  1385. setconfig_impl(pysqlite_Connection *self, int op, int enable);
  1386. static PyObject *
  1387. setconfig(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
  1388. {
  1389. PyObject *return_value = NULL;
  1390. int op;
  1391. int enable = 1;
  1392. if (!_PyArg_CheckPositional("setconfig", nargs, 1, 2)) {
  1393. goto exit;
  1394. }
  1395. op = _PyLong_AsInt(args[0]);
  1396. if (op == -1 && PyErr_Occurred()) {
  1397. goto exit;
  1398. }
  1399. if (nargs < 2) {
  1400. goto skip_optional;
  1401. }
  1402. enable = PyObject_IsTrue(args[1]);
  1403. if (enable < 0) {
  1404. goto exit;
  1405. }
  1406. skip_optional:
  1407. return_value = setconfig_impl(self, op, enable);
  1408. exit:
  1409. return return_value;
  1410. }
  1411. PyDoc_STRVAR(getconfig__doc__,
  1412. "getconfig($self, op, /)\n"
  1413. "--\n"
  1414. "\n"
  1415. "Query a boolean connection configuration option.\n"
  1416. "\n"
  1417. " op\n"
  1418. " The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes.");
  1419. #define GETCONFIG_METHODDEF \
  1420. {"getconfig", (PyCFunction)getconfig, METH_O, getconfig__doc__},
  1421. static int
  1422. getconfig_impl(pysqlite_Connection *self, int op);
  1423. static PyObject *
  1424. getconfig(pysqlite_Connection *self, PyObject *arg)
  1425. {
  1426. PyObject *return_value = NULL;
  1427. int op;
  1428. int _return_value;
  1429. op = _PyLong_AsInt(arg);
  1430. if (op == -1 && PyErr_Occurred()) {
  1431. goto exit;
  1432. }
  1433. _return_value = getconfig_impl(self, op);
  1434. if ((_return_value == -1) && PyErr_Occurred()) {
  1435. goto exit;
  1436. }
  1437. return_value = PyBool_FromLong((long)_return_value);
  1438. exit:
  1439. return return_value;
  1440. }
  1441. #ifndef CREATE_WINDOW_FUNCTION_METHODDEF
  1442. #define CREATE_WINDOW_FUNCTION_METHODDEF
  1443. #endif /* !defined(CREATE_WINDOW_FUNCTION_METHODDEF) */
  1444. #ifndef PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
  1445. #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
  1446. #endif /* !defined(PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF) */
  1447. #ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
  1448. #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
  1449. #endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
  1450. #ifndef SERIALIZE_METHODDEF
  1451. #define SERIALIZE_METHODDEF
  1452. #endif /* !defined(SERIALIZE_METHODDEF) */
  1453. #ifndef DESERIALIZE_METHODDEF
  1454. #define DESERIALIZE_METHODDEF
  1455. #endif /* !defined(DESERIALIZE_METHODDEF) */
  1456. /*[clinic end generated code: output=305d580e3eaa622d input=a9049054013a1b77]*/