Ticket #18332: ticket18332-patch2.diff

File ticket18332-patch2.diff, 3.7 KB (added by vanessagomes, 12 years ago)

Changind the return of backend_info()

  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index f26653f..82bbeb7 100644
    a b class BaseDatabaseWrapper(object):  
    310310
    311311    def make_debug_cursor(self, cursor):
    312312        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()
    313320
    314321class BaseDatabaseFeatures(object):
    315322    allows_group_by_pk = False
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    index 4fba304..3585591 100644
    a b import decimal  
    1010import warnings
    1111import re
    1212import sys
     13import sqlite3
    1314
     15from collections import namedtuple
    1416from django.db import utils
    1517from django.db.backends import *
    1618from django.db.backends.signals import connection_created
    try:  
    2628        from pysqlite2 import dbapi2 as Database
    2729    except ImportError:
    2830        from sqlite3 import dbapi2 as Database
     31        from sqlite3 import sqlite_version
    2932except ImportError as exc:
    3033    from django.core.exceptions import ImproperlyConfigured
    3134    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
    class DatabaseWrapper(BaseDatabaseWrapper):  
    322325        # an in-memory db.
    323326        if self.settings_dict['NAME'] != ":memory:":
    324327            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)
    325333
    326334FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
    327335
  • docs/releases/1.5.txt

    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.  
    3333What's new in Django 1.5
    3434========================
    3535
     36Backend 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
    3647Support for saving a subset of model's fields
    3748~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3849
  • tests/regressiontests/backends/tests.py

    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  
    44
    55import datetime
    66import threading
    7 
     7from sqlite3 import sqlite_version
    88from django.conf import settings
    99from django.core.management.color import no_style
    1010from django.core.exceptions import ImproperlyConfigured
    class BackendTestCase(TestCase):  
    409409        query = 'CREATE TABLE %s (id INTEGER);' % models.Article._meta.db_table
    410410        with self.assertRaises(DatabaseError):
    411411            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)           
    412417
    413418# We don't make these tests conditional because that means we would need to
    414419# check and differentiate between:
Back to Top