From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 624922C75D for ; Sun, 12 May 2019 12:32:54 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HMmiJFKoiZE5 for ; Sun, 12 May 2019 12:32:54 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 21CF72C738 for ; Sun, 12 May 2019 12:32:54 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 2/2] sql: allow only for string-like args References: <015351a65570062bdd3577b7222f047f7de7e89b.1557312975.git.roman.habibov@tarantool.org> From: Vladislav Shpilevoy Message-ID: <1abf945a-736f-735a-98c5-a85db184ddb5@tarantool.org> Date: Sun, 12 May 2019 19:32:52 +0300 MIME-Version: 1.0 In-Reply-To: <015351a65570062bdd3577b7222f047f7de7e89b.1557312975.git.roman.habibov@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: Roman Khabibov , tarantool-patches@freelists.org Sorry, the patch does not work: tarantool> box.execute('SELECT NOT TRUE COLLATE "unicode"') --- - metadata: - name: NOT TRUE COLLATE "unicode" type: boolean rows: - [false] ... Obviously, 'NOT TRUE' is not a string. Strange, but without 'NOT' everything is fine: tarantool> box.execute('SELECT TRUE COLLATE "unicode"') --- - error: COLLATE can't be used with non-string arguments ... Please, fix. > diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c > index ba7eea59d..29e3386fa 100644 > --- a/src/box/sql/expr.c > +++ b/src/box/sql/expr.c > @@ -4215,6 +4215,22 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) > } > case TK_SPAN: > case TK_COLLATE:{ > + enum field_type type; > + struct Expr *left = pExpr->pLeft; > + if (left->op == TK_COLUMN) { > + int col_num = left->iColumn; > + type = left->space_def->fields[col_num].type; > + } else > + type = left->type; > + if (left->op != TK_CONCAT && Why do you check for TK_CONCAT? Its type should be FIELD_TYPE_STRING. > + type != FIELD_TYPE_STRING && > + type != FIELD_TYPE_SCALAR) { > + diag_set(ClientError, ER_SQL_PARSER_GENERIC, > + "COLLATE can't be used with " > + "non-string arguments"); > + pParse->is_aborted = true; > + break; > + } > return sqlExprCodeTarget(pParse, pExpr->pLeft, > target); > }