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
+6k PHP : How to check if an array is empty ?
+7.2k Golang : Use modern ciphers only in secure connection
+12k Golang : Convert a rune to unicode style string \u
+10k Golang : Read file and convert content to string
+12.7k Golang : Sort and reverse sort a slice of bytes
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+28.8k Golang : Detect (OS) Operating System
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+12.1k Golang : Sort and reverse sort a slice of runes
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+9.4k Golang : Apply Histogram Equalization to color images
+19.7k Golang : Archive directory with tar and gzip