Getting the DATA TYPE from syscolumns: Code Sample #2:get_dts.sh
Posted in 1995
#!/bin/sh
##############################################################################
#
# PROGRAM: get_dts.sh: get data types shell for a table using the gettype
# program.
# AUTHOR: Tim Schaefer, The Computer Business Company, Inc.
# LATEST: Tue Oct 31 08:04:33 EST 1995
# USAGE: get_dts.sh database table
##############################################################################
#
DAT_FILE1=temp1.tmp
DAT_FILE2=temp2.tmp
DAT_FILE3=temp3.tmp
DAT_FILE4=temp4.tmp
DAT_FILE5=temp5.tmp
DAT_FILE6=temp6.tmp
database=$1
table=$2
if [ $# -lt 2 ]; then
echo "Usage: $0 database table"
exit
fi
isql -s ${database} > ${DAT_FILE1} 2>/dev/null <<+
select tabname, tabid
from systables
where tabname = "${table}" ;+
sed -e '/tabname/d' -e '/^$/d' ${DAT_FILE1} > ${DAT_FILE2}
awk ' { print $2 } ' ${DAT_FILE2} > ${DAT_FILE1}
tabid=`cat ${DAT_FILE1}`
isql -s ${database} > ${DAT_FILE3} 2>/dev/null <<+
select syscolumns.tabid, colno, colname, coltype, collength, tabname
from syscolumns, systables
where systables.tabid = $tabid and syscolumns.tabid = $tabid
order by syscolumns.colno;+
sed -e '/tabname/d' -e '/^$/d' ${DAT_FILE3} > ${DAT_FILE4}
awk ' { printf("%s|%s|%s|%s|%s|%s|\\n",$1,$2,$3,$4,$5,$6) } ' ${DAT_FILE4} >
${DAT_FILE5}
awk -F"|" ' BEGIN { run_str="" }
{
{ printf("%s|%-s|", $6,$3 ) }
run_str=" gettype "$4" "$5
{ system( run_str ) }
}
' ${DAT_FILE5} > ${DAT_FILE6}
awk ' { printf("%s|\\n",$0 ) } ' ${DAT_FILE6}
rm ${DAT_FILE1} ${DAT_FILE2} ${DAT_FILE3} ${DAT_FILE4} ${DAT_FILE5}
${DAT_FILE6}