'It is better to call a Room DataBase query many times or create a variable?
It is something that may seem very new but I have this doubt, I will do it with a simple example:
I have a database with a table that contains, among many other things, a "name" column
When I want to use the name of id 1 many times, what is the best practice?
Option 1: Create a String variable called "name" to make a single query in the database Option 2: Call "name" directly from the database every time it is to be used
I always create a variable to avoid many queries in my database but I don't know if I'm right
String name = appDataBase.tableDao().getName(id);
textView1.setText(name);
textView2.setText("Employee: " + name);
.
.
.
Solution 1:[1]
CRUD operations are always "expensive". Usually they involve network call. Avoid as.muchbas possible. Less is better.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mzlobecki |
