Search code examples
aquafold

Aqua Data Studio Macro possible?


is it possible to define some kind of macro/scripts in Aqua Data studio?

Basically, what I want to do: I have a folder containing several SQL-queries named xyz.sql, I want to run all of them and save them as xyz.csv

Is this somehow possible?

Thanks very much!


Solution

  • Aqua Data Studio has a feature called FluidShell which is an integrated shell, where you can use FluidShell commands to execute SELECT query and write it to File.

    FluidShell Introduction
    FluidShell Commands

    A few of the command which would be useful to achieve your task would be
    Executing SQL
    [Source][4]

    [4]: http://www.aquaclusters.com/app/home/project/public/aquadatastudio/wikibook/Documentation15/page/289/source

    To test I created 2 tables named foo and bar under SQL Server database named Northwind under a schema named dbo and inserted a few records. Next, I created a file named xyz.sql and put below 2 lines and saved the file.

    sqlexport -f csv -d Northwind -s dbo foo -o /Users/tariq/Desktop/stack1.csv
    sqlexport -f csv -d Northwind -s dbo bar -o /Users/tariq/Desktop/stack2.csv

    Then opened a fluidshell and used the source command source xyz.sql. Now the files were exported successfully to 2 files.

    Two things which I can think of are :
    A.) Contents in query.sql is SELECT * FROM dbo.Orders where ShipVia > 2 @
    Then I use the source combined with tee to get the results with
    source query.sql | \tee result.txt

    B.) Contents in query2.sql is as below
    select * from dbo.Orders where ShipVia > 2
    \go > mydata.txt
    Then at the FluidShell prompt use source query2.sql