-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruelolmlgnoscope360shrek.py
136 lines (113 loc) · 4.27 KB
/
truelolmlgnoscope360shrek.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
# предметная область - косметика
# придумать три таблицы
# таблицы дожны состоять больше чем из 2
# таблицы должны быть между собой связаны
# и написать запросы
import sqlite3
import os
con = sqlite3.connect("cosmetics.db")
#cur = con.cursor()
tables_whitelist = [
'brends',
'stocks',
'produkts'
]
def setup_tables():
con.execute('''CREATE TABLE IF NOT EXISTS brend
(id_brend INTEGER PRIMARY KEY autoincrement,
name_brend TEXT,
country TEXT);''')
con.execute('''CREATE TABLE IF NOT EXISTS stock
(id_stock INTEGER PRIMARY KEY autoincrement,
name_stock TEXT,
start_stock TEXT,
finish_stock TEXT,
percent_stock INTEGER);''')
con.execute('''CREATE TABLE product
(id_product INTEGER PRIMARY KEY autoincrement,
name_product TEXT,
catagory TEXT,
type TEXT,
id_brend INTEGER,
id_stock INTEGER,
FOREIGN KEY (id_brend) REFERENCES brend (id_brend),
FOREIGN KEY (id_stock) REFERENCES stock (id_stock));''')
#INSERT INTO brend(id_brend, name_brend, country) VALUES
def add_test_data():
con.execute("""
INSERT INTO brend(name_brend, country) VALUES
('BODYOGRAPHY', 'США'),
('LOREAL PARIS', 'Франция'),
('NYX PROFESSIONAL MAKEUP', 'США'),
('EVA MOSAIC', 'Россия')
""")
#INSERT INTO stock(id_stock, name_stock, start_stock, finish_stock, percent_stock) VALUES
con.execute("""
INSERT INTO stock(name_stock, start_stock, finish_stock, percent_stock) VALUES
('Black Friday', '21.11.2022', '30.11.2022', 70),
('Подарок от Sesderma', '27.10.2022', '31.10.2022', 25),
('Cкидка 15%', '28.12.2022', '31.12.2022', 15)
""")
#INSERT INTO product(name_product, catagory, type, id_brend, id_stock) VALUES
con.execute("""
INSERT INTO product(name_product, catagory, type, id_brend, id_stock) VALUES
('Rustam', 'Boss', 'Hotel228',12, 3),
('Daniil', 'Deputy boss', 'YEEE',3, 1),
('Sergay', 'Hacker', 'NoTell',11, 17)
""")
def get_all_product_joined():
cur = con.cursor()
cur.execute('''
select name_product, catagory, type, name_brend, name_stock from product
JOIN brend on product.id_brend==brend.id_brend
JOIN stock on product.id_stock==stock.id_stock
''')
data = cur.fetchall()
#for d in data:
#print(d)
cur.close()
return data
def get_all_brend_joined():
cur = con.cursor()
cur.execute('''
select id_brend,name_brend, country from brend
''')
data = cur.fetchall()
# for d in data:
# print (d)
cur.close()
return data
def get_all_kk_joined():
cur = con.cursor()
cur.execute( '''
SELECT id_stock, name_stock, start_stock, finish_stock, percent_stock from stock
''')
data = cur.fetchall()
#for d in data:
# print (d)
cur.close()
return data
def execute_fetch(sql): # новая функция
cur = con.cursor()
cur.execute(sql)
data = cur.fetchall()
cur.close()
return data
def execute_insert_commit(sql, data): # новая функция
cur = con.cursor()
cur.execute(sql, data)
con.commit()
def add_brend(name_brend, country):
sql = 'INSERT INTO brend(name_brend, country) VALUES (?, ?)'
execute_insert_commit(sql, (name_brend, country))
def add_stock(name_stock, start_stock, finish_stock, percent_stock):
sql = 'INSERT INTO stock(name_stock,start_stock, finish_stock, percent_stock) VALUES (?, ?, ?, ?)'
execute_insert_commit(sql, (name_stock, start_stock, finish_stock, percent_stock))
def add_product(name_product, catagory, type, id_brend, id_stock):
sql = 'INSERT INTO Tracks(name_product, catagory, type, id_brend, id_stock ) VALUES (?, ?, ?, ?, ?)'
execute_insert_commit(sql, (name_product, catagory, type, id_brend, id_stock))
#name_product, catagory, type, id_brend, id_stock
#setup_tables()
#add_test_data()
#con.commit()
print('igig')