Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>,
	tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH 2/2] sql: allow <COLLATE> only for string-like args
Date: Sun, 12 May 2019 19:32:52 +0300	[thread overview]
Message-ID: <1abf945a-736f-735a-98c5-a85db184ddb5@tarantool.org> (raw)
In-Reply-To: <015351a65570062bdd3577b7222f047f7de7e89b.1557312975.git.roman.habibov@tarantool.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);
>  		}

  reply	other threads:[~2019-05-12 16:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 11:29 [tarantool-patches] [PATCH 0/2] " Roman Khabibov
2019-05-08 11:29 ` [tarantool-patches] [PATCH 1/2] sql: fix collation node duplication in AST Roman Khabibov
2019-05-12 16:32   ` [tarantool-patches] " Vladislav Shpilevoy
2019-05-28 14:10     ` Roman Khabibov
2019-06-02 17:09       ` Vladislav Shpilevoy
2019-06-04 14:00         ` Roman Khabibov
2019-05-08 11:29 ` [tarantool-patches] [PATCH 2/2] sql: allow <COLLATE> only for string-like args Roman Khabibov
2019-05-12 16:32   ` Vladislav Shpilevoy [this message]
2019-05-28 14:08     ` [tarantool-patches] " Roman Khabibov
2019-06-02 17:09       ` Vladislav Shpilevoy
2019-06-04 14:27         ` Roman Khabibov
2019-06-04 19:49           ` Vladislav Shpilevoy
2019-06-07 15:01             ` Roman Khabibov
2019-06-09 16:55               ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1abf945a-736f-735a-98c5-a85db184ddb5@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 2/2] sql: allow <COLLATE> only for string-like args' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox