Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询在带有字符串的Sqlite中工作。当变量传递到Tcl中的查询时,它会中断_Sql_Sqlite_Tcl - Fatal编程技术网

查询在带有字符串的Sqlite中工作。当变量传递到Tcl中的查询时,它会中断

查询在带有字符串的Sqlite中工作。当变量传递到Tcl中的查询时,它会中断,sql,sqlite,tcl,Sql,Sqlite,Tcl,我有一个带有“Toxi”模式的Sqlite notes数据库(notes表,Tags表,Note has Tag表,称为“fkeys”)。还有另外一个线程,它的查询非常详细。接口或“前端”是从Tclsh运行的Tcl脚本。如果我只有1个arg并且没有INTERSECT,那么Tcl版本就可以正常工作。在SqliteManager中,INTERSECT可以工作(但2个参数被文字字符串替换)。为什么会断裂?首先显示错误消息: % can't read "rowid": no such variable

我有一个带有“Toxi”模式的Sqlite notes数据库(notes表,Tags表,Note has Tag表,称为“fkeys”)。还有另外一个线程,它的查询非常详细。接口或“前端”是从Tclsh运行的Tcl脚本。如果我只有1个arg并且没有INTERSECT,那么Tcl版本就可以正常工作。在SqliteManager中,INTERSECT可以工作(但2个参数被文字字符串替换)。为什么会断裂?首先显示错误消息:

% can't read "rowid": no such variable
然后代码:

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"}

}

没关系,只要我把这两行改成“as…”这样:

一切顺利。很抱歉浪费你的时间。希望有人受益

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