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
+7.9k Golang : Ways to recover memory during run time.
+9.6k Golang : How to extract video or image files from html source code
+9.8k Golang : Qt get screen resolution and display on center example
+30.8k Golang : Download file example
+11.7k Golang : Gorilla web tool kit secure cookie example
+7.5k Golang : Dealing with struct's private part
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+28.5k Golang : Change a file last modified date and time
+18.5k Golang : Write file with io.WriteString
+22.7k Golang : Strings to lowercase and uppercase example