Hi,

I'm experiencing strange behaviour to the point where I suspect a bug in PyQt4.
When I bind a value to a named placeholder in a prepared SqlQuery and that placeholder occures more than once, than not all (only the last?) occurances are bound correctly.
I'll attach an example demonstrating the problem.

sincerely yours
//Lorenz

PS: PyQt4 version: 4.7.3
    Python version: 2.6.5
    Qt verstion: 4.6.2
"""Demonstration of a bug:
    named parameters are not correctly bound to an sql query
    when they are used multiple times"""
from PyQt4.QtSql import *

# Setup the Database
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("sql_bug.db")
db.open()

# Setup an example table with one example entry
query = QSqlQuery()
query.exec_("""DROP TABLE IF EXISTs foo""")
query.exec_("""CREATE TABLE foo
               (id INTEGER PRIMARY KEY AUTOINCREMENT,
                bar INTEGER)""")
query.exec_("""INSERT INTO foo (bar)
               VALUES (0)""")

# this is the code revealing the bug. it will set bar to NULL
query.prepare("""UPDATE foo SET bar = :param
                 WHERE id IS :param""")
query.bindValue(":param", 1)

# using positional binding works fine and correctly sets 
## query.prepare("""UPDATE foo SET bar = ?
##                  WHERE id IS ?""")
## query.bindValue(0, 1)
## query.bindValue(1, 1)


query.exec_()
db.close()
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to