diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index f26653f..82bbeb7 100644
a
|
b
|
class BaseDatabaseWrapper(object):
|
310 | 310 | |
311 | 311 | def make_debug_cursor(self, cursor): |
312 | 312 | return util.CursorDebugWrapper(cursor, self) |
| 313 | |
| 314 | def backend_info(self): |
| 315 | """ |
| 316 | Returns a namedtuple that containd the name and version tuple |
| 317 | from the current database. |
| 318 | """ |
| 319 | return self._get_backend_info() |
313 | 320 | |
314 | 321 | class BaseDatabaseFeatures(object): |
315 | 322 | allows_group_by_pk = False |
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 4fba304..3585591 100644
a
|
b
|
import decimal
|
10 | 10 | import warnings |
11 | 11 | import re |
12 | 12 | import sys |
| 13 | import sqlite3 |
13 | 14 | |
| 15 | from collections import namedtuple |
14 | 16 | from django.db import utils |
15 | 17 | from django.db.backends import * |
16 | 18 | from django.db.backends.signals import connection_created |
… |
… |
try:
|
26 | 28 | from pysqlite2 import dbapi2 as Database |
27 | 29 | except ImportError: |
28 | 30 | from sqlite3 import dbapi2 as Database |
| 31 | from sqlite3 import sqlite_version |
29 | 32 | except ImportError as exc: |
30 | 33 | from django.core.exceptions import ImproperlyConfigured |
31 | 34 | raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc) |
… |
… |
class DatabaseWrapper(BaseDatabaseWrapper):
|
322 | 325 | # an in-memory db. |
323 | 326 | if self.settings_dict['NAME'] != ":memory:": |
324 | 327 | BaseDatabaseWrapper.close(self) |
| 328 | |
| 329 | def _get_backend_info(self): |
| 330 | version_tuple = tuple(map(lambda x: int(x), sqlite_version.split('.'))) |
| 331 | BackendInfo = namedtuple('BackendInfo', 'vendor version') |
| 332 | return BackendInfo(self.vendor, version_tuple) |
325 | 333 | |
326 | 334 | FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s') |
327 | 335 | |
diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt
index 51e64bd..d8b9aff 100644
a
|
b
|
version compatible with Python 2.6.
|
33 | 33 | What's new in Django 1.5 |
34 | 34 | ======================== |
35 | 35 | |
| 36 | Backend info |
| 37 | ~~~~~~~~~~~~ |
| 38 | * It was added connection.backend_info() that returns the name and the version of the current database. |
| 39 | Authors of other backends should implement this in their custom backends. |
| 40 | |
| 41 | * Use of backend_info: |
| 42 | >>> from django.db import connection |
| 43 | >>> connection.backend_info() |
| 44 | BackendInfo(vendor='sqlite', version=(3, 7, 2)) |
| 45 | |
| 46 | |
36 | 47 | Support for saving a subset of model's fields |
37 | 48 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
38 | 49 | |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 10e69b6..79bbbe0 100644
a
|
b
|
from __future__ import absolute_import
|
4 | 4 | |
5 | 5 | import datetime |
6 | 6 | import threading |
7 | | |
| 7 | from sqlite3 import sqlite_version |
8 | 8 | from django.conf import settings |
9 | 9 | from django.core.management.color import no_style |
10 | 10 | from django.core.exceptions import ImproperlyConfigured |
… |
… |
class BackendTestCase(TestCase):
|
409 | 409 | query = 'CREATE TABLE %s (id INTEGER);' % models.Article._meta.db_table |
410 | 410 | with self.assertRaises(DatabaseError): |
411 | 411 | cursor.execute(query) |
| 412 | |
| 413 | def test_backend_info_sqlite(self): |
| 414 | self.assertEqual(connection.vendor, connection.backend_info().vendor) |
| 415 | version_tuple = tuple(map(lambda x: int(x), sqlite_version.split('.'))) |
| 416 | self.assertEqual(version_tuple, connection.backend_info().version) |
412 | 417 | |
413 | 418 | # We don't make these tests conditional because that means we would need to |
414 | 419 | # check and differentiate between: |