Ticket #10459: diff.diff
File diff.diff, 18.8 KB (added by , 16 years ago) |
---|
-
django/db/__init__.py
diff --git a/django/db/__init__.py b/django/db/__init__.py index 8025721..250e0a0 100644
a b except ImportError, e: 37 37 raise # If there's some other error, this must be an error in Django itself. 38 38 39 39 # Convenient aliases for backend bits. 40 connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS) 40 connection = backend.DatabaseWrapper({ 41 'DATABASE_HOST': settings.DATABASE_HOST, 42 'DATABASE_NAME': settings.DATABASE_NAME, 43 'DATABASE_OPTIONS': settings.DATABASE_OPTIONS, 44 'DATABASE_PASSWORD': settings.DATABASE_PASSWORD, 45 'DATABASE_PORT': settings.DATABASE_PORT, 46 'DATABASE_USER': settings.DATABASE_USER, 47 }) 41 48 DatabaseError = backend.DatabaseError 42 49 IntegrityError = backend.IntegrityError 43 50 -
django/db/backends/__init__.py
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 187ff6c..1b5f265 100644
a b class BaseDatabaseWrapper(local): 24 24 Represents a database connection. 25 25 """ 26 26 ops = None 27 def __init__(self, **kwargs):27 def __init__(self, settings): 28 28 self.connection = None 29 29 self.queries = [] 30 self. options = kwargs30 self.settings = settings 31 31 32 32 def _commit(self): 33 33 if self.connection is not None: … … class BaseDatabaseWrapper(local): 59 59 60 60 def cursor(self): 61 61 from django.conf import settings 62 cursor = self._cursor( settings)62 cursor = self._cursor() 63 63 if settings.DEBUG: 64 64 return self.make_debug_cursor(cursor) 65 65 return cursor … … class BaseDatabaseClient(object): 497 497 # This should be a string representing the name of the executable 498 498 # (e.g., "psql"). Subclasses must override this. 499 499 executable_name = None 500 501 def __init__(self, connection): 502 self.connection = connection 500 503 501 504 def runshell(self): 502 505 raise NotImplementedError() -
django/db/backends/dummy/base.py
diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py index 530ea9c..a18c609 100644
a b class DatabaseWrapper(object): 46 46 47 47 self.features = BaseDatabaseFeatures() 48 48 self.ops = DatabaseOperations() 49 self.client = DatabaseClient( )49 self.client = DatabaseClient(self) 50 50 self.creation = BaseDatabaseCreation(self) 51 51 self.introspection = DatabaseIntrospection(self) 52 52 self.validation = BaseDatabaseValidation() -
django/db/backends/mysql/base.py
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 00da726..eb6dad1 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 238 238 239 239 self.features = DatabaseFeatures() 240 240 self.ops = DatabaseOperations() 241 self.client = DatabaseClient( )241 self.client = DatabaseClient(self) 242 242 self.creation = DatabaseCreation(self) 243 243 self.introspection = DatabaseIntrospection(self) 244 244 self.validation = DatabaseValidation() … … class DatabaseWrapper(BaseDatabaseWrapper): 253 253 self.connection = None 254 254 return False 255 255 256 def _cursor(self , settings):256 def _cursor(self): 257 257 if not self._valid_connection(): 258 258 kwargs = { 259 259 'conv': django_conversions, 260 260 'charset': 'utf8', 261 261 'use_unicode': True, 262 262 } 263 if se ttings.DATABASE_USER:264 kwargs['user'] = se ttings.DATABASE_USER265 if se ttings.DATABASE_NAME:266 kwargs['db'] = se ttings.DATABASE_NAME267 if se ttings.DATABASE_PASSWORD:268 kwargs['passwd'] = se ttings.DATABASE_PASSWORD269 if se ttings.DATABASE_HOST.startswith('/'):270 kwargs['unix_socket'] = se ttings.DATABASE_HOST271 elif se ttings.DATABASE_HOST:272 kwargs['host'] = se ttings.DATABASE_HOST273 if se ttings.DATABASE_PORT:274 kwargs['port'] = int(se ttings.DATABASE_PORT)275 kwargs.update(self. options)263 if self.settings['DATABASE_USER']: 264 kwargs['user'] = self.settings['DATABASE_USER'] 265 if self.settings['DATABASE_NAME']: 266 kwargs['db'] = self.settings['DATABASE_NAME'] 267 if self.settings['DATABASE_PASSWORD']: 268 kwargs['passwd'] = self.settings['DATABASE_PASSWORD'] 269 if self.settings['DATABASE_HOST'].startswith('/'): 270 kwargs['unix_socket'] = self.settings['DATABASE_HOST'] 271 elif self.settings['DATABASE_HOST']: 272 kwargs['host'] = self.settings['DATABASE_HOST'] 273 if self.settings['DATABASE_PORT']: 274 kwargs['port'] = int(self.settings['DATABASE_PORT']) 275 kwargs.update(self.settings['DATABASE_OPTIONS']) 276 276 self.connection = Database.connect(**kwargs) 277 277 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 278 278 self.connection.encoders[SafeString] = self.connection.encoders[str] -
django/db/backends/mysql/client.py
diff --git a/django/db/backends/mysql/client.py b/django/db/backends/mysql/client.py index 17daca9..d8783e0 100644
a b 1 1 from django.db.backends import BaseDatabaseClient 2 from django.conf import settings3 2 import os 4 3 5 4 class DatabaseClient(BaseDatabaseClient): … … class DatabaseClient(BaseDatabaseClient): 7 6 8 7 def runshell(self): 9 8 args = [''] 10 db = se ttings.DATABASE_OPTIONS.get('db', settings.DATABASE_NAME)11 user = se ttings.DATABASE_OPTIONS.get('user', settings.DATABASE_USER)12 passwd = se ttings.DATABASE_OPTIONS.get('passwd', settings.DATABASE_PASSWORD)13 host = se ttings.DATABASE_OPTIONS.get('host', settings.DATABASE_HOST)14 port = se ttings.DATABASE_OPTIONS.get('port', settings.DATABASE_PORT)15 defaults_file = se ttings.DATABASE_OPTIONS.get('read_default_file')9 db = self.connection.settings['DATABASE_OPTIONS'].get('db', self.connection.settings['DATABASE_NAME']) 10 user = self.connection.settings['DATABASE_OPTIONS'].get('user', self.connection.settings['DATABASE_USER']) 11 passwd = self.connection.settings['DATABASE_OPTIONS'].get('passwd', self.connection.settings['DATABASE_PASSWORD']) 12 host = self.connection.settings['DATABASE_OPTIONS'].get('host', self.connection.settings['DATABASE_HOST']) 13 port = self.connection.settings['DATABASE_OPTIONS'].get('port', self.connection.settings['DATABASE_PORT']) 14 defaults_file = self.connection.settings['DATABASE_OPTIONS'].get('read_default_file') 16 15 # Seems to be no good way to set sql_mode with CLI. 17 16 18 17 if defaults_file: -
django/db/backends/oracle/base.py
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index baa8486..d59804a 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 262 262 263 263 self.features = DatabaseFeatures() 264 264 self.ops = DatabaseOperations() 265 self.client = DatabaseClient( )265 self.client = DatabaseClient(self) 266 266 self.creation = DatabaseCreation(self) 267 267 self.introspection = DatabaseIntrospection(self) 268 268 self.validation = BaseDatabaseValidation() … … class DatabaseWrapper(BaseDatabaseWrapper): 270 270 def _valid_connection(self): 271 271 return self.connection is not None 272 272 273 def _connect_string(self , settings):274 if len(se ttings.DATABASE_HOST.strip()) == 0:275 se ttings.DATABASE_HOST= 'localhost'276 if len(se ttings.DATABASE_PORT.strip()) != 0:277 dsn = Database.makedsn(se ttings.DATABASE_HOST,278 int(se ttings.DATABASE_PORT),279 se ttings.DATABASE_NAME)273 def _connect_string(self): 274 if len(self.settings['DATABASE_HOST'].strip()) == 0: 275 self.settings['DATABASE_HOST'] = 'localhost' 276 if len(self.settings['DATABASE_PORT'].strip()) != 0: 277 dsn = Database.makedsn(self.settings['DATABASE_HOST'], 278 int(self.settings['DATABASE_PORT']), 279 self.settings['DATABASE_NAME']) 280 280 else: 281 dsn = se ttings.DATABASE_NAME282 return "%s/%s@%s" % (se ttings.DATABASE_USER,283 se ttings.DATABASE_PASSWORD, dsn)281 dsn = self.settings['DATABASE_NAME'] 282 return "%s/%s@%s" % (self.settings['DATABASE_USER'], 283 self.settings['DATABASE_PASSWORD'], dsn) 284 284 285 def _cursor(self , settings):285 def _cursor(self): 286 286 cursor = None 287 287 if not self._valid_connection(): 288 conn_string = self._connect_string( settings)289 self.connection = Database.connect(conn_string, **self. options)288 conn_string = self._connect_string() 289 self.connection = Database.connect(conn_string, **self.settings['DATABASE_OPTIONS']) 290 290 cursor = FormatStylePlaceholderCursor(self.connection) 291 291 # Set oracle date to ansi date format. This only needs to execute 292 292 # once when we create a new connection. We also set the Territory -
django/db/backends/oracle/client.py
diff --git a/django/db/backends/oracle/client.py b/django/db/backends/oracle/client.py index c95b810..84193ea 100644
a b 1 1 from django.db.backends import BaseDatabaseClient 2 from django.conf import settings3 2 import os 4 3 5 4 class DatabaseClient(BaseDatabaseClient): 6 5 executable_name = 'sqlplus' 7 6 8 7 def runshell(self): 9 from django.db import connection 10 conn_string = connection._connect_string(settings) 8 conn_string = self.connection._connect_string() 11 9 args = [self.executable_name, "-L", conn_string] 12 10 os.execvp(self.executable_name, args) -
django/db/backends/postgresql/base.py
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index ad271f2..d4fb01b 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 90 90 91 91 self.features = DatabaseFeatures() 92 92 self.ops = DatabaseOperations() 93 self.client = DatabaseClient( )93 self.client = DatabaseClient(self) 94 94 self.creation = DatabaseCreation(self) 95 95 self.introspection = DatabaseIntrospection(self) 96 96 self.validation = BaseDatabaseValidation() 97 97 98 def _cursor(self , settings):98 def _cursor(self): 99 99 set_tz = False 100 100 if self.connection is None: 101 101 set_tz = True 102 if se ttings.DATABASE_NAME== '':102 if self.settings['DATABASE_NAME'] == '': 103 103 from django.core.exceptions import ImproperlyConfigured 104 104 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") 105 conn_string = "dbname=%s" % se ttings.DATABASE_NAME106 if se ttings.DATABASE_USER:107 conn_string = "user=%s %s" % (se ttings.DATABASE_USER, conn_string)108 if se ttings.DATABASE_PASSWORD:109 conn_string += " password='%s'" % se ttings.DATABASE_PASSWORD110 if se ttings.DATABASE_HOST:111 conn_string += " host=%s" % se ttings.DATABASE_HOST112 if se ttings.DATABASE_PORT:113 conn_string += " port=%s" % se ttings.DATABASE_PORT114 self.connection = Database.connect(conn_string, **self. options)105 conn_string = "dbname=%s" % self.settings['DATABASE_NAME'] 106 if self.settings['DATABASE_USER']: 107 conn_string = "user=%s %s" % (self.settings['DATABASE_USER'], conn_string) 108 if self.settings['DATABASE_PASSWORD']: 109 conn_string += " password='%s'" % self.settings['DATABASE_PASSWORD'] 110 if self.settings['DATABASE_HOST']: 111 conn_string += " host=%s" % self.settings['DATABASE_HOST'] 112 if self.settings['DATABASE_PORT']: 113 conn_string += " port=%s" % self.settings['DATABASE_PORT'] 114 self.connection = Database.connect(conn_string, **self.settings['DATABASE_OPTIONS']) 115 115 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 116 116 cursor = self.connection.cursor() 117 117 if set_tz: -
django/db/backends/postgresql/client.py
diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py index 63f28a7..3e51423 100644
a b 1 1 from django.db.backends import BaseDatabaseClient 2 from django.conf import settings3 2 import os 4 3 5 4 class DatabaseClient(BaseDatabaseClient): … … class DatabaseClient(BaseDatabaseClient): 7 6 8 7 def runshell(self): 9 8 args = [self.executable_name] 10 if se ttings.DATABASE_USER:11 args += ["-U", se ttings.DATABASE_USER]12 if se ttings.DATABASE_PASSWORD:9 if self.connection.settings['DATABASE_USER']: 10 args += ["-U", self.connection.settings['DATABASE_USER']] 11 if self.connection.settings['DATABASE_PASSWORD']: 13 12 args += ["-W"] 14 if se ttings.DATABASE_HOST:15 args.extend(["-h", se ttings.DATABASE_HOST])16 if se ttings.DATABASE_PORT:17 args.extend(["-p", str(se ttings.DATABASE_PORT)])18 args += [se ttings.DATABASE_NAME]13 if self.connection.settings['DATABASE_HOST']: 14 args.extend(["-h", self.connection.settings['DATABASE_HOST']]) 15 if self.connection.settings['DATABASE_PORT']: 16 args.extend(["-p", str(self.connection.settings['DATABASE_PORT'])]) 17 args += [self.connection.settings['DATABASE_NAME']] 19 18 os.execvp(self.executable_name, args) -
django/db/backends/postgresql_psycopg2/base.py
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 27de942..76aaf96 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 60 60 61 61 self.features = DatabaseFeatures() 62 62 self.ops = DatabaseOperations() 63 self.client = DatabaseClient( )63 self.client = DatabaseClient(self) 64 64 self.creation = DatabaseCreation(self) 65 65 self.introspection = DatabaseIntrospection(self) 66 66 self.validation = BaseDatabaseValidation() 67 67 68 def _cursor(self , settings):68 def _cursor(self): 69 69 set_tz = False 70 70 if self.connection is None: 71 71 set_tz = True 72 if se ttings.DATABASE_NAME== '':72 if self.settings['DATABASE_NAME'] == '': 73 73 from django.core.exceptions import ImproperlyConfigured 74 74 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") 75 75 conn_params = { 76 'database': se ttings.DATABASE_NAME,76 'database': self.settings['DATABASE_NAME'], 77 77 } 78 conn_params.update(self. options)79 if se ttings.DATABASE_USER:80 conn_params['user'] = se ttings.DATABASE_USER81 if se ttings.DATABASE_PASSWORD:82 conn_params['password'] = se ttings.DATABASE_PASSWORD83 if se ttings.DATABASE_HOST:84 conn_params['host'] = se ttings.DATABASE_HOST85 if se ttings.DATABASE_PORT:86 conn_params['port'] = se ttings.DATABASE_PORT78 conn_params.update(self.settings['DATABASE_OPTIONS']) 79 if self.settings['DATABASE_USER']: 80 conn_params['user'] = self.settings['DATABASE_USER'] 81 if self.settings['DATABASE_PASSWORD']: 82 conn_params['password'] = self.settings['DATABASE_PASSWORD'] 83 if self.settings['DATABASE_HOST']: 84 conn_params['host'] = self.settings['DATABASE_HOST'] 85 if self.settings['DATABASE_PORT']: 86 conn_params['port'] = self.settings['DATABASE_PORT'] 87 87 self.connection = Database.connect(**conn_params) 88 88 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 89 89 self.connection.set_client_encoding('UTF8') -
django/db/backends/sqlite3/base.py
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index ba0ef16..e1f6732 100644
a b class DatabaseWrapper(BaseDatabaseWrapper): 149 149 150 150 self.features = DatabaseFeatures() 151 151 self.ops = DatabaseOperations() 152 self.client = DatabaseClient( )152 self.client = DatabaseClient(self) 153 153 self.creation = DatabaseCreation(self) 154 154 self.introspection = DatabaseIntrospection(self) 155 155 self.validation = BaseDatabaseValidation() 156 156 157 def _cursor(self , settings):157 def _cursor(self): 158 158 if self.connection is None: 159 if not se ttings.DATABASE_NAME:159 if not self.settings['DATABASE_NAME']: 160 160 from django.core.exceptions import ImproperlyConfigured 161 161 raise ImproperlyConfigured, "Please fill out DATABASE_NAME in the settings module before using the database." 162 162 kwargs = { 163 'database': se ttings.DATABASE_NAME,163 'database': self.settings['DATABASE_NAME'], 164 164 'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES, 165 165 } 166 kwargs.update(self. options)166 kwargs.update(self.settings['DATABASE_OPTIONS']) 167 167 self.connection = Database.connect(**kwargs) 168 168 # Register extract, date_trunc, and regexp functions. 169 169 self.connection.create_function("django_extract", 2, _sqlite_extract) … … class DatabaseWrapper(BaseDatabaseWrapper): 172 172 return self.connection.cursor(factory=SQLiteCursorWrapper) 173 173 174 174 def close(self): 175 from django.conf import settings176 175 # If database is in memory, closing the connection destroys the 177 176 # database. To prevent accidental data loss, ignore close requests on 178 177 # an in-memory db. 179 if se ttings.DATABASE_NAME!= ":memory:":178 if self.settings['DATABASE_NAME'] != ":memory:": 180 179 BaseDatabaseWrapper.close(self) 181 180 182 181 class SQLiteCursorWrapper(Database.Cursor): -
django/db/backends/sqlite3/client.py
diff --git a/django/db/backends/sqlite3/client.py b/django/db/backends/sqlite3/client.py index 239e72f..5b40ffb 100644
a b 1 1 from django.db.backends import BaseDatabaseClient 2 from django.conf import settings3 2 import os 4 3 5 4 class DatabaseClient(BaseDatabaseClient): 6 5 executable_name = 'sqlite3' 7 6 8 7 def runshell(self): 9 args = ['', se ttings.DATABASE_NAME]8 args = ['', self.connection.settings['DATABASE_NAME']] 10 9 os.execvp(self.executable_name, args)