Placebo Placebo - 22 days ago 5
Android Question

Generating a SQLite database dynamically

I am building an application which is a form generator (it creates a form with a SQLite database based on a configuration file). The problem is that the database will never be the same, so I need to make it dynamic meaning that I want to be able to specify all the table rows and tables of the database.

The problem I have is that, since it's a configuration file, when I create the database I dont know yet what are the tables and/or the table rows so I am not able to rely on the

onCreate()
of the database.

I was wondering if there would be a better way to proceed other than overriding the
onCreate()
to do nothing and making my own
tableCreate()
function.

I don't know if this is clear enough since english is not my native language but I will edit my question if I need to. And by the way I am new to android so snipet + explications are appreciated.


  • When the application loads, it creates the database using the configuration file (a simple text file) that is pushed to the application (only if the database does not exist).

  • Then it creates the tables based on the configuration file again (the name of the table rows and type of data).

  • The application builds the form based on the configuration file with an attribute which will allow me to save the answer in the database created previously.



This application's goal is to be able to create new forms efficiently and in a really quick way in order to gather some informations on given person.

Answer

Ok so I managed to build a workaround: what I came up with is that I have a db with 4 fields (_id, farmerId, fieldName and fieldValue) this allows me to have some kind of value key for a specific farmer.

Then I builded some functions that generate a JSONObject with the different rows concerning a specific farmer and returns it to my activity. This way, it does not really matters if an "object" would need 5 or 6 fields.

Comments