1

I'm trying to call a stored function from Python code. If I use:

import mysql.connector
from datetime import datetime

with ... as conn
  c = conn.cursor()
  func = "SELECT get_customer_balance(%s, %s)"
  customer_id = 577
  dt = datetime(2015, 6, 30, 18, 5, 30)
  result = c.execute(func, (customer_id, dt))
  val = result.fetchone()

But result.fetchone() call fails because the result is None. I tried also driver's callproc method used for stored procedures, but it fails as it does not recognize get_customer_balance (since it is a stored function).
I can't find any information about this. Would really appreciate some help.
Thanks.

2
  • I'm not a python expert, just want to ask, how did you construct your function also your connection string? is it tested and running? Commented Feb 7, 2017 at 5:56
  • Yes, it run. I had a separate function which created the connection object to the "sakila" database (a demo database from the MySQL site), but I didn't show it here for brevity. Commented Feb 7, 2017 at 19:10

1 Answer 1

1

sorry, my oversight... calling fetchone() on the result instead of the cursor. It actually works:

val = c.fetchone()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.