[sqlalchemy] MySQL's sql_mode (ORM)

2014-02-05 Thread Staszek
Hi How do you set sql_mode when using SQLAlchemy ORM with MySQL? For example, I would like to be able to do something equivalent to this: SET sql_mode = 'STRICT_ALL_TABLES'; so as to get an error (instead of a warning) when string length exceeds column size on INSERT. Ideally I would like to

Re: [sqlalchemy] MySQL's sql_mode (ORM)

2014-02-05 Thread Jonathan Rogers
Staszek wrote: Hi How do you set sql_mode when using SQLAlchemy ORM with MySQL? For example, I would like to be able to do something equivalent to this: SET sql_mode = 'STRICT_ALL_TABLES'; I don't know if SQLAlchemy has any specific support for this MySQL feature since I use PostgreSQL,

Re: [sqlalchemy] MySQL's sql_mode (ORM)

2014-02-05 Thread Michael Bayer
here’s a recipe for emitting that SQL on every connection, as well as right up front on first connect which is optional, though if you plan on changing ANSI_QUOTES would need to happen before the dialect checks on sql_mode: from sqlalchemy import create_engine, event eng =

Re: [sqlalchemy] MySQL's sql_mode (ORM)

2014-02-05 Thread Jonathan Vanasco
you can pass custom connect arguments to the DBAPI in `create_engine`. http://docs.sqlalchemy.org/en/rel_0_9/faq.html?#how-do-i-pass-custom-connect-arguments-to-my-database-api depending on which driver you use, it will be different. you shouldn't use `text`, because sqlalchemy

Re: [sqlalchemy] MySQL's sql_mode (ORM)

2014-02-05 Thread Jonathan Vanasco
just to clarify... mysqldb - `connect` accepts a `sql_mode` string: http://mysql-python.sourceforge.net/MySQLdb.html pymysql accepts it too https://github.com/PyMySQL/PyMySQL/blob/3576863f9cd0b66ce6c8b32ab3448ab68f55f489/pymysql/connections.py oursql: i couldn't find it

Re: [sqlalchemy] How To Insert Relationship-Object Data Into DB?

2014-02-05 Thread Matthew Phipps
On Wednesday, February 5, 2014 10:44:39 AM UTC-5, Michael Bayer wrote: On Feb 5, 2014, at 9:43 AM, Jude Lucien jlu...@gmail.com javascript: wrote: I have a secondary problem now having changed my model to use declarative base - as in db.create_all() does not create my tables in the

Re: [sqlalchemy] from_statement, TextAsFrom and stored procedures

2014-02-05 Thread Matt Phipps
I've been investigating this a little further and think I found some other issues. Our data team changed the stored procedure to stop aliasing the column names, so passing the mapped columns right into .columns() is working (in other words, the rest of this post doesn't reflect my use case anymore

Re: [sqlalchemy] from_statement, TextAsFrom and stored procedures

2014-02-05 Thread Michael Bayer
On Feb 5, 2014, at 6:32 PM, Matt Phipps matt.the.m...@gmail.com wrote: I've been investigating this a little further and think I found some other issues. Our data team changed the stored procedure to stop aliasing the column names, so passing the mapped columns right into .columns() is

[sqlalchemy] instance is not bound to a session

2014-02-05 Thread nathan
Hi, I'm looping writing Media objects with SA, which are just rows in the db that represent media files. The same Account object/instance is used during each iteration of the loop and contains the user's username, among other things. account =

[sqlalchemy] Re: instance is not bound to a session

2014-02-05 Thread Jonathan Vanasco
When you called 'commit', the 'account' object got expired. There are a few ways in the FAQ or Wiki to deal with this. IIRC, you can `merge` objects back into the session or `refresh` the object. One or both might hit the database. It would probably be better to change your code a bit, so