summaryrefslogtreecommitdiff
path: root/psycopg/connection_int.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-12-26 12:06:21 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-12-26 12:06:21 +0100
commit7caba160b7083c64197329e17d0d0e0eb17c8639 (patch)
tree9c7a8221ccdbbf3efdbac0ccd49287cc90647a6f /psycopg/connection_int.c
parent121cf3b8f8426765d983579d3a4b2e932429cd9f (diff)
parente9577e9b890fd9a27bb146e8ea1c24eb562f28b2 (diff)
downloadpsycopg2-7caba160b7083c64197329e17d0d0e0eb17c8639.tar.gz
Merge branch 'master' into fast-codecs
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r--psycopg/connection_int.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 62976d4..a63b47e 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -521,6 +521,25 @@ conn_setup_cancel(connectionObject *self, PGconn *pgconn)
return 0;
}
+/* Return 1 if the "replication" keyword is set in the DSN, 0 otherwise */
+static int
+dsn_has_replication(char *pgdsn)
+{
+ int ret = 0;
+ PQconninfoOption *connopts, *ptr;
+
+ connopts = PQconninfoParse(pgdsn, NULL);
+
+ for(ptr = connopts; ptr->keyword != NULL; ptr++) {
+ if(strcmp(ptr->keyword, "replication") == 0 && ptr->val != NULL)
+ ret = 1;
+ }
+
+ PQconninfoFree(connopts);
+
+ return ret;
+}
+
/* Return 1 if the server datestyle allows us to work without problems,
0 if it needs to be set to something better, e.g. ISO. */
@@ -549,28 +568,29 @@ conn_setup(connectionObject *self, PGconn *pgconn)
{
PGresult *pgres = NULL;
char *error = NULL;
+ int rv = -1;
self->equote = conn_get_standard_conforming_strings(pgconn);
self->server_version = conn_get_server_version(pgconn);
self->protocol = conn_get_protocol_version(self->pgconn);
if (3 != self->protocol) {
PyErr_SetString(InterfaceError, "only protocol 3 supported");
- return -1;
+ goto exit;
}
if (0 > conn_read_encoding(self, pgconn)) {
- return -1;
+ goto exit;
}
if (0 > conn_setup_cancel(self, pgconn)) {
- return -1;
+ goto exit;
}
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&self->lock);
Py_BLOCK_THREADS;
- if (!conn_is_datestyle_ok(self->pgconn)) {
+ if (!dsn_has_replication(self->dsn) && !conn_is_datestyle_ok(self->pgconn)) {
int res;
Py_UNBLOCK_THREADS;
res = pq_set_guc_locked(self, "datestyle", "ISO",
@@ -578,18 +598,23 @@ conn_setup(connectionObject *self, PGconn *pgconn)
Py_BLOCK_THREADS;
if (res < 0) {
pq_complete_error(self, &pgres, &error);
- return -1;
+ goto unlock;
}
}
/* for reset */
self->autocommit = 0;
+ /* success */
+ rv = 0;
+
+unlock:
Py_UNBLOCK_THREADS;
pthread_mutex_unlock(&self->lock);
Py_END_ALLOW_THREADS;
- return 0;
+exit:
+ return rv;
}
/* conn_connect - execute a connection to the database */
@@ -886,8 +911,11 @@ _conn_poll_setup_async(connectionObject *self)
self->autocommit = 1;
/* If the datestyle is ISO or anything else good,
- * we can skip the CONN_STATUS_DATESTYLE step. */
- if (!conn_is_datestyle_ok(self->pgconn)) {
+ * we can skip the CONN_STATUS_DATESTYLE step.
+ * Note that we cannot change the datestyle on a replication
+ * connection.
+ */
+ if (!dsn_has_replication(self->dsn) && !conn_is_datestyle_ok(self->pgconn)) {
Dprintf("conn_poll: status -> CONN_STATUS_DATESTYLE");
self->status = CONN_STATUS_DATESTYLE;
if (0 == pq_send_query(self, psyco_datestyle)) {