This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
71 lines (60 loc) · 2.01 KB
/
models.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
import sqlite3 as sql
import random
def insertUser(table,data):
con = sql.connect("accomodations.db")
cur = con.cursor()
c = "insert into "+table+" values ("+data+") ;"
print(c)
cur.execute(c)
id = cur.lastrowid
con.commit()
con.close()
return id
def select_all(prop_set):
con = sql.connect("accomodations.db")
cur = con.cursor()
data = []
a_data = []
for i in prop_set:
c =" SELECT * FROM room_details natural join location_details natural join properties natural join accom_amenities natural join accom_facilities natural join visitor_propert where property_id ="+str(i)+";"
# print(c)
cur.execute(" SELECT * FROM room_details natural join location_details natural join properties natural join accom_amenities natural join accom_facilities natural join properties_posted where property_id ="+str(i)+";")
data.append(cur.fetchall())
# c = [i[0] for i in cur.execute(" SELECT property_id FROM properties_posted where property_status != 'booked'").fetchall()]
# print(c)
# for i in data:
# if i[0][0] in c:
# a_data.append(i)
# print (a_data[0])
con.commit()
con.close()
# print(data)
return data
def group_by(field, condition, table):
con = sql.connect("accomodations.db")
cur = con.cursor()
c = " SELECT " + field + " FROM " + table + " group by " + condition + ";"
print(c)
cur.execute(c)
data = cur.fetchall()
con.commit()
con.close()
return data
def select(field, condition, table):
con = sql.connect("accomodations.db")
cur = con.cursor()
c = " SELECT "+ field + " FROM "+ table +" where " + condition+ ";"
# print(c)
cur.execute(c)
data = cur.fetchall()
con.commit()
con.close()
return data
def update(table, field, condition):
con = sql.connect("accomodations.db")
cur = con.cursor()
c = " UPDATE "+ table + " SET "+ field+" where " + condition+ ";"
# print(c)
cur.execute(c)
con.commit()
con.close()