IsTrue
This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and IS NOT FALSE operators.
An example
1 of the 178 statements we compiled against the sample database use IsTrue. This is the one with the shortest program; the rows that use IsTrue are highlighted.
SELECT id IS TRUE FROM tracks
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 8 | 0 | 0 | |
| 1 | OpenRead | 1 | 19 | 0 | k(2,,) | 0 |
| 2 | Rewind | 1 | 7 | 1 | 0 | 0 |
| 3 | IdxRowid | 1 | 2 | 0 | 0 | |
| 4 | IsTrue | 2 | 1 | 0 | 0 | 0 |
| 5 | ResultRow | 1 | 1 | 0 | 0 | |
| 6 | Next | 1 | 3 | 0 | 1 | |
| 7 | Halt | 0 | 0 | 0 | 0 | |
| 8 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 9 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Goto, Halt, IdxRowid, Init, Next, OpenRead, ResultRow, Rewind, Transaction.
What the SQLite documentation says
This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and IS NOT FALSE operators.
Interpret the value in register P1 as a boolean value. Store that boolean (a 0 or 1) in register P2. Or if the value in register P1 is NULL, then the P3 is stored in register P2. Invert the answer if P4 is 1.
The logic is summarized like this:
- If P3==0 and P4==0 then r[P2] := r[P1] IS TRUE
- If P3==1 and P4==1 then r[P2] := r[P1] IS FALSE
- If P3==0 and P4==1 then r[P2] := r[P1] IS NOT TRUE
- If P3==1 and P4==0 then r[P2] := r[P1] IS NOT FALSE
From sqlite.org's list of opcodes for SQLite 3.54.1, in the public domain. Opcodes are not a stable interface and change between releases.