Step 6 (S-53942)

From Stepik Wiki
Revision as of 09:57, 13 March 2017 by Admin (Talk | contribs) (Create page for step id=53942)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Step on Stepik: https://stepik.org/lesson/14829/step/6

Допустим вам нужно выбрать 1 статью с определенной категорией (не важно какую именно). Отметьте правильный (безопасный, эффективный, не создающий неожиданных исключений) способ сделать это:

A)


cursor.execute("select * from articles where category = " + category_id + " limit 1")
article = cursor.fetchall()[0]

  B)

cursor.execute("select * from articles where category = %s", (category_id,))
article = cursor.fetchall()[0]

C)

cursor.execute("select * from articles where category = %s limit 1", (category_id,))
article = cursor.fetchone()

D)

cursor.execute("select * from articles where category = %s limit 1", (category_id,))
article = cursor.fetchmany(size=1)[0]