hi Andy,
when you take a look at the documentation of the Rows type returned by
Query you will see a helpful example of its common use, appending the
scanned results into a slice. my recommendation would be to follow this
example and then check if the len(slice) == 0 to detect an empty set.
if you don't actually need the results scanned into a go slice, consider
using query row with a sql select count(*) … query and scan, then check
the resulting integer.
have fun!
On 12.09.20 21:16, Andy Hall wrote:
the database.Query func does not return ErrNoRows unlike the
database.QueryRow func so how to I handle an empty set when I wish to
run a query which returns multiple rows...
// tell other players in the room you have entered
rows_users, err := database.Query("SELECT username FROM users WHERE room
= ? AND username != ?", room, username)
// handle an empty set
if err != nil {
if err == sql.ErrNoRows {
fmt.Println("EMPTY SET")
} else {
fmt.Println(err)
return
}
The string "EMPTY SET" is never printed as the condition is never
set...so continues to run through the if statement.
Surely there is is way to handle no rows with Query ??
--
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts+unsubscr...@googlegroups.com
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/6d6c7d54-1a4b-4f07-bf22-8523045ce543n%40googlegroups.com
<https://groups.google.com/d/msgid/golang-nuts/6d6c7d54-1a4b-4f07-bf22-8523045ce543n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/e4d3d50e-18c3-9515-43f3-b6adadfd6998%40mb0.org.