Re: shell to perform dbaccess
Posted in 1997
Mario R. Canto
mcanto@unl.edu.ar
On Fri, 25 Apr 1997, ontop wrote:
} 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")
} > file name: adt_transactions
} > 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.
}
Yes, there is.
cat adt_transactions | dbaccess whateverdbnameis - -
Thats'all
Mario R. Canto
mcanto@unl.edu.ar