On Tuesday, January 8, 2019 at 11:29:04 PM UTC+8, Cédric Krier wrote:
> On 2019-01-08 06:55, pingfanrenwei...@gmail.com wrote:
> > 'The flavor of python-sql allows you to use almost any database using any 
> > PEP 249 python library.'
> > 
> > But I still don't know how to use it in mysql.
> > 
> > conn = MySQLdb.Connect(unix_socket = config.mysql_sock,
> >                                user = config.mysql_user,
> >                                passwd = secret,
> >                                connect_timeout=10,
> >                                charset="utf8",
> >                                cursorclass = MySQLdb.cursors.DictCursor)
> > cursor = conn.cursor()
> > 
> > user = Table('user')
> > select = user.select()
> > select.where = user.EnglishName=='testname'
> > 
> > How to excute it ?
> > cursor.execute(select) ?
> > cursor.execute(tuple(select) ?
> 
> You must run:
> 
>     cursor.execute(*select)
> 
> The query object is iterable and return the query string follwed by the
> params.
> 
> Or if you prefer you can also run:
> 
>     cursor.execute(str(select), select.params)
> 
> 
> -- 
> Cédric Krier - B2CK SPRL
> Email/Jabber: cedric.kr...@b2ck.com
> Tel: +32 472 54 46 59
> Website: http://www.b2ck.com/

Thanks very much.
In my Mysql, I need to set :
mysql> SET SESSION SQL_MODE=ANSI_QUOTES;

But there are another problem.
>>> select.where = user.name == 'foo'
>>> tuple(select)
('SELECT "a"."id", "a"."name" FROM "user" AS "a" WHERE ("a"."name" = %s)', 
('foo',))
In MySQL, it run like:

mysql>SELECT "a"."id", "a"."name" FROM "user" AS "a" WHERE ("a"."name" = foo)
which foo has no quotes?

-- 
You received this message because you are subscribed to the Google Groups 
"python-sql" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python-sql+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to