On Jun 30, 2008, at 1:04 PM, Hans wrote:

>
> The problem is that I'd like to have sqlalchemy return KML for all
> geometry types by default, but I don't know how to setup my type to
> specify a SQL function that needs to be applied to the column in the
> select clause.  Is this possible?  Alternatively, it would be
> *perfect* to have additional *_kml properties added to the result
> objects (one for each GEOMETRY column), but this seems even more
> complex (?).
>
>
> I was expecting my convert_result_value method to operate on the SQL,
> but I am assuming from looking at the generated SQL that this method
> is actually going to operate on the raw data that was returned from
> SQL.  So, is there a way to accomplish what I want?
>

TypeEngine currently has no hook that's consulted during SQL  
rendering, which is where you're looking for this to happen.    Its  
not impossible to add such a feature but its not yet clear to me that  
TypeEngine is the appropriate place for this decision to be made.    
Its also not apparent yet how specifically within the SQL it would be  
appropriate to render the function, and how labeling would work -  
since SQLA, when it generates nested select statements, uses labels to  
track each column named against a table outwards...such as "select  
foo, bar from (select a as foo, b as bar from table)".  In the case of  
a SQL function, the column name becomes somewhat undefined until a  
label is applied.  SQLA nests SELECT statements very often.

You might want to try experimenting with a simple monkeypatch approach  
just to see what kind of results you get - this is just a guess based  
on a particular compiler hook we have that specifically processes  
columns being rendered within a select:

from sqlalchemy.databases.postgres import PGCompiler

def label_select_column(self, select, column, asfrom):
        if isinstance(col.type, MyGISType):
                return func.some_kml_function(col).label(column.name)
        else:
                return super(self, PGCompiler).label_select_column(select, 
column,  
asfrom)

PGCompiler.label_select_column = label_select_column

if the above leads to decent results we can attempt to add a hook onto  
TypeEngine perhaps.



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to