diff options
author | June McEnroe <june@causal.agency> | 2019-12-17 17:27:59 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-17 17:27:59 -0500 |
commit | 6ef71b37cdcb04f983aeb89f94cbf0b5a7768a80 (patch) | |
tree | a83411ece399dc128273e58f8fe01a1c45b4f482 /database.h | |
parent | Handle ISUPPORT (diff) | |
download | litterbox-6ef71b37cdcb04f983aeb89f94cbf0b5a7768a80.tar.gz litterbox-6ef71b37cdcb04f983aeb89f94cbf0b5a7768a80.zip |
Use parameter names for all binds
Diffstat (limited to 'database.h')
-rw-r--r-- | database.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/database.h b/database.h index 6d705db..4ca9c81 100644 --- a/database.h +++ b/database.h @@ -108,8 +108,10 @@ dbPrepare(sqlite3 *db, unsigned flags, const char *sql) { } static inline void -dbBindText(sqlite3_stmt *stmt, int param, const char *text, int len) { - int error = sqlite3_bind_text(stmt, param, text, len, NULL); +dbBindText(sqlite3_stmt *stmt, const char *param, const char *text, int len) { + int index = sqlite3_bind_parameter_index(stmt, param); + if (!index) errx(EX_SOFTWARE, "no such parameter %s", param); + int error = sqlite3_bind_text(stmt, index, text, len, NULL); if (!error) return; errx( EX_SOFTWARE, "sqlite3_bind_text: %s", @@ -117,8 +119,11 @@ dbBindText(sqlite3_stmt *stmt, int param, const char *text, int len) { ); } -static inline void dbBindInt(sqlite3_stmt *stmt, int param, int64_t value) { - int error = sqlite3_bind_int64(stmt, param, value); +static inline void +dbBindInt(sqlite3_stmt *stmt, const char *param, int64_t value) { + int index = sqlite3_bind_parameter_index(stmt, param); + if (!index) errx(EX_SOFTWARE, "no such parameter %s", param); + int error = sqlite3_bind_int64(stmt, index, value); if (!error) return; errx( EX_SOFTWARE, "sqlite3_bind_int64: %s", |