Forbid distinct groupConcat with separator

This commit is contained in:
Simon Binder 2022-05-08 08:41:35 +02:00
parent 946b6807d4
commit 78470b4280
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 20 additions and 15 deletions

View File

@ -51,6 +51,12 @@ extension BaseAggregate<DT> on Expression<DT> {
}) {
const sqliteDefaultSeparator = ',';
// Distinct aggregates can only have one argument
if (distinct && separator != sqliteDefaultSeparator) {
throw ArgumentError(
'Cannot use groupConcat with distinct: true and a custom serparator');
}
return _AggregateExpression(
'GROUP_CONCAT',
[

View File

@ -83,21 +83,6 @@ void main() {
expect(foo.groupConcat(distinct: true),
generates('GROUP_CONCAT(DISTINCT foo)', isEmpty));
expect(foo.groupConcat(distinct: true, separator: ' and '),
generates('GROUP_CONCAT(DISTINCT foo, ?)', [' and ']));
expect(
foo.groupConcat(
distinct: true,
separator: ' and ',
filter: foo.isSmallerThan(const Variable(3)),
),
generates(
'GROUP_CONCAT(DISTINCT foo, ?) FILTER (WHERE foo < ?)',
[' and ', 3],
),
);
expect(
foo.groupConcat(
distinct: true,
@ -109,5 +94,19 @@ void main() {
),
);
});
test('does not allow distinct with a custom separator', () {
expect(() => foo.groupConcat(distinct: true, separator: ' and '),
throwsArgumentError);
expect(
() => foo.groupConcat(
distinct: true,
separator: ' and ',
filter: foo.isSmallerThan(const Variable(3)),
),
throwsArgumentError,
);
});
});
}