More flexible array retrieval + *vector support.

This commit is contained in:
eelke 2017-12-17 11:27:42 +01:00
parent d9854d81fa
commit db75d9ed50
5 changed files with 119 additions and 8 deletions

View file

@ -2,6 +2,7 @@
#define PGSQL_VALUE_H
#include "Pgsql_declare.h"
#include "Pgsql_oids.h"
#include "ArrayParser.h"
#include <sstream>
#include <QString>
@ -33,10 +34,6 @@ namespace Pgsql {
bool isString() const;
enum class NullHandling {
Ignore,
Throw
};
/**
*
* \param insert_iter An insert_iterator which is used to add the elements of the array to a container.
@ -51,7 +48,7 @@ namespace Pgsql {
if (res.ok) {
if (res.value) {
std::string str(res.value->data(), res.value->length());
Value val(str.c_str(), ANYOID);
Value val(str.c_str(), OidFor<E>::elem());
value_type v;
v << val;
insert_iter = v;
@ -76,7 +73,7 @@ namespace Pgsql {
if (res.ok) {
if (res.value) {
std::string str(res.value->data(), res.value->length());
Value val(str.c_str(), ANYOID);
Value val(str.c_str(), OidFor<E>::elem());
value_type v;
v << val;
insert_iter = v;
@ -100,7 +97,7 @@ namespace Pgsql {
if (res.ok) {
if (res.value) {
std::string str(res.value->data(), res.value->length());
Value val(str.c_str(), ANYOID);
Value val(str.c_str(), OidFor<E>::elem());
value_type v;
v << val;
insert_iter = v;
@ -113,6 +110,28 @@ namespace Pgsql {
break;
}
}
/** De catalog uses vector types which are similar to array
* but uses spaces as seperators. AFAIK there are only integral
* vector types so this implementation is only tested for those
*/
template <typename E, typename I>
void getAsVector(I insert_iter) const
{
const char * pos = m_val;
const char * start = pos;
for (;;) {
while (*pos != 0 && *pos != ' ') ++pos;
std::string str(start, pos-start);
Value val(str.c_str(), OidFor<E>::elem());
E v;
v << val;
insert_iter = v;
if (*pos == 0)
break;
start = ++pos; // skip space and set new start to match
}
}
private:
const char *m_val;
Oid m_typ;