[Qt-interest] QSqlTableModel: How to retrieve a primary key for a new row?
Timo Schmiade
the_isz at gmx.de
Tue Mar 2 14:08:33 CET 2010
Hi all,
I'm currently writing a small program which is basically just an editor
for a SQLITE database. This database has several tables and for each
except one of them, I have a separate dialog to edit the values of a
row. When I want to add a new row, I call insertRow() on the model and
then show the values of this row (which are empty at first) in the
dialog.
My problem emerges with the table that doesn't have a separate editor.
To get more specific, I'll give you an example of how the tables look:
Authors: Documents:
ID | Last name | First name ID | Title
0 | Knuth | Donald 2 | The art of computer programming
1 | Meyers | Scott 4 | Effective C++
AuthorDocument:
Author | Document
0 | 2
1 | 4
Now, if I'm creating a new document, I want to select authors from the
Authors table and insert their ID into the AuthorDocument table mapping
it to the respective document.
My problem is, that in the moment when I create a new row in the
Documents table, the new row doesn't have a primary key (ID) yet, so I
don't know what to insert into the AuthorDocument table.
Is there a way to know which primary key the document is going to get
when it's submitted? I'm currently using OnManualSubmit as the model's
EditStrategy, which might make the problem even more complicated, and
I'm willing to use another one as well, but I didn't have any success
with those either yet.
Any help is greatly appreciated, especially if my approach is wrong and
I'd better use another one.
Thanks in advance!
More information about the Qt-interest-old
mailing list