# $Header: /home/cvsroot/tcldb/wisql/Tlib/mkSelect,v 1.3 1997/08/28 05:24:17 de Exp $
# tcl procs saved on Tue Sep 05 09:33:07 PDT 1995

proc mkSelect {which w} {



	upvar #0 ${which}where where
	upvar #0 ${which}col col
	upvar #0 ${which}colatts colatts
	upvar #0 ${which}op op
	upvar #0 ${which}ind ind
	upvar #0 ${which}comp1 comp1
	upvar #0 ${which}comp2 comp2



	if {($op == "") || ($comp1 == "")} {
		$w.messages configure  -text "Sorry, you must choose an operator and value(s) before pressing OK."	
		return
	} else {
	$w.messages configure  -text "You say $col must be $op $comp1 $comp2:  checking."
	}

	set type [keylget colatts($col) type]
	set ct [getType $type]

	set where($col,op) $op

	case $op in {

	{= < <= > >= !=} {
		if {$ct == "S"} {
		set where($col,sql) [format "%s '%s'" $op $comp1]
		} else {
		set where($col,sql) [format "%s %s" $op $comp1]
		}
		set where($col,c1) $comp1
		set where($col,c2) ""
	}
	{sta} {
		set where($col,sql) [format "like '%s%%'" $comp1]
		set where($col,c1) $comp1
		set where($col,c2) ""
	}
	{con} {
		set where($col,sql) [format "like '%%%s%%'" $comp1]
		set where($col,c1) $comp1
		set where($col,c2) ""
	}
	{end} {
		set where($col,sql) [format "like '%%%s'" $comp1]
		set where($col,c1) $comp1
		set where($col,c2) ""
	}
	{bet} {
		if {$ct == "S"} {
		set where($col,sql) [format "between '%s' and '%s'" $comp1 $comp2]
		} else {
		set where($col,sql) [format "between %s and %s" $comp1 $comp2]
		}
		
		set where($col,c1) $comp1
		set where($col,c2) $comp2
	}
	{in} {
		set build "in ("
		foreach val $comp1 {
			if {$ct == "S"} {
				set build [format "%s'%s'," $build $val]	
			} else {
				set build [format "%s%s," $build $val]
			}
		}
		set where($col,sql) [format "%s)" [string trimright $build ,]]
	}
	{default} {
		return
	}
	}




	$w.data.pic.win.winR.$col.st delete 0 end 
	$w.data.pic.win.winR.$col.st insert 0 "$where($col,sql)"

	
}

