diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-07-03 16:55:44 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-07-03 16:55:44 +0100 |
commit | a3c014b1c938fd16ff6d1f8eadeea3effd3a5a90 (patch) | |
tree | e94a7bbf4b9dd8280ffbe133c712489ce7c40e28 /lib/input | |
parent | Support stopping the event stream reading (diff) | |
download | mygrate-a3c014b1c938fd16ff6d1f8eadeea3effd3a5a90.tar.bz2 mygrate-a3c014b1c938fd16ff6d1f8eadeea3effd3a5a90.tar.xz mygrate-a3c014b1c938fd16ff6d1f8eadeea3effd3a5a90.zip |
Split MySQLRecordSet data away from interface
Diffstat (limited to 'lib/input')
-rw-r--r-- | lib/input/mysqlRecordSet.cpp | 17 | ||||
-rw-r--r-- | lib/input/mysqlRecordSet.h | 19 |
2 files changed, 27 insertions, 9 deletions
diff --git a/lib/input/mysqlRecordSet.cpp b/lib/input/mysqlRecordSet.cpp index 9eec30f..33c5e6f 100644 --- a/lib/input/mysqlRecordSet.cpp +++ b/lib/input/mysqlRecordSet.cpp @@ -11,9 +11,8 @@ // IWYU pragma: no_include <ext/alloc_traits.h> namespace MyGrate::Input { - MySQLRecordSet::MySQLRecordSet(StmtPtr s) : - stmt {std::move(s)}, stmtres {nullptr, nullptr}, fields(mysql_stmt_field_count(stmt.get())), - extras(fields.size()) + MySQLData::MySQLData(StmtPtr s) : + stmt {std::move(s)}, fields(mysql_stmt_field_count(stmt.get())), extras(fields.size()) { auto getBind = [](const MYSQL_FIELD & f, MYSQL_BIND & b) -> std::unique_ptr<ResultData> { switch (f.type) { @@ -72,6 +71,16 @@ namespace MyGrate::Input { extras[i] = getBind(fieldDefs[i], fields[i]); } verify<MySQLErr>(!mysql_stmt_bind_result(stmt.get(), fields.data()), "Store result error", stmt->mysql); + } + + std::size_t + MySQLData::columns() const + { + return fields.size(); + } + + MySQLRecordSet::MySQLRecordSet(StmtPtr s) : MySQLData(std::move(s)), stmtres {nullptr, nullptr} + { verify<MySQLErr>(!mysql_stmt_store_result(stmt.get()), "Store result error", stmt->mysql); stmtres = {stmt.get(), mysql_stmt_free_result}; } @@ -85,7 +94,7 @@ namespace MyGrate::Input { std::size_t MySQLRecordSet::columns() const { - return fields.size(); + return MySQLData::columns(); } DbValue diff --git a/lib/input/mysqlRecordSet.h b/lib/input/mysqlRecordSet.h index aec733e..0b4a057 100644 --- a/lib/input/mysqlRecordSet.h +++ b/lib/input/mysqlRecordSet.h @@ -12,11 +12,23 @@ namespace MyGrate::Input { class ResultData; - class MySQLRecordSet : public RecordSet { + class MySQLData { public: + using ResultDataPtr = std::unique_ptr<ResultData>; using ResPtr = std::unique_ptr<MYSQL_RES, decltype(&mysql_free_result)>; + + explicit MySQLData(StmtPtr s); + + std::size_t columns() const; + + StmtPtr stmt; + std::vector<MYSQL_BIND> fields; + std::vector<ResultDataPtr> extras; + }; + + class MySQLRecordSet : public MySQLData, public RecordSet { + public: using StmtResPtr = std::unique_ptr<MYSQL_STMT, decltype(&mysql_stmt_free_result)>; - using ResultDataPtr = std::unique_ptr<ResultData>; explicit MySQLRecordSet(StmtPtr s); @@ -27,10 +39,7 @@ namespace MyGrate::Input { DbValue at(std::size_t row, std::size_t col) const override; private: - StmtPtr stmt; StmtResPtr stmtres; - std::vector<MYSQL_BIND> fields; - std::vector<ResultDataPtr> extras; mutable std::size_t currentRow {static_cast<size_t>(-1)}; }; } |