我是新來的,試圖從sqlite數據庫檢索數據。 我使用github.com/mattn/go-sqlite3作爲sqlite驅動程序。Go/golang sqlite查詢不返回任何行
我發送的查詢不會返回任何結果,即使它應該。我試過我的程序手動生成的查詢,它會返回數據,因爲它應該在手動使用查詢時以及當我通過我的程序發送時返回數據。
這裏是我的代碼:
for index := range Array {
id, _ := strconv.Atoi(Array[index])
rand.Seed(time.Now().UnixNano())
RandomNr := rand.Intn(100)
fmt.Printf("index: %d - randomnr: %d \n", id, RandomNr)
rows, errROW := db.Query("SELECT user.id,user.name,stage.link,player.url,player.characterchance,player.chance FROM user,stage,player WHERE user.id = '%d' AND '%d' <= user.chance AND stage.user = user.id AND stage.domain = player.id AND player.chance > 0 ORDER BY player.id ASC \n",id, RandomNr)//.Scan(&idr, &name, &link, &url, &characterchance, &chance)
//this is what the finished query looks like and it returns the rows as its supposed to
//rows, errROW := db.Query("SELECT user.id,user.name,stage.link,player.url,player.characterchance,player.chance FROM user,stage,player WHERE user.id = '203' AND '33' <= user.chance AND stage.user = user.id AND stage.domain = player.id AND player.chance > 0 ORDER BY player.id ASC")
if errROW != nil {
fmt.Println("errROW")
log.Println(errROW)
}
defer rows.Close()
if rows.Next() == false {
fmt.Println("no rows ")
}
for rows.Next() {
fmt.Println("where are the rows")
var id int
var name string
var link string
var url string
var characterchance int
var chance int
rows.Scan(&id, &name, &link, &url, &characterchance, &chance)
fmt.Println(id,name,link,url,characterchance,chance)
}
rows.Close()
}
}
這種查詢可以返回多個或單個行。我也嘗試通過QueryRow檢索數據作爲單行,也沒有返回任何結果。
任何幫助將不勝感激。
更新: 我加 如果rows.Next()==假
是試圖發現問題。刪除它會得到相同的結果。此外,我不會收到來自掃描的錯誤消息。 for rows.next()循環甚至不會執行。
沒有想法的人? – Markh