编译与安装
安装Python3 64bit
https://www.python.org/ftp/python/3.7.2/python-3.7.2-amd64.exe
安装OpenSSL
https://slproweb.com/products/Win32OpenSSL.html
这里使用了
Win64 OpenSSL v1.0.2q
版本。注意需要将OpenSSL的dll安装到系统目录,如果只是安装在OpenSSL的bin目录的话,使用的时候需要将bin目录加入系统PATH,或者自行拷贝相关dll到调用程序目录。
安装Tcl Windows(64-bit, x64)
https://www.activestate.com/products/activetcl/downloads/
我使用了
8.6.8.0
版本。安装 VisualStudio 2017
https://visualstudio.microsoft.com/zh-hans/downloads/
社区版即可,只须安装“使用C++的桌面开发”相关工具集。
下载 sqlcipher
1
D:\MyDocs\Desktop>git clone https://github.com/sqlcipher/sqlcipher.git
生成sqlite3源码
从开始菜单找到
适用于 VS 2017 的 x64 本机工具命令提示
,启动,打开附带了VS工作环境的控制台。切换到sqlcipher源码目录,执行
1
D:\MyDocs\Desktop\sqlcipher>nmake /f Makefile.msc
结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46Microsoft (R) 程序维护实用工具 14.16.27026.1 版
版权所有 (C) Microsoft Corporation。 保留所有权利。
copy .\tool\lempar.c .
已复制 1 个文件。
cl -nologo -W4 -MT -DNDEBUG -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -O2 -Zi -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206 -wd4210 -wd4232 -wd4305 -wd4306 -wd4702 -wd4706 -Daccess=_access -Felemon.exe .\tool\lemon.c /link /DEBUG
lemon.c
del /Q parse.y parse.h parse.h.temp 2>NUL
copy .\src\parse.y .
已复制 1 个文件。
.\lemon.exe -DSQLITE_MAX_TRIGGER_DEPTH=100 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_STMTVTAB=1 -DSQLITE_ENABLE_DBPAGE_VTAB=1 -DSQLITE_ENABLE_DBSTAT_VTAB=1 -DSQLITE_INTROSPECTION_PRAGMAS=1 -DSQLITE_ENABLE_DESERIALIZE=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 parse.y
move parse.h parse.h.temp
移动了 1 个文件。
tclsh .\tool\addopcodes.tcl parse.h.temp > parse.h
type parse.h .\src\vdbe.c | tclsh .\tool\mkopcodeh.tcl > opcodes.h
parse.h
.\src\vdbe.c
tclsh .\tool\mkopcodec.tcl opcodes.h > opcodes.c
cl -nologo -W4 -MT -DNDEBUG -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -O2 -Zi -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206 -wd4210 -wd4232 -wd4305 -wd4306 -wd4702 -wd4706 -Femkkeywordhash.exe -DSQLITE_MAX_TRIGGER_DEPTH=100 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_STMTVTAB=1 -DSQLITE_ENABLE_DBPAGE_VTAB=1 -DSQLITE_ENABLE_DBSTAT_VTAB=1 -DSQLITE_INTROSPECTION_PRAGMAS=1 -DSQLITE_ENABLE_DESERIALIZE=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 .\tool\mkkeywordhash.c /link /DEBUG
mkkeywordhash.c
.\mkkeywordhash.exe > keywordhash.h
tclsh .\tool\mkshellc.tcl > shell.c
cl -nologo -W4 -MT -DNDEBUG -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -O2 -Zi -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206 -wd4210 -wd4232 -wd4305 -wd4306 -wd4702 -wd4706 -Femksourceid.exe .\tool\mksourceid.c /link /DEBUG
mksourceid.c
tclsh .\tool\mksqlite3h.tcl . > sqlite3.h
copy .\ext\fts5\fts5parse.y .
已复制 1 个文件。
del /Q fts5parse.h 2>NUL
.\lemon.exe -DSQLITE_MAX_TRIGGER_DEPTH=100 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_STMTVTAB=1 -DSQLITE_ENABLE_DBPAGE_VTAB=1 -DSQLITE_ENABLE_DBSTAT_VTAB=1 -DSQLITE_INTROSPECTION_PRAGMAS=1 -DSQLITE_ENABLE_DESERIALIZE=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 fts5parse.y
tclsh .\ext\fts5\tool\mkfts5c.tcl
copy .\ext\fts5\fts5.h .
已复制 1 个文件。
rmdir /Q/S tsrc 2>NUL
mkdir tsrc
for %i in (.\src\crypto.c .\src\crypto_cc.c .\src\crypto_impl.c .\src\crypto_libtomcrypt.c .\src\crypto_openssl.c .\src\crypto.h .\src\sqlcipher.h .\src\alter.c .\src\analyze.c .\src\attach.c .\src\auth.c .\src\backup.c .\src\bitvec.c .\src\btmutex.c .\src\btree.c .\src\build.c .\src\callback.c .\src\complete.c .\src\ctime.c .\src\date.c .\src\dbpage.c .\src\dbstat.c .\src\delete.c .\src\expr.c .\src\fault.c .\src\fkey.c .\src\func.c .\src\global.c .\src\hash.c .\src\insert.c .\src\legacy.c .\src\loadext.c .\src\main.c .\src\malloc.c .\src\mem0.c .\src\mem1.c .\src\mem2.c .\src\mem3.c .\src\mem5.c .\src\memdb.c .\src\memjournal.c .\src\mutex.c .\src\mutex_noop.c .\src\mutex_unix.c .\src\mutex_w32.c .\src\notify.c .\src\os.c .\src\os_unix.c .\src\os_win.c) do copy /Y %i tsrc
......略
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.EXE"”: 返回代码“0x2”
Stop.最终编译会报错,不过没关系,我们这里并不需要真正的编译,只需要中间生成的
sqlite3.h
和sqlite3.c
就够了。中间过程如果执行有其他差错,可以clean一下再重试:
1
D:\MyDocs\Desktop\sqlcipher>nmake /f Makefile.msc clean
编译正式的sqlcipher控制台程序(非必须)
这并不是 pysqlcipher3 需要的,但如果自己想成功编译一份 sqlcipher 的 Windows 程序,可以参考这篇 Win64 setup — Compiling SQLCipher,修改Makefile.msc再构建。
下载 pysqlcipher3
1
git clone https://github.com/rigglemania/pysqlcipher3.git
在
pysqlcipher3
目录下创建amalgamation
目录,拷贝上一步 sqlcipher 项目目录中生成的sqlite3.h
和sqlite3.c
文件到其中。并在其下创建一个sqlcipher
目录,且再次拷贝一份sqlite3.h
文件到sqlcipher
目录中。执行编译
1
D:\MyDocs\Desktop\pysqlcipher3>python setup.py build_amalgamation
结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41D:\MyDocs\Desktop\pysqlcipher3>python setup.py build_amalgamation
running build_amalgamation
Builds a C extension using a sqlcipher amalgamation
building 'pysqlcipher3._sqlite3' extension
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\src
creating build\temp.win-amd64-3.7\Release\src\python3
creating build\temp.win-amd64-3.7\Release\amalgamation
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\module.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\module.obj
module.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\connection.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\connection.obj
connection.c
src\python3\connection.c(1546): warning C4090: “=”: 不同的“const”限定符
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\cursor.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\cursor.obj
cursor.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\cache.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\cache.obj
cache.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\microprotocols.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\microprotocols.obj
microprotocols.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\prepare_protocol.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\prepare_protocol.obj
prepare_protocol.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\statement.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\statement.obj
statement.c
src\python3\statement.c(138): warning C4090: “=”: 不同的“const”限定符
src\python3\statement.c(158): warning C4244: “函数”: 从“Py_ssize_t”转换到“int”,可能丢失数据
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\util.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\util.obj
util.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc\python3\row.c /Fobuild\temp.win-amd64-3.7\Release\src\python3\row.obj
row.c
src\python3\row.c(101): warning C4090: “=”: 不同的“const”限定符
src\python3\row.c(111): warning C4090: “=”: 不同的“const”限定符
src\python3\row.c(168): warning C4244: “=”: 从“Py_ssize_t”转换到“int”,可能丢失数据
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME=\"pysqlcipher3.dbapi2\" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_TEMP_STORE=2 -Dinline=__inline -Iamalgamation -Id:\Work\OpenSSL-Win64\include -ID:\work\Python37\include -ID:\work\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcamalgamation\sqlite3.c /Fobuild\temp.win-amd64-3.7\Release\amalgamation\sqlite3.obj
sqlite3.c
amalgamation\sqlite3.c(23097): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h(208): note: 参见“fopen”的声明
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:\work\Python37\libs /LIBPATH:D:\work\Python37\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" /EXPORT:PyInit__sqlite3 build\temp.win-amd64-3.7\Release\src\python3\module.obj build\temp.win-amd64-3.7\Release\src\python3\connection.obj build\temp.win-amd64-3.7\Release\src\python3\cursor.obj build\temp.win-amd64-3.7\Release\src\python3\cache.obj build\temp.win-amd64-3.7\Release\src\python3\microprotocols.obj build\temp.win-amd64-3.7\Release\src\python3\prepare_protocol.obj build\temp.win-amd64-3.7\Release\src\python3\statement.obj build\temp.win-amd64-3.7\Release\src\python3\util.obj build\temp.win-amd64-3.7\Release\src\python3\row.obj build\temp.win-amd64-3.7\Release\amalgamation\sqlite3.obj /OUT:build\lib.win-amd64-3.7\pysqlcipher3\_sqlite3.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\src\python3\_sqlite3.cp37-win_amd64.lib libeay32.lib /LIBPATH:d:\Work\OpenSSL-Win64\lib
正在创建库 build\temp.win-amd64-3.7\Release\src\python3\_sqlite3.cp37-win_amd64.lib 和对象 build\temp.win-amd64-3.7\Release\src\python3\_sqlite3.cp37-win_amd64.exp
正在生成代码
已完成代码的生成安装至python环境
1
D:\MyDocs\Desktop\pysqlcipher3>python setup.py install
结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71running install
running bdist_egg
running egg_info
writing pysqlcipher3.egg-info\PKG-INFO
writing dependency_links to pysqlcipher3.egg-info\dependency_links.txt
writing top-level names to pysqlcipher3.egg-info\top_level.txt
reading manifest file 'pysqlcipher3.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
writing manifest file 'pysqlcipher3.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
Builds a C extension linking against libsqlcipher library
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\pysqlcipher3
copying build\lib.win-amd64-3.7\pysqlcipher3\dbapi2.py -> build\bdist.win-amd64\egg\pysqlcipher3
copying build\lib.win-amd64-3.7\pysqlcipher3\dump.py -> build\bdist.win-amd64\egg\pysqlcipher3
creating build\bdist.win-amd64\egg\pysqlcipher3\test
creating build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\dbapi.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\dump.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\factory.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\hooks.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\regression.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\sqlcipher.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\transactions.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\types.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\userfunctions.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\python3\__init__.py -> build\bdist.win-amd64\egg\pysqlcipher3\test\python3
copying build\lib.win-amd64-3.7\pysqlcipher3\test\__init__.py -> build\bdist.win-amd64\egg\pysqlcipher3\test
copying build\lib.win-amd64-3.7\pysqlcipher3\_sqlite3.cp37-win_amd64.pyd -> build\bdist.win-amd64\egg\pysqlcipher3
copying build\lib.win-amd64-3.7\pysqlcipher3\__init__.py -> build\bdist.win-amd64\egg\pysqlcipher3
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\dbapi2.py to dbapi2.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\dump.py to dump.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\dbapi.py to dbapi.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\dump.py to dump.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\factory.py to factory.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\hooks.py to hooks.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\regression.py to regression.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\sqlcipher.py to sqlcipher.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\transactions.py to transactions.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\types.py to types.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\userfunctions.py to userfunctions.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\python3\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\test\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\__init__.py to __init__.cpython-37.pyc
creating stub loader for pysqlcipher3\_sqlite3.cp37-win_amd64.pyd
byte-compiling build\bdist.win-amd64\egg\pysqlcipher3\_sqlite3.py to _sqlite3.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying pysqlcipher3.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying pysqlcipher3.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying pysqlcipher3.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying pysqlcipher3.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
pysqlcipher3.__pycache__._sqlite3.cpython-37: module references __file__
creating dist
creating 'dist\pysqlcipher3-1.0.3-py3.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing pysqlcipher3-1.0.3-py3.7-win-amd64.egg
creating d:\work\python37\lib\site-packages\pysqlcipher3-1.0.3-py3.7-win-amd64.egg
Extracting pysqlcipher3-1.0.3-py3.7-win-amd64.egg to d:\work\python37\lib\site-packages
Adding pysqlcipher3 1.0.3 to easy-install.pth file
Installed d:\work\python37\lib\site-packages\pysqlcipher3-1.0.3-py3.7-win-amd64.egg
Processing dependencies for pysqlcipher3==1.0.3
Finished processing dependencies for pysqlcipher3==1.0.3中间过程如果执行有差错,可以clean一下再重试:
1
D:\MyDocs\Desktop\pysqlcipher3>python setup.py clean
测试
至此pysqlcipher3编译安装完毕,写个程序测试一下:
1 | from pysqlcipher3 import dbapi2 as sqlite |
结果
1 | D:\work\Python37\python.exe |
也可能执行失败,提示
1 | D:\work\Python37\python.exe |
最有可能的原因是上面提到的 OpenSSL 问题,没有拷贝到 Windows 系统目录,或者没有将 OpenSSL-Win64\bin 目录增加到环境变量PATH。
关于sqlcipher版本问题
编译完成后,自己测试创建一个db再读取没问题,但可能打开其他现成的加密db会失败,提示file is not a database
,实际错误是解密失败,最大的可能性是我们clone的sqlcipher当前是4.x版本,而要打开的db是由3.x版本创建的。
SQLCipher Core
- Default page size for databases increased to 4096 bytes (up from 1024)
- Default PBKDF2 iterations increased to 256,000 (up from 64,000)
- Default KDF algorithm is now PBKDF2-HMAC-SHA512 (from PBKDF2-HMAC-SHA1)
- Default HMAC algorithm is now HMAC-SHA512 (from HMAC-SHA1)
- …
使用最新版本的DB Browser for SQLCipher也无法打开测试代码创建的test.db,原因也是如此
想要使用Python打开sqlcipher3版本的数据库,可以在调用代码里指定加密算法
1 | ... |
如果完全不需要sqlcipher4的支持,可以在第5步
时指定切换到sqlcipher3编译(目前最新的是3.4.2版本):
1 | D:\MyDocs\Desktop>git clone https://github.com/sqlcipher/sqlcipher.git |
这样生成的test.db
也可以用DB Browser for SQLCipher来打开编辑了。