From 1e6a2096e38a15ff7b02d34ef9fc1cfb8d4ddc69 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 26 Sep 2011 17:22:52 -0400 Subject: [PATCH] - Adjusted dictlike-polymorphic.py example to apply the CAST such that it works on PG, other databases. [ticket:2266] --- CHANGES | 6 ++++++ examples/vertical/dictlike-polymorphic.py | 17 +++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index cc30f03c0d..229f50bffd 100644 --- a/CHANGES +++ b/CHANGES @@ -270,6 +270,12 @@ CHANGES dictionary that had tuples as keys would be misinterpreted as a sequence. [ticket:2275] +- examples + - Adjusted dictlike-polymorphic.py example + to apply the CAST such that it works on + PG, other databases. [ticket:2266] + Also in 0.6.9. + 0.7.2 ===== - orm diff --git a/examples/vertical/dictlike-polymorphic.py b/examples/vertical/dictlike-polymorphic.py index d66b1872f3..c4eb6b5ce6 100644 --- a/examples/vertical/dictlike-polymorphic.py +++ b/examples/vertical/dictlike-polymorphic.py @@ -113,14 +113,14 @@ class PolymorphicVerticalProperty(object): self.cls = cls def _case(self): - whens = [(text("'%s'" % p[0]), getattr(self.cls, p[1])) + whens = [(text("'%s'" % p[0]), cast(getattr(self.cls, p[1]), String)) for p in self.cls.type_map.values() if p[1] is not None] return case(whens, self.cls.type, null()) def __eq__(self, other): - return cast(self._case(), String) == cast(other, String) + return self._case() == cast(other, String) def __ne__(self, other): - return cast(self._case(), String) != cast(other, String) + return self._case() != cast(other, String) def __repr__(self): return '<%s %r=%r>' % (self.__class__.__name__, self.key, self.value) @@ -185,9 +185,10 @@ if __name__ == '__main__': mapper(AnimalFact, chars) - metadata.bind = create_engine('sqlite://', echo=True) - metadata.create_all() - session = Session() + engine = create_engine('sqlite://', echo=True) + + metadata.create_all(engine) + session = Session(engine) stoat = Animal(u'stoat') stoat[u'color'] = u'red' @@ -254,5 +255,5 @@ if __name__ == '__main__': filter(with_characteristic(u'cuteness', u'very cute'))) print q.all() - - metadata.drop_all() + session.close() + metadata.drop_all(engine) -- 2.47.3