查询在 Sqlite 中使用字符串进行。当变量传递给 Tcl 中的查询时,它会中断

发布于 2024-09-10 06:42:28 字数 1322 浏览 3 评论 0原文

我有一个带有“Toxi”模式的 Sqlite 笔记数据库(Notes 表、Tags 表、Note-has-Tag 表称为“fkeys”)。还有另一个线程涉及这个问题,以及它的查询,它非常详细。界面或“前端”是从 Tclsh 运行的 Tcl 脚本。如果我只有 1 个参数且没有 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"}

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2024-09-17 06:42:28

没关系,一旦我将两行更改为“as ....”,如下所示:

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

一切正常。抱歉浪费您的时间。希望有人受益。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文