* You are viewing Posts Tagged ‘mysql query’

What is wrong in m

Hi everyone,

What is wrong in below asterisk application? The output should be content of
field booth_status from table booths:

[extension-status]
exten => _X.,1,MYSQL(Connect connid 127.0.0.1 root password my-extensions)
exten => _X.,n,MYSQL(Query allow_call ${connid} SELECT extension_status FROM
mytable WHERE extension=${CALLERID(num)} ORDER BY id DESC LIMIT 1)
exten => _X.,n,NoOp(allow_call is: ${allow_call})

But I get:
*”allow_call is: 4″ *while it should actually be ACTIVE or INACTIVE

I want to read the LAST record found under column “extension” in “mytable”
and do a NoOp for it’s contents. But instead I am getting 4 which I think
refers to the connection ID?!

***There is only one record in my table right now.

Thanks,

mysql call stored procedure

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?

How to use MYSQL(Set timeout x)

I use Asterisk 1.6.2.11 and this is my dialplan:

[test]
exten => 9999,1,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,Answer()
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,PlayBack(hello-world)
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,MYSQL(Set timeout 2)
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,MYSQL(Connect connid localhost user pass asterisk)
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,MYSQL(Query resultid ${connid} SELECT SLEEP(10))
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,MYSQL(Fetch fetchid ${resultid} RESULT)
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,MYSQL(Clear ${resultid})
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,MYSQL(Disconnect ${connid})
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,NoOp(Result: ${RESULT})
exten => 9999,n,NoOp(${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
exten => 9999,n,Hangup()

When i call to 9999 this is the CLI output:

Connected to Asterisk 1.6.2.11 currently running on Asterisk (pid = 2092)
Verbosity is at least 2147483647
Asterisk*CLI>
== Using SIP RTP CoS mark 5