def addAdventure(adventure1, details): try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute("INSERT into adventure1 VAlUES(" + str(adventure1.get_aid()) + ",'" + adventure1.get_name() + "','" + adventure1.get_description() + "')") '''Inserting data into adventure1 table''' cur.close() for adventure2 in details: cur = createCursor( con ) #creating cursor with database using db_connectivity module cur.execute("INSERT into adventure2 VAlUES(" + str(adventure2.get_aid()) + ",'" + adventure2.get_place() + "'," + str(adventure2.get_price()) + "," + str(adventure2.get_no_of_slots()) + ")") cur.close() con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise admin_menu_exceptions.SomethingWrongException finally: con.close()
def getPassword(emailid): #function to get password try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute("SELECT uid,name,password FROM user WHERE emailid='" + emailid + "'") #geting the information of given emailid uid = None name = None password = None for c1, c2, c3 in cur: uid = c1 name = c2 password = c3 return [uid, name, password] #returning those information except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise login_password_exceptions.SomethingWrongException finally: cur.close() con.close()
def getPeopleDetails(uid,bid): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT name,gender,age FROM people_information WHERE uid="+str(uid)+" AND bid="+str(bid)) name=[] gendar=[] age=[] for c1,c2,c3 in cur: name.append(c1) gendar.append(c2) age.append(c3) if(len(name)==0): return False return [name,gendar,age] except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def getSecurityQuestionAnswer( emailid): #function to get security question, answer try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute( "SELECT uid,name,sec_qn,sec_ans FROM user WHERE emailid='" + emailid + "'" ) #getting the security question answer related information of given email id uid = None name = None sec_qn = None sec_ans = None for c1, c2, c3, c4 in cur: uid = c1 name = c2 sec_qn = c3 sec_ans = c4 return [uid, name, sec_qn, sec_ans] #returning those information except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise login_password_exceptions.SomethingWrongException finally: cur.close() con.close()
def finalBooking(booking,people_information): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("INSERT INTO booking(uid,aid,name,place,date,amount_per_person,no_of_slots,total_amount) VALUES ('"+str(booking.get_uid())+"','"+str(booking.get_aid())+"','"+booking.get_name()+"','"+booking.get_place()+"','"+booking.get_date()+"','"+str(booking.get_amount_per_person())+"','"+str(booking.get_no_of_slots())+"','"+str(booking.get_total_amount())+"')"); '''Inserting booking data into databse''' cur.execute("SELECT max(bid) FROM booking") '''Getting the booking id''' uid=booking.get_uid() bid=None for col1 in cur: bid=col1[0] booking.set_bid(bid) #Setting the bookingbooking id into object cur.close() cur=createCursor(con) #creating cursor with database using db_connectivity module for i in people_information: cur.execute("INSERT INTO people_information VALUES("+str(uid)+","+str(bid)+",'"+i[0]+"','"+i[1]+"',"+str(i[2])+")") con.commit() return booking #returning booking objects except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def getBookingDetails(uid): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT bid,name,place,date,amount_per_person,no_of_slots,total_amount FROM booking WHERE uid="+str(uid)) bid=[] name=[] place=[] date=[] amount_per_person=[] no_of_slots=[] total_amount=[] for c1,c2,c3,c4,c5,c6,c7 in cur: bid.append(c1) name.append(c2) place.append(c3) date.append(c4) amount_per_person.append(c5) no_of_slots.append(c6) total_amount.append(c7) if(len(bid)==0): return False return [bid,name,place,date,amount_per_person,no_of_slots,total_amount] except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def deletePreplan(pid): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("DELETE FROM preplan WHERE pid="+str(pid)) con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def savePreplan(preplan): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("INSERT INTO preplan(uid,aid,name,place,date,amount_per_person,no_of_slots,total_amount) VALUES ('"+str(preplan.get_uid())+"','"+str(preplan.get_aid())+"','"+preplan.get_name()+"','"+preplan.get_place()+"','"+preplan.get_date()+"','"+str(preplan.get_amount_per_person())+"','"+str(preplan.get_no_of_slots())+"','"+str(preplan.get_total_amount())+"')"); '''Inserting plan data into databse''' con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def getDescription(aid): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT description FROM adventure1 WHERE aid="+str(aid)) description=None for col1 in cur: description=col1[0] return description except Exception as e: raise e #here in real life scenario a alert will be sent to developer team with exception e finally: cur.close() con.close()
def editSlot(aid, place, no_of_slots): try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute("UPDATE adventure2 SET no_of_slots='" + str(no_of_slots) + "' WHERE aid=" + str(aid) + " AND place='" + place + "'") con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise admin_menu_exceptions.SomethingWrongException finally: cur.close() con.close()
def editAdventureDescription(aid, description): try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute("UPDATE adventure1 SET description='" + description + "' WHERE aid=" + str(aid)) con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise admin_menu_exceptions.SomethingWrongException finally: cur.close() con.close()
def deleteAdventureLocation(aid, place): try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute("DELETE FROM adventure2 WHERE aid=" + str(aid) + " AND place='" + place + "'") con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise admin_menu_exceptions.SomethingWrongException finally: cur.close() con.close()
def getAdventures(): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT aid,name FROM adventure1 ORDER BY aid") aid=[] name=[] for c1,c2 in cur: aid.append(c1) name.append(c2) return [aid,name] except Exception as e: raise e #here in real life scenario a alert will be sent to developer team with exception e finally: cur.close() con.close()
def getAdventureDetails(aid): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT place,price FROM adventure2 WHERE aid="+str(aid)) place=[] price=[] for c1,c2 in cur: place.append(c1) price.append(c2) return [place,price] except Exception as e: raise e #here in real life scenario a alert will be sent to developer team with exception e finally: cur.close() con.close()
def getMaxaid(): try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute("SELECT max(aid) FROM adventure1") aid = None for col1 in cur: aid = col1[0] return aid except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise admin_menu_exceptions.SomethingWrongException finally: cur.close() con.close()
def saveCardDetails(uid,card_no,valid_till): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("INSERT INTO card VALUES("+str(uid)+","+str(card_no)+",'"+valid_till+"')") con.commit() except mysql.connector.Error as e: if e.errno==1062: #It is the error mysql throw if email id is already present raise booking_preplan_exceptions.CardAlreadySavedException else: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def getCardDetails(uid): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT card_no,valid_till FROM card WHERE uid="+str(uid)) card_no=[] valid_till=[] for c1,c2 in cur: card_no.append(c1) valid_till.append(c2) if(len(card_no)==0): return False return [card_no,valid_till] except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()
def updatePassword(uid, password, sec_qn, sec_ans): #function to uodate password try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute( "UPDATE user SET password = '******', sec_qn='" + sec_qn + "', sec_ans='" + sec_ans + "' WHERE uid=" + str(uid) ) #updation new password,security question answer to database con.commit() except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise login_password_exceptions.SomethingWrongException finally: cur.close() con.close()
def userRegistration( user): #fuction to perform insertion of user information into database try: con = createConnection( ) #creating connection with database using db_connectivity module cur = createCursor( con) #creating cursor with database using db_connectivity module cur.execute( "INSERT INTO USER(name,emailid,dateofbirth,contact_no,password,sec_qn,sec_ans) VALUES ('" + user.get_name() + "','" + user.get_emailid() + "','" + user.get_dateofbirth() + "','" + str(user.get_contact_no()) + "','" + user.get_password() + "','" + user.get_sec_qn() + "','" + user.get_sec_ans() + "')") '''Inserting user data into databse''' cur.execute("SELECT uid FROM user WHERE emailid='" + user.get_emailid() + "'") '''Getting the user id of user''' uid = None for col1 in cur: uid = col1[0] user.set_uid(uid) #Setting the user id into user object con.commit() return user #returning user objects except mysql.connector.Error as e: if e.errno == 1062: #It is the error mysql throw if email id is already present raise registration_exceptions.EmailAlreadyPresentException else: #here in real life scenario a alert will be sent to developer team with exception e raise registration_exceptions.SomethingWrongException except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise registration_exceptions.SomethingWrongException finally: cur.close() con.close()
def getAvailaleSlots(aid,place,date): try: con=createConnection() #creating connection with database using db_connectivity module cur=createCursor(con) #creating cursor with database using db_connectivity module cur.execute("SELECT no_of_slots FROM adventure2 WHERE aid="+str(aid)+" AND place='"+place+"'") total_slot=None for col1 in cur: total_slot=col1[0] cur.execute("SELECT sum(no_of_slots) FROM booking WHERE date='"+date+"' AND aid="+str(aid)+" AND place='"+place+"'") booked_slot=None for col1 in cur: booked_slot=col1[0] if(booked_slot==None): return total_slot return int(total_slot)-int(booked_slot) except Exception: #here in real life scenario a alert will be sent to developer team with exception e raise booking_preplan_exceptions.SomethingWrongException finally: cur.close() con.close()