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
+15.3k Golang : How to get Unix file descriptor for console and file
+9.7k Golang : interface - when and where to use examples
+7.9k Golang : Get today's weekday name and calculate target day distance example
+5.6k Swift : Get substring with rangeOfString() function example
+8.9k Golang : Find network service name from given port and protocol
+13.4k Golang : Get constant name from value
+24.5k Golang : Time slice or date sort and reverse sort example
+26.8k Golang : Find files by extension
+7.8k Golang : Regular Expression find string example
+7.1k Golang : Validate credit card example
+16k Golang : Read large file with bufio.Scanner cause token too long error
+5.2k Golang : The Tao of importing package