FOSSology  4.4.0
Open Source License Compliance by Open Source Software
libfossdbQueryResult.cc
Go to the documentation of this file.
1 /*
2  Author: Daniele Fognini
3  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
10 #include <string>
11 
12 using namespace fo;
13 
23 QueryResult::QueryResult(PGresult* pgResult) : ptr(unptr::unique_ptr<PGresult, PGresultDeleter>(pgResult)) {
24 };
25 
32 bool QueryResult::isFailed() const {
33  return ptr.get() == NULL;
34 }
35 
41  if (ptr) {
42  return PQntuples(ptr.get());
43  }
44 
45  return -1;
46 }
47 
53 std::vector<std::string> QueryResult::getRow(int i) const {
54  std::vector<std::string> result;
55 
56  if (ptr) {
57  PGresult* r = ptr.get();
58 
59  if (i >= 0 && i < getRowCount()) {
60  for (int j = 0; j < PQnfields(r); j++) {
61  result.push_back(std::string(PQgetvalue(r, i, j)));
62  }
63  }
64  }
65 
66  return result;
67 }
PGresult deleter (for shared pointer)
bool isFailed() const
Check if the query failed.
unptr::unique_ptr< PGresult, PGresultDeleter > ptr
Unique pointer to the actual PGresult.
std::vector< std::string > getRow(int i) const
QueryResult(PGresult *ptr)
Wrapper for DB result.
fo namespace holds the FOSSology library functions.