blob: 2860a0c6f9f297340dc5ceccb2fd69d8efda7f43 [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001/* connection.h - definitions for the connection type
2 *
Florent Xiclunac934f322010-09-03 23:47:32 +00003 * Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004 *
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
35typedef struct
36{
37 PyObject_HEAD
38 sqlite3* db;
39
Thomas Wouters477c8d52006-05-27 19:21:47 +000040 /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
41 * bitwise combination thereof makes sense */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000042 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 Storchaka483405b2015-02-17 10:14:30 +020051 /* None for autocommit, otherwise a PyUnicode with the isolation level */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000052 PyObject* isolation_level;
53
Serhiy Storchaka28914922016-09-01 22:18:03 +030054 /* NULL for autocommit, otherwise a string with the BEGIN statement */
55 const char* begin_statement;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000056
Thomas Wouters477c8d52006-05-27 19:21:47 +000057 /* 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 Wouters49fd7fa2006-04-21 10:40:58 +000059 int check_same_thread;
Thomas Wouters477c8d52006-05-27 19:21:47 +000060
Gerhard Häringf9cee222010-03-05 15:20:03 +000061 int initialized;
62
Thomas Wouters477c8d52006-05-27 19:21:47 +000063 /* thread identification of the thread the connection was created in */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000064 long thread_ident;
65
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +000066 pysqlite_Cache* statement_cache;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000067
Gerhard Häringf9cee222010-03-05 15:20:03 +000068 /* Lists of weak references to statements and cursors used within this connection */
Thomas Wouters477c8d52006-05-27 19:21:47 +000069 PyObject* statements;
Gerhard Häringf9cee222010-03-05 15:20:03 +000070 PyObject* cursors;
Thomas Wouters477c8d52006-05-27 19:21:47 +000071
Gerhard Häringf9cee222010-03-05 15:20:03 +000072 /* Counters for how many statements/cursors were created in the connection. May be
Thomas Wouters477c8d52006-05-27 19:21:47 +000073 * reset to 0 at certain intervals */
74 int created_statements;
Gerhard Häringf9cee222010-03-05 15:20:03 +000075 int created_cursors;
Thomas Wouters477c8d52006-05-27 19:21:47 +000076
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000077 PyObject* row_factory;
78
Thomas Wouters477c8d52006-05-27 19:21:47 +000079 /* Determines how bytestrings from SQLite are converted to Python objects:
80 * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
Petri Lehtinenbc35beb2012-02-09 21:09:03 +020081 * - PyBytes_Type: The bytestrings are returned as-is.
Thomas Wouters477c8d52006-05-27 19:21:47 +000082 * - Any custom callable: Any object returned from the callable called with the bytestring
83 * as single parameter.
84 */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000085 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 Woutersfc7bb8c2007-01-15 15:49:28 +0000107} pysqlite_Connection;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000108
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000109extern PyTypeObject pysqlite_ConnectionType;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000110
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000111PyObject* pysqlite_connection_alloc(PyTypeObject* type, int aware);
112void pysqlite_connection_dealloc(pysqlite_Connection* self);
113PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
114PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args);
115PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
116PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args);
117PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args);
118PyObject* pysqlite_connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
119int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000120
Gerhard Häringf9cee222010-03-05 15:20:03 +0000121int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor);
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000122int pysqlite_check_thread(pysqlite_Connection* self);
123int pysqlite_check_connection(pysqlite_Connection* con);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000124
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000125int pysqlite_connection_setup_types(void);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000126
127#endif