编译SQLite 3.51源码并体验新功能
11月4日,SQLite 3.51发布了,第一时间下载体验,Linux上预编译的只有AMD64版本,而且依赖高版本C动态库,不方便使用,所以按编译说明,手工编译。
我下载的是 amalgamation版本,解压缩后只有4个文件,
root@6ae32a5ffcde:/par/sqlite351# ls -l
total 10912
-rwxrwxrwx 1 root root 1068027 Nov 5 12:18 shell.c
-rwxrwxrwx 1 root root 9385376 Nov 5 12:18 sqlite3.c
-rwxrwxrwx 1 root root 671792 Nov 5 12:18 sqlite3.h
-rwxrwxrwx 1 root root 38632 Nov 5 12:18 sqlite3ext.hroot@6ae32a5ffcde:/par/sqlite351# gcc -Os -I. -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS4 \-DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 \-DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS \-DHAVE_READLINE \shell.c sqlite3.c -ldl -lm -lreadline -lncurses -o sqlite351 -O3
编译过程有一些警告,但没有错误,生成了sqlite351 文件。发版说明写到,
root@6ae32a5ffcde:/par/sqlite351# ls
shell.c sqlite351 sqlite3.c sqlite3.h sqlite351 sqlite3ext.h
root@6ae32a5ffcde:/par/sqlite351# ./sqlite351
SQLite version 3.51.0 2025-11-04 19:38:17
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .mode box
sqlite> select 1 a, '中文' b;
┌───┬──────┐
│ a │ b │
├───┼──────┤
│ 1 │ 中文 │
└───┴──────┘
作为对比,再次编译了上一个版本3.50.4版源码,旧版本的源码到github镜像获取,结果如下:
root@6ae32a5ffcde:/par/sqlite3504# ./sqlite3504
SQLite version 3.50.4 2025-07-30 19:33:53
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .mode box
sqlite> select 1 a, '中文' b;
┌───┬────┐
│ a │ b │
├───┼────┤
│ 1 │ 中 │
└───┴────┘
sqlite>
这么明显的问题,不知为何到现在才解决,也许用SQLite作为前台的少,大部分都是在后台调用。
2.对于当前时间戳的支持
sqlite> create table test as select now()ts;
Parse error: no such function: nowcreate table test as select now()ts;error here ---^
sqlite> create table test as select current_timestamp() ts;
Parse error: near "(": syntax errorcreate table test as select current_timestamp() ts;error here ---^
sqlite> create table test as select current_timestamp ts;
sqlite> select * from test;
┌─────────────────────┐
│ ts │
├─────────────────────┤
│ 2025-11-05 13:06:28 │
└─────────────────────┘
只能用不带括号的current_timestamp来查询。
3. .timer计时精确到毫秒
sqlite> select sum(value) from generate_series(1,100000);
┌────────────┐
│ sum(value) │
├────────────┤
│ 5000050000 │
└────────────┘
Run Time: real 0.004330 user 0.004000 sys 0.000000-- 再试一个高难度数独
WITH RECURSIVEinput(sud) AS (VALUES('.....1..7....6..2.8..9..3...954....3..3...4..4......8......7..6.1..2....5..3..9..')),digits(z, lp) AS (VALUES('1', 1)UNION ALL SELECTCAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9),x(s, ind) AS (SELECT sud, instr(sud, '.') FROM inputUNION ALLSELECTsubstr(s, 1, ind-1) || z || substr(s, ind+1),instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )FROM x, digits AS zWHERE ind>0AND NOT EXISTS (SELECT 1FROM digits AS lpWHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)OR z.z = substr(s, ((ind-1)%9) + (lp-1)*9 + 1, 1)OR z.z = substr(s, (((ind-1)/3) % 3) * 3+ ((ind-1)/27) * 27 + lp+ ((lp-1) / 3) * 6, 1)))
SELECT s FROM x WHERE ind=0;
┌──────────────────────────────────────────────────────────────┐
│ s │
├──────────────────────────────────────────────────────────────┤
│ 346251897759863124821974365195486273683712459472539681238197 │
│ 546914625738567348912 │
└──────────────────────────────────────────────────────────────┘
Run Time: real 10.579288 user 10.548000 sys 0.032000--旧版
sqlite> select sum(value) from generate_series(1,100000);
┌────────────┐
│ sum(value) │
├────────────┤
│ 5000050000 │
└────────────┘
Run Time: real 0.003 user 0.004000 sys 0.000000
