20#include <drogon/exports.h>
25#include <trantor/utils/Logger.h>
43class DROGON_EXPORT Field
46 using SizeType =
unsigned long;
66 return result_.getLength(row_,
column_);
75 auto data_ = result_.getValue(row_,
column_);
98 std::stringstream ss(data_);
103 LOG_DEBUG <<
"Type error";
122 template <
typename T>
123 std::vector<std::shared_ptr<T>> asArray()
const
125 std::vector<std::shared_ptr<T>> ret;
126 auto arrParser = getArrayParser();
129 auto arrVal = arrParser.getNext();
134 if (arrVal.first == ArrayParser::juncture::string_value)
137 std::stringstream ss(std::move(arrVal.second));
139 ret.push_back(std::shared_ptr<T>(
new T(val)));
141 else if (arrVal.first == ArrayParser::juncture::null_value)
143 ret.push_back(std::shared_ptr<T>());
150 Result::SizeType row_;
158 Field(
const Row &row, Row::SizeType columnNum)
noexcept;
176 auto first = result_.getValue(row_, column_);
177 auto length = result_.getLength(row_, column_);
178 return {first, length};
186 return std::stof(result_.getValue(row_,
column_));
194 return std::stod(result_.getValue(row_,
column_));
200 if (result_.getLength(row_,
column_) != 1)
204 auto value = result_.getValue(row_,
column_);
205 if (*value ==
't' || *value ==
'1')
215 return std::stoi(result_.getValue(row_,
column_));
223 return std::stol(result_.getValue(row_,
column_));
231 return static_cast<int8_t
>(atoi(result_.getValue(row_,
column_)));
239 return atoll(result_.getValue(row_,
column_));
247 return static_cast<unsigned int>(
248 std::stoul(result_.getValue(row_,
column_)));
256 return std::stoul(result_.getValue(row_,
column_));
264 return static_cast<uint8_t
>(atoi(result_.getValue(row_,
column_)));
272 return std::stoull(result_.getValue(row_,
column_));
Low-level array parser.
Definition ArrayParser.h:53
@ done
Parsing has completed.
Definition ArrayParser.h:67
size_t length() const
Get the length of the plain C string.
Definition Field.h:64
T as() const
Convert to a type T value.
Definition Field.h:71
const char * c_str() const
Read as plain C string.
long column_
Definition Field.h:156
ArrayParser getArrayParser() const
Parse the field as an SQL array.
Definition Field.h:117
const char * name() const
Column name.
bool isNull() const
Is this field's value null?
Result set containing data returned by a query or command.
Definition Result.h:58
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23