[tarantool-patches] Re: [PATCH 2/2] sql: allow <COLLATE> only for string-like args

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun May 12 19:32:52 MSK 2019


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);
>  		}




More information about the Tarantool-patches mailing list