On Mon, Jun 6, 2011 at 9:47 PM, Eric Lemoine
<eric.lemo...@camptocamp.com> 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.

Hi

Here's another issue with porting GeoAlchemy to SQLAlchemy 0.7.


So GeoA defines a TypeEngine, which looks like this:

class Geometry(TypeEngine):

    def __init__(self, dimension=2, srid=4326, spatial_index=True, **kwargs):
        self.dimension = dimension
        self.srid = srid
        self.spatial_index = True
        self.kwargs = kwargs
        super(GeometryBase, self).__init__()


Using the Geometry type with Oracle requires passing an additional
argument to the constructor, namely "diminfo":

    Geometry(dimension=2, srid=4326, spatial_index=True,
diminfo='the_diminfo_string')

Then our Oracle-specific code uses type.kwargs['diminfo'] to access
the "diminfo" value.


This worked well with SQLA 0.6, but it doesn't work with SQLA 0.7.

It doesn't work with 0.7 because SQLA may clone the type instance, and
because of the way SQLA clones object (constructor_copy), the clone
does not have self.kwargs['diminfo'].


What is the recommended way to address the issue?


We've considered using an "additional_args" argument:

class Geometry(TypeEngine):

    def __init__(self, dimension=2, srid=4326, spatial_index=True,
additional_args={}, **kwargs):
        self.dimension = dimension
        self.srid = srid
        self.spatial_index = True
        self.additional_args = additional_args
        self.kwargs = kwargs
        super(GeometryBase, self).__init__()

which would be used like this:

    Geometry(dimension=2, srid=4326, spatial_index=True,
additional_args={'diminfo'='the_diminfo_string'})

but introducing an "additional_args" argument doesn't look very pythonic.


Thanks a lot for any guidance on the way to address the issue.



-- 
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.

Reply via email to