Golang database/sql.Rows.Close function usage examples
package database/sql
Close closes the Rows, preventing further enumeration. If Next returns false, the Rows are closed automatically and it will suffice to check the result of Err. Close is idempotent and does not affect the result of Err.
Golang database/sql.Rows.Close function usage examples
Example 1:
rows, err := db.Query("select id, name from users where id = ?", 1)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&id, &name)
if err != nil {
log.Fatal(err)
}
log.Println(id, name)
}
Example 2:
microsecsSupported := false
if rows, err := dbt.db.Query(`SELECT cast("00:00:00.1" as TIME(1)) = "00:00:00.1"`); err == nil {
rows.Scan(µsecsSupported)
rows.Close()
}
Reference :
Advertisement
Something interesting
Tutorials
+5.9k Golang : Denco multiplexer example
+11.8k Golang : convert(cast) float to string
+7.2k Golang : Dealing with postal or zip code example
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+5.4k Unix/Linux : How to archive and compress entire directory ?
+9.7k Golang : interface - when and where to use examples
+7k Golang : Takes a plural word and makes it singular
+62.7k Golang : Convert HTTP Response body to string
+19.1k Golang : Clearing slice
+12k Golang : Convert a rune to unicode style string \u