我正在通过 Go 运行查询
stmt, err := db.Prepare(sqlstring)
if err != nil{
log.Fatal(err)
}
defer stmt.Close()
这是 sql 字符串?是'安'
select
k_ele.value as kanji, id as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as gloss_id, NULL as gloss_val
from k_ele where value like ?
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
r_ele.id as r_ele_id, r_ele.value as r_ele_val,
NULL as gloss_id, NULL as gloss_val
from
r_ele, k_ele where k_ele.value like ? and k_ele.fk = r_ele.fk
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
gloss.id as gloss_id, gloss.value as gloss_val
from
sense, gloss, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
gloss.fk = sense.id;
这个查询可以通过控制台上的 sqlite3 和 SQLite 的 DB 浏览器很好地使用,并返回 8 行,甚至 go 代码中的 for 循环循环 8 次。
问题是,在
rows.Scan()
除了出现在每一行中的汉字(因为它在每一行中)之外,没有任何列值存储在变量中,但除了汉字之外什么都没有在 log.Println() 中打印出来。
rows, err := stmt.Query(parameter,parameter,parameter)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var kanji, r_ele_val, gloss_val string
var k_ele_id, r_ele_id, gloss_id int
rows.Scan(&kanji,&k_ele_id,&r_ele_id,&r_ele_val,&gloss_id,&gloss_val)
log.Println(kanji,k_ele_id, r_ele_id,r_ele_val,gloss_id,gloss_val)
}
这是输出(它是?因为我的 cmd 无法打印日语字符(如果将 ? 发送到我的浏览器,它将正确显示字符)
2015/02/11 22:18:42 ? 105921 0 0
2015/02/11 22:18:42 ? 0 0 0
2015/02/11 22:18:43 ? 0 0 0
2015/02/11 22:18:43 ? 0 0 0
2015/02/11 22:18:43 ? 0 0 0
2015/02/11 22:18:43 ? 0 0 0
2015/02/11 22:18:43 ? 0 0 0
2015/02/11 22:18:43 ? 0 0 0
奇怪的是,如果我更改列的顺序,例如将gloss_id、gloss_val 放在select 语句中。每个变量都存储为 0,甚至是在gloss_id 具有值之前的汉字。(这些是相同的数据集)
冉冉说
相关分类