Yasin Caner
Yasin Caner

Reputation: 151

Function odbc cannot be read - Asterisk

i am working on getting numbers from soft phone and then inserting in mysql db. all drivers and stuffs is ok. i configure them. i can select /poll all my datas. but i cant insert my new data. my func_odbc.conf likes that;

[ADDX];

dsn=asterisk
writesql = INSERT INTO aktarma (musterino,aktartel) values (${VAL1},${VAL2})

and my extensions.conf is ;

exten=>_X.,n(sqlekle),SET(a=${ODBC_ADDX(${digit},${aktartel})})

i checked my variables ${digit} and ${aktartel} is right it gives error as ;

[Jan 30 05:43:21] ERROR[4601]: pbx.c:3380 ast_func_read: Function ODBC_ADDX cannot be read
-- Executing [XXXXXXXXX@phones:30] Set("SIP/out-0000001a", "a=") in new stack

So what is wrong friends. i cannot find a way to solve this Thanks a lot.

Upvotes: 0

Views: 4488

Answers (3)

Apache
Apache

Reputation: 23

it is strange that i can not update the database with writesql='' but readsql='' get executed. Asterisk version 18

so I ended up using below func_odbc.conf

[myfunction2]
prefix=ODBC
writehandle=MySQL-asterisk
readsql=UPDATE callog SET caller=${SQL_ESC(${ARG1})} WHERE id='11'

Upvotes: 0

miken32
miken32

Reputation: 42757

It's a year late but I'm going to answer this to help anyone coming from search land like I was.

In your func_odbc.conf you are trying to write VAL1 and VAL2 but in fact you want to use ARG1 and ARG2; in the dialplan that follows, VAL1 and VAL2 are not set (they would come after the =)

[ADDX]
dsn=asterisk
writesql = INSERT INTO aktarma (musterino,aktartel) VALUES (${ARG1},${ARG2})

One more note, it's always good practice to escape and quote your SQL input; you never know when some bastard is going to press "A" on his DTMF keypad just to keep you on your toes! In your query use '${SQL_ESC(${ARG1})}':

INSERT INTO aktarma (musterino, aktartel) VALUES ('${SQL_ESC(${ARG1})}', '${SQL_ESC(${ARG2})}')

Moving on to your dialplan: you were trying to read a value from the function which is only a write function. Even if you aren't reading a value, you still need an = in your Set command to avoid errors, but it should be at the end. Also the function doesn't need to be wrapped in ${} for writing.

exten=>_X.,n(sqlekle),Set(ODBC_ADDX(${digit},${aktartel})=)

Regarding ARG vs VAL, here is an example that uses both:

[ADDX]
dsn=asterisk
writesql = INSERT INTO aktarma SET ${ARG1}='${VAL1}', ${ARG2}='${VAL2}'

We use both VAL and ARG; then put this in the dialplan:

exten=>_X.,n(sqlekle),Set(ODBC_ADDX(musterino,aktartel)=${digit},${aktartel})

So ARGx is passed as an argument to the function, while VALx is on the right-hand side of the Set call.

There is little documentation available on how this works; hopefully this helps someone.

Upvotes: 1

arheops
arheops

Reputation: 15259

You have use write-only functions in left part of assigment.

[PRESENCE]
dsn=mydb
writesql=UPDATE `locationtable` SET `location`=${SQL_ESC(${VAL1})}` WHERE `username`='${SQL_ESC(${ARG1})}'

extensions.conf:

exten => 1234,1,NoOp(Set and read location)
exten => 1234,n,Set(ODBC_PRESENCE(${EXTEN})=office)

Upvotes: 0

Related Questions