Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
Mitja Udovc asked how to pass a parameter into an SQL script run through dbaccess. yurik shestakov said dbaccess cannot do this and gave a shell script feeding SQL through a here-document with the table name as an argument. Thomas Ronayne gave Bourne and Korn shell loops, and Nebojsa Sevo gave a similar script. Solved with shell wrappers.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
Hello!
I would like to do following:
in sql script file test.sql is:
select * from $1
I would like to call this sql from command line and pass parameter into it.
like: cat test.sql|dbaccess db-test - .... ???parameter
Mitja
On Fri, Dec 05, 2003 at 02:09:43PM +0100, Mitja Udovc wrote:
MU> Hello!
MU> I would like to do following:
MU> in sql script file test.sql is:
MU> select * from $1
MU> I would like to call this sql from command line and pass parameter into it.
MU> like: cat test.sql|dbaccess db-test - .... ???parameter
You can't use dbaccess in such way. Try this:
> cat my_query.sh
#!/bin/sh
if [ $0 -eq 0 ] ; then
echo "Usage: $0 table_name"
exit 1
fi
cat <<SQL | dbaccess db-test
select * from $1SQL
========================================================================
Example of usage: select all from table 'test_table':
> ./my_query.sh test_table
--
// yurik shestakov
↪ replying to Mitja Udovc
Thomas Ronayne — — source: Usenet: comp.databases.informix
Bourne shell:
#!/bin/sh
for what in `cat tablis`
do
echo 'select * from ${what}' | dbaccess dbname
done
Korn shell:
#!/bin/ksh
for what in $(cat tablist)
do
print "select * from ${what}" | dbaccess dbname
done
or (ksh)
#!/bin/ksh
print "select tabname from systables where tabid > 99 order by tabname"
| dbaccess dbname | sed '/tabname/d;s/ *$//;/^$/d' > list
for table in $(cat list)
do
print "select * from ${1} | dbaccess dbname
done
or (ksh):
cat > doit
#!/bin/ksh
print "select * from ${1}" | dbaccess dbname
^d
chmod 755 doit
doit tabname
and so on.
Mitja Udovc wrote:
> Hello!
>
> I would like to do following:
>
> in sql script file test.sql is:
>
> select * from $1>
> I would like to call this sql from command line and pass parameter into it.
> like: cat test.sql|dbaccess db-test - .... ???parameter
>
> Mitja
>
>
↪ replying to Thomas Ronayne
Thomas Ronayne — — source: Usenet: comp.databases.informix
>
> #!/bin/ksh
> print "select tabname from systables where tabid > 99 order by tabname"
> | dbaccess dbname | sed '/tabname/d;s/ *$//;/^$/d' > list
> for table in $(cat list)
> do
> print "select * from ${1} | dbaccess dbname
oops -- that's
print "select * from ${table}" | dbaccess dbname
> done
>
sorry
Napisi SHELL skriptu i u njoj:
#!/bin/sh
if [ ! $# = 1 ]; then
echo "Usage: $0 ime_tablice"
exit 1
fi
dbaccess ime_baze - <<KRAJ
select * from $1KRAJ
Recimo da se skripta zove run_sql. Treba joj dati pravilna ovlastenja:
chmod 775 run_sql
i izvodis je s
run_sql neka_tvoja_tablica
Pozdrav
Nebojsa
On Fri, 5 Dec 2003 14:09:43 +0100, "Mitja Udovc" <mitja.udovc@mf.uni-lj.si>
wrote:
>Hello!
>
>I would like to do following:
>
>in sql script file test.sql is:
>
>select * from $1>
>I would like to call this sql from command line and pass parameter into it.
>like: cat test.sql|dbaccess db-test - .... ???parameter
>
>Mitja
>
------------------------------------
Remove spam block (DELETE_) to reply
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.