PureFunc
Invoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run) with arguments taken from register P2 and successors.
An example
8 of the 178 statements we compiled against the sample database use PureFunc. This is the one with the shortest program; the rows that use PureFunc are highlighted.
INSERT INTO artists (name) VALUES ('Lower case')| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 21 | 0 | 0 | |
| 1 | OpenWrite | 0 | 2 | 0 | 3 | 0 |
| 2 | OpenWrite | 1 | 7 | 0 | k(2,,) | 0 |
| 3 | OpenWrite | 2 | 6 | 0 | k(2,,) | 0 |
| 4 | SoftNull | 2 | 0 | 0 | 0 | |
| 5 | String8 | 0 | 3 | 0 | Lower case | 0 |
| 6 | NewRowid | 0 | 1 | 0 | 0 | |
| 7 | HaltIfNull | 1299 | 2 | 3 | artists.name | 1 |
| 8 | Affinity | 2 | 3 | 0 | DBB | 0 |
| 9 | SCopy | 3 | 12 | 0 | 0 | |
| 10 | PureFunc | 0 | 12 | 6 | lower(1) | 32 |
| 11 | IntCopy | 1 | 7 | 0 | 0 | |
| 12 | MakeRecord | 6 | 2 | 5 | 0 | |
| 13 | SCopy | 3 | 9 | 0 | 0 | |
| 14 | IntCopy | 1 | 10 | 0 | 0 | |
| 15 | MakeRecord | 9 | 2 | 8 | 0 | |
| 16 | MakeRecord | 2 | 3 | 11 | 0 | |
| 17 | IdxInsert | 1 | 5 | 6 | 2 | 16 |
| 18 | IdxInsert | 2 | 8 | 9 | 2 | 16 |
| 19 | Insert | 0 | 11 | 1 | artists | 57 |
| 20 | Halt | 0 | 0 | 0 | 0 | |
| 21 | Transaction | 0 | 1 | 1 | 0 | 1 |
| 22 | Null | 0 | 4 | 0 | 0 | |
| 23 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Affinity, Goto, Halt, HaltIfNull, IdxInsert, Init, Insert, IntCopy, MakeRecord, NewRowid, Null, OpenWrite, SCopy, SoftNull, String8, Transaction.
What the SQLite documentation says
Invoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run) with arguments taken from register P2 and successors. The number of arguments is in the sqlite3_context object that P4 points to. The result of the function is stored in register P3. Register P3 must not be one of the function inputs.
P1 is a 32-bit bitmask indicating whether or not each argument to the function was determined to be constant at compile time. If the first argument was constant then bit 0 of P1 is set. This is used to determine whether meta data associated with a user function argument using the sqlite3_set_auxdata() API may be safely retained until the next invocation of this opcode.
This opcode works exactly like Function. The only difference is in its name. This opcode is used in places where the function must be purely non-deterministic. Some built-in date/time functions can be either deterministic of non-deterministic, depending on their arguments. When those function are used in a non-deterministic way, they will check to see if they were called using PureFunc instead of Function, and if they were, they throw an error.
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.
← Program · ReadCookie →