Guest User

Untitled

a guest
Nov 9th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. import pymysql.connections
  2. from model.group import Group
  3. from model.contact import Contact
  4.  
  5. class DbFixture:
  6.  
  7. def __init__(self, host, name, user, password):
  8. self.host = host
  9. self.name = name
  10. self.user = user
  11. self.password = password
  12. self.connection = pymysql.connect(host=host, database=name, user=user, password=password, autocommit=True)
  13.  
  14. def get_group_list(self):
  15. list = []
  16. cursor = self.connection.cursor()
  17. try:
  18. cursor.execute("select group_id, group_name, group_header, group_footer from group_list")
  19. #cursor.execute("select group_id, group_name from group_list")
  20. for row in cursor:
  21. #(id, name) = row
  22. (id, name, header, footer) = row
  23. list.append(Group(id=str(id), name=name))
  24. #list.append(Group(id=str(id), name=name, header=header, footer=footer))
  25. finally:
  26. cursor.close()
  27. return list
  28.  
  29. def destroy(self):
  30. self.connection.close()
  31.  
  32.  
  33. def get_contact_list(self):
  34. list = []
  35. cursor = self.connection.cursor()
  36. try:
  37. cursor.execute("select id, firstname, middlename, lastname, nickname, title, company, address, home, mobile, work, fax, email, email2,"
  38. " email3, homepage, bday, bmonth, byear, aday, amonth, ayear, address2, phone2, notes from addressbook where deprecated='0000-00-00 00:00:00'")
  39. for row in cursor:
  40. (id, firstname, middlename, lastname, nickname, title, company, address, home, mobile, work, fax, email, email2, email3,
  41. homepage, bday, bmonth, byear, aday, amonth, ayear, address2, phone2, notes) = row
  42. #list.append(Contact(id=str(id), firstname=firstname, middlename=middlename, lastname=lastname, nickname=nickname, title=title,
  43. #company=company, address=address, home=home, mobile=mobile, work=work, fax=fax, email=email, email2=email2,
  44. #email3=email3, homepage=homepage, bday=bday, bmonth=bmonth, byear=byear, aday=aday, amonth=amonth,
  45. #ayear=ayear, address2=address, phone2=phone2, notes=notes))
  46. #list.append(Contact(id=str(id), firstname=firstname, lastname=lastname, address=address, home=home, mobile=mobile, work=work, fax=fax, email=email, email2=email2, email3=email3))
  47. list.append(Contact(id=str(id), firstname=firstname, lastname=lastname, address=address))
  48. finally:
  49. cursor.close()
  50. return list
  51.  
  52. def destroy(self):
  53. self.connection.close()
Add Comment
Please, Sign In to add comment