sqlite
vesion-3.45.1Features
-
Public domain source code allowing for unrestricted use, modification, and distribution.
-
Modular architecture separating the SQL compiler front-end from the B-Tree and Pager back-end.
-
Virtual Database Engine (VDBE) that executes prepared SQL statements as bytecode for high performance.
-
B-Tree storage engine providing ordered key/data storage for tables and indices within a single disk file.
-
Pager module implementing atomic transactions, rollback, and recovery via journals or Write-Ahead Logs (WAL).
-
Pluggable Virtual File System (VFS) layer to abstract operating system-specific file I/O and locking.
-
Lemon parser generator for creating a reentrant, thread-safe, and memory-efficient SQL parser.
-
Amalgamation build option that combines the entire library into a single C file for maximum compiler optimization.
-
Support for Full-Text Search (FTS5) and R-Tree spatial indexing extensions for advanced querying.
-
Atomic commit and rollback mechanisms that ensure data integrity during power failures or system crashes.
-
Zero-configuration design requiring no server process, setup, or administrative overhead.
-
Cross-platform compatibility with stable, well-defined file formats guaranteed to be compatible moving forward.
-
Extensive testing infrastructure including TCL-based test suites, valgrind analysis, and fuzz testing.
-
Support for WITHOUT ROWID tables to optimize storage for tables with specific primary key requirements.
-
Built-in JSON functions and operators for handling semi-structured data within relational tables.
Architecture
SQLite employs a highly modular, layered architecture designed to transform SQL text into efficient database operations. The process begins at the Interface, where C-language APIs receive SQL queries. These queries pass through a Tokenizer and a Parser (generated by the Lemon parser generator) to create a parse tree. The Code Generator then analyzes this tree to produce bytecode, which is stored in a prepared statement object. This bytecode is executed by the Virtual Database Engine (VDBE), a custom virtual machine that serves as the heart of SQLite’s internal logic.
The backend of the library manages data persistence and concurrency. The B-Tree layer organizes data into pages and maintains indices for rapid retrieval. Below the B-Tree, the Pager module handles the complexities of atomic commits, locking, and caching, utilizing either a rollback journal or a Write-Ahead Log (WAL) to ensure ACID compliance. Finally, the Virtual File System (VFS) provides an abstraction layer that allows SQLite to interact with different operating systems (such as Unix or Windows) through a standardized interface for file I/O and time acquisition.
Core Components
- SQL Compiler: Includes the Tokenizer, Parser, and Code Generator for bytecode production.
- VDBE: The bytecode engine that executes prepared statements.
- B-Tree: The storage engine managing tables and indices.
- Pager: The module responsible for transactions and page-level caching.
- VFS: The OS abstraction layer for portability.
Use Cases
This library is ideal for:
- Embedded Devices: Providing a robust database for IoT devices, mobile phones, and automotive systems where resources are constrained.
- Application File Format: Serving as a high-performance, cross-platform alternative to custom XML, JSON, or binary file formats for desktop applications.
- Websites: Powering low-to-medium traffic websites where a serverless architecture simplifies deployment and maintenance.
- Data Analysis: Acting as a temporary engine for processing large datasets or as an intermediate format for data science workflows.
- Edge Computing: Storing and synchronizing data at the edge before uploading to a centralized cloud database.
Getting Started
Developers can integrate SQLite by either using the Amalgamation (a single sqlite3.c and sqlite3.h file pair) or by linking against a precompiled library. The amalgamation is the recommended method as it allows the C compiler to perform cross-procedure optimizations, resulting in a 5% performance boost. To begin, include sqlite3.h in your project and use sqlite3_open() to initialize a database connection. SQL statements are typically executed using the sqlite3_prepare_v2(), sqlite3_step(), and sqlite3_finalize() workflow. For testing and quick prototyping, the provided Command Line Interface (CLI) shell allows for direct interaction with database files. Detailed API specifications and architectural overviews are available at the official SQLite documentation.
Related Projects (27)
View All 27 Projects →pico-vfs: A Virtual File System for Raspberry Pi Pico
pico-vfs is a modular virtual file system designed for the Raspberry Pi Pico that provides a unified POSIX-compliant API for various storage media. It allows developers to mount multiple file systems, such as littlefs and FatFs, across physical storage like onboard flash and SD cards. The project streamlines embedded development by abstracting hardware differences and supporting standard C file operations.
SQLite for Raspberry Pi Pico
A port of the SQLite3 database engine for the Raspberry Pi Pico, enabling structured data storage on microcontrollers. It leverages littlefs for flash persistence and pico-vfs for flexible filesystem support, providing both a C/C++ library and an interactive shell.
SQLite3 for ESP-IDF
A port of the SQLite3 relational database engine for ESP32 microcontrollers using the ESP-IDF framework. It supports ESP-IDF V5.x, offers specialized PSRAM memory management, and integrates with various filesystems including SPIFFS, LittleFS, and FATFS.
ESPMonitor - IoT Environmental Monitoring System
A comprehensive IoT solution for real-time environmental monitoring using ESP32 or ESP8266 microcontrollers. It tracks temperature, humidity, and water levels, transmitting data via HTTP to a Flask-based server with SQLite storage and a responsive web dashboard. Features include remote threshold management and local LED alerts.
Automatic Pet Feeder With ESP32-CAM & Yolov8 Object Detection
An IoT-based automatic pet feeder that utilizes an ESP32-CAM for live streaming and a servo motor for dispensing food. It features a Flask web interface for remote control and employs a YOLOv8 object detection model to automatically feed pets when they are recognized.
Owl - Always-on Wearable AI
An open-source platform for always-on wearable AI that captures and processes life experiences using LLMs. It supports custom hardware like the ESP32S3 and Sony Spresense alongside consumer devices like the Apple Watch, providing a full stack from firmware to mobile interfaces.
MQTT Viewer
A high-performance desktop MQTT visualization and debugging tool for Windows, Mac, and Linux. It supports MQTT v3 and v5 protocols, Sparkplug B codecs, and concurrent broker connections, providing a comprehensive interface for monitoring IoT message traffic.
SMS Server
A self-hosted SMS gateway designed for GSM modem hardware, specifically targeting Raspberry Pi setups with GSM HATs. It provides HTTP and WebSocket APIs for messaging, GNSS location tracking, and modem control with encrypted database persistence using SQLite.