4

I have a MySQL stored procedure called test which accepts one argument. I can execute the stored procedure from python 2.7x using below code

data='Teststr'
cur = db.cursor()
cur.execute("CALL test('{0}')".format(data))

But when I use

data='Teststr'
cur = db.cursor()
cur.callproc('test',data)

I am encountering

OperationalError: (1318, 'Incorrect number of arguments for PROCEDURE MyDb.test; expected 1, got 7')

Looks like python treats each character as one argument. What am I missing here?

1 Answer 1

8

You want cur.callproc('test', (data,)) to pass a tuple of 1 element

eg:

>>> a = 'hello'
>>> len(a) # just a
5
>>> len( (a) ) # still just a
5
>>> len( (a,) ) # single element tuple containing a
1
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.