Hi TP,
I didn't actually try to run the code but to me the syntax would appear
to be correct. Just go ahead and file it. :-)
Cheers,
ma.
On 22.11.2010 17:51, ext TP wrote:
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
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside