Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- result1 = connector_mysql(subSerialNum, ldev, today_date)
- print(result1) #this works and appears to be a dictonary but i can split it
- ## into its elements like:
- ldev_cap = result1['ldev_cap'] ##-> this dosn't work here.....???? if i return it as a dictonary..
- #and i'm unsure how to split them when i pass just the paramaters
- #back if i split the dictionary in the sql function.
- ...
- def connector_mysql(subSerialNum, ldev, today_date):
- import pymysql.cursors
- db_server = 'localhost'
- db_name = 'CBDB'
- db_pass = 'secure_password'
- db_user = 'user1'
- sql_query = (
- "SELECT ldev_cap, ldev_usdcap FROM Ldevs WHERE sub_serial=%(serial)s "
- "and ldev_id=%(lun)s and data_date=%(todayD)s")
- connection = pymysql.connect(host=db_server,
- user=db_user,
- password=db_pass,
- db=db_name,
- cursorclass=pymysql.cursors.DictCursor)
- try:
- with connection.cursor() as cursor:
- cursor.execute(sql_query, {'serial': subSerialNum, 'lun': ldev, 'todayD': today_date})
- result = cursor.fetchone()
- while result:
- ldev_cap = result['ldev_cap'] #here the dictionary acts as
- #expected and i can assign a value
- ldev_usdcap = result['ldev_usdcap']
- print(result)
- return ldev_cap, ldev_usdcap #here i can return
- finally:
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement