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
+8.1k Golang : Get all countries phone codes
+17.3k Golang : How to tell if a file is compressed either gzip or zip ?
+5.4k Gogland : Datasource explorer
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+5.1k Swift : Convert (cast) Float to Int or Int32 value
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+6.1k Golang : Debug with Godebug
+7.5k Golang : Rename part of filename
+7.1k Golang : A simple forex opportunities scanner
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+8.2k Golang : Metaprogramming example of wrapping a function