Value::getAsArray function to parse array convert to correct type and
uses inserter to fill container. Unit tests included.
This commit is contained in:
parent
ec930218cd
commit
2ad4a2601f
3 changed files with 55 additions and 9 deletions
|
|
@ -2,11 +2,14 @@
|
|||
#define PGSQL_VALUE_H
|
||||
|
||||
#include "Pgsql_declare.h"
|
||||
#include "ArrayParser.h"
|
||||
#include <sstream>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace Pgsql {
|
||||
|
||||
|
||||
/** \brief Class that is returned as value of a cell to facilitate auto conversion.
|
||||
*/
|
||||
class Value {
|
||||
|
|
@ -30,19 +33,35 @@ namespace Pgsql {
|
|||
|
||||
bool isString() const;
|
||||
|
||||
/**
|
||||
*
|
||||
* \param insert_iter An insert_iterator which is used to add the elements of the array to a container.
|
||||
*/
|
||||
template <typename E, typename I>
|
||||
void getAsArray(I insert_iter) const
|
||||
{
|
||||
using value_type = E;
|
||||
ArrayParser parser(m_val);
|
||||
for (;;) {
|
||||
auto res = parser.GetNextElem();
|
||||
if (res.ok) {
|
||||
std::string str(res.value->data(), res.value->length());
|
||||
// std::istringstream iss(str);
|
||||
Value val(str.c_str(), ANYOID);
|
||||
value_type v;
|
||||
// iss >> v;
|
||||
v << val;
|
||||
insert_iter = v;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
private:
|
||||
const char *m_val;
|
||||
Oid m_typ;
|
||||
};
|
||||
|
||||
// void operator<<(QString &s, const Value &v);
|
||||
// void operator<<(QDateTime &l, const Value &v);
|
||||
// void operator<<(std::string &l, const Value &v);
|
||||
// void operator<<(short &l, const Value &v);
|
||||
// void operator<<(int &l, const Value &v);
|
||||
// void operator<<(Oid &l, const Value &v);
|
||||
// void operator<<(__int64 &l, const Value &v);
|
||||
// void operator<<(bool &l, const Value &v);
|
||||
template <typename T>
|
||||
void operator<<(T &s, const Value &v)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue