Ticket #18332: ticket18332.diff

File ticket18332.diff, 2.3 KB (added by vanessagomes, 12 years ago)
  • It was added connection.backend_info() that returns the name and the version of the current database. Authors of other backends should implement this in their custom backends. * Use of backend_info: >>> from django.db import connection >>> print (connection.backend_info()) sqlite 3.7.2
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index f26653f..435972c 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 the name and the version from the current database.
     317        """
     318        return self._get_backend_info()
    313319
    314320class BaseDatabaseFeatures(object):
    315321    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..861e801 100644
    a b import decimal  
    1010import warnings
    1111import re
    1212import sys
     13import sqlite3
    1314
    1415from django.db import utils
    1516from django.db.backends import *
    try:  
    2627        from pysqlite2 import dbapi2 as Database
    2728    except ImportError:
    2829        from sqlite3 import dbapi2 as Database
     30        from sqlite3 import *
    2931except ImportError as exc:
    3032    from django.core.exceptions import ImproperlyConfigured
    3133    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
    class DatabaseWrapper(BaseDatabaseWrapper):  
    322324        # an in-memory db.
    323325        if self.settings_dict['NAME'] != ":memory:":
    324326            BaseDatabaseWrapper.close(self)
     327   
     328    def _get_backend_info(self):
     329        return str(self.vendor) +" "+ (sqlite_version)
    325330
    326331FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
    327332
  • docs/releases/1.5.txt

    diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt
    index 51e64bd..5af94a3 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    >>> print (connection.backend_info())
     44    sqlite 3.7.2
     45
    3646Support for saving a subset of model's fields
    3747~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3848
Back to Top