Open a read-only cursor for the database
table whose root page is P2 in a
database file
.
The database file is determined by an integer
from the top of the stack. 0 means the main database and 1 means the
database used for temporary tables. Give
the new cursor an identifier of P1
. The P1 values need not be
contiguous but all P1 values should be small integers. It is an error
for P1 to be negative.
If
P2==0 then take the root page number from off of the stack.
There will be a read lock on the database whenever there is an open
cursor. If the data-
base was unlocked prior to this instruction then
a read lock is acquired as part of this instruction. A read lock allows
other processes to read the database but prohibits any other process
from modifying the database. The read lock is released when all cursors
are closed. If this instruction attempts to get a read lock but fails,
the script terminates with an SQLITE_BUSY error code.
The P3 value is a pointer to a KeyInfo
structure
that defines the content and collating
sequence of indices. P3 is NULL for cursors that are not pointing to
indices.
现在来看看其余的指令,Goto指令是一条跳转指令,跳到P2处,即第12条指令。指令12是Transaction,它开始
一个新的事务;然后执行
VerifyCookie,它的主要功能VDBE程序编译后,数据库模式是否改变(即是否进行过更新操作)。这在SQLite中是一个很重要的概念,在
SQL被sqlite3_prepare()编译成VDBE代码至程序调用sqlite3_step()执行字节码的这段时间,另一个SQL命令可能会改
变数据库模式(such as ALTER TABLE, DROP TABLE, or CREATE
TABLE)。一旦发生这种情况,之前编译的statement就会变得无效,数据库模式信息记录在数据库文件的根页面中。类似,每一个
statement都有一份用来比较的在编译时刻该模式的备份,VerifyCookie的功能就是检查它们是否匹配,如果不匹配,将采取相关操作。
(1)Transaction指令自己不会获取锁( The Transaction
instruction doesn’t acquire any locks in
itself)。它的功能相当于BEGIN,而实际是由OpenRead指令获取share
lock的。当事务关闭时释放锁,这取决于Halt指令,它会进行扫尾工作。