0

I have a single registration form in my application. When the user clicks on the submit button for this form, these values will be stored in a database. I want to design the table for that database, but the problem is that I have dynamically added values. This means I have added a "add(+)" button. When the user clicks this button, it adds more text fields. If the userfills those fields, I now have more fields that need to be entered into the database.

An example of my query:

String CREATE_MEDICINE_TABLE = " CREATE TABLE medicinetable "
            + "( id INTEGER PRIMARY KEY ,"
            + " class INTEGER ,name TEXT, instructions TEXT , fdate TEXT ,tdate TEXT,time char)";
1
  • Could you just have the variable-length data from user be stored in the one column, comma-separated (or similar)?
    – Anonsage
    Nov 13, 2014 at 19:34

2 Answers 2

1

have a fixed schema table for your default form elements.

for storing the data where user keeps adding new fields have another table like bolew

_id, user_id, field_key, field_value

you will have 1 to many relation from main table to the second table

user_id will be the foriegn key to the main table that has the default form entry for the user

now if the case is like, you dont have any default entries in the form, all all dynamic keys, then just generate a user_id for the user and follow just the second table which i described.

And if the dynamic entry is just value, and there is no key, just ignore/remove the field_key in the table.

5
  • thank you for your post Aun, PLEASE CHECK THIS SAMPLE EX. in the table id, class, name, instructions,fdate, tdata, time fields are there, time fiels only add more timings, in the sense once set time after click add more timings button then another fields will come for set timing, and then again click add more timing button , again more timins will be added, NOW PLEASE TELL ME HOW TO DESIGN DATABASE TABLE FOR THIS TIMINGS???
    – venkat
    Nov 14, 2014 at 5:57
  • i shall call main tables as exercise ---> { id, class, name, instructions,fdate, tdata } . then sub table will be exercise_timing ----> { id, exercise__id, timing} . exercise__id will be foriegn key to exercise table. so for one entry in exercise table, you will have multiple entries in the exercise_timing table.
    – Aun
    Nov 14, 2014 at 6:06
  • Hi Aun, i wrote query like tghis way, please check this query //create medicine table String CREATE_MEDICINE_TABLE = " CREATE TABLE medicinetable " + "( id INTEGER PRIMARY KEY , + " class INTEGER ,name TEXT, instructions TEXT , fdate TEXT ,tdate TEXT," +"time TEXT NOT NULL, FOREIGN KEY(time) REFERENCES "+timingstable+"(timeid)")"; //create time table String CREATE_TIMINGS_TABLE="CREATE TABLE timingstable" +"(timeid INTERGER PRIMARY KEY AUTOINCREMENT,timecol TEXT)";
    – venkat
    Nov 14, 2014 at 13:01
  • if this query correct then ok, other wise please make changes in my query.
    – venkat
    Nov 14, 2014 at 13:04
  • discussion like this is not encouraged in stackoverflow. and I don't see any query.. Better put new question specific to your problem
    – Aun
    Nov 14, 2014 at 13:06
0

So couldn't you just have all possible fields in your SQLite database and enter them as null if they aren't entered?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.