Josh Emmick
Josh Emmick

Reputation: 21

Adding text output to Informix

I have a server running Informix and have 2 questions about text output while code is running.

I have a file that contains the code

sperform rtl_est_dte
isql <g_rtl_mrg1.sql> test
isql <fm_prft.sql> test
isql <whs_prft.sql> test
isql <upgfp_frgt.sql> test
isql <upd_plants.sql> test

Is there a way to add text output between each sql on the output screen so I can tell which step it is on?

OR

Can I add text into the actual SQL coding for each stage that would show in the output when running? Right now all I see is "Selected Database" "Deleted 424 rows" etc. I know how to add hidden text with { … } but not how to display text.

Upvotes: 1

Views: 680

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754490

That looks like a shell script. It would be clearer if it started with a shebang and some comments:

#!/bin/sh
#
# Run rtl_est_dte form to get new data,
# then run 5 scripts to process the data, saving the results in file test

Anyway, given that it is probably a shell script, you should be able to add echo lines to annotate what you want:

sperform rtl_est_dte
echo "Running g_rtl_mrg1"
isql <g_rtl_mrg1.sql> test
echo "Running fm_prft"
isql <fm_prft.sql> test
echo "Running whs_prft"
isql <whs_prft.sql> test
echo "Running upgfp_frgt"
isql <upgfp_frgt.sql> test
echo "Running upd_plants"
isql <upd_plants.sql> test
echo "Finished"

I hope you'll be able to give more meaningful names to the steps being run, but that illustrates what you could do.

I also observe that it keeps on zapping the test file, so the information saved by running g_rtl_mrg1.sql is lost when fm_prft.sql is run, and that's lost when whs_prft.sql is run, and so on. Use >> to append to the test file. It would be more conventional to separate the output redirection from the input redirection:

isql <upd_plants.sql >>test

rather than the current:

isql <upd_plants.sql> test

That isn't anything remotely like XML. Still, at least the original author didn't use:

<upd_plant.sql> test isql

That works the same — it confuses everyone who reads it.

You can also embed shell escapes in the .sql files:

SELECT * FROM SomeWhere;

!echo "Hello world!"

SELECT * FROM ElseWhere;

IIRC, the shell escapes don't work if you try to read the .sql file in the isql SQL Editor and then run it. It only works from the command line as in the code in the question.

The progress output (Database selected etc) is written to standard error, for better or worse (worse, IMO, but I wrote my own SQLCMD years before Microsoft produced theirs, precisely because I didn't like what isql did, nor what dbaccess did after it was released).

Upvotes: 1

Related Questions