[PyKDE] Re: Using QSqlQuery + bindValue = TypeError ?

Hans-Peter Jansen hpj at urpla.net
Sun Feb 27 16:32:59 GMT 2005


On Sunday 27 February 2005 16:10, Jorge Godoy wrote:
> Hans-Peter Jansen <hpj at urpla.net> writes:
> > You may try to reproduce this behaviour within a minimal Qt
> > example, since I would suspect this problem there.. PyQts cover
> > is just to thin to mangle the results in such a way ;-)
>
> I'll try and see if I remember enough C++ for that (hey! it's been
> more than 5 years that I don't write C or C++ code, thanks to Perl
> and Python ;-))

Just mangle one of the SQL examples, that comes with Qt...

> > Anyway, I would go the pythonic way by using %s or in more
> > complex situations dictionary referencing: %(senha)s with python
> > strings..
>
> The problem here is loosing the "auto-quoting" facility.  I'd have
> to check the string to see if there's no single quote inside it or
> anything else that can be used to trick the DB and do something
> that is not allowed.
>
> Letting the driver quote everything I don't have to worry with
> that.  At least, everything used to be correct with both pypgsql
> and psycopg when I used to use wxPython for this application.
>
> OR, did I misunderstand you and PyQt will auto-quote things
> correctly if I use the DB API syntax?

You can't use the Python DB API syntax, since it's completely bypassed 
with Qt SQL. I was talking about the usual Python string syntax, but 
you're right, you have to handle the quoting yourself in this case.

BTW, I just checked your problem with the attached script, MySQL, and 
a database as defined as in testdb_mysql.sql from PyQt/examples3/SQL 
without such problems.

Python version: 2.3+
sip version: 4.2
Qt version: 3.2.1
PyQt version: 3.14
MySQL version: 4.0.21

Cheers,
Pete
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testdb.py
Type: text/x-python
Size: 1562 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20050227/4a0967d9/testdb.py


More information about the PyQt mailing list