On Jan 30, 2011, at 10:23 PM, ObjectEvolution wrote: > Thanks Michael. So then it looks like my options are to: > > 1. Convert the longs.
> 2. Declare my columns instead of using reflection so I get the right > types. If your concern is they print funny, you should use str() for formatting. Python ints and longs are otherwise fully cross-compatible. > As I said, "not using reflection" makes no difference here, unless your plan is to use a custom TypeDecorator against Integer to force the int() call as rows are fetched. Otherwise, reflection knows your column type is INTEGER. The reason for the longs is that your MySQL-python library is returns ints as longs, and SQLA's Integer type does not interfere with this. > > > On Jan 30, 7:18 pm, Michael Bayer <[email protected]> wrote: >> On Jan 30, 2011, at 8:55 PM, ObjectEvolution wrote: >> >> >> >> >> >>> Hi, >> >>> I'm reflecting some tables out of MySQL for a User object and when I >>> call: >> >>> user.ID >> >>> I get a value like this: >> >>> 10L >> >>> instead of: >> >>> 10 >> >>> If I wrap it up like this: >> >>> int(user.ID) >> >>> I get: >> >>> 10 >> >>> It seems that the reflection thinks my int column is a long. Why is >>> that happening and how can I fix it? Abandon reflection? >> >> MySQL-python returns ints as Python longs. They are cross compatible. >> SQLA's reflection is not involved. >> >> from sqlalchemy import * >> >> e = create_engine('mysql://scott:tiger@localhost/test') >> print repr(e.scalar(select([1]))) >> print repr(e.scalar(select([cast(1, Integer)]))) >> >> raw_mysqldb_connection = e.connect().connection >> cursor = raw_mysqldb_connection.cursor() >> cursor.execute("select 1") >> print cursor.fetchall() >> >> output: >> >> 1L >> 1L >> ((1L,),) > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > 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. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. 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.
