-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule14_1.py
More file actions
54 lines (42 loc) · 1.23 KB
/
Copy pathmodule14_1.py
File metadata and controls
54 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import sqlite3 as db
DB_FILE = 'not_telegram.db'
if not os.path.exists(DB_FILE):
try:
open(DB_FILE, "w")
except OSError:
exit(1)
db_connection = db.connect(DB_FILE)
db_connection.execute('''
CREATE TABLE IF NOT EXISTS "Users"(
"id" INTEGER NOT NULL,
"username" TEXT NOT NULL,
"email" TEXT NOT NULL COLLATE NOCASE,
"age" INTEGER,
"balance" INTEGER NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT)
)
''')
db_connection.executemany('''
INSERT INTO Users (username, email, age, balance)
VALUES (CONCAT('User', ?), CONCAT('example', ?, '@gmail.com'), ? * 10, 1000
)
''', ((i, i, i) for i in range(1, 11))
)
db_connection.execute('''
UPDATE Users SET balance = 500
WHERE MOD(SUBSTR(username, 5), 2) <> 0
''')
db_connection.execute('''
DELETE FROM Users
WHERE MOD(SUBSTR(username, 5) - 1, 3) = 0
''')
db_connection.commit()
db_cursor = db_connection.execute('''
SELECT username, email, age, balance
FROM Users
WHERE age <> 60
''')
for db_row in db_cursor.fetchall():
print(f'Имя: {db_row[0]} | Почта: {db_row[1]} | Возраст: {db_row[2]} | Баланс: {db_row[3]}')
db_connection.close()