RE: Q: executing sql script from within another sql script?
Posted in 1998
Peter's correct, but I'd add two comments:
1. If DB-Access is reading from standard input, you can execute shell
scripts in it:
dbaccess dbase - <<EOF
SELECT * FROM Somewhere; !date
SELECT * FROM SomewhereElse; EOF
Note that you could run dbaccess instead of date, but any database locks
held by the first process would interfere with the second.
2. The SQLCMD program in the IIUG archives (http://www.iiug.org) has the
ability to read from other scripts, recursively to an arbitrary depth
determined by memory or (more plausibly) the number of available file
descriptors.
sqlcmd -d dbase - <<!
SELECT * FROM Somewhere; input scriptname.sql;
SELECT * FROM SomewhereElse; !
You can also redirect output to a file, and errors to a file (output
somefile; error notherfile;). You can redirect I/O back to the normal
input by specifying /dev/stdin, /dev/stdout, /dev/stderr, even on systems
which don't have such devices in the /dev directory. Also, the script that
is read cannot alter the redirection in the calling script; it can change
its own redirection, but the redirection terminates when the nested script
does. Similarly for all the other attributes which can be set. Note that
sqlcmd does not make any assumptions about script names ending with '.sql'.
If you ask it to read 'xyz', that's the file it will read, and not
'xyz.sql'.
I'll be releasing a new version of SQLCMD shortly which will have support
for CONNECT, DISCONNECT and SET CONNECTION in it (provided your ESQL/C has
support for them, of course, which means version 6.00 or later). This
version uses a small YACC grammar to handle these statements, but I will
distribute a pre-yacced C file for those without YACC.
Yours,
Jonathan Leffler (jleffler@visa.com) #include <bother.ms-exchange.h>
----------
From: Peter Lancashire[SMTP:Peter.Lancashire.PL1@bayer.co.uk]
Sent: Wednesday, April 08, 1998 9:40 AM
EA wrote:
> Is it possible in Informix dbaccess to call another sql script from
within a
> sql script?
> In Oracle the @ sign is used for that like in
> @scriptname.sql
Not directly. But you can feed SQL scripts into dbaccess through stdin,
so a bit of mucking about with awk, sed or some such should do what you
want.