From 7d8dae0ec07f35fd0c0a67d39bb31e3f9513ad91 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 4 Jul 2021 12:39:48 +0100 Subject: Get mysql statement errors from the statement, not connection --- lib/input/mysqlConn.cpp | 3 +++ lib/input/mysqlConn.h | 1 + lib/input/mysqlRecordSet.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/input/mysqlConn.cpp b/lib/input/mysqlConn.cpp index 99c2891..305d638 100644 --- a/lib/input/mysqlConn.cpp +++ b/lib/input/mysqlConn.cpp @@ -12,6 +12,9 @@ namespace MyGrate::Input { MySQLErr::MySQLErr(const std::string & when, MYSQL * c) : std::runtime_error(when + ": " + mysql_error(c)) { } + MySQLErr::MySQLErr(const std::string & when, MYSQL_STMT * s) : std::runtime_error(when + ": " + mysql_stmt_error(s)) + { + } MySQLConn::MySQLConn(const char * const host, const char * const user, const char * const pass, unsigned short port, const char * const db) : diff --git a/lib/input/mysqlConn.h b/lib/input/mysqlConn.h index bd53616..3e775c1 100644 --- a/lib/input/mysqlConn.h +++ b/lib/input/mysqlConn.h @@ -13,6 +13,7 @@ namespace MyGrate::Input { class MySQLErr : public std::runtime_error { public: MySQLErr(const std::string & when, MYSQL *); + MySQLErr(const std::string & when, MYSQL_STMT *); }; class MySQLConn : public MYSQL, public DbConn { diff --git a/lib/input/mysqlRecordSet.cpp b/lib/input/mysqlRecordSet.cpp index 33c5e6f..1585052 100644 --- a/lib/input/mysqlRecordSet.cpp +++ b/lib/input/mysqlRecordSet.cpp @@ -66,11 +66,11 @@ namespace MyGrate::Input { throw std::logic_error("Unsupported column type"); }; ResPtr meta {mysql_stmt_result_metadata(stmt.get()), mysql_free_result}; - const auto fieldDefs = verify(mysql_fetch_fields(meta.get()), "Fetch fields", stmt->mysql); + const auto fieldDefs = verify(mysql_fetch_fields(meta.get()), "Fetch fields", stmt.get()); for (std::size_t i = 0; i < fields.size(); i += 1) { extras[i] = getBind(fieldDefs[i], fields[i]); } - verify(!mysql_stmt_bind_result(stmt.get(), fields.data()), "Store result error", stmt->mysql); + verify(!mysql_stmt_bind_result(stmt.get(), fields.data()), "Bind result error", stmt.get()); } std::size_t @@ -81,7 +81,7 @@ namespace MyGrate::Input { MySQLRecordSet::MySQLRecordSet(StmtPtr s) : MySQLData(std::move(s)), stmtres {nullptr, nullptr} { - verify(!mysql_stmt_store_result(stmt.get()), "Store result error", stmt->mysql); + verify(!mysql_stmt_store_result(stmt.get()), "Store result error", stmt.get()); stmtres = {stmt.get(), mysql_stmt_free_result}; } @@ -102,7 +102,7 @@ namespace MyGrate::Input { { if (currentRow != row) { mysql_stmt_data_seek(stmt.get(), row); - verify(!mysql_stmt_fetch(stmt.get()), "Fetch", stmt->mysql); + verify(!mysql_stmt_fetch(stmt.get()), "Fetch", stmt.get()); currentRow = row; } if (extras[col]->null) { -- cgit v1.2.3