From 70643a9e4821bd11c3f363f1708fe420965467d1 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 28 Aug 2026 22:17:10 +0200 Subject: Format again --- server/src/sqlite3.cppm | 86 ++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'server/src/sqlite3.cppm') diff --git a/server/src/sqlite3.cppm b/server/src/sqlite3.cppm index 70f58c0..45366b8 100644 --- a/server/src/sqlite3.cppm +++ b/server/src/sqlite3.cppm @@ -18,7 +18,7 @@ class mutex_guard friend auto do_guarded(::sqlite3_mutex* mut, std::invocable auto f) - -> decltype(f(std::declval())); + -> decltype(f(std::declval())); public: mutex_guard(mutex_guard const&) = delete; @@ -29,13 +29,13 @@ private: }; auto do_guarded(::sqlite3_mutex* mut, std::invocable auto f) - -> decltype(f(std::declval())) + -> decltype(f(std::declval())) { return f(mutex_guard{mut}); } auto do_guarded(::sqlite3* dbc, std::invocable auto f) - -> decltype(f(std::declval())) + -> decltype(f(std::declval())) { return do_guarded(::sqlite3_db_mutex(dbc), f); } @@ -143,16 +143,16 @@ public: { ::sqlite3* dbc = ::sqlite3_db_handle(stmt_.get()); return do_guarded( - dbc, - [&](auto const& guard) -> bool - { - auto const s = ::sqlite3_step(stmt_.get()); - if (s == SQLITE_ROW) - return true; - if (s == SQLITE_DONE) - return false; - throw error{guard, s, dbc}; - }); + dbc, + [&](auto const& guard) -> bool + { + auto const s = ::sqlite3_step(stmt_.get()); + if (s == SQLITE_ROW) + return true; + if (s == SQLITE_DONE) + return false; + throw error{guard, s, dbc}; + }); } auto scan(scannable auto&... args) -> void @@ -162,7 +162,7 @@ public: throw std::logic_error{"got unexpected negative amount of columns"}; if (sizeof...(args) > *ncols) throw std::invalid_argument{ - "more scanning arguments provided than columns in result set" + "more scanning arguments provided than columns in result set" }; auto col = 0; (..., scan(col++, args)); @@ -192,15 +192,15 @@ public: auto text(std::string const& param_name, std::string_view str) -> void { int const i = - ::sqlite3_bind_parameter_index(stmt_.get(), param_name.c_str()); + ::sqlite3_bind_parameter_index(stmt_.get(), param_name.c_str()); if (i == 0) throw std::invalid_argument{std::format( - "bind: no parameter with name {} found", param_name)}; + "bind: no parameter with name {} found", param_name)}; auto str_size = util::int_from_size(str.size()); if (!str_size.has_value()) throw std::invalid_argument{"bind: provided text is too long"}; if (auto s = ::sqlite3_bind_text( - stmt_.get(), i, str.data(), *str_size, SQLITE_TRANSIENT); + stmt_.get(), i, str.data(), *str_size, SQLITE_TRANSIENT); s != SQLITE_OK) { throw error{s}; @@ -232,8 +232,8 @@ public: } [[nodiscard]] auto query( - std::string const& sql, - std::function const& bf = binder::noop) -> row_reader + std::string const& sql, + std::function const& bf = binder::noop) -> row_reader { ::sqlite3_stmt* pstmt = nullptr; char const* sql_tail = nullptr; @@ -242,31 +242,31 @@ public: || *sql_size >= std::numeric_limits::max() - 1) throw std::invalid_argument{"provided input text too large"}; do_guarded( - mut_, - [&](auto const& guard) -> void + mut_, + [&](auto const& guard) -> void + { + if (auto s = ::sqlite3_prepare_v2( + dbc_, sql.data(), *sql_size + 1, &pstmt, &sql_tail); + s != SQLITE_OK) { - if (auto s = ::sqlite3_prepare_v2( - dbc_, sql.data(), *sql_size + 1, &pstmt, &sql_tail); - s != SQLITE_OK) + if (pstmt != nullptr) { - if (pstmt != nullptr) - { - // Use contract_assert when having a compiler with - // contracts available - ::sqlite3_finalize(pstmt); - throw std::logic_error{ - "expected stmt to be null after failed preparation" - }; - } - throw error{guard, s, dbc_}; + // Use contract_assert when having a compiler with + // contracts available + ::sqlite3_finalize(pstmt); + throw std::logic_error{ + "expected stmt to be null after failed preparation" + }; } - }); + throw error{guard, s, dbc_}; + } + }); if (!pstmt) throw std::invalid_argument{"provided input text contains no SQL"}; auto stmt = statement{pstmt}; if (sql_tail && std::strlen(sql_tail) > 0) throw std::invalid_argument{ - "provided input text contains more than one SQL statement" + "provided input text contains more than one SQL statement" }; auto b = binder{stmt}; bf(b); @@ -274,8 +274,8 @@ public: } auto exec( - std::string const& sql, - std::function const& bf = binder::noop) -> void + std::string const& sql, + std::function const& bf = binder::noop) -> void { auto reader = query(sql, bf); while (reader.next()) @@ -289,16 +289,16 @@ export auto open(std::string const& filename) -> connection { ::sqlite3* dbc = nullptr; auto s = ::sqlite3_open_v2( - filename.c_str(), &dbc, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX - | SQLITE_OPEN_EXRESCODE, - nullptr); + filename.c_str(), &dbc, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX + | SQLITE_OPEN_EXRESCODE, + nullptr); if (s != SQLITE_OK) { if (dbc) { do_guarded( - dbc, [&](auto const& guard) -> void { throw error{guard, s, dbc}; }); + dbc, [&](auto const& guard) -> void { throw error{guard, s, dbc}; }); } else { -- cgit v1.3