bpo-44106: Improve sqlite3 example database contents (GH-26027)

This commit is contained in:
Erlend Egeberg Aasland 2021-05-19 09:41:19 +02:00 committed by GitHub
parent 9014437573
commit 92d1064727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 42 deletions

View file

@ -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