From aaf87602272c768d4d50d5e9a27f06f4b19164dd Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 19 Aug 2007 23:59:06 +0000 Subject: [PATCH] Refactored get_pk_default_value() to DatabaseOperations.pk_default_value(). Refs #5106 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5961 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/__init__.py | 7 +++++++ django/db/backends/ado_mssql/base.py | 3 --- django/db/backends/dummy/base.py | 1 - django/db/backends/mysql/base.py | 3 --- django/db/backends/mysql_old/base.py | 3 --- django/db/backends/oracle/base.py | 3 --- django/db/backends/postgresql/base.py | 3 --- django/db/backends/postgresql_psycopg2/base.py | 3 --- django/db/backends/sqlite3/base.py | 6 +++--- django/db/models/base.py | 2 +- 10 files changed, 11 insertions(+), 23 deletions(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 5df24eb3c8..fb38c125b7 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -126,3 +126,10 @@ class BaseDatabaseOperations(object): is no limit. """ return None + + def pk_default_value(self): + """ + Returns the value to use during an INSERT statement to specify that + the field should use its default value. + """ + return 'DEFAULT' diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py index f42bc7e2af..3b4ffeb44f 100644 --- a/django/db/backends/ado_mssql/base.py +++ b/django/db/backends/ado_mssql/base.py @@ -103,9 +103,6 @@ dictfetchall = util.dictfetchall def get_random_function_sql(): return "RAND()" -def get_pk_default_value(): - return "DEFAULT" - def get_start_transaction_sql(): return "BEGIN;" diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py index 1cee9687f7..114042a701 100644 --- a/django/db/backends/dummy/base.py +++ b/django/db/backends/dummy/base.py @@ -44,7 +44,6 @@ dictfetchone = complain dictfetchmany = complain dictfetchall = complain get_random_function_sql = complain -get_pk_default_value = complain get_start_transaction_sql = complain get_sql_flush = complain get_sql_sequence_reset = complain diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 545ae3dcdf..9daf0e1c0b 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -165,9 +165,6 @@ dictfetchall = util.dictfetchall def get_random_function_sql(): return "RAND()" -def get_pk_default_value(): - return "DEFAULT" - def get_start_transaction_sql(): return "BEGIN;" diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index f445dcb8d6..dee70db41c 100644 --- a/django/db/backends/mysql_old/base.py +++ b/django/db/backends/mysql_old/base.py @@ -184,9 +184,6 @@ dictfetchall = util.dictfetchall def get_random_function_sql(): return "RAND()" -def get_pk_default_value(): - return "DEFAULT" - def get_start_transaction_sql(): return "BEGIN;" diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 9908518d47..133f587cce 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -189,9 +189,6 @@ def get_field_cast_sql(db_type): def get_random_function_sql(): return "DBMS_RANDOM.RANDOM" -def get_pk_default_value(): - return "DEFAULT" - def get_start_transaction_sql(): return None diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 9193e532c8..fee127ec90 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -134,9 +134,6 @@ def dictfetchall(cursor): def get_random_function_sql(): return "RANDOM()" -def get_pk_default_value(): - return "DEFAULT" - def get_start_transaction_sql(): return "BEGIN;" diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index b1611c5848..964d2688ec 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -88,9 +88,6 @@ dictfetchall = util.dictfetchall def get_random_function_sql(): return "RANDOM()" -def get_pk_default_value(): - return "DEFAULT" - def get_start_transaction_sql(): return "BEGIN;" diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index ad792e1fa0..f17eb9686f 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -48,6 +48,9 @@ class DatabaseOperations(BaseDatabaseOperations): def drop_foreignkey_sql(self): return "" + def pk_default_value(self): + return 'NULL' + class DatabaseWrapper(BaseDatabaseWrapper): ops = DatabaseOperations() @@ -118,9 +121,6 @@ def _sqlite_extract(lookup_type, dt): def get_random_function_sql(): return "RANDOM()" -def get_pk_default_value(): - return "NULL" - def get_start_transaction_sql(): return "BEGIN;" diff --git a/django/db/models/base.py b/django/db/models/base.py index 3ae3c26fb3..d328bda31e 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -252,7 +252,7 @@ class Model(object): cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), - backend.get_pk_default_value())) + connection.ops.pk_default_value())) if self._meta.has_auto_field and not pk_set: setattr(self, self._meta.pk.attname, connection.ops.last_insert_id(cursor, self._meta.db_table, self._meta.pk.column)) transaction.commit_unless_managed()