]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Docs: improve sqlite3 placeholders example (#101092)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Wed, 18 Jan 2023 09:36:17 +0000 (10:36 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Jan 2023 09:36:17 +0000 (10:36 +0100)
Doc/library/sqlite3.rst

index ba72b96c6741c4dc81f66961fd9864fb26928ee6..8796bdfc0b6f70665db99cf3a06a6f19fad9e4ac 100644 (file)
@@ -1958,19 +1958,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::