1 /* connection.h - definition for the psycopg connection type
3 * Copyright (C) 2003 Federico Di Gregorio <fog@debian.org>
5 * This file is part of psycopg.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef PSYCOPG_CONNECTION_H
23 #define PSYCOPG_CONNECTION_H 1
32 /* connection status */
33 #define CONN_STATUS_READY 1
34 #define CONN_STATUS_BEGIN 2
35 #define CONN_STATUS_SYNC 3
36 #define CONN_STATUS_ASYNC 4
38 extern PyTypeObject connectionType;
43 pthread_mutex_t lock; /* the global connection lock */
45 char *dsn; /* data source name */
46 char *critical; /* critical error on this connection */
47 char *encoding; /* current backend encoding */
49 long int closed; /* 2 means connection has been closed */
50 long int isolation_level; /* isolation level for this connection */
51 long int mark; /* number of commits/rollbacks done so far */
52 int status; /* status of the connection */
53 int protocol; /* protocol version */
55 PGconn *pgconn; /* the postgresql connection */
57 PyObject *async_cursor;
59 /* notice processing */
60 PyObject *notice_list;
61 PyObject *notice_filter;
66 /* errors (DBAPI-2.0 extension) */
68 PyObject *exc_Warning;
69 PyObject *exc_InterfaceError;
70 PyObject *exc_DatabaseError;
71 PyObject *exc_InternalError;
72 PyObject *exc_OperationalError;
73 PyObject *exc_ProgrammingError;
74 PyObject *exc_IntegrityError;
75 PyObject *exc_DataError;
76 PyObject *exc_NotSupportedError;
80 /* C-callable functions in connection_int.c and connection_ext.c */
81 extern int conn_connect(connectionObject *self);
82 extern void conn_close(connectionObject *self);
83 extern int conn_commit(connectionObject *self);
84 extern int conn_rollback(connectionObject *self);
85 extern int conn_switch_isolation_level(connectionObject *self, int level);
86 extern int conn_set_client_encoding(connectionObject *self, char *enc);
88 /* exception-raising macros */
89 #define EXC_IF_CONN_CLOSED(self) if ((self)->closed > 0) { \
90 PyErr_SetString(InterfaceError, "connection already closed"); \
97 #endif /* !defined(PSYCOPG_CONNECTION_H) */