mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-29 12:23:42 +03:00
Don't inconditionately run a query at connection to set datestyle to ISO.
Run it only if PQparameterStatus() reports the datestyle is set to something different.
This commit is contained in:
parent
15bba2966f
commit
e1a04bec0e
|
@ -6,9 +6,12 @@
|
||||||
* psycopg/connection_int.c: dropped support for protocol 2 at compile
|
* psycopg/connection_int.c: dropped support for protocol 2 at compile
|
||||||
time and protocol 2-specific code.
|
time and protocol 2-specific code.
|
||||||
|
|
||||||
* psycopg/connection_int.c: don't run a query at connection to detect
|
* psycopg/connection_int.c: don't run a query at every connection to detect
|
||||||
client encoding: use PQparameterStatus() instead.
|
client encoding: use PQparameterStatus() instead.
|
||||||
|
|
||||||
|
* psycopg/connection_int.c: don't run a query at every connection to set
|
||||||
|
the datestyle to ISO if PQparameterStatus() reports it already is.
|
||||||
|
|
||||||
2010-11-11 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
2010-11-11 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||||
|
|
||||||
* lib/extras.py: build the namedtuple only once per execution, not once
|
* lib/extras.py: build the namedtuple only once per execution, not once
|
||||||
|
|
4
NEWS-2.3
4
NEWS-2.3
|
@ -15,7 +15,9 @@ psycopg 2.3 aims to expose some new features introduced in PostgreSQL 9.0.
|
||||||
|
|
||||||
- Dropped support for protocol 2: Psycopg 2.3 can only connect to PostgreSQL
|
- Dropped support for protocol 2: Psycopg 2.3 can only connect to PostgreSQL
|
||||||
servers with version at least 7.4.
|
servers with version at least 7.4.
|
||||||
- don't issue a query at every connection to detect the client encoding.
|
- don't issue a query at every connection to detect the client encoding
|
||||||
|
and to set the datestyle to ISO if it is already compatible with what
|
||||||
|
expected.
|
||||||
- `mogrify()` now supports unicode queries.
|
- `mogrify()` now supports unicode queries.
|
||||||
- subclasses of a type that can be adapted are adapted as the superclass.
|
- subclasses of a type that can be adapted are adapted as the superclass.
|
||||||
- `errorcodes` knows a couple of new codes introduced in PostgreSQL 9.0.
|
- `errorcodes` knows a couple of new codes introduced in PostgreSQL 9.0.
|
||||||
|
|
|
@ -292,6 +292,22 @@ conn_get_server_version(PGconn *pgconn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 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. */
|
||||||
|
static int
|
||||||
|
conn_is_datestyle_ok(PGconn *pgconn)
|
||||||
|
{
|
||||||
|
const char *ds;
|
||||||
|
|
||||||
|
ds = PQparameterStatus(pgconn, "DateStyle");
|
||||||
|
Dprintf("conn_connect: DateStyle %s", ds);
|
||||||
|
|
||||||
|
/* Return true if ds starts with "ISO"
|
||||||
|
* e.g. "ISO, DMY" is fine, "German" not. */
|
||||||
|
return (ds[0] == 'I' && ds[1] == 'S' && ds[2] == 'O');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* conn_setup - setup and read basic information about the connection */
|
/* conn_setup - setup and read basic information about the connection */
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -323,8 +339,10 @@ conn_setup(connectionObject *self, PGconn *pgconn)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!conn_is_datestyle_ok(self->pgconn)) {
|
||||||
if (!green) {
|
if (!green) {
|
||||||
Py_UNBLOCK_THREADS;
|
Py_UNBLOCK_THREADS;
|
||||||
|
Dprintf("conn_connect: exec query \"%s\";", psyco_datestyle);
|
||||||
pgres = PQexec(pgconn, psyco_datestyle);
|
pgres = PQexec(pgconn, psyco_datestyle);
|
||||||
Py_BLOCK_THREADS;
|
Py_BLOCK_THREADS;
|
||||||
} else {
|
} else {
|
||||||
|
@ -340,6 +358,7 @@ conn_setup(connectionObject *self, PGconn *pgconn)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
CLEARPGRES(pgres);
|
CLEARPGRES(pgres);
|
||||||
|
}
|
||||||
|
|
||||||
if (!green) {
|
if (!green) {
|
||||||
Py_UNBLOCK_THREADS;
|
Py_UNBLOCK_THREADS;
|
||||||
|
@ -642,6 +661,9 @@ _conn_poll_setup_async(connectionObject *self)
|
||||||
*/
|
*/
|
||||||
self->isolation_level = 0;
|
self->isolation_level = 0;
|
||||||
|
|
||||||
|
/* If the datestyle is ISO or anything else good,
|
||||||
|
* we can skip the CONN_STATUS_DATESTYLE step. */
|
||||||
|
if (!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)) {
|
||||||
|
@ -651,6 +673,12 @@ _conn_poll_setup_async(connectionObject *self)
|
||||||
Dprintf("conn_poll: async_status -> ASYNC_WRITE");
|
Dprintf("conn_poll: async_status -> ASYNC_WRITE");
|
||||||
self->async_status = ASYNC_WRITE;
|
self->async_status = ASYNC_WRITE;
|
||||||
res = PSYCO_POLL_WRITE;
|
res = PSYCO_POLL_WRITE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Dprintf("conn_poll: status -> CONN_STATUS_READY");
|
||||||
|
self->status = CONN_STATUS_READY;
|
||||||
|
res = PSYCO_POLL_OK;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONN_STATUS_DATESTYLE:
|
case CONN_STATUS_DATESTYLE:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user