Hey Steve,

So I initially tried that, and Golang reported that Query() is for a single 
value context:

# command-line-arguments
./2multi.go:20: multiple-value db.Query() in single-value context

Since the table has 2 columns, do I need to scan each column to it's own 
variable like this?

var str1 string
var str2 string
rows := db.QueryRow("SELECT * FROM animals").Scan(&str1, &str2)



On Thursday, September 14, 2017 at 7:24:16 PM UTC-7, Steven Hartland wrote:
>
> QueryRow(..) returns a *Row but you then chained a .Scan(..) which returns 
> an error as compile error suggests.
>
> I'm guessing you want rows, if so have a look at:
> https://golang.org/pkg/database/sql/#DB.Query
>
> On 15/09/2017 03:10, Alexandre K wrote:
>
> Thank you so much for your response!
>
> The code you added probably works, but I'm getting held up by something 
> else.
>
> I'm running into a set of errors when I execute this on the command 
> line...It seems the "rows" value I'm creating doesn't have the 
> functionality that the guide says it would????
>
> # command-line-arguments
> ./2multi.go:22: rows.Columns undefined (type error has no field or method 
> Columns)
> ./2multi.go:30: rows.Next undefined (type error has no field or method 
> Next)
> ./2multi.go:34: rows.Scan undefined (type error has no field or method 
> Scan)
> Here's an updated version of my code
>
> package main
> import (
>        "database/sql"
>        "fmt"
>        "log"
>         _ "github.com/go-sql-driver/mysql"
> )
> func main() {
> //Connect to database and check for errors  
>        db, err := sql.Open("mysql",
>                "script:script1!@tcp(10.14.0.173:3306)/dbaTesting")
>        if err != nil {
>                log.Println(err)
>        }
>         var str string
>        rows := db.QueryRow("SELECT * FROM animals").Scan(&str)
>         cols, err := rows.Columns() // Remember to check err afterwards
>        if err != nil {
>                log.Fatal(err)
>        }
>         vals := make([]interface{}, len(cols))
>         for rows.Next() {
>        for i := range cols {
>            vals[i] = &vals[i]
>                }
>        err = rows.Scan(vals...)
>        // Now you can check each element of vals for nil-ness,
>        if err != nil {
>                log.Fatal(err)
>        }
>        for i := range cols {
>                    fmt.Println(vals[i]) 
>                 }
>        }
> }
>
>
> Shouldn't the value I create in "rows" be able to pass arguments to the 
> "db" class I'm referencing when I'm creating "rows?"
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to