diff --git a/pgsql/Pgsql_Value.h b/pgsql/Pgsql_Value.h index c2ad771..258dd27 100644 --- a/pgsql/Pgsql_Value.h +++ b/pgsql/Pgsql_Value.h @@ -40,16 +40,19 @@ namespace Pgsql { bool isString() const; - /** - * - * \param insert_iter An insert_iterator which is used to add the elements of the array to a container. - */ + /// Retrieves an array type value and passes them to an insert iterator. + /// + /// When the array it self is NULL this function behaves the same as for an empty array. No + /// elements are given to the insert iterator and the function returns. Use the null() function + /// to check for NULL values. + /// + /// \param insert_iter An insert_iterator which is used to add the elements of the array to a container. + /// \param nullhandling This only affects how NULL elements within the array are handled. template void getAsArray(I insert_iter, NullHandling nullhandling = NullHandling::Throw) const { if (m_val == nullptr) { - if (nullhandling == NullHandling::Throw) - throw std::runtime_error("Unexpected NULL value for array"); + return; } else { using value_type = E; @@ -75,6 +78,10 @@ namespace Pgsql { } } + /// Retrieves an array typed value, and passes the element to the insert iterator + /// + /// \param value_for_nulls Each time it encounters a NULL element in the array it + /// will instead pass this value to the insert iterator. template void getAsArray(I insert_iter, const E &value_for_nulls) const { @@ -101,9 +108,12 @@ namespace Pgsql { } } + /// Retrieves an array typed value, and passes the elements to the insert iterator template void getAsArrayOfOptional(I insert_iter) const { + if (m_val == nullptr) return; + using value_type = E; ArrayParser parser(m_val); for (;;) { @@ -125,18 +135,20 @@ namespace Pgsql { } } - /** 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 - */ + /// 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 void getAsVector(I insert_iter) const { + if (m_val == nullptr || *m_val == '\0') return; + const char * pos = m_val; const char * start = pos; for (;;) { while (*pos != 0 && *pos != ' ') ++pos; - std::string str(start, pos-start); + // The cast (to prevent warning) should be save as start should always be <= pos + std::string str(start, static_cast(pos-start)); Value val(str.c_str(), OidFor::elem()); E v; v << val;