Func_odbc and diaplan issues

Hi all!

here is part of my dialplan, upon hangup events:

exten => h,1,NoOp("Hangup") exten => h,n,SET(ODBC_TEST_INSERT( ${CDR(start)}, ${CDR(clid)}, ${CDR(src)} , ${DESTINATIONCALL} , ${CDR(dcontext)} , ${CDR(channel)} , ${CDR(dstchannel)}, ${CDR(lastapp)}, ${CDR(lastdata)} , '${CDR(duration)}', '${CDR(billsec)}' , ${CDR(disposition)} ,0, ${CDR(accountcode)} , ${CDR(uniqueid)} , ${CDR(userfield)} )=1)

the func_odbc is as follows:

[TEST_INSERT] dsn=SQLCLUSTER_PHONEHOUSE write=INSERT INTO cdr ([calldate],[clid],[src],[dst],[dcontext],[channel],[dstchannel],[lastapp],[lastdata],[duration],[billsec],[disposition],[amaflags],[accountcode],[uniqueid],[userfield]) VALUES ( '${ARG1}', '${ARG2}', '${ARG3}','${ARG4}','${ARG5}','${ARG6}','${ARG7}','${ARG8}','${ARG9}',${ARG10},${ARG11},'${ARG12}', '${ARG13}','${ARG14}','${ARG15}','${ARG16}')

Problems are:
1 - if ANY argument includes a = character, the query fails. Example: if argument related to CDR(lastapp) is something like “CALL=ok” then the query fails. If the same argument CDR(lastapp) equals to “CALL OK”, everything works!
2 - if, instead of using a prepared statement like INSERT INTO described above, i use a exec InsertCDR(…) passing arguments, NO stored procedures is calls.

i’m using ODBC and SQLServer 2005, and FreeTDS drivers.
Asterisk is Asterisk 1.4.18, on a Linux version 2.6.18-53.1.21.el5

Also, i’m wondering if there is any possibility to change CDR database according to the extensions.conf context? i mean, if it is possible to specify for each context where to save the CDR data, specifying Database, Server, Table. This is because i have 20 Asterisk Servers on HP DL460, all of them with 4 to 12 PRIs channel banks, being used for TV and Radio contests, receiving thousands of calls per hour. Each TV show/contest has its own database and dialplan context, and it would be great if i could change the target server/database/table via the Dialplan context.

exten => _X., 1, SetCDROutput(server1, database1, table1)
exten => _X., 1, SetCDROutput(server2, database2, table1)

Thanks in advance,