tags:

views:

16

answers:

1

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:

% can't read "rowid": no such variable

then the 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] > 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"}

}
A: 

Nevermind, as soon as I changed the 2 lines to have the "as ...." like so:

 SELECT DISTINCT n.rowid as rowid, n.note_txt as note_txt, n.timestamp as timestamp

Everything worked. Sorry to waste your time. Hope someone benefits.

klausnrooster