it just changes to .columns, should fix it as below:

    def __init__(self, table):
        event.listen(table, "before_create", self.before_create)
        event.listen(table, "after_create", self.after_create)
        event.listen(table, "before_drop", self.before_drop)
        event.listen(table, "after_drop", self.before_drop)
        self._stack = []

    def before_create(self, target, connection, **kw):
        self("before-create", target, connection)

    def after_create(self, target, connection, **kw):
        self("after-create", target, connection)

    def before_drop(self, target, connection, **kw):
        self("before-drop", target, connection)

    def after_drop(self, target, connection, **kw):
        self("after-drop", target, connection)

    def __call__(self, event, table, bind):
        if event in ('before-create', 'before-drop'):
            regular_cols = [c for c in table.c if not isinstance(c.type, 
Geometry)]
            gis_cols = set(table.c).difference(regular_cols)
            self._stack.append(table.c)
            table.columns = expression.ColumnCollection(*regular_cols)

            if event == 'before-drop':
                for c in gis_cols:
                    bind.execute(select([func.DropGeometryColumn('public', 
table.name, c.name)], autocommit=True))

        elif event == 'after-create':
            table.columns = self._stack.pop()

            for c in table.c:
                if isinstance(c.type, Geometry):
                    bind.execute(select([func.AddGeometryColumn(table.name, 
c.name, c.type.srid, c.type.name, c.type.dimension)], autocommit=True))
        elif event == 'after-drop':
            table.columns = self._stack.pop()



On Jun 6, 2011, at 3:47 PM, Eric Lemoine wrote:

> Hi
> 
> i'm currently in the process of porting GeoAlchemy to SQLAlchemy 0.7.
> 
> The first issue I'm having is related to before_create and
> after_create DDL listeners we have in GeoAlchemy.
> 
> We use before_create and after_create listeners to prevent SQLA from
> adding the geometry column, and do it ourselves.
> 
> Basically, the before_create function removes the geometry column from
> table._columns, and the after_create function adds the geometry column
> by calling the AddGeometryColumn SQL function.
> 
> I'm trying to use a similar mechanism with 0.7, relying on
> before_create and after_create event listeners. That doesn't work,
> because  setting table._colums seems to have no effect, i.e. SQLA
> still attempts to add the gemetry column.
> 
> I've been thinking about resetting table.c (setting it to None or
> something) and using table.append_column to add all columns but the
> geometry column in before_create, but I'm wondering if that's the
> proper way.
> 
> Thanks for any guidance on that,
> 
> PS: I was hoping to get inspiration from examples/postgis.py, but this
> example looks outdated. Maybe it should be removed from the 0.7 code
> base.
> 
> -- 
> Eric Lemoine
> 
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
> 
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemo...@camptocamp.com
> http://www.camptocamp.com
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to