0

I've got such a method:

from app.database import db

def get_channels_list(user_token):
    data = jwt.decode(user_token, app.config.get('JWT_SECRET'))
    connection = db.engine.raw_connection()
    try:
        cursor = connection.cursor()
        cursor.callproc("permission_list_user", [958539, 'web'])
        results = list(cursor.fetchall())
        cursor.close()
        connection.commit()
    finally:
        connection.close()
    print(len(results))
    return success(results)

And when I run it I get len(results) == 0 but when I run the same procedure via mysql console like that:

CALL permission_list_user(958539, 'web');

I get results it should return.

Maxim
  • 52,561
  • 27
  • 155
  • 209
michalSolarz
  • 485
  • 6
  • 18
  • do you call from the same MySQL account? It could happen if you don't have EXECUTE privilege – Marat Mar 23 '17 at 15:17
  • I guess so because when I run this: `cursor.execute("select * from users limit 10;")` instead of callproc I get results – michalSolarz Mar 23 '17 at 15:25
  • Ok, I've figured it out from code posted here: http://stackoverflow.com/questions/15320265/cannot-return-results-from-stored-procedure-using-python-cursor – michalSolarz Mar 23 '17 at 16:11

1 Answers1

1

I`m having the same problem, I didn't like the way, but I solved running a SELECT query after call the procedure:

query ='call loginAPI("{0}","{1}",@logged, @hashAPI)'.format(user,password)
 select = 'select @logged, @hashAPI'

  cursor.execute(query)
  cursor.execute(select)
  rv = cursor.fetchall()

Looking for prettier solution.

  • I reviewed how to access the results of calling stored procedures in [this answer](https://stackoverflow.com/a/59546157/5320906) – snakecharmerb Dec 31 '19 at 15:54