Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

boulder-oracle-sprint: Fixed #4093 and added tests that cover it and …

…the tricky datetime

fields.


git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5046 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4230f0c936dab3eb5eabdf96e3a2f24d4213a326 1 parent 557a0d4
authored April 20, 2007
6  django/db/backends/oracle/base.py
@@ -454,7 +454,8 @@ def _get_sql_clause(self, get_full_query=False):
454 454
                 return select, " ".join(sql), params
455 455
 
456 456
         def resolve_columns(self, row, fields=()):
457  
-            from django.db.models.fields import DateField, DateTimeField, TimeField
  457
+            from django.db.models.fields import DateField, DateTimeField, \
  458
+                TimeField, BooleanField, NullBooleanField
458 459
             values = []
459 460
             for value, field in map(None, row, fields):
460 461
                 if isinstance(value, Database.LOB):
@@ -464,6 +465,9 @@ def resolve_columns(self, row, fields=()):
464 465
                 # where we undo that treachery.
465 466
                 if value == ' ':
466 467
                     value = ''
  468
+                # Convert 1 or 0 to True or False
  469
+                elif value in (1, 0) and isinstance(field, (BooleanField, NullBooleanField)):
  470
+                    value = bool(value)
467 471
                 # cx_Oracle always returns datetime.datetime objects for
468 472
                 # DATE and TIMESTAMP columns, but Django wants to see a
469 473
                 # python datetime.date, .time, or .datetime.  We use the type
1  django/db/models/fields/__init__.py
@@ -537,6 +537,7 @@ def get_db_prep_save(self, value):
537 537
             # neither database supports microseconds.
538 538
             if settings.DATABASE_ENGINE in ('mysql', 'oracle') and hasattr(value, 'microsecond'):
539 539
                 value = value.replace(microsecond=0)
  540
+            value = str(value)
540 541
         return Field.get_db_prep_save(self, value)
541 542
 
542 543
     def get_db_prep_lookup(self, lookup_type, value):
0  tests/modeltests/datatypes/__init__.py
No changes.
60  tests/modeltests/datatypes/models.py
... ...
@@ -0,0 +1,60 @@
  1
+"""
  2
+1. Simple data types testing.
  3
+
  4
+This is a basic model to test saving and loading boolean and date-related
  5
+types, which in the past were problematic for some database backends.
  6
+"""
  7
+
  8
+from django.db import models
  9
+
  10
+class Donut(models.Model):
  11
+    name = models.CharField(maxlength=100)
  12
+    is_frosted = models.BooleanField(default=False)
  13
+    has_sprinkles = models.NullBooleanField()
  14
+    baked_date = models.DateField(null=True)
  15
+    baked_time = models.TimeField(null=True)
  16
+    consumed_at = models.DateTimeField(null=True)
  17
+
  18
+    class Meta:
  19
+        ordering = ('consumed_at',)
  20
+
  21
+    def __str__(self):
  22
+        return self.name
  23
+
  24
+__test__ = {'API_TESTS': """
  25
+# No donuts are in the system yet.
  26
+>>> Donut.objects.all()
  27
+[]
  28
+
  29
+>>> d = Donut(name='Apple Fritter')
  30
+
  31
+# Ensure we're getting True and False, not 0 and 1
  32
+>>> d.is_frosted
  33
+False
  34
+>>> d.has_sprinkles
  35
+>>> d.has_sprinkles = True
  36
+>>> d.has_sprinkles
  37
+True
  38
+>>> d.save()
  39
+>>> d2 = Donut.objects.all()[0]
  40
+>>> d2
  41
+<Donut: Apple Fritter>
  42
+>>> d2.is_frosted
  43
+False
  44
+>>> d2.has_sprinkles
  45
+True
  46
+
  47
+>>> import datetime
  48
+>>> d2.baked_date = datetime.date(year=1938, month=6, day=4)
  49
+>>> d2.baked_time = datetime.time(hour=5, minute=30)
  50
+>>> d2.consumed_at = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
  51
+>>> d2.save()
  52
+
  53
+>>> d3 = Donut.objects.all()[0]
  54
+>>> d3.baked_date
  55
+datetime.date(1938, 6, 4)
  56
+>>> d3.baked_time
  57
+datetime.time(5, 30)
  58
+>>> d3.consumed_at
  59
+datetime.datetime(2007, 4, 20, 16, 19, 59)
  60
+"""}

0 notes on commit 4230f0c

Please sign in to comment.
Something went wrong with that request. Please try again.