Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import MySQLdb
  2.  
  3. class AdoptBranch:
  4. def __init__(self):
  5. self.connection = MySQLdb.connect(host='localhost',user='root', db='activeDB')
  6. self.cursor = self.connection.cursor()
  7.  
  8. def __enter__(self):
  9. return self.cursor
  10. def __exit__(self, type, value, traceback):
  11. self.connection.commit()
  12. self.connection.close()
  13.  
  14. @staticmethod
  15. def select_country():
  16. return 'select distinct countryName from FileOVPN'
  17. @staticmethod
  18. def select_state(country):
  19. return 'select stateProv FROM FileOVPN WHERE countryName = \'%s\'' % (country)
  20.  
  21.  
  22. """"""""""""""""""""""""""""""""""
  23.  
  24.  
  25.  
  26. NEW FILE
  27.  
  28.  
  29.  
  30.  
  31. """"""""""""""""""""""""""""""""""
  32.  
  33.  
  34.  
  35. def country():
  36. with AdoptBranch() as cur:
  37. cur.execute(AdoptBranch.select_country())
  38. return cur.fetchall()
  39.  
  40. def state(country):
  41. with AdoptBranch() as cur:
  42. cur.execute(AdoptBranch.select_state(country))
  43. return cur.fetchall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement