Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebird iSQL - How to input SQL query from command line, and retrieve output in simpler format

Tags:

sql

nsis

firebird

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>

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

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.

like image 422
Obay Avatar asked Dec 25 '22 01:12

Obay


1 Answers

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.

like image 108
Mark Rotteveel Avatar answered Dec 27 '22 17:12

Mark Rotteveel