connection.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* connection.h - definitions for the connection type
  2. *
  3. * Copyright (C) 2004-2009 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. #include "Python.h"
  26. #include "pythread.h"
  27. #include "structmember.h"
  28. #include "cache.h"
  29. #include "module.h"
  30. #include "sqlite3.h"
  31. typedef struct
  32. {
  33. PyObject_HEAD
  34. sqlite3* db;
  35. /* 1 if we are currently within a transaction, i. e. if a BEGIN has been
  36. * issued */
  37. int inTransaction;
  38. /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
  39. * bitwise combination thereof makes sense */
  40. int detect_types;
  41. /* the timeout value in seconds for database locks */
  42. double timeout;
  43. /* for internal use in the timeout handler: when did the timeout handler
  44. * first get called with count=0? */
  45. double timeout_started;
  46. /* None for autocommit, otherwise a PyString with the isolation level */
  47. PyObject* isolation_level;
  48. /* NULL for autocommit, otherwise a string with the BEGIN statment; will be
  49. * freed in connection destructor */
  50. char* begin_statement;
  51. /* 1 if a check should be performed for each API call if the connection is
  52. * used from the same thread it was created in */
  53. int check_same_thread;
  54. int initialized;
  55. /* thread identification of the thread the connection was created in */
  56. long thread_ident;
  57. pysqlite_Cache* statement_cache;
  58. /* Lists of weak references to statements and cursors used within this connection */
  59. PyObject* statements;
  60. PyObject* cursors;
  61. /* Counters for how many statements/cursors were created in the connection. May be
  62. * reset to 0 at certain intervals */
  63. int created_statements;
  64. int created_cursors;
  65. PyObject* row_factory;
  66. /* Determines how bytestrings from SQLite are converted to Python objects:
  67. * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
  68. * - OptimizedUnicode: Like before, but for ASCII data, only PyStrings are created.
  69. * - PyString_Type: PyStrings are created 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 references to functions/classes used in
  75. * create_function/create/aggregate, use these as dictionary keys, so we
  76. * can keep the total system refcount constant by clearing that dictionary
  77. * in connection_dealloc */
  78. PyObject* function_pinboard;
  79. /* a dictionary of registered collation name => collation callable mappings */
  80. PyObject* collations;
  81. /* if our connection was created from a APSW connection, we keep a
  82. * reference to the APSW connection around and get rid of it in our
  83. * destructor */
  84. PyObject* apsw_connection;
  85. /* Exception objects */
  86. PyObject* Warning;
  87. PyObject* Error;
  88. PyObject* InterfaceError;
  89. PyObject* DatabaseError;
  90. PyObject* DataError;
  91. PyObject* OperationalError;
  92. PyObject* IntegrityError;
  93. PyObject* InternalError;
  94. PyObject* ProgrammingError;
  95. PyObject* NotSupportedError;
  96. } pysqlite_Connection;
  97. extern PyTypeObject pysqlite_ConnectionType;
  98. PyObject* pysqlite_connection_alloc(PyTypeObject* type, int aware);
  99. void pysqlite_connection_dealloc(pysqlite_Connection* self);
  100. PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
  101. PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args);
  102. PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
  103. PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args);
  104. PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args);
  105. PyObject* pysqlite_connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
  106. int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
  107. int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor);
  108. int pysqlite_check_thread(pysqlite_Connection* self);
  109. int pysqlite_check_connection(pysqlite_Connection* con);
  110. int pysqlite_connection_setup_types(void);
  111. #endif