# Why the last line of the script does not execute?

**URL:** <https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584>\
**Category:** Ignition\
**Created:** [March 24, 2022, 1:50pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584 "2022-03-24T13:50:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [March 24, 2022, 1:50pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/1 "2022-03-24T13:50:53Z")

</div>

Hi All  
I have a script behind the action performed event handler which is triggered by the button.  
In the script there is a call to the function in the project module.  
In the function there is system.db.runQuery(SQL), where SQL is a list of statements to reset some data in the database.

The last command in the function after system.db.runQuery(SQL) is command system.tag.write(tagpath, not tagvalue) to toggle a value after reset it does not execute.

What is strange:  
If the last toggle command is placed inside the function after system.db.runQuery(SQL) it does not execute at all without any error (although i am questioning my sanity as i think i saw some error just once).  
But if above command is placed outside the function but inside the script behind the button it does execute properly and reliably every time.

Does anybody know what might be the reason?  
I don’t see any error now but is this possible that sometimes errors are somehow supressed and stop displaying?

---

<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:** [March 24, 2022, 1:54pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/2 "2022-03-24T13:54:10Z")

</div>

Are you sure your SQL is ok? JDBC doesn’t specifically allow multiple statements or comments, though some branded JDBC drivers do.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [March 24, 2022, 1:59pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/3 "2022-03-24T13:59:25Z")

</div>

The best we can help is if you show your script, formated by pressing `</>`

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [March 24, 2022, 2:18pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/4 "2022-03-24T14:18:38Z")

</div>

Wow that’s spot on suggestion. I am using mariadb jdbc driver and i use multiple delete data statements inside the function behind the button:  
SQL =   
“”"  
BEGIN  
DELETE  
FROM Table1  
DELETE  
FROM Table2  
…  
END  
“”"  
1 do you know where can i find more info about maria jdbc driver. It seems to work at the moment but i need to test it more  
2 do you think if using BEGIN and END statements in the SQL command make any difference or is it just block of code to be executed?

As a test i did commend out system.db.runQuery(SQL), saved the change and refreshed and the toggle command still did not work.

Below is the code behind the button which opens a popup which then triggers a function

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/0/f0a245ef67f37cde525ad5e71f922ebe81914d85.png)

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [March 24, 2022, 2:19pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/5 "2022-03-24T14:19:32Z")

</div>

thanks for reply please my reply to Phil’s comment

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [March 24, 2022, 2:22pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/6 "2022-03-24T14:22:36Z")

</div>

i did not know about code formatting feature -thanks

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [March 24, 2022, 2:26pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/7 "2022-03-24T14:26:52Z")

</div>

you say thanks but did not use it xd

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 24, 2022, 2:30pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/8 "2022-03-24T14:30:00Z")

</div>

In this case I don’t see why you can’t just run two `system.db.runUpdateQuery` statements one for each table.

If there’s more logic to it you’re not showing to use and want to make it done in a single database call, you can always make it a stored procedure and call that.

If the concern is that you want to avoid the situation where `DELETE FROM table1` one runs but `DELETE FROM table2` does not, I would suggest using database transactions.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [March 24, 2022, 2:32pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/9 "2022-03-24T14:32:33Z")

</div>

i read your comment after pasting the code  
i will use it from now on 🙂

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [March 24, 2022, 2:34pm UTC](https://forum.inductiveautomation.com/t/why-the-last-line-of-the-script-does-not-execute/57584/10 "2022-03-24T14:34:52Z")

</div>

i totally agree i should run a transaction because if one command fails due to some foreign keys issue the whole reset would be dangerous and should be reverted.
