# Load the sql package:
package require sql

# Connect to the database
set conn [sql connect]

# select the database 'test' to be used.
set res [catch {sql selectdb $conn test} msg]

if {$res != 0} {
	puts "Sorry, could not select the database 'test': $msg"
}

# Create a table and put some data in it:
catch {sql exec $conn "drop table junk"}
set res [catch {
  sql exec $conn "create table junk (i integer, r real, s char(10))"
} msg]

if {$res != 0} {
	puts "Unable to create table junk: $msg"
}

# Put some dummy data in:
for {set i 0} {$i < 10} {incr i} {
	sql exec $conn "insert into junk values ($i, $i.01, 'xx $i xx')"
}

# Do a select and display the results
sql query $conn "select * from junk where i > 3" 

while {[set row [sql fetchrow $conn]] != ""} {
	set i [lindex $row 0]
	set r [lindex $row 1]
	set s [lindex $row 2]
	puts "$i\t$r\t$s"
}

sql endquery $conn
sql disconnect $conn