#!/bin/sh
# Copyright (c) 1999-2000  David Muse
# See the file COPYING for more information

for i in `sqlr-query -host $1 -port $2 -user $3 -password $4 -query "select table_name from user_tables"`
do
	TABLE=`echo $i | cut -d"\"" -f2`

	echo "Processing: $TABLE"

	CTLFILE=$TABLE.ctl

	echo "LOAD DATA" > $CTLFILE
	echo "INFILE *" >> $CTLFILE
	echo "APPEND" >> $CTLFILE
	echo "INTO TABLE $TABLE" >> $CTLFILE
	echo "FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'" >> $CTLFILE
	echo -n "(" >> $CTLFILE
	sqlr-fields -host $1 -port $2 -user $3 -password $4 -table "$TABLE" >> $CTLFILE
	echo -n ")" >> $CTLFILE
	echo >> $CTLFILE
	echo "BEGINDATA" >> $CTLFILE

	sqlr-query -host $1 -port $2 -user $3 -password $4 -query "select * from $TABLE" >> $CTLFILE
done
