From 63b2ca0dbdae190941d60a55c9cff99d4a75a0e1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 31 May 2021 13:18:17 +0100 Subject: Initial commit of prepstmt, selects, record sets This is full of holes, but all the basics are covered. --- lib/input/mysqlStmt.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/input/mysqlStmt.cpp (limited to 'lib/input/mysqlStmt.cpp') 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 +#include +#include +#include +#include + +namespace MyGrate::Input { + MySQLPrepStmt::MySQLPrepStmt(const char * const q, MYSQL * c) : stmt {mysql_stmt_init(c), &mysql_stmt_close} + { + verify(!mysql_stmt_prepare(stmt.get(), q, strlen(q)), q); + } + + void + MySQLPrepStmt::execute(const std::initializer_list & vs) + { + Bindings b {vs}; + verify(!mysql_stmt_bind_param(stmt.get(), b.binds.data()), "Param count mismatch"); + verify(!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(std::move(stmt)); + } +} -- cgit v1.2.3