-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite3.py
More file actions
31 lines (22 loc) · 841 Bytes
/
sqlite3.py
File metadata and controls
31 lines (22 loc) · 841 Bytes
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
import sqlite3
#Create, read, update, delete
db = sqlite3.connect('users.db')
cursor = db.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS pupils(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR,
school VARCHAR,
grade INTEGER
)""") # Create request
db.commit()
cursor.execute("""INSERT INTO pupils(name, school, grade) VALUES (?, ?, ?)""", ("Витя", "Школа 13123", 5))
db.commit()
#cursor.execute("""DELETE FROM pupils WHERE name=?""", ("Витя",))
#db.commit()
cursor.execute("""SELECT * FROM pupils""")
print(cursor.fetchall())
print("################################################################################################################")
cursor.execute("""UPDATE pupils SET name=? WHERE id=8""", ("Андрей",))
db.commit()
cursor.execute("""SELECT * FROM pupils""")
print(cursor.fetchone())