[PyQt] QDataWidgetMapper and default values

Scott Frankel frankel at circlesfx.com
Mon Jul 6 06:27:13 BST 2009


Is there a way to specify a default value for a Data Widget Mapper if  
a user leaves a mapped field  empty?  The mapper appears to ignore the  
db schema's default declarations.  Ideally, I'd like to insert Null.   
Something analogous to this:

	test=# INSERT INTO gear (name, addr) VALUES ('qwe', Null);

My test case example has a table with a MACADDR field.  There are  
times when a user would enter a valid macaddr and times when the  
macaddr field should be left blank.  Note that the QSQLITE driver  
happily allows the field to be filled-in or not.  But the QPSQL driver  
appears to validate the macaddr field.  When empty, this causes the  
mapper's model to fail with an invalid input syntax error on  
submitAll().  eg:

	ERROR: invalid input syntax for type macaddr: "" QPSQL: Unable to  
create query

Attached please find a simple example program, mapperTest.py, and a db  
schema file, test_db.sql.  (Not sure how to combine the two into a  
single .py file.)  To recreate the db from the cmd-line:

	% createdb test
	% psql test < test_db.sql

Thanks in advance!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mapperTest.py
Type: text/x-python-script
Size: 5711 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090706/2d4a78c0/mapperTest.bin
-------------- next part --------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_db.sql
Type: application/octet-stream
Size: 426 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090706/2d4a78c0/test_db.obj

More information about the PyQt mailing list