diff --git a/include/tao/pq/result_traits_array.hpp b/include/tao/pq/result_traits_array.hpp index 6e80b73..c546ddf 100644 --- a/include/tao/pq/result_traits_array.hpp +++ b/include/tao/pq/result_traits_array.hpp @@ -58,15 +58,19 @@ namespace tao::pq } template< typename T > + requires( !pq::is_array_result< T > ) && ( result_traits_size< T > >= 2 ) [[nodiscard]] auto parse_element( const char*& value ) -> T { - if constexpr( result_traits_size< T > >= 2 ) { - if( *value++ != '{' ) { - throw std::invalid_argument( "expected '{'" ); - } - throw std::runtime_error( "NOT YET IMPLEMENTED" ); + if( *value++ != '{' ) { + throw std::invalid_argument( "expected '{'" ); } - else if( *value == '"' ) { + throw std::runtime_error( "NOT YET IMPLEMENTED" ); + } + + template< typename T > + [[nodiscard]] auto parse_element( const char*& value ) -> T + { + if( *value == '"' ) { ++value; std::string input; while( const auto* pos = std::strpbrk( value, "\\\"" ) ) { @@ -117,7 +121,12 @@ namespace tao::pq } while( true ) { using value_type = std::decay_t< decltype( container ) >::value_type; - container.push_back( internal::parse_element< value_type >( value ) ); + if constexpr( requires { container.push_back( internal::parse_element< value_type >( value ) ); } ) { + container.push_back( internal::parse_element< value_type >( value ) ); + } + else { + container.insert( internal::parse_element< value_type >( value ) ); + } switch( *value++ ) { case ',': case ';': diff --git a/src/test/pq/array.cpp b/src/test/pq/array.cpp index 928b610..e7a311c 100644 --- a/src/test/pq/array.cpp +++ b/src/test/pq/array.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -69,7 +70,7 @@ namespace connection->execute( "DROP TABLE IF EXISTS tao_array_test" ); connection->execute( "CREATE TABLE tao_array_test ( a TEXT[][] NOT NULL )" ); - using type = std::vector< std::vector< std::string > >; + using type = std::vector< std::set< std::string > >; const type v = { { "1", "F\"O\\O", "NULL" }, { "4", " XYZ ", "6" } }; connection->execute( "INSERT INTO tao_array_test VALUES ( $1 )", v );