Hi,
I have created a query tag reading value from a postgesSQL database.
I can read the value correctly with 1sec update time, but I cannot write value to the tag. Error shown below.
"Error writing “1” to tag [default]dbPlant/Devices/Light/cmd_manual Bad_ReadOnly(“Tag value source does not support writing.”
The tag value source is “db”.
Is it possible to write value to a query tag?
It works using the following script:
system.db.runUpdateQuery(“UPDATE device SET cmd_mode = ‘%s’ WHERE name = ‘%s’” % (queryValue, keyValue1), ‘dbPlant’)
I haven’t tested this, but I imagine this also works:
queryString = "UPDATE device SET cmd_mode=? WHERE name=?"
params = [queryValue,keyValue1]
system.db.runPrepUpdate(queryString,params,'dbPlant')
There’s a variety of reasons this is probably better than concatenating the query and values yourself including security (sql injection) and maybe performance (I think there might be a caching thing that runPrepUpdate takes advantage of). Even if I’m wrong about the performance part, it’s still good practice to use runPrepUpdate/runPrepQuery when needed instead of runQuery/runUpdateQuery for security.