summaryrefslogtreecommitdiff
path: root/lib/dbStmt.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-06-03 00:17:28 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-06-03 00:17:39 +0100
commit6e726340e23a97480b17065a633c36a9ba53cf14 (patch)
treecd9f161a542f85e5cae9119e43c870651431d0ca /lib/dbStmt.h
parentAdd event source ptr typedef (diff)
downloadmygrate-6e726340e23a97480b17065a633c36a9ba53cf14.tar.bz2
mygrate-6e726340e23a97480b17065a633c36a9ba53cf14.tar.xz
mygrate-6e726340e23a97480b17065a633c36a9ba53cf14.zip
Determine parameter mode at point of call by DB type property
It's still constexpr, so that's all good.
Diffstat (limited to 'lib/dbStmt.h')
-rw-r--r--lib/dbStmt.h17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/dbStmt.h b/lib/dbStmt.h
index 81621de..80dbd71 100644
--- a/lib/dbStmt.h
+++ b/lib/dbStmt.h
@@ -9,17 +9,16 @@
#include <type_traits>
namespace MyGrate {
- class DbConn;
- enum class ParamMode { None, DollarNum, QMark };
-
- template<Support::basic_fixed_string S, ParamMode pm = ParamMode::None> class DbStmt {
+ template<Support::basic_fixed_string S> class DbStmt {
public:
// This don't account for common table expressions, hopefully won't need those :)
static constexpr auto isSelect {S.v().starts_with("SELECT") || S.v().starts_with("SHOW")
|| S.v().find("RETURNING") != std::string_view::npos};
// These don't account for string literals, which we'd prefer to avoid anyway :)
- static constexpr auto paramCount {[]() -> std::size_t {
+ static constexpr std::size_t
+ paramCount(ParamMode pm)
+ {
switch (pm) {
case ParamMode::None:
return 0LU;
@@ -42,15 +41,15 @@ namespace MyGrate {
return c == '?';
});
}
- }()};
+ }
using Return = std::conditional_t<isSelect, RecordSetPtr, std::size_t>;
- template<typename... P>
+ template<typename ConnType, typename... P>
static Return
- execute(DbConn * c, P &&... p)
+ execute(ConnType * c, P &&... p)
{
- static_assert(sizeof...(P) == paramCount);
+ static_assert(sizeof...(P) == paramCount(ConnType::paramMode));
auto stmt {c->prepare(S, sizeof...(P))};
stmt->execute({std::forward<P...>(p)...});
if constexpr (isSelect) {