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
[1.0.0] Exception on 'SELECT *, MAX(...) FROM ...' query #506
Comments
I modified the example to make it even easier. |
@vitusortner |
I started investigating this issue. Does it only happen when the database is empty? |
Yes. |
I modified the example. The database is not empty: test('Get max', () async {
await taskDao.insertTask(Task(null, 'test'));
print(await taskDao.getMax());
}); Output:
The database is empty: test('Get max', () async {
print(await taskDao.getMax());
}); Output:
|
@vitusortner |
@vitusortner |
I looked at it briefly and I'm not sure what you're expecting the query to return, purely from an sql viewpoint. Afaik, on an empty database, this query will normally return no rows, but due to the max() function will return a single (aggregated) row, where all other columns are set to null. If the returned type (in this case Foo) can't set its values to null, thats when you get the error. As this is specified behaviour by SQL itself, I don't see the bug here. |
@mqus |
I don't think this would work either way because the ´MAX(id)´ will not get mapped either way(as you can see in the generated code). Where should it even be mapped to? Maybe you could explain your situation(what do you have and what do you want to achieve) from a higher level and we could start from there. I want to add that we sadly do not yet support arbitrary return values for queries, so returning the maximum might require workarounds. |
@mqus |
What you are trying to do should be easy with floor and needs no workarounds. The query you could try is (You'll have to replace (Updated: I have tried this in sqlite and it works as expected: no output in an empty table and only the rows with the maximum prio if entries are there). |
Yes, it works. |
Alternate query, that works: SELECT *, MAX(id) FROM Foo GROUP BY id |
I don't think this query does what you think it does. It is semantically completely different. |
Issue seems to be solved, so I'm closing this. Reopen if you disagree :) |
It's easier to understand this from an example. I tried to make a simplified version of what is used in my project. Let's say we have the following null-safety code:
database.g.dart
will generate code like this for thegetMax()
method:But there will be an exception when calling the method if the DB is empty.
SELECT *, MAX(id) FROM Foo
query is an important condition for reproducing the error. If you write justSELECT * FROM Foo
, there will be no error.The text was updated successfully, but these errors were encountered: