[PyQt] problem in <variable usage in sql statement>

Phil Thompson phil at riverbankcomputing.com
Thu Feb 7 09:03:55 GMT 2008


On Thursday 07 February 2008, Enis Karaarslan wrote:
> Hello all,
>
> I am a newbie in PyQt, just a simple question.
> I want to use a variable in my sql tatement.
>
> If I use string, following statment runs smoothly
>
> db.query("""SELECT OS, IP_Adress
> FROM ServerDB
> WHERE IP_Adresi='10.22.5.1'""")
> s = db.store_result()
>
>
> But I want to use the variable "chosen" and get the IP_Adresses equal to
> that variable such as:
>
> db.query("""
> 			SELECT OS, IP_Adress
> 			FROM ServerDB
> 			WHERE IP_Adress = chosen
> 			""")
>
> But it doesn't work ...
>
> thanks for the help

Dynamically create the string you want...

db.query("""
 			SELECT OS, IP_Adress
 			FROM ServerDB
 			WHERE IP_Adress = '%s'
 			""" % chosen)

Phil


More information about the PyQt mailing list