pymssql - How do I use SQL parameters with python? -


I have Python 2.7 and above. I am using.

To query the database, I will do something like .net: Use

  (SQL Commands Com = New SQL Commands ("Choose from the Customer, Where Customer ID = @CustomMedia ", Connection)) {com.Parameters.AddWithValue (" @ Customer ID ", Customer ID); // something with the command}  

I'm trying to understand what is equivalent to the python and more specifically, pymssql I realize that I can only format the string, though It does not seem that there is no problem in avoiding the parameters as well (I may be wrong on that).

How can I do this in Python?

After creating a connection object db :

  Cursor = db.execute ('Select customer from customer, where customer id =% s', [customer_id])  

then fetch ... Use any of the methods cursor of the object <. Do not be fooled by the part

% s : This string is not formatting, this parameter replacement (different DB API module parameters use different syntax for replacement - pymssql is just unfortunate % s ! -) is used to use.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -