Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue in query adapter's queryList where CompoundSelectStatemen… #781

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mthongvanh
Copy link

…t is not executed

queryList does not allow compound select statements to be executed. UNION queries throw state errors.
updating the rootNode's type check to BaseSelectStatement instead of SelectStatement fixes the issue.

@dkaera
Copy link
Collaborator

dkaera commented Sep 20, 2023

Is there an open issue for this PR?

@mthongvanh
Copy link
Author

mthongvanh commented Sep 20, 2023 via email

@dkaera
Copy link
Collaborator

dkaera commented Sep 20, 2023

Hi Dmytro, There's not currently an open issue. We just saw an issue recently after updating our fork. Should I create an issue first?

Please add a sample code that does not work in the current Floor version and a relevant explanation of the issue.
It'll help reviewers understand what problem this PR solves.

@mthongvanh
Copy link
Author

Floor version 1.4.2
Dart 2.19.6
Flutter 3.7.12

Issue:
When performing a queryList with a raw SELECT UNION directly with QueryAdapter, the query fails and throws a StateError. Since sqlparser returns the rootNode as a CompoundSelectStatement, the type check for SelectStatement fails.

Fix:
To fix the issue and allow other types of SELECT statements, it should instead check for the BaseSelectStatement type which is extended by both SelectStatement and CompoundSelectStatement.

Sample Code
The code below throws a StateError when added to the floor example project.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final database = await $FloorFlutterDatabase
      .databaseBuilder('flutter_database.db')
      .build();
  final dao = database.taskDao;

  var qa = QueryAdapter(database.database);
  var list = await qa.queryList(
      'SELECT message FROM `Task` UNION SELECT message FROM `Task`',
      mapper: (e) => Task.optional(message: e['message'] as String?));
  
  runApp(FloorApp(dao));
}

@dkaera
Copy link
Collaborator

dkaera commented Sep 21, 2023

@mthongvanh
thank you for details
yes, I can see the problem, but we need to verify if we're breaking anything with this change.
Meanwhile, Floor now supports Dart types, so the following approach can be used to retrieve the list of messages in the DAO.

@Query('SELECT message FROM Task UNION SELECT message FROM Task')
Future<List<String>> queryMessages();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants