Skip to content

Commit 0333971

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a5c96dc commit 0333971

File tree

5 files changed

+24
-48
lines changed

5 files changed

+24
-48
lines changed

docs/save-data/sqlite/create_data.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
cursor = conn.cursor()
55

66
# insert a record into the database
7-
cursor.execute(
8-
"""INSERT INTO books
7+
cursor.execute("""INSERT INTO books
98
VALUES ('Python basics', 'en', 'Veit Schiele', 'BSD',
10-
'2021-10-28')"""
11-
)
9+
'2021-10-28')""")
1210

1311
# save data to database
1412
conn.commit()

docs/save-data/sqlite/create_db.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
cursor = conn.cursor()
77

88
# create books table
9-
cursor.execute(
10-
"""CREATE TABLE books
9+
cursor.execute("""CREATE TABLE books
1110
(title text, language text, author text, license text,
1211
release_date text)
13-
"""
14-
)
12+
""")

docs/save-data/sqlite/normalise.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@
33
conn = sqlite3.connect("library.db")
44
cursor = conn.cursor()
55

6-
cursor.execute(
7-
"""CREATE TABLE languages
6+
cursor.execute("""CREATE TABLE languages
87
(id INTEGER PRIMARY KEY AUTOINCREMENT,
9-
language_code VARCHAR(2))"""
10-
)
8+
language_code VARCHAR(2))""")
119

12-
cursor.execute(
13-
"""INSERT INTO languages (language_code)
14-
VALUES ('de')"""
15-
)
10+
cursor.execute("""INSERT INTO languages (language_code)
11+
VALUES ('de')""")
1612

17-
cursor.execute(
18-
"""INSERT INTO languages (language_code)
19-
VALUES ('en')"""
20-
)
13+
cursor.execute("""INSERT INTO languages (language_code)
14+
VALUES ('en')""")
2115

22-
cursor.execute(
23-
"""CREATE TABLE "temp" (
16+
cursor.execute("""CREATE TABLE "temp" (
2417
"id" INTEGER,
2518
"title" TEXT,
2619
"language_code" INTEGER REFERENCES languages(id),
@@ -29,25 +22,18 @@
2922
"license" TEXT,
3023
"release_date" DATE,
3124
PRIMARY KEY("id" AUTOINCREMENT)
32-
)"""
33-
)
25+
)""")
3426

35-
cursor.execute(
36-
"""INSERT INTO temp (title,language,author,license,release_date)
37-
SELECT title,language,author,license,release_date FROM books"""
38-
)
27+
cursor.execute("""INSERT INTO temp (title,language,author,license,release_date)
28+
SELECT title,language,author,license,release_date FROM books""")
3929

40-
cursor.execute(
41-
"""UPDATE temp
30+
cursor.execute("""UPDATE temp
4231
SET language_code = 1
43-
WHERE language = 'de'"""
44-
)
32+
WHERE language = 'de'""")
4533

46-
cursor.execute(
47-
"""UPDATE temp
34+
cursor.execute("""UPDATE temp
4835
SET language_code = 2
49-
WHERE language = 'en'"""
50-
)
36+
WHERE language = 'en'""")
5137

5238
# Only SQLite ≥ 3.35.0 allows DROP COLUMN;
5339
# Only Python versions ≥ 3.8 released after 27 April 2021 will receive these or

docs/save-data/sqlite/query_normalised.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
def select_all_records_ordered_by_language_number(cursor):
88
print("All books ordered by language id and title:")
9-
for row in cursor.execute(
10-
"""SELECT language_code, author, title FROM books
11-
ORDER BY language_code,title"""
12-
):
9+
for row in cursor.execute("""SELECT language_code, author, title FROM books
10+
ORDER BY language_code,title"""):
1311
print(row)
1412

1513

docs/save-data/sqlite/test_sqlite.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ def setUp(self):
1919
self.conn = sqlite3.connect(":memory:")
2020
cursor = self.conn.cursor()
2121

22-
cursor.execute(
23-
"""CREATE TABLE books
22+
cursor.execute("""CREATE TABLE books
2423
(title text, language text, author text, license text,
2524
release_date text)
26-
"""
27-
)
25+
""")
2826

29-
cursor.execute(
30-
"""INSERT INTO books
27+
cursor.execute("""INSERT INTO books
3128
VALUES ('Python basics', 'en', 'Veit Schiele', 'BSD',
32-
'2021-10-28')"""
33-
)
29+
'2021-10-28')""")
3430

3531
def test_func_like(self):
3632
self.conn = sqlite3.connect(":memory:")

0 commit comments

Comments
 (0)