未验证 提交 b6c6f866 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #16514 from taosdata/fix/ZhiqiangWang/TD-18733-shell-csv-rfc-4180

feature: shell csv rfc 4180
char version[12] = "${TD_VER_NUMBER}";
char version[64] = "${TD_VER_NUMBER}";
char compatible_version[12] = "${TD_VER_COMPATIBLE}";
char gitinfo[48] = "${TD_VER_GIT}";
char buildinfo[64] = "Built at ${TD_VER_DATE}";
......
......@@ -492,7 +492,6 @@ static char* shellFormatTimestamp(char* buf, int64_t val, int32_t precision) {
static void shellDumpFieldToFile(TdFilePtr pFile, const char* val, TAOS_FIELD* field, int32_t length,
int32_t precision) {
if (val == NULL) {
taosFprintfFile(pFile, "%s", TSDB_DATA_NULL_STR);
return;
}
......@@ -540,13 +539,34 @@ static void shellDumpFieldToFile(TdFilePtr pFile, const char* val, TAOS_FIELD* f
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON:
memcpy(buf, val, length);
buf[length] = 0;
taosFprintfFile(pFile, "\'%s\'", buf);
{
char quotationStr[2];
int32_t bufIndex = 0;
quotationStr[0] = 0;
quotationStr[1] = 0;
for (int32_t i = 0; i < length; i++) {
buf[bufIndex] = val[i];
bufIndex++;
if (val[i] == '\"') {
buf[bufIndex] = val[i];
bufIndex++;
quotationStr[0] = '\"';
}
if (val[i] == ',') {
quotationStr[0] = '\"';
}
}
buf[bufIndex] = 0;
if (length == 0) {
quotationStr[0] = '\"';
}
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
}
break;
case TSDB_DATA_TYPE_TIMESTAMP:
shellFormatTimestamp(buf, *(int64_t*)val, precision);
taosFprintfFile(pFile, "'%s'", buf);
taosFprintfFile(pFile, "%s", buf);
break;
default:
break;
......
......@@ -266,7 +266,6 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) {
void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision) {
if (val == NULL) {
taosFprintfFile(pFile, "%s", TSDB_DATA_NULL_STR);
return;
}
......@@ -314,13 +313,34 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON:
memcpy(buf, val, length);
buf[length] = 0;
taosFprintfFile(pFile, "\'%s\'", buf);
{
char quotationStr[2];
int32_t bufIndex = 0;
quotationStr[0] = 0;
quotationStr[1] = 0;
for (int32_t i = 0; i < length; i++) {
buf[bufIndex] = val[i];
bufIndex++;
if (val[i] == '\"') {
buf[bufIndex] = val[i];
bufIndex++;
quotationStr[0] = '\"';
}
if (val[i] == ',') {
quotationStr[0] = '\"';
}
}
buf[bufIndex] = 0;
if (length == 0) {
quotationStr[0] = '\"';
}
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
}
break;
case TSDB_DATA_TYPE_TIMESTAMP:
shellFormatTimestamp(buf, *(int64_t *)val, precision);
taosFprintfFile(pFile, "'%s'", buf);
taosFprintfFile(pFile, "%s", buf);
break;
default:
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册