]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Adjusted dictlike-polymorphic.py example
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Sep 2011 21:22:17 +0000 (17:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Sep 2011 21:22:17 +0000 (17:22 -0400)
    to apply the CAST such that it works on
    PG, other databases.  [ticket:2266]

CHANGES
examples/vertical/dictlike-polymorphic.py

diff --git a/CHANGES b/CHANGES
index 6a53e9d057d4b851e324bff9897e147ececbc9ab..b06899297eab326447e9caaf6ed65dcf10fad932 100644 (file)
--- 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
index 1acb6aee5c7d545f739365822003ad5bd7af2fc2..a66a7d2d3ba0b348d66053ec6fe666ce005cfdf7 100644 (file)
@@ -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)