[sqlalchemy] get_col_spec behavior has changed from 0.5.8 to 0.6.X

2010-08-13 Thread robert rottermann

hi there,
up to now I did use something like:

c = tblCompany.__table__.columns
COMPANY_FIELDS = [(k, c[k].type.get_col_spec()) for k in c.keys() if not 
k=='id']


to build some dynamic forms for a web application.

now this breaks with an error:
 AttributeError: 'VARCHAR' object has no attribute 'get_col_spec'

it seems to work still with MySQL but not with postgres. (maybe MySQL 
uses a slightly older version out of the 6.xx serie)


what is the correct way to build a list of fields a table provides ?

thanks
robert

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



Re: [sqlalchemy] get_col_spec behavior has changed from 0.5.8 to 0.6.X

2010-08-13 Thread Michael Bayer

On Aug 13, 2010, at 8:19 AM, robert rottermann wrote:

 hi there,
 up to now I did use something like:
 
 c = tblCompany.__table__.columns
 COMPANY_FIELDS = [(k, c[k].type.get_col_spec()) for k in c.keys() if not 
 k=='id']
 
 to build some dynamic forms for a web application.
 
 now this breaks with an error:
 AttributeError: 'VARCHAR' object has no attribute 'get_col_spec'
 
 it seems to work still with MySQL but not with postgres. (maybe MySQL uses a 
 slightly older version out of the 6.xx serie)
 
 what is the correct way to build a list of fields a table provides ?

get_col_spec() was removed in 0.6 and replaced with the compiler structure.

the string form of a type is available if you compile it against a dialect, 
like type.compile(dialect=engine.dialect).

its not a great idea to rely upon the string form of a type for anything other 
than issuing SQL since it changes based on dialect involved and arguments.   if 
you're needing a hash key or some kind of discriminator, use the type object or 
its class by itself.


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