[Qt-interest] QSqlRecord pqsql & INSERT

Israel Brewster israel at frontierflying.com
Thu Dec 24 18:11:03 CET 2009


On Dec 24, 2009, at 3:59 AM, Jan wrote:

> Bill King schrieb:
>> 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.
>
>    QSqlRecord r = model->record();
>    r.setGenerated(0, false);
>    r.setValue(1, "name4");
>    model->insertRecord(-1, r);
>    model->submitAll();

If you just want to insert a record for "name4", all you need to do is  
the following:

QSqlRecord r = model->record();
r.setValue(1, "name4");
model->insertRecord(-1, r);
model->submitAll();

Since you didn't set any value for the first field, PostgreSQL (or any  
of the other databases for that matter) will automatically populate it  
(since it is an auto-increment). I'm actually not even sure what the  
setGenerated function does or when you would want to call it - I have  
made a number of PostgreSQL Qt applications (and driven Bill King nuts  
when I run into issues ;-) ), and never needed to use that function.  
All my tables have an auto-increment column.

>    qDebug() << model->lastError().text();
>
>    delete model;
> }
>
>
> merry christmas btw
> Jan
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

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

-------------- 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/20091224/7b6d3aa2/attachment.bin 
-------------- next part --------------




More information about the Qt-interest-old mailing list