Opened 18 years ago

Closed 18 years ago

#2772 closed enhancement (fixed)

[patch] Add support for standard sqlite3 module

Reported by: ymasuda[at]ethercube.com Owned by: Malcolm Tredinnick
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Starting with Python 2.5, SQLite binding was introduced as sqlite3 standard module which is
mostly identical to pysqlite2. The attached diff allows to import sqlite3 instead of pysqlite3
if sys.hexversion is greater than 0x020500a1 (Python 2.5a1).
This integration was tested under tests/runtest.py with #2771 patch.

Attachments (2)

patch_to_sqlite3_base.diff (894 bytes ) - added by Yasushi Masuda 18 years ago.
patch to trunk/django/db/backends/sqlite3/base.py
patch_sqlite3_base_revised.diff (738 bytes ) - added by ymasuda[at]ethercube.com 18 years ago.
revised version of the patch

Download all attachments as: .zip

Change History (8)

by Yasushi Masuda, 18 years ago

Attachment: patch_to_sqlite3_base.diff added

patch to trunk/django/db/backends/sqlite3/base.py

comment:1 by Yasushi Masuda, 18 years ago

Summary: Add support for standard sqlite3 module[patch] Add support for standard sqlite3 module

prepended [patch] to the summary.

comment:2 by James Bennett, 18 years ago

Maybe a better way to handle this would be what we do with threading -- try to import the 2.5 standard module, and if it tosses an ImportError, catch that and import the pysqlite2 module instead.

comment:3 by ymasuda[at]ethercube.com, 18 years ago

Then, how about like this:

try:
    try:
        # (*explicitly installed*) pysqlite2 succeeds
        from pysqlite2 import dbapi2 as Database
    except ImportError, e:
        # fallback to sqlite3
        from sqlite3 import dbapi2 as Database
except ImportError, e:
    from django.core.exceptions import ImproperlyConfigured
    raise ImproperlyConfigured, "Error loading module: %s" % e

comment:4 by Malcolm Tredinnick, 18 years ago

Owner: changed from Adrian Holovaty to Malcolm Tredinnick

The second approach looks better, although I would rather try to import the standard Python module (sqlite3) first and then fallback. That fits in more with the trend to try to do the right thing first and fallback if we need a backwards-compatiblity feature that is common throughout Python's core.

I need to get a Python 2.5 build done and then I'll get this in.

comment:5 by ymasuda[at]ethercube.com, 18 years ago

Thanks ubernostrum and mtredinnick for comments.
Here I post a revised version of the patch: using nested try...except, and sqlite3 first then pysqlite2.

by ymasuda[at]ethercube.com, 18 years ago

revised version of the patch

comment:6 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

(In [3818]) Fixed #2772 -- Made SQLite support work correctly with Python 2.5 standard
module (as well as pysqlite2 for earlier Python versions). Patch from
ymasuda[at]ethercube.com.

Note: See TracTickets for help on using tickets.
Back to Top