def deleteById(id): emp=Ems_services.searchById(id) if emp==None: return False else: cnx=DBconnection.connect() cur=cnx.cursor() query="delete from empDetails where empId=%s" data=[] data.append(id) cur.execute(query,data) cnx.commit() cur.close() cnx.close() return True
def getAllEmployees(): emplist=[] cnx=DBconnection.connect() cur=cnx.cursor() query="select * from empDetails" cur.execute(query) tb=cur.fetchall() for row in tb: emp=Employee() emp.setId(int(row[0])) emp.setName(row[1]) emp.setSalary(float(row[2])) emp.setAddress(row[3]) emplist.append(emp) cur.close() cnx.close() return emplist
def addEmployee(emp): result=False cnx=DBconnection.connect() cur=cnx.cursor() query="insert into empDetails values(%s,%s,%s,%s)" data=[] data.append(emp.getId()) data.append(emp.getName()) data.append(emp.getSalary()) data.append(emp.getAddress()) try: cur.execute(query,data) except: return False if (cur.rowcount==1): result=True cnx.commit() cur.close() cnx.close() return result
def searchBySalRange(min, max): emplist = [] cnx = DBconnection.connect() cur = cnx.cursor() query = "select * from empDetails_2 where empSalary>%s and empSalary<%s" data = [] data.append(min) data.append(max) cur.execute(query, data) tb = cur.fetchall() for row in tb: emp = Employee() emp.setId(int(row[0])) emp.setName(row[1]) emp.setSalary(float(row[2])) emp.setAddress(row[3]) emplist.append(emp) cur.close() cnx.close() return emplist
def searchById(id): cnx=DBconnection.connect() cur=cnx.cursor() query="select * from empDetails where empId=%s" data=[] data.append(id) cur.execute(query,data) tb=cur.fetchall() if cur.rowcount==0: cur.close() cnx.close() return None for row in tb: emp=Employee() emp.setId(int(row[0])) emp.setName(row[1]) emp.setSalary(float(row[2])) emp.setAddress(row[3]) cur.close() cnx.close() return emp