Commits

adamv  committed 5092ca7

Revert aggregates test; add empty strings to query as literals (similar to how NULL is handled) to avoid type errors; added test for issue 62.

  • Participants
  • Parent commits a061dfb

Comments (0)

Files changed (3)

File source/sqlserver_ado/dbapi.py

             if value is None:
                 parameter_replacements.append('NULL')
                 continue
+                
+            if isinstance(value, basestring) and value == "":
+                parameter_replacements.append("''")
+                continue
 
-            # Otherwise, process the non-NULL parameter.
+            # Otherwise, process the non-NULL, non-empty string parameter.
             parameter_replacements.append('?')
             try:
                 p = self.cmd.CreateParameter('p%i' % i, _ado_type(value))

File tests/test_main/aggregates/models.py

     >>> GamerCard(player=p1).save()
     >>> GamerCard(player=p2).save()
     
-    >>> Bet(player=p1, amount="100.00", won="50.00").save()
-    >>> Bet(player=p1, amount="200.00", won="50.00").save()
-    >>> Bet(player=p1, amount="300.00", won="50.00").save()
-    >>> Bet(player=p1, amount="400.00", won="50.00").save()
-    >>> Bet(player=p1, amount="500.00", won="50.00").save()
+    >>> Bet(player=p1, amount="100.00").save()
+    >>> Bet(player=p1, amount="200.00").save()
+    >>> Bet(player=p1, amount="300.00").save()
+    >>> Bet(player=p1, amount="400.00").save()
+    >>> Bet(player=p1, amount="500.00").save()
     
-    >>> Bet(player=p2, amount="1000.00", won="50.00").save()
-    >>> Bet(player=p2, amount="2000.00", won="50.00").save()
-    >>> Bet(player=p2, amount="3000.00", won="50.00").save()
-    >>> Bet(player=p2, amount="4000.00", won="50.00").save()
-    >>> Bet(player=p2, amount="5000.00", won="50.00").save()
+    >>> Bet(player=p2, amount="1000.00").save()
+    >>> Bet(player=p2, amount="2000.00").save()
+    >>> Bet(player=p2, amount="3000.00").save()
+    >>> Bet(player=p2, amount="4000.00").save()
+    >>> Bet(player=p2, amount="5000.00").save()
     
     >>> p = Player.objects.annotate(Count('bet'), avg_bet=Avg('bet__amount')).order_by('name')
     
     >>> p[1].avg_bet
     3000
     
-    >>> g = GamerCard.objects.annotate(bets=Sum('player__bet__amount'), winnings=Sum('player__bet__won')).order_by('name')
-    >>> g = g.extra(select={'net_result': 'winnings-bets'})
-    >>> g = list(g)[0]
-    >>> g.bets
-    1500
-    >>> g.winnings
-    250
-    >>> g.net_result
-    -1250
+    >>> p = Player.objects.annotate(bets=Count('bet'), avg_bet=Avg('bet__amount')).values()
     """
     player = models.ForeignKey(Player)
     amount = models.DecimalField(max_digits=10, decimal_places=2)
-    won = models.DecimalField(max_digits=10, decimal_places=2)

File tests/test_main/regressiontests/models.py

     """
 
     a = models.IntegerField()
+    
+class Bug62Table(models.Model):
+    email = models.CharField(max_length=255, blank=True)
+
+class Bug62TestCase(TestCase):
+    def testExclude(self):
+        Bug62Table(email='').save()
+        Bug62Table(email='abc').save()
+        Bug62Table(email='').save()
+        Bug62Table(email='def').save()
+        
+        q = list(Bug62Table.objects.exclude(email='abc'))
+        self.assertEqual(len(q), 3)
+
+    def testExcludeEmpty(self):
+        Bug62Table(email='').save()
+        Bug62Table(email='abc').save()
+        Bug62Table(email='').save()
+        Bug62Table(email='def').save()
+
+        q = list(Bug62Table.objects.exclude(email=''))
+        self.assertEqual(len(q), 2)
+
+    def testExcludeEmptyUnicode(self):
+        Bug62Table(email='').save()
+        Bug62Table(email='abc').save()
+        Bug62Table(email='').save()
+        Bug62Table(email='def').save()
+        
+        q = list(Bug62Table.objects.exclude(email=u''))
+        self.assertEqual(len(q), 2)