So, this appears to be working...However, something isn't being converted into a string.
The code is returning the following values. [50] [99 97 116] [49] [100 111 103] [52] [108 97 120] [54] [111 115 116 114 105 99 104] [51] [112 101 110 103 117 105 110] [53] [119 104 97 108 101] On Thursday, September 14, 2017 at 7:41:24 PM UTC-7, dja...@gmail.com wrote: > > Again not tested: > > 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) > } > > rows,err := db.Query("SELECT * FROM animals") > if err != nil { > log.Fatal(err) > } > defer rows.Close() > > 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]) > } > } > } > > > On Friday, September 15, 2017 at 5:10:43 AM UTC+3, 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.