Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 64

Show
Ignore:
Timestamp:
02/26/05 02:25:43
Author:
fumanchu
Message:

db.SM.distinct() now falls back to slow method if imperfect (and warns if so).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/storage/db.py

    r63 r64  
    10531053            # ^%$#@! There's no way to handle imperfect queries without 
    10541054            # creating all involved Units, which defeats the purpose of 
    1055             # distinct, which was a speed issue more than anything. Grr. 
    1056             raise ValueError(u"The following query cannot be reliably " 
    1057                              u"returned from this data source.", 
    1058                              u"distinct()", cls, fields, expr) 
    1059          
    1060         data, columns = self.fetch(sql) 
    1061         actualTypes = [x[1] for x in columns] 
    1062         expectedTypes = [cls.property_type(x) for x in fields] 
    1063          
    1064         coerce = self.fromAdapter.coerce 
    1065         # Must use inner tuples for hashability in Sandbox.distinct() 
    1066         return [tuple([coerce(val, actualTypes[i], expectedTypes[i]) 
    1067                        for i, val in enumerate(row)]) 
    1068                  for row in data] 
     1055            # distinct, which was a speed issue more than anything. 
     1056            warnings.warn("The requested distinct() query for %s Units " 
     1057                          "cannot produce perfect SQL with a %s datasource. " 
     1058                          "It may take an absurd amount of time to run, " 
     1059                          "since each unit must be fully-formed. %s" 
     1060                          % (cls.__name__, self.__class__.__name__, expr)) 
     1061            distvals = {} 
     1062            for unit in self.recall(cls, expr): 
     1063                # Must use inner tuples for hashability in Sandbox.distinct() 
     1064                val = tuple([getattr(unit, f) for f in fields]) 
     1065                distvals[val] = None 
     1066            return distvals.keys() 
     1067        else: 
     1068            data, columns = self.fetch(sql) 
     1069            actualTypes = [x[1] for x in columns] 
     1070            expectedTypes = [cls.property_type(x) for x in fields] 
     1071             
     1072            coerce = self.fromAdapter.coerce 
     1073            # Must use inner tuples for hashability in Sandbox.distinct() 
     1074            return [tuple([coerce(val, actualTypes[i], expectedTypes[i]) 
     1075                           for i, val in enumerate(row)]) 
     1076                     for row in data] 
    10691077     
    10701078    def multiselect(self, pairs): 
  • trunk/storage/storeado.py

    r63 r64  
    446446            # compare TEXT or NTEXT fields??!? Fine. We'll deny such, and 
    447447            # warn the deployer with less swearing and exclamation points. 
    448             import warnings 
    449448            warnings.warn("You have defined a string property without " 
    450449                          "limiting its length. Microsoft SQL Server does " 
  • trunk/storage/storemysql.py

    r63 r64  
    1414# Use _mysql directly to avoid all of the DB-API overhead. 
    1515import _mysql 
     16import warnings 
    1617import datetime 
    1718from dejavu import storage, logic 
  • trunk/storage/zoo_fixture.py

    r63 r64  
    252252        legs.sort() 
    253253        self.assertEqual(legs, [1, 2, 4, 100, 1000000]) 
     254         
     255        # This may raise a warning on some DB's. 
     256        f = logic.Expression(lambda x: x.Name == 'Lion') 
     257        escapees = box.distinct(zoo.Animal, ['Legs'], f) 
     258        self.assertEqual(escapees, [4]) 
    254259     
    255260    def test_4_Multiselect(self):