diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index b7772fd13..ced8bca83 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -287,22 +287,10 @@ void Query::PrintResultSet(std::ostream& fp, const std::vector& columns, else fp << ";"; - if (value.IsObjectType()) { - bool first_inner = true; - Array::Ptr arr = static_cast(value); - - ObjectLock rlock(arr); - BOOST_FOREACH(const Value& arr_val, arr) { - if (first_inner) - first_inner = false; - else - fp << ","; - - fp << Convert::ToString(arr_val); - } - } else { + if (value.IsObjectType()) + PrintCsvArray(fp, value, 0); + else fp << Convert::ToString(value); - } } fp << "\n"; @@ -312,6 +300,24 @@ void Query::PrintResultSet(std::ostream& fp, const std::vector& columns, } } +void Query::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) +{ + bool first = true; + + ObjectLock olock(array); + BOOST_FOREACH(const Value& value, array) { + if (first) + first = false; + else + fp << ((level == 0) ? "," : "|"); + + if (value.IsObjectType()) + PrintCsvArray(fp, value, level + 1); + else + fp << Convert::ToString(value); + } +} + void Query::ExecuteGetHelper(const Stream::Ptr& stream) { Log(LogInformation, "livestatus", "Table: " + m_Table); diff --git a/components/livestatus/query.h b/components/livestatus/query.h index 843e47c25..512c973b1 100644 --- a/components/livestatus/query.h +++ b/components/livestatus/query.h @@ -77,6 +77,7 @@ private: String m_ErrorMessage; void PrintResultSet(std::ostream& fp, const std::vector& columns, const Array::Ptr& rs); + void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level); void ExecuteGetHelper(const Stream::Ptr& stream); void ExecuteCommandHelper(const Stream::Ptr& stream);