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

**URL:** <https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [February 15, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760 "2024-02-15T15:03:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [February 15, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/1 "2024-02-15T15:03:55Z")

</div>

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:

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 15, 2024, 3:07pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/2 "2024-02-15T15:07:39Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [February 15, 2024, 3:15pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/3 "2024-02-15T15:15:58Z")

</div>

Here is the full error.

```auto
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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 15, 2024, 3:19pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/4 "2024-02-15T15:19:57Z")

</div>

> [@Daniella\_Donn](#):
>
> `Cannot find database connection - name cannot be null`

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.)

> **[system.db.runPrepUpdate | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-db/system-db-runPrepUpdate)**
>
> Runs a prepared statement against the database, returning the number of rows that were affected.

---

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [February 15, 2024, 7:51pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/5 "2024-02-15T19:51:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 15, 2024, 7:53pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/6 "2024-02-15T19:53:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daniella\_Donn](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@Daniella\_Donn](https://forum.inductiveautomation.com/u/Daniella_Donn)\
**Post date:** [February 15, 2024, 7:54pm UTC](https://forum.inductiveautomation.com/t/updating-a-query-db-running-into-system-db-runprepupdate-error/85760/7 "2024-02-15T19:54:57Z")

</div>

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