Subject Re[8]: [IBO] SQLWhereItems
Author Ramil
Hello Alan,

Let's consider funny example:
2 + 2 * 2 = 6
(2 + 2) * 2 = 8

('+' is logical OR, '*' is logical AND)
If you want correct result - take care of brackets!

2 * 2 * 2 * TERM_1 * TERM_2 *...*TERM_N
is logical structure of SQLWhereItems.
'*' is implicit.
It's simple. It as should be. No matter where to put brackets.
You just do SQLWhereItems.Add(TERM_i).

When there is parsing SQLWhereItems the terms equal '(' force to skip
implicit AND until term=')'. Only a single symbol '(' or ')'.


As I say in previous post:

Your task of the PROGRAMMER - to build CORRECT LOGIC EXPRESSION
and to not miss necessary brackets.
It's possible for any unknown number of items.
And it should do the application logic, not IBO.
If you are confused with features of SQLWhereItems use directly
SQLWhere or entirely processing SQL as answered others.
But I do not see difficulties especially for the example.

procedure TForm1.IB_Query1PrepareSQL(Sender: TIB_Statement);
var
TERM: String;
begin
TERM := _ANY_HUGE_bracketed_CORRECT_logical_expression_
// to make correct TERM is your problem
IB_Query1.SQLWhereItems.Add( TERM );
end;


Glad to help.
Ramil.

>
>
>
>
>
>> Hello Alan,
>>
>> There are no problems again:
>>
>> procedure TForm1.IB_Query1PrepareSQL(Sender: TIB_Statement);
>> begin
>> IB_Query1.SQLWhereItems.Add( 'DRPWFACT>0');
>> IB_Query1.SQLWhereItems.Add( '(' );
>> IB_Query1.SQLWhereItems.Add( '(' );
>> IB_Query1.SQLWhereItems.Add( 'WCALC >0' );
>> IB_Query1.SQLWhereItems.Add( 'AND' );
>> IB_Query1.SQLWhereItems.Add( 'DRPLITTER = 4.8' );
>> IB_Query1.SQLWhereItems.Add( ')' );
>> IB_Query1.SQLWhereItems.Add( 'OR' );
>> IB_Query1.SQLWhereItems.Add( '(' );
>> IB_Query1.SQLWhereItems.Add( 'WCOND >0' );
>> IB_Query1.SQLWhereItems.Add( 'AND' );
>> IB_Query1.SQLWhereItems.Add( 'DRPHUMIDITY = 11.6' );
>> IB_Query1.SQLWhereItems.Add( ')' );
>> IB_Query1.SQLWhereItems.Add( ')' );
>> end;
>>
>> Works fine...
>> The same result gives:
>
> sorry - I'm wasting your time... that's note what I meant.
> Let's say I have several booleans I set (toggle) from a popup menu to view
> certain things. Each setting leaves the popup menu item checked/not checked
> so now I have a set of booleans. At the end of each setting of the menu, I
> call invalidate and refresh so as to invoke prepare.
> In the PrepareSQL I need to add items dependent upon the boolean values. In
> this case I never end up knowing if brackets are required since I don't know
> if the next value is true or not or to be OR'd. I can't setup the brackets
> this way..
> But never mind I've changed the logic for my purposes. I was only asking
> because the help file inferred, if you like, that by sticking an OR in front
> of an item, the AND would be substituted with an OR. In your case above,
> these items are all AND'd. AND is implicit. OR needs to be explicit. I just
> wanted it to make OR implicit if I added it separately. That's not what it
> does. The brackets just protect the OR and leave it explicit.
> Another way to look at it is that you can add a number of items and never
> include AND anywhere but the AND will be included for you in the parsing. OR
> will never be included for you if you leave it out. I wanted a trigger to
> force the parsing to use OR instead of AND.
> Alan
>