A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/husio/python-sqlite3-backup below:

husio/python-sqlite3-backup: Sqlite3 online API CPython implementation module

Backup function is now provided by the standard library

SQLite3 backup function implementation for Python sqlite3 module

Single function that allows to copy content of one sqlite3 database to another one. You can use this for example for loading and dumping in memory database (:memory:) into a file (alternative to the iter dump functionality).

See the Sqlite3 C API docs for more information.

The same functionality is being provided by the apsw backup API, which provides more information about the copy process.

You can build or install sqlitebck using distutils:

$ python setup.py build
$ python setup.py install

You can also install it, using the pip command:

Test basic functionality (make sure you have build the sqlitebck module):

Basic usage example - a memory database saved into a file:

>>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> curr = conn.cursor()

Create a table and put there some data:

>>> curr.execute('CREATE TABLE foo (bar INTEGER)')
<sqlite3.Cursor object at 0xb73b2800>
>>> curr.execute('INSERT INTO foo VALUES (123)')
<sqlite3.Cursor object at 0xb73b2800>
>>> curr.close()
>>> conn.commit()
>>> import sqlitebck

Save a memory database (conn) into a file:

>>> conn2 = sqlite3.connect('/tmp/in_memory_sqlite_db_save.db')
>>> sqlitebck.copy(conn, conn2)
>>> conn.close()
>>> curr2 = conn2.cursor()

Check if data is in a file database:

>>> curr2.execute('SELECT * FROM foo');
<sqlite3.Cursor object at 0xb73b2860>
>>> curr2.fetchall()
[(123,)]

If you want to load a file database into a memory:

>>> sqlitebck.copy(conn2, conn)

If you want to copy a (large) online database, you can release the read-lock on the source database for a specified time between copying each batch of pages:

>>> sqlitebck.copy(conn2, conn, pages, sleep)

By default, pages=0 and sleep=0, which copies all pages with no interruption.

The online copying process handles situations with a write-lock on the source database and copying of changes written to the source database while copying batches of pages.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4