未验证 提交 69eb1271 编写于 作者: S slguan 提交者: GitHub

Merge pull request #1760 from taosdata/newmaster/lihui

[TD-207,TD-213]
...@@ -1438,6 +1438,9 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) { ...@@ -1438,6 +1438,9 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
pTableDataBlock->size = sizeof(SShellSubmitBlock); pTableDataBlock->size = sizeof(SShellSubmitBlock);
pTableDataBlock->rowSize = pMeterMeta->rowSize; pTableDataBlock->rowSize = pMeterMeta->rowSize;
code = tscAllocateMemIfNeed(pTableDataBlock, rowSize, &maxRows);
if (TSDB_CODE_SUCCESS != code) return -1;
numOfRows += pSql->res.numOfRows; numOfRows += pSql->res.numOfRows;
pSql->res.numOfRows = 0; pSql->res.numOfRows = 0;
count = 0; count = 0;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <unistd.h> #include <unistd.h>
#include <wordexp.h> #include <wordexp.h>
#include <iconv.h> #include <iconv.h>
#include <time.h>
#include "taos.h" #include "taos.h"
#include "taosmsg.h" #include "taosmsg.h"
...@@ -162,6 +163,7 @@ static struct argp_option options[] = { ...@@ -162,6 +163,7 @@ static struct argp_option options[] = {
{"password", 'p', "PASSWORD", 0, "User password to connect to server. Default is taosdata.", 0}, {"password", 'p', "PASSWORD", 0, "User password to connect to server. Default is taosdata.", 0},
{"port", 'P', "PORT", 0, "Port to connect", 0}, {"port", 'P', "PORT", 0, "Port to connect", 0},
{"cversion", 'v', "CVERION", 0, "client version", 0}, {"cversion", 'v', "CVERION", 0, "client version", 0},
{"mysqlFlag", 'q', "MYSQLFLAG", 0, "mysqlFlag, Default is 0", 0},
// input/output file // input/output file
{"outpath", 'o', "OUTPATH", 0, "Output file path.", 1}, {"outpath", 'o', "OUTPATH", 0, "Output file path.", 1},
{"inpath", 'i', "INPATH", 0, "Input file path.", 1}, {"inpath", 'i', "INPATH", 0, "Input file path.", 1},
...@@ -189,6 +191,7 @@ struct arguments { ...@@ -189,6 +191,7 @@ struct arguments {
char *password; char *password;
uint16_t port; uint16_t port;
char cversion[TSDB_FILENAME_LEN+1]; char cversion[TSDB_FILENAME_LEN+1];
uint16_t mysqlFlag;
// output file // output file
char outpath[TSDB_FILENAME_LEN+1]; char outpath[TSDB_FILENAME_LEN+1];
char inpath[TSDB_FILENAME_LEN+1]; char inpath[TSDB_FILENAME_LEN+1];
...@@ -236,6 +239,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -236,6 +239,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case 'P': case 'P':
arguments->port = atoi(arg); arguments->port = atoi(arg);
break; break;
case 'q':
arguments->sqlCmdFlag = atoi(arg);
break;
case 'v': case 'v':
if (wordexp(arg, &full_path, 0) != 0) { if (wordexp(arg, &full_path, 0) != 0) {
fprintf(stderr, "Invalid client vesion %s\n", arg); fprintf(stderr, "Invalid client vesion %s\n", arg);
...@@ -341,6 +347,7 @@ struct arguments tsArguments = { ...@@ -341,6 +347,7 @@ struct arguments tsArguments = {
"taosdata", "taosdata",
0, 0,
"", "",
0,
// outpath and inpath // outpath and inpath
"", "",
"", "",
...@@ -384,7 +391,8 @@ int main(int argc, char *argv[]) { ...@@ -384,7 +391,8 @@ int main(int argc, char *argv[]) {
printf("user: %s\n", tsArguments.user); printf("user: %s\n", tsArguments.user);
printf("password: %s\n", tsArguments.password); printf("password: %s\n", tsArguments.password);
printf("port: %u\n", tsArguments.port); printf("port: %u\n", tsArguments.port);
printf("cversion: %s\n", tsArguments.cversion); printf("cversion: %s\n", tsArguments.cversion);
printf("mysqlFlag: %d", tsArguments.mysqlFlag);
printf("outpath: %s\n", tsArguments.outpath); printf("outpath: %s\n", tsArguments.outpath);
printf("inpath: %s\n", tsArguments.inpath); printf("inpath: %s\n", tsArguments.inpath);
printf("encode: %s\n", tsArguments.encode); printf("encode: %s\n", tsArguments.encode);
...@@ -918,6 +926,8 @@ void taosDumpCreateDbClause(SDbInfo *dbInfo, bool isDumpProperty, FILE *fp) { ...@@ -918,6 +926,8 @@ void taosDumpCreateDbClause(SDbInfo *dbInfo, bool isDumpProperty, FILE *fp) {
dbInfo->ablocks, dbInfo->tblocks, dbInfo->ctime, dbInfo->clog, dbInfo->comp); dbInfo->ablocks, dbInfo->tblocks, dbInfo->ctime, dbInfo->clog, dbInfo->comp);
} }
pstr += sprintf(pstr, ";");
fprintf(fp, "%s\n\n", tmpCommand); fprintf(fp, "%s\n\n", tmpCommand);
free(tmpCommand); free(tmpCommand);
} }
...@@ -1236,7 +1246,7 @@ void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, FILE *fp) { ...@@ -1236,7 +1246,7 @@ void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, FILE *fp) {
} }
} }
pstr += sprintf(pstr, ")"); pstr += sprintf(pstr, ");");
fprintf(fp, "%s\n", tmpBuf); fprintf(fp, "%s\n", tmpBuf);
...@@ -1289,7 +1299,7 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols ...@@ -1289,7 +1299,7 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
/* } */ /* } */
} }
pstr += sprintf(pstr, ")"); pstr += sprintf(pstr, ");");
fprintf(fp, "%s\n", tmpBuf); fprintf(fp, "%s\n", tmpBuf);
free(tmpBuf); free(tmpBuf);
...@@ -1359,14 +1369,31 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS* ...@@ -1359,14 +1369,31 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
return -1; return -1;
} }
char sqlStr[8] = "\0";
if (arguments->mysqlFlag) {
sprintf(sqlStr, "INSERT");
} else {
sprintf(sqlStr, "IMPORT");
}
int rowFlag = 0;
count = 0; count = 0;
while ((row = taos_fetch_row(tmpResult)) != NULL) { while ((row = taos_fetch_row(tmpResult)) != NULL) {
pstr = tmpBuffer; pstr = tmpBuffer;
if (count == 0) { if (count == 0) {
pstr += sprintf(pstr, "IMPORT INTO %s VALUES (", tbname); pstr += sprintf(pstr, "%s INTO %s VALUES (", sqlStr, tbname);
} else { } else {
pstr += sprintf(pstr, "("); if (arguments->mysqlFlag) {
if (0 == rowFlag) {
pstr += sprintf(pstr, "(");
rowFlag++;
} else {
pstr += sprintf(pstr, ", (");
}
} else {
pstr += sprintf(pstr, "(");
}
} }
for (int col = 0; col < numFields; col++) { for (int col = 0; col < numFields; col++) {
...@@ -1410,12 +1437,22 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS* ...@@ -1410,12 +1437,22 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
pstr += sprintf(pstr, "\'%s\'", tbuf); pstr += sprintf(pstr, "\'%s\'", tbuf);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
pstr += sprintf(pstr, "%" PRId64 "", *(int64_t *)row[col]); if (!arguments->mysqlFlag) {
pstr += sprintf(pstr, "%" PRId64 "", *(int64_t *)row[col]);
} else {
char buf[64] = "\0";
int64_t ts = *((int64_t *)row[col]);
time_t tt = (time_t)(ts / 1000);
struct tm *ptm = localtime(&tt);
strftime(buf, 64, "%y-%m-%d %H:%M:%S", ptm);
pstr += sprintf(pstr, "\'%s.%03d\'", buf, (int)(ts % 1000));
}
break; break;
default: default:
break; break;
} }
} }
pstr += sprintf(pstr, ") "); pstr += sprintf(pstr, ") ");
totalRows++; totalRows++;
...@@ -1423,7 +1460,7 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS* ...@@ -1423,7 +1460,7 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
fprintf(fp, "%s", tmpBuffer); fprintf(fp, "%s", tmpBuffer);
if (count >= arguments->data_batch) { if (count >= arguments->data_batch) {
fprintf(fp, "\n"); fprintf(fp, ";\n");
count = 0; count = 0;
} //else { } //else {
//fprintf(fp, "\\\n"); //fprintf(fp, "\\\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册