[Qt-interest] QSqlRecord pqsql & INSERT

Bill King bill.king at nokia.com
Thu Dec 24 02:26:46 CET 2009


On 12/24/2009 11:06 AM, ext Jan wrote:
> Hi,
>
> I am trying to insert a record into a QSqlTableModel (Postgres DB Table).
> The first column is a serial primary key. setRecord and submitAll fails 
> with the message that the serial unique constraint failed.
> I tried to set the record's field to setAutoValue(true) or 
> setGenerated(false) but it always failed.
>
> The postgres docs say I could use DEFAULT in an insert statement. But if 
> I use DEFAULT in the record it is treated as a string.
>
> Does anyone know how I could insert a record with a serial field?
>
> Jan
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   
yes, insert the record, but don't set anything in that field.
QSqlQuery::lastInsertId () will return you the value of the field from
the last insert so that you can then use this if necessary.

-- 
Bill King, Software Engineer
Qt Development Frameworks, Nokia Pty Ltd
Brisbane Office

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091224/dd60f158/attachment.html 


More information about the Qt-interest-old mailing list