Re: shell to perform dbaccess
Posted in 1997
you need to type the following:
>dbaccess {database name} {filename}
where filename is the file containing sql statements. It must have the
extension of .sql.
ontop <ontop@worldnet.att.net> wrote in article
<5jqm34$b6s@cssun.mathcs.emory.edu>...
> Teresa Crowl wrote:
>
> > Does anyone know how I would write a shell program to
> > take sql statements from a file and execute them
> > via dbaccess?
> >
> > ie:
> > file name: adt_transactions
> > data is:
> > insert into patient_census
> > VALUES("04/04/1997","A04","BC","3045","A")
> > insert into patient_census
> > VALUES("04/04/1997","A04","WC","4045","A")
> > insert into patient_census
> > VALUES("04/04/1997","A04","BC","3047","B")> > Teresa Crowl
> > tjc@umbra.pvh.org
>
> Interesting. I wonder if the data are the values in the quotes in your
> insert statements or the whole of the statements. It is a little easier
> if I get just the data in the quotes. Then I'd have file that looks
> like this. (pipe separated fields)
>
> 04/04/1997|A04|BC|3045|A
> 04/04/1997|A04|WC|4045|A
> 04/04/1997|A04|BC|3047|B|
>
> and I'd say
>
> cat adt_transactions |
> read
> do
> ARG1=`cat $REPLY | awk -F'|' '{print $1}'`
> ARG2=`cat $REPLY | awk -F'|' '{print $2}'`
> ARG3=`cat $REPLY | awk -F'|' '{print $3}'`
> ARG4=`cat $REPLY | awk -F'|' '{print $5}'`
>
> echo "insert into patient_census values(${ARG1}, ${ARG2}, ${ARG3},
> ${ARG4})" | dbaccess <dbname>
> done
>
> I am sure there is a fancier way of dividing the reply up into the
> arguments.
>
>