Safe SELECT ... LIKE abc% in psycopg

Поиск
Список
Период
Сортировка
От Philippe Strauss
Тема Safe SELECT ... LIKE abc% in psycopg
Дата
Msg-id 6b4e2581-8b08-4f0c-b159-cd078fd988a9@straussaudio.ch
обсуждение исходный текст
Ответы Re: Safe SELECT ... LIKE abc% in psycopg  (Adrian Klaver <adrian.klaver@aklaver.com>)
Re: Safe SELECT ... LIKE abc% in psycopg  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список psycopg
Hello, I'm Philippe from switzerland,

I'm writing using python a small JSON API for a mycology photos archive 
webapp. Aside the main API endpoint are two
helpers for an autocomplete form.
Here is the first one:

--8<--
@app.route('/genus/<genus>')
def genus(genus):
     with dbconn.cursor() as cur:
         cur.execute("""SELECT myco.genus.name
             FROM myco.genus
             WHERE myco.genus.name LIKE %s""", (genus.upper()+'%',))
         lsgenus = cur.fetchall()
         ls = []
         for genus in lsgenus:
             ls.append(genus[0])
     return jsonify(ls)
--8<--

My questions:
- What is the best way to use in psycopg3 to express a SELECT ... WHERE 
... LIKE blah% ?
- Is my code above safe or vulnerable to a injection attack?
- What peoples having passed on the same pattern have to recommend?

Thanks!

-- 
Philippe Strauss
https://straussengineering.ch/




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

Предыдущее
От: Daniele Varrazzo
Дата:
Сообщение: [MASSMAIL]Waiting for Psycopg 3.2
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Safe SELECT ... LIKE abc% in psycopg