Posted to tcl by stu at Wed Feb 21 19:17:16 GMT 2018view raw

  1. proc giantSquid {q} {
  2. foreach v [lsearch -all -inline [tdbc::tokenize $q] :*] {
  3. set k [string range $v 1 end]
  4. uplevel 1 [subst -nocommands {if {![info exists $k]} { error {Billy sez: "My dog's name is: '$k'!"}}}]
  5. }
  6. return $q
  7. }
  8.  
  9. # Usage:
  10.  
  11. # set query "SELECT COUNT(*) FROM `$table(data)` WHERE `this`=:that AND `command`=:command AND `data`=:insert"
  12. # if {![$tdbc(1) allrows -as lists [giantSquid $query]]} { ... }
  13.  
  14.  
  15. # Test:
  16. package require tdbc
  17. proc z {} {
  18. set table(data) cow
  19. set that that
  20. set command command
  21. set insert insert
  22. set q "SELECT COUNT(*) FROM `$table(data)` WHERE `this`=:that AND `command`=:command AND `data`=:insert"
  23. puts [giantSquid $q]
  24. };z
  25.  
  26.