Matti Airas wrote:

> You should be able to use None to replace C++ NULL values. If it doesn't
> work, it's probably a bug in PySide. Could you please report it at
> http://bugs.openbossa.org to ensure it's fixed ASAP?

Ok, I have written a small example that exhibits this problem, for READING a 
database. But the problem also exists for WRITING a database, as I have said 
in my original post, and is surely more general: Null QVariant are probably 
not properly converted to None.
I give below two versions:
* a working PyQt version: the NULL value is tested by applying the isNull() 
method to the QVariant returned by QSqlQuery.value()
* a non-working PySide version: the value returned by QSqlQuery.value() is 
not None, it is the empty string "", so it is not detected by the display 
loop.

Tell me if you agree that this behavior is a bug. If yes, I will enter a bug 
report on the PySide website.

####################
# PyQt version
from PyQt4.QtSql import *
import sys

db = QSqlDatabase.addDatabase( "QSQLITE" )
db.setDatabaseName( ":memory:" )

if not db.open():
    sys.exit(1)

query = QSqlQuery()

query.exec_( "CREATE TABLE person ( firstname VARCHAR(20)"
        ", lastname VARCHAR(20) );" )
query.exec_( "INSERT INTO person VALUES( 'Danny', 'Young');" )
query.exec_( "INSERT INTO person ( firstname ) VALUES( 'Christine' );" )
query.exec_( "INSERT INTO person VALUES( 'Lars', 'Gordon');" )

query.exec_( "SELECT * FROM person;" )

record = query.record()
for i in range( record.count() ):
    print record.fieldName( i ), "\t",

print "\n----------------------------"

for i in range( record.count() ):
    while query.next():
        for i in range( record.count() ):
            value = query.value(i)
            if value.isNull():
                print "NULL", "\t",
            else:
                print value.toString(), "\t",
        print

####################
# PySide version
from PySide.QtSql import *
import sys

db = QSqlDatabase.addDatabase( "QSQLITE" )
db.setDatabaseName( ":memory:" )

if not db.open():
    sys.exit(1)

query = QSqlQuery()

query.exec_( "CREATE TABLE person ( firstname VARCHAR(20)"
        ", lastname VARCHAR(20) );" )
query.exec_( "INSERT INTO person VALUES( 'Danny', 'Young');" )
query.exec_( "INSERT INTO person ( firstname ) VALUES( 'Christine' );" )
query.exec_( "INSERT INTO person VALUES( 'Lars', 'Gordon');" )

query.exec_( "SELECT * FROM person;" )

record = query.record()
for i in range( record.count() ):
    print record.fieldName( i ), "\t",

print "\n----------------------------"

for i in range( record.count() ):
    while query.next():
        for i in range( record.count() ):
            value = query.value(i)
            if value == None:
                print "NULL", "\t",
            else:
                print value, "\t",
        print

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)

_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to