OpenWrite
Open a read/write cursor named P1 on the table or index whose root page is P2 (or whose root page is held in register P2 if the OPFLAG_P2ISREG bit is set in P5 - see below).
An example
43 of the 178 statements we compiled against the sample database use OpenWrite. This is the one with the shortest program; the rows that use OpenWrite are highlighted.
DELETE FROM genres WHERE name < ?
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 12 | 0 | 0 | |
| 1 | Noop | 2 | 1 | 0 | 0 | |
| 2 | OpenWrite | 1 | 9 | 0 | k(1,) | 0 |
| 3 | Rewind | 1 | 11 | 2 | 0 | 0 |
| 4 | Variable | 1 | 2 | 0 | 0 | |
| 5 | IsNull | 2 | 11 | 0 | 0 | |
| 6 | Affinity | 2 | 1 | 0 | B | 0 |
| 7 | IdxGE | 1 | 11 | 2 | 1 | 0 |
| 8 | Column | 1 | 0 | 1 | 0 | |
| 9 | Delete | 1 | 1 | 0 | genres | 2 |
| 10 | Next | 1 | 7 | 0 | 0 | |
| 11 | Halt | 0 | 0 | 0 | 0 | |
| 12 | Transaction | 0 | 1 | 1 | 0 | 1 |
| 13 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Affinity, Column, Delete, Goto, Halt, IdxGE, Init, IsNull, Next, Noop, Rewind, Transaction, Variable.
What the SQLite documentation says
Open a read/write cursor named P1 on the table or index whose root page is P2 (or whose root page is held in register P2 if the OPFLAG_P2ISREG bit is set in P5 - see below).
The P4 value may be either an integer (P4_INT32) or a pointer to a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo object, then table being opened must be an index b-tree where the KeyInfo object defines the content and collating sequence of that index b-tree. Otherwise, if P4 is an integer value, then the table being opened must be a table b-tree with a number of columns no less than the value of P4.
Allowed P5 bits:
- 0x02 OPFLAG_SEEKEQ: This cursor will only be used for equality lookups (implemented as a pair of opcodes SeekGE/IdxGT of SeekLE/IdxLT)
- 0x08 OPFLAG_FORDELETE: This cursor is used only to seek and subsequently delete entries in an index btree. This is a hint to the storage engine that the storage engine is allowed to ignore. The hint is not used by the official SQLite b*tree storage engine, but is used by COMDB2.
- 0x10 OPFLAG_P2ISREG: Use the content of register P2 as the root page, not the value of P2 itself.
This instruction works like OpenRead except that it opens the cursor in read/write mode.
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.