# $Header: /home/cvsroot/tcldb/wisql/Tlib/SYBshowFields,v 1.2 1998/02/16 04:40:46 de Exp ${DB}showFields,v 1.1.1.1 1996/10/12 02:26:27 de Exp $
# tcl procs saved on Tue Sep 05 09:33:15 PDT 1995

proc SYBshowFields {} {


  global dbpipe1 DB
  global sybmsg
  global server
  global table
  global MsgW

#	hack, used to be single arg called tab
	set tab $table

	if {$tab == ""} {
		setMsg $MsgW "You must select a table before showing its fields."
		return
	}

  set plist ""
  set dbname [sybuse $dbpipe1]

  # use to use "sp_help tabname", changed to get the info directly from
  # system tables, now shows full column name to 30 characters
  # (thanks to Paul Friberg for this change)

   	set temp [split $tab .]
	set usr [lindex $temp 0]
	set tbl  [lindex $temp 1]
	set sqlcmd "select syscolumns.name, systypes.name,  syscolumns.length from syscolumns, sysobjects, systypes  where syscolumns.id = sysobjects.id and  sysobjects.name = '$tbl' and  sysobjects.uid = user_id('$usr') and  syscolumns.usertype = systypes.usertype"

        set sqt "syscolumns/sysobjects/systypes"
        set res [doSQL 1]
        if {[lindex $res 0] == "ERROR"} {
                echo "Serious problem here"
                echo "$sqlcmd"
                echo "$res"
                exit 1
        }


  set row [sybNext 1]

  ${DB}chkMsg

  while {[string compare $sybmsg(nextrow) REG_ROW] == 0} {
    set n [lindex $row 0]
    set t [lindex $row 1]
    if {[string match "*char" $t]} {
      set t ${t}([lindex $row 2])
    }
    lappend plist [format "%-15.15s %-12.12s" $n $t]
    set row [sybNext 1]
    ${DB}chkMsg

  }

  if {[llength $plist] == 0} {
    setMsg $MsgW "No fields in table $tab?  Something must be wrong."
    return
  }
  set tlabel "${usr}_$tbl"
  pickList .$dbname:$tlabel Fields 200x300 $plist ""

}

