How to collect column headers and data using dbisqlc.exe command

2.5k Views Asked by At

I am trying to query a Sybase ASA database using the dbisqlc.exe command-line on a Windows system and would like to collect the column headers along with the associated table data.

Example:

dbisqlc.exe -nogui -c "ENG=myDB;DBN=dbName;UID=dba;PWD=mypwd;CommLinks=tcpip{PORT=12345}" select * from myTable; OUTPUT TO C:\OutputFile.txt

I would prefer it if this command wrote to stdout however that does not appear to be an option aside from using dbisql.exe which is not available in the environment I am in.

When I run it in this format the header and data is generated however in an unparsable format.

Any assistance would be greatly appreciated.

2

There are 2 best solutions below

3
On

Try adding the 'FORMAT SQL' clause to the OUTPUT statement. It will give you the select statement containing the column names as well as the data.

0
On

In reviewing the output from the following dbisqlc.exe command, it appears as though I can parse the output using perl.

Command: dbisqlc.exe -nogui -c "ENG=myDB;DBN=dbName;UID=dba;PWD=mypwd;CommLinks=tcpip{PORT=12345}" select * from myTable; OUTPUT TO C:\OutputFile.txt

The output appears to break in odd places using text editors such as vi or TextPad however the output from this command is actually returned with specific column widths.

The second line of the output includes a set of ='s signs which are contained for the width of each column. What I did was build a "template" string based on the ='s which can be passed to perls unpack function. I then use this template to build an array of column names and parse the result set using unpack.

This may not be the most efficient method however I think it should give me the results I am looking for.