blob: ef03bc4f96622ac383569c31a8e76ac61e8e40fe [file] [log] [blame]
Anthony Baxterc51ee692006-04-01 00:57:31 +00001/* connection.h - definitions for the connection type
2 *
3 * Copyright (C) 2004-2005 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#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
40 int inTransaction;
41 int detect_types;
42
43 /* the timeout value in seconds for database locks */
44 double timeout;
45
46 /* for internal use in the timeout handler: when did the timeout handler
47 * first get called with count=0? */
48 double timeout_started;
49
50 /* None for autocommit, otherwise a PyString with the isolation level */
51 PyObject* isolation_level;
52
53 /* NULL for autocommit, otherwise a string with the BEGIN statment; will be
54 * freed in connection destructor */
55 char* begin_statement;
56
57 int check_same_thread;
58 long thread_ident;
59
60 Cache* statement_cache;
61
62 PyObject* row_factory;
63
64 PyObject* text_factory;
65
66 /* remember references to functions/classes used in
67 * create_function/create/aggregate, use these as dictionary keys, so we
68 * can keep the total system refcount constant by clearing that dictionary
69 * in connection_dealloc */
70 PyObject* function_pinboard;
71
72 /* Exception objects */
73 PyObject* Warning;
74 PyObject* Error;
75 PyObject* InterfaceError;
76 PyObject* DatabaseError;
77 PyObject* DataError;
78 PyObject* OperationalError;
79 PyObject* IntegrityError;
80 PyObject* InternalError;
81 PyObject* ProgrammingError;
82 PyObject* NotSupportedError;
83} Connection;
84
85extern PyTypeObject ConnectionType;
86
87PyObject* connection_alloc(PyTypeObject* type, int aware);
88void connection_dealloc(Connection* self);
89PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs);
90PyObject* connection_close(Connection* self, PyObject* args);
91PyObject* _connection_begin(Connection* self);
92PyObject* connection_begin(Connection* self, PyObject* args);
93PyObject* connection_commit(Connection* self, PyObject* args);
94PyObject* connection_rollback(Connection* self, PyObject* args);
95PyObject* connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
96int connection_init(Connection* self, PyObject* args, PyObject* kwargs);
97
98int check_thread(Connection* self);
99int check_connection(Connection* con);
100
101int connection_setup_types(void);
102
103#endif