diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-09-26 17:22:52 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-09-26 17:22:52 -0400 |
| commit | 1e6a2096e38a15ff7b02d34ef9fc1cfb8d4ddc69 (patch) | |
| tree | be28d1a7bfef7edde57649f81cbf112cacf8e443 /examples | |
| parent | 3104da41399bc827bee8b67d83991802711c1683 (diff) | |
| download | sqlalchemy-1e6a2096e38a15ff7b02d34ef9fc1cfb8d4ddc69.tar.gz | |
- Adjusted dictlike-polymorphic.py example
to apply the CAST such that it works on
PG, other databases. [ticket:2266]
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/vertical/dictlike-polymorphic.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/vertical/dictlike-polymorphic.py b/examples/vertical/dictlike-polymorphic.py index d66b1872f..c4eb6b5ce 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) |
