Commit 85ffd025 authored by Shawn Webb's avatar Shawn Webb
Browse files

Add row and column accessors



This just gets the rows and columns by IDs. A follow-up commit will
provide a name-based column accessor.
Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
parent fe1006f9
......@@ -311,6 +311,24 @@ bool lattutil_sqlite_bind_time(lattutil_sqlite_query_t *, int, time_t);
*/
bool lattutil_sqlite_exec(lattutil_sqlite_query_t *);
/**
* Look up a row in the query result
*
* @param The query object
* @param The integer row ID
* @return UCL object of the row
*/
const ucl_object_t *lattutil_sqlite_get_row(lattutil_sqlite_query_t *, size_t);
/**
* Look up a column in a row object
*
* @param The UCL object containing the row
* @param The integer column ID
* @return UCL object of the column
*/
const ucl_object_t *lattutil_sqlite_get_column(const ucl_object_t *, size_t);
#ifdef _lattutil_internal
ssize_t lattutil_log_syslog_err(lattutil_log_t *, int,
const char *, ...);
......
......@@ -284,6 +284,53 @@ end:
return (ret);
}
EXPORTED_SYM
const ucl_object_t *
lattutil_sqlite_get_row(lattutil_sqlite_query_t *query, size_t rowid)
{
const ucl_object_t *obj;
ucl_object_iter_t it;
size_t i;
if (query == NULL) {
return (NULL);
}
it = NULL;
i = 0;
while ((obj = ucl_iterate_object(query->lsq_result.lsr_rows, &it,
true))) {
if (i++ == rowid) {
return (obj);
}
}
return (NULL);
}
EXPORTED_SYM
const ucl_object_t *
lattutil_sqlite_get_column(const ucl_object_t *row, size_t colid)
{
const ucl_object_t *obj;
ucl_object_iter_t it;
size_t i;
if (row == NULL) {
return (NULL);
}
it = NULL;
i = 0;
while ((obj = ucl_iterate_object(row, &it, true))) {
if (i++ == colid) {
return (obj);
}
}
return (NULL);
}
static bool
_lattutil_sqlite_add_row(lattutil_sqlite_query_t *query)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment