Skip to content

Commit 1352309

Browse files
committed
QueryResult. Update interface.
1 parent d434bfe commit 1352309

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/oatpp-postgresql/QueryResult.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ QueryResult::~QueryResult() {
5959
PQclear(m_dbResult);
6060
}
6161

62-
bool QueryResult::isSuccess() {
62+
bool QueryResult::isSuccess() const {
6363
return m_success;
6464
}
6565

66-
v_int64 QueryResult::count() {
66+
v_int64 QueryResult::position() const {
67+
return m_resultData.rowIndex;
68+
}
69+
70+
v_int64 QueryResult::count() const {
6771
switch(m_type) {
68-
case TYPE_TUPLES: return PQntuples(m_dbResult);
72+
case TYPE_TUPLES: return m_resultData.rowCount;
6973
// case TYPE_COMMAND: return 0;
7074
}
7175
return 0;
7276
}
7377

74-
std::vector<std::vector<oatpp::Void>> QueryResult::fetchRows(v_int64 count) {
75-
return {};
76-
}
77-
7878
void QueryResult::fetch(oatpp::Void& polymorph, v_int64 count) {
7979
polymorph = m_resultMapper->readRows(&m_resultData, polymorph.valueType, count);
8080
}

src/oatpp-postgresql/QueryResult.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class QueryResult : public orm::QueryResult {
5454

5555
~QueryResult();
5656

57-
bool isSuccess() override;
57+
bool isSuccess() const override;
5858

59-
v_int64 count() override;
59+
v_int64 position() const override;
6060

61-
std::vector<std::vector<oatpp::Void>> fetchRows(v_int64 count) override;
61+
v_int64 count() const override;
6262

6363
void fetch(oatpp::Void& polymorph, v_int64 count) override;
6464

test/oatpp-postgresql/tests.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,17 @@ class Test : public oatpp::test::UnitTest {
102102
//client.insertFloats(0.32, 0.64, connection);
103103
//client.insertFloats(-0.32, -0.64, connection);
104104

105-
auto res = client.selectInts(connection);
106-
107-
OATPP_LOGD(TAG, "OK=%d, count=%d", res->isSuccess(), res->count());
108-
109105
{
110-
oatpp::Vector<oatpp::Fields<oatpp::Any>> resObjType;
111-
oatpp::Void polymorph(resObjType.valueType);
112106

113-
res->fetch(polymorph, res->count());
107+
auto res = client.selectInts(connection);
108+
OATPP_LOGD(TAG, "OK=%d, count=%d", res->isSuccess(), res->count());
109+
110+
auto dataset = res->fetch<oatpp::Vector<oatpp::Fields<oatpp::Any>>>();
114111

115112
oatpp::parser::json::mapping::ObjectMapper om;
116113
om.getSerializer()->getConfig()->useBeautifier = true;
117114

118-
auto str = om.writeToString(polymorph);
115+
auto str = om.writeToString(dataset);
119116

120117
OATPP_LOGD(TAG, "res=%s", str->c_str());
121118

0 commit comments

Comments
 (0)