Refs #29444 -- Allowed returning multiple fields from INSERT statements on PostgreSQL.

Thanks Florian Apolloner, Tim Graham, Simon Charette, Nick Pope, and
Mariusz Felisiak for reviews.
This commit is contained in:
Johannes Hoppe 2019-07-24 08:42:41 +02:00 committed by Mariusz Felisiak
parent 736e7d44de
commit 7254f1138d
16 changed files with 209 additions and 89 deletions

View file

@ -1,4 +1,3 @@
import datetime
import unittest
from django.db import connection
@ -6,7 +5,7 @@ from django.db.models.fields import BooleanField, NullBooleanField
from django.db.utils import DatabaseError
from django.test import TransactionTestCase
from ..models import NonIntegerAutoField, Square
from ..models import Square
@unittest.skipUnless(connection.vendor == 'oracle', 'Oracle tests')
@ -96,23 +95,3 @@ class TransactionalTests(TransactionTestCase):
self.assertIn('ORA-01017', context.exception.args[0].message)
finally:
connection.settings_dict['PASSWORD'] = old_password
def test_non_integer_auto_field(self):
with connection.cursor() as cursor:
# Create trigger that fill non-integer auto field.
cursor.execute("""
CREATE OR REPLACE TRIGGER "TRG_FILL_CREATION_DATETIME"
BEFORE INSERT ON "BACKENDS_NONINTEGERAUTOFIELD"
FOR EACH ROW
BEGIN
:NEW.CREATION_DATETIME := SYSTIMESTAMP;
END;
""")
try:
NonIntegerAutoField._meta.auto_field = NonIntegerAutoField.creation_datetime
obj = NonIntegerAutoField.objects.create()
self.assertIsNotNone(obj.creation_datetime)
self.assertIsInstance(obj.creation_datetime, datetime.datetime)
finally:
with connection.cursor() as cursor:
cursor.execute('DROP TRIGGER "TRG_FILL_CREATION_DATETIME"')