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#define PY_SSIZE_T_CLEAN
27#include "Python.h"
28#include "pythread.h"
29#include "structmember.h"
30
31#include "cache.h"
32#include "module.h"
33
34#include "sqlite3.h"
35
36typedef struct
37{
38 PyObject_HEAD
39 sqlite3* db;
40
41 /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
42 * bitwise combination thereof makes sense */
43 int detect_types;
44
45 /* the timeout value in seconds for database locks */
46 double timeout;
47
48 /* for internal use in the timeout handler: when did the timeout handler
49 * first get called with count=0? */
50 double timeout_started;
51
52 /* None for autocommit, otherwise a PyUnicode with the isolation level */
53 PyObject* isolation_level;
54
55 /* NULL for autocommit, otherwise a string with the BEGIN statement */
56 const char* begin_statement;
57
58 /* 1 if a check should be performed for each API call if the connection is
59 * used from the same thread it was created in */
60 int check_same_thread;
61
62 int initialized;
63
64 /* thread identification of the thread the connection was created in */
65 unsigned long thread_ident;
66
67 pysqlite_Cache* statement_cache;
68
69 /* Lists of weak references to statements and cursors used within this connection */
70 PyObject* statements;
71 PyObject* cursors;
72
73 /* Counters for how many statements/cursors were created in the connection. May be
74 * reset to 0 at certain intervals */
75 int created_statements;
76 int created_cursors;
77
78 PyObject* row_factory;
79
80 /* Determines how bytestrings from SQLite are converted to Python objects:
81 * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
82 * - PyBytes_Type: The bytestrings are returned as-is.
83 * - Any custom callable: Any object returned from the callable called with the bytestring
84 * as single parameter.
85 */
86 PyObject* text_factory;
87
88 /* remember references to object used in trace_callback/progress_handler/authorizer_cb */
89 PyObject* function_pinboard_trace_callback;
90 PyObject* function_pinboard_progress_handler;
91 PyObject* function_pinboard_authorizer_cb;
92
93 /* a dictionary of registered collation name => collation callable mappings */
94 PyObject* collations;
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
109extern PyTypeObject *pysqlite_ConnectionType;
110
111PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
112
113int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor);
114int pysqlite_check_thread(pysqlite_Connection* self);
115int pysqlite_check_connection(pysqlite_Connection* con);
116
117int pysqlite_connection_setup_types(PyObject *module);
118
119#endif
120