-
Notifications
You must be signed in to change notification settings - Fork 0
/
aldiarSQL.py
176 lines (116 loc) · 6.27 KB
/
aldiarSQL.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import sqlite3
from contextlib import closing
ShoesCreateTable = "CREATE TABLE IF NOT EXISTS Shoes(category2 text, photo text, name text primary key, price text)"
OuterwearCreateTable = "CREATE TABLE IF NOT EXISTS Outerwear(category2 text, photo text, name text primary key, price text)"
PantsCreateTable = "CREATE TABLE IF NOT EXISTS Pants(category2 text, photo text, name text primary key, price text)"
AccessoriesCreateTable = "CREATE TABLE IF NOT EXISTS Accessories(category2 text, photo text, name text primary key, price text)"
connectionM = sqlite3.connect('MaleDB.db')
connectionF = sqlite3.connect('FemaleDB.db')
connectionM.execute(ShoesCreateTable)
connectionM.execute(OuterwearCreateTable)
connectionM.execute(PantsCreateTable)
connectionM.execute(AccessoriesCreateTable)
connectionF.execute(ShoesCreateTable)
connectionF.execute(OuterwearCreateTable)
connectionF.execute(PantsCreateTable)
connectionF.execute(AccessoriesCreateTable)
def sql_male(data):
connectionM = sqlite3.connect('MaleDB.db')
if data['category1'] == 'Аксессуары':
AccessoriesInsertTable = f"INSERT INTO Accessories(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionM.execute(AccessoriesInsertTable)
elif data['category1'] == 'Обувь':
ShoesInsertTable = f"INSERT INTO Shoes(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionM.execute(ShoesInsertTable)
elif data['category1'] == 'Верхняя одежда':
OuterwearInsertTable = f"INSERT INTO Outerwear(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionM.execute(OuterwearInsertTable)
elif data['category1'] == 'Штаны':
PantsInsertTable = f"INSERT INTO Pants(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionM.execute(PantsInsertTable)
connectionM.commit()
connectionM.close()
def sql_female(data):
connectionF = sqlite3.connect('FemaleDB.db')
if data['category1'] == 'Аксессуары':
AccessoriesInsertTable = f"INSERT INTO Accessories(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionF.execute(AccessoriesInsertTable)
elif data['category1'] == 'Обувь':
ShoesInsertTable = f"INSERT INTO Shoes(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionF.execute(ShoesInsertTable)
elif data['category1'] == 'Верхняя одежда':
OuterwearInsertTable = f"INSERT INTO Outerwear(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionF.execute(OuterwearInsertTable)
elif data['category1'] == 'Штаны':
PantsInsertTable = f"INSERT INTO Pants(category2, photo, name, price) VALUES ('{data['category2']}', '{data['photo']}', '{data['name']}', '{data['price']}')"
connectionF.execute(PantsInsertTable)
connectionF.commit()
connectionF.close()
def sql_male_select(choise, product):
connectionM = sqlite3.connect('MaleDB.db')
cursorM = connectionM.cursor()
global SelectedList
if choise == 'Аксессуары':
AccessoriesSelect = f"SELECT * FROM Accessories WHERE category2 = '{product}'"
cursorM.execute(AccessoriesSelect)
SelectedList = cursorM.fetchall()
elif choise == 'Обувь':
ShoesSelect = f"SELECT * FROM Shoes WHERE category2 = '{product}'"
cursorM.execute(ShoesSelect)
SelectedList = cursorM.fetchall()
elif choise == 'Верхняя одежда':
OuterwearSelect = f"SELECT * FROM Outerwear WHERE category2 = '{product}'"
cursorM.execute(OuterwearSelect)
SelectedList = cursorM.fetchall()
elif choise == 'Штаны':
PantsSelect = f"SELECT * FROM Pants WHERE category2 = '{product}'"
cursorM.execute(PantsSelect)
SelectedList = cursorM.fetchall()
return SelectedList
def sql_female_select(choise, product):
connectionF = sqlite3.connect('FemaleDB.db')
cursorF = connectionF.cursor()
global SelectedList
if choise == 'Аксессуары':
AccessoriesSelect = f"SELECT * FROM Accessories WHERE category2 = '{product}'"
cursorF.execute(AccessoriesSelect)
SelectedList = cursorM.fetchall()
elif choise == 'Обувь':
ShoesSelect = f"SELECT * FROM Shoes WHERE category2 = '{product}'"
cursorF.execute(ShoesSelect)
SelectedList = cursorF.fetchall()
elif choise == 'Верхняя одежда':
OuterwearSelect = f"SELECT * FROM Outerwear WHERE category2 = '{product}'"
cursorF.execute(OuterwearSelect)
SelectedList = cursorF.fetchall()
elif choise == 'Штаны':
PantsSelect = f"SELECT * FROM Pants WHERE category2 = '{product}'"
cursorF.execute(PantsSelect)
SelectedList = cursorF.fetchall()
return SelectedList
def sql_ONEselect(data):
if data['gender'] == 'Женская':
connectionF = sqlite3.connect('FemaleDB.db')
cursorF = connectionF.cursor()
cursorF.execute(f"SELECT * FROM {data['category1']} WHERE category2 = '{data['category2']}' and name = '{data['name']}'")
connectionF.commit()
selected = cursorF.fetchone()
if data['gender'] == 'Мужская':
connectionM = sqlite3.connect('MaleDB.db')
cursorM = connectionM.cursor()
cursorM.execute(f"SELECT * FROM {data['category1']} WHERE category2 = '{data['category2']}' and name = '{data['name']}'")
connectionM.commit()
selected = cursorM.fetchone()
return selected
def delete_something(data):
if data['gender'] == 'Женская':
connectionF = sqlite3.connect('FemaleDB.db')
cursorF = connectionF.cursor()
cursorF.execute(f"DELETE FROM {data['category1']} WHERE category2 = '{data['category2']}' and name='{data['name']}'")
print(data['category1'], data['name'])
connectionF.commit()
if data['gender'] == 'Мужская':
connectionM = sqlite3.connect('MaleDB.db')
cursorM = connectionM.cursor()
cursorM.execute(f"DELETE FROM {data['category1']} WHERE category2 = '{data['category2']}' and name='{data['name']}'")
connectionM.commit()