Error system.db.runPrepUpdate

Hello,

I tried to enter in the changed value of a tag the following script:
valore = 110
system.db.runPrepUpdate(“UPDATE scd_command SET id_command_status = 25 WHERE cd_command = (?)”, [valore])

But when I change the value I get this error:
[b]Value Changed Error executing script.
Traceback (most recent call last):
File “tagevent:valueChanged”, line 17, in valueChanged
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:260)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.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.runPrepUpdate(UPDATE scd_command SET id_command_status = 25 WHERE cd_command = (?), [110], , , false, false)
ERROR[/b]

I attach photos.
How can I fix this error?




You can fix it by supplying the database argument in the system.db.runPrepUpdate function call.

When the database argument is not supplied a project’s default datasource is used. That doesn’t work in this case because a Tag Event script is not associated with a project.

Best,

1 Like

Thanks a lot!

I have one more question. I put in the script the name of the database connection (dscada_main) like this:

valore = 110 system.db.runPrepUpdate("UPDATE scd_command SET id_command_status = 25 WHERE cd_command = (?)", [valore] ,dscada_main)

This is the syntax:
system.db.runPrepUpdate(query, args, database, tx, getKey, skipAudit)
Parameters
String database - The name of the database connection to execute against. If omitted or “”, the project’s default database connection will be used.

But it gives me this error:
Value Changed Error executing script.
Traceback (most recent call last):
File “tagevent:valueChanged”, line 17, in valueChanged
NameError: global name ‘dscada_main’ is not defined
ERROR

Can you help me?

Thanks


Yes.

Use a string argument, like this:

valore = 110
system.db.runPrepUpdate("UPDATE scd_command SET id_command_status = 25 WHERE cd_command = (?)", [valore] ,"dscada_main")

Now it works.

Thanks a lot!

Andrea