summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/dbConn.h1
-rw-r--r--lib/dbRecordSet.h8
-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
-rw-r--r--lib/output/pq/pqStmt.cpp6
-rw-r--r--lib/output/pq/pqStmt.h2
8 files changed, 44 insertions, 0 deletions
diff --git a/lib/dbConn.h b/lib/dbConn.h
index ffdd2e0..f0549d3 100644
--- a/lib/dbConn.h
+++ b/lib/dbConn.h
@@ -12,6 +12,7 @@ namespace MyGrate {
virtual void execute(const std::initializer_list<DbValue> &) = 0;
virtual std::size_t rows() const = 0;
virtual RecordSetPtr recordSet() = 0;
+ virtual CursorPtr cursor() = 0;
};
using DbPrepStmtPtr = std::unique_ptr<DbPrepStmt>;
diff --git a/lib/dbRecordSet.h b/lib/dbRecordSet.h
index a9da882..a217f12 100644
--- a/lib/dbRecordSet.h
+++ b/lib/dbRecordSet.h
@@ -49,6 +49,14 @@ namespace MyGrate {
RowView end() const;
};
using RecordSetPtr = std::unique_ptr<RecordSet>;
+
+ class Cursor {
+ public:
+ virtual ~Cursor() = default;
+
+ virtual bool fetch() = 0;
+ };
+ using CursorPtr = std::unique_ptr<Cursor>;
}
#endif
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;
};
diff --git a/lib/output/pq/pqStmt.cpp b/lib/output/pq/pqStmt.cpp
index dc258b6..2265f64 100644
--- a/lib/output/pq/pqStmt.cpp
+++ b/lib/output/pq/pqStmt.cpp
@@ -40,6 +40,12 @@ namespace MyGrate::Output::Pq {
return std::make_unique<PqRecordSet>(std::move(res));
}
+ CursorPtr
+ PqPrepStmt::cursor()
+ {
+ throw std::logic_error("Not implemented");
+ }
+
std::string
PqPrepStmt::prepareAsNeeded(const char * const q, std::size_t n, PqConn * c)
{
diff --git a/lib/output/pq/pqStmt.h b/lib/output/pq/pqStmt.h
index 6531180..887a326 100644
--- a/lib/output/pq/pqStmt.h
+++ b/lib/output/pq/pqStmt.h
@@ -27,6 +27,8 @@ namespace MyGrate::Output::Pq {
RecordSetPtr recordSet() override;
+ CursorPtr cursor() override;
+
private:
static std::string prepareAsNeeded(const char * const q, std::size_t n, PqConn * c);