| 1 |
/* connection.h - definitions for the connection type |
| 2 |
* |
| 3 |
* Copyright (C) 2004-2010 Gerhard Häring <[email protected]> |
| 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 "module.h" |
| 31 |
|
| 32 |
#include "sqlite3.h" |
| 33 |
|
| 34 |
typedef struct _callback_context |
| 35 |
{ |
| 36 |
PyObject *callable; |
| 37 |
PyObject *module; |
| 38 |
pysqlite_state *state; |
| 39 |
Py_ssize_t refcount; |
| 40 |
} callback_context; |
| 41 |
|
| 42 |
enum autocommit_mode { |
| 43 |
AUTOCOMMIT_LEGACY = LEGACY_TRANSACTION_CONTROL, |
| 44 |
AUTOCOMMIT_ENABLED = 1, |
| 45 |
AUTOCOMMIT_DISABLED = 0, |
| 46 |
}; |
| 47 |
|
| 48 |
typedef struct |
| 49 |
{ |
| 50 |
PyObject_HEAD |
| 51 |
sqlite3 *db; |
| 52 |
pysqlite_state *state; |
| 53 |
|
| 54 |
/* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a |
| 55 |
* bitwise combination thereof makes sense */ |
| 56 |
int detect_types; |
| 57 |
|
| 58 |
/* NULL for autocommit, otherwise a string with the isolation level */ |
| 59 |
const char *isolation_level; |
| 60 |
enum autocommit_mode autocommit; |
| 61 |
|
| 62 |
/* 1 if a check should be performed for each API call if the connection is |
| 63 |
* used from the same thread it was created in */ |
| 64 |
int check_same_thread; |
| 65 |
|
| 66 |
int initialized; |
| 67 |
|
| 68 |
/* thread identification of the thread the connection was created in */ |
| 69 |
unsigned long thread_ident; |
| 70 |
|
| 71 |
PyObject *statement_cache; |
| 72 |
|
| 73 |
/* Lists of weak references to cursors and blobs used within this connection */ |
| 74 |
PyObject *cursors; |
| 75 |
PyObject *blobs; |
| 76 |
|
| 77 |
/* Counters for how many cursors were created in the connection. May be |
| 78 |
* reset to 0 at certain intervals */ |
| 79 |
int created_cursors; |
| 80 |
|
| 81 |
PyObject* row_factory; |
| 82 |
|
| 83 |
/* Determines how bytestrings from SQLite are converted to Python objects: |
| 84 |
* - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings |
| 85 |
* - PyBytes_Type: The bytestrings are returned as-is. |
| 86 |
* - Any custom callable: Any object returned from the callable called with the bytestring |
| 87 |
* as single parameter. |
| 88 |
*/ |
| 89 |
PyObject* text_factory; |
| 90 |
|
| 91 |
// Remember contexts used by the trace, progress, and authoriser callbacks |
| 92 |
callback_context *trace_ctx; |
| 93 |
callback_context *progress_ctx; |
| 94 |
callback_context *authorizer_ctx; |
| 95 |
|
| 96 |
/* Exception objects: borrowed refs. */ |
| 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; |
| 107 |
} pysqlite_Connection; |
| 108 |
|
| 109 |
int pysqlite_check_thread(pysqlite_Connection* self); |
| 110 |
int pysqlite_check_connection(pysqlite_Connection* con); |
| 111 |
|
| 112 |
int pysqlite_connection_setup_types(PyObject *module); |
| 113 |
|
| 114 |
#endif |