# SQL within a client

**URL:** <https://forum.inductiveautomation.com/t/sql-within-a-client/29208>\
**Category:** Ignition\
**Created:** [October 18, 2019, 7:52pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208 "2019-10-18T19:52:54Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 18, 2019, 7:52pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/1 "2019-10-18T19:52:54Z")

</div>

I have a SQL statement that outputs results to a file. Where will the file attempt to be written? on the Client’s local machine, or the Gateway computer?

Snippet:  
SELECT columns…  
FROM table  
INTO OUTFILE “C:\tmp\output.csv”

REF:

> <https://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format>

---

<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:** [October 18, 2019, 7:57pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/2 "2019-10-18T19:57:57Z")

</div>

If you’re running it via a SQL command, it’s almost certainly going to dump into a file on whatever machine the database is running on.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 18, 2019, 8:27pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/3 "2019-10-18T20:27:19Z")

</div>

Yes, it is a large SQL stmt run via system.db.runquery(stmt) in an event handler for a button.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 18, 2019, 9:02pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/4 "2019-10-18T21:02:30Z")

</div>

I’m really looking for a way to save it to the client machine. Since the save button for the easy chart does not work…I"m going to test where the file actually goes. So far it has landed on the client computer.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 21, 2019, 5:23pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/5 "2019-10-21T17:23:40Z")

</div>

Is there any way to replicate the function of the Easy Chart’s Save button? It does not workfrom Ignition 7.9.8 and up.

---

<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:** [October 21, 2019, 5:27pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/6 "2019-10-21T17:27:09Z")

</div>

Can you clarify what “does not work” means? There was a bug in 7.9.8 **in particular** that’s fixed in 7.9.9 and up, where exporting would result in an empty file.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 21, 2019, 5:42pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/7 "2019-10-21T17:42:20Z")

</div>

“Does not work” means just that, I get an empty, corrupted excel file when using the built in save button, I have been attempting several methods of work arounds. Thought I would try to more fully address the issue first before continuing…in addition, I have tested 7.9.8 and higher. I have tested the respective versions and found none of them with a working save button.

---

<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:** [October 21, 2019, 5:47pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/8 "2019-10-21T17:47:03Z")

</div>

And what version of Ignition are you using? Are there any errors in the client/designer logs? Can you upload one of the corrupted files here, or PM it to me?

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 21, 2019, 6:26pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/9 "2019-10-21T18:26:56Z")

</div>

I sent you an output file. There are no error messages in the logfile.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 21, 2019, 6:35pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/10 "2019-10-21T18:35:21Z")

</div>

Not sure if this helps, but I just noticed the exported excel file has 9 columns and the related SQL table for that UDT has 14 columns.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [October 21, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/11 "2019-10-21T19:19:13Z")

</div>

FYI,

The select into outfile statement, even when being called via Ignition’s RunQuery command will consistently output the file on the physical machine local to the mySQL server instance.

---

<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:** [October 21, 2019, 7:34pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/12 "2019-10-21T19:34:43Z")

</div>

> [@lrhyrne](#):
>
> will consistently output the file on the physical machine local to the mySQL server instance.

Uhm, that's by design. Of your database. Ignition has no way to impact that. It would be true of (the equivalent syntax in) SQL Server and Postgres and Oracle, too.

As to your OP, consider using the interfaces of JFreeChart to script access to the actual data in your EasyChart, and feed that to whatever Excel export tool you like. Python's own `csv` module is quite configurable.

---

<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:** [October 21, 2019, 7:38pm UTC](https://forum.inductiveautomation.com/t/sql-within-a-client/29208/13 "2019-10-21T19:38:22Z")

</div>

Not sure what’s going on with the easy chart export. I’d get in touch with support, if you can - we’re exporting the column information to the file, so it’s just the data that’s missing, which is odd - I would have expected the file to be completely empty.
