SQLite VDBE opcode

Insert

Write an entry into the table of cursor P1.

An example

38 of the 178 statements we compiled against the sample database use Insert. This is the one with the shortest program; the rows that use Insert are highlighted.

CREATE TRIGGER t1 AFTER INSERT ON artists BEGIN SELECT 1; END
addropcodep1p2p3p4p5
0Init01300
1OpenWrite01050
2String8020trigger0
3String8030t10
4String8040artists0
5Integer0500
6String8060CREATE TRIGGER t1 AFTER INSERT ON artists BEGIN SELECT 1; END0
7NewRowid0100
8MakeRecord257BBBDB0
9Insert07124
10SetCookie0120
11ParseSchema000type='trigger' AND name='t1'0
12Halt0000
13Transaction01101
14Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Goto, Halt, Init, Integer, MakeRecord, NewRowid, OpenWrite, ParseSchema, SetCookie, String8, Transaction.

What the SQLite documentation says

Write an entry into the table of cursor P1. A new entry is created if it doesn't already exist or the data for an existing entry is overwritten. The data is the value MEM_Blob stored in register number P2. The key is stored in register P3. The key must be a MEM_Int.

If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set, then rowid is stored for subsequent return by the sqlite3_last_insert_rowid() function (otherwise it is unmodified).

If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might run faster by avoiding an unnecessary seek on cursor P1. However, the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior seeks on the cursor or if the most recent seek used a key equal to P3.

If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an UPDATE operation. Otherwise (if the flag is clear) then this opcode is part of an INSERT operation. The difference is only important to the update hook.

Parameter P4 may point to a Table structure, or may be NULL. If it is not NULL, then the update-hook (sqlite3.xUpdateCallback) is invoked following a successful insert.

(WARNING/TODO: If P1 is a pseudo-cursor and P2 is dynamically allocated, then ownership of P2 is transferred to the pseudo-cursor and register P2 becomes ephemeral. If the cursor is changed, the value of register P2 will then change. Make sure this does not cause any problems.)

This instruction only works on tables. The equivalent instruction for indices is IdxInsert.

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.

← InitCoroutine · Int64 →