Changeset 5950
- Timestamp:
- 08/19/07 17:29:57 (1 year ago)
- Files:
-
- django/trunk/django/core/management/sql.py (modified) (2 diffs)
- django/trunk/django/db/backends/ado_mssql/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/dummy/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/__init__.py (modified) (2 diffs)
- django/trunk/django/db/backends/mysql/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/mysql_old/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/oracle/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/postgresql/base.py (modified) (3 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/core/management/sql.py
r5898 r5950 214 214 (list_of_sql, pending_references_dict) 215 215 """ 216 from django.db import backend, models216 from django.db import backend, connection, models 217 217 218 218 opts = model._meta … … 268 268 final_output.append('\n'.join(full_statement)) 269 269 270 if opts.has_auto_field and hasattr(backend, 'get_autoinc_sql'):271 # Add any extra SQL needed to support auto-incrementing primary keys 272 autoinc_sql = backend.get_autoinc_sql(opts.db_table)270 if opts.has_auto_field: 271 # Add any extra SQL needed to support auto-incrementing primary keys. 272 autoinc_sql = connection.ops.autoinc_sql(opts.db_table) 273 273 if autoinc_sql: 274 274 for stmt in autoinc_sql: django/trunk/django/db/backends/ado_mssql/base.py
r5949 r5950 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util 8 8 try: 9 9 import adodbapi as Database … … 49 49 Database.convertVariantToPython = variantToPython 50 50 51 class DatabaseOperations(BaseDatabaseOperations): 52 pass 53 51 54 class DatabaseWrapper(BaseDatabaseWrapper): 55 ops = DatabaseOperations() 56 52 57 def _cursor(self, settings): 53 58 if self.connection is None: … … 131 136 return "ON %s" % quote_name(tablespace) 132 137 133 def get_autoinc_sql(table):134 return None135 136 138 def get_sql_flush(style, tables, sequences): 137 139 """Return a list of SQL statements required to remove all data from django/trunk/django/db/backends/dummy/base.py
r5557 r5950 22 22 pass 23 23 24 class DatabaseWrapper: 24 class DatabaseOperations(object): 25 def __getattr__(self, *args, **kwargs): 26 complain() 27 28 class DatabaseWrapper(object): 29 ops = DatabaseOperations() 25 30 cursor = complain 26 31 _commit = complain … … 51 56 get_max_name_length = ignore 52 57 get_start_transaction_sql = complain 53 get_autoinc_sql = complain54 58 get_sql_flush = complain 55 59 get_sql_sequence_reset = complain django/trunk/django/db/backends/__init__.py
r5949 r5950 7 7 8 8 class BaseDatabaseWrapper(local): 9 """ 10 Represents a database connection. 11 """ 12 ops = None 9 13 def __init__(self, **kwargs): 10 14 self.connection = None … … 35 39 from django.db.backends import util 36 40 return util.CursorDebugWrapper(cursor, self) 41 42 class BaseDatabaseOperations(object): 43 """ 44 This class encapsulates all backend-specific differences, such as the way 45 a backend performs ordering or calculates the ID of a recently-inserted 46 row. 47 """ 48 def autoinc_sql(self, table): 49 """ 50 Returns any SQL needed to support auto-incrementing primary keys, or 51 None if no SQL is necessary. 52 53 This SQL is executed when a table is created. 54 """ 55 return None django/trunk/django/db/backends/mysql/base.py
r5949 r5950 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, 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 class DatabaseOperations(BaseDatabaseOperations): 57 pass 58 56 59 class DatabaseWrapper(BaseDatabaseWrapper): 60 ops = DatabaseOperations() 61 57 62 def __init__(self, **kwargs): 58 63 super(DatabaseWrapper, self).__init__(**kwargs) … … 182 187 return "BEGIN;" 183 188 184 def get_autoinc_sql(table):185 return None186 187 189 def get_sql_flush(style, tables, sequences): 188 190 """Return a list of SQL statements required to remove all data from django/trunk/django/db/backends/mysql_old/base.py
r5949 r5950 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util 8 8 from django.utils.encoding import force_unicode 9 9 try: … … 64 64 return getattr(self.cursor, attr) 65 65 66 class DatabaseOperations(BaseDatabaseOperations): 67 pass 68 66 69 class DatabaseWrapper(BaseDatabaseWrapper): 70 ops = DatabaseOperations() 71 67 72 def __init__(self, **kwargs): 68 73 super(DatabaseWrapper, self).__init__(**kwargs) … … 201 206 return "BEGIN;" 202 207 203 def get_autoinc_sql(table):204 return None205 206 208 def get_sql_flush(style, tables, sequences): 207 209 """Return a list of SQL statements required to remove all data from django/trunk/django/db/backends/oracle/base.py
r5949 r5950 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util 8 8 from django.utils.datastructures import SortedDict 9 9 from django.utils.encoding import smart_str, force_unicode … … 22 22 IntegrityError = Database.IntegrityError 23 23 24 class DatabaseOperations(BaseDatabaseOperations): 25 def autoinc_sql(self, table): 26 # To simulate auto-incrementing primary keys in Oracle, we have to 27 # create a sequence and a trigger. 28 sq_name = get_sequence_name(table) 29 tr_name = get_trigger_name(table) 30 sequence_sql = 'CREATE SEQUENCE %s;' % sq_name 31 trigger_sql = """ 32 CREATE OR REPLACE TRIGGER %s 33 BEFORE INSERT ON %s 34 FOR EACH ROW 35 WHEN (new.id IS NULL) 36 BEGIN 37 SELECT %s.nextval INTO :new.id FROM dual; 38 END;/""" % (tr_name, quote_name(table), sq_name) 39 return sequence_sql, trigger_sql 40 24 41 class DatabaseWrapper(BaseDatabaseWrapper): 42 ops = DatabaseOperations() 43 25 44 def _valid_connection(self): 26 45 return self.connection is not None … … 187 206 def get_tablespace_sql(tablespace, inline=False): 188 207 return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), quote_name(tablespace)) 189 190 def get_autoinc_sql(table):191 # To simulate auto-incrementing primary keys in Oracle, we have to192 # create a sequence and a trigger.193 sq_name = get_sequence_name(table)194 tr_name = get_trigger_name(table)195 sequence_sql = 'CREATE SEQUENCE %s;' % sq_name196 trigger_sql = """CREATE OR REPLACE TRIGGER %s197 BEFORE INSERT ON %s198 FOR EACH ROW199 WHEN (new.id IS NULL)200 BEGIN201 SELECT %s.nextval INTO :new.id FROM dual;202 END;203 /""" % (tr_name, quote_name(table), sq_name)204 return sequence_sql, trigger_sql205 208 206 209 def get_drop_sequence(table): django/trunk/django/db/backends/postgresql/base.py
r5949 r5950 6 6 7 7 from django.utils.encoding import smart_str, smart_unicode 8 from django.db.backends import BaseDatabaseWrapper, util8 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util 9 9 try: 10 10 import psycopg as Database … … 58 58 postgres_version = None 59 59 60 class DatabaseOperations(BaseDatabaseOperations): 61 pass 62 60 63 class DatabaseWrapper(BaseDatabaseWrapper): 64 ops = DatabaseOperations() 65 61 66 def _cursor(self, settings): 62 67 set_tz = False … … 157 162 def get_start_transaction_sql(): 158 163 return "BEGIN;" 159 160 def get_autoinc_sql(table):161 return None162 164 163 165 def get_sql_flush(style, tables, sequences): django/trunk/django/db/backends/postgresql_psycopg2/base.py
r5949 r5950 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util 8 8 try: 9 9 import psycopg2 as Database … … 20 20 postgres_version = None 21 21 22 class DatabaseOperations(BaseDatabaseOperations): 23 pass 24 22 25 class DatabaseWrapper(BaseDatabaseWrapper): 26 ops = DatabaseOperations() 27 23 28 def _cursor(self, settings): 24 29 set_tz = False … … 111 116 def get_start_transaction_sql(): 112 117 return "BEGIN;" 113 114 def get_autoinc_sql(table):115 return None116 118 117 119 def get_sql_flush(style, tables, sequences): django/trunk/django/db/backends/sqlite3/base.py
r5949 r5950 3 3 """ 4 4 5 from django.db.backends import BaseDatabaseWrapper, util5 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util 6 6 try: 7 7 try: … … 35 35 Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal) 36 36 37 class DatabaseOperations(BaseDatabaseOperations): 38 pass 39 37 40 class DatabaseWrapper(BaseDatabaseWrapper): 41 ops = DatabaseOperations() 42 38 43 def _cursor(self, settings): 39 44 if self.connection is None: … … 143 148 def get_start_transaction_sql(): 144 149 return "BEGIN;" 145 146 def get_autoinc_sql(table):147 return None148 150 149 151 def get_sql_flush(style, tables, sequences):
