I've thrown up no less than five dragons in the docs for these flags that should be up by now. I'm evaluating if I can deprecate these flags for 1.3 since really everything thats py2k only should be heading towards deprecation.
On Fri, Dec 21, 2018, 11:48 AM Mike Bayer <[email protected] wrote: > On Fri, Dec 21, 2018 at 11:29 AM mdob <[email protected]> wrote: > > > > Hi, > > > > I was looking into create_engine options enocding and convert_unicode > and it seems it works for ORM but not for executing raw sql. > > Is that intentional or I'm missing something? > > the MySQL DBAPIs already handle unicode conversion by default, and as > your URLs do not include ?use_unicode=0 (which is a flag specific to > pymysql, mysqlclient and mysql-python DBAPIs), this capability is > turned on. This flag used to be documented in the SQLAlchemy docs > but as there is no reason to use use_unicode=0 with modern DBAPIs, > these docs have been removed. > > The SQLAlchemy convert_unicode flag, which should be considered very > legacy at this point, doesn't do anything if the DBAPI is already > doing unicode conversion for us, unless you send > convert_unicode='force'. This is documented at > > https://docs.sqlalchemy.org/en/latest/core/type_basics.html#sqlalchemy.types.String.params.convert_unicode > . > > But as the docs should indicate, perhaps not strongly enough, there is > no reason to use this flag with modern DBAPIs, all of which now > natively support unicode. > > > > > > > > from sqlalchemy import create_engine > > from sqlalchemy.orm import Session > > from sqlalchemy.ext.automap import automap_base > > from sqlalchemy.sql import text > > > > def get_first_name(engine): > > row = engine.execute(text('SELECT FirstName FROM Customer LIMIT > 1')).fetchone() > > print row[0] > > > > Base = automap_base() > > Base.prepare(engine, reflect=True) > > Customer = Base.classes.Customer > > c1 = Session(engine).query(Customer).first() > > print c1.FirstName > > print 5*'--' > > > > > > engine = create_engine('mysql://chinook:[email protected]:3309/Chinook') > > unicode_engine = create_engine('mysql:// > chinook:[email protected]:3309/Chinook', encoding='latin1', > convert_unicode=True) > > > > get_first_name(engine) > > get_first_name(unicode_engine) > > > > > > The output was > > Lu�s > > Lu�s > > ---------- > > Lu�s > > Luís > > ---------- > > > > Kind regards, > > Michal > > > > -- > > 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 [email protected]. > > To post to this group, send email to [email protected]. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
