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
Advertisement
Something interesting
Tutorials
+8.1k Golang : Multiplexer with net/http and map
+5.4k Golang : fmt.Println prints out empty data from struct
+11k Golang : Generate random elements without repetition or duplicate
+12.4k Golang : Search and extract certain XML data example
+21.6k Golang : GORM create record or insert new record into database example
+9.9k Golang : Translate language with language package example
+6.7k Golang : Skip or discard items of non-interest when iterating example
+7k Golang : How to call function inside template with template.FuncMap
+14.4k Golang : How to filter a map's elements for faster lookup
+8.8k Golang : Take screen shot of browser with JQuery example
+23.1k Golang : Randomly pick an item from a slice/array example
+9.7k Golang : Populate slice with sequential integers example