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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With