It is better to call a Room DataBase query many times or create a variable?

JP711

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);
    .
    .
    .
Sambhav Khandelwal
  1. If you are not modifying the value, it is preferred to Create a String variable called "name" to make a single query in the database
  2. If you are modifying it , it is preferred to Call "name" directly from the database every time it is to be used
  3. If somebody else can modify the name, and you need to see the latest value, Get it from the database directly

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to Query in a many to many relationship Room database?

Failed to create table with @Query in Room database

In Android Room how can I create and call a custom query

Call a method in a class many times and the variable stays consistent

Android room database query

Create variable that counts progressively how many times an ID is repeated in a day

Room: using variable in query

Call to undefined method Illuminate\Database\Query\Builder::has_many()

Many to many android room ref extra variable

Database design need better solution many to many

Hardcode Boolean Query In Room Database

Room database full dynamic query

Database query is not working in SQLite room

Room Database Query - Delete User

Android room database migration is running multiple times

How to Create Database for Storage Room

using member variable for query in Room

Better way to call Function multiple times

Trouble with one to many relations via room database

Database Query - One to Many

SQL Search Query show same results many times although it is only single time in my database

sequelize to create better database structure

Unable to create a better database structure

In PHP, how can I just create the conn to database once and use it many times from JavaScript through Ajax?

printing second variable as many times as first variable

while($query6=mysql_fetch_array($query5)).How many times it will run?If it select 4 values from the database

mySQL - Is there a better way of using many OR oparators in query?

Would Iterator loop call end() for many times?

Call function many times without duplicate it (with %>%)