Writing to mysql from dialplan

I am trying to write a value to a mysql table but I am getting

[2012-08-30 17:08:40] ERROR[26225]: pbx.c:3812 ast_func_read: Function test_timestamp cannot be read

I can read without error but I can not write even though I have root access to the database via ODBC.

Dialplan
same =>n,NoOp(${test_timestamp(${ext})})

My func_odbc.conf has the following
[timestamp]
prefix=test
dsn=asterisk
writesql= UPDATE testdb.acc SET val=1 WHERE acc.ext=’${ARG1}’

Asterisk version 10

First guess:
Don’t use the NOOP function: i guess it searches for a readsql instead of a writesql
use the Set-function

It’s not Noop that actually triggers the read. That is done before the application is run. The ${} syntax triggers the read.

I have had a look at a few examples using the writesql command in func_odbc.conf and it looks like they are doing a readsql first.

I’ve adjusted the my config to this
readsql=SELECT val FROM testdb.acc WHERE ext=’${ARG1}‘
writesql+=UPDATE btestdb.acc SET val=‘1’ WHERE ext=’${ARG1}’

It performs the read ok but doesn’t write

I have also tried this without the +
Does anyone have a working example of a writesql they could share? I’m running Asterisk V10

I think there is a bug in Asterisk V10.x

I have updated the writesql as follows. Works via the mysql cli but now has no effect when executed from the dialplan

writesql=UPDATE btestdb.acc SET val = val + 1 WHERE ext=’${ARG1}‘
readsql=SELECT val FROM testdb.acc WHERE ext=’${ARG1}’

I get the read back but nothing is writed to sql

Opening a case in JIRA

Posted a bug report but it’s been closed saying it’s not a bug but nothing else.

Keen not to use the bug tracker as a support site, would have liked a bit more of a reason why they are confident it is not a bug but I will press on trying to get this, what looks like a simple config working.

Anyone out there see what I am doing wrong?

The reason the bug report has been rejected is that you have provided no evidence of a bug. Saying something doesn’t work is not nearly enough. The first responder gave you the benefit of the doubt and asked for evidence. The second responder just felt this looked too much like a user error, and closed it.

I think they also took the view that, if it really were broken, a lot more people would be complaining.

You didn’t even refer to this thread.

I don’t use the database access capabilities in Asterisk, so I’m not in a position to say what should and shouldn’t work.

Looking at the bug report chain it looks like I had less than 60 seconds to get a debug uploaded, not realy long enough but that will teach me for not putting enough detail in to start with.

Thanks for the input.

So back to the matter in hand. Does anyone have a working example of a writesql command? None of my ones do anything other than course Asterisk to crash.

This is the first time you said anything about crashing. If Asterisk really is crashing, the bug report is likely to be valid (although it can happen because of failing to remove old modules). I’m not sure if you really mean crashing, though. Google “asterisk wiki backtrace” for how to report real crashes.

If it really is crashing, that needs to be in the subject, and you need to attach the backtrace.

You probably got less than a minute becauase two people independently responded, and one was harsher than the other.

Yes I do mean it crashes but I assumed it was due to a malformed fun_odbc statement.

Effectivly if I use the readsql command instead of the writesql commond when you get to that step of the dialplan Asterisk reloads with an error code every time.

I have func_odbc loaded and I can perform readsql functions but not writesql functions.

You don’t have to compile asterisk with a write functionality do you. I’m using asterisk v10 built from RPM’s

it’s as if writesql functions are not available.

If I don’t have a readsql function defined it says the function is not readable.

Found plenty of posts talking about having problems but no posted fixes

For anyone who is interested the fix is as follows

Dialplan
same =>n,Set(test_timestamp(${ext})=1)

func_odbc.conf has the following
[timestamp]
prefix=test
dsn=asterisk
writesql= UPDATE testdb.acc SET val = val + ‘${VAL1}’ WHERE acc.ext = ‘${ARG1}’

It looks like you need to send an argument (${ext}) and a value, “=1” in this case. I don’t think you can issue a set command without passing an argument and a value to func_odbc and expect it to run the writesql command.
Well it’s been a long slog on this but learnt a bit.

Wish there was a bit more documentation around this although I guess if you read this type of syntax the two lines of documentation that exists on the asterisk WIKI is all you need.

Thanks for those that offered assistance.