def flush(self, connection, oldTime=None, oldStaffName=None): """ Updates or creates the Staff member in the database """ cursor = connection.cursor() #maps attributes of the object to db columns sqlMap = {"time":"time", "employee_name":"staffName", "site":"location", "description":"description", "client_name":"clientName", "purpose":"purpose", "previous_client":"previousClient", "contact_number":"contactNumber", "made_by":"madeBy", "date_made":"dateMade", "advocate_called":"advocateCalled", "confirmed_by":"confirmedBy", "date_confirmed":"dateConfirmed", "last_period":"lastPeriod"} params = model.createSqlParams(AppointmentWriteColumns, sqlMap, self) #if and old time and old staff (primary keys) are given then do an update if oldTime and oldStaffName: query = model.updateString("appointment", AppointmentWriteColumns, \ "time = %(oldTime)s and employee_name = %(oldName)s") #add the where clause values just for the update sql statement params["oldTime"] = oldTime params["oldName"] = oldStaffName #else do a create statement else: query = model.insertString("appointment", AppointmentWriteColumns) cursor.execute(query, params) connection.commit() cursor.close()
def flush(self, connection, oldName=None): """ Updates or creates the appointment in the database """ cursor = connection.cursor() #map the database fields to this objects attributes sqlMap = {"name":"name", "role_id":"roleId", "is_active":"isActive", "street_address":"street", "city":"city", "zip":"zipCode", "phone":"phone", "state":"state"} #map the data params = model.createSqlParams(EmployeeColumns, sqlMap, self) #if a old name was given then do an update statement if oldName: query = model.updateString("employee", EmployeeColumns, "name = %(oldName)s") params["oldName"] = oldName #else do a create statement else: query = model.insertString("employee", EmployeeColumns) cursor.execute(query, params) connection.commit() cursor.close()
def flush(self, connection): """ Flushes the booking to the database """ cursor = connection.cursor() #map the database fields to this objects attributes sqlMap = {"name":"staffName", "start_time":"startTime", "end_time":"endTime", "site":"site"} #remove the last column, the id because it is autogenerated by the database columns = BookingColumns[:len(BookingColumns)-1] #map the data params = model.createSqlParams(columns, sqlMap, self) print "params!", params #if a old name was given then do an update statement if self.bookingId != None: query = model.updateString("booking", columns, "booking_id = %(theId)s") params["theId"] = self.bookingId #else do a create statement else: query = model.insertString("booking", columns) #get the id assigned to the object #select currval('booking_booking_id_seq') from booking; print "WHAT?",cursor.execute(query, params) connection.commit() cursor.close()