对于这样的问题SQLite也没有特别的解决方案。你说的方法几乎就是“标准”的做法,先把customer_id 设置为null, 然后插入该订单,( 
这样就不会引起外部键检查失败), 当获取该订单准确的customer_id后,再把它更新。
App的逻辑应考虑到这一点,所有customer_id 为null的订单都是不完整的,相当于草稿。

Zhai

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: 邱朗<mailto:qiulang2...@126.com>
Sent: 2017年3月31日 18:09
To: SQLite mailing list<mailto:sqlite-users@mailinglists.sqlite.org>
Subject: [sqlite] If I got many to many relationship data first, how do I 
insert them to my table?

Say my mobile app has a customer table, a product table, and an order table to 
record who buys what, the order table basically has 2 foreign keys, customer_id 
& product_id.

Now I got the order information first, within in it I can't find the customer 
information in my local sqlite table. As it turns out this is a new customer, 
whose information will come later from another thread/queue. To make things 
even worse the customer id I got from the order information is not the same one 
I used locally. My local customer id is INTEGER PRIMARY KEY (I do record that 
"true customer id" as another column and set index on it)

So how I do record this order information? I can come up with some clumsy 
solution, e.g. if I can't find contact info, I insert a record for it first. 
Later after I get the real information for this customer, I update customer & 
order table. But I was wondering is there any "standard" way for the situation 
like this?
BTW, I did ask the same question at stackoverflow, but because I use sqlite 
(while all the data come from web storing in MySQL) I was wondering if sqlite 
has any specific solution for it.
Thanks,
Qiulang
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to