13. Add/Remove Page
13.1. add
<<argparse_entries>>=
{"add", 3, p_add, NULL},
<<static_funcdefs>>=
static int p_add(int argc, char *argv[]);
<<functions>>=
static int p_add(int argc, char *argv[])
{
weewiki_d ww;
sqlite3 *db;
sqlite3_stmt *stmt;
int rc;
rc = 0;
if (argc < 2) {
fprintf(stderr,
"Usage: %s key\n",
argv[0]);
return 1;
}
weewiki_init(&ww);
weewiki_open(&ww, weewiki_dbname_get());
db = ww.db;
sqlite3_prepare_v2(db,
"INSERT INTO wiki"
"(key)\n"
"VALUES(?1);",
-1,
&stmt,
NULL);
sqlite3_bind_text(stmt, 1, argv[1], -1, NULL);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
rc = 1;
}
sqlite3_finalize(stmt);
weewiki_close(&ww);
weewiki_clean(&ww);
return rc;
}
13.2. del
<<argparse_entries>>=
{"del", 3, p_del, NULL},
<<static_funcdefs>>=
static int p_del(int argc, char *argv[]);
<<functions>>=
static int p_del(int argc, char *argv[])
{
weewiki_d ww;
sqlite3 *db;
sqlite3_stmt *stmt;
int rc;
rc = 0;
if (argc < 2) {
fprintf(stderr,
"Usage: %s key\n",
argv[0]);
return 1;
}
weewiki_init(&ww);
weewiki_open(&ww, weewiki_dbname_get());
db = ww.db;
sqlite3_prepare_v2(db,
"DELETE FROM wiki "
"WHERE (key ==?1);",
-1,
&stmt,
NULL);
sqlite3_bind_text(stmt, 1, argv[1], -1, NULL);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
rc = 1;
}
sqlite3_finalize(stmt);
sqlite3_prepare_v2(db,
"DELETE FROM wikilinks "
"WHERE (key ==?1);",
-1,
&stmt,
NULL);
sqlite3_bind_text(stmt, 1, argv[1], -1, NULL);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
rc = 1;
}
sqlite3_finalize(stmt);
weewiki_close(&ww);
weewiki_clean(&ww);
return rc;
}
prev | home | next