[PyKDE] Sql prepare
Diez B. Roggisch
deets at web.de
Thu Nov 3 22:12:21 GMT 2005
Matthias Frick wrote:
> hi i got some problems with the prepare function fo QSqlQuery
>
> i dont get some usefull back.
>
> here my code:
>
> print db
> query = QSqlQuery(db)
> print query.prepare( "Select :l, lot_id from yb_lot_history where rownum
> < 4" )
> print query.bindValue( ":l", QVariant("lot_id"), QSql.ParameterType(3))
> print query.execQuery()
> print query.isActive()
> print query.executedQuery ()
>
> while query.next():
> print "erg:",query.value(0).toString()
>
>
> and here the output:
>
> <qtsql.QSqlDatabase object at 0x009C8B70>
> True
> None
> True
> True
> Select :l, lot_id from yb_lot_history where rownum < 4
> erg: lot_id
> erg: lot_id
> erg: lot_id
That won't work, as binding parameters fills in the _value_ of that
parameter. So it is equivalent to
select 'lot_id', lot_id from ....
I fear you can't do what you want - you have to create the sql statement
directly with strings:
"select " + column_name + " from ..."
Regards,
Diez
More information about the PyQt
mailing list