-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAO.py
executable file
·116 lines (85 loc) · 3.34 KB
/
DAO.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pymysql
from model import *
import config.config as conf
from config.BaseResponse import *
class DAO():
def __init__(self):
self.conn = None
def connect(self):
self.conn = pymysql.connect(host=conf.db['host'], user=conf.db['user'], passwd=conf.db['password'],
db="furniture", charset="utf8")
def disconnect(self):
self.conn.close()
# 가구 테이블 조회
def furniture(self):
self.connect()
cur = self.conn.cursor()
sql = "SELECT * FROM furniture"
cur.execute(sql)
furniture_list = cur.fetchall()
self.conn.commit()
self.disconnect()
return furniture_list
# 가구분류 테이블 조회
def furniture_classification(self):
self.connect()
cur = self.conn.cursor()
sql = "SELECT * FROM furniture_classification"
cur.execute(sql)
furniture_classification_list = cur.fetchall()
self.conn.commit()
self.disconnect()
return furniture_classification_list
def getProduct(self, productIdx):
try:
self.connect()
cur = self.conn.cursor()
sql = f"SELECT product_information, name, price, site, furniture_imgs\
FROM furniture\
INNER JOIN (\
SELECT furniture_idx, group_concat(files) as furniture_imgs\
FROM furniture_img\
WHERE furniture_idx={productIdx}\
GROUP BY furniture_idx\
) furniture_img\
ON furniture.idx = furniture_img.furniture_idx\
WHERE furniture.idx={productIdx}"
cur.execute(sql)
result = cur.fetchall()
self.conn.commit()
self.disconnect()
productName = result[0][1]
productPrice = result[0][2]
productDescrip = result[0][0]
productUrl = result[0][3]
productImgs = str(result[0][4]).split(',')
getProductRes = GetProductRes(productIdx, productName, productPrice, productDescrip, productUrl, productImgs)
return getProductRes
except IndexError as e:
print(result)
return BaseResponseStatus.REQUEST_ERROR
except Exception as e:
print(e)
return BaseResponseStatus.UNKNOWN_ERROR
def foo(self, productIdx):
try:
# name, price, image, descr, c_url
self.connect()
cur = self.conn.cursor()
print(f'idx ::: {productIdx}')
sql = f"SELECT product_information, name, price, site FROM furniture WHERE furniture.idx={int(float(productIdx))}"
cur.execute(sql)
result = cur.fetchall()
self.conn.commit()
self.disconnect()
productName = result[0][1]
productPrice = result[0][2]
productDescrip = result[0][0]
productUrl = result[0][3]
return (productName, productPrice, productDescrip, productUrl)
except IndexError as e:
print(result)
return BaseResponseStatus.REQUEST_ERROR
except Exception as e:
print(e)
return BaseResponseStatus.UNKNOWN_ERROR