From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v1 1/2] sql: properly check bind variable names Date: Sat, 20 Nov 2021 01:45:36 +0100 [thread overview] Message-ID: <f20d62b1-a6eb-ecd4-ed2d-2e699f2a4418@tarantool.org> (raw) In-Reply-To: <bdd4ececf501f97dcfbea220a47028b0cf7c3163.1637244389.git.imeevma@gmail.com> Thanks for the patch! Shouldn't these be the same? tarantool> box.execute('SELECT $name', {}) --- - null - Index of binding slots must start from 1 ... tarantool> box.execute('SELECT @name', {}) --- - metadata: - name: COLUMN_1 type: boolean rows: - [null] ... See 4 comments below. > diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c > index eb169aeb8..74a98c550 100644 > --- a/src/box/sql/expr.c > +++ b/src/box/sql/expr.c > @@ -1314,6 +1314,52 @@ sqlExprAssignVarNumber(Parse * pParse, Expr * pExpr, u32 n) > } > } > > +struct Expr * > +expr_variable(struct Parse *parse, struct Token *spec, struct Token *id) 1. You might want to call it expr_new_variable(). Or sql_expr_new_variable(). To be consistent with our naming policy for constructors allocating memory and for consistency with with sql_expr_new_column(), sql_expr_new(), sql_expr_new_dequoted(), sql_expr_new_named(), sql_expr_new_anon(). 2. spec and id can be made const. > +{ > + assert(spec != 0 && id != NULL && spec->n == 1); > + if (id->z - spec->z != 1) { > + diag_set(ClientError, ER_SQL_UNKNOWN_TOKEN, parse->line_count, > + spec->z - parse->zTail + 1, spec->n, spec->z); > + parse->is_aborted = true; > + return NULL; > + } > diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y > index 92fb37dd4..06e6244e3 100644 > --- a/src/box/sql/parse.y > +++ b/src/box/sql/parse.y > @@ -1087,31 +1087,29 @@ term(A) ::= INTEGER(X). { > A.zEnd = X.z + X.n; > if( A.pExpr ) A.pExpr->flags |= EP_Leaf; > } > -expr(A) ::= VARIABLE(X). { > - Token t = X; > +expr(A) ::= VARNUM(X). { > if (pParse->parse_only) { > - spanSet(&A, &t, &t); > diag_set(ClientError, ER_SQL_PARSER_GENERIC_WITH_POS, pParse->line_count, > pParse->line_pos, "bindings are not allowed in DDL"); > pParse->is_aborted = true; 3. Hm. It looks not so good that this complicated error is now in 2 places and is exactly the same. Maybe we could have a common function both for positional and named arguments? Or 2 functions, but they would use one more generic function inside? For instance, one function could be sql_expr_new_var(struct Parse *parse, const struct Token *spec, const struct Token *id); For positionals it would be called as sql_expr_new_var(pParse, &X, NULL); For named: sql_expr_new_var(pParse, &X, &Y); (like now) Then we could also drop TK_VARIABLE from spanExpr() completely. > A.pExpr = NULL; > - } else if (!(X.z[0]=='#' && sqlIsdigit(X.z[1]))) { > - u32 n = X.n; > + A.zEnd = &X.z[X.n]; > + } else { > spanExpr(&A, pParse, TK_VARIABLE, X); > - if (A.pExpr->u.zToken[0] == '?' && n > 1) { > - diag_set(ClientError, ER_SQL_SYNTAX_NEAR_TOKEN, pParse->line_count, t.n, t.z); > - pParse->is_aborted = true; > - } else { > - sqlExprAssignVarNumber(pParse, A.pExpr, n); > - } > - }else{ > - assert( t.n>=2 ); > - spanSet(&A, &t, &t); > - diag_set(ClientError, ER_SQL_SYNTAX_NEAR_TOKEN, pParse->line_count, t.n, t.z); > - pParse->is_aborted = true; > - A.pExpr = NULL; > + assert(A.pExpr->u.zToken[0] == '?' && X.n == 1); > + sqlExprAssignVarNumber(pParse, A.pExpr, X.n); > } > } > +expr(A) ::= VARIABLE(X) id(Y). { > + A.pExpr = expr_variable(pParse, &X, &Y); > + A.zStart = X.z; > + A.zEnd = &Y.z[Y.n]; > +} > +expr(A) ::= VARIABLE(X) INTEGER(Y). { > + A.pExpr = expr_variable(pParse, &X, &Y); > + A.zStart = X.z; > + A.zEnd = &Y.z[Y.n]; > +} 4. Lets drop the extra spaces before { symbols.
next prev parent reply other threads:[~2021-11-20 0:45 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-18 14:08 [Tarantool-patches] [PATCH v1 0/2] Introduce syntax for MAP values is SQL Mergen Imeev via Tarantool-patches 2021-11-18 14:08 ` [Tarantool-patches] [PATCH v1 1/2] sql: properly check bind variable names Mergen Imeev via Tarantool-patches 2021-11-20 0:45 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-11-25 8:33 ` Mergen Imeev via Tarantool-patches 2021-11-30 22:02 ` Vladislav Shpilevoy via Tarantool-patches 2021-12-02 8:32 ` Mergen Imeev via Tarantool-patches 2021-12-09 0:31 ` Vladislav Shpilevoy via Tarantool-patches 2021-12-13 7:34 ` Mergen Imeev via Tarantool-patches 2021-12-13 21:47 ` Vladislav Shpilevoy via Tarantool-patches 2021-11-18 14:08 ` [Tarantool-patches] [PATCH v1 2/2] sql: introduce syntax for MAP values Mergen Imeev via Tarantool-patches 2021-11-20 0:46 ` Vladislav Shpilevoy via Tarantool-patches 2021-11-25 8:55 ` Mergen Imeev via Tarantool-patches 2021-11-30 22:04 ` Vladislav Shpilevoy via Tarantool-patches 2021-12-02 8:38 ` Mergen Imeev via Tarantool-patches 2021-12-09 0:31 ` Vladislav Shpilevoy via Tarantool-patches 2021-12-13 7:42 ` Mergen Imeev via Tarantool-patches 2021-12-13 21:48 ` Vladislav Shpilevoy via Tarantool-patches
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=f20d62b1-a6eb-ecd4-ed2d-2e699f2a4418@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v1 1/2] sql: properly check bind variable names' \ /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