i have an entity Settings
@Entity()
class Settings {
@PrimaryKey(autoGenerate: true)
int? id;
String key;
String? value;
Settings(this.id, this.key, this.value);
}
and DAO for Settings
@dao
abstract class SettingsDao {
@Query('SELECT * FROM Settings')
Future<List<Settings>> findAll();
@Query("SELECT * FROM Settings WHERE key = 'update_date_time'")
Future<Settings?> findByKey();
}
after execution this code
SettingsDao settingsDao=sl.get<SettingsDao>();
Settings? updateDataTime = await settingsDao.findByKey();
and updateDataTime == null, but
final allSettings = await settingsDao.findAll();
allSettings contains all my Settings entity
why updateDataTime is null? in allSettings list I have my Settings(6) , one of which has update_date_time in key field
and if i add in my Dao another method, if I want to retrieve a List instead of one entity
@Query("SELECT * FROM Settings WHERE key = 'update_date_time'")
Future<List<Settings>> findByKey2();
I has this error:
E/flutter (23265): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Unsupported query "SELECT * FROM Settings WHERE key = 'update_date_time'" for List return type. It should be SELECT, since DELETE, UPDATE, INSERT returns
int type. E/flutter (23265): #0 QueryAdapter.queryList (package:floor_common/src/adapter/query_adapter.dart:53:7) E/flutter (23265): #1 _$SettingsDao.findByKey2 (package:vr360newtablet/vr360_database.g.dart:892:26)
tried to receive data via streams: null there too
Igor Abramov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.