add error case

This commit is contained in:
Bob Liu 2023-12-06 10:11:52 +08:00
parent 17866b2b85
commit 1ec8bf9ef9
2 changed files with 21 additions and 15 deletions

View File

@ -126,16 +126,19 @@ int32_t toDoubleEx(const char *z, int32_t n, uint32_t type, double* value) {
*value = 0; *value = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// rm tail space
while (n > 1 && z[n-1] == ' ') {
n--;
}
errno = 0; errno = 0;
char* endPtr = NULL; char* endPtr = NULL;
*value = taosStr2Double(z, &endPtr); *value = taosStr2Double(z, &endPtr);
if (errno == ERANGE || errno == EINVAL || endPtr - z != n) { if (errno == ERANGE || errno == EINVAL) {
return TSDB_CODE_FAILED;
}
// rm tail space
while (n > 1 && z[n-1] == ' ') {
n--;
}
if (endPtr - z != n) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -152,12 +155,12 @@ int32_t toIntegerEx(const char *z, int32_t n, uint32_t type, int64_t *value) {
parsed = true; parsed = true;
} break; } break;
case TK_NK_FLOAT: { case TK_NK_FLOAT: {
double val = taosStr2Double(z, &endPtr); double val = round(taosStr2Double(z, &endPtr));
parsed = true; parsed = true;
if (!IS_VALID_INT64(val)) { if (!IS_VALID_INT64(val)) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
*value = round(val); *value = val;
} break; } break;
default: default:
break; break;
@ -167,7 +170,7 @@ int32_t toIntegerEx(const char *z, int32_t n, uint32_t type, int64_t *value) {
if (errno == ERANGE || errno == EINVAL) { if (errno == ERANGE || errno == EINVAL) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
while (n > 0 && z[n-1] == ' ') { while (n > 1 && z[n-1] == ' ') {
n--; n--;
} }
if (endPtr - z != n) { if (endPtr - z != n) {
@ -176,7 +179,7 @@ int32_t toIntegerEx(const char *z, int32_t n, uint32_t type, int64_t *value) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
// parse string // parse as string
if (n == 0) { if (n == 0) {
*value = 0; *value = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -231,7 +234,7 @@ int32_t toUIntegerEx(const char *z, int32_t n, uint32_t type, uint64_t *value) {
break; break;
} }
// parse string // parse as string
if (n == 0) { if (n == 0) {
*value = 0; *value = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;

View File

@ -72,11 +72,14 @@ class TDTestCase:
tdSql.query(f"select * from {table_name}") tdSql.query(f"select * from {table_name}")
tdSql.checkRows(26) tdSql.checkRows(26)
# fail # error case
tdSql.error(f"insert into {table_name} values(now, 0, {max_u+1})", "error") tdSql.error(f"insert into {table_name} values(now, 0, {max_u+1})")
tdSql.error(f"insert into {table_name} values(now, 0, {max_u+1})", "error") tdSql.error(f"insert into {table_name} values(now, 0, -1)")
tdSql.error(f"insert into {table_name} values(now, {max_i+1}, -1)", "error") tdSql.error(f"insert into {table_name} values(now, 0, -2.0)")
tdSql.error(f"insert into {table_name} values(now, 0, '-2.0')")
tdSql.error(f"insert into {table_name} values(now, {max_i+1}, 0)")
tdSql.error(f"insert into {table_name} values(now, {min_i-1}, 0)")
tdSql.error(f"insert into {table_name} values(now, '{min_i-1}', 0)")
def test_tags(self, stable_name, dtype, bits): def test_tags(self, stable_name, dtype, bits):
tdSql.execute(f"create stable {stable_name}(ts timestamp, i1 {dtype}, i2 {dtype} unsigned) tags(id {dtype})") tdSql.execute(f"create stable {stable_name}(ts timestamp, i1 {dtype}, i2 {dtype} unsigned) tags(id {dtype})")