Python Berkeley DB/Sqlite



由于BerkeleyDB可以使用SQLite api, python可以使用SQLite模块连接BerkeleyDB吗?

这篇文章建议使用其他东西,但可以在api同步之前编写。最好的Python模块伯克利数据库?

可以得到一个简单的连接字符串。如果有已知的问题,请张贴。我正在研究这个问题。

在linux和windows上使用python 2.7。

此处建议https://forums.oracle.com/forums/thread.jspa?threadID=2302793我在linux x86_64上尝试过python27,这里是制作静态版本的步骤我怀疑你的发行版有bdb sqlite api。

下载db-5.2.36.tar.gz

tar xzvf db-5.2.36.tar.gz
cd db-5.2.36/build_unix/
CFLAGS="-fPIC" ../dist/configure --enable-static --disable-shared --enable-sql-compat
# you need -fPIC to build the python ext of pysqlite
make
make prefix=/tmp/bdb install

从http://code.google.com/p/pysqlite/获取pysqlite2的副本,我使用了hg checkout。在setup.cfg中添加build_ext部分(还有两个注释行可以重用)

include_dirs=/tmp/bdb/include
library_dirs=/tmp/bdb/lib

then CD in pysqlite:

python setup.py build
python setup.py install

或不安装

cd build/lib.linux-x86_64-2.7
python
from pysqlite2 import dbapi2
conn = dbapi2.connect('test.db')
c = conn.cursor()
c.execute('bla bla bla sql')

在win32上构建和合并库是一个挑战:)

我的假设:

  • python27(我有ActiveState python,但python.org应该是好的)在c:python27
  • visual studio 2010 professional(我觉得express应该也可以)

下载bdb和pysqlite(这次我有2.6.3),并把它放在c:bdb,解压缩BDB,得到

C:bdbdb-5.2.36

C:bdbdb-5.2.36build_windows中取Berkeley_DB_vs2010.sln,选择Static Release作为配置和构建

你需要有libdb52s.liblibdb_sql52s.lib

C:bdbdb-5.2.36build_windowsWin32Static Release

现在解压缩c:bdb中的pysqlite,进入C:bdbpysqlite-2.6.3和编辑setup.cfg

[build_ext]
include_dirs=C:bdbdb-5.2.36langsqlgenerated
library_dirs=C:bdbdb-5.2.36build_windowsWin32Static Release
define=SQLITE_OMIT_LOAD_EXTENSION

一定要删除库=我必须把它们添加到setup.py中,由于静态链接,我们需要指定多个库,如果有人知道在setup.cfg中指定列表的方法,请告诉我:)

现在打开setup.py go在第191行,并替换:

libraries=libraries

:

libraries=['libdb_sql52s', 'libdb52s', 'ws2_32', 'advapi32'],

打开vs2010命令提示符(在visual studio工具菜单中)

进入c:bdbpysqlite

set DISTUTILS_USE_SDK=1
set MSSdk=1
python setup.py build
# ignore errors about manifests, just make sure _sqlite.pyd is built
# make same tests of the linux instructions
python setup.py bdist_wininst
will make the .exe installer in dist subdir

根据OracleBSDDB文档,你可以强制BsdDB生成一个sqlite3替代库,然后(理论上)你将能够使用这个库来替代标准的sqlite3库,然后使用sqlite3 python模块。

然而,要小心,使用支持SQLite API的bsdb版本是在SleepyCat许可下许可的,这将迫使你向Oracle支付费用或成为一个开源项目(这两种解决方案都不是很糟糕,但你必须选择)。

相关内容

最新更新