-
-
Notifications
You must be signed in to change notification settings - Fork 800
Description
Question
How can I combined two filters, one being a collated one? Or combine two collated ones?
Description
I have a query which contains two filters. The filter searches based off of a TYPE column, and a NAME column. In my database, many of the characters in NAME have polish characters, therefore I have written a custom collation. I am trying to filter based off of TYPE, and a collated NAME (with my custom collation)
I tried taking my existing query and adding .collate to the nameFilter:
let rawTypes = types.map { $0.rawValue.uppercased() }
let cityFilter = rawTypes.contains(Column(Location.Column.type.rawValue))
let nameFilter = Column(Location.Column.name.rawValue).like("%\(searchText)%").collating(AccentInsensitiveCollation)
let request = Location.filter(cityFilter && nameFilter)
return try request.fetchAll(db)When I did this, I got the following error:
Binary operator '&&' cannot be applied to operands of type 'SQLExpression' and 'SQLCollatedExpression'
When I saw this, I was like "alright, no big deal, lets make the SQLExpression (the none-collated one) into a SQLCollatedExpression, surely I can compare those?
So I changed:
let cityFilter = rawTypes.contains(Column(Location.Column.type.rawValue))To:
let cityFilter = rawTypes.contains(Column(Location.Column.type.rawValue)).collating(.nocase)And then I got:
Binary operator '&&' cannot be applied to two 'SQLCollatedExpression' operands
Disclamer
This could totally be an SQLite thing I don't understand (not being able to compare two collated expressions), I have done research into this but wanted to post here knowing some experts could help 😄
Environment
**GRDB flavor(s): GRDB
**GRDB version: 5.0.4
**Installation method: SPM
**Xcode version: 13.0
**Swift version: Swift 5.0
**Platform(s) running GRDB: iOS
**macOS version running Xcode: 12.0.1 (21A559)