# Error in excution of system.db.runUpdateQuery with variable!

**URL:** <https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663>\
**Category:** Ignition\
**Tags:** database\
**Created:** [August 22, 2019, 1:26pm UTC](https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663 "2019-08-22T13:26:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarmad.al-rubaye](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@sarmad.al-rubaye](https://forum.inductiveautomation.com/u/sarmad.al-rubaye)\
**Post date:** [August 22, 2019, 1:26pm UTC](https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663/1 "2019-08-22T13:26:23Z")

</div>

Hi Guys,  
I'm trying to excute the script below with variable but I allways get error, is there any one can help me into how pass avariable to the command "system.db.runUpdateQuery"

query\_01="INSERT INTO predictive\_test\_data (station\_number, line\_number, test\_ID, test\_result\_value, test\_date\_and\_time)"  
query\_02=" VALUES (?,?,?,?,?)"  
row\_data= (st\_number,'plm\_num',test\_id ,test\_value ,'datetime')  
query=query\_01 + query\_02  
print query  
system.db.runUpdateQuery(query ,row\_data)

Error

Java Traceback:  
Traceback (most recent call last):  
File "", line 14, in   
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)

```
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runUpdateQuery(AbstractDBUtilities.java:183)

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.runUpdateQuery(INSERT INTO predictive\_test\_data (station\_number, line\_number, test\_ID, test\_result\_value, test\_date\_and\_time) VALUES (10,'s000001',21 ,1543 ,'2019.08.20 10:10:34'), , , false)

```
at org.python.core.Py.JavaError(Py.java:552)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runUpdateQuery(AbstractDBUtilities.java:183)

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:188)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:514)

at org.python.core.PyObject. __call__ (PyObject.java:480)

at org.python.core.PyObject. __call__ (PyObject.java:484)

at org.python.pycode._pyx34.f$0(<buffer>:16)

at org.python.pycode._pyx34.call_function(<buffer>)

at org.python.core.PyTableCode.call(PyTableCode.java:171)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1614)

at org.python.core.Py.exec(Py.java:1658)

at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:116)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$InterpreterWorker.doInBackground(JythonConsole.java:506)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$InterpreterWorker.doInBackground(JythonConsole.java:494)

at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.desktop/javax.swing.SwingWorker.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 java.base/java.lang.Thread.run(Unknown Source)

```

Caused by: java.lang.Exception: Error executing system.db.runUpdateQuery(INSERT INTO predictive\_test\_data (station\_number, line\_number, test\_ID, test\_result\_value, test\_date\_and\_time) VALUES (10,'s000001',21 ,1543 ,'2019.08.20 10:10:34'), , , false)

```
... 27 more

```

Caused by: com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: Cannot run this function when in read-only mode.

```
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.getResponse(GatewayInterface.java:374)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:273)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:268)

at com.inductiveautomation.ignition.client.script.ClientDBUtilities._runUpdateQuery(ClientDBUtilities.java:189)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runUpdateQuery(AbstractDBUtilities.java:181)

... 25 more

```

Traceback (most recent call last):  
File "", line 14, in   
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)

```
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runUpdateQuery(AbstractDBUtilities.java:183)

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.runUpdateQuery(INSERT INTO predictive\_test\_data (station\_number, line\_number, test\_ID, test\_result\_value, test\_date\_and\_time) VALUES (10,'s000001',21 ,1543 ,'2019.08.20 10:10:34'), , , false)

> > >

---

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [August 22, 2019, 1:33pm UTC](https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663/2 "2019-08-22T13:33:07Z")

</div>

> Cannot run this function when in read-only mode.

For one thing, your designer has to be in Read/Write communications mode.

Another is how you're calling `system.db.runUpdateQuery`, it doesn't take row data like that. [Check out the documentation for it](https://docs.inductiveautomation.com/display/DOC80/system.db.runUpdateQuery).

If you want to insert variables into your query, you'll need to use string interpolation like such:

```auto
query = """
INSERT INTO predictive_test_data (station_number, line_number, test_ID, test_result_value, test_date_and_time)
VALUES {}, 'plm_num', {}, {}, 'datetime'
""".format(st_number, test_id, test_value)

```

(Also note that you can use multi-line strings in Python to make this much cleaner.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [August 22, 2019, 1:35pm UTC](https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663/3 "2019-08-22T13:35:04Z")

</div>

Use RunPrepUpdate when using ’ VALUES ?, ?’…

---

<div class="post-metadata">

**Author:** ![sarmad.al-rubaye](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@sarmad.al-rubaye](https://forum.inductiveautomation.com/u/sarmad.al-rubaye)\
**Post date:** [August 22, 2019, 1:53pm UTC](https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663/4 "2019-08-22T13:53:26Z")

</div>

thank you for your Reply, I Change the command to runPrepUpdate then I gor new error 🙂

Traceback (most recent call last):  
File “”, line 15, in   
TypeError: not all arguments converted during string formatting

---

<div class="post-metadata">

**Author:** ![sarmad.al-rubaye](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@sarmad.al-rubaye](https://forum.inductiveautomation.com/u/sarmad.al-rubaye)\
**Post date:** [August 22, 2019, 1:58pm UTC](https://forum.inductiveautomation.com/t/error-in-excution-of-system-db-runupdatequery-with-variable/27663/5 "2019-08-22T13:58:38Z")

</div>

now it’s working when I do the following Change:

System.db.runPrepUpdate(query,row\_data).  
👍👍
