creating an alias() or otherwise using the .c. collection of any selectable
that's derived from another selectable (as when you say
select([sometable]).c.somecolumn) means that the Column objects are actually
copies of the original column objects. This copying procedure is performed by
column._make_proxy(). in rb03613c840a4 I have modified this so that it
uses the effective class of the object, typically self.__class__, when it
constructs the new Column object. However in 0.6 it is harcdoded to
ColumnClause and/or Column. So for the current release, you'd have to
ensure your GeometryExtensionColumn is overriding _make_proxy() as well. I
would use the _make_proxy() of Column to get its result, then change the class
of the returned Column to GeometryExtensionColumn on the way out.you might
want to first check that the problem goes away when using the current tip.
On May 10, 2010, at 6:07 AM, Tobias wrote:
Hi,
I am currently working on adding support for Oracle to GeoAlchemy and
Oracle has some methods [1] that (somehow) are only recognized when a
table alias is used. The function aliased [2] seemed to work
perfectly, but then I realized that the compiler extension for my
custom column is not executed anymore.
The compiler extension looks like this [3]:
[..]
class GeometryExtensionColumn(Column):
pass
@compiles(GeometryExtensionColumn)
def compile_column(element, compiler, **kw):
if kw.has_key(within_columns_clause) and
kw[within_columns_clause] == True:
return compiler.process(functions.wkb(element))
return element.__str__()
[..]
And if I make a query using the original mapped class, it works as
expected:
s = session.query(Spot).get(1)
2010-05-10 11:49:19,957 INFO sqlalchemy.engine.base.Engine.0x...408c
SELECT SDO_UTIL.TO_WKBGEOMETRY(spots.spot_location) AS
spots_spot_location, spots.spot_id AS spots_spot_id, spots.spot_height
AS spots_spot_height
FROM spots
WHERE spots.spot_id = :param_1
2010-05-10 11:49:19,958 INFO sqlalchemy.engine.base.Engine.0x...408c
{'param_1': 1}
But when I create an alias and use this alias in a query,
compile_column is not called anymore and in this case
SDO_UTIL.TO_WKBGEOMETRY is not added to the query:
spot_alias = aliased(Spot)
s_alias = session.query(spot_alias).filter(spot_alias.spot_id ==
1).first()
2010-05-10 11:49:36,481 INFO sqlalchemy.engine.base.Engine.0x...408c
SELECT spots_1_spot_location, spots_1_spot_id, spots_1_spot_height
FROM (SELECT spots_1_spot_location, spots_1_spot_id,
spots_1_spot_height, ROWNUM AS ora_rn
FROM (SELECT spots_1.spot_location AS spots_1_spot_location,
spots_1.spot_id AS spots_1_spot_id, spots_1.spot_height AS
spots_1_spot_height
FROM spots spots_1
WHERE spots_1.spot_id = :spot_id_1)
WHERE ROWNUM = :ROWNUM_1)
WHERE ora_rn :ora_rn_1
What is going wrong?
Thanks,
Tobias
[1]:
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11830/sdo_objrelschema.htm#insertedID3
[2]: http://www.sqlalchemy.org/docs/ormtutorial.html#using-aliases
[3]:
http://bitbucket.org/geoalchemy/geoalchemy/src/c0bfcd46cb3a/geoalchemy/geometry.py#cl-121
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to sqlalch...@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 sqlalch...@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.