Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix compatibility with PostgreSQL 9.x: rows affected.

Starting with PostgreSQL 9.0, libpq's PQcmdTuples() returns row count
for SELECT queries (previously it returned empty string).

Because we're using this value to detect number of changed rows,
both: "postgres_rewrite" directive and "$postgres_affected" variable
were working incorrectly.

Reported by Yichun Zhang (agentzh).
  • Loading branch information...
commit 7c1cde332912cd06a362a38def5bd9c3d38ff073 1 parent 0bd9db4
@PiotrSikora PiotrSikora authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/ngx_postgres_processor.c
View
10 src/ngx_postgres_processor.c
@@ -353,10 +353,12 @@ ngx_postgres_process_response(ngx_http_request_t *r, PGresult *res)
pgctx->var_rows = PQntuples(res);
/* set $postgres_affected */
- affected = PQcmdTuples(res);
- affected_len = ngx_strlen(affected);
- if (affected_len) {
- pgctx->var_affected = ngx_atoi((u_char *) affected, affected_len);
+ if (ngx_strncmp(PQcmdStatus(res), "SELECT", sizeof("SELECT") - 1)) {
+ affected = PQcmdTuples(res);
+ affected_len = ngx_strlen(affected);
+ if (affected_len) {
+ pgctx->var_affected = ngx_atoi((u_char *) affected, affected_len);
+ }
}
if (pglcf->rewrites) {
Please sign in to comment.
Something went wrong with that request. Please try again.