]>
Commit | Line | Data |
---|---|---|
76975d66 JF |
1 | #include <sqlite3.h> |
2 | #include <string.h> | |
3 | ||
4 | #define sqlcall(expr) \ | |
5 | do { \ | |
6 | int _value = (expr); \ | |
7 | if (_value == 0 || (_value >= 100 && _value < 200)) \ | |
8 | break; \ | |
9 | fprintf(stderr, "%s(%u): sqlcall(%u:%s): %s\n", __FILE__, __LINE__, _value, #expr, sqlite3_errmsg(database_)); \ | |
10 | exit(1); \ | |
11 | } while (false) | |
12 | ||
13 | int sqlite3_bind_string(sqlite3_stmt *stmt, int n, const char *value) { | |
14 | if (value == NULL) | |
15 | return sqlite3_bind_null(stmt, n); | |
16 | else | |
17 | return sqlite3_bind_text(stmt, n, strdup(value), -1, &free); | |
18 | } | |
19 | ||
20 | int sqlite3_bind_boolean(sqlite3_stmt *stmt, int n, bool value) { | |
21 | return sqlite3_bind_int(stmt, n, value ? 1 : 0); | |
22 | } | |
23 | ||
24 | char *sqlite3_column_string(sqlite3_stmt *stmt, int n) { | |
25 | const unsigned char *value = sqlite3_column_text(stmt, n); | |
26 | return value == NULL ? NULL : strdup((const char *) value); | |
27 | } | |
28 | ||
29 | bool sqlite3_column_boolean(sqlite3_stmt *stmt, int n) { | |
30 | return sqlite3_column_int(stmt, n) != 0; | |
31 | } |