If I were to go into my MySQL DB and

mysql> SET GLOBAL sql_mode='STRICT_TRANS_TABLES';

would that have the same effect? I find the MySQL documentation 
<https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html> somewhat lacking on 
that topic. What are the scope and lifetime of the above vs. using a 
listener as suggested by Michael?



On Wednesday, February 5, 2014 at 2:08:00 PM UTC-8, Michael Bayer wrote:
>
> 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.lis...@eisenbits.com 
> <javascript:>> 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+...@googlegroups.com <javascript:>. 
> > To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>. 
> > Visit this group at http://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to