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
+18.5k Golang : Set, Get and List environment variables
+9.2k Golang : Write multiple lines or divide string into multiple lines
+7.4k Golang : Check to see if *File is a file or directory
+10.9k Golang : Sieve of Eratosthenes algorithm
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+24.6k Golang : How to validate URL the right way
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+14.5k How to automatically restart your crashed Golang server
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+9k Golang : Go as a script or running go with shebang/hashbang style
+9.3k Golang : How to get ECDSA curve and parameters data?
+7.6k Javascript : Push notifications to browser with Push.js