Summary:ASTERISK-09879: Results containing spaces from FETCH cause ast_yyerror()
Reporter:James Brindle (jamesb63)Labels:
Date Opened:2007-07-15 09:54:31Date Closed:2011-06-07 14:02:41
Versions:Frequency of
Description:When executing a query and getting its result, a field in a mysql table containing a space causes the following error:

[Jul 15 16:06:13] WARNING[30551]: ast_expr2.fl:398 ast_yyerror: ast_yyerror():  syntax error: syntax error, unexpected '<token>', expecting $end; Input:
James Mobile

With the ^ under the M

The query is simply:

select cidname from caller_id where cidnum = '${CALLERID(num)}';

If I remoe the space in the table and replace with _ (underscore), the problem goes away.

This may not be the right category to post the bug but it's a result of using the MYSQL() command from the addons package that I found the problem.
Comments:By: Tilghman Lesher (tilghman) 2007-07-15 11:48:57

Please paste in here the EXACT dialplan that is causing this error.  I suspect that the problem is not in Asterisk, but that you aren't quoting an argument with spaces.

By: James Brindle (jamesb63) 2007-07-16 02:32:14

Here is the entire macro in question:

---- CUT ----
macro setcidprefix(lineprefix) {
 if ("${connID}" != "") {
   MYSQL(Query resultID ${connID} select cidname from caller_id where cidnum='${CALLERID(num)}');
   if ("${resultID}" != "") {
     MYSQL(Fetch fetchID ${resultID} CID_NAME);
     if ("${CID_NAME}" != "") {
       CALLERID(name) = ${CID_NAME};
     } else {
       CALLERID(name) = ${CALLERID(num)};
     MYSQL(Clear ${resultID});
   MYSQL(Disconnect ${connID});
 } else {
   NoOp(Couldn't connect to database);
 CALLERID(num) = "9${CALLERID(num)}";

 // if the lineprefix is empty we don't prepend anything to the caller ID name
 if ("${lineprefix}" != "") {
   CALLERID(name) = "${lineprefix}: ${CALLERID(name)}";
---- CUT ----

It's the FETCH call that generates the error and seems to be when it attempts to transfer the result from the returned row into a variable.

The field "cidname" in the table "caller_id" contains spaces.  The value it was attempting to return was "James Mobile", however, after the error, only the value "James" was found in the CID_NAME variable.

Hope this helps

By: Steve Murphy (murf) 2007-07-16 16:49:53

I've got some documentation on the "space problem" that results from variable expansion; see the doc/channelvariables.txt file, the section

You can force the expression parser to accept a space-containing value as a single token by wrapping it in double quotes.

Also, saying something like:


is dangerous if CID_NAME can contain spaces, because the right hand side of the
assignment is enclosed with $[..] when it's compiled. You can prevent the
evaluation of the right hand side by using the Set application:


Reopen this bug if you feel that I am grossly in error, didn't understand your problem, or you perceive that I am in la-la land.