SHARE
TWEET

Untitled

a guest Sep 14th, 2017 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. result = cursor.fetchone(variable1, variable2, variable3)
  2. return result
  3.    
  4. result1 = connector_mysql(subSerialNum, ldev, today_date)
  5.     print(result1)
  6.    
  7. {'ldev_cap': '0938376656', 'ldev_usedcap': '90937763873'}
  8.    
  9. used_capacity = result1['ldev_cap']
  10.    
  11. cursor.execute(sql_query, {'serial': subSerialNum, 'lun': ldev, 'todayD': today_date})
  12. result = cursor.fetchone()
  13. while result:
  14.     ldev_cap = result['ldev_cap']
  15.     ldev_usdcap = result['ldev_usdcap']
  16.     return ldev_cap, ldev_usdcap
  17.    
  18. ldev_cap = result['ldev_cap']
  19.    
  20. result1 = connector_mysql(subSerialNum, ldev, today_date)
  21.    
  22. return ldev_cap, ldev_usdcap
  23.    
  24. capacity, usd_capacity = connector_mysql(subSerialNum, ldev, today_date)
  25.    
  26. capacity, usd_capacity = connector_mysql(subSerialNum, ldev, today_date)
  27. print(capacity)
  28. print(usd_capacity)
  29.  
  30. def connector_mysql(subSerialNum, ldev, today_date):
  31.  
  32.     import pymysql.cursors
  33.  
  34.     db_server = 'localhost'
  35.     db_name = 'CBDB'
  36.     db_pass = 'secure_password'
  37.     db_user = 'user1'
  38.  
  39.     sql_query = (
  40.         "SELECT ldev_cap, ldev_usdcap FROM Ldevs WHERE sub_serial=%(serial)s "
  41.         "and ldev_id=%(lun)s and data_date=%(todayD)s")
  42.  
  43.     connection = pymysql.connect(host=db_server,
  44.                                  user=db_user,
  45.                                  password=db_pass,
  46.                                  db=db_name,
  47.                                  cursorclass=pymysql.cursors.DictCursor)
  48.  
  49.     try:
  50.         with connection.cursor() as cursor:
  51.             cursor.execute(sql_query, {'serial': subSerialNum, 'lun': ldev, 'todayD': today_date})
  52.             result = cursor.fetchone()
  53.             #return result          #used for returning dict
  54.  
  55.             while result:
  56.                 ldev_cap = result['ldev_cap']
  57.                 ldev_usdcap = result['ldev_usdcap']
  58.  
  59.                 print(result)
  60.                 return ldev_cap, ldev_usdcap
  61.  
  62.     finally:
  63.         connection.close()
RAW Paste Data
Top