mysql call stored procedure

Home » Asterisk Users » mysql call stored procedure
Asterisk Users 1 Comment

Hi Guys,
I am getting an error when executing another mysql query in dialplan after
calling stored procedure.
If calling the procedure from mysql cli it gives a result like:
mysql> call call_control(78236721,1000,1233);
+——+
| pass |
+——+
| 1 |
+——+
So I need asterisk to recognize this pass and take some actions based on
what the pass value is.
Dialplan looks like this:

MYSQL(Connect connid ${DBDefaultHost} ${DBuser} ${DBpass} ${DBname})
MySQL(Query resultid ${connid} CALL call_control(78236721,1000,1233))
MySQL(Fetch fetchid ${resultid} pass)
MYSQL(clear ${resultid})
MySQL(Query resultid ${connid} SELECT/INSERT whatever from table)

So, it gives me this pass value correct, but if I execute some other query
INSERT or SELECT after clearing the result, it gives me an error
[May 17 16:16:13] WARNING[19572]: app_addon_sql_mysql.c:374 aMYSQL_query:
aMYSQL_query: mysql_query failed. Error: Commands out of sync; you can’t run
this command now
The error disappears if I reconnect to mysql after calling the stored
procedure but it seams not right to me to connect to mysql 2 times for 1
call.

Did anyone have the same issue?

One thought on - mysql call stored procedure

  • MYSQL(Nextresult resultid ${connid}) after MySQL(Fetch fetchid ${resultid}
    pass) helped to resolve this.
    you should always get all results sp produce otherwise mysql returns error.