Posted to tcl by AspiringTickler at Sun Oct 03 10:03:11 GMT 2021view raw
- proc withdb { var handler } {
- upvar $var $var;
- sqlite3 $var "db"
- $var timeout 10000
- uplevel $handler
- $var close
- }
- proc someImport {id} {
- withdb db {
- if [db eval { SELECT COUNT() FROM foo WHERE id = $id }] {
- puts [format "%s already exists" $id]
- return
- }
- db eval { INSERT OR IGNORE INTO foo(id) VALUES($id) }
- }
- puts "should have returned here if count is 1"
- }