Commit 4078182f authored by Shawn Webb's avatar Shawn Webb
Browse files

Document the SQLit3 abstraction API


Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
parent a178b793
......@@ -25,7 +25,7 @@ Do not terminate the log message with a newline.
Sample syslog logging code:
```
```C
#include <liblattutil.h>
lattutil_log_t *logp;
......@@ -45,3 +45,46 @@ logp->ll_log_info(logp, 2, "This debugging message will get ignored"
logp->ll_log_info(logp, 5, "This will get logged");
lattutil_log_free(&logp);
```
## SQLite3 Queries
liblattutil has a SQLite3 abstraction layer. Right now, it only
supports those data types that I myself care about. I'm open to
accepting patches for supporting unimplemented data types.
The sqlite3 APIs also support the logging APIs described above. When
creating a sqlite3 context, you have the option of specifying a
logging context object. Error, info, and debugging messages will be
reported through the logging object.
Sample sqlite3 code:
```C
#include <liblattutil.h>
lattutil_sqlite_query_t *query;
lattutil_sqlite_ctx_t *ctx;
const ucl_object_t *row;
ctx = lattutil_sqlite_ctx_new("/tmp/db.sqlite3", NULL, 0);
if (ctx == NULL) {
Fatal();
}
query = lattutil_sqlite_prepare(ctx, "SELECT id FROM table WHERE id = ?");
if (query == NULL) {
Fatal();
}
if (!lattutil_sqlite_bind_int(query, 1, 1234)) {
Fatal();
}
if (!lattutil_sqlite_exec(query)) {
Fatal();
}
row = lattutil_sqlite_get_row(query, 0);
printf("ID: %ld\n", lattutil_sqlite_get_column_int(row, 0, 0));
```
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