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

(cherry picked from commit 92d1064727)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
Miss Islington (bot) 2021-05-19 00:43:44 -07:00 committed by GitHub
parent 76ed53ca7b
commit db20afe6c4
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