[Qt-interest] QSqlRecord population error checking

Israel Brewster israel at frontierflying.com
Thu Dec 10 22:42:34 CET 2009


What is the best way to do error checking when populating a QSqlRecord  
with data? Or, a slightly different question that might solve the  
first, what is the best way to add and populate a new row on a  
QSqlTableModel? The goal here is to insert a new record into a  
QSqlTableModel (and, thus, into the database) populated with data.

The method I am using is to create a new QSqlRecord, which I set equal  
to QSqlTableModel::record() (i.e. an "empty" record from the table). I  
then use QSqlRecord::setValue on each field that I expect to be there  
to set the data, and use QSqlTableModel::insertRecord(QSqlRecord) to  
append the new record to the table. This process works.

The problem I have is that QSqlRecord::setValue() function has no  
error checking that I can see. According to the documentation, the  
setValue function "Sets the value of the field at position index to  
val. If the field does not exist, nothing happens". It's that "nothing  
happens" that scares me. In a perfect world, the database in question  
will always be set up correctly, and this will always work. In the  
real world, I don't want to assume that-someone may have messed with  
the database, misspelled a column name, etc. In this case, this  
process would still work with no errors as far as the program is  
concerned, but data would be lost- obviously not acceptable. At the  
moment what I am doing is after each setValue call, I do an inverse  
value call and make sure the return is what I just set. This seems  
rather kludgy, however. Is there a better way?

-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091210/cdd58d5a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091210/cdd58d5a/attachment.bin 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091210/cdd58d5a/attachment-0001.html 


More information about the Qt-interest-old mailing list