@@ -1455,19 +1455,18 @@ Here's an example of both styles:
1455
1455
con = sqlite3.connect(":memory: ")
1456
1456
cur = con.execute("CREATE TABLE lang(name, first_appeared)")
1457
1457
1458
- # This is the qmark style:
1459
- cur.execute("INSERT INTO lang VALUES(?, ?)", ("C", 1972))
1460
-
1461
- # The qmark style used with executemany():
1462
- lang_list = [
1463
- ("Fortran", 1957),
1464
- ("Python", 1991),
1465
- ("Go", 2009),
1466
- ]
1467
- cur.executemany("INSERT INTO lang VALUES(?, ?)", lang_list)
1468
-
1469
- # And this is the named style:
1470
- cur.execute("SELECT * FROM lang WHERE first_appeared = :year", {"year": 1972})
1458
+ # This is the named style used with executemany():
1459
+ data = (
1460
+ {"name": "C", "year": 1972},
1461
+ {"name": "Fortran", "year": 1957},
1462
+ {"name": "Python", "year": 1991},
1463
+ {"name": "Go", "year": 2009},
1464
+ )
1465
+ cur.executemany("INSERT INTO lang VALUES(:name, :year)", data)
1466
+
1467
+ # This is the qmark style used in a SELECT query:
1468
+ params = (1972,)
1469
+ cur.execute("SELECT * FROM lang WHERE first_appeared = ?", params)
1471
1470
print(cur.fetchall())
1472
1471
1473
1472
.. testoutput ::
0 commit comments