[PyKDE] QSqlCursor problems

Phil Thompson phil at river-bank.demon.co.uk
Thu Dec 20 11:45:02 GMT 2001


Nico van der Walt wrote:
> 
> I am using PyQT3 to access a PostgreSQL database. The data that the SQL
> cursor returns is blank for character fields and 0 for integer fields. The
> correct number of rows are returned.
> 
> Here is a small program I wrote and it's output:
> 
> -----------------------------------------------------------------------------------------------
> 
> import sys
> from qt import *
> from qtsql import *
> 
> a = QApplication(sys.argv)
> 
> db = QSqlDatabase.addDatabase('QPSQL7')
> db.setDatabaseName('test')
> db.setHostName('ns2')
> if not db.open():
>    raise SystemExit
> 
> c = QSqlCursor('gl')
> c.select()
> while c.next():
>         print c.toString(c.editBuffer(),'',':',' | ')
>         print c.value('acc_number').toString()
> 
> ---------------------------------------------------------------------------------------------
> 
> Output:
> acc_number : 0 |  name : '' |  type : ''
> 0
> acc_number : 0 |  name : '' |  type : ''
> 0
> acc_number : 0 |  name : '' |  type : ''
> 0
> 

Hmm, I'm struggling with this. It's definately a bug because the
equivalent C++ code works as expected. The QVariant returned by
QSqlCursor.next() has the right type for the column, and (as you say) it
seems to process each row - it's just the value itself is always zero or
null.

I'll continue to poke around - but any other suggestions are welcome.

Phil




More information about the PyQt mailing list