2006/2/24, Michael Bayer <[EMAIL PROTECTED]>: > so, you want a mapping of types.TypeEngine types to python type > objects ? I suppose we could add a "python_type" accessor on each > TypeEngine (i.e. types.String.python_type == str). would that work ? Yes that would be perfect. I think the mapping will have to be hard coded since there is no way to get it from the dbapi... Do you think it could also be useful using type checking in the setattr of a mapped class? for instance:
mapped.attribute = 'foo' if attribute refers to a types.Integer it would fail with a TypeError. > > > On Feb 24, 2006, at 8:15 AM, Michele Comitini wrote: > > > 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 > > ------------------------------------------------------- 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