Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / psycopg2 / psycopg / connection.h
1 /* connection.h - definition for the psycopg connection type
2  *
3  * Copyright (C) 2003 Federico Di Gregorio <fog@debian.org>
4  *
5  * This file is part of psycopg.
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #ifndef PSYCOPG_CONNECTION_H
23 #define PSYCOPG_CONNECTION_H 1
24
25 #include <Python.h>
26 #include <libpq-fe.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
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
37     
38 extern PyTypeObject connectionType;
39
40 typedef struct {
41     PyObject HEAD;
42
43     pthread_mutex_t lock;   /* the global connection lock */
44
45     char *dsn;              /* data source name */
46     char *critical;         /* critical error on this connection */
47     char *encoding;         /* current backend encoding */
48     
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 */
54     
55     PGconn *pgconn;         /* the postgresql connection */
56
57     PyObject *async_cursor;
58     
59     /* notice processing */
60     PyObject *notice_list;
61     PyObject *notice_filter;
62
63     /* notifies */
64     PyObject *notifies;
65
66     /* errors (DBAPI-2.0 extension) */
67     PyObject *exc_Error;
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;
77     
78 } connectionObject;
79     
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); 
87
88 /* exception-raising macros */
89 #define EXC_IF_CONN_CLOSED(self) if ((self)->closed > 0) { \
90     PyErr_SetString(InterfaceError, "connection already closed"); \
91     return NULL; }
92     
93 #ifdef __cplusplus
94 }
95 #endif
96
97 #endif /* !defined(PSYCOPG_CONNECTION_H) */