Home > OS >  Is SQLite/Android Room the right database for my app?
Is SQLite/Android Room the right database for my app?

Time:08-09

I'm building an app where the user will control a few sliders, produce an output based on those sliders, and then that output will be saved so they can scroll through their history. The sliders will be labeled with information and attributes assigned, the outputs of the sliders will be procedurally generated (with the exception of a few pre-coded examples). So for example, if three sliders are "red", "green", and "blue", then sliding the red and green sliders all the way on would output "yellow", and then "yellow" would be saved in the user's history with the current date and time. All of this will be done on-device with nothing coming from or going to a server.

On the data management end, this seems like three databases, each with a many-to-many relationship with the others. ie, each slider will be attached to multiple outputs and each output can be attached to multiple sliders; then, each output can be attached to multiple timestamps, although each timestamp will be attached to just one output.

In order to achieve this, I think I need to use SQLite Room for data management. I'm imagining one table for the sliders, a second table for the outputs, and a third for the user's history, plus join tables for sliders-to-outputs and outputs-to-history.

My only coding experience is hobbyist-level web development, so Kotlin, SQLite, room, relational databases, and Android development is all new to me. I'm just trying to figure out what tools I need to learn in order to build this so I don't invest weeks of time just to learn I'm not even using the right tools for the job. I don't know what I don't know, so any help is appreciated.

CodePudding user response:

I suggest using ROOM as its easier to implement and comes with less boilerplate code ( enter image description here

  • The database, at this stage is empty (although created due to the attempt to extract data).

If Black (or anything) is entered into the Edit Text and the SAVE button is clicked then :-

enter image description here

i.e. the row that was inserted, is now displayed.

Now if

  • the red slider is move all the way over to the right and red is entered into the edit text and save is clicked, and then
  • only the green slider is all the way over to the right and green is entered into the edit text and save is clicked, and then
  • likewise for blue and then
  • all three sliders are moved and white is entered then:-

enter image description here

Now if Black is clicked in the List :-

enter image description here

Red is clicked :-

enter image description here

etc. (of course intermediate values will be saved likewise, that is all three values are saved every time).

Now if you wanted to extract the date and time and have it show in the ListView instead of the combined colour values, then changing the line:-

csr = db.getOpenHelper().writableDatabase.query("SELECT *,sliderhistoryId AS ${BaseColumns._ID}, sliderRed||':'||sliderGreen||':'||sliderBlue AS sliderValues FROM sliderhistory")

to

csr = db.getOpenHelper().writableDatabase.query("SELECT *,sliderhistoryId as ${BaseColumns._ID}, datetime(sliderTimestamp,'unixepoch') AS sliderValues FROM sliderhistory")

will facilitate this resulting in, for example :-

enter image description here

  • Related