Ticket #1946: source-patch

File source-patch, 4.3 KB (added by hanne.moa@…, 17 years ago)

Custom sequence-name patch for trunk (v7156)

Line 
1diff -rduP -x .svn -x '*.pyc' django-trunk/django/db/backends/ado_mssql/base.py django-new/django/db/backends/ado_mssql/base.py
2--- django-trunk/django/db/backends/ado_mssql/base.py 2008-02-26 15:22:14.000000000 +0100
3+++ django-new/django/db/backends/ado_mssql/base.py 2008-02-26 15:04:52.000000000 +0100
4@@ -66,7 +66,9 @@
5 def deferrable_sql(self):
6 return " DEFERRABLE INITIALLY DEFERRED"
7
8- def last_insert_id(self, cursor, table_name, pk_name):
9+ # FIXME: seq_name might be a useful thing to add to backends other
10+ # than PostgreSQL
11+ def last_insert_id(self, cursor, table_name, pk_name, seq_name):
12 cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name))
13 return cursor.fetchone()[0]
14
15diff -rduP -x .svn -x '*.pyc' django-trunk/django/db/backends/__init__.py django-new/django/db/backends/__init__.py
16--- django-trunk/django/db/backends/__init__.py 2008-02-26 15:22:14.000000000 +0100
17+++ django-new/django/db/backends/__init__.py 2008-02-26 15:11:26.000000000 +0100
18@@ -149,7 +149,9 @@
19
20 return smart_unicode(sql) % u_params
21
22- def last_insert_id(self, cursor, table_name, pk_name):
23+ # FIXME: seq_name might be a useful thing to add to backends other
24+ # than PostgreSQL
25+ def last_insert_id(self, cursor, table_name, pk_name, seq_name):
26 """
27 Given a cursor object that has just performed an INSERT statement into
28 a table that has an auto-incrementing ID, returns the newly created ID.
29diff -rduP -x .svn -x '*.pyc' django-trunk/django/db/backends/postgresql/operations.py django-new/django/db/backends/postgresql/operations.py
30--- django-trunk/django/db/backends/postgresql/operations.py 2008-02-26 15:22:14.000000000 +0100
31+++ django-new/django/db/backends/postgresql/operations.py 2008-02-26 15:08:46.000000000 +0100
32@@ -32,8 +32,10 @@
33 return 'CAST(%s AS TEXT)'
34 return '%s'
35
36- def last_insert_id(self, cursor, table_name, pk_name):
37- cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
38+ def last_insert_id(self, cursor, table_name, pk_name, seq_name):
39+ if seq_name is None:
40+ seq_name = "%s_%s_seq" % (table_name, pk_name)
41+ cursor.execute("SELECT CURRVAL('\"%s\"')" % seq_name)
42 return cursor.fetchone()[0]
43
44 def quote_name(self, name):
45diff -rduP -x .svn -x '*.pyc' django-trunk/django/db/models/base.py django-new/django/db/models/base.py
46--- django-trunk/django/db/models/base.py 2008-02-26 15:22:14.000000000 +0100
47+++ django-new/django/db/models/base.py 2008-02-26 15:17:19.000000000 +0100
48@@ -268,7 +268,7 @@
49 (qn(self._meta.db_table), qn(self._meta.pk.column),
50 connection.ops.pk_default_value()))
51 if self._meta.has_auto_field and not pk_set:
52- setattr(self, self._meta.pk.attname, connection.ops.last_insert_id(cursor, self._meta.db_table, self._meta.pk.column))
53+ setattr(self, self._meta.pk.attname, connection.ops.last_insert_id(cursor, self._meta.db_table, self._meta.pk.column, self._meta.pk.seq_name))
54 transaction.commit_unless_managed()
55
56 # Run any post-save hooks.
57diff -rduP -x .svn -x '*.pyc' django-trunk/django/db/models/fields/__init__.py django-new/django/db/models/fields/__init__.py
58--- django-trunk/django/db/models/fields/__init__.py 2008-02-26 15:22:14.000000000 +0100
59+++ django-new/django/db/models/fields/__init__.py 2008-02-26 15:19:27.000000000 +0100
60@@ -83,7 +83,7 @@
61 core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True,
62 prepopulate_from=None, unique_for_date=None, unique_for_month=None,
63 unique_for_year=None, validator_list=None, choices=None, radio_admin=None,
64- help_text='', db_column=None, db_tablespace=None):
65+ help_text='', db_column=None, db_tablespace=None, seq_name=None):
66 self.name = name
67 self.verbose_name = verbose_name
68 self.primary_key = primary_key
69@@ -105,6 +105,7 @@
70 self.help_text = help_text
71 self.db_column = db_column
72 self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
73+ self.seq_name = seq_name
74
75 # Set db_index to True if the field has a relationship and doesn't explicitly set db_index.
76 self.db_index = db_index
Back to Top