Updating a query db, running into system.db.runPrepUpdate error

Hi everyone!
I'm very new to ignition so I am still learning as I go. I have a table in perspective which is bonded to a query. The current goal is to have the user update the table in any cell they want and for the table to update that value as well as the query to update that value. I have written a script under the "onEditCellCommit" actions and it currently looks like so:

def runAction(self, event):
	row = event.row
	col  = event.column
	ds = self.props.data
	id = ds.getValueAt(row,'Delivery')
	query = "UPDATE DeliveryT SET %s = ? WHERE Delivery =?" % (col)
	system.db.runPrepUpdate(query, [event.value,id])
	self.refreshBinding('props.data')

However, every time I run this, I receive the same error and I'm not sure why:

File "<function:runAction>", line 7, in runAction
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE DeliveryT SET Yesterday = ? WHERE Delivery =?, [1, Small Stack Assembly], , , false, false).

Please let me know if there were any mistakes I have made and how to improve.
Thanks!

There should be more to that error message ("details"). Please post it here, using the pre-formatted text button in the forum comment editor to keep it neat. (Please also go back and edit your OP to apply that to your posted code.)

1 Like

Here is the full error.

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 7, in runAction
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:268)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE DeliveryT SET Yesterday = ? WHERE Delivery =?, [10, Small Stack Assembly], , , false, false)

	at org.python.core.Py.JavaError(Py.java:545)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:268)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:553)
	at org.python.core.PyObject.__call__(PyObject.java:477)
	at org.python.core.PyObject.__call__(PyObject.java:481)
	at org.python.pycode._pyx62.runAction$1(<function:runAction>:8)
	at org.python.pycode._pyx62.call_function(<function:runAction>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
	at org.python.core.PyFunction.function___call__(PyFunction.java:474)
	at org.python.core.PyFunction.__call__(PyFunction.java:469)
	at org.python.core.PyFunction.__call__(PyFunction.java:464)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)
	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:868)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1010)
	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:950)
	at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:161)
	at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:98)
	at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:80)
	at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263)
	at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54)
	at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252)
	at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221)
	at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 7, in runAction
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:268)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE DeliveryT SET Yesterday = ? WHERE Delivery =?, [10, Small Stack Assembly], , , false, false)

	... 37 more
Caused by: java.lang.Exception
com.inductiveautomation.ignition.common.GenericTransferrableException: Error executing system.db.runPrepUpdate(UPDATE DeliveryT SET Yesterday = ? WHERE Delivery =?, [10, Small Stack Assembly], , , false, false)
	... 36 more
Caused by: java.lang.IllegalArgumentException
com.inductiveautomation.ignition.common.GenericTransferrableException: Cannot find database connection - name cannot be null.
	at com.inductiveautomation.ignition.gateway.datasource.DatasourceManagerImpl.findForName(DatasourceManagerImpl.java:551)
	at com.inductiveautomation.ignition.gateway.datasource.DatasourceManagerImpl.getConnection(DatasourceManagerImpl.java:146)
	at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.getConnection(GatewayDBUtilities.java:101)
	at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.getConnection(GatewayDBUtilities.java:85)
	at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities._runPrepStmt(GatewayDBUtilities.java:198)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:261)
	... 34 more

Ignition v8.1.37 (b2024013011)
Java: Azul Systems, Inc. 17.0.9

Thank you for the quick response and how to format the code properly.

You are calling runPrepUpdate from a scope that doesn't apply a project default database. That makes that argument to runPrespUpdate no longer optional.

(Or you never set the project's default database.)

good catch! I didn't see that. Yea that was the problem. I added a db connection and now I don't get that error. When I run it on the browser, it does work, however, the current user is unable to see the updated table value another person put in, unless the current user updates another cell themself. What might the cause of this be?
Thank you for all the help!
Daniella

You would have to send a message to other sessions to refresh their table, too.

Oh ok. I'll look into how to do that now as the next step.
Thanks again!