Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Imeev Mergen <imeevma@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v3 3/9] sql: remove field nErr of struct Parse
Date: Tue, 5 Mar 2019 12:06:26 +0300	[thread overview]
Message-ID: <5CA490C5-A18E-4A2B-8EB0-55A2EE273963@tarantool.org> (raw)
In-Reply-To: <0448cc416f3401eeecbad1883fea7193399a72aa.1551530224.git.imeevma@gmail.com>


> New version:
> 
> commit 0448cc416f3401eeecbad1883fea7193399a72aa
> Author: Mergen Imeev <imeevma@gmail.com>
> Date:   Tue Feb 26 22:22:26 2019 +0300
> 
>    sql: remove field nErr of struct Parse

Nit: remove from (not of).

> 
>    At the moment, the only purpose of the field nErr of struct Parse
>    is to show whether the field rc of the same struct is SQL_OK or
>    SQL_TARANTOOL_ERROR. Let's remove it.
> 
>    Part of #3965

The same problem with ordering here: you replaced nErr > 0 check
with rc == SQL_TARANTOOL_ERROR and then replaced it with
is_aborted. If you firstly replaced rc with is_aborted and then
nErr > 0 -> is_aborted - diff would be slightly smaller.

> @@ -145,9 +144,11 @@ sql_finish_coding(struct Parse *parse_context)
> 			     "Exit with an error if CREATE statement fails"));
> 	}
> 
> -	if (db->mallocFailed || parse_context->nErr != 0) {
> -		if (parse_context->rc == SQL_OK)
> -			parse_context->rc = SQL_ERROR;
> +	if (parse_context->rc == SQL_TARANTOOL_ERROR)
> +		return;
> +	if (db->mallocFailed) {
> +		diag_set(OutOfMemory, 0, "SQL", "db”);

It is not a place to set OOM. Firstly, there are a lot of other
places where mallocFailed is set, but diag is not.
You should set this error in sqlOomFault(). Check if any
other function also can set this flag.

> +		parse_context->rc = SQL_TARANTOOL_ERROR;
> 		return;
> 	}
> 	/*
> @@ -189,13 +190,12 @@ sql_finish_coding(struct Parse *parse_context)
> 		sqlVdbeGoto(v, 1);
> 	}
> 	/* Get the VDBE program ready for execution. */
> -	if (parse_context->nErr == 0 && !db->mallocFailed) {
> +	if (parse_context->rc == SQL_OK && !db->mallocFailed) {
> 		assert(parse_context->iCacheLevel == 0);
> 		sqlVdbeMakeReady(v, parse_context);
> -		parse_context->rc = SQL_DONE;
> -	} else {
> -		if (parse_context->rc != SQL_TARANTOOL_ERROR)
> -			parse_context->rc = SQL_ERROR;
> +	} else if (parse_context->rc != SQL_TARANTOOL_ERROR){
> +		diag_set(OutOfMemory, 0, "SQL", "db");
> +		parse_context->rc = SQL_TARANTOOL_ERROR;

The same here.

> @@ -1284,7 +1273,7 @@ sql_create_view(struct Parse *parse_context, struct Token *begin,
> 	}
> 	sqlStartTable(parse_context, name, if_exists);
> 	struct space *space = parse_context->new_space;
> -	if (space == NULL || parse_context->nErr != 0)
> +	if (space == NULL || parse_context->rc == SQL_TARANTOOL_ERROR)

Instead of checking that rc == SQL_TARANTOOL_ERROR, I’d rather
test that rc != 0. It doesn’t matter now, since rc is anyway removed.

> diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
> index 58685c4..fac2781 100644
> --- a/src/box/sql/tokenize.c
> +++ b/src/box/sql/tokenize.c
> @@ -483,7 +483,9 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg)
> 				      &pParse->sLastToken.isReserved);
> 			i += pParse->sLastToken.n;
> 			if (i > mxSqlLen) {
> -				pParse->rc = SQL_TOOBIG;
> +				diag_set(ClientError, ER_SQL_PARSER_GENERIC,
> +					 "string or blob too big");
> +				pParse->rc = SQL_TARANTOOL_ERROR;
> 				break;

Move this change to previous patch.

> @@ -502,7 +504,9 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg)
> 			assert(tokenType == TK_SPACE
> 			       || tokenType == TK_ILLEGAL);
> 			if (db->u1.isInterrupted) {
> -				pParse->rc = SQL_INTERRUPT;
> +				diag_set(ClientError, ER_SQL_PARSER_GENERIC,
> +					 "interrupted");
> +				pParse->rc = SQL_TARANTOOL_ERROR;

The same.

> @@ -529,7 +533,8 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg)
> #endif				/* YYDEBUG */
> 	sqlParserFree(pEngine, sql_free);
> 	if (db->mallocFailed) {
> -		pParse->rc = SQL_NOMEM;
> +		diag_set(OutOfMemory, 0, "SQL", "db");
> +		pParse->rc = SQL_TARANTOOL_ERROR;
> 	}

The same.

> 	if (pParse->rc != SQL_OK && pParse->rc != SQL_DONE
> 	    && pParse->zErrMsg == 0) {
> diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
> index f67c32e..a42e872 100644
> --- a/src/box/sql/vdbemem.c
> +++ b/src/box/sql/vdbemem.c
> @@ -1227,7 +1227,8 @@ valueFromFunction(sql * db,	/* The database connection */
> 		sql_value_apply_type(pVal, type);
> 		assert(rc == SQL_OK);
> 	}
> -	pCtx->pParse->rc = rc;
> +	if (rc != SQL_OK)
> +		pCtx->pParse->rc = SQL_TARANTOOL_ERROR;
> 

Why did you change this code?

>  value_from_function_out:
> 	if (rc != SQL_OK) {

  parent reply	other threads:[~2019-03-05  9:06 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-02 13:07 [tarantool-patches] [PATCH v3 0/9] sql: use diag_set() for errors in SQL imeevma
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 1/9] sql: rework syntax errors imeevma
2019-03-04 17:47   ` [tarantool-patches] " n.pettik
2019-03-05  8:31   ` Konstantin Osipov
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 2/9] sql: save SQL parser errors in diag_set() imeevma
2019-03-05  8:40   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 3/9] sql: remove field nErr of struct Parse imeevma
2019-03-05  8:41   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik [this message]
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 4/9] sql: remove field rc " imeevma
2019-03-05  8:42   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 5/9] sql: remove field zErrMsg " imeevma
2019-03-05  8:43   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:06   ` n.pettik
2019-03-02 13:07 ` [tarantool-patches] [PATCH v3 6/9] sql: rework six syntax errors imeevma
2019-03-05  8:45   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:07   ` n.pettik
2019-03-02 13:08 ` [tarantool-patches] [PATCH v3 7/9] sql: rework four semantic errors imeevma
2019-03-05  8:46   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:16   ` n.pettik
2019-03-02 13:08 ` [tarantool-patches] [PATCH v3 8/9] sql: rework three errors of "unsupported" type imeevma
2019-03-05  8:47   ` [tarantool-patches] " Konstantin Osipov
2019-03-05  9:34   ` n.pettik
2019-03-05  9:43     ` Konstantin Osipov
2019-03-02 13:08 ` [tarantool-patches] [PATCH v3 9/9] sql: remove sqlErrorMsg() imeevma
2019-03-05  8:48   ` [tarantool-patches] " Konstantin Osipov
2019-03-05 12:16   ` n.pettik
2019-03-05 15:44     ` Konstantin Osipov

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=5CA490C5-A18E-4A2B-8EB0-55A2EE273963@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v3 3/9] sql: remove field nErr of struct Parse' \
    /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