mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 19:03:43 +03:00
do not "SET datestyle" on replication connections
A replication connection - marked by the use of the keyword "replication" in the DSN - does not support SET commands. Trying to sent "SET datestyle" will result in an exception.
This commit is contained in:
parent
584c7e6890
commit
fb1dbc2a9b
|
@ -494,6 +494,26 @@ conn_setup_cancel(connectionObject *self, PGconn *pgconn)
|
||||||
return 0;
|
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++) {
|
||||||
|
printf("keyword %s val %s\n", ptr->keyword, ptr->val);
|
||||||
|
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,
|
/* 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. */
|
0 if it needs to be set to something better, e.g. ISO. */
|
||||||
|
@ -543,7 +563,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
|
||||||
pthread_mutex_lock(&self->lock);
|
pthread_mutex_lock(&self->lock);
|
||||||
Py_BLOCK_THREADS;
|
Py_BLOCK_THREADS;
|
||||||
|
|
||||||
if (!conn_is_datestyle_ok(self->pgconn)) {
|
if (!dsn_has_replication(self->dsn) && !conn_is_datestyle_ok(self->pgconn)) {
|
||||||
int res;
|
int res;
|
||||||
Py_UNBLOCK_THREADS;
|
Py_UNBLOCK_THREADS;
|
||||||
res = pq_set_guc_locked(self, "datestyle", "ISO",
|
res = pq_set_guc_locked(self, "datestyle", "ISO",
|
||||||
|
@ -859,8 +879,11 @@ _conn_poll_setup_async(connectionObject *self)
|
||||||
self->autocommit = 1;
|
self->autocommit = 1;
|
||||||
|
|
||||||
/* If the datestyle is ISO or anything else good,
|
/* If the datestyle is ISO or anything else good,
|
||||||
* we can skip the CONN_STATUS_DATESTYLE step. */
|
* we can skip the CONN_STATUS_DATESTYLE step.
|
||||||
if (!conn_is_datestyle_ok(self->pgconn)) {
|
* 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");
|
Dprintf("conn_poll: status -> CONN_STATUS_DATESTYLE");
|
||||||
self->status = CONN_STATUS_DATESTYLE;
|
self->status = CONN_STATUS_DATESTYLE;
|
||||||
if (0 == pq_send_query(self, psyco_datestyle)) {
|
if (0 == pq_send_query(self, psyco_datestyle)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user