summaryrefslogtreecommitdiff
path: root/lib/input
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-07-04 12:48:02 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-07-04 12:48:02 +0100
commit5389571e2db6b62ecc8e45b5e8bea1739ab67957 (patch)
tree77f66babcfcf584ebc2a1c013731e19eeccbef5c /lib/input
parentPush mysqldata at into base class (diff)
downloadmygrate-5389571e2db6b62ecc8e45b5e8bea1739ab67957.tar.bz2
mygrate-5389571e2db6b62ecc8e45b5e8bea1739ab67957.tar.xz
mygrate-5389571e2db6b62ecc8e45b5e8bea1739ab67957.zip
Introduce the cursor concept
Not implemented for PQ yet.
Diffstat (limited to 'lib/input')
-rw-r--r--lib/input/mysqlRecordSet.cpp12
-rw-r--r--lib/input/mysqlRecordSet.h7
-rw-r--r--lib/input/mysqlStmt.cpp6
-rw-r--r--lib/input/mysqlStmt.h2
4 files changed, 27 insertions, 0 deletions
diff --git a/lib/input/mysqlRecordSet.cpp b/lib/input/mysqlRecordSet.cpp
index 494ce13..5fbbfe9 100644
--- a/lib/input/mysqlRecordSet.cpp
+++ b/lib/input/mysqlRecordSet.cpp
@@ -116,4 +116,16 @@ namespace MyGrate::Input {
}
return extras[col]->getValue();
}
+
+ bool
+ MySQLCursor::fetch()
+ {
+ switch (mysql_stmt_fetch(stmt.get())) {
+ case 0:
+ return true;
+ case MYSQL_NO_DATA:
+ return false;
+ }
+ throw MySQLErr("Fetch", stmt.get());
+ }
}
diff --git a/lib/input/mysqlRecordSet.h b/lib/input/mysqlRecordSet.h
index d843dfd..0e3a96f 100644
--- a/lib/input/mysqlRecordSet.h
+++ b/lib/input/mysqlRecordSet.h
@@ -28,6 +28,13 @@ namespace MyGrate::Input {
std::vector<ResultDataPtr> extras;
};
+ class MySQLCursor : public MySQLData, public Cursor {
+ public:
+ using MySQLData::MySQLData;
+
+ bool fetch();
+ };
+
class MySQLRecordSet : public MySQLData, public RecordSet {
public:
using StmtResPtr = std::unique_ptr<MYSQL_STMT, decltype(&mysql_stmt_free_result)>;
diff --git a/lib/input/mysqlStmt.cpp b/lib/input/mysqlStmt.cpp
index d3ba9ef..e0f4cbc 100644
--- a/lib/input/mysqlStmt.cpp
+++ b/lib/input/mysqlStmt.cpp
@@ -33,4 +33,10 @@ namespace MyGrate::Input {
{
return std::make_unique<MySQLRecordSet>(std::move(stmt));
}
+
+ CursorPtr
+ MySQLPrepStmt::cursor()
+ {
+ return std::make_unique<MySQLCursor>(std::move(stmt));
+ }
}
diff --git a/lib/input/mysqlStmt.h b/lib/input/mysqlStmt.h
index 69e62d4..09b5c73 100644
--- a/lib/input/mysqlStmt.h
+++ b/lib/input/mysqlStmt.h
@@ -23,6 +23,8 @@ namespace MyGrate::Input {
RecordSetPtr recordSet() override;
+ CursorPtr cursor() override;
+
private:
StmtPtr stmt;
};