Merge branch '2.3' into 2.4

This commit is contained in:
Markus Mäkelä
2019-10-10 21:42:43 +03:00
12 changed files with 854 additions and 231 deletions

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);
@ -227,4 +245,6 @@ void ResultSet::write_as_json(DCB* dcb)
char* js = json_dumps(arr, JSON_INDENT(4));
dcb_printf(dcb, "%s", js);
MXS_FREE(js);
json_decref(arr);
}