Problem with SQL Query in a Tag change script

Good evening all,

We are actually facing some difficulties to put an SQL query inside a Tag change Script.

We are actually having an error message looking like :

.......", line 7, in valueChanged at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:364) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:290) at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(select * from HISTORY, , [null], .>

When we put the query in a simple button for example or in the Scrpting console, it works perfectly, but on the tag change script, it never works. Did we missed something ?

King regards,
Yassine

here is a picture f the very basic script

The tag events are run in the gateway scope, so they do not have a default database, you probably need to include your db connection name in the runPrepQuery call.

6 Likes

accyroy is correct. You will need to list your DB you are pulling from.

example: system.db.runPrepUpdate(‘DELETE FROM PROD_Line_Summary WHERE RunUUID = ?’,[RunID],“Analysis”)

The DB is in bold in the example above. Hope this helps.

1 Like

Thank you guys!
It works perfectly !

2 Likes