I try to insert some data in a table from the dialplan, but it seems that something is wrong since no row is created after the exection of the following:
From the mysql manual it says that the alternate syntax
insert into x set a=b,c=d
is acceptable.
Check for error messages in /var/log/mysql to begin with.
How are you checking to see if the record has been added? If using browser did you refresh the access to the db? It might be there all along but waiting to be discovered…
you learn something new every day … i too many years, i’ve never written an insert statement like that … the pedant in me
just been playing with this, it turns out you should escape the ‘,’ too !! try exten => s,n,Read(number|beep|10)
exten => s,n,MYSQL(Connect connid 127.0.0.1 aaa aaa aaa)
exten => s,n,MYSQL(Query resultid ${connid} INSERT\ INTO\ client\ set\ uniqueid=${UNIQUEID}\,number=${number})
exten => s,n,MYSQL(Disconnect ${connid})
I use phpmyadmin to check if the records are actually added. When I insert a record to the table from the prompt, I see directly it is added by refreshing phpmyadmin. I do the same after executing the dialplan, but no new record added.
I do not have the file /var/log/mysql. I just have /var/log/mysqld.log in which nothing related to the execution of the code.
baconbuttie,
I added the “” after uniqueid=${UNIQUEID}, but still doesn’t work.
Do you have a directory /var/log/mysql inside which there might be a file which contains info about errors logged? Otherwise you might want to check where your install of mysql has been instructed to store this info (mysql.cnf/my.ini?). Do you have anything in /var/log/messages?
when i was playing with this (away from the office now), i was getting errors seen in the /var/log/asterisk/full log … but nothing in the CLI itself with verbosity set at 10.
according to the log, the “,” was being interpreted as a “|” (like other Asterisk applications/functions).
after the Clear and Close i also had a PlayDTMF($MYSQL_STATUS}) to read out the result … was always 0 (success) regardless !
here’s the log. Note that I removed the “” after ${UNIQUEID} in the INSERT command. Otherwise, in the log file you have “|” instead of “,”.
Oct 13 10:58:42 VERBOSE[6400] logger.c: – Executing Goto(“SIP/3001-108e”, “Leave-Number|s|1”) in new stack
Oct 13 10:58:42 VERBOSE[6400] logger.c: – Goto (Leave-Number,s,1)
Oct 13 10:58:42 VERBOSE[6400] logger.c: – Executing Playback(“SIP/3001-108e”, “after-the-tone”) in new stack
Oct 13 10:58:42 DEBUG[6400] channel.c: Scheduling timer at 160 sample intervals
Oct 13 10:58:42 VERBOSE[6400] logger.c: – Playing ‘after-the-tone’ (language ‘en’)
Oct 13 10:58:43 DEBUG[6400] channel.c: Scheduling timer at 0 sample intervals
Oct 13 10:58:43 DEBUG[6400] channel.c: Scheduling timer at 0 sample intervals
Oct 13 10:58:43 VERBOSE[6400] logger.c: – Executing Read(“SIP/3001-108e”, “number|beep|10”) in new stack
Oct 13 10:58:43 VERBOSE[6400] logger.c: – Accepting a maximum of 10 digits.
Oct 13 10:58:43 DEBUG[6400] channel.c: Scheduling timer at 160 sample intervals
Oct 13 10:58:43 VERBOSE[6400] logger.c: – Playing ‘beep’ (language ‘en’)
Oct 13 10:58:44 DEBUG[6400] channel.c: Scheduling timer at 0 sample intervals
Oct 13 10:58:44 DEBUG[6400] channel.c: Scheduling timer at 0 sample intervals
Oct 13 10:58:54 VERBOSE[6400] logger.c: – User entered '022455526’
Oct 13 10:58:54 VERBOSE[6400] logger.c: – Executing MYSQL(“SIP/3001-108e”, “Connect connid 127.0.0.1 aaa aaa aaa”) in new stack
Oct 13 10:58:54 VERBOSE[6400] logger.c: – Executing MYSQL(“SIP/3001-108e”, “Query resultid 1 INSERT INTO client set uniqueid=asterisk-6308-1160729883.0,number=022455526”) in new stack
Oct 13 10:58:54 VERBOSE[6400] logger.c: – Executing MYSQL(“SIP/3001-108e”, “Disconnect 1”) in new stack
Oct 13 10:58:54 VERBOSE[6400] logger.c: – Executing Playback(“SIP/3001-108e”, “goodbye”) in new stack
Oct 13 10:58:54 DEBUG[6400] channel.c: Scheduling timer at 160 sample intervals
Oct 13 10:58:54 VERBOSE[6400] logger.c: – Playing ‘goodbye’ (language ‘en’)
Oct 13 10:58:55 DEBUG[6400] channel.c: Scheduling timer at 0 sample intervals
Oct 13 10:58:55 DEBUG[6400] channel.c: Scheduling timer at 0 sample intervals
Oct 13 10:58:55 VERBOSE[6400] logger.c: – Executing Hangup(“SIP/3001-108e”, “”) in new stack
Oct 13 10:58:55 VERBOSE[6400] logger.c: == Spawn extension (Leave-Number, s, 7) exited non-zero on ‘SIP/3001-108e’
Hmmm, I just tried inserting a record into char fields without quotes and it worked fine. My first test was using int fields. Latest theory shot to nothing.
Is it time to consider whether your version of asterisk-addons is suitable for your version of asterisk? One of the caveats on compile is to ensure that you upgrade the addons at the same time as upgrading the asterisk server. What versions are you using? Do you get any notifys when asterisk starts up?
yes, i can’t check again now 'cos i’m off-site, but i was doing the same as you … checking with phpMyAdmin … and the code i’ve pasted is what i used when the record went in … except the username and password has been changed.
it’s not a permissions issue for the user you’re connecting with is it ?
Thanks guys, I found the problem. It couldn’t insert records with ‘uniqueid’=’${UNIQUEID}’. The correct syntax is ‘uniqueid’=’"${UNIQUEID}"’. It seems that without " ", the ${UNIQUEID} (that is something like asterisk-2688-1160986278.32) cannot be converted into VARCHAR. Starange.