On Sep 11, 2006, at 4:03 PM, Eric Brunson wrote:

> I'm trying to convert some code I wrote over to using SA.  I have code
> that generates an HTML given the name of a table, it parses the
> information_schema to get the structure of the table, then creates an

SA supports reflection of tables using the "autoload" construct, you  
shouldnt have to go into information_schema yourself.

> SQL query to get the data and formats the table with the column  
> names at
> the top and one row per <TR>.  The simple part of that I've switched
> over to using SA metadata, but now I'm looking to take the next  
> step and
> dereference any foreign keys.

yeah, ForeignKey has a "column" attribute referencing the column it  
references, and a "parent" attribute referencing the Column is was  
declared on.  Column has a "table" attribute referencing the Table it  
belongs to.

> Will something in SA build this SQL for me?  Right now I'm playing  
> with
> a loop like this:
>
> def dereferenced_columns( self ):
>     columnnames = []
>     derefcolumnstext = ''
>     for column in self.table.columns:
>         if column.foreign_key:
>             # do whatever it takes to figure out the foreign key
>             # and add it to my list
>         else:
>             columnnames.append( "%s" % column )
>     return derefcolumnstext += ','.join( columnnames )
>

seems fine to me (whats the ultimate result you want from that ? a  
query ? or an HTML string ?)

>
> I'm new to SA and unfamiliar with all the functionality, most examples
> assume that you're creating the schema and have implicit knowledge of
> it, rather than trying to read it from the metadata,
> so I'm doing a lot
> of iteration and dir()'s over columns objects in the metadata and it's
> slow going.

you should read over the generated docs at the end of the SA  
documentation, and maybe read over the source to schema.py to get a  
handle on some other attributes that might be helpful.




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to