Python Berkeley DB / Sqlite

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

This article suggests using something else, but pre-api sync might be written. Best Python module for Berkeley DB?

You can get a simple connection string. If there is a known problem, PLEASE write. I am studying this topic.

Using python 2.7 for linux and windows.

+6
source share
3 answers

As suggested here https://forums.oracle.com/forums/thread.jspa?threadID=2302793 I tried on linux x86_64 with python27, here are the steps to make a static version with I doubt your distribution has a 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 used hg checkout. In setup.cfg add to the build_ext section (there are two more lines with comments that you can reuse)

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

then cd in pysqlite:

 python setup.py build python setup.py install 

or without installation:

 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') 
+4
source

Creating and merging libraries on win32 is difficult :)

My assumptions:

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

Download bdb and pysqlite (this time I have 2.6.3) and put it in c:\bdb , unzip bdb so you have

 C:\bdb\db-5.2.36 

go to C:\bdb\db-5.2.36\build_windows select 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 unzip pysqlite to c:\bdb , go to C:\bdb\pysqlite-2.6.3 and edit setup.cfg as follows:

 [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 delete the libraries = I had to add them to setup.py, because of the static link we need to specify more than one library, if someone knows a way to list in setup.cfg, tell me :)

now open setup.py on line 191 and replace:

 libraries=libraries 

from:

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

open vs2010 command line (in the visual studio tools menu)

go to 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 
+4
source

According to OracleBSDDB documentation , you can force BsdDB to generate the sqlite3 replacement library, then (theoretically) you can use this library to replace the standard sqlite3 library, and then use the python sqlite3 module.

However, be useful using a version of BsdDB that supports the SQLite API, licensed under the License SleepyCat , which will force you to pay fees for Oracle OR, an open source project (none of these solutions are very bad, but you should select).

+3
source

Source: https://habr.com/ru/post/903304/


All Articles