I am running a query through Go using
stmt, err := db.Prepare(sqlstring)
if err != nil{
log.Fatal(err)
}
defer stmt.Close()
this is the sql string with ? being '安'
select
k_ele.value as kanji, id as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
NULL as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_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 re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
NULL as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_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,
re_restr.id as re_restr_id, re_restr.value as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
NULL as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
r_ele, re_restr, k_ele
where
k_ele.value like ? and
k_ele.fk = r_ele.fk and
re_restr.fk = r_ele.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
re_inf.id as re_inf_id, re_inf.entity as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
NULL as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
r_ele, re_inf, k_ele
where
k_ele.value like ? and
k_ele.fk = r_ele.fk and
re_inf.fk = r_ele.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
re_pri.id as re_pri_id, re_pri.value as re_pri_val,
NULL as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
r_ele, re_pri, k_ele
where
k_ele.value like ? and
k_ele.fk = r_ele.fk and
re_pri.fk = r_ele.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
stagk.id as stagk_id, stagk.value as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, stagk, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
stagk.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
stagr.id as stagr_id, stagr.value as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, stagr, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
stagr.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
pos.id as pos_id, pos.entity as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, pos, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
pos.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
xref.id as xref_id, xref.value as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, xref, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
xref.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
ant.id as ant_id, ant.value as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, ant, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
ant.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
field.id as field_id, field.entity as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, field, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
field.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
misc.id as misc_id, misc.entity as misc_val,
NULL as s_inf_id, NULL as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, misc, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
misc.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
s_inf.id as s_inf_id, s_inf.value as s_inf_val,
NULL as gloss_id, NULL as gloss_val
from
sense, s_inf, k_ele
where
k_ele.value like ? and
k_ele.fk = sense.fk and
s_inf.fk = sense.id
UNION ALL
select
k_ele.value as kanji, NULL as k_ele_id,
NULL as r_ele_id, NULL as r_ele_val,
NULL as re_restr_id, NULL as re_restr_val,
NULL as re_inf_id, NULL as re_inf_val,
NULL as re_pri_id, NULL as re_pri_val,
sense.id as sense_id,
NULL as stagk_id, NULL as stagk_val,
NULL as stagr_id, NULL as stagr_val,
NULL as pos_id, NULL as pos_val,
NULL as xref_id, NULL as xref_val,
NULL as ant_id, NULL as ant_val,
NULL as field_id, NULL as field_val,
NULL as misc_id, NULL as misc_val,
NULL as s_inf_id, NULL as s_inf_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;
This query can be used fine through sqlite3 on console and DB Browser for SQLite and returns 14 rows and even the for loop in the go code loops 14 times.
The problem is that during
rows.Scan()
none of the column values are being stored in the variables except kanji which appears in every row (since it is in every row) but nothing but kanji is printed out in log.Println().
rows, err := stmt.Query(parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter,parameter)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var kanji, r_ele_val, r_ele_nokanji, re_restr_val, re_inf_val, re_pri_val, stagk_val, stagr_val, pos_val, xref_val, ant_val, field_val, misc_val, s_inf_val, gloss_val string
var k_ele_id, r_ele_id, re_restr_id, re_inf_id, re_pri_id, sense_id, stagk_id, stagr_id, pos_id, xref_id, ant_id, field_id, misc_id, s_inf_id, gloss_id int
rows.Scan(&kanji,&k_ele_id,&r_ele_id,&r_ele_val,&r_ele_nokanji,&re_restr_id,&re_restr_val,&re_inf_id,&re_inf_val,&re_pri_id,&re_pri_val,&sense_id,&stagk_id,&stagk_val,&stagr_id,&stagr_val,&pos_id,&pos_val,&xref_id,&xref_val,&ant_id,&ant_val,&field_id,&field_val,&misc_id,&misc_val,&s_inf_id,&s_inf_val,&gloss_id,&gloss_val)
log.Println(kanji,k_ele_id, r_ele_id, re_restr_id, re_inf_id, re_pri_id, stagk_id, stagr_id, pos_id, xref_id, ant_id, field_id, misc_id, s_inf_id, gloss_id)
}
The strange thing is if I change the order of the columns for example putting gloss_id, gloss_val first. Every variable gets 0 stored, even kanji. The sql works perfectly fine in sqlite3, the for loop runs the correct number of times. I'm not sure what to try next. I'm not sure if this is a bug or is there something wrong with what I'm doing?
Aucun commentaire:
Enregistrer un commentaire