Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | /* connection.h - definitions for the connection type |
| 2 | * |
Florent Xicluna | c934f32 | 2010-09-03 23:47:32 +0000 | [diff] [blame] | 3 | * Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de> |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 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 | |
| 24 | #ifndef PYSQLITE_CONNECTION_H |
| 25 | #define PYSQLITE_CONNECTION_H |
| 26 | #include "Python.h" |
| 27 | #include "pythread.h" |
| 28 | #include "structmember.h" |
| 29 | |
| 30 | #include "cache.h" |
| 31 | #include "module.h" |
| 32 | |
| 33 | #include "sqlite3.h" |
| 34 | |
| 35 | typedef struct |
| 36 | { |
| 37 | PyObject_HEAD |
| 38 | sqlite3* db; |
| 39 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 40 | /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a |
| 41 | * bitwise combination thereof makes sense */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 42 | int detect_types; |
| 43 | |
| 44 | /* the timeout value in seconds for database locks */ |
| 45 | double timeout; |
| 46 | |
| 47 | /* for internal use in the timeout handler: when did the timeout handler |
| 48 | * first get called with count=0? */ |
| 49 | double timeout_started; |
| 50 | |
Serhiy Storchaka | 483405b | 2015-02-17 10:14:30 +0200 | [diff] [blame] | 51 | /* None for autocommit, otherwise a PyUnicode with the isolation level */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 52 | PyObject* isolation_level; |
| 53 | |
Serhiy Storchaka | 2891492 | 2016-09-01 22:18:03 +0300 | [diff] [blame] | 54 | /* NULL for autocommit, otherwise a string with the BEGIN statement */ |
| 55 | const char* begin_statement; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 56 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 57 | /* 1 if a check should be performed for each API call if the connection is |
| 58 | * used from the same thread it was created in */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 59 | int check_same_thread; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 60 | |
Gerhard Häring | f9cee22 | 2010-03-05 15:20:03 +0000 | [diff] [blame] | 61 | int initialized; |
| 62 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 63 | /* thread identification of the thread the connection was created in */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 64 | long thread_ident; |
| 65 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 66 | pysqlite_Cache* statement_cache; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 67 | |
Gerhard Häring | f9cee22 | 2010-03-05 15:20:03 +0000 | [diff] [blame] | 68 | /* Lists of weak references to statements and cursors used within this connection */ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 69 | PyObject* statements; |
Gerhard Häring | f9cee22 | 2010-03-05 15:20:03 +0000 | [diff] [blame] | 70 | PyObject* cursors; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 71 | |
Gerhard Häring | f9cee22 | 2010-03-05 15:20:03 +0000 | [diff] [blame] | 72 | /* Counters for how many statements/cursors were created in the connection. May be |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 73 | * reset to 0 at certain intervals */ |
| 74 | int created_statements; |
Gerhard Häring | f9cee22 | 2010-03-05 15:20:03 +0000 | [diff] [blame] | 75 | int created_cursors; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 76 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 77 | PyObject* row_factory; |
| 78 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 79 | /* Determines how bytestrings from SQLite are converted to Python objects: |
| 80 | * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings |
Petri Lehtinen | bc35beb | 2012-02-09 21:09:03 +0200 | [diff] [blame] | 81 | * - PyBytes_Type: The bytestrings are returned as-is. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 82 | * - Any custom callable: Any object returned from the callable called with the bytestring |
| 83 | * as single parameter. |
| 84 | */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 85 | PyObject* text_factory; |
| 86 | |
| 87 | /* remember references to functions/classes used in |
| 88 | * create_function/create/aggregate, use these as dictionary keys, so we |
| 89 | * can keep the total system refcount constant by clearing that dictionary |
| 90 | * in connection_dealloc */ |
| 91 | PyObject* function_pinboard; |
| 92 | |
| 93 | /* a dictionary of registered collation name => collation callable mappings */ |
| 94 | PyObject* collations; |
| 95 | |
| 96 | /* Exception objects */ |
| 97 | PyObject* Warning; |
| 98 | PyObject* Error; |
| 99 | PyObject* InterfaceError; |
| 100 | PyObject* DatabaseError; |
| 101 | PyObject* DataError; |
| 102 | PyObject* OperationalError; |
| 103 | PyObject* IntegrityError; |
| 104 | PyObject* InternalError; |
| 105 | PyObject* ProgrammingError; |
| 106 | PyObject* NotSupportedError; |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 107 | } pysqlite_Connection; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 108 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 109 | extern PyTypeObject pysqlite_ConnectionType; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 110 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 111 | PyObject* pysqlite_connection_alloc(PyTypeObject* type, int aware); |
| 112 | void pysqlite_connection_dealloc(pysqlite_Connection* self); |
| 113 | PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs); |
| 114 | PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args); |
| 115 | PyObject* _pysqlite_connection_begin(pysqlite_Connection* self); |
| 116 | PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args); |
| 117 | PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args); |
| 118 | PyObject* pysqlite_connection_new(PyTypeObject* type, PyObject* args, PyObject* kw); |
| 119 | int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 120 | |
Gerhard Häring | f9cee22 | 2010-03-05 15:20:03 +0000 | [diff] [blame] | 121 | int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor); |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 122 | int pysqlite_check_thread(pysqlite_Connection* self); |
| 123 | int pysqlite_check_connection(pysqlite_Connection* con); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 124 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 125 | int pysqlite_connection_setup_types(void); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 126 | |
| 127 | #endif |