stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.67k stars 1.56k forks source link

Building dynamic filters returning wrong conditions #948

Closed xsheru closed 3 years ago

xsheru commented 5 years ago

XCODE 10.2 SWIFT 5.1 COCOAPODS

https://stackoverflow.com/questions/31595212/sqlite-swift-create-dynamic-complex-queries I have tried to find the solution and finally I ended up here...

I am iterating an array and trying to make something like this --- (columnName == "this" || columnName == "this")

CODE:

var customPartyNamesFilter = Expression(value: true) for i in 0..<filterPartyNames.count { ----let item = filterPartyNames[i] ----if i == 0 { --------customPartyNamesFilter = (tradeSellerName == item || tradeBrokeName == item || tradeBuyerName == item) ----} else { --------customPartyNamesFilter = customPartyNamesFilter || (tradeSellerName == item || tradeBrokeName == item || tradeBuyerName == item) ----} }

Now this should return SQL like ("trade_seller_name" == "actual name 1" || "trade_broker_name" == "actual name 1" || "trade_buyer_name" == "actual name 1")

But actual output I am getting is like ((("trade_seller_name" == "actual name 1") || ("trade_broker_name" == "actual name 1")) || ("trade_buyer_name" == "actual name 1"))

how are these extra brackets are coming? if this is by design then how can I create query like I need?

nathanfallet commented 3 years ago

The way OR condition is treated has changed in 0.13.0. If you still have a problem with it, please reopen this issue.

hosy commented 2 years ago

Is there a sample code, how OR conditions can be build since 0.13.0 to get a result, like mentioned above?