-/* $Id: mandocdb.c,v 1.93 2014/04/16 18:59:38 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.94 2014/04/16 21:35:48 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
struct mpage {
struct inodev inodev; /* used for hashing routine */
- int64_t recno; /* id in mpages SQL table */
+ int64_t pageid; /* pageid in mpages SQL table */
enum form form; /* format from file content */
char *sec; /* section from file content */
char *arch; /* architecture from file content */
* to the target.
*/
- if (mpage_dest->recno)
+ if (mpage_dest->pageid)
dbadd_mlink(mlink);
if (NULL == mlink->next)
SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mlink->dsec);
SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mlink->arch);
SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mlink->name);
- SQL_BIND_INT64(stmts[STMT_INSERT_LINK], i, mlink->mpage->recno);
+ SQL_BIND_INT64(stmts[STMT_INSERT_LINK], i, mlink->mpage->pageid);
SQL_STEP(stmts[STMT_INSERT_LINK]);
sqlite3_reset(stmts[STMT_INSERT_LINK]);
}
SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->desc);
SQL_BIND_INT(stmts[STMT_INSERT_PAGE], i, FORM_SRC == mpage->form);
SQL_STEP(stmts[STMT_INSERT_PAGE]);
- mpage->recno = sqlite3_last_insert_rowid(db);
+ mpage->pageid = sqlite3_last_insert_rowid(db);
sqlite3_reset(stmts[STMT_INSERT_PAGE]);
while (NULL != mlink) {
i = 1;
SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, key->mask);
SQL_BIND_TEXT(stmts[STMT_INSERT_NAME], i, key->rendered);
- SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, mpage->recno);
+ SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, mpage->pageid);
SQL_STEP(stmts[STMT_INSERT_NAME]);
sqlite3_reset(stmts[STMT_INSERT_NAME]);
if (key->rendered != key->key)
i = 1;
SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask);
SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->rendered);
- SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, mpage->recno);
+ SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, mpage->pageid);
SQL_STEP(stmts[STMT_INSERT_KEY]);
sqlite3_reset(stmts[STMT_INSERT_KEY]);
if (key->rendered != key->key)
sql = "CREATE TABLE \"mpages\" (\n"
" \"desc\" TEXT NOT NULL,\n"
" \"form\" INTEGER NOT NULL,\n"
- " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"
+ " \"pageid\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n"
");\n"
"\n"
"CREATE TABLE \"mlinks\" (\n"
" \"sec\" TEXT NOT NULL,\n"
" \"arch\" TEXT NOT NULL,\n"
" \"name\" TEXT NOT NULL,\n"
- " \"pageid\" INTEGER NOT NULL REFERENCES mpages(id) "
+ " \"pageid\" INTEGER NOT NULL REFERENCES mpages(pageid) "
"ON DELETE CASCADE\n"
");\n"
"CREATE INDEX mlinks_pageid_idx ON mlinks (pageid);\n"
"CREATE TABLE \"names\" (\n"
" \"bits\" INTEGER NOT NULL,\n"
" \"name\" TEXT NOT NULL,\n"
- " \"pageid\" INTEGER NOT NULL REFERENCES mpages(id) "
+ " \"pageid\" INTEGER NOT NULL REFERENCES mpages(pageid) "
"ON DELETE CASCADE\n"
");\n"
"\n"
"CREATE TABLE \"keys\" (\n"
" \"bits\" INTEGER NOT NULL,\n"
" \"key\" TEXT NOT NULL,\n"
- " \"pageid\" INTEGER NOT NULL REFERENCES mpages(id) "
+ " \"pageid\" INTEGER NOT NULL REFERENCES mpages(pageid) "
"ON DELETE CASCADE\n"
");\n"
"CREATE INDEX keys_pageid_idx ON keys (pageid);\n";
prepare_statements:
SQL_EXEC("PRAGMA foreign_keys = ON");
- sql = "DELETE FROM mpages WHERE id IN "
+ sql = "DELETE FROM mpages WHERE pageid IN "
"(SELECT pageid FROM mlinks WHERE "
"sec=? AND arch=? AND name=?)";
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE_PAGE], NULL);
-/* $Id: mansearch.c,v 1.21 2014/04/16 00:33:24 schwarze Exp $ */
+/* $Id: mansearch.c,v 1.22 2014/04/16 21:35:48 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
};
struct match {
- uint64_t id; /* identifier in database */
+ uint64_t pageid; /* identifier in database */
char *desc; /* manual page description */
int form; /* 0 == catpage */
};
struct manpage **res, size_t *sz)
{
int fd, rc, c, indexbit;
- int64_t id;
+ int64_t pageid;
uint64_t outbit, iterbit;
char buf[PATH_MAX];
char *sql;
info.halloc = hash_halloc;
info.alloc = hash_alloc;
info.hfree = hash_free;
- info.key_offset = offsetof(struct match, id);
+ info.key_offset = offsetof(struct match, pageid);
*sz = cur = maxres = 0;
sql = NULL;
* distribution of buckets in the table.
*/
while (SQLITE_ROW == (c = sqlite3_step(s))) {
- id = sqlite3_column_int64(s, 2);
+ pageid = sqlite3_column_int64(s, 2);
idx = ohash_lookup_memory
- (&htab, (char *)&id,
- sizeof(uint64_t), (uint32_t)id);
+ (&htab, (char *)&pageid,
+ sizeof(uint64_t), (uint32_t)pageid);
if (NULL != ohash_find(&htab, idx))
continue;
mp = mandoc_calloc(1, sizeof(struct match));
- mp->id = id;
+ mp->pageid = pageid;
mp->form = sqlite3_column_int(s, 1);
if (TYPE_Nd == outbit)
mp->desc = mandoc_strdup(
}
mpage = *res + cur;
mpage->form = mp->form;
- buildnames(mpage, db, s, mp->id,
+ buildnames(mpage, db, s, mp->pageid,
paths->paths[i], mp->form);
mpage->output = TYPE_Nd & outbit ?
mp->desc : outbit ?
- buildoutput(db, s2, mp->id, outbit) : NULL;
+ buildoutput(db, s2, mp->pageid, outbit) : NULL;
free(mp);
cur++;
static void
buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s,
- uint64_t id, const char *path, int form)
+ uint64_t pageid, const char *path, int form)
{
char *newnames, *prevsec, *prevarch;
const char *oldnames, *sep1, *name, *sec, *sep2, *arch, *fsec;
mpage->names = NULL;
prevsec = prevarch = NULL;
i = 1;
- SQL_BIND_INT64(db, s, i, id);
+ SQL_BIND_INT64(db, s, i, pageid);
while (SQLITE_ROW == (c = sqlite3_step(s))) {
/* Decide whether we already have some names. */
}
static char *
-buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t id, uint64_t outbit)
+buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t pageid, uint64_t outbit)
{
char *output, *newoutput;
const char *oldoutput, *sep1, *data;
output = NULL;
i = 1;
- SQL_BIND_INT64(db, s, i, id);
+ SQL_BIND_INT64(db, s, i, pageid);
SQL_BIND_INT64(db, s, i, outbit);
while (SQLITE_ROW == (c = sqlite3_step(s))) {
if (NULL == output) {
: "desc MATCH ?")
: TYPE_Nm == e->bits
? (NULL == e->substr
- ? "id IN (SELECT pageid FROM names "
+ ? "pageid IN (SELECT pageid FROM names "
"WHERE name REGEXP ?)"
- : "id IN (SELECT pageid FROM names "
+ : "pageid IN (SELECT pageid FROM names "
"WHERE name MATCH ?)")
: (NULL == e->substr
- ? "id IN (SELECT pageid FROM keys "
+ ? "pageid IN (SELECT pageid FROM keys "
"WHERE key REGEXP ? AND bits & ?)"
- : "id IN (SELECT pageid FROM keys "
+ : "pageid IN (SELECT pageid FROM keys "
"WHERE key MATCH ? AND bits & ?)"), 1);
if (e->close)
sql_append(&sql, &sz, ")", e->close);