Jump to content

query database records using a parameter

- - - - -

  • Please log in to reply
2 replies to this topic

#1
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
please guys Am using this code to query the database and is working but when i want to use parameter in the sql where clause,
it does not work again, i knew may be am using wrong parameter. any help please



 rs = con.query("SELECT * from product where price = '200')

this works but when used parameter %s in the where clause as showed below, it stop working


 rs = connection.query("SELECT * from product where price = '%s')


Okay in Python, i have achieved it this way




rs = "SELECT * FROM product where price='%s'" % (price)


thanks

#2
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
 rs = con.query("SELECT * from product where price = '200')
I don't think you need to put 200 in single quotes.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#3
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
well whether 200 is surround by single quote or not its working. What am saying is that i need to make the selection
using a parameter symbols that will replace the 200 so that the code will look like


rs = connection.query("SELECT * from product where price = [B]'%s'[/B]")



see in python below i did it this way and is working


rs = "SELECT * FROM product where price='%s'" % (price)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users