Search code examples
androidandroid-roomandroid-architecture-components

Getting Error when Passing the TableName with Parameters using -Android Sqlite Room ORM


1.when trying to access the data with tablename as a parameter using method, getting below mentioned error using Room Library in android.

--> There is a problem with the query: ERROR] SQL error or missing database (no such table: table Name)

MainActivity.class

userData1= userSampleDatabase.daoAccessForUser().getItembyIdvalue("UserData","1");

DaoAccessForUser.class

 @Query("select * from 'tableName' where id = :id")
 List<UserData> getItembyIdvalue(String tableName,String id);

Thanks in Advance.


Solution

  • Room does not support dynamic replacement of the table name.

    In your DAO, replace 'tableName' with the actual table name, as defined on the associated @Entity. Or, use @RawQuery instead of @Query and provide the entire SQL SELECT statement at runtime.