Flexible Typing
Type is at cell level.
Sqlite will convert the type to the declared type if it can without losing data.
5 data types:
Type Affinity
Contains --> Type
Strict Typing
Flexible typing and strict typing can be mixed:
Dates
sqlite> SELECT date(); 2025-02-10 sqlite> SELECT time(); 10:13:27 sqlite> SELECT datetime(); 2025-02-10 10:06:00 sqlite> SELECT julianday(); 2460716.92186773 sqlite> SELECT strftime("%d", "now"); 10 sqlite> SELECT strftime("%s", "now"); 1739182503 sqlite> SELECT datetime('now', 'start of month'); 2025-02-01 00:00:00 sqlite> SELECT datetime('now', 'start of month', '+1 month'); 2025-03-01 00:00:00 sqlite> SELECT datetime('now', 'start of month', '+1 month', '-1 day'); 2025-02-28 00:00:00
Booleans
sqlite> SELECT true; 1 sqlite> SELECT false; 0
Floating point
rowid
Auto increment
Another table modifier: without rowid
Generated columns
Locking
Locking states:
1. Unlocked: no reading, no writing
2. Shared Lock: everyone can read it, but nobody can write to it
3. Reserved Lock: I'm going to write at some point, but I'm not writing yet. In this state, a new Shared Lock can be required.
4. Pending: In this state, nobody can require a new Shared Lock, waiting for open Shared Locks to go away.
5. Exclusive Lock: The lock owner can write to the database. Only one writer can hold this lock.
SQLite uses database-level locking rather than table-level locking. This means that when a write operation occurs, the entire database is locked, preventing other write operations from happening simultaneously. However, reads can still occur concurrently in most cases.
Journal Mode:
sqlite> pragma journal_mode; memory
Rollback mode is the default.
Busy Timeout
In Wal mode, while a writer is writing the write-ahead-log, other writers have to wait. busy_timeout is how we can figure how long they can wait before giving up and throwing an error. The default value is 0.
Transaction Modes: deferred, exclusive, immediate
In Wal mode, immediate and exclusive are the same.
Deferred is the default.
Vaccum
Deleting data didn't reduce the size of the database file.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-02-10 Outlook - stop displaying enter sign at line end
2021-02-10 Sed - Edit crontab with sed