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