4

I'm using Firebird's isql.exe tool to query an existing database:

isql -u <username> -p <password> <database> -i <file.sql> -o <output.txt>

which reads my SQL statements from file.sql and saves the results to output.txt.

But is there a way to feed the SQL statements into isql via command line, and not from a file?

This is because I actually plan to execute the command above in my .exe installer script (via ExecWait of NSIS Installer).

Also, is there a way to format the output such that only the actual info needed are returned? Currently the output's first line contains the column names, second line a bunch of "====" as separator, third line the actual info, with an arbitrary number of spaces in between each column. This output format makes it hard for me to use in my script.

Obay
  • 3,053
  • 12
  • 49
  • 74
  • 1
    Regarding your second question: [SET HEADING](http://www.firebirdsql.org/file/documentation/reference_manuals/user_manuals/html/isql-set.html#isql-set-heading) – Mark Rotteveel Dec 04 '14 at 09:56

2 Answers2

7

For your first problem, you can use Firebird isql without an input file as:

echo select * from rdb$database; | isql -u sysdba -p password C:\path\to\db.fdb

This redirects the standard output from echo (value select * from rdb$database;) to the standard input of isql. The result of the query (or queries) will be printed to the standard output of isql (or to file if you use -o).

However as echo is a feature of the command prompt, I am not certain if this will work from NSIS. Otherwise you will need something that does the same thing as echo: print its parameter values to the standard out.

As I commented before, for your second question you should look at SET HEADING and maybe SET WIDTH.

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
1

I case others find this useful, I was actually able to implement this in NSIS by using $PLUGINSDIR, which is a temporary folder created by NSIS at runtime. I created a temporary input and output file in that folder. I wrote the SQL statements into the input file using FileWrite and read the output using FileRead

Obay
  • 3,053
  • 12
  • 49
  • 74