~pbatch/weewiki

a02373c976116d5b1e23d85ae5586f3e9f1ff23e — paul 11 months ago b924bea
added ww-del-page

FossilOrigin-Name: 3826d0ba5f929b54fbe0754d8725beb9110ea5cf37ec60b5b0c1db87337baa8f
2 files changed, 61 insertions(+), 0 deletions(-)

M jan.org
M weewiki.org
M jan.org => jan.org +28 -0
@@ 187,6 187,10 @@ void weewiki_janet_cfuns(JanetTable *env)
              janet_wrap_cfunction(cfun_ww_add_page),
              NULL);
    janet_def(env,
              "ww-del-page",
              janet_wrap_cfunction(cfun_ww_del_page),
              NULL);
    janet_def(env,
              "ww-add-link",
              janet_wrap_cfunction(cfun_ww_add_link),
              NULL);


@@ 335,6 339,30 @@ static Janet cfun_ww_add_page(int32_t argc, Janet *argv)
    return janet_wrap_nil();
}
#+END_SRC
** Delete Page
Deletes a Page from the database.

#+NAME: static_funcdefs
#+BEGIN_SRC c
static Janet cfun_ww_del_page(int32_t argc, Janet *argv);
#+END_SRC

#+NAME: functions
#+BEGIN_SRC c
static Janet cfun_ww_del_page(int32_t argc, Janet *argv)
{
    const char *key;
    weewiki_d *ww;

    janet_fixarity(argc, 1);
    key = (const char *)janet_getstring(argv, 0);
    ww = weewiki_get();

    weewiki_del_page(ww, key);

    return janet_wrap_nil();
}
#+END_SRC
** Add Link
Adds a link to the note. Note that the mtime will be set to
zero, so that the page is automatically pushed by default.

M weewiki.org => weewiki.org +33 -0
@@ 527,6 527,39 @@ void weewiki_add_page(weewiki_d *ww,
    sqlite3_finalize(stmt);
}
#+END_SRC
** Delete Page
#+NAME: funcdefs
#+BEGIN_SRC c
void weewiki_del_page(weewiki_d *ww, const char *key);
#+END_SRC

#+NAME: functions
#+BEGIN_SRC c
void weewiki_del_page(weewiki_d *ww, const char *key)
{
    sqlite3 *db;
    sqlite3_stmt *stmt;
    int rc;

    db = ww->db;

    sqlite3_prepare_v2(db,
                       "DELETE FROM wiki "
                       "WHERE (key ==?1);",
                       -1,
                       &stmt,
                       NULL);
    sqlite3_bind_text(stmt, 1, key, -1, NULL);
    rc = sqlite3_step(stmt);

    if (rc != SQLITE_DONE) {
        fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
        rc = 1;
    }

    sqlite3_finalize(stmt);
}
#+END_SRC
** Link Page
#+NAME: funcdefs
#+BEGIN_SRC c