Guest User

Untitled

a guest
Apr 2nd, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import pymysql.cursors
  2. from model.group import Group
  3. from model.contact import Contact
  4.  
  5. class DbFixture:
  6. def __init__(self, host, name, user, password):
  7. self.host = host
  8. self.name = name
  9. self.user = user
  10. self.password = password
  11. self.connection = pymysql.connect(host=host, database=name, user=user, password=password, autocommit=True)
  12.  
  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. for row in cursor:
  20. (id, name, header, footer) = row
  21. list.append(Group(id=str(id), name=name, header=header, footer=footer))
  22. finally:
  23. cursor.close()
  24. return list
  25.  
  26. def get_contact_list(self):
  27. list = []
  28. cursor = self.connection.cursor()
  29. try:
  30. cursor.execute("select id, firstname, lastname from addressbook")
  31. for row in cursor:
  32. (id, firstname, lastname) = row
  33. list.append(Contact(id=str(id), firstname=firstname, lastname=lastname))
  34. finally:
  35. cursor.close()
  36. return list
  37.  
  38. def destroy(self):
  39. self.connection.close()
Add Comment
Please, Sign In to add comment