mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Clarify code that aims at fixing #1357
This commit is contained in:
1 parent
61c7fdf81b
commit
a4132a00db
2 files changed
+14
-4
No files matched your search
@@ -636,7 +636,7 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
// <https://github.com/groue/GRDB.swift/issues/1357>
|
||||
guard selection.allSatisfy(\.isTriviallyCountable) else {
|
||||
if selection.contains(where: \.requiresTrivialCount) {
|
||||
return try fetchTrivialCount(db)
|
||||
}
|
||||
|
||||
|
||||
@@ -245,15 +245,25 @@ extension SQLSelection {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether this selection MUST be counted with a "trivial"
|
||||
/// count: `SELECT COUNT(*) FROM (SELECT ...)`.
|
||||
///
|
||||
/// Supports SQLRelation.fetchCount.
|
||||
///
|
||||
/// See <https://github.com/groue/GRDB.swift/issues/1357>
|
||||
var isTriviallyCountable: Bool {
|
||||
var requiresTrivialCount: Bool {
|
||||
switch impl {
|
||||
case .aliasedExpression, .literal:
|
||||
return false
|
||||
case .allColumns, .qualifiedAllColumns, .expression:
|
||||
// Trivial count is required.
|
||||
//
|
||||
// For example, the WHERE clause here requires the aliased
|
||||
// column to be preserved in the counting request:
|
||||
// SELECT *, column AS alt FROM player WHERE alt
|
||||
return true
|
||||
case .allColumns, .qualifiedAllColumns:
|
||||
return false
|
||||
case .expression:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user