Search notes:

Compile SQLite

2024-06-17 / Linux / Version 3.43.0

These are some notes about compiling SQLite 3.43.0 on Linux, taken 2024-06-17.
Clone the official Git mirror of the SQLite
cd ~
git clone https://github.com/sqlite/sqlite
cd sqlite
./configure
Calling .configure created the following files:
$ find . -type f -cmin -1
./libtool
./config.status
./Makefile
./config.log
./sqlite_cfg.h
./sqlite3.pc

sqlite_cfg.h

sqlite_cfg.h (which was produced by calling ./configure from sqlite_cfg.h.in) contains various HAVE_ (such as HAVE_INT64_T etc.) and other macros (such as #define PACKAGE_VERSION "3.47.0")
sqlite_cfg.h is included from src/sqliteInt.h which in turn is included from most (or all C source files).

src/sqliteInt.h

sqlite3.h

sqlite3.h is the public «SQLIte interface» and included from src/sqliteInt.h.

Some functions

sqlite3_open_v2 Note, If flags contains SQLITE3_CREATE it also must contain SQLITE_OPEN_READWRITE, otherwise SQLITE_MISUSE is returned.
sqlite3_initialize Allocation of memory, VFS and the mutex subsystem. Must be called explicitely prior to doing any serious work unless SQLITE_OMIT_AUTOINIT` is defined.

struct sqlite3

sqlite3_vfs *pVfs OS Interface
struct Vdbe *pVdbe List of active virtual machines
CollSeq *pDfltColl BINARY collseq for the database encoding
sqlite3_mutex *mutex Connection mutex
Db *aDb All backends (database files). aDB[0] is the main database file and aDB[1] is the database file used to hold temporary tables. Additional databases may be attached. Unlike most scheme objects, aDb[1] is not associated witha B-Tree
int nDb Number of backends currently in use
u32 mDbFlags flags recording internal state
u64 flags flags settable by pragmas. See below
i64 lastRowid ROWID of most recent insert (see above)
i64 szMmap Default mmap_size setting
u32 nSchemaLock Do not reset the schema when non-zero
unsigned int openFlags Flags passed to sqlite3_vfs.xOpen()
int errCode Most recent error code (SQLITE_*)
int errByteOffset Byte offset of error in SQL statement
int errMask & result codes with this before returning
int iSysErrno Errno value from last system error
u32 dbOptFlags Flags to enable/disable optimizations
u8 enc Text encoding
u8 autoCommit The auto-commit flag.
u8 temp_store 1: file 2: memory 0: default
u8 mallocFailed True if we have seen a malloc failure
u8 bBenignMalloc Do not require OOMs if true
u8 dfltLockMode Default locking-mode for attached dbs
signed char nextAutovac Autovac setting after VACUUM if >=0
u8 suppressErr Do not issue error messages if true
u8 vtabOnConflict Value to return for s3_vtab_on_conflict()
u8 isTransactionSavepoint True if the outermost savepoint is a TS
u8 mTrace zero or more SQLITE_TRACE flags
u8 noSharedCache True if no shared-cache backends
u8 nSqlExec Number of pending OP_SqlExec opcodes
u8 eOpenState Current condition of the connection
int nextPagesize Pagesize after VACUUM if >0
i64 nChange Value returned by sqlite3_changes()
i64 nTotalChange Value returned by sqlite3_total_changes()
int aLimit[SQLITE_N_LIMIT] Limits
int nMaxSorterMmap Maximum size of regions mapped by sorter
struct sqlite3InitInfo init Information used during initialization
int nVdbeActive Number of VDBEs currently running
int nVdbeRead Number of active VDBEs that read or write
int nVdbeWrite Number of active VDBEs that read and write
int nVdbeExec Number of nested calls to VdbeExec()
int nVDestroy Number of active OP_VDestroy operations
int nExtension Number of loaded extensions
void **aExtension Array of shared library handles
trace A union withvoid (xLegacy)(void,const char*) and int (xV2)(u32,void,void*,void*)
void *pTraceArg Argument to the trace function
void (xProfile)(void,const char*,u64) Profiling function Not SQLITE_OMIT_DEPRECATED
void *pProfileArg Argument to profile function Not SQLITE_OMIT_DEPRECATED
void *pCommitArg Argument to xCommitCallback()
int (xCommitCallback)(void) Invoked at every commit.
void *pRollbackArg Argument to xRollbackCallback()
void (xRollbackCallback)(void) Invoked at every commit.
void *pUpdateArg
void (xUpdateCallback)(void,int, const char*,const char*,sqlite_int64)
void *pAutovacPagesArg Client argument to autovac_pages
void (xAutovacDestr)(void) Destructor for pAutovacPAgesArg
unsigned int (xAutovacPages)(void,const char*,u32,u32,u32)
Parse *pParse Current parse
void *pPreUpdateArg First argument to xPreUpdateCallback SQLITE_ENABLE_PREUPDATE_HOOK
void (xPreUpdateCallback)(void,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64) Registered using sqlite3_preupdate_hook() SQLITE_ENABLE_PREUPDATE_HOOK
PreUpdate *pPreUpdate Context for active pre-update callback SQLITE_ENABLE_PREUPDATE_HOOK
int (xWalCallback)(void , sqlite3 *, const char *, int) Not SQLITE_OMIT_WAL
void *pWalArg Not SQLITE_OMIT_WAL
void(xCollNeeded)(void,sqlite3*,int eTextRep,const char*)
void(xCollNeeded16)(void,sqlite3*,int eTextRep,const void*)
void *pCollNeededArg
sqlite3_value *pErr Most recent error message
u1 A union with volatile int isInterrupted (true if sqlite3_interrupt has been called) and `double notUsed1
Lookaside lookaside Lookaside malloc configuration
sqlite3_xauth xAuth Access authorization function Not SQLITE_OMIT_AUTHORIZATION
void *pAuthArg 1st argument to the access auth function Not SQLITE_OMIT_AUTHORIZATION
int (xProgress)(void ) The progress callback not SQLITE_OMIT_PROGRESS_CALLBACK
void *pProgressArg Argument to the progress callback not SQLITE_OMIT_PROGRESS_CALLBACK
unsigned nProgressOps Number of opcodes for progress callback not SQLITE_OMIT_PROGRESS_CALLBACK
int nVTrans Allocated size of aVTrans not SQLITE_OMIT_VIRTUALTABLE
Hash aModule populated by sqlite3_create_module() not SQLITE_OMIT_VIRTUALTABLE
VtabCtx *pVtabCtx Context for active vtab connect/create not SQLITE_OMIT_VIRTUALTABLE
VTable **aVTrans Virtual tables with open transactions not SQLITE_OMIT_VIRTUALTABLE
VTable *pDisconnect Disconnect these in next sqlite3_prepare() not SQLITE_OMIT_VIRTUALTABLE
Hash aFunc Hash table of connection functions
Hash aCollSeq All collating sequences
BusyHandler busyHandler The busy callback for the database handle. Each pager opened via the sqlite** handle is passed a pointer to sqlite.busyHandler. The busy-handler callback is currently invoked only from within pager.c
Db aDbStatic[2] Static space for the 2 default backends
Savepoint *pSavepoint List of active savepoints
int nAnalysisLimit Number of index rows to ANALYZE
int busyTimeout Busy handler timeout, in msec
int nSavepoint Number of non-transaction savepoints
int nStatement Number of nested statement-transactions
i64 nDeferredCons Net deferred constraints this transaction.
i64 nDeferredImmCons Net deferred immediate constraints
int *pnBytesFreed If not NULL, increment this in DbFree()
DbClientData *pDbData sqlite3_set_clientdata() content
sqlite3 *pBlockingConnection Connection that caused SQLITE_LOCKED SQLITE_ENABLE_UNLOCK_NOTIFY
sqlite3 *pUnlockConnection Connection to watch for unlock SQLITE_ENABLE_UNLOCK_NOTIFY
void *pUnlockArg Argument to xUnlockNotify SQLITE_ENABLE_UNLOCK_NOTIFY
void (*xUnlockNotify)(void **, int) Unlock notify callback SQLITE_ENABLE_UNLOCK_NOTIFY
sqlite3 *pNextBlocked Next in list of all blocked connections SQLITE_ENABLE_UNLOCK_NOTIFY
sqlite3_userauth auth User authentication information. SQLITE_USER_AUTHENTICATION

SQLITE_… macros

Some (imho) interesting SQLITE_ macros include:
PREFERRED_SCHEMA_TABLE With the value "sqlite_schema"
PREFERRED_TEMP_SCHEMA_TABLE With the value "sqlite_temp_schema"
SQLITE_CUSTOM_INCLUDE Optionally include a user-defined header to define compilation options before they take effect. (This custom include file would be included in src/sqliteInt.h if specified).
SQLITE_DEBUG Is the opposite of NDEBUG. It should always be true that defined(NDEBUG)==!defined(SQLITE_DEBUG). SQLITE_DEBUG implies SQLITE_ENABLE_EXPLAIN_COMMENTS
SQLITE_DEFAULT_FILE_FORMAT See also SQLITE_MAX_FILE_FORMAT
SQLITE_DEFAULT_PCACHE_INITSZ The default initial allocation for the pagecache when using separate pagecaches for each database connection. A positive number is the number of pages. A negative number N translations means that a buffer of -1024*N bytes is allocated and used for as many pages as it will hold.
SQLITE_DEFAULT_RECURSIVE_TRIGGERS Value can be changed at runtime with a pragma.
SQLITE_DEFAULT_SORTERREF_SIZE
SQLITE_DEFAULT_WORKER_THREADS See also SQLITE_MAX_WORKER_THREADS
SQLITE_ENABLE_BATCH_ATOMIC_WRITE Cannot be used together with SQLITE_MMAP_READWRITE.
SQLITE_ENABLE_EXPLAIN_COMMENTS Incompatible with SQLITE_OMIT_EXPLAIN; enabled if SQLITE_DEBUG is defined.
SQLITE_ENABLE_SQLLOG
SQLITE_FORCE_OS_TRACE
SQLITE_MAX_FILE_FORMAT The file format number is an integer that is incremented whenever the VDBE-level file format changes. See also SQLITE_DEFAULT_FILE_FORMAT
SQLITE_MAX_WORKER_THREADS See also SQLITE_DEFAULT_WORKER_THREADS
SQLITE_MMAP_READWRITE Cannot be used together with SQLITE_ENABLE_BATCH_ATOMIC_WRITE.
SQLITE_MUTEX_STATIC_TEMPDIR defined to the value of SQLITE_MUTEX_STATIC_VFS1
SQLITE_NEED_ERR_NAME Needed for sqlite3ErrName()
SQLITE_OMIT_AUTHORIZATION Compare with SQLITE_USER_AUTHENTICATION
SQLITE_OMIT_AUTOINIT Omit automatic alls to sqlite3_initialize() (for example from from sqlite3_open()). This option might become the default behavior in a future release.
SQLITE_OMIT_EXPLAIN Incompatible with SQLITE_ENABLE_EXPLAIN_COMMENTS
SQLITE_OMIT_FLOATING_POINT
SQLITE_OMIT_TEMPDB
SQLITE_OMIT_VIRTUALTABLE Implies SQLITE_OMIT_ALTERTABLE
SQLITE_OMIT_WAL
SQLITE_TEMP_STORE If set to 3, temporary files are never used.
SQLITE_THREADSAFE
SQLITE_USER_AUTHENTICATION Compare with SQLITE_OMIT_AUTHORIZATION

Typedefs

sqlite_int64, sqlite_uint64, i64, u64 etc.
tRowcnt The datatype used to store estimates of the number of rows in a table or index.
VList Records a mapping between parameters/variables/wildcards in the SQL statement (such as $abc, @pqr or :xyz) and the integer variable number associated with that parameter. See the format description on the sqlite3VListAdd() routine for more information. ? A VList is really just an array of integers ?

Other observations

AggInfo
AuthContext
AutoincInfo
Bitvec
BtCursor A pointer to a particular entry within a particular B-Tree within a database file. Declared in src/btreeInt.h
Btree A Btree instance is used for every open database file an SQLite has opened. When the database file is shared, there are multiple Btree objects bunt only one BtShared object. Unclear to me is if Btree is used in other scenarios as well. Defined in src/btreeInt.h.
BtShared An instance of this object represents a single database file. If the database file is shared bu multiple connections, there is only one BtShared object but multiple Btree objects.
CellInfo Information about a cell, filled by parseCellPtr(). See also the structs Table and Column
CollSeq A collating sequence, basically a name and comparison function which defines the sequence's order.
Column A column's name, datatype and collating sequence. See also the structs Table and CellInfo.
Cte A common table expression. See also the With struct
CteUse
Db The «backend»? used to access database files. See the aDb array in the sqlite3 struct.
DbClientData Client data associated with sqlite3_set_clientdata() and sqlite3_get_clientdata().
DbFixer
Schema
Expr
ExprList
FKey An object corresponds to a foreign key.
FpDecode
FuncDestructor
FuncDef Objects correspond to SQL functions. See also the FuncDestructor object.
FuncDefHash
FuncDestructor
IdList
Index
IndexedExpr
IndexSample
KeyClass
KeyInfo An instance of this object is passed as the first argument to sqlite3VdbeKeyCompare. It controls the comparison of two index keys.
Lookaside
LookasideSlot
MemPage Each instance of this struct corresponds to a database page that is loaded into memory. Access to its data is secured by the mutex MemPage.pBt->mutex. This struct declared in btreeInt.h.
Module Module == virtual table definition?
NameContext
OnOrUsing
Parse An SQL parser context.
ParseCleanup
PreUpdate
PrintfArguments
RCStr
RenameToken
Returning Information about the RETURNING clause.
RowSet
Savepoint
Select All information needed to generate code for a single SELECT statement
SQLiteThread
Sqlite3Config Global configurations for the SQLite library.
SelectDest
SrcItem Representation of a single term in the FROM clause of a query.
SrcList One or more tables that are the source of content for an SQL statement
sqlite3_str StrAccum is an internal alias for sqlite3_str.
Table Each schema for each SQL table, virtual table or view is represented in memory by an instance of this struct.
TableLock
Token A token as produces by the lexer.
TreeView printing the content of data structures on sqlite3DebugPrintf() using a tree-like view.Only available when SQLITE_DEBUG is enabled.
Trigger
TriggerPrg
TriggerStep
UnpackedRecord
Upsert Description of a single ON CONFLICT clause in an upsert.
VTable An object corresponds to a virtual table.
VtabCtx
Walker
WhereInfo
https://github.com/sqlite/sqlite/blob/c7cbcfbbbd522c972527b92b9dfee63c82a97fbc/src/sqliteInt.h#L4477-L4507]Window] Used in various ways, mostly for window functions.
With See also the Cte struct.

Database files

Database files can be shared by multiple database connectsion, unlike cursors.

Older notes of unknown date, tyring to compile SQLIte on Windows with Visual Studio

Apparently, tclsh.exe is needed. It can be downloaded from https://bitbucket.org/tombert/tcltk/downloads/tcltk85-8.5.19-14.tcl85.Win10.x86_64.tgz
After downloading it, tar.exe (pre-installed with Windows Version 10) can be used to extract tclsh.exe and tcl85.dll:
rem tar -xf tcltk85-8.5.19-14.tcl85.Win10.x86_64.tgz  *tclsh.exe  *tcl85.dll
rem move  tcltk85-8.5.19-14.tcl85.Win10.x86_64\bin\* %userprofile%\bin
tar -xf tcltk85-8.5.19-14.tcl85.Win10.x86_64.tgz
set PATH=%cd%\tcltk85-8.5.19-14.tcl85.Win10.x86_64\bin;%path%
Possibly, an init.tcl file should now be created under the user's home directory.
In order to prevent Error: NMAKE : fatal error U1073: don't know how to make '..\manifest':
fsutil file createNew manifest
fsutil file createNew manifest.uuid
mkdir bld
cd    bld

rem nmake /f ..\Makefile.msc TOP=..
nmake /f ..\Makefile.msc TOP=.. sqlite3.c
nmake /f ..\Makefile.msc TOP=.. sqlite3.dll
nmake /f ..\Makefile.msc TOP=.. sqlite3.exe
nmake /f ..\Makefile.msc TOP=.. test
TODO: test creates lots of fatal error C1083: Cannot open include file: 'tcl.h': No such file or directory.

See also

Compile time options

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759612703, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQLite/compile/index(354): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78