2017-02-18 12:05:48 +01:00
|
|
|
|
#ifndef PGSQL_VALUE_H
|
|
|
|
|
|
#define PGSQL_VALUE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "Pgsql_declare.h"
|
2017-12-16 21:40:19 +01:00
|
|
|
|
#include "ArrayParser.h"
|
|
|
|
|
|
#include <sstream>
|
2017-02-18 12:05:48 +01:00
|
|
|
|
#include <QString>
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
|
2017-12-16 21:40:19 +01:00
|
|
|
|
|
2017-02-18 12:05:48 +01:00
|
|
|
|
/** \brief Class that is returned as value of a cell to facilitate auto conversion.
|
|
|
|
|
|
*/
|
|
|
|
|
|
class Value {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Value(const char *val, Oid typ);
|
|
|
|
|
|
QString asQString() const;
|
2017-08-22 12:45:45 +02:00
|
|
|
|
const char* c_str() const { return m_val; }
|
|
|
|
|
|
|
2017-02-18 12:05:48 +01:00
|
|
|
|
operator QString() const;
|
|
|
|
|
|
operator QDateTime() const;
|
2017-12-09 10:45:13 +01:00
|
|
|
|
operator QDate() const;
|
|
|
|
|
|
operator QTime() const;
|
2017-02-18 12:05:48 +01:00
|
|
|
|
operator std::string() const;
|
|
|
|
|
|
operator short() const;
|
|
|
|
|
|
operator int() const;
|
|
|
|
|
|
operator Oid() const;
|
2017-08-23 08:10:01 +02:00
|
|
|
|
operator long long() const;
|
2017-02-18 12:05:48 +01:00
|
|
|
|
operator bool() const;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
operator float() const;
|
|
|
|
|
|
operator double() const;
|
2017-12-09 10:45:13 +01:00
|
|
|
|
|
|
|
|
|
|
bool isString() const;
|
|
|
|
|
|
|
2017-12-16 21:40:19 +01:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* \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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-02-18 12:05:48 +01:00
|
|
|
|
private:
|
|
|
|
|
|
const char *m_val;
|
|
|
|
|
|
Oid m_typ;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-08-22 12:45:45 +02:00
|
|
|
|
template <typename T>
|
|
|
|
|
|
void operator<<(T &s, const Value &v)
|
|
|
|
|
|
{
|
|
|
|
|
|
s = static_cast<T>(v);
|
|
|
|
|
|
}
|
2017-08-26 11:44:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-18 12:05:48 +01:00
|
|
|
|
} // end namespace Pgsql
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGSQL_VALUE_H
|