Golang database/sql.Rows.Next function examples
package database/sql
Next prepares the next result row for reading with the Scan method. It returns true on success, or false if there is no next result row or an error happened while preparing it. Err should be consulted to distinguish between the two cases.
Every call to Scan, even the first one, must be preceded by a call to Next.
Golang database/sql.Rows.Next function usage examples
Example 1:
rows, err := db.Query("INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') RETURNING did;")
if err != nil {
t.Fatal(err)
}
if !rows.Next() { // <----- here
t.Fatal("no rows")
}
Example 2:
rows, err := db.conn.Query("SELECT name, parent_id FROM edge WHERE entity_id = ?;", id)
if err != nil {
return refs
}
defer rows.Close()
for rows.Next() { // <--- here
var name string
var parentId string
if err := rows.Scan(&name, &parentId); err != nil {
return refs
}
refs = append(refs, &Edge{
EntityID: id,
Name: name,
ParentID: parentId,
})
}
References :
https://github.com/docker/docker/blob/master/pkg/graphdb/graphdb.go
Advertisement
Something interesting
Tutorials
+8k Findstr command the Grep equivalent for Windows
+30.6k Golang : Remove characters from string example
+10k CodeIgniter : Load different view for mobile devices
+9.8k Golang : Get current, epoch time and display by year, month and day
+5.5k Golang : If else example and common mistake
+8.3k Golang: Prevent over writing file with md5 hash
+9.4k Golang : Apply Histogram Equalization to color images
+21.2k Golang : How to get time zone and load different time zone?
+28.6k Get file path of temporary file in Go
+5.3k Golang : Pad file extension automagically
+7.2k Golang : Dealing with postal or zip code example
+28.5k Golang : Change a file last modified date and time