diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-12 20:26:01 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-12 20:26:01 +0100 |
commit | 231bc3fc8d1902bb19b6fce39ffd72cce4b4f2c3 (patch) | |
tree | e074ea9bf53400600831215822a848fe27bfac55 /lib/input/mysqlStmt.cpp | |
parent | Have verify return its expression, might be useful (diff) | |
download | mygrate-231bc3fc8d1902bb19b6fce39ffd72cce4b4f2c3.tar.bz2 mygrate-231bc3fc8d1902bb19b6fce39ffd72cce4b4f2c3.tar.xz mygrate-231bc3fc8d1902bb19b6fce39ffd72cce4b4f2c3.zip |
Avoid direct use of runtime_error in MySQL stuff
Adds proper exception which extends it and gets the MySQL error message.
Diffstat (limited to 'lib/input/mysqlStmt.cpp')
-rw-r--r-- | lib/input/mysqlStmt.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/input/mysqlStmt.cpp b/lib/input/mysqlStmt.cpp index 08d1303..d3ba9ef 100644 --- a/lib/input/mysqlStmt.cpp +++ b/lib/input/mysqlStmt.cpp @@ -1,5 +1,6 @@ #include "mysqlStmt.h" #include "mysqlBindings.h" +#include "mysqlConn.h" #include "mysqlRecordSet.h" #include <cstring> #include <helpers.h> @@ -10,15 +11,15 @@ 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); + verify<MySQLErr>(!mysql_stmt_prepare(stmt.get(), q, strlen(q)), q, c); } 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"); + verify<std::logic_error>(!mysql_stmt_bind_param(stmt.get(), b.binds.data()), "Param count mismatch"); + verify<MySQLErr>(!mysql_stmt_execute(stmt.get()), "Prepared statement execute", stmt->mysql); } std::size_t |