Golang database/sql.Stmt.Query function examples

package database/sql

Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.

Golang database/sql.Stmt.Query function usage examples

Example 1:

 func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows) {
 rows, err := dbt.db.Query(query, args...) // <--- here
 if err != nil {
 dbt.fail("Query", query, err)
 }
 return rows
 }

Example 2:

 var db = openDB()
 stmt, _ := db.Prepare("select created_on from staffs")
 rows, _ := stmt.Query() // <--- here

 for rows.Next() {
 time1 := new(time.Time)
 rows.Scan(time1)
 ...
 }

References :

https://github.com/go-sql-driver/mysql/blob/master/driver_test.go

http://golang.org/pkg/database/sql/#Stmt.Query

Advertisement