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

Enis Karaarslan enis.karaarslan at ege.edu.tr
Thu Feb 7 09:23:43 GMT 2008


thanks for the reply,

But It still doesn't work. it gives error such:

Traceback (most recent call last):
  File "main.py", line 107, in on_listWidget_itemClicked
                            """ %chosen)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for 
the right syntax to use 
near '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2' 
at line 4")


I use MySQLdb, I take input from listWidget when clicked and convert to string 
and store it in "chosen"

chosen= str(item.text());
print chosen					# prints on command line for debugging

and the error is on the last line

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

thanks,



On Thursday 07 February 2008 11:03:55 Phil Thompson wrote:
> 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
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
--------------------------------------------
* Ar.Gör.Enis Karaarslan                    
* Ege University
* Kampüs Network Yönetim Grubu                 
* ULAK-CSIRT - http://csirt.ulakbim.gov.tr  
--------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080207/2dbda52c/attachment.bin


More information about the PyQt mailing list