Ticket #463: mysql_magic-removal_rev2360.diff
File mysql_magic-removal_rev2360.diff, 2.3 KB (added by , 19 years ago) |
---|
-
django/db/backends/mysql/base.py
9 9 from MySQLdb.converters import conversions 10 10 from MySQLdb.constants import FIELD_TYPE 11 11 import types 12 import threading 12 13 13 14 DatabaseError = Database.DatabaseError 14 15 … … 48 49 49 50 class DatabaseWrapper: 50 51 def __init__(self): 51 self. connection = None52 self.threadlocal = threading.local() 52 53 self.queries = [] 53 54 54 55 def cursor(self): 55 56 from django.conf import settings 56 if self.connection is None: 57 conn = getattr(self.threadlocal, 'connection', None) 58 if conn is None: 57 59 kwargs = { 58 60 'user': settings.DATABASE_USER, 59 61 'db': settings.DATABASE_NAME, … … 63 65 } 64 66 if settings.DATABASE_PORT: 65 67 kwargs['port'] = settings.DATABASE_PORT 66 self.connection = Database.connect(**kwargs) 67 cursor = self.connection.cursor() 68 if self.connection.get_server_info() >= '4.1': 68 conn = self.threadlocal.connection = Database.connect(**kwargs) 69 else: 70 conn.ping() 71 cursor = conn.cursor() 72 if conn.get_server_info() >= '4.1': 69 73 cursor.execute("SET NAMES utf8") 70 74 if settings.DEBUG: 71 75 return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self) 72 76 return cursor 73 77 74 78 def commit(self): 75 self.connection.commit() 79 conn = getattr(self.threadlocal, 'connection', None) 80 if conn is not None: 81 conn.commit() 76 82 77 83 def rollback(self): 78 if self.connection: 84 conn = getattr(self.threadlocal, 'connection', None) 85 if conn is not None: 79 86 try: 80 self.connection.rollback()87 conn.rollback() 81 88 except Database.NotSupportedError: 82 89 pass 83 90 84 91 def close(self): 85 if self.connection is not None: 86 self.connection.close() 87 self.connection = None 92 conn = getattr(self.threadlocal, 'connection', None) 93 if conn is not None: 94 conn.close() 95 self.threadlocal.connection = None 88 96 89 97 supports_constraints = True 90 98