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 = create_engine("mysql://scott:tiger@localhost/test", echo='debug')

@event.listens_for(eng, "first_connect", insert=True)  # make sure we're the 
very first thing
@event.listens_for(eng, "connect")
def connect(dbapi_connection, connection_record):
    cursor = dbapi_connection.cursor()
    cursor.execute("SET sql_mode = 'STRICT_ALL_TABLES'")

conn = eng.connect()



On Feb 5, 2014, at 3:20 PM, Staszek <stf.list.ot...@eisenbits.com> 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';
> 
> so as to get an error (instead of a warning) when string length exceeds
> column size on INSERT.
> 
> Ideally I would like to be able to combine several SQL modes together.
> List of available MySQL modes:
> http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sql_mode
> .
> 
> Thanks!
> 
> -- 
> http://people.eisenbits.com/~stf/
> http://www.eisenbits.com/
> 
> OpenPGP: 80FC 1824 2EA4 9223 A986  DB4E 934E FEA0 F492 A63B
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to