forked from coders-of-the-caribbean/Hack59
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqldb.py
More file actions
92 lines (80 loc) · 3.35 KB
/
sqldb.py
File metadata and controls
92 lines (80 loc) · 3.35 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
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
#!/usr/bin/python
import sqlite3
class db:
def __init__(self):
self.conn = sqlite3.connect('test.db')
print "Opened database successfully";
def create(self):
self.conn.execute('''CREATE TABLE IF NOT EXISTS HOTEL
(NAME TEXT PRIMARY KEY NOT NULL,
ONE INT NOT NULL,
TWO INT NOT NULL,
THREE INT NOT NULL,
FOUR INT NOT NULL);''')
print "Table created successfully";
def insert(self, hotel, a, b, c, d):
self.cursor = self.conn.execute("SELECT NAME FROM HOTEL WHERE NAME = ?", (hotel))
data = self.cursor.fetchall()
if len(data)==0:
self.conn.execute("INSERT INTO HOTEL VALUES (?, ?, ?, ?, ?);", (hotel, int(a), int(b), int(c), int(d)))
self.conn.commit()
else:
self.cursor = self.conn.execute("SELECT ONE, TWO, THREE, FOUR FROM HOTEL WHERE NAME=?", (hotel))
for row in self.cursor:
tup = [row[0], row[1], row[2], row[3]]
tup[0] += a
tup[1] += b
tup[2] += c
tup[3] += d
self.conn.execute("UPDATE HOTEL SET one=?, TWO=?, THREE=?, FOUR=? WHERE NAME=?", (tup[0], tup[1], tup[2], tup[3], hotel))
self.conn.commit()
print "Records created successfully";
def select(self):
self.cursor = self.conn.execute("SELECT NAME, ONE, TWO, THREE, FOUR from HOTEL ")
tup = []
for row in self.cursor:
tup.append([str(row[0]), row[1], row[2], row[3], row[4]])
return tup
def close(self):
self.conn.close()
#!/usr/bin/python
import sqlite3
class db:
def __init__(self):
self.conn = sqlite3.connect('test.db')
print "Opened database successfully";
def create(self):
self.conn.execute('''CREATE TABLE IF NOT EXISTS HOTEL
(NAME TEXT PRIMARY KEY NOT NULL,
ONE INT NOT NULL,
TWO INT NOT NULL,
THREE INT NOT NULL,
FOUR INT NOT NULL);''')
print "Table created successfully";
def insert(self, hotel, a, b, c, d):
print hotel
self.cursor = self.conn.execute("SELECT * FROM HOTEL WHERE NAME = ?", (hotel, ))
data = self.cursor.fetchall()
print data
if len(data)==0:
self.conn.execute("INSERT INTO HOTEL VALUES (?, ?, ?, ?, ?);", (hotel, int(a), int(b), int(c), int(d)))
self.conn.commit()
else:
self.cursor = self.conn.execute("SELECT ONE, TWO, THREE, FOUR FROM HOTEL WHERE NAME=?", (hotel,))
for row in self.cursor:
tup = [row[0], row[1], row[2], row[3]]
tup[0] += a
tup[1] += b
tup[2] += c
tup[3] += d
self.conn.execute("UPDATE HOTEL SET one=?, TWO=?, THREE=?, FOUR=? WHERE NAME=?", (tup[0], tup[1], tup[2], tup[3], hotel))
self.conn.commit()
print "Records created successfully";
def select(self):
self.cursor = self.conn.execute("SELECT NAME, ONE, TWO, THREE, FOUR from HOTEL ")
tup = []
for row in self.cursor:
tup.append([str(row[0]), row[1], row[2], row[3], row[4]])
return tup
def close(self):
self.conn.close()