Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
continue adding to sqlite3 example
Browse files Browse the repository at this point in the history
goatshriek committed Nov 23, 2023
1 parent 24c353c commit 1911df7
Showing 2 changed files with 39 additions and 9 deletions.
33 changes: 32 additions & 1 deletion docs/examples/sqlite3/README.md
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ values.
You might have noticed that the default SQL statement uses several named SQL
parameters for the entry values. You can use these in your custom SQL as well!
They are resolved by name (position is ignored) and if a name is not present
in the SQL then it is simply left out. In addition to the parameters listed in
in the SQL then it is simply left out. In addition to the parameters used in
the default statement, there are a few more available if you need them:
* `$facility` is the facility portion of the entry as an integer. This is
@@ -109,8 +109,39 @@ For this example, lets say that you have your own log table with the following
schema, and you want entries to go into it instead.
```sql
CREATE TABLE card_logs (
log_id INTEGER PRIMARY KEY,
facility INTEGER NOT NULL,
severity INTEGER NOT NULL,
timestamp TEXT,
structured_data TEXT,
message TEXT
);
```
We've made a few adjustments to the default schema here. Of course, there is a
different table name to be more descriptive about the type of logs that are in
the table. We've also broken the prival into it's separate parts, so that it is
easier to filter entries using SQL without needing to parse the prival first.
Finally, we've cut the columns down to specific things that our application
cares about.
The default insert statement won't work here of course, so we'll need to write
a new one to fit. This is pretty straightforward:
```sql
INSERT INTO card_logs ( facility, severity, timestamp, structured_data,
message )
VALUES ( $facility, $severity, $timestamp, $structured_data, $message )
```
Now we can start putting logs into our new table! This time, we'll include some
structured data in our entry as well.
```c
```
# Custom Prepared SQL Statements
TODO fill in
15 changes: 7 additions & 8 deletions test/function/target/sqlite3.cpp
Original file line number Diff line number Diff line change
@@ -402,14 +402,13 @@ namespace {
"message TEXT)";
sqlite3_stmt *create_stmt = NULL;
int sql_result;
const char *insert_sql = "INSERT INTO l (prival, version,"
" timestamp, hostname, app_name,"
" procid, msgid, structured_data,"
" message) "
"VALUES ($prival, 1, $timestamp,"
" $hostname, $app_name, $procid,"
" $msgid, '-',"
" $message)";
const char *insert_sql = "INSERT INTO l ( prival, version, timestamp,"
" hostname, app_name, procid,"
" msgid, structured_data,"
" message ) "
"VALUES ( $prival, 1, $timestamp, $hostname,"
" $app_name, $procid, $msgid, '-',"
" $message )";
const struct stumpless_target *result;
const char *current_sql;
int add_result;

0 comments on commit 1911df7

Please sign in to comment.