diff options
| author | Johannes Hoppe <info@johanneshoppe.com> | 2019-06-10 13:56:50 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-08 08:53:08 +0200 |
| commit | bc91f27a86090b4c688b56cd4e37f95eebe6e969 (patch) | |
| tree | 52d2e64c5e468f1aeb35ea89b244e38f17239aff /tests | |
| parent | 34a88b21dae71a26a9b136b599e5cbcf817eae16 (diff) | |
Refs #29444 -- Added support for fetching a returned non-integer insert values on Oracle.
This is currently not actively used, since the ORM will ask the
SQL compiler to only return auto fields.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/models.py | 4 | ||||
| -rw-r--r-- | tests/backends/oracle/tests.py | 23 |
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/backends/models.py b/tests/backends/models.py index 1fa8d44e63..a2c8616cc6 100644 --- a/tests/backends/models.py +++ b/tests/backends/models.py @@ -5,6 +5,10 @@ from django.contrib.contenttypes.models import ContentType from django.db import models +class NonIntegerAutoField(models.Model): + creation_datetime = models.DateTimeField(primary_key=True) + + class Square(models.Model): root = models.IntegerField() square = models.PositiveIntegerField() diff --git a/tests/backends/oracle/tests.py b/tests/backends/oracle/tests.py index a0d49854d9..30d981da69 100644 --- a/tests/backends/oracle/tests.py +++ b/tests/backends/oracle/tests.py @@ -1,3 +1,4 @@ +import datetime import unittest from django.db import connection @@ -5,7 +6,7 @@ from django.db.models.fields import BooleanField, NullBooleanField from django.db.utils import DatabaseError from django.test import TransactionTestCase -from ..models import Square +from ..models import NonIntegerAutoField, Square @unittest.skipUnless(connection.vendor == 'oracle', 'Oracle tests') @@ -95,3 +96,23 @@ 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"') |
