-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
executable file
·95 lines (75 loc) · 2.61 KB
/
database.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
#!/usr/bin/python
import sqlite3
conn = sqlite3.connect('index.db')
def create(inp0, inp1, inp2, inp3, inp4, inp5, inp6, inp7, inp8, inp9, inp10):
inp=[inp0, inp1, inp2, inp3, inp4, inp5, inp6, inp7, inp8, inp9, inp10]
conn.execute('INSERT INTO COMPANY VALUES (?,?,?,?,?,?,?,?,?,?,?)', inp);
conn.commit()
def show(inp):
cur=conn.cursor()
cur = conn.execute("SELECT ID, COMPANY, CATEGORY, PRODUCTID, PRICEPERUNIT, CURRENCY, ORIGIN, REGION, SCORE, RELIABILITY, CONTACT from COMPANY")
for row in cur:
print 'ID= ', row[0]
print 'COMPANY= ', row[1]
print 'CATEGORY= ', row[2]
print 'PRODUCTID= ', row[3]
print 'PRICEPERUNIT= ', row[4]
print 'CURRENCY= ', row[5]
print 'ORIGIN= ', row[6]
print 'REGION= ', row[7]
print 'SCORE= ', row[8]
print 'RELIABILITY= ', row[9]
print 'CONTACT= ', row[10] , "\n"
def delete(inp):
sql='DELETE FROM COMPANY WHERE ID=?'
cur=conn.cursor()
conn.execute(sql, (inp,))
conn.commit()
def deleteall():
sql='DELETE FROM COMPANY'
cur=conn.cursor()
conn.execute(sql)
conn.commit()
def compare(pid):
cur=conn.cursor()
cur=conn.execute("SELECT ID, COMPANY, CATEGORY, PRODUCTID, PRICEPERUNIT, CURRENCY, ORIGIN, REGION, SCORE, RELIABILITY, CONTACT from COMPANY")
i=0
k=0
print("checking")
for row in cur:
print("check")
if pid==row[3]:
k=1
print 'ID= ', row[0]
print 'COMPANY= ', row[1]
print 'CATEGORY= ', row[2]
print 'PRODUCTID= ', row[3]
print 'PRICEPERUNIT= ', row[4]
print 'CURRENCY= ', row[5]
print 'ORIGIN= ', row[6]
print 'REGION= ', row[7]
print 'SCORE= ', row[8]
print 'RELIABILITY= ', row[9]
print 'CONTACT= ', row[10]
print(i)
print("k=", k)
k=0
break
else:
print("No entry found")
print("checked")
def close():
conn.close()
####################################
#Try
#############################
##conn.execute("INSERT INTO COMPANY (ID, BRAND, PRODUCT, SEGMENT, PRICE) \
## VALUES ('inp[0]', 'inp[1]', 'inp[2]', 'inp[3]', 180 )");
#
##conn.execute("INSERT INTO COMPANY (ID, BRAND, PRODUCT, SEGMENT, PRICE) \
## VALUES ("input("New database entry: [ID, 'BRAND', 'PRODUCT', 'SEGMENT', PRICE] ")")");
#
##conn.execute("INSERT INTO COMPANY (ID, NAME, AGE, ADDRESS, SALARY) \
## VALUES (1, 'Paul', 32, 'California', 20000.00)");
#["2", "NIKE", "AIRMAX", "SHOES", "180"]
#1, 'NIKE', 'AIRMAX', 'SHOES', '180'