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
24 #ifndef PYSQLITE_CONNECTION_H
25 #define PYSQLITE_CONNECTION_H
26 #define PY_SSIZE_T_CLEAN
27 #include "Python.h"
28 #include "pythread.h"
29 #include "structmember.h"
30
31 #include "module.h"
32
33 #include "sqlite3.h"
34
35 typedef struct _callback_context
36 {
37 PyObject *callable;
38 PyObject *module;
39 pysqlite_state *state;
40 } callback_context;
41
42 typedef struct
43 {
44 PyObject_HEAD
45 sqlite3 *db;
46 pysqlite_state *state;
47
48 /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
49 * bitwise combination thereof makes sense */
50 int detect_types;
51
52 /* NULL for autocommit, otherwise a string with the isolation level */
53 const char *isolation_level;
54
55 /* 1 if a check should be performed for each API call if the connection is
56 * used from the same thread it was created in */
57 int check_same_thread;
58
59 int initialized;
60
61 /* thread identification of the thread the connection was created in */
62 unsigned long thread_ident;
63
64 PyObject *statement_cache;
65
66 /* Lists of weak references to cursors and blobs used within this connection */
67 PyObject *cursors;
68 PyObject *blobs;
69
70 /* Counters for how many cursors were created in the connection. May be
71 * reset to 0 at certain intervals */
72 int created_cursors;
73
74 PyObject* row_factory;
75
76 /* Determines how bytestrings from SQLite are converted to Python objects:
77 * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
78 * - PyBytes_Type: The bytestrings are returned as-is.
79 * - Any custom callable: Any object returned from the callable called with the bytestring
80 * as single parameter.
81 */
82 PyObject* text_factory;
83
84 // Remember contexts used by the trace, progress, and authoriser callbacks
85 callback_context *trace_ctx;
86 callback_context *progress_ctx;
87 callback_context *authorizer_ctx;
88
89 /* Exception objects: borrowed refs. */
90 PyObject* Warning;
91 PyObject* Error;
92 PyObject* InterfaceError;
93 PyObject* DatabaseError;
94 PyObject* DataError;
95 PyObject* OperationalError;
96 PyObject* IntegrityError;
97 PyObject* InternalError;
98 PyObject* ProgrammingError;
99 PyObject* NotSupportedError;
100 } pysqlite_Connection;
101
102 int pysqlite_check_thread(pysqlite_Connection* self);
103 int pysqlite_check_connection(pysqlite_Connection* con);
104
105 int pysqlite_connection_setup_types(PyObject *module);
106
107 #endif