]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Session.scalar() now converts raw SQL strings to text()
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 17 Feb 2009 23:10:52 +0000 (23:10 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 17 Feb 2009 23:10:52 +0000 (23:10 +0000)
the same way Session.execute() does and accepts same
alternative **kw args.

CHANGES
lib/sqlalchemy/orm/session.py
test/orm/session.py

diff --git a/CHANGES b/CHANGES
index 629fd4f21bbb74c826e742e7d6ef7068a2c70832..e4248cde93b5cf4997b590d26826a62e6cb66789 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,10 @@ CHANGES
       in the database.  Presents some degree of a workaround for 
       [ticket:1315], although we are considering removing the 
       flush([objects]) feature altogether.
+    
+    - Session.scalar() now converts raw SQL strings to text()
+      the same way Session.execute() does and accepts same 
+      alternative **kw args.
       
     - improvements to the "determine direction" logic of 
       relation() such that the direction of tricky situations 
index 4fb6c185934af8247c42c50b745768631beec796..1c061c7ebf3298c7abb7454eb8168cef841c0e7e 100644 (file)
@@ -754,13 +754,10 @@ class Session(object):
         return self.__connection(engine, close_with_result=True).execute(
             clause, params or {})
 
-    def scalar(self, clause, params=None, mapper=None):
+    def scalar(self, clause, params=None, mapper=None, **kw):
         """Like execute() but return a scalar result."""
-
-        engine = self.get_bind(mapper, clause=clause)
-
-        return self.__connection(engine, close_with_result=True).scalar(
-            clause, params or {})
+        
+        return self.execute(clause, params=params, mapper=mapper, **kw).scalar()
 
     def close(self):
         """Close this Session.
index e1eaf82cfc6476f202a5bdbd1aec82a9889286fe..818ab03daf50091624c09e2f95602e6a568f823d 100644 (file)
@@ -325,6 +325,12 @@ class SessionTest(_fixtures.FixtureTest):
                          {'id':7}).fetchall(),
             [(7, u'jack')])
 
+
+        # use :bindparam style
+        eq_(sess.scalar("select id from users where id=:id",
+                         {'id':7}),
+            7)
+
     @engines.close_open_connections
     @testing.resolve_artifact_names
     def test_subtransaction_on_external(self):