Combining validation into main query

Поиск
Список
Период
Сортировка
От Robert James
Тема Combining validation into main query
Дата
Msg-id CAGYyBgjbrrOA=NAmE631O4_zzx0qV6BdrmEtuEwtWYFg9xamtw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Combining validation into main query  (Serge Fonville <serge.fonville@gmail.com>)
Re: Combining validation into main query  (Adrian Klaver <adrian.klaver@gmail.com>)
Список pgsql-general
Typically, my web application does some initial validation, then, if
it passes, does the actual query.  For both performance and
simplicity, I'd like to combine these all into one trip to Postgres.
Ideally, I'd like to do this in SQL.  If that's not possible, I could
use PL/pgsql, though I'm not adept at it.

Example #1:
qry = "SELECT 1 FROM users WHERE username = ? AND PASSWORD = ?"
if qry.count > 0
    qry = "SELECT ..."

Example #2:
qry = "SELECT 1 FROM users WHERE username = ? AND PASSWORD = ?"
if qry.count > 0
  qry = "SELECT product WHERE ..."
  if qry.count > 0
     qry = "UPDATE product SET..."

How can I combine these into one Postgres call? I'd like it to look
something like:

GET_PRODUCTS(username, password) -- Returns products, or -1 if
username bad, -2 if password is bad

UPDATE_PRODUCTS(username, password, productid, newval) -- Updates
product, Returns 0 if good, -1 if username bad, -2 if password bad, -3
if productid bad


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

Предыдущее
От: Serge Fonville
Дата:
Сообщение: Re: pgadmin connection via tunnel and ubuntu user instead of postgres
Следующее
От: Serge Fonville
Дата:
Сообщение: Re: Combining validation into main query