aboutsummaryrefslogtreecommitdiff
path: root/modules/postgres/postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/postgres/postgres.c')
-rw-r--r--modules/postgres/postgres.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/modules/postgres/postgres.c b/modules/postgres/postgres.c
index 1218564..05f35e8 100644
--- a/modules/postgres/postgres.c
+++ b/modules/postgres/postgres.c
@@ -74,6 +74,14 @@ modpg_negative_reply(struct modpg_db *db)
(def_db.negative_reply ? def_db.negative_reply : "NOTFOUND");
}
+static const char *
+modpg_onerror_reply(struct modpg_db *db)
+{
+ return db->onerror_reply ?
+ db->onerror_reply :
+ (def_db.onerror_reply ? def_db.onerror_reply : "NOTFOUND");
+}
+
static int
opendb(struct modpg_db *db)
{
@@ -560,25 +568,24 @@ modpg_query(smap_database_t dbp,
PGresult *res;
int rc;
char **env, **qenv;
- size_t ntuples;
if (create_query_env(map, key, conninfo, &env, &qenv))
return 1;
rc = do_query(db, qenv, &res);
free_env(qenv);
- if (rc) {
- free_env(env);
- return 1; /* FIXME: honor onerror_reply */
+ if (rc)
+ rc = send_reply(ostr, modpg_onerror_reply(db), env);
+ else {
+ size_t ntuples = PQntuples(res);
+ smap_debug(dbgid, 1,
+ ("query returned %u columns in %u rows",
+ PQnfields(res), ntuples));
+ if (ntuples)
+ rc = do_positive_reply(db, ostr, &env, res);
+ else
+ rc = send_reply(ostr, modpg_negative_reply(db), env);
}
- ntuples = PQntuples(res);
- smap_debug(dbgid, 1,
- ("query returned %u columns in %u rows",
- PQnfields(res), ntuples));
- if (ntuples)
- rc = do_positive_reply(db, ostr, &env, res);
- else
- rc = send_reply(ostr, modpg_negative_reply(db), env);
free_env(env);
return rc;
}

Return to:

Send suggestions and report system problems to the System administrator.