Figure shows a TCL version
of our application.
#!/usr/local/pgsql/bin/pgtclsh
#
# pgtclsh sample program
#
set conn [pg_connect -conninfo "dbname=test"] ;# connect to the database
puts -nonewline "Enter a state code: " ;# prompt user for a state code
flush stdout
gets stdin state_code
;# send the query
set res [pg_exec $conn \
"SELECT name \
FROM statename \
WHERE code = '$state_code'"]
set ntups [pg_result $res -numTuples]
for {set i 0} {$i < $ntups} {incr i} { ;# loop through all rows returned
puts stdout [lindex [pg_result $res -getTuple $i] 0] ;# print the value returned
}
pg_disconnect $conn ;# disconnect from the database
This interface's specialty is accessing other toolkits and applications. The TK graphical interface toolkit is one example. TCL uses it for graphical applications. The TK toolkit has become so popular that several other scripting languages also use it as their graphical interface library.