提交 c571c38b 编写于 作者: S slguan

revise issue #124

上级 0da8e9ad
...@@ -63,8 +63,8 @@ void httpJsonString(JsonBuf* buf, char* sVal, int len); ...@@ -63,8 +63,8 @@ void httpJsonString(JsonBuf* buf, char* sVal, int len);
void httpJsonOriginString(JsonBuf* buf, char* sVal, int len); void httpJsonOriginString(JsonBuf* buf, char* sVal, int len);
void httpJsonStringForTransMean(JsonBuf* buf, char* SVal, int maxLen); void httpJsonStringForTransMean(JsonBuf* buf, char* SVal, int maxLen);
void httpJsonInt64(JsonBuf* buf, int64_t num); void httpJsonInt64(JsonBuf* buf, int64_t num);
void httpJsonTimestamp(JsonBuf* buf, int64_t t); void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us);
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t); void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us);
void httpJsonInt(JsonBuf* buf, int num); void httpJsonInt(JsonBuf* buf, int num);
void httpJsonFloat(JsonBuf* buf, float num); void httpJsonFloat(JsonBuf* buf, float num);
void httpJsonDouble(JsonBuf* buf, double num); void httpJsonDouble(JsonBuf* buf, double num);
......
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
#define REST_JSON_AFFECT_ROWS_LEN 13 #define REST_JSON_AFFECT_ROWS_LEN 13
#define REST_TIMESTAMP_FMT_LOCAL_STRING 0 #define REST_TIMESTAMP_FMT_LOCAL_STRING 0
#define REST_TIMESTAMP_FMT_TIMESTAMP 1 #define REST_TIMESTAMP_FMT_TIMESTAMP 1
#define REST_TIMESTAMP_FMT_UTC_STRING 2 #define REST_TIMESTAMP_FMT_UTC_STRING 2
void restBuildSqlAffectRowsJson(HttpContext *pContext, HttpSqlCmd *cmd, int affect_rows); void restBuildSqlAffectRowsJson(HttpContext *pContext, HttpSqlCmd *cmd, int affect_rows);
......
...@@ -260,30 +260,45 @@ void httpJsonInt64(JsonBuf* buf, int64_t num) { ...@@ -260,30 +260,45 @@ void httpJsonInt64(JsonBuf* buf, int64_t num) {
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%ld", num); buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%ld", num);
} }
void httpJsonTimestamp(JsonBuf* buf, int64_t t) { void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
char ts[30] = {0}; char ts[35] = {0};
struct tm *ptm;
int precision = 1000;
if (us) {
precision = 1000000;
}
struct tm* ptm; time_t tt = t / precision;
time_t tt = t / 1000;
ptm = localtime(&tt); ptm = localtime(&tt);
int length = (int)strftime(ts, 30, "%Y-%m-%d %H:%M:%S", ptm); int length = (int) strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm);
if (us) {
snprintf(ts+length, MAX_NUM_STR_SZ, ".%03ld", t % 1000); length += snprintf(ts + length, 8, ".%06ld", t % precision);
} else {
length += snprintf(ts + length, 5, ".%03ld", t % precision);
}
httpJsonString(buf, ts, length + 4); httpJsonString(buf, ts, length);
} }
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t) { void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us) {
char ts[35] = {0}; char ts[40] = {0};
struct tm *ptm; struct tm *ptm;
time_t tt = t / 1000; int precision = 1000;
if (us) {
precision = 1000000;
}
time_t tt = t / precision;
ptm = localtime(&tt); ptm = localtime(&tt);
int length = (int) strftime(ts, 35, "%Y-%m-%dT%H:%M:%S", ptm); int length = (int) strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm);
length += snprintf(ts + length, MAX_NUM_STR_SZ, ".%03ld", t % 1000); if (us) {
length += (int) strftime(ts + length, 35 - length, "%z", ptm); length += snprintf(ts + length, 8, ".%06ld", t % precision);
} else {
length += snprintf(ts + length, 5, ".%03ld", t % precision);
}
length += (int) strftime(ts + length, 40 - length, "%z", ptm);
httpJsonString(buf, ts, length + 4); httpJsonString(buf, ts, length);
} }
void httpJsonInt(JsonBuf* buf, int num) { void httpJsonInt(JsonBuf* buf, int num) {
......
...@@ -135,11 +135,11 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, ...@@ -135,11 +135,11 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) { if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) {
httpJsonTimestamp(jsonBuf, *((int64_t *)row[i])); httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO);
} else if (timestampFormat == REST_TIMESTAMP_FMT_TIMESTAMP) { } else if (timestampFormat == REST_TIMESTAMP_FMT_TIMESTAMP) {
httpJsonInt64(jsonBuf, *((int64_t *)row[i])); httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
} else { } else {
httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i])); httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO);
} }
break; break;
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册