proc pgSQL conno {
# $Header: /home/cvsroot/tcldb/ucodb/Tlib/pgSQL,v 1.5 1997/07/22 17:21:23 de Exp $

        global dbpipe$conno pgmsg 
        upvar sqlcmd sc
        upvar sqt sqt

#	puts stderr "doing pgSQL on dbpipe$conno set pg var"
        set pg [eval set dbpipe$conno]
#	puts stderr "got pipe name $pg for number $conno"

	set result NO_DICE

#	puts stderr "let's now do pgsql statement pgsql $pg $sc"
        set err [catch {set pghand [pg_exec $pg $sc]} msg]
        if {$err} {
               puts stderr "pgSQL was trying to do the command \n$sc\n on pipe $conno"
               puts stderr "Failed to access table $sqt, tell your dba:"
	       puts stderr "ERROR $msg"
               return "[list 0 ERROR $msg]"
        } 
	set pgmsg [pg_result $pghand -status]
	set pgct [pg_result $pghand -numTuples]
	set pgid [pg_result $pghand -oid]

	upvar #0 curs.$pghand curs.$pghand
	catch {unset curs.$pghand}
	set curs.$pghand 0

	set result "$pgct $pghand $pgmsg"
#	puts stderr "pgSQL got pgid $pgid, returning $result"
	
        return $result

}
