Dropped pgconn argument from conn_setup()

This commit is contained in:
Daniele Varrazzo 2019-03-17 02:35:42 +00:00
parent c15e4c1a85
commit e740c21ee6
3 changed files with 16 additions and 17 deletions

View File

@ -160,7 +160,7 @@ HIDDEN int conn_get_server_version(PGconn *pgconn);
HIDDEN void conn_notice_process(connectionObject *self); HIDDEN void conn_notice_process(connectionObject *self);
HIDDEN void conn_notice_clean(connectionObject *self); HIDDEN void conn_notice_clean(connectionObject *self);
HIDDEN void conn_notifies_process(connectionObject *self); HIDDEN void conn_notifies_process(connectionObject *self);
RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn); RAISES_NEG HIDDEN int conn_setup(connectionObject *self);
HIDDEN int conn_connect(connectionObject *self, long int async); HIDDEN int conn_connect(connectionObject *self, long int async);
HIDDEN void conn_close(connectionObject *self); HIDDEN void conn_close(connectionObject *self);
HIDDEN void conn_close_locked(connectionObject *self); HIDDEN void conn_close_locked(connectionObject *self);

View File

@ -649,24 +649,24 @@ conn_is_datestyle_ok(PGconn *pgconn)
/* conn_setup - setup and read basic information about the connection */ /* conn_setup - setup and read basic information about the connection */
RAISES_NEG int RAISES_NEG int
conn_setup(connectionObject *self, PGconn *pgconn) conn_setup(connectionObject *self)
{ {
char *error = NULL; char *error = NULL;
int rv = -1; int rv = -1;
self->equote = conn_get_standard_conforming_strings(pgconn); self->equote = conn_get_standard_conforming_strings(self->pgconn);
self->server_version = conn_get_server_version(pgconn); self->server_version = conn_get_server_version(self->pgconn);
self->protocol = conn_get_protocol_version(self->pgconn); self->protocol = conn_get_protocol_version(self->pgconn);
if (3 != self->protocol) { if (3 != self->protocol) {
PyErr_SetString(InterfaceError, "only protocol 3 supported"); PyErr_SetString(InterfaceError, "only protocol 3 supported");
goto exit; goto exit;
} }
if (0 > conn_read_encoding(self, pgconn)) { if (0 > conn_read_encoding(self, self->pgconn)) {
goto exit; goto exit;
} }
if (0 > conn_setup_cancel(self, pgconn)) { if (0 > conn_setup_cancel(self, self->pgconn)) {
goto exit; goto exit;
} }
@ -708,7 +708,6 @@ exit:
static int static int
_conn_sync_connect(connectionObject *self) _conn_sync_connect(connectionObject *self)
{ {
PGconn *pgconn;
int green; int green;
/* store this value to prevent inconsistencies due to a change /* store this value to prevent inconsistencies due to a change
@ -716,31 +715,31 @@ _conn_sync_connect(connectionObject *self)
green = psyco_green(); green = psyco_green();
if (!green) { if (!green) {
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
self->pgconn = pgconn = PQconnectdb(self->dsn); self->pgconn = PQconnectdb(self->dsn);
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
Dprintf("conn_connect: new postgresql connection at %p", pgconn); Dprintf("conn_connect: new PG connection at %p", self->pgconn);
} }
else { else {
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
self->pgconn = pgconn = PQconnectStart(self->dsn); self->pgconn = PQconnectStart(self->dsn);
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
Dprintf("conn_connect: new green postgresql connection at %p", pgconn); Dprintf("conn_connect: new green PG connection at %p", self->pgconn);
} }
if (pgconn == NULL) if (!self->pgconn)
{ {
Dprintf("conn_connect: PQconnectdb(%s) FAILED", self->dsn); Dprintf("conn_connect: PQconnectdb(%s) FAILED", self->dsn);
PyErr_SetString(OperationalError, "PQconnectdb() failed"); PyErr_SetString(OperationalError, "PQconnectdb() failed");
return -1; return -1;
} }
else if (PQstatus(pgconn) == CONNECTION_BAD) else if (PQstatus(self->pgconn) == CONNECTION_BAD)
{ {
Dprintf("conn_connect: PQconnectdb(%s) returned BAD", self->dsn); Dprintf("conn_connect: PQconnectdb(%s) returned BAD", self->dsn);
PyErr_SetString(OperationalError, PQerrorMessage(pgconn)); PyErr_SetString(OperationalError, PQerrorMessage(self->pgconn));
return -1; return -1;
} }
PQsetNoticeProcessor(pgconn, conn_notice_callback, (void*)self); PQsetNoticeProcessor(self->pgconn, conn_notice_callback, (void*)self);
/* if the connection is green, wait to finish connection */ /* if the connection is green, wait to finish connection */
if (green) { if (green) {
@ -757,7 +756,7 @@ _conn_sync_connect(connectionObject *self)
*/ */
self->status = CONN_STATUS_READY; self->status = CONN_STATUS_READY;
if (conn_setup(self, self->pgconn) == -1) { if (conn_setup(self) == -1) {
return -1; return -1;
} }

View File

@ -1052,7 +1052,7 @@ psyco_conn_reset(connectionObject *self, PyObject *dummy)
if (pq_reset(self) < 0) if (pq_reset(self) < 0)
return NULL; return NULL;
res = conn_setup(self, self->pgconn); res = conn_setup(self);
if (res < 0) if (res < 0)
return NULL; return NULL;