Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. ...
  2. result1 = connector_mysql(subSerialNum, ldev, today_date)
  3.  
  4. print(result1) #this works and appears to be a dictonary but i can split it
  5. ## into its elements like:
  6. ldev_cap = result1['ldev_cap'] ##-> this dosn't work here.....???? if i return it as a dictonary..
  7. #and i'm unsure how to split them when i pass just the paramaters
  8. #back if i split the dictionary in the sql function.
  9.  
  10. ...
  11.  
  12. def connector_mysql(subSerialNum, ldev, today_date):
  13.  
  14. import pymysql.cursors
  15.  
  16. db_server = 'localhost'
  17. db_name = 'CBDB'
  18. db_pass = 'secure_password'
  19. db_user = 'user1'
  20.  
  21. sql_query = (
  22. "SELECT ldev_cap, ldev_usdcap FROM Ldevs WHERE sub_serial=%(serial)s "
  23. "and ldev_id=%(lun)s and data_date=%(todayD)s")
  24.  
  25. connection = pymysql.connect(host=db_server,
  26. user=db_user,
  27. password=db_pass,
  28. db=db_name,
  29. cursorclass=pymysql.cursors.DictCursor)
  30.  
  31. try:
  32. with connection.cursor() as cursor:
  33. cursor.execute(sql_query, {'serial': subSerialNum, 'lun': ldev, 'todayD': today_date})
  34. result = cursor.fetchone()
  35.  
  36. while result:
  37. ldev_cap = result['ldev_cap'] #here the dictionary acts as
  38. #expected and i can assign a value
  39. ldev_usdcap = result['ldev_usdcap']
  40.  
  41. print(result)
  42. return ldev_cap, ldev_usdcap #here i can return
  43.  
  44. finally:
  45. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement