# SQL script cause database to lock block

**URL:** <https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 16, 2023, 1:37am UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246 "2023-09-16T01:37:24Z")\
**Posts on this page:** 15\
**Page:** 3

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 21, 2023, 5:05pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/41 "2023-09-21T17:05:26Z")

</div>

Thank you.  
It is working perfect now:

```auto
	from java.lang import Throwable

	tx = system.db.beginNamedQueryTransaction(system.util.getProjectName(),Project.database, timeout=5000)
	
	queryPath = "Select_All"
	
	ds = ""
	#do query
	try:
		ds = system.db.runNamedQuery(queryPath, tx=tx)
	except Exception as e:
		system.perspective.print(str(e))
	except Throwable as t:
		system.perspective.print(str(t))
		system.db.rollbackTransaction(tx)
	else:
	    system.db.commitTransaction(tx)
	finally:
	    system.db.closeTransaction(tx)
	
	self.getChild("Table").props.data = ds

```

---

<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:** [September 21, 2023, 5:17pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/42 "2023-09-21T17:17:44Z")

</div>

```auto
except Exception as e:
		system.perspective.print(str(e))
	except Throwable as t:

```

You can use `e` for both of these, the `e` will only be available inside the except clause if triggered, and I think using e for the error is what you'll typically see in the field/other peoples scripts.

Also, and I guess this doesn't matter as much since you only have one named query, but in cases you have multiple named queries in a row, you probably want to roll back in your `except Exception as e` clause as well.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [November 30, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/43 "2023-11-30T17:49:34Z")

</div>

When error happened on Try Block. Code flow does not proceed? (after Finally block below)

> [@Eugene49](#):
>
> ```auto
> try:
> ds = system.db.runNamedQuery(queryPath, tx=tx)
> except Exception as e:
> system.perspective.print(str(e))
> except Throwable as t:
> system.perspective.print(str(t))
> system.db.rollbackTransaction(tx)
> else:
> system.db.commitTransaction(tx)
> finally:
> system.db.closeTransaction(tx)
> 	
> self.getChild("Table").props.data = ds
> 
> ```

---

<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:** [November 30, 2023, 6:06pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/44 "2023-11-30T18:06:20Z")

</div>

How do you know it isn't? `ds` wouldn't have a value if an exception was thrown.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [November 30, 2023, 6:13pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/45 "2023-11-30T18:13:24Z")

</div>

My bad - that is right. I got an error after the try block Thanks.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [November 30, 2023, 8:29pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/46 "2023-11-30T20:29:20Z")

</div>

When logging error, is there a variable I can print that shows location(component path) of the script where the error came from.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 30, 2023, 8:37pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/47 "2023-11-30T20:37:20Z")

</div>

No, but utilizing a custom logger, you can have it indicate what ever you need it to indicate.

---

<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:** [November 30, 2023, 8:41pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/48 "2023-11-30T20:41:38Z")

</div>

And a custom logger, when called to log something, will include Perspective view and component information as environment labels.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [November 30, 2023, 9:14pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/49 "2023-11-30T21:14:56Z")

</div>

I don't know if its just me, but this is not so user friendly.  
On a push of a button:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/5/95e1a572a6ccf682d4b706e7ba4ddb273df1f092.png)  
This is what I get in gateway log:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/6/46f550f4dfa61c4794ddb9ae440ca1afb440d11a.png)

How do I make the life of debug engineer easier?  
Where do I tell more details?

---

<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:** [November 30, 2023, 9:53pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/50 "2023-11-30T21:53:40Z")

</div>

Look at/click the icons in the right margin of that page. Or use `tail --follow` on the wrapper log file itself (my preference).

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [November 30, 2023, 11:04pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/51 "2023-11-30T23:04:15Z")

</div>

I think I am now beginning to understand.

The gateway "log monitor" has a log level "Ranking" settings which is universal (fixed).  
It can be as follows:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f501d1d7b8ed94cf094f821e6cd6a078d81fb899.png)

Depending on what is set on this Ranking settings.  
your logger command will show or not show.

If your logging method (.info(), .debug() ) are not under the ranking level set on the Log Monitor, it will not show up. (does this mean, its gone forever?)

Where is the Log Level Ranking(who is greater than who) be found?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 30, 2023, 11:13pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/52 "2023-11-30T23:13:24Z")

</div>

The ranking of log levels is exactly as pictured in that dropdown - trace \< debug \< info \< warn \< error \< fatal (which we never use in Ignition).

If you log a message in your script, it is logged to the gateway system log (per the `logback.xml` file in the gateway install directory) as well as output to `stdout`, which is captured by the 'service wrapper' process and dumped to the `wrapper.log` automatically rolling journal (which can be configured via the `ignition.conf` file).

The setting on the gateway webpage only controls what is shown on that particular page.

There are a few rare use cases where an individual logger uses the `logger.isTraceEnabled()` or `isDebugEnabled()` methods to check the _global_ state of a particular logger (which _is_ configurable on that page in the settings menu, or via [`system.util.setLoggingLevel`](https://docs.inductiveautomation.com/display/DOC81/system.util.setLoggingLevel)), but that's rare and not the primary action you'd undertake on that page.

Finally, if you're looking to interact with the `system_logs.idb`, or a diagnostics bundle, or a variety of other file formats Ignition can export that are useful for troubleshooting/diagnostics, may I not-so-humbly plug [Kindling](https://forum.inductiveautomation.com/t/kindling-a-collection-of-tools-to-help-with-ignition/54689), a tool I originally created to help our internal support team that has since been publicly released and semi-officially blessed.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [November 30, 2023, 11:33pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/53 "2023-11-30T23:33:57Z")

</div>

Thank you for shedding a light on this.  
As its bugging me for sometime now, how logger works.  
Finally I can close this.  
My only desire is to have a single place, where I can see all my custom message log, inspect if my system has an error or has unnecessary error.

One important question though:

As a developer, how would you read the Gateway Diagnostic Logs, such that to inspect and make sure, there is no loose scripts (errors from old script that was forgotten). also such that there is no critical error. What should I look for?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 1, 2023, 3:02am UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/54 "2023-12-01T03:02:32Z")

</div>

> [@Eugene49](#):
>
> As a developer, how would you read the Gateway Diagnostic Logs, such that to inspect and make sure, there is no loose scripts (errors from old script that was forgotten). also such that there is no critical error. What should I look for?

Scanning the logs for errors is as good an approach as any. "Stale" scripts don't really exist - if you change a script's config, the old code will stop firing and the new code will apply \[1\]. So if you keep seeing errors in the logs, you know you have an active problem; if you don't, then it's either intermittent or it's disappeared entirely. There's no single way to distinguish between the two.

* * *

1. _Technically_ you can have old code stick around, but you have to either try pretty hard or do something pretty wrong, so in practice for 99% of folks it's not an issue.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [March 23, 2024, 6:39pm UTC](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246/55 "2024-03-23T18:39:52Z")

</div>

> [@paul-griffith](#):
>
> If you log a message in your script, it is logged to the gateway system log (per the `logback.xml` file in the gateway install directory) as well as output to `stdout`, which is captured by the 'service wrapper' process and dumped to the `wrapper.log` automatically rolling journal (which can be configured via the `ignition.conf` file).

I now see the benefit of using `system.util.getLogger` and `system.util.setLoggingLevel`.  
getLogger allows to log different level, and setLoggingLevel allows the enabling which level to log or show.

Is there a way to output the log message to designer console? Is it wise to use logger instead of `system.perspective.print()` when debugging script and after debugging set logging level to lowest to hide debug messages.

[Previous page](https://forum.inductiveautomation.com/t/sql-script-cause-database-to-lock-block/79246.md?page=2)
