diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 19d537eb11a84ef7a5e64428b060a198f3497fb6..73337469b2b9a7ad696ba9a6dc24c734accd109a 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1584,9 +1584,6 @@ int tsInsertInitialCheck(SSqlObj *pSql) { int32_t index = 0; SSqlCmd *pCmd = &pSql->cmd; - SStrToken sToken = tStrGetToken(pSql->sqlstr, &index, false); - assert(sToken.type == TK_INSERT || sToken.type == TK_IMPORT); - pCmd->count = 0; pCmd->command = TSDB_SQL_INSERT; SInsertStatementParam* pInsertParam = &pCmd->insertParam; @@ -1594,6 +1591,11 @@ int tsInsertInitialCheck(SSqlObj *pSql) { SQueryInfo *pQueryInfo = tscGetQueryInfoS(pCmd); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT); + SStrToken sToken = tStrGetToken(pSql->sqlstr, &index, false); + if (sToken.type != TK_INSERT && sToken.type != TK_IMPORT) { + return tscSQLSyntaxErrMsg(pInsertParam->msg, NULL, sToken.z); + } + sToken = tStrGetToken(pSql->sqlstr, &index, false); if (sToken.type != TK_INTO) { return tscSQLSyntaxErrMsg(pInsertParam->msg, "keyword INTO is expected", sToken.z); diff --git a/tests/develop-test/2-query/TD-13246.py b/tests/develop-test/2-query/TD-13246.py new file mode 100644 index 0000000000000000000000000000000000000000..e9675f8a0c99e8b528b13e77a05754b6d23e3d61 --- /dev/null +++ b/tests/develop-test/2-query/TD-13246.py @@ -0,0 +1,56 @@ +################################################################### +# Copyright (c) 2021 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def caseDescription(self): + ''' + case1: [TD-13246] Coredump when parentheses appear before the insert_sql + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self._conn = conn + + def run(self): + print("running {}".format(__file__)) + tdSql.prepare() + + tdSql.execute('create stable st(ts timestamp , value int) tags (ind int)') + tdSql.execute('create table ctb using st tags(1)') + tdSql.execute('create table tb (ts timestamp, value int)') + tdSql.query('insert into ctb values(now, 1)'); + tdSql.query('insert into tb values(now, 1)'); + + tdSql.error('(insert into ctb values(now, 1)'); + tdSql.error('(insert into tb values(now, 1)'); + tdSql.error('(insert into ctb values'); + tdSql.error('(insert into ctb'); + tdSql.error('(insert into'); + tdSql.error('(insert'); + tdSql.error('('); + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/develop-test/fulltest-query.sh b/tests/develop-test/fulltest-query.sh index c91c592adfbee5b48b9cc0fac3fade70ff4a611c..f5523576401a2144083207f40e9430df846ffe14 100755 --- a/tests/develop-test/fulltest-query.sh +++ b/tests/develop-test/fulltest-query.sh @@ -7,3 +7,4 @@ python3 ./test.py -f 2-query/ts_2016.py python3 ./test.py -f 2-query/escape.py python3 ./test.py -f 2-query/function_mavg.py python3 ./test.py -f 2-query/func_compare.py +python3 ./test.py -f 2-query/TD-13246.py