Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Shawn Webb
liblattutil
Commits
a02d0a73
Commit
a02d0a73
authored
Jul 18, 2021
by
Shawn Webb
Browse files
Provide string and integer column accessors
Signed-off-by:
Shawn Webb
<
shawn.webb@hardenedbsd.org
>
parent
8400d7e1
Changes
2
Show whitespace changes
Inline
Side-by-side
include/liblattutil.h
View file @
a02d0a73
...
...
@@ -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
*
,
...);
...
...
src/sqlite3.c
View file @
a02d0a73
...
...
@@ -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
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment