MXS-2706: Fix maxinfo JSON output

The output now correctly formats integers.
This commit is contained in:
Markus Mäkelä 2019-10-07 11:37:24 +03:00
parent 65e18b0c91
commit 026109f9bc
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 20 additions and 1 deletions

View File

@ -64,4 +64,5 @@ private:
std::vector<std::vector<std::string>> m_rows;
ResultSet(std::initializer_list<std::string> names);
json_t* get_json_value(const std::string& s);
};

View File

@ -208,6 +208,24 @@ void ResultSet::write(DCB* dcb)
mysql_send_eof(dcb, seqno);
}
json_t* ResultSet::get_json_value(const std::string& s)
{
json_t* js;
char* end;
long l = strtol(s.c_str(), &end, 10);
if (end != s.c_str() && *end == '\0')
{
js = json_integer(l);
}
else
{
js = json_string(s.c_str());
}
return js;
}
void ResultSet::write_as_json(DCB* dcb)
{
json_t* arr = json_array();
@ -218,7 +236,7 @@ void ResultSet::write_as_json(DCB* dcb)
for (size_t i = 0; i < row.size(); i++)
{
json_object_set_new(obj, m_columns[i].c_str(), json_string(row[i].c_str()));
json_object_set_new(obj, m_columns[i].c_str(), get_json_value(row[i]));
}
json_array_append_new(arr, obj);