Commits

Mike Bayer committed ae2340a

renamed new scalar() method to as_scalar(), not deprecating normal ClauseElement.scalar()...

  • Participants
  • Parent commits 5039434
  • Branches rel_0_4

Comments (0)

Files changed (3)

     regarding "is subquery" and "correlation" pushed to SQL generation phase.
     select() elements are now *never* mutated by their enclosing containers
     or by any dialect's compilation process [ticket:52] [ticket:569]
+  - select(scalar=True) argument is deprecated; use select(..).as_scalar().
+    the resulting object obeys the full "column" interface and plays better
+    within expressions
   - result sets make a better attempt at matching the DBAPI types present
     in cursor.description to the TypeEngine objects defined by the dialect,
     which are then used for result-processing. Note this only takes effect 

File lib/sqlalchemy/sql.py

           will attempt to provide similar functionality.
         
         scalar=False
-          deprecated.  use select(...).scalar() to create a "scalar column"
+          deprecated.  use select(...).as_scalar() to create a "scalar column"
           proxy for an existing Select object.
 
         correlate=True
     scalar = kwargs.pop('scalar', False)
     s = Select(columns, whereclause=whereclause, from_obj=from_obj, **kwargs)
     if scalar:
-        return s.scalar()
+        return s.as_scalar()
     else:
         return s
 
         self.append_order_by(*util.to_list(order_by, []))
         self.append_group_by(*util.to_list(group_by, []))
     
-    def scalar(self):
+    def as_scalar(self):
         return _ScalarSelect(self)
     
     def label(self, name):
-        return self.scalar().label(name)
+        return self.as_scalar().label(name)
         
     def supports_execution(self):
         return True

File test/sql/select.py

         s = select([table1.c.myid], scalar=True)
         self.runtest(select([table2, s]), "SELECT myothertable.otherid, myothertable.othername, (SELECT mytable.myid FROM mytable) FROM myothertable")
 
-        s = select([table1.c.myid]).correlate(None).scalar()
+        s = select([table1.c.myid]).correlate(None).as_scalar()
         self.runtest(select([table1, s]), "SELECT mytable.myid, mytable.name, mytable.description, (SELECT mytable.myid FROM mytable) FROM mytable")
 
-        s = select([table1.c.myid]).scalar()
+        s = select([table1.c.myid]).as_scalar()
         self.runtest(select([table2, s]), "SELECT myothertable.otherid, myothertable.othername, (SELECT mytable.myid FROM mytable) FROM myothertable")
 
         # test expressions against scalar selects
         self.runtest(select([s - literal(8)]), "SELECT (SELECT mytable.myid FROM mytable) - :literal")
-        self.runtest(select([select([table1.c.name]).scalar() + literal('x')]), "SELECT (SELECT mytable.name FROM mytable) || :literal")
+        self.runtest(select([select([table1.c.name]).as_scalar() + literal('x')]), "SELECT (SELECT mytable.name FROM mytable) || :literal")
         self.runtest(select([s > literal(8)]), "SELECT (SELECT mytable.myid FROM mytable) > :literal")
 
         self.runtest(select([select([table1.c.name]).label('foo')]), "SELECT (SELECT mytable.name FROM mytable) AS foo")
             column('nm')
         )
         zip = '12345'
-        qlat = select([zips.c.latitude], zips.c.zipcode == zip).correlate(None).scalar()
-        qlng = select([zips.c.longitude], zips.c.zipcode == zip).correlate(None).scalar()
+        qlat = select([zips.c.latitude], zips.c.zipcode == zip).correlate(None).as_scalar()
+        qlng = select([zips.c.longitude], zips.c.zipcode == zip).correlate(None).as_scalar()
  
         q = select([places.c.id, places.c.nm, zips.c.zipcode, func.latlondist(qlat, qlng).label('dist')],
                          zips.c.zipcode==zip,