[Qt-interest] How to retreive a value in relational sql model?

Yevgen Yashchenko lester.dev at gmail.com
Thu Dec 3 10:36:01 CET 2009


> The mapper returns Table1.id, Table2.name where Table2.id == Table1.id
you meant Table2.id = Table1.name_id, right? Because otherwise it's not
correct.

Unfortunately I can't lookup for table2.id by table2.name because it's not
unique. Actually there are more values in the table2 I just skipped to be
more clear. What I get from table1->record(index.row()) is "id" from table1,
"name" from table2 and that's all.
Now I made a workaround with "SELECT name_id FROM table1 WHERE id" = id from
table1 inside a data() of my sublclaseed model
but that's an ugly hack and I should be killed for that (sigh).

upd: forgot to cc: qt-interest

2009/12/3 jjDaNiMoTh <jjdanimoth at gmail.com>

2009/12/3 Yevgen Yashchenko <lester.dev at gmail.com>:
> > You see the rows in the table1 don't exactly match the appropriate rows
> in
> > the table2. For example the first row in table1 can hold a key to the row
> 12
> > in the table2, so just use of index.row() is insufficient. How this
> > situation is beaten?
>
> First of all, [1].
> Then, you need to retrieve the key not from table1, but in table2, as
> you know the name.
>
> Ex.
>
> Table1 --> id, name_id ( REF to Table2.id )
> Table2 --> id, name
>
> The mapper returns Table1.id, Table2.name where Table2.id == Table1.id
>
> So, you need to find Table2.id where Table2.name is the value returned
> from the mapper.
>
> [1] http://www.faqs.org/rfcs/rfc1855.html
>
> --
> Key Fingerprint
> 4588 F931 A6E7 C7D5 A302  3064 12EB E87F 9B28 A9D2
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091203/39792eac/attachment.html 


More information about the Qt-interest-old mailing list