Logical operators are used on boolean expressions (true or false). The labels 'true' and 'false' are interpreted as integer-type constants (1 and 0, respectively).

1 Introduction

Relational operators are often used with conditional operators to formulate more complex expressions.

Conditional Operators
Operator Java Equivalent Class Description Applicable to
<and> & BINARY AND number
<or> | BINARY O number
<not> ! UNARY No number
<between> b <= a >= c TERNARY Between number

The result of conditional operations is always true or false. Below is a decision table for the application of conditional operators. The order in which cases are listed is the one followed by the evaluator. Relationships not included in the table are not supported.

Application and Results of Conditional Binary Operators
Type 1 Type 2 Result Operator Notes
null any false and The operation AND returns a result of 'false' if one of the operators is null.
null any true | false or The operation OR returns a result of 'true' if the non-null operator is true. Otherwise, it is false.
boolean any true | false and, or The result of the comparison between the first boolean and the toBoolean (object).
smallint smallint true | false and, or The result of the comparison between two numbers (smallint).
number number true | false and, or The result of the comparison between two numbers.
number number true | false and, or The result of the comparison between two numbers.

A unary conditional operator is also available, <not>.

Note

The <and> and <or> operators, for bitwise operations, are incorporated into the <math> package. Therefore, in XSQL scripting language, <and> and <or> only apply conditionally. In Java, on the other hand, both operators act conditionally if both are boolean and bitwise if they are numeric.

Application and Results of Unary Conditional Operators
Type 1 Result Operator Notes
any true | false not The NOT operator will return a result that reverses the truth or falsity of the operand.

2 <and> Function

This function allows you to perform AND operations. The result of an AND logical operation is true only if all operands are true.

There are two possible ways of writing:

Copy
<expr><value_1 /><and /><value_2 /></expr>
Copy
<expr><and><value_1 /><value_2 /></and></expr>

<and>
    <value_1> !
    <value_2> !
</and>
Example
Copy
<xsql-script name='sample'>
    <body>
        <!-- Sample 0 (false) -->
        <println>
            <expr>
                <true /><and /><false />
            </expr>
        </println>

        <!-- Sample1 (true) -->
        <println>
            <expr>
                <true /><and /><true />
            </expr>
        </println>

        <!-- Sample 0 (false) -->
        <set name='a'>5</set>
        <println>
            <expr>
                <lt><a/>1</lt>
                <and />
                <lt><a/>4</lt>
            </expr>
        </println>

        <!-- Sample 1 (true). The 'and' clause goes between the comparables. -->
        <set name='a'>0</set>
        <println>
            <expr>
                <lt><a/>1</lt>
                <and />
                <lt><a/>4</lt>
            </expr>
        </println>

        <!-- Sample 0 (false). The comparables are passed as arguments. -->
        <set name='a'>3</set>
        <println>
            <expr>
                <and>
                    <lt><a/>1</lt>
                    <lt><a/>4</lt>
                </and>
            </expr>
        </println>
    </body>
</xsql-script>

3 <or> function

This function allows the user to perform OR operations. The result of an OR logical operation is true if at least one of the operands is true.

There are two possible ways of writing:

Copy
<expr><value_1 /><or /><value_2 /></expr>
Copy
<expr><or><value_1 /><value_2 /></or></expr>

<or>
    <value_1> !
    <value_2> !
</or>
Example
Copy
<xsql-script name='sample'>
    <body>
        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <true /><or /><false />
            </expr>
        </println>

        <!-- Sample 1 (true) -->
        <println>
            <expr>
                <true /><or /><true />
            </expr>
        </println>

        <!-- Sample 0 (false) -->
        <set name='a'>5</set>
        <println>
            <expr>
                <lt><a/>1</lt>
                <or />
                <lt><a/>4</lt>
            </expr>
        </println>

        <!-- Sample 1 (true). The 'or' clause goes between the comparables. -->
        <set name='a'>3</set>
        <println>
            <expr>
                <lt><a/>1</lt>
                <or />
                <lt><a/>4</lt>
            </expr>
        </println>

        <!-- Sample 1 (true). The comparables are passed as arguments. -->
        <set name='a'>3</set>
        <println>
            <expr>
                <or>
                    <lt><a/>1</lt>
                    <lt><a/>4</lt>
                </or>
            </expr>
        </println>
    </body>
</xsql-script>

4 <not> function

With this function, the user can carry out logical negations.

<not>
    <value> !
</not>
Example
Copy
<xsql-script name='sample'>
    <body>
        <!-- not false: 1 (true) -->
        <println>
            not false: <not><false /></not>
        </println>

        <!-- not hola: 0 (false) -->
        <println>
            not hola: <not><string>hola</string></not>
        </println>

        <!-- not '0.0': 1 (true) -->
        <println>
            not '0.0': <not><string>0.0</string></not>
        </println>

        <!-- not 4: 0 (false) -->
        <println>not 4: <not>4</not></println>
    </body>
</xsql-script>

5 <between> function

This function is only applicable to numbers. Determines if a numerical value is between two other numerical values.

<between>
    <value> !
    <minimum> !
    <maximum> !
</between>
Example
Copy
<xsql-script name='not_sample1'>
    <body>
        <!-- 3.4 between 8.9 and 90: false -->
        <println>3.4 between 8.9 and 90:
            <between>
                <number>3.4</number>
                <number>8.9</number>
                <number>90</number>
            </between>
        </println>

        <!-- 3.4 between 1.9 and 90: true -->
        <println>3.4 between 1.9 and 90:
            <between>
                <number>3.4</number>
                <number>1.9</number>
                <number>90</number>
            </between>
        </println>
    </body>
</xsql-script>