diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-01-18 09:42:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 09:42:55 (GMT) |
commit | 2c1eeb508cf202d744d06b7d76d002d76f7f45bf (patch) | |
tree | 693251427c78ff7471370f7b67a6f31fb598796a /Doc | |
parent | 940763140f7519a125229782ca7a095af01edda4 (diff) | |
download | cpython-2c1eeb508cf202d744d06b7d76d002d76f7f45bf.zip cpython-2c1eeb508cf202d744d06b7d76d002d76f7f45bf.tar.gz cpython-2c1eeb508cf202d744d06b7d76d002d76f7f45bf.tar.bz2 |
Docs: improve sqlite3 placeholders example (GH-101092)
(cherry picked from commit b84be8d9c0e6eca37be14c38250580251a3ef908)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/sqlite3.rst | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 2cc0d8a..065243c 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -1455,19 +1455,18 @@ Here's an example of both styles: con = sqlite3.connect(":memory:") cur = con.execute("CREATE TABLE lang(name, first_appeared)") - # This is the qmark style: - cur.execute("INSERT INTO lang VALUES(?, ?)", ("C", 1972)) - - # The qmark style used with executemany(): - lang_list = [ - ("Fortran", 1957), - ("Python", 1991), - ("Go", 2009), - ] - cur.executemany("INSERT INTO lang VALUES(?, ?)", lang_list) - - # And this is the named style: - cur.execute("SELECT * FROM lang WHERE first_appeared = :year", {"year": 1972}) + # This is the named style used with executemany(): + data = ( + {"name": "C", "year": 1972}, + {"name": "Fortran", "year": 1957}, + {"name": "Python", "year": 1991}, + {"name": "Go", "year": 2009}, + ) + cur.executemany("INSERT INTO lang VALUES(:name, :year)", data) + + # This is the qmark style used in a SELECT query: + params = (1972,) + cur.execute("SELECT * FROM lang WHERE first_appeared = ?", params) print(cur.fetchall()) .. testoutput:: |