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 C079F25B1A for ; Wed, 13 Jun 2018 14:53:25 -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 QllZYUEnntO9 for ; Wed, 13 Jun 2018 14:53:25 -0400 (EDT) Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 7D44D259A5 for ; Wed, 13 Jun 2018 14:53:25 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 06/11] sql: refactor sql_expr_compile to return AST References: <74d9d3a2f3198fc4821395b91bb7b637b35af5d3.1528535873.git.kshcherbatov@tarantool.org> From: Vladislav Shpilevoy Message-ID: <01231fae-68d6-f6c3-5ead-8df59efae4cf@tarantool.org> Date: Wed, 13 Jun 2018 21:53:20 +0300 MIME-Version: 1.0 In-Reply-To: <74d9d3a2f3198fc4821395b91bb7b637b35af5d3.1528535873.git.kshcherbatov@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed 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: tarantool-patches@freelists.org, Kirill Shcherbatov Thanks for the patch! See 1 comment below. On 09/06/2018 12:32, Kirill Shcherbatov wrote: > --- > src/box/alter.cc | 6 +++--- > src/box/sql.c | 5 +++-- > src/box/sql.h | 9 ++++----- > src/box/sql/tokenize.c | 33 +++++++++++++++++++++------------ > 4 files changed, 31 insertions(+), 22 deletions(-) > > diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c > index 42c70a2..5b7c97d 100644 > --- a/src/box/sql/tokenize.c > +++ b/src/box/sql/tokenize.c > @@ -550,19 +555,23 @@ sql_expr_compile(sqlite3 *db, const char *expr, int expr_len, > sql_parser_create(&parser, db); > parser.parse_only = true; > > + struct Expr *expression = NULL; > char *stmt = (char *)region_alloc(&parser.region, len + 1); > if (stmt == NULL) { > diag_set(OutOfMemory, len + 1, "region_alloc", "stmt"); > - return -1; > + return NULL; > } > sprintf(stmt, "%s%.*s", outer, expr_len, expr); > > - char *unused; > - if (sqlite3RunParser(&parser, stmt, &unused) != SQLITE_OK) { > - diag_set(ClientError, ER_SQL_EXECUTE, expr); > - return -1; > + char *sql_error; > + if (sqlite3RunParser(&parser, stmt, &sql_error) != SQLITE_OK) { > + char *error = tt_static_buf(); > + snprintf(error, TT_STATIC_BUF_LEN, "%s", sql_error); > + diag_set(ClientError, ER_SQL, error); > + sqlite3DbFree(db, sql_error); Why not just diag_set(ClientError, ER_SQL, sql_error); ? > + } else { > + expression = parser.parsed_expr; > } > - *result = parser.parsed_expr; > sql_parser_destroy(&parser); > - return 0; > + return expression; > } >