]>
Commit | Line | Data |
---|---|---|
ee9c93b9 JF |
1 | /* Minimal - the simplest thing that could possibly work |
2 | * Copyright (C) 2007 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* | |
6 | * Redistribution and use in source and binary | |
7 | * forms, with or without modification, are permitted | |
8 | * provided that the following conditions are met: | |
9 | * | |
10 | * 1. Redistributions of source code must retain the | |
11 | * above copyright notice, this list of conditions | |
12 | * and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the | |
14 | * above copyright notice, this list of conditions | |
15 | * and the following disclaimer in the documentation | |
16 | * and/or other materials provided with the | |
17 | * distribution. | |
18 | * 3. The name of the author may not be used to endorse | |
19 | * or promote products derived from this software | |
20 | * without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
24 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
33 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
35 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
64c5d5aa JF |
38 | #ifndef MINIMAL_SQLITE3_H |
39 | #define MINIMAL_SQLITE3_H | |
40 | ||
76975d66 JF |
41 | #include <sqlite3.h> |
42 | #include <string.h> | |
43 | ||
66b708b1 JF |
44 | #define _sqlcall(expr) ({ \ |
45 | __typeof__(expr) _value = (expr); \ | |
46 | if (_value != 0 && (_value < 100 || _value >= 200)) \ | |
47 | _assert(false, "_sqlcall(%u:%s): %s\n", _value, #expr, sqlite3_errmsg(database_)); \ | |
48 | _value; \ | |
49 | }) | |
76975d66 JF |
50 | |
51 | int sqlite3_bind_string(sqlite3_stmt *stmt, int n, const char *value) { | |
52 | if (value == NULL) | |
53 | return sqlite3_bind_null(stmt, n); | |
54 | else | |
55 | return sqlite3_bind_text(stmt, n, strdup(value), -1, &free); | |
56 | } | |
57 | ||
58 | int sqlite3_bind_boolean(sqlite3_stmt *stmt, int n, bool value) { | |
59 | return sqlite3_bind_int(stmt, n, value ? 1 : 0); | |
60 | } | |
61 | ||
62 | char *sqlite3_column_string(sqlite3_stmt *stmt, int n) { | |
63 | const unsigned char *value = sqlite3_column_text(stmt, n); | |
64 | return value == NULL ? NULL : strdup((const char *) value); | |
65 | } | |
66 | ||
67 | bool sqlite3_column_boolean(sqlite3_stmt *stmt, int n) { | |
68 | return sqlite3_column_int(stmt, n) != 0; | |
69 | } | |
64c5d5aa JF |
70 | |
71 | #endif/*MINIMAL_SQLITE3_H*/ |