From: Mike Bayer Date: Mon, 26 Sep 2011 21:22:52 +0000 (-0400) Subject: - Adjusted dictlike-polymorphic.py example X-Git-Tag: rel_0_7_3~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e6a2096e38a15ff7b02d34ef9fc1cfb8d4ddc69;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Adjusted dictlike-polymorphic.py example to apply the CAST such that it works on PG, other databases. [ticket:2266] --- 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)