Make JSON result sets produce nmeric valeus without quotes
Updated HTTPD protocol module to return application/json as the encoding
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <resultset.h>
|
||||
#include <buffer.h>
|
||||
#include <dcb.h>
|
||||
@ -402,6 +403,24 @@ uint8_t *ptr;
|
||||
return dcb->func.write(dcb, pkt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the string only contains numerics
|
||||
*
|
||||
* @param value String to test
|
||||
* @return Non-zero if the string is made of of numeric values
|
||||
*/
|
||||
static int
|
||||
value_is_numeric(char *value)
|
||||
{
|
||||
while (*value)
|
||||
{
|
||||
if (!isdigit(*value))
|
||||
return 0;
|
||||
value++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream a result set encoding it as a JSON object
|
||||
* Each row is retrieved by calling the function passed in the
|
||||
@ -430,7 +449,9 @@ int rowno = 0;
|
||||
{
|
||||
|
||||
dcb_printf(dcb, "\"%s\" : ", col->name);
|
||||
if (row->cols[i])
|
||||
if (row->cols[i] && value_is_numeric(row->cols[i]))
|
||||
dcb_printf(dcb, "%s", row->cols[i]);
|
||||
else if (row->cols[i])
|
||||
dcb_printf(dcb, "\"%s\"", row->cols[i]);
|
||||
else
|
||||
dcb_printf(dcb, "NULL");
|
||||
|
||||
Reference in New Issue
Block a user