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.8k Javascript : How to replace HTML inside <div>?
+8.3k Golang: Prevent over writing file with md5 hash
+6.8k Golang : Muxing with Martini example
+8.6k Golang : Progress bar with ∎ character
+10.1k Golang : Find and replace data in all files recursively
+32.5k Golang : Copy directory - including sub-directories and files
+11.3k Golang : Intercept and process UNIX signals example
+12.3k Golang : Get month name from date example
+11.1k Golang : Read until certain character to break for loop
+9.5k Golang : Convert(cast) string to int64
+11.8k Golang : convert(cast) float to string
+17.9k Golang : How to make a file read only and set it to writable again?