(user_id, date_of_purchase, item_id, amount)
| 82 | |
| 83 | |
| 84 | def add_purchase(user_id, date_of_purchase, item_id, amount): |
| 85 | conn = get_connection() |
| 86 | cursor = conn.cursor() |
| 87 | |
| 88 | # Check if the purchase already exists |
| 89 | cursor.execute( |
| 90 | """ |
| 91 | SELECT * FROM PurchaseHistory |
| 92 | WHERE user_id = ? AND item_id = ? AND date_of_purchase = ? |
| 93 | """, |
| 94 | (user_id, item_id, date_of_purchase), |
| 95 | ) |
| 96 | if cursor.fetchone(): |
| 97 | # print(f"Purchase already exists for user_id {user_id} on {date_of_purchase} for item_id {item_id}.") |
| 98 | return |
| 99 | |
| 100 | try: |
| 101 | cursor.execute( |
| 102 | """ |
| 103 | INSERT INTO PurchaseHistory (user_id, date_of_purchase, item_id, amount) |
| 104 | VALUES (?, ?, ?, ?) |
| 105 | """, |
| 106 | (user_id, date_of_purchase, item_id, amount), |
| 107 | ) |
| 108 | |
| 109 | conn.commit() |
| 110 | except sqlite3.Error as e: |
| 111 | print(f"Database Error: {e}") |
| 112 | |
| 113 | |
| 114 | def add_product(product_id, product_name, price): |
no test coverage detected
searching dependent graphs…