forked from Rusheelraj/Supermart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
35 lines (27 loc) · 688 Bytes
/
sql.py
File metadata and controls
35 lines (27 loc) · 688 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
32
33
34
35
import sqlite3
# Connect to SQLite database (it will be created if it doesn't exist)
conn = sqlite3.connect('database.db')
# Create a cursor object using the cursor() method
cursor = conn.cursor()
# Create table
cursor.execute('''
CREATE TABLE users(
id INTEGER PRIMARY KEY,
username TEXT NOT NULL,
password TEXT NOT NULL
)
''')
# Insert sample data
users = [
('admin', 'password123'),
('user1', 'mypassword'),
('user2', 'password321')
]
cursor.executemany('''
INSERT INTO users (username, password) VALUES (?,?)
''', users)
# Commit the transaction
conn.commit()
# Close the connection
conn.close()
print("Database and sample data created successfully.")