diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-31 13:18:17 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-31 13:18:17 +0100 |
commit | 63b2ca0dbdae190941d60a55c9cff99d4a75a0e1 (patch) | |
tree | d3766bcbc98fb5fb0fb2d8dddf2f194bedcb0325 /lib/input/mysqlStmt.cpp | |
parent | Map std::size_t to a sensible header (diff) | |
download | mygrate-63b2ca0dbdae190941d60a55c9cff99d4a75a0e1.tar.bz2 mygrate-63b2ca0dbdae190941d60a55c9cff99d4a75a0e1.tar.xz mygrate-63b2ca0dbdae190941d60a55c9cff99d4a75a0e1.zip |
Initial commit of prepstmt, selects, record sets
This is full of holes, but all the basics are covered.
Diffstat (limited to 'lib/input/mysqlStmt.cpp')
-rw-r--r-- | lib/input/mysqlStmt.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/input/mysqlStmt.cpp b/lib/input/mysqlStmt.cpp new file mode 100644 index 0000000..08d1303 --- /dev/null +++ b/lib/input/mysqlStmt.cpp @@ -0,0 +1,35 @@ +#include "mysqlStmt.h" +#include "mysqlBindings.h" +#include "mysqlRecordSet.h" +#include <cstring> +#include <helpers.h> +#include <stdexcept> +#include <utility> +#include <vector> + +namespace MyGrate::Input { + MySQLPrepStmt::MySQLPrepStmt(const char * const q, MYSQL * c) : stmt {mysql_stmt_init(c), &mysql_stmt_close} + { + verify<std::runtime_error>(!mysql_stmt_prepare(stmt.get(), q, strlen(q)), q); + } + + void + MySQLPrepStmt::execute(const std::initializer_list<DbValue> & vs) + { + Bindings b {vs}; + verify<std::runtime_error>(!mysql_stmt_bind_param(stmt.get(), b.binds.data()), "Param count mismatch"); + verify<std::runtime_error>(!mysql_stmt_execute(stmt.get()), "Prepared statement execute"); + } + + std::size_t + MySQLPrepStmt::rows() const + { + return mysql_stmt_affected_rows(stmt.get()); + } + + RecordSetPtr + MySQLPrepStmt::recordSet() + { + return std::make_unique<MySQLRecordSet>(std::move(stmt)); + } +} |