# Ignition SQL Client Instance Separation

**URL:** <https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439>\
**Category:** Ignition\
**Tags:** ignition79, database\
**Created:** [October 29, 2018, 10:36pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439 "2018-10-29T22:36:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacslade](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacslade/32/3587_2.png) [@zacslade](https://forum.inductiveautomation.com/u/zacslade)\
**Post date:** [October 29, 2018, 10:36pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439/1 "2018-10-29T22:36:19Z")

</div>

Hi all,

Are Ignition Clients each their own independent SQL clients for the purposes of client or button scripts which use system.db.runQuery?

I’m testing a project which will read from a MySQL database which has several tables with autoincrement columns. In order to maintain consistency in the DB, I need to get the autoincrement values after each insertion, and then insert those values into some other tables. The [MySQL docs](https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-usagenotes-functionality-last-insert-id.html) indicate that the way to do this is by querying LAST\_INSERT\_ID(), and that [this value is client-independent](https://dba.stackexchange.com/questions/21181/is-mysqls-last-insert-id-function-guaranteed-to-be-correct). So, as long as each individual Ignition client sets up its own connection to the database, and acts as an independent SQL client, there shouldn’t be any issues with having multiple clients making insertions and then attempting to retrieve their autoincrement values.

Can anyone speak to this? Is that how Ignition works?

Thanks,

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 29, 2018, 10:42pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439/2 "2018-10-29T22:42:36Z")

</div>

> [@zacslade](#):
>
> So, as long as each individual Ignition client sets up its own connection to the database, and acts as an independent SQL client, there shouldn't be any issues with having multiple clients making insertions and then attempting to retrieve their autoincrement values.
> 
> Can anyone speak to this? Is that how Ignition works?

No, that's not how Ignition works. Database connections are made from the gateway. There's a pool of connections and you don't know which one your query will execute on when you run it.

---

<div class="post-metadata">

**Author:** ![zacslade](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacslade/32/3587_2.png) [@zacslade](https://forum.inductiveautomation.com/u/zacslade)\
**Post date:** [October 29, 2018, 11:33pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439/3 "2018-10-29T23:33:03Z")

</div>

Good information! Thanks!

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [October 30, 2018, 2:11pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439/4 "2018-10-30T14:11:55Z")

</div>

To accomplish what you want, you should use a function such as [system.db.runPrepUpdate](https://docs.inductiveautomation.com/display/DOC79/system.db.runPrepUpdate) that supports the parameter getKey and set it equal to 1 to retrieve your newly created key.

---

<div class="post-metadata">

**Author:** ![zacslade](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacslade/32/3587_2.png) [@zacslade](https://forum.inductiveautomation.com/u/zacslade)\
**Post date:** [October 30, 2018, 5:00pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439/5 "2018-10-30T17:00:48Z")

</div>

Thanks! I’ll be trying that out.

Also, would specifying a transaction ID guarantee that the same client was used for the entire transaction? And if I start a transaction, can I do multiple reads and writes in sequence with python processing, or does the entire transaction get committed to the DB at once?

---

<div class="post-metadata">

**Author:** ![zacslade](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacslade/32/3587_2.png) [@zacslade](https://forum.inductiveautomation.com/u/zacslade)\
**Post date:** [October 30, 2018, 6:02pm UTC](https://forum.inductiveautomation.com/t/ignition-sql-client-instance-separation/20439/6 "2018-10-30T18:02:08Z")

</div>

That worked! Thanks!
