samedi 9 mai 2015

Go/golang sqlite query not returning any rows

I am new to go and trying to retrieve data from a sqlite database. Im using http://ift.tt/1lwG0Ak as sqlite driver.

The query I m sending does not return any results even though it should. I tried the query my programme is generating manually and it returns data as it should when I use the query manually as well as when I send it via my programme.

Here is my code:

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 WTF")

}
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()

}

}

This query can return multiple and single rows. I also tried retrieving the data via QueryRow as a single row which also did not return any result.

Any help would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire