1

When I was trying to call the MySQL stored procedure using cursor.callproc() I encountered some problems. When there were multiple input and output parameters, there was no problem and everything works fine as following: I created procedure in MySQL like this with 5 input/output parameters:

create procedure enrollclass(in yeartime int, in quartertime char(20), in stid char(20), in course_no char(20), out result int) 

and call procedure in python using something like this:

arg2 = ('2016', 'Q2', info[0][0], course_no, 0)
ac = cursor.callproc('enrollclass',arg2)

this worked fine. However, if I called another procedure with only one input parameter (with no output parameter) like this:

create procedure prerequisite( in course_no char(20))

and called the procedure using this line:

  arg3 = ('INFO1101')
  cursor.callproc('prerequisite', arg3)

then the system kept giving me error message 'args must be a sequence'. I have no idea how to fix it since I have no other argument to form a sequence. Could someone tell me what's going on here? Thanks!

1
  • when creating args, instead of round brackets ( ) user square brackets [ ] and it should work. Commented Nov 8, 2017 at 9:38

1 Answer 1

3

You might think that

arg3 = ('INFO1101')

would create a tuple containing a single element, but it doesn't. In that context the parentheses act as "order of operations" specifiers, e.g.

foo = (2 + 1) * 4

To create a single-element tuple you need to add a comma, as in

arg3 = ('INFO1101',)
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.