summaryrefslogtreecommitdiff
path: root/lib/input
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-06-17 19:54:11 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-06-17 19:54:11 +0100
commitbbffe078612e5cbf6a893ef4f2df9575197175fc (patch)
tree28219df966b6090e95a2c5b1a25f1e62593ad6da /lib/input
parentAdd wrapper for writing a DbValueV to a stream (diff)
downloadmygrate-bbffe078612e5cbf6a893ef4f2df9575197175fc.tar.bz2
mygrate-bbffe078612e5cbf6a893ef4f2df9575197175fc.tar.xz
mygrate-bbffe078612e5cbf6a893ef4f2df9575197175fc.zip
Fix MySQLRecordSet seek/fetch behaviour
Diffstat (limited to 'lib/input')
-rw-r--r--lib/input/mysqlRecordSet.cpp7
-rw-r--r--lib/input/mysqlRecordSet.h1
2 files changed, 6 insertions, 2 deletions
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<MySQLErr>(!mysql_stmt_bind_result(stmt.get(), fields.data()), "Store result error", stmt->mysql);
verify<MySQLErr>(!mysql_stmt_store_result(stmt.get()), "Store result error", stmt->mysql);
stmtres = {stmt.get(), mysql_stmt_free_result};
- verify<MySQLErr>(!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<MySQLErr>(!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<MYSQL_BIND> fields;
std::vector<ResultDataPtr> extras;
+ mutable std::size_t currentRow {static_cast<size_t>(-1)};
};
}