]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix some tests
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Jun 2011 07:09:08 +0000 (03:09 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Jun 2011 07:09:08 +0000 (03:09 -0400)
lib/sqlalchemy/sql/expression.py
test/sql/test_defaults.py
test/sql/test_functions.py
test/sql/test_types.py

index 47f19806a6a73bcdc36f5721d0101fde7cfcb53a..38eb71da87530ce16079adddc8853647d3937068 100644 (file)
@@ -1144,6 +1144,12 @@ func = _FunctionGenerator()
         >>> print func.count(1)
         count(:param_1)
 
+   The element is a column-oriented SQL element like any other, and is
+   used in that way::
+   
+        >>> print select([func.count(table.c.id)])
+        SELECT count(sometable.id) FROM sometable
+
    Any name can be given to ``func``. If the function name is unknown to
    SQLAlchemy, it will be rendered exactly as is. For common SQL functions
    which SQLAlchemy is aware of, the name may be interpreted as a *generic
@@ -1171,7 +1177,16 @@ func = _FunctionGenerator()
    This object meets the "column" interface, including comparison and labeling
    functions.  The object can also be passed the :meth:`~.Connectable.execute`
    method of a :class:`.Connection` or :class:`.Engine`, where it will be
-   wrapped inside of a SELECT statement first.
+   wrapped inside of a SELECT statement first::
+   
+        print connection.execute(func.current_timestamp()).scalar()
+        
+   A function can also be "bound" to a :class:`.Engine` or :class:`.Connection`
+   using the ``bind`` keyword argument, providing an execute() as well
+   as a scalar() method::
+   
+        myfunc = func.current_timestamp(bind=some_engine)
+        print myfunc.scalar()
 
    Functions which are interpreted as "generic" functions know how to
    calculate their return type automatically. For a listing of known generic
index 82ca1412bfaff4dc47033aaf31b82196dd3f102a..2bb961d4e15918e598f8a413f5241d9af95a17be 100644 (file)
@@ -68,7 +68,7 @@ class DefaultTest(fixtures.TestBase):
                 def2 = sa.text("getdate()")
             else:
                 def2 = sa.text("current_date")
-            ts = db.func.current_date().scalar()
+            ts = db.scalar(func.current_date())
         else:
             f = len('abcdef')
             f2 = len('abcdefghijk')
index f08fde1f5d574cb74baca1dd4ba4172a8e4c4daf..961845bac701d93f792b3638184f162914fd8159 100644 (file)
@@ -195,6 +195,7 @@ class ExecuteTest(fixtures.TestBase):
     def tearDown(self):
         pass
 
+    @testing.uses_deprecated
     def test_standalone_execute(self):
         x = testing.db.func.current_date().execute().scalar()
         y = testing.db.func.current_date().select().execute().scalar()
@@ -300,13 +301,13 @@ class ExecuteTest(fixtures.TestBase):
     @testing.fails_on_everything_except('postgresql')
     def test_as_from(self):
         # TODO: shouldnt this work on oracle too ?
-        x = testing.db.func.current_date().execute().scalar()
-        y = testing.db.func.current_date().select().execute().scalar()
-        z = testing.db.func.current_date().scalar()
-        w = select(['*'], from_obj=[testing.db.func.current_date()]).scalar()
+        x = func.current_date(bind=testing.db).execute().scalar()
+        y = func.current_date(bind=testing.db).select().execute().scalar()
+        z = func.current_date(bind=testing.db).scalar()
+        w = select(['*'], from_obj=[func.current_date(bind=testing.db)]).scalar()
 
         # construct a column-based FROM object out of a function, like in [ticket:172]
-        s = select([sql.column('date', type_=DateTime)], from_obj=[testing.db.func.current_date()])
+        s = select([sql.column('date', type_=DateTime)], from_obj=[func.current_date(bind=testing.db)])
         q = s.execute().first()[s.c.date]
         r = s.alias('datequery').select().scalar()
 
index 8a8ae9cae574a0f4157ac19831adc85ab8a174a1..6ccb67f9198f836b5af65da1d268b4c4a1547b58 100644 (file)
@@ -1263,15 +1263,15 @@ class DateTest(fixtures.TestBase, AssertsExecutionResults):
                      'DateTest mismatch: got:%s expected:%s' % (l, insert_data))
 
     def testtextdate(self):
-        x = testing.db.text(
+        x = testing.db.execute(text(
             "select user_datetime from query_users_with_date",
-            typemap={'user_datetime':DateTime}).execute().fetchall()
+            typemap={'user_datetime':DateTime})).fetchall()
 
         self.assert_(isinstance(x[0][0], datetime.datetime))
 
-        x = testing.db.text(
+        x = testing.db.execute(text(
             "select * from query_users_with_date where user_datetime=:somedate",
-            bindparams=[bindparam('somedate', type_=types.DateTime)]).execute(
+            bindparams=[bindparam('somedate', type_=types.DateTime)]),
             somedate=datetime.datetime(2005, 11, 10, 11, 52, 35)).fetchall()
 
     def testdate2(self):