#!/usr/local/bin/tcl -f
#------------------------ Global Variables ---------------------------
#
# Feb 9th generalized setOrder and the loop in changeElem
#
#
loadlibindex /usr/local/tcl/local/ucosyb.tlib
loadlibindex /u/de/tcl/f/fosql.tlib
#
#---------------------------------------------------------------------------
# MAIN CODE
#---------------------------------------------------------------------------
# Code to stuff the data dictionary with incomplete entries for all
# fields in a given table.

# Handy Dandy Global Vars
#
global dbpipe1 dbpipe2 dbpipe3 dbpipe4 dbpipe5
global sybmsg
global server
global uname
global table
global debugs
set debugs {}

# Customization options:
#
global bitmapdir
global exedir
global reference
global fassists
global forms
global fwidgets
global site
global ftypes
#
# Directory in which to find icon bitmaps
set bitmapdir /u/de/tcl/f/bitmaps
#
# Directory in which to find extra executables like 'detached' and
# 'anyprint'
set exedir /usr/local/bin
#
# names of essential tables -- change these according to
#	your site
#	your app
#	your mood :-)
#
set site "UCOLick"
set fassists "info.dbo.fassists"
set forms "info.dbo.forms"
set fwidgets "info.dbo.fwidgets"
set ftypes "devel.cc.types"
# set dictionary "NONE"
set reference "info.dbo.data_dict"
#
set stdcols "nid pid stamp uid "
#
set uname ""

if {[llength $argv] == 0} {
	echo "Usage:  stuffdict Base.Owner.Table \[,Base.Owner.Table,...\]"
	exit 1
}

        echo "Please tell me your sybase username:"
        gets stdin user
        echo "Please enter your sybase password:"
        gets stdin pass

	set dbpipe1 [sybOpen $base $user $pass {}]

	foreach fqtable $argv {

	set t [split $fqtable .]

	if {[llength $t] < 3} {
		echo "$fqtable is not an base.owner.object table specification."
		echo "Please provide the tablename in the FQ form. Skipping..."
		continue
	}

        set base "[lindex $t 0]"
	set owner "[lindex $t 1]"
	set table "[lindex $t 2]"


	echo "adding column $c for table $table to reference"
	set sqlcmd "insert into $reference (tblid,dbname,owner,tablename) values (-1,'$base','$owner','$table')"
	doSQL 1

	}

	exit 0
