-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
33 lines (25 loc) · 1.49 KB
/
Copy pathsql.py
File metadata and controls
33 lines (25 loc) · 1.49 KB
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
import mysql.connector
aws = False
if aws:
mydb = mysql.connector.connect(host='codefusion-rds.czuesa2uqj17.us-east-1.rds.amazonaws.com', user='admin', password = 'CodeFusion-RDS', database = "CodeFusion_DB")
else:
mydb = mysql.connector.connect(host= "localhost", user = "root", password = '',database = "CodeFusion_Local")
mycursor = mydb.cursor()
def create_user(username, password, usertype):
mycursor.execute(f"INSERT INTO `userdetails` (`uid`, `username`,`password`, `usertype`) VALUES (NULL, '{username}', '{password}', '{usertype}');")
mydb.commit()
def getpassword(username):
mycursor.execute(f"SELECT `password` FROM `userdetails` WHERE `username` = '{username}';")
password = mycursor.fetchone()
return password[0]
def auth(username, password):
return getpassword(username) == password
def create_listing(uid_of_seller,brand_model,specs,years_used,condition,price):
mycursor.execute(f"INSERT INTO `listings` (`uid_of_seller`, `brand_model`, `specs`, `years_used`, `condition`,`uid_sell_table`, `price`) VALUES ('{uid_of_seller}', '{brand_model}', '{specs}', '{years_used}', '{condition}', NULL, '{price}');")
mydb.commit()
def all_listings(): #returns nested tuple of format ( (uid_of_seller, brand_model, specs, c, condition), () )
mycursor.execute("select * from `listings`")
return mycursor.fetchall()
def getuidofseller(username):
mycursor.execute(f"SELECT `uid` FROM `userdetails` WHERE `username` = '{username}';")
return mycursor.fetchone()[0]