kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 8e93dbc396147dd2320d420ee893144b3c51b01f
parent 71b69f108ed08923c57706a66ecea6fb92bc0156
Author: Joris Vink <joris@coders.se>
Date:   Wed,  2 Apr 2014 23:01:47 +0200

amend example with additional query + kore_pgsql_logerror()

Diffstat:
contrib/modules/pgsql_test/src/pgsql_test.c | 19++++++++++++++-----
contrib/postgres/kore_pgsql.c | 7+++++++
includes/contrib/postgres/kore_pgsql.h | 1+
3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/contrib/modules/pgsql_test/src/pgsql_test.c b/contrib/modules/pgsql_test/src/pgsql_test.c @@ -30,10 +30,8 @@ serve_pgsql_test(struct http_request *req) KORE_PGSQL(req, "SELECT * FROM test", 0, { if (req->pgsql[0]->state == KORE_PGSQL_STATE_ERROR) { - kore_log(LOG_NOTICE, "pgsql: %s", - (req->pgsql[0]->error) ? - req->pgsql[0]->error : "unknown"); - http_response(req, 500, "fail", 4); + kore_pgsql_logerror(req->pgsql[0]); + http_response(req, 500, "fail\n", 5); return (KORE_RESULT_OK); } @@ -46,8 +44,19 @@ serve_pgsql_test(struct http_request *req) } }); + KORE_PGSQL(req, "SELECT * FROM foobar", 1, { + if (req->pgsql[1]->state != KORE_PGSQL_STATE_ERROR) { + kore_log(LOG_NOTICE, "expected error, got %d", + req->pgsql[1]->state); + http_response(req, 500, "fail2\n", 6); + return (KORE_RESULT_OK); + } else { + kore_pgsql_logerror(req->pgsql[1]); + } + }); + /* Query successfully completed */ - http_response(req, 200, "ok", 2); + http_response(req, 200, "ok\n", 3); return (KORE_RESULT_OK); } diff --git a/contrib/postgres/kore_pgsql.c b/contrib/postgres/kore_pgsql.c @@ -219,6 +219,13 @@ kore_pgsql_cleanup(struct http_request *req) } } +void +kore_pgsql_logerror(struct kore_pgsql *pgsql) +{ + kore_log(LOG_NOTICE, "pgsql error: %s", + (pgsql->error) ? pgsql->error : "unknown"); +} + int kore_pgsql_ntuples(struct kore_pgsql *pgsql) { diff --git a/includes/contrib/postgres/kore_pgsql.h b/includes/contrib/postgres/kore_pgsql.h @@ -33,6 +33,7 @@ void kore_pgsql_continue(struct http_request *, int); int kore_pgsql_query(struct http_request *, char *, int); int kore_pgsql_ntuples(struct kore_pgsql *); +void kore_pgsql_logerror(struct kore_pgsql *); char *kore_pgsql_getvalue(struct kore_pgsql *, int, int); #define KORE_PGSQL_STATE_INIT 1