aboutsummaryrefslogtreecommitdiff
path: root/src/clog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clog.c')
-rw-r--r--src/clog.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/clog.c b/src/clog.c
index ea5c9b2..9e11790 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -8,15 +8,13 @@ int init(int);
int page(struct http_request *);
/* Called when our module is loaded (see config) */
-int
-init(int state)
+int init(int state)
{
/* Register our database. */
int err = kore_pgsql_register(
"db",
"host=127.0.0.1 port=5432 user=postgres password=p0stgres dbname=clog sslmode=disable"
);
- // kore_pgsql_register("db", "host=/tmp dbname=clog");
return (err);
}
@@ -25,14 +23,17 @@ int page(struct http_request *req)
{
struct kore_buf *buf;
- buf = kore_buf_alloc(2048);
+ buf = kore_buf_alloc(4096);
kore_buf_append(buf, asset_index_begin_html, asset_len_index_begin_html);
- /* sql stuff */
+ // SQL vars
struct kore_pgsql sql;
- char *name;
- int rows, i;
+ int row, rows;
+
+ // Results
+ char *id;
+ char *title, *body;
/* req->status = HTTP_STATUS_INTERNAL_ERROR; */
@@ -45,21 +46,17 @@ int page(struct http_request *req)
* query (KORE_PGSQL_SYNC).
*/
int err = kore_pgsql_setup(&sql, "db", KORE_PGSQL_SYNC);
- kore_log(1, "kore_pgsql_setup: %d", err);
- kore_log(1, "sql->state: %d", sql.state);
+ kore_log(LOG_ERR, "kore_pgsql_setup: %d", err);
if (!err) {
- kore_log(1, "here1!");
kore_pgsql_logerror(&sql);
goto out;
}
- kore_log(1, "here!");
-
/*
* Now we can fire off the query, once it returns we either have
* a result on which we can operate or an error occurred.
*/
- if (!kore_pgsql_query(&sql, "SELECT * FROM entries")) {
+ if (!kore_pgsql_query(&sql, "SELECT id, title, body FROM entries")) {
kore_pgsql_logerror(&sql);
goto out;
}
@@ -68,9 +65,13 @@ int page(struct http_request *req)
* Iterate over the result and dump it to somewhere.
*/
rows = kore_pgsql_ntuples(&sql);
- for (i = 0; i < rows; i++) {
- name = kore_pgsql_getvalue(&sql, i, 0);
- kore_log(LOG_NOTICE, "name: '%s'", name);
+ for (row = 0; row < rows; row++) {
+ id = kore_pgsql_getvalue(&sql, row, 0);
+ title = kore_pgsql_getvalue(&sql, row, 1);
+ body = kore_pgsql_getvalue(&sql, row, 2);
+ kore_log(LOG_NOTICE, "id: '%s'", id);
+ kore_log(LOG_NOTICE, "title: '%s'", title);
+ kore_log(LOG_NOTICE, "body: '%s'", body);
}
out: ;