diff --git a/sqlite3cpp.cpp b/sqlite3cpp.cpp old mode 100644 new mode 100755 index 28cb27b..da7f28a --- a/sqlite3cpp.cpp +++ b/sqlite3cpp.cpp @@ -45,7 +45,7 @@ namespace sqlite3cpp { namespace detail { // An tag type for row iter session struct session {}; -} // namespace detail +} // namespace detail /** * row_iter impl @@ -61,10 +61,8 @@ row_iter::row_iter(cursor &csr, std::weak_ptr session) noexcept } row_iter &row_iter::operator++() { - if (!m_session.expired()) - m_csr->step(); - if (m_session.expired()) - m_csr = nullptr; + if (!m_session.expired()) m_csr->step(); + if (m_session.expired()) m_csr = nullptr; return *this; } @@ -115,13 +113,12 @@ void cursor::step() { } row_iter cursor::begin() noexcept { - if (!m_stmt) - return {}; + if (!m_stmt) return {}; // NOTE(acer): There is actually a redundant reset as we invoke // |execute().begin()|. It's possible to be eliminated, though I keep it for - // ensuring non-query SQL can be executed right away after calling |execute()|. - // Besides, results of previous |step()| should be cached by sqlite3 s.t. - // performance penality would be minor. + // ensuring non-query SQL can be executed right away after calling + // |execute()|. Besides, results of previous |step()| should be cached by + // sqlite3 s.t. performance penality would be minor. m_session.reset((void *)new detail::session, [](void *s) { delete (detail::session *)s; }); sqlite3_reset(m_stmt.get()); @@ -148,9 +145,7 @@ transaction::~transaction() { } } -void transaction::commit() noexcept { - m_params.end_sql = "end"; -} +void transaction::commit() noexcept { m_params.end_sql = "end"; } /** * database impl diff --git a/sqlite3cpp.h b/sqlite3cpp.h old mode 100644 new mode 100755 index 4be0ca5..3e949ec --- a/sqlite3cpp.h +++ b/sqlite3cpp.h @@ -195,7 +195,7 @@ struct SQLITE3CPP_EXPORT transaction { // will be executed right away. The |end_sql| will be executed in // |~transaction()|. transaction(database &db, params_t const ¶ms); - transaction(transaction&&) = default; + transaction(transaction &&) = default; // Commit or rollback this transaction per |params|. Default to rollback. ~transaction(); @@ -262,15 +262,15 @@ struct SQLITE3CPP_EXPORT database { std::string version() const; private: - using xfunc_t = std::function; - using xfinal_t = std::function; - using xreset_t = std::function; - - struct aggregate_wrapper_t { - xfunc_t step; - xfinal_t fin; - xreset_t reset; - xreset_t release; + using xfunc_t = std::function; + using xfinal_t = std::function; + using xreset_t = std::function; + + struct aggregate_wrapper_t { + xfunc_t step; + xfinal_t fin; + xreset_t reset; + xreset_t release; }; static void forward(sqlite3_context *ctx, int argc, sqlite3_value **argv); diff --git a/sqlite3cpp.ipp b/sqlite3cpp.ipp old mode 100644 new mode 100755 index 30d01ef..0aee02c --- a/sqlite3cpp.ipp +++ b/sqlite3cpp.ipp @@ -37,20 +37,20 @@ namespace detail { template struct placeholder_tmpl {}; -template +template using indexes = std::integer_sequence; -template +template using make_indexes_t = std::make_integer_sequence; -} -} // namespace sqlite3cpp::detail +} // namespace detail +} // namespace sqlite3cpp // custome placeholders namespace std { template struct is_placeholder> : integral_constant {}; -} +} // namespace std namespace sqlite3cpp { namespace detail { @@ -94,11 +94,10 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *, int index, inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index, std::string &val) { - char const* res = (char const *)sqlite3_column_text(stmt, index); + char const *res = (char const *)sqlite3_column_text(stmt, index); if (!res) { int ec = sqlite3_errcode(db); - if (ec != SQLITE_OK) - throw error(ec); + if (ec != SQLITE_OK) throw error(ec); } val.assign(res, sqlite3_column_bytes(stmt, index)); } @@ -108,8 +107,7 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index, char const *res = (char const *)sqlite3_column_text(stmt, index); if (!res) { int ec = sqlite3_errcode(db); - if (ec != SQLITE_OK) - throw error(ec); + if (ec != SQLITE_OK) throw error(ec); } val = std::string_view{ (char const *)sqlite3_column_text(stmt, index), @@ -118,11 +116,10 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index, inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index, std::optional &val) { - char const* res = (char const *)sqlite3_column_text(stmt, index); + char const *res = (char const *)sqlite3_column_text(stmt, index); if (!res) { int ec = sqlite3_errcode(db); - if (ec != SQLITE_OK) - val.reset(); + if (ec != SQLITE_OK) val.reset(); } val = std::string{res, (std::string::size_type)sqlite3_column_bytes(stmt, index)}; @@ -133,8 +130,7 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index, char const *res = (char const *)sqlite3_column_text(stmt, index); if (!res) { int ec = sqlite3_errcode(db); - if (ec != SQLITE_OK) - val.reset(); + if (ec != SQLITE_OK) val.reset(); } val = std::string_view{ res, (std::string_view::size_type)sqlite3_column_bytes(stmt, index)}; @@ -172,8 +168,7 @@ inline int bind_val(sqlite3_stmt *stmt, int index, std::nullptr_t _) { template void bind_to_stmt(sqlite3_stmt *stmt, int index, T &&val, Args &&... args) { int ec = 0; - if (0 != (ec = bind_val(stmt, index, std::forward(val)))) - throw error(ec); + if (0 != (ec = bind_val(stmt, index, std::forward(val)))) throw error(ec); bind_to_stmt(stmt, index + 1, std::forward(args)...); } @@ -200,7 +195,8 @@ inline std::string get(Type, sqlite3_value **v, int const index) { (size_t)sqlite3_value_bytes(v[index])); } -inline std::string_view get(Type, sqlite3_value **v, int const index) { +inline std::string_view get(Type, sqlite3_value **v, + int const index) { return std::string_view((char const *)sqlite3_value_text(v[index]), (size_t)sqlite3_value_bytes(v[index])); } @@ -296,8 +292,8 @@ typename function_traits::f_type bind_this(F f, C *this_) { using traits = function_traits; return bind_this(f, this_, make_indexes_t{}); } -} -} // namespace sqlite3cpp::detail +} // namespace detail +} // namespace sqlite3cpp namespace sqlite3cpp { @@ -362,8 +358,8 @@ void database::create_scalar(std::string const &name, FUNC func, int flags) { template void database::create_aggregate(std::string const &name, int flags) { - using detail::make_invoker; using detail::bind_this; + using detail::make_invoker; using detail::result; using traits = detail::function_traits;