From bbffe078612e5cbf6a893ef4f2df9575197175fc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Jun 2021 19:54:11 +0100 Subject: Fix MySQLRecordSet seek/fetch behaviour --- lib/input/mysqlRecordSet.cpp | 7 +++++-- lib/input/mysqlRecordSet.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/input/mysqlRecordSet.cpp b/lib/input/mysqlRecordSet.cpp index 22b7214..71c5148 100644 --- a/lib/input/mysqlRecordSet.cpp +++ b/lib/input/mysqlRecordSet.cpp @@ -72,7 +72,6 @@ namespace MyGrate::Input { verify(!mysql_stmt_bind_result(stmt.get(), fields.data()), "Store result error", stmt->mysql); verify(!mysql_stmt_store_result(stmt.get()), "Store result error", stmt->mysql); stmtres = {stmt.get(), mysql_stmt_free_result}; - verify(!mysql_stmt_fetch(stmt.get()), "Fetch", stmt->mysql); } std::size_t @@ -90,7 +89,11 @@ namespace MyGrate::Input { DbValue MySQLRecordSet::at(std::size_t row, std::size_t col) const { - mysql_stmt_data_seek(stmt.get(), row); + if (currentRow != row) { + mysql_stmt_data_seek(stmt.get(), row); + verify(!mysql_stmt_fetch(stmt.get()), "Fetch", stmt->mysql); + currentRow = row; + } if (extras[col]->null) { return nullptr; } diff --git a/lib/input/mysqlRecordSet.h b/lib/input/mysqlRecordSet.h index 849a653..aec733e 100644 --- a/lib/input/mysqlRecordSet.h +++ b/lib/input/mysqlRecordSet.h @@ -31,6 +31,7 @@ namespace MyGrate::Input { StmtResPtr stmtres; std::vector fields; std::vector extras; + mutable std::size_t currentRow {static_cast(-1)}; }; } -- cgit v1.2.3