mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
bpo-44106: Improve sqlite3 example database contents (GH-26027)
This commit is contained in:
parent
9014437573
commit
92d1064727
9 changed files with 37 additions and 42 deletions
|
@ -1,23 +1,23 @@
|
|||
import sqlite3
|
||||
|
||||
persons = [
|
||||
("Hugo", "Boss"),
|
||||
("Calvin", "Klein")
|
||||
]
|
||||
langs = [
|
||||
("C++", 1985),
|
||||
("Objective-C", 1984),
|
||||
]
|
||||
|
||||
con = sqlite3.connect(":memory:")
|
||||
|
||||
# Create the table
|
||||
con.execute("create table person(firstname, lastname)")
|
||||
con.execute("create table lang(name, first_appeared)")
|
||||
|
||||
# Fill the table
|
||||
con.executemany("insert into person(firstname, lastname) values (?, ?)", persons)
|
||||
con.executemany("insert into lang(name, first_appeared) values (?, ?)", langs)
|
||||
|
||||
# Print the table contents
|
||||
for row in con.execute("select firstname, lastname from person"):
|
||||
for row in con.execute("select name, first_appeared from lang"):
|
||||
print(row)
|
||||
|
||||
print("I just deleted", con.execute("delete from person").rowcount, "rows")
|
||||
print("I just deleted", con.execute("delete from lang").rowcount, "rows")
|
||||
|
||||
# close is not a shortcut method and it's not called automatically,
|
||||
# so the connection object should be closed manually
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue