connection.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* connection.h - definitions for the connection type
  2. *
  3. * Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
  4. *
  5. * This file is part of pysqlite.
  6. *
  7. * This software is provided 'as-is', without any express or implied
  8. * warranty. In no event will the authors be held liable for any damages
  9. * arising from the use of this software.
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software. If you use this software
  17. * in a product, an acknowledgment in the product documentation would be
  18. * appreciated but is not required.
  19. * 2. Altered source versions must be plainly marked as such, and must not be
  20. * misrepresented as being the original software.
  21. * 3. This notice may not be removed or altered from any source distribution.
  22. */
  23. #ifndef PYSQLITE_CONNECTION_H
  24. #define PYSQLITE_CONNECTION_H
  25. #define PY_SSIZE_T_CLEAN
  26. #include "Python.h"
  27. #include "pythread.h"
  28. #include "structmember.h"
  29. #include "module.h"
  30. #include "sqlite3.h"
  31. typedef struct _callback_context
  32. {
  33. PyObject *callable;
  34. PyObject *module;
  35. pysqlite_state *state;
  36. } callback_context;
  37. enum autocommit_mode {
  38. AUTOCOMMIT_LEGACY = LEGACY_TRANSACTION_CONTROL,
  39. AUTOCOMMIT_ENABLED = 1,
  40. AUTOCOMMIT_DISABLED = 0,
  41. };
  42. typedef struct
  43. {
  44. PyObject_HEAD
  45. sqlite3 *db;
  46. pysqlite_state *state;
  47. /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
  48. * bitwise combination thereof makes sense */
  49. int detect_types;
  50. /* NULL for autocommit, otherwise a string with the isolation level */
  51. const char *isolation_level;
  52. enum autocommit_mode autocommit;
  53. /* 1 if a check should be performed for each API call if the connection is
  54. * used from the same thread it was created in */
  55. int check_same_thread;
  56. int initialized;
  57. /* thread identification of the thread the connection was created in */
  58. unsigned long thread_ident;
  59. PyObject *statement_cache;
  60. /* Lists of weak references to cursors and blobs used within this connection */
  61. PyObject *cursors;
  62. PyObject *blobs;
  63. /* Counters for how many cursors were created in the connection. May be
  64. * reset to 0 at certain intervals */
  65. int created_cursors;
  66. PyObject* row_factory;
  67. /* Determines how bytestrings from SQLite are converted to Python objects:
  68. * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
  69. * - PyBytes_Type: The bytestrings are returned as-is.
  70. * - Any custom callable: Any object returned from the callable called with the bytestring
  71. * as single parameter.
  72. */
  73. PyObject* text_factory;
  74. // Remember contexts used by the trace, progress, and authoriser callbacks
  75. callback_context *trace_ctx;
  76. callback_context *progress_ctx;
  77. callback_context *authorizer_ctx;
  78. /* Exception objects: borrowed refs. */
  79. PyObject* Warning;
  80. PyObject* Error;
  81. PyObject* InterfaceError;
  82. PyObject* DatabaseError;
  83. PyObject* DataError;
  84. PyObject* OperationalError;
  85. PyObject* IntegrityError;
  86. PyObject* InternalError;
  87. PyObject* ProgrammingError;
  88. PyObject* NotSupportedError;
  89. } pysqlite_Connection;
  90. int pysqlite_check_thread(pysqlite_Connection* self);
  91. int pysqlite_check_connection(pysqlite_Connection* con);
  92. int pysqlite_connection_setup_types(PyObject *module);
  93. #endif