Linance / app.py
ka1kuk's picture
Update app.py
4e684c0
raw
history blame
No virus
901 Bytes
import sqlite3
# Connect to the database
conn = sqlite3.connect('lindb.db')
# Create a table
conn.execute('''CREATE TABLE users
(id INT PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
email TEXT NOT NULL);''')
# Insert data into the table
conn.execute("INSERT INTO users (id, name, email) VALUES (1, 'John Doe', 'john.doe@example.com')")
conn.execute("INSERT INTO users (id, name, email) VALUES (2, 'Jane Doe', 'jane.doe@example.com')")
# Read data from the table
cursor = conn.execute("SELECT id, name, email FROM users")
for row in cursor:
print(f"ID = {row[0]}, NAME = {row[1]}, EMAIL = {row[2]}")
# Update data in the table
conn.execute("UPDATE users SET email = 'jane.doe@newexample.com' WHERE id = 2")
# Delete data from the table
conn.execute("DELETE FROM users WHERE id = 1")
# Commit the changes and close the connection
conn.commit()
conn.close()