python 2.7 - mysql.connector, multi=True, sql variable assignment not working -
sql code (all in 1 file saved in python variable "query"):
select @dtmax:=date_format(max(dt), '%y%m') table_a; delete table_b date_format(dt, '%y%m')=@dtmax;
does mysql-connector allow use of variable assignment i've done in query above. i.e. take value of max(date) table_a , delete date table_b.
python code:
c = conn.cursor(buffered=true) c.execute(query, multi=true) conn.commit() conn.close()
all know 2nd sql statement doesnt execute.
i can copy , paste sql code toad , run there without problems not through mysql.connector library. have used pandas legacy script written else , don't have time re-write everything.
i kindly appreciate help.
when use multi=true
, execute()
return generator. need iterate on generator advance processing next sql statement in multi-statement query:
c = conn.cursor(buffered=true) results = c.execute(query, multi=true) cur in results: print('cursor:', cur) if cur.with_rows: print('result:', cur.fetchall()) conn.commit() conn.close()
cur.with_rows
true
if there results fetch current statement.
this describend in documentation of mysqlcursor.execute()
Comments
Post a Comment