File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -1169,16 +1169,25 @@ public struct Row {
11691169 }
11701170
11711171 guard let idx = columnNames [ column. template] else {
1172- let similar = Array ( columnNames. keys) . filter { $0. hasSuffix ( " . \( column. template) " ) }
1172+ func similar( _ name: String ) -> Bool {
1173+ return name. hasSuffix ( " . \( column. template) " )
1174+ }
11731175
1174- switch similar. count {
1175- case 0 :
1176+ guard let firstIndex = columnNames. firstIndex ( where: { similar ( $0. key) } ) else {
11761177 throw QueryError . noSuchColumn ( name: column. template, columns: columnNames. keys. sorted ( ) )
1177- case 1 :
1178- return valueAtIndex ( columnNames [ similar [ 0 ] ] !)
1179- default :
1180- throw QueryError . ambiguousColumn ( name: column. template, similar: similar)
11811178 }
1179+
1180+ let secondIndex = columnNames
1181+ . suffix ( from: columnNames. index ( after: firstIndex) )
1182+ . firstIndex ( where: { similar ( $0. key) } )
1183+
1184+ guard secondIndex == nil else {
1185+ throw QueryError . ambiguousColumn (
1186+ name: column. template,
1187+ similar: columnNames. keys. filter ( similar) . sorted ( )
1188+ )
1189+ }
1190+ return valueAtIndex ( columnNames [ firstIndex] . value)
11821191 }
11831192
11841193 return valueAtIndex ( idx)
You can’t perform that action at this time.
0 commit comments