DQL (Doctrine Query Language) - Operators - Logical operators.php 2.72 KB
Newer Older
hansbrix's avatar
hansbrix committed
1

2
* 
hansbrix's avatar
hansbrix committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42


NOT, !
          



            Logical NOT. Evaluates to 1 if the
            operand is 0, to 0 if
            the operand is non-zero, and NOT NULL
            returns NULL.
          
<b class='title'>DQL condition :** NOT 10

        -&gt; 0

<b class='title'>DQL condition :** NOT 0

        -&gt; 1

<b class='title'>DQL condition :** NOT NULL

        -&gt; NULL

<b class='title'>DQL condition :** ! (1+1)

        -&gt; 0

<b class='title'>DQL condition :** ! 1+1

        -&gt; 1

</pre>



            The last example produces 1 because the
            expression evaluates the same way as
            (!1)+1.
          
43 44

* 
hansbrix's avatar
hansbrix committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83


<a name="function_and"></a>
            <a class="indexterm" name="id2965271"></a>

            <a class="indexterm" name="id2965283"></a>

            AND
          



            Logical AND. Evaluates to 1 if all
            operands are non-zero and not NULL, to
            0 if one or more operands are
            0, otherwise NULL is
            returned.
          
<b class='title'>DQL condition :** 1 AND 1

        -&gt; 1

<b class='title'>DQL condition :** 1 AND 0

        -&gt; 0

<b class='title'>DQL condition :** 1 AND NULL

        -&gt; NULL

<b class='title'>DQL condition :** 0 AND NULL

        -&gt; 0

<b class='title'>DQL condition :** NULL AND 0

        -&gt; 0

</pre>
84 85

* 
hansbrix's avatar
hansbrix committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123


            OR
          



            Logical OR. When both operands are
            non-NULL, the result is
            1 if any operand is non-zero, and
            0 otherwise. With a
            NULL operand, the result is
            1 if the other operand is non-zero, and
            NULL otherwise. If both operands are
            NULL, the result is
            NULL.
          
<b class='title'>DQL condition :** 1 OR 1

        -&gt; 1

<b class='title'>DQL condition :** 1 OR 0

        -&gt; 1

<b class='title'>DQL condition :** 0 OR 0

        -&gt; 0

<b class='title'>DQL condition :** 0 OR NULL

        -&gt; NULL

<b class='title'>DQL condition :** 1 OR NULL

        -&gt; 1

</pre>
124 125

* 
hansbrix's avatar
hansbrix committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164


<a name="function_xor"></a>
            <a class="indexterm" name="id2965520"></a>

            XOR
          



            Logical XOR. Returns NULL if either
            operand is NULL. For
            non-NULL operands, evaluates to
            1 if an odd number of operands is
            non-zero, otherwise 0 is returned.
          
<b class='title'>DQL condition :** 1 XOR 1

        -&gt; 0

<b class='title'>DQL condition :** 1 XOR 0

        -&gt; 1

<b class='title'>DQL condition :** 1 XOR NULL

        -&gt; NULL

<b class='title'>DQL condition :** 1 XOR 1 XOR 1

        -&gt; 1

</pre>



            a XOR b is mathematically equal to
            (a AND (NOT b)) OR ((NOT a) and b).
          
165

hansbrix's avatar
hansbrix committed
166

167