summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql
diff options
context:
space:
mode:
authorRobin Munn <robin.munn@gmail.com>2006-10-24 07:49:37 +0000
committerRobin Munn <robin.munn@gmail.com>2006-10-24 07:49:37 +0000
commit0b059aa4eadc1d95ceca3a32821b65a9fb2a53e8 (patch)
tree76f84c62e3ac5cd5172d43dd73a651bb8574e2d1 /django/db/backends/mysql
parent1bb4fa2cb66269b1eff3b7d73f8c7864c0622368 (diff)
sqlalchemy: Merged revisions 3832 to 3917 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/sqlalchemy@3918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/mysql')
-rw-r--r--django/db/backends/mysql/base.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 23ea76316f..04e5814988 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -13,6 +13,7 @@ except ImportError, e:
from MySQLdb.converters import conversions
from MySQLdb.constants import FIELD_TYPE
import types
+import re
DatabaseError = Database.DatabaseError
@@ -24,6 +25,12 @@ django_conversions.update({
FIELD_TYPE.TIME: util.typecast_time,
})
+# This should match the numerical portion of the version numbers (we can treat
+# versions like 5.0.24 and 5.0.24a as the same). Based on the list of version
+# at http://dev.mysql.com/doc/refman/4.1/en/news.html and
+# http://dev.mysql.com/doc/refman/5.0/en/news.html .
+server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')
+
# This is an extra debug layer over MySQL queries, to display warnings.
# It's only used when DEBUG=True.
class MysqlDebugWrapper:
@@ -61,6 +68,7 @@ class DatabaseWrapper(local):
def __init__(self):
self.connection = None
self.queries = []
+ self.server_version = None
def _valid_connection(self):
if self.connection is not None:
@@ -110,6 +118,16 @@ class DatabaseWrapper(local):
self.connection.close()
self.connection = None
+ def get_server_version(self):
+ if not self.server_version:
+ if not self._valid_connection():
+ self.cursor()
+ m = server_version_re.match(self.connection.get_server_info())
+ if not m:
+ raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
+ self.server_version = tuple([int(x) for x in m.groups()])
+ return self.server_version
+
supports_constraints = True
def quote_name(name):