diff options
Diffstat (limited to 'psycopg/connection.h')
-rw-r--r-- | psycopg/connection.h | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/psycopg/connection.h b/psycopg/connection.h index 552b93d..7f512a1 100644 --- a/psycopg/connection.h +++ b/psycopg/connection.h @@ -59,14 +59,6 @@ extern "C" { later change it, she must know what she's doing... these are the queries we need to issue */ #define psyco_datestyle "SET DATESTYLE TO 'ISO'" -#define psyco_transaction_isolation "SHOW default_transaction_isolation" - -/* possible values for isolation_level */ -typedef enum { - ISOLATION_LEVEL_AUTOCOMMIT = 0, - ISOLATION_LEVEL_READ_COMMITTED = 1, - ISOLATION_LEVEL_SERIALIZABLE = 2, -} conn_isolation_level_t; extern HIDDEN PyTypeObject connectionType; @@ -87,7 +79,6 @@ typedef struct { long int closed; /* 1 means connection has been closed; 2 that something horrible happened */ - long int isolation_level; /* isolation level for this connection */ long int mark; /* number of commits/rollbacks done so far */ int status; /* status of the connection */ XidObject *tpc_xid; /* Transaction ID in two-phase commit */ @@ -99,7 +90,10 @@ typedef struct { PGconn *pgconn; /* the postgresql connection */ PGcancel *cancel; /* the cancellation structure */ - PyObject *async_cursor; /* weakref to a cursor executing an asynchronous query */ + /* Weakref to the object executing an asynchronous query. The object + * is a cursor for async connections, but it may be something else + * for a green connection. If NULL, the connection is idle. */ + PyObject *async_cursor; int async_status; /* asynchronous execution status */ /* notice processing */ @@ -117,12 +111,20 @@ typedef struct { int equote; /* use E''-style quotes for escaped strings */ PyObject *weakreflist; /* list of weak references */ + int autocommit; + } connectionObject; +/* map isolation level values into a numeric const */ +typedef struct { + char *name; + int value; +} IsolationLevel; + /* C-callable functions in connection_int.c and connection_ext.c */ HIDDEN PyObject *conn_text_from_chars(connectionObject *pgconn, const char *str); HIDDEN int conn_get_standard_conforming_strings(PGconn *pgconn); -HIDDEN int conn_get_isolation_level(PGresult *pgres); +HIDDEN int conn_get_isolation_level(connectionObject *self); HIDDEN int conn_get_protocol_version(PGconn *pgconn); HIDDEN int conn_get_server_version(PGconn *pgconn); HIDDEN PGcancel *conn_get_cancel(PGconn *pgconn); @@ -134,6 +136,10 @@ HIDDEN int conn_connect(connectionObject *self, long int async); HIDDEN void conn_close(connectionObject *self); HIDDEN int conn_commit(connectionObject *self); HIDDEN int conn_rollback(connectionObject *self); +HIDDEN int conn_set_session(connectionObject *self, const char *isolevel, + const char *readonly, const char *deferrable, + int autocommit); +HIDDEN int conn_set_autocommit(connectionObject *self, int value); HIDDEN int conn_switch_isolation_level(connectionObject *self, int level); HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc); HIDDEN int conn_poll(connectionObject *self); @@ -152,6 +158,13 @@ HIDDEN PyObject *conn_tpc_recover(connectionObject *self); "in asynchronous mode"); \ return NULL; } +#define EXC_IF_IN_TRANSACTION(self, cmd) \ + if (self->status != CONN_STATUS_READY) { \ + PyErr_Format(ProgrammingError, \ + "%s cannot be used inside a transaction", #cmd); \ + return NULL; \ + } + #define EXC_IF_TPC_NOT_SUPPORTED(self) \ if ((self)->server_version < 80100) { \ PyErr_Format(NotSupportedError, \ |