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
+11.7k Golang : Find age or leap age from date of birth example
+18k Golang : Get all upper case or lower case characters from string example
+5.6k PHP : Convert CSV to JSON with YQL example
+21.6k Golang : GORM create record or insert new record into database example
+12.6k Golang : Exit, terminating or aborting a program
+7.9k Javascript : How to check a browser's Do Not Track status?
+6.7k Golang : Skip or discard items of non-interest when iterating example
+7.5k Golang : Shuffle strings array
+10.6k Golang : Flip coin example
+9.6k Golang : Quadratic example
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+5.5k Clean up Visual Studio For Mac installation failed disk full problem