Re: SQL from the command line
Posted in 1995
Andy Cordell <andy@bnr.ca> writes:
>What is the proper way to provide a SQL command line interface to
>a user without making them create a sql command file to issue a
>command? What I'd like is the ability to type something like
>this on the unix command line:
><dbname> <SQL command here>
>The response would come back to stdout.
I think you have to pass the argument as a full string if you're using
anything Unix would expand (*, ?, ||). So training the user to enter
the statement as a quoted string:
shell_name "SELECT * FROM foo"
I had a similar problem when I wrote a shell script to EXECUTE a store
procedure. I have to type in:
exe "procedure()"
Because discluding the quotes causes Unix to choke on ().
=======================================================================
Dennis J. Pimple dennisp@informix.com Opinions expressed
Senior Consultant -------------------- are mine, and do not
Informix Software Inc Voice: 303-850-0210 necessarily reflect
Denver Colorado USA Fax: 303-779-4025 those of my employer.
>This is the almost working script that I wrote:
>#! /bin/sh
>echo "$@" > temp.sql
>dbaccess -e <dbname> temp.sql
>The only problem with this is that it expands the * in
>"select * from <table> " to be the current directory listing, so
>I end up with :
>select <insert really big directory listing here> from <table>
>as my SQL command, which is not good.
>Is this the right approach? Is there already a utility that will
>provide SQL statements (not cmd files) from the command line?
>Any help is much appreciated!
>Andy Cordell
>andy@bnr.ca