I'm trying to get all value of column 'group' from table 'group' at android room-database. Here is table 'group' at my android room-database. enter image description here
And this is Dao. I want to use getGroupName() enter image description here
But when I use this function at MainActivity and test by print it, result is enter image description here
I think column name is printed... But I don't know what to do.
What should I do if I want to get only values of column 'group'?? For example, in this case, [group1, group2, groupA]
I agree with the above answer https://stackoverflow.com/a/77204367/8432542
My edition -
I think, There are a couple of issues with your Room DAO class code snippet:
Incorrect quotation marks: You are using single quotes around table and column names ('color' and 'group'). In SQL, single quotes are used to denote string literals, not table or column names. You should use backticks (`) to enclose table and column names if needed, especially if they contain spaces or keywords.
Using reserved keywords: "group" is a reserved keyword in SQL, and it's generally not a good practice to use reserved words as table or column names. If you insist on using it, you can use backticks to escape it.
Here's a corrected version of your code:
@Query("SELECT `color` FROM `group` WHERE `group` = :groupName") fun getGroupColor(groupName: String): String
This should work as expected in your Android application.