=== modified file 'django/db/backends/__init__.py'
|
|
|
|
| | 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 | |
| | 9 | class BaseDatabaseWrapper(local): |
| | 10 | |
| | 11 | def __init__(self, **kwargs): |
| | 12 | self.connection = None |
| | 13 | self.queries = [] |
| | 14 | self.options = kwargs |
| | 15 | |
| | 16 | def _commit(self): |
| | 17 | if self.connection is not None: |
| | 18 | return self.connection.commit() |
| | 19 | |
| | 20 | def _rollback(self): |
| | 21 | if self.connection is not None: |
| | 22 | return self.connection.rollback() |
| | 23 | |
| | 24 | def close(self): |
| | 25 | if self.connection is not None: |
| | 26 | self.connection.close() |
| | 27 | self.connection = None |
| | 28 | |
| | 29 | def cursor(self): |
| | 30 | from django.conf import settings |
| | 31 | cursor = self._cursor(settings) |
| | 32 | if settings.DEBUG: |
| | 33 | return self.make_debug_cursor(cursor) |
| | 34 | return cursor |
| | 35 | |
| | 36 | def make_debug_cursor(self, cursor): |
| | 37 | from django.db.backends import util |
| | 38 | return util.CursorDebugWrapper(cursor, self) |
=== modified file 'django/db/backends/ado_mssql/base.py'
|
|
|
|
| 48 | 48 | return res |
| 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 | from django.db.backends import BaseDatabaseWrapper |
| | 52 | |
| | 53 | class DatabaseWrapper(BaseDatabaseWrapper): |
| | 54 | |
| | 55 | def _cursor(self, settings): |
| 65 | 56 | if self.connection is None: |
| 66 | 57 | if settings.DATABASE_NAME == '' or settings.DATABASE_USER == '': |
| 67 | 58 | from django.core.exceptions import ImproperlyConfigured |
| … |
… |
|
| 71 | 62 | # TODO: Handle DATABASE_PORT. |
| 72 | 63 | 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 | 64 | 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 |
| | 65 | return self.connection.cursor() |
| | 66 | |
| 91 | 67 | |
| 92 | 68 | allows_group_by_ordinal = True |
| 93 | 69 | allows_unique_and_pk = True |
=== modified file 'django/db/backends/mysql/base.py'
|
|
|
|
| 53 | 53 | # standard util.CursorDebugWrapper can be used. Also, using sql_mode |
| 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 | |
| | 57 | from django.db.backends import BaseDatabaseWrapper |
| | 58 | |
| | 59 | class DatabaseWrapper(BaseDatabaseWrapper): |
| | 60 | |
| 64 | 61 | def __init__(self, **kwargs): |
| 65 | | self.connection = None |
| 66 | | self.queries = [] |
| | 62 | super(DatabaseWrapper, self).__init__(**kwargs) |
| 67 | 63 | self.server_version = None |
| 68 | | self.options = kwargs |
| 69 | 64 | |
| 70 | 65 | def _valid_connection(self): |
| 71 | 66 | if self.connection is not None: |
| … |
… |
|
| 77 | 72 | self.connection = None |
| 78 | 73 | return False |
| 79 | 74 | |
| 80 | | def cursor(self): |
| 81 | | from django.conf import settings |
| | 75 | def _cursor(self, settings): |
| 82 | 76 | from warnings import filterwarnings |
| 83 | 77 | if not self._valid_connection(): |
| 84 | 78 | kwargs = { |
| … |
… |
|
| 100 | 94 | kwargs['port'] = int(settings.DATABASE_PORT) |
| 101 | 95 | kwargs.update(self.options) |
| 102 | 96 | self.connection = Database.connect(**kwargs) |
| 103 | | cursor = self.connection.cursor() |
| 104 | | else: |
| 105 | | cursor = self.connection.cursor() |
| | 97 | cursor = self.connection.cursor() |
| 106 | 98 | if settings.DEBUG: |
| 107 | 99 | filterwarnings("error", category=Database.Warning) |
| 108 | | return util.CursorDebugWrapper(cursor, self) |
| 109 | 100 | return cursor |
| 110 | 101 | |
| 111 | | def _commit(self): |
| 112 | | if self.connection is not None: |
| 113 | | self.connection.commit() |
| 114 | | |
| 115 | 102 | 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 |
| | 103 | try: |
| | 104 | BaseDatabaseWrapper._rollback(self) |
| | 105 | except Database.NotSupportedError: |
| | 106 | pass |
| 126 | 107 | |
| 127 | 108 | def get_server_version(self): |
| 128 | 109 | if not self.server_version: |
=== modified file 'django/db/backends/mysql_old/base.py'
|
|
|
|
| 63 | 63 | else: |
| 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 |
| | 66 | from django.db.backends import BaseDatabaseWrapper |
| 72 | 67 | |
| 73 | | class DatabaseWrapper(local): |
| | 68 | class DatabaseWrapper(BaseDatabaseWrapper): |
| 74 | 69 | def __init__(self, **kwargs): |
| 75 | | self.connection = None |
| 76 | | self.queries = [] |
| | 70 | super(DatabaseWrapper, self).__init__(**kwargs) |
| 77 | 71 | self.server_version = None |
| 78 | | self.options = kwargs |
| 79 | 72 | |
| 80 | 73 | def _valid_connection(self): |
| 81 | 74 | if self.connection is not None: |
| … |
… |
|
| 87 | 80 | self.connection = None |
| 88 | 81 | return False |
| 89 | 82 | |
| 90 | | def cursor(self): |
| 91 | | from django.conf import settings |
| | 83 | def _cursor(self, settings): |
| 92 | 84 | if not self._valid_connection(): |
| 93 | 85 | kwargs = { |
| 94 | 86 | # Note: use_unicode intentonally not set to work around some |
| … |
… |
|
| 119 | 111 | self.connection.set_character_set('utf8') |
| 120 | 112 | else: |
| 121 | 113 | cursor = self.connection.cursor() |
| 122 | | if settings.DEBUG: |
| 123 | | return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self) |
| | 114 | |
| 124 | 115 | return cursor |
| 125 | 116 | |
| 126 | | def _commit(self): |
| 127 | | if self.connection is not None: |
| 128 | | self.connection.commit() |
| | 117 | def make_debug_cursor(self, cursor): |
| | 118 | return BaseDatabaseWrapper.make_debug_cursor(self, MysqlDebugWrapper(cursor)) |
| 129 | 119 | |
| 130 | 120 | 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 |
| | 121 | try: |
| | 122 | BaseDatabaseWrapper._rollback(self) |
| | 123 | except Database.NotSupportedError: |
| | 124 | pass |
| 141 | 125 | |
| 142 | 126 | def get_server_version(self): |
| 143 | 127 | if not self.server_version: |
=== modified file 'django/db/backends/oracle/base.py'
|
|
|
|
| 23 | 23 | DatabaseError = Database.Error |
| 24 | 24 | IntegrityError = Database.IntegrityError |
| 25 | 25 | |
| 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 |
| | 26 | from django.db.backends import BaseDatabaseWrapper |
| 32 | 27 | |
| 33 | | class DatabaseWrapper(local): |
| 34 | | def __init__(self, **kwargs): |
| 35 | | self.connection = None |
| 36 | | self.queries = [] |
| 37 | | self.options = kwargs |
| | 28 | class DatabaseWrapper(BaseDatabaseWrapper): |
| 38 | 29 | |
| 39 | 30 | def _valid_connection(self): |
| 40 | 31 | return self.connection is not None |
| 41 | 32 | |
| 42 | | def cursor(self): |
| | 33 | def _cursor(self, settings): |
| 43 | 34 | if not self._valid_connection(): |
| 44 | 35 | if len(settings.DATABASE_HOST.strip()) == 0: |
| 45 | 36 | settings.DATABASE_HOST = 'localhost' |
| … |
… |
|
| 55 | 46 | # Set oracle date to ansi date format. |
| 56 | 47 | cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") |
| 57 | 48 | 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 | 49 | return cursor |
| 61 | 50 | |
| 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 = None |
| 74 | 51 | |
| 75 | 52 | allows_group_by_ordinal = False |
| 76 | 53 | allows_unique_and_pk = False # Suppress UNIQUE/PK for Oracle (ORA-02259) |
=== modified file 'django/db/backends/postgresql/base.py'
|
|
|
|
| 15 | 15 | DatabaseError = Database.DatabaseError |
| 16 | 16 | IntegrityError = Database.IntegrityError |
| 17 | 17 | |
| 18 | | try: |
| 19 | | # Only exists in Python 2.4+ |
| 20 | | from threading import local |
| 21 | | except ImportError: |
| 22 | | # Import copy of _thread_local.py from Python 2.4 |
| 23 | | from django.utils._threading_local import local |
| | 18 | from django.db.backends import BaseDatabaseWrapper |
| 24 | 19 | |
| 25 | 20 | class UnicodeCursorWrapper(object): |
| 26 | 21 | """ |
| … |
… |
|
| 64 | 59 | |
| 65 | 60 | postgres_version = None |
| 66 | 61 | |
| 67 | | class DatabaseWrapper(local): |
| 68 | | def __init__(self, **kwargs): |
| 69 | | self.connection = None |
| 70 | | self.queries = [] |
| 71 | | self.options = kwargs |
| | 62 | class DatabaseWrapper(BaseDatabaseWrapper): |
| 72 | 63 | |
| 73 | | def cursor(self): |
| 74 | | from django.conf import settings |
| | 64 | def _cursor(self, settings): |
| 75 | 65 | set_tz = False |
| 76 | 66 | if self.connection is None: |
| 77 | 67 | set_tz = True |
| … |
… |
|
| 98 | 88 | if not postgres_version: |
| 99 | 89 | cursor.execute("SELECT version()") |
| 100 | 90 | postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] |
| 101 | | if settings.DEBUG: |
| 102 | | return util.CursorDebugWrapper(cursor, self) |
| 103 | 91 | return cursor |
| 104 | 92 | |
| 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 = None |
| 117 | | |
| 118 | 93 | allows_group_by_ordinal = True |
| 119 | 94 | allows_unique_and_pk = True |
| 120 | 95 | autoindexes_primary_keys = True |
=== modified file 'django/db/backends/postgresql_psycopg2/base.py'
|
|
|
|
| 5 | 5 | """ |
| 6 | 6 | |
| 7 | 7 | from django.db.backends import util |
| | 8 | from django.db.backends import BaseDatabaseWrapper |
| | 9 | |
| 8 | 10 | try: |
| 9 | 11 | import psycopg2 as Database |
| 10 | 12 | import psycopg2.extensions |
| … |
… |
|
| 15 | 17 | DatabaseError = Database.DatabaseError |
| 16 | 18 | IntegrityError = Database.IntegrityError |
| 17 | 19 | |
| 18 | | try: |
| 19 | | # Only exists in Python 2.4+ |
| 20 | | from threading import local |
| 21 | | except ImportError: |
| 22 | | # Import copy of _thread_local.py from Python 2.4 |
| 23 | | from django.utils._threading_local import local |
| 24 | | |
| 25 | 20 | psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) |
| 26 | 21 | |
| 27 | 22 | postgres_version = None |
| 28 | 23 | |
| 29 | | class DatabaseWrapper(local): |
| 30 | | def __init__(self, **kwargs): |
| 31 | | self.connection = None |
| 32 | | self.queries = [] |
| 33 | | self.options = kwargs |
| | 24 | class DatabaseWrapper(BaseDatabaseWrapper): |
| 34 | 25 | |
| 35 | | def cursor(self): |
| 36 | | from django.conf import settings |
| | 26 | def _cursor(self, settings): |
| 37 | 27 | set_tz = False |
| 38 | 28 | if self.connection is None: |
| 39 | 29 | set_tz = True |
| … |
… |
|
| 60 | 50 | if not postgres_version: |
| 61 | 51 | cursor.execute("SELECT version()") |
| 62 | 52 | postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] |
| 63 | | if settings.DEBUG: |
| 64 | | return util.CursorDebugWrapper(cursor, self) |
| 65 | 53 | return cursor |
| 66 | 54 | |
| 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 = None |
| 79 | 55 | |
| 80 | 56 | allows_group_by_ordinal = True |
| 81 | 57 | allows_unique_and_pk = True |
=== modified file 'django/db/backends/sqlite3/base.py'
|
|
|
|
| 34 | 34 | Database.register_converter("decimal", util.typecast_decimal) |
| 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 | from django.db.backends import BaseDatabaseWrapper |
| | 38 | |
| | 39 | class DatabaseWrapper(BaseDatabaseWrapper): |
| | 40 | |
| | 41 | def _cursor(self, settings): |
| 52 | 42 | if self.connection is None: |
| 53 | 43 | kwargs = { |
| 54 | 44 | 'database': settings.DATABASE_NAME, |
| … |
… |
|
| 60 | 50 | self.connection.create_function("django_extract", 2, _sqlite_extract) |
| 61 | 51 | self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) |
| 62 | 52 | 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() |
| | 53 | return self.connection.cursor(factory=SQLiteCursorWrapper) |
| 76 | 54 | |
| 77 | 55 | def close(self): |
| 78 | 56 | from django.conf import settings |
| 79 | 57 | # If database is in memory, closing the connection destroys the |
| 80 | 58 | # database. To prevent accidental data loss, ignore close requests on |
| 81 | 59 | # an in-memory db. |
| 82 | | if self.connection is not None and settings.DATABASE_NAME != ":memory:": |
| 83 | | self.connection.close() |
| 84 | | self.connection = None |
| | 60 | if settings.DATABASE_NAME != ':memory:': |
| | 61 | BaseDatabaseWrapper.close(self) |
| | 62 | |
| 85 | 63 | |
| 86 | 64 | class SQLiteCursorWrapper(Database.Cursor): |
| 87 | 65 | """ |