17 #include <rapidjson/document.h> 19 typedef enum column_type {
38 m_value.str = (
char *)malloc(value.length() + 1);
39 strncpy(m_value.str, value.c_str(), value.length() + 1);
40 m_type = STRING_COLUMN;
55 m_type = NUMBER_COLUMN;
59 m_doc =
new rapidjson::Document();
60 rapidjson::Document::AllocatorType& a = m_doc->GetAllocator();
61 m_value.json =
new rapidjson::Value(value, a);
66 if (m_type == STRING_COLUMN)
68 else if (m_type == JSON_COLUMN)
74 ColumnType getType() {
return m_type; };
78 const rapidjson::Value *getJSON()
const {
return m_value.json; };
87 rapidjson::Value *json;
89 rapidjson::Document *m_doc;
97 for (
auto it = m_values.cbegin();
98 it != m_values.cend(); it++)
103 m_values.push_back(value);
105 ColumnType getType(
unsigned int column);
106 ColumnType getType(
const std::string& name);
108 ColumnValue *getColumn(
const std::string& name)
const;
109 ColumnValue *operator[] (
unsigned long colNo)
const {
110 return m_values[colNo];
114 Row& operator=(
Row const&);
115 std::vector<ResultSet::ColumnValue *> m_values;
119 typedef std::vector<Row *>::iterator RowIterator;
123 unsigned int rowCount()
const {
return m_rowCount; };
124 unsigned int columnCount()
const {
return m_columns.size(); };
125 const std::string&
columnName(
unsigned int column)
const;
126 ColumnType
columnType(
unsigned int column)
const;
127 ColumnType
columnType(
const std::string& name)
const;
129 RowIterator
nextRow(RowIterator it);
132 unsigned int findColumn(
const std::string& name)
const;
133 const Row * operator[] (
unsigned long rowNo) {
134 return m_rows[rowNo];
142 Column(
const std::string& name, ColumnType type) : m_name(name), m_type(type) {};
143 const std::string& getName() {
return m_name; };
144 ColumnType getType() {
return m_type; };
146 const std::string m_name;
151 unsigned int m_rowCount;
152 std::vector<ResultSet::Column *> m_columns;
153 std::vector<ResultSet::Row *> m_rows;
162 m_what = strdup(what);
169 virtual const char *what()
const throw()
179 virtual const char *what()
const throw()
181 return "Column does not exist";
187 virtual const char *what()
const throw()
189 return "No more rows in the result set";
195 virtual const char *what()
const throw()
197 return "No more rows in the result set";
ResultSet(const std::string &json)
Construct a result set from a JSON document returned from the Fledge storage service.
Definition: result_set.cpp:25
~ResultSet()
Destructor for a result set.
Definition: result_set.cpp:140
unsigned int findColumn(const std::string &name) const
Find the named column in the result set and return the column index.
Definition: result_set.cpp:312
const std::string & columnName(unsigned int column) const
Return the name of a specific column.
Definition: result_set.cpp:162
Definition: resultset.h:34
long getInteger() const
Retrieve a column value as an integer.
Definition: result_set.cpp:330
bool hasNextRow(RowIterator it) const
Given an iterator over the rows in a result set return if there are any more rows in the result set...
Definition: result_set.cpp:234
RowIterator nextRow(RowIterator it)
Given an iterator over the rows in a result set move to the next row in the result set...
Definition: result_set.cpp:219
Result set.
Definition: resultset.h:32
double getNumber() const
Retrieve a column value as a floating point number.
Definition: result_set.cpp:349
Definition: resultset.h:185
bool isLastRow(RowIterator it) const
Given an iterator over the rows in a result set return if there this is the last row in the result se...
Definition: result_set.cpp:246
Definition: resultset.h:177
ColumnType columnType(unsigned int column) const
Return the type of a specific column.
Definition: result_set.cpp:179
Definition: resultset.h:92
Definition: resultset.h:157
Definition: resultset.h:193
RowIterator firstRow()
Fetch an iterator for the rows in a result set.
Definition: result_set.cpp:206
char * getString() const
Retrieve a column value as a string.
Definition: result_set.cpp:368