[PyQt] QSqlQuery: one parameter in two different places?

Hans-Peter Jansen hpj at urpla.net
Tue Jan 1 22:22:38 GMT 2008


Am Dienstag, 1. Januar 2008 schrieb Sibylle Koczian:
> Hello,
>
> my SQL query has this form:
>
> sqltext = 'UPDATE mytable SET field_1 = :newvalue WHERE field_2 <
> :newvalue'
>
> The database is SQLITE. If I use this query as is:
>
> query = QSqlQuery()
> query.prepare(sqltext)
> query.bindValue(':newvalue', QVariant(mynewvalue))
> query.exec()
>
> then nothing is updated. If I change to
>
> sqltext = 'UPDATE mytable SET field_1 = :value_1 WHERE field_2 <
> :value_2' query = QSqlQuery()
> query.prepare(sqltext)
> query.bindValue(':value_1', QVariant(mynewvalue))
> query.bindValue(':value_2', QVariant(mynewvalue))
> query.exec()
>
> the update works as expected. Can't I use the same parameter name in two
> different places of the query, if I want to use the same value twice?

On debugging such problems, I found QSqlQuery.lastQuery() pretty useful 
(before digging in the Qt source..). Hopefully it still exists in Qt4.
Applied to your problem, let us know about the outcome.

Cheers,
Pete


More information about the PyQt mailing list