Re: [HACKERS] psql - add special variable to reflect the last querystatus

Поиск
Список
Период
Сортировка
От Fabien COELHO
Тема Re: [HACKERS] psql - add special variable to reflect the last querystatus
Дата
Msg-id alpine.DEB.2.20.1706280951170.1763@lancre
обсуждение исходный текст
Ответ на Re: [HACKERS] psql - add special variable to reflect the last query status  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: [HACKERS] psql - add special variable to reflect the last query status  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers
Hello Pavel,

> + if (success)
> + {
> + char   *ntuples = PQcmdTuples(results);
> + SetVariable(pset.vars, "ROW_COUNT", *ntuples ? ntuples : "0");
> + SetVariable(pset.vars, "ERROR", "FALSE");
> + }
> + else
> + {
> + SetVariable(pset.vars, "ROW_COUNT", "0");
> + SetVariable(pset.vars, "ERROR", "TRUE");
> + }
> +}
>
> It can be simplified
>
> SetVariable(pset.vars, "ROW_COUNT", success ? PQcmdTuples(results) : 0);

According to the documentation, PQcmdTuples returns "" in some cases and 
ISTM we want "0" instead for consistency, so that it is always a number. I 
rejected calling PQcmdTuples twice:
  ..., success && *PQcmdTuples(results) ? PQcmdTuples(results) : "0")

Thus it makes the "if (success)" necessary for ROW_COUNT, and then it 
looked simpler to handle ERROR the same way.

Now if the semantics is changed to put as row count whatever comes out of 
the function, even if not a count, then the code could indeed be 
simplified as you suggest.

-- 
Fabien.



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: [HACKERS] psql - add special variable to reflect the last query status
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: [HACKERS] psql - add special variable to reflect the last query status