proc find_next { db db_name t col } { # This proc finds the next numerical value for a given column. # This is most useful with an "ID" column, such as that in a # users table where you want to reuse user IDs. # db: The database file name # db_name: The name of the database in case there is more than one in the database file. Can be "". # t: The table name # col: The column to process set val "" sqlite3 dbs $db if {$db_name ne ""} { set table $db_name.$t putlog ">>> 1 >> 1 > table: $table" if {[catch { [set val [dbs eval "SELECT $col FROM $table"]] }]} { foreach l [split $::errorInfo \n] { putlog "ERROR:trace - $l" } } else { putlog ">>> 1 >> 3" } } else { set table $t putlog ">>> 1 >> 2 > table: $table" if {[catch { [set val [dbs eval "SELECT $col FROM $table"]] }]} { foreach l [split $::errorInfo \n] { putlog "ERROR:trace - $l" } } else { putlog ">>> 1 >> 4" } } dbs close return $val } When I run the following: set id [find_next "test.db" "main" "domain" "id"] I get: [22:11] >>> 1 >> 1 > table: main.domain [22:11] ERROR:trace - invalid command name "{} {} {} {}" [22:11] ERROR:trace - while executing [22:11] ERROR:trace - "[set val [dbs eval "SELECT $col FROM $table"]] " When I run the following: set id [find_next "test.db" "" "test" "id"] I get: [22:12] >>> 1 >> 2 > table: domain [22:12] ERROR:trace - invalid command name "{} {} {} {}" [22:12] ERROR:trace - while executing [22:12] ERROR:trace - "[set val [dbs eval "SELECT $col FROM $table"]] "