On Jun 9, 2010, at 11:27 AM, Cserna, Zsolt wrote:
>
> Hi all,
>
> We're trying to use sybase dialect in sqlalchemy, but it creates invalid
> select parameters when we are trying to use a python-string (or unicode
> object) variable to specify a sql-int variable.
> That problem occurs when we use pylons web framework with formalchemy with
> sqlalchem+sybase - which actually specifies all the parameters in unicode
> objects to filter_by() method.
> I'm using the nightly snapshot from sqlalchemy.org.
>
> A simple example to re-produce this error is the following (only the relevant
> parts):
>
> metadata = MetaData()
> users_table = Table('users', metadata,
> Column('id', Integer, primary_key=True),
> Column('name', String(64)),
> Column('fullname', String(64)),
> Column('password', String(64))
> )
>
> session.query(User).filter_by(id="1").order_by(User.id)
>
> Here, we want to filter to id="1", where "1" is a string value, but it's an
> integer in the database. If I execute the example, it says (again, only the
> relevant parts):
>
> 2010-06-09 16:59:50,458 INFO sqlalchemy.engine.base.Engine.0x...ae2c BEGIN
> 2010-06-09 16:59:50,459 INFO sqlalchemy.engine.base.Engine.0x...ae2c SELECT
> users.id AS users_id, users.name AS users_name, users.fullname AS
> users_fullname, users.password AS users_password
> FROM users
> WHERE users.id = @id_1 ORDER BY users.id
> 2010-06-09 16:59:50,459 INFO sqlalchemy.engine.base.Engine.0x...ae2c
> {'@id_1': '1'}
>
> sqlalchemy.exc.DatabaseError: (DatabaseError) Msg 257, Level 16, State 1,
> Line 1
> Implicit conversion from datatype 'CHAR' to 'INT' is not allowed. Use the
> CONVERT function to run this query.
SQLAlchemy doesn't do type coercion out of the box. Some DBAPIs do, which is
why you may have not noticed this issue on other platforms. You can build
that functionality yourself using TypeDecorator:
http://www.sqlalchemy.org/docs/reference/sqlalchemy/types.html?highlight=typedecorator#sqlalchemy.types.TypeDecorator
--
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.