0

How to pass my value to sql query?

I'm currently trying to write an api with python flask and sqlalchemy I'm able to insert data into my database table with 'hardcoded' sql insert queries. Example for the working code:

session.execute('INSERT INTO Persons(FirstName) VALUES(\'Henry\')' )

Now I would like to substitute VALUES in the query.

Code currently looks like this:

session.execute('INSERT INTO Persons(FirstName) VALUES(%(var_FirstName)s)',{
    'var_FirstName': request.args['FirstName'],
})

request.args['FirstName'] works fine and gets the FirstName i pass it but it does'nt get inserted into the sql query resulting in the following error:

Error message

davidism
  • 121,510
  • 29
  • 395
  • 339
M.Cav
  • 9
  • 3

0 Answers0