# See prepared SQL statement and/or database tracing?

**URL:** <https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943>\
**Category:** Ignition\
**Tags:** ignition79, database, scripting\
**Created:** [November 19, 2018, 4:45pm UTC](https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943 "2018-11-19T16:45:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [November 19, 2018, 4:45pm UTC](https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943/1 "2018-11-19T16:45:59Z")

</div>

In the project I’m working on, database queries that were run are saved to a different database. Presently, the statements are prepared manually, but that allows for the exact query to get stored as a log of sorts

Is there a way to update this to prepared statements (`runPrepQuery`) and get the compiled statement easily? Is there any sort of tracing available?

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:** [November 19, 2018, 6:37pm UTC](https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943/2 "2018-11-19T18:37:59Z")

</div>

I’ve always used the database’s own ability to log queries.

---

<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 19, 2018, 6:42pm UTC](https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943/3 "2018-11-19T18:42:03Z")

</div>

You can also set the Gateway.Database.Updates (or Selects) loggers to TRACE to get _every_ database event that’s going through Ignition’s connection pooling. On a busy system, that can obviously be quite a lot.

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [November 19, 2018, 6:52pm UTC](https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943/4 "2018-11-19T18:52:07Z")

</div>

I’m terrible at making these questions smh

When storing the queries that were sent to the database, the user information is stored as well, which is the beauty of this method… `INSERT INTO queryLog (userName, query)` kind of thing. So while using the database’s built in method would normally be my go-to, since Ignition is just one user to the database this method makes sense

I just wish I could get us off of manually preparing queries. Perl’s DBI module, for instance, has a method to show you the specific trace event for the latest query you ran with your DBI object. It’s part of what gets returned

Thanks

---

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [November 21, 2018, 10:37am UTC](https://forum.inductiveautomation.com/t/see-prepared-sql-statement-and-or-database-tracing/20943/5 "2018-11-21T10:37:04Z")

</div>

You might want to consider using Ignition’s built in auditing. It stores all the information you are looking for plus a whole lot more. Following is a link to the documentation: [https://docs.inductiveautomation.com/display/DOC79/Using+Audit+Profiles](https://docs.inductiveautomation.com/display/DOC79/Using+Audit+Profiles)
