@@ -1958,19 +1958,18 @@ Here's an example of both styles:
1958
1958
con = sqlite3.connect(":memory: ")
1959
1959
cur = con.execute("CREATE TABLE lang(name, first_appeared)")
1960
1960
1961
- # This is the qmark style:
1962
- cur.execute("INSERT INTO lang VALUES(?, ?)", ("C", 1972))
1963
-
1964
- # The qmark style used with executemany():
1965
- lang_list = [
1966
- ("Fortran", 1957),
1967
- ("Python", 1991),
1968
- ("Go", 2009),
1969
- ]
1970
- cur.executemany("INSERT INTO lang VALUES(?, ?)", lang_list)
1971
-
1972
- # And this is the named style:
1973
- cur.execute("SELECT * FROM lang WHERE first_appeared = :year", {"year": 1972})
1961
+ # This is the named style used with executemany():
1962
+ data = (
1963
+ {"name": "C", "year": 1972},
1964
+ {"name": "Fortran", "year": 1957},
1965
+ {"name": "Python", "year": 1991},
1966
+ {"name": "Go", "year": 2009},
1967
+ )
1968
+ cur.executemany("INSERT INTO lang VALUES(:name, :year)", data)
1969
+
1970
+ # This is the qmark style used in a SELECT query:
1971
+ params = (1972,)
1972
+ cur.execute("SELECT * FROM lang WHERE first_appeared = ?", params)
1974
1973
print(cur.fetchall())
1975
1974
1976
1975
.. testoutput ::
0 commit comments