I only started Asterisk a couple of days ago, so I might be missing something.
For the past 15 years I have been using Dialogic soft- and hardware, so it’s a bit of a culture shock as how easy most stuff is implemented.
Unfortunately I have been pondering over the following all day so I hope someone might point me in the right direction.
I am using CentOS 6.5 and Asterisk 11.12.0.
Currently no packages are updated, just the RPM’s on the CentOS DVD’s.
There are 2 issues :
-
INSERTING a new record and getting the LAST_INSERT_ID() without the possibility that another call inserts a new record while I still need to get the ID. In C I used to lock the MySQL thread, but I don’t think that can be done. Or does each call has it’s own MySQL connection ?
I have a specific asterisk_insert in func_odbc.conf for that, but I am not sure if that is the correct way to do this. -
When using commands containing (), such as now and LAST_INSERT_ID() I get starnge errors.
I tried all kinds of permutations to get it working using double quotes, Q_r and Q_w, escaping ( and ) but to no avail.
[Sep 19 17:32:36] VERBOSE[2901][C-00000048] pbx.c: -- Executing [9991@from-internal:46] Set("SIP/6002-00000046", "Q="INSERT INTO callsystem.history SET IServer=1,Project='LOOKUP',CallerId='6002',Status='ONLINE'") in new stack
[Sep 19 17:32:36] WARNING[2901][C-00000048] func_odbc.c: SQL Execute returned an error -1: 42000: [MySQL][ODBC 5.1 Driver][mysqld-5.1.71]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 'Q' at line 1 (186)
[Sep 19 17:32:36] WARNING[2901][C-00000048] func_odbc.c: SQL Exec Direct failed (-1)![Q]
[Sep 19 17:32:36] WARNING[2901][C-00000048] res_odbc.c: SQL Execute error! Verifying connection to asterisk [MySQL-Asterisk]...
[Sep 19 17:32:36] WARNING[2901][C-00000048] func_odbc.c: SQL Execute returned an error -1: 42000: [MySQL][ODBC 5.1 Driver][mysqld-5.1.71]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 'Q' at line 1 (186)
[Sep 19 17:32:36] WARNING[2901][C-00000048] func_odbc.c: SQL Exec Direct failed (-1)![Q]
[Sep 19 17:32:36] ERROR[2901][C-00000048] func_odbc.c: Unable to execute query [Q]
[Sep 19 17:32:36] VERBOSE[2901][C-00000048] pbx.c: -- Executing [9991@from-internal:47] Set("SIP/6002-00000046", "R=") in new stack
When not using commands containing () everything is OK.
[Sep 19 17:33:35] VERBOSE[2907][C-00000049] pbx.c: -- Executing [9991@from-internal:46] Set("SIP/6002-00000047", "Q="INSERT INTO callsystem.history SET IServer=1,Project='LOOKUP',CallerId='6002',Status='ONLINE'") in new stack
[Sep 19 17:33:35] VERBOSE[2907][C-00000049] pbx.c: -- Executing [9991@from-internal:47] Set("SIP/6002-00000047", "Q_w()="INSERT INTO callsystem.history SET IServer=1,Project='LOOKUP',CallerId='6002',Status='ONLINE'") in new stack
[Sep 19 17:33:35] VERBOSE[2907][C-00000049] pbx.c: -- Executing [9991@from-internal:48] NoOp("SIP/6002-00000047", "") in new stack
This is my query in extensions.conf for the working part.
same = n,Set(Q="INSERT INTO callsystem.history SET IServer=${IServer},Project='${Project}',CallerId='${ANI}',Status='ONLINE';")
same = n,Set(Q_w()=${Q})
This is my query in extensions.conf when it is showing the errors.
same = n,Set(Q="INSERT INTO callsystem.history SET IServer=${IServer},SIVR=NOW(),EIVR=NOW(),Project='${Project}',CallerId='${ANI}',Status='ONLINE';")
same = n,Set(Q_w()=${Q})
This is my func_odbc.conf
[code][r]
prefix=Q
dsn=asterisk
readsql=${ARG1}
[w]
prefix=Q
dsn=asterisk
writesql=${VAL1}
[history]
prefix=insert
dsn=asterisk
writesql=INSERT INTO callsystem.history SET IServer=${ARG1},SIVR=NOW(),EIVR=NOW(),Project=’${ARG2}’,CallerId=’${ARG3}’,Status=‘ONLINE’;
readsql=SELECT LAST_INSERT_ID() FROM callsystem.history LIMIT 1;[/code]