From: Mike Bayer Date: Mon, 26 Sep 2011 21:22:17 +0000 (-0400) Subject: - Adjusted dictlike-polymorphic.py example X-Git-Tag: rel_0_6_9~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=78bdb1067dc4635d772c775671c711cb164dc76f;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 6a53e9d057..b06899297e 100644 --- a/CHANGES +++ b/CHANGES @@ -96,6 +96,11 @@ CHANGES - added CURRENT to reserved word list. [ticket:2212] +- examples + - Adjusted dictlike-polymorphic.py example + to apply the CAST such that it works on + PG, other databases. [ticket:2266] + 0.6.8 ===== - orm diff --git a/examples/vertical/dictlike-polymorphic.py b/examples/vertical/dictlike-polymorphic.py index 1acb6aee5c..a66a7d2d3b 100644 --- a/examples/vertical/dictlike-polymorphic.py +++ b/examples/vertical/dictlike-polymorphic.py @@ -85,14 +85,14 @@ class PolymorphicVerticalProperty(object): def _case(self): cls = self.prop.parent.class_ - whens = [(text("'%s'" % p[0]), getattr(cls, p[1])) + whens = [(text("'%s'" % p[0]), cast(getattr(cls, p[1]), String)) for p in cls.type_map.values() if p[1] is not None] return case(whens, 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 __init__(self, key, value=None): self.key = key @@ -131,7 +131,7 @@ class PolymorphicVerticalProperty(object): if __name__ == '__main__': from sqlalchemy import (MetaData, Table, Column, Integer, Unicode, ForeignKey, UnicodeText, and_, not_, or_, String, Boolean, cast, text, - null, case) + null, case, create_engine) from sqlalchemy.orm import mapper, relationship, Session from sqlalchemy.orm.collections import attribute_mapped_collection @@ -189,9 +189,10 @@ if __name__ == '__main__': 'value': comparable_property(AnimalFact.Comparator, AnimalFact.value) }) - metadata.bind = 'sqlite:///' - 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' @@ -208,9 +209,7 @@ if __name__ == '__main__': print "changing cuteness value and type:" critter[u'cuteness'] = u'very cute' - metadata.bind.echo = True session.commit() - metadata.bind.echo = False marten = Animal(u'marten') marten[u'cuteness'] = 5 @@ -260,5 +259,5 @@ if __name__ == '__main__': filter(with_characteristic(u'cuteness', u'very cute'))) print q.all() - - metadata.drop_all() + session.close() + metadata.drop_all(engine)