I have created two tables category and subcategory in mysql database. I am retrieving the same from sqlite and adding it to the sqlite database. In sqlite I have created a table category and added category values to it. I have created table subcategory with a foreign key referencing category id which is a auto increment value in category table.
String subcategoryquery="CREATE TABLE subcategory(subcategoryno INTEGER PRIMARY KEY AUTOINCREMENT, category_id INTEGER,subcategory TEXT,FOREIGN KEY (category_id) REFERENCES category(id))";
I have subcategory values in the content values.
My doubts are
- How to insert content values to the subcategory table which has a foreign key?
- How to insert subcategory for a particular category? For example dimmer has two subcategories. I do not want to specify in where clause as category='dimmer' particularly and while adding adding 'light' as subcategory I do not want to specify category='regweer'. How do I insert them in this condition?
My JSON array looks like this
[
{"category":"dimmer","subcategory":"led"},
{"category":"dimmer","subcategory":"flo"},
{"category":"relay","subcategory":""},
{"category":"regweer","subcategory":"light"}
]
Aucun commentaire:
Enregistrer un commentaire