Problem with query

Hi friends
I have the problem with the query
In the message find this error

app_mysql.c:417 aMYSQL_query: aMYSQL_query: mysql_query failed. Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘\ Number\ from\ _numbersEnabled’ at line 1

And this the query with error

exten => _.,n,MYSQL(Query resultid ${connid} SELECT\ Number\ from\ _numbersEnabled\ where\ Number={$EXTEN})

I find on internet but dont find the problem.

MYSQL app it is deprecated, also you have an issue with the query, I was about this app and it says “NOTE, using the backslash “escape” character in front of spaces and other special characters, as is done above in the SELECT command, is no longer needed as of asterisk 1.6.x, in fact it will cause the commands to fail.”

maybe, check your asterisk module!
specaily app_mysql.so in /usr/lib/asterisk/module or /usr/lib64/asterisk/module

I think the module is correctly loaded, as the error point specifically to Query format issue.

app_mysql.c:417 aMYSQL_query: aMYSQL_query: mysql_query failed. Err

Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘\ Number\ from\ _numbersEnabled’ at line 1

Thanks. you’re right!!

1 Like

Hi ambiorixg12 i try with and without backslash but dont work and have same error

I have this extension.conf

exten => _X.,3,MYSQL(Connect connid localhost mouse password database)
exten => _X.,4,MYSQL(Query resultid {connid} SELECT\ Enabled\ FROM\ _numbersEnabled\ WHERE\ Number={CALLERID})

I try the QUERY on MYSQL and work but when is in extension dont work.
How can try the connection on SQL?

Shell Function easiest method
ODBC recommended method

I check but the configuration is ok.

echo ‘show tables;’ | isql -v db-connect
±--------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
±--------------------------------------+
SQL> show tables;
±-------------------------------------------------------------------------+
| Tables_in_db |
±-------------------------------------------------------------------------+
| _numbersEnabled |
±-------------------------------------------------------------------------+
SQLRowCount returns 1
1 rows fetched

odbc show

ODBC DSN Settings

Name: MySQL-db
DSN: db-connect
Last fail connection attempt: 2020-01-19 20:34:14
Number of active connections: 0 (out of 1)
Logging: Disabled

I want check from extension it is work.

I think MYSQL function doesnt use ODBC, assuming query is OK, try using ODBC directly or Shell function as I made reference before

I try and work

echo ‘select Number from _numbersEnabled where Number=961557221386;’ | isql -v db-connect

select Number from _numbersEnabled where Number=961557221386;
±----------------------------------------------------------------+
| Number |
±----------------------------------------------------------------+
| +961557221386 |
±----------------------------------------------------------------+
SQLRowCount returns 1
1 rows fetched

I mean use ODBC, it s that instead of use MYSQL command switch to func_odbc on the dial plan

Scuse me but i dont know.
How can I do?

http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/getting_funky.html

This is crazy
I remove the backslash and now i dont have the problem and the query work

congrats!

I check it out at CentOS 6 + Asterisk 16 + MySQL 5.5.62
https://hsunryou.blog.me/221707313582?Redirect=Log&from=postView

I pointed about that on my first post, but you said you tried without and with it

Yes i try with and without backslash.
It is a possibile that it was a space?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.