Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Berkeley DB/Sqlite

Since BerkeleyDB can use the SQLite api, can python use sqlite module to connect to BerkeleyDB.

This post suggests using something else, but could have been written pre-Api sync. Best Python module for Berkeley DB?

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.

like image 939
Merlin Avatar asked Dec 07 '11 16:12

Merlin


2 Answers

Building and amalgamating libraries on win32 is challenging :)

My assumptions:

  • python27 (I have ActiveState python but python.org should be ok) in c:\python27
  • visual studio 2010 professional (I think express should work too)

Download bdb and pysqlite (this time I've got 2.6.3) and place it in c:\bdb, unpack bdb so you'll have

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

you need to have libdb52s.lib and libdb_sql52s.lib in

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:

[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 :)

now open setup.py go at line 191 and replace:

libraries=libraries

with:

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

open vs2010 command prompt (in visual studio tools menu)

go in 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
like image 174
sherpya Avatar answered Nov 12 '22 02:11

sherpya


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.

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).

like image 44
Cédric Julien Avatar answered Nov 12 '22 01:11

Cédric Julien