Posted to tcl by AspiringTickler at Sun Oct 03 10:03:11 GMT 2021view raw

  1. proc withdb { var handler } {
  2. upvar $var $var;
  3. sqlite3 $var "db"
  4. $var timeout 10000
  5. uplevel $handler
  6. $var close
  7. }
  8.  
  9. proc someImport {id} {
  10. withdb db {
  11. if [db eval { SELECT COUNT() FROM foo WHERE id = $id }] {
  12. puts [format "%s already exists" $id]
  13. return
  14. }
  15. db eval { INSERT OR IGNORE INTO foo(id) VALUES($id) }
  16. }
  17. puts "should have returned here if count is 1"
  18. }
  19.