我是新手,試圖從 sqlite 數(shù)據(jù)庫(kù)中檢索數(shù)據(jù)。我使用 github.com/mattn/go-sqlite3 作為 sqlite 驅(qū)動(dòng)程序。我發(fā)送的查詢不返回任何結(jié)果,即使它應(yīng)該返回。我嘗試了我的程序手動(dòng)生成的查詢,它在我手動(dòng)使用查詢以及通過我的程序發(fā)送查詢時(shí)返回?cái)?shù)據(jù)。這是我的代碼: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 作為單行檢索數(shù)據(jù),但也沒有返回任何結(jié)果。任何幫助將非常感激。更新:我添加了 if rows.Next() == false作為尋找問題的嘗試。刪除它會(huì)產(chǎn)生相同的結(jié)果。此外,我沒有從掃描中收到錯(cuò)誤消息。for rows.next() 循環(huán)甚至不會(huì)被執(zhí)行。
Go/golang sqlite 查詢不返回任何行
人到中年有點(diǎn)甜
2021-10-04 16:52:37