File size: 990 Bytes
3df77f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# database.py
import sqlite3

def init_db():
    conn = sqlite3.connect('medications.db')
    cursor = conn.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS medications (
            id INTEGER PRIMARY KEY,
            medication_name TEXT NOT NULL,
            dosage TEXT NOT NULL,
            time_of_day TEXT NOT NULL,
            date TEXT NOT NULL
        )
    ''')
    conn.commit()
    conn.close()

def add_medication(medication_name, dosage, time_of_day, date):
    conn = sqlite3.connect('medications.db')
    cursor = conn.cursor()
    cursor.execute('''
        INSERT INTO medications (medication_name, dosage, time_of_day, date)
        VALUES (?, ?, ?, ?)
    ''', (medication_name, dosage, time_of_day, date))
    conn.commit()
    conn.close()

def get_all_medications():
    conn = sqlite3.connect('medications.db')
    cursor = conn.cursor()
    cursor.execute('SELECT * FROM medications')
    rows = cursor.fetchall()
    conn.close()
    return rows