From: Mike Bayer Date: Tue, 17 Feb 2009 23:10:52 +0000 (+0000) Subject: - Session.scalar() now converts raw SQL strings to text() X-Git-Tag: rel_0_5_3~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=911c7b9b36277d31b5b74bd6ea6dc73743c7cb9f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Session.scalar() now converts raw SQL strings to text() the same way Session.execute() does and accepts same alternative **kw args. --- diff --git a/CHANGES b/CHANGES index 629fd4f21b..e4248cde93 100644 --- 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 diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 4fb6c18593..1c061c7ebf 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -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. diff --git a/test/orm/session.py b/test/orm/session.py index e1eaf82cfc..818ab03daf 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -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):