Commit a02d0a73 authored by Shawn Webb's avatar Shawn Webb
Browse files

Provide string and integer column accessors


Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
parent 8400d7e1
......@@ -359,6 +359,26 @@ const ucl_object_t *lattutil_sqlite_get_row(lattutil_sqlite_query_t *, size_t);
*/
const ucl_object_t *lattutil_sqlite_get_column(const ucl_object_t *, size_t);
/**
* Return a column as a string
*
* @param The UCL object containing the row
* @param The integer column ID
* @return The string value of the column
*/
const char *lattutil_sqlite_get_column_string(const ucl_object_t *, size_t);
/**
* Return a column as a 64-bit signed integer
*
* @param The UCL object containing the row
* @param The integer column ID
* @param The default value if the column cannot be found or converted
* to int64_t
* @return The integer value of the column or the default value
*/
int64_t lattutil_sqlite_get_column_int(const ucl_object_t *, size_t, int64_t);
#ifdef _lattutil_internal
ssize_t lattutil_log_syslog_debug(lattutil_log_t *, int,
const char *, ...);
......
......@@ -345,6 +345,42 @@ lattutil_sqlite_get_column(const ucl_object_t *row, size_t colid)
return (NULL);
}
EXPORTED_SYM
const char *
lattutil_sqlite_get_column_string(const ucl_object_t *row, size_t colid)
{
const ucl_object_t *obj;
if (row == NULL) {
return (NULL);
}
obj = lattutil_sqlite_get_column(row, colid);
if (obj != NULL) {
return (ucl_object_tostring(obj));
}
return (NULL);
}
EXPORTED_SYM
int64_t
lattutil_sqlite_get_column_int(const ucl_object_t *row, size_t colid, int64_t def)
{
const ucl_object_t *obj;
if (row == NULL) {
return (def);
}
obj = lattutil_sqlite_get_column(row, colid);
if (obj != NULL) {
return (ucl_object_toint(obj));
}
return (def);
}
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