[Interest] Storing complex SQL relations with Qt

Knut Krause knut.krause at lagom.de
Thu Dec 12 07:57:50 CET 2013


Hi,

my application uses sqlite for its data and I modeled some complex relations 
for customers, appointments and so on.

Now I want to edit such a relation using a custom dialog where the 
appointments go to a list and some other stuff to a table (all are 
QSqlTableModels).

The problem is: How do I insert the data depending on other things? Let's say 
an appointment needs a customer. I insert the new customer data and the 
appointments and when I click on submit I'd have to do something like

1. insert customer (I think with primary key autoincrement I can simply do 
that)

2. retrieve the inserted customers ID. Can I use the models query() to get 
lastInsertId()? Is this save?

3. Set this ID to all models that depends on customer (by hand?) and submit 
them as well

Is this approach safe? I mean AFAIK there are no transactions involved and 
what happens for example if I insert the customer and then my application 
crashes leaving my database in an inconsistent state?

Would be nice if someone could explain how I'm supposed to do this.

regards


Knut



More information about the Interest mailing list