Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: check-added-large-files
args: ['--maxkb=1024']
- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.11.1
rev: v2.12.1
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
Expand All @@ -35,7 +35,7 @@ repos:
entry: isort --profile=black
name: isort (python)
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
Expand Down
6 changes: 2 additions & 4 deletions docs/save-data/sqlite/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
cursor = conn.cursor()

# insert a record into the database
cursor.execute(
"""INSERT INTO books
cursor.execute("""INSERT INTO books
VALUES ('Python basics', 'en', 'Veit Schiele', 'BSD',
'2021-10-28')"""
)
'2021-10-28')""")

# save data to database
conn.commit()
Expand Down
6 changes: 2 additions & 4 deletions docs/save-data/sqlite/create_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
cursor = conn.cursor()

# create books table
cursor.execute(
"""CREATE TABLE books
cursor.execute("""CREATE TABLE books
(title text, language text, author text, license text,
release_date text)
"""
)
""")
42 changes: 14 additions & 28 deletions docs/save-data/sqlite/normalise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
conn = sqlite3.connect("library.db")
cursor = conn.cursor()

cursor.execute(
"""CREATE TABLE languages
cursor.execute("""CREATE TABLE languages
(id INTEGER PRIMARY KEY AUTOINCREMENT,
language_code VARCHAR(2))"""
)
language_code VARCHAR(2))""")

cursor.execute(
"""INSERT INTO languages (language_code)
VALUES ('de')"""
)
cursor.execute("""INSERT INTO languages (language_code)
VALUES ('de')""")

cursor.execute(
"""INSERT INTO languages (language_code)
VALUES ('en')"""
)
cursor.execute("""INSERT INTO languages (language_code)
VALUES ('en')""")

cursor.execute(
"""CREATE TABLE "temp" (
cursor.execute("""CREATE TABLE "temp" (
"id" INTEGER,
"title" TEXT,
"language_code" INTEGER REFERENCES languages(id),
Expand All @@ -29,25 +22,18 @@
"license" TEXT,
"release_date" DATE,
PRIMARY KEY("id" AUTOINCREMENT)
)"""
)
)""")

cursor.execute(
"""INSERT INTO temp (title,language,author,license,release_date)
SELECT title,language,author,license,release_date FROM books"""
)
cursor.execute("""INSERT INTO temp (title,language,author,license,release_date)
SELECT title,language,author,license,release_date FROM books""")

cursor.execute(
"""UPDATE temp
cursor.execute("""UPDATE temp
SET language_code = 1
WHERE language = 'de'"""
)
WHERE language = 'de'""")

cursor.execute(
"""UPDATE temp
cursor.execute("""UPDATE temp
SET language_code = 2
WHERE language = 'en'"""
)
WHERE language = 'en'""")

# Only SQLite ≥ 3.35.0 allows DROP COLUMN;
# Only Python versions ≥ 3.8 released after 27 April 2021 will receive these or
Expand Down
6 changes: 2 additions & 4 deletions docs/save-data/sqlite/query_normalised.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

def select_all_records_ordered_by_language_number(cursor):
print("All books ordered by language id and title:")
for row in cursor.execute(
"""SELECT language_code, author, title FROM books
ORDER BY language_code,title"""
):
for row in cursor.execute("""SELECT language_code, author, title FROM books
ORDER BY language_code,title"""):
print(row)


Expand Down
12 changes: 4 additions & 8 deletions docs/save-data/sqlite/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ def setUp(self):
self.conn = sqlite3.connect(":memory:")
cursor = self.conn.cursor()

cursor.execute(
"""CREATE TABLE books
cursor.execute("""CREATE TABLE books
(title text, language text, author text, license text,
release_date text)
"""
)
""")

cursor.execute(
"""INSERT INTO books
cursor.execute("""INSERT INTO books
VALUES ('Python basics', 'en', 'Veit Schiele', 'BSD',
'2021-10-28')"""
)
'2021-10-28')""")

def test_func_like(self):
self.conn = sqlite3.connect(":memory:")
Expand Down
Loading