| 1 | /* connection.h - definitions for the connection type
|
|---|
| 2 | *
|
|---|
| 3 | * Copyright (C) 2004-2006 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 "cache.h"
|
|---|
| 31 | #include "module.h"
|
|---|
| 32 |
|
|---|
| 33 | #include "sqlite3.h"
|
|---|
| 34 |
|
|---|
| 35 | typedef struct
|
|---|
| 36 | {
|
|---|
| 37 | PyObject_HEAD
|
|---|
| 38 | sqlite3* db;
|
|---|
| 39 |
|
|---|
| 40 | /* 1 if we are currently within a transaction, i. e. if a BEGIN has been
|
|---|
| 41 | * issued */
|
|---|
| 42 | int inTransaction;
|
|---|
| 43 |
|
|---|
| 44 | /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
|
|---|
| 45 | * bitwise combination thereof makes sense */
|
|---|
| 46 | int detect_types;
|
|---|
| 47 |
|
|---|
| 48 | /* the timeout value in seconds for database locks */
|
|---|
| 49 | double timeout;
|
|---|
| 50 |
|
|---|
| 51 | /* for internal use in the timeout handler: when did the timeout handler
|
|---|
| 52 | * first get called with count=0? */
|
|---|
| 53 | double timeout_started;
|
|---|
| 54 |
|
|---|
| 55 | /* None for autocommit, otherwise a PyString with the isolation level */
|
|---|
| 56 | PyObject* isolation_level;
|
|---|
| 57 |
|
|---|
| 58 | /* NULL for autocommit, otherwise a string with the BEGIN statment; will be
|
|---|
| 59 | * freed in connection destructor */
|
|---|
| 60 | char* begin_statement;
|
|---|
| 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 | /* thread identification of the thread the connection was created in */
|
|---|
| 67 | long thread_ident;
|
|---|
| 68 |
|
|---|
| 69 | Cache* statement_cache;
|
|---|
| 70 |
|
|---|
| 71 | /* A list of weak references to statements used within this connection */
|
|---|
| 72 | PyObject* statements;
|
|---|
| 73 |
|
|---|
| 74 | /* a counter for how many statements were created in the connection. May be
|
|---|
| 75 | * reset to 0 at certain intervals */
|
|---|
| 76 | int created_statements;
|
|---|
| 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 | * - OptimizedUnicode: Like before, but for ASCII data, only PyStrings are created.
|
|---|
| 83 | * - PyString_Type: PyStrings are created as-is.
|
|---|
| 84 | * - Any custom callable: Any object returned from the callable called with the bytestring
|
|---|
| 85 | * as single parameter.
|
|---|
| 86 | */
|
|---|
| 87 | PyObject* text_factory;
|
|---|
| 88 |
|
|---|
| 89 | /* remember references to functions/classes used in
|
|---|
| 90 | * create_function/create/aggregate, use these as dictionary keys, so we
|
|---|
| 91 | * can keep the total system refcount constant by clearing that dictionary
|
|---|
| 92 | * in connection_dealloc */
|
|---|
| 93 | PyObject* function_pinboard;
|
|---|
| 94 |
|
|---|
| 95 | /* a dictionary of registered collation name => collation callable mappings */
|
|---|
| 96 | PyObject* collations;
|
|---|
| 97 |
|
|---|
| 98 | /* Exception objects */
|
|---|
| 99 | PyObject* Warning;
|
|---|
| 100 | PyObject* Error;
|
|---|
| 101 | PyObject* InterfaceError;
|
|---|
| 102 | PyObject* DatabaseError;
|
|---|
| 103 | PyObject* DataError;
|
|---|
| 104 | PyObject* OperationalError;
|
|---|
| 105 | PyObject* IntegrityError;
|
|---|
| 106 | PyObject* InternalError;
|
|---|
| 107 | PyObject* ProgrammingError;
|
|---|
| 108 | PyObject* NotSupportedError;
|
|---|
| 109 | } Connection;
|
|---|
| 110 |
|
|---|
| 111 | extern PyTypeObject ConnectionType;
|
|---|
| 112 |
|
|---|
| 113 | PyObject* connection_alloc(PyTypeObject* type, int aware);
|
|---|
| 114 | void connection_dealloc(Connection* self);
|
|---|
| 115 | PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs);
|
|---|
| 116 | PyObject* connection_close(Connection* self, PyObject* args);
|
|---|
| 117 | PyObject* _connection_begin(Connection* self);
|
|---|
| 118 | PyObject* connection_begin(Connection* self, PyObject* args);
|
|---|
| 119 | PyObject* connection_commit(Connection* self, PyObject* args);
|
|---|
| 120 | PyObject* connection_rollback(Connection* self, PyObject* args);
|
|---|
| 121 | PyObject* connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
|
|---|
| 122 | int connection_init(Connection* self, PyObject* args, PyObject* kwargs);
|
|---|
| 123 |
|
|---|
| 124 | int check_thread(Connection* self);
|
|---|
| 125 | int check_connection(Connection* con);
|
|---|
| 126 |
|
|---|
| 127 | int connection_setup_types(void);
|
|---|
| 128 |
|
|---|
| 129 | #endif
|
|---|