提交 9b6a1ab4 编写于 作者: H huili

[Support using capitalized by table/db name]

上级 551b590b
...@@ -207,7 +207,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -207,7 +207,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; SSQLToken* pToken = &pInfo->pDCLInfo->a[0];
tscValidateName(pToken); if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
char msg1[] = "invalid db name";
setErrMsg(pCmd, msg1, tListLen(msg1));
return TSDB_CODE_INVALID_SQL;
}
if (pToken->n > TSDB_DB_NAME_LEN) { if (pToken->n > TSDB_DB_NAME_LEN) {
setErrMsg(pCmd, msg, tListLen(msg)); setErrMsg(pCmd, msg, tListLen(msg));
...@@ -393,7 +397,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -393,7 +397,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; SSQLToken* pToken = &pInfo->pDCLInfo->a[0];
char msg[] = "table name is too long"; char msg[] = "table name is too long";
tscValidateName(pToken); if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
char msg1[] = "invalid table name";
setErrMsg(pCmd, msg1, tListLen(msg1));
return TSDB_CODE_INVALID_SQL;
}
if (pToken->n > TSDB_METER_NAME_LEN) { if (pToken->n > TSDB_METER_NAME_LEN) {
setErrMsg(pCmd, msg, tListLen(msg)); setErrMsg(pCmd, msg, tListLen(msg));
...@@ -571,7 +579,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -571,7 +579,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
// metric name, create table by using dst // metric name, create table by using dst
SSQLToken* pToken = &(pInfo->pCreateTableInfo->usingInfo.metricName); SSQLToken* pToken = &(pInfo->pCreateTableInfo->usingInfo.metricName);
tscValidateName(pToken); if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
setErrMsg(pCmd, msg, tListLen(msg));
return TSDB_CODE_INVALID_SQL;
}
int32_t ret = setMeterID(pSql, pToken); int32_t ret = setMeterID(pSql, pToken);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -739,7 +750,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -739,7 +750,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
tscValidateName(&(pQuerySql->from)); if (tscValidateName(&(pQuerySql->from)) != TSDB_CODE_SUCCESS) {
char msg[] = "invalid table name";
setErrMsg(pCmd, msg, tListLen(msg));
return TSDB_CODE_INVALID_SQL;
}
if (setMeterID(pSql, &pQuerySql->from) != TSDB_CODE_SUCCESS) { if (setMeterID(pSql, &pQuerySql->from) != TSDB_CODE_SUCCESS) {
char msg[] = "table name too long"; char msg[] = "table name too long";
...@@ -3477,7 +3492,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -3477,7 +3492,11 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo; SAlterTableSQL* pAlterSQL = pInfo->pAlterInfo;
pCmd->command = TSDB_SQL_ALTER_TABLE; pCmd->command = TSDB_SQL_ALTER_TABLE;
tscValidateName(&(pAlterSQL->name)); if (tscValidateName(&(pAlterSQL->name)) != TSDB_CODE_SUCCESS) {
char msg[] = "invalid table name";
setErrMsg(pCmd, msg, tListLen(msg));
return TSDB_CODE_INVALID_SQL;
}
if (setMeterID(pSql, &(pAlterSQL->name)) != TSDB_CODE_SUCCESS) { if (setMeterID(pSql, &(pAlterSQL->name)) != TSDB_CODE_SUCCESS) {
char msg[] = "table name too long"; char msg[] = "table name too long";
......
...@@ -800,9 +800,16 @@ static int32_t validateQuoteToken(SSQLToken* pToken) { ...@@ -800,9 +800,16 @@ static int32_t validateQuoteToken(SSQLToken* pToken) {
pToken->n = (uint32_t)strlen(pToken->z); pToken->n = (uint32_t)strlen(pToken->z);
int32_t k = tSQLGetToken(pToken->z, &pToken->type); int32_t k = tSQLGetToken(pToken->z, &pToken->type);
if (k != pToken->n || pToken->type != TK_ID) {
if (k != pToken->n) {
if (pToken->type == TK_STRING) {
return tscValidateName(pToken);
}
} else {
if (pToken->type != TK_ID) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -812,7 +819,7 @@ int32_t tscValidateName(SSQLToken* pToken) { ...@@ -812,7 +819,7 @@ int32_t tscValidateName(SSQLToken* pToken) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n); char* sep = strnchrNoquote(pToken->z, TS_PATH_DELIMITER[0], pToken->n);
if (sep == NULL) { // single part if (sep == NULL) { // single part
if (pToken->type == TK_STRING) { if (pToken->type == TK_STRING) {
return validateQuoteToken(pToken); return validateQuoteToken(pToken);
......
...@@ -155,6 +155,7 @@ int32_t strdequote(char *src); ...@@ -155,6 +155,7 @@ int32_t strdequote(char *src);
void strtrim(char *src); void strtrim(char *src);
char *strnchr(char *haystack, char needle, int32_t len); char *strnchr(char *haystack, char needle, int32_t len);
char *strnchrNoquote(char *haystack, char needle, int32_t len);
char **strsplit(char *src, const char *delim, int32_t *num); char **strsplit(char *src, const char *delim, int32_t *num);
......
...@@ -131,6 +131,26 @@ char *strnchr(char *haystack, char needle, int32_t len) { ...@@ -131,6 +131,26 @@ char *strnchr(char *haystack, char needle, int32_t len) {
return NULL; return NULL;
} }
char *strnchrNoquote(char *haystack, char needle, int32_t len) {
for (int32_t i = 0; i < len; ++i) {
if (haystack[i] == '\'' || haystack[i] == '"') {
char quote = haystack[i++];
while(i < len && haystack[i] != quote){++i;}
if (++i >= len) {
return NULL;
}
}
if (haystack[i] == needle) {
return &haystack[i];
}
}
return NULL;
}
void strtolower(char *z, char *dst) { void strtolower(char *z, char *dst) {
int quote = 0; int quote = 0;
char *str = z; char *str = z;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册