Python Berkeley DB/Sqlite
Asked Answered
S

3

6

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.

Stearn answered 7/12, 2011 at 16:9 Comment(3)
I'm taking a survey, Why do you think you even want this? Keeping the same API won't make the database files themselves more portable, you'll have to repeat the non-standard compile procedure each time you have to migrate to a new host. Using a more featureful database than Sqlite3 is pretty simple, all major databases have DBApi compatible bindings.Lannielanning
Answer to your survey: Everyone has their own use case and dev path.Stearn
I'm asking about Your use case, since you are probably looking for a solution to that particular case.Lannielanning
D
4

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.

Download 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. In setup.cfg add in build_ext section (there are yet two commented lines you can reuse them)

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

then cd in pysqlite:

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')
Doublecross answered 9/12, 2011 at 4:59 Comment(0)
D
4

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
Doublecross answered 18/12, 2011 at 3:0 Comment(1)
+1 "Building and amalgamating libraries on win32 is challenging :)"Stearn
L
3

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

Lap answered 7/12, 2011 at 16:35 Comment(2)
On the fees, what using BSDDB alone, would I have to pay a fee? Isnt BSDDB open source, Akin to MySQL.Stearn
@Stearn : I updated my answer with a link to the BsdDB license.Semele

© 2022 - 2024 — McMap. All rights reserved.