Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does ? mean in python pyodbc module

import pyodbc
cursor.execute("INSERT INTO Testing_Param(Seed_Number,Cycle_Name) VALUES (?,?)",('0','CoupleIn'))

what does the "?" mean in the code? When I try to replace the ? to %s for the "CoupleIn" which is the string and %d for the "0", why does it appear error message:

pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 2 parameters were supplied', 'HY000')

I am new to the pyodbc module to do transfering data from Python into Microsoft SQL server

like image 201
Dsw Wds Avatar asked Jan 02 '26 03:01

Dsw Wds


1 Answers

? is the placeholder for the substitution engine. The cursor.execute function is responsible for properly escaping the values in the tuple and inserting them into the query where the respective question marks are to form a valid query. This keeps you safe from sql injection attacks where normal string interpolation would leave your database vulnerable to attackers.

You can read more about the standard python database apis in PEP-0249 -- Specifically, your database wrapper is using qmark paramstyle.

like image 177
mgilson Avatar answered Jan 03 '26 15:01

mgilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!