Hello Michael,

Thanks for your great piece of software.

I have a question about getting type information from a mapper created
with reflection. How do I know the python type of a mapped attribute
without having to extract at least one record?

Right now I do this:

colnames = mapper.c.keys()
coltypes = [type(getattr(mapper.select()[0],x)) for x in colnames]

which would fail if I have an empty table
This way I know which _python_ types I can expect as a result of a
select() on that mapper and what types I have to use on insert.  While
if do:

If I do this:

colnames = mapper.c.keys()
coltypes = [(getattr(mapper,x)).type for x in colnames]

I get the sqlalchemy.types (or derivatives) which tell me only the
type stored in the db.

This could be useful to check for correct type binding _before_
actually having the driver raising an exception and manage type
conversion on the python side.

Thanks for you help and keep up the great work!

Michele Comitini


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to