RE : Shell to perform dbaccess
Posted in 1997
Hi all
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")
Not quite sure what your'e looking for here so I will give you a couple
of solutions...Ok?
First, try a load statement.
Step 1:
----------
Copy the file adt_transactions to xxx
Vi xxx and modify the lines above to read as follows...
04/04/1997|A04|BC|3045|A|
04/04/1997|A04|WC|4045|A|
04/04/1997|A04|BC|3047|B|
Each of the sets of data on a new line, no qotes and a pipe ( | )
seperating each of the values.
This is a load file.
Now fire up dbaccess, select query-language then new and type the
following statement:
Step 2
----------
LOAD FROM "xxx"
INSERT INTO patient_sensus
Each of the transactions in the file will be loaded and when complete it
will report
x row/s loaded.
at the bottom of the screen.
------------------------------------------------------------------------
Another alternative is to repeat step 1 above then
type the following at the command line :
echo "LOAD FROM \\"xxx\\" INSERT INTO patient_sensus"|dbaccess
your_database_name
This will execute is from the command line and there will be no need to
run dbaccess.
----------------------------------------------------------------------
A third method would be to hack the file adt_transactions and modify
each line to look as follows :
echo "insert into patient_census
VALUES(\\"04/04/1997\\",\\"A04\\",\\"BC\\",\\"3045\\",\\"A\\")"|dbaccess
your_database_name
echo "insert into patient_census
VALUES(\\"04/04/1997\\",\\"A04\\",\\"WC\\",\\"4045\\",\\"A\\")"|dbaccess
your_database_name
echo "insert into patient_census
VALUES(\\"04/04/1997\\",\\"A04\\",\\"BC\\",\\"3047\\",\\"B\\")"dbaccess
your_database_name
.
The backslash ( \\ ) in from of each of the quotes inside the echo
statement are very important.
Now save the file and change the permissions to 777.
ie: chmod 777 adt_transactions
then type aaa and press enter.
This will ececute each of the statements inside the file individually
and "1 row inserted" will
appear many times on your screen.
I suspect this is the solution you were looking for, however no matter
which way you look at it
you will have to change the information in the file for this to work, as
the status quo of the file
will not execute.
Hope this helps
Regards
David
.
david@west.co.za
Software Consultant
The West Solutions Group
Friends help you move...REAL friends help you move bodies!