I've got a python GUI framework that allows for the use of dropdown lists and returns the key/value list from the dropdown and any form submission boxes in the window. The problem that I am trying to solve is that I need to pass one of these values removed from the string type, specifically the 'FirstName' value from the dropdown list as it passes to the MySQL statement as 'FirstName'
rather than FirstName
.
I attempted to solve this on the MySQL side by use of a PREPARE statement but it didn't seem like that was a solution.
SQL_queries file
upi_update = '''UPDATE supplements_test.people
SET %(selection)s = %(first)s
WHERE IndividualID = CAST(%(id)s AS UNSIGNED)'''
usi_update = '''UPDATE supplements_test.supplements
SET %(selection)s = %(SuppName)s
WHERE SuppID = CAST(%(id)s AS UNSIGNED)'''
Main program file
import mysql.connector as mysql
# local file holding several dynamic query sets with validations/updates/inserts
# small sample above
import SQL_queries as sq
# MySQL connection code
cnx = mysql.connect(connection_info_here)
cur = cnx.cursor()
# key generated based on what functionality the user chooses from menu.
q_key = 'upi'
# Key value pairs returned from the GUI drop down selection/form input fields.
keys = {'first': 'John',
'last': 'Smith',
'email': 'j.smith@gmail.com',
'id': '1',
'selection': 'FirstName'}
cur.execute(eval(f'sq.{q_key}_update'), params=keys)
conn.commit()
UPDATE
After realizing I poorly described the complexities of my question, by giving a code example that attempted to simplify my code, I have edited the original with more information and found a solution which is posted as a self answer.