1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include <assert.h>
#include <err.h>
#include <stdio.h>
#include "sqlite/sqlite3.h"
static const char *DATABASE = "booking.db";
int
main(void)
{
sqlite3 *db;
if (sqlite3_open(DATABASE, &db))
errx(1, "sqlite3_open: %s", sqlite3_errmsg(db));
const char *sql = "SELECT "
"datetime(start, 'unixepoch'), "
"datetime(end, 'unixepoch'), "
"(end-start)/60/60, "
"summary "
"FROM event "
"WHERE unixepoch()-6*3600 < start "
"AND summary IS NOT NULL "
"ORDER BY start";
sqlite3_stmt *stmt = NULL;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL))
errx(1, "sqlite3_prepare_v2: %s", sqlite3_errmsg(db));
for (;;) {
int step = sqlite3_step(stmt);
if (SQLITE_DONE == step)
break;
if (SQLITE_ROW != step)
errx(1, "sqlite3_step: %s", sqlite3_errmsg(db));
const unsigned char *summary = sqlite3_column_text(stmt, 3);
assert(summary);
printf("%s\n", summary);
}
sqlite3_close(db);
}
|