From 90697d04401f470247a681911c50d65de06ad634 Mon Sep 17 00:00:00 2001 From: dengyihao Date: Mon, 15 Jun 2020 01:55:39 +0800 Subject: [PATCH] bugfix TD-690 --- src/client/src/tscSQLParser.c | 8 ++++++++ src/query/inc/sql.y | 14 +++++++++++--- src/query/src/qparserImpl.c | 12 ++++++++++-- src/query/src/sql.c | 22 +++++++++++++++------- 4 files changed, 44 insertions(+), 12 deletions(-) mode change 100644 => 100755 src/query/src/sql.c diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 494540290b..788d53e00a 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -752,6 +752,10 @@ static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd) { int32_t nLen = 0; for (int32_t i = 0; i < pFieldList->nField; ++i) { + if (pFieldList->p[i].bytes == 0) { + invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5); + return false; + } nLen += pFieldList->p[i].bytes; } @@ -808,6 +812,10 @@ static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSq int32_t nLen = 0; for (int32_t i = 0; i < pTagsList->nField; ++i) { + if (pTagsList->p[i].bytes == 0) { + invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7); + return false; + } nLen += pTagsList->p[i].bytes; } diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 4a20502e4e..b4ea1254b7 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -251,12 +251,20 @@ alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLeve alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); } %type typename {TAOS_FIELD} -typename(A) ::= ids(X). { tSQLSetColumnType (&A, &X); } +typename(A) ::= ids(X). { + X.type = 0; + tSQLSetColumnType (&A, &X); +} //define binary type, e.g., binary(10), nchar(10) typename(A) ::= ids(X) LP signed(Y) RP. { - X.type = -Y; // negative value of name length - tSQLSetColumnType(&A, &X); + if (Y <= 0) { + X.type = 0; + tSQLSetColumnType(&A, &X); + } else { + X.type = -Y; // negative value of name length + tSQLSetColumnType(&A, &X); + } } %type signed {int64_t} diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index 87add1e69e..928b9eb873 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -497,10 +497,18 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) { * number of bytes in UCS-4 format, which is 4 times larger than the * number of characters */ - pField->bytes = -(int32_t)type->type * TSDB_NCHAR_SIZE + LENGTH_SIZE_OF_STR; + if (type->type == 0) { + pField->bytes = 0; + } else { + pField->bytes = -(int32_t)type->type * TSDB_NCHAR_SIZE + LENGTH_SIZE_OF_STR; + } } else if (i == TSDB_DATA_TYPE_BINARY) { /* for binary, the TOKENTYPE is the length of binary */ - pField->bytes = -(int32_t) type->type + LENGTH_SIZE_OF_STR; + if (type->type == 0) { + pField->bytes = 0; + } else { + pField->bytes = -(int32_t) type->type + LENGTH_SIZE_OF_STR; + } } break; } diff --git a/src/query/src/sql.c b/src/query/src/sql.c old mode 100644 new mode 100755 index 545cef4082..e75802a98f --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -25,17 +25,17 @@ #include /************ Begin %include sections from the grammar ************************/ -#include -#include +#include #include #include +#include +#include +#include "tutil.h" #include "qsqlparser.h" #include "tstoken.h" -#include "tutil.h" #include "tvariant.h" #include "ttokendef.h" #include "qsqltype.h" - /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols ** in a format understandable to "makeheaders". This section is blank unless @@ -2262,13 +2262,21 @@ static void yy_reduce( { setDefaultCreateDbOption(&yymsp[1].minor.yy374);} break; case 102: /* typename ::= ids */ -{ tSQLSetColumnType (&yylhsminor.yy325, &yymsp[0].minor.yy0); } +{ + yymsp[0].minor.yy0.type = 0; + tSQLSetColumnType (&yylhsminor.yy325, &yymsp[0].minor.yy0); +} yymsp[0].minor.yy325 = yylhsminor.yy325; break; case 103: /* typename ::= ids LP signed RP */ { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy279; // negative value of name length - tSQLSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); + if (yymsp[-1].minor.yy279 <= 0) { + yymsp[-3].minor.yy0.type = 0; + tSQLSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); + } else { + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy279; // negative value of name length + tSQLSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); + } } yymsp[-3].minor.yy325 = yylhsminor.yy325; break; -- GitLab