title: Query works in Sqlite with strings. When vars passed to query in Tcl it breaks
body: <p>I have a Sqlite notes database with a "Toxi" schema (Notes table, Tags table, Note-has-Tag table called "fkeys"). There is another thread that goes into this, and the querying of it, it great detail. The interface or "front end" is a Tcl script run from Tclsh. The Tcl version works just fine if I just have 1 arg and no INTERSECT. In SqliteManager INTERSECT works (but the 2 args are replaced with literal strings). Why does it break? First the error message:</p>
  
  <pre><code>% can't read "rowid": no such variable
  </code></pre>
  
  <p>then the code:</p>
  
  <pre><code>proc gn {args} {
  
  package require sqlite3
  sqlite3 db jaysnotes.sqlite
  
  set tagsofar [db eval {select tag_text from tag}]
  puts "Tags so far: $tagsofar"
  
  if {$args eq ""} {
  puts "Enter 1 or more tags separated by spaces"
  gets stdin taglist
  } else {
  set taglist $args}
  
  set taglist [split $taglist " "]
  
  # note (note_txt, timestamp)
  # tag (tag_text)
  # fkeys (note_id ,tag_id)
  
  
  set srchtxt0 [lindex $taglist 0]
  if {[llength $taglist] &gt; 1}  {
  set srchtxt1 [lindex $taglist 1]
  } else {set srchtxt1 $srchtxt0}
  
  db eval {
    SELECT DISTINCT n.rowid, n.note_txt, n.timestamp
    FROM note n
    JOIN fkeys f
    ON n.rowid = f.note_id
    JOIN tag t
    ON t.rowid = f.tag_id
    WHERE t.tag_text = $srchtxt0
  INTERSECT  
    SELECT DISTINCT n.rowid, n.note_txt, n.timestamp
    FROM note n
    JOIN fkeys f
    ON n.rowid = f.note_id
    JOIN tag t
    ON t.rowid = f.tag_id
    WHERE t.tag_text = $srchtxt1      
  
    ORDER BY timestamp;} {puts "NOTE $rowid: $note_txt"
              puts "DATE: $timestamp\n"}
  
  }
  </code></pre>