From ab9ef24316b06948065f3228d5e951e88ac85032 Mon Sep 17 00:00:00 2001 From: semsevens Date: Sat, 9 Jul 2016 16:43:22 +0800 Subject: [PATCH] bool argument support for lambda function call --- hdr/sqlite_modern_cpp.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hdr/sqlite_modern_cpp.h b/hdr/sqlite_modern_cpp.h index 07f99772..d3f2b15a 100644 --- a/hdr/sqlite_modern_cpp.h +++ b/hdr/sqlite_modern_cpp.h @@ -224,6 +224,8 @@ namespace sqlite { template friend void get_col_from_db(database_binder& db, int inx, std::unique_ptr& val); template friend T operator++(database_binder& db, int); // for nontemplate functions + friend database_binder& operator<<(database_binder& db, const bool& val); + friend void get_col_from_db(database_binder& db, int inx, bool& val); friend database_binder& operator<<(database_binder& db, const int& val); friend void get_col_from_db(database_binder& db, int inx, int& val); friend database_binder& operator <<(database_binder& db, const sqlite_int64& val); @@ -382,6 +384,23 @@ namespace sqlite { } }; + // bool + inline database_binder& operator<<(database_binder& db, const bool& val) { + int hresult; + if((hresult = sqlite3_bind_int(db._stmt.get(), db._inx, val)) != SQLITE_OK) { + exceptions::throw_sqlite_error(hresult); + } + ++db._inx; + return db; + } + inline void get_col_from_db(database_binder& db, int inx, bool& val) { + if(sqlite3_column_type(db._stmt.get(), inx) == SQLITE_NULL) { + val = false; + } else { + val = sqlite3_column_int(db._stmt.get(), inx); + } + } + // int inline database_binder& operator<<(database_binder& db, const int& val) { int hresult;