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");
|
||||
|
||||
@ -501,7 +501,7 @@ static void httpd_send_headers(DCB *dcb, int final)
|
||||
|
||||
strftime(date, sizeof(date), fmt, localtime(&httpd_current_time));
|
||||
|
||||
dcb_printf(dcb, "HTTP/1.1 200 OK\r\nDate: %s\r\nServer: %s\r\nConnection: close\r\nContent-Type: text/plain\r\n", date, HTTP_SERVER_STRING);
|
||||
dcb_printf(dcb, "HTTP/1.1 200 OK\r\nDate: %s\r\nServer: %s\r\nConnection: close\r\nContent-Type: application/json\r\n", date, HTTP_SERVER_STRING);
|
||||
|
||||
/* close the headers */
|
||||
if (final) {
|
||||
|
||||
Reference in New Issue
Block a user