Hi again,
still using Glorp ;-)
Quite a while ago I found a cool way of constructing SQL queries for a QBE feature from GUI elements. The basic idea is that you have a
q := Query readOneOf: SomeClass where: [:obj| obj customerId= 4711].
And then add condistions from a list of GUI elements that lets a user construct a list of search criteria. For this I use the AND: method, like this:
(self guiFilters select: [:filter| filter hasRelevantSearchCriteria]) do: [:filter|
q AND: filter queryBlock].
This works fantastically nice for QBE dialogs where every criterion can be added as an AND condition.
I have now come to a situation where I need to add one Criterion as AND and a dynamic list of OR criteria, one or even multiple of which must be met for a row to be in the result set.
So I want something like
Select * from table
where customerid = 4711
and (
criterion1
and (criterion2
or criterion3
or criterion4
or ... )).
How can I nest these blocks using AND: and OR: when criterion1 is just the first of the blocks in a collection and the rest follows in the same collection of query blocks?
Nothing I tried yields a correct SQL statement, so I am afraid I am asking for a non-exstent feature? Extra col would be if there is a way to construct arbitrary nesting of such Query blocks....
Joachim