Convert pgsql-sync example after pgsql changes.

Only check if we bound something if we're asynchronous.
This commit is contained in:
Joris Vink 2017-03-24 13:00:05 +01:00
parent 59f7e85f45
commit a3ed3bf7eb
2 changed files with 8 additions and 4 deletions

View File

@ -49,6 +49,8 @@ page(struct http_request *req)
req->status = HTTP_STATUS_INTERNAL_ERROR;
kore_pgsql_init(&sql);
/*
* Initialise our kore_pgsql data structure with the database name
* we want to connect to (note that we registered this earlier with
@ -56,7 +58,7 @@ page(struct http_request *req)
* query (KORE_PGSQL_SYNC) and we do not need to pass our http_request
* so we pass NULL instead.
*/
if (!kore_pgsql_query_init(&sql, NULL, "db", KORE_PGSQL_SYNC)) {
if (!kore_pgsql_setup(&sql, "db", KORE_PGSQL_SYNC)) {
kore_pgsql_logerror(&sql);
goto out;
}

View File

@ -110,9 +110,11 @@ kore_pgsql_setup(struct kore_pgsql *pgsql, const char *dbname, int flags)
return (KORE_RESULT_ERROR);
}
if (pgsql->req == NULL && pgsql->cb == NULL) {
pgsql_set_error(pgsql, "nothing was bound");
return (KORE_RESULT_ERROR);
if (flags & KORE_PGSQL_ASYNC) {
if (pgsql->req == NULL && pgsql->cb == NULL) {
pgsql_set_error(pgsql, "nothing was bound");
return (KORE_RESULT_ERROR);
}
}
db = NULL;