[英]Python Berkeley DB/Sqlite
Since BerkeleyDB can use the SQLite api, can python use sqlite module to connect to BerkeleyDB. 由于BerkeleyDB可以使用SQLite api,因此python可以使用sqlite模块连接到BerkeleyDB。
This post suggests using something else, but could have been written pre-Api sync. 这篇文章建议使用其他东西,但可能是在Api之前同步写的。 Best Python module for Berkeley DB? Berkeley DB的最佳Python模块?
Can get a simple connection string. 可以获得简单的连接字符串。 If there known problem, PLEASE post. 如果有已知问题,请发帖。 I am exploring this topic. 我正在探索这个话题。
Using python 2.7 on linux and windows. 在linux和windows上使用python 2.7。
As suggested here https://forums.oracle.com/forums/thread.jspa?threadID=2302793 I've tried on linux x86_64 with python27, here the steps to make a static version since I doubt your distribution has bdb sqlite api. 正如在这里建议的https://forums.oracle.com/forums/thread.jspa?threadID=2302793我已经尝试使用python27在linux x86_64上,这里是制作静态版本的步骤,因为我怀疑你的发行版有bdb sqlite api。
Download db-5.2.36.tar.gz 下载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
get a copy of pysqlite2 from http://code.google.com/p/pysqlite/ , I've used an hg checkout. 从http://code.google.com/p/pysqlite/获取pysqlite2的副本,我使用了hg结帐。 In setup.cfg add in build_ext section (there are yet two commented lines you can reuse them) 在setup.cfg中添加build_ext部分(还有两行注释行可以重用它们)
include_dirs=/tmp/bdb/include
library_dirs=/tmp/bdb/lib
then cd in pysqlite: 然后在pysqlite中cd:
python setup.py build
python setup.py install
or without installing: 或者没有安装:
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')
Building and amalgamating libraries on win32 is challenging :) 在win32上构建和合并库是具有挑战性的:)
My assumptions: 我的假设:
Download bdb and pysqlite (this time I've got 2.6.3) and place it in c:\\bdb
, unpack bdb so you'll have 下载bdb和pysqlite(这次我有2.6.3)并将它放在c:\\bdb
,解包bdb这样你就有了
C:\bdb\db-5.2.36
go in C:\\bdb\\db-5.2.36\\build_windows
pick Berkeley_DB_vs2010.sln
, select Static Release
as configuration and build 进入C:\\bdb\\db-5.2.36\\build_windows
选择Berkeley_DB_vs2010.sln
,选择Static Release
作为配置和构建
you need to have libdb52s.lib
and libdb_sql52s.lib
in 你需要有libdb52s.lib
和libdb_sql52s.lib
C:\bdb\db-5.2.36\build_windows\Win32\Static Release
now unpack pysqlite in c:\\bdb
, go in C:\\bdb\\pysqlite-2.6.3
and edit setup.cfg
as follow: 现在在c:\\bdb
解压缩pysqlite,进入C:\\bdb\\pysqlite-2.6.3
并编辑setup.cfg
,如下所示:
[build_ext]
include_dirs=C:\bdb\db-5.2.36\lang\sql\generated
library_dirs=C:\bdb\db-5.2.36\build_windows\Win32\Static Release
define=SQLITE_OMIT_LOAD_EXTENSION
be sure to remove libraries= I had to add them to setup.py, because of static link we need to specify more than one library, if someone knows a way to specify a list in setup.cfg, please tell me :) 一定要删除库=我必须将它们添加到setup.py,因为静态链接我们需要指定多个库,如果有人知道在setup.cfg中指定列表的方法,请告诉我:)
now open setup.py
go at line 191 and replace: 现在打开setup.py
去第191行并替换:
libraries=libraries
with: 有:
libraries=['libdb_sql52s', 'libdb52s', 'ws2_32', 'advapi32'],
open vs2010 command prompt (in visual studio tools menu) 打开vs2010命令提示符(在visual studio工具菜单中)
go in c:\\bdb\\pysqlite
进入c:\\bdb\\pysqlite
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
According to the OracleBSDDB documentation , you can force BsdDB to generate a sqlite3 replacement library, then (in theory) you will be able to use this library in replacement of the standard sqlite3 library, and then use the sqlite3 python module. 根据OracleBSDDB文档 ,你可以强制BsdDB生成一个sqlite3替换库,然后(理论上)你将能够使用这个库来代替标准的sqlite3库,然后使用sqlite3 python模块。
Yet, be carrefull, using the version of BsdDB which support SQLite API is licensed under the SleepyCat License that will force you to pay fees to Oracle OR be an open source project (neither of those solutions are really bad, but you have to choose). 然而,使用支持SQLite API的BsdDB版本是根据SleepyCat许可证许可的 ,这将迫使您向Oracle支付费用或者是一个开源项目(这些解决方案都不是很糟糕,但您必须选择) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.