Changeset 5949
- Timestamp:
- 08/19/07 16:30:57 (1 year ago)
- Files:
-
- django/trunk/django/db/backends/ado_mssql/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/__init__.py (modified) (1 diff)
- django/trunk/django/db/backends/mysql/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/mysql_old/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/oracle/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/postgresql/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/postgresql_psycopg2/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/sqlite3/base.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/backends/ado_mssql/base.py
r5519 r5949 5 5 """ 6 6 7 from django.db.backends import util7 from django.db.backends import BaseDatabaseWrapper, util 8 8 try: 9 9 import adodbapi as Database … … 49 49 Database.convertVariantToPython = variantToPython 50 50 51 try: 52 # Only exists in Python 2.4+ 53 from threading import local 54 except ImportError: 55 # Import copy of _thread_local.py from Python 2.4 56 from django.utils._threading_local import local 57 58 class DatabaseWrapper(local): 59 def __init__(self, **kwargs): 60 self.connection = None 61 self.queries = [] 62 63 def cursor(self): 64 from django.conf import settings 51 class DatabaseWrapper(BaseDatabaseWrapper): 52 def _cursor(self, settings): 65 53 if self.connection is None: 66 54 if settings.DATABASE_NAME == '' or settings.DATABASE_USER == '': 67 55 from django.core.exceptions import ImproperlyConfigured 68 raise ImproperlyConfigured , "You need to specify both DATABASE_NAME and DATABASE_USER in your Django settings file."56 raise ImproperlyConfigured("You need to specify both DATABASE_NAME and DATABASE_USER in your Django settings file.") 69 57 if not settings.DATABASE_HOST: 70 58 settings.DATABASE_HOST = "127.0.0.1" … … 72 60 conn_string = "PROVIDER=SQLOLEDB;DATA SOURCE=%s;UID=%s;PWD=%s;DATABASE=%s" % (settings.DATABASE_HOST, settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME) 73 61 self.connection = Database.connect(conn_string) 74 cursor = self.connection.cursor() 75 if settings.DEBUG: 76 return util.CursorDebugWrapper(cursor, self) 77 return cursor 78 79 def _commit(self): 80 if self.connection is not None: 81 return self.connection.commit() 82 83 def _rollback(self): 84 if self.connection is not None: 85 return self.connection.rollback() 86 87 def close(self): 88 if self.connection is not None: 89 self.connection.close() 90 self.connection = None 62 return self.connection.cursor() 91 63 92 64 allows_group_by_ordinal = True django/trunk/django/db/backends/__init__.py
r4265 r5949 1 try: 2 # Only exists in Python 2.4+ 3 from threading import local 4 except ImportError: 5 # Import copy of _thread_local.py from Python 2.4 6 from django.utils._threading_local import local 7 8 class BaseDatabaseWrapper(local): 9 def __init__(self, **kwargs): 10 self.connection = None 11 self.queries = [] 12 self.options = kwargs 13 14 def _commit(self): 15 if self.connection is not None: 16 return self.connection.commit() 17 18 def _rollback(self): 19 if self.connection is not None: 20 return self.connection.rollback() 21 22 def close(self): 23 if self.connection is not None: 24 self.connection.close() 25 self.connection = None 26 27 def cursor(self): 28 from django.conf import settings 29 cursor = self._cursor(settings) 30 if settings.DEBUG: 31 return self.make_debug_cursor(cursor) 32 return cursor 33 34 def make_debug_cursor(self, cursor): 35 from django.db.backends import util 36 return util.CursorDebugWrapper(cursor, self) django/trunk/django/db/backends/mysql/base.py
r5609 r5949 5 5 """ 6 6 7 from django.db.backends import util7 from django.db.backends import BaseDatabaseWrapper, util 8 8 try: 9 9 import MySQLdb as Database … … 54 54 # TRADITIONAL will automatically cause most warnings to be treated as errors. 55 55 56 try: 57 # Only exists in Python 2.4+ 58 from threading import local 59 except ImportError: 60 # Import copy of _thread_local.py from Python 2.4 61 from django.utils._threading_local import local 62 63 class DatabaseWrapper(local): 56 class DatabaseWrapper(BaseDatabaseWrapper): 64 57 def __init__(self, **kwargs): 65 self.connection = None 66 self.queries = [] 58 super(DatabaseWrapper, self).__init__(**kwargs) 67 59 self.server_version = None 68 self.options = kwargs69 60 70 61 def _valid_connection(self): … … 78 69 return False 79 70 80 def cursor(self): 81 from django.conf import settings 71 def _cursor(self, settings): 82 72 from warnings import filterwarnings 83 73 if not self._valid_connection(): … … 101 91 kwargs.update(self.options) 102 92 self.connection = Database.connect(**kwargs) 103 cursor = self.connection.cursor() 104 else: 105 cursor = self.connection.cursor() 93 cursor = self.connection.cursor() 106 94 if settings.DEBUG: 107 95 filterwarnings("error", category=Database.Warning) 108 return util.CursorDebugWrapper(cursor, self)109 96 return cursor 110 97 111 def _commit(self):112 if self.connection is not None:113 self.connection.commit()114 115 98 def _rollback(self): 116 if self.connection is not None: 117 try: 118 self.connection.rollback() 119 except Database.NotSupportedError: 120 pass 121 122 def close(self): 123 if self.connection is not None: 124 self.connection.close() 125 self.connection = None 99 try: 100 BaseDatabaseWrapper._rollback(self) 101 except Database.NotSupportedError: 102 pass 126 103 127 104 def get_server_version(self): django/trunk/django/db/backends/mysql_old/base.py
r5876 r5949 5 5 """ 6 6 7 from django.db.backends import util7 from django.db.backends import BaseDatabaseWrapper, util 8 8 from django.utils.encoding import force_unicode 9 9 try: … … 64 64 return getattr(self.cursor, attr) 65 65 66 try: 67 # Only exists in Python 2.4+ 68 from threading import local 69 except ImportError: 70 # Import copy of _thread_local.py from Python 2.4 71 from django.utils._threading_local import local 72 73 class DatabaseWrapper(local): 66 class DatabaseWrapper(BaseDatabaseWrapper): 74 67 def __init__(self, **kwargs): 75 self.connection = None 76 self.queries = [] 68 super(DatabaseWrapper, self).__init__(**kwargs) 77 69 self.server_version = None 78 self.options = kwargs79 70 80 71 def _valid_connection(self): … … 88 79 return False 89 80 90 def cursor(self): 91 from django.conf import settings 81 def _cursor(self, settings): 92 82 if not self._valid_connection(): 93 83 kwargs = { … … 120 110 else: 121 111 cursor = self.connection.cursor() 122 if settings.DEBUG:123 return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self)124 112 return cursor 125 113 126 def _commit(self): 127 if self.connection is not None: 128 self.connection.commit() 114 def make_debug_cursor(self, cursor): 115 return BaseDatabaseWrapper.make_debug_cursor(self, MysqlDebugWrapper(cursor)) 129 116 130 117 def _rollback(self): 131 if self.connection is not None: 132 try: 133 self.connection.rollback() 134 except Database.NotSupportedError: 135 pass 136 137 def close(self): 138 if self.connection is not None: 139 self.connection.close() 140 self.connection = None 118 try: 119 BaseDatabaseWrapper._rollback(self) 120 except Database.NotSupportedError: 121 pass 141 122 142 123 def get_server_version(self): django/trunk/django/db/backends/oracle/base.py
r5943 r5949 5 5 """ 6 6 7 from django.conf import settings 8 from django.db.backends import util 7 from django.db.backends import BaseDatabaseWrapper, util 9 8 from django.utils.datastructures import SortedDict 10 9 from django.utils.encoding import smart_str, force_unicode … … 20 19 raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e 21 20 22 23 21 DatabaseError = Database.Error 24 22 IntegrityError = Database.IntegrityError 25 23 26 try: 27 # Only exists in Python 2.4+ 28 from threading import local 29 except ImportError: 30 # Import copy of _thread_local.py from Python 2.4 31 from django.utils._threading_local import local 32 33 class DatabaseWrapper(local): 34 def __init__(self, **kwargs): 35 self.connection = None 36 self.queries = [] 37 self.options = kwargs 38 24 class DatabaseWrapper(BaseDatabaseWrapper): 39 25 def _valid_connection(self): 40 26 return self.connection is not None 41 27 42 def cursor(self):28 def _cursor(self, settings): 43 29 if not self._valid_connection(): 44 30 if len(settings.DATABASE_HOST.strip()) == 0: … … 56 42 cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") 57 43 cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") 58 if settings.DEBUG:59 return util.CursorDebugWrapper(cursor, self)60 44 return cursor 61 62 def _commit(self):63 if self.connection is not None:64 return self.connection.commit()65 66 def _rollback(self):67 if self.connection is not None:68 return self.connection.rollback()69 70 def close(self):71 if self.connection is not None:72 self.connection.close()73 self.connection = None74 45 75 46 allows_group_by_ordinal = False django/trunk/django/db/backends/postgresql/base.py
r5834 r5949 6 6 7 7 from django.utils.encoding import smart_str, smart_unicode 8 from django.db.backends import util8 from django.db.backends import BaseDatabaseWrapper, util 9 9 try: 10 10 import psycopg as Database … … 15 15 DatabaseError = Database.DatabaseError 16 16 IntegrityError = Database.IntegrityError 17 18 try:19 # Only exists in Python 2.4+20 from threading import local21 except ImportError:22 # Import copy of _thread_local.py from Python 2.423 from django.utils._threading_local import local24 17 25 18 class UnicodeCursorWrapper(object): … … 65 58 postgres_version = None 66 59 67 class DatabaseWrapper(local): 68 def __init__(self, **kwargs): 69 self.connection = None 70 self.queries = [] 71 self.options = kwargs 72 73 def cursor(self): 74 from django.conf import settings 60 class DatabaseWrapper(BaseDatabaseWrapper): 61 def _cursor(self, settings): 75 62 set_tz = False 76 63 if self.connection is None: … … 99 86 cursor.execute("SELECT version()") 100 87 postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 101 if settings.DEBUG:102 return util.CursorDebugWrapper(cursor, self)103 88 return cursor 104 105 def _commit(self):106 if self.connection is not None:107 return self.connection.commit()108 109 def _rollback(self):110 if self.connection is not None:111 return self.connection.rollback()112 113 def close(self):114 if self.connection is not None:115 self.connection.close()116 self.connection = None117 89 118 90 allows_group_by_ordinal = True django/trunk/django/db/backends/postgresql_psycopg2/base.py
r5609 r5949 5 5 """ 6 6 7 from django.db.backends import util7 from django.db.backends import BaseDatabaseWrapper, util 8 8 try: 9 9 import psycopg2 as Database … … 16 16 IntegrityError = Database.IntegrityError 17 17 18 try:19 # Only exists in Python 2.4+20 from threading import local21 except ImportError:22 # Import copy of _thread_local.py from Python 2.423 from django.utils._threading_local import local24 25 18 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) 26 19 27 20 postgres_version = None 28 21 29 class DatabaseWrapper(local): 30 def __init__(self, **kwargs): 31 self.connection = None 32 self.queries = [] 33 self.options = kwargs 34 35 def cursor(self): 36 from django.conf import settings 22 class DatabaseWrapper(BaseDatabaseWrapper): 23 def _cursor(self, settings): 37 24 set_tz = False 38 25 if self.connection is None: … … 61 48 cursor.execute("SELECT version()") 62 49 postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 63 if settings.DEBUG:64 return util.CursorDebugWrapper(cursor, self)65 50 return cursor 66 67 def _commit(self):68 if self.connection is not None:69 return self.connection.commit()70 71 def _rollback(self):72 if self.connection is not None:73 return self.connection.rollback()74 75 def close(self):76 if self.connection is not None:77 self.connection.close()78 self.connection = None79 51 80 52 allows_group_by_ordinal = True django/trunk/django/db/backends/sqlite3/base.py
r5609 r5949 3 3 """ 4 4 5 from django.db.backends import util5 from django.db.backends import BaseDatabaseWrapper, util 6 6 try: 7 7 try: … … 35 35 Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal) 36 36 37 try: 38 # Only exists in Python 2.4+ 39 from threading import local 40 except ImportError: 41 # Import copy of _thread_local.py from Python 2.4 42 from django.utils._threading_local import local 43 44 class DatabaseWrapper(local): 45 def __init__(self, **kwargs): 46 self.connection = None 47 self.queries = [] 48 self.options = kwargs 49 50 def cursor(self): 51 from django.conf import settings 37 class DatabaseWrapper(BaseDatabaseWrapper): 38 def _cursor(self, settings): 52 39 if self.connection is None: 53 40 kwargs = { … … 61 48 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 62 49 self.connection.create_function("regexp", 2, _sqlite_regexp) 63 cursor = self.connection.cursor(factory=SQLiteCursorWrapper) 64 if settings.DEBUG: 65 return util.CursorDebugWrapper(cursor, self) 66 else: 67 return cursor 68 69 def _commit(self): 70 if self.connection is not None: 71 self.connection.commit() 72 73 def _rollback(self): 74 if self.connection is not None: 75 self.connection.rollback() 50 return self.connection.cursor(factory=SQLiteCursorWrapper) 76 51 77 52 def close(self): 78 53 from django.conf import settings 79 54 # If database is in memory, closing the connection destroys the 80 # database. To prevent accidental data loss, ignore close requests on55 # database. To prevent accidental data loss, ignore close requests on 81 56 # an in-memory db. 82 if self.connection is not None and settings.DATABASE_NAME != ":memory:": 83 self.connection.close() 84 self.connection = None 57 if settings.DATABASE_NAME != ":memory:": 58 BaseDatabaseWrapper.close(self) 85 59 86 60 class SQLiteCursorWrapper(Database.Cursor):
