Skip to content

Commit

Permalink
Fix compatibility with PostgreSQL 9.x: rows affected.
Browse files Browse the repository at this point in the history
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
PiotrSikora committed Nov 10, 2011
1 parent 0bd9db4 commit 7c1cde3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ngx_postgres_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7c1cde3

Please sign in to comment.