diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-07-14 01:31:35 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-07-14 01:33:36 +0100 |
commit | 6fd16aeac962cd80a37307fa90e3eb9a7102330b (patch) | |
tree | c3808c9b8be7ef8e1dbb6e286466abfaa4063128 | |
parent | Wider type support for PQ bindings (diff) | |
download | mygrate-6fd16aeac962cd80a37307fa90e3eb9a7102330b.tar.bz2 mygrate-6fd16aeac962cd80a37307fa90e3eb9a7102330b.tar.xz mygrate-6fd16aeac962cd80a37307fa90e3eb9a7102330b.zip |
Pass bindings as a span, only wrap with initializer_list
-rw-r--r-- | lib/dbConn.h | 7 | ||||
-rw-r--r-- | lib/input/mysqlBindings.h | 3 | ||||
-rw-r--r-- | lib/input/mysqlStmt.cpp | 2 | ||||
-rw-r--r-- | lib/input/mysqlStmt.h | 2 | ||||
-rw-r--r-- | lib/output/pq/pqBindings.h | 3 | ||||
-rw-r--r-- | lib/output/pq/pqStmt.cpp | 2 | ||||
-rw-r--r-- | lib/output/pq/pqStmt.h | 2 |
7 files changed, 12 insertions, 9 deletions
diff --git a/lib/dbConn.h b/lib/dbConn.h index f0549d3..b464e2b 100644 --- a/lib/dbConn.h +++ b/lib/dbConn.h @@ -9,7 +9,12 @@ namespace MyGrate { class DbPrepStmt { public: virtual ~DbPrepStmt() = default; - virtual void execute(const std::initializer_list<DbValue> &) = 0; + virtual void execute(const std::span<const DbValue>) = 0; + void + execute(const std::initializer_list<DbValue> & v) + { + return execute(std::span<const DbValue> {v}); + } virtual std::size_t rows() const = 0; virtual RecordSetPtr recordSet() = 0; virtual CursorPtr cursor() = 0; diff --git a/lib/input/mysqlBindings.h b/lib/input/mysqlBindings.h index 84a2d28..ccf876e 100644 --- a/lib/input/mysqlBindings.h +++ b/lib/input/mysqlBindings.h @@ -17,8 +17,7 @@ namespace MyGrate::Input { }; struct Bindings { - // NOLINTNEXTLINE(hicpp-explicit-conversions) - explicit Bindings(const std::initializer_list<DbValue> & vs) + explicit Bindings(const std::span<const DbValue> vs) { binds.reserve(vs.size()); data.reserve(vs.size()); diff --git a/lib/input/mysqlStmt.cpp b/lib/input/mysqlStmt.cpp index e0f4cbc..0a80258 100644 --- a/lib/input/mysqlStmt.cpp +++ b/lib/input/mysqlStmt.cpp @@ -15,7 +15,7 @@ namespace MyGrate::Input { } void - MySQLPrepStmt::execute(const std::initializer_list<DbValue> & vs) + MySQLPrepStmt::execute(const std::span<const DbValue> vs) { Bindings b {vs}; verify<std::logic_error>(!mysql_stmt_bind_param(stmt.get(), b.binds.data()), "Param count mismatch"); diff --git a/lib/input/mysqlStmt.h b/lib/input/mysqlStmt.h index 09b5c73..4a4ad8f 100644 --- a/lib/input/mysqlStmt.h +++ b/lib/input/mysqlStmt.h @@ -17,7 +17,7 @@ namespace MyGrate::Input { class MySQLPrepStmt : public DbPrepStmt { public: MySQLPrepStmt(const char * const q, MYSQL * c); - void execute(const std::initializer_list<DbValue> & vs) override; + void execute(const std::span<const DbValue> vs) override; std::size_t rows() const override; diff --git a/lib/output/pq/pqBindings.h b/lib/output/pq/pqBindings.h index 13d0f69..2a4ac8c 100644 --- a/lib/output/pq/pqBindings.h +++ b/lib/output/pq/pqBindings.h @@ -11,8 +11,7 @@ namespace MyGrate::Output::Pq { struct Bindings { - // NOLINTNEXTLINE(hicpp-explicit-conversions) - explicit Bindings(const std::initializer_list<DbValue> & vs) + explicit Bindings(const std::span<const DbValue> vs) { bufs.reserve(vs.size()); values.reserve(vs.size()); diff --git a/lib/output/pq/pqStmt.cpp b/lib/output/pq/pqStmt.cpp index 7e085b5..eb3c32d 100644 --- a/lib/output/pq/pqStmt.cpp +++ b/lib/output/pq/pqStmt.cpp @@ -19,7 +19,7 @@ namespace MyGrate::Output::Pq { } void - PqPrepStmt::execute(const std::initializer_list<DbValue> & vs) + PqPrepStmt::execute(const std::span<const DbValue> vs) { Bindings b {vs}; res = {PQexecPrepared( diff --git a/lib/output/pq/pqStmt.h b/lib/output/pq/pqStmt.h index 887a326..33047c0 100644 --- a/lib/output/pq/pqStmt.h +++ b/lib/output/pq/pqStmt.h @@ -21,7 +21,7 @@ namespace MyGrate::Output::Pq { public: PqPrepStmt(const char * const q, std::size_t n, PqConn * c); - void execute(const std::initializer_list<DbValue> & vs) override; + void execute(const std::span<const DbValue> vs) override; std::size_t rows() const override; |