TypeCheck
Apply affinities to the range of P2 registers beginning with P1.
An example
6 of the 178 statements we compiled against the sample database use TypeCheck. This is the one with the shortest program; the rows that use TypeCheck are highlighted.
SELECT total FROM sales
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 12 | 0 | 0 | |
| 1 | OpenRead | 0 | 17 | 0 | 4 | 0 |
| 2 | Rewind | 0 | 11 | 0 | 0 | |
| 3 | IfNullRow | 0 | 9 | 1 | 0 | |
| 4 | Column | 0 | 2 | 2 | 0 | |
| 5 | Column | 0 | 3 | 3 | 0 | |
| 6 | RealAffinity | 3 | 0 | 0 | 0 | |
| 7 | Multiply | 3 | 2 | 1 | 0 | |
| 8 | TypeCheck | 1 | 1 | 6 | sales | 0 |
| 9 | ResultRow | 1 | 1 | 0 | 0 | |
| 10 | Next | 0 | 3 | 0 | 1 | |
| 11 | Halt | 0 | 0 | 0 | 0 | |
| 12 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 13 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Column, Goto, Halt, IfNullRow, Init, Multiply, Next, OpenRead, RealAffinity, ResultRow, Rewind, Transaction.
What the SQLite documentation says
Apply affinities to the range of P2 registers beginning with P1. Take the affinities from the Table object in P4. If any value cannot be coerced into the correct type, then raise an error.
If P3==0, then omit checking of VIRTUAL columns.
If P3==1, then omit checking of all generated column, both VIRTUAL and STORED.
If P3>=2, then only check column number P3-2 in the table (which will be a VIRTUAL column) against the value in reg[P1]. In this case, P2 will be 1.
This opcode is similar to Affinity except that this opcode forces the register type to the Table column type. This is used to implement "strict affinity".
GENERATED ALWAYS AS ... STATIC columns are only checked if P3 is zero. When P3 is non-zero, no type checking occurs for static generated columns. Virtual columns are computed at query time and so they are never checked.
Preconditions:
- P2 should be the number of non-virtual columns in the table of P4 unless P3>1, in which case P2 will be 1.
- Table P4 is a STRICT table.
If any precondition is false, an assertion fault occurs.
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.
← Transaction · Vacuum →