• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

Asterisk PBX and MYSQL Syntax

I have a the following dial plan:
[Test]
exten => s,1,MYSQL(Connect CONNID 10.0.5.20 root password timecard)
exten => s,n,GotoIf($["${MYSQL_STATUS}" = "-1"]?lbl_Test_0:)
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ blockedcallerid.callerid=\'${LogCallerID}\'\ AND\ blockedcallerid.blocked\ =\ 1;)
exten => s,n,GotoIf($["${MYSQL_STATUS}" = "-1"]?lbl_Test_0:)
exten => s,n(lbl_Test_1),MYSQL(Clear ${ResultID})
exten => s,n,GotoIf($["${MYSQL_STATUS}" = "-1"]?lbl_Test_2:)
exten => s,n,MYSQL(Disconnect ${CONNID})
exten => s,n,GotoIf($["${MYSQL_STATUS}" = "-1"]?lbl_Test_2:)
exten => s,n(lbl_Test_2),Return()
exten => s,n(lbl_Test_0),NoOp(****ERROR****SQL Command Failed)
exten => s,n,Goto(lbl_Test_1)

The line with SQL Query is where I am having problems:
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ blockedcallerid.callerid=\'${LogCallerID}\'\ AND\ blockedcallerid.blocked\ =\ 1;)

The CLI Debug window has the following displayed when it hits the SQL Query Line:
     -- Executing [s@Test:3] MYSQL("SIP/238-acf019e0", "Query ResultID 9 SELECT COUNT(*") in new stack
[Feb 18 13:21:33] WARNING[20598]: app_addon_sql_mysql.c:270 aMYSQL_query: aMYSQL_query: mysql_query failed. Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

The MYSQL query.log just shows: SELECT COUNT(*
The SQL query is being truncated after the *

My question is what is the syntax for the SQL string...
0
bullet117
Asked:
bullet117
  • 4
  • 3
1 Solution
 
Ron MalmsteadInformation Services ManagerCommented:
Try it like this...
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT\ FROM\ blockedcallerid\ WHERE\ blockedcallerid.callerid='${LogCallerID}'\ AND\ blockedcallerid.blocked='1')

Open in new window

0
 
Ron MalmsteadInformation Services ManagerCommented:
sorry...like this...  
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ blockedcallerid.callerid='${LogCallerID}'\ AND\ blockedcallerid.blocked='1')
0
 
Ron MalmsteadInformation Services ManagerCommented:
lol....sorry....again...  I think you were referencing the table as well...  "blockedcallerid.callerid"...  It should just be the column name...  "callerid" and "blocked".

Like this,...
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ callerid='${LogCallerID}'\ AND\ blocked='1')
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
bullet117Author Commented:
xuserx2000: You helped a lot the final syntax for this was:
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ callerid=\'10.0.5.238\'\ AND\ blocked=1)

I needed to add the \ in front of the tick marks and deleted the tick marks from the numeric field (blocked)...Thanks for your help....
0
 
bullet117Author Commented:
xuserx2000: I'm getting as bad as you..Ha...Ha...Ha

Here is the final final syntax:
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ callerid=\'${LogCallerID}\'\ AND\ blocked=1)
0
 
bullet117Author Commented:
Thank you for your help, The only thing I had to add was a \ in front of the   ` (ticks)
Here is the final syntax:
exten => s,n,MYSQL(Query ResultID ${CONNID} SELECT\ COUNT(*)\ FROM\ blockedcallerid\ WHERE\ callerid=\'${LogCallerID}\'\ AND\ blocked=1)

)...Thanks again...Brian
0
 
Ron MalmsteadInformation Services ManagerCommented:
cool.

Thanks,
R
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now