From: Jay Freeman (saurik) Date: Mon, 26 Nov 2007 02:13:40 +0000 (+0000) Subject: Almost forgot this minimality. X-Git-Url: https://git.saurik.com/minimal.git/commitdiff_plain/76975d6677704758eefc37d494040ec6dc84d3bf?ds=sidebyside Almost forgot this minimality. --- diff --git a/sqlite3.h b/sqlite3.h new file mode 100644 index 0000000..049521d --- /dev/null +++ b/sqlite3.h @@ -0,0 +1,31 @@ +#include +#include + +#define sqlcall(expr) \ + do { \ + int _value = (expr); \ + if (_value == 0 || (_value >= 100 && _value < 200)) \ + break; \ + fprintf(stderr, "%s(%u): sqlcall(%u:%s): %s\n", __FILE__, __LINE__, _value, #expr, sqlite3_errmsg(database_)); \ + exit(1); \ + } while (false) + +int sqlite3_bind_string(sqlite3_stmt *stmt, int n, const char *value) { + if (value == NULL) + return sqlite3_bind_null(stmt, n); + else + return sqlite3_bind_text(stmt, n, strdup(value), -1, &free); +} + +int sqlite3_bind_boolean(sqlite3_stmt *stmt, int n, bool value) { + return sqlite3_bind_int(stmt, n, value ? 1 : 0); +} + +char *sqlite3_column_string(sqlite3_stmt *stmt, int n) { + const unsigned char *value = sqlite3_column_text(stmt, n); + return value == NULL ? NULL : strdup((const char *) value); +} + +bool sqlite3_column_boolean(sqlite3_stmt *stmt, int n) { + return sqlite3_column_int(stmt, n) != 0; +}