SQLite source code learning (36) Btree miscellaneous

1. Why doesn't the original overwrite when writing the first 100 bytes of the database in the newDatabase function?

The key code is as follows:

  if( pBt->nPage>0 ){
    return SQLITE_OK;
  }

Only write when the database is empty, return directly when it is not empty, and will not execute further.

2. How to print the following line in sqlite3VdbePrintOp function

30 TableLock 0 1 1 sqlite_master 00 iDb=0 root=1 write=1

First define the character array

    /* 161 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
    # define OpHelp(X) "\0" X

sqlite3OpcodeName(pOp->opcode) gets the TableLock string, displayComment parses the comment, and replaces P1, P2, P3 in the comment with the real value

3. Turn on debugging to track the execution of the virtual machine

file delete -force example1.db
sqlite3 db example1.db
db eval {PRAGMA vdbe_trace = 1}
db eval {CREATE TABLE t1(a TEXT, b INTEGER)}

The execution results are as follows

OPEN 537402416 E:\qxqb\open_source\sqlite-src-3310100\test\example1.db
SQL: [PRAGMA vdbe_trace = 1]
VDBE Trace:
   0 Init             0    1    0               00 Start at 1
   1 Expire           0    0    0               00 
   2 Halt             0    0    0               00 
......
//此处未打印SQL语句----(1)
VDBE Trace:
   0 Init             0   13    0               00 Start at 13
  13 Transaction      0    0    0 0             00 usesStmtJournal=0
  14 TableLock        0    1    0 sqlite_master 00 iDb=0 root=1 write=0
  15 Goto             0    1    0               00 
......
SQL: [CREATE TABLE t1(a TEXT, b INTEGER)]
VDBE Trace:
   0 Init             0   29    0               00 Start at 29
  29 Transaction      0    1    0 0             01 usesStmtJournal=0
 30 TableLock        0    1    1 sqlite_master 00 iDb=0 root=1 write=1
  31 Goto             0    1    0               00 
   1 ReadCookie       0    3    2               00 
......
  27 ParseSchema      0    0    0 tbl_name='t1' AND type!='trigger' 00 
  //此处未打印SQL语句----(1)
VDBE Trace:
   0 Init             0   19    0               00 Start at 19
  19 Transaction      0    0    1 0             00 usesStmtJournal=0
  20 TableLock        0    1    0 sqlite_master 00 iDb=0 root=1 write=0
  21 String8          0    2    0 t1            00 r[2]='t1'

Every SQL code executed corresponds to a VDBE bytecode program, why are there no SQL statements in 2 places?

This is an internally executed SQL statement, not an external input. It is at (1) and is
SELECT*FROM\"main\".sqlite_master ORDER BY rowid
at (2)
SELECT*FROM\"main\".sqlite_master WHERE tbl_name='t1' AND type!='trigger' ORDER BY rowid

Explanation of SQL statement Execution sqlite3_exec includes two parts: sqlite3_prepare_v2 and sqlite3_step. The execution process at (1) is as follows
Insert picture description here
. The execution process at (2) is as follows
Insert picture description here

4. Why doesn't sqlite3VdbePrintSql print the above two SQL statements?

Insert picture description here
Insert picture description here
Insert picture description here
As shown in the above three pictures, only when db->init.busy is 0, it will print, but the Create Table statement has already set db->init.busy to 1, and all internal sql statements will not be printed.

5 The first 100 bytes of the first page of the database are used as the header, when was the 101st byte written

In fact, in the zeroPage of newDatabase, after the first 100 bytes are initialized, a new sqlite_master table is created to store all the tables.

  data[hdr] = (char)flags;
  first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
  memset(&data[hdr+1], 0, 4);
  data[hdr+7] = 0;
  put2byte(&data[hdr+5], pBt->usableSize);

6 How to modify make -j24 testfixture.exe error

test_quota.c test_fs.c:
#define SQLITE_OS_WIN 0
#define SQLITE_OS_UNIX 1

If the function is not defined, comment out the relevant compilation option or directly shield the error in zipfile.c in the code, compile and add -lz

SQLITE_ENABLE_DESERIALIZE are all commented out, regardless of the code or Makefile

Probably the modification method is as above, there may be some differences on different machines, but the ideas are the same, and if there is an error like the following

'_P_WAIT' undeclared (first use in this function); did you mean '__VALIST'?

   rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);

Change build_libtool_libs=yes in the libtool file in the bld folder to build_libtool_libs=no

Guess you like

Origin blog.csdn.net/pfysw/article/details/107735158